No subject


Fri Nov 6 13:01:15 EST 2009


need something like this is the AMBA PL011 UART driver, RX part,
where data comes in from the outside and we have no control over
the data flow. I trigger one transfer to a buffer here, then wait for it
to complete or be interrupted. If it completes, I immediately trigger
another transfer to the second buffer before I start processing the just
recieved buffer (like front/back buffers).

I just hope that this will always be fast enough, queueing two transfers
after each other at the same time first would perhaps be better if the
hardware can handle it, now we have no hardware that can actually
queue that up so we can work it over the day we see something like
that...

(I don't know if I'm making myself clear, the PL011 patch may
speak for itself rather.)

> o =A0TODO: PAUSE/RESUME support. Currently the DMA API driver has to emul=
ate it.

The only PrimeCell that needs this is currently again the PL011.
It needs to PAUSE then get the number of pending bytes and then
terminate the transfer. This is done when we timeout transfers e.g.
for UART consoles. So being able to pause and retrieve the number
of bytes left and then cancel is the most advanced sequence that
will be used by a PrimeCell currently.

I've seen sample PCM/I2S drivers that wants PAUSE/RESUME though.

(...)
> Basic PL330 engine driver
>
> Signed-off-by: Jassi Brar <jassi.brar at samsung.com>
> ---
> =A0arch/arm/common/Kconfig =A0 =A0 =A0 =A0 =A0 =A0 =A0 | =A0 =A03 +
> =A0arch/arm/common/Makefile =A0 =A0 =A0 =A0 =A0 =A0 =A0| =A0 =A01 +
> =A0arch/arm/common/pl330.c =A0 =A0 =A0 =A0 =A0 =A0 =A0 | 1891 +++++++++++=
++++++++++++++++++++++
> =A0arch/arm/include/asm/hardware/pl330.h | =A0197 ++++
> =A04 files changed, 2092 insertions(+), 0 deletions(-)
> =A0create mode 100644 arch/arm/common/pl330.c
> =A0create mode 100644 arch/arm/include/asm/hardware/pl330.h

Contemplate moving all but the header file to drivers/dma (not that I
have any strong feelings about it, just feels right).

(...)
> +/* Register and Bit field Definitions */
> +#define DS =A0 =A0 =A0 =A0 =A0 =A0 0x0
> +#define DS_ST_STOP =A0 =A0 0x0
> +#define DS_ST_EXEC =A0 =A0 0x1
> +#define DS_ST_CMISS =A0 =A00x2
> +#define DS_ST_UPDTPC =A0 0x3
> +#define DS_ST_WFE =A0 =A0 =A00x4
> +#define DS_ST_ATBRR =A0 =A00x5
> +#define DS_ST_QBUSY =A0 =A00x6
> +#define DS_ST_WFP =A0 =A0 =A00x7
> +#define DS_ST_KILL =A0 =A0 0x8
> +#define DS_ST_CMPLT =A0 =A00x9
> +#define DS_ST_FLTCMP =A0 0xe
> +#define DS_ST_FAULT =A0 =A00xf
> +
> +#define DPC =A0 =A0 =A0 =A0 =A0 =A00x4
> +#define INTEN =A0 =A0 =A0 =A0 =A00x20
> +#define ES =A0 =A0 =A0 =A0 =A0 =A0 0x24
> +#define INTSTATUS =A0 =A0 =A00x28
> +#define INTCLR =A0 =A0 =A0 =A0 0x2c
> +#define FSM =A0 =A0 =A0 =A0 =A0 =A00x30
> +#define FSC =A0 =A0 =A0 =A0 =A0 =A00x34
> +#define FTM =A0 =A0 =A0 =A0 =A0 =A00x38
> +
> +#define _FTC =A0 =A0 =A0 =A0 =A0 0x40
> +#define FTC(n) =A0 =A0 =A0 =A0 (_FTC + (n)*0x4)
> +
> +#define _CS =A0 =A0 =A0 =A0 =A0 =A00x100
> +#define CS(n) =A0 =A0 =A0 =A0 =A0(_CS + (n)*0x8)
> +#define CS_CNS =A0 =A0 =A0 =A0 (1 << 21)
> +
> +#define _CPC =A0 =A0 =A0 =A0 =A0 0x104
> +#define CPC(n) =A0 =A0 =A0 =A0 (_CPC + (n)*0x8)
> +
> +#define _SA =A0 =A0 =A0 =A0 =A0 =A00x400
> +#define SA(n) =A0 =A0 =A0 =A0 =A0(_SA + (n)*0x20)
> +
> +#define _DA =A0 =A0 =A0 =A0 =A0 =A00x404
> +#define DA(n) =A0 =A0 =A0 =A0 =A0(_DA + (n)*0x20)
> +
> +#define _CC =A0 =A0 =A0 =A0 =A0 =A00x408
> +#define CC(n) =A0 =A0 =A0 =A0 =A0(_CC + (n)*0x20)
> +
> +#define CC_SRCINC =A0 =A0 =A0(1 << 0)
> +#define CC_DSTINC =A0 =A0 =A0(1 << 14)
> +#define CC_SRCPRI =A0 =A0 =A0(1 << 8)
> +#define CC_DSTPRI =A0 =A0 =A0(1 << 22)
> +#define CC_SRCNS =A0 =A0 =A0 (1 << 9)
> +#define CC_DSTNS =A0 =A0 =A0 (1 << 23)
> +#define CC_SRCIA =A0 =A0 =A0 (1 << 10)
> +#define CC_DSTIA =A0 =A0 =A0 (1 << 24)
> +#define CC_SRCBRSTLEN_SHFT =A0 =A0 4
> +#define CC_DSTBRSTLEN_SHFT =A0 =A0 18
> +#define CC_SRCBRSTSIZE_SHFT =A0 =A01
> +#define CC_DSTBRSTSIZE_SHFT =A0 =A015
> +#define CC_SRCCCTRL_SHFT =A0 =A0 =A0 11
> +#define CC_SRCCCTRL_MASK =A0 =A0 =A0 0x7
> +#define CC_DSTCCTRL_SHFT =A0 =A0 =A0 25
> +#define CC_DRCCCTRL_MASK =A0 =A0 =A0 0x7
> +#define CC_SWAP_SHFT =A0 28
> +
> +#define _LC0 =A0 =A0 =A0 =A0 =A0 0x40c
> +#define LC0(n) =A0 =A0 =A0 =A0 (_LC0 + (n)*0x20)
> +
> +#define _LC1 =A0 =A0 =A0 =A0 =A0 0x410
> +#define LC1(n) =A0 =A0 =A0 =A0 (_LC1 + (n)*0x20)
> +
> +#define DBGSTATUS =A0 =A0 =A00xd00
> +#define DBG_BUSY =A0 =A0 =A0 (1 << 0)
> +
> +#define DBGCMD =A0 =A0 =A0 =A0 0xd04
> +#define DBGINST0 =A0 =A0 =A0 0xd08
> +#define DBGINST1 =A0 =A0 =A0 0xd0c
> +
> +#define CR0 =A0 =A0 =A0 =A0 =A0 =A00xe00
> +#define CR1 =A0 =A0 =A0 =A0 =A0 =A00xe04
> +#define CR2 =A0 =A0 =A0 =A0 =A0 =A00xe08
> +#define CR3 =A0 =A0 =A0 =A0 =A0 =A00xe0c
> +#define CR4 =A0 =A0 =A0 =A0 =A0 =A00xe10
> +#define CRD =A0 =A0 =A0 =A0 =A0 =A00xe14
> +
> +#define PERIPH_ID =A0 =A0 =A00xfe0
> +#define PCELL_ID =A0 =A0 =A0 0xff0
> +
> +#define CR0_PERIPH_REQ_SET =A0 =A0 (1 << 0)
> +#define CR0_BOOT_EN_SET =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(1 << 1)
> +#define CR0_BOOT_MAN_NS =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(1 << 2)
> +#define CR0_NUM_CHANS_SHIFT =A0 =A04
> +#define CR0_NUM_CHANS_MASK =A0 =A0 0x7
> +#define CR0_NUM_PERIPH_SHIFT =A0 12
> +#define CR0_NUM_PERIPH_MASK =A0 =A00x1f
> +#define CR0_NUM_EVENTS_SHIFT =A0 17
> +#define CR0_NUM_EVENTS_MASK =A0 =A00x1f
> +
> +#define CR1_ICACHE_LEN_SHIFT =A0 0
> +#define CR1_ICACHE_LEN_MASK =A0 =A00x7
> +#define CR1_NUM_ICACHELINES_SHIFT =A0 =A0 =A04
> +#define CR1_NUM_ICACHELINES_MASK =A0 =A0 =A0 0xf
> +
> +#define CRD_DATA_WIDTH_SHIFT =A0 0
> +#define CRD_DATA_WIDTH_MASK =A0 =A00x7
> +#define CRD_WR_CAP_SHIFT =A0 =A0 =A0 4
> +#define CRD_WR_CAP_MASK =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A00x7
> +#define CRD_WR_Q_DEP_SHIFT =A0 =A0 8
> +#define CRD_WR_Q_DEP_MASK =A0 =A0 =A00xf
> +#define CRD_RD_CAP_SHIFT =A0 =A0 =A0 12
> +#define CRD_RD_CAP_MASK =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A00x7
> +#define CRD_RD_Q_DEP_SHIFT =A0 =A0 16
> +#define CRD_RD_Q_DEP_MASK =A0 =A0 =A00xf
> +#define CRD_DATA_BUFF_SHIFT =A0 =A020
> +#define CRD_DATA_BUFF_MASK =A0 =A0 0x3ff
> +
> +#define =A0 =A0 =A0 =A0PART =A0 =A0 =A0 =A0 =A0 =A00x330
> +#define DESIGNER =A0 =A0 =A0 0x41
> +#define REVISION =A0 =A0 =A0 0x0
> +#define INTEG_CFG =A0 =A0 =A00x0
> +#define PERIPH_ID_VAL =A0((PART << 0) | (DESIGNER << 12) \
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 | (REVISION << 20) | (I=
NTEG_CFG << 24))
> +
> +#define PCELL_ID_VAL =A0 0xb105f00d
> +
> +#define PL330_STATE_STOPPED =A0 =A0 =A0 =A0 =A0 =A0(1 << 0)
> +#define PL330_STATE_EXECUTING =A0 =A0 =A0 =A0 =A0(1 << 1)
> +#define PL330_STATE_WFE =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(=
1 << 2)
> +#define PL330_STATE_FAULTING =A0 =A0 =A0 =A0 =A0 (1 << 3)
> +#define PL330_STATE_COMPLETING =A0 =A0 =A0 =A0 (1 << 4)
> +#define PL330_STATE_WFP =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(=
1 << 5) /* TOUT for exit? */
> +#define PL330_STATE_KILLING =A0 =A0 =A0 =A0 =A0 =A0(1 << 6)
> +#define PL330_STATE_FAULT_COMPLETING =A0 (1 << 7)
> +#define PL330_STATE_CACHEMISS =A0 =A0 =A0 =A0 =A0(1 << 8)
> +#define PL330_STATE_UPDTPC =A0 =A0 =A0 =A0 =A0 =A0 (1 << 9)
> +#define PL330_STATE_ATBARRIER =A0 =A0 =A0 =A0 =A0(1 << 10) /* TOUT for e=
xit? */
> +#define PL330_STATE_QUEUEBUSY =A0 =A0 =A0 =A0 =A0(1 << 11) /* TOUT for e=
xit? */
> +#define PL330_STATE_INVALID =A0 =A0 =A0 =A0 =A0 =A0(1 << 15) /* To catch=
 error */
