]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/UefiRuntimeLib/RuntimeLib.c
Restore original algorithm and add comments
[mirror_edk2.git] / MdePkg / Library / UefiRuntimeLib / RuntimeLib.c
CommitLineData
ebcc8fb7 1/**@file\r
2 Library utility functions for Runtime driver.\r
3\r
4Copyright (c) 2006 Intel Corporation. <BR>\r
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
15#include <RuntimeLibInternal.h>\r
16\r
17///\r
18/// Driver Lib Module Globals\r
19///\r
20\r
21STATIC EFI_EVENT mEfiVirtualNotifyEvent;\r
21998b67 22STATIC EFI_EVENT mEfiExitBootServicesEvent;\r
ebcc8fb7 23STATIC BOOLEAN mEfiGoneVirtual = FALSE;\r
24STATIC BOOLEAN mEfiAtRuntime = FALSE;\r
25EFI_RUNTIME_SERVICES *mRT;\r
26\r
27/**\r
28 Set AtRuntime flag as TRUE after ExitBootServices\r
29\r
30 @param[in] Event The Event that is being processed\r
31 @param[in] Context Event Context\r
32**/\r
21998b67 33STATIC\r
ebcc8fb7 34VOID\r
35EFIAPI\r
21998b67 36RuntimeLibExitBootServicesEvent (\r
ebcc8fb7 37 IN EFI_EVENT Event,\r
38 IN VOID *Context\r
39 )\r
40{\r
41 //\r
42 // Clear out BootService globals\r
43 //\r
44 gBS = NULL;\r
45\r
46 mEfiAtRuntime = TRUE;\r
47}\r
48\r
49/**\r
50 Fixup internal data so that EFI can be call in virtual mode.\r
51 Call the passed in Child Notify event and convert any pointers in\r
52 lib to virtual mode.\r
53\r
54 @param[in] Event The Event that is being processed\r
55 @param[in] Context Event Context\r
56**/\r
57STATIC\r
58VOID\r
59EFIAPI\r
60RuntimeLibVirtualNotifyEvent (\r
61 IN EFI_EVENT Event,\r
62 IN VOID *Context\r
63 )\r
64{\r
ebcc8fb7 65 //\r
66 // Update global for Runtime Services Table and IO\r
67 //\r
68 EfiConvertPointer (0, (VOID **) &mRT);\r
69\r
70 mEfiGoneVirtual = TRUE;\r
71}\r
72\r
73/**\r
74 Intialize runtime Driver Lib if it has not yet been initialized.\r
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
ad9e507a 90 mRT = gRT;\r
ebcc8fb7 91 ASSERT (mRT != NULL);\r
92 \r
93 //\r
94 // Register SetVirtualAddressMap () notify function\r
95 //\r
96 ASSERT (gBS != NULL);\r
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
121 This routine will free some resources which have been allocated in\r
122 EfiInitializeRuntimeDriverLib(). If a runtime driver exits with an error,\r
123 it must call this routine to free the allocated resource before the exiting.\r
124\r
125 @retval EFI_SUCCESS Shutdown the Runtime Driver Lib successfully\r
126 @retval EFI_UNSUPPORTED Runtime Driver lib was not initialized at all\r
127**/\r
128EFI_STATUS\r
129EFIAPI\r
130RuntimeDriverLibDeconstruct (\r
131 IN EFI_HANDLE ImageHandle,\r
132 IN EFI_SYSTEM_TABLE *SystemTable\r
133 )\r
134{\r
135 EFI_STATUS Status;\r
136\r
137 //\r
138 // Close SetVirtualAddressMap () notify function\r
139 //\r
140 ASSERT (gBS != NULL);\r
141 Status = gBS->CloseEvent (mEfiVirtualNotifyEvent);\r
142 ASSERT_EFI_ERROR (Status);\r
143\r
21998b67 144 Status = gBS->CloseEvent (mEfiExitBootServicesEvent);\r
145 ASSERT_EFI_ERROR (Status);\r
146\r
ebcc8fb7 147 return Status;\r
148}\r
149\r
150/**\r
151 Return TRUE if ExitBootServices () has been called\r
152\r
153 @retval TRUE If ExitBootServices () has been called\r
154**/\r
155BOOLEAN\r
156EFIAPI\r
157EfiAtRuntime (\r
158 VOID\r
159 )\r
160{\r
161 return mEfiAtRuntime;\r
162}\r
163\r
164/**\r
165 Return TRUE if SetVirtualAddressMap () has been called\r
166\r
167 @retval TRUE If SetVirtualAddressMap () has been called\r
168**/\r
169BOOLEAN\r
170EFIAPI\r
171EfiGoneVirtual (\r
172 VOID\r
173 )\r
174{\r
175 return mEfiGoneVirtual;\r
176}\r
177\r