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-common.h"
22 #include "qemu/units.h"
23 #include "qapi/error.h"
24 #include "sysemu/sysemu.h"
25 #include "sysemu/numa.h"
26 #include "sysemu/reset.h"
27 #include "sysemu/runstate.h"
28 #include "sysemu/cpus.h"
29 #include "sysemu/device_tree.h"
30 #include "sysemu/hw_accel.h"
31 #include "target/ppc/cpu.h"
33 #include "hw/ppc/fdt.h"
34 #include "hw/ppc/ppc.h"
35 #include "hw/ppc/pnv.h"
36 #include "hw/ppc/pnv_core.h"
37 #include "hw/loader.h"
39 #include "exec/address-spaces.h"
40 #include "qapi/visitor.h"
41 #include "monitor/monitor.h"
42 #include "hw/intc/intc.h"
43 #include "hw/ipmi/ipmi.h"
44 #include "target/ppc/mmu-hash64.h"
45 #include "hw/pci/msi.h"
47 #include "hw/ppc/xics.h"
48 #include "hw/qdev-properties.h"
49 #include "hw/ppc/pnv_xscom.h"
50 #include "hw/ppc/pnv_pnor.h"
52 #include "hw/isa/isa.h"
53 #include "hw/boards.h"
54 #include "hw/char/serial.h"
55 #include "hw/rtc/mc146818rtc.h"
59 #define FDT_MAX_SIZE (1 * MiB)
61 #define FW_FILE_NAME "skiboot.lid"
62 #define FW_LOAD_ADDR 0x0
63 #define FW_MAX_SIZE (4 * MiB)
65 #define KERNEL_LOAD_ADDR 0x20000000
66 #define KERNEL_MAX_SIZE (256 * MiB)
67 #define INITRD_LOAD_ADDR 0x60000000
68 #define INITRD_MAX_SIZE (256 * MiB)
70 static const char *pnv_chip_core_typename(const PnvChip
*o
)
72 const char *chip_type
= object_class_get_name(object_get_class(OBJECT(o
)));
73 int len
= strlen(chip_type
) - strlen(PNV_CHIP_TYPE_SUFFIX
);
74 char *s
= g_strdup_printf(PNV_CORE_TYPE_NAME("%.*s"), len
, chip_type
);
75 const char *core_type
= object_class_get_name(object_class_by_name(s
));
81 * On Power Systems E880 (POWER8), the max cpus (threads) should be :
82 * 4 * 4 sockets * 12 cores * 8 threads = 1536
88 * Memory nodes are created by hostboot, one for each range of memory
89 * that has a different "affinity". In practice, it means one range
92 static void pnv_dt_memory(void *fdt
, int chip_id
, hwaddr start
, hwaddr size
)
95 uint64_t mem_reg_property
[2];
98 mem_reg_property
[0] = cpu_to_be64(start
);
99 mem_reg_property
[1] = cpu_to_be64(size
);
101 mem_name
= g_strdup_printf("memory@%"HWADDR_PRIx
, start
);
102 off
= fdt_add_subnode(fdt
, 0, mem_name
);
105 _FDT((fdt_setprop_string(fdt
, off
, "device_type", "memory")));
106 _FDT((fdt_setprop(fdt
, off
, "reg", mem_reg_property
,
107 sizeof(mem_reg_property
))));
108 _FDT((fdt_setprop_cell(fdt
, off
, "ibm,chip-id", chip_id
)));
111 static int get_cpus_node(void *fdt
)
113 int cpus_offset
= fdt_path_offset(fdt
, "/cpus");
115 if (cpus_offset
< 0) {
116 cpus_offset
= fdt_add_subnode(fdt
, 0, "cpus");
118 _FDT((fdt_setprop_cell(fdt
, cpus_offset
, "#address-cells", 0x1)));
119 _FDT((fdt_setprop_cell(fdt
, cpus_offset
, "#size-cells", 0x0)));
127 * The PowerNV cores (and threads) need to use real HW ids and not an
128 * incremental index like it has been done on other platforms. This HW
129 * id is stored in the CPU PIR, it is used to create cpu nodes in the
130 * device tree, used in XSCOM to address cores and in interrupt
133 static void pnv_dt_core(PnvChip
*chip
, PnvCore
*pc
, void *fdt
)
135 PowerPCCPU
*cpu
= pc
->threads
[0];
136 CPUState
*cs
= CPU(cpu
);
137 DeviceClass
*dc
= DEVICE_GET_CLASS(cs
);
138 int smt_threads
= CPU_CORE(pc
)->nr_threads
;
139 CPUPPCState
*env
= &cpu
->env
;
140 PowerPCCPUClass
*pcc
= POWERPC_CPU_GET_CLASS(cs
);
141 uint32_t servers_prop
[smt_threads
];
143 uint32_t segs
[] = {cpu_to_be32(28), cpu_to_be32(40),
144 0xffffffff, 0xffffffff};
145 uint32_t tbfreq
= PNV_TIMEBASE_FREQ
;
146 uint32_t cpufreq
= 1000000000;
147 uint32_t page_sizes_prop
[64];
148 size_t page_sizes_prop_size
;
149 const uint8_t pa_features
[] = { 24, 0,
150 0xf6, 0x3f, 0xc7, 0xc0, 0x80, 0xf0,
151 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
152 0x00, 0x00, 0x00, 0x00, 0x80, 0x00,
153 0x80, 0x00, 0x80, 0x00, 0x80, 0x00 };
156 int cpus_offset
= get_cpus_node(fdt
);
158 nodename
= g_strdup_printf("%s@%x", dc
->fw_name
, pc
->pir
);
159 offset
= fdt_add_subnode(fdt
, cpus_offset
, nodename
);
163 _FDT((fdt_setprop_cell(fdt
, offset
, "ibm,chip-id", chip
->chip_id
)));
165 _FDT((fdt_setprop_cell(fdt
, offset
, "reg", pc
->pir
)));
166 _FDT((fdt_setprop_cell(fdt
, offset
, "ibm,pir", pc
->pir
)));
167 _FDT((fdt_setprop_string(fdt
, offset
, "device_type", "cpu")));
169 _FDT((fdt_setprop_cell(fdt
, offset
, "cpu-version", env
->spr
[SPR_PVR
])));
170 _FDT((fdt_setprop_cell(fdt
, offset
, "d-cache-block-size",
171 env
->dcache_line_size
)));
172 _FDT((fdt_setprop_cell(fdt
, offset
, "d-cache-line-size",
173 env
->dcache_line_size
)));
174 _FDT((fdt_setprop_cell(fdt
, offset
, "i-cache-block-size",
175 env
->icache_line_size
)));
176 _FDT((fdt_setprop_cell(fdt
, offset
, "i-cache-line-size",
177 env
->icache_line_size
)));
179 if (pcc
->l1_dcache_size
) {
180 _FDT((fdt_setprop_cell(fdt
, offset
, "d-cache-size",
181 pcc
->l1_dcache_size
)));
183 warn_report("Unknown L1 dcache size for cpu");
185 if (pcc
->l1_icache_size
) {
186 _FDT((fdt_setprop_cell(fdt
, offset
, "i-cache-size",
187 pcc
->l1_icache_size
)));
189 warn_report("Unknown L1 icache size for cpu");
192 _FDT((fdt_setprop_cell(fdt
, offset
, "timebase-frequency", tbfreq
)));
193 _FDT((fdt_setprop_cell(fdt
, offset
, "clock-frequency", cpufreq
)));
194 _FDT((fdt_setprop_cell(fdt
, offset
, "ibm,slb-size",
195 cpu
->hash64_opts
->slb_size
)));
196 _FDT((fdt_setprop_string(fdt
, offset
, "status", "okay")));
197 _FDT((fdt_setprop(fdt
, offset
, "64-bit", NULL
, 0)));
199 if (env
->spr_cb
[SPR_PURR
].oea_read
) {
200 _FDT((fdt_setprop(fdt
, offset
, "ibm,purr", NULL
, 0)));
203 if (ppc_hash64_has(cpu
, PPC_HASH64_1TSEG
)) {
204 _FDT((fdt_setprop(fdt
, offset
, "ibm,processor-segment-sizes",
205 segs
, sizeof(segs
))));
209 * Advertise VMX/VSX (vector extensions) if available
210 * 0 / no property == no vector extensions
211 * 1 == VMX / Altivec available
214 if (env
->insns_flags
& PPC_ALTIVEC
) {
215 uint32_t vmx
= (env
->insns_flags2
& PPC2_VSX
) ? 2 : 1;
217 _FDT((fdt_setprop_cell(fdt
, offset
, "ibm,vmx", vmx
)));
221 * Advertise DFP (Decimal Floating Point) if available
222 * 0 / no property == no DFP
225 if (env
->insns_flags2
& PPC2_DFP
) {
226 _FDT((fdt_setprop_cell(fdt
, offset
, "ibm,dfp", 1)));
229 page_sizes_prop_size
= ppc_create_page_sizes_prop(cpu
, page_sizes_prop
,
230 sizeof(page_sizes_prop
));
231 if (page_sizes_prop_size
) {
232 _FDT((fdt_setprop(fdt
, offset
, "ibm,segment-page-sizes",
233 page_sizes_prop
, page_sizes_prop_size
)));
236 _FDT((fdt_setprop(fdt
, offset
, "ibm,pa-features",
237 pa_features
, sizeof(pa_features
))));
239 /* Build interrupt servers properties */
240 for (i
= 0; i
< smt_threads
; i
++) {
241 servers_prop
[i
] = cpu_to_be32(pc
->pir
+ i
);
243 _FDT((fdt_setprop(fdt
, offset
, "ibm,ppc-interrupt-server#s",
244 servers_prop
, sizeof(servers_prop
))));
247 static void pnv_dt_icp(PnvChip
*chip
, void *fdt
, uint32_t pir
,
250 uint64_t addr
= PNV_ICP_BASE(chip
) | (pir
<< 12);
252 const char compat
[] = "IBM,power8-icp\0IBM,ppc-xicp";
253 uint32_t irange
[2], i
, rsize
;
257 irange
[0] = cpu_to_be32(pir
);
258 irange
[1] = cpu_to_be32(nr_threads
);
260 rsize
= sizeof(uint64_t) * 2 * nr_threads
;
261 reg
= g_malloc(rsize
);
262 for (i
= 0; i
< nr_threads
; i
++) {
263 reg
[i
* 2] = cpu_to_be64(addr
| ((pir
+ i
) * 0x1000));
264 reg
[i
* 2 + 1] = cpu_to_be64(0x1000);
267 name
= g_strdup_printf("interrupt-controller@%"PRIX64
, addr
);
268 offset
= fdt_add_subnode(fdt
, 0, name
);
272 _FDT((fdt_setprop(fdt
, offset
, "compatible", compat
, sizeof(compat
))));
273 _FDT((fdt_setprop(fdt
, offset
, "reg", reg
, rsize
)));
274 _FDT((fdt_setprop_string(fdt
, offset
, "device_type",
275 "PowerPC-External-Interrupt-Presentation")));
276 _FDT((fdt_setprop(fdt
, offset
, "interrupt-controller", NULL
, 0)));
277 _FDT((fdt_setprop(fdt
, offset
, "ibm,interrupt-server-ranges",
278 irange
, sizeof(irange
))));
279 _FDT((fdt_setprop_cell(fdt
, offset
, "#interrupt-cells", 1)));
280 _FDT((fdt_setprop_cell(fdt
, offset
, "#address-cells", 0)));
284 static void pnv_chip_power8_dt_populate(PnvChip
*chip
, void *fdt
)
286 static const char compat
[] = "ibm,power8-xscom\0ibm,xscom";
289 pnv_dt_xscom(chip
, fdt
, 0,
290 cpu_to_be64(PNV_XSCOM_BASE(chip
)),
291 cpu_to_be64(PNV_XSCOM_SIZE
),
292 compat
, sizeof(compat
));
294 for (i
= 0; i
< chip
->nr_cores
; i
++) {
295 PnvCore
*pnv_core
= chip
->cores
[i
];
297 pnv_dt_core(chip
, pnv_core
, fdt
);
299 /* Interrupt Control Presenters (ICP). One per core. */
300 pnv_dt_icp(chip
, fdt
, pnv_core
->pir
, CPU_CORE(pnv_core
)->nr_threads
);
303 if (chip
->ram_size
) {
304 pnv_dt_memory(fdt
, chip
->chip_id
, chip
->ram_start
, chip
->ram_size
);
308 static void pnv_chip_power9_dt_populate(PnvChip
*chip
, void *fdt
)
310 static const char compat
[] = "ibm,power9-xscom\0ibm,xscom";
313 pnv_dt_xscom(chip
, fdt
, 0,
314 cpu_to_be64(PNV9_XSCOM_BASE(chip
)),
315 cpu_to_be64(PNV9_XSCOM_SIZE
),
316 compat
, sizeof(compat
));
318 for (i
= 0; i
< chip
->nr_cores
; i
++) {
319 PnvCore
*pnv_core
= chip
->cores
[i
];
321 pnv_dt_core(chip
, pnv_core
, fdt
);
324 if (chip
->ram_size
) {
325 pnv_dt_memory(fdt
, chip
->chip_id
, chip
->ram_start
, chip
->ram_size
);
328 pnv_dt_lpc(chip
, fdt
, 0, PNV9_LPCM_BASE(chip
), PNV9_LPCM_SIZE
);
331 static void pnv_chip_power10_dt_populate(PnvChip
*chip
, void *fdt
)
333 static const char compat
[] = "ibm,power10-xscom\0ibm,xscom";
336 pnv_dt_xscom(chip
, fdt
, 0,
337 cpu_to_be64(PNV10_XSCOM_BASE(chip
)),
338 cpu_to_be64(PNV10_XSCOM_SIZE
),
339 compat
, sizeof(compat
));
341 for (i
= 0; i
< chip
->nr_cores
; i
++) {
342 PnvCore
*pnv_core
= chip
->cores
[i
];
344 pnv_dt_core(chip
, pnv_core
, fdt
);
347 if (chip
->ram_size
) {
348 pnv_dt_memory(fdt
, chip
->chip_id
, chip
->ram_start
, chip
->ram_size
);
351 pnv_dt_lpc(chip
, fdt
, 0, PNV10_LPCM_BASE(chip
), PNV10_LPCM_SIZE
);
354 static void pnv_dt_rtc(ISADevice
*d
, void *fdt
, int lpc_off
)
356 uint32_t io_base
= d
->ioport_id
;
357 uint32_t io_regs
[] = {
359 cpu_to_be32(io_base
),
365 name
= g_strdup_printf("%s@i%x", qdev_fw_name(DEVICE(d
)), io_base
);
366 node
= fdt_add_subnode(fdt
, lpc_off
, name
);
370 _FDT((fdt_setprop(fdt
, node
, "reg", io_regs
, sizeof(io_regs
))));
371 _FDT((fdt_setprop_string(fdt
, node
, "compatible", "pnpPNP,b00")));
374 static void pnv_dt_serial(ISADevice
*d
, void *fdt
, int lpc_off
)
376 const char compatible
[] = "ns16550\0pnpPNP,501";
377 uint32_t io_base
= d
->ioport_id
;
378 uint32_t io_regs
[] = {
380 cpu_to_be32(io_base
),
386 name
= g_strdup_printf("%s@i%x", qdev_fw_name(DEVICE(d
)), io_base
);
387 node
= fdt_add_subnode(fdt
, lpc_off
, name
);
391 _FDT((fdt_setprop(fdt
, node
, "reg", io_regs
, sizeof(io_regs
))));
392 _FDT((fdt_setprop(fdt
, node
, "compatible", compatible
,
393 sizeof(compatible
))));
395 _FDT((fdt_setprop_cell(fdt
, node
, "clock-frequency", 1843200)));
396 _FDT((fdt_setprop_cell(fdt
, node
, "current-speed", 115200)));
397 _FDT((fdt_setprop_cell(fdt
, node
, "interrupts", d
->isairq
[0])));
398 _FDT((fdt_setprop_cell(fdt
, node
, "interrupt-parent",
399 fdt_get_phandle(fdt
, lpc_off
))));
401 /* This is needed by Linux */
402 _FDT((fdt_setprop_string(fdt
, node
, "device_type", "serial")));
405 static void pnv_dt_ipmi_bt(ISADevice
*d
, void *fdt
, int lpc_off
)
407 const char compatible
[] = "bt\0ipmi-bt";
409 uint32_t io_regs
[] = {
411 0, /* 'io_base' retrieved from the 'ioport' property of 'isa-ipmi-bt' */
418 io_base
= object_property_get_int(OBJECT(d
), "ioport", &error_fatal
);
419 io_regs
[1] = cpu_to_be32(io_base
);
421 irq
= object_property_get_int(OBJECT(d
), "irq", &error_fatal
);
423 name
= g_strdup_printf("%s@i%x", qdev_fw_name(DEVICE(d
)), io_base
);
424 node
= fdt_add_subnode(fdt
, lpc_off
, name
);
428 _FDT((fdt_setprop(fdt
, node
, "reg", io_regs
, sizeof(io_regs
))));
429 _FDT((fdt_setprop(fdt
, node
, "compatible", compatible
,
430 sizeof(compatible
))));
432 /* Mark it as reserved to avoid Linux trying to claim it */
433 _FDT((fdt_setprop_string(fdt
, node
, "status", "reserved")));
434 _FDT((fdt_setprop_cell(fdt
, node
, "interrupts", irq
)));
435 _FDT((fdt_setprop_cell(fdt
, node
, "interrupt-parent",
436 fdt_get_phandle(fdt
, lpc_off
))));
439 typedef struct ForeachPopulateArgs
{
442 } ForeachPopulateArgs
;
444 static int pnv_dt_isa_device(DeviceState
*dev
, void *opaque
)
446 ForeachPopulateArgs
*args
= opaque
;
447 ISADevice
*d
= ISA_DEVICE(dev
);
449 if (object_dynamic_cast(OBJECT(dev
), TYPE_MC146818_RTC
)) {
450 pnv_dt_rtc(d
, args
->fdt
, args
->offset
);
451 } else if (object_dynamic_cast(OBJECT(dev
), TYPE_ISA_SERIAL
)) {
452 pnv_dt_serial(d
, args
->fdt
, args
->offset
);
453 } else if (object_dynamic_cast(OBJECT(dev
), "isa-ipmi-bt")) {
454 pnv_dt_ipmi_bt(d
, args
->fdt
, args
->offset
);
456 error_report("unknown isa device %s@i%x", qdev_fw_name(dev
),
464 * The default LPC bus of a multichip system is on chip 0. It's
465 * recognized by the firmware (skiboot) using a "primary" property.
467 static void pnv_dt_isa(PnvMachineState
*pnv
, void *fdt
)
469 int isa_offset
= fdt_path_offset(fdt
, pnv
->chips
[0]->dt_isa_nodename
);
470 ForeachPopulateArgs args
= {
472 .offset
= isa_offset
,
476 _FDT((fdt_setprop(fdt
, isa_offset
, "primary", NULL
, 0)));
478 phandle
= qemu_fdt_alloc_phandle(fdt
);
480 _FDT((fdt_setprop_cell(fdt
, isa_offset
, "phandle", phandle
)));
483 * ISA devices are not necessarily parented to the ISA bus so we
484 * can not use object_child_foreach()
486 qbus_walk_children(BUS(pnv
->isa_bus
), pnv_dt_isa_device
, NULL
, NULL
, NULL
,
490 static void pnv_dt_power_mgt(PnvMachineState
*pnv
, void *fdt
)
494 off
= fdt_add_subnode(fdt
, 0, "ibm,opal");
495 off
= fdt_add_subnode(fdt
, off
, "power-mgt");
497 _FDT(fdt_setprop_cell(fdt
, off
, "ibm,enabled-stop-levels", 0xc0000000));
500 static void *pnv_dt_create(MachineState
*machine
)
502 PnvMachineClass
*pmc
= PNV_MACHINE_GET_CLASS(machine
);
503 PnvMachineState
*pnv
= PNV_MACHINE(machine
);
509 fdt
= g_malloc0(FDT_MAX_SIZE
);
510 _FDT((fdt_create_empty_tree(fdt
, FDT_MAX_SIZE
)));
513 _FDT((fdt_add_subnode(fdt
, 0, "qemu")));
516 _FDT((fdt_setprop_cell(fdt
, 0, "#address-cells", 0x2)));
517 _FDT((fdt_setprop_cell(fdt
, 0, "#size-cells", 0x2)));
518 _FDT((fdt_setprop_string(fdt
, 0, "model",
519 "IBM PowerNV (emulated by qemu)")));
520 _FDT((fdt_setprop(fdt
, 0, "compatible", pmc
->compat
, pmc
->compat_size
)));
522 buf
= qemu_uuid_unparse_strdup(&qemu_uuid
);
523 _FDT((fdt_setprop_string(fdt
, 0, "vm,uuid", buf
)));
525 _FDT((fdt_property_string(fdt
, "system-id", buf
)));
529 off
= fdt_add_subnode(fdt
, 0, "chosen");
530 if (machine
->kernel_cmdline
) {
531 _FDT((fdt_setprop_string(fdt
, off
, "bootargs",
532 machine
->kernel_cmdline
)));
535 if (pnv
->initrd_size
) {
536 uint32_t start_prop
= cpu_to_be32(pnv
->initrd_base
);
537 uint32_t end_prop
= cpu_to_be32(pnv
->initrd_base
+ pnv
->initrd_size
);
539 _FDT((fdt_setprop(fdt
, off
, "linux,initrd-start",
540 &start_prop
, sizeof(start_prop
))));
541 _FDT((fdt_setprop(fdt
, off
, "linux,initrd-end",
542 &end_prop
, sizeof(end_prop
))));
545 /* Populate device tree for each chip */
546 for (i
= 0; i
< pnv
->num_chips
; i
++) {
547 PNV_CHIP_GET_CLASS(pnv
->chips
[i
])->dt_populate(pnv
->chips
[i
], fdt
);
550 /* Populate ISA devices on chip 0 */
551 pnv_dt_isa(pnv
, fdt
);
554 pnv_dt_bmc_sensors(pnv
->bmc
, fdt
);
557 /* Create an extra node for power management on machines that support it */
558 if (pmc
->dt_power_mgt
) {
559 pmc
->dt_power_mgt(pnv
, fdt
);
565 static void pnv_powerdown_notify(Notifier
*n
, void *opaque
)
567 PnvMachineState
*pnv
= container_of(n
, PnvMachineState
, powerdown_notifier
);
570 pnv_bmc_powerdown(pnv
->bmc
);
574 static void pnv_reset(MachineState
*machine
)
576 PnvMachineState
*pnv
= PNV_MACHINE(machine
);
580 qemu_devices_reset();
583 * The machine should provide by default an internal BMC simulator.
584 * If not, try to use the BMC device that was provided on the command
587 bmc
= pnv_bmc_find(&error_fatal
);
590 warn_report("machine has no BMC device. Use '-device "
591 "ipmi-bmc-sim,id=bmc0 -device isa-ipmi-bt,bmc=bmc0,irq=10' "
594 pnv_bmc_set_pnor(bmc
, pnv
->pnor
);
599 fdt
= pnv_dt_create(machine
);
601 /* Pack resulting tree */
602 _FDT((fdt_pack(fdt
)));
604 qemu_fdt_dumpdtb(fdt
, fdt_totalsize(fdt
));
605 cpu_physical_memory_write(PNV_FDT_ADDR
, fdt
, fdt_totalsize(fdt
));
610 static ISABus
*pnv_chip_power8_isa_create(PnvChip
*chip
, Error
**errp
)
612 Pnv8Chip
*chip8
= PNV8_CHIP(chip
);
613 return pnv_lpc_isa_create(&chip8
->lpc
, true, errp
);
616 static ISABus
*pnv_chip_power8nvl_isa_create(PnvChip
*chip
, Error
**errp
)
618 Pnv8Chip
*chip8
= PNV8_CHIP(chip
);
619 return pnv_lpc_isa_create(&chip8
->lpc
, false, errp
);
622 static ISABus
*pnv_chip_power9_isa_create(PnvChip
*chip
, Error
**errp
)
624 Pnv9Chip
*chip9
= PNV9_CHIP(chip
);
625 return pnv_lpc_isa_create(&chip9
->lpc
, false, errp
);
628 static ISABus
*pnv_chip_power10_isa_create(PnvChip
*chip
, Error
**errp
)
630 Pnv10Chip
*chip10
= PNV10_CHIP(chip
);
631 return pnv_lpc_isa_create(&chip10
->lpc
, false, errp
);
634 static ISABus
*pnv_isa_create(PnvChip
*chip
, Error
**errp
)
636 return PNV_CHIP_GET_CLASS(chip
)->isa_create(chip
, errp
);
639 static void pnv_chip_power8_pic_print_info(PnvChip
*chip
, Monitor
*mon
)
641 Pnv8Chip
*chip8
= PNV8_CHIP(chip
);
644 ics_pic_print_info(&chip8
->psi
.ics
, mon
);
645 for (i
= 0; i
< chip
->num_phbs
; i
++) {
646 pnv_phb3_msi_pic_print_info(&chip8
->phbs
[i
].msis
, mon
);
647 ics_pic_print_info(&chip8
->phbs
[i
].lsis
, mon
);
651 static void pnv_chip_power9_pic_print_info(PnvChip
*chip
, Monitor
*mon
)
653 Pnv9Chip
*chip9
= PNV9_CHIP(chip
);
656 pnv_xive_pic_print_info(&chip9
->xive
, mon
);
657 pnv_psi_pic_print_info(&chip9
->psi
, mon
);
659 for (i
= 0; i
< PNV9_CHIP_MAX_PEC
; i
++) {
660 PnvPhb4PecState
*pec
= &chip9
->pecs
[i
];
661 for (j
= 0; j
< pec
->num_stacks
; j
++) {
662 pnv_phb4_pic_print_info(&pec
->stacks
[j
].phb
, mon
);
667 static uint64_t pnv_chip_power8_xscom_core_base(PnvChip
*chip
,
670 return PNV_XSCOM_EX_BASE(core_id
);
673 static uint64_t pnv_chip_power9_xscom_core_base(PnvChip
*chip
,
676 return PNV9_XSCOM_EC_BASE(core_id
);
679 static uint64_t pnv_chip_power10_xscom_core_base(PnvChip
*chip
,
682 return PNV10_XSCOM_EC_BASE(core_id
);
685 static bool pnv_match_cpu(const char *default_type
, const char *cpu_type
)
687 PowerPCCPUClass
*ppc_default
=
688 POWERPC_CPU_CLASS(object_class_by_name(default_type
));
689 PowerPCCPUClass
*ppc
=
690 POWERPC_CPU_CLASS(object_class_by_name(cpu_type
));
692 return ppc_default
->pvr_match(ppc_default
, ppc
->pvr
);
695 static void pnv_ipmi_bt_init(ISABus
*bus
, IPMIBmc
*bmc
, uint32_t irq
)
697 ISADevice
*dev
= isa_new("isa-ipmi-bt");
699 object_property_set_link(OBJECT(dev
), OBJECT(bmc
), "bmc", &error_fatal
);
700 object_property_set_int(OBJECT(dev
), irq
, "irq", &error_fatal
);
701 isa_realize_and_unref(dev
, bus
, &error_fatal
);
704 static void pnv_chip_power10_pic_print_info(PnvChip
*chip
, Monitor
*mon
)
706 Pnv10Chip
*chip10
= PNV10_CHIP(chip
);
708 pnv_psi_pic_print_info(&chip10
->psi
, mon
);
711 static void pnv_init(MachineState
*machine
)
713 PnvMachineState
*pnv
= PNV_MACHINE(machine
);
714 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
719 DriveInfo
*pnor
= drive_get(IF_MTD
, 0, 0);
723 if (machine
->ram_size
< (1 * GiB
)) {
724 warn_report("skiboot may not work with < 1GB of RAM");
726 memory_region_add_subregion(get_system_memory(), 0, machine
->ram
);
729 * Create our simple PNOR device
731 dev
= qdev_new(TYPE_PNV_PNOR
);
733 qdev_prop_set_drive(dev
, "drive", blk_by_legacy_dinfo(pnor
));
735 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev
), &error_fatal
);
736 pnv
->pnor
= PNV_PNOR(dev
);
738 /* load skiboot firmware */
739 if (bios_name
== NULL
) {
740 bios_name
= FW_FILE_NAME
;
743 fw_filename
= qemu_find_file(QEMU_FILE_TYPE_BIOS
, bios_name
);
745 error_report("Could not find OPAL firmware '%s'", bios_name
);
749 fw_size
= load_image_targphys(fw_filename
, pnv
->fw_load_addr
, FW_MAX_SIZE
);
751 error_report("Could not load OPAL firmware '%s'", fw_filename
);
757 if (machine
->kernel_filename
) {
760 kernel_size
= load_image_targphys(machine
->kernel_filename
,
761 KERNEL_LOAD_ADDR
, KERNEL_MAX_SIZE
);
762 if (kernel_size
< 0) {
763 error_report("Could not load kernel '%s'",
764 machine
->kernel_filename
);
770 if (machine
->initrd_filename
) {
771 pnv
->initrd_base
= INITRD_LOAD_ADDR
;
772 pnv
->initrd_size
= load_image_targphys(machine
->initrd_filename
,
773 pnv
->initrd_base
, INITRD_MAX_SIZE
);
774 if (pnv
->initrd_size
< 0) {
775 error_report("Could not load initial ram disk '%s'",
776 machine
->initrd_filename
);
781 /* MSIs are supported on this platform */
782 msi_nonbroken
= true;
785 * Check compatibility of the specified CPU with the machine
788 if (!pnv_match_cpu(mc
->default_cpu_type
, machine
->cpu_type
)) {
789 error_report("invalid CPU model '%s' for %s machine",
790 machine
->cpu_type
, mc
->name
);
794 /* Create the processor chips */
795 i
= strlen(machine
->cpu_type
) - strlen(POWERPC_CPU_TYPE_SUFFIX
);
796 chip_typename
= g_strdup_printf(PNV_CHIP_TYPE_NAME("%.*s"),
797 i
, machine
->cpu_type
);
798 if (!object_class_by_name(chip_typename
)) {
799 error_report("invalid chip model '%.*s' for %s machine",
800 i
, machine
->cpu_type
, mc
->name
);
805 machine
->smp
.max_cpus
/ (machine
->smp
.cores
* machine
->smp
.threads
);
807 * TODO: should we decide on how many chips we can create based
808 * on #cores and Venice vs. Murano vs. Naples chip type etc...,
810 if (!is_power_of_2(pnv
->num_chips
) || pnv
->num_chips
> 4) {
811 error_report("invalid number of chips: '%d'", pnv
->num_chips
);
812 error_printf("Try '-smp sockets=N'. Valid values are : 1, 2 or 4.\n");
816 pnv
->chips
= g_new0(PnvChip
*, pnv
->num_chips
);
817 for (i
= 0; i
< pnv
->num_chips
; i
++) {
819 Object
*chip
= OBJECT(qdev_new(chip_typename
));
821 pnv
->chips
[i
] = PNV_CHIP(chip
);
824 * TODO: put all the memory in one node on chip 0 until we find a
825 * way to specify different ranges for each chip
828 object_property_set_int(chip
, machine
->ram_size
, "ram-size",
832 snprintf(chip_name
, sizeof(chip_name
), "chip[%d]", PNV_CHIP_HWID(i
));
833 object_property_add_child(OBJECT(pnv
), chip_name
, chip
);
834 object_property_set_int(chip
, PNV_CHIP_HWID(i
), "chip-id",
836 object_property_set_int(chip
, machine
->smp
.cores
,
837 "nr-cores", &error_fatal
);
838 object_property_set_int(chip
, machine
->smp
.threads
,
839 "nr-threads", &error_fatal
);
841 * The POWER8 machine use the XICS interrupt interface.
842 * Propagate the XICS fabric to the chip and its controllers.
844 if (object_dynamic_cast(OBJECT(pnv
), TYPE_XICS_FABRIC
)) {
845 object_property_set_link(chip
, OBJECT(pnv
), "xics", &error_abort
);
847 if (object_dynamic_cast(OBJECT(pnv
), TYPE_XIVE_FABRIC
)) {
848 object_property_set_link(chip
, OBJECT(pnv
), "xive-fabric",
851 sysbus_realize_and_unref(SYS_BUS_DEVICE(chip
), &error_fatal
);
853 g_free(chip_typename
);
855 /* Instantiate ISA bus on chip 0 */
856 pnv
->isa_bus
= pnv_isa_create(pnv
->chips
[0], &error_fatal
);
858 /* Create serial port */
859 serial_hds_isa_init(pnv
->isa_bus
, 0, MAX_ISA_SERIAL_PORTS
);
861 /* Create an RTC ISA device too */
862 mc146818_rtc_init(pnv
->isa_bus
, 2000, NULL
);
865 * Create the machine BMC simulator and the IPMI BT device for
866 * communication with the BMC
868 if (defaults_enabled()) {
869 pnv
->bmc
= pnv_bmc_create(pnv
->pnor
);
870 pnv_ipmi_bt_init(pnv
->isa_bus
, pnv
->bmc
, 10);
874 * OpenPOWER systems use a IPMI SEL Event message to notify the
877 pnv
->powerdown_notifier
.notify
= pnv_powerdown_notify
;
878 qemu_register_powerdown_notifier(&pnv
->powerdown_notifier
);
882 * 0:21 Reserved - Read as zeros
887 static uint32_t pnv_chip_core_pir_p8(PnvChip
*chip
, uint32_t core_id
)
889 return (chip
->chip_id
<< 7) | (core_id
<< 3);
892 static void pnv_chip_power8_intc_create(PnvChip
*chip
, PowerPCCPU
*cpu
,
895 Pnv8Chip
*chip8
= PNV8_CHIP(chip
);
896 Error
*local_err
= NULL
;
898 PnvCPUState
*pnv_cpu
= pnv_cpu_state(cpu
);
900 obj
= icp_create(OBJECT(cpu
), TYPE_PNV_ICP
, chip8
->xics
, &local_err
);
902 error_propagate(errp
, local_err
);
910 static void pnv_chip_power8_intc_reset(PnvChip
*chip
, PowerPCCPU
*cpu
)
912 PnvCPUState
*pnv_cpu
= pnv_cpu_state(cpu
);
914 icp_reset(ICP(pnv_cpu
->intc
));
917 static void pnv_chip_power8_intc_destroy(PnvChip
*chip
, PowerPCCPU
*cpu
)
919 PnvCPUState
*pnv_cpu
= pnv_cpu_state(cpu
);
921 icp_destroy(ICP(pnv_cpu
->intc
));
922 pnv_cpu
->intc
= NULL
;
925 static void pnv_chip_power8_intc_print_info(PnvChip
*chip
, PowerPCCPU
*cpu
,
928 icp_pic_print_info(ICP(pnv_cpu_state(cpu
)->intc
), mon
);
932 * 0:48 Reserved - Read as zeroes
935 * 56 Reserved - Read as zero
939 * We only care about the lower bits. uint32_t is fine for the moment.
941 static uint32_t pnv_chip_core_pir_p9(PnvChip
*chip
, uint32_t core_id
)
943 return (chip
->chip_id
<< 8) | (core_id
<< 2);
946 static uint32_t pnv_chip_core_pir_p10(PnvChip
*chip
, uint32_t core_id
)
948 return (chip
->chip_id
<< 8) | (core_id
<< 2);
951 static void pnv_chip_power9_intc_create(PnvChip
*chip
, PowerPCCPU
*cpu
,
954 Pnv9Chip
*chip9
= PNV9_CHIP(chip
);
955 Error
*local_err
= NULL
;
957 PnvCPUState
*pnv_cpu
= pnv_cpu_state(cpu
);
960 * The core creates its interrupt presenter but the XIVE interrupt
961 * controller object is initialized afterwards. Hopefully, it's
962 * only used at runtime.
964 obj
= xive_tctx_create(OBJECT(cpu
), XIVE_PRESENTER(&chip9
->xive
),
967 error_propagate(errp
, local_err
);
974 static void pnv_chip_power9_intc_reset(PnvChip
*chip
, PowerPCCPU
*cpu
)
976 PnvCPUState
*pnv_cpu
= pnv_cpu_state(cpu
);
978 xive_tctx_reset(XIVE_TCTX(pnv_cpu
->intc
));
981 static void pnv_chip_power9_intc_destroy(PnvChip
*chip
, PowerPCCPU
*cpu
)
983 PnvCPUState
*pnv_cpu
= pnv_cpu_state(cpu
);
985 xive_tctx_destroy(XIVE_TCTX(pnv_cpu
->intc
));
986 pnv_cpu
->intc
= NULL
;
989 static void pnv_chip_power9_intc_print_info(PnvChip
*chip
, PowerPCCPU
*cpu
,
992 xive_tctx_pic_print_info(XIVE_TCTX(pnv_cpu_state(cpu
)->intc
), mon
);
995 static void pnv_chip_power10_intc_create(PnvChip
*chip
, PowerPCCPU
*cpu
,
998 PnvCPUState
*pnv_cpu
= pnv_cpu_state(cpu
);
1000 /* Will be defined when the interrupt controller is */
1001 pnv_cpu
->intc
= NULL
;
1004 static void pnv_chip_power10_intc_reset(PnvChip
*chip
, PowerPCCPU
*cpu
)
1009 static void pnv_chip_power10_intc_destroy(PnvChip
*chip
, PowerPCCPU
*cpu
)
1011 PnvCPUState
*pnv_cpu
= pnv_cpu_state(cpu
);
1013 pnv_cpu
->intc
= NULL
;
1016 static void pnv_chip_power10_intc_print_info(PnvChip
*chip
, PowerPCCPU
*cpu
,
1022 * Allowed core identifiers on a POWER8 Processor Chip :
1031 * <EX7,8 reserved> <reserved>
1033 * EX10 - Venice only
1034 * EX11 - Venice only
1040 #define POWER8E_CORE_MASK (0x7070ull)
1041 #define POWER8_CORE_MASK (0x7e7eull)
1044 * POWER9 has 24 cores, ids starting at 0x0
1046 #define POWER9_CORE_MASK (0xffffffffffffffull)
1049 #define POWER10_CORE_MASK (0xffffffffffffffull)
1051 static void pnv_chip_power8_instance_init(Object
*obj
)
1053 PnvChip
*chip
= PNV_CHIP(obj
);
1054 Pnv8Chip
*chip8
= PNV8_CHIP(obj
);
1055 PnvChipClass
*pcc
= PNV_CHIP_GET_CLASS(obj
);
1058 object_property_add_link(obj
, "xics", TYPE_XICS_FABRIC
,
1059 (Object
**)&chip8
->xics
,
1060 object_property_allow_set_link
,
1061 OBJ_PROP_LINK_STRONG
);
1063 object_initialize_child(obj
, "psi", &chip8
->psi
, TYPE_PNV8_PSI
);
1065 object_initialize_child(obj
, "lpc", &chip8
->lpc
, TYPE_PNV8_LPC
);
1067 object_initialize_child(obj
, "occ", &chip8
->occ
, TYPE_PNV8_OCC
);
1069 object_initialize_child(obj
, "homer", &chip8
->homer
, TYPE_PNV8_HOMER
);
1071 for (i
= 0; i
< pcc
->num_phbs
; i
++) {
1072 object_initialize_child(obj
, "phb[*]", &chip8
->phbs
[i
], TYPE_PNV_PHB3
);
1076 * Number of PHBs is the chip default
1078 chip
->num_phbs
= pcc
->num_phbs
;
1081 static void pnv_chip_icp_realize(Pnv8Chip
*chip8
, Error
**errp
)
1083 PnvChip
*chip
= PNV_CHIP(chip8
);
1084 PnvChipClass
*pcc
= PNV_CHIP_GET_CLASS(chip
);
1088 name
= g_strdup_printf("icp-%x", chip
->chip_id
);
1089 memory_region_init(&chip8
->icp_mmio
, OBJECT(chip
), name
, PNV_ICP_SIZE
);
1090 sysbus_init_mmio(SYS_BUS_DEVICE(chip
), &chip8
->icp_mmio
);
1093 sysbus_mmio_map(SYS_BUS_DEVICE(chip
), 1, PNV_ICP_BASE(chip
));
1095 /* Map the ICP registers for each thread */
1096 for (i
= 0; i
< chip
->nr_cores
; i
++) {
1097 PnvCore
*pnv_core
= chip
->cores
[i
];
1098 int core_hwid
= CPU_CORE(pnv_core
)->core_id
;
1100 for (j
= 0; j
< CPU_CORE(pnv_core
)->nr_threads
; j
++) {
1101 uint32_t pir
= pcc
->core_pir(chip
, core_hwid
) + j
;
1102 PnvICPState
*icp
= PNV_ICP(xics_icp_get(chip8
->xics
, pir
));
1104 memory_region_add_subregion(&chip8
->icp_mmio
, pir
<< 12,
1110 static void pnv_chip_power8_realize(DeviceState
*dev
, Error
**errp
)
1112 PnvChipClass
*pcc
= PNV_CHIP_GET_CLASS(dev
);
1113 PnvChip
*chip
= PNV_CHIP(dev
);
1114 Pnv8Chip
*chip8
= PNV8_CHIP(dev
);
1115 Pnv8Psi
*psi8
= &chip8
->psi
;
1116 Error
*local_err
= NULL
;
1119 assert(chip8
->xics
);
1121 /* XSCOM bridge is first */
1122 pnv_xscom_realize(chip
, PNV_XSCOM_SIZE
, &local_err
);
1124 error_propagate(errp
, local_err
);
1127 sysbus_mmio_map(SYS_BUS_DEVICE(chip
), 0, PNV_XSCOM_BASE(chip
));
1129 pcc
->parent_realize(dev
, &local_err
);
1131 error_propagate(errp
, local_err
);
1135 /* Processor Service Interface (PSI) Host Bridge */
1136 object_property_set_int(OBJECT(&chip8
->psi
), PNV_PSIHB_BASE(chip
),
1137 "bar", &error_fatal
);
1138 object_property_set_link(OBJECT(&chip8
->psi
), OBJECT(chip8
->xics
),
1139 ICS_PROP_XICS
, &error_abort
);
1140 qdev_realize(DEVICE(&chip8
->psi
), NULL
, &local_err
);
1142 error_propagate(errp
, local_err
);
1145 pnv_xscom_add_subregion(chip
, PNV_XSCOM_PSIHB_BASE
,
1146 &PNV_PSI(psi8
)->xscom_regs
);
1148 /* Create LPC controller */
1149 object_property_set_link(OBJECT(&chip8
->lpc
), OBJECT(&chip8
->psi
), "psi",
1151 qdev_realize(DEVICE(&chip8
->lpc
), NULL
, &error_fatal
);
1152 pnv_xscom_add_subregion(chip
, PNV_XSCOM_LPC_BASE
, &chip8
->lpc
.xscom_regs
);
1154 chip
->dt_isa_nodename
= g_strdup_printf("/xscom@%" PRIx64
"/isa@%x",
1155 (uint64_t) PNV_XSCOM_BASE(chip
),
1156 PNV_XSCOM_LPC_BASE
);
1159 * Interrupt Management Area. This is the memory region holding
1160 * all the Interrupt Control Presenter (ICP) registers
1162 pnv_chip_icp_realize(chip8
, &local_err
);
1164 error_propagate(errp
, local_err
);
1168 /* Create the simplified OCC model */
1169 object_property_set_link(OBJECT(&chip8
->occ
), OBJECT(&chip8
->psi
), "psi",
1171 qdev_realize(DEVICE(&chip8
->occ
), NULL
, &local_err
);
1173 error_propagate(errp
, local_err
);
1176 pnv_xscom_add_subregion(chip
, PNV_XSCOM_OCC_BASE
, &chip8
->occ
.xscom_regs
);
1178 /* OCC SRAM model */
1179 memory_region_add_subregion(get_system_memory(), PNV_OCC_SENSOR_BASE(chip
),
1180 &chip8
->occ
.sram_regs
);
1183 object_property_set_link(OBJECT(&chip8
->homer
), OBJECT(chip
), "chip",
1185 qdev_realize(DEVICE(&chip8
->homer
), NULL
, &local_err
);
1187 error_propagate(errp
, local_err
);
1190 /* Homer Xscom region */
1191 pnv_xscom_add_subregion(chip
, PNV_XSCOM_PBA_BASE
, &chip8
->homer
.pba_regs
);
1193 /* Homer mmio region */
1194 memory_region_add_subregion(get_system_memory(), PNV_HOMER_BASE(chip
),
1195 &chip8
->homer
.regs
);
1197 /* PHB3 controllers */
1198 for (i
= 0; i
< chip
->num_phbs
; i
++) {
1199 PnvPHB3
*phb
= &chip8
->phbs
[i
];
1200 PnvPBCQState
*pbcq
= &phb
->pbcq
;
1202 object_property_set_int(OBJECT(phb
), i
, "index", &error_fatal
);
1203 object_property_set_int(OBJECT(phb
), chip
->chip_id
, "chip-id",
1205 sysbus_realize(SYS_BUS_DEVICE(phb
), &local_err
);
1207 error_propagate(errp
, local_err
);
1211 /* Populate the XSCOM address space. */
1212 pnv_xscom_add_subregion(chip
,
1213 PNV_XSCOM_PBCQ_NEST_BASE
+ 0x400 * phb
->phb_id
,
1214 &pbcq
->xscom_nest_regs
);
1215 pnv_xscom_add_subregion(chip
,
1216 PNV_XSCOM_PBCQ_PCI_BASE
+ 0x400 * phb
->phb_id
,
1217 &pbcq
->xscom_pci_regs
);
1218 pnv_xscom_add_subregion(chip
,
1219 PNV_XSCOM_PBCQ_SPCI_BASE
+ 0x040 * phb
->phb_id
,
1220 &pbcq
->xscom_spci_regs
);
1224 static uint32_t pnv_chip_power8_xscom_pcba(PnvChip
*chip
, uint64_t addr
)
1226 addr
&= (PNV_XSCOM_SIZE
- 1);
1227 return ((addr
>> 4) & ~0xfull
) | ((addr
>> 3) & 0xf);
1230 static void pnv_chip_power8e_class_init(ObjectClass
*klass
, void *data
)
1232 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1233 PnvChipClass
*k
= PNV_CHIP_CLASS(klass
);
1235 k
->chip_cfam_id
= 0x221ef04980000000ull
; /* P8 Murano DD2.1 */
1236 k
->cores_mask
= POWER8E_CORE_MASK
;
1238 k
->core_pir
= pnv_chip_core_pir_p8
;
1239 k
->intc_create
= pnv_chip_power8_intc_create
;
1240 k
->intc_reset
= pnv_chip_power8_intc_reset
;
1241 k
->intc_destroy
= pnv_chip_power8_intc_destroy
;
1242 k
->intc_print_info
= pnv_chip_power8_intc_print_info
;
1243 k
->isa_create
= pnv_chip_power8_isa_create
;
1244 k
->dt_populate
= pnv_chip_power8_dt_populate
;
1245 k
->pic_print_info
= pnv_chip_power8_pic_print_info
;
1246 k
->xscom_core_base
= pnv_chip_power8_xscom_core_base
;
1247 k
->xscom_pcba
= pnv_chip_power8_xscom_pcba
;
1248 dc
->desc
= "PowerNV Chip POWER8E";
1250 device_class_set_parent_realize(dc
, pnv_chip_power8_realize
,
1251 &k
->parent_realize
);
1254 static void pnv_chip_power8_class_init(ObjectClass
*klass
, void *data
)
1256 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1257 PnvChipClass
*k
= PNV_CHIP_CLASS(klass
);
1259 k
->chip_cfam_id
= 0x220ea04980000000ull
; /* P8 Venice DD2.0 */
1260 k
->cores_mask
= POWER8_CORE_MASK
;
1262 k
->core_pir
= pnv_chip_core_pir_p8
;
1263 k
->intc_create
= pnv_chip_power8_intc_create
;
1264 k
->intc_reset
= pnv_chip_power8_intc_reset
;
1265 k
->intc_destroy
= pnv_chip_power8_intc_destroy
;
1266 k
->intc_print_info
= pnv_chip_power8_intc_print_info
;
1267 k
->isa_create
= pnv_chip_power8_isa_create
;
1268 k
->dt_populate
= pnv_chip_power8_dt_populate
;
1269 k
->pic_print_info
= pnv_chip_power8_pic_print_info
;
1270 k
->xscom_core_base
= pnv_chip_power8_xscom_core_base
;
1271 k
->xscom_pcba
= pnv_chip_power8_xscom_pcba
;
1272 dc
->desc
= "PowerNV Chip POWER8";
1274 device_class_set_parent_realize(dc
, pnv_chip_power8_realize
,
1275 &k
->parent_realize
);
1278 static void pnv_chip_power8nvl_class_init(ObjectClass
*klass
, void *data
)
1280 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1281 PnvChipClass
*k
= PNV_CHIP_CLASS(klass
);
1283 k
->chip_cfam_id
= 0x120d304980000000ull
; /* P8 Naples DD1.0 */
1284 k
->cores_mask
= POWER8_CORE_MASK
;
1286 k
->core_pir
= pnv_chip_core_pir_p8
;
1287 k
->intc_create
= pnv_chip_power8_intc_create
;
1288 k
->intc_reset
= pnv_chip_power8_intc_reset
;
1289 k
->intc_destroy
= pnv_chip_power8_intc_destroy
;
1290 k
->intc_print_info
= pnv_chip_power8_intc_print_info
;
1291 k
->isa_create
= pnv_chip_power8nvl_isa_create
;
1292 k
->dt_populate
= pnv_chip_power8_dt_populate
;
1293 k
->pic_print_info
= pnv_chip_power8_pic_print_info
;
1294 k
->xscom_core_base
= pnv_chip_power8_xscom_core_base
;
1295 k
->xscom_pcba
= pnv_chip_power8_xscom_pcba
;
1296 dc
->desc
= "PowerNV Chip POWER8NVL";
1298 device_class_set_parent_realize(dc
, pnv_chip_power8_realize
,
1299 &k
->parent_realize
);
1302 static void pnv_chip_power9_instance_init(Object
*obj
)
1304 PnvChip
*chip
= PNV_CHIP(obj
);
1305 Pnv9Chip
*chip9
= PNV9_CHIP(obj
);
1306 PnvChipClass
*pcc
= PNV_CHIP_GET_CLASS(obj
);
1309 object_initialize_child(obj
, "xive", &chip9
->xive
, TYPE_PNV_XIVE
);
1310 object_property_add_alias(obj
, "xive-fabric", OBJECT(&chip9
->xive
),
1313 object_initialize_child(obj
, "psi", &chip9
->psi
, TYPE_PNV9_PSI
);
1315 object_initialize_child(obj
, "lpc", &chip9
->lpc
, TYPE_PNV9_LPC
);
1317 object_initialize_child(obj
, "occ", &chip9
->occ
, TYPE_PNV9_OCC
);
1319 object_initialize_child(obj
, "homer", &chip9
->homer
, TYPE_PNV9_HOMER
);
1321 for (i
= 0; i
< PNV9_CHIP_MAX_PEC
; i
++) {
1322 object_initialize_child(obj
, "pec[*]", &chip9
->pecs
[i
],
1327 * Number of PHBs is the chip default
1329 chip
->num_phbs
= pcc
->num_phbs
;
1332 static void pnv_chip_quad_realize(Pnv9Chip
*chip9
, Error
**errp
)
1334 PnvChip
*chip
= PNV_CHIP(chip9
);
1337 chip9
->nr_quads
= DIV_ROUND_UP(chip
->nr_cores
, 4);
1338 chip9
->quads
= g_new0(PnvQuad
, chip9
->nr_quads
);
1340 for (i
= 0; i
< chip9
->nr_quads
; i
++) {
1342 PnvQuad
*eq
= &chip9
->quads
[i
];
1343 PnvCore
*pnv_core
= chip
->cores
[i
* 4];
1344 int core_id
= CPU_CORE(pnv_core
)->core_id
;
1346 snprintf(eq_name
, sizeof(eq_name
), "eq[%d]", core_id
);
1347 object_initialize_child_with_props(OBJECT(chip
), eq_name
, eq
,
1348 sizeof(*eq
), TYPE_PNV_QUAD
,
1349 &error_fatal
, NULL
);
1351 object_property_set_int(OBJECT(eq
), core_id
, "id", &error_fatal
);
1352 qdev_realize(DEVICE(eq
), NULL
, &error_fatal
);
1354 pnv_xscom_add_subregion(chip
, PNV9_XSCOM_EQ_BASE(eq
->id
),
1359 static void pnv_chip_power9_phb_realize(PnvChip
*chip
, Error
**errp
)
1361 Pnv9Chip
*chip9
= PNV9_CHIP(chip
);
1362 Error
*local_err
= NULL
;
1366 for (i
= 0; i
< PNV9_CHIP_MAX_PEC
; i
++) {
1367 PnvPhb4PecState
*pec
= &chip9
->pecs
[i
];
1368 PnvPhb4PecClass
*pecc
= PNV_PHB4_PEC_GET_CLASS(pec
);
1369 uint32_t pec_nest_base
;
1370 uint32_t pec_pci_base
;
1372 object_property_set_int(OBJECT(pec
), i
, "index", &error_fatal
);
1378 object_property_set_int(OBJECT(pec
), i
+ 1, "num-stacks",
1380 object_property_set_int(OBJECT(pec
), chip
->chip_id
, "chip-id",
1382 object_property_set_link(OBJECT(pec
), OBJECT(get_system_memory()),
1383 "system-memory", &error_abort
);
1384 qdev_realize(DEVICE(pec
), NULL
, &local_err
);
1386 error_propagate(errp
, local_err
);
1390 pec_nest_base
= pecc
->xscom_nest_base(pec
);
1391 pec_pci_base
= pecc
->xscom_pci_base(pec
);
1393 pnv_xscom_add_subregion(chip
, pec_nest_base
, &pec
->nest_regs_mr
);
1394 pnv_xscom_add_subregion(chip
, pec_pci_base
, &pec
->pci_regs_mr
);
1396 for (j
= 0; j
< pec
->num_stacks
&& phb_id
< chip
->num_phbs
;
1398 PnvPhb4PecStack
*stack
= &pec
->stacks
[j
];
1399 Object
*obj
= OBJECT(&stack
->phb
);
1401 object_property_set_int(obj
, phb_id
, "index", &error_fatal
);
1402 object_property_set_int(obj
, chip
->chip_id
, "chip-id",
1404 object_property_set_int(obj
, PNV_PHB4_VERSION
, "version",
1406 object_property_set_int(obj
, PNV_PHB4_DEVICE_ID
, "device-id",
1408 object_property_set_link(obj
, OBJECT(stack
), "stack", &error_abort
);
1409 sysbus_realize(SYS_BUS_DEVICE(obj
), &local_err
);
1411 error_propagate(errp
, local_err
);
1415 /* Populate the XSCOM address space. */
1416 pnv_xscom_add_subregion(chip
,
1417 pec_nest_base
+ 0x40 * (stack
->stack_no
+ 1),
1418 &stack
->nest_regs_mr
);
1419 pnv_xscom_add_subregion(chip
,
1420 pec_pci_base
+ 0x40 * (stack
->stack_no
+ 1),
1421 &stack
->pci_regs_mr
);
1422 pnv_xscom_add_subregion(chip
,
1423 pec_pci_base
+ PNV9_XSCOM_PEC_PCI_STK0
+
1424 0x40 * stack
->stack_no
,
1425 &stack
->phb_regs_mr
);
1430 static void pnv_chip_power9_realize(DeviceState
*dev
, Error
**errp
)
1432 PnvChipClass
*pcc
= PNV_CHIP_GET_CLASS(dev
);
1433 Pnv9Chip
*chip9
= PNV9_CHIP(dev
);
1434 PnvChip
*chip
= PNV_CHIP(dev
);
1435 Pnv9Psi
*psi9
= &chip9
->psi
;
1436 Error
*local_err
= NULL
;
1438 /* XSCOM bridge is first */
1439 pnv_xscom_realize(chip
, PNV9_XSCOM_SIZE
, &local_err
);
1441 error_propagate(errp
, local_err
);
1444 sysbus_mmio_map(SYS_BUS_DEVICE(chip
), 0, PNV9_XSCOM_BASE(chip
));
1446 pcc
->parent_realize(dev
, &local_err
);
1448 error_propagate(errp
, local_err
);
1452 pnv_chip_quad_realize(chip9
, &local_err
);
1454 error_propagate(errp
, local_err
);
1458 /* XIVE interrupt controller (POWER9) */
1459 object_property_set_int(OBJECT(&chip9
->xive
), PNV9_XIVE_IC_BASE(chip
),
1460 "ic-bar", &error_fatal
);
1461 object_property_set_int(OBJECT(&chip9
->xive
), PNV9_XIVE_VC_BASE(chip
),
1462 "vc-bar", &error_fatal
);
1463 object_property_set_int(OBJECT(&chip9
->xive
), PNV9_XIVE_PC_BASE(chip
),
1464 "pc-bar", &error_fatal
);
1465 object_property_set_int(OBJECT(&chip9
->xive
), PNV9_XIVE_TM_BASE(chip
),
1466 "tm-bar", &error_fatal
);
1467 object_property_set_link(OBJECT(&chip9
->xive
), OBJECT(chip
), "chip",
1469 sysbus_realize(SYS_BUS_DEVICE(&chip9
->xive
), &local_err
);
1471 error_propagate(errp
, local_err
);
1474 pnv_xscom_add_subregion(chip
, PNV9_XSCOM_XIVE_BASE
,
1475 &chip9
->xive
.xscom_regs
);
1477 /* Processor Service Interface (PSI) Host Bridge */
1478 object_property_set_int(OBJECT(&chip9
->psi
), PNV9_PSIHB_BASE(chip
),
1479 "bar", &error_fatal
);
1480 qdev_realize(DEVICE(&chip9
->psi
), NULL
, &local_err
);
1482 error_propagate(errp
, local_err
);
1485 pnv_xscom_add_subregion(chip
, PNV9_XSCOM_PSIHB_BASE
,
1486 &PNV_PSI(psi9
)->xscom_regs
);
1489 object_property_set_link(OBJECT(&chip9
->lpc
), OBJECT(&chip9
->psi
), "psi",
1491 qdev_realize(DEVICE(&chip9
->lpc
), NULL
, &local_err
);
1493 error_propagate(errp
, local_err
);
1496 memory_region_add_subregion(get_system_memory(), PNV9_LPCM_BASE(chip
),
1497 &chip9
->lpc
.xscom_regs
);
1499 chip
->dt_isa_nodename
= g_strdup_printf("/lpcm-opb@%" PRIx64
"/lpc@0",
1500 (uint64_t) PNV9_LPCM_BASE(chip
));
1502 /* Create the simplified OCC model */
1503 object_property_set_link(OBJECT(&chip9
->occ
), OBJECT(&chip9
->psi
), "psi",
1505 qdev_realize(DEVICE(&chip9
->occ
), NULL
, &local_err
);
1507 error_propagate(errp
, local_err
);
1510 pnv_xscom_add_subregion(chip
, PNV9_XSCOM_OCC_BASE
, &chip9
->occ
.xscom_regs
);
1512 /* OCC SRAM model */
1513 memory_region_add_subregion(get_system_memory(), PNV9_OCC_SENSOR_BASE(chip
),
1514 &chip9
->occ
.sram_regs
);
1517 object_property_set_link(OBJECT(&chip9
->homer
), OBJECT(chip
), "chip",
1519 qdev_realize(DEVICE(&chip9
->homer
), NULL
, &local_err
);
1521 error_propagate(errp
, local_err
);
1524 /* Homer Xscom region */
1525 pnv_xscom_add_subregion(chip
, PNV9_XSCOM_PBA_BASE
, &chip9
->homer
.pba_regs
);
1527 /* Homer mmio region */
1528 memory_region_add_subregion(get_system_memory(), PNV9_HOMER_BASE(chip
),
1529 &chip9
->homer
.regs
);
1532 pnv_chip_power9_phb_realize(chip
, &local_err
);
1534 error_propagate(errp
, local_err
);
1539 static uint32_t pnv_chip_power9_xscom_pcba(PnvChip
*chip
, uint64_t addr
)
1541 addr
&= (PNV9_XSCOM_SIZE
- 1);
1545 static void pnv_chip_power9_class_init(ObjectClass
*klass
, void *data
)
1547 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1548 PnvChipClass
*k
= PNV_CHIP_CLASS(klass
);
1550 k
->chip_cfam_id
= 0x220d104900008000ull
; /* P9 Nimbus DD2.0 */
1551 k
->cores_mask
= POWER9_CORE_MASK
;
1552 k
->core_pir
= pnv_chip_core_pir_p9
;
1553 k
->intc_create
= pnv_chip_power9_intc_create
;
1554 k
->intc_reset
= pnv_chip_power9_intc_reset
;
1555 k
->intc_destroy
= pnv_chip_power9_intc_destroy
;
1556 k
->intc_print_info
= pnv_chip_power9_intc_print_info
;
1557 k
->isa_create
= pnv_chip_power9_isa_create
;
1558 k
->dt_populate
= pnv_chip_power9_dt_populate
;
1559 k
->pic_print_info
= pnv_chip_power9_pic_print_info
;
1560 k
->xscom_core_base
= pnv_chip_power9_xscom_core_base
;
1561 k
->xscom_pcba
= pnv_chip_power9_xscom_pcba
;
1562 dc
->desc
= "PowerNV Chip POWER9";
1565 device_class_set_parent_realize(dc
, pnv_chip_power9_realize
,
1566 &k
->parent_realize
);
1569 static void pnv_chip_power10_instance_init(Object
*obj
)
1571 Pnv10Chip
*chip10
= PNV10_CHIP(obj
);
1573 object_initialize_child(obj
, "psi", &chip10
->psi
, TYPE_PNV10_PSI
);
1574 object_initialize_child(obj
, "lpc", &chip10
->lpc
, TYPE_PNV10_LPC
);
1577 static void pnv_chip_power10_realize(DeviceState
*dev
, Error
**errp
)
1579 PnvChipClass
*pcc
= PNV_CHIP_GET_CLASS(dev
);
1580 PnvChip
*chip
= PNV_CHIP(dev
);
1581 Pnv10Chip
*chip10
= PNV10_CHIP(dev
);
1582 Error
*local_err
= NULL
;
1584 /* XSCOM bridge is first */
1585 pnv_xscom_realize(chip
, PNV10_XSCOM_SIZE
, &local_err
);
1587 error_propagate(errp
, local_err
);
1590 sysbus_mmio_map(SYS_BUS_DEVICE(chip
), 0, PNV10_XSCOM_BASE(chip
));
1592 pcc
->parent_realize(dev
, &local_err
);
1594 error_propagate(errp
, local_err
);
1598 /* Processor Service Interface (PSI) Host Bridge */
1599 object_property_set_int(OBJECT(&chip10
->psi
), PNV10_PSIHB_BASE(chip
),
1600 "bar", &error_fatal
);
1601 qdev_realize(DEVICE(&chip10
->psi
), NULL
, &local_err
);
1603 error_propagate(errp
, local_err
);
1606 pnv_xscom_add_subregion(chip
, PNV10_XSCOM_PSIHB_BASE
,
1607 &PNV_PSI(&chip10
->psi
)->xscom_regs
);
1610 object_property_set_link(OBJECT(&chip10
->lpc
), OBJECT(&chip10
->psi
), "psi",
1612 qdev_realize(DEVICE(&chip10
->lpc
), NULL
, &local_err
);
1614 error_propagate(errp
, local_err
);
1617 memory_region_add_subregion(get_system_memory(), PNV10_LPCM_BASE(chip
),
1618 &chip10
->lpc
.xscom_regs
);
1620 chip
->dt_isa_nodename
= g_strdup_printf("/lpcm-opb@%" PRIx64
"/lpc@0",
1621 (uint64_t) PNV10_LPCM_BASE(chip
));
1624 static uint32_t pnv_chip_power10_xscom_pcba(PnvChip
*chip
, uint64_t addr
)
1626 addr
&= (PNV10_XSCOM_SIZE
- 1);
1630 static void pnv_chip_power10_class_init(ObjectClass
*klass
, void *data
)
1632 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1633 PnvChipClass
*k
= PNV_CHIP_CLASS(klass
);
1635 k
->chip_cfam_id
= 0x120da04900008000ull
; /* P10 DD1.0 (with NX) */
1636 k
->cores_mask
= POWER10_CORE_MASK
;
1637 k
->core_pir
= pnv_chip_core_pir_p10
;
1638 k
->intc_create
= pnv_chip_power10_intc_create
;
1639 k
->intc_reset
= pnv_chip_power10_intc_reset
;
1640 k
->intc_destroy
= pnv_chip_power10_intc_destroy
;
1641 k
->intc_print_info
= pnv_chip_power10_intc_print_info
;
1642 k
->isa_create
= pnv_chip_power10_isa_create
;
1643 k
->dt_populate
= pnv_chip_power10_dt_populate
;
1644 k
->pic_print_info
= pnv_chip_power10_pic_print_info
;
1645 k
->xscom_core_base
= pnv_chip_power10_xscom_core_base
;
1646 k
->xscom_pcba
= pnv_chip_power10_xscom_pcba
;
1647 dc
->desc
= "PowerNV Chip POWER10";
1649 device_class_set_parent_realize(dc
, pnv_chip_power10_realize
,
1650 &k
->parent_realize
);
1653 static void pnv_chip_core_sanitize(PnvChip
*chip
, Error
**errp
)
1655 PnvChipClass
*pcc
= PNV_CHIP_GET_CLASS(chip
);
1659 * No custom mask for this chip, let's use the default one from *
1662 if (!chip
->cores_mask
) {
1663 chip
->cores_mask
= pcc
->cores_mask
;
1666 /* filter alien core ids ! some are reserved */
1667 if ((chip
->cores_mask
& pcc
->cores_mask
) != chip
->cores_mask
) {
1668 error_setg(errp
, "warning: invalid core mask for chip Ox%"PRIx64
" !",
1672 chip
->cores_mask
&= pcc
->cores_mask
;
1674 /* now that we have a sane layout, let check the number of cores */
1675 cores_max
= ctpop64(chip
->cores_mask
);
1676 if (chip
->nr_cores
> cores_max
) {
1677 error_setg(errp
, "warning: too many cores for chip ! Limit is %d",
1683 static void pnv_chip_core_realize(PnvChip
*chip
, Error
**errp
)
1685 Error
*error
= NULL
;
1686 PnvChipClass
*pcc
= PNV_CHIP_GET_CLASS(chip
);
1687 const char *typename
= pnv_chip_core_typename(chip
);
1689 PnvMachineState
*pnv
= PNV_MACHINE(qdev_get_machine());
1691 if (!object_class_by_name(typename
)) {
1692 error_setg(errp
, "Unable to find PowerNV CPU Core '%s'", typename
);
1697 pnv_chip_core_sanitize(chip
, &error
);
1699 error_propagate(errp
, error
);
1703 chip
->cores
= g_new0(PnvCore
*, chip
->nr_cores
);
1705 for (i
= 0, core_hwid
= 0; (core_hwid
< sizeof(chip
->cores_mask
) * 8)
1706 && (i
< chip
->nr_cores
); core_hwid
++) {
1709 uint64_t xscom_core_base
;
1711 if (!(chip
->cores_mask
& (1ull << core_hwid
))) {
1715 pnv_core
= PNV_CORE(object_new(typename
));
1717 snprintf(core_name
, sizeof(core_name
), "core[%d]", core_hwid
);
1718 object_property_add_child(OBJECT(chip
), core_name
, OBJECT(pnv_core
));
1719 chip
->cores
[i
] = pnv_core
;
1720 object_property_set_int(OBJECT(pnv_core
), chip
->nr_threads
,
1721 "nr-threads", &error_fatal
);
1722 object_property_set_int(OBJECT(pnv_core
), core_hwid
,
1723 CPU_CORE_PROP_CORE_ID
, &error_fatal
);
1724 object_property_set_int(OBJECT(pnv_core
),
1725 pcc
->core_pir(chip
, core_hwid
),
1726 "pir", &error_fatal
);
1727 object_property_set_int(OBJECT(pnv_core
), pnv
->fw_load_addr
,
1728 "hrmor", &error_fatal
);
1729 object_property_set_link(OBJECT(pnv_core
), OBJECT(chip
), "chip",
1731 qdev_realize(DEVICE(pnv_core
), NULL
, &error_fatal
);
1733 /* Each core has an XSCOM MMIO region */
1734 xscom_core_base
= pcc
->xscom_core_base(chip
, core_hwid
);
1736 pnv_xscom_add_subregion(chip
, xscom_core_base
,
1737 &pnv_core
->xscom_regs
);
1742 static void pnv_chip_realize(DeviceState
*dev
, Error
**errp
)
1744 PnvChip
*chip
= PNV_CHIP(dev
);
1745 Error
*error
= NULL
;
1748 pnv_chip_core_realize(chip
, &error
);
1750 error_propagate(errp
, error
);
1755 static Property pnv_chip_properties
[] = {
1756 DEFINE_PROP_UINT32("chip-id", PnvChip
, chip_id
, 0),
1757 DEFINE_PROP_UINT64("ram-start", PnvChip
, ram_start
, 0),
1758 DEFINE_PROP_UINT64("ram-size", PnvChip
, ram_size
, 0),
1759 DEFINE_PROP_UINT32("nr-cores", PnvChip
, nr_cores
, 1),
1760 DEFINE_PROP_UINT64("cores-mask", PnvChip
, cores_mask
, 0x0),
1761 DEFINE_PROP_UINT32("nr-threads", PnvChip
, nr_threads
, 1),
1762 DEFINE_PROP_UINT32("num-phbs", PnvChip
, num_phbs
, 0),
1763 DEFINE_PROP_END_OF_LIST(),
1766 static void pnv_chip_class_init(ObjectClass
*klass
, void *data
)
1768 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1770 set_bit(DEVICE_CATEGORY_CPU
, dc
->categories
);
1771 dc
->realize
= pnv_chip_realize
;
1772 device_class_set_props(dc
, pnv_chip_properties
);
1773 dc
->desc
= "PowerNV Chip";
1776 PowerPCCPU
*pnv_chip_find_cpu(PnvChip
*chip
, uint32_t pir
)
1780 for (i
= 0; i
< chip
->nr_cores
; i
++) {
1781 PnvCore
*pc
= chip
->cores
[i
];
1782 CPUCore
*cc
= CPU_CORE(pc
);
1784 for (j
= 0; j
< cc
->nr_threads
; j
++) {
1785 if (ppc_cpu_pir(pc
->threads
[j
]) == pir
) {
1786 return pc
->threads
[j
];
1793 static ICSState
*pnv_ics_get(XICSFabric
*xi
, int irq
)
1795 PnvMachineState
*pnv
= PNV_MACHINE(xi
);
1798 for (i
= 0; i
< pnv
->num_chips
; i
++) {
1799 PnvChip
*chip
= pnv
->chips
[i
];
1800 Pnv8Chip
*chip8
= PNV8_CHIP(pnv
->chips
[i
]);
1802 if (ics_valid_irq(&chip8
->psi
.ics
, irq
)) {
1803 return &chip8
->psi
.ics
;
1805 for (j
= 0; j
< chip
->num_phbs
; j
++) {
1806 if (ics_valid_irq(&chip8
->phbs
[j
].lsis
, irq
)) {
1807 return &chip8
->phbs
[j
].lsis
;
1809 if (ics_valid_irq(ICS(&chip8
->phbs
[j
].msis
), irq
)) {
1810 return ICS(&chip8
->phbs
[j
].msis
);
1817 static void pnv_ics_resend(XICSFabric
*xi
)
1819 PnvMachineState
*pnv
= PNV_MACHINE(xi
);
1822 for (i
= 0; i
< pnv
->num_chips
; i
++) {
1823 PnvChip
*chip
= pnv
->chips
[i
];
1824 Pnv8Chip
*chip8
= PNV8_CHIP(pnv
->chips
[i
]);
1826 ics_resend(&chip8
->psi
.ics
);
1827 for (j
= 0; j
< chip
->num_phbs
; j
++) {
1828 ics_resend(&chip8
->phbs
[j
].lsis
);
1829 ics_resend(ICS(&chip8
->phbs
[j
].msis
));
1834 static ICPState
*pnv_icp_get(XICSFabric
*xi
, int pir
)
1836 PowerPCCPU
*cpu
= ppc_get_vcpu_by_pir(pir
);
1838 return cpu
? ICP(pnv_cpu_state(cpu
)->intc
) : NULL
;
1841 static void pnv_pic_print_info(InterruptStatsProvider
*obj
,
1844 PnvMachineState
*pnv
= PNV_MACHINE(obj
);
1849 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
1851 /* XXX: loop on each chip/core/thread instead of CPU_FOREACH() */
1852 PNV_CHIP_GET_CLASS(pnv
->chips
[0])->intc_print_info(pnv
->chips
[0], cpu
,
1856 for (i
= 0; i
< pnv
->num_chips
; i
++) {
1857 PNV_CHIP_GET_CLASS(pnv
->chips
[i
])->pic_print_info(pnv
->chips
[i
], mon
);
1861 static int pnv_match_nvt(XiveFabric
*xfb
, uint8_t format
,
1862 uint8_t nvt_blk
, uint32_t nvt_idx
,
1863 bool cam_ignore
, uint8_t priority
,
1864 uint32_t logic_serv
,
1865 XiveTCTXMatch
*match
)
1867 PnvMachineState
*pnv
= PNV_MACHINE(xfb
);
1868 int total_count
= 0;
1871 for (i
= 0; i
< pnv
->num_chips
; i
++) {
1872 Pnv9Chip
*chip9
= PNV9_CHIP(pnv
->chips
[i
]);
1873 XivePresenter
*xptr
= XIVE_PRESENTER(&chip9
->xive
);
1874 XivePresenterClass
*xpc
= XIVE_PRESENTER_GET_CLASS(xptr
);
1877 count
= xpc
->match_nvt(xptr
, format
, nvt_blk
, nvt_idx
, cam_ignore
,
1878 priority
, logic_serv
, match
);
1884 total_count
+= count
;
1890 static void pnv_machine_power8_class_init(ObjectClass
*oc
, void *data
)
1892 MachineClass
*mc
= MACHINE_CLASS(oc
);
1893 XICSFabricClass
*xic
= XICS_FABRIC_CLASS(oc
);
1894 PnvMachineClass
*pmc
= PNV_MACHINE_CLASS(oc
);
1895 static const char compat
[] = "qemu,powernv8\0qemu,powernv\0ibm,powernv";
1897 mc
->desc
= "IBM PowerNV (Non-Virtualized) POWER8";
1898 mc
->default_cpu_type
= POWERPC_CPU_TYPE_NAME("power8_v2.0");
1900 xic
->icp_get
= pnv_icp_get
;
1901 xic
->ics_get
= pnv_ics_get
;
1902 xic
->ics_resend
= pnv_ics_resend
;
1904 pmc
->compat
= compat
;
1905 pmc
->compat_size
= sizeof(compat
);
1908 static void pnv_machine_power9_class_init(ObjectClass
*oc
, void *data
)
1910 MachineClass
*mc
= MACHINE_CLASS(oc
);
1911 XiveFabricClass
*xfc
= XIVE_FABRIC_CLASS(oc
);
1912 PnvMachineClass
*pmc
= PNV_MACHINE_CLASS(oc
);
1913 static const char compat
[] = "qemu,powernv9\0ibm,powernv";
1915 mc
->desc
= "IBM PowerNV (Non-Virtualized) POWER9";
1916 mc
->default_cpu_type
= POWERPC_CPU_TYPE_NAME("power9_v2.0");
1917 xfc
->match_nvt
= pnv_match_nvt
;
1919 mc
->alias
= "powernv";
1921 pmc
->compat
= compat
;
1922 pmc
->compat_size
= sizeof(compat
);
1923 pmc
->dt_power_mgt
= pnv_dt_power_mgt
;
1926 static void pnv_machine_power10_class_init(ObjectClass
*oc
, void *data
)
1928 MachineClass
*mc
= MACHINE_CLASS(oc
);
1929 PnvMachineClass
*pmc
= PNV_MACHINE_CLASS(oc
);
1930 static const char compat
[] = "qemu,powernv10\0ibm,powernv";
1932 mc
->desc
= "IBM PowerNV (Non-Virtualized) POWER10";
1933 mc
->default_cpu_type
= POWERPC_CPU_TYPE_NAME("power10_v1.0");
1935 pmc
->compat
= compat
;
1936 pmc
->compat_size
= sizeof(compat
);
1937 pmc
->dt_power_mgt
= pnv_dt_power_mgt
;
1940 static bool pnv_machine_get_hb(Object
*obj
, Error
**errp
)
1942 PnvMachineState
*pnv
= PNV_MACHINE(obj
);
1944 return !!pnv
->fw_load_addr
;
1947 static void pnv_machine_set_hb(Object
*obj
, bool value
, Error
**errp
)
1949 PnvMachineState
*pnv
= PNV_MACHINE(obj
);
1952 pnv
->fw_load_addr
= 0x8000000;
1956 static void pnv_cpu_do_nmi_on_cpu(CPUState
*cs
, run_on_cpu_data arg
)
1958 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
1959 CPUPPCState
*env
= &cpu
->env
;
1961 cpu_synchronize_state(cs
);
1962 ppc_cpu_do_system_reset(cs
);
1963 if (env
->spr
[SPR_SRR1
] & SRR1_WAKESTATE
) {
1965 * Power-save wakeups, as indicated by non-zero SRR1[46:47] put the
1966 * wakeup reason in SRR1[42:45], system reset is indicated with 0b0100
1969 if (!(env
->spr
[SPR_SRR1
] & SRR1_WAKERESET
)) {
1970 warn_report("ppc_cpu_do_system_reset does not set system reset wakeup reason");
1971 env
->spr
[SPR_SRR1
] |= SRR1_WAKERESET
;
1975 * For non-powersave system resets, SRR1[42:45] are defined to be
1976 * implementation-dependent. The POWER9 User Manual specifies that
1977 * an external (SCOM driven, which may come from a BMC nmi command or
1978 * another CPU requesting a NMI IPI) system reset exception should be
1979 * 0b0010 (PPC_BIT(44)).
1981 env
->spr
[SPR_SRR1
] |= SRR1_WAKESCOM
;
1985 static void pnv_nmi(NMIState
*n
, int cpu_index
, Error
**errp
)
1990 async_run_on_cpu(cs
, pnv_cpu_do_nmi_on_cpu
, RUN_ON_CPU_NULL
);
1994 static void pnv_machine_class_init(ObjectClass
*oc
, void *data
)
1996 MachineClass
*mc
= MACHINE_CLASS(oc
);
1997 InterruptStatsProviderClass
*ispc
= INTERRUPT_STATS_PROVIDER_CLASS(oc
);
1998 NMIClass
*nc
= NMI_CLASS(oc
);
2000 mc
->desc
= "IBM PowerNV (Non-Virtualized)";
2001 mc
->init
= pnv_init
;
2002 mc
->reset
= pnv_reset
;
2003 mc
->max_cpus
= MAX_CPUS
;
2004 /* Pnv provides a AHCI device for storage */
2005 mc
->block_default_type
= IF_IDE
;
2006 mc
->no_parallel
= 1;
2007 mc
->default_boot_order
= NULL
;
2009 * RAM defaults to less than 2048 for 32-bit hosts, and large
2010 * enough to fit the maximum initrd size at it's load address
2012 mc
->default_ram_size
= INITRD_LOAD_ADDR
+ INITRD_MAX_SIZE
;
2013 mc
->default_ram_id
= "pnv.ram";
2014 ispc
->print_info
= pnv_pic_print_info
;
2015 nc
->nmi_monitor_handler
= pnv_nmi
;
2017 object_class_property_add_bool(oc
, "hb-mode",
2018 pnv_machine_get_hb
, pnv_machine_set_hb
);
2019 object_class_property_set_description(oc
, "hb-mode",
2020 "Use a hostboot like boot loader");
2023 #define DEFINE_PNV8_CHIP_TYPE(type, class_initfn) \
2026 .class_init = class_initfn, \
2027 .parent = TYPE_PNV8_CHIP, \
2030 #define DEFINE_PNV9_CHIP_TYPE(type, class_initfn) \
2033 .class_init = class_initfn, \
2034 .parent = TYPE_PNV9_CHIP, \
2037 #define DEFINE_PNV10_CHIP_TYPE(type, class_initfn) \
2040 .class_init = class_initfn, \
2041 .parent = TYPE_PNV10_CHIP, \
2044 static const TypeInfo types
[] = {
2046 .name
= MACHINE_TYPE_NAME("powernv10"),
2047 .parent
= TYPE_PNV_MACHINE
,
2048 .class_init
= pnv_machine_power10_class_init
,
2051 .name
= MACHINE_TYPE_NAME("powernv9"),
2052 .parent
= TYPE_PNV_MACHINE
,
2053 .class_init
= pnv_machine_power9_class_init
,
2054 .interfaces
= (InterfaceInfo
[]) {
2055 { TYPE_XIVE_FABRIC
},
2060 .name
= MACHINE_TYPE_NAME("powernv8"),
2061 .parent
= TYPE_PNV_MACHINE
,
2062 .class_init
= pnv_machine_power8_class_init
,
2063 .interfaces
= (InterfaceInfo
[]) {
2064 { TYPE_XICS_FABRIC
},
2069 .name
= TYPE_PNV_MACHINE
,
2070 .parent
= TYPE_MACHINE
,
2072 .instance_size
= sizeof(PnvMachineState
),
2073 .class_init
= pnv_machine_class_init
,
2074 .class_size
= sizeof(PnvMachineClass
),
2075 .interfaces
= (InterfaceInfo
[]) {
2076 { TYPE_INTERRUPT_STATS_PROVIDER
},
2082 .name
= TYPE_PNV_CHIP
,
2083 .parent
= TYPE_SYS_BUS_DEVICE
,
2084 .class_init
= pnv_chip_class_init
,
2085 .instance_size
= sizeof(PnvChip
),
2086 .class_size
= sizeof(PnvChipClass
),
2091 * P10 chip and variants
2094 .name
= TYPE_PNV10_CHIP
,
2095 .parent
= TYPE_PNV_CHIP
,
2096 .instance_init
= pnv_chip_power10_instance_init
,
2097 .instance_size
= sizeof(Pnv10Chip
),
2099 DEFINE_PNV10_CHIP_TYPE(TYPE_PNV_CHIP_POWER10
, pnv_chip_power10_class_init
),
2102 * P9 chip and variants
2105 .name
= TYPE_PNV9_CHIP
,
2106 .parent
= TYPE_PNV_CHIP
,
2107 .instance_init
= pnv_chip_power9_instance_init
,
2108 .instance_size
= sizeof(Pnv9Chip
),
2110 DEFINE_PNV9_CHIP_TYPE(TYPE_PNV_CHIP_POWER9
, pnv_chip_power9_class_init
),
2113 * P8 chip and variants
2116 .name
= TYPE_PNV8_CHIP
,
2117 .parent
= TYPE_PNV_CHIP
,
2118 .instance_init
= pnv_chip_power8_instance_init
,
2119 .instance_size
= sizeof(Pnv8Chip
),
2121 DEFINE_PNV8_CHIP_TYPE(TYPE_PNV_CHIP_POWER8
, pnv_chip_power8_class_init
),
2122 DEFINE_PNV8_CHIP_TYPE(TYPE_PNV_CHIP_POWER8E
, pnv_chip_power8e_class_init
),
2123 DEFINE_PNV8_CHIP_TYPE(TYPE_PNV_CHIP_POWER8NVL
,
2124 pnv_chip_power8nvl_class_init
),