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

Merge tag 'dmaengine-4.2-rc1' of git://git.infradead.org/users/vkoul/slave-dma

Pull dmaengine updates from Vinod Koul:
"This time we have support for few new devices, few new features and
odd fixes spread thru the subsystem.

New devices added:
- support for CSRatlas7 dma controller
- Allwinner H3(sun8i) controller
- TI DMA crossbar driver on DRA7x
- new pxa driver

New features added:
- memset support is bought back now that we have a user in xdmac controller
- interleaved transfers support different source and destination strides
- supporting DMA routers and configuration thru DT
- support for reusing descriptors
- xdmac memset and interleaved transfer support
- hdmac support for interleaved transfers
- omap-dma support for memcpy

Others:
- Constify platform_device_id
- mv_xor fixes and improvements"

* tag 'dmaengine-4.2-rc1' of git://git.infradead.org/users/vkoul/slave-dma: (46 commits)
dmaengine: xgene: fix file permission
dmaengine: fsl-edma: clear pending interrupts on initialization
dmaengine: xdmac: Add memset support
Documentation: dmaengine: document DMA_CTRL_ACK
dmaengine: virt-dma: don't always free descriptor upon completion
dmaengine: Revert "drivers/dma: remove unused support for MEMSET operations"
dmaengine: hdmac: Implement interleaved transfers
dmaengine: Move icg helpers to global header
dmaengine: mv_xor: improve descriptors list handling and reduce locking
dmaengine: mv_xor: Enlarge descriptor pool size
dmaengine: mv_xor: add support for a38x command in descriptor mode
dmaengine: mv_xor: Rename function for consistent naming
dmaengine: mv_xor: bug fix for racing condition in descriptors cleanup
dmaengine: pl330: fix wording in mcbufsz message
dmaengine: sirf: add CSRatlas7 SoC support
dmaengine: xgene-dma: Fix "incorrect type in assignement" warnings
dmaengine: fix kernel-doc documentation
dmaengine: pxa_dma: add support for legacy transition
dmaengine: pxa_dma: add debug information
dmaengine: pxa: add pxa dmaengine driver
...

