diff mbox series

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

Message ID 20220317063615.20816-2-heinrich.schuchardt@canonical.com
State Accepted
Commit ca7e93fa9f6c417a2d260440ff4c0aaded259989
Delegated to: Andes
Headers show
Series cmd/sbi: add missing SBI information | expand

Commit Message

Heinrich Schuchardt March 17, 2022, 6:36 a.m. UTC
Provide library functions to read:

* machine vendor ID
* machine architecture ID
* machine implementation ID

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

Comments

Sean Anderson March 20, 2022, 7:32 p.m. UTC | #1
On 3/17/22 2:36 AM, Heinrich Schuchardt wrote:
> Provide library functions to read:
> 
> * machine vendor ID
> * machine architecture ID
> * machine implementation ID
> 
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
> ---
>   arch/riscv/include/asm/sbi.h |  3 ++
>   arch/riscv/lib/sbi.c         | 65 ++++++++++++++++++++++++++++++++++++
>   2 files changed, 68 insertions(+)
> 
> diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h
> index 76453121ea..81fcfe0b36 100644
> --- a/arch/riscv/include/asm/sbi.h
> +++ b/arch/riscv/include/asm/sbi.h
> @@ -155,6 +155,9 @@ long sbi_get_spec_version(void);
>   int sbi_get_impl_id(void);
>   int sbi_get_impl_version(long *version);
>   int sbi_probe_extension(int ext);
> +int sbi_get_mvendorid(long *mvendorid);
> +int sbi_get_marchid(long *marchid);
> +int sbi_get_mimpid(long *mimpid);
>   void sbi_srst_reset(unsigned long type, unsigned long reason);
>   
>   #endif
> diff --git a/arch/riscv/lib/sbi.c b/arch/riscv/lib/sbi.c
> index d427d1b29e..8724e3a460 100644
> --- a/arch/riscv/lib/sbi.c
> +++ b/arch/riscv/lib/sbi.c
> @@ -127,6 +127,71 @@ int sbi_probe_extension(int extid)
>   	return -ENOTSUPP;
>   }
>   
> +/**
> + * sbi_get_mvendorid() - get machine vendor ID
> + *
> + * @mimpid:	on return machine vendor ID
> + * Return:	0 on success
> + */
> +int sbi_get_mvendorid(long *mvendorid)
> +{
> +	struct sbiret ret;
> +
> +	ret = sbi_ecall(SBI_EXT_BASE, SBI_EXT_BASE_GET_MVENDORID,
> +			0, 0, 0, 0, 0, 0);
> +	if (ret.error)
> +		return -ENOTSUPP;
> +
> +	if (mvendorid)
> +		*mvendorid = ret.value;
> +
> +	return 0;
> +}
> +
> +/**
> + * sbi_get_marchid() - get machine architecture ID
> + *
> + * @mimpid:	on return machine architecture ID
> + * Return:	0 on success
> + */
> +int sbi_get_marchid(long *marchid)
> +{
> +	struct sbiret ret;
> +
> +	ret = sbi_ecall(SBI_EXT_BASE, SBI_EXT_BASE_GET_MARCHID,
> +			0, 0, 0, 0, 0, 0);
> +
> +	if (ret.error)
> +		return -ENOTSUPP;
> +
> +	if (marchid)
> +		*marchid = ret.value;
> +
> +	return 0;
> +}
> +
> +/**
> + * sbi_get_mimpid() - get machine implementation ID
> + *
> + * @mimpid:	on return machine implementation ID
> + * Return:	0 on success
> + */
> +int sbi_get_mimpid(long *mimpid)
> +{
> +	struct sbiret ret;
> +
> +	ret = sbi_ecall(SBI_EXT_BASE, SBI_EXT_BASE_GET_MIMPID,
> +			0, 0, 0, 0, 0, 0);
> +
> +	if (ret.error)
> +		return -ENOTSUPP;
> +
> +	if (mimpid)
> +		*mimpid = ret.value;
> +
> +	return 0;
> +}
> +
>   /**
>    * sbi_srst_reset() - invoke system reset extension
>    *
> 

Perhaps this could be rewritten like

int sbi_get_mimpid(long *mimpid)
{
	return sbi_base_get_info(mimpid, SBI_EXT_BASE_GET_MIMPID);
}

where sbi_base_get_info is common to all 6 of the generic "get info" functions.

The current implementation is fine as well.

Reviewed-by: Sean Anderson <seanga2@gmail.com>
diff mbox series

Patch

diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h
index 76453121ea..81fcfe0b36 100644
--- a/arch/riscv/include/asm/sbi.h
+++ b/arch/riscv/include/asm/sbi.h
@@ -155,6 +155,9 @@  long sbi_get_spec_version(void);
 int sbi_get_impl_id(void);
 int sbi_get_impl_version(long *version);
 int sbi_probe_extension(int ext);
+int sbi_get_mvendorid(long *mvendorid);
+int sbi_get_marchid(long *marchid);
+int sbi_get_mimpid(long *mimpid);
 void sbi_srst_reset(unsigned long type, unsigned long reason);
 
 #endif
diff --git a/arch/riscv/lib/sbi.c b/arch/riscv/lib/sbi.c
index d427d1b29e..8724e3a460 100644
--- a/arch/riscv/lib/sbi.c
+++ b/arch/riscv/lib/sbi.c
@@ -127,6 +127,71 @@  int sbi_probe_extension(int extid)
 	return -ENOTSUPP;
 }
 
+/**
+ * sbi_get_mvendorid() - get machine vendor ID
+ *
+ * @mimpid:	on return machine vendor ID
+ * Return:	0 on success
+ */
+int sbi_get_mvendorid(long *mvendorid)
+{
+	struct sbiret ret;
+
+	ret = sbi_ecall(SBI_EXT_BASE, SBI_EXT_BASE_GET_MVENDORID,
+			0, 0, 0, 0, 0, 0);
+	if (ret.error)
+		return -ENOTSUPP;
+
+	if (mvendorid)
+		*mvendorid = ret.value;
+
+	return 0;
+}
+
+/**
+ * sbi_get_marchid() - get machine architecture ID
+ *
+ * @mimpid:	on return machine architecture ID
+ * Return:	0 on success
+ */
+int sbi_get_marchid(long *marchid)
+{
+	struct sbiret ret;
+
+	ret = sbi_ecall(SBI_EXT_BASE, SBI_EXT_BASE_GET_MARCHID,
+			0, 0, 0, 0, 0, 0);
+
+	if (ret.error)
+		return -ENOTSUPP;
+
+	if (marchid)
+		*marchid = ret.value;
+
+	return 0;
+}
+
+/**
+ * sbi_get_mimpid() - get machine implementation ID
+ *
+ * @mimpid:	on return machine implementation ID
+ * Return:	0 on success
+ */
+int sbi_get_mimpid(long *mimpid)
+{
+	struct sbiret ret;
+
+	ret = sbi_ecall(SBI_EXT_BASE, SBI_EXT_BASE_GET_MIMPID,
+			0, 0, 0, 0, 0, 0);
+
+	if (ret.error)
+		return -ENOTSUPP;
+
+	if (mimpid)
+		*mimpid = ret.value;
+
+	return 0;
+}
+
 /**
  * sbi_srst_reset() - invoke system reset extension
  *