]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/UefiRuntimeLib/RuntimeLib.c
Code have been checked with spec
[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
ebcc8fb7 25EFI_RUNTIME_SERVICES *mRT;\r
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
66 EfiConvertPointer (0, (VOID **) &mRT);\r
67\r
68 mEfiGoneVirtual = TRUE;\r
69}\r
70\r
71/**\r
72 Intialize 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
ad9e507a 93 mRT = gRT;\r
ebcc8fb7 94 //\r
95 // Register SetVirtualAddressMap () notify function\r
96 //\r
ebcc8fb7 97 Status = gBS->CreateEvent (\r
98 EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE,\r
99 TPL_NOTIFY,\r
100 RuntimeLibVirtualNotifyEvent,\r
101 NULL,\r
102 &mEfiVirtualNotifyEvent\r
103 );\r
104\r
105 ASSERT_EFI_ERROR (Status);\r
106\r
21998b67 107 Status = gBS->CreateEvent (\r
108 EVT_SIGNAL_EXIT_BOOT_SERVICES,\r
109 TPL_NOTIFY,\r
110 RuntimeLibExitBootServicesEvent,\r
111 NULL,\r
112 &mEfiExitBootServicesEvent\r
113 );\r
114\r
115 ASSERT_EFI_ERROR (Status);\r
116\r
ebcc8fb7 117 return Status;\r
118}\r
119\r
120/**\r
60c93673
LG
121 If a runtime driver exits with an error, it must call this routine \r
122 to free the allocated resource before the exiting.\r
123 It will ASSERT() if gBS is NULL.\r
124 It will ASSERT() if that operation fails.\r
ebcc8fb7 125\r
42eedea9 126 @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
127 @param[in] SystemTable A pointer to the EFI System Table.\r
128\r
ebcc8fb7 129 @retval EFI_SUCCESS Shutdown the Runtime Driver Lib successfully\r
130 @retval EFI_UNSUPPORTED Runtime Driver lib was not initialized at all\r
131**/\r
132EFI_STATUS\r
133EFIAPI\r
134RuntimeDriverLibDeconstruct (\r
135 IN EFI_HANDLE ImageHandle,\r
136 IN EFI_SYSTEM_TABLE *SystemTable\r
137 )\r
138{\r
139 EFI_STATUS Status;\r
140\r
141 //\r
142 // Close SetVirtualAddressMap () notify function\r
143 //\r
144 ASSERT (gBS != NULL);\r
145 Status = gBS->CloseEvent (mEfiVirtualNotifyEvent);\r
146 ASSERT_EFI_ERROR (Status);\r
147\r
21998b67 148 Status = gBS->CloseEvent (mEfiExitBootServicesEvent);\r
149 ASSERT_EFI_ERROR (Status);\r
150\r
ebcc8fb7 151 return Status;\r
152}\r
153\r
154/**\r
1d37ab9f 155 This function allows the caller to determine if UEFI ExitBootServices() has been called.\r
156\r
157 This function returns TRUE after all the EVT_SIGNAL_EXIT_BOOT_SERVICES functions have\r
158 executed as a result of the OS calling ExitBootServices(). Prior to this time FALSE\r
159 is returned. This function is used by runtime code to decide it is legal to access\r
160 services that go away after ExitBootServices().\r
161\r
162 @retval TRUE The system has finished executing the EVT_SIGNAL_EXIT_BOOT_SERVICES event.\r
163 @retval FALSE The system has not finished executing the EVT_SIGNAL_EXIT_BOOT_SERVICES event.\r
ebcc8fb7 164\r
ebcc8fb7 165**/\r
166BOOLEAN\r
167EFIAPI\r
168EfiAtRuntime (\r
169 VOID\r
170 )\r
171{\r
172 return mEfiAtRuntime;\r
173}\r
174\r
175/**\r
1d37ab9f 176 This function allows the caller to determine if UEFI SetVirtualAddressMap() has been called. \r
177\r
178 This function returns TRUE after all the EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE functions have\r
179 executed as a result of the OS calling SetVirtualAddressMap(). Prior to this time FALSE\r
180 is returned. This function is used by runtime code to decide it is legal to access services\r
181 that go away after SetVirtualAddressMap().\r
182\r
183 @retval TRUE The system has finished executing the EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.\r
184 @retval FALSE The system has not finished executing the EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.\r
ebcc8fb7 185\r
ebcc8fb7 186**/\r
187BOOLEAN\r
188EFIAPI\r
189EfiGoneVirtual (\r
190 VOID\r
191 )\r
192{\r
193 return mEfiGoneVirtual;\r
194}\r
195\r