]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Compatibility/LegacyRegion2OnLegacyRegionThunk/LegacyRegion2OnLegacyRegionThunk.c
Thunk driver producing PI Legacy Region 2 Protocol based on Framework Legacy Region...
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / LegacyRegion2OnLegacyRegionThunk / LegacyRegion2OnLegacyRegionThunk.c
1 /** @file
2 Implementation of Legacy Region 2 Protocol based on Framework Legacy Region Protocol.
3
4 Intel's Framework Legacy Region Protocol is replaced by Legacy Region 2 Protocol in PI 1.2.
5 This module produces PI Legacy Region 2 Protocol on top of Framework Legacy Region Protocol.
6
7 Copyright (c) 2009, Intel Corporation
8 All rights reserved. This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
12
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15
16 **/
17
18 #include "LegacyRegion2OnLegacyRegionThunk.h"
19
20 EFI_HANDLE mLegacyRegion2Handle = NULL;
21
22 EFI_LEGACY_REGION_PROTOCOL *mLegacyRegion;
23
24 EFI_LEGACY_REGION2_PROTOCOL mLegacyRegion2 = {
25 LegacyRegion2Decode,
26 LegacyRegion2Lock,
27 LegacyRegion2BootLock,
28 LegacyRegion2Unlock,
29 LegacyRegionGetInfo
30 };
31
32 /**
33 Modify the hardware to allow (decode) or disallow (not decode) memory reads in a region.
34
35 If the On parameter evaluates to TRUE, this function enables memory reads in the address range
36 Start to (Start + Length - 1).
37 If the On parameter evaluates to FALSE, this function disables memory reads in the address range
38 Start to (Start + Length - 1).
39
40 @param This[in] Indicates the EFI_LEGACY_REGION_PROTOCOL instance.
41 @param Start[in] The beginning of the physical address of the region whose attributes
42 should be modified.
43 @param Length[in] The number of bytes of memory whose attributes should be modified.
44 The actual number of bytes modified may be greater than the number
45 specified.
46 @param Granularity[out] The number of bytes in the last region affected. This may be less
47 than the total number of bytes affected if the starting address
48 was not aligned to a region's starting address or if the length
49 was greater than the number of bytes in the first region.
50 @param On[in] Decode / Non-Decode flag.
51
52 @retval EFI_SUCCESS The region's attributes were successfully modified.
53 @retval EFI_INVALID_PARAMETER If Start or Length describe an address not in the Legacy Region.
54
55 **/
56 EFI_STATUS
57 EFIAPI
58 LegacyRegion2Decode (
59 IN EFI_LEGACY_REGION2_PROTOCOL *This,
60 IN UINT32 Start,
61 IN UINT32 Length,
62 OUT UINT32 *Granularity,
63 IN BOOLEAN *On
64 )
65 {
66 ASSERT (Granularity != NULL);
67 *Granularity = 0;
68
69 return mLegacyRegion->Decode (
70 mLegacyRegion,
71 Start,
72 Length,
73 On
74 );
75 }
76
77 /**
78 Modify the hardware to disallow memory writes in a region.
79
80 This function changes the attributes of a memory range to not allow writes.
81
82 @param This[in] Indicates the EFI_LEGACY_REGION_PROTOCOL instance.
83 @param Start[in] The beginning of the physical address of the region whose
84 attributes should be modified.
85 @param Length[in] The number of bytes of memory whose attributes should be modified.
86 The actual number of bytes modified may be greater than the number
87 specified.
88 @param Granularity[out] The number of bytes in the last region affected. This may be less
89 than the total number of bytes affected if the starting address was
90 not aligned to a region's starting address or if the length was
91 greater than the number of bytes in the first region.
92
93 @retval EFI_SUCCESS The region's attributes were successfully modified.
94 @retval EFI_INVALID_PARAMETER If Start or Length describe an address not in the Legacy Region.
95
96 **/
97 EFI_STATUS
98 EFIAPI
99 LegacyRegion2Lock (
100 IN EFI_LEGACY_REGION2_PROTOCOL *This,
101 IN UINT32 Start,
102 IN UINT32 Length,
103 OUT UINT32 *Granularity
104 )
105 {
106 ASSERT (Granularity != NULL);
107
108 return mLegacyRegion->Lock (
109 mLegacyRegion,
110 Start,
111 Length,
112 Granularity
113 );
114 }
115
116 /**
117 Modify the hardware to disallow memory attribute changes in a region.
118
119 This function makes the attributes of a region read only. Once a region is boot-locked with this
120 function, the read and write attributes of that region cannot be changed until a power cycle has
121 reset the boot-lock attribute. Calls to Decode(), Lock() and Unlock() will have no effect.
122
123 @param This[in] Indicates the EFI_LEGACY_REGION_PROTOCOL instance.
124 @param Start[in] The beginning of the physical address of the region whose
125 attributes should be modified.
126 @param Length[in] The number of bytes of memory whose attributes should be modified.
127 The actual number of bytes modified may be greater than the number
128 specified.
129 @param Granularity[out] The number of bytes in the last region affected. This may be less
130 than the total number of bytes affected if the starting address was
131 not aligned to a region's starting address or if the length was
132 greater than the number of bytes in the first region.
133
134 @retval EFI_SUCCESS The region's attributes were successfully modified.
135 @retval EFI_INVALID_PARAMETER If Start or Length describe an address not in the Legacy Region.
136 @retval EFI_UNSUPPORTED The chipset does not support locking the configuration registers in
137 a way that will not affect memory regions outside the legacy memory
138 region.
139
140 **/
141 EFI_STATUS
142 EFIAPI
143 LegacyRegion2BootLock (
144 IN EFI_LEGACY_REGION2_PROTOCOL *This,
145 IN UINT32 Start,
146 IN UINT32 Length,
147 OUT UINT32 *Granularity
148 )
149 {
150 ASSERT (Granularity != NULL);
151
152 return mLegacyRegion->BootLock (
153 mLegacyRegion,
154 Start,
155 Length,
156 Granularity
157 );
158 }
159
160 /**
161 Modify the hardware to allow memory writes in a region.
162
163 This function changes the attributes of a memory range to allow writes.
164
165 @param This[in] Indicates the EFI_LEGACY_REGION_PROTOCOL instance.
166 @param Start[in] The beginning of the physical address of the region whose
167 attributes should be modified.
168 @param Length[in] The number of bytes of memory whose attributes should be modified.
169 The actual number of bytes modified may be greater than the number
170 specified.
171 @param Granularity[out] The number of bytes in the last region affected. This may be less
172 than the total number of bytes affected if the starting address was
173 not aligned to a region's starting address or if the length was
174 greater than the number of bytes in the first region.
175
176 @retval EFI_SUCCESS The region's attributes were successfully modified.
177 @retval EFI_INVALID_PARAMETER If Start or Length describe an address not in the Legacy Region.
178
179 **/
180 EFI_STATUS
181 EFIAPI
182 LegacyRegion2Unlock (
183 IN EFI_LEGACY_REGION2_PROTOCOL *This,
184 IN UINT32 Start,
185 IN UINT32 Length,
186 OUT UINT32 *Granularity
187 )
188 {
189 ASSERT (Granularity != NULL);
190
191 return mLegacyRegion->UnLock (
192 mLegacyRegion,
193 Start,
194 Length,
195 Granularity
196 );
197 }
198
199 /**
200 Get region information for the attributes of the Legacy Region.
201
202 This function is used to discover the granularity of the attributes for the memory in the legacy
203 region. Each attribute may have a different granularity and the granularity may not be the same
204 for all memory ranges in the legacy region.
205
206 @param This[in] Indicates the EFI_LEGACY_REGION_PROTOCOL instance.
207 @param DescriptorCount[out] The number of region descriptor entries returned in the Descriptor
208 buffer.
209 @param Descriptor[out] A pointer to a pointer used to return a buffer where the legacy
210 region information is deposited. This buffer will contain a list of
211 DescriptorCount number of region descriptors. This function will
212 provide the memory for the buffer.
213
214 @retval EFI_SUCCESS The region's attributes were successfully modified.
215 @retval EFI_INVALID_PARAMETER If Start or Length describe an address not in the Legacy Region.
216
217 **/
218 EFI_STATUS
219 EFIAPI
220 LegacyRegionGetInfo (
221 IN EFI_LEGACY_REGION2_PROTOCOL *This,
222 OUT UINT32 *DescriptorCount,
223 OUT EFI_LEGACY_REGION_DESCRIPTOR **Descriptor
224 )
225 {
226 return EFI_UNSUPPORTED;
227 }
228
229 /**
230 The user Entry Point for module LegacyRegionDxe. The user code starts with this function.
231
232 @param[in] ImageHandle The firmware allocated handle for the EFI image.
233 @param[in] SystemTable A pointer to the EFI System Table.
234
235 @retval EFI_SUCCESS The entry point is executed successfully.
236
237 **/
238 EFI_STATUS
239 EFIAPI
240 LegacyRegion2OnLegacyRegionThunkInitialize (
241 IN EFI_HANDLE ImageHandle,
242 IN EFI_SYSTEM_TABLE *SystemTable
243 )
244 {
245 EFI_STATUS Status;
246
247 //
248 // Make sure the Legacy Region 2 Protocol is not already installed in the system
249 //
250 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiLegacyRegion2ProtocolGuid);
251
252 //
253 // Locate and cache Framework Legacy Region Protocol.
254 //
255 Status = gBS->LocateProtocol (
256 &gEfiLegacyRegionProtocolGuid,
257 NULL,
258 (VOID **) &mLegacyRegion
259 );
260 ASSERT_EFI_ERROR (Status);
261
262 //
263 // Install the protocol on a new handle.
264 //
265 Status = gBS->InstallMultipleProtocolInterfaces (
266 &mLegacyRegion2Handle,
267 &gEfiLegacyRegion2ProtocolGuid, &mLegacyRegion2,
268 NULL
269 );
270 ASSERT_EFI_ERROR (Status);
271
272 return Status;
273 }