Add Qualcomm BAM dmaengine driver
Subsystems (3)
v2 cover Add Qualcomm BAM dmaengine driver
This patch set introduces the dmaengine driver for the Qualcomm Bus Access Manager (BAM) DMA controller present on MSM 8x74 devices. A number of the on-chip devices have their own BAM DMA controller and use it to move data between system memory and peripherals or between two peripherals.
The initial version of this driver will only support slave DMA operations between system memory and peripherals.
Changes from v1:
- Converted driver to use virt-dma
- Reworked probe function per review comments
- tx_status function now computes and returns residuals
- Removed proprietary slave config. Removed associated include file.
- Renamed files to reflect vendor name instead of specific device
- Converted to use (readl|writel)_relaxed w/ appropriate barriers
- Removed unions in favor of standard types.
Andy Gross (2):
dmaengine: add Qualcomm BAM dma driver
dmaengine: qcom_bam_dma: Add device tree binding
.../devicetree/bindings/dma/qcom_bam_dma.txt | 52 ++ drivers/dma/Kconfig | 9 + drivers/dma/Makefile | 1 + drivers/dma/qcom_bam_dma.c | 843 +++++++++++++++++++++ drivers/dma/qcom_bam_dma.h | 268 +++++++ 5 files changed, 1173 insertions(+) create mode 100644 Documentation/devicetree/bindings/dma/qcom_bam_dma.txt create mode 100644 drivers/dma/qcom_bam_dma.c create mode 100644 drivers/dma/qcom_bam_dma.h
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation
PATCH v2 1/2 dmaengine: add Qualcomm BAM dma driver
Add the DMA engine driver for the QCOM Bus Access Manager (BAM) DMA controller found in the MSM 8x74 platforms.
Each BAM DMA device is associated with a specific on-chip peripheral. Each channel provides a uni-directional data transfer engine that is capable of transferring data between the peripheral and system memory (System mode), or between two peripherals (BAM2BAM).
The initial release of this driver only supports slave transfers between peripherals and system memory.
--- drivers/dma/Kconfig | 9 + drivers/dma/Makefile | 1 + drivers/dma/qcom_bam_dma.c | 843 +++++++++++++++++++++++++++++++++++++++++++++ drivers/dma/qcom_bam_dma.h | 268 ++++++++++++++ 4 files changed, 1121 insertions(+) create mode 100644 drivers/dma/qcom_bam_dma.c create mode 100644 drivers/dma/qcom_bam_dma.h
drivers/dma/Kconfig +9 -0
@@ -384,4 +384,13 @@ config DMATEST config DMA_ENGINE_RAID bool +config QCOM_BAM_DMA + tristate "QCOM BAM DMA support" + depends on ARCH_MSM || COMPILE_TEST + select DMA_ENGINE + select DMA_VIRTUAL_CHANNELS + ---help--- + Enable support for the QCOM BAM DMA controller. This controller + provides DMA capabilities for a variety of on-chip devices. + endif
drivers/dma/Makefile +1 -0
@@ -42,3 +42,4 @@ obj-$(CONFIG_MMP_PDMA) += mmp_pdma.o obj-$(CONFIG_DMA_JZ4740) += dma-jz4740.o obj-$(CONFIG_TI_CPPI41) += cppi41.o obj-$(CONFIG_K3_DMA) += k3dma.o +obj-$(CONFIG_QCOM_BAM_DMA) += qcom_bam_dma.o
drivers/dma/qcom_bam_dma.c new file +843 -0
843 lines not on this page · raw message
drivers/dma/qcom_bam_dma.h new file +268 -0
268 lines not on this page · raw message
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation
PATCH v2 1/2 dmaengine: add Qualcomm BAM dma driver
Quoted 491 lines · Andy Gross
Add the DMA engine driver for the QCOM Bus Access Manager (BAM) DMA controller found in the MSM 8x74 platforms.
Each BAM DMA device is associated with a specific on-chip peripheral. Each channel provides a uni-directional data transfer engine that is capable of transferring data between the peripheral and system memory (System mode), or between two peripherals (BAM2BAM).
The initial release of this driver only supports slave transfers between peripherals and system memory.
Signed-off-by Andy Gross <[email protected]>--- drivers/dma/Kconfig | 9 + drivers/dma/Makefile | 1 + drivers/dma/qcom_bam_dma.c | 843 +++++++++++++++++++++++++++++++++++++++++++++ drivers/dma/qcom_bam_dma.h | 268 ++++++++++++++ 4 files changed, 1121 insertions(+) create mode 100644 drivers/dma/qcom_bam_dma.c create mode 100644 drivers/dma/qcom_bam_dma.hdrivers/dma/Kconfig +9
-0@@ -384,4 +384,13 @@ config DMATEST config DMA_ENGINE_RAID bool +config QCOM_BAM_DMA + tristate "QCOM BAM DMA support" + depends on ARCH_MSM || COMPILE_TEST + select DMA_ENGINE + select DMA_VIRTUAL_CHANNELS + ---help--- + Enable support for the QCOM BAM DMA controller. This controller + provides DMA capabilities for a variety of on-chip devices. + endifdrivers/dma/Makefile +1
-0@@ -42,3 +42,4 @@ obj-$(CONFIG_MMP_PDMA) += mmp_pdma.o obj-$(CONFIG_DMA_JZ4740) += dma-jz4740.o obj-$(CONFIG_TI_CPPI41) += cppi41.o obj-$(CONFIG_K3_DMA) += k3dma.o +obj-$(CONFIG_QCOM_BAM_DMA) += qcom_bam_dma.odrivers/dma/qcom_bam_dma.c new file +437
-0@@ -0,0 +1,843 @@ +/* +* QCOM BAM DMA engine driver +* +* Copyright (c) 2013, The Linux Foundation. All rights reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 and +* only version 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* +* QCOM BAM DMA blocks are distributed amongst a number of the on-chip +* peripherals on the MSM 8x74. The configuration of the channels are dependent +* on the way they are hard wired to that specific peripheral. The peripheral +* device tree entries specify the configuration of each channel. +* +* The DMA controller requires the use of external memory for storage of the +* hardware descriptors for each channel. The descriptor FIFO is accessed as a +* circular buffer and operations are managed according to the offset within the +* FIFO. After pipe/channel reset, all of the pipe registers and internal state +* are back to defaults. +* +* During DMA operations, we write descriptors to the FIFO, being careful to +* handle wrapping and then write the last FIFO offset to that channel's +* P_EVNT_REG register to kick off the transaction. The P_SW_OFSTS register +* indicates the current FIFO offset that is being processed, so there is some +* indication of where the hardware is currently working. +*/ + +#include <linux/kernel.h> +#include <linux/io.h> +#include <linux/init.h> +#include <linux/slab.h> +#include <linux/module.h> +#include <linux/interrupt.h> +#include <linux/dma-mapping.h> +#include <linux/scatterlist.h> +#include <linux/device.h> +#include <linux/platform_device.h> +#include <linux/of.h> +#include <linux/of_address.h> +#include <linux/of_irq.h> +#include <linux/of_dma.h> +#include <linux/clk.h> + +#include "dmaengine.h" +#include "qcom_bam_dma.h" + + +/** +* bam_reset_channel - Reset individual BAM DMA channel +* @bdev: bam device +* @channel: channel id +*/ +static void bam_reset_channel (struct bam_device *bdev,u32 channel) +{ +/* reset channel */ +writel_relaxed (1 , bdev->regs +BAM_P_RST (channel)); +writel_relaxed (0 , bdev->regs +BAM_P_RST (channel)); +} + +/** +* bam_alloc_chan - Allocate channel resources for DMA channel. +* @chan: specified channel +* +* This function allocates the FIFO descriptor memory and resets the channel +*/ +static int bam_alloc_chan (struct dma_chan *chan) +{ +struct bam_chan *bchan =to_bam_chan (chan); +struct bam_device *bdev = bchan->bdev; +u32 val; + +/* allocate FIFO descriptor space, but only if necessary */ +if (!bchan->fifo_virt) { + bchan->fifo_virt =dma_alloc_coherent (bdev->dev, +BAM_DESC_FIFO_SIZE , &bchan->fifo_phys, +GFP_KERNEL ); + +if (!bchan->fifo_virt) { +dev_err (bdev->dev,"Failed to allocate desc fifo\n" ); +return -ENOMEM ; + } + } + +/* Go ahead and initialize the pipe/channel hardware here +- Reset the channel to clear internal state of the FIFO +- Program in the FIFO address +- Configure the irq based on the EE passed in from the DT entry +- Set mode, direction and enable channel + +We do this here because the channel can only be enabled once and +can only be disabled via a reset. If done here, we don't have to +manage additional state to figure out when to do this +*/ + +bam_reset_channel (bdev, bchan->id); + +/* write out 8 byte aligned address. We have enough space for this +because we allocated 1 more descriptor (8 bytes) than we can use */ +writel_relaxed (ALIGN (bchan->fifo_phys,sizeof (struct bam_desc_hw )), + bdev->regs +BAM_P_DESC_FIFO_ADDR (bchan->id)); +writel_relaxed (BAM_DESC_FIFO_SIZE , bdev->regs + +BAM_P_FIFO_SIZES (bchan->id)); + +/* unmask and enable interrupts for defined EE, bam and error irqs */ +writel_relaxed (BAM_IRQ_MSK , bdev->regs +BAM_IRQ_SRCS_EE (bchan->ee)); + +/* enable the per pipe interrupts, enable EOT, ERR, and INT irqs */ +writel_relaxed (P_DEFAULT_IRQS_EN , bdev->regs +BAM_P_IRQ_EN (bchan->id)); + +/* unmask the specific pipe and EE combo */ + val =readl_relaxed (bdev->regs +BAM_IRQ_SRCS_MSK_EE (bchan->ee)); + val |=BIT (bchan->id); +writel_relaxed (val, bdev->regs +BAM_IRQ_SRCS_MSK_EE (bchan->ee)); + +/* set fixed direction and mode, then enable channel */ + val =P_EN |P_SYS_MODE ; +if (bchan->slave.direction ==DMA_DEV_TO_MEM ) + val |=P_DIRECTION ; + +/* make sure the other stores occur before enabling channel */ +wmb (); +writel_relaxed (val, bdev->regs +BAM_P_CTRL (bchan->id)); + +/* do bookkeeping for tracking used EEs, used during IRQ handling */ +set_bit (bchan->ee, &bdev->enabled_ees); + + bchan->head =0 ; + bchan->tail =0 ; + +return BAM_DESC_FIFO_SIZE ; +} + +/** +* bam_free_chan - Frees dma resources associated with specific channel +* @chan: specified channel +* +* Free the allocated fifo descriptor memory and channel resources +* +*/ +static void bam_free_chan (struct dma_chan *chan) +{ +struct bam_chan *bchan =to_bam_chan (chan); +struct bam_device *bdev = bchan->bdev; +u32 val; + +vchan_free_chan_resources (to_virt_chan (chan)); + +if (bchan->curr_txd) { +dev_err (bchan->bdev->dev,"Cannot free busy channel\n" ); +return ; + } + +bam_reset_channel (bdev, bchan->id); + +dma_free_coherent (bdev->dev,BAM_DESC_FIFO_SIZE , bchan->fifo_virt, + bchan->fifo_phys); + bchan->fifo_virt =NULL ; + +/* mask irq for pipe/channel */ + val =readl_relaxed (bdev->regs +BAM_IRQ_SRCS_MSK_EE (bchan->ee)); + val &= ~BIT (bchan->id); +writel_relaxed (val, bdev->regs +BAM_IRQ_SRCS_MSK_EE (bchan->ee)); + +/* disable irq */ +writel_relaxed (0 , bdev->regs +BAM_P_IRQ_EN (bchan->id)); + +clear_bit (bchan->ee, &bdev->enabled_ees); +} + +/** +* bam_slave_config - set slave configuration for channel +* @chan: dma channel +* @cfg: slave configuration +* +* Sets slave configuration for channel +* Only allow setting direction once. BAM channels are unidirectional +* and the direction is set in hardware. +* +*/ +static void bam_slave_config (struct bam_chan *bchan, +struct dma_slave_config *cfg) +{ +struct bam_device *bdev = bchan->bdev; +u32 maxburst; + +if (bchan->slave.direction ==DMA_DEV_TO_MEM ) + maxburst = bchan->slave.src_maxburst = cfg->src_maxburst; +else + maxburst = bchan->slave.dst_maxburst = cfg->dst_maxburst; + +/* set desc threshold */ +writel_relaxed (maxburst, bdev->regs +BAM_DESC_CNT_TRSHLD ); +} + +/** +* bam_prep_slave_sg - Prep slave sg transaction +* +* @chan: dma channel +* @sgl: scatter gather list +* @sg_len: length of sg +* @direction: DMA transfer direction +* @flags: DMA flags +* @context: transfer context (unused) +*/ +static struct dma_async_tx_descriptor *bam_prep_slave_sg (struct dma_chan *chan, +struct scatterlist *sgl,unsigned int sg_len, +enum dma_transfer_direction direction,unsigned long flags, +void *context) +{ +struct bam_chan *bchan =to_bam_chan (chan); +struct bam_device *bdev = bchan->bdev; +struct bam_async_desc *async_desc; +struct scatterlist *sg; +u32 i; +struct bam_desc_hw *desc; + + +if (!is_slave_direction (direction)) { +dev_err (bdev->dev,"invalid dma direction\n" ); +return NULL ; + } + +/* direction has to match pipe configuration from the slave config */ +if (direction != bchan->slave.direction) { +dev_err (bdev->dev, +"direction does not match configuration\n" ); +return NULL ; + } + +/* allocate enough room to accomodate the number of entries */ + async_desc =kzalloc (sizeof (*async_desc) + + (sg_len *sizeof (struct bam_desc_hw )),GFP_NOWAIT ); + +if (!async_desc) { +dev_err (bdev->dev,"failed to allocate async descriptor\n" ); + goto err_out; + } + + async_desc->num_desc = sg_len; + async_desc->curr_desc = async_desc->desc; + async_desc->dir = (direction ==DMA_DEV_TO_MEM ) ?BAM_PIPE_PRODUCER : +BAM_PIPE_CONSUMER ; + +/* fill in descriptors, align hw descriptor to 8 bytes */ + desc = async_desc->desc; +for_each_sg (sgl, sg, sg_len, i) { +if (sg_dma_len (sg) >BAM_MAX_DATA_SIZE ) { +dev_err (bdev->dev,"segment exceeds max size\n" ); + goto err_out; + } + + desc->addr =sg_dma_address (sg); + desc->size =sg_dma_len (sg); + async_desc->length +=sg_dma_len (sg); + desc++; + } + +return vchan_tx_prep (&bchan->vc, &async_desc->vd, flags); + +err_out: +kfree (async_desc); +return NULL ; +} + +/** +* bam_dma_terminate_all - terminate all transactions +* @chan: dma channel +* +* Idles channel and dequeues and frees all transactions +* No callbacks are done +* +*/ +static void bam_dma_terminate_all (struct dma_chan *chan) +{ +struct bam_chan *bchan =to_bam_chan (chan); +struct bam_device *bdev = bchan->bdev; + +bam_reset_channel (bdev, bchan->id); + +vchan_free_chan_resources (&bchan->vc); +} + +/** +* bam_control - DMA device control +* @chan: dma channel +* @cmd: control cmd +* @arg: cmd argument +* +* Perform DMA control command +* +*/ +static int bam_control (struct dma_chan *chan,enum dma_ctrl_cmd cmd, +unsigned long arg) +{ +struct bam_chan *bchan =to_bam_chan (chan); +struct bam_device *bdev = bchan->bdev; +int ret =0 ; +unsigned long flag; + +switch (cmd) { +case DMA_PAUSE : +spin_lock_irqsave (&bchan->vc.lock, flag); +writel_relaxed (1 , bdev->regs +BAM_P_HALT (bchan->id)); + bchan->paused =1 ; +spin_unlock_irqrestore (&bchan->vc.lock, flag); +break ; +case DMA_RESUME : +spin_lock_irqsave (&bchan->vc.lock, flag); +writel_relaxed (0 , bdev->regs +BAM_P_HALT (bchan->id)); + bchan->paused =0 ; +spin_unlock_irqrestore (&bchan->vc.lock, flag); +break ; +case DMA_TERMINATE_ALL : +spin_lock_irqsave (&bchan->vc.lock, flag); +bam_dma_terminate_all (chan); +spin_unlock_irqrestore (&bchan->vc.lock, flag); +break ; +case DMA_SLAVE_CONFIG : +bam_slave_config (bchan, (struct dma_slave_config *)arg); +break ; +default : + ret = -ENXIO ; +break ; + } + +return ret; +} + +/** +* process_irqs_per_ee - processes the interrupts for a specific ee +* @bdev: bam controller +* @ee: execution environment +* +* This function processes the interrupts for a given execution environment +* +*/ +static u32 process_irqs_per_ee (struct bam_device *bdev,u32 ee) +{ +u32 i, srcs, pipe_stts; +unsigned long flags; +struct bam_async_desc *async_desc; + + + srcs =readl_relaxed (bdev->regs +BAM_IRQ_SRCS_EE (ee)); + +/* return early if no pipe/channel interrupts are present */ +if (!(srcs &P_IRQ )) +return srcs; + +for (i =0 ; i < bdev->num_channels; i++) { +struct bam_chan *bchan = &bdev->channels[i]; +if (srcs &BIT (i)) { +/* clear pipe irq */ + pipe_stts =readl_relaxed (bdev->regs + +BAM_P_IRQ_STTS (i)); + +writel_relaxed (pipe_stts, bdev->regs + +BAM_P_IRQ_CLR (i)); + +spin_lock_irqsave (&bchan->vc.lock, flags); + async_desc = bchan->curr_txd; + +if (async_desc) { + async_desc->num_desc -= async_desc->xfer_len; + async_desc->curr_desc += async_desc->xfer_len; + bchan->curr_txd =NULL ; + +/* manage FIFO */ + bchan->head += async_desc->xfer_len; + bchan->head %=MAX_DESCRIPTORS ; + +/* if complete, process cookie. Otherwise +push back to front of desc_issued so that +it gets restarted by the tasklet */ +if (!async_desc->num_desc) +vchan_cookie_complete (&async_desc->vd); +else +list_add (&async_desc->vd.node, + &bchan->vc.desc_issued); + } + +spin_unlock_irqrestore (&bchan->vc.lock, flags); + } + } + +return srcs; +} + +/** +* bam_dma_irq - irq handler for bam controller +* @irq: IRQ of interrupt +* @data: callback data +* +* IRQ handler for the bam controller +*/ +static irqreturn_t bam_dma_irq (int irq,void *data) +{ +struct bam_device *bdev = (struct bam_device *)data; +u32 clr_mask =0 , srcs =0 ; +u32 i; + + +for (i =0 ; i < bdev->num_ees; i++) +if (test_bit (i, &bdev->enabled_ees)) + srcs |=process_irqs_per_ee (bdev, i); + +/* kick off tasklet to start next dma transfer */ +if (srcs &P_IRQ ) +tasklet_schedule (&bdev->task); + +if (srcs &BAM_IRQ ) + clr_mask =readl_relaxed (bdev->regs +BAM_IRQ_STTS ); + +/* don't allow reorder of the various accesses to the BAM registers */ +mb (); + +writel_relaxed (clr_mask, bdev->regs +BAM_IRQ_CLR ); + +return IRQ_HANDLED ; +} + +/** +* bam_tx_status - returns status of transaction +* @chan: dma channel +* @cookie: transaction cookie +* @txstate: DMA transaction state +* +* Return status of dma transaction +*/ +static enum dma_status bam_tx_status (struct dma_chan *chan,dma_cookie_t cookie, +struct dma_tx_state *txstate)
drivers/dma/qcom_bam_dma.c line 447
Quoted 10 lines
drivers/dma/qcom_bam_dma.c new file +10
-0+{ +struct bam_chan *bchan =to_bam_chan (chan); +struct virt_dma_desc *vd; +int ret; +size_t residue =0 ; +unsigned int i; +unsigned long flags; + + ret =dma_cookie_status (chan, cookie, txstate); +
Redundant empty line.
Quoted 5 lines
drivers/dma/qcom_bam_dma.c new file +5
-0+if (ret ==DMA_COMPLETE ) +return ret; + +if (!txstate) +return bchan->paused ?DMA_PAUSED : ret;
drivers/dma/qcom_bam_dma.c line 462
Quoted 10 lines
drivers/dma/qcom_bam_dma.c new file +10
-0+ +spin_lock_irqsave (&bchan->vc.lock, flags); + vd =vchan_find_desc (&bchan->vc, cookie); +if (vd) + residue = container_of(vd, struct bam_async_desc, vd)->length; +else if (bchan->curr_txd && bchan->curr_txd->vd.tx.cookie == cookie) +for (i =0 ; i < bchan->curr_txd->num_desc; i++) + residue += bchan->curr_txd->curr_desc[i].size; + +dma_set_residue (txstate, residue);
I'm pretty sure you could do this outside of spin lock.
Quoted 40 lines
drivers/dma/qcom_bam_dma.c new file +39
-0+ +spin_unlock_irqrestore (&bchan->vc.lock, flags); + +if (ret ==DMA_IN_PROGRESS && bchan->paused) + ret =DMA_PAUSED ; + +return ret; +} + +/** +* bam_start_dma - start next transaction +* @bchan - bam dma channel +* +* Note: must hold bam dma channel vc.lock +*/ +static void bam_start_dma (struct bam_chan *bchan) +{ +struct virt_dma_desc *vd =vchan_next_desc (&bchan->vc); +struct bam_device *bdev = bchan->bdev; +struct bam_async_desc *async_desc; +struct bam_desc_hw *desc; +struct bam_desc_hw *fifo =PTR_ALIGN (bchan->fifo_virt, +sizeof (struct bam_desc_hw )); + +if (!vd) +return ; + +list_del (&vd->node); + + async_desc = container_of(vd, struct bam_async_desc, vd); + bchan->curr_txd = async_desc; + + desc = bchan->curr_txd->curr_desc; + +if (async_desc->num_desc >MAX_DESCRIPTORS ) + async_desc->xfer_len =MAX_DESCRIPTORS ; +else + async_desc->xfer_len = async_desc->num_desc; +
drivers/dma/qcom_bam_dma.c line 511
Quoted 10 lines
drivers/dma/qcom_bam_dma.c new file +10
-0+/* set INT on last descriptor */ + desc[async_desc->xfer_len -1 ].flags |=DESC_FLAG_INT ; + +if (bchan->tail + async_desc->xfer_len >MAX_DESCRIPTORS ) { +u32 partial =MAX_DESCRIPTORS - bchan->tail; + +memcpy (&fifo[bchan->tail], desc, + partial *sizeof (struct bam_desc_hw )); +memcpy (fifo, &desc[partial], (async_desc->xfer_len - partial) * +sizeof (struct bam_desc_hw ));
I'm just curious if you could avoid memcpys at all somehow.
drivers/dma/qcom_bam_dma.c line 512
Quoted 1 line
drivers/dma/qcom_bam_dma.c new file +1
-0+ }else
Keep style
} else {
...
}
Have you run checkpatch.pl?
Quoted 176 lines
drivers/dma/qcom_bam_dma.c new file +176
-0+memcpy (&fifo[bchan->tail], desc, + async_desc->xfer_len *sizeof (struct bam_desc_hw )); + + bchan->tail += async_desc->xfer_len; + bchan->tail %=MAX_DESCRIPTORS ; + +/* ensure descriptor writes and dma start not reordered */ +wmb (); +writel_relaxed (bchan->tail *sizeof (struct bam_desc_hw ), + bdev->regs +BAM_P_EVNT_REG (bchan->id)); +} + +/** +* dma_tasklet - DMA IRQ tasklet +* @data: tasklet argument (bam controller structure) +* +* Sets up next DMA operation and then processes all completed transactions +*/ +static void dma_tasklet (unsigned long data) +{ +struct bam_device *bdev = (struct bam_device *)data; +struct bam_chan *bchan; +unsigned long flags; +unsigned int i; + +/* go through the channels and kick off transactions */ +for (i =0 ; i < bdev->num_channels; i++) { + bchan = &bdev->channels[i]; +spin_lock_irqsave (&bchan->vc.lock, flags); + +if (!list_empty (&bchan->vc.desc_issued) && !bchan->curr_txd) +bam_start_dma (bchan); +spin_unlock_irqrestore (&bchan->vc.lock, flags); + } +} + +/** +* bam_issue_pending - starts pending transactions +* @chan: dma channel +* +* Calls tasklet directly which in turn starts any pending transactions +*/ +static void bam_issue_pending (struct dma_chan *chan) +{ +struct bam_chan *bchan =to_bam_chan (chan); +unsigned long flags; + +spin_lock_irqsave (&bchan->vc.lock, flags); + +/* if work pending and idle, start a transaction */ +if (vchan_issue_pending (&bchan->vc) && !bchan->curr_txd) +bam_start_dma (bchan); + +spin_unlock_irqrestore (&bchan->vc.lock, flags); +} + +/** +* bam_dma_free_desc - free descriptor memory +* @vd: virtual descriptor +* +*/ +static void bam_dma_free_desc (struct virt_dma_desc *vd) +{ +struct bam_async_desc *async_desc =container_of (vd, + struct bam_async_desc, vd); + +kfree (async_desc); +} + +struct bam_filter_args { +struct dma_device *dev; +u32 id; +u32 ee; +u32 dir; +}; + +static bool bam_dma_filter (struct dma_chan *chan,void *data) +{ +struct bam_filter_args *args = data; +struct bam_chan *bchan =to_bam_chan (chan); + +if (args->dev == chan->device && + args->id == bchan->id) { + +/* we found the channel, so lets set the EE and dir */ + bchan->ee = args->ee; + bchan->slave.direction = args->dir ? +DMA_DEV_TO_MEM :DMA_MEM_TO_DEV ; +return true; + } + +return false; +} + +static struct dma_chan *bam_dma_xlate (struct of_phandle_args *dma_spec, +struct of_dma *of) +{ +struct bam_filter_args args; +dma_cap_mask_t cap; + +if (dma_spec->args_count !=3 ) +return NULL ; + + args.dev = of->of_dma_data; + args.id = dma_spec->args[0 ]; + args.ee = dma_spec->args[1 ]; + args.dir = dma_spec->args[2 ]; + +dma_cap_zero (cap); +dma_cap_set (DMA_SLAVE , cap); + +return dma_request_channel (cap, bam_dma_filter, &args); +} + +/** +* bam_init +* @bdev: bam device +* +* Initialization helper for global bam registers +*/ +static void bam_init (struct bam_device *bdev) +{ +u32 val; + +/* read versioning information */ + val =readl_relaxed (bdev->regs +BAM_REVISION ); + bdev->num_ees = val &NUM_EES_MASK ; + + val =readl_relaxed (bdev->regs +BAM_NUM_PIPES ); + bdev->num_channels = val &BAM_NUM_PIPES_MASK ; + +/* s/w reset bam */ +/* after reset all pipes are disabled and idle */ + val =readl_relaxed (bdev->regs +BAM_CTRL ); + val |=BAM_SW_RST ; +writel_relaxed (val, bdev->regs +BAM_CTRL ); + val &= ~BAM_SW_RST ; +writel_relaxed (val, bdev->regs +BAM_CTRL ); + +/* make sure previous stores are visible before enabling BAM */ +wmb (); + +/* enable bam */ + val |=BAM_EN ; +writel_relaxed (val, bdev->regs +BAM_CTRL ); + +/* set descriptor threshhold, start with 4 bytes */ +writel_relaxed (DEFAULT_CNT_THRSHLD , bdev->regs +BAM_DESC_CNT_TRSHLD ); + +/* Enable default set of h/w workarounds, ie all except BAM_FULL_PIPE */ +writel_relaxed (BAM_CNFG_BITS_DEFAULT , bdev->regs +BAM_CNFG_BITS ); + +/* enable irqs for errors */ +writel_relaxed (BAM_ERROR_EN |BAM_HRESP_ERR_EN , + bdev->regs +BAM_IRQ_EN ); +} + +static void bam_channel_init (struct bam_device *bdev,struct bam_chan *bchan, +u32 index) +{ + bchan->id = index; + bchan->bdev = bdev; + +vchan_init (&bchan->vc, &bdev->common); + bchan->vc.desc_free = bam_dma_free_desc; + +bam_reset_channel (bdev, bchan->id); +} + +static int bam_dma_probe (struct platform_device *pdev) +{ +struct bam_device *bdev; +struct resource *iores, *irq_res; +int ret, i; + + bdev =devm_kzalloc (&pdev->dev,sizeof (*bdev),GFP_KERNEL );
drivers/dma/qcom_bam_dma.c line 698
Quoted 10 lines
drivers/dma/qcom_bam_dma.c new file +10
-0+if (!bdev) +return -ENOMEM ; + + bdev->dev = &pdev->dev; + + iores =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!iores) { +dev_err (bdev->dev,"register resource is missing\n" ); +return -EINVAL ; + }
Useless check and messaging, devm_ioremap_resource will do this for you.
Quoted 16 lines
drivers/dma/qcom_bam_dma.c new file +16
-0+ + bdev->regs =devm_ioremap_resource (&pdev->dev, iores); +if (IS_ERR (bdev->regs)) +return PTR_ERR (bdev->regs); + + irq_res =platform_get_resource (pdev,IORESOURCE_IRQ ,0 ); +if (!irq_res) { +dev_err (bdev->dev,"irq resource is missing\n" ); +return -EINVAL ; + } + + bdev->bamclk =devm_clk_get (bdev->dev,"bam_clk" ); +if (IS_ERR (bdev->bamclk)) +return PTR_ERR (bdev->bamclk); + + ret =clk_prepare_enable (bdev->bamclk);
drivers/dma/qcom_bam_dma.c line 724
Quoted 10 lines
drivers/dma/qcom_bam_dma.c new file +10
-0+if (ret) { +dev_err (bdev->dev,"failed to prepare/enable clock" ); +return ret; + } + +bam_init (bdev); + +tasklet_init (&bdev->task, dma_tasklet, (unsigned long )bdev); + + bdev->channels = devm_kzalloc(bdev->dev,
devm_kcalloc.
Quoted 108 lines
drivers/dma/qcom_bam_dma.c new file +105
-0+sizeof (*bdev->channels) * bdev->num_channels, + GFP_KERNEL); + +if (!bdev->channels) { + ret = -ENOMEM ; + goto err_disable_clk; + } + +/* allocate and initialize channels */ +INIT_LIST_HEAD (&bdev->common.channels); + +for (i =0 ; i < bdev->num_channels; i++) +bam_channel_init (bdev, &bdev->channels[i], i); + + ret =devm_request_irq (bdev->dev, irq_res->start, bam_dma_irq, +IRQF_TRIGGER_HIGH ,"bam_dma" , bdev); +if (ret) { +dev_err (bdev->dev,"cannot register IRQ\n" ); + goto err_disable_clk; + } + +/* set max dma segment size */ + bdev->common.dev = bdev->dev; + bdev->common.dev->dma_parms = &bdev->dma_parms; + ret =dma_set_max_seg_size (bdev->common.dev,BAM_MAX_DATA_SIZE ); +if (ret) { +dev_err (bdev->dev,"cannot set maximum segment size\n" ); + goto err_disable_clk; + } + +platform_set_drvdata (pdev, bdev); + +/* set capabilities */ +dma_cap_zero (bdev->common.cap_mask); +dma_cap_set (DMA_SLAVE , bdev->common.cap_mask); + +/* initialize dmaengine apis */ + bdev->common.device_alloc_chan_resources = bam_alloc_chan; + bdev->common.device_free_chan_resources = bam_free_chan; + bdev->common.device_prep_slave_sg = bam_prep_slave_sg; + bdev->common.device_control = bam_control; + bdev->common.device_issue_pending = bam_issue_pending; + bdev->common.device_tx_status = bam_tx_status; + bdev->common.dev = bdev->dev; + + ret =dma_async_device_register (&bdev->common); +if (ret) { +dev_err (bdev->dev,"failed to register dma async device\n" ); + goto err_disable_clk; + } + +if (pdev->dev.of_node) { + ret =of_dma_controller_register (pdev->dev.of_node, + bam_dma_xlate, &bdev->common); + +if (ret) { +dev_err (bdev->dev,"failed to register of_dma\n" ); + goto err_unregister_dma; + } + } + +return 0 ; + +err_unregister_dma: +dma_async_device_unregister (&bdev->common); +err_disable_clk: +clk_disable_unprepare (bdev->bamclk); +return ret; +} + +static int bam_dma_remove (struct platform_device *pdev) +{ +struct bam_device *bdev =platform_get_drvdata (pdev); + +dma_async_device_unregister (&bdev->common); + +if (pdev->dev.of_node) +of_dma_controller_free (pdev->dev.of_node); + +clk_disable_unprepare (bdev->bamclk); + +return 0 ; +} + +#ifdef CONFIG_OF +static const struct of_device_id bam_of_match[] = { + { .compatible ="qcom,bam-v1.4.0" , }, + { .compatible ="qcom,bam-v1.4.1" , }, + {} +}; +MODULE_DEVICE_TABLE (of, bam_of_match); +#endif + +static struct platform_driver bam_dma_driver = { + .probe = bam_dma_probe, + .remove = bam_dma_remove, + .driver = { + .name ="bam-dma-engine" , + .owner =THIS_MODULE , + .of_match_table =of_match_ptr (bam_of_match), + }, +}; + +static int __init bam_dma_init (void ) +{
drivers/dma/qcom_bam_dma.c line 839
Quoted 10 lines
drivers/dma/qcom_bam_dma.c new file +10
-0+return platform_driver_register (&bam_dma_driver); +} + +static void __exit bam_dma_exit(void) +{ +return platform_driver_unregister (&bam_dma_driver); +} + +module_init (bam_dma_init); +module_exit (bam_dma_exit);
module_platform_driver() ?
drivers/dma/qcom_bam_dma.h line 2
Quoted 12 lines
drivers/dma/qcom_bam_dma.c new file +4
-0+ +MODULE_AUTHOR ("Andy Gross <[email protected]>" ); +MODULE_DESCRIPTION ("QCOM BAM DMA engine driver" ); +MODULE_LICENSE ("GPL v2" );drivers/dma/qcom_bam_dma.h new file +2
-0@@ -0,0 +1,268 @@ +/* +* Copyright (c) 2013, The Linux Foundation. All rights reserved.
2014 ?
Quoted 266 lines
drivers/dma/qcom_bam_dma.h new file +266
-0+* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 and +* only version 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ +#ifndef __QCOM_BAM_DMA_H__ +#define __QCOM_BAM_DMA_H__ + +#include <linux/dmaengine.h> +#include "virt-dma.h" + +enum bam_channel_dir { +BAM_PIPE_CONSUMER =0 ,/* channel reads from data-fifo or memory */ +BAM_PIPE_PRODUCER ,/* channel writes to data-fifo or memory */ +}; + +struct bam_desc_hw { +u32 addr;/* Buffer physical address */ +u16 size;/* Buffer size in bytes */ +u16 flags; +} __packed; + +#define DESC_FLAG_INT BIT(15) +#define DESC_FLAG_EOT BIT(14) +#define DESC_FLAG_EOB BIT(13) + +struct bam_async_desc { +struct virt_dma_desc vd; + +u32 num_desc; +u32 xfer_len; +struct bam_desc_hw *curr_desc; + +enum bam_channel_dir dir; +size_t length; +struct bam_desc_hw desc[0 ]; +}; + +#define BAM_CTRL 0x0000 +#define BAM_REVISION 0x0004 +#define BAM_SW_REVISION 0x0080 +#define BAM_NUM_PIPES 0x003C +#define BAM_TIMER 0x0040 +#define BAM_TIMER_CTRL 0x0044 +#define BAM_DESC_CNT_TRSHLD 0x0008 +#define BAM_IRQ_SRCS 0x000C +#define BAM_IRQ_SRCS_MSK 0x0010 +#define BAM_IRQ_SRCS_UNMASKED 0x0030 +#define BAM_IRQ_STTS 0x0014 +#define BAM_IRQ_CLR 0x0018 +#define BAM_IRQ_EN 0x001C +#define BAM_CNFG_BITS 0x007C +#define BAM_IRQ_SRCS_EE (pipe) (0x0800 + ((pipe) * 0x80)) +#define BAM_IRQ_SRCS_MSK_EE (pipe) (0x0804 + ((pipe) * 0x80)) +#define BAM_P_CTRL (pipe) (0x1000 + ((pipe) * 0x1000)) +#define BAM_P_RST (pipe) (0x1004 + ((pipe) * 0x1000)) +#define BAM_P_HALT (pipe) (0x1008 + ((pipe) * 0x1000)) +#define BAM_P_IRQ_STTS (pipe) (0x1010 + ((pipe) * 0x1000)) +#define BAM_P_IRQ_CLR (pipe) (0x1014 + ((pipe) * 0x1000)) +#define BAM_P_IRQ_EN (pipe) (0x1018 + ((pipe) * 0x1000)) +#define BAM_P_EVNT_DEST_ADDR (pipe) (0x182C + ((pipe) * 0x1000)) +#define BAM_P_EVNT_REG (pipe) (0x1818 + ((pipe) * 0x1000)) +#define BAM_P_SW_OFSTS (pipe) (0x1800 + ((pipe) * 0x1000)) +#define BAM_P_DATA_FIFO_ADDR (pipe) (0x1824 + ((pipe) * 0x1000)) +#define BAM_P_DESC_FIFO_ADDR (pipe) (0x181C + ((pipe) * 0x1000)) +#define BAM_P_EVNT_TRSHLD (pipe) (0x1828 + ((pipe) * 0x1000)) +#define BAM_P_FIFO_SIZES (pipe) (0x1820 + ((pipe) * 0x1000)) + +/* BAM CTRL */ +#define BAM_SW_RST BIT(0) +#define BAM_EN BIT(1) +#define BAM_EN_ACCUM BIT(4) +#define BAM_TESTBUS_SEL_SHIFT 5 +#define BAM_TESTBUS_SEL_MASK 0x3F +#define BAM_DESC_CACHE_SEL_SHIFT 13 +#define BAM_DESC_CACHE_SEL_MASK 0x3 +#define BAM_CACHED_DESC_STORE BIT(15) +#define IBC_DISABLE BIT(16) + +/* BAM REVISION */ +#define REVISION_SHIFT 0 +#define REVISION_MASK 0xFF +#define NUM_EES_SHIFT 8 +#define NUM_EES_MASK 0xF +#define CE_BUFFER_SIZE BIT(13) +#define AXI_ACTIVE BIT(14) +#define USE_VMIDMT BIT(15) +#define SECURED BIT(16) +#define BAM_HAS_NO_BYPASS BIT(17) +#define HIGH_FREQUENCY_BAM BIT(18) +#define INACTIV_TMRS_EXST BIT(19) +#define NUM_INACTIV_TMRS BIT(20) +#define DESC_CACHE_DEPTH_SHIFT 21 +#define DESC_CACHE_DEPTH_1 (0 << DESC_CACHE_DEPTH_SHIFT) +#define DESC_CACHE_DEPTH_2 (1 << DESC_CACHE_DEPTH_SHIFT) +#define DESC_CACHE_DEPTH_3 (2 << DESC_CACHE_DEPTH_SHIFT) +#define DESC_CACHE_DEPTH_4 (3 << DESC_CACHE_DEPTH_SHIFT) +#define CMD_DESC_EN BIT(23) +#define INACTIV_TMR_BASE_SHIFT 24 +#define INACTIV_TMR_BASE_MASK 0xFF + +/* BAM NUM PIPES */ +#define BAM_NUM_PIPES_SHIFT 0 +#define BAM_NUM_PIPES_MASK 0xFF +#define PERIPH_NON_PIPE_GRP_SHIFT 16 +#define PERIPH_NON_PIP_GRP_MASK 0xFF +#define BAM_NON_PIPE_GRP_SHIFT 24 +#define BAM_NON_PIPE_GRP_MASK 0xFF + +/* BAM CNFG BITS */ +#define BAM_PIPE_CNFG BIT(2) +#define BAM_FULL_PIPE BIT(11) +#define BAM_NO_EXT_P_RST BIT(12) +#define BAM_IBC_DISABLE BIT(13) +#define BAM_SB_CLK_REQ BIT(14) +#define BAM_PSM_CSW_REQ BIT(15) +#define BAM_PSM_P_RES BIT(16) +#define BAM_AU_P_RES BIT(17) +#define BAM_SI_P_RES BIT(18) +#define BAM_WB_P_RES BIT(19) +#define BAM_WB_BLK_CSW BIT(20) +#define BAM_WB_CSW_ACK_IDL BIT(21) +#define BAM_WB_RETR_SVPNT BIT(22) +#define BAM_WB_DSC_AVL_P_RST BIT(23) +#define BAM_REG_P_EN BIT(24) +#define BAM_PSM_P_HD_DATA BIT(25) +#define BAM_AU_ACCUMED BIT(26) +#define BAM_CMD_ENABLE BIT(27) + +#define BAM_CNFG_BITS_DEFAULT (BAM_PIPE_CNFG | \ + BAM_NO_EXT_P_RST | \ + BAM_IBC_DISABLE | \ + BAM_SB_CLK_REQ | \ + BAM_PSM_CSW_REQ | \ + BAM_PSM_P_RES | \ + BAM_AU_P_RES | \ + BAM_SI_P_RES | \ + BAM_WB_P_RES | \ + BAM_WB_BLK_CSW | \ + BAM_WB_CSW_ACK_IDL | \ + BAM_WB_RETR_SVPNT | \ + BAM_WB_DSC_AVL_P_RST | \ + BAM_REG_P_EN | \ + BAM_PSM_P_HD_DATA | \ + BAM_AU_ACCUMED | \ + BAM_CMD_ENABLE) + +/* PIPE CTRL */ +#define P_EN BIT(1) +#define P_DIRECTION BIT(3) +#define P_SYS_STRM BIT(4) +#define P_SYS_MODE BIT(5) +#define P_AUTO_EOB BIT(6) +#define P_AUTO_EOB_SEL_SHIFT 7 +#define P_AUTO_EOB_SEL_512 (0 << P_AUTO_EOB_SEL_SHIFT) +#define P_AUTO_EOB_SEL_256 (1 << P_AUTO_EOB_SEL_SHIFT) +#define P_AUTO_EOB_SEL_128 (2 << P_AUTO_EOB_SEL_SHIFT) +#define P_AUTO_EOB_SEL_64 (3 << P_AUTO_EOB_SEL_SHIFT) +#define P_PREFETCH_LIMIT_SHIFT 9 +#define P_PREFETCH_LIMIT_32 (0 << P_PREFETCH_LIMIT_SHIFT) +#define P_PREFETCH_LIMIT_16 (1 << P_PREFETCH_LIMIT_SHIFT) +#define P_PREFETCH_LIMIT_4 (2 << P_PREFETCH_LIMIT_SHIFT) +#define P_WRITE_NWD BIT(11) +#define P_LOCK_GROUP_SHIFT 16 +#define P_LOCK_GROUP_MASK 0x1F + +/* BAM_DESC_CNT_TRSHLD */ +#define CNT_TRSHLD 0xffff +#define DEFAULT_CNT_THRSHLD 0x4 + +/* BAM_IRQ_SRCS */ +#define BAM_IRQ BIT(31) +#define P_IRQ 0x7fffffff + +/* BAM_IRQ_SRCS_MSK */ +#define BAM_IRQ_MSK BAM_IRQ +#define P_IRQ_MSK P_IRQ + +/* BAM_IRQ_STTS */ +#define BAM_TIMER_IRQ BIT(4) +#define BAM_EMPTY_IRQ BIT(3) +#define BAM_ERROR_IRQ BIT(2) +#define BAM_HRESP_ERR_IRQ BIT(1) + +/* BAM_IRQ_CLR */ +#define BAM_TIMER_CLR BIT(4) +#define BAM_EMPTY_CLR BIT(3) +#define BAM_ERROR_CLR BIT(2) +#define BAM_HRESP_ERR_CLR BIT(1) + +/* BAM_IRQ_EN */ +#define BAM_TIMER_EN BIT(4) +#define BAM_EMPTY_EN BIT(3) +#define BAM_ERROR_EN BIT(2) +#define BAM_HRESP_ERR_EN BIT(1) + +/* BAM_P_IRQ_EN */ +#define P_PRCSD_DESC_EN BIT(0) +#define P_TIMER_EN BIT(1) +#define P_WAKE_EN BIT(2) +#define P_OUT_OF_DESC_EN BIT(3) +#define P_ERR_EN BIT(4) +#define P_TRNSFR_END_EN BIT(5) +#define P_DEFAULT_IRQS_EN (P_PRCSD_DESC_EN | P_ERR_EN | P_TRNSFR_END_EN) + +/* BAM_P_SW_OFSTS */ +#define P_SW_OFSTS_MASK 0xffff + +#define BAM_DESC_FIFO_SIZE SZ_32K +#define MAX_DESCRIPTORS (BAM_DESC_FIFO_SIZE / sizeof(struct bam_desc_hw) - 1) +#define BAM_MAX_DATA_SIZE (SZ_32K - 8) + +struct bam_chan { +struct virt_dma_chan vc; + +struct bam_device *bdev; + +/* configuration from device tree */ +u32 id; +u32 ee; + +struct bam_async_desc *curr_txd;/* current running dma */ + +/* runtime configuration */ +struct dma_slave_config slave; + +/* fifo storage */ +struct bam_desc_hw *fifo_virt; +dma_addr_t fifo_phys; + +/* fifo markers */ +unsigned short head;/* start of active descriptor entries */ +unsigned short tail;/* end of active descriptor entries */ + +unsigned int paused;/* is the channel paused? */ + +struct list_head node; +}; + +static inline struct bam_chan *to_bam_chan (struct dma_chan *common) +{ + return container_of(common, struct bam_chan, vc.chan); +} + +struct bam_device { +void __iomem *regs; +struct device *dev; +struct dma_device common; +struct device_dma_parameters dma_parms; +struct bam_chan *channels; +u32 num_channels; +u32 num_ees; +unsigned long enabled_ees; +int irq; +struct clk *bamclk; + +/* dma start transaction tasklet */ +struct tasklet_struct task; +}; + +#endif /* __QCOM_BAM_DMA_H__ */
Signature · 12 lines
Andy Shevchenko <[email protected]> Intel Finland Oy --------------------------------------------------------------------- Intel Finland Oy Registered Address: PL 281, 00181 Helsinki Business Identity Code: 0357606 - 4 Domiciled in Helsinki This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
PATCH v2 1/2 dmaengine: add Qualcomm BAM dma driver
Quoted 22 lines · Andriy
Quoted 21 lines · Andy Gross
Add the DMA engine driver for the QCOM Bus Access Manager (BAM) DMA controller found in the MSM 8x74 platforms.
Each BAM DMA device is associated with a specific on-chip peripheral. Each channel provides a uni-directional data transfer engine that is capable of transferring data between the peripheral and system memory (System mode), or between two peripherals (BAM2BAM).
The initial release of this driver only supports slave transfers between peripherals and system memory.
Signed-off-by Andy Gross <[email protected]>--- drivers/dma/Kconfig | 9 + drivers/dma/Makefile | 1 + drivers/dma/qcom_bam_dma.c | 843 +++++++++++++++++++++++++++++++++++++++++++++ drivers/dma/qcom_bam_dma.h | 268 ++++++++++++++ 4 files changed, 1121 insertions(+) create mode 100644 drivers/dma/qcom_bam_dma.c create mode 100644 drivers/dma/qcom_bam_dma.h
[...]
Quoted 13 lines
Quoted 13 lines
+ *
bam_tx_status- returns status of transaction
+ * @chan: dma channel
+ * @cookie: transaction cookie
+ * @txstate: DMA transaction state
+ *
+ * Return status of dma transaction
+ */drivers/dma/qcom_bam_dma.c new file +6
-0+static enum dma_status bam_tx_status (struct dma_chan *chan,dma_cookie_t cookie, +struct dma_tx_state *txstate) +{ +struct bam_chan *bchan =to_bam_chan (chan); +struct virt_dma_desc *vd; +int ret;
Quoted 9 lines
drivers/dma/qcom_bam_dma.c line 447
Quoted 6 lines
drivers/dma/qcom_bam_dma.c new file +6
-0+size_t residue =0 ; +unsigned int i; +unsigned long flags; + + ret =dma_cookie_status (chan, cookie, txstate); +Redundant empty line.
Will remove.
Quoted 9 lines
Quoted 9 lines
drivers/dma/qcom_bam_dma.c new file +9
-0+if (ret ==DMA_COMPLETE ) +return ret; + +if (!txstate) +return bchan->paused ?DMA_PAUSED : ret; + +spin_lock_irqsave (&bchan->vc.lock, flags); + vd =vchan_find_desc (&bchan->vc, cookie); +if (vd)
Quoted 9 lines
drivers/dma/qcom_bam_dma.c line 462
Quoted 6 lines
drivers/dma/qcom_bam_dma.c new file +6
-0+ residue = container_of(vd, struct bam_async_desc, vd)->length; + else if (bchan->curr_txd && bchan->curr_txd->vd.tx.cookie == cookie) + for (i = 0; i < bchan->curr_txd->num_desc; i++) + residue += bchan->curr_txd->curr_desc[i].size; + +dma_set_residue (txstate, residue);I'm pretty sure you could do this outside of spin lock.
Yes, I'll move it.
Quoted 44 lines
Quoted 44 lines
drivers/dma/qcom_bam_dma.c new file +43
-0+ +spin_unlock_irqrestore (&bchan->vc.lock, flags); + +if (ret ==DMA_IN_PROGRESS && bchan->paused) + ret =DMA_PAUSED ; + +return ret; +} + +/** +* bam_start_dma - start next transaction +* @bchan - bam dma channel +* +* Note: must hold bam dma channel vc.lock +*/ +static void bam_start_dma (struct bam_chan *bchan) +{ +struct virt_dma_desc *vd =vchan_next_desc (&bchan->vc); +struct bam_device *bdev = bchan->bdev; +struct bam_async_desc *async_desc; +struct bam_desc_hw *desc; +struct bam_desc_hw *fifo =PTR_ALIGN (bchan->fifo_virt, +sizeof (struct bam_desc_hw )); + +if (!vd) +return ; + +list_del (&vd->node); + + async_desc = container_of(vd, struct bam_async_desc, vd); + bchan->curr_txd = async_desc; + + desc = bchan->curr_txd->curr_desc; + +if (async_desc->num_desc >MAX_DESCRIPTORS ) + async_desc->xfer_len =MAX_DESCRIPTORS ; +else + async_desc->xfer_len = async_desc->num_desc; + +/* set INT on last descriptor */ + desc[async_desc->xfer_len -1 ].flags |=DESC_FLAG_INT ; + +if (bchan->tail + async_desc->xfer_len >MAX_DESCRIPTORS ) {
Quoted 9 lines
drivers/dma/qcom_bam_dma.c line 511
Quoted 6 lines
drivers/dma/qcom_bam_dma.c new file +6
-0+u32 partial =MAX_DESCRIPTORS - bchan->tail; + +memcpy (&fifo[bchan->tail], desc, + partial *sizeof (struct bam_desc_hw )); +memcpy (fifo, &desc[partial], (async_desc->xfer_len - partial) * +sizeof (struct bam_desc_hw ));I'm just curious if you could avoid memcpys at all somehow.
Unfortunately not. The descriptors have to be copied into the FIFO memory that is being used by the dma controller for this channel. Due to the way the FIFO works, I have to copy into the FIFO during either the issue_pending or when I start the next transaction. Either way, it means copying from the txd to the FIFO.
Quoted 4 lines
drivers/dma/qcom_bam_dma.c line 512
Quoted 1 line
drivers/dma/qcom_bam_dma.c new file +1
-0+ }else Keep style
OK.
Quoted 6 lines
} else {
...
}Have you run checkpatch.pl?
Yes. And I fixed any discrepancies before sending this.
Quoted 180 lines
Quoted 180 lines
drivers/dma/qcom_bam_dma.c new file +180
-0+memcpy (&fifo[bchan->tail], desc, + async_desc->xfer_len *sizeof (struct bam_desc_hw )); + + bchan->tail += async_desc->xfer_len; + bchan->tail %=MAX_DESCRIPTORS ; + +/* ensure descriptor writes and dma start not reordered */ +wmb (); +writel_relaxed (bchan->tail *sizeof (struct bam_desc_hw ), + bdev->regs +BAM_P_EVNT_REG (bchan->id)); +} + +/** +* dma_tasklet - DMA IRQ tasklet +* @data: tasklet argument (bam controller structure) +* +* Sets up next DMA operation and then processes all completed transactions +*/ +static void dma_tasklet (unsigned long data) +{ +struct bam_device *bdev = (struct bam_device *)data; +struct bam_chan *bchan; +unsigned long flags; +unsigned int i; + +/* go through the channels and kick off transactions */ +for (i =0 ; i < bdev->num_channels; i++) { + bchan = &bdev->channels[i]; +spin_lock_irqsave (&bchan->vc.lock, flags); + +if (!list_empty (&bchan->vc.desc_issued) && !bchan->curr_txd) +bam_start_dma (bchan); +spin_unlock_irqrestore (&bchan->vc.lock, flags); + } +} + +/** +* bam_issue_pending - starts pending transactions +* @chan: dma channel +* +* Calls tasklet directly which in turn starts any pending transactions +*/ +static void bam_issue_pending (struct dma_chan *chan) +{ +struct bam_chan *bchan =to_bam_chan (chan); +unsigned long flags; + +spin_lock_irqsave (&bchan->vc.lock, flags); + +/* if work pending and idle, start a transaction */ +if (vchan_issue_pending (&bchan->vc) && !bchan->curr_txd) +bam_start_dma (bchan); + +spin_unlock_irqrestore (&bchan->vc.lock, flags); +} + +/** +* bam_dma_free_desc - free descriptor memory +* @vd: virtual descriptor +* +*/ +static void bam_dma_free_desc (struct virt_dma_desc *vd) +{ +struct bam_async_desc *async_desc =container_of (vd, + struct bam_async_desc, vd); + +kfree (async_desc); +} + +struct bam_filter_args { +struct dma_device *dev; +u32 id; +u32 ee; +u32 dir; +}; + +static bool bam_dma_filter (struct dma_chan *chan,void *data) +{ +struct bam_filter_args *args = data; +struct bam_chan *bchan =to_bam_chan (chan); + +if (args->dev == chan->device && + args->id == bchan->id) { + +/* we found the channel, so lets set the EE and dir */ + bchan->ee = args->ee; + bchan->slave.direction = args->dir ? +DMA_DEV_TO_MEM :DMA_MEM_TO_DEV ; +return true; + } + +return false; +} + +static struct dma_chan *bam_dma_xlate (struct of_phandle_args *dma_spec, +struct of_dma *of) +{ +struct bam_filter_args args; +dma_cap_mask_t cap; + +if (dma_spec->args_count !=3 ) +return NULL ; + + args.dev = of->of_dma_data; + args.id = dma_spec->args[0 ]; + args.ee = dma_spec->args[1 ]; + args.dir = dma_spec->args[2 ]; + +dma_cap_zero (cap); +dma_cap_set (DMA_SLAVE , cap); + +return dma_request_channel (cap, bam_dma_filter, &args); +} + +/** +* bam_init +* @bdev: bam device +* +* Initialization helper for global bam registers +*/ +static void bam_init (struct bam_device *bdev) +{ +u32 val; + +/* read versioning information */ + val =readl_relaxed (bdev->regs +BAM_REVISION ); + bdev->num_ees = val &NUM_EES_MASK ; + + val =readl_relaxed (bdev->regs +BAM_NUM_PIPES ); + bdev->num_channels = val &BAM_NUM_PIPES_MASK ; + +/* s/w reset bam */ +/* after reset all pipes are disabled and idle */ + val =readl_relaxed (bdev->regs +BAM_CTRL ); + val |=BAM_SW_RST ; +writel_relaxed (val, bdev->regs +BAM_CTRL ); + val &= ~BAM_SW_RST ; +writel_relaxed (val, bdev->regs +BAM_CTRL ); + +/* make sure previous stores are visible before enabling BAM */ +wmb (); + +/* enable bam */ + val |=BAM_EN ; +writel_relaxed (val, bdev->regs +BAM_CTRL ); + +/* set descriptor threshhold, start with 4 bytes */ +writel_relaxed (DEFAULT_CNT_THRSHLD , bdev->regs +BAM_DESC_CNT_TRSHLD ); + +/* Enable default set of h/w workarounds, ie all except BAM_FULL_PIPE */ +writel_relaxed (BAM_CNFG_BITS_DEFAULT , bdev->regs +BAM_CNFG_BITS ); + +/* enable irqs for errors */ +writel_relaxed (BAM_ERROR_EN |BAM_HRESP_ERR_EN , + bdev->regs +BAM_IRQ_EN ); +} + +static void bam_channel_init (struct bam_device *bdev,struct bam_chan *bchan, +u32 index) +{ + bchan->id = index; + bchan->bdev = bdev; + +vchan_init (&bchan->vc, &bdev->common); + bchan->vc.desc_free = bam_dma_free_desc; + +bam_reset_channel (bdev, bchan->id); +} + +static int bam_dma_probe (struct platform_device *pdev) +{ +struct bam_device *bdev; +struct resource *iores, *irq_res; +int ret, i; + + bdev =devm_kzalloc (&pdev->dev,sizeof (*bdev),GFP_KERNEL ); +if (!bdev) +return -ENOMEM ; + + bdev->dev = &pdev->dev;
Quoted 9 lines
drivers/dma/qcom_bam_dma.c line 698
Quoted 6 lines
drivers/dma/qcom_bam_dma.c new file +6
-0+ + iores =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!iores) { +dev_err (bdev->dev,"register resource is missing\n" ); +return -EINVAL ; + }Useless check and messaging,
devm_ioremap_resourcewill do this for you.
Will fix this along with the other resource comment.
Quoted 20 lines
Quoted 20 lines
drivers/dma/qcom_bam_dma.c new file +20
-0+ + bdev->regs =devm_ioremap_resource (&pdev->dev, iores); +if (IS_ERR (bdev->regs)) +return PTR_ERR (bdev->regs); + + irq_res =platform_get_resource (pdev,IORESOURCE_IRQ ,0 ); +if (!irq_res) { +dev_err (bdev->dev,"irq resource is missing\n" ); +return -EINVAL ; + } + + bdev->bamclk =devm_clk_get (bdev->dev,"bam_clk" ); +if (IS_ERR (bdev->bamclk)) +return PTR_ERR (bdev->bamclk); + + ret =clk_prepare_enable (bdev->bamclk); +if (ret) { +dev_err (bdev->dev,"failed to prepare/enable clock" ); +return ret; + }
Quoted 9 lines
drivers/dma/qcom_bam_dma.c line 724
Quoted 6 lines
drivers/dma/qcom_bam_dma.c new file +6
-0+ +bam_init (bdev); + +tasklet_init (&bdev->task, dma_tasklet, (unsigned long )bdev); + + bdev->channels = devm_kzalloc(bdev->dev,
devm_kcalloc.
Will fix.
Quoted 112 lines
Quoted 112 lines
drivers/dma/qcom_bam_dma.c new file +109
-0+sizeof (*bdev->channels) * bdev->num_channels, + GFP_KERNEL); + +if (!bdev->channels) { + ret = -ENOMEM ; + goto err_disable_clk; + } + +/* allocate and initialize channels */ +INIT_LIST_HEAD (&bdev->common.channels); + +for (i =0 ; i < bdev->num_channels; i++) +bam_channel_init (bdev, &bdev->channels[i], i); + + ret =devm_request_irq (bdev->dev, irq_res->start, bam_dma_irq, +IRQF_TRIGGER_HIGH ,"bam_dma" , bdev); +if (ret) { +dev_err (bdev->dev,"cannot register IRQ\n" ); + goto err_disable_clk; + } + +/* set max dma segment size */ + bdev->common.dev = bdev->dev; + bdev->common.dev->dma_parms = &bdev->dma_parms; + ret =dma_set_max_seg_size (bdev->common.dev,BAM_MAX_DATA_SIZE ); +if (ret) { +dev_err (bdev->dev,"cannot set maximum segment size\n" ); + goto err_disable_clk; + } + +platform_set_drvdata (pdev, bdev); + +/* set capabilities */ +dma_cap_zero (bdev->common.cap_mask); +dma_cap_set (DMA_SLAVE , bdev->common.cap_mask); + +/* initialize dmaengine apis */ + bdev->common.device_alloc_chan_resources = bam_alloc_chan; + bdev->common.device_free_chan_resources = bam_free_chan; + bdev->common.device_prep_slave_sg = bam_prep_slave_sg; + bdev->common.device_control = bam_control; + bdev->common.device_issue_pending = bam_issue_pending; + bdev->common.device_tx_status = bam_tx_status; + bdev->common.dev = bdev->dev; + + ret =dma_async_device_register (&bdev->common); +if (ret) { +dev_err (bdev->dev,"failed to register dma async device\n" ); + goto err_disable_clk; + } + +if (pdev->dev.of_node) { + ret =of_dma_controller_register (pdev->dev.of_node, + bam_dma_xlate, &bdev->common); + +if (ret) { +dev_err (bdev->dev,"failed to register of_dma\n" ); + goto err_unregister_dma; + } + } + +return 0 ; + +err_unregister_dma: +dma_async_device_unregister (&bdev->common); +err_disable_clk: +clk_disable_unprepare (bdev->bamclk); +return ret; +} + +static int bam_dma_remove (struct platform_device *pdev) +{ +struct bam_device *bdev =platform_get_drvdata (pdev); + +dma_async_device_unregister (&bdev->common); + +if (pdev->dev.of_node) +of_dma_controller_free (pdev->dev.of_node); + +clk_disable_unprepare (bdev->bamclk); + +return 0 ; +} + +#ifdef CONFIG_OF +static const struct of_device_id bam_of_match[] = { + { .compatible ="qcom,bam-v1.4.0" , }, + { .compatible ="qcom,bam-v1.4.1" , }, + {} +}; +MODULE_DEVICE_TABLE (of, bam_of_match); +#endif + +static struct platform_driver bam_dma_driver = { + .probe = bam_dma_probe, + .remove = bam_dma_remove, + .driver = { + .name ="bam-dma-engine" , + .owner =THIS_MODULE , + .of_match_table =of_match_ptr (bam_of_match), + }, +}; + +static int __init bam_dma_init (void ) +{ +return platform_driver_register (&bam_dma_driver); +} + +static void __exit bam_dma_exit(void)
Quoted 9 lines
drivers/dma/qcom_bam_dma.c line 839
Quoted 6 lines
drivers/dma/qcom_bam_dma.c new file +6
-0+{ +return platform_driver_unregister (&bam_dma_driver); +} + +module_init (bam_dma_init); +module_exit (bam_dma_exit);
module_platform_driver()?
Will fix.
Quoted 6 lines
Quoted 6 lines
drivers/dma/qcom_bam_dma.c new file +4
-0+ +MODULE_AUTHOR ("Andy Gross <[email protected]>" ); +MODULE_DESCRIPTION ("QCOM BAM DMA engine driver" ); +MODULE_LICENSE ("GPL v2" );drivers/dma/qcom_bam_dma.h new file +0
-0
Quoted 9 lines
drivers/dma/qcom_bam_dma.h line 2
Quoted 6 lines
index 0000000..2cb3b5f
drivers/dma/qcom_bam_dma.h new file +2
-0@@ -0,0 +1,268 @@ +/* +* Copyright (c) 2013, The Linux Foundation. All rights reserved. 2014 ?
Should probably be 2013-2014 since development has spanned the change in year.
Quoted 280 lines
Quoted 266 lines
drivers/dma/qcom_bam_dma.h new file +266
-0+* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 and +* only version 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ +#ifndef __QCOM_BAM_DMA_H__ +#define __QCOM_BAM_DMA_H__ + +#include <linux/dmaengine.h> +#include "virt-dma.h" + +enum bam_channel_dir { +BAM_PIPE_CONSUMER =0 ,/* channel reads from data-fifo or memory */ +BAM_PIPE_PRODUCER ,/* channel writes to data-fifo or memory */ +}; + +struct bam_desc_hw { +u32 addr;/* Buffer physical address */ +u16 size;/* Buffer size in bytes */ +u16 flags; +} __packed; + +#define DESC_FLAG_INT BIT(15) +#define DESC_FLAG_EOT BIT(14) +#define DESC_FLAG_EOB BIT(13) + +struct bam_async_desc { +struct virt_dma_desc vd; + +u32 num_desc; +u32 xfer_len; +struct bam_desc_hw *curr_desc; + +enum bam_channel_dir dir; +size_t length; +struct bam_desc_hw desc[0 ]; +}; + +#define BAM_CTRL 0x0000 +#define BAM_REVISION 0x0004 +#define BAM_SW_REVISION 0x0080 +#define BAM_NUM_PIPES 0x003C +#define BAM_TIMER 0x0040 +#define BAM_TIMER_CTRL 0x0044 +#define BAM_DESC_CNT_TRSHLD 0x0008 +#define BAM_IRQ_SRCS 0x000C +#define BAM_IRQ_SRCS_MSK 0x0010 +#define BAM_IRQ_SRCS_UNMASKED 0x0030 +#define BAM_IRQ_STTS 0x0014 +#define BAM_IRQ_CLR 0x0018 +#define BAM_IRQ_EN 0x001C +#define BAM_CNFG_BITS 0x007C +#define BAM_IRQ_SRCS_EE (pipe) (0x0800 + ((pipe) * 0x80)) +#define BAM_IRQ_SRCS_MSK_EE (pipe) (0x0804 + ((pipe) * 0x80)) +#define BAM_P_CTRL (pipe) (0x1000 + ((pipe) * 0x1000)) +#define BAM_P_RST (pipe) (0x1004 + ((pipe) * 0x1000)) +#define BAM_P_HALT (pipe) (0x1008 + ((pipe) * 0x1000)) +#define BAM_P_IRQ_STTS (pipe) (0x1010 + ((pipe) * 0x1000)) +#define BAM_P_IRQ_CLR (pipe) (0x1014 + ((pipe) * 0x1000)) +#define BAM_P_IRQ_EN (pipe) (0x1018 + ((pipe) * 0x1000)) +#define BAM_P_EVNT_DEST_ADDR (pipe) (0x182C + ((pipe) * 0x1000)) +#define BAM_P_EVNT_REG (pipe) (0x1818 + ((pipe) * 0x1000)) +#define BAM_P_SW_OFSTS (pipe) (0x1800 + ((pipe) * 0x1000)) +#define BAM_P_DATA_FIFO_ADDR (pipe) (0x1824 + ((pipe) * 0x1000)) +#define BAM_P_DESC_FIFO_ADDR (pipe) (0x181C + ((pipe) * 0x1000)) +#define BAM_P_EVNT_TRSHLD (pipe) (0x1828 + ((pipe) * 0x1000)) +#define BAM_P_FIFO_SIZES (pipe) (0x1820 + ((pipe) * 0x1000)) + +/* BAM CTRL */ +#define BAM_SW_RST BIT(0) +#define BAM_EN BIT(1) +#define BAM_EN_ACCUM BIT(4) +#define BAM_TESTBUS_SEL_SHIFT 5 +#define BAM_TESTBUS_SEL_MASK 0x3F +#define BAM_DESC_CACHE_SEL_SHIFT 13 +#define BAM_DESC_CACHE_SEL_MASK 0x3 +#define BAM_CACHED_DESC_STORE BIT(15) +#define IBC_DISABLE BIT(16) + +/* BAM REVISION */ +#define REVISION_SHIFT 0 +#define REVISION_MASK 0xFF +#define NUM_EES_SHIFT 8 +#define NUM_EES_MASK 0xF +#define CE_BUFFER_SIZE BIT(13) +#define AXI_ACTIVE BIT(14) +#define USE_VMIDMT BIT(15) +#define SECURED BIT(16) +#define BAM_HAS_NO_BYPASS BIT(17) +#define HIGH_FREQUENCY_BAM BIT(18) +#define INACTIV_TMRS_EXST BIT(19) +#define NUM_INACTIV_TMRS BIT(20) +#define DESC_CACHE_DEPTH_SHIFT 21 +#define DESC_CACHE_DEPTH_1 (0 << DESC_CACHE_DEPTH_SHIFT) +#define DESC_CACHE_DEPTH_2 (1 << DESC_CACHE_DEPTH_SHIFT) +#define DESC_CACHE_DEPTH_3 (2 << DESC_CACHE_DEPTH_SHIFT) +#define DESC_CACHE_DEPTH_4 (3 << DESC_CACHE_DEPTH_SHIFT) +#define CMD_DESC_EN BIT(23) +#define INACTIV_TMR_BASE_SHIFT 24 +#define INACTIV_TMR_BASE_MASK 0xFF + +/* BAM NUM PIPES */ +#define BAM_NUM_PIPES_SHIFT 0 +#define BAM_NUM_PIPES_MASK 0xFF +#define PERIPH_NON_PIPE_GRP_SHIFT 16 +#define PERIPH_NON_PIP_GRP_MASK 0xFF +#define BAM_NON_PIPE_GRP_SHIFT 24 +#define BAM_NON_PIPE_GRP_MASK 0xFF + +/* BAM CNFG BITS */ +#define BAM_PIPE_CNFG BIT(2) +#define BAM_FULL_PIPE BIT(11) +#define BAM_NO_EXT_P_RST BIT(12) +#define BAM_IBC_DISABLE BIT(13) +#define BAM_SB_CLK_REQ BIT(14) +#define BAM_PSM_CSW_REQ BIT(15) +#define BAM_PSM_P_RES BIT(16) +#define BAM_AU_P_RES BIT(17) +#define BAM_SI_P_RES BIT(18) +#define BAM_WB_P_RES BIT(19) +#define BAM_WB_BLK_CSW BIT(20) +#define BAM_WB_CSW_ACK_IDL BIT(21) +#define BAM_WB_RETR_SVPNT BIT(22) +#define BAM_WB_DSC_AVL_P_RST BIT(23) +#define BAM_REG_P_EN BIT(24) +#define BAM_PSM_P_HD_DATA BIT(25) +#define BAM_AU_ACCUMED BIT(26) +#define BAM_CMD_ENABLE BIT(27) + +#define BAM_CNFG_BITS_DEFAULT (BAM_PIPE_CNFG | \ + BAM_NO_EXT_P_RST | \ + BAM_IBC_DISABLE | \ + BAM_SB_CLK_REQ | \ + BAM_PSM_CSW_REQ | \ + BAM_PSM_P_RES | \ + BAM_AU_P_RES | \ + BAM_SI_P_RES | \ + BAM_WB_P_RES | \ + BAM_WB_BLK_CSW | \ + BAM_WB_CSW_ACK_IDL | \ + BAM_WB_RETR_SVPNT | \ + BAM_WB_DSC_AVL_P_RST | \ + BAM_REG_P_EN | \ + BAM_PSM_P_HD_DATA | \ + BAM_AU_ACCUMED | \ + BAM_CMD_ENABLE) + +/* PIPE CTRL */ +#define P_EN BIT(1) +#define P_DIRECTION BIT(3) +#define P_SYS_STRM BIT(4) +#define P_SYS_MODE BIT(5) +#define P_AUTO_EOB BIT(6) +#define P_AUTO_EOB_SEL_SHIFT 7 +#define P_AUTO_EOB_SEL_512 (0 << P_AUTO_EOB_SEL_SHIFT) +#define P_AUTO_EOB_SEL_256 (1 << P_AUTO_EOB_SEL_SHIFT) +#define P_AUTO_EOB_SEL_128 (2 << P_AUTO_EOB_SEL_SHIFT) +#define P_AUTO_EOB_SEL_64 (3 << P_AUTO_EOB_SEL_SHIFT) +#define P_PREFETCH_LIMIT_SHIFT 9 +#define P_PREFETCH_LIMIT_32 (0 << P_PREFETCH_LIMIT_SHIFT) +#define P_PREFETCH_LIMIT_16 (1 << P_PREFETCH_LIMIT_SHIFT) +#define P_PREFETCH_LIMIT_4 (2 << P_PREFETCH_LIMIT_SHIFT) +#define P_WRITE_NWD BIT(11) +#define P_LOCK_GROUP_SHIFT 16 +#define P_LOCK_GROUP_MASK 0x1F + +/* BAM_DESC_CNT_TRSHLD */ +#define CNT_TRSHLD 0xffff +#define DEFAULT_CNT_THRSHLD 0x4 + +/* BAM_IRQ_SRCS */ +#define BAM_IRQ BIT(31) +#define P_IRQ 0x7fffffff + +/* BAM_IRQ_SRCS_MSK */ +#define BAM_IRQ_MSK BAM_IRQ +#define P_IRQ_MSK P_IRQ + +/* BAM_IRQ_STTS */ +#define BAM_TIMER_IRQ BIT(4) +#define BAM_EMPTY_IRQ BIT(3) +#define BAM_ERROR_IRQ BIT(2) +#define BAM_HRESP_ERR_IRQ BIT(1) + +/* BAM_IRQ_CLR */ +#define BAM_TIMER_CLR BIT(4) +#define BAM_EMPTY_CLR BIT(3) +#define BAM_ERROR_CLR BIT(2) +#define BAM_HRESP_ERR_CLR BIT(1) + +/* BAM_IRQ_EN */ +#define BAM_TIMER_EN BIT(4) +#define BAM_EMPTY_EN BIT(3) +#define BAM_ERROR_EN BIT(2) +#define BAM_HRESP_ERR_EN BIT(1) + +/* BAM_P_IRQ_EN */ +#define P_PRCSD_DESC_EN BIT(0) +#define P_TIMER_EN BIT(1) +#define P_WAKE_EN BIT(2) +#define P_OUT_OF_DESC_EN BIT(3) +#define P_ERR_EN BIT(4) +#define P_TRNSFR_END_EN BIT(5) +#define P_DEFAULT_IRQS_EN (P_PRCSD_DESC_EN | P_ERR_EN | P_TRNSFR_END_EN) + +/* BAM_P_SW_OFSTS */ +#define P_SW_OFSTS_MASK 0xffff + +#define BAM_DESC_FIFO_SIZE SZ_32K +#define MAX_DESCRIPTORS (BAM_DESC_FIFO_SIZE / sizeof(struct bam_desc_hw) - 1) +#define BAM_MAX_DATA_SIZE (SZ_32K - 8) + +struct bam_chan { +struct virt_dma_chan vc; + +struct bam_device *bdev; + +/* configuration from device tree */ +u32 id; +u32 ee; + +struct bam_async_desc *curr_txd;/* current running dma */ + +/* runtime configuration */ +struct dma_slave_config slave; + +/* fifo storage */ +struct bam_desc_hw *fifo_virt; +dma_addr_t fifo_phys; + +/* fifo markers */ +unsigned short head;/* start of active descriptor entries */ +unsigned short tail;/* end of active descriptor entries */ + +unsigned int paused;/* is the channel paused? */ + +struct list_head node; +}; + +static inline struct bam_chan *to_bam_chan (struct dma_chan *common) +{ + return container_of(common, struct bam_chan, vc.chan); +} + +struct bam_device { +void __iomem *regs; +struct device *dev; +struct dma_device common; +struct device_dma_parameters dma_parms; +struct bam_chan *channels; +u32 num_channels; +u32 num_ees; +unsigned long enabled_ees; +int irq; +struct clk *bamclk; + +/* dma start transaction tasklet */ +struct tasklet_struct task; +}; + +#endif /* __QCOM_BAM_DMA_H__ */ Signature · 12 lines
Andy Shevchenko <[email protected]> Intel Finland Oy --------------------------------------------------------------------- Intel Finland Oy Registered Address: PL 281, 00181 Helsinki Business Identity Code: 0357606 - 4 Domiciled in Helsinki This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
Signature · 3 lines
sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation
PATCH v2 1/2 dmaengine: add Qualcomm BAM dma driver
In reply to Andy Gross(Mostly nitpicks)
Quoted 26 lines · Andy Gross
Add the DMA engine driver for the QCOM Bus Access Manager (BAM) DMA controller found in the MSM 8x74 platforms.
Each BAM DMA device is associated with a specific on-chip peripheral. Each channel provides a uni-directional data transfer engine that is capable of transferring data between the peripheral and system memory (System mode), or between two peripherals (BAM2BAM).
The initial release of this driver only supports slave transfers between peripherals and system memory.
Signed-off-by Andy Gross <[email protected]>--- drivers/dma/Kconfig | 9 + drivers/dma/Makefile | 1 + drivers/dma/qcom_bam_dma.c | 843 +++++++++++++++++++++++++++++++++++++++++++++ drivers/dma/qcom_bam_dma.h | 268 ++++++++++++++ 4 files changed, 1121 insertions(+) create mode 100644 drivers/dma/qcom_bam_dma.c create mode 100644 drivers/dma/qcom_bam_dma.hdrivers/dma/Kconfig +0
-0
drivers/dma/Kconfig config DMATEST · line 389
Quoted 6 lines
drivers/dma/Kconfig +3
-0@@ -384,4 +384,13 @@ config DMATEST config DMA_ENGINE_RAID bool +config QCOM_BAM_DMA + tristate "QCOM BAM DMA support" + depends on ARCH_MSM || COMPILE_TEST
I don't think writel_relaxed() is available on every arch, so it's possible this will break some random arch that doesn't have that function.
Quoted 12 lines
drivers/dma/Kconfig +6
-0+ select DMA_ENGINE + select DMA_VIRTUAL_CHANNELS + ---help--- + Enable support for the QCOM BAM DMA controller. This controller + provides DMA capabilities for a variety of on-chip devices. + endifdrivers/dma/qcom_bam_dma.c new file +0
-0
[...]
Quoted 1 line
+static int
bam_alloc_chan(struct dma_chan *chan)
[...]
drivers/dma/qcom_bam_dma.c line 99
Quoted 11 lines
drivers/dma/qcom_bam_dma.c new file +11
-0+ +/* Go ahead and initialize the pipe/channel hardware here +- Reset the channel to clear internal state of the FIFO +- Program in the FIFO address +- Configure the irq based on the EE passed in from the DT entry +- Set mode, direction and enable channel + +We do this here because the channel can only be enabled once and +can only be disabled via a reset. If done here, we don't have to +manage additional state to figure out when to do this +*/
Multi-line comments are of the form:
/* * comment */
Quoted 9 lines
drivers/dma/qcom_bam_dma.c new file +9
-0+ +bam_reset_channel (bdev, bchan->id); + +/* write out 8 byte aligned address. We have enough space for this +because we allocated 1 more descriptor (8 bytes) than we can use */ +writel_relaxed (ALIGN (bchan->fifo_phys,sizeof (struct bam_desc_hw )), + bdev->regs +BAM_P_DESC_FIFO_ADDR (bchan->id)); +writel_relaxed (BAM_DESC_FIFO_SIZE , bdev->regs + +BAM_P_FIFO_SIZES (bchan->id));
[...]
drivers/dma/qcom_bam_dma.c line 278
Quoted 9 lines
drivers/dma/qcom_bam_dma.c new file +9
-0+ +/** +* bam_dma_terminate_all - terminate all transactions +* @chan: dma channel +* +* Idles channel and dequeues and frees all transactions +* No callbacks are done +* +*/
Weird '*' starting the line here and on the next function.
Quoted 27 lines
drivers/dma/qcom_bam_dma.c new file +27
-0+static void bam_dma_terminate_all (struct dma_chan *chan) +{ +struct bam_chan *bchan =to_bam_chan (chan); +struct bam_device *bdev = bchan->bdev; + +bam_reset_channel (bdev, bchan->id); + +vchan_free_chan_resources (&bchan->vc); +} + +/** +* bam_control - DMA device control +* @chan: dma channel +* @cmd: control cmd +* @arg: cmd argument +* +* Perform DMA control command +* +*/ +static int bam_control (struct dma_chan *chan,enum dma_ctrl_cmd cmd, +unsigned long arg) +{ +struct bam_chan *bchan =to_bam_chan (chan); +struct bam_device *bdev = bchan->bdev; +int ret =0 ; +unsigned long flag; +
[...]
drivers/dma/qcom_bam_dma.c line 404
Quoted 10 lines
drivers/dma/qcom_bam_dma.c new file +10
-0+/** +* bam_dma_irq - irq handler for bam controller +* @irq: IRQ of interrupt +* @data: callback data +* +* IRQ handler for the bam controller +*/ +static irqreturn_t bam_dma_irq (int irq,void *data) +{ +struct bam_device *bdev = (struct bam_device *)data;
Unnecessary cast from void.
Quoted 2 lines
drivers/dma/qcom_bam_dma.c new file +2
-0+static int bam_dma_probe (struct platform_device *pdev) +{
[...]
drivers/dma/qcom_bam_dma.c line 708
Quoted 6 lines
drivers/dma/qcom_bam_dma.c new file +6
-0+ + irq_res =platform_get_resource (pdev,IORESOURCE_IRQ ,0 ); +if (!irq_res) { +dev_err (bdev->dev,"irq resource is missing\n" ); +return -EINVAL ; + }
Please use platform_get_irq() instead.
Quoted 5 lines
drivers/dma/qcom_bam_dma.h new file +0
-0
[...]
Quoted 10 lines
drivers/dma/qcom_bam_dma.h new file +10
-0+#define BAM_CNFG_BITS_DEFAULT (BAM_PIPE_CNFG | \ + BAM_NO_EXT_P_RST | \ + BAM_IBC_DISABLE | \ + BAM_SB_CLK_REQ | \ + BAM_PSM_CSW_REQ | \ + BAM_PSM_P_RES | \ + BAM_AU_P_RES | \ + BAM_SI_P_RES | \ + BAM_WB_P_RES | \ + BAM_WB_BLK_CSW | \
drivers/dma/qcom_bam_dma.h line 156
Quoted 10 lines
drivers/dma/qcom_bam_dma.h new file +10
-0+ BAM_WB_CSW_ACK_IDL | \ + BAM_WB_RETR_SVPNT | \ + BAM_WB_DSC_AVL_P_RST | \ + BAM_REG_P_EN | \ + BAM_PSM_P_HD_DATA | \ + BAM_AU_ACCUMED | \ + BAM_CMD_ENABLE) + +/* PIPE CTRL */ +#define P_EN BIT(1)
Nit: Weird formatting here?
Quoted 1 line
+#define
P_DIRECTIONBIT(3)
[...]
drivers/dma/qcom_bam_dma.h line 257
Quoted 8 lines
drivers/dma/qcom_bam_dma.h new file +8
-0+ + +struct bam_device { +void __iomem *regs; +struct device *dev; +struct dma_device common; +struct device_dma_parameters dma_parms; +struct bam_chan *channels;
Maybe this should be a flexible array. It looks like probe might need to be rewritten to detect the number of channels from the hardware before assigning anything, but it should be possible. But it probably doesn't matter.
drivers/dma/qcom_bam_dma.h line 261
Quoted 4 lines
drivers/dma/qcom_bam_dma.h new file +4
-0+u32 num_channels; +u32 num_ees; +unsigned long enabled_ees; +int irq;
Is irq used?
Quoted 5 lines
drivers/dma/qcom_bam_dma.h new file +5
-0+struct clk *bamclk; + +/* dma start transaction tasklet */ +struct tasklet_struct task; +};
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH v2 1/2 dmaengine: add Qualcomm BAM dma driver
Quoted 32 lines · Stephen Boyd
(Mostly nitpicks)
Quoted 29 lines · Andy Gross
Add the DMA engine driver for the QCOM Bus Access Manager (BAM) DMA controller found in the MSM 8x74 platforms.
Each BAM DMA device is associated with a specific on-chip peripheral. Each channel provides a uni-directional data transfer engine that is capable of transferring data between the peripheral and system memory (System mode), or between two peripherals (BAM2BAM).
The initial release of this driver only supports slave transfers between peripherals and system memory.
Signed-off-by Andy Gross <[email protected]>--- drivers/dma/Kconfig | 9 + drivers/dma/Makefile | 1 + drivers/dma/qcom_bam_dma.c | 843 +++++++++++++++++++++++++++++++++++++++++++++ drivers/dma/qcom_bam_dma.h | 268 ++++++++++++++ 4 files changed, 1121 insertions(+) create mode 100644 drivers/dma/qcom_bam_dma.c create mode 100644 drivers/dma/qcom_bam_dma.hdrivers/dma/Kconfig +0
-0@@ -384,4 +384,13 @@ config DMATEST config DMA_ENGINE_RAID bool
Quoted 8 lines
drivers/dma/Kconfig config DMATEST · line 389
Quoted 3 lines
drivers/dma/Kconfig +3
-0+config QCOM_BAM_DMA + tristate "QCOM BAM DMA support" + depends on ARCH_MSM || COMPILE_TESTI don't think
writel_relaxed()is available on every arch, so it's possible this will break some random arch that doesn't have that function.
I'll look into this to see. If that's the case, I can remove the COMPILE_TEST if there is no alternative.
Quoted 29 lines
Quoted 12 lines
drivers/dma/Kconfig +6
-0+ select DMA_ENGINE + select DMA_VIRTUAL_CHANNELS + ---help--- + Enable support for the QCOM BAM DMA controller. This controller + provides DMA capabilities for a variety of on-chip devices. + endifdrivers/dma/qcom_bam_dma.c new file +0
-0[...]
Quoted 1 line
+static int
bam_alloc_chan(struct dma_chan *chan)[...]
drivers/dma/qcom_bam_dma.c line 99
Quoted 11 lines
drivers/dma/qcom_bam_dma.c new file +11
-0+ +/* Go ahead and initialize the pipe/channel hardware here +- Reset the channel to clear internal state of the FIFO +- Program in the FIFO address +- Configure the irq based on the EE passed in from the DT entry +- Set mode, direction and enable channel + +We do this here because the channel can only be enabled once and +can only be disabled via a reset. If done here, we don't have to +manage additional state to figure out when to do this +*/ Multi-line comments are of the form:
Quoted 4 lines
/* * comment */
Right. I converted some comments and didn't do the correct multi-line
Quoted 10 lines
Quoted 9 lines
drivers/dma/qcom_bam_dma.c new file +9
-0+ +bam_reset_channel (bdev, bchan->id); + +/* write out 8 byte aligned address. We have enough space for this +because we allocated 1 more descriptor (8 bytes) than we can use */ +writel_relaxed (ALIGN (bchan->fifo_phys,sizeof (struct bam_desc_hw )), + bdev->regs +BAM_P_DESC_FIFO_ADDR (bchan->id)); +writel_relaxed (BAM_DESC_FIFO_SIZE , bdev->regs + +BAM_P_FIFO_SIZES (bchan->id));[...]
Quoted 12 lines
drivers/dma/qcom_bam_dma.c line 278
Quoted 9 lines
drivers/dma/qcom_bam_dma.c new file +9
-0+ +/** +* bam_dma_terminate_all - terminate all transactions +* @chan: dma channel +* +* Idles channel and dequeues and frees all transactions +* No callbacks are done +* +*/ Weird '*' starting the line here and on the next function.
Will fix.
Quoted 28 lines
Quoted 27 lines
drivers/dma/qcom_bam_dma.c new file +27
-0+static void bam_dma_terminate_all (struct dma_chan *chan) +{ +struct bam_chan *bchan =to_bam_chan (chan); +struct bam_device *bdev = bchan->bdev; + +bam_reset_channel (bdev, bchan->id); + +vchan_free_chan_resources (&bchan->vc); +} + +/** +* bam_control - DMA device control +* @chan: dma channel +* @cmd: control cmd +* @arg: cmd argument +* +* Perform DMA control command +* +*/ +static int bam_control (struct dma_chan *chan,enum dma_ctrl_cmd cmd, +unsigned long arg) +{ +struct bam_chan *bchan =to_bam_chan (chan); +struct bam_device *bdev = bchan->bdev; +int ret =0 ; +unsigned long flag; +[...]
Quoted 13 lines
drivers/dma/qcom_bam_dma.c line 404
Quoted 10 lines
drivers/dma/qcom_bam_dma.c new file +10
-0+/** +* bam_dma_irq - irq handler for bam controller +* @irq: IRQ of interrupt +* @data: callback data +* +* IRQ handler for the bam controller +*/ +static irqreturn_t bam_dma_irq (int irq,void *data) +{ +struct bam_device *bdev = (struct bam_device *)data;Unnecessary cast from void.
Fixed.
Quoted 12 lines
Quoted 2 lines
drivers/dma/qcom_bam_dma.c new file +2
-0+static int bam_dma_probe (struct platform_device *pdev) +{[...]
drivers/dma/qcom_bam_dma.c line 708
Quoted 6 lines
drivers/dma/qcom_bam_dma.c new file +6
-0+ + irq_res =platform_get_resource (pdev,IORESOURCE_IRQ ,0 ); +if (!irq_res) { +dev_err (bdev->dev,"irq resource is missing\n" ); +return -EINVAL ; + }Please use
platform_get_irq()instead.
Fixed.
Quoted 20 lines
Quoted 5 lines
drivers/dma/qcom_bam_dma.h new file +0
-0[...]
Quoted 14 lines
drivers/dma/qcom_bam_dma.h new file +14
-0+#define BAM_CNFG_BITS_DEFAULT (BAM_PIPE_CNFG | \ + BAM_NO_EXT_P_RST | \ + BAM_IBC_DISABLE | \ + BAM_SB_CLK_REQ | \ + BAM_PSM_CSW_REQ | \ + BAM_PSM_P_RES | \ + BAM_AU_P_RES | \ + BAM_SI_P_RES | \ + BAM_WB_P_RES | \ + BAM_WB_BLK_CSW | \ + BAM_WB_CSW_ACK_IDL | \ + BAM_WB_RETR_SVPNT | \ + BAM_WB_DSC_AVL_P_RST | \ + BAM_REG_P_EN | \
Quoted 9 lines
drivers/dma/qcom_bam_dma.h line 156
Quoted 6 lines
drivers/dma/qcom_bam_dma.h new file +6
-0+ BAM_PSM_P_HD_DATA | \ + BAM_AU_ACCUMED | \ + BAM_CMD_ENABLE) + +/* PIPE CTRL */ +#define P_EN BIT(1)Nit: Weird formatting here?
That is odd. Will fix.
Quoted 16 lines
Quoted 1 line
+#define
P_DIRECTIONBIT(3)[...]
drivers/dma/qcom_bam_dma.h line 257
Quoted 8 lines
drivers/dma/qcom_bam_dma.h new file +8
-0+ + +struct bam_device { +void __iomem *regs; +struct device *dev; +struct dma_device common; +struct device_dma_parameters dma_parms; +struct bam_chan *channels;Maybe this should be a flexible array. It looks like probe might need to be rewritten to detect the number of channels from the hardware before assigning anything, but it should be possible. But it probably doesn't matter.
You can't take the number of channels at face value. Only a subset of that number are actually usable by the CPUs execution environment.
Quoted 7 lines
drivers/dma/qcom_bam_dma.h line 261
Quoted 4 lines
drivers/dma/qcom_bam_dma.h new file +4
-0+u32 num_channels; +u32 num_ees; +unsigned long enabled_ees; +int irq;Is irq used?
Will remove.
Quoted 9 lines
Quoted 5 lines
drivers/dma/qcom_bam_dma.h new file +5
-0+struct clk *bamclk; + +/* dma start transaction tasklet */ +struct tasklet_struct task; +};Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Signature · 3 lines
sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation
PATCH v2 1/2 dmaengine: add Qualcomm BAM dma driver
In reply to Andy GrossQuoted 7 lines · Andy Gross
drivers/dma/qcom_bam_dma.c new file +7
-0+static bool bam_dma_filter (struct dma_chan *chan,void *data) +{ +struct bam_filter_args *args = data; +struct bam_chan *bchan =to_bam_chan (chan); + +if (args->dev == chan->device && + args->id == bchan->id) {
drivers/dma/qcom_bam_dma.c line 605
Quoted 10 lines
drivers/dma/qcom_bam_dma.c new file +10
-0+ +/* we found the channel, so lets set the EE and dir */ + bchan->ee = args->ee; + bchan->slave.direction = args->dir ? +DMA_DEV_TO_MEM :DMA_MEM_TO_DEV ; +return true; + } + +return false; +}
A filter function should no longer be needed.
Quoted 9 lines
drivers/dma/qcom_bam_dma.c new file +9
-0+static struct dma_chan *bam_dma_xlate (struct of_phandle_args *dma_spec, +struct of_dma *of) +{ +struct bam_filter_args args; +dma_cap_mask_t cap; + +if (dma_spec->args_count !=3 ) +return NULL ; +
drivers/dma/qcom_bam_dma.c line 625
Quoted 10 lines
drivers/dma/qcom_bam_dma.c new file +10
-0+ args.dev = of->of_dma_data; + args.id = dma_spec->args[0 ]; + args.ee = dma_spec->args[1 ]; + args.dir = dma_spec->args[2 ]; + +dma_cap_zero (cap); +dma_cap_set (DMA_SLAVE , cap); + +return dma_request_channel (cap, bam_dma_filter, &args); +}
Instead, call dma_get_slave_channel() with the right channel that you already know here.
drivers/dma/qcom_bam_dma.c line 784
Quoted 9 lines
drivers/dma/qcom_bam_dma.c new file +9
-0+if (pdev->dev.of_node) { + ret =of_dma_controller_register (pdev->dev.of_node, + bam_dma_xlate, &bdev->common); + +if (ret) { +dev_err (bdev->dev,"failed to register of_dma\n" ); + goto err_unregister_dma; + } + }
No need to check for pdev->dev.of_node when that is the only mode of probing.
drivers/dma/qcom_bam_dma.c line 816
Quoted 9 lines
drivers/dma/qcom_bam_dma.c new file +9
-0+ +#ifdef CONFIG_OF +static const struct of_device_id bam_of_match[] = { + { .compatible ="qcom,bam-v1.4.0" , }, + { .compatible ="qcom,bam-v1.4.1" , }, + {} +}; +MODULE_DEVICE_TABLE (of, bam_of_match); +#endif
Also, you can remove the #ifdef here and the of_match_ptr() below.
Quoted 11 lines
drivers/dma/qcom_bam_dma.c new file +11
-0+ +static struct platform_driver bam_dma_driver = { + .probe = bam_dma_probe, + .remove = bam_dma_remove, + .driver = { + .name ="bam-dma-engine" , + .owner =THIS_MODULE , + .of_match_table =of_match_ptr (bam_of_match), + }, +}; +
drivers/dma/qcom_bam_dma.c line 837
Quoted 10 lines
drivers/dma/qcom_bam_dma.c new file +10
-0+static int __init bam_dma_init (void ) +{ +return platform_driver_register (&bam_dma_driver); +} + +static void __exit bam_dma_exit(void) +{ +return platform_driver_unregister (&bam_dma_driver); +} +
module_platform_driver()
Quoted 6 lines
drivers/dma/qcom_bam_dma.h new file +0
-0
drivers/dma/qcom_bam_dma.h line 10
Quoted 10 lines
drivers/dma/qcom_bam_dma.h new file +10
-0@@ -0,0 +1,268 @@ +#ifndef __QCOM_BAM_DMA_H__ +#define __QCOM_BAM_DMA_H__ + +#include <linux/dmaengine.h> +#include "virt-dma.h" + +enum bam_channel_dir { +BAM_PIPE_CONSUMER =0 ,/* channel reads from data-fifo or memory */ +BAM_PIPE_PRODUCER ,/* channel writes to data-fifo or memory */ +};
Since the header does not serve as an interface, just move all the contents into the driver directly.
drivers/dma/qcom_bam_dma.h line 28
Quoted 5 lines
drivers/dma/qcom_bam_dma.h new file +5
-0+struct bam_desc_hw { +u32 addr;/* Buffer physical address */ +u16 size;/* Buffer size in bytes */ +u16 flags; +} __packed;
Remove __packed here, it only makes the access less efficient but does not change the layout, which is already packed.
Arnd
PATCH v2 1/2 dmaengine: add Qualcomm BAM dma driver
Quoted 13 lines · Arnd Bergmann
Quoted 11 lines · Andy Gross
drivers/dma/qcom_bam_dma.c new file +11
-0+static bool bam_dma_filter (struct dma_chan *chan,void *data) +{ +struct bam_filter_args *args = data; +struct bam_chan *bchan =to_bam_chan (chan); + +if (args->dev == chan->device && + args->id == bchan->id) { + +/* we found the channel, so lets set the EE and dir */ + bchan->ee = args->ee; + bchan->slave.direction = args->dir ?
Quoted 9 lines
drivers/dma/qcom_bam_dma.c line 605
Quoted 6 lines
drivers/dma/qcom_bam_dma.c new file +6
-0+ DMA_DEV_TO_MEM :DMA_MEM_TO_DEV ; +return true; + } + +return false; +}A filter function should no longer be needed.
Ok, will remove.
Quoted 14 lines
Quoted 14 lines
drivers/dma/qcom_bam_dma.c new file +14
-0+static struct dma_chan *bam_dma_xlate (struct of_phandle_args *dma_spec, +struct of_dma *of) +{ +struct bam_filter_args args; +dma_cap_mask_t cap; + +if (dma_spec->args_count !=3 ) +return NULL ; + + args.dev = of->of_dma_data; + args.id = dma_spec->args[0 ]; + args.ee = dma_spec->args[1 ]; + args.dir = dma_spec->args[2 ]; +
Quoted 9 lines
drivers/dma/qcom_bam_dma.c line 625
Quoted 5 lines
drivers/dma/qcom_bam_dma.c new file +5
-0+dma_cap_zero (cap); +dma_cap_set (DMA_SLAVE , cap); + +return dma_request_channel (cap, bam_dma_filter, &args); +}Instead, call
dma_get_slave_channel()with the right channel that you already know here.
Agreed.
Quoted 12 lines
drivers/dma/qcom_bam_dma.c line 784
Quoted 9 lines
drivers/dma/qcom_bam_dma.c new file +9
-0+if (pdev->dev.of_node) { + ret =of_dma_controller_register (pdev->dev.of_node, + bam_dma_xlate, &bdev->common); + +if (ret) { +dev_err (bdev->dev,"failed to register of_dma\n" ); + goto err_unregister_dma; + } + }No need to check for
pdev->dev.of_nodewhen that is the only mode of probing.
Good point. I'll remove extraneous check.
Quoted 12 lines
drivers/dma/qcom_bam_dma.c line 816
Quoted 9 lines
drivers/dma/qcom_bam_dma.c new file +9
-0+ +#ifdef CONFIG_OF +static const struct of_device_id bam_of_match[] = { + { .compatible ="qcom,bam-v1.4.0" , }, + { .compatible ="qcom,bam-v1.4.1" , }, + {} +}; +MODULE_DEVICE_TABLE (of, bam_of_match); +#endif Also, you can remove the #ifdef here and the
of_match_ptr()below.
If this is removed, then I'll have to add the OF dependency in the Kconfig, correct?
Quoted 15 lines
Quoted 15 lines
drivers/dma/qcom_bam_dma.c new file +15
-0+ +static struct platform_driver bam_dma_driver = { + .probe = bam_dma_probe, + .remove = bam_dma_remove, + .driver = { + .name ="bam-dma-engine" , + .owner =THIS_MODULE , + .of_match_table =of_match_ptr (bam_of_match), + }, +}; + +static int __init bam_dma_init (void ) +{ +return platform_driver_register (&bam_dma_driver); +}
Quoted 9 lines
drivers/dma/qcom_bam_dma.c line 837
Quoted 6 lines
drivers/dma/qcom_bam_dma.c new file +6
-0+ +static void __exit bam_dma_exit(void) +{ +return platform_driver_unregister (&bam_dma_driver); +} +
module_platform_driver()
Will fix.
Quoted 11 lines
Quoted 11 lines
drivers/dma/qcom_bam_dma.h new file +5
-0@@ -0,0 +1,268 @@ +#ifndef __QCOM_BAM_DMA_H__ +#define __QCOM_BAM_DMA_H__ + +#include <linux/dmaengine.h> +#include "virt-dma.h"
Quoted 9 lines
drivers/dma/qcom_bam_dma.h line 22
Quoted 5 lines
drivers/dma/qcom_bam_dma.h new file +5
-0+ +enum bam_channel_dir { +BAM_PIPE_CONSUMER =0 ,/* channel reads from data-fifo or memory */ +BAM_PIPE_PRODUCER ,/* channel writes to data-fifo or memory */ +};Since the header does not serve as an interface, just move all the contents into the driver directly.
OK. SBoyd made the same comment. I'll go ahead and collapse both down to 1 file.
Quoted 8 lines
drivers/dma/qcom_bam_dma.h line 28
Quoted 5 lines
drivers/dma/qcom_bam_dma.h new file +5
-0+struct bam_desc_hw { +u32 addr;/* Buffer physical address */ +u16 size;/* Buffer size in bytes */ +u16 flags; +} __packed;Remove
__packedhere, it only makes the access less efficient but does not change the layout, which is already packed.
Ok. Will fix.
Signature · 3 lines
sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation
PATCH v2 1/2 dmaengine: add Qualcomm BAM dma driver
Quoted 12 lines · On Monday 20 January 2014 16:52:45 Andy Gross wrote:
Quoted 11 lines
drivers/dma/qcom_bam_dma.c line 816
Quoted 8 lines
drivers/dma/qcom_bam_dma.c new file +8
-0+#ifdef CONFIG_OF +static const struct of_device_id bam_of_match[] = { + { .compatible ="qcom,bam-v1.4.0" , }, + { .compatible ="qcom,bam-v1.4.1" , }, + {} +}; +MODULE_DEVICE_TABLE (of, bam_of_match); +#endif Also, you can remove the #ifdef here and the
of_match_ptr()below.
Quoted 2 lines
If this is removed, then I'll have to add the OF dependency in the
Kconfig, correct?
I believe it will still compile without the CONFIG_OF dependency, but having the dependency still makes sense as it's impossible to use the driver without CONFIG_OF.
The best dependency line is probably
depends on (ARCH_MSM && OF) || COMPILE_TEST"
If you expect the same driver to be used on non-MSM platforms from qualcomm, e.g. some networking or server equipment, you can also just drop the ARCH_MSM dependency.
Arnd
PATCH v2 1/2 dmaengine: add Qualcomm BAM dma driver
Quoted 21 lines · Arnd Bergmann
Quoted 12 lines · On Monday 20 January 2014 16:52:45 Andy Gross wrote:
Quoted 11 lines
drivers/dma/qcom_bam_dma.c line 816
Quoted 8 lines
drivers/dma/qcom_bam_dma.c new file +8
-0+#ifdef CONFIG_OF +static const struct of_device_id bam_of_match[] = { + { .compatible ="qcom,bam-v1.4.0" , }, + { .compatible ="qcom,bam-v1.4.1" , }, + {} +}; +MODULE_DEVICE_TABLE (of, bam_of_match); +#endif Also, you can remove the #ifdef here and the
of_match_ptr()below.Quoted 2 lines
If this is removed, then I'll have to add the OF dependency in the
Kconfig, correct?I believe it will still compile without the
CONFIG_OFdependency, but having the dependency still makes sense as it's impossible to use the driver withoutCONFIG_OF.
Quoted 7 lines
The best dependency line is probably
depends on (ARCH_MSM && OF) || COMPILE_TEST"If you expect the same driver to be used on non-MSM platforms from qualcomm, e.g. some networking or server equipment, you can also just drop the
ARCH_MSMdependency.
Thanks for the clarification. I think I'll probably do:ARCH_MSM_DT || (COMPILE_TEST && ARM)
The latter due to my use of writel_relaxed.
Signature · 3 lines
sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation
PATCH v2 1/2 dmaengine: add Qualcomm BAM dma driver
Quoted 5 lines · On Tuesday 21 January 2014 17:01:03 Andy Gross wrote:
Thanks for the clarification. I think I'll probably do:
ARCH_MSM_DT|| (COMPILE_TEST&& ARM)The latter due to my use of
writel_relaxed.
Yes, looks good.
Arnd
PATCH v2 1/2 dmaengine: add Qualcomm BAM dma driver
In reply to Andy GrossQuoted 26 lines · Andy Gross
Quoted 25 lines · Arnd Bergmann
Quoted 12 lines · On Monday 20 January 2014 16:52:45 Andy Gross wrote:
Quoted 11 lines
drivers/dma/qcom_bam_dma.c line 816
Quoted 8 lines
drivers/dma/qcom_bam_dma.c new file +8
-0+#ifdef CONFIG_OF +static const struct of_device_id bam_of_match[] = { + { .compatible ="qcom,bam-v1.4.0" , }, + { .compatible ="qcom,bam-v1.4.1" , }, + {} +}; +MODULE_DEVICE_TABLE (of, bam_of_match); +#endif Also, you can remove the #ifdef here and the
of_match_ptr()below.Quoted 2 lines
If this is removed, then I'll have to add the OF dependency in the
Kconfig, correct?I believe it will still compile without the
CONFIG_OFdependency, but having the dependency still makes sense as it's impossible to use the driver withoutCONFIG_OF.The best dependency line is probably
depends on (ARCH_MSM && OF) || COMPILE_TEST"
Quoted 7 lines
Quoted 3 lines
If you expect the same driver to be used on non-MSM platforms from qualcomm, e.g. some networking or server equipment, you can also just drop the
ARCH_MSMdependency.Thanks for the clarification. I think I'll probably do:
ARCH_MSM_DT|| (COMPILE_TEST&& ARM)
Didn?t you need it to be:
ARCH_MSM_DT || (COMPILE_TEST && OF && ARM)
- k
Signature · 2 lines
Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH v2 1/2 dmaengine: add Qualcomm BAM dma driver
On Thu, Jan 23, 2014 at 02:17:19PM -0600, Kumar Gala wrote:
[....]
Quoted 10 lines
Quoted 4 lines
Thanks for the clarification. I think I'll probably do:
ARCH_MSM_DT|| (COMPILE_TEST&& ARM)Didn?t you need it to be:
ARCH_MSM_DT|| (COMPILE_TEST&& OF && ARM)- k
Yes. That's the version I am going with. I might be able to get away without the OF if it compiles fine without it, provided it stubs out the OF stuff if the config option is not present.
Quoted 10 lines
Signature · 9 lines
-- Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel at lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Signature · 3 lines
sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation
PATCH v2 2/2 dmaengine: qcom_bam_dma: Add device tree binding
In reply to Andy GrossAdd device tree binding support for the QCOM BAM DMA driver.
--- .../devicetree/bindings/dma/qcom_bam_dma.txt | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Documentation/devicetree/bindings/dma/qcom_bam_dma.txt
Documentation/devicetree/bindings/dma/qcom_bam_dma.txt new file +52 -0
@@ -0,0 +1,52 @@ +QCOM BAM DMA controller + +Required properties: +- compatible: Must be "qcom,bam-v1.4.0" for MSM8974 V1 + Must be "qcom,bam-v1.4.1" for MSM8974 V2 +- reg: Address range for DMA registers +- interrupts: single interrupt for this controller +- #dma-cells: must be <3> +- clocks: required clock +- clock-names: name of clock + +Example: + + uart-bam: dma at f9984000 = { + compatible = "qcom,bam-v1.4.1"; + reg = <0xf9984000 0x15000>; + interrupts = <0 94 0>; + clocks = <&gcc GCC_BAM_DMA_AHB_CLK>; + clock-names = "bam_clk"; + #dma-cells = <3>; + }; + +Client: +Required properties: +- dmas: List of dma channel requests +- dma-names: Names of aforementioned requested channels + +Clients must use the format described in the dma.txt file, using a four cell +specifier for each channel. + +The four cells in order are: + 1. A phandle pointing to the DMA controller + 2. The channel number + 3. The execution environment value for this channel. This is used to indicate + the trustzone index used during register access. + 4. Direction of the fixed unidirectional channel + 0 - Memory to Device + 1 - Device to Memory + 2 - Device to Device + +Example: + serial at f991e000 { + compatible = "qcom,msm-uart"; + reg = <0xf991e000 0x1000> + <0xf9944000 0x19000>; + interrupts = <0 108 0>; + clocks = <&gcc GCC_BLSP1_UART2_APPS_CLK>, <&gcc GCC_BLSP1_AHB_CLK>; + clock-names = "core", "iface"; + + dmas = <&uart-bam 0 0 1>, <&uart-bam 1 0 0>; + dma-names = "rx", "tx"; + };
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation