[PATCH 1/2] riscv: provide missing base extension functions

Heinrich Schuchardt xypron.glpk at gmx.de
Mon Jul 19 22:28:34 CEST 2021


Provide library functions to read:

* SBI implementation version
* machine vendor ID
* machine architecture ID
* machine implementation ID

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt at canonical.com>
---
 arch/riscv/include/asm/sbi.h |  4 ++
 arch/riscv/lib/sbi.c         | 71 ++++++++++++++++++++++++++++++++++++
 2 files changed, 75 insertions(+)

diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h
index 53ca316180..262cc9228c 100644
--- a/arch/riscv/include/asm/sbi.h
+++ b/arch/riscv/include/asm/sbi.h
@@ -117,6 +117,10 @@ void sbi_remote_sfence_vma_asid(const unsigned long *hart_mask,
 void sbi_set_timer(uint64_t stime_value);
 long sbi_get_spec_version(void);
 int sbi_get_impl_id(void);
+long sbi_get_impl_version(void);
 int sbi_probe_extension(int ext);
+long sbi_get_mvendorid(void);
+long sbi_get_marchid(void);
+long sbi_get_mimpid(void);

 #endif
diff --git a/arch/riscv/lib/sbi.c b/arch/riscv/lib/sbi.c
index 77845a73ca..8b8b4b278f 100644
--- a/arch/riscv/lib/sbi.c
+++ b/arch/riscv/lib/sbi.c
@@ -89,6 +89,23 @@ int sbi_get_impl_id(void)
 	return -ENOTSUPP;
 }

+/**
+ * sbi_get_impl_version() - get SBI implementation version
+ *
+ * Return: implementation version
+ */
+long sbi_get_impl_version(void)
+{
+	struct sbiret ret;
+
+	ret = sbi_ecall(SBI_EXT_BASE, SBI_EXT_BASE_GET_IMP_VERSION,
+			0, 0, 0, 0, 0, 0);
+	if (!ret.error)
+		return ret.value;
+
+	return -ENOTSUPP;
+}
+
 /**
  * sbi_probe_extension() - Check if an SBI extension ID is supported or not.
  * @extid: The extension ID to be probed.
@@ -108,6 +125,60 @@ int sbi_probe_extension(int extid)
 	return -ENOTSUPP;
 }

+/**
+ * sbi_get_mvendorid() - get machine vendor ID
+ *
+ * Return: implementation vendor ID
+ */
+long sbi_get_mvendorid(void)
+{
+	struct sbiret ret;
+
+	ret = sbi_ecall(SBI_EXT_BASE, SBI_EXT_BASE_GET_MVENDORID,
+			0, 0, 0, 0, 0, 0);
+	if (!ret.error)
+		if (ret.value)
+			return ret.value;
+
+	return -ENOTSUPP;
+}
+
+/**
+ * sbi_get_marchid() - get machine architecture ID
+ *
+ * Return: implementation version
+ */
+long sbi_get_marchid(void)
+{
+	struct sbiret ret;
+
+	ret = sbi_ecall(SBI_EXT_BASE, SBI_EXT_BASE_GET_MARCHID,
+			0, 0, 0, 0, 0, 0);
+	if (!ret.error)
+		if (ret.value)
+			return ret.value;
+
+	return -ENOTSUPP;
+}
+
+/**
+ * sbi_get_mimpid() - get machine implementation ID
+ *
+ * Return: machine implementation ID
+ */
+long sbi_get_mimpid(void)
+{
+	struct sbiret ret;
+
+	ret = sbi_ecall(SBI_EXT_BASE, SBI_EXT_BASE_GET_MIMPID,
+			0, 0, 0, 0, 0, 0);
+	if (!ret.error)
+		if (ret.value)
+			return ret.value;
+
+	return -ENOTSUPP;
+}
+
 #ifdef CONFIG_SBI_V01

 /**
--
2.30.2



More information about the U-Boot mailing list