2 * QEMU PowerPC e500-based platforms
4 * Copyright (C) 2009 Freescale Semiconductor, Inc. All rights reserved.
6 * Author: Yu Liu, <yu.liu@freescale.com>
8 * This file is derived from hw/ppc440_bamboo.c,
9 * the copyright for that material belongs to the original owners.
11 * This is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
18 #include "qemu-common.h"
20 #include "e500-ccsr.h"
22 #include "qemu/config-file.h"
24 #include "hw/char/serial.h"
25 #include "hw/pci/pci.h"
26 #include "hw/boards.h"
27 #include "sysemu/sysemu.h"
28 #include "sysemu/kvm.h"
30 #include "sysemu/device_tree.h"
31 #include "hw/ppc/openpic.h"
32 #include "hw/ppc/ppc.h"
33 #include "hw/loader.h"
35 #include "hw/sysbus.h"
36 #include "exec/address-spaces.h"
37 #include "qemu/host-utils.h"
38 #include "hw/pci-host/ppce500.h"
40 #define EPAPR_MAGIC (0x45504150)
41 #define BINARY_DEVICE_TREE_FILE "mpc8544ds.dtb"
42 #define DTC_LOAD_PAD 0x1800000
43 #define DTC_PAD_MASK 0xFFFFF
44 #define DTB_MAX_SIZE (8 * 1024 * 1024)
45 #define INITRD_LOAD_PAD 0x2000000
46 #define INITRD_PAD_MASK 0xFFFFFF
48 #define RAM_SIZES_ALIGN (64UL << 20)
50 /* TODO: parameterize */
51 #define MPC8544_CCSRBAR_BASE 0xE0000000ULL
52 #define MPC8544_CCSRBAR_SIZE 0x00100000ULL
53 #define MPC8544_MPIC_REGS_OFFSET 0x40000ULL
54 #define MPC8544_MSI_REGS_OFFSET 0x41600ULL
55 #define MPC8544_SERIAL0_REGS_OFFSET 0x4500ULL
56 #define MPC8544_SERIAL1_REGS_OFFSET 0x4600ULL
57 #define MPC8544_PCI_REGS_OFFSET 0x8000ULL
58 #define MPC8544_PCI_REGS_BASE (MPC8544_CCSRBAR_BASE + \
59 MPC8544_PCI_REGS_OFFSET)
60 #define MPC8544_PCI_REGS_SIZE 0x1000ULL
61 #define MPC8544_PCI_IO 0xE1000000ULL
62 #define MPC8544_UTIL_OFFSET 0xe0000ULL
63 #define MPC8544_SPIN_BASE 0xEF000000ULL
72 static uint32_t *pci_map_create(void *fdt
, uint32_t mpic
, int first_slot
,
73 int nr_slots
, int *len
)
79 int last_slot
= first_slot
+ nr_slots
;
82 *len
= nr_slots
* 4 * 7 * sizeof(uint32_t);
83 pci_map
= g_malloc(*len
);
85 for (slot
= first_slot
; slot
< last_slot
; slot
++) {
86 for (pci_irq
= 0; pci_irq
< 4; pci_irq
++) {
87 pci_map
[i
++] = cpu_to_be32(slot
<< 11);
88 pci_map
[i
++] = cpu_to_be32(0x0);
89 pci_map
[i
++] = cpu_to_be32(0x0);
90 pci_map
[i
++] = cpu_to_be32(pci_irq
+ 1);
91 pci_map
[i
++] = cpu_to_be32(mpic
);
92 host_irq
= ppce500_pci_map_irq_slot(slot
, pci_irq
);
93 pci_map
[i
++] = cpu_to_be32(host_irq
+ 1);
94 pci_map
[i
++] = cpu_to_be32(0x1);
98 assert((i
* sizeof(uint32_t)) == *len
);
103 static void dt_serial_create(void *fdt
, unsigned long long offset
,
104 const char *soc
, const char *mpic
,
105 const char *alias
, int idx
, bool defcon
)
109 snprintf(ser
, sizeof(ser
), "%s/serial@%llx", soc
, offset
);
110 qemu_fdt_add_subnode(fdt
, ser
);
111 qemu_fdt_setprop_string(fdt
, ser
, "device_type", "serial");
112 qemu_fdt_setprop_string(fdt
, ser
, "compatible", "ns16550");
113 qemu_fdt_setprop_cells(fdt
, ser
, "reg", offset
, 0x100);
114 qemu_fdt_setprop_cell(fdt
, ser
, "cell-index", idx
);
115 qemu_fdt_setprop_cell(fdt
, ser
, "clock-frequency", 0);
116 qemu_fdt_setprop_cells(fdt
, ser
, "interrupts", 42, 2);
117 qemu_fdt_setprop_phandle(fdt
, ser
, "interrupt-parent", mpic
);
118 qemu_fdt_setprop_string(fdt
, "/aliases", alias
, ser
);
121 qemu_fdt_setprop_string(fdt
, "/chosen", "linux,stdout-path", ser
);
125 static int ppce500_load_device_tree(MachineState
*machine
,
126 PPCE500Params
*params
,
134 CPUPPCState
*env
= first_cpu
->env_ptr
;
136 uint64_t mem_reg_property
[] = { 0, cpu_to_be64(machine
->ram_size
) };
139 uint8_t hypercall
[16];
140 uint32_t clock_freq
= 400000000;
141 uint32_t tb_freq
= 400000000;
143 char compatible_sb
[] = "fsl,mpc8544-immr\0simple-bus";
151 uint32_t *pci_map
= NULL
;
153 uint32_t pci_ranges
[14] =
155 0x2000000, 0x0, 0xc0000000,
163 QemuOpts
*machine_opts
= qemu_get_machine_opts();
164 const char *dtb_file
= qemu_opt_get(machine_opts
, "dtb");
165 const char *toplevel_compat
= qemu_opt_get(machine_opts
, "dt_compatible");
169 filename
= qemu_find_file(QEMU_FILE_TYPE_BIOS
, dtb_file
);
174 fdt
= load_device_tree(filename
, &fdt_size
);
181 fdt
= create_device_tree(&fdt_size
);
186 /* Manipulate device tree in memory. */
187 qemu_fdt_setprop_cell(fdt
, "/", "#address-cells", 2);
188 qemu_fdt_setprop_cell(fdt
, "/", "#size-cells", 2);
190 qemu_fdt_add_subnode(fdt
, "/memory");
191 qemu_fdt_setprop_string(fdt
, "/memory", "device_type", "memory");
192 qemu_fdt_setprop(fdt
, "/memory", "reg", mem_reg_property
,
193 sizeof(mem_reg_property
));
195 qemu_fdt_add_subnode(fdt
, "/chosen");
197 ret
= qemu_fdt_setprop_cell(fdt
, "/chosen", "linux,initrd-start",
200 fprintf(stderr
, "couldn't set /chosen/linux,initrd-start\n");
203 ret
= qemu_fdt_setprop_cell(fdt
, "/chosen", "linux,initrd-end",
204 (initrd_base
+ initrd_size
));
206 fprintf(stderr
, "couldn't set /chosen/linux,initrd-end\n");
211 if (kernel_base
!= -1ULL) {
212 qemu_fdt_setprop_cells(fdt
, "/chosen", "qemu,boot-kernel",
213 kernel_base
>> 32, kernel_base
,
214 kernel_size
>> 32, kernel_size
);
217 ret
= qemu_fdt_setprop_string(fdt
, "/chosen", "bootargs",
218 machine
->kernel_cmdline
);
220 fprintf(stderr
, "couldn't set /chosen/bootargs\n");
223 /* Read out host's frequencies */
224 clock_freq
= kvmppc_get_clockfreq();
225 tb_freq
= kvmppc_get_tbfreq();
227 /* indicate KVM hypercall interface */
228 qemu_fdt_add_subnode(fdt
, "/hypervisor");
229 qemu_fdt_setprop_string(fdt
, "/hypervisor", "compatible",
231 kvmppc_get_hypercall(env
, hypercall
, sizeof(hypercall
));
232 qemu_fdt_setprop(fdt
, "/hypervisor", "hcall-instructions",
233 hypercall
, sizeof(hypercall
));
234 /* if KVM supports the idle hcall, set property indicating this */
235 if (kvmppc_get_hasidle(env
)) {
236 qemu_fdt_setprop(fdt
, "/hypervisor", "has-idle", NULL
, 0);
240 /* Create CPU nodes */
241 qemu_fdt_add_subnode(fdt
, "/cpus");
242 qemu_fdt_setprop_cell(fdt
, "/cpus", "#address-cells", 1);
243 qemu_fdt_setprop_cell(fdt
, "/cpus", "#size-cells", 0);
245 /* We need to generate the cpu nodes in reverse order, so Linux can pick
246 the first node as boot node and be happy */
247 for (i
= smp_cpus
- 1; i
>= 0; i
--) {
251 uint64_t cpu_release_addr
= MPC8544_SPIN_BASE
+ (i
* 0x20);
253 cpu
= qemu_get_cpu(i
);
258 pcpu
= POWERPC_CPU(cpu
);
260 snprintf(cpu_name
, sizeof(cpu_name
), "/cpus/PowerPC,8544@%x",
261 ppc_get_vcpu_dt_id(pcpu
));
262 qemu_fdt_add_subnode(fdt
, cpu_name
);
263 qemu_fdt_setprop_cell(fdt
, cpu_name
, "clock-frequency", clock_freq
);
264 qemu_fdt_setprop_cell(fdt
, cpu_name
, "timebase-frequency", tb_freq
);
265 qemu_fdt_setprop_string(fdt
, cpu_name
, "device_type", "cpu");
266 qemu_fdt_setprop_cell(fdt
, cpu_name
, "reg",
267 ppc_get_vcpu_dt_id(pcpu
));
268 qemu_fdt_setprop_cell(fdt
, cpu_name
, "d-cache-line-size",
269 env
->dcache_line_size
);
270 qemu_fdt_setprop_cell(fdt
, cpu_name
, "i-cache-line-size",
271 env
->icache_line_size
);
272 qemu_fdt_setprop_cell(fdt
, cpu_name
, "d-cache-size", 0x8000);
273 qemu_fdt_setprop_cell(fdt
, cpu_name
, "i-cache-size", 0x8000);
274 qemu_fdt_setprop_cell(fdt
, cpu_name
, "bus-frequency", 0);
275 if (cpu
->cpu_index
) {
276 qemu_fdt_setprop_string(fdt
, cpu_name
, "status", "disabled");
277 qemu_fdt_setprop_string(fdt
, cpu_name
, "enable-method",
279 qemu_fdt_setprop_u64(fdt
, cpu_name
, "cpu-release-addr",
282 qemu_fdt_setprop_string(fdt
, cpu_name
, "status", "okay");
286 qemu_fdt_add_subnode(fdt
, "/aliases");
287 /* XXX These should go into their respective devices' code */
288 snprintf(soc
, sizeof(soc
), "/soc@%llx", MPC8544_CCSRBAR_BASE
);
289 qemu_fdt_add_subnode(fdt
, soc
);
290 qemu_fdt_setprop_string(fdt
, soc
, "device_type", "soc");
291 qemu_fdt_setprop(fdt
, soc
, "compatible", compatible_sb
,
292 sizeof(compatible_sb
));
293 qemu_fdt_setprop_cell(fdt
, soc
, "#address-cells", 1);
294 qemu_fdt_setprop_cell(fdt
, soc
, "#size-cells", 1);
295 qemu_fdt_setprop_cells(fdt
, soc
, "ranges", 0x0,
296 MPC8544_CCSRBAR_BASE
>> 32, MPC8544_CCSRBAR_BASE
,
297 MPC8544_CCSRBAR_SIZE
);
298 /* XXX should contain a reasonable value */
299 qemu_fdt_setprop_cell(fdt
, soc
, "bus-frequency", 0);
301 snprintf(mpic
, sizeof(mpic
), "%s/pic@%llx", soc
, MPC8544_MPIC_REGS_OFFSET
);
302 qemu_fdt_add_subnode(fdt
, mpic
);
303 qemu_fdt_setprop_string(fdt
, mpic
, "device_type", "open-pic");
304 qemu_fdt_setprop_string(fdt
, mpic
, "compatible", "fsl,mpic");
305 qemu_fdt_setprop_cells(fdt
, mpic
, "reg", MPC8544_MPIC_REGS_OFFSET
,
307 qemu_fdt_setprop_cell(fdt
, mpic
, "#address-cells", 0);
308 qemu_fdt_setprop_cell(fdt
, mpic
, "#interrupt-cells", 2);
309 mpic_ph
= qemu_fdt_alloc_phandle(fdt
);
310 qemu_fdt_setprop_cell(fdt
, mpic
, "phandle", mpic_ph
);
311 qemu_fdt_setprop_cell(fdt
, mpic
, "linux,phandle", mpic_ph
);
312 qemu_fdt_setprop(fdt
, mpic
, "interrupt-controller", NULL
, 0);
315 * We have to generate ser1 first, because Linux takes the first
316 * device it finds in the dt as serial output device. And we generate
317 * devices in reverse order to the dt.
320 dt_serial_create(fdt
, MPC8544_SERIAL1_REGS_OFFSET
,
321 soc
, mpic
, "serial1", 1, false);
325 dt_serial_create(fdt
, MPC8544_SERIAL0_REGS_OFFSET
,
326 soc
, mpic
, "serial0", 0, true);
329 snprintf(gutil
, sizeof(gutil
), "%s/global-utilities@%llx", soc
,
330 MPC8544_UTIL_OFFSET
);
331 qemu_fdt_add_subnode(fdt
, gutil
);
332 qemu_fdt_setprop_string(fdt
, gutil
, "compatible", "fsl,mpc8544-guts");
333 qemu_fdt_setprop_cells(fdt
, gutil
, "reg", MPC8544_UTIL_OFFSET
, 0x1000);
334 qemu_fdt_setprop(fdt
, gutil
, "fsl,has-rstcr", NULL
, 0);
336 snprintf(msi
, sizeof(msi
), "/%s/msi@%llx", soc
, MPC8544_MSI_REGS_OFFSET
);
337 qemu_fdt_add_subnode(fdt
, msi
);
338 qemu_fdt_setprop_string(fdt
, msi
, "compatible", "fsl,mpic-msi");
339 qemu_fdt_setprop_cells(fdt
, msi
, "reg", MPC8544_MSI_REGS_OFFSET
, 0x200);
340 msi_ph
= qemu_fdt_alloc_phandle(fdt
);
341 qemu_fdt_setprop_cells(fdt
, msi
, "msi-available-ranges", 0x0, 0x100);
342 qemu_fdt_setprop_phandle(fdt
, msi
, "interrupt-parent", mpic
);
343 qemu_fdt_setprop_cells(fdt
, msi
, "interrupts",
352 qemu_fdt_setprop_cell(fdt
, msi
, "phandle", msi_ph
);
353 qemu_fdt_setprop_cell(fdt
, msi
, "linux,phandle", msi_ph
);
355 snprintf(pci
, sizeof(pci
), "/pci@%llx", MPC8544_PCI_REGS_BASE
);
356 qemu_fdt_add_subnode(fdt
, pci
);
357 qemu_fdt_setprop_cell(fdt
, pci
, "cell-index", 0);
358 qemu_fdt_setprop_string(fdt
, pci
, "compatible", "fsl,mpc8540-pci");
359 qemu_fdt_setprop_string(fdt
, pci
, "device_type", "pci");
360 qemu_fdt_setprop_cells(fdt
, pci
, "interrupt-map-mask", 0xf800, 0x0,
362 pci_map
= pci_map_create(fdt
, qemu_fdt_get_phandle(fdt
, mpic
),
363 params
->pci_first_slot
, params
->pci_nr_slots
,
365 qemu_fdt_setprop(fdt
, pci
, "interrupt-map", pci_map
, len
);
366 qemu_fdt_setprop_phandle(fdt
, pci
, "interrupt-parent", mpic
);
367 qemu_fdt_setprop_cells(fdt
, pci
, "interrupts", 24, 2);
368 qemu_fdt_setprop_cells(fdt
, pci
, "bus-range", 0, 255);
369 for (i
= 0; i
< 14; i
++) {
370 pci_ranges
[i
] = cpu_to_be32(pci_ranges
[i
]);
372 qemu_fdt_setprop_cell(fdt
, pci
, "fsl,msi", msi_ph
);
373 qemu_fdt_setprop(fdt
, pci
, "ranges", pci_ranges
, sizeof(pci_ranges
));
374 qemu_fdt_setprop_cells(fdt
, pci
, "reg", MPC8544_PCI_REGS_BASE
>> 32,
375 MPC8544_PCI_REGS_BASE
, 0, 0x1000);
376 qemu_fdt_setprop_cell(fdt
, pci
, "clock-frequency", 66666666);
377 qemu_fdt_setprop_cell(fdt
, pci
, "#interrupt-cells", 1);
378 qemu_fdt_setprop_cell(fdt
, pci
, "#size-cells", 2);
379 qemu_fdt_setprop_cell(fdt
, pci
, "#address-cells", 3);
380 qemu_fdt_setprop_string(fdt
, "/aliases", "pci0", pci
);
382 params
->fixup_devtree(params
, fdt
);
384 if (toplevel_compat
) {
385 qemu_fdt_setprop(fdt
, "/", "compatible", toplevel_compat
,
386 strlen(toplevel_compat
) + 1);
391 qemu_fdt_dumpdtb(fdt
, fdt_size
);
392 cpu_physical_memory_write(addr
, fdt
, fdt_size
);
402 typedef struct DeviceTreeParams
{
403 MachineState
*machine
;
404 PPCE500Params params
;
412 static void ppce500_reset_device_tree(void *opaque
)
414 DeviceTreeParams
*p
= opaque
;
415 ppce500_load_device_tree(p
->machine
, &p
->params
, p
->addr
, p
->initrd_base
,
416 p
->initrd_size
, p
->kernel_base
, p
->kernel_size
,
420 static int ppce500_prep_device_tree(MachineState
*machine
,
421 PPCE500Params
*params
,
428 DeviceTreeParams
*p
= g_new(DeviceTreeParams
, 1);
429 p
->machine
= machine
;
432 p
->initrd_base
= initrd_base
;
433 p
->initrd_size
= initrd_size
;
434 p
->kernel_base
= kernel_base
;
435 p
->kernel_size
= kernel_size
;
437 qemu_register_reset(ppce500_reset_device_tree
, p
);
439 /* Issue the device tree loader once, so that we get the size of the blob */
440 return ppce500_load_device_tree(machine
, params
, addr
, initrd_base
,
441 initrd_size
, kernel_base
, kernel_size
,
445 /* Create -kernel TLB entries for BookE. */
446 static inline hwaddr
booke206_page_size_to_tlb(uint64_t size
)
448 return 63 - clz64(size
>> 10);
451 static int booke206_initial_map_tsize(CPUPPCState
*env
)
453 struct boot_info
*bi
= env
->load_info
;
457 /* Our initial TLB entry needs to cover everything from 0 to
458 the device tree top */
459 dt_end
= bi
->dt_base
+ bi
->dt_size
;
460 ps
= booke206_page_size_to_tlb(dt_end
) + 1;
462 /* e500v2 can only do even TLB size bits */
468 static uint64_t mmubooke_initial_mapsize(CPUPPCState
*env
)
472 tsize
= booke206_initial_map_tsize(env
);
473 return (1ULL << 10 << tsize
);
476 static void mmubooke_create_initial_mapping(CPUPPCState
*env
)
478 ppcmas_tlb_t
*tlb
= booke206_get_tlbm(env
, 1, 0, 0);
482 ps
= booke206_initial_map_tsize(env
);
483 size
= (ps
<< MAS1_TSIZE_SHIFT
);
484 tlb
->mas1
= MAS1_VALID
| size
;
487 tlb
->mas7_3
|= MAS3_UR
| MAS3_UW
| MAS3_UX
| MAS3_SR
| MAS3_SW
| MAS3_SX
;
489 env
->tlb_dirty
= true;
492 static void ppce500_cpu_reset_sec(void *opaque
)
494 PowerPCCPU
*cpu
= opaque
;
495 CPUState
*cs
= CPU(cpu
);
499 /* Secondary CPU starts in halted state for now. Needs to change when
500 implementing non-kernel boot. */
502 cs
->exception_index
= EXCP_HLT
;
505 static void ppce500_cpu_reset(void *opaque
)
507 PowerPCCPU
*cpu
= opaque
;
508 CPUState
*cs
= CPU(cpu
);
509 CPUPPCState
*env
= &cpu
->env
;
510 struct boot_info
*bi
= env
->load_info
;
514 /* Set initial guest state. */
516 env
->gpr
[1] = (16<<20) - 8;
517 env
->gpr
[3] = bi
->dt_base
;
520 env
->gpr
[6] = EPAPR_MAGIC
;
521 env
->gpr
[7] = mmubooke_initial_mapsize(env
);
524 env
->nip
= bi
->entry
;
525 mmubooke_create_initial_mapping(env
);
528 static DeviceState
*ppce500_init_mpic_qemu(PPCE500Params
*params
,
535 dev
= qdev_create(NULL
, TYPE_OPENPIC
);
536 qdev_prop_set_uint32(dev
, "model", params
->mpic_version
);
537 qdev_prop_set_uint32(dev
, "nb_cpus", smp_cpus
);
539 qdev_init_nofail(dev
);
540 s
= SYS_BUS_DEVICE(dev
);
543 for (i
= 0; i
< smp_cpus
; i
++) {
544 for (j
= 0; j
< OPENPIC_OUTPUT_NB
; j
++) {
545 sysbus_connect_irq(s
, k
++, irqs
[i
][j
]);
552 static DeviceState
*ppce500_init_mpic_kvm(PPCE500Params
*params
,
559 dev
= qdev_create(NULL
, TYPE_KVM_OPENPIC
);
560 qdev_prop_set_uint32(dev
, "model", params
->mpic_version
);
568 if (kvm_openpic_connect_vcpu(dev
, cs
)) {
569 fprintf(stderr
, "%s: failed to connect vcpu to irqchip\n",
578 static qemu_irq
*ppce500_init_mpic(PPCE500Params
*params
, MemoryRegion
*ccsr
,
582 DeviceState
*dev
= NULL
;
586 mpic
= g_new(qemu_irq
, 256);
589 QemuOpts
*machine_opts
= qemu_get_machine_opts();
590 bool irqchip_allowed
= qemu_opt_get_bool(machine_opts
,
591 "kernel_irqchip", true);
592 bool irqchip_required
= qemu_opt_get_bool(machine_opts
,
593 "kernel_irqchip", false);
595 if (irqchip_allowed
) {
596 dev
= ppce500_init_mpic_kvm(params
, irqs
);
599 if (irqchip_required
&& !dev
) {
600 fprintf(stderr
, "%s: irqchip requested but unavailable\n",
607 dev
= ppce500_init_mpic_qemu(params
, irqs
);
610 for (i
= 0; i
< 256; i
++) {
611 mpic
[i
] = qdev_get_gpio_in(dev
, i
);
614 s
= SYS_BUS_DEVICE(dev
);
615 memory_region_add_subregion(ccsr
, MPC8544_MPIC_REGS_OFFSET
,
621 void ppce500_init(MachineState
*machine
, PPCE500Params
*params
)
623 MemoryRegion
*address_space_mem
= get_system_memory();
624 MemoryRegion
*ram
= g_new(MemoryRegion
, 1);
626 CPUPPCState
*env
= NULL
;
628 hwaddr kernel_base
= -1LL;
631 hwaddr initrd_base
= 0;
635 hwaddr bios_entry
= 0;
636 target_long bios_size
;
637 struct boot_info
*boot_info
;
640 /* irq num for pin INTA, INTB, INTC and INTD is 1, 2, 3 and
642 unsigned int pci_irq_nrs
[PCI_NUM_PINS
] = {1, 2, 3, 4};
643 qemu_irq
**irqs
, *mpic
;
645 CPUPPCState
*firstenv
= NULL
;
646 MemoryRegion
*ccsr_addr_space
;
648 PPCE500CCSRState
*ccsr
;
651 if (machine
->cpu_model
== NULL
) {
652 machine
->cpu_model
= "e500v2_v30";
655 irqs
= g_malloc0(smp_cpus
* sizeof(qemu_irq
*));
656 irqs
[0] = g_malloc0(smp_cpus
* sizeof(qemu_irq
) * OPENPIC_OUTPUT_NB
);
657 for (i
= 0; i
< smp_cpus
; i
++) {
662 cpu
= cpu_ppc_init(machine
->cpu_model
);
664 fprintf(stderr
, "Unable to initialize CPU!\n");
674 irqs
[i
] = irqs
[0] + (i
* OPENPIC_OUTPUT_NB
);
675 input
= (qemu_irq
*)env
->irq_inputs
;
676 irqs
[i
][OPENPIC_OUTPUT_INT
] = input
[PPCE500_INPUT_INT
];
677 irqs
[i
][OPENPIC_OUTPUT_CINT
] = input
[PPCE500_INPUT_CINT
];
678 env
->spr_cb
[SPR_BOOKE_PIR
].default_value
= cs
->cpu_index
= i
;
679 env
->mpic_iack
= MPC8544_CCSRBAR_BASE
+
680 MPC8544_MPIC_REGS_OFFSET
+ 0xa0;
682 ppc_booke_timers_init(cpu
, 400000000, PPC_TIMER_E500
);
684 /* Register reset handler */
687 struct boot_info
*boot_info
;
688 boot_info
= g_malloc0(sizeof(struct boot_info
));
689 qemu_register_reset(ppce500_cpu_reset
, cpu
);
690 env
->load_info
= boot_info
;
693 qemu_register_reset(ppce500_cpu_reset_sec
, cpu
);
699 /* Fixup Memory size on a alignment boundary */
700 ram_size
&= ~(RAM_SIZES_ALIGN
- 1);
701 machine
->ram_size
= ram_size
;
703 /* Register Memory */
704 memory_region_allocate_system_memory(ram
, NULL
, "mpc8544ds.ram", ram_size
);
705 memory_region_add_subregion(address_space_mem
, 0, ram
);
707 dev
= qdev_create(NULL
, "e500-ccsr");
708 object_property_add_child(qdev_get_machine(), "e500-ccsr",
710 qdev_init_nofail(dev
);
712 ccsr_addr_space
= &ccsr
->ccsr_space
;
713 memory_region_add_subregion(address_space_mem
, MPC8544_CCSRBAR_BASE
,
716 mpic
= ppce500_init_mpic(params
, ccsr_addr_space
, irqs
);
720 serial_mm_init(ccsr_addr_space
, MPC8544_SERIAL0_REGS_OFFSET
,
722 serial_hds
[0], DEVICE_BIG_ENDIAN
);
726 serial_mm_init(ccsr_addr_space
, MPC8544_SERIAL1_REGS_OFFSET
,
728 serial_hds
[1], DEVICE_BIG_ENDIAN
);
731 /* General Utility device */
732 dev
= qdev_create(NULL
, "mpc8544-guts");
733 qdev_init_nofail(dev
);
734 s
= SYS_BUS_DEVICE(dev
);
735 memory_region_add_subregion(ccsr_addr_space
, MPC8544_UTIL_OFFSET
,
736 sysbus_mmio_get_region(s
, 0));
739 dev
= qdev_create(NULL
, "e500-pcihost");
740 qdev_prop_set_uint32(dev
, "first_slot", params
->pci_first_slot
);
741 qdev_prop_set_uint32(dev
, "first_pin_irq", pci_irq_nrs
[0]);
742 qdev_init_nofail(dev
);
743 s
= SYS_BUS_DEVICE(dev
);
744 for (i
= 0; i
< PCI_NUM_PINS
; i
++) {
745 sysbus_connect_irq(s
, i
, mpic
[pci_irq_nrs
[i
]]);
748 memory_region_add_subregion(ccsr_addr_space
, MPC8544_PCI_REGS_OFFSET
,
749 sysbus_mmio_get_region(s
, 0));
751 pci_bus
= (PCIBus
*)qdev_get_child_bus(dev
, "pci.0");
753 printf("couldn't create PCI controller!\n");
755 sysbus_mmio_map(SYS_BUS_DEVICE(dev
), 1, MPC8544_PCI_IO
);
758 /* Register network interfaces. */
759 for (i
= 0; i
< nb_nics
; i
++) {
760 pci_nic_init_nofail(&nd_table
[i
], pci_bus
, "virtio", NULL
);
764 /* Register spinning region */
765 sysbus_create_simple("e500-spin", MPC8544_SPIN_BASE
, NULL
);
767 if (cur_base
< (32 * 1024 * 1024)) {
768 /* u-boot occupies memory up to 32MB, so load blobs above */
769 cur_base
= (32 * 1024 * 1024);
773 if (machine
->kernel_filename
) {
774 kernel_base
= cur_base
;
775 kernel_size
= load_image_targphys(machine
->kernel_filename
,
777 ram_size
- cur_base
);
778 if (kernel_size
< 0) {
779 fprintf(stderr
, "qemu: could not load kernel '%s'\n",
780 machine
->kernel_filename
);
784 cur_base
+= kernel_size
;
788 if (machine
->initrd_filename
) {
789 initrd_base
= (cur_base
+ INITRD_LOAD_PAD
) & ~INITRD_PAD_MASK
;
790 initrd_size
= load_image_targphys(machine
->initrd_filename
, initrd_base
,
791 ram_size
- initrd_base
);
793 if (initrd_size
< 0) {
794 fprintf(stderr
, "qemu: could not load initial ram disk '%s'\n",
795 machine
->initrd_filename
);
799 cur_base
= initrd_base
+ initrd_size
;
803 * Smart firmware defaults ahead!
805 * We follow the following table to select which payload we execute.
807 * -kernel | -bios | payload
808 * ---------+-------+---------
814 * This ensures backwards compatibility with how we used to expose
815 * -kernel to users but allows them to run through u-boot as well.
817 if (bios_name
== NULL
) {
818 if (machine
->kernel_filename
) {
819 bios_name
= machine
->kernel_filename
;
821 bios_name
= "u-boot.e500";
824 filename
= qemu_find_file(QEMU_FILE_TYPE_BIOS
, bios_name
);
826 bios_size
= load_elf(filename
, NULL
, NULL
, &bios_entry
, &loadaddr
, NULL
,
830 * Hrm. No ELF image? Try a uImage, maybe someone is giving us an
831 * ePAPR compliant kernel
833 kernel_size
= load_uimage(filename
, &bios_entry
, &loadaddr
, NULL
);
834 if (kernel_size
< 0) {
835 fprintf(stderr
, "qemu: could not load firmware '%s'\n", filename
);
840 /* Reserve space for dtb */
841 dt_base
= (loadaddr
+ bios_size
+ DTC_LOAD_PAD
) & ~DTC_PAD_MASK
;
843 dt_size
= ppce500_prep_device_tree(machine
, params
, dt_base
,
844 initrd_base
, initrd_size
,
845 kernel_base
, kernel_size
);
847 fprintf(stderr
, "couldn't load device tree\n");
850 assert(dt_size
< DTB_MAX_SIZE
);
852 boot_info
= env
->load_info
;
853 boot_info
->entry
= bios_entry
;
854 boot_info
->dt_base
= dt_base
;
855 boot_info
->dt_size
= dt_size
;
862 static int e500_ccsr_initfn(SysBusDevice
*dev
)
864 PPCE500CCSRState
*ccsr
;
867 memory_region_init(&ccsr
->ccsr_space
, OBJECT(ccsr
), "e500-ccsr",
868 MPC8544_CCSRBAR_SIZE
);
872 static void e500_ccsr_class_init(ObjectClass
*klass
, void *data
)
874 SysBusDeviceClass
*k
= SYS_BUS_DEVICE_CLASS(klass
);
875 k
->init
= e500_ccsr_initfn
;
878 static const TypeInfo e500_ccsr_info
= {
880 .parent
= TYPE_SYS_BUS_DEVICE
,
881 .instance_size
= sizeof(PPCE500CCSRState
),
882 .class_init
= e500_ccsr_class_init
,
885 static void e500_register_types(void)
887 type_register_static(&e500_ccsr_info
);
890 type_init(e500_register_types
)