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