2010-05-28 14:44:36 +02:00
|
|
|
/** @file
|
|
|
|
Generic ARM implementation of DmaLib.h
|
|
|
|
|
|
|
|
Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2010-05-28 14:44:36 +02:00
|
|
|
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 <Uefi.h>
|
|
|
|
#include <Library/DebugLib.h>
|
|
|
|
#include <Library/DmaLib.h>
|
|
|
|
#include <Library/MemoryAllocationLib.h>
|
|
|
|
|
|
|
|
|
2017-08-30 09:02:15 +02:00
|
|
|
STATIC
|
|
|
|
PHYSICAL_ADDRESS
|
|
|
|
HostToDeviceAddress (
|
|
|
|
IN VOID *Address
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return (PHYSICAL_ADDRESS)(UINTN)Address + PcdGet64 (PcdDmaDeviceOffset);
|
|
|
|
}
|
2010-05-28 14:44:36 +02:00
|
|
|
|
2014-08-19 15:29:52 +02:00
|
|
|
/**
|
2010-05-28 14:44:36 +02:00
|
|
|
Provides the DMA controller-specific addresses needed to access system memory.
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2010-05-28 14:44:36 +02:00
|
|
|
Operation is relative to the DMA bus master.
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2010-05-28 14:44:36 +02:00
|
|
|
@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 DMA controller.
|
|
|
|
@param NumberOfBytes On input the number of bytes to map. On output the number of bytes
|
2014-08-19 15:29:52 +02:00
|
|
|
that were mapped.
|
2010-05-28 14:44:36 +02:00
|
|
|
@param DeviceAddress The resulting map address for the bus master controller to use to
|
2014-08-19 15:29:52 +02:00
|
|
|
access the hosts HostAddress.
|
2010-05-28 14:44:36 +02:00
|
|
|
@param Mapping A resulting value to pass to Unmap().
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2010-05-28 14:44:36 +02:00
|
|
|
@retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.
|
2014-08-19 15:29:52 +02:00
|
|
|
@retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.
|
2010-05-28 14:44:36 +02:00
|
|
|
@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.
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2010-05-28 14:44:36 +02:00
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
DmaMap (
|
|
|
|
IN DMA_MAP_OPERATION Operation,
|
|
|
|
IN VOID *HostAddress,
|
|
|
|
IN OUT UINTN *NumberOfBytes,
|
|
|
|
OUT PHYSICAL_ADDRESS *DeviceAddress,
|
|
|
|
OUT VOID **Mapping
|
|
|
|
)
|
|
|
|
{
|
2018-09-06 20:55:03 +02:00
|
|
|
if (HostAddress == NULL ||
|
|
|
|
NumberOfBytes == NULL ||
|
|
|
|
DeviceAddress == NULL ||
|
|
|
|
Mapping == NULL ) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
2017-08-30 09:02:15 +02:00
|
|
|
*DeviceAddress = HostToDeviceAddress (HostAddress);
|
2010-05-29 00:50:59 +02:00
|
|
|
*Mapping = NULL;
|
2010-05-28 14:44:36 +02:00
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-19 15:29:52 +02:00
|
|
|
/**
|
2010-05-28 14:44:36 +02:00
|
|
|
Completes the DmaMapBusMasterRead(), DmaMapBusMasterWrite(), or DmaMapBusMasterCommonBuffer()
|
|
|
|
operation and releases any corresponding resources.
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2010-05-28 14:44:36 +02:00
|
|
|
@param Mapping The mapping value returned from DmaMap*().
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2010-05-28 14:44:36 +02:00
|
|
|
@retval EFI_SUCCESS The range was unmapped.
|
|
|
|
@retval EFI_DEVICE_ERROR The data was not committed to the target system memory.
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2010-05-28 14:44:36 +02:00
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
DmaUnmap (
|
|
|
|
IN VOID *Mapping
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2014-08-19 15:29:52 +02:00
|
|
|
/**
|
2010-05-28 14:44:36 +02:00
|
|
|
Allocates pages that are suitable for an DmaMap() of type MapOperationBusMasterCommonBuffer.
|
2014-08-19 15:29:52 +02:00
|
|
|
mapping.
|
|
|
|
|
2010-05-28 14:44:36 +02:00
|
|
|
@param MemoryType The type of memory to allocate, EfiBootServicesData or
|
2014-08-19 15:29:52 +02:00
|
|
|
EfiRuntimeServicesData.
|
|
|
|
@param Pages The number of pages to allocate.
|
2010-05-28 14:44:36 +02:00
|
|
|
@param HostAddress A pointer to store the base system memory address of the
|
2014-08-19 15:29:52 +02:00
|
|
|
allocated range.
|
2010-05-28 14:44:36 +02:00
|
|
|
|
|
|
|
@retval EFI_SUCCESS The requested memory pages were allocated.
|
|
|
|
@retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are
|
2014-08-19 15:29:52 +02:00
|
|
|
MEMORY_WRITE_COMBINE and MEMORY_CACHED.
|
2010-05-28 14:44:36 +02:00
|
|
|
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
|
2014-08-19 15:29:52 +02:00
|
|
|
@retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
|
|
|
|
|
2010-05-28 14:44:36 +02:00
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
DmaAllocateBuffer (
|
|
|
|
IN EFI_MEMORY_TYPE MemoryType,
|
|
|
|
IN UINTN Pages,
|
|
|
|
OUT VOID **HostAddress
|
|
|
|
)
|
|
|
|
{
|
2017-08-24 21:05:48 +02:00
|
|
|
return DmaAllocateAlignedBuffer (MemoryType, Pages, 0, HostAddress);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Allocates pages that are suitable for an DmaMap() of type
|
|
|
|
MapOperationBusMasterCommonBuffer mapping, at the requested alignment.
|
|
|
|
|
|
|
|
@param MemoryType The type of memory to allocate, EfiBootServicesData or
|
|
|
|
EfiRuntimeServicesData.
|
|
|
|
@param Pages The number of pages to allocate.
|
|
|
|
@param Alignment Alignment in bytes of the base of the returned
|
|
|
|
buffer (must be a power of 2)
|
|
|
|
@param HostAddress A pointer to store the base system memory address of the
|
|
|
|
allocated range.
|
|
|
|
|
|
|
|
@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
|
|
|
|
EFIAPI
|
|
|
|
DmaAllocateAlignedBuffer (
|
|
|
|
IN EFI_MEMORY_TYPE MemoryType,
|
|
|
|
IN UINTN Pages,
|
|
|
|
IN UINTN Alignment,
|
|
|
|
OUT VOID **HostAddress
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if (Alignment == 0) {
|
|
|
|
Alignment = EFI_PAGE_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (HostAddress == NULL ||
|
|
|
|
(Alignment & (Alignment - 1)) != 0) {
|
2010-05-28 14:44:36 +02:00
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// The only valid memory types are EfiBootServicesData and EfiRuntimeServicesData
|
|
|
|
//
|
|
|
|
if (MemoryType == EfiBootServicesData) {
|
2017-08-24 21:05:48 +02:00
|
|
|
*HostAddress = AllocateAlignedPages (Pages, Alignment);
|
2018-09-06 20:55:02 +02:00
|
|
|
} else if (MemoryType == EfiRuntimeServicesData) {
|
2017-08-24 21:05:48 +02:00
|
|
|
*HostAddress = AllocateAlignedRuntimePages (Pages, Alignment);
|
2010-05-28 14:44:36 +02:00
|
|
|
} else {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2017-08-24 21:05:48 +02:00
|
|
|
if (*HostAddress == NULL) {
|
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
2010-05-28 14:44:36 +02:00
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-19 15:29:52 +02:00
|
|
|
/**
|
2010-05-28 14:44:36 +02:00
|
|
|
Frees memory that was allocated with DmaAllocateBuffer().
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
|
|
@param Pages The number of pages to free.
|
|
|
|
@param HostAddress The base system memory address of the allocated range.
|
|
|
|
|
2010-05-28 14:44:36 +02:00
|
|
|
@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 DmaAllocateBuffer().
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2010-05-28 14:44:36 +02:00
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
DmaFreeBuffer (
|
|
|
|
IN UINTN Pages,
|
|
|
|
IN VOID *HostAddress
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if (HostAddress == NULL) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
2014-08-19 15:29:52 +02:00
|
|
|
}
|
|
|
|
|
2010-05-28 14:44:36 +02:00
|
|
|
FreePages (HostAddress, Pages);
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|