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"
26 #define BINARY_DEVICE_TREE_FILE "bamboo.dtb"
28 static void *bamboo_load_device_tree(target_phys_addr_t addr
,
30 target_phys_addr_t initrd_base
,
31 target_phys_addr_t initrd_size
,
32 const char *kernel_cmdline
)
36 uint32_t mem_reg_property
[] = { 0, 0, ramsize
};
41 filename
= qemu_find_file(QEMU_FILE_TYPE_BIOS
, BINARY_DEVICE_TREE_FILE
);
45 fdt
= load_device_tree(filename
, &fdt_size
);
51 /* Manipulate device tree in memory. */
53 ret
= qemu_devtree_setprop(fdt
, "/memory", "reg", mem_reg_property
,
54 sizeof(mem_reg_property
));
56 fprintf(stderr
, "couldn't set /memory/reg\n");
58 ret
= qemu_devtree_setprop_cell(fdt
, "/chosen", "linux,initrd-start",
61 fprintf(stderr
, "couldn't set /chosen/linux,initrd-start\n");
63 ret
= qemu_devtree_setprop_cell(fdt
, "/chosen", "linux,initrd-end",
64 (initrd_base
+ initrd_size
));
66 fprintf(stderr
, "couldn't set /chosen/linux,initrd-end\n");
68 ret
= qemu_devtree_setprop_string(fdt
, "/chosen", "bootargs",
71 fprintf(stderr
, "couldn't set /chosen/bootargs\n");
74 kvmppc_fdt_update(fdt
);
76 cpu_physical_memory_write (addr
, (void *)fdt
, fdt_size
);
84 static void bamboo_init(ram_addr_t ram_size
,
85 const char *boot_device
,
86 const char *kernel_filename
,
87 const char *kernel_cmdline
,
88 const char *initrd_filename
,
89 const char *cpu_model
)
91 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, cpu_model
);
112 /* Add virtio block devices. */
113 while ((i
= drive_get_index(IF_VIRTIO
, 0, unit_id
)) != -1) {
114 pci_dev
= pci_create("virtio-blk-pci", drives_table
[i
].devaddr
);
115 qdev_init(&pci_dev
->qdev
);
119 /* Add virtio console devices */
120 for(i
= 0; i
< MAX_VIRTIO_CONSOLES
; i
++) {
121 if (virtcon_hds
[i
]) {
122 pci_create_simple(pcibus
, -1, "virtio-console-pci");
126 /* Register network interfaces. */
127 for (i
= 0; i
< nb_nics
; i
++) {
128 /* There are no PCI NICs on the Bamboo board, but there are
129 * PCI slots, so we can pick whatever default model we want. */
130 pci_nic_init(&nd_table
[i
], "e1000", NULL
);
135 if (kernel_filename
) {
136 kernel_size
= load_uimage(kernel_filename
, &entry
, &loadaddr
, NULL
);
137 if (kernel_size
< 0) {
138 kernel_size
= load_elf(kernel_filename
, 0, &elf_entry
, &elf_lowaddr
,
141 loadaddr
= elf_lowaddr
;
143 /* XXX try again as binary */
144 if (kernel_size
< 0) {
145 fprintf(stderr
, "qemu: could not load kernel '%s'\n",
152 if (initrd_filename
) {
153 initrd_base
= kernel_size
+ loadaddr
;
154 initrd_size
= load_image_targphys(initrd_filename
, initrd_base
,
155 ram_size
- initrd_base
);
157 if (initrd_size
< 0) {
158 fprintf(stderr
, "qemu: could not load initial ram disk '%s'\n",
164 /* If we're loading a kernel directly, we must load the device tree too. */
165 if (kernel_filename
) {
167 dt_base
= initrd_base
+ initrd_size
;
169 dt_base
= kernel_size
+ loadaddr
;
171 fdt
= bamboo_load_device_tree(dt_base
, ram_size
,
172 initrd_base
, initrd_size
, kernel_cmdline
);
174 fprintf(stderr
, "couldn't load device tree\n");
178 /* Set initial guest state. */
179 env
->gpr
[1] = (16<<20) - 8;
180 env
->gpr
[3] = dt_base
;
182 /* XXX we currently depend on KVM to create some initial TLB entries. */
189 static QEMUMachine bamboo_machine
= {
195 static void bamboo_machine_init(void)
197 qemu_register_machine(&bamboo_machine
);
200 machine_init(bamboo_machine_init
);