Add vmstate_load() and vmstate_save() functions
[qemu/cris-port.git] / hw / ppc440_bamboo.c
blob3c59f3309920b76d97c7b88230bf68e45c78aeb5
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"
26 #define BINARY_DEVICE_TREE_FILE "bamboo.dtb"
28 static void *bamboo_load_device_tree(target_phys_addr_t addr,
29 uint32_t ramsize,
30 target_phys_addr_t initrd_base,
31 target_phys_addr_t initrd_size,
32 const char *kernel_cmdline)
34 void *fdt = NULL;
35 #ifdef CONFIG_FDT
36 uint32_t mem_reg_property[] = { 0, 0, ramsize };
37 char *filename;
38 int fdt_size;
39 int ret;
41 filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, BINARY_DEVICE_TREE_FILE);
42 if (!filename) {
43 goto out;
45 fdt = load_device_tree(filename, &fdt_size);
46 qemu_free(filename);
47 if (fdt == NULL) {
48 goto out;
51 /* Manipulate device tree in memory. */
53 ret = qemu_devtree_setprop(fdt, "/memory", "reg", mem_reg_property,
54 sizeof(mem_reg_property));
55 if (ret < 0)
56 fprintf(stderr, "couldn't set /memory/reg\n");
58 ret = qemu_devtree_setprop_cell(fdt, "/chosen", "linux,initrd-start",
59 initrd_base);
60 if (ret < 0)
61 fprintf(stderr, "couldn't set /chosen/linux,initrd-start\n");
63 ret = qemu_devtree_setprop_cell(fdt, "/chosen", "linux,initrd-end",
64 (initrd_base + initrd_size));
65 if (ret < 0)
66 fprintf(stderr, "couldn't set /chosen/linux,initrd-end\n");
68 ret = qemu_devtree_setprop_string(fdt, "/chosen", "bootargs",
69 kernel_cmdline);
70 if (ret < 0)
71 fprintf(stderr, "couldn't set /chosen/bootargs\n");
73 if (kvm_enabled())
74 kvmppc_fdt_update(fdt);
76 cpu_physical_memory_write (addr, (void *)fdt, fdt_size);
78 out:
79 #endif
81 return fdt;
84 static void bamboo_init(ram_addr_t ram_size,
85 const char *boot_device,
86 const char *kernel_filename,
87 const char *kernel_cmdline,
88 const char *initrd_filename,
89 const char *cpu_model)
91 unsigned int pci_irq_nrs[4] = { 28, 27, 26, 25 };
92 PCIBus *pcibus;
93 CPUState *env;
94 uint64_t elf_entry;
95 uint64_t elf_lowaddr;
96 target_ulong entry = 0;
97 target_ulong loadaddr = 0;
98 target_long kernel_size = 0;
99 target_ulong initrd_base = 0;
100 target_long initrd_size = 0;
101 target_ulong dt_base = 0;
102 void *fdt;
103 int i;
105 /* Setup CPU. */
106 env = ppc440ep_init(&ram_size, &pcibus, pci_irq_nrs, 1, cpu_model);
108 if (pcibus) {
109 /* Add virtio console devices */
110 for(i = 0; i < MAX_VIRTIO_CONSOLES; i++) {
111 if (virtcon_hds[i]) {
112 pci_create_simple(pcibus, -1, "virtio-console-pci");
116 /* Register network interfaces. */
117 for (i = 0; i < nb_nics; i++) {
118 /* There are no PCI NICs on the Bamboo board, but there are
119 * PCI slots, so we can pick whatever default model we want. */
120 pci_nic_init(&nd_table[i], "e1000", NULL);
124 /* Load kernel. */
125 if (kernel_filename) {
126 kernel_size = load_uimage(kernel_filename, &entry, &loadaddr, NULL);
127 if (kernel_size < 0) {
128 kernel_size = load_elf(kernel_filename, 0, &elf_entry, &elf_lowaddr,
129 NULL);
130 entry = elf_entry;
131 loadaddr = elf_lowaddr;
133 /* XXX try again as binary */
134 if (kernel_size < 0) {
135 fprintf(stderr, "qemu: could not load kernel '%s'\n",
136 kernel_filename);
137 exit(1);
141 /* Load initrd. */
142 if (initrd_filename) {
143 initrd_base = kernel_size + loadaddr;
144 initrd_size = load_image_targphys(initrd_filename, initrd_base,
145 ram_size - initrd_base);
147 if (initrd_size < 0) {
148 fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
149 initrd_filename);
150 exit(1);
154 /* If we're loading a kernel directly, we must load the device tree too. */
155 if (kernel_filename) {
156 if (initrd_base)
157 dt_base = initrd_base + initrd_size;
158 else
159 dt_base = kernel_size + loadaddr;
161 fdt = bamboo_load_device_tree(dt_base, ram_size,
162 initrd_base, initrd_size, kernel_cmdline);
163 if (fdt == NULL) {
164 fprintf(stderr, "couldn't load device tree\n");
165 exit(1);
168 /* Set initial guest state. */
169 env->gpr[1] = (16<<20) - 8;
170 env->gpr[3] = dt_base;
171 env->nip = entry;
172 /* XXX we currently depend on KVM to create some initial TLB entries. */
175 if (kvm_enabled())
176 kvmppc_init();
179 static QEMUMachine bamboo_machine = {
180 .name = "bamboo",
181 .desc = "bamboo",
182 .init = bamboo_init,
185 static void bamboo_machine_init(void)
187 qemu_register_machine(&bamboo_machine);
190 machine_init(bamboo_machine_init);