]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Library/EdkUefiRuntimeLib/Common/RuntimeLib.c
Update library constructor definition.
[mirror_edk2.git] / EdkModulePkg / Library / EdkUefiRuntimeLib / Common / RuntimeLib.c
1 /*++
2
3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 RuntimeLib.c
15
16 Abstract:
17
18 Light weight lib to support Tiano drivers.
19
20 --*/
21
22 #include <RuntimeLibInternal.h>
23
24 //
25 // Driver Lib Module Globals
26 //
27 STATIC EFI_EVENT mRuntimeNotifyEvent;
28 STATIC EFI_EVENT mEfiVirtualNotifyEvent;
29 STATIC BOOLEAN mEfiGoneVirtual = FALSE;
30 STATIC BOOLEAN mEfiAtRuntime = FALSE;
31
32 EFI_RUNTIME_SERVICES *mRT = NULL;
33
34 VOID
35 EFIAPI
36 RuntimeDriverExitBootServices (
37 IN EFI_EVENT Event,
38 IN VOID *Context
39 )
40 /*++
41
42 Routine Description:
43
44 Set AtRuntime flag as TRUE after ExitBootServices
45
46 Arguments:
47
48 Event - The Event that is being processed
49
50 Context - Event Context
51
52 Returns:
53
54 None
55
56 --*/
57 {
58 EFI_EVENT_NOTIFY ChildNotifyEventHandler;
59 UINTN Index;
60
61 for (Index = 0;
62 _gDriverExitBootServicesEvent[Index] != NULL;
63 Index++) {
64 ChildNotifyEventHandler = _gDriverExitBootServicesEvent[Index];
65 ChildNotifyEventHandler (Event, NULL);
66 }
67
68 mEfiAtRuntime = TRUE;
69 }
70
71 STATIC
72 VOID
73 EFIAPI
74 RuntimeLibVirtualNotifyEvent (
75 IN EFI_EVENT Event,
76 IN VOID *Context
77 )
78 /*++
79
80 Routine Description:
81
82 Fixup internal data so that EFI can be call in virtual mode.
83 Call the passed in Child Notify event and convert any pointers in
84 lib to virtual mode.
85
86 Arguments:
87
88 Event - The Event that is being processed
89
90 Context - Event Context
91
92 Returns:
93
94 None
95
96 --*/
97 {
98 UINTN Index;
99 EFI_EVENT_NOTIFY ChildNotifyEventHandler;
100
101 for (Index = 0;
102 _gDriverSetVirtualAddressMapEvent[Index] != NULL;
103 Index++) {
104 ChildNotifyEventHandler = _gDriverSetVirtualAddressMapEvent[Index];
105 ChildNotifyEventHandler (Event, NULL);
106 }
107
108 //
109 // Update global for Runtime Services Table and IO
110 //
111 EfiConvertInternalPointer ((VOID **) &mRT);
112
113 //
114 // Clear out BootService globals
115 //
116 gBS = NULL;
117 gST = NULL;
118 mEfiGoneVirtual = TRUE;
119 }
120
121 EFI_STATUS
122 EFIAPI
123 RuntimeDriverLibConstruct (
124 IN EFI_HANDLE ImageHandle,
125 IN EFI_SYSTEM_TABLE *SystemTable
126 )
127 /*++
128
129 Routine Description:
130
131 Intialize runtime Driver Lib if it has not yet been initialized.
132
133 Arguments:
134
135 ImageHandle - The firmware allocated handle for the EFI image.
136
137 SystemTable - A pointer to the EFI System Table.
138
139 GoVirtualChildEvent - Caller can register a virtual notification event.
140
141 Returns:
142
143 EFI_STATUS always returns EFI_SUCCESS except EFI_ALREADY_STARTED if already started.
144
145 --*/
146 {
147 EFI_STATUS Status;
148
149 mRT = SystemTable->RuntimeServices;
150
151 //
152 // Register our ExitBootServices () notify function
153 //
154 Status = gBS->CreateEvent (
155 EFI_EVENT_SIGNAL_EXIT_BOOT_SERVICES,
156 EFI_TPL_NOTIFY,
157 RuntimeDriverExitBootServices,
158 NULL,
159 &mRuntimeNotifyEvent
160 );
161
162 ASSERT_EFI_ERROR (Status);
163
164 //
165 // Register SetVirtualAddressMap () notify function
166 //
167 Status = gBS->CreateEvent (
168 EFI_EVENT_SIGNAL_VIRTUAL_ADDRESS_CHANGE,
169 EFI_TPL_NOTIFY,
170 RuntimeLibVirtualNotifyEvent,
171 NULL,
172 &mEfiVirtualNotifyEvent
173 );
174
175 ASSERT_EFI_ERROR (Status);
176
177 return EFI_SUCCESS;
178 }
179
180 EFI_STATUS
181 EFIAPI
182 RuntimeDriverLibDeconstruct (
183 VOID
184 )
185 /*++
186
187 Routine Description:
188
189 This routine will free some resources which have been allocated in
190 EfiInitializeRuntimeDriverLib(). If a runtime driver exits with an error,
191 it must call this routine to free the allocated resource before the exiting.
192
193 Arguments:
194
195 None
196
197 Returns:
198
199 EFI_SUCCESS - Shotdown the Runtime Driver Lib successfully
200 EFI_UNSUPPORTED - Runtime Driver lib was not initialized at all
201
202 --*/
203 {
204 EFI_STATUS Status;
205
206 //
207 // Close our ExitBootServices () notify function
208 //
209 Status = gBS->CloseEvent (mRuntimeNotifyEvent);
210 ASSERT_EFI_ERROR (Status);
211
212 //
213 // Close SetVirtualAddressMap () notify function
214 //
215 Status = gBS->CloseEvent (mEfiVirtualNotifyEvent);
216 ASSERT_EFI_ERROR (Status);
217
218 return EFI_SUCCESS;
219 }
220
221 BOOLEAN
222 EfiAtRuntime (
223 VOID
224 )
225 /*++
226
227 Routine Description:
228 Return TRUE if ExitBootServices () has been called
229
230 Arguments:
231 NONE
232
233 Returns:
234 TRUE - If ExitBootServices () has been called
235
236 --*/
237 {
238 return mEfiAtRuntime;
239 }
240
241 BOOLEAN
242 EfiGoneVirtual (
243 VOID
244 )
245 /*++
246
247 Routine Description:
248 Return TRUE if SetVirtualAddressMap () has been called
249
250 Arguments:
251 NONE
252
253 Returns:
254 TRUE - If SetVirtualAddressMap () has been called
255
256 --*/
257 {
258 return mEfiGoneVirtual;
259 }
260