Disable preadv/pwritev support
[qemu-kvm/fedora.git] / hw / ppc440_bamboo.c
blob9f2262327975c2e712b1b6bf3770fe84ae108255
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 "sysemu.h"
21 #include "ppc440.h"
22 #include "kvm.h"
23 #include "kvm_ppc.h"
24 #include "device_tree.h"
25 #include "qemu-kvm.h"
27 #define BINARY_DEVICE_TREE_FILE "bamboo.dtb"
29 static void *bamboo_load_device_tree(target_phys_addr_t addr,
30 uint32_t ramsize,
31 target_phys_addr_t initrd_base,
32 target_phys_addr_t initrd_size,
33 const char *kernel_cmdline)
35 void *fdt = NULL;
36 #ifdef HAVE_FDT
37 uint32_t mem_reg_property[] = { 0, 0, ramsize };
38 char *filename;
39 int fdt_size;
40 int ret;
42 filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, BINARY_DEVICE_TREE_FILE);
43 if (!filename) {
44 goto out;
46 fdt = load_device_tree(filename, &fdt_size);
47 qemu_free(filename);
48 if (fdt == NULL) {
49 goto out;
52 /* Manipulate device tree in memory. */
54 ret = qemu_devtree_setprop(fdt, "/memory", "reg", mem_reg_property,
55 sizeof(mem_reg_property));
56 if (ret < 0)
57 fprintf(stderr, "couldn't set /memory/reg\n");
59 ret = qemu_devtree_setprop_cell(fdt, "/chosen", "linux,initrd-start",
60 initrd_base);
61 if (ret < 0)
62 fprintf(stderr, "couldn't set /chosen/linux,initrd-start\n");
64 ret = qemu_devtree_setprop_cell(fdt, "/chosen", "linux,initrd-end",
65 (initrd_base + initrd_size));
66 if (ret < 0)
67 fprintf(stderr, "couldn't set /chosen/linux,initrd-end\n");
69 ret = qemu_devtree_setprop_string(fdt, "/chosen", "bootargs",
70 kernel_cmdline);
71 if (ret < 0)
72 fprintf(stderr, "couldn't set /chosen/bootargs\n");
74 if (kvm_enabled())
75 kvmppc_fdt_update(fdt);
77 cpu_physical_memory_write (addr, (void *)fdt, fdt_size);
79 out:
80 #endif
82 return fdt;
85 static void bamboo_init(ram_addr_t 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 PCIDevice *pci_dev;
95 CPUState *env;
96 uint64_t elf_entry;
97 uint64_t elf_lowaddr;
98 target_ulong entry = 0;
99 target_ulong loadaddr = 0;
100 target_long kernel_size = 0;
101 target_ulong initrd_base = 0;
102 target_long initrd_size = 0;
103 target_ulong dt_base = 0;
104 void *fdt;
105 int i;
107 /* Setup CPU. */
108 env = ppc440ep_init(&ram_size, &pcibus, pci_irq_nrs, 1, cpu_model);
110 if (pcibus) {
111 int unit_id = 0;
113 /* Add virtio block devices. */
114 while ((i = drive_get_index(IF_VIRTIO, 0, unit_id)) != -1) {
115 pci_dev = pci_create("virtio-blk-pci", drives_table[i].devaddr);
116 qdev_init(&pci_dev->qdev);
117 unit_id++;
120 /* Add virtio console devices */
121 for(i = 0; i < MAX_VIRTIO_CONSOLES; i++) {
122 if (virtcon_hds[i]) {
123 pci_create_simple(pcibus, -1, "virtio-console-pci");
127 /* Register network interfaces. */
128 for (i = 0; i < nb_nics; i++) {
129 /* There are no PCI NICs on the Bamboo board, but there are
130 * PCI slots, so we can pick whatever default model we want. */
131 pci_nic_init_nofail(&nd_table[i], "e1000", NULL);
135 /* Load kernel. */
136 if (kernel_filename) {
137 kernel_size = load_uimage(kernel_filename, &entry, &loadaddr, NULL);
138 if (kernel_size < 0) {
139 kernel_size = load_elf(kernel_filename, 0, &elf_entry, &elf_lowaddr,
140 NULL);
141 entry = elf_entry;
142 loadaddr = elf_lowaddr;
144 /* XXX try again as binary */
145 if (kernel_size < 0) {
146 fprintf(stderr, "qemu: could not load kernel '%s'\n",
147 kernel_filename);
148 exit(1);
152 /* Load initrd. */
153 if (initrd_filename) {
154 initrd_base = kernel_size + loadaddr;
155 initrd_size = load_image_targphys(initrd_filename, initrd_base,
156 ram_size - initrd_base);
158 if (initrd_size < 0) {
159 fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
160 initrd_filename);
161 exit(1);
165 /* If we're loading a kernel directly, we must load the device tree too. */
166 if (kernel_filename) {
167 if (initrd_base)
168 dt_base = initrd_base + initrd_size;
169 else
170 dt_base = kernel_size + loadaddr;
172 fdt = bamboo_load_device_tree(dt_base, ram_size,
173 initrd_base, initrd_size, kernel_cmdline);
174 if (fdt == NULL) {
175 fprintf(stderr, "couldn't load device tree\n");
176 exit(1);
179 /* Set initial guest state. */
180 env->gpr[1] = (16<<20) - 8;
181 env->gpr[3] = dt_base;
182 env->nip = entry;
183 /* XXX we currently depend on KVM to create some initial TLB entries. */
186 if (kvm_enabled())
187 kvmppc_init();
190 static QEMUMachine bamboo_machine = {
191 .name = "bamboo",
192 .desc = "bamboo",
193 .init = bamboo_init,
196 static void bamboo_machine_init(void)
198 qemu_register_machine(&bamboo_machine);
201 machine_init(bamboo_machine_init);