From: Christoph Hellwig <hch@lst.de>
To: Alexey Kardashevskiy <aik@ozlabs.ru>
Cc: Michael Ellerman <mpe@ellerman.id.au>,
iommu@lists.linux-foundation.org, linuxppc-dev@lists.ozlabs.org,
Christoph Hellwig <hch@lst.de>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH kernel v2 1/2] dma: Allow mixing bypass and normal IOMMU operation
Date: Tue, 27 Oct 2020 17:48:58 +0100 [thread overview]
Message-ID: <20201027164858.GA30651@lst.de> (raw)
In-Reply-To: <20201027101841.96056-2-aik@ozlabs.ru>
> +static inline bool dma_handle_direct(struct device *dev, dma_addr_t dma_handle)
> +{
> + return dma_handle >= dev->archdata.dma_offset;
> +}
This won't compile except for powerpc, and directly accesing arch members
in common code is a bad idea. Maybe both your helpers need to be
supplied by arch code to better abstract this out.
> if (dma_map_direct(dev, ops))
> addr = dma_direct_map_page(dev, page, offset, size, dir, attrs);
> +#ifdef CONFIG_DMA_OPS_BYPASS_BUS_LIMIT
> + else if (dev->bus_dma_limit &&
> + can_map_direct(dev, (phys_addr_t) page_to_phys(page) + offset + size))
> + addr = dma_direct_map_page(dev, page, offset, size, dir, attrs);
> +#endif
I don't think page_to_phys needs a phys_addr_t on the return value.
I'd also much prefer if we make this a little more beautiful, here
are a few suggestions:
- hide the bus_dma_limit check inside can_map_direct, and provide a
stub so that we can avoid the ifdef
- use a better name for can_map_direct, and maybe also a better calling
convention by passing the page (the sg code also has the page), and
maybe even hide the dma_map_direct inside it.
if (dma_map_direct(dev, ops) ||
arch_dma_map_page_direct(dev, page, offset, size))
addr = dma_direct_map_page(dev, page, offset, size, dir, attrs);
> BUG_ON(!valid_dma_direction(dir));
> if (dma_map_direct(dev, ops))
> dma_direct_unmap_page(dev, addr, size, dir, attrs);
> +#ifdef CONFIG_DMA_OPS_BYPASS_BUS_LIMIT
> + else if (dev->bus_dma_limit && dma_handle_direct(dev, addr + size))
> + dma_direct_unmap_page(dev, addr, size, dir, attrs);
> +#endif
Same here.
> if (dma_map_direct(dev, ops))
> ents = dma_direct_map_sg(dev, sg, nents, dir, attrs);
> +#ifdef CONFIG_DMA_OPS_BYPASS_BUS_LIMIT
> + else if (dev->bus_dma_limit) {
> + struct scatterlist *s;
> + bool direct = true;
> + int i;
> +
> + for_each_sg(sg, s, nents, i) {
> + direct = can_map_direct(dev, sg_phys(s) + s->offset + s->length);
> + if (!direct)
> + break;
> + }
> + if (direct)
> + ents = dma_direct_map_sg(dev, sg, nents, dir, attrs);
> + else
> + ents = ops->map_sg(dev, sg, nents, dir, attrs);
> + }
> +#endif
This needs to go into a helper as well. I think the same style as
above would work pretty nicely as well:
if (dma_map_direct(dev, ops) ||
arch_dma_map_sg_direct(dev, sg, nents))
ents = dma_direct_map_sg(dev, sg, nents, dir, attrs);
else
ents = ops->map_sg(dev, sg, nents, dir, attrs);
> +#ifdef CONFIG_DMA_OPS_BYPASS_BUS_LIMIT
> + if (dev->bus_dma_limit) {
> + struct scatterlist *s;
> + bool direct = true;
> + int i;
> +
> + for_each_sg(sg, s, nents, i) {
> + direct = dma_handle_direct(dev, s->dma_address + s->length);
> + if (!direct)
> + break;
> + }
> + if (direct) {
> + dma_direct_unmap_sg(dev, sg, nents, dir, attrs);
> + return;
> + }
> + }
> +#endif
One more time here..
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
next prev parent reply other threads:[~2020-10-27 16:49 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-27 10:18 [PATCH kernel v2 0/2] DMA, powerpc/dma: Fallback to dma_ops when persistent memory present Alexey Kardashevskiy
2020-10-27 10:18 ` [PATCH kernel v2 1/2] dma: Allow mixing bypass and normal IOMMU operation Alexey Kardashevskiy
2020-10-27 16:48 ` Christoph Hellwig [this message]
2020-10-28 6:55 ` Alexey Kardashevskiy
2020-10-28 17:21 ` Christoph Hellwig
2020-10-28 23:11 ` Alexey Kardashevskiy
2020-10-27 10:18 ` [PATCH kernel v2 2/2] powerpc/dma: Fallback to dma_ops when persistent memory present Alexey Kardashevskiy
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=20201027164858.GA30651@lst.de \
--to=hch@lst.de \
--cc=aik@ozlabs.ru \
--cc=iommu@lists.linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mpe@ellerman.id.au \
/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 NNTP newsgroup(s).