public inbox for opensbi@lists.infradead.org
 help / color / mirror / Atom feed
From: Ben Zong-You Xie <ben717@andestech.com>
To: <opensbi@lists.infradead.org>
Subject: [PATCH 3/5] lib: utils/cache: add cache enable function
Date: Mon, 29 Dec 2025 15:19:12 +0800	[thread overview]
Message-ID: <20251229071914.1451587-4-ben717@andestech.com> (raw)
In-Reply-To: <20251229071914.1451587-1-ben717@andestech.com>

Add functions to enable/disable the cache.

Signed-off-by: Ben Zong-You Xie <ben717@andestech.com>
---
 include/sbi_utils/cache/cache.h          | 11 +++++++++++
 include/sbi_utils/cache/fdt_cmo_helper.h | 13 +++++++++++++
 lib/utils/cache/cache.c                  | 11 +++++++++++
 lib/utils/cache/fdt_cmo_helper.c         | 23 +++++++++++++++++++++++
 4 files changed, 58 insertions(+)

diff --git a/include/sbi_utils/cache/cache.h b/include/sbi_utils/cache/cache.h
index 70d9286f9a0a..de6cf50d1da6 100644
--- a/include/sbi_utils/cache/cache.h
+++ b/include/sbi_utils/cache/cache.h
@@ -19,6 +19,8 @@ struct cache_ops {
 	int (*warm_init)(struct cache_device *dev);
 	/** Flush entire cache **/
 	int (*cache_flush_all)(struct cache_device *dev);
+	/** Enable/Disable cache **/
+	int (*cache_enable)(struct cache_device *dev, bool enable);
 };
 
 struct cache_device {
@@ -66,4 +68,13 @@ int cache_add(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
diff --git a/include/sbi_utils/cache/fdt_cmo_helper.h b/include/sbi_utils/cache/fdt_cmo_helper.h
index a6a28db9ede2..8b3ec89b9c15 100644
--- a/include/sbi_utils/cache/fdt_cmo_helper.h
+++ b/include/sbi_utils/cache/fdt_cmo_helper.h
@@ -22,6 +22,19 @@ int fdt_cmo_private_flc_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
  *
diff --git a/lib/utils/cache/cache.c b/lib/utils/cache/cache.c
index 6bc3d10e9347..2810d5e9570c 100644
--- a/lib/utils/cache/cache.c
+++ b/lib/utils/cache/cache.c
@@ -44,3 +44,14 @@ int cache_flush_all(struct cache_device *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);
+}
diff --git a/lib/utils/cache/fdt_cmo_helper.c b/lib/utils/cache/fdt_cmo_helper.c
index d87bab76ca00..3ab8abe667ba 100644
--- a/lib/utils/cache/fdt_cmo_helper.c
+++ b/lib/utils/cache/fdt_cmo_helper.c
@@ -41,6 +41,29 @@ int fdt_cmo_llc_flush_all(void)
 	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)
 {
 	struct sbi_scratch *scratch;
-- 
2.34.1


-- 
opensbi mailing list
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

  parent reply	other threads:[~2025-12-29  7:19 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-29  7:19 [PATCH 0/5] Add hart state management and system suspend support for AE350 Ben Zong-You Xie
2025-12-29  7:19 ` [PATCH 1/5] lib: utils/hsm: factor out ATCSMU code into an HSM driver Ben Zong-You Xie
2025-12-29  7:19 ` [PATCH 2/5] platform: generic/andes: add CSR save and restore functions for AE350 platform Ben Zong-You Xie
2025-12-29  7:19 ` Ben Zong-You Xie [this message]
2025-12-29  7:19 ` [PATCH 4/5] lib: utils/cache: add Andes last level cache controller Ben Zong-You Xie
2025-12-29  7:19 ` [PATCH 5/5] lib: utils/suspend: add Andes ATCSMU suspend driver Ben Zong-You Xie
2026-02-11 15:59   ` Andrew Jones
2026-02-23  3:53     ` Ben Zong-You Xie
2026-02-11  6:24 ` [PATCH 0/5] Add hart state management and system suspend support for AE350 Anup Patel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251229071914.1451587-4-ben717@andestech.com \
    --to=ben717@andestech.com \
    --cc=opensbi@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox