]>
Commit | Line | Data |
---|---|---|
9fdf0c29 DG |
1 | /* |
2 | * QEMU PowerPC pSeries Logical Partition (aka sPAPR) hardware System Emulator | |
3 | * | |
4 | * Copyright (c) 2004-2007 Fabrice Bellard | |
5 | * Copyright (c) 2007 Jocelyn Mayer | |
6 | * Copyright (c) 2010 David Gibson, IBM Corporation. | |
7 | * | |
8 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
9 | * of this software and associated documentation files (the "Software"), to deal | |
10 | * in the Software without restriction, including without limitation the rights | |
11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
12 | * copies of the Software, and to permit persons to whom the Software is | |
13 | * furnished to do so, subject to the following conditions: | |
14 | * | |
15 | * The above copyright notice and this permission notice shall be included in | |
16 | * all copies or substantial portions of the Software. | |
17 | * | |
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
21 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
24 | * THE SOFTWARE. | |
25 | * | |
26 | */ | |
27 | #include "sysemu.h" | |
9fdf0c29 DG |
28 | #include "hw.h" |
29 | #include "elf.h" | |
8d90ad90 | 30 | #include "net.h" |
6e270446 | 31 | #include "blockdev.h" |
e97c3636 DG |
32 | #include "cpus.h" |
33 | #include "kvm.h" | |
34 | #include "kvm_ppc.h" | |
9fdf0c29 DG |
35 | |
36 | #include "hw/boards.h" | |
37 | #include "hw/ppc.h" | |
38 | #include "hw/loader.h" | |
39 | ||
40 | #include "hw/spapr.h" | |
4040ab72 | 41 | #include "hw/spapr_vio.h" |
b5cec4c5 | 42 | #include "hw/xics.h" |
9fdf0c29 | 43 | |
f61b4bed AG |
44 | #include "kvm.h" |
45 | #include "kvm_ppc.h" | |
46 | ||
890c2b77 AK |
47 | #include "exec-memory.h" |
48 | ||
9fdf0c29 DG |
49 | #include <libfdt.h> |
50 | ||
51 | #define KERNEL_LOAD_ADDR 0x00000000 | |
52 | #define INITRD_LOAD_ADDR 0x02800000 | |
53 | #define FDT_MAX_SIZE 0x10000 | |
39ac8455 | 54 | #define RTAS_MAX_SIZE 0x10000 |
a9f8ad8f DG |
55 | #define FW_MAX_SIZE 0x400000 |
56 | #define FW_FILE_NAME "slof.bin" | |
57 | ||
58 | #define MIN_RAM_SLOF 512UL | |
9fdf0c29 DG |
59 | |
60 | #define TIMEBASE_FREQ 512000000ULL | |
61 | ||
41019fec | 62 | #define MAX_CPUS 256 |
b5cec4c5 | 63 | #define XICS_IRQS 1024 |
9fdf0c29 | 64 | |
0c103f8e DG |
65 | #define PHANDLE_XICP 0x00001111 |
66 | ||
9fdf0c29 DG |
67 | sPAPREnvironment *spapr; |
68 | ||
e6c866d4 DG |
69 | qemu_irq spapr_allocate_irq(uint32_t hint, uint32_t *irq_num) |
70 | { | |
71 | uint32_t irq; | |
72 | qemu_irq qirq; | |
73 | ||
74 | if (hint) { | |
75 | irq = hint; | |
76 | /* FIXME: we should probably check for collisions somehow */ | |
77 | } else { | |
78 | irq = spapr->next_irq++; | |
79 | } | |
80 | ||
81 | qirq = xics_find_qirq(spapr->icp, irq); | |
82 | if (!qirq) { | |
83 | return NULL; | |
84 | } | |
85 | ||
86 | if (irq_num) { | |
87 | *irq_num = irq; | |
88 | } | |
89 | ||
90 | return qirq; | |
91 | } | |
92 | ||
a3467baa DG |
93 | static void *spapr_create_fdt_skel(const char *cpu_model, |
94 | target_phys_addr_t initrd_base, | |
95 | target_phys_addr_t initrd_size, | |
96 | const char *boot_device, | |
97 | const char *kernel_cmdline, | |
98 | long hash_shift) | |
9fdf0c29 DG |
99 | { |
100 | void *fdt; | |
c7a5c0c9 | 101 | CPUState *env; |
a3467baa | 102 | uint64_t mem_reg_property[] = { 0, cpu_to_be64(ram_size) }; |
9fdf0c29 DG |
103 | uint32_t start_prop = cpu_to_be32(initrd_base); |
104 | uint32_t end_prop = cpu_to_be32(initrd_base + initrd_size); | |
f43e3525 | 105 | uint32_t pft_size_prop[] = {0, cpu_to_be32(hash_shift)}; |
ee86dfee | 106 | char hypertas_prop[] = "hcall-pft\0hcall-term\0hcall-dabr\0hcall-interrupt" |
a3d0abae | 107 | "\0hcall-tce\0hcall-vio\0hcall-splpar\0hcall-bulk"; |
b5cec4c5 | 108 | uint32_t interrupt_server_ranges_prop[] = {0, cpu_to_be32(smp_cpus)}; |
9fdf0c29 DG |
109 | int i; |
110 | char *modelname; | |
e97c3636 | 111 | int smt = kvmppc_smt_threads(); |
9fdf0c29 DG |
112 | |
113 | #define _FDT(exp) \ | |
114 | do { \ | |
115 | int ret = (exp); \ | |
116 | if (ret < 0) { \ | |
117 | fprintf(stderr, "qemu: error creating device tree: %s: %s\n", \ | |
118 | #exp, fdt_strerror(ret)); \ | |
119 | exit(1); \ | |
120 | } \ | |
121 | } while (0) | |
122 | ||
7267c094 | 123 | fdt = g_malloc0(FDT_MAX_SIZE); |
9fdf0c29 DG |
124 | _FDT((fdt_create(fdt, FDT_MAX_SIZE))); |
125 | ||
126 | _FDT((fdt_finish_reservemap(fdt))); | |
127 | ||
128 | /* Root node */ | |
129 | _FDT((fdt_begin_node(fdt, ""))); | |
130 | _FDT((fdt_property_string(fdt, "device_type", "chrp"))); | |
5d73dd66 | 131 | _FDT((fdt_property_string(fdt, "model", "IBM pSeries (emulated by qemu)"))); |
9fdf0c29 DG |
132 | |
133 | _FDT((fdt_property_cell(fdt, "#address-cells", 0x2))); | |
134 | _FDT((fdt_property_cell(fdt, "#size-cells", 0x2))); | |
135 | ||
136 | /* /chosen */ | |
137 | _FDT((fdt_begin_node(fdt, "chosen"))); | |
138 | ||
139 | _FDT((fdt_property_string(fdt, "bootargs", kernel_cmdline))); | |
140 | _FDT((fdt_property(fdt, "linux,initrd-start", | |
141 | &start_prop, sizeof(start_prop)))); | |
142 | _FDT((fdt_property(fdt, "linux,initrd-end", | |
143 | &end_prop, sizeof(end_prop)))); | |
a9f8ad8f | 144 | _FDT((fdt_property_string(fdt, "qemu,boot-device", boot_device))); |
9fdf0c29 DG |
145 | |
146 | _FDT((fdt_end_node(fdt))); | |
147 | ||
148 | /* memory node */ | |
149 | _FDT((fdt_begin_node(fdt, "memory@0"))); | |
150 | ||
151 | _FDT((fdt_property_string(fdt, "device_type", "memory"))); | |
152 | _FDT((fdt_property(fdt, "reg", | |
153 | mem_reg_property, sizeof(mem_reg_property)))); | |
154 | ||
155 | _FDT((fdt_end_node(fdt))); | |
156 | ||
157 | /* cpus */ | |
158 | _FDT((fdt_begin_node(fdt, "cpus"))); | |
159 | ||
160 | _FDT((fdt_property_cell(fdt, "#address-cells", 0x1))); | |
161 | _FDT((fdt_property_cell(fdt, "#size-cells", 0x0))); | |
162 | ||
7267c094 | 163 | modelname = g_strdup(cpu_model); |
9fdf0c29 DG |
164 | |
165 | for (i = 0; i < strlen(modelname); i++) { | |
166 | modelname[i] = toupper(modelname[i]); | |
167 | } | |
168 | ||
c7a5c0c9 DG |
169 | for (env = first_cpu; env != NULL; env = env->next_cpu) { |
170 | int index = env->cpu_index; | |
e97c3636 DG |
171 | uint32_t servers_prop[smp_threads]; |
172 | uint32_t gservers_prop[smp_threads * 2]; | |
9fdf0c29 DG |
173 | char *nodename; |
174 | uint32_t segs[] = {cpu_to_be32(28), cpu_to_be32(40), | |
175 | 0xffffffff, 0xffffffff}; | |
0a8b2938 AG |
176 | uint32_t tbfreq = kvm_enabled() ? kvmppc_get_tbfreq() : TIMEBASE_FREQ; |
177 | uint32_t cpufreq = kvm_enabled() ? kvmppc_get_clockfreq() : 1000000000; | |
9fdf0c29 | 178 | |
e97c3636 DG |
179 | if ((index % smt) != 0) { |
180 | continue; | |
181 | } | |
182 | ||
c7a5c0c9 | 183 | if (asprintf(&nodename, "%s@%x", modelname, index) < 0) { |
9fdf0c29 DG |
184 | fprintf(stderr, "Allocation failure\n"); |
185 | exit(1); | |
186 | } | |
187 | ||
188 | _FDT((fdt_begin_node(fdt, nodename))); | |
189 | ||
190 | free(nodename); | |
191 | ||
c7a5c0c9 | 192 | _FDT((fdt_property_cell(fdt, "reg", index))); |
9fdf0c29 DG |
193 | _FDT((fdt_property_string(fdt, "device_type", "cpu"))); |
194 | ||
195 | _FDT((fdt_property_cell(fdt, "cpu-version", env->spr[SPR_PVR]))); | |
196 | _FDT((fdt_property_cell(fdt, "dcache-block-size", | |
197 | env->dcache_line_size))); | |
198 | _FDT((fdt_property_cell(fdt, "icache-block-size", | |
199 | env->icache_line_size))); | |
0a8b2938 AG |
200 | _FDT((fdt_property_cell(fdt, "timebase-frequency", tbfreq))); |
201 | _FDT((fdt_property_cell(fdt, "clock-frequency", cpufreq))); | |
9fdf0c29 | 202 | _FDT((fdt_property_cell(fdt, "ibm,slb-size", env->slb_nr))); |
f43e3525 DG |
203 | _FDT((fdt_property(fdt, "ibm,pft-size", |
204 | pft_size_prop, sizeof(pft_size_prop)))); | |
9fdf0c29 DG |
205 | _FDT((fdt_property_string(fdt, "status", "okay"))); |
206 | _FDT((fdt_property(fdt, "64-bit", NULL, 0))); | |
e97c3636 DG |
207 | |
208 | /* Build interrupt servers and gservers properties */ | |
209 | for (i = 0; i < smp_threads; i++) { | |
210 | servers_prop[i] = cpu_to_be32(index + i); | |
211 | /* Hack, direct the group queues back to cpu 0 */ | |
212 | gservers_prop[i*2] = cpu_to_be32(index + i); | |
213 | gservers_prop[i*2 + 1] = 0; | |
214 | } | |
215 | _FDT((fdt_property(fdt, "ibm,ppc-interrupt-server#s", | |
216 | servers_prop, sizeof(servers_prop)))); | |
b5cec4c5 | 217 | _FDT((fdt_property(fdt, "ibm,ppc-interrupt-gserver#s", |
e97c3636 | 218 | gservers_prop, sizeof(gservers_prop)))); |
9fdf0c29 | 219 | |
c7a5c0c9 | 220 | if (env->mmu_model & POWERPC_MMU_1TSEG) { |
9fdf0c29 DG |
221 | _FDT((fdt_property(fdt, "ibm,processor-segment-sizes", |
222 | segs, sizeof(segs)))); | |
223 | } | |
224 | ||
225 | _FDT((fdt_end_node(fdt))); | |
226 | } | |
227 | ||
7267c094 | 228 | g_free(modelname); |
9fdf0c29 DG |
229 | |
230 | _FDT((fdt_end_node(fdt))); | |
231 | ||
f43e3525 DG |
232 | /* RTAS */ |
233 | _FDT((fdt_begin_node(fdt, "rtas"))); | |
234 | ||
235 | _FDT((fdt_property(fdt, "ibm,hypertas-functions", hypertas_prop, | |
236 | sizeof(hypertas_prop)))); | |
237 | ||
238 | _FDT((fdt_end_node(fdt))); | |
239 | ||
b5cec4c5 | 240 | /* interrupt controller */ |
9dfef5aa | 241 | _FDT((fdt_begin_node(fdt, "interrupt-controller"))); |
b5cec4c5 DG |
242 | |
243 | _FDT((fdt_property_string(fdt, "device_type", | |
244 | "PowerPC-External-Interrupt-Presentation"))); | |
245 | _FDT((fdt_property_string(fdt, "compatible", "IBM,ppc-xicp"))); | |
b5cec4c5 DG |
246 | _FDT((fdt_property(fdt, "interrupt-controller", NULL, 0))); |
247 | _FDT((fdt_property(fdt, "ibm,interrupt-server-ranges", | |
248 | interrupt_server_ranges_prop, | |
249 | sizeof(interrupt_server_ranges_prop)))); | |
0c103f8e DG |
250 | _FDT((fdt_property_cell(fdt, "#interrupt-cells", 2))); |
251 | _FDT((fdt_property_cell(fdt, "linux,phandle", PHANDLE_XICP))); | |
252 | _FDT((fdt_property_cell(fdt, "phandle", PHANDLE_XICP))); | |
b5cec4c5 DG |
253 | |
254 | _FDT((fdt_end_node(fdt))); | |
255 | ||
4040ab72 DG |
256 | /* vdevice */ |
257 | _FDT((fdt_begin_node(fdt, "vdevice"))); | |
258 | ||
259 | _FDT((fdt_property_string(fdt, "device_type", "vdevice"))); | |
260 | _FDT((fdt_property_string(fdt, "compatible", "IBM,vdevice"))); | |
261 | _FDT((fdt_property_cell(fdt, "#address-cells", 0x1))); | |
262 | _FDT((fdt_property_cell(fdt, "#size-cells", 0x0))); | |
b5cec4c5 DG |
263 | _FDT((fdt_property_cell(fdt, "#interrupt-cells", 0x2))); |
264 | _FDT((fdt_property(fdt, "interrupt-controller", NULL, 0))); | |
4040ab72 DG |
265 | |
266 | _FDT((fdt_end_node(fdt))); | |
267 | ||
9fdf0c29 DG |
268 | _FDT((fdt_end_node(fdt))); /* close root node */ |
269 | _FDT((fdt_finish(fdt))); | |
270 | ||
a3467baa DG |
271 | return fdt; |
272 | } | |
273 | ||
274 | static void spapr_finalize_fdt(sPAPREnvironment *spapr, | |
275 | target_phys_addr_t fdt_addr, | |
276 | target_phys_addr_t rtas_addr, | |
277 | target_phys_addr_t rtas_size) | |
278 | { | |
279 | int ret; | |
280 | void *fdt; | |
281 | ||
7267c094 | 282 | fdt = g_malloc(FDT_MAX_SIZE); |
a3467baa DG |
283 | |
284 | /* open out the base tree into a temp buffer for the final tweaks */ | |
285 | _FDT((fdt_open_into(spapr->fdt_skel, fdt, FDT_MAX_SIZE))); | |
4040ab72 DG |
286 | |
287 | ret = spapr_populate_vdevice(spapr->vio_bus, fdt); | |
288 | if (ret < 0) { | |
289 | fprintf(stderr, "couldn't setup vio devices in fdt\n"); | |
290 | exit(1); | |
291 | } | |
292 | ||
39ac8455 DG |
293 | /* RTAS */ |
294 | ret = spapr_rtas_device_tree_setup(fdt, rtas_addr, rtas_size); | |
295 | if (ret < 0) { | |
296 | fprintf(stderr, "Couldn't set up RTAS device tree properties\n"); | |
297 | } | |
298 | ||
4040ab72 DG |
299 | _FDT((fdt_pack(fdt))); |
300 | ||
a3467baa | 301 | cpu_physical_memory_write(fdt_addr, fdt, fdt_totalsize(fdt)); |
9fdf0c29 | 302 | |
7267c094 | 303 | g_free(fdt); |
9fdf0c29 DG |
304 | } |
305 | ||
306 | static uint64_t translate_kernel_address(void *opaque, uint64_t addr) | |
307 | { | |
308 | return (addr & 0x0fffffff) + KERNEL_LOAD_ADDR; | |
309 | } | |
310 | ||
311 | static void emulate_spapr_hypercall(CPUState *env) | |
312 | { | |
313 | env->gpr[3] = spapr_hypercall(env, env->gpr[3], &env->gpr[4]); | |
314 | } | |
315 | ||
a3467baa DG |
316 | static void spapr_reset(void *opaque) |
317 | { | |
318 | sPAPREnvironment *spapr = (sPAPREnvironment *)opaque; | |
319 | ||
320 | fprintf(stderr, "sPAPR reset\n"); | |
321 | ||
322 | /* flush out the hash table */ | |
323 | memset(spapr->htab, 0, spapr->htab_size); | |
324 | ||
325 | /* Load the fdt */ | |
326 | spapr_finalize_fdt(spapr, spapr->fdt_addr, spapr->rtas_addr, | |
327 | spapr->rtas_size); | |
328 | ||
329 | /* Set up the entry state */ | |
330 | first_cpu->gpr[3] = spapr->fdt_addr; | |
331 | first_cpu->gpr[5] = 0; | |
332 | first_cpu->halted = 0; | |
333 | first_cpu->nip = spapr->entry_point; | |
334 | ||
335 | } | |
336 | ||
9fdf0c29 DG |
337 | /* pSeries LPAR / sPAPR hardware init */ |
338 | static void ppc_spapr_init(ram_addr_t ram_size, | |
339 | const char *boot_device, | |
340 | const char *kernel_filename, | |
341 | const char *kernel_cmdline, | |
342 | const char *initrd_filename, | |
343 | const char *cpu_model) | |
344 | { | |
c7a5c0c9 | 345 | CPUState *env; |
9fdf0c29 | 346 | int i; |
890c2b77 AK |
347 | MemoryRegion *sysmem = get_system_memory(); |
348 | MemoryRegion *ram = g_new(MemoryRegion, 1); | |
a3467baa DG |
349 | uint32_t initrd_base; |
350 | long kernel_size, initrd_size, fw_size; | |
f43e3525 | 351 | long pteg_shift = 17; |
39ac8455 | 352 | char *filename; |
9fdf0c29 | 353 | |
7267c094 | 354 | spapr = g_malloc(sizeof(*spapr)); |
9fdf0c29 DG |
355 | cpu_ppc_hypercall = emulate_spapr_hypercall; |
356 | ||
357 | /* We place the device tree just below either the top of RAM, or | |
358 | * 2GB, so that it can be processed with 32-bit code if | |
359 | * necessary */ | |
a3467baa DG |
360 | spapr->fdt_addr = MIN(ram_size, 0x80000000) - FDT_MAX_SIZE; |
361 | spapr->rtas_addr = spapr->fdt_addr - RTAS_MAX_SIZE; | |
9fdf0c29 DG |
362 | |
363 | /* init CPUs */ | |
364 | if (cpu_model == NULL) { | |
365 | cpu_model = "POWER7"; | |
366 | } | |
367 | for (i = 0; i < smp_cpus; i++) { | |
c7a5c0c9 | 368 | env = cpu_init(cpu_model); |
9fdf0c29 DG |
369 | |
370 | if (!env) { | |
371 | fprintf(stderr, "Unable to find PowerPC CPU definition\n"); | |
372 | exit(1); | |
373 | } | |
374 | /* Set time-base frequency to 512 MHz */ | |
375 | cpu_ppc_tb_init(env, TIMEBASE_FREQ); | |
376 | qemu_register_reset((QEMUResetHandler *)&cpu_reset, env); | |
377 | ||
378 | env->hreset_vector = 0x60; | |
379 | env->hreset_excp_prefix = 0; | |
c7a5c0c9 | 380 | env->gpr[3] = env->cpu_index; |
9fdf0c29 DG |
381 | } |
382 | ||
383 | /* allocate RAM */ | |
f73a2575 | 384 | spapr->ram_limit = ram_size; |
890c2b77 AK |
385 | memory_region_init_ram(ram, NULL, "ppc_spapr.ram", spapr->ram_limit); |
386 | memory_region_add_subregion(sysmem, 0, ram); | |
9fdf0c29 | 387 | |
f43e3525 DG |
388 | /* allocate hash page table. For now we always make this 16mb, |
389 | * later we should probably make it scale to the size of guest | |
390 | * RAM */ | |
a3467baa | 391 | spapr->htab_size = 1ULL << (pteg_shift + 7); |
f61b4bed | 392 | spapr->htab = qemu_memalign(spapr->htab_size, spapr->htab_size); |
f43e3525 | 393 | |
c7a5c0c9 | 394 | for (env = first_cpu; env != NULL; env = env->next_cpu) { |
a3467baa | 395 | env->external_htab = spapr->htab; |
c7a5c0c9 | 396 | env->htab_base = -1; |
a3467baa | 397 | env->htab_mask = spapr->htab_size - 1; |
f61b4bed AG |
398 | |
399 | /* Tell KVM that we're in PAPR mode */ | |
400 | env->spr[SPR_SDR1] = (unsigned long)spapr->htab | | |
401 | ((pteg_shift + 7) - 18); | |
402 | env->spr[SPR_HIOR] = 0; | |
403 | ||
404 | if (kvm_enabled()) { | |
405 | kvmppc_set_papr(env); | |
406 | } | |
f43e3525 DG |
407 | } |
408 | ||
39ac8455 | 409 | filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, "spapr-rtas.bin"); |
a3467baa DG |
410 | spapr->rtas_size = load_image_targphys(filename, spapr->rtas_addr, |
411 | ram_size - spapr->rtas_addr); | |
412 | if (spapr->rtas_size < 0) { | |
39ac8455 DG |
413 | hw_error("qemu: could not load LPAR rtas '%s'\n", filename); |
414 | exit(1); | |
415 | } | |
7267c094 | 416 | g_free(filename); |
39ac8455 | 417 | |
b5cec4c5 | 418 | /* Set up Interrupt Controller */ |
c7a5c0c9 | 419 | spapr->icp = xics_system_init(XICS_IRQS); |
e6c866d4 | 420 | spapr->next_irq = 16; |
b5cec4c5 DG |
421 | |
422 | /* Set up VIO bus */ | |
4040ab72 DG |
423 | spapr->vio_bus = spapr_vio_bus_init(); |
424 | ||
277f9acf | 425 | for (i = 0; i < MAX_SERIAL_PORTS; i++) { |
4040ab72 | 426 | if (serial_hds[i]) { |
b4a78527 | 427 | spapr_vty_create(spapr->vio_bus, SPAPR_VTY_BASE_ADDRESS + i, |
277f9acf | 428 | serial_hds[i]); |
4040ab72 DG |
429 | } |
430 | } | |
9fdf0c29 | 431 | |
277f9acf | 432 | for (i = 0; i < nb_nics; i++) { |
8d90ad90 DG |
433 | NICInfo *nd = &nd_table[i]; |
434 | ||
435 | if (!nd->model) { | |
7267c094 | 436 | nd->model = g_strdup("ibmveth"); |
8d90ad90 DG |
437 | } |
438 | ||
439 | if (strcmp(nd->model, "ibmveth") == 0) { | |
277f9acf | 440 | spapr_vlan_create(spapr->vio_bus, 0x1000 + i, nd); |
8d90ad90 DG |
441 | } else { |
442 | fprintf(stderr, "pSeries (sPAPR) platform does not support " | |
443 | "NIC model '%s' (only ibmveth is supported)\n", | |
444 | nd->model); | |
445 | exit(1); | |
446 | } | |
447 | } | |
448 | ||
6e270446 | 449 | for (i = 0; i <= drive_get_max_bus(IF_SCSI); i++) { |
277f9acf | 450 | spapr_vscsi_create(spapr->vio_bus, 0x2000 + i); |
6e270446 BH |
451 | } |
452 | ||
9fdf0c29 DG |
453 | if (kernel_filename) { |
454 | uint64_t lowaddr = 0; | |
455 | ||
9fdf0c29 DG |
456 | kernel_size = load_elf(kernel_filename, translate_kernel_address, NULL, |
457 | NULL, &lowaddr, NULL, 1, ELF_MACHINE, 0); | |
458 | if (kernel_size < 0) { | |
a3467baa DG |
459 | kernel_size = load_image_targphys(kernel_filename, |
460 | KERNEL_LOAD_ADDR, | |
461 | ram_size - KERNEL_LOAD_ADDR); | |
9fdf0c29 DG |
462 | } |
463 | if (kernel_size < 0) { | |
464 | fprintf(stderr, "qemu: could not load kernel '%s'\n", | |
465 | kernel_filename); | |
466 | exit(1); | |
467 | } | |
468 | ||
469 | /* load initrd */ | |
470 | if (initrd_filename) { | |
471 | initrd_base = INITRD_LOAD_ADDR; | |
472 | initrd_size = load_image_targphys(initrd_filename, initrd_base, | |
473 | ram_size - initrd_base); | |
474 | if (initrd_size < 0) { | |
475 | fprintf(stderr, "qemu: could not load initial ram disk '%s'\n", | |
476 | initrd_filename); | |
477 | exit(1); | |
478 | } | |
479 | } else { | |
480 | initrd_base = 0; | |
481 | initrd_size = 0; | |
482 | } | |
a3467baa DG |
483 | |
484 | spapr->entry_point = KERNEL_LOAD_ADDR; | |
9fdf0c29 | 485 | } else { |
a9f8ad8f DG |
486 | if (ram_size < (MIN_RAM_SLOF << 20)) { |
487 | fprintf(stderr, "qemu: pSeries SLOF firmware requires >= " | |
488 | "%ldM guest RAM\n", MIN_RAM_SLOF); | |
489 | exit(1); | |
490 | } | |
68722054 | 491 | filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, FW_FILE_NAME); |
a9f8ad8f DG |
492 | fw_size = load_image_targphys(filename, 0, FW_MAX_SIZE); |
493 | if (fw_size < 0) { | |
494 | hw_error("qemu: could not load LPAR rtas '%s'\n", filename); | |
495 | exit(1); | |
496 | } | |
7267c094 | 497 | g_free(filename); |
a3467baa | 498 | spapr->entry_point = 0x100; |
a9f8ad8f DG |
499 | initrd_base = 0; |
500 | initrd_size = 0; | |
501 | ||
502 | /* SLOF will startup the secondary CPUs using RTAS, | |
503 | rather than expecting a kexec() style entry */ | |
c7a5c0c9 DG |
504 | for (env = first_cpu; env != NULL; env = env->next_cpu) { |
505 | env->halted = 1; | |
a9f8ad8f | 506 | } |
9fdf0c29 DG |
507 | } |
508 | ||
509 | /* Prepare the device tree */ | |
a3467baa DG |
510 | spapr->fdt_skel = spapr_create_fdt_skel(cpu_model, |
511 | initrd_base, initrd_size, | |
512 | boot_device, kernel_cmdline, | |
513 | pteg_shift + 7); | |
514 | assert(spapr->fdt_skel != NULL); | |
9fdf0c29 | 515 | |
a3467baa | 516 | qemu_register_reset(spapr_reset, spapr); |
9fdf0c29 DG |
517 | } |
518 | ||
519 | static QEMUMachine spapr_machine = { | |
520 | .name = "pseries", | |
521 | .desc = "pSeries Logical Partition (PAPR compliant)", | |
522 | .init = ppc_spapr_init, | |
523 | .max_cpus = MAX_CPUS, | |
524 | .no_vga = 1, | |
525 | .no_parallel = 1, | |
6e270446 | 526 | .use_scsi = 1, |
9fdf0c29 DG |
527 | }; |
528 | ||
529 | static void spapr_machine_init(void) | |
530 | { | |
531 | qemu_register_machine(&spapr_machine); | |
532 | } | |
533 | ||
534 | machine_init(spapr_machine_init); |