Statistics
| Branch: | Revision:

root / hw / virtex_ml507.c @ 37952117

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 2c50e26e Edgar E. Iglesias
#include "pc.h"
28 2c50e26e Edgar E. Iglesias
#include "net.h"
29 2c50e26e Edgar E. Iglesias
#include "flash.h"
30 2c50e26e Edgar E. Iglesias
#include "sysemu.h"
31 2c50e26e Edgar E. Iglesias
#include "devices.h"
32 2c50e26e Edgar E. Iglesias
#include "boards.h"
33 2c50e26e Edgar E. Iglesias
#include "device_tree.h"
34 2c50e26e Edgar E. Iglesias
#include "loader.h"
35 2c50e26e Edgar E. Iglesias
#include "elf.h"
36 2c50e26e Edgar E. Iglesias
#include "qemu-log.h"
37 39186d8a Richard Henderson
#include "exec-memory.h"
38 2c50e26e Edgar E. Iglesias
39 2c50e26e Edgar E. Iglesias
#include "ppc.h"
40 2c50e26e Edgar E. Iglesias
#include "ppc4xx.h"
41 2c50e26e Edgar E. Iglesias
#include "ppc405.h"
42 2c50e26e Edgar E. Iglesias
43 2c50e26e Edgar E. Iglesias
#include "blockdev.h"
44 2c50e26e Edgar E. Iglesias
#include "xilinx.h"
45 2c50e26e Edgar E. Iglesias
46 2c50e26e Edgar E. Iglesias
#define EPAPR_MAGIC    (0x45504150)
47 2c50e26e Edgar E. Iglesias
#define FLASH_SIZE     (16 * 1024 * 1024)
48 2c50e26e Edgar E. Iglesias
49 2c50e26e Edgar E. Iglesias
static struct boot_info
50 2c50e26e Edgar E. Iglesias
{
51 2c50e26e Edgar E. Iglesias
    uint32_t bootstrap_pc;
52 2c50e26e Edgar E. Iglesias
    uint32_t cmdline;
53 2c50e26e Edgar E. Iglesias
    uint32_t fdt;
54 2c50e26e Edgar E. Iglesias
    uint32_t ima_size;
55 2c50e26e Edgar E. Iglesias
    void *vfdt;
56 2c50e26e Edgar E. Iglesias
} boot_info;
57 2c50e26e Edgar E. Iglesias
58 2c50e26e Edgar E. Iglesias
/* Create reset TLB entries for BookE, spanning the 32bit addr space.  */
59 e2684c0b Andreas Färber
static void mmubooke_create_initial_mapping(CPUPPCState *env,
60 2c50e26e Edgar E. Iglesias
                                     target_ulong va,
61 2c50e26e Edgar E. Iglesias
                                     target_phys_addr_t pa)
62 2c50e26e Edgar E. Iglesias
{
63 1c53accc Alexander Graf
    ppcemb_tlb_t *tlb = &env->tlb.tlbe[0];
64 2c50e26e Edgar E. Iglesias
65 2c50e26e Edgar E. Iglesias
    tlb->attr = 0;
66 2c50e26e Edgar E. Iglesias
    tlb->prot = PAGE_VALID | ((PAGE_READ | PAGE_WRITE | PAGE_EXEC) << 4);
67 2c50e26e Edgar E. Iglesias
    tlb->size = 1 << 31; /* up to 0x80000000  */
68 2c50e26e Edgar E. Iglesias
    tlb->EPN = va & TARGET_PAGE_MASK;
69 2c50e26e Edgar E. Iglesias
    tlb->RPN = pa & TARGET_PAGE_MASK;
70 2c50e26e Edgar E. Iglesias
    tlb->PID = 0;
71 2c50e26e Edgar E. Iglesias
72 1c53accc Alexander Graf
    tlb = &env->tlb.tlbe[1];
73 2c50e26e Edgar E. Iglesias
    tlb->attr = 0;
74 2c50e26e Edgar E. Iglesias
    tlb->prot = PAGE_VALID | ((PAGE_READ | PAGE_WRITE | PAGE_EXEC) << 4);
75 2c50e26e Edgar E. Iglesias
    tlb->size = 1 << 31; /* up to 0xffffffff  */
76 2c50e26e Edgar E. Iglesias
    tlb->EPN = 0x80000000 & TARGET_PAGE_MASK;
77 2c50e26e Edgar E. Iglesias
    tlb->RPN = 0x80000000 & TARGET_PAGE_MASK;
78 2c50e26e Edgar E. Iglesias
    tlb->PID = 0;
79 2c50e26e Edgar E. Iglesias
}
80 2c50e26e Edgar E. Iglesias
81 68281699 Andreas Färber
static PowerPCCPU *ppc440_init_xilinx(ram_addr_t *ram_size,
82 68281699 Andreas Färber
                                      int do_init,
83 68281699 Andreas Färber
                                      const char *cpu_model,
84 68281699 Andreas Färber
                                      uint32_t sysclk)
