]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - EdkModulePkg/Library/EdkUefiRuntimeLib/Common/RuntimeLib.c
Add more assert to check table pointer.
[mirror_edk2.git] / EdkModulePkg / Library / EdkUefiRuntimeLib / Common / RuntimeLib.c
... / ...
CommitLineData
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
22STATIC BOOLEAN mEfiGoneVirtual = FALSE;\r
23STATIC BOOLEAN mEfiAtRuntime = FALSE;\r
24EFI_RUNTIME_SERVICES *mRT;\r
25\r
26/**\r
27 Set AtRuntime flag as TRUE after ExitBootServices\r
28 \r
29 @param[in] Event The Event that is being processed\r
30 @param[in] Context Event Context\r
31**/\r
32VOID\r
33EFIAPI\r
34RuntimeDriverExitBootServices (\r
35 IN EFI_EVENT Event,\r
36 IN VOID *Context\r
37 )\r
38{\r
39 //\r
40 // Clear out BootService globals\r
41 //\r
42 gBS = NULL;\r
43\r
44 mEfiAtRuntime = TRUE;\r
45}\r
46\r
47/**\r
48 Fixup internal data so that EFI can be call in virtual mode.\r
49 Call the passed in Child Notify event and convert any pointers in \r
50 lib to virtual mode.\r
51 \r
52 @param[in] Event The Event that is being processed\r
53 @param[in] Context Event Context\r
54**/\r
55STATIC\r
56VOID\r
57EFIAPI\r
58RuntimeLibVirtualNotifyEvent (\r
59 IN EFI_EVENT Event,\r
60 IN VOID *Context\r
61 )\r
62{\r
63 UINTN Index;\r
64 EFI_EVENT_NOTIFY ChildNotifyEventHandler;\r
65\r
66 for (Index = 0; \r
67 _gDriverSetVirtualAddressMapEvent[Index] != NULL;\r
68 Index++) {\r
69 ChildNotifyEventHandler = _gDriverSetVirtualAddressMapEvent[Index];\r
70 ChildNotifyEventHandler (Event, NULL);\r
71 }\r
72\r
73 //\r
74 // Update global for Runtime Services Table and IO\r
75 //\r
76 EfiConvertPointer (0, (VOID **) &mRT);\r
77\r
78 mEfiGoneVirtual = TRUE;\r
79}\r
80\r
81/**\r
82 Intialize runtime Driver Lib if it has not yet been initialized. \r
83 \r
84 @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
85 @param[in] SystemTable A pointer to the EFI System Table.\r
86 \r
87 @return EFI_STATUS always returns EFI_SUCCESS except EFI_ALREADY_STARTED if already started.\r
88**/\r
89EFI_STATUS\r
90EFIAPI\r
91RuntimeDriverLibConstruct (\r
92 IN EFI_HANDLE ImageHandle,\r
93 IN EFI_SYSTEM_TABLE *SystemTable\r
94 )\r
95{\r
96 EFI_STATUS Status;\r
97\r
98 ASSERT (SystemTable != NULL);\r
99 mRT = SystemTable->RuntimeServices;\r
100 ASSERT (mRT != NULL);\r
101 \r
102 //\r
103 // Register SetVirtualAddressMap () notify function\r
104 // \r
105 if (_gDriverSetVirtualAddressMapEvent[0] != NULL) {\r
106 ASSERT (gBS != NULL);\r
107 Status = gBS->CreateEvent (\r
108 EFI_EVENT_SIGNAL_VIRTUAL_ADDRESS_CHANGE,\r
109 EFI_TPL_NOTIFY,\r
110 RuntimeLibVirtualNotifyEvent,\r
111 NULL,\r
112 &mEfiVirtualNotifyEvent\r
113 );\r
114\r
115 ASSERT_EFI_ERROR (Status);\r
116 }\r
117\r
118 return EFI_SUCCESS;\r
119}\r
120\r
121/**\r
122 This routine will free some resources which have been allocated in\r
123 EfiInitializeRuntimeDriverLib(). If a runtime driver exits with an error, \r
124 it must call this routine to free the allocated resource before the exiting.\r
125\r
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 VOID\r
133 )\r
134{\r
135 EFI_STATUS Status;\r
136\r
137 //\r
138 // Close SetVirtualAddressMap () notify function\r
139 //\r
140 if (_gDriverSetVirtualAddressMapEvent[0] != NULL) {\r
141 ASSERT (gBS != NULL);\r
142 Status = gBS->CloseEvent (mEfiVirtualNotifyEvent);\r
143 ASSERT_EFI_ERROR (Status);\r
144 }\r
145\r
146 return EFI_SUCCESS;\r
147}\r
148\r
149/**\r
150 Return TRUE if ExitBootServices () has been called\r
151 \r
152 @retval TRUE If ExitBootServices () has been called\r
153**/\r
154BOOLEAN\r
155EFIAPI\r
156EfiAtRuntime (\r
157 VOID\r
158 )\r
159{\r
160 return mEfiAtRuntime;\r
161}\r
162\r
163/**\r
164 Return TRUE if SetVirtualAddressMap () has been called\r
165 \r
166 @retval TRUE If SetVirtualAddressMap () has been called\r
167**/\r
168BOOLEAN\r
169EFIAPI\r
170EfiGoneVirtual (\r
171 VOID\r
172 )\r
173{\r
174 return mEfiGoneVirtual;\r
175}\r
176\r