summaryrefslogtreecommitdiff
path: root/include/sbi_utils
diff options
context:
space:
mode:
authorNick Hu <[email protected]>2025-10-20 14:34:03 +0800
committerAnup Patel <[email protected]>2025-10-28 10:39:59 +0530
commit1207c7568fbe07714e3b75f9ebf25d7ed21612fe (patch)
tree255f21949a307234bebe0b20ada6abcb75b8737e /include/sbi_utils
parentac16c6b604961525bb096c0513c6ad4dbf5a5695 (diff)
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 <[email protected]> Reviewed-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Anup Patel <[email protected]>
Diffstat (limited to 'include/sbi_utils')
-rw-r--r--include/sbi_utils/cache/cache.h69
1 files changed, 69 insertions, 0 deletions
diff --git a/include/sbi_utils/cache/cache.h b/include/sbi_utils/cache/cache.h
new file mode 100644
index 00000000..70d9286f
--- /dev/null
+++ b/include/sbi_utils/cache/cache.h
@@ -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