mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2025-11-22 19:01:33 +00:00
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. Signed-off-by: Nick Hu <nick.hu@sifive.com> Reviewed-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org> Link: https://lore.kernel.org/r/20251020-cache-upstream-v7-1-69a132447d8a@sifive.com Signed-off-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
9
lib/utils/cache/Kconfig
vendored
Normal file
9
lib/utils/cache/Kconfig
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
|
||||
menu "Cache Support"
|
||||
|
||||
config CACHE
|
||||
bool "Cache support"
|
||||
default n
|
||||
|
||||
endmenu
|
||||
46
lib/utils/cache/cache.c
vendored
Normal file
46
lib/utils/cache/cache.c
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* Copyright (c) 2025 SiFive Inc.
|
||||
*/
|
||||
|
||||
#include <sbi/sbi_error.h>
|
||||
#include <sbi_utils/cache/cache.h>
|
||||
|
||||
static SBI_LIST_HEAD(cache_list);
|
||||
|
||||
struct cache_device *cache_find(u32 id)
|
||||
{
|
||||
struct cache_device *dev;
|
||||
|
||||
sbi_list_for_each_entry(dev, &cache_list, node) {
|
||||
if (dev->id == id)
|
||||
return dev;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int cache_add(struct cache_device *dev)
|
||||
{
|
||||
if (!dev)
|
||||
return SBI_ENODEV;
|
||||
|
||||
if (cache_find(dev->id))
|
||||
return SBI_EALREADY;
|
||||
|
||||
sbi_list_add(&dev->node, &cache_list);
|
||||
|
||||
return SBI_OK;
|
||||
}
|
||||
|
||||
int cache_flush_all(struct cache_device *dev)
|
||||
{
|
||||
if (!dev)
|
||||
return SBI_ENODEV;
|
||||
|
||||
if (!dev->ops || !dev->ops->cache_flush_all)
|
||||
return SBI_ENOTSUPP;
|
||||
|
||||
return dev->ops->cache_flush_all(dev);
|
||||
}
|
||||
7
lib/utils/cache/objects.mk
vendored
Normal file
7
lib/utils/cache/objects.mk
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
#
|
||||
# Copyright (c) 2025 SiFive
|
||||
#
|
||||
|
||||
libsbiutils-objs-$(CONFIG_CACHE) += cache/cache.o
|
||||
Reference in New Issue
Block a user