]>
Commit | Line | Data |
---|---|---|
00914b7d MS |
1 | /* |
2 | * Model of Petalogix linux reference design targeting Xilinx Spartan ml605 | |
3 | * board. | |
4 | * | |
5 | * Copyright (c) 2011 Michal Simek <[email protected]> | |
6 | * Copyright (c) 2011 PetaLogix | |
7 | * Copyright (c) 2009 Edgar E. Iglesias. | |
8 | * | |
9 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
10 | * of this software and associated documentation files (the "Software"), to deal | |
11 | * in the Software without restriction, including without limitation the rights | |
12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
13 | * copies of the Software, and to permit persons to whom the Software is | |
14 | * furnished to do so, subject to the following conditions: | |
15 | * | |
16 | * The above copyright notice and this permission notice shall be included in | |
17 | * all copies or substantial portions of the Software. | |
18 | * | |
19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
22 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
25 | * THE SOFTWARE. | |
26 | */ | |
27 | ||
28 | #include "sysbus.h" | |
29 | #include "hw.h" | |
30 | #include "net.h" | |
31 | #include "flash.h" | |
32 | #include "sysemu.h" | |
33 | #include "devices.h" | |
34 | #include "boards.h" | |
35 | #include "device_tree.h" | |
36 | #include "xilinx.h" | |
37 | #include "loader.h" | |
38 | #include "elf.h" | |
39 | #include "blockdev.h" | |
40 | #include "pc.h" | |
39186d8a | 41 | #include "exec-memory.h" |
00914b7d | 42 | |
b861b741 | 43 | #include "microblaze_pic_cpu.h" |
00914b7d MS |
44 | #include "xilinx_axidma.h" |
45 | ||
46 | #define LMB_BRAM_SIZE (128 * 1024) | |
47 | #define FLASH_SIZE (32 * 1024 * 1024) | |
48 | ||
49 | static struct | |
50 | { | |
51 | uint32_t bootstrap_pc; | |
52 | uint32_t cmdline; | |
53 | uint32_t fdt; | |
54 | } boot_info; | |
55 | ||
56 | static void main_cpu_reset(void *opaque) | |
57 | { | |
58 | CPUState *env = opaque; | |
59 | ||
60 | cpu_reset(env); | |
61 | env->regs[5] = boot_info.cmdline; | |
62 | env->regs[7] = boot_info.fdt; | |
63 | env->sregs[SR_PC] = boot_info.bootstrap_pc; | |
64 | env->pvr.regs[10] = 0x0e000000; /* virtex 6 */ | |
65 | /* setup pvr to match kernel setting */ | |
66 | env->pvr.regs[5] |= PVR5_DCACHE_WRITEBACK_MASK; | |
67 | env->pvr.regs[0] |= PVR0_USE_FPU_MASK | PVR0_ENDI; | |
68 | env->pvr.regs[0] = (env->pvr.regs[0] & ~PVR0_VERSION_MASK) | (0x14 << 8); | |
69 | env->pvr.regs[2] ^= PVR2_USE_FPU2_MASK; | |
70 | env->pvr.regs[4] = 0xc56b8000; | |
71 | env->pvr.regs[5] = 0xc56be000; | |
72 | } | |
73 | ||
74 | #define BINARY_DEVICE_TREE_FILE "petalogix-ml605.dtb" | |
75 | static int petalogix_load_device_tree(target_phys_addr_t addr, | |
76 | uint32_t ramsize, | |
77 | target_phys_addr_t initrd_base, | |
78 | target_phys_addr_t initrd_size, | |
79 | const char *kernel_cmdline) | |
80 | { | |
81 | char *path; | |
82 | int fdt_size; | |
83 | #ifdef CONFIG_FDT | |
84 | void *fdt; | |
85 | int r; | |
86 | ||
87 | /* Try the local "mb.dtb" override. */ | |
88 | fdt = load_device_tree("mb.dtb", &fdt_size); | |
89 | if (!fdt) { | |
90 | path = qemu_find_file(QEMU_FILE_TYPE_BIOS, BINARY_DEVICE_TREE_FILE); | |
91 | if (path) { | |
92 | fdt = load_device_tree(path, &fdt_size); | |
7267c094 | 93 | g_free(path); |
00914b7d MS |
94 | } |
95 | if (!fdt) { | |
96 | return 0; | |
97 | } | |
98 | } | |
99 | ||
100 | r = qemu_devtree_setprop_string(fdt, "/chosen", "bootargs", kernel_cmdline); | |
101 | if (r < 0) { | |
102 | fprintf(stderr, "couldn't set /chosen/bootargs\n"); | |
103 | } | |
104 | cpu_physical_memory_write(addr, (void *)fdt, fdt_size); | |
105 | #else | |
106 | /* We lack libfdt so we cannot manipulate the fdt. Just pass on the blob | |
107 | to the kernel. */ | |
108 | fdt_size = load_image_targphys("mb.dtb", addr, 0x10000); | |
109 | if (fdt_size < 0) { | |
110 | path = qemu_find_file(QEMU_FILE_TYPE_BIOS, BINARY_DEVICE_TREE_FILE); | |
111 | if (path) { | |
112 | fdt_size = load_image_targphys(path, addr, 0x10000); | |
7267c094 | 113 | g_free(path); |
00914b7d MS |
114 | } |
115 | } | |
116 | ||
117 | if (kernel_cmdline) { | |
118 | fprintf(stderr, | |
119 | "Warning: missing libfdt, cannot pass cmdline to kernel!\n"); | |
120 | } | |
121 | #endif | |
122 | return fdt_size; | |
123 | } | |
124 | ||
125 | static uint64_t translate_kernel_address(void *opaque, uint64_t addr) | |
126 | { | |
127 | return addr - 0x30000000LL; | |
128 | } | |
129 | ||
130 | #define MEMORY_BASEADDR 0x50000000 | |
131 | #define FLASH_BASEADDR 0x86000000 | |
132 | #define INTC_BASEADDR 0x81800000 | |
133 | #define TIMER_BASEADDR 0x83c00000 | |
134 | #define UART16550_BASEADDR 0x83e00000 | |
135 | #define AXIENET_BASEADDR 0x82780000 | |
136 | #define AXIDMA_BASEADDR 0x84600000 | |
137 | ||
138 | static void | |
139 | petalogix_ml605_init(ram_addr_t ram_size, | |
140 | const char *boot_device, | |
141 | const char *kernel_filename, | |
142 | const char *kernel_cmdline, | |
143 | const char *initrd_filename, const char *cpu_model) | |
144 | { | |
39186d8a | 145 | MemoryRegion *address_space_mem = get_system_memory(); |
00914b7d MS |
146 | DeviceState *dev; |
147 | CPUState *env; | |
148 | int kernel_size; | |
149 | DriveInfo *dinfo; | |
150 | int i; | |
151 | target_phys_addr_t ddr_base = MEMORY_BASEADDR; | |
d7973c77 AK |
152 | MemoryRegion *phys_lmb_bram = g_new(MemoryRegion, 1); |
153 | MemoryRegion *phys_ram = g_new(MemoryRegion, 1); | |
00914b7d | 154 | qemu_irq irq[32], *cpu_irq; |
00914b7d MS |
155 | |
156 | /* init CPUs */ | |
157 | if (cpu_model == NULL) { | |
158 | cpu_model = "microblaze"; | |
159 | } | |
160 | env = cpu_init(cpu_model); | |
161 | ||
162 | qemu_register_reset(main_cpu_reset, env); | |
163 | ||
164 | /* Attach emulated BRAM through the LMB. */ | |
c5705a77 | 165 | memory_region_init_ram(phys_lmb_bram, "petalogix_ml605.lmb_bram", |
d7973c77 | 166 | LMB_BRAM_SIZE); |
c5705a77 | 167 | vmstate_register_ram_global(phys_lmb_bram); |
d7973c77 | 168 | memory_region_add_subregion(address_space_mem, 0x00000000, phys_lmb_bram); |
00914b7d | 169 | |
c5705a77 AK |
170 | memory_region_init_ram(phys_ram, "petalogix_ml605.ram", ram_size); |
171 | vmstate_register_ram_global(phys_ram); | |
d7973c77 | 172 | memory_region_add_subregion(address_space_mem, ddr_base, phys_ram); |
00914b7d | 173 | |
00914b7d MS |
174 | dinfo = drive_get(IF_PFLASH, 0, 0); |
175 | /* 5th parameter 2 means bank-width | |
176 | * 10th paremeter 0 means little-endian */ | |
cfe5f011 AK |
177 | pflash_cfi01_register(FLASH_BASEADDR, |
178 | NULL, "petalogix_ml605.flash", FLASH_SIZE, | |
00914b7d MS |
179 | dinfo ? dinfo->bdrv : NULL, (64 * 1024), |
180 | FLASH_SIZE >> 16, | |
01e0451a | 181 | 2, 0x89, 0x18, 0x0000, 0x0, 0); |
00914b7d MS |
182 | |
183 | ||
184 | cpu_irq = microblaze_pic_init_cpu(env); | |
185 | dev = xilinx_intc_create(INTC_BASEADDR, cpu_irq[0], 4); | |
186 | for (i = 0; i < 32; i++) { | |
187 | irq[i] = qdev_get_gpio_in(dev, i); | |
188 | } | |
189 | ||
39186d8a RH |
190 | serial_mm_init(address_space_mem, UART16550_BASEADDR + 0x1000, 2, |
191 | irq[5], 115200, serial_hds[0], DEVICE_LITTLE_ENDIAN); | |
00914b7d MS |
192 | |
193 | /* 2 timers at irq 2 @ 100 Mhz. */ | |
194 | xilinx_timer_create(TIMER_BASEADDR, irq[2], 2, 100 * 1000000); | |
195 | ||
196 | /* axi ethernet and dma initialization. TODO: Dynamically connect them. */ | |
197 | { | |
198 | static struct XilinxDMAConnection dmach; | |
199 | ||
200 | xilinx_axiethernet_create(&dmach, &nd_table[0], 0x82780000, | |
201 | irq[3], 0x1000, 0x1000); | |
202 | xilinx_axiethernetdma_create(&dmach, 0x84600000, | |
203 | irq[1], irq[0], 100 * 1000000); | |
204 | } | |
205 | ||
206 | if (kernel_filename) { | |
207 | uint64_t entry, low, high; | |
208 | uint32_t base32; | |
209 | int big_endian = 0; | |
210 | ||
211 | #ifdef TARGET_WORDS_BIGENDIAN | |
212 | big_endian = 1; | |
213 | #endif | |
214 | ||
215 | /* Boots a kernel elf binary. */ | |
216 | kernel_size = load_elf(kernel_filename, NULL, NULL, | |
217 | &entry, &low, &high, | |
218 | big_endian, ELF_MACHINE, 0); | |
219 | base32 = entry; | |
220 | if (base32 == 0xc0000000) { | |
221 | kernel_size = load_elf(kernel_filename, translate_kernel_address, | |
222 | NULL, &entry, NULL, NULL, | |
223 | big_endian, ELF_MACHINE, 0); | |
224 | } | |
225 | /* Always boot into physical ram. */ | |
226 | boot_info.bootstrap_pc = ddr_base + (entry & 0x0fffffff); | |
227 | ||
228 | /* If it wasn't an ELF image, try an u-boot image. */ | |
229 | if (kernel_size < 0) { | |
230 | target_phys_addr_t uentry, loadaddr; | |
231 | ||
232 | kernel_size = load_uimage(kernel_filename, &uentry, &loadaddr, 0); | |
233 | boot_info.bootstrap_pc = uentry; | |
234 | high = (loadaddr + kernel_size + 3) & ~3; | |
235 | } | |
236 | ||
237 | /* Not an ELF image nor an u-boot image, try a RAW image. */ | |
238 | if (kernel_size < 0) { | |
239 | kernel_size = load_image_targphys(kernel_filename, ddr_base, | |
240 | ram_size); | |
241 | boot_info.bootstrap_pc = ddr_base; | |
242 | high = (ddr_base + kernel_size + 3) & ~3; | |
243 | } | |
244 | ||
245 | boot_info.cmdline = high + 4096; | |
246 | if (kernel_cmdline && strlen(kernel_cmdline)) { | |
247 | pstrcpy_targphys("cmdline", boot_info.cmdline, 256, kernel_cmdline); | |
248 | } | |
249 | /* Provide a device-tree. */ | |
250 | boot_info.fdt = boot_info.cmdline + 4096; | |
251 | petalogix_load_device_tree(boot_info.fdt, ram_size, | |
252 | 0, 0, | |
253 | kernel_cmdline); | |
254 | } | |
255 | } | |
256 | ||
257 | static QEMUMachine petalogix_ml605_machine = { | |
258 | .name = "petalogix-ml605", | |
259 | .desc = "PetaLogix linux refdesign for xilinx ml605 little endian", | |
260 | .init = petalogix_ml605_init, | |
261 | .is_default = 0 | |
262 | }; | |
263 | ||
264 | static void petalogix_ml605_machine_init(void) | |
265 | { | |
266 | qemu_register_machine(&petalogix_ml605_machine); | |
267 | } | |
268 | ||
269 | machine_init(petalogix_ml605_machine_init); |