Alistair Francis | 4690bf4 | 2018-01-22 11:43:20 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Xilinx Zynq MPSoC PMU (Power Management Unit) emulation |
| 3 | * |
| 4 | * Copyright (C) 2017 Xilinx Inc |
| 5 | * Written by Alistair Francis <alistair.francis@xilinx.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the |
| 9 | * Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 15 | * for more details. |
| 16 | */ |
| 17 | |
| 18 | #include "qemu/osdep.h" |
| 19 | #include "qapi/error.h" |
Alistair Francis | 133d23b | 2018-01-22 11:43:25 -0800 | [diff] [blame] | 20 | #include "exec/address-spaces.h" |
Alistair Francis | 4690bf4 | 2018-01-22 11:43:20 -0800 | [diff] [blame] | 21 | #include "hw/boards.h" |
| 22 | #include "cpu.h" |
Alistair Francis | 133d23b | 2018-01-22 11:43:25 -0800 | [diff] [blame] | 23 | #include "boot.h" |
Alistair Francis | 4690bf4 | 2018-01-22 11:43:20 -0800 | [diff] [blame] | 24 | |
Alistair Francis | 07b3020 | 2018-01-22 11:43:48 -0800 | [diff] [blame] | 25 | #include "hw/intc/xlnx-zynqmp-ipi.h" |
Alistair Francis | 633a91b | 2018-01-22 11:43:38 -0800 | [diff] [blame] | 26 | #include "hw/intc/xlnx-pmu-iomod-intc.h" |
Eduardo Habkost | db1015e | 2020-09-03 16:43:22 -0400 | [diff] [blame] | 27 | #include "qom/object.h" |
Alistair Francis | 633a91b | 2018-01-22 11:43:38 -0800 | [diff] [blame] | 28 | |
Alistair Francis | 4690bf4 | 2018-01-22 11:43:20 -0800 | [diff] [blame] | 29 | /* Define the PMU device */ |
| 30 | |
Markus Armbruster | e178113 | 2021-03-04 15:02:28 +0100 | [diff] [blame] | 31 | #define TYPE_XLNX_ZYNQMP_PMU_SOC "xlnx-zynqmp-pmu-soc" |
Eduardo Habkost | 8063396 | 2020-09-16 14:25:19 -0400 | [diff] [blame] | 32 | OBJECT_DECLARE_SIMPLE_TYPE(XlnxZynqMPPMUSoCState, XLNX_ZYNQMP_PMU_SOC) |
Alistair Francis | 4690bf4 | 2018-01-22 11:43:20 -0800 | [diff] [blame] | 33 | |
Alistair Francis | 133d23b | 2018-01-22 11:43:25 -0800 | [diff] [blame] | 34 | #define XLNX_ZYNQMP_PMU_ROM_SIZE 0x8000 |
| 35 | #define XLNX_ZYNQMP_PMU_ROM_ADDR 0xFFD00000 |
| 36 | #define XLNX_ZYNQMP_PMU_RAM_ADDR 0xFFDC0000 |
| 37 | |
Alistair Francis | 633a91b | 2018-01-22 11:43:38 -0800 | [diff] [blame] | 38 | #define XLNX_ZYNQMP_PMU_INTC_ADDR 0xFFD40000 |
| 39 | |
Alistair Francis | 07b3020 | 2018-01-22 11:43:48 -0800 | [diff] [blame] | 40 | #define XLNX_ZYNQMP_PMU_NUM_IPIS 4 |
| 41 | |
| 42 | static const uint64_t ipi_addr[XLNX_ZYNQMP_PMU_NUM_IPIS] = { |
| 43 | 0xFF340000, 0xFF350000, 0xFF360000, 0xFF370000, |
| 44 | }; |
| 45 | static const uint64_t ipi_irq[XLNX_ZYNQMP_PMU_NUM_IPIS] = { |
| 46 | 19, 20, 21, 22, |
| 47 | }; |
| 48 | |
Eduardo Habkost | db1015e | 2020-09-03 16:43:22 -0400 | [diff] [blame] | 49 | struct XlnxZynqMPPMUSoCState { |
Alistair Francis | 4690bf4 | 2018-01-22 11:43:20 -0800 | [diff] [blame] | 50 | /*< private >*/ |
| 51 | DeviceState parent_obj; |
| 52 | |
| 53 | /*< public >*/ |
Alistair Francis | 133d23b | 2018-01-22 11:43:25 -0800 | [diff] [blame] | 54 | MicroBlazeCPU cpu; |
Alistair Francis | 633a91b | 2018-01-22 11:43:38 -0800 | [diff] [blame] | 55 | XlnxPMUIOIntc intc; |
Philippe Mathieu-Daudé | a8ae92e | 2019-05-07 18:34:11 +0200 | [diff] [blame] | 56 | XlnxZynqMPIPI ipi[XLNX_ZYNQMP_PMU_NUM_IPIS]; |
Eduardo Habkost | db1015e | 2020-09-03 16:43:22 -0400 | [diff] [blame] | 57 | }; |
Alistair Francis | 4690bf4 | 2018-01-22 11:43:20 -0800 | [diff] [blame] | 58 | |
Alistair Francis | 633a91b | 2018-01-22 11:43:38 -0800 | [diff] [blame] | 59 | |
Alistair Francis | 4690bf4 | 2018-01-22 11:43:20 -0800 | [diff] [blame] | 60 | static void xlnx_zynqmp_pmu_soc_init(Object *obj) |
| 61 | { |
Alistair Francis | 133d23b | 2018-01-22 11:43:25 -0800 | [diff] [blame] | 62 | XlnxZynqMPPMUSoCState *s = XLNX_ZYNQMP_PMU_SOC(obj); |
Alistair Francis | 4690bf4 | 2018-01-22 11:43:20 -0800 | [diff] [blame] | 63 | |
Markus Armbruster | 9fc7fc4 | 2020-06-10 07:32:25 +0200 | [diff] [blame] | 64 | object_initialize_child(obj, "pmu-cpu", &s->cpu, TYPE_MICROBLAZE_CPU); |
Alistair Francis | 633a91b | 2018-01-22 11:43:38 -0800 | [diff] [blame] | 65 | |
Markus Armbruster | db873cc | 2020-06-10 07:32:37 +0200 | [diff] [blame] | 66 | object_initialize_child(obj, "intc", &s->intc, TYPE_XLNX_PMU_IO_INTC); |
Philippe Mathieu-Daudé | da4aeff | 2019-05-07 18:34:12 +0200 | [diff] [blame] | 67 | |
| 68 | /* Create the IPI device */ |
| 69 | for (int i = 0; i < XLNX_ZYNQMP_PMU_NUM_IPIS; i++) { |
Philippe Mathieu-Daudé | ff5d4dc | 2019-05-07 18:34:13 +0200 | [diff] [blame] | 70 | char *name = g_strdup_printf("ipi%d", i); |
Markus Armbruster | db873cc | 2020-06-10 07:32:37 +0200 | [diff] [blame] | 71 | object_initialize_child(obj, name, &s->ipi[i], TYPE_XLNX_ZYNQMP_IPI); |
Philippe Mathieu-Daudé | ff5d4dc | 2019-05-07 18:34:13 +0200 | [diff] [blame] | 72 | g_free(name); |
Philippe Mathieu-Daudé | da4aeff | 2019-05-07 18:34:12 +0200 | [diff] [blame] | 73 | } |
Alistair Francis | 4690bf4 | 2018-01-22 11:43:20 -0800 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | static void xlnx_zynqmp_pmu_soc_realize(DeviceState *dev, Error **errp) |
| 77 | { |
Alistair Francis | 133d23b | 2018-01-22 11:43:25 -0800 | [diff] [blame] | 78 | XlnxZynqMPPMUSoCState *s = XLNX_ZYNQMP_PMU_SOC(dev); |
Alistair Francis | 4690bf4 | 2018-01-22 11:43:20 -0800 | [diff] [blame] | 79 | |
Markus Armbruster | 5325cc3 | 2020-07-07 18:05:54 +0200 | [diff] [blame] | 80 | object_property_set_uint(OBJECT(&s->cpu), "base-vectors", |
| 81 | XLNX_ZYNQMP_PMU_ROM_ADDR, &error_abort); |
| 82 | object_property_set_bool(OBJECT(&s->cpu), "use-stack-protection", true, |
Alistair Francis | 133d23b | 2018-01-22 11:43:25 -0800 | [diff] [blame] | 83 | &error_abort); |
Markus Armbruster | 5325cc3 | 2020-07-07 18:05:54 +0200 | [diff] [blame] | 84 | object_property_set_uint(OBJECT(&s->cpu), "use-fpu", 0, &error_abort); |
| 85 | object_property_set_uint(OBJECT(&s->cpu), "use-hw-mul", 0, &error_abort); |
| 86 | object_property_set_bool(OBJECT(&s->cpu), "use-barrel", true, |
Alistair Francis | 133d23b | 2018-01-22 11:43:25 -0800 | [diff] [blame] | 87 | &error_abort); |
Markus Armbruster | 5325cc3 | 2020-07-07 18:05:54 +0200 | [diff] [blame] | 88 | object_property_set_bool(OBJECT(&s->cpu), "use-msr-instr", true, |
Alistair Francis | 133d23b | 2018-01-22 11:43:25 -0800 | [diff] [blame] | 89 | &error_abort); |
Markus Armbruster | 5325cc3 | 2020-07-07 18:05:54 +0200 | [diff] [blame] | 90 | object_property_set_bool(OBJECT(&s->cpu), "use-pcmp-instr", true, |
Alistair Francis | 133d23b | 2018-01-22 11:43:25 -0800 | [diff] [blame] | 91 | &error_abort); |
Markus Armbruster | 5325cc3 | 2020-07-07 18:05:54 +0200 | [diff] [blame] | 92 | object_property_set_bool(OBJECT(&s->cpu), "use-mmu", false, &error_abort); |
| 93 | object_property_set_bool(OBJECT(&s->cpu), "endianness", true, |
Alistair Francis | 133d23b | 2018-01-22 11:43:25 -0800 | [diff] [blame] | 94 | &error_abort); |
Markus Armbruster | 5325cc3 | 2020-07-07 18:05:54 +0200 | [diff] [blame] | 95 | object_property_set_str(OBJECT(&s->cpu), "version", "8.40.b", |
Alistair Francis | 133d23b | 2018-01-22 11:43:25 -0800 | [diff] [blame] | 96 | &error_abort); |
Markus Armbruster | 5325cc3 | 2020-07-07 18:05:54 +0200 | [diff] [blame] | 97 | object_property_set_uint(OBJECT(&s->cpu), "pvr", 0, &error_abort); |
Markus Armbruster | 668f62e | 2020-07-07 18:06:02 +0200 | [diff] [blame] | 98 | if (!qdev_realize(DEVICE(&s->cpu), NULL, errp)) { |
Alistair Francis | 133d23b | 2018-01-22 11:43:25 -0800 | [diff] [blame] | 99 | return; |
| 100 | } |
Alistair Francis | 633a91b | 2018-01-22 11:43:38 -0800 | [diff] [blame] | 101 | |
Markus Armbruster | 5325cc3 | 2020-07-07 18:05:54 +0200 | [diff] [blame] | 102 | object_property_set_uint(OBJECT(&s->intc), "intc-intr-size", 0x10, |
Alistair Francis | 633a91b | 2018-01-22 11:43:38 -0800 | [diff] [blame] | 103 | &error_abort); |
Markus Armbruster | 5325cc3 | 2020-07-07 18:05:54 +0200 | [diff] [blame] | 104 | object_property_set_uint(OBJECT(&s->intc), "intc-level-edge", 0x0, |
Alistair Francis | 633a91b | 2018-01-22 11:43:38 -0800 | [diff] [blame] | 105 | &error_abort); |
Markus Armbruster | 5325cc3 | 2020-07-07 18:05:54 +0200 | [diff] [blame] | 106 | object_property_set_uint(OBJECT(&s->intc), "intc-positive", 0xffff, |
Alistair Francis | 633a91b | 2018-01-22 11:43:38 -0800 | [diff] [blame] | 107 | &error_abort); |
Markus Armbruster | 668f62e | 2020-07-07 18:06:02 +0200 | [diff] [blame] | 108 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->intc), errp)) { |
Alistair Francis | 633a91b | 2018-01-22 11:43:38 -0800 | [diff] [blame] | 109 | return; |
| 110 | } |
| 111 | sysbus_mmio_map(SYS_BUS_DEVICE(&s->intc), 0, XLNX_ZYNQMP_PMU_INTC_ADDR); |
| 112 | sysbus_connect_irq(SYS_BUS_DEVICE(&s->intc), 0, |
| 113 | qdev_get_gpio_in(DEVICE(&s->cpu), MB_CPU_IRQ)); |
Philippe Mathieu-Daudé | da4aeff | 2019-05-07 18:34:12 +0200 | [diff] [blame] | 114 | |
| 115 | /* Connect the IPI device */ |
| 116 | for (int i = 0; i < XLNX_ZYNQMP_PMU_NUM_IPIS; i++) { |
Markus Armbruster | db873cc | 2020-06-10 07:32:37 +0200 | [diff] [blame] | 117 | sysbus_realize(SYS_BUS_DEVICE(&s->ipi[i]), &error_abort); |
Philippe Mathieu-Daudé | da4aeff | 2019-05-07 18:34:12 +0200 | [diff] [blame] | 118 | sysbus_mmio_map(SYS_BUS_DEVICE(&s->ipi[i]), 0, ipi_addr[i]); |
| 119 | sysbus_connect_irq(SYS_BUS_DEVICE(&s->ipi[i]), 0, |
| 120 | qdev_get_gpio_in(DEVICE(&s->intc), ipi_irq[i])); |
| 121 | } |
Alistair Francis | 4690bf4 | 2018-01-22 11:43:20 -0800 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | static void xlnx_zynqmp_pmu_soc_class_init(ObjectClass *oc, void *data) |
| 125 | { |
| 126 | DeviceClass *dc = DEVICE_CLASS(oc); |
| 127 | |
Thomas Huth | ed355dc | 2024-03-22 19:31:53 +0100 | [diff] [blame] | 128 | /* xlnx-zynqmp-pmu-soc causes crashes when cold-plugged twice */ |
| 129 | dc->user_creatable = false; |
Alistair Francis | 4690bf4 | 2018-01-22 11:43:20 -0800 | [diff] [blame] | 130 | dc->realize = xlnx_zynqmp_pmu_soc_realize; |
| 131 | } |
| 132 | |
| 133 | static const TypeInfo xlnx_zynqmp_pmu_soc_type_info = { |
| 134 | .name = TYPE_XLNX_ZYNQMP_PMU_SOC, |
| 135 | .parent = TYPE_DEVICE, |
| 136 | .instance_size = sizeof(XlnxZynqMPPMUSoCState), |
| 137 | .instance_init = xlnx_zynqmp_pmu_soc_init, |
| 138 | .class_init = xlnx_zynqmp_pmu_soc_class_init, |
| 139 | }; |
| 140 | |
| 141 | static void xlnx_zynqmp_pmu_soc_register_types(void) |
| 142 | { |
| 143 | type_register_static(&xlnx_zynqmp_pmu_soc_type_info); |
| 144 | } |
| 145 | |
| 146 | type_init(xlnx_zynqmp_pmu_soc_register_types) |
| 147 | |
| 148 | /* Define the PMU Machine */ |
| 149 | |
| 150 | static void xlnx_zynqmp_pmu_init(MachineState *machine) |
| 151 | { |
Alistair Francis | 133d23b | 2018-01-22 11:43:25 -0800 | [diff] [blame] | 152 | XlnxZynqMPPMUSoCState *pmu = g_new0(XlnxZynqMPPMUSoCState, 1); |
| 153 | MemoryRegion *address_space_mem = get_system_memory(); |
| 154 | MemoryRegion *pmu_rom = g_new(MemoryRegion, 1); |
| 155 | MemoryRegion *pmu_ram = g_new(MemoryRegion, 1); |
Alistair Francis | 4690bf4 | 2018-01-22 11:43:20 -0800 | [diff] [blame] | 156 | |
Alistair Francis | 133d23b | 2018-01-22 11:43:25 -0800 | [diff] [blame] | 157 | /* Create the ROM */ |
| 158 | memory_region_init_rom(pmu_rom, NULL, "xlnx-zynqmp-pmu.rom", |
| 159 | XLNX_ZYNQMP_PMU_ROM_SIZE, &error_fatal); |
| 160 | memory_region_add_subregion(address_space_mem, XLNX_ZYNQMP_PMU_ROM_ADDR, |
| 161 | pmu_rom); |
| 162 | |
| 163 | /* Create the RAM */ |
| 164 | memory_region_init_ram(pmu_ram, NULL, "xlnx-zynqmp-pmu.ram", |
| 165 | machine->ram_size, &error_fatal); |
| 166 | memory_region_add_subregion(address_space_mem, XLNX_ZYNQMP_PMU_RAM_ADDR, |
| 167 | pmu_ram); |
| 168 | |
| 169 | /* Create the PMU device */ |
Markus Armbruster | 9fc7fc4 | 2020-06-10 07:32:25 +0200 | [diff] [blame] | 170 | object_initialize_child(OBJECT(machine), "pmu", pmu, |
| 171 | TYPE_XLNX_ZYNQMP_PMU_SOC); |
Markus Armbruster | ce189ab | 2020-06-10 07:32:45 +0200 | [diff] [blame] | 172 | qdev_realize(DEVICE(pmu), NULL, &error_fatal); |
Alistair Francis | 133d23b | 2018-01-22 11:43:25 -0800 | [diff] [blame] | 173 | |
| 174 | /* Load the kernel */ |
| 175 | microblaze_load_kernel(&pmu->cpu, XLNX_ZYNQMP_PMU_RAM_ADDR, |
| 176 | machine->ram_size, |
| 177 | machine->initrd_filename, |
| 178 | machine->dtb, |
| 179 | NULL); |
Alistair Francis | 4690bf4 | 2018-01-22 11:43:20 -0800 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | static void xlnx_zynqmp_pmu_machine_init(MachineClass *mc) |
| 183 | { |
| 184 | mc->desc = "Xilinx ZynqMP PMU machine"; |
| 185 | mc->init = xlnx_zynqmp_pmu_init; |
| 186 | } |
| 187 | |
| 188 | DEFINE_MACHINE("xlnx-zynqmp-pmu", xlnx_zynqmp_pmu_machine_init) |
| 189 | |