pcnet: address TODOs
[qemu/qemu-dev-zwu.git] / hw / ppc440_bamboo.c
blob6ca873ee7eeb179eccaccb786800fb1da172fc1f
1 /*
2 * Qemu PowerPC 440 Bamboo board emulation
4 * Copyright 2007 IBM Corporation.
5 * Authors:
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.
14 #include "config.h"
15 #include "qemu-common.h"
16 #include "net.h"
17 #include "hw.h"
18 #include "pci.h"
19 #include "boards.h"
20 #include "sysemu.h"
21 #include "ppc440.h"
22 #include "kvm.h"
23 #include "kvm_ppc.h"
24 #include "device_tree.h"
25 #include "loader.h"
26 #include "elf.h"
28 #define BINARY_DEVICE_TREE_FILE "bamboo.dtb"
30 static int bamboo_load_device_tree(target_phys_addr_t addr,
31 uint32_t ramsize,
32 target_phys_addr_t initrd_base,
33 target_phys_addr_t initrd_size,
34 const char *kernel_cmdline)
36 int ret = -1;
37 #ifdef CONFIG_FDT
38 uint32_t mem_reg_property[] = { 0, 0, ramsize };
39 char *filename;
40 int fdt_size;
41 void *fdt;
43 filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, BINARY_DEVICE_TREE_FILE);
44 if (!filename) {
45 goto out;
47 fdt = load_device_tree(filename, &fdt_size);
48 qemu_free(filename);
49 if (fdt == NULL) {
50 goto out;
53 /* Manipulate device tree in memory. */
55 ret = qemu_devtree_setprop(fdt, "/memory", "reg", mem_reg_property,
56 sizeof(mem_reg_property));
57 if (ret < 0)
58 fprintf(stderr, "couldn't set /memory/reg\n");
60 ret = qemu_devtree_setprop_cell(fdt, "/chosen", "linux,initrd-start",
61 initrd_base);
62 if (ret < 0)
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));
67 if (ret < 0)
68 fprintf(stderr, "couldn't set /chosen/linux,initrd-end\n");
70 ret = qemu_devtree_setprop_string(fdt, "/chosen", "bootargs",
71 kernel_cmdline);
72 if (ret < 0)
73 fprintf(stderr, "couldn't set /chosen/bootargs\n");
75 if (kvm_enabled())
76 kvmppc_fdt_update(fdt);
78 ret = rom_add_blob_fixed(BINARY_DEVICE_TREE_FILE, fdt, fdt_size, addr);
79 qemu_free(fdt);
81 out:
82 #endif
84 return ret;
87 static void bamboo_init(ram_addr_t ram_size,
88 const char *boot_device,
89 const char *kernel_filename,
90 const char *kernel_cmdline,
91 const char *initrd_filename,
92 const char *cpu_model)
94 unsigned int pci_irq_nrs[4] = { 28, 27, 26, 25 };
95 PCIBus *pcibus;
96 CPUState *env;
97 uint64_t elf_entry;
98 uint64_t elf_lowaddr;
99 target_phys_addr_t entry = 0;
100 target_phys_addr_t loadaddr = 0;
101 target_long kernel_size = 0;
102 target_ulong initrd_base = 0;
103 target_long initrd_size = 0;
104 target_ulong dt_base = 0;
105 int i;
107 /* Setup CPU. */
108 env = ppc440ep_init(&ram_size, &pcibus, pci_irq_nrs, 1, cpu_model);
110 if (pcibus) {
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);
119 /* Load kernel. */
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, NULL, NULL, &elf_entry,
124 &elf_lowaddr, NULL, 1, ELF_MACHINE, 0);
125 entry = elf_entry;
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",
131 kernel_filename);
132 exit(1);
136 /* Load initrd. */
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",
144 initrd_filename);
145 exit(1);
149 /* If we're loading a kernel directly, we must load the device tree too. */
150 if (kernel_filename) {
151 if (initrd_base)
152 dt_base = initrd_base + initrd_size;
153 else
154 dt_base = kernel_size + loadaddr;
156 if (bamboo_load_device_tree(dt_base, ram_size,
157 initrd_base, initrd_size, kernel_cmdline) < 0) {
158 fprintf(stderr, "couldn't load device tree\n");
159 exit(1);
162 cpu_synchronize_state(env);
164 /* Set initial guest state. */
165 env->gpr[1] = (16<<20) - 8;
166 env->gpr[3] = dt_base;
167 env->nip = entry;
168 /* XXX we currently depend on KVM to create some initial TLB entries. */
171 if (kvm_enabled())
172 kvmppc_init();
175 static QEMUMachine bamboo_machine = {
176 .name = "bamboo-0.13",
177 .alias = "bamboo",
178 .desc = "bamboo",
179 .init = bamboo_init,
182 static QEMUMachine bamboo_machine_v0_12 = {
183 .name = "bamboo-0.12",
184 .desc = "bamboo",
185 .init = bamboo_init,
186 .compat_props = (GlobalProperty[]) {
188 .driver = "virtio-serial-pci",
189 .property = "max_nr_ports",
190 .value = stringify(1),
192 .driver = "virtio-serial-pci",
193 .property = "vectors",
194 .value = stringify(0),
196 { /* end of list */ }
200 static void bamboo_machine_init(void)
202 qemu_register_machine(&bamboo_machine);
203 qemu_register_machine(&bamboo_machine_v0_12);
206 machine_init(bamboo_machine_init);