lib: sbi: Map/Unmap debug console shared memory buffers
authorHimanshu Chauhan <hchauhan@ventanamicro.com>
Wed, 12 Jul 2023 04:34:36 +0000 (10:04 +0530)
committerAnup Patel <anup@brainfault.org>
Thu, 13 Jul 2023 07:14:22 +0000 (12:44 +0530)
With Smepmp enabled, it is necessary for shared memory from
S/U mode to be mapped/unmapped before and after read/write
of the memory region. This patch maps the debug console
shared memory before accessing it.

Signed-off-by: Himanshu Chauhan <hchauhan@ventanamicro.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
lib/sbi/sbi_ecall_dbcn.c

index 8e687298a39e2c7c8ac08d97fe4da2c121596d3b..18cd6c8b5ccf12a0aafd97104e74baf29beacd2e 100644 (file)
@@ -14,6 +14,7 @@
 #include <sbi/sbi_ecall_interface.h>
 #include <sbi/sbi_trap.h>
 #include <sbi/riscv_asm.h>
+#include <sbi/sbi_hart.h>
 
 static int sbi_ecall_dbcn_handler(unsigned long extid, unsigned long funcid,
                                  const struct sbi_trap_regs *regs,
@@ -46,10 +47,12 @@ static int sbi_ecall_dbcn_handler(unsigned long extid, unsigned long funcid,
                                        regs->a1, regs->a0, smode,
                                        SBI_DOMAIN_READ|SBI_DOMAIN_WRITE))
                        return SBI_ERR_INVALID_PARAM;
+               sbi_hart_map_saddr(regs->a1, regs->a0);
                if (funcid == SBI_EXT_DBCN_CONSOLE_WRITE)
                        *out_val = sbi_nputs((const char *)regs->a1, regs->a0);
                else
                        *out_val = sbi_ngets((char *)regs->a1, regs->a0);
+               sbi_hart_unmap_saddr();
                return 0;
        case SBI_EXT_DBCN_CONSOLE_WRITE_BYTE:
                sbi_putc(regs->a0);