lib: utils/serial: Add shared regions for serial drivers
authorMayuresh Chitale <mchitale@ventanamicro.com>
Thu, 7 Sep 2023 11:49:46 +0000 (17:19 +0530)
committerAnup Patel <anup@brainfault.org>
Sun, 24 Sep 2023 11:34:41 +0000 (17:04 +0530)
The serial driver regions used by OpenSBI should be marked as a shared
read-write regions between M-mode and SU-mode as those are accessed
by earlycon and the corresponding tty serial drivers running in 'S' mode.
When the smepmp extension is enabled, PMP entries for these shared regions
will get programmed.

Signed-off-by: Mayuresh Chitale <mchitale@ventanamicro.com>
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
lib/utils/serial/cadence-uart.c
lib/utils/serial/fdt_serial_htif.c
lib/utils/serial/uart8250.c

index 8a2b6ba7a72d132adeabc488ec4c9533c14086f1..30fbb95f44534778dbc5c97f8411c51a7f7be14c 100644 (file)
@@ -6,6 +6,8 @@
  * Author: Jun Liang Tan <junliang.tan@linux.starfivetech.com>
  */
 
+#include <sbi/sbi_domain.h>
+#include <sbi/riscv_asm.h>
 #include <sbi/riscv_io.h>
 #include <sbi/sbi_console.h>
 #include <sbi_utils/serial/cadence-uart.h>
@@ -124,5 +126,7 @@ int cadence_uart_init(unsigned long base, u32 in_freq, u32 baudrate)
 
        sbi_console_set_device(&cadence_console);
 
-       return 0;
+       return sbi_domain_root_add_memrange(base, PAGE_SIZE, PAGE_SIZE,
+                                           (SBI_DOMAIN_MEMREGION_MMIO |
+                                           SBI_DOMAIN_MEMREGION_SHARED_SURW_MRW));
 }
index 61f66d683e8f3bf4f5a1ca2c5c00a51789a14954..7d88e7a16b82908fc34cb7b28816abb19b3ceaba 100644 (file)
@@ -7,6 +7,8 @@
  *   Anup Patel <anup.patel@wdc.com>
  */
 
+#include <sbi/riscv_asm.h>
+#include <sbi/sbi_domain.h>
 #include <sbi_utils/fdt/fdt_helper.h>
 #include <sbi_utils/serial/fdt_serial.h>
 #include <sbi_utils/sys/htif.h>
@@ -19,6 +21,7 @@ static const struct fdt_match serial_htif_match[] = {
 static int serial_htif_init(void *fdt, int nodeoff,
                            const struct fdt_match *match)
 {
+       int rc;
        bool custom = false;
        uint64_t fromhost_addr = 0, tohost_addr = 0;
 
@@ -29,6 +32,12 @@ static int serial_htif_init(void *fdt, int nodeoff,
 
        fdt_get_node_addr_size(fdt, nodeoff, 1, &tohost_addr, NULL);
 
+       rc = sbi_domain_root_add_memrange(fromhost_addr, PAGE_SIZE, PAGE_SIZE,
+                                         (SBI_DOMAIN_MEMREGION_MMIO |
+                                          SBI_DOMAIN_MEMREGION_SHARED_SURW_MRW));
+       if (rc)
+               return rc;
+
        return htif_serial_init(custom, fromhost_addr, tohost_addr);
 }
 
index 99bf1bf733f294a783ebd1d2707fd7257619520a..4d158d3b8391d6527749ad224cdeef2b5a005f5a 100644 (file)
@@ -7,8 +7,10 @@
  *   Anup Patel <anup.patel@wdc.com>
  */
 
+#include <sbi/riscv_asm.h>
 #include <sbi/riscv_io.h>
 #include <sbi/sbi_console.h>
+#include <sbi/sbi_domain.h>
 #include <sbi_utils/serial/uart8250.h>
 
 /* clang-format off */
@@ -133,5 +135,8 @@ int uart8250_init(unsigned long base, u32 in_freq, u32 baudrate, u32 reg_shift,
 
        sbi_console_set_device(&uart8250_console);
 
-       return 0;
+       return sbi_domain_root_add_memrange(base + reg_offset, PAGE_SIZE,
+                                           PAGE_SIZE,
+                                           (SBI_DOMAIN_MEMREGION_MMIO |
+                                           SBI_DOMAIN_MEMREGION_SHARED_SURW_MRW));
 }