mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2026-02-28 02:01:50 +00:00
lib: utils/cache: add cache enable function
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>
This commit is contained in:
committed by
Anup Patel
parent
85bff9cc16
commit
6d26b43c47
11
include/sbi_utils/cache/cache.h
vendored
11
include/sbi_utils/cache/cache.h
vendored
@@ -19,6 +19,8 @@ struct cache_ops {
|
|||||||
int (*warm_init)(struct cache_device *dev);
|
int (*warm_init)(struct cache_device *dev);
|
||||||
/** Flush entire cache **/
|
/** Flush entire cache **/
|
||||||
int (*cache_flush_all)(struct cache_device *dev);
|
int (*cache_flush_all)(struct cache_device *dev);
|
||||||
|
/** Enable/Disable cache **/
|
||||||
|
int (*cache_enable)(struct cache_device *dev, bool enable);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cache_device {
|
struct cache_device {
|
||||||
@@ -66,4 +68,13 @@ int cache_add(struct cache_device *dev);
|
|||||||
*/
|
*/
|
||||||
int cache_flush_all(struct cache_device *dev);
|
int cache_flush_all(struct cache_device *dev);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable/Disable the cache
|
||||||
|
*
|
||||||
|
* @param dev the cache to enable/disable
|
||||||
|
*
|
||||||
|
* @return 0 on success, or a negative error code on failure
|
||||||
|
*/
|
||||||
|
int cache_enable(struct cache_device *dev, bool enable);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
13
include/sbi_utils/cache/fdt_cmo_helper.h
vendored
13
include/sbi_utils/cache/fdt_cmo_helper.h
vendored
@@ -22,6 +22,19 @@ int fdt_cmo_private_flc_flush_all(void);
|
|||||||
*/
|
*/
|
||||||
int fdt_cmo_llc_flush_all(void);
|
int fdt_cmo_llc_flush_all(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable/Disable 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_enable(bool enable);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable/Disable the last level cache of the current hart
|
||||||
|
*
|
||||||
|
* @return 0 on success, or a negative error code on failure
|
||||||
|
*/
|
||||||
|
int fdt_cmo_llc_enable(bool enable);
|
||||||
/**
|
/**
|
||||||
* Initialize the cache devices for each hart
|
* Initialize the cache devices for each hart
|
||||||
*
|
*
|
||||||
|
|||||||
11
lib/utils/cache/cache.c
vendored
11
lib/utils/cache/cache.c
vendored
@@ -44,3 +44,14 @@ int cache_flush_all(struct cache_device *dev)
|
|||||||
|
|
||||||
return dev->ops->cache_flush_all(dev);
|
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);
|
||||||
|
}
|
||||||
|
|||||||
23
lib/utils/cache/fdt_cmo_helper.c
vendored
23
lib/utils/cache/fdt_cmo_helper.c
vendored
@@ -41,6 +41,29 @@ int fdt_cmo_llc_flush_all(void)
|
|||||||
return cache_flush_all(llc);
|
return cache_flush_all(llc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int fdt_cmo_private_flc_enable(bool enable)
|
||||||
|
{
|
||||||
|
struct cache_device *flc = get_hart_flc(sbi_scratch_thishart_ptr());
|
||||||
|
|
||||||
|
if (!flc || !flc->cpu_private)
|
||||||
|
return SBI_ENODEV;
|
||||||
|
|
||||||
|
return cache_enable(flc, enable);
|
||||||
|
}
|
||||||
|
|
||||||
|
int fdt_cmo_llc_enable(bool enable)
|
||||||
|
{
|
||||||
|
struct cache_device *llc = get_hart_flc(sbi_scratch_thishart_ptr());
|
||||||
|
|
||||||
|
if (!llc)
|
||||||
|
return SBI_ENODEV;
|
||||||
|
|
||||||
|
while (llc->next)
|
||||||
|
llc = llc->next;
|
||||||
|
|
||||||
|
return cache_enable(llc, enable);
|
||||||
|
}
|
||||||
|
|
||||||
static int fdt_cmo_cold_init(const void *fdt)
|
static int fdt_cmo_cold_init(const void *fdt)
|
||||||
{
|
{
|
||||||
struct sbi_scratch *scratch;
|
struct sbi_scratch *scratch;
|
||||||
|
|||||||
Reference in New Issue
Block a user