x86/cpuid: Fix crash on -cpu ""
[qemu/ar7.git] / hw / ppc440_bamboo.c
blobb734e3a56c636e635ca6dd724fd45a6edcd6ecba
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 "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"
28 #define BINARY_DEVICE_TREE_FILE "bamboo.dtb"
30 /* from u-boot */
31 #define KERNEL_ADDR 0x1000000
32 #define FDT_ADDR 0x1800000
33 #define RAMDISK_ADDR 0x1900000
35 static int bamboo_load_device_tree(target_phys_addr_t addr,
36 uint32_t ramsize,
37 target_phys_addr_t initrd_base,
38 target_phys_addr_t initrd_size,
39 const char *kernel_cmdline)
41 int ret = -1;
42 #ifdef CONFIG_FDT
43 uint32_t mem_reg_property[] = { 0, 0, ramsize };
44 char *filename;
45 int fdt_size;
46 void *fdt;
47 uint32_t tb_freq = 400000000;
48 uint32_t clock_freq = 400000000;
50 filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, BINARY_DEVICE_TREE_FILE);
51 if (!filename) {
52 goto out;
54 fdt = load_device_tree(filename, &fdt_size);
55 g_free(filename);
56 if (fdt == NULL) {
57 goto out;
60 /* Manipulate device tree in memory. */
62 ret = qemu_devtree_setprop(fdt, "/memory", "reg", mem_reg_property,
63 sizeof(mem_reg_property));
64 if (ret < 0)
65 fprintf(stderr, "couldn't set /memory/reg\n");
67 ret = qemu_devtree_setprop_cell(fdt, "/chosen", "linux,initrd-start",
68 initrd_base);
69 if (ret < 0)
70 fprintf(stderr, "couldn't set /chosen/linux,initrd-start\n");
72 ret = qemu_devtree_setprop_cell(fdt, "/chosen", "linux,initrd-end",
73 (initrd_base + initrd_size));
74 if (ret < 0)
75 fprintf(stderr, "couldn't set /chosen/linux,initrd-end\n");
77 ret = qemu_devtree_setprop_string(fdt, "/chosen", "bootargs",
78 kernel_cmdline);
79 if (ret < 0)
80 fprintf(stderr, "couldn't set /chosen/bootargs\n");
82 /* Copy data from the host device tree into the guest. Since the guest can
83 * directly access the timebase without host involvement, we must expose
84 * the correct frequencies. */
85 if (kvm_enabled()) {
86 tb_freq = kvmppc_get_tbfreq();
87 clock_freq = kvmppc_get_clockfreq();
90 qemu_devtree_setprop_cell(fdt, "/cpus/cpu@0", "clock-frequency",
91 clock_freq);
92 qemu_devtree_setprop_cell(fdt, "/cpus/cpu@0", "timebase-frequency",
93 tb_freq);
95 ret = rom_add_blob_fixed(BINARY_DEVICE_TREE_FILE, fdt, fdt_size, addr);
96 g_free(fdt);
98 out:
99 #endif
101 return ret;
104 static void bamboo_init(ram_addr_t ram_size,
105 const char *boot_device,
106 const char *kernel_filename,
107 const char *kernel_cmdline,
108 const char *initrd_filename,
109 const char *cpu_model)
111 unsigned int pci_irq_nrs[4] = { 28, 27, 26, 25 };
112 MemoryRegion *address_space_mem = get_system_memory();
113 PCIBus *pcibus;
114 CPUState *env;
115 uint64_t elf_entry;
116 uint64_t elf_lowaddr;
117 target_phys_addr_t entry = 0;
118 target_phys_addr_t loadaddr = 0;
119 target_long initrd_size = 0;
120 int success;
121 int i;
123 /* Setup CPU. */
124 env = ppc440ep_init(address_space_mem, &ram_size, &pcibus,
125 pci_irq_nrs, 1, cpu_model);
127 if (pcibus) {
128 /* Register network interfaces. */
129 for (i = 0; i < nb_nics; i++) {
130 /* There are no PCI NICs on the Bamboo board, but there are
131 * PCI slots, so we can pick whatever default model we want. */
132 pci_nic_init_nofail(&nd_table[i], "e1000", NULL);
136 /* Load kernel. */
137 if (kernel_filename) {
138 success = load_uimage(kernel_filename, &entry, &loadaddr, NULL);
139 if (success < 0) {
140 success = load_elf(kernel_filename, NULL, NULL, &elf_entry,
141 &elf_lowaddr, NULL, 1, ELF_MACHINE, 0);
142 entry = elf_entry;
143 loadaddr = elf_lowaddr;
145 /* XXX try again as binary */
146 if (success < 0) {
147 fprintf(stderr, "qemu: could not load kernel '%s'\n",
148 kernel_filename);
149 exit(1);
153 /* Load initrd. */
154 if (initrd_filename) {
155 initrd_size = load_image_targphys(initrd_filename, RAMDISK_ADDR,
156 ram_size - RAMDISK_ADDR);
158 if (initrd_size < 0) {
159 fprintf(stderr, "qemu: could not load ram disk '%s' at %x\n",
160 initrd_filename, RAMDISK_ADDR);
161 exit(1);
165 /* If we're loading a kernel directly, we must load the device tree too. */
166 if (kernel_filename) {
167 if (bamboo_load_device_tree(FDT_ADDR, ram_size, RAMDISK_ADDR,
168 initrd_size, kernel_cmdline) < 0) {
169 fprintf(stderr, "couldn't load device tree\n");
170 exit(1);
173 /* Set initial guest state. */
174 env->gpr[1] = (16<<20) - 8;
175 env->gpr[3] = FDT_ADDR;
176 env->nip = entry;
177 /* XXX we currently depend on KVM to create some initial TLB entries. */
180 if (kvm_enabled())
181 kvmppc_init();
184 static QEMUMachine bamboo_machine = {
185 .name = "bamboo-0.13",
186 .alias = "bamboo",
187 .desc = "bamboo",
188 .init = bamboo_init,
191 static QEMUMachine bamboo_machine_v0_12 = {
192 .name = "bamboo-0.12",
193 .desc = "bamboo",
194 .init = bamboo_init,
195 .compat_props = (GlobalProperty[]) {
197 .driver = "virtio-serial-pci",
198 .property = "max_ports",
199 .value = stringify(1),
201 .driver = "virtio-serial-pci",
202 .property = "vectors",
203 .value = stringify(0),
205 { /* end of list */ }
209 static void bamboo_machine_init(void)
211 qemu_register_machine(&bamboo_machine);
212 qemu_register_machine(&bamboo_machine_v0_12);
215 machine_init(bamboo_machine_init);