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 20 #include "qemu/osdep.h" 21 #include "qapi/error.h" 22 #include "hw/mips/cps.h" 23 #include "hw/mips/mips.h" 24 #include "hw/mips/cpudevs.h" 25 26 qemu_irq get_cps_irq(MIPSCPSState *s, int pin_number) 27 { 28 MIPSCPU *cpu = MIPS_CPU(first_cpu); 29 CPUMIPSState *env = &cpu->env; 30 31 assert(pin_number < s->num_irq); 32 33 /* TODO: return GIC pins once implemented */ 34 return env->irq[pin_number]; 35 } 36 37 static void mips_cps_init(Object *obj) 38 { 39 SysBusDevice *sbd = SYS_BUS_DEVICE(obj); 40 MIPSCPSState *s = MIPS_CPS(obj); 41 42 /* Cover entire address space as there do not seem to be any 43 * constraints for the base address of CPC and GIC. */ 44 memory_region_init(&s->container, obj, "mips-cps-container", UINT64_MAX); 45 sysbus_init_mmio(sbd, &s->container); 46 } 47 48 static void main_cpu_reset(void *opaque) 49 { 50 MIPSCPU *cpu = opaque; 51 CPUState *cs = CPU(cpu); 52 53 cpu_reset(cs); 54 55 /* All VPs are halted on reset. Leave powering up to CPC. */ 56 cs->halted = 1; 57 } 58 59 static void mips_cps_realize(DeviceState *dev, Error **errp) 60 { 61 MIPSCPSState *s = MIPS_CPS(dev); 62 CPUMIPSState *env; 63 MIPSCPU *cpu; 64 int i; 65 Error *err = NULL; 66 target_ulong gcr_base; 67 68 for (i = 0; i < s->num_vp; i++) { 69 cpu = cpu_mips_init(s->cpu_model); 70 if (cpu == NULL) { 71 error_setg(errp, "%s: CPU initialization failed\n", __func__); 72 return; 73 } 74 env = &cpu->env; 75 76 /* Init internal devices */ 77 cpu_mips_irq_init_cpu(env); 78 cpu_mips_clock_init(env); 79 qemu_register_reset(main_cpu_reset, cpu); 80 } 81 82 cpu = MIPS_CPU(first_cpu); 83 env = &cpu->env; 84 85 /* Cluster Power Controller */ 86 object_initialize(&s->cpc, sizeof(s->cpc), TYPE_MIPS_CPC); 87 qdev_set_parent_bus(DEVICE(&s->cpc), sysbus_get_default()); 88 89 object_property_set_int(OBJECT(&s->cpc), s->num_vp, "num-vp", &err); 90 object_property_set_int(OBJECT(&s->cpc), 1, "vp-start-running", &err); 91 object_property_set_bool(OBJECT(&s->cpc), true, "realized", &err); 92 if (err != NULL) { 93 error_propagate(errp, err); 94 return; 95 } 96 97 memory_region_add_subregion(&s->container, 0, 98 sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->cpc), 0)); 99 100 /* Global Configuration Registers */ 101 gcr_base = env->CP0_CMGCRBase << 4; 102 103 object_initialize(&s->gcr, sizeof(s->gcr), TYPE_MIPS_GCR); 104 qdev_set_parent_bus(DEVICE(&s->gcr), sysbus_get_default()); 105 106 object_property_set_int(OBJECT(&s->gcr), s->num_vp, "num-vp", &err); 107 object_property_set_int(OBJECT(&s->gcr), 0x800, "gcr-rev", &err); 108 object_property_set_int(OBJECT(&s->gcr), gcr_base, "gcr-base", &err); 109 object_property_set_link(OBJECT(&s->gcr), OBJECT(&s->cpc.mr), "cpc", &err); 110 object_property_set_bool(OBJECT(&s->gcr), true, "realized", &err); 111 if (err != NULL) { 112 error_propagate(errp, err); 113 return; 114 } 115 116 memory_region_add_subregion(&s->container, gcr_base, 117 sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->gcr), 0)); 118 } 119 120 static Property mips_cps_properties[] = { 121 DEFINE_PROP_UINT32("num-vp", MIPSCPSState, num_vp, 1), 122 DEFINE_PROP_UINT32("num-irq", MIPSCPSState, num_irq, 8), 123 DEFINE_PROP_STRING("cpu-model", MIPSCPSState, cpu_model), 124 DEFINE_PROP_END_OF_LIST() 125 }; 126 127 static void mips_cps_class_init(ObjectClass *klass, void *data) 128 { 129 DeviceClass *dc = DEVICE_CLASS(klass); 130 131 dc->realize = mips_cps_realize; 132 dc->props = mips_cps_properties; 133 } 134 135 static const TypeInfo mips_cps_info = { 136 .name = TYPE_MIPS_CPS, 137 .parent = TYPE_SYS_BUS_DEVICE, 138 .instance_size = sizeof(MIPSCPSState), 139 .instance_init = mips_cps_init, 140 .class_init = mips_cps_class_init, 141 }; 142 143 static void mips_cps_register_types(void) 144 { 145 type_register_static(&mips_cps_info); 146 } 147 148 type_init(mips_cps_register_types) 149