linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC 1/2] arm64: Add support for system cache memory type
@ 2021-11-16 23:15 Georgi Djakov
  2021-11-16 23:16 ` [RFC 2/2] drm/msm/gem: Make use of the system cache Georgi Djakov
  2021-11-17 10:04 ` [RFC 1/2] arm64: Add support for system cache memory type Christoph Hellwig
  0 siblings, 2 replies; 4+ messages in thread
From: Georgi Djakov @ 2021-11-16 23:15 UTC (permalink / raw)
  To: catalin.marinas, will, robdclark
  Cc: sean, robin.murphy, maz, arnd, linux-arm-kernel, linux-kernel, iommu

From: "Isaac J. Manjarres" <isaacm@codeaurora.org>

Non-coherent devices on systems that support a system or
last level cache may want to request that allocations be
cached in the system cache. For memory that is allocated
by the kernel, and used for DMA with devices, the memory
attributes used for CPU access should match the memory
attributes that will be used for device access.

The memory attributes that need to be programmed into
the MAIR for system cache usage are:

0xf4 - Normal memory, outer write back read/write allocate,
inner non-cacheable.

There is currently no support for this memory attribute for
CPU mappings, so add it.

Signed-off-by: Isaac J. Manjarres <isaacm@codeaurora.org>
Signed-off-by: Georgi Djakov <quic_c_gdjako@quicinc.com>
---
 arch/arm64/include/asm/memory.h  | 1 +
 arch/arm64/include/asm/pgtable.h | 9 +++++++++
 arch/arm64/include/asm/sysreg.h  | 1 +
 arch/arm64/mm/proc.S             | 3 ++-
 include/linux/dma-map-ops.h      | 8 ++++++++
 5 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h
index 0af70d9abede..22553aab67a4 100644
--- a/arch/arm64/include/asm/memory.h
+++ b/arch/arm64/include/asm/memory.h
@@ -134,6 +134,7 @@
 #define MT_NORMAL_NC		2
 #define MT_DEVICE_nGnRnE	3
 #define MT_DEVICE_nGnRE		4
+#define MT_NORMAL_iNC_oWB	5
 
 /*
  * Memory types for Stage-2 translation
diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
index c4ba047a82d2..681c294c364e 100644
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -524,6 +524,15 @@ static inline pmd_t pmd_mkdevmap(pmd_t pmd)
 	__pgprot_modify(prot, PTE_ATTRINDX_MASK, \
 			PTE_ATTRINDX(MT_NORMAL_NC) | PTE_PXN | PTE_UXN)
 
+/*
+ * Mark the prot value as outer cacheable and inner non-cacheable. Non-coherent
+ * devices on a system with support for a system or last level cache use these
+ * attributes to cache allocations in the system cache.
+ */
+#define pgprot_syscached(prot) \
+	__pgprot_modify(prot, PTE_ATTRINDX_MASK, \
+			PTE_ATTRINDX(MT_NORMAL_iNC_oWB) | PTE_PXN | PTE_UXN)
+
 #define __HAVE_PHYS_MEM_ACCESS_PROT
 struct file;
 extern pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h
index 16b3f1a1d468..7c50b1840532 100644
--- a/arch/arm64/include/asm/sysreg.h
+++ b/arch/arm64/include/asm/sysreg.h
@@ -715,6 +715,7 @@
 #define MAIR_ATTR_NORMAL_TAGGED		UL(0xf0)
 #define MAIR_ATTR_NORMAL		UL(0xff)
 #define MAIR_ATTR_MASK			UL(0xff)
+#define MAIR_ATTR_NORMAL_iNC_oWB	UL(0xf4)
 
 /* Position the attr at the correct index */
 #define MAIR_ATTRIDX(attr, idx)		((attr) << ((idx) * 8))
diff --git a/arch/arm64/mm/proc.S b/arch/arm64/mm/proc.S
index d35c90d2e47a..8a75973e5148 100644
--- a/arch/arm64/mm/proc.S
+++ b/arch/arm64/mm/proc.S
@@ -64,7 +64,8 @@
 	 MAIR_ATTRIDX(MAIR_ATTR_DEVICE_nGnRE, MT_DEVICE_nGnRE) |	\
 	 MAIR_ATTRIDX(MAIR_ATTR_NORMAL_NC, MT_NORMAL_NC) |		\
 	 MAIR_ATTRIDX(MAIR_ATTR_NORMAL, MT_NORMAL) |			\
