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/datadir.h"
22 #include "qemu/units.h"
23 #include "qemu/cutils.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"
34 #include "hw/ppc/fdt.h"
35 #include "hw/ppc/ppc.h"
36 #include "hw/ppc/pnv.h"
37 #include "hw/ppc/pnv_core.h"
38 #include "hw/loader.h"
40 #include "qapi/visitor.h"
41 #include "hw/intc/intc.h"
42 #include "hw/ipmi/ipmi.h"
43 #include "target/ppc/mmu-hash64.h"
44 #include "hw/pci/msi.h"
45 #include "hw/pci-host/pnv_phb.h"
46 #include "hw/pci-host/pnv_phb3.h"
47 #include "hw/pci-host/pnv_phb4.h"
49 #include "hw/ppc/xics.h"
50 #include "hw/qdev-properties.h"
51 #include "hw/ppc/pnv_chip.h"
52 #include "hw/ppc/pnv_xscom.h"
53 #include "hw/ppc/pnv_pnor.h"
55 #include "hw/isa/isa.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 int 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 PnvChipClass
*pnv_cc
= PNV_CHIP_GET_CLASS(chip
);
144 g_autofree
uint32_t *servers_prop
= g_new(uint32_t, smt_threads
);
147 uint32_t segs
[] = {cpu_to_be32(28), cpu_to_be32(40),
148 0xffffffff, 0xffffffff};
149 uint32_t tbfreq
= PNV_TIMEBASE_FREQ
;
150 uint32_t cpufreq
= 1000000000;
151 uint32_t page_sizes_prop
[64];
152 size_t page_sizes_prop_size
;
155 int cpus_offset
= get_cpus_node(fdt
);
157 pir
= pnv_cc
->chip_pir(chip
, pc
->hwid
, 0);
159 nodename
= g_strdup_printf("%s@%x", dc
->fw_name
, pir
);
160 offset
= fdt_add_subnode(fdt
, cpus_offset
, nodename
);
164 _FDT((fdt_setprop_cell(fdt
, offset
, "ibm,chip-id", chip
->chip_id
)));
166 _FDT((fdt_setprop_cell(fdt
, offset
, "reg", pir
)));
167 _FDT((fdt_setprop_cell(fdt
, offset
, "ibm,pir", pir
)));
168 _FDT((fdt_setprop_string(fdt
, offset
, "device_type", "cpu")));
170 _FDT((fdt_setprop_cell(fdt
, offset
, "cpu-version", env
->spr
[SPR_PVR
])));
171 _FDT((fdt_setprop_cell(fdt
, offset
, "d-cache-block-size",
172 env
->dcache_line_size
)));
173 _FDT((fdt_setprop_cell(fdt
, offset
, "d-cache-line-size",
174 env
->dcache_line_size
)));
175 _FDT((fdt_setprop_cell(fdt
, offset
, "i-cache-block-size",
176 env
->icache_line_size
)));
177 _FDT((fdt_setprop_cell(fdt
, offset
, "i-cache-line-size",
178 env
->icache_line_size
)));
180 if (pcc
->l1_dcache_size
) {
181 _FDT((fdt_setprop_cell(fdt
, offset
, "d-cache-size",
182 pcc
->l1_dcache_size
)));
184 warn_report("Unknown L1 dcache size for cpu");
186 if (pcc
->l1_icache_size
) {
187 _FDT((fdt_setprop_cell(fdt
, offset
, "i-cache-size",
188 pcc
->l1_icache_size
)));
190 warn_report("Unknown L1 icache size for cpu");
193 _FDT((fdt_setprop_cell(fdt
, offset
, "timebase-frequency", tbfreq
)));
194 _FDT((fdt_setprop_cell(fdt
, offset
, "clock-frequency", cpufreq
)));
195 _FDT((fdt_setprop_cell(fdt
, offset
, "ibm,slb-size",
196 cpu
->hash64_opts
->slb_size
)));
197 _FDT((fdt_setprop_string(fdt
, offset
, "status", "okay")));
198 _FDT((fdt_setprop(fdt
, offset
, "64-bit", NULL
, 0)));
200 if (ppc_has_spr(cpu
, SPR_PURR
)) {
201 _FDT((fdt_setprop(fdt
, offset
, "ibm,purr", NULL
, 0)));
204 if (ppc_hash64_has(cpu
, PPC_HASH64_1TSEG
)) {
205 _FDT((fdt_setprop(fdt
, offset
, "ibm,processor-segment-sizes",
206 segs
, sizeof(segs
))));
210 * Advertise VMX/VSX (vector extensions) if available
211 * 0 / no property == no vector extensions
212 * 1 == VMX / Altivec available
215 if (env
->insns_flags
& PPC_ALTIVEC
) {
216 uint32_t vmx
= (env
->insns_flags2
& PPC2_VSX
) ? 2 : 1;
218 _FDT((fdt_setprop_cell(fdt
, offset
, "ibm,vmx", vmx
)));
222 * Advertise DFP (Decimal Floating Point) if available
223 * 0 / no property == no DFP
226 if (env
->insns_flags2
& PPC2_DFP
) {
227 _FDT((fdt_setprop_cell(fdt
, offset
, "ibm,dfp", 1)));
230 page_sizes_prop_size
= ppc_create_page_sizes_prop(cpu
, page_sizes_prop
,
231 sizeof(page_sizes_prop
));
232 if (page_sizes_prop_size
) {
233 _FDT((fdt_setprop(fdt
, offset
, "ibm,segment-page-sizes",
234 page_sizes_prop
, page_sizes_prop_size
)));
237 /* Build interrupt servers properties */
238 for (i
= 0; i
< smt_threads
; i
++) {
239 servers_prop
[i
] = cpu_to_be32(pnv_cc
->chip_pir(chip
, pc
->hwid
, i
));
241 _FDT((fdt_setprop(fdt
, offset
, "ibm,ppc-interrupt-server#s",
242 servers_prop
, sizeof(*servers_prop
) * smt_threads
)));
247 static void pnv_dt_icp(PnvChip
*chip
, void *fdt
, uint32_t hwid
,
250 PnvChipClass
*pcc
= PNV_CHIP_GET_CLASS(chip
);
251 uint32_t pir
= pcc
->chip_pir(chip
, hwid
, 0);
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 /* We know P8 PIR is linear with thread id */
266 reg
[i
* 2] = cpu_to_be64(addr
| ((pir
+ i
) * 0x1000));
267 reg
[i
* 2 + 1] = cpu_to_be64(0x1000);
270 name
= g_strdup_printf("interrupt-controller@%"PRIX64
, addr
);
271 offset
= fdt_add_subnode(fdt
, 0, name
);
275 _FDT((fdt_setprop(fdt
, offset
, "compatible", compat
, sizeof(compat
))));
276 _FDT((fdt_setprop(fdt
, offset
, "reg", reg
, rsize
)));
277 _FDT((fdt_setprop_string(fdt
, offset
, "device_type",
278 "PowerPC-External-Interrupt-Presentation")));
279 _FDT((fdt_setprop(fdt
, offset
, "interrupt-controller", NULL
, 0)));
280 _FDT((fdt_setprop(fdt
, offset
, "ibm,interrupt-server-ranges",
281 irange
, sizeof(irange
))));
282 _FDT((fdt_setprop_cell(fdt
, offset
, "#interrupt-cells", 1)));
283 _FDT((fdt_setprop_cell(fdt
, offset
, "#address-cells", 0)));
288 * Adds a PnvPHB to the chip on P8.
289 * Implemented here, like for defaults PHBs
291 PnvChip
*pnv_chip_add_phb(PnvChip
*chip
, PnvPHB
*phb
)
293 Pnv8Chip
*chip8
= PNV8_CHIP(chip
);
297 chip8
->phbs
[chip8
->num_phbs
] = phb
;
303 * Same as spapr pa_features_207 except pnv always enables CI largepages bit.
304 * HTM is always enabled because TCG does implement HTM, it's just a
305 * degenerate implementation.
307 static const uint8_t pa_features_207
[] = { 24, 0,
308 0xf6, 0x3f, 0xc7, 0xc0, 0x00, 0xf0,
309 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
310 0x00, 0x00, 0x00, 0x00, 0x80, 0x00,
311 0x80, 0x00, 0x80, 0x00, 0x80, 0x00 };
313 static void pnv_chip_power8_dt_populate(PnvChip
*chip
, void *fdt
)
315 static const char compat
[] = "ibm,power8-xscom\0ibm,xscom";
318 pnv_dt_xscom(chip
, fdt
, 0,
319 cpu_to_be64(PNV_XSCOM_BASE(chip
)),
320 cpu_to_be64(PNV_XSCOM_SIZE
),
321 compat
, sizeof(compat
));
323 for (i
= 0; i
< chip
->nr_cores
; i
++) {
324 PnvCore
*pnv_core
= chip
->cores
[i
];
327 offset
= pnv_dt_core(chip
, pnv_core
, fdt
);
329 _FDT((fdt_setprop(fdt
, offset
, "ibm,pa-features",
330 pa_features_207
, sizeof(pa_features_207
))));
332 /* Interrupt Control Presenters (ICP). One per core. */
333 pnv_dt_icp(chip
, fdt
, pnv_core
->hwid
, CPU_CORE(pnv_core
)->nr_threads
);
336 if (chip
->ram_size
) {
337 pnv_dt_memory(fdt
, chip
->chip_id
, chip
->ram_start
, chip
->ram_size
);
342 * Same as spapr pa_features_300 except pnv always enables CI largepages bit.
344 static const uint8_t pa_features_300
[] = { 66, 0,
345 /* 0: MMU|FPU|SLB|RUN|DABR|NX, 1: CILRG|fri[nzpm]|DABRX|SPRG3|SLB0|PP110 */
346 /* 2: VPM|DS205|PPR|DS202|DS206, 3: LSD|URG, 5: LE|CFAR|EB|LSQ */
347 0xf6, 0x3f, 0xc7, 0xc0, 0x00, 0xf0, /* 0 - 5 */
349 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, /* 6 - 11 */
351 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, /* 12 - 17 */
352 /* 18: Vec. Scalar, 20: Vec. XOR, 22: HTM */
353 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, /* 18 - 23 */
354 /* 24: Ext. Dec, 26: 64 bit ftrs, 28: PM ftrs */
355 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, /* 24 - 29 */
356 /* 32: LE atomic, 34: EBB + ext EBB */
357 0x00, 0x00, 0x80, 0x00, 0xC0, 0x00, /* 30 - 35 */
359 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, /* 36 - 41 */
360 /* 42: PM, 44: PC RA, 46: SC vec'd */
361 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, /* 42 - 47 */
362 /* 48: SIMD, 50: QP BFP, 52: String */
363 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, /* 48 - 53 */
364 /* 54: DecFP, 56: DecI, 58: SHA */
365 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, /* 54 - 59 */
366 /* 60: NM atomic, 62: RNG */
367 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, /* 60 - 65 */
370 static void pnv_chip_power9_dt_populate(PnvChip
*chip
, void *fdt
)
372 static const char compat
[] = "ibm,power9-xscom\0ibm,xscom";
375 pnv_dt_xscom(chip
, fdt
, 0,
376 cpu_to_be64(PNV9_XSCOM_BASE(chip
)),
377 cpu_to_be64(PNV9_XSCOM_SIZE
),
378 compat
, sizeof(compat
));
380 for (i
= 0; i
< chip
->nr_cores
; i
++) {
381 PnvCore
*pnv_core
= chip
->cores
[i
];
384 offset
= pnv_dt_core(chip
, pnv_core
, fdt
);
386 _FDT((fdt_setprop(fdt
, offset
, "ibm,pa-features",
387 pa_features_300
, sizeof(pa_features_300
))));
390 if (chip
->ram_size
) {
391 pnv_dt_memory(fdt
, chip
->chip_id
, chip
->ram_start
, chip
->ram_size
);
394 pnv_dt_lpc(chip
, fdt
, 0, PNV9_LPCM_BASE(chip
), PNV9_LPCM_SIZE
);
398 * Same as spapr pa_features_31 except pnv always enables CI largepages bit,
399 * always disables copy/paste.
401 static const uint8_t pa_features_31
[] = { 74, 0,
402 /* 0: MMU|FPU|SLB|RUN|DABR|NX, 1: CILRG|fri[nzpm]|DABRX|SPRG3|SLB0|PP110 */
403 /* 2: VPM|DS205|PPR|DS202|DS206, 3: LSD|URG, 5: LE|CFAR|EB|LSQ */
404 0xf6, 0x3f, 0xc7, 0xc0, 0x00, 0xf0, /* 0 - 5 */
406 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, /* 6 - 11 */
408 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, /* 12 - 17 */
409 /* 18: Vec. Scalar, 20: Vec. XOR */
410 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, /* 18 - 23 */
411 /* 24: Ext. Dec, 26: 64 bit ftrs, 28: PM ftrs */
412 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, /* 24 - 29 */
413 /* 32: LE atomic, 34: EBB + ext EBB */
414 0x00, 0x00, 0x80, 0x00, 0xC0, 0x00, /* 30 - 35 */
416 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, /* 36 - 41 */
417 /* 42: PM, 44: PC RA, 46: SC vec'd */
418 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, /* 42 - 47 */
419 /* 48: SIMD, 50: QP BFP, 52: String */
420 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, /* 48 - 53 */
421 /* 54: DecFP, 56: DecI, 58: SHA */
422 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, /* 54 - 59 */
423 /* 60: NM atomic, 62: RNG */
424 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, /* 60 - 65 */
425 /* 68: DEXCR[SBHE|IBRTPDUS|SRAPD|NPHIE|PHIE] */
426 0x00, 0x00, 0xce, 0x00, 0x00, 0x00, /* 66 - 71 */
427 /* 72: [P]HASHST/[P]HASHCHK */
428 0x80, 0x00, /* 72 - 73 */
431 static void pnv_chip_power10_dt_populate(PnvChip
*chip
, void *fdt
)
433 static const char compat
[] = "ibm,power10-xscom\0ibm,xscom";
436 pnv_dt_xscom(chip
, fdt
, 0,
437 cpu_to_be64(PNV10_XSCOM_BASE(chip
)),
438 cpu_to_be64(PNV10_XSCOM_SIZE
),
439 compat
, sizeof(compat
));
441 for (i
= 0; i
< chip
->nr_cores
; i
++) {
442 PnvCore
*pnv_core
= chip
->cores
[i
];
445 offset
= pnv_dt_core(chip
, pnv_core
, fdt
);
447 _FDT((fdt_setprop(fdt
, offset
, "ibm,pa-features",
448 pa_features_31
, sizeof(pa_features_31
))));
451 if (chip
->ram_size
) {
452 pnv_dt_memory(fdt
, chip
->chip_id
, chip
->ram_start
, chip
->ram_size
);
455 pnv_dt_lpc(chip
, fdt
, 0, PNV10_LPCM_BASE(chip
), PNV10_LPCM_SIZE
);
458 static void pnv_dt_rtc(ISADevice
*d
, void *fdt
, int lpc_off
)
460 uint32_t io_base
= d
->ioport_id
;
461 uint32_t io_regs
[] = {
463 cpu_to_be32(io_base
),
469 name
= g_strdup_printf("%s@i%x", qdev_fw_name(DEVICE(d
)), io_base
);
470 node
= fdt_add_subnode(fdt
, lpc_off
, name
);
474 _FDT((fdt_setprop(fdt
, node
, "reg", io_regs
, sizeof(io_regs
))));
475 _FDT((fdt_setprop_string(fdt
, node
, "compatible", "pnpPNP,b00")));
478 static void pnv_dt_serial(ISADevice
*d
, void *fdt
, int lpc_off
)
480 const char compatible
[] = "ns16550\0pnpPNP,501";
481 uint32_t io_base
= d
->ioport_id
;
482 uint32_t io_regs
[] = {
484 cpu_to_be32(io_base
),
491 irq
= object_property_get_uint(OBJECT(d
), "irq", &error_fatal
);
493 name
= g_strdup_printf("%s@i%x", qdev_fw_name(DEVICE(d
)), io_base
);
494 node
= fdt_add_subnode(fdt
, lpc_off
, name
);
498 _FDT((fdt_setprop(fdt
, node
, "reg", io_regs
, sizeof(io_regs
))));
499 _FDT((fdt_setprop(fdt
, node
, "compatible", compatible
,
500 sizeof(compatible
))));
502 _FDT((fdt_setprop_cell(fdt
, node
, "clock-frequency", 1843200)));
503 _FDT((fdt_setprop_cell(fdt
, node
, "current-speed", 115200)));
504 _FDT((fdt_setprop_cell(fdt
, node
, "interrupts", irq
)));
505 _FDT((fdt_setprop_cell(fdt
, node
, "interrupt-parent",
506 fdt_get_phandle(fdt
, lpc_off
))));
508 /* This is needed by Linux */
509 _FDT((fdt_setprop_string(fdt
, node
, "device_type", "serial")));
512 static void pnv_dt_ipmi_bt(ISADevice
*d
, void *fdt
, int lpc_off
)
514 const char compatible
[] = "bt\0ipmi-bt";
516 uint32_t io_regs
[] = {
518 0, /* 'io_base' retrieved from the 'ioport' property of 'isa-ipmi-bt' */
525 io_base
= object_property_get_int(OBJECT(d
), "ioport", &error_fatal
);
526 io_regs
[1] = cpu_to_be32(io_base
);
528 irq
= object_property_get_int(OBJECT(d
), "irq", &error_fatal
);
530 name
= g_strdup_printf("%s@i%x", qdev_fw_name(DEVICE(d
)), io_base
);
531 node
= fdt_add_subnode(fdt
, lpc_off
, name
);
535 _FDT((fdt_setprop(fdt
, node
, "reg", io_regs
, sizeof(io_regs
))));
536 _FDT((fdt_setprop(fdt
, node
, "compatible", compatible
,
537 sizeof(compatible
))));
539 /* Mark it as reserved to avoid Linux trying to claim it */
540 _FDT((fdt_setprop_string(fdt
, node
, "status", "reserved")));
541 _FDT((fdt_setprop_cell(fdt
, node
, "interrupts", irq
)));
542 _FDT((fdt_setprop_cell(fdt
, node
, "interrupt-parent",
543 fdt_get_phandle(fdt
, lpc_off
))));
546 typedef struct ForeachPopulateArgs
{
549 } ForeachPopulateArgs
;
551 static int pnv_dt_isa_device(DeviceState
*dev
, void *opaque
)
553 ForeachPopulateArgs
*args
= opaque
;
554 ISADevice
*d
= ISA_DEVICE(dev
);
556 if (object_dynamic_cast(OBJECT(dev
), TYPE_MC146818_RTC
)) {
557 pnv_dt_rtc(d
, args
->fdt
, args
->offset
);
558 } else if (object_dynamic_cast(OBJECT(dev
), TYPE_ISA_SERIAL
)) {
559 pnv_dt_serial(d
, args
->fdt
, args
->offset
);
560 } else if (object_dynamic_cast(OBJECT(dev
), "isa-ipmi-bt")) {
561 pnv_dt_ipmi_bt(d
, args
->fdt
, args
->offset
);
563 error_report("unknown isa device %s@i%x", qdev_fw_name(dev
),
571 * The default LPC bus of a multichip system is on chip 0. It's
572 * recognized by the firmware (skiboot) using a "primary" property.
574 static void pnv_dt_isa(PnvMachineState
*pnv
, void *fdt
)
576 int isa_offset
= fdt_path_offset(fdt
, pnv
->chips
[0]->dt_isa_nodename
);
577 ForeachPopulateArgs args
= {
579 .offset
= isa_offset
,
583 _FDT((fdt_setprop(fdt
, isa_offset
, "primary", NULL
, 0)));
585 phandle
= qemu_fdt_alloc_phandle(fdt
);
587 _FDT((fdt_setprop_cell(fdt
, isa_offset
, "phandle", phandle
)));
590 * ISA devices are not necessarily parented to the ISA bus so we
591 * can not use object_child_foreach()
593 qbus_walk_children(BUS(pnv
->isa_bus
), pnv_dt_isa_device
, NULL
, NULL
, NULL
,
597 static void pnv_dt_power_mgt(PnvMachineState
*pnv
, void *fdt
)
601 off
= fdt_add_subnode(fdt
, 0, "ibm,opal");
602 off
= fdt_add_subnode(fdt
, off
, "power-mgt");
604 _FDT(fdt_setprop_cell(fdt
, off
, "ibm,enabled-stop-levels", 0xc0000000));
607 static void *pnv_dt_create(MachineState
*machine
)
609 PnvMachineClass
*pmc
= PNV_MACHINE_GET_CLASS(machine
);
610 PnvMachineState
*pnv
= PNV_MACHINE(machine
);
616 fdt
= g_malloc0(FDT_MAX_SIZE
);
617 _FDT((fdt_create_empty_tree(fdt
, FDT_MAX_SIZE
)));
620 _FDT((fdt_add_subnode(fdt
, 0, "qemu")));
623 _FDT((fdt_setprop_cell(fdt
, 0, "#address-cells", 0x2)));
624 _FDT((fdt_setprop_cell(fdt
, 0, "#size-cells", 0x2)));
625 _FDT((fdt_setprop_string(fdt
, 0, "model",
626 "IBM PowerNV (emulated by qemu)")));
627 _FDT((fdt_setprop(fdt
, 0, "compatible", pmc
->compat
, pmc
->compat_size
)));
629 buf
= qemu_uuid_unparse_strdup(&qemu_uuid
);
630 _FDT((fdt_setprop_string(fdt
, 0, "vm,uuid", buf
)));
632 _FDT((fdt_setprop_string(fdt
, 0, "system-id", buf
)));
636 off
= fdt_add_subnode(fdt
, 0, "chosen");
637 if (machine
->kernel_cmdline
) {
638 _FDT((fdt_setprop_string(fdt
, off
, "bootargs",
639 machine
->kernel_cmdline
)));
642 if (pnv
->initrd_size
) {
643 uint32_t start_prop
= cpu_to_be32(pnv
->initrd_base
);
644 uint32_t end_prop
= cpu_to_be32(pnv
->initrd_base
+ pnv
->initrd_size
);
646 _FDT((fdt_setprop(fdt
, off
, "linux,initrd-start",
647 &start_prop
, sizeof(start_prop
))));
648 _FDT((fdt_setprop(fdt
, off
, "linux,initrd-end",
649 &end_prop
, sizeof(end_prop
))));
652 /* Populate device tree for each chip */
653 for (i
= 0; i
< pnv
->num_chips
; i
++) {
654 PNV_CHIP_GET_CLASS(pnv
->chips
[i
])->dt_populate(pnv
->chips
[i
], fdt
);
657 /* Populate ISA devices on chip 0 */
658 pnv_dt_isa(pnv
, fdt
);
661 pnv_dt_bmc_sensors(pnv
->bmc
, fdt
);
664 /* Create an extra node for power management on machines that support it */
665 if (pmc
->dt_power_mgt
) {
666 pmc
->dt_power_mgt(pnv
, fdt
);
672 static void pnv_powerdown_notify(Notifier
*n
, void *opaque
)
674 PnvMachineState
*pnv
= container_of(n
, PnvMachineState
, powerdown_notifier
);
677 pnv_bmc_powerdown(pnv
->bmc
);
681 static void pnv_reset(MachineState
*machine
, ShutdownCause reason
)
683 PnvMachineState
*pnv
= PNV_MACHINE(machine
);
687 qemu_devices_reset(reason
);
690 * The machine should provide by default an internal BMC simulator.
691 * If not, try to use the BMC device that was provided on the command
694 bmc
= pnv_bmc_find(&error_fatal
);
697 if (!qtest_enabled()) {
698 warn_report("machine has no BMC device. Use '-device "
699 "ipmi-bmc-sim,id=bmc0 -device isa-ipmi-bt,bmc=bmc0,irq=10' "
703 pnv_bmc_set_pnor(bmc
, pnv
->pnor
);
708 fdt
= pnv_dt_create(machine
);
710 /* Pack resulting tree */
711 _FDT((fdt_pack(fdt
)));
713 qemu_fdt_dumpdtb(fdt
, fdt_totalsize(fdt
));
714 cpu_physical_memory_write(PNV_FDT_ADDR
, fdt
, fdt_totalsize(fdt
));
717 * Set machine->fdt for 'dumpdtb' QMP/HMP command. Free
718 * the existing machine->fdt to avoid leaking it during
721 g_free(machine
->fdt
);
725 static ISABus
*pnv_chip_power8_isa_create(PnvChip
*chip
, Error
**errp
)
727 Pnv8Chip
*chip8
= PNV8_CHIP(chip
);
728 qemu_irq irq
= qdev_get_gpio_in(DEVICE(&chip8
->psi
), PSIHB_IRQ_EXTERNAL
);
730 qdev_connect_gpio_out(DEVICE(&chip8
->lpc
), 0, irq
);
731 return pnv_lpc_isa_create(&chip8
->lpc
, true, errp
);
734 static ISABus
*pnv_chip_power8nvl_isa_create(PnvChip
*chip
, Error
**errp
)
736 Pnv8Chip
*chip8
= PNV8_CHIP(chip
);
737 qemu_irq irq
= qdev_get_gpio_in(DEVICE(&chip8
->psi
), PSIHB_IRQ_LPC_I2C
);
739 qdev_connect_gpio_out(DEVICE(&chip8
->lpc
), 0, irq
);
740 return pnv_lpc_isa_create(&chip8
->lpc
, false, errp
);
743 static ISABus
*pnv_chip_power9_isa_create(PnvChip
*chip
, Error
**errp
)
745 Pnv9Chip
*chip9
= PNV9_CHIP(chip
);
746 qemu_irq irq
= qdev_get_gpio_in(DEVICE(&chip9
->psi
), PSIHB9_IRQ_LPCHC
);
748 qdev_connect_gpio_out(DEVICE(&chip9
->lpc
), 0, irq
);
749 return pnv_lpc_isa_create(&chip9
->lpc
, false, errp
);
752 static ISABus
*pnv_chip_power10_isa_create(PnvChip
*chip
, Error
**errp
)
754 Pnv10Chip
*chip10
= PNV10_CHIP(chip
);
755 qemu_irq irq
= qdev_get_gpio_in(DEVICE(&chip10
->psi
), PSIHB9_IRQ_LPCHC
);
757 qdev_connect_gpio_out(DEVICE(&chip10
->lpc
), 0, irq
);
758 return pnv_lpc_isa_create(&chip10
->lpc
, false, errp
);
761 static ISABus
*pnv_isa_create(PnvChip
*chip
, Error
**errp
)
763 return PNV_CHIP_GET_CLASS(chip
)->isa_create(chip
, errp
);
766 static void pnv_chip_power8_pic_print_info(PnvChip
*chip
, GString
*buf
)
768 Pnv8Chip
*chip8
= PNV8_CHIP(chip
);
771 ics_pic_print_info(&chip8
->psi
.ics
, buf
);
773 for (i
= 0; i
< chip8
->num_phbs
; i
++) {
774 PnvPHB
*phb
= chip8
->phbs
[i
];
775 PnvPHB3
*phb3
= PNV_PHB3(phb
->backend
);
777 pnv_phb3_msi_pic_print_info(&phb3
->msis
, buf
);
778 ics_pic_print_info(&phb3
->lsis
, buf
);
782 static int pnv_chip_power9_pic_print_info_child(Object
*child
, void *opaque
)
784 GString
*buf
= opaque
;
785 PnvPHB
*phb
= (PnvPHB
*) object_dynamic_cast(child
, TYPE_PNV_PHB
);
791 pnv_phb4_pic_print_info(PNV_PHB4(phb
->backend
), buf
);
796 static void pnv_chip_power9_pic_print_info(PnvChip
*chip
, GString
*buf
)
798 Pnv9Chip
*chip9
= PNV9_CHIP(chip
);
800 pnv_xive_pic_print_info(&chip9
->xive
, buf
);
801 pnv_psi_pic_print_info(&chip9
->psi
, buf
);
802 object_child_foreach_recursive(OBJECT(chip
),
803 pnv_chip_power9_pic_print_info_child
, buf
);
806 static uint64_t pnv_chip_power8_xscom_core_base(PnvChip
*chip
,
809 return PNV_XSCOM_EX_BASE(core_id
);
812 static uint64_t pnv_chip_power9_xscom_core_base(PnvChip
*chip
,
815 return PNV9_XSCOM_EC_BASE(core_id
);
818 static uint64_t pnv_chip_power10_xscom_core_base(PnvChip
*chip
,
821 return PNV10_XSCOM_EC_BASE(core_id
);
824 static bool pnv_match_cpu(const char *default_type
, const char *cpu_type
)
826 PowerPCCPUClass
*ppc_default
=
827 POWERPC_CPU_CLASS(object_class_by_name(default_type
));
828 PowerPCCPUClass
*ppc
=
829 POWERPC_CPU_CLASS(object_class_by_name(cpu_type
));
831 return ppc_default
->pvr_match(ppc_default
, ppc
->pvr
, false);
834 static void pnv_ipmi_bt_init(ISABus
*bus
, IPMIBmc
*bmc
, uint32_t irq
)
836 ISADevice
*dev
= isa_new("isa-ipmi-bt");
838 object_property_set_link(OBJECT(dev
), "bmc", OBJECT(bmc
), &error_fatal
);
839 object_property_set_int(OBJECT(dev
), "irq", irq
, &error_fatal
);
840 isa_realize_and_unref(dev
, bus
, &error_fatal
);
843 static void pnv_chip_power10_pic_print_info(PnvChip
*chip
, GString
*buf
)
845 Pnv10Chip
*chip10
= PNV10_CHIP(chip
);
847 pnv_xive2_pic_print_info(&chip10
->xive
, buf
);
848 pnv_psi_pic_print_info(&chip10
->psi
, buf
);
849 object_child_foreach_recursive(OBJECT(chip
),
850 pnv_chip_power9_pic_print_info_child
, buf
);
853 /* Always give the first 1GB to chip 0 else we won't boot */
854 static uint64_t pnv_chip_get_ram_size(PnvMachineState
*pnv
, int chip_id
)
856 MachineState
*machine
= MACHINE(pnv
);
857 uint64_t ram_per_chip
;
859 assert(machine
->ram_size
>= 1 * GiB
);
861 ram_per_chip
= machine
->ram_size
/ pnv
->num_chips
;
862 if (ram_per_chip
>= 1 * GiB
) {
863 return QEMU_ALIGN_DOWN(ram_per_chip
, 1 * MiB
);
866 assert(pnv
->num_chips
> 1);
868 ram_per_chip
= (machine
->ram_size
- 1 * GiB
) / (pnv
->num_chips
- 1);
869 return chip_id
== 0 ? 1 * GiB
: QEMU_ALIGN_DOWN(ram_per_chip
, 1 * MiB
);
872 static void pnv_init(MachineState
*machine
)
874 const char *bios_name
= machine
->firmware
?: FW_FILE_NAME
;
875 PnvMachineState
*pnv
= PNV_MACHINE(machine
);
876 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
877 PnvMachineClass
*pmc
= PNV_MACHINE_GET_CLASS(machine
);
880 uint64_t chip_ram_start
= 0;
883 DriveInfo
*pnor
= drive_get(IF_MTD
, 0, 0);
887 error_report("machine %s does not support the KVM accelerator",
893 if (machine
->ram_size
< mc
->default_ram_size
) {
894 char *sz
= size_to_str(mc
->default_ram_size
);
895 error_report("Invalid RAM size, should be bigger than %s", sz
);
899 memory_region_add_subregion(get_system_memory(), 0, machine
->ram
);
902 * Create our simple PNOR device
904 dev
= qdev_new(TYPE_PNV_PNOR
);
906 qdev_prop_set_drive(dev
, "drive", blk_by_legacy_dinfo(pnor
));
908 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev
), &error_fatal
);
909 pnv
->pnor
= PNV_PNOR(dev
);
911 /* load skiboot firmware */
912 fw_filename
= qemu_find_file(QEMU_FILE_TYPE_BIOS
, bios_name
);
914 error_report("Could not find OPAL firmware '%s'", bios_name
);
918 fw_size
= load_image_targphys(fw_filename
, pnv
->fw_load_addr
, FW_MAX_SIZE
);
920 error_report("Could not load OPAL firmware '%s'", fw_filename
);
926 if (machine
->kernel_filename
) {
929 kernel_size
= load_image_targphys(machine
->kernel_filename
,
930 KERNEL_LOAD_ADDR
, KERNEL_MAX_SIZE
);
931 if (kernel_size
< 0) {
932 error_report("Could not load kernel '%s'",
933 machine
->kernel_filename
);
939 if (machine
->initrd_filename
) {
940 pnv
->initrd_base
= INITRD_LOAD_ADDR
;
941 pnv
->initrd_size
= load_image_targphys(machine
->initrd_filename
,
942 pnv
->initrd_base
, INITRD_MAX_SIZE
);
943 if (pnv
->initrd_size
< 0) {
944 error_report("Could not load initial ram disk '%s'",
945 machine
->initrd_filename
);
950 /* MSIs are supported on this platform */
951 msi_nonbroken
= true;
954 * Check compatibility of the specified CPU with the machine
957 if (!pnv_match_cpu(mc
->default_cpu_type
, machine
->cpu_type
)) {
958 error_report("invalid CPU model '%s' for %s machine",
959 machine
->cpu_type
, mc
->name
);
963 /* Create the processor chips */
964 i
= strlen(machine
->cpu_type
) - strlen(POWERPC_CPU_TYPE_SUFFIX
);
965 chip_typename
= g_strdup_printf(PNV_CHIP_TYPE_NAME("%.*s"),
966 i
, machine
->cpu_type
);
967 if (!object_class_by_name(chip_typename
)) {
968 error_report("invalid chip model '%.*s' for %s machine",
969 i
, machine
->cpu_type
, mc
->name
);
974 machine
->smp
.max_cpus
/ (machine
->smp
.cores
* machine
->smp
.threads
);
976 if (machine
->smp
.threads
> 8) {
977 error_report("Cannot support more than 8 threads/core "
978 "on a powernv machine");
981 if (!is_power_of_2(machine
->smp
.threads
)) {
982 error_report("Cannot support %d threads/core on a powernv"
983 "machine because it must be a power of 2",
984 machine
->smp
.threads
);
988 * TODO: should we decide on how many chips we can create based
989 * on #cores and Venice vs. Murano vs. Naples chip type etc...,
991 if (!is_power_of_2(pnv
->num_chips
) || pnv
->num_chips
> 16) {
992 error_report("invalid number of chips: '%d'", pnv
->num_chips
);
994 "Try '-smp sockets=N'. Valid values are : 1, 2, 4, 8 and 16.\n");
998 pnv
->chips
= g_new0(PnvChip
*, pnv
->num_chips
);
999 for (i
= 0; i
< pnv
->num_chips
; i
++) {
1001 Object
*chip
= OBJECT(qdev_new(chip_typename
));
1002 uint64_t chip_ram_size
= pnv_chip_get_ram_size(pnv
, i
);
1004 pnv
->chips
[i
] = PNV_CHIP(chip
);
1006 /* Distribute RAM among the chips */
1007 object_property_set_int(chip
, "ram-start", chip_ram_start
,
1009 object_property_set_int(chip
, "ram-size", chip_ram_size
,
1011 chip_ram_start
+= chip_ram_size
;
1013 snprintf(chip_name
, sizeof(chip_name
), "chip[%d]", i
);
1014 object_property_add_child(OBJECT(pnv
), chip_name
, chip
);
1015 object_property_set_int(chip
, "chip-id", i
, &error_fatal
);
1016 object_property_set_int(chip
, "nr-cores", machine
->smp
.cores
,
1018 object_property_set_int(chip
, "nr-threads", machine
->smp
.threads
,
1021 * The POWER8 machine use the XICS interrupt interface.
1022 * Propagate the XICS fabric to the chip and its controllers.
1024 if (object_dynamic_cast(OBJECT(pnv
), TYPE_XICS_FABRIC
)) {
1025 object_property_set_link(chip
, "xics", OBJECT(pnv
), &error_abort
);
1027 if (object_dynamic_cast(OBJECT(pnv
), TYPE_XIVE_FABRIC
)) {
1028 object_property_set_link(chip
, "xive-fabric", OBJECT(pnv
),
1031 sysbus_realize_and_unref(SYS_BUS_DEVICE(chip
), &error_fatal
);
1033 g_free(chip_typename
);
1035 /* Instantiate ISA bus on chip 0 */
1036 pnv
->isa_bus
= pnv_isa_create(pnv
->chips
[0], &error_fatal
);
1038 /* Create serial port */
1039 serial_hds_isa_init(pnv
->isa_bus
, 0, MAX_ISA_SERIAL_PORTS
);
1041 /* Create an RTC ISA device too */
1042 mc146818_rtc_init(pnv
->isa_bus
, 2000, NULL
);
1045 * Create the machine BMC simulator and the IPMI BT device for
1046 * communication with the BMC
1048 if (defaults_enabled()) {
1049 pnv
->bmc
= pnv_bmc_create(pnv
->pnor
);
1050 pnv_ipmi_bt_init(pnv
->isa_bus
, pnv
->bmc
, 10);
1054 * The PNOR is mapped on the LPC FW address space by the BMC.
1055 * Since we can not reach the remote BMC machine with LPC memops,
1056 * map it always for now.
1058 memory_region_add_subregion(pnv
->chips
[0]->fw_mr
, PNOR_SPI_OFFSET
,
1062 * OpenPOWER systems use a IPMI SEL Event message to notify the
1065 pnv
->powerdown_notifier
.notify
= pnv_powerdown_notify
;
1066 qemu_register_powerdown_notifier(&pnv
->powerdown_notifier
);
1069 * Create/Connect any machine-specific I2C devices
1071 if (pmc
->i2c_init
) {
1077 * 0:21 Reserved - Read as zeros
1082 static uint32_t pnv_chip_pir_p8(PnvChip
*chip
, uint32_t core_id
,
1085 return (chip
->chip_id
<< 7) | (core_id
<< 3) | thread_id
;
1088 static void pnv_chip_power8_intc_create(PnvChip
*chip
, PowerPCCPU
*cpu
,
1091 Pnv8Chip
*chip8
= PNV8_CHIP(chip
);
1092 Error
*local_err
= NULL
;
1094 PnvCPUState
*pnv_cpu
= pnv_cpu_state(cpu
);
1096 obj
= icp_create(OBJECT(cpu
), TYPE_PNV_ICP
, chip8
->xics
, &local_err
);
1098 error_propagate(errp
, local_err
);
1102 pnv_cpu
->intc
= obj
;
1106 static void pnv_chip_power8_intc_reset(PnvChip
*chip
, PowerPCCPU
*cpu
)
1108 PnvCPUState
*pnv_cpu
= pnv_cpu_state(cpu
);
1110 icp_reset(ICP(pnv_cpu
->intc
));
1113 static void pnv_chip_power8_intc_destroy(PnvChip
*chip
, PowerPCCPU
*cpu
)
1115 PnvCPUState
*pnv_cpu
= pnv_cpu_state(cpu
);
1117 icp_destroy(ICP(pnv_cpu
->intc
));
1118 pnv_cpu
->intc
= NULL
;
1121 static void pnv_chip_power8_intc_print_info(PnvChip
*chip
, PowerPCCPU
*cpu
,
1124 icp_pic_print_info(ICP(pnv_cpu_state(cpu
)->intc
), buf
);
1128 * 0:48 Reserved - Read as zeroes
1131 * 56 Reserved - Read as zero
1135 * We only care about the lower bits. uint32_t is fine for the moment.
1137 static uint32_t pnv_chip_pir_p9(PnvChip
*chip
, uint32_t core_id
,
1140 if (chip
->nr_threads
== 8) {
1141 return (chip
->chip_id
<< 8) | ((thread_id
& 1) << 2) | (core_id
<< 3) |
1144 return (chip
->chip_id
<< 8) | (core_id
<< 2) | thread_id
;
1149 * 0:48 Reserved - Read as zeroes
1152 * 56 Reserved - Read as zero
1154 * 60 Core Chiplet Pair ID
1155 * 61:63 Thread/Core Chiplet ID t0-t2
1157 * We only care about the lower bits. uint32_t is fine for the moment.
1159 static uint32_t pnv_chip_pir_p10(PnvChip
*chip
, uint32_t core_id
,
1162 if (chip
->nr_threads
== 8) {
1163 return (chip
->chip_id
<< 8) | ((core_id
/ 4) << 4) |
1164 ((core_id
% 2) << 3) | thread_id
;
1166 return (chip
->chip_id
<< 8) | (core_id
<< 2) | thread_id
;
1170 static void pnv_chip_power9_intc_create(PnvChip
*chip
, PowerPCCPU
*cpu
,
1173 Pnv9Chip
*chip9
= PNV9_CHIP(chip
);
1174 Error
*local_err
= NULL
;
1176 PnvCPUState
*pnv_cpu
= pnv_cpu_state(cpu
);
1179 * The core creates its interrupt presenter but the XIVE interrupt
1180 * controller object is initialized afterwards. Hopefully, it's
1181 * only used at runtime.
1183 obj
= xive_tctx_create(OBJECT(cpu
), XIVE_PRESENTER(&chip9
->xive
),
1186 error_propagate(errp
, local_err
);
1190 pnv_cpu
->intc
= obj
;
1193 static void pnv_chip_power9_intc_reset(PnvChip
*chip
, PowerPCCPU
*cpu
)
1195 PnvCPUState
*pnv_cpu
= pnv_cpu_state(cpu
);
1197 xive_tctx_reset(XIVE_TCTX(pnv_cpu
->intc
));
1200 static void pnv_chip_power9_intc_destroy(PnvChip
*chip
, PowerPCCPU
*cpu
)
1202 PnvCPUState
*pnv_cpu
= pnv_cpu_state(cpu
);
1204 xive_tctx_destroy(XIVE_TCTX(pnv_cpu
->intc
));
1205 pnv_cpu
->intc
= NULL
;
1208 static void pnv_chip_power9_intc_print_info(PnvChip
*chip
, PowerPCCPU
*cpu
,
1211 xive_tctx_pic_print_info(XIVE_TCTX(pnv_cpu_state(cpu
)->intc
), buf
);
1214 static void pnv_chip_power10_intc_create(PnvChip
*chip
, PowerPCCPU
*cpu
,
1217 Pnv10Chip
*chip10
= PNV10_CHIP(chip
);
1218 Error
*local_err
= NULL
;
1220 PnvCPUState
*pnv_cpu
= pnv_cpu_state(cpu
);
1223 * The core creates its interrupt presenter but the XIVE2 interrupt
1224 * controller object is initialized afterwards. Hopefully, it's
1225 * only used at runtime.
1227 obj
= xive_tctx_create(OBJECT(cpu
), XIVE_PRESENTER(&chip10
->xive
),
1230 error_propagate(errp
, local_err
);
1234 pnv_cpu
->intc
= obj
;
1237 static void pnv_chip_power10_intc_reset(PnvChip
*chip
, PowerPCCPU
*cpu
)
1239 PnvCPUState
*pnv_cpu
= pnv_cpu_state(cpu
);
1241 xive_tctx_reset(XIVE_TCTX(pnv_cpu
->intc
));
1244 static void pnv_chip_power10_intc_destroy(PnvChip
*chip
, PowerPCCPU
*cpu
)
1246 PnvCPUState
*pnv_cpu
= pnv_cpu_state(cpu
);
1248 xive_tctx_destroy(XIVE_TCTX(pnv_cpu
->intc
));
1249 pnv_cpu
->intc
= NULL
;
1252 static void pnv_chip_power10_intc_print_info(PnvChip
*chip
, PowerPCCPU
*cpu
,
1255 xive_tctx_pic_print_info(XIVE_TCTX(pnv_cpu_state(cpu
)->intc
), buf
);
1259 * Allowed core identifiers on a POWER8 Processor Chip :
1268 * <EX7,8 reserved> <reserved>
1270 * EX10 - Venice only
1271 * EX11 - Venice only
1277 #define POWER8E_CORE_MASK (0x7070ull)
1278 #define POWER8_CORE_MASK (0x7e7eull)
1281 * POWER9 has 24 cores, ids starting at 0x0
1283 #define POWER9_CORE_MASK (0xffffffffffffffull)
1286 #define POWER10_CORE_MASK (0xffffffffffffffull)
1288 static void pnv_chip_power8_instance_init(Object
*obj
)
1290 Pnv8Chip
*chip8
= PNV8_CHIP(obj
);
1291 PnvChipClass
*pcc
= PNV_CHIP_GET_CLASS(obj
);
1294 object_property_add_link(obj
, "xics", TYPE_XICS_FABRIC
,
1295 (Object
**)&chip8
->xics
,
1296 object_property_allow_set_link
,
1297 OBJ_PROP_LINK_STRONG
);
1299 object_initialize_child(obj
, "psi", &chip8
->psi
, TYPE_PNV8_PSI
);
1301 object_initialize_child(obj
, "lpc", &chip8
->lpc
, TYPE_PNV8_LPC
);
1303 object_initialize_child(obj
, "occ", &chip8
->occ
, TYPE_PNV8_OCC
);
1305 object_initialize_child(obj
, "homer", &chip8
->homer
, TYPE_PNV8_HOMER
);
1307 if (defaults_enabled()) {
1308 chip8
->num_phbs
= pcc
->num_phbs
;
1310 for (i
= 0; i
< chip8
->num_phbs
; i
++) {
1311 Object
*phb
= object_new(TYPE_PNV_PHB
);
1314 * We need the chip to parent the PHB to allow the DT
1315 * to build correctly (via pnv_xscom_dt()).
1317 * TODO: the PHB should be parented by a PEC device that, at
1318 * this moment, is not modelled powernv8/phb3.
1320 object_property_add_child(obj
, "phb[*]", phb
);
1321 chip8
->phbs
[i
] = PNV_PHB(phb
);
1327 static void pnv_chip_icp_realize(Pnv8Chip
*chip8
, Error
**errp
)
1329 PnvChip
*chip
= PNV_CHIP(chip8
);
1330 PnvChipClass
*pcc
= PNV_CHIP_GET_CLASS(chip
);
1334 name
= g_strdup_printf("icp-%x", chip
->chip_id
);
1335 memory_region_init(&chip8
->icp_mmio
, OBJECT(chip
), name
, PNV_ICP_SIZE
);
1337 memory_region_add_subregion(get_system_memory(), PNV_ICP_BASE(chip
),
1340 /* Map the ICP registers for each thread */
1341 for (i
= 0; i
< chip
->nr_cores
; i
++) {
1342 PnvCore
*pnv_core
= chip
->cores
[i
];
1343 int core_hwid
= CPU_CORE(pnv_core
)->core_id
;
1345 for (j
= 0; j
< CPU_CORE(pnv_core
)->nr_threads
; j
++) {
1346 uint32_t pir
= pcc
->chip_pir(chip
, core_hwid
, j
);
1347 PnvICPState
*icp
= PNV_ICP(xics_icp_get(chip8
->xics
, pir
));
1349 memory_region_add_subregion(&chip8
->icp_mmio
, pir
<< 12,
1355 static void pnv_chip_power8_realize(DeviceState
*dev
, Error
**errp
)
1357 PnvChipClass
*pcc
= PNV_CHIP_GET_CLASS(dev
);
1358 PnvChip
*chip
= PNV_CHIP(dev
);
1359 Pnv8Chip
*chip8
= PNV8_CHIP(dev
);
1360 Pnv8Psi
*psi8
= &chip8
->psi
;
1361 Error
*local_err
= NULL
;
1364 assert(chip8
->xics
);
1366 /* XSCOM bridge is first */
1367 pnv_xscom_init(chip
, PNV_XSCOM_SIZE
, PNV_XSCOM_BASE(chip
));
1369 pcc
->parent_realize(dev
, &local_err
);
1371 error_propagate(errp
, local_err
);
1375 /* Processor Service Interface (PSI) Host Bridge */
1376 object_property_set_int(OBJECT(psi8
), "bar", PNV_PSIHB_BASE(chip
),
1378 object_property_set_link(OBJECT(psi8
), ICS_PROP_XICS
,
1379 OBJECT(chip8
->xics
), &error_abort
);
1380 if (!qdev_realize(DEVICE(psi8
), NULL
, errp
)) {
1383 pnv_xscom_add_subregion(chip
, PNV_XSCOM_PSIHB_BASE
,
1384 &PNV_PSI(psi8
)->xscom_regs
);
1386 /* Create LPC controller */
1387 qdev_realize(DEVICE(&chip8
->lpc
), NULL
, &error_fatal
);
1388 pnv_xscom_add_subregion(chip
, PNV_XSCOM_LPC_BASE
, &chip8
->lpc
.xscom_regs
);
1390 chip
->fw_mr
= &chip8
->lpc
.isa_fw
;
1391 chip
->dt_isa_nodename
= g_strdup_printf("/xscom@%" PRIx64
"/isa@%x",
1392 (uint64_t) PNV_XSCOM_BASE(chip
),
1393 PNV_XSCOM_LPC_BASE
);
1396 * Interrupt Management Area. This is the memory region holding
1397 * all the Interrupt Control Presenter (ICP) registers
1399 pnv_chip_icp_realize(chip8
, &local_err
);
1401 error_propagate(errp
, local_err
);
1405 /* Create the simplified OCC model */
1406 if (!qdev_realize(DEVICE(&chip8
->occ
), NULL
, errp
)) {
1409 pnv_xscom_add_subregion(chip
, PNV_XSCOM_OCC_BASE
, &chip8
->occ
.xscom_regs
);
1410 qdev_connect_gpio_out(DEVICE(&chip8
->occ
), 0,
1411 qdev_get_gpio_in(DEVICE(psi8
), PSIHB_IRQ_OCC
));
1413 /* OCC SRAM model */
1414 memory_region_add_subregion(get_system_memory(), PNV_OCC_SENSOR_BASE(chip
),
1415 &chip8
->occ
.sram_regs
);
1418 object_property_set_link(OBJECT(&chip8
->homer
), "chip", OBJECT(chip
),
1420 if (!qdev_realize(DEVICE(&chip8
->homer
), NULL
, errp
)) {
1423 /* Homer Xscom region */
1424 pnv_xscom_add_subregion(chip
, PNV_XSCOM_PBA_BASE
, &chip8
->homer
.pba_regs
);
1426 /* Homer mmio region */
1427 memory_region_add_subregion(get_system_memory(), PNV_HOMER_BASE(chip
),
1428 &chip8
->homer
.regs
);
1430 /* PHB controllers */
1431 for (i
= 0; i
< chip8
->num_phbs
; i
++) {
1432 PnvPHB
*phb
= chip8
->phbs
[i
];
1434 object_property_set_int(OBJECT(phb
), "index", i
, &error_fatal
);
1435 object_property_set_int(OBJECT(phb
), "chip-id", chip
->chip_id
,
1437 object_property_set_link(OBJECT(phb
), "chip", OBJECT(chip
),
1439 if (!sysbus_realize(SYS_BUS_DEVICE(phb
), errp
)) {
1445 static uint32_t pnv_chip_power8_xscom_pcba(PnvChip
*chip
, uint64_t addr
)
1447 addr
&= (PNV_XSCOM_SIZE
- 1);
1448 return ((addr
>> 4) & ~0xfull
) | ((addr
>> 3) & 0xf);
1451 static void pnv_chip_power8e_class_init(ObjectClass
*klass
, void *data
)
1453 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1454 PnvChipClass
*k
= PNV_CHIP_CLASS(klass
);
1456 k
->chip_cfam_id
= 0x221ef04980000000ull
; /* P8 Murano DD2.1 */
1457 k
->cores_mask
= POWER8E_CORE_MASK
;
1459 k
->chip_pir
= pnv_chip_pir_p8
;
1460 k
->intc_create
= pnv_chip_power8_intc_create
;
1461 k
->intc_reset
= pnv_chip_power8_intc_reset
;
1462 k
->intc_destroy
= pnv_chip_power8_intc_destroy
;
1463 k
->intc_print_info
= pnv_chip_power8_intc_print_info
;
1464 k
->isa_create
= pnv_chip_power8_isa_create
;
1465 k
->dt_populate
= pnv_chip_power8_dt_populate
;
1466 k
->pic_print_info
= pnv_chip_power8_pic_print_info
;
1467 k
->xscom_core_base
= pnv_chip_power8_xscom_core_base
;
1468 k
->xscom_pcba
= pnv_chip_power8_xscom_pcba
;
1469 dc
->desc
= "PowerNV Chip POWER8E";
1471 device_class_set_parent_realize(dc
, pnv_chip_power8_realize
,
1472 &k
->parent_realize
);
1475 static void pnv_chip_power8_class_init(ObjectClass
*klass
, void *data
)
1477 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1478 PnvChipClass
*k
= PNV_CHIP_CLASS(klass
);
1480 k
->chip_cfam_id
= 0x220ea04980000000ull
; /* P8 Venice DD2.0 */
1481 k
->cores_mask
= POWER8_CORE_MASK
;
1483 k
->chip_pir
= pnv_chip_pir_p8
;
1484 k
->intc_create
= pnv_chip_power8_intc_create
;
1485 k
->intc_reset
= pnv_chip_power8_intc_reset
;
1486 k
->intc_destroy
= pnv_chip_power8_intc_destroy
;
1487 k
->intc_print_info
= pnv_chip_power8_intc_print_info
;
1488 k
->isa_create
= pnv_chip_power8_isa_create
;
1489 k
->dt_populate
= pnv_chip_power8_dt_populate
;
1490 k
->pic_print_info
= pnv_chip_power8_pic_print_info
;
1491 k
->xscom_core_base
= pnv_chip_power8_xscom_core_base
;
1492 k
->xscom_pcba
= pnv_chip_power8_xscom_pcba
;
1493 dc
->desc
= "PowerNV Chip POWER8";
1495 device_class_set_parent_realize(dc
, pnv_chip_power8_realize
,
1496 &k
->parent_realize
);
1499 static void pnv_chip_power8nvl_class_init(ObjectClass
*klass
, void *data
)
1501 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1502 PnvChipClass
*k
= PNV_CHIP_CLASS(klass
);
1504 k
->chip_cfam_id
= 0x120d304980000000ull
; /* P8 Naples DD1.0 */
1505 k
->cores_mask
= POWER8_CORE_MASK
;
1507 k
->chip_pir
= pnv_chip_pir_p8
;
1508 k
->intc_create
= pnv_chip_power8_intc_create
;
1509 k
->intc_reset
= pnv_chip_power8_intc_reset
;
1510 k
->intc_destroy
= pnv_chip_power8_intc_destroy
;
1511 k
->intc_print_info
= pnv_chip_power8_intc_print_info
;
1512 k
->isa_create
= pnv_chip_power8nvl_isa_create
;
1513 k
->dt_populate
= pnv_chip_power8_dt_populate
;
1514 k
->pic_print_info
= pnv_chip_power8_pic_print_info
;
1515 k
->xscom_core_base
= pnv_chip_power8_xscom_core_base
;
1516 k
->xscom_pcba
= pnv_chip_power8_xscom_pcba
;
1517 dc
->desc
= "PowerNV Chip POWER8NVL";
1519 device_class_set_parent_realize(dc
, pnv_chip_power8_realize
,
1520 &k
->parent_realize
);
1523 static void pnv_chip_power9_instance_init(Object
*obj
)
1525 PnvChip
*chip
= PNV_CHIP(obj
);
1526 Pnv9Chip
*chip9
= PNV9_CHIP(obj
);
1527 PnvChipClass
*pcc
= PNV_CHIP_GET_CLASS(obj
);
1530 object_initialize_child(obj
, "xive", &chip9
->xive
, TYPE_PNV_XIVE
);
1531 object_property_add_alias(obj
, "xive-fabric", OBJECT(&chip9
->xive
),
1534 object_initialize_child(obj
, "psi", &chip9
->psi
, TYPE_PNV9_PSI
);
1536 object_initialize_child(obj
, "lpc", &chip9
->lpc
, TYPE_PNV9_LPC
);
1538 object_initialize_child(obj
, "chiptod", &chip9
->chiptod
, TYPE_PNV9_CHIPTOD
);
1540 object_initialize_child(obj
, "occ", &chip9
->occ
, TYPE_PNV9_OCC
);
1542 object_initialize_child(obj
, "sbe", &chip9
->sbe
, TYPE_PNV9_SBE
);
1544 object_initialize_child(obj
, "homer", &chip9
->homer
, TYPE_PNV9_HOMER
);
1546 /* Number of PECs is the chip default */
1547 chip
->num_pecs
= pcc
->num_pecs
;
1549 for (i
= 0; i
< chip
->num_pecs
; i
++) {
1550 object_initialize_child(obj
, "pec[*]", &chip9
->pecs
[i
],
1554 for (i
= 0; i
< pcc
->i2c_num_engines
; i
++) {
1555 object_initialize_child(obj
, "i2c[*]", &chip9
->i2c
[i
], TYPE_PNV_I2C
);
1559 static void pnv_chip_quad_realize_one(PnvChip
*chip
, PnvQuad
*eq
,
1564 int core_id
= CPU_CORE(pnv_core
)->core_id
;
1566 snprintf(eq_name
, sizeof(eq_name
), "eq[%d]", core_id
);
1567 object_initialize_child_with_props(OBJECT(chip
), eq_name
, eq
,
1569 &error_fatal
, NULL
);
1571 object_property_set_int(OBJECT(eq
), "quad-id", core_id
, &error_fatal
);
1572 qdev_realize(DEVICE(eq
), NULL
, &error_fatal
);
1575 static void pnv_chip_quad_realize(Pnv9Chip
*chip9
, Error
**errp
)
1577 PnvChip
*chip
= PNV_CHIP(chip9
);
1580 chip9
->nr_quads
= DIV_ROUND_UP(chip
->nr_cores
, 4);
1581 chip9
->quads
= g_new0(PnvQuad
, chip9
->nr_quads
);
1583 for (i
= 0; i
< chip9
->nr_quads
; i
++) {
1584 PnvQuad
*eq
= &chip9
->quads
[i
];
1586 pnv_chip_quad_realize_one(chip
, eq
, chip
->cores
[i
* 4],
1587 PNV_QUAD_TYPE_NAME("power9"));
1589 pnv_xscom_add_subregion(chip
, PNV9_XSCOM_EQ_BASE(eq
->quad_id
),
1594 static void pnv_chip_power9_pec_realize(PnvChip
*chip
, Error
**errp
)
1596 Pnv9Chip
*chip9
= PNV9_CHIP(chip
);
1599 for (i
= 0; i
< chip
->num_pecs
; i
++) {
1600 PnvPhb4PecState
*pec
= &chip9
->pecs
[i
];
1601 PnvPhb4PecClass
*pecc
= PNV_PHB4_PEC_GET_CLASS(pec
);
1602 uint32_t pec_nest_base
;
1603 uint32_t pec_pci_base
;
1605 object_property_set_int(OBJECT(pec
), "index", i
, &error_fatal
);
1606 object_property_set_int(OBJECT(pec
), "chip-id", chip
->chip_id
,
1608 object_property_set_link(OBJECT(pec
), "chip", OBJECT(chip
),
1610 if (!qdev_realize(DEVICE(pec
), NULL
, errp
)) {
1614 pec_nest_base
= pecc
->xscom_nest_base(pec
);
1615 pec_pci_base
= pecc
->xscom_pci_base(pec
);
1617 pnv_xscom_add_subregion(chip
, pec_nest_base
, &pec
->nest_regs_mr
);
1618 pnv_xscom_add_subregion(chip
, pec_pci_base
, &pec
->pci_regs_mr
);
1622 static void pnv_chip_power9_realize(DeviceState
*dev
, Error
**errp
)
1624 PnvChipClass
*pcc
= PNV_CHIP_GET_CLASS(dev
);
1625 Pnv9Chip
*chip9
= PNV9_CHIP(dev
);
1626 PnvChip
*chip
= PNV_CHIP(dev
);
1627 Pnv9Psi
*psi9
= &chip9
->psi
;
1628 Error
*local_err
= NULL
;
1631 /* XSCOM bridge is first */
1632 pnv_xscom_init(chip
, PNV9_XSCOM_SIZE
, PNV9_XSCOM_BASE(chip
));
1634 pcc
->parent_realize(dev
, &local_err
);
1636 error_propagate(errp
, local_err
);
1640 pnv_chip_quad_realize(chip9
, &local_err
);
1642 error_propagate(errp
, local_err
);
1646 /* XIVE interrupt controller (POWER9) */
1647 object_property_set_int(OBJECT(&chip9
->xive
), "ic-bar",
1648 PNV9_XIVE_IC_BASE(chip
), &error_fatal
);
1649 object_property_set_int(OBJECT(&chip9
->xive
), "vc-bar",
1650 PNV9_XIVE_VC_BASE(chip
), &error_fatal
);
1651 object_property_set_int(OBJECT(&chip9
->xive
), "pc-bar",
1652 PNV9_XIVE_PC_BASE(chip
), &error_fatal
);
1653 object_property_set_int(OBJECT(&chip9
->xive
), "tm-bar",
1654 PNV9_XIVE_TM_BASE(chip
), &error_fatal
);
1655 object_property_set_link(OBJECT(&chip9
->xive
), "chip", OBJECT(chip
),
1657 if (!sysbus_realize(SYS_BUS_DEVICE(&chip9
->xive
), errp
)) {
1660 pnv_xscom_add_subregion(chip
, PNV9_XSCOM_XIVE_BASE
,
1661 &chip9
->xive
.xscom_regs
);
1663 /* Processor Service Interface (PSI) Host Bridge */
1664 object_property_set_int(OBJECT(psi9
), "bar", PNV9_PSIHB_BASE(chip
),
1666 /* This is the only device with 4k ESB pages */
1667 object_property_set_int(OBJECT(psi9
), "shift", XIVE_ESB_4K
,
1669 if (!qdev_realize(DEVICE(psi9
), NULL
, errp
)) {
1672 pnv_xscom_add_subregion(chip
, PNV9_XSCOM_PSIHB_BASE
,
1673 &PNV_PSI(psi9
)->xscom_regs
);
1676 if (!qdev_realize(DEVICE(&chip9
->lpc
), NULL
, errp
)) {
1679 memory_region_add_subregion(get_system_memory(), PNV9_LPCM_BASE(chip
),
1680 &chip9
->lpc
.xscom_regs
);
1682 chip
->fw_mr
= &chip9
->lpc
.isa_fw
;
1683 chip
->dt_isa_nodename
= g_strdup_printf("/lpcm-opb@%" PRIx64
"/lpc@0",
1684 (uint64_t) PNV9_LPCM_BASE(chip
));
1687 object_property_set_bool(OBJECT(&chip9
->chiptod
), "primary",
1688 chip
->chip_id
== 0, &error_abort
);
1689 object_property_set_bool(OBJECT(&chip9
->chiptod
), "secondary",
1690 chip
->chip_id
== 1, &error_abort
);
1691 object_property_set_link(OBJECT(&chip9
->chiptod
), "chip", OBJECT(chip
),
1693 if (!qdev_realize(DEVICE(&chip9
->chiptod
), NULL
, errp
)) {
1696 pnv_xscom_add_subregion(chip
, PNV9_XSCOM_CHIPTOD_BASE
,
1697 &chip9
->chiptod
.xscom_regs
);
1699 /* Create the simplified OCC model */
1700 if (!qdev_realize(DEVICE(&chip9
->occ
), NULL
, errp
)) {
1703 pnv_xscom_add_subregion(chip
, PNV9_XSCOM_OCC_BASE
, &chip9
->occ
.xscom_regs
);
1704 qdev_connect_gpio_out(DEVICE(&chip9
->occ
), 0, qdev_get_gpio_in(
1705 DEVICE(psi9
), PSIHB9_IRQ_OCC
));
1707 /* OCC SRAM model */
1708 memory_region_add_subregion(get_system_memory(), PNV9_OCC_SENSOR_BASE(chip
),
1709 &chip9
->occ
.sram_regs
);
1712 if (!qdev_realize(DEVICE(&chip9
->sbe
), NULL
, errp
)) {
1715 pnv_xscom_add_subregion(chip
, PNV9_XSCOM_SBE_CTRL_BASE
,
1716 &chip9
->sbe
.xscom_ctrl_regs
);
1717 pnv_xscom_add_subregion(chip
, PNV9_XSCOM_SBE_MBOX_BASE
,
1718 &chip9
->sbe
.xscom_mbox_regs
);
1719 qdev_connect_gpio_out(DEVICE(&chip9
->sbe
), 0, qdev_get_gpio_in(
1720 DEVICE(psi9
), PSIHB9_IRQ_PSU
));
1723 object_property_set_link(OBJECT(&chip9
->homer
), "chip", OBJECT(chip
),
1725 if (!qdev_realize(DEVICE(&chip9
->homer
), NULL
, errp
)) {
1728 /* Homer Xscom region */
1729 pnv_xscom_add_subregion(chip
, PNV9_XSCOM_PBA_BASE
, &chip9
->homer
.pba_regs
);
1731 /* Homer mmio region */
1732 memory_region_add_subregion(get_system_memory(), PNV9_HOMER_BASE(chip
),
1733 &chip9
->homer
.regs
);
1736 pnv_chip_power9_pec_realize(chip
, &local_err
);
1738 error_propagate(errp
, local_err
);
1745 for (i
= 0; i
< pcc
->i2c_num_engines
; i
++) {
1746 Object
*obj
= OBJECT(&chip9
->i2c
[i
]);
1748 object_property_set_int(obj
, "engine", i
+ 1, &error_fatal
);
1749 object_property_set_int(obj
, "num-busses",
1750 pcc
->i2c_ports_per_engine
[i
],
1752 object_property_set_link(obj
, "chip", OBJECT(chip
), &error_abort
);
1753 if (!qdev_realize(DEVICE(obj
), NULL
, errp
)) {
1756 pnv_xscom_add_subregion(chip
, PNV9_XSCOM_I2CM_BASE
+
1757 (chip9
->i2c
[i
].engine
- 1) *
1758 PNV9_XSCOM_I2CM_SIZE
,
1759 &chip9
->i2c
[i
].xscom_regs
);
1760 qdev_connect_gpio_out(DEVICE(&chip9
->i2c
[i
]), 0,
1761 qdev_get_gpio_in(DEVICE(psi9
),
1762 PSIHB9_IRQ_SBE_I2C
));
1766 static uint32_t pnv_chip_power9_xscom_pcba(PnvChip
*chip
, uint64_t addr
)
1768 addr
&= (PNV9_XSCOM_SIZE
- 1);
1772 static void pnv_chip_power9_class_init(ObjectClass
*klass
, void *data
)
1774 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1775 PnvChipClass
*k
= PNV_CHIP_CLASS(klass
);
1776 static const int i2c_ports_per_engine
[PNV9_CHIP_MAX_I2C
] = {2, 13, 2, 2};
1778 k
->chip_cfam_id
= 0x220d104900008000ull
; /* P9 Nimbus DD2.0 */
1779 k
->cores_mask
= POWER9_CORE_MASK
;
1780 k
->chip_pir
= pnv_chip_pir_p9
;
1781 k
->intc_create
= pnv_chip_power9_intc_create
;
1782 k
->intc_reset
= pnv_chip_power9_intc_reset
;
1783 k
->intc_destroy
= pnv_chip_power9_intc_destroy
;
1784 k
->intc_print_info
= pnv_chip_power9_intc_print_info
;
1785 k
->isa_create
= pnv_chip_power9_isa_create
;
1786 k
->dt_populate
= pnv_chip_power9_dt_populate
;
1787 k
->pic_print_info
= pnv_chip_power9_pic_print_info
;
1788 k
->xscom_core_base
= pnv_chip_power9_xscom_core_base
;
1789 k
->xscom_pcba
= pnv_chip_power9_xscom_pcba
;
1790 dc
->desc
= "PowerNV Chip POWER9";
1791 k
->num_pecs
= PNV9_CHIP_MAX_PEC
;
1792 k
->i2c_num_engines
= PNV9_CHIP_MAX_I2C
;
1793 k
->i2c_ports_per_engine
= i2c_ports_per_engine
;
1795 device_class_set_parent_realize(dc
, pnv_chip_power9_realize
,
1796 &k
->parent_realize
);
1799 static void pnv_chip_power10_instance_init(Object
*obj
)
1801 PnvChip
*chip
= PNV_CHIP(obj
);
1802 Pnv10Chip
*chip10
= PNV10_CHIP(obj
);
1803 PnvChipClass
*pcc
= PNV_CHIP_GET_CLASS(obj
);
1806 object_initialize_child(obj
, "xive", &chip10
->xive
, TYPE_PNV_XIVE2
);
1807 object_property_add_alias(obj
, "xive-fabric", OBJECT(&chip10
->xive
),
1809 object_initialize_child(obj
, "psi", &chip10
->psi
, TYPE_PNV10_PSI
);
1810 object_initialize_child(obj
, "lpc", &chip10
->lpc
, TYPE_PNV10_LPC
);
1811 object_initialize_child(obj
, "chiptod", &chip10
->chiptod
,
1812 TYPE_PNV10_CHIPTOD
);
1813 object_initialize_child(obj
, "occ", &chip10
->occ
, TYPE_PNV10_OCC
);
1814 object_initialize_child(obj
, "sbe", &chip10
->sbe
, TYPE_PNV10_SBE
);
1815 object_initialize_child(obj
, "homer", &chip10
->homer
, TYPE_PNV10_HOMER
);
1816 object_initialize_child(obj
, "n1-chiplet", &chip10
->n1_chiplet
,
1817 TYPE_PNV_N1_CHIPLET
);
1819 chip
->num_pecs
= pcc
->num_pecs
;
1821 for (i
= 0; i
< chip
->num_pecs
; i
++) {
1822 object_initialize_child(obj
, "pec[*]", &chip10
->pecs
[i
],
1826 for (i
= 0; i
< pcc
->i2c_num_engines
; i
++) {
1827 object_initialize_child(obj
, "i2c[*]", &chip10
->i2c
[i
], TYPE_PNV_I2C
);
1831 static void pnv_chip_power10_quad_realize(Pnv10Chip
*chip10
, Error
**errp
)
1833 PnvChip
*chip
= PNV_CHIP(chip10
);
1836 chip10
->nr_quads
= DIV_ROUND_UP(chip
->nr_cores
, 4);
1837 chip10
->quads
= g_new0(PnvQuad
, chip10
->nr_quads
);
1839 for (i
= 0; i
< chip10
->nr_quads
; i
++) {
1840 PnvQuad
*eq
= &chip10
->quads
[i
];
1842 pnv_chip_quad_realize_one(chip
, eq
, chip
->cores
[i
* 4],
1843 PNV_QUAD_TYPE_NAME("power10"));
1845 pnv_xscom_add_subregion(chip
, PNV10_XSCOM_EQ_BASE(eq
->quad_id
),
1848 pnv_xscom_add_subregion(chip
, PNV10_XSCOM_QME_BASE(eq
->quad_id
),
1849 &eq
->xscom_qme_regs
);
1853 static void pnv_chip_power10_phb_realize(PnvChip
*chip
, Error
**errp
)
1855 Pnv10Chip
*chip10
= PNV10_CHIP(chip
);
1858 for (i
= 0; i
< chip
->num_pecs
; i
++) {
1859 PnvPhb4PecState
*pec
= &chip10
->pecs
[i
];
1860 PnvPhb4PecClass
*pecc
= PNV_PHB4_PEC_GET_CLASS(pec
);
1861 uint32_t pec_nest_base
;
1862 uint32_t pec_pci_base
;
1864 object_property_set_int(OBJECT(pec
), "index", i
, &error_fatal
);
1865 object_property_set_int(OBJECT(pec
), "chip-id", chip
->chip_id
,
1867 object_property_set_link(OBJECT(pec
), "chip", OBJECT(chip
),
1869 if (!qdev_realize(DEVICE(pec
), NULL
, errp
)) {
1873 pec_nest_base
= pecc
->xscom_nest_base(pec
);
1874 pec_pci_base
= pecc
->xscom_pci_base(pec
);
1876 pnv_xscom_add_subregion(chip
, pec_nest_base
, &pec
->nest_regs_mr
);
1877 pnv_xscom_add_subregion(chip
, pec_pci_base
, &pec
->pci_regs_mr
);
1881 static void pnv_chip_power10_realize(DeviceState
*dev
, Error
**errp
)
1883 PnvChipClass
*pcc
= PNV_CHIP_GET_CLASS(dev
);
1884 PnvChip
*chip
= PNV_CHIP(dev
);
1885 Pnv10Chip
*chip10
= PNV10_CHIP(dev
);
1886 Error
*local_err
= NULL
;
1889 /* XSCOM bridge is first */
1890 pnv_xscom_init(chip
, PNV10_XSCOM_SIZE
, PNV10_XSCOM_BASE(chip
));
1892 pcc
->parent_realize(dev
, &local_err
);
1894 error_propagate(errp
, local_err
);
1898 pnv_chip_power10_quad_realize(chip10
, &local_err
);
1900 error_propagate(errp
, local_err
);
1904 /* XIVE2 interrupt controller (POWER10) */
1905 object_property_set_int(OBJECT(&chip10
->xive
), "ic-bar",
1906 PNV10_XIVE2_IC_BASE(chip
), &error_fatal
);
1907 object_property_set_int(OBJECT(&chip10
->xive
), "esb-bar",
1908 PNV10_XIVE2_ESB_BASE(chip
), &error_fatal
);
1909 object_property_set_int(OBJECT(&chip10
->xive
), "end-bar",
1910 PNV10_XIVE2_END_BASE(chip
), &error_fatal
);
1911 object_property_set_int(OBJECT(&chip10
->xive
), "nvpg-bar",
1912 PNV10_XIVE2_NVPG_BASE(chip
), &error_fatal
);
1913 object_property_set_int(OBJECT(&chip10
->xive
), "nvc-bar",
1914 PNV10_XIVE2_NVC_BASE(chip
), &error_fatal
);
1915 object_property_set_int(OBJECT(&chip10
->xive
), "tm-bar",
1916 PNV10_XIVE2_TM_BASE(chip
), &error_fatal
);
1917 object_property_set_link(OBJECT(&chip10
->xive
), "chip", OBJECT(chip
),
1919 if (!sysbus_realize(SYS_BUS_DEVICE(&chip10
->xive
), errp
)) {
1922 pnv_xscom_add_subregion(chip
, PNV10_XSCOM_XIVE2_BASE
,
1923 &chip10
->xive
.xscom_regs
);
1925 /* Processor Service Interface (PSI) Host Bridge */
1926 object_property_set_int(OBJECT(&chip10
->psi
), "bar",
1927 PNV10_PSIHB_BASE(chip
), &error_fatal
);
1928 /* PSI can now be configured to use 64k ESB pages on POWER10 */
1929 object_property_set_int(OBJECT(&chip10
->psi
), "shift", XIVE_ESB_64K
,
1931 if (!qdev_realize(DEVICE(&chip10
->psi
), NULL
, errp
)) {
1934 pnv_xscom_add_subregion(chip
, PNV10_XSCOM_PSIHB_BASE
,
1935 &PNV_PSI(&chip10
->psi
)->xscom_regs
);
1938 if (!qdev_realize(DEVICE(&chip10
->lpc
), NULL
, errp
)) {
1941 memory_region_add_subregion(get_system_memory(), PNV10_LPCM_BASE(chip
),
1942 &chip10
->lpc
.xscom_regs
);
1944 chip
->fw_mr
= &chip10
->lpc
.isa_fw
;
1945 chip
->dt_isa_nodename
= g_strdup_printf("/lpcm-opb@%" PRIx64
"/lpc@0",
1946 (uint64_t) PNV10_LPCM_BASE(chip
));
1949 object_property_set_bool(OBJECT(&chip10
->chiptod
), "primary",
1950 chip
->chip_id
== 0, &error_abort
);
1951 object_property_set_bool(OBJECT(&chip10
->chiptod
), "secondary",
1952 chip
->chip_id
== 1, &error_abort
);
1953 object_property_set_link(OBJECT(&chip10
->chiptod
), "chip", OBJECT(chip
),
1955 if (!qdev_realize(DEVICE(&chip10
->chiptod
), NULL
, errp
)) {
1958 pnv_xscom_add_subregion(chip
, PNV10_XSCOM_CHIPTOD_BASE
,
1959 &chip10
->chiptod
.xscom_regs
);
1961 /* Create the simplified OCC model */
1962 if (!qdev_realize(DEVICE(&chip10
->occ
), NULL
, errp
)) {
1965 pnv_xscom_add_subregion(chip
, PNV10_XSCOM_OCC_BASE
,
1966 &chip10
->occ
.xscom_regs
);
1967 qdev_connect_gpio_out(DEVICE(&chip10
->occ
), 0, qdev_get_gpio_in(
1968 DEVICE(&chip10
->psi
), PSIHB9_IRQ_OCC
));
1970 /* OCC SRAM model */
1971 memory_region_add_subregion(get_system_memory(),
1972 PNV10_OCC_SENSOR_BASE(chip
),
1973 &chip10
->occ
.sram_regs
);
1976 if (!qdev_realize(DEVICE(&chip10
->sbe
), NULL
, errp
)) {
1979 pnv_xscom_add_subregion(chip
, PNV10_XSCOM_SBE_CTRL_BASE
,
1980 &chip10
->sbe
.xscom_ctrl_regs
);
1981 pnv_xscom_add_subregion(chip
, PNV10_XSCOM_SBE_MBOX_BASE
,
1982 &chip10
->sbe
.xscom_mbox_regs
);
1983 qdev_connect_gpio_out(DEVICE(&chip10
->sbe
), 0, qdev_get_gpio_in(
1984 DEVICE(&chip10
->psi
), PSIHB9_IRQ_PSU
));
1987 object_property_set_link(OBJECT(&chip10
->homer
), "chip", OBJECT(chip
),
1989 if (!qdev_realize(DEVICE(&chip10
->homer
), NULL
, errp
)) {
1992 /* Homer Xscom region */
1993 pnv_xscom_add_subregion(chip
, PNV10_XSCOM_PBA_BASE
,
1994 &chip10
->homer
.pba_regs
);
1996 /* Homer mmio region */
1997 memory_region_add_subregion(get_system_memory(), PNV10_HOMER_BASE(chip
),
1998 &chip10
->homer
.regs
);
2001 if (!qdev_realize(DEVICE(&chip10
->n1_chiplet
), NULL
, errp
)) {
2004 pnv_xscom_add_subregion(chip
, PNV10_XSCOM_N1_CHIPLET_CTRL_REGS_BASE
,
2005 &chip10
->n1_chiplet
.nest_pervasive
.xscom_ctrl_regs_mr
);
2007 pnv_xscom_add_subregion(chip
, PNV10_XSCOM_N1_PB_SCOM_EQ_BASE
,
2008 &chip10
->n1_chiplet
.xscom_pb_eq_mr
);
2010 pnv_xscom_add_subregion(chip
, PNV10_XSCOM_N1_PB_SCOM_ES_BASE
,
2011 &chip10
->n1_chiplet
.xscom_pb_es_mr
);
2014 pnv_chip_power10_phb_realize(chip
, &local_err
);
2016 error_propagate(errp
, local_err
);
2024 for (i
= 0; i
< pcc
->i2c_num_engines
; i
++) {
2025 Object
*obj
= OBJECT(&chip10
->i2c
[i
]);
2027 object_property_set_int(obj
, "engine", i
+ 1, &error_fatal
);
2028 object_property_set_int(obj
, "num-busses",
2029 pcc
->i2c_ports_per_engine
[i
],
2031 object_property_set_link(obj
, "chip", OBJECT(chip
), &error_abort
);
2032 if (!qdev_realize(DEVICE(obj
), NULL
, errp
)) {
2035 pnv_xscom_add_subregion(chip
, PNV10_XSCOM_I2CM_BASE
+
2036 (chip10
->i2c
[i
].engine
- 1) *
2037 PNV10_XSCOM_I2CM_SIZE
,
2038 &chip10
->i2c
[i
].xscom_regs
);
2039 qdev_connect_gpio_out(DEVICE(&chip10
->i2c
[i
]), 0,
2040 qdev_get_gpio_in(DEVICE(&chip10
->psi
),
2041 PSIHB9_IRQ_SBE_I2C
));
2046 static void pnv_rainier_i2c_init(PnvMachineState
*pnv
)
2049 for (i
= 0; i
< pnv
->num_chips
; i
++) {
2050 Pnv10Chip
*chip10
= PNV10_CHIP(pnv
->chips
[i
]);
2053 * Add a PCA9552 I2C device for PCIe hotplug control
2054 * to engine 2, bus 1, address 0x63
2056 I2CSlave
*dev
= i2c_slave_create_simple(chip10
->i2c
[2].busses
[1],
2060 * Connect PCA9552 GPIO pins 0-4 (SLOTx_EN) outputs to GPIO pins 5-9
2061 * (SLOTx_PG) inputs in order to fake the pgood state of PCIe slots
2062 * after hypervisor code sets a SLOTx_EN pin high.
2064 qdev_connect_gpio_out(DEVICE(dev
), 0, qdev_get_gpio_in(DEVICE(dev
), 5));
2065 qdev_connect_gpio_out(DEVICE(dev
), 1, qdev_get_gpio_in(DEVICE(dev
), 6));
2066 qdev_connect_gpio_out(DEVICE(dev
), 2, qdev_get_gpio_in(DEVICE(dev
), 7));
2067 qdev_connect_gpio_out(DEVICE(dev
), 3, qdev_get_gpio_in(DEVICE(dev
), 8));
2068 qdev_connect_gpio_out(DEVICE(dev
), 4, qdev_get_gpio_in(DEVICE(dev
), 9));
2071 * Add a PCA9554 I2C device for cable card presence detection
2072 * to engine 2, bus 1, address 0x25
2074 i2c_slave_create_simple(chip10
->i2c
[2].busses
[1], "pca9554", 0x25);
2078 static uint32_t pnv_chip_power10_xscom_pcba(PnvChip
*chip
, uint64_t addr
)
2080 addr
&= (PNV10_XSCOM_SIZE
- 1);
2084 static void pnv_chip_power10_class_init(ObjectClass
*klass
, void *data
)
2086 DeviceClass
*dc
= DEVICE_CLASS(klass
);
2087 PnvChipClass
*k
= PNV_CHIP_CLASS(klass
);
2088 static const int i2c_ports_per_engine
[PNV10_CHIP_MAX_I2C
] = {14, 14, 2, 16};
2090 k
->chip_cfam_id
= 0x120da04900008000ull
; /* P10 DD1.0 (with NX) */
2091 k
->cores_mask
= POWER10_CORE_MASK
;
2092 k
->chip_pir
= pnv_chip_pir_p10
;
2093 k
->intc_create
= pnv_chip_power10_intc_create
;
2094 k
->intc_reset
= pnv_chip_power10_intc_reset
;
2095 k
->intc_destroy
= pnv_chip_power10_intc_destroy
;
2096 k
->intc_print_info
= pnv_chip_power10_intc_print_info
;
2097 k
->isa_create
= pnv_chip_power10_isa_create
;
2098 k
->dt_populate
= pnv_chip_power10_dt_populate
;
2099 k
->pic_print_info
= pnv_chip_power10_pic_print_info
;
2100 k
->xscom_core_base
= pnv_chip_power10_xscom_core_base
;
2101 k
->xscom_pcba
= pnv_chip_power10_xscom_pcba
;
2102 dc
->desc
= "PowerNV Chip POWER10";
2103 k
->num_pecs
= PNV10_CHIP_MAX_PEC
;
2104 k
->i2c_num_engines
= PNV10_CHIP_MAX_I2C
;
2105 k
->i2c_ports_per_engine
= i2c_ports_per_engine
;
2107 device_class_set_parent_realize(dc
, pnv_chip_power10_realize
,
2108 &k
->parent_realize
);
2111 static void pnv_chip_core_sanitize(PnvChip
*chip
, Error
**errp
)
2113 PnvChipClass
*pcc
= PNV_CHIP_GET_CLASS(chip
);
2117 * No custom mask for this chip, let's use the default one from *
2120 if (!chip
->cores_mask
) {
2121 chip
->cores_mask
= pcc
->cores_mask
;
2124 /* filter alien core ids ! some are reserved */
2125 if ((chip
->cores_mask
& pcc
->cores_mask
) != chip
->cores_mask
) {
2126 error_setg(errp
, "warning: invalid core mask for chip Ox%"PRIx64
" !",
2130 chip
->cores_mask
&= pcc
->cores_mask
;
2132 /* now that we have a sane layout, let check the number of cores */
2133 cores_max
= ctpop64(chip
->cores_mask
);
2134 if (chip
->nr_cores
> cores_max
) {
2135 error_setg(errp
, "warning: too many cores for chip ! Limit is %d",
2141 static void pnv_chip_core_realize(PnvChip
*chip
, Error
**errp
)
2143 Error
*error
= NULL
;
2144 PnvChipClass
*pcc
= PNV_CHIP_GET_CLASS(chip
);
2145 const char *typename
= pnv_chip_core_typename(chip
);
2147 PnvMachineState
*pnv
= PNV_MACHINE(qdev_get_machine());
2149 if (!object_class_by_name(typename
)) {
2150 error_setg(errp
, "Unable to find PowerNV CPU Core '%s'", typename
);
2155 pnv_chip_core_sanitize(chip
, &error
);
2157 error_propagate(errp
, error
);
2161 chip
->cores
= g_new0(PnvCore
*, chip
->nr_cores
);
2163 for (i
= 0, core_hwid
= 0; (core_hwid
< sizeof(chip
->cores_mask
) * 8)
2164 && (i
< chip
->nr_cores
); core_hwid
++) {
2167 uint64_t xscom_core_base
;
2169 if (!(chip
->cores_mask
& (1ull << core_hwid
))) {
2173 pnv_core
= PNV_CORE(object_new(typename
));
2175 snprintf(core_name
, sizeof(core_name
), "core[%d]", core_hwid
);
2176 object_property_add_child(OBJECT(chip
), core_name
, OBJECT(pnv_core
));
2177 chip
->cores
[i
] = pnv_core
;
2178 object_property_set_int(OBJECT(pnv_core
), "nr-threads",
2179 chip
->nr_threads
, &error_fatal
);
2180 object_property_set_int(OBJECT(pnv_core
), CPU_CORE_PROP_CORE_ID
,
2181 core_hwid
, &error_fatal
);
2182 object_property_set_int(OBJECT(pnv_core
), "hwid", core_hwid
,
2184 object_property_set_int(OBJECT(pnv_core
), "hrmor", pnv
->fw_load_addr
,
2186 object_property_set_link(OBJECT(pnv_core
), "chip", OBJECT(chip
),
2188 qdev_realize(DEVICE(pnv_core
), NULL
, &error_fatal
);
2190 /* Each core has an XSCOM MMIO region */
2191 xscom_core_base
= pcc
->xscom_core_base(chip
, core_hwid
);
2193 pnv_xscom_add_subregion(chip
, xscom_core_base
,
2194 &pnv_core
->xscom_regs
);
2199 static void pnv_chip_realize(DeviceState
*dev
, Error
**errp
)
2201 PnvChip
*chip
= PNV_CHIP(dev
);
2202 Error
*error
= NULL
;
2205 pnv_chip_core_realize(chip
, &error
);
2207 error_propagate(errp
, error
);
2212 static Property pnv_chip_properties
[] = {
2213 DEFINE_PROP_UINT32("chip-id", PnvChip
, chip_id
, 0),
2214 DEFINE_PROP_UINT64("ram-start", PnvChip
, ram_start
, 0),
2215 DEFINE_PROP_UINT64("ram-size", PnvChip
, ram_size
, 0),
2216 DEFINE_PROP_UINT32("nr-cores", PnvChip
, nr_cores
, 1),
2217 DEFINE_PROP_UINT64("cores-mask", PnvChip
, cores_mask
, 0x0),
2218 DEFINE_PROP_UINT32("nr-threads", PnvChip
, nr_threads
, 1),
2219 DEFINE_PROP_END_OF_LIST(),
2222 static void pnv_chip_class_init(ObjectClass
*klass
, void *data
)
2224 DeviceClass
*dc
= DEVICE_CLASS(klass
);
2226 set_bit(DEVICE_CATEGORY_CPU
, dc
->categories
);
2227 dc
->realize
= pnv_chip_realize
;
2228 device_class_set_props(dc
, pnv_chip_properties
);
2229 dc
->desc
= "PowerNV Chip";
2232 PnvCore
*pnv_chip_find_core(PnvChip
*chip
, uint32_t core_id
)
2236 for (i
= 0; i
< chip
->nr_cores
; i
++) {
2237 PnvCore
*pc
= chip
->cores
[i
];
2238 CPUCore
*cc
= CPU_CORE(pc
);
2240 if (cc
->core_id
== core_id
) {
2247 PowerPCCPU
*pnv_chip_find_cpu(PnvChip
*chip
, uint32_t pir
)
2251 for (i
= 0; i
< chip
->nr_cores
; i
++) {
2252 PnvCore
*pc
= chip
->cores
[i
];
2253 CPUCore
*cc
= CPU_CORE(pc
);
2255 for (j
= 0; j
< cc
->nr_threads
; j
++) {
2256 if (ppc_cpu_pir(pc
->threads
[j
]) == pir
) {
2257 return pc
->threads
[j
];
2264 static void pnv_chip_foreach_cpu(PnvChip
*chip
,
2265 void (*fn
)(PnvChip
*chip
, PowerPCCPU
*cpu
, void *opaque
),
2270 for (i
= 0; i
< chip
->nr_cores
; i
++) {
2271 PnvCore
*pc
= chip
->cores
[i
];
2273 for (j
= 0; j
< CPU_CORE(pc
)->nr_threads
; j
++) {
2274 fn(chip
, pc
->threads
[j
], opaque
);
2279 static ICSState
*pnv_ics_get(XICSFabric
*xi
, int irq
)
2281 PnvMachineState
*pnv
= PNV_MACHINE(xi
);
2284 for (i
= 0; i
< pnv
->num_chips
; i
++) {
2285 Pnv8Chip
*chip8
= PNV8_CHIP(pnv
->chips
[i
]);
2287 if (ics_valid_irq(&chip8
->psi
.ics
, irq
)) {
2288 return &chip8
->psi
.ics
;
2291 for (j
= 0; j
< chip8
->num_phbs
; j
++) {
2292 PnvPHB
*phb
= chip8
->phbs
[j
];
2293 PnvPHB3
*phb3
= PNV_PHB3(phb
->backend
);
2295 if (ics_valid_irq(&phb3
->lsis
, irq
)) {
2299 if (ics_valid_irq(ICS(&phb3
->msis
), irq
)) {
2300 return ICS(&phb3
->msis
);
2307 PnvChip
*pnv_get_chip(PnvMachineState
*pnv
, uint32_t chip_id
)
2311 for (i
= 0; i
< pnv
->num_chips
; i
++) {
2312 PnvChip
*chip
= pnv
->chips
[i
];
2313 if (chip
->chip_id
== chip_id
) {
2320 static void pnv_ics_resend(XICSFabric
*xi
)
2322 PnvMachineState
*pnv
= PNV_MACHINE(xi
);
2325 for (i
= 0; i
< pnv
->num_chips
; i
++) {
2326 Pnv8Chip
*chip8
= PNV8_CHIP(pnv
->chips
[i
]);
2328 ics_resend(&chip8
->psi
.ics
);
2330 for (j
= 0; j
< chip8
->num_phbs
; j
++) {
2331 PnvPHB
*phb
= chip8
->phbs
[j
];
2332 PnvPHB3
*phb3
= PNV_PHB3(phb
->backend
);
2334 ics_resend(&phb3
->lsis
);
2335 ics_resend(ICS(&phb3
->msis
));
2340 static ICPState
*pnv_icp_get(XICSFabric
*xi
, int pir
)
2342 PowerPCCPU
*cpu
= ppc_get_vcpu_by_pir(pir
);
2344 return cpu
? ICP(pnv_cpu_state(cpu
)->intc
) : NULL
;
2347 static void pnv_pic_intc_print_info(PnvChip
*chip
, PowerPCCPU
*cpu
,
2350 PNV_CHIP_GET_CLASS(chip
)->intc_print_info(chip
, cpu
, opaque
);
2353 static void pnv_pic_print_info(InterruptStatsProvider
*obj
, GString
*buf
)
2355 PnvMachineState
*pnv
= PNV_MACHINE(obj
);
2358 for (i
= 0; i
< pnv
->num_chips
; i
++) {
2359 PnvChip
*chip
= pnv
->chips
[i
];
2361 /* First CPU presenters */
2362 pnv_chip_foreach_cpu(chip
, pnv_pic_intc_print_info
, buf
);
2364 /* Then other devices, PHB, PSI, XIVE */
2365 PNV_CHIP_GET_CLASS(chip
)->pic_print_info(chip
, buf
);
2369 static int pnv_match_nvt(XiveFabric
*xfb
, uint8_t format
,
2370 uint8_t nvt_blk
, uint32_t nvt_idx
,
2371 bool cam_ignore
, uint8_t priority
,
2372 uint32_t logic_serv
,
2373 XiveTCTXMatch
*match
)
2375 PnvMachineState
*pnv
= PNV_MACHINE(xfb
);
2376 int total_count
= 0;
2379 for (i
= 0; i
< pnv
->num_chips
; i
++) {
2380 Pnv9Chip
*chip9
= PNV9_CHIP(pnv
->chips
[i
]);
2381 XivePresenter
*xptr
= XIVE_PRESENTER(&chip9
->xive
);
2382 XivePresenterClass
*xpc
= XIVE_PRESENTER_GET_CLASS(xptr
);
2385 count
= xpc
->match_nvt(xptr
, format
, nvt_blk
, nvt_idx
, cam_ignore
,
2386 priority
, logic_serv
, match
);
2392 total_count
+= count
;
2398 static int pnv10_xive_match_nvt(XiveFabric
*xfb
, uint8_t format
,
2399 uint8_t nvt_blk
, uint32_t nvt_idx
,
2400 bool cam_ignore
, uint8_t priority
,
2401 uint32_t logic_serv
,
2402 XiveTCTXMatch
*match
)
2404 PnvMachineState
*pnv
= PNV_MACHINE(xfb
);
2405 int total_count
= 0;
2408 for (i
= 0; i
< pnv
->num_chips
; i
++) {
2409 Pnv10Chip
*chip10
= PNV10_CHIP(pnv
->chips
[i
]);
2410 XivePresenter
*xptr
= XIVE_PRESENTER(&chip10
->xive
);
2411 XivePresenterClass
*xpc
= XIVE_PRESENTER_GET_CLASS(xptr
);
2414 count
= xpc
->match_nvt(xptr
, format
, nvt_blk
, nvt_idx
, cam_ignore
,
2415 priority
, logic_serv
, match
);
2421 total_count
+= count
;
2427 static void pnv_machine_power8_class_init(ObjectClass
*oc
, void *data
)
2429 MachineClass
*mc
= MACHINE_CLASS(oc
);
2430 XICSFabricClass
*xic
= XICS_FABRIC_CLASS(oc
);
2431 PnvMachineClass
*pmc
= PNV_MACHINE_CLASS(oc
);
2432 static const char compat
[] = "qemu,powernv8\0qemu,powernv\0ibm,powernv";
2434 static GlobalProperty phb_compat
[] = {
2435 { TYPE_PNV_PHB
, "version", "3" },
2436 { TYPE_PNV_PHB_ROOT_PORT
, "version", "3" },
2439 mc
->desc
= "IBM PowerNV (Non-Virtualized) POWER8";
2440 mc
->default_cpu_type
= POWERPC_CPU_TYPE_NAME("power8_v2.0");
2441 compat_props_add(mc
->compat_props
, phb_compat
, G_N_ELEMENTS(phb_compat
));
2443 xic
->icp_get
= pnv_icp_get
;
2444 xic
->ics_get
= pnv_ics_get
;
2445 xic
->ics_resend
= pnv_ics_resend
;
2447 pmc
->compat
= compat
;
2448 pmc
->compat_size
= sizeof(compat
);
2450 machine_class_allow_dynamic_sysbus_dev(mc
, TYPE_PNV_PHB
);
2453 static void pnv_machine_power9_class_init(ObjectClass
*oc
, void *data
)
2455 MachineClass
*mc
= MACHINE_CLASS(oc
);
2456 XiveFabricClass
*xfc
= XIVE_FABRIC_CLASS(oc
);
2457 PnvMachineClass
*pmc
= PNV_MACHINE_CLASS(oc
);
2458 static const char compat
[] = "qemu,powernv9\0ibm,powernv";
2460 static GlobalProperty phb_compat
[] = {
2461 { TYPE_PNV_PHB
, "version", "4" },
2462 { TYPE_PNV_PHB_ROOT_PORT
, "version", "4" },
2465 mc
->desc
= "IBM PowerNV (Non-Virtualized) POWER9";
2466 mc
->default_cpu_type
= POWERPC_CPU_TYPE_NAME("power9_v2.2");
2467 compat_props_add(mc
->compat_props
, phb_compat
, G_N_ELEMENTS(phb_compat
));
2469 xfc
->match_nvt
= pnv_match_nvt
;
2471 pmc
->compat
= compat
;
2472 pmc
->compat_size
= sizeof(compat
);
2473 pmc
->dt_power_mgt
= pnv_dt_power_mgt
;
2475 machine_class_allow_dynamic_sysbus_dev(mc
, TYPE_PNV_PHB
);
2478 static void pnv_machine_p10_common_class_init(ObjectClass
*oc
, void *data
)
2480 MachineClass
*mc
= MACHINE_CLASS(oc
);
2481 PnvMachineClass
*pmc
= PNV_MACHINE_CLASS(oc
);
2482 XiveFabricClass
*xfc
= XIVE_FABRIC_CLASS(oc
);
2483 static const char compat
[] = "qemu,powernv10\0ibm,powernv";
2485 static GlobalProperty phb_compat
[] = {
2486 { TYPE_PNV_PHB
, "version", "5" },
2487 { TYPE_PNV_PHB_ROOT_PORT
, "version", "5" },
2490 mc
->default_cpu_type
= POWERPC_CPU_TYPE_NAME("power10_v2.0");
2491 compat_props_add(mc
->compat_props
, phb_compat
, G_N_ELEMENTS(phb_compat
));
2493 mc
->alias
= "powernv";
2495 pmc
->compat
= compat
;
2496 pmc
->compat_size
= sizeof(compat
);
2497 pmc
->dt_power_mgt
= pnv_dt_power_mgt
;
2499 xfc
->match_nvt
= pnv10_xive_match_nvt
;
2501 machine_class_allow_dynamic_sysbus_dev(mc
, TYPE_PNV_PHB
);
2504 static void pnv_machine_power10_class_init(ObjectClass
*oc
, void *data
)
2506 MachineClass
*mc
= MACHINE_CLASS(oc
);
2508 pnv_machine_p10_common_class_init(oc
, data
);
2509 mc
->desc
= "IBM PowerNV (Non-Virtualized) POWER10";
2512 static void pnv_machine_p10_rainier_class_init(ObjectClass
*oc
, void *data
)
2514 MachineClass
*mc
= MACHINE_CLASS(oc
);
2515 PnvMachineClass
*pmc
= PNV_MACHINE_CLASS(oc
);
2517 pnv_machine_p10_common_class_init(oc
, data
);
2518 mc
->desc
= "IBM PowerNV (Non-Virtualized) POWER10 Rainier";
2519 pmc
->i2c_init
= pnv_rainier_i2c_init
;
2522 static bool pnv_machine_get_hb(Object
*obj
, Error
**errp
)
2524 PnvMachineState
*pnv
= PNV_MACHINE(obj
);
2526 return !!pnv
->fw_load_addr
;
2529 static void pnv_machine_set_hb(Object
*obj
, bool value
, Error
**errp
)
2531 PnvMachineState
*pnv
= PNV_MACHINE(obj
);
2534 pnv
->fw_load_addr
= 0x8000000;
2538 static void pnv_cpu_do_nmi_on_cpu(CPUState
*cs
, run_on_cpu_data arg
)
2540 CPUPPCState
*env
= cpu_env(cs
);
2542 cpu_synchronize_state(cs
);
2543 ppc_cpu_do_system_reset(cs
);
2544 if (env
->spr
[SPR_SRR1
] & SRR1_WAKESTATE
) {
2546 * Power-save wakeups, as indicated by non-zero SRR1[46:47] put the
2547 * wakeup reason in SRR1[42:45], system reset is indicated with 0b0100
2550 if (!(env
->spr
[SPR_SRR1
] & SRR1_WAKERESET
)) {
2551 warn_report("ppc_cpu_do_system_reset does not set system reset wakeup reason");
2552 env
->spr
[SPR_SRR1
] |= SRR1_WAKERESET
;
2556 * For non-powersave system resets, SRR1[42:45] are defined to be
2557 * implementation-dependent. The POWER9 User Manual specifies that
2558 * an external (SCOM driven, which may come from a BMC nmi command or
2559 * another CPU requesting a NMI IPI) system reset exception should be
2560 * 0b0010 (PPC_BIT(44)).
2562 env
->spr
[SPR_SRR1
] |= SRR1_WAKESCOM
;
2566 static void pnv_cpu_do_nmi(PnvChip
*chip
, PowerPCCPU
*cpu
, void *opaque
)
2568 async_run_on_cpu(CPU(cpu
), pnv_cpu_do_nmi_on_cpu
, RUN_ON_CPU_NULL
);
2571 static void pnv_nmi(NMIState
*n
, int cpu_index
, Error
**errp
)
2573 PnvMachineState
*pnv
= PNV_MACHINE(qdev_get_machine());
2576 for (i
= 0; i
< pnv
->num_chips
; i
++) {
2577 pnv_chip_foreach_cpu(pnv
->chips
[i
], pnv_cpu_do_nmi
, NULL
);
2581 static void pnv_machine_class_init(ObjectClass
*oc
, void *data
)
2583 MachineClass
*mc
= MACHINE_CLASS(oc
);
2584 InterruptStatsProviderClass
*ispc
= INTERRUPT_STATS_PROVIDER_CLASS(oc
);
2585 NMIClass
*nc
= NMI_CLASS(oc
);
2587 mc
->desc
= "IBM PowerNV (Non-Virtualized)";
2588 mc
->init
= pnv_init
;
2589 mc
->reset
= pnv_reset
;
2590 mc
->max_cpus
= MAX_CPUS
;
2591 /* Pnv provides a AHCI device for storage */
2592 mc
->block_default_type
= IF_IDE
;
2593 mc
->no_parallel
= 1;
2594 mc
->default_boot_order
= NULL
;
2596 * RAM defaults to less than 2048 for 32-bit hosts, and large
2597 * enough to fit the maximum initrd size at it's load address
2599 mc
->default_ram_size
= 1 * GiB
;
2600 mc
->default_ram_id
= "pnv.ram";
2601 ispc
->print_info
= pnv_pic_print_info
;
2602 nc
->nmi_monitor_handler
= pnv_nmi
;
2604 object_class_property_add_bool(oc
, "hb-mode",
2605 pnv_machine_get_hb
, pnv_machine_set_hb
);
2606 object_class_property_set_description(oc
, "hb-mode",
2607 "Use a hostboot like boot loader");
2610 #define DEFINE_PNV8_CHIP_TYPE(type, class_initfn) \
2613 .class_init = class_initfn, \
2614 .parent = TYPE_PNV8_CHIP, \
2617 #define DEFINE_PNV9_CHIP_TYPE(type, class_initfn) \
2620 .class_init = class_initfn, \
2621 .parent = TYPE_PNV9_CHIP, \
2624 #define DEFINE_PNV10_CHIP_TYPE(type, class_initfn) \
2627 .class_init = class_initfn, \
2628 .parent = TYPE_PNV10_CHIP, \
2631 static const TypeInfo types
[] = {
2633 .name
= MACHINE_TYPE_NAME("powernv10-rainier"),
2634 .parent
= MACHINE_TYPE_NAME("powernv10"),
2635 .class_init
= pnv_machine_p10_rainier_class_init
,
2638 .name
= MACHINE_TYPE_NAME("powernv10"),
2639 .parent
= TYPE_PNV_MACHINE
,
2640 .class_init
= pnv_machine_power10_class_init
,
2641 .interfaces
= (InterfaceInfo
[]) {
2642 { TYPE_XIVE_FABRIC
},
2647 .name
= MACHINE_TYPE_NAME("powernv9"),
2648 .parent
= TYPE_PNV_MACHINE
,
2649 .class_init
= pnv_machine_power9_class_init
,
2650 .interfaces
= (InterfaceInfo
[]) {
2651 { TYPE_XIVE_FABRIC
},
2656 .name
= MACHINE_TYPE_NAME("powernv8"),
2657 .parent
= TYPE_PNV_MACHINE
,
2658 .class_init
= pnv_machine_power8_class_init
,
2659 .interfaces
= (InterfaceInfo
[]) {
2660 { TYPE_XICS_FABRIC
},
2665 .name
= TYPE_PNV_MACHINE
,
2666 .parent
= TYPE_MACHINE
,
2668 .instance_size
= sizeof(PnvMachineState
),
2669 .class_init
= pnv_machine_class_init
,
2670 .class_size
= sizeof(PnvMachineClass
),
2671 .interfaces
= (InterfaceInfo
[]) {
2672 { TYPE_INTERRUPT_STATS_PROVIDER
},
2678 .name
= TYPE_PNV_CHIP
,
2679 .parent
= TYPE_SYS_BUS_DEVICE
,
2680 .class_init
= pnv_chip_class_init
,
2681 .instance_size
= sizeof(PnvChip
),
2682 .class_size
= sizeof(PnvChipClass
),
2687 * P10 chip and variants
2690 .name
= TYPE_PNV10_CHIP
,
2691 .parent
= TYPE_PNV_CHIP
,
2692 .instance_init
= pnv_chip_power10_instance_init
,
2693 .instance_size
= sizeof(Pnv10Chip
),
2695 DEFINE_PNV10_CHIP_TYPE(TYPE_PNV_CHIP_POWER10
, pnv_chip_power10_class_init
),
2698 * P9 chip and variants
2701 .name
= TYPE_PNV9_CHIP
,
2702 .parent
= TYPE_PNV_CHIP
,
2703 .instance_init
= pnv_chip_power9_instance_init
,
2704 .instance_size
= sizeof(Pnv9Chip
),
2706 DEFINE_PNV9_CHIP_TYPE(TYPE_PNV_CHIP_POWER9
, pnv_chip_power9_class_init
),
2709 * P8 chip and variants
2712 .name
= TYPE_PNV8_CHIP
,
2713 .parent
= TYPE_PNV_CHIP
,
2714 .instance_init
= pnv_chip_power8_instance_init
,
2715 .instance_size
= sizeof(Pnv8Chip
),
2717 DEFINE_PNV8_CHIP_TYPE(TYPE_PNV_CHIP_POWER8
, pnv_chip_power8_class_init
),
2718 DEFINE_PNV8_CHIP_TYPE(TYPE_PNV_CHIP_POWER8E
, pnv_chip_power8e_class_init
),
2719 DEFINE_PNV8_CHIP_TYPE(TYPE_PNV_CHIP_POWER8NVL
,
2720 pnv_chip_power8nvl_class_init
),