musca.c 25 KB

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