Support external CMO to flush entire cache
v2 cover Support external CMO to flush entire cache
Some features, such as power management, may require flushing the entire cache before entering a non-retention power state. To support this, a simple cache framework is introduced to allow the external CMO to perform a full cache flush.
Changes in v2:
- Since the platform override hooks was deprecated, use the fdt_driver for initializing the sifive_dev_platform.
Nick Hu (3):
lib: utils: Add cache flush library
lib: utils: Add FDT cache library
lib: utils/cache: Add fdt cmo helpers
Vincent Chen (2):
utils: cache: Add SiFive ccache controller
platform: generic: Add SiFive development platform
include/sbi_utils/cache/cache.h | 69 +++++++ include/sbi_utils/cache/fdt_cache.h | 34 ++++ include/sbi_utils/cache/fdt_cmo_helper.h | 34 ++++ lib/utils/Kconfig | 2 + lib/utils/cache/Kconfig | 23 +++ lib/utils/cache/cache.c | 46 +++++ lib/utils/cache/fdt_cache.c | 87 +++++++++ lib/utils/cache/fdt_cache_drivers.carray | 3 + lib/utils/cache/fdt_cmo_helper.c | 112 +++++++++++ lib/utils/cache/fdt_sifive_ccache.c | 175 ++++++++++++++++++ lib/utils/cache/objects.mk | 14 ++ platform/generic/Kconfig | 5 + platform/generic/configs/defconfig | 3 + platform/generic/sifive/objects.mk | 3 + platform/generic/sifive/sifive_dev_platform.c | 42 +++++ 15 files changed, 652 insertions(+) create mode 100644 include/sbi_utils/cache/cache.h create mode 100644 include/sbi_utils/cache/fdt_cache.h create mode 100644 include/sbi_utils/cache/fdt_cmo_helper.h create mode 100644 lib/utils/cache/Kconfig create mode 100644 lib/utils/cache/cache.c create mode 100644 lib/utils/cache/fdt_cache.c create mode 100644 lib/utils/cache/fdt_cache_drivers.carray create mode 100644 lib/utils/cache/fdt_cmo_helper.c create mode 100644 lib/utils/cache/fdt_sifive_ccache.c create mode 100644 lib/utils/cache/objects.mk create mode 100644 platform/generic/sifive/sifive_dev_platform.c
Signature · 7 lines
2.17.1 -- opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi
PATCH v2 1/5 lib: utils: Add cache flush library
The current RISC-V CMO only defines how to flush a cache block. However, certain use cases, such as power management, may require flushing the entire cache. Therefore, a framework is being introduced to allow vendors to flush the entire cache using their own methods.
--- include/sbi_utils/cache/cache.h | 69 +++++++++++++++++++++++++++++++++ lib/utils/Kconfig | 2 + lib/utils/cache/Kconfig | 9 +++++ lib/utils/cache/cache.c | 46 ++++++++++++++++++++++ lib/utils/cache/objects.mk | 7 ++++ 5 files changed, 133 insertions(+) create mode 100644 include/sbi_utils/cache/cache.h create mode 100644 lib/utils/cache/Kconfig create mode 100644 lib/utils/cache/cache.c create mode 100644 lib/utils/cache/objects.mk
include/sbi_utils/cache/cache.h new file +69 -0
@@ -0,0 +1,69 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* Copyright (c) 2025 SiFive Inc. +*/ + +#ifndef __CACHE_H__ +#define __CACHE_H__ + +#include <sbi/sbi_list.h> +#include <sbi/sbi_types.h> + +#define CACHE_NAME_LEN 32 + +struct cache_device ; + +struct cache_ops { +/** Warm init **/ +int (*warm_init)(struct cache_device *dev); +/** Flush entire cache **/ +int (*cache_flush_all)(struct cache_device *dev); +}; + +struct cache_device { +/** Name of the device **/ +char name[CACHE_NAME_LEN ]; +/** List node for search **/ +struct sbi_dlist node; +/** Point to the next level cache **/ +struct cache_device *next; +/** Cache Management Operations **/ +struct cache_ops *ops; +/** CPU private cache **/ +bool cpu_private; +/** The unique id of this cache device **/ +u32 id; +}; + +/** +* Find a registered cache device +* +* @param id unique ID of the cache device +* +* @return the cache device or NULL +*/ +struct cache_device *cache_find (u32 id); + +/** +* Register a cache device +* +* cache_device->id must be initialized already and must not change during the life +* of the cache_device object. +* +* @param dev the cache device to register +* +* @return 0 on success, or a negative error code on failure +*/ +int cache_add (struct cache_device *dev); + +/** +* Flush the entire cache +* +* @param dev the cache to flush +* +* @return 0 on success, or a negative error code on failure +*/ +int cache_flush_all (struct cache_device *dev); + +#endif
lib/utils/Kconfig +2 -0
@@ -2,6 +2,8 @@ menu "Utils and Drivers Support" +source "$(OPENSBI_SRC_DIR)/lib/utils/cache/Kconfig" + source "$(OPENSBI_SRC_DIR)/lib/utils/cppc/Kconfig" source "$(OPENSBI_SRC_DIR)/lib/utils/fdt/Kconfig"
lib/utils/cache/Kconfig new file +9 -0
@@ -0,0 +1,9 @@ +# SPDX-License-Identifier: BSD-2-Clause + +menu "Cache Support" + +config CACHE + bool "Cache support" + default n + +endmenu
lib/utils/cache/cache.c new file +46 -0
46 lines not on this page · raw message
lib/utils/cache/objects.mk new file +7 -0
@@ -0,0 +1,7 @@ +# +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (c) 2025 SiFive +# + +libsbiutils-objs-$(CONFIG_CACHE) += cache/cache.o
Signature · 7 lines
2.17.1 -- opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi
PATCH v2 2/5 lib: utils: Add FDT cache library
In reply to Nick HuAdd the FDT cache library so we can build up the cache topology via the 'next-level-cache' DT property.
--- include/sbi_utils/cache/fdt_cache.h | 34 +++++++++ lib/utils/cache/Kconfig | 6 ++ lib/utils/cache/fdt_cache.c | 87 ++++++++++++++++++++++++ lib/utils/cache/fdt_cache_drivers.carray | 3 + lib/utils/cache/objects.mk | 3 + platform/generic/configs/defconfig | 1 + 6 files changed, 134 insertions(+) create mode 100644 include/sbi_utils/cache/fdt_cache.h create mode 100644 lib/utils/cache/fdt_cache.c create mode 100644 lib/utils/cache/fdt_cache_drivers.carray
include/sbi_utils/cache/fdt_cache.h new file +34 -0
@@ -0,0 +1,34 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* Copyright (c) 2025 SiFive Inc. +*/ + +#ifndef __FDT_CACHE_H__ +#define __FDT_CACHE_H__ + +#include <sbi_utils/cache/cache.h> + +/** +* Register a cache device using information from the DT +* +* @param fdt devicetree blob +* @param noff offset of a node in the devicetree blob +* @param dev cache device to register for this devicetree node +* +* @return 0 on success, or a negative error code on failure +*/ +int fdt_cache_add (const void *fdt,int noff,struct cache_device *dev); + +/** +* Get the cache device referencd by the "next-level-cache" property of a DT node +* +* @param fdt devicetree blob +* @param noff offset of a node in the devicetree blob +* @param out_dev location to return the cache device +* +* @return 0 on success, or a negative error code on failure +*/ +int fdt_next_cache_get (const void *fdt,int noff,struct cache_device **out_dev); + +#endif
lib/utils/cache/Kconfig +6 -0
@@ -2,6 +2,12 @@ menu "Cache Support" +config FDT_CACHE + bool "FDT based cache drivers" + depends on FDT + select CACHE + default n + config CACHE bool "Cache support" default n
lib/utils/cache/fdt_cache.c new file +87 -0
87 lines not on this page · raw message
lib/utils/cache/fdt_cache_drivers.carray new file +3 -0
@@ -0,0 +1,3 @@ +HEADER: sbi_utils/cache/fdt_cache.h +TYPE: const struct fdt_driver +NAME: fdt_cache_drivers
lib/utils/cache/objects.mk +3 -0
@@ -4,4 +4,7 @@ # Copyright (c) 2025 SiFive # +libsbiutils-objs-$(CONFIG_FDT_CACHE) += cache/fdt_cache.o +libsbiutils-objs-$(CONFIG_FDT_CACHE) += cache/fdt_cache_drivers.carray.o + libsbiutils-objs-$(CONFIG_CACHE) += cache/cache.o
platform/generic/configs/defconfig +1 -0
@@ -6,6 +6,7 @@ CONFIG_PLATFORM_SIFIVE_FU740=y CONFIG_PLATFORM_SOPHGO_SG2042=y CONFIG_PLATFORM_STARFIVE_JH7110=y CONFIG_PLATFORM_THEAD=y +CONFIG_FDT_CACHE=y CONFIG_FDT_CPPC=y CONFIG_FDT_CPPC_RPMI=y CONFIG_FDT_GPIO=y
Signature · 7 lines
2.17.1 -- opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi
PATCH v2 3/5 utils: cache: Add SiFive ccache controller
In reply to Nick HuFrom: Vincent Chen <[email protected]>
SiFive Composable cache is a L3 share cache of the core complex. Add this driver to support the share cache maintenance operations via the MMIO registers.
--- lib/utils/cache/Kconfig | 8 ++ lib/utils/cache/fdt_sifive_ccache.c | 175 ++++++++++++++++++++++++++++ lib/utils/cache/objects.mk | 3 + platform/generic/configs/defconfig | 1 + 4 files changed, 187 insertions(+) create mode 100644 lib/utils/cache/fdt_sifive_ccache.c
lib/utils/cache/Kconfig +8 -0
@@ -8,6 +8,14 @@ config FDT_CACHE select CACHE default n +if FDT_CACHE + +config FDT_CACHE_SIFIVE_CCACHE + bool "SiFive CCACHE FDT cache driver" + default n + +endif + config CACHE bool "Cache support" default n
lib/utils/cache/fdt_sifive_ccache.c new file +175 -0
175 lines not on this page · raw message
lib/utils/cache/objects.mk +3 -0
@@ -7,4 +7,7 @@ libsbiutils-objs-$(CONFIG_FDT_CACHE) += cache/fdt_cache.o libsbiutils-objs-$(CONFIG_FDT_CACHE) += cache/fdt_cache_drivers.carray.o +carray-fdt_cache_drivers-$(CONFIG_FDT_CACHE_SIFIVE_CCACHE) += fdt_sifive_ccache +libsbiutils-objs-$(CONFIG_FDT_CACHE_SIFIVE_CCACHE) += cache/fdt_sifive_ccache.o + libsbiutils-objs-$(CONFIG_CACHE) += cache/cache.o
platform/generic/configs/defconfig +1 -0
@@ -7,6 +7,7 @@ CONFIG_PLATFORM_SOPHGO_SG2042=y CONFIG_PLATFORM_STARFIVE_JH7110=y CONFIG_PLATFORM_THEAD=y CONFIG_FDT_CACHE=y +CONFIG_FDT_CACHE_SIFIVE_CCACHE=y CONFIG_FDT_CPPC=y CONFIG_FDT_CPPC_RPMI=y CONFIG_FDT_GPIO=y
Signature · 7 lines
2.17.1 -- opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi
PATCH v2 4/5 lib: utils/cache: Add fdt cmo helpers
In reply to Nick HuAdd the helpers to build up the cache hierarchy via FDT and provide some cmo functions for the user who want to flush the entire cache.
--- include/sbi_utils/cache/fdt_cmo_helper.h | 34 +++++++ lib/utils/cache/fdt_cmo_helper.c | 112 +++++++++++++++++++++++ lib/utils/cache/objects.mk | 1 + 3 files changed, 147 insertions(+) create mode 100644 include/sbi_utils/cache/fdt_cmo_helper.h create mode 100644 lib/utils/cache/fdt_cmo_helper.c
include/sbi_utils/cache/fdt_cmo_helper.h new file +34 -0
@@ -0,0 +1,34 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* Copyright (c) 2025 SiFive Inc. +*/ + +#ifndef __FDT_CMO_HELPER_H__ +#define __FDT_CMO_HELPER_H__ + +/** +* Flush the private first level cache of the current hart +* +* @return 0 on success, or a negative error code on failure +*/ +int fdt_cmo_private_flc_flush_all (void ); + +/** +* Flush the last level cache of the current hart +* +* @return 0 on success, or a negative error code on failure +*/ +int fdt_cmo_llc_flush_all (void ); + +/** +* Initialize the cache devices for each hart +* +* @param fdt devicetree blob +* @param cold_boot cold init or warm init +* +* @return 0 on success, or a negative error code on failure +*/ +int fdt_cmo_init (bool cold_boot); + +#endif
lib/utils/cache/fdt_cmo_helper.c new file +112 -0
112 lines not on this page · raw message
lib/utils/cache/objects.mk +1 -0
@@ -6,6 +6,7 @@ libsbiutils-objs-$(CONFIG_FDT_CACHE) += cache/fdt_cache.o libsbiutils-objs-$(CONFIG_FDT_CACHE) += cache/fdt_cache_drivers.carray.o +libsbiutils-objs-$(CONFIG_FDT_CACHE) += cache/fdt_cmo_helper.o carray-fdt_cache_drivers-$(CONFIG_FDT_CACHE_SIFIVE_CCACHE) += fdt_sifive_ccache libsbiutils-objs-$(CONFIG_FDT_CACHE_SIFIVE_CCACHE) += cache/fdt_sifive_ccache.o
Signature · 7 lines
2.17.1 -- opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi
PATCH v2 5/5 platform: generic: Add SiFive development platform
In reply to Nick HuFrom: Vincent Chen <[email protected]>
The sifive_dev_platform is a new platform which is compatible to the generic platform to place some features which are only for the SiFive development machine.
--- platform/generic/Kconfig | 5 +++ platform/generic/configs/defconfig | 1 + platform/generic/sifive/objects.mk | 3 ++ platform/generic/sifive/sifive_dev_platform.c | 41 +++++++++++++++++++ 4 files changed, 50 insertions(+) create mode 100644 platform/generic/sifive/sifive_dev_platform.c
platform/generic/Kconfig +5 -0
@@ -43,6 +43,11 @@ config PLATFORM_RENESAS_RZFIVE select ANDES_PMU default n +config PLATFORM_SIFIVE_DEV + bool "SiFive development platform support" + depends on FDT_CACHE + default n + config PLATFORM_SIFIVE_FU540 bool "SiFive FU540 support" default n
platform/generic/configs/defconfig +1 -0
@@ -1,6 +1,7 @@ CONFIG_PLATFORM_ALLWINNER_D1=y CONFIG_PLATFORM_ANDES_AE350=y CONFIG_PLATFORM_RENESAS_RZFIVE=y +CONFIG_PLATFORM_SIFIVE_DEV=y CONFIG_PLATFORM_SIFIVE_FU540=y CONFIG_PLATFORM_SIFIVE_FU740=y CONFIG_PLATFORM_SOPHGO_SG2042=y
platform/generic/sifive/objects.mk +3 -0
@@ -2,6 +2,9 @@ # SPDX-License-Identifier: BSD-2-Clause # +carray-platform_override_modules-$(CONFIG_PLATFORM_SIFIVE_DEV) += sifive_dev_platform +platform-objs-$(CONFIG_PLATFORM_SIFIVE_DEV) += sifive/sifive_dev_platform.o + carray-platform_override_modules-$(CONFIG_PLATFORM_SIFIVE_FU540) += sifive_fu540 platform-objs-$(CONFIG_PLATFORM_SIFIVE_FU540) += sifive/fu540.o
platform/generic/sifive/sifive_dev_platform.c new file +41 -0
41 lines not on this page · raw message
Signature · 7 lines
2.17.1 -- opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi
Hi
Any feedback about this?
Quoted 50 lines · Nick Hu
Some features, such as power management, may require flushing the entire cache before entering a non-retention power state. To support this, a simple cache framework is introduced to allow the external CMO to perform a full cache flush.
Changes in v2:
- Since the platform override hooks was deprecated, use thefdt_driverfor initializing thesifive_dev_platform.Nick Hu (3):
lib: utils: Add cache flush library
lib: utils: Add FDT cache library
lib: utils/cache: Add fdt cmo helpersVincent Chen (2):
utils: cache: Add SiFive ccache controller
platform: generic: Add SiFive development platforminclude/sbi_utils/cache/cache.h | 69 +++++++ include/sbi_utils/cache/fdt_cache.h | 34 ++++ include/sbi_utils/cache/fdt_cmo_helper.h | 34 ++++ lib/utils/Kconfig | 2 + lib/utils/cache/Kconfig | 23 +++ lib/utils/cache/cache.c | 46 +++++ lib/utils/cache/fdt_cache.c | 87 +++++++++ lib/utils/cache/fdt_cache_drivers.carray | 3 + lib/utils/cache/fdt_cmo_helper.c | 112 +++++++++++ lib/utils/cache/fdt_sifive_ccache.c | 175 ++++++++++++++++++ lib/utils/cache/objects.mk | 14 ++ platform/generic/Kconfig | 5 + platform/generic/configs/defconfig | 3 + platform/generic/sifive/objects.mk | 3 + platform/generic/sifive/sifive_dev_platform.c | 42 +++++ 15 files changed, 652 insertions(+) create mode 100644 include/sbi_utils/cache/cache.h create mode 100644 include/sbi_utils/cache/fdt_cache.h create mode 100644 include/sbi_utils/cache/fdt_cmo_helper.h create mode 100644 lib/utils/cache/Kconfig create mode 100644 lib/utils/cache/cache.c create mode 100644 lib/utils/cache/fdt_cache.c create mode 100644 lib/utils/cache/fdt_cache_drivers.carray create mode 100644 lib/utils/cache/fdt_cmo_helper.c create mode 100644 lib/utils/cache/fdt_sifive_ccache.c create mode 100644 lib/utils/cache/objects.mk create mode 100644 platform/generic/sifive/sifive_dev_platform.c--
2.17.1
Signature · 3 lines
opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi
Quoted 5 lines · Nick Hu
Some features, such as power management, may require flushing the entire cache before entering a non-retention power state. To support this, a simple cache framework is introduced to allow the external CMO to perform a full cache flush.
This series should also include patches which use the cache_xyz() APIs upon power management operations (e.g. suspend to RAM).
Regards,
Anup
Quoted 45 lines
Changes in v2:
- Since the platform override hooks was deprecated, use thefdt_driverfor initializing thesifive_dev_platform.Nick Hu (3):
lib: utils: Add cache flush library
lib: utils: Add FDT cache library
lib: utils/cache: Add fdt cmo helpersVincent Chen (2):
utils: cache: Add SiFive ccache controller
platform: generic: Add SiFive development platforminclude/sbi_utils/cache/cache.h | 69 +++++++ include/sbi_utils/cache/fdt_cache.h | 34 ++++ include/sbi_utils/cache/fdt_cmo_helper.h | 34 ++++ lib/utils/Kconfig | 2 + lib/utils/cache/Kconfig | 23 +++ lib/utils/cache/cache.c | 46 +++++ lib/utils/cache/fdt_cache.c | 87 +++++++++ lib/utils/cache/fdt_cache_drivers.carray | 3 + lib/utils/cache/fdt_cmo_helper.c | 112 +++++++++++ lib/utils/cache/fdt_sifive_ccache.c | 175 ++++++++++++++++++ lib/utils/cache/objects.mk | 14 ++ platform/generic/Kconfig | 5 + platform/generic/configs/defconfig | 3 + platform/generic/sifive/objects.mk | 3 + platform/generic/sifive/sifive_dev_platform.c | 42 +++++ 15 files changed, 652 insertions(+) create mode 100644 include/sbi_utils/cache/cache.h create mode 100644 include/sbi_utils/cache/fdt_cache.h create mode 100644 include/sbi_utils/cache/fdt_cmo_helper.h create mode 100644 lib/utils/cache/Kconfig create mode 100644 lib/utils/cache/cache.c create mode 100644 lib/utils/cache/fdt_cache.c create mode 100644 lib/utils/cache/fdt_cache_drivers.carray create mode 100644 lib/utils/cache/fdt_cmo_helper.c create mode 100644 lib/utils/cache/fdt_sifive_ccache.c create mode 100644 lib/utils/cache/objects.mk create mode 100644 platform/generic/sifive/sifive_dev_platform.c--
2.17.1
Signature · 3 lines
opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi
Quoted 11 lines · Anup Patel
Quoted 5 lines · Nick Hu
Some features, such as power management, may require flushing the entire cache before entering a non-retention power state. To support this, a simple cache framework is introduced to allow the external CMO to perform a full cache flush.
This series should also include patches which use the
cache_xyz()APIs upon power management operations (e.g. suspend to RAM).
Will add it in the next version. Thanks.
Quoted 48 lines
Regards,
AnupQuoted 45 lines
Changes in v2:
- Since the platform override hooks was deprecated, use thefdt_driverfor initializing thesifive_dev_platform.Nick Hu (3):
lib: utils: Add cache flush library
lib: utils: Add FDT cache library
lib: utils/cache: Add fdt cmo helpersVincent Chen (2):
utils: cache: Add SiFive ccache controller
platform: generic: Add SiFive development platforminclude/sbi_utils/cache/cache.h | 69 +++++++ include/sbi_utils/cache/fdt_cache.h | 34 ++++ include/sbi_utils/cache/fdt_cmo_helper.h | 34 ++++ lib/utils/Kconfig | 2 + lib/utils/cache/Kconfig | 23 +++ lib/utils/cache/cache.c | 46 +++++ lib/utils/cache/fdt_cache.c | 87 +++++++++ lib/utils/cache/fdt_cache_drivers.carray | 3 + lib/utils/cache/fdt_cmo_helper.c | 112 +++++++++++ lib/utils/cache/fdt_sifive_ccache.c | 175 ++++++++++++++++++ lib/utils/cache/objects.mk | 14 ++ platform/generic/Kconfig | 5 + platform/generic/configs/defconfig | 3 + platform/generic/sifive/objects.mk | 3 + platform/generic/sifive/sifive_dev_platform.c | 42 +++++ 15 files changed, 652 insertions(+) create mode 100644 include/sbi_utils/cache/cache.h create mode 100644 include/sbi_utils/cache/fdt_cache.h create mode 100644 include/sbi_utils/cache/fdt_cmo_helper.h create mode 100644 lib/utils/cache/Kconfig create mode 100644 lib/utils/cache/cache.c create mode 100644 lib/utils/cache/fdt_cache.c create mode 100644 lib/utils/cache/fdt_cache_drivers.carray create mode 100644 lib/utils/cache/fdt_cmo_helper.c create mode 100644 lib/utils/cache/fdt_sifive_ccache.c create mode 100644 lib/utils/cache/objects.mk create mode 100644 platform/generic/sifive/sifive_dev_platform.c--
2.17.1
Regard,
Nick
Signature · 3 lines
opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi