Fix warnings when compiling hppa-dis.c
[qemu/hppa.git] / hw / ppc440_bamboo.c
blob5f03661672c00c8ff0176c886743d741356f7ec3
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 #include "kvm.h"
25 #include "kvm_ppc.h"
26 #include "device_tree.h"
28 #define BINARY_DEVICE_TREE_FILE "bamboo.dtb"
30 static void *bamboo_load_device_tree(void *addr,
31 uint32_t ramsize,
32 target_phys_addr_t initrd_base,
33 target_phys_addr_t initrd_size,
34 const char *kernel_cmdline)
36 void *fdt = NULL;
37 #ifdef HAVE_FDT
38 uint32_t mem_reg_property[] = { 0, 0, ramsize };
39 char *path;
40 int pathlen;
41 int ret;
43 pathlen = snprintf(NULL, 0, "%s/%s", bios_dir, BINARY_DEVICE_TREE_FILE) + 1;
44 path = qemu_malloc(pathlen);
45 if (path == NULL)
46 return NULL;
48 snprintf(path, pathlen, "%s/%s", bios_dir, BINARY_DEVICE_TREE_FILE);
50 fdt = load_device_tree(path, addr);
51 free(path);
52 if (fdt == NULL)
53 goto out;
55 /* Manipulate device tree in memory. */
57 ret = qemu_devtree_setprop(fdt, "/memory", "reg", mem_reg_property,
58 sizeof(mem_reg_property));
59 if (ret < 0)
60 fprintf(stderr, "couldn't set /memory/reg\n");
62 ret = qemu_devtree_setprop_cell(fdt, "/chosen", "linux,initrd-start",
63 initrd_base);
64 if (ret < 0)
65 fprintf(stderr, "couldn't set /chosen/linux,initrd-start\n");
67 ret = qemu_devtree_setprop_cell(fdt, "/chosen", "linux,initrd-end",
68 (initrd_base + initrd_size));
69 if (ret < 0)
70 fprintf(stderr, "couldn't set /chosen/linux,initrd-end\n");
72 ret = qemu_devtree_setprop_string(fdt, "/chosen", "bootargs",
73 kernel_cmdline);
74 if (ret < 0)
75 fprintf(stderr, "couldn't set /chosen/bootargs\n");
77 if (kvm_enabled())
78 kvmppc_fdt_update(fdt);
80 out:
81 #endif
83 return fdt;
86 static void bamboo_init(ram_addr_t ram_size, int vga_ram_size,
87 const char *boot_device,
88 const char *kernel_filename,
89 const char *kernel_cmdline,
90 const char *initrd_filename,
91 const char *cpu_model)
93 unsigned int pci_irq_nrs[4] = { 28, 27, 26, 25 };
94 PCIBus *pcibus;
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);
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 virtio_blk_init(pcibus, drives_table[i].bdrv);
116 unit_id++;
119 /* Add virtio console devices */
120 for(i = 0; i < MAX_VIRTIO_CONSOLES; i++) {
121 if (virtcon_hds[i])
122 virtio_console_init(pcibus, virtcon_hds[i]);
125 /* Register network interfaces. */
126 for (i = 0; i < nb_nics; i++) {
127 /* There are no PCI NICs on the Bamboo board, but there are
128 * PCI slots, so we can pick whatever default model we want. */
129 pci_nic_init(pcibus, &nd_table[i], -1, "e1000");
133 /* Load kernel. */
134 if (kernel_filename) {
135 kernel_size = load_uimage(kernel_filename, &entry, &loadaddr, NULL);
136 if (kernel_size < 0) {
137 kernel_size = load_elf(kernel_filename, 0, &elf_entry, &elf_lowaddr,
138 NULL);
139 entry = elf_entry;
140 loadaddr = elf_lowaddr;
142 /* XXX try again as binary */
143 if (kernel_size < 0) {
144 fprintf(stderr, "qemu: could not load kernel '%s'\n",
145 kernel_filename);
146 exit(1);
150 /* Load initrd. */
151 if (initrd_filename) {
152 initrd_base = kernel_size + loadaddr;
153 initrd_size = load_image(initrd_filename, phys_ram_base + initrd_base);
155 if (initrd_size < 0) {
156 fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
157 initrd_filename);
158 exit(1);
162 /* If we're loading a kernel directly, we must load the device tree too. */
163 if (kernel_filename) {
164 if (initrd_base)
165 dt_base = initrd_base + initrd_size;
166 else
167 dt_base = kernel_size + loadaddr;
169 fdt = bamboo_load_device_tree(phys_ram_base + dt_base, ram_size,
170 initrd_base, initrd_size, kernel_cmdline);
171 if (fdt == NULL) {
172 fprintf(stderr, "couldn't load device tree\n");
173 exit(1);
176 /* Set initial guest state. */
177 env->gpr[1] = (16<<20) - 8;
178 env->gpr[3] = dt_base;
179 env->nip = entry;
180 /* XXX we currently depend on KVM to create some initial TLB entries. */
183 if (kvm_enabled())
184 kvmppc_init();
187 QEMUMachine bamboo_machine = {
188 .name = "bamboo",
189 .desc = "bamboo",
190 .init = bamboo_init,
191 .ram_require = 8<<20 | RAMSIZE_FIXED,