cps.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. * Coherent Processing System emulation.
  3. *
  4. * Copyright (c) 2016 Imagination Technologies
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include "qemu/osdep.h"
  20. #include "qapi/error.h"
  21. #include "qemu/module.h"
  22. #include "hw/mips/cps.h"
  23. #include "hw/mips/mips.h"
  24. #include "hw/qdev-properties.h"
  25. #include "hw/mips/cpudevs.h"
  26. #include "sysemu/kvm.h"
  27. #include "sysemu/reset.h"
  28. qemu_irq get_cps_irq(MIPSCPSState *s, int pin_number)
  29. {
  30. assert(pin_number < s->num_irq);
  31. return s->gic.irq_state[pin_number].irq;
  32. }
  33. static void mips_cps_init(Object *obj)
  34. {
  35. SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
  36. MIPSCPSState *s = MIPS_CPS(obj);
  37. /*
  38. * Cover entire address space as there do not seem to be any
  39. * constraints for the base address of CPC and GIC.
  40. */
  41. memory_region_init(&s->container, obj, "mips-cps-container", UINT64_MAX);
  42. sysbus_init_mmio(sbd, &s->container);
  43. }
  44. static void main_cpu_reset(void *opaque)
  45. {
  46. MIPSCPU *cpu = opaque;
  47. CPUState *cs = CPU(cpu);
  48. cpu_reset(cs);
  49. /* All VPs are halted on reset. Leave powering up to CPC. */
  50. cs->halted = 1;
  51. }
  52. static bool cpu_mips_itu_supported(CPUMIPSState *env)
  53. {
  54. bool is_mt = (env->CP0_Config5 & (1 << CP0C5_VP)) ||
  55. (env->CP0_Config3 & (1 << CP0C3_MT));
  56. return is_mt && !kvm_enabled();
  57. }
  58. static void mips_cps_realize(DeviceState *dev, Error **errp)
  59. {
  60. MIPSCPSState *s = MIPS_CPS(dev);
  61. CPUMIPSState *env;
  62. MIPSCPU *cpu;
  63. int i;
  64. target_ulong gcr_base;
  65. bool itu_present = false;
  66. bool saar_present = false;
  67. for (i = 0; i < s->num_vp; i++) {
  68. cpu = MIPS_CPU(cpu_create(s->cpu_type));
  69. /* Init internal devices */
  70. cpu_mips_irq_init_cpu(cpu);
  71. cpu_mips_clock_init(cpu);
  72. env = &cpu->env;
  73. if (cpu_mips_itu_supported(env)) {
  74. itu_present = true;
  75. /* Attach ITC Tag to the VP */
  76. env->itc_tag = mips_itu_get_tag_region(&s->itu);
  77. env->itu = &s->itu;
  78. }
  79. qemu_register_reset(main_cpu_reset, cpu);
  80. }
  81. cpu = MIPS_CPU(first_cpu);
  82. env = &cpu->env;
  83. saar_present = (bool)env->saarp;
  84. /* Inter-Thread Communication Unit */
  85. if (itu_present) {
  86. object_initialize_child(OBJECT(dev), "itu", &s->itu, TYPE_MIPS_ITU);
  87. object_property_set_int(OBJECT(&s->itu), "num-fifo", 16,
  88. &error_abort);
  89. object_property_set_int(OBJECT(&s->itu), "num-semaphores", 16,
  90. &error_abort);
  91. object_property_set_bool(OBJECT(&s->itu), "saar-present", saar_present,
  92. &error_abort);
  93. if (saar_present) {
  94. s->itu.saar = &env->CP0_SAAR;
  95. }
  96. if (!sysbus_realize(SYS_BUS_DEVICE(&s->itu), errp)) {
  97. return;
  98. }
  99. memory_region_add_subregion(&s->container, 0,
  100. sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->itu), 0));
  101. }
  102. /* Cluster Power Controller */
  103. object_initialize_child(OBJECT(dev), "cpc", &s->cpc, TYPE_MIPS_CPC);
  104. object_property_set_int(OBJECT(&s->cpc), "num-vp", s->num_vp,
  105. &error_abort);
  106. object_property_set_int(OBJECT(&s->cpc), "vp-start-running", 1,
  107. &error_abort);
  108. if (!sysbus_realize(SYS_BUS_DEVICE(&s->cpc), errp)) {
  109. return;
  110. }
  111. memory_region_add_subregion(&s->container, 0,
  112. sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->cpc), 0));
  113. /* Global Interrupt Controller */
  114. object_initialize_child(OBJECT(dev), "gic", &s->gic, TYPE_MIPS_GIC);
  115. object_property_set_int(OBJECT(&s->gic), "num-vp", s->num_vp,
  116. &error_abort);
  117. object_property_set_int(OBJECT(&s->gic), "num-irq", 128,
  118. &error_abort);
  119. if (!sysbus_realize(SYS_BUS_DEVICE(&s->gic), errp)) {
  120. return;
  121. }
  122. memory_region_add_subregion(&s->container, 0,
  123. sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->gic), 0));
  124. /* Global Configuration Registers */
  125. gcr_base = env->CP0_CMGCRBase << 4;
  126. object_initialize_child(OBJECT(dev), "gcr", &s->gcr, TYPE_MIPS_GCR);
  127. object_property_set_int(OBJECT(&s->gcr), "num-vp", s->num_vp,
  128. &error_abort);
  129. object_property_set_int(OBJECT(&s->gcr), "gcr-rev", 0x800,
  130. &error_abort);
  131. object_property_set_int(OBJECT(&s->gcr), "gcr-base", gcr_base,
  132. &error_abort);
  133. object_property_set_link(OBJECT(&s->gcr), "gic", OBJECT(&s->gic.mr),
  134. &error_abort);
  135. object_property_set_link(OBJECT(&s->gcr), "cpc", OBJECT(&s->cpc.mr),
  136. &error_abort);
  137. if (!sysbus_realize(SYS_BUS_DEVICE(&s->gcr), errp)) {
  138. return;
  139. }
  140. memory_region_add_subregion(&s->container, gcr_base,
  141. sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->gcr), 0));
  142. }
  143. static Property mips_cps_properties[] = {
  144. DEFINE_PROP_UINT32("num-vp", MIPSCPSState, num_vp, 1),
  145. DEFINE_PROP_UINT32("num-irq", MIPSCPSState, num_irq, 256),
  146. DEFINE_PROP_STRING("cpu-type", MIPSCPSState, cpu_type),
  147. DEFINE_PROP_END_OF_LIST()
  148. };
  149. static void mips_cps_class_init(ObjectClass *klass, void *data)
  150. {
  151. DeviceClass *dc = DEVICE_CLASS(klass);
  152. dc->realize = mips_cps_realize;
  153. device_class_set_props(dc, mips_cps_properties);
  154. }
  155. static const TypeInfo mips_cps_info = {
  156. .name = TYPE_MIPS_CPS,
  157. .parent = TYPE_SYS_BUS_DEVICE,
  158. .instance_size = sizeof(MIPSCPSState),
  159. .instance_init = mips_cps_init,
  160. .class_init = mips_cps_class_init,
  161. };
  162. static void mips_cps_register_types(void)
  163. {
  164. type_register_static(&mips_cps_info);
  165. }
  166. type_init(mips_cps_register_types)