> +
> +#define PL330_STABLE_STATES (PL330_STATE_STOPPED | PL330_STATE_EXECUTING=
 \
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 | PL330_STA=
TE_WFE | PL330_STATE_FAULTING)
> +
> +#define CMD_DMAADDH =A0 =A00x54
> +#define CMD_DMAEND =A0 =A0 0x00
> +#define CMD_DMAFLUSHP =A00x35
> +#define CMD_DMAGO =A0 =A0 =A00xa0
> +#define CMD_DMALD =A0 =A0 =A00x04
> +#define CMD_DMALDP =A0 =A0 0x25
> +#define CMD_DMALP =A0 =A0 =A00x20
> +#define CMD_DMALPEND =A0 0x28
> +#define CMD_DMAKILL =A0 =A00x01
> +#define CMD_DMAMOV =A0 =A0 0xbc
> +#define CMD_DMANOP =A0 =A0 0x18
> +#define CMD_DMARMB =A0 =A0 0x12
> +#define CMD_DMASEV =A0 =A0 0x34
> +#define CMD_DMAST =A0 =A0 =A00x08
> +#define CMD_DMASTP =A0 =A0 0x29
> +#define CMD_DMASTZ =A0 =A0 0x0c
> +#define CMD_DMAWFE =A0 =A0 0x36
> +#define CMD_DMAWFP =A0 =A0 0x30
> +#define CMD_DMAWMB =A0 =A0 0x13
> +
> +#define SZ_DMAADDH =A0 =A0 3
> +#define SZ_DMAEND =A0 =A0 =A01
> +#define SZ_DMAFLUSHP =A0 2
> +#define SZ_DMALD =A0 =A0 =A0 1
> +#define SZ_DMALDP =A0 =A0 =A02
> +#define SZ_DMALP =A0 =A0 =A0 2
> +#define SZ_DMALPEND =A0 =A02
> +#define SZ_DMAKILL =A0 =A0 1
> +#define SZ_DMAMOV =A0 =A0 =A06
> +#define SZ_DMANOP =A0 =A0 =A01
> +#define SZ_DMARMB =A0 =A0 =A01
> +#define SZ_DMASEV =A0 =A0 =A02
> +#define SZ_DMAST =A0 =A0 =A0 1
> +#define SZ_DMASTP =A0 =A0 =A02
> +#define SZ_DMASTZ =A0 =A0 =A01
> +#define SZ_DMAWFE =A0 =A0 =A02
> +#define SZ_DMAWFP =A0 =A0 =A02
> +#define SZ_DMAWMB =A0 =A0 =A01
> +#define SZ_DMAGO =A0 =A0 =A0 6
> +
> +#define BRST_LEN(ccr) =A0((((ccr) >> CC_SRCBRSTLEN_SHFT) & 0xf) + 1)
> +#define BRST_SIZE(ccr) (1 << (((ccr) >> CC_SRCBRSTSIZE_SHFT) & 0x7))
> +
> +#define BYTE_TO_BURST(b, ccr) =A0 =A0 =A0 =A0 =A0((b) / BRST_SIZE(ccr))
> +#define BURST_TO_BYTE(c, ccr) =A0 =A0 =A0 =A0 =A0((c) * BRST_SIZE(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.
> + */


I like multiline comments like this, notice blank first line:

/*
 * Foo
 */

(Yeah I know it's picky. Applies to entire file.)

> +#define MCODE_BUFF_PER_REQ =A0 =A0 256
> +
> +/* If program counter 'pc' is at req 'r' */
> +#define PC_AT_REQ(r, sz, pc) =A0 (((pc) >=3D (r)->mc_bus) && \
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ((pc) < ((r=
)->mc_bus + sz)))
> +
> +#define msecs_to_loops(t) (loops_per_jiffy / 1000 * HZ * t)
> +
> +struct _xfer_spec {
> + =A0 =A0 =A0 u32 ccr;
> + =A0 =A0 =A0 struct pl330_req *r;
> + =A0 =A0 =A0 struct pl330_xfer *x;
> +};
> +
> +enum dmamov_dst {
> + =A0 =A0 =A0 SAR =3D 0,
> + =A0 =A0 =A0 CCR,
> + =A0 =A0 =A0 DAR,
> +};
> +
> +enum pl330_dst {
> + =A0 =A0 =A0 SRC =3D 0,
> + =A0 =A0 =A0 DST,
> +};
> +
> +enum pl330_cond {
> + =A0 =A0 =A0 SINGLE,
> + =A0 =A0 =A0 BURST,
> + =A0 =A0 =A0 ALWAYS,
> +};
> +
> +struct _pl330_req {
> + =A0 =A0 =A0 u32 mc_bus;
> + =A0 =A0 =A0 void *mc_cpu;
> + =A0 =A0 =A0 struct pl330_req *r;
> + =A0 =A0 =A0 /* hook to attach to DMAC's list of reqs with callbacks due=
 */
> + =A0 =A0 =A0 struct list_head rqd;
> +};
> +
> +struct _pl330_tbd {
> + =A0 =A0 =A0 /* DMAC needs to be reset */
> + =A0 =A0 =A0 unsigned reset_dmac:1;
> + =A0 =A0 =A0 /* manager needs to be reset */
> + =A0 =A0 =A0 unsigned reset_mngr:1;

Contemplate using bool for these two members.

> + =A0 =A0 =A0 /* which thread needs to be reset */
> + =A0 =A0 =A0 unsigned reset_chan:8;

Why not use:
u8 reset_chan;

> +};
> +
> +struct pl330_thread { /* Each DMA Channel */
> + =A0 =A0 =A0 u8 id;
> + =A0 =A0 =A0 int ev;
> + =A0 =A0 =A0 /* If the channel is not yet acquired by any client */
> + =A0 =A0 =A0 bool free;
> + =A0 =A0 =A0 /* 0 for inactive, index of active request + 1, otherwise *=
/
> + =A0 =A0 =A0 unsigned active;
> + =A0 =A0 =A0 struct mutex mtx;
> + =A0 =A0 =A0 /* Only two at a time */
> + =A0 =A0 =A0 struct _pl330_req req[2];
> + =A0 =A0 =A0 /* parent DMAC */
> + =A0 =A0 =A0 struct pl330_dmac *dmac;
> +};
> +
> +enum pl330_dmac_state {
> + =A0 =A0 =A0 UNINIT,
> + =A0 =A0 =A0 INIT,
> + =A0 =A0 =A0 DYING,
> +};
> +
> +/* Each DMA Controller */
> +struct pl330_dmac {
> + =A0 =A0 =A0 struct _pl330_tbd =A0 =A0 =A0 dmac_tbd;
> + =A0 =A0 =A0 spinlock_t =A0 =A0 =A0 =A0 =A0 =A0 =A0lock;
> + =A0 =A0 =A0 /* hook to attach to global list of DMACs */
> + =A0 =A0 =A0 struct list_head =A0 =A0 =A0 =A0node;
> + =A0 =A0 =A0 /* Holds list of reqs with due callbacks */
> + =A0 =A0 =A0 struct list_head =A0 =A0 =A0 =A0req_done;
> + =A0 =A0 =A0 struct device =A0 =A0 =A0 =A0 =A0 *dev;
> + =A0 =A0 =A0 struct pl330_info =A0 =A0 =A0 pinfo;
> + =A0 =A0 =A0 /* Maximum possible events/irqs */
> + =A0 =A0 =A0 int =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 events[32];
> + =A0 =A0 =A0 /* BUS address of buffer allocated for MicroCode for all Ch=
annels */
> + =A0 =A0 =A0 u32 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 mcode_bus;
> + =A0 =A0 =A0 /* CPU address of buffer allocated for MicroCode for all Ch=
annels*/
> + =A0 =A0 =A0 void =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0*mcode_cpu;
> + =A0 =A0 =A0 struct pl330_thread =A0 =A0 *channels;
> + =A0 =A0 =A0 /* MANAGER thread is _always_ the last one */
> + =A0 =A0 =A0 struct pl330_thread =A0 =A0 *manager;
> + =A0 =A0 =A0 struct tasklet_struct =A0 tasks;
> + =A0 =A0 =A0 enum pl330_dmac_state =A0 state;
> +};
> +
> +/* All PL-330 DMACs are added to this list */
> +static LIST_HEAD(pl330_list);
> +/* Protection mutex while list manipulation */
> +static DEFINE_MUTEX(pl330_mutex);
> +
> +static inline void _callback(struct pl330_req *r, int err)
> +{
> + =A0 =A0 =A0 if (r && r->xfer_cb)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 r->xfer_cb(r->token, err);
> +}
> +
> +static inline bool _queue_empty(struct pl330_thread *thrd)
> +{
> + =A0 =A0 =A0 return (thrd->req[0].r || thrd->req[1].r) ? false : true;
> +}
> +
> +static inline bool _queue_full(struct pl330_thread *thrd)
> +{
> + =A0 =A0 =A0 return (thrd->req[0].r && thrd->req[1].r) ? true : false;
> +}
> +
> +static inline bool is_manager(struct pl330_thread *thrd)
> +{
> + =A0 =A0 =A0 struct pl330_dmac *pl330 =3D thrd->dmac;
> +
> + =A0 =A0 =A0 /* MANAGER is indexed at the end */
> + =A0 =A0 =A0 if (thrd->id =3D=3D pl330->pinfo.pcfg.num_chan)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return true;
> + =A0 =A0 =A0 else
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return false;
> +}
> +
> +/* If manager of the thread is in Non-Secure mode */
> +static inline bool _manager_ns(struct pl330_thread *thrd)
> +{
> + =A0 =A0 =A0 struct pl330_dmac *pl330 =3D thrd->dmac;
> +
> + =A0 =A0 =A0 return (pl330->pinfo.pcfg.mode & DMAC_MODE_NS) ? true : fal=
se;
> +}
> +
> +static inline u32 get_id(struct pl330_dmac *pl330, u32 off)
> +{
> + =A0 =A0 =A0 void __iomem *r =3D pl330->pinfo.base;
> + =A0 =A0 =A0 u32 id =3D 0;
> +
> + =A0 =A0 =A0 id |=3D (readb(r + off + 0x0) << 0);
> + =A0 =A0 =A0 id |=3D (readb(r + off + 0x4) << 8);
> + =A0 =A0 =A0 id |=3D (readb(r + off + 0x8) << 16);
> + =A0 =A0 =A0 id |=3D (readb(r + off + 0xc) << 24);
> +
> + =A0 =A0 =A0 return id;
> +}
> +
> +static inline u32 _emit_ADDH(unsigned dry_run, u8 buf[],
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 enum pl330_dst da, u16 val)
> +{
> + =A0 =A0 =A0 if (dry_run)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return SZ_DMAADDH;
> +
> + =A0 =A0 =A0 buf[0] =3D CMD_DMAADDH;
> + =A0 =A0 =A0 buf[0] |=3D (da << 1);
> + =A0 =A0 =A0 *((u16 *)&buf[1]) =3D val;
> +
> + =A0 =A0 =A0 return SZ_DMAADDH;
> +}
> +
> +static inline u32 _emit_END(unsigned dry_run, u8 buf[])
> +{
> + =A0 =A0 =A0 if (dry_run)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return SZ_DMAEND;
> +
> + =A0 =A0 =A0 buf[0] =3D CMD_DMAEND;
> +
> + =A0 =A0 =A0 return SZ_DMAEND;
> +}
> +
> +static inline u32 _emit_FLUSHP(unsigned dry_run, u8 buf[], u8 peri)
> +{
> + =A0 =A0 =A0 if (dry_run)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return SZ_DMAFLUSHP;
> +
> + =A0 =A0 =A0 buf[0] =3D CMD_DMAFLUSHP;
> +
> + =A0 =A0 =A0 peri &=3D 0x1f;
> + =A0 =A0 =A0 peri <<=3D 3;
> + =A0 =A0 =A0 buf[1] =3D peri;
> +
> + =A0 =A0 =A0 return SZ_DMAFLUSHP;
> +}
> +
> +static inline u32 _emit_LD(unsigned dry_run, u8 buf[], enum pl330_cond c=
ond)
> +{
> + =A0 =A0 =A0 if (dry_run)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return SZ_DMALD;
> +
> + =A0 =A0 =A0 buf[0] =3D CMD_DMALD;
> +
> + =A0 =A0 =A0 if (cond =3D=3D SINGLE)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 buf[0] |=3D (0 << 1) | (1 << 0);
> + =A0 =A0 =A0 else if (cond =3D=3D BURST)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 buf[0] |=3D (1 << 1) | (1 << 0);
> +
> + =A0 =A0 =A0 return SZ_DMALD;
> +}
> +
> +static inline u32 _emit_LDP(unsigned dry_run, u8 buf[],
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 enum pl330_cond cond, u8 peri)
> +{
> + =A0 =A0 =A0 if (dry_run)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return SZ_DMALDP;
> +
> + =A0 =A0 =A0 buf[0] =3D CMD_DMALDP;
> +
> + =A0 =A0 =A0 if (cond =3D=3D BURST)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 buf[0] |=3D (1 << 1);
> +
> + =A0 =A0 =A0 peri &=3D 0x1f;
> + =A0 =A0 =A0 peri <<=3D 3;
> + =A0 =A0 =A0 buf[1] =3D peri;
> +
> + =A0 =A0 =A0 return SZ_DMALDP;
> +}
> +
> +static inline u32 _emit_LP(unsigned dry_run, u8 buf[],
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 unsigned loop, u8 cnt)
> +{
> + =A0 =A0 =A0 if (dry_run)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return SZ_DMALP;
> +
> + =A0 =A0 =A0 buf[0] =3D CMD_DMALP;
> +
> + =A0 =A0 =A0 if (loop)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 buf[0] |=3D (1 << 1);
> +
> + =A0 =A0 =A0 buf[1] =3D cnt;
> +
> + =A0 =A0 =A0 return SZ_DMALP;
> +}
> +
> +struct _arg_LPEND {
> + =A0 =A0 =A0 enum pl330_cond cond;
> + =A0 =A0 =A0 bool forever;
> + =A0 =A0 =A0 unsigned loop;
> + =A0 =A0 =A0 u8 bjump;
> +};
> +
> +static inline u32 _emit_LPEND(unsigned dry_run, u8 buf[],
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 const struct _arg_LPEND *arg)
> +{
> + =A0 =A0 =A0 enum pl330_cond cond =3D arg->cond;
> + =A0 =A0 =A0 bool forever =3D arg->forever;
> + =A0 =A0 =A0 unsigned loop =3D arg->loop;
> + =A0 =A0 =A0 u8 bjump =3D arg->bjump;
> +
> +
> + =A0 =A0 =A0 if (dry_run)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return SZ_DMALPEND;
> +
> + =A0 =A0 =A0 buf[0] =3D CMD_DMALPEND;
> +
> + =A0 =A0 =A0 if (loop)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 buf[0] |=3D (1 << 2);
> +
> + =A0 =A0 =A0 if (forever)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 buf[0] |=3D (1 << 4);
> +
> + =A0 =A0 =A0 if (cond =3D=3D SINGLE)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 buf[0] |=3D (0 << 1) | (1 << 0);
> + =A0 =A0 =A0 else if (cond =3D=3D BURST)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 buf[0] |=3D (1 << 1) | (1 << 0);
> +
> + =A0 =A0 =A0 buf[1] =3D bjump;
> +
> + =A0 =A0 =A0 return SZ_DMALPEND;
> +}
> +
> +static inline u32 _emit_KILL(unsigned dry_run, u8 buf[])
> +{
> + =A0 =A0 =A0 if (dry_run)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return SZ_DMAKILL;
> +
> + =A0 =A0 =A0 buf[0] =3D CMD_DMAKILL;
> +
> + =A0 =A0 =A0 return SZ_DMAKILL;
> +}
> +
> +static inline u32 _emit_MOV(unsigned dry_run, u8 buf[],
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 enum dmamov_dst dst, u32 val)
> +{
> + =A0 =A0 =A0 if (dry_run)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return SZ_DMAMOV;
> +
> + =A0 =A0 =A0 buf[0] =3D CMD_DMAMOV;
> + =A0 =A0 =A0 buf[1] =3D dst;
> + =A0 =A0 =A0 *((u32 *)&buf[2]) =3D val;
> +
> + =A0 =A0 =A0 return SZ_DMAMOV;
> +}
> +
> +static inline u32 _emit_NOP(unsigned dry_run, u8 buf[])
> +{
> + =A0 =A0 =A0 if (dry_run)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return SZ_DMANOP;
> +
> + =A0 =A0 =A0 buf[0] =3D CMD_DMANOP;
> +
> + =A0 =A0 =A0 return SZ_DMANOP;
> +}
> +
> +static inline u32 _emit_RMB(unsigned dry_run, u8 buf[])
> +{
> + =A0 =A0 =A0 if (dry_run)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return SZ_DMARMB;
> +
> + =A0 =A0 =A0 buf[0] =3D CMD_DMARMB;
> +
> + =A0 =A0 =A0 return SZ_DMARMB;
> +}
> +
> +static inline u32 _emit_SEV(unsigned dry_run, u8 buf[], u8 ev)
> +{
> + =A0 =A0 =A0 if (dry_run)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return SZ_DMASEV;
> +
> + =A0 =A0 =A0 buf[0] =3D CMD_DMASEV;
> +
> + =A0 =A0 =A0 ev &=3D 0x1f;
> + =A0 =A0 =A0 ev <<=3D 3;
> + =A0 =A0 =A0 buf[1] =3D ev;
> +
> + =A0 =A0 =A0 return SZ_DMASEV;
> +}
> +
> +static inline u32 _emit_ST(unsigned dry_run, u8 buf[], enum pl330_cond c=
ond)
> +{
> + =A0 =A0 =A0 if (dry_run)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return SZ_DMAST;
> +
> + =A0 =A0 =A0 buf[0] =3D CMD_DMAST;
> +
> + =A0 =A0 =A0 if (cond =3D=3D SINGLE)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 buf[0] |=3D (0 << 1) | (1 << 0);
> + =A0 =A0 =A0 else if (cond =3D=3D BURST)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 buf[0] |=3D (1 << 1) | (1 << 0);
> +
> + =A0 =A0 =A0 return SZ_DMAST;
> +}
> +
> +static inline u32 _emit_STP(unsigned dry_run, u8 buf[],
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 enum pl330_cond cond, u8 peri)
> +{
> + =A0 =A0 =A0 if (dry_run)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return SZ_DMASTP;
> +
> + =A0 =A0 =A0 buf[0] =3D CMD_DMASTP;
> +
> + =A0 =A0 =A0 if (cond =3D=3D BURST)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 buf[0] |=3D (1 << 1);
> +
> + =A0 =A0 =A0 peri &=3D 0x1f;
> + =A0 =A0 =A0 peri <<=3D 3;
> + =A0 =A0 =A0 buf[1] =3D peri;
> +
> + =A0 =A0 =A0 return SZ_DMASTP;
> +}
> +
> +static inline u32 _emit_STZ(unsigned dry_run, u8 buf[])
> +{
> + =A0 =A0 =A0 if (dry_run)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return SZ_DMASTZ;
> +
> + =A0 =A0 =A0 buf[0] =3D CMD_DMASTZ;
> +
> + =A0 =A0 =A0 return SZ_DMASTZ;
> +}
> +
> +static inline u32 _emit_WFE(unsigned dry_run, u8 buf[], u8 ev,
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 unsigned invalidate)
> +{
> + =A0 =A0 =A0 if (dry_run)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return SZ_DMAWFE;
> +
> + =A0 =A0 =A0 buf[0] =3D CMD_DMAWFE;
> +
> + =A0 =A0 =A0 ev &=3D 0x1f;
> + =A0 =A0 =A0 ev <<=3D 3;
> + =A0 =A0 =A0 buf[1] =3D ev;
> +
> + =A0 =A0 =A0 if (invalidate)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 buf[1] |=3D (1 << 1);
> +
> + =A0 =A0 =A0 return SZ_DMAWFE;
> +}
> +
> +static inline u32 _emit_WFP(unsigned dry_run, u8 buf[],
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 enum pl330_cond cond, u8 peri)
> +{
> + =A0 =A0 =A0 if (dry_run)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return SZ_DMAWFP;
> +
> + =A0 =A0 =A0 buf[0] =3D CMD_DMAWFP;
> +
> + =A0 =A0 =A0 if (cond =3D=3D SINGLE)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 buf[0] |=3D (0 << 1) | (0 << 0);
> + =A0 =A0 =A0 else if (cond =3D=3D BURST)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 buf[0] |=3D (1 << 1) | (0 << 0);
> + =A0 =A0 =A0 else
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 buf[0] |=3D (0 << 1) | (1 << 0);
> +
> + =A0 =A0 =A0 peri &=3D 0x1f;
> + =A0 =A0 =A0 peri <<=3D 3;
> + =A0 =A0 =A0 buf[1] =3D peri;
> +
> + =A0 =A0 =A0 return SZ_DMAWFP;
> +}
> +
> +static inline u32 _emit_WMB(unsigned dry_run, u8 buf[])
> +{
> + =A0 =A0 =A0 if (dry_run)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return SZ_DMAWMB;
> +
> + =A0 =A0 =A0 buf[0] =3D CMD_DMAWMB;
> +
> + =A0 =A0 =A0 return SZ_DMAWMB;
> +}
> +
> +struct _arg_GO {
> + =A0 =A0 =A0 u8 chan;
> + =A0 =A0 =A0 u32 addr;
> + =A0 =A0 =A0 unsigned ns:1;
> +};
> +
> +static inline u32 _emit_GO(unsigned dry_run, u8 buf[],
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 const struct _arg_GO *arg)
> +{
> + =A0 =A0 =A0 u8 chan =3D arg->chan;
> + =A0 =A0 =A0 u32 addr =3D arg->addr;
> + =A0 =A0 =A0 unsigned ns =3D arg->ns;
> +
> + =A0 =A0 =A0 if (dry_run)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return SZ_DMAGO;
> +
> + =A0 =A0 =A0 buf[0] =3D CMD_DMAGO;
> + =A0 =A0 =A0 if (ns)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 buf[0] |=3D (ns << 1);
> +
> + =A0 =A0 =A0 buf[1] =3D chan & 0x7;
> +
> + =A0 =A0 =A0 *((u32 *)&buf[2]) =3D addr;
> +
> + =A0 =A0 =A0 return SZ_DMAGO;
> +}

