]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/UefiRuntimeLib/RuntimeLib.c
Use GUIDed event for virtual address change event
[mirror_edk2.git] / MdePkg / Library / UefiRuntimeLib / RuntimeLib.c
CommitLineData
42eedea9 1/** @file\r
60c93673 2 UEFI Runtime Library implementation for non IPF processor types.\r
ebcc8fb7 3\r
60c93673 4Copyright (c) 2006 - 2008 Intel Corporation. <BR>\r
ebcc8fb7 5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
6c401377 15#include "RuntimeLibInternal.h"\r
ebcc8fb7 16\r
17///\r
18/// Driver Lib Module Globals\r
19///\r
20\r
fe467413 21EFI_EVENT mEfiVirtualNotifyEvent;\r
22EFI_EVENT mEfiExitBootServicesEvent;\r
23BOOLEAN mEfiGoneVirtual = FALSE;\r
24BOOLEAN mEfiAtRuntime = FALSE;\r
51969ecb 25EFI_RUNTIME_SERVICES *gInternalRT;\r
ebcc8fb7 26\r
27/**\r
42eedea9 28 Set AtRuntime flag as TRUE after ExitBootServices.\r
ebcc8fb7 29\r
30 @param[in] Event The Event that is being processed\r
31 @param[in] Context Event Context\r
32**/\r
33VOID\r
34EFIAPI\r
21998b67 35RuntimeLibExitBootServicesEvent (\r
ebcc8fb7 36 IN EFI_EVENT Event,\r
37 IN VOID *Context\r
38 )\r
39{\r
40 //\r
41 // Clear out BootService globals\r
42 //\r
43 gBS = NULL;\r
44\r
45 mEfiAtRuntime = TRUE;\r
46}\r
47\r
48/**\r
49 Fixup internal data so that EFI can be call in virtual mode.\r
50 Call the passed in Child Notify event and convert any pointers in\r
51 lib to virtual mode.\r
52\r
53 @param[in] Event The Event that is being processed\r
54 @param[in] Context Event Context\r
55**/\r
ebcc8fb7 56VOID\r
57EFIAPI\r
58RuntimeLibVirtualNotifyEvent (\r
59 IN EFI_EVENT Event,\r
60 IN VOID *Context\r
61 )\r
62{\r
ebcc8fb7 63 //\r
64 // Update global for Runtime Services Table and IO\r
65 //\r
51969ecb 66 EfiConvertPointer (0, (VOID **) &gInternalRT);\r
ebcc8fb7 67\r
68 mEfiGoneVirtual = TRUE;\r
69}\r
70\r
71/**\r
a9b896f4 72 Initialize runtime Driver Lib if it has not yet been initialized.\r
60c93673
LG
73 It will ASSERT() if gRT is NULL or gBS is NULL.\r
74 It will ASSERT() if that operation fails.\r
ebcc8fb7 75\r
76 @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
77 @param[in] SystemTable A pointer to the EFI System Table.\r
78\r
79 @return EFI_STATUS always returns EFI_SUCCESS except EFI_ALREADY_STARTED if already started.\r
80**/\r
81EFI_STATUS\r
82EFIAPI\r
83RuntimeDriverLibConstruct (\r
84 IN EFI_HANDLE ImageHandle,\r
85 IN EFI_SYSTEM_TABLE *SystemTable\r
86 )\r
87{\r
88 EFI_STATUS Status;\r
89\r
60c93673
LG
90 ASSERT (gRT != NULL);\r
91 ASSERT (gBS != NULL);\r
92\r
51969ecb 93 gInternalRT = gRT;\r
ebcc8fb7 94 //\r
95 // Register SetVirtualAddressMap () notify function\r
96 //\r
57a31578 97 Status = gBS->CreateEventEx (\r
98 EVT_NOTIFY_SIGNAL,\r
ebcc8fb7 99 TPL_NOTIFY,\r
100 RuntimeLibVirtualNotifyEvent,\r
101 NULL,\r
57a31578 102 &gEfiEventVirtualAddressChangeGuid,\r
ebcc8fb7 103 &mEfiVirtualNotifyEvent\r
104 );\r
105\r
106 ASSERT_EFI_ERROR (Status);\r
107\r
57a31578 108 Status = gBS->CreateEventEx (\r
109 EVT_NOTIFY_SIGNAL,\r
21998b67 110 TPL_NOTIFY,\r
111 RuntimeLibExitBootServicesEvent,\r
112 NULL,\r
57a31578 113 &gEfiEventExitBootServicesGuid,\r
21998b67 114 &mEfiExitBootServicesEvent\r
115 );\r
116\r
117 ASSERT_EFI_ERROR (Status);\r
118\r
ebcc8fb7 119 return Status;\r
120}\r
121\r
122/**\r
60c93673
LG
123 If a runtime driver exits with an error, it must call this routine \r
124 to free the allocated resource before the exiting.\r
125 It will ASSERT() if gBS is NULL.\r
126 It will ASSERT() if that operation fails.\r
ebcc8fb7 127\r
42eedea9 128 @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
129 @param[in] SystemTable A pointer to the EFI System Table.\r
130\r
ebcc8fb7 131 @retval EFI_SUCCESS Shutdown the Runtime Driver Lib successfully\r
132 @retval EFI_UNSUPPORTED Runtime Driver lib was not initialized at all\r
133**/\r
134EFI_STATUS\r
135EFIAPI\r
136RuntimeDriverLibDeconstruct (\r
137 IN EFI_HANDLE ImageHandle,\r
138 IN EFI_SYSTEM_TABLE *SystemTable\r
139 )\r
140{\r
141 EFI_STATUS Status;\r
142\r
143 //\r
144 // Close SetVirtualAddressMap () notify function\r
145 //\r
146 ASSERT (gBS != NULL);\r
147 Status = gBS->CloseEvent (mEfiVirtualNotifyEvent);\r
148 ASSERT_EFI_ERROR (Status);\r
149\r
21998b67 150 Status = gBS->CloseEvent (mEfiExitBootServicesEvent);\r
151 ASSERT_EFI_ERROR (Status);\r
152\r
ebcc8fb7 153 return Status;\r
154}\r
155\r
156/**\r
1d37ab9f 157 This function allows the caller to determine if UEFI ExitBootServices() has been called.\r
158\r
159 This function returns TRUE after all the EVT_SIGNAL_EXIT_BOOT_SERVICES functions have\r
160 executed as a result of the OS calling ExitBootServices(). Prior to this time FALSE\r
161 is returned. This function is used by runtime code to decide it is legal to access\r
162 services that go away after ExitBootServices().\r
163\r
164 @retval TRUE The system has finished executing the EVT_SIGNAL_EXIT_BOOT_SERVICES event.\r
165 @retval FALSE The system has not finished executing the EVT_SIGNAL_EXIT_BOOT_SERVICES event.\r
ebcc8fb7 166\r
ebcc8fb7 167**/\r
168BOOLEAN\r
169EFIAPI\r
170EfiAtRuntime (\r
171 VOID\r
172 )\r
173{\r
174 return mEfiAtRuntime;\r
175}\r
176\r
177/**\r
1d37ab9f 178 This function allows the caller to determine if UEFI SetVirtualAddressMap() has been called. \r
179\r
180 This function returns TRUE after all the EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE functions have\r
181 executed as a result of the OS calling SetVirtualAddressMap(). Prior to this time FALSE\r
182 is returned. This function is used by runtime code to decide it is legal to access services\r
183 that go away after SetVirtualAddressMap().\r
184\r
185 @retval TRUE The system has finished executing the EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.\r
186 @retval FALSE The system has not finished executing the EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.\r
ebcc8fb7 187\r
ebcc8fb7 188**/\r
189BOOLEAN\r
190EFIAPI\r
191EfiGoneVirtual (\r
192 VOID\r
193 )\r
194{\r
195 return mEfiGoneVirtual;\r
196}\r
197\r