// SPDX-License-Identifier: GPL-2.0-or-later/* * Copyright (c) 2012 Samsung Electronics Co., Ltd. * http://www.samsung.com * * Copyright (C) 2010 Samsung Electronics Co. Ltd. * Jaswinder Singh <jassi.brar@samsung.com> */ #include <linux/debugfs.h>#include <linux/kernel.h>#include <linux/io.h>#include <linux/init.h>#include <linux/slab.h>#include <linux/module.h>#include <linux/string.h>#include <linux/delay.h>#include <linux/interrupt.h>#include <linux/dma-mapping.h>#include <linux/dmaengine.h>#include <linux/amba/bus.h>#include <linux/scatterlist.h>#include <linux/of.h>#include <linux/of_dma.h>#include <linux/err.h>#include <linux/pm_runtime.h>#include <linux/bug.h>#include <linux/reset.h> #include "dmaengine.h"#define PL330_MAX_CHAN 8#define PL330_MAX_IRQS 32#define PL330_MAX_PERI 32#define PL330_MAX_BURST 16 #define PL330_QUIRK_BROKEN_NO_FLUSHP BIT(0)#define PL330_QUIRK_PERIPH_BURST BIT(1) enum pl330_cachectrl { CCTRL0, /* Noncacheable and nonbufferable */ CCTRL1, /* Bufferable only */ CCTRL2, /* Cacheable, but do not allocate */ CCTRL3, /* Cacheable and bufferable, but do not allocate */ INVALID1, /* AWCACHE = 0x1000 */ INVALID2, CCTRL6, /* Cacheable write-through, allocate on writes only */ CCTRL7, /* Cacheable write-back, allocate on writes only */}; enum pl330_byteswap { SWAP_NO, SWAP_2, SWAP_4, SWAP_8, SWAP_16,}; /* Register and Bit field Definitions */#define DS 0x0#define DS_ST_STOP 0x0#define DS_ST_EXEC 0x1#define DS_ST_CMISS 0x2#define DS_ST_UPDTPC 0x3#define DS_ST_WFE 0x4#define DS_ST_ATBRR 0x5#define DS_ST_QBUSY 0x6#define DS_ST_WFP 0x7#define DS_ST_KILL 0x8#define DS_ST_CMPLT 0x9#define DS_ST_FLTCMP 0xe#define DS_ST_FAULT 0xf #define DPC 0x4#define INTEN 0x20#define ES 0x24#define INTSTATUS 0x28#define INTCLR 0x2c#define FSM 0x30#define FSC 0x34#define FTM 0x38 #define _FTC 0x40#define FTC(n) (_FTC + (n)*0x4) #define _CS 0x100#define CS(n) (_CS + (n)*0x8)#define CS_CNS (1 << 21) #define _CPC 0x104#define CPC(n) (_CPC + (n)*0x8) #define _SA 0x400#define SA(n) (_SA + (n)*0x20) #define _DA 0x404#define DA(n) (_DA + (n)*0x20) #define _CC 0x408#define CC(n) (_CC + (n)*0x20) #define CC_SRCINC (1 << 0)#define CC_DSTINC (1 << 14)#define CC_SRCPRI (1 << 8)#define CC_DSTPRI (1 << 22)#define CC_SRCNS (1 << 9)#define CC_DSTNS (1 << 23)#define CC_SRCIA (1 << 10)#define CC_DSTIA (1 << 24)#define CC_SRCBRSTLEN_SHFT 4#define CC_DSTBRSTLEN_SHFT 18#define CC_SRCBRSTSIZE_SHFT 1#define CC_DSTBRSTSIZE_SHFT 15#define CC_SRCCCTRL_SHFT 11#define CC_SRCCCTRL_MASK 0x7#define CC_DSTCCTRL_SHFT 25#define CC_DRCCCTRL_MASK 0x7#define CC_SWAP_SHFT 28 #define _LC0 0x40c#define LC0(n) (_LC0 + (n)*0x20) #define _LC1 0x410#define LC1(n) (_LC1 + (n)*0x20) #define DBGSTATUS 0xd00#define DBG_BUSY (1 << 0) #define DBGCMD 0xd04#define DBGINST0 0xd08#define DBGINST1 0xd0c #define CR0 0xe00#define CR1 0xe04#define CR2 0xe08#define CR3 0xe0c#define CR4 0xe10#define CRD 0xe14 #define PERIPH_ID 0xfe0#define PERIPH_REV_SHIFT 20#define PERIPH_REV_MASK 0xf#define PERIPH_REV_R0P0 0#define PERIPH_REV_R1P0 1#define PERIPH_REV_R1P1 2 #define CR0_PERIPH_REQ_SET (1 << 0)#define CR0_BOOT_EN_SET (1 << 1)#define CR0_BOOT_MAN_NS (1 << 2)#define CR0_NUM_CHANS_SHIFT 4#define CR0_NUM_CHANS_MASK 0x7#define CR0_NUM_PERIPH_SHIFT 12#define CR0_NUM_PERIPH_MASK 0x1f#define CR0_NUM_EVENTS_SHIFT 17#define CR0_NUM_EVENTS_MASK 0x1f #define CR1_ICACHE_LEN_SHIFT 0#define CR1_ICACHE_LEN_MASK 0x7#define CR1_NUM_ICACHELINES_SHIFT 4#define CR1_NUM_ICACHELINES_MASK 0xf #define CRD_DATA_WIDTH_SHIFT 0#define CRD_DATA_WIDTH_MASK 0x7#define CRD_WR_CAP_SHIFT 4#define CRD_WR_CAP_MASK 0x7#define CRD_WR_Q_DEP_SHIFT 8#define CRD_WR_Q_DEP_MASK 0xf#define CRD_RD_CAP_SHIFT 12#define CRD_RD_CAP_MASK 0x7#define CRD_RD_Q_DEP_SHIFT 16#define CRD_RD_Q_DEP_MASK 0xf#define CRD_DATA_BUFF_SHIFT 20#define CRD_DATA_BUFF_MASK 0x3ff #define PART 0x330#define DESIGNER 0x41#define REVISION 0x0#define INTEG_CFG 0x0#define PERIPH_ID_VAL ((PART << 0) | (DESIGNER << 12)) #define PL330_STATE_STOPPED (1 << 0)#define PL330_STATE_EXECUTING (1 << 1)#define PL330_STATE_WFE (1 << 2)#define PL330_STATE_FAULTING (1 << 3)#define PL330_STATE_COMPLETING (1 << 4)#define PL330_STATE_WFP (1 << 5)#define PL330_STATE_KILLING (1 << 6)#define PL330_STATE_FAULT_COMPLETING (1 << 7)#define PL330_STATE_CACHEMISS (1 << 8)#define PL330_STATE_UPDTPC (1 << 9)#define PL330_STATE_ATBARRIER (1 << 10)#define PL330_STATE_QUEUEBUSY (1 << 11)#define PL330_STATE_INVALID (1 << 15) #define PL330_STABLE_STATES (PL330_STATE_STOPPED | PL330_STATE_EXECUTING \ | PL330_STATE_WFE | PL330_STATE_FAULTING) #define CMD_DMAADDH 0x54#define CMD_DMAEND 0x00#define CMD_DMAFLUSHP 0x35#define CMD_DMAGO 0xa0#define CMD_DMALD 0x04#define CMD_DMALDP 0x25#define CMD_DMALP 0x20#define CMD_DMALPEND 0x28#define CMD_DMAKILL 0x01#define CMD_DMAMOV 0xbc#define CMD_DMANOP 0x18#define CMD_DMARMB 0x12#define CMD_DMASEV 0x34#define CMD_DMAST 0x08#define CMD_DMASTP 0x29#define CMD_DMASTZ 0x0c#define CMD_DMAWFE 0x36#define CMD_DMAWFP 0x30#define CMD_DMAWMB 0x13 #define SZ_DMAADDH 3#define SZ_DMAEND 1#define SZ_DMAFLUSHP 2#define SZ_DMALD 1#define SZ_DMALDP 2#define SZ_DMALP 2#define SZ_DMALPEND 2#define SZ_DMAKILL 1#define SZ_DMAMOV 6#define SZ_DMANOP 1#define SZ_DMARMB 1#define SZ_DMASEV 2#define SZ_DMAST 1#define SZ_DMASTP 2#define SZ_DMASTZ 1#define SZ_DMAWFE 2#define SZ_DMAWFP 2#define SZ_DMAWMB 1#define SZ_DMAGO 6 #define BRST_LEN(ccr) ((((ccr) >> CC_SRCBRSTLEN_SHFT) & 0xf) + 1)#define BRST_SIZE(ccr) (1 << (((ccr) >> CC_SRCBRSTSIZE_SHFT) & 0x7)) #define BYTE_TO_BURST(b, ccr) ((b) / BRST_SIZE(ccr) / BRST_LEN(ccr))#define BURST_TO_BYTE(c, ccr) ((c) * BRST_SIZE(ccr) * BRST_LEN(ccr)) /* * With 256 bytes, we can do more than 2.5MB and 5MB xfers per req * at 1byte/burst for P<->M and M<->M respectively. * For typical scenario, at 1word/burst, 10MB and 20MB xfers per req * should be enough for P<->M and M<->M respectively. */#define MCODE_BUFF_PER_REQ 256 /* Use this _only_ to wait on transient states */#define UNTIL(t, s) while (!(_state(t) & (s))) cpu_relax(); #ifdef PL330_DEBUG_MCGENstatic unsigned cmd_line;#define PL330_DBGCMD_DUMP(off, x...) do { \ printk("%x:", cmd_line); \ printk(KERN_CONT x); \ cmd_line += off; \ } while (0)#define PL330_DBGMC_START(addr) (cmd_line = addr)#else#define PL330_DBGCMD_DUMP(off, x...) do {} while (0)#define PL330_DBGMC_START(addr) do {} while (0)#endif /* The number of default descriptors */ #define NR_DEFAULT_DESC 16 /* Delay for runtime PM autosuspend, ms */#define PL330_AUTOSUSPEND_DELAY 20 /* Populated by the PL330 core driver for DMA API driver's info */struct pl330_config { u32 periph_id;#define DMAC_MODE_NS (1 << 0) unsigned int mode; unsigned int data_bus_width:10; /* In number of bits */ unsigned int data_buf_dep:11; unsigned int num_chan:4; unsigned int num_peri:6; u32 peri_ns; unsigned int num_events:6; u32 irq_ns;}; /* * Request Configuration. * The PL330 core does not modify this and uses the last * working configuration if the request doesn't provide any. * * The Client may want to provide this info only for the * first request and a request with new settings. */struct pl330_reqcfg { /* Address Incrementing */ unsigned dst_inc:1; unsigned src_inc:1; /* * For now, the SRC & DST protection levels * and burst size/length are assumed same. */ bool nonsecure; bool privileged; bool insnaccess; unsigned brst_len:5; unsigned brst_size:3; /* in power of 2 */ enum pl330_cachectrl dcctl; enum pl330_cachectrl scctl; enum pl330_byteswap swap; struct pl330_config *pcfg;}; /* * One cycle of DMAC operation. * There may be more than one xfer in a request. */struct pl330_xfer { u32 src_addr; u32 dst_addr; /* Size to xfer */ u32 bytes;}; /* The xfer callbacks are made with one of these arguments. */enum pl330_op_err { /* The all xfers in the request were success. */ PL330_ERR_NONE, /* If req aborted due to global error. */ PL330_ERR_ABORT, /* If req failed due to problem with Channel. */ PL330_ERR_FAIL,}; enum dmamov_dst { SAR = 0, CCR, DAR,}; enum pl330_dst { SRC = 0, DST,}; enum pl330_cond { SINGLE, BURST, ALWAYS,}; struct dma_pl330_desc; struct _pl330_req { u32 mc_bus; void *mc_cpu; struct dma_pl330_desc *desc;}; /* ToBeDone for tasklet */struct _pl330_tbd { bool reset_dmac; bool reset_mngr; u8 reset_chan;}; /* A DMAC Thread */struct pl330_thread { u8 id; int ev; /* If the channel is not yet acquired by any client */ bool free; /* Parent DMAC */ struct pl330_dmac *dmac; /* Only two at a time */ struct _pl330_req req[2]; /* Index of the last enqueued request */ unsigned lstenq; /* Index of the last submitted request or -1 if the DMA is stopped */ int req_running;}; enum pl330_dmac_state { UNINIT, INIT, DYING,}; enum desc_status { /* In the DMAC pool */ FREE, /* * Allocated to some channel during prep_xxx * Also may be sitting on the work_list. */ PREP, /* * Sitting on the work_list and already submitted * to the PL330 core. Not more than two descriptors * of a channel can be BUSY at any time. */ BUSY, /* * Pause was called while descriptor was BUSY. Due to hardware * limitations, only termination is possible for descriptors * that have been paused. */ PAUSED, /* * Sitting on the channel work_list but xfer done * by PL330 core */ DONE,}; struct dma_pl330_chan { /* Schedule desc completion */ struct tasklet_struct task; /* DMA-Engine Channel */ struct dma_chan chan; /* List of submitted descriptors */ struct list_head submitted_list; /* List of issued descriptors */ struct list_head work_list; /* List of completed descriptors */ struct list_head completed_list; /* Pointer to the DMAC that manages this channel, * NULL if the channel is available to be acquired. * As the parent, this DMAC also provides descriptors * to the channel. */ struct pl330_dmac *dmac; /* To protect channel manipulation */ spinlock_t lock; /* * Hardware channel thread of PL330 DMAC. NULL if the channel is * available. */ struct pl330_thread *thread; /* For D-to-M and M-to-D channels */ int burst_sz; /* the peripheral fifo width */ int burst_len; /* the number of burst */ phys_addr_t fifo_addr; /* DMA-mapped view of the FIFO; may differ if an IOMMU is present */ dma_addr_t fifo_dma; enum dma_data_direction dir; struct dma_slave_config slave_config; /* for cyclic capability */ bool cyclic; /* for runtime pm tracking */ bool active;}; struct pl330_dmac { /* DMA-Engine Device */ struct dma_device ddma; /* Pool of descriptors available for the DMAC's channels */ struct list_head desc_pool; /* To protect desc_pool manipulation */ spinlock_t pool_lock; /* Size of MicroCode buffers for each channel. */ unsigned mcbufsz; /* ioremap'ed address of PL330 registers. */ void __iomem *base; /* Populated by the PL330 core driver during pl330_add */ struct pl330_config pcfg; spinlock_t lock; /* Maximum possible events/irqs */ int events[32]; /* BUS address of MicroCode buffer */ dma_addr_t mcode_bus; /* CPU address of MicroCode buffer */ void *mcode_cpu; /* List of all Channel threads */ struct pl330_thread *channels; /* Pointer to the MANAGER thread */ struct pl330_thread *manager; /* To handle bad news in interrupt */ struct tasklet_struct tasks; struct _pl330_tbd dmac_tbd; /* State of DMAC operation */ enum pl330_dmac_state state; /* Holds list of reqs with due callbacks */ struct list_head req_done; /* Peripheral channels connected to this DMAC */Lines 1–500 of 3280. Load more
// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) 2012 Samsung Electronics Co., Ltd. * http://www.samsung.com * * Copyright (C) 2010 Samsung Electronics Co. Ltd. * Jaswinder Singh <jassi.brar@samsung.com> */ #include <linux/debugfs.h> #include <linux/kernel.h> #include <linux/io.h> #include <linux/init.h> #include <linux/slab.h> #include <linux/module.h> #include <linux/string.h> #include <linux/delay.h> #include <linux/interrupt.h> #include <linux/dma-mapping.h> #include <linux/dmaengine.h> #include <linux/amba/bus.h> #include <linux/scatterlist.h> #include <linux/of.h> #include <linux/of_dma.h> #include <linux/err.h> #include <linux/pm_runtime.h> #include <linux/bug.h> #include <linux/reset.h> #include "dmaengine.h" #define PL330_MAX_CHAN 8 #define PL330_MAX_IRQS 32 #define PL330_MAX_PERI 32 #define PL330_MAX_BURST 16 #define PL330_QUIRK_BROKEN_NO_FLUSHP BIT(0) #define PL330_QUIRK_PERIPH_BURST BIT(1) enum pl330_cachectrl { CCTRL0, /* Noncacheable and nonbufferable */ CCTRL1, /* Bufferable only */ CCTRL2, /* Cacheable, but do not allocate */ CCTRL3, /* Cacheable and bufferable, but do not allocate */ INVALID1, /* AWCACHE = 0x1000 */ INVALID2, CCTRL6, /* Cacheable write-through, allocate on writes only */ CCTRL7, /* Cacheable write-back, allocate on writes only */ }; enum pl330_byteswap { SWAP_NO, SWAP_2, SWAP_4, SWAP_8, SWAP_16, }; /* Register and Bit field Definitions */ #define DS 0x0 #define DS_ST_STOP 0x0 #define DS_ST_EXEC 0x1 #define DS_ST_CMISS 0x2 #define DS_ST_UPDTPC 0x3 #define DS_ST_WFE 0x4 #define DS_ST_ATBRR 0x5 #define DS_ST_QBUSY 0x6 #define DS_ST_WFP 0x7 #define DS_ST_KILL 0x8 #define DS_ST_CMPLT 0x9 #define DS_ST_FLTCMP 0xe #define DS_ST_FAULT 0xf #define DPC 0x4 #define INTEN 0x20 #define ES 0x24 #define INTSTATUS 0x28 #define INTCLR 0x2c #define FSM 0x30 #define FSC 0x34 #define FTM 0x38 #define _FTC 0x40 #define FTC(n) (_FTC + (n)*0x4) #define _CS 0x100 #define CS(n) (_CS + (n)*0x8) #define CS_CNS (1 << 21) #define _CPC 0x104 #define CPC(n) (_CPC + (n)*0x8) #define _SA 0x400 #define SA(n) (_SA + (n)*0x20) #define _DA 0x404 #define DA(n) (_DA + (n)*0x20) #define _CC 0x408 #define CC(n) (_CC + (n)*0x20) #define CC_SRCINC (1 << 0) #define CC_DSTINC (1 << 14) #define CC_SRCPRI (1 << 8) #define CC_DSTPRI (1 << 22) #define CC_SRCNS (1 << 9) #define CC_DSTNS (1 << 23) #define CC_SRCIA (1 << 10) #define CC_DSTIA (1 << 24) #define CC_SRCBRSTLEN_SHFT 4 #define CC_DSTBRSTLEN_SHFT 18 #define CC_SRCBRSTSIZE_SHFT 1 #define CC_DSTBRSTSIZE_SHFT 15 #define CC_SRCCCTRL_SHFT 11 #define CC_SRCCCTRL_MASK 0x7 #define CC_DSTCCTRL_SHFT 25 #define CC_DRCCCTRL_MASK 0x7 #define CC_SWAP_SHFT 28 #define _LC0 0x40c #define LC0(n) (_LC0 + (n)*0x20) #define _LC1 0x410 #define LC1(n) (_LC1 + (n)*0x20) #define DBGSTATUS 0xd00 #define DBG_BUSY (1 << 0) #define DBGCMD 0xd04 #define DBGINST0 0xd08 #define DBGINST1 0xd0c #define CR0 0xe00 #define CR1 0xe04 #define CR2 0xe08 #define CR3 0xe0c #define CR4 0xe10 #define CRD 0xe14 #define PERIPH_ID 0xfe0 #define PERIPH_REV_SHIFT 20 #define PERIPH_REV_MASK 0xf #define PERIPH_REV_R0P0 0 #define PERIPH_REV_R1P0 1 #define PERIPH_REV_R1P1 2 #define CR0_PERIPH_REQ_SET (1 << 0) #define CR0_BOOT_EN_SET (1 << 1) #define CR0_BOOT_MAN_NS (1 << 2) #define CR0_NUM_CHANS_SHIFT 4 #define CR0_NUM_CHANS_MASK 0x7 #define CR0_NUM_PERIPH_SHIFT 12 #define CR0_NUM_PERIPH_MASK 0x1f #define CR0_NUM_EVENTS_SHIFT 17 #define CR0_NUM_EVENTS_MASK 0x1f #define CR1_ICACHE_LEN_SHIFT 0 #define CR1_ICACHE_LEN_MASK 0x7 #define CR1_NUM_ICACHELINES_SHIFT 4 #define CR1_NUM_ICACHELINES_MASK 0xf #define CRD_DATA_WIDTH_SHIFT 0 #define CRD_DATA_WIDTH_MASK 0x7 #define CRD_WR_CAP_SHIFT 4 #define CRD_WR_CAP_MASK 0x7 #define CRD_WR_Q_DEP_SHIFT 8 #define CRD_WR_Q_DEP_MASK 0xf #define CRD_RD_CAP_SHIFT 12 #define CRD_RD_CAP_MASK 0x7 #define CRD_RD_Q_DEP_SHIFT 16 #define CRD_RD_Q_DEP_MASK 0xf #define CRD_DATA_BUFF_SHIFT 20 #define CRD_DATA_BUFF_MASK 0x3ff #define PART 0x330 #define DESIGNER 0x41 #define REVISION 0x0 #define INTEG_CFG 0x0 #define PERIPH_ID_VAL ((PART << 0) | (DESIGNER << 12)) #define PL330_STATE_STOPPED (1 << 0) #define PL330_STATE_EXECUTING (1 << 1) #define PL330_STATE_WFE (1 << 2) #define PL330_STATE_FAULTING (1 << 3) #define PL330_STATE_COMPLETING (1 << 4) #define PL330_STATE_WFP (1 << 5) #define PL330_STATE_KILLING (1 << 6) #define PL330_STATE_FAULT_COMPLETING (1 << 7) #define PL330_STATE_CACHEMISS (1 << 8) #define PL330_STATE_UPDTPC (1 << 9) #define PL330_STATE_ATBARRIER (1 << 10) #define PL330_STATE_QUEUEBUSY (1 << 11) #define PL330_STATE_INVALID (1 << 15) #define PL330_STABLE_STATES (PL330_STATE_STOPPED | PL330_STATE_EXECUTING \ | PL330_STATE_WFE | PL330_STATE_FAULTING) #define CMD_DMAADDH 0x54 #define CMD_DMAEND 0x00 #define CMD_DMAFLUSHP 0x35 #define CMD_DMAGO 0xa0 #define CMD_DMALD 0x04 #define CMD_DMALDP 0x25 #define CMD_DMALP 0x20 #define CMD_DMALPEND 0x28 #define CMD_DMAKILL 0x01 #define CMD_DMAMOV 0xbc #define CMD_DMANOP 0x18 #define CMD_DMARMB 0x12 #define CMD_DMASEV 0x34 #define CMD_DMAST 0x08 #define CMD_DMASTP 0x29 #define CMD_DMASTZ 0x0c #define CMD_DMAWFE 0x36 #define CMD_DMAWFP 0x30 #define CMD_DMAWMB 0x13 #define SZ_DMAADDH 3 #define SZ_DMAEND 1 #define SZ_DMAFLUSHP 2 #define SZ_DMALD 1 #define SZ_DMALDP 2 #define SZ_DMALP 2 #define SZ_DMALPEND 2 #define SZ_DMAKILL 1 #define SZ_DMAMOV 6 #define SZ_DMANOP 1 #define SZ_DMARMB 1 #define SZ_DMASEV 2 #define SZ_DMAST 1 #define SZ_DMASTP 2 #define SZ_DMASTZ 1 #define SZ_DMAWFE 2 #define SZ_DMAWFP 2 #define SZ_DMAWMB 1 #define SZ_DMAGO 6 #define BRST_LEN(ccr) ((((ccr) >> CC_SRCBRSTLEN_SHFT) & 0xf) + 1) #define BRST_SIZE(ccr) (1 << (((ccr) >> CC_SRCBRSTSIZE_SHFT) & 0x7)) #define BYTE_TO_BURST(b, ccr) ((b) / BRST_SIZE(ccr) / BRST_LEN(ccr)) #define BURST_TO_BYTE(c, ccr) ((c) * BRST_SIZE(ccr) * BRST_LEN(ccr)) /* * With 256 bytes, we can do more than 2.5MB and 5MB xfers per req * at 1byte/burst for P<->M and M<->M respectively. * For typical scenario, at 1word/burst, 10MB and 20MB xfers per req * should be enough for P<->M and M<->M respectively. */ #define MCODE_BUFF_PER_REQ 256 /* Use this _only_ to wait on transient states */ #define UNTIL(t, s) while (!(_state(t) & (s))) cpu_relax(); #ifdef PL330_DEBUG_MCGEN static unsigned cmd_line; #define PL330_DBGCMD_DUMP(off, x...) do { \ printk("%x:", cmd_line); \ printk(KERN_CONT x); \ cmd_line += off; \ } while (0) #define PL330_DBGMC_START(addr) (cmd_line = addr) #else #define PL330_DBGCMD_DUMP(off, x...) do {} while (0) #define PL330_DBGMC_START(addr) do {} while (0) #endif /* The number of default descriptors */ #define NR_DEFAULT_DESC 16 /* Delay for runtime PM autosuspend, ms */ #define PL330_AUTOSUSPEND_DELAY 20 /* Populated by the PL330 core driver for DMA API driver's info */ struct pl330_config { u32 periph_id; #define DMAC_MODE_NS (1 << 0) unsigned int mode; unsigned int data_bus_width:10; /* In number of bits */ unsigned int data_buf_dep:11; unsigned int num_chan:4; unsigned int num_peri:6; u32 peri_ns; unsigned int num_events:6; u32 irq_ns; }; /* * Request Configuration. * The PL330 core does not modify this and uses the last * working configuration if the request doesn't provide any. * * The Client may want to provide this info only for the * first request and a request with new settings. */ struct pl330_reqcfg { /* Address Incrementing */ unsigned dst_inc:1; unsigned src_inc:1; /* * For now, the SRC & DST protection levels * and burst size/length are assumed same. */ bool nonsecure; bool privileged; bool insnaccess; unsigned brst_len:5; unsigned brst_size:3; /* in power of 2 */ enum pl330_cachectrl dcctl; enum pl330_cachectrl scctl; enum pl330_byteswap swap; struct pl330_config *pcfg; }; /* * One cycle of DMAC operation. * There may be more than one xfer in a request. */ struct pl330_xfer { u32 src_addr; u32 dst_addr; /* Size to xfer */ u32 bytes; }; /* The xfer callbacks are made with one of these arguments. */ enum pl330_op_err { /* The all xfers in the request were success. */ PL330_ERR_NONE, /* If req aborted due to global error. */ PL330_ERR_ABORT, /* If req failed due to problem with Channel. */ PL330_ERR_FAIL, }; enum dmamov_dst { SAR = 0, CCR, DAR, }; enum pl330_dst { SRC = 0, DST, }; enum pl330_cond { SINGLE, BURST, ALWAYS, }; struct dma_pl330_desc; struct _pl330_req { u32 mc_bus; void *mc_cpu; struct dma_pl330_desc *desc; }; /* ToBeDone for tasklet */ struct _pl330_tbd { bool reset_dmac; bool reset_mngr; u8 reset_chan; }; /* A DMAC Thread */ struct pl330_thread { u8 id; int ev; /* If the channel is not yet acquired by any client */ bool free; /* Parent DMAC */ struct pl330_dmac *dmac; /* Only two at a time */ struct _pl330_req req[2]; /* Index of the last enqueued request */ unsigned lstenq; /* Index of the last submitted request or -1 if the DMA is stopped */ int req_running; }; enum pl330_dmac_state { UNINIT, INIT, DYING, }; enum desc_status { /* In the DMAC pool */ FREE, /* * Allocated to some channel during prep_xxx * Also may be sitting on the work_list. */ PREP, /* * Sitting on the work_list and already submitted * to the PL330 core. Not more than two descriptors * of a channel can be BUSY at any time. */ BUSY, /* * Pause was called while descriptor was BUSY. Due to hardware * limitations, only termination is possible for descriptors * that have been paused. */ PAUSED, /* * Sitting on the channel work_list but xfer done * by PL330 core */ DONE, }; struct dma_pl330_chan { /* Schedule desc completion */ struct tasklet_struct task; /* DMA-Engine Channel */ struct dma_chan chan; /* List of submitted descriptors */ struct list_head submitted_list; /* List of issued descriptors */ struct list_head work_list; /* List of completed descriptors */ struct list_head completed_list; /* Pointer to the DMAC that manages this channel, * NULL if the channel is available to be acquired. * As the parent, this DMAC also provides descriptors * to the channel. */ struct pl330_dmac *dmac; /* To protect channel manipulation */ spinlock_t lock; /* * Hardware channel thread of PL330 DMAC. NULL if the channel is * available. */ struct pl330_thread *thread; /* For D-to-M and M-to-D channels */ int burst_sz; /* the peripheral fifo width */ int burst_len; /* the number of burst */ phys_addr_t fifo_addr; /* DMA-mapped view of the FIFO; may differ if an IOMMU is present */ dma_addr_t fifo_dma; enum dma_data_direction dir; struct dma_slave_config slave_config; /* for cyclic capability */ bool cyclic; /* for runtime pm tracking */ bool active; }; struct pl330_dmac { /* DMA-Engine Device */ struct dma_device ddma; /* Pool of descriptors available for the DMAC's channels */ struct list_head desc_pool; /* To protect desc_pool manipulation */ spinlock_t pool_lock; /* Size of MicroCode buffers for each channel. */ unsigned mcbufsz; /* ioremap'ed address of PL330 registers. */ void __iomem *base; /* Populated by the PL330 core driver during pl330_add */ struct pl330_config pcfg; spinlock_t lock; /* Maximum possible events/irqs */ int events[32]; /* BUS address of MicroCode buffer */ dma_addr_t mcode_bus; /* CPU address of MicroCode buffer */ void *mcode_cpu; /* List of all Channel threads */ struct pl330_thread *channels; /* Pointer to the MANAGER thread */ struct pl330_thread *manager; /* To handle bad news in interrupt */ struct tasklet_struct tasks; struct _pl330_tbd dmac_tbd; /* State of DMAC operation */ enum pl330_dmac_state state; /* Holds list of reqs with due callbacks */ struct list_head req_done; /* Peripheral channels connected to this DMAC */