]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Library/EdkDxeRuntimeDriverLib/Common/RuntimeLib.c
6cc2da31b0942897bf7b68062de1651420de30c0
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / EdkIIGlueLib / Library / EdkDxeRuntimeDriverLib / Common / RuntimeLib.c
1 /*++
2
3 Copyright (c) 2004 - 2006, Intel Corporation. All rights reserved.<BR>
4 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 mEfiAtRuntime = TRUE;
48 }
49
50 /**
51 Fixup internal data so that EFI can be call in virtual mode.
52 Call the passed in Child Notify event and convert any pointers in
53 lib to virtual mode.
54
55 @param[in] Event The Event that is being processed
56 @param[in] Context Event Context
57 **/
58 STATIC
59 VOID
60 EFIAPI
61 RuntimeLibVirtualNotifyEvent (
62 IN EFI_EVENT Event,
63 IN VOID *Context
64 )
65 {
66 UINTN Index;
67 EFI_EVENT_NOTIFY ChildNotifyEventHandler;
68
69 for (Index = 0;
70 _gDriverSetVirtualAddressMapEvent[Index] != NULL;
71 Index++) {
72 ChildNotifyEventHandler = _gDriverSetVirtualAddressMapEvent[Index];
73 ChildNotifyEventHandler (Event, NULL);
74 }
75
76 //
77 // Update global for Runtime Services Table and IO
78 //
79 EfiConvertPointer (0, (VOID **) &mRT);
80
81 mEfiGoneVirtual = TRUE;
82 }
83
84 /**
85 Intialize runtime Driver Lib if it has not yet been initialized.
86
87 @param[in] ImageHandle The firmware allocated handle for the EFI image.
88 @param[in] SystemTable A pointer to the EFI System Table.
89
90 @return EFI_STATUS always returns EFI_SUCCESS except EFI_ALREADY_STARTED if already started.
91 **/
92 EFI_STATUS
93 EFIAPI
94 RuntimeDriverLibConstruct (
95 IN EFI_HANDLE ImageHandle,
96 IN EFI_SYSTEM_TABLE *SystemTable
97 )
98 {
99 EFI_STATUS Status;
100
101 ASSERT (SystemTable != NULL);
102 mRT = SystemTable->RuntimeServices;
103 ASSERT (mRT != NULL);
104
105 //
106 // Register SetVirtualAddressMap () notify function
107 //
108 ASSERT (gBS != NULL);
109 Status = gBS->CreateEvent (
110 EFI_EVENT_SIGNAL_VIRTUAL_ADDRESS_CHANGE,
111 EFI_TPL_NOTIFY,
112 RuntimeLibVirtualNotifyEvent,
113 NULL,
114 &mEfiVirtualNotifyEvent
115 );
116
117 ASSERT_EFI_ERROR (Status);
118
119 return Status;
120 }
121
122 /**
123 This routine will free some resources which have been allocated in
124 EfiInitializeRuntimeDriverLib(). If a runtime driver exits with an error,
125 it must call this routine to free the allocated resource before the exiting.
126
127 @retval EFI_SUCCESS Shutdown the Runtime Driver Lib successfully
128 @retval EFI_UNSUPPORTED Runtime Driver lib was not initialized at all
129 **/
130 EFI_STATUS
131 EFIAPI
132 RuntimeDriverLibDeconstruct (
133 IN EFI_HANDLE ImageHandle,
134 IN EFI_SYSTEM_TABLE *SystemTable
135 )
136 {
137 EFI_STATUS Status;
138
139 //
140 // Close SetVirtualAddressMap () notify function
141 //
142 ASSERT (gBS != NULL);
143 Status = gBS->CloseEvent (mEfiVirtualNotifyEvent);
144 ASSERT_EFI_ERROR (Status);
145
146 return Status;
147 }
148
149 /**
150 Return TRUE if ExitBootServices () has been called
151
152 @retval TRUE If ExitBootServices () has been called
153 **/
154 BOOLEAN
155 EFIAPI
156 EfiAtRuntime (
157 VOID
158 )
159 {
160 return mEfiAtRuntime;
161 }
162
163 /**
164 Return TRUE if SetVirtualAddressMap () has been called
165
166 @retval TRUE If SetVirtualAddressMap () has been called
167 **/
168 BOOLEAN
169 EFIAPI
170 EfiGoneVirtual (
171 VOID
172 )
173 {
174 return mEfiGoneVirtual;
175 }
176