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