With all these emit_* functions you have half a microcode compiler in the
driver, but I really, really like it! It's the right foundation for
hackers that want
to have fun with the microcode generation later on.

> +static inline void _execute_DBGINSN(struct pl330_thread *thrd,
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 u8 insn[], bool as_manager)
> +{
> + =A0 =A0 =A0 void __iomem *regs =3D thrd->dmac->pinfo.base;
> + =A0 =A0 =A0 u32 val;
> +
> + =A0 =A0 =A0 val =3D (insn[0] << 16) | (insn[1] << 24);
> + =A0 =A0 =A0 if (!as_manager) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 val |=3D (1 << 0);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 val |=3D (thrd->id << 8); /* Channel Number=
 */
> + =A0 =A0 =A0 }
> + =A0 =A0 =A0 writel(val, regs + DBGINST0);
> +
> + =A0 =A0 =A0 val =3D *((u32 *)&insn[2]);
> + =A0 =A0 =A0 writel(val, regs + DBGINST1);
> +}
> +
> +/* Returns Time-Out */
> +static bool _until_dmac_idle(struct pl330_thread *thrd)
> +{
> + =A0 =A0 =A0 void __iomem *regs =3D thrd->dmac->pinfo.base;
> + =A0 =A0 =A0 unsigned long loops =3D msecs_to_loops(5);
> +
> + =A0 =A0 =A0 do {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Until Manager is Idle */
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!(readl(regs + DBGSTATUS) & DBG_BUSY))
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 break;
> +
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 cpu_relax();
> + =A0 =A0 =A0 } while (--loops);
> +
> + =A0 =A0 =A0 if (!loops)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return true;
> +
> + =A0 =A0 =A0 return false;
> +}
> +
> +static inline u32 _state(struct pl330_thread *thrd)
> +{
> + =A0 =A0 =A0 void __iomem *regs =3D thrd->dmac->pinfo.base;
> + =A0 =A0 =A0 u32 val;
> +
> + =A0 =A0 =A0 if (is_manager(thrd))
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 val =3D readl(regs + DS) & 0xf;
> + =A0 =A0 =A0 else
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 val =3D readl(regs + CS(thrd->id)) & 0xf;
> +
> + =A0 =A0 =A0 switch (val) {
> + =A0 =A0 =A0 case DS_ST_STOP:
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return PL330_STATE_STOPPED;
> + =A0 =A0 =A0 case DS_ST_EXEC:
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return PL330_STATE_EXECUTING;
> + =A0 =A0 =A0 case DS_ST_CMISS:
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return PL330_STATE_CACHEMISS;
> + =A0 =A0 =A0 case DS_ST_UPDTPC:
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return PL330_STATE_UPDTPC;
> + =A0 =A0 =A0 case DS_ST_WFE:
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return PL330_STATE_WFE;
> + =A0 =A0 =A0 case DS_ST_FAULT:
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return PL330_STATE_FAULTING;
> + =A0 =A0 =A0 case DS_ST_ATBRR:
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (is_manager(thrd))
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return PL330_STATE_INVALID;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 else
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return PL330_STATE_ATBARRIE=
R;
> + =A0 =A0 =A0 case DS_ST_QBUSY:
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (is_manager(thrd))
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return PL330_STATE_INVALID;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 else
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return PL330_STATE_QUEUEBUS=
Y;
> + =A0 =A0 =A0 case DS_ST_WFP:
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (is_manager(thrd))
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return PL330_STATE_INVALID;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 else
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return PL330_STATE_WFP;
> + =A0 =A0 =A0 case DS_ST_KILL:
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (is_manager(thrd))
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return PL330_STATE_INVALID;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 else
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return PL330_STATE_KILLING;
> + =A0 =A0 =A0 case DS_ST_CMPLT:
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (is_manager(thrd))
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return PL330_STATE_INVALID;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 else
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return PL330_STATE_COMPLETI=
NG;
> + =A0 =A0 =A0 case DS_ST_FLTCMP:
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (is_manager(thrd))
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return PL330_STATE_INVALID;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 else
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return PL330_STATE_FAULT_CO=
MPLETING;
> + =A0 =A0 =A0 default:
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return PL330_STATE_INVALID;
> + =A0 =A0 =A0 }
> +}
> +
> +/* Use this _only_ to wait on transient states */
> +#define UNTIL(t, s) =A0 =A0while (!(_state(t) & (s))) cpu_relax();
> +
> +/* Start doing req 'idx' of thread 'thrd' */
> +static bool _trigger(struct pl330_thread *thrd, unsigned idx)
> +{
> + =A0 =A0 =A0 void __iomem *regs =3D thrd->dmac->pinfo.base;
> + =A0 =A0 =A0 struct _pl330_req *req =3D &thrd->req[idx];
> + =A0 =A0 =A0 struct pl330_req *r =3D req->r;
> + =A0 =A0 =A0 struct _arg_GO go;
> + =A0 =A0 =A0 unsigned ns;

bool

> + =A0 =A0 =A0 u8 insn[6] =3D {0, 0, 0, 0, 0, 0};
> +
> + =A0 =A0 =A0 /* Return if already ACTIVE */
> + =A0 =A0 =A0 if (_state(thrd) !=3D PL330_STATE_STOPPED)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return true;
> +
> + =A0 =A0 =A0 /* Return if no request */
> + =A0 =A0 =A0 if (!r)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return true;
> +
> + =A0 =A0 =A0 /* If timed out due to halted state-machine */
> + =A0 =A0 =A0 if (_until_dmac_idle(thrd))
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return false;
> +
> + =A0 =A0 =A0 if (r->cfg)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ns =3D r->cfg->nonsecure ? 1 : 0;

Since you defined nonsecure as :1 you could just assign it.
But please make both ns and cfg->nonsecure bool.

> + =A0 =A0 =A0 else if (readl(regs + CS(thrd->id)) & CS_CNS)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ns =3D 1;
> + =A0 =A0 =A0 else
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ns =3D 0;
> +
> + =A0 =A0 =A0 /* See 'Abort Sources' point-4 at Page 2-25 */
> + =A0 =A0 =A0 if (_manager_ns(thrd) && !ns)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 printk(KERN_INFO "%s:%d Recipe for ABORT!\n=
",
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 __func__, __LINE__);


dev_info(thrd->dmac->dev, "....");

> +
> + =A0 =A0 =A0 go.chan =3D thrd->id;
> + =A0 =A0 =A0 go.addr =3D req->mc_bus;
> + =A0 =A0 =A0 go.ns =3D ns;
> + =A0 =A0 =A0 _emit_GO(0, insn, &go);
> +
> + =A0 =A0 =A0 /* Set to generate interrupts for SEV */
> + =A0 =A0 =A0 writel(readl(regs + INTEN) | (1 << thrd->ev), regs + INTEN)=
;
> +
> + =A0 =A0 =A0 /* Only manager can execute GO */
> + =A0 =A0 =A0 _execute_DBGINSN(thrd, insn, true);
> +
> + =A0 =A0 =A0 return true;
> +}
> +
> +/* Makes sure the thread is in STOPPED state */
> +static void _stop(struct pl330_thread *thrd)
> +{
> + =A0 =A0 =A0 u8 insn[6] =3D {0, 0, 0, 0, 0, 0};
> +
> + =A0 =A0 =A0 /* Return if already STOPPED */
> + =A0 =A0 =A0 if (_state(thrd) =3D=3D PL330_STATE_STOPPED)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return;
> +
> + =A0 =A0 =A0 if (is_manager(thrd))
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 _emit_END(0, insn);
> + =A0 =A0 =A0 else
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 _emit_KILL(0, insn);
> +
> + =A0 =A0 =A0 _execute_DBGINSN(thrd, insn, is_manager(thrd));
> +}
> +
> +static bool _start(struct pl330_thread *thrd)
> +{
> + =A0 =A0 =A0 switch (_state(thrd)) {
> + =A0 =A0 =A0 case PL330_STATE_FAULT_COMPLETING:
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 UNTIL(thrd, PL330_STATE_FAULTING | PL330_ST=
ATE_KILLING);
> +
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (_state(thrd) =3D=3D PL330_STATE_KILLING=
)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 UNTIL(thrd, PL330_STATE_STO=
PPED)
> +
> + =A0 =A0 =A0 case PL330_STATE_FAULTING:
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 _stop(thrd);
> +
> + =A0 =A0 =A0 case PL330_STATE_KILLING:
> + =A0 =A0 =A0 case PL330_STATE_COMPLETING:
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 UNTIL(thrd, PL330_STATE_STOPPED)
> +
> + =A0 =A0 =A0 case PL330_STATE_STOPPED:
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return _trigger(thrd, thrd->req[0].r ? 0 : =
1);
> +
> + =A0 =A0 =A0 case PL330_STATE_WFP:
> + =A0 =A0 =A0 case PL330_STATE_QUEUEBUSY:
> + =A0 =A0 =A0 case PL330_STATE_ATBARRIER:
> + =A0 =A0 =A0 case PL330_STATE_UPDTPC:
> + =A0 =A0 =A0 case PL330_STATE_CACHEMISS:
> + =A0 =A0 =A0 case PL330_STATE_EXECUTING:
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return true;
> +
> + =A0 =A0 =A0 case PL330_STATE_WFE: /* for PAUSE - nothing yet */
> + =A0 =A0 =A0 default: /* Shouldn't reach here with some transient state =
*/
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return false;
> + =A0 =A0 =A0 }
> +}
> +
> +static inline u32 _prepare_ccr(struct pl330_reqcfg *rqc)
> +{
> + =A0 =A0 =A0 u32 ccr =3D 0;
> +
> + =A0 =A0 =A0 if (rqc->src_inc)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ccr |=3D CC_SRCINC;
> +
> + =A0 =A0 =A0 if (rqc->dst_inc)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ccr |=3D CC_DSTINC;
> +
> + =A0 =A0 =A0 /* We set same protection levels for Src and DST for now */
> + =A0 =A0 =A0 if (rqc->privileged)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ccr |=3D CC_SRCPRI | CC_DSTPRI;
> + =A0 =A0 =A0 if (rqc->nonsecure)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ccr |=3D CC_SRCNS | CC_DSTNS;
> + =A0 =A0 =A0 if (rqc->insnaccess)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ccr |=3D CC_SRCIA | CC_DSTIA;
> +
> + =A0 =A0 =A0 ccr |=3D (((rqc->brst_len - 1) & 0xf) << CC_SRCBRSTLEN_SHFT=
);
> + =A0 =A0 =A0 ccr |=3D (((rqc->brst_len - 1) & 0xf) << CC_DSTBRSTLEN_SHFT=
);
> +
> + =A0 =A0 =A0 ccr |=3D (rqc->brst_size << CC_SRCBRSTSIZE_SHFT);
> + =A0 =A0 =A0 ccr |=3D (rqc->brst_size << CC_DSTBRSTSIZE_SHFT);
> +
> + =A0 =A0 =A0 ccr |=3D (rqc->dcctl << CC_SRCCCTRL_SHFT);
> + =A0 =A0 =A0 ccr |=3D (rqc->scctl << CC_DSTCCTRL_SHFT);
> +
> + =A0 =A0 =A0 ccr |=3D (rqc->swap << CC_SWAP_SHFT);
> +
> + =A0 =A0 =A0 return ccr;
> +}
> +
> +static inline bool _is_valid(u32 ccr)
> +{
> + =A0 =A0 =A0 enum pl330_dstcachectrl dcctl;
> + =A0 =A0 =A0 enum pl330_srccachectrl scctl;
> +
> + =A0 =A0 =A0 dcctl =3D (ccr >> CC_DSTCCTRL_SHFT) & CC_DRCCCTRL_MASK;
> + =A0 =A0 =A0 scctl =3D (ccr >> CC_SRCCCTRL_SHFT) & CC_SRCCCTRL_MASK;
> +
> + =A0 =A0 =A0 if (dcctl =3D=3D DINVALID1 || dcctl =3D=3D DINVALID2
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 || scctl =3D=3D SINVALID1 |=
| scctl =3D=3D SINVALID2)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return false;
> + =A0 =A0 =A0 else
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return true;
> +}
> +
> +static inline int _ldst_memtomem(unsigned dry_run, u8 buf[],
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 const struct _xfer_spec *pxs, int cyc)
> +{
> + =A0 =A0 =A0 int off =3D 0;
> +
> + =A0 =A0 =A0 while (cyc--) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Do we need RMB/WMB for each load/store? =
REVISIT XXX */
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 off +=3D _emit_LD(dry_run, &buf[off], ALWAY=
S);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 off +=3D _emit_RMB(dry_run, &buf[off]);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 off +=3D _emit_ST(dry_run, &buf[off], ALWAY=
S);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 off +=3D _emit_WMB(dry_run, &buf[off]);
> + =A0 =A0 =A0 }
> +
> + =A0 =A0 =A0 return off;
> +}
> +
> +static inline int _ldst_devtomem(unsigned dry_run, u8 buf[],
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 const struct _xfer_spec *pxs, int cyc)
> +{
> + =A0 =A0 =A0 int off =3D 0;
> +
> + =A0 =A0 =A0 while (cyc--) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Do we need WFP for every cycle? REVISIT =
XXX */
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 off +=3D _emit_WFP(dry_run, &buf[off], SING=
LE, pxs->r->peri);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 off +=3D _emit_LDP(dry_run, &buf[off], SING=
LE, pxs->r->peri);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 off +=3D _emit_ST(dry_run, &buf[off], ALWAY=
S);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Do we need FLUSHP for every cycle? REVIS=
IT XXX */
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 off +=3D _emit_FLUSHP(dry_run, &buf[off], p=
xs->r->peri);
> + =A0 =A0 =A0 }
> +
> + =A0 =A0 =A0 return off;
> +}
> +
> +static inline int _ldst_memtodev(unsigned dry_run, u8 buf[],
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 const struct _xfer_spec *pxs, int cyc)
> +{
> + =A0 =A0 =A0 int off =3D 0;
> +
> + =A0 =A0 =A0 while (cyc--) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Do we need WFP for every cycle? REVISIT =
XXX */
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 off +=3D _emit_WFP(dry_run, &buf[off], SING=
LE, pxs->r->peri);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 off +=3D _emit_LD(dry_run, &buf[off], ALWAY=
S);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 off +=3D _emit_STP(dry_run, &buf[off], SING=
LE, pxs->r->peri);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Do we need FLUSHP for every cycle? REVIS=
IT XXX */
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 off +=3D _emit_FLUSHP(dry_run, &buf[off], p=
xs->r->peri);
> + =A0 =A0 =A0 }
> +
> + =A0 =A0 =A0 return off;
> +}
> +
> +static int _bursts(unsigned dry_run, u8 buf[],
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 const struct _xfer_spec *pxs, int cyc)
> +{
> + =A0 =A0 =A0 int off =3D 0;
> +
> + =A0 =A0 =A0 switch (pxs->r->rqtype) {
> + =A0 =A0 =A0 case MEMTODEV:
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 off +=3D _ldst_memtodev(dry_run, &buf[off],=
 pxs, cyc);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 break;
> +
> + =A0 =A0 =A0 case DEVTOMEM:
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 off +=3D _ldst_devtomem(dry_run, &buf[off],=
 pxs, cyc);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 break;
> +
> + =A0 =A0 =A0 case MEMTOMEM:
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 off +=3D _ldst_memtomem(dry_run, &buf[off],=
 pxs, cyc);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 break;
> +
> + =A0 =A0 =A0 default:
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 off +=3D 0x40000000; /* Scare off the Clien=
t */
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 break;
> + =A0 =A0 =A0 }
> +
> + =A0 =A0 =A0 return off;
> +}
> +
> +/* Returns bytes consumed and updates bursts */
> +static inline int _loop(unsigned dry_run, u8 buf[],
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 unsigned long *bursts, const struct _xfer_s=
pec *pxs)
> +{
> + =A0 =A0 =A0 int cyc, cycmax, szlp, szlpend, szbrst, off;
> + =A0 =A0 =A0 unsigned lcnt0, lcnt1, ljmp0, ljmp1;
> + =A0 =A0 =A0 struct _arg_LPEND lpend;
> +
> + =A0 =A0 =A0 /* Max iterations possibile in DMALP is 256 */
> + =A0 =A0 =A0 if (*bursts >=3D 256*256) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 lcnt1 =3D 256;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 lcnt0 =3D 256;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 cyc =3D *bursts / lcnt1 / lcnt0;
> + =A0 =A0 =A0 } else if (*bursts > 256) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 lcnt1 =3D 256;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 lcnt0 =3D *bursts / lcnt1;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 cyc =3D 1;
> + =A0 =A0 =A0 } else {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 lcnt1 =3D *bursts;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 lcnt0 =3D 0;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 cyc =3D 1;
> + =A0 =A0 =A0 }
> +
> + =A0 =A0 =A0 szlp =3D _emit_LP(1, buf, 0, 0);
> + =A0 =A0 =A0 szbrst =3D _bursts(1, buf, pxs, 1);
> +
> + =A0 =A0 =A0 lpend.cond =3D ALWAYS;
> + =A0 =A0 =A0 lpend.forever =3D false;
> + =A0 =A0 =A0 lpend.loop =3D 0;
> + =A0 =A0 =A0 lpend.bjump =3D 0;
> + =A0 =A0 =A0 szlpend =3D _emit_LPEND(1, buf, &lpend);
> +
> + =A0 =A0 =A0 if (lcnt0) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 szlp *=3D 2;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 szlpend *=3D 2;
> + =A0 =A0 =A0 }
> +
> + =A0 =A0 =A0 /** Do not mess with the construct **/

