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