2 DXE Core library services.
4 Copyright (c) 2006 - 2007, Intel Corporation
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
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.
17 UINTN mErrorLevel
= EFI_D_ERROR
| EFI_D_LOAD
;
19 EFI_DXE_DEVICE_HANDLE_EXTENDED_DATA mStatusCodeData
= {
21 sizeof (EFI_STATUS_CODE_DATA
),
23 EFI_STATUS_CODE_DXE_CORE_GUID
29 CoreReportProgressCodeSpecific (
30 IN EFI_STATUS_CODE_VALUE Value
,
37 Report status code of type EFI_PROGRESS_CODE by caller ID gEfiCallerIdGuid,
38 with a handle as additional information.
42 Value - Describes the class/subclass/operation of the hardware or software entity
43 that the Status Code relates to.
45 Handle - Additional information.
53 mStatusCodeData
.DataHeader
.Size
= sizeof (EFI_DXE_DEVICE_HANDLE_EXTENDED_DATA
) - sizeof (EFI_STATUS_CODE_DATA
);
54 mStatusCodeData
.Handle
= Handle
;
56 if ((gStatusCode
!= NULL
) && (gStatusCode
->ReportStatusCode
!= NULL
) ) {
57 gStatusCode
->ReportStatusCode (
62 (EFI_STATUS_CODE_DATA
*) &mStatusCodeData
68 CoreReportProgressCode (
69 IN EFI_STATUS_CODE_VALUE Value
75 Report status code of type EFI_PROGRESS_CODE by caller ID gEfiCallerIdGuid.
79 Value - Describes the class/subclass/operation of the hardware or software entity
80 that the Status Code relates to.
88 if ((gStatusCode
!= NULL
) && (gStatusCode
->ReportStatusCode
!= NULL
) ) {
89 gStatusCode
->ReportStatusCode (
101 CoreAllocateBootServicesPool (
102 IN UINTN AllocationSize
108 Allocate pool of type EfiBootServicesData, the size is specified with AllocationSize.
112 AllocationSize - Size to allocate.
116 Pointer of the allocated pool.
122 CoreAllocatePool (EfiBootServicesData
, AllocationSize
, &Memory
);
128 CoreAllocateZeroBootServicesPool (
129 IN UINTN AllocationSize
135 Allocate pool of type EfiBootServicesData and zero it, the size is specified with AllocationSize.
139 AllocationSize - Size to allocate.
143 Pointer of the allocated pool.
149 Memory
= CoreAllocateBootServicesPool (AllocationSize
);
150 SetMem (Memory
, (Memory
== NULL
) ? 0 : AllocationSize
, 0);
156 CoreAllocateCopyPool (
157 IN UINTN AllocationSize
,
164 Allocate pool of specified size with EfiBootServicesData type, and copy specified buffer to this pool.
168 AllocationSize - Size to allocate.
170 Buffer - Specified buffer that will be copy to the allocated pool
174 Pointer of the allocated pool.
180 Memory
= CoreAllocateBootServicesPool (AllocationSize
);
181 CopyMem (Memory
, Buffer
, (Memory
== NULL
) ? 0 : AllocationSize
);
189 CoreAllocateRuntimePool (
190 IN UINTN AllocationSize
196 Allocate pool of type EfiRuntimeServicesData, the size is specified with AllocationSize.
200 AllocationSize - Size to allocate.
204 Pointer of the allocated pool.
210 CoreAllocatePool (EfiRuntimeServicesData
, AllocationSize
, &Memory
);
215 CoreAllocateRuntimeCopyPool (
216 IN UINTN AllocationSize
,
223 Allocate pool of specified size with EfiRuntimeServicesData type, and copy specified buffer to this pool.
227 AllocationSize - Size to allocate.
229 Buffer - Specified buffer that will be copy to the allocated pool
233 Pointer of the allocated pool.
240 Memory
= CoreAllocateRuntimePool (AllocationSize
);
241 CopyMem (Memory
, Buffer
, (Memory
== NULL
) ? 0 : AllocationSize
);
255 CoreAcquireLockOrFail (
262 Initialize a basic mutual exclusion lock. Each lock
263 provides mutual exclusion access at it's task priority
264 level. Since there is no-premption (at any TPL) or
265 multiprocessor support, acquiring the lock only consists
266 of raising to the locks TPL.
270 Lock - The EFI_LOCK structure to initialize
274 EFI_SUCCESS - Lock Owned.
275 EFI_ACCESS_DENIED - Reentrant Lock Acquisition, Lock not Owned.
279 ASSERT (Lock
!= NULL
);
280 ASSERT (Lock
->Lock
!= EfiLockUninitialized
);
282 if (Lock
->Lock
== EfiLockAcquired
) {
284 // Lock is already owned, so bail out
286 return EFI_ACCESS_DENIED
;
289 Lock
->OwnerTpl
= CoreRaiseTpl (Lock
->Tpl
);
291 Lock
->Lock
= EfiLockAcquired
;
304 Raising to the task priority level of the mutual exclusion
305 lock, and then acquires ownership of the lock.
309 Lock - The lock to acquire
317 ASSERT (Lock
!= NULL
);
318 ASSERT (Lock
->Lock
== EfiLockReleased
);
320 Lock
->OwnerTpl
= CoreRaiseTpl (Lock
->Tpl
);
321 Lock
->Lock
= EfiLockAcquired
;
333 Releases ownership of the mutual exclusion lock, and
334 restores the previous task priority level.
338 Lock - The lock to release
348 ASSERT (Lock
!= NULL
);
349 ASSERT (Lock
->Lock
== EfiLockAcquired
);
351 Tpl
= Lock
->OwnerTpl
;
353 Lock
->Lock
= EfiLockReleased
;
355 CoreRestoreTpl (Tpl
);
361 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
367 Calculate the size of a whole device path.
371 DevicePath - The pointer to the device path data.
375 Size of device path data structure..
379 EFI_DEVICE_PATH_PROTOCOL
*Start
;
381 if (DevicePath
== NULL
) {
386 // Search for the end of the device path structure
389 while (!EfiIsDevicePathEnd (DevicePath
)) {
390 DevicePath
= EfiNextDevicePathNode (DevicePath
);
394 // Compute the size and add back in the size of the end device path structure
396 return ((UINTN
)DevicePath
- (UINTN
)Start
) + sizeof(EFI_DEVICE_PATH_PROTOCOL
);
401 CoreIsDevicePathMultiInstance (
402 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
407 Return TRUE is this is a multi instance device path.
410 DevicePath - A pointer to a device path data structure.
414 TRUE - If DevicePath is multi instance. FALSE - If DevicePath is not multi
419 EFI_DEVICE_PATH_PROTOCOL
*Node
;
421 if (DevicePath
== NULL
) {
426 while (!EfiIsDevicePathEnd (Node
)) {
427 if (EfiIsDevicePathEndInstance (Node
)) {
430 Node
= EfiNextDevicePathNode (Node
);
437 EFI_DEVICE_PATH_PROTOCOL
*
438 CoreDuplicateDevicePath (
439 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
444 Duplicate a new device path data structure from the old one.
447 DevicePath - A pointer to a device path data structure.
450 A pointer to the new allocated device path data.
451 Caller must free the memory used by DevicePath if it is no longer needed.
455 EFI_DEVICE_PATH_PROTOCOL
*NewDevicePath
;
458 if (DevicePath
== NULL
) {
465 Size
= CoreDevicePathSize (DevicePath
);
468 // Allocate space for duplicate device path
470 NewDevicePath
= CoreAllocateCopyPool (Size
, DevicePath
);
472 return NewDevicePath
;
477 EFI_DEVICE_PATH_PROTOCOL
*
478 CoreAppendDevicePath (
479 IN EFI_DEVICE_PATH_PROTOCOL
*Src1
,
480 IN EFI_DEVICE_PATH_PROTOCOL
*Src2
485 Function is used to append a Src1 and Src2 together.
488 Src1 - A pointer to a device path data structure.
490 Src2 - A pointer to a device path data structure.
494 A pointer to the new device path is returned.
495 NULL is returned if space for the new device path could not be allocated from pool.
496 It is up to the caller to free the memory used by Src1 and Src2 if they are no longer needed.
503 EFI_DEVICE_PATH_PROTOCOL
*NewDevicePath
;
504 EFI_DEVICE_PATH_PROTOCOL
*SecondDevicePath
;
506 if (Src1
== NULL
&& Src2
== NULL
) {
511 // Allocate space for the combined device path. It only has one end node of
512 // length EFI_DEVICE_PATH_PROTOCOL
514 Size1
= CoreDevicePathSize (Src1
);
515 Size2
= CoreDevicePathSize (Src2
);
516 Size
= Size1
+ Size2
- sizeof(EFI_DEVICE_PATH_PROTOCOL
);
518 NewDevicePath
= CoreAllocateCopyPool (Size
, Src1
);
519 if (NewDevicePath
!= NULL
) {
522 // Over write Src1 EndNode and do the copy
524 SecondDevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*)((CHAR8
*)NewDevicePath
+ (Size1
- sizeof(EFI_DEVICE_PATH_PROTOCOL
)));
525 CopyMem (SecondDevicePath
, Src2
, Size2
);
528 return NewDevicePath
;
534 CoreCreateProtocolNotifyEvent (
535 IN EFI_GUID
*ProtocolGuid
,
536 IN EFI_TPL NotifyTpl
,
537 IN EFI_EVENT_NOTIFY NotifyFunction
,
538 IN VOID
*NotifyContext
,
539 OUT VOID
**Registration
,
540 IN BOOLEAN SignalFlag
546 Create a protocol notification event and return it.
550 ProtocolGuid - Protocol to register notification event on.
552 NotifyTpl - Maximum TPL to signal the NotifyFunction.
554 NotifyFuncition - EFI notification routine.
556 NotifyContext - Context passed into Event when it is created.
558 Registration - Registration key returned from RegisterProtocolNotify().
560 SignalFlag - Boolean value to decide whether kick the event after register or not.
564 The EFI_EVENT that has been registered to be signaled when a ProtocolGuid
565 is added to the system.
576 Status
= CoreCreateEvent (
583 ASSERT_EFI_ERROR (Status
);
586 // Register for protocol notifactions on this event
589 Status
= CoreRegisterProtocolNotify (
594 ASSERT_EFI_ERROR (Status
);
598 // Kick the event so we will perform an initial pass of
599 // current installed drivers
601 CoreSignalEvent (Event
);