]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Library/EdkDxeRuntimeDriverLib/Common/RuntimeLib.c
Add in the 1st version of ECP.
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / EdkIIGlueLib / Library / EdkDxeRuntimeDriverLib / Common / RuntimeLib.c
1 /*++
2
3 Copyright (c) 2004 - 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
13 Module Name:
14
15 RuntimeLib.c
16
17 Abstract:
18
19 Runtime lib
20
21 --*/
22
23 #include "..\RuntimeLibInternal.h"
24
25 //
26 // Driver Lib Module Globals
27 //
28
29 STATIC EFI_EVENT mEfiVirtualNotifyEvent;
30 STATIC BOOLEAN mEfiGoneVirtual = FALSE;
31 STATIC BOOLEAN mEfiAtRuntime = FALSE;
32 EFI_RUNTIME_SERVICES *mRT;
33
34 /**
35 Set AtRuntime flag as TRUE after ExitBootServices
36
37 @param[in] Event The Event that is being processed
38 @param[in] Context Event Context
39 **/
40 VOID
41 EFIAPI
42 RuntimeDriverExitBootServices (
43 IN EFI_EVENT Event,
44 IN VOID *Context
45 )
46 {
47 //
48 // Clear out BootService globals
49 //
50 gBS = NULL;
51
52 mEfiAtRuntime = TRUE;
53 }
54
55 /**
56 Fixup internal data so that EFI can be call in virtual mode.
57 Call the passed in Child Notify event and convert any pointers in
58 lib to virtual mode.
59
60 @param[in] Event The Event that is being processed
61 @param[in] Context Event Context
62 **/
63 STATIC
64 VOID
65 EFIAPI
66 RuntimeLibVirtualNotifyEvent (
67 IN EFI_EVENT Event,
68 IN VOID *Context
69 )
70 {
71 UINTN Index;
72 EFI_EVENT_NOTIFY ChildNotifyEventHandler;
73
74 for (Index = 0;
75 _gDriverSetVirtualAddressMapEvent[Index] != NULL;
76 Index++) {
77 ChildNotifyEventHandler = _gDriverSetVirtualAddressMapEvent[Index];
78 ChildNotifyEventHandler (Event, NULL);
79 }
80
81 //
82 // Update global for Runtime Services Table and IO
83 //
84 EfiConvertPointer (0, (VOID **) &mRT);
85
86 mEfiGoneVirtual = TRUE;
87 }
88
89 /**
90 Intialize runtime Driver Lib if it has not yet been initialized.
91
92 @param[in] ImageHandle The firmware allocated handle for the EFI image.
93 @param[in] SystemTable A pointer to the EFI System Table.
94
95 @return EFI_STATUS always returns EFI_SUCCESS except EFI_ALREADY_STARTED if already started.
96 **/
97 EFI_STATUS
98 EFIAPI
99 RuntimeDriverLibConstruct (
100 IN EFI_HANDLE ImageHandle,
101 IN EFI_SYSTEM_TABLE *SystemTable
102 )
103 {
104 EFI_STATUS Status;
105
106 ASSERT (SystemTable != NULL);
107 mRT = SystemTable->RuntimeServices;
108 ASSERT (mRT != NULL);
109
110 //
111 // Register SetVirtualAddressMap () notify function
112 //
113 ASSERT (gBS != NULL);
114 Status = gBS->CreateEvent (
115 EFI_EVENT_SIGNAL_VIRTUAL_ADDRESS_CHANGE,
116 EFI_TPL_NOTIFY,
117 RuntimeLibVirtualNotifyEvent,
118 NULL,
119 &mEfiVirtualNotifyEvent
120 );
121
122 ASSERT_EFI_ERROR (Status);
123
124 return EFI_SUCCESS;
125 }
126
127 /**
128 This routine will free some resources which have been allocated in
129 EfiInitializeRuntimeDriverLib(). If a runtime driver exits with an error,
130 it must call this routine to free the allocated resource before the exiting.
131
132 @retval EFI_SUCCESS Shutdown the Runtime Driver Lib successfully
133 @retval EFI_UNSUPPORTED Runtime Driver lib was not initialized at all
134 **/
135 EFI_STATUS
136 EFIAPI
137 RuntimeDriverLibDeconstruct (
138 IN EFI_HANDLE ImageHandle,
139 IN EFI_SYSTEM_TABLE *SystemTable
140 )
141 {
142 EFI_STATUS Status;
143
144 //
145 // Close SetVirtualAddressMap () notify function
146 //
147 ASSERT (gBS != NULL);
148 Status = gBS->CloseEvent (mEfiVirtualNotifyEvent);
149 ASSERT_EFI_ERROR (Status);
150
151 return EFI_SUCCESS;
152 }
153
154 /**
155 Return TRUE if ExitBootServices () has been called
156
157 @retval TRUE If ExitBootServices () has been called
158 **/
159 BOOLEAN
160 EFIAPI
161 EfiAtRuntime (
162 VOID
163 )
164 {
165 return mEfiAtRuntime;
166 }
167
168 /**
169 Return TRUE if SetVirtualAddressMap () has been called
170
171 @retval TRUE If SetVirtualAddressMap () has been called
172 **/
173 BOOLEAN
174 EFIAPI
175 EfiGoneVirtual (
176 VOID
177 )
178 {
179 return mEfiGoneVirtual;
180 }
181