diff options
| author | Damien Le Moal <[email protected]> | 2018-12-21 09:13:37 +0900 |
|---|---|---|
| committer | Damien Le Moal <[email protected]> | 2018-12-21 15:09:13 +0900 |
| commit | aa68f0252f2a0749dee35bda309c397f79ae26a0 (patch) | |
| tree | 1edc7262e0c70f0a391abbc4c009e42f8a303aad /lib | |
| parent | f003787455709a1a6c69c1b6ab6a02d4d767c325 (diff) | |
Refine platform features control
Allow a platform to report its supported features in more details.
The new features defined are:
* SBI_PLATFORM_HAS_PMP
* SBI_PLATFORM_HAS_SCOUNTEREN
* SBI_PLATFORM_HAS_MCOUNTEREN
In addition, define the macro SBI_PLATFORM_DEFAULT_FEATURES as the set
of features that are generally expected to be supported by a Linux
capable platform.
Operations touching the features controlled with these falgs are not
executed if the platform does not set the corresponding feature flags.
Signed-off-by: Damien Le Moal <[email protected]>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/sbi_hart.c | 27 | ||||
| -rw-r--r-- | lib/sbi_init.c | 2 |
2 files changed, 18 insertions, 11 deletions
diff --git a/lib/sbi_hart.c b/lib/sbi_hart.c index a375ecf6..26d435bd 100644 --- a/lib/sbi_hart.c +++ b/lib/sbi_hart.c @@ -17,16 +17,20 @@ #include <sbi/sbi_hart.h> #include <sbi/sbi_platform.h> -static int mstatus_init(u32 hartid) +static void mstatus_init(struct sbi_scratch *scratch, u32 hartid) { + struct sbi_platform *plat = sbi_platform_ptr(scratch); + /* Enable FPU */ if (misa_extension('D') || misa_extension('F')) csr_write(mstatus, MSTATUS_FS); /* Enable user/supervisor use of perf counters */ - if (misa_extension('S')) + if (misa_extension('S') && + sbi_platform_has_scounteren(plat)) csr_write(scounteren, -1); - csr_write(mcounteren, -1); + if (sbi_platform_has_mcounteren(plat)) + csr_write(mcounteren, -1); /* Disable all interrupts */ csr_write(mie, 0); @@ -34,8 +38,6 @@ static int mstatus_init(u32 hartid) /* Disable S-mode paging */ if (misa_extension('S')) csr_write(sptbr, 0); - - return 0; } #ifdef __riscv_flen @@ -111,10 +113,14 @@ unsigned long log2roundup(unsigned long x) return ret; } -void sbi_hart_pmp_dump(void) +void sbi_hart_pmp_dump(struct sbi_scratch *scratch) { - unsigned int i; + struct sbi_platform *plat = sbi_platform_ptr(scratch); unsigned long prot, addr, size, l2l; + unsigned int i; + + if (!sbi_platform_has_pmp(plat)) + return; for (i = 0; i < PMP_COUNT; i++) { pmp_get(i, &prot, &addr, &l2l); @@ -149,6 +155,9 @@ static int pmp_init(struct sbi_scratch *scratch, u32 hartid) ulong prot, addr, log2size; struct sbi_platform *plat = sbi_platform_ptr(scratch); + if (!sbi_platform_has_pmp(plat)) + return 0; + fw_size_log2 = log2roundup(scratch->fw_size); fw_start = scratch->fw_start & ~((1UL << fw_size_log2) - 1UL); @@ -172,9 +181,7 @@ int sbi_hart_init(struct sbi_scratch *scratch, u32 hartid) { int rc; - rc = mstatus_init(hartid); - if (rc) - return rc; + mstatus_init(scratch, hartid); rc = fp_init(hartid); if (rc) diff --git a/lib/sbi_init.c b/lib/sbi_init.c index 82384b39..3e7bda35 100644 --- a/lib/sbi_init.c +++ b/lib/sbi_init.c @@ -91,7 +91,7 @@ static void __attribute__((noreturn)) init_coldboot(struct sbi_scratch *scratch, sbi_ecall_version_major(), sbi_ecall_version_minor()); sbi_printf("\n"); - sbi_hart_pmp_dump(); + sbi_hart_pmp_dump(scratch); sbi_hart_mark_available(hartid); |
