Statistics
| Branch: | Revision:

root / hw / ppc440_bamboo.c @ bc20ba98

History | View | Annotate | Download (5.9 kB)

1 2c9fade2 aurel32
/*
2 2c9fade2 aurel32
 * Qemu PowerPC 440 Bamboo board emulation
3 2c9fade2 aurel32
 *
4 2c9fade2 aurel32
 * Copyright 2007 IBM Corporation.
5 2c9fade2 aurel32
 * Authors:
6 2c9fade2 aurel32
 *         Jerone Young <jyoung5@us.ibm.com>
7 2c9fade2 aurel32
 *         Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
8 2c9fade2 aurel32
 *         Hollis Blanchard <hollisb@us.ibm.com>
9 2c9fade2 aurel32
 *
10 2c9fade2 aurel32
 * This work is licensed under the GNU GPL license version 2 or later.
11 2c9fade2 aurel32
 *
12 2c9fade2 aurel32
 */
13 2c9fade2 aurel32
14 2c9fade2 aurel32
#include "config.h"
15 2c9fade2 aurel32
#include "qemu-common.h"
16 2c9fade2 aurel32
#include "net.h"
17 2c9fade2 aurel32
#include "hw.h"
18 2c9fade2 aurel32
#include "pci.h"
19 2c9fade2 aurel32
#include "boards.h"
20 2c9fade2 aurel32
#include "sysemu.h"
21 2c9fade2 aurel32
#include "ppc440.h"
22 2c9fade2 aurel32
#include "kvm.h"
23 2c9fade2 aurel32
#include "kvm_ppc.h"
24 2c9fade2 aurel32
#include "device_tree.h"
25 ca20cf32 Blue Swirl
#include "loader.h"
26 ca20cf32 Blue Swirl
#include "elf.h"
27 2c9fade2 aurel32
28 2c9fade2 aurel32
#define BINARY_DEVICE_TREE_FILE "bamboo.dtb"
29 2c9fade2 aurel32
30 04088adb Liu Yu
static int bamboo_load_device_tree(target_phys_addr_t addr,
31 2c9fade2 aurel32
                                     uint32_t ramsize,
32 c227f099 Anthony Liguori
                                     target_phys_addr_t initrd_base,
33 c227f099 Anthony Liguori
                                     target_phys_addr_t initrd_size,
34 2c9fade2 aurel32
                                     const char *kernel_cmdline)
35 2c9fade2 aurel32
{
36 dbf916d8 Aurelien Jarno
    int ret = -1;
37 3f0855b1 Juan Quintela
#ifdef CONFIG_FDT
38 2c9fade2 aurel32
    uint32_t mem_reg_property[] = { 0, 0, ramsize };
39 5cea8590 Paul Brook
    char *filename;
40 7ec632b4 pbrook
    int fdt_size;
41 dbf916d8 Aurelien Jarno
    void *fdt;
42 2c9fade2 aurel32
43 5cea8590 Paul Brook
    filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, BINARY_DEVICE_TREE_FILE);
44 5cea8590 Paul Brook
    if (!filename) {
45 5cea8590 Paul Brook
        goto out;
46 5cea8590 Paul Brook
    }
47 5cea8590 Paul Brook
    fdt = load_device_tree(filename, &fdt_size);
48 5cea8590 Paul Brook
    qemu_free(filename);
49 5cea8590 Paul Brook
    if (fdt == NULL) {
50 2c9fade2 aurel32
        goto out;
51 5cea8590 Paul Brook
    }
52 2c9fade2 aurel32
53 2c9fade2 aurel32
    /* Manipulate device tree in memory. */
54 2c9fade2 aurel32
55 2c9fade2 aurel32
    ret = qemu_devtree_setprop(fdt, "/memory", "reg", mem_reg_property,
56 2c9fade2 aurel32
                               sizeof(mem_reg_property));
57 2c9fade2 aurel32
    if (ret < 0)
58 2c9fade2 aurel32
        fprintf(stderr, "couldn't set /memory/reg\n");
59 2c9fade2 aurel32
60 2c9fade2 aurel32
    ret = qemu_devtree_setprop_cell(fdt, "/chosen", "linux,initrd-start",
61 2c9fade2 aurel32
                                    initrd_base);
62 2c9fade2 aurel32
    if (ret < 0)
63 2c9fade2 aurel32
        fprintf(stderr, "couldn't set /chosen/linux,initrd-start\n");
64 2c9fade2 aurel32
65 2c9fade2 aurel32
    ret = qemu_devtree_setprop_cell(fdt, "/chosen", "linux,initrd-end",
66 2c9fade2 aurel32
                                    (initrd_base + initrd_size));
67 2c9fade2 aurel32
    if (ret < 0)
68 2c9fade2 aurel32
        fprintf(stderr, "couldn't set /chosen/linux,initrd-end\n");
69 2c9fade2 aurel32
70 2c9fade2 aurel32
    ret = qemu_devtree_setprop_string(fdt, "/chosen", "bootargs",
71 2c9fade2 aurel32
                                      kernel_cmdline);
72 2c9fade2 aurel32
    if (ret < 0)
73 2c9fade2 aurel32
        fprintf(stderr, "couldn't set /chosen/bootargs\n");
74 2c9fade2 aurel32
75 2c9fade2 aurel32
    if (kvm_enabled())
76 2c9fade2 aurel32
        kvmppc_fdt_update(fdt);
77 2c9fade2 aurel32
78 04088adb Liu Yu
    ret = rom_add_blob_fixed(BINARY_DEVICE_TREE_FILE, fdt, fdt_size, addr);
79 04088adb Liu Yu
    qemu_free(fdt);
80 7ec632b4 pbrook
81 2c9fade2 aurel32
out:
82 2c9fade2 aurel32
#endif
83 2c9fade2 aurel32
84 04088adb Liu Yu
    return ret;
85 2c9fade2 aurel32
}
86 2c9fade2 aurel32
87 c227f099 Anthony Liguori
static void bamboo_init(ram_addr_t ram_size,
88 a147d62b blueswir1
                        const char *boot_device,
89 2c9fade2 aurel32
                        const char *kernel_filename,
90 2c9fade2 aurel32
                        const char *kernel_cmdline,
91 2c9fade2 aurel32
                        const char *initrd_filename,
92 2c9fade2 aurel32
                        const char *cpu_model)
93 2c9fade2 aurel32
{
94 2c9fade2 aurel32
    unsigned int pci_irq_nrs[4] = { 28, 27, 26, 25 };
95 2c9fade2 aurel32
    PCIBus *pcibus;
96 2c9fade2 aurel32
    CPUState *env;
97 2c9fade2 aurel32
    uint64_t elf_entry;
98 2c9fade2 aurel32
    uint64_t elf_lowaddr;
99 c227f099 Anthony Liguori
    target_phys_addr_t entry = 0;
100 c227f099 Anthony Liguori
    target_phys_addr_t loadaddr = 0;
101 2c9fade2 aurel32
    target_long kernel_size = 0;
102 2c9fade2 aurel32
    target_ulong initrd_base = 0;
103 2c9fade2 aurel32
    target_long initrd_size = 0;
104 2c9fade2 aurel32
    target_ulong dt_base = 0;
105 2c9fade2 aurel32
    int i;
106 2c9fade2 aurel32
107 2c9fade2 aurel32
    /* Setup CPU. */
108 727170b6 Blue Swirl
    env = ppc440ep_init(&ram_size, &pcibus, pci_irq_nrs, 1, cpu_model);
109 2c9fade2 aurel32
110 2c9fade2 aurel32
    if (pcibus) {
111 2c9fade2 aurel32
        /* Register network interfaces. */
112 2c9fade2 aurel32
        for (i = 0; i < nb_nics; i++) {
113 cb457d76 aliguori
            /* There are no PCI NICs on the Bamboo board, but there are
114 cb457d76 aliguori
             * PCI slots, so we can pick whatever default model we want. */
115 07caea31 Markus Armbruster
            pci_nic_init_nofail(&nd_table[i], "e1000", NULL);
116 2c9fade2 aurel32
        }
117 2c9fade2 aurel32
    }
118 2c9fade2 aurel32
119 2c9fade2 aurel32
    /* Load kernel. */
120 2c9fade2 aurel32
    if (kernel_filename) {
121 2c9fade2 aurel32
        kernel_size = load_uimage(kernel_filename, &entry, &loadaddr, NULL);
122 2c9fade2 aurel32
        if (kernel_size < 0) {
123 409dbce5 Aurelien Jarno
            kernel_size = load_elf(kernel_filename, NULL, NULL, &elf_entry,
124 409dbce5 Aurelien Jarno
                                   &elf_lowaddr, NULL, 1, ELF_MACHINE, 0);
125 2c9fade2 aurel32
            entry = elf_entry;
126 2c9fade2 aurel32
            loadaddr = elf_lowaddr;
127 2c9fade2 aurel32
        }
128 2c9fade2 aurel32
        /* XXX try again as binary */
129 2c9fade2 aurel32
        if (kernel_size < 0) {
130 2c9fade2 aurel32
            fprintf(stderr, "qemu: could not load kernel '%s'\n",
131 2c9fade2 aurel32
                    kernel_filename);
132 2c9fade2 aurel32
            exit(1);
133 2c9fade2 aurel32
        }
134 2c9fade2 aurel32
    }
135 2c9fade2 aurel32
136 2c9fade2 aurel32
    /* Load initrd. */
137 2c9fade2 aurel32
    if (initrd_filename) {
138 2c9fade2 aurel32
        initrd_base = kernel_size + loadaddr;
139 dcac9679 pbrook
        initrd_size = load_image_targphys(initrd_filename, initrd_base,
140 dcac9679 pbrook
                                          ram_size - initrd_base);
141 2c9fade2 aurel32
142 2c9fade2 aurel32
        if (initrd_size < 0) {
143 2c9fade2 aurel32
            fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
144 2c9fade2 aurel32
                    initrd_filename);
145 2c9fade2 aurel32
            exit(1);
146 2c9fade2 aurel32
        }
147 2c9fade2 aurel32
    }
