]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Core/Dxe/Library/Library.c
Clean up DxeCore to remove duplicate memory allocation & device path utility services...
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Library / Library.c
CommitLineData
162ed594 1/** @file\r
797a9d67 2 DXE Core library services.\r
23c98c94 3\r
4Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r
28a00297 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
797a9d67 13**/\r
28a00297 14\r
9c4ac31c 15#include "DxeMain.h"\r
28a00297 16\r
162ed594 17UINTN mErrorLevel = DEBUG_ERROR | DEBUG_LOAD;\r
28a00297 18\r
797a9d67 19EFI_DXE_DEVICE_HANDLE_EXTENDED_DATA mStatusCodeData = {\r
28a00297 20 {\r
21 sizeof (EFI_STATUS_CODE_DATA),\r
22 0,\r
797a9d67 23 EFI_STATUS_CODE_DXE_CORE_GUID\r
28a00297 24 },\r
25 NULL\r
26};\r
27\r
28a00297 28\r
162ed594 29/**\r
eba54e17 30 Report status code of type EFI_PROGRESS_CODE by caller ID gEfiCallerIdGuid,\r
28a00297 31 with a handle as additional information.\r
32\r
022c6d45 33 @param Value Describes the class/subclass/operation of the\r
34 hardware or software entity that the Status Code\r
35 relates to.\r
162ed594 36 @param Handle Additional information.\r
28a00297 37\r
162ed594 38**/\r
39VOID\r
40CoreReportProgressCodeSpecific (\r
41 IN EFI_STATUS_CODE_VALUE Value,\r
42 IN EFI_HANDLE Handle\r
43 )\r
28a00297 44{\r
797a9d67 45 mStatusCodeData.DataHeader.Size = sizeof (EFI_DXE_DEVICE_HANDLE_EXTENDED_DATA) - sizeof (EFI_STATUS_CODE_DATA);\r
28a00297 46 mStatusCodeData.Handle = Handle;\r
47\r
48 if ((gStatusCode != NULL) && (gStatusCode->ReportStatusCode != NULL) ) {\r
49 gStatusCode->ReportStatusCode (\r
50 EFI_PROGRESS_CODE,\r
51 Value,\r
52 0,\r
eba54e17 53 &gEfiCallerIdGuid,\r
28a00297 54 (EFI_STATUS_CODE_DATA *) &mStatusCodeData\r
55 );\r
56 }\r
57}\r
58\r
28a00297 59\r
162ed594 60/**\r
eba54e17 61 Report status code of type EFI_PROGRESS_CODE by caller ID gEfiCallerIdGuid.\r
28a00297 62\r
022c6d45 63 @param Value Describes the class/subclass/operation of the\r
64 hardware or software entity that the Status Code\r
162ed594 65 relates to.\r
28a00297 66\r
162ed594 67**/\r
68VOID\r
69CoreReportProgressCode (\r
70 IN EFI_STATUS_CODE_VALUE Value\r
71 )\r
28a00297 72{\r
73 if ((gStatusCode != NULL) && (gStatusCode->ReportStatusCode != NULL) ) {\r
74 gStatusCode->ReportStatusCode (\r
75 EFI_PROGRESS_CODE,\r
76 Value,\r
77 0,\r
eba54e17 78 &gEfiCallerIdGuid,\r
28a00297 79 NULL\r
80 );\r
81 }\r
82}\r
83\r
84\r
28a00297 85//\r
86// Lock Stuff\r
87//\r
162ed594 88/**\r
28a00297 89 Initialize a basic mutual exclusion lock. Each lock\r
90 provides mutual exclusion access at it's task priority\r
91 level. Since there is no-premption (at any TPL) or\r
92 multiprocessor support, acquiring the lock only consists\r
93 of raising to the locks TPL.\r
94\r
022c6d45 95 @param Lock The EFI_LOCK structure to initialize\r
28a00297 96\r
022c6d45 97 @retval EFI_SUCCESS Lock Owned.\r
162ed594 98 @retval EFI_ACCESS_DENIED Reentrant Lock Acquisition, Lock not Owned.\r
28a00297 99\r
162ed594 100**/\r
101EFI_STATUS\r
102CoreAcquireLockOrFail (\r
103 IN EFI_LOCK *Lock\r
104 )\r
28a00297 105{\r
106 ASSERT (Lock != NULL);\r
107 ASSERT (Lock->Lock != EfiLockUninitialized);\r
108\r
109 if (Lock->Lock == EfiLockAcquired) {\r
110 //\r
111 // Lock is already owned, so bail out\r
112 //\r
113 return EFI_ACCESS_DENIED;\r
114 }\r
115\r
116 Lock->OwnerTpl = CoreRaiseTpl (Lock->Tpl);\r
117\r
118 Lock->Lock = EfiLockAcquired;\r
119 return EFI_SUCCESS;\r
120}\r
121\r
122\r
28a00297 123\r
162ed594 124/**\r
28a00297 125 Raising to the task priority level of the mutual exclusion\r
126 lock, and then acquires ownership of the lock.\r
127\r
022c6d45 128 @param Lock The lock to acquire\r
28a00297 129\r
162ed594 130 @return Lock owned\r
28a00297 131\r
162ed594 132**/\r
133VOID\r
134CoreAcquireLock (\r
135 IN EFI_LOCK *Lock\r
136 )\r
28a00297 137{\r
138 ASSERT (Lock != NULL);\r
139 ASSERT (Lock->Lock == EfiLockReleased);\r
140\r
141 Lock->OwnerTpl = CoreRaiseTpl (Lock->Tpl);\r
142 Lock->Lock = EfiLockAcquired;\r
143}\r
144\r
145\r
28a00297 146\r
162ed594 147/**\r
148 Releases ownership of the mutual exclusion lock, and\r
149 restores the previous task priority level.\r
28a00297 150\r
022c6d45 151 @param Lock The lock to release\r
28a00297 152\r
162ed594 153 @return Lock unowned\r
28a00297 154\r
162ed594 155**/\r
156VOID\r
157CoreReleaseLock (\r
158 IN EFI_LOCK *Lock\r
159 )\r
28a00297 160{\r
161 EFI_TPL Tpl;\r
162\r
163 ASSERT (Lock != NULL);\r
164 ASSERT (Lock->Lock == EfiLockAcquired);\r
165\r
166 Tpl = Lock->OwnerTpl;\r
167\r
168 Lock->Lock = EfiLockReleased;\r
169\r
170 CoreRestoreTpl (Tpl);\r
171}\r
172\r
173\r
162ed594 174/**\r
175 Create a protocol notification event and return it.\r
176\r
022c6d45 177 @param ProtocolGuid Protocol to register notification event on.\r
178 @param NotifyTpl Maximum TPL to signal the NotifyFunction.\r
179 @param NotifyFunction EFI notification routine.\r
180 @param NotifyContext Context passed into Event when it is created.\r
181 @param Registration Registration key returned from\r
182 RegisterProtocolNotify().\r
183 @param SignalFlag Boolean value to decide whether kick the event after\r
184 register or not.\r
162ed594 185\r
186 @return The EFI_EVENT that has been registered to be signaled when a ProtocolGuid\r
187 is added to the system.\r
188\r
189**/\r
28a00297 190EFI_EVENT\r
191CoreCreateProtocolNotifyEvent (\r
192 IN EFI_GUID *ProtocolGuid,\r
193 IN EFI_TPL NotifyTpl,\r
194 IN EFI_EVENT_NOTIFY NotifyFunction,\r
195 IN VOID *NotifyContext,\r
196 OUT VOID **Registration,\r
197 IN BOOLEAN SignalFlag\r
198 )\r
28a00297 199{\r
200 EFI_STATUS Status;\r
201 EFI_EVENT Event;\r
202\r
203 //\r
204 // Create the event\r
205 //\r
28a00297 206 Status = CoreCreateEvent (\r
207 EVT_NOTIFY_SIGNAL,\r
208 NotifyTpl,\r
209 NotifyFunction,\r
210 NotifyContext,\r
e94a9ff7 211 &Event\r
28a00297 212 );\r
213 ASSERT_EFI_ERROR (Status);\r
214\r
215 //\r
216 // Register for protocol notifactions on this event\r
217 //\r
28a00297 218 Status = CoreRegisterProtocolNotify (\r
e94a9ff7 219 ProtocolGuid,\r
220 Event,\r
221 Registration\r
222 );\r
28a00297 223 ASSERT_EFI_ERROR (Status);\r
224\r
225 if (SignalFlag) {\r
226 //\r
227 // Kick the event so we will perform an initial pass of\r
228 // current installed drivers\r
229 //\r
230 CoreSignalEvent (Event);\r
231 }\r
232\r
233 return Event;\r
234}\r
235\r
162ed594 236\r