]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Library/EdkUefiRuntimeLib/Common/RuntimeLib.c
1b11dfb5fa4a7f288f8680ba83f5005c8471a40a
[mirror_edk2.git] / EdkModulePkg / Library / EdkUefiRuntimeLib / Common / RuntimeLib.c
1 /**@file
2 Library utility functions for Runtime driver.
3
4 Copyright (c) 2006 Intel Corporation. <BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include <RuntimeLibInternal.h>
16
17 ///
18 /// Driver Lib Module Globals
19 ///
20
21 STATIC EFI_EVENT mEfiVirtualNotifyEvent;
22 STATIC BOOLEAN mEfiGoneVirtual = FALSE;
23 STATIC BOOLEAN mEfiAtRuntime = FALSE;
24 EFI_RUNTIME_SERVICES *mRT;
25
26 /**
27 Set AtRuntime flag as TRUE after ExitBootServices
28
29 @param[in] Event The Event that is being processed
30 @param[in] Context Event Context
31 **/
32 VOID
33 EFIAPI
34 RuntimeDriverExitBootServices (
35 IN EFI_EVENT Event,
36 IN VOID *Context
37 )
38 {
39 //
40 // Clear out BootService globals
41 //
42 gBS = NULL;
43
44 mEfiAtRuntime = TRUE;
45 }
46
47 /**
48 Fixup internal data so that EFI can be call in virtual mode.
49 Call the passed in Child Notify event and convert any pointers in
50 lib to virtual mode.
51
52 @param[in] Event The Event that is being processed
53 @param[in] Context Event Context
54 **/
55 STATIC
56 VOID
57 EFIAPI
58 RuntimeLibVirtualNotifyEvent (
59 IN EFI_EVENT Event,
60 IN VOID *Context
61 )
62 {
63 UINTN Index;
64 EFI_EVENT_NOTIFY ChildNotifyEventHandler;
65
66 for (Index = 0;
67 _gDriverSetVirtualAddressMapEvent[Index] != NULL;
68 Index++) {
69 ChildNotifyEventHandler = _gDriverSetVirtualAddressMapEvent[Index];
70 ChildNotifyEventHandler (Event, NULL);
71 }
72
73 //
74 // Update global for Runtime Services Table and IO
75 //
76 EfiConvertPointer (0, (VOID **) &mRT);
77
78 mEfiGoneVirtual = TRUE;
79 }
80
81 /**
82 Intialize runtime Driver Lib if it has not yet been initialized.
83
84 @param[in] ImageHandle The firmware allocated handle for the EFI image.
85 @param[in] SystemTable A pointer to the EFI System Table.
86
87 @return EFI_STATUS always returns EFI_SUCCESS except EFI_ALREADY_STARTED if already started.
88 **/
89 EFI_STATUS
90 EFIAPI
91 RuntimeDriverLibConstruct (
92 IN EFI_HANDLE ImageHandle,
93 IN EFI_SYSTEM_TABLE *SystemTable
94 )
95 {
96 EFI_STATUS Status;
97
98 ASSERT (SystemTable != NULL);
99 mRT = SystemTable->RuntimeServices;
100 ASSERT (mRT != NULL);
101
102 //
103 // Register SetVirtualAddressMap () notify function
104 //
105 if (_gDriverSetVirtualAddressMapEvent[0] != NULL) {
106 ASSERT (gBS != NULL);
107 Status = gBS->CreateEvent (
108 EFI_EVENT_SIGNAL_VIRTUAL_ADDRESS_CHANGE,
109 EFI_TPL_NOTIFY,
110 RuntimeLibVirtualNotifyEvent,
111 NULL,
112 &mEfiVirtualNotifyEvent
113 );
114
115 ASSERT_EFI_ERROR (Status);
116 }
117
118 return EFI_SUCCESS;
119 }
120
121 /**
122 This routine will free some resources which have been allocated in
123 EfiInitializeRuntimeDriverLib(). If a runtime driver exits with an error,
124 it must call this routine to free the allocated resource before the exiting.
125
126 @retval EFI_SUCCESS Shutdown the Runtime Driver Lib successfully
127 @retval EFI_UNSUPPORTED Runtime Driver lib was not initialized at all
128 **/
129 EFI_STATUS
130 EFIAPI
131 RuntimeDriverLibDeconstruct (
132 VOID
133 )
134 {
135 EFI_STATUS Status;
136
137 //
138 // Close SetVirtualAddressMap () notify function
139 //
140 if (_gDriverSetVirtualAddressMapEvent[0] != NULL) {
141 ASSERT (gBS != NULL);
142 Status = gBS->CloseEvent (mEfiVirtualNotifyEvent);
143 ASSERT_EFI_ERROR (Status);
144 }
145
146 return EFI_SUCCESS;
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