[edk2-devel] [[edk2-platforms] PATCH v2 12/14] RISC-V: Switch to latest OpenSBI

Daniel Schaefer posted 1 patch 2 weeks, 2 days ago
Failed in applying to current master (apply log)
Platform/RISC-V/PlatformPkg/Library/OpensbiPlatformLibNull/Platform.c                                     | 27 ++++---
Platform/RISC-V/PlatformPkg/Universal/Sec/Riscv64/SecEntry.S                                              |  2 +
Platform/RISC-V/PlatformPkg/Universal/Sec/SecMain.c                                                       |  5 +-
Platform/SiFive/U5SeriesPkg/FreedomU500VC707Board/Library/OpensbiPlatformLib/Platform.c                   | 29 +------
Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/Library/OpensbiPlatformLib/Platform.c         | 31 +++-----
Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/Library/OpensbiPlatformLib/PlatformOverride.h |  5 +-
Platform/SiFive/U5SeriesPkg/Library/SerialIoLib/SerialPortLib.c                                           | 81 +++++++++++++++++++-
Silicon/RISC-V/ProcessorPkg/Include/Library/RiscVEdk2SbiLib.h                                             |  1 +
Silicon/RISC-V/ProcessorPkg/Include/OpensbiTypes.h                                                        |  1 +
Silicon/RISC-V/ProcessorPkg/Library/RiscVOpensbiLib/RiscVOpensbiLib.inf                                   | 13 +++-
10 files changed, 128 insertions(+), 67 deletions(-)

[edk2-devel] [[edk2-platforms] PATCH v2 12/14] RISC-V: Switch to latest OpenSBI

Posted by Daniel Schaefer 2 weeks, 2 days ago
Cc: Daniel Schaefer <daniel.schaefer@hpe.com>
Cc: Abner Chang <abner.chang@hpe.com>
Cc: Sunil V L <sunilvl@ventanamicro.com>

Signed-off-by: Daniel Schaefer <daniel.schaefer@hpe.com>
---
 Platform/RISC-V/PlatformPkg/Library/OpensbiPlatformLibNull/Platform.c                                     | 27 ++++---
 Platform/RISC-V/PlatformPkg/Universal/Sec/Riscv64/SecEntry.S                                              |  2 +
 Platform/RISC-V/PlatformPkg/Universal/Sec/SecMain.c                                                       |  5 +-
 Platform/SiFive/U5SeriesPkg/FreedomU500VC707Board/Library/OpensbiPlatformLib/Platform.c                   | 29 +------
 Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/Library/OpensbiPlatformLib/Platform.c         | 31 +++-----
 Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/Library/OpensbiPlatformLib/PlatformOverride.h |  5 +-
 Platform/SiFive/U5SeriesPkg/Library/SerialIoLib/SerialPortLib.c                                           | 81 +++++++++++++++++++-
 Silicon/RISC-V/ProcessorPkg/Include/Library/RiscVEdk2SbiLib.h                                             |  1 +
 Silicon/RISC-V/ProcessorPkg/Include/OpensbiTypes.h                                                        |  1 +
 Silicon/RISC-V/ProcessorPkg/Library/RiscVOpensbiLib/RiscVOpensbiLib.inf                                   | 13 +++-
 10 files changed, 128 insertions(+), 67 deletions(-)

