dv-bfin_dmac.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. /* Blackfin Direct Memory Access (DMA) Controller model.
  2. Copyright (C) 2010-2022 Free Software Foundation, Inc.
  3. Contributed by Analog Devices, Inc.
  4. This file is part of simulators.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  15. /* This must come before any other includes. */
  16. #include "defs.h"
  17. #include "sim-main.h"
  18. #include "sim-hw.h"
  19. #include "devices.h"
  20. #include "hw-device.h"
  21. #include "dv-bfin_dma.h"
  22. #include "dv-bfin_dmac.h"
  23. struct bfin_dmac
  24. {
  25. /* This top portion matches common dv_bfin struct. */
  26. bu32 base;
  27. struct hw *dma_master;
  28. bool acked;
  29. const char * const *pmap;
  30. unsigned int pmap_count;
  31. };
  32. struct hw *
  33. bfin_dmac_get_peer (struct hw *dma, bu16 pmap)
  34. {
  35. struct hw *ret, *me;
  36. struct bfin_dmac *dmac;
  37. char peer[100];
  38. me = hw_parent (dma);
  39. dmac = hw_data (me);
  40. if (pmap & CTYPE)
  41. {
  42. /* MDMA channel. */
  43. unsigned int chan_num = dv_get_bus_num (dma);
  44. if (chan_num & 1)
  45. chan_num &= ~1;
  46. else
  47. chan_num |= 1;
  48. sprintf (peer, "%s/bfin_dma@%u", hw_path (me), chan_num);
  49. }
  50. else
  51. {
  52. unsigned int idx = pmap >> 12;
  53. if (idx >= dmac->pmap_count)
  54. hw_abort (me, "Invalid DMA peripheral_map %#x", pmap);
  55. else
  56. sprintf (peer, "/core/bfin_%s", dmac->pmap[idx]);
  57. }
  58. ret = hw_tree_find_device (me, peer);
  59. if (!ret)
  60. hw_abort (me, "Unable to locate peer for %s (pmap:%#x %s)",
  61. hw_name (dma), pmap, peer);
  62. return ret;
  63. }
  64. bu16
  65. bfin_dmac_default_pmap (struct hw *dma)
  66. {
  67. unsigned int chan_num = dv_get_bus_num (dma);
  68. if (chan_num < BFIN_DMAC_MDMA_BASE)
  69. return (chan_num % 12) << 12;
  70. else
  71. return CTYPE; /* MDMA */
  72. }
  73. static const char * const bfin_dmac_50x_pmap[] =
  74. {
  75. "ppi@0", "rsi", "sport@0", "sport@0", "sport@1", "sport@1",
  76. "spi@0", "spi@1", "uart2@0", "uart2@0", "uart2@1", "uart2@1",
  77. };
  78. /* XXX: Need to figure out how to handle portmuxed DMA channels. */
  79. static const struct hw_port_descriptor bfin_dmac_50x_ports[] =
  80. {
  81. { "ppi@0", 0, 0, input_port, },
  82. { "rsi", 1, 0, input_port, },
  83. { "sport@0_rx", 2, 0, input_port, },
  84. { "sport@0_tx", 3, 0, input_port, },
  85. { "sport@1_tx", 4, 0, input_port, },
  86. { "sport@1_rx", 5, 0, input_port, },
  87. { "spi@0", 6, 0, input_port, },
  88. { "spi@1", 7, 0, input_port, },
  89. { "uart2@0_rx", 8, 0, input_port, },
  90. { "uart2@0_tx", 9, 0, input_port, },
  91. { "uart2@1_rx", 10, 0, input_port, },
  92. { "uart2@1_tx", 11, 0, input_port, },
  93. { NULL, 0, 0, 0, },
  94. };
  95. static const char * const bfin_dmac_51x_pmap[] =
  96. {
  97. "ppi@0", "emac", "emac", "sport@0", "sport@0", "sport@1",
  98. "sport@1", "spi@0", "uart@0", "uart@0", "uart@1", "uart@1",
  99. };
  100. /* XXX: Need to figure out how to handle portmuxed DMA channels. */
  101. static const struct hw_port_descriptor bfin_dmac_51x_ports[] =
  102. {
  103. { "ppi@0", 0, 0, input_port, },
  104. { "emac_rx", 1, 0, input_port, },
  105. { "emac_tx", 2, 0, input_port, },
  106. { "sport@0_rx", 3, 0, input_port, },
  107. { "sport@0_tx", 4, 0, input_port, },
  108. /*{ "rsi", 4, 0, input_port, },*/
  109. { "sport@1_tx", 5, 0, input_port, },
  110. /*{ "spi@1", 5, 0, input_port, },*/
  111. { "sport@1_rx", 6, 0, input_port, },
  112. { "spi@0", 7, 0, input_port, },
  113. { "uart@0_rx", 8, 0, input_port, },
  114. { "uart@0_tx", 9, 0, input_port, },
  115. { "uart@1_rx", 10, 0, input_port, },
  116. { "uart@1_tx", 11, 0, input_port, },
  117. { NULL, 0, 0, 0, },
  118. };
  119. static const char * const bfin_dmac_52x_pmap[] =
  120. {
  121. "ppi@0", "emac", "emac", "sport@0", "sport@0", "sport@1",
  122. "sport@1", "spi", "uart@0", "uart@0", "uart@1", "uart@1",
  123. };
  124. /* XXX: Need to figure out how to handle portmuxed DMA channels
  125. like PPI/NFC here which share DMA0. */
  126. static const struct hw_port_descriptor bfin_dmac_52x_ports[] =
  127. {
  128. { "ppi@0", 0, 0, input_port, },
  129. /*{ "nfc", 0, 0, input_port, },*/
  130. { "emac_rx", 1, 0, input_port, },
  131. /*{ "hostdp", 1, 0, input_port, },*/
  132. { "emac_tx", 2, 0, input_port, },
  133. /*{ "nfc", 2, 0, input_port, },*/
  134. { "sport@0_tx", 3, 0, input_port, },
  135. { "sport@0_rx", 4, 0, input_port, },
  136. { "sport@1_tx", 5, 0, input_port, },
  137. { "sport@1_rx", 6, 0, input_port, },
  138. { "spi", 7, 0, input_port, },
  139. { "uart@0_tx", 8, 0, input_port, },
  140. { "uart@0_rx", 9, 0, input_port, },
  141. { "uart@1_tx", 10, 0, input_port, },
  142. { "uart@1_rx", 11, 0, input_port, },
  143. { NULL, 0, 0, 0, },
  144. };
  145. static const char * const bfin_dmac_533_pmap[] =
  146. {
  147. "ppi@0", "sport@0", "sport@0", "sport@1", "sport@1", "spi",
  148. "uart@0", "uart@0",
  149. };
  150. static const struct hw_port_descriptor bfin_dmac_533_ports[] =
  151. {
  152. { "ppi@0", 0, 0, input_port, },
  153. { "sport@0_tx", 1, 0, input_port, },
  154. { "sport@0_rx", 2, 0, input_port, },
  155. { "sport@1_tx", 3, 0, input_port, },
  156. { "sport@1_rx", 4, 0, input_port, },
  157. { "spi", 5, 0, input_port, },
  158. { "uart@0_tx", 6, 0, input_port, },
  159. { "uart@0_rx", 7, 0, input_port, },
  160. { NULL, 0, 0, 0, },
  161. };
  162. static const char * const bfin_dmac_537_pmap[] =
  163. {
  164. "ppi@0", "emac", "emac", "sport@0", "sport@0", "sport@1",
  165. "sport@1", "spi", "uart@0", "uart@0", "uart@1", "uart@1",
  166. };
  167. static const struct hw_port_descriptor bfin_dmac_537_ports[] =
  168. {
  169. { "ppi@0", 0, 0, input_port, },
  170. { "emac_rx", 1, 0, input_port, },
  171. { "emac_tx", 2, 0, input_port, },
  172. { "sport@0_tx", 3, 0, input_port, },
  173. { "sport@0_rx", 4, 0, input_port, },
  174. { "sport@1_tx", 5, 0, input_port, },
  175. { "sport@1_rx", 6, 0, input_port, },
  176. { "spi", 7, 0, input_port, },
  177. { "uart@0_tx", 8, 0, input_port, },
  178. { "uart@0_rx", 9, 0, input_port, },
  179. { "uart@1_tx", 10, 0, input_port, },
  180. { "uart@1_rx", 11, 0, input_port, },
  181. { NULL, 0, 0, 0, },
  182. };
  183. static const char * const bfin_dmac0_538_pmap[] =
  184. {
  185. "ppi@0", "sport@0", "sport@0", "sport@1", "sport@1", "spi@0",
  186. "uart@0", "uart@0",
  187. };
  188. static const struct hw_port_descriptor bfin_dmac0_538_ports[] =
  189. {
  190. { "ppi@0", 0, 0, input_port, },
  191. { "sport@0_rx", 1, 0, input_port, },
  192. { "sport@0_tx", 2, 0, input_port, },
  193. { "sport@1_rx", 3, 0, input_port, },
  194. { "sport@1_tx", 4, 0, input_port, },
  195. { "spi@0", 5, 0, input_port, },
  196. { "uart@0_rx", 6, 0, input_port, },
  197. { "uart@0_tx", 7, 0, input_port, },
  198. { NULL, 0, 0, 0, },
  199. };
  200. static const char * const bfin_dmac1_538_pmap[] =
  201. {
  202. "sport@2", "sport@2", "sport@3", "sport@3", NULL, NULL,
  203. "spi@1", "spi@2", "uart@1", "uart@1", "uart@2", "uart@2",
  204. };
  205. static const struct hw_port_descriptor bfin_dmac1_538_ports[] =
  206. {
  207. { "sport@2_rx", 0, 0, input_port, },
  208. { "sport@2_tx", 1, 0, input_port, },
  209. { "sport@3_rx", 2, 0, input_port, },
  210. { "sport@3_tx", 3, 0, input_port, },
  211. { "spi@1", 6, 0, input_port, },
  212. { "spi@2", 7, 0, input_port, },
  213. { "uart@1_rx", 8, 0, input_port, },
  214. { "uart@1_tx", 9, 0, input_port, },
  215. { "uart@2_rx", 10, 0, input_port, },
  216. { "uart@2_tx", 11, 0, input_port, },
  217. { NULL, 0, 0, 0, },
  218. };
  219. static const char * const bfin_dmac0_54x_pmap[] =
  220. {
  221. "sport@0", "sport@0", "sport@1", "sport@1", "spi@0", "spi@1",
  222. "uart2@0", "uart2@0", "uart2@1", "uart2@1", "atapi", "atapi",
  223. };
  224. static const struct hw_port_descriptor bfin_dmac0_54x_ports[] =
  225. {
  226. { "sport@0_rx", 0, 0, input_port, },
  227. { "sport@0_tx", 1, 0, input_port, },
  228. { "sport@1_rx", 2, 0, input_port, },
  229. { "sport@1_tx", 3, 0, input_port, },
  230. { "spi@0", 4, 0, input_port, },
  231. { "spi@1", 5, 0, input_port, },
  232. { "uart2@0_rx", 6, 0, input_port, },
  233. { "uart2@0_tx", 7, 0, input_port, },
  234. { "uart2@1_rx", 8, 0, input_port, },
  235. { "uart2@1_tx", 9, 0, input_port, },
  236. { "atapi", 10, 0, input_port, },
  237. { "atapi", 11, 0, input_port, },
  238. { NULL, 0, 0, 0, },
  239. };
  240. static const char * const bfin_dmac1_54x_pmap[] =
  241. {
  242. "eppi@0", "eppi@1", "eppi@2", "pixc", "pixc", "pixc",
  243. "sport@2", "sport@2", "sport@3", "sport@3", "sdh",
  244. "spi@2", "uart2@2", "uart2@2", "uart2@3", "uart2@3",
  245. };
  246. static const struct hw_port_descriptor bfin_dmac1_54x_ports[] =
  247. {
  248. { "eppi@0", 0, 0, input_port, },
  249. { "eppi@1", 1, 0, input_port, },
  250. { "eppi@2", 2, 0, input_port, },
  251. { "pixc", 3, 0, input_port, },
  252. { "pixc", 4, 0, input_port, },
  253. { "pixc", 5, 0, input_port, },
  254. { "sport@2_rx", 6, 0, input_port, },
  255. { "sport@2_tx", 7, 0, input_port, },
  256. { "sport@3_rx", 8, 0, input_port, },
  257. { "sport@3_tx", 9, 0, input_port, },
  258. { "sdh", 10, 0, input_port, },
  259. /*{ "nfc", 10, 0, input_port, },*/
  260. { "spi@2", 11, 0, input_port, },
  261. { "uart2@2_rx", 12, 0, input_port, },
  262. { "uart2@2_tx", 13, 0, input_port, },
  263. { "uart2@3_rx", 14, 0, input_port, },
  264. { "uart2@3_tx", 15, 0, input_port, },
  265. { NULL, 0, 0, 0, },
  266. };
  267. static const char * const bfin_dmac0_561_pmap[] =
  268. {
  269. "sport@0", "sport@0", "sport@1", "sport@1", "spi", "uart@0", "uart@0",
  270. };
  271. static const struct hw_port_descriptor bfin_dmac0_561_ports[] =
  272. {
  273. { "sport@0_rx", 0, 0, input_port, },
  274. { "sport@0_tx", 1, 0, input_port, },
  275. { "sport@1_rx", 2, 0, input_port, },
  276. { "sport@1_tx", 3, 0, input_port, },
  277. { "spi@0", 4, 0, input_port, },
  278. { "uart@0_rx", 5, 0, input_port, },
  279. { "uart@0_tx", 6, 0, input_port, },
  280. { NULL, 0, 0, 0, },
  281. };
  282. static const char * const bfin_dmac1_561_pmap[] =
  283. {
  284. "ppi@0", "ppi@1",
  285. };
  286. static const struct hw_port_descriptor bfin_dmac1_561_ports[] =
  287. {
  288. { "ppi@0", 0, 0, input_port, },
  289. { "ppi@1", 1, 0, input_port, },
  290. { NULL, 0, 0, 0, },
  291. };
  292. static const char * const bfin_dmac_59x_pmap[] =
  293. {
  294. "ppi@0", "sport@0", "sport@0", "sport@1", "sport@1", "spi@0",
  295. "spi@1", "uart@0", "uart@0",
  296. };
  297. static const struct hw_port_descriptor bfin_dmac_59x_ports[] =
  298. {
  299. { "ppi@0", 0, 0, input_port, },
  300. { "sport@0_tx", 1, 0, input_port, },
  301. { "sport@0_rx", 2, 0, input_port, },
  302. { "sport@1_tx", 3, 0, input_port, },
  303. { "sport@1_rx", 4, 0, input_port, },
  304. { "spi@0", 5, 0, input_port, },
  305. { "spi@1", 6, 0, input_port, },
  306. { "uart@0_rx", 7, 0, input_port, },
  307. { "uart@0_tx", 8, 0, input_port, },
  308. { NULL, 0, 0, 0, },
  309. };
  310. static void
  311. bfin_dmac_port_event (struct hw *me, int my_port, struct hw *source,
  312. int source_port, int level)
  313. {
  314. SIM_DESC sd = hw_system (me);
  315. struct bfin_dmac *dmac = hw_data (me);
  316. struct hw *dma = hw_child (me);
  317. while (dma)
  318. {
  319. bu16 pmap;
  320. sim_hw_io_read_buffer (sd, dma, &pmap, 0, 0x2c, sizeof (pmap));
  321. pmap >>= 12;
  322. if (pmap == my_port)
  323. break;
  324. dma = hw_sibling (dma);
  325. }
  326. if (!dma)
  327. hw_abort (me, "no valid dma mapping found for %s", dmac->pmap[my_port]);
  328. /* Have the DMA channel raise its interrupt to the SIC. */
  329. hw_port_event (dma, 0, 1);
  330. }
  331. static void
  332. bfin_dmac_finish (struct hw *me)
  333. {
  334. struct bfin_dmac *dmac;
  335. unsigned int dmac_num = dv_get_bus_num (me);
  336. dmac = HW_ZALLOC (me, struct bfin_dmac);
  337. set_hw_data (me, dmac);
  338. set_hw_port_event (me, bfin_dmac_port_event);
  339. /* Initialize the DMA Controller. */
  340. if (hw_find_property (me, "type") == NULL)
  341. hw_abort (me, "Missing \"type\" property");
  342. switch (hw_find_integer_property (me, "type"))
  343. {
  344. case 500 ... 509:
  345. if (dmac_num != 0)
  346. hw_abort (me, "this Blackfin only has a DMAC0");
  347. dmac->pmap = bfin_dmac_50x_pmap;
  348. dmac->pmap_count = ARRAY_SIZE (bfin_dmac_50x_pmap);
  349. set_hw_ports (me, bfin_dmac_50x_ports);
  350. break;
  351. case 510 ... 519:
  352. if (dmac_num != 0)
  353. hw_abort (me, "this Blackfin only has a DMAC0");
  354. dmac->pmap = bfin_dmac_51x_pmap;
  355. dmac->pmap_count = ARRAY_SIZE (bfin_dmac_51x_pmap);
  356. set_hw_ports (me, bfin_dmac_51x_ports);
  357. break;
  358. case 522 ... 527:
  359. if (dmac_num != 0)
  360. hw_abort (me, "this Blackfin only has a DMAC0");
  361. dmac->pmap = bfin_dmac_52x_pmap;
  362. dmac->pmap_count = ARRAY_SIZE (bfin_dmac_52x_pmap);
  363. set_hw_ports (me, bfin_dmac_52x_ports);
  364. break;
  365. case 531 ... 533:
  366. if (dmac_num != 0)
  367. hw_abort (me, "this Blackfin only has a DMAC0");
  368. dmac->pmap = bfin_dmac_533_pmap;
  369. dmac->pmap_count = ARRAY_SIZE (bfin_dmac_533_pmap);
  370. set_hw_ports (me, bfin_dmac_533_ports);
  371. break;
  372. case 534:
  373. case 536:
  374. case 537:
  375. if (dmac_num != 0)
  376. hw_abort (me, "this Blackfin only has a DMAC0");
  377. dmac->pmap = bfin_dmac_537_pmap;
  378. dmac->pmap_count = ARRAY_SIZE (bfin_dmac_537_pmap);
  379. set_hw_ports (me, bfin_dmac_537_ports);
  380. break;
  381. case 538 ... 539:
  382. switch (dmac_num)
  383. {
  384. case 0:
  385. dmac->pmap = bfin_dmac0_538_pmap;
  386. dmac->pmap_count = ARRAY_SIZE (bfin_dmac0_538_pmap);
  387. set_hw_ports (me, bfin_dmac0_538_ports);
  388. break;
  389. case 1:
  390. dmac->pmap = bfin_dmac1_538_pmap;
  391. dmac->pmap_count = ARRAY_SIZE (bfin_dmac1_538_pmap);
  392. set_hw_ports (me, bfin_dmac1_538_ports);
  393. break;
  394. default:
  395. hw_abort (me, "this Blackfin only has a DMAC0 & DMAC1");
  396. }
  397. break;
  398. case 540 ... 549:
  399. switch (dmac_num)
  400. {
  401. case 0:
  402. dmac->pmap = bfin_dmac0_54x_pmap;
  403. dmac->pmap_count = ARRAY_SIZE (bfin_dmac0_54x_pmap);
  404. set_hw_ports (me, bfin_dmac0_54x_ports);
  405. break;
  406. case 1:
  407. dmac->pmap = bfin_dmac1_54x_pmap;
  408. dmac->pmap_count = ARRAY_SIZE (bfin_dmac1_54x_pmap);
  409. set_hw_ports (me, bfin_dmac1_54x_ports);
  410. break;
  411. default:
  412. hw_abort (me, "this Blackfin only has a DMAC0 & DMAC1");
  413. }
  414. break;
  415. case 561:
  416. switch (dmac_num)
  417. {
  418. case 0:
  419. dmac->pmap = bfin_dmac0_561_pmap;
  420. dmac->pmap_count = ARRAY_SIZE (bfin_dmac0_561_pmap);
  421. set_hw_ports (me, bfin_dmac0_561_ports);
  422. break;
  423. case 1:
  424. dmac->pmap = bfin_dmac1_561_pmap;
  425. dmac->pmap_count = ARRAY_SIZE (bfin_dmac1_561_pmap);
  426. set_hw_ports (me, bfin_dmac1_561_ports);
  427. break;
  428. default:
  429. hw_abort (me, "this Blackfin only has a DMAC0 & DMAC1");
  430. }
  431. break;
  432. case 590 ... 599:
  433. if (dmac_num != 0)
  434. hw_abort (me, "this Blackfin only has a DMAC0");
  435. dmac->pmap = bfin_dmac_59x_pmap;
  436. dmac->pmap_count = ARRAY_SIZE (bfin_dmac_59x_pmap);
  437. set_hw_ports (me, bfin_dmac_59x_ports);
  438. break;
  439. default:
  440. hw_abort (me, "no support for DMAC on this Blackfin model yet");
  441. }
  442. }
  443. const struct hw_descriptor dv_bfin_dmac_descriptor[] =
  444. {
  445. {"bfin_dmac", bfin_dmac_finish,},
  446. {NULL, NULL},
  447. };