148 2c9fade2 aurel32
149 2c9fade2 aurel32
    /* If we're loading a kernel directly, we must load the device tree too. */
150 2c9fade2 aurel32
    if (kernel_filename) {
151 2c9fade2 aurel32
        if (initrd_base)
152 2c9fade2 aurel32
            dt_base = initrd_base + initrd_size;
153 2c9fade2 aurel32
        else
154 2c9fade2 aurel32
            dt_base = kernel_size + loadaddr;
155 2c9fade2 aurel32
156 04088adb Liu Yu
        if (bamboo_load_device_tree(dt_base, ram_size,
157 04088adb Liu Yu
                        initrd_base, initrd_size, kernel_cmdline) < 0) {
158 2c9fade2 aurel32
            fprintf(stderr, "couldn't load device tree\n");
159 2c9fade2 aurel32
            exit(1);
160 2c9fade2 aurel32
        }
161 2c9fade2 aurel32
162 c4963817 Liu Yu
        cpu_synchronize_state(env);
163 c4963817 Liu Yu
164 2c9fade2 aurel32
        /* Set initial guest state. */
165 2c9fade2 aurel32
        env->gpr[1] = (16<<20) - 8;
166 2c9fade2 aurel32
        env->gpr[3] = dt_base;
167 2c9fade2 aurel32
        env->nip = entry;
168 2c9fade2 aurel32
        /* XXX we currently depend on KVM to create some initial TLB entries. */
169 2c9fade2 aurel32
    }
170 2c9fade2 aurel32
171 2c9fade2 aurel32
    if (kvm_enabled())
172 2c9fade2 aurel32
        kvmppc_init();
173 2c9fade2 aurel32
}
174 2c9fade2 aurel32
175 f80f9ec9 Anthony Liguori
static QEMUMachine bamboo_machine = {
176 977b6b91 Amit Shah
    .name = "bamboo-0.13",
177 977b6b91 Amit Shah
    .alias = "bamboo",
178 977b6b91 Amit Shah
    .desc = "bamboo",
179 977b6b91 Amit Shah
    .init = bamboo_init,
180 977b6b91 Amit Shah
};
181 977b6b91 Amit Shah
182 977b6b91 Amit Shah
static QEMUMachine bamboo_machine_v0_12 = {
183 977b6b91 Amit Shah
    .name = "bamboo-0.12",
184 2c9fade2 aurel32
    .desc = "bamboo",
185 2c9fade2 aurel32
    .init = bamboo_init,
186 21be440c Amit Shah
    .compat_props = (GlobalProperty[]) {
187 21be440c Amit Shah
        {
188 21be440c Amit Shah
            .driver   = "virtio-serial-pci",
189 21be440c Amit Shah
            .property = "max_nr_ports",
190 21be440c Amit Shah
            .value    = stringify(1),
191 21be440c Amit Shah
        },{
192 21be440c Amit Shah
            .driver   = "virtio-serial-pci",
193 21be440c Amit Shah
            .property = "vectors",
194 21be440c Amit Shah
            .value    = stringify(0),
195 21be440c Amit Shah
        },
196 21be440c Amit Shah
        { /* end of list */ }
197 21be440c Amit Shah
    },
198 2c9fade2 aurel32
};
199 f80f9ec9 Anthony Liguori
200 f80f9ec9 Anthony Liguori
static void bamboo_machine_init(void)
201 f80f9ec9 Anthony Liguori
{
202 f80f9ec9 Anthony Liguori
    qemu_register_machine(&bamboo_machine);
203 977b6b91 Amit Shah
    qemu_register_machine(&bamboo_machine_v0_12);
204 f80f9ec9 Anthony Liguori
}
205 f80f9ec9 Anthony Liguori
206 f80f9ec9 Anthony Liguori
machine_init(bamboo_machine_init);