0cef1f7ffc67390b8395af60f32830dc78cb2624
[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 --*/
17
18 #include <RuntimeLibInternal.h>
19
20 //
21 // Driver Lib Module Globals
22 //
23
24 STATIC EFI_EVENT mEfiVirtualNotifyEvent;
25 STATIC BOOLEAN mEfiGoneVirtual = FALSE;
26 STATIC BOOLEAN mEfiAtRuntime = FALSE;
27 EFI_RUNTIME_SERVICES *mRT;
28
29 VOID
30 EFIAPI
31 RuntimeDriverExitBootServices (
32 IN EFI_EVENT Event,
33 IN VOID *Context
34 )
35 /*++
36
37 Routine Description:
38
39 Set AtRuntime flag as TRUE after ExitBootServices
40
41 Arguments:
42
43 Event - The Event that is being processed
44
45 Context - Event Context
46
47 Returns:
48
49 None
50
51 --*/
52 {
53 //
54 // Clear out BootService globals
55 //
56 gBS = NULL;
57
58 mEfiAtRuntime = TRUE;
59 }
60
61 STATIC
62 VOID
63 EFIAPI
64 RuntimeLibVirtualNotifyEvent (
65 IN EFI_EVENT Event,
66 IN VOID *Context
67 )
68 /*++
69
70 Routine Description:
71
72 Fixup internal data so that EFI can be call in virtual mode.
73 Call the passed in Child Notify event and convert any pointers in
74 lib to virtual mode.
75
76 Arguments:
77
78 Event - The Event that is being processed
79
80 Context - Event Context
81
82 Returns:
83
84 None
85
86 --*/
87 {
88 UINTN Index;
89 EFI_EVENT_NOTIFY ChildNotifyEventHandler;
90
91 for (Index = 0;
92 _gDriverSetVirtualAddressMapEvent[Index] != NULL;
93 Index++) {
94 ChildNotifyEventHandler = _gDriverSetVirtualAddressMapEvent[Index];
95 ChildNotifyEventHandler (Event, NULL);
96 }
97
98 //
99 // Update global for Runtime Services Table and IO
100 //
101 EfiConvertPointer (0, (VOID **) &mRT);
102
103 mEfiGoneVirtual = TRUE;
104 }
105
106 EFI_STATUS
107 EFIAPI
108 RuntimeDriverLibConstruct (
109 IN EFI_HANDLE ImageHandle,
110 IN EFI_SYSTEM_TABLE *SystemTable
111 )
112 /*++
113
114 Routine Description:
115
116 Intialize runtime Driver Lib if it has not yet been initialized.
117
118 Arguments:
119
120 ImageHandle - The firmware allocated handle for the EFI image.
121
122 SystemTable - A pointer to the EFI System Table.
123
124 GoVirtualChildEvent - Caller can register a virtual notification event.
125
126 Returns:
127
128 EFI_STATUS always returns EFI_SUCCESS except EFI_ALREADY_STARTED if already started.
129
130 --*/
131 {
132 EFI_STATUS Status;
133
134 mRT = SystemTable->RuntimeServices;
135
136 //
137 // Register SetVirtualAddressMap () notify function
138 //
139 if (_gDriverSetVirtualAddressMapEvent[0] != NULL) {
140 Status = gBS->CreateEvent (
141 EFI_EVENT_SIGNAL_VIRTUAL_ADDRESS_CHANGE,
142 EFI_TPL_NOTIFY,
143 RuntimeLibVirtualNotifyEvent,
144 NULL,
145 &mEfiVirtualNotifyEvent
146 );
147
148 ASSERT_EFI_ERROR (Status);
149 }
150
151 return EFI_SUCCESS;
152 }
153
154 EFI_STATUS
155 EFIAPI
156 RuntimeDriverLibDeconstruct (
157 VOID
158 )
159 /*++
160
161 Routine Description:
162
163 This routine will free some resources which have been allocated in
164 EfiInitializeRuntimeDriverLib(). If a runtime driver exits with an error,
165 it must call this routine to free the allocated resource before the exiting.
166
167 Arguments:
168
169 None
170
171 Returns:
172
173 EFI_SUCCESS - Shotdown the Runtime Driver Lib successfully
174 EFI_UNSUPPORTED - Runtime Driver lib was not initialized at all
175
176 --*/
177 {
178 EFI_STATUS Status;
179
180 //
181 // Close SetVirtualAddressMap () notify function
182 //
183 if (_gDriverSetVirtualAddressMapEvent[0] != NULL) {
184 Status = gBS->CloseEvent (mEfiVirtualNotifyEvent);
185 ASSERT_EFI_ERROR (Status);
186 }
187
188 return EFI_SUCCESS;
189 }
190
191 BOOLEAN
192 EFIAPI
193 EfiAtRuntime (
194 VOID
195 )
196 /*++
197
198 Routine Description:
199 Return TRUE if ExitBootServices () has been called
200
201 Arguments:
202 NONE
203
204 Returns:
205 TRUE - If ExitBootServices () has been called
206
207 --*/
208 {
209 return mEfiAtRuntime;
210 }
211
212 BOOLEAN
213 EFIAPI
214 EfiGoneVirtual (
215 VOID
216 )
217 /*++
218
219 Routine Description:
220 Return TRUE if SetVirtualAddressMap () has been called
221
222 Arguments:
223 NONE
224
225 Returns:
226 TRUE - If SetVirtualAddressMap () has been called
227
228 --*/
229 {
230 return mEfiGoneVirtual;
231 }
232