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