2 * Qemu PowerPC 440 Bamboo board emulation
4 * Copyright 2007 IBM Corporation.
6 * Jerone Young <jyoung5@us.ibm.com>
7 * Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
8 * Hollis Blanchard <hollisb@us.ibm.com>
10 * This work is licensed under the GNU GPL license version 2 or later.
15 #include "qemu-common.h"
23 #include "device_tree.h"
26 #include "exec-memory.h"
28 #define BINARY_DEVICE_TREE_FILE "bamboo.dtb"
31 #define KERNEL_ADDR 0x1000000
32 #define FDT_ADDR 0x1800000
33 #define RAMDISK_ADDR 0x1900000
35 static target_phys_addr_t entry
;
37 static int bamboo_load_device_tree(target_phys_addr_t addr
,
39 target_phys_addr_t initrd_base
,
40 target_phys_addr_t initrd_size
,
41 const char *kernel_cmdline
)
45 uint32_t mem_reg_property
[] = { 0, 0, ramsize
};
49 uint32_t tb_freq
= 400000000;
50 uint32_t clock_freq
= 400000000;
52 filename
= qemu_find_file(QEMU_FILE_TYPE_BIOS
, BINARY_DEVICE_TREE_FILE
);
56 fdt
= load_device_tree(filename
, &fdt_size
);
62 /* Manipulate device tree in memory. */
64 ret
= qemu_devtree_setprop(fdt
, "/memory", "reg", mem_reg_property
,
65 sizeof(mem_reg_property
));
67 fprintf(stderr
, "couldn't set /memory/reg\n");
69 ret
= qemu_devtree_setprop_cell(fdt
, "/chosen", "linux,initrd-start",
72 fprintf(stderr
, "couldn't set /chosen/linux,initrd-start\n");
74 ret
= qemu_devtree_setprop_cell(fdt
, "/chosen", "linux,initrd-end",
75 (initrd_base
+ initrd_size
));
77 fprintf(stderr
, "couldn't set /chosen/linux,initrd-end\n");
79 ret
= qemu_devtree_setprop_string(fdt
, "/chosen", "bootargs",
82 fprintf(stderr
, "couldn't set /chosen/bootargs\n");
84 /* Copy data from the host device tree into the guest. Since the guest can
85 * directly access the timebase without host involvement, we must expose
86 * the correct frequencies. */
88 tb_freq
= kvmppc_get_tbfreq();
89 clock_freq
= kvmppc_get_clockfreq();
92 qemu_devtree_setprop_cell(fdt
, "/cpus/cpu@0", "clock-frequency",
94 qemu_devtree_setprop_cell(fdt
, "/cpus/cpu@0", "timebase-frequency",
97 ret
= rom_add_blob_fixed(BINARY_DEVICE_TREE_FILE
, fdt
, fdt_size
, addr
);
106 /* Create reset TLB entries for BookE, spanning the 32bit addr space. */
107 static void mmubooke_create_initial_mapping(CPUState
*env
,
109 target_phys_addr_t pa
)
111 ppcemb_tlb_t
*tlb
= &env
->tlb
.tlbe
[0];
114 tlb
->prot
= PAGE_VALID
| ((PAGE_READ
| PAGE_WRITE
| PAGE_EXEC
) << 4);
115 tlb
->size
= 1 << 31; /* up to 0x80000000 */
116 tlb
->EPN
= va
& TARGET_PAGE_MASK
;
117 tlb
->RPN
= pa
& TARGET_PAGE_MASK
;
120 tlb
= &env
->tlb
.tlbe
[1];
122 tlb
->prot
= PAGE_VALID
| ((PAGE_READ
| PAGE_WRITE
| PAGE_EXEC
) << 4);
123 tlb
->size
= 1 << 31; /* up to 0xffffffff */
124 tlb
->EPN
= 0x80000000 & TARGET_PAGE_MASK
;
125 tlb
->RPN
= 0x80000000 & TARGET_PAGE_MASK
;
129 static void main_cpu_reset(void *opaque
)
131 CPUState
*env
= opaque
;
134 env
->gpr
[1] = (16<<20) - 8;
135 env
->gpr
[3] = FDT_ADDR
;
138 /* Create a mapping for the kernel. */
139 mmubooke_create_initial_mapping(env
, 0, 0);
142 static void bamboo_init(ram_addr_t ram_size
,
143 const char *boot_device
,
144 const char *kernel_filename
,
145 const char *kernel_cmdline
,
146 const char *initrd_filename
,
147 const char *cpu_model
)
149 unsigned int pci_irq_nrs
[4] = { 28, 27, 26, 25 };
150 MemoryRegion
*address_space_mem
= get_system_memory();
154 uint64_t elf_lowaddr
;
155 target_phys_addr_t loadaddr
= 0;
156 target_long initrd_size
= 0;
161 env
= ppc440ep_init(address_space_mem
, &ram_size
, &pcibus
,
162 pci_irq_nrs
, 1, cpu_model
);
163 qemu_register_reset(main_cpu_reset
, env
);
166 /* Register network interfaces. */
167 for (i
= 0; i
< nb_nics
; i
++) {
168 /* There are no PCI NICs on the Bamboo board, but there are
169 * PCI slots, so we can pick whatever default model we want. */
170 pci_nic_init_nofail(&nd_table
[i
], "e1000", NULL
);
175 if (kernel_filename
) {
176 success
= load_uimage(kernel_filename
, &entry
, &loadaddr
, NULL
);
178 success
= load_elf(kernel_filename
, NULL
, NULL
, &elf_entry
,
179 &elf_lowaddr
, NULL
, 1, ELF_MACHINE
, 0);
181 loadaddr
= elf_lowaddr
;
183 /* XXX try again as binary */
185 fprintf(stderr
, "qemu: could not load kernel '%s'\n",
192 if (initrd_filename
) {
193 initrd_size
= load_image_targphys(initrd_filename
, RAMDISK_ADDR
,
194 ram_size
- RAMDISK_ADDR
);
196 if (initrd_size
< 0) {
197 fprintf(stderr
, "qemu: could not load ram disk '%s' at %x\n",
198 initrd_filename
, RAMDISK_ADDR
);
203 /* If we're loading a kernel directly, we must load the device tree too. */
204 if (kernel_filename
) {
205 if (bamboo_load_device_tree(FDT_ADDR
, ram_size
, RAMDISK_ADDR
,
206 initrd_size
, kernel_cmdline
) < 0) {
207 fprintf(stderr
, "couldn't load device tree\n");
216 static QEMUMachine bamboo_machine
= {
222 static void bamboo_machine_init(void)
224 qemu_register_machine(&bamboo_machine
);
227 machine_init(bamboo_machine_init
);