]>
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" | |
21 | #include "qapi/error.h" | |
22 | #include "sysemu/sysemu.h" | |
23 | #include "sysemu/numa.h" | |
d2528bdc | 24 | #include "sysemu/cpus.h" |
9e933f4a | 25 | #include "hw/hw.h" |
fcf5ef2a | 26 | #include "target/ppc/cpu.h" |
9e933f4a BH |
27 | #include "qemu/log.h" |
28 | #include "hw/ppc/fdt.h" | |
29 | #include "hw/ppc/ppc.h" | |
30 | #include "hw/ppc/pnv.h" | |
d2fd9612 | 31 | #include "hw/ppc/pnv_core.h" |
9e933f4a BH |
32 | #include "hw/loader.h" |
33 | #include "exec/address-spaces.h" | |
34 | #include "qemu/cutils.h" | |
e997040e | 35 | #include "qapi/visitor.h" |
47fea43a CLG |
36 | #include "monitor/monitor.h" |
37 | #include "hw/intc/intc.h" | |
aeaef83d | 38 | #include "hw/ipmi/ipmi.h" |
58969eee | 39 | #include "target/ppc/mmu-hash64.h" |
9e933f4a | 40 | |
36fc6f08 | 41 | #include "hw/ppc/xics.h" |
967b7523 CLG |
42 | #include "hw/ppc/pnv_xscom.h" |
43 | ||
3495b6b6 CLG |
44 | #include "hw/isa/isa.h" |
45 | #include "hw/char/serial.h" | |
46 | #include "hw/timer/mc146818rtc.h" | |
47 | ||
9e933f4a BH |
48 | #include <libfdt.h> |
49 | ||
50 | #define FDT_MAX_SIZE 0x00100000 | |
51 | ||
52 | #define FW_FILE_NAME "skiboot.lid" | |
53 | #define FW_LOAD_ADDR 0x0 | |
54 | #define FW_MAX_SIZE 0x00400000 | |
55 | ||
56 | #define KERNEL_LOAD_ADDR 0x20000000 | |
fef592f9 | 57 | #define INITRD_LOAD_ADDR 0x60000000 |
9e933f4a | 58 | |
40abf43f IM |
59 | static const char *pnv_chip_core_typename(const PnvChip *o) |
60 | { | |
61 | const char *chip_type = object_class_get_name(object_get_class(OBJECT(o))); | |
62 | int len = strlen(chip_type) - strlen(PNV_CHIP_TYPE_SUFFIX); | |
63 | char *s = g_strdup_printf(PNV_CORE_TYPE_NAME("%.*s"), len, chip_type); | |
64 | const char *core_type = object_class_get_name(object_class_by_name(s)); | |
65 | g_free(s); | |
66 | return core_type; | |
67 | } | |
68 | ||
9e933f4a BH |
69 | /* |
70 | * On Power Systems E880 (POWER8), the max cpus (threads) should be : | |
71 | * 4 * 4 sockets * 12 cores * 8 threads = 1536 | |
72 | * Let's make it 2^11 | |
73 | */ | |
74 | #define MAX_CPUS 2048 | |
75 | ||
76 | /* | |
77 | * Memory nodes are created by hostboot, one for each range of memory | |
78 | * that has a different "affinity". In practice, it means one range | |
79 | * per chip. | |
80 | */ | |
b168a138 | 81 | static void pnv_dt_memory(void *fdt, int chip_id, hwaddr start, hwaddr size) |
9e933f4a BH |
82 | { |
83 | char *mem_name; | |
84 | uint64_t mem_reg_property[2]; | |
85 | int off; | |
86 | ||
87 | mem_reg_property[0] = cpu_to_be64(start); | |
88 | mem_reg_property[1] = cpu_to_be64(size); | |
89 | ||
90 | mem_name = g_strdup_printf("memory@%"HWADDR_PRIx, start); | |
91 | off = fdt_add_subnode(fdt, 0, mem_name); | |
92 | g_free(mem_name); | |
93 | ||
94 | _FDT((fdt_setprop_string(fdt, off, "device_type", "memory"))); | |
95 | _FDT((fdt_setprop(fdt, off, "reg", mem_reg_property, | |
96 | sizeof(mem_reg_property)))); | |
97 | _FDT((fdt_setprop_cell(fdt, off, "ibm,chip-id", chip_id))); | |
98 | } | |
99 | ||
d2fd9612 CLG |
100 | static int get_cpus_node(void *fdt) |
101 | { | |
102 | int cpus_offset = fdt_path_offset(fdt, "/cpus"); | |
103 | ||
104 | if (cpus_offset < 0) { | |
a4f3885c | 105 | cpus_offset = fdt_add_subnode(fdt, 0, "cpus"); |
d2fd9612 CLG |
106 | if (cpus_offset) { |
107 | _FDT((fdt_setprop_cell(fdt, cpus_offset, "#address-cells", 0x1))); | |
108 | _FDT((fdt_setprop_cell(fdt, cpus_offset, "#size-cells", 0x0))); | |
109 | } | |
110 | } | |
111 | _FDT(cpus_offset); | |
112 | return cpus_offset; | |
113 | } | |
114 | ||
115 | /* | |
116 | * The PowerNV cores (and threads) need to use real HW ids and not an | |
117 | * incremental index like it has been done on other platforms. This HW | |
118 | * id is stored in the CPU PIR, it is used to create cpu nodes in the | |
119 | * device tree, used in XSCOM to address cores and in interrupt | |
120 | * servers. | |
121 | */ | |
b168a138 | 122 | static void pnv_dt_core(PnvChip *chip, PnvCore *pc, void *fdt) |
d2fd9612 | 123 | { |
08304a86 DG |
124 | PowerPCCPU *cpu = pc->threads[0]; |
125 | CPUState *cs = CPU(cpu); | |
d2fd9612 | 126 | DeviceClass *dc = DEVICE_GET_CLASS(cs); |
8bd9530e | 127 | int smt_threads = CPU_CORE(pc)->nr_threads; |
d2fd9612 CLG |
128 | CPUPPCState *env = &cpu->env; |
129 | PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cs); | |
130 | uint32_t servers_prop[smt_threads]; | |
131 | int i; | |
132 | uint32_t segs[] = {cpu_to_be32(28), cpu_to_be32(40), | |
133 | 0xffffffff, 0xffffffff}; | |
134 | uint32_t tbfreq = PNV_TIMEBASE_FREQ; | |
135 | uint32_t cpufreq = 1000000000; | |
136 | uint32_t page_sizes_prop[64]; | |
137 | size_t page_sizes_prop_size; | |
138 | const uint8_t pa_features[] = { 24, 0, | |
139 | 0xf6, 0x3f, 0xc7, 0xc0, 0x80, 0xf0, | |
140 | 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, | |
141 | 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, | |
142 | 0x80, 0x00, 0x80, 0x00, 0x80, 0x00 }; | |
143 | int offset; | |
144 | char *nodename; | |
145 | int cpus_offset = get_cpus_node(fdt); | |
146 | ||
147 | nodename = g_strdup_printf("%s@%x", dc->fw_name, pc->pir); | |
148 | offset = fdt_add_subnode(fdt, cpus_offset, nodename); | |
149 | _FDT(offset); | |
150 | g_free(nodename); | |
151 | ||
152 | _FDT((fdt_setprop_cell(fdt, offset, "ibm,chip-id", chip->chip_id))); | |
153 | ||
154 | _FDT((fdt_setprop_cell(fdt, offset, "reg", pc->pir))); | |
155 | _FDT((fdt_setprop_cell(fdt, offset, "ibm,pir", pc->pir))); | |
156 | _FDT((fdt_setprop_string(fdt, offset, "device_type", "cpu"))); | |
157 | ||
158 | _FDT((fdt_setprop_cell(fdt, offset, "cpu-version", env->spr[SPR_PVR]))); | |
159 | _FDT((fdt_setprop_cell(fdt, offset, "d-cache-block-size", | |
160 | env->dcache_line_size))); | |
161 | _FDT((fdt_setprop_cell(fdt, offset, "d-cache-line-size", | |
162 | env->dcache_line_size))); | |
163 | _FDT((fdt_setprop_cell(fdt, offset, "i-cache-block-size", | |
164 | env->icache_line_size))); | |
165 | _FDT((fdt_setprop_cell(fdt, offset, "i-cache-line-size", | |
166 | env->icache_line_size))); | |
167 | ||
168 | if (pcc->l1_dcache_size) { | |
169 | _FDT((fdt_setprop_cell(fdt, offset, "d-cache-size", | |
170 | pcc->l1_dcache_size))); | |
171 | } else { | |
3dc6f869 | 172 | warn_report("Unknown L1 dcache size for cpu"); |
d2fd9612 CLG |
173 | } |
174 | if (pcc->l1_icache_size) { | |
175 | _FDT((fdt_setprop_cell(fdt, offset, "i-cache-size", | |
176 | pcc->l1_icache_size))); | |
177 | } else { | |
3dc6f869 | 178 | warn_report("Unknown L1 icache size for cpu"); |
d2fd9612 CLG |
179 | } |
180 | ||
181 | _FDT((fdt_setprop_cell(fdt, offset, "timebase-frequency", tbfreq))); | |
182 | _FDT((fdt_setprop_cell(fdt, offset, "clock-frequency", cpufreq))); | |
67d7d66f | 183 | _FDT((fdt_setprop_cell(fdt, offset, "ibm,slb-size", cpu->hash64_opts->slb_size))); |
d2fd9612 CLG |
184 | _FDT((fdt_setprop_string(fdt, offset, "status", "okay"))); |
185 | _FDT((fdt_setprop(fdt, offset, "64-bit", NULL, 0))); | |
186 | ||
187 | if (env->spr_cb[SPR_PURR].oea_read) { | |
188 | _FDT((fdt_setprop(fdt, offset, "ibm,purr", NULL, 0))); | |
189 | } | |
190 | ||
58969eee | 191 | if (ppc_hash64_has(cpu, PPC_HASH64_1TSEG)) { |
d2fd9612 CLG |
192 | _FDT((fdt_setprop(fdt, offset, "ibm,processor-segment-sizes", |
193 | segs, sizeof(segs)))); | |
194 | } | |
195 | ||
196 | /* Advertise VMX/VSX (vector extensions) if available | |
197 | * 0 / no property == no vector extensions | |
198 | * 1 == VMX / Altivec available | |
199 | * 2 == VSX available */ | |
200 | if (env->insns_flags & PPC_ALTIVEC) { | |
201 | uint32_t vmx = (env->insns_flags2 & PPC2_VSX) ? 2 : 1; | |
202 | ||
203 | _FDT((fdt_setprop_cell(fdt, offset, "ibm,vmx", vmx))); | |
204 | } | |
205 | ||
206 | /* Advertise DFP (Decimal Floating Point) if available | |
207 | * 0 / no property == no DFP | |
208 | * 1 == DFP available */ | |
209 | if (env->insns_flags2 & PPC2_DFP) { | |
210 | _FDT((fdt_setprop_cell(fdt, offset, "ibm,dfp", 1))); | |
211 | } | |
212 | ||
644a2c99 DG |
213 | page_sizes_prop_size = ppc_create_page_sizes_prop(cpu, page_sizes_prop, |
214 | sizeof(page_sizes_prop)); | |
d2fd9612 CLG |
215 | if (page_sizes_prop_size) { |
216 | _FDT((fdt_setprop(fdt, offset, "ibm,segment-page-sizes", | |
217 | page_sizes_prop, page_sizes_prop_size))); | |
218 | } | |
219 | ||
220 | _FDT((fdt_setprop(fdt, offset, "ibm,pa-features", | |
221 | pa_features, sizeof(pa_features)))); | |
222 | ||
d2fd9612 CLG |
223 | /* Build interrupt servers properties */ |
224 | for (i = 0; i < smt_threads; i++) { | |
225 | servers_prop[i] = cpu_to_be32(pc->pir + i); | |
226 | } | |
227 | _FDT((fdt_setprop(fdt, offset, "ibm,ppc-interrupt-server#s", | |
228 | servers_prop, sizeof(servers_prop)))); | |
229 | } | |
230 | ||
b168a138 CLG |
231 | static void pnv_dt_icp(PnvChip *chip, void *fdt, uint32_t pir, |
232 | uint32_t nr_threads) | |
bf5615e7 CLG |
233 | { |
234 | uint64_t addr = PNV_ICP_BASE(chip) | (pir << 12); | |
235 | char *name; | |
236 | const char compat[] = "IBM,power8-icp\0IBM,ppc-xicp"; | |
237 | uint32_t irange[2], i, rsize; | |
238 | uint64_t *reg; | |
239 | int offset; | |
240 | ||
241 | irange[0] = cpu_to_be32(pir); | |
242 | irange[1] = cpu_to_be32(nr_threads); | |
243 | ||
244 | rsize = sizeof(uint64_t) * 2 * nr_threads; | |
245 | reg = g_malloc(rsize); | |
246 | for (i = 0; i < nr_threads; i++) { | |
247 | reg[i * 2] = cpu_to_be64(addr | ((pir + i) * 0x1000)); | |
248 | reg[i * 2 + 1] = cpu_to_be64(0x1000); | |
249 | } | |
250 | ||
251 | name = g_strdup_printf("interrupt-controller@%"PRIX64, addr); | |
252 | offset = fdt_add_subnode(fdt, 0, name); | |
253 | _FDT(offset); | |
254 | g_free(name); | |
255 | ||
256 | _FDT((fdt_setprop(fdt, offset, "compatible", compat, sizeof(compat)))); | |
257 | _FDT((fdt_setprop(fdt, offset, "reg", reg, rsize))); | |
258 | _FDT((fdt_setprop_string(fdt, offset, "device_type", | |
259 | "PowerPC-External-Interrupt-Presentation"))); | |
260 | _FDT((fdt_setprop(fdt, offset, "interrupt-controller", NULL, 0))); | |
261 | _FDT((fdt_setprop(fdt, offset, "ibm,interrupt-server-ranges", | |
262 | irange, sizeof(irange)))); | |
263 | _FDT((fdt_setprop_cell(fdt, offset, "#interrupt-cells", 1))); | |
264 | _FDT((fdt_setprop_cell(fdt, offset, "#address-cells", 0))); | |
265 | g_free(reg); | |
266 | } | |
267 | ||
5a7e14a2 CLG |
268 | static int pnv_chip_lpc_offset(PnvChip *chip, void *fdt) |
269 | { | |
270 | char *name; | |
271 | int offset; | |
272 | ||
273 | name = g_strdup_printf("/xscom@%" PRIx64 "/isa@%x", | |
274 | (uint64_t) PNV_XSCOM_BASE(chip), PNV_XSCOM_LPC_BASE); | |
275 | offset = fdt_path_offset(fdt, name); | |
276 | g_free(name); | |
277 | return offset; | |
278 | } | |
279 | ||
b168a138 | 280 | static void pnv_dt_chip(PnvChip *chip, void *fdt) |
e997040e | 281 | { |
40abf43f | 282 | const char *typename = pnv_chip_core_typename(chip); |
d2fd9612 CLG |
283 | size_t typesize = object_type_get_instance_size(typename); |
284 | int i; | |
285 | ||
b168a138 | 286 | pnv_dt_xscom(chip, fdt, 0); |
967b7523 | 287 | |
5a7e14a2 CLG |
288 | /* The default LPC bus of a multichip system is on chip 0. It's |
289 | * recognized by the firmware (skiboot) using a "primary" | |
290 | * property. | |
291 | */ | |
292 | if (chip->chip_id == 0x0) { | |
293 | int lpc_offset = pnv_chip_lpc_offset(chip, fdt); | |
294 | ||
295 | _FDT((fdt_setprop(fdt, lpc_offset, "primary", NULL, 0))); | |
296 | } | |
297 | ||
d2fd9612 CLG |
298 | for (i = 0; i < chip->nr_cores; i++) { |
299 | PnvCore *pnv_core = PNV_CORE(chip->cores + i * typesize); | |
300 | ||
b168a138 | 301 | pnv_dt_core(chip, pnv_core, fdt); |
bf5615e7 CLG |
302 | |
303 | /* Interrupt Control Presenters (ICP). One per core. */ | |
b168a138 | 304 | pnv_dt_icp(chip, fdt, pnv_core->pir, CPU_CORE(pnv_core)->nr_threads); |
d2fd9612 CLG |
305 | } |
306 | ||
e997040e | 307 | if (chip->ram_size) { |
b168a138 | 308 | pnv_dt_memory(fdt, chip->chip_id, chip->ram_start, chip->ram_size); |
e997040e CLG |
309 | } |
310 | } | |
311 | ||
b168a138 | 312 | static void pnv_dt_rtc(ISADevice *d, void *fdt, int lpc_off) |
c5ffdcae CLG |
313 | { |
314 | uint32_t io_base = d->ioport_id; | |
315 | uint32_t io_regs[] = { | |
316 | cpu_to_be32(1), | |
317 | cpu_to_be32(io_base), | |
318 | cpu_to_be32(2) | |
319 | }; | |
320 | char *name; | |
321 | int node; | |
322 | ||
323 | name = g_strdup_printf("%s@i%x", qdev_fw_name(DEVICE(d)), io_base); | |
324 | node = fdt_add_subnode(fdt, lpc_off, name); | |
325 | _FDT(node); | |
326 | g_free(name); | |
327 | ||
328 | _FDT((fdt_setprop(fdt, node, "reg", io_regs, sizeof(io_regs)))); | |
329 | _FDT((fdt_setprop_string(fdt, node, "compatible", "pnpPNP,b00"))); | |
330 | } | |
331 | ||
b168a138 | 332 | static void pnv_dt_serial(ISADevice *d, void *fdt, int lpc_off) |
cb228f5a CLG |
333 | { |
334 | const char compatible[] = "ns16550\0pnpPNP,501"; | |
335 | uint32_t io_base = d->ioport_id; | |
336 | uint32_t io_regs[] = { | |
337 | cpu_to_be32(1), | |
338 | cpu_to_be32(io_base), | |
339 | cpu_to_be32(8) | |
340 | }; | |
341 | char *name; | |
342 | int node; | |
343 | ||
344 | name = g_strdup_printf("%s@i%x", qdev_fw_name(DEVICE(d)), io_base); | |
345 | node = fdt_add_subnode(fdt, lpc_off, name); | |
346 | _FDT(node); | |
347 | g_free(name); | |
348 | ||
349 | _FDT((fdt_setprop(fdt, node, "reg", io_regs, sizeof(io_regs)))); | |
350 | _FDT((fdt_setprop(fdt, node, "compatible", compatible, | |
351 | sizeof(compatible)))); | |
352 | ||
353 | _FDT((fdt_setprop_cell(fdt, node, "clock-frequency", 1843200))); | |
354 | _FDT((fdt_setprop_cell(fdt, node, "current-speed", 115200))); | |
355 | _FDT((fdt_setprop_cell(fdt, node, "interrupts", d->isairq[0]))); | |
356 | _FDT((fdt_setprop_cell(fdt, node, "interrupt-parent", | |
357 | fdt_get_phandle(fdt, lpc_off)))); | |
358 | ||
359 | /* This is needed by Linux */ | |
360 | _FDT((fdt_setprop_string(fdt, node, "device_type", "serial"))); | |
361 | } | |
362 | ||
b168a138 | 363 | static void pnv_dt_ipmi_bt(ISADevice *d, void *fdt, int lpc_off) |
04f6c8b2 CLG |
364 | { |
365 | const char compatible[] = "bt\0ipmi-bt"; | |
366 | uint32_t io_base; | |
367 | uint32_t io_regs[] = { | |
368 | cpu_to_be32(1), | |
369 | 0, /* 'io_base' retrieved from the 'ioport' property of 'isa-ipmi-bt' */ | |
370 | cpu_to_be32(3) | |
371 | }; | |
372 | uint32_t irq; | |
373 | char *name; | |
374 | int node; | |
375 | ||
376 | io_base = object_property_get_int(OBJECT(d), "ioport", &error_fatal); | |
377 | io_regs[1] = cpu_to_be32(io_base); | |
378 | ||
379 | irq = object_property_get_int(OBJECT(d), "irq", &error_fatal); | |
380 | ||
381 | name = g_strdup_printf("%s@i%x", qdev_fw_name(DEVICE(d)), io_base); | |
382 | node = fdt_add_subnode(fdt, lpc_off, name); | |
383 | _FDT(node); | |
384 | g_free(name); | |
385 | ||
7032d92a CLG |
386 | _FDT((fdt_setprop(fdt, node, "reg", io_regs, sizeof(io_regs)))); |
387 | _FDT((fdt_setprop(fdt, node, "compatible", compatible, | |
388 | sizeof(compatible)))); | |
04f6c8b2 CLG |
389 | |
390 | /* Mark it as reserved to avoid Linux trying to claim it */ | |
391 | _FDT((fdt_setprop_string(fdt, node, "status", "reserved"))); | |
392 | _FDT((fdt_setprop_cell(fdt, node, "interrupts", irq))); | |
393 | _FDT((fdt_setprop_cell(fdt, node, "interrupt-parent", | |
394 | fdt_get_phandle(fdt, lpc_off)))); | |
395 | } | |
396 | ||
e7a3fee3 CLG |
397 | typedef struct ForeachPopulateArgs { |
398 | void *fdt; | |
399 | int offset; | |
400 | } ForeachPopulateArgs; | |
401 | ||
b168a138 | 402 | static int pnv_dt_isa_device(DeviceState *dev, void *opaque) |
e7a3fee3 | 403 | { |
c5ffdcae CLG |
404 | ForeachPopulateArgs *args = opaque; |
405 | ISADevice *d = ISA_DEVICE(dev); | |
406 | ||
407 | if (object_dynamic_cast(OBJECT(dev), TYPE_MC146818_RTC)) { | |
b168a138 | 408 | pnv_dt_rtc(d, args->fdt, args->offset); |
cb228f5a | 409 | } else if (object_dynamic_cast(OBJECT(dev), TYPE_ISA_SERIAL)) { |
b168a138 | 410 | pnv_dt_serial(d, args->fdt, args->offset); |
04f6c8b2 | 411 | } else if (object_dynamic_cast(OBJECT(dev), "isa-ipmi-bt")) { |
b168a138 | 412 | pnv_dt_ipmi_bt(d, args->fdt, args->offset); |
c5ffdcae CLG |
413 | } else { |
414 | error_report("unknown isa device %s@i%x", qdev_fw_name(dev), | |
415 | d->ioport_id); | |
416 | } | |
417 | ||
e7a3fee3 CLG |
418 | return 0; |
419 | } | |
420 | ||
b168a138 | 421 | static void pnv_dt_isa(ISABus *bus, void *fdt, int lpc_offset) |
e7a3fee3 CLG |
422 | { |
423 | ForeachPopulateArgs args = { | |
424 | .fdt = fdt, | |
425 | .offset = lpc_offset, | |
426 | }; | |
427 | ||
428 | /* ISA devices are not necessarily parented to the ISA bus so we | |
429 | * can not use object_child_foreach() */ | |
b168a138 | 430 | qbus_walk_children(BUS(bus), pnv_dt_isa_device, NULL, NULL, NULL, &args); |
e7a3fee3 CLG |
431 | } |
432 | ||
b168a138 | 433 | static void *pnv_dt_create(MachineState *machine) |
9e933f4a BH |
434 | { |
435 | const char plat_compat[] = "qemu,powernv\0ibm,powernv"; | |
b168a138 | 436 | PnvMachineState *pnv = PNV_MACHINE(machine); |
9e933f4a BH |
437 | void *fdt; |
438 | char *buf; | |
439 | int off; | |
e997040e | 440 | int i; |
e7a3fee3 | 441 | int lpc_offset; |
9e933f4a BH |
442 | |
443 | fdt = g_malloc0(FDT_MAX_SIZE); | |
444 | _FDT((fdt_create_empty_tree(fdt, FDT_MAX_SIZE))); | |
445 | ||
446 | /* Root node */ | |
447 | _FDT((fdt_setprop_cell(fdt, 0, "#address-cells", 0x2))); | |
448 | _FDT((fdt_setprop_cell(fdt, 0, "#size-cells", 0x2))); | |
449 | _FDT((fdt_setprop_string(fdt, 0, "model", | |
450 | "IBM PowerNV (emulated by qemu)"))); | |
451 | _FDT((fdt_setprop(fdt, 0, "compatible", plat_compat, | |
452 | sizeof(plat_compat)))); | |
453 | ||
454 | buf = qemu_uuid_unparse_strdup(&qemu_uuid); | |
455 | _FDT((fdt_setprop_string(fdt, 0, "vm,uuid", buf))); | |
456 | if (qemu_uuid_set) { | |
457 | _FDT((fdt_property_string(fdt, "system-id", buf))); | |
458 | } | |
459 | g_free(buf); | |
460 | ||
461 | off = fdt_add_subnode(fdt, 0, "chosen"); | |
462 | if (machine->kernel_cmdline) { | |
463 | _FDT((fdt_setprop_string(fdt, off, "bootargs", | |
464 | machine->kernel_cmdline))); | |
465 | } | |
466 | ||
467 | if (pnv->initrd_size) { | |
468 | uint32_t start_prop = cpu_to_be32(pnv->initrd_base); | |
469 | uint32_t end_prop = cpu_to_be32(pnv->initrd_base + pnv->initrd_size); | |
470 | ||
471 | _FDT((fdt_setprop(fdt, off, "linux,initrd-start", | |
472 | &start_prop, sizeof(start_prop)))); | |
473 | _FDT((fdt_setprop(fdt, off, "linux,initrd-end", | |
474 | &end_prop, sizeof(end_prop)))); | |
475 | } | |
476 | ||
e997040e CLG |
477 | /* Populate device tree for each chip */ |
478 | for (i = 0; i < pnv->num_chips; i++) { | |
b168a138 | 479 | pnv_dt_chip(pnv->chips[i], fdt); |
e997040e | 480 | } |
e7a3fee3 CLG |
481 | |
482 | /* Populate ISA devices on chip 0 */ | |
483 | lpc_offset = pnv_chip_lpc_offset(pnv->chips[0], fdt); | |
b168a138 | 484 | pnv_dt_isa(pnv->isa_bus, fdt, lpc_offset); |
aeaef83d CLG |
485 | |
486 | if (pnv->bmc) { | |
b168a138 | 487 | pnv_dt_bmc_sensors(pnv->bmc, fdt); |
aeaef83d CLG |
488 | } |
489 | ||
9e933f4a BH |
490 | return fdt; |
491 | } | |
492 | ||
bce0b691 CLG |
493 | static void pnv_powerdown_notify(Notifier *n, void *opaque) |
494 | { | |
b168a138 | 495 | PnvMachineState *pnv = PNV_MACHINE(qdev_get_machine()); |
bce0b691 CLG |
496 | |
497 | if (pnv->bmc) { | |
498 | pnv_bmc_powerdown(pnv->bmc); | |
499 | } | |
500 | } | |
501 | ||
b168a138 | 502 | static void pnv_reset(void) |
9e933f4a BH |
503 | { |
504 | MachineState *machine = MACHINE(qdev_get_machine()); | |
b168a138 | 505 | PnvMachineState *pnv = PNV_MACHINE(machine); |
9e933f4a | 506 | void *fdt; |
aeaef83d | 507 | Object *obj; |
9e933f4a BH |
508 | |
509 | qemu_devices_reset(); | |
510 | ||
aeaef83d CLG |
511 | /* OpenPOWER systems have a BMC, which can be defined on the |
512 | * command line with: | |
513 | * | |
514 | * -device ipmi-bmc-sim,id=bmc0 | |
515 | * | |
516 | * This is the internal simulator but it could also be an external | |
517 | * BMC. | |
518 | */ | |
a1a636b8 | 519 | obj = object_resolve_path_type("", "ipmi-bmc-sim", NULL); |
aeaef83d CLG |
520 | if (obj) { |
521 | pnv->bmc = IPMI_BMC(obj); | |
522 | } | |
523 | ||
b168a138 | 524 | fdt = pnv_dt_create(machine); |
9e933f4a BH |
525 | |
526 | /* Pack resulting tree */ | |
527 | _FDT((fdt_pack(fdt))); | |
528 | ||
529 | cpu_physical_memory_write(PNV_FDT_ADDR, fdt, fdt_totalsize(fdt)); | |
530 | } | |
531 | ||
3495b6b6 CLG |
532 | static ISABus *pnv_isa_create(PnvChip *chip) |
533 | { | |
534 | PnvLpcController *lpc = &chip->lpc; | |
535 | ISABus *isa_bus; | |
536 | qemu_irq *irqs; | |
537 | PnvChipClass *pcc = PNV_CHIP_GET_CLASS(chip); | |
538 | ||
539 | /* let isa_bus_new() create its own bridge on SysBus otherwise | |
540 | * devices speficied on the command line won't find the bus and | |
541 | * will fail to create. | |
542 | */ | |
543 | isa_bus = isa_bus_new(NULL, &lpc->isa_mem, &lpc->isa_io, | |
544 | &error_fatal); | |
545 | ||
4d1df88b | 546 | irqs = pnv_lpc_isa_irq_create(lpc, pcc->chip_type, ISA_NUM_IRQS); |
3495b6b6 CLG |
547 | |
548 | isa_bus_irqs(isa_bus, irqs); | |
549 | return isa_bus; | |
550 | } | |
551 | ||
b168a138 | 552 | static void pnv_init(MachineState *machine) |
9e933f4a | 553 | { |
b168a138 | 554 | PnvMachineState *pnv = PNV_MACHINE(machine); |
9e933f4a BH |
555 | MemoryRegion *ram; |
556 | char *fw_filename; | |
557 | long fw_size; | |
e997040e CLG |
558 | int i; |
559 | char *chip_typename; | |
9e933f4a BH |
560 | |
561 | /* allocate RAM */ | |
562 | if (machine->ram_size < (1 * G_BYTE)) { | |
3dc6f869 | 563 | warn_report("skiboot may not work with < 1GB of RAM"); |
9e933f4a BH |
564 | } |
565 | ||
566 | ram = g_new(MemoryRegion, 1); | |
b168a138 | 567 | memory_region_allocate_system_memory(ram, NULL, "pnv.ram", |
9e933f4a BH |
568 | machine->ram_size); |
569 | memory_region_add_subregion(get_system_memory(), 0, ram); | |
570 | ||
571 | /* load skiboot firmware */ | |
572 | if (bios_name == NULL) { | |
573 | bios_name = FW_FILE_NAME; | |
574 | } | |
575 | ||
576 | fw_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name); | |
15fcedb2 CLG |
577 | if (!fw_filename) { |
578 | error_report("Could not find OPAL firmware '%s'", bios_name); | |
579 | exit(1); | |
580 | } | |
9e933f4a BH |
581 | |
582 | fw_size = load_image_targphys(fw_filename, FW_LOAD_ADDR, FW_MAX_SIZE); | |
583 | if (fw_size < 0) { | |
15fcedb2 | 584 | error_report("Could not load OPAL firmware '%s'", fw_filename); |
9e933f4a BH |
585 | exit(1); |
586 | } | |
587 | g_free(fw_filename); | |
588 | ||
589 | /* load kernel */ | |
590 | if (machine->kernel_filename) { | |
591 | long kernel_size; | |
592 | ||
593 | kernel_size = load_image_targphys(machine->kernel_filename, | |
594 | KERNEL_LOAD_ADDR, 0x2000000); | |
595 | if (kernel_size < 0) { | |
802fc7ab | 596 | error_report("Could not load kernel '%s'", |
7c6e8797 | 597 | machine->kernel_filename); |
9e933f4a BH |
598 | exit(1); |
599 | } | |
600 | } | |
601 | ||
602 | /* load initrd */ | |
603 | if (machine->initrd_filename) { | |
604 | pnv->initrd_base = INITRD_LOAD_ADDR; | |
605 | pnv->initrd_size = load_image_targphys(machine->initrd_filename, | |
606 | pnv->initrd_base, 0x10000000); /* 128MB max */ | |
607 | if (pnv->initrd_size < 0) { | |
802fc7ab | 608 | error_report("Could not load initial ram disk '%s'", |
9e933f4a BH |
609 | machine->initrd_filename); |
610 | exit(1); | |
611 | } | |
612 | } | |
e997040e | 613 | |
e997040e | 614 | /* Create the processor chips */ |
4a12c699 | 615 | i = strlen(machine->cpu_type) - strlen(POWERPC_CPU_TYPE_SUFFIX); |
7fd544d8 | 616 | chip_typename = g_strdup_printf(PNV_CHIP_TYPE_NAME("%.*s"), |
4a12c699 | 617 | i, machine->cpu_type); |
e997040e | 618 | if (!object_class_by_name(chip_typename)) { |
4a12c699 IM |
619 | error_report("invalid CPU model '%.*s' for %s machine", |
620 | i, machine->cpu_type, MACHINE_GET_CLASS(machine)->name); | |
e997040e CLG |
621 | exit(1); |
622 | } | |
623 | ||
624 | pnv->chips = g_new0(PnvChip *, pnv->num_chips); | |
625 | for (i = 0; i < pnv->num_chips; i++) { | |
626 | char chip_name[32]; | |
627 | Object *chip = object_new(chip_typename); | |
628 | ||
629 | pnv->chips[i] = PNV_CHIP(chip); | |
630 | ||
631 | /* TODO: put all the memory in one node on chip 0 until we find a | |
632 | * way to specify different ranges for each chip | |
633 | */ | |
634 | if (i == 0) { | |
635 | object_property_set_int(chip, machine->ram_size, "ram-size", | |
636 | &error_fatal); | |
637 | } | |
638 | ||
639 | snprintf(chip_name, sizeof(chip_name), "chip[%d]", PNV_CHIP_HWID(i)); | |
640 | object_property_add_child(OBJECT(pnv), chip_name, chip, &error_fatal); | |
641 | object_property_set_int(chip, PNV_CHIP_HWID(i), "chip-id", | |
642 | &error_fatal); | |
397a79e7 | 643 | object_property_set_int(chip, smp_cores, "nr-cores", &error_fatal); |
e997040e CLG |
644 | object_property_set_bool(chip, true, "realized", &error_fatal); |
645 | } | |
646 | g_free(chip_typename); | |
3495b6b6 CLG |
647 | |
648 | /* Instantiate ISA bus on chip 0 */ | |
649 | pnv->isa_bus = pnv_isa_create(pnv->chips[0]); | |
650 | ||
651 | /* Create serial port */ | |
def337ff | 652 | serial_hds_isa_init(pnv->isa_bus, 0, MAX_ISA_SERIAL_PORTS); |
3495b6b6 CLG |
653 | |
654 | /* Create an RTC ISA device too */ | |
6c646a11 | 655 | mc146818_rtc_init(pnv->isa_bus, 2000, NULL); |
bce0b691 CLG |
656 | |
657 | /* OpenPOWER systems use a IPMI SEL Event message to notify the | |
658 | * host to powerdown */ | |
659 | pnv->powerdown_notifier.notify = pnv_powerdown_notify; | |
660 | qemu_register_powerdown_notifier(&pnv->powerdown_notifier); | |
e997040e CLG |
661 | } |
662 | ||
631adaff CLG |
663 | /* |
664 | * 0:21 Reserved - Read as zeros | |
665 | * 22:24 Chip ID | |
666 | * 25:28 Core number | |
667 | * 29:31 Thread ID | |
668 | */ | |
669 | static uint32_t pnv_chip_core_pir_p8(PnvChip *chip, uint32_t core_id) | |
670 | { | |
671 | return (chip->chip_id << 7) | (core_id << 3); | |
672 | } | |
673 | ||
d35aefa9 CLG |
674 | static Object *pnv_chip_power8_intc_create(PnvChip *chip, Object *child, |
675 | Error **errp) | |
676 | { | |
677 | return icp_create(child, TYPE_PNV_ICP, XICS_FABRIC(qdev_get_machine()), | |
678 | errp); | |
679 | } | |
680 | ||
631adaff CLG |
681 | /* |
682 | * 0:48 Reserved - Read as zeroes | |
683 | * 49:52 Node ID | |
684 | * 53:55 Chip ID | |
685 | * 56 Reserved - Read as zero | |
686 | * 57:61 Core number | |
687 | * 62:63 Thread ID | |
688 | * | |
689 | * We only care about the lower bits. uint32_t is fine for the moment. | |
690 | */ | |
691 | static uint32_t pnv_chip_core_pir_p9(PnvChip *chip, uint32_t core_id) | |
692 | { | |
693 | return (chip->chip_id << 8) | (core_id << 2); | |
694 | } | |
695 | ||
d35aefa9 CLG |
696 | static Object *pnv_chip_power9_intc_create(PnvChip *chip, Object *child, |
697 | Error **errp) | |
698 | { | |
699 | return NULL; | |
700 | } | |
701 | ||
397a79e7 CLG |
702 | /* Allowed core identifiers on a POWER8 Processor Chip : |
703 | * | |
704 | * <EX0 reserved> | |
705 | * EX1 - Venice only | |
706 | * EX2 - Venice only | |
707 | * EX3 - Venice only | |
708 | * EX4 | |
709 | * EX5 | |
710 | * EX6 | |
711 | * <EX7,8 reserved> <reserved> | |
712 | * EX9 - Venice only | |
713 | * EX10 - Venice only | |
714 | * EX11 - Venice only | |
715 | * EX12 | |
716 | * EX13 | |
717 | * EX14 | |
718 | * <EX15 reserved> | |
719 | */ | |
720 | #define POWER8E_CORE_MASK (0x7070ull) | |
721 | #define POWER8_CORE_MASK (0x7e7eull) | |
722 | ||
723 | /* | |
09279d7e | 724 | * POWER9 has 24 cores, ids starting at 0x0 |
397a79e7 | 725 | */ |
09279d7e | 726 | #define POWER9_CORE_MASK (0xffffffffffffffull) |
397a79e7 | 727 | |
e997040e CLG |
728 | static void pnv_chip_power8e_class_init(ObjectClass *klass, void *data) |
729 | { | |
730 | DeviceClass *dc = DEVICE_CLASS(klass); | |
731 | PnvChipClass *k = PNV_CHIP_CLASS(klass); | |
732 | ||
e997040e CLG |
733 | k->chip_type = PNV_CHIP_POWER8E; |
734 | k->chip_cfam_id = 0x221ef04980000000ull; /* P8 Murano DD2.1 */ | |
397a79e7 | 735 | k->cores_mask = POWER8E_CORE_MASK; |
631adaff | 736 | k->core_pir = pnv_chip_core_pir_p8; |
d35aefa9 | 737 | k->intc_create = pnv_chip_power8_intc_create; |
967b7523 | 738 | k->xscom_base = 0x003fc0000000000ull; |
e997040e CLG |
739 | dc->desc = "PowerNV Chip POWER8E"; |
740 | } | |
741 | ||
e997040e CLG |
742 | static void pnv_chip_power8_class_init(ObjectClass *klass, void *data) |
743 | { | |
744 | DeviceClass *dc = DEVICE_CLASS(klass); | |
745 | PnvChipClass *k = PNV_CHIP_CLASS(klass); | |
746 | ||
e997040e CLG |
747 | k->chip_type = PNV_CHIP_POWER8; |
748 | k->chip_cfam_id = 0x220ea04980000000ull; /* P8 Venice DD2.0 */ | |
397a79e7 | 749 | k->cores_mask = POWER8_CORE_MASK; |
631adaff | 750 | k->core_pir = pnv_chip_core_pir_p8; |
d35aefa9 | 751 | k->intc_create = pnv_chip_power8_intc_create; |
967b7523 | 752 | k->xscom_base = 0x003fc0000000000ull; |
e997040e CLG |
753 | dc->desc = "PowerNV Chip POWER8"; |
754 | } | |
755 | ||
e997040e CLG |
756 | static void pnv_chip_power8nvl_class_init(ObjectClass *klass, void *data) |
757 | { | |
758 | DeviceClass *dc = DEVICE_CLASS(klass); | |
759 | PnvChipClass *k = PNV_CHIP_CLASS(klass); | |
760 | ||
e997040e CLG |
761 | k->chip_type = PNV_CHIP_POWER8NVL; |
762 | k->chip_cfam_id = 0x120d304980000000ull; /* P8 Naples DD1.0 */ | |
397a79e7 | 763 | k->cores_mask = POWER8_CORE_MASK; |
631adaff | 764 | k->core_pir = pnv_chip_core_pir_p8; |
d35aefa9 | 765 | k->intc_create = pnv_chip_power8_intc_create; |
967b7523 | 766 | k->xscom_base = 0x003fc0000000000ull; |
e997040e CLG |
767 | dc->desc = "PowerNV Chip POWER8NVL"; |
768 | } | |
769 | ||
e997040e CLG |
770 | static void pnv_chip_power9_class_init(ObjectClass *klass, void *data) |
771 | { | |
772 | DeviceClass *dc = DEVICE_CLASS(klass); | |
773 | PnvChipClass *k = PNV_CHIP_CLASS(klass); | |
774 | ||
e997040e | 775 | k->chip_type = PNV_CHIP_POWER9; |
83028a2b | 776 | k->chip_cfam_id = 0x220d104900008000ull; /* P9 Nimbus DD2.0 */ |
397a79e7 | 777 | k->cores_mask = POWER9_CORE_MASK; |
631adaff | 778 | k->core_pir = pnv_chip_core_pir_p9; |
d35aefa9 | 779 | k->intc_create = pnv_chip_power9_intc_create; |
967b7523 | 780 | k->xscom_base = 0x00603fc00000000ull; |
e997040e CLG |
781 | dc->desc = "PowerNV Chip POWER9"; |
782 | } | |
783 | ||
397a79e7 CLG |
784 | static void pnv_chip_core_sanitize(PnvChip *chip, Error **errp) |
785 | { | |
786 | PnvChipClass *pcc = PNV_CHIP_GET_CLASS(chip); | |
787 | int cores_max; | |
788 | ||
789 | /* | |
790 | * No custom mask for this chip, let's use the default one from * | |
791 | * the chip class | |
792 | */ | |
793 | if (!chip->cores_mask) { | |
794 | chip->cores_mask = pcc->cores_mask; | |
795 | } | |
796 | ||
797 | /* filter alien core ids ! some are reserved */ | |
798 | if ((chip->cores_mask & pcc->cores_mask) != chip->cores_mask) { | |
799 | error_setg(errp, "warning: invalid core mask for chip Ox%"PRIx64" !", | |
800 | chip->cores_mask); | |
801 | return; | |
802 | } | |
803 | chip->cores_mask &= pcc->cores_mask; | |
804 | ||
805 | /* now that we have a sane layout, let check the number of cores */ | |
27d9ffd4 | 806 | cores_max = ctpop64(chip->cores_mask); |
397a79e7 CLG |
807 | if (chip->nr_cores > cores_max) { |
808 | error_setg(errp, "warning: too many cores for chip ! Limit is %d", | |
809 | cores_max); | |
810 | return; | |
811 | } | |
812 | } | |
813 | ||
967b7523 CLG |
814 | static void pnv_chip_init(Object *obj) |
815 | { | |
816 | PnvChip *chip = PNV_CHIP(obj); | |
817 | PnvChipClass *pcc = PNV_CHIP_GET_CLASS(chip); | |
818 | ||
819 | chip->xscom_base = pcc->xscom_base; | |
a3980bf5 BH |
820 | |
821 | object_initialize(&chip->lpc, sizeof(chip->lpc), TYPE_PNV_LPC); | |
822 | object_property_add_child(obj, "lpc", OBJECT(&chip->lpc), NULL); | |
54f59d78 CLG |
823 | |
824 | object_initialize(&chip->psi, sizeof(chip->psi), TYPE_PNV_PSI); | |
825 | object_property_add_child(obj, "psi", OBJECT(&chip->psi), NULL); | |
826 | object_property_add_const_link(OBJECT(&chip->psi), "xics", | |
827 | OBJECT(qdev_get_machine()), &error_abort); | |
0722d05a BH |
828 | |
829 | object_initialize(&chip->occ, sizeof(chip->occ), TYPE_PNV_OCC); | |
830 | object_property_add_child(obj, "occ", OBJECT(&chip->occ), NULL); | |
831 | object_property_add_const_link(OBJECT(&chip->occ), "psi", | |
832 | OBJECT(&chip->psi), &error_abort); | |
4d1df88b BH |
833 | |
834 | /* The LPC controller needs PSI to generate interrupts */ | |
835 | object_property_add_const_link(OBJECT(&chip->lpc), "psi", | |
836 | OBJECT(&chip->psi), &error_abort); | |
967b7523 CLG |
837 | } |
838 | ||
bf5615e7 CLG |
839 | static void pnv_chip_icp_realize(PnvChip *chip, Error **errp) |
840 | { | |
841 | PnvChipClass *pcc = PNV_CHIP_GET_CLASS(chip); | |
40abf43f | 842 | const char *typename = pnv_chip_core_typename(chip); |
bf5615e7 CLG |
843 | size_t typesize = object_type_get_instance_size(typename); |
844 | int i, j; | |
845 | char *name; | |
846 | XICSFabric *xi = XICS_FABRIC(qdev_get_machine()); | |
847 | ||
848 | name = g_strdup_printf("icp-%x", chip->chip_id); | |
849 | memory_region_init(&chip->icp_mmio, OBJECT(chip), name, PNV_ICP_SIZE); | |
850 | sysbus_init_mmio(SYS_BUS_DEVICE(chip), &chip->icp_mmio); | |
851 | g_free(name); | |
852 | ||
853 | sysbus_mmio_map(SYS_BUS_DEVICE(chip), 1, PNV_ICP_BASE(chip)); | |
854 | ||
855 | /* Map the ICP registers for each thread */ | |
856 | for (i = 0; i < chip->nr_cores; i++) { | |
857 | PnvCore *pnv_core = PNV_CORE(chip->cores + i * typesize); | |
858 | int core_hwid = CPU_CORE(pnv_core)->core_id; | |
859 | ||
860 | for (j = 0; j < CPU_CORE(pnv_core)->nr_threads; j++) { | |
861 | uint32_t pir = pcc->core_pir(chip, core_hwid) + j; | |
862 | PnvICPState *icp = PNV_ICP(xics_icp_get(xi, pir)); | |
863 | ||
864 | memory_region_add_subregion(&chip->icp_mmio, pir << 12, &icp->mmio); | |
865 | } | |
866 | } | |
bf5615e7 CLG |
867 | } |
868 | ||
51c04728 | 869 | static void pnv_chip_core_realize(PnvChip *chip, Error **errp) |
e997040e | 870 | { |
397a79e7 | 871 | Error *error = NULL; |
d2fd9612 | 872 | PnvChipClass *pcc = PNV_CHIP_GET_CLASS(chip); |
40abf43f | 873 | const char *typename = pnv_chip_core_typename(chip); |
d2fd9612 CLG |
874 | size_t typesize = object_type_get_instance_size(typename); |
875 | int i, core_hwid; | |
876 | ||
877 | if (!object_class_by_name(typename)) { | |
878 | error_setg(errp, "Unable to find PowerNV CPU Core '%s'", typename); | |
879 | return; | |
880 | } | |
397a79e7 | 881 | |
d2fd9612 | 882 | /* Cores */ |
397a79e7 CLG |
883 | pnv_chip_core_sanitize(chip, &error); |
884 | if (error) { | |
885 | error_propagate(errp, error); | |
886 | return; | |
887 | } | |
d2fd9612 CLG |
888 | |
889 | chip->cores = g_malloc0(typesize * chip->nr_cores); | |
890 | ||
891 | for (i = 0, core_hwid = 0; (core_hwid < sizeof(chip->cores_mask) * 8) | |
892 | && (i < chip->nr_cores); core_hwid++) { | |
893 | char core_name[32]; | |
894 | void *pnv_core = chip->cores + i * typesize; | |
c035851a | 895 | uint64_t xscom_core_base; |
d2fd9612 CLG |
896 | |
897 | if (!(chip->cores_mask & (1ull << core_hwid))) { | |
898 | continue; | |
899 | } | |
900 | ||
901 | object_initialize(pnv_core, typesize, typename); | |
902 | snprintf(core_name, sizeof(core_name), "core[%d]", core_hwid); | |
903 | object_property_add_child(OBJECT(chip), core_name, OBJECT(pnv_core), | |
904 | &error_fatal); | |
905 | object_property_set_int(OBJECT(pnv_core), smp_threads, "nr-threads", | |
906 | &error_fatal); | |
907 | object_property_set_int(OBJECT(pnv_core), core_hwid, | |
908 | CPU_CORE_PROP_CORE_ID, &error_fatal); | |
909 | object_property_set_int(OBJECT(pnv_core), | |
910 | pcc->core_pir(chip, core_hwid), | |
911 | "pir", &error_fatal); | |
d35aefa9 CLG |
912 | object_property_add_const_link(OBJECT(pnv_core), "chip", |
913 | OBJECT(chip), &error_fatal); | |
d2fd9612 CLG |
914 | object_property_set_bool(OBJECT(pnv_core), true, "realized", |
915 | &error_fatal); | |
916 | object_unref(OBJECT(pnv_core)); | |
24ece072 CLG |
917 | |
918 | /* Each core has an XSCOM MMIO region */ | |
c035851a CLG |
919 | if (!pnv_chip_is_power9(chip)) { |
920 | xscom_core_base = PNV_XSCOM_EX_BASE(core_hwid); | |
921 | } else { | |
922 | xscom_core_base = PNV_XSCOM_P9_EC_BASE(core_hwid); | |
923 | } | |
924 | ||
925 | pnv_xscom_add_subregion(chip, xscom_core_base, | |
24ece072 | 926 | &PNV_CORE(pnv_core)->xscom_regs); |
d2fd9612 CLG |
927 | i++; |
928 | } | |
51c04728 CLG |
929 | } |
930 | ||
931 | static void pnv_chip_realize(DeviceState *dev, Error **errp) | |
932 | { | |
933 | PnvChip *chip = PNV_CHIP(dev); | |
934 | Error *error = NULL; | |
935 | ||
936 | /* XSCOM bridge */ | |
937 | pnv_xscom_realize(chip, &error); | |
938 | if (error) { | |
939 | error_propagate(errp, error); | |
940 | return; | |
941 | } | |
942 | sysbus_mmio_map(SYS_BUS_DEVICE(chip), 0, PNV_XSCOM_BASE(chip)); | |
943 | ||
944 | /* Cores */ | |
945 | pnv_chip_core_realize(chip, &error); | |
946 | if (error) { | |
947 | error_propagate(errp, error); | |
948 | return; | |
949 | } | |
a3980bf5 BH |
950 | |
951 | /* Create LPC controller */ | |
952 | object_property_set_bool(OBJECT(&chip->lpc), true, "realized", | |
953 | &error_fatal); | |
954 | pnv_xscom_add_subregion(chip, PNV_XSCOM_LPC_BASE, &chip->lpc.xscom_regs); | |
bf5615e7 CLG |
955 | |
956 | /* Interrupt Management Area. This is the memory region holding | |
957 | * all the Interrupt Control Presenter (ICP) registers */ | |
958 | pnv_chip_icp_realize(chip, &error); | |
959 | if (error) { | |
960 | error_propagate(errp, error); | |
961 | return; | |
962 | } | |
54f59d78 CLG |
963 | |
964 | /* Processor Service Interface (PSI) Host Bridge */ | |
965 | object_property_set_int(OBJECT(&chip->psi), PNV_PSIHB_BASE(chip), | |
966 | "bar", &error_fatal); | |
967 | object_property_set_bool(OBJECT(&chip->psi), true, "realized", &error); | |
968 | if (error) { | |
969 | error_propagate(errp, error); | |
970 | return; | |
971 | } | |
972 | pnv_xscom_add_subregion(chip, PNV_XSCOM_PSIHB_BASE, &chip->psi.xscom_regs); | |
0722d05a BH |
973 | |
974 | /* Create the simplified OCC model */ | |
975 | object_property_set_bool(OBJECT(&chip->occ), true, "realized", &error); | |
976 | if (error) { | |
977 | error_propagate(errp, error); | |
978 | return; | |
979 | } | |
980 | pnv_xscom_add_subregion(chip, PNV_XSCOM_OCC_BASE, &chip->occ.xscom_regs); | |
e997040e CLG |
981 | } |
982 | ||
983 | static Property pnv_chip_properties[] = { | |
984 | DEFINE_PROP_UINT32("chip-id", PnvChip, chip_id, 0), | |
985 | DEFINE_PROP_UINT64("ram-start", PnvChip, ram_start, 0), | |
986 | DEFINE_PROP_UINT64("ram-size", PnvChip, ram_size, 0), | |
397a79e7 CLG |
987 | DEFINE_PROP_UINT32("nr-cores", PnvChip, nr_cores, 1), |
988 | DEFINE_PROP_UINT64("cores-mask", PnvChip, cores_mask, 0x0), | |
e997040e CLG |
989 | DEFINE_PROP_END_OF_LIST(), |
990 | }; | |
991 | ||
992 | static void pnv_chip_class_init(ObjectClass *klass, void *data) | |
993 | { | |
994 | DeviceClass *dc = DEVICE_CLASS(klass); | |
995 | ||
9d169fb3 | 996 | set_bit(DEVICE_CATEGORY_CPU, dc->categories); |
e997040e CLG |
997 | dc->realize = pnv_chip_realize; |
998 | dc->props = pnv_chip_properties; | |
999 | dc->desc = "PowerNV Chip"; | |
1000 | } | |
1001 | ||
54f59d78 CLG |
1002 | static ICSState *pnv_ics_get(XICSFabric *xi, int irq) |
1003 | { | |
b168a138 | 1004 | PnvMachineState *pnv = PNV_MACHINE(xi); |
54f59d78 CLG |
1005 | int i; |
1006 | ||
1007 | for (i = 0; i < pnv->num_chips; i++) { | |
1008 | if (ics_valid_irq(&pnv->chips[i]->psi.ics, irq)) { | |
1009 | return &pnv->chips[i]->psi.ics; | |
1010 | } | |
1011 | } | |
1012 | return NULL; | |
1013 | } | |
1014 | ||
1015 | static void pnv_ics_resend(XICSFabric *xi) | |
1016 | { | |
b168a138 | 1017 | PnvMachineState *pnv = PNV_MACHINE(xi); |
54f59d78 CLG |
1018 | int i; |
1019 | ||
1020 | for (i = 0; i < pnv->num_chips; i++) { | |
1021 | ics_resend(&pnv->chips[i]->psi.ics); | |
1022 | } | |
1023 | } | |
1024 | ||
36fc6f08 CLG |
1025 | static PowerPCCPU *ppc_get_vcpu_by_pir(int pir) |
1026 | { | |
1027 | CPUState *cs; | |
1028 | ||
1029 | CPU_FOREACH(cs) { | |
1030 | PowerPCCPU *cpu = POWERPC_CPU(cs); | |
1031 | CPUPPCState *env = &cpu->env; | |
1032 | ||
1033 | if (env->spr_cb[SPR_PIR].default_value == pir) { | |
1034 | return cpu; | |
1035 | } | |
1036 | } | |
1037 | ||
1038 | return NULL; | |
1039 | } | |
1040 | ||
1041 | static ICPState *pnv_icp_get(XICSFabric *xi, int pir) | |
1042 | { | |
1043 | PowerPCCPU *cpu = ppc_get_vcpu_by_pir(pir); | |
1044 | ||
1045 | return cpu ? ICP(cpu->intc) : NULL; | |
1046 | } | |
1047 | ||
47fea43a CLG |
1048 | static void pnv_pic_print_info(InterruptStatsProvider *obj, |
1049 | Monitor *mon) | |
1050 | { | |
b168a138 | 1051 | PnvMachineState *pnv = PNV_MACHINE(obj); |
54f59d78 | 1052 | int i; |
47fea43a CLG |
1053 | CPUState *cs; |
1054 | ||
1055 | CPU_FOREACH(cs) { | |
1056 | PowerPCCPU *cpu = POWERPC_CPU(cs); | |
1057 | ||
1058 | icp_pic_print_info(ICP(cpu->intc), mon); | |
1059 | } | |
54f59d78 CLG |
1060 | |
1061 | for (i = 0; i < pnv->num_chips; i++) { | |
1062 | ics_pic_print_info(&pnv->chips[i]->psi.ics, mon); | |
1063 | } | |
47fea43a CLG |
1064 | } |
1065 | ||
e997040e CLG |
1066 | static void pnv_get_num_chips(Object *obj, Visitor *v, const char *name, |
1067 | void *opaque, Error **errp) | |
1068 | { | |
b168a138 | 1069 | visit_type_uint32(v, name, &PNV_MACHINE(obj)->num_chips, errp); |
e997040e CLG |
1070 | } |
1071 | ||
1072 | static void pnv_set_num_chips(Object *obj, Visitor *v, const char *name, | |
1073 | void *opaque, Error **errp) | |
1074 | { | |
b168a138 | 1075 | PnvMachineState *pnv = PNV_MACHINE(obj); |
e997040e CLG |
1076 | uint32_t num_chips; |
1077 | Error *local_err = NULL; | |
1078 | ||
1079 | visit_type_uint32(v, name, &num_chips, &local_err); | |
1080 | if (local_err) { | |
1081 | error_propagate(errp, local_err); | |
1082 | return; | |
1083 | } | |
1084 | ||
1085 | /* | |
1086 | * TODO: should we decide on how many chips we can create based | |
1087 | * on #cores and Venice vs. Murano vs. Naples chip type etc..., | |
1088 | */ | |
1089 | if (!is_power_of_2(num_chips) || num_chips > 4) { | |
1090 | error_setg(errp, "invalid number of chips: '%d'", num_chips); | |
1091 | return; | |
1092 | } | |
1093 | ||
1094 | pnv->num_chips = num_chips; | |
1095 | } | |
1096 | ||
b168a138 | 1097 | static void pnv_machine_initfn(Object *obj) |
e997040e | 1098 | { |
b168a138 | 1099 | PnvMachineState *pnv = PNV_MACHINE(obj); |
e997040e CLG |
1100 | pnv->num_chips = 1; |
1101 | } | |
1102 | ||
b168a138 | 1103 | static void pnv_machine_class_props_init(ObjectClass *oc) |
e997040e | 1104 | { |
1e507bb0 | 1105 | object_class_property_add(oc, "num-chips", "uint32", |
e997040e CLG |
1106 | pnv_get_num_chips, pnv_set_num_chips, |
1107 | NULL, NULL, NULL); | |
1108 | object_class_property_set_description(oc, "num-chips", | |
1109 | "Specifies the number of processor chips", | |
1110 | NULL); | |
9e933f4a BH |
1111 | } |
1112 | ||
b168a138 | 1113 | static void pnv_machine_class_init(ObjectClass *oc, void *data) |
9e933f4a BH |
1114 | { |
1115 | MachineClass *mc = MACHINE_CLASS(oc); | |
36fc6f08 | 1116 | XICSFabricClass *xic = XICS_FABRIC_CLASS(oc); |
47fea43a | 1117 | InterruptStatsProviderClass *ispc = INTERRUPT_STATS_PROVIDER_CLASS(oc); |
9e933f4a BH |
1118 | |
1119 | mc->desc = "IBM PowerNV (Non-Virtualized)"; | |
b168a138 CLG |
1120 | mc->init = pnv_init; |
1121 | mc->reset = pnv_reset; | |
9e933f4a | 1122 | mc->max_cpus = MAX_CPUS; |
4a12c699 | 1123 | mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("power8_v2.0"); |
9e933f4a BH |
1124 | mc->block_default_type = IF_IDE; /* Pnv provides a AHCI device for |
1125 | * storage */ | |
1126 | mc->no_parallel = 1; | |
1127 | mc->default_boot_order = NULL; | |
1128 | mc->default_ram_size = 1 * G_BYTE; | |
36fc6f08 | 1129 | xic->icp_get = pnv_icp_get; |
54f59d78 CLG |
1130 | xic->ics_get = pnv_ics_get; |
1131 | xic->ics_resend = pnv_ics_resend; | |
47fea43a | 1132 | ispc->print_info = pnv_pic_print_info; |
e997040e | 1133 | |
b168a138 | 1134 | pnv_machine_class_props_init(oc); |
9e933f4a BH |
1135 | } |
1136 | ||
beba5c0f IM |
1137 | #define DEFINE_PNV_CHIP_TYPE(type, class_initfn) \ |
1138 | { \ | |
1139 | .name = type, \ | |
1140 | .class_init = class_initfn, \ | |
1141 | .parent = TYPE_PNV_CHIP, \ | |
1142 | } | |
1143 | ||
1144 | static const TypeInfo types[] = { | |
1145 | { | |
b168a138 | 1146 | .name = TYPE_PNV_MACHINE, |
beba5c0f IM |
1147 | .parent = TYPE_MACHINE, |
1148 | .instance_size = sizeof(PnvMachineState), | |
b168a138 CLG |
1149 | .instance_init = pnv_machine_initfn, |
1150 | .class_init = pnv_machine_class_init, | |
beba5c0f IM |
1151 | .interfaces = (InterfaceInfo[]) { |
1152 | { TYPE_XICS_FABRIC }, | |
1153 | { TYPE_INTERRUPT_STATS_PROVIDER }, | |
1154 | { }, | |
1155 | }, | |
36fc6f08 | 1156 | }, |
beba5c0f IM |
1157 | { |
1158 | .name = TYPE_PNV_CHIP, | |
1159 | .parent = TYPE_SYS_BUS_DEVICE, | |
1160 | .class_init = pnv_chip_class_init, | |
1161 | .instance_init = pnv_chip_init, | |
1162 | .instance_size = sizeof(PnvChip), | |
1163 | .class_size = sizeof(PnvChipClass), | |
1164 | .abstract = true, | |
1165 | }, | |
1166 | DEFINE_PNV_CHIP_TYPE(TYPE_PNV_CHIP_POWER9, pnv_chip_power9_class_init), | |
1167 | DEFINE_PNV_CHIP_TYPE(TYPE_PNV_CHIP_POWER8, pnv_chip_power8_class_init), | |
1168 | DEFINE_PNV_CHIP_TYPE(TYPE_PNV_CHIP_POWER8E, pnv_chip_power8e_class_init), | |
1169 | DEFINE_PNV_CHIP_TYPE(TYPE_PNV_CHIP_POWER8NVL, | |
1170 | pnv_chip_power8nvl_class_init), | |
9e933f4a BH |
1171 | }; |
1172 | ||
beba5c0f | 1173 | DEFINE_TYPES(types) |