mirror of https://github.com/acidanthera/audk.git
MdeModulePkg/EmmcBlockIoPei: Support IoMmu
Update the EmmcBlockIoPei driver to consume IOMMU_PPI to allocate DMA buffer. If no IOMMU_PPI exists, this driver still calls PEI service to allocate DMA buffer, with assumption that DRAM==DMA. This is a compatible change. Cc: Jiewen Yao <jiewen.yao@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Hao Wu <hao.a.wu@intel.com> Reviewed-by: Star Zeng <star.zeng@intel.com>
This commit is contained in:
parent
44a0857ec6
commit
85ad9a6e0a
|
@ -0,0 +1,249 @@
|
||||||
|
/** @file
|
||||||
|
The DMA memory help function.
|
||||||
|
|
||||||
|
Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
|
||||||
|
|
||||||
|
This program and the accompanying materials
|
||||||
|
are licensed and made available under the terms and conditions
|
||||||
|
of the BSD License which accompanies this distribution. The
|
||||||
|
full text of the license may be found at
|
||||||
|
http://opensource.org/licenses/bsd-license.php
|
||||||
|
|
||||||
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include "EmmcBlockIoPei.h"
|
||||||
|
|
||||||
|
EDKII_IOMMU_PPI *mIoMmu;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Provides the controller-specific addresses required to access system memory from a
|
||||||
|
DMA bus master.
|
||||||
|
|
||||||
|
@param Operation Indicates if the bus master is going to read or write to system memory.
|
||||||
|
@param HostAddress The system memory address to map to the PCI controller.
|
||||||
|
@param NumberOfBytes On input the number of bytes to map. On output the number of bytes
|
||||||
|
that were mapped.
|
||||||
|
@param DeviceAddress The resulting map address for the bus master PCI controller to use to
|
||||||
|
access the hosts HostAddress.
|
||||||
|
@param Mapping A resulting value to pass to Unmap().
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.
|
||||||
|
@retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.
|
||||||
|
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
|
||||||
|
@retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
|
||||||
|
@retval EFI_DEVICE_ERROR The system hardware could not map the requested address.
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
IoMmuMap (
|
||||||
|
IN EDKII_IOMMU_OPERATION Operation,
|
||||||
|
IN VOID *HostAddress,
|
||||||
|
IN OUT UINTN *NumberOfBytes,
|
||||||
|
OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,
|
||||||
|
OUT VOID **Mapping
|
||||||
|
)
|
||||||
|
{
|
||||||
|
EFI_STATUS Status;
|
||||||
|
UINT64 Attribute;
|
||||||
|
|
||||||
|
if (mIoMmu != NULL) {
|
||||||
|
Status = mIoMmu->Map (
|
||||||
|
mIoMmu,
|
||||||
|
Operation,
|
||||||
|
HostAddress,
|
||||||
|
NumberOfBytes,
|
||||||
|
DeviceAddress,
|
||||||
|
Mapping
|
||||||
|
);
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
return EFI_OUT_OF_RESOURCES;
|
||||||
|
}
|
||||||
|
switch (Operation) {
|
||||||
|
case EdkiiIoMmuOperationBusMasterRead:
|
||||||
|
case EdkiiIoMmuOperationBusMasterRead64:
|
||||||
|
Attribute = EDKII_IOMMU_ACCESS_READ;
|
||||||
|
break;
|
||||||
|
case EdkiiIoMmuOperationBusMasterWrite:
|
||||||
|
case EdkiiIoMmuOperationBusMasterWrite64:
|
||||||
|
Attribute = EDKII_IOMMU_ACCESS_WRITE;
|
||||||
|
break;
|
||||||
|
case EdkiiIoMmuOperationBusMasterCommonBuffer:
|
||||||
|
case EdkiiIoMmuOperationBusMasterCommonBuffer64:
|
||||||
|
Attribute = EDKII_IOMMU_ACCESS_READ | EDKII_IOMMU_ACCESS_WRITE;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ASSERT(FALSE);
|
||||||
|
return EFI_INVALID_PARAMETER;
|
||||||
|
}
|
||||||
|
Status = mIoMmu->SetAttribute (
|
||||||
|
mIoMmu,
|
||||||
|
*Mapping,
|
||||||
|
Attribute
|
||||||
|
);
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
*DeviceAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)HostAddress;
|
||||||
|
*Mapping = NULL;
|
||||||
|
Status = EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Completes the Map() operation and releases any corresponding resources.
|
||||||
|
|
||||||
|
@param Mapping The mapping value returned from Map().
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS The range was unmapped.
|
||||||
|
@retval EFI_INVALID_PARAMETER Mapping is not a value that was returned by Map().
|
||||||
|
@retval EFI_DEVICE_ERROR The data was not committed to the target system memory.
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
IoMmuUnmap (
|
||||||
|
IN VOID *Mapping
|
||||||
|
)
|
||||||
|
{
|
||||||
|
EFI_STATUS Status;
|
||||||
|
|
||||||
|
if (mIoMmu != NULL) {
|
||||||
|
Status = mIoMmu->SetAttribute (mIoMmu, Mapping, 0);
|
||||||
|
Status = mIoMmu->Unmap (mIoMmu, Mapping);
|
||||||
|
} else {
|
||||||
|
Status = EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Allocates pages that are suitable for an OperationBusMasterCommonBuffer or
|
||||||
|
OperationBusMasterCommonBuffer64 mapping.
|
||||||
|
|
||||||
|
@param Pages The number of pages to allocate.
|
||||||
|
@param HostAddress A pointer to store the base system memory address of the
|
||||||
|
allocated range.
|
||||||
|
@param DeviceAddress The resulting map address for the bus master PCI controller to use to
|
||||||
|
access the hosts HostAddress.
|
||||||
|
@param Mapping A resulting value to pass to Unmap().
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS The requested memory pages were allocated.
|
||||||
|
@retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are
|
||||||
|
MEMORY_WRITE_COMBINE and MEMORY_CACHED.
|
||||||
|
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
|
||||||
|
@retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
IoMmuAllocateBuffer (
|
||||||
|
IN UINTN Pages,
|
||||||
|
OUT VOID **HostAddress,
|
||||||
|
OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,
|
||||||
|
OUT VOID **Mapping
|
||||||
|
)
|
||||||
|
{
|
||||||
|
EFI_STATUS Status;
|
||||||
|
UINTN NumberOfBytes;
|
||||||
|
EFI_PHYSICAL_ADDRESS HostPhyAddress;
|
||||||
|
|
||||||
|
*HostAddress = NULL;
|
||||||
|
*DeviceAddress = 0;
|
||||||
|
|
||||||
|
if (mIoMmu != NULL) {
|
||||||
|
Status = mIoMmu->AllocateBuffer (
|
||||||
|
mIoMmu,
|
||||||
|
EfiBootServicesData,
|
||||||
|
Pages,
|
||||||
|
HostAddress,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
return EFI_OUT_OF_RESOURCES;
|
||||||
|
}
|
||||||
|
|
||||||
|
NumberOfBytes = EFI_PAGES_TO_SIZE(Pages);
|
||||||
|
Status = mIoMmu->Map (
|
||||||
|
mIoMmu,
|
||||||
|
EdkiiIoMmuOperationBusMasterCommonBuffer,
|
||||||
|
*HostAddress,
|
||||||
|
&NumberOfBytes,
|
||||||
|
DeviceAddress,
|
||||||
|
Mapping
|
||||||
|
);
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
return EFI_OUT_OF_RESOURCES;
|
||||||
|
}
|
||||||
|
Status = mIoMmu->SetAttribute (
|
||||||
|
mIoMmu,
|
||||||
|
*Mapping,
|
||||||
|
EDKII_IOMMU_ACCESS_READ | EDKII_IOMMU_ACCESS_WRITE
|
||||||
|
);
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Status = PeiServicesAllocatePages (
|
||||||
|
EfiBootServicesData,
|
||||||
|
Pages,
|
||||||
|
&HostPhyAddress
|
||||||
|
);
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
return EFI_OUT_OF_RESOURCES;
|
||||||
|
}
|
||||||
|
*HostAddress = (VOID *)(UINTN)HostPhyAddress;
|
||||||
|
*DeviceAddress = HostPhyAddress;
|
||||||
|
*Mapping = NULL;
|
||||||
|
}
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Frees memory that was allocated with AllocateBuffer().
|
||||||
|
|
||||||
|
@param Pages The number of pages to free.
|
||||||
|
@param HostAddress The base system memory address of the allocated range.
|
||||||
|
@param Mapping The mapping value returned from Map().
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS The requested memory pages were freed.
|
||||||
|
@retval EFI_INVALID_PARAMETER The memory range specified by HostAddress and Pages
|
||||||
|
was not allocated with AllocateBuffer().
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
IoMmuFreeBuffer (
|
||||||
|
IN UINTN Pages,
|
||||||
|
IN VOID *HostAddress,
|
||||||
|
IN VOID *Mapping
|
||||||
|
)
|
||||||
|
{
|
||||||
|
EFI_STATUS Status;
|
||||||
|
|
||||||
|
if (mIoMmu != NULL) {
|
||||||
|
Status = mIoMmu->SetAttribute (mIoMmu, Mapping, 0);
|
||||||
|
Status = mIoMmu->Unmap (mIoMmu, Mapping);
|
||||||
|
Status = mIoMmu->FreeBuffer (mIoMmu, Pages, HostAddress);
|
||||||
|
} else {
|
||||||
|
Status = EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Initialize IOMMU.
|
||||||
|
**/
|
||||||
|
VOID
|
||||||
|
IoMmuInit (
|
||||||
|
VOID
|
||||||
|
)
|
||||||
|
{
|
||||||
|
PeiServicesLocatePpi (
|
||||||
|
&gEdkiiIoMmuPpiGuid,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
(VOID **)&mIoMmu
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/** @file
|
/** @file
|
||||||
|
|
||||||
Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
|
Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>
|
||||||
This program and the accompanying materials
|
This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
which accompanies this distribution. The full text of the license may be found at
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
@ -136,6 +136,11 @@ EMMC_PEIM_HC_PRIVATE_DATA gEmmcHcPrivateTemplate = {
|
||||||
&gEfiPeiVirtualBlockIo2PpiGuid,
|
&gEfiPeiVirtualBlockIo2PpiGuid,
|
||||||
NULL
|
NULL
|
||||||
},
|
},
|
||||||
|
{ // EndOfPeiNotifyList
|
||||||
|
(EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
|
||||||
|
&gEfiEndOfPeiSignalPpiGuid,
|
||||||
|
EmmcBlockIoPeimEndOfPei
|
||||||
|
},
|
||||||
{ // Slot
|
{ // Slot
|
||||||
{
|
{
|
||||||
0,
|
0,
|
||||||
|
@ -618,6 +623,36 @@ EmmcBlockIoPeimReadBlocks2 (
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
One notified function to cleanup the allocated DMA buffers at the end of PEI.
|
||||||
|
|
||||||
|
@param[in] PeiServices Pointer to PEI Services Table.
|
||||||
|
@param[in] NotifyDescriptor Pointer to the descriptor for the Notification
|
||||||
|
event that caused this function to execute.
|
||||||
|
@param[in] Ppi Pointer to the PPI data associated with this function.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS The function completes successfully
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
EmmcBlockIoPeimEndOfPei (
|
||||||
|
IN EFI_PEI_SERVICES **PeiServices,
|
||||||
|
IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
|
||||||
|
IN VOID *Ppi
|
||||||
|
)
|
||||||
|
{
|
||||||
|
EMMC_PEIM_HC_PRIVATE_DATA *Private;
|
||||||
|
|
||||||
|
Private = GET_EMMC_PEIM_HC_PRIVATE_DATA_FROM_THIS_NOTIFY (NotifyDescriptor);
|
||||||
|
|
||||||
|
if ((Private->Pool != NULL) && (Private->Pool->Head != NULL)) {
|
||||||
|
EmmcPeimFreeMemPool (Private->Pool);
|
||||||
|
}
|
||||||
|
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The user code starts with this function.
|
The user code starts with this function.
|
||||||
|
|
||||||
|
@ -672,6 +707,8 @@ InitializeEmmcBlockIoPeim (
|
||||||
return EFI_DEVICE_ERROR;
|
return EFI_DEVICE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IoMmuInit ();
|
||||||
|
|
||||||
Controller = 0;
|
Controller = 0;
|
||||||
MmioBase = NULL;
|
MmioBase = NULL;
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
|
@ -800,6 +837,11 @@ InitializeEmmcBlockIoPeim (
|
||||||
|
|
||||||
if (!EFI_ERROR (Status)) {
|
if (!EFI_ERROR (Status)) {
|
||||||
PeiServicesInstallPpi (&Private->BlkIoPpiList);
|
PeiServicesInstallPpi (&Private->BlkIoPpiList);
|
||||||
|
PeiServicesNotifyPpi (&Private->EndOfPeiNotifyList);
|
||||||
|
} else {
|
||||||
|
if (Private->Pool->Head != NULL) {
|
||||||
|
EmmcPeimFreeMemPool (Private->Pool);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/** @file
|
/** @file
|
||||||
|
|
||||||
Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
|
Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>
|
||||||
This program and the accompanying materials
|
This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
which accompanies this distribution. The full text of the license may be found at
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
@ -19,6 +19,8 @@
|
||||||
#include <Ppi/SdMmcHostController.h>
|
#include <Ppi/SdMmcHostController.h>
|
||||||
#include <Ppi/BlockIo.h>
|
#include <Ppi/BlockIo.h>
|
||||||
#include <Ppi/BlockIo2.h>
|
#include <Ppi/BlockIo2.h>
|
||||||
|
#include <Ppi/IoMmu.h>
|
||||||
|
#include <Ppi/EndOfPeiPhase.h>
|
||||||
|
|
||||||
#include <Library/DebugLib.h>
|
#include <Library/DebugLib.h>
|
||||||
#include <Library/BaseLib.h>
|
#include <Library/BaseLib.h>
|
||||||
|
@ -64,6 +66,12 @@ struct _EMMC_PEIM_HC_PRIVATE_DATA {
|
||||||
EFI_PEI_RECOVERY_BLOCK_IO2_PPI BlkIo2Ppi;
|
EFI_PEI_RECOVERY_BLOCK_IO2_PPI BlkIo2Ppi;
|
||||||
EFI_PEI_PPI_DESCRIPTOR BlkIoPpiList;
|
EFI_PEI_PPI_DESCRIPTOR BlkIoPpiList;
|
||||||
EFI_PEI_PPI_DESCRIPTOR BlkIo2PpiList;
|
EFI_PEI_PPI_DESCRIPTOR BlkIo2PpiList;
|
||||||
|
|
||||||
|
//
|
||||||
|
// EndOfPei callback is used to do the cleanups before exit of PEI phase.
|
||||||
|
//
|
||||||
|
EFI_PEI_NOTIFY_DESCRIPTOR EndOfPeiNotifyList;
|
||||||
|
|
||||||
EMMC_PEIM_HC_SLOT Slot[EMMC_PEIM_MAX_SLOTS];
|
EMMC_PEIM_HC_SLOT Slot[EMMC_PEIM_MAX_SLOTS];
|
||||||
UINT8 SlotNum;
|
UINT8 SlotNum;
|
||||||
UINT8 TotalBlkIoDevices;
|
UINT8 TotalBlkIoDevices;
|
||||||
|
@ -72,6 +80,7 @@ struct _EMMC_PEIM_HC_PRIVATE_DATA {
|
||||||
#define EMMC_TIMEOUT MultU64x32((UINT64)(3), 1000000)
|
#define EMMC_TIMEOUT MultU64x32((UINT64)(3), 1000000)
|
||||||
#define GET_EMMC_PEIM_HC_PRIVATE_DATA_FROM_THIS(a) CR (a, EMMC_PEIM_HC_PRIVATE_DATA, BlkIoPpi, EMMC_PEIM_SIG)
|
#define GET_EMMC_PEIM_HC_PRIVATE_DATA_FROM_THIS(a) CR (a, EMMC_PEIM_HC_PRIVATE_DATA, BlkIoPpi, EMMC_PEIM_SIG)
|
||||||
#define GET_EMMC_PEIM_HC_PRIVATE_DATA_FROM_THIS2(a) CR (a, EMMC_PEIM_HC_PRIVATE_DATA, BlkIo2Ppi, EMMC_PEIM_SIG)
|
#define GET_EMMC_PEIM_HC_PRIVATE_DATA_FROM_THIS2(a) CR (a, EMMC_PEIM_HC_PRIVATE_DATA, BlkIo2Ppi, EMMC_PEIM_SIG)
|
||||||
|
#define GET_EMMC_PEIM_HC_PRIVATE_DATA_FROM_THIS_NOTIFY(a) CR (a, EMMC_PEIM_HC_PRIVATE_DATA, EndOfPeiNotifyList, EMMC_PEIM_SIG)
|
||||||
|
|
||||||
struct _EMMC_TRB {
|
struct _EMMC_TRB {
|
||||||
EMMC_PEIM_HC_SLOT *Slot;
|
EMMC_PEIM_HC_SLOT *Slot;
|
||||||
|
@ -81,6 +90,8 @@ struct _EMMC_TRB {
|
||||||
VOID *Data;
|
VOID *Data;
|
||||||
UINT32 DataLen;
|
UINT32 DataLen;
|
||||||
BOOLEAN Read;
|
BOOLEAN Read;
|
||||||
|
EFI_PHYSICAL_ADDRESS DataPhy;
|
||||||
|
VOID *DataMap;
|
||||||
EMMC_HC_TRANSFER_MODE Mode;
|
EMMC_HC_TRANSFER_MODE Mode;
|
||||||
|
|
||||||
UINT64 Timeout;
|
UINT64 Timeout;
|
||||||
|
@ -347,6 +358,20 @@ EmmcPeimInitMemPool (
|
||||||
IN EMMC_PEIM_HC_PRIVATE_DATA *Private
|
IN EMMC_PEIM_HC_PRIVATE_DATA *Private
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Release the memory management pool.
|
||||||
|
|
||||||
|
@param Pool The memory pool to free.
|
||||||
|
|
||||||
|
@retval EFI_DEVICE_ERROR Fail to free the memory pool.
|
||||||
|
@retval EFI_SUCCESS The memory pool is freed.
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EmmcPeimFreeMemPool (
|
||||||
|
IN EMMC_PEIM_MEM_POOL *Pool
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Allocate some memory from the host controller's memory pool
|
Allocate some memory from the host controller's memory pool
|
||||||
which can be used to communicate with host controller.
|
which can be used to communicate with host controller.
|
||||||
|
@ -378,4 +403,118 @@ EmmcPeimFreeMem (
|
||||||
IN UINTN Size
|
IN UINTN Size
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Initialize IOMMU.
|
||||||
|
**/
|
||||||
|
VOID
|
||||||
|
IoMmuInit (
|
||||||
|
VOID
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Provides the controller-specific addresses required to access system memory from a
|
||||||
|
DMA bus master.
|
||||||
|
|
||||||
|
@param Operation Indicates if the bus master is going to read or write to system memory.
|
||||||
|
@param HostAddress The system memory address to map to the PCI controller.
|
||||||
|
@param NumberOfBytes On input the number of bytes to map. On output the number of bytes
|
||||||
|
that were mapped.
|
||||||
|
@param DeviceAddress The resulting map address for the bus master PCI controller to use to
|
||||||
|
access the hosts HostAddress.
|
||||||
|
@param Mapping A resulting value to pass to Unmap().
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.
|
||||||
|
@retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.
|
||||||
|
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
|
||||||
|
@retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
|
||||||
|
@retval EFI_DEVICE_ERROR The system hardware could not map the requested address.
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
IoMmuMap (
|
||||||
|
IN EDKII_IOMMU_OPERATION Operation,
|
||||||
|
IN VOID *HostAddress,
|
||||||
|
IN OUT UINTN *NumberOfBytes,
|
||||||
|
OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,
|
||||||
|
OUT VOID **Mapping
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Completes the Map() operation and releases any corresponding resources.
|
||||||
|
|
||||||
|
@param Mapping The mapping value returned from Map().
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS The range was unmapped.
|
||||||
|
@retval EFI_INVALID_PARAMETER Mapping is not a value that was returned by Map().
|
||||||
|
@retval EFI_DEVICE_ERROR The data was not committed to the target system memory.
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
IoMmuUnmap (
|
||||||
|
IN VOID *Mapping
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Allocates pages that are suitable for an OperationBusMasterCommonBuffer or
|
||||||
|
OperationBusMasterCommonBuffer64 mapping.
|
||||||
|
|
||||||
|
@param Pages The number of pages to allocate.
|
||||||
|
@param HostAddress A pointer to store the base system memory address of the
|
||||||
|
allocated range.
|
||||||
|
@param DeviceAddress The resulting map address for the bus master PCI controller to use to
|
||||||
|
access the hosts HostAddress.
|
||||||
|
@param Mapping A resulting value to pass to Unmap().
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS The requested memory pages were allocated.
|
||||||
|
@retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are
|
||||||
|
MEMORY_WRITE_COMBINE and MEMORY_CACHED.
|
||||||
|
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
|
||||||
|
@retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
IoMmuAllocateBuffer (
|
||||||
|
IN UINTN Pages,
|
||||||
|
OUT VOID **HostAddress,
|
||||||
|
OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,
|
||||||
|
OUT VOID **Mapping
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Frees memory that was allocated with AllocateBuffer().
|
||||||
|
|
||||||
|
@param Pages The number of pages to free.
|
||||||
|
@param HostAddress The base system memory address of the allocated range.
|
||||||
|
@param Mapping The mapping value returned from Map().
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS The requested memory pages were freed.
|
||||||
|
@retval EFI_INVALID_PARAMETER The memory range specified by HostAddress and Pages
|
||||||
|
was not allocated with AllocateBuffer().
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
IoMmuFreeBuffer (
|
||||||
|
IN UINTN Pages,
|
||||||
|
IN VOID *HostAddress,
|
||||||
|
IN VOID *Mapping
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
One notified function to cleanup the allocated DMA buffers at the end of PEI.
|
||||||
|
|
||||||
|
@param[in] PeiServices Pointer to PEI Services Table.
|
||||||
|
@param[in] NotifyDescriptor Pointer to the descriptor for the Notification
|
||||||
|
event that caused this function to execute.
|
||||||
|
@param[in] Ppi Pointer to the PPI data associated with this function.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS The function completes successfully
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
EmmcBlockIoPeimEndOfPei (
|
||||||
|
IN EFI_PEI_SERVICES **PeiServices,
|
||||||
|
IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
|
||||||
|
IN VOID *Ppi
|
||||||
|
);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
## @file
|
## @file
|
||||||
# Description file for the Embedded MMC (eMMC) Peim driver.
|
# Description file for the Embedded MMC (eMMC) Peim driver.
|
||||||
#
|
#
|
||||||
# Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
|
# Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>
|
||||||
#
|
#
|
||||||
# This program and the accompanying materials
|
# This program and the accompanying materials
|
||||||
# are licensed and made available under the terms and conditions of the BSD License
|
# are licensed and made available under the terms and conditions of the BSD License
|
||||||
|
@ -36,6 +36,7 @@
|
||||||
EmmcHci.h
|
EmmcHci.h
|
||||||
EmmcHcMem.c
|
EmmcHcMem.c
|
||||||
EmmcHcMem.h
|
EmmcHcMem.h
|
||||||
|
DmaMem.c
|
||||||
|
|
||||||
[Packages]
|
[Packages]
|
||||||
MdePkg/MdePkg.dec
|
MdePkg/MdePkg.dec
|
||||||
|
@ -53,6 +54,8 @@
|
||||||
gEfiPeiVirtualBlockIoPpiGuid ## PRODUCES
|
gEfiPeiVirtualBlockIoPpiGuid ## PRODUCES
|
||||||
gEfiPeiVirtualBlockIo2PpiGuid ## PRODUCES
|
gEfiPeiVirtualBlockIo2PpiGuid ## PRODUCES
|
||||||
gEdkiiPeiSdMmcHostControllerPpiGuid ## CONSUMES
|
gEdkiiPeiSdMmcHostControllerPpiGuid ## CONSUMES
|
||||||
|
gEdkiiIoMmuPpiGuid ## CONSUMES
|
||||||
|
gEfiEndOfPeiSignalPpiGuid ## CONSUMES
|
||||||
|
|
||||||
[Depex]
|
[Depex]
|
||||||
gEfiPeiMemoryDiscoveredPpiGuid AND gEdkiiPeiSdMmcHostControllerPpiGuid
|
gEfiPeiMemoryDiscoveredPpiGuid AND gEdkiiPeiSdMmcHostControllerPpiGuid
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/** @file
|
/** @file
|
||||||
|
|
||||||
Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
|
Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.<BR>
|
||||||
|
|
||||||
This program and the accompanying materials
|
This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions
|
are licensed and made available under the terms and conditions
|
||||||
|
@ -29,9 +29,11 @@ EmmcPeimAllocMemBlock (
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EMMC_PEIM_MEM_BLOCK *Block;
|
EMMC_PEIM_MEM_BLOCK *Block;
|
||||||
|
VOID *BufHost;
|
||||||
|
VOID *Mapping;
|
||||||
|
EFI_PHYSICAL_ADDRESS MappedAddr;
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
VOID *TempPtr;
|
VOID *TempPtr;
|
||||||
EFI_PHYSICAL_ADDRESS Address;
|
|
||||||
|
|
||||||
TempPtr = NULL;
|
TempPtr = NULL;
|
||||||
Block = NULL;
|
Block = NULL;
|
||||||
|
@ -62,19 +64,22 @@ EmmcPeimAllocMemBlock (
|
||||||
|
|
||||||
Block->Bits = (UINT8*)(UINTN)TempPtr;
|
Block->Bits = (UINT8*)(UINTN)TempPtr;
|
||||||
|
|
||||||
Status = PeiServicesAllocatePages (
|
Status = IoMmuAllocateBuffer (
|
||||||
EfiBootServicesCode,
|
|
||||||
Pages,
|
Pages,
|
||||||
&Address
|
&BufHost,
|
||||||
|
&MappedAddr,
|
||||||
|
&Mapping
|
||||||
);
|
);
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ZeroMem ((VOID*)(UINTN)Address, EFI_PAGES_TO_SIZE (Pages));
|
ZeroMem ((VOID*)(UINTN)BufHost, EFI_PAGES_TO_SIZE (Pages));
|
||||||
|
|
||||||
Block->Buf = (UINT8*)((UINTN)Address);
|
Block->BufHost = (UINT8 *) (UINTN) BufHost;
|
||||||
Block->Next = NULL;
|
Block->Buf = (UINT8 *) (UINTN) MappedAddr;
|
||||||
|
Block->Mapping = Mapping;
|
||||||
|
Block->Next = NULL;
|
||||||
|
|
||||||
return Block;
|
return Block;
|
||||||
}
|
}
|
||||||
|
@ -93,6 +98,8 @@ EmmcPeimFreeMemBlock (
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
ASSERT ((Pool != NULL) && (Block != NULL));
|
ASSERT ((Pool != NULL) && (Block != NULL));
|
||||||
|
|
||||||
|
IoMmuFreeBuffer (EFI_SIZE_TO_PAGES (Block->BufLen), Block->BufHost, Block->Mapping);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/** @file
|
/** @file
|
||||||
|
|
||||||
Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
|
Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>
|
||||||
|
|
||||||
This program and the accompanying materials
|
This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions
|
are licensed and made available under the terms and conditions
|
||||||
|
@ -27,7 +27,9 @@ struct _EMMC_PEIM_MEM_BLOCK {
|
||||||
UINT8 *Bits; // Bit array to record which unit is allocated
|
UINT8 *Bits; // Bit array to record which unit is allocated
|
||||||
UINTN BitsLen;
|
UINTN BitsLen;
|
||||||
UINT8 *Buf;
|
UINT8 *Buf;
|
||||||
|
UINT8 *BufHost;
|
||||||
UINTN BufLen; // Memory size in bytes
|
UINTN BufLen; // Memory size in bytes
|
||||||
|
VOID *Mapping;
|
||||||
EMMC_PEIM_MEM_BLOCK *Next;
|
EMMC_PEIM_MEM_BLOCK *Next;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -929,7 +929,7 @@ BuildAdmaDescTable (
|
||||||
UINT64 Remaining;
|
UINT64 Remaining;
|
||||||
UINT32 Address;
|
UINT32 Address;
|
||||||
|
|
||||||
Data = (EFI_PHYSICAL_ADDRESS)(UINTN)Trb->Data;
|
Data = Trb->DataPhy;
|
||||||
DataLen = Trb->DataLen;
|
DataLen = Trb->DataLen;
|
||||||
//
|
//
|
||||||
// Only support 32bit ADMA Descriptor Table
|
// Only support 32bit ADMA Descriptor Table
|
||||||
|
@ -998,6 +998,8 @@ EmmcPeimCreateTrb (
|
||||||
EMMC_TRB *Trb;
|
EMMC_TRB *Trb;
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
EMMC_HC_SLOT_CAP Capability;
|
EMMC_HC_SLOT_CAP Capability;
|
||||||
|
EDKII_IOMMU_OPERATION MapOp;
|
||||||
|
UINTN MapLength;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Calculate a divisor for SD clock frequency
|
// Calculate a divisor for SD clock frequency
|
||||||
|
@ -1007,7 +1009,7 @@ EmmcPeimCreateTrb (
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Trb = EmmcPeimAllocateMem (Slot->Private->Pool, sizeof (EMMC_TRB));
|
Trb = AllocateZeroPool (sizeof (EMMC_TRB));
|
||||||
if (Trb == NULL) {
|
if (Trb == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -1039,6 +1041,22 @@ EmmcPeimCreateTrb (
|
||||||
if (Packet->EmmcCmdBlk->CommandIndex == EMMC_SEND_TUNING_BLOCK) {
|
if (Packet->EmmcCmdBlk->CommandIndex == EMMC_SEND_TUNING_BLOCK) {
|
||||||
Trb->Mode = EmmcPioMode;
|
Trb->Mode = EmmcPioMode;
|
||||||
} else {
|
} else {
|
||||||
|
if (Trb->Read) {
|
||||||
|
MapOp = EdkiiIoMmuOperationBusMasterWrite;
|
||||||
|
} else {
|
||||||
|
MapOp = EdkiiIoMmuOperationBusMasterRead;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Trb->DataLen != 0) {
|
||||||
|
MapLength = Trb->DataLen;
|
||||||
|
Status = IoMmuMap (MapOp, Trb->Data, &MapLength, &Trb->DataPhy, &Trb->DataMap);
|
||||||
|
|
||||||
|
if (EFI_ERROR (Status) || (MapLength != Trb->DataLen)) {
|
||||||
|
DEBUG ((DEBUG_ERROR, "EmmcPeimCreateTrb: Fail to map data buffer.\n"));
|
||||||
|
goto Error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (Trb->DataLen == 0) {
|
if (Trb->DataLen == 0) {
|
||||||
Trb->Mode = EmmcNoData;
|
Trb->Mode = EmmcNoData;
|
||||||
} else if (Capability.Adma2 != 0) {
|
} else if (Capability.Adma2 != 0) {
|
||||||
|
@ -1071,12 +1089,16 @@ EmmcPeimFreeTrb (
|
||||||
IN EMMC_TRB *Trb
|
IN EMMC_TRB *Trb
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
if ((Trb != NULL) && (Trb->DataMap != NULL)) {
|
||||||
|
IoMmuUnmap (Trb->DataMap);
|
||||||
|
}
|
||||||
|
|
||||||
if ((Trb != NULL) && (Trb->AdmaDesc != NULL)) {
|
if ((Trb != NULL) && (Trb->AdmaDesc != NULL)) {
|
||||||
EmmcPeimFreeMem (Trb->Slot->Private->Pool, Trb->AdmaDesc, Trb->AdmaDescSize);
|
EmmcPeimFreeMem (Trb->Slot->Private->Pool, Trb->AdmaDesc, Trb->AdmaDescSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Trb != NULL) {
|
if (Trb != NULL) {
|
||||||
EmmcPeimFreeMem (Trb->Slot->Private->Pool, Trb, sizeof (EMMC_TRB));
|
FreePool (Trb);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1241,11 +1263,11 @@ EmmcPeimExecTrb (
|
||||||
EmmcPeimHcLedOnOff (Bar, TRUE);
|
EmmcPeimHcLedOnOff (Bar, TRUE);
|
||||||
|
|
||||||
if (Trb->Mode == EmmcSdmaMode) {
|
if (Trb->Mode == EmmcSdmaMode) {
|
||||||
if ((UINT64)(UINTN)Trb->Data >= 0x100000000ul) {
|
if ((UINT64)(UINTN)Trb->DataPhy >= 0x100000000ul) {
|
||||||
return EFI_INVALID_PARAMETER;
|
return EFI_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
SdmaAddr = (UINT32)(UINTN)Trb->Data;
|
SdmaAddr = (UINT32)(UINTN)Trb->DataPhy;
|
||||||
Status = EmmcPeimHcRwMmio (Bar + EMMC_HC_SDMA_ADDR, FALSE, sizeof (SdmaAddr), &SdmaAddr);
|
Status = EmmcPeimHcRwMmio (Bar + EMMC_HC_SDMA_ADDR, FALSE, sizeof (SdmaAddr), &SdmaAddr);
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
return Status;
|
return Status;
|
||||||
|
@ -1480,7 +1502,7 @@ EmmcPeimCheckTrbResult (
|
||||||
//
|
//
|
||||||
// Update SDMA Address register.
|
// Update SDMA Address register.
|
||||||
//
|
//
|
||||||
SdmaAddr = EMMC_SDMA_ROUND_UP ((UINT32)(UINTN)Trb->Data, EMMC_SDMA_BOUNDARY);
|
SdmaAddr = EMMC_SDMA_ROUND_UP ((UINT32)(UINTN)Trb->DataPhy, EMMC_SDMA_BOUNDARY);
|
||||||
Status = EmmcPeimHcRwMmio (
|
Status = EmmcPeimHcRwMmio (
|
||||||
Bar + EMMC_HC_SDMA_ADDR,
|
Bar + EMMC_HC_SDMA_ADDR,
|
||||||
FALSE,
|
FALSE,
|
||||||
|
@ -1490,7 +1512,7 @@ EmmcPeimCheckTrbResult (
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
goto Done;
|
goto Done;
|
||||||
}
|
}
|
||||||
Trb->Data = (VOID*)(UINTN)SdmaAddr;
|
Trb->DataPhy = (UINT32)(UINTN)SdmaAddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((Packet->EmmcCmdBlk->CommandType != EmmcCommandTypeAdtc) &&
|
if ((Packet->EmmcCmdBlk->CommandType != EmmcCommandTypeAdtc) &&
|
||||||
|
|
Loading…
Reference in New Issue