2 The DMA memory help functions.
4 Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
13 Provides the controller-specific addresses required to access system memory from a
16 @param IoMmu Pointer to IOMMU PPI.
17 @param Operation Indicates if the bus master is going to read or write to system memory.
18 @param HostAddress The system memory address to map to the PCI controller.
19 @param NumberOfBytes On input the number of bytes to map. On output the number of bytes
21 @param DeviceAddress The resulting map address for the bus master PCI controller to use to
22 access the hosts HostAddress.
23 @param Mapping A resulting value to pass to Unmap().
25 @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.
26 @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.
27 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
28 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
29 @retval EFI_DEVICE_ERROR The system hardware could not map the requested address.
34 IN EDKII_IOMMU_PPI
*IoMmu
,
35 IN EDKII_IOMMU_OPERATION Operation
,
37 IN OUT UINTN
*NumberOfBytes
,
38 OUT EFI_PHYSICAL_ADDRESS
*DeviceAddress
,
54 if (EFI_ERROR (Status
)) {
55 return EFI_OUT_OF_RESOURCES
;
59 case EdkiiIoMmuOperationBusMasterRead
:
60 case EdkiiIoMmuOperationBusMasterRead64
:
61 Attribute
= EDKII_IOMMU_ACCESS_READ
;
63 case EdkiiIoMmuOperationBusMasterWrite
:
64 case EdkiiIoMmuOperationBusMasterWrite64
:
65 Attribute
= EDKII_IOMMU_ACCESS_WRITE
;
67 case EdkiiIoMmuOperationBusMasterCommonBuffer
:
68 case EdkiiIoMmuOperationBusMasterCommonBuffer64
:
69 Attribute
= EDKII_IOMMU_ACCESS_READ
| EDKII_IOMMU_ACCESS_WRITE
;
73 return EFI_INVALID_PARAMETER
;
76 Status
= IoMmu
->SetAttribute (
81 if (EFI_ERROR (Status
)) {
82 IoMmu
->Unmap (IoMmu
, Mapping
);
87 *DeviceAddress
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)HostAddress
;
96 Completes the Map() operation and releases any corresponding resources.
98 @param IoMmu Pointer to IOMMU PPI.
99 @param Mapping The mapping value returned from Map().
104 IN EDKII_IOMMU_PPI
*IoMmu
,
109 IoMmu
->SetAttribute (IoMmu
, Mapping
, 0);
110 IoMmu
->Unmap (IoMmu
, Mapping
);
115 Allocates pages that are suitable for an OperationBusMasterCommonBuffer or
116 OperationBusMasterCommonBuffer64 mapping.
118 @param IoMmu Pointer to IOMMU PPI.
119 @param Pages The number of pages to allocate.
120 @param HostAddress A pointer to store the base system memory address of the
122 @param DeviceAddress The resulting map address for the bus master PCI controller to use to
123 access the hosts HostAddress.
124 @param Mapping A resulting value to pass to Unmap().
126 @retval EFI_SUCCESS The requested memory pages were allocated.
127 @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are
128 MEMORY_WRITE_COMBINE and MEMORY_CACHED.
129 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
130 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
134 IoMmuAllocateBuffer (
135 IN EDKII_IOMMU_PPI
*IoMmu
,
137 OUT VOID
**HostAddress
,
138 OUT EFI_PHYSICAL_ADDRESS
*DeviceAddress
,
144 EFI_PHYSICAL_ADDRESS HostPhyAddress
;
151 Status
= IoMmu
->AllocateBuffer (
158 if (EFI_ERROR (Status
)) {
159 return EFI_OUT_OF_RESOURCES
;
162 NumberOfBytes
= EFI_PAGES_TO_SIZE (Pages
);
163 Status
= IoMmu
->Map (
165 EdkiiIoMmuOperationBusMasterCommonBuffer
,
171 if (EFI_ERROR (Status
)) {
172 IoMmu
->FreeBuffer (IoMmu
, Pages
, *HostAddress
);
174 return EFI_OUT_OF_RESOURCES
;
177 Status
= IoMmu
->SetAttribute (
180 EDKII_IOMMU_ACCESS_READ
| EDKII_IOMMU_ACCESS_WRITE
182 if (EFI_ERROR (Status
)) {
183 IoMmu
->Unmap (IoMmu
, *Mapping
);
184 IoMmu
->FreeBuffer (IoMmu
, Pages
, *HostAddress
);
190 Status
= PeiServicesAllocatePages (
195 if (EFI_ERROR (Status
)) {
196 return EFI_OUT_OF_RESOURCES
;
199 *HostAddress
= (VOID
*)(UINTN
)HostPhyAddress
;
200 *DeviceAddress
= HostPhyAddress
;
210 @param IoMmu Pointer to pointer to IOMMU PPI.
215 OUT EDKII_IOMMU_PPI
**IoMmu
219 PeiServicesLocatePpi (