Statistics
| Branch: | Revision:

root / hw / virtex_ml507.c @ 9a6ee9fd

History | View | Annotate | Download (8.5 kB)

1 2c50e26e Edgar E. Iglesias
/*
2 2c50e26e Edgar E. Iglesias
 * Model of Xilinx Virtex5 ML507 PPC-440 refdesign.
3 2c50e26e Edgar E. Iglesias
 *
4 2c50e26e Edgar E. Iglesias
 * Copyright (c) 2010 Edgar E. Iglesias.
5 2c50e26e Edgar E. Iglesias
 *
6 2c50e26e Edgar E. Iglesias
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 2c50e26e Edgar E. Iglesias
 * of this software and associated documentation files (the "Software"), to deal
8 2c50e26e Edgar E. Iglesias
 * in the Software without restriction, including without limitation the rights
9 2c50e26e Edgar E. Iglesias
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 2c50e26e Edgar E. Iglesias
 * copies of the Software, and to permit persons to whom the Software is
11 2c50e26e Edgar E. Iglesias
 * furnished to do so, subject to the following conditions:
12 2c50e26e Edgar E. Iglesias
 *
13 2c50e26e Edgar E. Iglesias
 * The above copyright notice and this permission notice shall be included in
14 2c50e26e Edgar E. Iglesias
 * all copies or substantial portions of the Software.
15 2c50e26e Edgar E. Iglesias
 *
16 2c50e26e Edgar E. Iglesias
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 2c50e26e Edgar E. Iglesias
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 2c50e26e Edgar E. Iglesias
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 2c50e26e Edgar E. Iglesias
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 2c50e26e Edgar E. Iglesias
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 2c50e26e Edgar E. Iglesias
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 2c50e26e Edgar E. Iglesias
 * THE SOFTWARE.
23 2c50e26e Edgar E. Iglesias
 */
24 2c50e26e Edgar E. Iglesias
25 2c50e26e Edgar E. Iglesias
#include "sysbus.h"
26 2c50e26e Edgar E. Iglesias
#include "hw.h"
27 488cb996 Gerd Hoffmann
#include "serial.h"
28 2c50e26e Edgar E. Iglesias
#include "flash.h"
29 9c17d615 Paolo Bonzini
#include "sysemu/sysemu.h"
30 2c50e26e Edgar E. Iglesias
#include "devices.h"
31 2c50e26e Edgar E. Iglesias
#include "boards.h"
32 9c17d615 Paolo Bonzini
#include "sysemu/device_tree.h"
33 2c50e26e Edgar E. Iglesias
#include "loader.h"
34 2c50e26e Edgar E. Iglesias
#include "elf.h"
35 1de7afc9 Paolo Bonzini
#include "qemu/log.h"
36 022c62cb Paolo Bonzini
#include "exec/address-spaces.h"
37 2c50e26e Edgar E. Iglesias
38 2c50e26e Edgar E. Iglesias
#include "ppc.h"
39 2c50e26e Edgar E. Iglesias
#include "ppc4xx.h"
40 2c50e26e Edgar E. Iglesias
#include "ppc405.h"
41 2c50e26e Edgar E. Iglesias
42 9c17d615 Paolo Bonzini
#include "sysemu/blockdev.h"
43 2c50e26e Edgar E. Iglesias
#include "xilinx.h"
44 2c50e26e Edgar E. Iglesias
45 2c50e26e Edgar E. Iglesias
#define EPAPR_MAGIC    (0x45504150)
46 2c50e26e Edgar E. Iglesias
#define FLASH_SIZE     (16 * 1024 * 1024)
47 2c50e26e Edgar E. Iglesias
48 2c50e26e Edgar E. Iglesias
static struct boot_info
49 2c50e26e Edgar E. Iglesias
{
50 2c50e26e Edgar E. Iglesias
    uint32_t bootstrap_pc;
51 2c50e26e Edgar E. Iglesias
    uint32_t cmdline;
52 2c50e26e Edgar E. Iglesias
    uint32_t fdt;
53 2c50e26e Edgar E. Iglesias
    uint32_t ima_size;
54 2c50e26e Edgar E. Iglesias
    void *vfdt;
55 2c50e26e Edgar E. Iglesias
} boot_info;
56 2c50e26e Edgar E. Iglesias
57 2c50e26e Edgar E. Iglesias
/* Create reset TLB entries for BookE, spanning the 32bit addr space.  */
58 e2684c0b Andreas Färber
static void mmubooke_create_initial_mapping(CPUPPCState *env,
59 2c50e26e Edgar E. Iglesias
                                     target_ulong va,
60 a8170e5e Avi Kivity
                                     hwaddr pa)
