diff options
author | Marcin Wojtas <mw@semihalf.com> | 2017-10-21 11:46:24 +0200 |
---|---|---|
committer | Leif Lindholm <leif.lindholm@linaro.org> | 2017-11-30 15:50:16 +0000 |
commit | efd85c6b423095f841631301178959f791b21347 (patch) | |
tree | 03e5215623984f16c95240b72dd01b6810cb80a4 /Platform/Marvell/Drivers | |
parent | a35f740b6a2902387b46135ac777d71214109eeb (diff) | |
download | edk2-platforms-efd85c6b423095f841631301178959f791b21347.tar.xz |
Marvell/Drivers: MvSpiDxe: Enable using driver in RT
This patch applies necessary modifications, which allow to use
MvSpiDxe driver in variable support as a runtime service.
The driver's type is modified to DXE_RUNTIME_DRIVER, as well as
a new callback is introduced as a part of the SpiMasterProtocol.
It configures the memory space for mmio access to the host
controller registers.
Apply locking in the driver only during boot services. Once at
runtime, resource protection is handled by the operating system.
Moreover ensure proper execution order before MvSpiFlashDxe
(and hence MvFvbDxe) by setting according Depex dependency.
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Marcin Wojtas <mw@semihalf.com>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
Diffstat (limited to 'Platform/Marvell/Drivers')
-rwxr-xr-x | Platform/Marvell/Drivers/Spi/MvSpiDxe.c | 50 | ||||
-rw-r--r-- | Platform/Marvell/Drivers/Spi/MvSpiDxe.h | 2 | ||||
-rw-r--r-- | Platform/Marvell/Drivers/Spi/MvSpiDxe.inf | 9 |
3 files changed, 55 insertions, 6 deletions
diff --git a/Platform/Marvell/Drivers/Spi/MvSpiDxe.c b/Platform/Marvell/Drivers/Spi/MvSpiDxe.c index c60a520efc..bab6cf4d56 100755 --- a/Platform/Marvell/Drivers/Spi/MvSpiDxe.c +++ b/Platform/Marvell/Drivers/Spi/MvSpiDxe.c @@ -211,7 +211,9 @@ MvSpiTransfer ( Length = 8 * DataByteCount;
- EfiAcquireLock (&SpiMaster->Lock);
+ if (!EfiAtRuntime ()) {
+ EfiAcquireLock (&SpiMaster->Lock);
+ }
if (Flag & SPI_TRANSFER_BEGIN) {
SpiActivateCs (Slave);
@@ -254,7 +256,9 @@ MvSpiTransfer ( SpiDeactivateCs (Slave);
}
- EfiReleaseLock (&SpiMaster->Lock);
+ if (!EfiAtRuntime ()) {
+ EfiReleaseLock (&SpiMaster->Lock);
+ }
return EFI_SUCCESS;
}
@@ -338,6 +342,44 @@ MvSpiFreeSlave ( return EFI_SUCCESS;
}
+EFI_STATUS
+EFIAPI
+MvSpiConfigRuntime (
+ IN SPI_DEVICE *Slave
+ )
+{
+ EFI_STATUS Status;
+ UINTN AlignedAddress;
+
+ //
+ // Host register base may be not aligned to the page size,
+ // which is not accepted when setting memory space attributes.
+ // Add one aligned page of memory space which covers the host
+ // controller registers.
+ //
+ AlignedAddress = Slave->HostRegisterBaseAddress & ~(SIZE_4KB - 1);
+
+ Status = gDS->AddMemorySpace (EfiGcdMemoryTypeMemoryMappedIo,
+ AlignedAddress,
+ SIZE_4KB,
+ EFI_MEMORY_UC | EFI_MEMORY_RUNTIME);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: Failed to add memory space\n", __FUNCTION__));
+ return Status;
+ }
+
+ Status = gDS->SetMemorySpaceAttributes (AlignedAddress,
+ SIZE_4KB,
+ EFI_MEMORY_UC | EFI_MEMORY_RUNTIME);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: Failed to set memory attributes\n", __FUNCTION__));
+ gDS->RemoveMemorySpace (AlignedAddress, SIZE_4KB);
+ return Status;
+ }
+
+ return EFI_SUCCESS;
+}
+
STATIC
EFI_STATUS
SpiMasterInitProtocol (
@@ -350,6 +392,7 @@ SpiMasterInitProtocol ( SpiMasterProtocol->FreeDevice = MvSpiFreeSlave;
SpiMasterProtocol->Transfer = MvSpiTransfer;
SpiMasterProtocol->ReadWrite = MvSpiReadWrite;
+ SpiMasterProtocol->ConfigRuntime = MvSpiConfigRuntime;
return EFI_SUCCESS;
}
@@ -363,8 +406,7 @@ SpiMasterEntryPoint ( {
EFI_STATUS Status;
- mSpiMasterInstance = AllocateZeroPool (sizeof (SPI_MASTER));
-
+ mSpiMasterInstance = AllocateRuntimeZeroPool (sizeof (SPI_MASTER));
if (mSpiMasterInstance == NULL) {
return EFI_OUT_OF_RESOURCES;
}
diff --git a/Platform/Marvell/Drivers/Spi/MvSpiDxe.h b/Platform/Marvell/Drivers/Spi/MvSpiDxe.h index e7e280a799..50cdc025c7 100644 --- a/Platform/Marvell/Drivers/Spi/MvSpiDxe.h +++ b/Platform/Marvell/Drivers/Spi/MvSpiDxe.h @@ -38,10 +38,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <Library/PcdLib.h>
#include <Library/UefiLib.h>
#include <Library/DebugLib.h>
+#include <Library/DxeServicesTableLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Uefi/UefiBaseType.h>
#include <Library/BaseMemoryLib.h>
#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiRuntimeLib.h>
#include <Protocol/Spi.h>
diff --git a/Platform/Marvell/Drivers/Spi/MvSpiDxe.inf b/Platform/Marvell/Drivers/Spi/MvSpiDxe.inf index 08c6c04159..ac0e407092 100644 --- a/Platform/Marvell/Drivers/Spi/MvSpiDxe.inf +++ b/Platform/Marvell/Drivers/Spi/MvSpiDxe.inf @@ -33,7 +33,7 @@ INF_VERSION = 0x00010005
BASE_NAME = SpiMasterDxe
FILE_GUID = c19dbc8a-f4f9-43b0-aee5-802e3ed03d15
- MODULE_TYPE = DXE_DRIVER
+ MODULE_TYPE = DXE_RUNTIME_DRIVER
VERSION_STRING = 1.0
ENTRY_POINT = SpiMasterEntryPoint
@@ -53,8 +53,10 @@ TimerLib
UefiLib
DebugLib
+ DxeServicesTableLib
MemoryAllocationLib
IoLib
+ UefiRuntimeLib
[FixedPcd]
gMarvellTokenSpaceGuid.PcdSpiRegBase
@@ -65,4 +67,7 @@ gMarvellSpiMasterProtocolGuid
[Depex]
- TRUE
+ #
+ # MvSpiDxe must be loaded prior to MvSpiFlash driver
+ #
+ BEFORE gMarvellSpiFlashDxeGuid
|