Support Andes RISC-V l2cache on AE350 platform
Subsystems (2)
cover Support Andes RISC-V l2cache on AE350 platform
From: Rick Chen <[email protected]>
Add a v5l2 cache controller driver that is usually found on Andes RISC-V ae350 platform. It will parse and configure the cache settings (data & instruction prefetch, data & tag latency) from the device tree blob.
Also implement L2 cache flush and disable before jump to linux. The sequence will be preferred as below:
L1 flush -> L1 disable -> L2 flush -> L2 disable
Rick Chen (6):
dm: cache: add v5l2 cache controller driver
riscv: ae350: use the v5l2 driver to configure the cache
riscv: ae350: add imply v5l2 cache controller
riscv: cache: Flush L2 cache before jump to linux
riscv: dts: move out AE350 L2 node from cpus node
riscv: ax25: use CCTL to flush d-cache
arch/riscv/cpu/ax25/cache.c | 22 ++++--- arch/riscv/cpu/ax25/cpu.c | 4 ++ arch/riscv/dts/ae350_32.dts | 17 ++++-- arch/riscv/dts/ae350_64.dts | 17 ++++-- arch/riscv/include/asm/global_data.h | 3 + arch/riscv/include/asm/v5l2cache.h | 61 +++++++++++++++++++ board/AndesTech/ax25-ae350/Kconfig | 1 + board/AndesTech/ax25-ae350/ax25-ae350.c | 15 +++++ drivers/cache/Kconfig | 9 +++ drivers/cache/Makefile | 1 + drivers/cache/cache-v5l2.c | 102 ++++++++++++++++++++++++++++++++ 11 files changed, 231 insertions(+), 21 deletions(-) create mode 100644 arch/riscv/include/asm/v5l2cache.h create mode 100644 drivers/cache/cache-v5l2.c
Signature · 1 line
2.7.4
PATCH 1/6 dm: cache: add v5l2 cache controller driver
From: Rick Chen <[email protected]>
Add a v5l2 cache controller driver that is usually found on Andes RISC-V ae350 platform. It will parse the cache settings from the dtb.
In this version tag and data ram control timing can be adjusted by the requirement from the dtb.
--- arch/riscv/include/asm/global_data.h | 3 ++ arch/riscv/include/asm/v5l2cache.h | 61 +++++++++++++++++++++ drivers/cache/Kconfig | 9 ++++ drivers/cache/Makefile | 1 + drivers/cache/cache-v5l2.c | 102 +++++++++++++++++++++++++++++++++++ 5 files changed, 176 insertions(+) create mode 100644 arch/riscv/include/asm/v5l2cache.h create mode 100644 drivers/cache/cache-v5l2.c
arch/riscv/include/asm/global_data.h +3 -0
@@ -24,6 +24,9 @@ struct arch_global_data {#ifdef CONFIG_ANDES_PLMT void __iomem *plmt;/* plmt base address */ #endif +#ifdef CONFIG_V5L2_CACHE +void __iomem *v5l2;/* v5l2 base address */ +#endif #ifdef CONFIG_SMP struct ipi_data ipi[CONFIG_NR_CPUS ];#endif
arch/riscv/include/asm/v5l2cache.h new file +61 -0
61 lines not on this page · raw message
drivers/cache/Kconfig +9 -0
@@ -22,4 +22,13 @@ config L2X0_CACHE ARMv7(32-bit) devices. The driver configures the cache settings found in the device tree. +config V5L2_CACHE + tristate "Andes V5L2 cache driver" + select CACHE + depends on RISCV_NDS_CACHE + help + Support Andes V5L2 cache controller in AE350 platform. + It will configure tag and data ram timing control from the + device tree and enable L2 cache. + endmenu
drivers/cache/Makefile +1 -0
@@ -2,3 +2,4 @@ obj-$(CONFIG_CACHE) += cache-uclass.o obj-$(CONFIG_SANDBOX) += sandbox_cache.o obj-$(CONFIG_L2X0_CACHE) += cache-l2x0.o +obj-$(CONFIG_V5L2_CACHE) += cache-v5l2.o
drivers/cache/cache-v5l2.c new file +102 -0
102 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH 1/6 dm: cache: add v5l2 cache controller driver
Hi Rick,
Quoted 27 lines · Andes
From: Rick Chen <[email protected]>
Add a v5l2 cache controller driver that is usually found on Andes RISC-V ae350 platform. It will parse the cache settings from the dtb.
In this version tag and data ram control timing can be adjusted by the requirement from the dtb.
Signed-off-by Rick Chen <[email protected]>Cc Greentime Hu <[email protected]>--- arch/riscv/include/asm/global_data.h | 3 ++ arch/riscv/include/asm/v5l2cache.h | 61 +++++++++++++++++++++ drivers/cache/Kconfig | 9 ++++ drivers/cache/Makefile | 1 + drivers/cache/cache-v5l2.c | 102 +++++++++++++++++++++++++++++++++++ 5 files changed, 176 insertions(+) create mode 100644 arch/riscv/include/asm/v5l2cache.h create mode 100644 drivers/cache/cache-v5l2.carch/riscv/include/asm/global_data.h +0
-0
arch/riscv/include/asm/global_data.h struct arch_global_data { · line 29
Quoted 6 lines
arch/riscv/include/asm/global_data.h +3
-0@@ -24,6 +24,9 @@ struct arch_global_data {#ifdef CONFIG_ANDES_PLMT void __iomem *plmt;/* plmt base address */ #endif +#ifdef CONFIG_V5L2_CACHE +void __iomem *v5l2;/* v5l2 base address */ +#endif
Please do not expose this to global data if it is only used inside a driver. Anything that is here is for "global" usage.
arch/riscv/include/asm/v5l2cache.h
Quoted 8 lines
arch/riscv/include/asm/global_data.h +0
-0#ifdef CONFIG_SMP struct ipi_data ipi[CONFIG_NR_CPUS ];#endif arch/riscv/include/asm/v5l2cache.h new file +0
-0
Please create arch/riscv/include/asm/arch-ax25/v5l2cache.h. Speaking of the name, would it be more readable to name it as v5_l2cache.h? Or even add more information to v5, for me, I don't know what v5 stands for :)
arch/riscv/include/asm/v5l2cache.h line 11
Quoted 12 lines
arch/riscv/include/asm/v5l2cache.h new file +11
-0@@ -0,0 +1,61 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright (C) 2019 Andes Technology Corporation +* Rick Chen, Andes Technology Corporation <[email protected]> +*/ + +#ifndef _ASM_V5_L2CACHE_H +#define _ASM_V5_L2CACHE_H + +struct l2cache { + volatile u64 configure;
checkpatch.pl will report warnings against volatile usage. I think we should drop these.
Quoted 55 lines
arch/riscv/include/asm/v5l2cache.h new file +50
-0+volatile u64 control; +volatile u64 hpm0; +volatile u64 hpm1; +volatile u64 hpm2; +volatile u64 hpm3; +volatile u64 error_status; +volatile u64 ecc_error; +volatile u64 cctl_command0; +volatile u64 cctl_access_line0; +volatile u64 cctl_command1; +volatile u64 cctl_access_line1; +volatile u64 cctl_command2; +volatile u64 cctl_access_line2; +volatile u64 cctl_command3; +volatile u64 cctl_access_line4; + volatile u64 cctl_status; +}; + +/* Control Register */ +#define L2_ENABLE 0x1 +/* prefetch */ +#define IPREPETCH_OFF 3 +#define DPREPETCH_OFF 5 +#define IPREPETCH_MSK (3 << IPREPETCH_OFF) +#define DPREPETCH_MSK (3 << DPREPETCH_OFF) +/* tag ram */ +#define TRAMOCTL_OFF 8 +#define TRAMICTL_OFF 10 +#define TRAMOCTL_MSK (3 << TRAMOCTL_OFF) +#define TRAMICTL_MSK BIT(TRAMICTL_OFF) +/* data ram */ +#define DRAMOCTL_OFF 11 +#define DRAMICTL_OFF 13 +#define DRAMOCTL_MSK (3 << DRAMOCTL_OFF) +#define DRAMICTL_MSK BIT(DRAMICTL_OFF) + +/* CCTL Command Register */ +#define CCTL_CMD_REG (base, hart) ((ulong)(base) + 0x40 + (hart) * 0x10) +#define L2_WBINVAL_ALL 0x12 + +/* CCTL Status Register */ +#define CCTL_STATUS_MSK (hart) (0xf << ((hart) * 4)) +#define CCTL_STATUS_IDLE (hart) (0 << ((hart) * 4)) +#define CCTL_STATUS_PROCESS (hart) (1 << ((hart) * 4)) +#define CCTL_STATUS_ILLEGAL (hart) (2 << ((hart) * 4)) + +void v5l2_enable (void ); +void v5l2_disable (void ); + +#endif /* _ASM_V5_L2CACHE_H */ drivers/cache/Kconfig +0
-0
drivers/cache/Kconfig config L2X0_CACHE · line 26
Quoted 5 lines
drivers/cache/Kconfig +2
-0@@ -22,4 +22,13 @@ config L2X0_CACHE ARMv7(32-bit) devices. The driver configures the cache settings found in the device tree. +config V5L2_CACHE + tristate "Andes V5L2 cache driver"
This should be bool. U-Boot does not support "tristate"
Quoted 29 lines
drivers/cache/Kconfig +7
-0+ select CACHE + depends on RISCV_NDS_CACHE + help + Support Andes V5L2 cache controller in AE350 platform. + It will configure tag and data ram timing control from the + device tree and enable L2 cache. + endmenudrivers/cache/Makefile +1
-0@@ -2,3 +2,4 @@ obj-$(CONFIG_CACHE) += cache-uclass.o obj-$(CONFIG_SANDBOX) += sandbox_cache.o obj-$(CONFIG_L2X0_CACHE) += cache-l2x0.o +obj-$(CONFIG_V5L2_CACHE) += cache-v5l2.odrivers/cache/cache-v5l2.c new file +6
-0@@ -0,0 +1,102 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2019 Andes Technology Corporation +* Rick Chen, Andes Technology Corporation <[email protected]> +*/ +
drivers/cache/cache-v5l2.c line 16
Quoted 10 lines
drivers/cache/cache-v5l2.c new file +10
-0+#include <common.h> +#include <command.h> +#include <dm.h> +#include <asm/io.h> +#include <dm/ofnode.h> +#include <asm/v5l2cache.h> + +DECLARE_GLOBAL_DATA_PTR ; + +void v5l2_enable (void )
This should really be avoided. It looks current DM cache uclass driver is lacking of ops to do cache enable/disable. Please improve the DM cache uclass driver first.
Quoted 17 lines
drivers/cache/cache-v5l2.c new file +17
-0+{ +struct l2cache *regs = gd->arch.v5l2; + +if (regs) +setbits_le32 (®s->control,L2_ENABLE ); +} + +void v5l2_disable (void ) +{ +volatile struct l2cache *regs = gd->arch.v5l2; +u8 hart = gd->arch.boot_hart; +void __iomem *cctlcmd = (void __iomem *)CCTL_CMD_REG (gd->arch.v5l2, hart); + +if ((regs) && (readl (®s->control) &L2_ENABLE )) { +writel (L2_WBINVAL_ALL , cctlcmd); + +while ((readl (®s->cctl_status) &CCTL_STATUS_MSK (hart))) {
drivers/cache/cache-v5l2.c line 43
Quoted 10 lines
drivers/cache/cache-v5l2.c new file +10
-0+if ((readl (®s->cctl_status) &CCTL_STATUS_ILLEGAL (hart))) { +printf ("L2 flush illegal! hanging..." ); +hang (); + } + } +clrbits_le32 (®s->control,L2_ENABLE ); + } +} + +static void v5l2_of_parse_and_init (struct udevice *dev)
The entire function below should really be created as the driver's ofdata_to_platdata() function, inside which all DT properties are parsed and saved to driver's platdata. After that, there is no need to get register base from global data.
Quoted 39 lines
drivers/cache/cache-v5l2.c new file +39
-0+{ +struct l2cache *regs; +u32 ctl_val, prefetch; +u32 tram_ctl[2 ]; +u32 dram_ctl[2 ]; + + regs = (struct l2cache *)dev_read_addr (dev); + gd->arch.v5l2 = regs; + ctl_val =readl (®s->control); + +if (!(ctl_val &L2_ENABLE )) + ctl_val |=L2_ENABLE ; + +/* Instruction and data fetch prefetch depth */ +if (!dev_read_u32 (dev,"andes,inst-prefetch" , &prefetch)) { + ctl_val &= ~(IPREPETCH_MSK ); + ctl_val |= (prefetch <<IPREPETCH_OFF ); + } + +if (!dev_read_u32 (dev,"andes,data-prefetch" , &prefetch)) { + ctl_val &= ~(DPREPETCH_MSK ); + ctl_val |= (prefetch <<DPREPETCH_OFF ); + } + +/* Set tag RAM and data RAM setup and output cycle */ +if (!dev_read_u32_array (dev,"andes,tag-ram-ctl" , tram_ctl,2 )) { + ctl_val &= ~(TRAMOCTL_MSK |TRAMICTL_MSK ); + ctl_val |= tram_ctl[0 ] <<TRAMOCTL_OFF ; + ctl_val |= tram_ctl[1 ] <<TRAMICTL_OFF ; + } + +if (!dev_read_u32_array (dev,"andes,data-ram-ctl" , dram_ctl,2 )) { + ctl_val &= ~(DRAMOCTL_MSK |DRAMICTL_MSK ); + ctl_val |= dram_ctl[0 ] <<DRAMOCTL_OFF ; + ctl_val |= dram_ctl[1 ] <<DRAMICTL_OFF ; + } + +writel (ctl_val, ®s->control); +}
drivers/cache/cache-v5l2.c line 92
Quoted 10 lines
drivers/cache/cache-v5l2.c new file +10
-0+ +static int v5l2_probe (struct udevice *dev) +{ +v5l2_of_parse_and_init (dev); + +return 0 ; +} + +static const struct udevice_id v5l2_cache_ids[] = { + { .compatible ="cache" },
I suspect this compatible string is too generic. Has this been reviewed by DT community upstream?
drivers/cache/cache-v5l2.c
Quoted 11 lines
drivers/cache/cache-v5l2.c new file +10
-1+ {} +}; + +U_BOOT_DRIVER (v5l2_cache) = { + .name ="v5l2_cache" , + .id =UCLASS_CACHE , + .of_match = v5l2_cache_ids, + .probe = v5l2_probe, + .flags =DM_FLAG_PRE_RELOC , +}; --
Regards,
Bin
PATCH 1/6 dm: cache: add v5l2 cache controller driver
Hi Bin
Bin Meng <[email protected]> 於 2019年6月4日 週二 上午10:48寫道:
Quoted 26 lines
Hi Rick,
Quoted 22 lines · Andes
From: Rick Chen <[email protected]>
Add a v5l2 cache controller driver that is usually found on Andes RISC-V ae350 platform. It will parse the cache settings from the dtb.
In this version tag and data ram control timing can be adjusted by the requirement from the dtb.
Signed-off-by Rick Chen <[email protected]>Cc Greentime Hu <[email protected]>--- arch/riscv/include/asm/global_data.h | 3 ++ arch/riscv/include/asm/v5l2cache.h | 61 +++++++++++++++++++++ drivers/cache/Kconfig | 9 ++++ drivers/cache/Makefile | 1 + drivers/cache/cache-v5l2.c | 102 +++++++++++++++++++++++++++++++++++ 5 files changed, 176 insertions(+) create mode 100644 arch/riscv/include/asm/v5l2cache.h create mode 100644 drivers/cache/cache-v5l2.c
Quoted 14 lines
arch/riscv/include/asm/global_data.h struct arch_global_data { · line 29
Quoted 11 lines
arch/riscv/include/asm/global_data.h +3
-0@@ -24,6 +24,9 @@ struct arch_global_data {#ifdef CONFIG_ANDES_PLMT void __iomem *plmt;/* plmt base address */ #endif +#ifdef CONFIG_V5L2_CACHE +void __iomem *v5l2;/* v5l2 base address */ +#endif Please do not expose this to global data if it is only used inside a driver. Anything that is here is for "global" usage.
OK.
I will remove it.
Quoted 14 lines
arch/riscv/include/asm/v5l2cache.h
Quoted 9 lines
arch/riscv/include/asm/global_data.h +0
-0#ifdef CONFIG_SMP struct ipi_data ipi[CONFIG_NR_CPUS ];#endif arch/riscv/include/asm/v5l2cache.h new file +0
-0Please create
arch/riscv/include/asm/arch-ax25/v5l2cache.h. Speaking of the name, would it be more readable to name it asv5_l2cache.h? Or even add more information to v5, for me, I don't know what v5 stands for :)
OK
I will create arch/riscv/include/asm/arch-ax25/v5_l2cache.h
Quoted 16 lines
arch/riscv/include/asm/v5l2cache.h line 11
Quoted 13 lines
arch/riscv/include/asm/v5l2cache.h new file +11
-0@@ -0,0 +1,61 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright (C) 2019 Andes Technology Corporation +* Rick Chen, Andes Technology Corporation <[email protected]> +*/ + +#ifndef _ASM_V5_L2CACHE_H +#define _ASM_V5_L2CACHE_H + +struct l2cache { + volatile u64 configure;checkpatch.pl will report warnings against volatile usage. I think we should drop these.
I know that checkpatch.pl will report this warning.
But I still need to add volatile. It help to fix some unpredictable problem. Without this some driver code flows will be optimized and go wrong somehow.
Quoted 59 lines
Quoted 59 lines
arch/riscv/include/asm/v5l2cache.h new file +50
-0+volatile u64 control; +volatile u64 hpm0; +volatile u64 hpm1; +volatile u64 hpm2; +volatile u64 hpm3; +volatile u64 error_status; +volatile u64 ecc_error; +volatile u64 cctl_command0; +volatile u64 cctl_access_line0; +volatile u64 cctl_command1; +volatile u64 cctl_access_line1; +volatile u64 cctl_command2; +volatile u64 cctl_access_line2; +volatile u64 cctl_command3; +volatile u64 cctl_access_line4; + volatile u64 cctl_status; +}; + +/* Control Register */ +#define L2_ENABLE 0x1 +/* prefetch */ +#define IPREPETCH_OFF 3 +#define DPREPETCH_OFF 5 +#define IPREPETCH_MSK (3 << IPREPETCH_OFF) +#define DPREPETCH_MSK (3 << DPREPETCH_OFF) +/* tag ram */ +#define TRAMOCTL_OFF 8 +#define TRAMICTL_OFF 10 +#define TRAMOCTL_MSK (3 << TRAMOCTL_OFF) +#define TRAMICTL_MSK BIT(TRAMICTL_OFF) +/* data ram */ +#define DRAMOCTL_OFF 11 +#define DRAMICTL_OFF 13 +#define DRAMOCTL_MSK (3 << DRAMOCTL_OFF) +#define DRAMICTL_MSK BIT(DRAMICTL_OFF) + +/* CCTL Command Register */ +#define CCTL_CMD_REG (base, hart) ((ulong)(base) + 0x40 + (hart) * 0x10) +#define L2_WBINVAL_ALL 0x12 + +/* CCTL Status Register */ +#define CCTL_STATUS_MSK (hart) (0xf << ((hart) * 4)) +#define CCTL_STATUS_IDLE (hart) (0 << ((hart) * 4)) +#define CCTL_STATUS_PROCESS (hart) (1 << ((hart) * 4)) +#define CCTL_STATUS_ILLEGAL (hart) (2 << ((hart) * 4)) + +void v5l2_enable (void ); +void v5l2_disable (void ); + +#endif /* _ASM_V5_L2CACHE_H */ drivers/cache/Kconfig +0
-0@@ -22,4 +22,13 @@ config L2X0_CACHE ARMv7(32-bit) devices. The driver configures the cache settings found in the device tree.
Quoted 4 lines
drivers/cache/Kconfig config L2X0_CACHE · line 26
Quoted 2 lines
drivers/cache/Kconfig +2
-0+config V5L2_CACHE + tristate "Andes V5L2 cache driver"This should be bool. U-Boot does not support "tristate"
I will modify it as bool.
Quoted 36 lines
Quoted 36 lines
drivers/cache/Kconfig +7
-0+ select CACHE + depends on RISCV_NDS_CACHE + help + Support Andes V5L2 cache controller in AE350 platform. + It will configure tag and data ram timing control from the + device tree and enable L2 cache. + endmenudrivers/cache/Makefile +1
-0@@ -2,3 +2,4 @@ obj-$(CONFIG_CACHE) += cache-uclass.o obj-$(CONFIG_SANDBOX) += sandbox_cache.o obj-$(CONFIG_L2X0_CACHE) += cache-l2x0.o +obj-$(CONFIG_V5L2_CACHE) += cache-v5l2.odrivers/cache/cache-v5l2.c new file +12
-0@@ -0,0 +1,102 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2019 Andes Technology Corporation +* Rick Chen, Andes Technology Corporation <[email protected]> +*/ + +#include <common.h> +#include <command.h> +#include <dm.h> +#include <asm/io.h> +#include <dm/ofnode.h> +#include <asm/v5l2cache.h>
Quoted 8 lines
drivers/cache/cache-v5l2.c line 16
Quoted 4 lines
drivers/cache/cache-v5l2.c new file +4
-0+ +DECLARE_GLOBAL_DATA_PTR ; + +void v5l2_enable (void )This should really be avoided. It looks current DM cache uclass driver is lacking of ops to do cache enable/disable. Please improve the DM cache uclass driver first.
OK
I will improve the DM cache uclass driver.
Quoted 25 lines
Quoted 25 lines
drivers/cache/cache-v5l2.c new file +24
-0+{ +struct l2cache *regs = gd->arch.v5l2; + +if (regs) +setbits_le32 (®s->control,L2_ENABLE ); +} + +void v5l2_disable (void ) +{ +volatile struct l2cache *regs = gd->arch.v5l2; +u8 hart = gd->arch.boot_hart; +void __iomem *cctlcmd = (void __iomem *)CCTL_CMD_REG (gd->arch.v5l2, hart); + +if ((regs) && (readl (®s->control) &L2_ENABLE )) { +writel (L2_WBINVAL_ALL , cctlcmd); + +while ((readl (®s->cctl_status) &CCTL_STATUS_MSK (hart))) { +if ((readl (®s->cctl_status) &CCTL_STATUS_ILLEGAL (hart))) { +printf ("L2 flush illegal! hanging..." ); +hang (); + } + } +clrbits_le32 (®s->control,L2_ENABLE ); + }
Quoted 8 lines
drivers/cache/cache-v5l2.c line 43
Quoted 3 lines
drivers/cache/cache-v5l2.c new file +3
-0+} + +static void v5l2_of_parse_and_init (struct udevice *dev)The entire function below should really be created as the driver's
ofdata_to_platdata()function, inside which all DT properties are parsed and saved to driver's platdata. After that, there is no need to get register base from global data.
I will use ofdata_to_platdata() to parse dtb information and save it into platdata instead of saving in global data.
Quoted 45 lines
Quoted 45 lines
drivers/cache/cache-v5l2.c new file +44
-0+{ +struct l2cache *regs; +u32 ctl_val, prefetch; +u32 tram_ctl[2 ]; +u32 dram_ctl[2 ]; + + regs = (struct l2cache *)dev_read_addr (dev); + gd->arch.v5l2 = regs; + ctl_val =readl (®s->control); + +if (!(ctl_val &L2_ENABLE )) + ctl_val |=L2_ENABLE ; + +/* Instruction and data fetch prefetch depth */ +if (!dev_read_u32 (dev,"andes,inst-prefetch" , &prefetch)) { + ctl_val &= ~(IPREPETCH_MSK ); + ctl_val |= (prefetch <<IPREPETCH_OFF ); + } + +if (!dev_read_u32 (dev,"andes,data-prefetch" , &prefetch)) { + ctl_val &= ~(DPREPETCH_MSK ); + ctl_val |= (prefetch <<DPREPETCH_OFF ); + } + +/* Set tag RAM and data RAM setup and output cycle */ +if (!dev_read_u32_array (dev,"andes,tag-ram-ctl" , tram_ctl,2 )) { + ctl_val &= ~(TRAMOCTL_MSK |TRAMICTL_MSK ); + ctl_val |= tram_ctl[0 ] <<TRAMOCTL_OFF ; + ctl_val |= tram_ctl[1 ] <<TRAMICTL_OFF ; + } + +if (!dev_read_u32_array (dev,"andes,data-ram-ctl" , dram_ctl,2 )) { + ctl_val &= ~(DRAMOCTL_MSK |DRAMICTL_MSK ); + ctl_val |= dram_ctl[0 ] <<DRAMOCTL_OFF ; + ctl_val |= dram_ctl[1 ] <<DRAMICTL_OFF ; + } + +writel (ctl_val, ®s->control); +} + +static int v5l2_probe (struct udevice *dev) +{ +v5l2_of_parse_and_init (dev); +
Quoted 9 lines
drivers/cache/cache-v5l2.c line 92
Quoted 5 lines
drivers/cache/cache-v5l2.c new file +5
-0+return 0 ; +} + +static const struct udevice_id v5l2_cache_ids[] = { + { .compatible ="cache" },I suspect this compatible string is too generic. Has this been reviewed by DT community upstream?
It refer to many dts examples from arm,
For example :arch/arm/dts/fsl-imx8-ca35.dtsi
A35_L2: l2-cache0 {
compatible = "cache";
};Thanks
Rick
Quoted 14 lines
drivers/cache/cache-v5l2.c
Quoted 11 lines
drivers/cache/cache-v5l2.c new file +10
-1+ {} +}; + +U_BOOT_DRIVER (v5l2_cache) = { + .name ="v5l2_cache" , + .id =UCLASS_CACHE , + .of_match = v5l2_cache_ids, + .probe = v5l2_probe, + .flags =DM_FLAG_PRE_RELOC , +}; --Regards,
Bin
Auer
PATCH 1/6 dm: cache: add v5l2 cache controller driver
Hi Rick,
Quoted 284 lines · Rick Chen
Hi Bin
Bin Meng <[email protected]> 於 2019年6月4日 週二 上午10:48寫道:
Quoted 24 lines
Hi Rick,
Quoted 21 lines · Andes
From: Rick Chen <[email protected]>
Add a v5l2 cache controller driver that is usually found on Andes RISC-V ae350 platform. It will parse the cache settings from the dtb.
In this version tag and data ram control timing can be adjusted by the requirement from the dtb.
Signed-off-by Rick Chen <[email protected]>Cc Greentime Hu <[email protected]>--- arch/riscv/include/asm/global_data.h | 3 ++ arch/riscv/include/asm/v5l2cache.h | 61 +++++++++++++++++++++ drivers/cache/Kconfig | 9 ++++ drivers/cache/Makefile | 1 + drivers/cache/cache-v5l2.c | 102 +++++++++++++++++++++++++++++++++++ 5 files changed, 176 insertions(+) create mode 100644 arch/riscv/include/asm/v5l2cache.h create mode 100644 drivers/cache/cache-v5l2.cQuoted 14 lines
arch/riscv/include/asm/global_data.h struct arch_global_data { · line 29
Quoted 11 lines
arch/riscv/include/asm/global_data.h +3
-0@@ -24,6 +24,9 @@ struct arch_global_data {#ifdef CONFIG_ANDES_PLMT void __iomem *plmt;/* plmt base address */ #endif +#ifdef CONFIG_V5L2_CACHE +void __iomem *v5l2;/* v5l2 base address */ +#endif Please do not expose this to global data if it is only used inside a driver. Anything that is here is for "global" usage.
OK.
I will remove it.Quoted 5 lines
Quoted 5 lines
arch/riscv/include/asm/global_data.h +0
-0#ifdef CONFIG_SMP struct ipi_data ipi[CONFIG_NR_CPUS ];#endif arch/riscv/include/asm/v5l2cache.h new file +0
-0Quoted 8 lines
arch/riscv/include/asm/v5l2cache.h
Quoted 3 lines
index 0000000..8ed1c6c
arch/riscv/include/asm/v5l2cache.h new file +0
-0Please create
arch/riscv/include/asm/arch-ax25/v5l2cache.h. Speaking of the name, would it be more readable to name it asv5_l2cache.h? Or even add more information to v5, for me, I don't know what v5 stands for :)OK
I will createarch/riscv/include/asm/arch-ax25/v5_l2cache.hQuoted 7 lines
Quoted 7 lines
arch/riscv/include/asm/v5l2cache.h new file +6
-0@@ -0,0 +1,61 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright (C) 2019 Andes Technology Corporation +* Rick Chen, Andes Technology Corporation <[email protected]> +*/ +Quoted 8 lines
arch/riscv/include/asm/v5l2cache.h line 11
Quoted 5 lines
arch/riscv/include/asm/v5l2cache.h new file +5
-0+#ifndef _ASM_V5_L2CACHE_H +#define _ASM_V5_L2CACHE_H + +struct l2cache { + volatile u64 configure;checkpatch.pl will report warnings against volatile usage. I think we should drop these.
I know that checkpatch.pl will report this warning.
But I still need to add volatile. It help to fix some unpredictable problem. Without this some driver code flows will be optimized and go wrong somehow.Quoted 58 lines
Quoted 58 lines
arch/riscv/include/asm/v5l2cache.h new file +50
-0+volatile u64 control; +volatile u64 hpm0; +volatile u64 hpm1; +volatile u64 hpm2; +volatile u64 hpm3; +volatile u64 error_status; +volatile u64 ecc_error; +volatile u64 cctl_command0; +volatile u64 cctl_access_line0; +volatile u64 cctl_command1; +volatile u64 cctl_access_line1; +volatile u64 cctl_command2; +volatile u64 cctl_access_line2; +volatile u64 cctl_command3; +volatile u64 cctl_access_line4; + volatile u64 cctl_status; +}; + +/* Control Register */ +#define L2_ENABLE 0x1 +/* prefetch */ +#define IPREPETCH_OFF 3 +#define DPREPETCH_OFF 5 +#define IPREPETCH_MSK (3 << IPREPETCH_OFF) +#define DPREPETCH_MSK (3 << DPREPETCH_OFF) +/* tag ram */ +#define TRAMOCTL_OFF 8 +#define TRAMICTL_OFF 10 +#define TRAMOCTL_MSK (3 << TRAMOCTL_OFF) +#define TRAMICTL_MSK BIT(TRAMICTL_OFF) +/* data ram */ +#define DRAMOCTL_OFF 11 +#define DRAMICTL_OFF 13 +#define DRAMOCTL_MSK (3 << DRAMOCTL_OFF) +#define DRAMICTL_MSK BIT(DRAMICTL_OFF) + +/* CCTL Command Register */ +#define CCTL_CMD_REG (base, hart) ((ulong)(base) + 0x40 + (hart) * 0x10) +#define L2_WBINVAL_ALL 0x12 + +/* CCTL Status Register */ +#define CCTL_STATUS_MSK (hart) (0xf << ((hart) * 4)) +#define CCTL_STATUS_IDLE (hart) (0 << ((hart) * 4)) +#define CCTL_STATUS_PROCESS (hart) (1 << ((hart) * 4)) +#define CCTL_STATUS_ILLEGAL (hart) (2 << ((hart) * 4)) + +void v5l2_enable (void ); +void v5l2_disable (void ); + +#endif /* _ASM_V5_L2CACHE_H */ drivers/cache/Kconfig +0
-0@@ -22,4 +22,13 @@ config L2X0_CACHE ARMv7(32-bit) devices. The driver configures the cache settings found in the device tree.Quoted 4 lines
drivers/cache/Kconfig config L2X0_CACHE · line 26
Quoted 2 lines
drivers/cache/Kconfig +2
-0+config V5L2_CACHE + tristate "Andes V5L2 cache driver"This should be bool. U-Boot does not support "tristate"
I will modify it as bool.
Quoted 35 lines
Quoted 35 lines
drivers/cache/Kconfig +7
-0+ select CACHE + depends on RISCV_NDS_CACHE + help + Support Andes V5L2 cache controller in AE350 platform. + It will configure tag and data ram timing control from the + device tree and enable L2 cache. + endmenudrivers/cache/Makefile +1
-0@@ -2,3 +2,4 @@ obj-$(CONFIG_CACHE) += cache-uclass.o obj-$(CONFIG_SANDBOX) += sandbox_cache.o obj-$(CONFIG_L2X0_CACHE) += cache-l2x0.o +obj-$(CONFIG_V5L2_CACHE) += cache-v5l2.odrivers/cache/cache-v5l2.c new file +12
-0@@ -0,0 +1,102 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2019 Andes Technology Corporation +* Rick Chen, Andes Technology Corporation <[email protected]> +*/ + +#include <common.h> +#include <command.h> +#include <dm.h> +#include <asm/io.h> +#include <dm/ofnode.h> +#include <asm/v5l2cache.h> Quoted 8 lines
drivers/cache/cache-v5l2.c line 16
Quoted 4 lines
drivers/cache/cache-v5l2.c new file +4
-0+ +DECLARE_GLOBAL_DATA_PTR ; + +void v5l2_enable (void )This should really be avoided. It looks current DM cache uclass driver is lacking of ops to do cache enable/disable. Please improve the DM cache uclass driver first.
OK
I will improve the DM cache uclass driver.Quoted 24 lines
Quoted 24 lines
drivers/cache/cache-v5l2.c new file +24
-0+{ +struct l2cache *regs = gd->arch.v5l2; + +if (regs) +setbits_le32 (®s->control,L2_ENABLE ); +} + +void v5l2_disable (void ) +{ +volatile struct l2cache *regs = gd->arch.v5l2; +u8 hart = gd->arch.boot_hart; +void __iomem *cctlcmd = (void __iomem *)CCTL_CMD_REG (gd->arch.v5l2, hart); + +if ((regs) && (readl (®s->control) &L2_ENABLE )) { +writel (L2_WBINVAL_ALL , cctlcmd); + +while ((readl (®s->cctl_status) &CCTL_STATUS_MSK (hart))) { +if ((readl (®s->cctl_status) &CCTL_STATUS_ILLEGAL (hart))) { +printf ("L2 flush illegal! hanging..." ); +hang (); + } + } +clrbits_le32 (®s->control,L2_ENABLE ); + }Quoted 8 lines
drivers/cache/cache-v5l2.c line 43
Quoted 3 lines
drivers/cache/cache-v5l2.c new file +3
-0+} + +static void v5l2_of_parse_and_init (struct udevice *dev)The entire function below should really be created as the driver's
ofdata_to_platdata()function, inside which all DT properties are parsed and saved to driver's platdata. After that, there is no need to get register base from global data.I will use
ofdata_to_platdata()to parse dtb information and save it into platdata instead of saving in global data.Quoted 44 lines
Quoted 44 lines
drivers/cache/cache-v5l2.c new file +44
-0+{ +struct l2cache *regs; +u32 ctl_val, prefetch; +u32 tram_ctl[2 ]; +u32 dram_ctl[2 ]; + + regs = (struct l2cache *)dev_read_addr (dev); + gd->arch.v5l2 = regs; + ctl_val =readl (®s->control); + +if (!(ctl_val &L2_ENABLE )) + ctl_val |=L2_ENABLE ; + +/* Instruction and data fetch prefetch depth */ +if (!dev_read_u32 (dev,"andes,inst-prefetch" , &prefetch)) { + ctl_val &= ~(IPREPETCH_MSK ); + ctl_val |= (prefetch <<IPREPETCH_OFF ); + } + +if (!dev_read_u32 (dev,"andes,data-prefetch" , &prefetch)) { + ctl_val &= ~(DPREPETCH_MSK ); + ctl_val |= (prefetch <<DPREPETCH_OFF ); + } + +/* Set tag RAM and data RAM setup and output cycle */ +if (!dev_read_u32_array (dev,"andes,tag-ram-ctl" , tram_ctl,2 )) { + ctl_val &= ~(TRAMOCTL_MSK |TRAMICTL_MSK ); + ctl_val |= tram_ctl[0 ] <<TRAMOCTL_OFF ; + ctl_val |= tram_ctl[1 ] <<TRAMICTL_OFF ; + } + +if (!dev_read_u32_array (dev,"andes,data-ram-ctl" , dram_ctl,2 )) { + ctl_val &= ~(DRAMOCTL_MSK |DRAMICTL_MSK ); + ctl_val |= dram_ctl[0 ] <<DRAMOCTL_OFF ; + ctl_val |= dram_ctl[1 ] <<DRAMICTL_OFF ; + } + +writel (ctl_val, ®s->control); +} + +static int v5l2_probe (struct udevice *dev) +{ +v5l2_of_parse_and_init (dev); +Quoted 9 lines
drivers/cache/cache-v5l2.c line 92
Quoted 5 lines
drivers/cache/cache-v5l2.c new file +5
-0+return 0 ; +} + +static const struct udevice_id v5l2_cache_ids[] = { + { .compatible ="cache" },I suspect this compatible string is too generic. Has this been reviewed by DT community upstream?
Quoted 7 lines
It refer to many dts examples from arm,
For example :arch/arm/dts/fsl-imx8-ca35.dtsiA35_L2: l2-cache0 { compatible = "cache"; };
None of these have a driver for the cache controller, which is why it is sufficient to just use a generic compatible string.
I agree with Bin that you should choose a more specific compatible string. This is likely to cause problems in the future otherwise. For example, if Andes develops a new L2 cache controller, it must be differentiated from this one using the compatible string. The new controller would therefore have to use a different compatible string. It is good practice to already use a more specific one now to avoid the headache later. :)
Thanks,
Lukas
PATCH 1/6 dm: cache: add v5l2 cache controller driver
Hi Lukas
Quoted 299 lines
Hi Rick,
Quoted 284 lines · Rick Chen
Hi Bin
Bin Meng <[email protected]> 於 2019年6月4日 週二 上午10:48寫道:
Quoted 24 lines
Hi Rick,
Quoted 21 lines · Andes
From: Rick Chen <[email protected]>
Add a v5l2 cache controller driver that is usually found on Andes RISC-V ae350 platform. It will parse the cache settings from the dtb.
In this version tag and data ram control timing can be adjusted by the requirement from the dtb.
Signed-off-by Rick Chen <[email protected]>Cc Greentime Hu <[email protected]>--- arch/riscv/include/asm/global_data.h | 3 ++ arch/riscv/include/asm/v5l2cache.h | 61 +++++++++++++++++++++ drivers/cache/Kconfig | 9 ++++ drivers/cache/Makefile | 1 + drivers/cache/cache-v5l2.c | 102 +++++++++++++++++++++++++++++++++++ 5 files changed, 176 insertions(+) create mode 100644 arch/riscv/include/asm/v5l2cache.h create mode 100644 drivers/cache/cache-v5l2.cQuoted 14 lines
arch/riscv/include/asm/global_data.h struct arch_global_data { · line 29
Quoted 11 lines
arch/riscv/include/asm/global_data.h +3
-0@@ -24,6 +24,9 @@ struct arch_global_data {#ifdef CONFIG_ANDES_PLMT void __iomem *plmt;/* plmt base address */ #endif +#ifdef CONFIG_V5L2_CACHE +void __iomem *v5l2;/* v5l2 base address */ +#endif Please do not expose this to global data if it is only used inside a driver. Anything that is here is for "global" usage.
OK.
I will remove it.Quoted 5 lines
Quoted 5 lines
arch/riscv/include/asm/global_data.h +0
-0#ifdef CONFIG_SMP struct ipi_data ipi[CONFIG_NR_CPUS ];#endif arch/riscv/include/asm/v5l2cache.h new file +0
-0Quoted 8 lines
arch/riscv/include/asm/v5l2cache.h
Quoted 3 lines
index 0000000..8ed1c6c
arch/riscv/include/asm/v5l2cache.h new file +0
-0Please create
arch/riscv/include/asm/arch-ax25/v5l2cache.h. Speaking of the name, would it be more readable to name it asv5_l2cache.h? Or even add more information to v5, for me, I don't know what v5 stands for :)OK
I will createarch/riscv/include/asm/arch-ax25/v5_l2cache.hQuoted 7 lines
Quoted 7 lines
arch/riscv/include/asm/v5l2cache.h new file +6
-0@@ -0,0 +1,61 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright (C) 2019 Andes Technology Corporation +* Rick Chen, Andes Technology Corporation <[email protected]> +*/ +Quoted 8 lines
arch/riscv/include/asm/v5l2cache.h line 11
Quoted 5 lines
arch/riscv/include/asm/v5l2cache.h new file +5
-0+#ifndef _ASM_V5_L2CACHE_H +#define _ASM_V5_L2CACHE_H + +struct l2cache { + volatile u64 configure;checkpatch.pl will report warnings against volatile usage. I think we should drop these.
I know that checkpatch.pl will report this warning.
But I still need to add volatile. It help to fix some unpredictable problem. Without this some driver code flows will be optimized and go wrong somehow.Quoted 58 lines
Quoted 58 lines
arch/riscv/include/asm/v5l2cache.h new file +50
-0+volatile u64 control; +volatile u64 hpm0; +volatile u64 hpm1; +volatile u64 hpm2; +volatile u64 hpm3; +volatile u64 error_status; +volatile u64 ecc_error; +volatile u64 cctl_command0; +volatile u64 cctl_access_line0; +volatile u64 cctl_command1; +volatile u64 cctl_access_line1; +volatile u64 cctl_command2; +volatile u64 cctl_access_line2; +volatile u64 cctl_command3; +volatile u64 cctl_access_line4; + volatile u64 cctl_status; +}; + +/* Control Register */ +#define L2_ENABLE 0x1 +/* prefetch */ +#define IPREPETCH_OFF 3 +#define DPREPETCH_OFF 5 +#define IPREPETCH_MSK (3 << IPREPETCH_OFF) +#define DPREPETCH_MSK (3 << DPREPETCH_OFF) +/* tag ram */ +#define TRAMOCTL_OFF 8 +#define TRAMICTL_OFF 10 +#define TRAMOCTL_MSK (3 << TRAMOCTL_OFF) +#define TRAMICTL_MSK BIT(TRAMICTL_OFF) +/* data ram */ +#define DRAMOCTL_OFF 11 +#define DRAMICTL_OFF 13 +#define DRAMOCTL_MSK (3 << DRAMOCTL_OFF) +#define DRAMICTL_MSK BIT(DRAMICTL_OFF) + +/* CCTL Command Register */ +#define CCTL_CMD_REG (base, hart) ((ulong)(base) + 0x40 + (hart) * 0x10) +#define L2_WBINVAL_ALL 0x12 + +/* CCTL Status Register */ +#define CCTL_STATUS_MSK (hart) (0xf << ((hart) * 4)) +#define CCTL_STATUS_IDLE (hart) (0 << ((hart) * 4)) +#define CCTL_STATUS_PROCESS (hart) (1 << ((hart) * 4)) +#define CCTL_STATUS_ILLEGAL (hart) (2 << ((hart) * 4)) + +void v5l2_enable (void ); +void v5l2_disable (void ); + +#endif /* _ASM_V5_L2CACHE_H */ drivers/cache/Kconfig +0
-0@@ -22,4 +22,13 @@ config L2X0_CACHE ARMv7(32-bit) devices. The driver configures the cache settings found in the device tree.Quoted 4 lines
drivers/cache/Kconfig config L2X0_CACHE · line 26
Quoted 2 lines
drivers/cache/Kconfig +2
-0+config V5L2_CACHE + tristate "Andes V5L2 cache driver"This should be bool. U-Boot does not support "tristate"
I will modify it as bool.
Quoted 35 lines
Quoted 35 lines
drivers/cache/Kconfig +7
-0+ select CACHE + depends on RISCV_NDS_CACHE + help + Support Andes V5L2 cache controller in AE350 platform. + It will configure tag and data ram timing control from the + device tree and enable L2 cache. + endmenudrivers/cache/Makefile +1
-0@@ -2,3 +2,4 @@ obj-$(CONFIG_CACHE) += cache-uclass.o obj-$(CONFIG_SANDBOX) += sandbox_cache.o obj-$(CONFIG_L2X0_CACHE) += cache-l2x0.o +obj-$(CONFIG_V5L2_CACHE) += cache-v5l2.odrivers/cache/cache-v5l2.c new file +12
-0@@ -0,0 +1,102 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2019 Andes Technology Corporation +* Rick Chen, Andes Technology Corporation <[email protected]> +*/ + +#include <common.h> +#include <command.h> +#include <dm.h> +#include <asm/io.h> +#include <dm/ofnode.h> +#include <asm/v5l2cache.h> Quoted 8 lines
drivers/cache/cache-v5l2.c line 16
Quoted 4 lines
drivers/cache/cache-v5l2.c new file +4
-0+ +DECLARE_GLOBAL_DATA_PTR ; + +void v5l2_enable (void )This should really be avoided. It looks current DM cache uclass driver is lacking of ops to do cache enable/disable. Please improve the DM cache uclass driver first.
OK
I will improve the DM cache uclass driver.Quoted 24 lines
Quoted 24 lines
drivers/cache/cache-v5l2.c new file +24
-0+{ +struct l2cache *regs = gd->arch.v5l2; + +if (regs) +setbits_le32 (®s->control,L2_ENABLE ); +} + +void v5l2_disable (void ) +{ +volatile struct l2cache *regs = gd->arch.v5l2; +u8 hart = gd->arch.boot_hart; +void __iomem *cctlcmd = (void __iomem *)CCTL_CMD_REG (gd->arch.v5l2, hart); + +if ((regs) && (readl (®s->control) &L2_ENABLE )) { +writel (L2_WBINVAL_ALL , cctlcmd); + +while ((readl (®s->cctl_status) &CCTL_STATUS_MSK (hart))) { +if ((readl (®s->cctl_status) &CCTL_STATUS_ILLEGAL (hart))) { +printf ("L2 flush illegal! hanging..." ); +hang (); + } + } +clrbits_le32 (®s->control,L2_ENABLE ); + }Quoted 8 lines
drivers/cache/cache-v5l2.c line 43
Quoted 3 lines
drivers/cache/cache-v5l2.c new file +3
-0+} + +static void v5l2_of_parse_and_init (struct udevice *dev)The entire function below should really be created as the driver's
ofdata_to_platdata()function, inside which all DT properties are parsed and saved to driver's platdata. After that, there is no need to get register base from global data.I will use
ofdata_to_platdata()to parse dtb information and save it into platdata instead of saving in global data.Quoted 44 lines
Quoted 44 lines
drivers/cache/cache-v5l2.c new file +44
-0+{ +struct l2cache *regs; +u32 ctl_val, prefetch; +u32 tram_ctl[2 ]; +u32 dram_ctl[2 ]; + + regs = (struct l2cache *)dev_read_addr (dev); + gd->arch.v5l2 = regs; + ctl_val =readl (®s->control); + +if (!(ctl_val &L2_ENABLE )) + ctl_val |=L2_ENABLE ; + +/* Instruction and data fetch prefetch depth */ +if (!dev_read_u32 (dev,"andes,inst-prefetch" , &prefetch)) { + ctl_val &= ~(IPREPETCH_MSK ); + ctl_val |= (prefetch <<IPREPETCH_OFF ); + } + +if (!dev_read_u32 (dev,"andes,data-prefetch" , &prefetch)) { + ctl_val &= ~(DPREPETCH_MSK ); + ctl_val |= (prefetch <<DPREPETCH_OFF ); + } + +/* Set tag RAM and data RAM setup and output cycle */ +if (!dev_read_u32_array (dev,"andes,tag-ram-ctl" , tram_ctl,2 )) { + ctl_val &= ~(TRAMOCTL_MSK |TRAMICTL_MSK ); + ctl_val |= tram_ctl[0 ] <<TRAMOCTL_OFF ; + ctl_val |= tram_ctl[1 ] <<TRAMICTL_OFF ; + } + +if (!dev_read_u32_array (dev,"andes,data-ram-ctl" , dram_ctl,2 )) { + ctl_val &= ~(DRAMOCTL_MSK |DRAMICTL_MSK ); + ctl_val |= dram_ctl[0 ] <<DRAMOCTL_OFF ; + ctl_val |= dram_ctl[1 ] <<DRAMICTL_OFF ; + } + +writel (ctl_val, ®s->control); +} + +static int v5l2_probe (struct udevice *dev) +{ +v5l2_of_parse_and_init (dev); +Quoted 9 lines
drivers/cache/cache-v5l2.c line 92
Quoted 5 lines
drivers/cache/cache-v5l2.c new file +5
-0+return 0 ; +} + +static const struct udevice_id v5l2_cache_ids[] = { + { .compatible ="cache" },I suspect this compatible string is too generic. Has this been reviewed by DT community upstream?
Quoted 7 lines
It refer to many dts examples from arm,
For example :arch/arm/dts/fsl-imx8-ca35.dtsiA35_L2: l2-cache0 { compatible = "cache"; };None of these have a driver for the cache controller, which is why it is sufficient to just use a generic compatible string.
Quoted 7 lines
I agree with Bin that you should choose a more specific compatible string. This is likely to cause problems in the future otherwise. For example, if Andes develops a new L2 cache controller, it must be differentiated from this one using the compatible string. The new controller would therefore have to use a different compatible string. It is good practice to already use a more specific one now to avoid the headache later. :)
You are right.
I will modify it as compatible = "v5l2cache"
Thanks
Rick
Quoted 3 lines
Thanks,
Lukas
PATCH 1/6 dm: cache: add v5l2 cache controller driver
Hi Rick,
Quoted 310 lines · Rick Chen
Hi Lukas
Quoted 299 lines
Hi Rick,
Quoted 284 lines · Rick Chen
Hi Bin
Bin Meng <[email protected]> 於 2019年6月4日 週二 上午10:48寫道:
Quoted 24 lines
Hi Rick,
Quoted 21 lines · Andes
From: Rick Chen <[email protected]>
Add a v5l2 cache controller driver that is usually found on Andes RISC-V ae350 platform. It will parse the cache settings from the dtb.
In this version tag and data ram control timing can be adjusted by the requirement from the dtb.
Signed-off-by Rick Chen <[email protected]>Cc Greentime Hu <[email protected]>--- arch/riscv/include/asm/global_data.h | 3 ++ arch/riscv/include/asm/v5l2cache.h | 61 +++++++++++++++++++++ drivers/cache/Kconfig | 9 ++++ drivers/cache/Makefile | 1 + drivers/cache/cache-v5l2.c | 102 +++++++++++++++++++++++++++++++++++ 5 files changed, 176 insertions(+) create mode 100644 arch/riscv/include/asm/v5l2cache.h create mode 100644 drivers/cache/cache-v5l2.cQuoted 14 lines
arch/riscv/include/asm/global_data.h struct arch_global_data { · line 29
Quoted 11 lines
arch/riscv/include/asm/global_data.h +3
-0@@ -24,6 +24,9 @@ struct arch_global_data {#ifdef CONFIG_ANDES_PLMT void __iomem *plmt;/* plmt base address */ #endif +#ifdef CONFIG_V5L2_CACHE +void __iomem *v5l2;/* v5l2 base address */ +#endif Please do not expose this to global data if it is only used inside a driver. Anything that is here is for "global" usage.
OK.
I will remove it.Quoted 5 lines
Quoted 5 lines
arch/riscv/include/asm/global_data.h +0
-0#ifdef CONFIG_SMP struct ipi_data ipi[CONFIG_NR_CPUS ];#endif arch/riscv/include/asm/v5l2cache.h new file +0
-0Quoted 8 lines
arch/riscv/include/asm/v5l2cache.h
Quoted 3 lines
index 0000000..8ed1c6c
arch/riscv/include/asm/v5l2cache.h new file +0
-0Please create
arch/riscv/include/asm/arch-ax25/v5l2cache.h. Speaking of the name, would it be more readable to name it asv5_l2cache.h? Or even add more information to v5, for me, I don't know what v5 stands for :)OK
I will createarch/riscv/include/asm/arch-ax25/v5_l2cache.hQuoted 7 lines
Quoted 7 lines
arch/riscv/include/asm/v5l2cache.h new file +6
-0@@ -0,0 +1,61 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright (C) 2019 Andes Technology Corporation +* Rick Chen, Andes Technology Corporation <[email protected]> +*/ +Quoted 8 lines
arch/riscv/include/asm/v5l2cache.h line 11
Quoted 5 lines
arch/riscv/include/asm/v5l2cache.h new file +5
-0+#ifndef _ASM_V5_L2CACHE_H +#define _ASM_V5_L2CACHE_H + +struct l2cache { + volatile u64 configure;checkpatch.pl will report warnings against volatile usage. I think we should drop these.
I know that checkpatch.pl will report this warning.
But I still need to add volatile. It help to fix some unpredictable problem. Without this some driver code flows will be optimized and go wrong somehow.Quoted 58 lines
Quoted 58 lines
arch/riscv/include/asm/v5l2cache.h new file +50
-0+volatile u64 control; +volatile u64 hpm0; +volatile u64 hpm1; +volatile u64 hpm2; +volatile u64 hpm3; +volatile u64 error_status; +volatile u64 ecc_error; +volatile u64 cctl_command0; +volatile u64 cctl_access_line0; +volatile u64 cctl_command1; +volatile u64 cctl_access_line1; +volatile u64 cctl_command2; +volatile u64 cctl_access_line2; +volatile u64 cctl_command3; +volatile u64 cctl_access_line4; + volatile u64 cctl_status; +}; + +/* Control Register */ +#define L2_ENABLE 0x1 +/* prefetch */ +#define IPREPETCH_OFF 3 +#define DPREPETCH_OFF 5 +#define IPREPETCH_MSK (3 << IPREPETCH_OFF) +#define DPREPETCH_MSK (3 << DPREPETCH_OFF) +/* tag ram */ +#define TRAMOCTL_OFF 8 +#define TRAMICTL_OFF 10 +#define TRAMOCTL_MSK (3 << TRAMOCTL_OFF) +#define TRAMICTL_MSK BIT(TRAMICTL_OFF) +/* data ram */ +#define DRAMOCTL_OFF 11 +#define DRAMICTL_OFF 13 +#define DRAMOCTL_MSK (3 << DRAMOCTL_OFF) +#define DRAMICTL_MSK BIT(DRAMICTL_OFF) + +/* CCTL Command Register */ +#define CCTL_CMD_REG (base, hart) ((ulong)(base) + 0x40 + (hart) * 0x10) +#define L2_WBINVAL_ALL 0x12 + +/* CCTL Status Register */ +#define CCTL_STATUS_MSK (hart) (0xf << ((hart) * 4)) +#define CCTL_STATUS_IDLE (hart) (0 << ((hart) * 4)) +#define CCTL_STATUS_PROCESS (hart) (1 << ((hart) * 4)) +#define CCTL_STATUS_ILLEGAL (hart) (2 << ((hart) * 4)) + +void v5l2_enable (void ); +void v5l2_disable (void ); + +#endif /* _ASM_V5_L2CACHE_H */ drivers/cache/Kconfig +0
-0@@ -22,4 +22,13 @@ config L2X0_CACHE ARMv7(32-bit) devices. The driver configures the cache settings found in the device tree.Quoted 4 lines
drivers/cache/Kconfig config L2X0_CACHE · line 26
Quoted 2 lines
drivers/cache/Kconfig +2
-0+config V5L2_CACHE + tristate "Andes V5L2 cache driver"This should be bool. U-Boot does not support "tristate"
I will modify it as bool.
Quoted 35 lines
Quoted 35 lines
drivers/cache/Kconfig +7
-0+ select CACHE + depends on RISCV_NDS_CACHE + help + Support Andes V5L2 cache controller in AE350 platform. + It will configure tag and data ram timing control from the + device tree and enable L2 cache. + endmenudrivers/cache/Makefile +1
-0@@ -2,3 +2,4 @@ obj-$(CONFIG_CACHE) += cache-uclass.o obj-$(CONFIG_SANDBOX) += sandbox_cache.o obj-$(CONFIG_L2X0_CACHE) += cache-l2x0.o +obj-$(CONFIG_V5L2_CACHE) += cache-v5l2.odrivers/cache/cache-v5l2.c new file +12
-0@@ -0,0 +1,102 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2019 Andes Technology Corporation +* Rick Chen, Andes Technology Corporation <[email protected]> +*/ + +#include <common.h> +#include <command.h> +#include <dm.h> +#include <asm/io.h> +#include <dm/ofnode.h> +#include <asm/v5l2cache.h> Quoted 8 lines
drivers/cache/cache-v5l2.c line 16
Quoted 4 lines
drivers/cache/cache-v5l2.c new file +4
-0+ +DECLARE_GLOBAL_DATA_PTR ; + +void v5l2_enable (void )This should really be avoided. It looks current DM cache uclass driver is lacking of ops to do cache enable/disable. Please improve the DM cache uclass driver first.
OK
I will improve the DM cache uclass driver.Quoted 24 lines
Quoted 24 lines
drivers/cache/cache-v5l2.c new file +24
-0+{ +struct l2cache *regs = gd->arch.v5l2; + +if (regs) +setbits_le32 (®s->control,L2_ENABLE ); +} + +void v5l2_disable (void ) +{ +volatile struct l2cache *regs = gd->arch.v5l2; +u8 hart = gd->arch.boot_hart; +void __iomem *cctlcmd = (void __iomem *)CCTL_CMD_REG (gd->arch.v5l2, hart); + +if ((regs) && (readl (®s->control) &L2_ENABLE )) { +writel (L2_WBINVAL_ALL , cctlcmd); + +while ((readl (®s->cctl_status) &CCTL_STATUS_MSK (hart))) { +if ((readl (®s->cctl_status) &CCTL_STATUS_ILLEGAL (hart))) { +printf ("L2 flush illegal! hanging..." ); +hang (); + } + } +clrbits_le32 (®s->control,L2_ENABLE ); + }Quoted 8 lines
drivers/cache/cache-v5l2.c line 43
Quoted 3 lines
drivers/cache/cache-v5l2.c new file +3
-0+} + +static void v5l2_of_parse_and_init (struct udevice *dev)The entire function below should really be created as the driver's
ofdata_to_platdata()function, inside which all DT properties are parsed and saved to driver's platdata. After that, there is no need to get register base from global data.I will use
ofdata_to_platdata()to parse dtb information and save it into platdata instead of saving in global data.Quoted 44 lines
Quoted 44 lines
drivers/cache/cache-v5l2.c new file +44
-0+{ +struct l2cache *regs; +u32 ctl_val, prefetch; +u32 tram_ctl[2 ]; +u32 dram_ctl[2 ]; + + regs = (struct l2cache *)dev_read_addr (dev); + gd->arch.v5l2 = regs; + ctl_val =readl (®s->control); + +if (!(ctl_val &L2_ENABLE )) + ctl_val |=L2_ENABLE ; + +/* Instruction and data fetch prefetch depth */ +if (!dev_read_u32 (dev,"andes,inst-prefetch" , &prefetch)) { + ctl_val &= ~(IPREPETCH_MSK ); + ctl_val |= (prefetch <<IPREPETCH_OFF ); + } + +if (!dev_read_u32 (dev,"andes,data-prefetch" , &prefetch)) { + ctl_val &= ~(DPREPETCH_MSK ); + ctl_val |= (prefetch <<DPREPETCH_OFF ); + } + +/* Set tag RAM and data RAM setup and output cycle */ +if (!dev_read_u32_array (dev,"andes,tag-ram-ctl" , tram_ctl,2 )) { + ctl_val &= ~(TRAMOCTL_MSK |TRAMICTL_MSK ); + ctl_val |= tram_ctl[0 ] <<TRAMOCTL_OFF ; + ctl_val |= tram_ctl[1 ] <<TRAMICTL_OFF ; + } + +if (!dev_read_u32_array (dev,"andes,data-ram-ctl" , dram_ctl,2 )) { + ctl_val &= ~(DRAMOCTL_MSK |DRAMICTL_MSK ); + ctl_val |= dram_ctl[0 ] <<DRAMOCTL_OFF ; + ctl_val |= dram_ctl[1 ] <<DRAMICTL_OFF ; + } + +writel (ctl_val, ®s->control); +} + +static int v5l2_probe (struct udevice *dev) +{ +v5l2_of_parse_and_init (dev); +Quoted 9 lines
drivers/cache/cache-v5l2.c line 92
Quoted 5 lines
drivers/cache/cache-v5l2.c new file +5
-0+return 0 ; +} + +static const struct udevice_id v5l2_cache_ids[] = { + { .compatible ="cache" },I suspect this compatible string is too generic. Has this been reviewed by DT community upstream?
Quoted 7 lines
It refer to many dts examples from arm,
For example :arch/arm/dts/fsl-imx8-ca35.dtsiA35_L2: l2-cache0 { compatible = "cache"; };None of these have a driver for the cache controller, which is why it is sufficient to just use a generic compatible string.
Quoted 7 lines
I agree with Bin that you should choose a more specific compatible string. This is likely to cause problems in the future otherwise. For example, if Andes develops a new L2 cache controller, it must be differentiated from this one using the compatible string. The new controller would therefore have to use a different compatible string. It is good practice to already use a more specific one now to avoid the headache later. :)
Quoted 2 lines
You are right.
I will modify it as compatible = "v5l2cache"
Before you do that, could you please check whether this L2 cache driver will be supported in the Linux kernel too? If yes, I think you need go through the kernel upstream process, during which the compatible string is to be discussed and approved.
Regards,
Bin
PATCH 1/6 dm: cache: add v5l2 cache controller driver
Hi Bin
Quoted 314 lines
Hi Rick,
Quoted 310 lines · Rick Chen
Hi Lukas
Quoted 306 lines
Hi Rick,
Quoted 284 lines · Rick Chen
Hi Bin
Bin Meng <[email protected]> 於 2019年6月4日 週二 上午10:48寫道:
Quoted 24 lines
Hi Rick,
Quoted 21 lines · Andes
From: Rick Chen <[email protected]>
Add a v5l2 cache controller driver that is usually found on Andes RISC-V ae350 platform. It will parse the cache settings from the dtb.
In this version tag and data ram control timing can be adjusted by the requirement from the dtb.
Signed-off-by Rick Chen <[email protected]>Cc Greentime Hu <[email protected]>--- arch/riscv/include/asm/global_data.h | 3 ++ arch/riscv/include/asm/v5l2cache.h | 61 +++++++++++++++++++++ drivers/cache/Kconfig | 9 ++++ drivers/cache/Makefile | 1 + drivers/cache/cache-v5l2.c | 102 +++++++++++++++++++++++++++++++++++ 5 files changed, 176 insertions(+) create mode 100644 arch/riscv/include/asm/v5l2cache.h create mode 100644 drivers/cache/cache-v5l2.cQuoted 14 lines
arch/riscv/include/asm/global_data.h struct arch_global_data { · line 29
Quoted 11 lines
arch/riscv/include/asm/global_data.h +3
-0@@ -24,6 +24,9 @@ struct arch_global_data {#ifdef CONFIG_ANDES_PLMT void __iomem *plmt;/* plmt base address */ #endif +#ifdef CONFIG_V5L2_CACHE +void __iomem *v5l2;/* v5l2 base address */ +#endif Please do not expose this to global data if it is only used inside a driver. Anything that is here is for "global" usage.
OK.
I will remove it.Quoted 5 lines
Quoted 5 lines
arch/riscv/include/asm/global_data.h +0
-0#ifdef CONFIG_SMP struct ipi_data ipi[CONFIG_NR_CPUS ];#endif arch/riscv/include/asm/v5l2cache.h new file +0
-0Quoted 8 lines
arch/riscv/include/asm/v5l2cache.h
Quoted 3 lines
index 0000000..8ed1c6c
arch/riscv/include/asm/v5l2cache.h new file +0
-0Please create
arch/riscv/include/asm/arch-ax25/v5l2cache.h. Speaking of the name, would it be more readable to name it asv5_l2cache.h? Or even add more information to v5, for me, I don't know what v5 stands for :)OK
I will createarch/riscv/include/asm/arch-ax25/v5_l2cache.hQuoted 7 lines
Quoted 7 lines
arch/riscv/include/asm/v5l2cache.h new file +6
-0@@ -0,0 +1,61 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright (C) 2019 Andes Technology Corporation +* Rick Chen, Andes Technology Corporation <[email protected]> +*/ +Quoted 8 lines
arch/riscv/include/asm/v5l2cache.h line 11
Quoted 5 lines
arch/riscv/include/asm/v5l2cache.h new file +5
-0+#ifndef _ASM_V5_L2CACHE_H +#define _ASM_V5_L2CACHE_H + +struct l2cache { + volatile u64 configure;checkpatch.pl will report warnings against volatile usage. I think we should drop these.
I know that checkpatch.pl will report this warning.
But I still need to add volatile. It help to fix some unpredictable problem. Without this some driver code flows will be optimized and go wrong somehow.Quoted 58 lines
Quoted 58 lines
arch/riscv/include/asm/v5l2cache.h new file +50
-0+volatile u64 control; +volatile u64 hpm0; +volatile u64 hpm1; +volatile u64 hpm2; +volatile u64 hpm3; +volatile u64 error_status; +volatile u64 ecc_error; +volatile u64 cctl_command0; +volatile u64 cctl_access_line0; +volatile u64 cctl_command1; +volatile u64 cctl_access_line1; +volatile u64 cctl_command2; +volatile u64 cctl_access_line2; +volatile u64 cctl_command3; +volatile u64 cctl_access_line4; + volatile u64 cctl_status; +}; + +/* Control Register */ +#define L2_ENABLE 0x1 +/* prefetch */ +#define IPREPETCH_OFF 3 +#define DPREPETCH_OFF 5 +#define IPREPETCH_MSK (3 << IPREPETCH_OFF) +#define DPREPETCH_MSK (3 << DPREPETCH_OFF) +/* tag ram */ +#define TRAMOCTL_OFF 8 +#define TRAMICTL_OFF 10 +#define TRAMOCTL_MSK (3 << TRAMOCTL_OFF) +#define TRAMICTL_MSK BIT(TRAMICTL_OFF) +/* data ram */ +#define DRAMOCTL_OFF 11 +#define DRAMICTL_OFF 13 +#define DRAMOCTL_MSK (3 << DRAMOCTL_OFF) +#define DRAMICTL_MSK BIT(DRAMICTL_OFF) + +/* CCTL Command Register */ +#define CCTL_CMD_REG (base, hart) ((ulong)(base) + 0x40 + (hart) * 0x10) +#define L2_WBINVAL_ALL 0x12 + +/* CCTL Status Register */ +#define CCTL_STATUS_MSK (hart) (0xf << ((hart) * 4)) +#define CCTL_STATUS_IDLE (hart) (0 << ((hart) * 4)) +#define CCTL_STATUS_PROCESS (hart) (1 << ((hart) * 4)) +#define CCTL_STATUS_ILLEGAL (hart) (2 << ((hart) * 4)) + +void v5l2_enable (void ); +void v5l2_disable (void ); + +#endif /* _ASM_V5_L2CACHE_H */ drivers/cache/Kconfig +0
-0@@ -22,4 +22,13 @@ config L2X0_CACHE ARMv7(32-bit) devices. The driver configures the cache settings found in the device tree.Quoted 4 lines
drivers/cache/Kconfig config L2X0_CACHE · line 26
Quoted 2 lines
drivers/cache/Kconfig +2
-0+config V5L2_CACHE + tristate "Andes V5L2 cache driver"This should be bool. U-Boot does not support "tristate"
I will modify it as bool.
Quoted 35 lines
Quoted 35 lines
drivers/cache/Kconfig +7
-0+ select CACHE + depends on RISCV_NDS_CACHE + help + Support Andes V5L2 cache controller in AE350 platform. + It will configure tag and data ram timing control from the + device tree and enable L2 cache. + endmenudrivers/cache/Makefile +1
-0@@ -2,3 +2,4 @@ obj-$(CONFIG_CACHE) += cache-uclass.o obj-$(CONFIG_SANDBOX) += sandbox_cache.o obj-$(CONFIG_L2X0_CACHE) += cache-l2x0.o +obj-$(CONFIG_V5L2_CACHE) += cache-v5l2.odrivers/cache/cache-v5l2.c new file +12
-0@@ -0,0 +1,102 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2019 Andes Technology Corporation +* Rick Chen, Andes Technology Corporation <[email protected]> +*/ + +#include <common.h> +#include <command.h> +#include <dm.h> +#include <asm/io.h> +#include <dm/ofnode.h> +#include <asm/v5l2cache.h> Quoted 8 lines
drivers/cache/cache-v5l2.c line 16
Quoted 4 lines
drivers/cache/cache-v5l2.c new file +4
-0+ +DECLARE_GLOBAL_DATA_PTR ; + +void v5l2_enable (void )This should really be avoided. It looks current DM cache uclass driver is lacking of ops to do cache enable/disable. Please improve the DM cache uclass driver first.
OK
I will improve the DM cache uclass driver.Quoted 24 lines
Quoted 24 lines
drivers/cache/cache-v5l2.c new file +24
-0+{ +struct l2cache *regs = gd->arch.v5l2; + +if (regs) +setbits_le32 (®s->control,L2_ENABLE ); +} + +void v5l2_disable (void ) +{ +volatile struct l2cache *regs = gd->arch.v5l2; +u8 hart = gd->arch.boot_hart; +void __iomem *cctlcmd = (void __iomem *)CCTL_CMD_REG (gd->arch.v5l2, hart); + +if ((regs) && (readl (®s->control) &L2_ENABLE )) { +writel (L2_WBINVAL_ALL , cctlcmd); + +while ((readl (®s->cctl_status) &CCTL_STATUS_MSK (hart))) { +if ((readl (®s->cctl_status) &CCTL_STATUS_ILLEGAL (hart))) { +printf ("L2 flush illegal! hanging..." ); +hang (); + } + } +clrbits_le32 (®s->control,L2_ENABLE ); + }Quoted 8 lines
drivers/cache/cache-v5l2.c line 43
Quoted 3 lines
drivers/cache/cache-v5l2.c new file +3
-0+} + +static void v5l2_of_parse_and_init (struct udevice *dev)The entire function below should really be created as the driver's
ofdata_to_platdata()function, inside which all DT properties are parsed and saved to driver's platdata. After that, there is no need to get register base from global data.I will use
ofdata_to_platdata()to parse dtb information and save it into platdata instead of saving in global data.Quoted 44 lines
Quoted 44 lines
drivers/cache/cache-v5l2.c new file +44
-0+{ +struct l2cache *regs; +u32 ctl_val, prefetch; +u32 tram_ctl[2 ]; +u32 dram_ctl[2 ]; + + regs = (struct l2cache *)dev_read_addr (dev); + gd->arch.v5l2 = regs; + ctl_val =readl (®s->control); + +if (!(ctl_val &L2_ENABLE )) + ctl_val |=L2_ENABLE ; + +/* Instruction and data fetch prefetch depth */ +if (!dev_read_u32 (dev,"andes,inst-prefetch" , &prefetch)) { + ctl_val &= ~(IPREPETCH_MSK ); + ctl_val |= (prefetch <<IPREPETCH_OFF ); + } + +if (!dev_read_u32 (dev,"andes,data-prefetch" , &prefetch)) { + ctl_val &= ~(DPREPETCH_MSK ); + ctl_val |= (prefetch <<DPREPETCH_OFF ); + } + +/* Set tag RAM and data RAM setup and output cycle */ +if (!dev_read_u32_array (dev,"andes,tag-ram-ctl" , tram_ctl,2 )) { + ctl_val &= ~(TRAMOCTL_MSK |TRAMICTL_MSK ); + ctl_val |= tram_ctl[0 ] <<TRAMOCTL_OFF ; + ctl_val |= tram_ctl[1 ] <<TRAMICTL_OFF ; + } + +if (!dev_read_u32_array (dev,"andes,data-ram-ctl" , dram_ctl,2 )) { + ctl_val &= ~(DRAMOCTL_MSK |DRAMICTL_MSK ); + ctl_val |= dram_ctl[0 ] <<DRAMOCTL_OFF ; + ctl_val |= dram_ctl[1 ] <<DRAMICTL_OFF ; + } + +writel (ctl_val, ®s->control); +} + +static int v5l2_probe (struct udevice *dev) +{ +v5l2_of_parse_and_init (dev); +Quoted 9 lines
drivers/cache/cache-v5l2.c line 92
Quoted 5 lines
drivers/cache/cache-v5l2.c new file +5
-0+return 0 ; +} + +static const struct udevice_id v5l2_cache_ids[] = { + { .compatible ="cache" },I suspect this compatible string is too generic. Has this been reviewed by DT community upstream?
Quoted 7 lines
It refer to many dts examples from arm,
For example :arch/arm/dts/fsl-imx8-ca35.dtsiA35_L2: l2-cache0 { compatible = "cache"; };None of these have a driver for the cache controller, which is why it is sufficient to just use a generic compatible string.
I agree with Bin that you should choose a more specific compatible string. This is likely to cause problems in the future otherwise. For example, if Andes develops a new L2 cache controller, it must be differentiated from this one using the compatible string. The new controller would therefore have to use a different compatible string. It is good practice to already use a more specific one now to avoid the headache later. :)
Quoted 8 lines
Quoted 2 lines
You are right.
I will modify it as compatible = "v5l2cache"Before you do that, could you please check whether this L2 cache driver will be supported in the Linux kernel too? If yes, I think you need go through the kernel upstream process, during which the compatible string is to be discussed and approved.
No, we only support this L2 cache in U-Boot about upstream.
Rick
Quoted 2 lines
Regards,
Bin
PATCH 2/6 riscv: ae350: use the v5l2 driver to configure the cache
In reply to AndesFrom: Rick Chen <[email protected]>
Find the UCLASS_CACHE driver to configure the cache controller's settings.
--- board/AndesTech/ax25-ae350/ax25-ae350.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
board/AndesTech/ax25-ae350/ax25-ae350.c +15 -0
@@ -11,6 +11,7 @@#include <linux/io.h> #include <faraday/ftsmc020.h> #include <fdtdec.h> +#include <dm.h> DECLARE_GLOBAL_DATA_PTR ;
@@ -93,10 +94,24 @@ int smc_init(void)return 0 ; } +int v5l2_init (void ) +{ +struct udevice *dev; +int ret; + + ret =uclass_get_device (UCLASS_CACHE ,0 , &dev); + +if (ret) +return ret; + +return 0 ; +} +#ifdef CONFIG_BOARD_EARLY_INIT_F int board_early_init_f (void ) {smc_init (); +v5l2_init ();return 0 ; }
Signature · 1 line
2.7.4
PATCH 2/6 riscv: ae350: use the v5l2 driver to configure the cache
Hi Rick,
Quoted 36 lines · Andes
From: Rick Chen <[email protected]>
Find the
UCLASS_CACHEdriver to configure the cache controller's settings.Signed-off-by Rick Chen <[email protected]>Cc Greentime Hu <[email protected]>--- board/AndesTech/ax25-ae350/ax25-ae350.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)board/AndesTech/ax25-ae350/ax25-ae350.c +9
-0@@ -11,6 +11,7 @@#include <linux/io.h> #include <faraday/ftsmc020.h> #include <fdtdec.h> +#include <dm.h> DECLARE_GLOBAL_DATA_PTR ;@@ -93,10 +94,24 @@ int smc_init(void)return 0 ; } +int v5l2_init (void ) +{ +struct udevice *dev; +int ret; + + ret =uclass_get_device (UCLASS_CACHE ,0 , &dev); + +if (ret)
board/AndesTech/ax25-ae350/ax25-ae350.c int smc_init(void) · line 114
Quoted 10 lines
board/AndesTech/ax25-ae350/ax25-ae350.c +6
-0+return ret; + +return 0 ; +} +#ifdef CONFIG_BOARD_EARLY_INIT_F int board_early_init_f (void ) {smc_init (); +v5l2_init ();
Please check the return value here, or you can make v512_init() returns void.
board/AndesTech/ax25-ae350/ax25-ae350.c int smc_init(void)
Quoted 4 lines
board/AndesTech/ax25-ae350/ax25-ae350.c +0
-1return 0 ; } --
Regards,
Bin
PATCH 2/6 riscv: ae350: use the v5l2 driver to configure the cache
Bin Meng <[email protected]> 於 2019年6月4日 週二 上午10:48寫道:
Quoted 60 lines
Hi Rick,
Quoted 36 lines · Andes
From: Rick Chen <[email protected]>
Find the
UCLASS_CACHEdriver to configure the cache controller's settings.Signed-off-by Rick Chen <[email protected]>Cc Greentime Hu <[email protected]>--- board/AndesTech/ax25-ae350/ax25-ae350.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)board/AndesTech/ax25-ae350/ax25-ae350.c +9
-0@@ -11,6 +11,7 @@#include <linux/io.h> #include <faraday/ftsmc020.h> #include <fdtdec.h> +#include <dm.h> DECLARE_GLOBAL_DATA_PTR ;@@ -93,10 +94,24 @@ int smc_init(void)return 0 ; } +int v5l2_init (void ) +{ +struct udevice *dev; +int ret; + + ret =uclass_get_device (UCLASS_CACHE ,0 , &dev); + +if (ret)board/AndesTech/ax25-ae350/ax25-ae350.c int smc_init(void) · line 114
Quoted 10 lines
board/AndesTech/ax25-ae350/ax25-ae350.c +6
-0+return ret; + +return 0 ; +} +#ifdef CONFIG_BOARD_EARLY_INIT_F int board_early_init_f (void ) {smc_init (); +v5l2_init ();Please check the return value here, or you can make
v512_init()returns void.board/AndesTech/ax25-ae350/ax25-ae350.c int smc_init(void)
Quoted 4 lines
board/AndesTech/ax25-ae350/ax25-ae350.c +0
-1return 0 ; } --Regards,
Bin
PATCH 2/6 riscv: ae350: use the v5l2 driver to configure the cache
In reply to Bin MengHi Bin
Bin Meng <[email protected]> 於 2019年6月4日 週二 上午10:48寫道:
Quoted 44 lines
Hi Rick,
Quoted 40 lines · Andes
From: Rick Chen <[email protected]>
Find the
UCLASS_CACHEdriver to configure the cache controller's settings.Signed-off-by Rick Chen <[email protected]>Cc Greentime Hu <[email protected]>--- board/AndesTech/ax25-ae350/ax25-ae350.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)board/AndesTech/ax25-ae350/ax25-ae350.c +13
-0@@ -11,6 +11,7 @@#include <linux/io.h> #include <faraday/ftsmc020.h> #include <fdtdec.h> +#include <dm.h> DECLARE_GLOBAL_DATA_PTR ;@@ -93,10 +94,24 @@ int smc_init(void)return 0 ; } +int v5l2_init (void ) +{ +struct udevice *dev; +int ret; + + ret =uclass_get_device (UCLASS_CACHE ,0 , &dev); + +if (ret) +return ret; + +return 0 ; +}
Quoted 8 lines
board/AndesTech/ax25-ae350/ax25-ae350.c int smc_init(void) · line 114
Quoted 6 lines
board/AndesTech/ax25-ae350/ax25-ae350.c +2
-0+#ifdef CONFIG_BOARD_EARLY_INIT_F int board_early_init_f (void ) {smc_init (); +v5l2_init ();Please check the return value here, or you can make
v512_init()returns void.
OK.
I will check the return value here.
Quoted 8 lines
board/AndesTech/ax25-ae350/ax25-ae350.c int smc_init(void)
Quoted 5 lines
board/AndesTech/ax25-ae350/ax25-ae350.c +0
-1return 0 ; } --Regards,
Bin
PATCH 3/6 riscv: ae350: add imply v5l2 cache controller
In reply to AndesFrom: Rick Chen <[email protected]>
Select the v5l2 UCLASS_CACHE driver for AE350.
--- board/AndesTech/ax25-ae350/Kconfig | 1 + 1 file changed, 1 insertion(+)
board/AndesTech/ax25-ae350/Kconfig +1 -0
@@ -25,5 +25,6 @@ config BOARD_SPECIFIC_OPTIONS # dummy def_bool y select RISCV_NDS imply SMP + imply V5L2_CACHE endif
Signature · 1 line
2.7.4
PATCH 3/6 riscv: ae350: add imply v5l2 cache controller
Hi Rick,
Quoted 16 lines · Andes
From: Rick Chen <[email protected]>
Select the v5l2
UCLASS_CACHEdriver for AE350.Signed-off-by Rick Chen <[email protected]>Cc Greentime Hu <[email protected]>--- board/AndesTech/ax25-ae350/Kconfig | 1 + 1 file changed, 1 insertion(+)board/AndesTech/ax25-ae350/Kconfig +0
-0
board/AndesTech/ax25-ae350/Kconfig config BOARD_SPECIFIC_OPTIONS # dummy · line 28
Quoted 4 lines
board/AndesTech/ax25-ae350/Kconfig +1
-0@@ -25,5 +25,6 @@ config BOARD_SPECIFIC_OPTIONS # dummy def_bool y select RISCV_NDS imply SMP + imply V5L2_CACHE
I believe L2 cache is a CPU specific feature, hence this should be implied from arch/riscv/cpu/ax25/Kconfig
Regards,
Bin
PATCH 3/6 riscv: ae350: add imply v5l2 cache controller
Hi Bin
Quoted 15 lines
Hi Rick,
Quoted 11 lines · Andes
From: Rick Chen <[email protected]>
Select the v5l2
UCLASS_CACHEdriver for AE350.Signed-off-by Rick Chen <[email protected]>Cc Greentime Hu <[email protected]>--- board/AndesTech/ax25-ae350/Kconfig | 1 + 1 file changed, 1 insertion(+)
Quoted 12 lines
board/AndesTech/ax25-ae350/Kconfig config BOARD_SPECIFIC_OPTIONS # dummy · line 28
Quoted 9 lines
board/AndesTech/ax25-ae350/Kconfig +1
-0@@ -25,5 +25,6 @@ config BOARD_SPECIFIC_OPTIONS # dummy def_bool y select RISCV_NDS imply SMP + imply V5L2_CACHEI believe L2 cache is a CPU specific feature, hence this should be implied from
arch/riscv/cpu/ax25/Kconfig
OK
I will move it to arch/riscv/cpu/ax25/Kconfig
Thanks
Rick
Quoted 3 lines
Regards,
Bin
PATCH 4/6 riscv: cache: Flush L2 cache before jump to linux
In reply to AndesFrom: Rick Chen <[email protected]>
Flush and disable cache in cleanup_before_linux()
which will be called before jump to linux.
The sequence will be preferred as below:
L1 flush -> L1 disable -> L2 flush -> L2 disable
--- arch/riscv/cpu/ax25/cpu.c | 4 ++++ 1 file changed, 4 insertions(+)
arch/riscv/cpu/ax25/cpu.c +4 -0
@@ -7,6 +7,7 @@/* CPU specific code */ #include <common.h> #include <asm/cache.h> +#include <asm/v5l2cache.h> /* * cleanup_before_linux() is called just before we call linux
@@ -22,6 +23,9 @@ int cleanup_before_linux(void)cache_flush ();icache_disable ();dcache_disable (); +#ifdef CONFIG_RISCV_NDS_CACHE +v5l2_disable (); +#endif return 0 ; }
Signature · 1 line
2.7.4
PATCH 4/6 riscv: cache: Flush L2 cache before jump to linux
Hi Rick,
Quoted 28 lines · Andes
From: Rick Chen <[email protected]>
Flush and disable cache in
cleanup_before_linux()
which will be called before jump to linux.The sequence will be preferred as below:
L1 flush -> L1 disable -> L2 flush -> L2 disableSigned-off-by Rick Chen <[email protected]>Cc Greentime Hu <[email protected]>--- arch/riscv/cpu/ax25/cpu.c | 4 ++++ 1 file changed, 4 insertions(+)arch/riscv/cpu/ax25/cpu.c +1
-0@@ -7,6 +7,7 @@/* CPU specific code */ #include <common.h> #include <asm/cache.h> +#include <asm/v5l2cache.h> /* * cleanup_before_linux() is called just before we call linux
arch/riscv/cpu/ax25/cpu.c int cleanup_before_linux(void) · line 28
Quoted 6 lines
arch/riscv/cpu/ax25/cpu.c +3
-0@@ -22,6 +23,9 @@ int cleanup_before_linux(void)cache_flush ();icache_disable ();dcache_disable (); +#ifdef CONFIG_RISCV_NDS_CACHE +v5l2_disable (); +#endif
The direct call into a driver should be avoided. Instead, use a proper DM cache uclass driver API (see my review comments in patch [1/6])
Regards,
Bin
PATCH 4/6 riscv: cache: Flush L2 cache before jump to linux
Hi Bin
Quoted 29 lines
Hi Rick,
Quoted 25 lines · Andes
From: Rick Chen <[email protected]>
Flush and disable cache in
cleanup_before_linux()
which will be called before jump to linux.The sequence will be preferred as below:
L1 flush -> L1 disable -> L2 flush -> L2 disableSigned-off-by Rick Chen <[email protected]>Cc Greentime Hu <[email protected]>--- arch/riscv/cpu/ax25/cpu.c | 4 ++++ 1 file changed, 4 insertions(+)arch/riscv/cpu/ax25/cpu.c +1
-0@@ -7,6 +7,7 @@/* CPU specific code */ #include <common.h> #include <asm/cache.h> +#include <asm/v5l2cache.h>
Quoted 12 lines
arch/riscv/cpu/ax25/cpu.c int cleanup_before_linux(void) · line 28
Quoted 9 lines
arch/riscv/cpu/ax25/cpu.c +3
-0/* * cleanup_before_linux() is called just before we call linux @@ -22,6 +23,9 @@ int cleanup_before_linux(void)cache_flush ();icache_disable ();dcache_disable (); +#ifdef CONFIG_RISCV_NDS_CACHE +v5l2_disable (); +#endif The direct call into a driver should be avoided. Instead, use a proper DM cache uclass driver API (see my review comments in patch [1/6])
OK
I will use DM cache uclass driver API to disable L2 driver.
Thanks
Rick
Quoted 3 lines
Regards,
Bin
PATCH 5/6 riscv: dts: move out AE350 L2 node from cpus node
In reply to AndesFrom: Rick Chen <[email protected]>
When L2 node exists inside cpus node, uclass_get_device can not parse L2 node successfully. So move it outside from cpus node.
Also add tag-ram-ctl and data-ram-ctl attributes for v5l2 cache controller driver. This can adjust timing by requirement from dtb to improve performance.
--- arch/riscv/dts/ae350_32.dts | 17 +++++++++++------ arch/riscv/dts/ae350_64.dts | 17 +++++++++++------ 2 files changed, 22 insertions(+), 12 deletions(-)
arch/riscv/dts/ae350_32.dts +11 -6
@@ -62,13 +62,18 @@ compatible = "riscv,cpu-intc"; }; }; + }; - L2: l2-cache at e0500000 { - compatible = "cache"; - cache-level = <2>; - cache-size = <0x40000>; - reg = <0x0 0xe0500000 0x0 0x40000>; - }; + L2: l2-cache at e0500000 { + compatible = "cache"; + cache-level = <2>; + cache-size = <0x40000>; + reg = <0xe0500000 0x40000>; + andes,inst-prefetch = <3>; + andes,data-prefetch = <3>; + // The value format is <XRAMOCTL XRAMICTL> + andes,tag-ram-ctl = <0 0>; + andes,data-ram-ctl = <0 0>; }; memory at 0 {
arch/riscv/dts/ae350_64.dts +11 -6
@@ -62,13 +62,18 @@ compatible = "riscv,cpu-intc"; }; }; + }; - L2: l2-cache at e0500000 { - compatible = "cache"; - cache-level = <2>; - cache-size = <0x40000>; - reg = <0x0 0xe0500000 0x0 0x40000>; - }; + L2: l2-cache at e0500000 { + compatible = "cache"; + cache-level = <2>; + cache-size = <0x40000>; + reg = <0x0 0xe0500000 0x0 0x40000>; + andes,inst-prefetch = <3>; + andes,data-prefetch = <3>; + // The value format is <XRAMOCTL XRAMICTL> + andes,tag-ram-ctl = <0 0>; + andes,data-ram-ctl = <0 0>; }; memory at 0 {
Signature · 1 line
2.7.4
PATCH 5/6 riscv: dts: move out AE350 L2 node from cpus node
Hi Rick,
Quoted 26 lines · Andes
From: Rick Chen <[email protected]>
When L2 node exists inside cpus node,
uclass_get_devicecan not parse L2 node successfully. So move it outside from cpus node.Also add tag-ram-ctl and data-ram-ctl attributes for v5l2 cache controller driver. This can adjust timing by requirement from dtb to improve performance.
Signed-off-by Rick Chen <[email protected]>Cc Greentime Hu <[email protected]>--- arch/riscv/dts/ae350_32.dts | 17 +++++++++++------ arch/riscv/dts/ae350_64.dts | 17 +++++++++++------ 2 files changed, 22 insertions(+), 12 deletions(-)arch/riscv/dts/ae350_32.dts +0
-0@@ -62,13 +62,18 @@ compatible = "riscv,cpu-intc"; }; };
arch/riscv/dts/ae350_32.dts line 68
Quoted 10 lines
arch/riscv/dts/ae350_32.dts +3
-6+ }; - L2: l2-cache at e0500000 { - compatible = "cache"; - cache-level = <2>; - cache-size = <0x40000>; - reg = <0x0 0xe0500000 0x0 0x40000>; - }; + L2: l2-cache at e0500000 { + compatible = "cache";
too generic compatible string (see my previous comments in patch [1/6])
arch/riscv/dts/ae350_32.dts line 74
Quoted 6 lines
arch/riscv/dts/ae350_32.dts +6
-0+ cache-level = <2>; + cache-size = <0x40000>; + reg = <0xe0500000 0x40000>; + andes,inst-prefetch = <3>; + andes,data-prefetch = <3>; + // The value format is <XRAMOCTL XRAMICTL>
nits: no //, use /* */
Quoted 19 lines
arch/riscv/dts/ae350_32.dts +2
-0+ andes,tag-ram-ctl = <0 0>; + andes,data-ram-ctl = <0 0>; }; memory at 0 {arch/riscv/dts/ae350_64.dts +1
-4@@ -62,13 +62,18 @@ compatible = "riscv,cpu-intc"; }; }; + }; - L2: l2-cache at e0500000 { - compatible = "cache"; - cache-level = <2>; - cache-size = <0x40000>;
arch/riscv/dts/ae350_64.dts line 74
Quoted 10 lines
arch/riscv/dts/ae350_64.dts +8
-2- reg = <0x0 0xe0500000 0x0 0x40000>; - }; + L2: l2-cache at e0500000 { + compatible = "cache"; + cache-level = <2>; + cache-size = <0x40000>; + reg = <0x0 0xe0500000 0x0 0x40000>; + andes,inst-prefetch = <3>; + andes,data-prefetch = <3>; + // The value format is <XRAMOCTL XRAMICTL>
nits: no //, use /* */
arch/riscv/dts/ae350_64.dts
Quoted 6 lines
arch/riscv/dts/ae350_64.dts +2
-1+ andes,tag-ram-ctl = <0 0>; + andes,data-ram-ctl = <0 0>; }; memory at 0 { --
Regards,
Bin
PATCH 5/6 riscv: dts: move out AE350 L2 node from cpus node
Hi Bin
Bin Meng <[email protected]> 於 2019年6月4日 週二 上午10:48寫道:
Quoted 32 lines
Hi Rick,
Quoted 28 lines · Andes
From: Rick Chen <[email protected]>
When L2 node exists inside cpus node,
uclass_get_devicecan not parse L2 node successfully. So move it outside from cpus node.Also add tag-ram-ctl and data-ram-ctl attributes for v5l2 cache controller driver. This can adjust timing by requirement from dtb to improve performance.
Signed-off-by Rick Chen <[email protected]>Cc Greentime Hu <[email protected]>--- arch/riscv/dts/ae350_32.dts | 17 +++++++++++------ arch/riscv/dts/ae350_64.dts | 17 +++++++++++------ 2 files changed, 22 insertions(+), 12 deletions(-)arch/riscv/dts/ae350_32.dts +1
-0@@ -62,13 +62,18 @@ compatible = "riscv,cpu-intc"; }; }; + };
Quoted 10 lines
arch/riscv/dts/ae350_32.dts line 68
Quoted 8 lines
arch/riscv/dts/ae350_32.dts +2
-6- L2: l2-cache at e0500000 { - compatible = "cache"; - cache-level = <2>; - cache-size = <0x40000>; - reg = <0x0 0xe0500000 0x0 0x40000>; - }; + L2: l2-cache at e0500000 { + compatible = "cache";too generic compatible string (see my previous comments in patch [1/6])
Same replying in patch [1/6]
Quoted 9 lines
arch/riscv/dts/ae350_32.dts line 74
Quoted 7 lines
arch/riscv/dts/ae350_32.dts +6
-0+ cache-level = <2>; + cache-size = <0x40000>; + reg = <0xe0500000 0x40000>; + andes,inst-prefetch = <3>; + andes,data-prefetch = <3>; + // The value format is <XRAMOCTL XRAMICTL>nits: no //, use /* */
OK
I will use /* */ instead of //
Quoted 16 lines
Quoted 16 lines
arch/riscv/dts/ae350_32.dts +2
-0+ andes,tag-ram-ctl = <0 0>; + andes,data-ram-ctl = <0 0>; }; memory at 0 {arch/riscv/dts/ae350_64.dts +1
-0@@ -62,13 +62,18 @@ compatible = "riscv,cpu-intc"; }; }; + };
Quoted 16 lines
Quoted 4 lines
arch/riscv/dts/ae350_64.dts +0
-4- L2: l2-cache at e0500000 { - compatible = "cache"; - cache-level = <2>; - cache-size = <0x40000>;arch/riscv/dts/ae350_64.dts line 74
Quoted 10 lines
arch/riscv/dts/ae350_64.dts +8
-2- reg = <0x0 0xe0500000 0x0 0x40000>; - }; + L2: l2-cache at e0500000 { + compatible = "cache"; + cache-level = <2>; + cache-size = <0x40000>; + reg = <0x0 0xe0500000 0x0 0x40000>; + andes,inst-prefetch = <3>; + andes,data-prefetch = <3>; + // The value format is <XRAMOCTL XRAMICTL>nits: no //, use /* */
I will use /* */ instead of //
Thanks
Rick
Quoted 10 lines
arch/riscv/dts/ae350_64.dts
Quoted 7 lines
arch/riscv/dts/ae350_64.dts +2
-1+ andes,tag-ram-ctl = <0 0>; + andes,data-ram-ctl = <0 0>; }; memory at 0 { --Regards,
Bin
PATCH 6/6 riscv: ax25: use CCTL to flush d-cache
In reply to AndesFrom: Rick Chen <[email protected]>
Use CCTL command to do d-cache write back and invalidate instead of fence.
--- arch/riscv/cpu/ax25/cache.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-)
arch/riscv/cpu/ax25/cache.c +13 -9
@@ -5,17 +5,21 @@*/ #include <common.h> +#include <asm/csr.h> + +#ifdef CONFIG_RISCV_NDS_CACHE +/* mcctlcommand */ +#define CCTL_REG_MCCTLCOMMAND_NUM 0x7cc + +/* D-cache operation */ +#define CCTL_L1D_WBINVAL_ALL 6 +#endif void flush_dcache_all (void ) { -/* -* Andes' AX25 does not have a coherence agent. U-Boot must use data -* cache flush and invalidate functions to keep data in the system -* coherent. -* The implementation of the fence instruction in the AX25 flushes the -* data cache and is used for this purpose. -*/ - asmvolatile ("fence" :::"memory" ); +#ifdef CONFIG_RISCV_NDS_CACHE +csr_write (CCTL_REG_MCCTLCOMMAND_NUM ,CCTL_L1D_WBINVAL_ALL ); +#endif }void flush_dcache_range (unsigned long start,unsigned long end)
@@ -72,8 +76,8 @@ void dcache_disable(void) {#ifndef CONFIG_SYS_DCACHE_OFF #ifdef CONFIG_RISCV_NDS_CACHE +csr_write (CCTL_REG_MCCTLCOMMAND_NUM ,CCTL_L1D_WBINVAL_ALL ); asmvolatile ( -"fence\n\t" "csrr t1, mcache_ctl\n\t" "andi t0, t1, ~0x2\n\t" "csrw mcache_ctl, t0\n\t"
Signature · 1 line
2.7.4
PATCH 6/6 riscv: ax25: use CCTL to flush d-cache
Hi Rick,
Quoted 32 lines · Andes
From: Rick Chen <[email protected]>
Use CCTL command to do d-cache write back and invalidate instead of fence.
Signed-off-by Rick Chen <[email protected]>Cc Greentime Hu <[email protected]>--- arch/riscv/cpu/ax25/cache.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-)arch/riscv/cpu/ax25/cache.c +9
-0@@ -5,17 +5,21 @@*/ #include <common.h> +#include <asm/csr.h> + +#ifdef CONFIG_RISCV_NDS_CACHE +/* mcctlcommand */ +#define CCTL_REG_MCCTLCOMMAND_NUM 0x7cc + +/* D-cache operation */ +#define CCTL_L1D_WBINVAL_ALL 6 +#endif void flush_dcache_all (void ) {
arch/riscv/cpu/ax25/cache.c line 21
Quoted 10 lines
arch/riscv/cpu/ax25/cache.c +2
-8-/* -* Andes' AX25 does not have a coherence agent. U-Boot must use data -* cache flush and invalidate functions to keep data in the system -* coherent. -* The implementation of the fence instruction in the AX25 flushes the -* data cache and is used for this purpose. -*/ - asmvolatile ("fence" :::"memory" ); +#ifdef CONFIG_RISCV_NDS_CACHE +csr_write (CCTL_REG_MCCTLCOMMAND_NUM ,CCTL_L1D_WBINVAL_ALL );
I think CCTL_REG_MCCTLCOMMAND_NUM is a vendor specific CSR. Does upstream GCC support this CSR?
Quoted 5 lines
arch/riscv/cpu/ax25/cache.c +1
-0+#endif }void flush_dcache_range (unsigned long start,unsigned long end)
arch/riscv/cpu/ax25/cache.c void dcache_disable(void)
Quoted 10 lines
arch/riscv/cpu/ax25/cache.c +1
-2@@ -72,8 +76,8 @@ void dcache_disable(void) {#ifndef CONFIG_SYS_DCACHE_OFF #ifdef CONFIG_RISCV_NDS_CACHE +csr_write (CCTL_REG_MCCTLCOMMAND_NUM ,CCTL_L1D_WBINVAL_ALL ); asmvolatile ( - "fence\n\t""csrr t1, mcache_ctl\n\t" "andi t0, t1, ~0x2\n\t" "csrw mcache_ctl, t0\n\t" --
Regards,
Bin
PATCH 6/6 riscv: ax25: use CCTL to flush d-cache
Hi Bin
Quoted 34 lines
Hi Rick,
Quoted 30 lines · Andes
From: Rick Chen <[email protected]>
Use CCTL command to do d-cache write back and invalidate instead of fence.
Signed-off-by Rick Chen <[email protected]>Cc Greentime Hu <[email protected]>--- arch/riscv/cpu/ax25/cache.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-)arch/riscv/cpu/ax25/cache.c +9
-0@@ -5,17 +5,21 @@*/ #include <common.h> +#include <asm/csr.h> + +#ifdef CONFIG_RISCV_NDS_CACHE +/* mcctlcommand */ +#define CCTL_REG_MCCTLCOMMAND_NUM 0x7cc + +/* D-cache operation */ +#define CCTL_L1D_WBINVAL_ALL 6 +#endif
Quoted 15 lines
arch/riscv/cpu/ax25/cache.c line 21
Quoted 12 lines
arch/riscv/cpu/ax25/cache.c +2
-8void flush_dcache_all (void ) { -/* -* Andes' AX25 does not have a coherence agent. U-Boot must use data -* cache flush and invalidate functions to keep data in the system -* coherent. -* The implementation of the fence instruction in the AX25 flushes the -* data cache and is used for this purpose. -*/ - asmvolatile ("fence" :::"memory" ); +#ifdef CONFIG_RISCV_NDS_CACHE +csr_write (CCTL_REG_MCCTLCOMMAND_NUM ,CCTL_L1D_WBINVAL_ALL );I think
CCTL_REG_MCCTLCOMMAND_NUMis a vendor specific CSR. Does upstream GCC support this CSR?
Yes. It is a vendor specific CSR. Upstream GCC shall not support it. So I isolate it by CONFIG_RISCV_NDS_CACHE.
Thanks
Rick
Quoted 19 lines
Quoted 6 lines
arch/riscv/cpu/ax25/cache.c +1
-0+#endif }void flush_dcache_range (unsigned long start,unsigned long end)arch/riscv/cpu/ax25/cache.c void dcache_disable(void)
Quoted 10 lines
arch/riscv/cpu/ax25/cache.c +1
-2@@ -72,8 +76,8 @@ void dcache_disable(void) {#ifndef CONFIG_SYS_DCACHE_OFF #ifdef CONFIG_RISCV_NDS_CACHE +csr_write (CCTL_REG_MCCTLCOMMAND_NUM ,CCTL_L1D_WBINVAL_ALL ); asmvolatile ( - "fence\n\t""csrr t1, mcache_ctl\n\t" "andi t0, t1, ~0x2\n\t" "csrw mcache_ctl, t0\n\t" --Regards,
Bin
PATCH 6/6 riscv: ax25: use CCTL to flush d-cache
Hi Rick,
Quoted 53 lines · Rick Chen
Hi Bin
Quoted 34 lines
Hi Rick,
Quoted 30 lines · Andes
From: Rick Chen <[email protected]>
Use CCTL command to do d-cache write back and invalidate instead of fence.
Signed-off-by Rick Chen <[email protected]>Cc Greentime Hu <[email protected]>--- arch/riscv/cpu/ax25/cache.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-)arch/riscv/cpu/ax25/cache.c +9
-0@@ -5,17 +5,21 @@*/ #include <common.h> +#include <asm/csr.h> + +#ifdef CONFIG_RISCV_NDS_CACHE +/* mcctlcommand */ +#define CCTL_REG_MCCTLCOMMAND_NUM 0x7cc + +/* D-cache operation */ +#define CCTL_L1D_WBINVAL_ALL 6 +#endif Quoted 15 lines
arch/riscv/cpu/ax25/cache.c line 21
Quoted 12 lines
arch/riscv/cpu/ax25/cache.c +2
-8void flush_dcache_all (void ) { -/* -* Andes' AX25 does not have a coherence agent. U-Boot must use data -* cache flush and invalidate functions to keep data in the system -* coherent. -* The implementation of the fence instruction in the AX25 flushes the -* data cache and is used for this purpose. -*/ - asmvolatile ("fence" :::"memory" ); +#ifdef CONFIG_RISCV_NDS_CACHE +csr_write (CCTL_REG_MCCTLCOMMAND_NUM ,CCTL_L1D_WBINVAL_ALL );I think
CCTL_REG_MCCTLCOMMAND_NUMis a vendor specific CSR. Does upstream GCC support this CSR?
Quoted 3 lines
Yes. It is a vendor specific CSR. Upstream GCC shall not support it. So I isolate it by
CONFIG_RISCV_NDS_CACHE.
OK, but I suspect you will need do something for the travis build since upstream gcc is used?
Regards,
Bin
Auer
PATCH 6/6 riscv: ax25: use CCTL to flush d-cache
Hi Rick,
Quoted 53 lines · Bin Meng
Hi Rick,
Quoted 50 lines · Rick Chen
Hi Bin
Quoted 47 lines
Hi Rick,
Quoted 31 lines · Andes
From: Rick Chen <[email protected]>
Use CCTL command to do d-cache write back and invalidate instead of fence.
Signed-off-by Rick Chen <[email protected]>Cc Greentime Hu <[email protected]>--- arch/riscv/cpu/ax25/cache.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-)arch/riscv/cpu/ax25/cache.c +9
-0@@ -5,17 +5,21 @@*/ #include <common.h> +#include <asm/csr.h> + +#ifdef CONFIG_RISCV_NDS_CACHE +/* mcctlcommand */ +#define CCTL_REG_MCCTLCOMMAND_NUM 0x7cc + +/* D-cache operation */ +#define CCTL_L1D_WBINVAL_ALL 6 +#endif void flush_dcache_all (void ) {arch/riscv/cpu/ax25/cache.c line 21
Quoted 10 lines
arch/riscv/cpu/ax25/cache.c +2
-8-/* -* Andes' AX25 does not have a coherence agent. U-Boot must use data -* cache flush and invalidate functions to keep data in the system -* coherent. -* The implementation of the fence instruction in the AX25 flushes the -* data cache and is used for this purpose. -*/ - asmvolatile ("fence" :::"memory" ); +#ifdef CONFIG_RISCV_NDS_CACHE +csr_write (CCTL_REG_MCCTLCOMMAND_NUM ,CCTL_L1D_WBINVAL_ALL );I think
CCTL_REG_MCCTLCOMMAND_NUMis a vendor specific CSR. Does upstream GCC support this CSR?
Quoted 7 lines
Quoted 3 lines
Yes. It is a vendor specific CSR. Upstream GCC shall not support it. So I isolate it by
CONFIG_RISCV_NDS_CACHE.OK, but I suspect you will need do something for the travis build since upstream gcc is used?
How about using the CSR address instead of the name? This way the board can be built in Travis.
Thanks,
Lukas