dmaengine Archive mirror
 help / color / mirror / Atom feed
From: Andrea della Porta <aporta@suse.de>
To: Robin Murphy <robin.murphy@arm.com>
Cc: Andrea della Porta <andrea.porta@suse.com>,
	Vinod Koul <vkoul@kernel.org>,
	Florian Fainelli <florian.fainelli@broadcom.com>,
	Ray Jui <rjui@broadcom.com>,
	Scott Branden <sbranden@broadcom.com>,
	Broadcom internal kernel review list
	<bcm-kernel-feedback-list@broadcom.com>,
	dmaengine@vger.kernel.org, linux-rpi-kernel@lists.infradead.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, Maxime Ripard <maxime@cerno.tech>,
	Dom Cobley <popcornmix@gmail.com>,
	Phil Elwell <phil@raspberrypi.com>
Subject: Re: [PATCH 04/12] bcm2835-dma: Advertise the full DMA range
Date: Fri, 1 Mar 2024 14:55:30 +0100	[thread overview]
Message-ID: <ZeHeUh06ZBazgMDO@apocalypse> (raw)
In-Reply-To: <1e71c153-e482-409c-b229-9b9c0662b67e@arm.com>

On 17:55 Mon 05 Feb     , Robin Murphy wrote:
> On 2024-02-04 6:59 am, Andrea della Porta wrote:
> > From: Phil Elwell <phil@raspberrypi.com>
> > 
> > Unless the DMA mask is set wider than 32 bits, DMA mapping will use a
> > bounce buffer.
> > 
> > Signed-off-by: Phil Elwell <phil@raspberrypi.com>
> > ---
> >   drivers/dma/bcm2835-dma.c | 18 +++++++++++++++---
> >   1 file changed, 15 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/dma/bcm2835-dma.c b/drivers/dma/bcm2835-dma.c
> > index 36bad198b655..237dcdb8d726 100644
> > --- a/drivers/dma/bcm2835-dma.c
> > +++ b/drivers/dma/bcm2835-dma.c
> > @@ -39,6 +39,7 @@
> >   #define BCM2711_DMA_MEMCPY_CHAN 14
> >   struct bcm2835_dma_cfg_data {
> > +	u64	dma_mask;
> >   	u32	chan_40bit_mask;
> >   };
> > @@ -308,10 +309,12 @@ DEFINE_SPINLOCK(memcpy_lock);
> >   static const struct bcm2835_dma_cfg_data bcm2835_dma_cfg = {
> >   	.chan_40bit_mask = 0,
> > +	.dma_mask = DMA_BIT_MASK(32),
> >   };
> >   static const struct bcm2835_dma_cfg_data bcm2711_dma_cfg = {
> >   	.chan_40bit_mask = BIT(11) | BIT(12) | BIT(13) | BIT(14),
> > +	.dma_mask = DMA_BIT_MASK(36),
> >   };
> >   static inline size_t bcm2835_dma_max_frame_length(struct bcm2835_chan *c)
> > @@ -1263,6 +1266,8 @@ static struct dma_chan *bcm2835_dma_xlate(struct of_phandle_args *spec,
> >   static int bcm2835_dma_probe(struct platform_device *pdev)
> >   {
> > +	const struct bcm2835_dma_cfg_data *cfg_data;
> > +	const struct of_device_id *of_id;
> >   	struct bcm2835_dmadev *od;
> >   	struct resource *res;
> >   	void __iomem *base;
> > @@ -1272,13 +1277,20 @@ static int bcm2835_dma_probe(struct platform_device *pdev)
> >   	int irq_flags;
> >   	uint32_t chans_available;
> >   	char chan_name[BCM2835_DMA_CHAN_NAME_SIZE];
> > -	const struct of_device_id *of_id;
> >   	int chan_count, chan_start, chan_end;
> > +	of_id = of_match_node(bcm2835_dma_of_match, pdev->dev.of_node);
> > +	if (!of_id) {
> > +		dev_err(&pdev->dev, "Failed to match compatible string\n");
> > +		return -EINVAL;
> > +	}
> > +
> > +	cfg_data = of_id->data;
> 
> We've had of_device_get_match_data() for nearly 9 years now, and even a
> generic device_get_match_data() for 6 ;)
> 
> > +
> >   	if (!pdev->dev.dma_mask)
> >   		pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
> 
> [ Passing nit: that also really shouldn't be there, especially since
> cdfee5623290 ]
> 
> > -	rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
> > +	rc = dma_set_mask_and_coherent(&pdev->dev, cfg_data->dma_mask);
> 
> Wait, does chan_40bit_mask mean that you still have some channels which
> *can't* address this full mask? If so this can't work properly. You may well
> need to redesign a bit further to have a separate DMA device for each
> channel such they can each have different masks.
>

It seems that the original intention here was to create a device for each value of dma_mask in
hw descriptors. That is, for 2711 which has 32 and 40 bit channels, the DT should look something
like this:

	dma: dma-controller@7e007000 {
		interrupts = <...>;
		brcm,dma-channel-mask = <0x7f5>;
		compatible = "brcm,bcm2835-dma";
		interrupt-names = "...";
		reg = <0x7e007000 0xb00>;
		#dma-cells = <0x01>;
	};      

	dma40: dma-controller@7e007b00 {
		interrupts = <...>;     
		brcm,dma-channel-mask = <0x3000>;
		compatible = "brcm,bcm2711-dma";
		interrupt-names = "...";
		reg = <0x00 0x7e007b00 0x00 0x400>;
		#dma-cells = <0x01>;
	};

Two devices dma0 and dma1 will be created, each one serving a different mask and the call
to dma_set_mask_and_coherent(..., dma_mask) on the specific device will be consistent. Please
note that of course "brcm,dma-channel-mask" from DT only refers to what channels are available
to be used in the kernel, while dma_mask parameter of the aforementioned dma_set_mask_and_coherent()
call is the addressing mask enforced by the driver, and its the same for each specific device
(dma0 or dma1).

Many thanks,
Andrea

  reply	other threads:[~2024-03-01 13:55 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-04  6:59 [PATCH 00/12] Add support for BCM2712 DMA engine Andrea della Porta
2024-02-04  6:59 ` [PATCH 01/12] bcm2835-dma: Add support for per-channel flags Andrea della Porta
2024-02-04  6:59 ` [PATCH 02/12] bcm2835-dma: Add proper 40-bit DMA support Andrea della Porta
2024-02-05 18:50   ` Stefan Wahren
2024-02-06 16:31     ` Dave Stevenson
2024-02-06 18:08       ` Stefan Wahren
2024-02-06 18:11         ` Stefan Wahren
2024-02-04  6:59 ` [PATCH 03/12] bcm2835-dma: Add NO_WAIT_RESP, DMA_WIDE_SOURCE and DMA_WIDE_DEST flag Andrea della Porta
2024-02-04  6:59 ` [PATCH 04/12] bcm2835-dma: Advertise the full DMA range Andrea della Porta
2024-02-05 17:55   ` Robin Murphy
2024-03-01 13:55     ` Andrea della Porta [this message]
2024-02-05 18:25   ` Stefan Wahren
2024-02-04  6:59 ` [PATCH 05/12] bcm2835-dma: Derive slave DMA addresses correctly Andrea della Porta
2024-02-05 18:03   ` Robin Murphy
2024-02-04  6:59 ` [PATCH 06/12] dmaengine: bcm2835: Use to_bcm2711_cbaddr where relevant Andrea della Porta
2024-02-04 17:04   ` Florian Fainelli
2024-02-05 10:25     ` Andrea della Porta
2024-02-04  6:59 ` [PATCH 07/12] bcm2835-dma: Support dma flags for multi-beat burst Andrea della Porta
2024-02-07  8:22   ` Vinod Koul
2024-02-04  6:59 ` [PATCH 08/12] bcm2835-dma: Need to keep PROT bits set in CS on 40bit controller Andrea della Porta
2024-02-04  6:59 ` [PATCH 09/12] dmaengine: bcm2835: Add BCM2712 support Andrea della Porta
2024-02-04  6:59 ` [PATCH 10/12] dmaengine: bcm2835: Support DMA-Lite channels Andrea della Porta
2024-02-07  8:26   ` Vinod Koul
2024-02-04  6:59 ` [PATCH 11/12] dmaengine: bcm2835: Rename to_bcm2711_cbaddr to to_40bit_cbaddr Andrea della Porta
2024-02-04  6:59 ` [PATCH 12/12] bcm2835-dma: Fixes for dma_abort Andrea della Porta
2024-02-05 19:06 ` [PATCH 00/12] Add support for BCM2712 DMA engine Stefan Wahren
2024-02-07  8:19 ` Vinod Koul
2024-02-07 10:24   ` Andrea della Porta

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=ZeHeUh06ZBazgMDO@apocalypse \
    --to=aporta@suse.de \
    --cc=andrea.porta@suse.com \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=dmaengine@vger.kernel.org \
    --cc=florian.fainelli@broadcom.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=maxime@cerno.tech \
    --cc=phil@raspberrypi.com \
    --cc=popcornmix@gmail.com \
    --cc=rjui@broadcom.com \
    --cc=robin.murphy@arm.com \
    --cc=sbranden@broadcom.com \
    --cc=vkoul@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).