From: Russell King - ARM Linux <linux@arm.linux.org.uk>
To: "Krzysztof Hałasa" <khalasa@piap.pl>
Cc: linux-kernel@vger.kernel.org,
James Bottomley <JBottomley@Parallels.com>,
"David S. Miller" <davem@davemloft.net>,
Bjorn Helgaas <bhelgaas@google.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: Re: DMA masks
Date: Fri, 9 Aug 2013 11:48:52 +0100 [thread overview]
Message-ID: <20130809104852.GQ23006@n2100.arm.linux.org.uk> (raw)
In-Reply-To: <m3bo57gnks.fsf@t19.piap.pl>
On Fri, Aug 09, 2013 at 12:34:11PM +0200, Krzysztof Hałasa wrote:
> Russell King - ARM Linux <linux@arm.linux.org.uk> writes:
>
> >> struct device {
> >> ...
> >>
> >> u64 *dma_mask; /* dma mask (if dma'able device) */
> >> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> >
> > "If dma-able device" gives a clue. It is now the case that the DMA API
> > refuses DMA (via dma_supported) if the DMA mask pointer is NULL.
>
> But precisely the same effect can be obtained by setting the (actual)
> dma_mask to 0 (most preferably, using DMA API's dma_set_mask()).
> This is what coherent_dma_mask does.
No. If dma_mask is NULL, then dma_set_mask() will return -EIO no matter
what. If dma_mask is non-NULL, dma_set_mask() will succeed if the mask
is supported by the hardware. For example, on x86:
int dma_set_mask(struct device *dev, u64 mask)
{
if (!dev->dma_mask || !dma_supported(dev, mask))
return -EIO;
*dev->dma_mask = mask;
return 0;
}
EXPORT_SYMBOL(dma_set_mask);
and this is the same pattern we implement on ARM. So, a valid dma_mask
pointer pointing at a variable holding zero can have a supported mask
set.
> Things like this:
> pdev1->dev.dma_mask = &pdev1->dev.coherent_dma_mask;
> pdev1->dev.coherent_dma_mask = DMA_BIT_MASK(32);
> (which are all over the place) make me wonder what happens when some
> code requires and tries to set different masks for normal and coherent
> DMA.
Have you looked at my massive dma-masks patch series earlier this week?
Obviously you haven't...
The separate coherent and streaming masks are only required for a very
small subset of devices (rather systems - non-ARM I add). For the
general case, especially on ARM where the above pattern seems to be
very prevalent, this does not apply; the two masks are always the same.
Many people took the above shortcut, and while not strictly correct, it
is a work-around for the shortcoming in the core device code.
What my patch set does is pull all that out into a central place so that
rather than having to modify a continually growing number of drivers when
we've decided how we're going fix this, we can fix it in one place and
switch everyone over at the same time. That may not be needed now that
Greg has agreed to having stream_dma_mask in the struct device, but
even so I think removing the direct initialization from drivers is a good
idea.
> > However, placing the storage for the dma_mask pointer into struct device
> > is something which I've recently discussed with Greg, and is something
> > he'd like to see happen, so I'll be adding that to my DMA masks patch
> > series in the very near future.
>
> Does this mean the dma_mask would remain a pointer, but it would point
> (usually) to a variable in struct device?
Yes.
next prev parent reply other threads:[~2013-08-09 10:49 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <m3fvujgrcr.fsf@t19.piap.pl>
2013-08-09 9:35 ` Russell King - ARM Linux
2013-08-09 10:34 ` Krzysztof Hałasa
2013-08-09 10:48 ` Russell King - ARM Linux [this message]
2013-08-09 11:38 ` Krzysztof Hałasa
2013-08-09 14:56 ` James Bottomley
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=20130809104852.GQ23006@n2100.arm.linux.org.uk \
--to=linux@arm.linux.org.uk \
--cc=JBottomley@Parallels.com \
--cc=bhelgaas@google.com \
--cc=davem@davemloft.net \
--cc=gregkh@linuxfoundation.org \
--cc=khalasa@piap.pl \
--cc=linux-kernel@vger.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
all inboxes | Powered by JetHome®