]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Universal/LegacyRegionDxe/LegacyRegion.c
c5467b222f021c59fcb79c294f0ca9df044a2bba
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / LegacyRegionDxe / LegacyRegion.c
1 /**
2 Produces the Legacy Region Protocol.
3
4 This generic implementation of the Legacy Region 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 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 <PiDxe.h>
22 #include <Protocol/LegacyRegion.h>
23 #include <Library/DebugLib.h>
24 #include <Library/UefiBootServicesTableLib.h>
25
26 //
27 // Function prototypes of the Legacy Region Protocol services this module produces
28 //
29 EFI_STATUS
30 EFIAPI
31 LegacyRegionDecode (
32 IN EFI_LEGACY_REGION_PROTOCOL *This,
33 IN UINT32 Start,
34 IN UINT32 Length,
35 IN BOOLEAN *On
36 );
37
38 EFI_STATUS
39 EFIAPI
40 LegacyRegionLock (
41 IN EFI_LEGACY_REGION_PROTOCOL *This,
42 IN UINT32 Start,
43 IN UINT32 Length,
44 OUT UINT32 *Granularity OPTIONAL
45 );
46
47 EFI_STATUS
48 EFIAPI
49 LegacyRegionBootLock (
50 IN EFI_LEGACY_REGION_PROTOCOL *This,
51 IN UINT32 Start,
52 IN UINT32 Length,
53 OUT UINT32 *Granularity OPTIONAL
54 );
55
56 EFI_STATUS
57 EFIAPI
58 LegacyRegionUnlock (
59 IN EFI_LEGACY_REGION_PROTOCOL *This,
60 IN UINT32 Start,
61 IN UINT32 Length,
62 OUT UINT32 *Granularity OPTIONAL
63 );
64
65 //
66 // Module global for the handle the Legacy Region Protocol is installed
67 //
68 EFI_HANDLE mLegacyRegionHandle = NULL;
69
70 //
71 // Module global for the Legacy Region Protocol instance that is installed onto
72 // mLegacyRegionHandle
73 //
74 EFI_LEGACY_REGION_PROTOCOL mLegacyRegion = {
75 LegacyRegionDecode,
76 LegacyRegionLock,
77 LegacyRegionBootLock,
78 LegacyRegionUnlock
79 };
80
81 /**
82 Sets hardware to decode or not decode a region.
83
84 @param This Indicates the EFI_LEGACY_REGION_PROTOCOL instance
85 @param Start Start of region to decode.
86 @param Length Size in bytes of the region.
87 @param On Decode/nondecode flag.
88
89 @retval EFI_SUCCESS Decode range successfully changed.
90
91 **/
92 EFI_STATUS
93 EFIAPI
94 LegacyRegionDecode (
95 IN EFI_LEGACY_REGION_PROTOCOL *This,
96 IN UINT32 Start,
97 IN UINT32 Length,
98 IN BOOLEAN *On
99 )
100 {
101 return EFI_SUCCESS;
102 }
103
104 /**
105 Sets a region to read only.
106
107 @param This Indicates the EFI_LEGACY_REGION_PROTOCOL instance
108 @param Start Start of region to lock.
109 @param Length Size in bytes of the region.
110 @param Granularity Lock attribute affects this granularity in bytes.
111
112 @retval EFI_SUCCESS The region was made read only.
113
114 **/
115 EFI_STATUS
116 EFIAPI
117 LegacyRegionLock (
118 IN EFI_LEGACY_REGION_PROTOCOL *This,
119 IN UINT32 Start,
120 IN UINT32 Length,
121 OUT UINT32 *Granularity OPTIONAL
122 )
123 {
124 return EFI_SUCCESS;
125 }
126
127 /**
128 Sets a region to read only and ensures that flash is locked from being
129 inadvertently modified.
130
131 @param This Indicates the EFI_LEGACY_REGION_PROTOCOL instance
132 @param Start Start of region to lock.
133 @param Length Size in bytes of the region.
134 @param Granularity Lock attribute affects this granularity in bytes.
135
136 @retval EFI_SUCCESS The region was made read only and flash is locked.
137
138 **/
139 EFI_STATUS
140 EFIAPI
141 LegacyRegionBootLock (
142 IN EFI_LEGACY_REGION_PROTOCOL *This,
143 IN UINT32 Start,
144 IN UINT32 Length,
145 OUT UINT32 *Granularity OPTIONAL
146 )
147 {
148 return EFI_SUCCESS;
149 }
150
151 /**
152 Sets a region to read-write.
153
154 @param This Indicates the EFI_LEGACY_REGION_PROTOCOL instance
155 @param Start Start of region to lock.
156 @param Length Size in bytes of the region.
157 @param Granularity Lock attribute affects this granularity in bytes.
158
159 @retval EFI_SUCCESS The region was successfully made read-write.
160
161 **/
162 EFI_STATUS
163 EFIAPI
164 LegacyRegionUnlock (
165 IN EFI_LEGACY_REGION_PROTOCOL *This,
166 IN UINT32 Start,
167 IN UINT32 Length,
168 OUT UINT32 *Granularity OPTIONAL
169 )
170 {
171 return EFI_SUCCESS;
172 }
173
174 /**
175 The user Entry Point for module LegacyRegionDxe. The user code starts with this function.
176
177 @param[in] ImageHandle The firmware allocated handle for the EFI image.
178 @param[in] SystemTable A pointer to the EFI System Table.
179
180 @retval EFI_SUCCESS The entry point is executed successfully.
181 @retval other Some error occurs when executing this entry point.
182
183 **/
184 EFI_STATUS
185 EFIAPI
186 LegacyRegionInstall (
187 IN EFI_HANDLE ImageHandle,
188 IN EFI_SYSTEM_TABLE *SystemTable
189 )
190 {
191 EFI_STATUS Status;
192
193 //
194 // Make sure the Legacy Region Protocol is not already installed in the system
195 //
196 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiLegacyRegionProtocolGuid);
197
198 //
199 // Install the protocol on a new handle.
200 //
201 Status = gBS->InstallMultipleProtocolInterfaces (
202 &mLegacyRegionHandle,
203 &gEfiLegacyRegionProtocolGuid, &mLegacyRegion,
204 NULL
205 );
206 ASSERT_EFI_ERROR (Status);
207
208 return Status;
209 }