]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/UefiRuntimeLib/RuntimeLib.c
Code Scrub for Protocol Definition
[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
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
73\r
74 @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
75 @param[in] SystemTable A pointer to the EFI System Table.\r
76\r
77 @return EFI_STATUS always returns EFI_SUCCESS except EFI_ALREADY_STARTED if already started.\r
78**/\r
79EFI_STATUS\r
80EFIAPI\r
81RuntimeDriverLibConstruct (\r
82 IN EFI_HANDLE ImageHandle,\r
83 IN EFI_SYSTEM_TABLE *SystemTable\r
84 )\r
85{\r
86 EFI_STATUS Status;\r
87\r
ad9e507a 88 mRT = gRT;\r
ebcc8fb7 89 ASSERT (mRT != NULL);\r
90 \r
91 //\r
92 // Register SetVirtualAddressMap () notify function\r
93 //\r
94 ASSERT (gBS != NULL);\r
95 Status = gBS->CreateEvent (\r
96 EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE,\r
97 TPL_NOTIFY,\r
98 RuntimeLibVirtualNotifyEvent,\r
99 NULL,\r
100 &mEfiVirtualNotifyEvent\r
101 );\r
102\r
103 ASSERT_EFI_ERROR (Status);\r
104\r
21998b67 105 Status = gBS->CreateEvent (\r
106 EVT_SIGNAL_EXIT_BOOT_SERVICES,\r
107 TPL_NOTIFY,\r
108 RuntimeLibExitBootServicesEvent,\r
109 NULL,\r
110 &mEfiExitBootServicesEvent\r
111 );\r
112\r
113 ASSERT_EFI_ERROR (Status);\r
114\r
ebcc8fb7 115 return Status;\r
116}\r
117\r
118/**\r
119 This routine will free some resources which have been allocated in\r
120 EfiInitializeRuntimeDriverLib(). If a runtime driver exits with an error,\r
121 it must call this routine to free the allocated resource before the exiting.\r
122\r
123 @retval EFI_SUCCESS Shutdown the Runtime Driver Lib successfully\r
124 @retval EFI_UNSUPPORTED Runtime Driver lib was not initialized at all\r
125**/\r
126EFI_STATUS\r
127EFIAPI\r
128RuntimeDriverLibDeconstruct (\r
129 IN EFI_HANDLE ImageHandle,\r
130 IN EFI_SYSTEM_TABLE *SystemTable\r
131 )\r
132{\r
133 EFI_STATUS Status;\r
134\r
135 //\r
136 // Close SetVirtualAddressMap () notify function\r
137 //\r
138 ASSERT (gBS != NULL);\r
139 Status = gBS->CloseEvent (mEfiVirtualNotifyEvent);\r
140 ASSERT_EFI_ERROR (Status);\r
141\r
21998b67 142 Status = gBS->CloseEvent (mEfiExitBootServicesEvent);\r
143 ASSERT_EFI_ERROR (Status);\r
144\r
ebcc8fb7 145 return Status;\r
146}\r
147\r
148/**\r
149 Return TRUE if ExitBootServices () has been called\r
150\r
151 @retval TRUE If ExitBootServices () has been called\r
152**/\r
153BOOLEAN\r
154EFIAPI\r
155EfiAtRuntime (\r
156 VOID\r
157 )\r
158{\r
159 return mEfiAtRuntime;\r
160}\r
161\r
162/**\r
163 Return TRUE if SetVirtualAddressMap () has been called\r
164\r
165 @retval TRUE If SetVirtualAddressMap () has been called\r
166**/\r
167BOOLEAN\r
168EFIAPI\r
169EfiGoneVirtual (\r
170 VOID\r
171 )\r
172{\r
173 return mEfiGoneVirtual;\r
174}\r
175\r