a9mpcore.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * Cortex-A9MPCore internal peripheral emulation.
  3. *
  4. * Copyright (c) 2009 CodeSourcery.
  5. * Copyright (c) 2011 Linaro Limited.
  6. * Written by Paul Brook, Peter Maydell.
  7. *
  8. * This code is licensed under the GPL.
  9. */
  10. #include "qemu/osdep.h"
  11. #include "qapi/error.h"
  12. #include "qemu/module.h"
  13. #include "hw/cpu/a9mpcore.h"
  14. #include "hw/irq.h"
  15. #include "hw/qdev-properties.h"
  16. #include "hw/core/cpu.h"
  17. #include "cpu.h"
  18. #define A9_GIC_NUM_PRIORITY_BITS 5
  19. static void a9mp_priv_set_irq(void *opaque, int irq, int level)
  20. {
  21. A9MPPrivState *s = (A9MPPrivState *)opaque;
  22. qemu_set_irq(qdev_get_gpio_in(DEVICE(&s->gic), irq), level);
  23. }
  24. static void a9mp_priv_initfn(Object *obj)
  25. {
  26. A9MPPrivState *s = A9MPCORE_PRIV(obj);
  27. memory_region_init(&s->container, obj, "a9mp-priv-container", 0x2000);
  28. sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->container);
  29. object_initialize_child(obj, "scu", &s->scu, TYPE_A9_SCU);
  30. object_initialize_child(obj, "gic", &s->gic, TYPE_ARM_GIC);
  31. object_initialize_child(obj, "gtimer", &s->gtimer, TYPE_A9_GTIMER);
  32. object_initialize_child(obj, "mptimer", &s->mptimer, TYPE_ARM_MPTIMER);
  33. object_initialize_child(obj, "wdt", &s->wdt, TYPE_ARM_MPTIMER);
  34. }
  35. static void a9mp_priv_realize(DeviceState *dev, Error **errp)
  36. {
  37. SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
  38. A9MPPrivState *s = A9MPCORE_PRIV(dev);
  39. DeviceState *scudev, *gicdev, *gtimerdev, *mptimerdev, *wdtdev;
  40. SysBusDevice *scubusdev, *gicbusdev, *gtimerbusdev, *mptimerbusdev,
  41. *wdtbusdev;
  42. int i;
  43. bool has_el3;
  44. CPUState *cpu0;
  45. Object *cpuobj;
  46. cpu0 = qemu_get_cpu(0);
  47. cpuobj = OBJECT(cpu0);
  48. if (strcmp(object_get_typename(cpuobj), ARM_CPU_TYPE_NAME("cortex-a9"))) {
  49. /* We might allow Cortex-A5 once we model it */
  50. error_setg(errp,
  51. "Cortex-A9MPCore peripheral can only use Cortex-A9 CPU");
  52. return;
  53. }
  54. scudev = DEVICE(&s->scu);
  55. qdev_prop_set_uint32(scudev, "num-cpu", s->num_cpu);
  56. if (!sysbus_realize(SYS_BUS_DEVICE(&s->scu), errp)) {
  57. return;
  58. }
  59. scubusdev = SYS_BUS_DEVICE(&s->scu);
  60. gicdev = DEVICE(&s->gic);
  61. qdev_prop_set_uint32(gicdev, "num-cpu", s->num_cpu);
  62. qdev_prop_set_uint32(gicdev, "num-irq", s->num_irq);
  63. qdev_prop_set_uint32(gicdev, "num-priority-bits",
  64. A9_GIC_NUM_PRIORITY_BITS);
  65. /* Make the GIC's TZ support match the CPUs. We assume that
  66. * either all the CPUs have TZ, or none do.
  67. */
  68. has_el3 = object_property_find(cpuobj, "has_el3") &&
  69. object_property_get_bool(cpuobj, "has_el3", &error_abort);
  70. qdev_prop_set_bit(gicdev, "has-security-extensions", has_el3);
  71. if (!sysbus_realize(SYS_BUS_DEVICE(&s->gic), errp)) {
  72. return;
  73. }
  74. gicbusdev = SYS_BUS_DEVICE(&s->gic);
  75. /* Pass through outbound IRQ lines from the GIC */
  76. sysbus_pass_irq(sbd, gicbusdev);
  77. /* Pass through inbound GPIO lines to the GIC */
  78. qdev_init_gpio_in(dev, a9mp_priv_set_irq, s->num_irq - 32);
  79. gtimerdev = DEVICE(&s->gtimer);
  80. qdev_prop_set_uint32(gtimerdev, "num-cpu", s->num_cpu);
  81. if (!sysbus_realize(SYS_BUS_DEVICE(&s->gtimer), errp)) {
  82. return;
  83. }
  84. gtimerbusdev = SYS_BUS_DEVICE(&s->gtimer);
  85. mptimerdev = DEVICE(&s->mptimer);
  86. qdev_prop_set_uint32(mptimerdev, "num-cpu", s->num_cpu);
  87. if (!sysbus_realize(SYS_BUS_DEVICE(&s->mptimer), errp)) {
  88. return;
  89. }
  90. mptimerbusdev = SYS_BUS_DEVICE(&s->mptimer);
  91. wdtdev = DEVICE(&s->wdt);
  92. qdev_prop_set_uint32(wdtdev, "num-cpu", s->num_cpu);
  93. if (!sysbus_realize(SYS_BUS_DEVICE(&s->wdt), errp)) {
  94. return;
  95. }
  96. wdtbusdev = SYS_BUS_DEVICE(&s->wdt);
  97. /* Memory map (addresses are offsets from PERIPHBASE):
  98. * 0x0000-0x00ff -- Snoop Control Unit
  99. * 0x0100-0x01ff -- GIC CPU interface
  100. * 0x0200-0x02ff -- Global Timer
  101. * 0x0300-0x05ff -- nothing
  102. * 0x0600-0x06ff -- private timers and watchdogs
  103. * 0x0700-0x0fff -- nothing
  104. * 0x1000-0x1fff -- GIC Distributor
  105. */
  106. memory_region_add_subregion(&s->container, 0,
  107. sysbus_mmio_get_region(scubusdev, 0));
  108. /* GIC CPU interface */
  109. memory_region_add_subregion(&s->container, 0x100,
  110. sysbus_mmio_get_region(gicbusdev, 1));
  111. memory_region_add_subregion(&s->container, 0x200,
  112. sysbus_mmio_get_region(gtimerbusdev, 0));
  113. /* Note that the A9 exposes only the "timer/watchdog for this core"
  114. * memory region, not the "timer/watchdog for core X" ones 11MPcore has.
  115. */
  116. memory_region_add_subregion(&s->container, 0x600,
  117. sysbus_mmio_get_region(mptimerbusdev, 0));
  118. memory_region_add_subregion(&s->container, 0x620,
  119. sysbus_mmio_get_region(wdtbusdev, 0));
  120. memory_region_add_subregion(&s->container, 0x1000,
  121. sysbus_mmio_get_region(gicbusdev, 0));
  122. /* Wire up the interrupt from each watchdog and timer.
  123. * For each core the global timer is PPI 27, the private
  124. * timer is PPI 29 and the watchdog PPI 30.
  125. */
  126. for (i = 0; i < s->num_cpu; i++) {
  127. int ppibase = (s->num_irq - 32) + i * 32;
  128. sysbus_connect_irq(gtimerbusdev, i,
  129. qdev_get_gpio_in(gicdev, ppibase + 27));
  130. sysbus_connect_irq(mptimerbusdev, i,
  131. qdev_get_gpio_in(gicdev, ppibase + 29));
  132. sysbus_connect_irq(wdtbusdev, i,
  133. qdev_get_gpio_in(gicdev, ppibase + 30));
  134. }
  135. }
  136. static Property a9mp_priv_properties[] = {
  137. DEFINE_PROP_UINT32("num-cpu", A9MPPrivState, num_cpu, 1),
  138. /* The Cortex-A9MP may have anything from 0 to 224 external interrupt
  139. * IRQ lines (with another 32 internal). We default to 64+32, which
  140. * is the number provided by the Cortex-A9MP test chip in the
  141. * Realview PBX-A9 and Versatile Express A9 development boards.
  142. * Other boards may differ and should set this property appropriately.
  143. */
  144. DEFINE_PROP_UINT32("num-irq", A9MPPrivState, num_irq, 96),
  145. DEFINE_PROP_END_OF_LIST(),
  146. };
  147. static void a9mp_priv_class_init(ObjectClass *klass, void *data)
  148. {
  149. DeviceClass *dc = DEVICE_CLASS(klass);
  150. dc->realize = a9mp_priv_realize;
  151. device_class_set_props(dc, a9mp_priv_properties);
  152. }
  153. static const TypeInfo a9mp_priv_info = {
  154. .name = TYPE_A9MPCORE_PRIV,
  155. .parent = TYPE_SYS_BUS_DEVICE,
  156. .instance_size = sizeof(A9MPPrivState),
  157. .instance_init = a9mp_priv_initfn,
  158. .class_init = a9mp_priv_class_init,
  159. };
  160. static void a9mp_register_types(void)
  161. {
  162. type_register_static(&a9mp_priv_info);
  163. }
  164. type_init(a9mp_register_types)