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