From 6590a7dab9d7182b659a13338043889350d9c6bb Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Thu, 12 Dec 2019 07:00:59 +0530 Subject: [PATCH] lib: Delegate guest page faults to HS-mode As-per RISC-V hypervisor v0.5 spec, we have new guest page faults which need to be delegated to HS-mode. Also, we can have bits in in MIDELEG and MEDELEG hardwired to 1 which means we need to fix the sainty check on these CSRs at the end of delegate_traps() function. Signed-off-by: Anup Patel Reviewed-by: Alistair Francis --- lib/sbi/sbi_hart.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index dee2e216..493e7fcb 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -88,19 +88,25 @@ static int delegate_traps(struct sbi_scratch *scratch, u32 hartid) (1U << CAUSE_STORE_PAGE_FAULT); /* - * If hypervisor extension available then we only handle - * hypervisor calls (i.e. ecalls from HS-mode) and we let - * HS-mode handle supervisor calls (i.e. ecalls from VS-mode) + * If hypervisor extension available then we only handle hypervisor + * calls (i.e. ecalls from HS-mode) in M-mode. + * + * The HS-mode will additionally handle supervisor calls (i.e. ecalls + * from VS-mode), Guest page faults and Virtual interrupts. */ - if (misa_extension('H')) + if (misa_extension('H')) { exceptions |= (1U << CAUSE_SUPERVISOR_ECALL); + exceptions |= (1U << CAUSE_FETCH_GUEST_PAGE_FAULT); + exceptions |= (1U << CAUSE_LOAD_GUEST_PAGE_FAULT); + exceptions |= (1U << CAUSE_STORE_GUEST_PAGE_FAULT); + } csr_write(CSR_MIDELEG, interrupts); csr_write(CSR_MEDELEG, exceptions); - if (csr_read(CSR_MIDELEG) != interrupts) + if ((csr_read(CSR_MIDELEG) & interrupts) != interrupts) return SBI_EFAIL; - if (csr_read(CSR_MEDELEG) != exceptions) + if ((csr_read(CSR_MEDELEG) & exceptions) != exceptions) return SBI_EFAIL; return 0;