2 The DMA memory help function.
4 Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions
8 of the BSD License which accompanies this distribution. The
9 full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 EDKII_IOMMU_PPI
*mIoMmu
;
22 Provides the controller-specific addresses required to access system memory from a
25 @param Operation Indicates if the bus master is going to read or write to system memory.
26 @param HostAddress The system memory address to map to the PCI controller.
27 @param NumberOfBytes On input the number of bytes to map. On output the number of bytes
29 @param DeviceAddress The resulting map address for the bus master PCI controller to use to
30 access the hosts HostAddress.
31 @param Mapping A resulting value to pass to Unmap().
33 @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.
34 @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.
35 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
36 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
37 @retval EFI_DEVICE_ERROR The system hardware could not map the requested address.
42 IN EDKII_IOMMU_OPERATION Operation
,
44 IN OUT UINTN
*NumberOfBytes
,
45 OUT EFI_PHYSICAL_ADDRESS
*DeviceAddress
,
53 Status
= mIoMmu
->Map (
61 if (EFI_ERROR (Status
)) {
62 return EFI_OUT_OF_RESOURCES
;
65 case EdkiiIoMmuOperationBusMasterRead
:
66 case EdkiiIoMmuOperationBusMasterRead64
:
67 Attribute
= EDKII_IOMMU_ACCESS_READ
;
69 case EdkiiIoMmuOperationBusMasterWrite
:
70 case EdkiiIoMmuOperationBusMasterWrite64
:
71 Attribute
= EDKII_IOMMU_ACCESS_WRITE
;
73 case EdkiiIoMmuOperationBusMasterCommonBuffer
:
74 case EdkiiIoMmuOperationBusMasterCommonBuffer64
:
75 Attribute
= EDKII_IOMMU_ACCESS_READ
| EDKII_IOMMU_ACCESS_WRITE
;
79 return EFI_INVALID_PARAMETER
;
81 Status
= mIoMmu
->SetAttribute (
86 if (EFI_ERROR (Status
)) {
90 *DeviceAddress
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)HostAddress
;
98 Completes the Map() operation and releases any corresponding resources.
100 @param Mapping The mapping value returned from Map().
102 @retval EFI_SUCCESS The range was unmapped.
103 @retval EFI_INVALID_PARAMETER Mapping is not a value that was returned by Map().
104 @retval EFI_DEVICE_ERROR The data was not committed to the target system memory.
113 if (mIoMmu
!= NULL
) {
114 Status
= mIoMmu
->SetAttribute (mIoMmu
, Mapping
, 0);
115 Status
= mIoMmu
->Unmap (mIoMmu
, Mapping
);
117 Status
= EFI_SUCCESS
;
123 Allocates pages that are suitable for an OperationBusMasterCommonBuffer or
124 OperationBusMasterCommonBuffer64 mapping.
126 @param Pages The number of pages to allocate.
127 @param HostAddress A pointer to store the base system memory address of the
129 @param DeviceAddress The resulting map address for the bus master PCI controller to use to
130 access the hosts HostAddress.
131 @param Mapping A resulting value to pass to Unmap().
133 @retval EFI_SUCCESS The requested memory pages were allocated.
134 @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are
135 MEMORY_WRITE_COMBINE and MEMORY_CACHED.
136 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
137 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
141 IoMmuAllocateBuffer (
143 OUT VOID
**HostAddress
,
144 OUT EFI_PHYSICAL_ADDRESS
*DeviceAddress
,
150 EFI_PHYSICAL_ADDRESS HostPhyAddress
;
155 if (mIoMmu
!= NULL
) {
156 Status
= mIoMmu
->AllocateBuffer (
163 if (EFI_ERROR (Status
)) {
164 return EFI_OUT_OF_RESOURCES
;
167 NumberOfBytes
= EFI_PAGES_TO_SIZE(Pages
);
168 Status
= mIoMmu
->Map (
170 EdkiiIoMmuOperationBusMasterCommonBuffer
,
176 if (EFI_ERROR (Status
)) {
177 return EFI_OUT_OF_RESOURCES
;
179 Status
= mIoMmu
->SetAttribute (
182 EDKII_IOMMU_ACCESS_READ
| EDKII_IOMMU_ACCESS_WRITE
184 if (EFI_ERROR (Status
)) {
188 Status
= PeiServicesAllocatePages (
193 if (EFI_ERROR (Status
)) {
194 return EFI_OUT_OF_RESOURCES
;
196 *HostAddress
= (VOID
*)(UINTN
)HostPhyAddress
;
197 *DeviceAddress
= HostPhyAddress
;
204 Frees memory that was allocated with AllocateBuffer().
206 @param Pages The number of pages to free.
207 @param HostAddress The base system memory address of the allocated range.
208 @param Mapping The mapping value returned from Map().
210 @retval EFI_SUCCESS The requested memory pages were freed.
211 @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress and Pages
212 was not allocated with AllocateBuffer().
218 IN VOID
*HostAddress
,
224 if (mIoMmu
!= NULL
) {
225 Status
= mIoMmu
->SetAttribute (mIoMmu
, Mapping
, 0);
226 Status
= mIoMmu
->Unmap (mIoMmu
, Mapping
);
227 Status
= mIoMmu
->FreeBuffer (mIoMmu
, Pages
, HostAddress
);
229 Status
= EFI_SUCCESS
;
242 PeiServicesLocatePpi (