Which means? Hackers like to mess with stuff... Note to self?
Usually comments like that is a trace of questionable design
so if the design is solid, remove the comments because then it
will be obvious that you don't want to mess with the construct.

> +
> + =A0 =A0 =A0 /* Max bursts that we can unroll due to limit on the
> + =A0 =A0 =A0 =A0* size of backward jump that can be encoded in DMALPEND
> + =A0 =A0 =A0 =A0* which is 8-bits and hence 255
> + =A0 =A0 =A0 =A0*/
> + =A0 =A0 =A0 cycmax =3D (255 - (szlp + szlpend)) / szbrst;
> +
> + =A0 =A0 =A0 cyc =3D (cycmax < cyc) ? cycmax : cyc;
> +
> + =A0 =A0 =A0 off =3D 0;
> +
> + =A0 =A0 =A0 ljmp0 =3D off;
> + =A0 =A0 =A0 if (lcnt0)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 off +=3D _emit_LP(dry_run, &buf[off], 0, lc=
nt0);
> +
> + =A0 =A0 =A0 ljmp1 =3D off;
> + =A0 =A0 =A0 off +=3D _emit_LP(dry_run, &buf[off], 1, lcnt1);
> +
> + =A0 =A0 =A0 off +=3D _bursts(dry_run, &buf[off], pxs, cyc);
> +
> + =A0 =A0 =A0 lpend.cond =3D ALWAYS;
> + =A0 =A0 =A0 lpend.forever =3D false;
> + =A0 =A0 =A0 lpend.loop =3D 1;
> + =A0 =A0 =A0 lpend.bjump =3D off - ljmp1;
> + =A0 =A0 =A0 off +=3D _emit_LPEND(dry_run, &buf[off], &lpend);
> +
> + =A0 =A0 =A0 if (lcnt0) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 lpend.cond =3D ALWAYS;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 lpend.forever =3D false;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 lpend.loop =3D 0;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 lpend.bjump =3D off - ljmp0;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 off +=3D _emit_LPEND(dry_run, &buf[off], &l=
pend);
> + =A0 =A0 =A0 }
> + =A0 =A0 =A0 /***********************************/
> +
> + =A0 =A0 =A0 *bursts =3D lcnt1 * cyc;
> + =A0 =A0 =A0 if (lcnt0)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 *bursts *=3D lcnt0;
> +
> + =A0 =A0 =A0 return off;
> +}
> +
> +static inline int _setup_loops(unsigned dry_run, u8 buf[],
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 const struct _xfer_spec *pxs)
> +{
> + =A0 =A0 =A0 struct pl330_xfer *x =3D pxs->x;
> + =A0 =A0 =A0 u32 ccr =3D pxs->ccr;
> + =A0 =A0 =A0 unsigned long c, bursts =3D BYTE_TO_BURST(x->bytes, ccr);
> + =A0 =A0 =A0 int off =3D 0;
> +
> + =A0 =A0 =A0 while (bursts) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 c =3D bursts;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 off +=3D _loop(dry_run, &buf[off], &c, pxs)=
;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 bursts -=3D c;
> + =A0 =A0 =A0 }
> +
> + =A0 =A0 =A0 return off;
> +}
> +
> +static inline int _setup_xfer(unsigned dry_run, u8 buf[],
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 const struct _xfer_spec *pxs)
> +{
> + =A0 =A0 =A0 struct pl330_xfer *x =3D pxs->x;
> + =A0 =A0 =A0 int off =3D 0;
> +
> + =A0 =A0 =A0 /* DMAMOV SAR, x->src_addr */
> + =A0 =A0 =A0 off +=3D _emit_MOV(dry_run, &buf[off], SAR, x->src_addr);
> + =A0 =A0 =A0 /* DMAMOV DAR, x->dst_addr */
> + =A0 =A0 =A0 off +=3D _emit_MOV(dry_run, &buf[off], DAR, x->dst_addr);
> +
> + =A0 =A0 =A0 /* Setup Loop(s) */
> + =A0 =A0 =A0 off +=3D _setup_loops(dry_run, &buf[off], pxs);
> +
> + =A0 =A0 =A0 return off;
> +}
> +
> +/* A req is a sequence of one or more xfer units.
> + * Returns the number of bytes taken to setup the MC
> + * for the req.
> + */
> +static int _setup_req(unsigned dry_run, struct pl330_thread *thrd,
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 unsigned index, struct _xfer_spec *pxs)
> +{
> + =A0 =A0 =A0 struct _pl330_req *req =3D &thrd->req[index];
> + =A0 =A0 =A0 struct pl330_xfer *x;
> + =A0 =A0 =A0 u8 *buf =3D req->mc_cpu;
> + =A0 =A0 =A0 int off =3D 0;
> +
> + =A0 =A0 =A0 /* DMAMOV CCR, ccr */
> + =A0 =A0 =A0 off +=3D _emit_MOV(dry_run, &buf[off], CCR, pxs->ccr);
> +
> + =A0 =A0 =A0 x =3D pxs->r->x;
> + =A0 =A0 =A0 do {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Error if xfer length is not aligned at b=
urst size */
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (x->bytes % BRST_SIZE(pxs->ccr))
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -EINVAL;
> +
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 pxs->x =3D x;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 off +=3D _setup_xfer(dry_run, &buf[off], px=
s);
> +
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 x =3D x->next;
> + =A0 =A0 =A0 } while (x);
> +
> + =A0 =A0 =A0 /* DMAFLUSHP peripheral */
> + =A0 =A0 =A0 off +=3D _emit_FLUSHP(dry_run, &buf[off], pxs->r->peri);
> + =A0 =A0 =A0 /* DMASEV peripheral/event */
> + =A0 =A0 =A0 off +=3D _emit_SEV(dry_run, &buf[off], thrd->ev);
> + =A0 =A0 =A0 /* DMAEND */
> + =A0 =A0 =A0 off +=3D _emit_END(dry_run, &buf[off]);
> +
> + =A0 =A0 =A0 return off;
> +}
> +
> +/* Submit a list of xfers after which the client wants notification.
> + * Client is not notified after each xfer unit, just once after all
> + * xfer units are done or some error occurs.
> + * The actual xfer on bus starts automatically
> + */
> +int pl330_submit_req(void *ch_id, struct pl330_req *r)
> +{
> + =A0 =A0 =A0 struct pl330_thread *thrd =3D ch_id;
> + =A0 =A0 =A0 struct pl330_info *pi;
> + =A0 =A0 =A0 struct _xfer_spec xs;
> + =A0 =A0 =A0 void __iomem *regs;
> + =A0 =A0 =A0 u32 ccr;
> + =A0 =A0 =A0 unsigned idx;
> + =A0 =A0 =A0 int ret =3D 0;
> +
> + =A0 =A0 =A0 /* No Req or Unacquired Channel or DMAC stopping */
> + =A0 =A0 =A0 if (!r || !thrd || thrd->free || thrd->dmac->state =3D=3D D=
YING)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -EINVAL;
> +
> + =A0 =A0 =A0 pi =3D &thrd->dmac->pinfo;
> + =A0 =A0 =A0 regs =3D pi->base;
> +
> + =A0 =A0 =A0 /* If request for non-existing peripheral */
> + =A0 =A0 =A0 if (r->peri >=3D pi->pcfg.num_peri)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -EINVAL;
> +
> + =A0 =A0 =A0 mutex_lock(&thrd->mtx);
> +
> + =A0 =A0 =A0 if (_queue_full(thrd)) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D -EBUSY;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto xfer_exit;
> + =A0 =A0 =A0 }
> +
> + =A0 =A0 =A0 /* Use last settings, if not provided */
> + =A0 =A0 =A0 if (r->cfg)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ccr =3D _prepare_ccr(r->cfg);
> + =A0 =A0 =A0 else
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ccr =3D readl(regs + CC(thrd->id));
> +
> + =A0 =A0 =A0 /* If this req doesn't have valid xfer settings */
> + =A0 =A0 =A0 if (!_is_valid(ccr)) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D -EINVAL;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto xfer_exit;
> + =A0 =A0 =A0 }
> +
> + =A0 =A0 =A0 idx =3D thrd->req[0].r ? 1 : 0;
> +
> + =A0 =A0 =A0 xs.ccr =3D ccr;
> + =A0 =A0 =A0 xs.r =3D r;
> +
> + =A0 =A0 =A0 /* First dry run to check if req is acceptable */
> + =A0 =A0 =A0 ret =3D _setup_req(1, thrd, idx, &xs);
> + =A0 =A0 =A0 if (ret < 0)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto xfer_exit;
> +
> + =A0 =A0 =A0 if (ret > pi->mcbufsz / 2) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D -ENOMEM;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto xfer_exit;
> + =A0 =A0 =A0 }
> +
> + =A0 =A0 =A0 ret =3D 0;
> +
> + =A0 =A0 =A0 /* Hook the request */
> + =A0 =A0 =A0 _setup_req(0, thrd, idx, &xs);
> + =A0 =A0 =A0 thrd->req[idx].r =3D r;
> +
> + =A0 =A0 =A0 if (!_start(thrd)) { /* Could not start */
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D -EIO;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto xfer_exit;
> + =A0 =A0 =A0 }
> +
> +xfer_exit:
> + =A0 =A0 =A0 mutex_unlock(&thrd->mtx);
> + =A0 =A0 =A0 return ret;
> +}
> +EXPORT_SYMBOL(pl330_submit_req);

