]> Git Repo - qemu.git/blob - hw/petalogix_s3adsp1800_mmu.c
es1370: symbolic names for pci registers
[qemu.git] / hw / petalogix_s3adsp1800_mmu.c
1 /*
2  * Model of Petalogix linux reference design targeting Xilinx Spartan 3ADSP-1800
3  * boards.
4  *
5  * Copyright (c) 2009 Edgar E. Iglesias.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to deal
9  * in the Software without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in
15  * all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23  * THE SOFTWARE.
24  */
25
26 #include "sysbus.h"
27 #include "hw.h"
28 #include "net.h"
29 #include "flash.h"
30 #include "sysemu.h"
31 #include "devices.h"
32 #include "boards.h"
33 #include "device_tree.h"
34 #include "xilinx.h"
35 #include "loader.h"
36 #include "elf.h"
37
38 #define LMB_BRAM_SIZE  (128 * 1024)
39 #define FLASH_SIZE     (16 * 1024 * 1024)
40
41 static struct
42 {
43     uint32_t bootstrap_pc;
44     uint32_t cmdline;
45     uint32_t fdt;
46 } boot_info;
47
48 static void main_cpu_reset(void *opaque)
49 {
50     CPUState *env = opaque;
51
52     cpu_reset(env);
53     env->regs[5] = boot_info.cmdline;
54     env->regs[7] = boot_info.fdt;
55     env->sregs[SR_PC] = boot_info.bootstrap_pc;
56 }
57
58 #define BINARY_DEVICE_TREE_FILE "petalogix-s3adsp1800.dtb"
59 static int petalogix_load_device_tree(target_phys_addr_t addr,
60                                       uint32_t ramsize,
61                                       target_phys_addr_t initrd_base,
62                                       target_phys_addr_t initrd_size,
63                                       const char *kernel_cmdline)
64 {
65     char *path;
66     int fdt_size;
67 #ifdef CONFIG_FDT
68     void *fdt;
69     int r;
70
71     /* Try the local "mb.dtb" override.  */
72     fdt = load_device_tree("mb.dtb", &fdt_size);
73     if (!fdt) {
74         path = qemu_find_file(QEMU_FILE_TYPE_BIOS, BINARY_DEVICE_TREE_FILE);
75         if (path) {
76             fdt = load_device_tree(path, &fdt_size);
77             qemu_free(path);
78         }
79         if (!fdt)
80             return 0;
81     }
82
83     r = qemu_devtree_setprop_string(fdt, "/chosen", "bootargs", kernel_cmdline);
84     if (r < 0)
85         fprintf(stderr, "couldn't set /chosen/bootargs\n");
86     cpu_physical_memory_write (addr, (void *)fdt, fdt_size);
87 #else
88     /* We lack libfdt so we cannot manipulate the fdt. Just pass on the blob
89        to the kernel.  */
90     fdt_size = load_image_targphys("mb.dtb", addr, 0x10000);
91     if (fdt_size < 0) {
92         path = qemu_find_file(QEMU_FILE_TYPE_BIOS, BINARY_DEVICE_TREE_FILE);
93         if (path) {
94             fdt_size = load_image_targphys(path, addr, 0x10000);
95             qemu_free(path);
96         }
97     }
98
99     if (kernel_cmdline) {
100         fprintf(stderr,
101                 "Warning: missing libfdt, cannot pass cmdline to kernel!\n");
102     }
103 #endif
104     return fdt_size;
105 }
106
107 static void
108 petalogix_s3adsp1800_init(ram_addr_t ram_size,
109                           const char *boot_device,
110                           const char *kernel_filename,
111                           const char *kernel_cmdline,
112                           const char *initrd_filename, const char *cpu_model)
113 {
114     DeviceState *dev;
115     CPUState *env;
116     int kernel_size;
117     DriveInfo *dinfo;
118     int i;
119     target_phys_addr_t ddr_base = 0x90000000;
120     ram_addr_t phys_lmb_bram;
121     ram_addr_t phys_ram;
122     ram_addr_t phys_flash;
123     qemu_irq irq[32], *cpu_irq;
124
125     /* init CPUs */
126     if (cpu_model == NULL) {
127         cpu_model = "microblaze";
128     }
129     env = cpu_init(cpu_model);
130
131     env->pvr.regs[10] = 0x0c000000; /* spartan 3a dsp family.  */
132     qemu_register_reset(main_cpu_reset, env);
133
134     /* Attach emulated BRAM through the LMB.  */
135     phys_lmb_bram = qemu_ram_alloc(LMB_BRAM_SIZE);
136     cpu_register_physical_memory(0x00000000, LMB_BRAM_SIZE,
137                                  phys_lmb_bram | IO_MEM_RAM);
138
139     phys_ram = qemu_ram_alloc(ram_size);
140     cpu_register_physical_memory(ddr_base, ram_size, phys_ram | IO_MEM_RAM);
141
142     phys_flash = qemu_ram_alloc(FLASH_SIZE);
143     dinfo = drive_get(IF_PFLASH, 0, 0);
144     pflash_cfi02_register(0xa0000000, phys_flash,
145                           dinfo ? dinfo->bdrv : NULL, (64 * 1024),
146                           FLASH_SIZE >> 16,
147                           1, 1, 0x0000, 0x0000, 0x0000, 0x0000,
148                           0x555, 0x2aa);
149
150     cpu_irq = microblaze_pic_init_cpu(env);
151     dev = xilinx_intc_create(0x81800000, cpu_irq[0], 2);
152     for (i = 0; i < 32; i++) {
153         irq[i] = qdev_get_gpio_in(dev, i);
154     }
155
156     sysbus_create_simple("xilinx,uartlite", 0x84000000, irq[3]);
157     /* 2 timers at irq 2 @ 62 Mhz.  */
158     xilinx_timer_create(0x83c00000, irq[0], 2, 62 * 1000000);
159     xilinx_ethlite_create(&nd_table[0], 0x81000000, irq[1], 0, 0);
160
161     if (kernel_filename) {
162         uint64_t entry, low, high;
163         int kcmdline_len;
164         uint32_t base32;
165
166         /* Boots a kernel elf binary.  */
167         kernel_size = load_elf(kernel_filename, 0,
168                                &entry, &low, &high,
169                                1, ELF_MACHINE, 0);
170         base32 = entry;
171         if (base32 == 0xc0000000) {
172             kernel_size = load_elf(kernel_filename, -0x30000000LL,
173                                    &entry, NULL, NULL,
174                                    1, ELF_MACHINE, 0);
175         }
176         /* Always boot into physical ram.  */
177         boot_info.bootstrap_pc = ddr_base + (entry & 0x0fffffff);
178         if (kernel_size < 0) {
179             /* If we failed loading ELF's try a raw image.  */
180             kernel_size = load_image_targphys(kernel_filename, ddr_base,
181                                               ram_size);
182             boot_info.bootstrap_pc = ddr_base;
183         }
184
185         boot_info.cmdline = ddr_base + kernel_size + 8192;
186         if (kernel_cmdline && (kcmdline_len = strlen(kernel_cmdline))) {
187             pstrcpy_targphys("cmdline", boot_info.cmdline, 256, kernel_cmdline);
188         }
189         /* Provide a device-tree.  */
190         boot_info.fdt = boot_info.cmdline + 256;
191         petalogix_load_device_tree(boot_info.fdt, ram_size,
192                                    0, 0,
193                                    kernel_cmdline);
194     }
195 }
196
197 static QEMUMachine petalogix_s3adsp1800_machine = {
198     .name = "petalogix-s3adsp1800",
199     .desc = "Petalogix linux refdesign for xilinx Spartan 3ADSP1800",
200     .init = petalogix_s3adsp1800_init,
201     .is_default = 1
202 };
203
204 static void petalogix_s3adsp1800_machine_init(void)
205 {
206     qemu_register_machine(&petalogix_s3adsp1800_machine);
207 }
208
209 machine_init(petalogix_s3adsp1800_machine_init);
This page took 0.036568 seconds and 4 git commands to generate.