Convert udiv/sdiv
[qemu/hppa.git] / hw / ppc440_bamboo.c
blob6963309306c6594024f88d29f002a1fbcfcacfa8
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(target_phys_addr_t 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 fdt_size;
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, &fdt_size);
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 cpu_physical_memory_write (addr, (void *)fdt, fdt_size);
81 out:
82 #endif
84 return fdt;
87 static void bamboo_init(ram_addr_t ram_size, int vga_ram_size,
88 const char *boot_device,
89 const char *kernel_filename,
90 const char *kernel_cmdline,
91 const char *initrd_filename,
92 const char *cpu_model)
94 unsigned int pci_irq_nrs[4] = { 28, 27, 26, 25 };
95 PCIBus *pcibus;
96 CPUState *env;
97 uint64_t elf_entry;
98 uint64_t elf_lowaddr;
99 target_ulong entry = 0;
100 target_ulong loadaddr = 0;
101 target_long kernel_size = 0;
102 target_ulong initrd_base = 0;
103 target_long initrd_size = 0;
104 target_ulong dt_base = 0;
105 void *fdt;
106 int i;
108 /* Setup CPU. */
109 env = ppc440ep_init(&ram_size, &pcibus, pci_irq_nrs, 1);
111 if (pcibus) {
112 int unit_id = 0;
114 /* Add virtio block devices. */
115 while ((i = drive_get_index(IF_VIRTIO, 0, unit_id)) != -1) {
116 virtio_blk_init(pcibus, drives_table[i].bdrv);
117 unit_id++;
120 /* Add virtio console devices */
121 for(i = 0; i < MAX_VIRTIO_CONSOLES; i++) {
122 if (virtcon_hds[i])
123 virtio_console_init(pcibus, virtcon_hds[i]);
126 /* Register network interfaces. */
127 for (i = 0; i < nb_nics; i++) {
128 /* There are no PCI NICs on the Bamboo board, but there are
129 * PCI slots, so we can pick whatever default model we want. */
130 pci_nic_init(pcibus, &nd_table[i], -1, "e1000");
134 /* Load kernel. */
135 if (kernel_filename) {
136 kernel_size = load_uimage(kernel_filename, &entry, &loadaddr, NULL);
137 if (kernel_size < 0) {
138 kernel_size = load_elf(kernel_filename, 0, &elf_entry, &elf_lowaddr,
139 NULL);
140 entry = elf_entry;
141 loadaddr = elf_lowaddr;
143 /* XXX try again as binary */
144 if (kernel_size < 0) {
145 fprintf(stderr, "qemu: could not load kernel '%s'\n",
146 kernel_filename);
147 exit(1);
151 /* Load initrd. */
152 if (initrd_filename) {
153 initrd_base = kernel_size + loadaddr;
154 initrd_size = load_image_targphys(initrd_filename, initrd_base,
155 ram_size - initrd_base);
157 if (initrd_size < 0) {
158 fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
159 initrd_filename);
160 exit(1);
164 /* If we're loading a kernel directly, we must load the device tree too. */
165 if (kernel_filename) {
166 if (initrd_base)
167 dt_base = initrd_base + initrd_size;
168 else
169 dt_base = kernel_size + loadaddr;
171 fdt = bamboo_load_device_tree(dt_base, ram_size,
172 initrd_base, initrd_size, kernel_cmdline);
173 if (fdt == NULL) {
174 fprintf(stderr, "couldn't load device tree\n");
175 exit(1);
178 /* Set initial guest state. */
179 env->gpr[1] = (16<<20) - 8;
180 env->gpr[3] = dt_base;
181 env->nip = entry;
182 /* XXX we currently depend on KVM to create some initial TLB entries. */
185 if (kvm_enabled())
186 kvmppc_init();
189 QEMUMachine bamboo_machine = {
190 .name = "bamboo",
191 .desc = "bamboo",
192 .init = bamboo_init,