]>
Commit | Line | Data |
---|---|---|
2c9fade2 AJ |
1 | /* |
2 | * Qemu PowerPC 440 Bamboo board emulation | |
3 | * | |
4 | * Copyright 2007 IBM Corporation. | |
5 | * Authors: | |
acd1bf90 AG |
6 | * Jerone Young <jyoung5@us.ibm.com> |
7 | * Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com> | |
8 | * Hollis Blanchard <hollisb@us.ibm.com> | |
2c9fade2 AJ |
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" | |
3e9f0113 | 26 | #include "exec-memory.h" |
2c9fade2 AJ |
27 | |
28 | #define BINARY_DEVICE_TREE_FILE "bamboo.dtb" | |
29 | ||
ceee6da6 HB |
30 | /* from u-boot */ |
31 | #define KERNEL_ADDR 0x1000000 | |
32 | #define FDT_ADDR 0x1800000 | |
33 | #define RAMDISK_ADDR 0x1900000 | |
34 | ||
b10a04b5 AG |
35 | static target_phys_addr_t entry; |
36 | ||
623f7c21 AG |
37 | static PCIBus *ppc4xx_pci_init(CPUState *env, qemu_irq pci_irqs[4], |
38 | target_phys_addr_t config_space, | |
39 | target_phys_addr_t int_ack, | |
40 | target_phys_addr_t special_cycle, | |
41 | target_phys_addr_t registers) | |
42 | { | |
43 | return NULL; | |
44 | } | |
45 | ||
04088adb | 46 | static int bamboo_load_device_tree(target_phys_addr_t addr, |
2c9fade2 | 47 | uint32_t ramsize, |
c227f099 AL |
48 | target_phys_addr_t initrd_base, |
49 | target_phys_addr_t initrd_size, | |
2c9fade2 AJ |
50 | const char *kernel_cmdline) |
51 | { | |
dbf916d8 | 52 | int ret = -1; |
3f0855b1 | 53 | #ifdef CONFIG_FDT |
2c9fade2 | 54 | uint32_t mem_reg_property[] = { 0, 0, ramsize }; |
5cea8590 | 55 | char *filename; |
7ec632b4 | 56 | int fdt_size; |
dbf916d8 | 57 | void *fdt; |
7dadd40c AG |
58 | uint32_t tb_freq = 400000000; |
59 | uint32_t clock_freq = 400000000; | |
2c9fade2 | 60 | |
5cea8590 PB |
61 | filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, BINARY_DEVICE_TREE_FILE); |
62 | if (!filename) { | |
63 | goto out; | |
64 | } | |
65 | fdt = load_device_tree(filename, &fdt_size); | |
7267c094 | 66 | g_free(filename); |
5cea8590 | 67 | if (fdt == NULL) { |
2c9fade2 | 68 | goto out; |
5cea8590 | 69 | } |
2c9fade2 AJ |
70 | |
71 | /* Manipulate device tree in memory. */ | |
72 | ||
73 | ret = qemu_devtree_setprop(fdt, "/memory", "reg", mem_reg_property, | |
74 | sizeof(mem_reg_property)); | |
75 | if (ret < 0) | |
76 | fprintf(stderr, "couldn't set /memory/reg\n"); | |
77 | ||
78 | ret = qemu_devtree_setprop_cell(fdt, "/chosen", "linux,initrd-start", | |
79 | initrd_base); | |
80 | if (ret < 0) | |
81 | fprintf(stderr, "couldn't set /chosen/linux,initrd-start\n"); | |
82 | ||
83 | ret = qemu_devtree_setprop_cell(fdt, "/chosen", "linux,initrd-end", | |
84 | (initrd_base + initrd_size)); | |
85 | if (ret < 0) | |
86 | fprintf(stderr, "couldn't set /chosen/linux,initrd-end\n"); | |
87 | ||
88 | ret = qemu_devtree_setprop_string(fdt, "/chosen", "bootargs", | |
89 | kernel_cmdline); | |
90 | if (ret < 0) | |
91 | fprintf(stderr, "couldn't set /chosen/bootargs\n"); | |
92 | ||
7dadd40c AG |
93 | /* Copy data from the host device tree into the guest. Since the guest can |
94 | * directly access the timebase without host involvement, we must expose | |
95 | * the correct frequencies. */ | |
a489f7f7 | 96 | if (kvm_enabled()) { |
7dadd40c AG |
97 | tb_freq = kvmppc_get_tbfreq(); |
98 | clock_freq = kvmppc_get_clockfreq(); | |
a489f7f7 | 99 | } |
2c9fade2 | 100 | |
7dadd40c AG |
101 | qemu_devtree_setprop_cell(fdt, "/cpus/cpu@0", "clock-frequency", |
102 | clock_freq); | |
103 | qemu_devtree_setprop_cell(fdt, "/cpus/cpu@0", "timebase-frequency", | |
104 | tb_freq); | |
2c9fade2 | 105 | |
04088adb | 106 | ret = rom_add_blob_fixed(BINARY_DEVICE_TREE_FILE, fdt, fdt_size, addr); |
7267c094 | 107 | g_free(fdt); |
7ec632b4 | 108 | |
2c9fade2 AJ |
109 | out: |
110 | #endif | |
111 | ||
04088adb | 112 | return ret; |
2c9fade2 AJ |
113 | } |
114 | ||
72718e9a AG |
115 | /* Create reset TLB entries for BookE, spanning the 32bit addr space. */ |
116 | static void mmubooke_create_initial_mapping(CPUState *env, | |
117 | target_ulong va, | |
118 | target_phys_addr_t pa) | |
119 | { | |
120 | ppcemb_tlb_t *tlb = &env->tlb.tlbe[0]; | |
121 | ||
122 | tlb->attr = 0; | |
123 | tlb->prot = PAGE_VALID | ((PAGE_READ | PAGE_WRITE | PAGE_EXEC) << 4); | |
124 | tlb->size = 1 << 31; /* up to 0x80000000 */ | |
125 | tlb->EPN = va & TARGET_PAGE_MASK; | |
126 | tlb->RPN = pa & TARGET_PAGE_MASK; | |
127 | tlb->PID = 0; | |
128 | ||
129 | tlb = &env->tlb.tlbe[1]; | |
130 | tlb->attr = 0; | |
131 | tlb->prot = PAGE_VALID | ((PAGE_READ | PAGE_WRITE | PAGE_EXEC) << 4); | |
132 | tlb->size = 1 << 31; /* up to 0xffffffff */ | |
133 | tlb->EPN = 0x80000000 & TARGET_PAGE_MASK; | |
134 | tlb->RPN = 0x80000000 & TARGET_PAGE_MASK; | |
135 | tlb->PID = 0; | |
136 | } | |
137 | ||
b10a04b5 AG |
138 | static void main_cpu_reset(void *opaque) |
139 | { | |
140 | CPUState *env = opaque; | |
141 | ||
142 | cpu_reset(env); | |
143 | env->gpr[1] = (16<<20) - 8; | |
144 | env->gpr[3] = FDT_ADDR; | |
145 | env->nip = entry; | |
72718e9a AG |
146 | |
147 | /* Create a mapping for the kernel. */ | |
148 | mmubooke_create_initial_mapping(env, 0, 0); | |
b10a04b5 AG |
149 | } |
150 | ||
c227f099 | 151 | static void bamboo_init(ram_addr_t ram_size, |
a147d62b | 152 | const char *boot_device, |
2c9fade2 AJ |
153 | const char *kernel_filename, |
154 | const char *kernel_cmdline, | |
155 | const char *initrd_filename, | |
156 | const char *cpu_model) | |
157 | { | |
158 | unsigned int pci_irq_nrs[4] = { 28, 27, 26, 25 }; | |
3e9f0113 | 159 | MemoryRegion *address_space_mem = get_system_memory(); |
2c9fade2 AJ |
160 | PCIBus *pcibus; |
161 | CPUState *env; | |
162 | uint64_t elf_entry; | |
163 | uint64_t elf_lowaddr; | |
c227f099 | 164 | target_phys_addr_t loadaddr = 0; |
2c9fade2 | 165 | target_long initrd_size = 0; |
ceee6da6 | 166 | int success; |
2c9fade2 AJ |
167 | int i; |
168 | ||
169 | /* Setup CPU. */ | |
3e9f0113 RH |
170 | env = ppc440ep_init(address_space_mem, &ram_size, &pcibus, |
171 | pci_irq_nrs, 1, cpu_model); | |
b10a04b5 | 172 | qemu_register_reset(main_cpu_reset, env); |
2c9fade2 AJ |
173 | |
174 | if (pcibus) { | |
2c9fade2 AJ |
175 | /* Register network interfaces. */ |
176 | for (i = 0; i < nb_nics; i++) { | |
cb457d76 AL |
177 | /* There are no PCI NICs on the Bamboo board, but there are |
178 | * PCI slots, so we can pick whatever default model we want. */ | |
07caea31 | 179 | pci_nic_init_nofail(&nd_table[i], "e1000", NULL); |
2c9fade2 AJ |
180 | } |
181 | } | |
182 | ||
183 | /* Load kernel. */ | |
184 | if (kernel_filename) { | |
ceee6da6 HB |
185 | success = load_uimage(kernel_filename, &entry, &loadaddr, NULL); |
186 | if (success < 0) { | |
187 | success = load_elf(kernel_filename, NULL, NULL, &elf_entry, | |
188 | &elf_lowaddr, NULL, 1, ELF_MACHINE, 0); | |
2c9fade2 AJ |
189 | entry = elf_entry; |
190 | loadaddr = elf_lowaddr; | |
191 | } | |
192 | /* XXX try again as binary */ | |
ceee6da6 | 193 | if (success < 0) { |
2c9fade2 AJ |
194 | fprintf(stderr, "qemu: could not load kernel '%s'\n", |
195 | kernel_filename); | |
196 | exit(1); | |
197 | } | |
198 | } | |
199 | ||
200 | /* Load initrd. */ | |
201 | if (initrd_filename) { | |
ceee6da6 HB |
202 | initrd_size = load_image_targphys(initrd_filename, RAMDISK_ADDR, |
203 | ram_size - RAMDISK_ADDR); | |
2c9fade2 AJ |
204 | |
205 | if (initrd_size < 0) { | |
ceee6da6 HB |
206 | fprintf(stderr, "qemu: could not load ram disk '%s' at %x\n", |
207 | initrd_filename, RAMDISK_ADDR); | |
2c9fade2 AJ |
208 | exit(1); |
209 | } | |
210 | } | |
211 | ||
212 | /* If we're loading a kernel directly, we must load the device tree too. */ | |
213 | if (kernel_filename) { | |
ceee6da6 HB |
214 | if (bamboo_load_device_tree(FDT_ADDR, ram_size, RAMDISK_ADDR, |
215 | initrd_size, kernel_cmdline) < 0) { | |
2c9fade2 AJ |
216 | fprintf(stderr, "couldn't load device tree\n"); |
217 | exit(1); | |
218 | } | |
2c9fade2 AJ |
219 | } |
220 | ||
221 | if (kvm_enabled()) | |
222 | kvmppc_init(); | |
223 | } | |
224 | ||
f80f9ec9 | 225 | static QEMUMachine bamboo_machine = { |
d3c4548b | 226 | .name = "bamboo", |
977b6b91 AS |
227 | .desc = "bamboo", |
228 | .init = bamboo_init, | |
977b6b91 AS |
229 | }; |
230 | ||
f80f9ec9 AL |
231 | static void bamboo_machine_init(void) |
232 | { | |
233 | qemu_register_machine(&bamboo_machine); | |
234 | } | |
235 | ||
236 | machine_init(bamboo_machine_init); |