Avoid harmless unhandled wrmsr 0xc0010117 messages
[qemu-kvm/fedora.git] / hw / ppc440_bamboo.c
blob60ddaf4ae5f9f1573fc9d4ffee72a2cc69f55dc0
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 "virtio-blk.h"
20 #include "virtio-console.h"
21 #include "boards.h"
22 #include "sysemu.h"
23 #include "ppc440.h"
24 #define KVM_UPSTREAM
25 #include "kvm.h"
26 #include "kvm_ppc.h"
27 #include "device_tree.h"
29 #define BINARY_DEVICE_TREE_FILE "bamboo.dtb"
31 static void *bamboo_load_device_tree(void *addr,
32 uint32_t ramsize,
33 target_phys_addr_t initrd_base,
34 target_phys_addr_t initrd_size,
35 const char *kernel_cmdline)
37 void *fdt = NULL;
38 #ifdef HAVE_FDT
39 uint32_t mem_reg_property[] = { 0, 0, ramsize };
40 char *path;
41 int pathlen;
42 int ret;
44 pathlen = snprintf(NULL, 0, "%s/%s", bios_dir, BINARY_DEVICE_TREE_FILE) + 1;
45 path = qemu_malloc(pathlen);
47 snprintf(path, pathlen, "%s/%s", bios_dir, BINARY_DEVICE_TREE_FILE);
49 fdt = load_device_tree(path, addr);
50 free(path);
51 if (fdt == NULL)
52 goto out;
54 /* Manipulate device tree in memory. */
56 ret = qemu_devtree_setprop(fdt, "/memory", "reg", mem_reg_property,
57 sizeof(mem_reg_property));
58 if (ret < 0)
59 fprintf(stderr, "couldn't set /memory/reg\n");
61 ret = qemu_devtree_setprop_cell(fdt, "/chosen", "linux,initrd-start",
62 initrd_base);
63 if (ret < 0)
64 fprintf(stderr, "couldn't set /chosen/linux,initrd-start\n");
66 ret = qemu_devtree_setprop_cell(fdt, "/chosen", "linux,initrd-end",
67 (initrd_base + initrd_size));
68 if (ret < 0)
69 fprintf(stderr, "couldn't set /chosen/linux,initrd-end\n");
71 ret = qemu_devtree_setprop_string(fdt, "/chosen", "bootargs",
72 kernel_cmdline);
73 if (ret < 0)
74 fprintf(stderr, "couldn't set /chosen/bootargs\n");
76 if (kvm_enabled())
77 kvmppc_fdt_update(fdt);
79 out:
80 #endif
82 return fdt;
85 static void bamboo_init(ram_addr_t ram_size, int vga_ram_size,
86 const char *boot_device,
87 const char *kernel_filename,
88 const char *kernel_cmdline,
89 const char *initrd_filename,
90 const char *cpu_model)
92 unsigned int pci_irq_nrs[4] = { 28, 27, 26, 25 };
93 PCIBus *pcibus;
94 CPUState *env;
95 uint64_t elf_entry;
96 uint64_t elf_lowaddr;
97 target_ulong entry = 0;
98 target_ulong loadaddr = 0;
99 target_long kernel_size = 0;
100 target_ulong initrd_base = 0;
101 target_long initrd_size = 0;
102 target_ulong dt_base = 0;
103 void *fdt;
104 int i;
106 /* Setup CPU. */
107 env = ppc440ep_init(&ram_size, &pcibus, pci_irq_nrs, 1);
109 if (pcibus) {
110 int unit_id = 0;
112 /* Add virtio block devices. */
113 while ((i = drive_get_index(IF_VIRTIO, 0, unit_id)) != -1) {
114 virtio_blk_init(pcibus, drives_table[i].bdrv);
115 unit_id++;
118 /* Add virtio console devices */
119 for(i = 0; i < MAX_VIRTIO_CONSOLES; i++) {
120 if (virtcon_hds[i])
121 virtio_console_init(pcibus, virtcon_hds[i]);
124 /* Register network interfaces. */
125 for (i = 0; i < nb_nics; i++) {
126 /* There are no PCI NICs on the Bamboo board, but there are
127 * PCI slots, so we can pick whatever default model we want. */
128 pci_nic_init(pcibus, &nd_table[i], -1, "e1000");
132 /* Load kernel. */
133 if (kernel_filename) {
134 kernel_size = load_uimage(kernel_filename, &entry, &loadaddr, NULL);
135 if (kernel_size < 0) {
136 kernel_size = load_elf(kernel_filename, 0, &elf_entry, &elf_lowaddr,
137 NULL);
138 entry = elf_entry;
139 loadaddr = elf_lowaddr;
141 /* XXX try again as binary */
142 if (kernel_size < 0) {
143 fprintf(stderr, "qemu: could not load kernel '%s'\n",
144 kernel_filename);
145 exit(1);
149 /* Load initrd. */
150 if (initrd_filename) {
151 initrd_base = kernel_size + loadaddr;
152 initrd_size = load_image(initrd_filename, phys_ram_base + initrd_base);
154 if (initrd_size < 0) {
155 fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
156 initrd_filename);
157 exit(1);
161 /* If we're loading a kernel directly, we must load the device tree too. */
162 if (kernel_filename) {
163 if (initrd_base)
164 dt_base = initrd_base + initrd_size;
165 else
166 dt_base = kernel_size + loadaddr;
168 fdt = bamboo_load_device_tree(phys_ram_base + dt_base, ram_size,
169 initrd_base, initrd_size, kernel_cmdline);
170 if (fdt == NULL) {
171 fprintf(stderr, "couldn't load device tree\n");
172 exit(1);
175 /* Set initial guest state. */
176 env->gpr[1] = (16<<20) - 8;
177 env->gpr[3] = dt_base;
178 env->nip = entry;
179 /* XXX we currently depend on KVM to create some initial TLB entries. */
182 if (kvm_enabled())
183 kvmppc_init();
186 QEMUMachine bamboo_machine = {
187 .name = "bamboo",
188 .desc = "bamboo",
189 .init = bamboo_init,
190 .ram_require = 8<<20 | RAMSIZE_FIXED,