61 2c50e26e Edgar E. Iglesias
{
62 1c53accc Alexander Graf
    ppcemb_tlb_t *tlb = &env->tlb.tlbe[0];
63 2c50e26e Edgar E. Iglesias
64 2c50e26e Edgar E. Iglesias
    tlb->attr = 0;
65 2c50e26e Edgar E. Iglesias
    tlb->prot = PAGE_VALID | ((PAGE_READ | PAGE_WRITE | PAGE_EXEC) << 4);
66 2c50e26e Edgar E. Iglesias
    tlb->size = 1 << 31; /* up to 0x80000000  */
67 2c50e26e Edgar E. Iglesias
    tlb->EPN = va & TARGET_PAGE_MASK;
68 2c50e26e Edgar E. Iglesias
    tlb->RPN = pa & TARGET_PAGE_MASK;
69 2c50e26e Edgar E. Iglesias
    tlb->PID = 0;
70 2c50e26e Edgar E. Iglesias
71 1c53accc Alexander Graf
    tlb = &env->tlb.tlbe[1];
72 2c50e26e Edgar E. Iglesias
    tlb->attr = 0;
73 2c50e26e Edgar E. Iglesias
    tlb->prot = PAGE_VALID | ((PAGE_READ | PAGE_WRITE | PAGE_EXEC) << 4);
74 2c50e26e Edgar E. Iglesias
    tlb->size = 1 << 31; /* up to 0xffffffff  */
75 2c50e26e Edgar E. Iglesias
    tlb->EPN = 0x80000000 & TARGET_PAGE_MASK;
76 2c50e26e Edgar E. Iglesias
    tlb->RPN = 0x80000000 & TARGET_PAGE_MASK;
77 2c50e26e Edgar E. Iglesias
    tlb->PID = 0;
78 2c50e26e Edgar E. Iglesias
}
79 2c50e26e Edgar E. Iglesias
80 68281699 Andreas Färber
static PowerPCCPU *ppc440_init_xilinx(ram_addr_t *ram_size,
81 68281699 Andreas Färber
                                      int do_init,
82 68281699 Andreas Färber
                                      const char *cpu_model,
83 68281699 Andreas Färber
                                      uint32_t sysclk)
84 2c50e26e Edgar E. Iglesias
{
85 d1d4938b Andreas Färber
    PowerPCCPU *cpu;
86 e2684c0b Andreas Färber
    CPUPPCState *env;
87 2c50e26e Edgar E. Iglesias
    qemu_irq *irqs;
88 2c50e26e Edgar E. Iglesias
89 d1d4938b Andreas Färber
    cpu = cpu_ppc_init(cpu_model);
90 d1d4938b Andreas Färber
    if (cpu == NULL) {
91 2c50e26e Edgar E. Iglesias
        fprintf(stderr, "Unable to initialize CPU!\n");
92 2c50e26e Edgar E. Iglesias
        exit(1);
93 2c50e26e Edgar E. Iglesias
    }
94 d1d4938b Andreas Färber
    env = &cpu->env;
95 2c50e26e Edgar E. Iglesias
96 a34a92b9 Andreas Färber
    ppc_booke_timers_init(cpu, sysclk, 0/* no flags */);
97 2c50e26e Edgar E. Iglesias
98 2c50e26e Edgar E. Iglesias
    ppc_dcr_init(env, NULL, NULL);
99 2c50e26e Edgar E. Iglesias
100 2c50e26e Edgar E. Iglesias
    /* interrupt controller */
101 7267c094 Anthony Liguori
    irqs = g_malloc0(sizeof(qemu_irq) * PPCUIC_OUTPUT_NB);
102 2c50e26e Edgar E. Iglesias
    irqs[PPCUIC_OUTPUT_INT] = ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_INT];