For all exported symbols: I have a hard time seeing anyone compiling the
DMA engine driver or anything else using this as a module and making use
of all these exports. But maybe for testing, what do I know...

> +static void pl330_dotask(unsigned long data)
> +{
> + =A0 =A0 =A0 struct pl330_dmac *pl330 =3D (struct pl330_dmac *) data;
> + =A0 =A0 =A0 struct pl330_info *pi =3D &pl330->pinfo;
> + =A0 =A0 =A0 struct pl330_thread *thrd;
> + =A0 =A0 =A0 int i;
> +
> + =A0 =A0 =A0 /* The DMAC itself gone nuts */
> + =A0 =A0 =A0 if (pl330->dmac_tbd.reset_dmac) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 pl330->state =3D DYING;
> +
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 for (i =3D 0; i < pi->pcfg.num_chan; i++) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 thrd =3D &pl330->channels[i=
];
> +
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Mark thread as infected =
*/
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 pl330->dmac_tbd.reset_chan =
|=3D (1 << thrd->id);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> +
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 pl330->dmac_tbd.reset_mngr =3D 1;
> + =A0 =A0 =A0 }
> +
> + =A0 =A0 =A0 if (pl330->dmac_tbd.reset_mngr)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 _stop(pl330->manager);
> +
> + =A0 =A0 =A0 for (i =3D 0; i < pi->pcfg.num_chan; i++) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 thrd =3D &pl330->channels[i];
> +
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (pl330->dmac_tbd.reset_chan & (1 << thrd=
->id)) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (thrd->active) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 struct pl33=
0_req *r1, *r2;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 enum pl330_=
op_err err;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 void __iome=
m *regs =3D pi->base;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 unsigned ac=
tive;
> +
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 active =3D =
thrd->active - 1;
> +
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 r1 =3D thrd=
->req[active].r;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 r2 =3D thrd=
->req[1 - active].r;
> +
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 thrd->req[a=
ctive].r =3D NULL;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 thrd->req[1=
 - active].r =3D NULL;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 thrd->activ=
e =3D 0;
> +
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (readl(r=
egs + FSC) & (1 << thrd->id))
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
 =A0 err =3D PL330_ERR_FAIL;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 else
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
 =A0 err =3D PL330_ERR_ABORT;
> +
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 _callback(r=
1, err);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 _callback(r=
2, err);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> +
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 _stop(thrd);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> + =A0 =A0 =A0 }
> +
> + =A0 =A0 =A0 /* Clear all errors */
> + =A0 =A0 =A0 pl330->dmac_tbd.reset_dmac =3D 0;
> + =A0 =A0 =A0 pl330->dmac_tbd.reset_mngr =3D 0;
> + =A0 =A0 =A0 pl330->dmac_tbd.reset_chan =3D 0;
> +
> + =A0 =A0 =A0 return;
> +}
> +
> +/* Returns 1 if state was updated, 0 otherwise */
> +int pl330_update(struct pl330_info *pi)
> +{
> + =A0 =A0 =A0 struct pl330_dmac *pl330;
> + =A0 =A0 =A0 void __iomem *regs;
> + =A0 =A0 =A0 u32 val;
> + =A0 =A0 =A0 int id, ev, ret =3D 0;
> +
> + =A0 =A0 =A0 if (!pi)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return 0;
> +
> + =A0 =A0 =A0 pl330 =3D container_of(pi, struct pl330_dmac, pinfo);
> +
> + =A0 =A0 =A0 if (pl330->state =3D=3D DYING)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return 0;
> +
> + =A0 =A0 =A0 regs =3D pi->base;
> +
> + =A0 =A0 =A0 val =3D readl(regs + FSM) & 0x1;
> + =A0 =A0 =A0 pl330->dmac_tbd.reset_mngr |=3D val;
> +
> + =A0 =A0 =A0 val =3D readl(regs + FSC) & ((1 << pi->pcfg.num_chan) - 1);
> + =A0 =A0 =A0 pl330->dmac_tbd.reset_chan |=3D val;
> +
> + =A0 =A0 =A0 /* Check which event happened i.e, thread notified */
> + =A0 =A0 =A0 val =3D readl(regs + ES);
> + =A0 =A0 =A0 if (pi->pcfg.num_events < 32
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 && val & ~((1 << pi->pcfg.n=
um_events) - 1)) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 pl330->dmac_tbd.reset_dmac =3D 1;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 printk(KERN_INFO "%s:%d Unexpected!\n", __f=
unc__, __LINE__);

dev_info(pl330->dev, "...");

> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D 1;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto updt_exit;
> + =A0 =A0 =A0 }
> +
> + =A0 =A0 =A0 INIT_LIST_HEAD(&pl330->req_done);
> +
> + =A0 =A0 =A0 for (ev =3D 0; ev < pi->pcfg.num_events; ev++) {
> +
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 struct _pl330_req *rqdone;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 struct pl330_thread *thrd;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 int active;
> +
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (val & (1 << ev)) { /* Event occured */
> +
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 id =3D pl330->events[ev];
> +
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 thrd =3D &pl330->channels[i=
d];
> +
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 mutex_lock(&thrd->mtx);
> +
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!thrd->active) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 pl330->dmac=
_tbd.reset_chan |=3D (1 << id);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 printk(KERN=
_INFO "%s:%d Unexpected!\n",
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
 =A0 __func__, __LINE__);

dev_info(pl330->dev, "....");

> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> +
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 active =3D thrd->active - 1=
;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 rqdone =3D &thrd->req[activ=
e];
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 rqdone->r =3D NULL;
> +
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (thrd->req[1 - active].r=
)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 thrd->activ=
e =3D 2 - active;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 else
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 thrd->activ=
e =3D 0;
> +
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* Get going again ASAP */
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 _start(thrd);
> +
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* For now, just make a lis=
t of callbacks to be done */
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 list_add_tail(&rqdone->rqd,=
 &pl330->req_done);
> +
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 mutex_unlock(&thrd->mtx);
> +
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D 1;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> + =A0 =A0 =A0 }
> +
> + =A0 =A0 =A0 /* Clear all event interrupts */
> + =A0 =A0 =A0 writel(val, regs + INTCLR);
> +
> + =A0 =A0 =A0 /* Now that we are in no hurry, do the callbacks */
> + =A0 =A0 =A0 while (!list_empty(&pl330->req_done)) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 struct _pl330_req *rqdone =3D
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 container_o=
f(pl330->req_done.next,
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
 =A0 struct _pl330_req, rqd);
> +
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 list_del_init(&rqdone->rqd);
> +
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 _callback(rqdone->r, PL330_ERR_NONE);
> + =A0 =A0 =A0 }
> +
> +updt_exit:
> +
> + =A0 =A0 =A0 if (pl330->dmac_tbd.reset_dmac
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 || pl330->dmac_tbd.reset_mn=
gr
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 || pl330->dmac_tbd.reset_ch=
an) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D 1;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 tasklet_schedule(&pl330->tasks);
> + =A0 =A0 =A0 }
> +
> + =A0 =A0 =A0 return ret;
> +}
> +EXPORT_SYMBOL(pl330_update);
> +
> +/* This must be atomic. Since the DMA client calls this,
> + * there is no need to do callbacks. Otherwise, this may not be atomic.
> + */
> +int pl330_chan_ctrl(void *ch_id, enum pl330_chan_op op)
> +{
> + =A0 =A0 =A0 struct pl330_thread *thrd =3D ch_id;
> + =A0 =A0 =A0 int ret =3D 0;
> +
> + =A0 =A0 =A0 if (!thrd || thrd->free || thrd->dmac->state =3D=3D DYING)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -EINVAL;
> +
> + =A0 =A0 =A0 mutex_lock(&thrd->mtx);
> +
> + =A0 =A0 =A0 if (_queue_empty(thrd))
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto ctrl_exit;
> +
> + =A0 =A0 =A0 switch (op) {
> + =A0 =A0 =A0 case PL330_OP_FLUSH:
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 _stop(thrd);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 thrd->req[0].r =3D NULL;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 thrd->req[1].r =3D NULL;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 thrd->active =3D 0;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 break;
> +
> + =A0 =A0 =A0 case PL330_OP_ABORT:
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 _stop(thrd);
> +
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* ABORT is only for the active req */
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!thrd->active)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 break;
> +
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 thrd->req[thrd->active - 1].r =3D NULL;
> +
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (_queue_empty(thrd)) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 thrd->active =3D 0;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 break;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> +
> + =A0 =A0 =A0 case PL330_OP_START: /* Should be un-necessary */
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!_queue_empty(thrd) && !_start(thrd))
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D -EIO;
> +
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 break;
> +
> + =A0 =A0 =A0 default:
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D -EINVAL;
> + =A0 =A0 =A0 }
> +
> +ctrl_exit:
> + =A0 =A0 =A0 mutex_unlock(&thrd->mtx);
> + =A0 =A0 =A0 return ret;
> +}
> +EXPORT_SYMBOL(pl330_chan_ctrl);
> +
> +int pl330_chan_status(void *ch_id, struct pl330_chanstatus *pstatus)
> +{
> + =A0 =A0 =A0 struct pl330_thread *thrd =3D ch_id;
> + =A0 =A0 =A0 struct pl330_dmac *pl330;
> + =A0 =A0 =A0 struct pl330_info *pi;
> + =A0 =A0 =A0 void __iomem *regs;
> + =A0 =A0 =A0 int i;
> + =A0 =A0 =A0 u32 val;
> +
> + =A0 =A0 =A0 if (!pstatus || !thrd || thrd->free)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -EINVAL;
> +
> + =A0 =A0 =A0 mutex_lock(&thrd->mtx);
> +
> + =A0 =A0 =A0 pl330 =3D thrd->dmac;
> + =A0 =A0 =A0 pi =3D &pl330->pinfo;
> + =A0 =A0 =A0 regs =3D pi->base;
> +
> + =A0 =A0 =A0 /* The client should remove the DMAC and add again */
> + =A0 =A0 =A0 if (pl330->state =3D=3D DYING)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 pstatus->dmac_halted =3D true;
> + =A0 =A0 =A0 else
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 pstatus->dmac_halted =3D false;
> +
> + =A0 =A0 =A0 val =3D readl(regs + FSC);
> + =A0 =A0 =A0 if (val & (1 << thrd->id))
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 pstatus->faulting =3D true;
> + =A0 =A0 =A0 else
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 pstatus->faulting =3D false;
> +
> + =A0 =A0 =A0 val =3D readl(regs + CPC(thrd->id));
> + =A0 =A0 =A0 if (PC_AT_REQ(&thrd->req[0], pi->mcbufsz / 2, val))
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 i =3D 1;
> + =A0 =A0 =A0 else if (PC_AT_REQ(&thrd->req[1], pi->mcbufsz / 2, val))
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 i =3D 2;
> + =A0 =A0 =A0 else
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 i =3D 0;
> +
> + =A0 =A0 =A0 /* If channel inactive while req in queue */
> + =A0 =A0 =A0 if ((thrd->active !=3D i) || (!_queue_empty(thrd) && !i))
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 printk(KERN_INFO "%s:%d DBG: Invalid state!=
",
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 __func__, __LINE__);

dev_err(pl330->dev, "....");

Notice err! Not info.

> +
> + =A0 =A0 =A0 if (i) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 i--;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 pstatus->act_req =3D thrd->req[i].r;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 pstatus->enq_req =3D thrd->req[1-i].r;
> + =A0 =A0 =A0 } else {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 pstatus->act_req =3D NULL;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 pstatus->enq_req =3D NULL;
> + =A0 =A0 =A0 }
> +
> + =A0 =A0 =A0 pstatus->src_addr =3D readl(regs + SA(thrd->id));
> + =A0 =A0 =A0 pstatus->dst_addr =3D readl(regs + DA(thrd->id));
> +
> + =A0 =A0 =A0 mutex_unlock(&thrd->mtx);
> +
> + =A0 =A0 =A0 return 0;
> +}
> +EXPORT_SYMBOL(pl330_chan_status);
> +
> +static inline void _reset_thread(struct pl330_thread *thrd)
> +{
> + =A0 =A0 =A0 struct pl330_dmac *pl330 =3D thrd->dmac;
> + =A0 =A0 =A0 struct pl330_info *pi =3D &pl330->pinfo;
> +
> + =A0 =A0 =A0 thrd->req[0].r =3D NULL;
> + =A0 =A0 =A0 thrd->req[0].mc_cpu =3D pl330->mcode_cpu
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 + (thrd->id=
 * pi->mcbufsz);
> + =A0 =A0 =A0 thrd->req[0].mc_bus =3D pl330->mcode_bus
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 + (thrd->id=
 * pi->mcbufsz);
> +
> + =A0 =A0 =A0 thrd->req[1].r =3D NULL;
> + =A0 =A0 =A0 thrd->req[1].mc_cpu =3D thrd->req[0].mc_cpu
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 + pi->mcbuf=
sz / 2;
> + =A0 =A0 =A0 thrd->req[1].mc_bus =3D thrd->req[0].mc_bus
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 + pi->mcbuf=
sz / 2;
> +}
> +
> +/* Reserve an event */
> +static inline int _alloc_event(struct pl330_thread *thrd)
> +{
> + =A0 =A0 =A0 struct pl330_dmac *pl330 =3D thrd->dmac;
> + =A0 =A0 =A0 struct pl330_info *pi =3D &pl330->pinfo;
> + =A0 =A0 =A0 int ev;
> +
> + =A0 =A0 =A0 for (ev =3D 0; ev < pi->pcfg.num_events; ev++) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (pl330->events[ev] =3D=3D -1) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 pl330->events[ev] =3D thrd-=
>id;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return ev;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> + =A0 =A0 =A0 }
> +
> + =A0 =A0 =A0 return -1;
> +}
> +
> +/* Release an event */
> +static inline void _free_event(struct pl330_thread *thrd, int ev)
> +{
> + =A0 =A0 =A0 struct pl330_dmac *pl330 =3D thrd->dmac;
> + =A0 =A0 =A0 struct pl330_info *pi =3D &pl330->pinfo;
> +
> + =A0 =A0 =A0 if (ev >=3D 0 && ev < pi->pcfg.num_events
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 && pl330->events[ev] =3D=3D=
 thrd->id)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 pl330->events[ev] =3D -1;
> +}
> +
> +void *pl330_request_channel(struct pl330_info *pi)
> +{
> + =A0 =A0 =A0 struct pl330_dmac *pl330;
> + =A0 =A0 =A0 struct pl330_thread *thrd;
> + =A0 =A0 =A0 unsigned long flags;
> + =A0 =A0 =A0 int chans, i;
> +
> + =A0 =A0 =A0 if (!pi)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return NULL;
> +
> + =A0 =A0 =A0 pl330 =3D container_of(pi, struct pl330_dmac, pinfo);
> +
> + =A0 =A0 =A0 if (pl330->state =3D=3D DYING)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return NULL;
> +
> + =A0 =A0 =A0 chans =3D pi->pcfg.num_chan;
> +
> + =A0 =A0 =A0 spin_lock_irqsave(&pl330->lock, flags);
> +
> + =A0 =A0 =A0 thrd =3D NULL;
> + =A0 =A0 =A0 for (i =3D 0; i < chans; i++) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (pl330->channels[i].free) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 thrd =3D &pl330->channels[i=
];
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 _reset_thread(thrd);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 thrd->ev =3D _alloc_event(t=
hrd);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (thrd->ev >=3D 0) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 thrd->free =
=3D false;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 break;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 thrd =3D NULL;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> + =A0 =A0 =A0 }
> +
> + =A0 =A0 =A0 spin_unlock_irqrestore(&pl330->lock, flags);
> +
> + =A0 =A0 =A0 return thrd;
> +}
> +EXPORT_SYMBOL(pl330_request_channel);
> +
> +void pl330_release_channel(void *ch_id)
> +{
> + =A0 =A0 =A0 struct pl330_thread *thrd =3D ch_id;
> + =A0 =A0 =A0 struct pl330_dmac *pl330;
> + =A0 =A0 =A0 struct pl330_req *r1, *r2;
> + =A0 =A0 =A0 unsigned long flags;
> +
> + =A0 =A0 =A0 if (!thrd || thrd->free || thrd->dmac->state =3D=3D DYING)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return;
> +
> + =A0 =A0 =A0 pl330 =3D thrd->dmac;
> +
> + =A0 =A0 =A0 if (thrd->active =3D=3D 1) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 r1 =3D thrd->req[0].r;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 r2 =3D thrd->req[1].r;
> + =A0 =A0 =A0 } else {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 r1 =3D thrd->req[1].r;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 r2 =3D thrd->req[0].r;
> + =A0 =A0 =A0 }
> +
> + =A0 =A0 =A0 mutex_lock(&thrd->mtx);
> +
> + =A0 =A0 =A0 _stop(thrd);
> +
> + =A0 =A0 =A0 mutex_unlock(&thrd->mtx);
> +
> + =A0 =A0 =A0 _callback(r1, PL330_ERR_ABORT);
> + =A0 =A0 =A0 _callback(r2, PL330_ERR_ABORT);
> +
> + =A0 =A0 =A0 spin_lock_irqsave(&pl330->lock, flags);
> + =A0 =A0 =A0 _reset_thread(thrd);
> + =A0 =A0 =A0 _free_event(thrd, thrd->ev);
> + =A0 =A0 =A0 thrd->free =3D true;
> + =A0 =A0 =A0 spin_unlock_irqrestore(&pl330->lock, flags);
> +}
> +EXPORT_SYMBOL(pl330_release_channel);
> +
> +static int dmac_alloc_threads(struct pl330_dmac *pl330)
> +{
> + =A0 =A0 =A0 struct pl330_info *pi =3D &pl330->pinfo;
> + =A0 =A0 =A0 int chans =3D pi->pcfg.num_chan;
> + =A0 =A0 =A0 struct pl330_thread *thrd;
> + =A0 =A0 =A0 int i;
> +
> + =A0 =A0 =A0 /* Allocate 1 Manager and 'chans' Channel threads */
> + =A0 =A0 =A0 pl330->channels =3D kzalloc((1 + chans) * sizeof(*thrd),
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
 =A0 GFP_KERNEL);
> + =A0 =A0 =A0 if (!pl330->channels)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -ENOMEM;
> +
> + =A0 =A0 =A0 /* Init Channel threads */
> + =A0 =A0 =A0 for (i =3D 0; i < chans; i++) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 thrd =3D &pl330->channels[i];
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 thrd->id =3D i;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 thrd->dmac =3D pl330;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 mutex_init(&thrd->mtx);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 _reset_thread(thrd);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 thrd->free =3D true;
> + =A0 =A0 =A0 }
> +
> + =A0 =A0 =A0 /* MANAGER is indexed at the end */
> + =A0 =A0 =A0 thrd =3D &pl330->channels[chans];
> + =A0 =A0 =A0 thrd->id =3D chans;
> + =A0 =A0 =A0 thrd->dmac =3D pl330;
> + =A0 =A0 =A0 thrd->free =3D false; /* Manager can't do xfer */
> + =A0 =A0 =A0 mutex_init(&thrd->mtx);
> + =A0 =A0 =A0 pl330->manager =3D thrd;
> +
> + =A0 =A0 =A0 return 0;
> +}
> +
> +static int dmac_free_threads(struct pl330_dmac *pl330)
> +{
> + =A0 =A0 =A0 struct pl330_info *pi =3D &pl330->pinfo;
> + =A0 =A0 =A0 int chans =3D pi->pcfg.num_chan;
> + =A0 =A0 =A0 struct pl330_thread *thrd;
> + =A0 =A0 =A0 int i;
> +
> + =A0 =A0 =A0 /* Release Channel threads */
> + =A0 =A0 =A0 for (i =3D 0; i < chans; i++) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 thrd =3D &pl330->channels[i];
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 pl330_release_channel((void *)thrd);
> + =A0 =A0 =A0 }
> +
> + =A0 =A0 =A0 /* Free memory */
> + =A0 =A0 =A0 kfree(pl330->channels);
> +
> + =A0 =A0 =A0 return 0;
> +}
> +
> +/* Must be called after pl330_info has been initialized */
> +static int dmac_alloc_resources(struct pl330_dmac *pl330)
> +{
> + =A0 =A0 =A0 struct pl330_info *pi =3D &pl330->pinfo;
> + =A0 =A0 =A0 int chans =3D pi->pcfg.num_chan;
> + =A0 =A0 =A0 int ret;
> +
> + =A0 =A0 =A0 /* Alloc MicroCode buffer for 'chans' Channel threads.
> + =A0 =A0 =A0 =A0* A channel's buffer offset is (Channel_Id * MCODE_BUFF_=
PERCHAN)
> + =A0 =A0 =A0 =A0*/
> + =A0 =A0 =A0 pl330->mcode_cpu =3D dma_alloc_coherent(pl330->dev,
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 chans * pi-=
>mcbufsz,
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 &pl330->mco=
de_bus, GFP_KERNEL);
> + =A0 =A0 =A0 if (!pl330->mcode_cpu) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 printk(KERN_INFO "Unable to allocate MCODE =
buffer\n");

dev_err(pl330->dev, "....");
ERR!

> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -ENOMEM;
> + =A0 =A0 =A0 }
> +
> + =A0 =A0 =A0 ret =3D dmac_alloc_threads(pl330);
> + =A0 =A0 =A0 if (ret) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 printk(KERN_INFO "Unable to create channels=
 for DMAC\n");


dev_err(pl330->dev, "....");
ERR!

> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 dma_free_coherent(pl330->dev,
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 chans * pi-=
>mcbufsz,
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 pl330->mcod=
e_cpu, pl330->mcode_bus);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return ret;
> + =A0 =A0 =A0 }
> +
> + =A0 =A0 =A0 return 0;
> +}
> +
> +static void dmac_free_resources(struct pl330_dmac *pl330)
> +{
> + =A0 =A0 =A0 struct pl330_info *pi =3D &pl330->pinfo;
> + =A0 =A0 =A0 int chans =3D pi->pcfg.num_chan;
> +
> + =A0 =A0 =A0 dmac_free_threads(pl330);
> +
> + =A0 =A0 =A0 dma_free_coherent(pl330->dev, chans * pi->mcbufsz,
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 pl330->mcod=
e_cpu, pl330->mcode_bus);
> +}
> +/* Initialize the structure for PL330 configuration, that can be used
> + * by the client driver the make best use of the DMAC
> + */
> +static void read_dmac_config(struct pl330_dmac *pl330)
> +{
> + =A0 =A0 =A0 struct pl330_info *pi =3D &pl330->pinfo;
> + =A0 =A0 =A0 void __iomem *regs =3D pi->base;
> + =A0 =A0 =A0 u32 val;
> +
> + =A0 =A0 =A0 val =3D readl(regs + CRD) >> CRD_DATA_WIDTH_SHIFT;
> + =A0 =A0 =A0 val &=3D CRD_DATA_WIDTH_MASK;
> + =A0 =A0 =A0 pi->pcfg.data_bus_width =3D 8 * (1 << val);
> +
> + =A0 =A0 =A0 val =3D readl(regs + CR0) >> CR0_NUM_CHANS_SHIFT;
> + =A0 =A0 =A0 val &=3D CR0_NUM_CHANS_MASK;
> + =A0 =A0 =A0 val +=3D 1;
> + =A0 =A0 =A0 pi->pcfg.num_chan =3D val;
> +
> + =A0 =A0 =A0 val =3D readl(regs + CR0);
> + =A0 =A0 =A0 if (val & CR0_PERIPH_REQ_SET) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 val =3D (val >> CR0_NUM_PERIPH_SHIFT) & CR0=
_NUM_PERIPH_MASK;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 val +=3D 1;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 pi->pcfg.num_peri =3D val;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 pi->pcfg.peri_ns =3D readl(regs + CR4);
> + =A0 =A0 =A0 } else {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 pi->pcfg.num_peri =3D 0;
> + =A0 =A0 =A0 }
> +
> + =A0 =A0 =A0 val =3D readl(regs + CR0);
> + =A0 =A0 =A0 if (val & CR0_BOOT_MAN_NS)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 pi->pcfg.mode |=3D DMAC_MODE_NS;
> + =A0 =A0 =A0 else
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 pi->pcfg.mode &=3D ~DMAC_MODE_NS;
> +
> + =A0 =A0 =A0 val =3D readl(regs + CR0) >> CR0_NUM_EVENTS_SHIFT;
> + =A0 =A0 =A0 val &=3D CR0_NUM_EVENTS_MASK;
> + =A0 =A0 =A0 val +=3D 1;
> + =A0 =A0 =A0 pi->pcfg.num_events =3D val;
> +
> + =A0 =A0 =A0 pi->pcfg.irq_ns =3D readl(regs + CR3);
> +
> + =A0 =A0 =A0 pi->pcfg.periph_id =3D get_id(pl330, PERIPH_ID);
> + =A0 =A0 =A0 pi->pcfg.pcell_id =3D get_id(pl330, PCELL_ID);
> +}
> +
> +/* After pl330_alloc, initialize pl330_info.base
> + * before calling pl330_add
> + */
> +int pl330_add(struct pl330_info *pi)
> +{
> + =A0 =A0 =A0 struct pl330_dmac *pl330, *pt;
> + =A0 =A0 =A0 void __iomem *regs;
> + =A0 =A0 =A0 int i;
> +
> + =A0 =A0 =A0 if (!pi)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -EINVAL;
> +
> + =A0 =A0 =A0 pl330 =3D container_of(pi, struct pl330_dmac, pinfo);
> +
> + =A0 =A0 =A0 regs =3D pi->base;
> +
> + =A0 =A0 =A0 /* If the SoC can perform reset on the DMAC, then do it
> + =A0 =A0 =A0 =A0* before reading its configuration.
> + =A0 =A0 =A0 =A0*/
> + =A0 =A0 =A0 if (pi->dmac_reset)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 pi->dmac_reset(pi);
> +
> + =A0 =A0 =A0 /* Check if we can handle this DMAC */
> + =A0 =A0 =A0 if (get_id(pl330, PERIPH_ID) !=3D PERIPH_ID_VAL
> + =A0 =A0 =A0 =A0 =A0|| get_id(pl330, PCELL_ID) !=3D PCELL_ID_VAL) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 printk(KERN_INFO "PERIPH_ID 0x%x, PCELL_ID =
0x%x !\n",
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 readl(regs + PERIPH_ID), re=
adl(regs + PCELL_ID));

dev_info(pl330->dev, ...)

> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -EINVAL;
> + =A0 =A0 =A0 }