-	 MAIR_ATTRIDX(MAIR_ATTR_NORMAL, MT_NORMAL_TAGGED))
+	 MAIR_ATTRIDX(MAIR_ATTR_NORMAL, MT_NORMAL_TAGGED) |		\
+	 MAIR_ATTRIDX(MAIR_ATTR_NORMAL_iNC_oWB, MT_NORMAL_iNC_oWB))
 
 #ifdef CONFIG_CPU_PM
 /**
diff --git a/include/linux/dma-map-ops.h b/include/linux/dma-map-ops.h
index 0d5b06b3a4a6..1f7d75201577 100644
--- a/include/linux/dma-map-ops.h
+++ b/include/linux/dma-map-ops.h
@@ -277,6 +277,14 @@ void arch_dma_free(struct device *dev, size_t size, void *cpu_addr,
 #define pgprot_dmacoherent(prot)	pgprot_noncached(prot)
 #endif
 
+/*
+ * If there is no system cache pgprot, then fallback to dmacoherent
+ * pgprot, as the expectation is that the device is not coherent.
+ */
+#ifndef pgprot_syscached
+#define pgprot_syscached(prot)		pgprot_dmacoherent(prot)
+#endif
+
 pgprot_t dma_pgprot(struct device *dev, pgprot_t prot, unsigned long attrs);
 #else
 static inline pgprot_t dma_pgprot(struct device *dev, pgprot_t prot,

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [RFC 2/2]  drm/msm/gem: Make use of the system cache
  2021-11-16 23:15 [RFC 1/2] arm64: Add support for system cache memory type Georgi Djakov
@ 2021-11-16 23:16 ` Georgi Djakov
  2021-11-17  7:37   ` Arnd Bergmann
  2021-11-17 10:04 ` [RFC 1/2] arm64: Add support for system cache memory type Christoph Hellwig
  1 sibling, 1 reply; 4+ messages in thread
From: Georgi Djakov @ 2021-11-16 23:16 UTC (permalink / raw)
  To: catalin.marinas, will, robdclark
  Cc: sean, robin.murphy, maz, arnd, linux-arm-kernel, linux-kernel, iommu

Instead of writing to WC cmdstream buffers that go all the way to the main
memory, let's use the system cache to improve the performance.

Signed-off-by: Georgi Djakov <quic_c_gdjako@quicinc.com>
---
 drivers/gpu/drm/msm/msm_gem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c
index 104fdfc14027..921a1c24721e 100644
--- a/drivers/gpu/drm/msm/msm_gem.c
+++ b/drivers/gpu/drm/msm/msm_gem.c
@@ -214,7 +214,7 @@ void msm_gem_put_pages(struct drm_gem_object *obj)
 static pgprot_t msm_gem_pgprot(struct msm_gem_object *msm_obj, pgprot_t prot)
 {
 	if (msm_obj->flags & (MSM_BO_WC|MSM_BO_UNCACHED))
-		return pgprot_writecombine(prot);
+		return pgprot_syscached(prot);
 	return prot;
 }
 

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [RFC 2/2] drm/msm/gem: Make use of the system cache
  2021-11-16 23:16 ` [RFC 2/2] drm/msm/gem: Make use of the system cache Georgi Djakov
@ 2021-11-17  7:37   ` Arnd Bergmann
  0 siblings, 0 replies; 4+ messages in thread
From: Arnd Bergmann @ 2021-11-17  7:37 UTC (permalink / raw)
  To: Georgi Djakov
  Cc: Catalin Marinas, Will Deacon, Rob Clark, Sean Paul, Robin Murphy,
	Marc Zyngier, Arnd Bergmann, Linux ARM,
	Linux Kernel Mailing List, open list:IOMMU DRIVERS

On Wed, Nov 17, 2021 at 12:16 AM Georgi Djakov
<quic_c_gdjako@quicinc.com> wrote:
>
> Instead of writing to WC cmdstream buffers that go all the way to the main
> memory, let's use the system cache to improve the performance.
>
> Signed-off-by: Georgi Djakov <quic_c_gdjako@quicinc.com>
> ---
>  drivers/gpu/drm/msm/msm_gem.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c
> index 104fdfc14027..921a1c24721e 100644
> --- a/drivers/gpu/drm/msm/msm_gem.c
> +++ b/drivers/gpu/drm/msm/msm_gem.c
> @@ -214,7 +214,7 @@ void msm_gem_put_pages(struct drm_gem_object *obj)
>  static pgprot_t msm_gem_pgprot(struct msm_gem_object *msm_obj, pgprot_t prot)
>  {
>         if (msm_obj->flags & (MSM_BO_WC|MSM_BO_UNCACHED))
> -               return pgprot_writecombine(prot);
> +               return pgprot_syscached(prot);
>         return prot;
>  }

Based on the definition in patch 1, doesn't this mean that 32-bit
kernels degrade
from writecombined to uncached, making them a lot slower?

My feeling about this series is that there should be a clearer
definition of what
exactly happens on systems with and without system cache.

         Arnd

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFC 1/2] arm64: Add support for system cache memory type
  2021-11-16 23:15 [RFC 1/2] arm64: Add support for system cache memory type Georgi Djakov
  2021-11-16 23:16 ` [RFC 2/2] drm/msm/gem: Make use of the system cache Georgi Djakov
@ 2021-11-17 10:04 ` Christoph Hellwig
  1 sibling, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2021-11-17 10:04 UTC (permalink / raw)
  To: Georgi Djakov
  Cc: catalin.marinas, will, robdclark, arnd, sean, linux-kernel,
	iommu, maz, robin.murphy, linux-arm-kernel

On Tue, Nov 16, 2021 at 03:15:59PM -0800, Georgi Djakov wrote:
>  include/linux/dma-map-ops.h      | 8 ++++++++

Your forgot to CC the maintainer.  Also don't try to ever hide DMA
core changes in arch specific patches ever again.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-11-17 10:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-16 23:15 [RFC 1/2] arm64: Add support for system cache memory type Georgi Djakov
2021-11-16 23:16 ` [RFC 2/2] drm/msm/gem: Make use of the system cache Georgi Djakov
2021-11-17  7:37   ` Arnd Bergmann
2021-11-17 10:04 ` [RFC 1/2] arm64: Add support for system cache memory type Christoph Hellwig

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).