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