Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'next' of git://git.infradead.org/users/vkoul/slave-dma

Pull slave-dmaengine update from Vinod Koul:
"This includes the cookie cleanup by Russell, the addition of context
parameter for dmaengine APIs, more arm dmaengine driver cleanup by
moving code to dmaengine, this time for imx by Javier and pl330 by
Boojin along with the usual driver fixes."

Fix up some fairly trivial conflicts with various other cleanups.

* 'next' of git://git.infradead.org/users/vkoul/slave-dma: (67 commits)
dmaengine: imx: fix the build failure on x86_64
dmaengine: i.MX: Fix merge of cookie branch.
dmaengine: i.MX: Add support for interleaved transfers.
dmaengine: imx-dma: use 'dev_dbg' and 'dev_warn' for messages.
dmaengine: imx-dma: remove 'imx_dmav1_baseaddr' and 'dma_clk'.
dmaengine: imx-dma: remove unused arg of imxdma_sg_next.
dmaengine: imx-dma: remove internal structure.
dmaengine: imx-dma: remove 'resbytes' field of 'internal' structure.
dmaengine: imx-dma: remove 'in_use' field of 'internal' structure.
dmaengine: imx-dma: remove sg member from internal structure.
dmaengine: imx-dma: remove 'imxdma_setup_sg_hw' function.
dmaengine: imx-dma: remove 'imxdma_config_channel_hw' function.
dmaengine: imx-dma: remove 'imxdma_setup_mem2mem_hw' function.
dmaengine: imx-dma: remove dma_mode member of internal structure.
dmaengine: imx-dma: remove data member from internal structure.
dmaengine: imx-dma: merge old dma-v1.c with imx-dma.c
dmaengine: at_hdmac: add slave config operation
dmaengine: add context parameter to prep_slave_sg and prep_dma_cyclic
dmaengine/dma_slave: introduce inline wrappers
dma: imx-sdma: Treat firmware messages as warnings instead of erros
...

+3706 -4229
-3
arch/arm/common/Kconfig
··· 24 24 config ICST 25 25 bool 26 26 27 - config PL330 28 - bool 29 - 30 27 config SA1111 31 28 bool 32 29 select DMABOUNCE if !ARCH_PXA
-1
arch/arm/common/Makefile
··· 5 5 obj-$(CONFIG_ARM_GIC) += gic.o 6 6 obj-$(CONFIG_ARM_VIC) += vic.o 7 7 obj-$(CONFIG_ICST) += icst.o 8 - obj-$(CONFIG_PL330) += pl330.o 9 8 obj-$(CONFIG_SA1111) += sa1111.o 10 9 obj-$(CONFIG_PCI_HOST_VIA82C505) += via82c505.o 11 10 obj-$(CONFIG_DMABOUNCE) += dmabounce.o
-1960
arch/arm/common/pl330.c
··· 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 - 21 - #include <linux/kernel.h> 22 - #include <linux/init.h> 23 - #include <linux/slab.h> 24 - #include <linux/module.h> 25 - #include <linux/string.h> 26 - #include <linux/io.h> 27 - #include <linux/delay.h> 28 - #include <linux/interrupt.h> 29 - #include <linux/dma-mapping.h> 30 - 31 - #include <asm/hardware/pl330.h> 32 - 33 - /* Register and Bit field Definitions */ 34 - #define DS 0x0 35 - #define DS_ST_STOP 0x0 36 - #define DS_ST_EXEC 0x1 37 - #define DS_ST_CMISS 0x2 38 - #define DS_ST_UPDTPC 0x3 39 - #define DS_ST_WFE 0x4 40 - #define DS_ST_ATBRR 0x5 41 - #define DS_ST_QBUSY 0x6 42 - #define DS_ST_WFP 0x7 43 - #define DS_ST_KILL 0x8 44 - #define DS_ST_CMPLT 0x9 45 - #define DS_ST_FLTCMP 0xe 46 - #define DS_ST_FAULT 0xf 47 - 48 - #define DPC 0x4 49 - #define INTEN 0x20 50 - #define ES 0x24 51 - #define INTSTATUS 0x28 52 - #define INTCLR 0x2c 53 - #define FSM 0x30 54 - #define FSC 0x34 55 - #define FTM 0x38 56 - 57 - #define _FTC 0x40 58 - #define FTC(n) (_FTC + (n)*0x4) 59 - 60 - #define _CS 0x100 61 - #define CS(n) (_CS + (n)*0x8) 62 - #define CS_CNS (1 << 21) 63 - 64 - #define _CPC 0x104 65 - #define CPC(n) (_CPC + (n)*0x8) 66 - 67 - #define _SA 0x400 68 - #define SA(n) (_SA + (n)*0x20) 69 - 70 - #define _DA 0x404 71 - #define DA(n) (_DA + (n)*0x20) 72 - 73 - #define _CC 0x408 74 - #define CC(n) (_CC + (n)*0x20) 75 - 76 - #define CC_SRCINC (1 << 0) 77 - #define CC_DSTINC (1 << 14) 78 - #define CC_SRCPRI (1 << 8) 79 - #define CC_DSTPRI (1 << 22) 80 - #define CC_SRCNS (1 << 9) 81 - #define CC_DSTNS (1 << 23) 82 - #define CC_SRCIA (1 << 10) 83 - #define CC_DSTIA (1 << 24) 84 - #define CC_SRCBRSTLEN_SHFT 4 85 - #define CC_DSTBRSTLEN_SHFT 18 86 - #define CC_SRCBRSTSIZE_SHFT 1 87 - #define CC_DSTBRSTSIZE_SHFT 15 88 - #define CC_SRCCCTRL_SHFT 11 89 - #define CC_SRCCCTRL_MASK 0x7 90 - #define CC_DSTCCTRL_SHFT 25 91 - #define CC_DRCCCTRL_MASK 0x7 92 - #define CC_SWAP_SHFT 28 93 - 94 - #define _LC0 0x40c 95 - #define LC0(n) (_LC0 + (n)*0x20) 96 - 97 - #define _LC1 0x410 98 - #define LC1(n) (_LC1 + (n)*0x20) 99 - 100 - #define DBGSTATUS 0xd00 101 - #define DBG_BUSY (1 << 0) 102 - 103 - #define DBGCMD 0xd04 104 - #define DBGINST0 0xd08 105 - #define DBGINST1 0xd0c 106 - 107 - #define CR0 0xe00 108 - #define CR1 0xe04 109 - #define CR2 0xe08 110 - #define CR3 0xe0c 111 - #define CR4 0xe10 112 - #define CRD 0xe14 113 - 114 - #define PERIPH_ID 0xfe0 115 - #define PCELL_ID 0xff0 116 - 117 - #define CR0_PERIPH_REQ_SET (1 << 0) 118 - #define CR0_BOOT_EN_SET (1 << 1) 119 - #define CR0_BOOT_MAN_NS (1 << 2) 120 - #define CR0_NUM_CHANS_SHIFT 4 121 - #define CR0_NUM_CHANS_MASK 0x7 122 - #define CR0_NUM_PERIPH_SHIFT 12 123 - #define CR0_NUM_PERIPH_MASK 0x1f 124 - #define CR0_NUM_EVENTS_SHIFT 17 125 - #define CR0_NUM_EVENTS_MASK 0x1f 126 - 127 - #define CR1_ICACHE_LEN_SHIFT 0 128 - #define CR1_ICACHE_LEN_MASK 0x7 129 - #define CR1_NUM_ICACHELINES_SHIFT 4 130 - #define CR1_NUM_ICACHELINES_MASK 0xf 131 - 132 - #define CRD_DATA_WIDTH_SHIFT 0 133 - #define CRD_DATA_WIDTH_MASK 0x7 134 - #define CRD_WR_CAP_SHIFT 4 135 - #define CRD_WR_CAP_MASK 0x7 136 - #define CRD_WR_Q_DEP_SHIFT 8 137 - #define CRD_WR_Q_DEP_MASK 0xf 138 - #define CRD_RD_CAP_SHIFT 12 139 - #define CRD_RD_CAP_MASK 0x7 140 - #define CRD_RD_Q_DEP_SHIFT 16 141 - #define CRD_RD_Q_DEP_MASK 0xf 142 - #define CRD_DATA_BUFF_SHIFT 20 143 - #define CRD_DATA_BUFF_MASK 0x3ff 144 - 145 - #define PART 0x330 146 - #define DESIGNER 0x41 147 - #define REVISION 0x0 148 - #define INTEG_CFG 0x0 149 - #define PERIPH_ID_VAL ((PART << 0) | (DESIGNER << 12)) 150 - 151 - #define PCELL_ID_VAL 0xb105f00d 152 - 153 - #define PL330_STATE_STOPPED (1 << 0) 154 - #define PL330_STATE_EXECUTING (1 << 1) 155 - #define PL330_STATE_WFE (1 << 2) 156 - #define PL330_STATE_FAULTING (1 << 3) 157 - #define PL330_STATE_COMPLETING (1 << 4) 158 - #define PL330_STATE_WFP (1 << 5) 159 - #define PL330_STATE_KILLING (1 << 6) 160 - #define PL330_STATE_FAULT_COMPLETING (1 << 7) 161 - #define PL330_STATE_CACHEMISS (1 << 8) 162 - #define PL330_STATE_UPDTPC (1 << 9) 163 - #define PL330_STATE_ATBARRIER (1 << 10) 164 - #define PL330_STATE_QUEUEBUSY (1 << 11) 165 - #define PL330_STATE_INVALID (1 << 15) 166 - 167 - #define PL330_STABLE_STATES (PL330_STATE_STOPPED | PL330_STATE_EXECUTING \ 168 - | PL330_STATE_WFE | PL330_STATE_FAULTING) 169 - 170 - #define CMD_DMAADDH 0x54 171 - #define CMD_DMAEND 0x00 172 - #define CMD_DMAFLUSHP 0x35 173 - #define CMD_DMAGO 0xa0 174 - #define CMD_DMALD 0x04 175 - #define CMD_DMALDP 0x25 176 - #define CMD_DMALP 0x20 177 - #define CMD_DMALPEND 0x28 178 - #define CMD_DMAKILL 0x01 179 - #define CMD_DMAMOV 0xbc 180 - #define CMD_DMANOP 0x18 181 - #define CMD_DMARMB 0x12 182 - #define CMD_DMASEV 0x34 183 - #define CMD_DMAST 0x08 184 - #define CMD_DMASTP 0x29 185 - #define CMD_DMASTZ 0x0c 186 - #define CMD_DMAWFE 0x36 187 - #define CMD_DMAWFP 0x30 188 - #define CMD_DMAWMB 0x13 189 - 190 - #define SZ_DMAADDH 3 191 - #define SZ_DMAEND 1 192 - #define SZ_DMAFLUSHP 2 193 - #define SZ_DMALD 1 194 - #define SZ_DMALDP 2 195 - #define SZ_DMALP 2 196 - #define SZ_DMALPEND 2 197 - #define SZ_DMAKILL 1 198 - #define SZ_DMAMOV 6 199 - #define SZ_DMANOP 1 200 - #define SZ_DMARMB 1 201 - #define SZ_DMASEV 2 202 - #define SZ_DMAST 1 203 - #define SZ_DMASTP 2 204 - #define SZ_DMASTZ 1 205 - #define SZ_DMAWFE 2 206 - #define SZ_DMAWFP 2 207 - #define SZ_DMAWMB 1 208 - #define SZ_DMAGO 6 209 - 210 - #define BRST_LEN(ccr) ((((ccr) >> CC_SRCBRSTLEN_SHFT) & 0xf) + 1) 211 - #define BRST_SIZE(ccr) (1 << (((ccr) >> CC_SRCBRSTSIZE_SHFT) & 0x7)) 212 - 213 - #define BYTE_TO_BURST(b, ccr) ((b) / BRST_SIZE(ccr) / BRST_LEN(ccr)) 214 - #define BURST_TO_BYTE(c, ccr) ((c) * BRST_SIZE(ccr) * BRST_LEN(ccr)) 215 - 216 - /* 217 - * With 256 bytes, we can do more than 2.5MB and 5MB xfers per req 218 - * at 1byte/burst for P<->M and M<->M respectively. 219 - * For typical scenario, at 1word/burst, 10MB and 20MB xfers per req 220 - * should be enough for P<->M and M<->M respectively. 221 - */ 222 - #define MCODE_BUFF_PER_REQ 256 223 - 224 - /* If the _pl330_req is available to the client */ 225 - #define IS_FREE(req) (*((u8 *)((req)->mc_cpu)) == CMD_DMAEND) 226 - 227 - /* Use this _only_ to wait on transient states */ 228 - #define UNTIL(t, s) while (!(_state(t) & (s))) cpu_relax(); 229 - 230 - #ifdef PL330_DEBUG_MCGEN 231 - static unsigned cmd_line; 232 - #define PL330_DBGCMD_DUMP(off, x...) do { \ 233 - printk("%x:", cmd_line); \ 234 - printk(x); \ 235 - cmd_line += off; \ 236 - } while (0) 237 - #define PL330_DBGMC_START(addr) (cmd_line = addr) 238 - #else 239 - #define PL330_DBGCMD_DUMP(off, x...) do {} while (0) 240 - #define PL330_DBGMC_START(addr) do {} while (0) 241 - #endif 242 - 243 - struct _xfer_spec { 244 - u32 ccr; 245 - struct pl330_req *r; 246 - struct pl330_xfer *x; 247 - }; 248 - 249 - enum dmamov_dst { 250 - SAR = 0, 251 - CCR, 252 - DAR, 253 - }; 254 - 255 - enum pl330_dst { 256 - SRC = 0, 257 - DST, 258 - }; 259 - 260 - enum pl330_cond { 261 - SINGLE, 262 - BURST, 263 - ALWAYS, 264 - }; 265 - 266 - struct _pl330_req { 267 - u32 mc_bus; 268 - void *mc_cpu; 269 - /* Number of bytes taken to setup MC for the req */ 270 - u32 mc_len; 271 - struct pl330_req *r; 272 - /* Hook to attach to DMAC's list of reqs with due callback */ 273 - struct list_head rqd; 274 - }; 275 - 276 - /* ToBeDone for tasklet */ 277 - struct _pl330_tbd { 278 - bool reset_dmac; 279 - bool reset_mngr; 280 - u8 reset_chan; 281 - }; 282 - 283 - /* A DMAC Thread */ 284 - struct pl330_thread { 285 - u8 id; 286 - int ev; 287 - /* If the channel is not yet acquired by any client */ 288 - bool free; 289 - /* Parent DMAC */ 290 - struct pl330_dmac *dmac; 291 - /* Only two at a time */ 292 - struct _pl330_req req[2]; 293 - /* Index of the last enqueued request */ 294 - unsigned lstenq; 295 - /* Index of the last submitted request or -1 if the DMA is stopped */ 296 - int req_running; 297 - }; 298 - 299 - enum pl330_dmac_state { 300 - UNINIT, 301 - INIT, 302 - DYING, 303 - }; 304 - 305 - /* A DMAC */ 306 - struct pl330_dmac { 307 - spinlock_t lock; 308 - /* Holds list of reqs with due callbacks */ 309 - struct list_head req_done; 310 - /* Pointer to platform specific stuff */ 311 - struct pl330_info *pinfo; 312 - /* Maximum possible events/irqs */ 313 - int events[32]; 314 - /* BUS address of MicroCode buffer */ 315 - u32 mcode_bus; 316 - /* CPU address of MicroCode buffer */ 317 - void *mcode_cpu; 318 - /* List of all Channel threads */ 319 - struct pl330_thread *channels; 320 - /* Pointer to the MANAGER thread */ 321 - struct pl330_thread *manager; 322 - /* To handle bad news in interrupt */ 323 - struct tasklet_struct tasks; 324 - struct _pl330_tbd dmac_tbd; 325 - /* State of DMAC operation */ 326 - enum pl330_dmac_state state; 327 - }; 328 - 329 - static inline void _callback(struct pl330_req *r, enum pl330_op_err err) 330 - { 331 - if (r && r->xfer_cb) 332 - r->xfer_cb(r->token, err); 333 - } 334 - 335 - static inline bool _queue_empty(struct pl330_thread *thrd) 336 - { 337 - return (IS_FREE(&thrd->req[0]) && IS_FREE(&thrd->req[1])) 338 - ? true : false; 339 - } 340 - 341 - static inline bool _queue_full(struct pl330_thread *thrd) 342 - { 343 - return (IS_FREE(&thrd->req[0]) || IS_FREE(&thrd->req[1])) 344 - ? false : true; 345 - } 346 - 347 - static inline bool is_manager(struct pl330_thread *thrd) 348 - { 349 - struct pl330_dmac *pl330 = thrd->dmac; 350 - 351 - /* MANAGER is indexed at the end */ 352 - if (thrd->id == pl330->pinfo->pcfg.num_chan) 353 - return true; 354 - else 355 - return false; 356 - } 357 - 358 - /* If manager of the thread is in Non-Secure mode */ 359 - static inline bool _manager_ns(struct pl330_thread *thrd) 360 - { 361 - struct pl330_dmac *pl330 = thrd->dmac; 362 - 363 - return (pl330->pinfo->pcfg.mode & DMAC_MODE_NS) ? true : false; 364 - } 365 - 366 - static inline u32 get_id(struct pl330_info *pi, u32 off) 367 - { 368 - void __iomem *regs = pi->base; 369 - u32 id = 0; 370 - 371 - id |= (readb(regs + off + 0x0) << 0); 372 - id |= (readb(regs + off + 0x4) << 8); 373 - id |= (readb(regs + off + 0x8) << 16); 374 - id |= (readb(regs + off + 0xc) << 24); 375 - 376 - return id; 377 - } 378 - 379 - static inline u32 _emit_ADDH(unsigned dry_run, u8 buf[], 380 - enum pl330_dst da, u16 val) 381 - { 382 - if (dry_run) 383 - return SZ_DMAADDH; 384 - 385 - buf[0] = CMD_DMAADDH; 386 - buf[0] |= (da << 1); 387 - *((u16 *)&buf[1]) = val; 388 - 389 - PL330_DBGCMD_DUMP(SZ_DMAADDH, "\tDMAADDH %s %u\n", 390 - da == 1 ? "DA" : "SA", val); 391 - 392 - return SZ_DMAADDH; 393 - } 394 - 395 - static inline u32 _emit_END(unsigned dry_run, u8 buf[]) 396 - { 397 - if (dry_run) 398 - return SZ_DMAEND; 399 - 400 - buf[0] = CMD_DMAEND; 401 - 402 - PL330_DBGCMD_DUMP(SZ_DMAEND, "\tDMAEND\n"); 403 - 404 - return SZ_DMAEND; 405 - } 406 - 407 - static inline u32 _emit_FLUSHP(unsigned dry_run, u8 buf[], u8 peri) 408 - { 409 - if (dry_run) 410 - return SZ_DMAFLUSHP; 411 - 412 - buf[0] = CMD_DMAFLUSHP; 413 - 414 - peri &= 0x1f; 415 - peri <<= 3; 416 - buf[1] = peri; 417 - 418 - PL330_DBGCMD_DUMP(SZ_DMAFLUSHP, "\tDMAFLUSHP %u\n", peri >> 3); 419 - 420 - return SZ_DMAFLUSHP; 421 - } 422 - 423 - static inline u32 _emit_LD(unsigned dry_run, u8 buf[], enum pl330_cond cond) 424 - { 425 - if (dry_run) 426 - return SZ_DMALD; 427 - 428 - buf[0] = CMD_DMALD; 429 - 430 - if (cond == SINGLE) 431 - buf[0] |= (0 << 1) | (1 << 0); 432 - else if (cond == BURST) 433 - buf[0] |= (1 << 1) | (1 << 0); 434 - 435 - PL330_DBGCMD_DUMP(SZ_DMALD, "\tDMALD%c\n", 436 - cond == SINGLE ? 'S' : (cond == BURST ? 'B' : 'A')); 437 - 438 - return SZ_DMALD; 439 - } 440 - 441 - static inline u32 _emit_LDP(unsigned dry_run, u8 buf[], 442 - enum pl330_cond cond, u8 peri) 443 - { 444 - if (dry_run) 445 - return SZ_DMALDP; 446 - 447 - buf[0] = CMD_DMALDP; 448 - 449 - if (cond == BURST) 450 - buf[0] |= (1 << 1); 451 - 452 - peri &= 0x1f; 453 - peri <<= 3; 454 - buf[1] = peri; 455 - 456 - PL330_DBGCMD_DUMP(SZ_DMALDP, "\tDMALDP%c %u\n", 457 - cond == SINGLE ? 'S' : 'B', peri >> 3); 458 - 459 - return SZ_DMALDP; 460 - } 461 - 462 - static inline u32 _emit_LP(unsigned dry_run, u8 buf[], 463 - unsigned loop, u8 cnt) 464 - { 465 - if (dry_run) 466 - return SZ_DMALP; 467 - 468 - buf[0] = CMD_DMALP; 469 - 470 - if (loop) 471 - buf[0] |= (1 << 1); 472 - 473 - cnt--; /* DMAC increments by 1 internally */ 474 - buf[1] = cnt; 475 - 476 - PL330_DBGCMD_DUMP(SZ_DMALP, "\tDMALP_%c %u\n", loop ? '1' : '0', cnt); 477 - 478 - return SZ_DMALP; 479 - } 480 - 481 - struct _arg_LPEND { 482 - enum pl330_cond cond; 483 - bool forever; 484 - unsigned loop; 485 - u8 bjump; 486 - }; 487 - 488 - static inline u32 _emit_LPEND(unsigned dry_run, u8 buf[], 489 - const struct _arg_LPEND *arg) 490 - { 491 - enum pl330_cond cond = arg->cond; 492 - bool forever = arg->forever; 493 - unsigned loop = arg->loop; 494 - u8 bjump = arg->bjump; 495 - 496 - if (dry_run) 497 - return SZ_DMALPEND; 498 - 499 - buf[0] = CMD_DMALPEND; 500 - 501 - if (loop) 502 - buf[0] |= (1 << 2); 503 - 504 - if (!forever) 505 - buf[0] |= (1 << 4); 506 - 507 - if (cond == SINGLE) 508 - buf[0] |= (0 << 1) | (1 << 0); 509 - else if (cond == BURST) 510 - buf[0] |= (1 << 1) | (1 << 0); 511 - 512 - buf[1] = bjump; 513 - 514 - PL330_DBGCMD_DUMP(SZ_DMALPEND, "\tDMALP%s%c_%c bjmpto_%x\n", 515 - forever ? "FE" : "END", 516 - cond == SINGLE ? 'S' : (cond == BURST ? 'B' : 'A'), 517 - loop ? '1' : '0', 518 - bjump); 519 - 520 - return SZ_DMALPEND; 521 - } 522 - 523 - static inline u32 _emit_KILL(unsigned dry_run, u8 buf[]) 524 - { 525 - if (dry_run) 526 - return SZ_DMAKILL; 527 - 528 - buf[0] = CMD_DMAKILL; 529 - 530 - return SZ_DMAKILL; 531 - } 532 - 533 - static inline u32 _emit_MOV(unsigned dry_run, u8 buf[], 534 - enum dmamov_dst dst, u32 val) 535 - { 536 - if (dry_run) 537 - return SZ_DMAMOV; 538 - 539 - buf[0] = CMD_DMAMOV; 540 - buf[1] = dst; 541 - *((u32 *)&buf[2]) = val; 542 - 543 - PL330_DBGCMD_DUMP(SZ_DMAMOV, "\tDMAMOV %s 0x%x\n", 544 - dst == SAR ? "SAR" : (dst == DAR ? "DAR" : "CCR"), val); 545 - 546 - return SZ_DMAMOV; 547 - } 548 - 549 - static inline u32 _emit_NOP(unsigned dry_run, u8 buf[]) 550 - { 551 - if (dry_run) 552 - return SZ_DMANOP; 553 - 554 - buf[0] = CMD_DMANOP; 555 - 556 - PL330_DBGCMD_DUMP(SZ_DMANOP, "\tDMANOP\n"); 557 - 558 - return SZ_DMANOP; 559 - } 560 - 561 - static inline u32 _emit_RMB(unsigned dry_run, u8 buf[]) 562 - { 563 - if (dry_run) 564 - return SZ_DMARMB; 565 - 566 - buf[0] = CMD_DMARMB; 567 - 568 - PL330_DBGCMD_DUMP(SZ_DMARMB, "\tDMARMB\n"); 569 - 570 - return SZ_DMARMB; 571 - } 572 - 573 - static inline u32 _emit_SEV(unsigned dry_run, u8 buf[], u8 ev) 574 - { 575 - if (dry_run) 576 - return SZ_DMASEV; 577 - 578 - buf[0] = CMD_DMASEV; 579 - 580 - ev &= 0x1f; 581 - ev <<= 3; 582 - buf[1] = ev; 583 - 584 - PL330_DBGCMD_DUMP(SZ_DMASEV, "\tDMASEV %u\n", ev >> 3); 585 - 586 - return SZ_DMASEV; 587 - } 588 - 589 - static inline u32 _emit_ST(unsigned dry_run, u8 buf[], enum pl330_cond cond) 590 - { 591 - if (dry_run) 592 - return SZ_DMAST; 593 - 594 - buf[0] = CMD_DMAST; 595 - 596 - if (cond == SINGLE) 597 - buf[0] |= (0 << 1) | (1 << 0); 598 - else if (cond == BURST) 599 - buf[0] |= (1 << 1) | (1 << 0); 600 - 601 - PL330_DBGCMD_DUMP(SZ_DMAST, "\tDMAST%c\n", 602 - cond == SINGLE ? 'S' : (cond == BURST ? 'B' : 'A')); 603 - 604 - return SZ_DMAST; 605 - } 606 - 607 - static inline u32 _emit_STP(unsigned dry_run, u8 buf[], 608 - enum pl330_cond cond, u8 peri) 609 - { 610 - if (dry_run) 611 - return SZ_DMASTP; 612 - 613 - buf[0] = CMD_DMASTP; 614 - 615 - if (cond == BURST) 616 - buf[0] |= (1 << 1); 617 - 618 - peri &= 0x1f; 619 - peri <<= 3; 620 - buf[1] = peri; 621 - 622 - PL330_DBGCMD_DUMP(SZ_DMASTP, "\tDMASTP%c %u\n", 623 - cond == SINGLE ? 'S' : 'B', peri >> 3); 624 - 625 - return SZ_DMASTP; 626 - } 627 - 628 - static inline u32 _emit_STZ(unsigned dry_run, u8 buf[]) 629 - { 630 - if (dry_run) 631 - return SZ_DMASTZ; 632 - 633 - buf[0] = CMD_DMASTZ; 634 - 635 - PL330_DBGCMD_DUMP(SZ_DMASTZ, "\tDMASTZ\n"); 636 - 637 - return SZ_DMASTZ; 638 - } 639 - 640 - static inline u32 _emit_WFE(unsigned dry_run, u8 buf[], u8 ev, 641 - unsigned invalidate) 642 - { 643 - if (dry_run) 644 - return SZ_DMAWFE; 645 - 646 - buf[0] = CMD_DMAWFE; 647 - 648 - ev &= 0x1f; 649 - ev <<= 3; 650 - buf[1] = ev; 651 - 652 - if (invalidate) 653 - buf[1] |= (1 << 1); 654 - 655 - PL330_DBGCMD_DUMP(SZ_DMAWFE, "\tDMAWFE %u%s\n", 656 - ev >> 3, invalidate ? ", I" : ""); 657 - 658 - return SZ_DMAWFE; 659 - } 660 - 661 - static inline u32 _emit_WFP(unsigned dry_run, u8 buf[], 662 - enum pl330_cond cond, u8 peri) 663 - { 664 - if (dry_run) 665 - return SZ_DMAWFP; 666 - 667 - buf[0] = CMD_DMAWFP; 668 - 669 - if (cond == SINGLE) 670 - buf[0] |= (0 << 1) | (0 << 0); 671 - else if (cond == BURST) 672 - buf[0] |= (1 << 1) | (0 << 0); 673 - else 674 - buf[0] |= (0 << 1) | (1 << 0); 675 - 676 - peri &= 0x1f; 677 - peri <<= 3; 678 - buf[1] = peri; 679 - 680 - PL330_DBGCMD_DUMP(SZ_DMAWFP, "\tDMAWFP%c %u\n", 681 - cond == SINGLE ? 'S' : (cond == BURST ? 'B' : 'P'), peri >> 3); 682 - 683 - return SZ_DMAWFP; 684 - } 685 - 686 - static inline u32 _emit_WMB(unsigned dry_run, u8 buf[]) 687 - { 688 - if (dry_run) 689 - return SZ_DMAWMB; 690 - 691 - buf[0] = CMD_DMAWMB; 692 - 693 - PL330_DBGCMD_DUMP(SZ_DMAWMB, "\tDMAWMB\n"); 694 - 695 - return SZ_DMAWMB; 696 - } 697 - 698 - struct _arg_GO { 699 - u8 chan; 700 - u32 addr; 701 - unsigned ns; 702 - }; 703 - 704 - static inline u32 _emit_GO(unsigned dry_run, u8 buf[], 705 - const struct _arg_GO *arg) 706 - { 707 - u8 chan = arg->chan; 708 - u32 addr = arg->addr; 709 - unsigned ns = arg->ns; 710 - 711 - if (dry_run) 712 - return SZ_DMAGO; 713 - 714 - buf[0] = CMD_DMAGO; 715 - buf[0] |= (ns << 1); 716 - 717 - buf[1] = chan & 0x7; 718 - 719 - *((u32 *)&buf[2]) = addr; 720 - 721 - return SZ_DMAGO; 722 - } 723 - 724 - #define msecs_to_loops(t) (loops_per_jiffy / 1000 * HZ * t) 725 - 726 - /* Returns Time-Out */ 727 - static bool _until_dmac_idle(struct pl330_thread *thrd) 728 - { 729 - void __iomem *regs = thrd->dmac->pinfo->base; 730 - unsigned long loops = msecs_to_loops(5); 731 - 732 - do { 733 - /* Until Manager is Idle */ 734 - if (!(readl(regs + DBGSTATUS) & DBG_BUSY)) 735 - break; 736 - 737 - cpu_relax(); 738 - } while (--loops); 739 - 740 - if (!loops) 741 - return true; 742 - 743 - return false; 744 - } 745 - 746 - static inline void _execute_DBGINSN(struct pl330_thread *thrd, 747 - u8 insn[], bool as_manager) 748 - { 749 - void __iomem *regs = thrd->dmac->pinfo->base; 750 - u32 val; 751 - 752 - val = (insn[0] << 16) | (insn[1] << 24); 753 - if (!as_manager) { 754 - val |= (1 << 0); 755 - val |= (thrd->id << 8); /* Channel Number */ 756 - } 757 - writel(val, regs + DBGINST0); 758 - 759 - val = *((u32 *)&insn[2]); 760 - writel(val, regs + DBGINST1); 761 - 762 - /* If timed out due to halted state-machine */ 763 - if (_until_dmac_idle(thrd)) { 764 - dev_err(thrd->dmac->pinfo->dev, "DMAC halted!\n"); 765 - return; 766 - } 767 - 768 - /* Get going */ 769 - writel(0, regs + DBGCMD); 770 - } 771 - 772 - /* 773 - * Mark a _pl330_req as free. 774 - * We do it by writing DMAEND as the first instruction 775 - * because no valid request is going to have DMAEND as 776 - * its first instruction to execute. 777 - */ 778 - static void mark_free(struct pl330_thread *thrd, int idx) 779 - { 780 - struct _pl330_req *req = &thrd->req[idx]; 781 - 782 - _emit_END(0, req->mc_cpu); 783 - req->mc_len = 0; 784 - 785 - thrd->req_running = -1; 786 - } 787 - 788 - static inline u32 _state(struct pl330_thread *thrd) 789 - { 790 - void __iomem *regs = thrd->dmac->pinfo->base; 791 - u32 val; 792 - 793 - if (is_manager(thrd)) 794 - val = readl(regs + DS) & 0xf; 795 - else 796 - val = readl(regs + CS(thrd->id)) & 0xf; 797 - 798 - switch (val) { 799 - case DS_ST_STOP: 800 - return PL330_STATE_STOPPED; 801 - case DS_ST_EXEC: 802 - return PL330_STATE_EXECUTING; 803 - case DS_ST_CMISS: 804 - return PL330_STATE_CACHEMISS; 805 - case DS_ST_UPDTPC: 806 - return PL330_STATE_UPDTPC; 807 - case DS_ST_WFE: 808 - return PL330_STATE_WFE; 809 - case DS_ST_FAULT: 810 - return PL330_STATE_FAULTING; 811 - case DS_ST_ATBRR: 812 - if (is_manager(thrd)) 813 - return PL330_STATE_INVALID; 814 - else 815 - return PL330_STATE_ATBARRIER; 816 - case DS_ST_QBUSY: 817 - if (is_manager(thrd)) 818 - return PL330_STATE_INVALID; 819 - else 820 - return PL330_STATE_QUEUEBUSY; 821 - case DS_ST_WFP: 822 - if (is_manager(thrd)) 823 - return PL330_STATE_INVALID; 824 - else 825 - return PL330_STATE_WFP; 826 - case DS_ST_KILL: 827 - if (is_manager(thrd)) 828 - return PL330_STATE_INVALID; 829 - else 830 - return PL330_STATE_KILLING; 831 - case DS_ST_CMPLT: 832 - if (is_manager(thrd)) 833 - return PL330_STATE_INVALID; 834 - else 835 - return PL330_STATE_COMPLETING; 836 - case DS_ST_FLTCMP: 837 - if (is_manager(thrd)) 838 - return PL330_STATE_INVALID; 839 - else 840 - return PL330_STATE_FAULT_COMPLETING; 841 - default: 842 - return PL330_STATE_INVALID; 843 - } 844 - } 845 - 846 - static void _stop(struct pl330_thread *thrd) 847 - { 848 - void __iomem *regs = thrd->dmac->pinfo->base; 849 - u8 insn[6] = {0, 0, 0, 0, 0, 0}; 850 - 851 - if (_state(thrd) == PL330_STATE_FAULT_COMPLETING) 852 - UNTIL(thrd, PL330_STATE_FAULTING | PL330_STATE_KILLING); 853 - 854 - /* Return if nothing needs to be done */ 855 - if (_state(thrd) == PL330_STATE_COMPLETING 856 - || _state(thrd) == PL330_STATE_KILLING 857 - || _state(thrd) == PL330_STATE_STOPPED) 858 - return; 859 - 860 - _emit_KILL(0, insn); 861 - 862 - /* Stop generating interrupts for SEV */ 863 - writel(readl(regs + INTEN) & ~(1 << thrd->ev), regs + INTEN); 864 - 865 - _execute_DBGINSN(thrd, insn, is_manager(thrd)); 866 - } 867 - 868 - /* Start doing req 'idx' of thread 'thrd' */ 869 - static bool _trigger(struct pl330_thread *thrd) 870 - { 871 - void __iomem *regs = thrd->dmac->pinfo->base; 872 - struct _pl330_req *req; 873 - struct pl330_req *r; 874 - struct _arg_GO go; 875 - unsigned ns; 876 - u8 insn[6] = {0, 0, 0, 0, 0, 0}; 877 - int idx; 878 - 879 - /* Return if already ACTIVE */ 880 - if (_state(thrd) != PL330_STATE_STOPPED) 881 - return true; 882 - 883 - idx = 1 - thrd->lstenq; 884 - if (!IS_FREE(&thrd->req[idx])) 885 - req = &thrd->req[idx]; 886 - else { 887 - idx = thrd->lstenq; 888 - if (!IS_FREE(&thrd->req[idx])) 889 - req = &thrd->req[idx]; 890 - else 891 - req = NULL; 892 - } 893 - 894 - /* Return if no request */ 895 - if (!req || !req->r) 896 - return true; 897 - 898 - r = req->r; 899 - 900 - if (r->cfg) 901 - ns = r->cfg->nonsecure ? 1 : 0; 902 - else if (readl(regs + CS(thrd->id)) & CS_CNS) 903 - ns = 1; 904 - else 905 - ns = 0; 906 - 907 - /* See 'Abort Sources' point-4 at Page 2-25 */ 908 - if (_manager_ns(thrd) && !ns) 909 - dev_info(thrd->dmac->pinfo->dev, "%s:%d Recipe for ABORT!\n", 910 - __func__, __LINE__); 911 - 912 - go.chan = thrd->id; 913 - go.addr = req->mc_bus; 914 - go.ns = ns; 915 - _emit_GO(0, insn, &go); 916 - 917 - /* Set to generate interrupts for SEV */ 918 - writel(readl(regs + INTEN) | (1 << thrd->ev), regs + INTEN); 919 - 920 - /* Only manager can execute GO */ 921 - _execute_DBGINSN(thrd, insn, true); 922 - 923 - thrd->req_running = idx; 924 - 925 - return true; 926 - } 927 - 928 - static bool _start(struct pl330_thread *thrd) 929 - { 930 - switch (_state(thrd)) { 931 - case PL330_STATE_FAULT_COMPLETING: 932 - UNTIL(thrd, PL330_STATE_FAULTING | PL330_STATE_KILLING); 933 - 934 - if (_state(thrd) == PL330_STATE_KILLING) 935 - UNTIL(thrd, PL330_STATE_STOPPED) 936 - 937 - case PL330_STATE_FAULTING: 938 - _stop(thrd); 939 - 940 - case PL330_STATE_KILLING: 941 - case PL330_STATE_COMPLETING: 942 - UNTIL(thrd, PL330_STATE_STOPPED) 943 - 944 - case PL330_STATE_STOPPED: 945 - return _trigger(thrd); 946 - 947 - case PL330_STATE_WFP: 948 - case PL330_STATE_QUEUEBUSY: 949 - case PL330_STATE_ATBARRIER: 950 - case PL330_STATE_UPDTPC: 951 - case PL330_STATE_CACHEMISS: 952 - case PL330_STATE_EXECUTING: 953 - return true; 954 - 955 - case PL330_STATE_WFE: /* For RESUME, nothing yet */ 956 - default: 957 - return false; 958 - } 959 - } 960 - 961 - static inline int _ldst_memtomem(unsigned dry_run, u8 buf[], 962 - const struct _xfer_spec *pxs, int cyc) 963 - { 964 - int off = 0; 965 - 966 - while (cyc--) { 967 - off += _emit_LD(dry_run, &buf[off], ALWAYS); 968 - off += _emit_RMB(dry_run, &buf[off]); 969 - off += _emit_ST(dry_run, &buf[off], ALWAYS); 970 - off += _emit_WMB(dry_run, &buf[off]); 971 - } 972 - 973 - return off; 974 - } 975 - 976 - static inline int _ldst_devtomem(unsigned dry_run, u8 buf[], 977 - const struct _xfer_spec *pxs, int cyc) 978 - { 979 - int off = 0; 980 - 981 - while (cyc--) { 982 - off += _emit_WFP(dry_run, &buf[off], SINGLE, pxs->r->peri); 983 - off += _emit_LDP(dry_run, &buf[off], SINGLE, pxs->r->peri); 984 - off += _emit_ST(dry_run, &buf[off], ALWAYS); 985 - off += _emit_FLUSHP(dry_run, &buf[off], pxs->r->peri); 986 - } 987 - 988 - return off; 989 - } 990 - 991 - static inline int _ldst_memtodev(unsigned dry_run, u8 buf[], 992 - const struct _xfer_spec *pxs, int cyc) 993 - { 994 - int off = 0; 995 - 996 - while (cyc--) { 997 - off += _emit_WFP(dry_run, &buf[off], SINGLE, pxs->r->peri); 998 - off += _emit_LD(dry_run, &buf[off], ALWAYS); 999 - off += _emit_STP(dry_run, &buf[off], SINGLE, pxs->r->peri); 1000 - off += _emit_FLUSHP(dry_run, &buf[off], pxs->r->peri); 1001 - } 1002 - 1003 - return off; 1004 - } 1005 - 1006 - static int _bursts(unsigned dry_run, u8 buf[], 1007 - const struct _xfer_spec *pxs, int cyc) 1008 - { 1009 - int off = 0; 1010 - 1011 - switch (pxs->r->rqtype) { 1012 - case MEMTODEV: 1013 - off += _ldst_memtodev(dry_run, &buf[off], pxs, cyc); 1014 - break; 1015 - case DEVTOMEM: 1016 - off += _ldst_devtomem(dry_run, &buf[off], pxs, cyc); 1017 - break; 1018 - case MEMTOMEM: 1019 - off += _ldst_memtomem(dry_run, &buf[off], pxs, cyc); 1020 - break; 1021 - default: 1022 - off += 0x40000000; /* Scare off the Client */ 1023 - break; 1024 - } 1025 - 1026 - return off; 1027 - } 1028 - 1029 - /* Returns bytes consumed and updates bursts */ 1030 - static inline int _loop(unsigned dry_run, u8 buf[], 1031 - unsigned long *bursts, const struct _xfer_spec *pxs) 1032 - { 1033 - int cyc, cycmax, szlp, szlpend, szbrst, off; 1034 - unsigned lcnt0, lcnt1, ljmp0, ljmp1; 1035 - struct _arg_LPEND lpend; 1036 - 1037 - /* Max iterations possible in DMALP is 256 */ 1038 - if (*bursts >= 256*256) { 1039 - lcnt1 = 256; 1040 - lcnt0 = 256; 1041 - cyc = *bursts / lcnt1 / lcnt0; 1042 - } else if (*bursts > 256) { 1043 - lcnt1 = 256; 1044 - lcnt0 = *bursts / lcnt1; 1045 - cyc = 1; 1046 - } else { 1047 - lcnt1 = *bursts; 1048 - lcnt0 = 0; 1049 - cyc = 1; 1050 - } 1051 - 1052 - szlp = _emit_LP(1, buf, 0, 0); 1053 - szbrst = _bursts(1, buf, pxs, 1); 1054 - 1055 - lpend.cond = ALWAYS; 1056 - lpend.forever = false; 1057 - lpend.loop = 0; 1058 - lpend.bjump = 0; 1059 - szlpend = _emit_LPEND(1, buf, &lpend); 1060 - 1061 - if (lcnt0) { 1062 - szlp *= 2; 1063 - szlpend *= 2; 1064 - } 1065 - 1066 - /* 1067 - * Max bursts that we can unroll due to limit on the 1068 - * size of backward jump that can be encoded in DMALPEND 1069 - * which is 8-bits and hence 255 1070 - */ 1071 - cycmax = (255 - (szlp + szlpend)) / szbrst; 1072 - 1073 - cyc = (cycmax < cyc) ? cycmax : cyc; 1074 - 1075 - off = 0; 1076 - 1077 - if (lcnt0) { 1078 - off += _emit_LP(dry_run, &buf[off], 0, lcnt0); 1079 - ljmp0 = off; 1080 - } 1081 - 1082 - off += _emit_LP(dry_run, &buf[off], 1, lcnt1); 1083 - ljmp1 = off; 1084 - 1085 - off += _bursts(dry_run, &buf[off], pxs, cyc); 1086 - 1087 - lpend.cond = ALWAYS; 1088 - lpend.forever = false; 1089 - lpend.loop = 1; 1090 - lpend.bjump = off - ljmp1; 1091 - off += _emit_LPEND(dry_run, &buf[off], &lpend); 1092 - 1093 - if (lcnt0) { 1094 - lpend.cond = ALWAYS; 1095 - lpend.forever = false; 1096 - lpend.loop = 0; 1097 - lpend.bjump = off - ljmp0; 1098 - off += _emit_LPEND(dry_run, &buf[off], &lpend); 1099 - } 1100 - 1101 - *bursts = lcnt1 * cyc; 1102 - if (lcnt0) 1103 - *bursts *= lcnt0; 1104 - 1105 - return off; 1106 - } 1107 - 1108 - static inline int _setup_loops(unsigned dry_run, u8 buf[], 1109 - const struct _xfer_spec *pxs) 1110 - { 1111 - struct pl330_xfer *x = pxs->x; 1112 - u32 ccr = pxs->ccr; 1113 - unsigned long c, bursts = BYTE_TO_BURST(x->bytes, ccr); 1114 - int off = 0; 1115 - 1116 - while (bursts) { 1117 - c = bursts; 1118 - off += _loop(dry_run, &buf[off], &c, pxs); 1119 - bursts -= c; 1120 - } 1121 - 1122 - return off; 1123 - } 1124 - 1125 - static inline int _setup_xfer(unsigned dry_run, u8 buf[], 1126 - const struct _xfer_spec *pxs) 1127 - { 1128 - struct pl330_xfer *x = pxs->x; 1129 - int off = 0; 1130 - 1131 - /* DMAMOV SAR, x->src_addr */ 1132 - off += _emit_MOV(dry_run, &buf[off], SAR, x->src_addr); 1133 - /* DMAMOV DAR, x->dst_addr */ 1134 - off += _emit_MOV(dry_run, &buf[off], DAR, x->dst_addr); 1135 - 1136 - /* Setup Loop(s) */ 1137 - off += _setup_loops(dry_run, &buf[off], pxs); 1138 - 1139 - return off; 1140 - } 1141 - 1142 - /* 1143 - * A req is a sequence of one or more xfer units. 1144 - * Returns the number of bytes taken to setup the MC for the req. 1145 - */ 1146 - static int _setup_req(unsigned dry_run, struct pl330_thread *thrd, 1147 - unsigned index, struct _xfer_spec *pxs) 1148 - { 1149 - struct _pl330_req *req = &thrd->req[index]; 1150 - struct pl330_xfer *x; 1151 - u8 *buf = req->mc_cpu; 1152 - int off = 0; 1153 - 1154 - PL330_DBGMC_START(req->mc_bus); 1155 - 1156 - /* DMAMOV CCR, ccr */ 1157 - off += _emit_MOV(dry_run, &buf[off], CCR, pxs->ccr); 1158 - 1159 - x = pxs->r->x; 1160 - do { 1161 - /* Error if xfer length is not aligned at burst size */ 1162 - if (x->bytes % (BRST_SIZE(pxs->ccr) * BRST_LEN(pxs->ccr))) 1163 - return -EINVAL; 1164 - 1165 - pxs->x = x; 1166 - off += _setup_xfer(dry_run, &buf[off], pxs); 1167 - 1168 - x = x->next; 1169 - } while (x); 1170 - 1171 - /* DMASEV peripheral/event */ 1172 - off += _emit_SEV(dry_run, &buf[off], thrd->ev); 1173 - /* DMAEND */ 1174 - off += _emit_END(dry_run, &buf[off]); 1175 - 1176 - return off; 1177 - } 1178 - 1179 - static inline u32 _prepare_ccr(const struct pl330_reqcfg *rqc) 1180 - { 1181 - u32 ccr = 0; 1182 - 1183 - if (rqc->src_inc) 1184 - ccr |= CC_SRCINC; 1185 - 1186 - if (rqc->dst_inc) 1187 - ccr |= CC_DSTINC; 1188 - 1189 - /* We set same protection levels for Src and DST for now */ 1190 - if (rqc->privileged) 1191 - ccr |= CC_SRCPRI | CC_DSTPRI; 1192 - if (rqc->nonsecure) 1193 - ccr |= CC_SRCNS | CC_DSTNS; 1194 - if (rqc->insnaccess) 1195 - ccr |= CC_SRCIA | CC_DSTIA; 1196 - 1197 - ccr |= (((rqc->brst_len - 1) & 0xf) << CC_SRCBRSTLEN_SHFT); 1198 - ccr |= (((rqc->brst_len - 1) & 0xf) << CC_DSTBRSTLEN_SHFT); 1199 - 1200 - ccr |= (rqc->brst_size << CC_SRCBRSTSIZE_SHFT); 1201 - ccr |= (rqc->brst_size << CC_DSTBRSTSIZE_SHFT); 1202 - 1203 - ccr |= (rqc->scctl << CC_SRCCCTRL_SHFT); 1204 - ccr |= (rqc->dcctl << CC_DSTCCTRL_SHFT); 1205 - 1206 - ccr |= (rqc->swap << CC_SWAP_SHFT); 1207 - 1208 - return ccr; 1209 - } 1210 - 1211 - static inline bool _is_valid(u32 ccr) 1212 - { 1213 - enum pl330_dstcachectrl dcctl; 1214 - enum pl330_srccachectrl scctl; 1215 - 1216 - dcctl = (ccr >> CC_DSTCCTRL_SHFT) & CC_DRCCCTRL_MASK; 1217 - scctl = (ccr >> CC_SRCCCTRL_SHFT) & CC_SRCCCTRL_MASK; 1218 - 1219 - if (dcctl == DINVALID1 || dcctl == DINVALID2 1220 - || scctl == SINVALID1 || scctl == SINVALID2) 1221 - return false; 1222 - else 1223 - return true; 1224 - } 1225 - 1226 - /* 1227 - * Submit a list of xfers after which the client wants notification. 1228 - * Client is not notified after each xfer unit, just once after all 1229 - * xfer units are done or some error occurs. 1230 - */ 1231 - int pl330_submit_req(void *ch_id, struct pl330_req *r) 1232 - { 1233 - struct pl330_thread *thrd = ch_id; 1234 - struct pl330_dmac *pl330; 1235 - struct pl330_info *pi; 1236 - struct _xfer_spec xs; 1237 - unsigned long flags; 1238 - void __iomem *regs; 1239 - unsigned idx; 1240 - u32 ccr; 1241 - int ret = 0; 1242 - 1243 - /* No Req or Unacquired Channel or DMAC */ 1244 - if (!r || !thrd || thrd->free) 1245 - return -EINVAL; 1246 - 1247 - pl330 = thrd->dmac; 1248 - pi = pl330->pinfo; 1249 - regs = pi->base; 1250 - 1251 - if (pl330->state == DYING 1252 - || pl330->dmac_tbd.reset_chan & (1 << thrd->id)) { 1253 - dev_info(thrd->dmac->pinfo->dev, "%s:%d\n", 1254 - __func__, __LINE__); 1255 - return -EAGAIN; 1256 - } 1257 - 1258 - /* If request for non-existing peripheral */ 1259 - if (r->rqtype != MEMTOMEM && r->peri >= pi->pcfg.num_peri) { 1260 - dev_info(thrd->dmac->pinfo->dev, 1261 - "%s:%d Invalid peripheral(%u)!\n", 1262 - __func__, __LINE__, r->peri); 1263 - return -EINVAL; 1264 - } 1265 - 1266 - spin_lock_irqsave(&pl330->lock, flags); 1267 - 1268 - if (_queue_full(thrd)) { 1269 - ret = -EAGAIN; 1270 - goto xfer_exit; 1271 - } 1272 - 1273 - /* Prefer Secure Channel */ 1274 - if (!_manager_ns(thrd)) 1275 - r->cfg->nonsecure = 0; 1276 - else 1277 - r->cfg->nonsecure = 1; 1278 - 1279 - /* Use last settings, if not provided */ 1280 - if (r->cfg) 1281 - ccr = _prepare_ccr(r->cfg); 1282 - else 1283 - ccr = readl(regs + CC(thrd->id)); 1284 - 1285 - /* If this req doesn't have valid xfer settings */ 1286 - if (!_is_valid(ccr)) { 1287 - ret = -EINVAL; 1288 - dev_info(thrd->dmac->pinfo->dev, "%s:%d Invalid CCR(%x)!\n", 1289 - __func__, __LINE__, ccr); 1290 - goto xfer_exit; 1291 - } 1292 - 1293 - idx = IS_FREE(&thrd->req[0]) ? 0 : 1; 1294 - 1295 - xs.ccr = ccr; 1296 - xs.r = r; 1297 - 1298 - /* First dry run to check if req is acceptable */ 1299 - ret = _setup_req(1, thrd, idx, &xs); 1300 - if (ret < 0) 1301 - goto xfer_exit; 1302 - 1303 - if (ret > pi->mcbufsz / 2) { 1304 - dev_info(thrd->dmac->pinfo->dev, 1305 - "%s:%d Trying increasing mcbufsz\n", 1306 - __func__, __LINE__); 1307 - ret = -ENOMEM; 1308 - goto xfer_exit; 1309 - } 1310 - 1311 - /* Hook the request */ 1312 - thrd->lstenq = idx; 1313 - thrd->req[idx].mc_len = _setup_req(0, thrd, idx, &xs); 1314 - thrd->req[idx].r = r; 1315 - 1316 - ret = 0; 1317 - 1318 - xfer_exit: 1319 - spin_unlock_irqrestore(&pl330->lock, flags); 1320 - 1321 - return ret; 1322 - } 1323 - EXPORT_SYMBOL(pl330_submit_req); 1324 - 1325 - static void pl330_dotask(unsigned long data) 1326 - { 1327 - struct pl330_dmac *pl330 = (struct pl330_dmac *) data; 1328 - struct pl330_info *pi = pl330->pinfo; 1329 - unsigned long flags; 1330 - int i; 1331 - 1332 - spin_lock_irqsave(&pl330->lock, flags); 1333 - 1334 - /* The DMAC itself gone nuts */ 1335 - if (pl330->dmac_tbd.reset_dmac) { 1336 - pl330->state = DYING; 1337 - /* Reset the manager too */ 1338 - pl330->dmac_tbd.reset_mngr = true; 1339 - /* Clear the reset flag */ 1340 - pl330->dmac_tbd.reset_dmac = false; 1341 - } 1342 - 1343 - if (pl330->dmac_tbd.reset_mngr) { 1344 - _stop(pl330->manager); 1345 - /* Reset all channels */ 1346 - pl330->dmac_tbd.reset_chan = (1 << pi->pcfg.num_chan) - 1; 1347 - /* Clear the reset flag */ 1348 - pl330->dmac_tbd.reset_mngr = false; 1349 - } 1350 - 1351 - for (i = 0; i < pi->pcfg.num_chan; i++) { 1352 - 1353 - if (pl330->dmac_tbd.reset_chan & (1 << i)) { 1354 - struct pl330_thread *thrd = &pl330->channels[i]; 1355 - void __iomem *regs = pi->base; 1356 - enum pl330_op_err err; 1357 - 1358 - _stop(thrd); 1359 - 1360 - if (readl(regs + FSC) & (1 << thrd->id)) 1361 - err = PL330_ERR_FAIL; 1362 - else 1363 - err = PL330_ERR_ABORT; 1364 - 1365 - spin_unlock_irqrestore(&pl330->lock, flags); 1366 - 1367 - _callback(thrd->req[1 - thrd->lstenq].r, err); 1368 - _callback(thrd->req[thrd->lstenq].r, err); 1369 - 1370 - spin_lock_irqsave(&pl330->lock, flags); 1371 - 1372 - thrd->req[0].r = NULL; 1373 - thrd->req[1].r = NULL; 1374 - mark_free(thrd, 0); 1375 - mark_free(thrd, 1); 1376 - 1377 - /* Clear the reset flag */ 1378 - pl330->dmac_tbd.reset_chan &= ~(1 << i); 1379 - } 1380 - } 1381 - 1382 - spin_unlock_irqrestore(&pl330->lock, flags); 1383 - 1384 - return; 1385 - } 1386 - 1387 - /* Returns 1 if state was updated, 0 otherwise */ 1388 - int pl330_update(const struct pl330_info *pi) 1389 - { 1390 - struct _pl330_req *rqdone; 1391 - struct pl330_dmac *pl330; 1392 - unsigned long flags; 1393 - void __iomem *regs; 1394 - u32 val; 1395 - int id, ev, ret = 0; 1396 - 1397 - if (!pi || !pi->pl330_data) 1398 - return 0; 1399 - 1400 - regs = pi->base; 1401 - pl330 = pi->pl330_data; 1402 - 1403 - spin_lock_irqsave(&pl330->lock, flags); 1404 - 1405 - val = readl(regs + FSM) & 0x1; 1406 - if (val) 1407 - pl330->dmac_tbd.reset_mngr = true; 1408 - else 1409 - pl330->dmac_tbd.reset_mngr = false; 1410 - 1411 - val = readl(regs + FSC) & ((1 << pi->pcfg.num_chan) - 1); 1412 - pl330->dmac_tbd.reset_chan |= val; 1413 - if (val) { 1414 - int i = 0; 1415 - while (i < pi->pcfg.num_chan) { 1416 - if (val & (1 << i)) { 1417 - dev_info(pi->dev, 1418 - "Reset Channel-%d\t CS-%x FTC-%x\n", 1419 - i, readl(regs + CS(i)), 1420 - readl(regs + FTC(i))); 1421 - _stop(&pl330->channels[i]); 1422 - } 1423 - i++; 1424 - } 1425 - } 1426 - 1427 - /* Check which event happened i.e, thread notified */ 1428 - val = readl(regs + ES); 1429 - if (pi->pcfg.num_events < 32 1430 - && val & ~((1 << pi->pcfg.num_events) - 1)) { 1431 - pl330->dmac_tbd.reset_dmac = true; 1432 - dev_err(pi->dev, "%s:%d Unexpected!\n", __func__, __LINE__); 1433 - ret = 1; 1434 - goto updt_exit; 1435 - } 1436 - 1437 - for (ev = 0; ev < pi->pcfg.num_events; ev++) { 1438 - if (val & (1 << ev)) { /* Event occurred */ 1439 - struct pl330_thread *thrd; 1440 - u32 inten = readl(regs + INTEN); 1441 - int active; 1442 - 1443 - /* Clear the event */ 1444 - if (inten & (1 << ev)) 1445 - writel(1 << ev, regs + INTCLR); 1446 - 1447 - ret = 1; 1448 - 1449 - id = pl330->events[ev]; 1450 - 1451 - thrd = &pl330->channels[id]; 1452 - 1453 - active = thrd->req_running; 1454 - if (active == -1) /* Aborted */ 1455 - continue; 1456 - 1457 - rqdone = &thrd->req[active]; 1458 - mark_free(thrd, active); 1459 - 1460 - /* Get going again ASAP */ 1461 - _start(thrd); 1462 - 1463 - /* For now, just make a list of callbacks to be done */ 1464 - list_add_tail(&rqdone->rqd, &pl330->req_done); 1465 - } 1466 - } 1467 - 1468 - /* Now that we are in no hurry, do the callbacks */ 1469 - while (!list_empty(&pl330->req_done)) { 1470 - struct pl330_req *r; 1471 - 1472 - rqdone = container_of(pl330->req_done.next, 1473 - struct _pl330_req, rqd); 1474 - 1475 - list_del_init(&rqdone->rqd); 1476 - 1477 - /* Detach the req */ 1478 - r = rqdone->r; 1479 - rqdone->r = NULL; 1480 - 1481 - spin_unlock_irqrestore(&pl330->lock, flags); 1482 - _callback(r, PL330_ERR_NONE); 1483 - spin_lock_irqsave(&pl330->lock, flags); 1484 - } 1485 - 1486 - updt_exit: 1487 - spin_unlock_irqrestore(&pl330->lock, flags); 1488 - 1489 - if (pl330->dmac_tbd.reset_dmac 1490 - || pl330->dmac_tbd.reset_mngr 1491 - || pl330->dmac_tbd.reset_chan) { 1492 - ret = 1; 1493 - tasklet_schedule(&pl330->tasks); 1494 - } 1495 - 1496 - return ret; 1497 - } 1498 - EXPORT_SYMBOL(pl330_update); 1499 - 1500 - int pl330_chan_ctrl(void *ch_id, enum pl330_chan_op op) 1501 - { 1502 - struct pl330_thread *thrd = ch_id; 1503 - struct pl330_dmac *pl330; 1504 - unsigned long flags; 1505 - int ret = 0, active; 1506 - 1507 - if (!thrd || thrd->free || thrd->dmac->state == DYING) 1508 - return -EINVAL; 1509 - 1510 - pl330 = thrd->dmac; 1511 - active = thrd->req_running; 1512 - 1513 - spin_lock_irqsave(&pl330->lock, flags); 1514 - 1515 - switch (op) { 1516 - case PL330_OP_FLUSH: 1517 - /* Make sure the channel is stopped */ 1518 - _stop(thrd); 1519 - 1520 - thrd->req[0].r = NULL; 1521 - thrd->req[1].r = NULL; 1522 - mark_free(thrd, 0); 1523 - mark_free(thrd, 1); 1524 - break; 1525 - 1526 - case PL330_OP_ABORT: 1527 - /* Make sure the channel is stopped */ 1528 - _stop(thrd); 1529 - 1530 - /* ABORT is only for the active req */ 1531 - if (active == -1) 1532 - break; 1533 - 1534 - thrd->req[active].r = NULL; 1535 - mark_free(thrd, active); 1536 - 1537 - /* Start the next */ 1538 - case PL330_OP_START: 1539 - if ((active == -1) && !_start(thrd)) 1540 - ret = -EIO; 1541 - break; 1542 - 1543 - default: 1544 - ret = -EINVAL; 1545 - } 1546 - 1547 - spin_unlock_irqrestore(&pl330->lock, flags); 1548 - return ret; 1549 - } 1550 - EXPORT_SYMBOL(pl330_chan_ctrl); 1551 - 1552 - int pl330_chan_status(void *ch_id, struct pl330_chanstatus *pstatus) 1553 - { 1554 - struct pl330_thread *thrd = ch_id; 1555 - struct pl330_dmac *pl330; 1556 - struct pl330_info *pi; 1557 - void __iomem *regs; 1558 - int active; 1559 - u32 val; 1560 - 1561 - if (!pstatus || !thrd || thrd->free) 1562 - return -EINVAL; 1563 - 1564 - pl330 = thrd->dmac; 1565 - pi = pl330->pinfo; 1566 - regs = pi->base; 1567 - 1568 - /* The client should remove the DMAC and add again */ 1569 - if (pl330->state == DYING) 1570 - pstatus->dmac_halted = true; 1571 - else 1572 - pstatus->dmac_halted = false; 1573 - 1574 - val = readl(regs + FSC); 1575 - if (val & (1 << thrd->id)) 1576 - pstatus->faulting = true; 1577 - else 1578 - pstatus->faulting = false; 1579 - 1580 - active = thrd->req_running; 1581 - 1582 - if (active == -1) { 1583 - /* Indicate that the thread is not running */ 1584 - pstatus->top_req = NULL; 1585 - pstatus->wait_req = NULL; 1586 - } else { 1587 - pstatus->top_req = thrd->req[active].r; 1588 - pstatus->wait_req = !IS_FREE(&thrd->req[1 - active]) 1589 - ? thrd->req[1 - active].r : NULL; 1590 - } 1591 - 1592 - pstatus->src_addr = readl(regs + SA(thrd->id)); 1593 - pstatus->dst_addr = readl(regs + DA(thrd->id)); 1594 - 1595 - return 0; 1596 - } 1597 - EXPORT_SYMBOL(pl330_chan_status); 1598 - 1599 - /* Reserve an event */ 1600 - static inline int _alloc_event(struct pl330_thread *thrd) 1601 - { 1602 - struct pl330_dmac *pl330 = thrd->dmac; 1603 - struct pl330_info *pi = pl330->pinfo; 1604 - int ev; 1605 - 1606 - for (ev = 0; ev < pi->pcfg.num_events; ev++) 1607 - if (pl330->events[ev] == -1) { 1608 - pl330->events[ev] = thrd->id; 1609 - return ev; 1610 - } 1611 - 1612 - return -1; 1613 - } 1614 - 1615 - static bool _chan_ns(const struct pl330_info *pi, int i) 1616 - { 1617 - return pi->pcfg.irq_ns & (1 << i); 1618 - } 1619 - 1620 - /* Upon success, returns IdentityToken for the 1621 - * allocated channel, NULL otherwise. 1622 - */ 1623 - void *pl330_request_channel(const struct pl330_info *pi) 1624 - { 1625 - struct pl330_thread *thrd = NULL; 1626 - struct pl330_dmac *pl330; 1627 - unsigned long flags; 1628 - int chans, i; 1629 - 1630 - if (!pi || !pi->pl330_data) 1631 - return NULL; 1632 - 1633 - pl330 = pi->pl330_data; 1634 - 1635 - if (pl330->state == DYING) 1636 - return NULL; 1637 - 1638 - chans = pi->pcfg.num_chan; 1639 - 1640 - spin_lock_irqsave(&pl330->lock, flags); 1641 - 1642 - for (i = 0; i < chans; i++) { 1643 - thrd = &pl330->channels[i]; 1644 - if ((thrd->free) && (!_manager_ns(thrd) || 1645 - _chan_ns(pi, i))) { 1646 - thrd->ev = _alloc_event(thrd); 1647 - if (thrd->ev >= 0) { 1648 - thrd->free = false; 1649 - thrd->lstenq = 1; 1650 - thrd->req[0].r = NULL; 1651 - mark_free(thrd, 0); 1652 - thrd->req[1].r = NULL; 1653 - mark_free(thrd, 1); 1654 - break; 1655 - } 1656 - } 1657 - thrd = NULL; 1658 - } 1659 - 1660 - spin_unlock_irqrestore(&pl330->lock, flags); 1661 - 1662 - return thrd; 1663 - } 1664 - EXPORT_SYMBOL(pl330_request_channel); 1665 - 1666 - /* Release an event */ 1667 - static inline void _free_event(struct pl330_thread *thrd, int ev) 1668 - { 1669 - struct pl330_dmac *pl330 = thrd->dmac; 1670 - struct pl330_info *pi = pl330->pinfo; 1671 - 1672 - /* If the event is valid and was held by the thread */ 1673 - if (ev >= 0 && ev < pi->pcfg.num_events 1674 - && pl330->events[ev] == thrd->id) 1675 - pl330->events[ev] = -1; 1676 - } 1677 - 1678 - void pl330_release_channel(void *ch_id) 1679 - { 1680 - struct pl330_thread *thrd = ch_id; 1681 - struct pl330_dmac *pl330; 1682 - unsigned long flags; 1683 - 1684 - if (!thrd || thrd->free) 1685 - return; 1686 - 1687 - _stop(thrd); 1688 - 1689 - _callback(thrd->req[1 - thrd->lstenq].r, PL330_ERR_ABORT); 1690 - _callback(thrd->req[thrd->lstenq].r, PL330_ERR_ABORT); 1691 - 1692 - pl330 = thrd->dmac; 1693 - 1694 - spin_lock_irqsave(&pl330->lock, flags); 1695 - _free_event(thrd, thrd->ev); 1696 - thrd->free = true; 1697 - spin_unlock_irqrestore(&pl330->lock, flags); 1698 - } 1699 - EXPORT_SYMBOL(pl330_release_channel); 1700 - 1701 - /* Initialize the structure for PL330 configuration, that can be used 1702 - * by the client driver the make best use of the DMAC 1703 - */ 1704 - static void read_dmac_config(struct pl330_info *pi) 1705 - { 1706 - void __iomem *regs = pi->base; 1707 - u32 val; 1708 - 1709 - val = readl(regs + CRD) >> CRD_DATA_WIDTH_SHIFT; 1710 - val &= CRD_DATA_WIDTH_MASK; 1711 - pi->pcfg.data_bus_width = 8 * (1 << val); 1712 - 1713 - val = readl(regs + CRD) >> CRD_DATA_BUFF_SHIFT; 1714 - val &= CRD_DATA_BUFF_MASK; 1715 - pi->pcfg.data_buf_dep = val + 1; 1716 - 1717 - val = readl(regs + CR0) >> CR0_NUM_CHANS_SHIFT; 1718 - val &= CR0_NUM_CHANS_MASK; 1719 - val += 1; 1720 - pi->pcfg.num_chan = val; 1721 - 1722 - val = readl(regs + CR0); 1723 - if (val & CR0_PERIPH_REQ_SET) { 1724 - val = (val >> CR0_NUM_PERIPH_SHIFT) & CR0_NUM_PERIPH_MASK; 1725 - val += 1; 1726 - pi->pcfg.num_peri = val; 1727 - pi->pcfg.peri_ns = readl(regs + CR4); 1728 - } else { 1729 - pi->pcfg.num_peri = 0; 1730 - } 1731 - 1732 - val = readl(regs + CR0); 1733 - if (val & CR0_BOOT_MAN_NS) 1734 - pi->pcfg.mode |= DMAC_MODE_NS; 1735 - else 1736 - pi->pcfg.mode &= ~DMAC_MODE_NS; 1737 - 1738 - val = readl(regs + CR0) >> CR0_NUM_EVENTS_SHIFT; 1739 - val &= CR0_NUM_EVENTS_MASK; 1740 - val += 1; 1741 - pi->pcfg.num_events = val; 1742 - 1743 - pi->pcfg.irq_ns = readl(regs + CR3); 1744 - 1745 - pi->pcfg.periph_id = get_id(pi, PERIPH_ID); 1746 - pi->pcfg.pcell_id = get_id(pi, PCELL_ID); 1747 - } 1748 - 1749 - static inline void _reset_thread(struct pl330_thread *thrd) 1750 - { 1751 - struct pl330_dmac *pl330 = thrd->dmac; 1752 - struct pl330_info *pi = pl330->pinfo; 1753 - 1754 - thrd->req[0].mc_cpu = pl330->mcode_cpu 1755 - + (thrd->id * pi->mcbufsz); 1756 - thrd->req[0].mc_bus = pl330->mcode_bus 1757 - + (thrd->id * pi->mcbufsz); 1758 - thrd->req[0].r = NULL; 1759 - mark_free(thrd, 0); 1760 - 1761 - thrd->req[1].mc_cpu = thrd->req[0].mc_cpu 1762 - + pi->mcbufsz / 2; 1763 - thrd->req[1].mc_bus = thrd->req[0].mc_bus 1764 - + pi->mcbufsz / 2; 1765 - thrd->req[1].r = NULL; 1766 - mark_free(thrd, 1); 1767 - } 1768 - 1769 - static int dmac_alloc_threads(struct pl330_dmac *pl330) 1770 - { 1771 - struct pl330_info *pi = pl330->pinfo; 1772 - int chans = pi->pcfg.num_chan; 1773 - struct pl330_thread *thrd; 1774 - int i; 1775 - 1776 - /* Allocate 1 Manager and 'chans' Channel threads */ 1777 - pl330->channels = kzalloc((1 + chans) * sizeof(*thrd), 1778 - GFP_KERNEL); 1779 - if (!pl330->channels) 1780 - return -ENOMEM; 1781 - 1782 - /* Init Channel threads */ 1783 - for (i = 0; i < chans; i++) { 1784 - thrd = &pl330->channels[i]; 1785 - thrd->id = i; 1786 - thrd->dmac = pl330; 1787 - _reset_thread(thrd); 1788 - thrd->free = true; 1789 - } 1790 - 1791 - /* MANAGER is indexed at the end */ 1792 - thrd = &pl330->channels[chans]; 1793 - thrd->id = chans; 1794 - thrd->dmac = pl330; 1795 - thrd->free = false; 1796 - pl330->manager = thrd; 1797 - 1798 - return 0; 1799 - } 1800 - 1801 - static int dmac_alloc_resources(struct pl330_dmac *pl330) 1802 - { 1803 - struct pl330_info *pi = pl330->pinfo; 1804 - int chans = pi->pcfg.num_chan; 1805 - int ret; 1806 - 1807 - /* 1808 - * Alloc MicroCode buffer for 'chans' Channel threads. 1809 - * A channel's buffer offset is (Channel_Id * MCODE_BUFF_PERCHAN) 1810 - */ 1811 - pl330->mcode_cpu = dma_alloc_coherent(pi->dev, 1812 - chans * pi->mcbufsz, 1813 - &pl330->mcode_bus, GFP_KERNEL); 1814 - if (!pl330->mcode_cpu) { 1815 - dev_err(pi->dev, "%s:%d Can't allocate memory!\n", 1816 - __func__, __LINE__); 1817 - return -ENOMEM; 1818 - } 1819 - 1820 - ret = dmac_alloc_threads(pl330); 1821 - if (ret) { 1822 - dev_err(pi->dev, "%s:%d Can't to create channels for DMAC!\n", 1823 - __func__, __LINE__); 1824 - dma_free_coherent(pi->dev, 1825 - chans * pi->mcbufsz, 1826 - pl330->mcode_cpu, pl330->mcode_bus); 1827 - return ret; 1828 - } 1829 - 1830 - return 0; 1831 - } 1832 - 1833 - int pl330_add(struct pl330_info *pi) 1834 - { 1835 - struct pl330_dmac *pl330; 1836 - void __iomem *regs; 1837 - int i, ret; 1838 - 1839 - if (!pi || !pi->dev) 1840 - return -EINVAL; 1841 - 1842 - /* If already added */ 1843 - if (pi->pl330_data) 1844 - return -EINVAL; 1845 - 1846 - /* 1847 - * If the SoC can perform reset on the DMAC, then do it 1848 - * before reading its configuration. 1849 - */ 1850 - if (pi->dmac_reset) 1851 - pi->dmac_reset(pi); 1852 - 1853 - regs = pi->base; 1854 - 1855 - /* Check if we can handle this DMAC */ 1856 - if ((get_id(pi, PERIPH_ID) & 0xfffff) != PERIPH_ID_VAL 1857 - || get_id(pi, PCELL_ID) != PCELL_ID_VAL) { 1858 - dev_err(pi->dev, "PERIPH_ID 0x%x, PCELL_ID 0x%x !\n", 1859 - get_id(pi, PERIPH_ID), get_id(pi, PCELL_ID)); 1860 - return -EINVAL; 1861 - } 1862 - 1863 - /* Read the configuration of the DMAC */ 1864 - read_dmac_config(pi); 1865 - 1866 - if (pi->pcfg.num_events == 0) { 1867 - dev_err(pi->dev, "%s:%d Can't work without events!\n", 1868 - __func__, __LINE__); 1869 - return -EINVAL; 1870 - } 1871 - 1872 - pl330 = kzalloc(sizeof(*pl330), GFP_KERNEL); 1873 - if (!pl330) { 1874 - dev_err(pi->dev, "%s:%d Can't allocate memory!\n", 1875 - __func__, __LINE__); 1876 - return -ENOMEM; 1877 - } 1878 - 1879 - /* Assign the info structure and private data */ 1880 - pl330->pinfo = pi; 1881 - pi->pl330_data = pl330; 1882 - 1883 - spin_lock_init(&pl330->lock); 1884 - 1885 - INIT_LIST_HEAD(&pl330->req_done); 1886 - 1887 - /* Use default MC buffer size if not provided */ 1888 - if (!pi->mcbufsz) 1889 - pi->mcbufsz = MCODE_BUFF_PER_REQ * 2; 1890 - 1891 - /* Mark all events as free */ 1892 - for (i = 0; i < pi->pcfg.num_events; i++) 1893 - pl330->events[i] = -1; 1894 - 1895 - /* Allocate resources needed by the DMAC */ 1896 - ret = dmac_alloc_resources(pl330); 1897 - if (ret) { 1898 - dev_err(pi->dev, "Unable to create channels for DMAC\n"); 1899 - kfree(pl330); 1900 - return ret; 1901 - } 1902 - 1903 - tasklet_init(&pl330->tasks, pl330_dotask, (unsigned long) pl330); 1904 - 1905 - pl330->state = INIT; 1906 - 1907 - return 0; 1908 - } 1909 - EXPORT_SYMBOL(pl330_add); 1910 - 1911 - static int dmac_free_threads(struct pl330_dmac *pl330) 1912 - { 1913 - struct pl330_info *pi = pl330->pinfo; 1914 - int chans = pi->pcfg.num_chan; 1915 - struct pl330_thread *thrd; 1916 - int i; 1917 - 1918 - /* Release Channel threads */ 1919 - for (i = 0; i < chans; i++) { 1920 - thrd = &pl330->channels[i]; 1921 - pl330_release_channel((void *)thrd); 1922 - } 1923 - 1924 - /* Free memory */ 1925 - kfree(pl330->channels); 1926 - 1927 - return 0; 1928 - } 1929 - 1930 - static void dmac_free_resources(struct pl330_dmac *pl330) 1931 - { 1932 - struct pl330_info *pi = pl330->pinfo; 1933 - int chans = pi->pcfg.num_chan; 1934 - 1935 - dmac_free_threads(pl330); 1936 - 1937 - dma_free_coherent(pi->dev, chans * pi->mcbufsz, 1938 - pl330->mcode_cpu, pl330->mcode_bus); 1939 - } 1940 - 1941 - void pl330_del(struct pl330_info *pi) 1942 - { 1943 - struct pl330_dmac *pl330; 1944 - 1945 - if (!pi || !pi->pl330_data) 1946 - return; 1947 - 1948 - pl330 = pi->pl330_data; 1949 - 1950 - pl330->state = UNINIT; 1951 - 1952 - tasklet_kill(&pl330->tasks); 1953 - 1954 - /* Free DMAC resources */ 1955 - dmac_free_resources(pl330); 1956 - 1957 - kfree(pl330); 1958 - pi->pl330_data = NULL; 1959 - } 1960 - EXPORT_SYMBOL(pl330_del);
-2
arch/arm/include/asm/hardware/iop_adma.h
··· 49 49 /** 50 50 * struct iop_adma_chan - internal representation of an ADMA device 51 51 * @pending: allows batching of hardware operations 52 - * @completed_cookie: identifier for the most recently completed operation 53 52 * @lock: serializes enqueue/dequeue operations to the slot pool 54 53 * @mmr_base: memory mapped register base 55 54 * @chain: device chain view of the descriptors ··· 61 62 */ 62 63 struct iop_adma_chan { 63 64 int pending; 64 - dma_cookie_t completed_cookie; 65 65 spinlock_t lock; /* protects the descriptor slot pool */ 66 66 void __iomem *mmr_base; 67 67 struct list_head chain;
-217
arch/arm/include/asm/hardware/pl330.h
··· 1 - /* linux/include/asm/hardware/pl330.h 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 - 21 - #ifndef __PL330_CORE_H 22 - #define __PL330_CORE_H 23 - 24 - #define PL330_MAX_CHAN 8 25 - #define PL330_MAX_IRQS 32 26 - #define PL330_MAX_PERI 32 27 - 28 - enum pl330_srccachectrl { 29 - SCCTRL0 = 0, /* Noncacheable and nonbufferable */ 30 - SCCTRL1, /* Bufferable only */ 31 - SCCTRL2, /* Cacheable, but do not allocate */ 32 - SCCTRL3, /* Cacheable and bufferable, but do not allocate */ 33 - SINVALID1, 34 - SINVALID2, 35 - SCCTRL6, /* Cacheable write-through, allocate on reads only */ 36 - SCCTRL7, /* Cacheable write-back, allocate on reads only */ 37 - }; 38 - 39 - enum pl330_dstcachectrl { 40 - DCCTRL0 = 0, /* Noncacheable and nonbufferable */ 41 - DCCTRL1, /* Bufferable only */ 42 - DCCTRL2, /* Cacheable, but do not allocate */ 43 - DCCTRL3, /* Cacheable and bufferable, but do not allocate */ 44 - DINVALID1, /* AWCACHE = 0x1000 */ 45 - DINVALID2, 46 - DCCTRL6, /* Cacheable write-through, allocate on writes only */ 47 - DCCTRL7, /* Cacheable write-back, allocate on writes only */ 48 - }; 49 - 50 - /* Populated by the PL330 core driver for DMA API driver's info */ 51 - struct pl330_config { 52 - u32 periph_id; 53 - u32 pcell_id; 54 - #define DMAC_MODE_NS (1 << 0) 55 - unsigned int mode; 56 - unsigned int data_bus_width:10; /* In number of bits */ 57 - unsigned int data_buf_dep:10; 58 - unsigned int num_chan:4; 59 - unsigned int num_peri:6; 60 - u32 peri_ns; 61 - unsigned int num_events:6; 62 - u32 irq_ns; 63 - }; 64 - 65 - /* Handle to the DMAC provided to the PL330 core */ 66 - struct pl330_info { 67 - /* Owning device */ 68 - struct device *dev; 69 - /* Size of MicroCode buffers for each channel. */ 70 - unsigned mcbufsz; 71 - /* ioremap'ed address of PL330 registers. */ 72 - void __iomem *base; 73 - /* Client can freely use it. */ 74 - void *client_data; 75 - /* PL330 core data, Client must not touch it. */ 76 - void *pl330_data; 77 - /* Populated by the PL330 core driver during pl330_add */ 78 - struct pl330_config pcfg; 79 - /* 80 - * If the DMAC has some reset mechanism, then the 81 - * client may want to provide pointer to the method. 82 - */ 83 - void (*dmac_reset)(struct pl330_info *pi); 84 - }; 85 - 86 - enum pl330_byteswap { 87 - SWAP_NO = 0, 88 - SWAP_2, 89 - SWAP_4, 90 - SWAP_8, 91 - SWAP_16, 92 - }; 93 - 94 - /** 95 - * Request Configuration. 96 - * The PL330 core does not modify this and uses the last 97 - * working configuration if the request doesn't provide any. 98 - * 99 - * The Client may want to provide this info only for the 100 - * first request and a request with new settings. 101 - */ 102 - struct pl330_reqcfg { 103 - /* Address Incrementing */ 104 - unsigned dst_inc:1; 105 - unsigned src_inc:1; 106 - 107 - /* 108 - * For now, the SRC & DST protection levels 109 - * and burst size/length are assumed same. 110 - */ 111 - bool nonsecure; 112 - bool privileged; 113 - bool insnaccess; 114 - unsigned brst_len:5; 115 - unsigned brst_size:3; /* in power of 2 */ 116 - 117 - enum pl330_dstcachectrl dcctl; 118 - enum pl330_srccachectrl scctl; 119 - enum pl330_byteswap swap; 120 - }; 121 - 122 - /* 123 - * One cycle of DMAC operation. 124 - * There may be more than one xfer in a request. 125 - */ 126 - struct pl330_xfer { 127 - u32 src_addr; 128 - u32 dst_addr; 129 - /* Size to xfer */ 130 - u32 bytes; 131 - /* 132 - * Pointer to next xfer in the list. 133 - * The last xfer in the req must point to NULL. 134 - */ 135 - struct pl330_xfer *next; 136 - }; 137 - 138 - /* The xfer callbacks are made with one of these arguments. */ 139 - enum pl330_op_err { 140 - /* The all xfers in the request were success. */ 141 - PL330_ERR_NONE, 142 - /* If req aborted due to global error. */ 143 - PL330_ERR_ABORT, 144 - /* If req failed due to problem with Channel. */ 145 - PL330_ERR_FAIL, 146 - }; 147 - 148 - enum pl330_reqtype { 149 - MEMTOMEM, 150 - MEMTODEV, 151 - DEVTOMEM, 152 - DEVTODEV, 153 - }; 154 - 155 - /* A request defining Scatter-Gather List ending with NULL xfer. */ 156 - struct pl330_req { 157 - enum pl330_reqtype rqtype; 158 - /* Index of peripheral for the xfer. */ 159 - unsigned peri:5; 160 - /* Unique token for this xfer, set by the client. */ 161 - void *token; 162 - /* Callback to be called after xfer. */ 163 - void (*xfer_cb)(void *token, enum pl330_op_err err); 164 - /* If NULL, req will be done at last set parameters. */ 165 - struct pl330_reqcfg *cfg; 166 - /* Pointer to first xfer in the request. */ 167 - struct pl330_xfer *x; 168 - }; 169 - 170 - /* 171 - * To know the status of the channel and DMAC, the client 172 - * provides a pointer to this structure. The PL330 core 173 - * fills it with current information. 174 - */ 175 - struct pl330_chanstatus { 176 - /* 177 - * If the DMAC engine halted due to some error, 178 - * the client should remove-add DMAC. 179 - */ 180 - bool dmac_halted; 181 - /* 182 - * If channel is halted due to some error, 183 - * the client should ABORT/FLUSH and START the channel. 184 - */ 185 - bool faulting; 186 - /* Location of last load */ 187 - u32 src_addr; 188 - /* Location of last store */ 189 - u32 dst_addr; 190 - /* 191 - * Pointer to the currently active req, NULL if channel is 192 - * inactive, even though the requests may be present. 193 - */ 194 - struct pl330_req *top_req; 195 - /* Pointer to req waiting second in the queue if any. */ 196 - struct pl330_req *wait_req; 197 - }; 198 - 199 - enum pl330_chan_op { 200 - /* Start the channel */ 201 - PL330_OP_START, 202 - /* Abort the active xfer */ 203 - PL330_OP_ABORT, 204 - /* Stop xfer and flush queue */ 205 - PL330_OP_FLUSH, 206 - }; 207 - 208 - extern int pl330_add(struct pl330_info *); 209 - extern void pl330_del(struct pl330_info *pi); 210 - extern int pl330_update(const struct pl330_info *pi); 211 - extern void pl330_release_channel(void *ch_id); 212 - extern void *pl330_request_channel(const struct pl330_info *pi); 213 - extern int pl330_chan_status(void *ch_id, struct pl330_chanstatus *pstatus); 214 - extern int pl330_chan_ctrl(void *ch_id, enum pl330_chan_op op); 215 - extern int pl330_submit_req(void *ch_id, struct pl330_req *r); 216 - 217 - #endif /* __PL330_CORE_H */
-1
arch/arm/mach-at91/at91sam9g45_devices.c
··· 437 437 438 438 /* DMA slave channel configuration */ 439 439 atslave->dma_dev = &at_hdmac_device.dev; 440 - atslave->reg_width = AT_DMA_SLAVE_WIDTH_32BIT; 441 440 atslave->cfg = ATC_FIFOCFG_HALFFIFO 442 441 | ATC_SRC_H2SEL_HW | ATC_DST_H2SEL_HW; 443 442 atslave->ctrla = ATC_SCSIZE_16 | ATC_DCSIZE_16;
-15
arch/arm/mach-at91/include/mach/at_hdmac.h
··· 24 24 }; 25 25 26 26 /** 27 - * enum at_dma_slave_width - DMA slave register access width. 28 - * @AT_DMA_SLAVE_WIDTH_8BIT: Do 8-bit slave register accesses 29 - * @AT_DMA_SLAVE_WIDTH_16BIT: Do 16-bit slave register accesses 30 - * @AT_DMA_SLAVE_WIDTH_32BIT: Do 32-bit slave register accesses 31 - */ 32 - enum at_dma_slave_width { 33 - AT_DMA_SLAVE_WIDTH_8BIT = 0, 34 - AT_DMA_SLAVE_WIDTH_16BIT, 35 - AT_DMA_SLAVE_WIDTH_32BIT, 36 - }; 37 - 38 - /** 39 27 * struct at_dma_slave - Controller-specific information about a slave 40 28 * @dma_dev: required DMA master device 41 29 * @tx_reg: physical address of data register used for ··· 36 48 */ 37 49 struct at_dma_slave { 38 50 struct device *dma_dev; 39 - dma_addr_t tx_reg; 40 - dma_addr_t rx_reg; 41 - enum at_dma_slave_width reg_width; 42 51 u32 cfg; 43 52 u32 ctrla; 44 53 };
-6
arch/arm/mach-imx/Kconfig
··· 1 - config IMX_HAVE_DMA_V1 2 - bool 3 - 4 1 config HAVE_IMX_GPC 5 2 bool 6 3 ··· 35 38 bool 36 39 select ARCH_MX1 37 40 select CPU_ARM920T 38 - select IMX_HAVE_DMA_V1 39 41 select IMX_HAVE_IOMUX_V1 40 42 select MXC_AVIC 41 43 ··· 42 46 bool 43 47 select MACH_MX21 44 48 select CPU_ARM926T 45 - select IMX_HAVE_DMA_V1 46 49 select IMX_HAVE_IOMUX_V1 47 50 select MXC_AVIC 48 51 ··· 56 61 bool 57 62 select MACH_MX27 58 63 select CPU_ARM926T 59 - select IMX_HAVE_DMA_V1 60 64 select IMX_HAVE_IOMUX_V1 61 65 select MXC_AVIC 62 66
-2
arch/arm/mach-imx/Makefile
··· 1 - obj-$(CONFIG_IMX_HAVE_DMA_V1) += dma-v1.o 2 - 3 1 obj-$(CONFIG_SOC_IMX1) += clock-imx1.o mm-imx1.o 4 2 obj-$(CONFIG_SOC_IMX21) += clock-imx21.o mm-imx21.o 5 3
-845
arch/arm/mach-imx/dma-v1.c
··· 1 - /* 2 - * linux/arch/arm/plat-mxc/dma-v1.c 3 - * 4 - * i.MX DMA registration and IRQ dispatching 5 - * 6 - * Copyright 2006 Pavel Pisa <pisa@cmp.felk.cvut.cz> 7 - * Copyright 2008 Juergen Beisert, <kernel@pengutronix.de> 8 - * Copyright 2008 Sascha Hauer, <s.hauer@pengutronix.de> 9 - * 10 - * This program is free software; you can redistribute it and/or 11 - * modify it under the terms of the GNU General Public License 12 - * as published by the Free Software Foundation; either version 2 13 - * of the License, or (at your option) any later version. 14 - * This program is distributed in the hope that it will be useful, 15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 - * GNU General Public License for more details. 18 - * 19 - * You should have received a copy of the GNU General Public License 20 - * along with this program; if not, write to the Free Software 21 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 22 - * MA 02110-1301, USA. 23 - */ 24 - 25 - #include <linux/module.h> 26 - #include <linux/init.h> 27 - #include <linux/kernel.h> 28 - #include <linux/interrupt.h> 29 - #include <linux/err.h> 30 - #include <linux/errno.h> 31 - #include <linux/clk.h> 32 - #include <linux/scatterlist.h> 33 - #include <linux/io.h> 34 - 35 - #include <asm/irq.h> 36 - #include <mach/hardware.h> 37 - #include <mach/dma-v1.h> 38 - 39 - #define DMA_DCR 0x00 /* Control Register */ 40 - #define DMA_DISR 0x04 /* Interrupt status Register */ 41 - #define DMA_DIMR 0x08 /* Interrupt mask Register */ 42 - #define DMA_DBTOSR 0x0c /* Burst timeout status Register */ 43 - #define DMA_DRTOSR 0x10 /* Request timeout Register */ 44 - #define DMA_DSESR 0x14 /* Transfer Error Status Register */ 45 - #define DMA_DBOSR 0x18 /* Buffer overflow status Register */ 46 - #define DMA_DBTOCR 0x1c /* Burst timeout control Register */ 47 - #define DMA_WSRA 0x40 /* W-Size Register A */ 48 - #define DMA_XSRA 0x44 /* X-Size Register A */ 49 - #define DMA_YSRA 0x48 /* Y-Size Register A */ 50 - #define DMA_WSRB 0x4c /* W-Size Register B */ 51 - #define DMA_XSRB 0x50 /* X-Size Register B */ 52 - #define DMA_YSRB 0x54 /* Y-Size Register B */ 53 - #define DMA_SAR(x) (0x80 + ((x) << 6)) /* Source Address Registers */ 54 - #define DMA_DAR(x) (0x84 + ((x) << 6)) /* Destination Address Registers */ 55 - #define DMA_CNTR(x) (0x88 + ((x) << 6)) /* Count Registers */ 56 - #define DMA_CCR(x) (0x8c + ((x) << 6)) /* Control Registers */ 57 - #define DMA_RSSR(x) (0x90 + ((x) << 6)) /* Request source select Registers */ 58 - #define DMA_BLR(x) (0x94 + ((x) << 6)) /* Burst length Registers */ 59 - #define DMA_RTOR(x) (0x98 + ((x) << 6)) /* Request timeout Registers */ 60 - #define DMA_BUCR(x) (0x98 + ((x) << 6)) /* Bus Utilization Registers */ 61 - #define DMA_CCNR(x) (0x9C + ((x) << 6)) /* Channel counter Registers */ 62 - 63 - #define DCR_DRST (1<<1) 64 - #define DCR_DEN (1<<0) 65 - #define DBTOCR_EN (1<<15) 66 - #define DBTOCR_CNT(x) ((x) & 0x7fff) 67 - #define CNTR_CNT(x) ((x) & 0xffffff) 68 - #define CCR_ACRPT (1<<14) 69 - #define CCR_DMOD_LINEAR (0x0 << 12) 70 - #define CCR_DMOD_2D (0x1 << 12) 71 - #define CCR_DMOD_FIFO (0x2 << 12) 72 - #define CCR_DMOD_EOBFIFO (0x3 << 12) 73 - #define CCR_SMOD_LINEAR (0x0 << 10) 74 - #define CCR_SMOD_2D (0x1 << 10) 75 - #define CCR_SMOD_FIFO (0x2 << 10) 76 - #define CCR_SMOD_EOBFIFO (0x3 << 10) 77 - #define CCR_MDIR_DEC (1<<9) 78 - #define CCR_MSEL_B (1<<8) 79 - #define CCR_DSIZ_32 (0x0 << 6) 80 - #define CCR_DSIZ_8 (0x1 << 6) 81 - #define CCR_DSIZ_16 (0x2 << 6) 82 - #define CCR_SSIZ_32 (0x0 << 4) 83 - #define CCR_SSIZ_8 (0x1 << 4) 84 - #define CCR_SSIZ_16 (0x2 << 4) 85 - #define CCR_REN (1<<3) 86 - #define CCR_RPT (1<<2) 87 - #define CCR_FRC (1<<1) 88 - #define CCR_CEN (1<<0) 89 - #define RTOR_EN (1<<15) 90 - #define RTOR_CLK (1<<14) 91 - #define RTOR_PSC (1<<13) 92 - 93 - /* 94 - * struct imx_dma_channel - i.MX specific DMA extension 95 - * @name: name specified by DMA client 96 - * @irq_handler: client callback for end of transfer 97 - * @err_handler: client callback for error condition 98 - * @data: clients context data for callbacks 99 - * @dma_mode: direction of the transfer %DMA_MODE_READ or %DMA_MODE_WRITE 100 - * @sg: pointer to the actual read/written chunk for scatter-gather emulation 101 - * @resbytes: total residual number of bytes to transfer 102 - * (it can be lower or same as sum of SG mapped chunk sizes) 103 - * @sgcount: number of chunks to be read/written 104 - * 105 - * Structure is used for IMX DMA processing. It would be probably good 106 - * @struct dma_struct in the future for external interfacing and use 107 - * @struct imx_dma_channel only as extension to it. 108 - */ 109 - 110 - struct imx_dma_channel { 111 - const char *name; 112 - void (*irq_handler) (int, void *); 113 - void (*err_handler) (int, void *, int errcode); 114 - void (*prog_handler) (int, void *, struct scatterlist *); 115 - void *data; 116 - unsigned int dma_mode; 117 - struct scatterlist *sg; 118 - unsigned int resbytes; 119 - int dma_num; 120 - 121 - int in_use; 122 - 123 - u32 ccr_from_device; 124 - u32 ccr_to_device; 125 - 126 - struct timer_list watchdog; 127 - 128 - int hw_chaining; 129 - }; 130 - 131 - static void __iomem *imx_dmav1_baseaddr; 132 - 133 - static void imx_dmav1_writel(unsigned val, unsigned offset) 134 - { 135 - __raw_writel(val, imx_dmav1_baseaddr + offset); 136 - } 137 - 138 - static unsigned imx_dmav1_readl(unsigned offset) 139 - { 140 - return __raw_readl(imx_dmav1_baseaddr + offset); 141 - } 142 - 143 - static struct imx_dma_channel imx_dma_channels[IMX_DMA_CHANNELS]; 144 - 145 - static struct clk *dma_clk; 146 - 147 - static int imx_dma_hw_chain(struct imx_dma_channel *imxdma) 148 - { 149 - if (cpu_is_mx27()) 150 - return imxdma->hw_chaining; 151 - else 152 - return 0; 153 - } 154 - 155 - /* 156 - * imx_dma_sg_next - prepare next chunk for scatter-gather DMA emulation 157 - */ 158 - static inline int imx_dma_sg_next(int channel, struct scatterlist *sg) 159 - { 160 - struct imx_dma_channel *imxdma = &imx_dma_channels[channel]; 161 - unsigned long now; 162 - 163 - if (!imxdma->name) { 164 - printk(KERN_CRIT "%s: called for not allocated channel %d\n", 165 - __func__, channel); 166 - return 0; 167 - } 168 - 169 - now = min(imxdma->resbytes, sg->length); 170 - if (imxdma->resbytes != IMX_DMA_LENGTH_LOOP) 171 - imxdma->resbytes -= now; 172 - 173 - if ((imxdma->dma_mode & DMA_MODE_MASK) == DMA_MODE_READ) 174 - imx_dmav1_writel(sg->dma_address, DMA_DAR(channel)); 175 - else 176 - imx_dmav1_writel(sg->dma_address, DMA_SAR(channel)); 177 - 178 - imx_dmav1_writel(now, DMA_CNTR(channel)); 179 - 180 - pr_debug("imxdma%d: next sg chunk dst 0x%08x, src 0x%08x, " 181 - "size 0x%08x\n", channel, 182 - imx_dmav1_readl(DMA_DAR(channel)), 183 - imx_dmav1_readl(DMA_SAR(channel)), 184 - imx_dmav1_readl(DMA_CNTR(channel))); 185 - 186 - return now; 187 - } 188 - 189 - /** 190 - * imx_dma_setup_single - setup i.MX DMA channel for linear memory to/from 191 - * device transfer 192 - * 193 - * @channel: i.MX DMA channel number 194 - * @dma_address: the DMA/physical memory address of the linear data block 195 - * to transfer 196 - * @dma_length: length of the data block in bytes 197 - * @dev_addr: physical device port address 198 - * @dmamode: DMA transfer mode, %DMA_MODE_READ from the device to the memory 199 - * or %DMA_MODE_WRITE from memory to the device 200 - * 201 - * Return value: if incorrect parameters are provided -%EINVAL. 202 - * Zero indicates success. 203 - */ 204 - int 205 - imx_dma_setup_single(int channel, dma_addr_t dma_address, 206 - unsigned int dma_length, unsigned int dev_addr, 207 - unsigned int dmamode) 208 - { 209 - struct imx_dma_channel *imxdma = &imx_dma_channels[channel]; 210 - 211 - imxdma->sg = NULL; 212 - imxdma->dma_mode = dmamode; 213 - 214 - if (!dma_address) { 215 - printk(KERN_ERR "imxdma%d: imx_dma_setup_single null address\n", 216 - channel); 217 - return -EINVAL; 218 - } 219 - 220 - if (!dma_length) { 221 - printk(KERN_ERR "imxdma%d: imx_dma_setup_single zero length\n", 222 - channel); 223 - return -EINVAL; 224 - } 225 - 226 - if ((dmamode & DMA_MODE_MASK) == DMA_MODE_READ) { 227 - pr_debug("imxdma%d: %s dma_addressg=0x%08x dma_length=%d " 228 - "dev_addr=0x%08x for read\n", 229 - channel, __func__, (unsigned int)dma_address, 230 - dma_length, dev_addr); 231 - 232 - imx_dmav1_writel(dev_addr, DMA_SAR(channel)); 233 - imx_dmav1_writel(dma_address, DMA_DAR(channel)); 234 - imx_dmav1_writel(imxdma->ccr_from_device, DMA_CCR(channel)); 235 - } else if ((dmamode & DMA_MODE_MASK) == DMA_MODE_WRITE) { 236 - pr_debug("imxdma%d: %s dma_addressg=0x%08x dma_length=%d " 237 - "dev_addr=0x%08x for write\n", 238 - channel, __func__, (unsigned int)dma_address, 239 - dma_length, dev_addr); 240 - 241 - imx_dmav1_writel(dma_address, DMA_SAR(channel)); 242 - imx_dmav1_writel(dev_addr, DMA_DAR(channel)); 243 - imx_dmav1_writel(imxdma->ccr_to_device, 244 - DMA_CCR(channel)); 245 - } else { 246 - printk(KERN_ERR "imxdma%d: imx_dma_setup_single bad dmamode\n", 247 - channel); 248 - return -EINVAL; 249 - } 250 - 251 - imx_dmav1_writel(dma_length, DMA_CNTR(channel)); 252 - 253 - return 0; 254 - } 255 - EXPORT_SYMBOL(imx_dma_setup_single); 256 - 257 - /** 258 - * imx_dma_setup_sg - setup i.MX DMA channel SG list to/from device transfer 259 - * @channel: i.MX DMA channel number 260 - * @sg: pointer to the scatter-gather list/vector 261 - * @sgcount: scatter-gather list hungs count 262 - * @dma_length: total length of the transfer request in bytes 263 - * @dev_addr: physical device port address 264 - * @dmamode: DMA transfer mode, %DMA_MODE_READ from the device to the memory 265 - * or %DMA_MODE_WRITE from memory to the device 266 - * 267 - * The function sets up DMA channel state and registers to be ready for 268 - * transfer specified by provided parameters. The scatter-gather emulation 269 - * is set up according to the parameters. 270 - * 271 - * The full preparation of the transfer requires setup of more register 272 - * by the caller before imx_dma_enable() can be called. 273 - * 274 - * %BLR(channel) holds transfer burst length in bytes, 0 means 64 bytes 275 - * 276 - * %RSSR(channel) has to be set to the DMA request line source %DMA_REQ_xxx 277 - * 278 - * %CCR(channel) has to specify transfer parameters, the next settings is 279 - * typical for linear or simple scatter-gather transfers if %DMA_MODE_READ is 280 - * specified 281 - * 282 - * %CCR_DMOD_LINEAR | %CCR_DSIZ_32 | %CCR_SMOD_FIFO | %CCR_SSIZ_x 283 - * 284 - * The typical setup for %DMA_MODE_WRITE is specified by next options 285 - * combination 286 - * 287 - * %CCR_SMOD_LINEAR | %CCR_SSIZ_32 | %CCR_DMOD_FIFO | %CCR_DSIZ_x 288 - * 289 - * Be careful here and do not mistakenly mix source and target device 290 - * port sizes constants, they are really different: 291 - * %CCR_SSIZ_8, %CCR_SSIZ_16, %CCR_SSIZ_32, 292 - * %CCR_DSIZ_8, %CCR_DSIZ_16, %CCR_DSIZ_32 293 - * 294 - * Return value: if incorrect parameters are provided -%EINVAL. 295 - * Zero indicates success. 296 - */ 297 - int 298 - imx_dma_setup_sg(int channel, 299 - struct scatterlist *sg, unsigned int sgcount, 300 - unsigned int dma_length, unsigned int dev_addr, 301 - unsigned int dmamode) 302 - { 303 - struct imx_dma_channel *imxdma = &imx_dma_channels[channel]; 304 - 305 - if (imxdma->in_use) 306 - return -EBUSY; 307 - 308 - imxdma->sg = sg; 309 - imxdma->dma_mode = dmamode; 310 - imxdma->resbytes = dma_length; 311 - 312 - if (!sg || !sgcount) { 313 - printk(KERN_ERR "imxdma%d: imx_dma_setup_sg empty sg list\n", 314 - channel); 315 - return -EINVAL; 316 - } 317 - 318 - if (!sg->length) { 319 - printk(KERN_ERR "imxdma%d: imx_dma_setup_sg zero length\n", 320 - channel); 321 - return -EINVAL; 322 - } 323 - 324 - if ((dmamode & DMA_MODE_MASK) == DMA_MODE_READ) { 325 - pr_debug("imxdma%d: %s sg=%p sgcount=%d total length=%d " 326 - "dev_addr=0x%08x for read\n", 327 - channel, __func__, sg, sgcount, dma_length, dev_addr); 328 - 329 - imx_dmav1_writel(dev_addr, DMA_SAR(channel)); 330 - imx_dmav1_writel(imxdma->ccr_from_device, DMA_CCR(channel)); 331 - } else if ((dmamode & DMA_MODE_MASK) == DMA_MODE_WRITE) { 332 - pr_debug("imxdma%d: %s sg=%p sgcount=%d total length=%d " 333 - "dev_addr=0x%08x for write\n", 334 - channel, __func__, sg, sgcount, dma_length, dev_addr); 335 - 336 - imx_dmav1_writel(dev_addr, DMA_DAR(channel)); 337 - imx_dmav1_writel(imxdma->ccr_to_device, DMA_CCR(channel)); 338 - } else { 339 - printk(KERN_ERR "imxdma%d: imx_dma_setup_sg bad dmamode\n", 340 - channel); 341 - return -EINVAL; 342 - } 343 - 344 - imx_dma_sg_next(channel, sg); 345 - 346 - return 0; 347 - } 348 - EXPORT_SYMBOL(imx_dma_setup_sg); 349 - 350 - int 351 - imx_dma_config_channel(int channel, unsigned int config_port, 352 - unsigned int config_mem, unsigned int dmareq, int hw_chaining) 353 - { 354 - struct imx_dma_channel *imxdma = &imx_dma_channels[channel]; 355 - u32 dreq = 0; 356 - 357 - imxdma->hw_chaining = 0; 358 - 359 - if (hw_chaining) { 360 - imxdma->hw_chaining = 1; 361 - if (!imx_dma_hw_chain(imxdma)) 362 - return -EINVAL; 363 - } 364 - 365 - if (dmareq) 366 - dreq = CCR_REN; 367 - 368 - imxdma->ccr_from_device = config_port | (config_mem << 2) | dreq; 369 - imxdma->ccr_to_device = config_mem | (config_port << 2) | dreq; 370 - 371 - imx_dmav1_writel(dmareq, DMA_RSSR(channel)); 372 - 373 - return 0; 374 - } 375 - EXPORT_SYMBOL(imx_dma_config_channel); 376 - 377 - void imx_dma_config_burstlen(int channel, unsigned int burstlen) 378 - { 379 - imx_dmav1_writel(burstlen, DMA_BLR(channel)); 380 - } 381 - EXPORT_SYMBOL(imx_dma_config_burstlen); 382 - 383 - /** 384 - * imx_dma_setup_handlers - setup i.MX DMA channel end and error notification 385 - * handlers 386 - * @channel: i.MX DMA channel number 387 - * @irq_handler: the pointer to the function called if the transfer 388 - * ends successfully 389 - * @err_handler: the pointer to the function called if the premature 390 - * end caused by error occurs 391 - * @data: user specified value to be passed to the handlers 392 - */ 393 - int 394 - imx_dma_setup_handlers(int channel, 395 - void (*irq_handler) (int, void *), 396 - void (*err_handler) (int, void *, int), 397 - void *data) 398 - { 399 - struct imx_dma_channel *imxdma = &imx_dma_channels[channel]; 400 - unsigned long flags; 401 - 402 - if (!imxdma->name) { 403 - printk(KERN_CRIT "%s: called for not allocated channel %d\n", 404 - __func__, channel); 405 - return -ENODEV; 406 - } 407 - 408 - local_irq_save(flags); 409 - imx_dmav1_writel(1 << channel, DMA_DISR); 410 - imxdma->irq_handler = irq_handler; 411 - imxdma->err_handler = err_handler; 412 - imxdma->data = data; 413 - local_irq_restore(flags); 414 - return 0; 415 - } 416 - EXPORT_SYMBOL(imx_dma_setup_handlers); 417 - 418 - /** 419 - * imx_dma_setup_progression_handler - setup i.MX DMA channel progression 420 - * handlers 421 - * @channel: i.MX DMA channel number 422 - * @prog_handler: the pointer to the function called if the transfer progresses 423 - */ 424 - int 425 - imx_dma_setup_progression_handler(int channel, 426 - void (*prog_handler) (int, void*, struct scatterlist*)) 427 - { 428 - struct imx_dma_channel *imxdma = &imx_dma_channels[channel]; 429 - unsigned long flags; 430 - 431 - if (!imxdma->name) { 432 - printk(KERN_CRIT "%s: called for not allocated channel %d\n", 433 - __func__, channel); 434 - return -ENODEV; 435 - } 436 - 437 - local_irq_save(flags); 438 - imxdma->prog_handler = prog_handler; 439 - local_irq_restore(flags); 440 - return 0; 441 - } 442 - EXPORT_SYMBOL(imx_dma_setup_progression_handler); 443 - 444 - /** 445 - * imx_dma_enable - function to start i.MX DMA channel operation 446 - * @channel: i.MX DMA channel number 447 - * 448 - * The channel has to be allocated by driver through imx_dma_request() 449 - * or imx_dma_request_by_prio() function. 450 - * The transfer parameters has to be set to the channel registers through 451 - * call of the imx_dma_setup_single() or imx_dma_setup_sg() function 452 - * and registers %BLR(channel), %RSSR(channel) and %CCR(channel) has to 453 - * be set prior this function call by the channel user. 454 - */ 455 - void imx_dma_enable(int channel) 456 - { 457 - struct imx_dma_channel *imxdma = &imx_dma_channels[channel]; 458 - unsigned long flags; 459 - 460 - pr_debug("imxdma%d: imx_dma_enable\n", channel); 461 - 462 - if (!imxdma->name) { 463 - printk(KERN_CRIT "%s: called for not allocated channel %d\n", 464 - __func__, channel); 465 - return; 466 - } 467 - 468 - if (imxdma->in_use) 469 - return; 470 - 471 - local_irq_save(flags); 472 - 473 - imx_dmav1_writel(1 << channel, DMA_DISR); 474 - imx_dmav1_writel(imx_dmav1_readl(DMA_DIMR) & ~(1 << channel), DMA_DIMR); 475 - imx_dmav1_writel(imx_dmav1_readl(DMA_CCR(channel)) | CCR_CEN | 476 - CCR_ACRPT, DMA_CCR(channel)); 477 - 478 - if ((cpu_is_mx21() || cpu_is_mx27()) && 479 - imxdma->sg && imx_dma_hw_chain(imxdma)) { 480 - imxdma->sg = sg_next(imxdma->sg); 481 - if (imxdma->sg) { 482 - u32 tmp; 483 - imx_dma_sg_next(channel, imxdma->sg); 484 - tmp = imx_dmav1_readl(DMA_CCR(channel)); 485 - imx_dmav1_writel(tmp | CCR_RPT | CCR_ACRPT, 486 - DMA_CCR(channel)); 487 - } 488 - } 489 - imxdma->in_use = 1; 490 - 491 - local_irq_restore(flags); 492 - } 493 - EXPORT_SYMBOL(imx_dma_enable); 494 - 495 - /** 496 - * imx_dma_disable - stop, finish i.MX DMA channel operatin 497 - * @channel: i.MX DMA channel number 498 - */ 499 - void imx_dma_disable(int channel) 500 - { 501 - struct imx_dma_channel *imxdma = &imx_dma_channels[channel]; 502 - unsigned long flags; 503 - 504 - pr_debug("imxdma%d: imx_dma_disable\n", channel); 505 - 506 - if (imx_dma_hw_chain(imxdma)) 507 - del_timer(&imxdma->watchdog); 508 - 509 - local_irq_save(flags); 510 - imx_dmav1_writel(imx_dmav1_readl(DMA_DIMR) | (1 << channel), DMA_DIMR); 511 - imx_dmav1_writel(imx_dmav1_readl(DMA_CCR(channel)) & ~CCR_CEN, 512 - DMA_CCR(channel)); 513 - imx_dmav1_writel(1 << channel, DMA_DISR); 514 - imxdma->in_use = 0; 515 - local_irq_restore(flags); 516 - } 517 - EXPORT_SYMBOL(imx_dma_disable); 518 - 519 - static void imx_dma_watchdog(unsigned long chno) 520 - { 521 - struct imx_dma_channel *imxdma = &imx_dma_channels[chno]; 522 - 523 - imx_dmav1_writel(0, DMA_CCR(chno)); 524 - imxdma->in_use = 0; 525 - imxdma->sg = NULL; 526 - 527 - if (imxdma->err_handler) 528 - imxdma->err_handler(chno, imxdma->data, IMX_DMA_ERR_TIMEOUT); 529 - } 530 - 531 - static irqreturn_t dma_err_handler(int irq, void *dev_id) 532 - { 533 - int i, disr; 534 - struct imx_dma_channel *imxdma; 535 - unsigned int err_mask; 536 - int errcode; 537 - 538 - disr = imx_dmav1_readl(DMA_DISR); 539 - 540 - err_mask = imx_dmav1_readl(DMA_DBTOSR) | 541 - imx_dmav1_readl(DMA_DRTOSR) | 542 - imx_dmav1_readl(DMA_DSESR) | 543 - imx_dmav1_readl(DMA_DBOSR); 544 - 545 - if (!err_mask) 546 - return IRQ_HANDLED; 547 - 548 - imx_dmav1_writel(disr & err_mask, DMA_DISR); 549 - 550 - for (i = 0; i < IMX_DMA_CHANNELS; i++) { 551 - if (!(err_mask & (1 << i))) 552 - continue; 553 - imxdma = &imx_dma_channels[i]; 554 - errcode = 0; 555 - 556 - if (imx_dmav1_readl(DMA_DBTOSR) & (1 << i)) { 557 - imx_dmav1_writel(1 << i, DMA_DBTOSR); 558 - errcode |= IMX_DMA_ERR_BURST; 559 - } 560 - if (imx_dmav1_readl(DMA_DRTOSR) & (1 << i)) { 561 - imx_dmav1_writel(1 << i, DMA_DRTOSR); 562 - errcode |= IMX_DMA_ERR_REQUEST; 563 - } 564 - if (imx_dmav1_readl(DMA_DSESR) & (1 << i)) { 565 - imx_dmav1_writel(1 << i, DMA_DSESR); 566 - errcode |= IMX_DMA_ERR_TRANSFER; 567 - } 568 - if (imx_dmav1_readl(DMA_DBOSR) & (1 << i)) { 569 - imx_dmav1_writel(1 << i, DMA_DBOSR); 570 - errcode |= IMX_DMA_ERR_BUFFER; 571 - } 572 - if (imxdma->name && imxdma->err_handler) { 573 - imxdma->err_handler(i, imxdma->data, errcode); 574 - continue; 575 - } 576 - 577 - imx_dma_channels[i].sg = NULL; 578 - 579 - printk(KERN_WARNING 580 - "DMA timeout on channel %d (%s) -%s%s%s%s\n", 581 - i, imxdma->name, 582 - errcode & IMX_DMA_ERR_BURST ? " burst" : "", 583 - errcode & IMX_DMA_ERR_REQUEST ? " request" : "", 584 - errcode & IMX_DMA_ERR_TRANSFER ? " transfer" : "", 585 - errcode & IMX_DMA_ERR_BUFFER ? " buffer" : ""); 586 - } 587 - return IRQ_HANDLED; 588 - } 589 - 590 - static void dma_irq_handle_channel(int chno) 591 - { 592 - struct imx_dma_channel *imxdma = &imx_dma_channels[chno]; 593 - 594 - if (!imxdma->name) { 595 - /* 596 - * IRQ for an unregistered DMA channel: 597 - * let's clear the interrupts and disable it. 598 - */ 599 - printk(KERN_WARNING 600 - "spurious IRQ for DMA channel %d\n", chno); 601 - return; 602 - } 603 - 604 - if (imxdma->sg) { 605 - u32 tmp; 606 - struct scatterlist *current_sg = imxdma->sg; 607 - imxdma->sg = sg_next(imxdma->sg); 608 - 609 - if (imxdma->sg) { 610 - imx_dma_sg_next(chno, imxdma->sg); 611 - 612 - tmp = imx_dmav1_readl(DMA_CCR(chno)); 613 - 614 - if (imx_dma_hw_chain(imxdma)) { 615 - /* FIXME: The timeout should probably be 616 - * configurable 617 - */ 618 - mod_timer(&imxdma->watchdog, 619 - jiffies + msecs_to_jiffies(500)); 620 - 621 - tmp |= CCR_CEN | CCR_RPT | CCR_ACRPT; 622 - imx_dmav1_writel(tmp, DMA_CCR(chno)); 623 - } else { 624 - imx_dmav1_writel(tmp & ~CCR_CEN, DMA_CCR(chno)); 625 - tmp |= CCR_CEN; 626 - } 627 - 628 - imx_dmav1_writel(tmp, DMA_CCR(chno)); 629 - 630 - if (imxdma->prog_handler) 631 - imxdma->prog_handler(chno, imxdma->data, 632 - current_sg); 633 - 634 - return; 635 - } 636 - 637 - if (imx_dma_hw_chain(imxdma)) { 638 - del_timer(&imxdma->watchdog); 639 - return; 640 - } 641 - } 642 - 643 - imx_dmav1_writel(0, DMA_CCR(chno)); 644 - imxdma->in_use = 0; 645 - if (imxdma->irq_handler) 646 - imxdma->irq_handler(chno, imxdma->data); 647 - } 648 - 649 - static irqreturn_t dma_irq_handler(int irq, void *dev_id) 650 - { 651 - int i, disr; 652 - 653 - if (cpu_is_mx21() || cpu_is_mx27()) 654 - dma_err_handler(irq, dev_id); 655 - 656 - disr = imx_dmav1_readl(DMA_DISR); 657 - 658 - pr_debug("imxdma: dma_irq_handler called, disr=0x%08x\n", 659 - disr); 660 - 661 - imx_dmav1_writel(disr, DMA_DISR); 662 - for (i = 0; i < IMX_DMA_CHANNELS; i++) { 663 - if (disr & (1 << i)) 664 - dma_irq_handle_channel(i); 665 - } 666 - 667 - return IRQ_HANDLED; 668 - } 669 - 670 - /** 671 - * imx_dma_request - request/allocate specified channel number 672 - * @channel: i.MX DMA channel number 673 - * @name: the driver/caller own non-%NULL identification 674 - */ 675 - int imx_dma_request(int channel, const char *name) 676 - { 677 - struct imx_dma_channel *imxdma = &imx_dma_channels[channel]; 678 - unsigned long flags; 679 - int ret = 0; 680 - 681 - /* basic sanity checks */ 682 - if (!name) 683 - return -EINVAL; 684 - 685 - if (channel >= IMX_DMA_CHANNELS) { 686 - printk(KERN_CRIT "%s: called for non-existed channel %d\n", 687 - __func__, channel); 688 - return -EINVAL; 689 - } 690 - 691 - local_irq_save(flags); 692 - if (imxdma->name) { 693 - local_irq_restore(flags); 694 - return -EBUSY; 695 - } 696 - memset(imxdma, 0, sizeof(*imxdma)); 697 - imxdma->name = name; 698 - local_irq_restore(flags); /* request_irq() can block */ 699 - 700 - if (cpu_is_mx21() || cpu_is_mx27()) { 701 - ret = request_irq(MX2x_INT_DMACH0 + channel, 702 - dma_irq_handler, 0, "DMA", NULL); 703 - if (ret) { 704 - imxdma->name = NULL; 705 - pr_crit("Can't register IRQ %d for DMA channel %d\n", 706 - MX2x_INT_DMACH0 + channel, channel); 707 - return ret; 708 - } 709 - init_timer(&imxdma->watchdog); 710 - imxdma->watchdog.function = &imx_dma_watchdog; 711 - imxdma->watchdog.data = channel; 712 - } 713 - 714 - return ret; 715 - } 716 - EXPORT_SYMBOL(imx_dma_request); 717 - 718 - /** 719 - * imx_dma_free - release previously acquired channel 720 - * @channel: i.MX DMA channel number 721 - */ 722 - void imx_dma_free(int channel) 723 - { 724 - unsigned long flags; 725 - struct imx_dma_channel *imxdma = &imx_dma_channels[channel]; 726 - 727 - if (!imxdma->name) { 728 - printk(KERN_CRIT 729 - "%s: trying to free free channel %d\n", 730 - __func__, channel); 731 - return; 732 - } 733 - 734 - local_irq_save(flags); 735 - /* Disable interrupts */ 736 - imx_dma_disable(channel); 737 - imxdma->name = NULL; 738 - 739 - if (cpu_is_mx21() || cpu_is_mx27()) 740 - free_irq(MX2x_INT_DMACH0 + channel, NULL); 741 - 742 - local_irq_restore(flags); 743 - } 744 - EXPORT_SYMBOL(imx_dma_free); 745 - 746 - /** 747 - * imx_dma_request_by_prio - find and request some of free channels best 748 - * suiting requested priority 749 - * @channel: i.MX DMA channel number 750 - * @name: the driver/caller own non-%NULL identification 751 - * 752 - * This function tries to find a free channel in the specified priority group 753 - * if the priority cannot be achieved it tries to look for free channel 754 - * in the higher and then even lower priority groups. 755 - * 756 - * Return value: If there is no free channel to allocate, -%ENODEV is returned. 757 - * On successful allocation channel is returned. 758 - */ 759 - int imx_dma_request_by_prio(const char *name, enum imx_dma_prio prio) 760 - { 761 - int i; 762 - int best; 763 - 764 - switch (prio) { 765 - case (DMA_PRIO_HIGH): 766 - best = 8; 767 - break; 768 - case (DMA_PRIO_MEDIUM): 769 - best = 4; 770 - break; 771 - case (DMA_PRIO_LOW): 772 - default: 773 - best = 0; 774 - break; 775 - } 776 - 777 - for (i = best; i < IMX_DMA_CHANNELS; i++) 778 - if (!imx_dma_request(i, name)) 779 - return i; 780 - 781 - for (i = best - 1; i >= 0; i--) 782 - if (!imx_dma_request(i, name)) 783 - return i; 784 - 785 - printk(KERN_ERR "%s: no free DMA channel found\n", __func__); 786 - 787 - return -ENODEV; 788 - } 789 - EXPORT_SYMBOL(imx_dma_request_by_prio); 790 - 791 - static int __init imx_dma_init(void) 792 - { 793 - int ret = 0; 794 - int i; 795 - 796 - if (cpu_is_mx1()) 797 - imx_dmav1_baseaddr = MX1_IO_ADDRESS(MX1_DMA_BASE_ADDR); 798 - else if (cpu_is_mx21()) 799 - imx_dmav1_baseaddr = MX21_IO_ADDRESS(MX21_DMA_BASE_ADDR); 800 - else if (cpu_is_mx27()) 801 - imx_dmav1_baseaddr = MX27_IO_ADDRESS(MX27_DMA_BASE_ADDR); 802 - else 803 - return 0; 804 - 805 - dma_clk = clk_get(NULL, "dma"); 806 - if (IS_ERR(dma_clk)) 807 - return PTR_ERR(dma_clk); 808 - clk_enable(dma_clk); 809 - 810 - /* reset DMA module */ 811 - imx_dmav1_writel(DCR_DRST, DMA_DCR); 812 - 813 - if (cpu_is_mx1()) { 814 - ret = request_irq(MX1_DMA_INT, dma_irq_handler, 0, "DMA", NULL); 815 - if (ret) { 816 - pr_crit("Wow! Can't register IRQ for DMA\n"); 817 - return ret; 818 - } 819 - 820 - ret = request_irq(MX1_DMA_ERR, dma_err_handler, 0, "DMA", NULL); 821 - if (ret) { 822 - pr_crit("Wow! Can't register ERRIRQ for DMA\n"); 823 - free_irq(MX1_DMA_INT, NULL); 824 - return ret; 825 - } 826 - } 827 - 828 - /* enable DMA module */ 829 - imx_dmav1_writel(DCR_DEN, DMA_DCR); 830 - 831 - /* clear all interrupts */ 832 - imx_dmav1_writel((1 << IMX_DMA_CHANNELS) - 1, DMA_DISR); 833 - 834 - /* disable interrupts */ 835 - imx_dmav1_writel((1 << IMX_DMA_CHANNELS) - 1, DMA_DIMR); 836 - 837 - for (i = 0; i < IMX_DMA_CHANNELS; i++) { 838 - imx_dma_channels[i].sg = NULL; 839 - imx_dma_channels[i].dma_num = i; 840 - } 841 - 842 - return ret; 843 - } 844 - 845 - arch_initcall(imx_dma_init);
-103
arch/arm/mach-imx/include/mach/dma-v1.h
··· 1 - /* 2 - * linux/arch/arm/mach-imx/include/mach/dma-v1.h 3 - * 4 - * i.MX DMA registration and IRQ dispatching 5 - * 6 - * Copyright 2006 Pavel Pisa <pisa@cmp.felk.cvut.cz> 7 - * Copyright 2008 Juergen Beisert, <kernel@pengutronix.de> 8 - * Copyright 2008 Sascha Hauer, <s.hauer@pengutronix.de> 9 - * 10 - * This program is free software; you can redistribute it and/or 11 - * modify it under the terms of the GNU General Public License 12 - * as published by the Free Software Foundation; either version 2 13 - * of the License, or (at your option) any later version. 14 - * This program is distributed in the hope that it will be useful, 15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 - * GNU General Public License for more details. 18 - * 19 - * You should have received a copy of the GNU General Public License 20 - * along with this program; if not, write to the Free Software 21 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 22 - * MA 02110-1301, USA. 23 - */ 24 - 25 - #ifndef __MACH_DMA_V1_H__ 26 - #define __MACH_DMA_V1_H__ 27 - 28 - #define imx_has_dma_v1() (cpu_is_mx1() || cpu_is_mx21() || cpu_is_mx27()) 29 - 30 - #include <mach/dma.h> 31 - 32 - #define IMX_DMA_CHANNELS 16 33 - 34 - #define DMA_MODE_READ 0 35 - #define DMA_MODE_WRITE 1 36 - #define DMA_MODE_MASK 1 37 - 38 - #define MX1_DMA_REG(offset) MX1_IO_ADDRESS(MX1_DMA_BASE_ADDR + (offset)) 39 - 40 - /* DMA Interrupt Mask Register */ 41 - #define MX1_DMA_DIMR MX1_DMA_REG(0x08) 42 - 43 - /* Channel Control Register */ 44 - #define MX1_DMA_CCR(x) MX1_DMA_REG(0x8c + ((x) << 6)) 45 - 46 - #define IMX_DMA_MEMSIZE_32 (0 << 4) 47 - #define IMX_DMA_MEMSIZE_8 (1 << 4) 48 - #define IMX_DMA_MEMSIZE_16 (2 << 4) 49 - #define IMX_DMA_TYPE_LINEAR (0 << 10) 50 - #define IMX_DMA_TYPE_2D (1 << 10) 51 - #define IMX_DMA_TYPE_FIFO (2 << 10) 52 - 53 - #define IMX_DMA_ERR_BURST (1 << 0) 54 - #define IMX_DMA_ERR_REQUEST (1 << 1) 55 - #define IMX_DMA_ERR_TRANSFER (1 << 2) 56 - #define IMX_DMA_ERR_BUFFER (1 << 3) 57 - #define IMX_DMA_ERR_TIMEOUT (1 << 4) 58 - 59 - int 60 - imx_dma_config_channel(int channel, unsigned int config_port, 61 - unsigned int config_mem, unsigned int dmareq, int hw_chaining); 62 - 63 - void 64 - imx_dma_config_burstlen(int channel, unsigned int burstlen); 65 - 66 - int 67 - imx_dma_setup_single(int channel, dma_addr_t dma_address, 68 - unsigned int dma_length, unsigned int dev_addr, 69 - unsigned int dmamode); 70 - 71 - 72 - /* 73 - * Use this flag as the dma_length argument to imx_dma_setup_sg() 74 - * to create an endless running dma loop. The end of the scatterlist 75 - * must be linked to the beginning for this to work. 76 - */ 77 - #define IMX_DMA_LENGTH_LOOP ((unsigned int)-1) 78 - 79 - int 80 - imx_dma_setup_sg(int channel, struct scatterlist *sg, 81 - unsigned int sgcount, unsigned int dma_length, 82 - unsigned int dev_addr, unsigned int dmamode); 83 - 84 - int 85 - imx_dma_setup_handlers(int channel, 86 - void (*irq_handler) (int, void *), 87 - void (*err_handler) (int, void *, int), void *data); 88 - 89 - int 90 - imx_dma_setup_progression_handler(int channel, 91 - void (*prog_handler) (int, void*, struct scatterlist*)); 92 - 93 - void imx_dma_enable(int channel); 94 - 95 - void imx_dma_disable(int channel); 96 - 97 - int imx_dma_request(int channel, const char *name); 98 - 99 - void imx_dma_free(int channel); 100 - 101 - int imx_dma_request_by_prio(const char *name, enum imx_dma_prio prio); 102 - 103 - #endif /* __MACH_DMA_V1_H__ */
+1 -2
arch/arm/plat-nomadik/include/plat/ste_dma40.h
··· 200 200 sg.dma_address = addr; 201 201 sg.length = size; 202 202 203 - return chan->device->device_prep_slave_sg(chan, &sg, 1, 204 - direction, flags); 203 + return dmaengine_prep_slave_sg(chan, &sg, 1, direction, flags); 205 204 } 206 205 207 206 #else
+2 -2
arch/arm/plat-samsung/dma-ops.c
··· 79 79 info->len, offset_in_page(info->buf)); 80 80 sg_dma_address(&sg) = info->buf; 81 81 82 - desc = chan->device->device_prep_slave_sg(chan, 82 + desc = dmaengine_prep_slave_sg(chan, 83 83 &sg, 1, info->direction, DMA_PREP_INTERRUPT); 84 84 break; 85 85 case DMA_CYCLIC: 86 - desc = chan->device->device_prep_dma_cyclic(chan, 86 + desc = dmaengine_prep_dma_cyclic(chan, 87 87 info->buf, info->len, info->period, info->direction); 88 88 break; 89 89 default:
-13
arch/avr32/mach-at32ap/at32ap700x.c
··· 1351 1351 goto fail; 1352 1352 1353 1353 slave->sdata.dma_dev = &dw_dmac0_device.dev; 1354 - slave->sdata.reg_width = DW_DMA_SLAVE_WIDTH_32BIT; 1355 1354 slave->sdata.cfg_hi = (DWC_CFGH_SRC_PER(0) 1356 1355 | DWC_CFGH_DST_PER(1)); 1357 1356 slave->sdata.cfg_lo &= ~(DWC_CFGL_HS_DST_POL ··· 2045 2046 /* Check if DMA slave interface for capture should be configured. */ 2046 2047 if (flags & AC97C_CAPTURE) { 2047 2048 rx_dws->dma_dev = &dw_dmac0_device.dev; 2048 - rx_dws->reg_width = DW_DMA_SLAVE_WIDTH_16BIT; 2049 2049 rx_dws->cfg_hi = DWC_CFGH_SRC_PER(3); 2050 2050 rx_dws->cfg_lo &= ~(DWC_CFGL_HS_DST_POL | DWC_CFGL_HS_SRC_POL); 2051 2051 rx_dws->src_master = 0; 2052 2052 rx_dws->dst_master = 1; 2053 - rx_dws->src_msize = DW_DMA_MSIZE_1; 2054 - rx_dws->dst_msize = DW_DMA_MSIZE_1; 2055 - rx_dws->fc = DW_DMA_FC_D_P2M; 2056 2053 } 2057 2054 2058 2055 /* Check if DMA slave interface for playback should be configured. */ 2059 2056 if (flags & AC97C_PLAYBACK) { 2060 2057 tx_dws->dma_dev = &dw_dmac0_device.dev; 2061 - tx_dws->reg_width = DW_DMA_SLAVE_WIDTH_16BIT; 2062 2058 tx_dws->cfg_hi = DWC_CFGH_DST_PER(4); 2063 2059 tx_dws->cfg_lo &= ~(DWC_CFGL_HS_DST_POL | DWC_CFGL_HS_SRC_POL); 2064 2060 tx_dws->src_master = 0; 2065 2061 tx_dws->dst_master = 1; 2066 - tx_dws->src_msize = DW_DMA_MSIZE_1; 2067 - tx_dws->dst_msize = DW_DMA_MSIZE_1; 2068 - tx_dws->fc = DW_DMA_FC_D_M2P; 2069 2062 } 2070 2063 2071 2064 if (platform_device_add_data(pdev, data, ··· 2127 2136 dws = &data->dws; 2128 2137 2129 2138 dws->dma_dev = &dw_dmac0_device.dev; 2130 - dws->reg_width = DW_DMA_SLAVE_WIDTH_32BIT; 2131 2139 dws->cfg_hi = DWC_CFGH_DST_PER(2); 2132 2140 dws->cfg_lo &= ~(DWC_CFGL_HS_DST_POL | DWC_CFGL_HS_SRC_POL); 2133 2141 dws->src_master = 0; 2134 2142 dws->dst_master = 1; 2135 - dws->src_msize = DW_DMA_MSIZE_1; 2136 - dws->dst_msize = DW_DMA_MSIZE_1; 2137 - dws->fc = DW_DMA_FC_D_M2P; 2138 2143 2139 2144 if (platform_device_add_data(pdev, data, 2140 2145 sizeof(struct atmel_abdac_pdata)))
-7
arch/avr32/mach-at32ap/include/mach/atmel-mci.h
··· 14 14 #define slave_data_ptr(s) (&(s)->sdata) 15 15 #define find_slave_dev(s) ((s)->sdata.dma_dev) 16 16 17 - #define setup_dma_addr(s, t, r) do { \ 18 - if (s) { \ 19 - (s)->sdata.tx_reg = (t); \ 20 - (s)->sdata.rx_reg = (r); \ 21 - } \ 22 - } while (0) 23 - 24 17 #endif /* __MACH_ATMEL_MCI_H */
+1 -2
drivers/dma/Kconfig
··· 201 201 tristate "DMA API Driver for PL330" 202 202 select DMA_ENGINE 203 203 depends on ARM_AMBA 204 - select PL330 205 204 help 206 205 Select if your platform has one or more PL330 DMACs. 207 206 You need to provide platform specific settings via ··· 230 231 231 232 config IMX_DMA 232 233 tristate "i.MX DMA support" 233 - depends on IMX_HAVE_DMA_V1 234 + depends on ARCH_MXC 234 235 select DMA_ENGINE 235 236 help 236 237 Support the i.MX DMA engine. This engine is integrated into
+16 -30
drivers/dma/amba-pl08x.c
··· 85 85 #include <linux/slab.h> 86 86 #include <asm/hardware/pl080.h> 87 87 88 + #include "dmaengine.h" 89 + 88 90 #define DRIVER_NAME "pl08xdmac" 89 91 90 92 static struct amba_driver pl08x_amba_driver; ··· 651 649 } 652 650 653 651 if ((bd.srcbus.addr % bd.srcbus.buswidth) || 654 - (bd.srcbus.addr % bd.srcbus.buswidth)) { 652 + (bd.dstbus.addr % bd.dstbus.buswidth)) { 655 653 dev_err(&pl08x->adev->dev, 656 654 "%s src & dst address must be aligned to src" 657 655 " & dst width if peripheral is flow controller", ··· 921 919 struct pl08x_dma_chan *plchan = to_pl08x_chan(tx->chan); 922 920 struct pl08x_txd *txd = to_pl08x_txd(tx); 923 921 unsigned long flags; 922 + dma_cookie_t cookie; 924 923 925 924 spin_lock_irqsave(&plchan->lock, flags); 926 - 927 - plchan->chan.cookie += 1; 928 - if (plchan->chan.cookie < 0) 929 - plchan->chan.cookie = 1; 930 - tx->cookie = plchan->chan.cookie; 925 + cookie = dma_cookie_assign(tx); 931 926 932 927 /* Put this onto the pending list */ 933 928 list_add_tail(&txd->node, &plchan->pend_list); ··· 944 945 945 946 spin_unlock_irqrestore(&plchan->lock, flags); 946 947 947 - return tx->cookie; 948 + return cookie; 948 949 } 949 950 950 951 static struct dma_async_tx_descriptor *pl08x_prep_dma_interrupt( ··· 964 965 dma_cookie_t cookie, struct dma_tx_state *txstate) 965 966 { 966 967 struct pl08x_dma_chan *plchan = to_pl08x_chan(chan); 967 - dma_cookie_t last_used; 968 - dma_cookie_t last_complete; 969 968 enum dma_status ret; 970 - u32 bytesleft = 0; 971 969 972 - last_used = plchan->chan.cookie; 973 - last_complete = plchan->lc; 974 - 975 - ret = dma_async_is_complete(cookie, last_complete, last_used); 976 - if (ret == DMA_SUCCESS) { 977 - dma_set_tx_state(txstate, last_complete, last_used, 0); 970 + ret = dma_cookie_status(chan, cookie, txstate); 971 + if (ret == DMA_SUCCESS) 978 972 return ret; 979 - } 980 973 981 974 /* 982 975 * This cookie not complete yet 976 + * Get number of bytes left in the active transactions and queue 983 977 */ 984 - last_used = plchan->chan.cookie; 985 - last_complete = plchan->lc; 986 - 987 - /* Get number of bytes left in the active transactions and queue */ 988 - bytesleft = pl08x_getbytes_chan(plchan); 989 - 990 - dma_set_tx_state(txstate, last_complete, last_used, 991 - bytesleft); 978 + dma_set_residue(txstate, pl08x_getbytes_chan(plchan)); 992 979 993 980 if (plchan->state == PL08X_CHAN_PAUSED) 994 981 return DMA_PAUSED; ··· 1123 1138 burst = pl08x_burst(maxburst); 1124 1139 cctl |= burst << PL080_CONTROL_SB_SIZE_SHIFT; 1125 1140 cctl |= burst << PL080_CONTROL_DB_SIZE_SHIFT; 1141 + 1142 + plchan->device_fc = config->device_fc; 1126 1143 1127 1144 if (plchan->runtime_direction == DMA_DEV_TO_MEM) { 1128 1145 plchan->src_addr = config->src_addr; ··· 1313 1326 static struct dma_async_tx_descriptor *pl08x_prep_slave_sg( 1314 1327 struct dma_chan *chan, struct scatterlist *sgl, 1315 1328 unsigned int sg_len, enum dma_transfer_direction direction, 1316 - unsigned long flags) 1329 + unsigned long flags, void *context) 1317 1330 { 1318 1331 struct pl08x_dma_chan *plchan = to_pl08x_chan(chan); 1319 1332 struct pl08x_driver_data *pl08x = plchan->host; ··· 1357 1370 return NULL; 1358 1371 } 1359 1372 1360 - if (plchan->cd->device_fc) 1373 + if (plchan->device_fc) 1361 1374 tmp = (direction == DMA_MEM_TO_DEV) ? PL080_FLOW_MEM2PER_PER : 1362 1375 PL080_FLOW_PER2MEM_PER; 1363 1376 else ··· 1528 1541 1529 1542 if (txd) { 1530 1543 /* Update last completed */ 1531 - plchan->lc = txd->tx.cookie; 1544 + dma_cookie_complete(&txd->tx); 1532 1545 } 1533 1546 1534 1547 /* If a new descriptor is queued, set it up plchan->at is NULL here */ ··· 1709 1722 chan->name); 1710 1723 1711 1724 chan->chan.device = dmadev; 1712 - chan->chan.cookie = 0; 1713 - chan->lc = 0; 1725 + dma_cookie_init(&chan->chan); 1714 1726 1715 1727 spin_lock_init(&chan->lock); 1716 1728 INIT_LIST_HEAD(&chan->pend_list);
+59 -52
drivers/dma/at_hdmac.c
··· 27 27 #include <linux/of_device.h> 28 28 29 29 #include "at_hdmac_regs.h" 30 + #include "dmaengine.h" 30 31 31 32 /* 32 33 * Glossary ··· 193 192 } 194 193 195 194 /** 196 - * atc_assign_cookie - compute and assign new cookie 197 - * @atchan: channel we work on 198 - * @desc: descriptor to assign cookie for 199 - * 200 - * Called with atchan->lock held and bh disabled 201 - */ 202 - static dma_cookie_t 203 - atc_assign_cookie(struct at_dma_chan *atchan, struct at_desc *desc) 204 - { 205 - dma_cookie_t cookie = atchan->chan_common.cookie; 206 - 207 - if (++cookie < 0) 208 - cookie = 1; 209 - 210 - atchan->chan_common.cookie = cookie; 211 - desc->txd.cookie = cookie; 212 - 213 - return cookie; 214 - } 215 - 216 - /** 217 195 * atc_dostart - starts the DMA engine for real 218 196 * @atchan: the channel we want to start 219 197 * @first: first descriptor in the list we want to begin with ··· 249 269 dev_vdbg(chan2dev(&atchan->chan_common), 250 270 "descriptor %u complete\n", txd->cookie); 251 271 252 - atchan->completed_cookie = txd->cookie; 272 + dma_cookie_complete(txd); 253 273 254 274 /* move children to free_list */ 255 275 list_splice_init(&desc->tx_list, &atchan->free_list); ··· 527 547 unsigned long flags; 528 548 529 549 spin_lock_irqsave(&atchan->lock, flags); 530 - cookie = atc_assign_cookie(atchan, desc); 550 + cookie = dma_cookie_assign(tx); 531 551 532 552 if (list_empty(&atchan->active_list)) { 533 553 dev_vdbg(chan2dev(tx->chan), "tx_submit: started %u\n", ··· 639 659 * @sg_len: number of entries in @scatterlist 640 660 * @direction: DMA direction 641 661 * @flags: tx descriptor status flags 662 + * @context: transaction context (ignored) 642 663 */ 643 664 static struct dma_async_tx_descriptor * 644 665 atc_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl, 645 666 unsigned int sg_len, enum dma_transfer_direction direction, 646 - unsigned long flags) 667 + unsigned long flags, void *context) 647 668 { 648 669 struct at_dma_chan *atchan = to_at_dma_chan(chan); 649 670 struct at_dma_slave *atslave = chan->private; 671 + struct dma_slave_config *sconfig = &atchan->dma_sconfig; 650 672 struct at_desc *first = NULL; 651 673 struct at_desc *prev = NULL; 652 674 u32 ctrla; ··· 670 688 return NULL; 671 689 } 672 690 673 - reg_width = atslave->reg_width; 674 - 675 691 ctrla = ATC_DEFAULT_CTRLA | atslave->ctrla; 676 692 ctrlb = ATC_IEN; 677 693 678 694 switch (direction) { 679 695 case DMA_MEM_TO_DEV: 696 + reg_width = convert_buswidth(sconfig->dst_addr_width); 680 697 ctrla |= ATC_DST_WIDTH(reg_width); 681 698 ctrlb |= ATC_DST_ADDR_MODE_FIXED 682 699 | ATC_SRC_ADDR_MODE_INCR 683 700 | ATC_FC_MEM2PER 684 701 | ATC_SIF(AT_DMA_MEM_IF) | ATC_DIF(AT_DMA_PER_IF); 685 - reg = atslave->tx_reg; 702 + reg = sconfig->dst_addr; 686 703 for_each_sg(sgl, sg, sg_len, i) { 687 704 struct at_desc *desc; 688 705 u32 len; ··· 709 728 } 710 729 break; 711 730 case DMA_DEV_TO_MEM: 731 + reg_width = convert_buswidth(sconfig->src_addr_width); 712 732 ctrla |= ATC_SRC_WIDTH(reg_width); 713 733 ctrlb |= ATC_DST_ADDR_MODE_INCR 714 734 | ATC_SRC_ADDR_MODE_FIXED 715 735 | ATC_FC_PER2MEM 716 736 | ATC_SIF(AT_DMA_PER_IF) | ATC_DIF(AT_DMA_MEM_IF); 717 737 718 - reg = atslave->rx_reg; 738 + reg = sconfig->src_addr; 719 739 for_each_sg(sgl, sg, sg_len, i) { 720 740 struct at_desc *desc; 721 741 u32 len; ··· 792 810 * atc_dma_cyclic_fill_desc - Fill one period decriptor 793 811 */ 794 812 static int 795 - atc_dma_cyclic_fill_desc(struct at_dma_slave *atslave, struct at_desc *desc, 813 + atc_dma_cyclic_fill_desc(struct dma_chan *chan, struct at_desc *desc, 796 814 unsigned int period_index, dma_addr_t buf_addr, 797 - size_t period_len, enum dma_transfer_direction direction) 815 + unsigned int reg_width, size_t period_len, 816 + enum dma_transfer_direction direction) 798 817 { 799 - u32 ctrla; 800 - unsigned int reg_width = atslave->reg_width; 818 + struct at_dma_chan *atchan = to_at_dma_chan(chan); 819 + struct at_dma_slave *atslave = chan->private; 820 + struct dma_slave_config *sconfig = &atchan->dma_sconfig; 821 + u32 ctrla; 801 822 802 823 /* prepare common CRTLA value */ 803 824 ctrla = ATC_DEFAULT_CTRLA | atslave->ctrla ··· 811 826 switch (direction) { 812 827 case DMA_MEM_TO_DEV: 813 828 desc->lli.saddr = buf_addr + (period_len * period_index); 814 - desc->lli.daddr = atslave->tx_reg; 829 + desc->lli.daddr = sconfig->dst_addr; 815 830 desc->lli.ctrla = ctrla; 816 831 desc->lli.ctrlb = ATC_DST_ADDR_MODE_FIXED 817 832 | ATC_SRC_ADDR_MODE_INCR ··· 821 836 break; 822 837 823 838 case DMA_DEV_TO_MEM: 824 - desc->lli.saddr = atslave->rx_reg; 839 + desc->lli.saddr = sconfig->src_addr; 825 840 desc->lli.daddr = buf_addr + (period_len * period_index); 826 841 desc->lli.ctrla = ctrla; 827 842 desc->lli.ctrlb = ATC_DST_ADDR_MODE_INCR ··· 845 860 * @buf_len: total number of bytes for the entire buffer 846 861 * @period_len: number of bytes for each period 847 862 * @direction: transfer direction, to or from device 863 + * @context: transfer context (ignored) 848 864 */ 849 865 static struct dma_async_tx_descriptor * 850 866 atc_prep_dma_cyclic(struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len, 851 - size_t period_len, enum dma_transfer_direction direction) 867 + size_t period_len, enum dma_transfer_direction direction, 868 + void *context) 852 869 { 853 870 struct at_dma_chan *atchan = to_at_dma_chan(chan); 854 871 struct at_dma_slave *atslave = chan->private; 872 + struct dma_slave_config *sconfig = &atchan->dma_sconfig; 855 873 struct at_desc *first = NULL; 856 874 struct at_desc *prev = NULL; 857 875 unsigned long was_cyclic; 876 + unsigned int reg_width; 858 877 unsigned int periods = buf_len / period_len; 859 878 unsigned int i; 860 879 ··· 878 889 return NULL; 879 890 } 880 891 892 + if (sconfig->direction == DMA_MEM_TO_DEV) 893 + reg_width = convert_buswidth(sconfig->dst_addr_width); 894 + else 895 + reg_width = convert_buswidth(sconfig->src_addr_width); 896 + 881 897 /* Check for too big/unaligned periods and unaligned DMA buffer */ 882 - if (atc_dma_cyclic_check_values(atslave->reg_width, buf_addr, 898 + if (atc_dma_cyclic_check_values(reg_width, buf_addr, 883 899 period_len, direction)) 884 900 goto err_out; 885 901 ··· 896 902 if (!desc) 897 903 goto err_desc_get; 898 904 899 - if (atc_dma_cyclic_fill_desc(atslave, desc, i, buf_addr, 900 - period_len, direction)) 905 + if (atc_dma_cyclic_fill_desc(chan, desc, i, buf_addr, 906 + reg_width, period_len, direction)) 901 907 goto err_desc_get; 902 908 903 909 atc_desc_chain(&first, &prev, desc); ··· 918 924 err_out: 919 925 clear_bit(ATC_IS_CYCLIC, &atchan->status); 920 926 return NULL; 927 + } 928 + 929 + static int set_runtime_config(struct dma_chan *chan, 930 + struct dma_slave_config *sconfig) 931 + { 932 + struct at_dma_chan *atchan = to_at_dma_chan(chan); 933 + 934 + /* Check if it is chan is configured for slave transfers */ 935 + if (!chan->private) 936 + return -EINVAL; 937 + 938 + memcpy(&atchan->dma_sconfig, sconfig, sizeof(*sconfig)); 939 + 940 + convert_burst(&atchan->dma_sconfig.src_maxburst); 941 + convert_burst(&atchan->dma_sconfig.dst_maxburst); 942 + 943 + return 0; 921 944 } 922 945 923 946 ··· 997 986 clear_bit(ATC_IS_CYCLIC, &atchan->status); 998 987 999 988 spin_unlock_irqrestore(&atchan->lock, flags); 989 + } else if (cmd == DMA_SLAVE_CONFIG) { 990 + return set_runtime_config(chan, (struct dma_slave_config *)arg); 1000 991 } else { 1001 992 return -ENXIO; 1002 993 } ··· 1029 1016 1030 1017 spin_lock_irqsave(&atchan->lock, flags); 1031 1018 1032 - last_complete = atchan->completed_cookie; 1033 - last_used = chan->cookie; 1034 - 1035 - ret = dma_async_is_complete(cookie, last_complete, last_used); 1019 + ret = dma_cookie_status(chan, cookie, txstate); 1036 1020 if (ret != DMA_SUCCESS) { 1037 1021 atc_cleanup_descriptors(atchan); 1038 1022 1039 - last_complete = atchan->completed_cookie; 1040 - last_used = chan->cookie; 1041 - 1042 - ret = dma_async_is_complete(cookie, last_complete, last_used); 1023 + ret = dma_cookie_status(chan, cookie, txstate); 1043 1024 } 1025 + 1026 + last_complete = chan->completed_cookie; 1027 + last_used = chan->cookie; 1044 1028 1045 1029 spin_unlock_irqrestore(&atchan->lock, flags); 1046 1030 1047 1031 if (ret != DMA_SUCCESS) 1048 - dma_set_tx_state(txstate, last_complete, last_used, 1049 - atc_first_active(atchan)->len); 1050 - else 1051 - dma_set_tx_state(txstate, last_complete, last_used, 0); 1032 + dma_set_residue(txstate, atc_first_active(atchan)->len); 1052 1033 1053 1034 if (atc_chan_is_paused(atchan)) 1054 1035 ret = DMA_PAUSED; ··· 1136 1129 spin_lock_irqsave(&atchan->lock, flags); 1137 1130 atchan->descs_allocated = i; 1138 1131 list_splice(&tmp_list, &atchan->free_list); 1139 - atchan->completed_cookie = chan->cookie = 1; 1132 + dma_cookie_init(chan); 1140 1133 spin_unlock_irqrestore(&atchan->lock, flags); 1141 1134 1142 1135 /* channel parameters */ ··· 1336 1329 struct at_dma_chan *atchan = &atdma->chan[i]; 1337 1330 1338 1331 atchan->chan_common.device = &atdma->dma_common; 1339 - atchan->chan_common.cookie = atchan->completed_cookie = 1; 1332 + dma_cookie_init(&atchan->chan_common); 1340 1333 list_add_tail(&atchan->chan_common.device_node, 1341 1334 &atdma->dma_common.channels); 1342 1335
+32 -2
drivers/dma/at_hdmac_regs.h
··· 207 207 * @save_cfg: configuration register that is saved on suspend/resume cycle 208 208 * @save_dscr: for cyclic operations, preserve next descriptor address in 209 209 * the cyclic list on suspend/resume cycle 210 + * @dma_sconfig: configuration for slave transfers, passed via DMA_SLAVE_CONFIG 210 211 * @lock: serializes enqueue/dequeue operations to descriptors lists 211 - * @completed_cookie: identifier for the most recently completed operation 212 212 * @active_list: list of descriptors dmaengine is being running on 213 213 * @queue: list of descriptors ready to be submitted to engine 214 214 * @free_list: list of descriptors usable by the channel ··· 223 223 struct tasklet_struct tasklet; 224 224 u32 save_cfg; 225 225 u32 save_dscr; 226 + struct dma_slave_config dma_sconfig; 226 227 227 228 spinlock_t lock; 228 229 229 230 /* these other elements are all protected by lock */ 230 - dma_cookie_t completed_cookie; 231 231 struct list_head active_list; 232 232 struct list_head queue; 233 233 struct list_head free_list; ··· 245 245 return container_of(dchan, struct at_dma_chan, chan_common); 246 246 } 247 247 248 + /* 249 + * Fix sconfig's burst size according to at_hdmac. We need to convert them as: 250 + * 1 -> 0, 4 -> 1, 8 -> 2, 16 -> 3, 32 -> 4, 64 -> 5, 128 -> 6, 256 -> 7. 251 + * 252 + * This can be done by finding most significant bit set. 253 + */ 254 + static inline void convert_burst(u32 *maxburst) 255 + { 256 + if (*maxburst > 1) 257 + *maxburst = fls(*maxburst) - 2; 258 + else 259 + *maxburst = 0; 260 + } 261 + 262 + /* 263 + * Fix sconfig's bus width according to at_hdmac. 264 + * 1 byte -> 0, 2 bytes -> 1, 4 bytes -> 2. 265 + */ 266 + static inline u8 convert_buswidth(enum dma_slave_buswidth addr_width) 267 + { 268 + switch (addr_width) { 269 + case DMA_SLAVE_BUSWIDTH_2_BYTES: 270 + return 1; 271 + case DMA_SLAVE_BUSWIDTH_4_BYTES: 272 + return 2; 273 + default: 274 + /* For 1 byte width or fallback */ 275 + return 0; 276 + } 277 + } 248 278 249 279 /*-- Controller ------------------------------------------------------*/ 250 280
+11 -30
drivers/dma/coh901318.c
··· 24 24 #include <mach/coh901318.h> 25 25 26 26 #include "coh901318_lli.h" 27 + #include "dmaengine.h" 27 28 28 29 #define COHC_2_DEV(cohc) (&cohc->chan.dev->device) 29 30 ··· 60 59 struct coh901318_chan { 61 60 spinlock_t lock; 62 61 int allocated; 63 - int completed; 64 62 int id; 65 63 int stopped; 66 64 ··· 317 317 COH901318_CX_CTRL_SPACING * channel); 318 318 319 319 return 0; 320 - } 321 - static dma_cookie_t 322 - coh901318_assign_cookie(struct coh901318_chan *cohc, 323 - struct coh901318_desc *cohd) 324 - { 325 - dma_cookie_t cookie = cohc->chan.cookie; 326 - 327 - if (++cookie < 0) 328 - cookie = 1; 329 - 330 - cohc->chan.cookie = cookie; 331 - cohd->desc.cookie = cookie; 332 - 333 - return cookie; 334 320 } 335 321 336 322 static struct coh901318_desc * ··· 691 705 callback_param = cohd_fin->desc.callback_param; 692 706 693 707 /* sign this job as completed on the channel */ 694 - cohc->completed = cohd_fin->desc.cookie; 708 + dma_cookie_complete(&cohd_fin->desc); 695 709 696 710 /* release the lli allocation and remove the descriptor */ 697 711 coh901318_lli_free(&cohc->base->pool, &cohd_fin->lli); ··· 915 929 coh901318_config(cohc, NULL); 916 930 917 931 cohc->allocated = 1; 918 - cohc->completed = chan->cookie = 1; 932 + dma_cookie_init(chan); 919 933 920 934 spin_unlock_irqrestore(&cohc->lock, flags); 921 935 ··· 952 966 desc); 953 967 struct coh901318_chan *cohc = to_coh901318_chan(tx->chan); 954 968 unsigned long flags; 969 + dma_cookie_t cookie; 955 970 956 971 spin_lock_irqsave(&cohc->lock, flags); 957 - 958 - tx->cookie = coh901318_assign_cookie(cohc, cohd); 972 + cookie = dma_cookie_assign(tx); 959 973 960 974 coh901318_desc_queue(cohc, cohd); 961 975 962 976 spin_unlock_irqrestore(&cohc->lock, flags); 963 977 964 - return tx->cookie; 978 + return cookie; 965 979 } 966 980 967 981 static struct dma_async_tx_descriptor * ··· 1021 1035 static struct dma_async_tx_descriptor * 1022 1036 coh901318_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl, 1023 1037 unsigned int sg_len, enum dma_transfer_direction direction, 1024 - unsigned long flags) 1038 + unsigned long flags, void *context) 1025 1039 { 1026 1040 struct coh901318_chan *cohc = to_coh901318_chan(chan); 1027 1041 struct coh901318_lli *lli; ··· 1151 1165 struct dma_tx_state *txstate) 1152 1166 { 1153 1167 struct coh901318_chan *cohc = to_coh901318_chan(chan); 1154 - dma_cookie_t last_used; 1155 - dma_cookie_t last_complete; 1156 - int ret; 1168 + enum dma_status ret; 1157 1169 1158 - last_complete = cohc->completed; 1159 - last_used = chan->cookie; 1170 + ret = dma_cookie_status(chan, cookie, txstate); 1171 + /* FIXME: should be conditional on ret != DMA_SUCCESS? */ 1172 + dma_set_residue(txstate, coh901318_get_bytes_left(chan)); 1160 1173 1161 - ret = dma_async_is_complete(cookie, last_complete, last_used); 1162 - 1163 - dma_set_tx_state(txstate, last_complete, last_used, 1164 - coh901318_get_bytes_left(chan)); 1165 1174 if (ret == DMA_IN_PROGRESS && cohc->stopped) 1166 1175 ret = DMA_PAUSED; 1167 1176
+4 -4
drivers/dma/dmaengine.c
··· 510 510 dma_chan_name(chan)); 511 511 list_del_rcu(&device->global_node); 512 512 } else if (err) 513 - pr_debug("dmaengine: failed to get %s: (%d)\n", 514 - dma_chan_name(chan), err); 513 + pr_debug("%s: failed to get %s: (%d)\n", 514 + __func__, dma_chan_name(chan), err); 515 515 else 516 516 break; 517 517 if (--device->privatecnt == 0) ··· 564 564 list_del_rcu(&device->global_node); 565 565 break; 566 566 } else if (err) 567 - pr_err("dmaengine: failed to get %s: (%d)\n", 568 - dma_chan_name(chan), err); 567 + pr_err("%s: failed to get %s: (%d)\n", 568 + __func__, dma_chan_name(chan), err); 569 569 } 570 570 } 571 571
+89
drivers/dma/dmaengine.h
··· 1 + /* 2 + * The contents of this file are private to DMA engine drivers, and is not 3 + * part of the API to be used by DMA engine users. 4 + */ 5 + #ifndef DMAENGINE_H 6 + #define DMAENGINE_H 7 + 8 + #include <linux/bug.h> 9 + #include <linux/dmaengine.h> 10 + 11 + /** 12 + * dma_cookie_init - initialize the cookies for a DMA channel 13 + * @chan: dma channel to initialize 14 + */ 15 + static inline void dma_cookie_init(struct dma_chan *chan) 16 + { 17 + chan->cookie = DMA_MIN_COOKIE; 18 + chan->completed_cookie = DMA_MIN_COOKIE; 19 + } 20 + 21 + /** 22 + * dma_cookie_assign - assign a DMA engine cookie to the descriptor 23 + * @tx: descriptor needing cookie 24 + * 25 + * Assign a unique non-zero per-channel cookie to the descriptor. 26 + * Note: caller is expected to hold a lock to prevent concurrency. 27 + */ 28 + static inline dma_cookie_t dma_cookie_assign(struct dma_async_tx_descriptor *tx) 29 + { 30 + struct dma_chan *chan = tx->chan; 31 + dma_cookie_t cookie; 32 + 33 + cookie = chan->cookie + 1; 34 + if (cookie < DMA_MIN_COOKIE) 35 + cookie = DMA_MIN_COOKIE; 36 + tx->cookie = chan->cookie = cookie; 37 + 38 + return cookie; 39 + } 40 + 41 + /** 42 + * dma_cookie_complete - complete a descriptor 43 + * @tx: descriptor to complete 44 + * 45 + * Mark this descriptor complete by updating the channels completed 46 + * cookie marker. Zero the descriptors cookie to prevent accidental 47 + * repeated completions. 48 + * 49 + * Note: caller is expected to hold a lock to prevent concurrency. 50 + */ 51 + static inline void dma_cookie_complete(struct dma_async_tx_descriptor *tx) 52 + { 53 + BUG_ON(tx->cookie < DMA_MIN_COOKIE); 54 + tx->chan->completed_cookie = tx->cookie; 55 + tx->cookie = 0; 56 + } 57 + 58 + /** 59 + * dma_cookie_status - report cookie status 60 + * @chan: dma channel 61 + * @cookie: cookie we are interested in 62 + * @state: dma_tx_state structure to return last/used cookies 63 + * 64 + * Report the status of the cookie, filling in the state structure if 65 + * non-NULL. No locking is required. 66 + */ 67 + static inline enum dma_status dma_cookie_status(struct dma_chan *chan, 68 + dma_cookie_t cookie, struct dma_tx_state *state) 69 + { 70 + dma_cookie_t used, complete; 71 + 72 + used = chan->cookie; 73 + complete = chan->completed_cookie; 74 + barrier(); 75 + if (state) { 76 + state->last = complete; 77 + state->used = used; 78 + state->residue = 0; 79 + } 80 + return dma_async_is_complete(cookie, complete, used); 81 + } 82 + 83 + static inline void dma_set_residue(struct dma_tx_state *state, u32 residue) 84 + { 85 + if (state) 86 + state->residue = residue; 87 + } 88 + 89 + #endif
+128 -100
drivers/dma/dw_dmac.c
··· 9 9 * it under the terms of the GNU General Public License version 2 as 10 10 * published by the Free Software Foundation. 11 11 */ 12 + #include <linux/bitops.h> 12 13 #include <linux/clk.h> 13 14 #include <linux/delay.h> 14 15 #include <linux/dmaengine.h> ··· 23 22 #include <linux/slab.h> 24 23 25 24 #include "dw_dmac_regs.h" 25 + #include "dmaengine.h" 26 26 27 27 /* 28 28 * This supports the Synopsys "DesignWare AHB Central DMA Controller", ··· 35 33 * which does not support descriptor writeback. 36 34 */ 37 35 38 - #define DWC_DEFAULT_CTLLO(private) ({ \ 39 - struct dw_dma_slave *__slave = (private); \ 40 - int dms = __slave ? __slave->dst_master : 0; \ 41 - int sms = __slave ? __slave->src_master : 1; \ 42 - u8 smsize = __slave ? __slave->src_msize : DW_DMA_MSIZE_16; \ 43 - u8 dmsize = __slave ? __slave->dst_msize : DW_DMA_MSIZE_16; \ 36 + #define DWC_DEFAULT_CTLLO(_chan) ({ \ 37 + struct dw_dma_slave *__slave = (_chan->private); \ 38 + struct dw_dma_chan *_dwc = to_dw_dma_chan(_chan); \ 39 + struct dma_slave_config *_sconfig = &_dwc->dma_sconfig; \ 40 + int _dms = __slave ? __slave->dst_master : 0; \ 41 + int _sms = __slave ? __slave->src_master : 1; \ 42 + u8 _smsize = __slave ? _sconfig->src_maxburst : \ 43 + DW_DMA_MSIZE_16; \ 44 + u8 _dmsize = __slave ? _sconfig->dst_maxburst : \ 45 + DW_DMA_MSIZE_16; \ 44 46 \ 45 - (DWC_CTLL_DST_MSIZE(dmsize) \ 46 - | DWC_CTLL_SRC_MSIZE(smsize) \ 47 + (DWC_CTLL_DST_MSIZE(_dmsize) \ 48 + | DWC_CTLL_SRC_MSIZE(_smsize) \ 47 49 | DWC_CTLL_LLP_D_EN \ 48 50 | DWC_CTLL_LLP_S_EN \ 49 - | DWC_CTLL_DMS(dms) \ 50 - | DWC_CTLL_SMS(sms)); \ 51 + | DWC_CTLL_DMS(_dms) \ 52 + | DWC_CTLL_SMS(_sms)); \ 51 53 }) 52 54 53 55 /* ··· 157 151 } 158 152 } 159 153 160 - /* Called with dwc->lock held and bh disabled */ 161 - static dma_cookie_t 162 - dwc_assign_cookie(struct dw_dma_chan *dwc, struct dw_desc *desc) 163 - { 164 - dma_cookie_t cookie = dwc->chan.cookie; 165 - 166 - if (++cookie < 0) 167 - cookie = 1; 168 - 169 - dwc->chan.cookie = cookie; 170 - desc->txd.cookie = cookie; 171 - 172 - return cookie; 173 - } 174 - 175 154 static void dwc_initialize(struct dw_dma_chan *dwc) 176 155 { 177 156 struct dw_dma *dw = to_dw_dma(dwc->chan.device); ··· 183 192 184 193 /* Enable interrupts */ 185 194 channel_set_bit(dw, MASK.XFER, dwc->mask); 186 - channel_set_bit(dw, MASK.BLOCK, dwc->mask); 187 195 channel_set_bit(dw, MASK.ERROR, dwc->mask); 188 196 189 197 dwc->initialized = true; ··· 235 245 dev_vdbg(chan2dev(&dwc->chan), "descriptor %u complete\n", txd->cookie); 236 246 237 247 spin_lock_irqsave(&dwc->lock, flags); 238 - dwc->completed = txd->cookie; 248 + dma_cookie_complete(txd); 239 249 if (callback_required) { 240 250 callback = txd->callback; 241 251 param = txd->callback_param; ··· 319 329 unsigned long flags; 320 330 321 331 spin_lock_irqsave(&dwc->lock, flags); 322 - /* 323 - * Clear block interrupt flag before scanning so that we don't 324 - * miss any, and read LLP before RAW_XFER to ensure it is 325 - * valid if we decide to scan the list. 326 - */ 327 - dma_writel(dw, CLEAR.BLOCK, dwc->mask); 328 332 llp = channel_readl(dwc, LLP); 329 333 status_xfer = dma_readl(dw, RAW.XFER); 330 334 ··· 454 470 455 471 /* called with dwc->lock held and all DMAC interrupts disabled */ 456 472 static void dwc_handle_cyclic(struct dw_dma *dw, struct dw_dma_chan *dwc, 457 - u32 status_block, u32 status_err, u32 status_xfer) 473 + u32 status_err, u32 status_xfer) 458 474 { 459 475 unsigned long flags; 460 476 461 - if (status_block & dwc->mask) { 477 + if (dwc->mask) { 462 478 void (*callback)(void *param); 463 479 void *callback_param; 464 480 465 481 dev_vdbg(chan2dev(&dwc->chan), "new cyclic period llp 0x%08x\n", 466 482 channel_readl(dwc, LLP)); 467 - dma_writel(dw, CLEAR.BLOCK, dwc->mask); 468 483 469 484 callback = dwc->cdesc->period_callback; 470 485 callback_param = dwc->cdesc->period_callback_param; ··· 503 520 channel_writel(dwc, CTL_LO, 0); 504 521 channel_writel(dwc, CTL_HI, 0); 505 522 506 - dma_writel(dw, CLEAR.BLOCK, dwc->mask); 507 523 dma_writel(dw, CLEAR.ERROR, dwc->mask); 508 524 dma_writel(dw, CLEAR.XFER, dwc->mask); 509 525 ··· 519 537 { 520 538 struct dw_dma *dw = (struct dw_dma *)data; 521 539 struct dw_dma_chan *dwc; 522 - u32 status_block; 523 540 u32 status_xfer; 524 541 u32 status_err; 525 542 int i; 526 543 527 - status_block = dma_readl(dw, RAW.BLOCK); 528 544 status_xfer = dma_readl(dw, RAW.XFER); 529 545 status_err = dma_readl(dw, RAW.ERROR); 530 546 531 - dev_vdbg(dw->dma.dev, "tasklet: status_block=%x status_err=%x\n", 532 - status_block, status_err); 547 + dev_vdbg(dw->dma.dev, "tasklet: status_err=%x\n", status_err); 533 548 534 549 for (i = 0; i < dw->dma.chancnt; i++) { 535 550 dwc = &dw->chan[i]; 536 551 if (test_bit(DW_DMA_IS_CYCLIC, &dwc->flags)) 537 - dwc_handle_cyclic(dw, dwc, status_block, status_err, 538 - status_xfer); 552 + dwc_handle_cyclic(dw, dwc, status_err, status_xfer); 539 553 else if (status_err & (1 << i)) 540 554 dwc_handle_error(dw, dwc); 541 - else if ((status_block | status_xfer) & (1 << i)) 555 + else if (status_xfer & (1 << i)) 542 556 dwc_scan_descriptors(dw, dwc); 543 557 } 544 558 545 559 /* 546 - * Re-enable interrupts. Block Complete interrupts are only 547 - * enabled if the INT_EN bit in the descriptor is set. This 548 - * will trigger a scan before the whole list is done. 560 + * Re-enable interrupts. 549 561 */ 550 562 channel_set_bit(dw, MASK.XFER, dw->all_chan_mask); 551 - channel_set_bit(dw, MASK.BLOCK, dw->all_chan_mask); 552 563 channel_set_bit(dw, MASK.ERROR, dw->all_chan_mask); 553 564 } 554 565 ··· 558 583 * softirq handler. 559 584 */ 560 585 channel_clear_bit(dw, MASK.XFER, dw->all_chan_mask); 561 - channel_clear_bit(dw, MASK.BLOCK, dw->all_chan_mask); 562 586 channel_clear_bit(dw, MASK.ERROR, dw->all_chan_mask); 563 587 564 588 status = dma_readl(dw, STATUS_INT); ··· 568 594 569 595 /* Try to recover */ 570 596 channel_clear_bit(dw, MASK.XFER, (1 << 8) - 1); 571 - channel_clear_bit(dw, MASK.BLOCK, (1 << 8) - 1); 572 597 channel_clear_bit(dw, MASK.SRC_TRAN, (1 << 8) - 1); 573 598 channel_clear_bit(dw, MASK.DST_TRAN, (1 << 8) - 1); 574 599 channel_clear_bit(dw, MASK.ERROR, (1 << 8) - 1); ··· 588 615 unsigned long flags; 589 616 590 617 spin_lock_irqsave(&dwc->lock, flags); 591 - cookie = dwc_assign_cookie(dwc, desc); 618 + cookie = dma_cookie_assign(tx); 592 619 593 620 /* 594 621 * REVISIT: We should attempt to chain as many descriptors as ··· 647 674 else 648 675 src_width = dst_width = 0; 649 676 650 - ctllo = DWC_DEFAULT_CTLLO(chan->private) 677 + ctllo = DWC_DEFAULT_CTLLO(chan) 651 678 | DWC_CTLL_DST_WIDTH(dst_width) 652 679 | DWC_CTLL_SRC_WIDTH(src_width) 653 680 | DWC_CTLL_DST_INC ··· 704 731 static struct dma_async_tx_descriptor * 705 732 dwc_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl, 706 733 unsigned int sg_len, enum dma_transfer_direction direction, 707 - unsigned long flags) 734 + unsigned long flags, void *context) 708 735 { 709 736 struct dw_dma_chan *dwc = to_dw_dma_chan(chan); 710 737 struct dw_dma_slave *dws = chan->private; 738 + struct dma_slave_config *sconfig = &dwc->dma_sconfig; 711 739 struct dw_desc *prev; 712 740 struct dw_desc *first; 713 741 u32 ctllo; ··· 724 750 if (unlikely(!dws || !sg_len)) 725 751 return NULL; 726 752 727 - reg_width = dws->reg_width; 728 753 prev = first = NULL; 729 754 730 755 switch (direction) { 731 756 case DMA_MEM_TO_DEV: 732 - ctllo = (DWC_DEFAULT_CTLLO(chan->private) 757 + reg_width = __fls(sconfig->dst_addr_width); 758 + reg = sconfig->dst_addr; 759 + ctllo = (DWC_DEFAULT_CTLLO(chan) 733 760 | DWC_CTLL_DST_WIDTH(reg_width) 734 761 | DWC_CTLL_DST_FIX 735 - | DWC_CTLL_SRC_INC 736 - | DWC_CTLL_FC(dws->fc)); 737 - reg = dws->tx_reg; 762 + | DWC_CTLL_SRC_INC); 763 + 764 + ctllo |= sconfig->device_fc ? DWC_CTLL_FC(DW_DMA_FC_P_M2P) : 765 + DWC_CTLL_FC(DW_DMA_FC_D_M2P); 766 + 738 767 for_each_sg(sgl, sg, sg_len, i) { 739 768 struct dw_desc *desc; 740 769 u32 len, dlen, mem; 741 770 742 771 mem = sg_phys(sg); 743 772 len = sg_dma_len(sg); 744 - mem_width = 2; 745 - if (unlikely(mem & 3 || len & 3)) 773 + 774 + if (!((mem | len) & 7)) 775 + mem_width = 3; 776 + else if (!((mem | len) & 3)) 777 + mem_width = 2; 778 + else if (!((mem | len) & 1)) 779 + mem_width = 1; 780 + else 746 781 mem_width = 0; 747 782 748 783 slave_sg_todev_fill_desc: ··· 795 812 } 796 813 break; 797 814 case DMA_DEV_TO_MEM: 798 - ctllo = (DWC_DEFAULT_CTLLO(chan->private) 815 + reg_width = __fls(sconfig->src_addr_width); 816 + reg = sconfig->src_addr; 817 + ctllo = (DWC_DEFAULT_CTLLO(chan) 799 818 | DWC_CTLL_SRC_WIDTH(reg_width) 800 819 | DWC_CTLL_DST_INC 801 - | DWC_CTLL_SRC_FIX 802 - | DWC_CTLL_FC(dws->fc)); 820 + | DWC_CTLL_SRC_FIX); 803 821 804 - reg = dws->rx_reg; 822 + ctllo |= sconfig->device_fc ? DWC_CTLL_FC(DW_DMA_FC_P_P2M) : 823 + DWC_CTLL_FC(DW_DMA_FC_D_P2M); 824 + 805 825 for_each_sg(sgl, sg, sg_len, i) { 806 826 struct dw_desc *desc; 807 827 u32 len, dlen, mem; 808 828 809 829 mem = sg_phys(sg); 810 830 len = sg_dma_len(sg); 811 - mem_width = 2; 812 - if (unlikely(mem & 3 || len & 3)) 831 + 832 + if (!((mem | len) & 7)) 833 + mem_width = 3; 834 + else if (!((mem | len) & 3)) 835 + mem_width = 2; 836 + else if (!((mem | len) & 1)) 837 + mem_width = 1; 838 + else 813 839 mem_width = 0; 814 840 815 841 slave_sg_fromdev_fill_desc: ··· 882 890 return NULL; 883 891 } 884 892 893 + /* 894 + * Fix sconfig's burst size according to dw_dmac. We need to convert them as: 895 + * 1 -> 0, 4 -> 1, 8 -> 2, 16 -> 3. 896 + * 897 + * NOTE: burst size 2 is not supported by controller. 898 + * 899 + * This can be done by finding least significant bit set: n & (n - 1) 900 + */ 901 + static inline void convert_burst(u32 *maxburst) 902 + { 903 + if (*maxburst > 1) 904 + *maxburst = fls(*maxburst) - 2; 905 + else 906 + *maxburst = 0; 907 + } 908 + 909 + static int 910 + set_runtime_config(struct dma_chan *chan, struct dma_slave_config *sconfig) 911 + { 912 + struct dw_dma_chan *dwc = to_dw_dma_chan(chan); 913 + 914 + /* Check if it is chan is configured for slave transfers */ 915 + if (!chan->private) 916 + return -EINVAL; 917 + 918 + memcpy(&dwc->dma_sconfig, sconfig, sizeof(*sconfig)); 919 + 920 + convert_burst(&dwc->dma_sconfig.src_maxburst); 921 + convert_burst(&dwc->dma_sconfig.dst_maxburst); 922 + 923 + return 0; 924 + } 925 + 885 926 static int dwc_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd, 886 927 unsigned long arg) 887 928 { ··· 964 939 /* Flush all pending and queued descriptors */ 965 940 list_for_each_entry_safe(desc, _desc, &list, desc_node) 966 941 dwc_descriptor_complete(dwc, desc, false); 967 - } else 942 + } else if (cmd == DMA_SLAVE_CONFIG) { 943 + return set_runtime_config(chan, (struct dma_slave_config *)arg); 944 + } else { 968 945 return -ENXIO; 946 + } 969 947 970 948 return 0; 971 949 } ··· 979 951 struct dma_tx_state *txstate) 980 952 { 981 953 struct dw_dma_chan *dwc = to_dw_dma_chan(chan); 982 - dma_cookie_t last_used; 983 - dma_cookie_t last_complete; 984 - int ret; 954 + enum dma_status ret; 985 955 986 - last_complete = dwc->completed; 987 - last_used = chan->cookie; 988 - 989 - ret = dma_async_is_complete(cookie, last_complete, last_used); 956 + ret = dma_cookie_status(chan, cookie, txstate); 990 957 if (ret != DMA_SUCCESS) { 991 958 dwc_scan_descriptors(to_dw_dma(chan->device), dwc); 992 959 993 - last_complete = dwc->completed; 994 - last_used = chan->cookie; 995 - 996 - ret = dma_async_is_complete(cookie, last_complete, last_used); 960 + ret = dma_cookie_status(chan, cookie, txstate); 997 961 } 998 962 999 963 if (ret != DMA_SUCCESS) 1000 - dma_set_tx_state(txstate, last_complete, last_used, 1001 - dwc_first_active(dwc)->len); 1002 - else 1003 - dma_set_tx_state(txstate, last_complete, last_used, 0); 964 + dma_set_residue(txstate, dwc_first_active(dwc)->len); 1004 965 1005 966 if (dwc->paused) 1006 967 return DMA_PAUSED; ··· 1021 1004 return -EIO; 1022 1005 } 1023 1006 1024 - dwc->completed = chan->cookie = 1; 1007 + dma_cookie_init(chan); 1025 1008 1026 1009 /* 1027 1010 * NOTE: some controllers may have additional features that we ··· 1085 1068 1086 1069 /* Disable interrupts */ 1087 1070 channel_clear_bit(dw, MASK.XFER, dwc->mask); 1088 - channel_clear_bit(dw, MASK.BLOCK, dwc->mask); 1089 1071 channel_clear_bit(dw, MASK.ERROR, dwc->mask); 1090 1072 1091 1073 spin_unlock_irqrestore(&dwc->lock, flags); ··· 1136 1120 return -EBUSY; 1137 1121 } 1138 1122 1139 - dma_writel(dw, CLEAR.BLOCK, dwc->mask); 1140 1123 dma_writel(dw, CLEAR.ERROR, dwc->mask); 1141 1124 dma_writel(dw, CLEAR.XFER, dwc->mask); 1142 1125 ··· 1190 1175 enum dma_transfer_direction direction) 1191 1176 { 1192 1177 struct dw_dma_chan *dwc = to_dw_dma_chan(chan); 1178 + struct dma_slave_config *sconfig = &dwc->dma_sconfig; 1193 1179 struct dw_cyclic_desc *cdesc; 1194 1180 struct dw_cyclic_desc *retval = NULL; 1195 1181 struct dw_desc *desc; 1196 1182 struct dw_desc *last = NULL; 1197 - struct dw_dma_slave *dws = chan->private; 1198 1183 unsigned long was_cyclic; 1199 1184 unsigned int reg_width; 1200 1185 unsigned int periods; ··· 1218 1203 } 1219 1204 1220 1205 retval = ERR_PTR(-EINVAL); 1221 - reg_width = dws->reg_width; 1206 + 1207 + if (direction == DMA_MEM_TO_DEV) 1208 + reg_width = __ffs(sconfig->dst_addr_width); 1209 + else 1210 + reg_width = __ffs(sconfig->src_addr_width); 1211 + 1222 1212 periods = buf_len / period_len; 1223 1213 1224 1214 /* Check for too big/unaligned periods and unaligned DMA buffer. */ ··· 1256 1236 1257 1237 switch (direction) { 1258 1238 case DMA_MEM_TO_DEV: 1259 - desc->lli.dar = dws->tx_reg; 1239 + desc->lli.dar = sconfig->dst_addr; 1260 1240 desc->lli.sar = buf_addr + (period_len * i); 1261 - desc->lli.ctllo = (DWC_DEFAULT_CTLLO(chan->private) 1241 + desc->lli.ctllo = (DWC_DEFAULT_CTLLO(chan) 1262 1242 | DWC_CTLL_DST_WIDTH(reg_width) 1263 1243 | DWC_CTLL_SRC_WIDTH(reg_width) 1264 1244 | DWC_CTLL_DST_FIX 1265 1245 | DWC_CTLL_SRC_INC 1266 - | DWC_CTLL_FC(dws->fc) 1267 1246 | DWC_CTLL_INT_EN); 1247 + 1248 + desc->lli.ctllo |= sconfig->device_fc ? 1249 + DWC_CTLL_FC(DW_DMA_FC_P_M2P) : 1250 + DWC_CTLL_FC(DW_DMA_FC_D_M2P); 1251 + 1268 1252 break; 1269 1253 case DMA_DEV_TO_MEM: 1270 1254 desc->lli.dar = buf_addr + (period_len * i); 1271 - desc->lli.sar = dws->rx_reg; 1272 - desc->lli.ctllo = (DWC_DEFAULT_CTLLO(chan->private) 1255 + desc->lli.sar = sconfig->src_addr; 1256 + desc->lli.ctllo = (DWC_DEFAULT_CTLLO(chan) 1273 1257 | DWC_CTLL_SRC_WIDTH(reg_width) 1274 1258 | DWC_CTLL_DST_WIDTH(reg_width) 1275 1259 | DWC_CTLL_DST_INC 1276 1260 | DWC_CTLL_SRC_FIX 1277 - | DWC_CTLL_FC(dws->fc) 1278 1261 | DWC_CTLL_INT_EN); 1262 + 1263 + desc->lli.ctllo |= sconfig->device_fc ? 1264 + DWC_CTLL_FC(DW_DMA_FC_P_P2M) : 1265 + DWC_CTLL_FC(DW_DMA_FC_D_P2M); 1266 + 1279 1267 break; 1280 1268 default: 1281 1269 break; ··· 1350 1322 while (dma_readl(dw, CH_EN) & dwc->mask) 1351 1323 cpu_relax(); 1352 1324 1353 - dma_writel(dw, CLEAR.BLOCK, dwc->mask); 1354 1325 dma_writel(dw, CLEAR.ERROR, dwc->mask); 1355 1326 dma_writel(dw, CLEAR.XFER, dwc->mask); 1356 1327 ··· 1374 1347 dma_writel(dw, CFG, 0); 1375 1348 1376 1349 channel_clear_bit(dw, MASK.XFER, dw->all_chan_mask); 1377 - channel_clear_bit(dw, MASK.BLOCK, dw->all_chan_mask); 1378 1350 channel_clear_bit(dw, MASK.SRC_TRAN, dw->all_chan_mask); 1379 1351 channel_clear_bit(dw, MASK.DST_TRAN, dw->all_chan_mask); 1380 1352 channel_clear_bit(dw, MASK.ERROR, dw->all_chan_mask); ··· 1395 1369 int err; 1396 1370 int i; 1397 1371 1398 - pdata = pdev->dev.platform_data; 1372 + pdata = dev_get_platdata(&pdev->dev); 1399 1373 if (!pdata || pdata->nr_channels > DW_DMA_MAX_NR_CHANNELS) 1400 1374 return -EINVAL; 1401 1375 ··· 1449 1423 struct dw_dma_chan *dwc = &dw->chan[i]; 1450 1424 1451 1425 dwc->chan.device = &dw->dma; 1452 - dwc->chan.cookie = dwc->completed = 1; 1426 + dma_cookie_init(&dwc->chan); 1453 1427 if (pdata->chan_allocation_order == CHAN_ALLOCATION_ASCENDING) 1454 1428 list_add_tail(&dwc->chan.device_node, 1455 1429 &dw->dma.channels); ··· 1458 1432 1459 1433 /* 7 is highest priority & 0 is lowest. */ 1460 1434 if (pdata->chan_priority == CHAN_PRIORITY_ASCENDING) 1461 - dwc->priority = 7 - i; 1435 + dwc->priority = pdata->nr_channels - i - 1; 1462 1436 else 1463 1437 dwc->priority = i; 1464 1438 ··· 1475 1449 1476 1450 /* Clear/disable all interrupts on all channels. */ 1477 1451 dma_writel(dw, CLEAR.XFER, dw->all_chan_mask); 1478 - dma_writel(dw, CLEAR.BLOCK, dw->all_chan_mask); 1479 1452 dma_writel(dw, CLEAR.SRC_TRAN, dw->all_chan_mask); 1480 1453 dma_writel(dw, CLEAR.DST_TRAN, dw->all_chan_mask); 1481 1454 dma_writel(dw, CLEAR.ERROR, dw->all_chan_mask); 1482 1455 1483 1456 channel_clear_bit(dw, MASK.XFER, dw->all_chan_mask); 1484 - channel_clear_bit(dw, MASK.BLOCK, dw->all_chan_mask); 1485 1457 channel_clear_bit(dw, MASK.SRC_TRAN, dw->all_chan_mask); 1486 1458 channel_clear_bit(dw, MASK.DST_TRAN, dw->all_chan_mask); 1487 1459 channel_clear_bit(dw, MASK.ERROR, dw->all_chan_mask); ··· 1586 1562 static const struct dev_pm_ops dw_dev_pm_ops = { 1587 1563 .suspend_noirq = dw_suspend_noirq, 1588 1564 .resume_noirq = dw_resume_noirq, 1565 + .freeze_noirq = dw_suspend_noirq, 1566 + .thaw_noirq = dw_resume_noirq, 1567 + .restore_noirq = dw_resume_noirq, 1568 + .poweroff_noirq = dw_suspend_noirq, 1589 1569 }; 1590 1570 1591 1571 static struct platform_driver dw_driver = {
+15 -1
drivers/dma/dw_dmac_regs.h
··· 13 13 14 14 #define DW_DMA_MAX_NR_CHANNELS 8 15 15 16 + /* flow controller */ 17 + enum dw_dma_fc { 18 + DW_DMA_FC_D_M2M, 19 + DW_DMA_FC_D_M2P, 20 + DW_DMA_FC_D_P2M, 21 + DW_DMA_FC_D_P2P, 22 + DW_DMA_FC_P_P2M, 23 + DW_DMA_FC_SP_P2P, 24 + DW_DMA_FC_P_M2P, 25 + DW_DMA_FC_DP_P2P, 26 + }; 27 + 16 28 /* 17 29 * Redefine this macro to handle differences between 32- and 64-bit 18 30 * addressing, big vs. little endian, etc. ··· 158 146 159 147 /* these other elements are all protected by lock */ 160 148 unsigned long flags; 161 - dma_cookie_t completed; 162 149 struct list_head active_list; 163 150 struct list_head queue; 164 151 struct list_head free_list; 165 152 struct dw_cyclic_desc *cdesc; 166 153 167 154 unsigned int descs_allocated; 155 + 156 + /* configuration passed via DMA_SLAVE_CONFIG */ 157 + struct dma_slave_config dma_sconfig; 168 158 }; 169 159 170 160 static inline struct dw_dma_chan_regs __iomem *
+10 -21
drivers/dma/ep93xx_dma.c
··· 28 28 29 29 #include <mach/dma.h> 30 30 31 + #include "dmaengine.h" 32 + 31 33 /* M2P registers */ 32 34 #define M2P_CONTROL 0x0000 33 35 #define M2P_CONTROL_STALLINT BIT(0) ··· 124 122 * @lock: lock protecting the fields following 125 123 * @flags: flags for the channel 126 124 * @buffer: which buffer to use next (0/1) 127 - * @last_completed: last completed cookie value 128 125 * @active: flattened chain of descriptors currently being processed 129 126 * @queue: pending descriptors which are handled next 130 127 * @free_list: list of free descriptors which can be used ··· 158 157 #define EP93XX_DMA_IS_CYCLIC 0 159 158 160 159 int buffer; 161 - dma_cookie_t last_completed; 162 160 struct list_head active; 163 161 struct list_head queue; 164 162 struct list_head free_list; ··· 703 703 desc = ep93xx_dma_get_active(edmac); 704 704 if (desc) { 705 705 if (desc->complete) { 706 - edmac->last_completed = desc->txd.cookie; 706 + dma_cookie_complete(&desc->txd); 707 707 list_splice_init(&edmac->active, &list); 708 708 } 709 709 callback = desc->txd.callback; ··· 783 783 unsigned long flags; 784 784 785 785 spin_lock_irqsave(&edmac->lock, flags); 786 - 787 - cookie = edmac->chan.cookie; 788 - 789 - if (++cookie < 0) 790 - cookie = 1; 786 + cookie = dma_cookie_assign(tx); 791 787 792 788 desc = container_of(tx, struct ep93xx_dma_desc, txd); 793 - 794 - edmac->chan.cookie = cookie; 795 - desc->txd.cookie = cookie; 796 789 797 790 /* 798 791 * If nothing is currently prosessed, we push this descriptor ··· 854 861 goto fail_clk_disable; 855 862 856 863 spin_lock_irq(&edmac->lock); 857 - edmac->last_completed = 1; 858 - edmac->chan.cookie = 1; 864 + dma_cookie_init(&edmac->chan); 859 865 ret = edmac->edma->hw_setup(edmac); 860 866 spin_unlock_irq(&edmac->lock); 861 867 ··· 975 983 * @sg_len: number of entries in @sgl 976 984 * @dir: direction of tha DMA transfer 977 985 * @flags: flags for the descriptor 986 + * @context: operation context (ignored) 978 987 * 979 988 * Returns a valid DMA descriptor or %NULL in case of failure. 980 989 */ 981 990 static struct dma_async_tx_descriptor * 982 991 ep93xx_dma_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl, 983 992 unsigned int sg_len, enum dma_transfer_direction dir, 984 - unsigned long flags) 993 + unsigned long flags, void *context) 985 994 { 986 995 struct ep93xx_dma_chan *edmac = to_ep93xx_dma_chan(chan); 987 996 struct ep93xx_dma_desc *desc, *first; ··· 1049 1056 * @buf_len: length of the buffer (in bytes) 1050 1057 * @period_len: lenght of a single period 1051 1058 * @dir: direction of the operation 1059 + * @context: operation context (ignored) 1052 1060 * 1053 1061 * Prepares a descriptor for cyclic DMA operation. This means that once the 1054 1062 * descriptor is submitted, we will be submitting in a @period_len sized ··· 1062 1068 static struct dma_async_tx_descriptor * 1063 1069 ep93xx_dma_prep_dma_cyclic(struct dma_chan *chan, dma_addr_t dma_addr, 1064 1070 size_t buf_len, size_t period_len, 1065 - enum dma_transfer_direction dir) 1071 + enum dma_transfer_direction dir, void *context) 1066 1072 { 1067 1073 struct ep93xx_dma_chan *edmac = to_ep93xx_dma_chan(chan); 1068 1074 struct ep93xx_dma_desc *desc, *first; ··· 1242 1248 struct dma_tx_state *state) 1243 1249 { 1244 1250 struct ep93xx_dma_chan *edmac = to_ep93xx_dma_chan(chan); 1245 - dma_cookie_t last_used, last_completed; 1246 1251 enum dma_status ret; 1247 1252 unsigned long flags; 1248 1253 1249 1254 spin_lock_irqsave(&edmac->lock, flags); 1250 - last_used = chan->cookie; 1251 - last_completed = edmac->last_completed; 1255 + ret = dma_cookie_status(chan, cookie, state); 1252 1256 spin_unlock_irqrestore(&edmac->lock, flags); 1253 - 1254 - ret = dma_async_is_complete(cookie, last_completed, last_used); 1255 - dma_set_tx_state(state, last_completed, last_used, 0); 1256 1257 1257 1258 return ret; 1258 1259 }
+10 -18
drivers/dma/fsldma.c
··· 35 35 #include <linux/dmapool.h> 36 36 #include <linux/of_platform.h> 37 37 38 + #include "dmaengine.h" 38 39 #include "fsldma.h" 39 40 40 41 #define chan_dbg(chan, fmt, arg...) \ ··· 414 413 * assign cookies to all of the software descriptors 415 414 * that make up this transaction 416 415 */ 417 - cookie = chan->common.cookie; 418 416 list_for_each_entry(child, &desc->tx_list, node) { 419 - cookie++; 420 - if (cookie < DMA_MIN_COOKIE) 421 - cookie = DMA_MIN_COOKIE; 422 - 423 - child->async_tx.cookie = cookie; 417 + cookie = dma_cookie_assign(&child->async_tx); 424 418 } 425 - 426 - chan->common.cookie = cookie; 427 419 428 420 /* put this transaction onto the tail of the pending queue */ 429 421 append_ld_queue(chan, desc); ··· 759 765 * @sg_len: number of entries in @scatterlist 760 766 * @direction: DMA direction 761 767 * @flags: DMAEngine flags 768 + * @context: transaction context (ignored) 762 769 * 763 770 * Prepare a set of descriptors for a DMA_SLAVE transaction. Following the 764 771 * DMA_SLAVE API, this gets the device-specific information from the ··· 767 772 */ 768 773 static struct dma_async_tx_descriptor *fsl_dma_prep_slave_sg( 769 774 struct dma_chan *dchan, struct scatterlist *sgl, unsigned int sg_len, 770 - enum dma_transfer_direction direction, unsigned long flags) 775 + enum dma_transfer_direction direction, unsigned long flags, 776 + void *context) 771 777 { 772 778 /* 773 779 * This operation is not supported on the Freescale DMA controller ··· 980 984 struct dma_tx_state *txstate) 981 985 { 982 986 struct fsldma_chan *chan = to_fsl_chan(dchan); 983 - dma_cookie_t last_complete; 984 - dma_cookie_t last_used; 987 + enum dma_status ret; 985 988 unsigned long flags; 986 989 987 990 spin_lock_irqsave(&chan->desc_lock, flags); 988 - 989 - last_complete = chan->completed_cookie; 990 - last_used = dchan->cookie; 991 - 991 + ret = dma_cookie_status(dchan, cookie, txstate); 992 992 spin_unlock_irqrestore(&chan->desc_lock, flags); 993 993 994 - dma_set_tx_state(txstate, last_complete, last_used, 0); 995 - return dma_async_is_complete(cookie, last_complete, last_used); 994 + return ret; 996 995 } 997 996 998 997 /*----------------------------------------------------------------------------*/ ··· 1078 1087 1079 1088 desc = to_fsl_desc(chan->ld_running.prev); 1080 1089 cookie = desc->async_tx.cookie; 1090 + dma_cookie_complete(&desc->async_tx); 1081 1091 1082 - chan->completed_cookie = cookie; 1083 1092 chan_dbg(chan, "completed_cookie=%d\n", cookie); 1084 1093 } 1085 1094 ··· 1294 1303 chan->idle = true; 1295 1304 1296 1305 chan->common.device = &fdev->common; 1306 + dma_cookie_init(&chan->common); 1297 1307 1298 1308 /* find the IRQ line, if it exists in the device tree */ 1299 1309 chan->irq = irq_of_parse_and_map(node, 0);
-1
drivers/dma/fsldma.h
··· 137 137 struct fsldma_chan { 138 138 char name[8]; /* Channel name */ 139 139 struct fsldma_chan_regs __iomem *regs; 140 - dma_cookie_t completed_cookie; /* The maximum cookie completed */ 141 140 spinlock_t desc_lock; /* Descriptor operation lock */ 142 141 struct list_head ld_pending; /* Link descriptors queue */ 143 142 struct list_head ld_running; /* Link descriptors queue */
+821 -131
drivers/dma/imx-dma.c
··· 5 5 * found on i.MX1/21/27 6 6 * 7 7 * Copyright 2010 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de> 8 + * Copyright 2012 Javier Martin, Vista Silicon <javier.martin@vista-silicon.com> 8 9 * 9 10 * The code contained herein is licensed under the GNU General Public 10 11 * License. You may obtain a copy of the GNU General Public License ··· 23 22 #include <linux/dma-mapping.h> 24 23 #include <linux/slab.h> 25 24 #include <linux/platform_device.h> 25 + #include <linux/clk.h> 26 26 #include <linux/dmaengine.h> 27 27 #include <linux/module.h> 28 28 29 29 #include <asm/irq.h> 30 - #include <mach/dma-v1.h> 30 + #include <mach/dma.h> 31 31 #include <mach/hardware.h> 32 32 33 + #include "dmaengine.h" 34 + #define IMXDMA_MAX_CHAN_DESCRIPTORS 16 35 + #define IMX_DMA_CHANNELS 16 36 + 37 + #define IMX_DMA_2D_SLOTS 2 38 + #define IMX_DMA_2D_SLOT_A 0 39 + #define IMX_DMA_2D_SLOT_B 1 40 + 41 + #define IMX_DMA_LENGTH_LOOP ((unsigned int)-1) 42 + #define IMX_DMA_MEMSIZE_32 (0 << 4) 43 + #define IMX_DMA_MEMSIZE_8 (1 << 4) 44 + #define IMX_DMA_MEMSIZE_16 (2 << 4) 45 + #define IMX_DMA_TYPE_LINEAR (0 << 10) 46 + #define IMX_DMA_TYPE_2D (1 << 10) 47 + #define IMX_DMA_TYPE_FIFO (2 << 10) 48 + 49 + #define IMX_DMA_ERR_BURST (1 << 0) 50 + #define IMX_DMA_ERR_REQUEST (1 << 1) 51 + #define IMX_DMA_ERR_TRANSFER (1 << 2) 52 + #define IMX_DMA_ERR_BUFFER (1 << 3) 53 + #define IMX_DMA_ERR_TIMEOUT (1 << 4) 54 + 55 + #define DMA_DCR 0x00 /* Control Register */ 56 + #define DMA_DISR 0x04 /* Interrupt status Register */ 57 + #define DMA_DIMR 0x08 /* Interrupt mask Register */ 58 + #define DMA_DBTOSR 0x0c /* Burst timeout status Register */ 59 + #define DMA_DRTOSR 0x10 /* Request timeout Register */ 60 + #define DMA_DSESR 0x14 /* Transfer Error Status Register */ 61 + #define DMA_DBOSR 0x18 /* Buffer overflow status Register */ 62 + #define DMA_DBTOCR 0x1c /* Burst timeout control Register */ 63 + #define DMA_WSRA 0x40 /* W-Size Register A */ 64 + #define DMA_XSRA 0x44 /* X-Size Register A */ 65 + #define DMA_YSRA 0x48 /* Y-Size Register A */ 66 + #define DMA_WSRB 0x4c /* W-Size Register B */ 67 + #define DMA_XSRB 0x50 /* X-Size Register B */ 68 + #define DMA_YSRB 0x54 /* Y-Size Register B */ 69 + #define DMA_SAR(x) (0x80 + ((x) << 6)) /* Source Address Registers */ 70 + #define DMA_DAR(x) (0x84 + ((x) << 6)) /* Destination Address Registers */ 71 + #define DMA_CNTR(x) (0x88 + ((x) << 6)) /* Count Registers */ 72 + #define DMA_CCR(x) (0x8c + ((x) << 6)) /* Control Registers */ 73 + #define DMA_RSSR(x) (0x90 + ((x) << 6)) /* Request source select Registers */ 74 + #define DMA_BLR(x) (0x94 + ((x) << 6)) /* Burst length Registers */ 75 + #define DMA_RTOR(x) (0x98 + ((x) << 6)) /* Request timeout Registers */ 76 + #define DMA_BUCR(x) (0x98 + ((x) << 6)) /* Bus Utilization Registers */ 77 + #define DMA_CCNR(x) (0x9C + ((x) << 6)) /* Channel counter Registers */ 78 + 79 + #define DCR_DRST (1<<1) 80 + #define DCR_DEN (1<<0) 81 + #define DBTOCR_EN (1<<15) 82 + #define DBTOCR_CNT(x) ((x) & 0x7fff) 83 + #define CNTR_CNT(x) ((x) & 0xffffff) 84 + #define CCR_ACRPT (1<<14) 85 + #define CCR_DMOD_LINEAR (0x0 << 12) 86 + #define CCR_DMOD_2D (0x1 << 12) 87 + #define CCR_DMOD_FIFO (0x2 << 12) 88 + #define CCR_DMOD_EOBFIFO (0x3 << 12) 89 + #define CCR_SMOD_LINEAR (0x0 << 10) 90 + #define CCR_SMOD_2D (0x1 << 10) 91 + #define CCR_SMOD_FIFO (0x2 << 10) 92 + #define CCR_SMOD_EOBFIFO (0x3 << 10) 93 + #define CCR_MDIR_DEC (1<<9) 94 + #define CCR_MSEL_B (1<<8) 95 + #define CCR_DSIZ_32 (0x0 << 6) 96 + #define CCR_DSIZ_8 (0x1 << 6) 97 + #define CCR_DSIZ_16 (0x2 << 6) 98 + #define CCR_SSIZ_32 (0x0 << 4) 99 + #define CCR_SSIZ_8 (0x1 << 4) 100 + #define CCR_SSIZ_16 (0x2 << 4) 101 + #define CCR_REN (1<<3) 102 + #define CCR_RPT (1<<2) 103 + #define CCR_FRC (1<<1) 104 + #define CCR_CEN (1<<0) 105 + #define RTOR_EN (1<<15) 106 + #define RTOR_CLK (1<<14) 107 + #define RTOR_PSC (1<<13) 108 + 109 + enum imxdma_prep_type { 110 + IMXDMA_DESC_MEMCPY, 111 + IMXDMA_DESC_INTERLEAVED, 112 + IMXDMA_DESC_SLAVE_SG, 113 + IMXDMA_DESC_CYCLIC, 114 + }; 115 + 116 + struct imx_dma_2d_config { 117 + u16 xsr; 118 + u16 ysr; 119 + u16 wsr; 120 + int count; 121 + }; 122 + 123 + struct imxdma_desc { 124 + struct list_head node; 125 + struct dma_async_tx_descriptor desc; 126 + enum dma_status status; 127 + dma_addr_t src; 128 + dma_addr_t dest; 129 + size_t len; 130 + enum dma_transfer_direction direction; 131 + enum imxdma_prep_type type; 132 + /* For memcpy and interleaved */ 133 + unsigned int config_port; 134 + unsigned int config_mem; 135 + /* For interleaved transfers */ 136 + unsigned int x; 137 + unsigned int y; 138 + unsigned int w; 139 + /* For slave sg and cyclic */ 140 + struct scatterlist *sg; 141 + unsigned int sgcount; 142 + }; 143 + 33 144 struct imxdma_channel { 145 + int hw_chaining; 146 + struct timer_list watchdog; 34 147 struct imxdma_engine *imxdma; 35 148 unsigned int channel; 36 - unsigned int imxdma_channel; 37 149 150 + struct tasklet_struct dma_tasklet; 151 + struct list_head ld_free; 152 + struct list_head ld_queue; 153 + struct list_head ld_active; 154 + int descs_allocated; 38 155 enum dma_slave_buswidth word_size; 39 156 dma_addr_t per_address; 40 157 u32 watermark_level; 41 158 struct dma_chan chan; 42 - spinlock_t lock; 43 159 struct dma_async_tx_descriptor desc; 44 - dma_cookie_t last_completed; 45 160 enum dma_status status; 46 161 int dma_request; 47 162 struct scatterlist *sg_list; 163 + u32 ccr_from_device; 164 + u32 ccr_to_device; 165 + bool enabled_2d; 166 + int slot_2d; 48 167 }; 49 - 50 - #define MAX_DMA_CHANNELS 8 51 168 52 169 struct imxdma_engine { 53 170 struct device *dev; 54 171 struct device_dma_parameters dma_parms; 55 172 struct dma_device dma_device; 56 - struct imxdma_channel channel[MAX_DMA_CHANNELS]; 173 + void __iomem *base; 174 + struct clk *dma_clk; 175 + spinlock_t lock; 176 + struct imx_dma_2d_config slots_2d[IMX_DMA_2D_SLOTS]; 177 + struct imxdma_channel channel[IMX_DMA_CHANNELS]; 57 178 }; 58 179 59 180 static struct imxdma_channel *to_imxdma_chan(struct dma_chan *chan) ··· 183 60 return container_of(chan, struct imxdma_channel, chan); 184 61 } 185 62 186 - static void imxdma_handle(struct imxdma_channel *imxdmac) 63 + static inline bool imxdma_chan_is_doing_cyclic(struct imxdma_channel *imxdmac) 187 64 { 188 - if (imxdmac->desc.callback) 189 - imxdmac->desc.callback(imxdmac->desc.callback_param); 190 - imxdmac->last_completed = imxdmac->desc.cookie; 65 + struct imxdma_desc *desc; 66 + 67 + if (!list_empty(&imxdmac->ld_active)) { 68 + desc = list_first_entry(&imxdmac->ld_active, struct imxdma_desc, 69 + node); 70 + if (desc->type == IMXDMA_DESC_CYCLIC) 71 + return true; 72 + } 73 + return false; 191 74 } 192 75 193 - static void imxdma_irq_handler(int channel, void *data) 194 - { 195 - struct imxdma_channel *imxdmac = data; 196 76 197 - imxdmac->status = DMA_SUCCESS; 198 - imxdma_handle(imxdmac); 77 + 78 + static void imx_dmav1_writel(struct imxdma_engine *imxdma, unsigned val, 79 + unsigned offset) 80 + { 81 + __raw_writel(val, imxdma->base + offset); 199 82 } 200 83 201 - static void imxdma_err_handler(int channel, void *data, int error) 84 + static unsigned imx_dmav1_readl(struct imxdma_engine *imxdma, unsigned offset) 202 85 { 203 - struct imxdma_channel *imxdmac = data; 204 - 205 - imxdmac->status = DMA_ERROR; 206 - imxdma_handle(imxdmac); 86 + return __raw_readl(imxdma->base + offset); 207 87 } 208 88 209 - static void imxdma_progression(int channel, void *data, 210 - struct scatterlist *sg) 89 + static int imxdma_hw_chain(struct imxdma_channel *imxdmac) 211 90 { 212 - struct imxdma_channel *imxdmac = data; 91 + if (cpu_is_mx27()) 92 + return imxdmac->hw_chaining; 93 + else 94 + return 0; 95 + } 213 96 214 - imxdmac->status = DMA_SUCCESS; 215 - imxdma_handle(imxdmac); 97 + /* 98 + * imxdma_sg_next - prepare next chunk for scatter-gather DMA emulation 99 + */ 100 + static inline int imxdma_sg_next(struct imxdma_desc *d) 101 + { 102 + struct imxdma_channel *imxdmac = to_imxdma_chan(d->desc.chan); 103 + struct imxdma_engine *imxdma = imxdmac->imxdma; 104 + struct scatterlist *sg = d->sg; 105 + unsigned long now; 106 + 107 + now = min(d->len, sg->length); 108 + if (d->len != IMX_DMA_LENGTH_LOOP) 109 + d->len -= now; 110 + 111 + if (d->direction == DMA_DEV_TO_MEM) 112 + imx_dmav1_writel(imxdma, sg->dma_address, 113 + DMA_DAR(imxdmac->channel)); 114 + else 115 + imx_dmav1_writel(imxdma, sg->dma_address, 116 + DMA_SAR(imxdmac->channel)); 117 + 118 + imx_dmav1_writel(imxdma, now, DMA_CNTR(imxdmac->channel)); 119 + 120 + dev_dbg(imxdma->dev, " %s channel: %d dst 0x%08x, src 0x%08x, " 121 + "size 0x%08x\n", __func__, imxdmac->channel, 122 + imx_dmav1_readl(imxdma, DMA_DAR(imxdmac->channel)), 123 + imx_dmav1_readl(imxdma, DMA_SAR(imxdmac->channel)), 124 + imx_dmav1_readl(imxdma, DMA_CNTR(imxdmac->channel))); 125 + 126 + return now; 127 + } 128 + 129 + static void imxdma_enable_hw(struct imxdma_desc *d) 130 + { 131 + struct imxdma_channel *imxdmac = to_imxdma_chan(d->desc.chan); 132 + struct imxdma_engine *imxdma = imxdmac->imxdma; 133 + int channel = imxdmac->channel; 134 + unsigned long flags; 135 + 136 + dev_dbg(imxdma->dev, "%s channel %d\n", __func__, channel); 137 + 138 + local_irq_save(flags); 139 + 140 + imx_dmav1_writel(imxdma, 1 << channel, DMA_DISR); 141 + imx_dmav1_writel(imxdma, imx_dmav1_readl(imxdma, DMA_DIMR) & 142 + ~(1 << channel), DMA_DIMR); 143 + imx_dmav1_writel(imxdma, imx_dmav1_readl(imxdma, DMA_CCR(channel)) | 144 + CCR_CEN | CCR_ACRPT, DMA_CCR(channel)); 145 + 146 + if ((cpu_is_mx21() || cpu_is_mx27()) && 147 + d->sg && imxdma_hw_chain(imxdmac)) { 148 + d->sg = sg_next(d->sg); 149 + if (d->sg) { 150 + u32 tmp; 151 + imxdma_sg_next(d); 152 + tmp = imx_dmav1_readl(imxdma, DMA_CCR(channel)); 153 + imx_dmav1_writel(imxdma, tmp | CCR_RPT | CCR_ACRPT, 154 + DMA_CCR(channel)); 155 + } 156 + } 157 + 158 + local_irq_restore(flags); 159 + } 160 + 161 + static void imxdma_disable_hw(struct imxdma_channel *imxdmac) 162 + { 163 + struct imxdma_engine *imxdma = imxdmac->imxdma; 164 + int channel = imxdmac->channel; 165 + unsigned long flags; 166 + 167 + dev_dbg(imxdma->dev, "%s channel %d\n", __func__, channel); 168 + 169 + if (imxdma_hw_chain(imxdmac)) 170 + del_timer(&imxdmac->watchdog); 171 + 172 + local_irq_save(flags); 173 + imx_dmav1_writel(imxdma, imx_dmav1_readl(imxdma, DMA_DIMR) | 174 + (1 << channel), DMA_DIMR); 175 + imx_dmav1_writel(imxdma, imx_dmav1_readl(imxdma, DMA_CCR(channel)) & 176 + ~CCR_CEN, DMA_CCR(channel)); 177 + imx_dmav1_writel(imxdma, 1 << channel, DMA_DISR); 178 + local_irq_restore(flags); 179 + } 180 + 181 + static void imxdma_watchdog(unsigned long data) 182 + { 183 + struct imxdma_channel *imxdmac = (struct imxdma_channel *)data; 184 + struct imxdma_engine *imxdma = imxdmac->imxdma; 185 + int channel = imxdmac->channel; 186 + 187 + imx_dmav1_writel(imxdma, 0, DMA_CCR(channel)); 188 + 189 + /* Tasklet watchdog error handler */ 190 + tasklet_schedule(&imxdmac->dma_tasklet); 191 + dev_dbg(imxdma->dev, "channel %d: watchdog timeout!\n", 192 + imxdmac->channel); 193 + } 194 + 195 + static irqreturn_t imxdma_err_handler(int irq, void *dev_id) 196 + { 197 + struct imxdma_engine *imxdma = dev_id; 198 + unsigned int err_mask; 199 + int i, disr; 200 + int errcode; 201 + 202 + disr = imx_dmav1_readl(imxdma, DMA_DISR); 203 + 204 + err_mask = imx_dmav1_readl(imxdma, DMA_DBTOSR) | 205 + imx_dmav1_readl(imxdma, DMA_DRTOSR) | 206 + imx_dmav1_readl(imxdma, DMA_DSESR) | 207 + imx_dmav1_readl(imxdma, DMA_DBOSR); 208 + 209 + if (!err_mask) 210 + return IRQ_HANDLED; 211 + 212 + imx_dmav1_writel(imxdma, disr & err_mask, DMA_DISR); 213 + 214 + for (i = 0; i < IMX_DMA_CHANNELS; i++) { 215 + if (!(err_mask & (1 << i))) 216 + continue; 217 + errcode = 0; 218 + 219 + if (imx_dmav1_readl(imxdma, DMA_DBTOSR) & (1 << i)) { 220 + imx_dmav1_writel(imxdma, 1 << i, DMA_DBTOSR); 221 + errcode |= IMX_DMA_ERR_BURST; 222 + } 223 + if (imx_dmav1_readl(imxdma, DMA_DRTOSR) & (1 << i)) { 224 + imx_dmav1_writel(imxdma, 1 << i, DMA_DRTOSR); 225 + errcode |= IMX_DMA_ERR_REQUEST; 226 + } 227 + if (imx_dmav1_readl(imxdma, DMA_DSESR) & (1 << i)) { 228 + imx_dmav1_writel(imxdma, 1 << i, DMA_DSESR); 229 + errcode |= IMX_DMA_ERR_TRANSFER; 230 + } 231 + if (imx_dmav1_readl(imxdma, DMA_DBOSR) & (1 << i)) { 232 + imx_dmav1_writel(imxdma, 1 << i, DMA_DBOSR); 233 + errcode |= IMX_DMA_ERR_BUFFER; 234 + } 235 + /* Tasklet error handler */ 236 + tasklet_schedule(&imxdma->channel[i].dma_tasklet); 237 + 238 + printk(KERN_WARNING 239 + "DMA timeout on channel %d -%s%s%s%s\n", i, 240 + errcode & IMX_DMA_ERR_BURST ? " burst" : "", 241 + errcode & IMX_DMA_ERR_REQUEST ? " request" : "", 242 + errcode & IMX_DMA_ERR_TRANSFER ? " transfer" : "", 243 + errcode & IMX_DMA_ERR_BUFFER ? " buffer" : ""); 244 + } 245 + return IRQ_HANDLED; 246 + } 247 + 248 + static void dma_irq_handle_channel(struct imxdma_channel *imxdmac) 249 + { 250 + struct imxdma_engine *imxdma = imxdmac->imxdma; 251 + int chno = imxdmac->channel; 252 + struct imxdma_desc *desc; 253 + 254 + spin_lock(&imxdma->lock); 255 + if (list_empty(&imxdmac->ld_active)) { 256 + spin_unlock(&imxdma->lock); 257 + goto out; 258 + } 259 + 260 + desc = list_first_entry(&imxdmac->ld_active, 261 + struct imxdma_desc, 262 + node); 263 + spin_unlock(&imxdma->lock); 264 + 265 + if (desc->sg) { 266 + u32 tmp; 267 + desc->sg = sg_next(desc->sg); 268 + 269 + if (desc->sg) { 270 + imxdma_sg_next(desc); 271 + 272 + tmp = imx_dmav1_readl(imxdma, DMA_CCR(chno)); 273 + 274 + if (imxdma_hw_chain(imxdmac)) { 275 + /* FIXME: The timeout should probably be 276 + * configurable 277 + */ 278 + mod_timer(&imxdmac->watchdog, 279 + jiffies + msecs_to_jiffies(500)); 280 + 281 + tmp |= CCR_CEN | CCR_RPT | CCR_ACRPT; 282 + imx_dmav1_writel(imxdma, tmp, DMA_CCR(chno)); 283 + } else { 284 + imx_dmav1_writel(imxdma, tmp & ~CCR_CEN, 285 + DMA_CCR(chno)); 286 + tmp |= CCR_CEN; 287 + } 288 + 289 + imx_dmav1_writel(imxdma, tmp, DMA_CCR(chno)); 290 + 291 + if (imxdma_chan_is_doing_cyclic(imxdmac)) 292 + /* Tasklet progression */ 293 + tasklet_schedule(&imxdmac->dma_tasklet); 294 + 295 + return; 296 + } 297 + 298 + if (imxdma_hw_chain(imxdmac)) { 299 + del_timer(&imxdmac->watchdog); 300 + return; 301 + } 302 + } 303 + 304 + out: 305 + imx_dmav1_writel(imxdma, 0, DMA_CCR(chno)); 306 + /* Tasklet irq */ 307 + tasklet_schedule(&imxdmac->dma_tasklet); 308 + } 309 + 310 + static irqreturn_t dma_irq_handler(int irq, void *dev_id) 311 + { 312 + struct imxdma_engine *imxdma = dev_id; 313 + int i, disr; 314 + 315 + if (cpu_is_mx21() || cpu_is_mx27()) 316 + imxdma_err_handler(irq, dev_id); 317 + 318 + disr = imx_dmav1_readl(imxdma, DMA_DISR); 319 + 320 + dev_dbg(imxdma->dev, "%s called, disr=0x%08x\n", __func__, disr); 321 + 322 + imx_dmav1_writel(imxdma, disr, DMA_DISR); 323 + for (i = 0; i < IMX_DMA_CHANNELS; i++) { 324 + if (disr & (1 << i)) 325 + dma_irq_handle_channel(&imxdma->channel[i]); 326 + } 327 + 328 + return IRQ_HANDLED; 329 + } 330 + 331 + static int imxdma_xfer_desc(struct imxdma_desc *d) 332 + { 333 + struct imxdma_channel *imxdmac = to_imxdma_chan(d->desc.chan); 334 + struct imxdma_engine *imxdma = imxdmac->imxdma; 335 + unsigned long flags; 336 + int slot = -1; 337 + int i; 338 + 339 + /* Configure and enable */ 340 + switch (d->type) { 341 + case IMXDMA_DESC_INTERLEAVED: 342 + /* Try to get a free 2D slot */ 343 + spin_lock_irqsave(&imxdma->lock, flags); 344 + for (i = 0; i < IMX_DMA_2D_SLOTS; i++) { 345 + if ((imxdma->slots_2d[i].count > 0) && 346 + ((imxdma->slots_2d[i].xsr != d->x) || 347 + (imxdma->slots_2d[i].ysr != d->y) || 348 + (imxdma->slots_2d[i].wsr != d->w))) 349 + continue; 350 + slot = i; 351 + break; 352 + } 353 + if (slot < 0) 354 + return -EBUSY; 355 + 356 + imxdma->slots_2d[slot].xsr = d->x; 357 + imxdma->slots_2d[slot].ysr = d->y; 358 + imxdma->slots_2d[slot].wsr = d->w; 359 + imxdma->slots_2d[slot].count++; 360 + 361 + imxdmac->slot_2d = slot; 362 + imxdmac->enabled_2d = true; 363 + spin_unlock_irqrestore(&imxdma->lock, flags); 364 + 365 + if (slot == IMX_DMA_2D_SLOT_A) { 366 + d->config_mem &= ~CCR_MSEL_B; 367 + d->config_port &= ~CCR_MSEL_B; 368 + imx_dmav1_writel(imxdma, d->x, DMA_XSRA); 369 + imx_dmav1_writel(imxdma, d->y, DMA_YSRA); 370 + imx_dmav1_writel(imxdma, d->w, DMA_WSRA); 371 + } else { 372 + d->config_mem |= CCR_MSEL_B; 373 + d->config_port |= CCR_MSEL_B; 374 + imx_dmav1_writel(imxdma, d->x, DMA_XSRB); 375 + imx_dmav1_writel(imxdma, d->y, DMA_YSRB); 376 + imx_dmav1_writel(imxdma, d->w, DMA_WSRB); 377 + } 378 + /* 379 + * We fall-through here intentionally, since a 2D transfer is 380 + * similar to MEMCPY just adding the 2D slot configuration. 381 + */ 382 + case IMXDMA_DESC_MEMCPY: 383 + imx_dmav1_writel(imxdma, d->src, DMA_SAR(imxdmac->channel)); 384 + imx_dmav1_writel(imxdma, d->dest, DMA_DAR(imxdmac->channel)); 385 + imx_dmav1_writel(imxdma, d->config_mem | (d->config_port << 2), 386 + DMA_CCR(imxdmac->channel)); 387 + 388 + imx_dmav1_writel(imxdma, d->len, DMA_CNTR(imxdmac->channel)); 389 + 390 + dev_dbg(imxdma->dev, "%s channel: %d dest=0x%08x src=0x%08x " 391 + "dma_length=%d\n", __func__, imxdmac->channel, 392 + d->dest, d->src, d->len); 393 + 394 + break; 395 + /* Cyclic transfer is the same as slave_sg with special sg configuration. */ 396 + case IMXDMA_DESC_CYCLIC: 397 + case IMXDMA_DESC_SLAVE_SG: 398 + if (d->direction == DMA_DEV_TO_MEM) { 399 + imx_dmav1_writel(imxdma, imxdmac->per_address, 400 + DMA_SAR(imxdmac->channel)); 401 + imx_dmav1_writel(imxdma, imxdmac->ccr_from_device, 402 + DMA_CCR(imxdmac->channel)); 403 + 404 + dev_dbg(imxdma->dev, "%s channel: %d sg=%p sgcount=%d " 405 + "total length=%d dev_addr=0x%08x (dev2mem)\n", 406 + __func__, imxdmac->channel, d->sg, d->sgcount, 407 + d->len, imxdmac->per_address); 408 + } else if (d->direction == DMA_MEM_TO_DEV) { 409 + imx_dmav1_writel(imxdma, imxdmac->per_address, 410 + DMA_DAR(imxdmac->channel)); 411 + imx_dmav1_writel(imxdma, imxdmac->ccr_to_device, 412 + DMA_CCR(imxdmac->channel)); 413 + 414 + dev_dbg(imxdma->dev, "%s channel: %d sg=%p sgcount=%d " 415 + "total length=%d dev_addr=0x%08x (mem2dev)\n", 416 + __func__, imxdmac->channel, d->sg, d->sgcount, 417 + d->len, imxdmac->per_address); 418 + } else { 419 + dev_err(imxdma->dev, "%s channel: %d bad dma mode\n", 420 + __func__, imxdmac->channel); 421 + return -EINVAL; 422 + } 423 + 424 + imxdma_sg_next(d); 425 + 426 + break; 427 + default: 428 + return -EINVAL; 429 + } 430 + imxdma_enable_hw(d); 431 + return 0; 432 + } 433 + 434 + static void imxdma_tasklet(unsigned long data) 435 + { 436 + struct imxdma_channel *imxdmac = (void *)data; 437 + struct imxdma_engine *imxdma = imxdmac->imxdma; 438 + struct imxdma_desc *desc; 439 + 440 + spin_lock(&imxdma->lock); 441 + 442 + if (list_empty(&imxdmac->ld_active)) { 443 + /* Someone might have called terminate all */ 444 + goto out; 445 + } 446 + desc = list_first_entry(&imxdmac->ld_active, struct imxdma_desc, node); 447 + 448 + if (desc->desc.callback) 449 + desc->desc.callback(desc->desc.callback_param); 450 + 451 + dma_cookie_complete(&desc->desc); 452 + 453 + /* If we are dealing with a cyclic descriptor keep it on ld_active */ 454 + if (imxdma_chan_is_doing_cyclic(imxdmac)) 455 + goto out; 456 + 457 + /* Free 2D slot if it was an interleaved transfer */ 458 + if (imxdmac->enabled_2d) { 459 + imxdma->slots_2d[imxdmac->slot_2d].count--; 460 + imxdmac->enabled_2d = false; 461 + } 462 + 463 + list_move_tail(imxdmac->ld_active.next, &imxdmac->ld_free); 464 + 465 + if (!list_empty(&imxdmac->ld_queue)) { 466 + desc = list_first_entry(&imxdmac->ld_queue, struct imxdma_desc, 467 + node); 468 + list_move_tail(imxdmac->ld_queue.next, &imxdmac->ld_active); 469 + if (imxdma_xfer_desc(desc) < 0) 470 + dev_warn(imxdma->dev, "%s: channel: %d couldn't xfer desc\n", 471 + __func__, imxdmac->channel); 472 + } 473 + out: 474 + spin_unlock(&imxdma->lock); 216 475 } 217 476 218 477 static int imxdma_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd, ··· 602 97 { 603 98 struct imxdma_channel *imxdmac = to_imxdma_chan(chan); 604 99 struct dma_slave_config *dmaengine_cfg = (void *)arg; 605 - int ret; 100 + struct imxdma_engine *imxdma = imxdmac->imxdma; 101 + unsigned long flags; 606 102 unsigned int mode = 0; 607 103 608 104 switch (cmd) { 609 105 case DMA_TERMINATE_ALL: 610 - imxdmac->status = DMA_ERROR; 611 - imx_dma_disable(imxdmac->imxdma_channel); 106 + imxdma_disable_hw(imxdmac); 107 + 108 + spin_lock_irqsave(&imxdma->lock, flags); 109 + list_splice_tail_init(&imxdmac->ld_active, &imxdmac->ld_free); 110 + list_splice_tail_init(&imxdmac->ld_queue, &imxdmac->ld_free); 111 + spin_unlock_irqrestore(&imxdma->lock, flags); 612 112 return 0; 613 113 case DMA_SLAVE_CONFIG: 614 114 if (dmaengine_cfg->direction == DMA_DEV_TO_MEM) { ··· 638 128 mode = IMX_DMA_MEMSIZE_32; 639 129 break; 640 130 } 641 - ret = imx_dma_config_channel(imxdmac->imxdma_channel, 642 - mode | IMX_DMA_TYPE_FIFO, 643 - IMX_DMA_MEMSIZE_32 | IMX_DMA_TYPE_LINEAR, 644 - imxdmac->dma_request, 1); 645 131 646 - if (ret) 647 - return ret; 132 + imxdmac->hw_chaining = 1; 133 + if (!imxdma_hw_chain(imxdmac)) 134 + return -EINVAL; 135 + imxdmac->ccr_from_device = (mode | IMX_DMA_TYPE_FIFO) | 136 + ((IMX_DMA_MEMSIZE_32 | IMX_DMA_TYPE_LINEAR) << 2) | 137 + CCR_REN; 138 + imxdmac->ccr_to_device = 139 + (IMX_DMA_MEMSIZE_32 | IMX_DMA_TYPE_LINEAR) | 140 + ((mode | IMX_DMA_TYPE_FIFO) << 2) | CCR_REN; 141 + imx_dmav1_writel(imxdma, imxdmac->dma_request, 142 + DMA_RSSR(imxdmac->channel)); 648 143 649 - imx_dma_config_burstlen(imxdmac->imxdma_channel, 650 - imxdmac->watermark_level * imxdmac->word_size); 144 + /* Set burst length */ 145 + imx_dmav1_writel(imxdma, imxdmac->watermark_level * 146 + imxdmac->word_size, DMA_BLR(imxdmac->channel)); 651 147 652 148 return 0; 653 149 default: ··· 667 151 dma_cookie_t cookie, 668 152 struct dma_tx_state *txstate) 669 153 { 670 - struct imxdma_channel *imxdmac = to_imxdma_chan(chan); 671 - dma_cookie_t last_used; 672 - enum dma_status ret; 673 - 674 - last_used = chan->cookie; 675 - 676 - ret = dma_async_is_complete(cookie, imxdmac->last_completed, last_used); 677 - dma_set_tx_state(txstate, imxdmac->last_completed, last_used, 0); 678 - 679 - return ret; 680 - } 681 - 682 - static dma_cookie_t imxdma_assign_cookie(struct imxdma_channel *imxdma) 683 - { 684 - dma_cookie_t cookie = imxdma->chan.cookie; 685 - 686 - if (++cookie < 0) 687 - cookie = 1; 688 - 689 - imxdma->chan.cookie = cookie; 690 - imxdma->desc.cookie = cookie; 691 - 692 - return cookie; 154 + return dma_cookie_status(chan, cookie, txstate); 693 155 } 694 156 695 157 static dma_cookie_t imxdma_tx_submit(struct dma_async_tx_descriptor *tx) 696 158 { 697 159 struct imxdma_channel *imxdmac = to_imxdma_chan(tx->chan); 160 + struct imxdma_engine *imxdma = imxdmac->imxdma; 698 161 dma_cookie_t cookie; 162 + unsigned long flags; 699 163 700 - spin_lock_irq(&imxdmac->lock); 701 - 702 - cookie = imxdma_assign_cookie(imxdmac); 703 - 704 - imx_dma_enable(imxdmac->imxdma_channel); 705 - 706 - spin_unlock_irq(&imxdmac->lock); 164 + spin_lock_irqsave(&imxdma->lock, flags); 165 + list_move_tail(imxdmac->ld_free.next, &imxdmac->ld_queue); 166 + cookie = dma_cookie_assign(tx); 167 + spin_unlock_irqrestore(&imxdma->lock, flags); 707 168 708 169 return cookie; 709 170 } ··· 690 197 struct imxdma_channel *imxdmac = to_imxdma_chan(chan); 691 198 struct imx_dma_data *data = chan->private; 692 199 693 - imxdmac->dma_request = data->dma_request; 200 + if (data != NULL) 201 + imxdmac->dma_request = data->dma_request; 694 202 695 - dma_async_tx_descriptor_init(&imxdmac->desc, chan); 696 - imxdmac->desc.tx_submit = imxdma_tx_submit; 697 - /* txd.flags will be overwritten in prep funcs */ 698 - imxdmac->desc.flags = DMA_CTRL_ACK; 203 + while (imxdmac->descs_allocated < IMXDMA_MAX_CHAN_DESCRIPTORS) { 204 + struct imxdma_desc *desc; 699 205 700 - imxdmac->status = DMA_SUCCESS; 206 + desc = kzalloc(sizeof(*desc), GFP_KERNEL); 207 + if (!desc) 208 + break; 209 + __memzero(&desc->desc, sizeof(struct dma_async_tx_descriptor)); 210 + dma_async_tx_descriptor_init(&desc->desc, chan); 211 + desc->desc.tx_submit = imxdma_tx_submit; 212 + /* txd.flags will be overwritten in prep funcs */ 213 + desc->desc.flags = DMA_CTRL_ACK; 214 + desc->status = DMA_SUCCESS; 701 215 702 - return 0; 216 + list_add_tail(&desc->node, &imxdmac->ld_free); 217 + imxdmac->descs_allocated++; 218 + } 219 + 220 + if (!imxdmac->descs_allocated) 221 + return -ENOMEM; 222 + 223 + return imxdmac->descs_allocated; 703 224 } 704 225 705 226 static void imxdma_free_chan_resources(struct dma_chan *chan) 706 227 { 707 228 struct imxdma_channel *imxdmac = to_imxdma_chan(chan); 229 + struct imxdma_engine *imxdma = imxdmac->imxdma; 230 + struct imxdma_desc *desc, *_desc; 231 + unsigned long flags; 708 232 709 - imx_dma_disable(imxdmac->imxdma_channel); 233 + spin_lock_irqsave(&imxdma->lock, flags); 234 + 235 + imxdma_disable_hw(imxdmac); 236 + list_splice_tail_init(&imxdmac->ld_active, &imxdmac->ld_free); 237 + list_splice_tail_init(&imxdmac->ld_queue, &imxdmac->ld_free); 238 + 239 + spin_unlock_irqrestore(&imxdma->lock, flags); 240 + 241 + list_for_each_entry_safe(desc, _desc, &imxdmac->ld_free, node) { 242 + kfree(desc); 243 + imxdmac->descs_allocated--; 244 + } 245 + INIT_LIST_HEAD(&imxdmac->ld_free); 710 246 711 247 if (imxdmac->sg_list) { 712 248 kfree(imxdmac->sg_list); ··· 746 224 static struct dma_async_tx_descriptor *imxdma_prep_slave_sg( 747 225 struct dma_chan *chan, struct scatterlist *sgl, 748 226 unsigned int sg_len, enum dma_transfer_direction direction, 749 - unsigned long flags) 227 + unsigned long flags, void *context) 750 228 { 751 229 struct imxdma_channel *imxdmac = to_imxdma_chan(chan); 752 230 struct scatterlist *sg; 753 - int i, ret, dma_length = 0; 754 - unsigned int dmamode; 231 + int i, dma_length = 0; 232 + struct imxdma_desc *desc; 755 233 756 - if (imxdmac->status == DMA_IN_PROGRESS) 234 + if (list_empty(&imxdmac->ld_free) || 235 + imxdma_chan_is_doing_cyclic(imxdmac)) 757 236 return NULL; 758 237 759 - imxdmac->status = DMA_IN_PROGRESS; 238 + desc = list_first_entry(&imxdmac->ld_free, struct imxdma_desc, node); 760 239 761 240 for_each_sg(sgl, sg, sg_len, i) { 762 241 dma_length += sg->length; 763 242 } 764 - 765 - if (direction == DMA_DEV_TO_MEM) 766 - dmamode = DMA_MODE_READ; 767 - else 768 - dmamode = DMA_MODE_WRITE; 769 243 770 244 switch (imxdmac->word_size) { 771 245 case DMA_SLAVE_BUSWIDTH_4_BYTES: ··· 778 260 return NULL; 779 261 } 780 262 781 - ret = imx_dma_setup_sg(imxdmac->imxdma_channel, sgl, sg_len, 782 - dma_length, imxdmac->per_address, dmamode); 783 - if (ret) 784 - return NULL; 263 + desc->type = IMXDMA_DESC_SLAVE_SG; 264 + desc->sg = sgl; 265 + desc->sgcount = sg_len; 266 + desc->len = dma_length; 267 + desc->direction = direction; 268 + if (direction == DMA_DEV_TO_MEM) { 269 + desc->src = imxdmac->per_address; 270 + } else { 271 + desc->dest = imxdmac->per_address; 272 + } 273 + desc->desc.callback = NULL; 274 + desc->desc.callback_param = NULL; 785 275 786 - return &imxdmac->desc; 276 + return &desc->desc; 787 277 } 788 278 789 279 static struct dma_async_tx_descriptor *imxdma_prep_dma_cyclic( 790 280 struct dma_chan *chan, dma_addr_t dma_addr, size_t buf_len, 791 - size_t period_len, enum dma_transfer_direction direction) 281 + size_t period_len, enum dma_transfer_direction direction, 282 + void *context) 792 283 { 793 284 struct imxdma_channel *imxdmac = to_imxdma_chan(chan); 794 285 struct imxdma_engine *imxdma = imxdmac->imxdma; 795 - int i, ret; 286 + struct imxdma_desc *desc; 287 + int i; 796 288 unsigned int periods = buf_len / period_len; 797 - unsigned int dmamode; 798 289 799 290 dev_dbg(imxdma->dev, "%s channel: %d buf_len=%d period_len=%d\n", 800 291 __func__, imxdmac->channel, buf_len, period_len); 801 292 802 - if (imxdmac->status == DMA_IN_PROGRESS) 293 + if (list_empty(&imxdmac->ld_free) || 294 + imxdma_chan_is_doing_cyclic(imxdmac)) 803 295 return NULL; 804 - imxdmac->status = DMA_IN_PROGRESS; 805 296 806 - ret = imx_dma_setup_progression_handler(imxdmac->imxdma_channel, 807 - imxdma_progression); 808 - if (ret) { 809 - dev_err(imxdma->dev, "Failed to setup the DMA handler\n"); 810 - return NULL; 811 - } 297 + desc = list_first_entry(&imxdmac->ld_free, struct imxdma_desc, node); 812 298 813 299 if (imxdmac->sg_list) 814 300 kfree(imxdmac->sg_list); ··· 838 316 imxdmac->sg_list[periods].page_link = 839 317 ((unsigned long)imxdmac->sg_list | 0x01) & ~0x02; 840 318 841 - if (direction == DMA_DEV_TO_MEM) 842 - dmamode = DMA_MODE_READ; 843 - else 844 - dmamode = DMA_MODE_WRITE; 319 + desc->type = IMXDMA_DESC_CYCLIC; 320 + desc->sg = imxdmac->sg_list; 321 + desc->sgcount = periods; 322 + desc->len = IMX_DMA_LENGTH_LOOP; 323 + desc->direction = direction; 324 + if (direction == DMA_DEV_TO_MEM) { 325 + desc->src = imxdmac->per_address; 326 + } else { 327 + desc->dest = imxdmac->per_address; 328 + } 329 + desc->desc.callback = NULL; 330 + desc->desc.callback_param = NULL; 845 331 846 - ret = imx_dma_setup_sg(imxdmac->imxdma_channel, imxdmac->sg_list, periods, 847 - IMX_DMA_LENGTH_LOOP, imxdmac->per_address, dmamode); 848 - if (ret) 332 + return &desc->desc; 333 + } 334 + 335 + static struct dma_async_tx_descriptor *imxdma_prep_dma_memcpy( 336 + struct dma_chan *chan, dma_addr_t dest, 337 + dma_addr_t src, size_t len, unsigned long flags) 338 + { 339 + struct imxdma_channel *imxdmac = to_imxdma_chan(chan); 340 + struct imxdma_engine *imxdma = imxdmac->imxdma; 341 + struct imxdma_desc *desc; 342 + 343 + dev_dbg(imxdma->dev, "%s channel: %d src=0x%x dst=0x%x len=%d\n", 344 + __func__, imxdmac->channel, src, dest, len); 345 + 346 + if (list_empty(&imxdmac->ld_free) || 347 + imxdma_chan_is_doing_cyclic(imxdmac)) 849 348 return NULL; 850 349 851 - return &imxdmac->desc; 350 + desc = list_first_entry(&imxdmac->ld_free, struct imxdma_desc, node); 351 + 352 + desc->type = IMXDMA_DESC_MEMCPY; 353 + desc->src = src; 354 + desc->dest = dest; 355 + desc->len = len; 356 + desc->direction = DMA_MEM_TO_MEM; 357 + desc->config_port = IMX_DMA_MEMSIZE_32 | IMX_DMA_TYPE_LINEAR; 358 + desc->config_mem = IMX_DMA_MEMSIZE_32 | IMX_DMA_TYPE_LINEAR; 359 + desc->desc.callback = NULL; 360 + desc->desc.callback_param = NULL; 361 + 362 + return &desc->desc; 363 + } 364 + 365 + static struct dma_async_tx_descriptor *imxdma_prep_dma_interleaved( 366 + struct dma_chan *chan, struct dma_interleaved_template *xt, 367 + unsigned long flags) 368 + { 369 + struct imxdma_channel *imxdmac = to_imxdma_chan(chan); 370 + struct imxdma_engine *imxdma = imxdmac->imxdma; 371 + struct imxdma_desc *desc; 372 + 373 + dev_dbg(imxdma->dev, "%s channel: %d src_start=0x%x dst_start=0x%x\n" 374 + " src_sgl=%s dst_sgl=%s numf=%d frame_size=%d\n", __func__, 375 + imxdmac->channel, xt->src_start, xt->dst_start, 376 + xt->src_sgl ? "true" : "false", xt->dst_sgl ? "true" : "false", 377 + xt->numf, xt->frame_size); 378 + 379 + if (list_empty(&imxdmac->ld_free) || 380 + imxdma_chan_is_doing_cyclic(imxdmac)) 381 + return NULL; 382 + 383 + if (xt->frame_size != 1 || xt->numf <= 0 || xt->dir != DMA_MEM_TO_MEM) 384 + return NULL; 385 + 386 + desc = list_first_entry(&imxdmac->ld_free, struct imxdma_desc, node); 387 + 388 + desc->type = IMXDMA_DESC_INTERLEAVED; 389 + desc->src = xt->src_start; 390 + desc->dest = xt->dst_start; 391 + desc->x = xt->sgl[0].size; 392 + desc->y = xt->numf; 393 + desc->w = xt->sgl[0].icg + desc->x; 394 + desc->len = desc->x * desc->y; 395 + desc->direction = DMA_MEM_TO_MEM; 396 + desc->config_port = IMX_DMA_MEMSIZE_32; 397 + desc->config_mem = IMX_DMA_MEMSIZE_32; 398 + if (xt->src_sgl) 399 + desc->config_mem |= IMX_DMA_TYPE_2D; 400 + if (xt->dst_sgl) 401 + desc->config_port |= IMX_DMA_TYPE_2D; 402 + desc->desc.callback = NULL; 403 + desc->desc.callback_param = NULL; 404 + 405 + return &desc->desc; 852 406 } 853 407 854 408 static void imxdma_issue_pending(struct dma_chan *chan) 855 409 { 856 - /* 857 - * Nothing to do. We only have a single descriptor 858 - */ 410 + struct imxdma_channel *imxdmac = to_imxdma_chan(chan); 411 + struct imxdma_engine *imxdma = imxdmac->imxdma; 412 + struct imxdma_desc *desc; 413 + unsigned long flags; 414 + 415 + spin_lock_irqsave(&imxdma->lock, flags); 416 + if (list_empty(&imxdmac->ld_active) && 417 + !list_empty(&imxdmac->ld_queue)) { 418 + desc = list_first_entry(&imxdmac->ld_queue, 419 + struct imxdma_desc, node); 420 + 421 + if (imxdma_xfer_desc(desc) < 0) { 422 + dev_warn(imxdma->dev, 423 + "%s: channel: %d couldn't issue DMA xfer\n", 424 + __func__, imxdmac->channel); 425 + } else { 426 + list_move_tail(imxdmac->ld_queue.next, 427 + &imxdmac->ld_active); 428 + } 429 + } 430 + spin_unlock_irqrestore(&imxdma->lock, flags); 859 431 } 860 432 861 433 static int __init imxdma_probe(struct platform_device *pdev) 862 - { 434 + { 863 435 struct imxdma_engine *imxdma; 864 436 int ret, i; 437 + 865 438 866 439 imxdma = kzalloc(sizeof(*imxdma), GFP_KERNEL); 867 440 if (!imxdma) 868 441 return -ENOMEM; 869 442 443 + if (cpu_is_mx1()) { 444 + imxdma->base = MX1_IO_ADDRESS(MX1_DMA_BASE_ADDR); 445 + } else if (cpu_is_mx21()) { 446 + imxdma->base = MX21_IO_ADDRESS(MX21_DMA_BASE_ADDR); 447 + } else if (cpu_is_mx27()) { 448 + imxdma->base = MX27_IO_ADDRESS(MX27_DMA_BASE_ADDR); 449 + } else { 450 + kfree(imxdma); 451 + return 0; 452 + } 453 + 454 + imxdma->dma_clk = clk_get(NULL, "dma"); 455 + if (IS_ERR(imxdma->dma_clk)) 456 + return PTR_ERR(imxdma->dma_clk); 457 + clk_enable(imxdma->dma_clk); 458 + 459 + /* reset DMA module */ 460 + imx_dmav1_writel(imxdma, DCR_DRST, DMA_DCR); 461 + 462 + if (cpu_is_mx1()) { 463 + ret = request_irq(MX1_DMA_INT, dma_irq_handler, 0, "DMA", imxdma); 464 + if (ret) { 465 + dev_warn(imxdma->dev, "Can't register IRQ for DMA\n"); 466 + kfree(imxdma); 467 + return ret; 468 + } 469 + 470 + ret = request_irq(MX1_DMA_ERR, imxdma_err_handler, 0, "DMA", imxdma); 471 + if (ret) { 472 + dev_warn(imxdma->dev, "Can't register ERRIRQ for DMA\n"); 473 + free_irq(MX1_DMA_INT, NULL); 474 + kfree(imxdma); 475 + return ret; 476 + } 477 + } 478 + 479 + /* enable DMA module */ 480 + imx_dmav1_writel(imxdma, DCR_DEN, DMA_DCR); 481 + 482 + /* clear all interrupts */ 483 + imx_dmav1_writel(imxdma, (1 << IMX_DMA_CHANNELS) - 1, DMA_DISR); 484 + 485 + /* disable interrupts */ 486 + imx_dmav1_writel(imxdma, (1 << IMX_DMA_CHANNELS) - 1, DMA_DIMR); 487 + 870 488 INIT_LIST_HEAD(&imxdma->dma_device.channels); 871 489 872 490 dma_cap_set(DMA_SLAVE, imxdma->dma_device.cap_mask); 873 491 dma_cap_set(DMA_CYCLIC, imxdma->dma_device.cap_mask); 492 + dma_cap_set(DMA_MEMCPY, imxdma->dma_device.cap_mask); 493 + dma_cap_set(DMA_INTERLEAVE, imxdma->dma_device.cap_mask); 494 + 495 + /* Initialize 2D global parameters */ 496 + for (i = 0; i < IMX_DMA_2D_SLOTS; i++) 497 + imxdma->slots_2d[i].count = 0; 498 + 499 + spin_lock_init(&imxdma->lock); 874 500 875 501 /* Initialize channel parameters */ 876 - for (i = 0; i < MAX_DMA_CHANNELS; i++) { 502 + for (i = 0; i < IMX_DMA_CHANNELS; i++) { 877 503 struct imxdma_channel *imxdmac = &imxdma->channel[i]; 878 504 879 - imxdmac->imxdma_channel = imx_dma_request_by_prio("dmaengine", 880 - DMA_PRIO_MEDIUM); 881 - if ((int)imxdmac->channel < 0) { 882 - ret = -ENODEV; 883 - goto err_init; 505 + if (cpu_is_mx21() || cpu_is_mx27()) { 506 + ret = request_irq(MX2x_INT_DMACH0 + i, 507 + dma_irq_handler, 0, "DMA", imxdma); 508 + if (ret) { 509 + dev_warn(imxdma->dev, "Can't register IRQ %d " 510 + "for DMA channel %d\n", 511 + MX2x_INT_DMACH0 + i, i); 512 + goto err_init; 513 + } 514 + init_timer(&imxdmac->watchdog); 515 + imxdmac->watchdog.function = &imxdma_watchdog; 516 + imxdmac->watchdog.data = (unsigned long)imxdmac; 884 517 } 885 518 886 - imx_dma_setup_handlers(imxdmac->imxdma_channel, 887 - imxdma_irq_handler, imxdma_err_handler, imxdmac); 888 - 889 519 imxdmac->imxdma = imxdma; 890 - spin_lock_init(&imxdmac->lock); 891 520 521 + INIT_LIST_HEAD(&imxdmac->ld_queue); 522 + INIT_LIST_HEAD(&imxdmac->ld_free); 523 + INIT_LIST_HEAD(&imxdmac->ld_active); 524 + 525 + tasklet_init(&imxdmac->dma_tasklet, imxdma_tasklet, 526 + (unsigned long)imxdmac); 892 527 imxdmac->chan.device = &imxdma->dma_device; 528 + dma_cookie_init(&imxdmac->chan); 893 529 imxdmac->channel = i; 894 530 895 531 /* Add the channel to the DMAC list */ 896 - list_add_tail(&imxdmac->chan.device_node, &imxdma->dma_device.channels); 532 + list_add_tail(&imxdmac->chan.device_node, 533 + &imxdma->dma_device.channels); 897 534 } 898 535 899 536 imxdma->dev = &pdev->dev; ··· 1063 382 imxdma->dma_device.device_tx_status = imxdma_tx_status; 1064 383 imxdma->dma_device.device_prep_slave_sg = imxdma_prep_slave_sg; 1065 384 imxdma->dma_device.device_prep_dma_cyclic = imxdma_prep_dma_cyclic; 385 + imxdma->dma_device.device_prep_dma_memcpy = imxdma_prep_dma_memcpy; 386 + imxdma->dma_device.device_prep_interleaved_dma = imxdma_prep_dma_interleaved; 1066 387 imxdma->dma_device.device_control = imxdma_control; 1067 388 imxdma->dma_device.device_issue_pending = imxdma_issue_pending; 1068 389 1069 390 platform_set_drvdata(pdev, imxdma); 1070 391 392 + imxdma->dma_device.copy_align = 2; /* 2^2 = 4 bytes alignment */ 1071 393 imxdma->dma_device.dev->dma_parms = &imxdma->dma_parms; 1072 394 dma_set_max_seg_size(imxdma->dma_device.dev, 0xffffff); 1073 395 ··· 1083 399 return 0; 1084 400 1085 401 err_init: 1086 - while (--i >= 0) { 1087 - struct imxdma_channel *imxdmac = &imxdma->channel[i]; 1088 - imx_dma_free(imxdmac->imxdma_channel); 402 + 403 + if (cpu_is_mx21() || cpu_is_mx27()) { 404 + while (--i >= 0) 405 + free_irq(MX2x_INT_DMACH0 + i, NULL); 406 + } else if cpu_is_mx1() { 407 + free_irq(MX1_DMA_INT, NULL); 408 + free_irq(MX1_DMA_ERR, NULL); 1089 409 } 1090 410 1091 411 kfree(imxdma); ··· 1103 415 1104 416 dma_async_device_unregister(&imxdma->dma_device); 1105 417 1106 - for (i = 0; i < MAX_DMA_CHANNELS; i++) { 1107 - struct imxdma_channel *imxdmac = &imxdma->channel[i]; 1108 - 1109 - imx_dma_free(imxdmac->imxdma_channel); 418 + if (cpu_is_mx21() || cpu_is_mx27()) { 419 + for (i = 0; i < IMX_DMA_CHANNELS; i++) 420 + free_irq(MX2x_INT_DMACH0 + i, NULL); 421 + } else if cpu_is_mx1() { 422 + free_irq(MX1_DMA_INT, NULL); 423 + free_irq(MX1_DMA_ERR, NULL); 1110 424 } 1111 425 1112 426 kfree(imxdma);
+88 -99
drivers/dma/imx-sdma.c
··· 20 20 #include <linux/init.h> 21 21 #include <linux/module.h> 22 22 #include <linux/types.h> 23 + #include <linux/bitops.h> 23 24 #include <linux/mm.h> 24 25 #include <linux/interrupt.h> 25 26 #include <linux/clk.h> ··· 41 40 #include <mach/sdma.h> 42 41 #include <mach/dma.h> 43 42 #include <mach/hardware.h> 43 + 44 + #include "dmaengine.h" 44 45 45 46 /* SDMA registers */ 46 47 #define SDMA_H_C0PTR 0x000 ··· 262 259 unsigned int pc_from_device, pc_to_device; 263 260 unsigned long flags; 264 261 dma_addr_t per_address; 265 - u32 event_mask0, event_mask1; 266 - u32 watermark_level; 262 + unsigned long event_mask[2]; 263 + unsigned long watermark_level; 267 264 u32 shp_addr, per_addr; 268 265 struct dma_chan chan; 269 266 spinlock_t lock; 270 267 struct dma_async_tx_descriptor desc; 271 - dma_cookie_t last_completed; 272 268 enum dma_status status; 273 269 unsigned int chn_count; 274 270 unsigned int chn_real_count; 275 271 }; 276 272 277 - #define IMX_DMA_SG_LOOP (1 << 0) 273 + #define IMX_DMA_SG_LOOP BIT(0) 278 274 279 275 #define MAX_DMA_CHANNELS 32 280 276 #define MXC_SDMA_DEFAULT_PRIORITY 1 ··· 347 345 }; 348 346 MODULE_DEVICE_TABLE(of, sdma_dt_ids); 349 347 350 - #define SDMA_H_CONFIG_DSPDMA (1 << 12) /* indicates if the DSPDMA is used */ 351 - #define SDMA_H_CONFIG_RTD_PINS (1 << 11) /* indicates if Real-Time Debug pins are enabled */ 352 - #define SDMA_H_CONFIG_ACR (1 << 4) /* indicates if AHB freq /core freq = 2 or 1 */ 348 + #define SDMA_H_CONFIG_DSPDMA BIT(12) /* indicates if the DSPDMA is used */ 349 + #define SDMA_H_CONFIG_RTD_PINS BIT(11) /* indicates if Real-Time Debug pins are enabled */ 350 + #define SDMA_H_CONFIG_ACR BIT(4) /* indicates if AHB freq /core freq = 2 or 1 */ 353 351 #define SDMA_H_CONFIG_CSM (3) /* indicates which context switch mode is selected*/ 354 352 355 353 static inline u32 chnenbl_ofs(struct sdma_engine *sdma, unsigned int event) ··· 364 362 { 365 363 struct sdma_engine *sdma = sdmac->sdma; 366 364 int channel = sdmac->channel; 367 - u32 evt, mcu, dsp; 365 + unsigned long evt, mcu, dsp; 368 366 369 367 if (event_override && mcu_override && dsp_override) 370 368 return -EINVAL; 371 369 372 - evt = __raw_readl(sdma->regs + SDMA_H_EVTOVR); 373 - mcu = __raw_readl(sdma->regs + SDMA_H_HOSTOVR); 374 - dsp = __raw_readl(sdma->regs + SDMA_H_DSPOVR); 370 + evt = readl_relaxed(sdma->regs + SDMA_H_EVTOVR); 371 + mcu = readl_relaxed(sdma->regs + SDMA_H_HOSTOVR); 372 + dsp = readl_relaxed(sdma->regs + SDMA_H_DSPOVR); 375 373 376 374 if (dsp_override) 377 - dsp &= ~(1 << channel); 375 + __clear_bit(channel, &dsp); 378 376 else 379 - dsp |= (1 << channel); 377 + __set_bit(channel, &dsp); 380 378 381 379 if (event_override) 382 - evt &= ~(1 << channel); 380 + __clear_bit(channel, &evt); 383 381 else 384 - evt |= (1 << channel); 382 + __set_bit(channel, &evt); 385 383 386 384 if (mcu_override) 387 - mcu &= ~(1 << channel); 385 + __clear_bit(channel, &mcu); 388 386 else 389 - mcu |= (1 << channel); 387 + __set_bit(channel, &mcu); 390 388 391 - __raw_writel(evt, sdma->regs + SDMA_H_EVTOVR); 392 - __raw_writel(mcu, sdma->regs + SDMA_H_HOSTOVR); 393 - __raw_writel(dsp, sdma->regs + SDMA_H_DSPOVR); 389 + writel_relaxed(evt, sdma->regs + SDMA_H_EVTOVR); 390 + writel_relaxed(mcu, sdma->regs + SDMA_H_HOSTOVR); 391 + writel_relaxed(dsp, sdma->regs + SDMA_H_DSPOVR); 394 392 395 393 return 0; 394 + } 395 + 396 + static void sdma_enable_channel(struct sdma_engine *sdma, int channel) 397 + { 398 + writel(BIT(channel), sdma->regs + SDMA_H_START); 396 399 } 397 400 398 401 /* ··· 411 404 412 405 init_completion(&sdmac->done); 413 406 414 - __raw_writel(1 << channel, sdma->regs + SDMA_H_START); 407 + sdma_enable_channel(sdma, channel); 415 408 416 409 ret = wait_for_completion_timeout(&sdmac->done, HZ); 417 410 ··· 458 451 { 459 452 struct sdma_engine *sdma = sdmac->sdma; 460 453 int channel = sdmac->channel; 461 - u32 val; 454 + unsigned long val; 462 455 u32 chnenbl = chnenbl_ofs(sdma, event); 463 456 464 - val = __raw_readl(sdma->regs + chnenbl); 465 - val |= (1 << channel); 466 - __raw_writel(val, sdma->regs + chnenbl); 457 + val = readl_relaxed(sdma->regs + chnenbl); 458 + __set_bit(channel, &val); 459 + writel_relaxed(val, sdma->regs + chnenbl); 467 460 } 468 461 469 462 static void sdma_event_disable(struct sdma_channel *sdmac, unsigned int event) ··· 471 464 struct sdma_engine *sdma = sdmac->sdma; 472 465 int channel = sdmac->channel; 473 466 u32 chnenbl = chnenbl_ofs(sdma, event); 474 - u32 val; 467 + unsigned long val; 475 468 476 - val = __raw_readl(sdma->regs + chnenbl); 477 - val &= ~(1 << channel); 478 - __raw_writel(val, sdma->regs + chnenbl); 469 + val = readl_relaxed(sdma->regs + chnenbl); 470 + __clear_bit(channel, &val); 471 + writel_relaxed(val, sdma->regs + chnenbl); 479 472 } 480 473 481 474 static void sdma_handle_channel_loop(struct sdma_channel *sdmac) ··· 529 522 else 530 523 sdmac->status = DMA_SUCCESS; 531 524 532 - sdmac->last_completed = sdmac->desc.cookie; 525 + dma_cookie_complete(&sdmac->desc); 533 526 if (sdmac->desc.callback) 534 527 sdmac->desc.callback(sdmac->desc.callback_param); 535 528 } ··· 551 544 static irqreturn_t sdma_int_handler(int irq, void *dev_id) 552 545 { 553 546 struct sdma_engine *sdma = dev_id; 554 - u32 stat; 547 + unsigned long stat; 555 548 556 - stat = __raw_readl(sdma->regs + SDMA_H_INTR); 557 - __raw_writel(stat, sdma->regs + SDMA_H_INTR); 549 + stat = readl_relaxed(sdma->regs + SDMA_H_INTR); 550 + writel_relaxed(stat, sdma->regs + SDMA_H_INTR); 558 551 559 552 while (stat) { 560 553 int channel = fls(stat) - 1; ··· 562 555 563 556 mxc_sdma_handle_channel(sdmac); 564 557 565 - stat &= ~(1 << channel); 558 + __clear_bit(channel, &stat); 566 559 } 567 560 568 561 return IRQ_HANDLED; ··· 670 663 return load_address; 671 664 672 665 dev_dbg(sdma->dev, "load_address = %d\n", load_address); 673 - dev_dbg(sdma->dev, "wml = 0x%08x\n", sdmac->watermark_level); 666 + dev_dbg(sdma->dev, "wml = 0x%08x\n", (u32)sdmac->watermark_level); 674 667 dev_dbg(sdma->dev, "shp_addr = 0x%08x\n", sdmac->shp_addr); 675 668 dev_dbg(sdma->dev, "per_addr = 0x%08x\n", sdmac->per_addr); 676 - dev_dbg(sdma->dev, "event_mask0 = 0x%08x\n", sdmac->event_mask0); 677 - dev_dbg(sdma->dev, "event_mask1 = 0x%08x\n", sdmac->event_mask1); 669 + dev_dbg(sdma->dev, "event_mask0 = 0x%08x\n", (u32)sdmac->event_mask[0]); 670 + dev_dbg(sdma->dev, "event_mask1 = 0x%08x\n", (u32)sdmac->event_mask[1]); 678 671 679 672 mutex_lock(&sdma->channel_0_lock); 680 673 ··· 684 677 /* Send by context the event mask,base address for peripheral 685 678 * and watermark level 686 679 */ 687 - context->gReg[0] = sdmac->event_mask1; 688 - context->gReg[1] = sdmac->event_mask0; 680 + context->gReg[0] = sdmac->event_mask[1]; 681 + context->gReg[1] = sdmac->event_mask[0]; 689 682 context->gReg[2] = sdmac->per_addr; 690 683 context->gReg[6] = sdmac->shp_addr; 691 684 context->gReg[7] = sdmac->watermark_level; ··· 708 701 struct sdma_engine *sdma = sdmac->sdma; 709 702 int channel = sdmac->channel; 710 703 711 - __raw_writel(1 << channel, sdma->regs + SDMA_H_STATSTOP); 704 + writel_relaxed(BIT(channel), sdma->regs + SDMA_H_STATSTOP); 712 705 sdmac->status = DMA_ERROR; 713 706 } 714 707 ··· 718 711 719 712 sdma_disable_channel(sdmac); 720 713 721 - sdmac->event_mask0 = 0; 722 - sdmac->event_mask1 = 0; 714 + sdmac->event_mask[0] = 0; 715 + sdmac->event_mask[1] = 0; 723 716 sdmac->shp_addr = 0; 724 717 sdmac->per_addr = 0; 725 718 726 719 if (sdmac->event_id0) { 727 - if (sdmac->event_id0 > 32) 720 + if (sdmac->event_id0 >= sdmac->sdma->num_events) 728 721 return -EINVAL; 729 722 sdma_event_enable(sdmac, sdmac->event_id0); 730 723 } ··· 747 740 (sdmac->peripheral_type != IMX_DMATYPE_DSP)) { 748 741 /* Handle multiple event channels differently */ 749 742 if (sdmac->event_id1) { 750 - sdmac->event_mask1 = 1 << (sdmac->event_id1 % 32); 743 + sdmac->event_mask[1] = BIT(sdmac->event_id1 % 32); 751 744 if (sdmac->event_id1 > 31) 752 - sdmac->watermark_level |= 1 << 31; 753 - sdmac->event_mask0 = 1 << (sdmac->event_id0 % 32); 745 + __set_bit(31, &sdmac->watermark_level); 746 + sdmac->event_mask[0] = BIT(sdmac->event_id0 % 32); 754 747 if (sdmac->event_id0 > 31) 755 - sdmac->watermark_level |= 1 << 30; 748 + __set_bit(30, &sdmac->watermark_level); 756 749 } else { 757 - sdmac->event_mask0 = 1 << sdmac->event_id0; 758 - sdmac->event_mask1 = 1 << (sdmac->event_id0 - 32); 750 + __set_bit(sdmac->event_id0, sdmac->event_mask); 759 751 } 760 752 /* Watermark Level */ 761 753 sdmac->watermark_level |= sdmac->watermark_level; ··· 780 774 return -EINVAL; 781 775 } 782 776 783 - __raw_writel(priority, sdma->regs + SDMA_CHNPRI_0 + 4 * channel); 777 + writel_relaxed(priority, sdma->regs + SDMA_CHNPRI_0 + 4 * channel); 784 778 785 779 return 0; 786 780 } ··· 802 796 sdma->channel_control[channel].base_bd_ptr = sdmac->bd_phys; 803 797 sdma->channel_control[channel].current_bd_ptr = sdmac->bd_phys; 804 798 805 - clk_enable(sdma->clk); 806 - 807 799 sdma_set_channel_priority(sdmac, MXC_SDMA_DEFAULT_PRIORITY); 808 800 809 801 init_completion(&sdmac->done); ··· 814 810 return ret; 815 811 } 816 812 817 - static void sdma_enable_channel(struct sdma_engine *sdma, int channel) 818 - { 819 - __raw_writel(1 << channel, sdma->regs + SDMA_H_START); 820 - } 821 - 822 - static dma_cookie_t sdma_assign_cookie(struct sdma_channel *sdmac) 823 - { 824 - dma_cookie_t cookie = sdmac->chan.cookie; 825 - 826 - if (++cookie < 0) 827 - cookie = 1; 828 - 829 - sdmac->chan.cookie = cookie; 830 - sdmac->desc.cookie = cookie; 831 - 832 - return cookie; 833 - } 834 - 835 813 static struct sdma_channel *to_sdma_chan(struct dma_chan *chan) 836 814 { 837 815 return container_of(chan, struct sdma_channel, chan); ··· 823 837 { 824 838 unsigned long flags; 825 839 struct sdma_channel *sdmac = to_sdma_chan(tx->chan); 826 - struct sdma_engine *sdma = sdmac->sdma; 827 840 dma_cookie_t cookie; 828 841 829 842 spin_lock_irqsave(&sdmac->lock, flags); 830 843 831 - cookie = sdma_assign_cookie(sdmac); 832 - 833 - sdma_enable_channel(sdma, sdmac->channel); 844 + cookie = dma_cookie_assign(tx); 834 845 835 846 spin_unlock_irqrestore(&sdmac->lock, flags); 836 847 ··· 858 875 859 876 sdmac->peripheral_type = data->peripheral_type; 860 877 sdmac->event_id0 = data->dma_request; 861 - ret = sdma_set_channel_priority(sdmac, prio); 878 + 879 + clk_enable(sdmac->sdma->clk); 880 + 881 + ret = sdma_request_channel(sdmac); 862 882 if (ret) 863 883 return ret; 864 884 865 - ret = sdma_request_channel(sdmac); 885 + ret = sdma_set_channel_priority(sdmac, prio); 866 886 if (ret) 867 887 return ret; 868 888 ··· 902 916 static struct dma_async_tx_descriptor *sdma_prep_slave_sg( 903 917 struct dma_chan *chan, struct scatterlist *sgl, 904 918 unsigned int sg_len, enum dma_transfer_direction direction, 905 - unsigned long flags) 919 + unsigned long flags, void *context) 906 920 { 907 921 struct sdma_channel *sdmac = to_sdma_chan(chan); 908 922 struct sdma_engine *sdma = sdmac->sdma; ··· 1000 1014 1001 1015 static struct dma_async_tx_descriptor *sdma_prep_dma_cyclic( 1002 1016 struct dma_chan *chan, dma_addr_t dma_addr, size_t buf_len, 1003 - size_t period_len, enum dma_transfer_direction direction) 1017 + size_t period_len, enum dma_transfer_direction direction, 1018 + void *context) 1004 1019 { 1005 1020 struct sdma_channel *sdmac = to_sdma_chan(chan); 1006 1021 struct sdma_engine *sdma = sdmac->sdma; ··· 1115 1128 1116 1129 last_used = chan->cookie; 1117 1130 1118 - dma_set_tx_state(txstate, sdmac->last_completed, last_used, 1131 + dma_set_tx_state(txstate, chan->completed_cookie, last_used, 1119 1132 sdmac->chn_count - sdmac->chn_real_count); 1120 1133 1121 1134 return sdmac->status; ··· 1123 1136 1124 1137 static void sdma_issue_pending(struct dma_chan *chan) 1125 1138 { 1126 - /* 1127 - * Nothing to do. We only have a single descriptor 1128 - */ 1139 + struct sdma_channel *sdmac = to_sdma_chan(chan); 1140 + struct sdma_engine *sdma = sdmac->sdma; 1141 + 1142 + if (sdmac->status == DMA_IN_PROGRESS) 1143 + sdma_enable_channel(sdma, sdmac->channel); 1129 1144 } 1130 1145 1131 1146 #define SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V1 34 ··· 1219 1230 clk_enable(sdma->clk); 1220 1231 1221 1232 /* Be sure SDMA has not started yet */ 1222 - __raw_writel(0, sdma->regs + SDMA_H_C0PTR); 1233 + writel_relaxed(0, sdma->regs + SDMA_H_C0PTR); 1223 1234 1224 1235 sdma->channel_control = dma_alloc_coherent(NULL, 1225 1236 MAX_DMA_CHANNELS * sizeof (struct sdma_channel_control) + ··· 1242 1253 1243 1254 /* disable all channels */ 1244 1255 for (i = 0; i < sdma->num_events; i++) 1245 - __raw_writel(0, sdma->regs + chnenbl_ofs(sdma, i)); 1256 + writel_relaxed(0, sdma->regs + chnenbl_ofs(sdma, i)); 1246 1257 1247 1258 /* All channels have priority 0 */ 1248 1259 for (i = 0; i < MAX_DMA_CHANNELS; i++) 1249 - __raw_writel(0, sdma->regs + SDMA_CHNPRI_0 + i * 4); 1260 + writel_relaxed(0, sdma->regs + SDMA_CHNPRI_0 + i * 4); 1250 1261 1251 1262 ret = sdma_request_channel(&sdma->channel[0]); 1252 1263 if (ret) ··· 1255 1266 sdma_config_ownership(&sdma->channel[0], false, true, false); 1256 1267 1257 1268 /* Set Command Channel (Channel Zero) */ 1258 - __raw_writel(0x4050, sdma->regs + SDMA_CHN0ADDR); 1269 + writel_relaxed(0x4050, sdma->regs + SDMA_CHN0ADDR); 1259 1270 1260 1271 /* Set bits of CONFIG register but with static context switching */ 1261 1272 /* FIXME: Check whether to set ACR bit depending on clock ratios */ 1262 - __raw_writel(0, sdma->regs + SDMA_H_CONFIG); 1273 + writel_relaxed(0, sdma->regs + SDMA_H_CONFIG); 1263 1274 1264 - __raw_writel(ccb_phys, sdma->regs + SDMA_H_C0PTR); 1275 + writel_relaxed(ccb_phys, sdma->regs + SDMA_H_C0PTR); 1265 1276 1266 1277 /* Set bits of CONFIG register with given context switching mode */ 1267 - __raw_writel(SDMA_H_CONFIG_CSM, sdma->regs + SDMA_H_CONFIG); 1278 + writel_relaxed(SDMA_H_CONFIG_CSM, sdma->regs + SDMA_H_CONFIG); 1268 1279 1269 1280 /* Initializes channel's priorities */ 1270 1281 sdma_set_channel_priority(&sdma->channel[0], 7); ··· 1356 1367 spin_lock_init(&sdmac->lock); 1357 1368 1358 1369 sdmac->chan.device = &sdma->dma_device; 1370 + dma_cookie_init(&sdmac->chan); 1359 1371 sdmac->channel = i; 1360 1372 1361 1373 /* ··· 1377 1387 sdma_add_scripts(sdma, pdata->script_addrs); 1378 1388 1379 1389 if (pdata) { 1380 - sdma_get_firmware(sdma, pdata->fw_name); 1390 + ret = sdma_get_firmware(sdma, pdata->fw_name); 1391 + if (ret) 1392 + dev_warn(&pdev->dev, "failed to get firmware from platform data\n"); 1381 1393 } else { 1382 1394 /* 1383 1395 * Because that device tree does not encode ROM script address, ··· 1388 1396 */ 1389 1397 ret = of_property_read_string(np, "fsl,sdma-ram-script-name", 1390 1398 &fw_name); 1391 - if (ret) { 1392 - dev_err(&pdev->dev, "failed to get firmware name\n"); 1393 - goto err_init; 1394 - } 1395 - 1396 - ret = sdma_get_firmware(sdma, fw_name); 1397 - if (ret) { 1398 - dev_err(&pdev->dev, "failed to get firmware\n"); 1399 - goto err_init; 1399 + if (ret) 1400 + dev_warn(&pdev->dev, "failed to get firmware name\n"); 1401 + else { 1402 + ret = sdma_get_firmware(sdma, fw_name); 1403 + if (ret) 1404 + dev_warn(&pdev->dev, "failed to get firmware from device tree\n"); 1400 1405 } 1401 1406 } 1402 1407
+15 -31
drivers/dma/intel_mid_dma.c
··· 29 29 #include <linux/intel_mid_dma.h> 30 30 #include <linux/module.h> 31 31 32 + #include "dmaengine.h" 33 + 32 34 #define MAX_CHAN 4 /*max ch across controllers*/ 33 35 #include "intel_mid_dma_regs.h" 34 36 ··· 290 288 struct intel_mid_dma_lli *llitem; 291 289 void *param_txd = NULL; 292 290 293 - midc->completed = txd->cookie; 291 + dma_cookie_complete(txd); 294 292 callback_txd = txd->callback; 295 293 param_txd = txd->callback_param; 296 294 ··· 436 434 dma_cookie_t cookie; 437 435 438 436 spin_lock_bh(&midc->lock); 439 - cookie = midc->chan.cookie; 440 - 441 - if (++cookie < 0) 442 - cookie = 1; 443 - 444 - midc->chan.cookie = cookie; 445 - desc->txd.cookie = cookie; 446 - 437 + cookie = dma_cookie_assign(tx); 447 438 448 439 if (list_empty(&midc->active_list)) 449 440 list_add_tail(&desc->desc_node, &midc->active_list); ··· 477 482 dma_cookie_t cookie, 478 483 struct dma_tx_state *txstate) 479 484 { 480 - struct intel_mid_dma_chan *midc = to_intel_mid_dma_chan(chan); 481 - dma_cookie_t last_used; 482 - dma_cookie_t last_complete; 483 - int ret; 485 + struct intel_mid_dma_chan *midc = to_intel_mid_dma_chan(chan); 486 + enum dma_status ret; 484 487 485 - last_complete = midc->completed; 486 - last_used = chan->cookie; 487 - 488 - ret = dma_async_is_complete(cookie, last_complete, last_used); 488 + ret = dma_cookie_status(chan, cookie, txstate); 489 489 if (ret != DMA_SUCCESS) { 490 490 spin_lock_bh(&midc->lock); 491 491 midc_scan_descriptors(to_middma_device(chan->device), midc); 492 492 spin_unlock_bh(&midc->lock); 493 493 494 - last_complete = midc->completed; 495 - last_used = chan->cookie; 496 - 497 - ret = dma_async_is_complete(cookie, last_complete, last_used); 494 + ret = dma_cookie_status(chan, cookie, txstate); 498 495 } 499 496 500 - if (txstate) { 501 - txstate->last = last_complete; 502 - txstate->used = last_used; 503 - txstate->residue = 0; 504 - } 505 497 return ret; 506 498 } 507 499 ··· 714 732 * @sg_len: length of sg txn 715 733 * @direction: DMA transfer dirtn 716 734 * @flags: DMA flags 735 + * @context: transfer context (ignored) 717 736 * 718 737 * Prepares LLI based periphral transfer 719 738 */ 720 739 static struct dma_async_tx_descriptor *intel_mid_dma_prep_slave_sg( 721 740 struct dma_chan *chan, struct scatterlist *sgl, 722 741 unsigned int sg_len, enum dma_transfer_direction direction, 723 - unsigned long flags) 742 + unsigned long flags, void *context) 724 743 { 725 744 struct intel_mid_dma_chan *midc = NULL; 726 745 struct intel_mid_dma_slave *mids = NULL; ··· 815 832 /*trying to free ch in use!!!!!*/ 816 833 pr_err("ERR_MDMA: trying to free ch in use\n"); 817 834 } 818 - pm_runtime_put(&mid->pdev->dev); 819 835 spin_lock_bh(&midc->lock); 820 836 midc->descs_allocated = 0; 821 837 list_for_each_entry_safe(desc, _desc, &midc->active_list, desc_node) { ··· 835 853 /* Disable CH interrupts */ 836 854 iowrite32(MASK_INTR_REG(midc->ch_id), mid->dma_base + MASK_BLOCK); 837 855 iowrite32(MASK_INTR_REG(midc->ch_id), mid->dma_base + MASK_ERR); 856 + pm_runtime_put(&mid->pdev->dev); 838 857 } 839 858 840 859 /** ··· 869 886 pm_runtime_put(&mid->pdev->dev); 870 887 return -EIO; 871 888 } 872 - midc->completed = chan->cookie = 1; 889 + dma_cookie_init(chan); 873 890 874 891 spin_lock_bh(&midc->lock); 875 892 while (midc->descs_allocated < DESCS_PER_CHANNEL) { ··· 1039 1056 } 1040 1057 err_status &= mid->intr_mask; 1041 1058 if (err_status) { 1042 - iowrite32(MASK_INTR_REG(err_status), mid->dma_base + MASK_ERR); 1059 + iowrite32((err_status << INT_MASK_WE), 1060 + mid->dma_base + MASK_ERR); 1043 1061 call_tasklet = 1; 1044 1062 } 1045 1063 if (call_tasklet) ··· 1102 1118 struct intel_mid_dma_chan *midch = &dma->ch[i]; 1103 1119 1104 1120 midch->chan.device = &dma->common; 1105 - midch->chan.cookie = 1; 1121 + dma_cookie_init(&midch->chan); 1106 1122 midch->ch_id = dma->chan_base + i; 1107 1123 pr_debug("MDMA:Init CH %d, ID %d\n", i, midch->ch_id); 1108 1124
-2
drivers/dma/intel_mid_dma_regs.h
··· 165 165 * @dma_base: MMIO register space DMA engine base pointer 166 166 * @ch_id: DMA channel id 167 167 * @lock: channel spinlock 168 - * @completed: DMA cookie 169 168 * @active_list: current active descriptors 170 169 * @queue: current queued up descriptors 171 170 * @free_list: current free descriptors ··· 182 183 void __iomem *dma_base; 183 184 int ch_id; 184 185 spinlock_t lock; 185 - dma_cookie_t completed; 186 186 struct list_head active_list; 187 187 struct list_head queue; 188 188 struct list_head free_list;
+10 -11
drivers/dma/ioat/dma.c
··· 40 40 #include "registers.h" 41 41 #include "hw.h" 42 42 43 + #include "../dmaengine.h" 44 + 43 45 int ioat_pending_level = 4; 44 46 module_param(ioat_pending_level, int, 0644); 45 47 MODULE_PARM_DESC(ioat_pending_level, ··· 109 107 chan->reg_base = device->reg_base + (0x80 * (idx + 1)); 110 108 spin_lock_init(&chan->cleanup_lock); 111 109 chan->common.device = dma; 110 + dma_cookie_init(&chan->common); 112 111 list_add_tail(&chan->common.device_node, &dma->channels); 113 112 device->idx[idx] = chan; 114 113 init_timer(&chan->timer); ··· 238 235 239 236 spin_lock_bh(&ioat->desc_lock); 240 237 /* cookie incr and addition to used_list must be atomic */ 241 - cookie = c->cookie; 242 - cookie++; 243 - if (cookie < 0) 244 - cookie = 1; 245 - c->cookie = cookie; 246 - tx->cookie = cookie; 238 + cookie = dma_cookie_assign(tx); 247 239 dev_dbg(to_dev(&ioat->base), "%s: cookie: %d\n", __func__, cookie); 248 240 249 241 /* write address into NextDescriptor field of last desc in chain */ ··· 601 603 */ 602 604 dump_desc_dbg(ioat, desc); 603 605 if (tx->cookie) { 604 - chan->completed_cookie = tx->cookie; 605 - tx->cookie = 0; 606 + dma_cookie_complete(tx); 606 607 ioat_dma_unmap(chan, tx->flags, desc->len, desc->hw); 607 608 ioat->active -= desc->hw->tx_cnt; 608 609 if (tx->callback) { ··· 730 733 { 731 734 struct ioat_chan_common *chan = to_chan_common(c); 732 735 struct ioatdma_device *device = chan->device; 736 + enum dma_status ret; 733 737 734 - if (ioat_tx_status(c, cookie, txstate) == DMA_SUCCESS) 735 - return DMA_SUCCESS; 738 + ret = dma_cookie_status(c, cookie, txstate); 739 + if (ret == DMA_SUCCESS) 740 + return ret; 736 741 737 742 device->cleanup_fn((unsigned long) c); 738 743 739 - return ioat_tx_status(c, cookie, txstate); 744 + return dma_cookie_status(c, cookie, txstate); 740 745 } 741 746 742 747 static void ioat1_dma_start_null_desc(struct ioat_dma_chan *ioat)
-23
drivers/dma/ioat/dma.h
··· 90 90 void __iomem *reg_base; 91 91 unsigned long last_completion; 92 92 spinlock_t cleanup_lock; 93 - dma_cookie_t completed_cookie; 94 93 unsigned long state; 95 94 #define IOAT_COMPLETION_PENDING 0 96 95 #define IOAT_COMPLETION_ACK 1 ··· 140 141 struct ioat_chan_common *chan = to_chan_common(c); 141 142 142 143 return container_of(chan, struct ioat_dma_chan, base); 143 - } 144 - 145 - /** 146 - * ioat_tx_status - poll the status of an ioat transaction 147 - * @c: channel handle 148 - * @cookie: transaction identifier 149 - * @txstate: if set, updated with the transaction state 150 - */ 151 - static inline enum dma_status 152 - ioat_tx_status(struct dma_chan *c, dma_cookie_t cookie, 153 - struct dma_tx_state *txstate) 154 - { 155 - struct ioat_chan_common *chan = to_chan_common(c); 156 - dma_cookie_t last_used; 157 - dma_cookie_t last_complete; 158 - 159 - last_used = c->cookie; 160 - last_complete = chan->completed_cookie; 161 - 162 - dma_set_tx_state(txstate, last_complete, last_used, 0); 163 - 164 - return dma_async_is_complete(cookie, last_complete, last_used); 165 144 } 166 145 167 146 /* wrapper around hardware descriptor format + additional software fields */
+5 -8
drivers/dma/ioat/dma_v2.c
··· 41 41 #include "registers.h" 42 42 #include "hw.h" 43 43 44 + #include "../dmaengine.h" 45 + 44 46 int ioat_ring_alloc_order = 8; 45 47 module_param(ioat_ring_alloc_order, int, 0644); 46 48 MODULE_PARM_DESC(ioat_ring_alloc_order, ··· 149 147 dump_desc_dbg(ioat, desc); 150 148 if (tx->cookie) { 151 149 ioat_dma_unmap(chan, tx->flags, desc->len, desc->hw); 152 - chan->completed_cookie = tx->cookie; 153 - tx->cookie = 0; 150 + dma_cookie_complete(tx); 154 151 if (tx->callback) { 155 152 tx->callback(tx->callback_param); 156 153 tx->callback = NULL; ··· 399 398 struct dma_chan *c = tx->chan; 400 399 struct ioat2_dma_chan *ioat = to_ioat2_chan(c); 401 400 struct ioat_chan_common *chan = &ioat->base; 402 - dma_cookie_t cookie = c->cookie; 401 + dma_cookie_t cookie; 403 402 404 - cookie++; 405 - if (cookie < 0) 406 - cookie = 1; 407 - tx->cookie = cookie; 408 - c->cookie = cookie; 403 + cookie = dma_cookie_assign(tx); 409 404 dev_dbg(to_dev(&ioat->base), "%s: cookie: %d\n", __func__, cookie); 410 405 411 406 if (!test_and_set_bit(IOAT_COMPLETION_PENDING, &chan->state))
+7 -5
drivers/dma/ioat/dma_v3.c
··· 61 61 #include <linux/dmaengine.h> 62 62 #include <linux/dma-mapping.h> 63 63 #include <linux/prefetch.h> 64 + #include "../dmaengine.h" 64 65 #include "registers.h" 65 66 #include "hw.h" 66 67 #include "dma.h" ··· 278 277 dump_desc_dbg(ioat, desc); 279 278 tx = &desc->txd; 280 279 if (tx->cookie) { 281 - chan->completed_cookie = tx->cookie; 280 + dma_cookie_complete(tx); 282 281 ioat3_dma_unmap(ioat, desc, idx + i); 283 - tx->cookie = 0; 284 282 if (tx->callback) { 285 283 tx->callback(tx->callback_param); 286 284 tx->callback = NULL; ··· 411 411 struct dma_tx_state *txstate) 412 412 { 413 413 struct ioat2_dma_chan *ioat = to_ioat2_chan(c); 414 + enum dma_status ret; 414 415 415 - if (ioat_tx_status(c, cookie, txstate) == DMA_SUCCESS) 416 - return DMA_SUCCESS; 416 + ret = dma_cookie_status(c, cookie, txstate); 417 + if (ret == DMA_SUCCESS) 418 + return ret; 417 419 418 420 ioat3_cleanup(ioat); 419 421 420 - return ioat_tx_status(c, cookie, txstate); 422 + return dma_cookie_status(c, cookie, txstate); 421 423 } 422 424 423 425 static struct dma_async_tx_descriptor *
+12 -38
drivers/dma/iop-adma.c
··· 36 36 37 37 #include <mach/adma.h> 38 38 39 + #include "dmaengine.h" 40 + 39 41 #define to_iop_adma_chan(chan) container_of(chan, struct iop_adma_chan, common) 40 42 #define to_iop_adma_device(dev) \ 41 43 container_of(dev, struct iop_adma_device, common) ··· 319 317 } 320 318 321 319 if (cookie > 0) { 322 - iop_chan->completed_cookie = cookie; 320 + iop_chan->common.completed_cookie = cookie; 323 321 pr_debug("\tcompleted cookie %d\n", cookie); 324 322 } 325 323 } ··· 440 438 return NULL; 441 439 } 442 440 443 - static dma_cookie_t 444 - iop_desc_assign_cookie(struct iop_adma_chan *iop_chan, 445 - struct iop_adma_desc_slot *desc) 446 - { 447 - dma_cookie_t cookie = iop_chan->common.cookie; 448 - cookie++; 449 - if (cookie < 0) 450 - cookie = 1; 451 - iop_chan->common.cookie = desc->async_tx.cookie = cookie; 452 - return cookie; 453 - } 454 - 455 441 static void iop_adma_check_threshold(struct iop_adma_chan *iop_chan) 456 442 { 457 443 dev_dbg(iop_chan->device->common.dev, "pending: %d\n", ··· 467 477 slots_per_op = grp_start->slots_per_op; 468 478 469 479 spin_lock_bh(&iop_chan->lock); 470 - cookie = iop_desc_assign_cookie(iop_chan, sw_desc); 480 + cookie = dma_cookie_assign(tx); 471 481 472 482 old_chain_tail = list_entry(iop_chan->chain.prev, 473 483 struct iop_adma_desc_slot, chain_node); ··· 894 904 struct dma_tx_state *txstate) 895 905 { 896 906 struct iop_adma_chan *iop_chan = to_iop_adma_chan(chan); 897 - dma_cookie_t last_used; 898 - dma_cookie_t last_complete; 899 - enum dma_status ret; 907 + int ret; 900 908 901 - last_used = chan->cookie; 902 - last_complete = iop_chan->completed_cookie; 903 - dma_set_tx_state(txstate, last_complete, last_used, 0); 904 - ret = dma_async_is_complete(cookie, last_complete, last_used); 909 + ret = dma_cookie_status(chan, cookie, txstate); 905 910 if (ret == DMA_SUCCESS) 906 911 return ret; 907 912 908 913 iop_adma_slot_cleanup(iop_chan); 909 914 910 - last_used = chan->cookie; 911 - last_complete = iop_chan->completed_cookie; 912 - dma_set_tx_state(txstate, last_complete, last_used, 0); 913 - 914 - return dma_async_is_complete(cookie, last_complete, last_used); 915 + return dma_cookie_status(chan, cookie, txstate); 915 916 } 916 917 917 918 static irqreturn_t iop_adma_eot_handler(int irq, void *data) ··· 1546 1565 INIT_LIST_HEAD(&iop_chan->chain); 1547 1566 INIT_LIST_HEAD(&iop_chan->all_slots); 1548 1567 iop_chan->common.device = dma_dev; 1568 + dma_cookie_init(&iop_chan->common); 1549 1569 list_add_tail(&iop_chan->common.device_node, &dma_dev->channels); 1550 1570 1551 1571 if (dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask)) { ··· 1624 1642 iop_desc_set_dest_addr(grp_start, iop_chan, 0); 1625 1643 iop_desc_set_memcpy_src_addr(grp_start, 0); 1626 1644 1627 - cookie = iop_chan->common.cookie; 1628 - cookie++; 1629 - if (cookie <= 1) 1630 - cookie = 2; 1645 + cookie = dma_cookie_assign(&sw_desc->async_tx); 1631 1646 1632 1647 /* initialize the completed cookie to be less than 1633 1648 * the most recently used cookie 1634 1649 */ 1635 - iop_chan->completed_cookie = cookie - 1; 1636 - iop_chan->common.cookie = sw_desc->async_tx.cookie = cookie; 1650 + iop_chan->common.completed_cookie = cookie - 1; 1637 1651 1638 1652 /* channel should not be busy */ 1639 1653 BUG_ON(iop_chan_is_busy(iop_chan)); ··· 1677 1699 iop_desc_set_xor_src_addr(grp_start, 0, 0); 1678 1700 iop_desc_set_xor_src_addr(grp_start, 1, 0); 1679 1701 1680 - cookie = iop_chan->common.cookie; 1681 - cookie++; 1682 - if (cookie <= 1) 1683 - cookie = 2; 1702 + cookie = dma_cookie_assign(&sw_desc->async_tx); 1684 1703 1685 1704 /* initialize the completed cookie to be less than 1686 1705 * the most recently used cookie 1687 1706 */ 1688 - iop_chan->completed_cookie = cookie - 1; 1689 - iop_chan->common.cookie = sw_desc->async_tx.cookie = cookie; 1707 + iop_chan->common.completed_cookie = cookie - 1; 1690 1708 1691 1709 /* channel should not be busy */ 1692 1710 BUG_ON(iop_chan_is_busy(iop_chan));
+8 -17
drivers/dma/ipu/ipu_idmac.c
··· 25 25 26 26 #include <mach/ipu.h> 27 27 28 + #include "../dmaengine.h" 28 29 #include "ipu_intern.h" 29 30 30 31 #define FS_VF_IN_VALID 0x00000002 ··· 867 866 868 867 dev_dbg(dev, "Submitting sg %p\n", &desc->sg[0]); 869 868 870 - cookie = ichan->dma_chan.cookie; 871 - 872 - if (++cookie < 0) 873 - cookie = 1; 874 - 875 - /* from dmaengine.h: "last cookie value returned to client" */ 876 - ichan->dma_chan.cookie = cookie; 877 - tx->cookie = cookie; 869 + cookie = dma_cookie_assign(tx); 878 870 879 871 /* ipu->lock can be taken under ichan->lock, but not v.v. */ 880 872 spin_lock_irqsave(&ichan->lock, flags); ··· 1289 1295 /* Flip the active buffer - even if update above failed */ 1290 1296 ichan->active_buffer = !ichan->active_buffer; 1291 1297 if (done) 1292 - ichan->completed = desc->txd.cookie; 1298 + dma_cookie_complete(&desc->txd); 1293 1299 1294 1300 callback = desc->txd.callback; 1295 1301 callback_param = desc->txd.callback_param; ··· 1335 1341 /* Allocate and initialise a transfer descriptor. */ 1336 1342 static struct dma_async_tx_descriptor *idmac_prep_slave_sg(struct dma_chan *chan, 1337 1343 struct scatterlist *sgl, unsigned int sg_len, 1338 - enum dma_transfer_direction direction, unsigned long tx_flags) 1344 + enum dma_transfer_direction direction, unsigned long tx_flags, 1345 + void *context) 1339 1346 { 1340 1347 struct idmac_channel *ichan = to_idmac_chan(chan); 1341 1348 struct idmac_tx_desc *desc = NULL; ··· 1505 1510 BUG_ON(chan->client_count > 1); 1506 1511 WARN_ON(ichan->status != IPU_CHANNEL_FREE); 1507 1512 1508 - chan->cookie = 1; 1509 - ichan->completed = -ENXIO; 1513 + dma_cookie_init(chan); 1510 1514 1511 1515 ret = ipu_irq_map(chan->chan_id); 1512 1516 if (ret < 0) ··· 1594 1600 static enum dma_status idmac_tx_status(struct dma_chan *chan, 1595 1601 dma_cookie_t cookie, struct dma_tx_state *txstate) 1596 1602 { 1597 - struct idmac_channel *ichan = to_idmac_chan(chan); 1598 - 1599 - dma_set_tx_state(txstate, ichan->completed, chan->cookie, 0); 1603 + dma_set_tx_state(txstate, chan->completed_cookie, chan->cookie, 0); 1600 1604 if (cookie != chan->cookie) 1601 1605 return DMA_ERROR; 1602 1606 return DMA_SUCCESS; ··· 1630 1638 1631 1639 ichan->status = IPU_CHANNEL_FREE; 1632 1640 ichan->sec_chan_en = false; 1633 - ichan->completed = -ENXIO; 1634 1641 snprintf(ichan->eof_name, sizeof(ichan->eof_name), "IDMAC EOF %d", i); 1635 1642 1636 1643 dma_chan->device = &idmac->dma; 1637 - dma_chan->cookie = 1; 1644 + dma_cookie_init(dma_chan); 1638 1645 dma_chan->chan_id = i; 1639 1646 list_add_tail(&dma_chan->device_node, &dma->channels); 1640 1647 }
+8 -17
drivers/dma/mpc512x_dma.c
··· 44 44 45 45 #include <linux/random.h> 46 46 47 + #include "dmaengine.h" 48 + 47 49 /* Number of DMA Transfer descriptors allocated per channel */ 48 50 #define MPC_DMA_DESCRIPTORS 64 49 51 ··· 190 188 struct list_head completed; 191 189 struct mpc_dma_tcd *tcd; 192 190 dma_addr_t tcd_paddr; 193 - dma_cookie_t completed_cookie; 194 191 195 192 /* Lock for this structure */ 196 193 spinlock_t lock; ··· 366 365 /* Free descriptors */ 367 366 spin_lock_irqsave(&mchan->lock, flags); 368 367 list_splice_tail_init(&list, &mchan->free); 369 - mchan->completed_cookie = last_cookie; 368 + mchan->chan.completed_cookie = last_cookie; 370 369 spin_unlock_irqrestore(&mchan->lock, flags); 371 370 } 372 371 } ··· 439 438 mpc_dma_execute(mchan); 440 439 441 440 /* Update cookie */ 442 - cookie = mchan->chan.cookie + 1; 443 - if (cookie <= 0) 444 - cookie = 1; 445 - 446 - mchan->chan.cookie = cookie; 447 - mdesc->desc.cookie = cookie; 448 - 441 + cookie = dma_cookie_assign(txd); 449 442 spin_unlock_irqrestore(&mchan->lock, flags); 450 443 451 444 return cookie; ··· 557 562 struct dma_tx_state *txstate) 558 563 { 559 564 struct mpc_dma_chan *mchan = dma_chan_to_mpc_dma_chan(chan); 565 + enum dma_status ret; 560 566 unsigned long flags; 561 - dma_cookie_t last_used; 562 - dma_cookie_t last_complete; 563 567 564 568 spin_lock_irqsave(&mchan->lock, flags); 565 - last_used = mchan->chan.cookie; 566 - last_complete = mchan->completed_cookie; 569 + ret = dma_cookie_status(chan, cookie, txstate); 567 570 spin_unlock_irqrestore(&mchan->lock, flags); 568 571 569 - dma_set_tx_state(txstate, last_complete, last_used, 0); 570 - return dma_async_is_complete(cookie, last_complete, last_used); 572 + return ret; 571 573 } 572 574 573 575 /* Prepare descriptor for memory to memory copy */ ··· 733 741 mchan = &mdma->channels[i]; 734 742 735 743 mchan->chan.device = dma; 736 - mchan->chan.cookie = 1; 737 - mchan->completed_cookie = mchan->chan.cookie; 744 + dma_cookie_init(&mchan->chan); 738 745 739 746 INIT_LIST_HEAD(&mchan->free); 740 747 INIT_LIST_HEAD(&mchan->prepared);
+7 -27
drivers/dma/mv_xor.c
··· 26 26 #include <linux/platform_device.h> 27 27 #include <linux/memory.h> 28 28 #include <plat/mv_xor.h> 29 + 30 + #include "dmaengine.h" 29 31 #include "mv_xor.h" 30 32 31 33 static void mv_xor_issue_pending(struct dma_chan *chan); ··· 437 435 } 438 436 439 437 if (cookie > 0) 440 - mv_chan->completed_cookie = cookie; 438 + mv_chan->common.completed_cookie = cookie; 441 439 } 442 440 443 441 static void ··· 536 534 return NULL; 537 535 } 538 536 539 - static dma_cookie_t 540 - mv_desc_assign_cookie(struct mv_xor_chan *mv_chan, 541 - struct mv_xor_desc_slot *desc) 542 - { 543 - dma_cookie_t cookie = mv_chan->common.cookie; 544 - 545 - if (++cookie < 0) 546 - cookie = 1; 547 - mv_chan->common.cookie = desc->async_tx.cookie = cookie; 548 - return cookie; 549 - } 550 - 551 537 /************************ DMA engine API functions ****************************/ 552 538 static dma_cookie_t 553 539 mv_xor_tx_submit(struct dma_async_tx_descriptor *tx) ··· 553 563 grp_start = sw_desc->group_head; 554 564 555 565 spin_lock_bh(&mv_chan->lock); 556 - cookie = mv_desc_assign_cookie(mv_chan, sw_desc); 566 + cookie = dma_cookie_assign(tx); 557 567 558 568 if (list_empty(&mv_chan->chain)) 559 569 list_splice_init(&sw_desc->tx_list, &mv_chan->chain); ··· 810 820 struct dma_tx_state *txstate) 811 821 { 812 822 struct mv_xor_chan *mv_chan = to_mv_xor_chan(chan); 813 - dma_cookie_t last_used; 814 - dma_cookie_t last_complete; 815 823 enum dma_status ret; 816 824 817 - last_used = chan->cookie; 818 - last_complete = mv_chan->completed_cookie; 819 - mv_chan->is_complete_cookie = cookie; 820 - dma_set_tx_state(txstate, last_complete, last_used, 0); 821 - 822 - ret = dma_async_is_complete(cookie, last_complete, last_used); 825 + ret = dma_cookie_status(chan, cookie, txstate); 823 826 if (ret == DMA_SUCCESS) { 824 827 mv_xor_clean_completed_slots(mv_chan); 825 828 return ret; 826 829 } 827 830 mv_xor_slot_cleanup(mv_chan); 828 831 829 - last_used = chan->cookie; 830 - last_complete = mv_chan->completed_cookie; 831 - 832 - dma_set_tx_state(txstate, last_complete, last_used, 0); 833 - return dma_async_is_complete(cookie, last_complete, last_used); 832 + return dma_cookie_status(chan, cookie, txstate); 834 833 } 835 834 836 835 static void mv_dump_xor_regs(struct mv_xor_chan *chan) ··· 1193 1214 INIT_LIST_HEAD(&mv_chan->completed_slots); 1194 1215 INIT_LIST_HEAD(&mv_chan->all_slots); 1195 1216 mv_chan->common.device = dma_dev; 1217 + dma_cookie_init(&mv_chan->common); 1196 1218 1197 1219 list_add_tail(&mv_chan->common.device_node, &dma_dev->channels); 1198 1220
-3
drivers/dma/mv_xor.h
··· 78 78 /** 79 79 * struct mv_xor_chan - internal representation of a XOR channel 80 80 * @pending: allows batching of hardware operations 81 - * @completed_cookie: identifier for the most recently completed operation 82 81 * @lock: serializes enqueue/dequeue operations to the descriptors pool 83 82 * @mmr_base: memory mapped register base 84 83 * @idx: the index of the xor channel ··· 92 93 */ 93 94 struct mv_xor_chan { 94 95 int pending; 95 - dma_cookie_t completed_cookie; 96 96 spinlock_t lock; /* protects the descriptor slot pool */ 97 97 void __iomem *mmr_base; 98 98 unsigned int idx; ··· 107 109 #ifdef USE_TIMER 108 110 unsigned long cleanup_time; 109 111 u32 current_on_last_cleanup; 110 - dma_cookie_t is_complete_cookie; 111 112 #endif 112 113 }; 113 114
+9 -19
drivers/dma/mxs-dma.c
··· 28 28 #include <mach/dma.h> 29 29 #include <mach/common.h> 30 30 31 + #include "dmaengine.h" 32 + 31 33 /* 32 34 * NOTE: The term "PIO" throughout the mxs-dma implementation means 33 35 * PIO mode of mxs apbh-dma and apbx-dma. With this working mode, ··· 113 111 struct mxs_dma_ccw *ccw; 114 112 dma_addr_t ccw_phys; 115 113 int desc_count; 116 - dma_cookie_t last_completed; 117 114 enum dma_status status; 118 115 unsigned int flags; 119 116 #define MXS_DMA_SG_LOOP (1 << 0) ··· 194 193 mxs_chan->status = DMA_IN_PROGRESS; 195 194 } 196 195 197 - static dma_cookie_t mxs_dma_assign_cookie(struct mxs_dma_chan *mxs_chan) 198 - { 199 - dma_cookie_t cookie = mxs_chan->chan.cookie; 200 - 201 - if (++cookie < 0) 202 - cookie = 1; 203 - 204 - mxs_chan->chan.cookie = cookie; 205 - mxs_chan->desc.cookie = cookie; 206 - 207 - return cookie; 208 - } 209 - 210 196 static struct mxs_dma_chan *to_mxs_dma_chan(struct dma_chan *chan) 211 197 { 212 198 return container_of(chan, struct mxs_dma_chan, chan); ··· 205 217 206 218 mxs_dma_enable_chan(mxs_chan); 207 219 208 - return mxs_dma_assign_cookie(mxs_chan); 220 + return dma_cookie_assign(tx); 209 221 } 210 222 211 223 static void mxs_dma_tasklet(unsigned long data) ··· 262 274 stat1 &= ~(1 << channel); 263 275 264 276 if (mxs_chan->status == DMA_SUCCESS) 265 - mxs_chan->last_completed = mxs_chan->desc.cookie; 277 + dma_cookie_complete(&mxs_chan->desc); 266 278 267 279 /* schedule tasklet on this channel */ 268 280 tasklet_schedule(&mxs_chan->tasklet); ··· 340 352 static struct dma_async_tx_descriptor *mxs_dma_prep_slave_sg( 341 353 struct dma_chan *chan, struct scatterlist *sgl, 342 354 unsigned int sg_len, enum dma_transfer_direction direction, 343 - unsigned long append) 355 + unsigned long append, void *context) 344 356 { 345 357 struct mxs_dma_chan *mxs_chan = to_mxs_dma_chan(chan); 346 358 struct mxs_dma_engine *mxs_dma = mxs_chan->mxs_dma; ··· 435 447 436 448 static struct dma_async_tx_descriptor *mxs_dma_prep_dma_cyclic( 437 449 struct dma_chan *chan, dma_addr_t dma_addr, size_t buf_len, 438 - size_t period_len, enum dma_transfer_direction direction) 450 + size_t period_len, enum dma_transfer_direction direction, 451 + void *context) 439 452 { 440 453 struct mxs_dma_chan *mxs_chan = to_mxs_dma_chan(chan); 441 454 struct mxs_dma_engine *mxs_dma = mxs_chan->mxs_dma; ··· 527 538 dma_cookie_t last_used; 528 539 529 540 last_used = chan->cookie; 530 - dma_set_tx_state(txstate, mxs_chan->last_completed, last_used, 0); 541 + dma_set_tx_state(txstate, chan->completed_cookie, last_used, 0); 531 542 532 543 return mxs_chan->status; 533 544 } ··· 619 630 620 631 mxs_chan->mxs_dma = mxs_dma; 621 632 mxs_chan->chan.device = &mxs_dma->dma_device; 633 + dma_cookie_init(&mxs_chan->chan); 622 634 623 635 tasklet_init(&mxs_chan->tasklet, mxs_dma_tasklet, 624 636 (unsigned long) mxs_chan);
+9 -28
drivers/dma/pch_dma.c
··· 25 25 #include <linux/module.h> 26 26 #include <linux/pch_dma.h> 27 27 28 + #include "dmaengine.h" 29 + 28 30 #define DRV_NAME "pch-dma" 29 31 30 32 #define DMA_CTL0_DISABLE 0x0 ··· 107 105 108 106 spinlock_t lock; 109 107 110 - dma_cookie_t completed_cookie; 111 108 struct list_head active_list; 112 109 struct list_head queue; 113 110 struct list_head free_list; ··· 417 416 } 418 417 } 419 418 420 - static dma_cookie_t pdc_assign_cookie(struct pch_dma_chan *pd_chan, 421 - struct pch_dma_desc *desc) 422 - { 423 - dma_cookie_t cookie = pd_chan->chan.cookie; 424 - 425 - if (++cookie < 0) 426 - cookie = 1; 427 - 428 - pd_chan->chan.cookie = cookie; 429 - desc->txd.cookie = cookie; 430 - 431 - return cookie; 432 - } 433 - 434 419 static dma_cookie_t pd_tx_submit(struct dma_async_tx_descriptor *txd) 435 420 { 436 421 struct pch_dma_desc *desc = to_pd_desc(txd); ··· 424 437 dma_cookie_t cookie; 425 438 426 439 spin_lock(&pd_chan->lock); 427 - cookie = pdc_assign_cookie(pd_chan, desc); 440 + cookie = dma_cookie_assign(txd); 428 441 429 442 if (list_empty(&pd_chan->active_list)) { 430 443 list_add_tail(&desc->desc_node, &pd_chan->active_list); ··· 531 544 spin_lock_irq(&pd_chan->lock); 532 545 list_splice(&tmp_list, &pd_chan->free_list); 533 546 pd_chan->descs_allocated = i; 534 - pd_chan->completed_cookie = chan->cookie = 1; 547 + dma_cookie_init(chan); 535 548 spin_unlock_irq(&pd_chan->lock); 536 549 537 550 pdc_enable_irq(chan, 1); ··· 565 578 struct dma_tx_state *txstate) 566 579 { 567 580 struct pch_dma_chan *pd_chan = to_pd_chan(chan); 568 - dma_cookie_t last_used; 569 - dma_cookie_t last_completed; 570 - int ret; 581 + enum dma_status ret; 571 582 572 583 spin_lock_irq(&pd_chan->lock); 573 - last_completed = pd_chan->completed_cookie; 574 - last_used = chan->cookie; 584 + ret = dma_cookie_status(chan, cookie, txstate); 575 585 spin_unlock_irq(&pd_chan->lock); 576 - 577 - ret = dma_async_is_complete(cookie, last_completed, last_used); 578 - 579 - dma_set_tx_state(txstate, last_completed, last_used, 0); 580 586 581 587 return ret; 582 588 } ··· 587 607 588 608 static struct dma_async_tx_descriptor *pd_prep_slave_sg(struct dma_chan *chan, 589 609 struct scatterlist *sgl, unsigned int sg_len, 590 - enum dma_transfer_direction direction, unsigned long flags) 610 + enum dma_transfer_direction direction, unsigned long flags, 611 + void *context) 591 612 { 592 613 struct pch_dma_chan *pd_chan = to_pd_chan(chan); 593 614 struct pch_dma_slave *pd_slave = chan->private; ··· 913 932 struct pch_dma_chan *pd_chan = &pd->channels[i]; 914 933 915 934 pd_chan->chan.device = &pd->dma; 916 - pd_chan->chan.cookie = 1; 935 + dma_cookie_init(&pd_chan->chan); 917 936 918 937 pd_chan->membase = &regs->desc[i]; 919 938
+2110 -39
drivers/dma/pl330.c
··· 1 - /* linux/drivers/dma/pl330.c 1 + /* 2 + * Copyright (c) 2012 Samsung Electronics Co., Ltd. 3 + * http://www.samsung.com 2 4 * 3 5 * Copyright (C) 2010 Samsung Electronics Co. Ltd. 4 6 * Jaswinder Singh <jassi.brar@samsung.com> ··· 11 9 * (at your option) any later version. 12 10 */ 13 11 12 + #include <linux/kernel.h> 14 13 #include <linux/io.h> 15 14 #include <linux/init.h> 16 15 #include <linux/slab.h> 17 16 #include <linux/module.h> 17 + #include <linux/string.h> 18 + #include <linux/delay.h> 19 + #include <linux/interrupt.h> 20 + #include <linux/dma-mapping.h> 18 21 #include <linux/dmaengine.h> 19 22 #include <linux/interrupt.h> 20 23 #include <linux/amba/bus.h> ··· 28 21 #include <linux/scatterlist.h> 29 22 #include <linux/of.h> 30 23 24 + #include "dmaengine.h" 25 + #define PL330_MAX_CHAN 8 26 + #define PL330_MAX_IRQS 32 27 + #define PL330_MAX_PERI 32 28 + 29 + enum pl330_srccachectrl { 30 + SCCTRL0, /* Noncacheable and nonbufferable */ 31 + SCCTRL1, /* Bufferable only */ 32 + SCCTRL2, /* Cacheable, but do not allocate */ 33 + SCCTRL3, /* Cacheable and bufferable, but do not allocate */ 34 + SINVALID1, 35 + SINVALID2, 36 + SCCTRL6, /* Cacheable write-through, allocate on reads only */ 37 + SCCTRL7, /* Cacheable write-back, allocate on reads only */ 38 + }; 39 + 40 + enum pl330_dstcachectrl { 41 + DCCTRL0, /* Noncacheable and nonbufferable */ 42 + DCCTRL1, /* Bufferable only */ 43 + DCCTRL2, /* Cacheable, but do not allocate */ 44 + DCCTRL3, /* Cacheable and bufferable, but do not allocate */ 45 + DINVALID1, /* AWCACHE = 0x1000 */ 46 + DINVALID2, 47 + DCCTRL6, /* Cacheable write-through, allocate on writes only */ 48 + DCCTRL7, /* Cacheable write-back, allocate on writes only */ 49 + }; 50 + 51 + enum pl330_byteswap { 52 + SWAP_NO, 53 + SWAP_2, 54 + SWAP_4, 55 + SWAP_8, 56 + SWAP_16, 57 + }; 58 + 59 + enum pl330_reqtype { 60 + MEMTOMEM, 61 + MEMTODEV, 62 + DEVTOMEM, 63 + DEVTODEV, 64 + }; 65 + 66 + /* Register and Bit field Definitions */ 67 + #define DS 0x0 68 + #define DS_ST_STOP 0x0 69 + #define DS_ST_EXEC 0x1 70 + #define DS_ST_CMISS 0x2 71 + #define DS_ST_UPDTPC 0x3 72 + #define DS_ST_WFE 0x4 73 + #define DS_ST_ATBRR 0x5 74 + #define DS_ST_QBUSY 0x6 75 + #define DS_ST_WFP 0x7 76 + #define DS_ST_KILL 0x8 77 + #define DS_ST_CMPLT 0x9 78 + #define DS_ST_FLTCMP 0xe 79 + #define DS_ST_FAULT 0xf 80 + 81 + #define DPC 0x4 82 + #define INTEN 0x20 83 + #define ES 0x24 84 + #define INTSTATUS 0x28 85 + #define INTCLR 0x2c 86 + #define FSM 0x30 87 + #define FSC 0x34 88 + #define FTM 0x38 89 + 90 + #define _FTC 0x40 91 + #define FTC(n) (_FTC + (n)*0x4) 92 + 93 + #define _CS 0x100 94 + #define CS(n) (_CS + (n)*0x8) 95 + #define CS_CNS (1 << 21) 96 + 97 + #define _CPC 0x104 98 + #define CPC(n) (_CPC + (n)*0x8) 99 + 100 + #define _SA 0x400 101 + #define SA(n) (_SA + (n)*0x20) 102 + 103 + #define _DA 0x404 104 + #define DA(n) (_DA + (n)*0x20) 105 + 106 + #define _CC 0x408 107 + #define CC(n) (_CC + (n)*0x20) 108 + 109 + #define CC_SRCINC (1 << 0) 110 + #define CC_DSTINC (1 << 14) 111 + #define CC_SRCPRI (1 << 8) 112 + #define CC_DSTPRI (1 << 22) 113 + #define CC_SRCNS (1 << 9) 114 + #define CC_DSTNS (1 << 23) 115 + #define CC_SRCIA (1 << 10) 116 + #define CC_DSTIA (1 << 24) 117 + #define CC_SRCBRSTLEN_SHFT 4 118 + #define CC_DSTBRSTLEN_SHFT 18 119 + #define CC_SRCBRSTSIZE_SHFT 1 120 + #define CC_DSTBRSTSIZE_SHFT 15 121 + #define CC_SRCCCTRL_SHFT 11 122 + #define CC_SRCCCTRL_MASK 0x7 123 + #define CC_DSTCCTRL_SHFT 25 124 + #define CC_DRCCCTRL_MASK 0x7 125 + #define CC_SWAP_SHFT 28 126 + 127 + #define _LC0 0x40c 128 + #define LC0(n) (_LC0 + (n)*0x20) 129 + 130 + #define _LC1 0x410 131 + #define LC1(n) (_LC1 + (n)*0x20) 132 + 133 + #define DBGSTATUS 0xd00 134 + #define DBG_BUSY (1 << 0) 135 + 136 + #define DBGCMD 0xd04 137 + #define DBGINST0 0xd08 138 + #define DBGINST1 0xd0c 139 + 140 + #define CR0 0xe00 141 + #define CR1 0xe04 142 + #define CR2 0xe08 143 + #define CR3 0xe0c 144 + #define CR4 0xe10 145 + #define CRD 0xe14 146 + 147 + #define PERIPH_ID 0xfe0 148 + #define PERIPH_REV_SHIFT 20 149 + #define PERIPH_REV_MASK 0xf 150 + #define PERIPH_REV_R0P0 0 151 + #define PERIPH_REV_R1P0 1 152 + #define PERIPH_REV_R1P1 2 153 + #define PCELL_ID 0xff0 154 + 155 + #define CR0_PERIPH_REQ_SET (1 << 0) 156 + #define CR0_BOOT_EN_SET (1 << 1) 157 + #define CR0_BOOT_MAN_NS (1 << 2) 158 + #define CR0_NUM_CHANS_SHIFT 4 159 + #define CR0_NUM_CHANS_MASK 0x7 160 + #define CR0_NUM_PERIPH_SHIFT 12 161 + #define CR0_NUM_PERIPH_MASK 0x1f 162 + #define CR0_NUM_EVENTS_SHIFT 17 163 + #define CR0_NUM_EVENTS_MASK 0x1f 164 + 165 + #define CR1_ICACHE_LEN_SHIFT 0 166 + #define CR1_ICACHE_LEN_MASK 0x7 167 + #define CR1_NUM_ICACHELINES_SHIFT 4 168 + #define CR1_NUM_ICACHELINES_MASK 0xf 169 + 170 + #define CRD_DATA_WIDTH_SHIFT 0 171 + #define CRD_DATA_WIDTH_MASK 0x7 172 + #define CRD_WR_CAP_SHIFT 4 173 + #define CRD_WR_CAP_MASK 0x7 174 + #define CRD_WR_Q_DEP_SHIFT 8 175 + #define CRD_WR_Q_DEP_MASK 0xf 176 + #define CRD_RD_CAP_SHIFT 12 177 + #define CRD_RD_CAP_MASK 0x7 178 + #define CRD_RD_Q_DEP_SHIFT 16 179 + #define CRD_RD_Q_DEP_MASK 0xf 180 + #define CRD_DATA_BUFF_SHIFT 20 181 + #define CRD_DATA_BUFF_MASK 0x3ff 182 + 183 + #define PART 0x330 184 + #define DESIGNER 0x41 185 + #define REVISION 0x0 186 + #define INTEG_CFG 0x0 187 + #define PERIPH_ID_VAL ((PART << 0) | (DESIGNER << 12)) 188 + 189 + #define PCELL_ID_VAL 0xb105f00d 190 + 191 + #define PL330_STATE_STOPPED (1 << 0) 192 + #define PL330_STATE_EXECUTING (1 << 1) 193 + #define PL330_STATE_WFE (1 << 2) 194 + #define PL330_STATE_FAULTING (1 << 3) 195 + #define PL330_STATE_COMPLETING (1 << 4) 196 + #define PL330_STATE_WFP (1 << 5) 197 + #define PL330_STATE_KILLING (1 << 6) 198 + #define PL330_STATE_FAULT_COMPLETING (1 << 7) 199 + #define PL330_STATE_CACHEMISS (1 << 8) 200 + #define PL330_STATE_UPDTPC (1 << 9) 201 + #define PL330_STATE_ATBARRIER (1 << 10) 202 + #define PL330_STATE_QUEUEBUSY (1 << 11) 203 + #define PL330_STATE_INVALID (1 << 15) 204 + 205 + #define PL330_STABLE_STATES (PL330_STATE_STOPPED | PL330_STATE_EXECUTING \ 206 + | PL330_STATE_WFE | PL330_STATE_FAULTING) 207 + 208 + #define CMD_DMAADDH 0x54 209 + #define CMD_DMAEND 0x00 210 + #define CMD_DMAFLUSHP 0x35 211 + #define CMD_DMAGO 0xa0 212 + #define CMD_DMALD 0x04 213 + #define CMD_DMALDP 0x25 214 + #define CMD_DMALP 0x20 215 + #define CMD_DMALPEND 0x28 216 + #define CMD_DMAKILL 0x01 217 + #define CMD_DMAMOV 0xbc 218 + #define CMD_DMANOP 0x18 219 + #define CMD_DMARMB 0x12 220 + #define CMD_DMASEV 0x34 221 + #define CMD_DMAST 0x08 222 + #define CMD_DMASTP 0x29 223 + #define CMD_DMASTZ 0x0c 224 + #define CMD_DMAWFE 0x36 225 + #define CMD_DMAWFP 0x30 226 + #define CMD_DMAWMB 0x13 227 + 228 + #define SZ_DMAADDH 3 229 + #define SZ_DMAEND 1 230 + #define SZ_DMAFLUSHP 2 231 + #define SZ_DMALD 1 232 + #define SZ_DMALDP 2 233 + #define SZ_DMALP 2 234 + #define SZ_DMALPEND 2 235 + #define SZ_DMAKILL 1 236 + #define SZ_DMAMOV 6 237 + #define SZ_DMANOP 1 238 + #define SZ_DMARMB 1 239 + #define SZ_DMASEV 2 240 + #define SZ_DMAST 1 241 + #define SZ_DMASTP 2 242 + #define SZ_DMASTZ 1 243 + #define SZ_DMAWFE 2 244 + #define SZ_DMAWFP 2 245 + #define SZ_DMAWMB 1 246 + #define SZ_DMAGO 6 247 + 248 + #define BRST_LEN(ccr) ((((ccr) >> CC_SRCBRSTLEN_SHFT) & 0xf) + 1) 249 + #define BRST_SIZE(ccr) (1 << (((ccr) >> CC_SRCBRSTSIZE_SHFT) & 0x7)) 250 + 251 + #define BYTE_TO_BURST(b, ccr) ((b) / BRST_SIZE(ccr) / BRST_LEN(ccr)) 252 + #define BURST_TO_BYTE(c, ccr) ((c) * BRST_SIZE(ccr) * BRST_LEN(ccr)) 253 + 254 + /* 255 + * With 256 bytes, we can do more than 2.5MB and 5MB xfers per req 256 + * at 1byte/burst for P<->M and M<->M respectively. 257 + * For typical scenario, at 1word/burst, 10MB and 20MB xfers per req 258 + * should be enough for P<->M and M<->M respectively. 259 + */ 260 + #define MCODE_BUFF_PER_REQ 256 261 + 262 + /* If the _pl330_req is available to the client */ 263 + #define IS_FREE(req) (*((u8 *)((req)->mc_cpu)) == CMD_DMAEND) 264 + 265 + /* Use this _only_ to wait on transient states */ 266 + #define UNTIL(t, s) while (!(_state(t) & (s))) cpu_relax(); 267 + 268 + #ifdef PL330_DEBUG_MCGEN 269 + static unsigned cmd_line; 270 + #define PL330_DBGCMD_DUMP(off, x...) do { \ 271 + printk("%x:", cmd_line); \ 272 + printk(x); \ 273 + cmd_line += off; \ 274 + } while (0) 275 + #define PL330_DBGMC_START(addr) (cmd_line = addr) 276 + #else 277 + #define PL330_DBGCMD_DUMP(off, x...) do {} while (0) 278 + #define PL330_DBGMC_START(addr) do {} while (0) 279 + #endif 280 + 281 + /* The number of default descriptors */ 282 + 31 283 #define NR_DEFAULT_DESC 16 284 + 285 + /* Populated by the PL330 core driver for DMA API driver's info */ 286 + struct pl330_config { 287 + u32 periph_id; 288 + u32 pcell_id; 289 + #define DMAC_MODE_NS (1 << 0) 290 + unsigned int mode; 291 + unsigned int data_bus_width:10; /* In number of bits */ 292 + unsigned int data_buf_dep:10; 293 + unsigned int num_chan:4; 294 + unsigned int num_peri:6; 295 + u32 peri_ns; 296 + unsigned int num_events:6; 297 + u32 irq_ns; 298 + }; 299 + 300 + /* Handle to the DMAC provided to the PL330 core */ 301 + struct pl330_info { 302 + /* Owning device */ 303 + struct device *dev; 304 + /* Size of MicroCode buffers for each channel. */ 305 + unsigned mcbufsz; 306 + /* ioremap'ed address of PL330 registers. */ 307 + void __iomem *base; 308 + /* Client can freely use it. */ 309 + void *client_data; 310 + /* PL330 core data, Client must not touch it. */ 311 + void *pl330_data; 312 + /* Populated by the PL330 core driver during pl330_add */ 313 + struct pl330_config pcfg; 314 + /* 315 + * If the DMAC has some reset mechanism, then the 316 + * client may want to provide pointer to the method. 317 + */ 318 + void (*dmac_reset)(struct pl330_info *pi); 319 + }; 320 + 321 + /** 322 + * Request Configuration. 323 + * The PL330 core does not modify this and uses the last 324 + * working configuration if the request doesn't provide any. 325 + * 326 + * The Client may want to provide this info only for the 327 + * first request and a request with new settings. 328 + */ 329 + struct pl330_reqcfg { 330 + /* Address Incrementing */ 331 + unsigned dst_inc:1; 332 + unsigned src_inc:1; 333 + 334 + /* 335 + * For now, the SRC & DST protection levels 336 + * and burst size/length are assumed same. 337 + */ 338 + bool nonsecure; 339 + bool privileged; 340 + bool insnaccess; 341 + unsigned brst_len:5; 342 + unsigned brst_size:3; /* in power of 2 */ 343 + 344 + enum pl330_dstcachectrl dcctl; 345 + enum pl330_srccachectrl scctl; 346 + enum pl330_byteswap swap; 347 + struct pl330_config *pcfg; 348 + }; 349 + 350 + /* 351 + * One cycle of DMAC operation. 352 + * There may be more than one xfer in a request. 353 + */ 354 + struct pl330_xfer { 355 + u32 src_addr; 356 + u32 dst_addr; 357 + /* Size to xfer */ 358 + u32 bytes; 359 + /* 360 + * Pointer to next xfer in the list. 361 + * The last xfer in the req must point to NULL. 362 + */ 363 + struct pl330_xfer *next; 364 + }; 365 + 366 + /* The xfer callbacks are made with one of these arguments. */ 367 + enum pl330_op_err { 368 + /* The all xfers in the request were success. */ 369 + PL330_ERR_NONE, 370 + /* If req aborted due to global error. */ 371 + PL330_ERR_ABORT, 372 + /* If req failed due to problem with Channel. */ 373 + PL330_ERR_FAIL, 374 + }; 375 + 376 + /* A request defining Scatter-Gather List ending with NULL xfer. */ 377 + struct pl330_req { 378 + enum pl330_reqtype rqtype; 379 + /* Index of peripheral for the xfer. */ 380 + unsigned peri:5; 381 + /* Unique token for this xfer, set by the client. */ 382 + void *token; 383 + /* Callback to be called after xfer. */ 384 + void (*xfer_cb)(void *token, enum pl330_op_err err); 385 + /* If NULL, req will be done at last set parameters. */ 386 + struct pl330_reqcfg *cfg; 387 + /* Pointer to first xfer in the request. */ 388 + struct pl330_xfer *x; 389 + }; 390 + 391 + /* 392 + * To know the status of the channel and DMAC, the client 393 + * provides a pointer to this structure. The PL330 core 394 + * fills it with current information. 395 + */ 396 + struct pl330_chanstatus { 397 + /* 398 + * If the DMAC engine halted due to some error, 399 + * the client should remove-add DMAC. 400 + */ 401 + bool dmac_halted; 402 + /* 403 + * If channel is halted due to some error, 404 + * the client should ABORT/FLUSH and START the channel. 405 + */ 406 + bool faulting; 407 + /* Location of last load */ 408 + u32 src_addr; 409 + /* Location of last store */ 410 + u32 dst_addr; 411 + /* 412 + * Pointer to the currently active req, NULL if channel is 413 + * inactive, even though the requests may be present. 414 + */ 415 + struct pl330_req *top_req; 416 + /* Pointer to req waiting second in the queue if any. */ 417 + struct pl330_req *wait_req; 418 + }; 419 + 420 + enum pl330_chan_op { 421 + /* Start the channel */ 422 + PL330_OP_START, 423 + /* Abort the active xfer */ 424 + PL330_OP_ABORT, 425 + /* Stop xfer and flush queue */ 426 + PL330_OP_FLUSH, 427 + }; 428 + 429 + struct _xfer_spec { 430 + u32 ccr; 431 + struct pl330_req *r; 432 + struct pl330_xfer *x; 433 + }; 434 + 435 + enum dmamov_dst { 436 + SAR = 0, 437 + CCR, 438 + DAR, 439 + }; 440 + 441 + enum pl330_dst { 442 + SRC = 0, 443 + DST, 444 + }; 445 + 446 + enum pl330_cond { 447 + SINGLE, 448 + BURST, 449 + ALWAYS, 450 + }; 451 + 452 + struct _pl330_req { 453 + u32 mc_bus; 454 + void *mc_cpu; 455 + /* Number of bytes taken to setup MC for the req */ 456 + u32 mc_len; 457 + struct pl330_req *r; 458 + /* Hook to attach to DMAC's list of reqs with due callback */ 459 + struct list_head rqd; 460 + }; 461 + 462 + /* ToBeDone for tasklet */ 463 + struct _pl330_tbd { 464 + bool reset_dmac; 465 + bool reset_mngr; 466 + u8 reset_chan; 467 + }; 468 + 469 + /* A DMAC Thread */ 470 + struct pl330_thread { 471 + u8 id; 472 + int ev; 473 + /* If the channel is not yet acquired by any client */ 474 + bool free; 475 + /* Parent DMAC */ 476 + struct pl330_dmac *dmac; 477 + /* Only two at a time */ 478 + struct _pl330_req req[2]; 479 + /* Index of the last enqueued request */ 480 + unsigned lstenq; 481 + /* Index of the last submitted request or -1 if the DMA is stopped */ 482 + int req_running; 483 + }; 484 + 485 + enum pl330_dmac_state { 486 + UNINIT, 487 + INIT, 488 + DYING, 489 + }; 490 + 491 + /* A DMAC */ 492 + struct pl330_dmac { 493 + spinlock_t lock; 494 + /* Holds list of reqs with due callbacks */ 495 + struct list_head req_done; 496 + /* Pointer to platform specific stuff */ 497 + struct pl330_info *pinfo; 498 + /* Maximum possible events/irqs */ 499 + int events[32]; 500 + /* BUS address of MicroCode buffer */ 501 + u32 mcode_bus; 502 + /* CPU address of MicroCode buffer */ 503 + void *mcode_cpu; 504 + /* List of all Channel threads */ 505 + struct pl330_thread *channels; 506 + /* Pointer to the MANAGER thread */ 507 + struct pl330_thread *manager; 508 + /* To handle bad news in interrupt */ 509 + struct tasklet_struct tasks; 510 + struct _pl330_tbd dmac_tbd; 511 + /* State of DMAC operation */ 512 + enum pl330_dmac_state state; 513 + }; 32 514 33 515 enum desc_status { 34 516 /* In the DMAC pool */ ··· 546 50 547 51 /* DMA-Engine Channel */ 548 52 struct dma_chan chan; 549 - 550 - /* Last completed cookie */ 551 - dma_cookie_t completed; 552 53 553 54 /* List of to be xfered descriptors */ 554 55 struct list_head work_list; ··· 609 116 /* The channel which currently holds this desc */ 610 117 struct dma_pl330_chan *pchan; 611 118 }; 119 + 120 + static inline void _callback(struct pl330_req *r, enum pl330_op_err err) 121 + { 122 + if (r && r->xfer_cb) 123 + r->xfer_cb(r->token, err); 124 + } 125 + 126 + static inline bool _queue_empty(struct pl330_thread *thrd) 127 + { 128 + return (IS_FREE(&thrd->req[0]) && IS_FREE(&thrd->req[1])) 129 + ? true : false; 130 + } 131 + 132 + static inline bool _queue_full(struct pl330_thread *thrd) 133 + { 134 + return (IS_FREE(&thrd->req[0]) || IS_FREE(&thrd->req[1])) 135 + ? false : true; 136 + } 137 + 138 + static inline bool is_manager(struct pl330_thread *thrd) 139 + { 140 + struct pl330_dmac *pl330 = thrd->dmac; 141 + 142 + /* MANAGER is indexed at the end */ 143 + if (thrd->id == pl330->pinfo->pcfg.num_chan) 144 + return true; 145 + else 146 + return false; 147 + } 148 + 149 + /* If manager of the thread is in Non-Secure mode */ 150 + static inline bool _manager_ns(struct pl330_thread *thrd) 151 + { 152 + struct pl330_dmac *pl330 = thrd->dmac; 153 + 154 + return (pl330->pinfo->pcfg.mode & DMAC_MODE_NS) ? true : false; 155 + } 156 + 157 + static inline u32 get_id(struct pl330_info *pi, u32 off) 158 + { 159 + void __iomem *regs = pi->base; 160 + u32 id = 0; 161 + 162 + id |= (readb(regs + off + 0x0) << 0); 163 + id |= (readb(regs + off + 0x4) << 8); 164 + id |= (readb(regs + off + 0x8) << 16); 165 + id |= (readb(regs + off + 0xc) << 24); 166 + 167 + return id; 168 + } 169 + 170 + static inline u32 get_revision(u32 periph_id) 171 + { 172 + return (periph_id >> PERIPH_REV_SHIFT) & PERIPH_REV_MASK; 173 + } 174 + 175 + static inline u32 _emit_ADDH(unsigned dry_run, u8 buf[], 176 + enum pl330_dst da, u16 val) 177 + { 178 + if (dry_run) 179 + return SZ_DMAADDH; 180 + 181 + buf[0] = CMD_DMAADDH; 182 + buf[0] |= (da << 1); 183 + *((u16 *)&buf[1]) = val; 184 + 185 + PL330_DBGCMD_DUMP(SZ_DMAADDH, "\tDMAADDH %s %u\n", 186 + da == 1 ? "DA" : "SA", val); 187 + 188 + return SZ_DMAADDH; 189 + } 190 + 191 + static inline u32 _emit_END(unsigned dry_run, u8 buf[]) 192 + { 193 + if (dry_run) 194 + return SZ_DMAEND; 195 + 196 + buf[0] = CMD_DMAEND; 197 + 198 + PL330_DBGCMD_DUMP(SZ_DMAEND, "\tDMAEND\n"); 199 + 200 + return SZ_DMAEND; 201 + } 202 + 203 + static inline u32 _emit_FLUSHP(unsigned dry_run, u8 buf[], u8 peri) 204 + { 205 + if (dry_run) 206 + return SZ_DMAFLUSHP; 207 + 208 + buf[0] = CMD_DMAFLUSHP; 209 + 210 + peri &= 0x1f; 211 + peri <<= 3; 212 + buf[1] = peri; 213 + 214 + PL330_DBGCMD_DUMP(SZ_DMAFLUSHP, "\tDMAFLUSHP %u\n", peri >> 3); 215 + 216 + return SZ_DMAFLUSHP; 217 + } 218 + 219 + static inline u32 _emit_LD(unsigned dry_run, u8 buf[], enum pl330_cond cond) 220 + { 221 + if (dry_run) 222 + return SZ_DMALD; 223 + 224 + buf[0] = CMD_DMALD; 225 + 226 + if (cond == SINGLE) 227 + buf[0] |= (0 << 1) | (1 << 0); 228 + else if (cond == BURST) 229 + buf[0] |= (1 << 1) | (1 << 0); 230 + 231 + PL330_DBGCMD_DUMP(SZ_DMALD, "\tDMALD%c\n", 232 + cond == SINGLE ? 'S' : (cond == BURST ? 'B' : 'A')); 233 + 234 + return SZ_DMALD; 235 + } 236 + 237 + static inline u32 _emit_LDP(unsigned dry_run, u8 buf[], 238 + enum pl330_cond cond, u8 peri) 239 + { 240 + if (dry_run) 241 + return SZ_DMALDP; 242 + 243 + buf[0] = CMD_DMALDP; 244 + 245 + if (cond == BURST) 246 + buf[0] |= (1 << 1); 247 + 248 + peri &= 0x1f; 249 + peri <<= 3; 250 + buf[1] = peri; 251 + 252 + PL330_DBGCMD_DUMP(SZ_DMALDP, "\tDMALDP%c %u\n", 253 + cond == SINGLE ? 'S' : 'B', peri >> 3); 254 + 255 + return SZ_DMALDP; 256 + } 257 + 258 + static inline u32 _emit_LP(unsigned dry_run, u8 buf[], 259 + unsigned loop, u8 cnt) 260 + { 261 + if (dry_run) 262 + return SZ_DMALP; 263 + 264 + buf[0] = CMD_DMALP; 265 + 266 + if (loop) 267 + buf[0] |= (1 << 1); 268 + 269 + cnt--; /* DMAC increments by 1 internally */ 270 + buf[1] = cnt; 271 + 272 + PL330_DBGCMD_DUMP(SZ_DMALP, "\tDMALP_%c %u\n", loop ? '1' : '0', cnt); 273 + 274 + return SZ_DMALP; 275 + } 276 + 277 + struct _arg_LPEND { 278 + enum pl330_cond cond; 279 + bool forever; 280 + unsigned loop; 281 + u8 bjump; 282 + }; 283 + 284 + static inline u32 _emit_LPEND(unsigned dry_run, u8 buf[], 285 + const struct _arg_LPEND *arg) 286 + { 287 + enum pl330_cond cond = arg->cond; 288 + bool forever = arg->forever; 289 + unsigned loop = arg->loop; 290 + u8 bjump = arg->bjump; 291 + 292 + if (dry_run) 293 + return SZ_DMALPEND; 294 + 295 + buf[0] = CMD_DMALPEND; 296 + 297 + if (loop) 298 + buf[0] |= (1 << 2); 299 + 300 + if (!forever) 301 + buf[0] |= (1 << 4); 302 + 303 + if (cond == SINGLE) 304 + buf[0] |= (0 << 1) | (1 << 0); 305 + else if (cond == BURST) 306 + buf[0] |= (1 << 1) | (1 << 0); 307 + 308 + buf[1] = bjump; 309 + 310 + PL330_DBGCMD_DUMP(SZ_DMALPEND, "\tDMALP%s%c_%c bjmpto_%x\n", 311 + forever ? "FE" : "END", 312 + cond == SINGLE ? 'S' : (cond == BURST ? 'B' : 'A'), 313 + loop ? '1' : '0', 314 + bjump); 315 + 316 + return SZ_DMALPEND; 317 + } 318 + 319 + static inline u32 _emit_KILL(unsigned dry_run, u8 buf[]) 320 + { 321 + if (dry_run) 322 + return SZ_DMAKILL; 323 + 324 + buf[0] = CMD_DMAKILL; 325 + 326 + return SZ_DMAKILL; 327 + } 328 + 329 + static inline u32 _emit_MOV(unsigned dry_run, u8 buf[], 330 + enum dmamov_dst dst, u32 val) 331 + { 332 + if (dry_run) 333 + return SZ_DMAMOV; 334 + 335 + buf[0] = CMD_DMAMOV; 336 + buf[1] = dst; 337 + *((u32 *)&buf[2]) = val; 338 + 339 + PL330_DBGCMD_DUMP(SZ_DMAMOV, "\tDMAMOV %s 0x%x\n", 340 + dst == SAR ? "SAR" : (dst == DAR ? "DAR" : "CCR"), val); 341 + 342 + return SZ_DMAMOV; 343 + } 344 + 345 + static inline u32 _emit_NOP(unsigned dry_run, u8 buf[]) 346 + { 347 + if (dry_run) 348 + return SZ_DMANOP; 349 + 350 + buf[0] = CMD_DMANOP; 351 + 352 + PL330_DBGCMD_DUMP(SZ_DMANOP, "\tDMANOP\n"); 353 + 354 + return SZ_DMANOP; 355 + } 356 + 357 + static inline u32 _emit_RMB(unsigned dry_run, u8 buf[]) 358 + { 359 + if (dry_run) 360 + return SZ_DMARMB; 361 + 362 + buf[0] = CMD_DMARMB; 363 + 364 + PL330_DBGCMD_DUMP(SZ_DMARMB, "\tDMARMB\n"); 365 + 366 + return SZ_DMARMB; 367 + } 368 + 369 + static inline u32 _emit_SEV(unsigned dry_run, u8 buf[], u8 ev) 370 + { 371 + if (dry_run) 372 + return SZ_DMASEV; 373 + 374 + buf[0] = CMD_DMASEV; 375 + 376 + ev &= 0x1f; 377 + ev <<= 3; 378 + buf[1] = ev; 379 + 380 + PL330_DBGCMD_DUMP(SZ_DMASEV, "\tDMASEV %u\n", ev >> 3); 381 + 382 + return SZ_DMASEV; 383 + } 384 + 385 + static inline u32 _emit_ST(unsigned dry_run, u8 buf[], enum pl330_cond cond) 386 + { 387 + if (dry_run) 388 + return SZ_DMAST; 389 + 390 + buf[0] = CMD_DMAST; 391 + 392 + if (cond == SINGLE) 393 + buf[0] |= (0 << 1) | (1 << 0); 394 + else if (cond == BURST) 395 + buf[0] |= (1 << 1) | (1 << 0); 396 + 397 + PL330_DBGCMD_DUMP(SZ_DMAST, "\tDMAST%c\n", 398 + cond == SINGLE ? 'S' : (cond == BURST ? 'B' : 'A')); 399 + 400 + return SZ_DMAST; 401 + } 402 + 403 + static inline u32 _emit_STP(unsigned dry_run, u8 buf[], 404 + enum pl330_cond cond, u8 peri) 405 + { 406 + if (dry_run) 407 + return SZ_DMASTP; 408 + 409 + buf[0] = CMD_DMASTP; 410 + 411 + if (cond == BURST) 412 + buf[0] |= (1 << 1); 413 + 414 + peri &= 0x1f; 415 + peri <<= 3; 416 + buf[1] = peri; 417 + 418 + PL330_DBGCMD_DUMP(SZ_DMASTP, "\tDMASTP%c %u\n", 419 + cond == SINGLE ? 'S' : 'B', peri >> 3); 420 + 421 + return SZ_DMASTP; 422 + } 423 + 424 + static inline u32 _emit_STZ(unsigned dry_run, u8 buf[]) 425 + { 426 + if (dry_run) 427 + return SZ_DMASTZ; 428 + 429 + buf[0] = CMD_DMASTZ; 430 + 431 + PL330_DBGCMD_DUMP(SZ_DMASTZ, "\tDMASTZ\n"); 432 + 433 + return SZ_DMASTZ; 434 + } 435 + 436 + static inline u32 _emit_WFE(unsigned dry_run, u8 buf[], u8 ev, 437 + unsigned invalidate) 438 + { 439 + if (dry_run) 440 + return SZ_DMAWFE; 441 + 442 + buf[0] = CMD_DMAWFE; 443 + 444 + ev &= 0x1f; 445 + ev <<= 3; 446 + buf[1] = ev; 447 + 448 + if (invalidate) 449 + buf[1] |= (1 << 1); 450 + 451 + PL330_DBGCMD_DUMP(SZ_DMAWFE, "\tDMAWFE %u%s\n", 452 + ev >> 3, invalidate ? ", I" : ""); 453 + 454 + return SZ_DMAWFE; 455 + } 456 + 457 + static inline u32 _emit_WFP(unsigned dry_run, u8 buf[], 458 + enum pl330_cond cond, u8 peri) 459 + { 460 + if (dry_run) 461 + return SZ_DMAWFP; 462 + 463 + buf[0] = CMD_DMAWFP; 464 + 465 + if (cond == SINGLE) 466 + buf[0] |= (0 << 1) | (0 << 0); 467 + else if (cond == BURST) 468 + buf[0] |= (1 << 1) | (0 << 0); 469 + else 470 + buf[0] |= (0 << 1) | (1 << 0); 471 + 472 + peri &= 0x1f; 473 + peri <<= 3; 474 + buf[1] = peri; 475 + 476 + PL330_DBGCMD_DUMP(SZ_DMAWFP, "\tDMAWFP%c %u\n", 477 + cond == SINGLE ? 'S' : (cond == BURST ? 'B' : 'P'), peri >> 3); 478 + 479 + return SZ_DMAWFP; 480 + } 481 + 482 + static inline u32 _emit_WMB(unsigned dry_run, u8 buf[]) 483 + { 484 + if (dry_run) 485 + return SZ_DMAWMB; 486 + 487 + buf[0] = CMD_DMAWMB; 488 + 489 + PL330_DBGCMD_DUMP(SZ_DMAWMB, "\tDMAWMB\n"); 490 + 491 + return SZ_DMAWMB; 492 + } 493 + 494 + struct _arg_GO { 495 + u8 chan; 496 + u32 addr; 497 + unsigned ns; 498 + }; 499 + 500 + static inline u32 _emit_GO(unsigned dry_run, u8 buf[], 501 + const struct _arg_GO *arg) 502 + { 503 + u8 chan = arg->chan; 504 + u32 addr = arg->addr; 505 + unsigned ns = arg->ns; 506 + 507 + if (dry_run) 508 + return SZ_DMAGO; 509 + 510 + buf[0] = CMD_DMAGO; 511 + buf[0] |= (ns << 1); 512 + 513 + buf[1] = chan & 0x7; 514 + 515 + *((u32 *)&buf[2]) = addr; 516 + 517 + return SZ_DMAGO; 518 + } 519 + 520 + #define msecs_to_loops(t) (loops_per_jiffy / 1000 * HZ * t) 521 + 522 + /* Returns Time-Out */ 523 + static bool _until_dmac_idle(struct pl330_thread *thrd) 524 + { 525 + void __iomem *regs = thrd->dmac->pinfo->base; 526 + unsigned long loops = msecs_to_loops(5); 527 + 528 + do { 529 + /* Until Manager is Idle */ 530 + if (!(readl(regs + DBGSTATUS) & DBG_BUSY)) 531 + break; 532 + 533 + cpu_relax(); 534 + } while (--loops); 535 + 536 + if (!loops) 537 + return true; 538 + 539 + return false; 540 + } 541 + 542 + static inline void _execute_DBGINSN(struct pl330_thread *thrd, 543 + u8 insn[], bool as_manager) 544 + { 545 + void __iomem *regs = thrd->dmac->pinfo->base; 546 + u32 val; 547 + 548 + val = (insn[0] << 16) | (insn[1] << 24); 549 + if (!as_manager) { 550 + val |= (1 << 0); 551 + val |= (thrd->id << 8); /* Channel Number */ 552 + } 553 + writel(val, regs + DBGINST0); 554 + 555 + val = *((u32 *)&insn[2]); 556 + writel(val, regs + DBGINST1); 557 + 558 + /* If timed out due to halted state-machine */ 559 + if (_until_dmac_idle(thrd)) { 560 + dev_err(thrd->dmac->pinfo->dev, "DMAC halted!\n"); 561 + return; 562 + } 563 + 564 + /* Get going */ 565 + writel(0, regs + DBGCMD); 566 + } 567 + 568 + /* 569 + * Mark a _pl330_req as free. 570 + * We do it by writing DMAEND as the first instruction 571 + * because no valid request is going to have DMAEND as 572 + * its first instruction to execute. 573 + */ 574 + static void mark_free(struct pl330_thread *thrd, int idx) 575 + { 576 + struct _pl330_req *req = &thrd->req[idx]; 577 + 578 + _emit_END(0, req->mc_cpu); 579 + req->mc_len = 0; 580 + 581 + thrd->req_running = -1; 582 + } 583 + 584 + static inline u32 _state(struct pl330_thread *thrd) 585 + { 586 + void __iomem *regs = thrd->dmac->pinfo->base; 587 + u32 val; 588 + 589 + if (is_manager(thrd)) 590 + val = readl(regs + DS) & 0xf; 591 + else 592 + val = readl(regs + CS(thrd->id)) & 0xf; 593 + 594 + switch (val) { 595 + case DS_ST_STOP: 596 + return PL330_STATE_STOPPED; 597 + case DS_ST_EXEC: 598 + return PL330_STATE_EXECUTING; 599 + case DS_ST_CMISS: 600 + return PL330_STATE_CACHEMISS; 601 + case DS_ST_UPDTPC: 602 + return PL330_STATE_UPDTPC; 603 + case DS_ST_WFE: 604 + return PL330_STATE_WFE; 605 + case DS_ST_FAULT: 606 + return PL330_STATE_FAULTING; 607 + case DS_ST_ATBRR: 608 + if (is_manager(thrd)) 609 + return PL330_STATE_INVALID; 610 + else 611 + return PL330_STATE_ATBARRIER; 612 + case DS_ST_QBUSY: 613 + if (is_manager(thrd)) 614 + return PL330_STATE_INVALID; 615 + else 616 + return PL330_STATE_QUEUEBUSY; 617 + case DS_ST_WFP: 618 + if (is_manager(thrd)) 619 + return PL330_STATE_INVALID; 620 + else 621 + return PL330_STATE_WFP; 622 + case DS_ST_KILL: 623 + if (is_manager(thrd)) 624 + return PL330_STATE_INVALID; 625 + else 626 + return PL330_STATE_KILLING; 627 + case DS_ST_CMPLT: 628 + if (is_manager(thrd)) 629 + return PL330_STATE_INVALID; 630 + else 631 + return PL330_STATE_COMPLETING; 632 + case DS_ST_FLTCMP: 633 + if (is_manager(thrd)) 634 + return PL330_STATE_INVALID; 635 + else 636 + return PL330_STATE_FAULT_COMPLETING; 637 + default: 638 + return PL330_STATE_INVALID; 639 + } 640 + } 641 + 642 + static void _stop(struct pl330_thread *thrd) 643 + { 644 + void __iomem *regs = thrd->dmac->pinfo->base; 645 + u8 insn[6] = {0, 0, 0, 0, 0, 0}; 646 + 647 + if (_state(thrd) == PL330_STATE_FAULT_COMPLETING) 648 + UNTIL(thrd, PL330_STATE_FAULTING | PL330_STATE_KILLING); 649 + 650 + /* Return if nothing needs to be done */ 651 + if (_state(thrd) == PL330_STATE_COMPLETING 652 + || _state(thrd) == PL330_STATE_KILLING 653 + || _state(thrd) == PL330_STATE_STOPPED) 654 + return; 655 + 656 + _emit_KILL(0, insn); 657 + 658 + /* Stop generating interrupts for SEV */ 659 + writel(readl(regs + INTEN) & ~(1 << thrd->ev), regs + INTEN); 660 + 661 + _execute_DBGINSN(thrd, insn, is_manager(thrd)); 662 + } 663 + 664 + /* Start doing req 'idx' of thread 'thrd' */ 665 + static bool _trigger(struct pl330_thread *thrd) 666 + { 667 + void __iomem *regs = thrd->dmac->pinfo->base; 668 + struct _pl330_req *req; 669 + struct pl330_req *r; 670 + struct _arg_GO go; 671 + unsigned ns; 672 + u8 insn[6] = {0, 0, 0, 0, 0, 0}; 673 + int idx; 674 + 675 + /* Return if already ACTIVE */ 676 + if (_state(thrd) != PL330_STATE_STOPPED) 677 + return true; 678 + 679 + idx = 1 - thrd->lstenq; 680 + if (!IS_FREE(&thrd->req[idx])) 681 + req = &thrd->req[idx]; 682 + else { 683 + idx = thrd->lstenq; 684 + if (!IS_FREE(&thrd->req[idx])) 685 + req = &thrd->req[idx]; 686 + else 687 + req = NULL; 688 + } 689 + 690 + /* Return if no request */ 691 + if (!req || !req->r) 692 + return true; 693 + 694 + r = req->r; 695 + 696 + if (r->cfg) 697 + ns = r->cfg->nonsecure ? 1 : 0; 698 + else if (readl(regs + CS(thrd->id)) & CS_CNS) 699 + ns = 1; 700 + else 701 + ns = 0; 702 + 703 + /* See 'Abort Sources' point-4 at Page 2-25 */ 704 + if (_manager_ns(thrd) && !ns) 705 + dev_info(thrd->dmac->pinfo->dev, "%s:%d Recipe for ABORT!\n", 706 + __func__, __LINE__); 707 + 708 + go.chan = thrd->id; 709 + go.addr = req->mc_bus; 710 + go.ns = ns; 711 + _emit_GO(0, insn, &go); 712 + 713 + /* Set to generate interrupts for SEV */ 714 + writel(readl(regs + INTEN) | (1 << thrd->ev), regs + INTEN); 715 + 716 + /* Only manager can execute GO */ 717 + _execute_DBGINSN(thrd, insn, true); 718 + 719 + thrd->req_running = idx; 720 + 721 + return true; 722 + } 723 + 724 + static bool _start(struct pl330_thread *thrd) 725 + { 726 + switch (_state(thrd)) { 727 + case PL330_STATE_FAULT_COMPLETING: 728 + UNTIL(thrd, PL330_STATE_FAULTING | PL330_STATE_KILLING); 729 + 730 + if (_state(thrd) == PL330_STATE_KILLING) 731 + UNTIL(thrd, PL330_STATE_STOPPED) 732 + 733 + case PL330_STATE_FAULTING: 734 + _stop(thrd); 735 + 736 + case PL330_STATE_KILLING: 737 + case PL330_STATE_COMPLETING: 738 + UNTIL(thrd, PL330_STATE_STOPPED) 739 + 740 + case PL330_STATE_STOPPED: 741 + return _trigger(thrd); 742 + 743 + case PL330_STATE_WFP: 744 + case PL330_STATE_QUEUEBUSY: 745 + case PL330_STATE_ATBARRIER: 746 + case PL330_STATE_UPDTPC: 747 + case PL330_STATE_CACHEMISS: 748 + case PL330_STATE_EXECUTING: 749 + return true; 750 + 751 + case PL330_STATE_WFE: /* For RESUME, nothing yet */ 752 + default: 753 + return false; 754 + } 755 + } 756 + 757 + static inline int _ldst_memtomem(unsigned dry_run, u8 buf[], 758 + const struct _xfer_spec *pxs, int cyc) 759 + { 760 + int off = 0; 761 + struct pl330_config *pcfg = pxs->r->cfg->pcfg; 762 + 763 + /* check lock-up free version */ 764 + if (get_revision(pcfg->periph_id) >= PERIPH_REV_R1P0) { 765 + while (cyc--) { 766 + off += _emit_LD(dry_run, &buf[off], ALWAYS); 767 + off += _emit_ST(dry_run, &buf[off], ALWAYS); 768 + } 769 + } else { 770 + while (cyc--) { 771 + off += _emit_LD(dry_run, &buf[off], ALWAYS); 772 + off += _emit_RMB(dry_run, &buf[off]); 773 + off += _emit_ST(dry_run, &buf[off], ALWAYS); 774 + off += _emit_WMB(dry_run, &buf[off]); 775 + } 776 + } 777 + 778 + return off; 779 + } 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 + 786 + while (cyc--) { 787 + off += _emit_WFP(dry_run, &buf[off], SINGLE, pxs->r->peri); 788 + off += _emit_LDP(dry_run, &buf[off], SINGLE, pxs->r->peri); 789 + off += _emit_ST(dry_run, &buf[off], ALWAYS); 790 + off += _emit_FLUSHP(dry_run, &buf[off], pxs->r->peri); 791 + } 792 + 793 + return off; 794 + } 795 + 796 + static inline int _ldst_memtodev(unsigned dry_run, u8 buf[], 797 + const struct _xfer_spec *pxs, int cyc) 798 + { 799 + int off = 0; 800 + 801 + while (cyc--) { 802 + off += _emit_WFP(dry_run, &buf[off], SINGLE, pxs->r->peri); 803 + off += _emit_LD(dry_run, &buf[off], ALWAYS); 804 + off += _emit_STP(dry_run, &buf[off], SINGLE, pxs->r->peri); 805 + off += _emit_FLUSHP(dry_run, &buf[off], pxs->r->peri); 806 + } 807 + 808 + return off; 809 + } 810 + 811 + static int _bursts(unsigned dry_run, u8 buf[], 812 + const struct _xfer_spec *pxs, int cyc) 813 + { 814 + int off = 0; 815 + 816 + switch (pxs->r->rqtype) { 817 + case MEMTODEV: 818 + off += _ldst_memtodev(dry_run, &buf[off], pxs, cyc); 819 + break; 820 + case DEVTOMEM: 821 + off += _ldst_devtomem(dry_run, &buf[off], pxs, cyc); 822 + break; 823 + case MEMTOMEM: 824 + off += _ldst_memtomem(dry_run, &buf[off], pxs, cyc); 825 + break; 826 + default: 827 + off += 0x40000000; /* Scare off the Client */ 828 + break; 829 + } 830 + 831 + return off; 832 + } 833 + 834 + /* Returns bytes consumed and updates bursts */ 835 + static inline int _loop(unsigned dry_run, u8 buf[], 836 + unsigned long *bursts, const struct _xfer_spec *pxs) 837 + { 838 + int cyc, cycmax, szlp, szlpend, szbrst, off; 839 + unsigned lcnt0, lcnt1, ljmp0, ljmp1; 840 + struct _arg_LPEND lpend; 841 + 842 + /* Max iterations possible in DMALP is 256 */ 843 + if (*bursts >= 256*256) { 844 + lcnt1 = 256; 845 + lcnt0 = 256; 846 + cyc = *bursts / lcnt1 / lcnt0; 847 + } else if (*bursts > 256) { 848 + lcnt1 = 256; 849 + lcnt0 = *bursts / lcnt1; 850 + cyc = 1; 851 + } else { 852 + lcnt1 = *bursts; 853 + lcnt0 = 0; 854 + cyc = 1; 855 + } 856 + 857 + szlp = _emit_LP(1, buf, 0, 0); 858 + szbrst = _bursts(1, buf, pxs, 1); 859 + 860 + lpend.cond = ALWAYS; 861 + lpend.forever = false; 862 + lpend.loop = 0; 863 + lpend.bjump = 0; 864 + szlpend = _emit_LPEND(1, buf, &lpend); 865 + 866 + if (lcnt0) { 867 + szlp *= 2; 868 + szlpend *= 2; 869 + } 870 + 871 + /* 872 + * Max bursts that we can unroll due to limit on the 873 + * size of backward jump that can be encoded in DMALPEND 874 + * which is 8-bits and hence 255 875 + */ 876 + cycmax = (255 - (szlp + szlpend)) / szbrst; 877 + 878 + cyc = (cycmax < cyc) ? cycmax : cyc; 879 + 880 + off = 0; 881 + 882 + if (lcnt0) { 883 + off += _emit_LP(dry_run, &buf[off], 0, lcnt0); 884 + ljmp0 = off; 885 + } 886 + 887 + off += _emit_LP(dry_run, &buf[off], 1, lcnt1); 888 + ljmp1 = off; 889 + 890 + off += _bursts(dry_run, &buf[off], pxs, cyc); 891 + 892 + lpend.cond = ALWAYS; 893 + lpend.forever = false; 894 + lpend.loop = 1; 895 + lpend.bjump = off - ljmp1; 896 + off += _emit_LPEND(dry_run, &buf[off], &lpend); 897 + 898 + if (lcnt0) { 899 + lpend.cond = ALWAYS; 900 + lpend.forever = false; 901 + lpend.loop = 0; 902 + lpend.bjump = off - ljmp0; 903 + off += _emit_LPEND(dry_run, &buf[off], &lpend); 904 + } 905 + 906 + *bursts = lcnt1 * cyc; 907 + if (lcnt0) 908 + *bursts *= lcnt0; 909 + 910 + return off; 911 + } 912 + 913 + static inline int _setup_loops(unsigned dry_run, u8 buf[], 914 + const struct _xfer_spec *pxs) 915 + { 916 + struct pl330_xfer *x = pxs->x; 917 + u32 ccr = pxs->ccr; 918 + unsigned long c, bursts = BYTE_TO_BURST(x->bytes, ccr); 919 + int off = 0; 920 + 921 + while (bursts) { 922 + c = bursts; 923 + off += _loop(dry_run, &buf[off], &c, pxs); 924 + bursts -= c; 925 + } 926 + 927 + return off; 928 + } 929 + 930 + static inline int _setup_xfer(unsigned dry_run, u8 buf[], 931 + const struct _xfer_spec *pxs) 932 + { 933 + struct pl330_xfer *x = pxs->x; 934 + int off = 0; 935 + 936 + /* DMAMOV SAR, x->src_addr */ 937 + off += _emit_MOV(dry_run, &buf[off], SAR, x->src_addr); 938 + /* DMAMOV DAR, x->dst_addr */ 939 + off += _emit_MOV(dry_run, &buf[off], DAR, x->dst_addr); 940 + 941 + /* Setup Loop(s) */ 942 + off += _setup_loops(dry_run, &buf[off], pxs); 943 + 944 + return off; 945 + } 946 + 947 + /* 948 + * A req is a sequence of one or more xfer units. 949 + * Returns the number of bytes taken to setup the MC for the req. 950 + */ 951 + static int _setup_req(unsigned dry_run, struct pl330_thread *thrd, 952 + unsigned index, struct _xfer_spec *pxs) 953 + { 954 + struct _pl330_req *req = &thrd->req[index]; 955 + struct pl330_xfer *x; 956 + u8 *buf = req->mc_cpu; 957 + int off = 0; 958 + 959 + PL330_DBGMC_START(req->mc_bus); 960 + 961 + /* DMAMOV CCR, ccr */ 962 + off += _emit_MOV(dry_run, &buf[off], CCR, pxs->ccr); 963 + 964 + x = pxs->r->x; 965 + do { 966 + /* Error if xfer length is not aligned at burst size */ 967 + if (x->bytes % (BRST_SIZE(pxs->ccr) * BRST_LEN(pxs->ccr))) 968 + return -EINVAL; 969 + 970 + pxs->x = x; 971 + off += _setup_xfer(dry_run, &buf[off], pxs); 972 + 973 + x = x->next; 974 + } while (x); 975 + 976 + /* DMASEV peripheral/event */ 977 + off += _emit_SEV(dry_run, &buf[off], thrd->ev); 978 + /* DMAEND */ 979 + off += _emit_END(dry_run, &buf[off]); 980 + 981 + return off; 982 + } 983 + 984 + static inline u32 _prepare_ccr(const struct pl330_reqcfg *rqc) 985 + { 986 + u32 ccr = 0; 987 + 988 + if (rqc->src_inc) 989 + ccr |= CC_SRCINC; 990 + 991 + if (rqc->dst_inc) 992 + ccr |= CC_DSTINC; 993 + 994 + /* We set same protection levels for Src and DST for now */ 995 + if (rqc->privileged) 996 + ccr |= CC_SRCPRI | CC_DSTPRI; 997 + if (rqc->nonsecure) 998 + ccr |= CC_SRCNS | CC_DSTNS; 999 + if (rqc->insnaccess) 1000 + ccr |= CC_SRCIA | CC_DSTIA; 1001 + 1002 + ccr |= (((rqc->brst_len - 1) & 0xf) << CC_SRCBRSTLEN_SHFT); 1003 + ccr |= (((rqc->brst_len - 1) & 0xf) << CC_DSTBRSTLEN_SHFT); 1004 + 1005 + ccr |= (rqc->brst_size << CC_SRCBRSTSIZE_SHFT); 1006 + ccr |= (rqc->brst_size << CC_DSTBRSTSIZE_SHFT); 1007 + 1008 + ccr |= (rqc->scctl << CC_SRCCCTRL_SHFT); 1009 + ccr |= (rqc->dcctl << CC_DSTCCTRL_SHFT); 1010 + 1011 + ccr |= (rqc->swap << CC_SWAP_SHFT); 1012 + 1013 + return ccr; 1014 + } 1015 + 1016 + static inline bool _is_valid(u32 ccr) 1017 + { 1018 + enum pl330_dstcachectrl dcctl; 1019 + enum pl330_srccachectrl scctl; 1020 + 1021 + dcctl = (ccr >> CC_DSTCCTRL_SHFT) & CC_DRCCCTRL_MASK; 1022 + scctl = (ccr >> CC_SRCCCTRL_SHFT) & CC_SRCCCTRL_MASK; 1023 + 1024 + if (dcctl == DINVALID1 || dcctl == DINVALID2 1025 + || scctl == SINVALID1 || scctl == SINVALID2) 1026 + return false; 1027 + else 1028 + return true; 1029 + } 1030 + 1031 + /* 1032 + * Submit a list of xfers after which the client wants notification. 1033 + * Client is not notified after each xfer unit, just once after all 1034 + * xfer units are done or some error occurs. 1035 + */ 1036 + static int pl330_submit_req(void *ch_id, struct pl330_req *r) 1037 + { 1038 + struct pl330_thread *thrd = ch_id; 1039 + struct pl330_dmac *pl330; 1040 + struct pl330_info *pi; 1041 + struct _xfer_spec xs; 1042 + unsigned long flags; 1043 + void __iomem *regs; 1044 + unsigned idx; 1045 + u32 ccr; 1046 + int ret = 0; 1047 + 1048 + /* No Req or Unacquired Channel or DMAC */ 1049 + if (!r || !thrd || thrd->free) 1050 + return -EINVAL; 1051 + 1052 + pl330 = thrd->dmac; 1053 + pi = pl330->pinfo; 1054 + regs = pi->base; 1055 + 1056 + if (pl330->state == DYING 1057 + || pl330->dmac_tbd.reset_chan & (1 << thrd->id)) { 1058 + dev_info(thrd->dmac->pinfo->dev, "%s:%d\n", 1059 + __func__, __LINE__); 1060 + return -EAGAIN; 1061 + } 1062 + 1063 + /* If request for non-existing peripheral */ 1064 + if (r->rqtype != MEMTOMEM && r->peri >= pi->pcfg.num_peri) { 1065 + dev_info(thrd->dmac->pinfo->dev, 1066 + "%s:%d Invalid peripheral(%u)!\n", 1067 + __func__, __LINE__, r->peri); 1068 + return -EINVAL; 1069 + } 1070 + 1071 + spin_lock_irqsave(&pl330->lock, flags); 1072 + 1073 + if (_queue_full(thrd)) { 1074 + ret = -EAGAIN; 1075 + goto xfer_exit; 1076 + } 1077 + 1078 + /* Prefer Secure Channel */ 1079 + if (!_manager_ns(thrd)) 1080 + r->cfg->nonsecure = 0; 1081 + else 1082 + r->cfg->nonsecure = 1; 1083 + 1084 + /* Use last settings, if not provided */ 1085 + if (r->cfg) 1086 + ccr = _prepare_ccr(r->cfg); 1087 + else 1088 + ccr = readl(regs + CC(thrd->id)); 1089 + 1090 + /* If this req doesn't have valid xfer settings */ 1091 + if (!_is_valid(ccr)) { 1092 + ret = -EINVAL; 1093 + dev_info(thrd->dmac->pinfo->dev, "%s:%d Invalid CCR(%x)!\n", 1094 + __func__, __LINE__, ccr); 1095 + goto xfer_exit; 1096 + } 1097 + 1098 + idx = IS_FREE(&thrd->req[0]) ? 0 : 1; 1099 + 1100 + xs.ccr = ccr; 1101 + xs.r = r; 1102 + 1103 + /* First dry run to check if req is acceptable */ 1104 + ret = _setup_req(1, thrd, idx, &xs); 1105 + if (ret < 0) 1106 + goto xfer_exit; 1107 + 1108 + if (ret > pi->mcbufsz / 2) { 1109 + dev_info(thrd->dmac->pinfo->dev, 1110 + "%s:%d Trying increasing mcbufsz\n", 1111 + __func__, __LINE__); 1112 + ret = -ENOMEM; 1113 + goto xfer_exit; 1114 + } 1115 + 1116 + /* Hook the request */ 1117 + thrd->lstenq = idx; 1118 + thrd->req[idx].mc_len = _setup_req(0, thrd, idx, &xs); 1119 + thrd->req[idx].r = r; 1120 + 1121 + ret = 0; 1122 + 1123 + xfer_exit: 1124 + spin_unlock_irqrestore(&pl330->lock, flags); 1125 + 1126 + return ret; 1127 + } 1128 + 1129 + static void pl330_dotask(unsigned long data) 1130 + { 1131 + struct pl330_dmac *pl330 = (struct pl330_dmac *) data; 1132 + struct pl330_info *pi = pl330->pinfo; 1133 + unsigned long flags; 1134 + int i; 1135 + 1136 + spin_lock_irqsave(&pl330->lock, flags); 1137 + 1138 + /* The DMAC itself gone nuts */ 1139 + if (pl330->dmac_tbd.reset_dmac) { 1140 + pl330->state = DYING; 1141 + /* Reset the manager too */ 1142 + pl330->dmac_tbd.reset_mngr = true; 1143 + /* Clear the reset flag */ 1144 + pl330->dmac_tbd.reset_dmac = false; 1145 + } 1146 + 1147 + if (pl330->dmac_tbd.reset_mngr) { 1148 + _stop(pl330->manager); 1149 + /* Reset all channels */ 1150 + pl330->dmac_tbd.reset_chan = (1 << pi->pcfg.num_chan) - 1; 1151 + /* Clear the reset flag */ 1152 + pl330->dmac_tbd.reset_mngr = false; 1153 + } 1154 + 1155 + for (i = 0; i < pi->pcfg.num_chan; i++) { 1156 + 1157 + if (pl330->dmac_tbd.reset_chan & (1 << i)) { 1158 + struct pl330_thread *thrd = &pl330->channels[i]; 1159 + void __iomem *regs = pi->base; 1160 + enum pl330_op_err err; 1161 + 1162 + _stop(thrd); 1163 + 1164 + if (readl(regs + FSC) & (1 << thrd->id)) 1165 + err = PL330_ERR_FAIL; 1166 + else 1167 + err = PL330_ERR_ABORT; 1168 + 1169 + spin_unlock_irqrestore(&pl330->lock, flags); 1170 + 1171 + _callback(thrd->req[1 - thrd->lstenq].r, err); 1172 + _callback(thrd->req[thrd->lstenq].r, err); 1173 + 1174 + spin_lock_irqsave(&pl330->lock, flags); 1175 + 1176 + thrd->req[0].r = NULL; 1177 + thrd->req[1].r = NULL; 1178 + mark_free(thrd, 0); 1179 + mark_free(thrd, 1); 1180 + 1181 + /* Clear the reset flag */ 1182 + pl330->dmac_tbd.reset_chan &= ~(1 << i); 1183 + } 1184 + } 1185 + 1186 + spin_unlock_irqrestore(&pl330->lock, flags); 1187 + 1188 + return; 1189 + } 1190 + 1191 + /* Returns 1 if state was updated, 0 otherwise */ 1192 + static int pl330_update(const struct pl330_info *pi) 1193 + { 1194 + struct _pl330_req *rqdone; 1195 + struct pl330_dmac *pl330; 1196 + unsigned long flags; 1197 + void __iomem *regs; 1198 + u32 val; 1199 + int id, ev, ret = 0; 1200 + 1201 + if (!pi || !pi->pl330_data) 1202 + return 0; 1203 + 1204 + regs = pi->base; 1205 + pl330 = pi->pl330_data; 1206 + 1207 + spin_lock_irqsave(&pl330->lock, flags); 1208 + 1209 + val = readl(regs + FSM) & 0x1; 1210 + if (val) 1211 + pl330->dmac_tbd.reset_mngr = true; 1212 + else 1213 + pl330->dmac_tbd.reset_mngr = false; 1214 + 1215 + val = readl(regs + FSC) & ((1 << pi->pcfg.num_chan) - 1); 1216 + pl330->dmac_tbd.reset_chan |= val; 1217 + if (val) { 1218 + int i = 0; 1219 + while (i < pi->pcfg.num_chan) { 1220 + if (val & (1 << i)) { 1221 + dev_info(pi->dev, 1222 + "Reset Channel-%d\t CS-%x FTC-%x\n", 1223 + i, readl(regs + CS(i)), 1224 + readl(regs + FTC(i))); 1225 + _stop(&pl330->channels[i]); 1226 + } 1227 + i++; 1228 + } 1229 + } 1230 + 1231 + /* Check which event happened i.e, thread notified */ 1232 + val = readl(regs + ES); 1233 + if (pi->pcfg.num_events < 32 1234 + && val & ~((1 << pi->pcfg.num_events) - 1)) { 1235 + pl330->dmac_tbd.reset_dmac = true; 1236 + dev_err(pi->dev, "%s:%d Unexpected!\n", __func__, __LINE__); 1237 + ret = 1; 1238 + goto updt_exit; 1239 + } 1240 + 1241 + for (ev = 0; ev < pi->pcfg.num_events; ev++) { 1242 + if (val & (1 << ev)) { /* Event occurred */ 1243 + struct pl330_thread *thrd; 1244 + u32 inten = readl(regs + INTEN); 1245 + int active; 1246 + 1247 + /* Clear the event */ 1248 + if (inten & (1 << ev)) 1249 + writel(1 << ev, regs + INTCLR); 1250 + 1251 + ret = 1; 1252 + 1253 + id = pl330->events[ev]; 1254 + 1255 + thrd = &pl330->channels[id]; 1256 + 1257 + active = thrd->req_running; 1258 + if (active == -1) /* Aborted */ 1259 + continue; 1260 + 1261 + rqdone = &thrd->req[active]; 1262 + mark_free(thrd, active); 1263 + 1264 + /* Get going again ASAP */ 1265 + _start(thrd); 1266 + 1267 + /* For now, just make a list of callbacks to be done */ 1268 + list_add_tail(&rqdone->rqd, &pl330->req_done); 1269 + } 1270 + } 1271 + 1272 + /* Now that we are in no hurry, do the callbacks */ 1273 + while (!list_empty(&pl330->req_done)) { 1274 + struct pl330_req *r; 1275 + 1276 + rqdone = container_of(pl330->req_done.next, 1277 + struct _pl330_req, rqd); 1278 + 1279 + list_del_init(&rqdone->rqd); 1280 + 1281 + /* Detach the req */ 1282 + r = rqdone->r; 1283 + rqdone->r = NULL; 1284 + 1285 + spin_unlock_irqrestore(&pl330->lock, flags); 1286 + _callback(r, PL330_ERR_NONE); 1287 + spin_lock_irqsave(&pl330->lock, flags); 1288 + } 1289 + 1290 + updt_exit: 1291 + spin_unlock_irqrestore(&pl330->lock, flags); 1292 + 1293 + if (pl330->dmac_tbd.reset_dmac 1294 + || pl330->dmac_tbd.reset_mngr 1295 + || pl330->dmac_tbd.reset_chan) { 1296 + ret = 1; 1297 + tasklet_schedule(&pl330->tasks); 1298 + } 1299 + 1300 + return ret; 1301 + } 1302 + 1303 + static int pl330_chan_ctrl(void *ch_id, enum pl330_chan_op op) 1304 + { 1305 + struct pl330_thread *thrd = ch_id; 1306 + struct pl330_dmac *pl330; 1307 + unsigned long flags; 1308 + int ret = 0, active; 1309 + 1310 + if (!thrd || thrd->free || thrd->dmac->state == DYING) 1311 + return -EINVAL; 1312 + 1313 + pl330 = thrd->dmac; 1314 + active = thrd->req_running; 1315 + 1316 + spin_lock_irqsave(&pl330->lock, flags); 1317 + 1318 + switch (op) { 1319 + case PL330_OP_FLUSH: 1320 + /* Make sure the channel is stopped */ 1321 + _stop(thrd); 1322 + 1323 + thrd->req[0].r = NULL; 1324 + thrd->req[1].r = NULL; 1325 + mark_free(thrd, 0); 1326 + mark_free(thrd, 1); 1327 + break; 1328 + 1329 + case PL330_OP_ABORT: 1330 + /* Make sure the channel is stopped */ 1331 + _stop(thrd); 1332 + 1333 + /* ABORT is only for the active req */ 1334 + if (active == -1) 1335 + break; 1336 + 1337 + thrd->req[active].r = NULL; 1338 + mark_free(thrd, active); 1339 + 1340 + /* Start the next */ 1341 + case PL330_OP_START: 1342 + if ((active == -1) && !_start(thrd)) 1343 + ret = -EIO; 1344 + break; 1345 + 1346 + default: 1347 + ret = -EINVAL; 1348 + } 1349 + 1350 + spin_unlock_irqrestore(&pl330->lock, flags); 1351 + return ret; 1352 + } 1353 + 1354 + /* Reserve an event */ 1355 + static inline int _alloc_event(struct pl330_thread *thrd) 1356 + { 1357 + struct pl330_dmac *pl330 = thrd->dmac; 1358 + struct pl330_info *pi = pl330->pinfo; 1359 + int ev; 1360 + 1361 + for (ev = 0; ev < pi->pcfg.num_events; ev++) 1362 + if (pl330->events[ev] == -1) { 1363 + pl330->events[ev] = thrd->id; 1364 + return ev; 1365 + } 1366 + 1367 + return -1; 1368 + } 1369 + 1370 + static bool _chan_ns(const struct pl330_info *pi, int i) 1371 + { 1372 + return pi->pcfg.irq_ns & (1 << i); 1373 + } 1374 + 1375 + /* Upon success, returns IdentityToken for the 1376 + * allocated channel, NULL otherwise. 1377 + */ 1378 + static void *pl330_request_channel(const struct pl330_info *pi) 1379 + { 1380 + struct pl330_thread *thrd = NULL; 1381 + struct pl330_dmac *pl330; 1382 + unsigned long flags; 1383 + int chans, i; 1384 + 1385 + if (!pi || !pi->pl330_data) 1386 + return NULL; 1387 + 1388 + pl330 = pi->pl330_data; 1389 + 1390 + if (pl330->state == DYING) 1391 + return NULL; 1392 + 1393 + chans = pi->pcfg.num_chan; 1394 + 1395 + spin_lock_irqsave(&pl330->lock, flags); 1396 + 1397 + for (i = 0; i < chans; i++) { 1398 + thrd = &pl330->channels[i]; 1399 + if ((thrd->free) && (!_manager_ns(thrd) || 1400 + _chan_ns(pi, i))) { 1401 + thrd->ev = _alloc_event(thrd); 1402 + if (thrd->ev >= 0) { 1403 + thrd->free = false; 1404 + thrd->lstenq = 1; 1405 + thrd->req[0].r = NULL; 1406 + mark_free(thrd, 0); 1407 + thrd->req[1].r = NULL; 1408 + mark_free(thrd, 1); 1409 + break; 1410 + } 1411 + } 1412 + thrd = NULL; 1413 + } 1414 + 1415 + spin_unlock_irqrestore(&pl330->lock, flags); 1416 + 1417 + return thrd; 1418 + } 1419 + 1420 + /* Release an event */ 1421 + static inline void _free_event(struct pl330_thread *thrd, int ev) 1422 + { 1423 + struct pl330_dmac *pl330 = thrd->dmac; 1424 + struct pl330_info *pi = pl330->pinfo; 1425 + 1426 + /* If the event is valid and was held by the thread */ 1427 + if (ev >= 0 && ev < pi->pcfg.num_events 1428 + && pl330->events[ev] == thrd->id) 1429 + pl330->events[ev] = -1; 1430 + } 1431 + 1432 + static void pl330_release_channel(void *ch_id) 1433 + { 1434 + struct pl330_thread *thrd = ch_id; 1435 + struct pl330_dmac *pl330; 1436 + unsigned long flags; 1437 + 1438 + if (!thrd || thrd->free) 1439 + return; 1440 + 1441 + _stop(thrd); 1442 + 1443 + _callback(thrd->req[1 - thrd->lstenq].r, PL330_ERR_ABORT); 1444 + _callback(thrd->req[thrd->lstenq].r, PL330_ERR_ABORT); 1445 + 1446 + pl330 = thrd->dmac; 1447 + 1448 + spin_lock_irqsave(&pl330->lock, flags); 1449 + _free_event(thrd, thrd->ev); 1450 + thrd->free = true; 1451 + spin_unlock_irqrestore(&pl330->lock, flags); 1452 + } 1453 + 1454 + /* Initialize the structure for PL330 configuration, that can be used 1455 + * by the client driver the make best use of the DMAC 1456 + */ 1457 + static void read_dmac_config(struct pl330_info *pi) 1458 + { 1459 + void __iomem *regs = pi->base; 1460 + u32 val; 1461 + 1462 + val = readl(regs + CRD) >> CRD_DATA_WIDTH_SHIFT; 1463 + val &= CRD_DATA_WIDTH_MASK; 1464 + pi->pcfg.data_bus_width = 8 * (1 << val); 1465 + 1466 + val = readl(regs + CRD) >> CRD_DATA_BUFF_SHIFT; 1467 + val &= CRD_DATA_BUFF_MASK; 1468 + pi->pcfg.data_buf_dep = val + 1; 1469 + 1470 + val = readl(regs + CR0) >> CR0_NUM_CHANS_SHIFT; 1471 + val &= CR0_NUM_CHANS_MASK; 1472 + val += 1; 1473 + pi->pcfg.num_chan = val; 1474 + 1475 + val = readl(regs + CR0); 1476 + if (val & CR0_PERIPH_REQ_SET) { 1477 + val = (val >> CR0_NUM_PERIPH_SHIFT) & CR0_NUM_PERIPH_MASK; 1478 + val += 1; 1479 + pi->pcfg.num_peri = val; 1480 + pi->pcfg.peri_ns = readl(regs + CR4); 1481 + } else { 1482 + pi->pcfg.num_peri = 0; 1483 + } 1484 + 1485 + val = readl(regs + CR0); 1486 + if (val & CR0_BOOT_MAN_NS) 1487 + pi->pcfg.mode |= DMAC_MODE_NS; 1488 + else 1489 + pi->pcfg.mode &= ~DMAC_MODE_NS; 1490 + 1491 + val = readl(regs + CR0) >> CR0_NUM_EVENTS_SHIFT; 1492 + val &= CR0_NUM_EVENTS_MASK; 1493 + val += 1; 1494 + pi->pcfg.num_events = val; 1495 + 1496 + pi->pcfg.irq_ns = readl(regs + CR3); 1497 + 1498 + pi->pcfg.periph_id = get_id(pi, PERIPH_ID); 1499 + pi->pcfg.pcell_id = get_id(pi, PCELL_ID); 1500 + } 1501 + 1502 + static inline void _reset_thread(struct pl330_thread *thrd) 1503 + { 1504 + struct pl330_dmac *pl330 = thrd->dmac; 1505 + struct pl330_info *pi = pl330->pinfo; 1506 + 1507 + thrd->req[0].mc_cpu = pl330->mcode_cpu 1508 + + (thrd->id * pi->mcbufsz); 1509 + thrd->req[0].mc_bus = pl330->mcode_bus 1510 + + (thrd->id * pi->mcbufsz); 1511 + thrd->req[0].r = NULL; 1512 + mark_free(thrd, 0); 1513 + 1514 + thrd->req[1].mc_cpu = thrd->req[0].mc_cpu 1515 + + pi->mcbufsz / 2; 1516 + thrd->req[1].mc_bus = thrd->req[0].mc_bus 1517 + + pi->mcbufsz / 2; 1518 + thrd->req[1].r = NULL; 1519 + mark_free(thrd, 1); 1520 + } 1521 + 1522 + static int dmac_alloc_threads(struct pl330_dmac *pl330) 1523 + { 1524 + struct pl330_info *pi = pl330->pinfo; 1525 + int chans = pi->pcfg.num_chan; 1526 + struct pl330_thread *thrd; 1527 + int i; 1528 + 1529 + /* Allocate 1 Manager and 'chans' Channel threads */ 1530 + pl330->channels = kzalloc((1 + chans) * sizeof(*thrd), 1531 + GFP_KERNEL); 1532 + if (!pl330->channels) 1533 + return -ENOMEM; 1534 + 1535 + /* Init Channel threads */ 1536 + for (i = 0; i < chans; i++) { 1537 + thrd = &pl330->channels[i]; 1538 + thrd->id = i; 1539 + thrd->dmac = pl330; 1540 + _reset_thread(thrd); 1541 + thrd->free = true; 1542 + } 1543 + 1544 + /* MANAGER is indexed at the end */ 1545 + thrd = &pl330->channels[chans]; 1546 + thrd->id = chans; 1547 + thrd->dmac = pl330; 1548 + thrd->free = false; 1549 + pl330->manager = thrd; 1550 + 1551 + return 0; 1552 + } 1553 + 1554 + static int dmac_alloc_resources(struct pl330_dmac *pl330) 1555 + { 1556 + struct pl330_info *pi = pl330->pinfo; 1557 + int chans = pi->pcfg.num_chan; 1558 + int ret; 1559 + 1560 + /* 1561 + * Alloc MicroCode buffer for 'chans' Channel threads. 1562 + * A channel's buffer offset is (Channel_Id * MCODE_BUFF_PERCHAN) 1563 + */ 1564 + pl330->mcode_cpu = dma_alloc_coherent(pi->dev, 1565 + chans * pi->mcbufsz, 1566 + &pl330->mcode_bus, GFP_KERNEL); 1567 + if (!pl330->mcode_cpu) { 1568 + dev_err(pi->dev, "%s:%d Can't allocate memory!\n", 1569 + __func__, __LINE__); 1570 + return -ENOMEM; 1571 + } 1572 + 1573 + ret = dmac_alloc_threads(pl330); 1574 + if (ret) { 1575 + dev_err(pi->dev, "%s:%d Can't to create channels for DMAC!\n", 1576 + __func__, __LINE__); 1577 + dma_free_coherent(pi->dev, 1578 + chans * pi->mcbufsz, 1579 + pl330->mcode_cpu, pl330->mcode_bus); 1580 + return ret; 1581 + } 1582 + 1583 + return 0; 1584 + } 1585 + 1586 + static int pl330_add(struct pl330_info *pi) 1587 + { 1588 + struct pl330_dmac *pl330; 1589 + void __iomem *regs; 1590 + int i, ret; 1591 + 1592 + if (!pi || !pi->dev) 1593 + return -EINVAL; 1594 + 1595 + /* If already added */ 1596 + if (pi->pl330_data) 1597 + return -EINVAL; 1598 + 1599 + /* 1600 + * If the SoC can perform reset on the DMAC, then do it 1601 + * before reading its configuration. 1602 + */ 1603 + if (pi->dmac_reset) 1604 + pi->dmac_reset(pi); 1605 + 1606 + regs = pi->base; 1607 + 1608 + /* Check if we can handle this DMAC */ 1609 + if ((get_id(pi, PERIPH_ID) & 0xfffff) != PERIPH_ID_VAL 1610 + || get_id(pi, PCELL_ID) != PCELL_ID_VAL) { 1611 + dev_err(pi->dev, "PERIPH_ID 0x%x, PCELL_ID 0x%x !\n", 1612 + get_id(pi, PERIPH_ID), get_id(pi, PCELL_ID)); 1613 + return -EINVAL; 1614 + } 1615 + 1616 + /* Read the configuration of the DMAC */ 1617 + read_dmac_config(pi); 1618 + 1619 + if (pi->pcfg.num_events == 0) { 1620 + dev_err(pi->dev, "%s:%d Can't work without events!\n", 1621 + __func__, __LINE__); 1622 + return -EINVAL; 1623 + } 1624 + 1625 + pl330 = kzalloc(sizeof(*pl330), GFP_KERNEL); 1626 + if (!pl330) { 1627 + dev_err(pi->dev, "%s:%d Can't allocate memory!\n", 1628 + __func__, __LINE__); 1629 + return -ENOMEM; 1630 + } 1631 + 1632 + /* Assign the info structure and private data */ 1633 + pl330->pinfo = pi; 1634 + pi->pl330_data = pl330; 1635 + 1636 + spin_lock_init(&pl330->lock); 1637 + 1638 + INIT_LIST_HEAD(&pl330->req_done); 1639 + 1640 + /* Use default MC buffer size if not provided */ 1641 + if (!pi->mcbufsz) 1642 + pi->mcbufsz = MCODE_BUFF_PER_REQ * 2; 1643 + 1644 + /* Mark all events as free */ 1645 + for (i = 0; i < pi->pcfg.num_events; i++) 1646 + pl330->events[i] = -1; 1647 + 1648 + /* Allocate resources needed by the DMAC */ 1649 + ret = dmac_alloc_resources(pl330); 1650 + if (ret) { 1651 + dev_err(pi->dev, "Unable to create channels for DMAC\n"); 1652 + kfree(pl330); 1653 + return ret; 1654 + } 1655 + 1656 + tasklet_init(&pl330->tasks, pl330_dotask, (unsigned long) pl330); 1657 + 1658 + pl330->state = INIT; 1659 + 1660 + return 0; 1661 + } 1662 + 1663 + static int dmac_free_threads(struct pl330_dmac *pl330) 1664 + { 1665 + struct pl330_info *pi = pl330->pinfo; 1666 + int chans = pi->pcfg.num_chan; 1667 + struct pl330_thread *thrd; 1668 + int i; 1669 + 1670 + /* Release Channel threads */ 1671 + for (i = 0; i < chans; i++) { 1672 + thrd = &pl330->channels[i]; 1673 + pl330_release_channel((void *)thrd); 1674 + } 1675 + 1676 + /* Free memory */ 1677 + kfree(pl330->channels); 1678 + 1679 + return 0; 1680 + } 1681 + 1682 + static void dmac_free_resources(struct pl330_dmac *pl330) 1683 + { 1684 + struct pl330_info *pi = pl330->pinfo; 1685 + int chans = pi->pcfg.num_chan; 1686 + 1687 + dmac_free_threads(pl330); 1688 + 1689 + dma_free_coherent(pi->dev, chans * pi->mcbufsz, 1690 + pl330->mcode_cpu, pl330->mcode_bus); 1691 + } 1692 + 1693 + static void pl330_del(struct pl330_info *pi) 1694 + { 1695 + struct pl330_dmac *pl330; 1696 + 1697 + if (!pi || !pi->pl330_data) 1698 + return; 1699 + 1700 + pl330 = pi->pl330_data; 1701 + 1702 + pl330->state = UNINIT; 1703 + 1704 + tasklet_kill(&pl330->tasks); 1705 + 1706 + /* Free DMAC resources */ 1707 + dmac_free_resources(pl330); 1708 + 1709 + kfree(pl330); 1710 + pi->pl330_data = NULL; 1711 + } 612 1712 613 1713 /* forward declaration */ 614 1714 static struct amba_driver pl330_driver; ··· 2320 234 /* Pick up ripe tomatoes */ 2321 235 list_for_each_entry_safe(desc, _dt, &pch->work_list, node) 2322 236 if (desc->status == DONE) { 2323 - pch->completed = desc->txd.cookie; 237 + dma_cookie_complete(&desc->txd); 2324 238 list_move_tail(&desc->node, &list); 2325 239 } 2326 240 ··· 2391 305 2392 306 spin_lock_irqsave(&pch->lock, flags); 2393 307 2394 - pch->completed = chan->cookie = 1; 308 + dma_cookie_init(chan); 2395 309 pch->cyclic = false; 2396 310 2397 311 pch->pl330_chid = pl330_request_channel(&pdmac->pif); ··· 2426 340 /* Mark all desc done */ 2427 341 list_for_each_entry_safe(desc, _dt, &pch->work_list , node) { 2428 342 desc->status = DONE; 2429 - pch->completed = desc->txd.cookie; 2430 343 list_move_tail(&desc->node, &list); 2431 344 } 2432 345 ··· 2481 396 pl330_tx_status(struct dma_chan *chan, dma_cookie_t cookie, 2482 397 struct dma_tx_state *txstate) 2483 398 { 2484 - struct dma_pl330_chan *pch = to_pchan(chan); 2485 - dma_cookie_t last_done, last_used; 2486 - int ret; 2487 - 2488 - last_done = pch->completed; 2489 - last_used = chan->cookie; 2490 - 2491 - ret = dma_async_is_complete(cookie, last_done, last_used); 2492 - 2493 - dma_set_tx_state(txstate, last_done, last_used, 0); 2494 - 2495 - return ret; 399 + return dma_cookie_status(chan, cookie, txstate); 2496 400 } 2497 401 2498 402 static void pl330_issue_pending(struct dma_chan *chan) ··· 2504 430 spin_lock_irqsave(&pch->lock, flags); 2505 431 2506 432 /* Assign cookies to all nodes */ 2507 - cookie = tx->chan->cookie; 2508 - 2509 433 while (!list_empty(&last->node)) { 2510 434 desc = list_entry(last->node.next, struct dma_pl330_desc, node); 2511 435 2512 - if (++cookie < 0) 2513 - cookie = 1; 2514 - desc->txd.cookie = cookie; 436 + dma_cookie_assign(&desc->txd); 2515 437 2516 438 list_move_tail(&desc->node, &pch->work_list); 2517 439 } 2518 440 2519 - if (++cookie < 0) 2520 - cookie = 1; 2521 - last->txd.cookie = cookie; 2522 - 441 + cookie = dma_cookie_assign(&last->txd); 2523 442 list_add_tail(&last->node, &pch->work_list); 2524 - 2525 - tx->chan->cookie = cookie; 2526 - 2527 443 spin_unlock_irqrestore(&pch->lock, flags); 2528 444 2529 445 return cookie; ··· 2617 553 async_tx_ack(&desc->txd); 2618 554 2619 555 desc->req.peri = peri_id ? pch->chan.chan_id : 0; 556 + desc->rqcfg.pcfg = &pch->dmac->pif.pcfg; 2620 557 2621 558 dma_async_tx_descriptor_init(&desc->txd, &pch->chan); 2622 559 ··· 2686 621 2687 622 static struct dma_async_tx_descriptor *pl330_prep_dma_cyclic( 2688 623 struct dma_chan *chan, dma_addr_t dma_addr, size_t len, 2689 - size_t period_len, enum dma_transfer_direction direction) 624 + size_t period_len, enum dma_transfer_direction direction, 625 + void *context) 2690 626 { 2691 627 struct dma_pl330_desc *desc; 2692 628 struct dma_pl330_chan *pch = to_pchan(chan); ··· 2777 711 static struct dma_async_tx_descriptor * 2778 712 pl330_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl, 2779 713 unsigned int sg_len, enum dma_transfer_direction direction, 2780 - unsigned long flg) 714 + unsigned long flg, void *context) 2781 715 { 2782 716 struct dma_pl330_desc *first, *desc = NULL; 2783 717 struct dma_pl330_chan *pch = to_pchan(chan); ··· 2895 829 if (IS_ERR(pdmac->clk)) { 2896 830 dev_err(&adev->dev, "Cannot get operation clock.\n"); 2897 831 ret = -EINVAL; 2898 - goto probe_err1; 832 + goto probe_err2; 2899 833 } 2900 834 2901 835 amba_set_drvdata(adev, pdmac); ··· 2909 843 ret = request_irq(irq, pl330_irq_handler, 0, 2910 844 dev_name(&adev->dev), pi); 2911 845 if (ret) 2912 - goto probe_err2; 846 + goto probe_err3; 2913 847 2914 848 ret = pl330_add(pi); 2915 849 if (ret) 2916 - goto probe_err3; 850 + goto probe_err4; 2917 851 2918 852 INIT_LIST_HEAD(&pdmac->desc_pool); 2919 853 spin_lock_init(&pdmac->pool_lock); ··· 2970 904 ret = dma_async_device_register(pd); 2971 905 if (ret) { 2972 906 dev_err(&adev->dev, "unable to register DMAC\n"); 2973 - goto probe_err4; 907 + goto probe_err5; 2974 908 } 2975 909 2976 910 dev_info(&adev->dev, ··· 2983 917 2984 918 return 0; 2985 919 2986 - probe_err4: 920 + probe_err5: 2987 921 pl330_del(pi); 2988 - probe_err3: 922 + probe_err4: 2989 923 free_irq(irq, pi); 924 + probe_err3: 925 + #ifndef CONFIG_PM_RUNTIME 926 + clk_disable(pdmac->clk); 927 + #endif 928 + clk_put(pdmac->clk); 2990 929 probe_err2: 2991 930 iounmap(pi->base); 2992 931 probe_err1:
+9 -40
drivers/dma/ppc4xx/adma.c
··· 46 46 #include <asm/dcr.h> 47 47 #include <asm/dcr-regs.h> 48 48 #include "adma.h" 49 + #include "../dmaengine.h" 49 50 50 51 enum ppc_adma_init_code { 51 52 PPC_ADMA_INIT_OK = 0, ··· 1931 1930 if (end_of_chain && slot_cnt) { 1932 1931 /* Should wait for ZeroSum completion */ 1933 1932 if (cookie > 0) 1934 - chan->completed_cookie = cookie; 1933 + chan->common.completed_cookie = cookie; 1935 1934 return; 1936 1935 } 1937 1936 ··· 1961 1960 BUG_ON(!seen_current); 1962 1961 1963 1962 if (cookie > 0) { 1964 - chan->completed_cookie = cookie; 1963 + chan->common.completed_cookie = cookie; 1965 1964 pr_debug("\tcompleted cookie %d\n", cookie); 1966 1965 } 1967 1966 ··· 2151 2150 } 2152 2151 2153 2152 /** 2154 - * ppc440spe_desc_assign_cookie - assign a cookie 2155 - */ 2156 - static dma_cookie_t ppc440spe_desc_assign_cookie( 2157 - struct ppc440spe_adma_chan *chan, 2158 - struct ppc440spe_adma_desc_slot *desc) 2159 - { 2160 - dma_cookie_t cookie = chan->common.cookie; 2161 - 2162 - cookie++; 2163 - if (cookie < 0) 2164 - cookie = 1; 2165 - chan->common.cookie = desc->async_tx.cookie = cookie; 2166 - return cookie; 2167 - } 2168 - 2169 - /** 2170 2153 * ppc440spe_rxor_set_region_data - 2171 2154 */ 2172 2155 static void ppc440spe_rxor_set_region(struct ppc440spe_adma_desc_slot *desc, ··· 2220 2235 slots_per_op = group_start->slots_per_op; 2221 2236 2222 2237 spin_lock_bh(&chan->lock); 2223 - 2224 - cookie = ppc440spe_desc_assign_cookie(chan, sw_desc); 2238 + cookie = dma_cookie_assign(tx); 2225 2239 2226 2240 if (unlikely(list_empty(&chan->chain))) { 2227 2241 /* first peer */ ··· 3928 3944 dma_cookie_t cookie, struct dma_tx_state *txstate) 3929 3945 { 3930 3946 struct ppc440spe_adma_chan *ppc440spe_chan; 3931 - dma_cookie_t last_used; 3932 - dma_cookie_t last_complete; 3933 3947 enum dma_status ret; 3934 3948 3935 3949 ppc440spe_chan = to_ppc440spe_adma_chan(chan); 3936 - last_used = chan->cookie; 3937 - last_complete = ppc440spe_chan->completed_cookie; 3938 - 3939 - dma_set_tx_state(txstate, last_complete, last_used, 0); 3940 - 3941 - ret = dma_async_is_complete(cookie, last_complete, last_used); 3950 + ret = dma_cookie_status(chan, cookie, txstate); 3942 3951 if (ret == DMA_SUCCESS) 3943 3952 return ret; 3944 3953 3945 3954 ppc440spe_adma_slot_cleanup(ppc440spe_chan); 3946 3955 3947 - last_used = chan->cookie; 3948 - last_complete = ppc440spe_chan->completed_cookie; 3949 - 3950 - dma_set_tx_state(txstate, last_complete, last_used, 0); 3951 - 3952 - return dma_async_is_complete(cookie, last_complete, last_used); 3956 + return dma_cookie_status(chan, cookie, txstate); 3953 3957 } 3954 3958 3955 3959 /** ··· 4022 4050 async_tx_ack(&sw_desc->async_tx); 4023 4051 ppc440spe_desc_init_null_xor(group_start); 4024 4052 4025 - cookie = chan->common.cookie; 4026 - cookie++; 4027 - if (cookie <= 1) 4028 - cookie = 2; 4053 + cookie = dma_cookie_assign(&sw_desc->async_tx); 4029 4054 4030 4055 /* initialize the completed cookie to be less than 4031 4056 * the most recently used cookie 4032 4057 */ 4033 - chan->completed_cookie = cookie - 1; 4034 - chan->common.cookie = sw_desc->async_tx.cookie = cookie; 4058 + chan->common.completed_cookie = cookie - 1; 4035 4059 4036 4060 /* channel should not be busy */ 4037 4061 BUG_ON(ppc440spe_chan_is_busy(chan)); ··· 4497 4529 INIT_LIST_HEAD(&chan->all_slots); 4498 4530 chan->device = adev; 4499 4531 chan->common.device = &adev->common; 4532 + dma_cookie_init(&chan->common); 4500 4533 list_add_tail(&chan->common.device_node, &adev->common.channels); 4501 4534 tasklet_init(&chan->irq_tasklet, ppc440spe_adma_tasklet, 4502 4535 (unsigned long)chan);
-2
drivers/dma/ppc4xx/adma.h
··· 81 81 * @common: common dmaengine channel object members 82 82 * @all_slots: complete domain of slots usable by the channel 83 83 * @pending: allows batching of hardware operations 84 - * @completed_cookie: identifier for the most recently completed operation 85 84 * @slots_allocated: records the actual size of the descriptor slot pool 86 85 * @hw_chain_inited: h/w descriptor chain initialization flag 87 86 * @irq_tasklet: bottom half where ppc440spe_adma_slot_cleanup runs ··· 98 99 struct list_head all_slots; 99 100 struct ppc440spe_adma_desc_slot *last_used; 100 101 int pending; 101 - dma_cookie_t completed_cookie; 102 102 int slots_allocated; 103 103 int hw_chain_inited; 104 104 struct tasklet_struct irq_tasklet;
+11 -22
drivers/dma/shdma.c
··· 30 30 #include <linux/kdebug.h> 31 31 #include <linux/spinlock.h> 32 32 #include <linux/rculist.h> 33 + 34 + #include "dmaengine.h" 33 35 #include "shdma.h" 34 36 35 37 /* DMA descriptor control */ ··· 298 296 else 299 297 power_up = false; 300 298 301 - cookie = sh_chan->common.cookie; 302 - cookie++; 303 - if (cookie < 0) 304 - cookie = 1; 305 - 306 - sh_chan->common.cookie = cookie; 307 - tx->cookie = cookie; 299 + cookie = dma_cookie_assign(tx); 308 300 309 301 /* Mark all chunks of this descriptor as submitted, move to the queue */ 310 302 list_for_each_entry_safe(chunk, c, desc->node.prev, node) { ··· 669 673 670 674 static struct dma_async_tx_descriptor *sh_dmae_prep_slave_sg( 671 675 struct dma_chan *chan, struct scatterlist *sgl, unsigned int sg_len, 672 - enum dma_transfer_direction direction, unsigned long flags) 676 + enum dma_transfer_direction direction, unsigned long flags, 677 + void *context) 673 678 { 674 679 struct sh_dmae_slave *param; 675 680 struct sh_dmae_chan *sh_chan; ··· 761 764 cookie = tx->cookie; 762 765 763 766 if (desc->mark == DESC_COMPLETED && desc->chunks == 1) { 764 - if (sh_chan->completed_cookie != desc->cookie - 1) 767 + if (sh_chan->common.completed_cookie != desc->cookie - 1) 765 768 dev_dbg(sh_chan->dev, 766 769 "Completing cookie %d, expected %d\n", 767 770 desc->cookie, 768 - sh_chan->completed_cookie + 1); 769 - sh_chan->completed_cookie = desc->cookie; 771 + sh_chan->common.completed_cookie + 1); 772 + sh_chan->common.completed_cookie = desc->cookie; 770 773 } 771 774 772 775 /* Call callback on the last chunk */ ··· 820 823 * Terminating and the loop completed normally: forgive 821 824 * uncompleted cookies 822 825 */ 823 - sh_chan->completed_cookie = sh_chan->common.cookie; 826 + sh_chan->common.completed_cookie = sh_chan->common.cookie; 824 827 825 828 spin_unlock_irqrestore(&sh_chan->desc_lock, flags); 826 829 ··· 880 883 struct dma_tx_state *txstate) 881 884 { 882 885 struct sh_dmae_chan *sh_chan = to_sh_chan(chan); 883 - dma_cookie_t last_used; 884 - dma_cookie_t last_complete; 885 886 enum dma_status status; 886 887 unsigned long flags; 887 888 888 889 sh_dmae_chan_ld_cleanup(sh_chan, false); 889 890 890 - /* First read completed cookie to avoid a skew */ 891 - last_complete = sh_chan->completed_cookie; 892 - rmb(); 893 - last_used = chan->cookie; 894 - BUG_ON(last_complete < 0); 895 - dma_set_tx_state(txstate, last_complete, last_used, 0); 896 - 897 891 spin_lock_irqsave(&sh_chan->desc_lock, flags); 898 892 899 - status = dma_async_is_complete(cookie, last_complete, last_used); 893 + status = dma_cookie_status(chan, cookie, txstate); 900 894 901 895 /* 902 896 * If we don't find cookie on the queue, it has been aborted and we have ··· 1090 1102 1091 1103 /* reference struct dma_device */ 1092 1104 new_sh_chan->common.device = &shdev->common; 1105 + dma_cookie_init(&new_sh_chan->common); 1093 1106 1094 1107 new_sh_chan->dev = shdev->common.dev; 1095 1108 new_sh_chan->id = id;
-1
drivers/dma/shdma.h
··· 30 30 }; 31 31 32 32 struct sh_dmae_chan { 33 - dma_cookie_t completed_cookie; /* The maximum cookie completed */ 34 33 spinlock_t desc_lock; /* Descriptor operation lock */ 35 34 struct list_head ld_queue; /* Link descriptors queue */ 36 35 struct list_head ld_free; /* Link descriptors free */
+9 -18
drivers/dma/sirf-dma.c
··· 18 18 #include <linux/of_platform.h> 19 19 #include <linux/sirfsoc_dma.h> 20 20 21 + #include "dmaengine.h" 22 + 21 23 #define SIRFSOC_DMA_DESCRIPTORS 16 22 24 #define SIRFSOC_DMA_CHANNELS 16 23 25 ··· 61 59 struct list_head queued; 62 60 struct list_head active; 63 61 struct list_head completed; 64 - dma_cookie_t completed_cookie; 65 62 unsigned long happened_cyclic; 66 63 unsigned long completed_cyclic; 67 64 ··· 209 208 /* Free descriptors */ 210 209 spin_lock_irqsave(&schan->lock, flags); 211 210 list_splice_tail_init(&list, &schan->free); 212 - schan->completed_cookie = last_cookie; 211 + schan->chan.completed_cookie = last_cookie; 213 212 spin_unlock_irqrestore(&schan->lock, flags); 214 213 } else { 215 214 /* for cyclic channel, desc is always in active list */ ··· 259 258 /* Move descriptor to queue */ 260 259 list_move_tail(&sdesc->node, &schan->queued); 261 260 262 - /* Update cookie */ 263 - cookie = schan->chan.cookie + 1; 264 - if (cookie <= 0) 265 - cookie = 1; 266 - 267 - schan->chan.cookie = cookie; 268 - sdesc->desc.cookie = cookie; 261 + cookie = dma_cookie_assign(txd); 269 262 270 263 spin_unlock_irqrestore(&schan->lock, flags); 271 264 ··· 409 414 { 410 415 struct sirfsoc_dma_chan *schan = dma_chan_to_sirfsoc_dma_chan(chan); 411 416 unsigned long flags; 412 - dma_cookie_t last_used; 413 - dma_cookie_t last_complete; 417 + enum dma_status ret; 414 418 415 419 spin_lock_irqsave(&schan->lock, flags); 416 - last_used = schan->chan.cookie; 417 - last_complete = schan->completed_cookie; 420 + ret = dma_cookie_status(chan, cookie, txstate); 418 421 spin_unlock_irqrestore(&schan->lock, flags); 419 422 420 - dma_set_tx_state(txstate, last_complete, last_used, 0); 421 - return dma_async_is_complete(cookie, last_complete, last_used); 423 + return ret; 422 424 } 423 425 424 426 static struct dma_async_tx_descriptor *sirfsoc_dma_prep_interleaved( ··· 489 497 static struct dma_async_tx_descriptor * 490 498 sirfsoc_dma_prep_cyclic(struct dma_chan *chan, dma_addr_t addr, 491 499 size_t buf_len, size_t period_len, 492 - enum dma_transfer_direction direction) 500 + enum dma_transfer_direction direction, void *context) 493 501 { 494 502 struct sirfsoc_dma_chan *schan = dma_chan_to_sirfsoc_dma_chan(chan); 495 503 struct sirfsoc_dma_desc *sdesc = NULL; ··· 627 635 schan = &sdma->channels[i]; 628 636 629 637 schan->chan.device = dma; 630 - schan->chan.cookie = 1; 631 - schan->completed_cookie = schan->chan.cookie; 638 + dma_cookie_init(&schan->chan); 632 639 633 640 INIT_LIST_HEAD(&schan->free); 634 641 INIT_LIST_HEAD(&schan->prepared);
+13 -28
drivers/dma/ste_dma40.c
··· 21 21 22 22 #include <plat/ste_dma40.h> 23 23 24 + #include "dmaengine.h" 24 25 #include "ste_dma40_ll.h" 25 26 26 27 #define D40_NAME "dma40" ··· 221 220 * 222 221 * @lock: A spinlock to protect this struct. 223 222 * @log_num: The logical number, if any of this channel. 224 - * @completed: Starts with 1, after first interrupt it is set to dma engine's 225 - * current cookie. 226 223 * @pending_tx: The number of pending transfers. Used between interrupt handler 227 224 * and tasklet. 228 225 * @busy: Set to true when transfer is ongoing on this channel. ··· 249 250 struct d40_chan { 250 251 spinlock_t lock; 251 252 int log_num; 252 - /* ID of the most recent completed transfer */ 253 - int completed; 254 253 int pending_tx; 255 254 bool busy; 256 255 struct d40_phy_res *phy_chan; ··· 1220 1223 chan); 1221 1224 struct d40_desc *d40d = container_of(tx, struct d40_desc, txd); 1222 1225 unsigned long flags; 1226 + dma_cookie_t cookie; 1223 1227 1224 1228 spin_lock_irqsave(&d40c->lock, flags); 1225 - 1226 - d40c->chan.cookie++; 1227 - 1228 - if (d40c->chan.cookie < 0) 1229 - d40c->chan.cookie = 1; 1230 - 1231 - d40d->txd.cookie = d40c->chan.cookie; 1232 - 1229 + cookie = dma_cookie_assign(tx); 1233 1230 d40_desc_queue(d40c, d40d); 1234 - 1235 1231 spin_unlock_irqrestore(&d40c->lock, flags); 1236 1232 1237 - return tx->cookie; 1233 + return cookie; 1238 1234 } 1239 1235 1240 1236 static int d40_start(struct d40_chan *d40c) ··· 1347 1357 goto err; 1348 1358 1349 1359 if (!d40d->cyclic) 1350 - d40c->completed = d40d->txd.cookie; 1360 + dma_cookie_complete(&d40d->txd); 1351 1361 1352 1362 /* 1353 1363 * If terminating a channel pending_tx is set to zero. ··· 2172 2182 bool is_free_phy; 2173 2183 spin_lock_irqsave(&d40c->lock, flags); 2174 2184 2175 - d40c->completed = chan->cookie = 1; 2185 + dma_cookie_init(chan); 2176 2186 2177 2187 /* If no dma configuration is set use default configuration (memcpy) */ 2178 2188 if (!d40c->configured) { ··· 2289 2299 struct scatterlist *sgl, 2290 2300 unsigned int sg_len, 2291 2301 enum dma_transfer_direction direction, 2292 - unsigned long dma_flags) 2302 + unsigned long dma_flags, 2303 + void *context) 2293 2304 { 2294 2305 if (direction != DMA_DEV_TO_MEM && direction != DMA_MEM_TO_DEV) 2295 2306 return NULL; ··· 2301 2310 static struct dma_async_tx_descriptor * 2302 2311 dma40_prep_dma_cyclic(struct dma_chan *chan, dma_addr_t dma_addr, 2303 2312 size_t buf_len, size_t period_len, 2304 - enum dma_transfer_direction direction) 2313 + enum dma_transfer_direction direction, void *context) 2305 2314 { 2306 2315 unsigned int periods = buf_len / period_len; 2307 2316 struct dma_async_tx_descriptor *txd; ··· 2333 2342 struct dma_tx_state *txstate) 2334 2343 { 2335 2344 struct d40_chan *d40c = container_of(chan, struct d40_chan, chan); 2336 - dma_cookie_t last_used; 2337 - dma_cookie_t last_complete; 2338 - int ret; 2345 + enum dma_status ret; 2339 2346 2340 2347 if (d40c->phy_chan == NULL) { 2341 2348 chan_err(d40c, "Cannot read status of unallocated channel\n"); 2342 2349 return -EINVAL; 2343 2350 } 2344 2351 2345 - last_complete = d40c->completed; 2346 - last_used = chan->cookie; 2352 + ret = dma_cookie_status(chan, cookie, txstate); 2353 + if (ret != DMA_SUCCESS) 2354 + dma_set_residue(txstate, stedma40_residue(chan)); 2347 2355 2348 2356 if (d40_is_paused(d40c)) 2349 2357 ret = DMA_PAUSED; 2350 - else 2351 - ret = dma_async_is_complete(cookie, last_complete, last_used); 2352 - 2353 - dma_set_tx_state(txstate, last_complete, last_used, 2354 - stedma40_residue(chan)); 2355 2358 2356 2359 return ret; 2357 2360 }
+11 -26
drivers/dma/timb_dma.c
··· 31 31 32 32 #include <linux/timb_dma.h> 33 33 34 + #include "dmaengine.h" 35 + 34 36 #define DRIVER_NAME "timb-dma" 35 37 36 38 /* Global DMA registers */ ··· 86 84 especially the lists and descriptors, 87 85 from races between the tasklet and calls 88 86 from above */ 89 - dma_cookie_t last_completed_cookie; 90 87 bool ongoing; 91 88 struct list_head active_list; 92 89 struct list_head queue; ··· 285 284 else 286 285 iowrite32(0, td_chan->membase + TIMBDMA_OFFS_TX_DLAR); 287 286 */ 288 - td_chan->last_completed_cookie = txd->cookie; 287 + dma_cookie_complete(txd); 289 288 td_chan->ongoing = false; 290 289 291 290 callback = txd->callback; ··· 350 349 dma_cookie_t cookie; 351 350 352 351 spin_lock_bh(&td_chan->lock); 353 - 354 - cookie = txd->chan->cookie; 355 - if (++cookie < 0) 356 - cookie = 1; 357 - txd->chan->cookie = cookie; 358 - txd->cookie = cookie; 352 + cookie = dma_cookie_assign(txd); 359 353 360 354 if (list_empty(&td_chan->active_list)) { 361 355 dev_dbg(chan2dev(txd->chan), "%s: started %u\n", __func__, ··· 477 481 } 478 482 479 483 spin_lock_bh(&td_chan->lock); 480 - td_chan->last_completed_cookie = 1; 481 - chan->cookie = 1; 484 + dma_cookie_init(chan); 482 485 spin_unlock_bh(&td_chan->lock); 483 486 484 487 return 0; ··· 510 515 static enum dma_status td_tx_status(struct dma_chan *chan, dma_cookie_t cookie, 511 516 struct dma_tx_state *txstate) 512 517 { 513 - struct timb_dma_chan *td_chan = 514 - container_of(chan, struct timb_dma_chan, chan); 515 - dma_cookie_t last_used; 516 - dma_cookie_t last_complete; 517 - int ret; 518 + enum dma_status ret; 518 519 519 520 dev_dbg(chan2dev(chan), "%s: Entry\n", __func__); 520 521 521 - last_complete = td_chan->last_completed_cookie; 522 - last_used = chan->cookie; 522 + ret = dma_cookie_status(chan, cookie, txstate); 523 523 524 - ret = dma_async_is_complete(cookie, last_complete, last_used); 525 - 526 - dma_set_tx_state(txstate, last_complete, last_used, 0); 527 - 528 - dev_dbg(chan2dev(chan), 529 - "%s: exit, ret: %d, last_complete: %d, last_used: %d\n", 530 - __func__, ret, last_complete, last_used); 524 + dev_dbg(chan2dev(chan), "%s: exit, ret: %d\n", __func__, ret); 531 525 532 526 return ret; 533 527 } ··· 542 558 543 559 static struct dma_async_tx_descriptor *td_prep_slave_sg(struct dma_chan *chan, 544 560 struct scatterlist *sgl, unsigned int sg_len, 545 - enum dma_transfer_direction direction, unsigned long flags) 561 + enum dma_transfer_direction direction, unsigned long flags, 562 + void *context) 546 563 { 547 564 struct timb_dma_chan *td_chan = 548 565 container_of(chan, struct timb_dma_chan, chan); ··· 751 766 } 752 767 753 768 td_chan->chan.device = &td->dma; 754 - td_chan->chan.cookie = 1; 769 + dma_cookie_init(&td_chan->chan); 755 770 spin_lock_init(&td_chan->lock); 756 771 INIT_LIST_HEAD(&td_chan->active_list); 757 772 INIT_LIST_HEAD(&td_chan->queue);
+10 -33
drivers/dma/txx9dmac.c
··· 15 15 #include <linux/platform_device.h> 16 16 #include <linux/slab.h> 17 17 #include <linux/scatterlist.h> 18 + 19 + #include "dmaengine.h" 18 20 #include "txx9dmac.h" 19 21 20 22 static struct txx9dmac_chan *to_txx9dmac_chan(struct dma_chan *chan) ··· 281 279 } 282 280 } 283 281 284 - /* Called with dc->lock held and bh disabled */ 285 - static dma_cookie_t 286 - txx9dmac_assign_cookie(struct txx9dmac_chan *dc, struct txx9dmac_desc *desc) 287 - { 288 - dma_cookie_t cookie = dc->chan.cookie; 289 - 290 - if (++cookie < 0) 291 - cookie = 1; 292 - 293 - dc->chan.cookie = cookie; 294 - desc->txd.cookie = cookie; 295 - 296 - return cookie; 297 - } 298 - 299 282 /*----------------------------------------------------------------------*/ 300 283 301 284 static void txx9dmac_dump_regs(struct txx9dmac_chan *dc) ··· 411 424 dev_vdbg(chan2dev(&dc->chan), "descriptor %u %p complete\n", 412 425 txd->cookie, desc); 413 426 414 - dc->completed = txd->cookie; 427 + dma_cookie_complete(txd); 415 428 callback = txd->callback; 416 429 param = txd->callback_param; 417 430 ··· 725 738 dma_cookie_t cookie; 726 739 727 740 spin_lock_bh(&dc->lock); 728 - cookie = txx9dmac_assign_cookie(dc, desc); 741 + cookie = dma_cookie_assign(tx); 729 742 730 743 dev_vdbg(chan2dev(tx->chan), "tx_submit: queued %u %p\n", 731 744 desc->txd.cookie, desc); ··· 833 846 static struct dma_async_tx_descriptor * 834 847 txx9dmac_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl, 835 848 unsigned int sg_len, enum dma_transfer_direction direction, 836 - unsigned long flags) 849 + unsigned long flags, void *context) 837 850 { 838 851 struct txx9dmac_chan *dc = to_txx9dmac_chan(chan); 839 852 struct txx9dmac_dev *ddev = dc->ddev; ··· 959 972 struct dma_tx_state *txstate) 960 973 { 961 974 struct txx9dmac_chan *dc = to_txx9dmac_chan(chan); 962 - dma_cookie_t last_used; 963 - dma_cookie_t last_complete; 964 - int ret; 975 + enum dma_status ret; 965 976 966 - last_complete = dc->completed; 967 - last_used = chan->cookie; 968 - 969 - ret = dma_async_is_complete(cookie, last_complete, last_used); 977 + ret = dma_cookie_status(chan, cookie, txstate); 970 978 if (ret != DMA_SUCCESS) { 971 979 spin_lock_bh(&dc->lock); 972 980 txx9dmac_scan_descriptors(dc); 973 981 spin_unlock_bh(&dc->lock); 974 982 975 - last_complete = dc->completed; 976 - last_used = chan->cookie; 977 - 978 - ret = dma_async_is_complete(cookie, last_complete, last_used); 983 + ret = dma_cookie_status(chan, cookie, txstate); 979 984 } 980 - 981 - dma_set_tx_state(txstate, last_complete, last_used, 0); 982 985 983 986 return ret; 984 987 } ··· 1034 1057 return -EIO; 1035 1058 } 1036 1059 1037 - dc->completed = chan->cookie = 1; 1060 + dma_cookie_init(chan); 1038 1061 1039 1062 dc->ccr = TXX9_DMA_CCR_IMMCHN | TXX9_DMA_CCR_INTENE | CCR_LE; 1040 1063 txx9dmac_chan_set_SMPCHN(dc); ··· 1163 1186 dc->ddev->chan[ch] = dc; 1164 1187 dc->chan.device = &dc->dma; 1165 1188 list_add_tail(&dc->chan.device_node, &dc->chan.device->channels); 1166 - dc->chan.cookie = dc->completed = 1; 1189 + dma_cookie_init(&dc->chan); 1167 1190 1168 1191 if (is_dmac64(dc)) 1169 1192 dc->ch_regs = &__txx9dmac_regs(dc->ddev)->CHAN[ch];
-1
drivers/dma/txx9dmac.h
··· 172 172 spinlock_t lock; 173 173 174 174 /* these other elements are all protected by lock */ 175 - dma_cookie_t completed; 176 175 struct list_head active_list; 177 176 struct list_head queue; 178 177 struct list_head free_list;
+1 -1
drivers/media/video/mx3_camera.c
··· 286 286 sg_dma_address(sg) = vb2_dma_contig_plane_dma_addr(vb, 0); 287 287 sg_dma_len(sg) = new_size; 288 288 289 - txd = ichan->dma_chan.device->device_prep_slave_sg( 289 + txd = dmaengine_prep_slave_sg( 290 290 &ichan->dma_chan, sg, 1, DMA_DEV_TO_MEM, 291 291 DMA_PREP_INTERRUPT); 292 292 if (!txd)
+1 -1
drivers/media/video/timblogiw.c
··· 564 564 565 565 spin_unlock_irq(&fh->queue_lock); 566 566 567 - desc = fh->chan->device->device_prep_slave_sg(fh->chan, 567 + desc = dmaengine_prep_slave_sg(fh->chan, 568 568 buf->sg, sg_elems, DMA_DEV_TO_MEM, 569 569 DMA_PREP_INTERRUPT | DMA_COMPL_SKIP_SRC_UNMAP); 570 570 if (!desc) {
+14 -7
drivers/mmc/host/atmel-mci.c
··· 24 24 #include <linux/seq_file.h> 25 25 #include <linux/slab.h> 26 26 #include <linux/stat.h> 27 + #include <linux/types.h> 27 28 28 29 #include <linux/mmc/host.h> 29 30 #include <linux/mmc/sdio.h> ··· 174 173 175 174 struct atmel_mci_dma dma; 176 175 struct dma_chan *data_chan; 176 + struct dma_slave_config dma_conf; 177 177 178 178 u32 cmd_status; 179 179 u32 data_status; ··· 865 863 866 864 if (data->flags & MMC_DATA_READ) { 867 865 direction = DMA_FROM_DEVICE; 868 - slave_dirn = DMA_DEV_TO_MEM; 866 + host->dma_conf.direction = slave_dirn = DMA_DEV_TO_MEM; 869 867 } else { 870 868 direction = DMA_TO_DEVICE; 871 - slave_dirn = DMA_MEM_TO_DEV; 869 + host->dma_conf.direction = slave_dirn = DMA_MEM_TO_DEV; 872 870 } 873 871 874 872 sglen = dma_map_sg(chan->device->dev, data->sg, 875 873 data->sg_len, direction); 876 874 877 - desc = chan->device->device_prep_slave_sg(chan, 875 + dmaengine_slave_config(chan, &host->dma_conf); 876 + desc = dmaengine_prep_slave_sg(chan, 878 877 data->sg, sglen, slave_dirn, 879 878 DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 880 879 if (!desc) ··· 1963 1960 if (pdata && find_slave_dev(pdata->dma_slave)) { 1964 1961 dma_cap_mask_t mask; 1965 1962 1966 - setup_dma_addr(pdata->dma_slave, 1967 - host->mapbase + ATMCI_TDR, 1968 - host->mapbase + ATMCI_RDR); 1969 - 1970 1963 /* Try to grab a DMA channel */ 1971 1964 dma_cap_zero(mask); 1972 1965 dma_cap_set(DMA_SLAVE, mask); ··· 1976 1977 dev_info(&host->pdev->dev, 1977 1978 "using %s for DMA transfers\n", 1978 1979 dma_chan_name(host->dma.chan)); 1980 + 1981 + host->dma_conf.src_addr = host->mapbase + ATMCI_RDR; 1982 + host->dma_conf.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; 1983 + host->dma_conf.src_maxburst = 1; 1984 + host->dma_conf.dst_addr = host->mapbase + ATMCI_TDR; 1985 + host->dma_conf.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; 1986 + host->dma_conf.dst_maxburst = 1; 1987 + host->dma_conf.device_fc = false; 1979 1988 return true; 1980 1989 } 1981 1990 }
+3 -1
drivers/mmc/host/mmci.c
··· 30 30 #include <linux/dma-mapping.h> 31 31 #include <linux/amba/mmci.h> 32 32 #include <linux/pm_runtime.h> 33 + #include <linux/types.h> 33 34 34 35 #include <asm/div64.h> 35 36 #include <asm/io.h> ··· 401 400 .dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES, 402 401 .src_maxburst = variant->fifohalfsize >> 2, /* # of words */ 403 402 .dst_maxburst = variant->fifohalfsize >> 2, /* # of words */ 403 + .device_fc = false, 404 404 }; 405 405 struct dma_chan *chan; 406 406 struct dma_device *device; ··· 443 441 return -EINVAL; 444 442 445 443 dmaengine_slave_config(chan, &conf); 446 - desc = device->device_prep_slave_sg(chan, data->sg, nr_sg, 444 + desc = dmaengine_prep_slave_sg(chan, data->sg, nr_sg, 447 445 conf.direction, DMA_CTRL_ACK); 448 446 if (!desc) 449 447 goto unmap_exit;
+4 -1
drivers/mmc/host/mxcmmc.c
··· 33 33 #include <linux/gpio.h> 34 34 #include <linux/regulator/consumer.h> 35 35 #include <linux/dmaengine.h> 36 + #include <linux/types.h> 36 37 37 38 #include <asm/dma.h> 38 39 #include <asm/irq.h> ··· 255 254 if (nents != data->sg_len) 256 255 return -EINVAL; 257 256 258 - host->desc = host->dma->device->device_prep_slave_sg(host->dma, 257 + host->desc = dmaengine_prep_slave_sg(host->dma, 259 258 data->sg, data->sg_len, slave_dirn, 260 259 DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 261 260 ··· 268 267 wmb(); 269 268 270 269 dmaengine_submit(host->desc); 270 + dma_async_issue_pending(host->dma); 271 271 272 272 return 0; 273 273 } ··· 712 710 config->src_addr_width = 4; 713 711 config->dst_maxburst = host->burstlen; 714 712 config->src_maxburst = host->burstlen; 713 + config->device_fc = false; 715 714 716 715 return dmaengine_slave_config(host->dma, config); 717 716 }
+1 -1
drivers/mmc/host/mxs-mmc.c
··· 324 324 sg_len = SSP_PIO_NUM; 325 325 } 326 326 327 - desc = host->dmach->device->device_prep_slave_sg(host->dmach, 327 + desc = dmaengine_prep_slave_sg(host->dmach, 328 328 sgl, sg_len, host->slave_dirn, append); 329 329 if (desc) { 330 330 desc->callback = mxs_mmc_dma_irq_callback;
+2 -2
drivers/mmc/host/sh_mmcif.c
··· 286 286 DMA_FROM_DEVICE); 287 287 if (ret > 0) { 288 288 host->dma_active = true; 289 - desc = chan->device->device_prep_slave_sg(chan, sg, ret, 289 + desc = dmaengine_prep_slave_sg(chan, sg, ret, 290 290 DMA_DEV_TO_MEM, DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 291 291 } 292 292 ··· 335 335 DMA_TO_DEVICE); 336 336 if (ret > 0) { 337 337 host->dma_active = true; 338 - desc = chan->device->device_prep_slave_sg(chan, sg, ret, 338 + desc = dmaengine_prep_slave_sg(chan, sg, ret, 339 339 DMA_MEM_TO_DEV, DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 340 340 } 341 341
+2 -2
drivers/mmc/host/tmio_mmc_dma.c
··· 88 88 89 89 ret = dma_map_sg(chan->device->dev, sg, host->sg_len, DMA_FROM_DEVICE); 90 90 if (ret > 0) 91 - desc = chan->device->device_prep_slave_sg(chan, sg, ret, 91 + desc = dmaengine_prep_slave_sg(chan, sg, ret, 92 92 DMA_DEV_TO_MEM, DMA_CTRL_ACK); 93 93 94 94 if (desc) { ··· 169 169 170 170 ret = dma_map_sg(chan->device->dev, sg, host->sg_len, DMA_TO_DEVICE); 171 171 if (ret > 0) 172 - desc = chan->device->device_prep_slave_sg(chan, sg, ret, 172 + desc = dmaengine_prep_slave_sg(chan, sg, ret, 173 173 DMA_MEM_TO_DEV, DMA_CTRL_ACK); 174 174 175 175 if (desc) {
+11 -14
drivers/mtd/nand/gpmi-nand/gpmi-lib.c
··· 835 835 | BM_GPMI_CTRL0_ADDRESS_INCREMENT 836 836 | BF_GPMI_CTRL0_XFER_COUNT(this->command_length); 837 837 pio[1] = pio[2] = 0; 838 - desc = channel->device->device_prep_slave_sg(channel, 838 + desc = dmaengine_prep_slave_sg(channel, 839 839 (struct scatterlist *)pio, 840 840 ARRAY_SIZE(pio), DMA_TRANS_NONE, 0); 841 841 if (!desc) { ··· 848 848 849 849 sg_init_one(sgl, this->cmd_buffer, this->command_length); 850 850 dma_map_sg(this->dev, sgl, 1, DMA_TO_DEVICE); 851 - desc = channel->device->device_prep_slave_sg(channel, 852 - sgl, 1, DMA_MEM_TO_DEV, 1); 851 + desc = dmaengine_prep_slave_sg(channel, sgl, 1, DMA_MEM_TO_DEV, 1); 853 852 if (!desc) { 854 853 pr_err("step 2 error\n"); 855 854 return -1; ··· 879 880 | BF_GPMI_CTRL0_ADDRESS(address) 880 881 | BF_GPMI_CTRL0_XFER_COUNT(this->upper_len); 881 882 pio[1] = 0; 882 - desc = channel->device->device_prep_slave_sg(channel, 883 - (struct scatterlist *)pio, 883 + desc = dmaengine_prep_slave_sg(channel, (struct scatterlist *)pio, 884 884 ARRAY_SIZE(pio), DMA_TRANS_NONE, 0); 885 885 if (!desc) { 886 886 pr_err("step 1 error\n"); ··· 888 890 889 891 /* [2] send DMA request */ 890 892 prepare_data_dma(this, DMA_TO_DEVICE); 891 - desc = channel->device->device_prep_slave_sg(channel, &this->data_sgl, 893 + desc = dmaengine_prep_slave_sg(channel, &this->data_sgl, 892 894 1, DMA_MEM_TO_DEV, 1); 893 895 if (!desc) { 894 896 pr_err("step 2 error\n"); ··· 914 916 | BF_GPMI_CTRL0_ADDRESS(BV_GPMI_CTRL0_ADDRESS__NAND_DATA) 915 917 | BF_GPMI_CTRL0_XFER_COUNT(this->upper_len); 916 918 pio[1] = 0; 917 - desc = channel->device->device_prep_slave_sg(channel, 919 + desc = dmaengine_prep_slave_sg(channel, 918 920 (struct scatterlist *)pio, 919 921 ARRAY_SIZE(pio), DMA_TRANS_NONE, 0); 920 922 if (!desc) { ··· 924 926 925 927 /* [2] : send DMA request */ 926 928 prepare_data_dma(this, DMA_FROM_DEVICE); 927 - desc = channel->device->device_prep_slave_sg(channel, &this->data_sgl, 928 - 1, DMA_DEV_TO_MEM, 1); 929 + desc = dmaengine_prep_slave_sg(channel, &this->data_sgl, 930 + 1, DMA_DEV_TO_MEM, 1); 929 931 if (!desc) { 930 932 pr_err("step 2 error\n"); 931 933 return -1; ··· 970 972 pio[4] = payload; 971 973 pio[5] = auxiliary; 972 974 973 - desc = channel->device->device_prep_slave_sg(channel, 974 - (struct scatterlist *)pio, 975 + desc = dmaengine_prep_slave_sg(channel, (struct scatterlist *)pio, 975 976 ARRAY_SIZE(pio), DMA_TRANS_NONE, 0); 976 977 if (!desc) { 977 978 pr_err("step 2 error\n"); ··· 1004 1007 | BF_GPMI_CTRL0_ADDRESS(address) 1005 1008 | BF_GPMI_CTRL0_XFER_COUNT(0); 1006 1009 pio[1] = 0; 1007 - desc = channel->device->device_prep_slave_sg(channel, 1010 + desc = dmaengine_prep_slave_sg(channel, 1008 1011 (struct scatterlist *)pio, 2, 1009 1012 DMA_TRANS_NONE, 0); 1010 1013 if (!desc) { ··· 1033 1036 pio[3] = geo->page_size; 1034 1037 pio[4] = payload; 1035 1038 pio[5] = auxiliary; 1036 - desc = channel->device->device_prep_slave_sg(channel, 1039 + desc = dmaengine_prep_slave_sg(channel, 1037 1040 (struct scatterlist *)pio, 1038 1041 ARRAY_SIZE(pio), DMA_TRANS_NONE, 1); 1039 1042 if (!desc) { ··· 1052 1055 | BF_GPMI_CTRL0_ADDRESS(address) 1053 1056 | BF_GPMI_CTRL0_XFER_COUNT(geo->page_size); 1054 1057 pio[1] = 0; 1055 - desc = channel->device->device_prep_slave_sg(channel, 1058 + desc = dmaengine_prep_slave_sg(channel, 1056 1059 (struct scatterlist *)pio, 2, 1057 1060 DMA_TRANS_NONE, 1); 1058 1061 if (!desc) {
+2 -2
drivers/net/ethernet/micrel/ks8842.c
··· 458 458 if (sg_dma_len(&ctl->sg) % 4) 459 459 sg_dma_len(&ctl->sg) += 4 - sg_dma_len(&ctl->sg) % 4; 460 460 461 - ctl->adesc = ctl->chan->device->device_prep_slave_sg(ctl->chan, 461 + ctl->adesc = dmaengine_prep_slave_sg(ctl->chan, 462 462 &ctl->sg, 1, DMA_MEM_TO_DEV, 463 463 DMA_PREP_INTERRUPT | DMA_COMPL_SKIP_SRC_UNMAP); 464 464 if (!ctl->adesc) ··· 570 570 571 571 sg_dma_len(sg) = DMA_BUFFER_SIZE; 572 572 573 - ctl->adesc = ctl->chan->device->device_prep_slave_sg(ctl->chan, 573 + ctl->adesc = dmaengine_prep_slave_sg(ctl->chan, 574 574 sg, 1, DMA_DEV_TO_MEM, 575 575 DMA_PREP_INTERRUPT | DMA_COMPL_SKIP_SRC_UNMAP); 576 576
+5 -2
drivers/spi/spi-dw-mid.c
··· 22 22 #include <linux/interrupt.h> 23 23 #include <linux/slab.h> 24 24 #include <linux/spi/spi.h> 25 + #include <linux/types.h> 25 26 26 27 #include "spi-dw.h" 27 28 ··· 137 136 txconf.dst_maxburst = LNW_DMA_MSIZE_16; 138 137 txconf.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; 139 138 txconf.dst_addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES; 139 + txconf.device_fc = false; 140 140 141 141 txchan->device->device_control(txchan, DMA_SLAVE_CONFIG, 142 142 (unsigned long) &txconf); ··· 146 144 dws->tx_sgl.dma_address = dws->tx_dma; 147 145 dws->tx_sgl.length = dws->len; 148 146 149 - txdesc = txchan->device->device_prep_slave_sg(txchan, 147 + txdesc = dmaengine_prep_slave_sg(txchan, 150 148 &dws->tx_sgl, 151 149 1, 152 150 DMA_MEM_TO_DEV, ··· 160 158 rxconf.src_maxburst = LNW_DMA_MSIZE_16; 161 159 rxconf.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; 162 160 rxconf.src_addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES; 161 + rxconf.device_fc = false; 163 162 164 163 rxchan->device->device_control(rxchan, DMA_SLAVE_CONFIG, 165 164 (unsigned long) &rxconf); ··· 169 166 dws->rx_sgl.dma_address = dws->rx_dma; 170 167 dws->rx_sgl.length = dws->len; 171 168 172 - rxdesc = rxchan->device->device_prep_slave_sg(rxchan, 169 + rxdesc = dmaengine_prep_slave_sg(rxchan, 173 170 &dws->rx_sgl, 174 171 1, 175 172 DMA_DEV_TO_MEM,
+2 -2
drivers/spi/spi-ep93xx.c
··· 633 633 if (!nents) 634 634 return ERR_PTR(-ENOMEM); 635 635 636 - txd = chan->device->device_prep_slave_sg(chan, sgt->sgl, nents, 637 - slave_dirn, DMA_CTRL_ACK); 636 + txd = dmaengine_prep_slave_sg(chan, sgt->sgl, nents, 637 + slave_dirn, DMA_CTRL_ACK); 638 638 if (!txd) { 639 639 dma_unmap_sg(chan->device->dev, sgt->sgl, sgt->nents, dir); 640 640 return ERR_PTR(-ENOMEM);
+4 -2
drivers/spi/spi-pl022.c
··· 880 880 struct dma_slave_config rx_conf = { 881 881 .src_addr = SSP_DR(pl022->phybase), 882 882 .direction = DMA_DEV_TO_MEM, 883 + .device_fc = false, 883 884 }; 884 885 struct dma_slave_config tx_conf = { 885 886 .dst_addr = SSP_DR(pl022->phybase), 886 887 .direction = DMA_MEM_TO_DEV, 888 + .device_fc = false, 887 889 }; 888 890 unsigned int pages; 889 891 int ret; ··· 1019 1017 goto err_tx_sgmap; 1020 1018 1021 1019 /* Send both scatterlists */ 1022 - rxdesc = rxchan->device->device_prep_slave_sg(rxchan, 1020 + rxdesc = dmaengine_prep_slave_sg(rxchan, 1023 1021 pl022->sgt_rx.sgl, 1024 1022 rx_sglen, 1025 1023 DMA_DEV_TO_MEM, ··· 1027 1025 if (!rxdesc) 1028 1026 goto err_rxdesc; 1029 1027 1030 - txdesc = txchan->device->device_prep_slave_sg(txchan, 1028 + txdesc = dmaengine_prep_slave_sg(txchan, 1031 1029 pl022->sgt_tx.sgl, 1032 1030 tx_sglen, 1033 1031 DMA_MEM_TO_DEV,
+2 -2
drivers/spi/spi-topcliff-pch.c
··· 1099 1099 sg_dma_address(sg) = dma->rx_buf_dma + sg->offset; 1100 1100 } 1101 1101 sg = dma->sg_rx_p; 1102 - desc_rx = dma->chan_rx->device->device_prep_slave_sg(dma->chan_rx, sg, 1102 + desc_rx = dmaengine_prep_slave_sg(dma->chan_rx, sg, 1103 1103 num, DMA_DEV_TO_MEM, 1104 1104 DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 1105 1105 if (!desc_rx) { ··· 1158 1158 sg_dma_address(sg) = dma->tx_buf_dma + sg->offset; 1159 1159 } 1160 1160 sg = dma->sg_tx_p; 1161 - desc_tx = dma->chan_tx->device->device_prep_slave_sg(dma->chan_tx, 1161 + desc_tx = dmaengine_prep_slave_sg(dma->chan_tx, 1162 1162 sg, num, DMA_MEM_TO_DEV, 1163 1163 DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 1164 1164 if (!desc_tx) {
+5 -4
drivers/tty/serial/amba-pl011.c
··· 51 51 #include <linux/dma-mapping.h> 52 52 #include <linux/scatterlist.h> 53 53 #include <linux/delay.h> 54 + #include <linux/types.h> 54 55 55 56 #include <asm/io.h> 56 57 #include <asm/sizes.h> ··· 272 271 .dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE, 273 272 .direction = DMA_MEM_TO_DEV, 274 273 .dst_maxburst = uap->fifosize >> 1, 274 + .device_fc = false, 275 275 }; 276 276 struct dma_chan *chan; 277 277 dma_cap_mask_t mask; ··· 306 304 .src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE, 307 305 .direction = DMA_DEV_TO_MEM, 308 306 .src_maxburst = uap->fifosize >> 1, 307 + .device_fc = false, 309 308 }; 310 309 311 310 chan = dma_request_channel(mask, plat->dma_filter, plat->dma_rx_param); ··· 484 481 return -EBUSY; 485 482 } 486 483 487 - desc = dma_dev->device_prep_slave_sg(chan, &dmatx->sg, 1, DMA_MEM_TO_DEV, 484 + desc = dmaengine_prep_slave_sg(chan, &dmatx->sg, 1, DMA_MEM_TO_DEV, 488 485 DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 489 486 if (!desc) { 490 487 dma_unmap_sg(dma_dev->dev, &dmatx->sg, 1, DMA_TO_DEVICE); ··· 667 664 static int pl011_dma_rx_trigger_dma(struct uart_amba_port *uap) 668 665 { 669 666 struct dma_chan *rxchan = uap->dmarx.chan; 670 - struct dma_device *dma_dev; 671 667 struct pl011_dmarx_data *dmarx = &uap->dmarx; 672 668 struct dma_async_tx_descriptor *desc; 673 669 struct pl011_sgbuf *sgbuf; ··· 677 675 /* Start the RX DMA job */ 678 676 sgbuf = uap->dmarx.use_buf_b ? 679 677 &uap->dmarx.sgbuf_b : &uap->dmarx.sgbuf_a; 680 - dma_dev = rxchan->device; 681 - desc = rxchan->device->device_prep_slave_sg(rxchan, &sgbuf->sg, 1, 678 + desc = dmaengine_prep_slave_sg(rxchan, &sgbuf->sg, 1, 682 679 DMA_DEV_TO_MEM, 683 680 DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 684 681 /*
+2 -2
drivers/tty/serial/pch_uart.c
··· 844 844 845 845 sg_dma_address(sg) = priv->rx_buf_dma; 846 846 847 - desc = priv->chan_rx->device->device_prep_slave_sg(priv->chan_rx, 847 + desc = dmaengine_prep_slave_sg(priv->chan_rx, 848 848 sg, 1, DMA_DEV_TO_MEM, 849 849 DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 850 850 ··· 1003 1003 sg_dma_len(sg) = size; 1004 1004 } 1005 1005 1006 - desc = priv->chan_tx->device->device_prep_slave_sg(priv->chan_tx, 1006 + desc = dmaengine_prep_slave_sg(priv->chan_tx, 1007 1007 priv->sg_tx_p, nent, DMA_MEM_TO_DEV, 1008 1008 DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 1009 1009 if (!desc) {
+2 -2
drivers/tty/serial/sh-sci.c
··· 1338 1338 struct scatterlist *sg = &s->sg_rx[i]; 1339 1339 struct dma_async_tx_descriptor *desc; 1340 1340 1341 - desc = chan->device->device_prep_slave_sg(chan, 1341 + desc = dmaengine_prep_slave_sg(chan, 1342 1342 sg, 1, DMA_DEV_TO_MEM, DMA_PREP_INTERRUPT); 1343 1343 1344 1344 if (desc) { ··· 1453 1453 1454 1454 BUG_ON(!sg_dma_len(sg)); 1455 1455 1456 - desc = chan->device->device_prep_slave_sg(chan, 1456 + desc = dmaengine_prep_slave_sg(chan, 1457 1457 sg, s->sg_len_tx, DMA_MEM_TO_DEV, 1458 1458 DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 1459 1459 if (!desc) {
+2 -2
drivers/usb/musb/ux500_dma.c
··· 115 115 slave_conf.dst_addr = usb_fifo_addr; 116 116 slave_conf.dst_addr_width = addr_width; 117 117 slave_conf.dst_maxburst = 16; 118 + slave_conf.device_fc = false; 118 119 119 120 dma_chan->device->device_control(dma_chan, DMA_SLAVE_CONFIG, 120 121 (unsigned long) &slave_conf); 121 122 122 - dma_desc = dma_chan->device-> 123 - device_prep_slave_sg(dma_chan, &sg, 1, direction, 123 + dma_desc = dmaengine_prep_slave_sg(dma_chan, &sg, 1, direction, 124 124 DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 125 125 if (!dma_desc) 126 126 return false;
+2 -3
drivers/usb/renesas_usbhs/fifo.c
··· 786 786 sg_dma_address(&sg) = pkt->dma + pkt->actual; 787 787 sg_dma_len(&sg) = pkt->trans; 788 788 789 - desc = chan->device->device_prep_slave_sg(chan, &sg, 1, dir, 790 - DMA_PREP_INTERRUPT | 791 - DMA_CTRL_ACK); 789 + desc = dmaengine_prep_slave_sg(chan, &sg, 1, dir, 790 + DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 792 791 if (!desc) 793 792 return; 794 793
+2 -2
drivers/video/mx3fb.c
··· 337 337 338 338 /* This enables the channel */ 339 339 if (mx3_fbi->cookie < 0) { 340 - mx3_fbi->txd = dma_chan->device->device_prep_slave_sg(dma_chan, 340 + mx3_fbi->txd = dmaengine_prep_slave_sg(dma_chan, 341 341 &mx3_fbi->sg[0], 1, DMA_MEM_TO_DEV, DMA_PREP_INTERRUPT); 342 342 if (!mx3_fbi->txd) { 343 343 dev_err(mx3fb->dev, "Cannot allocate descriptor on %d\n", ··· 1091 1091 if (mx3_fbi->txd) 1092 1092 async_tx_ack(mx3_fbi->txd); 1093 1093 1094 - txd = dma_chan->device->device_prep_slave_sg(dma_chan, sg + 1094 + txd = dmaengine_prep_slave_sg(dma_chan, sg + 1095 1095 mx3_fbi->cur_ipu_buf, 1, DMA_MEM_TO_DEV, DMA_PREP_INTERRUPT); 1096 1096 if (!txd) { 1097 1097 dev_err(fbi->device,
+4 -6
include/linux/amba/pl08x.h
··· 47 47 * @muxval: a number usually used to poke into some mux regiser to 48 48 * mux in the signal to this channel 49 49 * @cctl_opt: default options for the channel control register 50 - * @device_fc: Flow Controller Settings for ccfg register. Only valid for slave 51 - * channels. Fill with 'true' if peripheral should be flow controller. Direction 52 - * will be selected at Runtime. 53 50 * @addr: source/target address in physical memory for this DMA channel, 54 51 * can be the address of a FIFO register for burst requests for example. 55 52 * This can be left undefined if the PrimeCell API is used for configuring ··· 65 68 int max_signal; 66 69 u32 muxval; 67 70 u32 cctl; 68 - bool device_fc; 69 71 dma_addr_t addr; 70 72 bool circular_buffer; 71 73 bool single; ··· 172 176 * @runtime_addr: address for RX/TX according to the runtime config 173 177 * @runtime_direction: current direction of this channel according to 174 178 * runtime config 175 - * @lc: last completed transaction on this channel 176 179 * @pend_list: queued transactions pending on this channel 177 180 * @at: active transaction on this channel 178 181 * @lock: a lock for this channel data 179 182 * @host: a pointer to the host (internal use) 180 183 * @state: whether the channel is idle, paused, running etc 181 184 * @slave: whether this channel is a device (slave) or for memcpy 185 + * @device_fc: Flow Controller Settings for ccfg register. Only valid for slave 186 + * channels. Fill with 'true' if peripheral should be flow controller. Direction 187 + * will be selected at Runtime. 182 188 * @waiting: a TX descriptor on this channel which is waiting for a physical 183 189 * channel to become available 184 190 */ ··· 196 198 u32 src_cctl; 197 199 u32 dst_cctl; 198 200 enum dma_transfer_direction runtime_direction; 199 - dma_cookie_t lc; 200 201 struct list_head pend_list; 201 202 struct pl08x_txd *at; 202 203 spinlock_t lock; 203 204 struct pl08x_driver_data *host; 204 205 enum pl08x_dma_chan_state state; 205 206 bool slave; 207 + bool device_fc; 206 208 struct pl08x_txd *waiting; 207 209 }; 208 210
-1
include/linux/amba/pl330.h
··· 13 13 #define __AMBA_PL330_H_ 14 14 15 15 #include <linux/dmaengine.h> 16 - #include <asm/hardware/pl330.h> 17 16 18 17 struct dma_pl330_platdata { 19 18 /*
+30 -5
include/linux/dmaengine.h
··· 18 18 * The full GNU General Public License is included in this distribution in the 19 19 * file called COPYING. 20 20 */ 21 - #ifndef DMAENGINE_H 22 - #define DMAENGINE_H 21 + #ifndef LINUX_DMAENGINE_H 22 + #define LINUX_DMAENGINE_H 23 23 24 24 #include <linux/device.h> 25 25 #include <linux/uio.h> 26 26 #include <linux/bug.h> 27 27 #include <linux/scatterlist.h> 28 28 #include <linux/bitmap.h> 29 + #include <linux/types.h> 29 30 #include <asm/page.h> 30 31 31 32 /** ··· 259 258 * struct dma_chan - devices supply DMA channels, clients use them 260 259 * @device: ptr to the dma device who supplies this channel, always !%NULL 261 260 * @cookie: last cookie value returned to client 261 + * @completed_cookie: last completed cookie for this channel 262 262 * @chan_id: channel ID for sysfs 263 263 * @dev: class device for sysfs 264 264 * @device_node: used to add this to the device chan list ··· 271 269 struct dma_chan { 272 270 struct dma_device *device; 273 271 dma_cookie_t cookie; 272 + dma_cookie_t completed_cookie; 274 273 275 274 /* sysfs */ 276 275 int chan_id; ··· 335 332 * may or may not be applicable on memory sources. 336 333 * @dst_maxburst: same as src_maxburst but for destination target 337 334 * mutatis mutandis. 335 + * @device_fc: Flow Controller Settings. Only valid for slave channels. Fill 336 + * with 'true' if peripheral should be flow controller. Direction will be 337 + * selected at Runtime. 338 338 * 339 339 * This struct is passed in as configuration data to a DMA engine 340 340 * in order to set up a certain channel for DMA transport at runtime. ··· 364 358 enum dma_slave_buswidth dst_addr_width; 365 359 u32 src_maxburst; 366 360 u32 dst_maxburst; 361 + bool device_fc; 367 362 }; 368 363 369 364 static inline const char *dma_chan_name(struct dma_chan *chan) ··· 583 576 struct dma_async_tx_descriptor *(*device_prep_slave_sg)( 584 577 struct dma_chan *chan, struct scatterlist *sgl, 585 578 unsigned int sg_len, enum dma_transfer_direction direction, 586 - unsigned long flags); 579 + unsigned long flags, void *context); 587 580 struct dma_async_tx_descriptor *(*device_prep_dma_cyclic)( 588 581 struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len, 589 - size_t period_len, enum dma_transfer_direction direction); 582 + size_t period_len, enum dma_transfer_direction direction, 583 + void *context); 590 584 struct dma_async_tx_descriptor *(*device_prep_interleaved_dma)( 591 585 struct dma_chan *chan, struct dma_interleaved_template *xt, 592 586 unsigned long flags); ··· 621 613 struct scatterlist sg; 622 614 sg_init_one(&sg, buf, len); 623 615 624 - return chan->device->device_prep_slave_sg(chan, &sg, 1, dir, flags); 616 + return chan->device->device_prep_slave_sg(chan, &sg, 1, 617 + dir, flags, NULL); 618 + } 619 + 620 + static inline struct dma_async_tx_descriptor *dmaengine_prep_slave_sg( 621 + struct dma_chan *chan, struct scatterlist *sgl, unsigned int sg_len, 622 + enum dma_transfer_direction dir, unsigned long flags) 623 + { 624 + return chan->device->device_prep_slave_sg(chan, sgl, sg_len, 625 + dir, flags, NULL); 626 + } 627 + 628 + static inline struct dma_async_tx_descriptor *dmaengine_prep_dma_cyclic( 629 + struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len, 630 + size_t period_len, enum dma_transfer_direction dir) 631 + { 632 + return chan->device->device_prep_dma_cyclic(chan, buf_addr, buf_len, 633 + period_len, dir, NULL); 625 634 } 626 635 627 636 static inline int dmaengine_terminate_all(struct dma_chan *chan)
-38
include/linux/dw_dmac.h
··· 31 31 unsigned char chan_priority; 32 32 }; 33 33 34 - /** 35 - * enum dw_dma_slave_width - DMA slave register access width. 36 - * @DMA_SLAVE_WIDTH_8BIT: Do 8-bit slave register accesses 37 - * @DMA_SLAVE_WIDTH_16BIT: Do 16-bit slave register accesses 38 - * @DMA_SLAVE_WIDTH_32BIT: Do 32-bit slave register accesses 39 - */ 40 - enum dw_dma_slave_width { 41 - DW_DMA_SLAVE_WIDTH_8BIT, 42 - DW_DMA_SLAVE_WIDTH_16BIT, 43 - DW_DMA_SLAVE_WIDTH_32BIT, 44 - }; 45 - 46 34 /* bursts size */ 47 35 enum dw_dma_msize { 48 36 DW_DMA_MSIZE_1, ··· 43 55 DW_DMA_MSIZE_256, 44 56 }; 45 57 46 - /* flow controller */ 47 - enum dw_dma_fc { 48 - DW_DMA_FC_D_M2M, 49 - DW_DMA_FC_D_M2P, 50 - DW_DMA_FC_D_P2M, 51 - DW_DMA_FC_D_P2P, 52 - DW_DMA_FC_P_P2M, 53 - DW_DMA_FC_SP_P2P, 54 - DW_DMA_FC_P_M2P, 55 - DW_DMA_FC_DP_P2P, 56 - }; 57 - 58 58 /** 59 59 * struct dw_dma_slave - Controller-specific information about a slave 60 60 * 61 61 * @dma_dev: required DMA master device 62 - * @tx_reg: physical address of data register used for 63 - * memory-to-peripheral transfers 64 - * @rx_reg: physical address of data register used for 65 - * peripheral-to-memory transfers 66 - * @reg_width: peripheral register width 67 62 * @cfg_hi: Platform-specific initializer for the CFG_HI register 68 63 * @cfg_lo: Platform-specific initializer for the CFG_LO register 69 64 * @src_master: src master for transfers on allocated channel. 70 65 * @dst_master: dest master for transfers on allocated channel. 71 - * @src_msize: src burst size. 72 - * @dst_msize: dest burst size. 73 - * @fc: flow controller for DMA transfer 74 66 */ 75 67 struct dw_dma_slave { 76 68 struct device *dma_dev; 77 - dma_addr_t tx_reg; 78 - dma_addr_t rx_reg; 79 - enum dw_dma_slave_width reg_width; 80 69 u32 cfg_hi; 81 70 u32 cfg_lo; 82 71 u8 src_master; 83 72 u8 dst_master; 84 - u8 src_msize; 85 - u8 dst_msize; 86 - u8 fc; 87 73 }; 88 74 89 75 /* Platform-configurable bits in CFG_HI */
+14 -4
sound/atmel/abdac.c
··· 16 16 #include <linux/interrupt.h> 17 17 #include <linux/module.h> 18 18 #include <linux/platform_device.h> 19 + #include <linux/types.h> 19 20 #include <linux/io.h> 20 21 21 22 #include <sound/core.h> ··· 468 467 snd_card_set_dev(card, &pdev->dev); 469 468 470 469 if (pdata->dws.dma_dev) { 471 - struct dw_dma_slave *dws = &pdata->dws; 472 470 dma_cap_mask_t mask; 473 - 474 - dws->tx_reg = regs->start + DAC_DATA; 475 471 476 472 dma_cap_zero(mask); 477 473 dma_cap_set(DMA_SLAVE, mask); 478 474 479 - dac->dma.chan = dma_request_channel(mask, filter, dws); 475 + dac->dma.chan = dma_request_channel(mask, filter, &pdata->dws); 476 + if (dac->dma.chan) { 477 + struct dma_slave_config dma_conf = { 478 + .dst_addr = regs->start + DAC_DATA, 479 + .dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES, 480 + .src_maxburst = 1, 481 + .dst_maxburst = 1, 482 + .direction = DMA_MEM_TO_DEV, 483 + .device_fc = false, 484 + }; 485 + 486 + dmaengine_slave_config(dac->dma.chan, &dma_conf); 487 + } 480 488 } 481 489 if (!pdata->dws.dma_dev || !dac->dma.chan) { 482 490 dev_dbg(&pdev->dev, "DMA not available\n");
+33 -8
sound/atmel/ac97c.c
··· 20 20 #include <linux/platform_device.h> 21 21 #include <linux/mutex.h> 22 22 #include <linux/gpio.h> 23 + #include <linux/types.h> 23 24 #include <linux/io.h> 24 25 25 26 #include <sound/core.h> ··· 1015 1014 1016 1015 if (cpu_is_at32ap7000()) { 1017 1016 if (pdata->rx_dws.dma_dev) { 1018 - struct dw_dma_slave *dws = &pdata->rx_dws; 1019 1017 dma_cap_mask_t mask; 1020 - 1021 - dws->rx_reg = regs->start + AC97C_CARHR + 2; 1022 1018 1023 1019 dma_cap_zero(mask); 1024 1020 dma_cap_set(DMA_SLAVE, mask); 1025 1021 1026 1022 chip->dma.rx_chan = dma_request_channel(mask, filter, 1027 - dws); 1023 + &pdata->rx_dws); 1024 + if (chip->dma.rx_chan) { 1025 + struct dma_slave_config dma_conf = { 1026 + .src_addr = regs->start + AC97C_CARHR + 1027 + 2, 1028 + .src_addr_width = 1029 + DMA_SLAVE_BUSWIDTH_2_BYTES, 1030 + .src_maxburst = 1, 1031 + .dst_maxburst = 1, 1032 + .direction = DMA_DEV_TO_MEM, 1033 + .device_fc = false, 1034 + }; 1035 + 1036 + dmaengine_slave_config(chip->dma.rx_chan, 1037 + &dma_conf); 1038 + } 1028 1039 1029 1040 dev_info(&chip->pdev->dev, "using %s for DMA RX\n", 1030 1041 dev_name(&chip->dma.rx_chan->dev->device)); ··· 1044 1031 } 1045 1032 1046 1033 if (pdata->tx_dws.dma_dev) { 1047 - struct dw_dma_slave *dws = &pdata->tx_dws; 1048 1034 dma_cap_mask_t mask; 1049 - 1050 - dws->tx_reg = regs->start + AC97C_CATHR + 2; 1051 1035 1052 1036 dma_cap_zero(mask); 1053 1037 dma_cap_set(DMA_SLAVE, mask); 1054 1038 1055 1039 chip->dma.tx_chan = dma_request_channel(mask, filter, 1056 - dws); 1040 + &pdata->tx_dws); 1041 + if (chip->dma.tx_chan) { 1042 + struct dma_slave_config dma_conf = { 1043 + .dst_addr = regs->start + AC97C_CATHR + 1044 + 2, 1045 + .dst_addr_width = 1046 + DMA_SLAVE_BUSWIDTH_2_BYTES, 1047 + .src_maxburst = 1, 1048 + .dst_maxburst = 1, 1049 + .direction = DMA_MEM_TO_DEV, 1050 + .device_fc = false, 1051 + }; 1052 + 1053 + dmaengine_slave_config(chip->dma.tx_chan, 1054 + &dma_conf); 1055 + } 1057 1056 1058 1057 dev_info(&chip->pdev->dev, "using %s for DMA TX\n", 1059 1058 dev_name(&chip->dma.tx_chan->dev->device));
+3
sound/soc/imx/imx-pcm-dma-mx2.c
··· 21 21 #include <linux/platform_device.h> 22 22 #include <linux/slab.h> 23 23 #include <linux/dmaengine.h> 24 + #include <linux/types.h> 24 25 25 26 #include <sound/core.h> 26 27 #include <sound/initval.h> ··· 58 57 ret = snd_hwparams_to_dma_slave_config(substream, params, &slave_config); 59 58 if (ret) 60 59 return ret; 60 + 61 + slave_config.device_fc = false; 61 62 62 63 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 63 64 slave_config.dst_addr = dma_params->dma_addr;
+2 -2
sound/soc/sh/siu_pcm.c
··· 130 130 sg_dma_len(&sg) = size; 131 131 sg_dma_address(&sg) = buff; 132 132 133 - desc = siu_stream->chan->device->device_prep_slave_sg(siu_stream->chan, 133 + desc = dmaengine_prep_slave_sg(siu_stream->chan, 134 134 &sg, 1, DMA_MEM_TO_DEV, DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 135 135 if (!desc) { 136 136 dev_err(dev, "Failed to allocate a dma descriptor\n"); ··· 180 180 sg_dma_len(&sg) = size; 181 181 sg_dma_address(&sg) = buff; 182 182 183 - desc = siu_stream->chan->device->device_prep_slave_sg(siu_stream->chan, 183 + desc = dmaengine_prep_slave_sg(siu_stream->chan, 184 184 &sg, 1, DMA_DEV_TO_MEM, DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 185 185 if (!desc) { 186 186 dev_err(dev, "Failed to allocate dma descriptor\n");
+1 -1
sound/soc/txx9/txx9aclc.c
··· 132 132 sg_set_page(&sg, pfn_to_page(PFN_DOWN(buf_dma_addr)), 133 133 dmadata->frag_bytes, buf_dma_addr & (PAGE_SIZE - 1)); 134 134 sg_dma_address(&sg) = buf_dma_addr; 135 - desc = chan->device->device_prep_slave_sg(chan, &sg, 1, 135 + desc = dmaengine_prep_slave_sg(chan, &sg, 1, 136 136 dmadata->substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? 137 137 DMA_MEM_TO_DEV : DMA_DEV_TO_MEM, 138 138 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);