]>
Commit | Line | Data |
---|---|---|
9e933f4a BH |
1 | /* |
2 | * QEMU PowerPC PowerNV machine model | |
3 | * | |
4 | * Copyright (c) 2016, IBM Corporation. | |
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" | |
a8d25326 | 21 | #include "qemu-common.h" |
fc6b3cf9 | 22 | #include "qemu/units.h" |
9e933f4a BH |
23 | #include "qapi/error.h" |
24 | #include "sysemu/sysemu.h" | |
25 | #include "sysemu/numa.h" | |
71e8a915 | 26 | #include "sysemu/reset.h" |
54d31236 | 27 | #include "sysemu/runstate.h" |
d2528bdc | 28 | #include "sysemu/cpus.h" |
8d409261 | 29 | #include "sysemu/device_tree.h" |
fcf5ef2a | 30 | #include "target/ppc/cpu.h" |
9e933f4a BH |
31 | #include "qemu/log.h" |
32 | #include "hw/ppc/fdt.h" | |
33 | #include "hw/ppc/ppc.h" | |
34 | #include "hw/ppc/pnv.h" | |
d2fd9612 | 35 | #include "hw/ppc/pnv_core.h" |
9e933f4a BH |
36 | #include "hw/loader.h" |
37 | #include "exec/address-spaces.h" | |
e997040e | 38 | #include "qapi/visitor.h" |
47fea43a CLG |
39 | #include "monitor/monitor.h" |
40 | #include "hw/intc/intc.h" | |
aeaef83d | 41 | #include "hw/ipmi/ipmi.h" |
58969eee | 42 | #include "target/ppc/mmu-hash64.h" |
9e933f4a | 43 | |
36fc6f08 | 44 | #include "hw/ppc/xics.h" |
a27bd6c7 | 45 | #include "hw/qdev-properties.h" |
967b7523 CLG |
46 | #include "hw/ppc/pnv_xscom.h" |
47 | ||
3495b6b6 | 48 | #include "hw/isa/isa.h" |
12e9493d | 49 | #include "hw/boards.h" |
3495b6b6 CLG |
50 | #include "hw/char/serial.h" |
51 | #include "hw/timer/mc146818rtc.h" | |
52 | ||
9e933f4a BH |
53 | #include <libfdt.h> |
54 | ||
b268a616 | 55 | #define FDT_MAX_SIZE (1 * MiB) |
9e933f4a BH |
56 | |
57 | #define FW_FILE_NAME "skiboot.lid" | |
58 | #define FW_LOAD_ADDR 0x0 | |
b268a616 | 59 | #define FW_MAX_SIZE (4 * MiB) |
9e933f4a BH |
60 | |
61 | #define KERNEL_LOAD_ADDR 0x20000000 | |
b45b56ba | 62 | #define KERNEL_MAX_SIZE (256 * MiB) |
fef592f9 | 63 | #define INITRD_LOAD_ADDR 0x60000000 |
584ea7e7 | 64 | #define INITRD_MAX_SIZE (256 * MiB) |
9e933f4a | 65 | |
40abf43f IM |
66 | static const char *pnv_chip_core_typename(const PnvChip *o) |
67 | { | |
68 | const char *chip_type = object_class_get_name(object_get_class(OBJECT(o))); | |
69 | int len = strlen(chip_type) - strlen(PNV_CHIP_TYPE_SUFFIX); | |
70 | char *s = g_strdup_printf(PNV_CORE_TYPE_NAME("%.*s"), len, chip_type); | |
71 | const char *core_type = object_class_get_name(object_class_by_name(s)); | |
72 | g_free(s); | |
73 | return core_type; | |
74 | } | |
75 | ||
9e933f4a BH |
76 | /* |
77 | * On Power Systems E880 (POWER8), the max cpus (threads) should be : | |
78 | * 4 * 4 sockets * 12 cores * 8 threads = 1536 | |
79 | * Let's make it 2^11 | |
80 | */ | |
81 | #define MAX_CPUS 2048 | |
82 | ||
83 | /* | |
84 | * Memory nodes are created by hostboot, one for each range of memory | |
85 | * that has a different "affinity". In practice, it means one range | |
86 | * per chip. | |
87 | */ | |
b168a138 | 88 | static void pnv_dt_memory(void *fdt, int chip_id, hwaddr start, hwaddr size) |
9e933f4a BH |
89 | { |
90 | char *mem_name; | |
91 | uint64_t mem_reg_property[2]; | |
92 | int off; | |
93 | ||
94 | mem_reg_property[0] = cpu_to_be64(start); | |
95 | mem_reg_property[1] = cpu_to_be64(size); | |
96 | ||
97 | mem_name = g_strdup_printf("memory@%"HWADDR_PRIx, start); | |
98 | off = fdt_add_subnode(fdt, 0, mem_name); | |
99 | g_free(mem_name); | |
100 | ||
101 | _FDT((fdt_setprop_string(fdt, off, "device_type", "memory"))); | |
102 | _FDT((fdt_setprop(fdt, off, "reg", mem_reg_property, | |
103 | sizeof(mem_reg_property)))); | |
104 | _FDT((fdt_setprop_cell(fdt, off, "ibm,chip-id", chip_id))); | |
105 | } | |
106 | ||
d2fd9612 CLG |
107 | static int get_cpus_node(void *fdt) |
108 | { | |
109 | int cpus_offset = fdt_path_offset(fdt, "/cpus"); | |
110 | ||
111 | if (cpus_offset < 0) { | |
a4f3885c | 112 | cpus_offset = fdt_add_subnode(fdt, 0, "cpus"); |
d2fd9612 CLG |
113 | if (cpus_offset) { |
114 | _FDT((fdt_setprop_cell(fdt, cpus_offset, "#address-cells", 0x1))); | |
115 | _FDT((fdt_setprop_cell(fdt, cpus_offset, "#size-cells", 0x0))); | |
116 | } | |
117 | } | |
118 | _FDT(cpus_offset); | |
119 | return cpus_offset; | |
120 | } | |
121 | ||
122 | /* | |
123 | * The PowerNV cores (and threads) need to use real HW ids and not an | |
124 | * incremental index like it has been done on other platforms. This HW | |
125 | * id is stored in the CPU PIR, it is used to create cpu nodes in the | |
126 | * device tree, used in XSCOM to address cores and in interrupt | |
127 | * servers. | |
128 | */ | |
b168a138 | 129 | static void pnv_dt_core(PnvChip *chip, PnvCore *pc, void *fdt) |
d2fd9612 | 130 | { |
08304a86 DG |
131 | PowerPCCPU *cpu = pc->threads[0]; |
132 | CPUState *cs = CPU(cpu); | |
d2fd9612 | 133 | DeviceClass *dc = DEVICE_GET_CLASS(cs); |
8bd9530e | 134 | int smt_threads = CPU_CORE(pc)->nr_threads; |
d2fd9612 CLG |
135 | CPUPPCState *env = &cpu->env; |
136 | PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cs); | |
137 | uint32_t servers_prop[smt_threads]; | |
138 | int i; | |
139 | uint32_t segs[] = {cpu_to_be32(28), cpu_to_be32(40), | |
140 | 0xffffffff, 0xffffffff}; | |
141 | uint32_t tbfreq = PNV_TIMEBASE_FREQ; | |
142 | uint32_t cpufreq = 1000000000; | |
143 | uint32_t page_sizes_prop[64]; | |
144 | size_t page_sizes_prop_size; | |
145 | const uint8_t pa_features[] = { 24, 0, | |
146 | 0xf6, 0x3f, 0xc7, 0xc0, 0x80, 0xf0, | |
147 | 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, | |
148 | 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, | |
149 | 0x80, 0x00, 0x80, 0x00, 0x80, 0x00 }; | |
150 | int offset; | |
151 | char *nodename; | |
152 | int cpus_offset = get_cpus_node(fdt); | |
153 | ||
154 | nodename = g_strdup_printf("%s@%x", dc->fw_name, pc->pir); | |
155 | offset = fdt_add_subnode(fdt, cpus_offset, nodename); | |
156 | _FDT(offset); | |
157 | g_free(nodename); | |
158 | ||
159 | _FDT((fdt_setprop_cell(fdt, offset, "ibm,chip-id", chip->chip_id))); | |
160 | ||
161 | _FDT((fdt_setprop_cell(fdt, offset, "reg", pc->pir))); | |
162 | _FDT((fdt_setprop_cell(fdt, offset, "ibm,pir", pc->pir))); | |
163 | _FDT((fdt_setprop_string(fdt, offset, "device_type", "cpu"))); | |
164 | ||
165 | _FDT((fdt_setprop_cell(fdt, offset, "cpu-version", env->spr[SPR_PVR]))); | |
166 | _FDT((fdt_setprop_cell(fdt, offset, "d-cache-block-size", | |
167 | env->dcache_line_size))); | |
168 | _FDT((fdt_setprop_cell(fdt, offset, "d-cache-line-size", | |
169 | env->dcache_line_size))); | |
170 | _FDT((fdt_setprop_cell(fdt, offset, "i-cache-block-size", | |
171 | env->icache_line_size))); | |
172 | _FDT((fdt_setprop_cell(fdt, offset, "i-cache-line-size", | |
173 | env->icache_line_size))); | |
174 | ||
175 | if (pcc->l1_dcache_size) { | |
176 | _FDT((fdt_setprop_cell(fdt, offset, "d-cache-size", | |
177 | pcc->l1_dcache_size))); | |
178 | } else { | |
3dc6f869 | 179 | warn_report("Unknown L1 dcache size for cpu"); |
d2fd9612 CLG |
180 | } |
181 | if (pcc->l1_icache_size) { | |
182 | _FDT((fdt_setprop_cell(fdt, offset, "i-cache-size", | |
183 | pcc->l1_icache_size))); | |
184 | } else { | |
3dc6f869 | 185 | warn_report("Unknown L1 icache size for cpu"); |
d2fd9612 CLG |
186 | } |
187 | ||
188 | _FDT((fdt_setprop_cell(fdt, offset, "timebase-frequency", tbfreq))); | |
189 | _FDT((fdt_setprop_cell(fdt, offset, "clock-frequency", cpufreq))); | |
59b7c1c2 B |
190 | _FDT((fdt_setprop_cell(fdt, offset, "ibm,slb-size", |
191 | cpu->hash64_opts->slb_size))); | |
d2fd9612 CLG |
192 | _FDT((fdt_setprop_string(fdt, offset, "status", "okay"))); |
193 | _FDT((fdt_setprop(fdt, offset, "64-bit", NULL, 0))); | |
194 | ||
195 | if (env->spr_cb[SPR_PURR].oea_read) { | |
196 | _FDT((fdt_setprop(fdt, offset, "ibm,purr", NULL, 0))); | |
197 | } | |
198 | ||
58969eee | 199 | if (ppc_hash64_has(cpu, PPC_HASH64_1TSEG)) { |
d2fd9612 CLG |
200 | _FDT((fdt_setprop(fdt, offset, "ibm,processor-segment-sizes", |
201 | segs, sizeof(segs)))); | |
202 | } | |
203 | ||
59b7c1c2 B |
204 | /* |
205 | * Advertise VMX/VSX (vector extensions) if available | |
d2fd9612 CLG |
206 | * 0 / no property == no vector extensions |
207 | * 1 == VMX / Altivec available | |
59b7c1c2 B |
208 | * 2 == VSX available |
209 | */ | |
d2fd9612 CLG |
210 | if (env->insns_flags & PPC_ALTIVEC) { |
211 | uint32_t vmx = (env->insns_flags2 & PPC2_VSX) ? 2 : 1; | |
212 | ||
213 | _FDT((fdt_setprop_cell(fdt, offset, "ibm,vmx", vmx))); | |
214 | } | |
215 | ||
59b7c1c2 B |
216 | /* |
217 | * Advertise DFP (Decimal Floating Point) if available | |
d2fd9612 | 218 | * 0 / no property == no DFP |
59b7c1c2 B |
219 | * 1 == DFP available |
220 | */ | |
d2fd9612 CLG |
221 | if (env->insns_flags2 & PPC2_DFP) { |
222 | _FDT((fdt_setprop_cell(fdt, offset, "ibm,dfp", 1))); | |
223 | } | |
224 | ||
644a2c99 DG |
225 | page_sizes_prop_size = ppc_create_page_sizes_prop(cpu, page_sizes_prop, |
226 | sizeof(page_sizes_prop)); | |
d2fd9612 CLG |
227 | if (page_sizes_prop_size) { |
228 | _FDT((fdt_setprop(fdt, offset, "ibm,segment-page-sizes", | |
229 | page_sizes_prop, page_sizes_prop_size))); | |
230 | } | |
231 | ||
232 | _FDT((fdt_setprop(fdt, offset, "ibm,pa-features", | |
233 | pa_features, sizeof(pa_features)))); | |
234 | ||
d2fd9612 CLG |
235 | /* Build interrupt servers properties */ |
236 | for (i = 0; i < smt_threads; i++) { | |
237 | servers_prop[i] = cpu_to_be32(pc->pir + i); | |
238 | } | |
239 | _FDT((fdt_setprop(fdt, offset, "ibm,ppc-interrupt-server#s", | |
240 | servers_prop, sizeof(servers_prop)))); | |
241 | } | |
242 | ||
b168a138 CLG |
243 | static void pnv_dt_icp(PnvChip *chip, void *fdt, uint32_t pir, |
244 | uint32_t nr_threads) | |
bf5615e7 CLG |
245 | { |
246 | uint64_t addr = PNV_ICP_BASE(chip) | (pir << 12); | |
247 | char *name; | |
248 | const char compat[] = "IBM,power8-icp\0IBM,ppc-xicp"; | |
249 | uint32_t irange[2], i, rsize; | |
250 | uint64_t *reg; | |
251 | int offset; | |
252 | ||
253 | irange[0] = cpu_to_be32(pir); | |
254 | irange[1] = cpu_to_be32(nr_threads); | |
255 | ||
256 | rsize = sizeof(uint64_t) * 2 * nr_threads; | |
257 | reg = g_malloc(rsize); | |
258 | for (i = 0; i < nr_threads; i++) { | |
259 | reg[i * 2] = cpu_to_be64(addr | ((pir + i) * 0x1000)); | |
260 | reg[i * 2 + 1] = cpu_to_be64(0x1000); | |
261 | } | |
262 | ||
263 | name = g_strdup_printf("interrupt-controller@%"PRIX64, addr); | |
264 | offset = fdt_add_subnode(fdt, 0, name); | |
265 | _FDT(offset); | |
266 | g_free(name); | |
267 | ||
268 | _FDT((fdt_setprop(fdt, offset, "compatible", compat, sizeof(compat)))); | |
269 | _FDT((fdt_setprop(fdt, offset, "reg", reg, rsize))); | |
270 | _FDT((fdt_setprop_string(fdt, offset, "device_type", | |
271 | "PowerPC-External-Interrupt-Presentation"))); | |
272 | _FDT((fdt_setprop(fdt, offset, "interrupt-controller", NULL, 0))); | |
273 | _FDT((fdt_setprop(fdt, offset, "ibm,interrupt-server-ranges", | |
274 | irange, sizeof(irange)))); | |
275 | _FDT((fdt_setprop_cell(fdt, offset, "#interrupt-cells", 1))); | |
276 | _FDT((fdt_setprop_cell(fdt, offset, "#address-cells", 0))); | |
277 | g_free(reg); | |
278 | } | |
279 | ||
eb859a27 | 280 | static void pnv_chip_power8_dt_populate(PnvChip *chip, void *fdt) |
e997040e | 281 | { |
40abf43f | 282 | const char *typename = pnv_chip_core_typename(chip); |
d2fd9612 CLG |
283 | size_t typesize = object_type_get_instance_size(typename); |
284 | int i; | |
285 | ||
b168a138 | 286 | pnv_dt_xscom(chip, fdt, 0); |
967b7523 | 287 | |
d2fd9612 CLG |
288 | for (i = 0; i < chip->nr_cores; i++) { |
289 | PnvCore *pnv_core = PNV_CORE(chip->cores + i * typesize); | |
290 | ||
b168a138 | 291 | pnv_dt_core(chip, pnv_core, fdt); |
bf5615e7 CLG |
292 | |
293 | /* Interrupt Control Presenters (ICP). One per core. */ | |
b168a138 | 294 | pnv_dt_icp(chip, fdt, pnv_core->pir, CPU_CORE(pnv_core)->nr_threads); |
d2fd9612 CLG |
295 | } |
296 | ||
e997040e | 297 | if (chip->ram_size) { |
b168a138 | 298 | pnv_dt_memory(fdt, chip->chip_id, chip->ram_start, chip->ram_size); |
e997040e CLG |
299 | } |
300 | } | |
301 | ||
eb859a27 CLG |
302 | static void pnv_chip_power9_dt_populate(PnvChip *chip, void *fdt) |
303 | { | |
304 | const char *typename = pnv_chip_core_typename(chip); | |
305 | size_t typesize = object_type_get_instance_size(typename); | |
306 | int i; | |
307 | ||
308 | pnv_dt_xscom(chip, fdt, 0); | |
309 | ||
310 | for (i = 0; i < chip->nr_cores; i++) { | |
311 | PnvCore *pnv_core = PNV_CORE(chip->cores + i * typesize); | |
312 | ||
313 | pnv_dt_core(chip, pnv_core, fdt); | |
314 | } | |
315 | ||
316 | if (chip->ram_size) { | |
317 | pnv_dt_memory(fdt, chip->chip_id, chip->ram_start, chip->ram_size); | |
318 | } | |
15376c66 CLG |
319 | |
320 | pnv_dt_lpc(chip, fdt, 0); | |
eb859a27 CLG |
321 | } |
322 | ||
b168a138 | 323 | static void pnv_dt_rtc(ISADevice *d, void *fdt, int lpc_off) |
c5ffdcae CLG |
324 | { |
325 | uint32_t io_base = d->ioport_id; | |
326 | uint32_t io_regs[] = { | |
327 | cpu_to_be32(1), | |
328 | cpu_to_be32(io_base), | |
329 | cpu_to_be32(2) | |
330 | }; | |
331 | char *name; | |
332 | int node; | |
333 | ||
334 | name = g_strdup_printf("%s@i%x", qdev_fw_name(DEVICE(d)), io_base); | |
335 | node = fdt_add_subnode(fdt, lpc_off, name); | |
336 | _FDT(node); | |
337 | g_free(name); | |
338 | ||
339 | _FDT((fdt_setprop(fdt, node, "reg", io_regs, sizeof(io_regs)))); | |
340 | _FDT((fdt_setprop_string(fdt, node, "compatible", "pnpPNP,b00"))); | |
341 | } | |
342 | ||
b168a138 | 343 | static void pnv_dt_serial(ISADevice *d, void *fdt, int lpc_off) |
cb228f5a CLG |
344 | { |
345 | const char compatible[] = "ns16550\0pnpPNP,501"; | |
346 | uint32_t io_base = d->ioport_id; | |
347 | uint32_t io_regs[] = { | |
348 | cpu_to_be32(1), | |
349 | cpu_to_be32(io_base), | |
350 | cpu_to_be32(8) | |
351 | }; | |
352 | char *name; | |
353 | int node; | |
354 | ||
355 | name = g_strdup_printf("%s@i%x", qdev_fw_name(DEVICE(d)), io_base); | |
356 | node = fdt_add_subnode(fdt, lpc_off, name); | |
357 | _FDT(node); | |
358 | g_free(name); | |
359 | ||
360 | _FDT((fdt_setprop(fdt, node, "reg", io_regs, sizeof(io_regs)))); | |
361 | _FDT((fdt_setprop(fdt, node, "compatible", compatible, | |
362 | sizeof(compatible)))); | |
363 | ||
364 | _FDT((fdt_setprop_cell(fdt, node, "clock-frequency", 1843200))); | |
365 | _FDT((fdt_setprop_cell(fdt, node, "current-speed", 115200))); | |
366 | _FDT((fdt_setprop_cell(fdt, node, "interrupts", d->isairq[0]))); | |
367 | _FDT((fdt_setprop_cell(fdt, node, "interrupt-parent", | |
368 | fdt_get_phandle(fdt, lpc_off)))); | |
369 | ||
370 | /* This is needed by Linux */ | |
371 | _FDT((fdt_setprop_string(fdt, node, "device_type", "serial"))); | |
372 | } | |
373 | ||
b168a138 | 374 | static void pnv_dt_ipmi_bt(ISADevice *d, void *fdt, int lpc_off) |
04f6c8b2 CLG |
375 | { |
376 | const char compatible[] = "bt\0ipmi-bt"; | |
377 | uint32_t io_base; | |
378 | uint32_t io_regs[] = { | |
379 | cpu_to_be32(1), | |
380 | 0, /* 'io_base' retrieved from the 'ioport' property of 'isa-ipmi-bt' */ | |
381 | cpu_to_be32(3) | |
382 | }; | |
383 | uint32_t irq; | |
384 | char *name; | |
385 | int node; | |
386 | ||
387 | io_base = object_property_get_int(OBJECT(d), "ioport", &error_fatal); | |
388 | io_regs[1] = cpu_to_be32(io_base); | |
389 | ||
390 | irq = object_property_get_int(OBJECT(d), "irq", &error_fatal); | |
391 | ||
392 | name = g_strdup_printf("%s@i%x", qdev_fw_name(DEVICE(d)), io_base); | |
393 | node = fdt_add_subnode(fdt, lpc_off, name); | |
394 | _FDT(node); | |
395 | g_free(name); | |
396 | ||
7032d92a CLG |
397 | _FDT((fdt_setprop(fdt, node, "reg", io_regs, sizeof(io_regs)))); |
398 | _FDT((fdt_setprop(fdt, node, "compatible", compatible, | |
399 | sizeof(compatible)))); | |
04f6c8b2 CLG |
400 | |
401 | /* Mark it as reserved to avoid Linux trying to claim it */ | |
402 | _FDT((fdt_setprop_string(fdt, node, "status", "reserved"))); | |
403 | _FDT((fdt_setprop_cell(fdt, node, "interrupts", irq))); | |
404 | _FDT((fdt_setprop_cell(fdt, node, "interrupt-parent", | |
405 | fdt_get_phandle(fdt, lpc_off)))); | |
406 | } | |
407 | ||
e7a3fee3 CLG |
408 | typedef struct ForeachPopulateArgs { |
409 | void *fdt; | |
410 | int offset; | |
411 | } ForeachPopulateArgs; | |
412 | ||
b168a138 | 413 | static int pnv_dt_isa_device(DeviceState *dev, void *opaque) |
e7a3fee3 | 414 | { |
c5ffdcae CLG |
415 | ForeachPopulateArgs *args = opaque; |
416 | ISADevice *d = ISA_DEVICE(dev); | |
417 | ||
418 | if (object_dynamic_cast(OBJECT(dev), TYPE_MC146818_RTC)) { | |
b168a138 | 419 | pnv_dt_rtc(d, args->fdt, args->offset); |
cb228f5a | 420 | } else if (object_dynamic_cast(OBJECT(dev), TYPE_ISA_SERIAL)) { |
b168a138 | 421 | pnv_dt_serial(d, args->fdt, args->offset); |
04f6c8b2 | 422 | } else if (object_dynamic_cast(OBJECT(dev), "isa-ipmi-bt")) { |
b168a138 | 423 | pnv_dt_ipmi_bt(d, args->fdt, args->offset); |
c5ffdcae CLG |
424 | } else { |
425 | error_report("unknown isa device %s@i%x", qdev_fw_name(dev), | |
426 | d->ioport_id); | |
427 | } | |
428 | ||
e7a3fee3 CLG |
429 | return 0; |
430 | } | |
431 | ||
59b7c1c2 B |
432 | /* |
433 | * The default LPC bus of a multichip system is on chip 0. It's | |
bb7ab95c CLG |
434 | * recognized by the firmware (skiboot) using a "primary" property. |
435 | */ | |
436 | static void pnv_dt_isa(PnvMachineState *pnv, void *fdt) | |
437 | { | |
64d011d5 | 438 | int isa_offset = fdt_path_offset(fdt, pnv->chips[0]->dt_isa_nodename); |
e7a3fee3 CLG |
439 | ForeachPopulateArgs args = { |
440 | .fdt = fdt, | |
bb7ab95c | 441 | .offset = isa_offset, |
e7a3fee3 | 442 | }; |
f47a08d1 | 443 | uint32_t phandle; |
e7a3fee3 | 444 | |
bb7ab95c CLG |
445 | _FDT((fdt_setprop(fdt, isa_offset, "primary", NULL, 0))); |
446 | ||
f47a08d1 CLG |
447 | phandle = qemu_fdt_alloc_phandle(fdt); |
448 | assert(phandle > 0); | |
449 | _FDT((fdt_setprop_cell(fdt, isa_offset, "phandle", phandle))); | |
450 | ||
59b7c1c2 B |
451 | /* |
452 | * ISA devices are not necessarily parented to the ISA bus so we | |
453 | * can not use object_child_foreach() | |
454 | */ | |
bb7ab95c CLG |
455 | qbus_walk_children(BUS(pnv->isa_bus), pnv_dt_isa_device, NULL, NULL, NULL, |
456 | &args); | |
e7a3fee3 CLG |
457 | } |
458 | ||
e5694793 CLG |
459 | static void pnv_dt_power_mgt(void *fdt) |
460 | { | |
461 | int off; | |
462 | ||
463 | off = fdt_add_subnode(fdt, 0, "ibm,opal"); | |
464 | off = fdt_add_subnode(fdt, off, "power-mgt"); | |
465 | ||
466 | _FDT(fdt_setprop_cell(fdt, off, "ibm,enabled-stop-levels", 0xc0000000)); | |
467 | } | |
468 | ||
b168a138 | 469 | static void *pnv_dt_create(MachineState *machine) |
9e933f4a | 470 | { |
83b90bf0 CLG |
471 | const char plat_compat8[] = "qemu,powernv8\0qemu,powernv\0ibm,powernv"; |
472 | const char plat_compat9[] = "qemu,powernv9\0ibm,powernv"; | |
b168a138 | 473 | PnvMachineState *pnv = PNV_MACHINE(machine); |
9e933f4a BH |
474 | void *fdt; |
475 | char *buf; | |
476 | int off; | |
e997040e | 477 | int i; |
9e933f4a BH |
478 | |
479 | fdt = g_malloc0(FDT_MAX_SIZE); | |
480 | _FDT((fdt_create_empty_tree(fdt, FDT_MAX_SIZE))); | |
481 | ||
482 | /* Root node */ | |
483 | _FDT((fdt_setprop_cell(fdt, 0, "#address-cells", 0x2))); | |
484 | _FDT((fdt_setprop_cell(fdt, 0, "#size-cells", 0x2))); | |
485 | _FDT((fdt_setprop_string(fdt, 0, "model", | |
486 | "IBM PowerNV (emulated by qemu)"))); | |
83b90bf0 CLG |
487 | if (pnv_is_power9(pnv)) { |
488 | _FDT((fdt_setprop(fdt, 0, "compatible", plat_compat9, | |
489 | sizeof(plat_compat9)))); | |
490 | } else { | |
491 | _FDT((fdt_setprop(fdt, 0, "compatible", plat_compat8, | |
492 | sizeof(plat_compat8)))); | |
493 | } | |
494 | ||
9e933f4a BH |
495 | |
496 | buf = qemu_uuid_unparse_strdup(&qemu_uuid); | |
497 | _FDT((fdt_setprop_string(fdt, 0, "vm,uuid", buf))); | |
498 | if (qemu_uuid_set) { | |
499 | _FDT((fdt_property_string(fdt, "system-id", buf))); | |
500 | } | |
501 | g_free(buf); | |
502 | ||
503 | off = fdt_add_subnode(fdt, 0, "chosen"); | |
504 | if (machine->kernel_cmdline) { | |
505 | _FDT((fdt_setprop_string(fdt, off, "bootargs", | |
506 | machine->kernel_cmdline))); | |
507 | } | |
508 | ||
509 | if (pnv->initrd_size) { | |
510 | uint32_t start_prop = cpu_to_be32(pnv->initrd_base); | |
511 | uint32_t end_prop = cpu_to_be32(pnv->initrd_base + pnv->initrd_size); | |
512 | ||
513 | _FDT((fdt_setprop(fdt, off, "linux,initrd-start", | |
514 | &start_prop, sizeof(start_prop)))); | |
515 | _FDT((fdt_setprop(fdt, off, "linux,initrd-end", | |
516 | &end_prop, sizeof(end_prop)))); | |
517 | } | |
518 | ||
e997040e CLG |
519 | /* Populate device tree for each chip */ |
520 | for (i = 0; i < pnv->num_chips; i++) { | |
eb859a27 | 521 | PNV_CHIP_GET_CLASS(pnv->chips[i])->dt_populate(pnv->chips[i], fdt); |
e997040e | 522 | } |
e7a3fee3 CLG |
523 | |
524 | /* Populate ISA devices on chip 0 */ | |
bb7ab95c | 525 | pnv_dt_isa(pnv, fdt); |
aeaef83d CLG |
526 | |
527 | if (pnv->bmc) { | |
b168a138 | 528 | pnv_dt_bmc_sensors(pnv->bmc, fdt); |
aeaef83d CLG |
529 | } |
530 | ||
e5694793 CLG |
531 | /* Create an extra node for power management on Power9 */ |
532 | if (pnv_is_power9(pnv)) { | |
533 | pnv_dt_power_mgt(fdt); | |
534 | } | |
535 | ||
9e933f4a BH |
536 | return fdt; |
537 | } | |
538 | ||
bce0b691 CLG |
539 | static void pnv_powerdown_notify(Notifier *n, void *opaque) |
540 | { | |
b168a138 | 541 | PnvMachineState *pnv = PNV_MACHINE(qdev_get_machine()); |
bce0b691 CLG |
542 | |
543 | if (pnv->bmc) { | |
544 | pnv_bmc_powerdown(pnv->bmc); | |
545 | } | |
546 | } | |
547 | ||
a0628599 | 548 | static void pnv_reset(MachineState *machine) |
9e933f4a | 549 | { |
b168a138 | 550 | PnvMachineState *pnv = PNV_MACHINE(machine); |
9e933f4a | 551 | void *fdt; |
aeaef83d | 552 | Object *obj; |
9e933f4a BH |
553 | |
554 | qemu_devices_reset(); | |
555 | ||
59b7c1c2 B |
556 | /* |
557 | * OpenPOWER systems have a BMC, which can be defined on the | |
aeaef83d CLG |
558 | * command line with: |
559 | * | |
560 | * -device ipmi-bmc-sim,id=bmc0 | |
561 | * | |
562 | * This is the internal simulator but it could also be an external | |
563 | * BMC. | |
564 | */ | |
a1a636b8 | 565 | obj = object_resolve_path_type("", "ipmi-bmc-sim", NULL); |
aeaef83d CLG |
566 | if (obj) { |
567 | pnv->bmc = IPMI_BMC(obj); | |
568 | } | |
569 | ||
b168a138 | 570 | fdt = pnv_dt_create(machine); |
9e933f4a BH |
571 | |
572 | /* Pack resulting tree */ | |
573 | _FDT((fdt_pack(fdt))); | |
574 | ||
8d409261 | 575 | qemu_fdt_dumpdtb(fdt, fdt_totalsize(fdt)); |
9e933f4a BH |
576 | cpu_physical_memory_write(PNV_FDT_ADDR, fdt, fdt_totalsize(fdt)); |
577 | } | |
578 | ||
04026890 | 579 | static ISABus *pnv_chip_power8_isa_create(PnvChip *chip, Error **errp) |
3495b6b6 | 580 | { |
77864267 CLG |
581 | Pnv8Chip *chip8 = PNV8_CHIP(chip); |
582 | return pnv_lpc_isa_create(&chip8->lpc, true, errp); | |
04026890 | 583 | } |
3495b6b6 | 584 | |
04026890 CLG |
585 | static ISABus *pnv_chip_power8nvl_isa_create(PnvChip *chip, Error **errp) |
586 | { | |
77864267 CLG |
587 | Pnv8Chip *chip8 = PNV8_CHIP(chip); |
588 | return pnv_lpc_isa_create(&chip8->lpc, false, errp); | |
04026890 | 589 | } |
3495b6b6 | 590 | |
04026890 CLG |
591 | static ISABus *pnv_chip_power9_isa_create(PnvChip *chip, Error **errp) |
592 | { | |
15376c66 CLG |
593 | Pnv9Chip *chip9 = PNV9_CHIP(chip); |
594 | return pnv_lpc_isa_create(&chip9->lpc, false, errp); | |
04026890 | 595 | } |
3495b6b6 | 596 | |
04026890 CLG |
597 | static ISABus *pnv_isa_create(PnvChip *chip, Error **errp) |
598 | { | |
599 | return PNV_CHIP_GET_CLASS(chip)->isa_create(chip, errp); | |
3495b6b6 CLG |
600 | } |
601 | ||
d8e4aad5 CLG |
602 | static void pnv_chip_power8_pic_print_info(PnvChip *chip, Monitor *mon) |
603 | { | |
604 | Pnv8Chip *chip8 = PNV8_CHIP(chip); | |
605 | ||
606 | ics_pic_print_info(&chip8->psi.ics, mon); | |
607 | } | |
608 | ||
609 | static void pnv_chip_power9_pic_print_info(PnvChip *chip, Monitor *mon) | |
610 | { | |
611 | Pnv9Chip *chip9 = PNV9_CHIP(chip); | |
612 | ||
613 | pnv_xive_pic_print_info(&chip9->xive, mon); | |
c38536bc | 614 | pnv_psi_pic_print_info(&chip9->psi, mon); |
d8e4aad5 CLG |
615 | } |
616 | ||
f30c843c CLG |
617 | static bool pnv_match_cpu(const char *default_type, const char *cpu_type) |
618 | { | |
619 | PowerPCCPUClass *ppc_default = | |
620 | POWERPC_CPU_CLASS(object_class_by_name(default_type)); | |
621 | PowerPCCPUClass *ppc = | |
622 | POWERPC_CPU_CLASS(object_class_by_name(cpu_type)); | |
623 | ||
624 | return ppc_default->pvr_match(ppc_default, ppc->pvr); | |
625 | } | |
626 | ||
b168a138 | 627 | static void pnv_init(MachineState *machine) |
9e933f4a | 628 | { |
b168a138 | 629 | PnvMachineState *pnv = PNV_MACHINE(machine); |
f30c843c | 630 | MachineClass *mc = MACHINE_GET_CLASS(machine); |
9e933f4a BH |
631 | MemoryRegion *ram; |
632 | char *fw_filename; | |
633 | long fw_size; | |
e997040e CLG |
634 | int i; |
635 | char *chip_typename; | |
9e933f4a BH |
636 | |
637 | /* allocate RAM */ | |
d23b6caa | 638 | if (machine->ram_size < (1 * GiB)) { |
3dc6f869 | 639 | warn_report("skiboot may not work with < 1GB of RAM"); |
9e933f4a BH |
640 | } |
641 | ||
642 | ram = g_new(MemoryRegion, 1); | |
b168a138 | 643 | memory_region_allocate_system_memory(ram, NULL, "pnv.ram", |
9e933f4a BH |
644 | machine->ram_size); |
645 | memory_region_add_subregion(get_system_memory(), 0, ram); | |
646 | ||
647 | /* load skiboot firmware */ | |
648 | if (bios_name == NULL) { | |
649 | bios_name = FW_FILE_NAME; | |
650 | } | |
651 | ||
652 | fw_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name); | |
15fcedb2 CLG |
653 | if (!fw_filename) { |
654 | error_report("Could not find OPAL firmware '%s'", bios_name); | |
655 | exit(1); | |
656 | } | |
9e933f4a BH |
657 | |
658 | fw_size = load_image_targphys(fw_filename, FW_LOAD_ADDR, FW_MAX_SIZE); | |
659 | if (fw_size < 0) { | |
15fcedb2 | 660 | error_report("Could not load OPAL firmware '%s'", fw_filename); |
9e933f4a BH |
661 | exit(1); |
662 | } | |
663 | g_free(fw_filename); | |
664 | ||
665 | /* load kernel */ | |
666 | if (machine->kernel_filename) { | |
667 | long kernel_size; | |
668 | ||
669 | kernel_size = load_image_targphys(machine->kernel_filename, | |
b45b56ba | 670 | KERNEL_LOAD_ADDR, KERNEL_MAX_SIZE); |
9e933f4a | 671 | if (kernel_size < 0) { |
802fc7ab | 672 | error_report("Could not load kernel '%s'", |
7c6e8797 | 673 | machine->kernel_filename); |
9e933f4a BH |
674 | exit(1); |
675 | } | |
676 | } | |
677 | ||
678 | /* load initrd */ | |
679 | if (machine->initrd_filename) { | |
680 | pnv->initrd_base = INITRD_LOAD_ADDR; | |
681 | pnv->initrd_size = load_image_targphys(machine->initrd_filename, | |
584ea7e7 | 682 | pnv->initrd_base, INITRD_MAX_SIZE); |
9e933f4a | 683 | if (pnv->initrd_size < 0) { |
802fc7ab | 684 | error_report("Could not load initial ram disk '%s'", |
9e933f4a BH |
685 | machine->initrd_filename); |
686 | exit(1); | |
687 | } | |
688 | } | |
e997040e | 689 | |
f30c843c CLG |
690 | /* |
691 | * Check compatibility of the specified CPU with the machine | |
692 | * default. | |
693 | */ | |
694 | if (!pnv_match_cpu(mc->default_cpu_type, machine->cpu_type)) { | |
695 | error_report("invalid CPU model '%s' for %s machine", | |
696 | machine->cpu_type, mc->name); | |
697 | exit(1); | |
698 | } | |
699 | ||
e997040e | 700 | /* Create the processor chips */ |
4a12c699 | 701 | i = strlen(machine->cpu_type) - strlen(POWERPC_CPU_TYPE_SUFFIX); |
7fd544d8 | 702 | chip_typename = g_strdup_printf(PNV_CHIP_TYPE_NAME("%.*s"), |
4a12c699 | 703 | i, machine->cpu_type); |
e997040e | 704 | if (!object_class_by_name(chip_typename)) { |
f30c843c CLG |
705 | error_report("invalid chip model '%.*s' for %s machine", |
706 | i, machine->cpu_type, mc->name); | |
e997040e CLG |
707 | exit(1); |
708 | } | |
709 | ||
710 | pnv->chips = g_new0(PnvChip *, pnv->num_chips); | |
711 | for (i = 0; i < pnv->num_chips; i++) { | |
712 | char chip_name[32]; | |
713 | Object *chip = object_new(chip_typename); | |
714 | ||
715 | pnv->chips[i] = PNV_CHIP(chip); | |
716 | ||
59b7c1c2 B |
717 | /* |
718 | * TODO: put all the memory in one node on chip 0 until we find a | |
e997040e CLG |
719 | * way to specify different ranges for each chip |
720 | */ | |
721 | if (i == 0) { | |
722 | object_property_set_int(chip, machine->ram_size, "ram-size", | |
723 | &error_fatal); | |
724 | } | |
725 | ||
726 | snprintf(chip_name, sizeof(chip_name), "chip[%d]", PNV_CHIP_HWID(i)); | |
727 | object_property_add_child(OBJECT(pnv), chip_name, chip, &error_fatal); | |
728 | object_property_set_int(chip, PNV_CHIP_HWID(i), "chip-id", | |
729 | &error_fatal); | |
fe6b6346 LX |
730 | object_property_set_int(chip, machine->smp.cores, |
731 | "nr-cores", &error_fatal); | |
e997040e CLG |
732 | object_property_set_bool(chip, true, "realized", &error_fatal); |
733 | } | |
734 | g_free(chip_typename); | |
3495b6b6 CLG |
735 | |
736 | /* Instantiate ISA bus on chip 0 */ | |
04026890 | 737 | pnv->isa_bus = pnv_isa_create(pnv->chips[0], &error_fatal); |
3495b6b6 CLG |
738 | |
739 | /* Create serial port */ | |
def337ff | 740 | serial_hds_isa_init(pnv->isa_bus, 0, MAX_ISA_SERIAL_PORTS); |
3495b6b6 CLG |
741 | |
742 | /* Create an RTC ISA device too */ | |
6c646a11 | 743 | mc146818_rtc_init(pnv->isa_bus, 2000, NULL); |
bce0b691 | 744 | |
59b7c1c2 B |
745 | /* |
746 | * OpenPOWER systems use a IPMI SEL Event message to notify the | |
747 | * host to powerdown | |
748 | */ | |
bce0b691 CLG |
749 | pnv->powerdown_notifier.notify = pnv_powerdown_notify; |
750 | qemu_register_powerdown_notifier(&pnv->powerdown_notifier); | |
e997040e CLG |
751 | } |
752 | ||
631adaff CLG |
753 | /* |
754 | * 0:21 Reserved - Read as zeros | |
755 | * 22:24 Chip ID | |
756 | * 25:28 Core number | |
757 | * 29:31 Thread ID | |
758 | */ | |
759 | static uint32_t pnv_chip_core_pir_p8(PnvChip *chip, uint32_t core_id) | |
760 | { | |
761 | return (chip->chip_id << 7) | (core_id << 3); | |
762 | } | |
763 | ||
8fa1f4ef CLG |
764 | static void pnv_chip_power8_intc_create(PnvChip *chip, PowerPCCPU *cpu, |
765 | Error **errp) | |
d35aefa9 | 766 | { |
8fa1f4ef CLG |
767 | Error *local_err = NULL; |
768 | Object *obj; | |
8907fc25 | 769 | PnvCPUState *pnv_cpu = pnv_cpu_state(cpu); |
8fa1f4ef CLG |
770 | |
771 | obj = icp_create(OBJECT(cpu), TYPE_PNV_ICP, XICS_FABRIC(qdev_get_machine()), | |
772 | &local_err); | |
773 | if (local_err) { | |
774 | error_propagate(errp, local_err); | |
775 | return; | |
776 | } | |
777 | ||
956b8f46 | 778 | pnv_cpu->intc = obj; |
d35aefa9 CLG |
779 | } |
780 | ||
d49e8a9b CLG |
781 | static void pnv_chip_power8_intc_reset(PnvChip *chip, PowerPCCPU *cpu) |
782 | { | |
783 | PnvCPUState *pnv_cpu = pnv_cpu_state(cpu); | |
784 | ||
785 | icp_reset(ICP(pnv_cpu->intc)); | |
786 | } | |
787 | ||
631adaff CLG |
788 | /* |
789 | * 0:48 Reserved - Read as zeroes | |
790 | * 49:52 Node ID | |
791 | * 53:55 Chip ID | |
792 | * 56 Reserved - Read as zero | |
793 | * 57:61 Core number | |
794 | * 62:63 Thread ID | |
795 | * | |
796 | * We only care about the lower bits. uint32_t is fine for the moment. | |
797 | */ | |
798 | static uint32_t pnv_chip_core_pir_p9(PnvChip *chip, uint32_t core_id) | |
799 | { | |
800 | return (chip->chip_id << 8) | (core_id << 2); | |
801 | } | |
802 | ||
8fa1f4ef CLG |
803 | static void pnv_chip_power9_intc_create(PnvChip *chip, PowerPCCPU *cpu, |
804 | Error **errp) | |
d35aefa9 | 805 | { |
2dfa91a2 CLG |
806 | Pnv9Chip *chip9 = PNV9_CHIP(chip); |
807 | Error *local_err = NULL; | |
808 | Object *obj; | |
809 | PnvCPUState *pnv_cpu = pnv_cpu_state(cpu); | |
810 | ||
811 | /* | |
812 | * The core creates its interrupt presenter but the XIVE interrupt | |
813 | * controller object is initialized afterwards. Hopefully, it's | |
814 | * only used at runtime. | |
815 | */ | |
26aa5b1e | 816 | obj = xive_tctx_create(OBJECT(cpu), XIVE_ROUTER(&chip9->xive), &local_err); |
2dfa91a2 CLG |
817 | if (local_err) { |
818 | error_propagate(errp, local_err); | |
819 | return; | |
820 | } | |
821 | ||
822 | pnv_cpu->intc = obj; | |
d35aefa9 CLG |
823 | } |
824 | ||
d49e8a9b CLG |
825 | static void pnv_chip_power9_intc_reset(PnvChip *chip, PowerPCCPU *cpu) |
826 | { | |
827 | PnvCPUState *pnv_cpu = pnv_cpu_state(cpu); | |
828 | ||
829 | xive_tctx_reset(XIVE_TCTX(pnv_cpu->intc)); | |
830 | } | |
831 | ||
59b7c1c2 B |
832 | /* |
833 | * Allowed core identifiers on a POWER8 Processor Chip : | |
397a79e7 CLG |
834 | * |
835 | * <EX0 reserved> | |
836 | * EX1 - Venice only | |
837 | * EX2 - Venice only | |
838 | * EX3 - Venice only | |
839 | * EX4 | |
840 | * EX5 | |
841 | * EX6 | |
842 | * <EX7,8 reserved> <reserved> | |
843 | * EX9 - Venice only | |
844 | * EX10 - Venice only | |
845 | * EX11 - Venice only | |
846 | * EX12 | |
847 | * EX13 | |
848 | * EX14 | |
849 | * <EX15 reserved> | |
850 | */ | |
851 | #define POWER8E_CORE_MASK (0x7070ull) | |
852 | #define POWER8_CORE_MASK (0x7e7eull) | |
853 | ||
854 | /* | |
09279d7e | 855 | * POWER9 has 24 cores, ids starting at 0x0 |
397a79e7 | 856 | */ |
09279d7e | 857 | #define POWER9_CORE_MASK (0xffffffffffffffull) |
397a79e7 | 858 | |
77864267 CLG |
859 | static void pnv_chip_power8_instance_init(Object *obj) |
860 | { | |
861 | Pnv8Chip *chip8 = PNV8_CHIP(obj); | |
862 | ||
f6d4dca8 | 863 | object_initialize_child(obj, "psi", &chip8->psi, sizeof(chip8->psi), |
ae856055 | 864 | TYPE_PNV8_PSI, &error_abort, NULL); |
77864267 CLG |
865 | object_property_add_const_link(OBJECT(&chip8->psi), "xics", |
866 | OBJECT(qdev_get_machine()), &error_abort); | |
867 | ||
f6d4dca8 | 868 | object_initialize_child(obj, "lpc", &chip8->lpc, sizeof(chip8->lpc), |
82514be2 | 869 | TYPE_PNV8_LPC, &error_abort, NULL); |
77864267 CLG |
870 | object_property_add_const_link(OBJECT(&chip8->lpc), "psi", |
871 | OBJECT(&chip8->psi), &error_abort); | |
872 | ||
f6d4dca8 | 873 | object_initialize_child(obj, "occ", &chip8->occ, sizeof(chip8->occ), |
3233838c | 874 | TYPE_PNV8_OCC, &error_abort, NULL); |
77864267 CLG |
875 | object_property_add_const_link(OBJECT(&chip8->occ), "psi", |
876 | OBJECT(&chip8->psi), &error_abort); | |
3887d241 B |
877 | |
878 | object_initialize_child(obj, "homer", &chip8->homer, sizeof(chip8->homer), | |
879 | TYPE_PNV8_HOMER, &error_abort, NULL); | |
880 | object_property_add_const_link(OBJECT(&chip8->homer), "chip", obj, | |
881 | &error_abort); | |
77864267 CLG |
882 | } |
883 | ||
884 | static void pnv_chip_icp_realize(Pnv8Chip *chip8, Error **errp) | |
885 | { | |
886 | PnvChip *chip = PNV_CHIP(chip8); | |
887 | PnvChipClass *pcc = PNV_CHIP_GET_CLASS(chip); | |
888 | const char *typename = pnv_chip_core_typename(chip); | |
889 | size_t typesize = object_type_get_instance_size(typename); | |
890 | int i, j; | |
891 | char *name; | |
892 | XICSFabric *xi = XICS_FABRIC(qdev_get_machine()); | |
893 | ||
894 | name = g_strdup_printf("icp-%x", chip->chip_id); | |
895 | memory_region_init(&chip8->icp_mmio, OBJECT(chip), name, PNV_ICP_SIZE); | |
896 | sysbus_init_mmio(SYS_BUS_DEVICE(chip), &chip8->icp_mmio); | |
897 | g_free(name); | |
898 | ||
899 | sysbus_mmio_map(SYS_BUS_DEVICE(chip), 1, PNV_ICP_BASE(chip)); | |
900 | ||
901 | /* Map the ICP registers for each thread */ | |
902 | for (i = 0; i < chip->nr_cores; i++) { | |
903 | PnvCore *pnv_core = PNV_CORE(chip->cores + i * typesize); | |
904 | int core_hwid = CPU_CORE(pnv_core)->core_id; | |
905 | ||
906 | for (j = 0; j < CPU_CORE(pnv_core)->nr_threads; j++) { | |
907 | uint32_t pir = pcc->core_pir(chip, core_hwid) + j; | |
908 | PnvICPState *icp = PNV_ICP(xics_icp_get(xi, pir)); | |
909 | ||
910 | memory_region_add_subregion(&chip8->icp_mmio, pir << 12, | |
911 | &icp->mmio); | |
912 | } | |
913 | } | |
914 | } | |
915 | ||
916 | static void pnv_chip_power8_realize(DeviceState *dev, Error **errp) | |
917 | { | |
918 | PnvChipClass *pcc = PNV_CHIP_GET_CLASS(dev); | |
919 | PnvChip *chip = PNV_CHIP(dev); | |
920 | Pnv8Chip *chip8 = PNV8_CHIP(dev); | |
ae856055 | 921 | Pnv8Psi *psi8 = &chip8->psi; |
77864267 CLG |
922 | Error *local_err = NULL; |
923 | ||
709044fd CLG |
924 | /* XSCOM bridge is first */ |
925 | pnv_xscom_realize(chip, PNV_XSCOM_SIZE, &local_err); | |
926 | if (local_err) { | |
927 | error_propagate(errp, local_err); | |
928 | return; | |
929 | } | |
930 | sysbus_mmio_map(SYS_BUS_DEVICE(chip), 0, PNV_XSCOM_BASE(chip)); | |
931 | ||
77864267 CLG |
932 | pcc->parent_realize(dev, &local_err); |
933 | if (local_err) { | |
934 | error_propagate(errp, local_err); | |
935 | return; | |
936 | } | |
937 | ||
938 | /* Processor Service Interface (PSI) Host Bridge */ | |
939 | object_property_set_int(OBJECT(&chip8->psi), PNV_PSIHB_BASE(chip), | |
940 | "bar", &error_fatal); | |
941 | object_property_set_bool(OBJECT(&chip8->psi), true, "realized", &local_err); | |
942 | if (local_err) { | |
943 | error_propagate(errp, local_err); | |
944 | return; | |
945 | } | |
ae856055 CLG |
946 | pnv_xscom_add_subregion(chip, PNV_XSCOM_PSIHB_BASE, |
947 | &PNV_PSI(psi8)->xscom_regs); | |
77864267 CLG |
948 | |
949 | /* Create LPC controller */ | |
950 | object_property_set_bool(OBJECT(&chip8->lpc), true, "realized", | |
951 | &error_fatal); | |
952 | pnv_xscom_add_subregion(chip, PNV_XSCOM_LPC_BASE, &chip8->lpc.xscom_regs); | |
953 | ||
64d011d5 CLG |
954 | chip->dt_isa_nodename = g_strdup_printf("/xscom@%" PRIx64 "/isa@%x", |
955 | (uint64_t) PNV_XSCOM_BASE(chip), | |
956 | PNV_XSCOM_LPC_BASE); | |
957 | ||
59b7c1c2 B |
958 | /* |
959 | * Interrupt Management Area. This is the memory region holding | |
960 | * all the Interrupt Control Presenter (ICP) registers | |
961 | */ | |
77864267 CLG |
962 | pnv_chip_icp_realize(chip8, &local_err); |
963 | if (local_err) { | |
964 | error_propagate(errp, local_err); | |
965 | return; | |
966 | } | |
967 | ||
968 | /* Create the simplified OCC model */ | |
969 | object_property_set_bool(OBJECT(&chip8->occ), true, "realized", &local_err); | |
970 | if (local_err) { | |
971 | error_propagate(errp, local_err); | |
972 | return; | |
973 | } | |
974 | pnv_xscom_add_subregion(chip, PNV_XSCOM_OCC_BASE, &chip8->occ.xscom_regs); | |
f3db8266 B |
975 | |
976 | /* OCC SRAM model */ | |
977 | memory_region_add_subregion(get_system_memory(), PNV_OCC_COMMON_AREA(chip), | |
978 | &chip8->occ.sram_regs); | |
3887d241 B |
979 | |
980 | /* HOMER */ | |
981 | object_property_set_bool(OBJECT(&chip8->homer), true, "realized", | |
982 | &local_err); | |
983 | if (local_err) { | |
984 | error_propagate(errp, local_err); | |
985 | return; | |
986 | } | |
987 | memory_region_add_subregion(get_system_memory(), PNV_HOMER_BASE(chip), | |
988 | &chip8->homer.regs); | |
77864267 CLG |
989 | } |
990 | ||
e997040e CLG |
991 | static void pnv_chip_power8e_class_init(ObjectClass *klass, void *data) |
992 | { | |
993 | DeviceClass *dc = DEVICE_CLASS(klass); | |
994 | PnvChipClass *k = PNV_CHIP_CLASS(klass); | |
995 | ||
e997040e CLG |
996 | k->chip_type = PNV_CHIP_POWER8E; |
997 | k->chip_cfam_id = 0x221ef04980000000ull; /* P8 Murano DD2.1 */ | |
397a79e7 | 998 | k->cores_mask = POWER8E_CORE_MASK; |
631adaff | 999 | k->core_pir = pnv_chip_core_pir_p8; |
d35aefa9 | 1000 | k->intc_create = pnv_chip_power8_intc_create; |
d49e8a9b | 1001 | k->intc_reset = pnv_chip_power8_intc_reset; |
04026890 | 1002 | k->isa_create = pnv_chip_power8_isa_create; |
eb859a27 | 1003 | k->dt_populate = pnv_chip_power8_dt_populate; |
d8e4aad5 | 1004 | k->pic_print_info = pnv_chip_power8_pic_print_info; |
e997040e | 1005 | dc->desc = "PowerNV Chip POWER8E"; |
77864267 CLG |
1006 | |
1007 | device_class_set_parent_realize(dc, pnv_chip_power8_realize, | |
1008 | &k->parent_realize); | |
e997040e CLG |
1009 | } |
1010 | ||
e997040e CLG |
1011 | static void pnv_chip_power8_class_init(ObjectClass *klass, void *data) |
1012 | { | |
1013 | DeviceClass *dc = DEVICE_CLASS(klass); | |
1014 | PnvChipClass *k = PNV_CHIP_CLASS(klass); | |
1015 | ||
e997040e CLG |
1016 | k->chip_type = PNV_CHIP_POWER8; |
1017 | k->chip_cfam_id = 0x220ea04980000000ull; /* P8 Venice DD2.0 */ | |
397a79e7 | 1018 | k->cores_mask = POWER8_CORE_MASK; |
631adaff | 1019 | k->core_pir = pnv_chip_core_pir_p8; |
d35aefa9 | 1020 | k->intc_create = pnv_chip_power8_intc_create; |
d49e8a9b | 1021 | k->intc_reset = pnv_chip_power8_intc_reset; |
04026890 | 1022 | k->isa_create = pnv_chip_power8_isa_create; |
eb859a27 | 1023 | k->dt_populate = pnv_chip_power8_dt_populate; |
d8e4aad5 | 1024 | k->pic_print_info = pnv_chip_power8_pic_print_info; |
e997040e | 1025 | dc->desc = "PowerNV Chip POWER8"; |
77864267 CLG |
1026 | |
1027 | device_class_set_parent_realize(dc, pnv_chip_power8_realize, | |
1028 | &k->parent_realize); | |
e997040e CLG |
1029 | } |
1030 | ||
e997040e CLG |
1031 | static void pnv_chip_power8nvl_class_init(ObjectClass *klass, void *data) |
1032 | { | |
1033 | DeviceClass *dc = DEVICE_CLASS(klass); | |
1034 | PnvChipClass *k = PNV_CHIP_CLASS(klass); | |
1035 | ||
e997040e CLG |
1036 | k->chip_type = PNV_CHIP_POWER8NVL; |
1037 | k->chip_cfam_id = 0x120d304980000000ull; /* P8 Naples DD1.0 */ | |
397a79e7 | 1038 | k->cores_mask = POWER8_CORE_MASK; |
631adaff | 1039 | k->core_pir = pnv_chip_core_pir_p8; |
d35aefa9 | 1040 | k->intc_create = pnv_chip_power8_intc_create; |
d49e8a9b | 1041 | k->intc_reset = pnv_chip_power8_intc_reset; |
04026890 | 1042 | k->isa_create = pnv_chip_power8nvl_isa_create; |
eb859a27 | 1043 | k->dt_populate = pnv_chip_power8_dt_populate; |
d8e4aad5 | 1044 | k->pic_print_info = pnv_chip_power8_pic_print_info; |
e997040e | 1045 | dc->desc = "PowerNV Chip POWER8NVL"; |
77864267 CLG |
1046 | |
1047 | device_class_set_parent_realize(dc, pnv_chip_power8_realize, | |
1048 | &k->parent_realize); | |
1049 | } | |
1050 | ||
1051 | static void pnv_chip_power9_instance_init(Object *obj) | |
1052 | { | |
2dfa91a2 CLG |
1053 | Pnv9Chip *chip9 = PNV9_CHIP(obj); |
1054 | ||
1055 | object_initialize_child(obj, "xive", &chip9->xive, sizeof(chip9->xive), | |
1056 | TYPE_PNV_XIVE, &error_abort, NULL); | |
1057 | object_property_add_const_link(OBJECT(&chip9->xive), "chip", obj, | |
1058 | &error_abort); | |
c38536bc CLG |
1059 | |
1060 | object_initialize_child(obj, "psi", &chip9->psi, sizeof(chip9->psi), | |
1061 | TYPE_PNV9_PSI, &error_abort, NULL); | |
1062 | object_property_add_const_link(OBJECT(&chip9->psi), "chip", obj, | |
1063 | &error_abort); | |
15376c66 CLG |
1064 | |
1065 | object_initialize_child(obj, "lpc", &chip9->lpc, sizeof(chip9->lpc), | |
1066 | TYPE_PNV9_LPC, &error_abort, NULL); | |
1067 | object_property_add_const_link(OBJECT(&chip9->lpc), "psi", | |
1068 | OBJECT(&chip9->psi), &error_abort); | |
6598a70d CLG |
1069 | |
1070 | object_initialize_child(obj, "occ", &chip9->occ, sizeof(chip9->occ), | |
1071 | TYPE_PNV9_OCC, &error_abort, NULL); | |
1072 | object_property_add_const_link(OBJECT(&chip9->occ), "psi", | |
1073 | OBJECT(&chip9->psi), &error_abort); | |
3887d241 B |
1074 | |
1075 | object_initialize_child(obj, "homer", &chip9->homer, sizeof(chip9->homer), | |
1076 | TYPE_PNV9_HOMER, &error_abort, NULL); | |
1077 | object_property_add_const_link(OBJECT(&chip9->homer), "chip", obj, | |
1078 | &error_abort); | |
77864267 CLG |
1079 | } |
1080 | ||
5dad902c CLG |
1081 | static void pnv_chip_quad_realize(Pnv9Chip *chip9, Error **errp) |
1082 | { | |
1083 | PnvChip *chip = PNV_CHIP(chip9); | |
1084 | const char *typename = pnv_chip_core_typename(chip); | |
1085 | size_t typesize = object_type_get_instance_size(typename); | |
1086 | int i; | |
1087 | ||
1088 | chip9->nr_quads = DIV_ROUND_UP(chip->nr_cores, 4); | |
1089 | chip9->quads = g_new0(PnvQuad, chip9->nr_quads); | |
1090 | ||
1091 | for (i = 0; i < chip9->nr_quads; i++) { | |
1092 | char eq_name[32]; | |
1093 | PnvQuad *eq = &chip9->quads[i]; | |
1094 | PnvCore *pnv_core = PNV_CORE(chip->cores + (i * 4) * typesize); | |
1095 | int core_id = CPU_CORE(pnv_core)->core_id; | |
1096 | ||
5dad902c | 1097 | snprintf(eq_name, sizeof(eq_name), "eq[%d]", core_id); |
bc4c406c PMD |
1098 | object_initialize_child(OBJECT(chip), eq_name, eq, sizeof(*eq), |
1099 | TYPE_PNV_QUAD, &error_fatal, NULL); | |
5dad902c | 1100 | |
5dad902c CLG |
1101 | object_property_set_int(OBJECT(eq), core_id, "id", &error_fatal); |
1102 | object_property_set_bool(OBJECT(eq), true, "realized", &error_fatal); | |
5dad902c CLG |
1103 | |
1104 | pnv_xscom_add_subregion(chip, PNV9_XSCOM_EQ_BASE(eq->id), | |
1105 | &eq->xscom_regs); | |
1106 | } | |
1107 | } | |
1108 | ||
77864267 CLG |
1109 | static void pnv_chip_power9_realize(DeviceState *dev, Error **errp) |
1110 | { | |
1111 | PnvChipClass *pcc = PNV_CHIP_GET_CLASS(dev); | |
2dfa91a2 CLG |
1112 | Pnv9Chip *chip9 = PNV9_CHIP(dev); |
1113 | PnvChip *chip = PNV_CHIP(dev); | |
c38536bc | 1114 | Pnv9Psi *psi9 = &chip9->psi; |
77864267 CLG |
1115 | Error *local_err = NULL; |
1116 | ||
709044fd CLG |
1117 | /* XSCOM bridge is first */ |
1118 | pnv_xscom_realize(chip, PNV9_XSCOM_SIZE, &local_err); | |
1119 | if (local_err) { | |
1120 | error_propagate(errp, local_err); | |
1121 | return; | |
1122 | } | |
1123 | sysbus_mmio_map(SYS_BUS_DEVICE(chip), 0, PNV9_XSCOM_BASE(chip)); | |
1124 | ||
77864267 CLG |
1125 | pcc->parent_realize(dev, &local_err); |
1126 | if (local_err) { | |
1127 | error_propagate(errp, local_err); | |
1128 | return; | |
1129 | } | |
2dfa91a2 | 1130 | |
5dad902c CLG |
1131 | pnv_chip_quad_realize(chip9, &local_err); |
1132 | if (local_err) { | |
1133 | error_propagate(errp, local_err); | |
1134 | return; | |
1135 | } | |
1136 | ||
2dfa91a2 CLG |
1137 | /* XIVE interrupt controller (POWER9) */ |
1138 | object_property_set_int(OBJECT(&chip9->xive), PNV9_XIVE_IC_BASE(chip), | |
1139 | "ic-bar", &error_fatal); | |
1140 | object_property_set_int(OBJECT(&chip9->xive), PNV9_XIVE_VC_BASE(chip), | |
1141 | "vc-bar", &error_fatal); | |
1142 | object_property_set_int(OBJECT(&chip9->xive), PNV9_XIVE_PC_BASE(chip), | |
1143 | "pc-bar", &error_fatal); | |
1144 | object_property_set_int(OBJECT(&chip9->xive), PNV9_XIVE_TM_BASE(chip), | |
1145 | "tm-bar", &error_fatal); | |
1146 | object_property_set_bool(OBJECT(&chip9->xive), true, "realized", | |
1147 | &local_err); | |
1148 | if (local_err) { | |
1149 | error_propagate(errp, local_err); | |
1150 | return; | |
1151 | } | |
1152 | pnv_xscom_add_subregion(chip, PNV9_XSCOM_XIVE_BASE, | |
1153 | &chip9->xive.xscom_regs); | |
c38536bc CLG |
1154 | |
1155 | /* Processor Service Interface (PSI) Host Bridge */ | |
1156 | object_property_set_int(OBJECT(&chip9->psi), PNV9_PSIHB_BASE(chip), | |
1157 | "bar", &error_fatal); | |
1158 | object_property_set_bool(OBJECT(&chip9->psi), true, "realized", &local_err); | |
1159 | if (local_err) { | |
1160 | error_propagate(errp, local_err); | |
1161 | return; | |
1162 | } | |
1163 | pnv_xscom_add_subregion(chip, PNV9_XSCOM_PSIHB_BASE, | |
1164 | &PNV_PSI(psi9)->xscom_regs); | |
15376c66 CLG |
1165 | |
1166 | /* LPC */ | |
1167 | object_property_set_bool(OBJECT(&chip9->lpc), true, "realized", &local_err); | |
1168 | if (local_err) { | |
1169 | error_propagate(errp, local_err); | |
1170 | return; | |
1171 | } | |
1172 | memory_region_add_subregion(get_system_memory(), PNV9_LPCM_BASE(chip), | |
1173 | &chip9->lpc.xscom_regs); | |
1174 | ||
1175 | chip->dt_isa_nodename = g_strdup_printf("/lpcm-opb@%" PRIx64 "/lpc@0", | |
1176 | (uint64_t) PNV9_LPCM_BASE(chip)); | |
6598a70d CLG |
1177 | |
1178 | /* Create the simplified OCC model */ | |
1179 | object_property_set_bool(OBJECT(&chip9->occ), true, "realized", &local_err); | |
1180 | if (local_err) { | |
1181 | error_propagate(errp, local_err); | |
1182 | return; | |
1183 | } | |
1184 | pnv_xscom_add_subregion(chip, PNV9_XSCOM_OCC_BASE, &chip9->occ.xscom_regs); | |
f3db8266 B |
1185 | |
1186 | /* OCC SRAM model */ | |
1187 | memory_region_add_subregion(get_system_memory(), PNV9_OCC_COMMON_AREA(chip), | |
1188 | &chip9->occ.sram_regs); | |
3887d241 B |
1189 | |
1190 | /* HOMER */ | |
1191 | object_property_set_bool(OBJECT(&chip9->homer), true, "realized", | |
1192 | &local_err); | |
1193 | if (local_err) { | |
1194 | error_propagate(errp, local_err); | |
1195 | return; | |
1196 | } | |
1197 | memory_region_add_subregion(get_system_memory(), PNV9_HOMER_BASE(chip), | |
1198 | &chip9->homer.regs); | |
e997040e CLG |
1199 | } |
1200 | ||
e997040e CLG |
1201 | static void pnv_chip_power9_class_init(ObjectClass *klass, void *data) |
1202 | { | |
1203 | DeviceClass *dc = DEVICE_CLASS(klass); | |
1204 | PnvChipClass *k = PNV_CHIP_CLASS(klass); | |
1205 | ||
e997040e | 1206 | k->chip_type = PNV_CHIP_POWER9; |
83028a2b | 1207 | k->chip_cfam_id = 0x220d104900008000ull; /* P9 Nimbus DD2.0 */ |
397a79e7 | 1208 | k->cores_mask = POWER9_CORE_MASK; |
631adaff | 1209 | k->core_pir = pnv_chip_core_pir_p9; |
d35aefa9 | 1210 | k->intc_create = pnv_chip_power9_intc_create; |
d49e8a9b | 1211 | k->intc_reset = pnv_chip_power9_intc_reset; |
04026890 | 1212 | k->isa_create = pnv_chip_power9_isa_create; |
eb859a27 | 1213 | k->dt_populate = pnv_chip_power9_dt_populate; |
d8e4aad5 | 1214 | k->pic_print_info = pnv_chip_power9_pic_print_info; |
e997040e | 1215 | dc->desc = "PowerNV Chip POWER9"; |
77864267 CLG |
1216 | |
1217 | device_class_set_parent_realize(dc, pnv_chip_power9_realize, | |
1218 | &k->parent_realize); | |
e997040e CLG |
1219 | } |
1220 | ||
397a79e7 CLG |
1221 | static void pnv_chip_core_sanitize(PnvChip *chip, Error **errp) |
1222 | { | |
1223 | PnvChipClass *pcc = PNV_CHIP_GET_CLASS(chip); | |
1224 | int cores_max; | |
1225 | ||
1226 | /* | |
1227 | * No custom mask for this chip, let's use the default one from * | |
1228 | * the chip class | |
1229 | */ | |
1230 | if (!chip->cores_mask) { | |
1231 | chip->cores_mask = pcc->cores_mask; | |
1232 | } | |
1233 | ||
1234 | /* filter alien core ids ! some are reserved */ | |
1235 | if ((chip->cores_mask & pcc->cores_mask) != chip->cores_mask) { | |
1236 | error_setg(errp, "warning: invalid core mask for chip Ox%"PRIx64" !", | |
1237 | chip->cores_mask); | |
1238 | return; | |
1239 | } | |
1240 | chip->cores_mask &= pcc->cores_mask; | |
1241 | ||
1242 | /* now that we have a sane layout, let check the number of cores */ | |
27d9ffd4 | 1243 | cores_max = ctpop64(chip->cores_mask); |
397a79e7 CLG |
1244 | if (chip->nr_cores > cores_max) { |
1245 | error_setg(errp, "warning: too many cores for chip ! Limit is %d", | |
1246 | cores_max); | |
1247 | return; | |
1248 | } | |
1249 | } | |
1250 | ||
51c04728 | 1251 | static void pnv_chip_core_realize(PnvChip *chip, Error **errp) |
e997040e | 1252 | { |
fe6b6346 | 1253 | MachineState *ms = MACHINE(qdev_get_machine()); |
397a79e7 | 1254 | Error *error = NULL; |
d2fd9612 | 1255 | PnvChipClass *pcc = PNV_CHIP_GET_CLASS(chip); |
40abf43f | 1256 | const char *typename = pnv_chip_core_typename(chip); |
d2fd9612 CLG |
1257 | size_t typesize = object_type_get_instance_size(typename); |
1258 | int i, core_hwid; | |
1259 | ||
1260 | if (!object_class_by_name(typename)) { | |
1261 | error_setg(errp, "Unable to find PowerNV CPU Core '%s'", typename); | |
1262 | return; | |
1263 | } | |
397a79e7 | 1264 | |
d2fd9612 | 1265 | /* Cores */ |
397a79e7 CLG |
1266 | pnv_chip_core_sanitize(chip, &error); |
1267 | if (error) { | |
1268 | error_propagate(errp, error); | |
1269 | return; | |
1270 | } | |
d2fd9612 CLG |
1271 | |
1272 | chip->cores = g_malloc0(typesize * chip->nr_cores); | |
1273 | ||
1274 | for (i = 0, core_hwid = 0; (core_hwid < sizeof(chip->cores_mask) * 8) | |
1275 | && (i < chip->nr_cores); core_hwid++) { | |
1276 | char core_name[32]; | |
1277 | void *pnv_core = chip->cores + i * typesize; | |
c035851a | 1278 | uint64_t xscom_core_base; |
d2fd9612 CLG |
1279 | |
1280 | if (!(chip->cores_mask & (1ull << core_hwid))) { | |
1281 | continue; | |
1282 | } | |
1283 | ||
d2fd9612 | 1284 | snprintf(core_name, sizeof(core_name), "core[%d]", core_hwid); |
bc4c406c PMD |
1285 | object_initialize_child(OBJECT(chip), core_name, pnv_core, typesize, |
1286 | typename, &error_fatal, NULL); | |
fe6b6346 | 1287 | object_property_set_int(OBJECT(pnv_core), ms->smp.threads, "nr-threads", |
d2fd9612 CLG |
1288 | &error_fatal); |
1289 | object_property_set_int(OBJECT(pnv_core), core_hwid, | |
1290 | CPU_CORE_PROP_CORE_ID, &error_fatal); | |
1291 | object_property_set_int(OBJECT(pnv_core), | |
1292 | pcc->core_pir(chip, core_hwid), | |
1293 | "pir", &error_fatal); | |
d35aefa9 CLG |
1294 | object_property_add_const_link(OBJECT(pnv_core), "chip", |
1295 | OBJECT(chip), &error_fatal); | |
d2fd9612 CLG |
1296 | object_property_set_bool(OBJECT(pnv_core), true, "realized", |
1297 | &error_fatal); | |
24ece072 CLG |
1298 | |
1299 | /* Each core has an XSCOM MMIO region */ | |
c035851a CLG |
1300 | if (!pnv_chip_is_power9(chip)) { |
1301 | xscom_core_base = PNV_XSCOM_EX_BASE(core_hwid); | |
1302 | } else { | |
5dad902c | 1303 | xscom_core_base = PNV9_XSCOM_EC_BASE(core_hwid); |
c035851a CLG |
1304 | } |
1305 | ||
1306 | pnv_xscom_add_subregion(chip, xscom_core_base, | |
24ece072 | 1307 | &PNV_CORE(pnv_core)->xscom_regs); |
d2fd9612 CLG |
1308 | i++; |
1309 | } | |
51c04728 CLG |
1310 | } |
1311 | ||
1312 | static void pnv_chip_realize(DeviceState *dev, Error **errp) | |
1313 | { | |
1314 | PnvChip *chip = PNV_CHIP(dev); | |
1315 | Error *error = NULL; | |
1316 | ||
51c04728 CLG |
1317 | /* Cores */ |
1318 | pnv_chip_core_realize(chip, &error); | |
1319 | if (error) { | |
1320 | error_propagate(errp, error); | |
1321 | return; | |
1322 | } | |
e997040e CLG |
1323 | } |
1324 | ||
1325 | static Property pnv_chip_properties[] = { | |
1326 | DEFINE_PROP_UINT32("chip-id", PnvChip, chip_id, 0), | |
1327 | DEFINE_PROP_UINT64("ram-start", PnvChip, ram_start, 0), | |
1328 | DEFINE_PROP_UINT64("ram-size", PnvChip, ram_size, 0), | |
397a79e7 CLG |
1329 | DEFINE_PROP_UINT32("nr-cores", PnvChip, nr_cores, 1), |
1330 | DEFINE_PROP_UINT64("cores-mask", PnvChip, cores_mask, 0x0), | |
e997040e CLG |
1331 | DEFINE_PROP_END_OF_LIST(), |
1332 | }; | |
1333 | ||
1334 | static void pnv_chip_class_init(ObjectClass *klass, void *data) | |
1335 | { | |
1336 | DeviceClass *dc = DEVICE_CLASS(klass); | |
1337 | ||
9d169fb3 | 1338 | set_bit(DEVICE_CATEGORY_CPU, dc->categories); |
e997040e CLG |
1339 | dc->realize = pnv_chip_realize; |
1340 | dc->props = pnv_chip_properties; | |
1341 | dc->desc = "PowerNV Chip"; | |
1342 | } | |
1343 | ||
54f59d78 CLG |
1344 | static ICSState *pnv_ics_get(XICSFabric *xi, int irq) |
1345 | { | |
b168a138 | 1346 | PnvMachineState *pnv = PNV_MACHINE(xi); |
54f59d78 CLG |
1347 | int i; |
1348 | ||
1349 | for (i = 0; i < pnv->num_chips; i++) { | |
77864267 CLG |
1350 | Pnv8Chip *chip8 = PNV8_CHIP(pnv->chips[i]); |
1351 | ||
1352 | if (ics_valid_irq(&chip8->psi.ics, irq)) { | |
1353 | return &chip8->psi.ics; | |
54f59d78 CLG |
1354 | } |
1355 | } | |
1356 | return NULL; | |
1357 | } | |
1358 | ||
1359 | static void pnv_ics_resend(XICSFabric *xi) | |
1360 | { | |
b168a138 | 1361 | PnvMachineState *pnv = PNV_MACHINE(xi); |
54f59d78 CLG |
1362 | int i; |
1363 | ||
1364 | for (i = 0; i < pnv->num_chips; i++) { | |
77864267 CLG |
1365 | Pnv8Chip *chip8 = PNV8_CHIP(pnv->chips[i]); |
1366 | ics_resend(&chip8->psi.ics); | |
54f59d78 CLG |
1367 | } |
1368 | } | |
1369 | ||
36fc6f08 CLG |
1370 | static ICPState *pnv_icp_get(XICSFabric *xi, int pir) |
1371 | { | |
1372 | PowerPCCPU *cpu = ppc_get_vcpu_by_pir(pir); | |
1373 | ||
956b8f46 | 1374 | return cpu ? ICP(pnv_cpu_state(cpu)->intc) : NULL; |
36fc6f08 CLG |
1375 | } |
1376 | ||
47fea43a CLG |
1377 | static void pnv_pic_print_info(InterruptStatsProvider *obj, |
1378 | Monitor *mon) | |
1379 | { | |
b168a138 | 1380 | PnvMachineState *pnv = PNV_MACHINE(obj); |
54f59d78 | 1381 | int i; |
47fea43a CLG |
1382 | CPUState *cs; |
1383 | ||
1384 | CPU_FOREACH(cs) { | |
1385 | PowerPCCPU *cpu = POWERPC_CPU(cs); | |
1386 | ||
d8e4aad5 CLG |
1387 | if (pnv_chip_is_power9(pnv->chips[0])) { |
1388 | xive_tctx_pic_print_info(XIVE_TCTX(pnv_cpu_state(cpu)->intc), mon); | |
1389 | } else { | |
1390 | icp_pic_print_info(ICP(pnv_cpu_state(cpu)->intc), mon); | |
1391 | } | |
47fea43a | 1392 | } |
54f59d78 CLG |
1393 | |
1394 | for (i = 0; i < pnv->num_chips; i++) { | |
d8e4aad5 | 1395 | PNV_CHIP_GET_CLASS(pnv->chips[i])->pic_print_info(pnv->chips[i], mon); |
54f59d78 | 1396 | } |
47fea43a CLG |
1397 | } |
1398 | ||
e997040e CLG |
1399 | static void pnv_get_num_chips(Object *obj, Visitor *v, const char *name, |
1400 | void *opaque, Error **errp) | |
1401 | { | |
b168a138 | 1402 | visit_type_uint32(v, name, &PNV_MACHINE(obj)->num_chips, errp); |
e997040e CLG |
1403 | } |
1404 | ||
1405 | static void pnv_set_num_chips(Object *obj, Visitor *v, const char *name, | |
1406 | void *opaque, Error **errp) | |
1407 | { | |
b168a138 | 1408 | PnvMachineState *pnv = PNV_MACHINE(obj); |
e997040e CLG |
1409 | uint32_t num_chips; |
1410 | Error *local_err = NULL; | |
1411 | ||
1412 | visit_type_uint32(v, name, &num_chips, &local_err); | |
1413 | if (local_err) { | |
1414 | error_propagate(errp, local_err); | |
1415 | return; | |
1416 | } | |
1417 | ||
1418 | /* | |
1419 | * TODO: should we decide on how many chips we can create based | |
1420 | * on #cores and Venice vs. Murano vs. Naples chip type etc..., | |
1421 | */ | |
1422 | if (!is_power_of_2(num_chips) || num_chips > 4) { | |
1423 | error_setg(errp, "invalid number of chips: '%d'", num_chips); | |
1424 | return; | |
1425 | } | |
1426 | ||
1427 | pnv->num_chips = num_chips; | |
1428 | } | |
1429 | ||
77864267 | 1430 | static void pnv_machine_instance_init(Object *obj) |
e997040e | 1431 | { |
b168a138 | 1432 | PnvMachineState *pnv = PNV_MACHINE(obj); |
e997040e CLG |
1433 | pnv->num_chips = 1; |
1434 | } | |
1435 | ||
b168a138 | 1436 | static void pnv_machine_class_props_init(ObjectClass *oc) |
e997040e | 1437 | { |
1e507bb0 | 1438 | object_class_property_add(oc, "num-chips", "uint32", |
e997040e CLG |
1439 | pnv_get_num_chips, pnv_set_num_chips, |
1440 | NULL, NULL, NULL); | |
1441 | object_class_property_set_description(oc, "num-chips", | |
1442 | "Specifies the number of processor chips", | |
1443 | NULL); | |
9e933f4a BH |
1444 | } |
1445 | ||
f30c843c | 1446 | static void pnv_machine_power8_class_init(ObjectClass *oc, void *data) |
9e933f4a BH |
1447 | { |
1448 | MachineClass *mc = MACHINE_CLASS(oc); | |
36fc6f08 | 1449 | XICSFabricClass *xic = XICS_FABRIC_CLASS(oc); |
f30c843c CLG |
1450 | |
1451 | mc->desc = "IBM PowerNV (Non-Virtualized) POWER8"; | |
1452 | mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("power8_v2.0"); | |
1453 | ||
1454 | xic->icp_get = pnv_icp_get; | |
1455 | xic->ics_get = pnv_ics_get; | |
1456 | xic->ics_resend = pnv_ics_resend; | |
1457 | } | |
1458 | ||
1459 | static void pnv_machine_power9_class_init(ObjectClass *oc, void *data) | |
1460 | { | |
1461 | MachineClass *mc = MACHINE_CLASS(oc); | |
1462 | ||
1463 | mc->desc = "IBM PowerNV (Non-Virtualized) POWER9"; | |
1464 | mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("power9_v2.0"); | |
1465 | ||
1466 | mc->alias = "powernv"; | |
1467 | } | |
1468 | ||
1469 | static void pnv_machine_class_init(ObjectClass *oc, void *data) | |
1470 | { | |
1471 | MachineClass *mc = MACHINE_CLASS(oc); | |
47fea43a | 1472 | InterruptStatsProviderClass *ispc = INTERRUPT_STATS_PROVIDER_CLASS(oc); |
9e933f4a BH |
1473 | |
1474 | mc->desc = "IBM PowerNV (Non-Virtualized)"; | |
b168a138 CLG |
1475 | mc->init = pnv_init; |
1476 | mc->reset = pnv_reset; | |
9e933f4a | 1477 | mc->max_cpus = MAX_CPUS; |
59b7c1c2 B |
1478 | /* Pnv provides a AHCI device for storage */ |
1479 | mc->block_default_type = IF_IDE; | |
9e933f4a BH |
1480 | mc->no_parallel = 1; |
1481 | mc->default_boot_order = NULL; | |
f1d18b0a JS |
1482 | /* |
1483 | * RAM defaults to less than 2048 for 32-bit hosts, and large | |
1484 | * enough to fit the maximum initrd size at it's load address | |
1485 | */ | |
1486 | mc->default_ram_size = INITRD_LOAD_ADDR + INITRD_MAX_SIZE; | |
47fea43a | 1487 | ispc->print_info = pnv_pic_print_info; |
e997040e | 1488 | |
b168a138 | 1489 | pnv_machine_class_props_init(oc); |
9e933f4a BH |
1490 | } |
1491 | ||
77864267 CLG |
1492 | #define DEFINE_PNV8_CHIP_TYPE(type, class_initfn) \ |
1493 | { \ | |
1494 | .name = type, \ | |
1495 | .class_init = class_initfn, \ | |
1496 | .parent = TYPE_PNV8_CHIP, \ | |
1497 | } | |
1498 | ||
1499 | #define DEFINE_PNV9_CHIP_TYPE(type, class_initfn) \ | |
1500 | { \ | |
1501 | .name = type, \ | |
1502 | .class_init = class_initfn, \ | |
1503 | .parent = TYPE_PNV9_CHIP, \ | |
beba5c0f IM |
1504 | } |
1505 | ||
1506 | static const TypeInfo types[] = { | |
1aba8716 CLG |
1507 | { |
1508 | .name = MACHINE_TYPE_NAME("powernv9"), | |
1509 | .parent = TYPE_PNV_MACHINE, | |
1510 | .class_init = pnv_machine_power9_class_init, | |
1511 | }, | |
1512 | { | |
1513 | .name = MACHINE_TYPE_NAME("powernv8"), | |
1514 | .parent = TYPE_PNV_MACHINE, | |
1515 | .class_init = pnv_machine_power8_class_init, | |
1516 | .interfaces = (InterfaceInfo[]) { | |
1517 | { TYPE_XICS_FABRIC }, | |
1518 | { }, | |
1519 | }, | |
1520 | }, | |
beba5c0f | 1521 | { |
b168a138 | 1522 | .name = TYPE_PNV_MACHINE, |
beba5c0f | 1523 | .parent = TYPE_MACHINE, |
f30c843c | 1524 | .abstract = true, |
beba5c0f | 1525 | .instance_size = sizeof(PnvMachineState), |
77864267 | 1526 | .instance_init = pnv_machine_instance_init, |
b168a138 | 1527 | .class_init = pnv_machine_class_init, |
beba5c0f | 1528 | .interfaces = (InterfaceInfo[]) { |
beba5c0f IM |
1529 | { TYPE_INTERRUPT_STATS_PROVIDER }, |
1530 | { }, | |
1531 | }, | |
36fc6f08 | 1532 | }, |
beba5c0f IM |
1533 | { |
1534 | .name = TYPE_PNV_CHIP, | |
1535 | .parent = TYPE_SYS_BUS_DEVICE, | |
1536 | .class_init = pnv_chip_class_init, | |
beba5c0f IM |
1537 | .instance_size = sizeof(PnvChip), |
1538 | .class_size = sizeof(PnvChipClass), | |
1539 | .abstract = true, | |
1540 | }, | |
77864267 CLG |
1541 | |
1542 | /* | |
1543 | * P9 chip and variants | |
1544 | */ | |
1545 | { | |
1546 | .name = TYPE_PNV9_CHIP, | |
1547 | .parent = TYPE_PNV_CHIP, | |
1548 | .instance_init = pnv_chip_power9_instance_init, | |
1549 | .instance_size = sizeof(Pnv9Chip), | |
1550 | }, | |
1551 | DEFINE_PNV9_CHIP_TYPE(TYPE_PNV_CHIP_POWER9, pnv_chip_power9_class_init), | |
1552 | ||
1553 | /* | |
1554 | * P8 chip and variants | |
1555 | */ | |
1556 | { | |
1557 | .name = TYPE_PNV8_CHIP, | |
1558 | .parent = TYPE_PNV_CHIP, | |
1559 | .instance_init = pnv_chip_power8_instance_init, | |
1560 | .instance_size = sizeof(Pnv8Chip), | |
1561 | }, | |
1562 | DEFINE_PNV8_CHIP_TYPE(TYPE_PNV_CHIP_POWER8, pnv_chip_power8_class_init), | |
1563 | DEFINE_PNV8_CHIP_TYPE(TYPE_PNV_CHIP_POWER8E, pnv_chip_power8e_class_init), | |
1564 | DEFINE_PNV8_CHIP_TYPE(TYPE_PNV_CHIP_POWER8NVL, | |
1565 | pnv_chip_power8nvl_class_init), | |
9e933f4a BH |
1566 | }; |
1567 | ||
beba5c0f | 1568 | DEFINE_TYPES(types) |