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