All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vinod Koul <vkoul@kernel.org>
To: Lukas Wunner <lukas@wunner.de>
Cc: Mark Brown <broonie@kernel.org>, Stefan Wahren <wahrenst@gmx.net>,
	linux-spi@vger.kernel.org, dmaengine@vger.kernel.org,
	linux-rpi-kernel@lists.infradead.org,
	bcm-kernel-feedback-list@broadcom.com,
	Eric Anholt <eric@anholt.net>, Nuno Sa <nuno.sa@analog.com>,
	Martin Sperl <kernel@martin.sperl.org>,
	Noralf Tronnes <noralf@tronnes.org>,
	Robert Jarzmik <robert.jarzmik@free.fr>,
	Florian Kauer <florian.kauer@koalo.de>,
	Florian Fainelli <f.fainelli@gmail.com>,
	Ray Jui <rjui@broadcom.com>,
	Scott Branden <sbranden@broadcom.com>
Subject: Re: [PATCH 09/10] dmaengine: bcm2835: Avoid accessing memory when copying zeroes
Date: Thu, 8 Aug 2019 18:01:52 +0530	[thread overview]
Message-ID: <20190808123152.GW12733@vkoul-mobl.Dlink> (raw)
In-Reply-To: <a8efa43470bc5092b8727a93c9cf694c80e0c8c4.1564825752.git.lukas@wunner.de>

On 03-08-19, 12:10, Lukas Wunner wrote:
> The BCM2835 DMA controller is capable of synthesizing zeroes instead of
> copying them from a source address. The feature is enabled by setting
> the SRC_IGNORE bit in the Transfer Information field of a Control Block:
> 
> "Do not perform source reads.
>  In addition, destination writes will zero all the write strobes.
>  This is used for fast cache fill operations."
> https://www.raspberrypi.org/app/uploads/2012/02/BCM2835-ARM-Peripherals.pdf
> 
> The feature is only available on 8 of the 16 channels. The others are
> so-called "lite" channels with a limited feature set and performance.
> 
> Enable the feature if a cyclic transaction copies from the zero page.
> This reduces traffic on the memory bus.
> 
> A forthcoming use case is the BCM2835 SPI driver, which will cyclically
> copy from the zero page to the TX FIFO. The idea to use SRC_IGNORE was
> taken from an ancient GitHub conversation between Martin and Noralf:
> https://github.com/msperl/spi-bcm2835/issues/13#issuecomment-98180451

Acked-by: Vinod Koul <vkoul@kernel.org>

