···11+PXA/MMP - DMA Slave controller22+==============================33+44+Constraints55+-----------66+ a) Transfers hot queuing77+ A driver submitting a transfer and issuing it should be granted the transfer88+ is queued even on a running DMA channel.99+ This implies that the queuing doesn't wait for the previous transfer end,1010+ and that the descriptor chaining is not only done in the irq/tasklet code1111+ triggered by the end of the transfer.1212+ A transfer which is submitted and issued on a phy doesn't wait for a phy to1313+ stop and restart, but is submitted on a "running channel". The other1414+ drivers, especially mmp_pdma waited for the phy to stop before relaunching1515+ a new transfer.1616+1717+ b) All transfers having asked for confirmation should be signaled1818+ Any issued transfer with DMA_PREP_INTERRUPT should trigger a callback call.1919+ This implies that even if an irq/tasklet is triggered by end of tx1, but2020+ at the time of irq/dma tx2 is already finished, tx1->complete() and2121+ tx2->complete() should be called.2222+2323+ c) Channel running state2424+ A driver should be able to query if a channel is running or not. For the2525+ multimedia case, such as video capture, if a transfer is submitted and then2626+ a check of the DMA channel reports a "stopped channel", the transfer should2727+ not be issued until the next "start of frame interrupt", hence the need to2828+ know if a channel is in running or stopped state.2929+3030+ d) Bandwidth guarantee3131+ The PXA architecture has 4 levels of DMAs priorities : high, normal, low.3232+ The high prorities get twice as much bandwidth as the normal, which get twice3333+ as much as the low priorities.3434+ A driver should be able to request a priority, especially the real-time3535+ ones such as pxa_camera with (big) throughputs.3636+3737+Design3838+------3939+ a) Virtual channels4040+ Same concept as in sa11x0 driver, ie. a driver was assigned a "virtual4141+ channel" linked to the requestor line, and the physical DMA channel is4242+ assigned on the fly when the transfer is issued.4343+4444+ b) Transfer anatomy for a scatter-gather transfer4545+ +------------+-----+---------------+----------------+-----------------+4646+ | desc-sg[0] | ... | desc-sg[last] | status updater | finisher/linker |4747+ +------------+-----+---------------+----------------+-----------------+4848+4949+ This structure is pointed by dma->sg_cpu.5050+ The descriptors are used as follows :5151+ - desc-sg[i]: i-th descriptor, transferring the i-th sg5252+ element to the video buffer scatter gather5353+ - status updater5454+ Transfers a single u32 to a well known dma coherent memory to leave5555+ a trace that this transfer is done. The "well known" is unique per5656+ physical channel, meaning that a read of this value will tell which5757+ is the last finished transfer at that point in time.5858+ - finisher: has ddadr=DADDR_STOP, dcmd=ENDIRQEN5959+ - linker: has ddadr= desc-sg[0] of next transfer, dcmd=06060+6161+ c) Transfers hot-chaining6262+ Suppose the running chain is :6363+ Buffer 1 Buffer 26464+ +---------+----+---+ +----+----+----+---+6565+ | d0 | .. | dN | l | | d0 | .. | dN | f |6666+ +---------+----+-|-+ ^----+----+----+---+6767+ | |6868+ +----+6969+7070+ After a call to dmaengine_submit(b3), the chain will look like :7171+ Buffer 1 Buffer 2 Buffer 37272+ +---------+----+---+ +----+----+----+---+ +----+----+----+---+7373+ | d0 | .. | dN | l | | d0 | .. | dN | l | | d0 | .. | dN | f |7474+ +---------+----+-|-+ ^----+----+----+-|-+ ^----+----+----+---+7575+ | | | |7676+ +----+ +----+7777+ new_link7878+7979+ If while new_link was created the DMA channel stopped, it is _not_8080+ restarted. Hot-chaining doesn't break the assumption that8181+ dma_async_issue_pending() is to be used to ensure the transfer is actually started.8282+8383+ One exception to this rule :8484+ - if Buffer1 and Buffer2 had all their addresses 8 bytes aligned8585+ - and if Buffer3 has at least one address not 4 bytes aligned8686+ - then hot-chaining cannot happen, as the channel must be stopped, the8787+ "align bit" must be set, and the channel restarted As a consequence,8888+ such a transfer tx_submit() will be queued on the submitted queue, and8989+ this specific case if the DMA is already running in aligned mode.9090+9191+ d) Transfers completion updater9292+ Each time a transfer is completed on a channel, an interrupt might be9393+ generated or not, up to the client's request. But in each case, the last9494+ descriptor of a transfer, the "status updater", will write the latest9595+ transfer being completed into the physical channel's completion mark.9696+9797+ This will speed up residue calculation, for large transfers such as video9898+ buffers which hold around 6k descriptors or more. This also allows without9999+ any lock to find out what is the latest completed transfer in a running100100+ DMA chain.101101+102102+ e) Transfers completion, irq and tasklet103103+ When a transfer flagged as "DMA_PREP_INTERRUPT" is finished, the dma irq104104+ is raised. Upon this interrupt, a tasklet is scheduled for the physical105105+ channel.106106+ The tasklet is responsible for :107107+ - reading the physical channel last updater mark108108+ - calling all the transfer callbacks of finished transfers, based on109109+ that mark, and each transfer flags.110110+ If a transfer is completed while this handling is done, a dma irq will111111+ be raised, and the tasklet will be scheduled once again, having a new112112+ updater mark.113113+114114+ f) Residue115115+ Residue granularity will be descriptor based. The issued but not completed116116+ transfers will be scanned for all of their descriptors against the117117+ currently running descriptor.118118+119119+ g) Most complicated case of driver's tx queues120120+ The most tricky situation is when :121121+ - there are not "acked" transfers (tx0)122122+ - a driver submitted an aligned tx1, not chained123123+ - a driver submitted an aligned tx2 => tx2 is cold chained to tx1124124+ - a driver issued tx1+tx2 => channel is running in aligned mode125125+ - a driver submitted an aligned tx3 => tx3 is hot-chained126126+ - a driver submitted an unaligned tx4 => tx4 is put in submitted queue,127127+ not chained128128+ - a driver issued tx4 => tx4 is put in issued queue, not chained129129+ - a driver submitted an aligned tx5 => tx5 is put in submitted queue, not130130+ chained131131+ - a driver submitted an aligned tx6 => tx6 is put in submitted queue,132132+ cold chained to tx5133133+134134+ This translates into (after tx4 is issued) :135135+ - issued queue136136+ +-----+ +-----+ +-----+ +-----+137137+ | tx1 | | tx2 | | tx3 | | tx4 |138138+ +---|-+ ^---|-+ ^-----+ +-----+139139+ | | | |140140+ +---+ +---+141141+ - submitted queue142142+ +-----+ +-----+143143+ | tx5 | | tx6 |144144+ +---|-+ ^-----+145145+ | |146146+ +---+147147+ - completed queue : empty148148+ - allocated queue : tx0149149+150150+ It should be noted that after tx3 is completed, the channel is stopped, and151151+ restarted in "unaligned mode" to handle tx4.152152+153153+Author: Robert Jarzmik <robert.jarzmik@free.fr>