The cache uclass can enable and disable a cache controller, and disable() writes the cache back before turning it off. There is no way to write back and invalidate a cache while keeping it enabled, which flush_dcache_all() needs for an outer cache such as the Andes L2 cache.
Add an optional flush_all() operation and a cache_flush_all() wrapper, in the same style as cache_enable() and cache_disable(). Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Randolph Lin <[email protected]> --- drivers/cache/cache-uclass.c | 10 ++++++++++ include/cache.h | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/drivers/cache/cache-uclass.c b/drivers/cache/cache-uclass.c index 300e7bc86e1..b66dd500ee0 100644 --- a/drivers/cache/cache-uclass.c +++ b/drivers/cache/cache-uclass.c @@ -38,6 +38,16 @@ int cache_disable(struct udevice *dev) return ops->disable(dev); } +int cache_flush_all(struct udevice *dev) +{ + struct cache_ops *ops = cache_get_ops(dev); + + if (!ops->flush_all) + return -ENOSYS; + + return ops->flush_all(dev); +} + UCLASS_DRIVER(cache) = { .id = UCLASS_CACHE, .name = "cache", diff --git a/include/cache.h b/include/cache.h index 296ae3c8b48..08a820f7dd8 100644 --- a/include/cache.h +++ b/include/cache.h @@ -42,6 +42,14 @@ struct cache_ops { * @return 0 if OK, -ve on error */ int (*disable)(struct udevice *dev); + + /** + * flush_all() - Write back and invalidate the whole cache + * + * @dev: Device to check (UCLASS_CACHE) + * @return 0 if OK, -ve on error + */ + int (*flush_all)(struct udevice *dev); }; #define cache_get_ops(dev) ((struct cache_ops *)(dev)->driver->ops) @@ -70,4 +78,12 @@ int cache_enable(struct udevice *dev); * Return: 0 if OK, -ve on error */ int cache_disable(struct udevice *dev); + +/** + * cache_flush_all() - Write back and invalidate the whole cache + * + * @dev: Device to check (UCLASS_CACHE) + * Return: 0 if OK, -ve on error + */ +int cache_flush_all(struct udevice *dev); #endif -- 2.34.1
