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"
27 #define BINARY_DEVICE_TREE_FILE "bamboo.dtb"
30 #define KERNEL_ADDR 0x1000000
31 #define FDT_ADDR 0x1800000
32 #define RAMDISK_ADDR 0x1900000
34 static int bamboo_load_device_tree(target_phys_addr_t addr
,
36 target_phys_addr_t initrd_base
,
37 target_phys_addr_t initrd_size
,
38 const char *kernel_cmdline
)
42 uint32_t mem_reg_property
[] = { 0, 0, ramsize
};
47 filename
= qemu_find_file(QEMU_FILE_TYPE_BIOS
, BINARY_DEVICE_TREE_FILE
);
51 fdt
= load_device_tree(filename
, &fdt_size
);
57 /* Manipulate device tree in memory. */
59 ret
= qemu_devtree_setprop(fdt
, "/memory", "reg", mem_reg_property
,
60 sizeof(mem_reg_property
));
62 fprintf(stderr
, "couldn't set /memory/reg\n");
64 ret
= qemu_devtree_setprop_cell(fdt
, "/chosen", "linux,initrd-start",
67 fprintf(stderr
, "couldn't set /chosen/linux,initrd-start\n");
69 ret
= qemu_devtree_setprop_cell(fdt
, "/chosen", "linux,initrd-end",
70 (initrd_base
+ initrd_size
));
72 fprintf(stderr
, "couldn't set /chosen/linux,initrd-end\n");
74 ret
= qemu_devtree_setprop_string(fdt
, "/chosen", "bootargs",
77 fprintf(stderr
, "couldn't set /chosen/bootargs\n");
80 kvmppc_fdt_update(fdt
);
82 ret
= rom_add_blob_fixed(BINARY_DEVICE_TREE_FILE
, fdt
, fdt_size
, addr
);
91 static void bamboo_init(ram_addr_t ram_size
,
92 const char *boot_device
,
93 const char *kernel_filename
,
94 const char *kernel_cmdline
,
95 const char *initrd_filename
,
96 const char *cpu_model
)
98 unsigned int pci_irq_nrs
[4] = { 28, 27, 26, 25 };
102 uint64_t elf_lowaddr
;
103 target_phys_addr_t entry
= 0;
104 target_phys_addr_t loadaddr
= 0;
105 target_long initrd_size
= 0;
110 env
= ppc440ep_init(&ram_size
, &pcibus
, pci_irq_nrs
, 1, cpu_model
);
113 /* Register network interfaces. */
114 for (i
= 0; i
< nb_nics
; i
++) {
115 /* There are no PCI NICs on the Bamboo board, but there are
116 * PCI slots, so we can pick whatever default model we want. */
117 pci_nic_init_nofail(&nd_table
[i
], "e1000", NULL
);
122 if (kernel_filename
) {
123 success
= load_uimage(kernel_filename
, &entry
, &loadaddr
, NULL
);
125 success
= load_elf(kernel_filename
, NULL
, NULL
, &elf_entry
,
126 &elf_lowaddr
, NULL
, 1, ELF_MACHINE
, 0);
128 loadaddr
= elf_lowaddr
;
130 /* XXX try again as binary */
132 fprintf(stderr
, "qemu: could not load kernel '%s'\n",
139 if (initrd_filename
) {
140 initrd_size
= load_image_targphys(initrd_filename
, RAMDISK_ADDR
,
141 ram_size
- RAMDISK_ADDR
);
143 if (initrd_size
< 0) {
144 fprintf(stderr
, "qemu: could not load ram disk '%s' at %x\n",
145 initrd_filename
, RAMDISK_ADDR
);
150 /* If we're loading a kernel directly, we must load the device tree too. */
151 if (kernel_filename
) {
152 if (bamboo_load_device_tree(FDT_ADDR
, ram_size
, RAMDISK_ADDR
,
153 initrd_size
, kernel_cmdline
) < 0) {
154 fprintf(stderr
, "couldn't load device tree\n");
158 /* Set initial guest state. */
159 env
->gpr
[1] = (16<<20) - 8;
160 env
->gpr
[3] = FDT_ADDR
;
162 /* XXX we currently depend on KVM to create some initial TLB entries. */
169 static QEMUMachine bamboo_machine
= {
170 .name
= "bamboo-0.13",
176 static QEMUMachine bamboo_machine_v0_12
= {
177 .name
= "bamboo-0.12",
180 .compat_props
= (GlobalProperty
[]) {
182 .driver
= "virtio-serial-pci",
183 .property
= "max_ports",
184 .value
= stringify(1),
186 .driver
= "virtio-serial-pci",
187 .property
= "vectors",
188 .value
= stringify(0),
190 { /* end of list */ }
194 static void bamboo_machine_init(void)
196 qemu_register_machine(&bamboo_machine
);
197 qemu_register_machine(&bamboo_machine_v0_12
);
200 machine_init(bamboo_machine_init
);