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