xtfpga.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  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. #include "qemu/osdep.h"
  28. #include "qemu/units.h"
  29. #include "qapi/error.h"
  30. #include "cpu.h"
  31. #include "sysemu/sysemu.h"
  32. #include "hw/boards.h"
  33. #include "hw/loader.h"
  34. #include "hw/qdev-properties.h"
  35. #include "elf.h"
  36. #include "exec/memory.h"
  37. #include "hw/char/serial-mm.h"
  38. #include "net/net.h"
  39. #include "hw/sysbus.h"
  40. #include "hw/block/flash.h"
  41. #include "chardev/char.h"
  42. #include "sysemu/device_tree.h"
  43. #include "sysemu/reset.h"
  44. #include "sysemu/runstate.h"
  45. #include "qemu/error-report.h"
  46. #include "qemu/option.h"
  47. #include "bootparam.h"
  48. #include "xtensa_memory.h"
  49. #include "hw/xtensa/mx_pic.h"
  50. #include "migration/vmstate.h"
  51. typedef struct XtfpgaFlashDesc {
  52. hwaddr base;
  53. size_t size;
  54. size_t boot_base;
  55. size_t sector_size;
  56. } XtfpgaFlashDesc;
  57. typedef struct XtfpgaBoardDesc {
  58. const XtfpgaFlashDesc *flash;
  59. size_t sram_size;
  60. const hwaddr *io;
  61. } XtfpgaBoardDesc;
  62. typedef struct XtfpgaFpgaState {
  63. MemoryRegion iomem;
  64. uint32_t freq;
  65. uint32_t leds;
  66. uint32_t switches;
  67. } XtfpgaFpgaState;
  68. static void xtfpga_fpga_reset(void *opaque)
  69. {
  70. XtfpgaFpgaState *s = opaque;
  71. s->leds = 0;
  72. s->switches = 0;
  73. }
  74. static uint64_t xtfpga_fpga_read(void *opaque, hwaddr addr,
  75. unsigned size)
  76. {
  77. XtfpgaFpgaState *s = opaque;
  78. switch (addr) {
  79. case 0x0: /*build date code*/
  80. return 0x09272011;
  81. case 0x4: /*processor clock frequency, Hz*/
  82. return s->freq;
  83. case 0x8: /*LEDs (off = 0, on = 1)*/
  84. return s->leds;
  85. case 0xc: /*DIP switches (off = 0, on = 1)*/
  86. return s->switches;
  87. }
  88. return 0;
  89. }
  90. static void xtfpga_fpga_write(void *opaque, hwaddr addr,
  91. uint64_t val, unsigned size)
  92. {
  93. XtfpgaFpgaState *s = opaque;
  94. switch (addr) {
  95. case 0x8: /*LEDs (off = 0, on = 1)*/
  96. s->leds = val;
  97. break;
  98. case 0x10: /*board reset*/
  99. if (val == 0xdead) {
  100. qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
  101. }
  102. break;
  103. }
  104. }
  105. static const MemoryRegionOps xtfpga_fpga_ops = {
  106. .read = xtfpga_fpga_read,
  107. .write = xtfpga_fpga_write,
  108. .endianness = DEVICE_NATIVE_ENDIAN,
  109. };
  110. static XtfpgaFpgaState *xtfpga_fpga_init(MemoryRegion *address_space,
  111. hwaddr base, uint32_t freq)
  112. {
  113. XtfpgaFpgaState *s = g_new(XtfpgaFpgaState, 1);
  114. memory_region_init_io(&s->iomem, NULL, &xtfpga_fpga_ops, s,
  115. "xtfpga.fpga", 0x10000);
  116. memory_region_add_subregion(address_space, base, &s->iomem);
  117. s->freq = freq;
  118. xtfpga_fpga_reset(s);
  119. qemu_register_reset(xtfpga_fpga_reset, s);
  120. return s;
  121. }
  122. static void xtfpga_net_init(MemoryRegion *address_space,
  123. hwaddr base,
  124. hwaddr descriptors,
  125. hwaddr buffers,
  126. qemu_irq irq)
  127. {
  128. DeviceState *dev;
  129. SysBusDevice *s;
  130. MemoryRegion *ram;
  131. dev = qemu_create_nic_device("open_eth", true, NULL);
  132. if (!dev) {
  133. return;
  134. }
  135. s = SYS_BUS_DEVICE(dev);
  136. sysbus_realize_and_unref(s, &error_fatal);
  137. sysbus_connect_irq(s, 0, irq);
  138. memory_region_add_subregion(address_space, base,
  139. sysbus_mmio_get_region(s, 0));
  140. memory_region_add_subregion(address_space, descriptors,
  141. sysbus_mmio_get_region(s, 1));
  142. ram = g_malloc(sizeof(*ram));
  143. memory_region_init_ram_nomigrate(ram, OBJECT(s), "open_eth.ram", 16 * KiB,
  144. &error_fatal);
  145. vmstate_register_ram_global(ram);
  146. memory_region_add_subregion(address_space, buffers, ram);
  147. }
  148. static PFlashCFI01 *xtfpga_flash_init(MemoryRegion *address_space,
  149. const XtfpgaBoardDesc *board,
  150. DriveInfo *dinfo, int be)
  151. {
  152. SysBusDevice *s;
  153. DeviceState *dev = qdev_new(TYPE_PFLASH_CFI01);
  154. qdev_prop_set_drive(dev, "drive", blk_by_legacy_dinfo(dinfo));
  155. qdev_prop_set_uint32(dev, "num-blocks",
  156. board->flash->size / board->flash->sector_size);
  157. qdev_prop_set_uint64(dev, "sector-length", board->flash->sector_size);
  158. qdev_prop_set_uint8(dev, "width", 2);
  159. qdev_prop_set_bit(dev, "big-endian", be);
  160. qdev_prop_set_string(dev, "name", "xtfpga.io.flash");
  161. s = SYS_BUS_DEVICE(dev);
  162. sysbus_realize_and_unref(s, &error_fatal);
  163. memory_region_add_subregion(address_space, board->flash->base,
  164. sysbus_mmio_get_region(s, 0));
  165. return PFLASH_CFI01(dev);
  166. }
  167. static uint64_t translate_phys_addr(void *opaque, uint64_t addr)
  168. {
  169. XtensaCPU *cpu = opaque;
  170. return cpu_get_phys_page_debug(CPU(cpu), addr);
  171. }
  172. static void xtfpga_reset(void *opaque)
  173. {
  174. XtensaCPU *cpu = opaque;
  175. cpu_reset(CPU(cpu));
  176. }
  177. static uint64_t xtfpga_io_read(void *opaque, hwaddr addr,
  178. unsigned size)
  179. {
  180. return 0;
  181. }
  182. static void xtfpga_io_write(void *opaque, hwaddr addr,
  183. uint64_t val, unsigned size)
  184. {
  185. }
  186. static const MemoryRegionOps xtfpga_io_ops = {
  187. .read = xtfpga_io_read,
  188. .write = xtfpga_io_write,
  189. .endianness = DEVICE_NATIVE_ENDIAN,
  190. };
  191. static void xtfpga_init(const XtfpgaBoardDesc *board, MachineState *machine)
  192. {
  193. MemoryRegion *system_memory = get_system_memory();
  194. XtensaCPU *cpu = NULL;
  195. CPUXtensaState *env = NULL;
  196. MemoryRegion *system_io;
  197. XtensaMxPic *mx_pic = NULL;
  198. qemu_irq *extints;
  199. DriveInfo *dinfo;
  200. PFlashCFI01 *flash = NULL;
  201. const char *kernel_filename = machine->kernel_filename;
  202. const char *kernel_cmdline = machine->kernel_cmdline;
  203. const char *dtb_filename = machine->dtb;
  204. const char *initrd_filename = machine->initrd_filename;
  205. const unsigned system_io_size = 224 * MiB;
  206. uint32_t freq = 10000000;
  207. int n;
  208. unsigned int smp_cpus = machine->smp.cpus;
  209. if (smp_cpus > 1) {
  210. mx_pic = xtensa_mx_pic_init(31);
  211. qemu_register_reset(xtensa_mx_pic_reset, mx_pic);
  212. }
  213. for (n = 0; n < smp_cpus; n++) {
  214. CPUXtensaState *cenv = NULL;
  215. cpu = XTENSA_CPU(cpu_create(machine->cpu_type));
  216. cenv = &cpu->env;
  217. if (!env) {
  218. env = cenv;
  219. freq = env->config->clock_freq_khz * 1000;
  220. }
  221. if (mx_pic) {
  222. MemoryRegion *mx_eri;
  223. mx_eri = xtensa_mx_pic_register_cpu(mx_pic,
  224. xtensa_get_extints(cenv),
  225. xtensa_get_runstall(cenv));
  226. memory_region_add_subregion(xtensa_get_er_region(cenv),
  227. 0, mx_eri);
  228. }
  229. cenv->sregs[PRID] = n;
  230. xtensa_select_static_vectors(cenv, n != 0);
  231. qemu_register_reset(xtfpga_reset, cpu);
  232. /* Need MMU initialized prior to ELF loading,
  233. * so that ELF gets loaded into virtual addresses
  234. */
  235. cpu_reset(CPU(cpu));
  236. }
  237. if (smp_cpus > 1) {
  238. extints = xtensa_mx_pic_get_extints(mx_pic);
  239. } else {
  240. extints = xtensa_get_extints(env);
  241. }
  242. if (env) {
  243. XtensaMemory sysram = env->config->sysram;
  244. sysram.location[0].size = machine->ram_size;
  245. xtensa_create_memory_regions(&env->config->instrom, "xtensa.instrom",
  246. system_memory);
  247. xtensa_create_memory_regions(&env->config->instram, "xtensa.instram",
  248. system_memory);
  249. xtensa_create_memory_regions(&env->config->datarom, "xtensa.datarom",
  250. system_memory);
  251. xtensa_create_memory_regions(&env->config->dataram, "xtensa.dataram",
  252. system_memory);
  253. xtensa_create_memory_regions(&sysram, "xtensa.sysram",
  254. system_memory);
  255. }
  256. system_io = g_malloc(sizeof(*system_io));
  257. memory_region_init_io(system_io, NULL, &xtfpga_io_ops, NULL, "xtfpga.io",
  258. system_io_size);
  259. memory_region_add_subregion(system_memory, board->io[0], system_io);
  260. if (board->io[1]) {
  261. MemoryRegion *io = g_malloc(sizeof(*io));
  262. memory_region_init_alias(io, NULL, "xtfpga.io.cached",
  263. system_io, 0, system_io_size);
  264. memory_region_add_subregion(system_memory, board->io[1], io);
  265. }
  266. xtfpga_fpga_init(system_io, 0x0d020000, freq);
  267. xtfpga_net_init(system_io, 0x0d030000, 0x0d030400, 0x0d800000, extints[1]);
  268. serial_mm_init(system_io, 0x0d050020, 2, extints[0],
  269. 115200, serial_hd(0), DEVICE_NATIVE_ENDIAN);
  270. dinfo = drive_get(IF_PFLASH, 0, 0);
  271. if (dinfo) {
  272. flash = xtfpga_flash_init(system_io, board, dinfo, TARGET_BIG_ENDIAN);
  273. }
  274. /* Use presence of kernel file name as 'boot from SRAM' switch. */
  275. if (kernel_filename) {
  276. uint32_t entry_point = env->pc;
  277. size_t bp_size = 3 * get_tag_size(0); /* first/last and memory tags */
  278. uint32_t tagptr = env->config->sysrom.location[0].addr +
  279. board->sram_size;
  280. uint32_t cur_tagptr;
  281. BpMemInfo memory_location = {
  282. .type = tswap32(MEMORY_TYPE_CONVENTIONAL),
  283. .start = tswap32(env->config->sysram.location[0].addr),
  284. .end = tswap32(env->config->sysram.location[0].addr +
  285. machine->ram_size),
  286. };
  287. uint32_t lowmem_end = machine->ram_size < 0x08000000 ?
  288. machine->ram_size : 0x08000000;
  289. uint32_t cur_lowmem = QEMU_ALIGN_UP(lowmem_end / 2, 4096);
  290. lowmem_end += env->config->sysram.location[0].addr;
  291. cur_lowmem += env->config->sysram.location[0].addr;
  292. xtensa_create_memory_regions(&env->config->sysrom, "xtensa.sysrom",
  293. system_memory);
  294. if (kernel_cmdline) {
  295. bp_size += get_tag_size(strlen(kernel_cmdline) + 1);
  296. }
  297. if (dtb_filename) {
  298. bp_size += get_tag_size(sizeof(uint32_t));
  299. }
  300. if (initrd_filename) {
  301. bp_size += get_tag_size(sizeof(BpMemInfo));
  302. }
  303. /* Put kernel bootparameters to the end of that SRAM */
  304. tagptr = (tagptr - bp_size) & ~0xff;
  305. cur_tagptr = put_tag(tagptr, BP_TAG_FIRST, 0, NULL);
  306. cur_tagptr = put_tag(cur_tagptr, BP_TAG_MEMORY,
  307. sizeof(memory_location), &memory_location);
  308. if (kernel_cmdline) {
  309. cur_tagptr = put_tag(cur_tagptr, BP_TAG_COMMAND_LINE,
  310. strlen(kernel_cmdline) + 1, kernel_cmdline);
  311. }
  312. if (dtb_filename) {
  313. int fdt_size;
  314. void *fdt = load_device_tree(dtb_filename, &fdt_size);
  315. uint32_t dtb_addr = tswap32(cur_lowmem);
  316. if (!fdt) {
  317. error_report("could not load DTB '%s'", dtb_filename);
  318. exit(EXIT_FAILURE);
  319. }
  320. cpu_physical_memory_write(cur_lowmem, fdt, fdt_size);
  321. cur_tagptr = put_tag(cur_tagptr, BP_TAG_FDT,
  322. sizeof(dtb_addr), &dtb_addr);
  323. cur_lowmem = QEMU_ALIGN_UP(cur_lowmem + fdt_size, 4 * KiB);
  324. g_free(fdt);
  325. }
  326. if (initrd_filename) {
  327. BpMemInfo initrd_location = { 0 };
  328. int initrd_size = load_ramdisk(initrd_filename, cur_lowmem,
  329. lowmem_end - cur_lowmem);
  330. if (initrd_size < 0) {
  331. initrd_size = load_image_targphys(initrd_filename,
  332. cur_lowmem,
  333. lowmem_end - cur_lowmem);
  334. }
  335. if (initrd_size < 0) {
  336. error_report("could not load initrd '%s'", initrd_filename);
  337. exit(EXIT_FAILURE);
  338. }
  339. initrd_location.start = tswap32(cur_lowmem);
  340. initrd_location.end = tswap32(cur_lowmem + initrd_size);
  341. cur_tagptr = put_tag(cur_tagptr, BP_TAG_INITRD,
  342. sizeof(initrd_location), &initrd_location);
  343. cur_lowmem = QEMU_ALIGN_UP(cur_lowmem + initrd_size, 4 * KiB);
  344. }
  345. cur_tagptr = put_tag(cur_tagptr, BP_TAG_LAST, 0, NULL);
  346. env->regs[2] = tagptr;
  347. uint64_t elf_entry;
  348. int success = load_elf(kernel_filename, NULL, translate_phys_addr, cpu,
  349. &elf_entry, NULL, NULL, NULL, TARGET_BIG_ENDIAN,
  350. EM_XTENSA, 0, 0);
  351. if (success > 0) {
  352. entry_point = elf_entry;
  353. } else {
  354. hwaddr ep;
  355. int is_linux;
  356. success = load_uimage(kernel_filename, &ep, NULL, &is_linux,
  357. translate_phys_addr, cpu);
  358. if (success > 0 && is_linux) {
  359. entry_point = ep;
  360. } else {
  361. error_report("could not load kernel '%s'",
  362. kernel_filename);
  363. exit(EXIT_FAILURE);
  364. }
  365. }
  366. if (entry_point != env->pc) {
  367. uint8_t boot[] = {
  368. #if TARGET_BIG_ENDIAN
  369. 0x60, 0x00, 0x08, /* j 1f */
  370. 0x00, /* .literal_position */
  371. 0x00, 0x00, 0x00, 0x00, /* .literal entry_pc */
  372. 0x00, 0x00, 0x00, 0x00, /* .literal entry_a2 */
  373. /* 1: */
  374. 0x10, 0xff, 0xfe, /* l32r a0, entry_pc */
  375. 0x12, 0xff, 0xfe, /* l32r a2, entry_a2 */
  376. 0x0a, 0x00, 0x00, /* jx a0 */
  377. #else
  378. 0x06, 0x02, 0x00, /* j 1f */
  379. 0x00, /* .literal_position */
  380. 0x00, 0x00, 0x00, 0x00, /* .literal entry_pc */
  381. 0x00, 0x00, 0x00, 0x00, /* .literal entry_a2 */
  382. /* 1: */
  383. 0x01, 0xfe, 0xff, /* l32r a0, entry_pc */
  384. 0x21, 0xfe, 0xff, /* l32r a2, entry_a2 */
  385. 0xa0, 0x00, 0x00, /* jx a0 */
  386. #endif
  387. };
  388. uint32_t entry_pc = tswap32(entry_point);
  389. uint32_t entry_a2 = tswap32(tagptr);
  390. memcpy(boot + 4, &entry_pc, sizeof(entry_pc));
  391. memcpy(boot + 8, &entry_a2, sizeof(entry_a2));
  392. cpu_physical_memory_write(env->pc, boot, sizeof(boot));
  393. }
  394. } else {
  395. if (flash) {
  396. MemoryRegion *flash_mr = pflash_cfi01_get_memory(flash);
  397. MemoryRegion *flash_io = g_malloc(sizeof(*flash_io));
  398. uint32_t size = env->config->sysrom.location[0].size;
  399. if (board->flash->size - board->flash->boot_base < size) {
  400. size = board->flash->size - board->flash->boot_base;
  401. }
  402. memory_region_init_alias(flash_io, NULL, "xtfpga.flash",
  403. flash_mr, board->flash->boot_base, size);
  404. memory_region_add_subregion(system_memory,
  405. env->config->sysrom.location[0].addr,
  406. flash_io);
  407. } else {
  408. xtensa_create_memory_regions(&env->config->sysrom, "xtensa.sysrom",
  409. system_memory);
  410. }
  411. }
  412. }
  413. #define XTFPGA_MMU_RESERVED_MEMORY_SIZE (128 * MiB)
  414. static const hwaddr xtfpga_mmu_io[2] = {
  415. 0xf0000000,
  416. };
  417. static const hwaddr xtfpga_nommu_io[2] = {
  418. 0x90000000,
  419. 0x70000000,
  420. };
  421. static const XtfpgaFlashDesc lx60_flash = {
  422. .base = 0x08000000,
  423. .size = 0x00400000,
  424. .sector_size = 0x10000,
  425. };
  426. static void xtfpga_lx60_init(MachineState *machine)
  427. {
  428. static const XtfpgaBoardDesc lx60_board = {
  429. .flash = &lx60_flash,
  430. .sram_size = 0x20000,
  431. .io = xtfpga_mmu_io,
  432. };
  433. xtfpga_init(&lx60_board, machine);
  434. }
  435. static void xtfpga_lx60_nommu_init(MachineState *machine)
  436. {
  437. static const XtfpgaBoardDesc lx60_board = {
  438. .flash = &lx60_flash,
  439. .sram_size = 0x20000,
  440. .io = xtfpga_nommu_io,
  441. };
  442. xtfpga_init(&lx60_board, machine);
  443. }
  444. static const XtfpgaFlashDesc lx200_flash = {
  445. .base = 0x08000000,
  446. .size = 0x01000000,
  447. .sector_size = 0x20000,
  448. };
  449. static void xtfpga_lx200_init(MachineState *machine)
  450. {
  451. static const XtfpgaBoardDesc lx200_board = {
  452. .flash = &lx200_flash,
  453. .sram_size = 0x2000000,
  454. .io = xtfpga_mmu_io,
  455. };
  456. xtfpga_init(&lx200_board, machine);
  457. }
  458. static void xtfpga_lx200_nommu_init(MachineState *machine)
  459. {
  460. static const XtfpgaBoardDesc lx200_board = {
  461. .flash = &lx200_flash,
  462. .sram_size = 0x2000000,
  463. .io = xtfpga_nommu_io,
  464. };
  465. xtfpga_init(&lx200_board, machine);
  466. }
  467. static const XtfpgaFlashDesc ml605_flash = {
  468. .base = 0x08000000,
  469. .size = 0x01000000,
  470. .sector_size = 0x20000,
  471. };
  472. static void xtfpga_ml605_init(MachineState *machine)
  473. {
  474. static const XtfpgaBoardDesc ml605_board = {
  475. .flash = &ml605_flash,
  476. .sram_size = 0x2000000,
  477. .io = xtfpga_mmu_io,
  478. };
  479. xtfpga_init(&ml605_board, machine);
  480. }
  481. static void xtfpga_ml605_nommu_init(MachineState *machine)
  482. {
  483. static const XtfpgaBoardDesc ml605_board = {
  484. .flash = &ml605_flash,
  485. .sram_size = 0x2000000,
  486. .io = xtfpga_nommu_io,
  487. };
  488. xtfpga_init(&ml605_board, machine);
  489. }
  490. static const XtfpgaFlashDesc kc705_flash = {
  491. .base = 0x00000000,
  492. .size = 0x08000000,
  493. .boot_base = 0x06000000,
  494. .sector_size = 0x20000,
  495. };
  496. static void xtfpga_kc705_init(MachineState *machine)
  497. {
  498. static const XtfpgaBoardDesc kc705_board = {
  499. .flash = &kc705_flash,
  500. .sram_size = 0x2000000,
  501. .io = xtfpga_mmu_io,
  502. };
  503. xtfpga_init(&kc705_board, machine);
  504. }
  505. static void xtfpga_kc705_nommu_init(MachineState *machine)
  506. {
  507. static const XtfpgaBoardDesc kc705_board = {
  508. .flash = &kc705_flash,
  509. .sram_size = 0x2000000,
  510. .io = xtfpga_nommu_io,
  511. };
  512. xtfpga_init(&kc705_board, machine);
  513. }
  514. static void xtfpga_lx60_class_init(ObjectClass *oc, void *data)
  515. {
  516. MachineClass *mc = MACHINE_CLASS(oc);
  517. mc->desc = "lx60 EVB (" XTENSA_DEFAULT_CPU_MODEL ")";
  518. mc->init = xtfpga_lx60_init;
  519. mc->max_cpus = 32;
  520. mc->default_cpu_type = XTENSA_DEFAULT_CPU_TYPE;
  521. mc->default_ram_size = 64 * MiB;
  522. }
  523. static const TypeInfo xtfpga_lx60_type = {
  524. .name = MACHINE_TYPE_NAME("lx60"),
  525. .parent = TYPE_MACHINE,
  526. .class_init = xtfpga_lx60_class_init,
  527. };
  528. static void xtfpga_lx60_nommu_class_init(ObjectClass *oc, void *data)
  529. {
  530. MachineClass *mc = MACHINE_CLASS(oc);
  531. mc->desc = "lx60 noMMU EVB (" XTENSA_DEFAULT_CPU_NOMMU_MODEL ")";
  532. mc->init = xtfpga_lx60_nommu_init;
  533. mc->max_cpus = 32;
  534. mc->default_cpu_type = XTENSA_DEFAULT_CPU_NOMMU_TYPE;
  535. mc->default_ram_size = 64 * MiB;
  536. }
  537. static const TypeInfo xtfpga_lx60_nommu_type = {
  538. .name = MACHINE_TYPE_NAME("lx60-nommu"),
  539. .parent = TYPE_MACHINE,
  540. .class_init = xtfpga_lx60_nommu_class_init,
  541. };
  542. static void xtfpga_lx200_class_init(ObjectClass *oc, void *data)
  543. {
  544. MachineClass *mc = MACHINE_CLASS(oc);
  545. mc->desc = "lx200 EVB (" XTENSA_DEFAULT_CPU_MODEL ")";
  546. mc->init = xtfpga_lx200_init;
  547. mc->max_cpus = 32;
  548. mc->default_cpu_type = XTENSA_DEFAULT_CPU_TYPE;
  549. mc->default_ram_size = 96 * MiB;
  550. }
  551. static const TypeInfo xtfpga_lx200_type = {
  552. .name = MACHINE_TYPE_NAME("lx200"),
  553. .parent = TYPE_MACHINE,
  554. .class_init = xtfpga_lx200_class_init,
  555. };
  556. static void xtfpga_lx200_nommu_class_init(ObjectClass *oc, void *data)
  557. {
  558. MachineClass *mc = MACHINE_CLASS(oc);
  559. mc->desc = "lx200 noMMU EVB (" XTENSA_DEFAULT_CPU_NOMMU_MODEL ")";
  560. mc->init = xtfpga_lx200_nommu_init;
  561. mc->max_cpus = 32;
  562. mc->default_cpu_type = XTENSA_DEFAULT_CPU_NOMMU_TYPE;
  563. mc->default_ram_size = 96 * MiB;
  564. }
  565. static const TypeInfo xtfpga_lx200_nommu_type = {
  566. .name = MACHINE_TYPE_NAME("lx200-nommu"),
  567. .parent = TYPE_MACHINE,
  568. .class_init = xtfpga_lx200_nommu_class_init,
  569. };
  570. static void xtfpga_ml605_class_init(ObjectClass *oc, void *data)
  571. {
  572. MachineClass *mc = MACHINE_CLASS(oc);
  573. mc->desc = "ml605 EVB (" XTENSA_DEFAULT_CPU_MODEL ")";
  574. mc->init = xtfpga_ml605_init;
  575. mc->max_cpus = 32;
  576. mc->default_cpu_type = XTENSA_DEFAULT_CPU_TYPE;
  577. mc->default_ram_size = 512 * MiB - XTFPGA_MMU_RESERVED_MEMORY_SIZE;
  578. }
  579. static const TypeInfo xtfpga_ml605_type = {
  580. .name = MACHINE_TYPE_NAME("ml605"),
  581. .parent = TYPE_MACHINE,
  582. .class_init = xtfpga_ml605_class_init,
  583. };
  584. static void xtfpga_ml605_nommu_class_init(ObjectClass *oc, void *data)
  585. {
  586. MachineClass *mc = MACHINE_CLASS(oc);
  587. mc->desc = "ml605 noMMU EVB (" XTENSA_DEFAULT_CPU_NOMMU_MODEL ")";
  588. mc->init = xtfpga_ml605_nommu_init;
  589. mc->max_cpus = 32;
  590. mc->default_cpu_type = XTENSA_DEFAULT_CPU_NOMMU_TYPE;
  591. mc->default_ram_size = 256 * MiB;
  592. }
  593. static const TypeInfo xtfpga_ml605_nommu_type = {
  594. .name = MACHINE_TYPE_NAME("ml605-nommu"),
  595. .parent = TYPE_MACHINE,
  596. .class_init = xtfpga_ml605_nommu_class_init,
  597. };
  598. static void xtfpga_kc705_class_init(ObjectClass *oc, void *data)
  599. {
  600. MachineClass *mc = MACHINE_CLASS(oc);
  601. mc->desc = "kc705 EVB (" XTENSA_DEFAULT_CPU_MODEL ")";
  602. mc->init = xtfpga_kc705_init;
  603. mc->max_cpus = 32;
  604. mc->default_cpu_type = XTENSA_DEFAULT_CPU_TYPE;
  605. mc->default_ram_size = 1 * GiB - XTFPGA_MMU_RESERVED_MEMORY_SIZE;
  606. }
  607. static const TypeInfo xtfpga_kc705_type = {
  608. .name = MACHINE_TYPE_NAME("kc705"),
  609. .parent = TYPE_MACHINE,
  610. .class_init = xtfpga_kc705_class_init,
  611. };
  612. static void xtfpga_kc705_nommu_class_init(ObjectClass *oc, void *data)
  613. {
  614. MachineClass *mc = MACHINE_CLASS(oc);
  615. mc->desc = "kc705 noMMU EVB (" XTENSA_DEFAULT_CPU_NOMMU_MODEL ")";
  616. mc->init = xtfpga_kc705_nommu_init;
  617. mc->max_cpus = 32;
  618. mc->default_cpu_type = XTENSA_DEFAULT_CPU_NOMMU_TYPE;
  619. mc->default_ram_size = 256 * MiB;
  620. }
  621. static const TypeInfo xtfpga_kc705_nommu_type = {
  622. .name = MACHINE_TYPE_NAME("kc705-nommu"),
  623. .parent = TYPE_MACHINE,
  624. .class_init = xtfpga_kc705_nommu_class_init,
  625. };
  626. static void xtfpga_machines_init(void)
  627. {
  628. type_register_static(&xtfpga_lx60_type);
  629. type_register_static(&xtfpga_lx200_type);
  630. type_register_static(&xtfpga_ml605_type);
  631. type_register_static(&xtfpga_kc705_type);
  632. type_register_static(&xtfpga_lx60_nommu_type);
  633. type_register_static(&xtfpga_lx200_nommu_type);
  634. type_register_static(&xtfpga_ml605_nommu_type);
  635. type_register_static(&xtfpga_kc705_nommu_type);
  636. }
  637. type_init(xtfpga_machines_init)