+3327 -495
+28
Documentation/devicetree/bindings/dma/dma.txt
··· 31 31 dma-requests = <127>; 32 32 }; 33 33 34 + * DMA router 35 + 36 + DMA routers are transparent IP blocks used to route DMA request lines from 37 + devices to the DMA controller. Some SoCs (like TI DRA7x) have more peripherals 38 + integrated with DMA requests than what the DMA controller can handle directly. 39 + 40 + Required property: 41 + - dma-masters: phandle of the DMA controller or list of phandles for 42 + the DMA controllers the router can direct the signal to. 43 + - #dma-cells: Must be at least 1. Used to provide DMA router specific 44 + information. See DMA client binding below for more 45 + details. 46 + 47 + Optional properties: 48 + - dma-requests: Number of incoming request lines the router can handle. 49 + - In the node pointed by the dma-masters: 50 + - dma-requests: The router driver might need to look for this in order 51 + to configure the routing. 52 + 53 + Example: 54 + sdma_xbar: dma-router@4a002b78 { 55 + compatible = "ti,dra7-dma-crossbar"; 56 + reg = <0x4a002b78 0xfc>; 57 + #dma-cells = <1>; 58 + dma-requests = <205>; 59 + ti,dma-safe-map = <0>; 60 + dma-masters = <&sdma>; 61 + }; 34 62 35 63 * DMA client 36 64
+1 -1
Documentation/devicetree/bindings/dma/mv-xor.txt
··· 1 1 * Marvell XOR engines 2 2 3 3 Required properties: 4 - - compatible: Should be "marvell,orion-xor" 4 + - compatible: Should be "marvell,orion-xor" or "marvell,armada-380-xor" 5 5 - reg: Should contain registers location and length (two sets) 6 6 the first set is the low registers, the second set the high 7 7 registers for the XOR engine.
+2 -1
Documentation/devicetree/bindings/dma/sirfsoc-dma.txt
··· 3 3 See dma.txt first 4 4 5 5 Required properties: 6 - - compatible: Should be "sirf,prima2-dmac" or "sirf,marco-dmac" 6 + - compatible: Should be "sirf,prima2-dmac", "sirf,atlas7-dmac" or 7 + "sirf,atlas7-dmac-v2" 7 8 - reg: Should contain DMA registers location and length. 8 9 - interrupts: Should contain one interrupt shared by all channel 9 10 - #dma-cells: must be <1>. used to represent the number of integer
+4 -1
Documentation/devicetree/bindings/dma/sun6i-dma.txt
··· 4 4 5 5 Required properties: 6 6 7 - - compatible: Must be "allwinner,sun6i-a31-dma" or "allwinner,sun8i-a23-dma" 7 + - compatible: Must be one of 8 + "allwinner,sun6i-a31-dma" 9 + "allwinner,sun8i-a23-dma" 10 + "allwinner,sun8i-h3-dma" 8 11 - reg: Should contain the registers base address and length 9 12 - interrupts: Should contain a reference to the interrupt used by this device 10 13 - clocks: Should contain a reference to the parent AHB clock
+52
Documentation/devicetree/bindings/dma/ti-dma-crossbar.txt
··· 1 + Texas Instruments DMA Crossbar (DMA request router) 2 + 3 + Required properties: 4 + - compatible: "ti,dra7-dma-crossbar" for DRA7xx DMA crossbar 5 + - reg: Memory map for accessing module 6 + - #dma-cells: Should be set to <1>. 7 + Clients should use the crossbar request number (input) 8 + - dma-requests: Number of DMA requests the crossbar can receive 9 + - dma-masters: phandle pointing to the DMA controller 10 + 11 + The DMA controller node need to have the following poroperties: 12 + - dma-requests: Number of DMA requests the controller can handle 13 + 14 + Optional properties: 15 + - ti,dma-safe-map: Safe routing value for unused request lines 16 + 17 + Example: 18 + 19 + /* DMA controller */ 20 + sdma: dma-controller@4a056000 { 21 + compatible = "ti,omap4430-sdma"; 22 + reg = <0x4a056000 0x1000>; 23 + interrupts = <GIC_SPI 7 IRQ_TYPE_LEVEL_HIGH>, 24 + <GIC_SPI 8 IRQ_TYPE_LEVEL_HIGH>, 25 + <GIC_SPI 9 IRQ_TYPE_LEVEL_HIGH>, 26 + <GIC_SPI 10 IRQ_TYPE_LEVEL_HIGH>; 27 + #dma-cells = <1>; 28 + dma-channels = <32>; 29 + dma-requests = <127>; 30 + }; 31 + 32 + /* DMA crossbar */ 33 + sdma_xbar: dma-router@4a002b78 { 34 + compatible = "ti,dra7-dma-crossbar"; 35 + reg = <0x4a002b78 0xfc>; 36 + #dma-cells = <1>; 37 + dma-requests = <205>; 38 + ti,dma-safe-map = <0>; 39 + dma-masters = <&sdma>; 40 + }; 41 + 42 + /* DMA client */ 43 + uart1: serial@4806a000 { 44 + compatible = "ti,omap4-uart"; 45 + reg = <0x4806a000 0x100>; 46 + interrupts-extended = <&gic GIC_SPI 67 IRQ_TYPE_LEVEL_HIGH>; 47 + ti,hwmods = "uart1"; 48 + clock-frequency = <48000000>; 49 + status = "disabled"; 50 + dmas = <&sdma_xbar 49>, <&sdma_xbar 50>; 51 + dma-names = "tx", "rx"; 52 + };
+6 -5
Documentation/dmaengine/provider.txt
··· 345 345 that abstracts it away. 346 346 347 347 * DMA_CTRL_ACK 348 - - Undocumented feature 349 - - No one really has an idea of what it's about, besides being 350 - related to reusing the DMA transaction descriptors or having 351 - additional transactions added to it in the async-tx API 352 - - Useless in the case of the slave API 348 + - If set, the transfer can be reused after being completed. 349 + - There is a guarantee the transfer won't be freed until it is acked 350 + by async_tx_ack(). 351 + - As a consequence, if a device driver wants to skip the dma_map_sg() and 352 + dma_unmap_sg() in between 2 transfers, because the DMA'd data wasn't used, 353 + it can resubmit the transfer right after its completion. 353 354 354 355 General Design Notes 355 356 --------------------
+153
Documentation/dmaengine/pxa_dma.txt
··· 1 + PXA/MMP - DMA Slave controller 2 + ============================== 3 + 4 + Constraints 5 + ----------- 6 + a) Transfers hot queuing 7 + A driver submitting a transfer and issuing it should be granted the transfer 8 + is queued even on a running DMA channel. 9 + This implies that the queuing doesn't wait for the previous transfer end, 10 + and that the descriptor chaining is not only done in the irq/tasklet code 11 + triggered by the end of the transfer. 12 + A transfer which is submitted and issued on a phy doesn't wait for a phy to 13 + stop and restart, but is submitted on a "running channel". The other 14 + drivers, especially mmp_pdma waited for the phy to stop before relaunching 15 + a new transfer. 16 + 17 + b) All transfers having asked for confirmation should be signaled 18 + Any issued transfer with DMA_PREP_INTERRUPT should trigger a callback call. 19 + This implies that even if an irq/tasklet is triggered by end of tx1, but 20 + at the time of irq/dma tx2 is already finished, tx1->complete() and 21 + tx2->complete() should be called. 22 + 23 + c) Channel running state 24 + A driver should be able to query if a channel is running or not. For the 25 + multimedia case, such as video capture, if a transfer is submitted and then 26 + a check of the DMA channel reports a "stopped channel", the transfer should 27 + not be issued until the next "start of frame interrupt", hence the need to 28 + know if a channel is in running or stopped state. 29 + 30 + d) Bandwidth guarantee 31 + The PXA architecture has 4 levels of DMAs priorities : high, normal, low. 32 + The high prorities get twice as much bandwidth as the normal, which get twice 33 + as much as the low priorities. 34 + A driver should be able to request a priority, especially the real-time 35 + ones such as pxa_camera with (big) throughputs. 36 + 37 + Design 38 + ------ 39 + a) Virtual channels 40 + Same concept as in sa11x0 driver, ie. a driver was assigned a "virtual 41 + channel" linked to the requestor line, and the physical DMA channel is 42 + assigned on the fly when the transfer is issued. 43 + 44 + b) Transfer anatomy for a scatter-gather transfer 45 + +------------+-----+---------------+----------------+-----------------+ 46 + | desc-sg[0] | ... | desc-sg[last] | status updater | finisher/linker | 47 + +------------+-----+---------------+----------------+-----------------+ 48 + 49 + This structure is pointed by dma->sg_cpu. 50 + The descriptors are used as follows : 51 + - desc-sg[i]: i-th descriptor, transferring the i-th sg 52 + element to the video buffer scatter gather 53 + - status updater 54 + Transfers a single u32 to a well known dma coherent memory to leave 55 + a trace that this transfer is done. The "well known" is unique per 56 + physical channel, meaning that a read of this value will tell which 57 + is the last finished transfer at that point in time. 58 + - finisher: has ddadr=DADDR_STOP, dcmd=ENDIRQEN 59 + - linker: has ddadr= desc-sg[0] of next transfer, dcmd=0 60 + 61 + c) Transfers hot-chaining 62 + Suppose the running chain is : 63 + Buffer 1 Buffer 2 64 + +---------+----+---+ +----+----+----+---+ 65 + | d0 | .. | dN | l | | d0 | .. | dN | f | 66 + +---------+----+-|-+ ^----+----+----+---+ 67 + | | 68 + +----+ 69 + 70 + After a call to dmaengine_submit(b3), the chain will look like : 71 + Buffer 1 Buffer 2 Buffer 3 72 + +---------+----+---+ +----+----+----+---+ +----+----+----+---+ 73 + | d0 | .. | dN | l | | d0 | .. | dN | l | | d0 | .. | dN | f | 74 + +---------+----+-|-+ ^----+----+----+-|-+ ^----+----+----+---+ 75 + | | | | 76 + +----+ +----+ 77 + new_link 78 + 79 + If while new_link was created the DMA channel stopped, it is _not_ 80 + restarted. Hot-chaining doesn't break the assumption that 81 + dma_async_issue_pending() is to be used to ensure the transfer is actually started. 82 + 83 + One exception to this rule : 84 + - if Buffer1 and Buffer2 had all their addresses 8 bytes aligned 85 + - and if Buffer3 has at least one address not 4 bytes aligned 86 + - then hot-chaining cannot happen, as the channel must be stopped, the 87 + "align bit" must be set, and the channel restarted As a consequence, 88 + such a transfer tx_submit() will be queued on the submitted queue, and 89 + this specific case if the DMA is already running in aligned mode. 90 + 91 + d) Transfers completion updater 92 + Each time a transfer is completed on a channel, an interrupt might be 93 + generated or not, up to the client's request. But in each case, the last 94 + descriptor of a transfer, the "status updater", will write the latest 95 + transfer being completed into the physical channel's completion mark. 96 + 97 + This will speed up residue calculation, for large transfers such as video 98 + buffers which hold around 6k descriptors or more. This also allows without 99 + any lock to find out what is the latest completed transfer in a running 100 + DMA chain. 101 + 102 + e) Transfers completion, irq and tasklet 103 + When a transfer flagged as "DMA_PREP_INTERRUPT" is finished, the dma irq 104 + is raised. Upon this interrupt, a tasklet is scheduled for the physical 105 + channel. 106 + The tasklet is responsible for : 107 + - reading the physical channel last updater mark 108 + - calling all the transfer callbacks of finished transfers, based on 109 + that mark, and each transfer flags. 110 + If a transfer is completed while this handling is done, a dma irq will 111 + be raised, and the tasklet will be scheduled once again, having a new 112 + updater mark. 113 + 114 + f) Residue 115 + Residue granularity will be descriptor based. The issued but not completed 116 + transfers will be scanned for all of their descriptors against the 117 + currently running descriptor. 118 + 119 + g) Most complicated case of driver's tx queues 120 + The most tricky situation is when : 121 + - there are not "acked" transfers (tx0) 122 + - a driver submitted an aligned tx1, not chained 123 + - a driver submitted an aligned tx2 => tx2 is cold chained to tx1 124 + - a driver issued tx1+tx2 => channel is running in aligned mode 125 + - a driver submitted an aligned tx3 => tx3 is hot-chained 126 + - a driver submitted an unaligned tx4 => tx4 is put in submitted queue, 127 + not chained 128 + - a driver issued tx4 => tx4 is put in issued queue, not chained 129 + - a driver submitted an aligned tx5 => tx5 is put in submitted queue, not 130 + chained 131 + - a driver submitted an aligned tx6 => tx6 is put in submitted queue, 132 + cold chained to tx5 133 + 134 + This translates into (after tx4 is issued) : 135 + - issued queue 136 + +-----+ +-----+ +-----+ +-----+ 137 + | tx1 | | tx2 | | tx3 | | tx4 | 138 + +---|-+ ^---|-+ ^-----+ +-----+ 139 + | | | | 140 + +---+ +---+ 141 + - submitted queue 142 + +-----+ +-----+ 143 + | tx5 | | tx6 | 144 + +---|-+ ^-----+ 145 + | | 146 + +---+ 147 + - completed queue : empty 148 + - allocated queue : tx0 149 + 150 + It should be noted that after tx3 is completed, the channel is stopped, and 151 + restarted in "unaligned mode" to handle tx4. 152 + 153 + Author: Robert Jarzmik <robert.jarzmik@free.fr>
+1
MAINTAINERS
··· 8174 8174 T: git git://github.com/rjarzmik/linux.git 8175 8175 S: Maintained 8176 8176 F: arch/arm/mach-pxa/ 8177 + F: drivers/dma/pxa* 8177 8178 F: drivers/pcmcia/pxa2xx* 8178 8179 F: drivers/spi/spi-pxa2xx* 8179 8180 F: drivers/usb/gadget/udc/pxa2*
+15
drivers/dma/Kconfig
··· 162 162 To avoid bloating the irq_desc[] array we allocate a sufficient 163 163 number of IRQ slots and map them dynamically to specific sources. 164 164 165 + config PXA_DMA 166 + bool "PXA DMA support" 167 + depends on (ARCH_MMP || ARCH_PXA) 168 + select DMA_ENGINE 169 + select DMA_VIRTUAL_CHANNELS 170 + help 171 + Support the DMA engine for PXA. It is also compatible with MMP PDMA 172 + platform. The internal DMA IP of all PXA variants is supported, with 173 + 16 to 32 channels for peripheral to memory or memory to memory 174 + transfers. 175 + 165 176 config TXX9_DMAC 166 177 tristate "Toshiba TXx9 SoC DMA support" 167 178 depends on MACH_TX49XX || MACH_TX39XX ··· 255 244 help 256 245 Enable support for the TI EDMA controller. This DMA 257 246 engine is found on TI DaVinci and AM33xx parts. 247 + 248 + config TI_DMA_CROSSBAR 249 + bool 258 250 259 251 config ARCH_HAS_ASYNC_TX_FIND_CHANNEL 260 252 bool ··· 344 330 depends on ARCH_OMAP 345 331 select DMA_ENGINE 346 332 select DMA_VIRTUAL_CHANNELS 333 + select TI_DMA_CROSSBAR if SOC_DRA7XX 347 334 348 335 config DMA_BCM2835 349 336 tristate "BCM2835 DMA engine support"
+2
drivers/dma/Makefile
··· 25 25 obj-$(CONFIG_IMX_SDMA) += imx-sdma.o 26 26 obj-$(CONFIG_IMX_DMA) += imx-dma.o 27 27 obj-$(CONFIG_MXS_DMA) += mxs-dma.o 28 + obj-$(CONFIG_PXA_DMA) += pxa_dma.o 28 29 obj-$(CONFIG_TIMB_DMA) += timb_dma.o 29 30 obj-$(CONFIG_SIRF_DMA) += sirf-dma.o 30 31 obj-$(CONFIG_TI_EDMA) += edma.o ··· 39 38 obj-$(CONFIG_DMA_SA11X0) += sa11x0-dma.o 40 39 obj-$(CONFIG_MMP_TDMA) += mmp_tdma.o 41 40 obj-$(CONFIG_DMA_OMAP) += omap-dma.o 41 + obj-$(CONFIG_TI_DMA_CROSSBAR) += ti-dma-crossbar.o 42 42 obj-$(CONFIG_DMA_BCM2835) += bcm2835-dma.o 43 43 obj-$(CONFIG_MMP_PDMA) += mmp_pdma.o 44 44 obj-$(CONFIG_DMA_JZ4740) += dma-jz4740.o
+1 -1
drivers/dma/amba-pl08x.c
··· 474 474 u32 val = readl(ch->reg_config); 475 475 476 476 val &= ~(PL080_CONFIG_ENABLE | PL080_CONFIG_ERR_IRQ_MASK | 477 - PL080_CONFIG_TC_IRQ_MASK); 477 + PL080_CONFIG_TC_IRQ_MASK); 478 478 479 479 writel(val, ch->reg_config); 480 480
+106
drivers/dma/at_hdmac.c
··· 247 247 channel_writel(atchan, CTRLA, 0); 248 248 channel_writel(atchan, CTRLB, 0); 249 249 channel_writel(atchan, DSCR, first->txd.phys); 250 + channel_writel(atchan, SPIP, ATC_SPIP_HOLE(first->src_hole) | 251 + ATC_SPIP_BOUNDARY(first->boundary)); 252 + channel_writel(atchan, DPIP, ATC_DPIP_HOLE(first->dst_hole) | 253 + ATC_DPIP_BOUNDARY(first->boundary)); 250 254 dma_writel(atdma, CHER, atchan->mask); 251 255 252 256 vdbg_dump_regs(atchan); ··· 636 632 spin_unlock_irqrestore(&atchan->lock, flags); 637 633 638 634 return cookie; 635 + } 636 + 637 + /** 638 + * atc_prep_dma_interleaved - prepare memory to memory interleaved operation 639 + * @chan: the channel to prepare operation on 640 + * @xt: Interleaved transfer template 641 + * @flags: tx descriptor status flags 642 + */ 643 + static struct dma_async_tx_descriptor * 644 + atc_prep_dma_interleaved(struct dma_chan *chan, 645 + struct dma_interleaved_template *xt, 646 + unsigned long flags) 647 + { 648 + struct at_dma_chan *atchan = to_at_dma_chan(chan); 649 + struct data_chunk *first = xt->sgl; 650 + struct at_desc *desc = NULL; 651 + size_t xfer_count; 652 + unsigned int dwidth; 653 + u32 ctrla; 654 + u32 ctrlb; 655 + size_t len = 0; 656 + int i; 657 + 658 + dev_info(chan2dev(chan), 659 + "%s: src=0x%08x, dest=0x%08x, numf=%d, frame_size=%d, flags=0x%lx\n", 660 + __func__, xt->src_start, xt->dst_start, xt->numf, 661 + xt->frame_size, flags); 662 + 663 + if (unlikely(!xt || xt->numf != 1 || !xt->frame_size)) 664 + return NULL; 665 + 666 + /* 667 + * The controller can only "skip" X bytes every Y bytes, so we 668 + * need to make sure we are given a template that fit that 669 + * description, ie a template with chunks that always have the 670 + * same size, with the same ICGs. 671 + */ 672 + for (i = 0; i < xt->frame_size; i++) { 673 + struct data_chunk *chunk = xt->sgl + i; 674 + 675 + if ((chunk->size != xt->sgl->size) || 676 + (dmaengine_get_dst_icg(xt, chunk) != dmaengine_get_dst_icg(xt, first)) || 677 + (dmaengine_get_src_icg(xt, chunk) != dmaengine_get_src_icg(xt, first))) { 678 + dev_err(chan2dev(chan), 679 + "%s: the controller can transfer only identical chunks\n", 680 + __func__); 681 + return NULL; 682 + } 683 + 684 + len += chunk->size; 685 + } 686 + 687 + dwidth = atc_get_xfer_width(xt->src_start, 688 + xt->dst_start, len); 689 + 690 + xfer_count = len >> dwidth; 691 + if (xfer_count > ATC_BTSIZE_MAX) { 692 + dev_err(chan2dev(chan), "%s: buffer is too big\n", __func__); 693 + return NULL; 694 + } 695 + 696 + ctrla = ATC_SRC_WIDTH(dwidth) | 697 + ATC_DST_WIDTH(dwidth); 698 + 699 + ctrlb = ATC_DEFAULT_CTRLB | ATC_IEN 700 + | ATC_SRC_ADDR_MODE_INCR 701 + | ATC_DST_ADDR_MODE_INCR 702 + | ATC_SRC_PIP 703 + | ATC_DST_PIP 704 + | ATC_FC_MEM2MEM; 705 + 706 + /* create the transfer */ 707 + desc = atc_desc_get(atchan); 708 + if (!desc) { 709 + dev_err(chan2dev(chan), 710 + "%s: couldn't allocate our descriptor\n", __func__); 711 + return NULL; 712 + } 713 + 714 + desc->lli.saddr = xt->src_start; 715 + desc->lli.daddr = xt->dst_start; 716 + desc->lli.ctrla = ctrla | xfer_count; 717 + desc->lli.ctrlb = ctrlb; 718 + 719 + desc->boundary = first->size >> dwidth; 720 + desc->dst_hole = (dmaengine_get_dst_icg(xt, first) >> dwidth) + 1; 721 + desc->src_hole = (dmaengine_get_src_icg(xt, first) >> dwidth) + 1; 722 + 723 + desc->txd.cookie = -EBUSY; 724 + desc->total_len = desc->len = len; 725 + desc->tx_width = dwidth; 726 + 727 + /* set end-of-link to the last link descriptor of list*/ 728 + set_desc_eol(desc); 729 + 730 + desc->txd.flags = flags; /* client is in control of this ack */ 731 + 732 + return &desc->txd; 639 733 } 640 734 641 735 /** ··· 1711 1609 /* setup platform data for each SoC */ 1712 1610 dma_cap_set(DMA_MEMCPY, at91sam9rl_config.cap_mask); 1713 1611 dma_cap_set(DMA_SG, at91sam9rl_config.cap_mask); 1612 + dma_cap_set(DMA_INTERLEAVE, at91sam9g45_config.cap_mask); 1714 1613 dma_cap_set(DMA_MEMCPY, at91sam9g45_config.cap_mask); 1715 1614 dma_cap_set(DMA_SLAVE, at91sam9g45_config.cap_mask); 1716 1615 dma_cap_set(DMA_SG, at91sam9g45_config.cap_mask); ··· 1816 1713 atdma->dma_common.dev = &pdev->dev; 1817 1714 1818 1715 /* set prep routines based on capability */ 1716 + if (dma_has_cap(DMA_INTERLEAVE, atdma->dma_common.cap_mask)) 1717 + atdma->dma_common.device_prep_interleaved_dma = atc_prep_dma_interleaved; 1718 + 1819 1719 if (dma_has_cap(DMA_MEMCPY, atdma->dma_common.cap_mask)) 1820 1720 atdma->dma_common.device_prep_dma_memcpy = atc_prep_dma_memcpy; 1821 1721
+5
drivers/dma/at_hdmac_regs.h
··· 196 196 size_t len; 197 197 u32 tx_width; 198 198 size_t total_len; 199 + 200 + /* Interleaved data */ 201 + size_t boundary; 202 + size_t dst_hole; 203 + size_t src_hole; 199 204 }; 200 205 201 206 static inline struct at_desc *
+342 -52
drivers/dma/at_xdmac.c
··· 235 235 dma_addr_t mbr_sa; /* Source Address Member */ 236 236 dma_addr_t mbr_da; /* Destination Address Member */ 237 237 u32 mbr_cfg; /* Configuration Register */ 238 + u32 mbr_bc; /* Block Control Register */ 239 + u32 mbr_ds; /* Data Stride Register */ 240 + u32 mbr_sus; /* Source Microblock Stride Register */ 241 + u32 mbr_dus; /* Destination Microblock Stride Register */ 238 242 }; 239 243 240 244 ··· 362 358 if (at_xdmac_chan_is_cyclic(atchan)) { 363 359 reg = AT_XDMAC_CNDC_NDVIEW_NDV1; 364 360 at_xdmac_chan_write(atchan, AT_XDMAC_CC, first->lld.mbr_cfg); 361 + } else if (first->lld.mbr_ubc & AT_XDMAC_MBR_UBC_NDV3) { 362 + reg = AT_XDMAC_CNDC_NDVIEW_NDV3; 365 363 } else { 366 364 /* 367 365 * No need to write AT_XDMAC_CC reg, it will be done when the ··· 469 463 } 470 464 471 465 return desc; 466 + } 467 + 468 + static void at_xdmac_queue_desc(struct dma_chan *chan, 469 + struct at_xdmac_desc *prev, 470 + struct at_xdmac_desc *desc) 471 + { 472 + if (!prev || !desc) 473 + return; 474 + 475 + prev->lld.mbr_nda = desc->tx_dma_desc.phys; 476 + prev->lld.mbr_ubc |= AT_XDMAC_MBR_UBC_NDE; 477 + 478 + dev_dbg(chan2dev(chan), "%s: chain lld: prev=0x%p, mbr_nda=%pad\n", 479 + __func__, prev, &prev->lld.mbr_nda); 480 + } 481 + 482 + static inline void at_xdmac_increment_block_count(struct dma_chan *chan, 483 + struct at_xdmac_desc *desc) 484 + { 485 + if (!desc) 486 + return; 487 + 488 + desc->lld.mbr_bc++; 489 + 490 + dev_dbg(chan2dev(chan), 491 + "%s: incrementing the block count of the desc 0x%p\n", 492 + __func__, desc); 472 493 } 473 494 474 495 static struct dma_chan *at_xdmac_xlate(struct of_phandle_args *dma_spec, ··· 689 656 desc->lld.mbr_ubc = AT_XDMAC_MBR_UBC_NDV2 /* next descriptor view */ 690 657 | AT_XDMAC_MBR_UBC_NDEN /* next descriptor dst parameter update */ 691 658 | AT_XDMAC_MBR_UBC_NSEN /* next descriptor src parameter update */ 692 - | (i == sg_len - 1 ? 0 : AT_XDMAC_MBR_UBC_NDE) /* descriptor fetch */ 693 659 | (len >> fixed_dwidth); /* microblock length */ 694 660 dev_dbg(chan2dev(chan), 695 661 "%s: lld: mbr_sa=%pad, mbr_da=%pad, mbr_ubc=0x%08x\n", 696 662 __func__, &desc->lld.mbr_sa, &desc->lld.mbr_da, desc->lld.mbr_ubc); 697 663 698 664 /* Chain lld. */ 699 - if (prev) { 700 - prev->lld.mbr_nda = desc->tx_dma_desc.phys; 701 - dev_dbg(chan2dev(chan), 702 - "%s: chain lld: prev=0x%p, mbr_nda=%pad\n", 703 - __func__, prev, &prev->lld.mbr_nda); 704 - } 665 + if (prev) 666 + at_xdmac_queue_desc(chan, prev, desc); 705 667 706 668 prev = desc; 707 669 if (!first) ··· 776 748 desc->lld.mbr_ubc = AT_XDMAC_MBR_UBC_NDV1 777 749 | AT_XDMAC_MBR_UBC_NDEN 778 750 | AT_XDMAC_MBR_UBC_NSEN 779 - | AT_XDMAC_MBR_UBC_NDE 780 751 | period_len >> at_xdmac_get_dwidth(desc->lld.mbr_cfg); 781 752 782 753 dev_dbg(chan2dev(chan), ··· 783 756 __func__, &desc->lld.mbr_sa, &desc->lld.mbr_da, desc->lld.mbr_ubc); 784 757 785 758 /* Chain lld. */ 786 - if (prev) { 787 - prev->lld.mbr_nda = desc->tx_dma_desc.phys; 788 - dev_dbg(chan2dev(chan), 789 - "%s: chain lld: prev=0x%p, mbr_nda=%pad\n", 790 - __func__, prev, &prev->lld.mbr_nda); 791 - } 759 + if (prev) 760 + at_xdmac_queue_desc(chan, prev, desc); 792 761 793 762 prev = desc; 794 763 if (!first) ··· 802 779 first->tx_dma_desc.flags = flags; 803 780 first->xfer_size = buf_len; 804 781 first->direction = direction; 782 + 783 + return &first->tx_dma_desc; 784 + } 785 + 786 + static inline u32 at_xdmac_align_width(struct dma_chan *chan, dma_addr_t addr) 787 + { 788 + u32 width; 789 + 790 + /* 791 + * Check address alignment to select the greater data width we 792 + * can use. 793 + * 794 + * Some XDMAC implementations don't provide dword transfer, in 795 + * this case selecting dword has the same behavior as 796 + * selecting word transfers. 797 + */ 798 + if (!(addr & 7)) { 799 + width = AT_XDMAC_CC_DWIDTH_DWORD; 800 + dev_dbg(chan2dev(chan), "%s: dwidth: double word\n", __func__); 801 + } else if (!(addr & 3)) { 802 + width = AT_XDMAC_CC_DWIDTH_WORD; 803 + dev_dbg(chan2dev(chan), "%s: dwidth: word\n", __func__); 804 + } else if (!(addr & 1)) { 805 + width = AT_XDMAC_CC_DWIDTH_HALFWORD; 806 + dev_dbg(chan2dev(chan), "%s: dwidth: half word\n", __func__); 807 + } else { 808 + width = AT_XDMAC_CC_DWIDTH_BYTE; 809 + dev_dbg(chan2dev(chan), "%s: dwidth: byte\n", __func__); 810 + } 811 + 812 + return width; 813 + } 814 + 815 + static struct at_xdmac_desc * 816 + at_xdmac_interleaved_queue_desc(struct dma_chan *chan, 817 + struct at_xdmac_chan *atchan, 818 + struct at_xdmac_desc *prev, 819 + dma_addr_t src, dma_addr_t dst, 820 + struct dma_interleaved_template *xt, 821 + struct data_chunk *chunk) 822 + { 823 + struct at_xdmac_desc *desc; 824 + u32 dwidth; 825 + unsigned long flags; 826 + size_t ublen; 827 + /* 828 + * WARNING: The channel configuration is set here since there is no 829 + * dmaengine_slave_config call in this case. Moreover we don't know the 830 + * direction, it involves we can't dynamically set the source and dest 831 + * interface so we have to use the same one. Only interface 0 allows EBI 832 + * access. Hopefully we can access DDR through both ports (at least on 833 + * SAMA5D4x), so we can use the same interface for source and dest, 834 + * that solves the fact we don't know the direction. 835 + */ 836 + u32 chan_cc = AT_XDMAC_CC_DIF(0) 837 + | AT_XDMAC_CC_SIF(0) 838 + | AT_XDMAC_CC_MBSIZE_SIXTEEN 839 + | AT_XDMAC_CC_TYPE_MEM_TRAN; 840 + 841 + dwidth = at_xdmac_align_width(chan, src | dst | chunk->size); 842 + if (chunk->size >= (AT_XDMAC_MBR_UBC_UBLEN_MAX << dwidth)) { 843 + dev_dbg(chan2dev(chan), 844 + "%s: chunk too big (%d, max size %lu)...\n", 845 + __func__, chunk->size, 846 + AT_XDMAC_MBR_UBC_UBLEN_MAX << dwidth); 847 + return NULL; 848 + } 849 + 850 + if (prev) 851 + dev_dbg(chan2dev(chan), 852 + "Adding items at the end of desc 0x%p\n", prev); 853 + 854 + if (xt->src_inc) { 855 + if (xt->src_sgl) 856 + chan_cc |= AT_XDMAC_CC_SAM_UBS_DS_AM; 857 + else 858 + chan_cc |= AT_XDMAC_CC_SAM_INCREMENTED_AM; 859 + } 860 + 861 + if (xt->dst_inc) { 862 + if (xt->dst_sgl) 863 + chan_cc |= AT_XDMAC_CC_DAM_UBS_DS_AM; 864 + else 865 + chan_cc |= AT_XDMAC_CC_DAM_INCREMENTED_AM; 866 + } 867 + 868 + spin_lock_irqsave(&atchan->lock, flags); 869 + desc = at_xdmac_get_desc(atchan); 870 + spin_unlock_irqrestore(&atchan->lock, flags); 871 + if (!desc) { 872 + dev_err(chan2dev(chan), "can't get descriptor\n"); 873 + return NULL; 874 + } 875 + 876 + chan_cc |= AT_XDMAC_CC_DWIDTH(dwidth); 877 + 878 + ublen = chunk->size >> dwidth; 879 + 880 + desc->lld.mbr_sa = src; 881 + desc->lld.mbr_da = dst; 882 + desc->lld.mbr_sus = dmaengine_get_src_icg(xt, chunk); 883 + desc->lld.mbr_dus = dmaengine_get_dst_icg(xt, chunk); 884 + 885 + desc->lld.mbr_ubc = AT_XDMAC_MBR_UBC_NDV3 886 + | AT_XDMAC_MBR_UBC_NDEN 887 + | AT_XDMAC_MBR_UBC_NSEN 888 + | ublen; 889 + desc->lld.mbr_cfg = chan_cc; 890 + 891 + dev_dbg(chan2dev(chan), 892 + "%s: lld: mbr_sa=0x%08x, mbr_da=0x%08x, mbr_ubc=0x%08x, mbr_cfg=0x%08x\n", 893 + __func__, desc->lld.mbr_sa, desc->lld.mbr_da, 894 + desc->lld.mbr_ubc, desc->lld.mbr_cfg); 895 + 896 + /* Chain lld. */ 897 + if (prev) 898 + at_xdmac_queue_desc(chan, prev, desc); 899 + 900 + return desc; 901 + } 902 + 903 + static struct dma_async_tx_descriptor * 904 + at_xdmac_prep_interleaved(struct dma_chan *chan, 905 + struct dma_interleaved_template *xt, 906 + unsigned long flags) 907 + { 908 + struct at_xdmac_chan *atchan = to_at_xdmac_chan(chan); 909 + struct at_xdmac_desc *prev = NULL, *first = NULL; 910 + struct data_chunk *chunk, *prev_chunk = NULL; 911 + dma_addr_t dst_addr, src_addr; 912 + size_t dst_skip, src_skip, len = 0; 913 + size_t prev_dst_icg = 0, prev_src_icg = 0; 914 + int i; 915 + 916 + if (!xt || (xt->numf != 1) || (xt->dir != DMA_MEM_TO_MEM)) 917 + return NULL; 918 + 919 + dev_dbg(chan2dev(chan), "%s: src=0x%08x, dest=0x%08x, numf=%d, frame_size=%d, flags=0x%lx\n", 920 + __func__, xt->src_start, xt->dst_start, xt->numf, 921 + xt->frame_size, flags); 922 + 923 + src_addr = xt->src_start; 924 + dst_addr = xt->dst_start; 925 + 926 + for (i = 0; i < xt->frame_size; i++) { 927 + struct at_xdmac_desc *desc; 928 + size_t src_icg, dst_icg; 929 + 930 + chunk = xt->sgl + i; 931 + 932 + dst_icg = dmaengine_get_dst_icg(xt, chunk); 933 + src_icg = dmaengine_get_src_icg(xt, chunk); 934 + 935 + src_skip = chunk->size + src_icg; 936 + dst_skip = chunk->size + dst_icg; 937 + 938 + dev_dbg(chan2dev(chan), 939 + "%s: chunk size=%d, src icg=%d, dst icg=%d\n", 940 + __func__, chunk->size, src_icg, dst_icg); 941 + 942 + /* 943 + * Handle the case where we just have the same 944 + * transfer to setup, we can just increase the 945 + * block number and reuse the same descriptor. 946 + */ 947 + if (prev_chunk && prev && 948 + (prev_chunk->size == chunk->size) && 949 + (prev_src_icg == src_icg) && 950 + (prev_dst_icg == dst_icg)) { 951 + dev_dbg(chan2dev(chan), 952 + "%s: same configuration that the previous chunk, merging the descriptors...\n", 953 + __func__); 954 + at_xdmac_increment_block_count(chan, prev); 955 + continue; 956 + } 957 + 958 + desc = at_xdmac_interleaved_queue_desc(chan, atchan, 959 + prev, 960 + src_addr, dst_addr, 961 + xt, chunk); 962 + if (!desc) { 963 + list_splice_init(&first->descs_list, 964 + &atchan->free_descs_list); 965 + return NULL; 966 + } 967 + 968 + if (!first) 969 + first = desc; 970 + 971 + dev_dbg(chan2dev(chan), "%s: add desc 0x%p to descs_list 0x%p\n", 972 + __func__, desc, first); 973 + list_add_tail(&desc->desc_node, &first->descs_list); 974 + 975 + if (xt->src_sgl) 976 + src_addr += src_skip; 977 + 978 + if (xt->dst_sgl) 979 + dst_addr += dst_skip; 980 + 981 + len += chunk->size; 982 + prev_chunk = chunk; 983 + prev_dst_icg = dst_icg; 984 + prev_src_icg = src_icg; 985 + prev = desc; 986 + } 987 + 988 + first->tx_dma_desc.cookie = -EBUSY; 989 + first->tx_dma_desc.flags = flags; 990 + first->xfer_size = len; 805 991 806 992 return &first->tx_dma_desc; 807 993 } ··· 1046 814 if (unlikely(!len)) 1047 815 return NULL; 1048 816 1049 - /* 1050 - * Check address alignment to select the greater data width we can use. 1051 - * Some XDMAC implementations don't provide dword transfer, in this 1052 - * case selecting dword has the same behavior as selecting word transfers. 1053 - */ 1054 - if (!((src_addr | dst_addr) & 7)) { 1055 - dwidth = AT_XDMAC_CC_DWIDTH_DWORD; 1056 - dev_dbg(chan2dev(chan), "%s: dwidth: double word\n", __func__); 1057 - } else if (!((src_addr | dst_addr) & 3)) { 1058 - dwidth = AT_XDMAC_CC_DWIDTH_WORD; 1059 - dev_dbg(chan2dev(chan), "%s: dwidth: word\n", __func__); 1060 - } else if (!((src_addr | dst_addr) & 1)) { 1061 - dwidth = AT_XDMAC_CC_DWIDTH_HALFWORD; 1062 - dev_dbg(chan2dev(chan), "%s: dwidth: half word\n", __func__); 1063 - } else { 1064 - dwidth = AT_XDMAC_CC_DWIDTH_BYTE; 1065 - dev_dbg(chan2dev(chan), "%s: dwidth: byte\n", __func__); 1066 - } 817 + dwidth = at_xdmac_align_width(chan, src_addr | dst_addr); 1067 818 1068 819 /* Prepare descriptors. */ 1069 820 while (remaining_size) { ··· 1076 861 dev_dbg(chan2dev(chan), "%s: xfer_size=%zu\n", __func__, xfer_size); 1077 862 1078 863 /* Check remaining length and change data width if needed. */ 1079 - if (!((src_addr | dst_addr | xfer_size) & 7)) { 1080 - dwidth = AT_XDMAC_CC_DWIDTH_DWORD; 1081 - dev_dbg(chan2dev(chan), "%s: dwidth: double word\n", __func__); 1082 - } else if (!((src_addr | dst_addr | xfer_size) & 3)) { 1083 - dwidth = AT_XDMAC_CC_DWIDTH_WORD; 1084 - dev_dbg(chan2dev(chan), "%s: dwidth: word\n", __func__); 1085 - } else if (!((src_addr | dst_addr | xfer_size) & 1)) { 1086 - dwidth = AT_XDMAC_CC_DWIDTH_HALFWORD; 1087 - dev_dbg(chan2dev(chan), "%s: dwidth: half word\n", __func__); 1088 - } else if ((src_addr | dst_addr | xfer_size) & 1) { 1089 - dwidth = AT_XDMAC_CC_DWIDTH_BYTE; 1090 - dev_dbg(chan2dev(chan), "%s: dwidth: byte\n", __func__); 1091 - } 864 + dwidth = at_xdmac_align_width(chan, 865 + src_addr | dst_addr | xfer_size); 1092 866 chan_cc |= AT_XDMAC_CC_DWIDTH(dwidth); 1093 867 1094 868 ublen = xfer_size >> dwidth; ··· 1088 884 desc->lld.mbr_ubc = AT_XDMAC_MBR_UBC_NDV2 1089 885 | AT_XDMAC_MBR_UBC_NDEN 1090 886 | AT_XDMAC_MBR_UBC_NSEN 1091 - | (remaining_size ? AT_XDMAC_MBR_UBC_NDE : 0) 1092 887 | ublen; 1093 888 desc->lld.mbr_cfg = chan_cc; 1094 889 ··· 1096 893 __func__, &desc->lld.mbr_sa, &desc->lld.mbr_da, desc->lld.mbr_ubc, desc->lld.mbr_cfg); 1097 894 1098 895 /* Chain lld. */ 1099 - if (prev) { 1100 - prev->lld.mbr_nda = desc->tx_dma_desc.phys; 1101 - dev_dbg(chan2dev(chan), 1102 - "%s: chain lld: prev=0x%p, mbr_nda=0x%08x\n", 1103 - __func__, prev, prev->lld.mbr_nda); 1104 - } 896 + if (prev) 897 + at_xdmac_queue_desc(chan, prev, desc); 1105 898 1106 899 prev = desc; 1107 900 if (!first) ··· 1112 913 first->xfer_size = len; 1113 914 1114 915 return &first->tx_dma_desc; 916 + } 917 + 918 + static struct at_xdmac_desc *at_xdmac_memset_create_desc(struct dma_chan *chan, 919 + struct at_xdmac_chan *atchan, 920 + dma_addr_t dst_addr, 921 + size_t len, 922 + int value) 923 + { 924 + struct at_xdmac_desc *desc; 925 + unsigned long flags; 926 + size_t ublen; 927 + u32 dwidth; 928 + /* 929 + * WARNING: The channel configuration is set here since there is no 930 + * dmaengine_slave_config call in this case. Moreover we don't know the 931 + * direction, it involves we can't dynamically set the source and dest 932 + * interface so we have to use the same one. Only interface 0 allows EBI 933 + * access. Hopefully we can access DDR through both ports (at least on 934 + * SAMA5D4x), so we can use the same interface for source and dest, 935 + * that solves the fact we don't know the direction. 936 + */ 937 + u32 chan_cc = AT_XDMAC_CC_DAM_INCREMENTED_AM 938 + | AT_XDMAC_CC_SAM_INCREMENTED_AM 939 + | AT_XDMAC_CC_DIF(0) 940 + | AT_XDMAC_CC_SIF(0) 941 + | AT_XDMAC_CC_MBSIZE_SIXTEEN 942 + | AT_XDMAC_CC_MEMSET_HW_MODE 943 + | AT_XDMAC_CC_TYPE_MEM_TRAN; 944 + 945 + dwidth = at_xdmac_align_width(chan, dst_addr); 946 + 947 + if (len >= (AT_XDMAC_MBR_UBC_UBLEN_MAX << dwidth)) { 948 + dev_err(chan2dev(chan), 949 + "%s: Transfer too large, aborting...\n", 950 + __func__); 951 + return NULL; 952 + } 953 + 954 + spin_lock_irqsave(&atchan->lock, flags); 955 + desc = at_xdmac_get_desc(atchan); 956 + spin_unlock_irqrestore(&atchan->lock, flags); 957 + if (!desc) { 958 + dev_err(chan2dev(chan), "can't get descriptor\n"); 959 + return NULL; 960 + } 961 + 962 + chan_cc |= AT_XDMAC_CC_DWIDTH(dwidth); 963 + 964 + ublen = len >> dwidth; 965 + 966 + desc->lld.mbr_da = dst_addr; 967 + desc->lld.mbr_ds = value; 968 + desc->lld.mbr_ubc = AT_XDMAC_MBR_UBC_NDV3 969 + | AT_XDMAC_MBR_UBC_NDEN 970 + | AT_XDMAC_MBR_UBC_NSEN 971 + | ublen; 972 + desc->lld.mbr_cfg = chan_cc; 973 + 974 + dev_dbg(chan2dev(chan), 975 + "%s: lld: mbr_da=0x%08x, mbr_ds=0x%08x, mbr_ubc=0x%08x, mbr_cfg=0x%08x\n", 976 + __func__, desc->lld.mbr_da, desc->lld.mbr_ds, desc->lld.mbr_ubc, 977 + desc->lld.mbr_cfg); 978 + 979 + return desc; 980 + } 981 + 982 + struct dma_async_tx_descriptor * 983 + at_xdmac_prep_dma_memset(struct dma_chan *chan, dma_addr_t dest, int value, 984 + size_t len, unsigned long flags) 985 + { 986 + struct at_xdmac_chan *atchan = to_at_xdmac_chan(chan); 987 + struct at_xdmac_desc *desc; 988 + 989 + dev_dbg(chan2dev(chan), "%s: dest=0x%08x, len=%d, pattern=0x%x, flags=0x%lx\n", 990 + __func__, dest, len, value, flags); 991 + 992 + if (unlikely(!len)) 993 + return NULL; 994 + 995 + desc = at_xdmac_memset_create_desc(chan, atchan, dest, len, value); 996 + list_add_tail(&desc->desc_node, &desc->descs_list); 997 + 998 + desc->tx_dma_desc.cookie = -EBUSY; 999 + desc->tx_dma_desc.flags = flags; 1000 + desc->xfer_size = len; 1001 + 1002 + return &desc->tx_dma_desc; 1115 1003 } 1116 1004 1117 1005 static enum dma_status ··· 1731 1445 } 1732 1446 1733 1447 dma_cap_set(DMA_CYCLIC, atxdmac->dma.cap_mask); 1448 + dma_cap_set(DMA_INTERLEAVE, atxdmac->dma.cap_mask); 1734 1449 dma_cap_set(DMA_MEMCPY, atxdmac->dma.cap_mask); 1450 + dma_cap_set(DMA_MEMSET, atxdmac->dma.cap_mask); 1735 1451 dma_cap_set(DMA_SLAVE, atxdmac->dma.cap_mask); 1736 1452 /* 1737 1453 * Without DMA_PRIVATE the driver is not able to allocate more than ··· 1746 1458 atxdmac->dma.device_tx_status = at_xdmac_tx_status; 1747 1459 atxdmac->dma.device_issue_pending = at_xdmac_issue_pending; 1748 1460 atxdmac->dma.device_prep_dma_cyclic = at_xdmac_prep_dma_cyclic; 1461 + atxdmac->dma.device_prep_interleaved_dma = at_xdmac_prep_interleaved; 1749 1462 atxdmac->dma.device_prep_dma_memcpy = at_xdmac_prep_dma_memcpy; 1463 + atxdmac->dma.device_prep_dma_memset = at_xdmac_prep_dma_memset; 1750 1464 atxdmac->dma.device_prep_slave_sg = at_xdmac_prep_slave_sg; 1751 1465 atxdmac->dma.device_config = at_xdmac_device_config; 1752 1466 atxdmac->dma.device_pause = at_xdmac_device_pause;
+11 -2
drivers/dma/dmaengine.c
··· 267 267 /* This channel is not in use anymore, free it */ 268 268 if (!chan->client_count && chan->device->device_free_chan_resources) 269 269 chan->device->device_free_chan_resources(chan); 270 + 271 + /* If the channel is used via a DMA request router, free the mapping */ 272 + if (chan->router && chan->router->route_free) { 273 + chan->router->route_free(chan->router->dev, chan->route_data); 274 + chan->router = NULL; 275 + chan->route_data = NULL; 276 + } 270 277 } 271 278 272 279 enum dma_status dma_sync_wait(struct dma_chan *chan, dma_cookie_t cookie) ··· 543 536 } 544 537 545 538 /** 546 - * dma_request_slave_channel - try to get specific channel exclusively 539 + * dma_get_slave_channel - try to get specific channel exclusively 547 540 * @chan: target channel 548 541 */ 549 542 struct dma_chan *dma_get_slave_channel(struct dma_chan *chan) ··· 655 648 EXPORT_SYMBOL_GPL(__dma_request_channel); 656 649 657 650 /** 658 - * dma_request_slave_channel - try to allocate an exclusive slave channel 651 + * dma_request_slave_channel_reason - try to allocate an exclusive slave channel 659 652 * @dev: pointer to client device structure 660 653 * @name: slave channel name 661 654 * ··· 843 836 !device->device_prep_dma_pq); 844 837 BUG_ON(dma_has_cap(DMA_PQ_VAL, device->cap_mask) && 845 838 !device->device_prep_dma_pq_val); 839 + BUG_ON(dma_has_cap(DMA_MEMSET, device->cap_mask) && 840 + !device->device_prep_dma_memset); 846 841 BUG_ON(dma_has_cap(DMA_INTERRUPT, device->cap_mask) && 847 842 !device->device_prep_dma_interrupt); 848 843 BUG_ON(dma_has_cap(DMA_SG, device->cap_mask) &&
+1 -1
drivers/dma/ep93xx_dma.c
··· 1364 1364 return ret; 1365 1365 } 1366 1366 1367 - static struct platform_device_id ep93xx_dma_driver_ids[] = { 1367 + static const struct platform_device_id ep93xx_dma_driver_ids[] = { 1368 1368 { "ep93xx-dma-m2p", 0 }, 1369 1369 { "ep93xx-dma-m2m", 1 }, 1370 1370 { },
+5 -4
drivers/dma/fsl-edma.c
··· 881 881 882 882 } 883 883 884 - ret = fsl_edma_irq_init(pdev, fsl_edma); 885 - if (ret) 886 - return ret; 887 - 888 884 fsl_edma->big_endian = of_property_read_bool(np, "big-endian"); 889 885 890 886 INIT_LIST_HEAD(&fsl_edma->dma_dev.channels); ··· 895 899 edma_writew(fsl_edma, 0x0, fsl_edma->membase + EDMA_TCD_CSR(i)); 896 900 fsl_edma_chan_mux(fsl_chan, 0, false); 897 901 } 902 + 903 + edma_writel(fsl_edma, ~0, fsl_edma->membase + EDMA_INTR); 904 + ret = fsl_edma_irq_init(pdev, fsl_edma); 905 + if (ret) 906 + return ret; 898 907 899 908 dma_cap_set(DMA_PRIVATE, fsl_edma->dma_dev.cap_mask); 900 909 dma_cap_set(DMA_SLAVE, fsl_edma->dma_dev.cap_mask);
+1 -1
drivers/dma/imx-dma.c
··· 193 193 int request; 194 194 }; 195 195 196 - static struct platform_device_id imx_dma_devtype[] = { 196 + static const struct platform_device_id imx_dma_devtype[] = { 197 197 { 198 198 .name = "imx1-dma", 199 199 .driver_data = IMX1_DMA,
+1 -1
drivers/dma/imx-sdma.c
··· 420 420 .script_addrs = &sdma_script_imx6q, 421 421 }; 422 422 423 - static struct platform_device_id sdma_devtypes[] = { 423 + static const struct platform_device_id sdma_devtypes[] = { 424 424 { 425 425 .name = "imx25-sdma", 426 426 .driver_data = (unsigned long)&sdma_imx25,
+188 -160
drivers/dma/mv_xor.c
··· 19 19 #include <linux/dma-mapping.h> 20 20 #include <linux/spinlock.h> 21 21 #include <linux/interrupt.h> 22 + #include <linux/of_device.h> 22 23 #include <linux/platform_device.h> 23 24 #include <linux/memory.h> 24 25 #include <linux/clk.h> ··· 30 29 31 30 #include "dmaengine.h" 32 31 #include "mv_xor.h" 32 + 33 + enum mv_xor_mode { 34 + XOR_MODE_IN_REG, 35 + XOR_MODE_IN_DESC, 36 + }; 33 37 34 38 static void mv_xor_issue_pending(struct dma_chan *chan); 35 39 ··· 62 56 hw_desc->byte_count = byte_count; 63 57 } 64 58 59 + static void mv_desc_set_mode(struct mv_xor_desc_slot *desc) 60 + { 61 + struct mv_xor_desc *hw_desc = desc->hw_desc; 62 + 63 + switch (desc->type) { 64 + case DMA_XOR: 65 + case DMA_INTERRUPT: 66 + hw_desc->desc_command |= XOR_DESC_OPERATION_XOR; 67 + break; 68 + case DMA_MEMCPY: 69 + hw_desc->desc_command |= XOR_DESC_OPERATION_MEMCPY; 70 + break; 71 + default: 72 + BUG(); 73 + return; 74 + } 75 + } 76 + 65 77 static void mv_desc_set_next_desc(struct mv_xor_desc_slot *desc, 66 78 u32 next_desc_addr) 67 79 { 68 80 struct mv_xor_desc *hw_desc = desc->hw_desc; 69 81 BUG_ON(hw_desc->phy_next_desc); 70 82 hw_desc->phy_next_desc = next_desc_addr; 71 - } 72 - 73 - static void mv_desc_clear_next_desc(struct mv_xor_desc_slot *desc) 74 - { 75 - struct mv_xor_desc *hw_desc = desc->hw_desc; 76 - hw_desc->phy_next_desc = 0; 77 83 } 78 84 79 85 static void mv_desc_set_src_addr(struct mv_xor_desc_slot *desc, ··· 122 104 return intr_cause; 123 105 } 124 106 125 - static void mv_xor_device_clear_eoc_cause(struct mv_xor_chan *chan) 107 + static void mv_chan_clear_eoc_cause(struct mv_xor_chan *chan) 126 108 { 127 109 u32 val; 128 110 ··· 132 114 writel_relaxed(val, XOR_INTR_CAUSE(chan)); 133 115 } 134 116 135 - static void mv_xor_device_clear_err_status(struct mv_xor_chan *chan) 117 + static void mv_chan_clear_err_status(struct mv_xor_chan *chan) 136 118 { 137 119 u32 val = 0xFFFF0000 >> (chan->idx * 16); 138 120 writel_relaxed(val, XOR_INTR_CAUSE(chan)); 139 121 } 140 122 141 - static void mv_set_mode(struct mv_xor_chan *chan, 142 - enum dma_transaction_type type) 123 + static void mv_chan_set_mode(struct mv_xor_chan *chan, 124 + enum dma_transaction_type type) 143 125 { 144 126 u32 op_mode; 145 127 u32 config = readl_relaxed(XOR_CONFIG(chan)); ··· 162 144 config &= ~0x7; 163 145 config |= op_mode; 164 146 147 + if (IS_ENABLED(__BIG_ENDIAN)) 148 + config |= XOR_DESCRIPTOR_SWAP; 149 + else 150 + config &= ~XOR_DESCRIPTOR_SWAP; 151 + 152 + writel_relaxed(config, XOR_CONFIG(chan)); 153 + chan->current_type = type; 154 + } 155 + 156 + static void mv_chan_set_mode_to_desc(struct mv_xor_chan *chan) 157 + { 158 + u32 op_mode; 159 + u32 config = readl_relaxed(XOR_CONFIG(chan)); 160 + 161 + op_mode = XOR_OPERATION_MODE_IN_DESC; 162 + 163 + config &= ~0x7; 164 + config |= op_mode; 165 + 165 166 #if defined(__BIG_ENDIAN) 166 167 config |= XOR_DESCRIPTOR_SWAP; 167 168 #else ··· 188 151 #endif 189 152 190 153 writel_relaxed(config, XOR_CONFIG(chan)); 191 - chan->current_type = type; 192 154 } 193 155 194 156 static void mv_chan_activate(struct mv_xor_chan *chan) ··· 207 171 return (state == 1) ? 1 : 0; 208 172 } 209 173 210 - /** 211 - * mv_xor_free_slots - flags descriptor slots for reuse 212 - * @slot: Slot to free 213 - * Caller must hold &mv_chan->lock while calling this function 214 - */ 215 - static void mv_xor_free_slots(struct mv_xor_chan *mv_chan, 216 - struct mv_xor_desc_slot *slot) 217 - { 218 - dev_dbg(mv_chan_to_devp(mv_chan), "%s %d slot %p\n", 219 - __func__, __LINE__, slot); 220 - 221 - slot->slot_used = 0; 222 - 223 - } 224 - 225 174 /* 226 - * mv_xor_start_new_chain - program the engine to operate on new chain headed by 227 - * sw_desc 175 + * mv_chan_start_new_chain - program the engine to operate on new 176 + * chain headed by sw_desc 228 177 * Caller must hold &mv_chan->lock while calling this function 229 178 */ 230 - static void mv_xor_start_new_chain(struct mv_xor_chan *mv_chan, 231 - struct mv_xor_desc_slot *sw_desc) 179 + static void mv_chan_start_new_chain(struct mv_xor_chan *mv_chan, 180 + struct mv_xor_desc_slot *sw_desc) 232 181 { 233 182 dev_dbg(mv_chan_to_devp(mv_chan), "%s %d: sw_desc %p\n", 234 183 __func__, __LINE__, sw_desc); ··· 226 205 } 227 206 228 207 static dma_cookie_t 229 - mv_xor_run_tx_complete_actions(struct mv_xor_desc_slot *desc, 230 - struct mv_xor_chan *mv_chan, dma_cookie_t cookie) 208 + mv_desc_run_tx_complete_actions(struct mv_xor_desc_slot *desc, 209 + struct mv_xor_chan *mv_chan, 210 + dma_cookie_t cookie) 231 211 { 232 212 BUG_ON(desc->async_tx.cookie < 0); 233 213 ··· 252 230 } 253 231 254 232 static int 255 - mv_xor_clean_completed_slots(struct mv_xor_chan *mv_chan) 233 + mv_chan_clean_completed_slots(struct mv_xor_chan *mv_chan) 256 234 { 257 235 struct mv_xor_desc_slot *iter, *_iter; 258 236 259 237 dev_dbg(mv_chan_to_devp(mv_chan), "%s %d\n", __func__, __LINE__); 260 238 list_for_each_entry_safe(iter, _iter, &mv_chan->completed_slots, 261 - completed_node) { 239 + node) { 262 240 263 - if (async_tx_test_ack(&iter->async_tx)) { 264 - list_del(&iter->completed_node); 265 - mv_xor_free_slots(mv_chan, iter); 266 - } 241 + if (async_tx_test_ack(&iter->async_tx)) 242 + list_move_tail(&iter->node, &mv_chan->free_slots); 267 243 } 268 244 return 0; 269 245 } 270 246 271 247 static int 272 - mv_xor_clean_slot(struct mv_xor_desc_slot *desc, 273 - struct mv_xor_chan *mv_chan) 248 + mv_desc_clean_slot(struct mv_xor_desc_slot *desc, 249 + struct mv_xor_chan *mv_chan) 274 250 { 275 251 dev_dbg(mv_chan_to_devp(mv_chan), "%s %d: desc %p flags %d\n", 276 252 __func__, __LINE__, desc, desc->async_tx.flags); 277 - list_del(&desc->chain_node); 253 + 278 254 /* the client is allowed to attach dependent operations 279 255 * until 'ack' is set 280 256 */ 281 - if (!async_tx_test_ack(&desc->async_tx)) { 257 + if (!async_tx_test_ack(&desc->async_tx)) 282 258 /* move this slot to the completed_slots */ 283 - list_add_tail(&desc->completed_node, &mv_chan->completed_slots); 284 - return 0; 285 - } 259 + list_move_tail(&desc->node, &mv_chan->completed_slots); 260 + else 261 + list_move_tail(&desc->node, &mv_chan->free_slots); 286 262 287 - mv_xor_free_slots(mv_chan, desc); 288 263 return 0; 289 264 } 290 265 291 266 /* This function must be called with the mv_xor_chan spinlock held */ 292 - static void mv_xor_slot_cleanup(struct mv_xor_chan *mv_chan) 267 + static void mv_chan_slot_cleanup(struct mv_xor_chan *mv_chan) 293 268 { 294 269 struct mv_xor_desc_slot *iter, *_iter; 295 270 dma_cookie_t cookie = 0; 296 271 int busy = mv_chan_is_busy(mv_chan); 297 272 u32 current_desc = mv_chan_get_current_desc(mv_chan); 298 - int seen_current = 0; 273 + int current_cleaned = 0; 274 + struct mv_xor_desc *hw_desc; 299 275 300 276 dev_dbg(mv_chan_to_devp(mv_chan), "%s %d\n", __func__, __LINE__); 301 277 dev_dbg(mv_chan_to_devp(mv_chan), "current_desc %x\n", current_desc); 302 - mv_xor_clean_completed_slots(mv_chan); 278 + mv_chan_clean_completed_slots(mv_chan); 303 279 304 280 /* free completed slots from the chain starting with 305 281 * the oldest descriptor 306 282 */ 307 283 308 284 list_for_each_entry_safe(iter, _iter, &mv_chan->chain, 309 - chain_node) { 310 - prefetch(_iter); 311 - prefetch(&_iter->async_tx); 285 + node) { 312 286 313 - /* do not advance past the current descriptor loaded into the 314 - * hardware channel, subsequent descriptors are either in 315 - * process or have not been submitted 316 - */ 317 - if (seen_current) 318 - break; 287 + /* clean finished descriptors */ 288 + hw_desc = iter->hw_desc; 289 + if (hw_desc->status & XOR_DESC_SUCCESS) { 290 + cookie = mv_desc_run_tx_complete_actions(iter, mv_chan, 291 + cookie); 319 292 320 - /* stop the search if we reach the current descriptor and the 321 - * channel is busy 322 - */ 323 - if (iter->async_tx.phys == current_desc) { 324 - seen_current = 1; 325 - if (busy) 293 + /* done processing desc, clean slot */ 294 + mv_desc_clean_slot(iter, mv_chan); 295 + 296 + /* break if we did cleaned the current */ 297 + if (iter->async_tx.phys == current_desc) { 298 + current_cleaned = 1; 326 299 break; 300 + } 301 + } else { 302 + if (iter->async_tx.phys == current_desc) { 303 + current_cleaned = 0; 304 + break; 305 + } 327 306 } 328 - 329 - cookie = mv_xor_run_tx_complete_actions(iter, mv_chan, cookie); 330 - 331 - if (mv_xor_clean_slot(iter, mv_chan)) 332 - break; 333 307 } 334 308 335 309 if ((busy == 0) && !list_empty(&mv_chan->chain)) { 336 - struct mv_xor_desc_slot *chain_head; 337 - chain_head = list_entry(mv_chan->chain.next, 338 - struct mv_xor_desc_slot, 339 - chain_node); 340 - 341 - mv_xor_start_new_chain(mv_chan, chain_head); 310 + if (current_cleaned) { 311 + /* 312 + * current descriptor cleaned and removed, run 313 + * from list head 314 + */ 315 + iter = list_entry(mv_chan->chain.next, 316 + struct mv_xor_desc_slot, 317 + node); 318 + mv_chan_start_new_chain(mv_chan, iter); 319 + } else { 320 + if (!list_is_last(&iter->node, &mv_chan->chain)) { 321 + /* 322 + * descriptors are still waiting after 323 + * current, trigger them 324 + */ 325 + iter = list_entry(iter->node.next, 326 + struct mv_xor_desc_slot, 327 + node); 328 + mv_chan_start_new_chain(mv_chan, iter); 329 + } else { 330 + /* 331 + * some descriptors are still waiting 332 + * to be cleaned 333 + */ 334 + tasklet_schedule(&mv_chan->irq_tasklet); 335 + } 336 + } 342 337 } 343 338 344 339 if (cookie > 0) ··· 367 328 struct mv_xor_chan *chan = (struct mv_xor_chan *) data; 368 329 369 330 spin_lock_bh(&chan->lock); 370 - mv_xor_slot_cleanup(chan); 331 + mv_chan_slot_cleanup(chan); 371 332 spin_unlock_bh(&chan->lock); 372 333 } 373 334 374 335 static struct mv_xor_desc_slot * 375 - mv_xor_alloc_slot(struct mv_xor_chan *mv_chan) 336 + mv_chan_alloc_slot(struct mv_xor_chan *mv_chan) 376 337 { 377 - struct mv_xor_desc_slot *iter, *_iter; 378 - int retry = 0; 338 + struct mv_xor_desc_slot *iter; 379 339 380 - /* start search from the last allocated descrtiptor 381 - * if a contiguous allocation can not be found start searching 382 - * from the beginning of the list 383 - */ 384 - retry: 385 - if (retry == 0) 386 - iter = mv_chan->last_used; 387 - else 388 - iter = list_entry(&mv_chan->all_slots, 389 - struct mv_xor_desc_slot, 390 - slot_node); 340 + spin_lock_bh(&mv_chan->lock); 391 341 392 - list_for_each_entry_safe_continue( 393 - iter, _iter, &mv_chan->all_slots, slot_node) { 342 + if (!list_empty(&mv_chan->free_slots)) { 343 + iter = list_first_entry(&mv_chan->free_slots, 344 + struct mv_xor_desc_slot, 345 + node); 394 346 395 - prefetch(_iter); 396 - prefetch(&_iter->async_tx); 397 - if (iter->slot_used) { 398 - /* give up after finding the first busy slot 399 - * on the second pass through the list 400 - */ 401 - if (retry) 402 - break; 403 - continue; 404 - } 347 + list_move_tail(&iter->node, &mv_chan->allocated_slots); 348 + 349 + spin_unlock_bh(&mv_chan->lock); 405 350 406 351 /* pre-ack descriptor */ 407 352 async_tx_ack(&iter->async_tx); 408 - 409 - iter->slot_used = 1; 410 - INIT_LIST_HEAD(&iter->chain_node); 411 353 iter->async_tx.cookie = -EBUSY; 412 - mv_chan->last_used = iter; 413 - mv_desc_clear_next_desc(iter); 414 354 415 355 return iter; 416 356 417 357 } 418 - if (!retry++) 419 - goto retry; 358 + 359 + spin_unlock_bh(&mv_chan->lock); 420 360 421 361 /* try to free some slots if the allocation fails */ 422 362 tasklet_schedule(&mv_chan->irq_tasklet); ··· 421 403 cookie = dma_cookie_assign(tx); 422 404 423 405 if (list_empty(&mv_chan->chain)) 424 - list_add_tail(&sw_desc->chain_node, &mv_chan->chain); 406 + list_move_tail(&sw_desc->node, &mv_chan->chain); 425 407 else { 426 408 new_hw_chain = 0; 427 409 428 410 old_chain_tail = list_entry(mv_chan->chain.prev, 429 411 struct mv_xor_desc_slot, 430 - chain_node); 431 - list_add_tail(&sw_desc->chain_node, &mv_chan->chain); 412 + node); 413 + list_move_tail(&sw_desc->node, &mv_chan->chain); 432 414 433 415 dev_dbg(mv_chan_to_devp(mv_chan), "Append to last desc %pa\n", 434 416 &old_chain_tail->async_tx.phys); ··· 449 431 } 450 432 451 433 if (new_hw_chain) 452 - mv_xor_start_new_chain(mv_chan, sw_desc); 434 + mv_chan_start_new_chain(mv_chan, sw_desc); 453 435 454 436 spin_unlock_bh(&mv_chan->lock); 455 437 ··· 481 463 482 464 dma_async_tx_descriptor_init(&slot->async_tx, chan); 483 465 slot->async_tx.tx_submit = mv_xor_tx_submit; 484 - INIT_LIST_HEAD(&slot->chain_node); 485 - INIT_LIST_HEAD(&slot->slot_node); 466 + INIT_LIST_HEAD(&slot->node); 486 467 dma_desc = mv_chan->dma_desc_pool; 487 468 slot->async_tx.phys = dma_desc + idx * MV_XOR_SLOT_SIZE; 488 469 slot->idx = idx++; 489 470 490 471 spin_lock_bh(&mv_chan->lock); 491 472 mv_chan->slots_allocated = idx; 492 - list_add_tail(&slot->slot_node, &mv_chan->all_slots); 473 + list_add_tail(&slot->node, &mv_chan->free_slots); 493 474 spin_unlock_bh(&mv_chan->lock); 494 475 } 495 476 496 - if (mv_chan->slots_allocated && !mv_chan->last_used) 497 - mv_chan->last_used = list_entry(mv_chan->all_slots.next, 498 - struct mv_xor_desc_slot, 499 - slot_node); 500 - 501 477 dev_dbg(mv_chan_to_devp(mv_chan), 502 - "allocated %d descriptor slots last_used: %p\n", 503 - mv_chan->slots_allocated, mv_chan->last_used); 478 + "allocated %d descriptor slots\n", 479 + mv_chan->slots_allocated); 504 480 505 481 return mv_chan->slots_allocated ? : -ENOMEM; 506 482 } ··· 515 503 "%s src_cnt: %d len: %u dest %pad flags: %ld\n", 516 504 __func__, src_cnt, len, &dest, flags); 517 505 518 - spin_lock_bh(&mv_chan->lock); 519 - sw_desc = mv_xor_alloc_slot(mv_chan); 506 + sw_desc = mv_chan_alloc_slot(mv_chan); 520 507 if (sw_desc) { 521 508 sw_desc->type = DMA_XOR; 522 509 sw_desc->async_tx.flags = flags; 523 510 mv_desc_init(sw_desc, dest, len, flags); 511 + if (mv_chan->op_in_desc == XOR_MODE_IN_DESC) 512 + mv_desc_set_mode(sw_desc); 524 513 while (src_cnt--) 525 514 mv_desc_set_src_addr(sw_desc, src_cnt, src[src_cnt]); 526 515 } 527 - spin_unlock_bh(&mv_chan->lock); 516 + 528 517 dev_dbg(mv_chan_to_devp(mv_chan), 529 518 "%s sw_desc %p async_tx %p \n", 530 519 __func__, sw_desc, &sw_desc->async_tx); ··· 569 556 570 557 spin_lock_bh(&mv_chan->lock); 571 558 572 - mv_xor_slot_cleanup(mv_chan); 559 + mv_chan_slot_cleanup(mv_chan); 573 560 574 561 list_for_each_entry_safe(iter, _iter, &mv_chan->chain, 575 - chain_node) { 562 + node) { 576 563 in_use_descs++; 577 - list_del(&iter->chain_node); 564 + list_move_tail(&iter->node, &mv_chan->free_slots); 578 565 } 579 566 list_for_each_entry_safe(iter, _iter, &mv_chan->completed_slots, 580 - completed_node) { 567 + node) { 581 568 in_use_descs++; 582 - list_del(&iter->completed_node); 569 + list_move_tail(&iter->node, &mv_chan->free_slots); 570 + } 571 + list_for_each_entry_safe(iter, _iter, &mv_chan->allocated_slots, 572 + node) { 573 + in_use_descs++; 574 + list_move_tail(&iter->node, &mv_chan->free_slots); 583 575 } 584 576 list_for_each_entry_safe_reverse( 585 - iter, _iter, &mv_chan->all_slots, slot_node) { 586 - list_del(&iter->slot_node); 577 + iter, _iter, &mv_chan->free_slots, node) { 578 + list_del(&iter->node); 587 579 kfree(iter); 588 580 mv_chan->slots_allocated--; 589 581 } 590 - mv_chan->last_used = NULL; 591 582 592 583 dev_dbg(mv_chan_to_devp(mv_chan), "%s slots_allocated %d\n", 593 584 __func__, mv_chan->slots_allocated); ··· 620 603 return ret; 621 604 622 605 spin_lock_bh(&mv_chan->lock); 623 - mv_xor_slot_cleanup(mv_chan); 606 + mv_chan_slot_cleanup(mv_chan); 624 607 spin_unlock_bh(&mv_chan->lock); 625 608 626 609 return dma_cookie_status(chan, cookie, txstate); 627 610 } 628 611 629 - static void mv_dump_xor_regs(struct mv_xor_chan *chan) 612 + static void mv_chan_dump_regs(struct mv_xor_chan *chan) 630 613 { 631 614 u32 val; 632 615 ··· 649 632 dev_err(mv_chan_to_devp(chan), "error addr 0x%08x\n", val); 650 633 } 651 634 652 - static void mv_xor_err_interrupt_handler(struct mv_xor_chan *chan, 653 - u32 intr_cause) 635 + static void mv_chan_err_interrupt_handler(struct mv_xor_chan *chan, 636 + u32 intr_cause) 654 637 { 655 638 if (intr_cause & XOR_INT_ERR_DECODE) { 656 639 dev_dbg(mv_chan_to_devp(chan), "ignoring address decode error\n"); ··· 660 643 dev_err(mv_chan_to_devp(chan), "error on chan %d. intr cause 0x%08x\n", 661 644 chan->idx, intr_cause); 662 645 663 - mv_dump_xor_regs(chan); 646 + mv_chan_dump_regs(chan); 664 647 WARN_ON(1); 665 648 } 666 649 ··· 672 655 dev_dbg(mv_chan_to_devp(chan), "intr cause %x\n", intr_cause); 673 656 674 657 if (intr_cause & XOR_INTR_ERRORS) 675 - mv_xor_err_interrupt_handler(chan, intr_cause); 658 + mv_chan_err_interrupt_handler(chan, intr_cause); 676 659 677 660 tasklet_schedule(&chan->irq_tasklet); 678 661 679 - mv_xor_device_clear_eoc_cause(chan); 662 + mv_chan_clear_eoc_cause(chan); 680 663 681 664 return IRQ_HANDLED; 682 665 } ··· 695 678 * Perform a transaction to verify the HW works. 696 679 */ 697 680 698 - static int mv_xor_memcpy_self_test(struct mv_xor_chan *mv_chan) 681 + static int mv_chan_memcpy_self_test(struct mv_xor_chan *mv_chan) 699 682 { 700 683 int i, ret; 701 684 void *src, *dest; ··· 804 787 805 788 #define MV_XOR_NUM_SRC_TEST 4 /* must be <= 15 */ 806 789 static int 807 - mv_xor_xor_self_test(struct mv_xor_chan *mv_chan) 790 + mv_chan_xor_self_test(struct mv_xor_chan *mv_chan) 808 791 { 809 792 int i, src_idx, ret; 810 793 struct page *dest; ··· 968 951 static struct mv_xor_chan * 969 952 mv_xor_channel_add(struct mv_xor_device *xordev, 970 953 struct platform_device *pdev, 971 - int idx, dma_cap_mask_t cap_mask, int irq) 954 + int idx, dma_cap_mask_t cap_mask, int irq, int op_in_desc) 972 955 { 973 956 int ret = 0; 974 957 struct mv_xor_chan *mv_chan; ··· 980 963 981 964 mv_chan->idx = idx; 982 965 mv_chan->irq = irq; 966 + mv_chan->op_in_desc = op_in_desc; 983 967 984 968 dma_dev = &mv_chan->dmadev; 985 969 ··· 1032 1014 mv_chan); 1033 1015 1034 1016 /* clear errors before enabling interrupts */ 1035 - mv_xor_device_clear_err_status(mv_chan); 1017 + mv_chan_clear_err_status(mv_chan); 1036 1018 1037 1019 ret = request_irq(mv_chan->irq, mv_xor_interrupt_handler, 1038 1020 0, dev_name(&pdev->dev), mv_chan); ··· 1041 1023 1042 1024 mv_chan_unmask_interrupts(mv_chan); 1043 1025 1044 - mv_set_mode(mv_chan, DMA_XOR); 1026 + if (mv_chan->op_in_desc == XOR_MODE_IN_DESC) 1027 + mv_chan_set_mode_to_desc(mv_chan); 1028 + else 1029 + mv_chan_set_mode(mv_chan, DMA_XOR); 1045 1030 1046 1031 spin_lock_init(&mv_chan->lock); 1047 1032 INIT_LIST_HEAD(&mv_chan->chain); 1048 1033 INIT_LIST_HEAD(&mv_chan->completed_slots); 1049 - INIT_LIST_HEAD(&mv_chan->all_slots); 1034 + INIT_LIST_HEAD(&mv_chan->free_slots); 1035 + INIT_LIST_HEAD(&mv_chan->allocated_slots); 1050 1036 mv_chan->dmachan.device = dma_dev; 1051 1037 dma_cookie_init(&mv_chan->dmachan); 1052 1038 1053 1039 list_add_tail(&mv_chan->dmachan.device_node, &dma_dev->channels); 1054 1040 1055 1041 if (dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask)) { 1056 - ret = mv_xor_memcpy_self_test(mv_chan); 1042 + ret = mv_chan_memcpy_self_test(mv_chan); 1057 1043 dev_dbg(&pdev->dev, "memcpy self test returned %d\n", ret); 1058 1044 if (ret) 1059 1045 goto err_free_irq; 1060 1046 } 1061 1047 1062 1048 if (dma_has_cap(DMA_XOR, dma_dev->cap_mask)) { 1063 - ret = mv_xor_xor_self_test(mv_chan); 1049 + ret = mv_chan_xor_self_test(mv_chan); 1064 1050 dev_dbg(&pdev->dev, "xor self test returned %d\n", ret); 1065 1051 if (ret) 1066 1052 goto err_free_irq; 1067 1053 } 1068 1054 1069 - dev_info(&pdev->dev, "Marvell XOR: ( %s%s%s)\n", 1055 + dev_info(&pdev->dev, "Marvell XOR (%s): ( %s%s%s)\n", 1056 + mv_chan->op_in_desc ? "Descriptor Mode" : "Registers Mode", 1070 1057 dma_has_cap(DMA_XOR, dma_dev->cap_mask) ? "xor " : "", 1071 1058 dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask) ? "cpy " : "", 1072 1059 dma_has_cap(DMA_INTERRUPT, dma_dev->cap_mask) ? "intr " : ""); ··· 1120 1097 writel(0, base + WINDOW_OVERRIDE_CTRL(1)); 1121 1098 } 1122 1099 1100 + static const struct of_device_id mv_xor_dt_ids[] = { 1101 + { .compatible = "marvell,orion-xor", .data = (void *)XOR_MODE_IN_REG }, 1102 + { .compatible = "marvell,armada-380-xor", .data = (void *)XOR_MODE_IN_DESC }, 1103 + {}, 1104 + }; 1105 + MODULE_DEVICE_TABLE(of, mv_xor_dt_ids); 1106 + 1123 1107 static int mv_xor_probe(struct platform_device *pdev) 1124 1108 { 1125 1109 const struct mbus_dram_target_info *dram; ··· 1134 1104 struct mv_xor_platform_data *pdata = dev_get_platdata(&pdev->dev); 1135 1105 struct resource *res; 1136 1106 int i, ret; 1107 + int op_in_desc; 1137 1108 1138 1109 dev_notice(&pdev->dev, "Marvell shared XOR driver\n"); 1139 1110 ··· 1179 1148 if (pdev->dev.of_node) { 1180 1149 struct device_node *np; 1181 1150 int i = 0; 1151 + const struct of_device_id *of_id = 1152 + of_match_device(mv_xor_dt_ids, 1153 + &pdev->dev); 1182 1154 1183 1155 for_each_child_of_node(pdev->dev.of_node, np) { 1184 1156 struct mv_xor_chan *chan; 1185 1157 dma_cap_mask_t cap_mask; 1186 1158 int irq; 1159 + op_in_desc = (int)of_id->data; 1187 1160 1188 1161 dma_cap_zero(cap_mask); 1189 1162 if (of_property_read_bool(np, "dmacap,memcpy")) ··· 1204 1169 } 1205 1170 1206 1171 chan = mv_xor_channel_add(xordev, pdev, i, 1207 - cap_mask, irq); 1172 + cap_mask, irq, op_in_desc); 1208 1173 if (IS_ERR(chan)) { 1209 1174 ret = PTR_ERR(chan); 1210 1175 irq_dispose_mapping(irq); ··· 1233 1198 } 1234 1199 1235 1200 chan = mv_xor_channel_add(xordev, pdev, i, 1236 - cd->cap_mask, irq); 1201 + cd->cap_mask, irq, 1202 + XOR_MODE_IN_REG); 1237 1203 if (IS_ERR(chan)) { 1238 1204 ret = PTR_ERR(chan); 1239 1205 goto err_channel_add; ··· 1279 1243 1280 1244 return 0; 1281 1245 } 1282 - 1283 - #ifdef CONFIG_OF 1284 - static const struct of_device_id mv_xor_dt_ids[] = { 1285 - { .compatible = "marvell,orion-xor", }, 1286 - {}, 1287 - }; 1288 - MODULE_DEVICE_TABLE(of, mv_xor_dt_ids); 1289 - #endif 1290 1246 1291 1247 static struct platform_driver mv_xor_driver = { 1292 1248 .probe = mv_xor_probe,
+15 -12
drivers/dma/mv_xor.h
··· 19 19 #include <linux/dmaengine.h> 20 20 #include <linux/interrupt.h> 21 21 22 - #define MV_XOR_POOL_SIZE PAGE_SIZE 22 + #define MV_XOR_POOL_SIZE (MV_XOR_SLOT_SIZE * 3072) 23 23 #define MV_XOR_SLOT_SIZE 64 24 24 #define MV_XOR_THRESHOLD 1 25 25 #define MV_XOR_MAX_CHANNELS 2 ··· 30 30 /* Values for the XOR_CONFIG register */ 31 31 #define XOR_OPERATION_MODE_XOR 0 32 32 #define XOR_OPERATION_MODE_MEMCPY 2 33 + #define XOR_OPERATION_MODE_IN_DESC 7 33 34 #define XOR_DESCRIPTOR_SWAP BIT(14) 35 + #define XOR_DESC_SUCCESS 0x40000000 36 + 37 + #define XOR_DESC_OPERATION_XOR (0 << 24) 38 + #define XOR_DESC_OPERATION_CRC32C (1 << 24) 39 + #define XOR_DESC_OPERATION_MEMCPY (2 << 24) 34 40 35 41 #define XOR_DESC_DMA_OWNED BIT(31) 36 42 #define XOR_DESC_EOD_INT_EN BIT(31) ··· 94 88 * @mmr_base: memory mapped register base 95 89 * @idx: the index of the xor channel 96 90 * @chain: device chain view of the descriptors 91 + * @free_slots: free slots usable by the channel 92 + * @allocated_slots: slots allocated by the driver 97 93 * @completed_slots: slots completed by HW but still need to be acked 98 94 * @device: parent device 99 95 * @common: common dmaengine channel object members 100 - * @last_used: place holder for allocation to continue from where it left off 101 - * @all_slots: complete domain of slots usable by the channel 102 96 * @slots_allocated: records the actual size of the descriptor slot pool 103 97 * @irq_tasklet: bottom half where mv_xor_slot_cleanup runs 98 + * @op_in_desc: new mode of driver, each op is writen to descriptor. 104 99 */ 105 100 struct mv_xor_chan { 106 101 int pending; ··· 112 105 int irq; 113 106 enum dma_transaction_type current_type; 114 107 struct list_head chain; 108 + struct list_head free_slots; 109 + struct list_head allocated_slots; 115 110 struct list_head completed_slots; 116 111 dma_addr_t dma_desc_pool; 117 112 void *dma_desc_pool_virt; 118 113 size_t pool_size; 119 114 struct dma_device dmadev; 120 115 struct dma_chan dmachan; 121 - struct mv_xor_desc_slot *last_used; 122 - struct list_head all_slots; 123 116 int slots_allocated; 124 117 struct tasklet_struct irq_tasklet; 118 + int op_in_desc; 125 119 char dummy_src[MV_XOR_MIN_BYTE_COUNT]; 126 120 char dummy_dst[MV_XOR_MIN_BYTE_COUNT]; 127 121 dma_addr_t dummy_src_addr, dummy_dst_addr; ··· 130 122 131 123 /** 132 124 * struct mv_xor_desc_slot - software descriptor 133 - * @slot_node: node on the mv_xor_chan.all_slots list 134 - * @chain_node: node on the mv_xor_chan.chain list 135 - * @completed_node: node on the mv_xor_chan.completed_slots list 125 + * @node: node on the mv_xor_chan lists 136 126 * @hw_desc: virtual address of the hardware descriptor chain 137 127 * @phys: hardware address of the hardware descriptor chain 138 128 * @slot_used: slot in use or not ··· 139 133 * @async_tx: support for the async_tx api 140 134 */ 141 135 struct mv_xor_desc_slot { 142 - struct list_head slot_node; 143 - struct list_head chain_node; 144 - struct list_head completed_node; 136 + struct list_head node; 145 137 enum dma_transaction_type type; 146 138 void *hw_desc; 147 - u16 slot_used; 148 139 u16 idx; 149 140 struct dma_async_tx_descriptor async_tx; 150 141 };
+1 -1
drivers/dma/mxs-dma.c
··· 170 170 } 171 171 }; 172 172 173 - static struct platform_device_id mxs_dma_ids[] = { 173 + static const struct platform_device_id mxs_dma_ids[] = { 174 174 { 175 175 .name = "imx23-dma-apbh", 176 176 .driver_data = (kernel_ulong_t) &mxs_dma_types[0],
+1 -1
drivers/dma/nbpfaxi.c
··· 1455 1455 return 0; 1456 1456 } 1457 1457 1458 - static struct platform_device_id nbpf_ids[] = { 1458 + static const struct platform_device_id nbpf_ids[] = { 1459 1459 {"nbpfaxi64dmac1b4", (kernel_ulong_t)&nbpf_cfg[NBPF1B4]}, 1460 1460 {"nbpfaxi64dmac1b8", (kernel_ulong_t)&nbpf_cfg[NBPF1B8]}, 1461 1461 {"nbpfaxi64dmac1b16", (kernel_ulong_t)&nbpf_cfg[NBPF1B16]},
+89
drivers/dma/of-dma.c
··· 45 45 } 46 46 47 47 /** 48 + * of_dma_router_xlate - translation function for router devices 49 + * @dma_spec: pointer to DMA specifier as found in the device tree 50 + * @of_dma: pointer to DMA controller data (router information) 51 + * 52 + * The function creates new dma_spec to be passed to the router driver's 53 + * of_dma_route_allocate() function to prepare a dma_spec which will be used 54 + * to request channel from the real DMA controller. 55 + */ 56 + static struct dma_chan *of_dma_router_xlate(struct of_phandle_args *dma_spec, 57 + struct of_dma *ofdma) 58 + { 59 + struct dma_chan *chan; 60 + struct of_dma *ofdma_target; 61 + struct of_phandle_args dma_spec_target; 62 + void *route_data; 63 + 64 + /* translate the request for the real DMA controller */ 65 + memcpy(&dma_spec_target, dma_spec, sizeof(dma_spec_target)); 66 + route_data = ofdma->of_dma_route_allocate(&dma_spec_target, ofdma); 67 + if (IS_ERR(route_data)) 68 + return NULL; 69 + 70 + ofdma_target = of_dma_find_controller(&dma_spec_target); 71 + if (!ofdma_target) 72 + return NULL; 73 + 74 + chan = ofdma_target->of_dma_xlate(&dma_spec_target, ofdma_target); 75 + if (chan) { 76 + chan->router = ofdma->dma_router; 77 + chan->route_data = route_data; 78 + } else { 79 + ofdma->dma_router->route_free(ofdma->dma_router->dev, 80 + route_data); 81 + } 82 + 83 + /* 84 + * Need to put the node back since the ofdma->of_dma_route_allocate 85 + * has taken it for generating the new, translated dma_spec 86 + */ 87 + of_node_put(dma_spec_target.np); 88 + return chan; 89 + } 90 + 91 + /** 48 92 * of_dma_controller_register - Register a DMA controller to DT DMA helpers 49 93 * @np: device node of DMA controller 50 94 * @of_dma_xlate: translation function which converts a phandle ··· 152 108 mutex_unlock(&of_dma_lock); 153 109 } 154 110 EXPORT_SYMBOL_GPL(of_dma_controller_free); 111 + 112 + /** 113 + * of_dma_router_register - Register a DMA router to DT DMA helpers as a 114 + * controller 115 + * @np: device node of DMA router 116 + * @of_dma_route_allocate: setup function for the router which need to 117 + * modify the dma_spec for the DMA controller to 118 + * use and to set up the requested route. 119 + * @dma_router: pointer to dma_router structure to be used when 120 + * the route need to be free up. 121 + * 122 + * Returns 0 on success or appropriate errno value on error. 123 + * 124 + * Allocated memory should be freed with appropriate of_dma_controller_free() 125 + * call. 126 + */ 127 + int of_dma_router_register(struct device_node *np, 128 + void *(*of_dma_route_allocate) 129 + (struct of_phandle_args *, struct of_dma *), 130 + struct dma_router *dma_router) 131 + { 132 + struct of_dma *ofdma; 133 + 134 + if (!np || !of_dma_route_allocate || !dma_router) { 135 + pr_err("%s: not enough information provided\n", __func__); 136 + return -EINVAL; 137 + } 138 + 139 + ofdma = kzalloc(sizeof(*ofdma), GFP_KERNEL); 140 + if (!ofdma) 141 + return -ENOMEM; 142 + 143 + ofdma->of_node = np; 144 + ofdma->of_dma_xlate = of_dma_router_xlate; 145 + ofdma->of_dma_route_allocate = of_dma_route_allocate; 146 + ofdma->dma_router = dma_router; 147 + 148 + /* Now queue of_dma controller structure in list */ 149 + mutex_lock(&of_dma_lock); 150 + list_add_tail(&ofdma->of_dma_controllers, &of_dma_list); 151 + mutex_unlock(&of_dma_lock); 152 + 153 + return 0; 154 + } 155 + EXPORT_SYMBOL_GPL(of_dma_router_register); 155 156 156 157 /** 157 158 * of_dma_match_channel - Check if a DMA specifier matches name
+72 -8
drivers/dma/omap-dma.c
··· 22 22 23 23 #include "virt-dma.h" 24 24 25 + #define OMAP_SDMA_REQUESTS 127 26 + #define OMAP_SDMA_CHANNELS 32 27 + 25 28 struct omap_dmadev { 26 29 struct dma_device ddev; 27 30 spinlock_t lock; ··· 34 31 const struct omap_dma_reg *reg_map; 35 32 struct omap_system_dma_plat_info *plat; 36 33 bool legacy; 34 + unsigned dma_requests; 37 35 spinlock_t irq_lock; 38 36 uint32_t irq_enable_mask; 39 - struct omap_chan *lch_map[32]; 37 + struct omap_chan *lch_map[OMAP_SDMA_CHANNELS]; 40 38 }; 41 39 42 40 struct omap_chan { ··· 366 362 struct omap_sg *sg = d->sg + idx; 367 363 unsigned cxsa, cxei, cxfi; 368 364 369 - if (d->dir == DMA_DEV_TO_MEM) { 365 + if (d->dir == DMA_DEV_TO_MEM || d->dir == DMA_MEM_TO_MEM) { 370 366 cxsa = CDSA; 371 367 cxei = CDEI; 372 368 cxfi = CDFI; ··· 412 408 if (dma_omap1()) 413 409 omap_dma_chan_write(c, CCR2, d->ccr >> 16); 414 410 415 - if (d->dir == DMA_DEV_TO_MEM) { 411 + if (d->dir == DMA_DEV_TO_MEM || d->dir == DMA_MEM_TO_MEM) { 416 412 cxsa = CSSA; 417 413 cxei = CSEI; 418 414 cxfi = CSFI; ··· 593 589 omap_free_dma(c->dma_ch); 594 590 595 591 dev_dbg(od->ddev.dev, "freeing channel for %u\n", c->dma_sig); 592 + c->dma_sig = 0; 596 593 } 597 594 598 595 static size_t omap_dma_sg_size(struct omap_sg *sg) ··· 953 948 return vchan_tx_prep(&c->vc, &d->vd, flags); 954 949 } 955 950 951 + static struct dma_async_tx_descriptor *omap_dma_prep_dma_memcpy( 952 + struct dma_chan *chan, dma_addr_t dest, dma_addr_t src, 953 + size_t len, unsigned long tx_flags) 954 + { 955 + struct omap_chan *c = to_omap_dma_chan(chan); 956 + struct omap_desc *d; 957 + uint8_t data_type; 958 + 959 + d = kzalloc(sizeof(*d) + sizeof(d->sg[0]), GFP_ATOMIC); 960 + if (!d) 961 + return NULL; 962 + 963 + data_type = __ffs((src | dest | len)); 964 + if (data_type > CSDP_DATA_TYPE_32) 965 + data_type = CSDP_DATA_TYPE_32; 966 + 967 + d->dir = DMA_MEM_TO_MEM; 968 + d->dev_addr = src; 969 + d->fi = 0; 970 + d->es = data_type; 971 + d->sg[0].en = len / BIT(data_type); 972 + d->sg[0].fn = 1; 973 + d->sg[0].addr = dest; 974 + d->sglen = 1; 975 + d->ccr = c->ccr; 976 + d->ccr |= CCR_DST_AMODE_POSTINC | CCR_SRC_AMODE_POSTINC; 977 + 978 + d->cicr = CICR_DROP_IE; 979 + if (tx_flags & DMA_PREP_INTERRUPT) 980 + d->cicr |= CICR_FRAME_IE; 981 + 982 + d->csdp = data_type; 983 + 984 + if (dma_omap1()) { 985 + d->cicr |= CICR_TOUT_IE; 986 + d->csdp |= CSDP_DST_PORT_EMIFF | CSDP_SRC_PORT_EMIFF; 987 + } else { 988 + d->csdp |= CSDP_DST_PACKED | CSDP_SRC_PACKED; 989 + d->cicr |= CICR_MISALIGNED_ERR_IE | CICR_TRANS_ERR_IE; 990 + d->csdp |= CSDP_DST_BURST_64 | CSDP_SRC_BURST_64; 991 + } 992 + 993 + return vchan_tx_prep(&c->vc, &d->vd, tx_flags); 994 + } 995 + 956 996 static int omap_dma_slave_config(struct dma_chan *chan, struct dma_slave_config *cfg) 957 997 { 958 998 struct omap_chan *c = to_omap_dma_chan(chan); ··· 1087 1037 return 0; 1088 1038 } 1089 1039 1090 - static int omap_dma_chan_init(struct omap_dmadev *od, int dma_sig) 1040 + static int omap_dma_chan_init(struct omap_dmadev *od) 1091 1041 { 1092 1042 struct omap_chan *c; 1093 1043 ··· 1096 1046 return -ENOMEM; 1097 1047 1098 1048 c->reg_map = od->reg_map; 1099 - c->dma_sig = dma_sig; 1100 1049 c->vc.desc_free = omap_dma_desc_free; 1101 1050 vchan_init(&c->vc, &od->ddev); 1102 1051 INIT_LIST_HEAD(&c->node); ··· 1143 1094 1144 1095 dma_cap_set(DMA_SLAVE, od->ddev.cap_mask); 1145 1096 dma_cap_set(DMA_CYCLIC, od->ddev.cap_mask); 1097 + dma_cap_set(DMA_MEMCPY, od->ddev.cap_mask); 1146 1098 od->ddev.device_alloc_chan_resources = omap_dma_alloc_chan_resources; 1147 1099 od->ddev.device_free_chan_resources = omap_dma_free_chan_resources; 1148 1100 od->ddev.device_tx_status = omap_dma_tx_status; 1149 1101 od->ddev.device_issue_pending = omap_dma_issue_pending; 1150 1102 od->ddev.device_prep_slave_sg = omap_dma_prep_slave_sg; 1151 1103 od->ddev.device_prep_dma_cyclic = omap_dma_prep_dma_cyclic; 1104 + od->ddev.device_prep_dma_memcpy = omap_dma_prep_dma_memcpy; 1152 1105 od->ddev.device_config = omap_dma_slave_config; 1153 1106 od->ddev.device_pause = omap_dma_pause; 1154 1107 od->ddev.device_resume = omap_dma_resume; ··· 1167 1116 1168 1117 tasklet_init(&od->task, omap_dma_sched, (unsigned long)od); 1169 1118 1170 - for (i = 0; i < 127; i++) { 1171 - rc = omap_dma_chan_init(od, i); 1119 + od->dma_requests = OMAP_SDMA_REQUESTS; 1120 + if (pdev->dev.of_node && of_property_read_u32(pdev->dev.of_node, 1121 + "dma-requests", 1122 + &od->dma_requests)) { 1123 + dev_info(&pdev->dev, 1124 + "Missing dma-requests property, using %u.\n", 1125 + OMAP_SDMA_REQUESTS); 1126 + } 1127 + 1128 + for (i = 0; i < OMAP_SDMA_CHANNELS; i++) { 1129 + rc = omap_dma_chan_init(od); 1172 1130 if (rc) { 1173 1131 omap_dma_free(od); 1174 1132 return rc; ··· 1268 1208 bool omap_dma_filter_fn(struct dma_chan *chan, void *param) 1269 1209 { 1270 1210 if (chan->device->dev->driver == &omap_dma_driver.driver) { 1211 + struct omap_dmadev *od = to_omap_dma_dev(chan->device); 1271 1212 struct omap_chan *c = to_omap_dma_chan(chan); 1272 1213 unsigned req = *(unsigned *)param; 1273 1214 1274 - return req == c->dma_sig; 1215 + if (req <= od->dma_requests) { 1216 + c->dma_sig = req; 1217 + return true; 1218 + } 1275 1219 } 1276 1220 return false; 1277 1221 }
+5 -3
drivers/dma/pl330.c
··· 1424 1424 goto xfer_exit; 1425 1425 1426 1426 if (ret > pl330->mcbufsz / 2) { 1427 - dev_info(pl330->ddma.dev, "%s:%d Trying increasing mcbufsz\n", 1428 - __func__, __LINE__); 1427 + dev_info(pl330->ddma.dev, "%s:%d Try increasing mcbufsz (%i/%i)\n", 1428 + __func__, __LINE__, ret, pl330->mcbufsz / 2); 1429 1429 ret = -ENOMEM; 1430 1430 goto xfer_exit; 1431 1431 } ··· 2584 2584 { 2585 2585 struct dma_pl330_desc *desc; 2586 2586 struct dma_pl330_chan *pch = to_pchan(chan); 2587 - struct pl330_dmac *pl330 = pch->dmac; 2587 + struct pl330_dmac *pl330; 2588 2588 int burst; 2589 2589 2590 2590 if (unlikely(!pch || !len)) 2591 2591 return NULL; 2592 + 2593 + pl330 = pch->dmac; 2592 2594 2593 2595 desc = __pl330_prep_dma_memcpy(pch, dst, src, len); 2594 2596 if (!desc)
+1467
drivers/dma/pxa_dma.c
··· 1 + /* 2 + * Copyright 2015 Robert Jarzmik <robert.jarzmik@free.fr> 3 + * 4 + * This program is free software; you can redistribute it and/or modify 5 + * it under the terms of the GNU General Public License version 2 as 6 + * published by the Free Software Foundation. 7 + */ 8 + 9 + #include <linux/err.h> 10 + #include <linux/module.h> 11 + #include <linux/init.h> 12 + #include <linux/types.h> 13 + #include <linux/interrupt.h> 14 + #include <linux/dma-mapping.h> 15 + #include <linux/slab.h> 16 + #include <linux/dmaengine.h> 17 + #include <linux/platform_device.h> 18 + #include <linux/device.h> 19 + #include <linux/platform_data/mmp_dma.h> 20 + #include <linux/dmapool.h> 21 + #include <linux/of_device.h> 22 + #include <linux/of_dma.h> 23 + #include <linux/of.h> 24 + #include <linux/dma/pxa-dma.h> 25 + 26 + #include "dmaengine.h" 27 + #include "virt-dma.h" 28 + 29 + #define DCSR(n) (0x0000 + ((n) << 2)) 30 + #define DALGN(n) 0x00a0 31 + #define DINT 0x00f0 32 + #define DDADR(n) (0x0200 + ((n) << 4)) 33 + #define DSADR(n) (0x0204 + ((n) << 4)) 34 + #define DTADR(n) (0x0208 + ((n) << 4)) 35 + #define DCMD(n) (0x020c + ((n) << 4)) 36 + 37 + #define PXA_DCSR_RUN BIT(31) /* Run Bit (read / write) */ 38 + #define PXA_DCSR_NODESC BIT(30) /* No-Descriptor Fetch (read / write) */ 39 + #define PXA_DCSR_STOPIRQEN BIT(29) /* Stop Interrupt Enable (R/W) */ 40 + #define PXA_DCSR_REQPEND BIT(8) /* Request Pending (read-only) */ 41 + #define PXA_DCSR_STOPSTATE BIT(3) /* Stop State (read-only) */ 42 + #define PXA_DCSR_ENDINTR BIT(2) /* End Interrupt (read / write) */ 43 + #define PXA_DCSR_STARTINTR BIT(1) /* Start Interrupt (read / write) */ 44 + #define PXA_DCSR_BUSERR BIT(0) /* Bus Error Interrupt (read / write) */ 45 + 46 + #define PXA_DCSR_EORIRQEN BIT(28) /* End of Receive IRQ Enable (R/W) */ 47 + #define PXA_DCSR_EORJMPEN BIT(27) /* Jump to next descriptor on EOR */ 48 + #define PXA_DCSR_EORSTOPEN BIT(26) /* STOP on an EOR */ 49 + #define PXA_DCSR_SETCMPST BIT(25) /* Set Descriptor Compare Status */ 50 + #define PXA_DCSR_CLRCMPST BIT(24) /* Clear Descriptor Compare Status */ 51 + #define PXA_DCSR_CMPST BIT(10) /* The Descriptor Compare Status */ 52 + #define PXA_DCSR_EORINTR BIT(9) /* The end of Receive */ 53 + 54 + #define DRCMR_MAPVLD BIT(7) /* Map Valid (read / write) */ 55 + #define DRCMR_CHLNUM 0x1f /* mask for Channel Number (read / write) */ 56 + 57 + #define DDADR_DESCADDR 0xfffffff0 /* Address of next descriptor (mask) */ 58 + #define DDADR_STOP BIT(0) /* Stop (read / write) */ 59 + 60 + #define PXA_DCMD_INCSRCADDR BIT(31) /* Source Address Increment Setting. */ 61 + #define PXA_DCMD_INCTRGADDR BIT(30) /* Target Address Increment Setting. */ 62 + #define PXA_DCMD_FLOWSRC BIT(29) /* Flow Control by the source. */ 63 + #define PXA_DCMD_FLOWTRG BIT(28) /* Flow Control by the target. */ 64 + #define PXA_DCMD_STARTIRQEN BIT(22) /* Start Interrupt Enable */ 65 + #define PXA_DCMD_ENDIRQEN BIT(21) /* End Interrupt Enable */ 66 + #define PXA_DCMD_ENDIAN BIT(18) /* Device Endian-ness. */ 67 + #define PXA_DCMD_BURST8 (1 << 16) /* 8 byte burst */ 68 + #define PXA_DCMD_BURST16 (2 << 16) /* 16 byte burst */ 69 + #define PXA_DCMD_BURST32 (3 << 16) /* 32 byte burst */ 70 + #define PXA_DCMD_WIDTH1 (1 << 14) /* 1 byte width */ 71 + #define PXA_DCMD_WIDTH2 (2 << 14) /* 2 byte width (HalfWord) */ 72 + #define PXA_DCMD_WIDTH4 (3 << 14) /* 4 byte width (Word) */ 73 + #define PXA_DCMD_LENGTH 0x01fff /* length mask (max = 8K - 1) */ 74 + 75 + #define PDMA_ALIGNMENT 3 76 + #define PDMA_MAX_DESC_BYTES (PXA_DCMD_LENGTH & ~((1 << PDMA_ALIGNMENT) - 1)) 77 + 78 + struct pxad_desc_hw { 79 + u32 ddadr; /* Points to the next descriptor + flags */ 80 + u32 dsadr; /* DSADR value for the current transfer */ 81 + u32 dtadr; /* DTADR value for the current transfer */ 82 + u32 dcmd; /* DCMD value for the current transfer */ 83 + } __aligned(16); 84 + 85 + struct pxad_desc_sw { 86 + struct virt_dma_desc vd; /* Virtual descriptor */ 87 + int nb_desc; /* Number of hw. descriptors */ 88 + size_t len; /* Number of bytes xfered */ 89 + dma_addr_t first; /* First descriptor's addr */ 90 + 91 + /* At least one descriptor has an src/dst address not multiple of 8 */ 92 + bool misaligned; 93 + bool cyclic; 94 + struct dma_pool *desc_pool; /* Channel's used allocator */ 95 + 96 + struct pxad_desc_hw *hw_desc[]; /* DMA coherent descriptors */ 97 + }; 98 + 99 + struct pxad_phy { 100 + int idx; 101 + void __iomem *base; 102 + struct pxad_chan *vchan; 103 + }; 104 + 105 + struct pxad_chan { 106 + struct virt_dma_chan vc; /* Virtual channel */ 107 + u32 drcmr; /* Requestor of the channel */ 108 + enum pxad_chan_prio prio; /* Required priority of phy */ 109 + /* 110 + * At least one desc_sw in submitted or issued transfers on this channel 111 + * has one address such as: addr % 8 != 0. This implies the DALGN 112 + * setting on the phy. 113 + */ 114 + bool misaligned; 115 + struct dma_slave_config cfg; /* Runtime config */ 116 + 117 + /* protected by vc->lock */ 118 + struct pxad_phy *phy; 119 + struct dma_pool *desc_pool; /* Descriptors pool */ 120 + }; 121 + 122 + struct pxad_device { 123 + struct dma_device slave; 124 + int nr_chans; 125 + void __iomem *base; 126 + struct pxad_phy *phys; 127 + spinlock_t phy_lock; /* Phy association */ 128 + #ifdef CONFIG_DEBUG_FS 129 + struct dentry *dbgfs_root; 130 + struct dentry *dbgfs_state; 131 + struct dentry **dbgfs_chan; 132 + #endif 133 + }; 134 + 135 + #define tx_to_pxad_desc(tx) \ 136 + container_of(tx, struct pxad_desc_sw, async_tx) 137 + #define to_pxad_chan(dchan) \ 138 + container_of(dchan, struct pxad_chan, vc.chan) 139 + #define to_pxad_dev(dmadev) \ 140 + container_of(dmadev, struct pxad_device, slave) 141 + #define to_pxad_sw_desc(_vd) \ 142 + container_of((_vd), struct pxad_desc_sw, vd) 143 + 144 + #define _phy_readl_relaxed(phy, _reg) \ 145 + readl_relaxed((phy)->base + _reg((phy)->idx)) 146 + #define phy_readl_relaxed(phy, _reg) \ 147 + ({ \ 148 + u32 _v; \ 149 + _v = readl_relaxed((phy)->base + _reg((phy)->idx)); \ 150 + dev_vdbg(&phy->vchan->vc.chan.dev->device, \ 151 + "%s(): readl(%s): 0x%08x\n", __func__, #_reg, \ 152 + _v); \ 153 + _v; \ 154 + }) 155 + #define phy_writel(phy, val, _reg) \ 156 + do { \ 157 + writel((val), (phy)->base + _reg((phy)->idx)); \ 158 + dev_vdbg(&phy->vchan->vc.chan.dev->device, \ 159 + "%s(): writel(0x%08x, %s)\n", \ 160 + __func__, (u32)(val), #_reg); \ 161 + } while (0) 162 + #define phy_writel_relaxed(phy, val, _reg) \ 163 + do { \ 164 + writel_relaxed((val), (phy)->base + _reg((phy)->idx)); \ 165 + dev_vdbg(&phy->vchan->vc.chan.dev->device, \ 166 + "%s(): writel_relaxed(0x%08x, %s)\n", \ 167 + __func__, (u32)(val), #_reg); \ 168 + } while (0) 169 + 170 + static unsigned int pxad_drcmr(unsigned int line) 171 + { 172 + if (line < 64) 173 + return 0x100 + line * 4; 174 + return 0x1000 + line * 4; 175 + } 176 + 177 + /* 178 + * Debug fs 179 + */ 180 + #ifdef CONFIG_DEBUG_FS 181 + #include <linux/debugfs.h> 182 + #include <linux/uaccess.h> 183 + #include <linux/seq_file.h> 184 + 185 + static int dbg_show_requester_chan(struct seq_file *s, void *p) 186 + { 187 + int pos = 0; 188 + struct pxad_phy *phy = s->private; 189 + int i; 190 + u32 drcmr; 191 + 192 + pos += seq_printf(s, "DMA channel %d requester :\n", phy->idx); 193 + for (i = 0; i < 70; i++) { 194 + drcmr = readl_relaxed(phy->base + pxad_drcmr(i)); 195 + if ((drcmr & DRCMR_CHLNUM) == phy->idx) 196 + pos += seq_printf(s, "\tRequester %d (MAPVLD=%d)\n", i, 197 + !!(drcmr & DRCMR_MAPVLD)); 198 + } 199 + return pos; 200 + } 201 + 202 + static inline int dbg_burst_from_dcmd(u32 dcmd) 203 + { 204 + int burst = (dcmd >> 16) & 0x3; 205 + 206 + return burst ? 4 << burst : 0; 207 + } 208 + 209 + static int is_phys_valid(unsigned long addr) 210 + { 211 + return pfn_valid(__phys_to_pfn(addr)); 212 + } 213 + 214 + #define PXA_DCSR_STR(flag) (dcsr & PXA_DCSR_##flag ? #flag" " : "") 215 + #define PXA_DCMD_STR(flag) (dcmd & PXA_DCMD_##flag ? #flag" " : "") 216 + 217 + static int dbg_show_descriptors(struct seq_file *s, void *p) 218 + { 219 + struct pxad_phy *phy = s->private; 220 + int i, max_show = 20, burst, width; 221 + u32 dcmd; 222 + unsigned long phys_desc, ddadr; 223 + struct pxad_desc_hw *desc; 224 + 225 + phys_desc = ddadr = _phy_readl_relaxed(phy, DDADR); 226 + 227 + seq_printf(s, "DMA channel %d descriptors :\n", phy->idx); 228 + seq_printf(s, "[%03d] First descriptor unknown\n", 0); 229 + for (i = 1; i < max_show && is_phys_valid(phys_desc); i++) { 230 + desc = phys_to_virt(phys_desc); 231 + dcmd = desc->dcmd; 232 + burst = dbg_burst_from_dcmd(dcmd); 233 + width = (1 << ((dcmd >> 14) & 0x3)) >> 1; 234 + 235 + seq_printf(s, "[%03d] Desc at %08lx(virt %p)\n", 236 + i, phys_desc, desc); 237 + seq_printf(s, "\tDDADR = %08x\n", desc->ddadr); 238 + seq_printf(s, "\tDSADR = %08x\n", desc->dsadr); 239 + seq_printf(s, "\tDTADR = %08x\n", desc->dtadr); 240 + seq_printf(s, "\tDCMD = %08x (%s%s%s%s%s%s%sburst=%d width=%d len=%d)\n", 241 + dcmd, 242 + PXA_DCMD_STR(INCSRCADDR), PXA_DCMD_STR(INCTRGADDR), 243 + PXA_DCMD_STR(FLOWSRC), PXA_DCMD_STR(FLOWTRG), 244 + PXA_DCMD_STR(STARTIRQEN), PXA_DCMD_STR(ENDIRQEN), 245 + PXA_DCMD_STR(ENDIAN), burst, width, 246 + dcmd & PXA_DCMD_LENGTH); 247 + phys_desc = desc->ddadr; 248 + } 249 + if (i == max_show) 250 + seq_printf(s, "[%03d] Desc at %08lx ... max display reached\n", 251 + i, phys_desc); 252 + else 253 + seq_printf(s, "[%03d] Desc at %08lx is %s\n", 254 + i, phys_desc, phys_desc == DDADR_STOP ? 255 + "DDADR_STOP" : "invalid"); 256 + 257 + return 0; 258 + } 259 + 260 + static int dbg_show_chan_state(struct seq_file *s, void *p) 261 + { 262 + struct pxad_phy *phy = s->private; 263 + u32 dcsr, dcmd; 264 + int burst, width; 265 + static const char * const str_prio[] = { 266 + "high", "normal", "low", "invalid" 267 + }; 268 + 269 + dcsr = _phy_readl_relaxed(phy, DCSR); 270 + dcmd = _phy_readl_relaxed(phy, DCMD); 271 + burst = dbg_burst_from_dcmd(dcmd); 272 + width = (1 << ((dcmd >> 14) & 0x3)) >> 1; 273 + 274 + seq_printf(s, "DMA channel %d\n", phy->idx); 275 + seq_printf(s, "\tPriority : %s\n", 276 + str_prio[(phy->idx & 0xf) / 4]); 277 + seq_printf(s, "\tUnaligned transfer bit: %s\n", 278 + _phy_readl_relaxed(phy, DALGN) & BIT(phy->idx) ? 279 + "yes" : "no"); 280 + seq_printf(s, "\tDCSR = %08x (%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s)\n", 281 + dcsr, PXA_DCSR_STR(RUN), PXA_DCSR_STR(NODESC), 282 + PXA_DCSR_STR(STOPIRQEN), PXA_DCSR_STR(EORIRQEN), 283 + PXA_DCSR_STR(EORJMPEN), PXA_DCSR_STR(EORSTOPEN), 284 + PXA_DCSR_STR(SETCMPST), PXA_DCSR_STR(CLRCMPST), 285 + PXA_DCSR_STR(CMPST), PXA_DCSR_STR(EORINTR), 286 + PXA_DCSR_STR(REQPEND), PXA_DCSR_STR(STOPSTATE), 287 + PXA_DCSR_STR(ENDINTR), PXA_DCSR_STR(STARTINTR), 288 + PXA_DCSR_STR(BUSERR)); 289 + 290 + seq_printf(s, "\tDCMD = %08x (%s%s%s%s%s%s%sburst=%d width=%d len=%d)\n", 291 + dcmd, 292 + PXA_DCMD_STR(INCSRCADDR), PXA_DCMD_STR(INCTRGADDR), 293 + PXA_DCMD_STR(FLOWSRC), PXA_DCMD_STR(FLOWTRG), 294 + PXA_DCMD_STR(STARTIRQEN), PXA_DCMD_STR(ENDIRQEN), 295 + PXA_DCMD_STR(ENDIAN), burst, width, dcmd & PXA_DCMD_LENGTH); 296 + seq_printf(s, "\tDSADR = %08x\n", _phy_readl_relaxed(phy, DSADR)); 297 + seq_printf(s, "\tDTADR = %08x\n", _phy_readl_relaxed(phy, DTADR)); 298 + seq_printf(s, "\tDDADR = %08x\n", _phy_readl_relaxed(phy, DDADR)); 299 + 300 + return 0; 301 + } 302 + 303 + static int dbg_show_state(struct seq_file *s, void *p) 304 + { 305 + struct pxad_device *pdev = s->private; 306 + 307 + /* basic device status */ 308 + seq_puts(s, "DMA engine status\n"); 309 + seq_printf(s, "\tChannel number: %d\n", pdev->nr_chans); 310 + 311 + return 0; 312 + } 313 + 314 + #define DBGFS_FUNC_DECL(name) \ 315 + static int dbg_open_##name(struct inode *inode, struct file *file) \ 316 + { \ 317 + return single_open(file, dbg_show_##name, inode->i_private); \ 318 + } \ 319 + static const struct file_operations dbg_fops_##name = { \ 320 + .owner = THIS_MODULE, \ 321 + .open = dbg_open_##name, \ 322 + .llseek = seq_lseek, \ 323 + .read = seq_read, \ 324 + .release = single_release, \ 325 + } 326 + 327 + DBGFS_FUNC_DECL(state); 328 + DBGFS_FUNC_DECL(chan_state); 329 + DBGFS_FUNC_DECL(descriptors); 330 + DBGFS_FUNC_DECL(requester_chan); 331 + 332 + static struct dentry *pxad_dbg_alloc_chan(struct pxad_device *pdev, 333 + int ch, struct dentry *chandir) 334 + { 335 + char chan_name[11]; 336 + struct dentry *chan, *chan_state = NULL, *chan_descr = NULL; 337 + struct dentry *chan_reqs = NULL; 338 + void *dt; 339 + 340 + scnprintf(chan_name, sizeof(chan_name), "%d", ch); 341 + chan = debugfs_create_dir(chan_name, chandir); 342 + dt = (void *)&pdev->phys[ch]; 343 + 344 + if (chan) 345 + chan_state = debugfs_create_file("state", 0400, chan, dt, 346 + &dbg_fops_chan_state); 347 + if (chan_state) 348 + chan_descr = debugfs_create_file("descriptors", 0400, chan, dt, 349 + &dbg_fops_descriptors); 350 + if (chan_descr) 351 + chan_reqs = debugfs_create_file("requesters", 0400, chan, dt, 352 + &dbg_fops_requester_chan); 353 + if (!chan_reqs) 354 + goto err_state; 355 + 356 + return chan; 357 + 358 + err_state: 359 + debugfs_remove_recursive(chan); 360 + return NULL; 361 + } 362 + 363 + static void pxad_init_debugfs(struct pxad_device *pdev) 364 + { 365 + int i; 366 + struct dentry *chandir; 367 + 368 + pdev->dbgfs_root = debugfs_create_dir(dev_name(pdev->slave.dev), NULL); 369 + if (IS_ERR(pdev->dbgfs_root) || !pdev->dbgfs_root) 370 + goto err_root; 371 + 372 + pdev->dbgfs_state = debugfs_create_file("state", 0400, pdev->dbgfs_root, 373 + pdev, &dbg_fops_state); 374 + if (!pdev->dbgfs_state) 375 + goto err_state; 376 + 377 + pdev->dbgfs_chan = 378 + kmalloc_array(pdev->nr_chans, sizeof(*pdev->dbgfs_state), 379 + GFP_KERNEL); 380 + if (!pdev->dbgfs_chan) 381 + goto err_alloc; 382 + 383 + chandir = debugfs_create_dir("channels", pdev->dbgfs_root); 384 + if (!chandir) 385 + goto err_chandir; 386 + 387 + for (i = 0; i < pdev->nr_chans; i++) { 388 + pdev->dbgfs_chan[i] = pxad_dbg_alloc_chan(pdev, i, chandir); 389 + if (!pdev->dbgfs_chan[i]) 390 + goto err_chans; 391 + } 392 + 393 + return; 394 + err_chans: 395 + err_chandir: 396 + kfree(pdev->dbgfs_chan); 397 + err_alloc: 398 + err_state: 399 + debugfs_remove_recursive(pdev->dbgfs_root); 400 + err_root: 401 + pr_err("pxad: debugfs is not available\n"); 402 + } 403 + 404 + static void pxad_cleanup_debugfs(struct pxad_device *pdev) 405 + { 406 + debugfs_remove_recursive(pdev->dbgfs_root); 407 + } 408 + #else 409 + static inline void pxad_init_debugfs(struct pxad_device *pdev) {} 410 + static inline void pxad_cleanup_debugfs(struct pxad_device *pdev) {} 411 + #endif 412 + 413 + /* 414 + * In the transition phase where legacy pxa handling is done at the same time as 415 + * mmp_dma, the DMA physical channel split between the 2 DMA providers is done 416 + * through legacy_reserved. Legacy code reserves DMA channels by settings 417 + * corresponding bits in legacy_reserved. 418 + */ 419 + static u32 legacy_reserved; 420 + static u32 legacy_unavailable; 421 + 422 + static struct pxad_phy *lookup_phy(struct pxad_chan *pchan) 423 + { 424 + int prio, i; 425 + struct pxad_device *pdev = to_pxad_dev(pchan->vc.chan.device); 426 + struct pxad_phy *phy, *found = NULL; 427 + unsigned long flags; 428 + 429 + /* 430 + * dma channel priorities 431 + * ch 0 - 3, 16 - 19 <--> (0) 432 + * ch 4 - 7, 20 - 23 <--> (1) 433 + * ch 8 - 11, 24 - 27 <--> (2) 434 + * ch 12 - 15, 28 - 31 <--> (3) 435 + */ 436 + 437 + spin_lock_irqsave(&pdev->phy_lock, flags); 438 + for (prio = pchan->prio; prio >= PXAD_PRIO_HIGHEST; prio--) { 439 + for (i = 0; i < pdev->nr_chans; i++) { 440 + if (prio != (i & 0xf) >> 2) 441 + continue; 442 + if ((i < 32) && (legacy_reserved & BIT(i))) 443 + continue; 444 + phy = &pdev->phys[i]; 445 + if (!phy->vchan) { 446 + phy->vchan = pchan; 447 + found = phy; 448 + if (i < 32) 449 + legacy_unavailable |= BIT(i); 450 + goto out_unlock; 451 + } 452 + } 453 + } 454 + 455 + out_unlock: 456 + spin_unlock_irqrestore(&pdev->phy_lock, flags); 457 + dev_dbg(&pchan->vc.chan.dev->device, 458 + "%s(): phy=%p(%d)\n", __func__, found, 459 + found ? found->idx : -1); 460 + 461 + return found; 462 + } 463 + 464 + static void pxad_free_phy(struct pxad_chan *chan) 465 + { 466 + struct pxad_device *pdev = to_pxad_dev(chan->vc.chan.device); 467 + unsigned long flags; 468 + u32 reg; 469 + int i; 470 + 471 + dev_dbg(&chan->vc.chan.dev->device, 472 + "%s(): freeing\n", __func__); 473 + if (!chan->phy) 474 + return; 475 + 476 + /* clear the channel mapping in DRCMR */ 477 + reg = pxad_drcmr(chan->drcmr); 478 + writel_relaxed(0, chan->phy->base + reg); 479 + 480 + spin_lock_irqsave(&pdev->phy_lock, flags); 481 + for (i = 0; i < 32; i++) 482 + if (chan->phy == &pdev->phys[i]) 483 + legacy_unavailable &= ~BIT(i); 484 + chan->phy->vchan = NULL; 485 + chan->phy = NULL; 486 + spin_unlock_irqrestore(&pdev->phy_lock, flags); 487 + } 488 + 489 + static bool is_chan_running(struct pxad_chan *chan) 490 + { 491 + u32 dcsr; 492 + struct pxad_phy *phy = chan->phy; 493 + 494 + if (!phy) 495 + return false; 496 + dcsr = phy_readl_relaxed(phy, DCSR); 497 + return dcsr & PXA_DCSR_RUN; 498 + } 499 + 500 + static bool is_running_chan_misaligned(struct pxad_chan *chan) 501 + { 502 + u32 dalgn; 503 + 504 + BUG_ON(!chan->phy); 505 + dalgn = phy_readl_relaxed(chan->phy, DALGN); 506 + return dalgn & (BIT(chan->phy->idx)); 507 + } 508 + 509 + static void phy_enable(struct pxad_phy *phy, bool misaligned) 510 + { 511 + u32 reg, dalgn; 512 + 513 + if (!phy->vchan) 514 + return; 515 + 516 + dev_dbg(&phy->vchan->vc.chan.dev->device, 517 + "%s(); phy=%p(%d) misaligned=%d\n", __func__, 518 + phy, phy->idx, misaligned); 519 + 520 + reg = pxad_drcmr(phy->vchan->drcmr); 521 + writel_relaxed(DRCMR_MAPVLD | phy->idx, phy->base + reg); 522 + 523 + dalgn = phy_readl_relaxed(phy, DALGN); 524 + if (misaligned) 525 + dalgn |= BIT(phy->idx); 526 + else 527 + dalgn &= ~BIT(phy->idx); 528 + phy_writel_relaxed(phy, dalgn, DALGN); 529 + 530 + phy_writel(phy, PXA_DCSR_STOPIRQEN | PXA_DCSR_ENDINTR | 531 + PXA_DCSR_BUSERR | PXA_DCSR_RUN, DCSR); 532 + } 533 + 534 + static void phy_disable(struct pxad_phy *phy) 535 + { 536 + u32 dcsr; 537 + 538 + if (!phy) 539 + return; 540 + 541 + dcsr = phy_readl_relaxed(phy, DCSR); 542 + dev_dbg(&phy->vchan->vc.chan.dev->device, 543 + "%s(): phy=%p(%d)\n", __func__, phy, phy->idx); 544 + phy_writel(phy, dcsr & ~PXA_DCSR_RUN & ~PXA_DCSR_STOPIRQEN, DCSR); 545 + } 546 + 547 + static void pxad_launch_chan(struct pxad_chan *chan, 548 + struct pxad_desc_sw *desc) 549 + { 550 + dev_dbg(&chan->vc.chan.dev->device, 551 + "%s(): desc=%p\n", __func__, desc); 552 + if (!chan->phy) { 553 + chan->phy = lookup_phy(chan); 554 + if (!chan->phy) { 555 + dev_dbg(&chan->vc.chan.dev->device, 556 + "%s(): no free dma channel\n", __func__); 557 + return; 558 + } 559 + } 560 + 561 + /* 562 + * Program the descriptor's address into the DMA controller, 563 + * then start the DMA transaction 564 + */ 565 + phy_writel(chan->phy, desc->first, DDADR); 566 + phy_enable(chan->phy, chan->misaligned); 567 + } 568 + 569 + static void set_updater_desc(struct pxad_desc_sw *sw_desc, 570 + unsigned long flags) 571 + { 572 + struct pxad_desc_hw *updater = 573 + sw_desc->hw_desc[sw_desc->nb_desc - 1]; 574 + dma_addr_t dma = sw_desc->hw_desc[sw_desc->nb_desc - 2]->ddadr; 575 + 576 + updater->ddadr = DDADR_STOP; 577 + updater->dsadr = dma; 578 + updater->dtadr = dma + 8; 579 + updater->dcmd = PXA_DCMD_WIDTH4 | PXA_DCMD_BURST32 | 580 + (PXA_DCMD_LENGTH & sizeof(u32)); 581 + if (flags & DMA_PREP_INTERRUPT) 582 + updater->dcmd |= PXA_DCMD_ENDIRQEN; 583 + } 584 + 585 + static bool is_desc_completed(struct virt_dma_desc *vd) 586 + { 587 + struct pxad_desc_sw *sw_desc = to_pxad_sw_desc(vd); 588 + struct pxad_desc_hw *updater = 589 + sw_desc->hw_desc[sw_desc->nb_desc - 1]; 590 + 591 + return updater->dtadr != (updater->dsadr + 8); 592 + } 593 + 594 + static void pxad_desc_chain(struct virt_dma_desc *vd1, 595 + struct virt_dma_desc *vd2) 596 + { 597 + struct pxad_desc_sw *desc1 = to_pxad_sw_desc(vd1); 598 + struct pxad_desc_sw *desc2 = to_pxad_sw_desc(vd2); 599 + dma_addr_t dma_to_chain; 600 + 601 + dma_to_chain = desc2->first; 602 + desc1->hw_desc[desc1->nb_desc - 1]->ddadr = dma_to_chain; 603 + } 604 + 605 + static bool pxad_try_hotchain(struct virt_dma_chan *vc, 606 + struct virt_dma_desc *vd) 607 + { 608 + struct virt_dma_desc *vd_last_issued = NULL; 609 + struct pxad_chan *chan = to_pxad_chan(&vc->chan); 610 + 611 + /* 612 + * Attempt to hot chain the tx if the phy is still running. This is 613 + * considered successful only if either the channel is still running 614 + * after the chaining, or if the chained transfer is completed after 615 + * having been hot chained. 616 + * A change of alignment is not allowed, and forbids hotchaining. 617 + */ 618 + if (is_chan_running(chan)) { 619 + BUG_ON(list_empty(&vc->desc_issued)); 620 + 621 + if (!is_running_chan_misaligned(chan) && 622 + to_pxad_sw_desc(vd)->misaligned) 623 + return false; 624 + 625 + vd_last_issued = list_entry(vc->desc_issued.prev, 626 + struct virt_dma_desc, node); 627 + pxad_desc_chain(vd_last_issued, vd); 628 + if (is_chan_running(chan) || is_desc_completed(vd_last_issued)) 629 + return true; 630 + } 631 + 632 + return false; 633 + } 634 + 635 + static unsigned int clear_chan_irq(struct pxad_phy *phy) 636 + { 637 + u32 dcsr; 638 + u32 dint = readl(phy->base + DINT); 639 + 640 + if (!(dint & BIT(phy->idx))) 641 + return PXA_DCSR_RUN; 642 + 643 + /* clear irq */ 644 + dcsr = phy_readl_relaxed(phy, DCSR); 645 + phy_writel(phy, dcsr, DCSR); 646 + if ((dcsr & PXA_DCSR_BUSERR) && (phy->vchan)) 647 + dev_warn(&phy->vchan->vc.chan.dev->device, 648 + "%s(chan=%p): PXA_DCSR_BUSERR\n", 649 + __func__, &phy->vchan); 650 + 651 + return dcsr & ~PXA_DCSR_RUN; 652 + } 653 + 654 + static irqreturn_t pxad_chan_handler(int irq, void *dev_id) 655 + { 656 + struct pxad_phy *phy = dev_id; 657 + struct pxad_chan *chan = phy->vchan; 658 + struct virt_dma_desc *vd, *tmp; 659 + unsigned int dcsr; 660 + unsigned long flags; 661 + 662 + BUG_ON(!chan); 663 + 664 + dcsr = clear_chan_irq(phy); 665 + if (dcsr & PXA_DCSR_RUN) 666 + return IRQ_NONE; 667 + 668 + spin_lock_irqsave(&chan->vc.lock, flags); 669 + list_for_each_entry_safe(vd, tmp, &chan->vc.desc_issued, node) { 670 + dev_dbg(&chan->vc.chan.dev->device, 671 + "%s(): checking txd %p[%x]: completed=%d\n", 672 + __func__, vd, vd->tx.cookie, is_desc_completed(vd)); 673 + if (is_desc_completed(vd)) { 674 + list_del(&vd->node); 675 + vchan_cookie_complete(vd); 676 + } else { 677 + break; 678 + } 679 + } 680 + 681 + if (dcsr & PXA_DCSR_STOPSTATE) { 682 + dev_dbg(&chan->vc.chan.dev->device, 683 + "%s(): channel stopped, submitted_empty=%d issued_empty=%d", 684 + __func__, 685 + list_empty(&chan->vc.desc_submitted), 686 + list_empty(&chan->vc.desc_issued)); 687 + phy_writel_relaxed(phy, dcsr & ~PXA_DCSR_STOPIRQEN, DCSR); 688 + 689 + if (list_empty(&chan->vc.desc_issued)) { 690 + chan->misaligned = 691 + !list_empty(&chan->vc.desc_submitted); 692 + } else { 693 + vd = list_first_entry(&chan->vc.desc_issued, 694 + struct virt_dma_desc, node); 695 + pxad_launch_chan(chan, to_pxad_sw_desc(vd)); 696 + } 697 + } 698 + spin_unlock_irqrestore(&chan->vc.lock, flags); 699 + 700 + return IRQ_HANDLED; 701 + } 702 + 703 + static irqreturn_t pxad_int_handler(int irq, void *dev_id) 704 + { 705 + struct pxad_device *pdev = dev_id; 706 + struct pxad_phy *phy; 707 + u32 dint = readl(pdev->base + DINT); 708 + int i, ret = IRQ_NONE; 709 + 710 + while (dint) { 711 + i = __ffs(dint); 712 + dint &= (dint - 1); 713 + phy = &pdev->phys[i]; 714 + if ((i < 32) && (legacy_reserved & BIT(i))) 715 + continue; 716 + if (pxad_chan_handler(irq, phy) == IRQ_HANDLED) 717 + ret = IRQ_HANDLED; 718 + } 719 + 720 + return ret; 721 + } 722 + 723 + static int pxad_alloc_chan_resources(struct dma_chan *dchan) 724 + { 725 + struct pxad_chan *chan = to_pxad_chan(dchan); 726 + struct pxad_device *pdev = to_pxad_dev(chan->vc.chan.device); 727 + 728 + if (chan->desc_pool) 729 + return 1; 730 + 731 + chan->desc_pool = dma_pool_create(dma_chan_name(dchan), 732 + pdev->slave.dev, 733 + sizeof(struct pxad_desc_hw), 734 + __alignof__(struct pxad_desc_hw), 735 + 0); 736 + if (!chan->desc_pool) { 737 + dev_err(&chan->vc.chan.dev->device, 738 + "%s(): unable to allocate descriptor pool\n", 739 + __func__); 740 + return -ENOMEM; 741 + } 742 + 743 + return 1; 744 + } 745 + 746 + static void pxad_free_chan_resources(struct dma_chan *dchan) 747 + { 748 + struct pxad_chan *chan = to_pxad_chan(dchan); 749 + 750 + vchan_free_chan_resources(&chan->vc); 751 + dma_pool_destroy(chan->desc_pool); 752 + chan->desc_pool = NULL; 753 + 754 + } 755 + 756 + static void pxad_free_desc(struct virt_dma_desc *vd) 757 + { 758 + int i; 759 + dma_addr_t dma; 760 + struct pxad_desc_sw *sw_desc = to_pxad_sw_desc(vd); 761 + 762 + BUG_ON(sw_desc->nb_desc == 0); 763 + for (i = sw_desc->nb_desc - 1; i >= 0; i--) { 764 + if (i > 0) 765 + dma = sw_desc->hw_desc[i - 1]->ddadr; 766 + else 767 + dma = sw_desc->first; 768 + dma_pool_free(sw_desc->desc_pool, 769 + sw_desc->hw_desc[i], dma); 770 + } 771 + sw_desc->nb_desc = 0; 772 + kfree(sw_desc); 773 + } 774 + 775 + static struct pxad_desc_sw * 776 + pxad_alloc_desc(struct pxad_chan *chan, unsigned int nb_hw_desc) 777 + { 778 + struct pxad_desc_sw *sw_desc; 779 + dma_addr_t dma; 780 + int i; 781 + 782 + sw_desc = kzalloc(sizeof(*sw_desc) + 783 + nb_hw_desc * sizeof(struct pxad_desc_hw *), 784 + GFP_NOWAIT); 785 + if (!sw_desc) 786 + return NULL; 787 + sw_desc->desc_pool = chan->desc_pool; 788 + 789 + for (i = 0; i < nb_hw_desc; i++) { 790 + sw_desc->hw_desc[i] = dma_pool_alloc(sw_desc->desc_pool, 791 + GFP_NOWAIT, &dma); 792 + if (!sw_desc->hw_desc[i]) { 793 + dev_err(&chan->vc.chan.dev->device, 794 + "%s(): Couldn't allocate the %dth hw_desc from dma_pool %p\n", 795 + __func__, i, sw_desc->desc_pool); 796 + goto err; 797 + } 798 + 799 + if (i == 0) 800 + sw_desc->first = dma; 801 + else 802 + sw_desc->hw_desc[i - 1]->ddadr = dma; 803 + sw_desc->nb_desc++; 804 + } 805 + 806 + return sw_desc; 807 + err: 808 + pxad_free_desc(&sw_desc->vd); 809 + return NULL; 810 + } 811 + 812 + static dma_cookie_t pxad_tx_submit(struct dma_async_tx_descriptor *tx) 813 + { 814 + struct virt_dma_chan *vc = to_virt_chan(tx->chan); 815 + struct pxad_chan *chan = to_pxad_chan(&vc->chan); 816 + struct virt_dma_desc *vd_chained = NULL, 817 + *vd = container_of(tx, struct virt_dma_desc, tx); 818 + dma_cookie_t cookie; 819 + unsigned long flags; 820 + 821 + set_updater_desc(to_pxad_sw_desc(vd), tx->flags); 822 + 823 + spin_lock_irqsave(&vc->lock, flags); 824 + cookie = dma_cookie_assign(tx); 825 + 826 + if (list_empty(&vc->desc_submitted) && pxad_try_hotchain(vc, vd)) { 827 + list_move_tail(&vd->node, &vc->desc_issued); 828 + dev_dbg(&chan->vc.chan.dev->device, 829 + "%s(): txd %p[%x]: submitted (hot linked)\n", 830 + __func__, vd, cookie); 831 + goto out; 832 + } 833 + 834 + /* 835 + * Fallback to placing the tx in the submitted queue 836 + */ 837 + if (!list_empty(&vc->desc_submitted)) { 838 + vd_chained = list_entry(vc->desc_submitted.prev, 839 + struct virt_dma_desc, node); 840 + /* 841 + * Only chain the descriptors if no new misalignment is 842 + * introduced. If a new misalignment is chained, let the channel 843 + * stop, and be relaunched in misalign mode from the irq 844 + * handler. 845 + */ 846 + if (chan->misaligned || !to_pxad_sw_desc(vd)->misaligned) 847 + pxad_desc_chain(vd_chained, vd); 848 + else 849 + vd_chained = NULL; 850 + } 851 + dev_dbg(&chan->vc.chan.dev->device, 852 + "%s(): txd %p[%x]: submitted (%s linked)\n", 853 + __func__, vd, cookie, vd_chained ? "cold" : "not"); 854 + list_move_tail(&vd->node, &vc->desc_submitted); 855 + chan->misaligned |= to_pxad_sw_desc(vd)->misaligned; 856 + 857 + out: 858 + spin_unlock_irqrestore(&vc->lock, flags); 859 + return cookie; 860 + } 861 + 862 + static void pxad_issue_pending(struct dma_chan *dchan) 863 + { 864 + struct pxad_chan *chan = to_pxad_chan(dchan); 865 + struct virt_dma_desc *vd_first; 866 + unsigned long flags; 867 + 868 + spin_lock_irqsave(&chan->vc.lock, flags); 869 + if (list_empty(&chan->vc.desc_submitted)) 870 + goto out; 871 + 872 + vd_first = list_first_entry(&chan->vc.desc_submitted, 873 + struct virt_dma_desc, node); 874 + dev_dbg(&chan->vc.chan.dev->device, 875 + "%s(): txd %p[%x]", __func__, vd_first, vd_first->tx.cookie); 876 + 877 + vchan_issue_pending(&chan->vc); 878 + if (!pxad_try_hotchain(&chan->vc, vd_first)) 879 + pxad_launch_chan(chan, to_pxad_sw_desc(vd_first)); 880 + out: 881 + spin_unlock_irqrestore(&chan->vc.lock, flags); 882 + } 883 + 884 + static inline struct dma_async_tx_descriptor * 885 + pxad_tx_prep(struct virt_dma_chan *vc, struct virt_dma_desc *vd, 886 + unsigned long tx_flags) 887 + { 888 + struct dma_async_tx_descriptor *tx; 889 + struct pxad_chan *chan = container_of(vc, struct pxad_chan, vc); 890 + 891 + tx = vchan_tx_prep(vc, vd, tx_flags); 892 + tx->tx_submit = pxad_tx_submit; 893 + dev_dbg(&chan->vc.chan.dev->device, 894 + "%s(): vc=%p txd=%p[%x] flags=0x%lx\n", __func__, 895 + vc, vd, vd->tx.cookie, 896 + tx_flags); 897 + 898 + return tx; 899 + } 900 + 901 + static void pxad_get_config(struct pxad_chan *chan, 902 + enum dma_transfer_direction dir, 903 + u32 *dcmd, u32 *dev_src, u32 *dev_dst) 904 + { 905 + u32 maxburst = 0, dev_addr = 0; 906 + enum dma_slave_buswidth width = DMA_SLAVE_BUSWIDTH_UNDEFINED; 907 + 908 + *dcmd = 0; 909 + if (chan->cfg.direction == DMA_DEV_TO_MEM) { 910 + maxburst = chan->cfg.src_maxburst; 911 + width = chan->cfg.src_addr_width; 912 + dev_addr = chan->cfg.src_addr; 913 + *dev_src = dev_addr; 914 + *dcmd |= PXA_DCMD_INCTRGADDR | PXA_DCMD_FLOWSRC; 915 + } 916 + if (chan->cfg.direction == DMA_MEM_TO_DEV) { 917 + maxburst = chan->cfg.dst_maxburst; 918 + width = chan->cfg.dst_addr_width; 919 + dev_addr = chan->cfg.dst_addr; 920 + *dev_dst = dev_addr; 921 + *dcmd |= PXA_DCMD_INCSRCADDR | PXA_DCMD_FLOWTRG; 922 + } 923 + if (chan->cfg.direction == DMA_MEM_TO_MEM) 924 + *dcmd |= PXA_DCMD_BURST32 | PXA_DCMD_INCTRGADDR | 925 + PXA_DCMD_INCSRCADDR; 926 + 927 + dev_dbg(&chan->vc.chan.dev->device, 928 + "%s(): dev_addr=0x%x maxburst=%d width=%d dir=%d\n", 929 + __func__, dev_addr, maxburst, width, dir); 930 + 931 + if (width == DMA_SLAVE_BUSWIDTH_1_BYTE) 932 + *dcmd |= PXA_DCMD_WIDTH1; 933 + else if (width == DMA_SLAVE_BUSWIDTH_2_BYTES) 934 + *dcmd |= PXA_DCMD_WIDTH2; 935 + else if (width == DMA_SLAVE_BUSWIDTH_4_BYTES) 936 + *dcmd |= PXA_DCMD_WIDTH4; 937 + 938 + if (maxburst == 8) 939 + *dcmd |= PXA_DCMD_BURST8; 940 + else if (maxburst == 16) 941 + *dcmd |= PXA_DCMD_BURST16; 942 + else if (maxburst == 32) 943 + *dcmd |= PXA_DCMD_BURST32; 944 + 945 + /* FIXME: drivers should be ported over to use the filter 946 + * function. Once that's done, the following two lines can 947 + * be removed. 948 + */ 949 + if (chan->cfg.slave_id) 950 + chan->drcmr = chan->cfg.slave_id; 951 + } 952 + 953 + static struct dma_async_tx_descriptor * 954 + pxad_prep_memcpy(struct dma_chan *dchan, 955 + dma_addr_t dma_dst, dma_addr_t dma_src, 956 + size_t len, unsigned long flags) 957 + { 958 + struct pxad_chan *chan = to_pxad_chan(dchan); 959 + struct pxad_desc_sw *sw_desc; 960 + struct pxad_desc_hw *hw_desc; 961 + u32 dcmd; 962 + unsigned int i, nb_desc = 0; 963 + size_t copy; 964 + 965 + if (!dchan || !len) 966 + return NULL; 967 + 968 + dev_dbg(&chan->vc.chan.dev->device, 969 + "%s(): dma_dst=0x%lx dma_src=0x%lx len=%zu flags=%lx\n", 970 + __func__, (unsigned long)dma_dst, (unsigned long)dma_src, 971 + len, flags); 972 + pxad_get_config(chan, DMA_MEM_TO_MEM, &dcmd, NULL, NULL); 973 + 974 + nb_desc = DIV_ROUND_UP(len, PDMA_MAX_DESC_BYTES); 975 + sw_desc = pxad_alloc_desc(chan, nb_desc + 1); 976 + if (!sw_desc) 977 + return NULL; 978 + sw_desc->len = len; 979 + 980 + if (!IS_ALIGNED(dma_src, 1 << PDMA_ALIGNMENT) || 981 + !IS_ALIGNED(dma_dst, 1 << PDMA_ALIGNMENT)) 982 + sw_desc->misaligned = true; 983 + 984 + i = 0; 985 + do { 986 + hw_desc = sw_desc->hw_desc[i++]; 987 + copy = min_t(size_t, len, PDMA_MAX_DESC_BYTES); 988 + hw_desc->dcmd = dcmd | (PXA_DCMD_LENGTH & copy); 989 + hw_desc->dsadr = dma_src; 990 + hw_desc->dtadr = dma_dst; 991 + len -= copy; 992 + dma_src += copy; 993 + dma_dst += copy; 994 + } while (len); 995 + set_updater_desc(sw_desc, flags); 996 + 997 + return pxad_tx_prep(&chan->vc, &sw_desc->vd, flags); 998 + } 999 + 1000 + static struct dma_async_tx_descriptor * 1001 + pxad_prep_slave_sg(struct dma_chan *dchan, struct scatterlist *sgl, 1002 + unsigned int sg_len, enum dma_transfer_direction dir, 1003 + unsigned long flags, void *context) 1004 + { 1005 + struct pxad_chan *chan = to_pxad_chan(dchan); 1006 + struct pxad_desc_sw *sw_desc; 1007 + size_t len, avail; 1008 + struct scatterlist *sg; 1009 + dma_addr_t dma; 1010 + u32 dcmd, dsadr = 0, dtadr = 0; 1011 + unsigned int nb_desc = 0, i, j = 0; 1012 + 1013 + if ((sgl == NULL) || (sg_len == 0)) 1014 + return NULL; 1015 + 1016 + pxad_get_config(chan, dir, &dcmd, &dsadr, &dtadr); 1017 + dev_dbg(&chan->vc.chan.dev->device, 1018 + "%s(): dir=%d flags=%lx\n", __func__, dir, flags); 1019 + 1020 + for_each_sg(sgl, sg, sg_len, i) 1021 + nb_desc += DIV_ROUND_UP(sg_dma_len(sg), PDMA_MAX_DESC_BYTES); 1022 + sw_desc = pxad_alloc_desc(chan, nb_desc + 1); 1023 + if (!sw_desc) 1024 + return NULL; 1025 + 1026 + for_each_sg(sgl, sg, sg_len, i) { 1027 + dma = sg_dma_address(sg); 1028 + avail = sg_dma_len(sg); 1029 + sw_desc->len += avail; 1030 + 1031 + do { 1032 + len = min_t(size_t, avail, PDMA_MAX_DESC_BYTES); 1033 + if (dma & 0x7) 1034 + sw_desc->misaligned = true; 1035 + 1036 + sw_desc->hw_desc[j]->dcmd = 1037 + dcmd | (PXA_DCMD_LENGTH & len); 1038 + sw_desc->hw_desc[j]->dsadr = dsadr ? dsadr : dma; 1039 + sw_desc->hw_desc[j++]->dtadr = dtadr ? dtadr : dma; 1040 + 1041 + dma += len; 1042 + avail -= len; 1043 + } while (avail); 1044 + } 1045 + set_updater_desc(sw_desc, flags); 1046 + 1047 + return pxad_tx_prep(&chan->vc, &sw_desc->vd, flags); 1048 + } 1049 + 1050 + static struct dma_async_tx_descriptor * 1051 + pxad_prep_dma_cyclic(struct dma_chan *dchan, 1052 + dma_addr_t buf_addr, size_t len, size_t period_len, 1053 + enum dma_transfer_direction dir, unsigned long flags) 1054 + { 1055 + struct pxad_chan *chan = to_pxad_chan(dchan); 1056 + struct pxad_desc_sw *sw_desc; 1057 + struct pxad_desc_hw **phw_desc; 1058 + dma_addr_t dma; 1059 + u32 dcmd, dsadr = 0, dtadr = 0; 1060 + unsigned int nb_desc = 0; 1061 + 1062 + if (!dchan || !len || !period_len) 1063 + return NULL; 1064 + if ((dir != DMA_DEV_TO_MEM) && (dir != DMA_MEM_TO_DEV)) { 1065 + dev_err(&chan->vc.chan.dev->device, 1066 + "Unsupported direction for cyclic DMA\n"); 1067 + return NULL; 1068 + } 1069 + /* the buffer length must be a multiple of period_len */ 1070 + if (len % period_len != 0 || period_len > PDMA_MAX_DESC_BYTES || 1071 + !IS_ALIGNED(period_len, 1 << PDMA_ALIGNMENT)) 1072 + return NULL; 1073 + 1074 + pxad_get_config(chan, dir, &dcmd, &dsadr, &dtadr); 1075 + dcmd |= PXA_DCMD_ENDIRQEN | (PXA_DCMD_LENGTH | period_len); 1076 + dev_dbg(&chan->vc.chan.dev->device, 1077 + "%s(): buf_addr=0x%lx len=%zu period=%zu dir=%d flags=%lx\n", 1078 + __func__, (unsigned long)buf_addr, len, period_len, dir, flags); 1079 + 1080 + nb_desc = DIV_ROUND_UP(period_len, PDMA_MAX_DESC_BYTES); 1081 + nb_desc *= DIV_ROUND_UP(len, period_len); 1082 + sw_desc = pxad_alloc_desc(chan, nb_desc + 1); 1083 + if (!sw_desc) 1084 + return NULL; 1085 + sw_desc->cyclic = true; 1086 + sw_desc->len = len; 1087 + 1088 + phw_desc = sw_desc->hw_desc; 1089 + dma = buf_addr; 1090 + do { 1091 + phw_desc[0]->dsadr = dsadr ? dsadr : dma; 1092 + phw_desc[0]->dtadr = dtadr ? dtadr : dma; 1093 + phw_desc[0]->dcmd = dcmd; 1094 + phw_desc++; 1095 + dma += period_len; 1096 + len -= period_len; 1097 + } while (len); 1098 + set_updater_desc(sw_desc, flags); 1099 + 1100 + return pxad_tx_prep(&chan->vc, &sw_desc->vd, flags); 1101 + } 1102 + 1103 + static int pxad_config(struct dma_chan *dchan, 1104 + struct dma_slave_config *cfg) 1105 + { 1106 + struct pxad_chan *chan = to_pxad_chan(dchan); 1107 + 1108 + if (!dchan) 1109 + return -EINVAL; 1110 + 1111 + chan->cfg = *cfg; 1112 + return 0; 1113 + } 1114 + 1115 + static int pxad_terminate_all(struct dma_chan *dchan) 1116 + { 1117 + struct pxad_chan *chan = to_pxad_chan(dchan); 1118 + struct pxad_device *pdev = to_pxad_dev(chan->vc.chan.device); 1119 + struct virt_dma_desc *vd = NULL; 1120 + unsigned long flags; 1121 + struct pxad_phy *phy; 1122 + LIST_HEAD(head); 1123 + 1124 + dev_dbg(&chan->vc.chan.dev->device, 1125 + "%s(): vchan %p: terminate all\n", __func__, &chan->vc); 1126 + 1127 + spin_lock_irqsave(&chan->vc.lock, flags); 1128 + vchan_get_all_descriptors(&chan->vc, &head); 1129 + 1130 + list_for_each_entry(vd, &head, node) { 1131 + dev_dbg(&chan->vc.chan.dev->device, 1132 + "%s(): cancelling txd %p[%x] (completed=%d)", __func__, 1133 + vd, vd->tx.cookie, is_desc_completed(vd)); 1134 + } 1135 + 1136 + phy = chan->phy; 1137 + if (phy) { 1138 + phy_disable(chan->phy); 1139 + pxad_free_phy(chan); 1140 + chan->phy = NULL; 1141 + spin_lock(&pdev->phy_lock); 1142 + phy->vchan = NULL; 1143 + spin_unlock(&pdev->phy_lock); 1144 + } 1145 + spin_unlock_irqrestore(&chan->vc.lock, flags); 1146 + vchan_dma_desc_free_list(&chan->vc, &head); 1147 + 1148 + return 0; 1149 + } 1150 + 1151 + static unsigned int pxad_residue(struct pxad_chan *chan, 1152 + dma_cookie_t cookie) 1153 + { 1154 + struct virt_dma_desc *vd = NULL; 1155 + struct pxad_desc_sw *sw_desc = NULL; 1156 + struct pxad_desc_hw *hw_desc = NULL; 1157 + u32 curr, start, len, end, residue = 0; 1158 + unsigned long flags; 1159 + bool passed = false; 1160 + int i; 1161 + 1162 + /* 1163 + * If the channel does not have a phy pointer anymore, it has already 1164 + * been completed. Therefore, its residue is 0. 1165 + */ 1166 + if (!chan->phy) 1167 + return 0; 1168 + 1169 + spin_lock_irqsave(&chan->vc.lock, flags); 1170 + 1171 + vd = vchan_find_desc(&chan->vc, cookie); 1172 + if (!vd) 1173 + goto out; 1174 + 1175 + sw_desc = to_pxad_sw_desc(vd); 1176 + if (sw_desc->hw_desc[0]->dcmd & PXA_DCMD_INCSRCADDR) 1177 + curr = phy_readl_relaxed(chan->phy, DSADR); 1178 + else 1179 + curr = phy_readl_relaxed(chan->phy, DTADR); 1180 + 1181 + for (i = 0; i < sw_desc->nb_desc - 1; i++) { 1182 + hw_desc = sw_desc->hw_desc[i]; 1183 + if (sw_desc->hw_desc[0]->dcmd & PXA_DCMD_INCSRCADDR) 1184 + start = hw_desc->dsadr; 1185 + else 1186 + start = hw_desc->dtadr; 1187 + len = hw_desc->dcmd & PXA_DCMD_LENGTH; 1188 + end = start + len; 1189 + 1190 + /* 1191 + * 'passed' will be latched once we found the descriptor 1192 + * which lies inside the boundaries of the curr 1193 + * pointer. All descriptors that occur in the list 1194 + * _after_ we found that partially handled descriptor 1195 + * are still to be processed and are hence added to the 1196 + * residual bytes counter. 1197 + */ 1198 + 1199 + if (passed) { 1200 + residue += len; 1201 + } else if (curr >= start && curr <= end) { 1202 + residue += end - curr; 1203 + passed = true; 1204 + } 1205 + } 1206 + if (!passed) 1207 + residue = sw_desc->len; 1208 + 1209 + out: 1210 + spin_unlock_irqrestore(&chan->vc.lock, flags); 1211 + dev_dbg(&chan->vc.chan.dev->device, 1212 + "%s(): txd %p[%x] sw_desc=%p: %d\n", 1213 + __func__, vd, cookie, sw_desc, residue); 1214 + return residue; 1215 + } 1216 + 1217 + static enum dma_status pxad_tx_status(struct dma_chan *dchan, 1218 + dma_cookie_t cookie, 1219 + struct dma_tx_state *txstate) 1220 + { 1221 + struct pxad_chan *chan = to_pxad_chan(dchan); 1222 + enum dma_status ret; 1223 + 1224 + ret = dma_cookie_status(dchan, cookie, txstate); 1225 + if (likely(txstate && (ret != DMA_ERROR))) 1226 + dma_set_residue(txstate, pxad_residue(chan, cookie)); 1227 + 1228 + return ret; 1229 + } 1230 + 1231 + static void pxad_free_channels(struct dma_device *dmadev) 1232 + { 1233 + struct pxad_chan *c, *cn; 1234 + 1235 + list_for_each_entry_safe(c, cn, &dmadev->channels, 1236 + vc.chan.device_node) { 1237 + list_del(&c->vc.chan.device_node); 1238 + tasklet_kill(&c->vc.task); 1239 + } 1240 + } 1241 + 1242 + static int pxad_remove(struct platform_device *op) 1243 + { 1244 + struct pxad_device *pdev = platform_get_drvdata(op); 1245 + 1246 + pxad_cleanup_debugfs(pdev); 1247 + pxad_free_channels(&pdev->slave); 1248 + dma_async_device_unregister(&pdev->slave); 1249 + return 0; 1250 + } 1251 + 1252 + static int pxad_init_phys(struct platform_device *op, 1253 + struct pxad_device *pdev, 1254 + unsigned int nb_phy_chans) 1255 + { 1256 + int irq0, irq, nr_irq = 0, i, ret; 1257 + struct pxad_phy *phy; 1258 + 1259 + irq0 = platform_get_irq(op, 0); 1260 + if (irq0 < 0) 1261 + return irq0; 1262 + 1263 + pdev->phys = devm_kcalloc(&op->dev, nb_phy_chans, 1264 + sizeof(pdev->phys[0]), GFP_KERNEL); 1265 + if (!pdev->phys) 1266 + return -ENOMEM; 1267 + 1268 + for (i = 0; i < nb_phy_chans; i++) 1269 + if (platform_get_irq(op, i) > 0) 1270 + nr_irq++; 1271 + 1272 + for (i = 0; i < nb_phy_chans; i++) { 1273 + phy = &pdev->phys[i]; 1274 + phy->base = pdev->base; 1275 + phy->idx = i; 1276 + irq = platform_get_irq(op, i); 1277 + if ((nr_irq > 1) && (irq > 0)) 1278 + ret = devm_request_irq(&op->dev, irq, 1279 + pxad_chan_handler, 1280 + IRQF_SHARED, "pxa-dma", phy); 1281 + if ((nr_irq == 1) && (i == 0)) 1282 + ret = devm_request_irq(&op->dev, irq0, 1283 + pxad_int_handler, 1284 + IRQF_SHARED, "pxa-dma", pdev); 1285 + if (ret) { 1286 + dev_err(pdev->slave.dev, 1287 + "%s(): can't request irq %d:%d\n", __func__, 1288 + irq, ret); 1289 + return ret; 1290 + } 1291 + } 1292 + 1293 + return 0; 1294 + } 1295 + 1296 + static const struct of_device_id const pxad_dt_ids[] = { 1297 + { .compatible = "marvell,pdma-1.0", }, 1298 + {} 1299 + }; 1300 + MODULE_DEVICE_TABLE(of, pxad_dt_ids); 1301 + 1302 + static struct dma_chan *pxad_dma_xlate(struct of_phandle_args *dma_spec, 1303 + struct of_dma *ofdma) 1304 + { 1305 + struct pxad_device *d = ofdma->of_dma_data; 1306 + struct dma_chan *chan; 1307 + 1308 + chan = dma_get_any_slave_channel(&d->slave); 1309 + if (!chan) 1310 + return NULL; 1311 + 1312 + to_pxad_chan(chan)->drcmr = dma_spec->args[0]; 1313 + to_pxad_chan(chan)->prio = dma_spec->args[1]; 1314 + 1315 + return chan; 1316 + } 1317 + 1318 + static int pxad_init_dmadev(struct platform_device *op, 1319 + struct pxad_device *pdev, 1320 + unsigned int nr_phy_chans) 1321 + { 1322 + int ret; 1323 + unsigned int i; 1324 + struct pxad_chan *c; 1325 + 1326 + pdev->nr_chans = nr_phy_chans; 1327 + INIT_LIST_HEAD(&pdev->slave.channels); 1328 + pdev->slave.device_alloc_chan_resources = pxad_alloc_chan_resources; 1329 + pdev->slave.device_free_chan_resources = pxad_free_chan_resources; 1330 + pdev->slave.device_tx_status = pxad_tx_status; 1331 + pdev->slave.device_issue_pending = pxad_issue_pending; 1332 + pdev->slave.device_config = pxad_config; 1333 + pdev->slave.device_terminate_all = pxad_terminate_all; 1334 + 1335 + if (op->dev.coherent_dma_mask) 1336 + dma_set_mask(&op->dev, op->dev.coherent_dma_mask); 1337 + else 1338 + dma_set_mask(&op->dev, DMA_BIT_MASK(32)); 1339 + 1340 + ret = pxad_init_phys(op, pdev, nr_phy_chans); 1341 + if (ret) 1342 + return ret; 1343 + 1344 + for (i = 0; i < nr_phy_chans; i++) { 1345 + c = devm_kzalloc(&op->dev, sizeof(*c), GFP_KERNEL); 1346 + if (!c) 1347 + return -ENOMEM; 1348 + c->vc.desc_free = pxad_free_desc; 1349 + vchan_init(&c->vc, &pdev->slave); 1350 + } 1351 + 1352 + return dma_async_device_register(&pdev->slave); 1353 + } 1354 + 1355 + static int pxad_probe(struct platform_device *op) 1356 + { 1357 + struct pxad_device *pdev; 1358 + const struct of_device_id *of_id; 1359 + struct mmp_dma_platdata *pdata = dev_get_platdata(&op->dev); 1360 + struct resource *iores; 1361 + int ret, dma_channels = 0; 1362 + const enum dma_slave_buswidth widths = 1363 + DMA_SLAVE_BUSWIDTH_1_BYTE | DMA_SLAVE_BUSWIDTH_2_BYTES | 1364 + DMA_SLAVE_BUSWIDTH_4_BYTES; 1365 + 1366 + pdev = devm_kzalloc(&op->dev, sizeof(*pdev), GFP_KERNEL); 1367 + if (!pdev) 1368 + return -ENOMEM; 1369 + 1370 + spin_lock_init(&pdev->phy_lock); 1371 + 1372 + iores = platform_get_resource(op, IORESOURCE_MEM, 0); 1373 + pdev->base = devm_ioremap_resource(&op->dev, iores); 1374 + if (IS_ERR(pdev->base)) 1375 + return PTR_ERR(pdev->base); 1376 + 1377 + of_id = of_match_device(pxad_dt_ids, &op->dev); 1378 + if (of_id) 1379 + of_property_read_u32(op->dev.of_node, "#dma-channels", 1380 + &dma_channels); 1381 + else if (pdata && pdata->dma_channels) 1382 + dma_channels = pdata->dma_channels; 1383 + else 1384 + dma_channels = 32; /* default 32 channel */ 1385 + 1386 + dma_cap_set(DMA_SLAVE, pdev->slave.cap_mask); 1387 + dma_cap_set(DMA_MEMCPY, pdev->slave.cap_mask); 1388 + dma_cap_set(DMA_CYCLIC, pdev->slave.cap_mask); 1389 + dma_cap_set(DMA_PRIVATE, pdev->slave.cap_mask); 1390 + pdev->slave.device_prep_dma_memcpy = pxad_prep_memcpy; 1391 + pdev->slave.device_prep_slave_sg = pxad_prep_slave_sg; 1392 + pdev->slave.device_prep_dma_cyclic = pxad_prep_dma_cyclic; 1393 + 1394 + pdev->slave.copy_align = PDMA_ALIGNMENT; 1395 + pdev->slave.src_addr_widths = widths; 1396 + pdev->slave.dst_addr_widths = widths; 1397 + pdev->slave.directions = BIT(DMA_MEM_TO_DEV) | BIT(DMA_DEV_TO_MEM); 1398 + pdev->slave.residue_granularity = DMA_RESIDUE_GRANULARITY_DESCRIPTOR; 1399 + 1400 + pdev->slave.dev = &op->dev; 1401 + ret = pxad_init_dmadev(op, pdev, dma_channels); 1402 + if (ret) { 1403 + dev_err(pdev->slave.dev, "unable to register\n"); 1404 + return ret; 1405 + } 1406 + 1407 + if (op->dev.of_node) { 1408 + /* Device-tree DMA controller registration */ 1409 + ret = of_dma_controller_register(op->dev.of_node, 1410 + pxad_dma_xlate, pdev); 1411 + if (ret < 0) { 1412 + dev_err(pdev->slave.dev, 1413 + "of_dma_controller_register failed\n"); 1414 + return ret; 1415 + } 1416 + } 1417 + 1418 + platform_set_drvdata(op, pdev); 1419 + pxad_init_debugfs(pdev); 1420 + dev_info(pdev->slave.dev, "initialized %d channels\n", dma_channels); 1421 + return 0; 1422 + } 1423 + 1424 + static const struct platform_device_id pxad_id_table[] = { 1425 + { "pxa-dma", }, 1426 + { }, 1427 + }; 1428 + 1429 + static struct platform_driver pxad_driver = { 1430 + .driver = { 1431 + .name = "pxa-dma", 1432 + .of_match_table = pxad_dt_ids, 1433 + }, 1434 + .id_table = pxad_id_table, 1435 + .probe = pxad_probe, 1436 + .remove = pxad_remove, 1437 + }; 1438 + 1439 + bool pxad_filter_fn(struct dma_chan *chan, void *param) 1440 + { 1441 + struct pxad_chan *c = to_pxad_chan(chan); 1442 + struct pxad_param *p = param; 1443 + 1444 + if (chan->device->dev->driver != &pxad_driver.driver) 1445 + return false; 1446 + 1447 + c->drcmr = p->drcmr; 1448 + c->prio = p->prio; 1449 + 1450 + return true; 1451 + } 1452 + EXPORT_SYMBOL_GPL(pxad_filter_fn); 1453 + 1454 + int pxad_toggle_reserved_channel(int legacy_channel) 1455 + { 1456 + if (legacy_unavailable & (BIT(legacy_channel))) 1457 + return -EBUSY; 1458 + legacy_reserved ^= BIT(legacy_channel); 1459 + return 0; 1460 + } 1461 + EXPORT_SYMBOL_GPL(pxad_toggle_reserved_channel); 1462 + 1463 + module_platform_driver(pxad_driver); 1464 + 1465 + MODULE_DESCRIPTION("Marvell PXA Peripheral DMA Driver"); 1466 + MODULE_AUTHOR("Robert Jarzmik <robert.jarzmik@free.fr>"); 1467 + MODULE_LICENSE("GPL v2");
+1 -1
drivers/dma/s3c24xx-dma.c
··· 1168 1168 .has_clocks = true, 1169 1169 }; 1170 1170 1171 - static struct platform_device_id s3c24xx_dma_driver_ids[] = { 1171 + static const struct platform_device_id s3c24xx_dma_driver_ids[] = { 1172 1172 { 1173 1173 .name = "s3c2410-dma", 1174 1174 .driver_data = (kernel_ulong_t)&soc_s3c2410,
+1 -1
drivers/dma/sh/rcar-dmac.c
··· 183 183 unsigned int n_channels; 184 184 struct rcar_dmac_chan *channels; 185 185 186 - unsigned long modules[256 / BITS_PER_LONG]; 186 + DECLARE_BITMAP(modules, 256); 187 187 }; 188 188 189 189 #define to_rcar_dmac(d) container_of(d, struct rcar_dmac, engine)
+1 -1
drivers/dma/sh/shdma-r8a73a4.c
··· 11 11 12 12 #include "shdma-arm.h" 13 13 14 - const unsigned int dma_ts_shift[] = SH_DMAE_TS_SHIFT; 14 + static const unsigned int dma_ts_shift[] = SH_DMAE_TS_SHIFT; 15 15 16 16 static const struct sh_dmae_slave_config dma_slaves[] = { 17 17 {
+334 -89
drivers/dma/sirf-dma.c
··· 23 23 24 24 #include "dmaengine.h" 25 25 26 + #define SIRFSOC_DMA_VER_A7V1 1 27 + #define SIRFSOC_DMA_VER_A7V2 2 28 + #define SIRFSOC_DMA_VER_A6 4 29 + 26 30 #define SIRFSOC_DMA_DESCRIPTORS 16 27 31 #define SIRFSOC_DMA_CHANNELS 16 32 + #define SIRFSOC_DMA_TABLE_NUM 256 28 33 29 34 #define SIRFSOC_DMA_CH_ADDR 0x00 30 35 #define SIRFSOC_DMA_CH_XLEN 0x04 ··· 40 35 #define SIRFSOC_DMA_CH_VALID 0x140 41 36 #define SIRFSOC_DMA_CH_INT 0x144 42 37 #define SIRFSOC_DMA_INT_EN 0x148 43 - #define SIRFSOC_DMA_INT_EN_CLR 0x14C 38 + #define SIRFSOC_DMA_INT_EN_CLR 0x14C 44 39 #define SIRFSOC_DMA_CH_LOOP_CTRL 0x150 45 - #define SIRFSOC_DMA_CH_LOOP_CTRL_CLR 0x15C 40 + #define SIRFSOC_DMA_CH_LOOP_CTRL_CLR 0x154 41 + #define SIRFSOC_DMA_WIDTH_ATLAS7 0x10 42 + #define SIRFSOC_DMA_VALID_ATLAS7 0x14 43 + #define SIRFSOC_DMA_INT_ATLAS7 0x18 44 + #define SIRFSOC_DMA_INT_EN_ATLAS7 0x1c 45 + #define SIRFSOC_DMA_LOOP_CTRL_ATLAS7 0x20 46 + #define SIRFSOC_DMA_CUR_DATA_ADDR 0x34 47 + #define SIRFSOC_DMA_MUL_ATLAS7 0x38 48 + #define SIRFSOC_DMA_CH_LOOP_CTRL_ATLAS7 0x158 49 + #define SIRFSOC_DMA_CH_LOOP_CTRL_CLR_ATLAS7 0x15C 50 + #define SIRFSOC_DMA_IOBG_SCMD_EN 0x800 51 + #define SIRFSOC_DMA_EARLY_RESP_SET 0x818 52 + #define SIRFSOC_DMA_EARLY_RESP_CLR 0x81C 46 53 47 54 #define SIRFSOC_DMA_MODE_CTRL_BIT 4 48 55 #define SIRFSOC_DMA_DIR_CTRL_BIT 5 56 + #define SIRFSOC_DMA_MODE_CTRL_BIT_ATLAS7 2 57 + #define SIRFSOC_DMA_CHAIN_CTRL_BIT_ATLAS7 3 58 + #define SIRFSOC_DMA_DIR_CTRL_BIT_ATLAS7 4 59 + #define SIRFSOC_DMA_TAB_NUM_ATLAS7 7 60 + #define SIRFSOC_DMA_CHAIN_INT_BIT_ATLAS7 5 61 + #define SIRFSOC_DMA_CHAIN_FLAG_SHIFT_ATLAS7 25 62 + #define SIRFSOC_DMA_CHAIN_ADDR_SHIFT 32 63 + 64 + #define SIRFSOC_DMA_INT_FINI_INT_ATLAS7 BIT(0) 65 + #define SIRFSOC_DMA_INT_CNT_INT_ATLAS7 BIT(1) 66 + #define SIRFSOC_DMA_INT_PAU_INT_ATLAS7 BIT(2) 67 + #define SIRFSOC_DMA_INT_LOOP_INT_ATLAS7 BIT(3) 68 + #define SIRFSOC_DMA_INT_INV_INT_ATLAS7 BIT(4) 69 + #define SIRFSOC_DMA_INT_END_INT_ATLAS7 BIT(5) 70 + #define SIRFSOC_DMA_INT_ALL_ATLAS7 0x3F 49 71 50 72 /* xlen and dma_width register is in 4 bytes boundary */ 51 73 #define SIRFSOC_DMA_WORD_LEN 4 74 + #define SIRFSOC_DMA_XLEN_MAX_V1 0x800 75 + #define SIRFSOC_DMA_XLEN_MAX_V2 0x1000 52 76 53 77 struct sirfsoc_dma_desc { 54 78 struct dma_async_tx_descriptor desc; ··· 90 56 int width; /* DMA width */ 91 57 int dir; 92 58 bool cyclic; /* is loop DMA? */ 59 + bool chain; /* is chain DMA? */ 93 60 u32 addr; /* DMA buffer address */ 61 + u64 chain_table[SIRFSOC_DMA_TABLE_NUM]; /* chain tbl */ 94 62 }; 95 63 96 64 struct sirfsoc_dma_chan { ··· 123 87 void __iomem *base; 124 88 int irq; 125 89 struct clk *clk; 126 - bool is_marco; 90 + int type; 91 + void (*exec_desc)(struct sirfsoc_dma_desc *sdesc, 92 + int cid, int burst_mode, void __iomem *base); 127 93 struct sirfsoc_dma_regs regs_save; 94 + }; 95 + 96 + struct sirfsoc_dmadata { 97 + void (*exec)(struct sirfsoc_dma_desc *sdesc, 98 + int cid, int burst_mode, void __iomem *base); 99 + int type; 100 + }; 101 + 102 + enum sirfsoc_dma_chain_flag { 103 + SIRFSOC_DMA_CHAIN_NORMAL = 0x01, 104 + SIRFSOC_DMA_CHAIN_PAUSE = 0x02, 105 + SIRFSOC_DMA_CHAIN_LOOP = 0x03, 106 + SIRFSOC_DMA_CHAIN_END = 0x04 128 107 }; 129 108 130 109 #define DRV_NAME "sirfsoc_dma" ··· 160 109 return container_of(schan, struct sirfsoc_dma, channels[c->chan_id]); 161 110 } 162 111 112 + static void sirfsoc_dma_execute_hw_a7v2(struct sirfsoc_dma_desc *sdesc, 113 + int cid, int burst_mode, void __iomem *base) 114 + { 115 + if (sdesc->chain) { 116 + /* DMA v2 HW chain mode */ 117 + writel_relaxed((sdesc->dir << SIRFSOC_DMA_DIR_CTRL_BIT_ATLAS7) | 118 + (sdesc->chain << 119 + SIRFSOC_DMA_CHAIN_CTRL_BIT_ATLAS7) | 120 + (0x8 << SIRFSOC_DMA_TAB_NUM_ATLAS7) | 0x3, 121 + base + SIRFSOC_DMA_CH_CTRL); 122 + } else { 123 + /* DMA v2 legacy mode */ 124 + writel_relaxed(sdesc->xlen, base + SIRFSOC_DMA_CH_XLEN); 125 + writel_relaxed(sdesc->ylen, base + SIRFSOC_DMA_CH_YLEN); 126 + writel_relaxed(sdesc->width, base + SIRFSOC_DMA_WIDTH_ATLAS7); 127 + writel_relaxed((sdesc->width*((sdesc->ylen+1)>>1)), 128 + base + SIRFSOC_DMA_MUL_ATLAS7); 129 + writel_relaxed((sdesc->dir << SIRFSOC_DMA_DIR_CTRL_BIT_ATLAS7) | 130 + (sdesc->chain << 131 + SIRFSOC_DMA_CHAIN_CTRL_BIT_ATLAS7) | 132 + 0x3, base + SIRFSOC_DMA_CH_CTRL); 133 + } 134 + writel_relaxed(sdesc->chain ? SIRFSOC_DMA_INT_END_INT_ATLAS7 : 135 + (SIRFSOC_DMA_INT_FINI_INT_ATLAS7 | 136 + SIRFSOC_DMA_INT_LOOP_INT_ATLAS7), 137 + base + SIRFSOC_DMA_INT_EN_ATLAS7); 138 + writel(sdesc->addr, base + SIRFSOC_DMA_CH_ADDR); 139 + if (sdesc->cyclic) 140 + writel(0x10001, base + SIRFSOC_DMA_LOOP_CTRL_ATLAS7); 141 + } 142 + 143 + static void sirfsoc_dma_execute_hw_a7v1(struct sirfsoc_dma_desc *sdesc, 144 + int cid, int burst_mode, void __iomem *base) 145 + { 146 + writel_relaxed(1, base + SIRFSOC_DMA_IOBG_SCMD_EN); 147 + writel_relaxed((1 << cid), base + SIRFSOC_DMA_EARLY_RESP_SET); 148 + writel_relaxed(sdesc->width, base + SIRFSOC_DMA_WIDTH_0 + cid * 4); 149 + writel_relaxed(cid | (burst_mode << SIRFSOC_DMA_MODE_CTRL_BIT) | 150 + (sdesc->dir << SIRFSOC_DMA_DIR_CTRL_BIT), 151 + base + cid * 0x10 + SIRFSOC_DMA_CH_CTRL); 152 + writel_relaxed(sdesc->xlen, base + cid * 0x10 + SIRFSOC_DMA_CH_XLEN); 153 + writel_relaxed(sdesc->ylen, base + cid * 0x10 + SIRFSOC_DMA_CH_YLEN); 154 + writel_relaxed(readl_relaxed(base + SIRFSOC_DMA_INT_EN) | 155 + (1 << cid), base + SIRFSOC_DMA_INT_EN); 156 + writel(sdesc->addr >> 2, base + cid * 0x10 + SIRFSOC_DMA_CH_ADDR); 157 + if (sdesc->cyclic) { 158 + writel((1 << cid) | 1 << (cid + 16) | 159 + readl_relaxed(base + SIRFSOC_DMA_CH_LOOP_CTRL_ATLAS7), 160 + base + SIRFSOC_DMA_CH_LOOP_CTRL_ATLAS7); 161 + } 162 + 163 + } 164 + 165 + static void sirfsoc_dma_execute_hw_a6(struct sirfsoc_dma_desc *sdesc, 166 + int cid, int burst_mode, void __iomem *base) 167 + { 168 + writel_relaxed(sdesc->width, base + SIRFSOC_DMA_WIDTH_0 + cid * 4); 169 + writel_relaxed(cid | (burst_mode << SIRFSOC_DMA_MODE_CTRL_BIT) | 170 + (sdesc->dir << SIRFSOC_DMA_DIR_CTRL_BIT), 171 + base + cid * 0x10 + SIRFSOC_DMA_CH_CTRL); 172 + writel_relaxed(sdesc->xlen, base + cid * 0x10 + SIRFSOC_DMA_CH_XLEN); 173 + writel_relaxed(sdesc->ylen, base + cid * 0x10 + SIRFSOC_DMA_CH_YLEN); 174 + writel_relaxed(readl_relaxed(base + SIRFSOC_DMA_INT_EN) | 175 + (1 << cid), base + SIRFSOC_DMA_INT_EN); 176 + writel(sdesc->addr >> 2, base + cid * 0x10 + SIRFSOC_DMA_CH_ADDR); 177 + if (sdesc->cyclic) { 178 + writel((1 << cid) | 1 << (cid + 16) | 179 + readl_relaxed(base + SIRFSOC_DMA_CH_LOOP_CTRL), 180 + base + SIRFSOC_DMA_CH_LOOP_CTRL); 181 + } 182 + 183 + } 184 + 163 185 /* Execute all queued DMA descriptors */ 164 186 static void sirfsoc_dma_execute(struct sirfsoc_dma_chan *schan) 165 187 { 166 188 struct sirfsoc_dma *sdma = dma_chan_to_sirfsoc_dma(&schan->chan); 167 189 int cid = schan->chan.chan_id; 168 190 struct sirfsoc_dma_desc *sdesc = NULL; 191 + void __iomem *base; 169 192 170 193 /* 171 194 * lock has been held by functions calling this, so we don't hold 172 195 * lock again 173 196 */ 174 - 197 + base = sdma->base; 175 198 sdesc = list_first_entry(&schan->queued, struct sirfsoc_dma_desc, 176 - node); 199 + node); 177 200 /* Move the first queued descriptor to active list */ 178 201 list_move_tail(&sdesc->node, &schan->active); 179 202 203 + if (sdma->type == SIRFSOC_DMA_VER_A7V2) 204 + cid = 0; 205 + 180 206 /* Start the DMA transfer */ 181 - writel_relaxed(sdesc->width, sdma->base + SIRFSOC_DMA_WIDTH_0 + 182 - cid * 4); 183 - writel_relaxed(cid | (schan->mode << SIRFSOC_DMA_MODE_CTRL_BIT) | 184 - (sdesc->dir << SIRFSOC_DMA_DIR_CTRL_BIT), 185 - sdma->base + cid * 0x10 + SIRFSOC_DMA_CH_CTRL); 186 - writel_relaxed(sdesc->xlen, sdma->base + cid * 0x10 + 187 - SIRFSOC_DMA_CH_XLEN); 188 - writel_relaxed(sdesc->ylen, sdma->base + cid * 0x10 + 189 - SIRFSOC_DMA_CH_YLEN); 190 - writel_relaxed(readl_relaxed(sdma->base + SIRFSOC_DMA_INT_EN) | 191 - (1 << cid), sdma->base + SIRFSOC_DMA_INT_EN); 207 + sdma->exec_desc(sdesc, cid, schan->mode, base); 192 208 193 - /* 194 - * writel has an implict memory write barrier to make sure data is 195 - * flushed into memory before starting DMA 196 - */ 197 - writel(sdesc->addr >> 2, sdma->base + cid * 0x10 + SIRFSOC_DMA_CH_ADDR); 198 - 199 - if (sdesc->cyclic) { 200 - writel((1 << cid) | 1 << (cid + 16) | 201 - readl_relaxed(sdma->base + SIRFSOC_DMA_CH_LOOP_CTRL), 202 - sdma->base + SIRFSOC_DMA_CH_LOOP_CTRL); 209 + if (sdesc->cyclic) 203 210 schan->happened_cyclic = schan->completed_cyclic = 0; 204 - } 205 211 } 206 212 207 213 /* Interrupt handler */ ··· 268 160 struct sirfsoc_dma_chan *schan; 269 161 struct sirfsoc_dma_desc *sdesc = NULL; 270 162 u32 is; 163 + bool chain; 271 164 int ch; 165 + void __iomem *reg; 272 166 273 - is = readl(sdma->base + SIRFSOC_DMA_CH_INT); 274 - while ((ch = fls(is) - 1) >= 0) { 275 - is &= ~(1 << ch); 276 - writel_relaxed(1 << ch, sdma->base + SIRFSOC_DMA_CH_INT); 277 - schan = &sdma->channels[ch]; 167 + switch (sdma->type) { 168 + case SIRFSOC_DMA_VER_A6: 169 + case SIRFSOC_DMA_VER_A7V1: 170 + is = readl(sdma->base + SIRFSOC_DMA_CH_INT); 171 + reg = sdma->base + SIRFSOC_DMA_CH_INT; 172 + while ((ch = fls(is) - 1) >= 0) { 173 + is &= ~(1 << ch); 174 + writel_relaxed(1 << ch, reg); 175 + schan = &sdma->channels[ch]; 176 + spin_lock(&schan->lock); 177 + sdesc = list_first_entry(&schan->active, 178 + struct sirfsoc_dma_desc, node); 179 + if (!sdesc->cyclic) { 180 + /* Execute queued descriptors */ 181 + list_splice_tail_init(&schan->active, 182 + &schan->completed); 183 + dma_cookie_complete(&sdesc->desc); 184 + if (!list_empty(&schan->queued)) 185 + sirfsoc_dma_execute(schan); 186 + } else 187 + schan->happened_cyclic++; 188 + spin_unlock(&schan->lock); 189 + } 190 + break; 278 191 192 + case SIRFSOC_DMA_VER_A7V2: 193 + is = readl(sdma->base + SIRFSOC_DMA_INT_ATLAS7); 194 + 195 + reg = sdma->base + SIRFSOC_DMA_INT_ATLAS7; 196 + writel_relaxed(SIRFSOC_DMA_INT_ALL_ATLAS7, reg); 197 + schan = &sdma->channels[0]; 279 198 spin_lock(&schan->lock); 280 - 281 - sdesc = list_first_entry(&schan->active, struct sirfsoc_dma_desc, 282 - node); 199 + sdesc = list_first_entry(&schan->active, 200 + struct sirfsoc_dma_desc, node); 283 201 if (!sdesc->cyclic) { 284 - /* Execute queued descriptors */ 285 - list_splice_tail_init(&schan->active, &schan->completed); 286 - if (!list_empty(&schan->queued)) 287 - sirfsoc_dma_execute(schan); 288 - } else 202 + chain = sdesc->chain; 203 + if ((chain && (is & SIRFSOC_DMA_INT_END_INT_ATLAS7)) || 204 + (!chain && 205 + (is & SIRFSOC_DMA_INT_FINI_INT_ATLAS7))) { 206 + /* Execute queued descriptors */ 207 + list_splice_tail_init(&schan->active, 208 + &schan->completed); 209 + dma_cookie_complete(&sdesc->desc); 210 + if (!list_empty(&schan->queued)) 211 + sirfsoc_dma_execute(schan); 212 + } 213 + } else if (sdesc->cyclic && (is & 214 + SIRFSOC_DMA_INT_LOOP_INT_ATLAS7)) 289 215 schan->happened_cyclic++; 290 216 291 217 spin_unlock(&schan->lock); 218 + break; 219 + 220 + default: 221 + break; 292 222 } 293 223 294 224 /* Schedule tasklet */ ··· 373 227 schan->chan.completed_cookie = last_cookie; 374 228 spin_unlock_irqrestore(&schan->lock, flags); 375 229 } else { 376 - /* for cyclic channel, desc is always in active list */ 377 - sdesc = list_first_entry(&schan->active, struct sirfsoc_dma_desc, 378 - node); 379 - 380 - if (!sdesc || (sdesc && !sdesc->cyclic)) { 381 - /* without active cyclic DMA */ 230 + if (list_empty(&schan->active)) { 382 231 spin_unlock_irqrestore(&schan->lock, flags); 383 232 continue; 384 233 } 234 + 235 + /* for cyclic channel, desc is always in active list */ 236 + sdesc = list_first_entry(&schan->active, 237 + struct sirfsoc_dma_desc, node); 385 238 386 239 /* cyclic DMA */ 387 240 happened_cyclic = schan->happened_cyclic; ··· 452 307 453 308 spin_lock_irqsave(&schan->lock, flags); 454 309 455 - if (!sdma->is_marco) { 456 - writel_relaxed(readl_relaxed(sdma->base + SIRFSOC_DMA_INT_EN) & 457 - ~(1 << cid), sdma->base + SIRFSOC_DMA_INT_EN); 458 - writel_relaxed(readl_relaxed(sdma->base + SIRFSOC_DMA_CH_LOOP_CTRL) 459 - & ~((1 << cid) | 1 << (cid + 16)), 460 - sdma->base + SIRFSOC_DMA_CH_LOOP_CTRL); 461 - } else { 310 + switch (sdma->type) { 311 + case SIRFSOC_DMA_VER_A7V1: 462 312 writel_relaxed(1 << cid, sdma->base + SIRFSOC_DMA_INT_EN_CLR); 463 313 writel_relaxed((1 << cid) | 1 << (cid + 16), 464 - sdma->base + SIRFSOC_DMA_CH_LOOP_CTRL_CLR); 314 + sdma->base + 315 + SIRFSOC_DMA_CH_LOOP_CTRL_CLR_ATLAS7); 316 + writel_relaxed(1 << cid, sdma->base + SIRFSOC_DMA_CH_VALID); 317 + break; 318 + case SIRFSOC_DMA_VER_A7V2: 319 + writel_relaxed(0, sdma->base + SIRFSOC_DMA_INT_EN_ATLAS7); 320 + writel_relaxed(0, sdma->base + SIRFSOC_DMA_LOOP_CTRL_ATLAS7); 321 + writel_relaxed(0, sdma->base + SIRFSOC_DMA_VALID_ATLAS7); 322 + break; 323 + case SIRFSOC_DMA_VER_A6: 324 + writel_relaxed(readl_relaxed(sdma->base + SIRFSOC_DMA_INT_EN) & 325 + ~(1 << cid), sdma->base + SIRFSOC_DMA_INT_EN); 326 + writel_relaxed(readl_relaxed(sdma->base + 327 + SIRFSOC_DMA_CH_LOOP_CTRL) & 328 + ~((1 << cid) | 1 << (cid + 16)), 329 + sdma->base + SIRFSOC_DMA_CH_LOOP_CTRL); 330 + writel_relaxed(1 << cid, sdma->base + SIRFSOC_DMA_CH_VALID); 331 + break; 332 + default: 333 + break; 465 334 } 466 - 467 - writel_relaxed(1 << cid, sdma->base + SIRFSOC_DMA_CH_VALID); 468 335 469 336 list_splice_tail_init(&schan->active, &schan->free); 470 337 list_splice_tail_init(&schan->queued, &schan->free); ··· 495 338 496 339 spin_lock_irqsave(&schan->lock, flags); 497 340 498 - if (!sdma->is_marco) 499 - writel_relaxed(readl_relaxed(sdma->base + SIRFSOC_DMA_CH_LOOP_CTRL) 500 - & ~((1 << cid) | 1 << (cid + 16)), 501 - sdma->base + SIRFSOC_DMA_CH_LOOP_CTRL); 502 - else 341 + switch (sdma->type) { 342 + case SIRFSOC_DMA_VER_A7V1: 503 343 writel_relaxed((1 << cid) | 1 << (cid + 16), 504 - sdma->base + SIRFSOC_DMA_CH_LOOP_CTRL_CLR); 344 + sdma->base + 345 + SIRFSOC_DMA_CH_LOOP_CTRL_CLR_ATLAS7); 346 + break; 347 + case SIRFSOC_DMA_VER_A7V2: 348 + writel_relaxed(0, sdma->base + SIRFSOC_DMA_LOOP_CTRL_ATLAS7); 349 + break; 350 + case SIRFSOC_DMA_VER_A6: 351 + writel_relaxed(readl_relaxed(sdma->base + 352 + SIRFSOC_DMA_CH_LOOP_CTRL) & 353 + ~((1 << cid) | 1 << (cid + 16)), 354 + sdma->base + SIRFSOC_DMA_CH_LOOP_CTRL); 355 + break; 356 + 357 + default: 358 + break; 359 + } 505 360 506 361 spin_unlock_irqrestore(&schan->lock, flags); 507 362 ··· 528 359 unsigned long flags; 529 360 530 361 spin_lock_irqsave(&schan->lock, flags); 531 - 532 - if (!sdma->is_marco) 533 - writel_relaxed(readl_relaxed(sdma->base + SIRFSOC_DMA_CH_LOOP_CTRL) 534 - | ((1 << cid) | 1 << (cid + 16)), 535 - sdma->base + SIRFSOC_DMA_CH_LOOP_CTRL); 536 - else 362 + switch (sdma->type) { 363 + case SIRFSOC_DMA_VER_A7V1: 537 364 writel_relaxed((1 << cid) | 1 << (cid + 16), 538 - sdma->base + SIRFSOC_DMA_CH_LOOP_CTRL); 365 + sdma->base + SIRFSOC_DMA_CH_LOOP_CTRL_ATLAS7); 366 + break; 367 + case SIRFSOC_DMA_VER_A7V2: 368 + writel_relaxed(0x10001, 369 + sdma->base + SIRFSOC_DMA_LOOP_CTRL_ATLAS7); 370 + break; 371 + case SIRFSOC_DMA_VER_A6: 372 + writel_relaxed(readl_relaxed(sdma->base + 373 + SIRFSOC_DMA_CH_LOOP_CTRL) | 374 + ((1 << cid) | 1 << (cid + 16)), 375 + sdma->base + SIRFSOC_DMA_CH_LOOP_CTRL); 376 + break; 377 + 378 + default: 379 + break; 380 + } 539 381 540 382 spin_unlock_irqrestore(&schan->lock, flags); 541 383 ··· 653 473 654 474 spin_lock_irqsave(&schan->lock, flags); 655 475 656 - sdesc = list_first_entry(&schan->active, struct sirfsoc_dma_desc, 657 - node); 658 - dma_request_bytes = (sdesc->xlen + 1) * (sdesc->ylen + 1) * 659 - (sdesc->width * SIRFSOC_DMA_WORD_LEN); 476 + if (list_empty(&schan->active)) { 477 + ret = dma_cookie_status(chan, cookie, txstate); 478 + dma_set_residue(txstate, 0); 479 + spin_unlock_irqrestore(&schan->lock, flags); 480 + return ret; 481 + } 482 + sdesc = list_first_entry(&schan->active, struct sirfsoc_dma_desc, node); 483 + if (sdesc->cyclic) 484 + dma_request_bytes = (sdesc->xlen + 1) * (sdesc->ylen + 1) * 485 + (sdesc->width * SIRFSOC_DMA_WORD_LEN); 486 + else 487 + dma_request_bytes = sdesc->xlen * SIRFSOC_DMA_WORD_LEN; 660 488 661 489 ret = dma_cookie_status(chan, cookie, txstate); 662 - dma_pos = readl_relaxed(sdma->base + cid * 0x10 + SIRFSOC_DMA_CH_ADDR) 663 - << 2; 490 + 491 + if (sdma->type == SIRFSOC_DMA_VER_A7V2) 492 + cid = 0; 493 + 494 + if (sdma->type == SIRFSOC_DMA_VER_A7V2) { 495 + dma_pos = readl_relaxed(sdma->base + SIRFSOC_DMA_CUR_DATA_ADDR); 496 + } else { 497 + dma_pos = readl_relaxed( 498 + sdma->base + cid * 0x10 + SIRFSOC_DMA_CH_ADDR) << 2; 499 + } 500 + 664 501 residue = dma_request_bytes - (dma_pos - sdesc->addr); 665 502 dma_set_residue(txstate, residue); 666 503 ··· 844 647 struct dma_device *dma; 845 648 struct sirfsoc_dma *sdma; 846 649 struct sirfsoc_dma_chan *schan; 650 + struct sirfsoc_dmadata *data; 847 651 struct resource res; 848 652 ulong regs_start, regs_size; 849 653 u32 id; ··· 855 657 dev_err(dev, "Memory exhausted!\n"); 856 658 return -ENOMEM; 857 659 } 858 - 859 - if (of_device_is_compatible(dn, "sirf,marco-dmac")) 860 - sdma->is_marco = true; 660 + data = (struct sirfsoc_dmadata *) 661 + (of_match_device(op->dev.driver->of_match_table, 662 + &op->dev)->data); 663 + sdma->exec_desc = data->exec; 664 + sdma->type = data->type; 861 665 862 666 if (of_property_read_u32(dn, "cell-index", &id)) { 863 667 dev_err(dev, "Fail to get DMAC index\n"); ··· 1016 816 struct sirfsoc_dma_chan *schan; 1017 817 int ch; 1018 818 int ret; 819 + int count; 820 + u32 int_offset; 1019 821 1020 822 /* 1021 823 * if we were runtime-suspended before, resume to enable clock ··· 1029 827 return ret; 1030 828 } 1031 829 830 + if (sdma->type == SIRFSOC_DMA_VER_A7V2) { 831 + count = 1; 832 + int_offset = SIRFSOC_DMA_INT_EN_ATLAS7; 833 + } else { 834 + count = SIRFSOC_DMA_CHANNELS; 835 + int_offset = SIRFSOC_DMA_INT_EN; 836 + } 837 + 1032 838 /* 1033 839 * DMA controller will lose all registers while suspending 1034 840 * so we need to save registers for active channels 1035 841 */ 1036 - for (ch = 0; ch < SIRFSOC_DMA_CHANNELS; ch++) { 842 + for (ch = 0; ch < count; ch++) { 1037 843 schan = &sdma->channels[ch]; 1038 844 if (list_empty(&schan->active)) 1039 845 continue; ··· 1051 841 save->ctrl[ch] = readl_relaxed(sdma->base + 1052 842 ch * 0x10 + SIRFSOC_DMA_CH_CTRL); 1053 843 } 1054 - save->interrupt_en = readl_relaxed(sdma->base + SIRFSOC_DMA_INT_EN); 844 + save->interrupt_en = readl_relaxed(sdma->base + int_offset); 1055 845 1056 846 /* Disable clock */ 1057 847 sirfsoc_dma_runtime_suspend(dev); ··· 1067 857 struct sirfsoc_dma_chan *schan; 1068 858 int ch; 1069 859 int ret; 860 + int count; 861 + u32 int_offset; 862 + u32 width_offset; 1070 863 1071 864 /* Enable clock before accessing register */ 1072 865 ret = sirfsoc_dma_runtime_resume(dev); 1073 866 if (ret < 0) 1074 867 return ret; 1075 868 1076 - writel_relaxed(save->interrupt_en, sdma->base + SIRFSOC_DMA_INT_EN); 1077 - for (ch = 0; ch < SIRFSOC_DMA_CHANNELS; ch++) { 869 + if (sdma->type == SIRFSOC_DMA_VER_A7V2) { 870 + count = 1; 871 + int_offset = SIRFSOC_DMA_INT_EN_ATLAS7; 872 + width_offset = SIRFSOC_DMA_WIDTH_ATLAS7; 873 + } else { 874 + count = SIRFSOC_DMA_CHANNELS; 875 + int_offset = SIRFSOC_DMA_INT_EN; 876 + width_offset = SIRFSOC_DMA_WIDTH_0; 877 + } 878 + 879 + writel_relaxed(save->interrupt_en, sdma->base + int_offset); 880 + for (ch = 0; ch < count; ch++) { 1078 881 schan = &sdma->channels[ch]; 1079 882 if (list_empty(&schan->active)) 1080 883 continue; ··· 1095 872 struct sirfsoc_dma_desc, 1096 873 node); 1097 874 writel_relaxed(sdesc->width, 1098 - sdma->base + SIRFSOC_DMA_WIDTH_0 + ch * 4); 875 + sdma->base + width_offset + ch * 4); 1099 876 writel_relaxed(sdesc->xlen, 1100 877 sdma->base + ch * 0x10 + SIRFSOC_DMA_CH_XLEN); 1101 878 writel_relaxed(sdesc->ylen, 1102 879 sdma->base + ch * 0x10 + SIRFSOC_DMA_CH_YLEN); 1103 880 writel_relaxed(save->ctrl[ch], 1104 881 sdma->base + ch * 0x10 + SIRFSOC_DMA_CH_CTRL); 1105 - writel_relaxed(sdesc->addr >> 2, 1106 - sdma->base + ch * 0x10 + SIRFSOC_DMA_CH_ADDR); 882 + if (sdma->type == SIRFSOC_DMA_VER_A7V2) { 883 + writel_relaxed(sdesc->addr, 884 + sdma->base + SIRFSOC_DMA_CH_ADDR); 885 + } else { 886 + writel_relaxed(sdesc->addr >> 2, 887 + sdma->base + ch * 0x10 + SIRFSOC_DMA_CH_ADDR); 888 + 889 + } 1107 890 } 1108 891 1109 892 /* if we were runtime-suspended before, suspend again */ ··· 1125 896 SET_SYSTEM_SLEEP_PM_OPS(sirfsoc_dma_pm_suspend, sirfsoc_dma_pm_resume) 1126 897 }; 1127 898 899 + struct sirfsoc_dmadata sirfsoc_dmadata_a6 = { 900 + .exec = sirfsoc_dma_execute_hw_a6, 901 + .type = SIRFSOC_DMA_VER_A6, 902 + }; 903 + 904 + struct sirfsoc_dmadata sirfsoc_dmadata_a7v1 = { 905 + .exec = sirfsoc_dma_execute_hw_a7v1, 906 + .type = SIRFSOC_DMA_VER_A7V1, 907 + }; 908 + 909 + struct sirfsoc_dmadata sirfsoc_dmadata_a7v2 = { 910 + .exec = sirfsoc_dma_execute_hw_a7v2, 911 + .type = SIRFSOC_DMA_VER_A7V2, 912 + }; 913 + 1128 914 static const struct of_device_id sirfsoc_dma_match[] = { 1129 - { .compatible = "sirf,prima2-dmac", }, 1130 - { .compatible = "sirf,marco-dmac", }, 915 + { .compatible = "sirf,prima2-dmac", .data = &sirfsoc_dmadata_a6,}, 916 + { .compatible = "sirf,atlas7-dmac", .data = &sirfsoc_dmadata_a7v1,}, 917 + { .compatible = "sirf,atlas7-dmac-v2", .data = &sirfsoc_dmadata_a7v2,}, 1131 918 {}, 1132 919 }; 1133 920 ··· 1170 925 subsys_initcall(sirfsoc_dma_init); 1171 926 module_exit(sirfsoc_dma_exit); 1172 927 1173 - MODULE_AUTHOR("Rongjun Ying <rongjun.ying@csr.com>, " 1174 - "Barry Song <baohua.song@csr.com>"); 928 + MODULE_AUTHOR("Rongjun Ying <rongjun.ying@csr.com>"); 929 + MODULE_AUTHOR("Barry Song <baohua.song@csr.com>"); 1175 930 MODULE_DESCRIPTION("SIRFSOC DMA control driver"); 1176 931 MODULE_LICENSE("GPL v2");
+12
drivers/dma/sun6i-dma.c
··· 891 891 .nr_max_vchans = 37, 892 892 }; 893 893 894 + /* 895 + * The H3 has 12 physical channels, a maximum DRQ port id of 27, 896 + * and a total of 34 usable source and destination endpoints. 897 + */ 898 + 899 + static struct sun6i_dma_config sun8i_h3_dma_cfg = { 900 + .nr_max_channels = 12, 901 + .nr_max_requests = 27, 902 + .nr_max_vchans = 34, 903 + }; 904 + 894 905 static const struct of_device_id sun6i_dma_match[] = { 895 906 { .compatible = "allwinner,sun6i-a31-dma", .data = &sun6i_a31_dma_cfg }, 896 907 { .compatible = "allwinner,sun8i-a23-dma", .data = &sun8i_a23_dma_cfg }, 908 + { .compatible = "allwinner,sun8i-h3-dma", .data = &sun8i_h3_dma_cfg }, 897 909 { /* sentinel */ } 898 910 }; 899 911
+188
drivers/dma/ti-dma-crossbar.c
··· 1 + /* 2 + * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com 3 + * Author: Peter Ujfalusi <peter.ujfalusi@ti.com> 4 + * 5 + * This program is free software; you can redistribute it and/or modify 6 + * it under the terms of the GNU General Public License version 2 as 7 + * published by the Free Software Foundation. 8 + * 9 + */ 10 + #include <linux/slab.h> 11 + #include <linux/err.h> 12 + #include <linux/init.h> 13 + #include <linux/list.h> 14 + #include <linux/io.h> 15 + #include <linux/idr.h> 16 + #include <linux/of_address.h> 17 + #include <linux/of_device.h> 18 + #include <linux/of_dma.h> 19 + 20 + #define TI_XBAR_OUTPUTS 127 21 + #define TI_XBAR_INPUTS 256 22 + 23 + static DEFINE_IDR(map_idr); 24 + 25 + struct ti_dma_xbar_data { 26 + void __iomem *iomem; 27 + 28 + struct dma_router dmarouter; 29 + 30 + u16 safe_val; /* Value to rest the crossbar lines */ 31 + u32 xbar_requests; /* number of DMA requests connected to XBAR */ 32 + u32 dma_requests; /* number of DMA requests forwarded to DMA */ 33 + }; 34 + 35 + struct ti_dma_xbar_map { 36 + u16 xbar_in; 37 + int xbar_out; 38 + }; 39 + 40 + static inline void ti_dma_xbar_write(void __iomem *iomem, int xbar, u16 val) 41 + { 42 + writew_relaxed(val, iomem + (xbar * 2)); 43 + } 44 + 45 + static void ti_dma_xbar_free(struct device *dev, void *route_data) 46 + { 47 + struct ti_dma_xbar_data *xbar = dev_get_drvdata(dev); 48 + struct ti_dma_xbar_map *map = route_data; 49 + 50 + dev_dbg(dev, "Unmapping XBAR%u (was routed to %d)\n", 51 + map->xbar_in, map->xbar_out); 52 + 53 + ti_dma_xbar_write(xbar->iomem, map->xbar_out, xbar->safe_val); 54 + idr_remove(&map_idr, map->xbar_out); 55 + kfree(map); 56 + } 57 + 58 + static void *ti_dma_xbar_route_allocate(struct of_phandle_args *dma_spec, 59 + struct of_dma *ofdma) 60 + { 61 + struct platform_device *pdev = of_find_device_by_node(ofdma->of_node); 62 + struct ti_dma_xbar_data *xbar = platform_get_drvdata(pdev); 63 + struct ti_dma_xbar_map *map; 64 + 65 + if (dma_spec->args[0] >= xbar->xbar_requests) { 66 + dev_err(&pdev->dev, "Invalid XBAR request number: %d\n", 67 + dma_spec->args[0]); 68 + return ERR_PTR(-EINVAL); 69 + } 70 + 71 + /* The of_node_put() will be done in the core for the node */ 72 + dma_spec->np = of_parse_phandle(ofdma->of_node, "dma-masters", 0); 73 + if (!dma_spec->np) { 74 + dev_err(&pdev->dev, "Can't get DMA master\n"); 75 + return ERR_PTR(-EINVAL); 76 + } 77 + 78 + map = kzalloc(sizeof(*map), GFP_KERNEL); 79 + if (!map) { 80 + of_node_put(dma_spec->np); 81 + return ERR_PTR(-ENOMEM); 82 + } 83 + 84 + map->xbar_out = idr_alloc(&map_idr, NULL, 0, xbar->dma_requests, 85 + GFP_KERNEL); 86 + map->xbar_in = (u16)dma_spec->args[0]; 87 + 88 + /* The DMA request is 1 based in sDMA */ 89 + dma_spec->args[0] = map->xbar_out + 1; 90 + 91 + dev_dbg(&pdev->dev, "Mapping XBAR%u to DMA%d\n", 92 + map->xbar_in, map->xbar_out); 93 + 94 + ti_dma_xbar_write(xbar->iomem, map->xbar_out, map->xbar_in); 95 + 96 + return map; 97 + } 98 + 99 + static int ti_dma_xbar_probe(struct platform_device *pdev) 100 + { 101 + struct device_node *node = pdev->dev.of_node; 102 + struct device_node *dma_node; 103 + struct ti_dma_xbar_data *xbar; 104 + struct resource *res; 105 + u32 safe_val; 106 + void __iomem *iomem; 107 + int i, ret; 108 + 109 + if (!node) 110 + return -ENODEV; 111 + 112 + xbar = devm_kzalloc(&pdev->dev, sizeof(*xbar), GFP_KERNEL); 113 + if (!xbar) 114 + return -ENOMEM; 115 + 116 + dma_node = of_parse_phandle(node, "dma-masters", 0); 117 + if (!dma_node) { 118 + dev_err(&pdev->dev, "Can't get DMA master node\n"); 119 + return -ENODEV; 120 + } 121 + 122 + if (of_property_read_u32(dma_node, "dma-requests", 123 + &xbar->dma_requests)) { 124 + dev_info(&pdev->dev, 125 + "Missing XBAR output information, using %u.\n", 126 + TI_XBAR_OUTPUTS); 127 + xbar->dma_requests = TI_XBAR_OUTPUTS; 128 + } 129 + of_node_put(dma_node); 130 + 131 + if (of_property_read_u32(node, "dma-requests", &xbar->xbar_requests)) { 132 + dev_info(&pdev->dev, 133 + "Missing XBAR input information, using %u.\n", 134 + TI_XBAR_INPUTS); 135 + xbar->xbar_requests = TI_XBAR_INPUTS; 136 + } 137 + 138 + if (!of_property_read_u32(node, "ti,dma-safe-map", &safe_val)) 139 + xbar->safe_val = (u16)safe_val; 140 + 141 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 142 + if (!res) 143 + return -ENODEV; 144 + 145 + iomem = devm_ioremap_resource(&pdev->dev, res); 146 + if (!iomem) 147 + return -ENOMEM; 148 + 149 + xbar->iomem = iomem; 150 + 151 + xbar->dmarouter.dev = &pdev->dev; 152 + xbar->dmarouter.route_free = ti_dma_xbar_free; 153 + 154 + platform_set_drvdata(pdev, xbar); 155 + 156 + /* Reset the crossbar */ 157 + for (i = 0; i < xbar->dma_requests; i++) 158 + ti_dma_xbar_write(xbar->iomem, i, xbar->safe_val); 159 + 160 + ret = of_dma_router_register(node, ti_dma_xbar_route_allocate, 161 + &xbar->dmarouter); 162 + if (ret) { 163 + /* Restore the defaults for the crossbar */ 164 + for (i = 0; i < xbar->dma_requests; i++) 165 + ti_dma_xbar_write(xbar->iomem, i, i); 166 + } 167 + 168 + return ret; 169 + } 170 + 171 + static const struct of_device_id ti_dma_xbar_match[] = { 172 + { .compatible = "ti,dra7-dma-crossbar" }, 173 + {}, 174 + }; 175 + 176 + static struct platform_driver ti_dma_xbar_driver = { 177 + .driver = { 178 + .name = "ti-dma-crossbar", 179 + .of_match_table = of_match_ptr(ti_dma_xbar_match), 180 + }, 181 + .probe = ti_dma_xbar_probe, 182 + }; 183 + 184 + int omap_dmaxbar_init(void) 185 + { 186 + return platform_driver_register(&ti_dma_xbar_driver); 187 + } 188 + arch_initcall(omap_dmaxbar_init);
+13 -6
drivers/dma/virt-dma.c
··· 29 29 spin_lock_irqsave(&vc->lock, flags); 30 30 cookie = dma_cookie_assign(tx); 31 31 32 - list_add_tail(&vd->node, &vc->desc_submitted); 32 + list_move_tail(&vd->node, &vc->desc_submitted); 33 33 spin_unlock_irqrestore(&vc->lock, flags); 34 34 35 35 dev_dbg(vc->chan.device->dev, "vchan %p: txd %p[%x]: submitted\n", ··· 83 83 cb_data = vd->tx.callback_param; 84 84 85 85 list_del(&vd->node); 86 - 87 - vc->desc_free(vd); 86 + if (async_tx_test_ack(&vd->tx)) 87 + list_add(&vd->node, &vc->desc_allocated); 88 + else 89 + vc->desc_free(vd); 88 90 89 91 if (cb) 90 92 cb(cb_data); ··· 98 96 while (!list_empty(head)) { 99 97 struct virt_dma_desc *vd = list_first_entry(head, 100 98 struct virt_dma_desc, node); 101 - list_del(&vd->node); 102 - dev_dbg(vc->chan.device->dev, "txd %p: freeing\n", vd); 103 - vc->desc_free(vd); 99 + if (async_tx_test_ack(&vd->tx)) { 100 + list_move_tail(&vd->node, &vc->desc_allocated); 101 + } else { 102 + dev_dbg(vc->chan.device->dev, "txd %p: freeing\n", vd); 103 + list_del(&vd->node); 104 + vc->desc_free(vd); 105 + } 104 106 } 105 107 } 106 108 EXPORT_SYMBOL_GPL(vchan_dma_desc_free_list); ··· 114 108 dma_cookie_init(&vc->chan); 115 109 116 110 spin_lock_init(&vc->lock); 111 + INIT_LIST_HEAD(&vc->desc_allocated); 117 112 INIT_LIST_HEAD(&vc->desc_submitted); 118 113 INIT_LIST_HEAD(&vc->desc_issued); 119 114 INIT_LIST_HEAD(&vc->desc_completed);
+12 -1
drivers/dma/virt-dma.h
··· 29 29 spinlock_t lock; 30 30 31 31 /* protected by vc.lock */ 32 + struct list_head desc_allocated; 32 33 struct list_head desc_submitted; 33 34 struct list_head desc_issued; 34 35 struct list_head desc_completed; ··· 56 55 struct virt_dma_desc *vd, unsigned long tx_flags) 57 56 { 58 57 extern dma_cookie_t vchan_tx_submit(struct dma_async_tx_descriptor *); 58 + unsigned long flags; 59 59 60 60 dma_async_tx_descriptor_init(&vd->tx, &vc->chan); 61 61 vd->tx.flags = tx_flags; 62 62 vd->tx.tx_submit = vchan_tx_submit; 63 + 64 + spin_lock_irqsave(&vc->lock, flags); 65 + list_add_tail(&vd->node, &vc->desc_allocated); 66 + spin_unlock_irqrestore(&vc->lock, flags); 63 67 64 68 return &vd->tx; 65 69 } ··· 128 122 } 129 123 130 124 /** 131 - * vchan_get_all_descriptors - obtain all submitted and issued descriptors 125 + * vchan_get_all_descriptors - obtain all allocated, submitted and issued 126 + * descriptors 132 127 * vc: virtual channel to get descriptors from 133 128 * head: list of descriptors found 134 129 * ··· 141 134 static inline void vchan_get_all_descriptors(struct virt_dma_chan *vc, 142 135 struct list_head *head) 143 136 { 137 + list_splice_tail_init(&vc->desc_allocated, head); 144 138 list_splice_tail_init(&vc->desc_submitted, head); 145 139 list_splice_tail_init(&vc->desc_issued, head); 146 140 list_splice_tail_init(&vc->desc_completed, head); ··· 149 141 150 142 static inline void vchan_free_chan_resources(struct virt_dma_chan *vc) 151 143 { 144 + struct virt_dma_desc *vd; 152 145 unsigned long flags; 153 146 LIST_HEAD(head); 154 147 155 148 spin_lock_irqsave(&vc->lock, flags); 156 149 vchan_get_all_descriptors(vc, &head); 150 + list_for_each_entry(vd, &head, node) 151 + async_tx_clear_ack(&vd->tx); 157 152 spin_unlock_irqrestore(&vc->lock, flags); 158 153 159 154 vchan_dma_desc_free_list(vc, &head);
+66 -107
drivers/dma/xgene-dma.c
··· 124 124 #define XGENE_DMA_DESC_ELERR_POS 46 125 125 #define XGENE_DMA_DESC_RTYPE_POS 56 126 126 #define XGENE_DMA_DESC_LERR_POS 60 127 - #define XGENE_DMA_DESC_FLYBY_POS 4 128 127 #define XGENE_DMA_DESC_BUFLEN_POS 48 129 128 #define XGENE_DMA_DESC_HOENQ_NUM_POS 48 130 - 131 - #define XGENE_DMA_DESC_NV_SET(m) \ 132 - (((u64 *)(m))[0] |= XGENE_DMA_DESC_NV_BIT) 133 - #define XGENE_DMA_DESC_IN_SET(m) \ 134 - (((u64 *)(m))[0] |= XGENE_DMA_DESC_IN_BIT) 135 - #define XGENE_DMA_DESC_RTYPE_SET(m, v) \ 136 - (((u64 *)(m))[0] |= ((u64)(v) << XGENE_DMA_DESC_RTYPE_POS)) 137 - #define XGENE_DMA_DESC_BUFADDR_SET(m, v) \ 138 - (((u64 *)(m))[0] |= (v)) 139 - #define XGENE_DMA_DESC_BUFLEN_SET(m, v) \ 140 - (((u64 *)(m))[0] |= ((u64)(v) << XGENE_DMA_DESC_BUFLEN_POS)) 141 - #define XGENE_DMA_DESC_C_SET(m) \ 142 - (((u64 *)(m))[1] |= XGENE_DMA_DESC_C_BIT) 143 - #define XGENE_DMA_DESC_FLYBY_SET(m, v) \ 144 - (((u64 *)(m))[2] |= ((v) << XGENE_DMA_DESC_FLYBY_POS)) 145 - #define XGENE_DMA_DESC_MULTI_SET(m, v, i) \ 146 - (((u64 *)(m))[2] |= ((u64)(v) << (((i) + 1) * 8))) 147 - #define XGENE_DMA_DESC_DR_SET(m) \ 148 - (((u64 *)(m))[2] |= XGENE_DMA_DESC_DR_BIT) 149 - #define XGENE_DMA_DESC_DST_ADDR_SET(m, v) \ 150 - (((u64 *)(m))[3] |= (v)) 151 - #define XGENE_DMA_DESC_H0ENQ_NUM_SET(m, v) \ 152 - (((u64 *)(m))[3] |= ((u64)(v) << XGENE_DMA_DESC_HOENQ_NUM_POS)) 153 129 #define XGENE_DMA_DESC_ELERR_RD(m) \ 154 130 (((m) >> XGENE_DMA_DESC_ELERR_POS) & 0x3) 155 131 #define XGENE_DMA_DESC_LERR_RD(m) \ ··· 134 158 (((elerr) << 4) | (lerr)) 135 159 136 160 /* X-Gene DMA descriptor empty s/w signature */ 137 - #define XGENE_DMA_DESC_EMPTY_INDEX 0 138 161 #define XGENE_DMA_DESC_EMPTY_SIGNATURE ~0ULL 139 - #define XGENE_DMA_DESC_SET_EMPTY(m) \ 140 - (((u64 *)(m))[XGENE_DMA_DESC_EMPTY_INDEX] = \ 141 - XGENE_DMA_DESC_EMPTY_SIGNATURE) 142 - #define XGENE_DMA_DESC_IS_EMPTY(m) \ 143 - (((u64 *)(m))[XGENE_DMA_DESC_EMPTY_INDEX] == \ 144 - XGENE_DMA_DESC_EMPTY_SIGNATURE) 145 162 146 163 /* X-Gene DMA configurable parameters defines */ 147 164 #define XGENE_DMA_RING_NUM 512 ··· 153 184 #define XGENE_DMA_XOR_ALIGNMENT 6 /* 64 Bytes */ 154 185 #define XGENE_DMA_MAX_XOR_SRC 5 155 186 #define XGENE_DMA_16K_BUFFER_LEN_CODE 0x0 156 - #define XGENE_DMA_INVALID_LEN_CODE 0x7800 187 + #define XGENE_DMA_INVALID_LEN_CODE 0x7800000000000000ULL 157 188 158 189 /* X-Gene DMA descriptor error codes */ 159 190 #define ERR_DESC_AXI 0x01 ··· 183 214 #define ERR_DESC_SRC_INT 0xB 184 215 185 216 /* X-Gene DMA flyby operation code */ 186 - #define FLYBY_2SRC_XOR 0x8 187 - #define FLYBY_3SRC_XOR 0x9 188 - #define FLYBY_4SRC_XOR 0xA 189 - #define FLYBY_5SRC_XOR 0xB 217 + #define FLYBY_2SRC_XOR 0x80 218 + #define FLYBY_3SRC_XOR 0x90 219 + #define FLYBY_4SRC_XOR 0xA0 220 + #define FLYBY_5SRC_XOR 0xB0 190 221 191 222 /* X-Gene DMA SW descriptor flags */ 192 223 #define XGENE_DMA_FLAG_64B_DESC BIT(0) ··· 207 238 dev_err(chan->dev, "%s: " fmt, chan->name, ##arg) 208 239 209 240 struct xgene_dma_desc_hw { 210 - u64 m0; 211 - u64 m1; 212 - u64 m2; 213 - u64 m3; 241 + __le64 m0; 242 + __le64 m1; 243 + __le64 m2; 244 + __le64 m3; 214 245 }; 215 246 216 247 enum xgene_dma_ring_cfgsize { ··· 357 388 return !(val & XGENE_DMA_PQ_DISABLE_MASK); 358 389 } 359 390 360 - static void xgene_dma_cpu_to_le64(u64 *desc, int count) 361 - { 362 - int i; 363 - 364 - for (i = 0; i < count; i++) 365 - desc[i] = cpu_to_le64(desc[i]); 366 - } 367 - 368 - static u16 xgene_dma_encode_len(u32 len) 391 + static u64 xgene_dma_encode_len(size_t len) 369 392 { 370 393 return (len < XGENE_DMA_MAX_BYTE_CNT) ? 371 - len : XGENE_DMA_16K_BUFFER_LEN_CODE; 394 + ((u64)len << XGENE_DMA_DESC_BUFLEN_POS) : 395 + XGENE_DMA_16K_BUFFER_LEN_CODE; 372 396 } 373 397 374 398 static u8 xgene_dma_encode_xor_flyby(u32 src_cnt) ··· 386 424 return XGENE_DMA_RING_DESC_CNT(ring_state); 387 425 } 388 426 389 - static void xgene_dma_set_src_buffer(void *ext8, size_t *len, 427 + static void xgene_dma_set_src_buffer(__le64 *ext8, size_t *len, 390 428 dma_addr_t *paddr) 391 429 { 392 430 size_t nbytes = (*len < XGENE_DMA_MAX_BYTE_CNT) ? 393 431 *len : XGENE_DMA_MAX_BYTE_CNT; 394 432 395 - XGENE_DMA_DESC_BUFADDR_SET(ext8, *paddr); 396 - XGENE_DMA_DESC_BUFLEN_SET(ext8, xgene_dma_encode_len(nbytes)); 433 + *ext8 |= cpu_to_le64(*paddr); 434 + *ext8 |= cpu_to_le64(xgene_dma_encode_len(nbytes)); 397 435 *len -= nbytes; 398 436 *paddr += nbytes; 399 437 } 400 438 401 - static void xgene_dma_invalidate_buffer(void *ext8) 439 + static void xgene_dma_invalidate_buffer(__le64 *ext8) 402 440 { 403 - XGENE_DMA_DESC_BUFLEN_SET(ext8, XGENE_DMA_INVALID_LEN_CODE); 441 + *ext8 |= cpu_to_le64(XGENE_DMA_INVALID_LEN_CODE); 404 442 } 405 443 406 - static void *xgene_dma_lookup_ext8(u64 *desc, int idx) 444 + static __le64 *xgene_dma_lookup_ext8(struct xgene_dma_desc_hw *desc, int idx) 407 445 { 408 - return (idx % 2) ? (desc + idx - 1) : (desc + idx + 1); 446 + switch (idx) { 447 + case 0: 448 + return &desc->m1; 449 + case 1: 450 + return &desc->m0; 451 + case 2: 452 + return &desc->m3; 453 + case 3: 454 + return &desc->m2; 455 + default: 456 + pr_err("Invalid dma descriptor index\n"); 457 + } 458 + 459 + return NULL; 409 460 } 410 461 411 - static void xgene_dma_init_desc(void *desc, u16 dst_ring_num) 462 + static void xgene_dma_init_desc(struct xgene_dma_desc_hw *desc, 463 + u16 dst_ring_num) 412 464 { 413 - XGENE_DMA_DESC_C_SET(desc); /* Coherent IO */ 414 - XGENE_DMA_DESC_IN_SET(desc); 415 - XGENE_DMA_DESC_H0ENQ_NUM_SET(desc, dst_ring_num); 416 - XGENE_DMA_DESC_RTYPE_SET(desc, XGENE_DMA_RING_OWNER_DMA); 465 + desc->m0 |= cpu_to_le64(XGENE_DMA_DESC_IN_BIT); 466 + desc->m0 |= cpu_to_le64((u64)XGENE_DMA_RING_OWNER_DMA << 467 + XGENE_DMA_DESC_RTYPE_POS); 468 + desc->m1 |= cpu_to_le64(XGENE_DMA_DESC_C_BIT); 469 + desc->m3 |= cpu_to_le64((u64)dst_ring_num << 470 + XGENE_DMA_DESC_HOENQ_NUM_POS); 417 471 } 418 472 419 473 static void xgene_dma_prep_cpy_desc(struct xgene_dma_chan *chan, ··· 437 459 dma_addr_t dst, dma_addr_t src, 438 460 size_t len) 439 461 { 440 - void *desc1, *desc2; 462 + struct xgene_dma_desc_hw *desc1, *desc2; 441 463 int i; 442 464 443 465 /* Get 1st descriptor */ ··· 445 467 xgene_dma_init_desc(desc1, chan->tx_ring.dst_ring_num); 446 468 447 469 /* Set destination address */ 448 - XGENE_DMA_DESC_DR_SET(desc1); 449 - XGENE_DMA_DESC_DST_ADDR_SET(desc1, dst); 470 + desc1->m2 |= cpu_to_le64(XGENE_DMA_DESC_DR_BIT); 471 + desc1->m3 |= cpu_to_le64(dst); 450 472 451 473 /* Set 1st source address */ 452 - xgene_dma_set_src_buffer(desc1 + 8, &len, &src); 474 + xgene_dma_set_src_buffer(&desc1->m1, &len, &src); 453 475 454 - if (len <= 0) { 455 - desc2 = NULL; 456 - goto skip_additional_src; 457 - } 476 + if (!len) 477 + return; 458 478 459 479 /* 460 480 * We need to split this source buffer, 461 481 * and need to use 2nd descriptor 462 482 */ 463 483 desc2 = &desc_sw->desc2; 464 - XGENE_DMA_DESC_NV_SET(desc1); 484 + desc1->m0 |= cpu_to_le64(XGENE_DMA_DESC_NV_BIT); 465 485 466 486 /* Set 2nd to 5th source address */ 467 487 for (i = 0; i < 4 && len; i++) ··· 472 496 473 497 /* Updated flag that we have prepared 64B descriptor */ 474 498 desc_sw->flags |= XGENE_DMA_FLAG_64B_DESC; 475 - 476 - skip_additional_src: 477 - /* Hardware stores descriptor in little endian format */ 478 - xgene_dma_cpu_to_le64(desc1, 4); 479 - if (desc2) 480 - xgene_dma_cpu_to_le64(desc2, 4); 481 499 } 482 500 483 501 static void xgene_dma_prep_xor_desc(struct xgene_dma_chan *chan, ··· 480 510 u32 src_cnt, size_t *nbytes, 481 511 const u8 *scf) 482 512 { 483 - void *desc1, *desc2; 513 + struct xgene_dma_desc_hw *desc1, *desc2; 484 514 size_t len = *nbytes; 485 515 int i; 486 516 ··· 491 521 xgene_dma_init_desc(desc1, chan->tx_ring.dst_ring_num); 492 522 493 523 /* Set destination address */ 494 - XGENE_DMA_DESC_DR_SET(desc1); 495 - XGENE_DMA_DESC_DST_ADDR_SET(desc1, *dst); 524 + desc1->m2 |= cpu_to_le64(XGENE_DMA_DESC_DR_BIT); 525 + desc1->m3 |= cpu_to_le64(*dst); 496 526 497 527 /* We have multiple source addresses, so need to set NV bit*/ 498 - XGENE_DMA_DESC_NV_SET(desc1); 528 + desc1->m0 |= cpu_to_le64(XGENE_DMA_DESC_NV_BIT); 499 529 500 530 /* Set flyby opcode */ 501 - XGENE_DMA_DESC_FLYBY_SET(desc1, xgene_dma_encode_xor_flyby(src_cnt)); 531 + desc1->m2 |= cpu_to_le64(xgene_dma_encode_xor_flyby(src_cnt)); 502 532 503 533 /* Set 1st to 5th source addresses */ 504 534 for (i = 0; i < src_cnt; i++) { 505 535 len = *nbytes; 506 - xgene_dma_set_src_buffer((i == 0) ? (desc1 + 8) : 536 + xgene_dma_set_src_buffer((i == 0) ? &desc1->m1 : 507 537 xgene_dma_lookup_ext8(desc2, i - 1), 508 538 &len, &src[i]); 509 - XGENE_DMA_DESC_MULTI_SET(desc1, scf[i], i); 539 + desc1->m2 |= cpu_to_le64((scf[i] << ((i + 1) * 8))); 510 540 } 511 - 512 - /* Hardware stores descriptor in little endian format */ 513 - xgene_dma_cpu_to_le64(desc1, 4); 514 - xgene_dma_cpu_to_le64(desc2, 4); 515 541 516 542 /* Update meta data */ 517 543 *nbytes = len; ··· 704 738 * xgene_chan_xfer_ld_pending - push any pending transactions to hw 705 739 * @chan : X-Gene DMA channel 706 740 * 707 - * LOCKING: must hold chan->desc_lock 741 + * LOCKING: must hold chan->lock 708 742 */ 709 743 static void xgene_chan_xfer_ld_pending(struct xgene_dma_chan *chan) 710 744 { ··· 774 808 desc_hw = &ring->desc_hw[ring->head]; 775 809 776 810 /* Check if this descriptor has been completed */ 777 - if (unlikely(XGENE_DMA_DESC_IS_EMPTY(desc_hw))) 811 + if (unlikely(le64_to_cpu(desc_hw->m0) == 812 + XGENE_DMA_DESC_EMPTY_SIGNATURE)) 778 813 break; 779 814 780 815 if (++ring->head == ring->slots) ··· 809 842 iowrite32(-1, ring->cmd); 810 843 811 844 /* Mark this hw descriptor as processed */ 812 - XGENE_DMA_DESC_SET_EMPTY(desc_hw); 845 + desc_hw->m0 = cpu_to_le64(XGENE_DMA_DESC_EMPTY_SIGNATURE); 813 846 814 847 xgene_dma_run_tx_complete_actions(chan, desc_sw); 815 848 ··· 856 889 * @chan: X-Gene DMA channel 857 890 * @list: the list to free 858 891 * 859 - * LOCKING: must hold chan->desc_lock 892 + * LOCKING: must hold chan->lock 860 893 */ 861 894 static void xgene_dma_free_desc_list(struct xgene_dma_chan *chan, 862 895 struct list_head *list) 863 - { 864 - struct xgene_dma_desc_sw *desc, *_desc; 865 - 866 - list_for_each_entry_safe(desc, _desc, list, node) 867 - xgene_dma_clean_descriptor(chan, desc); 868 - } 869 - 870 - static void xgene_dma_free_tx_desc_list(struct xgene_dma_chan *chan, 871 - struct list_head *list) 872 896 { 873 897 struct xgene_dma_desc_sw *desc, *_desc; 874 898 ··· 943 985 if (!first) 944 986 return NULL; 945 987 946 - xgene_dma_free_tx_desc_list(chan, &first->tx_list); 988 + xgene_dma_free_desc_list(chan, &first->tx_list); 947 989 return NULL; 948 990 } 949 991 ··· 1051 1093 if (!first) 1052 1094 return NULL; 1053 1095 1054 - xgene_dma_free_tx_desc_list(chan, &first->tx_list); 1096 + xgene_dma_free_desc_list(chan, &first->tx_list); 1055 1097 return NULL; 1056 1098 } 1057 1099 ··· 1099 1141 if (!first) 1100 1142 return NULL; 1101 1143 1102 - xgene_dma_free_tx_desc_list(chan, &first->tx_list); 1144 + xgene_dma_free_desc_list(chan, &first->tx_list); 1103 1145 return NULL; 1104 1146 } 1105 1147 ··· 1176 1218 if (!first) 1177 1219 return NULL; 1178 1220 1179 - xgene_dma_free_tx_desc_list(chan, &first->tx_list); 1221 + xgene_dma_free_desc_list(chan, &first->tx_list); 1180 1222 return NULL; 1181 1223 } 1182 1224 ··· 1274 1316 { 1275 1317 void *ring_cfg = ring->state; 1276 1318 u64 addr = ring->desc_paddr; 1277 - void *desc; 1278 1319 u32 i, val; 1279 1320 1280 1321 ring->slots = ring->size / XGENE_DMA_RING_WQ_DESC_SIZE; ··· 1315 1358 1316 1359 /* Set empty signature to DMA Rx ring descriptors */ 1317 1360 for (i = 0; i < ring->slots; i++) { 1361 + struct xgene_dma_desc_hw *desc; 1362 + 1318 1363 desc = &ring->desc_hw[i]; 1319 - XGENE_DMA_DESC_SET_EMPTY(desc); 1364 + desc->m0 = cpu_to_le64(XGENE_DMA_DESC_EMPTY_SIGNATURE); 1320 1365 } 1321 1366 1322 1367 /* Enable DMA Rx ring interrupt */
+27
include/linux/dma/pxa-dma.h
··· 1 + #ifndef _PXA_DMA_H_ 2 + #define _PXA_DMA_H_ 3 + 4 + enum pxad_chan_prio { 5 + PXAD_PRIO_HIGHEST = 0, 6 + PXAD_PRIO_NORMAL, 7 + PXAD_PRIO_LOW, 8 + PXAD_PRIO_LOWEST, 9 + }; 10 + 11 + struct pxad_param { 12 + unsigned int drcmr; 13 + enum pxad_chan_prio prio; 14 + }; 15 + 16 + struct dma_chan; 17 + 18 + #ifdef CONFIG_PXA_DMA 19 + bool pxad_filter_fn(struct dma_chan *chan, void *param); 20 + #else 21 + static inline bool pxad_filter_fn(struct dma_chan *chan, void *param) 22 + { 23 + return false; 24 + } 25 + #endif 26 + 27 + #endif /* _PXA_DMA_H_ */
+76
include/linux/dmaengine.h
··· 65 65 DMA_PQ, 66 66 DMA_XOR_VAL, 67 67 DMA_PQ_VAL, 68 + DMA_MEMSET, 68 69 DMA_INTERRUPT, 69 70 DMA_SG, 70 71 DMA_PRIVATE, ··· 123 122 * chunk and before first src/dst address for next chunk. 124 123 * Ignored for dst(assumed 0), if dst_inc is true and dst_sgl is false. 125 124 * Ignored for src(assumed 0), if src_inc is true and src_sgl is false. 125 + * @dst_icg: Number of bytes to jump after last dst address of this 126 + * chunk and before the first dst address for next chunk. 127 + * Ignored if dst_inc is true and dst_sgl is false. 128 + * @src_icg: Number of bytes to jump after last src address of this 129 + * chunk and before the first src address for next chunk. 130 + * Ignored if src_inc is true and src_sgl is false. 126 131 */ 127 132 struct data_chunk { 128 133 size_t size; 129 134 size_t icg; 135 + size_t dst_icg; 136 + size_t src_icg; 130 137 }; 131 138 132 139 /** ··· 231 222 }; 232 223 233 224 /** 225 + * struct dma_router - DMA router structure 226 + * @dev: pointer to the DMA router device 227 + * @route_free: function to be called when the route can be disconnected 228 + */ 229 + struct dma_router { 230 + struct device *dev; 231 + void (*route_free)(struct device *dev, void *route_data); 232 + }; 233 + 234 + /** 234 235 * struct dma_chan - devices supply DMA channels, clients use them 235 236 * @device: ptr to the dma device who supplies this channel, always !%NULL 236 237 * @cookie: last cookie value returned to client ··· 251 232 * @local: per-cpu pointer to a struct dma_chan_percpu 252 233 * @client_count: how many clients are using this channel 253 234 * @table_count: number of appearances in the mem-to-mem allocation table 235 + * @router: pointer to the DMA router structure 236 + * @route_data: channel specific data for the router 254 237 * @private: private data for certain client-channel associations 255 238 */ 256 239 struct dma_chan { ··· 268 247 struct dma_chan_percpu __percpu *local; 269 248 int client_count; 270 249 int table_count; 250 + 251 + /* DMA router */ 252 + struct dma_router *router; 253 + void *route_data; 254 + 271 255 void *private; 272 256 }; 273 257 ··· 596 570 * @copy_align: alignment shift for memcpy operations 597 571 * @xor_align: alignment shift for xor operations 598 572 * @pq_align: alignment shift for pq operations 573 + * @fill_align: alignment shift for memset operations 599 574 * @dev_id: unique device ID 600 575 * @dev: struct device reference for dma mapping api 601 576 * @src_addr_widths: bit mask of src addr widths the device supports ··· 615 588 * @device_prep_dma_xor_val: prepares a xor validation operation 616 589 * @device_prep_dma_pq: prepares a pq operation 617 590 * @device_prep_dma_pq_val: prepares a pqzero_sum operation 591 + * @device_prep_dma_memset: prepares a memset operation 618 592 * @device_prep_dma_interrupt: prepares an end of chain interrupt operation 619 593 * @device_prep_slave_sg: prepares a slave dma operation 620 594 * @device_prep_dma_cyclic: prepare a cyclic dma operation suitable for audio. ··· 648 620 u8 copy_align; 649 621 u8 xor_align; 650 622 u8 pq_align; 623 + u8 fill_align; 651 624 #define DMA_HAS_PQ_CONTINUE (1 << 15) 652 625 653 626 int dev_id; ··· 679 650 struct dma_chan *chan, dma_addr_t *pq, dma_addr_t *src, 680 651 unsigned int src_cnt, const unsigned char *scf, size_t len, 681 652 enum sum_check_flags *pqres, unsigned long flags); 653 + struct dma_async_tx_descriptor *(*device_prep_dma_memset)( 654 + struct dma_chan *chan, dma_addr_t dest, int value, size_t len, 655 + unsigned long flags); 682 656 struct dma_async_tx_descriptor *(*device_prep_dma_interrupt)( 683 657 struct dma_chan *chan, unsigned long flags); 684 658 struct dma_async_tx_descriptor *(*device_prep_dma_sg)( ··· 777 745 return chan->device->device_prep_interleaved_dma(chan, xt, flags); 778 746 } 779 747 748 + static inline struct dma_async_tx_descriptor *dmaengine_prep_dma_memset( 749 + struct dma_chan *chan, dma_addr_t dest, int value, size_t len, 750 + unsigned long flags) 751 + { 752 + if (!chan || !chan->device) 753 + return NULL; 754 + 755 + return chan->device->device_prep_dma_memset(chan, dest, value, 756 + len, flags); 757 + } 758 + 780 759 static inline struct dma_async_tx_descriptor *dmaengine_prep_dma_sg( 781 760 struct dma_chan *chan, 782 761 struct scatterlist *dst_sg, unsigned int dst_nents, ··· 863 820 return dmaengine_check_align(dev->pq_align, off1, off2, len); 864 821 } 865 822 823 + static inline bool is_dma_fill_aligned(struct dma_device *dev, size_t off1, 824 + size_t off2, size_t len) 825 + { 826 + return dmaengine_check_align(dev->fill_align, off1, off2, len); 827 + } 828 + 866 829 static inline void 867 830 dma_set_maxpq(struct dma_device *dma, int maxpq, int has_pq_continue) 868 831 { ··· 921 872 else if (dmaf_continue(flags)) 922 873 return dma_dev_to_maxpq(dma) - 3; 923 874 BUG(); 875 + } 876 + 877 + static inline size_t dmaengine_get_icg(bool inc, bool sgl, size_t icg, 878 + size_t dir_icg) 879 + { 880 + if (inc) { 881 + if (dir_icg) 882 + return dir_icg; 883 + else if (sgl) 884 + return icg; 885 + } 886 + 887 + return 0; 888 + } 889 + 890 + static inline size_t dmaengine_get_dst_icg(struct dma_interleaved_template *xt, 891 + struct data_chunk *chunk) 892 + { 893 + return dmaengine_get_icg(xt->dst_inc, xt->dst_sgl, 894 + chunk->icg, chunk->dst_icg); 895 + } 896 + 897 + static inline size_t dmaengine_get_src_icg(struct dma_interleaved_template *xt, 898 + struct data_chunk *chunk) 899 + { 900 + return dmaengine_get_icg(xt->src_inc, xt->src_sgl, 901 + chunk->icg, chunk->src_icg); 924 902 } 925 903 926 904 /* --- public DMA engine API --- */
+21
include/linux/of_dma.h
··· 23 23 struct device_node *of_node; 24 24 struct dma_chan *(*of_dma_xlate) 25 25 (struct of_phandle_args *, struct of_dma *); 26 + void *(*of_dma_route_allocate) 27 + (struct of_phandle_args *, struct of_dma *); 28 + struct dma_router *dma_router; 26 29 void *of_dma_data; 27 30 }; 28 31 ··· 40 37 (struct of_phandle_args *, struct of_dma *), 41 38 void *data); 42 39 extern void of_dma_controller_free(struct device_node *np); 40 + 41 + extern int of_dma_router_register(struct device_node *np, 42 + void *(*of_dma_route_allocate) 43 + (struct of_phandle_args *, struct of_dma *), 44 + struct dma_router *dma_router); 45 + #define of_dma_router_free of_dma_controller_free 46 + 43 47 extern struct dma_chan *of_dma_request_slave_channel(struct device_node *np, 44 48 const char *name); 45 49 extern struct dma_chan *of_dma_simple_xlate(struct of_phandle_args *dma_spec, 46 50 struct of_dma *ofdma); 47 51 extern struct dma_chan *of_dma_xlate_by_chan_id(struct of_phandle_args *dma_spec, 48 52 struct of_dma *ofdma); 53 + 49 54 #else 50 55 static inline int of_dma_controller_register(struct device_node *np, 51 56 struct dma_chan *(*of_dma_xlate) ··· 66 55 static inline void of_dma_controller_free(struct device_node *np) 67 56 { 68 57 } 58 + 59 + static inline int of_dma_router_register(struct device_node *np, 60 + void *(*of_dma_route_allocate) 61 + (struct of_phandle_args *, struct of_dma *), 62 + struct dma_router *dma_router) 63 + { 64 + return -ENODEV; 65 + } 66 + 67 + #define of_dma_router_free of_dma_controller_free 69 68 70 69 static inline struct dma_chan *of_dma_request_slave_channel(struct device_node *np, 71 70 const char *name)
-34
include/linux/platform_data/dma-rcar-audmapp.h
··· 1 - /* 2 - * This is for Renesas R-Car Audio-DMAC-peri-peri. 3 - * 4 - * Copyright (C) 2014 Renesas Electronics Corporation 5 - * Copyright (C) 2014 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> 6 - * 7 - * This file is based on the include/linux/sh_dma.h 8 - * 9 - * Header for the new SH dmaengine driver 10 - * 11 - * Copyright (C) 2010 Guennadi Liakhovetski <g.liakhovetski@gmx.de> 12 - * 13 - * This program is free software; you can redistribute it and/or modify 14 - * it under the terms of the GNU General Public License version 2 as 15 - * published by the Free Software Foundation. 16 - */ 17 - #ifndef SH_AUDMAPP_H 18 - #define SH_AUDMAPP_H 19 - 20 - #include <linux/dmaengine.h> 21 - 22 - struct audmapp_slave_config { 23 - int slave_id; 24 - dma_addr_t src; 25 - dma_addr_t dst; 26 - u32 chcr; 27 - }; 28 - 29 - struct audmapp_pdata { 30 - struct audmapp_slave_config *slave; 31 - int slave_num; 32 - }; 33 - 34 - #endif /* SH_AUDMAPP_H */