[edk2] [platforms: PATCH 1/4] Marvell/Drivers: MvSpiFlash: Enable using driver in RT

Marcin Wojtas posted 4 patches 7 years, 1 month ago
There is a newer version of this series
[edk2] [platforms: PATCH 1/4] Marvell/Drivers: MvSpiFlash: Enable using driver in RT
Posted by Marcin Wojtas 7 years, 1 month ago
This patch applies necessary modifications, which allow to use
MvSpiFlash driver in variable support as a runtime service.
Its type is modified to DXE_RUNTIME_DRIVER, as well as
an event is created, which converts the pointers to the
SpiMasterProtocol and its routines.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Marcin Wojtas <mw@semihalf.com>
---
 Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.c   | 58 ++++++++++++++++++--
 Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.h   |  1 +
 Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.inf |  6 +-
 3 files changed, 60 insertions(+), 5 deletions(-)

diff --git a/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.c b/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.c
index 456d9f9..6886d01 100755
--- a/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.c
+++ b/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.c
@@ -33,6 +33,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *******************************************************************************/
 #include "MvSpiFlash.h"
 
+STATIC EFI_EVENT            mMvSpiFlashVirtualAddrChangeEvent;
 MARVELL_SPI_MASTER_PROTOCOL *SpiMasterProtocol;
 SPI_FLASH_INSTANCE  *mSpiFlashInstance;
 
@@ -503,6 +504,33 @@ MvSpiFlashInitProtocol (
   return EFI_SUCCESS;
 }
 
+/**
+  Fixup internal data so that EFI can be call in virtual mode.
+  Call the passed in Child Notify event and convert any pointers in
+  lib to virtual mode.
+
+  @param[in]    Event   The Event that is being processed
+  @param[in]    Context Event Context
+**/
+STATIC
+VOID
+EFIAPI
+MvSpiFlashVirtualNotifyEvent (
+  IN EFI_EVENT        Event,
+  IN VOID             *Context
+  )
+{
+  //
+  // Convert SpiMasterProtocol callbacks in MvSpiFlashErase and
+  // MvSpiFlashWrite required by runtime variable support.
+  //
+  EfiConvertPointer (0x0, (VOID**)&SpiMasterProtocol->ReadWrite);
+  EfiConvertPointer (0x0, (VOID**)&SpiMasterProtocol->Transfer);
+  EfiConvertPointer (0x0, (VOID**)&SpiMasterProtocol);
+
+  return;
+}
+
 EFI_STATUS
 EFIAPI
 MvSpiFlashEntryPoint (
@@ -522,8 +550,7 @@ MvSpiFlashEntryPoint (
     return EFI_DEVICE_ERROR;
   }
 
-  mSpiFlashInstance = AllocateZeroPool (sizeof (SPI_FLASH_INSTANCE));
-
+  mSpiFlashInstance = AllocateRuntimeZeroPool (sizeof (SPI_FLASH_INSTANCE));
   if (mSpiFlashInstance == NULL) {
     DEBUG((DEBUG_ERROR, "SpiFlash: Cannot allocate memory\n"));
     return EFI_OUT_OF_RESOURCES;
@@ -540,10 +567,33 @@ MvSpiFlashEntryPoint (
                   NULL
                   );
   if (EFI_ERROR (Status)) {
-    FreePool (mSpiFlashInstance);
     DEBUG((DEBUG_ERROR, "SpiFlash: Cannot install SPI flash protocol\n"));
-    return EFI_DEVICE_ERROR;
+    goto ErrorInstallProto;
+  }
+
+  //
+  // Register for the virtual address change event
+  //
+  Status = gBS->CreateEventEx (EVT_NOTIFY_SIGNAL,
+                  TPL_NOTIFY,
+                  MvSpiFlashVirtualNotifyEvent,
+                  NULL,
+                  &gEfiEventVirtualAddressChangeGuid,
+                  &mMvSpiFlashVirtualAddrChangeEvent);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: Failed to register VA change event\n", __FUNCTION__));
+    goto ErrorCreateEvent;
   }
 
   return EFI_SUCCESS;
+
+ErrorCreateEvent:
+  gBS->UninstallMultipleProtocolInterfaces (&mSpiFlashInstance->Handle,
+    &gMarvellSpiFlashProtocolGuid,
+    NULL);
+
+ErrorInstallProto:
+  FreePool (mSpiFlashInstance);
+
+  return EFI_SUCCESS;
 }