diff --git a/Platform/RISC-V/PlatformPkg/Library/OpensbiPlatformLibNull/Platform.c b/Platform/RISC-V/PlatformPkg/Library/OpensbiPlatformLibNull/Platform.c
index e78d811f4c..b7e39d19c1 100644
--- a/Platform/RISC-V/PlatformPkg/Library/OpensbiPlatformLibNull/Platform.c
+++ b/Platform/RISC-V/PlatformPkg/Library/OpensbiPlatformLibNull/Platform.c
@@ -14,31 +14,38 @@
 #include <sbi/sbi_platform.h>

 

 const struct sbi_platform_operations platform_ops = {

-    .pmp_region_count   = NULL,

-    .pmp_region_info    = NULL,

+    .early_init         = NULL,

     .final_init         = NULL,

+    .early_exit         = NULL,

+    .final_exit         = NULL,

+    .domains_root_regions = NULL,

+    .domains_init       = NULL,

     .console_putc       = NULL,

     .console_getc       = NULL,

     .console_init       = NULL,

     .irqchip_init       = NULL,

+    .irqchip_exit       = NULL,

     .ipi_send           = NULL,

     .ipi_clear          = NULL,

     .ipi_init           = NULL,

+    .ipi_exit           = NULL,

+    .get_tlbr_flush_limit = NULL,

     .timer_value        = NULL,

     .timer_event_stop   = NULL,

     .timer_event_start  = NULL,

     .timer_init         = NULL,

-    .system_reboot      = NULL,

-    .system_shutdown    = NULL

+    .timer_exit         = NULL,

+    .system_reset_check = NULL,

+    .system_reset       = NULL,

 };

 

