]>
Commit | Line | Data |
---|---|---|
c4e76d2f MX |
1 | /** @file\r |
2 | \r | |
3 | Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>\r | |
4 | \r | |
5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
6 | \r | |
7 | **/\r | |
8 | \r | |
9 | #ifndef IOMMU_INTERNAL_H_\r | |
10 | #define IOMMU_INTERNAL_H_\r | |
11 | \r | |
12 | #include <Base.h>\r | |
13 | #include <Protocol/IoMmu.h>\r | |
14 | #include <Uefi/UefiBaseType.h>\r | |
15 | #include <Uefi/UefiSpec.h>\r | |
16 | \r | |
17 | #define MAP_INFO_SIG SIGNATURE_64 ('M', 'A', 'P', '_', 'I', 'N', 'F', 'O')\r | |
18 | \r | |
19 | typedef struct {\r | |
20 | UINT64 Signature;\r | |
21 | LIST_ENTRY Link;\r | |
22 | EDKII_IOMMU_OPERATION Operation;\r | |
23 | UINTN NumberOfBytes;\r | |
24 | UINTN NumberOfPages;\r | |
25 | EFI_PHYSICAL_ADDRESS CryptedAddress;\r | |
26 | EFI_PHYSICAL_ADDRESS PlainTextAddress;\r | |
27 | UINT32 ReservedMemBitmap;\r | |
28 | } MAP_INFO;\r | |
29 | \r | |
30 | #define COMMON_BUFFER_SIG SIGNATURE_64 ('C', 'M', 'N', 'B', 'U', 'F', 'F', 'R')\r | |
31 | \r | |
32 | #pragma pack (1)\r | |
33 | //\r | |
34 | // The following structure enables Map() and Unmap() to perform in-place\r | |
35 | // decryption and encryption, respectively, for BusMasterCommonBuffer[64]\r | |
36 | // operations, without dynamic memory allocation or release.\r | |
37 | //\r | |
38 | // Both COMMON_BUFFER_HEADER and COMMON_BUFFER_HEADER.StashBuffer are allocated\r | |
39 | // by AllocateBuffer() and released by FreeBuffer().\r | |
40 | //\r | |
41 | typedef struct {\r | |
42 | UINT64 Signature;\r | |
43 | \r | |
44 | //\r | |
45 | // Always allocated from EfiBootServicesData type memory, and always\r | |
46 | // encrypted.\r | |
47 | //\r | |
48 | VOID *StashBuffer;\r | |
49 | \r | |
50 | //\r | |
51 | // Bitmap of reserved memory\r | |
52 | //\r | |
53 | UINT32 ReservedMemBitmap;\r | |
54 | \r | |
55 | //\r | |
56 | // Followed by the actual common buffer, starting at the next page.\r | |
57 | //\r | |
58 | } COMMON_BUFFER_HEADER;\r | |
59 | \r | |
60 | //\r | |
61 | // This data structure defines a memory range in the reserved memory region.\r | |
62 | // Please refer to IoMmuInitReservedSharedMem() for detailed information.\r | |
63 | //\r | |
64 | // The memory region looks like:\r | |
65 | // |------------|----------------------------|\r | |
66 | // | Header | Data |\r | |
67 | // | 4k, private| 4k/32k/128k/etc, shared |\r | |
68 | // |-----------------------------------------|\r | |
69 | //\r | |
70 | typedef struct {\r | |
71 | UINT32 BitmapMask;\r | |
72 | UINT32 Shift;\r | |
73 | UINT32 Slots;\r | |
74 | UINT32 DataSize;\r | |
75 | UINT32 HeaderSize;\r | |
76 | EFI_PHYSICAL_ADDRESS StartAddressOfMemRange;\r | |
77 | } IOMMU_RESERVED_MEM_RANGE;\r | |
78 | #pragma pack()\r | |
79 | \r | |
80 | /**\r | |
81 | * Allocate a memory region and convert it to be shared. This memory region will be\r | |
82 | * used in the DMA operation.\r | |
83 | *\r | |
84 | * The pre-alloc memory contains pieces of memory regions with different size. The\r | |
85 | * allocation of the shared memory regions are indicated by a 32-bit bitmap (mReservedMemBitmap).\r | |
86 | *\r | |
87 | * The memory regions are consumed by IoMmuAllocateBuffer (in which CommonBuffer is allocated) and\r | |
88 | * IoMmuMap (in which bounce buffer is allocated).\r | |
89 | *\r | |
90 | * The CommonBuffer contains 2 parts, one page for CommonBufferHeader which is private memory,\r | |
91 | * the other part is shared memory. So the layout of a piece of memory region after initialization\r | |
92 | * looks like:\r | |
93 | *\r | |
94 | * |------------|----------------------------|\r | |
95 | * | Header | Data | <-- a piece of pre-alloc memory region\r | |
96 | * | 4k, private| 4k/32k/128k/etc, shared |\r | |
97 | * |-----------------------------------------|\r | |
98 | *\r | |
99 | * @retval EFI_SUCCESS Successfully initialize the reserved memory.\r | |
100 | * @retval EFI_UNSUPPORTED This feature is not supported.\r | |
101 | */\r | |
102 | EFI_STATUS\r | |
103 | IoMmuInitReservedSharedMem (\r | |
104 | VOID\r | |
105 | );\r | |
106 | \r | |
107 | /**\r | |
108 | * Release the pre-alloc shared memory.\r | |
109 | *\r | |
110 | * @retval EFI_SUCCESS Successfully release the shared memory\r | |
111 | */\r | |
112 | EFI_STATUS\r | |
113 | IoMmuReleaseReservedSharedMem (\r | |
114 | BOOLEAN MemoryMapLocked\r | |
115 | );\r | |
116 | \r | |
117 | /**\r | |
118 | * Allocate reserved shared memory for bounce buffer.\r | |
119 | *\r | |
120 | * @param Type Allocate type\r | |
121 | * @param MemoryType The memory type to be allocated\r | |
122 | * @param MapInfo Pointer to the MAP_INFO\r | |
123 | *\r | |
124 | * @retval EFI_SUCCESS Successfully allocate the bounce buffer\r | |
125 | * @retval Other As the error code indicates\r | |
126 | */\r | |
127 | EFI_STATUS\r | |
128 | IoMmuAllocateBounceBuffer (\r | |
129 | IN EFI_ALLOCATE_TYPE Type,\r | |
130 | IN EFI_MEMORY_TYPE MemoryType,\r | |
131 | IN OUT MAP_INFO *MapInfo\r | |
132 | );\r | |
133 | \r | |
134 | /**\r | |
135 | * Free the bounce buffer allocated in IoMmuAllocateBounceBuffer.\r | |
136 | *\r | |
137 | * @param MapInfo Pointer to the MAP_INFO\r | |
138 | * @return EFI_SUCCESS Successfully free the bounce buffer.\r | |
139 | */\r | |
140 | EFI_STATUS\r | |
141 | IoMmuFreeBounceBuffer (\r | |
142 | IN OUT MAP_INFO *MapInfo\r | |
143 | );\r | |
144 | \r | |
145 | /**\r | |
146 | * Allocate CommonBuffer from pre-allocated shared memory.\r | |
147 | *\r | |
148 | * @param MemoryType Memory type\r | |
149 | * @param CommonBufferPages Pages of CommonBuffer\r | |
150 | * @param PhysicalAddress Allocated physical address\r | |
151 | * @param ReservedMemBitmap Bitmap which indicates the allocation of reserved memory\r | |
152 | *\r | |
153 | * @retval EFI_SUCCESS Successfully allocate the common buffer\r | |
154 | * @retval Other As the error code indicates\r | |
155 | */\r | |
156 | EFI_STATUS\r | |
157 | IoMmuAllocateCommonBuffer (\r | |
158 | IN EFI_MEMORY_TYPE MemoryType,\r | |
159 | IN UINTN CommonBufferPages,\r | |
160 | OUT EFI_PHYSICAL_ADDRESS *PhysicalAddress,\r | |
161 | OUT UINT32 *ReservedMemBitmap\r | |
162 | );\r | |
163 | \r | |
164 | /**\r | |
165 | * Free CommonBuffer which is allocated by IoMmuAllocateCommonBuffer().\r | |
166 | *\r | |
167 | * @param CommonBufferHeader Pointer to the CommonBufferHeader\r | |
168 | * @param CommonBufferPages Pages of CommonBuffer\r | |
169 | *\r | |
170 | * @retval EFI_SUCCESS Successfully free the common buffer\r | |
171 | * @retval Other As the error code indicates\r | |
172 | */\r | |
173 | EFI_STATUS\r | |
174 | IoMmuFreeCommonBuffer (\r | |
175 | IN COMMON_BUFFER_HEADER *CommonBufferHeader,\r | |
176 | IN UINTN CommonBufferPages\r | |
177 | );\r | |
178 | \r | |
179 | #endif\r |