]>
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" | |
41 | ||
42 | #include "xilinx_axidma.h" | |
43 | ||
44 | #define LMB_BRAM_SIZE (128 * 1024) | |
45 | #define FLASH_SIZE (32 * 1024 * 1024) | |
46 | ||
47 | static struct | |
48 | { | |
49 | uint32_t bootstrap_pc; | |
50 | uint32_t cmdline; | |
51 | uint32_t fdt; | |
52 | } boot_info; | |
53 | ||
54 | static void main_cpu_reset(void *opaque) | |
55 | { | |
56 | CPUState *env = opaque; | |
57 | ||
58 | cpu_reset(env); | |
59 | env->regs[5] = boot_info.cmdline; | |
60 | env->regs[7] = boot_info.fdt; | |
61 | env->sregs[SR_PC] = boot_info.bootstrap_pc; | |
62 | env->pvr.regs[10] = 0x0e000000; /* virtex 6 */ | |
63 | /* setup pvr to match kernel setting */ | |
64 | env->pvr.regs[5] |= PVR5_DCACHE_WRITEBACK_MASK; | |
65 | env->pvr.regs[0] |= PVR0_USE_FPU_MASK | PVR0_ENDI; | |
66 | env->pvr.regs[0] = (env->pvr.regs[0] & ~PVR0_VERSION_MASK) | (0x14 << 8); | |
67 | env->pvr.regs[2] ^= PVR2_USE_FPU2_MASK; | |
68 | env->pvr.regs[4] = 0xc56b8000; | |
69 | env->pvr.regs[5] = 0xc56be000; | |
70 | } | |
71 | ||
72 | #define BINARY_DEVICE_TREE_FILE "petalogix-ml605.dtb" | |
73 | static int petalogix_load_device_tree(target_phys_addr_t addr, | |
74 | uint32_t ramsize, | |
75 | target_phys_addr_t initrd_base, | |
76 | target_phys_addr_t initrd_size, | |
77 | const char *kernel_cmdline) | |
78 | { | |
79 | char *path; | |
80 | int fdt_size; | |
81 | #ifdef CONFIG_FDT | |
82 | void *fdt; | |
83 | int r; | |
84 | ||
85 | /* Try the local "mb.dtb" override. */ | |
86 | fdt = load_device_tree("mb.dtb", &fdt_size); | |
87 | if (!fdt) { | |
88 | path = qemu_find_file(QEMU_FILE_TYPE_BIOS, BINARY_DEVICE_TREE_FILE); | |
89 | if (path) { | |
90 | fdt = load_device_tree(path, &fdt_size); | |
91 | qemu_free(path); | |
92 | } | |
93 | if (!fdt) { | |
94 | return 0; | |
95 | } | |
96 | } | |
97 | ||
98 | r = qemu_devtree_setprop_string(fdt, "/chosen", "bootargs", kernel_cmdline); | |
99 | if (r < 0) { | |
100 | fprintf(stderr, "couldn't set /chosen/bootargs\n"); | |
101 | } | |
102 | cpu_physical_memory_write(addr, (void *)fdt, fdt_size); | |
103 | #else | |
104 | /* We lack libfdt so we cannot manipulate the fdt. Just pass on the blob | |
105 | to the kernel. */ | |
106 | fdt_size = load_image_targphys("mb.dtb", addr, 0x10000); | |
107 | if (fdt_size < 0) { | |
108 | path = qemu_find_file(QEMU_FILE_TYPE_BIOS, BINARY_DEVICE_TREE_FILE); | |
109 | if (path) { | |
110 | fdt_size = load_image_targphys(path, addr, 0x10000); | |
111 | qemu_free(path); | |
112 | } | |
113 | } | |
114 | ||
115 | if (kernel_cmdline) { | |
116 | fprintf(stderr, | |
117 | "Warning: missing libfdt, cannot pass cmdline to kernel!\n"); | |
118 | } | |
119 | #endif | |
120 | return fdt_size; | |
121 | } | |
122 | ||
123 | static uint64_t translate_kernel_address(void *opaque, uint64_t addr) | |
124 | { | |
125 | return addr - 0x30000000LL; | |
126 | } | |
127 | ||
128 | #define MEMORY_BASEADDR 0x50000000 | |
129 | #define FLASH_BASEADDR 0x86000000 | |
130 | #define INTC_BASEADDR 0x81800000 | |
131 | #define TIMER_BASEADDR 0x83c00000 | |
132 | #define UART16550_BASEADDR 0x83e00000 | |
133 | #define AXIENET_BASEADDR 0x82780000 | |
134 | #define AXIDMA_BASEADDR 0x84600000 | |
135 | ||
136 | static void | |
137 | petalogix_ml605_init(ram_addr_t ram_size, | |
138 | const char *boot_device, | |
139 | const char *kernel_filename, | |
140 | const char *kernel_cmdline, | |
141 | const char *initrd_filename, const char *cpu_model) | |
142 | { | |
143 | DeviceState *dev; | |
144 | CPUState *env; | |
145 | int kernel_size; | |
146 | DriveInfo *dinfo; | |
147 | int i; | |
148 | target_phys_addr_t ddr_base = MEMORY_BASEADDR; | |
149 | ram_addr_t phys_lmb_bram; | |
150 | ram_addr_t phys_ram; | |
151 | ram_addr_t phys_flash; | |
152 | qemu_irq irq[32], *cpu_irq; | |
00914b7d MS |
153 | |
154 | /* init CPUs */ | |
155 | if (cpu_model == NULL) { | |
156 | cpu_model = "microblaze"; | |
157 | } | |
158 | env = cpu_init(cpu_model); | |
159 | ||
160 | qemu_register_reset(main_cpu_reset, env); | |
161 | ||
162 | /* Attach emulated BRAM through the LMB. */ | |
163 | phys_lmb_bram = qemu_ram_alloc(NULL, "petalogix_ml605.lmb_bram", | |
164 | LMB_BRAM_SIZE); | |
165 | cpu_register_physical_memory(0x00000000, LMB_BRAM_SIZE, | |
166 | phys_lmb_bram | IO_MEM_RAM); | |
167 | ||
168 | phys_ram = qemu_ram_alloc(NULL, "petalogix_ml605.ram", ram_size); | |
169 | cpu_register_physical_memory(ddr_base, ram_size, phys_ram | IO_MEM_RAM); | |
170 | ||
171 | phys_flash = qemu_ram_alloc(NULL, "petalogix_ml605.flash", FLASH_SIZE); | |
172 | dinfo = drive_get(IF_PFLASH, 0, 0); | |
173 | /* 5th parameter 2 means bank-width | |
174 | * 10th paremeter 0 means little-endian */ | |
175 | pflash_cfi01_register(FLASH_BASEADDR, phys_flash, | |
176 | dinfo ? dinfo->bdrv : NULL, (64 * 1024), | |
177 | FLASH_SIZE >> 16, | |
178 | 2, 0x89, 0x18, 0x0000, 0x0, 0); | |
179 | ||
180 | ||
181 | cpu_irq = microblaze_pic_init_cpu(env); | |
182 | dev = xilinx_intc_create(INTC_BASEADDR, cpu_irq[0], 4); | |
183 | for (i = 0; i < 32; i++) { | |
184 | irq[i] = qdev_get_gpio_in(dev, i); | |
185 | } | |
186 | ||
d81e54de BS |
187 | serial_mm_init(UART16550_BASEADDR + 0x1000, 2, irq[5], 115200, |
188 | serial_hds[0], 1, 0); | |
00914b7d MS |
189 | |
190 | /* 2 timers at irq 2 @ 100 Mhz. */ | |
191 | xilinx_timer_create(TIMER_BASEADDR, irq[2], 2, 100 * 1000000); | |
192 | ||
193 | /* axi ethernet and dma initialization. TODO: Dynamically connect them. */ | |
194 | { | |
195 | static struct XilinxDMAConnection dmach; | |
196 | ||
197 | xilinx_axiethernet_create(&dmach, &nd_table[0], 0x82780000, | |
198 | irq[3], 0x1000, 0x1000); | |
199 | xilinx_axiethernetdma_create(&dmach, 0x84600000, | |
200 | irq[1], irq[0], 100 * 1000000); | |
201 | } | |
202 | ||
203 | if (kernel_filename) { | |
204 | uint64_t entry, low, high; | |
205 | uint32_t base32; | |
206 | int big_endian = 0; | |
207 | ||
208 | #ifdef TARGET_WORDS_BIGENDIAN | |
209 | big_endian = 1; | |
210 | #endif | |
211 | ||
212 | /* Boots a kernel elf binary. */ | |
213 | kernel_size = load_elf(kernel_filename, NULL, NULL, | |
214 | &entry, &low, &high, | |
215 | big_endian, ELF_MACHINE, 0); | |
216 | base32 = entry; | |
217 | if (base32 == 0xc0000000) { | |
218 | kernel_size = load_elf(kernel_filename, translate_kernel_address, | |
219 | NULL, &entry, NULL, NULL, | |
220 | big_endian, ELF_MACHINE, 0); | |
221 | } | |
222 | /* Always boot into physical ram. */ | |
223 | boot_info.bootstrap_pc = ddr_base + (entry & 0x0fffffff); | |
224 | ||
225 | /* If it wasn't an ELF image, try an u-boot image. */ | |
226 | if (kernel_size < 0) { | |
227 | target_phys_addr_t uentry, loadaddr; | |
228 | ||
229 | kernel_size = load_uimage(kernel_filename, &uentry, &loadaddr, 0); | |
230 | boot_info.bootstrap_pc = uentry; | |
231 | high = (loadaddr + kernel_size + 3) & ~3; | |
232 | } | |
233 | ||
234 | /* Not an ELF image nor an u-boot image, try a RAW image. */ | |
235 | if (kernel_size < 0) { | |
236 | kernel_size = load_image_targphys(kernel_filename, ddr_base, | |
237 | ram_size); | |
238 | boot_info.bootstrap_pc = ddr_base; | |
239 | high = (ddr_base + kernel_size + 3) & ~3; | |
240 | } | |
241 | ||
242 | boot_info.cmdline = high + 4096; | |
243 | if (kernel_cmdline && strlen(kernel_cmdline)) { | |
244 | pstrcpy_targphys("cmdline", boot_info.cmdline, 256, kernel_cmdline); | |
245 | } | |
246 | /* Provide a device-tree. */ | |
247 | boot_info.fdt = boot_info.cmdline + 4096; | |
248 | petalogix_load_device_tree(boot_info.fdt, ram_size, | |
249 | 0, 0, | |
250 | kernel_cmdline); | |
251 | } | |
252 | } | |
253 | ||
254 | static QEMUMachine petalogix_ml605_machine = { | |
255 | .name = "petalogix-ml605", | |
256 | .desc = "PetaLogix linux refdesign for xilinx ml605 little endian", | |
257 | .init = petalogix_ml605_init, | |
258 | .is_default = 0 | |
259 | }; | |
260 | ||
261 | static void petalogix_ml605_machine_init(void) | |
262 | { | |
263 | qemu_register_machine(&petalogix_ml605_machine); | |
264 | } | |
265 | ||
266 | machine_init(petalogix_ml605_machine_init); |