musca.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. /*
  2. * Arm Musca-B1 test chip board emulation
  3. *
  4. * Copyright (c) 2019 Linaro Limited
  5. * Written by Peter Maydell
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 or
  9. * (at your option) any later version.
  10. */
  11. /*
  12. * The Musca boards are a reference implementation of a system using
  13. * the SSE-200 subsystem for embedded:
  14. * https://developer.arm.com/products/system-design/development-boards/iot-test-chips-and-boards/musca-a-test-chip-board
  15. * https://developer.arm.com/products/system-design/development-boards/iot-test-chips-and-boards/musca-b-test-chip-board
  16. * We model the A and B1 variants of this board, as described in the TRMs:
  17. * http://infocenter.arm.com/help/topic/com.arm.doc.101107_0000_00_en/index.html
  18. * http://infocenter.arm.com/help/topic/com.arm.doc.101312_0000_00_en/index.html
  19. */
  20. #include "qemu/osdep.h"
  21. #include "qemu/error-report.h"
  22. #include "qapi/error.h"
  23. #include "exec/address-spaces.h"
  24. #include "sysemu/sysemu.h"
  25. #include "hw/arm/boot.h"
  26. #include "hw/arm/armsse.h"
  27. #include "hw/boards.h"
  28. #include "hw/char/pl011.h"
  29. #include "hw/core/split-irq.h"
  30. #include "hw/misc/tz-mpc.h"
  31. #include "hw/misc/tz-ppc.h"
  32. #include "hw/misc/unimp.h"
  33. #include "hw/rtc/pl031.h"
  34. #define MUSCA_NUMIRQ_MAX 96
  35. #define MUSCA_PPC_MAX 3
  36. #define MUSCA_MPC_MAX 5
  37. typedef struct MPCInfo MPCInfo;
  38. typedef enum MuscaType {
  39. MUSCA_A,
  40. MUSCA_B1,
  41. } MuscaType;
  42. typedef struct {
  43. MachineClass parent;
  44. MuscaType type;
  45. uint32_t init_svtor;
  46. int sram_addr_width;
  47. int num_irqs;
  48. const MPCInfo *mpc_info;
  49. int num_mpcs;
  50. } MuscaMachineClass;
  51. typedef struct {
  52. MachineState parent;
  53. ARMSSE sse;
  54. /* RAM and flash */
  55. MemoryRegion ram[MUSCA_MPC_MAX];
  56. SplitIRQ cpu_irq_splitter[MUSCA_NUMIRQ_MAX];
  57. SplitIRQ sec_resp_splitter;
  58. TZPPC ppc[MUSCA_PPC_MAX];
  59. MemoryRegion container;
  60. UnimplementedDeviceState eflash[2];
  61. UnimplementedDeviceState qspi;
  62. TZMPC mpc[MUSCA_MPC_MAX];
  63. UnimplementedDeviceState mhu[2];
  64. UnimplementedDeviceState pwm[3];
  65. UnimplementedDeviceState i2s;
  66. PL011State uart[2];
  67. UnimplementedDeviceState i2c[2];
  68. UnimplementedDeviceState spi;
  69. UnimplementedDeviceState scc;
  70. UnimplementedDeviceState timer;
  71. PL031State rtc;
  72. UnimplementedDeviceState pvt;
  73. UnimplementedDeviceState sdio;
  74. UnimplementedDeviceState gpio;
  75. UnimplementedDeviceState cryptoisland;
  76. } MuscaMachineState;
  77. #define TYPE_MUSCA_MACHINE "musca"
  78. #define TYPE_MUSCA_A_MACHINE MACHINE_TYPE_NAME("musca-a")
  79. #define TYPE_MUSCA_B1_MACHINE MACHINE_TYPE_NAME("musca-b1")
  80. #define MUSCA_MACHINE(obj) \
  81. OBJECT_CHECK(MuscaMachineState, obj, TYPE_MUSCA_MACHINE)
  82. #define MUSCA_MACHINE_GET_CLASS(obj) \
  83. OBJECT_GET_CLASS(MuscaMachineClass, obj, TYPE_MUSCA_MACHINE)
  84. #define MUSCA_MACHINE_CLASS(klass) \
  85. OBJECT_CLASS_CHECK(MuscaMachineClass, klass, TYPE_MUSCA_MACHINE)
  86. /*
  87. * Main SYSCLK frequency in Hz
  88. * TODO this should really be different for the two cores, but we
  89. * don't model that in our SSE-200 model yet.
  90. */
  91. #define SYSCLK_FRQ 40000000
  92. static qemu_irq get_sse_irq_in(MuscaMachineState *mms, int irqno)
  93. {
  94. /* Return a qemu_irq which will signal IRQ n to all CPUs in the SSE. */
  95. assert(irqno < MUSCA_NUMIRQ_MAX);
  96. return qdev_get_gpio_in(DEVICE(&mms->cpu_irq_splitter[irqno]), 0);
  97. }
  98. /*
  99. * Most of the devices in the Musca board sit behind Peripheral Protection
  100. * Controllers. These data structures define the layout of which devices
  101. * sit behind which PPCs.
  102. * The devfn for each port is a function which creates, configures
  103. * and initializes the device, returning the MemoryRegion which
  104. * needs to be plugged into the downstream end of the PPC port.
  105. */
  106. typedef MemoryRegion *MakeDevFn(MuscaMachineState *mms, void *opaque,
  107. const char *name, hwaddr size);
  108. typedef struct PPCPortInfo {
  109. const char *name;
  110. MakeDevFn *devfn;
  111. void *opaque;
  112. hwaddr addr;
  113. hwaddr size;
  114. } PPCPortInfo;
  115. typedef struct PPCInfo {
  116. const char *name;
  117. PPCPortInfo ports[TZ_NUM_PORTS];
  118. } PPCInfo;
  119. static MemoryRegion *make_unimp_dev(MuscaMachineState *mms,
  120. void *opaque, const char *name, hwaddr size)
  121. {
  122. /*
  123. * Initialize, configure and realize a TYPE_UNIMPLEMENTED_DEVICE,
  124. * and return a pointer to its MemoryRegion.
  125. */
  126. UnimplementedDeviceState *uds = opaque;
  127. object_initialize_child(OBJECT(mms), name, uds, TYPE_UNIMPLEMENTED_DEVICE);
  128. qdev_prop_set_string(DEVICE(uds), "name", name);
  129. qdev_prop_set_uint64(DEVICE(uds), "size", size);
  130. sysbus_realize(SYS_BUS_DEVICE(uds), &error_fatal);
  131. return sysbus_mmio_get_region(SYS_BUS_DEVICE(uds), 0);
  132. }
  133. typedef enum MPCInfoType {
  134. MPC_RAM,
  135. MPC_ROM,
  136. MPC_CRYPTOISLAND,
  137. } MPCInfoType;
  138. struct MPCInfo {
  139. const char *name;
  140. hwaddr addr;
  141. hwaddr size;
  142. MPCInfoType type;
  143. };
  144. /* Order of the MPCs here must match the order of the bits in SECMPCINTSTATUS */
  145. static const MPCInfo a_mpc_info[] = { {
  146. .name = "qspi",
  147. .type = MPC_ROM,
  148. .addr = 0x00200000,
  149. .size = 0x00800000,
  150. }, {
  151. .name = "sram",
  152. .type = MPC_RAM,
  153. .addr = 0x00000000,
  154. .size = 0x00200000,
  155. }
  156. };
  157. static const MPCInfo b1_mpc_info[] = { {
  158. .name = "qspi",
  159. .type = MPC_ROM,
  160. .addr = 0x00000000,
  161. .size = 0x02000000,
  162. }, {
  163. .name = "sram",
  164. .type = MPC_RAM,
  165. .addr = 0x0a400000,
  166. .size = 0x00080000,
  167. }, {
  168. .name = "eflash0",
  169. .type = MPC_ROM,
  170. .addr = 0x0a000000,
  171. .size = 0x00200000,
  172. }, {
  173. .name = "eflash1",
  174. .type = MPC_ROM,
  175. .addr = 0x0a200000,
  176. .size = 0x00200000,
  177. }, {
  178. .name = "cryptoisland",
  179. .type = MPC_CRYPTOISLAND,
  180. .addr = 0x0a000000,
  181. .size = 0x00200000,
  182. }
  183. };
  184. static MemoryRegion *make_mpc(MuscaMachineState *mms, void *opaque,
  185. const char *name, hwaddr size)
  186. {
  187. /*
  188. * Create an MPC and the RAM or flash behind it.
  189. * MPC 0: eFlash 0
  190. * MPC 1: eFlash 1
  191. * MPC 2: SRAM
  192. * MPC 3: QSPI flash
  193. * MPC 4: CryptoIsland
  194. * For now we implement the flash regions as ROM (ie not programmable)
  195. * (with their control interface memory regions being unimplemented
  196. * stubs behind the PPCs).
  197. * The whole CryptoIsland region behind its MPC is an unimplemented stub.
  198. */
  199. MuscaMachineClass *mmc = MUSCA_MACHINE_GET_CLASS(mms);
  200. TZMPC *mpc = opaque;
  201. int i = mpc - &mms->mpc[0];
  202. MemoryRegion *downstream;
  203. MemoryRegion *upstream;
  204. UnimplementedDeviceState *uds;
  205. char *mpcname;
  206. const MPCInfo *mpcinfo = mmc->mpc_info;
  207. mpcname = g_strdup_printf("%s-mpc", mpcinfo[i].name);
  208. switch (mpcinfo[i].type) {
  209. case MPC_ROM:
  210. downstream = &mms->ram[i];
  211. memory_region_init_rom(downstream, NULL, mpcinfo[i].name,
  212. mpcinfo[i].size, &error_fatal);
  213. break;
  214. case MPC_RAM:
  215. downstream = &mms->ram[i];
  216. memory_region_init_ram(downstream, NULL, mpcinfo[i].name,
  217. mpcinfo[i].size, &error_fatal);
  218. break;
  219. case MPC_CRYPTOISLAND:
  220. /* We don't implement the CryptoIsland yet */
  221. uds = &mms->cryptoisland;
  222. object_initialize_child(OBJECT(mms), name, uds,
  223. TYPE_UNIMPLEMENTED_DEVICE);
  224. qdev_prop_set_string(DEVICE(uds), "name", mpcinfo[i].name);
  225. qdev_prop_set_uint64(DEVICE(uds), "size", mpcinfo[i].size);
  226. sysbus_realize(SYS_BUS_DEVICE(uds), &error_fatal);
  227. downstream = sysbus_mmio_get_region(SYS_BUS_DEVICE(uds), 0);
  228. break;
  229. default:
  230. g_assert_not_reached();
  231. }
  232. object_initialize_child(OBJECT(mms), mpcname, mpc, TYPE_TZ_MPC);
  233. object_property_set_link(OBJECT(mpc), "downstream", OBJECT(downstream),
  234. &error_fatal);
  235. sysbus_realize(SYS_BUS_DEVICE(mpc), &error_fatal);
  236. /* Map the upstream end of the MPC into system memory */
  237. upstream = sysbus_mmio_get_region(SYS_BUS_DEVICE(mpc), 1);
  238. memory_region_add_subregion(get_system_memory(), mpcinfo[i].addr, upstream);
  239. /* and connect its interrupt to the SSE-200 */
  240. qdev_connect_gpio_out_named(DEVICE(mpc), "irq", 0,
  241. qdev_get_gpio_in_named(DEVICE(&mms->sse),
  242. "mpcexp_status", i));
  243. g_free(mpcname);
  244. /* Return the register interface MR for our caller to map behind the PPC */
  245. return sysbus_mmio_get_region(SYS_BUS_DEVICE(mpc), 0);
  246. }
  247. static MemoryRegion *make_rtc(MuscaMachineState *mms, void *opaque,
  248. const char *name, hwaddr size)
  249. {
  250. PL031State *rtc = opaque;
  251. object_initialize_child(OBJECT(mms), name, rtc, TYPE_PL031);
  252. sysbus_realize(SYS_BUS_DEVICE(rtc), &error_fatal);
  253. sysbus_connect_irq(SYS_BUS_DEVICE(rtc), 0, get_sse_irq_in(mms, 39));
  254. return sysbus_mmio_get_region(SYS_BUS_DEVICE(rtc), 0);
  255. }
  256. static MemoryRegion *make_uart(MuscaMachineState *mms, void *opaque,
  257. const char *name, hwaddr size)
  258. {
  259. PL011State *uart = opaque;
  260. int i = uart - &mms->uart[0];
  261. int irqbase = 7 + i * 6;
  262. SysBusDevice *s;
  263. object_initialize_child(OBJECT(mms), name, uart, TYPE_PL011);
  264. qdev_prop_set_chr(DEVICE(uart), "chardev", serial_hd(i));
  265. sysbus_realize(SYS_BUS_DEVICE(uart), &error_fatal);
  266. s = SYS_BUS_DEVICE(uart);
  267. sysbus_connect_irq(s, 0, get_sse_irq_in(mms, irqbase + 5)); /* combined */
  268. sysbus_connect_irq(s, 1, get_sse_irq_in(mms, irqbase + 0)); /* RX */
  269. sysbus_connect_irq(s, 2, get_sse_irq_in(mms, irqbase + 1)); /* TX */
  270. sysbus_connect_irq(s, 3, get_sse_irq_in(mms, irqbase + 2)); /* RT */
  271. sysbus_connect_irq(s, 4, get_sse_irq_in(mms, irqbase + 3)); /* MS */
  272. sysbus_connect_irq(s, 5, get_sse_irq_in(mms, irqbase + 4)); /* E */
  273. return sysbus_mmio_get_region(SYS_BUS_DEVICE(uart), 0);
  274. }
  275. static MemoryRegion *make_musca_a_devs(MuscaMachineState *mms, void *opaque,
  276. const char *name, hwaddr size)
  277. {
  278. /*
  279. * Create the container MemoryRegion for all the devices that live
  280. * behind the Musca-A PPC's single port. These devices don't have a PPC
  281. * port each, but we use the PPCPortInfo struct as a convenient way
  282. * to describe them. Note that addresses here are relative to the base
  283. * address of the PPC port region: 0x40100000, and devices appear both
  284. * at the 0x4... NS region and the 0x5... S region.
  285. */
  286. int i;
  287. MemoryRegion *container = &mms->container;
  288. const PPCPortInfo devices[] = {
  289. { "uart0", make_uart, &mms->uart[0], 0x1000, 0x1000 },
  290. { "uart1", make_uart, &mms->uart[1], 0x2000, 0x1000 },
  291. { "spi", make_unimp_dev, &mms->spi, 0x3000, 0x1000 },
  292. { "i2c0", make_unimp_dev, &mms->i2c[0], 0x4000, 0x1000 },
  293. { "i2c1", make_unimp_dev, &mms->i2c[1], 0x5000, 0x1000 },
  294. { "i2s", make_unimp_dev, &mms->i2s, 0x6000, 0x1000 },
  295. { "pwm0", make_unimp_dev, &mms->pwm[0], 0x7000, 0x1000 },
  296. { "rtc", make_rtc, &mms->rtc, 0x8000, 0x1000 },
  297. { "qspi", make_unimp_dev, &mms->qspi, 0xa000, 0x1000 },
  298. { "timer", make_unimp_dev, &mms->timer, 0xb000, 0x1000 },
  299. { "scc", make_unimp_dev, &mms->scc, 0xc000, 0x1000 },
  300. { "pwm1", make_unimp_dev, &mms->pwm[1], 0xe000, 0x1000 },
  301. { "pwm2", make_unimp_dev, &mms->pwm[2], 0xf000, 0x1000 },
  302. { "gpio", make_unimp_dev, &mms->gpio, 0x10000, 0x1000 },
  303. { "mpc0", make_mpc, &mms->mpc[0], 0x12000, 0x1000 },
  304. { "mpc1", make_mpc, &mms->mpc[1], 0x13000, 0x1000 },
  305. };
  306. memory_region_init(container, OBJECT(mms), "musca-device-container", size);
  307. for (i = 0; i < ARRAY_SIZE(devices); i++) {
  308. const PPCPortInfo *pinfo = &devices[i];
  309. MemoryRegion *mr;
  310. mr = pinfo->devfn(mms, pinfo->opaque, pinfo->name, pinfo->size);
  311. memory_region_add_subregion(container, pinfo->addr, mr);
  312. }
  313. return &mms->container;
  314. }
  315. static void musca_init(MachineState *machine)
  316. {
  317. MuscaMachineState *mms = MUSCA_MACHINE(machine);
  318. MuscaMachineClass *mmc = MUSCA_MACHINE_GET_CLASS(mms);
  319. MachineClass *mc = MACHINE_GET_CLASS(machine);
  320. MemoryRegion *system_memory = get_system_memory();
  321. DeviceState *ssedev;
  322. DeviceState *dev_splitter;
  323. const PPCInfo *ppcs;
  324. int num_ppcs;
  325. int i;
  326. assert(mmc->num_irqs <= MUSCA_NUMIRQ_MAX);
  327. assert(mmc->num_mpcs <= MUSCA_MPC_MAX);
  328. if (strcmp(machine->cpu_type, mc->default_cpu_type) != 0) {
  329. error_report("This board can only be used with CPU %s",
  330. mc->default_cpu_type);
  331. exit(1);
  332. }
  333. object_initialize_child(OBJECT(machine), "sse-200", &mms->sse,
  334. TYPE_SSE200);
  335. ssedev = DEVICE(&mms->sse);
  336. object_property_set_link(OBJECT(&mms->sse), "memory",
  337. OBJECT(system_memory), &error_fatal);
  338. qdev_prop_set_uint32(ssedev, "EXP_NUMIRQ", mmc->num_irqs);
  339. qdev_prop_set_uint32(ssedev, "init-svtor", mmc->init_svtor);
  340. qdev_prop_set_uint32(ssedev, "SRAM_ADDR_WIDTH", mmc->sram_addr_width);
  341. qdev_prop_set_uint32(ssedev, "MAINCLK", SYSCLK_FRQ);
  342. /*
  343. * Musca-A takes the default SSE-200 FPU/DSP settings (ie no for
  344. * CPU0 and yes for CPU1); Musca-B1 explicitly enables them for CPU0.
  345. */
  346. if (mmc->type == MUSCA_B1) {
  347. qdev_prop_set_bit(ssedev, "CPU0_FPU", true);
  348. qdev_prop_set_bit(ssedev, "CPU0_DSP", true);
  349. }
  350. sysbus_realize(SYS_BUS_DEVICE(&mms->sse), &error_fatal);
  351. /*
  352. * We need to create splitters to feed the IRQ inputs
  353. * for each CPU in the SSE-200 from each device in the board.
  354. */
  355. for (i = 0; i < mmc->num_irqs; i++) {
  356. char *name = g_strdup_printf("musca-irq-splitter%d", i);
  357. SplitIRQ *splitter = &mms->cpu_irq_splitter[i];
  358. object_initialize_child_with_props(OBJECT(machine), name, splitter,
  359. sizeof(*splitter), TYPE_SPLIT_IRQ,
  360. &error_fatal, NULL);
  361. g_free(name);
  362. object_property_set_int(OBJECT(splitter), "num-lines", 2,
  363. &error_fatal);
  364. qdev_realize(DEVICE(splitter), NULL, &error_fatal);
  365. qdev_connect_gpio_out(DEVICE(splitter), 0,
  366. qdev_get_gpio_in_named(ssedev, "EXP_IRQ", i));
  367. qdev_connect_gpio_out(DEVICE(splitter), 1,
  368. qdev_get_gpio_in_named(ssedev,
  369. "EXP_CPU1_IRQ", i));
  370. }
  371. /*
  372. * The sec_resp_cfg output from the SSE-200 must be split into multiple
  373. * lines, one for each of the PPCs we create here.
  374. */
  375. object_initialize_child_with_props(OBJECT(machine), "sec-resp-splitter",
  376. &mms->sec_resp_splitter,
  377. sizeof(mms->sec_resp_splitter),
  378. TYPE_SPLIT_IRQ, &error_fatal, NULL);
  379. object_property_set_int(OBJECT(&mms->sec_resp_splitter), "num-lines",
  380. ARRAY_SIZE(mms->ppc), &error_fatal);
  381. qdev_realize(DEVICE(&mms->sec_resp_splitter), NULL, &error_fatal);
  382. dev_splitter = DEVICE(&mms->sec_resp_splitter);
  383. qdev_connect_gpio_out_named(ssedev, "sec_resp_cfg", 0,
  384. qdev_get_gpio_in(dev_splitter, 0));
  385. /*
  386. * Most of the devices in the board are behind Peripheral Protection
  387. * Controllers. The required order for initializing things is:
  388. * + initialize the PPC
  389. * + initialize, configure and realize downstream devices
  390. * + connect downstream device MemoryRegions to the PPC
  391. * + realize the PPC
  392. * + map the PPC's MemoryRegions to the places in the address map
  393. * where the downstream devices should appear
  394. * + wire up the PPC's control lines to the SSE object
  395. *
  396. * The PPC mapping differs for the -A and -B1 variants; the -A version
  397. * is much simpler, using only a single port of a single PPC and putting
  398. * all the devices behind that.
  399. */
  400. const PPCInfo a_ppcs[] = { {
  401. .name = "ahb_ppcexp0",
  402. .ports = {
  403. { "musca-devices", make_musca_a_devs, 0, 0x40100000, 0x100000 },
  404. },
  405. },
  406. };
  407. /*
  408. * Devices listed with an 0x4.. address appear in both the NS 0x4.. region
  409. * and the 0x5.. S region. Devices listed with an 0x5.. address appear
  410. * only in the S region.
  411. */
  412. const PPCInfo b1_ppcs[] = { {
  413. .name = "apb_ppcexp0",
  414. .ports = {
  415. { "eflash0", make_unimp_dev, &mms->eflash[0],
  416. 0x52400000, 0x1000 },
  417. { "eflash1", make_unimp_dev, &mms->eflash[1],
  418. 0x52500000, 0x1000 },
  419. { "qspi", make_unimp_dev, &mms->qspi, 0x42800000, 0x100000 },
  420. { "mpc0", make_mpc, &mms->mpc[0], 0x52000000, 0x1000 },
  421. { "mpc1", make_mpc, &mms->mpc[1], 0x52100000, 0x1000 },
  422. { "mpc2", make_mpc, &mms->mpc[2], 0x52200000, 0x1000 },
  423. { "mpc3", make_mpc, &mms->mpc[3], 0x52300000, 0x1000 },
  424. { "mhu0", make_unimp_dev, &mms->mhu[0], 0x42600000, 0x100000 },
  425. { "mhu1", make_unimp_dev, &mms->mhu[1], 0x42700000, 0x100000 },
  426. { }, /* port 9: unused */
  427. { }, /* port 10: unused */
  428. { }, /* port 11: unused */
  429. { }, /* port 12: unused */
  430. { }, /* port 13: unused */
  431. { "mpc4", make_mpc, &mms->mpc[4], 0x52e00000, 0x1000 },
  432. },
  433. }, {
  434. .name = "apb_ppcexp1",
  435. .ports = {
  436. { "pwm0", make_unimp_dev, &mms->pwm[0], 0x40101000, 0x1000 },
  437. { "pwm1", make_unimp_dev, &mms->pwm[1], 0x40102000, 0x1000 },
  438. { "pwm2", make_unimp_dev, &mms->pwm[2], 0x40103000, 0x1000 },
  439. { "i2s", make_unimp_dev, &mms->i2s, 0x40104000, 0x1000 },
  440. { "uart0", make_uart, &mms->uart[0], 0x40105000, 0x1000 },
  441. { "uart1", make_uart, &mms->uart[1], 0x40106000, 0x1000 },
  442. { "i2c0", make_unimp_dev, &mms->i2c[0], 0x40108000, 0x1000 },
  443. { "i2c1", make_unimp_dev, &mms->i2c[1], 0x40109000, 0x1000 },
  444. { "spi", make_unimp_dev, &mms->spi, 0x4010a000, 0x1000 },
  445. { "scc", make_unimp_dev, &mms->scc, 0x5010b000, 0x1000 },
  446. { "timer", make_unimp_dev, &mms->timer, 0x4010c000, 0x1000 },
  447. { "rtc", make_rtc, &mms->rtc, 0x4010d000, 0x1000 },
  448. { "pvt", make_unimp_dev, &mms->pvt, 0x4010e000, 0x1000 },
  449. { "sdio", make_unimp_dev, &mms->sdio, 0x4010f000, 0x1000 },
  450. },
  451. }, {
  452. .name = "ahb_ppcexp0",
  453. .ports = {
  454. { }, /* port 0: unused */
  455. { "gpio", make_unimp_dev, &mms->gpio, 0x41000000, 0x1000 },
  456. },
  457. },
  458. };
  459. switch (mmc->type) {
  460. case MUSCA_A:
  461. ppcs = a_ppcs;
  462. num_ppcs = ARRAY_SIZE(a_ppcs);
  463. break;
  464. case MUSCA_B1:
  465. ppcs = b1_ppcs;
  466. num_ppcs = ARRAY_SIZE(b1_ppcs);
  467. break;
  468. default:
  469. g_assert_not_reached();
  470. }
  471. assert(num_ppcs <= MUSCA_PPC_MAX);
  472. for (i = 0; i < num_ppcs; i++) {
  473. const PPCInfo *ppcinfo = &ppcs[i];
  474. TZPPC *ppc = &mms->ppc[i];
  475. DeviceState *ppcdev;
  476. int port;
  477. char *gpioname;
  478. object_initialize_child(OBJECT(machine), ppcinfo->name, ppc,
  479. TYPE_TZ_PPC);
  480. ppcdev = DEVICE(ppc);
  481. for (port = 0; port < TZ_NUM_PORTS; port++) {
  482. const PPCPortInfo *pinfo = &ppcinfo->ports[port];
  483. MemoryRegion *mr;
  484. char *portname;
  485. if (!pinfo->devfn) {
  486. continue;
  487. }
  488. mr = pinfo->devfn(mms, pinfo->opaque, pinfo->name, pinfo->size);
  489. portname = g_strdup_printf("port[%d]", port);
  490. object_property_set_link(OBJECT(ppc), portname, OBJECT(mr),
  491. &error_fatal);
  492. g_free(portname);
  493. }
  494. sysbus_realize(SYS_BUS_DEVICE(ppc), &error_fatal);
  495. for (port = 0; port < TZ_NUM_PORTS; port++) {
  496. const PPCPortInfo *pinfo = &ppcinfo->ports[port];
  497. if (!pinfo->devfn) {
  498. continue;
  499. }
  500. sysbus_mmio_map(SYS_BUS_DEVICE(ppc), port, pinfo->addr);
  501. gpioname = g_strdup_printf("%s_nonsec", ppcinfo->name);
  502. qdev_connect_gpio_out_named(ssedev, gpioname, port,
  503. qdev_get_gpio_in_named(ppcdev,
  504. "cfg_nonsec",
  505. port));
  506. g_free(gpioname);
  507. gpioname = g_strdup_printf("%s_ap", ppcinfo->name);
  508. qdev_connect_gpio_out_named(ssedev, gpioname, port,
  509. qdev_get_gpio_in_named(ppcdev,
  510. "cfg_ap", port));
  511. g_free(gpioname);
  512. }
  513. gpioname = g_strdup_printf("%s_irq_enable", ppcinfo->name);
  514. qdev_connect_gpio_out_named(ssedev, gpioname, 0,
  515. qdev_get_gpio_in_named(ppcdev,
  516. "irq_enable", 0));
  517. g_free(gpioname);
  518. gpioname = g_strdup_printf("%s_irq_clear", ppcinfo->name);
  519. qdev_connect_gpio_out_named(ssedev, gpioname, 0,
  520. qdev_get_gpio_in_named(ppcdev,
  521. "irq_clear", 0));
  522. g_free(gpioname);
  523. gpioname = g_strdup_printf("%s_irq_status", ppcinfo->name);
  524. qdev_connect_gpio_out_named(ppcdev, "irq", 0,
  525. qdev_get_gpio_in_named(ssedev,
  526. gpioname, 0));
  527. g_free(gpioname);
  528. qdev_connect_gpio_out(dev_splitter, i,
  529. qdev_get_gpio_in_named(ppcdev,
  530. "cfg_sec_resp", 0));
  531. }
  532. armv7m_load_kernel(ARM_CPU(first_cpu), machine->kernel_filename, 0x2000000);
  533. }
  534. static void musca_class_init(ObjectClass *oc, void *data)
  535. {
  536. MachineClass *mc = MACHINE_CLASS(oc);
  537. mc->default_cpus = 2;
  538. mc->min_cpus = mc->default_cpus;
  539. mc->max_cpus = mc->default_cpus;
  540. mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m33");
  541. mc->init = musca_init;
  542. }
  543. static void musca_a_class_init(ObjectClass *oc, void *data)
  544. {
  545. MachineClass *mc = MACHINE_CLASS(oc);
  546. MuscaMachineClass *mmc = MUSCA_MACHINE_CLASS(oc);
  547. mc->desc = "ARM Musca-A board (dual Cortex-M33)";
  548. mmc->type = MUSCA_A;
  549. mmc->init_svtor = 0x10200000;
  550. mmc->sram_addr_width = 15;
  551. mmc->num_irqs = 64;
  552. mmc->mpc_info = a_mpc_info;
  553. mmc->num_mpcs = ARRAY_SIZE(a_mpc_info);
  554. }
  555. static void musca_b1_class_init(ObjectClass *oc, void *data)
  556. {
  557. MachineClass *mc = MACHINE_CLASS(oc);
  558. MuscaMachineClass *mmc = MUSCA_MACHINE_CLASS(oc);
  559. mc->desc = "ARM Musca-B1 board (dual Cortex-M33)";
  560. mmc->type = MUSCA_B1;
  561. /*
  562. * This matches the DAPlink firmware which boots from QSPI. There
  563. * is also a firmware blob which boots from the eFlash, which
  564. * uses init_svtor = 0x1A000000. QEMU doesn't currently support that,
  565. * though we could in theory expose a machine property on the command
  566. * line to allow the user to request eFlash boot.
  567. */
  568. mmc->init_svtor = 0x10000000;
  569. mmc->sram_addr_width = 17;
  570. mmc->num_irqs = 96;
  571. mmc->mpc_info = b1_mpc_info;
  572. mmc->num_mpcs = ARRAY_SIZE(b1_mpc_info);
  573. }
  574. static const TypeInfo musca_info = {
  575. .name = TYPE_MUSCA_MACHINE,
  576. .parent = TYPE_MACHINE,
  577. .abstract = true,
  578. .instance_size = sizeof(MuscaMachineState),
  579. .class_size = sizeof(MuscaMachineClass),
  580. .class_init = musca_class_init,
  581. };
  582. static const TypeInfo musca_a_info = {
  583. .name = TYPE_MUSCA_A_MACHINE,
  584. .parent = TYPE_MUSCA_MACHINE,
  585. .class_init = musca_a_class_init,
  586. };
  587. static const TypeInfo musca_b1_info = {
  588. .name = TYPE_MUSCA_B1_MACHINE,
  589. .parent = TYPE_MUSCA_MACHINE,
  590. .class_init = musca_b1_class_init,
  591. };
  592. static void musca_machine_init(void)
  593. {
  594. type_register_static(&musca_info);
  595. type_register_static(&musca_a_info);
  596. type_register_static(&musca_b1_info);
  597. }
  598. type_init(musca_machine_init);