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"
24 #include "device_tree.h"
28 #define BINARY_DEVICE_TREE_FILE "bamboo.dtb"
30 static void *bamboo_load_device_tree(target_phys_addr_t addr
,
32 target_phys_addr_t initrd_base
,
33 target_phys_addr_t initrd_size
,
34 const char *kernel_cmdline
)
38 uint32_t mem_reg_property
[] = { 0, 0, ramsize
};
43 filename
= qemu_find_file(QEMU_FILE_TYPE_BIOS
, BINARY_DEVICE_TREE_FILE
);
47 fdt
= load_device_tree(filename
, &fdt_size
);
53 /* Manipulate device tree in memory. */
55 ret
= qemu_devtree_setprop(fdt
, "/memory", "reg", mem_reg_property
,
56 sizeof(mem_reg_property
));
58 fprintf(stderr
, "couldn't set /memory/reg\n");
60 ret
= qemu_devtree_setprop_cell(fdt
, "/chosen", "linux,initrd-start",
63 fprintf(stderr
, "couldn't set /chosen/linux,initrd-start\n");
65 ret
= qemu_devtree_setprop_cell(fdt
, "/chosen", "linux,initrd-end",
66 (initrd_base
+ initrd_size
));
68 fprintf(stderr
, "couldn't set /chosen/linux,initrd-end\n");
70 ret
= qemu_devtree_setprop_string(fdt
, "/chosen", "bootargs",
73 fprintf(stderr
, "couldn't set /chosen/bootargs\n");
76 kvmppc_fdt_update(fdt
);
78 cpu_physical_memory_write (addr
, (void *)fdt
, fdt_size
);
86 static void bamboo_init(ram_addr_t ram_size
,
87 const char *boot_device
,
88 const char *kernel_filename
,
89 const char *kernel_cmdline
,
90 const char *initrd_filename
,
91 const char *cpu_model
)
93 unsigned int pci_irq_nrs
[4] = { 28, 27, 26, 25 };
98 target_phys_addr_t entry
= 0;
99 target_phys_addr_t loadaddr
= 0;
100 target_long kernel_size
= 0;
101 target_ulong initrd_base
= 0;
102 target_long initrd_size
= 0;
103 target_ulong dt_base
= 0;
108 env
= ppc440ep_init(&ram_size
, &pcibus
, pci_irq_nrs
, 1, cpu_model
);
111 /* Register network interfaces. */
112 for (i
= 0; i
< nb_nics
; i
++) {
113 /* There are no PCI NICs on the Bamboo board, but there are
114 * PCI slots, so we can pick whatever default model we want. */
115 pci_nic_init_nofail(&nd_table
[i
], "e1000", NULL
);
120 if (kernel_filename
) {
121 kernel_size
= load_uimage(kernel_filename
, &entry
, &loadaddr
, NULL
);
122 if (kernel_size
< 0) {
123 kernel_size
= load_elf(kernel_filename
, 0, &elf_entry
, &elf_lowaddr
,
124 NULL
, 1, ELF_MACHINE
, 0);
126 loadaddr
= elf_lowaddr
;
128 /* XXX try again as binary */
129 if (kernel_size
< 0) {
130 fprintf(stderr
, "qemu: could not load kernel '%s'\n",
137 if (initrd_filename
) {
138 initrd_base
= kernel_size
+ loadaddr
;
139 initrd_size
= load_image_targphys(initrd_filename
, initrd_base
,
140 ram_size
- initrd_base
);
142 if (initrd_size
< 0) {
143 fprintf(stderr
, "qemu: could not load initial ram disk '%s'\n",
149 /* If we're loading a kernel directly, we must load the device tree too. */
150 if (kernel_filename
) {
152 dt_base
= initrd_base
+ initrd_size
;
154 dt_base
= kernel_size
+ loadaddr
;
156 fdt
= bamboo_load_device_tree(dt_base
, ram_size
,
157 initrd_base
, initrd_size
, kernel_cmdline
);
159 fprintf(stderr
, "couldn't load device tree\n");
163 /* Set initial guest state. */
164 env
->gpr
[1] = (16<<20) - 8;
165 env
->gpr
[3] = dt_base
;
167 /* XXX we currently depend on KVM to create some initial TLB entries. */
174 static QEMUMachine bamboo_machine
= {
180 static void bamboo_machine_init(void)
182 qemu_register_machine(&bamboo_machine
);
185 machine_init(bamboo_machine_init
);