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 int bamboo_load_device_tree(target_phys_addr_t addr
,
37 target_phys_addr_t initrd_base
,
38 target_phys_addr_t initrd_size
,
39 const char *kernel_cmdline
)
43 uint32_t mem_reg_property
[] = { 0, 0, ramsize
};
47 uint32_t tb_freq
= 400000000;
48 uint32_t clock_freq
= 400000000;
50 filename
= qemu_find_file(QEMU_FILE_TYPE_BIOS
, BINARY_DEVICE_TREE_FILE
);
54 fdt
= load_device_tree(filename
, &fdt_size
);
60 /* Manipulate device tree in memory. */
62 ret
= qemu_devtree_setprop(fdt
, "/memory", "reg", mem_reg_property
,
63 sizeof(mem_reg_property
));
65 fprintf(stderr
, "couldn't set /memory/reg\n");
67 ret
= qemu_devtree_setprop_cell(fdt
, "/chosen", "linux,initrd-start",
70 fprintf(stderr
, "couldn't set /chosen/linux,initrd-start\n");
72 ret
= qemu_devtree_setprop_cell(fdt
, "/chosen", "linux,initrd-end",
73 (initrd_base
+ initrd_size
));
75 fprintf(stderr
, "couldn't set /chosen/linux,initrd-end\n");
77 ret
= qemu_devtree_setprop_string(fdt
, "/chosen", "bootargs",
80 fprintf(stderr
, "couldn't set /chosen/bootargs\n");
82 /* Copy data from the host device tree into the guest. Since the guest can
83 * directly access the timebase without host involvement, we must expose
84 * the correct frequencies. */
86 tb_freq
= kvmppc_get_tbfreq();
87 clock_freq
= kvmppc_get_clockfreq();
90 qemu_devtree_setprop_cell(fdt
, "/cpus/cpu@0", "clock-frequency",
92 qemu_devtree_setprop_cell(fdt
, "/cpus/cpu@0", "timebase-frequency",
95 ret
= rom_add_blob_fixed(BINARY_DEVICE_TREE_FILE
, fdt
, fdt_size
, addr
);
104 static void bamboo_init(ram_addr_t ram_size
,
105 const char *boot_device
,
106 const char *kernel_filename
,
107 const char *kernel_cmdline
,
108 const char *initrd_filename
,
109 const char *cpu_model
)
111 unsigned int pci_irq_nrs
[4] = { 28, 27, 26, 25 };
112 MemoryRegion
*address_space_mem
= get_system_memory();
116 uint64_t elf_lowaddr
;
117 target_phys_addr_t entry
= 0;
118 target_phys_addr_t loadaddr
= 0;
119 target_long initrd_size
= 0;
124 env
= ppc440ep_init(address_space_mem
, &ram_size
, &pcibus
,
125 pci_irq_nrs
, 1, cpu_model
);
128 /* Register network interfaces. */
129 for (i
= 0; i
< nb_nics
; i
++) {
130 /* There are no PCI NICs on the Bamboo board, but there are
131 * PCI slots, so we can pick whatever default model we want. */
132 pci_nic_init_nofail(&nd_table
[i
], "e1000", NULL
);
137 if (kernel_filename
) {
138 success
= load_uimage(kernel_filename
, &entry
, &loadaddr
, NULL
);
140 success
= load_elf(kernel_filename
, NULL
, NULL
, &elf_entry
,
141 &elf_lowaddr
, NULL
, 1, ELF_MACHINE
, 0);
143 loadaddr
= elf_lowaddr
;
145 /* XXX try again as binary */
147 fprintf(stderr
, "qemu: could not load kernel '%s'\n",
154 if (initrd_filename
) {
155 initrd_size
= load_image_targphys(initrd_filename
, RAMDISK_ADDR
,
156 ram_size
- RAMDISK_ADDR
);
158 if (initrd_size
< 0) {
159 fprintf(stderr
, "qemu: could not load ram disk '%s' at %x\n",
160 initrd_filename
, RAMDISK_ADDR
);
165 /* If we're loading a kernel directly, we must load the device tree too. */
166 if (kernel_filename
) {
167 if (bamboo_load_device_tree(FDT_ADDR
, ram_size
, RAMDISK_ADDR
,
168 initrd_size
, kernel_cmdline
) < 0) {
169 fprintf(stderr
, "couldn't load device tree\n");
173 /* Set initial guest state. */
174 env
->gpr
[1] = (16<<20) - 8;
175 env
->gpr
[3] = FDT_ADDR
;
177 /* XXX we currently depend on KVM to create some initial TLB entries. */
184 static QEMUMachine bamboo_machine
= {
185 .name
= "bamboo-0.13",
191 static QEMUMachine bamboo_machine_v0_12
= {
192 .name
= "bamboo-0.12",
195 .compat_props
= (GlobalProperty
[]) {
197 .driver
= "virtio-serial-pci",
198 .property
= "max_ports",
199 .value
= stringify(1),
201 .driver
= "virtio-serial-pci",
202 .property
= "vectors",
203 .value
= stringify(0),
205 { /* end of list */ }
209 static void bamboo_machine_init(void)
211 qemu_register_machine(&bamboo_machine
);
212 qemu_register_machine(&bamboo_machine_v0_12
);
215 machine_init(bamboo_machine_init
);