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