2 * QEMU PowerPC PowerNV machine model
4 * Copyright (c) 2016, IBM Corporation.
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.
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.
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/>.
20 #include "qemu/osdep.h"
21 #include "qemu/units.h"
22 #include "qapi/error.h"
23 #include "sysemu/sysemu.h"
24 #include "sysemu/numa.h"
25 #include "sysemu/cpus.h"
27 #include "target/ppc/cpu.h"
29 #include "hw/ppc/fdt.h"
30 #include "hw/ppc/ppc.h"
31 #include "hw/ppc/pnv.h"
32 #include "hw/ppc/pnv_core.h"
33 #include "hw/loader.h"
34 #include "exec/address-spaces.h"
35 #include "qapi/visitor.h"
36 #include "monitor/monitor.h"
37 #include "hw/intc/intc.h"
38 #include "hw/ipmi/ipmi.h"
39 #include "target/ppc/mmu-hash64.h"
41 #include "hw/ppc/xics.h"
42 #include "hw/ppc/pnv_xscom.h"
44 #include "hw/isa/isa.h"
45 #include "hw/char/serial.h"
46 #include "hw/timer/mc146818rtc.h"
50 #define FDT_MAX_SIZE (1 * MiB)
52 #define FW_FILE_NAME "skiboot.lid"
53 #define FW_LOAD_ADDR 0x0
54 #define FW_MAX_SIZE (4 * MiB)
56 #define KERNEL_LOAD_ADDR 0x20000000
57 #define KERNEL_MAX_SIZE (256 * MiB)
58 #define INITRD_LOAD_ADDR 0x60000000
59 #define INITRD_MAX_SIZE (256 * MiB)
61 static const char *pnv_chip_core_typename(const PnvChip
*o
)
63 const char *chip_type
= object_class_get_name(object_get_class(OBJECT(o
)));
64 int len
= strlen(chip_type
) - strlen(PNV_CHIP_TYPE_SUFFIX
);
65 char *s
= g_strdup_printf(PNV_CORE_TYPE_NAME("%.*s"), len
, chip_type
);
66 const char *core_type
= object_class_get_name(object_class_by_name(s
));
72 * On Power Systems E880 (POWER8), the max cpus (threads) should be :
73 * 4 * 4 sockets * 12 cores * 8 threads = 1536
79 * Memory nodes are created by hostboot, one for each range of memory
80 * that has a different "affinity". In practice, it means one range
83 static void pnv_dt_memory(void *fdt
, int chip_id
, hwaddr start
, hwaddr size
)
86 uint64_t mem_reg_property
[2];
89 mem_reg_property
[0] = cpu_to_be64(start
);
90 mem_reg_property
[1] = cpu_to_be64(size
);
92 mem_name
= g_strdup_printf("memory@%"HWADDR_PRIx
, start
);
93 off
= fdt_add_subnode(fdt
, 0, mem_name
);
96 _FDT((fdt_setprop_string(fdt
, off
, "device_type", "memory")));
97 _FDT((fdt_setprop(fdt
, off
, "reg", mem_reg_property
,
98 sizeof(mem_reg_property
))));
99 _FDT((fdt_setprop_cell(fdt
, off
, "ibm,chip-id", chip_id
)));
102 static int get_cpus_node(void *fdt
)
104 int cpus_offset
= fdt_path_offset(fdt
, "/cpus");
106 if (cpus_offset
< 0) {
107 cpus_offset
= fdt_add_subnode(fdt
, 0, "cpus");
109 _FDT((fdt_setprop_cell(fdt
, cpus_offset
, "#address-cells", 0x1)));
110 _FDT((fdt_setprop_cell(fdt
, cpus_offset
, "#size-cells", 0x0)));
118 * The PowerNV cores (and threads) need to use real HW ids and not an
119 * incremental index like it has been done on other platforms. This HW
120 * id is stored in the CPU PIR, it is used to create cpu nodes in the
121 * device tree, used in XSCOM to address cores and in interrupt
124 static void pnv_dt_core(PnvChip
*chip
, PnvCore
*pc
, void *fdt
)
126 PowerPCCPU
*cpu
= pc
->threads
[0];
127 CPUState
*cs
= CPU(cpu
);
128 DeviceClass
*dc
= DEVICE_GET_CLASS(cs
);
129 int smt_threads
= CPU_CORE(pc
)->nr_threads
;
130 CPUPPCState
*env
= &cpu
->env
;
131 PowerPCCPUClass
*pcc
= POWERPC_CPU_GET_CLASS(cs
);
132 uint32_t servers_prop
[smt_threads
];
134 uint32_t segs
[] = {cpu_to_be32(28), cpu_to_be32(40),
135 0xffffffff, 0xffffffff};
136 uint32_t tbfreq
= PNV_TIMEBASE_FREQ
;
137 uint32_t cpufreq
= 1000000000;
138 uint32_t page_sizes_prop
[64];
139 size_t page_sizes_prop_size
;
140 const uint8_t pa_features
[] = { 24, 0,
141 0xf6, 0x3f, 0xc7, 0xc0, 0x80, 0xf0,
142 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
143 0x00, 0x00, 0x00, 0x00, 0x80, 0x00,
144 0x80, 0x00, 0x80, 0x00, 0x80, 0x00 };
147 int cpus_offset
= get_cpus_node(fdt
);
149 nodename
= g_strdup_printf("%s@%x", dc
->fw_name
, pc
->pir
);
150 offset
= fdt_add_subnode(fdt
, cpus_offset
, nodename
);
154 _FDT((fdt_setprop_cell(fdt
, offset
, "ibm,chip-id", chip
->chip_id
)));
156 _FDT((fdt_setprop_cell(fdt
, offset
, "reg", pc
->pir
)));
157 _FDT((fdt_setprop_cell(fdt
, offset
, "ibm,pir", pc
->pir
)));
158 _FDT((fdt_setprop_string(fdt
, offset
, "device_type", "cpu")));
160 _FDT((fdt_setprop_cell(fdt
, offset
, "cpu-version", env
->spr
[SPR_PVR
])));
161 _FDT((fdt_setprop_cell(fdt
, offset
, "d-cache-block-size",
162 env
->dcache_line_size
)));
163 _FDT((fdt_setprop_cell(fdt
, offset
, "d-cache-line-size",
164 env
->dcache_line_size
)));
165 _FDT((fdt_setprop_cell(fdt
, offset
, "i-cache-block-size",
166 env
->icache_line_size
)));
167 _FDT((fdt_setprop_cell(fdt
, offset
, "i-cache-line-size",
168 env
->icache_line_size
)));
170 if (pcc
->l1_dcache_size
) {
171 _FDT((fdt_setprop_cell(fdt
, offset
, "d-cache-size",
172 pcc
->l1_dcache_size
)));
174 warn_report("Unknown L1 dcache size for cpu");
176 if (pcc
->l1_icache_size
) {
177 _FDT((fdt_setprop_cell(fdt
, offset
, "i-cache-size",
178 pcc
->l1_icache_size
)));
180 warn_report("Unknown L1 icache size for cpu");
183 _FDT((fdt_setprop_cell(fdt
, offset
, "timebase-frequency", tbfreq
)));
184 _FDT((fdt_setprop_cell(fdt
, offset
, "clock-frequency", cpufreq
)));
185 _FDT((fdt_setprop_cell(fdt
, offset
, "ibm,slb-size", cpu
->hash64_opts
->slb_size
)));
186 _FDT((fdt_setprop_string(fdt
, offset
, "status", "okay")));
187 _FDT((fdt_setprop(fdt
, offset
, "64-bit", NULL
, 0)));
189 if (env
->spr_cb
[SPR_PURR
].oea_read
) {
190 _FDT((fdt_setprop(fdt
, offset
, "ibm,purr", NULL
, 0)));
193 if (ppc_hash64_has(cpu
, PPC_HASH64_1TSEG
)) {
194 _FDT((fdt_setprop(fdt
, offset
, "ibm,processor-segment-sizes",
195 segs
, sizeof(segs
))));
198 /* Advertise VMX/VSX (vector extensions) if available
199 * 0 / no property == no vector extensions
200 * 1 == VMX / Altivec available
201 * 2 == VSX available */
202 if (env
->insns_flags
& PPC_ALTIVEC
) {
203 uint32_t vmx
= (env
->insns_flags2
& PPC2_VSX
) ? 2 : 1;
205 _FDT((fdt_setprop_cell(fdt
, offset
, "ibm,vmx", vmx
)));
208 /* Advertise DFP (Decimal Floating Point) if available
209 * 0 / no property == no DFP
210 * 1 == DFP available */
211 if (env
->insns_flags2
& PPC2_DFP
) {
212 _FDT((fdt_setprop_cell(fdt
, offset
, "ibm,dfp", 1)));
215 page_sizes_prop_size
= ppc_create_page_sizes_prop(cpu
, page_sizes_prop
,
216 sizeof(page_sizes_prop
));
217 if (page_sizes_prop_size
) {
218 _FDT((fdt_setprop(fdt
, offset
, "ibm,segment-page-sizes",
219 page_sizes_prop
, page_sizes_prop_size
)));
222 _FDT((fdt_setprop(fdt
, offset
, "ibm,pa-features",
223 pa_features
, sizeof(pa_features
))));
225 /* Build interrupt servers properties */
226 for (i
= 0; i
< smt_threads
; i
++) {
227 servers_prop
[i
] = cpu_to_be32(pc
->pir
+ i
);
229 _FDT((fdt_setprop(fdt
, offset
, "ibm,ppc-interrupt-server#s",
230 servers_prop
, sizeof(servers_prop
))));
233 static void pnv_dt_icp(PnvChip
*chip
, void *fdt
, uint32_t pir
,
236 uint64_t addr
= PNV_ICP_BASE(chip
) | (pir
<< 12);
238 const char compat
[] = "IBM,power8-icp\0IBM,ppc-xicp";
239 uint32_t irange
[2], i
, rsize
;
243 irange
[0] = cpu_to_be32(pir
);
244 irange
[1] = cpu_to_be32(nr_threads
);
246 rsize
= sizeof(uint64_t) * 2 * nr_threads
;
247 reg
= g_malloc(rsize
);
248 for (i
= 0; i
< nr_threads
; i
++) {
249 reg
[i
* 2] = cpu_to_be64(addr
| ((pir
+ i
) * 0x1000));
250 reg
[i
* 2 + 1] = cpu_to_be64(0x1000);
253 name
= g_strdup_printf("interrupt-controller@%"PRIX64
, addr
);
254 offset
= fdt_add_subnode(fdt
, 0, name
);
258 _FDT((fdt_setprop(fdt
, offset
, "compatible", compat
, sizeof(compat
))));
259 _FDT((fdt_setprop(fdt
, offset
, "reg", reg
, rsize
)));
260 _FDT((fdt_setprop_string(fdt
, offset
, "device_type",
261 "PowerPC-External-Interrupt-Presentation")));
262 _FDT((fdt_setprop(fdt
, offset
, "interrupt-controller", NULL
, 0)));
263 _FDT((fdt_setprop(fdt
, offset
, "ibm,interrupt-server-ranges",
264 irange
, sizeof(irange
))));
265 _FDT((fdt_setprop_cell(fdt
, offset
, "#interrupt-cells", 1)));
266 _FDT((fdt_setprop_cell(fdt
, offset
, "#address-cells", 0)));
270 static void pnv_chip_power8_dt_populate(PnvChip
*chip
, void *fdt
)
272 const char *typename
= pnv_chip_core_typename(chip
);
273 size_t typesize
= object_type_get_instance_size(typename
);
276 pnv_dt_xscom(chip
, fdt
, 0);
278 for (i
= 0; i
< chip
->nr_cores
; i
++) {
279 PnvCore
*pnv_core
= PNV_CORE(chip
->cores
+ i
* typesize
);
281 pnv_dt_core(chip
, pnv_core
, fdt
);
283 /* Interrupt Control Presenters (ICP). One per core. */
284 pnv_dt_icp(chip
, fdt
, pnv_core
->pir
, CPU_CORE(pnv_core
)->nr_threads
);
287 if (chip
->ram_size
) {
288 pnv_dt_memory(fdt
, chip
->chip_id
, chip
->ram_start
, chip
->ram_size
);
292 static void pnv_chip_power9_dt_populate(PnvChip
*chip
, void *fdt
)
294 const char *typename
= pnv_chip_core_typename(chip
);
295 size_t typesize
= object_type_get_instance_size(typename
);
298 pnv_dt_xscom(chip
, fdt
, 0);
300 for (i
= 0; i
< chip
->nr_cores
; i
++) {
301 PnvCore
*pnv_core
= PNV_CORE(chip
->cores
+ i
* typesize
);
303 pnv_dt_core(chip
, pnv_core
, fdt
);
306 if (chip
->ram_size
) {
307 pnv_dt_memory(fdt
, chip
->chip_id
, chip
->ram_start
, chip
->ram_size
);
310 pnv_dt_lpc(chip
, fdt
, 0);
313 static void pnv_dt_rtc(ISADevice
*d
, void *fdt
, int lpc_off
)
315 uint32_t io_base
= d
->ioport_id
;
316 uint32_t io_regs
[] = {
318 cpu_to_be32(io_base
),
324 name
= g_strdup_printf("%s@i%x", qdev_fw_name(DEVICE(d
)), io_base
);
325 node
= fdt_add_subnode(fdt
, lpc_off
, name
);
329 _FDT((fdt_setprop(fdt
, node
, "reg", io_regs
, sizeof(io_regs
))));
330 _FDT((fdt_setprop_string(fdt
, node
, "compatible", "pnpPNP,b00")));
333 static void pnv_dt_serial(ISADevice
*d
, void *fdt
, int lpc_off
)
335 const char compatible
[] = "ns16550\0pnpPNP,501";
336 uint32_t io_base
= d
->ioport_id
;
337 uint32_t io_regs
[] = {
339 cpu_to_be32(io_base
),
345 name
= g_strdup_printf("%s@i%x", qdev_fw_name(DEVICE(d
)), io_base
);
346 node
= fdt_add_subnode(fdt
, lpc_off
, name
);
350 _FDT((fdt_setprop(fdt
, node
, "reg", io_regs
, sizeof(io_regs
))));
351 _FDT((fdt_setprop(fdt
, node
, "compatible", compatible
,
352 sizeof(compatible
))));
354 _FDT((fdt_setprop_cell(fdt
, node
, "clock-frequency", 1843200)));
355 _FDT((fdt_setprop_cell(fdt
, node
, "current-speed", 115200)));
356 _FDT((fdt_setprop_cell(fdt
, node
, "interrupts", d
->isairq
[0])));
357 _FDT((fdt_setprop_cell(fdt
, node
, "interrupt-parent",
358 fdt_get_phandle(fdt
, lpc_off
))));
360 /* This is needed by Linux */
361 _FDT((fdt_setprop_string(fdt
, node
, "device_type", "serial")));
364 static void pnv_dt_ipmi_bt(ISADevice
*d
, void *fdt
, int lpc_off
)
366 const char compatible
[] = "bt\0ipmi-bt";
368 uint32_t io_regs
[] = {
370 0, /* 'io_base' retrieved from the 'ioport' property of 'isa-ipmi-bt' */
377 io_base
= object_property_get_int(OBJECT(d
), "ioport", &error_fatal
);
378 io_regs
[1] = cpu_to_be32(io_base
);
380 irq
= object_property_get_int(OBJECT(d
), "irq", &error_fatal
);
382 name
= g_strdup_printf("%s@i%x", qdev_fw_name(DEVICE(d
)), io_base
);
383 node
= fdt_add_subnode(fdt
, lpc_off
, name
);
387 _FDT((fdt_setprop(fdt
, node
, "reg", io_regs
, sizeof(io_regs
))));
388 _FDT((fdt_setprop(fdt
, node
, "compatible", compatible
,
389 sizeof(compatible
))));
391 /* Mark it as reserved to avoid Linux trying to claim it */
392 _FDT((fdt_setprop_string(fdt
, node
, "status", "reserved")));
393 _FDT((fdt_setprop_cell(fdt
, node
, "interrupts", irq
)));
394 _FDT((fdt_setprop_cell(fdt
, node
, "interrupt-parent",
395 fdt_get_phandle(fdt
, lpc_off
))));
398 typedef struct ForeachPopulateArgs
{
401 } ForeachPopulateArgs
;
403 static int pnv_dt_isa_device(DeviceState
*dev
, void *opaque
)
405 ForeachPopulateArgs
*args
= opaque
;
406 ISADevice
*d
= ISA_DEVICE(dev
);
408 if (object_dynamic_cast(OBJECT(dev
), TYPE_MC146818_RTC
)) {
409 pnv_dt_rtc(d
, args
->fdt
, args
->offset
);
410 } else if (object_dynamic_cast(OBJECT(dev
), TYPE_ISA_SERIAL
)) {
411 pnv_dt_serial(d
, args
->fdt
, args
->offset
);
412 } else if (object_dynamic_cast(OBJECT(dev
), "isa-ipmi-bt")) {
413 pnv_dt_ipmi_bt(d
, args
->fdt
, args
->offset
);
415 error_report("unknown isa device %s@i%x", qdev_fw_name(dev
),
422 /* The default LPC bus of a multichip system is on chip 0. It's
423 * recognized by the firmware (skiboot) using a "primary" property.
425 static void pnv_dt_isa(PnvMachineState
*pnv
, void *fdt
)
427 int isa_offset
= fdt_path_offset(fdt
, pnv
->chips
[0]->dt_isa_nodename
);
428 ForeachPopulateArgs args
= {
430 .offset
= isa_offset
,
433 _FDT((fdt_setprop(fdt
, isa_offset
, "primary", NULL
, 0)));
435 /* ISA devices are not necessarily parented to the ISA bus so we
436 * can not use object_child_foreach() */
437 qbus_walk_children(BUS(pnv
->isa_bus
), pnv_dt_isa_device
, NULL
, NULL
, NULL
,
441 static void pnv_dt_power_mgt(void *fdt
)
445 off
= fdt_add_subnode(fdt
, 0, "ibm,opal");
446 off
= fdt_add_subnode(fdt
, off
, "power-mgt");
448 _FDT(fdt_setprop_cell(fdt
, off
, "ibm,enabled-stop-levels", 0xc0000000));
451 static void *pnv_dt_create(MachineState
*machine
)
453 const char plat_compat
[] = "qemu,powernv\0ibm,powernv";
454 PnvMachineState
*pnv
= PNV_MACHINE(machine
);
460 fdt
= g_malloc0(FDT_MAX_SIZE
);
461 _FDT((fdt_create_empty_tree(fdt
, FDT_MAX_SIZE
)));
464 _FDT((fdt_setprop_cell(fdt
, 0, "#address-cells", 0x2)));
465 _FDT((fdt_setprop_cell(fdt
, 0, "#size-cells", 0x2)));
466 _FDT((fdt_setprop_string(fdt
, 0, "model",
467 "IBM PowerNV (emulated by qemu)")));
468 _FDT((fdt_setprop(fdt
, 0, "compatible", plat_compat
,
469 sizeof(plat_compat
))));
471 buf
= qemu_uuid_unparse_strdup(&qemu_uuid
);
472 _FDT((fdt_setprop_string(fdt
, 0, "vm,uuid", buf
)));
474 _FDT((fdt_property_string(fdt
, "system-id", buf
)));
478 off
= fdt_add_subnode(fdt
, 0, "chosen");
479 if (machine
->kernel_cmdline
) {
480 _FDT((fdt_setprop_string(fdt
, off
, "bootargs",
481 machine
->kernel_cmdline
)));
484 if (pnv
->initrd_size
) {
485 uint32_t start_prop
= cpu_to_be32(pnv
->initrd_base
);
486 uint32_t end_prop
= cpu_to_be32(pnv
->initrd_base
+ pnv
->initrd_size
);
488 _FDT((fdt_setprop(fdt
, off
, "linux,initrd-start",
489 &start_prop
, sizeof(start_prop
))));
490 _FDT((fdt_setprop(fdt
, off
, "linux,initrd-end",
491 &end_prop
, sizeof(end_prop
))));
494 /* Populate device tree for each chip */
495 for (i
= 0; i
< pnv
->num_chips
; i
++) {
496 PNV_CHIP_GET_CLASS(pnv
->chips
[i
])->dt_populate(pnv
->chips
[i
], fdt
);
499 /* Populate ISA devices on chip 0 */
500 pnv_dt_isa(pnv
, fdt
);
503 pnv_dt_bmc_sensors(pnv
->bmc
, fdt
);
506 /* Create an extra node for power management on Power9 */
507 if (pnv_is_power9(pnv
)) {
508 pnv_dt_power_mgt(fdt
);
514 static void pnv_powerdown_notify(Notifier
*n
, void *opaque
)
516 PnvMachineState
*pnv
= PNV_MACHINE(qdev_get_machine());
519 pnv_bmc_powerdown(pnv
->bmc
);
523 static void pnv_reset(void)
525 MachineState
*machine
= MACHINE(qdev_get_machine());
526 PnvMachineState
*pnv
= PNV_MACHINE(machine
);
530 qemu_devices_reset();
532 /* OpenPOWER systems have a BMC, which can be defined on the
535 * -device ipmi-bmc-sim,id=bmc0
537 * This is the internal simulator but it could also be an external
540 obj
= object_resolve_path_type("", "ipmi-bmc-sim", NULL
);
542 pnv
->bmc
= IPMI_BMC(obj
);
545 fdt
= pnv_dt_create(machine
);
547 /* Pack resulting tree */
548 _FDT((fdt_pack(fdt
)));
550 cpu_physical_memory_write(PNV_FDT_ADDR
, fdt
, fdt_totalsize(fdt
));
553 static ISABus
*pnv_chip_power8_isa_create(PnvChip
*chip
, Error
**errp
)
555 Pnv8Chip
*chip8
= PNV8_CHIP(chip
);
556 return pnv_lpc_isa_create(&chip8
->lpc
, true, errp
);
559 static ISABus
*pnv_chip_power8nvl_isa_create(PnvChip
*chip
, Error
**errp
)
561 Pnv8Chip
*chip8
= PNV8_CHIP(chip
);
562 return pnv_lpc_isa_create(&chip8
->lpc
, false, errp
);
565 static ISABus
*pnv_chip_power9_isa_create(PnvChip
*chip
, Error
**errp
)
567 Pnv9Chip
*chip9
= PNV9_CHIP(chip
);
568 return pnv_lpc_isa_create(&chip9
->lpc
, false, errp
);
571 static ISABus
*pnv_isa_create(PnvChip
*chip
, Error
**errp
)
573 return PNV_CHIP_GET_CLASS(chip
)->isa_create(chip
, errp
);
576 static void pnv_chip_power8_pic_print_info(PnvChip
*chip
, Monitor
*mon
)
578 Pnv8Chip
*chip8
= PNV8_CHIP(chip
);
580 ics_pic_print_info(&chip8
->psi
.ics
, mon
);
583 static void pnv_chip_power9_pic_print_info(PnvChip
*chip
, Monitor
*mon
)
585 Pnv9Chip
*chip9
= PNV9_CHIP(chip
);
587 pnv_xive_pic_print_info(&chip9
->xive
, mon
);
588 pnv_psi_pic_print_info(&chip9
->psi
, mon
);
591 static void pnv_init(MachineState
*machine
)
593 PnvMachineState
*pnv
= PNV_MACHINE(machine
);
601 if (machine
->ram_size
< (1 * GiB
)) {
602 warn_report("skiboot may not work with < 1GB of RAM");
605 ram
= g_new(MemoryRegion
, 1);
606 memory_region_allocate_system_memory(ram
, NULL
, "pnv.ram",
608 memory_region_add_subregion(get_system_memory(), 0, ram
);
610 /* load skiboot firmware */
611 if (bios_name
== NULL
) {
612 bios_name
= FW_FILE_NAME
;
615 fw_filename
= qemu_find_file(QEMU_FILE_TYPE_BIOS
, bios_name
);
617 error_report("Could not find OPAL firmware '%s'", bios_name
);
621 fw_size
= load_image_targphys(fw_filename
, FW_LOAD_ADDR
, FW_MAX_SIZE
);
623 error_report("Could not load OPAL firmware '%s'", fw_filename
);
629 if (machine
->kernel_filename
) {
632 kernel_size
= load_image_targphys(machine
->kernel_filename
,
633 KERNEL_LOAD_ADDR
, KERNEL_MAX_SIZE
);
634 if (kernel_size
< 0) {
635 error_report("Could not load kernel '%s'",
636 machine
->kernel_filename
);
642 if (machine
->initrd_filename
) {
643 pnv
->initrd_base
= INITRD_LOAD_ADDR
;
644 pnv
->initrd_size
= load_image_targphys(machine
->initrd_filename
,
645 pnv
->initrd_base
, INITRD_MAX_SIZE
);
646 if (pnv
->initrd_size
< 0) {
647 error_report("Could not load initial ram disk '%s'",
648 machine
->initrd_filename
);
653 /* Create the processor chips */
654 i
= strlen(machine
->cpu_type
) - strlen(POWERPC_CPU_TYPE_SUFFIX
);
655 chip_typename
= g_strdup_printf(PNV_CHIP_TYPE_NAME("%.*s"),
656 i
, machine
->cpu_type
);
657 if (!object_class_by_name(chip_typename
)) {
658 error_report("invalid CPU model '%.*s' for %s machine",
659 i
, machine
->cpu_type
, MACHINE_GET_CLASS(machine
)->name
);
663 pnv
->chips
= g_new0(PnvChip
*, pnv
->num_chips
);
664 for (i
= 0; i
< pnv
->num_chips
; i
++) {
666 Object
*chip
= object_new(chip_typename
);
668 pnv
->chips
[i
] = PNV_CHIP(chip
);
670 /* TODO: put all the memory in one node on chip 0 until we find a
671 * way to specify different ranges for each chip
674 object_property_set_int(chip
, machine
->ram_size
, "ram-size",
678 snprintf(chip_name
, sizeof(chip_name
), "chip[%d]", PNV_CHIP_HWID(i
));
679 object_property_add_child(OBJECT(pnv
), chip_name
, chip
, &error_fatal
);
680 object_property_set_int(chip
, PNV_CHIP_HWID(i
), "chip-id",
682 object_property_set_int(chip
, smp_cores
, "nr-cores", &error_fatal
);
683 object_property_set_bool(chip
, true, "realized", &error_fatal
);
685 g_free(chip_typename
);
687 /* Instantiate ISA bus on chip 0 */
688 pnv
->isa_bus
= pnv_isa_create(pnv
->chips
[0], &error_fatal
);
690 /* Create serial port */
691 serial_hds_isa_init(pnv
->isa_bus
, 0, MAX_ISA_SERIAL_PORTS
);
693 /* Create an RTC ISA device too */
694 mc146818_rtc_init(pnv
->isa_bus
, 2000, NULL
);
696 /* OpenPOWER systems use a IPMI SEL Event message to notify the
697 * host to powerdown */
698 pnv
->powerdown_notifier
.notify
= pnv_powerdown_notify
;
699 qemu_register_powerdown_notifier(&pnv
->powerdown_notifier
);
703 * 0:21 Reserved - Read as zeros
708 static uint32_t pnv_chip_core_pir_p8(PnvChip
*chip
, uint32_t core_id
)
710 return (chip
->chip_id
<< 7) | (core_id
<< 3);
713 static void pnv_chip_power8_intc_create(PnvChip
*chip
, PowerPCCPU
*cpu
,
716 Error
*local_err
= NULL
;
718 PnvCPUState
*pnv_cpu
= pnv_cpu_state(cpu
);
720 obj
= icp_create(OBJECT(cpu
), TYPE_PNV_ICP
, XICS_FABRIC(qdev_get_machine()),
723 error_propagate(errp
, local_err
);
731 * 0:48 Reserved - Read as zeroes
734 * 56 Reserved - Read as zero
738 * We only care about the lower bits. uint32_t is fine for the moment.
740 static uint32_t pnv_chip_core_pir_p9(PnvChip
*chip
, uint32_t core_id
)
742 return (chip
->chip_id
<< 8) | (core_id
<< 2);
745 static void pnv_chip_power9_intc_create(PnvChip
*chip
, PowerPCCPU
*cpu
,
748 Pnv9Chip
*chip9
= PNV9_CHIP(chip
);
749 Error
*local_err
= NULL
;
751 PnvCPUState
*pnv_cpu
= pnv_cpu_state(cpu
);
754 * The core creates its interrupt presenter but the XIVE interrupt
755 * controller object is initialized afterwards. Hopefully, it's
756 * only used at runtime.
758 obj
= xive_tctx_create(OBJECT(cpu
), XIVE_ROUTER(&chip9
->xive
), errp
);
760 error_propagate(errp
, local_err
);
767 /* Allowed core identifiers on a POWER8 Processor Chip :
776 * <EX7,8 reserved> <reserved>
785 #define POWER8E_CORE_MASK (0x7070ull)
786 #define POWER8_CORE_MASK (0x7e7eull)
789 * POWER9 has 24 cores, ids starting at 0x0
791 #define POWER9_CORE_MASK (0xffffffffffffffull)
793 static void pnv_chip_power8_instance_init(Object
*obj
)
795 Pnv8Chip
*chip8
= PNV8_CHIP(obj
);
797 object_initialize_child(obj
, "psi", &chip8
->psi
, sizeof(chip8
->psi
),
798 TYPE_PNV8_PSI
, &error_abort
, NULL
);
799 object_property_add_const_link(OBJECT(&chip8
->psi
), "xics",
800 OBJECT(qdev_get_machine()), &error_abort
);
802 object_initialize_child(obj
, "lpc", &chip8
->lpc
, sizeof(chip8
->lpc
),
803 TYPE_PNV8_LPC
, &error_abort
, NULL
);
804 object_property_add_const_link(OBJECT(&chip8
->lpc
), "psi",
805 OBJECT(&chip8
->psi
), &error_abort
);
807 object_initialize_child(obj
, "occ", &chip8
->occ
, sizeof(chip8
->occ
),
808 TYPE_PNV8_OCC
, &error_abort
, NULL
);
809 object_property_add_const_link(OBJECT(&chip8
->occ
), "psi",
810 OBJECT(&chip8
->psi
), &error_abort
);
813 static void pnv_chip_icp_realize(Pnv8Chip
*chip8
, Error
**errp
)
815 PnvChip
*chip
= PNV_CHIP(chip8
);
816 PnvChipClass
*pcc
= PNV_CHIP_GET_CLASS(chip
);
817 const char *typename
= pnv_chip_core_typename(chip
);
818 size_t typesize
= object_type_get_instance_size(typename
);
821 XICSFabric
*xi
= XICS_FABRIC(qdev_get_machine());
823 name
= g_strdup_printf("icp-%x", chip
->chip_id
);
824 memory_region_init(&chip8
->icp_mmio
, OBJECT(chip
), name
, PNV_ICP_SIZE
);
825 sysbus_init_mmio(SYS_BUS_DEVICE(chip
), &chip8
->icp_mmio
);
828 sysbus_mmio_map(SYS_BUS_DEVICE(chip
), 1, PNV_ICP_BASE(chip
));
830 /* Map the ICP registers for each thread */
831 for (i
= 0; i
< chip
->nr_cores
; i
++) {
832 PnvCore
*pnv_core
= PNV_CORE(chip
->cores
+ i
* typesize
);
833 int core_hwid
= CPU_CORE(pnv_core
)->core_id
;
835 for (j
= 0; j
< CPU_CORE(pnv_core
)->nr_threads
; j
++) {
836 uint32_t pir
= pcc
->core_pir(chip
, core_hwid
) + j
;
837 PnvICPState
*icp
= PNV_ICP(xics_icp_get(xi
, pir
));
839 memory_region_add_subregion(&chip8
->icp_mmio
, pir
<< 12,
845 static void pnv_chip_power8_realize(DeviceState
*dev
, Error
**errp
)
847 PnvChipClass
*pcc
= PNV_CHIP_GET_CLASS(dev
);
848 PnvChip
*chip
= PNV_CHIP(dev
);
849 Pnv8Chip
*chip8
= PNV8_CHIP(dev
);
850 Pnv8Psi
*psi8
= &chip8
->psi
;
851 Error
*local_err
= NULL
;
853 pcc
->parent_realize(dev
, &local_err
);
855 error_propagate(errp
, local_err
);
859 /* Processor Service Interface (PSI) Host Bridge */
860 object_property_set_int(OBJECT(&chip8
->psi
), PNV_PSIHB_BASE(chip
),
861 "bar", &error_fatal
);
862 object_property_set_bool(OBJECT(&chip8
->psi
), true, "realized", &local_err
);
864 error_propagate(errp
, local_err
);
867 pnv_xscom_add_subregion(chip
, PNV_XSCOM_PSIHB_BASE
,
868 &PNV_PSI(psi8
)->xscom_regs
);
870 /* Create LPC controller */
871 object_property_set_bool(OBJECT(&chip8
->lpc
), true, "realized",
873 pnv_xscom_add_subregion(chip
, PNV_XSCOM_LPC_BASE
, &chip8
->lpc
.xscom_regs
);
875 chip
->dt_isa_nodename
= g_strdup_printf("/xscom@%" PRIx64
"/isa@%x",
876 (uint64_t) PNV_XSCOM_BASE(chip
),
879 /* Interrupt Management Area. This is the memory region holding
880 * all the Interrupt Control Presenter (ICP) registers */
881 pnv_chip_icp_realize(chip8
, &local_err
);
883 error_propagate(errp
, local_err
);
887 /* Create the simplified OCC model */
888 object_property_set_bool(OBJECT(&chip8
->occ
), true, "realized", &local_err
);
890 error_propagate(errp
, local_err
);
893 pnv_xscom_add_subregion(chip
, PNV_XSCOM_OCC_BASE
, &chip8
->occ
.xscom_regs
);
896 static void pnv_chip_power8e_class_init(ObjectClass
*klass
, void *data
)
898 DeviceClass
*dc
= DEVICE_CLASS(klass
);
899 PnvChipClass
*k
= PNV_CHIP_CLASS(klass
);
901 k
->chip_type
= PNV_CHIP_POWER8E
;
902 k
->chip_cfam_id
= 0x221ef04980000000ull
; /* P8 Murano DD2.1 */
903 k
->cores_mask
= POWER8E_CORE_MASK
;
904 k
->core_pir
= pnv_chip_core_pir_p8
;
905 k
->intc_create
= pnv_chip_power8_intc_create
;
906 k
->isa_create
= pnv_chip_power8_isa_create
;
907 k
->dt_populate
= pnv_chip_power8_dt_populate
;
908 k
->pic_print_info
= pnv_chip_power8_pic_print_info
;
909 k
->xscom_base
= 0x003fc0000000000ull
;
910 dc
->desc
= "PowerNV Chip POWER8E";
912 device_class_set_parent_realize(dc
, pnv_chip_power8_realize
,
916 static void pnv_chip_power8_class_init(ObjectClass
*klass
, void *data
)
918 DeviceClass
*dc
= DEVICE_CLASS(klass
);
919 PnvChipClass
*k
= PNV_CHIP_CLASS(klass
);
921 k
->chip_type
= PNV_CHIP_POWER8
;
922 k
->chip_cfam_id
= 0x220ea04980000000ull
; /* P8 Venice DD2.0 */
923 k
->cores_mask
= POWER8_CORE_MASK
;
924 k
->core_pir
= pnv_chip_core_pir_p8
;
925 k
->intc_create
= pnv_chip_power8_intc_create
;
926 k
->isa_create
= pnv_chip_power8_isa_create
;
927 k
->dt_populate
= pnv_chip_power8_dt_populate
;
928 k
->pic_print_info
= pnv_chip_power8_pic_print_info
;
929 k
->xscom_base
= 0x003fc0000000000ull
;
930 dc
->desc
= "PowerNV Chip POWER8";
932 device_class_set_parent_realize(dc
, pnv_chip_power8_realize
,
936 static void pnv_chip_power8nvl_class_init(ObjectClass
*klass
, void *data
)
938 DeviceClass
*dc
= DEVICE_CLASS(klass
);
939 PnvChipClass
*k
= PNV_CHIP_CLASS(klass
);
941 k
->chip_type
= PNV_CHIP_POWER8NVL
;
942 k
->chip_cfam_id
= 0x120d304980000000ull
; /* P8 Naples DD1.0 */
943 k
->cores_mask
= POWER8_CORE_MASK
;
944 k
->core_pir
= pnv_chip_core_pir_p8
;
945 k
->intc_create
= pnv_chip_power8_intc_create
;
946 k
->isa_create
= pnv_chip_power8nvl_isa_create
;
947 k
->dt_populate
= pnv_chip_power8_dt_populate
;
948 k
->pic_print_info
= pnv_chip_power8_pic_print_info
;
949 k
->xscom_base
= 0x003fc0000000000ull
;
950 dc
->desc
= "PowerNV Chip POWER8NVL";
952 device_class_set_parent_realize(dc
, pnv_chip_power8_realize
,
956 static void pnv_chip_power9_instance_init(Object
*obj
)
958 Pnv9Chip
*chip9
= PNV9_CHIP(obj
);
960 object_initialize_child(obj
, "xive", &chip9
->xive
, sizeof(chip9
->xive
),
961 TYPE_PNV_XIVE
, &error_abort
, NULL
);
962 object_property_add_const_link(OBJECT(&chip9
->xive
), "chip", obj
,
965 object_initialize_child(obj
, "psi", &chip9
->psi
, sizeof(chip9
->psi
),
966 TYPE_PNV9_PSI
, &error_abort
, NULL
);
967 object_property_add_const_link(OBJECT(&chip9
->psi
), "chip", obj
,
970 object_initialize_child(obj
, "lpc", &chip9
->lpc
, sizeof(chip9
->lpc
),
971 TYPE_PNV9_LPC
, &error_abort
, NULL
);
972 object_property_add_const_link(OBJECT(&chip9
->lpc
), "psi",
973 OBJECT(&chip9
->psi
), &error_abort
);
975 object_initialize_child(obj
, "occ", &chip9
->occ
, sizeof(chip9
->occ
),
976 TYPE_PNV9_OCC
, &error_abort
, NULL
);
977 object_property_add_const_link(OBJECT(&chip9
->occ
), "psi",
978 OBJECT(&chip9
->psi
), &error_abort
);
981 static void pnv_chip_quad_realize(Pnv9Chip
*chip9
, Error
**errp
)
983 PnvChip
*chip
= PNV_CHIP(chip9
);
984 const char *typename
= pnv_chip_core_typename(chip
);
985 size_t typesize
= object_type_get_instance_size(typename
);
988 chip9
->nr_quads
= DIV_ROUND_UP(chip
->nr_cores
, 4);
989 chip9
->quads
= g_new0(PnvQuad
, chip9
->nr_quads
);
991 for (i
= 0; i
< chip9
->nr_quads
; i
++) {
993 PnvQuad
*eq
= &chip9
->quads
[i
];
994 PnvCore
*pnv_core
= PNV_CORE(chip
->cores
+ (i
* 4) * typesize
);
995 int core_id
= CPU_CORE(pnv_core
)->core_id
;
997 object_initialize(eq
, sizeof(*eq
), TYPE_PNV_QUAD
);
998 snprintf(eq_name
, sizeof(eq_name
), "eq[%d]", core_id
);
1000 object_property_add_child(OBJECT(chip
), eq_name
, OBJECT(eq
),
1002 object_property_set_int(OBJECT(eq
), core_id
, "id", &error_fatal
);
1003 object_property_set_bool(OBJECT(eq
), true, "realized", &error_fatal
);
1004 object_unref(OBJECT(eq
));
1006 pnv_xscom_add_subregion(chip
, PNV9_XSCOM_EQ_BASE(eq
->id
),
1011 static void pnv_chip_power9_realize(DeviceState
*dev
, Error
**errp
)
1013 PnvChipClass
*pcc
= PNV_CHIP_GET_CLASS(dev
);
1014 Pnv9Chip
*chip9
= PNV9_CHIP(dev
);
1015 PnvChip
*chip
= PNV_CHIP(dev
);
1016 Pnv9Psi
*psi9
= &chip9
->psi
;
1017 Error
*local_err
= NULL
;
1019 pcc
->parent_realize(dev
, &local_err
);
1021 error_propagate(errp
, local_err
);
1025 pnv_chip_quad_realize(chip9
, &local_err
);
1027 error_propagate(errp
, local_err
);
1031 /* XIVE interrupt controller (POWER9) */
1032 object_property_set_int(OBJECT(&chip9
->xive
), PNV9_XIVE_IC_BASE(chip
),
1033 "ic-bar", &error_fatal
);
1034 object_property_set_int(OBJECT(&chip9
->xive
), PNV9_XIVE_VC_BASE(chip
),
1035 "vc-bar", &error_fatal
);
1036 object_property_set_int(OBJECT(&chip9
->xive
), PNV9_XIVE_PC_BASE(chip
),
1037 "pc-bar", &error_fatal
);
1038 object_property_set_int(OBJECT(&chip9
->xive
), PNV9_XIVE_TM_BASE(chip
),
1039 "tm-bar", &error_fatal
);
1040 object_property_set_bool(OBJECT(&chip9
->xive
), true, "realized",
1043 error_propagate(errp
, local_err
);
1046 pnv_xscom_add_subregion(chip
, PNV9_XSCOM_XIVE_BASE
,
1047 &chip9
->xive
.xscom_regs
);
1049 /* Processor Service Interface (PSI) Host Bridge */
1050 object_property_set_int(OBJECT(&chip9
->psi
), PNV9_PSIHB_BASE(chip
),
1051 "bar", &error_fatal
);
1052 object_property_set_bool(OBJECT(&chip9
->psi
), true, "realized", &local_err
);
1054 error_propagate(errp
, local_err
);
1057 pnv_xscom_add_subregion(chip
, PNV9_XSCOM_PSIHB_BASE
,
1058 &PNV_PSI(psi9
)->xscom_regs
);
1061 object_property_set_bool(OBJECT(&chip9
->lpc
), true, "realized", &local_err
);
1063 error_propagate(errp
, local_err
);
1066 memory_region_add_subregion(get_system_memory(), PNV9_LPCM_BASE(chip
),
1067 &chip9
->lpc
.xscom_regs
);
1069 chip
->dt_isa_nodename
= g_strdup_printf("/lpcm-opb@%" PRIx64
"/lpc@0",
1070 (uint64_t) PNV9_LPCM_BASE(chip
));
1072 /* Create the simplified OCC model */
1073 object_property_set_bool(OBJECT(&chip9
->occ
), true, "realized", &local_err
);
1075 error_propagate(errp
, local_err
);
1078 pnv_xscom_add_subregion(chip
, PNV9_XSCOM_OCC_BASE
, &chip9
->occ
.xscom_regs
);
1081 static void pnv_chip_power9_class_init(ObjectClass
*klass
, void *data
)
1083 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1084 PnvChipClass
*k
= PNV_CHIP_CLASS(klass
);
1086 k
->chip_type
= PNV_CHIP_POWER9
;
1087 k
->chip_cfam_id
= 0x220d104900008000ull
; /* P9 Nimbus DD2.0 */
1088 k
->cores_mask
= POWER9_CORE_MASK
;
1089 k
->core_pir
= pnv_chip_core_pir_p9
;
1090 k
->intc_create
= pnv_chip_power9_intc_create
;
1091 k
->isa_create
= pnv_chip_power9_isa_create
;
1092 k
->dt_populate
= pnv_chip_power9_dt_populate
;
1093 k
->pic_print_info
= pnv_chip_power9_pic_print_info
;
1094 k
->xscom_base
= 0x00603fc00000000ull
;
1095 dc
->desc
= "PowerNV Chip POWER9";
1097 device_class_set_parent_realize(dc
, pnv_chip_power9_realize
,
1098 &k
->parent_realize
);
1101 static void pnv_chip_core_sanitize(PnvChip
*chip
, Error
**errp
)
1103 PnvChipClass
*pcc
= PNV_CHIP_GET_CLASS(chip
);
1107 * No custom mask for this chip, let's use the default one from *
1110 if (!chip
->cores_mask
) {
1111 chip
->cores_mask
= pcc
->cores_mask
;
1114 /* filter alien core ids ! some are reserved */
1115 if ((chip
->cores_mask
& pcc
->cores_mask
) != chip
->cores_mask
) {
1116 error_setg(errp
, "warning: invalid core mask for chip Ox%"PRIx64
" !",
1120 chip
->cores_mask
&= pcc
->cores_mask
;
1122 /* now that we have a sane layout, let check the number of cores */
1123 cores_max
= ctpop64(chip
->cores_mask
);
1124 if (chip
->nr_cores
> cores_max
) {
1125 error_setg(errp
, "warning: too many cores for chip ! Limit is %d",
1131 static void pnv_chip_instance_init(Object
*obj
)
1133 PNV_CHIP(obj
)->xscom_base
= PNV_CHIP_GET_CLASS(obj
)->xscom_base
;
1136 static void pnv_chip_core_realize(PnvChip
*chip
, Error
**errp
)
1138 Error
*error
= NULL
;
1139 PnvChipClass
*pcc
= PNV_CHIP_GET_CLASS(chip
);
1140 const char *typename
= pnv_chip_core_typename(chip
);
1141 size_t typesize
= object_type_get_instance_size(typename
);
1144 if (!object_class_by_name(typename
)) {
1145 error_setg(errp
, "Unable to find PowerNV CPU Core '%s'", typename
);
1150 pnv_chip_core_sanitize(chip
, &error
);
1152 error_propagate(errp
, error
);
1156 chip
->cores
= g_malloc0(typesize
* chip
->nr_cores
);
1158 for (i
= 0, core_hwid
= 0; (core_hwid
< sizeof(chip
->cores_mask
) * 8)
1159 && (i
< chip
->nr_cores
); core_hwid
++) {
1161 void *pnv_core
= chip
->cores
+ i
* typesize
;
1162 uint64_t xscom_core_base
;
1164 if (!(chip
->cores_mask
& (1ull << core_hwid
))) {
1168 object_initialize(pnv_core
, typesize
, typename
);
1169 snprintf(core_name
, sizeof(core_name
), "core[%d]", core_hwid
);
1170 object_property_add_child(OBJECT(chip
), core_name
, OBJECT(pnv_core
),
1172 object_property_set_int(OBJECT(pnv_core
), smp_threads
, "nr-threads",
1174 object_property_set_int(OBJECT(pnv_core
), core_hwid
,
1175 CPU_CORE_PROP_CORE_ID
, &error_fatal
);
1176 object_property_set_int(OBJECT(pnv_core
),
1177 pcc
->core_pir(chip
, core_hwid
),
1178 "pir", &error_fatal
);
1179 object_property_add_const_link(OBJECT(pnv_core
), "chip",
1180 OBJECT(chip
), &error_fatal
);
1181 object_property_set_bool(OBJECT(pnv_core
), true, "realized",
1183 object_unref(OBJECT(pnv_core
));
1185 /* Each core has an XSCOM MMIO region */
1186 if (!pnv_chip_is_power9(chip
)) {
1187 xscom_core_base
= PNV_XSCOM_EX_BASE(core_hwid
);
1189 xscom_core_base
= PNV9_XSCOM_EC_BASE(core_hwid
);
1192 pnv_xscom_add_subregion(chip
, xscom_core_base
,
1193 &PNV_CORE(pnv_core
)->xscom_regs
);
1198 static void pnv_chip_realize(DeviceState
*dev
, Error
**errp
)
1200 PnvChip
*chip
= PNV_CHIP(dev
);
1201 Error
*error
= NULL
;
1204 pnv_xscom_realize(chip
, &error
);
1206 error_propagate(errp
, error
);
1209 sysbus_mmio_map(SYS_BUS_DEVICE(chip
), 0, PNV_XSCOM_BASE(chip
));
1212 pnv_chip_core_realize(chip
, &error
);
1214 error_propagate(errp
, error
);
1219 static Property pnv_chip_properties
[] = {
1220 DEFINE_PROP_UINT32("chip-id", PnvChip
, chip_id
, 0),
1221 DEFINE_PROP_UINT64("ram-start", PnvChip
, ram_start
, 0),
1222 DEFINE_PROP_UINT64("ram-size", PnvChip
, ram_size
, 0),
1223 DEFINE_PROP_UINT32("nr-cores", PnvChip
, nr_cores
, 1),
1224 DEFINE_PROP_UINT64("cores-mask", PnvChip
, cores_mask
, 0x0),
1225 DEFINE_PROP_END_OF_LIST(),
1228 static void pnv_chip_class_init(ObjectClass
*klass
, void *data
)
1230 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1232 set_bit(DEVICE_CATEGORY_CPU
, dc
->categories
);
1233 dc
->realize
= pnv_chip_realize
;
1234 dc
->props
= pnv_chip_properties
;
1235 dc
->desc
= "PowerNV Chip";
1238 static ICSState
*pnv_ics_get(XICSFabric
*xi
, int irq
)
1240 PnvMachineState
*pnv
= PNV_MACHINE(xi
);
1243 for (i
= 0; i
< pnv
->num_chips
; i
++) {
1244 Pnv8Chip
*chip8
= PNV8_CHIP(pnv
->chips
[i
]);
1246 if (ics_valid_irq(&chip8
->psi
.ics
, irq
)) {
1247 return &chip8
->psi
.ics
;
1253 static void pnv_ics_resend(XICSFabric
*xi
)
1255 PnvMachineState
*pnv
= PNV_MACHINE(xi
);
1258 for (i
= 0; i
< pnv
->num_chips
; i
++) {
1259 Pnv8Chip
*chip8
= PNV8_CHIP(pnv
->chips
[i
]);
1260 ics_resend(&chip8
->psi
.ics
);
1264 static ICPState
*pnv_icp_get(XICSFabric
*xi
, int pir
)
1266 PowerPCCPU
*cpu
= ppc_get_vcpu_by_pir(pir
);
1268 return cpu
? ICP(pnv_cpu_state(cpu
)->intc
) : NULL
;
1271 static void pnv_pic_print_info(InterruptStatsProvider
*obj
,
1274 PnvMachineState
*pnv
= PNV_MACHINE(obj
);
1279 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
1281 if (pnv_chip_is_power9(pnv
->chips
[0])) {
1282 xive_tctx_pic_print_info(XIVE_TCTX(pnv_cpu_state(cpu
)->intc
), mon
);
1284 icp_pic_print_info(ICP(pnv_cpu_state(cpu
)->intc
), mon
);
1288 for (i
= 0; i
< pnv
->num_chips
; i
++) {
1289 PNV_CHIP_GET_CLASS(pnv
->chips
[i
])->pic_print_info(pnv
->chips
[i
], mon
);
1293 static void pnv_get_num_chips(Object
*obj
, Visitor
*v
, const char *name
,
1294 void *opaque
, Error
**errp
)
1296 visit_type_uint32(v
, name
, &PNV_MACHINE(obj
)->num_chips
, errp
);
1299 static void pnv_set_num_chips(Object
*obj
, Visitor
*v
, const char *name
,
1300 void *opaque
, Error
**errp
)
1302 PnvMachineState
*pnv
= PNV_MACHINE(obj
);
1304 Error
*local_err
= NULL
;
1306 visit_type_uint32(v
, name
, &num_chips
, &local_err
);
1308 error_propagate(errp
, local_err
);
1313 * TODO: should we decide on how many chips we can create based
1314 * on #cores and Venice vs. Murano vs. Naples chip type etc...,
1316 if (!is_power_of_2(num_chips
) || num_chips
> 4) {
1317 error_setg(errp
, "invalid number of chips: '%d'", num_chips
);
1321 pnv
->num_chips
= num_chips
;
1324 static void pnv_machine_instance_init(Object
*obj
)
1326 PnvMachineState
*pnv
= PNV_MACHINE(obj
);
1330 static void pnv_machine_class_props_init(ObjectClass
*oc
)
1332 object_class_property_add(oc
, "num-chips", "uint32",
1333 pnv_get_num_chips
, pnv_set_num_chips
,
1335 object_class_property_set_description(oc
, "num-chips",
1336 "Specifies the number of processor chips",
1340 static void pnv_machine_class_init(ObjectClass
*oc
, void *data
)
1342 MachineClass
*mc
= MACHINE_CLASS(oc
);
1343 XICSFabricClass
*xic
= XICS_FABRIC_CLASS(oc
);
1344 InterruptStatsProviderClass
*ispc
= INTERRUPT_STATS_PROVIDER_CLASS(oc
);
1346 mc
->desc
= "IBM PowerNV (Non-Virtualized)";
1347 mc
->init
= pnv_init
;
1348 mc
->reset
= pnv_reset
;
1349 mc
->max_cpus
= MAX_CPUS
;
1350 mc
->default_cpu_type
= POWERPC_CPU_TYPE_NAME("power8_v2.0");
1351 mc
->block_default_type
= IF_IDE
; /* Pnv provides a AHCI device for
1353 mc
->no_parallel
= 1;
1354 mc
->default_boot_order
= NULL
;
1355 mc
->default_ram_size
= 1 * GiB
;
1356 xic
->icp_get
= pnv_icp_get
;
1357 xic
->ics_get
= pnv_ics_get
;
1358 xic
->ics_resend
= pnv_ics_resend
;
1359 ispc
->print_info
= pnv_pic_print_info
;
1361 pnv_machine_class_props_init(oc
);
1364 #define DEFINE_PNV8_CHIP_TYPE(type, class_initfn) \
1367 .class_init = class_initfn, \
1368 .parent = TYPE_PNV8_CHIP, \
1371 #define DEFINE_PNV9_CHIP_TYPE(type, class_initfn) \
1374 .class_init = class_initfn, \
1375 .parent = TYPE_PNV9_CHIP, \
1378 static const TypeInfo types
[] = {
1380 .name
= TYPE_PNV_MACHINE
,
1381 .parent
= TYPE_MACHINE
,
1382 .instance_size
= sizeof(PnvMachineState
),
1383 .instance_init
= pnv_machine_instance_init
,
1384 .class_init
= pnv_machine_class_init
,
1385 .interfaces
= (InterfaceInfo
[]) {
1386 { TYPE_XICS_FABRIC
},
1387 { TYPE_INTERRUPT_STATS_PROVIDER
},
1392 .name
= TYPE_PNV_CHIP
,
1393 .parent
= TYPE_SYS_BUS_DEVICE
,
1394 .class_init
= pnv_chip_class_init
,
1395 .instance_init
= pnv_chip_instance_init
,
1396 .instance_size
= sizeof(PnvChip
),
1397 .class_size
= sizeof(PnvChipClass
),
1402 * P9 chip and variants
1405 .name
= TYPE_PNV9_CHIP
,
1406 .parent
= TYPE_PNV_CHIP
,
1407 .instance_init
= pnv_chip_power9_instance_init
,
1408 .instance_size
= sizeof(Pnv9Chip
),
1410 DEFINE_PNV9_CHIP_TYPE(TYPE_PNV_CHIP_POWER9
, pnv_chip_power9_class_init
),
1413 * P8 chip and variants
1416 .name
= TYPE_PNV8_CHIP
,
1417 .parent
= TYPE_PNV_CHIP
,
1418 .instance_init
= pnv_chip_power8_instance_init
,
1419 .instance_size
= sizeof(Pnv8Chip
),
1421 DEFINE_PNV8_CHIP_TYPE(TYPE_PNV_CHIP_POWER8
, pnv_chip_power8_class_init
),
1422 DEFINE_PNV8_CHIP_TYPE(TYPE_PNV_CHIP_POWER8E
, pnv_chip_power8e_class_init
),
1423 DEFINE_PNV8_CHIP_TYPE(TYPE_PNV_CHIP_POWER8NVL
,
1424 pnv_chip_power8nvl_class_init
),