diff options
| author | Xiang Wang <[email protected]> | 2019-11-26 16:06:29 +0530 |
|---|---|---|
| committer | Anup Patel <[email protected]> | 2019-11-26 16:06:29 +0530 |
| commit | c96cc03fcc2723fa007b65e5ae6fe2673ea41413 (patch) | |
| tree | 0ba08cbedbf6cefea45618ccdaf9180c27e9929c /include | |
| parent | 75f903dd78e2419057d04e14d6720fde764cbf78 (diff) | |
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 <[email protected]>
Signed-off-by: Anup Patel <[email protected]>
Diffstat (limited to 'include')
| -rw-r--r-- | include/sbi/riscv_asm.h | 16 | ||||
| -rw-r--r-- | include/sbi/sbi_platform.h | 40 |
2 files changed, 46 insertions, 10 deletions
diff --git a/include/sbi/riscv_asm.h b/include/sbi/riscv_asm.h index 4f12c03b..04502e1f 100644 --- a/include/sbi/riscv_asm.h +++ b/include/sbi/riscv_asm.h @@ -159,22 +159,18 @@ void csr_write_num(int csr_num, unsigned long val); __asm__ __volatile__("wfi" ::: "memory"); \ } while (0) -static inline int misa_extension(char ext) -{ - return csr_read(CSR_MISA) & (1 << (ext - 'A')); -} +/* Determine CPU extension, return non-zero support */ +int misa_extension(char ext); -static inline int misa_xlen(void) -{ - return ((long)csr_read(CSR_MISA) < 0) ? 64 : 32; -} +/* Get MXL field of misa, return -1 on error */ +int misa_xlen(void); static inline void misa_string(char *out, unsigned int out_sz) { - unsigned long i, val = csr_read(CSR_MISA); + unsigned long i; for (i = 0; i < 26; i++) { - if (val & (1 << i)) { + if (misa_extension('A' + i)) { *out = 'A' + i; out++; } diff --git a/include/sbi/sbi_platform.h b/include/sbi/sbi_platform.h index 01d4a854..beb2f237 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 |
