]>
Commit | Line | Data |
---|---|---|
6a8b1ae2 EI |
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" | |
ca20cf32 BS |
35 | #include "loader.h" |
36 | #include "elf.h" | |
2446333c | 37 | #include "blockdev.h" |
589f0aad | 38 | #include "exec-memory.h" |
6a8b1ae2 | 39 | |
b861b741 PC |
40 | #include "microblaze_pic_cpu.h" |
41 | ||
6a8b1ae2 EI |
42 | #define LMB_BRAM_SIZE (128 * 1024) |
43 | #define FLASH_SIZE (16 * 1024 * 1024) | |
44 | ||
7029a83b | 45 | static struct |
b4d34d5e EI |
46 | { |
47 | uint32_t bootstrap_pc; | |
48 | uint32_t cmdline; | |
49 | uint32_t fdt; | |
50 | } boot_info; | |
6a8b1ae2 EI |
51 | |
52 | static void main_cpu_reset(void *opaque) | |
53 | { | |
54 | CPUState *env = opaque; | |
be5e8349 EI |
55 | |
56 | cpu_reset(env); | |
b4d34d5e EI |
57 | env->regs[5] = boot_info.cmdline; |
58 | env->regs[7] = boot_info.fdt; | |
59 | env->sregs[SR_PC] = boot_info.bootstrap_pc; | |
6a8b1ae2 EI |
60 | } |
61 | ||
62 | #define BINARY_DEVICE_TREE_FILE "petalogix-s3adsp1800.dtb" | |
c227f099 | 63 | static int petalogix_load_device_tree(target_phys_addr_t addr, |
6a8b1ae2 | 64 | uint32_t ramsize, |
c227f099 AL |
65 | target_phys_addr_t initrd_base, |
66 | target_phys_addr_t initrd_size, | |
6a8b1ae2 EI |
67 | const char *kernel_cmdline) |
68 | { | |
84f15818 JQ |
69 | char *path; |
70 | int fdt_size; | |
3f0855b1 | 71 | #ifdef CONFIG_FDT |
6a8b1ae2 | 72 | void *fdt; |
6a8b1ae2 EI |
73 | int r; |
74 | ||
75 | /* Try the local "mb.dtb" override. */ | |
76 | fdt = load_device_tree("mb.dtb", &fdt_size); | |
77 | if (!fdt) { | |
4b0c7aa3 EI |
78 | path = qemu_find_file(QEMU_FILE_TYPE_BIOS, BINARY_DEVICE_TREE_FILE); |
79 | if (path) { | |
80 | fdt = load_device_tree(path, &fdt_size); | |
7267c094 | 81 | g_free(path); |
4b0c7aa3 | 82 | } |
6a8b1ae2 EI |
83 | if (!fdt) |
84 | return 0; | |
85 | } | |
86 | ||
87 | r = qemu_devtree_setprop_string(fdt, "/chosen", "bootargs", kernel_cmdline); | |
88 | if (r < 0) | |
89 | fprintf(stderr, "couldn't set /chosen/bootargs\n"); | |
6a8b1ae2 | 90 | cpu_physical_memory_write (addr, (void *)fdt, fdt_size); |
7696d1ec EI |
91 | #else |
92 | /* We lack libfdt so we cannot manipulate the fdt. Just pass on the blob | |
93 | to the kernel. */ | |
94 | fdt_size = load_image_targphys("mb.dtb", addr, 0x10000); | |
95 | if (fdt_size < 0) { | |
4b0c7aa3 EI |
96 | path = qemu_find_file(QEMU_FILE_TYPE_BIOS, BINARY_DEVICE_TREE_FILE); |
97 | if (path) { | |
98 | fdt_size = load_image_targphys(path, addr, 0x10000); | |
7267c094 | 99 | g_free(path); |
4b0c7aa3 | 100 | } |
7696d1ec EI |
101 | } |
102 | ||
103 | if (kernel_cmdline) { | |
104 | fprintf(stderr, | |
105 | "Warning: missing libfdt, cannot pass cmdline to kernel!\n"); | |
106 | } | |
107 | #endif | |
6a8b1ae2 EI |
108 | return fdt_size; |
109 | } | |
110 | ||
409dbce5 AJ |
111 | static uint64_t translate_kernel_address(void *opaque, uint64_t addr) |
112 | { | |
113 | return addr - 0x30000000LL; | |
114 | } | |
115 | ||
6a8b1ae2 | 116 | static void |
c227f099 | 117 | petalogix_s3adsp1800_init(ram_addr_t ram_size, |
6a8b1ae2 EI |
118 | const char *boot_device, |
119 | const char *kernel_filename, | |
120 | const char *kernel_cmdline, | |
121 | const char *initrd_filename, const char *cpu_model) | |
122 | { | |
123 | DeviceState *dev; | |
124 | CPUState *env; | |
125 | int kernel_size; | |
751c6a17 | 126 | DriveInfo *dinfo; |
6a8b1ae2 | 127 | int i; |
c227f099 | 128 | target_phys_addr_t ddr_base = 0x90000000; |
589f0aad AK |
129 | MemoryRegion *phys_lmb_bram = g_new(MemoryRegion, 1); |
130 | MemoryRegion *phys_ram = g_new(MemoryRegion, 1); | |
6a8b1ae2 | 131 | qemu_irq irq[32], *cpu_irq; |
589f0aad | 132 | MemoryRegion *sysmem = get_system_memory(); |
6a8b1ae2 EI |
133 | |
134 | /* init CPUs */ | |
135 | if (cpu_model == NULL) { | |
136 | cpu_model = "microblaze"; | |
137 | } | |
138 | env = cpu_init(cpu_model); | |
139 | ||
140 | env->pvr.regs[10] = 0x0c000000; /* spartan 3a dsp family. */ | |
a08d4367 | 141 | qemu_register_reset(main_cpu_reset, env); |
6a8b1ae2 EI |
142 | |
143 | /* Attach emulated BRAM through the LMB. */ | |
589f0aad AK |
144 | memory_region_init_ram(phys_lmb_bram, NULL, |
145 | "petalogix_s3adsp1800.lmb_bram", LMB_BRAM_SIZE); | |
146 | memory_region_add_subregion(sysmem, 0x00000000, phys_lmb_bram); | |
6a8b1ae2 | 147 | |
589f0aad AK |
148 | memory_region_init_ram(phys_ram, NULL, "petalogix_s3adsp1800.ram", |
149 | ram_size); | |
150 | memory_region_add_subregion(sysmem, ddr_base, phys_ram); | |
6a8b1ae2 | 151 | |
751c6a17 | 152 | dinfo = drive_get(IF_PFLASH, 0, 0); |
cfe5f011 AK |
153 | pflash_cfi01_register(0xa0000000, |
154 | NULL, "petalogix_s3adsp1800.flash", FLASH_SIZE, | |
751c6a17 | 155 | dinfo ? dinfo->bdrv : NULL, (64 * 1024), |
6a8b1ae2 | 156 | FLASH_SIZE >> 16, |
01e0451a | 157 | 1, 0x89, 0x18, 0x0000, 0x0, 1); |
6a8b1ae2 EI |
158 | |
159 | cpu_irq = microblaze_pic_init_cpu(env); | |
160 | dev = xilinx_intc_create(0x81800000, cpu_irq[0], 2); | |
161 | for (i = 0; i < 32; i++) { | |
162 | irq[i] = qdev_get_gpio_in(dev, i); | |
163 | } | |
164 | ||
165 | sysbus_create_simple("xilinx,uartlite", 0x84000000, irq[3]); | |
166 | /* 2 timers at irq 2 @ 62 Mhz. */ | |
167 | xilinx_timer_create(0x83c00000, irq[0], 2, 62 * 1000000); | |
168 | xilinx_ethlite_create(&nd_table[0], 0x81000000, irq[1], 0, 0); | |
169 | ||
170 | if (kernel_filename) { | |
171 | uint64_t entry, low, high; | |
6a8b1ae2 | 172 | uint32_t base32; |
082e5be8 EI |
173 | int big_endian = 0; |
174 | ||
175 | #ifdef TARGET_WORDS_BIGENDIAN | |
176 | big_endian = 1; | |
177 | #endif | |
6a8b1ae2 EI |
178 | |
179 | /* Boots a kernel elf binary. */ | |
409dbce5 | 180 | kernel_size = load_elf(kernel_filename, NULL, NULL, |
ca20cf32 | 181 | &entry, &low, &high, |
082e5be8 | 182 | big_endian, ELF_MACHINE, 0); |
6a8b1ae2 EI |
183 | base32 = entry; |
184 | if (base32 == 0xc0000000) { | |
409dbce5 AJ |
185 | kernel_size = load_elf(kernel_filename, translate_kernel_address, |
186 | NULL, &entry, NULL, NULL, | |
082e5be8 | 187 | big_endian, ELF_MACHINE, 0); |
6a8b1ae2 EI |
188 | } |
189 | /* Always boot into physical ram. */ | |
b4d34d5e | 190 | boot_info.bootstrap_pc = ddr_base + (entry & 0x0fffffff); |
872a91b4 EI |
191 | |
192 | /* If it wasn't an ELF image, try an u-boot image. */ | |
193 | if (kernel_size < 0) { | |
194 | target_phys_addr_t uentry, loadaddr; | |
195 | ||
196 | kernel_size = load_uimage(kernel_filename, &uentry, &loadaddr, 0); | |
197 | boot_info.bootstrap_pc = uentry; | |
198 | high = (loadaddr + kernel_size + 3) & ~3; | |
199 | } | |
200 | ||
201 | /* Not an ELF image nor an u-boot image, try a RAW image. */ | |
6a8b1ae2 | 202 | if (kernel_size < 0) { |
6a8b1ae2 EI |
203 | kernel_size = load_image_targphys(kernel_filename, ddr_base, |
204 | ram_size); | |
b4d34d5e | 205 | boot_info.bootstrap_pc = ddr_base; |
811976dc | 206 | high = (ddr_base + kernel_size + 3) & ~3; |
6a8b1ae2 EI |
207 | } |
208 | ||
7375c86f | 209 | boot_info.cmdline = high + 4096; |
183aa454 | 210 | if (kernel_cmdline && strlen(kernel_cmdline)) { |
b4d34d5e | 211 | pstrcpy_targphys("cmdline", boot_info.cmdline, 256, kernel_cmdline); |
6a8b1ae2 | 212 | } |
6a8b1ae2 | 213 | /* Provide a device-tree. */ |
7375c86f | 214 | boot_info.fdt = boot_info.cmdline + 4096; |
b4d34d5e EI |
215 | petalogix_load_device_tree(boot_info.fdt, ram_size, |
216 | 0, 0, | |
6a8b1ae2 EI |
217 | kernel_cmdline); |
218 | } | |
6a8b1ae2 EI |
219 | } |
220 | ||
221 | static QEMUMachine petalogix_s3adsp1800_machine = { | |
222 | .name = "petalogix-s3adsp1800", | |
73ad9e62 | 223 | .desc = "PetaLogix linux refdesign for xilinx Spartan 3ADSP1800", |
6a8b1ae2 EI |
224 | .init = petalogix_s3adsp1800_init, |
225 | .is_default = 1 | |
226 | }; | |
227 | ||
228 | static void petalogix_s3adsp1800_machine_init(void) | |
229 | { | |
230 | qemu_register_machine(&petalogix_s3adsp1800_machine); | |
231 | } | |
232 | ||
233 | machine_init(petalogix_s3adsp1800_machine_init); |