public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v4 0/1] New RISC-V Patches
@ 2020-06-02 16:51 Daniel Schaefer
  2020-06-02 16:51 ` [PATCH v4 1/1] ProcessorPkg/Library: Add RiscVEdk2SbiLib Daniel Schaefer
  0 siblings, 1 reply; 7+ messages in thread
From: Daniel Schaefer @ 2020-06-02 16:51 UTC (permalink / raw)
  To: devel; +Cc: Leif Lindholm, Gilbert Chen, Abner Chang, Michael D . Kinney

Hi,

here's the latest version of the RiscVEdk2SbiLib patch. The other commits from
the last series haven't changed, so I'm not resending them to reduce the noise.

Below in this email, I included a patch showing the differences betwen the last patchset and this one.

The branch is at https://github.com/changab/edk2-platforms/tree/devel-riscvplatforms
and I made another repo, to easily try out booting to EFI Shell on RISC-V:
https://github.com/JohnAZoidberg/riscv-edk2-docker

Other TODOs for upstreaming RISC-V:
- Deduplicating SMBIOS code -> I am doing that currently
- Figuring out in which repo to put the code -> Discussion is still going on

Cheers,
Daniel

Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Gilbert Chen <gilbert.chen@hpe.com>
Cc: Abner Chang <abner.chang@hpe.com>
Cc: Michael D. Kinney <michael.d.kinney@intel.com>

Daniel Schaefer (1):
  ProcessorPkg/Library: Add RiscVEdk2SbiLib

 Silicon/RISC-V/ProcessorPkg/Library/RiscVEdk2SbiLib/RiscVEdk2SbiLib.inf |  28 +
 Silicon/RISC-V/ProcessorPkg/Include/Library/RiscVEdk2SbiLib.h           | 563 ++++++++++++
 Silicon/RISC-V/ProcessorPkg/Library/RiscVEdk2SbiLib/RiscVEdk2SbiLib.c   | 897 ++++++++++++++++++++
 3 files changed, 1488 insertions(+)
 create mode 100644 Silicon/RISC-V/ProcessorPkg/Library/RiscVEdk2SbiLib/RiscVEdk2SbiLib.inf
 create mode 100644 Silicon/RISC-V/ProcessorPkg/Include/Library/RiscVEdk2SbiLib.h
 create mode 100644 Silicon/RISC-V/ProcessorPkg/Library/RiscVEdk2SbiLib/RiscVEdk2SbiLib.c
--
diff --git i/Silicon/RISC-V/ProcessorPkg/Library/RiscVEdk2SbiLib/RiscVEdk2SbiLib.c w/Silicon/RISC-V/ProcessorPkg/Library/RiscVEdk2SbiLib/RiscVEdk2SbiLib.c
index d26adaa37ce7..0df505d2675b 100644
--- i/Silicon/RISC-V/ProcessorPkg/Library/RiscVEdk2SbiLib/RiscVEdk2SbiLib.c
+++ w/Silicon/RISC-V/ProcessorPkg/Library/RiscVEdk2SbiLib/RiscVEdk2SbiLib.c
@@ -16,8 +16,10 @@
   - SbiLegacyShutdown            -> Wait for new System Reset extension
 
   Copyright (c) 2020, Hewlett Packard Development LP. All rights reserved.<BR>
-
   SPDX-License-Identifier: BSD-2-Clause-Patent
+
+  @par Revision Reference:
+    - OpenSBI Version 0.6
 **/
 
 #include <IndustryStandard/RiscVOpensbi.h>
@@ -30,12 +32,22 @@
 #include <sbi/sbi_init.h>
 
 
+//
+// Maximum arguments for SBI ecall
+// It's possible to pass more but no SBI call uses more as of SBI 0.2.
+// The additional arguments would have to be passed on the stack instead of as
+// registers, like it's done now.
+//
+#define SBI_CALL_MAX_ARGS 6
+
 /**
   Call SBI call using ecall instruction.
 
+  Asserts when NumArgs exceeds SBI_CALL_MAX_ARGS.
+
   @param[in] ExtId    SBI extension ID.
   @param[in] FuncId   SBI function ID.
-  @param[in] NumAargs Number of arguments to pass to the ecall.
+  @param[in] NumArgs  Number of arguments to pass to the ecall.
   @param[in] ...      Argument list for the ecall.
 
   @retval  Returns SbiRet structure with value and error code.
@@ -49,16 +61,19 @@ SbiCall(
   IN  UINTN FuncId,
   IN  UINTN NumArgs,
   ...
-) {
+  )
+{
     UINTN I;
     SbiRet Ret;
-    UINTN Args[6];
+    UINTN Args[SBI_CALL_MAX_ARGS];
     VA_LIST ArgList;
-    VA_START(ArgList, NumArgs);
+    VA_START (ArgList, NumArgs);
 
-    for (I = 0; I < 6; I++) {
+    ASSERT (NumArgs <= SBI_CALL_MAX_ARGS);
+
+    for (I = 0; I < SBI_CALL_MAX_ARGS; I++) {
       if (I < NumArgs) {
-        Args[I] = VA_ARG(ArgList, UINTN);
+        Args[I] = VA_ARG (ArgList, UINTN);
       } else {
         // Default to 0 for all arguments that are not given
         Args[I] = 0;
@@ -95,8 +110,9 @@ STATIC
 EFI_STATUS
 EFIAPI
 TranslateError(
-  IN UINTN SbiError
-  ) {
+  IN  UINTN SbiError
+  )
+{
   switch (SbiError) {
     case SBI_SUCCESS:
       return EFI_SUCCESS;
@@ -129,7 +145,7 @@ TranslateError(
 }
 
 //
-// OpenSBI libraary interface function for the base extension
+// OpenSBI library interface function for the base extension
 //
 
 /**
@@ -150,7 +166,7 @@ SbiGetSpecVersion (
   SbiRet Ret = SbiCall (SBI_EXT_BASE, SBI_EXT_BASE_GET_SPEC_VERSION, 0);
 
   if (!Ret.Error) {
-    *SpecVersion = (UINTN) Ret.Value;
+    *SpecVersion = (UINTN)Ret.Value;
   }
 }
 
@@ -169,7 +185,7 @@ SbiGetImplId (
   )
 {
   SbiRet Ret = SbiCall (SBI_EXT_BASE, SBI_EXT_BASE_GET_IMP_ID, 0);
-  *ImplId = (UINTN) Ret.Value;
+  *ImplId = (UINTN)Ret.Value;
 }
 
 /**
@@ -187,7 +203,7 @@ SbiGetImplVersion (
   )
 {
   SbiRet Ret = SbiCall (SBI_EXT_BASE, SBI_EXT_BASE_GET_IMP_VERSION, 0);
-  *ImplVersion = (UINTN) Ret.Value;
+  *ImplVersion = (UINTN)Ret.Value;
 }
 
 /**
@@ -207,7 +223,7 @@ SbiProbeExtension (
   )
 {
   SbiRet Ret = SbiCall (SBI_EXT_BASE, SBI_EXT_BASE_PROBE_EXT, 0);
-  *ProbeResult = (UINTN) Ret.Value;
+  *ProbeResult = (UINTN)Ret.Value;
 }
 
 /**
@@ -224,7 +240,7 @@ SbiGetMachineVendorId (
   )
 {
   SbiRet Ret = SbiCall (SBI_EXT_BASE, SBI_EXT_BASE_GET_MVENDORID, 0);
-  *MachineVendorId = (UINTN) Ret.Value;
+  *MachineVendorId = (UINTN)Ret.Value;
 }
 
 /**
@@ -241,7 +257,7 @@ SbiGetMachineArchId (
   )
 {
   SbiRet Ret = SbiCall (SBI_EXT_BASE, SBI_EXT_BASE_GET_MARCHID, 0);
-  *MachineArchId = (UINTN) Ret.Value;
+  *MachineArchId = (UINTN)Ret.Value;
 }
 
 /**
@@ -258,7 +274,7 @@ SbiGetMachineImplId (
   )
 {
   SbiRet Ret = SbiCall (SBI_EXT_BASE, SBI_EXT_BASE_GET_MIMPID, 0);
-  *MachineImplId = (UINTN) Ret.Value;
+  *MachineImplId = (UINTN)Ret.Value;
 }
 
 //
@@ -296,13 +312,15 @@ SbiHartStart (
   IN  UINTN                          Priv
   )
 {
-  SbiRet Ret = SbiCall (SBI_EXT_HSM,
-                        SBI_EXT_HSM_HART_START,
-                        3,
-                        HartId,
-                        StartAddr,
-                        Priv);
-  return TranslateError(Ret.Error);
+  SbiRet Ret = SbiCall (
+                 SBI_EXT_HSM,
+                 SBI_EXT_HSM_HART_START,
+                 3,
+                 HartId,
+                 StartAddr,
+                 Priv
+                 );
+  return TranslateError (Ret.Error);
 }
 
 /**
@@ -320,7 +338,7 @@ SbiHartStop (
   )
 {
   SbiRet Ret = SbiCall (SBI_EXT_HSM, SBI_EXT_HSM_HART_STOP, 0);
-  return TranslateError(Ret.Error);
+  return TranslateError (Ret.Error);
 }
 
 /**
@@ -350,10 +368,10 @@ SbiHartGetStatus (
   SbiRet Ret = SbiCall (SBI_EXT_HSM, SBI_EXT_HSM_HART_GET_STATUS, 1, HartId);
 
   if (!Ret.Error) {
-    *HartStatus = (UINTN) Ret.Value;
+    *HartStatus = (UINTN)Ret.Value;
   }
 
-  return TranslateError(Ret.Error);
+  return TranslateError (Ret.Error);
 }
 
 /**
@@ -380,12 +398,14 @@ SbiSendIpi (
   IN  UINTN                          HartMaskBase
   )
 {
-  SbiRet Ret = SbiCall (SBI_EXT_IPI,
-                        SBI_EXT_IPI_SEND_IPI,
-                        2,
-                        (UINTN) HartMask,
-                        HartMaskBase);
-  return TranslateError(Ret.Error);
+  SbiRet Ret = SbiCall (
+                 SBI_EXT_IPI,
+                 SBI_EXT_IPI_SEND_IPI,
+                 2,
+                 (UINTN)HartMask,
+                 HartMaskBase
+                 );
+  return TranslateError (Ret.Error);
 }
 
 /**
@@ -408,12 +428,14 @@ SbiRemoteFenceI (
   IN  UINTN                          HartMaskBase
   )
 {
-  SbiRet Ret = SbiCall (SBI_EXT_RFENCE,
-                        SBI_EXT_RFENCE_REMOTE_FENCE_I,
-                        2,
-                        (UINTN) HartMask,
-                        HartMaskBase);
-  return TranslateError(Ret.Error);
+  SbiRet Ret = SbiCall (
+                 SBI_EXT_RFENCE,
+                 SBI_EXT_RFENCE_REMOTE_FENCE_I,
+                 2,
+                 (UINTN)HartMask,
+                 HartMaskBase
+                 );
+  return TranslateError (Ret.Error);
 }
 
 /**
@@ -446,14 +468,16 @@ SbiRemoteSfenceVma (
   IN  UINTN                          Size
   )
 {
-  SbiRet Ret = SbiCall (SBI_EXT_RFENCE,
-                        SBI_EXT_RFENCE_REMOTE_SFENCE_VMA,
-                        4,
-                        (UINTN) HartMask,
-                        HartMaskBase,
-                        StartAddr,
-                        Size);
-  return TranslateError(Ret.Error);
+  SbiRet Ret = SbiCall (
+                 SBI_EXT_RFENCE,
+                 SBI_EXT_RFENCE_REMOTE_SFENCE_VMA,
+                 4,
+                 (UINTN)HartMask,
+                 HartMaskBase,
+                 StartAddr,
+                 Size
+                 );
+  return TranslateError (Ret.Error);
 }
 
 /**
@@ -488,15 +512,17 @@ SbiRemoteSfenceVmaAsid (
   IN  UINTN                          Asid
   )
 {
-  SbiRet Ret = SbiCall (SBI_EXT_RFENCE,
-                        SBI_EXT_RFENCE_REMOTE_SFENCE_VMA_ASID,
-                        5,
-                        (UINTN) HartMask,
-                        HartMaskBase,
-                        StartAddr,
-                        Size,
-                        Asid);
-  return TranslateError(Ret.Error);
+  SbiRet Ret = SbiCall (
+                 SBI_EXT_RFENCE,
+                 SBI_EXT_RFENCE_REMOTE_SFENCE_VMA_ASID,
+                 5,
+                 (UINTN)HartMask,
+                 HartMaskBase,
+                 StartAddr,
+                 Size,
+                 Asid
+                 );
+  return TranslateError (Ret.Error);
 }
 
 /**
@@ -535,15 +561,17 @@ SbiRemoteHFenceGvmaVmid (
   IN  UINTN                          Vmid
   )
 {
-  SbiRet Ret = SbiCall (SBI_EXT_RFENCE,
-                        SBI_EXT_RFENCE_REMOTE_HFENCE_GVMA,
-                        5,
-                        (UINTN) HartMask,
-                        HartMaskBase,
-                        StartAddr,
-                        Size,
-                        Vmid);
-  return TranslateError(Ret.Error);
+  SbiRet Ret = SbiCall (
+                 SBI_EXT_RFENCE,
+                 SBI_EXT_RFENCE_REMOTE_HFENCE_GVMA,
+                 5,
+                 (UINTN)HartMask,
+                 HartMaskBase,
+                 StartAddr,
+                 Size,
+                 Vmid
+                 );
+  return TranslateError (Ret.Error);
 }
 
 /**
@@ -580,14 +608,16 @@ SbiRemoteHFenceGvma (
   IN  UINTN                          Size
   )
 {
-  SbiRet Ret = SbiCall (SBI_EXT_RFENCE,
-                        SBI_EXT_RFENCE_REMOTE_HFENCE_GVMA_VMID,
-                        4,
-                        (UINTN) HartMask,
-                        HartMaskBase,
-                        StartAddr,
-                        Size);
-  return TranslateError(Ret.Error);
+  SbiRet Ret = SbiCall (
+                 SBI_EXT_RFENCE,
+                 SBI_EXT_RFENCE_REMOTE_HFENCE_GVMA_VMID,
+                 4,
+                 (UINTN)HartMask,
+                 HartMaskBase,
+                 StartAddr,
+                 Size
+                 );
+  return TranslateError (Ret.Error);
 }
 
 /**
@@ -626,15 +656,17 @@ SbiRemoteHFenceVvmaAsid (
   IN  UINTN                          Asid
   )
 {
-  SbiRet Ret = SbiCall (SBI_EXT_RFENCE,
-                        SBI_EXT_RFENCE_REMOTE_HFENCE_VVMA,
-                        5,
-                        (UINTN) HartMask,
-                        HartMaskBase,
-                        StartAddr,
-                        Size,
-                        Asid);
-  return TranslateError(Ret.Error);
+  SbiRet Ret = SbiCall (
+                 SBI_EXT_RFENCE,
+                 SBI_EXT_RFENCE_REMOTE_HFENCE_VVMA,
+                 5,
+                 (UINTN)HartMask,
+                 HartMaskBase,
+                 StartAddr,
+                 Size,
+                 Asid
+                 );
+  return TranslateError (Ret.Error);
 }
 
 /**
@@ -671,14 +703,16 @@ SbiRemoteHFenceVvma (
   IN  UINTN                          Size
   )
 {
-  SbiRet Ret = SbiCall (SBI_EXT_RFENCE,
-                        SBI_EXT_RFENCE_REMOTE_HFENCE_VVMA_ASID,
-                        4,
-                        (UINTN) HartMask,
-                        HartMaskBase,
-                        StartAddr,
-                        Size);
-  return TranslateError(Ret.Error);
+  SbiRet Ret = SbiCall (
+                 SBI_EXT_RFENCE,
+                 SBI_EXT_RFENCE_REMOTE_HFENCE_VVMA_ASID,
+                 4,
+                 (UINTN)HartMask,
+                 HartMaskBase,
+                 StartAddr,
+                 Size
+                 );
+  return TranslateError (Ret.Error);
 }
 
 //
@@ -689,14 +723,13 @@ SbiRemoteHFenceVvma (
   Call a function in a vendor defined SBI extension
 
   ASSERT() if the ExtensionId is not in the designated SBI Vendor Extension
-  Space.
+  Space or NumArgs exceeds SBI_CALL_MAX_ARGS.
 
   @param[in]  ExtensionId          The SBI vendor extension ID.
   @param[in]  FunctionId           The function ID to call in this extension.
   @param[in]  NumArgs              How many arguments are passed.
   @param[in]  ...                  Actual Arguments to the function.
   @retval EFI_SUCCESS if the SBI function was called and it was successful
-  @retval EFI_INVALID_PARAMETER if NumArgs exceeds 6
   @retval others if the called SBI function returns an error
 **/
 EFI_STATUS
@@ -710,39 +743,41 @@ SbiVendorCall (
 {
     SbiRet Ret;
     VA_LIST Args;
-    VA_START(Args, NumArgs);
+    VA_START (Args, NumArgs);
 
-    ASSERT (ExtensionId >= 0x09000000 && ExtensionId <= 0x09FFFFFF);
+    ASSERT (ExtensionId >= SBI_EXT_VENDOR_START && ExtensionId <= SBI_EXT_VENDOR_END);
+    ASSERT (NumArgs <= SBI_CALL_MAX_ARGS);
 
     switch (NumArgs) {
       case 0:
         Ret = SbiCall (ExtensionId, FunctionId, NumArgs);
         break;
       case 1:
-        Ret = SbiCall (ExtensionId, FunctionId, NumArgs, VA_ARG(Args, UINTN));
+        Ret = SbiCall (ExtensionId, FunctionId, NumArgs, VA_ARG (Args, UINTN));
         break;
       case 2:
-        Ret = SbiCall (ExtensionId, FunctionId, NumArgs, VA_ARG(Args, UINTN),
-                       VA_ARG(Args, UINTN));
+        Ret = SbiCall (ExtensionId, FunctionId, NumArgs, VA_ARG (Args, UINTN),
+                       VA_ARG (Args, UINTN));
         break;
       case 3:
-        Ret = SbiCall (ExtensionId, FunctionId, NumArgs, VA_ARG(Args, UINTN),
-                       VA_ARG(Args, UINTN), VA_ARG(Args, UINTN));
+        Ret = SbiCall (ExtensionId, FunctionId, NumArgs, VA_ARG (Args, UINTN),
+                       VA_ARG (Args, UINTN), VA_ARG (Args, UINTN));
         break;
       case 4:
-        Ret = SbiCall (ExtensionId, FunctionId, NumArgs, VA_ARG(Args, UINTN),
-                       VA_ARG(Args, UINTN), VA_ARG(Args, UINTN), VA_ARG(Args, UINTN));
+        Ret = SbiCall (ExtensionId, FunctionId, NumArgs, VA_ARG (Args, UINTN),
+                       VA_ARG (Args, UINTN), VA_ARG (Args, UINTN),
+                       VA_ARG (Args, UINTN));
         break;
       case 5:
-        Ret = SbiCall (ExtensionId, FunctionId, NumArgs, VA_ARG(Args, UINTN),
-                       VA_ARG(Args, UINTN), VA_ARG(Args, UINTN),
-                       VA_ARG(Args, UINTN), VA_ARG(Args, UINTN));
+        Ret = SbiCall (ExtensionId, FunctionId, NumArgs, VA_ARG (Args, UINTN),
+                       VA_ARG (Args, UINTN), VA_ARG (Args, UINTN),
+                       VA_ARG (Args, UINTN), VA_ARG (Args, UINTN));
         break;
       case 6:
-        Ret = SbiCall (ExtensionId, FunctionId, NumArgs, VA_ARG(Args, UINTN),
-                       VA_ARG(Args, UINTN), VA_ARG(Args, UINTN),
-                       VA_ARG(Args, UINTN), VA_ARG(Args, UINTN),
-                       VA_ARG(Args, UINTN));
+        Ret = SbiCall (ExtensionId, FunctionId, NumArgs, VA_ARG (Args, UINTN),
+                       VA_ARG (Args, UINTN), VA_ARG (Args, UINTN),
+                       VA_ARG (Args, UINTN), VA_ARG (Args, UINTN),
+                       VA_ARG (Args, UINTN));
         break;
       default:
         // Too many args. In theory SBI can handle more arguments when they are
@@ -752,7 +787,7 @@ SbiVendorCall (
      }
 
     VA_END(Args);
-    return TranslateError(Ret.Error);
+    return TranslateError (Ret.Error);
 }
 
 //
@@ -777,7 +812,7 @@ SbiGetMscratch (
   SbiRet Ret = SbiCall (SBI_EDK2_FW_EXT, SBI_EXT_FW_MSCRATCH_FUNC, 0);
 
   if (!Ret.Error) {
-    *ScratchSpace = (SBI_SCRATCH *) Ret.Value;
+    *ScratchSpace = (SBI_SCRATCH *)Ret.Value;
   }
 
   return EFI_SUCCESS;
@@ -797,13 +832,15 @@ SbiGetMscratchHartid (
   OUT SBI_SCRATCH                    **ScratchSpace
   )
 {
-  SbiRet Ret = SbiCall (SBI_EDK2_FW_EXT,
-                        SBI_EXT_FW_MSCRATCH_HARTID_FUNC,
-                        1,
-                        HartId);
+  SbiRet Ret = SbiCall (
+                 SBI_EDK2_FW_EXT,
+                 SBI_EXT_FW_MSCRATCH_HARTID_FUNC,
+                 1,
+                 HartId
+                 );
 
   if (!Ret.Error) {
-    *ScratchSpace = (SBI_SCRATCH *) Ret.Value;
+    *ScratchSpace = (SBI_SCRATCH *)Ret.Value;
   }
 
   return EFI_SUCCESS;
@@ -826,9 +863,9 @@ SbiGetFirmwareContext (
   SbiRet Ret = SbiCall (SBI_EDK2_FW_EXT, SBI_EXT_FW_MSCRATCH_FUNC, 0);
 
   if (!Ret.Error) {
-    ScratchSpace = (SBI_SCRATCH *) Ret.Value;
-    SbiPlatform = (SBI_PLATFORM *) sbi_platform_ptr(ScratchSpace);
-    *FirmwareContext = (EFI_RISCV_OPENSBI_FIRMWARE_CONTEXT *) SbiPlatform->firmware_context;
+    ScratchSpace = (SBI_SCRATCH *)Ret.Value;
+    SbiPlatform = (SBI_PLATFORM *)sbi_platform_ptr(ScratchSpace);
+    *FirmwareContext = (EFI_RISCV_OPENSBI_FIRMWARE_CONTEXT *)SbiPlatform->firmware_context;
   }
 
   return EFI_SUCCESS;
@@ -851,9 +888,9 @@ SbiSetFirmwareContext (
   SbiRet Ret = SbiCall (SBI_EDK2_FW_EXT, SBI_EXT_FW_MSCRATCH_FUNC, 0);
 
   if (!Ret.Error) {
-    ScratchSpace = (SBI_SCRATCH *) Ret.Value;
-    SbiPlatform = (SBI_PLATFORM *) sbi_platform_ptr(ScratchSpace);
-    SbiPlatform->firmware_context = (UINTN) FirmwareContext;
+    ScratchSpace = (SBI_SCRATCH *)Ret.Value;
+    SbiPlatform = (SBI_PLATFORM *)sbi_platform_ptr (ScratchSpace);
+    SbiPlatform->firmware_context = (UINTN)FirmwareContext;
   }
 
   return EFI_SUCCESS;
-- 
2.26.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-06-23  2:09 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-06-02 16:51 [PATCH v4 0/1] New RISC-V Patches Daniel Schaefer
2020-06-02 16:51 ` [PATCH v4 1/1] ProcessorPkg/Library: Add RiscVEdk2SbiLib Daniel Schaefer
2020-06-02 22:00   ` [edk2-devel] " Michael D Kinney
2020-06-03  1:24     ` Abner Chang
     [not found]     ` <1614E4344379EB27.21938@groups.io>
2020-06-03  1:33       ` Abner Chang
2020-06-18 16:49   ` Leif Lindholm
2020-06-23  2:08     ` Abner Chang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox