]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/LegacyRegion2Dxe/LegacyRegion2.c
Dummy implementation of Legacy Region 2 Protocol.
[mirror_edk2.git] / MdeModulePkg / Universal / LegacyRegion2Dxe / LegacyRegion2.c
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, Intel Corporation
11 All rights reserved. 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 ASSERT (Granularity != NULL);
68 *Granularity = 0;
69 return EFI_SUCCESS;
70 }
71
72 /**
73 Modify the hardware to disallow memory writes in a region.
74
75 This function changes the attributes of a memory range to not allow writes.
76
77 @param This[in] Indicates the EFI_LEGACY_REGION_PROTOCOL instance.
78 @param Start[in] The beginning of the physical address of the region whose
79 attributes should be modified.
80 @param Length[in] The number of bytes of memory whose attributes should be modified.
81 The actual number of bytes modified may be greater than the number
82 specified.
83 @param Granularity[out] The number of bytes in the last region affected. This may be less
84 than the total number of bytes affected if the starting address was
85 not aligned to a region's starting address or if the length was
86 greater than the number of bytes in the first region.
87
88 @retval EFI_SUCCESS The region's attributes were successfully modified.
89 @retval EFI_INVALID_PARAMETER If Start or Length describe an address not in the Legacy Region.
90
91 **/
92 EFI_STATUS
93 EFIAPI
94 LegacyRegion2Lock (
95 IN EFI_LEGACY_REGION2_PROTOCOL *This,
96 IN UINT32 Start,
97 IN UINT32 Length,
98 OUT UINT32 *Granularity
99 )
100 {
101 ASSERT (Granularity != NULL);
102 *Granularity = 0;
103 return EFI_SUCCESS;
104 }
105
106 /**
107 Modify the hardware to disallow memory attribute changes in a region.
108
109 This function makes the attributes of a region read only. Once a region is boot-locked with this
110 function, the read and write attributes of that region cannot be changed until a power cycle has
111 reset the boot-lock attribute. Calls to Decode(), Lock() and Unlock() will have no effect.
112
113 @param This[in] Indicates the EFI_LEGACY_REGION_PROTOCOL instance.
114 @param Start[in] The beginning of the physical address of the region whose
115 attributes should be modified.
116 @param Length[in] The number of bytes of memory whose attributes should be modified.
117 The actual number of bytes modified may be greater than the number
118 specified.
119 @param Granularity[out] The number of bytes in the last region affected. This may be less
120 than the total number of bytes affected if the starting address was
121 not aligned to a region's starting address or if the length was
122 greater than the number of bytes in the first region.
123
124 @retval EFI_SUCCESS The region's attributes were successfully modified.
125 @retval EFI_INVALID_PARAMETER If Start or Length describe an address not in the Legacy Region.
126 @retval EFI_UNSUPPORTED The chipset does not support locking the configuration registers in
127 a way that will not affect memory regions outside the legacy memory
128 region.
129
130 **/
131 EFI_STATUS
132 EFIAPI
133 LegacyRegion2BootLock (
134 IN EFI_LEGACY_REGION2_PROTOCOL *This,
135 IN UINT32 Start,
136 IN UINT32 Length,
137 OUT UINT32 *Granularity
138 )
139 {
140 ASSERT (Granularity != NULL);
141 *Granularity = 0;
142 return EFI_SUCCESS;
143 }
144
145 /**
146 Modify the hardware to allow memory writes in a region.
147
148 This function changes the attributes of a memory range to allow writes.
149
150 @param This[in] Indicates the EFI_LEGACY_REGION_PROTOCOL instance.
151 @param Start[in] The beginning of the physical address of the region whose
152 attributes should be modified.
153 @param Length[in] The number of bytes of memory whose attributes should be modified.
154 The actual number of bytes modified may be greater than the number
155 specified.
156 @param Granularity[out] The number of bytes in the last region affected. This may be less
157 than the total number of bytes affected if the starting address was
158 not aligned to a region's starting address or if the length was
159 greater than the number of bytes in the first region.
160
161 @retval EFI_SUCCESS The region's attributes were successfully modified.
162 @retval EFI_INVALID_PARAMETER If Start or Length describe an address not in the Legacy Region.
163
164 **/
165 EFI_STATUS
166 EFIAPI
167 LegacyRegion2Unlock (
168 IN EFI_LEGACY_REGION2_PROTOCOL *This,
169 IN UINT32 Start,
170 IN UINT32 Length,
171 OUT UINT32 *Granularity
172 )
173 {
174 ASSERT (Granularity != NULL);
175 *Granularity = 0;
176 return EFI_SUCCESS;
177 }
178
179 /**
180 Get region information for the attributes of the Legacy Region.
181
182 This function is used to discover the granularity of the attributes for the memory in the legacy
183 region. Each attribute may have a different granularity and the granularity may not be the same
184 for all memory ranges in the legacy region.
185
186 @param This[in] Indicates the EFI_LEGACY_REGION_PROTOCOL instance.
187 @param DescriptorCount[out] The number of region descriptor entries returned in the Descriptor
188 buffer.
189 @param Descriptor[out] A pointer to a pointer used to return a buffer where the legacy
190 region information is deposited. This buffer will contain a list of
191 DescriptorCount number of region descriptors. This function will
192 provide the memory for the buffer.
193
194 @retval EFI_SUCCESS The region's attributes were successfully modified.
195 @retval EFI_INVALID_PARAMETER If Start or Length describe an address not in the Legacy Region.
196
197 **/
198 EFI_STATUS
199 EFIAPI
200 LegacyRegionGetInfo (
201 IN EFI_LEGACY_REGION2_PROTOCOL *This,
202 OUT UINT32 *DescriptorCount,
203 OUT EFI_LEGACY_REGION_DESCRIPTOR **Descriptor
204 )
205 {
206 ASSERT (DescriptorCount != NULL);
207 ASSERT (Descriptor != NULL);
208
209 *DescriptorCount = 0;
210 *Descriptor = NULL;
211
212 return EFI_SUCCESS;
213 }
214
215 /**
216 The user Entry Point for module LegacyRegionDxe. The user code starts with this function.
217
218 @param[in] ImageHandle The firmware allocated handle for the EFI image.
219 @param[in] SystemTable A pointer to the EFI System Table.
220
221 @retval EFI_SUCCESS The entry point is executed successfully.
222
223 **/
224 EFI_STATUS
225 EFIAPI
226 LegacyRegion2Install (
227 IN EFI_HANDLE ImageHandle,
228 IN EFI_SYSTEM_TABLE *SystemTable
229 )
230 {
231 EFI_STATUS Status;
232
233 //
234 // Make sure the Legacy Region 2 Protocol is not already installed in the system
235 //
236 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiLegacyRegion2ProtocolGuid);
237
238 //
239 // Install the protocol on a new handle.
240 //
241 Status = gBS->InstallMultipleProtocolInterfaces (
242 &mLegacyRegion2Handle,
243 &gEfiLegacyRegion2ProtocolGuid, &mLegacyRegion2,
244 NULL
245 );
246 ASSERT_EFI_ERROR (Status);
247
248 return EFI_SUCCESS;
249 }