ARM: Add support for Hisilicon Kunpeng L3 cache controller
Subsystems (5)
v7 cover ARM: Add support for Hisilicon Kunpeng L3 cache controller
v6 --> v7:
1. Change all readl()/writel() to _relaxed(), add the corresponding description to the code.
2. Delete the unnecessary spinlock protection in l3cache_init().
v5 --> v6:
1. Use raw_spin_lock_irqsave() instead of spin_lock_irqsave()
2. Move the macros defined in cache-kunpeng-l3.h into cache-kunpeng-l3.c, and delete that header file.
3. In some places, replace readl()/writel() with readl_relaxed()/writel_relaxed() to improve performance without affecting functions.
4. Returns 0 instead of an error code when Kunpeng L3 Cache matching failed.
Thank you for Arnd's review comments and Russell's help.
v4 --> v5:
1. Add SoC macro ARCH_KUNPENG50X, and the Kunpeng L3 cache controller only enabled on that platform.
2. Require the compatible string of the Kunpeng L3 cache controller must have a relevant name on a specific SoC. For example:
compatible = "hisilicon,kunpeng509-l3cache", "hisilicon,kunpeng-l3cache";
v3 --> v4:
Rename the compatible string from "hisilicon,l3cache" to "hisilicon,kunpeng-l3cache". Then adjust the file name, configuration option name, and description accordingly.
v2 --> v3:
Add Hisilicon L3 cache controller driver and its document. That's: patch 2-3.
v1 --> v2:
Discard the middle-tier functions and do silent narrowing cast in the outcache hook functions. For example:
-static void l2c220_inv_range(unsigned long start, unsigned long end) +static void l2c220_inv_range(phys_addr_t pa_start, phys_addr_t pa_end)
{
+ unsigned long start = pa_start;
+ unsigned long end = pa_end;
v1:
Do cast phys_addr_t to unsigned long by adding a middle-tier function. For example:
-static void l2c220_inv_range(unsigned long start, unsigned long end) +static void __l2c220_inv_range(unsigned long start, unsigned long end)
{
...
}
+static void l2c220_inv_range(phys_addr_t start, phys_addr_t end) +{
+ __l2c220_inv_range(start, end);
+}
Zhen Lei (4):
ARM: LPAE: Use phys_addr_t instead of unsigned long in outercache
hooks
ARM: hisi: add support for Kunpeng50x SoC
dt-bindings: arm: hisilicon: Add binding for Kunpeng L3 cache
controller
ARM: Add support for Hisilicon Kunpeng L3 cache controller
.../arm/hisilicon/kunpeng-l3cache.yaml | 40 ++++ arch/arm/include/asm/outercache.h | 6 +- arch/arm/mach-hisi/Kconfig | 6 + arch/arm/mm/Kconfig | 10 + arch/arm/mm/Makefile | 1 + arch/arm/mm/cache-feroceon-l2.c | 15 +- arch/arm/mm/cache-kunpeng-l3.c | 178 ++++++++++++++++++ arch/arm/mm/cache-l2x0.c | 50 +++-- arch/arm/mm/cache-tauros2.c | 15 +- arch/arm/mm/cache-uniphier.c | 6 +- arch/arm/mm/cache-xsc3l2.c | 12 +- 11 files changed, 310 insertions(+), 29 deletions(-) create mode 100644 Documentation/devicetree/bindings/arm/hisilicon/kunpeng-l3cache.yaml create mode 100644 arch/arm/mm/cache-kunpeng-l3.c
Signature · 1 line
2.26.0.106.g9fadedd
PATCH v7 1/4 ARM: LPAE: Use phys_addr_t instead of unsigned long in outercache hooks
The outercache of some Hisilicon SOCs support physical addresses wider than 32-bits. The unsigned long datatype is not sufficient for mapping physical addresses >= 4GB. The commit ad6b9c9d78b9 ("ARM: 6671/1: LPAE:
use phys_addr_t instead of unsigned long in outercache functions") has already modified the outercache functions. But the parameters of the outercache hooks are not changed. This patch use phys_addr_t instead of unsigned long in outercache hooks: inv_range, clean_range, flush_range.
To ensure the outercache that does not support LPAE works properly, do cast phys_addr_t to unsigned long by adding a group of temporary variables. For example:
-static void l2c220_inv_range(unsigned long start, unsigned long end) +static void l2c220_inv_range(phys_addr_t pa_start, phys_addr_t pa_end)
{
+ unsigned long start = pa_start;
+ unsigned long end = pa_end;
Note that the outercache functions have been doing this cast before this patch. So now, the cast is just moved into the outercache hook functions.
No functional change.
--- arch/arm/include/asm/outercache.h | 6 ++-- arch/arm/mm/cache-feroceon-l2.c | 15 ++++++++-- arch/arm/mm/cache-l2x0.c | 50 ++++++++++++++++++++++--------- arch/arm/mm/cache-tauros2.c | 15 ++++++++-- arch/arm/mm/cache-uniphier.c | 6 ++-- arch/arm/mm/cache-xsc3l2.c | 12 ++++++-- 6 files changed, 75 insertions(+), 29 deletions(-)
arch/arm/include/asm/outercache.h +3 -3
@@ -14,9 +14,9 @@struct l2x0_regs ;struct outer_cache_fns { -void (*inv_range)(unsigned long ,unsigned long ); -void (*clean_range)(unsigned long ,unsigned long ); -void (*flush_range)(unsigned long ,unsigned long ); +void (*inv_range)(phys_addr_t ,phys_addr_t ); +void (*clean_range)(phys_addr_t ,phys_addr_t ); +void (*flush_range)(phys_addr_t ,phys_addr_t );void (*flush_all)(void );void (*disable)(void );#ifdef CONFIG_OUTER_CACHE_SYNC
arch/arm/mm/cache-feroceon-l2.c +12 -3
@@ -168,8 +168,11 @@ static unsigned long calc_range_end(unsigned long start, unsigned long end)return range_end; } -static void feroceon_l2_inv_range (unsigned long start,unsigned long end) +static void feroceon_l2_inv_range (phys_addr_t pa_start,phys_addr_t pa_end) { +unsigned long start = pa_start; +unsigned long end = pa_end; +/* * Clean and invalidate partial first cache line. */
@@ -198,8 +201,11 @@ static void feroceon_l2_inv_range(unsigned long start, unsigned long end)dsb (); } -static void feroceon_l2_clean_range (unsigned long start,unsigned long end) +static void feroceon_l2_clean_range (phys_addr_t pa_start,phys_addr_t pa_end) { +unsigned long start = pa_start; +unsigned long end = pa_end; +/* * If L2 is forced to WT, the L2 will always be clean and we * don't need to do anything here.
@@ -217,8 +223,11 @@ static void feroceon_l2_clean_range(unsigned long start, unsigned long end)dsb (); } -static void feroceon_l2_flush_range (unsigned long start,unsigned long end) +static void feroceon_l2_flush_range (phys_addr_t pa_start,phys_addr_t pa_end) { +unsigned long start = pa_start; +unsigned long end = pa_end; + start &= ~(CACHE_LINE_SIZE -1 ); end = (end +CACHE_LINE_SIZE -1 ) & ~(CACHE_LINE_SIZE -1 );while (start != end) {
arch/arm/mm/cache-l2x0.c +36 -14
143 lines not on this page · raw message
arch/arm/mm/cache-tauros2.c +12 -3
@@ -66,8 +66,11 @@ static inline void tauros2_inv_pa(unsigned long addr)*/ #define CACHE_LINE_SIZE 32 -static void tauros2_inv_range (unsigned long start,unsigned long end) +static void tauros2_inv_range (phys_addr_t pa_start,phys_addr_t pa_end) { +unsigned long start = pa_start; +unsigned long end = pa_end; +/* * Clean and invalidate partial first cache line. */
@@ -95,8 +98,11 @@ static void tauros2_inv_range(unsigned long start, unsigned long end)dsb (); } -static void tauros2_clean_range (unsigned long start,unsigned long end) +static void tauros2_clean_range (phys_addr_t pa_start,phys_addr_t pa_end) { +unsigned long start = pa_start; +unsigned long end = pa_end; + start &= ~(CACHE_LINE_SIZE -1 );while (start < end) {tauros2_clean_pa (start);
@@ -106,8 +112,11 @@ static void tauros2_clean_range(unsigned long start, unsigned long end)dsb (); } -static void tauros2_flush_range (unsigned long start,unsigned long end) +static void tauros2_flush_range (phys_addr_t pa_start,phys_addr_t pa_end) { +unsigned long start = pa_start; +unsigned long end = pa_end; + start &= ~(CACHE_LINE_SIZE -1 );while (start < end) {tauros2_clean_inv_pa (start);
arch/arm/mm/cache-uniphier.c +3 -3
@@ -250,17 +250,17 @@ static void uniphier_cache_maint_all(u32 operation)__uniphier_cache_maint_all (data, operation); } -static void uniphier_cache_inv_range (unsigned long start,unsigned long end) +static void uniphier_cache_inv_range (phys_addr_t start,phys_addr_t end) {uniphier_cache_maint_range (start, end,UNIPHIER_SSCOQM_CM_INV ); } -static void uniphier_cache_clean_range (unsigned long start,unsigned long end) +static void uniphier_cache_clean_range (phys_addr_t start,phys_addr_t end) {uniphier_cache_maint_range (start, end,UNIPHIER_SSCOQM_CM_CLEAN ); } -static void uniphier_cache_flush_range (unsigned long start,unsigned long end) +static void uniphier_cache_flush_range (phys_addr_t start,phys_addr_t end) {uniphier_cache_maint_range (start, end,UNIPHIER_SSCOQM_CM_FLUSH ); }
arch/arm/mm/cache-xsc3l2.c +9 -3
@@ -83,8 +83,10 @@ static inline unsigned long l2_map_va(unsigned long pa, unsigned long prev_va)#endif } -static void xsc3_l2_inv_range (unsigned long start,unsigned long end) +static void xsc3_l2_inv_range (phys_addr_t pa_start,phys_addr_t pa_end) { +unsigned long start = pa_start; +unsigned long end = pa_end;unsigned long vaddr;if (start ==0 && end ==-1ul ) {
@@ -127,8 +129,10 @@ static void xsc3_l2_inv_range(unsigned long start, unsigned long end)dsb (); } -static void xsc3_l2_clean_range (unsigned long start,unsigned long end) +static void xsc3_l2_clean_range (phys_addr_t pa_start,phys_addr_t pa_end) { +unsigned long start = pa_start; +unsigned long end = pa_end;unsigned long vaddr; vaddr =-1 ;/* to force the first mapping */
@@ -165,8 +169,10 @@ static inline void xsc3_l2_flush_all(void)dsb (); } -static void xsc3_l2_flush_range (unsigned long start,unsigned long end) +static void xsc3_l2_flush_range (phys_addr_t pa_start,phys_addr_t pa_end) { +unsigned long start = pa_start; +unsigned long end = pa_end;unsigned long vaddr;if (start ==0 && end ==-1ul ) {
Signature · 1 line
2.26.0.106.g9fadedd
PATCH v7 2/4 ARM: hisi: add support for Kunpeng50x SoC
In reply to Zhen LeiEnable support for the Hisilicon Kunpeng506 and Kunpeng509 SoC.
--- arch/arm/mach-hisi/Kconfig | 6 ++++++ 1 file changed, 6 insertions(+)
arch/arm/mach-hisi/Kconfig +6 -0
@@ -55,6 +55,12 @@ config ARCH_HIX5HD2 help Support for Hisilicon HIX5HD2 SoC family +config ARCH_KUNPENG50X + bool "Hisilicon Kunpeng50x family" + depends on ARCH_MULTI_V7 + help + Support for Hisilicon Kunpeng506 and Kunpeng509 SoC family + config ARCH_SD5203 bool "Hisilicon SD5203 family" depends on ARCH_MULTI_V5
Signature · 1 line
2.26.0.106.g9fadedd
PATCH v7 3/4 dt-bindings: arm: hisilicon: Add binding for Kunpeng L3 cache controller
In reply to Zhen LeiAdd devicetree binding for Hisilicon Kunpeng L3 cache controller.
--- .../arm/hisilicon/kunpeng-l3cache.yaml | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Documentation/devicetree/bindings/arm/hisilicon/kunpeng-l3cache.yaml
Documentation/devicetree/bindings/arm/hisilicon/kunpeng-l3cache.yaml new file +40 -0
@@ -0,0 +1,40 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/arm/hisilicon/kunpeng-l3cache.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Hisilicon Kunpeng L3 cache controller + +maintainers: + - Wei Xu <[email protected]> + +description: | + The Hisilicon Kunpeng L3 outer cache controller supports a maximum of 36-bit + physical addresses. The data cached in the L3 outer cache can be operated + based on the physical address range or the entire cache. + +properties: + compatible: + items: + - enum: + - hisilicon,kunpeng506-l3cache + - hisilicon,kunpeng509-l3cache + - const: hisilicon,kunpeng-l3cache + + reg: + maxItems: 1 + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + l3cache@f302b000 { + compatible = "hisilicon,kunpeng509-l3cache", "hisilicon,kunpeng-l3cache"; + reg = <0xf302b000 0x1000>; + }; +...
Signature · 1 line
2.26.0.106.g9fadedd
Re: [PATCH v7 3/4] dt-bindings: arm: hisilicon: Add binding for Kunpeng L3 cache controller
Quoted 9 lines · Zhen Lei
Add devicetree binding for Hisilicon Kunpeng L3 cache controller.
Signed-off-by Zhen Lei <[email protected]>Reviewed-by Arnd Bergmann <[email protected]>--- .../arm/hisilicon/kunpeng-l3cache.yaml | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Documentation/devicetree/bindings/arm/hisilicon/kunpeng-l3cache.yaml
PATCH v7 4/4 ARM: Add support for Hisilicon Kunpeng L3 cache controller
In reply to Zhen LeiAdd support for the Hisilicon Kunpeng L3 cache controller as used with Kunpeng506 and Kunpeng509 SoCs.
These Hisilicon SoCs support LPAE, so the physical addresses is wider than 32-bits, but the actual bit width does not exceed 36 bits. When the cache operation is performed based on the address range, the upper 30 bits of the physical address are recorded in registers L3_MAINT_START and L3_MAINT_END, and ignore the lower 6 bits cacheline offset.
--- arch/arm/mm/Kconfig | 10 ++ arch/arm/mm/Makefile | 1 + arch/arm/mm/cache-kunpeng-l3.c | 178 +++++++++++++++++++++++++++++++++ 3 files changed, 189 insertions(+) create mode 100644 arch/arm/mm/cache-kunpeng-l3.c
arch/arm/mm/Kconfig +10 -0
@@ -1070,6 +1070,16 @@ config CACHE_XSC3L2 help This option enables the L2 cache on XScale3. +config CACHE_KUNPENG_L3 + bool "Enable the Hisilicon Kunpeng L3 cache controller" + depends on ARCH_KUNPENG50X && OF + default y + select OUTER_CACHE + help + This option enables the Kunpeng L3 cache controller on Hisilicon + Kunpeng506 and Kunpeng509 SoCs. It supports a maximum of 36-bit + physical addresses. + config ARM_L1_CACHE_SHIFT_6 bool default y if CPU_V7
arch/arm/mm/Makefile +1 -0
@@ -112,6 +112,7 @@ obj-$(CONFIG_CACHE_L2X0_PMU) += cache-l2x0-pmu.o obj-$(CONFIG_CACHE_XSC3L2) += cache-xsc3l2.o obj-$(CONFIG_CACHE_TAUROS2) += cache-tauros2.o obj-$(CONFIG_CACHE_UNIPHIER) += cache-uniphier.o +obj-$(CONFIG_CACHE_KUNPENG_L3) += cache-kunpeng-l3.o KASAN_SANITIZE_kasan_init.o := n obj-$(CONFIG_KASAN) += kasan_init.o
arch/arm/mm/cache-kunpeng-l3.c new file +178 -0
178 lines not on this page · raw message
Signature · 1 line
2.26.0.106.g9fadedd
arch/arm/mm/cache-kunpeng-l3.c line 45
Quoted 6 lines · Zhen Lei
arch/arm/mm/cache-kunpeng-l3.c new file +6
-0+ +/* +* All read and write operations on L3 cache registers are protected by the +* spinlock, except for l3cache_init(). Each time the L3 cache operation is +* performed, all related information is filled into its registers. Therefore, +* there is no memory order problem when only _relaxed() functions are used.
Thank you for including the text.
I don't think the explanation with the spin_lock() explains why this can be considered safe though, as spin_lock() only contains serialization against other CPUs (smp_mb()) rather than the stronger DMA barriers implied by readl and writel. As Russell previously explained, these barriers are the L1 cache operations (e.g. v7_dma_inv_range) do include stronger barriers, so it would be better to come up with a justification based on those.
Quoted 3 lines
+ * This can help us achieve some performance improvement:
+ * 1) Thereadl_relaxed()is about 20ns faster thanreadl().
+ * 2) Thewritel_relaxed()is about 123ns faster thanwritel().
These are not really the performance numbers I asked for, as a low-level benchmark comparing the instructions is rather meaningless. The time spent waiting for the barrier depends on what else is going on around the barrier. Also, most of the time would likely be spent spinning in the loop around readl() while the cache operations are in progress, so the latency of a single readl() is not necessarily significant.
To have a more useful performance number, try mentioning the most performance sensitive non-coherent DMA master on one of the chips that has this cache controller, and a high-level performance number such as "1.2% more network packets per second" if that is something you can measure easily.
Of course, if all high-speed DMA masters on this chip are cache coherent, there is no need for performance numbers, just mention that we don't care about speed in that case.
Arnd
Quoted 10 lines · Arnd Bergmann
arch/arm/mm/cache-kunpeng-l3.c line 45
Quoted 6 lines · Zhen Lei
arch/arm/mm/cache-kunpeng-l3.c new file +6
-0+ +/* +* All read and write operations on L3 cache registers are protected by the +* spinlock, except for l3cache_init(). Each time the L3 cache operation is +* performed, all related information is filled into its registers. Therefore, +* there is no memory order problem when only _relaxed() functions are used. Thank you for including the text.
Quoted 7 lines
I don't think the explanation with the
spin_lock()explains why this can be considered safe though, asspin_lock()only contains serialization against other CPUs (smp_mb()) rather than the stronger DMA barriers implied by readl and writel. As Russell previously explained, these barriers are the L1 cache operations (e.g.v7_dma_inv_range) do include stronger barriers, so it would be better to come up with a justification based on those.
Okay, I'll correct the description.
Quoted 13 lines
Quoted 4 lines
+ * This can help us achieve some performance improvement:
+ * 1) Thereadl_relaxed()is about 20ns faster thanreadl().
+ * 2) Thewritel_relaxed()is about 123ns faster thanwritel().These are not really the performance numbers I asked for, as a low-level benchmark comparing the instructions is rather meaningless. The time spent waiting for the barrier depends on what else is going on around the barrier. Also, most of the time would likely be spent spinning in the loop around
readl()while the cache operations are in progress, so the latency of a singlereadl()is not necessarily significant.
Quoted 5 lines
To have a more useful performance number, try mentioning the most performance sensitive non-coherent DMA master on one of the chips that has this cache controller, and a high-level performance number such as "1.2% more network packets per second" if that is something you can measure easily.
It's not easy. My board only have debugging NIC, only the downstream products have high-speed service NIC. Software needs to be packaged layer by layer.
Quoted 4 lines
Of course, if all high-speed DMA masters on this chip are cache coherent, there is no need for performance numbers, just mention that we don't care about speed in that case.
It's not cache coherent, otherwise, the L3 cache does not need to be operated.
Quoted 5 lines
Arnd
.
Quoted 13 lines · Leizhen (ThunderTown)
Quoted 6 lines · Arnd Bergmann
To have a more useful performance number, try mentioning the most performance sensitive non-coherent DMA master on one of the chips that has this cache controller, and a high-level performance number such as "1.2% more network packets per second" if that is something you can measure easily.
It's not easy. My board only have debugging NIC, only the downstream products have high-speed service NIC. Software needs to be packaged layer by layer.
Quoted 1 line
Quoted 6 lines
Quoted 3 lines
Of course, if all high-speed DMA masters on this chip are cache coherent, there is no need for performance numbers, just mention that we don't care about speed in that case.
It's not cache coherent, otherwise, the L3 cache does not need to be operated.
Ok, I see. In this case, just explain that the high-speed NIC is not cache-coherent, so this is expected to make a difference, even if you can't quantify it exactly.
Arnd
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel