]>
Commit | Line | Data |
---|---|---|
2c9fade2 AJ |
1 | /* |
2 | * Qemu PowerPC 440 Bamboo board emulation | |
3 | * | |
4 | * Copyright 2007 IBM Corporation. | |
5 | * Authors: | |
6 | * Jerone Young <[email protected]> | |
7 | * Christian Ehrhardt <[email protected]> | |
8 | * Hollis Blanchard <[email protected]> | |
9 | * | |
10 | * This work is licensed under the GNU GPL license version 2 or later. | |
11 | * | |
12 | */ | |
13 | ||
14 | #include "config.h" | |
15 | #include "qemu-common.h" | |
16 | #include "net.h" | |
17 | #include "hw.h" | |
18 | #include "pci.h" | |
2c9fade2 | 19 | #include "boards.h" |
2c9fade2 AJ |
20 | #include "ppc440.h" |
21 | #include "kvm.h" | |
22 | #include "kvm_ppc.h" | |
23 | #include "device_tree.h" | |
ca20cf32 BS |
24 | #include "loader.h" |
25 | #include "elf.h" | |
2c9fade2 AJ |
26 | |
27 | #define BINARY_DEVICE_TREE_FILE "bamboo.dtb" | |
28 | ||
ceee6da6 HB |
29 | /* from u-boot */ |
30 | #define KERNEL_ADDR 0x1000000 | |
31 | #define FDT_ADDR 0x1800000 | |
32 | #define RAMDISK_ADDR 0x1900000 | |
33 | ||
a489f7f7 AG |
34 | #ifdef CONFIG_FDT |
35 | static int bamboo_copy_host_cell(void *fdt, const char *node, const char *prop) | |
36 | { | |
37 | uint32_t cell; | |
38 | int ret; | |
39 | ||
40 | ret = kvmppc_read_host_property(node, prop, &cell, sizeof(cell)); | |
41 | if (ret < 0) { | |
42 | fprintf(stderr, "couldn't read host %s/%s\n", node, prop); | |
43 | goto out; | |
44 | } | |
45 | ||
46 | ret = qemu_devtree_setprop_cell(fdt, node, prop, cell); | |
47 | if (ret < 0) { | |
48 | fprintf(stderr, "couldn't set guest %s/%s\n", node, prop); | |
49 | goto out; | |
50 | } | |
51 | ||
52 | out: | |
53 | return ret; | |
54 | } | |
55 | ||
56 | static void bamboo_fdt_update(void *fdt) | |
57 | { | |
58 | /* Copy data from the host device tree into the guest. Since the guest can | |
59 | * directly access the timebase without host involvement, we must expose | |
60 | * the correct frequencies. */ | |
61 | bamboo_copy_host_cell(fdt, "/cpus/cpu@0", "clock-frequency"); | |
62 | bamboo_copy_host_cell(fdt, "/cpus/cpu@0", "timebase-frequency"); | |
63 | } | |
64 | #endif | |
65 | ||
04088adb | 66 | static int bamboo_load_device_tree(target_phys_addr_t addr, |
2c9fade2 | 67 | uint32_t ramsize, |
c227f099 AL |
68 | target_phys_addr_t initrd_base, |
69 | target_phys_addr_t initrd_size, | |
2c9fade2 AJ |
70 | const char *kernel_cmdline) |
71 | { | |
dbf916d8 | 72 | int ret = -1; |
3f0855b1 | 73 | #ifdef CONFIG_FDT |
2c9fade2 | 74 | uint32_t mem_reg_property[] = { 0, 0, ramsize }; |
5cea8590 | 75 | char *filename; |
7ec632b4 | 76 | int fdt_size; |
dbf916d8 | 77 | void *fdt; |
2c9fade2 | 78 | |
5cea8590 PB |
79 | filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, BINARY_DEVICE_TREE_FILE); |
80 | if (!filename) { | |
81 | goto out; | |
82 | } | |
83 | fdt = load_device_tree(filename, &fdt_size); | |
7267c094 | 84 | g_free(filename); |
5cea8590 | 85 | if (fdt == NULL) { |
2c9fade2 | 86 | goto out; |
5cea8590 | 87 | } |
2c9fade2 AJ |
88 | |
89 | /* Manipulate device tree in memory. */ | |
90 | ||
91 | ret = qemu_devtree_setprop(fdt, "/memory", "reg", mem_reg_property, | |
92 | sizeof(mem_reg_property)); | |
93 | if (ret < 0) | |
94 | fprintf(stderr, "couldn't set /memory/reg\n"); | |
95 | ||
96 | ret = qemu_devtree_setprop_cell(fdt, "/chosen", "linux,initrd-start", | |
97 | initrd_base); | |
98 | if (ret < 0) | |
99 | fprintf(stderr, "couldn't set /chosen/linux,initrd-start\n"); | |
100 | ||
101 | ret = qemu_devtree_setprop_cell(fdt, "/chosen", "linux,initrd-end", | |
102 | (initrd_base + initrd_size)); | |
103 | if (ret < 0) | |
104 | fprintf(stderr, "couldn't set /chosen/linux,initrd-end\n"); | |
105 | ||
106 | ret = qemu_devtree_setprop_string(fdt, "/chosen", "bootargs", | |
107 | kernel_cmdline); | |
108 | if (ret < 0) | |
109 | fprintf(stderr, "couldn't set /chosen/bootargs\n"); | |
110 | ||
a489f7f7 AG |
111 | if (kvm_enabled()) { |
112 | bamboo_fdt_update(fdt); | |
113 | } | |
2c9fade2 | 114 | |
04088adb | 115 | ret = rom_add_blob_fixed(BINARY_DEVICE_TREE_FILE, fdt, fdt_size, addr); |
7267c094 | 116 | g_free(fdt); |
7ec632b4 | 117 | |
2c9fade2 AJ |
118 | out: |
119 | #endif | |
120 | ||
04088adb | 121 | return ret; |
2c9fade2 AJ |
122 | } |
123 | ||
c227f099 | 124 | static void bamboo_init(ram_addr_t ram_size, |
a147d62b | 125 | const char *boot_device, |
2c9fade2 AJ |
126 | const char *kernel_filename, |
127 | const char *kernel_cmdline, | |
128 | const char *initrd_filename, | |
129 | const char *cpu_model) | |
130 | { | |
131 | unsigned int pci_irq_nrs[4] = { 28, 27, 26, 25 }; | |
2c9fade2 AJ |
132 | PCIBus *pcibus; |
133 | CPUState *env; | |
134 | uint64_t elf_entry; | |
135 | uint64_t elf_lowaddr; | |
c227f099 AL |
136 | target_phys_addr_t entry = 0; |
137 | target_phys_addr_t loadaddr = 0; | |
2c9fade2 | 138 | target_long initrd_size = 0; |
ceee6da6 | 139 | int success; |
2c9fade2 AJ |
140 | int i; |
141 | ||
142 | /* Setup CPU. */ | |
727170b6 | 143 | env = ppc440ep_init(&ram_size, &pcibus, pci_irq_nrs, 1, cpu_model); |
2c9fade2 AJ |
144 | |
145 | if (pcibus) { | |
2c9fade2 AJ |
146 | /* Register network interfaces. */ |
147 | for (i = 0; i < nb_nics; i++) { | |
cb457d76 AL |
148 | /* There are no PCI NICs on the Bamboo board, but there are |
149 | * PCI slots, so we can pick whatever default model we want. */ | |
07caea31 | 150 | pci_nic_init_nofail(&nd_table[i], "e1000", NULL); |
2c9fade2 AJ |
151 | } |
152 | } | |
153 | ||
154 | /* Load kernel. */ | |
155 | if (kernel_filename) { | |
ceee6da6 HB |
156 | success = load_uimage(kernel_filename, &entry, &loadaddr, NULL); |
157 | if (success < 0) { | |
158 | success = load_elf(kernel_filename, NULL, NULL, &elf_entry, | |
159 | &elf_lowaddr, NULL, 1, ELF_MACHINE, 0); | |
2c9fade2 AJ |
160 | entry = elf_entry; |
161 | loadaddr = elf_lowaddr; | |
162 | } | |
163 | /* XXX try again as binary */ | |
ceee6da6 | 164 | if (success < 0) { |
2c9fade2 AJ |
165 | fprintf(stderr, "qemu: could not load kernel '%s'\n", |
166 | kernel_filename); | |
167 | exit(1); | |
168 | } | |
169 | } | |
170 | ||
171 | /* Load initrd. */ | |
172 | if (initrd_filename) { | |
ceee6da6 HB |
173 | initrd_size = load_image_targphys(initrd_filename, RAMDISK_ADDR, |
174 | ram_size - RAMDISK_ADDR); | |
2c9fade2 AJ |
175 | |
176 | if (initrd_size < 0) { | |
ceee6da6 HB |
177 | fprintf(stderr, "qemu: could not load ram disk '%s' at %x\n", |
178 | initrd_filename, RAMDISK_ADDR); | |
2c9fade2 AJ |
179 | exit(1); |
180 | } | |
181 | } | |
182 | ||
183 | /* If we're loading a kernel directly, we must load the device tree too. */ | |
184 | if (kernel_filename) { | |
ceee6da6 HB |
185 | if (bamboo_load_device_tree(FDT_ADDR, ram_size, RAMDISK_ADDR, |
186 | initrd_size, kernel_cmdline) < 0) { | |
2c9fade2 AJ |
187 | fprintf(stderr, "couldn't load device tree\n"); |
188 | exit(1); | |
189 | } | |
190 | ||
191 | /* Set initial guest state. */ | |
192 | env->gpr[1] = (16<<20) - 8; | |
ceee6da6 | 193 | env->gpr[3] = FDT_ADDR; |
2c9fade2 AJ |
194 | env->nip = entry; |
195 | /* XXX we currently depend on KVM to create some initial TLB entries. */ | |
196 | } | |
197 | ||
198 | if (kvm_enabled()) | |
199 | kvmppc_init(); | |
200 | } | |
201 | ||
f80f9ec9 | 202 | static QEMUMachine bamboo_machine = { |
977b6b91 AS |
203 | .name = "bamboo-0.13", |
204 | .alias = "bamboo", | |
205 | .desc = "bamboo", | |
206 | .init = bamboo_init, | |
977b6b91 AS |
207 | }; |
208 | ||
209 | static QEMUMachine bamboo_machine_v0_12 = { | |
210 | .name = "bamboo-0.12", | |
2c9fade2 AJ |
211 | .desc = "bamboo", |
212 | .init = bamboo_init, | |
21be440c AS |
213 | .compat_props = (GlobalProperty[]) { |
214 | { | |
215 | .driver = "virtio-serial-pci", | |
1e29a009 | 216 | .property = "max_ports", |
21be440c AS |
217 | .value = stringify(1), |
218 | },{ | |
219 | .driver = "virtio-serial-pci", | |
220 | .property = "vectors", | |
221 | .value = stringify(0), | |
222 | }, | |
223 | { /* end of list */ } | |
224 | }, | |
2c9fade2 | 225 | }; |
f80f9ec9 AL |
226 | |
227 | static void bamboo_machine_init(void) | |
228 | { | |
229 | qemu_register_machine(&bamboo_machine); | |
977b6b91 | 230 | qemu_register_machine(&bamboo_machine_v0_12); |
f80f9ec9 AL |
231 | } |
232 | ||
233 | machine_init(bamboo_machine_init); |