85 2c50e26e Edgar E. Iglesias
{
86 d1d4938b Andreas Färber
    PowerPCCPU *cpu;
87 e2684c0b Andreas Färber
    CPUPPCState *env;
88 2c50e26e Edgar E. Iglesias
    qemu_irq *irqs;
89 2c50e26e Edgar E. Iglesias
90 d1d4938b Andreas Färber
    cpu = cpu_ppc_init(cpu_model);
91 d1d4938b Andreas Färber
    if (cpu == NULL) {
92 2c50e26e Edgar E. Iglesias
        fprintf(stderr, "Unable to initialize CPU!\n");
93 2c50e26e Edgar E. Iglesias
        exit(1);
94 2c50e26e Edgar E. Iglesias
    }
95 d1d4938b Andreas Färber
    env = &cpu->env;
96 2c50e26e Edgar E. Iglesias
97 ddd1055b Fabien Chouteau
    ppc_booke_timers_init(env, sysclk, 0/* no flags */);
98 2c50e26e Edgar E. Iglesias
99 2c50e26e Edgar E. Iglesias
    ppc_dcr_init(env, NULL, NULL);
100 2c50e26e Edgar E. Iglesias
101 2c50e26e Edgar E. Iglesias
    /* interrupt controller */
102 7267c094 Anthony Liguori
    irqs = g_malloc0(sizeof(qemu_irq) * PPCUIC_OUTPUT_NB);
103 2c50e26e Edgar E. Iglesias
    irqs[PPCUIC_OUTPUT_INT] = ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_INT];
104 2c50e26e Edgar E. Iglesias
    irqs[PPCUIC_OUTPUT_CINT] = ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_CINT];
105 49a2942d Blue Swirl
    ppcuic_init(env, irqs, 0x0C0, 0, 1);
106 68281699 Andreas Färber
    return cpu;
