xref: /OK3568_Linux_fs/kernel/Documentation/driver-api/dmaengine/pxa_dma.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun==============================
2*4882a593SmuzhiyunPXA/MMP - DMA Slave controller
3*4882a593Smuzhiyun==============================
4*4882a593Smuzhiyun
5*4882a593SmuzhiyunConstraints
6*4882a593Smuzhiyun===========
7*4882a593Smuzhiyun
8*4882a593Smuzhiyuna) Transfers hot queuing
9*4882a593SmuzhiyunA driver submitting a transfer and issuing it should be granted the transfer
10*4882a593Smuzhiyunis queued even on a running DMA channel.
11*4882a593SmuzhiyunThis implies that the queuing doesn't wait for the previous transfer end,
12*4882a593Smuzhiyunand that the descriptor chaining is not only done in the irq/tasklet code
13*4882a593Smuzhiyuntriggered by the end of the transfer.
14*4882a593SmuzhiyunA transfer which is submitted and issued on a phy doesn't wait for a phy to
15*4882a593Smuzhiyunstop and restart, but is submitted on a "running channel". The other
16*4882a593Smuzhiyundrivers, especially mmp_pdma waited for the phy to stop before relaunching
17*4882a593Smuzhiyuna new transfer.
18*4882a593Smuzhiyun
19*4882a593Smuzhiyunb) All transfers having asked for confirmation should be signaled
20*4882a593SmuzhiyunAny issued transfer with DMA_PREP_INTERRUPT should trigger a callback call.
21*4882a593SmuzhiyunThis implies that even if an irq/tasklet is triggered by end of tx1, but
22*4882a593Smuzhiyunat the time of irq/dma tx2 is already finished, tx1->complete() and
23*4882a593Smuzhiyuntx2->complete() should be called.
24*4882a593Smuzhiyun
25*4882a593Smuzhiyunc) Channel running state
26*4882a593SmuzhiyunA driver should be able to query if a channel is running or not. For the
27*4882a593Smuzhiyunmultimedia case, such as video capture, if a transfer is submitted and then
28*4882a593Smuzhiyuna check of the DMA channel reports a "stopped channel", the transfer should
29*4882a593Smuzhiyunnot be issued until the next "start of frame interrupt", hence the need to
30*4882a593Smuzhiyunknow if a channel is in running or stopped state.
31*4882a593Smuzhiyun
32*4882a593Smuzhiyund) Bandwidth guarantee
33*4882a593SmuzhiyunThe PXA architecture has 4 levels of DMAs priorities : high, normal, low.
34*4882a593SmuzhiyunThe high priorities get twice as much bandwidth as the normal, which get twice
35*4882a593Smuzhiyunas much as the low priorities.
36*4882a593SmuzhiyunA driver should be able to request a priority, especially the real-time
37*4882a593Smuzhiyunones such as pxa_camera with (big) throughputs.
38*4882a593Smuzhiyun
39*4882a593SmuzhiyunDesign
40*4882a593Smuzhiyun======
41*4882a593Smuzhiyuna) Virtual channels
42*4882a593SmuzhiyunSame concept as in sa11x0 driver, ie. a driver was assigned a "virtual
43*4882a593Smuzhiyunchannel" linked to the requestor line, and the physical DMA channel is
44*4882a593Smuzhiyunassigned on the fly when the transfer is issued.
45*4882a593Smuzhiyun
46*4882a593Smuzhiyunb) Transfer anatomy for a scatter-gather transfer
47*4882a593Smuzhiyun
48*4882a593Smuzhiyun::
49*4882a593Smuzhiyun
50*4882a593Smuzhiyun   +------------+-----+---------------+----------------+-----------------+
51*4882a593Smuzhiyun   | desc-sg[0] | ... | desc-sg[last] | status updater | finisher/linker |
52*4882a593Smuzhiyun   +------------+-----+---------------+----------------+-----------------+
53*4882a593Smuzhiyun
54*4882a593SmuzhiyunThis structure is pointed by dma->sg_cpu.
55*4882a593SmuzhiyunThe descriptors are used as follows :
56*4882a593Smuzhiyun
57*4882a593Smuzhiyun    - desc-sg[i]: i-th descriptor, transferring the i-th sg
58*4882a593Smuzhiyun      element to the video buffer scatter gather
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun    - status updater
61*4882a593Smuzhiyun      Transfers a single u32 to a well known dma coherent memory to leave
62*4882a593Smuzhiyun      a trace that this transfer is done. The "well known" is unique per
63*4882a593Smuzhiyun      physical channel, meaning that a read of this value will tell which
64*4882a593Smuzhiyun      is the last finished transfer at that point in time.
65*4882a593Smuzhiyun
66*4882a593Smuzhiyun    - finisher: has ddadr=DADDR_STOP, dcmd=ENDIRQEN
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun    - linker: has ddadr= desc-sg[0] of next transfer, dcmd=0
69*4882a593Smuzhiyun
70*4882a593Smuzhiyunc) Transfers hot-chaining
71*4882a593SmuzhiyunSuppose the running chain is:
72*4882a593Smuzhiyun
73*4882a593Smuzhiyun::
74*4882a593Smuzhiyun
75*4882a593Smuzhiyun   Buffer 1              Buffer 2
76*4882a593Smuzhiyun   +---------+----+---+  +----+----+----+---+
77*4882a593Smuzhiyun   | d0 | .. | dN | l |  | d0 | .. | dN | f |
78*4882a593Smuzhiyun   +---------+----+-|-+  ^----+----+----+---+
79*4882a593Smuzhiyun                    |    |
80*4882a593Smuzhiyun                    +----+
81*4882a593Smuzhiyun
82*4882a593SmuzhiyunAfter a call to dmaengine_submit(b3), the chain will look like:
83*4882a593Smuzhiyun
84*4882a593Smuzhiyun::
85*4882a593Smuzhiyun
86*4882a593Smuzhiyun   Buffer 1              Buffer 2              Buffer 3
87*4882a593Smuzhiyun   +---------+----+---+  +----+----+----+---+  +----+----+----+---+
88*4882a593Smuzhiyun   | d0 | .. | dN | l |  | d0 | .. | dN | l |  | d0 | .. | dN | f |
89*4882a593Smuzhiyun   +---------+----+-|-+  ^----+----+----+-|-+  ^----+----+----+---+
90*4882a593Smuzhiyun                    |    |                |    |
91*4882a593Smuzhiyun                    +----+                +----+
92*4882a593Smuzhiyun                                         new_link
93*4882a593Smuzhiyun
94*4882a593SmuzhiyunIf while new_link was created the DMA channel stopped, it is _not_
95*4882a593Smuzhiyunrestarted. Hot-chaining doesn't break the assumption that
96*4882a593Smuzhiyundma_async_issue_pending() is to be used to ensure the transfer is actually started.
97*4882a593Smuzhiyun
98*4882a593SmuzhiyunOne exception to this rule :
99*4882a593Smuzhiyun
100*4882a593Smuzhiyun- if Buffer1 and Buffer2 had all their addresses 8 bytes aligned
101*4882a593Smuzhiyun
102*4882a593Smuzhiyun- and if Buffer3 has at least one address not 4 bytes aligned
103*4882a593Smuzhiyun
104*4882a593Smuzhiyun- then hot-chaining cannot happen, as the channel must be stopped, the
105*4882a593Smuzhiyun  "align bit" must be set, and the channel restarted As a consequence,
106*4882a593Smuzhiyun  such a transfer tx_submit() will be queued on the submitted queue, and
107*4882a593Smuzhiyun  this specific case if the DMA is already running in aligned mode.
108*4882a593Smuzhiyun
109*4882a593Smuzhiyund) Transfers completion updater
110*4882a593SmuzhiyunEach time a transfer is completed on a channel, an interrupt might be
111*4882a593Smuzhiyungenerated or not, up to the client's request. But in each case, the last
112*4882a593Smuzhiyundescriptor of a transfer, the "status updater", will write the latest
113*4882a593Smuzhiyuntransfer being completed into the physical channel's completion mark.
114*4882a593Smuzhiyun
115*4882a593SmuzhiyunThis will speed up residue calculation, for large transfers such as video
116*4882a593Smuzhiyunbuffers which hold around 6k descriptors or more. This also allows without
117*4882a593Smuzhiyunany lock to find out what is the latest completed transfer in a running
118*4882a593SmuzhiyunDMA chain.
119*4882a593Smuzhiyun
120*4882a593Smuzhiyune) Transfers completion, irq and tasklet
121*4882a593SmuzhiyunWhen a transfer flagged as "DMA_PREP_INTERRUPT" is finished, the dma irq
122*4882a593Smuzhiyunis raised. Upon this interrupt, a tasklet is scheduled for the physical
123*4882a593Smuzhiyunchannel.
124*4882a593Smuzhiyun
125*4882a593SmuzhiyunThe tasklet is responsible for :
126*4882a593Smuzhiyun
127*4882a593Smuzhiyun- reading the physical channel last updater mark
128*4882a593Smuzhiyun
129*4882a593Smuzhiyun- calling all the transfer callbacks of finished transfers, based on
130*4882a593Smuzhiyun  that mark, and each transfer flags.
131*4882a593Smuzhiyun
132*4882a593SmuzhiyunIf a transfer is completed while this handling is done, a dma irq will
133*4882a593Smuzhiyunbe raised, and the tasklet will be scheduled once again, having a new
134*4882a593Smuzhiyunupdater mark.
135*4882a593Smuzhiyun
136*4882a593Smuzhiyunf) Residue
137*4882a593SmuzhiyunResidue granularity will be descriptor based. The issued but not completed
138*4882a593Smuzhiyuntransfers will be scanned for all of their descriptors against the
139*4882a593Smuzhiyuncurrently running descriptor.
140*4882a593Smuzhiyun
141*4882a593Smuzhiyung) Most complicated case of driver's tx queues
142*4882a593SmuzhiyunThe most tricky situation is when :
143*4882a593Smuzhiyun
144*4882a593Smuzhiyun - there are not "acked" transfers (tx0)
145*4882a593Smuzhiyun
146*4882a593Smuzhiyun - a driver submitted an aligned tx1, not chained
147*4882a593Smuzhiyun
148*4882a593Smuzhiyun - a driver submitted an aligned tx2 => tx2 is cold chained to tx1
149*4882a593Smuzhiyun
150*4882a593Smuzhiyun - a driver issued tx1+tx2 => channel is running in aligned mode
151*4882a593Smuzhiyun
152*4882a593Smuzhiyun - a driver submitted an aligned tx3 => tx3 is hot-chained
153*4882a593Smuzhiyun
154*4882a593Smuzhiyun - a driver submitted an unaligned tx4 => tx4 is put in submitted queue,
155*4882a593Smuzhiyun   not chained
156*4882a593Smuzhiyun
157*4882a593Smuzhiyun - a driver issued tx4 => tx4 is put in issued queue, not chained
158*4882a593Smuzhiyun
159*4882a593Smuzhiyun - a driver submitted an aligned tx5 => tx5 is put in submitted queue, not
160*4882a593Smuzhiyun   chained
161*4882a593Smuzhiyun
162*4882a593Smuzhiyun - a driver submitted an aligned tx6 => tx6 is put in submitted queue,
163*4882a593Smuzhiyun   cold chained to tx5
164*4882a593Smuzhiyun
165*4882a593Smuzhiyun This translates into (after tx4 is issued) :
166*4882a593Smuzhiyun
167*4882a593Smuzhiyun - issued queue
168*4882a593Smuzhiyun
169*4882a593Smuzhiyun ::
170*4882a593Smuzhiyun
171*4882a593Smuzhiyun      +-----+ +-----+ +-----+ +-----+
172*4882a593Smuzhiyun      | tx1 | | tx2 | | tx3 | | tx4 |
173*4882a593Smuzhiyun      +---|-+ ^---|-+ ^-----+ +-----+
174*4882a593Smuzhiyun          |   |   |   |
175*4882a593Smuzhiyun          +---+   +---+
176*4882a593Smuzhiyun        - submitted queue
177*4882a593Smuzhiyun      +-----+ +-----+
178*4882a593Smuzhiyun      | tx5 | | tx6 |
179*4882a593Smuzhiyun      +---|-+ ^-----+
180*4882a593Smuzhiyun          |   |
181*4882a593Smuzhiyun          +---+
182*4882a593Smuzhiyun
183*4882a593Smuzhiyun- completed queue : empty
184*4882a593Smuzhiyun
185*4882a593Smuzhiyun- allocated queue : tx0
186*4882a593Smuzhiyun
187*4882a593SmuzhiyunIt should be noted that after tx3 is completed, the channel is stopped, and
188*4882a593Smuzhiyunrestarted in "unaligned mode" to handle tx4.
189*4882a593Smuzhiyun
190*4882a593SmuzhiyunAuthor: Robert Jarzmik <robert.jarzmik@free.fr>
191