jintack

QEMU hack to use sp804 timer instead of arm arch timer

Feb 8th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 4.19 KB | None | 0 0
  1. diff --git a/hw/arm/virt.c b/hw/arm/virt.c
  2. index 2972bb3..6a360d0 100644
  3. --- a/hw/arm/virt.c
  4. +++ b/hw/arm/virt.c
  5. @@ -72,6 +72,8 @@ enum {
  6.      VIRT_RTC,
  7.      VIRT_FW_CFG,
  8.      VIRT_PCIE,
  9. +    VIRT_TIMER01,
  10. +    VIRT_TIMER23,
  11.      VIRT_GIC_V2M,
  12.  };
  13.  
  14. @@ -134,6 +136,8 @@ static const MemMapEntry a15memmap[] = {
  15.      [VIRT_UART] =       { 0x09000000, 0x00001000 },
  16.      [VIRT_RTC] =        { 0x09010000, 0x00001000 },
  17.      [VIRT_FW_CFG] =     { 0x09020000, 0x0000000a },
  18. +    [VIRT_TIMER01] =    { 0x09030000, 0x00001000 },
  19. +    [VIRT_TIMER23] =    { 0x09040000, 0x00001000 },
  20.      [VIRT_MMIO] =       { 0x0a000000, 0x00000200 },
  21.      /* ...repeating for a total of NUM_VIRTIO_TRANSPORTS, each of that size */
  22.      /*
  23. @@ -151,6 +155,8 @@ static const int a15irqmap[] = {
  24.      [VIRT_UART] = 1,
  25.      [VIRT_RTC] = 2,
  26.      [VIRT_PCIE] = 3, /* ... to 6 */
  27. +    [VIRT_TIMER01] = 7,
  28. +    [VIRT_TIMER23] = 8,
  29.      [VIRT_MMIO] = 16, /* ...to 16 + NUM_VIRTIO_TRANSPORTS - 1 */
  30.      [VIRT_GIC_V2M] = 48, /* ...to 48 + NUM_GICV2M_SPIS - 1 */
  31.  };
  32. @@ -277,6 +283,7 @@ static void fdt_add_timer_nodes(const VirtBoardInfo *vbi)
  33.       * but for the GIC implementation provided by both QEMU and KVM
  34.       * they are edge-triggered.
  35.       */
  36. +#if 0
  37.      ARMCPU *armcpu;
  38.      uint32_t irqflags = GIC_FDT_IRQ_FLAGS_EDGE_LO_HI;
  39.  
  40. @@ -299,6 +306,7 @@ static void fdt_add_timer_nodes(const VirtBoardInfo *vbi)
  41.                                 GIC_FDT_IRQ_TYPE_PPI, 14, irqflags,
  42.                                 GIC_FDT_IRQ_TYPE_PPI, 11, irqflags,
  43.                                 GIC_FDT_IRQ_TYPE_PPI, 10, irqflags);
  44. +#endif
  45.  }
  46.  
  47.  static void fdt_add_cpu_nodes(const VirtBoardInfo *vbi)
  48. @@ -490,6 +498,29 @@ static void create_rtc(const VirtBoardInfo *vbi, qemu_irq *pic)
  49.      g_free(nodename);
  50.  }
  51.  
  52. +static void create_timer(const VirtBoardInfo *vbi, qemu_irq *pic)
  53. +{
  54. +   char *nodename;
  55. +   hwaddr base = vbi->memmap[VIRT_TIMER01].base;
  56. +   hwaddr size = vbi->memmap[VIRT_TIMER01].size;
  57. +   int irq = vbi->irqmap[VIRT_TIMER01];
  58. +   const char compat[] = "arm,sp804\0arm,primecell";
  59. +
  60. +   sysbus_create_simple("sp804", base, pic[irq]);
  61. +
  62. +   nodename = g_strdup_printf("/timer@%" PRIx64, base);
  63. +   qemu_fdt_add_subnode(vbi->fdt, nodename);
  64. +   qemu_fdt_setprop(vbi->fdt, nodename, "compatible", compat, sizeof(compat));
  65. +   qemu_fdt_setprop_sized_cells(vbi->fdt, nodename, "reg",
  66. +           2, base, 2, size); /* TODO: should be 1? */
  67. +   qemu_fdt_setprop_cells(vbi->fdt, nodename, "interrupts",
  68. +           GIC_FDT_IRQ_TYPE_SPI, irq,
  69. +           GIC_FDT_IRQ_FLAGS_LEVEL_HI);
  70. +   qemu_fdt_setprop_cell(vbi->fdt, nodename, "clocks", vbi->clock_phandle);
  71. +   qemu_fdt_setprop_string(vbi->fdt, nodename, "clock-names", "apb_pclk");
  72. +   g_free(nodename);
  73. +}
  74. +
  75.  static void create_virtio_devices(const VirtBoardInfo *vbi, qemu_irq *pic)
  76.  {
  77.      int i;
  78. @@ -860,6 +891,8 @@ static void machvirt_init(MachineState *machine)
  79.  
  80.      create_rtc(vbi, pic);
  81.  
  82. +    create_timer(vbi, pic);
  83. +
  84.      create_pcie(vbi, pic);
  85.  
  86.      /* Create mmio transports, so the user can create virtio backends
  87. diff --git a/hw/timer/arm_timer.c b/hw/timer/arm_timer.c
  88. index 1452910..6cb45f2 100644
  89. --- a/hw/timer/arm_timer.c
  90. +++ b/hw/timer/arm_timer.c
  91. @@ -382,8 +382,8 @@ static const TypeInfo icp_pit_info = {
  92.  };
  93.  
  94.  static Property sp804_properties[] = {
  95. -    DEFINE_PROP_UINT32("freq0", SP804State, freq0, 1000000),
  96. -    DEFINE_PROP_UINT32("freq1", SP804State, freq1, 1000000),
  97. +    DEFINE_PROP_UINT32("freq0", SP804State, freq0, 24000000),
  98. +    DEFINE_PROP_UINT32("freq1", SP804State, freq1, 24000000),
  99.      DEFINE_PROP_END_OF_LIST(),
  100.  };
  101.  
  102. diff --git a/kvm-all.c b/kvm-all.c
  103. index b2b1bc3..6434eba 100644
  104. --- a/kvm-all.c
  105. +++ b/kvm-all.c
  106. @@ -1388,9 +1388,11 @@ static int kvm_irqchip_create(MachineState *machine, KVMState *s)
  107.      if (!machine_kernel_irqchip_allowed(machine) ||
  108.          (!kvm_check_extension(s, KVM_CAP_IRQCHIP) &&
  109.           (kvm_vm_enable_cap(s, KVM_CAP_S390_IRQCHIP, 0) < 0))) {
  110. +        printf("[%s] gic is emulated\n", __func__);
  111.          return 0;
  112.      }
  113.  
  114. +    printf("[%s] gic is NOT emulated\n", __func__);
  115.      /* First probe and see if there's a arch-specific hook to create the
  116.       * in-kernel irqchip for us */
  117.      ret = kvm_arch_irqchip_create(s);
Add Comment
Please, Sign In to add comment