-const struct sbi_platform platform = {

-    .opensbi_version    = OPENSBI_VERSION,                      // The OpenSBI version this platform table is built bassed on.

-    .platform_version   = SBI_PLATFORM_VERSION(0x0000, 0x0000), // SBI Platform version 1.0

-    .name               = "NULL platform",

+struct sbi_platform platform = {

+    .opensbi_version    = OPENSBI_VERSION,

+    .platform_version   = SBI_PLATFORM_VERSION(0x0, 0x01),

+    .name               = "NULL Platform",

     .features           = 0,

     .hart_count         = 0,

+    .hart_index2id      = 0,

     .hart_stack_size    = 0,

-    .disabled_hart_mask = 0,

-    .platform_ops_addr  = 0

+    .platform_ops_addr  = 0,

 };

diff --git a/Platform/RISC-V/PlatformPkg/Universal/Sec/Riscv64/SecEntry.S b/Platform/RISC-V/PlatformPkg/Universal/Sec/Riscv64/SecEntry.S
index 0e3940180d..a8157c896e 100644
--- a/Platform/RISC-V/PlatformPkg/Universal/Sec/Riscv64/SecEntry.S
+++ b/Platform/RISC-V/PlatformPkg/Universal/Sec/Riscv64/SecEntry.S
@@ -21,6 +21,8 @@
 .text

 .align 3

 

+    .globl _start_warm

+

 ASM_FUNC (_ModuleEntryPoint)

   /*

    * Jump to warm-boot if this is not the selected core booting,

diff --git a/Platform/RISC-V/PlatformPkg/Universal/Sec/SecMain.c b/Platform/RISC-V/PlatformPkg/Universal/Sec/SecMain.c
index 0af0b4bac8..e9f030f352 100644
--- a/Platform/RISC-V/PlatformPkg/Universal/Sec/SecMain.c
+++ b/Platform/RISC-V/PlatformPkg/Universal/Sec/SecMain.c
@@ -21,6 +21,7 @@
 #include <sbi/sbi_platform.h> // Reference to header file in opensbi

 #include <sbi/sbi_init.h>     // Reference to header file in opensbi

 #include <sbi/sbi_ecall.h>    // Reference to header file in opensbi

+#include <sbi/sbi_trap.h>     // Reference to header file in opensbi

 

 //

 // Indicates the boot hart (PcdBootHartId) OpenSBI initialization is done.

@@ -434,7 +435,7 @@ EFI_STATUS EFIAPI TemporaryRamDone (
 STATIC int SbiEcallFirmwareHandler (

   IN  unsigned long         ExtId,

   IN  unsigned long         FuncId,

-  IN  unsigned long        *Args,

+  IN  CONST struct sbi_trap_regs *TrapRegs,

   OUT unsigned long        *OutVal,

   OUT struct sbi_trap_info *OutTrap

   )

@@ -446,7 +447,7 @@ STATIC int SbiEcallFirmwareHandler (
       *OutVal = (unsigned long) sbi_scratch_thishart_ptr();

       break;

     case SBI_EXT_FW_MSCRATCH_HARTID_FUNC:

-      *OutVal = (unsigned long) sbi_hartid_to_scratch (Args[0]);

+      *OutVal = (unsigned long) sbi_hartid_to_scratch (TrapRegs->a0);

       break;

     default:

       Ret = SBI_ENOTSUPP;

diff --git a/Platform/SiFive/U5SeriesPkg/FreedomU500VC707Board/Library/OpensbiPlatformLib/Platform.c b/Platform/SiFive/U5SeriesPkg/FreedomU500VC707Board/Library/OpensbiPlatformLib/Platform.c
index ed4b1550bc..b346eccaf0 100644
--- a/Platform/SiFive/U5SeriesPkg/FreedomU500VC707Board/Library/OpensbiPlatformLib/Platform.c
+++ b/Platform/SiFive/U5SeriesPkg/FreedomU500VC707Board/Library/OpensbiPlatformLib/Platform.c
@@ -111,30 +111,6 @@ static int U500_final_init(bool cold_boot)
     return 0;

 }

 

-static u32 U500_pmp_region_count(u32 hartid)

-{

-    return 1;

-}

-

-static int U500_pmp_region_info(u32 hartid, u32 index,

-                 ulong *prot, ulong *addr, ulong *log2size)

-{

-    int ret = 0;

-

-    switch (index) {

-    case 0:

-        *prot = PMP_R | PMP_W | PMP_X;

-        *addr = 0;

-        *log2size = __riscv_xlen;

-        break;

-    default:

-        ret = -1;

-        break;

-    };

-

-    return ret;

-}

-

 static int U500_console_init(void)

 {

     unsigned long peri_in_freq;

@@ -196,15 +172,12 @@ static int U500_timer_init(bool cold_boot)
  */

 static u32 u500_hart_index2id[U500_BOOTABLE_HART_COUNT] = {0, 1, 2, 3};

 

-static int U500_system_reset(u32 type)

+static void U500_system_reset(u32 type, u32 second_param)

 {

     /* For now nothing to do. */

-    return 0;

 }

 

 const struct sbi_platform_operations platform_ops = {

-    .pmp_region_count = U500_pmp_region_count,

-    .pmp_region_info = U500_pmp_region_info,

     .final_init = U500_final_init,

     .console_putc = sifive_uart_putc,

     .console_getc = sifive_uart_getc,

diff --git a/Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/Library/OpensbiPlatformLib/Platform.c b/Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/Library/OpensbiPlatformLib/Platform.c
index 4deb048566..2f51e45d58 100644
--- a/Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/Library/OpensbiPlatformLib/Platform.c
+++ b/Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/Library/OpensbiPlatformLib/Platform.c
@@ -13,6 +13,8 @@
 #include <sbi/sbi_hartmask.h>

 #include <sbi/sbi_platform.h>

 #include <sbi/sbi_string.h>

+#include <sbi/sbi_math.h>

+#include <sbi_utils/fdt/fdt_domain.h>

 #include <sbi_utils/fdt/fdt_fixup.h>

 #include <sbi_utils/fdt/fdt_helper.h>

 #include <sbi_utils/irqchip/fdt_irqchip.h>

@@ -71,7 +73,7 @@ unsigned long fw_platform_init(unsigned long arg0, unsigned long arg1,
 				unsigned long arg2, unsigned long arg3,

 				unsigned long arg4)

 {

-	const char *model, *mmu_type;

+	const char *model;

 	void *fdt = (void *)arg1;

 	u32 hartid, hart_count = 0;

 	int rc, root_offset, cpus_offset, cpu_offset, len;

@@ -101,10 +103,6 @@ unsigned long fw_platform_init(unsigned long arg0, unsigned long arg1,
 		if (SBI_HARTMASK_MAX_BITS <= hartid)

 			continue;

 

-		mmu_type = fdt_getprop(fdt, cpu_offset, "mmu-type", &len);

-		if (!mmu_type || !len)

-			hartid = -1U;

-

 		generic_hart_index2id[hart_count++] = hartid;

 	}

 

@@ -152,6 +150,7 @@ static int generic_final_init(bool cold_boot)
 

 	fdt_cpu_fixup(fdt);

 	fdt_fixups(fdt);

+	fdt_domain_fixup(fdt);

 

 	if (generic_plat && generic_plat->fdt_fixup) {

 		rc = generic_plat->fdt_fixup(fdt, generic_plat_match);

@@ -174,6 +173,11 @@ static void generic_final_exit(void)
 		generic_plat->final_exit(generic_plat_match);

 }

 

+static int generic_domains_init(void)

+{

+	return fdt_domains_populate(sbi_scratch_thishart_arg1_ptr());

+}

+

 static u64 generic_tlbr_flush_limit(void)

 {

 	if (generic_plat && generic_plat->tlbr_flush_limit)

@@ -181,35 +185,20 @@ static u64 generic_tlbr_flush_limit(void)
 	return SBI_PLATFORM_TLB_RANGE_FLUSH_LIMIT_DEFAULT;

 }

 

-static int generic_system_reset(u32 reset_type)

-{

-	if (generic_plat && generic_plat->system_reset)

-		return generic_plat->system_reset(reset_type,

-						  generic_plat_match);

-	return fdt_system_reset(reset_type);

-}

-

 const struct sbi_platform_operations platform_ops = {

 	.early_init		= generic_early_init,

 	.final_init		= generic_final_init,

 	.early_exit		= generic_early_exit,

 	.final_exit		= generic_final_exit,

-	.console_putc		= fdt_serial_putc,

-	.console_getc		= fdt_serial_getc,

+	.domains_init		= generic_domains_init,

 	.console_init		= fdt_serial_init,

 	.irqchip_init		= fdt_irqchip_init,

 	.irqchip_exit		= fdt_irqchip_exit,

-	.ipi_send		= fdt_ipi_send,

-	.ipi_clear		= fdt_ipi_clear,

 	.ipi_init		= fdt_ipi_init,

 	.ipi_exit		= fdt_ipi_exit,

 	.get_tlbr_flush_limit	= generic_tlbr_flush_limit,

-	.timer_value		= fdt_timer_value,

-	.timer_event_stop	= fdt_timer_event_stop,

-	.timer_event_start	= fdt_timer_event_start,

 	.timer_init		= fdt_timer_init,

 	.timer_exit		= fdt_timer_exit,

-	.system_reset		= generic_system_reset,

 };

 

 struct sbi_platform platform = {

diff --git a/Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/Library/OpensbiPlatformLib/PlatformOverride.h b/Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/Library/OpensbiPlatformLib/PlatformOverride.h
index 8a53cdf9ac..77a90d645e 100644
--- a/Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/Library/OpensbiPlatformLib/PlatformOverride.h
+++ b/Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/Library/OpensbiPlatformLib/PlatformOverride.h
@@ -20,7 +20,10 @@ struct platform_override {
 	int (*final_init)(bool cold_boot, const struct fdt_match *match);
 	void (*early_exit)(const struct fdt_match *match);
 	void (*final_exit)(const struct fdt_match *match);
-	int (*system_reset)(u32 reset_type, const struct fdt_match *match);
+	int (*system_reset_check)(u32 reset_type, u32 reset_reason,
+				  const struct fdt_match *match);
+	void (*system_reset)(u32 reset_type, u32 reset_reason,
+			     const struct fdt_match *match);
 	int (*fdt_fixup)(void *fdt, const struct fdt_match *match);
 };
 
diff --git a/Platform/SiFive/U5SeriesPkg/Library/SerialIoLib/SerialPortLib.c b/Platform/SiFive/U5SeriesPkg/Library/SerialIoLib/SerialPortLib.c
index e98c8523a3..7bc73a0b82 100644
--- a/Platform/SiFive/U5SeriesPkg/Library/SerialIoLib/SerialPortLib.c
+++ b/Platform/SiFive/U5SeriesPkg/Library/SerialIoLib/SerialPortLib.c
@@ -19,6 +19,21 @@
 #define UART_REG_IP     5

 #define UART_IP_RXWM    0x02

 

+

+#define UART_REG_TXFIFO     0

+#define UART_REG_RXFIFO     1

+#define UART_REG_TXCTRL     2

+#define UART_REG_RXCTRL     3

+#define UART_REG_IE         4

+#define UART_REG_IP         5

+#define UART_REG_DIV        6

+

+#define UART_TXFIFO_FULL    0x80000000

+#define UART_RXFIFO_EMPTY   0x80000000

+#define UART_RXFIFO_DATA    0x000000ff

+#define UART_TXCTRL_TXEN    0x1

+#define UART_RXCTRL_RXEN    0x1

+

 //---------------------------------------------

 // UART Settings

 //---------------------------------------------

@@ -28,6 +43,68 @@
 

 BOOLEAN Initiated = FALSE;

 

+/**

+  Get value from serial port register.

+

+  @param  RegIndex   Register index

+

+  @retval Vale returned from from serial port.

+

+**/

+UINT32 GetReg (

+  IN UINT32 RegIndex

+  )

+{

+  return MmioRead32 (FixedPcdGet32(PcdU5UartBase) + (RegIndex * 0x4));

+}

+

+/**

+  Set serial port register.

+

+  @param RegIndex   Register index

+  @param Value      Value write to Register

+

+**/

+VOID SetReg (

+  IN UINT32 RegIndex,

+  IN UINT32 Value

+  )

+{

+  MmioWrite32 (Value, FixedPcdGet32(PcdU5UartBase) + (RegIndex * 0x4));

+}

+

+/**

+  Character output to serial port.

+

+  @param Ch        The character to serial port.

+

+**/

+VOID SifiveUartPutChar (

+  IN UINT8 Ch

+  )

+{

+  while (GetReg (UART_REG_TXFIFO) & UART_TXFIFO_FULL);

+

+  SetReg (UART_REG_TXFIFO, Ch);

+}

+

+/**

+  Get character from serial port.

+

+  @retval character        The character from serial port.

+

+**/

+UINT32 SifiveUartGetChar (VOID)

+{

+  UINT32 Ret;

+

+  Ret = GetReg (UART_REG_RXFIFO);

+  if (!(Ret & UART_RXFIFO_EMPTY)) {

+    return Ret & UART_RXFIFO_DATA;

+  }

+  return -1;

+}

+

 /**

   Initialize the serial device hardware.

 

@@ -88,7 +165,7 @@ SerialPortWrite (
   }

 

   for(Index = 0; Index < NumberOfBytes; Index ++) {

-    sifive_uart_putc (Buffer [Index]);

+    SifiveUartPutChar (Buffer [Index]);

   }

 

   return Index;

@@ -119,7 +196,7 @@ SerialPortRead (
   }

 

   for (Index = 0; Index < NumberOfBytes; Index ++) {

-    Buffer [Index] = (UINT8)sifive_uart_getc ();

+    Buffer [Index] = (UINT8)SifiveUartGetChar ();

   }

 

   return Index;

diff --git a/Silicon/RISC-V/ProcessorPkg/Include/Library/RiscVEdk2SbiLib.h b/Silicon/RISC-V/ProcessorPkg/Include/Library/RiscVEdk2SbiLib.h
index f81ea06b05..66a87cb8c3 100644
--- a/Silicon/RISC-V/ProcessorPkg/Include/Library/RiscVEdk2SbiLib.h
+++ b/Silicon/RISC-V/ProcessorPkg/Include/Library/RiscVEdk2SbiLib.h
@@ -16,6 +16,7 @@
 #include <IndustryStandard/RiscVOpensbi.h>

 #include <sbi/sbi_scratch.h>

 #include <sbi/sbi_platform.h>

+#include <sbi/sbi_ecall.h>

 

 //

 // EDK2 OpenSBI Firmware extension.

diff --git a/Silicon/RISC-V/ProcessorPkg/Include/OpensbiTypes.h b/Silicon/RISC-V/ProcessorPkg/Include/OpensbiTypes.h
index 00c374f24a..bbf74e2a82 100644
--- a/Silicon/RISC-V/ProcessorPkg/Include/OpensbiTypes.h
+++ b/Silicon/RISC-V/ProcessorPkg/Include/OpensbiTypes.h
@@ -49,6 +49,7 @@ typedef UINT64   physical_size_t;
 

 #define __packed        __attribute__((packed))

 #define __noreturn      __attribute__((noreturn))

+#define __aligned(x)    __attribute__((aligned(x)))

 

 #if defined(__GNUC__) || defined(__clang__)

   #define likely(x) __builtin_expect((x), 1)

diff --git a/Silicon/RISC-V/ProcessorPkg/Library/RiscVOpensbiLib/RiscVOpensbiLib.inf b/Silicon/RISC-V/ProcessorPkg/Library/RiscVOpensbiLib/RiscVOpensbiLib.inf
index 71cc76444e..e40a797896 100644
--- a/Silicon/RISC-V/ProcessorPkg/Library/RiscVOpensbiLib/RiscVOpensbiLib.inf
+++ b/Silicon/RISC-V/ProcessorPkg/Library/RiscVOpensbiLib/RiscVOpensbiLib.inf
@@ -23,6 +23,7 @@
   opensbi/lib/sbi/sbi_bitmap.c

   opensbi/lib/sbi/sbi_bitops.c

   opensbi/lib/sbi/sbi_console.c

+  opensbi/lib/sbi/sbi_domain.c

   opensbi/lib/sbi/sbi_ecall.c

   opensbi/lib/sbi/sbi_ecall_base.c

   opensbi/lib/sbi/sbi_ecall_hsm.c

@@ -51,27 +52,33 @@
 

   opensbi/lib/utils/fdt/fdt_helper.c

   opensbi/lib/utils/fdt/fdt_fixup.c

+  opensbi/lib/utils/fdt/fdt_domain.c

   opensbi/lib/utils/ipi/fdt_ipi.c

-  opensbi/lib/utils/ipi/fdt_ipi_clint.c

+  opensbi/lib/utils/ipi/aclint_mswi.c

+  opensbi/lib/utils/ipi/fdt_ipi_mswi.c

   opensbi/lib/utils/irqchip/fdt_irqchip.c

   opensbi/lib/utils/irqchip/fdt_irqchip_plic.c

   opensbi/lib/utils/irqchip/plic.c

   opensbi/lib/utils/reset/fdt_reset.c

   opensbi/lib/utils/reset/fdt_reset_htif.c

   opensbi/lib/utils/reset/fdt_reset_sifive.c

+  opensbi/lib/utils/reset/fdt_reset_thead.c

+  opensbi/lib/utils/reset/fdt_reset_thead_asm.S

   opensbi/lib/utils/serial/fdt_serial.c

   opensbi/lib/utils/serial/fdt_serial_htif.c

   opensbi/lib/utils/serial/fdt_serial_shakti.c

   opensbi/lib/utils/serial/fdt_serial_sifive.c

   opensbi/lib/utils/serial/fdt_serial_uart8250.c

+  opensbi/lib/utils/serial/fdt_serial_gaisler.c

+  opensbi/lib/utils/serial/gaisler-uart.c

   opensbi/lib/utils/serial/shakti-uart.c

   opensbi/lib/utils/serial/sifive-uart.c

   opensbi/lib/utils/serial/uart8250.c

-  opensbi/lib/utils/sys/clint.c

   opensbi/lib/utils/sys/htif.c

   opensbi/lib/utils/sys/sifive_test.c

   opensbi/lib/utils/timer/fdt_timer.c

-  opensbi/lib/utils/timer/fdt_timer_clint.c

+  opensbi/lib/utils/timer/aclint_mtimer.c

+  opensbi/lib/utils/timer/fdt_timer_mtimer.c

 

 [Packages]

   EmbeddedPkg/EmbeddedPkg.dec   # For libfdt.

-- 
2.33.0



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#81549): https://edk2.groups.io/g/devel/message/81549
Mute This Topic: https://groups.io/mt/86117336/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-