103 2c50e26e Edgar E. Iglesias
    irqs[PPCUIC_OUTPUT_CINT] = ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_CINT];
104 49a2942d Blue Swirl
    ppcuic_init(env, irqs, 0x0C0, 0, 1);
105 68281699 Andreas Färber
    return cpu;
106 2c50e26e Edgar E. Iglesias
}
107 2c50e26e Edgar E. Iglesias
108 2c50e26e Edgar E. Iglesias
static void main_cpu_reset(void *opaque)
109 2c50e26e Edgar E. Iglesias
{
110 f8031482 Andreas Färber
    PowerPCCPU *cpu = opaque;
111 f8031482 Andreas Färber
    CPUPPCState *env = &cpu->env;
112 2c50e26e Edgar E. Iglesias
    struct boot_info *bi = env->load_info;
113 2c50e26e Edgar E. Iglesias
114 f8031482 Andreas Färber
    cpu_reset(CPU(cpu));
115 2c50e26e Edgar E. Iglesias
    /* Linux Kernel Parameters (passing device tree):
116 2c50e26e Edgar E. Iglesias
       *   r3: pointer to the fdt
117 2c50e26e Edgar E. Iglesias
       *   r4: 0
118 2c50e26e Edgar E. Iglesias
       *   r5: 0
119 2c50e26e Edgar E. Iglesias
       *   r6: epapr magic
120 2c50e26e Edgar E. Iglesias
       *   r7: size of IMA in bytes
121 2c50e26e Edgar E. Iglesias
       *   r8: 0
122 2c50e26e Edgar E. Iglesias
       *   r9: 0
123 2c50e26e Edgar E. Iglesias
    */
124 2c50e26e Edgar E. Iglesias
    env->gpr[1] = (16<<20) - 8;
125 2c50e26e Edgar E. Iglesias
    /* Provide a device-tree.  */
126 2c50e26e Edgar E. Iglesias
    env->gpr[3] = bi->fdt;
127 2c50e26e Edgar E. Iglesias
    env->nip = bi->bootstrap_pc;
128 2c50e26e Edgar E. Iglesias
129 2c50e26e Edgar E. Iglesias
    /* Create a mapping for the kernel.  */
130 2c50e26e Edgar E. Iglesias
    mmubooke_create_initial_mapping(env, 0, 0);
131 2c50e26e Edgar E. Iglesias
    env->gpr[6] = tswap32(EPAPR_MAGIC);
132 2c50e26e Edgar E. Iglesias
    env->gpr[7] = bi->ima_size;
133 2c50e26e Edgar E. Iglesias
}
134 2c50e26e Edgar E. Iglesias
135 2c50e26e Edgar E. Iglesias
#define BINARY_DEVICE_TREE_FILE "virtex-ml507.dtb"
136 a8170e5e Avi Kivity
static int xilinx_load_device_tree(hwaddr addr,
137 2c50e26e Edgar E. Iglesias
                                      uint32_t ramsize,
138 a8170e5e Avi Kivity
                                      hwaddr initrd_base,
139 a8170e5e Avi Kivity
                                      hwaddr initrd_size,
140 2c50e26e Edgar E. Iglesias
                                      const char *kernel_cmdline)
