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"
19 #include "virtio-blk.h"
25 #include "device_tree.h"
27 #define BINARY_DEVICE_TREE_FILE "bamboo.dtb"
29 static void *bamboo_load_device_tree(void *addr
,
31 target_phys_addr_t initrd_base
,
32 target_phys_addr_t initrd_size
,
33 const char *kernel_cmdline
)
37 uint32_t mem_reg_property
[] = { 0, 0, ramsize
};
42 pathlen
= snprintf(NULL
, 0, "%s/%s", bios_dir
, BINARY_DEVICE_TREE_FILE
) + 1;
43 path
= qemu_malloc(pathlen
);
47 snprintf(path
, pathlen
, "%s/%s", bios_dir
, BINARY_DEVICE_TREE_FILE
);
49 fdt
= load_device_tree(path
, addr
);
54 /* Manipulate device tree in memory. */
56 ret
= qemu_devtree_setprop(fdt
, "/memory", "reg", mem_reg_property
,
57 sizeof(mem_reg_property
));
59 fprintf(stderr
, "couldn't set /memory/reg\n");
61 ret
= qemu_devtree_setprop_cell(fdt
, "/chosen", "linux,initrd-start",
64 fprintf(stderr
, "couldn't set /chosen/linux,initrd-start\n");
66 ret
= qemu_devtree_setprop_cell(fdt
, "/chosen", "linux,initrd-end",
67 (initrd_base
+ initrd_size
));
69 fprintf(stderr
, "couldn't set /chosen/linux,initrd-end\n");
71 ret
= qemu_devtree_setprop_string(fdt
, "/chosen", "bootargs",
74 fprintf(stderr
, "couldn't set /chosen/bootargs\n");
77 kvmppc_fdt_update(fdt
);
85 static void bamboo_init(ram_addr_t ram_size
, int vga_ram_size
,
86 const char *boot_device
, DisplayState
*ds
,
87 const char *kernel_filename
,
88 const char *kernel_cmdline
,
89 const char *initrd_filename
,
90 const char *cpu_model
)
92 unsigned int pci_irq_nrs
[4] = { 28, 27, 26, 25 };
97 target_ulong entry
= 0;
98 target_ulong loadaddr
= 0;
99 target_long kernel_size
= 0;
100 target_ulong initrd_base
= 0;
101 target_long initrd_size
= 0;
102 target_ulong dt_base
= 0;
107 env
= ppc440ep_init(&ram_size
, &pcibus
, pci_irq_nrs
, 1);
112 /* Add virtio block devices. */
113 while ((i
= drive_get_index(IF_VIRTIO
, 0, unit_id
)) != -1) {
114 virtio_blk_init(pcibus
, drives_table
[i
].bdrv
);
118 /* Register network interfaces. */
119 for (i
= 0; i
< nb_nics
; i
++) {
120 /* There are no PCI NICs on the Bamboo board, but there are
121 * PCI slots, so we can pick whatever default model we want. */
122 pci_nic_init(pcibus
, &nd_table
[i
], -1, "e1000");
127 if (kernel_filename
) {
128 kernel_size
= load_uimage(kernel_filename
, &entry
, &loadaddr
, NULL
);
129 if (kernel_size
< 0) {
130 kernel_size
= load_elf(kernel_filename
, 0, &elf_entry
, &elf_lowaddr
,
133 loadaddr
= elf_lowaddr
;
135 /* XXX try again as binary */
136 if (kernel_size
< 0) {
137 fprintf(stderr
, "qemu: could not load kernel '%s'\n",
144 if (initrd_filename
) {
145 initrd_base
= kernel_size
+ loadaddr
;
146 initrd_size
= load_image(initrd_filename
, phys_ram_base
+ initrd_base
);
148 if (initrd_size
< 0) {
149 fprintf(stderr
, "qemu: could not load initial ram disk '%s'\n",
155 /* If we're loading a kernel directly, we must load the device tree too. */
156 if (kernel_filename
) {
158 dt_base
= initrd_base
+ initrd_size
;
160 dt_base
= kernel_size
+ loadaddr
;
162 fdt
= bamboo_load_device_tree(phys_ram_base
+ dt_base
, ram_size
,
163 initrd_base
, initrd_size
, kernel_cmdline
);
165 fprintf(stderr
, "couldn't load device tree\n");
169 /* Set initial guest state. */
170 env
->gpr
[1] = (16<<20) - 8;
171 env
->gpr
[3] = dt_base
;
173 /* XXX we currently depend on KVM to create some initial TLB entries. */
180 QEMUMachine bamboo_machine
= {
184 .ram_require
= 8<<20 | RAMSIZE_FIXED
,