vexpress.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. /*
  2. * ARM Versatile Express emulation.
  3. *
  4. * Copyright (c) 2010 - 2011 B Labs Ltd.
  5. * Copyright (c) 2011 Linaro Limited
  6. * Written by Bahadir Balban, Amit Mahajan, Peter Maydell
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program; if not, see <http://www.gnu.org/licenses/>.
  19. *
  20. * Contributions after 2012-01-13 are licensed under the terms of the
  21. * GNU GPL, version 2 or (at your option) any later version.
  22. */
  23. #include "sysbus.h"
  24. #include "arm-misc.h"
  25. #include "primecell.h"
  26. #include "devices.h"
  27. #include "net.h"
  28. #include "sysemu.h"
  29. #include "boards.h"
  30. #include "exec-memory.h"
  31. #define VEXPRESS_BOARD_ID 0x8e0
  32. static struct arm_boot_info vexpress_binfo;
  33. /* Address maps for peripherals:
  34. * the Versatile Express motherboard has two possible maps,
  35. * the "legacy" one (used for A9) and the "Cortex-A Series"
  36. * map (used for newer cores).
  37. * Individual daughterboards can also have different maps for
  38. * their peripherals.
  39. */
  40. enum {
  41. VE_SYSREGS,
  42. VE_SP810,
  43. VE_SERIALPCI,
  44. VE_PL041,
  45. VE_MMCI,
  46. VE_KMI0,
  47. VE_KMI1,
  48. VE_UART0,
  49. VE_UART1,
  50. VE_UART2,
  51. VE_UART3,
  52. VE_WDT,
  53. VE_TIMER01,
  54. VE_TIMER23,
  55. VE_SERIALDVI,
  56. VE_RTC,
  57. VE_COMPACTFLASH,
  58. VE_CLCD,
  59. VE_NORFLASH0,
  60. VE_NORFLASH1,
  61. VE_SRAM,
  62. VE_VIDEORAM,
  63. VE_ETHERNET,
  64. VE_USB,
  65. VE_DAPROM,
  66. };
  67. static target_phys_addr_t motherboard_legacy_map[] = {
  68. /* CS7: 0x10000000 .. 0x10020000 */
  69. [VE_SYSREGS] = 0x10000000,
  70. [VE_SP810] = 0x10001000,
  71. [VE_SERIALPCI] = 0x10002000,
  72. [VE_PL041] = 0x10004000,
  73. [VE_MMCI] = 0x10005000,
  74. [VE_KMI0] = 0x10006000,
  75. [VE_KMI1] = 0x10007000,
  76. [VE_UART0] = 0x10009000,
  77. [VE_UART1] = 0x1000a000,
  78. [VE_UART2] = 0x1000b000,
  79. [VE_UART3] = 0x1000c000,
  80. [VE_WDT] = 0x1000f000,
  81. [VE_TIMER01] = 0x10011000,
  82. [VE_TIMER23] = 0x10012000,
  83. [VE_SERIALDVI] = 0x10016000,
  84. [VE_RTC] = 0x10017000,
  85. [VE_COMPACTFLASH] = 0x1001a000,
  86. [VE_CLCD] = 0x1001f000,
  87. /* CS0: 0x40000000 .. 0x44000000 */
  88. [VE_NORFLASH0] = 0x40000000,
  89. /* CS1: 0x44000000 .. 0x48000000 */
  90. [VE_NORFLASH1] = 0x44000000,
  91. /* CS2: 0x48000000 .. 0x4a000000 */
  92. [VE_SRAM] = 0x48000000,
  93. /* CS3: 0x4c000000 .. 0x50000000 */
  94. [VE_VIDEORAM] = 0x4c000000,
  95. [VE_ETHERNET] = 0x4e000000,
  96. [VE_USB] = 0x4f000000,
  97. };
  98. static target_phys_addr_t motherboard_aseries_map[] = {
  99. /* CS0: 0x08000000 .. 0x0c000000 */
  100. [VE_NORFLASH0] = 0x08000000,
  101. /* CS4: 0x0c000000 .. 0x10000000 */
  102. [VE_NORFLASH1] = 0x0c000000,
  103. /* CS5: 0x10000000 .. 0x14000000 */
  104. /* CS1: 0x14000000 .. 0x18000000 */
  105. [VE_SRAM] = 0x14000000,
  106. /* CS2: 0x18000000 .. 0x1c000000 */
  107. [VE_VIDEORAM] = 0x18000000,
  108. [VE_ETHERNET] = 0x1a000000,
  109. [VE_USB] = 0x1b000000,
  110. /* CS3: 0x1c000000 .. 0x20000000 */
  111. [VE_DAPROM] = 0x1c000000,
  112. [VE_SYSREGS] = 0x1c010000,
  113. [VE_SP810] = 0x1c020000,
  114. [VE_SERIALPCI] = 0x1c030000,
  115. [VE_PL041] = 0x1c040000,
  116. [VE_MMCI] = 0x1c050000,
  117. [VE_KMI0] = 0x1c060000,
  118. [VE_KMI1] = 0x1c070000,
  119. [VE_UART0] = 0x1c090000,
  120. [VE_UART1] = 0x1c0a0000,
  121. [VE_UART2] = 0x1c0b0000,
  122. [VE_UART3] = 0x1c0c0000,
  123. [VE_WDT] = 0x1c0f0000,
  124. [VE_TIMER01] = 0x1c110000,
  125. [VE_TIMER23] = 0x1c120000,
  126. [VE_SERIALDVI] = 0x1c160000,
  127. [VE_RTC] = 0x1c170000,
  128. [VE_COMPACTFLASH] = 0x1c1a0000,
  129. [VE_CLCD] = 0x1c1f0000,
  130. };
  131. /* Structure defining the peculiarities of a specific daughterboard */
  132. typedef struct VEDBoardInfo VEDBoardInfo;
  133. typedef void DBoardInitFn(const VEDBoardInfo *daughterboard,
  134. ram_addr_t ram_size,
  135. const char *cpu_model,
  136. qemu_irq *pic, uint32_t *proc_id);
  137. struct VEDBoardInfo {
  138. const target_phys_addr_t *motherboard_map;
  139. target_phys_addr_t loader_start;
  140. const target_phys_addr_t gic_cpu_if_addr;
  141. DBoardInitFn *init;
  142. };
  143. static void a9_daughterboard_init(const VEDBoardInfo *daughterboard,
  144. ram_addr_t ram_size,
  145. const char *cpu_model,
  146. qemu_irq *pic, uint32_t *proc_id)
  147. {
  148. MemoryRegion *sysmem = get_system_memory();
  149. MemoryRegion *ram = g_new(MemoryRegion, 1);
  150. MemoryRegion *lowram = g_new(MemoryRegion, 1);
  151. DeviceState *dev;
  152. SysBusDevice *busdev;
  153. qemu_irq *irqp;
  154. int n;
  155. qemu_irq cpu_irq[4];
  156. ram_addr_t low_ram_size;
  157. if (!cpu_model) {
  158. cpu_model = "cortex-a9";
  159. }
  160. *proc_id = 0x0c000191;
  161. for (n = 0; n < smp_cpus; n++) {
  162. ARMCPU *cpu = cpu_arm_init(cpu_model);
  163. if (!cpu) {
  164. fprintf(stderr, "Unable to find CPU definition\n");
  165. exit(1);
  166. }
  167. irqp = arm_pic_init_cpu(cpu);
  168. cpu_irq[n] = irqp[ARM_PIC_CPU_IRQ];
  169. }
  170. if (ram_size > 0x40000000) {
  171. /* 1GB is the maximum the address space permits */
  172. fprintf(stderr, "vexpress-a9: cannot model more than 1GB RAM\n");
  173. exit(1);
  174. }
  175. memory_region_init_ram(ram, "vexpress.highmem", ram_size);
  176. vmstate_register_ram_global(ram);
  177. low_ram_size = ram_size;
  178. if (low_ram_size > 0x4000000) {
  179. low_ram_size = 0x4000000;
  180. }
  181. /* RAM is from 0x60000000 upwards. The bottom 64MB of the
  182. * address space should in theory be remappable to various
  183. * things including ROM or RAM; we always map the RAM there.
  184. */
  185. memory_region_init_alias(lowram, "vexpress.lowmem", ram, 0, low_ram_size);
  186. memory_region_add_subregion(sysmem, 0x0, lowram);
  187. memory_region_add_subregion(sysmem, 0x60000000, ram);
  188. /* 0x1e000000 A9MPCore (SCU) private memory region */
  189. dev = qdev_create(NULL, "a9mpcore_priv");
  190. qdev_prop_set_uint32(dev, "num-cpu", smp_cpus);
  191. qdev_init_nofail(dev);
  192. busdev = sysbus_from_qdev(dev);
  193. sysbus_mmio_map(busdev, 0, 0x1e000000);
  194. for (n = 0; n < smp_cpus; n++) {
  195. sysbus_connect_irq(busdev, n, cpu_irq[n]);
  196. }
  197. /* Interrupts [42:0] are from the motherboard;
  198. * [47:43] are reserved; [63:48] are daughterboard
  199. * peripherals. Note that some documentation numbers
  200. * external interrupts starting from 32 (because the
  201. * A9MP has internal interrupts 0..31).
  202. */
  203. for (n = 0; n < 64; n++) {
  204. pic[n] = qdev_get_gpio_in(dev, n);
  205. }
  206. /* Daughterboard peripherals : 0x10020000 .. 0x20000000 */
  207. /* 0x10020000 PL111 CLCD (daughterboard) */
  208. sysbus_create_simple("pl111", 0x10020000, pic[44]);
  209. /* 0x10060000 AXI RAM */
  210. /* 0x100e0000 PL341 Dynamic Memory Controller */
  211. /* 0x100e1000 PL354 Static Memory Controller */
  212. /* 0x100e2000 System Configuration Controller */
  213. sysbus_create_simple("sp804", 0x100e4000, pic[48]);
  214. /* 0x100e5000 SP805 Watchdog module */
  215. /* 0x100e6000 BP147 TrustZone Protection Controller */
  216. /* 0x100e9000 PL301 'Fast' AXI matrix */
  217. /* 0x100ea000 PL301 'Slow' AXI matrix */
  218. /* 0x100ec000 TrustZone Address Space Controller */
  219. /* 0x10200000 CoreSight debug APB */
  220. /* 0x1e00a000 PL310 L2 Cache Controller */
  221. sysbus_create_varargs("l2x0", 0x1e00a000, NULL);
  222. }
  223. static const VEDBoardInfo a9_daughterboard = {
  224. .motherboard_map = motherboard_legacy_map,
  225. .loader_start = 0x60000000,
  226. .gic_cpu_if_addr = 0x1e000100,
  227. .init = a9_daughterboard_init,
  228. };
  229. static void a15_daughterboard_init(const VEDBoardInfo *daughterboard,
  230. ram_addr_t ram_size,
  231. const char *cpu_model,
  232. qemu_irq *pic, uint32_t *proc_id)
  233. {
  234. int n;
  235. MemoryRegion *sysmem = get_system_memory();
  236. MemoryRegion *ram = g_new(MemoryRegion, 1);
  237. MemoryRegion *sram = g_new(MemoryRegion, 1);
  238. qemu_irq cpu_irq[4];
  239. DeviceState *dev;
  240. SysBusDevice *busdev;
  241. if (!cpu_model) {
  242. cpu_model = "cortex-a15";
  243. }
  244. *proc_id = 0x14000217;
  245. for (n = 0; n < smp_cpus; n++) {
  246. ARMCPU *cpu;
  247. qemu_irq *irqp;
  248. cpu = cpu_arm_init(cpu_model);
  249. if (!cpu) {
  250. fprintf(stderr, "Unable to find CPU definition\n");
  251. exit(1);
  252. }
  253. irqp = arm_pic_init_cpu(cpu);
  254. cpu_irq[n] = irqp[ARM_PIC_CPU_IRQ];
  255. }
  256. {
  257. /* We have to use a separate 64 bit variable here to avoid the gcc
  258. * "comparison is always false due to limited range of data type"
  259. * warning if we are on a host where ram_addr_t is 32 bits.
  260. */
  261. uint64_t rsz = ram_size;
  262. if (rsz > (30ULL * 1024 * 1024 * 1024)) {
  263. fprintf(stderr, "vexpress-a15: cannot model more than 30GB RAM\n");
  264. exit(1);
  265. }
  266. }
  267. memory_region_init_ram(ram, "vexpress.highmem", ram_size);
  268. vmstate_register_ram_global(ram);
  269. /* RAM is from 0x80000000 upwards; there is no low-memory alias for it. */
  270. memory_region_add_subregion(sysmem, 0x80000000, ram);
  271. /* 0x2c000000 A15MPCore private memory region (GIC) */
  272. dev = qdev_create(NULL, "a15mpcore_priv");
  273. qdev_prop_set_uint32(dev, "num-cpu", smp_cpus);
  274. qdev_init_nofail(dev);
  275. busdev = sysbus_from_qdev(dev);
  276. sysbus_mmio_map(busdev, 0, 0x2c000000);
  277. for (n = 0; n < smp_cpus; n++) {
  278. sysbus_connect_irq(busdev, n, cpu_irq[n]);
  279. }
  280. /* Interrupts [42:0] are from the motherboard;
  281. * [47:43] are reserved; [63:48] are daughterboard
  282. * peripherals. Note that some documentation numbers
  283. * external interrupts starting from 32 (because there
  284. * are internal interrupts 0..31).
  285. */
  286. for (n = 0; n < 64; n++) {
  287. pic[n] = qdev_get_gpio_in(dev, n);
  288. }
  289. /* A15 daughterboard peripherals: */
  290. /* 0x20000000: CoreSight interfaces: not modelled */
  291. /* 0x2a000000: PL301 AXI interconnect: not modelled */
  292. /* 0x2a420000: SCC: not modelled */
  293. /* 0x2a430000: system counter: not modelled */
  294. /* 0x2b000000: HDLCD controller: not modelled */
  295. /* 0x2b060000: SP805 watchdog: not modelled */
  296. /* 0x2b0a0000: PL341 dynamic memory controller: not modelled */
  297. /* 0x2e000000: system SRAM */
  298. memory_region_init_ram(sram, "vexpress.a15sram", 0x10000);
  299. vmstate_register_ram_global(sram);
  300. memory_region_add_subregion(sysmem, 0x2e000000, sram);
  301. /* 0x7ffb0000: DMA330 DMA controller: not modelled */
  302. /* 0x7ffd0000: PL354 static memory controller: not modelled */
  303. }
  304. static const VEDBoardInfo a15_daughterboard = {
  305. .motherboard_map = motherboard_aseries_map,
  306. .loader_start = 0x80000000,
  307. .gic_cpu_if_addr = 0x2c002000,
  308. .init = a15_daughterboard_init,
  309. };
  310. static void vexpress_common_init(const VEDBoardInfo *daughterboard,
  311. ram_addr_t ram_size,
  312. const char *boot_device,
  313. const char *kernel_filename,
  314. const char *kernel_cmdline,
  315. const char *initrd_filename,
  316. const char *cpu_model)
  317. {
  318. DeviceState *dev, *sysctl, *pl041;
  319. qemu_irq pic[64];
  320. uint32_t proc_id;
  321. uint32_t sys_id;
  322. ram_addr_t vram_size, sram_size;
  323. MemoryRegion *sysmem = get_system_memory();
  324. MemoryRegion *vram = g_new(MemoryRegion, 1);
  325. MemoryRegion *sram = g_new(MemoryRegion, 1);
  326. const target_phys_addr_t *map = daughterboard->motherboard_map;
  327. daughterboard->init(daughterboard, ram_size, cpu_model, pic, &proc_id);
  328. /* Motherboard peripherals: the wiring is the same but the
  329. * addresses vary between the legacy and A-Series memory maps.
  330. */
  331. sys_id = 0x1190f500;
  332. sysctl = qdev_create(NULL, "realview_sysctl");
  333. qdev_prop_set_uint32(sysctl, "sys_id", sys_id);
  334. qdev_prop_set_uint32(sysctl, "proc_id", proc_id);
  335. qdev_init_nofail(sysctl);
  336. sysbus_mmio_map(sysbus_from_qdev(sysctl), 0, map[VE_SYSREGS]);
  337. /* VE_SP810: not modelled */
  338. /* VE_SERIALPCI: not modelled */
  339. pl041 = qdev_create(NULL, "pl041");
  340. qdev_prop_set_uint32(pl041, "nc_fifo_depth", 512);
  341. qdev_init_nofail(pl041);
  342. sysbus_mmio_map(sysbus_from_qdev(pl041), 0, map[VE_PL041]);
  343. sysbus_connect_irq(sysbus_from_qdev(pl041), 0, pic[11]);
  344. dev = sysbus_create_varargs("pl181", map[VE_MMCI], pic[9], pic[10], NULL);
  345. /* Wire up MMC card detect and read-only signals */
  346. qdev_connect_gpio_out(dev, 0,
  347. qdev_get_gpio_in(sysctl, ARM_SYSCTL_GPIO_MMC_WPROT));
  348. qdev_connect_gpio_out(dev, 1,
  349. qdev_get_gpio_in(sysctl, ARM_SYSCTL_GPIO_MMC_CARDIN));
  350. sysbus_create_simple("pl050_keyboard", map[VE_KMI0], pic[12]);
  351. sysbus_create_simple("pl050_mouse", map[VE_KMI1], pic[13]);
  352. sysbus_create_simple("pl011", map[VE_UART0], pic[5]);
  353. sysbus_create_simple("pl011", map[VE_UART1], pic[6]);
  354. sysbus_create_simple("pl011", map[VE_UART2], pic[7]);
  355. sysbus_create_simple("pl011", map[VE_UART3], pic[8]);
  356. sysbus_create_simple("sp804", map[VE_TIMER01], pic[2]);
  357. sysbus_create_simple("sp804", map[VE_TIMER23], pic[3]);
  358. /* VE_SERIALDVI: not modelled */
  359. sysbus_create_simple("pl031", map[VE_RTC], pic[4]); /* RTC */
  360. /* VE_COMPACTFLASH: not modelled */
  361. sysbus_create_simple("pl111", map[VE_CLCD], pic[14]);
  362. /* VE_NORFLASH0: not modelled */
  363. /* VE_NORFLASH1: not modelled */
  364. sram_size = 0x2000000;
  365. memory_region_init_ram(sram, "vexpress.sram", sram_size);
  366. vmstate_register_ram_global(sram);
  367. memory_region_add_subregion(sysmem, map[VE_SRAM], sram);
  368. vram_size = 0x800000;
  369. memory_region_init_ram(vram, "vexpress.vram", vram_size);
  370. vmstate_register_ram_global(vram);
  371. memory_region_add_subregion(sysmem, map[VE_VIDEORAM], vram);
  372. /* 0x4e000000 LAN9118 Ethernet */
  373. if (nd_table[0].used) {
  374. lan9118_init(&nd_table[0], map[VE_ETHERNET], pic[15]);
  375. }
  376. /* VE_USB: not modelled */
  377. /* VE_DAPROM: not modelled */
  378. vexpress_binfo.ram_size = ram_size;
  379. vexpress_binfo.kernel_filename = kernel_filename;
  380. vexpress_binfo.kernel_cmdline = kernel_cmdline;
  381. vexpress_binfo.initrd_filename = initrd_filename;
  382. vexpress_binfo.nb_cpus = smp_cpus;
  383. vexpress_binfo.board_id = VEXPRESS_BOARD_ID;
  384. vexpress_binfo.loader_start = daughterboard->loader_start;
  385. vexpress_binfo.smp_loader_start = map[VE_SRAM];
  386. vexpress_binfo.smp_bootreg_addr = map[VE_SYSREGS] + 0x30;
  387. vexpress_binfo.gic_cpu_if_addr = daughterboard->gic_cpu_if_addr;
  388. arm_load_kernel(arm_env_get_cpu(first_cpu), &vexpress_binfo);
  389. }
  390. static void vexpress_a9_init(ram_addr_t ram_size,
  391. const char *boot_device,
  392. const char *kernel_filename,
  393. const char *kernel_cmdline,
  394. const char *initrd_filename,
  395. const char *cpu_model)
  396. {
  397. vexpress_common_init(&a9_daughterboard,
  398. ram_size, boot_device, kernel_filename,
  399. kernel_cmdline, initrd_filename, cpu_model);
  400. }
  401. static void vexpress_a15_init(ram_addr_t ram_size,
  402. const char *boot_device,
  403. const char *kernel_filename,
  404. const char *kernel_cmdline,
  405. const char *initrd_filename,
  406. const char *cpu_model)
  407. {
  408. vexpress_common_init(&a15_daughterboard,
  409. ram_size, boot_device, kernel_filename,
  410. kernel_cmdline, initrd_filename, cpu_model);
  411. }
  412. static QEMUMachine vexpress_a9_machine = {
  413. .name = "vexpress-a9",
  414. .desc = "ARM Versatile Express for Cortex-A9",
  415. .init = vexpress_a9_init,
  416. .use_scsi = 1,
  417. .max_cpus = 4,
  418. };
  419. static QEMUMachine vexpress_a15_machine = {
  420. .name = "vexpress-a15",
  421. .desc = "ARM Versatile Express for Cortex-A15",
  422. .init = vexpress_a15_init,
  423. .use_scsi = 1,
  424. .max_cpus = 4,
  425. };
  426. static void vexpress_machine_init(void)
  427. {
  428. qemu_register_machine(&vexpress_a9_machine);
  429. qemu_register_machine(&vexpress_a15_machine);
  430. }
  431. machine_init(vexpress_machine_init);