141 2c50e26e Edgar E. Iglesias
{
142 2c50e26e Edgar E. Iglesias
    char *path;
143 2c50e26e Edgar E. Iglesias
    int fdt_size;
144 2c50e26e Edgar E. Iglesias
#ifdef CONFIG_FDT
145 2c50e26e Edgar E. Iglesias
    void *fdt;
146 2c50e26e Edgar E. Iglesias
    int r;
147 2c50e26e Edgar E. Iglesias
148 2c50e26e Edgar E. Iglesias
    /* Try the local "ppc.dtb" override.  */
149 2c50e26e Edgar E. Iglesias
    fdt = load_device_tree("ppc.dtb", &fdt_size);
150 2c50e26e Edgar E. Iglesias
    if (!fdt) {
151 2c50e26e Edgar E. Iglesias
        path = qemu_find_file(QEMU_FILE_TYPE_BIOS, BINARY_DEVICE_TREE_FILE);
152 2c50e26e Edgar E. Iglesias
        if (path) {
153 2c50e26e Edgar E. Iglesias
            fdt = load_device_tree(path, &fdt_size);
154 7267c094 Anthony Liguori
            g_free(path);
155 2c50e26e Edgar E. Iglesias
        }
156 3b2e3dc9 Edgar E. Iglesias
        if (!fdt) {
157 2c50e26e Edgar E. Iglesias
            return 0;
158 3b2e3dc9 Edgar E. Iglesias
        }
159 2c50e26e Edgar E. Iglesias
    }
160 2c50e26e Edgar E. Iglesias
161 2c50e26e Edgar E. Iglesias
    r = qemu_devtree_setprop_string(fdt, "/chosen", "bootargs", kernel_cmdline);
162 2c50e26e Edgar E. Iglesias
    if (r < 0)
163 2c50e26e Edgar E. Iglesias
        fprintf(stderr, "couldn't set /chosen/bootargs\n");
164 2c50e26e Edgar E. Iglesias
    cpu_physical_memory_write (addr, (void *)fdt, fdt_size);
165 2c50e26e Edgar E. Iglesias
#else
166 2c50e26e Edgar E. Iglesias
    /* We lack libfdt so we cannot manipulate the fdt. Just pass on the blob
167 2c50e26e Edgar E. Iglesias
       to the kernel.  */
168 2c50e26e Edgar E. Iglesias
    fdt_size = load_image_targphys("ppc.dtb", addr, 0x10000);
169 2c50e26e Edgar E. Iglesias
    if (fdt_size < 0) {
170 2c50e26e Edgar E. Iglesias
        path = qemu_find_file(QEMU_FILE_TYPE_BIOS, BINARY_DEVICE_TREE_FILE);
171 2c50e26e Edgar E. Iglesias
        if (path) {
172 2c50e26e Edgar E. Iglesias
            fdt_size = load_image_targphys(path, addr, 0x10000);
173 7267c094 Anthony Liguori
            g_free(path);
174 2c50e26e Edgar E. Iglesias
        }
175 2c50e26e Edgar E. Iglesias
    }
176 2c50e26e Edgar E. Iglesias
177 2c50e26e Edgar E. Iglesias
    if (kernel_cmdline) {
178 2c50e26e Edgar E. Iglesias
        fprintf(stderr,
179 2c50e26e Edgar E. Iglesias
                "Warning: missing libfdt, cannot pass cmdline to kernel!\n");
180 2c50e26e Edgar E. Iglesias
    }
181 2c50e26e Edgar E. Iglesias
#endif
182 2c50e26e Edgar E. Iglesias
    return fdt_size;
183 2c50e26e Edgar E. Iglesias
}
184 2c50e26e Edgar E. Iglesias
185 5f072e1f Eduardo Habkost
static void virtex_init(QEMUMachineInitArgs *args)
186 2c50e26e Edgar E. Iglesias
{
187 5f072e1f Eduardo Habkost
    ram_addr_t ram_size = args->ram_size;
188 5f072e1f Eduardo Habkost
    const char *cpu_model = args->cpu_model;
189 5f072e1f Eduardo Habkost
    const char *kernel_filename = args->kernel_filename;
190 5f072e1f Eduardo Habkost
    const char *kernel_cmdline = args->kernel_cmdline;
191 39186d8a Richard Henderson
    MemoryRegion *address_space_mem = get_system_memory();
192 2c50e26e Edgar E. Iglesias
    DeviceState *dev;
193 68281699 Andreas Färber
    PowerPCCPU *cpu;
194 e2684c0b Andreas Färber
    CPUPPCState *env;
195 a8170e5e Avi Kivity
    hwaddr ram_base = 0;
196 2c50e26e Edgar E. Iglesias
    DriveInfo *dinfo;
197 333b13fc Avi Kivity
    MemoryRegion *phys_ram = g_new(MemoryRegion, 1);
198 2c50e26e Edgar E. Iglesias
    qemu_irq irq[32], *cpu_irq;
199 2c50e26e Edgar E. Iglesias
    int kernel_size;
200 2c50e26e Edgar E. Iglesias
    int i;
201 2c50e26e Edgar E. Iglesias
202 2c50e26e Edgar E. Iglesias
    /* init CPUs */
203 2c50e26e Edgar E. Iglesias
    if (cpu_model == NULL) {
204 2c50e26e Edgar E. Iglesias
        cpu_model = "440-Xilinx";
205 2c50e26e Edgar E. Iglesias
    }
206 2c50e26e Edgar E. Iglesias
207 68281699 Andreas Färber
    cpu = ppc440_init_xilinx(&ram_size, 1, cpu_model, 400000000);
208 68281699 Andreas Färber
    env = &cpu->env;
209 f8031482 Andreas Färber
    qemu_register_reset(main_cpu_reset, cpu);
210 2c50e26e Edgar E. Iglesias
211 c5705a77 Avi Kivity
    memory_region_init_ram(phys_ram, "ram", ram_size);
212 c5705a77 Avi Kivity
    vmstate_register_ram_global(phys_ram);
213 333b13fc Avi Kivity
    memory_region_add_subregion(address_space_mem, ram_base, phys_ram);
214 2c50e26e Edgar E. Iglesias
215 2c50e26e Edgar E. Iglesias
    dinfo = drive_get(IF_PFLASH, 0, 0);
216 cfe5f011 Avi Kivity
    pflash_cfi01_register(0xfc000000, NULL, "virtex.flash", FLASH_SIZE,
217 2c50e26e Edgar E. Iglesias
                          dinfo ? dinfo->bdrv : NULL, (64 * 1024),
218 2c50e26e Edgar E. Iglesias
                          FLASH_SIZE >> 16,
219 01e0451a Anthony Liguori
                          1, 0x89, 0x18, 0x0000, 0x0, 1);
220 2c50e26e Edgar E. Iglesias
221 2c50e26e Edgar E. Iglesias
    cpu_irq = (qemu_irq *) &env->irq_inputs[PPC40x_INPUT_INT];
222 2c50e26e Edgar E. Iglesias
    dev = xilinx_intc_create(0x81800000, cpu_irq[0], 0);
223 2c50e26e Edgar E. Iglesias
    for (i = 0; i < 32; i++) {
224 2c50e26e Edgar E. Iglesias
        irq[i] = qdev_get_gpio_in(dev, i);
225 2c50e26e Edgar E. Iglesias
    }
226 2c50e26e Edgar E. Iglesias
227 39186d8a Richard Henderson
    serial_mm_init(address_space_mem, 0x83e01003ULL, 2, irq[9], 115200,
228 39186d8a Richard Henderson
                   serial_hds[0], DEVICE_LITTLE_ENDIAN);
229 2c50e26e Edgar E. Iglesias
230 2c50e26e Edgar E. Iglesias
    /* 2 timers at irq 2 @ 62 Mhz.  */
231 abe098e4 Peter A. G. Crosthwaite
    xilinx_timer_create(0x83c00000, irq[3], 0, 62 * 1000000);
232 2c50e26e Edgar E. Iglesias
233 2c50e26e Edgar E. Iglesias
    if (kernel_filename) {
234 2c50e26e Edgar E. Iglesias
        uint64_t entry, low, high;
235 a8170e5e Avi Kivity
        hwaddr boot_offset;
236 2c50e26e Edgar E. Iglesias
237 2c50e26e Edgar E. Iglesias
        /* Boots a kernel elf binary.  */
238 2c50e26e Edgar E. Iglesias
        kernel_size = load_elf(kernel_filename, NULL, NULL,
239 2c50e26e Edgar E. Iglesias
                               &entry, &low, &high, 1, ELF_MACHINE, 0);
240 2c50e26e Edgar E. Iglesias
        boot_info.bootstrap_pc = entry & 0x00ffffff;
241 2c50e26e Edgar E. Iglesias
242 2c50e26e Edgar E. Iglesias
        if (kernel_size < 0) {
243 2c50e26e Edgar E. Iglesias
            boot_offset = 0x1200000;
244 2c50e26e Edgar E. Iglesias
            /* If we failed loading ELF's try a raw image.  */
245 2c50e26e Edgar E. Iglesias
            kernel_size = load_image_targphys(kernel_filename,
246 2c50e26e Edgar E. Iglesias
                                              boot_offset,
247 2c50e26e Edgar E. Iglesias
                                              ram_size);
248 2c50e26e Edgar E. Iglesias
            boot_info.bootstrap_pc = boot_offset;
249 2c50e26e Edgar E. Iglesias
            high = boot_info.bootstrap_pc + kernel_size + 8192;
250 2c50e26e Edgar E. Iglesias
        }
251 2c50e26e Edgar E. Iglesias
252 2c50e26e Edgar E. Iglesias
        boot_info.ima_size = kernel_size;
253 2c50e26e Edgar E. Iglesias
254 2c50e26e Edgar E. Iglesias
        /* Provide a device-tree.  */
255 2c50e26e Edgar E. Iglesias
        boot_info.fdt = high + (8192 * 2);
256 2c50e26e Edgar E. Iglesias
        boot_info.fdt &= ~8191;
257 2c50e26e Edgar E. Iglesias
        xilinx_load_device_tree(boot_info.fdt, ram_size, 0, 0, kernel_cmdline);
258 2c50e26e Edgar E. Iglesias
    }
259 2c50e26e Edgar E. Iglesias
    env->load_info = &boot_info;
260 2c50e26e Edgar E. Iglesias
}
261 2c50e26e Edgar E. Iglesias
262 2c50e26e Edgar E. Iglesias
static QEMUMachine virtex_machine = {
263 2c50e26e Edgar E. Iglesias
    .name = "virtex-ml507",
264 2c50e26e Edgar E. Iglesias
    .desc = "Xilinx Virtex ML507 reference design",
265 2c50e26e Edgar E. Iglesias
    .init = virtex_init,
266 e4ada29e Avik Sil
    DEFAULT_MACHINE_OPTIONS,
267 2c50e26e Edgar E. Iglesias
};
268 2c50e26e Edgar E. Iglesias
269 2c50e26e Edgar E. Iglesias
static void virtex_machine_init(void)
270 2c50e26e Edgar E. Iglesias
{
271 2c50e26e Edgar E. Iglesias
    qemu_register_machine(&virtex_machine);
272 2c50e26e Edgar E. Iglesias
}
273 2c50e26e Edgar E. Iglesias
274 2c50e26e Edgar E. Iglesias
machine_init(virtex_machine_init);