If the parent device (IMO a DMAdevices/DMAengine) is an struct amba_device
I don't think this ID check is necessary, there is already PrimeCell
matching code in
<linux/amba/bus.h>

> +
> + =A0 =A0 =A0 /* Make sure it isn't already added */
> + =A0 =A0 =A0 list_for_each_entry(pt, &pl330_list, node)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (pt =3D=3D pl330)

Perhaps print some warning here. Doesn't seem sound that this
would happen.

> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return 0;
> +
> + =A0 =A0 =A0 /* Read the configuration of the DMAC */
> + =A0 =A0 =A0 read_dmac_config(pl330);
> +
> + =A0 =A0 =A0 if (pi->pcfg.num_events =3D=3D 0) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 printk(KERN_INFO "%s:%d Can't work without =
events!\n",
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 __func__, __LINE__);

dev_info(pl330->dev, "....");

> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -EINVAL;
> + =A0 =A0 =A0 }
> +
> + =A0 =A0 =A0 /* Use default MC buffer size if not provided */
> + =A0 =A0 =A0 if (!pi->mcbufsz)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 pi->mcbufsz =3D MCODE_BUFF_PER_REQ * 2;
> +
> + =A0 =A0 =A0 /* Mark all events as free */
> + =A0 =A0 =A0 for (i =3D 0; i < pi->pcfg.num_events; i++)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 pl330->events[i] =3D -1;
> +
> + =A0 =A0 =A0 /* Allocate resources needed by the DMAC */
> + =A0 =A0 =A0 i =3D dmac_alloc_resources(pl330);
> + =A0 =A0 =A0 if (i) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 printk(KERN_INFO "Unable to create channels=
 for DMAC\n");

dev_info(pl330->dev, "....");

> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return i;
> + =A0 =A0 =A0 }
> +
> + =A0 =A0 =A0 mutex_lock(&pl330_mutex);
> + =A0 =A0 =A0 list_add_tail(&pl330->node, &pl330_list);
> + =A0 =A0 =A0 mutex_unlock(&pl330_mutex);
> +
> + =A0 =A0 =A0 tasklet_init(&pl330->tasks, pl330_dotask,
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (unsigned l=
ong) pl330);
> +
> + =A0 =A0 =A0 pl330->state =3D INIT;
> +
> + =A0 =A0 =A0 return 0;
> +}
> +EXPORT_SYMBOL(pl330_add);
> +
> +/* Drop DMAC from the list
> + */
> +void pl330_del(struct pl330_info *pi)
> +{
> + =A0 =A0 =A0 struct pl330_dmac *pl330, *pt;
> + =A0 =A0 =A0 int found;
> +
> + =A0 =A0 =A0 if (!pi)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return;
> +
> + =A0 =A0 =A0 pl330 =3D container_of(pi, struct pl330_dmac, pinfo);
> +
> + =A0 =A0 =A0 pl330->state =3D UNINIT;
> +
> + =A0 =A0 =A0 /* Make sure it is already added */
> + =A0 =A0 =A0 found =3D 0;
> + =A0 =A0 =A0 list_for_each_entry(pt, &pl330_list, node)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (pt =3D=3D pl330)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 found =3D 1;
> +
> + =A0 =A0 =A0 if (!found)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return;
> +
> + =A0 =A0 =A0 tasklet_kill(&pl330->tasks);
> +
> + =A0 =A0 =A0 mutex_lock(&pl330_mutex);
> + =A0 =A0 =A0 list_del(&pl330->node);
> + =A0 =A0 =A0 mutex_unlock(&pl330_mutex);
> +
> + =A0 =A0 =A0 /* Free DMAC resources */
> + =A0 =A0 =A0 dmac_free_resources(pl330);
> +}
> +EXPORT_SYMBOL(pl330_del);
> +
> +struct pl330_info *pl330_alloc(struct device *dev)
> +{
> + =A0 =A0 =A0 struct pl330_dmac *pl330;
> +
> + =A0 =A0 =A0 pl330 =3D kzalloc(sizeof(*pl330), GFP_KERNEL);
> + =A0 =A0 =A0 if (!pl330)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return NULL;
> +
> + =A0 =A0 =A0 spin_lock_init(&pl330->lock);
> +
> + =A0 =A0 =A0 pl330->dev =3D dev;
> +
> + =A0 =A0 =A0 return &pl330->pinfo;
> +}
> +EXPORT_SYMBOL(pl330_alloc);
> +
> +void pl330_free(struct pl330_info *pi)
> +{
> + =A0 =A0 =A0 struct pl330_dmac *pl330;
> +
> + =A0 =A0 =A0 if (!pi)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return;
> +
> + =A0 =A0 =A0 pl330_del(pi);
> +
> + =A0 =A0 =A0 pl330 =3D container_of(pi, struct pl330_dmac, pinfo);
> +
> + =A0 =A0 =A0 kfree(pl330);
> +}
> +EXPORT_SYMBOL(pl330_free);
> diff --git a/arch/arm/include/asm/hardware/pl330.h
> b/arch/arm/include/asm/hardware/pl330.h
> new file mode 100644
> index 0000000..4e907ad
> --- /dev/null
> +++ b/arch/arm/include/asm/hardware/pl330.h
> @@ -0,0 +1,197 @@
> +/* linux/include/asm/hardware/pl330.h
> + *
> + * Copyright (C) 2010 Samsung Electronics Co Ltd.
> + * =A0 =A0 Jaswinder Singh <jassi.brar at samsung.com>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. =A0See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
> + */
> +
> +#ifndef __PL330_CORE_H
> +#define __PL330_CORE_H
> +
> +enum pl330_srccachectrl {
> + =A0 =A0 =A0 SCCTRL0 =3D 0, /* Noncacheable and nonbufferable */
> + =A0 =A0 =A0 SCCTRL1, /* Bufferable only */
> + =A0 =A0 =A0 SCCTRL2, /* Cacheable, but do not allocate */
> + =A0 =A0 =A0 SCCTRL3, /* Cacheable and bufferable, but do not allocate *=
/
> + =A0 =A0 =A0 SINVALID1,
> + =A0 =A0 =A0 SINVALID2,
> + =A0 =A0 =A0 SCCTRL6, /* Cacheable write-through, allocate on reads only=
 */
> + =A0 =A0 =A0 SCCTRL7, /* Cacheable write-back, allocate on reads only */
> +};
> +
> +enum pl330_dstcachectrl {
> + =A0 =A0 =A0 DCCTRL0 =3D 0, /* Noncacheable and nonbufferable */
> + =A0 =A0 =A0 DCCTRL1, /* Bufferable only */
> + =A0 =A0 =A0 DCCTRL2, /* Cacheable, but do not allocate */
> + =A0 =A0 =A0 DCCTRL3, /* Cacheable and bufferable, but do not allocate *=
/
> + =A0 =A0 =A0 DINVALID1 =3D 8,
> + =A0 =A0 =A0 DINVALID2,
> + =A0 =A0 =A0 DCCTRL6, /* Cacheable write-through, allocate on writes onl=
y */
> + =A0 =A0 =A0 DCCTRL7, /* Cacheable write-back, allocate on writes only *=
/
> +};
> +
> +/* Populated by the PL330 core driver for DMA API driver's info */
> +struct pl330_config {
> + =A0 =A0 =A0 u32 =A0 =A0 periph_id;
> + =A0 =A0 =A0 u32 =A0 =A0 pcell_id;
> +#define DMAC_MODE_NS =A0 (1 << 0)
> + =A0 =A0 =A0 unsigned int =A0 =A0mode;
> + =A0 =A0 =A0 unsigned int =A0 =A0data_bus_width:10; /* In number of bits=
 */
> + =A0 =A0 =A0 unsigned int =A0 =A0num_chan:4;
> + =A0 =A0 =A0 unsigned int =A0 =A0num_peri:6;
> + =A0 =A0 =A0 u32 =A0 =A0 =A0 =A0 =A0 =A0 peri_ns;
> + =A0 =A0 =A0 unsigned int =A0 =A0num_events:6;
> + =A0 =A0 =A0 u32 =A0 =A0 =A0 =A0 =A0 =A0 irq_ns;
> +};
> +
> +/* Handle to the DMAC provided by PL330 engine */
> +struct pl330_info {

Contemplate adding:
      /* Owning device */
      struct device *dev;

> + =A0 =A0 =A0 /* Size of MicroCode buffers for each channel */
> + =A0 =A0 =A0 unsigned mcbufsz;
> + =A0 =A0 =A0 /* ioremap'ed address of PL330 registers */
> + =A0 =A0 =A0 void __iomem =A0 =A0*base;
> + =A0 =A0 =A0 /* Client can freely use it */
> + =A0 =A0 =A0 void =A0 =A0*private_data;
> + =A0 =A0 =A0 /* Populated by the PL330 core driver during pl330_add */
> + =A0 =A0 =A0 struct pl330_config =A0 =A0 pcfg;
> + =A0 =A0 =A0 /* If the DMAC has some reset mechanism, then the client
> + =A0 =A0 =A0 =A0* may want to provide pointer to the relevent function.
> + =A0 =A0 =A0 =A0*/
> + =A0 =A0 =A0 void (*dmac_reset)(struct pl330_info *pi);
> +};
> +
> +enum pl330_byteswap {
> + =A0 =A0 =A0 SWAP_NO =3D 0,
> + =A0 =A0 =A0 SWAP_2,
> + =A0 =A0 =A0 SWAP_4,
> + =A0 =A0 =A0 SWAP_8,
> + =A0 =A0 =A0 SWAP_16,
> +};
> +
> +enum pl330_reqtype {
> + =A0 =A0 =A0 MEMTOMEM,
> + =A0 =A0 =A0 MEMTODEV,
> + =A0 =A0 =A0 DEVTOMEM,
> + =A0 =A0 =A0 DEVTODEV,
> +};
> +
> +/* Request Configuration.
> + * The PL330 core 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 {
> + =A0 =A0 =A0 /* Implies Incrementing address */
> + =A0 =A0 =A0 unsigned dst_inc:1;
> + =A0 =A0 =A0 unsigned src_inc:1;
> +
> + =A0 =A0 =A0 /* For now, the SRC & DST protection levels
> + =A0 =A0 =A0 =A0* and burst size/length are assumed same
> + =A0 =A0 =A0 =A0*/
> + =A0 =A0 =A0 unsigned nonsecure:1;
> + =A0 =A0 =A0 unsigned privileged:1;
> + =A0 =A0 =A0 unsigned insnaccess:1;

For all of these things using just one bit, contemplate
turning them into bool instead, because that's what they are.

> + =A0 =A0 =A0 unsigned brst_len:5;
> + =A0 =A0 =A0 unsigned brst_size:3; /* power of 2 */
> +
> + =A0 =A0 =A0 enum pl330_dstcachectrl dcctl;
> + =A0 =A0 =A0 enum pl330_srccachectrl scctl;
> + =A0 =A0 =A0 enum pl330_byteswap swap;
> +};
> +
> +/* One cycle of DMAC operation.
> + * There may be more than one xfer in a request.
> + */
> +struct pl330_xfer {
> + =A0 =A0 =A0 u32 src_addr;
> + =A0 =A0 =A0 u32 dst_addr;
> + =A0 =A0 =A0 /* Number of total _bytes_ to xfer */
> + =A0 =A0 =A0 u32 bytes;
> + =A0 =A0 =A0 /* Pointer to next xfer in the list.
> + =A0 =A0 =A0 =A0* The last xfer in the req must point to NULL
> + =A0 =A0 =A0 =A0*/
> + =A0 =A0 =A0 struct pl330_xfer *next;
> +};
> +
> +/* A request defining Scatter-Gather List ending with NULL xfer */
> +struct pl330_req {
> + =A0 =A0 =A0 enum pl330_reqtype rqtype;
> + =A0 =A0 =A0 /* Index of peripheral for the xfer */
> + =A0 =A0 =A0 unsigned peri:5;
> + =A0 =A0 =A0 /* Unique token for this xfer, set by the DMA engine */
> + =A0 =A0 =A0 void *token;
> + =A0 =A0 =A0 /* Callback to be called after xfer */
> + =A0 =A0 =A0 void (*xfer_cb)(void *token, int result);
> + =A0 =A0 =A0 /* If NULL, req will be done at last set parameters */
> + =A0 =A0 =A0 struct pl330_reqcfg *cfg;
> + =A0 =A0 =A0 /* Pointer to first xfer in the List */
> + =A0 =A0 =A0 struct pl330_xfer *x;
> +};
> +
> +/* To know the status of the channel and DMAC, the client
> + * provides a pointer to this structure. The PL330 core
> + * fills it with current information
> + */
> +struct pl330_chanstatus {
> + =A0 =A0 =A0 /* If the DMAC engine halted due to some error,
> + =A0 =A0 =A0 =A0* the client should remove-add DMAC */
> + =A0 =A0 =A0 bool dmac_halted;
> + =A0 =A0 =A0 /* If channel is halted due to some error,
> + =A0 =A0 =A0 =A0* the client may ABORT or FLUSH the channel */
> + =A0 =A0 =A0 bool faulting;
> + =A0 =A0 =A0 /* Location of last load */
> + =A0 =A0 =A0 u32 src_addr;
> + =A0 =A0 =A0 /* Location of last store */
> + =A0 =A0 =A0 u32 dst_addr;
> + =A0 =A0 =A0 /* Pointer to the active req */
> + =A0 =A0 =A0 struct pl330_req *act_req;
> + =A0 =A0 =A0 /* Pointer to req waiting in the queue */
> + =A0 =A0 =A0 struct pl330_req *enq_req;
> +};
> +
> +/* The callbacks are made with one of these arguments */
> +enum pl330_op_err {
> + =A0 =A0 =A0 /* The all xfers in the request were success */
> + =A0 =A0 =A0 PL330_ERR_NONE,
> + =A0 =A0 =A0 /* If req aborted due to global error */
> + =A0 =A0 =A0 PL330_ERR_ABORT,
> + =A0 =A0 =A0 /* If req failed due to problem with Channel */
> + =A0 =A0 =A0 PL330_ERR_FAIL,
> +};
> +
> +enum pl330_chan_op {
> + =A0 =A0 =A0 /* Start the channel */
> + =A0 =A0 =A0 PL330_OP_START,
> + =A0 =A0 =A0 /* Abort the active xfer */
> + =A0 =A0 =A0 PL330_OP_ABORT,
> + =A0 =A0 =A0 /* Stop xfer and flush queue */
> + =A0 =A0 =A0 PL330_OP_FLUSH,
> +};
> +
> +extern struct pl330_info *pl330_alloc(struct device *);
> +extern int pl330_add(struct pl330_info *);
> +extern void pl330_del(struct pl330_info *pi);
> +extern int pl330_update(struct pl330_info *pi);
> +extern void pl330_release_channel(void *ch_id);
> +extern void *pl330_request_channel(struct pl330_info *pi);
> +extern int pl330_chan_status(void *ch_id, struct pl330_chanstatus *pstat=
us);
> +extern int pl330_chan_ctrl(void *ch_id, enum pl330_chan_op op);
> +extern int pl330_submit_req(void *ch_id, struct pl330_req *r);
> +extern void pl330_free(struct pl330_info *pi);


Do you really need both pairs:

pl330_alloc() + pl330_add() and
pl330_del() + pl330_free()

to be public and exposed in the interface and exported? I would suggest mak=
ing
removing two of them unless there is something I don't get here.
IMO:

int pl330_add(struct device *, struct pl330_info *);
Should be enough, pl330_info will be filled in if the call returns sucessfu=
lly.
You could also

struct pl330_info *pl330_add(struct device *);

If you prefer to use macros like IS_ERR() etc on the returned pointer.

> +#endif /* __PL330_CORE_H */
> --
> 1.6.2.5
>

Yours,
Linus Walleij



More information about the linux-arm-kernel mailing list