pl330.c 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960
  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;
  1203. if (!thrd || thrd->free || thrd->dmac->state == DYING)
  1204. return -EINVAL;
  1205. pl330 = thrd->dmac;
  1206. active = thrd->req_running;
  1207. spin_lock_irqsave(&pl330->lock, flags);
  1208. switch (op) {
  1209. case PL330_OP_FLUSH:
  1210. /* Make sure the channel is stopped */
  1211. _stop(thrd);
  1212. thrd->req[0].r = NULL;
  1213. thrd->req[1].r = NULL;
  1214. mark_free(thrd, 0);
  1215. mark_free(thrd, 1);
  1216. break;
  1217. case PL330_OP_ABORT:
  1218. /* Make sure the channel is stopped */
  1219. _stop(thrd);
  1220. /* ABORT is only for the active req */
  1221. if (active == -1)
  1222. break;
  1223. thrd->req[active].r = NULL;
  1224. mark_free(thrd, active);
  1225. /* Start the next */
  1226. case PL330_OP_START:
  1227. if ((active == -1) && !_start(thrd))
  1228. ret = -EIO;
  1229. break;
  1230. default:
  1231. ret = -EINVAL;
  1232. }
  1233. spin_unlock_irqrestore(&pl330->lock, flags);
  1234. return ret;
  1235. }
  1236. EXPORT_SYMBOL(pl330_chan_ctrl);
  1237. int pl330_chan_status(void *ch_id, struct pl330_chanstatus *pstatus)
  1238. {
  1239. struct pl330_thread *thrd = ch_id;
  1240. struct pl330_dmac *pl330;
  1241. struct pl330_info *pi;
  1242. void __iomem *regs;
  1243. int active;
  1244. u32 val;
  1245. if (!pstatus || !thrd || thrd->free)
  1246. return -EINVAL;
  1247. pl330 = thrd->dmac;
  1248. pi = pl330->pinfo;
  1249. regs = pi->base;
  1250. /* The client should remove the DMAC and add again */
  1251. if (pl330->state == DYING)
  1252. pstatus->dmac_halted = true;
  1253. else
  1254. pstatus->dmac_halted = false;
  1255. val = readl(regs + FSC);
  1256. if (val & (1 << thrd->id))
  1257. pstatus->faulting = true;
  1258. else
  1259. pstatus->faulting = false;
  1260. active = thrd->req_running;
  1261. if (active == -1) {
  1262. /* Indicate that the thread is not running */
  1263. pstatus->top_req = NULL;
  1264. pstatus->wait_req = NULL;
  1265. } else {
  1266. pstatus->top_req = thrd->req[active].r;
  1267. pstatus->wait_req = !IS_FREE(&thrd->req[1 - active])
  1268. ? thrd->req[1 - active].r : NULL;
  1269. }
  1270. pstatus->src_addr = readl(regs + SA(thrd->id));
  1271. pstatus->dst_addr = readl(regs + DA(thrd->id));
  1272. return 0;
  1273. }
  1274. EXPORT_SYMBOL(pl330_chan_status);
  1275. /* Reserve an event */
  1276. static inline int _alloc_event(struct pl330_thread *thrd)
  1277. {
  1278. struct pl330_dmac *pl330 = thrd->dmac;
  1279. struct pl330_info *pi = pl330->pinfo;
  1280. int ev;
  1281. for (ev = 0; ev < pi->pcfg.num_events; ev++)
  1282. if (pl330->events[ev] == -1) {
  1283. pl330->events[ev] = thrd->id;
  1284. return ev;
  1285. }
  1286. return -1;
  1287. }
  1288. static bool _chan_ns(const struct pl330_info *pi, int i)
  1289. {
  1290. return pi->pcfg.irq_ns & (1 << i);
  1291. }
  1292. /* Upon success, returns IdentityToken for the
  1293. * allocated channel, NULL otherwise.
  1294. */
  1295. void *pl330_request_channel(const struct pl330_info *pi)
  1296. {
  1297. struct pl330_thread *thrd = NULL;
  1298. struct pl330_dmac *pl330;
  1299. unsigned long flags;
  1300. int chans, i;
  1301. if (!pi || !pi->pl330_data)
  1302. return NULL;
  1303. pl330 = pi->pl330_data;
  1304. if (pl330->state == DYING)
  1305. return NULL;
  1306. chans = pi->pcfg.num_chan;
  1307. spin_lock_irqsave(&pl330->lock, flags);
  1308. for (i = 0; i < chans; i++) {
  1309. thrd = &pl330->channels[i];
  1310. if ((thrd->free) && (!_manager_ns(thrd) ||
  1311. _chan_ns(pi, i))) {
  1312. thrd->ev = _alloc_event(thrd);
  1313. if (thrd->ev >= 0) {
  1314. thrd->free = false;
  1315. thrd->lstenq = 1;
  1316. thrd->req[0].r = NULL;
  1317. mark_free(thrd, 0);
  1318. thrd->req[1].r = NULL;
  1319. mark_free(thrd, 1);
  1320. break;
  1321. }
  1322. }
  1323. thrd = NULL;
  1324. }
  1325. spin_unlock_irqrestore(&pl330->lock, flags);
  1326. return thrd;
  1327. }
  1328. EXPORT_SYMBOL(pl330_request_channel);
  1329. /* Release an event */
  1330. static inline void _free_event(struct pl330_thread *thrd, int ev)
  1331. {
  1332. struct pl330_dmac *pl330 = thrd->dmac;
  1333. struct pl330_info *pi = pl330->pinfo;
  1334. /* If the event is valid and was held by the thread */
  1335. if (ev >= 0 && ev < pi->pcfg.num_events
  1336. && pl330->events[ev] == thrd->id)
  1337. pl330->events[ev] = -1;
  1338. }
  1339. void pl330_release_channel(void *ch_id)
  1340. {
  1341. struct pl330_thread *thrd = ch_id;
  1342. struct pl330_dmac *pl330;
  1343. unsigned long flags;
  1344. if (!thrd || thrd->free)
  1345. return;
  1346. _stop(thrd);
  1347. _callback(thrd->req[1 - thrd->lstenq].r, PL330_ERR_ABORT);
  1348. _callback(thrd->req[thrd->lstenq].r, PL330_ERR_ABORT);
  1349. pl330 = thrd->dmac;
  1350. spin_lock_irqsave(&pl330->lock, flags);
  1351. _free_event(thrd, thrd->ev);
  1352. thrd->free = true;
  1353. spin_unlock_irqrestore(&pl330->lock, flags);
  1354. }
  1355. EXPORT_SYMBOL(pl330_release_channel);
  1356. /* Initialize the structure for PL330 configuration, that can be used
  1357. * by the client driver the make best use of the DMAC
  1358. */
  1359. static void read_dmac_config(struct pl330_info *pi)
  1360. {
  1361. void __iomem *regs = pi->base;
  1362. u32 val;
  1363. val = readl(regs + CRD) >> CRD_DATA_WIDTH_SHIFT;
  1364. val &= CRD_DATA_WIDTH_MASK;
  1365. pi->pcfg.data_bus_width = 8 * (1 << val);
  1366. val = readl(regs + CRD) >> CRD_DATA_BUFF_SHIFT;
  1367. val &= CRD_DATA_BUFF_MASK;
  1368. pi->pcfg.data_buf_dep = val + 1;
  1369. val = readl(regs + CR0) >> CR0_NUM_CHANS_SHIFT;
  1370. val &= CR0_NUM_CHANS_MASK;
  1371. val += 1;
  1372. pi->pcfg.num_chan = val;
  1373. val = readl(regs + CR0);
  1374. if (val & CR0_PERIPH_REQ_SET) {
  1375. val = (val >> CR0_NUM_PERIPH_SHIFT) & CR0_NUM_PERIPH_MASK;
  1376. val += 1;
  1377. pi->pcfg.num_peri = val;
  1378. pi->pcfg.peri_ns = readl(regs + CR4);
  1379. } else {
  1380. pi->pcfg.num_peri = 0;
  1381. }
  1382. val = readl(regs + CR0);
  1383. if (val & CR0_BOOT_MAN_NS)
  1384. pi->pcfg.mode |= DMAC_MODE_NS;
  1385. else
  1386. pi->pcfg.mode &= ~DMAC_MODE_NS;
  1387. val = readl(regs + CR0) >> CR0_NUM_EVENTS_SHIFT;
  1388. val &= CR0_NUM_EVENTS_MASK;
  1389. val += 1;
  1390. pi->pcfg.num_events = val;
  1391. pi->pcfg.irq_ns = readl(regs + CR3);
  1392. pi->pcfg.periph_id = get_id(pi, PERIPH_ID);
  1393. pi->pcfg.pcell_id = get_id(pi, PCELL_ID);
  1394. }
  1395. static inline void _reset_thread(struct pl330_thread *thrd)
  1396. {
  1397. struct pl330_dmac *pl330 = thrd->dmac;
  1398. struct pl330_info *pi = pl330->pinfo;
  1399. thrd->req[0].mc_cpu = pl330->mcode_cpu
  1400. + (thrd->id * pi->mcbufsz);
  1401. thrd->req[0].mc_bus = pl330->mcode_bus
  1402. + (thrd->id * pi->mcbufsz);
  1403. thrd->req[0].r = NULL;
  1404. mark_free(thrd, 0);
  1405. thrd->req[1].mc_cpu = thrd->req[0].mc_cpu
  1406. + pi->mcbufsz / 2;
  1407. thrd->req[1].mc_bus = thrd->req[0].mc_bus
  1408. + pi->mcbufsz / 2;
  1409. thrd->req[1].r = NULL;
  1410. mark_free(thrd, 1);
  1411. }
  1412. static int dmac_alloc_threads(struct pl330_dmac *pl330)
  1413. {
  1414. struct pl330_info *pi = pl330->pinfo;
  1415. int chans = pi->pcfg.num_chan;
  1416. struct pl330_thread *thrd;
  1417. int i;
  1418. /* Allocate 1 Manager and 'chans' Channel threads */
  1419. pl330->channels = kzalloc((1 + chans) * sizeof(*thrd),
  1420. GFP_KERNEL);
  1421. if (!pl330->channels)
  1422. return -ENOMEM;
  1423. /* Init Channel threads */
  1424. for (i = 0; i < chans; i++) {
  1425. thrd = &pl330->channels[i];
  1426. thrd->id = i;
  1427. thrd->dmac = pl330;
  1428. _reset_thread(thrd);
  1429. thrd->free = true;
  1430. }
  1431. /* MANAGER is indexed at the end */
  1432. thrd = &pl330->channels[chans];
  1433. thrd->id = chans;
  1434. thrd->dmac = pl330;
  1435. thrd->free = false;
  1436. pl330->manager = thrd;
  1437. return 0;
  1438. }
  1439. static int dmac_alloc_resources(struct pl330_dmac *pl330)
  1440. {
  1441. struct pl330_info *pi = pl330->pinfo;
  1442. int chans = pi->pcfg.num_chan;
  1443. int ret;
  1444. /*
  1445. * Alloc MicroCode buffer for 'chans' Channel threads.
  1446. * A channel's buffer offset is (Channel_Id * MCODE_BUFF_PERCHAN)
  1447. */
  1448. pl330->mcode_cpu = dma_alloc_coherent(pi->dev,
  1449. chans * pi->mcbufsz,
  1450. &pl330->mcode_bus, GFP_KERNEL);
  1451. if (!pl330->mcode_cpu) {
  1452. dev_err(pi->dev, "%s:%d Can't allocate memory!\n",
  1453. __func__, __LINE__);
  1454. return -ENOMEM;
  1455. }
  1456. ret = dmac_alloc_threads(pl330);
  1457. if (ret) {
  1458. dev_err(pi->dev, "%s:%d Can't to create channels for DMAC!\n",
  1459. __func__, __LINE__);
  1460. dma_free_coherent(pi->dev,
  1461. chans * pi->mcbufsz,
  1462. pl330->mcode_cpu, pl330->mcode_bus);
  1463. return ret;
  1464. }
  1465. return 0;
  1466. }
  1467. int pl330_add(struct pl330_info *pi)
  1468. {
  1469. struct pl330_dmac *pl330;
  1470. void __iomem *regs;
  1471. int i, ret;
  1472. if (!pi || !pi->dev)
  1473. return -EINVAL;
  1474. /* If already added */
  1475. if (pi->pl330_data)
  1476. return -EINVAL;
  1477. /*
  1478. * If the SoC can perform reset on the DMAC, then do it
  1479. * before reading its configuration.
  1480. */
  1481. if (pi->dmac_reset)
  1482. pi->dmac_reset(pi);
  1483. regs = pi->base;
  1484. /* Check if we can handle this DMAC */
  1485. if ((get_id(pi, PERIPH_ID) & 0xfffff) != PERIPH_ID_VAL
  1486. || get_id(pi, PCELL_ID) != PCELL_ID_VAL) {
  1487. dev_err(pi->dev, "PERIPH_ID 0x%x, PCELL_ID 0x%x !\n",
  1488. get_id(pi, PERIPH_ID), get_id(pi, PCELL_ID));
  1489. return -EINVAL;
  1490. }
  1491. /* Read the configuration of the DMAC */
  1492. read_dmac_config(pi);
  1493. if (pi->pcfg.num_events == 0) {
  1494. dev_err(pi->dev, "%s:%d Can't work without events!\n",
  1495. __func__, __LINE__);
  1496. return -EINVAL;
  1497. }
  1498. pl330 = kzalloc(sizeof(*pl330), GFP_KERNEL);
  1499. if (!pl330) {
  1500. dev_err(pi->dev, "%s:%d Can't allocate memory!\n",
  1501. __func__, __LINE__);
  1502. return -ENOMEM;
  1503. }
  1504. /* Assign the info structure and private data */
  1505. pl330->pinfo = pi;
  1506. pi->pl330_data = pl330;
  1507. spin_lock_init(&pl330->lock);
  1508. INIT_LIST_HEAD(&pl330->req_done);
  1509. /* Use default MC buffer size if not provided */
  1510. if (!pi->mcbufsz)
  1511. pi->mcbufsz = MCODE_BUFF_PER_REQ * 2;
  1512. /* Mark all events as free */
  1513. for (i = 0; i < pi->pcfg.num_events; i++)
  1514. pl330->events[i] = -1;
  1515. /* Allocate resources needed by the DMAC */
  1516. ret = dmac_alloc_resources(pl330);
  1517. if (ret) {
  1518. dev_err(pi->dev, "Unable to create channels for DMAC\n");
  1519. kfree(pl330);
  1520. return ret;
  1521. }
  1522. tasklet_init(&pl330->tasks, pl330_dotask, (unsigned long) pl330);
  1523. pl330->state = INIT;
  1524. return 0;
  1525. }
  1526. EXPORT_SYMBOL(pl330_add);
  1527. static int dmac_free_threads(struct pl330_dmac *pl330)
  1528. {
  1529. struct pl330_info *pi = pl330->pinfo;
  1530. int chans = pi->pcfg.num_chan;
  1531. struct pl330_thread *thrd;
  1532. int i;
  1533. /* Release Channel threads */
  1534. for (i = 0; i < chans; i++) {
  1535. thrd = &pl330->channels[i];
  1536. pl330_release_channel((void *)thrd);
  1537. }
  1538. /* Free memory */
  1539. kfree(pl330->channels);
  1540. return 0;
  1541. }
  1542. static void dmac_free_resources(struct pl330_dmac *pl330)
  1543. {
  1544. struct pl330_info *pi = pl330->pinfo;
  1545. int chans = pi->pcfg.num_chan;
  1546. dmac_free_threads(pl330);
  1547. dma_free_coherent(pi->dev, chans * pi->mcbufsz,
  1548. pl330->mcode_cpu, pl330->mcode_bus);
  1549. }
  1550. void pl330_del(struct pl330_info *pi)
  1551. {
  1552. struct pl330_dmac *pl330;
  1553. if (!pi || !pi->pl330_data)
  1554. return;
  1555. pl330 = pi->pl330_data;
  1556. pl330->state = UNINIT;
  1557. tasklet_kill(&pl330->tasks);
  1558. /* Free DMAC resources */
  1559. dmac_free_resources(pl330);
  1560. kfree(pl330);
  1561. pi->pl330_data = NULL;
  1562. }
  1563. EXPORT_SYMBOL(pl330_del);