cps.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. Error *err = NULL;
  65. target_ulong gcr_base;
  66. bool itu_present = false;
  67. bool saar_present = false;
  68. for (i = 0; i < s->num_vp; i++) {
  69. cpu = MIPS_CPU(cpu_create(s->cpu_type));
  70. /* Init internal devices */
  71. cpu_mips_irq_init_cpu(cpu);
  72. cpu_mips_clock_init(cpu);
  73. env = &cpu->env;
  74. if (cpu_mips_itu_supported(env)) {
  75. itu_present = true;
  76. /* Attach ITC Tag to the VP */
  77. env->itc_tag = mips_itu_get_tag_region(&s->itu);
  78. env->itu = &s->itu;
  79. }
  80. qemu_register_reset(main_cpu_reset, cpu);
  81. }
  82. cpu = MIPS_CPU(first_cpu);
  83. env = &cpu->env;
  84. saar_present = (bool)env->saarp;
  85. /* Inter-Thread Communication Unit */
  86. if (itu_present) {
  87. sysbus_init_child_obj(OBJECT(dev), "itu", &s->itu, sizeof(s->itu),
  88. TYPE_MIPS_ITU);
  89. object_property_set_int(OBJECT(&s->itu), 16, "num-fifo", &err);
  90. object_property_set_int(OBJECT(&s->itu), 16, "num-semaphores", &err);
  91. object_property_set_bool(OBJECT(&s->itu), saar_present, "saar-present",
  92. &err);
  93. if (saar_present) {
  94. qdev_prop_set_ptr(DEVICE(&s->itu), "saar", (void *)&env->CP0_SAAR);
  95. }
  96. object_property_set_bool(OBJECT(&s->itu), true, "realized", &err);
  97. if (err != NULL) {
  98. error_propagate(errp, err);
  99. return;
  100. }
  101. memory_region_add_subregion(&s->container, 0,
  102. sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->itu), 0));
  103. }
  104. /* Cluster Power Controller */
  105. sysbus_init_child_obj(OBJECT(dev), "cpc", &s->cpc, sizeof(s->cpc),
  106. TYPE_MIPS_CPC);
  107. object_property_set_int(OBJECT(&s->cpc), s->num_vp, "num-vp", &err);
  108. object_property_set_int(OBJECT(&s->cpc), 1, "vp-start-running", &err);
  109. object_property_set_bool(OBJECT(&s->cpc), true, "realized", &err);
  110. if (err != NULL) {
  111. error_propagate(errp, err);
  112. return;
  113. }
  114. memory_region_add_subregion(&s->container, 0,
  115. sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->cpc), 0));
  116. /* Global Interrupt Controller */
  117. sysbus_init_child_obj(OBJECT(dev), "gic", &s->gic, sizeof(s->gic),
  118. TYPE_MIPS_GIC);
  119. object_property_set_int(OBJECT(&s->gic), s->num_vp, "num-vp", &err);
  120. object_property_set_int(OBJECT(&s->gic), 128, "num-irq", &err);
  121. object_property_set_bool(OBJECT(&s->gic), true, "realized", &err);
  122. if (err != NULL) {
  123. error_propagate(errp, err);
  124. return;
  125. }
  126. memory_region_add_subregion(&s->container, 0,
  127. sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->gic), 0));
  128. /* Global Configuration Registers */
  129. gcr_base = env->CP0_CMGCRBase << 4;
  130. sysbus_init_child_obj(OBJECT(dev), "gcr", &s->gcr, sizeof(s->gcr),
  131. TYPE_MIPS_GCR);
  132. object_property_set_int(OBJECT(&s->gcr), s->num_vp, "num-vp", &err);
  133. object_property_set_int(OBJECT(&s->gcr), 0x800, "gcr-rev", &err);
  134. object_property_set_int(OBJECT(&s->gcr), gcr_base, "gcr-base", &err);
  135. object_property_set_link(OBJECT(&s->gcr), OBJECT(&s->gic.mr), "gic", &err);
  136. object_property_set_link(OBJECT(&s->gcr), OBJECT(&s->cpc.mr), "cpc", &err);
  137. object_property_set_bool(OBJECT(&s->gcr), true, "realized", &err);
  138. if (err != NULL) {
  139. error_propagate(errp, err);
  140. return;
  141. }
  142. memory_region_add_subregion(&s->container, gcr_base,
  143. sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->gcr), 0));
  144. }
  145. static Property mips_cps_properties[] = {
  146. DEFINE_PROP_UINT32("num-vp", MIPSCPSState, num_vp, 1),
  147. DEFINE_PROP_UINT32("num-irq", MIPSCPSState, num_irq, 256),
  148. DEFINE_PROP_STRING("cpu-type", MIPSCPSState, cpu_type),
  149. DEFINE_PROP_END_OF_LIST()
  150. };
  151. static void mips_cps_class_init(ObjectClass *klass, void *data)
  152. {
  153. DeviceClass *dc = DEVICE_CLASS(klass);
  154. dc->realize = mips_cps_realize;
  155. dc->props = mips_cps_properties;
  156. }
  157. static const TypeInfo mips_cps_info = {
  158. .name = TYPE_MIPS_CPS,
  159. .parent = TYPE_SYS_BUS_DEVICE,
  160. .instance_size = sizeof(MIPSCPSState),
  161. .instance_init = mips_cps_init,
  162. .class_init = mips_cps_class_init,
  163. };
  164. static void mips_cps_register_types(void)
  165. {
  166. type_register_static(&mips_cps_info);
  167. }
  168. type_init(mips_cps_register_types)