mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2026-02-27 18:01:45 +00:00
Add functions to enable/disable the cache. Signed-off-by: Ben Zong-You Xie <ben717@andestech.com> Link: https://lore.kernel.org/r/20251229071914.1451587-4-ben717@andestech.com Signed-off-by: Anup Patel <anup@brainfault.org>
58 lines
946 B
C
58 lines
946 B
C
/*
|
|
* 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);
|
|
}
|
|
|
|
int cache_enable(struct cache_device *dev, bool enable)
|
|
{
|
|
if (!dev)
|
|
return SBI_ENODEV;
|
|
|
|
if (!dev->ops || !dev->ops->cache_enable)
|
|
return SBI_ENOTSUPP;
|
|
|
|
return dev->ops->cache_enable(dev, enable);
|
|
}
|