107 2c50e26e Edgar E. Iglesias
}
108 2c50e26e Edgar E. Iglesias
109 2c50e26e Edgar E. Iglesias
static void main_cpu_reset(void *opaque)
110 2c50e26e Edgar E. Iglesias
{
111 f8031482 Andreas Färber
    PowerPCCPU *cpu = opaque;
112 f8031482 Andreas Färber
    CPUPPCState *env = &cpu->env;
113 2c50e26e Edgar E. Iglesias
    struct boot_info *bi = env->load_info;
114 2c50e26e Edgar E. Iglesias
115 f8031482 Andreas Färber
    cpu_reset(CPU(cpu));
116 2c50e26e Edgar E. Iglesias
    /* Linux Kernel Parameters (passing device tree):
117 2c50e26e Edgar E. Iglesias
       *   r3: pointer to the fdt
118 2c50e26e Edgar E. Iglesias
       *   r4: 0
119 2c50e26e Edgar E. Iglesias
       *   r5: 0
120 2c50e26e Edgar E. Iglesias
       *   r6: epapr magic
121 2c50e26e Edgar E. Iglesias
       *   r7: size of IMA in bytes
122 2c50e26e Edgar E. Iglesias
       *   r8: 0
123 2c50e26e Edgar E. Iglesias
       *   r9: 0
124 2c50e26e Edgar E. Iglesias
    */
125 2c50e26e Edgar E. Iglesias
    env->gpr[1] = (16<<20) - 8;
126 2c50e26e Edgar E. Iglesias
    /* Provide a device-tree.  */
127 2c50e26e Edgar E. Iglesias
    env->gpr[3] = bi->fdt;
128 2c50e26e Edgar E. Iglesias
    env->nip = bi->bootstrap_pc;
129 2c50e26e Edgar E. Iglesias
130 2c50e26e Edgar E. Iglesias
    /* Create a mapping for the kernel.  */
131 2c50e26e Edgar E. Iglesias
    mmubooke_create_initial_mapping(env, 0, 0);
132 2c50e26e Edgar E. Iglesias
    env->gpr[6] = tswap32(EPAPR_MAGIC);
133 2c50e26e Edgar E. Iglesias
    env->gpr[7] = bi->ima_size;
134 2c50e26e Edgar E. Iglesias
}
135 2c50e26e Edgar E. Iglesias
136 2c50e26e Edgar E. Iglesias
#define BINARY_DEVICE_TREE_FILE "virtex-ml507.dtb"
137 2c50e26e Edgar E. Iglesias
static int xilinx_load_device_tree(target_phys_addr_t addr,
138 2c50e26e Edgar E. Iglesias
                                      uint32_t ramsize,
139 2c50e26e Edgar E. Iglesias
                                      target_phys_addr_t initrd_base,
140 2c50e26e Edgar E. Iglesias
                                      target_phys_addr_t initrd_size,
141 2c50e26e Edgar E. Iglesias
                                      const char *kernel_cmdline)
142 2c50e26e Edgar E. Iglesias
{
143 2c50e26e Edgar E. Iglesias
    char *path;
144 2c50e26e Edgar E. Iglesias
    int fdt_size;
145 2c50e26e Edgar E. Iglesias
#ifdef CONFIG_FDT
146 2c50e26e Edgar E. Iglesias
    void *fdt;
147 2c50e26e Edgar E. Iglesias
    int r;
148 2c50e26e Edgar E. Iglesias
149 2c50e26e Edgar E. Iglesias
    /* Try the local "ppc.dtb" override.  */
150 2c50e26e Edgar E. Iglesias
    fdt = load_device_tree("ppc.dtb", &fdt_size);
151 2c50e26e Edgar E. Iglesias
    if (!fdt) {
152 2c50e26e Edgar E. Iglesias
        path = qemu_find_file(QEMU_FILE_TYPE_BIOS, BINARY_DEVICE_TREE_FILE);
153 2c50e26e Edgar E. Iglesias
        if (path) {
154 2c50e26e Edgar E. Iglesias
            fdt = load_device_tree(path, &fdt_size);
155 7267c094 Anthony Liguori
            g_free(path);
156 2c50e26e Edgar E. Iglesias
        }
157 3b2e3dc9 Edgar E. Iglesias
        if (!fdt) {
158 2c50e26e Edgar E. Iglesias
            return 0;
159 3b2e3dc9 Edgar E. Iglesias
        }
160 2c50e26e Edgar E. Iglesias
    }
161 2c50e26e Edgar E. Iglesias
162 2c50e26e Edgar E. Iglesias
    r = qemu_devtree_setprop_string(fdt, "/chosen", "bootargs", kernel_cmdline);
163 2c50e26e Edgar E. Iglesias
    if (r < 0)
164 2c50e26e Edgar E. Iglesias
        fprintf(stderr, "couldn't set /chosen/bootargs\n");
165 2c50e26e Edgar E. Iglesias
    cpu_physical_memory_write (addr, (void *)fdt, fdt_size);
166 2c50e26e Edgar E. Iglesias
#else
167 2c50e26e Edgar E. Iglesias
    /* We lack libfdt so we cannot manipulate the fdt. Just pass on the blob
168 2c50e26e Edgar E. Iglesias
       to the kernel.  */
169 2c50e26e Edgar E. Iglesias
    fdt_size = load_image_targphys("ppc.dtb", addr, 0x10000);
170 2c50e26e Edgar E. Iglesias
    if (fdt_size < 0) {
171 2c50e26e Edgar E. Iglesias
        path = qemu_find_file(QEMU_FILE_TYPE_BIOS, BINARY_DEVICE_TREE_FILE);
172 2c50e26e Edgar E. Iglesias
        if (path) {
173 2c50e26e Edgar E. Iglesias
            fdt_size = load_image_targphys(path, addr, 0x10000);
174 7267c094 Anthony Liguori
            g_free(path);
175 2c50e26e Edgar E. Iglesias
        }
176 2c50e26e Edgar E. Iglesias
    }
177 2c50e26e Edgar E. Iglesias
178 2c50e26e Edgar E. Iglesias
    if (kernel_cmdline) {
179 2c50e26e Edgar E. Iglesias
        fprintf(stderr,
180 2c50e26e Edgar E. Iglesias
                "Warning: missing libfdt, cannot pass cmdline to kernel!\n");
181 2c50e26e Edgar E. Iglesias
    }
182 2c50e26e Edgar E. Iglesias
#endif
183 2c50e26e Edgar E. Iglesias
    return fdt_size;
184 2c50e26e Edgar E. Iglesias
}
185 2c50e26e Edgar E. Iglesias
186 2c50e26e Edgar E. Iglesias
static void virtex_init(ram_addr_t ram_size,
187 2c50e26e Edgar E. Iglesias
                        const char *boot_device,
188 2c50e26e Edgar E. Iglesias
                        const char *kernel_filename,
189 2c50e26e Edgar E. Iglesias
                        const char *kernel_cmdline,
190 2c50e26e Edgar E. Iglesias
                        const char *initrd_filename, const char *cpu_model)
191 2c50e26e Edgar E. Iglesias
{
192 39186d8a Richard Henderson
    MemoryRegion *address_space_mem = get_system_memory();
193 2c50e26e Edgar E. Iglesias
    DeviceState *dev;
194 68281699 Andreas Färber
    PowerPCCPU *cpu;
195 e2684c0b Andreas Färber
    CPUPPCState *env;
196 2c50e26e Edgar E. Iglesias
    target_phys_addr_t ram_base = 0;
197 2c50e26e Edgar E. Iglesias
    DriveInfo *dinfo;
198 333b13fc Avi Kivity
    MemoryRegion *phys_ram = g_new(MemoryRegion, 1);
199 2c50e26e Edgar E. Iglesias
    qemu_irq irq[32], *cpu_irq;
200 2c50e26e Edgar E. Iglesias
    int kernel_size;
201 2c50e26e Edgar E. Iglesias
    int i;
202 2c50e26e Edgar E. Iglesias
203 2c50e26e Edgar E. Iglesias
    /* init CPUs */
204 2c50e26e Edgar E. Iglesias
    if (cpu_model == NULL) {
205 2c50e26e Edgar E. Iglesias
        cpu_model = "440-Xilinx";
206 2c50e26e Edgar E. Iglesias
    }
207 2c50e26e Edgar E. Iglesias
208 68281699 Andreas Färber
    cpu = ppc440_init_xilinx(&ram_size, 1, cpu_model, 400000000);
209 68281699 Andreas Färber
    env = &cpu->env;
210 f8031482 Andreas Färber
    qemu_register_reset(main_cpu_reset, cpu);
211 2c50e26e Edgar E. Iglesias
212 c5705a77 Avi Kivity
    memory_region_init_ram(phys_ram, "ram", ram_size);
213 c5705a77 Avi Kivity
    vmstate_register_ram_global(phys_ram);
214 333b13fc Avi Kivity
    memory_region_add_subregion(address_space_mem, ram_base, phys_ram);
215 2c50e26e Edgar E. Iglesias
216 2c50e26e Edgar E. Iglesias
    dinfo = drive_get(IF_PFLASH, 0, 0);
217 cfe5f011 Avi Kivity
    pflash_cfi01_register(0xfc000000, NULL, "virtex.flash", FLASH_SIZE,
218 2c50e26e Edgar E. Iglesias
                          dinfo ? dinfo->bdrv : NULL, (64 * 1024),
219 2c50e26e Edgar E. Iglesias
                          FLASH_SIZE >> 16,
220 01e0451a Anthony Liguori
                          1, 0x89, 0x18, 0x0000, 0x0, 1);
221 2c50e26e Edgar E. Iglesias
222 2c50e26e Edgar E. Iglesias
    cpu_irq = (qemu_irq *) &env->irq_inputs[PPC40x_INPUT_INT];
223 2c50e26e Edgar E. Iglesias
    dev = xilinx_intc_create(0x81800000, cpu_irq[0], 0);
224 2c50e26e Edgar E. Iglesias
    for (i = 0; i < 32; i++) {
225 2c50e26e Edgar E. Iglesias
        irq[i] = qdev_get_gpio_in(dev, i);
226 2c50e26e Edgar E. Iglesias
    }
227 2c50e26e Edgar E. Iglesias
228 39186d8a Richard Henderson
    serial_mm_init(address_space_mem, 0x83e01003ULL, 2, irq[9], 115200,
229 39186d8a Richard Henderson
                   serial_hds[0], DEVICE_LITTLE_ENDIAN);
230 2c50e26e Edgar E. Iglesias
231 2c50e26e Edgar E. Iglesias
    /* 2 timers at irq 2 @ 62 Mhz.  */
232 abe098e4 Peter A. G. Crosthwaite
    xilinx_timer_create(0x83c00000, irq[3], 0, 62 * 1000000);
233 2c50e26e Edgar E. Iglesias
234 2c50e26e Edgar E. Iglesias
    if (kernel_filename) {
235 2c50e26e Edgar E. Iglesias
        uint64_t entry, low, high;
236 2c50e26e Edgar E. Iglesias
        target_phys_addr_t boot_offset;
237 2c50e26e Edgar E. Iglesias
238 2c50e26e Edgar E. Iglesias
        /* Boots a kernel elf binary.  */
239 2c50e26e Edgar E. Iglesias
        kernel_size = load_elf(kernel_filename, NULL, NULL,
240 2c50e26e Edgar E. Iglesias
                               &entry, &low, &high, 1, ELF_MACHINE, 0);
241 2c50e26e Edgar E. Iglesias
        boot_info.bootstrap_pc = entry & 0x00ffffff;
242 2c50e26e Edgar E. Iglesias
243 2c50e26e Edgar E. Iglesias
        if (kernel_size < 0) {
244 2c50e26e Edgar E. Iglesias
            boot_offset = 0x1200000;
245 2c50e26e Edgar E. Iglesias
            /* If we failed loading ELF's try a raw image.  */
246 2c50e26e Edgar E. Iglesias
            kernel_size = load_image_targphys(kernel_filename,
247 2c50e26e Edgar E. Iglesias
                                              boot_offset,
248 2c50e26e Edgar E. Iglesias
                                              ram_size);
249 2c50e26e Edgar E. Iglesias
            boot_info.bootstrap_pc = boot_offset;
250 2c50e26e Edgar E. Iglesias
            high = boot_info.bootstrap_pc + kernel_size + 8192;
251 2c50e26e Edgar E. Iglesias
        }
252 2c50e26e Edgar E. Iglesias
253 2c50e26e Edgar E. Iglesias
        boot_info.ima_size = kernel_size;
254 2c50e26e Edgar E. Iglesias
255 2c50e26e Edgar E. Iglesias
        /* Provide a device-tree.  */
256 2c50e26e Edgar E. Iglesias
        boot_info.fdt = high + (8192 * 2);
257 2c50e26e Edgar E. Iglesias
        boot_info.fdt &= ~8191;
258 2c50e26e Edgar E. Iglesias
        xilinx_load_device_tree(boot_info.fdt, ram_size, 0, 0, kernel_cmdline);
259 2c50e26e Edgar E. Iglesias
    }
260 2c50e26e Edgar E. Iglesias
    env->load_info = &boot_info;
261 2c50e26e Edgar E. Iglesias
}
262 2c50e26e Edgar E. Iglesias
263 2c50e26e Edgar E. Iglesias
static QEMUMachine virtex_machine = {
264 2c50e26e Edgar E. Iglesias
    .name = "virtex-ml507",
265 2c50e26e Edgar E. Iglesias
    .desc = "Xilinx Virtex ML507 reference design",
266 2c50e26e Edgar E. Iglesias
    .init = virtex_init,
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);