2013-01-25 12:28:06 +01:00
|
|
|
/** @file
|
|
|
|
DMA abstraction library APIs. Based on UEFI PCI IO protocol DMA abstractions.
|
2014-08-19 15:29:52 +02:00
|
|
|
At some point these functions will probably end up in a non PCI protocol
|
2013-01-25 12:28:06 +01:00
|
|
|
for embedded systems.
|
|
|
|
|
2010-05-28 14:44:36 +02:00
|
|
|
DMA Bus Master Read Operation:
|
2014-08-19 15:29:52 +02:00
|
|
|
Call DmaMap() for MapOperationBusMasterRead.
|
|
|
|
Program the DMA Bus Master with the DeviceAddress returned by DmaMap().
|
|
|
|
Start the DMA Bus Master.
|
|
|
|
Wait for DMA Bus Master to complete the read operation.
|
2013-01-25 12:28:06 +01:00
|
|
|
Call DmaUnmap().
|
|
|
|
|
|
|
|
DMA Bus Master Write Operation:
|
2010-05-28 14:44:36 +02:00
|
|
|
Call DmaMap() for MapOperationBusMasterWrite.
|
|
|
|
Program the DMA Bus Master with the DeviceAddress returned by DmaMap().
|
|
|
|
Start the DMA Bus Master.
|
|
|
|
Wait for DMA Bus Master to complete the write operation.
|
2013-01-25 12:28:06 +01:00
|
|
|
Call DmaUnmap().
|
|
|
|
|
|
|
|
DMA Bus Master Common Buffer Operation:
|
2014-08-19 15:29:52 +02:00
|
|
|
Call DmaAllocateBuffer() to allocate a common buffer.
|
|
|
|
Call DmaMap() for MapOperationBusMasterCommonBuffer.
|
|
|
|
Program the DMA Bus Master with the DeviceAddress returned by DmaMap().
|
|
|
|
The common buffer can now be accessed equally by the processor and the DMA bus master.
|
|
|
|
Call DmaUnmap().
|
2013-01-25 12:28:06 +01:00
|
|
|
Call DmaFreeBuffer().
|
|
|
|
|
|
|
|
Copyright (c) 2008 - 2010, Apple Inc. 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.
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
#ifndef __DMA_LIB_H__
|
|
|
|
#define __DMA_LIB_H__
|
|
|
|
|
2010-05-28 14:44:36 +02:00
|
|
|
typedef enum {
|
|
|
|
///
|
|
|
|
/// A read operation from system memory by a bus master.
|
|
|
|
///
|
|
|
|
MapOperationBusMasterRead,
|
|
|
|
///
|
|
|
|
/// A write operation from system memory by a bus master.
|
|
|
|
///
|
|
|
|
MapOperationBusMasterWrite,
|
|
|
|
///
|
|
|
|
/// Provides both read and write access to system memory by both the processor and a
|
|
|
|
/// bus master. The buffer is coherent from both the processor's and the bus master's point of view.
|
|
|
|
///
|
|
|
|
MapOperationBusMasterCommonBuffer,
|
|
|
|
MapOperationMaximum
|
|
|
|
} DMA_MAP_OPERATION;
|
2013-01-25 12:28:06 +01: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 DmaUnmap().
|
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
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
DmaMap (
|
|
|
|
IN DMA_MAP_OPERATION Operation,
|
2010-05-28 14:44:36 +02:00
|
|
|
IN VOID *HostAddress,
|
|
|
|
IN OUT UINTN *NumberOfBytes,
|
|
|
|
OUT PHYSICAL_ADDRESS *DeviceAddress,
|
|
|
|
OUT VOID **Mapping
|
2013-01-25 12:28:06 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
DmaUnmap (
|
2010-05-28 14:44:36 +02:00
|
|
|
IN VOID *Mapping
|
2013-01-25 12:28:06 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
DmaAllocateBuffer (
|
|
|
|
IN EFI_MEMORY_TYPE MemoryType,
|
2010-05-28 14:44:36 +02:00
|
|
|
IN UINTN Pages,
|
|
|
|
OUT VOID **HostAddress
|
|
|
|
);
|
2013-01-25 12:28:06 +01:00
|
|
|
|
|
|
|
|
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
|
|
|
**/
|
2013-01-25 12:28:06 +01:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
DmaFreeBuffer (
|
2010-05-28 14:44:36 +02:00
|
|
|
IN UINTN Pages,
|
|
|
|
IN VOID *HostAddress
|
|
|
|
);
|
2013-01-25 12:28:06 +01:00
|
|
|
|
|
|
|
|
2014-08-19 15:29:52 +02:00
|
|
|
#endif
|
2013-01-25 12:28:06 +01:00
|
|
|
|