pl330.c 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959
  1. /* linux/arch/arm/common/pl330.c
  2. *
  3. * Copyright (C) 2010 Samsung Electronics Co Ltd.
  4. * Jaswinder Singh <jassi.brar@samsung.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20. #include <linux/kernel.h>
  21. #include <linux/init.h>
  22. #include <linux/slab.h>
  23. #include <linux/module.h>
  24. #include <linux/string.h>
  25. #include <linux/io.h>
  26. #include <linux/delay.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/dma-mapping.h>
  29. #include <asm/hardware/pl330.h>
  30. /* Register and Bit field Definitions */
  31. #define DS 0x0
  32. #define DS_ST_STOP 0x0
  33. #define DS_ST_EXEC 0x1
  34. #define DS_ST_CMISS 0x2
  35. #define DS_ST_UPDTPC 0x3
  36. #define DS_ST_WFE 0x4
  37. #define DS_ST_ATBRR 0x5
  38. #define DS_ST_QBUSY 0x6
  39. #define DS_ST_WFP 0x7
  40. #define DS_ST_KILL 0x8
  41. #define DS_ST_CMPLT 0x9
  42. #define DS_ST_FLTCMP 0xe
  43. #define DS_ST_FAULT 0xf
  44. #define DPC 0x4
  45. #define INTEN 0x20
  46. #define ES 0x24
  47. #define INTSTATUS 0x28
  48. #define INTCLR 0x2c
  49. #define FSM 0x30
  50. #define FSC 0x34
  51. #define FTM 0x38
  52. #define _FTC 0x40
  53. #define FTC(n) (_FTC + (n)*0x4)
  54. #define _CS 0x100
  55. #define CS(n) (_CS + (n)*0x8)
  56. #define CS_CNS (1 << 21)
  57. #define _CPC 0x104
  58. #define CPC(n) (_CPC + (n)*0x8)
  59. #define _SA 0x400
  60. #define SA(n) (_SA + (n)*0x20)
  61. #define _DA 0x404
  62. #define DA(n) (_DA + (n)*0x20)
  63. #define _CC 0x408
  64. #define CC(n) (_CC + (n)*0x20)
  65. #define CC_SRCINC (1 << 0)
  66. #define CC_DSTINC (1 << 14)
  67. #define CC_SRCPRI (1 << 8)
  68. #define CC_DSTPRI (1 << 22)
  69. #define CC_SRCNS (1 << 9)
  70. #define CC_DSTNS (1 << 23)
  71. #define CC_SRCIA (1 << 10)
  72. #define CC_DSTIA (1 << 24)
  73. #define CC_SRCBRSTLEN_SHFT 4
  74. #define CC_DSTBRSTLEN_SHFT 18
  75. #define CC_SRCBRSTSIZE_SHFT 1
  76. #define CC_DSTBRSTSIZE_SHFT 15
  77. #define CC_SRCCCTRL_SHFT 11
  78. #define CC_SRCCCTRL_MASK 0x7
  79. #define CC_DSTCCTRL_SHFT 25
  80. #define CC_DRCCCTRL_MASK 0x7
  81. #define CC_SWAP_SHFT 28
  82. #define _LC0 0x40c
  83. #define LC0(n) (_LC0 + (n)*0x20)
  84. #define _LC1 0x410
  85. #define LC1(n) (_LC1 + (n)*0x20)
  86. #define DBGSTATUS 0xd00
  87. #define DBG_BUSY (1 << 0)
  88. #define DBGCMD 0xd04
  89. #define DBGINST0 0xd08
  90. #define DBGINST1 0xd0c
  91. #define CR0 0xe00
  92. #define CR1 0xe04
  93. #define CR2 0xe08
  94. #define CR3 0xe0c
  95. #define CR4 0xe10
  96. #define CRD 0xe14
  97. #define PERIPH_ID 0xfe0
  98. #define PCELL_ID 0xff0
  99. #define CR0_PERIPH_REQ_SET (1 << 0)
  100. #define CR0_BOOT_EN_SET (1 << 1)
  101. #define CR0_BOOT_MAN_NS (1 << 2)
  102. #define CR0_NUM_CHANS_SHIFT 4
  103. #define CR0_NUM_CHANS_MASK 0x7
  104. #define CR0_NUM_PERIPH_SHIFT 12
  105. #define CR0_NUM_PERIPH_MASK 0x1f
  106. #define CR0_NUM_EVENTS_SHIFT 17
  107. #define CR0_NUM_EVENTS_MASK 0x1f
  108. #define CR1_ICACHE_LEN_SHIFT 0
  109. #define CR1_ICACHE_LEN_MASK 0x7
  110. #define CR1_NUM_ICACHELINES_SHIFT 4
  111. #define CR1_NUM_ICACHELINES_MASK 0xf
  112. #define CRD_DATA_WIDTH_SHIFT 0
  113. #define CRD_DATA_WIDTH_MASK 0x7
  114. #define CRD_WR_CAP_SHIFT 4
  115. #define CRD_WR_CAP_MASK 0x7
  116. #define CRD_WR_Q_DEP_SHIFT 8
  117. #define CRD_WR_Q_DEP_MASK 0xf
  118. #define CRD_RD_CAP_SHIFT 12
  119. #define CRD_RD_CAP_MASK 0x7
  120. #define CRD_RD_Q_DEP_SHIFT 16
  121. #define CRD_RD_Q_DEP_MASK 0xf
  122. #define CRD_DATA_BUFF_SHIFT 20
  123. #define CRD_DATA_BUFF_MASK 0x3ff
  124. #define PART 0x330
  125. #define DESIGNER 0x41
  126. #define REVISION 0x0
  127. #define INTEG_CFG 0x0
  128. #define PERIPH_ID_VAL ((PART << 0) | (DESIGNER << 12))
  129. #define PCELL_ID_VAL 0xb105f00d
  130. #define PL330_STATE_STOPPED (1 << 0)
  131. #define PL330_STATE_EXECUTING (1 << 1)
  132. #define PL330_STATE_WFE (1 << 2)
  133. #define PL330_STATE_FAULTING (1 << 3)
  134. #define PL330_STATE_COMPLETING (1 << 4)
  135. #define PL330_STATE_WFP (1 << 5)
  136. #define PL330_STATE_KILLING (1 << 6)
  137. #define PL330_STATE_FAULT_COMPLETING (1 << 7)
  138. #define PL330_STATE_CACHEMISS (1 << 8)
  139. #define PL330_STATE_UPDTPC (1 << 9)
  140. #define PL330_STATE_ATBARRIER (1 << 10)
  141. #define PL330_STATE_QUEUEBUSY (1 << 11)
  142. #define PL330_STATE_INVALID (1 << 15)
  143. #define PL330_STABLE_STATES (PL330_STATE_STOPPED | PL330_STATE_EXECUTING \
  144. | PL330_STATE_WFE | PL330_STATE_FAULTING)
  145. #define CMD_DMAADDH 0x54
  146. #define CMD_DMAEND 0x00
  147. #define CMD_DMAFLUSHP 0x35
  148. #define CMD_DMAGO 0xa0
  149. #define CMD_DMALD 0x04
  150. #define CMD_DMALDP 0x25
  151. #define CMD_DMALP 0x20
  152. #define CMD_DMALPEND 0x28
  153. #define CMD_DMAKILL 0x01
  154. #define CMD_DMAMOV 0xbc
  155. #define CMD_DMANOP 0x18
  156. #define CMD_DMARMB 0x12
  157. #define CMD_DMASEV 0x34
  158. #define CMD_DMAST 0x08
  159. #define CMD_DMASTP 0x29
  160. #define CMD_DMASTZ 0x0c
  161. #define CMD_DMAWFE 0x36
  162. #define CMD_DMAWFP 0x30
  163. #define CMD_DMAWMB 0x13
  164. #define SZ_DMAADDH 3
  165. #define SZ_DMAEND 1
  166. #define SZ_DMAFLUSHP 2
  167. #define SZ_DMALD 1
  168. #define SZ_DMALDP 2
  169. #define SZ_DMALP 2
  170. #define SZ_DMALPEND 2
  171. #define SZ_DMAKILL 1
  172. #define SZ_DMAMOV 6
  173. #define SZ_DMANOP 1
  174. #define SZ_DMARMB 1
  175. #define SZ_DMASEV 2
  176. #define SZ_DMAST 1
  177. #define SZ_DMASTP 2
  178. #define SZ_DMASTZ 1
  179. #define SZ_DMAWFE 2
  180. #define SZ_DMAWFP 2
  181. #define SZ_DMAWMB 1
  182. #define SZ_DMAGO 6
  183. #define BRST_LEN(ccr) ((((ccr) >> CC_SRCBRSTLEN_SHFT) & 0xf) + 1)
  184. #define BRST_SIZE(ccr) (1 << (((ccr) >> CC_SRCBRSTSIZE_SHFT) & 0x7))
  185. #define BYTE_TO_BURST(b, ccr) ((b) / BRST_SIZE(ccr) / BRST_LEN(ccr))
  186. #define BURST_TO_BYTE(c, ccr) ((c) * BRST_SIZE(ccr) * BRST_LEN(ccr))
  187. /*
  188. * With 256 bytes, we can do more than 2.5MB and 5MB xfers per req
  189. * at 1byte/burst for P<->M and M<->M respectively.
  190. * For typical scenario, at 1word/burst, 10MB and 20MB xfers per req
  191. * should be enough for P<->M and M<->M respectively.
  192. */
  193. #define MCODE_BUFF_PER_REQ 256
  194. /* If the _pl330_req is available to the client */
  195. #define IS_FREE(req) (*((u8 *)((req)->mc_cpu)) == CMD_DMAEND)
  196. /* Use this _only_ to wait on transient states */
  197. #define UNTIL(t, s) while (!(_state(t) & (s))) cpu_relax();
  198. #ifdef PL330_DEBUG_MCGEN
  199. static unsigned cmd_line;
  200. #define PL330_DBGCMD_DUMP(off, x...) do { \
  201. printk("%x:", cmd_line); \
  202. printk(x); \
  203. cmd_line += off; \
  204. } while (0)
  205. #define PL330_DBGMC_START(addr) (cmd_line = addr)
  206. #else
  207. #define PL330_DBGCMD_DUMP(off, x...) do {} while (0)
  208. #define PL330_DBGMC_START(addr) do {} while (0)
  209. #endif
  210. struct _xfer_spec {
  211. u32 ccr;
  212. struct pl330_req *r;
  213. struct pl330_xfer *x;
  214. };
  215. enum dmamov_dst {
  216. SAR = 0,
  217. CCR,
  218. DAR,
  219. };
  220. enum pl330_dst {
  221. SRC = 0,
  222. DST,
  223. };
  224. enum pl330_cond {
  225. SINGLE,
  226. BURST,
  227. ALWAYS,
  228. };
  229. struct _pl330_req {
  230. u32 mc_bus;
  231. void *mc_cpu;
  232. /* Number of bytes taken to setup MC for the req */
  233. u32 mc_len;
  234. struct pl330_req *r;
  235. /* Hook to attach to DMAC's list of reqs with due callback */
  236. struct list_head rqd;
  237. };
  238. /* ToBeDone for tasklet */
  239. struct _pl330_tbd {
  240. bool reset_dmac;
  241. bool reset_mngr;
  242. u8 reset_chan;
  243. };
  244. /* A DMAC Thread */
  245. struct pl330_thread {
  246. u8 id;
  247. int ev;
  248. /* If the channel is not yet acquired by any client */
  249. bool free;
  250. /* Parent DMAC */
  251. struct pl330_dmac *dmac;
  252. /* Only two at a time */
  253. struct _pl330_req req[2];
  254. /* Index of the last enqueued request */
  255. unsigned lstenq;
  256. /* Index of the last submitted request or -1 if the DMA is stopped */
  257. int req_running;
  258. };
  259. enum pl330_dmac_state {
  260. UNINIT,
  261. INIT,
  262. DYING,
  263. };
  264. /* A DMAC */
  265. struct pl330_dmac {
  266. spinlock_t lock;
  267. /* Holds list of reqs with due callbacks */
  268. struct list_head req_done;
  269. /* Pointer to platform specific stuff */
  270. struct pl330_info *pinfo;
  271. /* Maximum possible events/irqs */
  272. int events[32];
  273. /* BUS address of MicroCode buffer */
  274. u32 mcode_bus;
  275. /* CPU address of MicroCode buffer */
  276. void *mcode_cpu;
  277. /* List of all Channel threads */
  278. struct pl330_thread *channels;
  279. /* Pointer to the MANAGER thread */
  280. struct pl330_thread *manager;
  281. /* To handle bad news in interrupt */
  282. struct tasklet_struct tasks;
  283. struct _pl330_tbd dmac_tbd;
  284. /* State of DMAC operation */
  285. enum pl330_dmac_state state;
  286. };
  287. static inline void _callback(struct pl330_req *r, enum pl330_op_err err)
  288. {
  289. if (r && r->xfer_cb)
  290. r->xfer_cb(r->token, err);
  291. }
  292. static inline bool _queue_empty(struct pl330_thread *thrd)
  293. {
  294. return (IS_FREE(&thrd->req[0]) && IS_FREE(&thrd->req[1]))
  295. ? true : false;
  296. }
  297. static inline bool _queue_full(struct pl330_thread *thrd)
  298. {
  299. return (IS_FREE(&thrd->req[0]) || IS_FREE(&thrd->req[1]))
  300. ? false : true;
  301. }
  302. static inline bool is_manager(struct pl330_thread *thrd)
  303. {
  304. struct pl330_dmac *pl330 = thrd->dmac;
  305. /* MANAGER is indexed at the end */
  306. if (thrd->id == pl330->pinfo->pcfg.num_chan)
  307. return true;
  308. else
  309. return false;
  310. }
  311. /* If manager of the thread is in Non-Secure mode */
  312. static inline bool _manager_ns(struct pl330_thread *thrd)
  313. {
  314. struct pl330_dmac *pl330 = thrd->dmac;
  315. return (pl330->pinfo->pcfg.mode & DMAC_MODE_NS) ? true : false;
  316. }
  317. static inline u32 get_id(struct pl330_info *pi, u32 off)
  318. {
  319. void __iomem *regs = pi->base;
  320. u32 id = 0;
  321. id |= (readb(regs + off + 0x0) << 0);
  322. id |= (readb(regs + off + 0x4) << 8);
  323. id |= (readb(regs + off + 0x8) << 16);
  324. id |= (readb(regs + off + 0xc) << 24);
  325. return id;
  326. }
  327. static inline u32 _emit_ADDH(unsigned dry_run, u8 buf[],
  328. enum pl330_dst da, u16 val)
  329. {
  330. if (dry_run)
  331. return SZ_DMAADDH;
  332. buf[0] = CMD_DMAADDH;
  333. buf[0] |= (da << 1);
  334. *((u16 *)&buf[1]) = val;
  335. PL330_DBGCMD_DUMP(SZ_DMAADDH, "\tDMAADDH %s %u\n",
  336. da == 1 ? "DA" : "SA", val);
  337. return SZ_DMAADDH;
  338. }
  339. static inline u32 _emit_END(unsigned dry_run, u8 buf[])
  340. {
  341. if (dry_run)
  342. return SZ_DMAEND;
  343. buf[0] = CMD_DMAEND;
  344. PL330_DBGCMD_DUMP(SZ_DMAEND, "\tDMAEND\n");
  345. return SZ_DMAEND;
  346. }
  347. static inline u32 _emit_FLUSHP(unsigned dry_run, u8 buf[], u8 peri)
  348. {
  349. if (dry_run)
  350. return SZ_DMAFLUSHP;
  351. buf[0] = CMD_DMAFLUSHP;
  352. peri &= 0x1f;
  353. peri <<= 3;
  354. buf[1] = peri;
  355. PL330_DBGCMD_DUMP(SZ_DMAFLUSHP, "\tDMAFLUSHP %u\n", peri >> 3);
  356. return SZ_DMAFLUSHP;
  357. }
  358. static inline u32 _emit_LD(unsigned dry_run, u8 buf[], enum pl330_cond cond)
  359. {
  360. if (dry_run)
  361. return SZ_DMALD;
  362. buf[0] = CMD_DMALD;
  363. if (cond == SINGLE)
  364. buf[0] |= (0 << 1) | (1 << 0);
  365. else if (cond == BURST)
  366. buf[0] |= (1 << 1) | (1 << 0);
  367. PL330_DBGCMD_DUMP(SZ_DMALD, "\tDMALD%c\n",
  368. cond == SINGLE ? 'S' : (cond == BURST ? 'B' : 'A'));
  369. return SZ_DMALD;
  370. }
  371. static inline u32 _emit_LDP(unsigned dry_run, u8 buf[],
  372. enum pl330_cond cond, u8 peri)
  373. {
  374. if (dry_run)
  375. return SZ_DMALDP;
  376. buf[0] = CMD_DMALDP;
  377. if (cond == BURST)
  378. buf[0] |= (1 << 1);
  379. peri &= 0x1f;
  380. peri <<= 3;
  381. buf[1] = peri;
  382. PL330_DBGCMD_DUMP(SZ_DMALDP, "\tDMALDP%c %u\n",
  383. cond == SINGLE ? 'S' : 'B', peri >> 3);
  384. return SZ_DMALDP;
  385. }
  386. static inline u32 _emit_LP(unsigned dry_run, u8 buf[],
  387. unsigned loop, u8 cnt)
  388. {
  389. if (dry_run)
  390. return SZ_DMALP;
  391. buf[0] = CMD_DMALP;
  392. if (loop)
  393. buf[0] |= (1 << 1);
  394. cnt--; /* DMAC increments by 1 internally */
  395. buf[1] = cnt;
  396. PL330_DBGCMD_DUMP(SZ_DMALP, "\tDMALP_%c %u\n", loop ? '1' : '0', cnt);
  397. return SZ_DMALP;
  398. }
  399. struct _arg_LPEND {
  400. enum pl330_cond cond;
  401. bool forever;
  402. unsigned loop;
  403. u8 bjump;
  404. };
  405. static inline u32 _emit_LPEND(unsigned dry_run, u8 buf[],
  406. const struct _arg_LPEND *arg)
  407. {
  408. enum pl330_cond cond = arg->cond;
  409. bool forever = arg->forever;
  410. unsigned loop = arg->loop;
  411. u8 bjump = arg->bjump;
  412. if (dry_run)
  413. return SZ_DMALPEND;
  414. buf[0] = CMD_DMALPEND;
  415. if (loop)
  416. buf[0] |= (1 << 2);
  417. if (!forever)
  418. buf[0] |= (1 << 4);
  419. if (cond == SINGLE)
  420. buf[0] |= (0 << 1) | (1 << 0);
  421. else if (cond == BURST)
  422. buf[0] |= (1 << 1) | (1 << 0);
  423. buf[1] = bjump;
  424. PL330_DBGCMD_DUMP(SZ_DMALPEND, "\tDMALP%s%c_%c bjmpto_%x\n",
  425. forever ? "FE" : "END",
  426. cond == SINGLE ? 'S' : (cond == BURST ? 'B' : 'A'),
  427. loop ? '1' : '0',
  428. bjump);
  429. return SZ_DMALPEND;
  430. }
  431. static inline u32 _emit_KILL(unsigned dry_run, u8 buf[])
  432. {
  433. if (dry_run)
  434. return SZ_DMAKILL;
  435. buf[0] = CMD_DMAKILL;
  436. return SZ_DMAKILL;
  437. }
  438. static inline u32 _emit_MOV(unsigned dry_run, u8 buf[],
  439. enum dmamov_dst dst, u32 val)
  440. {
  441. if (dry_run)
  442. return SZ_DMAMOV;
  443. buf[0] = CMD_DMAMOV;
  444. buf[1] = dst;
  445. *((u32 *)&buf[2]) = val;
  446. PL330_DBGCMD_DUMP(SZ_DMAMOV, "\tDMAMOV %s 0x%x\n",
  447. dst == SAR ? "SAR" : (dst == DAR ? "DAR" : "CCR"), val);
  448. return SZ_DMAMOV;
  449. }
  450. static inline u32 _emit_NOP(unsigned dry_run, u8 buf[])
  451. {
  452. if (dry_run)
  453. return SZ_DMANOP;
  454. buf[0] = CMD_DMANOP;
  455. PL330_DBGCMD_DUMP(SZ_DMANOP, "\tDMANOP\n");
  456. return SZ_DMANOP;
  457. }
  458. static inline u32 _emit_RMB(unsigned dry_run, u8 buf[])
  459. {
  460. if (dry_run)
  461. return SZ_DMARMB;
  462. buf[0] = CMD_DMARMB;
  463. PL330_DBGCMD_DUMP(SZ_DMARMB, "\tDMARMB\n");
  464. return SZ_DMARMB;
  465. }
  466. static inline u32 _emit_SEV(unsigned dry_run, u8 buf[], u8 ev)
  467. {
  468. if (dry_run)
  469. return SZ_DMASEV;
  470. buf[0] = CMD_DMASEV;
  471. ev &= 0x1f;
  472. ev <<= 3;
  473. buf[1] = ev;
  474. PL330_DBGCMD_DUMP(SZ_DMASEV, "\tDMASEV %u\n", ev >> 3);
  475. return SZ_DMASEV;
  476. }
  477. static inline u32 _emit_ST(unsigned dry_run, u8 buf[], enum pl330_cond cond)
  478. {
  479. if (dry_run)
  480. return SZ_DMAST;
  481. buf[0] = CMD_DMAST;
  482. if (cond == SINGLE)
  483. buf[0] |= (0 << 1) | (1 << 0);
  484. else if (cond == BURST)
  485. buf[0] |= (1 << 1) | (1 << 0);
  486. PL330_DBGCMD_DUMP(SZ_DMAST, "\tDMAST%c\n",
  487. cond == SINGLE ? 'S' : (cond == BURST ? 'B' : 'A'));
  488. return SZ_DMAST;
  489. }
  490. static inline u32 _emit_STP(unsigned dry_run, u8 buf[],
  491. enum pl330_cond cond, u8 peri)
  492. {
  493. if (dry_run)
  494. return SZ_DMASTP;
  495. buf[0] = CMD_DMASTP;
  496. if (cond == BURST)
  497. buf[0] |= (1 << 1);
  498. peri &= 0x1f;
  499. peri <<= 3;
  500. buf[1] = peri;
  501. PL330_DBGCMD_DUMP(SZ_DMASTP, "\tDMASTP%c %u\n",
  502. cond == SINGLE ? 'S' : 'B', peri >> 3);
  503. return SZ_DMASTP;
  504. }
  505. static inline u32 _emit_STZ(unsigned dry_run, u8 buf[])
  506. {
  507. if (dry_run)
  508. return SZ_DMASTZ;
  509. buf[0] = CMD_DMASTZ;
  510. PL330_DBGCMD_DUMP(SZ_DMASTZ, "\tDMASTZ\n");
  511. return SZ_DMASTZ;
  512. }
  513. static inline u32 _emit_WFE(unsigned dry_run, u8 buf[], u8 ev,
  514. unsigned invalidate)
  515. {
  516. if (dry_run)
  517. return SZ_DMAWFE;
  518. buf[0] = CMD_DMAWFE;
  519. ev &= 0x1f;
  520. ev <<= 3;
  521. buf[1] = ev;
  522. if (invalidate)
  523. buf[1] |= (1 << 1);
  524. PL330_DBGCMD_DUMP(SZ_DMAWFE, "\tDMAWFE %u%s\n",
  525. ev >> 3, invalidate ? ", I" : "");
  526. return SZ_DMAWFE;
  527. }
  528. static inline u32 _emit_WFP(unsigned dry_run, u8 buf[],
  529. enum pl330_cond cond, u8 peri)
  530. {
  531. if (dry_run)
  532. return SZ_DMAWFP;
  533. buf[0] = CMD_DMAWFP;
  534. if (cond == SINGLE)
  535. buf[0] |= (0 << 1) | (0 << 0);
  536. else if (cond == BURST)
  537. buf[0] |= (1 << 1) | (0 << 0);
  538. else
  539. buf[0] |= (0 << 1) | (1 << 0);
  540. peri &= 0x1f;
  541. peri <<= 3;
  542. buf[1] = peri;
  543. PL330_DBGCMD_DUMP(SZ_DMAWFP, "\tDMAWFP%c %u\n",
  544. cond == SINGLE ? 'S' : (cond == BURST ? 'B' : 'P'), peri >> 3);
  545. return SZ_DMAWFP;
  546. }
  547. static inline u32 _emit_WMB(unsigned dry_run, u8 buf[])
  548. {
  549. if (dry_run)
  550. return SZ_DMAWMB;
  551. buf[0] = CMD_DMAWMB;
  552. PL330_DBGCMD_DUMP(SZ_DMAWMB, "\tDMAWMB\n");
  553. return SZ_DMAWMB;
  554. }
  555. struct _arg_GO {
  556. u8 chan;
  557. u32 addr;
  558. unsigned ns;
  559. };
  560. static inline u32 _emit_GO(unsigned dry_run, u8 buf[],
  561. const struct _arg_GO *arg)
  562. {
  563. u8 chan = arg->chan;
  564. u32 addr = arg->addr;
  565. unsigned ns = arg->ns;
  566. if (dry_run)
  567. return SZ_DMAGO;
  568. buf[0] = CMD_DMAGO;
  569. buf[0] |= (ns << 1);
  570. buf[1] = chan & 0x7;
  571. *((u32 *)&buf[2]) = addr;
  572. return SZ_DMAGO;
  573. }
  574. #define msecs_to_loops(t) (loops_per_jiffy / 1000 * HZ * t)
  575. /* Returns Time-Out */
  576. static bool _until_dmac_idle(struct pl330_thread *thrd)
  577. {
  578. void __iomem *regs = thrd->dmac->pinfo->base;
  579. unsigned long loops = msecs_to_loops(5);
  580. do {
  581. /* Until Manager is Idle */
  582. if (!(readl(regs + DBGSTATUS) & DBG_BUSY))
  583. break;
  584. cpu_relax();
  585. } while (--loops);
  586. if (!loops)
  587. return true;
  588. return false;
  589. }
  590. static inline void _execute_DBGINSN(struct pl330_thread *thrd,
  591. u8 insn[], bool as_manager)
  592. {
  593. void __iomem *regs = thrd->dmac->pinfo->base;
  594. u32 val;
  595. val = (insn[0] << 16) | (insn[1] << 24);
  596. if (!as_manager) {
  597. val |= (1 << 0);
  598. val |= (thrd->id << 8); /* Channel Number */
  599. }
  600. writel(val, regs + DBGINST0);
  601. val = *((u32 *)&insn[2]);
  602. writel(val, regs + DBGINST1);
  603. /* If timed out due to halted state-machine */
  604. if (_until_dmac_idle(thrd)) {
  605. dev_err(thrd->dmac->pinfo->dev, "DMAC halted!\n");
  606. return;
  607. }
  608. /* Get going */
  609. writel(0, regs + DBGCMD);
  610. }
  611. /*
  612. * Mark a _pl330_req as free.
  613. * We do it by writing DMAEND as the first instruction
  614. * because no valid request is going to have DMAEND as
  615. * its first instruction to execute.
  616. */
  617. static void mark_free(struct pl330_thread *thrd, int idx)
  618. {
  619. struct _pl330_req *req = &thrd->req[idx];
  620. _emit_END(0, req->mc_cpu);
  621. req->mc_len = 0;
  622. thrd->req_running = -1;
  623. }
  624. static inline u32 _state(struct pl330_thread *thrd)
  625. {
  626. void __iomem *regs = thrd->dmac->pinfo->base;
  627. u32 val;
  628. if (is_manager(thrd))
  629. val = readl(regs + DS) & 0xf;
  630. else
  631. val = readl(regs + CS(thrd->id)) & 0xf;
  632. switch (val) {
  633. case DS_ST_STOP:
  634. return PL330_STATE_STOPPED;
  635. case DS_ST_EXEC:
  636. return PL330_STATE_EXECUTING;
  637. case DS_ST_CMISS:
  638. return PL330_STATE_CACHEMISS;
  639. case DS_ST_UPDTPC:
  640. return PL330_STATE_UPDTPC;
  641. case DS_ST_WFE:
  642. return PL330_STATE_WFE;
  643. case DS_ST_FAULT:
  644. return PL330_STATE_FAULTING;
  645. case DS_ST_ATBRR:
  646. if (is_manager(thrd))
  647. return PL330_STATE_INVALID;
  648. else
  649. return PL330_STATE_ATBARRIER;
  650. case DS_ST_QBUSY:
  651. if (is_manager(thrd))
  652. return PL330_STATE_INVALID;
  653. else
  654. return PL330_STATE_QUEUEBUSY;
  655. case DS_ST_WFP:
  656. if (is_manager(thrd))
  657. return PL330_STATE_INVALID;
  658. else
  659. return PL330_STATE_WFP;
  660. case DS_ST_KILL:
  661. if (is_manager(thrd))
  662. return PL330_STATE_INVALID;
  663. else
  664. return PL330_STATE_KILLING;
  665. case DS_ST_CMPLT:
  666. if (is_manager(thrd))
  667. return PL330_STATE_INVALID;
  668. else
  669. return PL330_STATE_COMPLETING;
  670. case DS_ST_FLTCMP:
  671. if (is_manager(thrd))
  672. return PL330_STATE_INVALID;
  673. else
  674. return PL330_STATE_FAULT_COMPLETING;
  675. default:
  676. return PL330_STATE_INVALID;
  677. }
  678. }
  679. static void _stop(struct pl330_thread *thrd)
  680. {
  681. void __iomem *regs = thrd->dmac->pinfo->base;
  682. u8 insn[6] = {0, 0, 0, 0, 0, 0};
  683. if (_state(thrd) == PL330_STATE_FAULT_COMPLETING)
  684. UNTIL(thrd, PL330_STATE_FAULTING | PL330_STATE_KILLING);
  685. /* Return if nothing needs to be done */
  686. if (_state(thrd) == PL330_STATE_COMPLETING
  687. || _state(thrd) == PL330_STATE_KILLING
  688. || _state(thrd) == PL330_STATE_STOPPED)
  689. return;
  690. _emit_KILL(0, insn);
  691. /* Stop generating interrupts for SEV */
  692. writel(readl(regs + INTEN) & ~(1 << thrd->ev), regs + INTEN);
  693. _execute_DBGINSN(thrd, insn, is_manager(thrd));
  694. }
  695. /* Start doing req 'idx' of thread 'thrd' */
  696. static bool _trigger(struct pl330_thread *thrd)
  697. {
  698. void __iomem *regs = thrd->dmac->pinfo->base;
  699. struct _pl330_req *req;
  700. struct pl330_req *r;
  701. struct _arg_GO go;
  702. unsigned ns;
  703. u8 insn[6] = {0, 0, 0, 0, 0, 0};
  704. int idx;
  705. /* Return if already ACTIVE */
  706. if (_state(thrd) != PL330_STATE_STOPPED)
  707. return true;
  708. idx = 1 - thrd->lstenq;
  709. if (!IS_FREE(&thrd->req[idx]))
  710. req = &thrd->req[idx];
  711. else {
  712. idx = thrd->lstenq;
  713. if (!IS_FREE(&thrd->req[idx]))
  714. req = &thrd->req[idx];
  715. else
  716. req = NULL;
  717. }
  718. /* Return if no request */
  719. if (!req || !req->r)
  720. return true;
  721. r = req->r;
  722. if (r->cfg)
  723. ns = r->cfg->nonsecure ? 1 : 0;
  724. else if (readl(regs + CS(thrd->id)) & CS_CNS)
  725. ns = 1;
  726. else
  727. ns = 0;
  728. /* See 'Abort Sources' point-4 at Page 2-25 */
  729. if (_manager_ns(thrd) && !ns)
  730. dev_info(thrd->dmac->pinfo->dev, "%s:%d Recipe for ABORT!\n",
  731. __func__, __LINE__);
  732. go.chan = thrd->id;
  733. go.addr = req->mc_bus;
  734. go.ns = ns;
  735. _emit_GO(0, insn, &go);
  736. /* Set to generate interrupts for SEV */
  737. writel(readl(regs + INTEN) | (1 << thrd->ev), regs + INTEN);
  738. /* Only manager can execute GO */
  739. _execute_DBGINSN(thrd, insn, true);
  740. thrd->req_running = idx;
  741. return true;
  742. }
  743. static bool _start(struct pl330_thread *thrd)
  744. {
  745. switch (_state(thrd)) {
  746. case PL330_STATE_FAULT_COMPLETING:
  747. UNTIL(thrd, PL330_STATE_FAULTING | PL330_STATE_KILLING);
  748. if (_state(thrd) == PL330_STATE_KILLING)
  749. UNTIL(thrd, PL330_STATE_STOPPED)
  750. case PL330_STATE_FAULTING:
  751. _stop(thrd);
  752. case PL330_STATE_KILLING:
  753. case PL330_STATE_COMPLETING:
  754. UNTIL(thrd, PL330_STATE_STOPPED)
  755. case PL330_STATE_STOPPED:
  756. return _trigger(thrd);
  757. case PL330_STATE_WFP:
  758. case PL330_STATE_QUEUEBUSY:
  759. case PL330_STATE_ATBARRIER:
  760. case PL330_STATE_UPDTPC:
  761. case PL330_STATE_CACHEMISS:
  762. case PL330_STATE_EXECUTING:
  763. return true;
  764. case PL330_STATE_WFE: /* For RESUME, nothing yet */
  765. default:
  766. return false;
  767. }
  768. }
  769. static inline int _ldst_memtomem(unsigned dry_run, u8 buf[],
  770. const struct _xfer_spec *pxs, int cyc)
  771. {
  772. int off = 0;
  773. while (cyc--) {
  774. off += _emit_LD(dry_run, &buf[off], ALWAYS);
  775. off += _emit_RMB(dry_run, &buf[off]);
  776. off += _emit_ST(dry_run, &buf[off], ALWAYS);
  777. off += _emit_WMB(dry_run, &buf[off]);
  778. }
  779. return off;
  780. }
  781. static inline int _ldst_devtomem(unsigned dry_run, u8 buf[],
  782. const struct _xfer_spec *pxs, int cyc)
  783. {
  784. int off = 0;
  785. while (cyc--) {
  786. off += _emit_WFP(dry_run, &buf[off], SINGLE, pxs->r->peri);
  787. off += _emit_LDP(dry_run, &buf[off], SINGLE, pxs->r->peri);
  788. off += _emit_ST(dry_run, &buf[off], ALWAYS);
  789. off += _emit_FLUSHP(dry_run, &buf[off], pxs->r->peri);
  790. }
  791. return off;
  792. }
  793. static inline int _ldst_memtodev(unsigned dry_run, u8 buf[],
  794. const struct _xfer_spec *pxs, int cyc)
  795. {
  796. int off = 0;
  797. while (cyc--) {
  798. off += _emit_WFP(dry_run, &buf[off], SINGLE, pxs->r->peri);
  799. off += _emit_LD(dry_run, &buf[off], ALWAYS);
  800. off += _emit_STP(dry_run, &buf[off], SINGLE, pxs->r->peri);
  801. off += _emit_FLUSHP(dry_run, &buf[off], pxs->r->peri);
  802. }
  803. return off;
  804. }
  805. static int _bursts(unsigned dry_run, u8 buf[],
  806. const struct _xfer_spec *pxs, int cyc)
  807. {
  808. int off = 0;
  809. switch (pxs->r->rqtype) {
  810. case MEMTODEV:
  811. off += _ldst_memtodev(dry_run, &buf[off], pxs, cyc);
  812. break;
  813. case DEVTOMEM:
  814. off += _ldst_devtomem(dry_run, &buf[off], pxs, cyc);
  815. break;
  816. case MEMTOMEM:
  817. off += _ldst_memtomem(dry_run, &buf[off], pxs, cyc);
  818. break;
  819. default:
  820. off += 0x40000000; /* Scare off the Client */
  821. break;
  822. }
  823. return off;
  824. }
  825. /* Returns bytes consumed and updates bursts */
  826. static inline int _loop(unsigned dry_run, u8 buf[],
  827. unsigned long *bursts, const struct _xfer_spec *pxs)
  828. {
  829. int cyc, cycmax, szlp, szlpend, szbrst, off;
  830. unsigned lcnt0, lcnt1, ljmp0, ljmp1;
  831. struct _arg_LPEND lpend;
  832. /* Max iterations possible in DMALP is 256 */
  833. if (*bursts >= 256*256) {
  834. lcnt1 = 256;
  835. lcnt0 = 256;
  836. cyc = *bursts / lcnt1 / lcnt0;
  837. } else if (*bursts > 256) {
  838. lcnt1 = 256;
  839. lcnt0 = *bursts / lcnt1;
  840. cyc = 1;
  841. } else {
  842. lcnt1 = *bursts;
  843. lcnt0 = 0;
  844. cyc = 1;
  845. }
  846. szlp = _emit_LP(1, buf, 0, 0);
  847. szbrst = _bursts(1, buf, pxs, 1);
  848. lpend.cond = ALWAYS;
  849. lpend.forever = false;
  850. lpend.loop = 0;
  851. lpend.bjump = 0;
  852. szlpend = _emit_LPEND(1, buf, &lpend);
  853. if (lcnt0) {
  854. szlp *= 2;
  855. szlpend *= 2;
  856. }
  857. /*
  858. * Max bursts that we can unroll due to limit on the
  859. * size of backward jump that can be encoded in DMALPEND
  860. * which is 8-bits and hence 255
  861. */
  862. cycmax = (255 - (szlp + szlpend)) / szbrst;
  863. cyc = (cycmax < cyc) ? cycmax : cyc;
  864. off = 0;
  865. if (lcnt0) {
  866. off += _emit_LP(dry_run, &buf[off], 0, lcnt0);
  867. ljmp0 = off;
  868. }
  869. off += _emit_LP(dry_run, &buf[off], 1, lcnt1);
  870. ljmp1 = off;
  871. off += _bursts(dry_run, &buf[off], pxs, cyc);
  872. lpend.cond = ALWAYS;
  873. lpend.forever = false;
  874. lpend.loop = 1;
  875. lpend.bjump = off - ljmp1;
  876. off += _emit_LPEND(dry_run, &buf[off], &lpend);
  877. if (lcnt0) {
  878. lpend.cond = ALWAYS;
  879. lpend.forever = false;
  880. lpend.loop = 0;
  881. lpend.bjump = off - ljmp0;
  882. off += _emit_LPEND(dry_run, &buf[off], &lpend);
  883. }
  884. *bursts = lcnt1 * cyc;
  885. if (lcnt0)
  886. *bursts *= lcnt0;
  887. return off;
  888. }
  889. static inline int _setup_loops(unsigned dry_run, u8 buf[],
  890. const struct _xfer_spec *pxs)
  891. {
  892. struct pl330_xfer *x = pxs->x;
  893. u32 ccr = pxs->ccr;
  894. unsigned long c, bursts = BYTE_TO_BURST(x->bytes, ccr);
  895. int off = 0;
  896. while (bursts) {
  897. c = bursts;
  898. off += _loop(dry_run, &buf[off], &c, pxs);
  899. bursts -= c;
  900. }
  901. return off;
  902. }
  903. static inline int _setup_xfer(unsigned dry_run, u8 buf[],
  904. const struct _xfer_spec *pxs)
  905. {
  906. struct pl330_xfer *x = pxs->x;
  907. int off = 0;
  908. /* DMAMOV SAR, x->src_addr */
  909. off += _emit_MOV(dry_run, &buf[off], SAR, x->src_addr);
  910. /* DMAMOV DAR, x->dst_addr */
  911. off += _emit_MOV(dry_run, &buf[off], DAR, x->dst_addr);
  912. /* Setup Loop(s) */
  913. off += _setup_loops(dry_run, &buf[off], pxs);
  914. return off;
  915. }
  916. /*
  917. * A req is a sequence of one or more xfer units.
  918. * Returns the number of bytes taken to setup the MC for the req.
  919. */
  920. static int _setup_req(unsigned dry_run, struct pl330_thread *thrd,
  921. unsigned index, struct _xfer_spec *pxs)
  922. {
  923. struct _pl330_req *req = &thrd->req[index];
  924. struct pl330_xfer *x;
  925. u8 *buf = req->mc_cpu;
  926. int off = 0;
  927. PL330_DBGMC_START(req->mc_bus);
  928. /* DMAMOV CCR, ccr */
  929. off += _emit_MOV(dry_run, &buf[off], CCR, pxs->ccr);
  930. x = pxs->r->x;
  931. do {
  932. /* Error if xfer length is not aligned at burst size */
  933. if (x->bytes % (BRST_SIZE(pxs->ccr) * BRST_LEN(pxs->ccr)))
  934. return -EINVAL;
  935. pxs->x = x;
  936. off += _setup_xfer(dry_run, &buf[off], pxs);
  937. x = x->next;
  938. } while (x);
  939. /* DMASEV peripheral/event */
  940. off += _emit_SEV(dry_run, &buf[off], thrd->ev);
  941. /* DMAEND */
  942. off += _emit_END(dry_run, &buf[off]);
  943. return off;
  944. }
  945. static inline u32 _prepare_ccr(const struct pl330_reqcfg *rqc)
  946. {
  947. u32 ccr = 0;
  948. if (rqc->src_inc)
  949. ccr |= CC_SRCINC;
  950. if (rqc->dst_inc)
  951. ccr |= CC_DSTINC;
  952. /* We set same protection levels for Src and DST for now */
  953. if (rqc->privileged)
  954. ccr |= CC_SRCPRI | CC_DSTPRI;
  955. if (rqc->nonsecure)
  956. ccr |= CC_SRCNS | CC_DSTNS;
  957. if (rqc->insnaccess)
  958. ccr |= CC_SRCIA | CC_DSTIA;
  959. ccr |= (((rqc->brst_len - 1) & 0xf) << CC_SRCBRSTLEN_SHFT);
  960. ccr |= (((rqc->brst_len - 1) & 0xf) << CC_DSTBRSTLEN_SHFT);
  961. ccr |= (rqc->brst_size << CC_SRCBRSTSIZE_SHFT);
  962. ccr |= (rqc->brst_size << CC_DSTBRSTSIZE_SHFT);
  963. ccr |= (rqc->scctl << CC_SRCCCTRL_SHFT);
  964. ccr |= (rqc->dcctl << CC_DSTCCTRL_SHFT);
  965. ccr |= (rqc->swap << CC_SWAP_SHFT);
  966. return ccr;
  967. }
  968. static inline bool _is_valid(u32 ccr)
  969. {
  970. enum pl330_dstcachectrl dcctl;
  971. enum pl330_srccachectrl scctl;
  972. dcctl = (ccr >> CC_DSTCCTRL_SHFT) & CC_DRCCCTRL_MASK;
  973. scctl = (ccr >> CC_SRCCCTRL_SHFT) & CC_SRCCCTRL_MASK;
  974. if (dcctl == DINVALID1 || dcctl == DINVALID2
  975. || scctl == SINVALID1 || scctl == SINVALID2)
  976. return false;
  977. else
  978. return true;
  979. }
  980. /*
  981. * Submit a list of xfers after which the client wants notification.
  982. * Client is not notified after each xfer unit, just once after all
  983. * xfer units are done or some error occurs.
  984. */
  985. int pl330_submit_req(void *ch_id, struct pl330_req *r)
  986. {
  987. struct pl330_thread *thrd = ch_id;
  988. struct pl330_dmac *pl330;
  989. struct pl330_info *pi;
  990. struct _xfer_spec xs;
  991. unsigned long flags;
  992. void __iomem *regs;
  993. unsigned idx;
  994. u32 ccr;
  995. int ret = 0;
  996. /* No Req or Unacquired Channel or DMAC */
  997. if (!r || !thrd || thrd->free)
  998. return -EINVAL;
  999. pl330 = thrd->dmac;
  1000. pi = pl330->pinfo;
  1001. regs = pi->base;
  1002. if (pl330->state == DYING
  1003. || pl330->dmac_tbd.reset_chan & (1 << thrd->id)) {
  1004. dev_info(thrd->dmac->pinfo->dev, "%s:%d\n",
  1005. __func__, __LINE__);
  1006. return -EAGAIN;
  1007. }
  1008. /* If request for non-existing peripheral */
  1009. if (r->rqtype != MEMTOMEM && r->peri >= pi->pcfg.num_peri) {
  1010. dev_info(thrd->dmac->pinfo->dev,
  1011. "%s:%d Invalid peripheral(%u)!\n",
  1012. __func__, __LINE__, r->peri);
  1013. return -EINVAL;
  1014. }
  1015. spin_lock_irqsave(&pl330->lock, flags);
  1016. if (_queue_full(thrd)) {
  1017. ret = -EAGAIN;
  1018. goto xfer_exit;
  1019. }
  1020. /* Prefer Secure Channel */
  1021. if (!_manager_ns(thrd))
  1022. r->cfg->nonsecure = 0;
  1023. else
  1024. r->cfg->nonsecure = 1;
  1025. /* Use last settings, if not provided */
  1026. if (r->cfg)
  1027. ccr = _prepare_ccr(r->cfg);
  1028. else
  1029. ccr = readl(regs + CC(thrd->id));
  1030. /* If this req doesn't have valid xfer settings */
  1031. if (!_is_valid(ccr)) {
  1032. ret = -EINVAL;
  1033. dev_info(thrd->dmac->pinfo->dev, "%s:%d Invalid CCR(%x)!\n",
  1034. __func__, __LINE__, ccr);
  1035. goto xfer_exit;
  1036. }
  1037. idx = IS_FREE(&thrd->req[0]) ? 0 : 1;
  1038. xs.ccr = ccr;
  1039. xs.r = r;
  1040. /* First dry run to check if req is acceptable */
  1041. ret = _setup_req(1, thrd, idx, &xs);
  1042. if (ret < 0)
  1043. goto xfer_exit;
  1044. if (ret > pi->mcbufsz / 2) {
  1045. dev_info(thrd->dmac->pinfo->dev,
  1046. "%s:%d Trying increasing mcbufsz\n",
  1047. __func__, __LINE__);
  1048. ret = -ENOMEM;
  1049. goto xfer_exit;
  1050. }
  1051. /* Hook the request */
  1052. thrd->lstenq = idx;
  1053. thrd->req[idx].mc_len = _setup_req(0, thrd, idx, &xs);
  1054. thrd->req[idx].r = r;
  1055. ret = 0;
  1056. xfer_exit:
  1057. spin_unlock_irqrestore(&pl330->lock, flags);
  1058. return ret;
  1059. }
  1060. EXPORT_SYMBOL(pl330_submit_req);
  1061. static void pl330_dotask(unsigned long data)
  1062. {
  1063. struct pl330_dmac *pl330 = (struct pl330_dmac *) data;
  1064. struct pl330_info *pi = pl330->pinfo;
  1065. unsigned long flags;
  1066. int i;
  1067. spin_lock_irqsave(&pl330->lock, flags);
  1068. /* The DMAC itself gone nuts */
  1069. if (pl330->dmac_tbd.reset_dmac) {
  1070. pl330->state = DYING;
  1071. /* Reset the manager too */
  1072. pl330->dmac_tbd.reset_mngr = true;
  1073. /* Clear the reset flag */
  1074. pl330->dmac_tbd.reset_dmac = false;
  1075. }
  1076. if (pl330->dmac_tbd.reset_mngr) {
  1077. _stop(pl330->manager);
  1078. /* Reset all channels */
  1079. pl330->dmac_tbd.reset_chan = (1 << pi->pcfg.num_chan) - 1;
  1080. /* Clear the reset flag */
  1081. pl330->dmac_tbd.reset_mngr = false;
  1082. }
  1083. for (i = 0; i < pi->pcfg.num_chan; i++) {
  1084. if (pl330->dmac_tbd.reset_chan & (1 << i)) {
  1085. struct pl330_thread *thrd = &pl330->channels[i];
  1086. void __iomem *regs = pi->base;
  1087. enum pl330_op_err err;
  1088. _stop(thrd);
  1089. if (readl(regs + FSC) & (1 << thrd->id))
  1090. err = PL330_ERR_FAIL;
  1091. else
  1092. err = PL330_ERR_ABORT;
  1093. spin_unlock_irqrestore(&pl330->lock, flags);
  1094. _callback(thrd->req[1 - thrd->lstenq].r, err);
  1095. _callback(thrd->req[thrd->lstenq].r, err);
  1096. spin_lock_irqsave(&pl330->lock, flags);
  1097. thrd->req[0].r = NULL;
  1098. thrd->req[1].r = NULL;
  1099. mark_free(thrd, 0);
  1100. mark_free(thrd, 1);
  1101. /* Clear the reset flag */
  1102. pl330->dmac_tbd.reset_chan &= ~(1 << i);
  1103. }
  1104. }
  1105. spin_unlock_irqrestore(&pl330->lock, flags);
  1106. return;
  1107. }
  1108. /* Returns 1 if state was updated, 0 otherwise */
  1109. int pl330_update(const struct pl330_info *pi)
  1110. {
  1111. struct _pl330_req *rqdone;
  1112. struct pl330_dmac *pl330;
  1113. unsigned long flags;
  1114. void __iomem *regs;
  1115. u32 val;
  1116. int id, ev, ret = 0;
  1117. if (!pi || !pi->pl330_data)
  1118. return 0;
  1119. regs = pi->base;
  1120. pl330 = pi->pl330_data;
  1121. spin_lock_irqsave(&pl330->lock, flags);
  1122. val = readl(regs + FSM) & 0x1;
  1123. if (val)
  1124. pl330->dmac_tbd.reset_mngr = true;
  1125. else
  1126. pl330->dmac_tbd.reset_mngr = false;
  1127. val = readl(regs + FSC) & ((1 << pi->pcfg.num_chan) - 1);
  1128. pl330->dmac_tbd.reset_chan |= val;
  1129. if (val) {
  1130. int i = 0;
  1131. while (i < pi->pcfg.num_chan) {
  1132. if (val & (1 << i)) {
  1133. dev_info(pi->dev,
  1134. "Reset Channel-%d\t CS-%x FTC-%x\n",
  1135. i, readl(regs + CS(i)),
  1136. readl(regs + FTC(i)));
  1137. _stop(&pl330->channels[i]);
  1138. }
  1139. i++;
  1140. }
  1141. }
  1142. /* Check which event happened i.e, thread notified */
  1143. val = readl(regs + ES);
  1144. if (pi->pcfg.num_events < 32
  1145. && val & ~((1 << pi->pcfg.num_events) - 1)) {
  1146. pl330->dmac_tbd.reset_dmac = true;
  1147. dev_err(pi->dev, "%s:%d Unexpected!\n", __func__, __LINE__);
  1148. ret = 1;
  1149. goto updt_exit;
  1150. }
  1151. for (ev = 0; ev < pi->pcfg.num_events; ev++) {
  1152. if (val & (1 << ev)) { /* Event occurred */
  1153. struct pl330_thread *thrd;
  1154. u32 inten = readl(regs + INTEN);
  1155. int active;
  1156. /* Clear the event */
  1157. if (inten & (1 << ev))
  1158. writel(1 << ev, regs + INTCLR);
  1159. ret = 1;
  1160. id = pl330->events[ev];
  1161. thrd = &pl330->channels[id];
  1162. active = thrd->req_running;
  1163. if (active == -1) /* Aborted */
  1164. continue;
  1165. rqdone = &thrd->req[active];
  1166. mark_free(thrd, active);
  1167. /* Get going again ASAP */
  1168. _start(thrd);
  1169. /* For now, just make a list of callbacks to be done */
  1170. list_add_tail(&rqdone->rqd, &pl330->req_done);
  1171. }
  1172. }
  1173. /* Now that we are in no hurry, do the callbacks */
  1174. while (!list_empty(&pl330->req_done)) {
  1175. struct pl330_req *r;
  1176. rqdone = container_of(pl330->req_done.next,
  1177. struct _pl330_req, rqd);
  1178. list_del_init(&rqdone->rqd);
  1179. /* Detach the req */
  1180. r = rqdone->r;
  1181. rqdone->r = NULL;
  1182. spin_unlock_irqrestore(&pl330->lock, flags);
  1183. _callback(r, PL330_ERR_NONE);
  1184. spin_lock_irqsave(&pl330->lock, flags);
  1185. }
  1186. updt_exit:
  1187. spin_unlock_irqrestore(&pl330->lock, flags);
  1188. if (pl330->dmac_tbd.reset_dmac
  1189. || pl330->dmac_tbd.reset_mngr
  1190. || pl330->dmac_tbd.reset_chan) {
  1191. ret = 1;
  1192. tasklet_schedule(&pl330->tasks);
  1193. }
  1194. return ret;
  1195. }
  1196. EXPORT_SYMBOL(pl330_update);
  1197. int pl330_chan_ctrl(void *ch_id, enum pl330_chan_op op)
  1198. {
  1199. struct pl330_thread *thrd = ch_id;
  1200. struct pl330_dmac *pl330;
  1201. unsigned long flags;
  1202. int ret = 0, active = thrd->req_running;
  1203. if (!thrd || thrd->free || thrd->dmac->state == DYING)
  1204. return -EINVAL;
  1205. pl330 = thrd->dmac;
  1206. spin_lock_irqsave(&pl330->lock, flags);
  1207. switch (op) {
  1208. case PL330_OP_FLUSH:
  1209. /* Make sure the channel is stopped */
  1210. _stop(thrd);
  1211. thrd->req[0].r = NULL;
  1212. thrd->req[1].r = NULL;
  1213. mark_free(thrd, 0);
  1214. mark_free(thrd, 1);
  1215. break;
  1216. case PL330_OP_ABORT:
  1217. /* Make sure the channel is stopped */
  1218. _stop(thrd);
  1219. /* ABORT is only for the active req */
  1220. if (active == -1)
  1221. break;
  1222. thrd->req[active].r = NULL;
  1223. mark_free(thrd, active);
  1224. /* Start the next */
  1225. case PL330_OP_START:
  1226. if ((active == -1) && !_start(thrd))
  1227. ret = -EIO;
  1228. break;
  1229. default:
  1230. ret = -EINVAL;
  1231. }
  1232. spin_unlock_irqrestore(&pl330->lock, flags);
  1233. return ret;
  1234. }
  1235. EXPORT_SYMBOL(pl330_chan_ctrl);
  1236. int pl330_chan_status(void *ch_id, struct pl330_chanstatus *pstatus)
  1237. {
  1238. struct pl330_thread *thrd = ch_id;
  1239. struct pl330_dmac *pl330;
  1240. struct pl330_info *pi;
  1241. void __iomem *regs;
  1242. int active;
  1243. u32 val;
  1244. if (!pstatus || !thrd || thrd->free)
  1245. return -EINVAL;
  1246. pl330 = thrd->dmac;
  1247. pi = pl330->pinfo;
  1248. regs = pi->base;
  1249. /* The client should remove the DMAC and add again */
  1250. if (pl330->state == DYING)
  1251. pstatus->dmac_halted = true;
  1252. else
  1253. pstatus->dmac_halted = false;
  1254. val = readl(regs + FSC);
  1255. if (val & (1 << thrd->id))
  1256. pstatus->faulting = true;
  1257. else
  1258. pstatus->faulting = false;
  1259. active = thrd->req_running;
  1260. if (active == -1) {
  1261. /* Indicate that the thread is not running */
  1262. pstatus->top_req = NULL;
  1263. pstatus->wait_req = NULL;
  1264. } else {
  1265. pstatus->top_req = thrd->req[active].r;
  1266. pstatus->wait_req = !IS_FREE(&thrd->req[1 - active])
  1267. ? thrd->req[1 - active].r : NULL;
  1268. }
  1269. pstatus->src_addr = readl(regs + SA(thrd->id));
  1270. pstatus->dst_addr = readl(regs + DA(thrd->id));
  1271. return 0;
  1272. }
  1273. EXPORT_SYMBOL(pl330_chan_status);
  1274. /* Reserve an event */
  1275. static inline int _alloc_event(struct pl330_thread *thrd)
  1276. {
  1277. struct pl330_dmac *pl330 = thrd->dmac;
  1278. struct pl330_info *pi = pl330->pinfo;
  1279. int ev;
  1280. for (ev = 0; ev < pi->pcfg.num_events; ev++)
  1281. if (pl330->events[ev] == -1) {
  1282. pl330->events[ev] = thrd->id;
  1283. return ev;
  1284. }
  1285. return -1;
  1286. }
  1287. static bool _chan_ns(const struct pl330_info *pi, int i)
  1288. {
  1289. return pi->pcfg.irq_ns & (1 << i);
  1290. }
  1291. /* Upon success, returns IdentityToken for the
  1292. * allocated channel, NULL otherwise.
  1293. */
  1294. void *pl330_request_channel(const struct pl330_info *pi)
  1295. {
  1296. struct pl330_thread *thrd = NULL;
  1297. struct pl330_dmac *pl330;
  1298. unsigned long flags;
  1299. int chans, i;
  1300. if (!pi || !pi->pl330_data)
  1301. return NULL;
  1302. pl330 = pi->pl330_data;
  1303. if (pl330->state == DYING)
  1304. return NULL;
  1305. chans = pi->pcfg.num_chan;
  1306. spin_lock_irqsave(&pl330->lock, flags);
  1307. for (i = 0; i < chans; i++) {
  1308. thrd = &pl330->channels[i];
  1309. if ((thrd->free) && (!_manager_ns(thrd) ||
  1310. _chan_ns(pi, i))) {
  1311. thrd->ev = _alloc_event(thrd);
  1312. if (thrd->ev >= 0) {
  1313. thrd->free = false;
  1314. thrd->lstenq = 1;
  1315. thrd->req[0].r = NULL;
  1316. mark_free(thrd, 0);
  1317. thrd->req[1].r = NULL;
  1318. mark_free(thrd, 1);
  1319. break;
  1320. }
  1321. }
  1322. thrd = NULL;
  1323. }
  1324. spin_unlock_irqrestore(&pl330->lock, flags);
  1325. return thrd;
  1326. }
  1327. EXPORT_SYMBOL(pl330_request_channel);
  1328. /* Release an event */
  1329. static inline void _free_event(struct pl330_thread *thrd, int ev)
  1330. {
  1331. struct pl330_dmac *pl330 = thrd->dmac;
  1332. struct pl330_info *pi = pl330->pinfo;
  1333. /* If the event is valid and was held by the thread */
  1334. if (ev >= 0 && ev < pi->pcfg.num_events
  1335. && pl330->events[ev] == thrd->id)
  1336. pl330->events[ev] = -1;
  1337. }
  1338. void pl330_release_channel(void *ch_id)
  1339. {
  1340. struct pl330_thread *thrd = ch_id;
  1341. struct pl330_dmac *pl330;
  1342. unsigned long flags;
  1343. if (!thrd || thrd->free)
  1344. return;
  1345. _stop(thrd);
  1346. _callback(thrd->req[1 - thrd->lstenq].r, PL330_ERR_ABORT);
  1347. _callback(thrd->req[thrd->lstenq].r, PL330_ERR_ABORT);
  1348. pl330 = thrd->dmac;
  1349. spin_lock_irqsave(&pl330->lock, flags);
  1350. _free_event(thrd, thrd->ev);
  1351. thrd->free = true;
  1352. spin_unlock_irqrestore(&pl330->lock, flags);
  1353. }
  1354. EXPORT_SYMBOL(pl330_release_channel);
  1355. /* Initialize the structure for PL330 configuration, that can be used
  1356. * by the client driver the make best use of the DMAC
  1357. */
  1358. static void read_dmac_config(struct pl330_info *pi)
  1359. {
  1360. void __iomem *regs = pi->base;
  1361. u32 val;
  1362. val = readl(regs + CRD) >> CRD_DATA_WIDTH_SHIFT;
  1363. val &= CRD_DATA_WIDTH_MASK;
  1364. pi->pcfg.data_bus_width = 8 * (1 << val);
  1365. val = readl(regs + CRD) >> CRD_DATA_BUFF_SHIFT;
  1366. val &= CRD_DATA_BUFF_MASK;
  1367. pi->pcfg.data_buf_dep = val + 1;
  1368. val = readl(regs + CR0) >> CR0_NUM_CHANS_SHIFT;
  1369. val &= CR0_NUM_CHANS_MASK;
  1370. val += 1;
  1371. pi->pcfg.num_chan = val;
  1372. val = readl(regs + CR0);
  1373. if (val & CR0_PERIPH_REQ_SET) {
  1374. val = (val >> CR0_NUM_PERIPH_SHIFT) & CR0_NUM_PERIPH_MASK;
  1375. val += 1;
  1376. pi->pcfg.num_peri = val;
  1377. pi->pcfg.peri_ns = readl(regs + CR4);
  1378. } else {
  1379. pi->pcfg.num_peri = 0;
  1380. }
  1381. val = readl(regs + CR0);
  1382. if (val & CR0_BOOT_MAN_NS)
  1383. pi->pcfg.mode |= DMAC_MODE_NS;
  1384. else
  1385. pi->pcfg.mode &= ~DMAC_MODE_NS;
  1386. val = readl(regs + CR0) >> CR0_NUM_EVENTS_SHIFT;
  1387. val &= CR0_NUM_EVENTS_MASK;
  1388. val += 1;
  1389. pi->pcfg.num_events = val;
  1390. pi->pcfg.irq_ns = readl(regs + CR3);
  1391. pi->pcfg.periph_id = get_id(pi, PERIPH_ID);
  1392. pi->pcfg.pcell_id = get_id(pi, PCELL_ID);
  1393. }
  1394. static inline void _reset_thread(struct pl330_thread *thrd)
  1395. {
  1396. struct pl330_dmac *pl330 = thrd->dmac;
  1397. struct pl330_info *pi = pl330->pinfo;
  1398. thrd->req[0].mc_cpu = pl330->mcode_cpu
  1399. + (thrd->id * pi->mcbufsz);
  1400. thrd->req[0].mc_bus = pl330->mcode_bus
  1401. + (thrd->id * pi->mcbufsz);
  1402. thrd->req[0].r = NULL;
  1403. mark_free(thrd, 0);
  1404. thrd->req[1].mc_cpu = thrd->req[0].mc_cpu
  1405. + pi->mcbufsz / 2;
  1406. thrd->req[1].mc_bus = thrd->req[0].mc_bus
  1407. + pi->mcbufsz / 2;
  1408. thrd->req[1].r = NULL;
  1409. mark_free(thrd, 1);
  1410. }
  1411. static int dmac_alloc_threads(struct pl330_dmac *pl330)
  1412. {
  1413. struct pl330_info *pi = pl330->pinfo;
  1414. int chans = pi->pcfg.num_chan;
  1415. struct pl330_thread *thrd;
  1416. int i;
  1417. /* Allocate 1 Manager and 'chans' Channel threads */
  1418. pl330->channels = kzalloc((1 + chans) * sizeof(*thrd),
  1419. GFP_KERNEL);
  1420. if (!pl330->channels)
  1421. return -ENOMEM;
  1422. /* Init Channel threads */
  1423. for (i = 0; i < chans; i++) {
  1424. thrd = &pl330->channels[i];
  1425. thrd->id = i;
  1426. thrd->dmac = pl330;
  1427. _reset_thread(thrd);
  1428. thrd->free = true;
  1429. }
  1430. /* MANAGER is indexed at the end */
  1431. thrd = &pl330->channels[chans];
  1432. thrd->id = chans;
  1433. thrd->dmac = pl330;
  1434. thrd->free = false;
  1435. pl330->manager = thrd;
  1436. return 0;
  1437. }
  1438. static int dmac_alloc_resources(struct pl330_dmac *pl330)
  1439. {
  1440. struct pl330_info *pi = pl330->pinfo;
  1441. int chans = pi->pcfg.num_chan;
  1442. int ret;
  1443. /*
  1444. * Alloc MicroCode buffer for 'chans' Channel threads.
  1445. * A channel's buffer offset is (Channel_Id * MCODE_BUFF_PERCHAN)
  1446. */
  1447. pl330->mcode_cpu = dma_alloc_coherent(pi->dev,
  1448. chans * pi->mcbufsz,
  1449. &pl330->mcode_bus, GFP_KERNEL);
  1450. if (!pl330->mcode_cpu) {
  1451. dev_err(pi->dev, "%s:%d Can't allocate memory!\n",
  1452. __func__, __LINE__);
  1453. return -ENOMEM;
  1454. }
  1455. ret = dmac_alloc_threads(pl330);
  1456. if (ret) {
  1457. dev_err(pi->dev, "%s:%d Can't to create channels for DMAC!\n",
  1458. __func__, __LINE__);
  1459. dma_free_coherent(pi->dev,
  1460. chans * pi->mcbufsz,
  1461. pl330->mcode_cpu, pl330->mcode_bus);
  1462. return ret;
  1463. }
  1464. return 0;
  1465. }
  1466. int pl330_add(struct pl330_info *pi)
  1467. {
  1468. struct pl330_dmac *pl330;
  1469. void __iomem *regs;
  1470. int i, ret;
  1471. if (!pi || !pi->dev)
  1472. return -EINVAL;
  1473. /* If already added */
  1474. if (pi->pl330_data)
  1475. return -EINVAL;
  1476. /*
  1477. * If the SoC can perform reset on the DMAC, then do it
  1478. * before reading its configuration.
  1479. */
  1480. if (pi->dmac_reset)
  1481. pi->dmac_reset(pi);
  1482. regs = pi->base;
  1483. /* Check if we can handle this DMAC */
  1484. if ((get_id(pi, PERIPH_ID) & 0xfffff) != PERIPH_ID_VAL
  1485. || get_id(pi, PCELL_ID) != PCELL_ID_VAL) {
  1486. dev_err(pi->dev, "PERIPH_ID 0x%x, PCELL_ID 0x%x !\n",
  1487. get_id(pi, PERIPH_ID), get_id(pi, PCELL_ID));
  1488. return -EINVAL;
  1489. }
  1490. /* Read the configuration of the DMAC */
  1491. read_dmac_config(pi);
  1492. if (pi->pcfg.num_events == 0) {
  1493. dev_err(pi->dev, "%s:%d Can't work without events!\n",
  1494. __func__, __LINE__);
  1495. return -EINVAL;
  1496. }
  1497. pl330 = kzalloc(sizeof(*pl330), GFP_KERNEL);
  1498. if (!pl330) {
  1499. dev_err(pi->dev, "%s:%d Can't allocate memory!\n",
  1500. __func__, __LINE__);
  1501. return -ENOMEM;
  1502. }
  1503. /* Assign the info structure and private data */
  1504. pl330->pinfo = pi;
  1505. pi->pl330_data = pl330;
  1506. spin_lock_init(&pl330->lock);
  1507. INIT_LIST_HEAD(&pl330->req_done);
  1508. /* Use default MC buffer size if not provided */
  1509. if (!pi->mcbufsz)
  1510. pi->mcbufsz = MCODE_BUFF_PER_REQ * 2;
  1511. /* Mark all events as free */
  1512. for (i = 0; i < pi->pcfg.num_events; i++)
  1513. pl330->events[i] = -1;
  1514. /* Allocate resources needed by the DMAC */
  1515. ret = dmac_alloc_resources(pl330);
  1516. if (ret) {
  1517. dev_err(pi->dev, "Unable to create channels for DMAC\n");
  1518. kfree(pl330);
  1519. return ret;
  1520. }
  1521. tasklet_init(&pl330->tasks, pl330_dotask, (unsigned long) pl330);
  1522. pl330->state = INIT;
  1523. return 0;
  1524. }
  1525. EXPORT_SYMBOL(pl330_add);
  1526. static int dmac_free_threads(struct pl330_dmac *pl330)
  1527. {
  1528. struct pl330_info *pi = pl330->pinfo;
  1529. int chans = pi->pcfg.num_chan;
  1530. struct pl330_thread *thrd;
  1531. int i;
  1532. /* Release Channel threads */
  1533. for (i = 0; i < chans; i++) {
  1534. thrd = &pl330->channels[i];
  1535. pl330_release_channel((void *)thrd);
  1536. }
  1537. /* Free memory */
  1538. kfree(pl330->channels);
  1539. return 0;
  1540. }
  1541. static void dmac_free_resources(struct pl330_dmac *pl330)
  1542. {
  1543. struct pl330_info *pi = pl330->pinfo;
  1544. int chans = pi->pcfg.num_chan;
  1545. dmac_free_threads(pl330);
  1546. dma_free_coherent(pi->dev, chans * pi->mcbufsz,
  1547. pl330->mcode_cpu, pl330->mcode_bus);
  1548. }
  1549. void pl330_del(struct pl330_info *pi)
  1550. {
  1551. struct pl330_dmac *pl330;
  1552. if (!pi || !pi->pl330_data)
  1553. return;
  1554. pl330 = pi->pl330_data;
  1555. pl330->state = UNINIT;
  1556. tasklet_kill(&pl330->tasks);
  1557. /* Free DMAC resources */
  1558. dmac_free_resources(pl330);
  1559. kfree(pl330);
  1560. pi->pl330_data = NULL;
  1561. }
  1562. EXPORT_SYMBOL(pl330_del);