]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/UefiRuntimeLib/RuntimeLib.c
edk2/MdePkg/Include/Ia32/ProcessorBind.h:
[mirror_edk2.git] / MdePkg / Library / UefiRuntimeLib / RuntimeLib.c
CommitLineData
42eedea9 1/** @file\r
ebcc8fb7 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
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
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
42eedea9 123 @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
124 @param[in] SystemTable A pointer to the EFI System Table.\r
125\r
ebcc8fb7 126 @retval EFI_SUCCESS Shutdown the Runtime Driver Lib successfully\r
127 @retval EFI_UNSUPPORTED Runtime Driver lib was not initialized at all\r
128**/\r
129EFI_STATUS\r
130EFIAPI\r
131RuntimeDriverLibDeconstruct (\r
132 IN EFI_HANDLE ImageHandle,\r
133 IN EFI_SYSTEM_TABLE *SystemTable\r
134 )\r
135{\r
136 EFI_STATUS Status;\r
137\r
138 //\r
139 // Close SetVirtualAddressMap () notify function\r
140 //\r
141 ASSERT (gBS != NULL);\r
142 Status = gBS->CloseEvent (mEfiVirtualNotifyEvent);\r
143 ASSERT_EFI_ERROR (Status);\r
144\r
21998b67 145 Status = gBS->CloseEvent (mEfiExitBootServicesEvent);\r
146 ASSERT_EFI_ERROR (Status);\r
147\r
ebcc8fb7 148 return Status;\r
149}\r
150\r
151/**\r
42eedea9 152 Return TRUE if ExitBootServices () has been called.\r
ebcc8fb7 153\r
154 @retval TRUE If ExitBootServices () has been called\r
155**/\r
156BOOLEAN\r
157EFIAPI\r
158EfiAtRuntime (\r
159 VOID\r
160 )\r
161{\r
162 return mEfiAtRuntime;\r
163}\r
164\r
165/**\r
42eedea9 166 Return TRUE if SetVirtualAddressMap () has been called.\r
ebcc8fb7 167\r
168 @retval TRUE If SetVirtualAddressMap () has been called\r
169**/\r
170BOOLEAN\r
171EFIAPI\r
172EfiGoneVirtual (\r
173 VOID\r
174 )\r
175{\r
176 return mEfiGoneVirtual;\r
177}\r
178\r