From: catalin.marinas@arm.com (Catalin Marinas)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v7 3/8] arm64: introduce is_device_dma_coherent
Date: Thu, 6 Nov 2014 10:33:37 +0000 [thread overview]
Message-ID: <20141106103337.GA19702@e104818-lin.cambridge.arm.com> (raw)
In-Reply-To: <alpine.DEB.2.02.1411051757140.22875@kaball.uk.xensource.com>
On Wed, Nov 05, 2014 at 06:15:38PM +0000, Stefano Stabellini wrote:
> On Wed, 5 Nov 2014, Catalin Marinas wrote:
> > On Mon, Nov 03, 2014 at 11:10:18AM +0000, Stefano Stabellini wrote:
> > > On Mon, 3 Nov 2014, Will Deacon wrote:
> > > > On Mon, Nov 03, 2014 at 10:46:03AM +0000, Stefano Stabellini wrote:
> > > > > On Mon, 27 Oct 2014, Stefano Stabellini wrote:
> > > > > > Introduce a boolean flag and an accessor function to check whether a
> > > > > > device is dma_coherent. Set the flag from set_arch_dma_coherent_ops.
> > > > > >
> > > > > > Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
> > > > > > Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
> > > > > > CC: will.deacon at arm.com
> > > > >
> > > > > Will, Catalin,
> > > > > are you OK with this patch?
> > > >
> > > > It would be nicer if the dma_coherent flag didn't have to be duplicated by
> > > > each architecture in dev_archdata. Is there any reason not to put it in the
> > > > core code?
> > >
> > > Yes, there is a reason for it: if I added a boolean dma_coherent flag in
> > > struct device as Catalin initially suggested, what would be the default
> > > for each architecture? Where would I set it for arch that don't use
> > > device tree?
> >
> > You don't need to. An architecture that has coherent DMA always doesn't
> > need to do anything. One that has non-coherent DMA always only needs to
> > select HAVE_DMA_NONCOHERENT. One that has a mix of both needs to find a
> > way to set dev->dma_coherent. Since that's a new API you introduce, it
> > doesn't break any existing architectures.
>
> I am not sure that this is better than the current patch but I can see
> that this approach is not too controversial, so I am happy to go with
> whatever the maintainers prefer.
Functionally it is the same, but just less code duplication.
> > Note that if !is_device_dma_coherent(), it doesn't always mean that
> > standard cache maintenance would be enough (but that's a Xen problem,
> > not sure how to solve).
>
> It is a thorny issue indeed.
> Xen would need to know how to do non-standard cache maintenance
> operations.
Is EL2 hyp or EL1 dom0 doing such maintenance? If the latter, you could
just use the currently registered dma ops.
> Otherwise we would need to resurrect XENFEAT_grant_map_identity (that I
> am reverting in this series) and be content with having CONFIG_XEN_DOM0
> depend on CONFIG_ARM_LPAE.
So what does buy you? Is it just the hope that with LPAE you won't have
weird system caches?
> > diff --git a/arch/Kconfig b/arch/Kconfig
> > index 05d7a8a458d5..8462b2e7491b 100644
> > --- a/arch/Kconfig
> > +++ b/arch/Kconfig
> > @@ -203,6 +203,9 @@ config HAVE_DMA_ATTRS
> > config HAVE_DMA_CONTIGUOUS
> > bool
> >
> > +config HAVE_DMA_NONCOHERENT
> > + bool
> > +
> > config GENERIC_SMP_IDLE_THREAD
> > bool
> >
> > diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
> > index 89c4b5ccc68d..fd7d5522764c 100644
> > --- a/arch/arm/Kconfig
> > +++ b/arch/arm/Kconfig
> > @@ -40,6 +40,7 @@ config ARM
> > select HAVE_DMA_API_DEBUG
> > select HAVE_DMA_ATTRS
> > select HAVE_DMA_CONTIGUOUS if MMU
> > + select HAVE_DMA_NONCOHERENT if OF
> > select HAVE_DYNAMIC_FTRACE if (!XIP_KERNEL)
> > select HAVE_EFFICIENT_UNALIGNED_ACCESS if (CPU_V6 || CPU_V6K || CPU_V7) && MMU
> > select HAVE_FTRACE_MCOUNT_RECORD if (!XIP_KERNEL)
> > diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
> > index 9532f8d5857e..eb7a5aa64e0e 100644
> > --- a/arch/arm64/Kconfig
> > +++ b/arch/arm64/Kconfig
> > @@ -46,6 +46,7 @@ config ARM64
> > select HAVE_DMA_API_DEBUG
> > select HAVE_DMA_ATTRS
> > select HAVE_DMA_CONTIGUOUS
> > + select HAVE_DMA_NONCOHERENT
> > select HAVE_DYNAMIC_FTRACE
> > select HAVE_EFFICIENT_UNALIGNED_ACCESS
> > select HAVE_FTRACE_MCOUNT_RECORD
> > diff --git a/drivers/of/platform.c b/drivers/of/platform.c
> > index 3b64d0bf5bba..7e827726b702 100644
> > --- a/drivers/of/platform.c
> > +++ b/drivers/of/platform.c
> > @@ -183,6 +183,7 @@ static void of_dma_configure(struct device *dev)
> > * dma coherent operations.
> > */
> > if (of_dma_is_coherent(dev->of_node)) {
> > + dev->dma_coherent = true;
> > set_arch_dma_coherent_ops(dev);
> > dev_dbg(dev, "device is dma coherent\n");
> > }
>
> I think that this would need to be #ifdef'ed as it is possible to have
> OF support but no HAVE_DMA_NONCOHERENT (PPC?).
The field is always there. But with !HAVE_DMA_NONCOHERENT,
is_device_dma_coherent() would always return 1. You could avoid
defining is_device_dma_coherent() entirely when !HAVE_DMA_NONCOHERENT,
it wouldn't be worse than your patch in terms of an undefined function.
> > diff --git a/include/linux/device.h b/include/linux/device.h
> > index ce1f21608b16..e00ca876db01 100644
> > --- a/include/linux/device.h
> > +++ b/include/linux/device.h
> > @@ -796,6 +796,7 @@ struct device {
> >
> > bool offline_disabled:1;
> > bool offline:1;
> > + bool dma_coherent:1;
> > };
>
> I guess we would have to #ifdef CONFIG_HAVE_DMA_NONCOHERENT the
> dma_coherent flag, right? Otherwise architecures that do not select
> CONFIG_HAVE_DMA_NONCOHERENT (x86 for example) would end up with a flag
> in struct device that doesn't reflect the properties of the device (dma
> coherent devices with dev->dma_coherent == 0).
In my proposal you should not read this field directly but rather access
it only via is_device_dma_coherent() (you can add a function for setting
it as well).
--
Catalin
next prev parent reply other threads:[~2014-11-06 10:33 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-27 15:08 [PATCH v7 0/8] introduce GNTTABOP_cache_flush Stefano Stabellini
2014-10-27 15:09 ` [PATCH v7 1/8] xen/arm: remove handling of XENFEAT_grant_map_identity Stefano Stabellini
2014-10-27 15:09 ` [PATCH v7 2/8] xen/arm: remove outer_*_range call Stefano Stabellini
2014-10-27 15:09 ` [PATCH v7 3/8] arm64: introduce is_device_dma_coherent Stefano Stabellini
2014-11-03 10:46 ` Stefano Stabellini
2014-11-03 10:57 ` Will Deacon
2014-11-03 11:10 ` Stefano Stabellini
2014-11-04 11:35 ` Grygorii Strashko
2014-11-04 15:00 ` Stefano Stabellini
2014-11-05 16:56 ` Catalin Marinas
2014-11-05 18:15 ` Stefano Stabellini
2014-11-06 10:33 ` Catalin Marinas [this message]
2014-11-06 12:22 ` Stefano Stabellini
2014-11-06 13:40 ` Catalin Marinas
2014-11-07 11:05 ` Catalin Marinas
2014-11-07 11:11 ` Catalin Marinas
2014-11-07 14:10 ` Stefano Stabellini
2014-11-07 14:10 ` Stefano Stabellini
2014-11-07 16:00 ` Catalin Marinas
2014-11-07 17:24 ` Stefano Stabellini
2014-11-07 17:35 ` Stefano Stabellini
2014-11-07 18:14 ` Catalin Marinas
2014-11-07 18:45 ` Stefano Stabellini
2014-11-10 10:16 ` Catalin Marinas
2014-11-10 12:35 ` Stefano Stabellini
2014-11-10 12:41 ` Stefano Stabellini
2014-10-27 15:09 ` [PATCH v7 4/8] arm: " Stefano Stabellini
2014-11-03 10:55 ` Stefano Stabellini
2014-10-27 15:09 ` [PATCH v7 5/8] xen/arm: use is_device_dma_coherent Stefano Stabellini
2014-10-27 15:09 ` [PATCH v7 6/8] xen/arm/arm64: merge xen/mm32.c into xen/mm.c Stefano Stabellini
2014-11-07 14:22 ` Catalin Marinas
2014-11-07 15:28 ` Stefano Stabellini
2014-11-07 16:03 ` Catalin Marinas
2014-11-07 16:46 ` Stefano Stabellini
2014-10-27 15:09 ` [PATCH v7 7/8] xen/arm/arm64: introduce xen_arch_need_swiotlb Stefano Stabellini
2014-11-03 10:45 ` Stefano Stabellini
2014-11-03 11:01 ` [Xen-devel] " David Vrabel
2014-11-03 16:04 ` Konrad Rzeszutek Wilk
2014-10-27 15:09 ` [PATCH v7 8/8] xen/arm: introduce GNTTABOP_cache_flush Stefano Stabellini
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=20141106103337.GA19702@e104818-lin.cambridge.arm.com \
--to=catalin.marinas@arm.com \
--cc=linux-arm-kernel@lists.infradead.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 NNTP newsgroup(s).