summaryrefslogtreecommitdiff
path: root/include/sbi/sbi_platform.h
diff options
context:
space:
mode:
authorXiang Wang <merle@hardenedlinux.org>2019-11-26 13:36:29 +0300
committerAnup Patel <anup@brainfault.org>2019-11-26 13:36:29 +0300
commitc96cc03fcc2723fa007b65e5ae6fe2673ea41413 (patch)
tree0ba08cbedbf6cefea45618ccdaf9180c27e9929c /include/sbi/sbi_platform.h
parent75f903dd78e2419057d04e14d6720fde764cbf78 (diff)
downloadopensbi-c96cc03fcc2723fa007b65e5ae6fe2673ea41413.tar.xz
lib: Fix CPU capabilities detection function
On some platforms, misa may not be implemented. On such a platform, reading misa will get 0. At this time, platform is required to implement a non-standard function to detect the CPU's capabilities. Therefore, this modification add interfaces for non-standard function. The MXL field of misa is always at the highest two bits, whether it is a 32-bit 64-bit or a 128-bit machine. Therefore, this modification fixes the use of a fixed offset to detect the machine length. Signed-off-by: Xiang Wang <merle@hardenedlinux.org> Signed-off-by: Anup Patel <anup.patel@wdc.com>
Diffstat (limited to 'include/sbi/sbi_platform.h')
-rw-r--r--include/sbi/sbi_platform.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/include/sbi/sbi_platform.h b/include/sbi/sbi_platform.h
index 01d4a85..beb2f23 100644
--- a/include/sbi/sbi_platform.h
+++ b/include/sbi/sbi_platform.h
@@ -76,6 +76,16 @@ struct sbi_platform_operations {
/** Platform final initialization */
int (*final_init)(bool cold_boot);
+ /** For platforms that do not implement misa, non-standard
+ * methods are needed to determine cpu extension.
+ */
+ int (*misa_check_extension)(char ext);
+
+ /** For platforms that do not implement misa, non-standard
+ * methods are needed to get MXL field of misa.
+ */
+ int (*misa_get_xlen)(void);
+
/** Get number of PMP regions for given HART */
u32 (*pmp_region_count)(u32 hartid);
/**
@@ -292,6 +302,36 @@ static inline int sbi_platform_final_init(const struct sbi_platform *plat,
}
/**
+ * Check CPU extension in MISA
+ *
+ * @param plat pointer to struct sbi_platform
+ * @param ext shorthand letter for CPU extensions
+ *
+ * @return zero for not-supported and non-zero for supported
+ */
+static inline int sbi_platform_misa_extension(const struct sbi_platform *plat,
+ char ext)
+{
+ if (plat && sbi_platform_ops(plat)->misa_check_extension)
+ return sbi_platform_ops(plat)->misa_check_extension(ext);
+ return 0;
+}
+
+/**
+ * Get MXL field of MISA
+ *
+ * @param plat pointer to struct sbi_platform
+ *
+ * @return 1/2/3 on success and error code on failure
+ */
+static inline int sbi_platform_misa_xlen(const struct sbi_platform *plat)
+{
+ if (plat && sbi_platform_ops(plat)->misa_get_xlen)
+ return sbi_platform_ops(plat)->misa_get_xlen();
+ return -1;
+}
+
+/**
* Get the number of PMP regions of a HART
*
* @param plat pointer to struct sbi_platform