]>
Commit | Line | Data |
---|---|---|
0200db65 MF |
1 | /* |
2 | * Copyright (c) 2011, Max Filippov, Open Source and Linux Lab. | |
3 | * All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms, with or without | |
6 | * modification, are permitted provided that the following conditions are met: | |
7 | * * Redistributions of source code must retain the above copyright | |
8 | * notice, this list of conditions and the following disclaimer. | |
9 | * * Redistributions in binary form must reproduce the above copyright | |
10 | * notice, this list of conditions and the following disclaimer in the | |
11 | * documentation and/or other materials provided with the distribution. | |
12 | * * Neither the name of the Open Source and Linux Lab nor the | |
13 | * names of its contributors may be used to endorse or promote products | |
14 | * derived from this software without specific prior written permission. | |
15 | * | |
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
26 | */ | |
27 | ||
09aae23d | 28 | #include "qemu/osdep.h" |
b941329d | 29 | #include "qemu/units.h" |
da34e65c | 30 | #include "qapi/error.h" |
4771d756 | 31 | #include "cpu.h" |
9c17d615 | 32 | #include "sysemu/sysemu.h" |
83c9f4ca PB |
33 | #include "hw/boards.h" |
34 | #include "hw/loader.h" | |
0200db65 | 35 | #include "elf.h" |
022c62cb PB |
36 | #include "exec/memory.h" |
37 | #include "exec/address-spaces.h" | |
0d09e41a | 38 | #include "hw/char/serial.h" |
1422e32d | 39 | #include "net/net.h" |
83c9f4ca | 40 | #include "hw/sysbus.h" |
0d09e41a | 41 | #include "hw/block/flash.h" |
8228e353 | 42 | #include "chardev/char.h" |
996dfe98 | 43 | #include "sysemu/device_tree.h" |
8488ab02 | 44 | #include "qemu/error-report.h" |
922a01a0 | 45 | #include "qemu/option.h" |
b707ab75 | 46 | #include "bootparam.h" |
e53fa62c | 47 | #include "xtensa_memory.h" |
82b25dc8 | 48 | |
740ad9f7 MF |
49 | typedef struct XtfpgaFlashDesc { |
50 | hwaddr base; | |
51 | size_t size; | |
52 | size_t boot_base; | |
53 | size_t sector_size; | |
54 | } XtfpgaFlashDesc; | |
55 | ||
188ce01d | 56 | typedef struct XtfpgaBoardDesc { |
740ad9f7 | 57 | const XtfpgaFlashDesc *flash; |
82b25dc8 | 58 | size_t sram_size; |
85e2d8d5 | 59 | const hwaddr *io; |
188ce01d | 60 | } XtfpgaBoardDesc; |
0200db65 | 61 | |
188ce01d | 62 | typedef struct XtfpgaFpgaState { |
0200db65 | 63 | MemoryRegion iomem; |
fff7bf14 | 64 | uint32_t freq; |
0200db65 MF |
65 | uint32_t leds; |
66 | uint32_t switches; | |
188ce01d | 67 | } XtfpgaFpgaState; |
0200db65 | 68 | |
188ce01d | 69 | static void xtfpga_fpga_reset(void *opaque) |
0200db65 | 70 | { |
188ce01d | 71 | XtfpgaFpgaState *s = opaque; |
0200db65 MF |
72 | |
73 | s->leds = 0; | |
74 | s->switches = 0; | |
75 | } | |
76 | ||
188ce01d | 77 | static uint64_t xtfpga_fpga_read(void *opaque, hwaddr addr, |
0200db65 MF |
78 | unsigned size) |
79 | { | |
188ce01d | 80 | XtfpgaFpgaState *s = opaque; |
0200db65 MF |
81 | |
82 | switch (addr) { | |
83 | case 0x0: /*build date code*/ | |
556ba668 | 84 | return 0x09272011; |
0200db65 MF |
85 | |
86 | case 0x4: /*processor clock frequency, Hz*/ | |
fff7bf14 | 87 | return s->freq; |
0200db65 MF |
88 | |
89 | case 0x8: /*LEDs (off = 0, on = 1)*/ | |
90 | return s->leds; | |
91 | ||
92 | case 0xc: /*DIP switches (off = 0, on = 1)*/ | |
93 | return s->switches; | |
94 | } | |
95 | return 0; | |
96 | } | |
97 | ||
188ce01d | 98 | static void xtfpga_fpga_write(void *opaque, hwaddr addr, |
0200db65 MF |
99 | uint64_t val, unsigned size) |
100 | { | |
188ce01d | 101 | XtfpgaFpgaState *s = opaque; |
0200db65 MF |
102 | |
103 | switch (addr) { | |
104 | case 0x8: /*LEDs (off = 0, on = 1)*/ | |
105 | s->leds = val; | |
106 | break; | |
107 | ||
108 | case 0x10: /*board reset*/ | |
109 | if (val == 0xdead) { | |
cf83f140 | 110 | qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET); |
0200db65 MF |
111 | } |
112 | break; | |
113 | } | |
114 | } | |
115 | ||
188ce01d MF |
116 | static const MemoryRegionOps xtfpga_fpga_ops = { |
117 | .read = xtfpga_fpga_read, | |
118 | .write = xtfpga_fpga_write, | |
0200db65 MF |
119 | .endianness = DEVICE_NATIVE_ENDIAN, |
120 | }; | |
121 | ||
188ce01d | 122 | static XtfpgaFpgaState *xtfpga_fpga_init(MemoryRegion *address_space, |
fff7bf14 | 123 | hwaddr base, uint32_t freq) |
0200db65 | 124 | { |
188ce01d | 125 | XtfpgaFpgaState *s = g_malloc(sizeof(XtfpgaFpgaState)); |
0200db65 | 126 | |
188ce01d | 127 | memory_region_init_io(&s->iomem, NULL, &xtfpga_fpga_ops, s, |
fff7bf14 | 128 | "xtfpga.fpga", 0x10000); |
0200db65 | 129 | memory_region_add_subregion(address_space, base, &s->iomem); |
fff7bf14 | 130 | s->freq = freq; |
188ce01d MF |
131 | xtfpga_fpga_reset(s); |
132 | qemu_register_reset(xtfpga_fpga_reset, s); | |
0200db65 MF |
133 | return s; |
134 | } | |
135 | ||
188ce01d | 136 | static void xtfpga_net_init(MemoryRegion *address_space, |
a8170e5e AK |
137 | hwaddr base, |
138 | hwaddr descriptors, | |
139 | hwaddr buffers, | |
0200db65 MF |
140 | qemu_irq irq, NICInfo *nd) |
141 | { | |
142 | DeviceState *dev; | |
143 | SysBusDevice *s; | |
144 | MemoryRegion *ram; | |
145 | ||
146 | dev = qdev_create(NULL, "open_eth"); | |
147 | qdev_set_nic_properties(dev, nd); | |
148 | qdev_init_nofail(dev); | |
149 | ||
1356b98d | 150 | s = SYS_BUS_DEVICE(dev); |
0200db65 MF |
151 | sysbus_connect_irq(s, 0, irq); |
152 | memory_region_add_subregion(address_space, base, | |
153 | sysbus_mmio_get_region(s, 0)); | |
154 | memory_region_add_subregion(address_space, descriptors, | |
155 | sysbus_mmio_get_region(s, 1)); | |
156 | ||
157 | ram = g_malloc(sizeof(*ram)); | |
b941329d | 158 | memory_region_init_ram_nomigrate(ram, OBJECT(s), "open_eth.ram", 16 * KiB, |
f8ed85ac | 159 | &error_fatal); |
c5705a77 | 160 | vmstate_register_ram_global(ram); |
0200db65 MF |
161 | memory_region_add_subregion(address_space, buffers, ram); |
162 | } | |
163 | ||
68931a40 | 164 | static pflash_t *xtfpga_flash_init(MemoryRegion *address_space, |
188ce01d | 165 | const XtfpgaBoardDesc *board, |
68931a40 MF |
166 | DriveInfo *dinfo, int be) |
167 | { | |
168 | SysBusDevice *s; | |
169 | DeviceState *dev = qdev_create(NULL, "cfi.pflash01"); | |
170 | ||
171 | qdev_prop_set_drive(dev, "drive", blk_by_legacy_dinfo(dinfo), | |
172 | &error_abort); | |
173 | qdev_prop_set_uint32(dev, "num-blocks", | |
740ad9f7 MF |
174 | board->flash->size / board->flash->sector_size); |
175 | qdev_prop_set_uint64(dev, "sector-length", board->flash->sector_size); | |
f9a555e4 | 176 | qdev_prop_set_uint8(dev, "width", 2); |
68931a40 | 177 | qdev_prop_set_bit(dev, "big-endian", be); |
188ce01d | 178 | qdev_prop_set_string(dev, "name", "xtfpga.io.flash"); |
68931a40 MF |
179 | qdev_init_nofail(dev); |
180 | s = SYS_BUS_DEVICE(dev); | |
740ad9f7 | 181 | memory_region_add_subregion(address_space, board->flash->base, |
68931a40 MF |
182 | sysbus_mmio_get_region(s, 0)); |
183 | return OBJECT_CHECK(pflash_t, (dev), "cfi.pflash01"); | |
184 | } | |
185 | ||
00b941e5 | 186 | static uint64_t translate_phys_addr(void *opaque, uint64_t addr) |
0200db65 | 187 | { |
00b941e5 AF |
188 | XtensaCPU *cpu = opaque; |
189 | ||
190 | return cpu_get_phys_page_debug(CPU(cpu), addr); | |
0200db65 MF |
191 | } |
192 | ||
188ce01d | 193 | static void xtfpga_reset(void *opaque) |
0200db65 | 194 | { |
eded1267 | 195 | XtensaCPU *cpu = opaque; |
1bba0dc9 | 196 | |
eded1267 | 197 | cpu_reset(CPU(cpu)); |
0200db65 MF |
198 | } |
199 | ||
188ce01d | 200 | static uint64_t xtfpga_io_read(void *opaque, hwaddr addr, |
8bb3b575 MF |
201 | unsigned size) |
202 | { | |
203 | return 0; | |
204 | } | |
205 | ||
188ce01d | 206 | static void xtfpga_io_write(void *opaque, hwaddr addr, |
8bb3b575 MF |
207 | uint64_t val, unsigned size) |
208 | { | |
209 | } | |
210 | ||
188ce01d MF |
211 | static const MemoryRegionOps xtfpga_io_ops = { |
212 | .read = xtfpga_io_read, | |
213 | .write = xtfpga_io_write, | |
8bb3b575 MF |
214 | .endianness = DEVICE_NATIVE_ENDIAN, |
215 | }; | |
216 | ||
188ce01d | 217 | static void xtfpga_init(const XtfpgaBoardDesc *board, MachineState *machine) |
0200db65 MF |
218 | { |
219 | #ifdef TARGET_WORDS_BIGENDIAN | |
220 | int be = 1; | |
221 | #else | |
222 | int be = 0; | |
223 | #endif | |
224 | MemoryRegion *system_memory = get_system_memory(); | |
adbb0f75 | 225 | XtensaCPU *cpu = NULL; |
5bfcb36e | 226 | CPUXtensaState *env = NULL; |
e53fa62c | 227 | MemoryRegion *system_io; |
66f03d7e | 228 | qemu_irq *extints; |
82b25dc8 MF |
229 | DriveInfo *dinfo; |
230 | pflash_t *flash = NULL; | |
37b259d0 | 231 | QemuOpts *machine_opts = qemu_get_machine_opts(); |
37b259d0 MF |
232 | const char *kernel_filename = qemu_opt_get(machine_opts, "kernel"); |
233 | const char *kernel_cmdline = qemu_opt_get(machine_opts, "append"); | |
996dfe98 | 234 | const char *dtb_filename = qemu_opt_get(machine_opts, "dtb"); |
f55b32e7 | 235 | const char *initrd_filename = qemu_opt_get(machine_opts, "initrd"); |
b941329d | 236 | const unsigned system_io_size = 224 * MiB; |
fff7bf14 | 237 | uint32_t freq = 10000000; |
0200db65 MF |
238 | int n; |
239 | ||
240 | for (n = 0; n < smp_cpus; n++) { | |
288a3f2e MF |
241 | CPUXtensaState *cenv = NULL; |
242 | ||
f83eb10d | 243 | cpu = XTENSA_CPU(cpu_create(machine->cpu_type)); |
288a3f2e MF |
244 | cenv = &cpu->env; |
245 | if (!env) { | |
246 | env = cenv; | |
fff7bf14 | 247 | freq = env->config->clock_freq_khz * 1000; |
288a3f2e | 248 | } |
adbb0f75 | 249 | |
288a3f2e | 250 | cenv->sregs[PRID] = n; |
188ce01d | 251 | qemu_register_reset(xtfpga_reset, cpu); |
0200db65 MF |
252 | /* Need MMU initialized prior to ELF loading, |
253 | * so that ELF gets loaded into virtual addresses | |
254 | */ | |
adbb0f75 | 255 | cpu_reset(CPU(cpu)); |
0200db65 | 256 | } |
66f03d7e | 257 | extints = xtensa_get_extints(env); |
0200db65 | 258 | |
e53fa62c MF |
259 | if (env) { |
260 | XtensaMemory sysram = env->config->sysram; | |
261 | ||
262 | sysram.location[0].size = machine->ram_size; | |
263 | xtensa_create_memory_regions(&env->config->instrom, "xtensa.instrom", | |
264 | system_memory); | |
265 | xtensa_create_memory_regions(&env->config->instram, "xtensa.instram", | |
266 | system_memory); | |
267 | xtensa_create_memory_regions(&env->config->datarom, "xtensa.datarom", | |
268 | system_memory); | |
269 | xtensa_create_memory_regions(&env->config->dataram, "xtensa.dataram", | |
270 | system_memory); | |
271 | xtensa_create_memory_regions(&sysram, "xtensa.sysram", | |
272 | system_memory); | |
273 | } | |
0200db65 | 274 | |
0200db65 | 275 | system_io = g_malloc(sizeof(*system_io)); |
188ce01d | 276 | memory_region_init_io(system_io, NULL, &xtfpga_io_ops, NULL, "xtfpga.io", |
85e2d8d5 MF |
277 | system_io_size); |
278 | memory_region_add_subregion(system_memory, board->io[0], system_io); | |
279 | if (board->io[1]) { | |
280 | MemoryRegion *io = g_malloc(sizeof(*io)); | |
281 | ||
282 | memory_region_init_alias(io, NULL, "xtfpga.io.cached", | |
283 | system_io, 0, system_io_size); | |
284 | memory_region_add_subregion(system_memory, board->io[1], io); | |
285 | } | |
fff7bf14 | 286 | xtfpga_fpga_init(system_io, 0x0d020000, freq); |
a005d073 | 287 | if (nd_table[0].used) { |
188ce01d | 288 | xtfpga_net_init(system_io, 0x0d030000, 0x0d030400, 0x0d800000, |
66f03d7e | 289 | extints[1], nd_table); |
0200db65 MF |
290 | } |
291 | ||
66f03d7e MF |
292 | serial_mm_init(system_io, 0x0d050020, 2, extints[0], |
293 | 115200, serial_hd(0), DEVICE_NATIVE_ENDIAN); | |
0200db65 | 294 | |
82b25dc8 MF |
295 | dinfo = drive_get(IF_PFLASH, 0, 0); |
296 | if (dinfo) { | |
68931a40 | 297 | flash = xtfpga_flash_init(system_io, board, dinfo, be); |
82b25dc8 MF |
298 | } |
299 | ||
300 | /* Use presence of kernel file name as 'boot from SRAM' switch. */ | |
0200db65 | 301 | if (kernel_filename) { |
364d4802 | 302 | uint32_t entry_point = env->pc; |
b6edea8b | 303 | size_t bp_size = 3 * get_tag_size(0); /* first/last and memory tags */ |
e53fa62c MF |
304 | uint32_t tagptr = env->config->sysrom.location[0].addr + |
305 | board->sram_size; | |
a9a28591 | 306 | uint32_t cur_tagptr; |
b6edea8b MF |
307 | BpMemInfo memory_location = { |
308 | .type = tswap32(MEMORY_TYPE_CONVENTIONAL), | |
e53fa62c MF |
309 | .start = tswap32(env->config->sysram.location[0].addr), |
310 | .end = tswap32(env->config->sysram.location[0].addr + | |
311 | machine->ram_size), | |
b6edea8b | 312 | }; |
996dfe98 MF |
313 | uint32_t lowmem_end = machine->ram_size < 0x08000000 ? |
314 | machine->ram_size : 0x08000000; | |
315 | uint32_t cur_lowmem = QEMU_ALIGN_UP(lowmem_end / 2, 4096); | |
a9a28591 | 316 | |
e53fa62c MF |
317 | lowmem_end += env->config->sysram.location[0].addr; |
318 | cur_lowmem += env->config->sysram.location[0].addr; | |
319 | ||
320 | xtensa_create_memory_regions(&env->config->sysrom, "xtensa.sysrom", | |
321 | system_memory); | |
292627bb | 322 | |
a9a28591 MF |
323 | if (kernel_cmdline) { |
324 | bp_size += get_tag_size(strlen(kernel_cmdline) + 1); | |
325 | } | |
996dfe98 MF |
326 | if (dtb_filename) { |
327 | bp_size += get_tag_size(sizeof(uint32_t)); | |
328 | } | |
f55b32e7 MF |
329 | if (initrd_filename) { |
330 | bp_size += get_tag_size(sizeof(BpMemInfo)); | |
331 | } | |
a9a28591 | 332 | |
292627bb | 333 | /* Put kernel bootparameters to the end of that SRAM */ |
a9a28591 MF |
334 | tagptr = (tagptr - bp_size) & ~0xff; |
335 | cur_tagptr = put_tag(tagptr, BP_TAG_FIRST, 0, NULL); | |
b6edea8b MF |
336 | cur_tagptr = put_tag(cur_tagptr, BP_TAG_MEMORY, |
337 | sizeof(memory_location), &memory_location); | |
a9a28591 | 338 | |
292627bb | 339 | if (kernel_cmdline) { |
a9a28591 MF |
340 | cur_tagptr = put_tag(cur_tagptr, BP_TAG_COMMAND_LINE, |
341 | strlen(kernel_cmdline) + 1, kernel_cmdline); | |
292627bb | 342 | } |
0e80359e | 343 | #ifdef CONFIG_FDT |
996dfe98 MF |
344 | if (dtb_filename) { |
345 | int fdt_size; | |
346 | void *fdt = load_device_tree(dtb_filename, &fdt_size); | |
347 | uint32_t dtb_addr = tswap32(cur_lowmem); | |
348 | ||
349 | if (!fdt) { | |
ebbb419a | 350 | error_report("could not load DTB '%s'", dtb_filename); |
996dfe98 MF |
351 | exit(EXIT_FAILURE); |
352 | } | |
353 | ||
354 | cpu_physical_memory_write(cur_lowmem, fdt, fdt_size); | |
355 | cur_tagptr = put_tag(cur_tagptr, BP_TAG_FDT, | |
356 | sizeof(dtb_addr), &dtb_addr); | |
b941329d | 357 | cur_lowmem = QEMU_ALIGN_UP(cur_lowmem + fdt_size, 4 * KiB); |
996dfe98 | 358 | } |
0e80359e MF |
359 | #else |
360 | if (dtb_filename) { | |
361 | error_report("could not load DTB '%s': " | |
362 | "FDT support is not configured in QEMU", | |
363 | dtb_filename); | |
364 | exit(EXIT_FAILURE); | |
365 | } | |
366 | #endif | |
f55b32e7 MF |
367 | if (initrd_filename) { |
368 | BpMemInfo initrd_location = { 0 }; | |
369 | int initrd_size = load_ramdisk(initrd_filename, cur_lowmem, | |
370 | lowmem_end - cur_lowmem); | |
371 | ||
372 | if (initrd_size < 0) { | |
373 | initrd_size = load_image_targphys(initrd_filename, | |
374 | cur_lowmem, | |
375 | lowmem_end - cur_lowmem); | |
376 | } | |
377 | if (initrd_size < 0) { | |
ebbb419a | 378 | error_report("could not load initrd '%s'", initrd_filename); |
f55b32e7 MF |
379 | exit(EXIT_FAILURE); |
380 | } | |
381 | initrd_location.start = tswap32(cur_lowmem); | |
382 | initrd_location.end = tswap32(cur_lowmem + initrd_size); | |
383 | cur_tagptr = put_tag(cur_tagptr, BP_TAG_INITRD, | |
384 | sizeof(initrd_location), &initrd_location); | |
b941329d | 385 | cur_lowmem = QEMU_ALIGN_UP(cur_lowmem + initrd_size, 4 * KiB); |
f55b32e7 | 386 | } |
a9a28591 MF |
387 | cur_tagptr = put_tag(cur_tagptr, BP_TAG_LAST, 0, NULL); |
388 | env->regs[2] = tagptr; | |
389 | ||
0200db65 MF |
390 | uint64_t elf_entry; |
391 | uint64_t elf_lowaddr; | |
00b941e5 | 392 | int success = load_elf(kernel_filename, translate_phys_addr, cpu, |
7ef295ea | 393 | &elf_entry, &elf_lowaddr, NULL, be, EM_XTENSA, 0, 0); |
0200db65 | 394 | if (success > 0) { |
364d4802 MF |
395 | entry_point = elf_entry; |
396 | } else { | |
397 | hwaddr ep; | |
398 | int is_linux; | |
25bda50a | 399 | success = load_uimage(kernel_filename, &ep, NULL, &is_linux, |
6d2e4530 | 400 | translate_phys_addr, cpu); |
364d4802 MF |
401 | if (success > 0 && is_linux) { |
402 | entry_point = ep; | |
403 | } else { | |
ebbb419a | 404 | error_report("could not load kernel '%s'", |
364d4802 MF |
405 | kernel_filename); |
406 | exit(EXIT_FAILURE); | |
407 | } | |
408 | } | |
409 | if (entry_point != env->pc) { | |
339ef8fb | 410 | uint8_t boot[] = { |
364d4802 | 411 | #ifdef TARGET_WORDS_BIGENDIAN |
339ef8fb MF |
412 | 0x60, 0x00, 0x08, /* j 1f */ |
413 | 0x00, /* .literal_position */ | |
414 | 0x00, 0x00, 0x00, 0x00, /* .literal entry_pc */ | |
415 | 0x00, 0x00, 0x00, 0x00, /* .literal entry_a2 */ | |
416 | /* 1: */ | |
417 | 0x10, 0xff, 0xfe, /* l32r a0, entry_pc */ | |
418 | 0x12, 0xff, 0xfe, /* l32r a2, entry_a2 */ | |
419 | 0x0a, 0x00, 0x00, /* jx a0 */ | |
364d4802 | 420 | #else |
339ef8fb MF |
421 | 0x06, 0x02, 0x00, /* j 1f */ |
422 | 0x00, /* .literal_position */ | |
423 | 0x00, 0x00, 0x00, 0x00, /* .literal entry_pc */ | |
424 | 0x00, 0x00, 0x00, 0x00, /* .literal entry_a2 */ | |
425 | /* 1: */ | |
426 | 0x01, 0xfe, 0xff, /* l32r a0, entry_pc */ | |
427 | 0x21, 0xfe, 0xff, /* l32r a2, entry_a2 */ | |
428 | 0xa0, 0x00, 0x00, /* jx a0 */ | |
364d4802 MF |
429 | #endif |
430 | }; | |
339ef8fb MF |
431 | uint32_t entry_pc = tswap32(entry_point); |
432 | uint32_t entry_a2 = tswap32(tagptr); | |
433 | ||
434 | memcpy(boot + 4, &entry_pc, sizeof(entry_pc)); | |
435 | memcpy(boot + 8, &entry_a2, sizeof(entry_a2)); | |
436 | cpu_physical_memory_write(env->pc, boot, sizeof(boot)); | |
0200db65 | 437 | } |
82b25dc8 MF |
438 | } else { |
439 | if (flash) { | |
440 | MemoryRegion *flash_mr = pflash_cfi01_get_memory(flash); | |
441 | MemoryRegion *flash_io = g_malloc(sizeof(*flash_io)); | |
e53fa62c MF |
442 | uint32_t size = env->config->sysrom.location[0].size; |
443 | ||
740ad9f7 MF |
444 | if (board->flash->size - board->flash->boot_base < size) { |
445 | size = board->flash->size - board->flash->boot_base; | |
e53fa62c | 446 | } |
82b25dc8 | 447 | |
188ce01d | 448 | memory_region_init_alias(flash_io, NULL, "xtfpga.flash", |
740ad9f7 | 449 | flash_mr, board->flash->boot_base, size); |
e53fa62c MF |
450 | memory_region_add_subregion(system_memory, |
451 | env->config->sysrom.location[0].addr, | |
452 | flash_io); | |
453 | } else { | |
454 | xtensa_create_memory_regions(&env->config->sysrom, "xtensa.sysrom", | |
455 | system_memory); | |
82b25dc8 | 456 | } |
0200db65 MF |
457 | } |
458 | } | |
459 | ||
59b5e9bb MF |
460 | #define XTFPGA_MMU_RESERVED_MEMORY_SIZE (128 * MiB) |
461 | ||
85e2d8d5 MF |
462 | static const hwaddr xtfpga_mmu_io[2] = { |
463 | 0xf0000000, | |
464 | }; | |
465 | ||
466 | static const hwaddr xtfpga_nommu_io[2] = { | |
467 | 0x90000000, | |
468 | 0x70000000, | |
469 | }; | |
470 | ||
740ad9f7 MF |
471 | static const XtfpgaFlashDesc lx60_flash = { |
472 | .base = 0x08000000, | |
473 | .size = 0x00400000, | |
474 | .sector_size = 0x10000, | |
475 | }; | |
476 | ||
188ce01d | 477 | static void xtfpga_lx60_init(MachineState *machine) |
0200db65 | 478 | { |
188ce01d | 479 | static const XtfpgaBoardDesc lx60_board = { |
740ad9f7 | 480 | .flash = &lx60_flash, |
82b25dc8 | 481 | .sram_size = 0x20000, |
85e2d8d5 MF |
482 | .io = xtfpga_mmu_io, |
483 | }; | |
484 | xtfpga_init(&lx60_board, machine); | |
485 | } | |
486 | ||
487 | static void xtfpga_lx60_nommu_init(MachineState *machine) | |
488 | { | |
489 | static const XtfpgaBoardDesc lx60_board = { | |
490 | .flash = &lx60_flash, | |
491 | .sram_size = 0x20000, | |
492 | .io = xtfpga_nommu_io, | |
82b25dc8 | 493 | }; |
188ce01d | 494 | xtfpga_init(&lx60_board, machine); |
82b25dc8 MF |
495 | } |
496 | ||
740ad9f7 MF |
497 | static const XtfpgaFlashDesc lx200_flash = { |
498 | .base = 0x08000000, | |
499 | .size = 0x01000000, | |
500 | .sector_size = 0x20000, | |
501 | }; | |
502 | ||
188ce01d | 503 | static void xtfpga_lx200_init(MachineState *machine) |
82b25dc8 | 504 | { |
188ce01d | 505 | static const XtfpgaBoardDesc lx200_board = { |
740ad9f7 | 506 | .flash = &lx200_flash, |
82b25dc8 | 507 | .sram_size = 0x2000000, |
85e2d8d5 MF |
508 | .io = xtfpga_mmu_io, |
509 | }; | |
510 | xtfpga_init(&lx200_board, machine); | |
511 | } | |
512 | ||
513 | static void xtfpga_lx200_nommu_init(MachineState *machine) | |
514 | { | |
515 | static const XtfpgaBoardDesc lx200_board = { | |
516 | .flash = &lx200_flash, | |
517 | .sram_size = 0x2000000, | |
518 | .io = xtfpga_nommu_io, | |
82b25dc8 | 519 | }; |
188ce01d | 520 | xtfpga_init(&lx200_board, machine); |
0200db65 MF |
521 | } |
522 | ||
740ad9f7 MF |
523 | static const XtfpgaFlashDesc ml605_flash = { |
524 | .base = 0x08000000, | |
525 | .size = 0x01000000, | |
526 | .sector_size = 0x20000, | |
527 | }; | |
528 | ||
188ce01d | 529 | static void xtfpga_ml605_init(MachineState *machine) |
e0db904d | 530 | { |
188ce01d | 531 | static const XtfpgaBoardDesc ml605_board = { |
740ad9f7 | 532 | .flash = &ml605_flash, |
e0db904d | 533 | .sram_size = 0x2000000, |
85e2d8d5 MF |
534 | .io = xtfpga_mmu_io, |
535 | }; | |
536 | xtfpga_init(&ml605_board, machine); | |
537 | } | |
538 | ||
539 | static void xtfpga_ml605_nommu_init(MachineState *machine) | |
540 | { | |
541 | static const XtfpgaBoardDesc ml605_board = { | |
542 | .flash = &ml605_flash, | |
543 | .sram_size = 0x2000000, | |
544 | .io = xtfpga_nommu_io, | |
e0db904d | 545 | }; |
188ce01d | 546 | xtfpga_init(&ml605_board, machine); |
e0db904d MF |
547 | } |
548 | ||
740ad9f7 MF |
549 | static const XtfpgaFlashDesc kc705_flash = { |
550 | .base = 0x00000000, | |
551 | .size = 0x08000000, | |
552 | .boot_base = 0x06000000, | |
553 | .sector_size = 0x20000, | |
554 | }; | |
555 | ||
188ce01d | 556 | static void xtfpga_kc705_init(MachineState *machine) |
e0db904d | 557 | { |
188ce01d | 558 | static const XtfpgaBoardDesc kc705_board = { |
740ad9f7 | 559 | .flash = &kc705_flash, |
e0db904d | 560 | .sram_size = 0x2000000, |
85e2d8d5 MF |
561 | .io = xtfpga_mmu_io, |
562 | }; | |
563 | xtfpga_init(&kc705_board, machine); | |
564 | } | |
565 | ||
566 | static void xtfpga_kc705_nommu_init(MachineState *machine) | |
567 | { | |
568 | static const XtfpgaBoardDesc kc705_board = { | |
569 | .flash = &kc705_flash, | |
570 | .sram_size = 0x2000000, | |
571 | .io = xtfpga_nommu_io, | |
e0db904d | 572 | }; |
188ce01d | 573 | xtfpga_init(&kc705_board, machine); |
e0db904d MF |
574 | } |
575 | ||
188ce01d | 576 | static void xtfpga_lx60_class_init(ObjectClass *oc, void *data) |
e264d29d | 577 | { |
8a661aea AF |
578 | MachineClass *mc = MACHINE_CLASS(oc); |
579 | ||
e264d29d | 580 | mc->desc = "lx60 EVB (" XTENSA_DEFAULT_CPU_MODEL ")"; |
188ce01d | 581 | mc->init = xtfpga_lx60_init; |
e264d29d | 582 | mc->max_cpus = 4; |
f83eb10d | 583 | mc->default_cpu_type = XTENSA_DEFAULT_CPU_TYPE; |
59b5e9bb | 584 | mc->default_ram_size = 64 * MiB; |
e264d29d | 585 | } |
0200db65 | 586 | |
188ce01d | 587 | static const TypeInfo xtfpga_lx60_type = { |
8a661aea AF |
588 | .name = MACHINE_TYPE_NAME("lx60"), |
589 | .parent = TYPE_MACHINE, | |
188ce01d | 590 | .class_init = xtfpga_lx60_class_init, |
8a661aea | 591 | }; |
82b25dc8 | 592 | |
85e2d8d5 MF |
593 | static void xtfpga_lx60_nommu_class_init(ObjectClass *oc, void *data) |
594 | { | |
595 | MachineClass *mc = MACHINE_CLASS(oc); | |
596 | ||
a3c5e49d | 597 | mc->desc = "lx60 noMMU EVB (" XTENSA_DEFAULT_CPU_NOMMU_MODEL ")"; |
85e2d8d5 MF |
598 | mc->init = xtfpga_lx60_nommu_init; |
599 | mc->max_cpus = 4; | |
a3c5e49d | 600 | mc->default_cpu_type = XTENSA_DEFAULT_CPU_NOMMU_TYPE; |
59b5e9bb | 601 | mc->default_ram_size = 64 * MiB; |
85e2d8d5 MF |
602 | } |
603 | ||
604 | static const TypeInfo xtfpga_lx60_nommu_type = { | |
605 | .name = MACHINE_TYPE_NAME("lx60-nommu"), | |
606 | .parent = TYPE_MACHINE, | |
607 | .class_init = xtfpga_lx60_nommu_class_init, | |
608 | }; | |
609 | ||
188ce01d | 610 | static void xtfpga_lx200_class_init(ObjectClass *oc, void *data) |
e264d29d | 611 | { |
8a661aea AF |
612 | MachineClass *mc = MACHINE_CLASS(oc); |
613 | ||
e264d29d | 614 | mc->desc = "lx200 EVB (" XTENSA_DEFAULT_CPU_MODEL ")"; |
188ce01d | 615 | mc->init = xtfpga_lx200_init; |
e264d29d | 616 | mc->max_cpus = 4; |
f83eb10d | 617 | mc->default_cpu_type = XTENSA_DEFAULT_CPU_TYPE; |
59b5e9bb | 618 | mc->default_ram_size = 96 * MiB; |
e264d29d | 619 | } |
e0db904d | 620 | |
188ce01d | 621 | static const TypeInfo xtfpga_lx200_type = { |
8a661aea AF |
622 | .name = MACHINE_TYPE_NAME("lx200"), |
623 | .parent = TYPE_MACHINE, | |
188ce01d | 624 | .class_init = xtfpga_lx200_class_init, |
8a661aea | 625 | }; |
e264d29d | 626 | |
85e2d8d5 MF |
627 | static void xtfpga_lx200_nommu_class_init(ObjectClass *oc, void *data) |
628 | { | |
629 | MachineClass *mc = MACHINE_CLASS(oc); | |
630 | ||
a3c5e49d | 631 | mc->desc = "lx200 noMMU EVB (" XTENSA_DEFAULT_CPU_NOMMU_MODEL ")"; |
85e2d8d5 MF |
632 | mc->init = xtfpga_lx200_nommu_init; |
633 | mc->max_cpus = 4; | |
a3c5e49d | 634 | mc->default_cpu_type = XTENSA_DEFAULT_CPU_NOMMU_TYPE; |
59b5e9bb | 635 | mc->default_ram_size = 96 * MiB; |
85e2d8d5 MF |
636 | } |
637 | ||
638 | static const TypeInfo xtfpga_lx200_nommu_type = { | |
639 | .name = MACHINE_TYPE_NAME("lx200-nommu"), | |
640 | .parent = TYPE_MACHINE, | |
641 | .class_init = xtfpga_lx200_nommu_class_init, | |
642 | }; | |
643 | ||
188ce01d | 644 | static void xtfpga_ml605_class_init(ObjectClass *oc, void *data) |
e264d29d | 645 | { |
8a661aea AF |
646 | MachineClass *mc = MACHINE_CLASS(oc); |
647 | ||
e264d29d | 648 | mc->desc = "ml605 EVB (" XTENSA_DEFAULT_CPU_MODEL ")"; |
188ce01d | 649 | mc->init = xtfpga_ml605_init; |
e264d29d | 650 | mc->max_cpus = 4; |
f83eb10d | 651 | mc->default_cpu_type = XTENSA_DEFAULT_CPU_TYPE; |
59b5e9bb | 652 | mc->default_ram_size = 512 * MiB - XTFPGA_MMU_RESERVED_MEMORY_SIZE; |
e264d29d EH |
653 | } |
654 | ||
188ce01d | 655 | static const TypeInfo xtfpga_ml605_type = { |
8a661aea AF |
656 | .name = MACHINE_TYPE_NAME("ml605"), |
657 | .parent = TYPE_MACHINE, | |
188ce01d | 658 | .class_init = xtfpga_ml605_class_init, |
8a661aea | 659 | }; |
e0db904d | 660 | |
85e2d8d5 MF |
661 | static void xtfpga_ml605_nommu_class_init(ObjectClass *oc, void *data) |
662 | { | |
663 | MachineClass *mc = MACHINE_CLASS(oc); | |
664 | ||
a3c5e49d | 665 | mc->desc = "ml605 noMMU EVB (" XTENSA_DEFAULT_CPU_NOMMU_MODEL ")"; |
85e2d8d5 MF |
666 | mc->init = xtfpga_ml605_nommu_init; |
667 | mc->max_cpus = 4; | |
a3c5e49d | 668 | mc->default_cpu_type = XTENSA_DEFAULT_CPU_NOMMU_TYPE; |
59b5e9bb | 669 | mc->default_ram_size = 256 * MiB; |
85e2d8d5 MF |
670 | } |
671 | ||
672 | static const TypeInfo xtfpga_ml605_nommu_type = { | |
673 | .name = MACHINE_TYPE_NAME("ml605-nommu"), | |
674 | .parent = TYPE_MACHINE, | |
675 | .class_init = xtfpga_ml605_nommu_class_init, | |
676 | }; | |
677 | ||
188ce01d | 678 | static void xtfpga_kc705_class_init(ObjectClass *oc, void *data) |
0200db65 | 679 | { |
8a661aea AF |
680 | MachineClass *mc = MACHINE_CLASS(oc); |
681 | ||
e264d29d | 682 | mc->desc = "kc705 EVB (" XTENSA_DEFAULT_CPU_MODEL ")"; |
188ce01d | 683 | mc->init = xtfpga_kc705_init; |
e264d29d | 684 | mc->max_cpus = 4; |
f83eb10d | 685 | mc->default_cpu_type = XTENSA_DEFAULT_CPU_TYPE; |
59b5e9bb | 686 | mc->default_ram_size = 1 * GiB - XTFPGA_MMU_RESERVED_MEMORY_SIZE; |
0200db65 MF |
687 | } |
688 | ||
188ce01d | 689 | static const TypeInfo xtfpga_kc705_type = { |
8a661aea AF |
690 | .name = MACHINE_TYPE_NAME("kc705"), |
691 | .parent = TYPE_MACHINE, | |
188ce01d | 692 | .class_init = xtfpga_kc705_class_init, |
8a661aea AF |
693 | }; |
694 | ||
85e2d8d5 MF |
695 | static void xtfpga_kc705_nommu_class_init(ObjectClass *oc, void *data) |
696 | { | |
697 | MachineClass *mc = MACHINE_CLASS(oc); | |
698 | ||
a3c5e49d | 699 | mc->desc = "kc705 noMMU EVB (" XTENSA_DEFAULT_CPU_NOMMU_MODEL ")"; |
85e2d8d5 MF |
700 | mc->init = xtfpga_kc705_nommu_init; |
701 | mc->max_cpus = 4; | |
a3c5e49d | 702 | mc->default_cpu_type = XTENSA_DEFAULT_CPU_NOMMU_TYPE; |
59b5e9bb | 703 | mc->default_ram_size = 256 * MiB; |
85e2d8d5 MF |
704 | } |
705 | ||
706 | static const TypeInfo xtfpga_kc705_nommu_type = { | |
707 | .name = MACHINE_TYPE_NAME("kc705-nommu"), | |
708 | .parent = TYPE_MACHINE, | |
709 | .class_init = xtfpga_kc705_nommu_class_init, | |
710 | }; | |
711 | ||
188ce01d | 712 | static void xtfpga_machines_init(void) |
8a661aea | 713 | { |
188ce01d MF |
714 | type_register_static(&xtfpga_lx60_type); |
715 | type_register_static(&xtfpga_lx200_type); | |
716 | type_register_static(&xtfpga_ml605_type); | |
717 | type_register_static(&xtfpga_kc705_type); | |
85e2d8d5 MF |
718 | type_register_static(&xtfpga_lx60_nommu_type); |
719 | type_register_static(&xtfpga_lx200_nommu_type); | |
720 | type_register_static(&xtfpga_ml605_nommu_type); | |
721 | type_register_static(&xtfpga_kc705_nommu_type); | |
8a661aea AF |
722 | } |
723 | ||
188ce01d | 724 | type_init(xtfpga_machines_init) |