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.1 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/datadir.h"
23 #include "qemu/units.h"
24 #include "qapi/error.h"
25 #include "sysemu/qtest.h"
26 #include "sysemu/sysemu.h"
27 #include "sysemu/numa.h"
28 #include "sysemu/reset.h"
29 #include "sysemu/runstate.h"
30 #include "sysemu/cpus.h"
31 #include "sysemu/device_tree.h"
32 #include "sysemu/hw_accel.h"
33 #include "target/ppc/cpu.h"
35 #include "hw/ppc/fdt.h"
36 #include "hw/ppc/ppc.h"
37 #include "hw/ppc/pnv.h"
38 #include "hw/ppc/pnv_core.h"
39 #include "hw/loader.h"
41 #include "exec/address-spaces.h"
42 #include "qapi/visitor.h"
43 #include "monitor/monitor.h"
44 #include "hw/intc/intc.h"
45 #include "hw/ipmi/ipmi.h"
46 #include "target/ppc/mmu-hash64.h"
47 #include "hw/pci/msi.h"
49 #include "hw/ppc/xics.h"
50 #include "hw/qdev-properties.h"
51 #include "hw/ppc/pnv_xscom.h"
52 #include "hw/ppc/pnv_pnor.h"
54 #include "hw/isa/isa.h"
55 #include "hw/boards.h"
56 #include "hw/char/serial.h"
57 #include "hw/rtc/mc146818rtc.h"
61 #define FDT_MAX_SIZE (1 * MiB)
63 #define FW_FILE_NAME "skiboot.lid"
64 #define FW_LOAD_ADDR 0x0
65 #define FW_MAX_SIZE (16 * MiB)
67 #define KERNEL_LOAD_ADDR 0x20000000
68 #define KERNEL_MAX_SIZE (128 * MiB)
69 #define INITRD_LOAD_ADDR 0x28000000
70 #define INITRD_MAX_SIZE (128 * MiB)
72 static const char *pnv_chip_core_typename(const PnvChip
*o
)
74 const char *chip_type
= object_class_get_name(object_get_class(OBJECT(o
)));
75 int len
= strlen(chip_type
) - strlen(PNV_CHIP_TYPE_SUFFIX
);
76 char *s
= g_strdup_printf(PNV_CORE_TYPE_NAME("%.*s"), len
, chip_type
);
77 const char *core_type
= object_class_get_name(object_class_by_name(s
));
83 * On Power Systems E880 (POWER8), the max cpus (threads) should be :
84 * 4 * 4 sockets * 12 cores * 8 threads = 1536
90 * Memory nodes are created by hostboot, one for each range of memory
91 * that has a different "affinity". In practice, it means one range
94 static void pnv_dt_memory(void *fdt
, int chip_id
, hwaddr start
, hwaddr size
)
97 uint64_t mem_reg_property
[2];
100 mem_reg_property
[0] = cpu_to_be64(start
);
101 mem_reg_property
[1] = cpu_to_be64(size
);
103 mem_name
= g_strdup_printf("memory@%"HWADDR_PRIx
, start
);
104 off
= fdt_add_subnode(fdt
, 0, mem_name
);
107 _FDT((fdt_setprop_string(fdt
, off
, "device_type", "memory")));
108 _FDT((fdt_setprop(fdt
, off
, "reg", mem_reg_property
,
109 sizeof(mem_reg_property
))));
110 _FDT((fdt_setprop_cell(fdt
, off
, "ibm,chip-id", chip_id
)));
113 static int get_cpus_node(void *fdt
)
115 int cpus_offset
= fdt_path_offset(fdt
, "/cpus");
117 if (cpus_offset
< 0) {
118 cpus_offset
= fdt_add_subnode(fdt
, 0, "cpus");
120 _FDT((fdt_setprop_cell(fdt
, cpus_offset
, "#address-cells", 0x1)));
121 _FDT((fdt_setprop_cell(fdt
, cpus_offset
, "#size-cells", 0x0)));
129 * The PowerNV cores (and threads) need to use real HW ids and not an
130 * incremental index like it has been done on other platforms. This HW
131 * id is stored in the CPU PIR, it is used to create cpu nodes in the
132 * device tree, used in XSCOM to address cores and in interrupt
135 static void pnv_dt_core(PnvChip
*chip
, PnvCore
*pc
, void *fdt
)
137 PowerPCCPU
*cpu
= pc
->threads
[0];
138 CPUState
*cs
= CPU(cpu
);
139 DeviceClass
*dc
= DEVICE_GET_CLASS(cs
);
140 int smt_threads
= CPU_CORE(pc
)->nr_threads
;
141 CPUPPCState
*env
= &cpu
->env
;
142 PowerPCCPUClass
*pcc
= POWERPC_CPU_GET_CLASS(cs
);
143 uint32_t servers_prop
[smt_threads
];
145 uint32_t segs
[] = {cpu_to_be32(28), cpu_to_be32(40),
146 0xffffffff, 0xffffffff};
147 uint32_t tbfreq
= PNV_TIMEBASE_FREQ
;
148 uint32_t cpufreq
= 1000000000;
149 uint32_t page_sizes_prop
[64];
150 size_t page_sizes_prop_size
;
151 const uint8_t pa_features
[] = { 24, 0,
152 0xf6, 0x3f, 0xc7, 0xc0, 0x80, 0xf0,
153 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
154 0x00, 0x00, 0x00, 0x00, 0x80, 0x00,
155 0x80, 0x00, 0x80, 0x00, 0x80, 0x00 };
158 int cpus_offset
= get_cpus_node(fdt
);
160 nodename
= g_strdup_printf("%s@%x", dc
->fw_name
, pc
->pir
);
161 offset
= fdt_add_subnode(fdt
, cpus_offset
, nodename
);
165 _FDT((fdt_setprop_cell(fdt
, offset
, "ibm,chip-id", chip
->chip_id
)));
167 _FDT((fdt_setprop_cell(fdt
, offset
, "reg", pc
->pir
)));
168 _FDT((fdt_setprop_cell(fdt
, offset
, "ibm,pir", pc
->pir
)));
169 _FDT((fdt_setprop_string(fdt
, offset
, "device_type", "cpu")));
171 _FDT((fdt_setprop_cell(fdt
, offset
, "cpu-version", env
->spr
[SPR_PVR
])));
172 _FDT((fdt_setprop_cell(fdt
, offset
, "d-cache-block-size",
173 env
->dcache_line_size
)));
174 _FDT((fdt_setprop_cell(fdt
, offset
, "d-cache-line-size",
175 env
->dcache_line_size
)));
176 _FDT((fdt_setprop_cell(fdt
, offset
, "i-cache-block-size",
177 env
->icache_line_size
)));
178 _FDT((fdt_setprop_cell(fdt
, offset
, "i-cache-line-size",
179 env
->icache_line_size
)));
181 if (pcc
->l1_dcache_size
) {
182 _FDT((fdt_setprop_cell(fdt
, offset
, "d-cache-size",
183 pcc
->l1_dcache_size
)));
185 warn_report("Unknown L1 dcache size for cpu");
187 if (pcc
->l1_icache_size
) {
188 _FDT((fdt_setprop_cell(fdt
, offset
, "i-cache-size",
189 pcc
->l1_icache_size
)));
191 warn_report("Unknown L1 icache size for cpu");
194 _FDT((fdt_setprop_cell(fdt
, offset
, "timebase-frequency", tbfreq
)));
195 _FDT((fdt_setprop_cell(fdt
, offset
, "clock-frequency", cpufreq
)));
196 _FDT((fdt_setprop_cell(fdt
, offset
, "ibm,slb-size",
197 cpu
->hash64_opts
->slb_size
)));
198 _FDT((fdt_setprop_string(fdt
, offset
, "status", "okay")));
199 _FDT((fdt_setprop(fdt
, offset
, "64-bit", NULL
, 0)));
201 if (env
->spr_cb
[SPR_PURR
].oea_read
) {
202 _FDT((fdt_setprop(fdt
, offset
, "ibm,purr", NULL
, 0)));
205 if (ppc_hash64_has(cpu
, PPC_HASH64_1TSEG
)) {
206 _FDT((fdt_setprop(fdt
, offset
, "ibm,processor-segment-sizes",
207 segs
, sizeof(segs
))));
211 * Advertise VMX/VSX (vector extensions) if available
212 * 0 / no property == no vector extensions
213 * 1 == VMX / Altivec available
216 if (env
->insns_flags
& PPC_ALTIVEC
) {
217 uint32_t vmx
= (env
->insns_flags2
& PPC2_VSX
) ? 2 : 1;
219 _FDT((fdt_setprop_cell(fdt
, offset
, "ibm,vmx", vmx
)));
223 * Advertise DFP (Decimal Floating Point) if available
224 * 0 / no property == no DFP
227 if (env
->insns_flags2
& PPC2_DFP
) {
228 _FDT((fdt_setprop_cell(fdt
, offset
, "ibm,dfp", 1)));
231 page_sizes_prop_size
= ppc_create_page_sizes_prop(cpu
, page_sizes_prop
,
232 sizeof(page_sizes_prop
));
233 if (page_sizes_prop_size
) {
234 _FDT((fdt_setprop(fdt
, offset
, "ibm,segment-page-sizes",
235 page_sizes_prop
, page_sizes_prop_size
)));
238 _FDT((fdt_setprop(fdt
, offset
, "ibm,pa-features",
239 pa_features
, sizeof(pa_features
))));
241 /* Build interrupt servers properties */
242 for (i
= 0; i
< smt_threads
; i
++) {
243 servers_prop
[i
] = cpu_to_be32(pc
->pir
+ i
);
245 _FDT((fdt_setprop(fdt
, offset
, "ibm,ppc-interrupt-server#s",
246 servers_prop
, sizeof(servers_prop
))));
249 static void pnv_dt_icp(PnvChip
*chip
, void *fdt
, uint32_t pir
,
252 uint64_t addr
= PNV_ICP_BASE(chip
) | (pir
<< 12);
254 const char compat
[] = "IBM,power8-icp\0IBM,ppc-xicp";
255 uint32_t irange
[2], i
, rsize
;
259 irange
[0] = cpu_to_be32(pir
);
260 irange
[1] = cpu_to_be32(nr_threads
);
262 rsize
= sizeof(uint64_t) * 2 * nr_threads
;
263 reg
= g_malloc(rsize
);
264 for (i
= 0; i
< nr_threads
; i
++) {
265 reg
[i
* 2] = cpu_to_be64(addr
| ((pir
+ i
) * 0x1000));
266 reg
[i
* 2 + 1] = cpu_to_be64(0x1000);
269 name
= g_strdup_printf("interrupt-controller@%"PRIX64
, addr
);
270 offset
= fdt_add_subnode(fdt
, 0, name
);
274 _FDT((fdt_setprop(fdt
, offset
, "compatible", compat
, sizeof(compat
))));
275 _FDT((fdt_setprop(fdt
, offset
, "reg", reg
, rsize
)));
276 _FDT((fdt_setprop_string(fdt
, offset
, "device_type",
277 "PowerPC-External-Interrupt-Presentation")));
278 _FDT((fdt_setprop(fdt
, offset
, "interrupt-controller", NULL
, 0)));
279 _FDT((fdt_setprop(fdt
, offset
, "ibm,interrupt-server-ranges",
280 irange
, sizeof(irange
))));
281 _FDT((fdt_setprop_cell(fdt
, offset
, "#interrupt-cells", 1)));
282 _FDT((fdt_setprop_cell(fdt
, offset
, "#address-cells", 0)));
286 static void pnv_chip_power8_dt_populate(PnvChip
*chip
, void *fdt
)
288 static const char compat
[] = "ibm,power8-xscom\0ibm,xscom";
291 pnv_dt_xscom(chip
, fdt
, 0,
292 cpu_to_be64(PNV_XSCOM_BASE(chip
)),
293 cpu_to_be64(PNV_XSCOM_SIZE
),
294 compat
, sizeof(compat
));
296 for (i
= 0; i
< chip
->nr_cores
; i
++) {
297 PnvCore
*pnv_core
= chip
->cores
[i
];
299 pnv_dt_core(chip
, pnv_core
, fdt
);
301 /* Interrupt Control Presenters (ICP). One per core. */
302 pnv_dt_icp(chip
, fdt
, pnv_core
->pir
, CPU_CORE(pnv_core
)->nr_threads
);
305 if (chip
->ram_size
) {
306 pnv_dt_memory(fdt
, chip
->chip_id
, chip
->ram_start
, chip
->ram_size
);
310 static void pnv_chip_power9_dt_populate(PnvChip
*chip
, void *fdt
)
312 static const char compat
[] = "ibm,power9-xscom\0ibm,xscom";
315 pnv_dt_xscom(chip
, fdt
, 0,
316 cpu_to_be64(PNV9_XSCOM_BASE(chip
)),
317 cpu_to_be64(PNV9_XSCOM_SIZE
),
318 compat
, sizeof(compat
));
320 for (i
= 0; i
< chip
->nr_cores
; i
++) {
321 PnvCore
*pnv_core
= chip
->cores
[i
];
323 pnv_dt_core(chip
, pnv_core
, fdt
);
326 if (chip
->ram_size
) {
327 pnv_dt_memory(fdt
, chip
->chip_id
, chip
->ram_start
, chip
->ram_size
);
330 pnv_dt_lpc(chip
, fdt
, 0, PNV9_LPCM_BASE(chip
), PNV9_LPCM_SIZE
);
333 static void pnv_chip_power10_dt_populate(PnvChip
*chip
, void *fdt
)
335 static const char compat
[] = "ibm,power10-xscom\0ibm,xscom";
338 pnv_dt_xscom(chip
, fdt
, 0,
339 cpu_to_be64(PNV10_XSCOM_BASE(chip
)),
340 cpu_to_be64(PNV10_XSCOM_SIZE
),
341 compat
, sizeof(compat
));
343 for (i
= 0; i
< chip
->nr_cores
; i
++) {
344 PnvCore
*pnv_core
= chip
->cores
[i
];
346 pnv_dt_core(chip
, pnv_core
, fdt
);
349 if (chip
->ram_size
) {
350 pnv_dt_memory(fdt
, chip
->chip_id
, chip
->ram_start
, chip
->ram_size
);
353 pnv_dt_lpc(chip
, fdt
, 0, PNV10_LPCM_BASE(chip
), PNV10_LPCM_SIZE
);
356 static void pnv_dt_rtc(ISADevice
*d
, void *fdt
, int lpc_off
)
358 uint32_t io_base
= d
->ioport_id
;
359 uint32_t io_regs
[] = {
361 cpu_to_be32(io_base
),
367 name
= g_strdup_printf("%s@i%x", qdev_fw_name(DEVICE(d
)), io_base
);
368 node
= fdt_add_subnode(fdt
, lpc_off
, name
);
372 _FDT((fdt_setprop(fdt
, node
, "reg", io_regs
, sizeof(io_regs
))));
373 _FDT((fdt_setprop_string(fdt
, node
, "compatible", "pnpPNP,b00")));
376 static void pnv_dt_serial(ISADevice
*d
, void *fdt
, int lpc_off
)
378 const char compatible
[] = "ns16550\0pnpPNP,501";
379 uint32_t io_base
= d
->ioport_id
;
380 uint32_t io_regs
[] = {
382 cpu_to_be32(io_base
),
388 name
= g_strdup_printf("%s@i%x", qdev_fw_name(DEVICE(d
)), io_base
);
389 node
= fdt_add_subnode(fdt
, lpc_off
, name
);
393 _FDT((fdt_setprop(fdt
, node
, "reg", io_regs
, sizeof(io_regs
))));
394 _FDT((fdt_setprop(fdt
, node
, "compatible", compatible
,
395 sizeof(compatible
))));
397 _FDT((fdt_setprop_cell(fdt
, node
, "clock-frequency", 1843200)));
398 _FDT((fdt_setprop_cell(fdt
, node
, "current-speed", 115200)));
399 _FDT((fdt_setprop_cell(fdt
, node
, "interrupts", d
->isairq
[0])));
400 _FDT((fdt_setprop_cell(fdt
, node
, "interrupt-parent",
401 fdt_get_phandle(fdt
, lpc_off
))));
403 /* This is needed by Linux */
404 _FDT((fdt_setprop_string(fdt
, node
, "device_type", "serial")));
407 static void pnv_dt_ipmi_bt(ISADevice
*d
, void *fdt
, int lpc_off
)
409 const char compatible
[] = "bt\0ipmi-bt";
411 uint32_t io_regs
[] = {
413 0, /* 'io_base' retrieved from the 'ioport' property of 'isa-ipmi-bt' */
420 io_base
= object_property_get_int(OBJECT(d
), "ioport", &error_fatal
);
421 io_regs
[1] = cpu_to_be32(io_base
);
423 irq
= object_property_get_int(OBJECT(d
), "irq", &error_fatal
);
425 name
= g_strdup_printf("%s@i%x", qdev_fw_name(DEVICE(d
)), io_base
);
426 node
= fdt_add_subnode(fdt
, lpc_off
, name
);
430 _FDT((fdt_setprop(fdt
, node
, "reg", io_regs
, sizeof(io_regs
))));
431 _FDT((fdt_setprop(fdt
, node
, "compatible", compatible
,
432 sizeof(compatible
))));
434 /* Mark it as reserved to avoid Linux trying to claim it */
435 _FDT((fdt_setprop_string(fdt
, node
, "status", "reserved")));
436 _FDT((fdt_setprop_cell(fdt
, node
, "interrupts", irq
)));
437 _FDT((fdt_setprop_cell(fdt
, node
, "interrupt-parent",
438 fdt_get_phandle(fdt
, lpc_off
))));
441 typedef struct ForeachPopulateArgs
{
444 } ForeachPopulateArgs
;
446 static int pnv_dt_isa_device(DeviceState
*dev
, void *opaque
)
448 ForeachPopulateArgs
*args
= opaque
;
449 ISADevice
*d
= ISA_DEVICE(dev
);
451 if (object_dynamic_cast(OBJECT(dev
), TYPE_MC146818_RTC
)) {
452 pnv_dt_rtc(d
, args
->fdt
, args
->offset
);
453 } else if (object_dynamic_cast(OBJECT(dev
), TYPE_ISA_SERIAL
)) {
454 pnv_dt_serial(d
, args
->fdt
, args
->offset
);
455 } else if (object_dynamic_cast(OBJECT(dev
), "isa-ipmi-bt")) {
456 pnv_dt_ipmi_bt(d
, args
->fdt
, args
->offset
);
458 error_report("unknown isa device %s@i%x", qdev_fw_name(dev
),
466 * The default LPC bus of a multichip system is on chip 0. It's
467 * recognized by the firmware (skiboot) using a "primary" property.
469 static void pnv_dt_isa(PnvMachineState
*pnv
, void *fdt
)
471 int isa_offset
= fdt_path_offset(fdt
, pnv
->chips
[0]->dt_isa_nodename
);
472 ForeachPopulateArgs args
= {
474 .offset
= isa_offset
,
478 _FDT((fdt_setprop(fdt
, isa_offset
, "primary", NULL
, 0)));
480 phandle
= qemu_fdt_alloc_phandle(fdt
);
482 _FDT((fdt_setprop_cell(fdt
, isa_offset
, "phandle", phandle
)));
485 * ISA devices are not necessarily parented to the ISA bus so we
486 * can not use object_child_foreach()
488 qbus_walk_children(BUS(pnv
->isa_bus
), pnv_dt_isa_device
, NULL
, NULL
, NULL
,
492 static void pnv_dt_power_mgt(PnvMachineState
*pnv
, void *fdt
)
496 off
= fdt_add_subnode(fdt
, 0, "ibm,opal");
497 off
= fdt_add_subnode(fdt
, off
, "power-mgt");
499 _FDT(fdt_setprop_cell(fdt
, off
, "ibm,enabled-stop-levels", 0xc0000000));
502 static void *pnv_dt_create(MachineState
*machine
)
504 PnvMachineClass
*pmc
= PNV_MACHINE_GET_CLASS(machine
);
505 PnvMachineState
*pnv
= PNV_MACHINE(machine
);
511 fdt
= g_malloc0(FDT_MAX_SIZE
);
512 _FDT((fdt_create_empty_tree(fdt
, FDT_MAX_SIZE
)));
515 _FDT((fdt_add_subnode(fdt
, 0, "qemu")));
518 _FDT((fdt_setprop_cell(fdt
, 0, "#address-cells", 0x2)));
519 _FDT((fdt_setprop_cell(fdt
, 0, "#size-cells", 0x2)));
520 _FDT((fdt_setprop_string(fdt
, 0, "model",
521 "IBM PowerNV (emulated by qemu)")));
522 _FDT((fdt_setprop(fdt
, 0, "compatible", pmc
->compat
, pmc
->compat_size
)));
524 buf
= qemu_uuid_unparse_strdup(&qemu_uuid
);
525 _FDT((fdt_setprop_string(fdt
, 0, "vm,uuid", buf
)));
527 _FDT((fdt_property_string(fdt
, "system-id", buf
)));
531 off
= fdt_add_subnode(fdt
, 0, "chosen");
532 if (machine
->kernel_cmdline
) {
533 _FDT((fdt_setprop_string(fdt
, off
, "bootargs",
534 machine
->kernel_cmdline
)));
537 if (pnv
->initrd_size
) {
538 uint32_t start_prop
= cpu_to_be32(pnv
->initrd_base
);
539 uint32_t end_prop
= cpu_to_be32(pnv
->initrd_base
+ pnv
->initrd_size
);
541 _FDT((fdt_setprop(fdt
, off
, "linux,initrd-start",
542 &start_prop
, sizeof(start_prop
))));
543 _FDT((fdt_setprop(fdt
, off
, "linux,initrd-end",
544 &end_prop
, sizeof(end_prop
))));
547 /* Populate device tree for each chip */
548 for (i
= 0; i
< pnv
->num_chips
; i
++) {
549 PNV_CHIP_GET_CLASS(pnv
->chips
[i
])->dt_populate(pnv
->chips
[i
], fdt
);
552 /* Populate ISA devices on chip 0 */
553 pnv_dt_isa(pnv
, fdt
);
556 pnv_dt_bmc_sensors(pnv
->bmc
, fdt
);
559 /* Create an extra node for power management on machines that support it */
560 if (pmc
->dt_power_mgt
) {
561 pmc
->dt_power_mgt(pnv
, fdt
);
567 static void pnv_powerdown_notify(Notifier
*n
, void *opaque
)
569 PnvMachineState
*pnv
= container_of(n
, PnvMachineState
, powerdown_notifier
);
572 pnv_bmc_powerdown(pnv
->bmc
);
576 static void pnv_reset(MachineState
*machine
)
578 PnvMachineState
*pnv
= PNV_MACHINE(machine
);
582 qemu_devices_reset();
585 * The machine should provide by default an internal BMC simulator.
586 * If not, try to use the BMC device that was provided on the command
589 bmc
= pnv_bmc_find(&error_fatal
);
592 if (!qtest_enabled()) {
593 warn_report("machine has no BMC device. Use '-device "
594 "ipmi-bmc-sim,id=bmc0 -device isa-ipmi-bt,bmc=bmc0,irq=10' "
598 pnv_bmc_set_pnor(bmc
, pnv
->pnor
);
603 fdt
= pnv_dt_create(machine
);
605 /* Pack resulting tree */
606 _FDT((fdt_pack(fdt
)));
608 qemu_fdt_dumpdtb(fdt
, fdt_totalsize(fdt
));
609 cpu_physical_memory_write(PNV_FDT_ADDR
, fdt
, fdt_totalsize(fdt
));
614 static ISABus
*pnv_chip_power8_isa_create(PnvChip
*chip
, Error
**errp
)
616 Pnv8Chip
*chip8
= PNV8_CHIP(chip
);
617 return pnv_lpc_isa_create(&chip8
->lpc
, true, errp
);
620 static ISABus
*pnv_chip_power8nvl_isa_create(PnvChip
*chip
, Error
**errp
)
622 Pnv8Chip
*chip8
= PNV8_CHIP(chip
);
623 return pnv_lpc_isa_create(&chip8
->lpc
, false, errp
);
626 static ISABus
*pnv_chip_power9_isa_create(PnvChip
*chip
, Error
**errp
)
628 Pnv9Chip
*chip9
= PNV9_CHIP(chip
);
629 return pnv_lpc_isa_create(&chip9
->lpc
, false, errp
);
632 static ISABus
*pnv_chip_power10_isa_create(PnvChip
*chip
, Error
**errp
)
634 Pnv10Chip
*chip10
= PNV10_CHIP(chip
);
635 return pnv_lpc_isa_create(&chip10
->lpc
, false, errp
);
638 static ISABus
*pnv_isa_create(PnvChip
*chip
, Error
**errp
)
640 return PNV_CHIP_GET_CLASS(chip
)->isa_create(chip
, errp
);
643 static void pnv_chip_power8_pic_print_info(PnvChip
*chip
, Monitor
*mon
)
645 Pnv8Chip
*chip8
= PNV8_CHIP(chip
);
648 ics_pic_print_info(&chip8
->psi
.ics
, mon
);
649 for (i
= 0; i
< chip
->num_phbs
; i
++) {
650 pnv_phb3_msi_pic_print_info(&chip8
->phbs
[i
].msis
, mon
);
651 ics_pic_print_info(&chip8
->phbs
[i
].lsis
, mon
);
655 static void pnv_chip_power9_pic_print_info(PnvChip
*chip
, Monitor
*mon
)
657 Pnv9Chip
*chip9
= PNV9_CHIP(chip
);
660 pnv_xive_pic_print_info(&chip9
->xive
, mon
);
661 pnv_psi_pic_print_info(&chip9
->psi
, mon
);
663 for (i
= 0; i
< PNV9_CHIP_MAX_PEC
; i
++) {
664 PnvPhb4PecState
*pec
= &chip9
->pecs
[i
];
665 for (j
= 0; j
< pec
->num_stacks
; j
++) {
666 pnv_phb4_pic_print_info(&pec
->stacks
[j
].phb
, mon
);
671 static uint64_t pnv_chip_power8_xscom_core_base(PnvChip
*chip
,
674 return PNV_XSCOM_EX_BASE(core_id
);
677 static uint64_t pnv_chip_power9_xscom_core_base(PnvChip
*chip
,
680 return PNV9_XSCOM_EC_BASE(core_id
);
683 static uint64_t pnv_chip_power10_xscom_core_base(PnvChip
*chip
,
686 return PNV10_XSCOM_EC_BASE(core_id
);
689 static bool pnv_match_cpu(const char *default_type
, const char *cpu_type
)
691 PowerPCCPUClass
*ppc_default
=
692 POWERPC_CPU_CLASS(object_class_by_name(default_type
));
693 PowerPCCPUClass
*ppc
=
694 POWERPC_CPU_CLASS(object_class_by_name(cpu_type
));
696 return ppc_default
->pvr_match(ppc_default
, ppc
->pvr
);
699 static void pnv_ipmi_bt_init(ISABus
*bus
, IPMIBmc
*bmc
, uint32_t irq
)
701 ISADevice
*dev
= isa_new("isa-ipmi-bt");
703 object_property_set_link(OBJECT(dev
), "bmc", OBJECT(bmc
), &error_fatal
);
704 object_property_set_int(OBJECT(dev
), "irq", irq
, &error_fatal
);
705 isa_realize_and_unref(dev
, bus
, &error_fatal
);
708 static void pnv_chip_power10_pic_print_info(PnvChip
*chip
, Monitor
*mon
)
710 Pnv10Chip
*chip10
= PNV10_CHIP(chip
);
712 pnv_psi_pic_print_info(&chip10
->psi
, mon
);
715 static void pnv_init(MachineState
*machine
)
717 const char *bios_name
= machine
->firmware
?: FW_FILE_NAME
;
718 PnvMachineState
*pnv
= PNV_MACHINE(machine
);
719 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
724 DriveInfo
*pnor
= drive_get(IF_MTD
, 0, 0);
728 if (machine
->ram_size
< (1 * GiB
)) {
729 warn_report("skiboot may not work with < 1GB of RAM");
731 memory_region_add_subregion(get_system_memory(), 0, machine
->ram
);
734 * Create our simple PNOR device
736 dev
= qdev_new(TYPE_PNV_PNOR
);
738 qdev_prop_set_drive(dev
, "drive", blk_by_legacy_dinfo(pnor
));
740 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev
), &error_fatal
);
741 pnv
->pnor
= PNV_PNOR(dev
);
743 /* load skiboot firmware */
744 fw_filename
= qemu_find_file(QEMU_FILE_TYPE_BIOS
, bios_name
);
746 error_report("Could not find OPAL firmware '%s'", bios_name
);
750 fw_size
= load_image_targphys(fw_filename
, pnv
->fw_load_addr
, FW_MAX_SIZE
);
752 error_report("Could not load OPAL firmware '%s'", fw_filename
);
758 if (machine
->kernel_filename
) {
761 kernel_size
= load_image_targphys(machine
->kernel_filename
,
762 KERNEL_LOAD_ADDR
, KERNEL_MAX_SIZE
);
763 if (kernel_size
< 0) {
764 error_report("Could not load kernel '%s'",
765 machine
->kernel_filename
);
771 if (machine
->initrd_filename
) {
772 pnv
->initrd_base
= INITRD_LOAD_ADDR
;
773 pnv
->initrd_size
= load_image_targphys(machine
->initrd_filename
,
774 pnv
->initrd_base
, INITRD_MAX_SIZE
);
775 if (pnv
->initrd_size
< 0) {
776 error_report("Could not load initial ram disk '%s'",
777 machine
->initrd_filename
);
782 /* MSIs are supported on this platform */
783 msi_nonbroken
= true;
786 * Check compatibility of the specified CPU with the machine
789 if (!pnv_match_cpu(mc
->default_cpu_type
, machine
->cpu_type
)) {
790 error_report("invalid CPU model '%s' for %s machine",
791 machine
->cpu_type
, mc
->name
);
795 /* Create the processor chips */
796 i
= strlen(machine
->cpu_type
) - strlen(POWERPC_CPU_TYPE_SUFFIX
);
797 chip_typename
= g_strdup_printf(PNV_CHIP_TYPE_NAME("%.*s"),
798 i
, machine
->cpu_type
);
799 if (!object_class_by_name(chip_typename
)) {
800 error_report("invalid chip model '%.*s' for %s machine",
801 i
, machine
->cpu_type
, mc
->name
);
806 machine
->smp
.max_cpus
/ (machine
->smp
.cores
* machine
->smp
.threads
);
808 * TODO: should we decide on how many chips we can create based
809 * on #cores and Venice vs. Murano vs. Naples chip type etc...,
811 if (!is_power_of_2(pnv
->num_chips
) || pnv
->num_chips
> 4) {
812 error_report("invalid number of chips: '%d'", pnv
->num_chips
);
813 error_printf("Try '-smp sockets=N'. Valid values are : 1, 2 or 4.\n");
817 pnv
->chips
= g_new0(PnvChip
*, pnv
->num_chips
);
818 for (i
= 0; i
< pnv
->num_chips
; i
++) {
820 Object
*chip
= OBJECT(qdev_new(chip_typename
));
822 pnv
->chips
[i
] = PNV_CHIP(chip
);
825 * TODO: put all the memory in one node on chip 0 until we find a
826 * way to specify different ranges for each chip
829 object_property_set_int(chip
, "ram-size", machine
->ram_size
,
833 snprintf(chip_name
, sizeof(chip_name
), "chip[%d]", PNV_CHIP_HWID(i
));
834 object_property_add_child(OBJECT(pnv
), chip_name
, chip
);
835 object_property_set_int(chip
, "chip-id", PNV_CHIP_HWID(i
),
837 object_property_set_int(chip
, "nr-cores", machine
->smp
.cores
,
839 object_property_set_int(chip
, "nr-threads", machine
->smp
.threads
,
842 * The POWER8 machine use the XICS interrupt interface.
843 * Propagate the XICS fabric to the chip and its controllers.
845 if (object_dynamic_cast(OBJECT(pnv
), TYPE_XICS_FABRIC
)) {
846 object_property_set_link(chip
, "xics", OBJECT(pnv
), &error_abort
);
848 if (object_dynamic_cast(OBJECT(pnv
), TYPE_XIVE_FABRIC
)) {
849 object_property_set_link(chip
, "xive-fabric", OBJECT(pnv
),
852 sysbus_realize_and_unref(SYS_BUS_DEVICE(chip
), &error_fatal
);
854 g_free(chip_typename
);
856 /* Instantiate ISA bus on chip 0 */
857 pnv
->isa_bus
= pnv_isa_create(pnv
->chips
[0], &error_fatal
);
859 /* Create serial port */
860 serial_hds_isa_init(pnv
->isa_bus
, 0, MAX_ISA_SERIAL_PORTS
);
862 /* Create an RTC ISA device too */
863 mc146818_rtc_init(pnv
->isa_bus
, 2000, NULL
);
866 * Create the machine BMC simulator and the IPMI BT device for
867 * communication with the BMC
869 if (defaults_enabled()) {
870 pnv
->bmc
= pnv_bmc_create(pnv
->pnor
);
871 pnv_ipmi_bt_init(pnv
->isa_bus
, pnv
->bmc
, 10);
875 * The PNOR is mapped on the LPC FW address space by the BMC.
876 * Since we can not reach the remote BMC machine with LPC memops,
877 * map it always for now.
879 memory_region_add_subregion(pnv
->chips
[0]->fw_mr
, PNOR_SPI_OFFSET
,
883 * OpenPOWER systems use a IPMI SEL Event message to notify the
886 pnv
->powerdown_notifier
.notify
= pnv_powerdown_notify
;
887 qemu_register_powerdown_notifier(&pnv
->powerdown_notifier
);
891 * 0:21 Reserved - Read as zeros
896 static uint32_t pnv_chip_core_pir_p8(PnvChip
*chip
, uint32_t core_id
)
898 return (chip
->chip_id
<< 7) | (core_id
<< 3);
901 static void pnv_chip_power8_intc_create(PnvChip
*chip
, PowerPCCPU
*cpu
,
904 Pnv8Chip
*chip8
= PNV8_CHIP(chip
);
905 Error
*local_err
= NULL
;
907 PnvCPUState
*pnv_cpu
= pnv_cpu_state(cpu
);
909 obj
= icp_create(OBJECT(cpu
), TYPE_PNV_ICP
, chip8
->xics
, &local_err
);
911 error_propagate(errp
, local_err
);
919 static void pnv_chip_power8_intc_reset(PnvChip
*chip
, PowerPCCPU
*cpu
)
921 PnvCPUState
*pnv_cpu
= pnv_cpu_state(cpu
);
923 icp_reset(ICP(pnv_cpu
->intc
));
926 static void pnv_chip_power8_intc_destroy(PnvChip
*chip
, PowerPCCPU
*cpu
)
928 PnvCPUState
*pnv_cpu
= pnv_cpu_state(cpu
);
930 icp_destroy(ICP(pnv_cpu
->intc
));
931 pnv_cpu
->intc
= NULL
;
934 static void pnv_chip_power8_intc_print_info(PnvChip
*chip
, PowerPCCPU
*cpu
,
937 icp_pic_print_info(ICP(pnv_cpu_state(cpu
)->intc
), mon
);
941 * 0:48 Reserved - Read as zeroes
944 * 56 Reserved - Read as zero
948 * We only care about the lower bits. uint32_t is fine for the moment.
950 static uint32_t pnv_chip_core_pir_p9(PnvChip
*chip
, uint32_t core_id
)
952 return (chip
->chip_id
<< 8) | (core_id
<< 2);
955 static uint32_t pnv_chip_core_pir_p10(PnvChip
*chip
, uint32_t core_id
)
957 return (chip
->chip_id
<< 8) | (core_id
<< 2);
960 static void pnv_chip_power9_intc_create(PnvChip
*chip
, PowerPCCPU
*cpu
,
963 Pnv9Chip
*chip9
= PNV9_CHIP(chip
);
964 Error
*local_err
= NULL
;
966 PnvCPUState
*pnv_cpu
= pnv_cpu_state(cpu
);
969 * The core creates its interrupt presenter but the XIVE interrupt
970 * controller object is initialized afterwards. Hopefully, it's
971 * only used at runtime.
973 obj
= xive_tctx_create(OBJECT(cpu
), XIVE_PRESENTER(&chip9
->xive
),
976 error_propagate(errp
, local_err
);
983 static void pnv_chip_power9_intc_reset(PnvChip
*chip
, PowerPCCPU
*cpu
)
985 PnvCPUState
*pnv_cpu
= pnv_cpu_state(cpu
);
987 xive_tctx_reset(XIVE_TCTX(pnv_cpu
->intc
));
990 static void pnv_chip_power9_intc_destroy(PnvChip
*chip
, PowerPCCPU
*cpu
)
992 PnvCPUState
*pnv_cpu
= pnv_cpu_state(cpu
);
994 xive_tctx_destroy(XIVE_TCTX(pnv_cpu
->intc
));
995 pnv_cpu
->intc
= NULL
;
998 static void pnv_chip_power9_intc_print_info(PnvChip
*chip
, PowerPCCPU
*cpu
,
1001 xive_tctx_pic_print_info(XIVE_TCTX(pnv_cpu_state(cpu
)->intc
), mon
);
1004 static void pnv_chip_power10_intc_create(PnvChip
*chip
, PowerPCCPU
*cpu
,
1007 PnvCPUState
*pnv_cpu
= pnv_cpu_state(cpu
);
1009 /* Will be defined when the interrupt controller is */
1010 pnv_cpu
->intc
= NULL
;
1013 static void pnv_chip_power10_intc_reset(PnvChip
*chip
, PowerPCCPU
*cpu
)
1018 static void pnv_chip_power10_intc_destroy(PnvChip
*chip
, PowerPCCPU
*cpu
)
1020 PnvCPUState
*pnv_cpu
= pnv_cpu_state(cpu
);
1022 pnv_cpu
->intc
= NULL
;
1025 static void pnv_chip_power10_intc_print_info(PnvChip
*chip
, PowerPCCPU
*cpu
,
1031 * Allowed core identifiers on a POWER8 Processor Chip :
1040 * <EX7,8 reserved> <reserved>
1042 * EX10 - Venice only
1043 * EX11 - Venice only
1049 #define POWER8E_CORE_MASK (0x7070ull)
1050 #define POWER8_CORE_MASK (0x7e7eull)
1053 * POWER9 has 24 cores, ids starting at 0x0
1055 #define POWER9_CORE_MASK (0xffffffffffffffull)
1058 #define POWER10_CORE_MASK (0xffffffffffffffull)
1060 static void pnv_chip_power8_instance_init(Object
*obj
)
1062 PnvChip
*chip
= PNV_CHIP(obj
);
1063 Pnv8Chip
*chip8
= PNV8_CHIP(obj
);
1064 PnvChipClass
*pcc
= PNV_CHIP_GET_CLASS(obj
);
1067 object_property_add_link(obj
, "xics", TYPE_XICS_FABRIC
,
1068 (Object
**)&chip8
->xics
,
1069 object_property_allow_set_link
,
1070 OBJ_PROP_LINK_STRONG
);
1072 object_initialize_child(obj
, "psi", &chip8
->psi
, TYPE_PNV8_PSI
);
1074 object_initialize_child(obj
, "lpc", &chip8
->lpc
, TYPE_PNV8_LPC
);
1076 object_initialize_child(obj
, "occ", &chip8
->occ
, TYPE_PNV8_OCC
);
1078 object_initialize_child(obj
, "homer", &chip8
->homer
, TYPE_PNV8_HOMER
);
1080 for (i
= 0; i
< pcc
->num_phbs
; i
++) {
1081 object_initialize_child(obj
, "phb[*]", &chip8
->phbs
[i
], TYPE_PNV_PHB3
);
1085 * Number of PHBs is the chip default
1087 chip
->num_phbs
= pcc
->num_phbs
;
1090 static void pnv_chip_icp_realize(Pnv8Chip
*chip8
, Error
**errp
)
1092 PnvChip
*chip
= PNV_CHIP(chip8
);
1093 PnvChipClass
*pcc
= PNV_CHIP_GET_CLASS(chip
);
1097 name
= g_strdup_printf("icp-%x", chip
->chip_id
);
1098 memory_region_init(&chip8
->icp_mmio
, OBJECT(chip
), name
, PNV_ICP_SIZE
);
1099 sysbus_init_mmio(SYS_BUS_DEVICE(chip
), &chip8
->icp_mmio
);
1102 sysbus_mmio_map(SYS_BUS_DEVICE(chip
), 1, PNV_ICP_BASE(chip
));
1104 /* Map the ICP registers for each thread */
1105 for (i
= 0; i
< chip
->nr_cores
; i
++) {
1106 PnvCore
*pnv_core
= chip
->cores
[i
];
1107 int core_hwid
= CPU_CORE(pnv_core
)->core_id
;
1109 for (j
= 0; j
< CPU_CORE(pnv_core
)->nr_threads
; j
++) {
1110 uint32_t pir
= pcc
->core_pir(chip
, core_hwid
) + j
;
1111 PnvICPState
*icp
= PNV_ICP(xics_icp_get(chip8
->xics
, pir
));
1113 memory_region_add_subregion(&chip8
->icp_mmio
, pir
<< 12,
1119 static void pnv_chip_power8_realize(DeviceState
*dev
, Error
**errp
)
1121 PnvChipClass
*pcc
= PNV_CHIP_GET_CLASS(dev
);
1122 PnvChip
*chip
= PNV_CHIP(dev
);
1123 Pnv8Chip
*chip8
= PNV8_CHIP(dev
);
1124 Pnv8Psi
*psi8
= &chip8
->psi
;
1125 Error
*local_err
= NULL
;
1128 assert(chip8
->xics
);
1130 /* XSCOM bridge is first */
1131 pnv_xscom_realize(chip
, PNV_XSCOM_SIZE
, &local_err
);
1133 error_propagate(errp
, local_err
);
1136 sysbus_mmio_map(SYS_BUS_DEVICE(chip
), 0, PNV_XSCOM_BASE(chip
));
1138 pcc
->parent_realize(dev
, &local_err
);
1140 error_propagate(errp
, local_err
);
1144 /* Processor Service Interface (PSI) Host Bridge */
1145 object_property_set_int(OBJECT(&chip8
->psi
), "bar", PNV_PSIHB_BASE(chip
),
1147 object_property_set_link(OBJECT(&chip8
->psi
), ICS_PROP_XICS
,
1148 OBJECT(chip8
->xics
), &error_abort
);
1149 if (!qdev_realize(DEVICE(&chip8
->psi
), NULL
, errp
)) {
1152 pnv_xscom_add_subregion(chip
, PNV_XSCOM_PSIHB_BASE
,
1153 &PNV_PSI(psi8
)->xscom_regs
);
1155 /* Create LPC controller */
1156 object_property_set_link(OBJECT(&chip8
->lpc
), "psi", OBJECT(&chip8
->psi
),
1158 qdev_realize(DEVICE(&chip8
->lpc
), NULL
, &error_fatal
);
1159 pnv_xscom_add_subregion(chip
, PNV_XSCOM_LPC_BASE
, &chip8
->lpc
.xscom_regs
);
1161 chip
->fw_mr
= &chip8
->lpc
.isa_fw
;
1162 chip
->dt_isa_nodename
= g_strdup_printf("/xscom@%" PRIx64
"/isa@%x",
1163 (uint64_t) PNV_XSCOM_BASE(chip
),
1164 PNV_XSCOM_LPC_BASE
);
1167 * Interrupt Management Area. This is the memory region holding
1168 * all the Interrupt Control Presenter (ICP) registers
1170 pnv_chip_icp_realize(chip8
, &local_err
);
1172 error_propagate(errp
, local_err
);
1176 /* Create the simplified OCC model */
1177 object_property_set_link(OBJECT(&chip8
->occ
), "psi", OBJECT(&chip8
->psi
),
1179 if (!qdev_realize(DEVICE(&chip8
->occ
), NULL
, errp
)) {
1182 pnv_xscom_add_subregion(chip
, PNV_XSCOM_OCC_BASE
, &chip8
->occ
.xscom_regs
);
1184 /* OCC SRAM model */
1185 memory_region_add_subregion(get_system_memory(), PNV_OCC_SENSOR_BASE(chip
),
1186 &chip8
->occ
.sram_regs
);
1189 object_property_set_link(OBJECT(&chip8
->homer
), "chip", OBJECT(chip
),
1191 if (!qdev_realize(DEVICE(&chip8
->homer
), NULL
, errp
)) {
1194 /* Homer Xscom region */
1195 pnv_xscom_add_subregion(chip
, PNV_XSCOM_PBA_BASE
, &chip8
->homer
.pba_regs
);
1197 /* Homer mmio region */
1198 memory_region_add_subregion(get_system_memory(), PNV_HOMER_BASE(chip
),
1199 &chip8
->homer
.regs
);
1201 /* PHB3 controllers */
1202 for (i
= 0; i
< chip
->num_phbs
; i
++) {
1203 PnvPHB3
*phb
= &chip8
->phbs
[i
];
1204 PnvPBCQState
*pbcq
= &phb
->pbcq
;
1206 object_property_set_int(OBJECT(phb
), "index", i
, &error_fatal
);
1207 object_property_set_int(OBJECT(phb
), "chip-id", chip
->chip_id
,
1209 if (!sysbus_realize(SYS_BUS_DEVICE(phb
), errp
)) {
1213 /* Populate the XSCOM address space. */
1214 pnv_xscom_add_subregion(chip
,
1215 PNV_XSCOM_PBCQ_NEST_BASE
+ 0x400 * phb
->phb_id
,
1216 &pbcq
->xscom_nest_regs
);
1217 pnv_xscom_add_subregion(chip
,
1218 PNV_XSCOM_PBCQ_PCI_BASE
+ 0x400 * phb
->phb_id
,
1219 &pbcq
->xscom_pci_regs
);
1220 pnv_xscom_add_subregion(chip
,
1221 PNV_XSCOM_PBCQ_SPCI_BASE
+ 0x040 * phb
->phb_id
,
1222 &pbcq
->xscom_spci_regs
);
1226 static uint32_t pnv_chip_power8_xscom_pcba(PnvChip
*chip
, uint64_t addr
)
1228 addr
&= (PNV_XSCOM_SIZE
- 1);
1229 return ((addr
>> 4) & ~0xfull
) | ((addr
>> 3) & 0xf);
1232 static void pnv_chip_power8e_class_init(ObjectClass
*klass
, void *data
)
1234 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1235 PnvChipClass
*k
= PNV_CHIP_CLASS(klass
);
1237 k
->chip_cfam_id
= 0x221ef04980000000ull
; /* P8 Murano DD2.1 */
1238 k
->cores_mask
= POWER8E_CORE_MASK
;
1240 k
->core_pir
= pnv_chip_core_pir_p8
;
1241 k
->intc_create
= pnv_chip_power8_intc_create
;
1242 k
->intc_reset
= pnv_chip_power8_intc_reset
;
1243 k
->intc_destroy
= pnv_chip_power8_intc_destroy
;
1244 k
->intc_print_info
= pnv_chip_power8_intc_print_info
;
1245 k
->isa_create
= pnv_chip_power8_isa_create
;
1246 k
->dt_populate
= pnv_chip_power8_dt_populate
;
1247 k
->pic_print_info
= pnv_chip_power8_pic_print_info
;
1248 k
->xscom_core_base
= pnv_chip_power8_xscom_core_base
;
1249 k
->xscom_pcba
= pnv_chip_power8_xscom_pcba
;
1250 dc
->desc
= "PowerNV Chip POWER8E";
1252 device_class_set_parent_realize(dc
, pnv_chip_power8_realize
,
1253 &k
->parent_realize
);
1256 static void pnv_chip_power8_class_init(ObjectClass
*klass
, void *data
)
1258 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1259 PnvChipClass
*k
= PNV_CHIP_CLASS(klass
);
1261 k
->chip_cfam_id
= 0x220ea04980000000ull
; /* P8 Venice DD2.0 */
1262 k
->cores_mask
= POWER8_CORE_MASK
;
1264 k
->core_pir
= pnv_chip_core_pir_p8
;
1265 k
->intc_create
= pnv_chip_power8_intc_create
;
1266 k
->intc_reset
= pnv_chip_power8_intc_reset
;
1267 k
->intc_destroy
= pnv_chip_power8_intc_destroy
;
1268 k
->intc_print_info
= pnv_chip_power8_intc_print_info
;
1269 k
->isa_create
= pnv_chip_power8_isa_create
;
1270 k
->dt_populate
= pnv_chip_power8_dt_populate
;
1271 k
->pic_print_info
= pnv_chip_power8_pic_print_info
;
1272 k
->xscom_core_base
= pnv_chip_power8_xscom_core_base
;
1273 k
->xscom_pcba
= pnv_chip_power8_xscom_pcba
;
1274 dc
->desc
= "PowerNV Chip POWER8";
1276 device_class_set_parent_realize(dc
, pnv_chip_power8_realize
,
1277 &k
->parent_realize
);
1280 static void pnv_chip_power8nvl_class_init(ObjectClass
*klass
, void *data
)
1282 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1283 PnvChipClass
*k
= PNV_CHIP_CLASS(klass
);
1285 k
->chip_cfam_id
= 0x120d304980000000ull
; /* P8 Naples DD1.0 */
1286 k
->cores_mask
= POWER8_CORE_MASK
;
1288 k
->core_pir
= pnv_chip_core_pir_p8
;
1289 k
->intc_create
= pnv_chip_power8_intc_create
;
1290 k
->intc_reset
= pnv_chip_power8_intc_reset
;
1291 k
->intc_destroy
= pnv_chip_power8_intc_destroy
;
1292 k
->intc_print_info
= pnv_chip_power8_intc_print_info
;
1293 k
->isa_create
= pnv_chip_power8nvl_isa_create
;
1294 k
->dt_populate
= pnv_chip_power8_dt_populate
;
1295 k
->pic_print_info
= pnv_chip_power8_pic_print_info
;
1296 k
->xscom_core_base
= pnv_chip_power8_xscom_core_base
;
1297 k
->xscom_pcba
= pnv_chip_power8_xscom_pcba
;
1298 dc
->desc
= "PowerNV Chip POWER8NVL";
1300 device_class_set_parent_realize(dc
, pnv_chip_power8_realize
,
1301 &k
->parent_realize
);
1304 static void pnv_chip_power9_instance_init(Object
*obj
)
1306 PnvChip
*chip
= PNV_CHIP(obj
);
1307 Pnv9Chip
*chip9
= PNV9_CHIP(obj
);
1308 PnvChipClass
*pcc
= PNV_CHIP_GET_CLASS(obj
);
1311 object_initialize_child(obj
, "xive", &chip9
->xive
, TYPE_PNV_XIVE
);
1312 object_property_add_alias(obj
, "xive-fabric", OBJECT(&chip9
->xive
),
1315 object_initialize_child(obj
, "psi", &chip9
->psi
, TYPE_PNV9_PSI
);
1317 object_initialize_child(obj
, "lpc", &chip9
->lpc
, TYPE_PNV9_LPC
);
1319 object_initialize_child(obj
, "occ", &chip9
->occ
, TYPE_PNV9_OCC
);
1321 object_initialize_child(obj
, "homer", &chip9
->homer
, TYPE_PNV9_HOMER
);
1323 for (i
= 0; i
< PNV9_CHIP_MAX_PEC
; i
++) {
1324 object_initialize_child(obj
, "pec[*]", &chip9
->pecs
[i
],
1329 * Number of PHBs is the chip default
1331 chip
->num_phbs
= pcc
->num_phbs
;
1334 static void pnv_chip_quad_realize(Pnv9Chip
*chip9
, Error
**errp
)
1336 PnvChip
*chip
= PNV_CHIP(chip9
);
1339 chip9
->nr_quads
= DIV_ROUND_UP(chip
->nr_cores
, 4);
1340 chip9
->quads
= g_new0(PnvQuad
, chip9
->nr_quads
);
1342 for (i
= 0; i
< chip9
->nr_quads
; i
++) {
1344 PnvQuad
*eq
= &chip9
->quads
[i
];
1345 PnvCore
*pnv_core
= chip
->cores
[i
* 4];
1346 int core_id
= CPU_CORE(pnv_core
)->core_id
;
1348 snprintf(eq_name
, sizeof(eq_name
), "eq[%d]", core_id
);
1349 object_initialize_child_with_props(OBJECT(chip
), eq_name
, eq
,
1350 sizeof(*eq
), TYPE_PNV_QUAD
,
1351 &error_fatal
, NULL
);
1353 object_property_set_int(OBJECT(eq
), "id", core_id
, &error_fatal
);
1354 qdev_realize(DEVICE(eq
), NULL
, &error_fatal
);
1356 pnv_xscom_add_subregion(chip
, PNV9_XSCOM_EQ_BASE(eq
->id
),
1361 static void pnv_chip_power9_phb_realize(PnvChip
*chip
, Error
**errp
)
1363 Pnv9Chip
*chip9
= PNV9_CHIP(chip
);
1367 for (i
= 0; i
< PNV9_CHIP_MAX_PEC
; i
++) {
1368 PnvPhb4PecState
*pec
= &chip9
->pecs
[i
];
1369 PnvPhb4PecClass
*pecc
= PNV_PHB4_PEC_GET_CLASS(pec
);
1370 uint32_t pec_nest_base
;
1371 uint32_t pec_pci_base
;
1373 object_property_set_int(OBJECT(pec
), "index", i
, &error_fatal
);
1379 object_property_set_int(OBJECT(pec
), "num-stacks", i
+ 1,
1381 object_property_set_int(OBJECT(pec
), "chip-id", chip
->chip_id
,
1383 object_property_set_link(OBJECT(pec
), "system-memory",
1384 OBJECT(get_system_memory()), &error_abort
);
1385 if (!qdev_realize(DEVICE(pec
), NULL
, errp
)) {
1389 pec_nest_base
= pecc
->xscom_nest_base(pec
);
1390 pec_pci_base
= pecc
->xscom_pci_base(pec
);
1392 pnv_xscom_add_subregion(chip
, pec_nest_base
, &pec
->nest_regs_mr
);
1393 pnv_xscom_add_subregion(chip
, pec_pci_base
, &pec
->pci_regs_mr
);
1395 for (j
= 0; j
< pec
->num_stacks
&& phb_id
< chip
->num_phbs
;
1397 PnvPhb4PecStack
*stack
= &pec
->stacks
[j
];
1398 Object
*obj
= OBJECT(&stack
->phb
);
1400 object_property_set_int(obj
, "index", phb_id
, &error_fatal
);
1401 object_property_set_int(obj
, "chip-id", chip
->chip_id
,
1403 object_property_set_int(obj
, "version", PNV_PHB4_VERSION
,
1405 object_property_set_int(obj
, "device-id", PNV_PHB4_DEVICE_ID
,
1407 object_property_set_link(obj
, "stack", OBJECT(stack
),
1409 if (!sysbus_realize(SYS_BUS_DEVICE(obj
), errp
)) {
1413 /* Populate the XSCOM address space. */
1414 pnv_xscom_add_subregion(chip
,
1415 pec_nest_base
+ 0x40 * (stack
->stack_no
+ 1),
1416 &stack
->nest_regs_mr
);
1417 pnv_xscom_add_subregion(chip
,
1418 pec_pci_base
+ 0x40 * (stack
->stack_no
+ 1),
1419 &stack
->pci_regs_mr
);
1420 pnv_xscom_add_subregion(chip
,
1421 pec_pci_base
+ PNV9_XSCOM_PEC_PCI_STK0
+
1422 0x40 * stack
->stack_no
,
1423 &stack
->phb_regs_mr
);
1428 static void pnv_chip_power9_realize(DeviceState
*dev
, Error
**errp
)
1430 PnvChipClass
*pcc
= PNV_CHIP_GET_CLASS(dev
);
1431 Pnv9Chip
*chip9
= PNV9_CHIP(dev
);
1432 PnvChip
*chip
= PNV_CHIP(dev
);
1433 Pnv9Psi
*psi9
= &chip9
->psi
;
1434 Error
*local_err
= NULL
;
1436 /* XSCOM bridge is first */
1437 pnv_xscom_realize(chip
, PNV9_XSCOM_SIZE
, &local_err
);
1439 error_propagate(errp
, local_err
);
1442 sysbus_mmio_map(SYS_BUS_DEVICE(chip
), 0, PNV9_XSCOM_BASE(chip
));
1444 pcc
->parent_realize(dev
, &local_err
);
1446 error_propagate(errp
, local_err
);
1450 pnv_chip_quad_realize(chip9
, &local_err
);
1452 error_propagate(errp
, local_err
);
1456 /* XIVE interrupt controller (POWER9) */
1457 object_property_set_int(OBJECT(&chip9
->xive
), "ic-bar",
1458 PNV9_XIVE_IC_BASE(chip
), &error_fatal
);
1459 object_property_set_int(OBJECT(&chip9
->xive
), "vc-bar",
1460 PNV9_XIVE_VC_BASE(chip
), &error_fatal
);
1461 object_property_set_int(OBJECT(&chip9
->xive
), "pc-bar",
1462 PNV9_XIVE_PC_BASE(chip
), &error_fatal
);
1463 object_property_set_int(OBJECT(&chip9
->xive
), "tm-bar",
1464 PNV9_XIVE_TM_BASE(chip
), &error_fatal
);
1465 object_property_set_link(OBJECT(&chip9
->xive
), "chip", OBJECT(chip
),
1467 if (!sysbus_realize(SYS_BUS_DEVICE(&chip9
->xive
), errp
)) {
1470 pnv_xscom_add_subregion(chip
, PNV9_XSCOM_XIVE_BASE
,
1471 &chip9
->xive
.xscom_regs
);
1473 /* Processor Service Interface (PSI) Host Bridge */
1474 object_property_set_int(OBJECT(&chip9
->psi
), "bar", PNV9_PSIHB_BASE(chip
),
1476 if (!qdev_realize(DEVICE(&chip9
->psi
), NULL
, errp
)) {
1479 pnv_xscom_add_subregion(chip
, PNV9_XSCOM_PSIHB_BASE
,
1480 &PNV_PSI(psi9
)->xscom_regs
);
1483 object_property_set_link(OBJECT(&chip9
->lpc
), "psi", OBJECT(&chip9
->psi
),
1485 if (!qdev_realize(DEVICE(&chip9
->lpc
), NULL
, errp
)) {
1488 memory_region_add_subregion(get_system_memory(), PNV9_LPCM_BASE(chip
),
1489 &chip9
->lpc
.xscom_regs
);
1491 chip
->fw_mr
= &chip9
->lpc
.isa_fw
;
1492 chip
->dt_isa_nodename
= g_strdup_printf("/lpcm-opb@%" PRIx64
"/lpc@0",
1493 (uint64_t) PNV9_LPCM_BASE(chip
));
1495 /* Create the simplified OCC model */
1496 object_property_set_link(OBJECT(&chip9
->occ
), "psi", OBJECT(&chip9
->psi
),
1498 if (!qdev_realize(DEVICE(&chip9
->occ
), NULL
, errp
)) {
1501 pnv_xscom_add_subregion(chip
, PNV9_XSCOM_OCC_BASE
, &chip9
->occ
.xscom_regs
);
1503 /* OCC SRAM model */
1504 memory_region_add_subregion(get_system_memory(), PNV9_OCC_SENSOR_BASE(chip
),
1505 &chip9
->occ
.sram_regs
);
1508 object_property_set_link(OBJECT(&chip9
->homer
), "chip", OBJECT(chip
),
1510 if (!qdev_realize(DEVICE(&chip9
->homer
), NULL
, errp
)) {
1513 /* Homer Xscom region */
1514 pnv_xscom_add_subregion(chip
, PNV9_XSCOM_PBA_BASE
, &chip9
->homer
.pba_regs
);
1516 /* Homer mmio region */
1517 memory_region_add_subregion(get_system_memory(), PNV9_HOMER_BASE(chip
),
1518 &chip9
->homer
.regs
);
1521 pnv_chip_power9_phb_realize(chip
, &local_err
);
1523 error_propagate(errp
, local_err
);
1528 static uint32_t pnv_chip_power9_xscom_pcba(PnvChip
*chip
, uint64_t addr
)
1530 addr
&= (PNV9_XSCOM_SIZE
- 1);
1534 static void pnv_chip_power9_class_init(ObjectClass
*klass
, void *data
)
1536 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1537 PnvChipClass
*k
= PNV_CHIP_CLASS(klass
);
1539 k
->chip_cfam_id
= 0x220d104900008000ull
; /* P9 Nimbus DD2.0 */
1540 k
->cores_mask
= POWER9_CORE_MASK
;
1541 k
->core_pir
= pnv_chip_core_pir_p9
;
1542 k
->intc_create
= pnv_chip_power9_intc_create
;
1543 k
->intc_reset
= pnv_chip_power9_intc_reset
;
1544 k
->intc_destroy
= pnv_chip_power9_intc_destroy
;
1545 k
->intc_print_info
= pnv_chip_power9_intc_print_info
;
1546 k
->isa_create
= pnv_chip_power9_isa_create
;
1547 k
->dt_populate
= pnv_chip_power9_dt_populate
;
1548 k
->pic_print_info
= pnv_chip_power9_pic_print_info
;
1549 k
->xscom_core_base
= pnv_chip_power9_xscom_core_base
;
1550 k
->xscom_pcba
= pnv_chip_power9_xscom_pcba
;
1551 dc
->desc
= "PowerNV Chip POWER9";
1554 device_class_set_parent_realize(dc
, pnv_chip_power9_realize
,
1555 &k
->parent_realize
);
1558 static void pnv_chip_power10_instance_init(Object
*obj
)
1560 Pnv10Chip
*chip10
= PNV10_CHIP(obj
);
1562 object_initialize_child(obj
, "psi", &chip10
->psi
, TYPE_PNV10_PSI
);
1563 object_initialize_child(obj
, "lpc", &chip10
->lpc
, TYPE_PNV10_LPC
);
1566 static void pnv_chip_power10_realize(DeviceState
*dev
, Error
**errp
)
1568 PnvChipClass
*pcc
= PNV_CHIP_GET_CLASS(dev
);
1569 PnvChip
*chip
= PNV_CHIP(dev
);
1570 Pnv10Chip
*chip10
= PNV10_CHIP(dev
);
1571 Error
*local_err
= NULL
;
1573 /* XSCOM bridge is first */
1574 pnv_xscom_realize(chip
, PNV10_XSCOM_SIZE
, &local_err
);
1576 error_propagate(errp
, local_err
);
1579 sysbus_mmio_map(SYS_BUS_DEVICE(chip
), 0, PNV10_XSCOM_BASE(chip
));
1581 pcc
->parent_realize(dev
, &local_err
);
1583 error_propagate(errp
, local_err
);
1587 /* Processor Service Interface (PSI) Host Bridge */
1588 object_property_set_int(OBJECT(&chip10
->psi
), "bar",
1589 PNV10_PSIHB_BASE(chip
), &error_fatal
);
1590 if (!qdev_realize(DEVICE(&chip10
->psi
), NULL
, errp
)) {
1593 pnv_xscom_add_subregion(chip
, PNV10_XSCOM_PSIHB_BASE
,
1594 &PNV_PSI(&chip10
->psi
)->xscom_regs
);
1597 object_property_set_link(OBJECT(&chip10
->lpc
), "psi",
1598 OBJECT(&chip10
->psi
), &error_abort
);
1599 if (!qdev_realize(DEVICE(&chip10
->lpc
), NULL
, errp
)) {
1602 memory_region_add_subregion(get_system_memory(), PNV10_LPCM_BASE(chip
),
1603 &chip10
->lpc
.xscom_regs
);
1605 chip
->fw_mr
= &chip10
->lpc
.isa_fw
;
1606 chip
->dt_isa_nodename
= g_strdup_printf("/lpcm-opb@%" PRIx64
"/lpc@0",
1607 (uint64_t) PNV10_LPCM_BASE(chip
));
1610 static uint32_t pnv_chip_power10_xscom_pcba(PnvChip
*chip
, uint64_t addr
)
1612 addr
&= (PNV10_XSCOM_SIZE
- 1);
1616 static void pnv_chip_power10_class_init(ObjectClass
*klass
, void *data
)
1618 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1619 PnvChipClass
*k
= PNV_CHIP_CLASS(klass
);
1621 k
->chip_cfam_id
= 0x120da04900008000ull
; /* P10 DD1.0 (with NX) */
1622 k
->cores_mask
= POWER10_CORE_MASK
;
1623 k
->core_pir
= pnv_chip_core_pir_p10
;
1624 k
->intc_create
= pnv_chip_power10_intc_create
;
1625 k
->intc_reset
= pnv_chip_power10_intc_reset
;
1626 k
->intc_destroy
= pnv_chip_power10_intc_destroy
;
1627 k
->intc_print_info
= pnv_chip_power10_intc_print_info
;
1628 k
->isa_create
= pnv_chip_power10_isa_create
;
1629 k
->dt_populate
= pnv_chip_power10_dt_populate
;
1630 k
->pic_print_info
= pnv_chip_power10_pic_print_info
;
1631 k
->xscom_core_base
= pnv_chip_power10_xscom_core_base
;
1632 k
->xscom_pcba
= pnv_chip_power10_xscom_pcba
;
1633 dc
->desc
= "PowerNV Chip POWER10";
1635 device_class_set_parent_realize(dc
, pnv_chip_power10_realize
,
1636 &k
->parent_realize
);
1639 static void pnv_chip_core_sanitize(PnvChip
*chip
, Error
**errp
)
1641 PnvChipClass
*pcc
= PNV_CHIP_GET_CLASS(chip
);
1645 * No custom mask for this chip, let's use the default one from *
1648 if (!chip
->cores_mask
) {
1649 chip
->cores_mask
= pcc
->cores_mask
;
1652 /* filter alien core ids ! some are reserved */
1653 if ((chip
->cores_mask
& pcc
->cores_mask
) != chip
->cores_mask
) {
1654 error_setg(errp
, "warning: invalid core mask for chip Ox%"PRIx64
" !",
1658 chip
->cores_mask
&= pcc
->cores_mask
;
1660 /* now that we have a sane layout, let check the number of cores */
1661 cores_max
= ctpop64(chip
->cores_mask
);
1662 if (chip
->nr_cores
> cores_max
) {
1663 error_setg(errp
, "warning: too many cores for chip ! Limit is %d",
1669 static void pnv_chip_core_realize(PnvChip
*chip
, Error
**errp
)
1671 Error
*error
= NULL
;
1672 PnvChipClass
*pcc
= PNV_CHIP_GET_CLASS(chip
);
1673 const char *typename
= pnv_chip_core_typename(chip
);
1675 PnvMachineState
*pnv
= PNV_MACHINE(qdev_get_machine());
1677 if (!object_class_by_name(typename
)) {
1678 error_setg(errp
, "Unable to find PowerNV CPU Core '%s'", typename
);
1683 pnv_chip_core_sanitize(chip
, &error
);
1685 error_propagate(errp
, error
);
1689 chip
->cores
= g_new0(PnvCore
*, chip
->nr_cores
);
1691 for (i
= 0, core_hwid
= 0; (core_hwid
< sizeof(chip
->cores_mask
) * 8)
1692 && (i
< chip
->nr_cores
); core_hwid
++) {
1695 uint64_t xscom_core_base
;
1697 if (!(chip
->cores_mask
& (1ull << core_hwid
))) {
1701 pnv_core
= PNV_CORE(object_new(typename
));
1703 snprintf(core_name
, sizeof(core_name
), "core[%d]", core_hwid
);
1704 object_property_add_child(OBJECT(chip
), core_name
, OBJECT(pnv_core
));
1705 chip
->cores
[i
] = pnv_core
;
1706 object_property_set_int(OBJECT(pnv_core
), "nr-threads",
1707 chip
->nr_threads
, &error_fatal
);
1708 object_property_set_int(OBJECT(pnv_core
), CPU_CORE_PROP_CORE_ID
,
1709 core_hwid
, &error_fatal
);
1710 object_property_set_int(OBJECT(pnv_core
), "pir",
1711 pcc
->core_pir(chip
, core_hwid
), &error_fatal
);
1712 object_property_set_int(OBJECT(pnv_core
), "hrmor", pnv
->fw_load_addr
,
1714 object_property_set_link(OBJECT(pnv_core
), "chip", OBJECT(chip
),
1716 qdev_realize(DEVICE(pnv_core
), NULL
, &error_fatal
);
1718 /* Each core has an XSCOM MMIO region */
1719 xscom_core_base
= pcc
->xscom_core_base(chip
, core_hwid
);
1721 pnv_xscom_add_subregion(chip
, xscom_core_base
,
1722 &pnv_core
->xscom_regs
);
1727 static void pnv_chip_realize(DeviceState
*dev
, Error
**errp
)
1729 PnvChip
*chip
= PNV_CHIP(dev
);
1730 Error
*error
= NULL
;
1733 pnv_chip_core_realize(chip
, &error
);
1735 error_propagate(errp
, error
);
1740 static Property pnv_chip_properties
[] = {
1741 DEFINE_PROP_UINT32("chip-id", PnvChip
, chip_id
, 0),
1742 DEFINE_PROP_UINT64("ram-start", PnvChip
, ram_start
, 0),
1743 DEFINE_PROP_UINT64("ram-size", PnvChip
, ram_size
, 0),
1744 DEFINE_PROP_UINT32("nr-cores", PnvChip
, nr_cores
, 1),
1745 DEFINE_PROP_UINT64("cores-mask", PnvChip
, cores_mask
, 0x0),
1746 DEFINE_PROP_UINT32("nr-threads", PnvChip
, nr_threads
, 1),
1747 DEFINE_PROP_UINT32("num-phbs", PnvChip
, num_phbs
, 0),
1748 DEFINE_PROP_END_OF_LIST(),
1751 static void pnv_chip_class_init(ObjectClass
*klass
, void *data
)
1753 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1755 set_bit(DEVICE_CATEGORY_CPU
, dc
->categories
);
1756 dc
->realize
= pnv_chip_realize
;
1757 device_class_set_props(dc
, pnv_chip_properties
);
1758 dc
->desc
= "PowerNV Chip";
1761 PowerPCCPU
*pnv_chip_find_cpu(PnvChip
*chip
, uint32_t pir
)
1765 for (i
= 0; i
< chip
->nr_cores
; i
++) {
1766 PnvCore
*pc
= chip
->cores
[i
];
1767 CPUCore
*cc
= CPU_CORE(pc
);
1769 for (j
= 0; j
< cc
->nr_threads
; j
++) {
1770 if (ppc_cpu_pir(pc
->threads
[j
]) == pir
) {
1771 return pc
->threads
[j
];
1778 static ICSState
*pnv_ics_get(XICSFabric
*xi
, int irq
)
1780 PnvMachineState
*pnv
= PNV_MACHINE(xi
);
1783 for (i
= 0; i
< pnv
->num_chips
; i
++) {
1784 PnvChip
*chip
= pnv
->chips
[i
];
1785 Pnv8Chip
*chip8
= PNV8_CHIP(pnv
->chips
[i
]);
1787 if (ics_valid_irq(&chip8
->psi
.ics
, irq
)) {
1788 return &chip8
->psi
.ics
;
1790 for (j
= 0; j
< chip
->num_phbs
; j
++) {
1791 if (ics_valid_irq(&chip8
->phbs
[j
].lsis
, irq
)) {
1792 return &chip8
->phbs
[j
].lsis
;
1794 if (ics_valid_irq(ICS(&chip8
->phbs
[j
].msis
), irq
)) {
1795 return ICS(&chip8
->phbs
[j
].msis
);
1802 static void pnv_ics_resend(XICSFabric
*xi
)
1804 PnvMachineState
*pnv
= PNV_MACHINE(xi
);
1807 for (i
= 0; i
< pnv
->num_chips
; i
++) {
1808 PnvChip
*chip
= pnv
->chips
[i
];
1809 Pnv8Chip
*chip8
= PNV8_CHIP(pnv
->chips
[i
]);
1811 ics_resend(&chip8
->psi
.ics
);
1812 for (j
= 0; j
< chip
->num_phbs
; j
++) {
1813 ics_resend(&chip8
->phbs
[j
].lsis
);
1814 ics_resend(ICS(&chip8
->phbs
[j
].msis
));
1819 static ICPState
*pnv_icp_get(XICSFabric
*xi
, int pir
)
1821 PowerPCCPU
*cpu
= ppc_get_vcpu_by_pir(pir
);
1823 return cpu
? ICP(pnv_cpu_state(cpu
)->intc
) : NULL
;
1826 static void pnv_pic_print_info(InterruptStatsProvider
*obj
,
1829 PnvMachineState
*pnv
= PNV_MACHINE(obj
);
1834 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
1836 /* XXX: loop on each chip/core/thread instead of CPU_FOREACH() */
1837 PNV_CHIP_GET_CLASS(pnv
->chips
[0])->intc_print_info(pnv
->chips
[0], cpu
,
1841 for (i
= 0; i
< pnv
->num_chips
; i
++) {
1842 PNV_CHIP_GET_CLASS(pnv
->chips
[i
])->pic_print_info(pnv
->chips
[i
], mon
);
1846 static int pnv_match_nvt(XiveFabric
*xfb
, uint8_t format
,
1847 uint8_t nvt_blk
, uint32_t nvt_idx
,
1848 bool cam_ignore
, uint8_t priority
,
1849 uint32_t logic_serv
,
1850 XiveTCTXMatch
*match
)
1852 PnvMachineState
*pnv
= PNV_MACHINE(xfb
);
1853 int total_count
= 0;
1856 for (i
= 0; i
< pnv
->num_chips
; i
++) {
1857 Pnv9Chip
*chip9
= PNV9_CHIP(pnv
->chips
[i
]);
1858 XivePresenter
*xptr
= XIVE_PRESENTER(&chip9
->xive
);
1859 XivePresenterClass
*xpc
= XIVE_PRESENTER_GET_CLASS(xptr
);
1862 count
= xpc
->match_nvt(xptr
, format
, nvt_blk
, nvt_idx
, cam_ignore
,
1863 priority
, logic_serv
, match
);
1869 total_count
+= count
;
1875 static void pnv_machine_power8_class_init(ObjectClass
*oc
, void *data
)
1877 MachineClass
*mc
= MACHINE_CLASS(oc
);
1878 XICSFabricClass
*xic
= XICS_FABRIC_CLASS(oc
);
1879 PnvMachineClass
*pmc
= PNV_MACHINE_CLASS(oc
);
1880 static const char compat
[] = "qemu,powernv8\0qemu,powernv\0ibm,powernv";
1882 mc
->desc
= "IBM PowerNV (Non-Virtualized) POWER8";
1883 mc
->default_cpu_type
= POWERPC_CPU_TYPE_NAME("power8_v2.0");
1885 xic
->icp_get
= pnv_icp_get
;
1886 xic
->ics_get
= pnv_ics_get
;
1887 xic
->ics_resend
= pnv_ics_resend
;
1889 pmc
->compat
= compat
;
1890 pmc
->compat_size
= sizeof(compat
);
1893 static void pnv_machine_power9_class_init(ObjectClass
*oc
, void *data
)
1895 MachineClass
*mc
= MACHINE_CLASS(oc
);
1896 XiveFabricClass
*xfc
= XIVE_FABRIC_CLASS(oc
);
1897 PnvMachineClass
*pmc
= PNV_MACHINE_CLASS(oc
);
1898 static const char compat
[] = "qemu,powernv9\0ibm,powernv";
1900 mc
->desc
= "IBM PowerNV (Non-Virtualized) POWER9";
1901 mc
->default_cpu_type
= POWERPC_CPU_TYPE_NAME("power9_v2.0");
1902 xfc
->match_nvt
= pnv_match_nvt
;
1904 mc
->alias
= "powernv";
1906 pmc
->compat
= compat
;
1907 pmc
->compat_size
= sizeof(compat
);
1908 pmc
->dt_power_mgt
= pnv_dt_power_mgt
;
1911 static void pnv_machine_power10_class_init(ObjectClass
*oc
, void *data
)
1913 MachineClass
*mc
= MACHINE_CLASS(oc
);
1914 PnvMachineClass
*pmc
= PNV_MACHINE_CLASS(oc
);
1915 static const char compat
[] = "qemu,powernv10\0ibm,powernv";
1917 mc
->desc
= "IBM PowerNV (Non-Virtualized) POWER10";
1918 mc
->default_cpu_type
= POWERPC_CPU_TYPE_NAME("power10_v1.0");
1920 pmc
->compat
= compat
;
1921 pmc
->compat_size
= sizeof(compat
);
1922 pmc
->dt_power_mgt
= pnv_dt_power_mgt
;
1925 static bool pnv_machine_get_hb(Object
*obj
, Error
**errp
)
1927 PnvMachineState
*pnv
= PNV_MACHINE(obj
);
1929 return !!pnv
->fw_load_addr
;
1932 static void pnv_machine_set_hb(Object
*obj
, bool value
, Error
**errp
)
1934 PnvMachineState
*pnv
= PNV_MACHINE(obj
);
1937 pnv
->fw_load_addr
= 0x8000000;
1941 static void pnv_cpu_do_nmi_on_cpu(CPUState
*cs
, run_on_cpu_data arg
)
1943 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
1944 CPUPPCState
*env
= &cpu
->env
;
1946 cpu_synchronize_state(cs
);
1947 ppc_cpu_do_system_reset(cs
);
1948 if (env
->spr
[SPR_SRR1
] & SRR1_WAKESTATE
) {
1950 * Power-save wakeups, as indicated by non-zero SRR1[46:47] put the
1951 * wakeup reason in SRR1[42:45], system reset is indicated with 0b0100
1954 if (!(env
->spr
[SPR_SRR1
] & SRR1_WAKERESET
)) {
1955 warn_report("ppc_cpu_do_system_reset does not set system reset wakeup reason");
1956 env
->spr
[SPR_SRR1
] |= SRR1_WAKERESET
;
1960 * For non-powersave system resets, SRR1[42:45] are defined to be
1961 * implementation-dependent. The POWER9 User Manual specifies that
1962 * an external (SCOM driven, which may come from a BMC nmi command or
1963 * another CPU requesting a NMI IPI) system reset exception should be
1964 * 0b0010 (PPC_BIT(44)).
1966 env
->spr
[SPR_SRR1
] |= SRR1_WAKESCOM
;
1970 static void pnv_nmi(NMIState
*n
, int cpu_index
, Error
**errp
)
1975 async_run_on_cpu(cs
, pnv_cpu_do_nmi_on_cpu
, RUN_ON_CPU_NULL
);
1979 static void pnv_machine_class_init(ObjectClass
*oc
, void *data
)
1981 MachineClass
*mc
= MACHINE_CLASS(oc
);
1982 InterruptStatsProviderClass
*ispc
= INTERRUPT_STATS_PROVIDER_CLASS(oc
);
1983 NMIClass
*nc
= NMI_CLASS(oc
);
1985 mc
->desc
= "IBM PowerNV (Non-Virtualized)";
1986 mc
->init
= pnv_init
;
1987 mc
->reset
= pnv_reset
;
1988 mc
->max_cpus
= MAX_CPUS
;
1989 /* Pnv provides a AHCI device for storage */
1990 mc
->block_default_type
= IF_IDE
;
1991 mc
->no_parallel
= 1;
1992 mc
->default_boot_order
= NULL
;
1994 * RAM defaults to less than 2048 for 32-bit hosts, and large
1995 * enough to fit the maximum initrd size at it's load address
1997 mc
->default_ram_size
= INITRD_LOAD_ADDR
+ INITRD_MAX_SIZE
;
1998 mc
->default_ram_id
= "pnv.ram";
1999 ispc
->print_info
= pnv_pic_print_info
;
2000 nc
->nmi_monitor_handler
= pnv_nmi
;
2002 object_class_property_add_bool(oc
, "hb-mode",
2003 pnv_machine_get_hb
, pnv_machine_set_hb
);
2004 object_class_property_set_description(oc
, "hb-mode",
2005 "Use a hostboot like boot loader");
2008 #define DEFINE_PNV8_CHIP_TYPE(type, class_initfn) \
2011 .class_init = class_initfn, \
2012 .parent = TYPE_PNV8_CHIP, \
2015 #define DEFINE_PNV9_CHIP_TYPE(type, class_initfn) \
2018 .class_init = class_initfn, \
2019 .parent = TYPE_PNV9_CHIP, \
2022 #define DEFINE_PNV10_CHIP_TYPE(type, class_initfn) \
2025 .class_init = class_initfn, \
2026 .parent = TYPE_PNV10_CHIP, \
2029 static const TypeInfo types
[] = {
2031 .name
= MACHINE_TYPE_NAME("powernv10"),
2032 .parent
= TYPE_PNV_MACHINE
,
2033 .class_init
= pnv_machine_power10_class_init
,
2036 .name
= MACHINE_TYPE_NAME("powernv9"),
2037 .parent
= TYPE_PNV_MACHINE
,
2038 .class_init
= pnv_machine_power9_class_init
,
2039 .interfaces
= (InterfaceInfo
[]) {
2040 { TYPE_XIVE_FABRIC
},
2045 .name
= MACHINE_TYPE_NAME("powernv8"),
2046 .parent
= TYPE_PNV_MACHINE
,
2047 .class_init
= pnv_machine_power8_class_init
,
2048 .interfaces
= (InterfaceInfo
[]) {
2049 { TYPE_XICS_FABRIC
},
2054 .name
= TYPE_PNV_MACHINE
,
2055 .parent
= TYPE_MACHINE
,
2057 .instance_size
= sizeof(PnvMachineState
),
2058 .class_init
= pnv_machine_class_init
,
2059 .class_size
= sizeof(PnvMachineClass
),
2060 .interfaces
= (InterfaceInfo
[]) {
2061 { TYPE_INTERRUPT_STATS_PROVIDER
},
2067 .name
= TYPE_PNV_CHIP
,
2068 .parent
= TYPE_SYS_BUS_DEVICE
,
2069 .class_init
= pnv_chip_class_init
,
2070 .instance_size
= sizeof(PnvChip
),
2071 .class_size
= sizeof(PnvChipClass
),
2076 * P10 chip and variants
2079 .name
= TYPE_PNV10_CHIP
,
2080 .parent
= TYPE_PNV_CHIP
,
2081 .instance_init
= pnv_chip_power10_instance_init
,
2082 .instance_size
= sizeof(Pnv10Chip
),
2084 DEFINE_PNV10_CHIP_TYPE(TYPE_PNV_CHIP_POWER10
, pnv_chip_power10_class_init
),
2087 * P9 chip and variants
2090 .name
= TYPE_PNV9_CHIP
,
2091 .parent
= TYPE_PNV_CHIP
,
2092 .instance_init
= pnv_chip_power9_instance_init
,
2093 .instance_size
= sizeof(Pnv9Chip
),
2095 DEFINE_PNV9_CHIP_TYPE(TYPE_PNV_CHIP_POWER9
, pnv_chip_power9_class_init
),
2098 * P8 chip and variants
2101 .name
= TYPE_PNV8_CHIP
,
2102 .parent
= TYPE_PNV_CHIP
,
2103 .instance_init
= pnv_chip_power8_instance_init
,
2104 .instance_size
= sizeof(Pnv8Chip
),
2106 DEFINE_PNV8_CHIP_TYPE(TYPE_PNV_CHIP_POWER8
, pnv_chip_power8_class_init
),
2107 DEFINE_PNV8_CHIP_TYPE(TYPE_PNV_CHIP_POWER8E
, pnv_chip_power8e_class_init
),
2108 DEFINE_PNV8_CHIP_TYPE(TYPE_PNV_CHIP_POWER8NVL
,
2109 pnv_chip_power8nvl_class_init
),