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