diff --git a/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.h b/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.h
index f09ff50..f69c562 100755
--- a/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.h
+++ b/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.h
@@ -42,6 +42,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include <Uefi/UefiBaseType.h>
 #include <Library/BaseMemoryLib.h>
 #include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiRuntimeLib.h>
 
 #include <Protocol/Spi.h>
 #include <Protocol/SpiFlash.h>
diff --git a/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.inf b/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.inf
index 6587f69..200a00c 100644
--- a/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.inf
+++ b/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.inf
@@ -33,7 +33,7 @@
   INF_VERSION                    = 0x00010005
   BASE_NAME                      = SpiFlashDxe
   FILE_GUID                      = 49d7fb74-306d-42bd-94c8-c0c54b181dd7
-  MODULE_TYPE                    = DXE_DRIVER
+  MODULE_TYPE                    = DXE_RUNTIME_DRIVER
   VERSION_STRING                 = 1.0
   ENTRY_POINT                    = MvSpiFlashEntryPoint
 
@@ -54,6 +54,10 @@
   UefiLib
   DebugLib
   MemoryAllocationLib
+  UefiRuntimeLib
+
+[Guids]
+  gEfiEventVirtualAddressChangeGuid
 
 [Protocols]
   gMarvellSpiMasterProtocolGuid
-- 
2.7.4

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [platforms: PATCH 1/4] Marvell/Drivers: MvSpiFlash: Enable using driver in RT
Posted by Leif Lindholm 7 years, 1 month ago
On Sun, Nov 05, 2017 at 11:55:36AM +0100, Marcin Wojtas wrote:
> This patch applies necessary modifications, which allow to use
> MvSpiFlash driver in variable support as a runtime service.
> Its type is modified to DXE_RUNTIME_DRIVER, as well as
> an event is created, which converts the pointers to the
> SpiMasterProtocol and its routines.

Please also move the Depex addition here from 4/4.
The rest looks fine.

/
    Leif

> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Marcin Wojtas <mw@semihalf.com>
> ---
>  Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.c   | 58 ++++++++++++++++++--
>  Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.h   |  1 +
>  Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.inf |  6 +-
>  3 files changed, 60 insertions(+), 5 deletions(-)
> 
> diff --git a/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.c b/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.c
> index 456d9f9..6886d01 100755
> --- a/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.c
> +++ b/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.c
> @@ -33,6 +33,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
>  *******************************************************************************/
>  #include "MvSpiFlash.h"
>  
> +STATIC EFI_EVENT            mMvSpiFlashVirtualAddrChangeEvent;
>  MARVELL_SPI_MASTER_PROTOCOL *SpiMasterProtocol;
>  SPI_FLASH_INSTANCE  *mSpiFlashInstance;
>  
> @@ -503,6 +504,33 @@ MvSpiFlashInitProtocol (
>    return EFI_SUCCESS;
>  }
>  
> +/**
> +  Fixup internal data so that EFI can be call in virtual mode.
> +  Call the passed in Child Notify event and convert any pointers in
> +  lib to virtual mode.
> +
> +  @param[in]    Event   The Event that is being processed
> +  @param[in]    Context Event Context
> +**/
> +STATIC
> +VOID
> +EFIAPI
> +MvSpiFlashVirtualNotifyEvent (
> +  IN EFI_EVENT        Event,
> +  IN VOID             *Context
> +  )
> +{
> +  //
> +  // Convert SpiMasterProtocol callbacks in MvSpiFlashErase and
> +  // MvSpiFlashWrite required by runtime variable support.
> +  //
> +  EfiConvertPointer (0x0, (VOID**)&SpiMasterProtocol->ReadWrite);
> +  EfiConvertPointer (0x0, (VOID**)&SpiMasterProtocol->Transfer);
> +  EfiConvertPointer (0x0, (VOID**)&SpiMasterProtocol);
> +
> +  return;
> +}
> +
>  EFI_STATUS
>  EFIAPI
>  MvSpiFlashEntryPoint (
> @@ -522,8 +550,7 @@ MvSpiFlashEntryPoint (
>      return EFI_DEVICE_ERROR;
>    }
>  
> -  mSpiFlashInstance = AllocateZeroPool (sizeof (SPI_FLASH_INSTANCE));
> -
> +  mSpiFlashInstance = AllocateRuntimeZeroPool (sizeof (SPI_FLASH_INSTANCE));
>    if (mSpiFlashInstance == NULL) {
>      DEBUG((DEBUG_ERROR, "SpiFlash: Cannot allocate memory\n"));
>      return EFI_OUT_OF_RESOURCES;
> @@ -540,10 +567,33 @@ MvSpiFlashEntryPoint (
>                    NULL
>                    );
>    if (EFI_ERROR (Status)) {
> -    FreePool (mSpiFlashInstance);
>      DEBUG((DEBUG_ERROR, "SpiFlash: Cannot install SPI flash protocol\n"));
> -    return EFI_DEVICE_ERROR;
> +    goto ErrorInstallProto;
> +  }
> +
> +  //
> +  // Register for the virtual address change event
> +  //
> +  Status = gBS->CreateEventEx (EVT_NOTIFY_SIGNAL,
> +                  TPL_NOTIFY,
> +                  MvSpiFlashVirtualNotifyEvent,
> +                  NULL,
> +                  &gEfiEventVirtualAddressChangeGuid,
> +                  &mMvSpiFlashVirtualAddrChangeEvent);
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((DEBUG_ERROR, "%a: Failed to register VA change event\n", __FUNCTION__));
> +    goto ErrorCreateEvent;
>    }
>  
>    return EFI_SUCCESS;
> +
> +ErrorCreateEvent:
> +  gBS->UninstallMultipleProtocolInterfaces (&mSpiFlashInstance->Handle,
> +    &gMarvellSpiFlashProtocolGuid,
> +    NULL);
> +
> +ErrorInstallProto:
> +  FreePool (mSpiFlashInstance);
> +
> +  return EFI_SUCCESS;
>  }
> diff --git a/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.h b/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.h
> index f09ff50..f69c562 100755
> --- a/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.h
> +++ b/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.h
> @@ -42,6 +42,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
>  #include <Uefi/UefiBaseType.h>
>  #include <Library/BaseMemoryLib.h>
>  #include <Library/UefiBootServicesTableLib.h>
> +#include <Library/UefiRuntimeLib.h>
>  
>  #include <Protocol/Spi.h>
>  #include <Protocol/SpiFlash.h>
> diff --git a/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.inf b/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.inf
> index 6587f69..200a00c 100644
> --- a/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.inf
> +++ b/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.inf
> @@ -33,7 +33,7 @@
>    INF_VERSION                    = 0x00010005
>    BASE_NAME                      = SpiFlashDxe
>    FILE_GUID                      = 49d7fb74-306d-42bd-94c8-c0c54b181dd7
> -  MODULE_TYPE                    = DXE_DRIVER
> +  MODULE_TYPE                    = DXE_RUNTIME_DRIVER
>    VERSION_STRING                 = 1.0
>    ENTRY_POINT                    = MvSpiFlashEntryPoint
>  
> @@ -54,6 +54,10 @@
>    UefiLib
>    DebugLib
>    MemoryAllocationLib
> +  UefiRuntimeLib
> +
> +[Guids]
> +  gEfiEventVirtualAddressChangeGuid
>  
>  [Protocols]
>    gMarvellSpiMasterProtocolGuid
> -- 
> 2.7.4
> 
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel