Support Andes RISC-V l2cache on AE350 platform
Subsystems (2)
v4 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
Changes in v4:
- Remove definitions of v5l2cache.h to cache-v5l2.c
Changes in v3:
- Add the enable/disable in sandbox_cache.c.
- Parse dtb data in v5l2_ofdata_to_platdata() and configure HW in v5l2_probe().
- Move cache_disable() into dcache_disable() of cache.c
Changes in v2:
- Add new patch [1/7] to support dm cache uclass enable and disable ops.
- Use ofdata_to_platdata() to parse and save register base instead of global data.
- Rename compatible string of "cache" as "v5l2cache".
- make v512_init() return void.
- Use dm cache uclass api to disable L2 cache.
Rick Chen (8):
dm: cache: Add enable and disable ops for cache uclass
dm: cache: Add enable and disable ops for sandbox and test
dm: cache: add v5l2 cache controller driver
riscv: ae350: use the v5l2 driver to configure the cache
riscv: ax25: 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: cache: use CCTL to flush d-cache
arch/riscv/cpu/ax25/Kconfig | 1 + arch/riscv/cpu/ax25/cache.c | 39 +++++-- arch/riscv/dts/ae350_32.dts | 17 +-- arch/riscv/dts/ae350_64.dts | 17 +-- board/AndesTech/ax25-ae350/ax25-ae350.c | 9 ++ drivers/cache/Kconfig | 9 ++ drivers/cache/Makefile | 1 + drivers/cache/cache-uclass.c | 20 ++++ drivers/cache/cache-v5l2.c | 186 ++++++++++++++++++++++++++++++++ drivers/cache/sandbox_cache.c | 13 +++ include/cache.h | 31 ++++++ test/dm/cache.c | 2 + 12 files changed, 324 insertions(+), 21 deletions(-) create mode 100644 drivers/cache/cache-v5l2.c
Signature · 1 line
2.7.4
PATCH v4 1/8 dm: cache: Add enable and disable ops for cache uclass
From: Rick Chen <[email protected]>
Add cache enable/disable ops to the DM cache uclass driver
--- drivers/cache/cache-uclass.c | 20 ++++++++++++++++++++ include/cache.h | 31 +++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+)
drivers/cache/cache-uclass.c +20 -0
@@ -17,6 +17,26 @@ int cache_get_info(struct udevice *dev, struct cache_info *info)return ops->get_info (dev, info); } +int cache_enable (struct udevice *dev) +{ +struct cache_ops *ops =cache_get_ops (dev); + +if (!ops->enable) +return -ENOSYS ; + +return ops->enable (dev); +} + +int cache_disable (struct udevice *dev) +{ +struct cache_ops *ops =cache_get_ops (dev); + +if (!ops->disable) +return -ENOSYS ; + +return ops->disable (dev); +} +UCLASS_DRIVER (cache) = { .id =UCLASS_CACHE , .name ="cache" ,
include/cache.h +31 -0
@@ -22,6 +22,22 @@ struct cache_ops {* @return 0 if OK, -ve on error */ int (*get_info)(struct udevice *dev,struct cache_info *info); + +/** +* enable() - Enable cache +* +* @dev: Device to check (UCLASS_CACHE) +* @return 0 if OK, -ve on error +*/ +int (*enable)(struct udevice *dev); + +/** +* disable() - Flush and disable cache +* +* @dev: Device to check (UCLASS_CACHE) +* @return 0 if OK, -ve on error +*/ +int (*disable)(struct udevice *dev); };#define cache_get_ops (dev) ((struct cache_ops *)(dev)->driver->ops)
@@ -35,4 +51,19 @@ struct cache_ops {*/ int cache_get_info (struct udevice *dev,struct cache_info *info); +/** +* cache_enable() - Enable cache +* +* @dev: Device to check (UCLASS_CACHE) +* @return 0 if OK, -ve on error +*/ +int cache_enable (struct udevice *dev); + +/** +* cache_disable() - Flush and disable cache +* +* @dev: Device to check (UCLASS_CACHE) +* @return 0 if OK, -ve on error +*/ +int cache_disable (struct udevice *dev);#endif
Signature · 1 line
2.7.4
PATCH v4 2/8 dm: cache: Add enable and disable ops for sandbox and test
In reply to AndesFrom: Rick Chen <[email protected]>
Add cache enable and disable ops for test coverage.
--- drivers/cache/sandbox_cache.c | 13 +++++++++++++ test/dm/cache.c | 2 ++ 2 files changed, 15 insertions(+)
drivers/cache/sandbox_cache.c +13 -0
@@ -17,8 +17,21 @@ static int sandbox_get_info(struct udevice *dev, struct cache_info *info)return 0 ; } +static int sandbox_enable (struct udevice *dev) +{ +return 0 ; +} + +static int snadbox_disable (struct udevice *dev) +{ +return 0 ; +} + +static const struct cache_ops sandbox_cache_ops = { .get_info = sandbox_get_info, + .enable = sandbox_enable, + .disable = snadbox_disable, };static const struct udevice_id sandbox_cache_ids[] = {
test/dm/cache.c +2 -0
@@ -14,6 +14,8 @@ static int dm_test_reset(struct unit_test_state *uts)ut_assertok (uclass_get_device (UCLASS_CACHE ,0 , &dev_cache));ut_assertok (cache_get_info (dev, &info)); +ut_assertok (cache_enable (dev)); +ut_assertok (cache_disable (dev));return 0 ; }
Signature · 1 line
2.7.4
PATCH v4 3/8 dm: cache: add v5l2 cache controller driver
In reply to AndesFrom: 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.
--- drivers/cache/Kconfig | 9 +++ drivers/cache/Makefile | 1 + drivers/cache/cache-v5l2.c | 186 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 196 insertions(+) create mode 100644 drivers/cache/cache-v5l2.c
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 + bool "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 +186 -0
186 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v4 3/8 dm: cache: add v5l2 cache controller driver
Quoted 10 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.
Quoted 9 lines
Signed-off-by Rick Chen <[email protected]>Cc KC Lin <[email protected]>--- drivers/cache/Kconfig | 9 +++ drivers/cache/Makefile | 1 + drivers/cache/cache-v5l2.c | 186 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 196 insertions(+) create mode 100644 drivers/cache/cache-v5l2.c
PATCH v4 4/8 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 | 9 +++++++++ 1 file changed, 9 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,18 @@ int smc_init(void)return 0 ; } +static void v5l2_init (void ) +{ +struct udevice *dev; + +uclass_get_device (UCLASS_CACHE ,0 , &dev); +} +#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 v4 5/8 riscv: ax25: add imply v5l2 cache controller
In reply to AndesFrom: Rick Chen <[email protected]>
Select the v5l2 UCLASS_CACHE driver for ax25.
--- arch/riscv/cpu/ax25/Kconfig | 1 + 1 file changed, 1 insertion(+)
arch/riscv/cpu/ax25/Kconfig +1 -0
@@ -4,6 +4,7 @@ config RISCV_NDS imply CPU imply CPU_RISCV imply RISCV_TIMER + imply V5L2_CACHE imply ANDES_PLIC if RISCV_MMODE imply ANDES_PLMT if RISCV_MMODE help
Signature · 1 line
2.7.4
PATCH v4 6/8 riscv: cache: Flush L2 cache before jump to linux
In reply to AndesFrom: Rick Chen <[email protected]>
Flush and disable L2 cache in dcache_disable() which will be called in cleanup_before_linux() before jump to linux.
The sequence will be preferred as below:
L1 flush -> L1 disable -> L2 flush -> L2 disable
--- arch/riscv/cpu/ax25/cache.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
arch/riscv/cpu/ax25/cache.c +17 -0
@@ -5,6 +5,9 @@*/ #include <common.h> +#include <dm.h> +#include <dm/uclass-internal.h> +#include <cache.h> void flush_dcache_all (void ) {
@@ -59,11 +62,18 @@ void dcache_enable(void) {#if !CONFIG_IS_ENABLED (SYS_DCACHE_OFF )#ifdef CONFIG_RISCV_NDS_CACHE +struct udevice *dev =NULL ; + asmvolatile ("csrr t1, mcache_ctl\n\t" "ori t0, t1, 0x2\n\t" "csrw mcache_ctl, t0\n\t" ); + +uclass_find_first_device (UCLASS_CACHE , &dev); + +if (dev) +cache_enable (dev);#endif #endif }
@@ -72,12 +82,19 @@ void dcache_disable(void) {#if !CONFIG_IS_ENABLED (SYS_DCACHE_OFF )#ifdef CONFIG_RISCV_NDS_CACHE +struct udevice *dev =NULL ; + asmvolatile ("fence\n\t" "csrr t1, mcache_ctl\n\t" "andi t0, t1, ~0x2\n\t" "csrw mcache_ctl, t0\n\t" ); + +uclass_find_first_device (UCLASS_CACHE , &dev); + +if (dev) +cache_disable (dev);#endif #endif }
Signature · 1 line
2.7.4
PATCH v4 7/8 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 = "v5l2cache"; + 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 = "v5l2cache"; + 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 v4 8/8 riscv: cache: 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
@@ -8,17 +8,21 @@#include <dm.h> #include <dm/uclass-internal.h> #include <cache.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)
@@ -84,8 +88,8 @@ void dcache_disable(void)#ifdef CONFIG_RISCV_NDS_CACHE struct udevice *dev =NULL ; +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