> 
> Tested-by: Nuno Sá <nuno.sa@analog.com>
> Signed-off-by: Lukas Wunner <lukas@wunner.de>
> Cc: Martin Sperl <kernel@martin.sperl.org>
> Cc: Noralf Trønnes <noralf@tronnes.org>
> Cc: Florian Kauer <florian.kauer@koalo.de>
> ---
>  drivers/dma/bcm2835-dma.c | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
> 
> diff --git a/drivers/dma/bcm2835-dma.c b/drivers/dma/bcm2835-dma.c
> index 14358faf3bff..67100e4e1083 100644
> --- a/drivers/dma/bcm2835-dma.c
> +++ b/drivers/dma/bcm2835-dma.c
> @@ -42,11 +42,14 @@
>   * @ddev: DMA device
>   * @base: base address of register map
>   * @dma_parms: DMA parameters (to convey 1 GByte max segment size to clients)
> + * @zero_page: bus address of zero page (to detect transactions copying from
> + *	zero page and avoid accessing memory if so)
>   */
>  struct bcm2835_dmadev {
>  	struct dma_device ddev;
>  	void __iomem *base;
>  	struct device_dma_parameters dma_parms;
> +	dma_addr_t zero_page;
>  };
>  
>  struct bcm2835_dma_cb {
> @@ -693,6 +696,7 @@ static struct dma_async_tx_descriptor *bcm2835_dma_prep_dma_cyclic(
>  	size_t period_len, enum dma_transfer_direction direction,
>  	unsigned long flags)
>  {
> +	struct bcm2835_dmadev *od = to_bcm2835_dma_dev(chan->device);
>  	struct bcm2835_chan *c = to_bcm2835_dma_chan(chan);
>  	struct bcm2835_desc *d;
>  	dma_addr_t src, dst;
> @@ -743,6 +747,10 @@ static struct dma_async_tx_descriptor *bcm2835_dma_prep_dma_cyclic(
>  		dst = c->cfg.dst_addr;
>  		src = buf_addr;
>  		info |= BCM2835_DMA_D_DREQ | BCM2835_DMA_S_INC;
> +
> +		/* non-lite channels can write zeroes w/o accessing memory */
> +		if (buf_addr == od->zero_page && !c->is_lite_channel)
> +			info |= BCM2835_DMA_S_IGNORE;
>  	}
>  
>  	/* calculate number of frames */
> @@ -845,6 +853,9 @@ static void bcm2835_dma_free(struct bcm2835_dmadev *od)
>  		list_del(&c->vc.chan.device_node);
>  		tasklet_kill(&c->vc.task);
>  	}
> +
> +	dma_unmap_page_attrs(od->ddev.dev, od->zero_page, PAGE_SIZE,
> +			     DMA_TO_DEVICE, DMA_ATTR_SKIP_CPU_SYNC);
>  }
>  
>  static const struct of_device_id bcm2835_dma_of_match[] = {
> @@ -927,6 +938,14 @@ static int bcm2835_dma_probe(struct platform_device *pdev)
>  
>  	platform_set_drvdata(pdev, od);
>  
> +	od->zero_page = dma_map_page_attrs(od->ddev.dev, ZERO_PAGE(0), 0,
> +					   PAGE_SIZE, DMA_TO_DEVICE,
> +					   DMA_ATTR_SKIP_CPU_SYNC);
> +	if (dma_mapping_error(od->ddev.dev, od->zero_page)) {
> +		dev_err(&pdev->dev, "Failed to map zero page\n");
> +		return -ENOMEM;
> +	}
> +
>  	/* Request DMA channel mask from device tree */
>  	if (of_property_read_u32(pdev->dev.of_node,
>  			"brcm,dma-channel-mask",
> -- 
> 2.20.1

-- 
~Vinod

  reply	other threads:[~2019-08-08 12:33 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-03 10:10 [PATCH 00/10] Raspberry Pi SPI speedups Lukas Wunner
2019-08-03 10:10 ` [PATCH 01/10] dmaengine: bcm2835: Allow reusable descriptors Lukas Wunner
2019-08-08 12:30   ` Vinod Koul
2019-08-03 10:10 ` [PATCH 04/10] spi: bcm2835: Drop dma_pending flag Lukas Wunner
2019-08-03 10:10 ` [PATCH 05/10] spi: bcm2835: Work around DONE bit erratum Lukas Wunner
2019-08-11 19:45   ` Stefan Wahren
2019-08-11 19:57     ` Lukas Wunner
2019-08-11 20:29       ` Eric Anholt
2019-08-19 19:20       ` Stefan Wahren
2019-08-03 10:10 ` [PATCH 09/10] dmaengine: bcm2835: Avoid accessing memory when copying zeroes Lukas Wunner
2019-08-08 12:31   ` Vinod Koul [this message]
2019-08-03 10:10 ` [PATCH 07/10] spi: bcm2835: Speed up TX-only DMA transfers by clearing RX FIFO Lukas Wunner
2019-08-03 10:10 ` [PATCH 06/10] spi: bcm2835: Cache CS register value for ->prepare_message() Lukas Wunner
2019-08-03 10:10 ` [PATCH 02/10] dmaengine: bcm2835: Allow cyclic transactions without interrupt Lukas Wunner
2019-08-08 12:30   ` Vinod Koul
2019-08-03 10:10 ` [PATCH 08/10] dmaengine: bcm2835: Document struct bcm2835_dmadev Lukas Wunner
2019-08-08 12:31   ` Vinod Koul
2019-08-03 10:10 ` [PATCH 10/10] spi: bcm2835: Speed up RX-only DMA transfers by zero-filling TX FIFO Lukas Wunner
2019-08-03 10:10 ` [PATCH 03/10] spi: Guarantee cacheline alignment of driver-private data Lukas Wunner
2019-09-10 11:29   ` Mark Brown
2019-08-03 16:01 ` [PATCH 00/10] Raspberry Pi SPI speedups Noralf Trønnes
2019-08-11 19:50 ` Stefan Wahren
2019-08-11 19:52   ` Lukas Wunner
2019-08-19 19:22 ` Stefan Wahren
2019-08-21 15:21 ` kernel
2019-08-24 10:33 ` Lukas Wunner
2019-09-07  9:06 ` Lukas Wunner
2019-09-09 16:56   ` Mark Brown
2019-09-10 11:21   ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190808123152.GW12733@vkoul-mobl.Dlink \
    --to=vkoul@kernel.org \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=broonie@kernel.org \
    --cc=dmaengine@vger.kernel.org \
    --cc=eric@anholt.net \
    --cc=f.fainelli@gmail.com \
    --cc=florian.kauer@koalo.de \
    --cc=kernel@martin.sperl.org \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=noralf@tronnes.org \
    --cc=nuno.sa@analog.com \
    --cc=rjui@broadcom.com \
    --cc=robert.jarzmik@free.fr \
    --cc=sbranden@broadcom.com \
    --cc=wahrenst@gmx.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.