riscv: provide missing base extension functions
authorHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Thu, 17 Mar 2022 06:36:14 +0000 (07:36 +0100)
committerLeo Yu-Chi Liang <ycliang@andestech.com>
Wed, 6 Apr 2022 01:40:05 +0000 (09:40 +0800)
Provide library functions to read:

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

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Sean Anderson <seanga2@gmail.com>
arch/riscv/include/asm/sbi.h
arch/riscv/lib/sbi.c

index 7645312..81fcfe0 100644 (file)
@@ -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
index d427d1b..8724e3a 100644 (file)
@@ -128,6 +128,71 @@ int sbi_probe_extension(int extid)
 }
 
 /**
+ * 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
  *
  * @type:      type of reset