2
0

a9mpcore.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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 "target/arm/cpu-qom.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. if (s->num_irq < 32 || s->num_irq > 256) {
  47. error_setg(errp, "Property 'num-irq' must be between 32 and 256");
  48. return;
  49. }
  50. cpu0 = qemu_get_cpu(0);
  51. cpuobj = OBJECT(cpu0);
  52. if (strcmp(object_get_typename(cpuobj), ARM_CPU_TYPE_NAME("cortex-a9"))) {
  53. /* We might allow Cortex-A5 once we model it */
  54. error_setg(errp,
  55. "Cortex-A9MPCore peripheral can only use Cortex-A9 CPU");
  56. return;
  57. }
  58. scudev = DEVICE(&s->scu);
  59. qdev_prop_set_uint32(scudev, "num-cpu", s->num_cpu);
  60. if (!sysbus_realize(SYS_BUS_DEVICE(&s->scu), errp)) {
  61. return;
  62. }
  63. scubusdev = SYS_BUS_DEVICE(&s->scu);
  64. gicdev = DEVICE(&s->gic);
  65. qdev_prop_set_uint32(gicdev, "num-cpu", s->num_cpu);
  66. qdev_prop_set_uint32(gicdev, "num-irq", s->num_irq);
  67. qdev_prop_set_uint32(gicdev, "num-priority-bits",
  68. A9_GIC_NUM_PRIORITY_BITS);
  69. /* Make the GIC's TZ support match the CPUs. We assume that
  70. * either all the CPUs have TZ, or none do.
  71. */
  72. has_el3 = object_property_find(cpuobj, "has_el3") &&
  73. object_property_get_bool(cpuobj, "has_el3", &error_abort);
  74. qdev_prop_set_bit(gicdev, "has-security-extensions", has_el3);
  75. if (!sysbus_realize(SYS_BUS_DEVICE(&s->gic), errp)) {
  76. return;
  77. }
  78. gicbusdev = SYS_BUS_DEVICE(&s->gic);
  79. /* Pass through outbound IRQ lines from the GIC */
  80. sysbus_pass_irq(sbd, gicbusdev);
  81. /* Pass through inbound GPIO lines to the GIC */
  82. qdev_init_gpio_in(dev, a9mp_priv_set_irq, s->num_irq - 32);
  83. gtimerdev = DEVICE(&s->gtimer);
  84. qdev_prop_set_uint32(gtimerdev, "num-cpu", s->num_cpu);
  85. if (!sysbus_realize(SYS_BUS_DEVICE(&s->gtimer), errp)) {
  86. return;
  87. }
  88. gtimerbusdev = SYS_BUS_DEVICE(&s->gtimer);
  89. mptimerdev = DEVICE(&s->mptimer);
  90. qdev_prop_set_uint32(mptimerdev, "num-cpu", s->num_cpu);
  91. if (!sysbus_realize(SYS_BUS_DEVICE(&s->mptimer), errp)) {
  92. return;
  93. }
  94. mptimerbusdev = SYS_BUS_DEVICE(&s->mptimer);
  95. wdtdev = DEVICE(&s->wdt);
  96. qdev_prop_set_uint32(wdtdev, "num-cpu", s->num_cpu);
  97. if (!sysbus_realize(SYS_BUS_DEVICE(&s->wdt), errp)) {
  98. return;
  99. }
  100. wdtbusdev = SYS_BUS_DEVICE(&s->wdt);
  101. /* Memory map (addresses are offsets from PERIPHBASE):
  102. * 0x0000-0x00ff -- Snoop Control Unit
  103. * 0x0100-0x01ff -- GIC CPU interface
  104. * 0x0200-0x02ff -- Global Timer
  105. * 0x0300-0x05ff -- nothing
  106. * 0x0600-0x06ff -- private timers and watchdogs
  107. * 0x0700-0x0fff -- nothing
  108. * 0x1000-0x1fff -- GIC Distributor
  109. */
  110. memory_region_add_subregion(&s->container, 0,
  111. sysbus_mmio_get_region(scubusdev, 0));
  112. /* GIC CPU interface */
  113. memory_region_add_subregion(&s->container, 0x100,
  114. sysbus_mmio_get_region(gicbusdev, 1));
  115. memory_region_add_subregion(&s->container, 0x200,
  116. sysbus_mmio_get_region(gtimerbusdev, 0));
  117. /* Note that the A9 exposes only the "timer/watchdog for this core"
  118. * memory region, not the "timer/watchdog for core X" ones 11MPcore has.
  119. */
  120. memory_region_add_subregion(&s->container, 0x600,
  121. sysbus_mmio_get_region(mptimerbusdev, 0));
  122. memory_region_add_subregion(&s->container, 0x620,
  123. sysbus_mmio_get_region(wdtbusdev, 0));
  124. memory_region_add_subregion(&s->container, 0x1000,
  125. sysbus_mmio_get_region(gicbusdev, 0));
  126. /* Wire up the interrupt from each watchdog and timer.
  127. * For each core the global timer is PPI 27, the private
  128. * timer is PPI 29 and the watchdog PPI 30.
  129. */
  130. for (i = 0; i < s->num_cpu; i++) {
  131. int ppibase = (s->num_irq - 32) + i * 32;
  132. sysbus_connect_irq(gtimerbusdev, i,
  133. qdev_get_gpio_in(gicdev, ppibase + 27));
  134. sysbus_connect_irq(mptimerbusdev, i,
  135. qdev_get_gpio_in(gicdev, ppibase + 29));
  136. sysbus_connect_irq(wdtbusdev, i,
  137. qdev_get_gpio_in(gicdev, ppibase + 30));
  138. }
  139. }
  140. static const Property a9mp_priv_properties[] = {
  141. DEFINE_PROP_UINT32("num-cpu", A9MPPrivState, num_cpu, 1),
  142. /*
  143. * The Cortex-A9MP may have anything from 0 to 224 external interrupt
  144. * lines, plus always 32 internal IRQs. This property sets the total
  145. * of internal + external, so the valid range is from 32 to 256.
  146. * The board model must set this to whatever the configuration
  147. * used for the CPU on that board or SoC is.
  148. */
  149. DEFINE_PROP_UINT32("num-irq", A9MPPrivState, num_irq, 0),
  150. };
  151. static void a9mp_priv_class_init(ObjectClass *klass, void *data)
  152. {
  153. DeviceClass *dc = DEVICE_CLASS(klass);
  154. dc->realize = a9mp_priv_realize;
  155. device_class_set_props(dc, a9mp_priv_properties);
  156. }
  157. static const TypeInfo a9mp_types[] = {
  158. {
  159. .name = TYPE_A9MPCORE_PRIV,
  160. .parent = TYPE_SYS_BUS_DEVICE,
  161. .instance_size = sizeof(A9MPPrivState),
  162. .instance_init = a9mp_priv_initfn,
  163. .class_init = a9mp_priv_class_init,
  164. },
  165. };
  166. DEFINE_TYPES(a9mp_types)