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