3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 DXE Core library services.
24 UINTN mErrorLevel
= EFI_D_ERROR
| EFI_D_LOAD
;
26 EFI_DEVICE_HANDLE_EXTENDED_DATA mStatusCodeData
= {
28 sizeof (EFI_STATUS_CODE_DATA
),
30 EFI_STATUS_CODE_SPECIFIC_DATA_GUID
36 CoreReportProgressCodeSpecific (
37 IN EFI_STATUS_CODE_VALUE Value
,
44 Report status code of type EFI_PROGRESS_CODE by caller ID gEfiDxeServicesTableGuid,
45 with a handle as additional information.
49 Value - Describes the class/subclass/operation of the hardware or software entity
50 that the Status Code relates to.
52 Handle - Additional information.
60 mStatusCodeData
.DataHeader
.Size
= sizeof (EFI_DEVICE_HANDLE_EXTENDED_DATA
) - sizeof (EFI_STATUS_CODE_DATA
);
61 mStatusCodeData
.Handle
= Handle
;
63 if ((gStatusCode
!= NULL
) && (gStatusCode
->ReportStatusCode
!= NULL
) ) {
64 gStatusCode
->ReportStatusCode (
68 &gEfiDxeServicesTableGuid
,
69 (EFI_STATUS_CODE_DATA
*) &mStatusCodeData
75 CoreReportProgressCode (
76 IN EFI_STATUS_CODE_VALUE Value
82 Report status code of type EFI_PROGRESS_CODE by caller ID gEfiDxeServicesTableGuid.
86 Value - Describes the class/subclass/operation of the hardware or software entity
87 that the Status Code relates to.
95 if ((gStatusCode
!= NULL
) && (gStatusCode
->ReportStatusCode
!= NULL
) ) {
96 gStatusCode
->ReportStatusCode (
100 &gEfiDxeServicesTableGuid
,
108 CoreAllocateBootServicesPool (
109 IN UINTN AllocationSize
115 Allocate pool of type EfiBootServicesData, the size is specified with AllocationSize.
119 AllocationSize - Size to allocate.
123 Pointer of the allocated pool.
129 CoreAllocatePool (EfiBootServicesData
, AllocationSize
, &Memory
);
135 CoreAllocateZeroBootServicesPool (
136 IN UINTN AllocationSize
142 Allocate pool of type EfiBootServicesData and zero it, the size is specified with AllocationSize.
146 AllocationSize - Size to allocate.
150 Pointer of the allocated pool.
156 Memory
= CoreAllocateBootServicesPool (AllocationSize
);
157 SetMem (Memory
, (Memory
== NULL
) ? 0 : AllocationSize
, 0);
163 CoreAllocateCopyPool (
164 IN UINTN AllocationSize
,
171 Allocate pool of specified size with EfiBootServicesData type, and copy specified buffer to this pool.
175 AllocationSize - Size to allocate.
177 Buffer - Specified buffer that will be copy to the allocated pool
181 Pointer of the allocated pool.
187 Memory
= CoreAllocateBootServicesPool (AllocationSize
);
188 CopyMem (Memory
, Buffer
, (Memory
== NULL
) ? 0 : AllocationSize
);
196 CoreAllocateRuntimePool (
197 IN UINTN AllocationSize
203 Allocate pool of type EfiRuntimeServicesData, the size is specified with AllocationSize.
207 AllocationSize - Size to allocate.
211 Pointer of the allocated pool.
217 CoreAllocatePool (EfiRuntimeServicesData
, AllocationSize
, &Memory
);
222 CoreAllocateRuntimeCopyPool (
223 IN UINTN AllocationSize
,
230 Allocate pool of specified size with EfiRuntimeServicesData type, and copy specified buffer to this pool.
234 AllocationSize - Size to allocate.
236 Buffer - Specified buffer that will be copy to the allocated pool
240 Pointer of the allocated pool.
247 Memory
= CoreAllocateRuntimePool (AllocationSize
);
248 CopyMem (Memory
, Buffer
, (Memory
== NULL
) ? 0 : AllocationSize
);
262 CoreAcquireLockOrFail (
269 Initialize a basic mutual exclusion lock. Each lock
270 provides mutual exclusion access at it's task priority
271 level. Since there is no-premption (at any TPL) or
272 multiprocessor support, acquiring the lock only consists
273 of raising to the locks TPL.
277 Lock - The EFI_LOCK structure to initialize
281 EFI_SUCCESS - Lock Owned.
282 EFI_ACCESS_DENIED - Reentrant Lock Acquisition, Lock not Owned.
286 ASSERT (Lock
!= NULL
);
287 ASSERT (Lock
->Lock
!= EfiLockUninitialized
);
289 if (Lock
->Lock
== EfiLockAcquired
) {
291 // Lock is already owned, so bail out
293 return EFI_ACCESS_DENIED
;
296 Lock
->OwnerTpl
= CoreRaiseTpl (Lock
->Tpl
);
298 Lock
->Lock
= EfiLockAcquired
;
311 Raising to the task priority level of the mutual exclusion
312 lock, and then acquires ownership of the lock.
316 Lock - The lock to acquire
324 ASSERT (Lock
!= NULL
);
325 ASSERT (Lock
->Lock
== EfiLockReleased
);
327 Lock
->OwnerTpl
= CoreRaiseTpl (Lock
->Tpl
);
328 Lock
->Lock
= EfiLockAcquired
;
340 Releases ownership of the mutual exclusion lock, and
341 restores the previous task priority level.
345 Lock - The lock to release
355 ASSERT (Lock
!= NULL
);
356 ASSERT (Lock
->Lock
== EfiLockAcquired
);
358 Tpl
= Lock
->OwnerTpl
;
360 Lock
->Lock
= EfiLockReleased
;
362 CoreRestoreTpl (Tpl
);
368 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
374 Calculate the size of a whole device path.
378 DevicePath - The pointer to the device path data.
382 Size of device path data structure..
386 EFI_DEVICE_PATH_PROTOCOL
*Start
;
388 if (DevicePath
== NULL
) {
393 // Search for the end of the device path structure
396 while (!EfiIsDevicePathEnd (DevicePath
)) {
397 DevicePath
= EfiNextDevicePathNode (DevicePath
);
401 // Compute the size and add back in the size of the end device path structure
403 return ((UINTN
)DevicePath
- (UINTN
)Start
) + sizeof(EFI_DEVICE_PATH_PROTOCOL
);
408 CoreIsDevicePathMultiInstance (
409 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
414 Return TRUE is this is a multi instance device path.
417 DevicePath - A pointer to a device path data structure.
421 TRUE - If DevicePath is multi instance. FALSE - If DevicePath is not multi
426 EFI_DEVICE_PATH_PROTOCOL
*Node
;
428 if (DevicePath
== NULL
) {
433 while (!EfiIsDevicePathEnd (Node
)) {
434 if (EfiIsDevicePathEndInstance (Node
)) {
437 Node
= EfiNextDevicePathNode (Node
);
444 EFI_DEVICE_PATH_PROTOCOL
*
445 CoreDuplicateDevicePath (
446 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
451 Duplicate a new device path data structure from the old one.
454 DevicePath - A pointer to a device path data structure.
457 A pointer to the new allocated device path data.
458 Caller must free the memory used by DevicePath if it is no longer needed.
462 EFI_DEVICE_PATH_PROTOCOL
*NewDevicePath
;
465 if (DevicePath
== NULL
) {
472 Size
= CoreDevicePathSize (DevicePath
);
475 // Allocate space for duplicate device path
477 NewDevicePath
= CoreAllocateCopyPool (Size
, DevicePath
);
479 return NewDevicePath
;
484 EFI_DEVICE_PATH_PROTOCOL
*
485 CoreAppendDevicePath (
486 IN EFI_DEVICE_PATH_PROTOCOL
*Src1
,
487 IN EFI_DEVICE_PATH_PROTOCOL
*Src2
492 Function is used to append a Src1 and Src2 together.
495 Src1 - A pointer to a device path data structure.
497 Src2 - A pointer to a device path data structure.
501 A pointer to the new device path is returned.
502 NULL is returned if space for the new device path could not be allocated from pool.
503 It is up to the caller to free the memory used by Src1 and Src2 if they are no longer needed.
510 EFI_DEVICE_PATH_PROTOCOL
*NewDevicePath
;
511 EFI_DEVICE_PATH_PROTOCOL
*SecondDevicePath
;
513 if (Src1
== NULL
&& Src2
== NULL
) {
518 // Allocate space for the combined device path. It only has one end node of
519 // length EFI_DEVICE_PATH_PROTOCOL
521 Size1
= CoreDevicePathSize (Src1
);
522 Size2
= CoreDevicePathSize (Src2
);
523 Size
= Size1
+ Size2
- sizeof(EFI_DEVICE_PATH_PROTOCOL
);
525 NewDevicePath
= CoreAllocateCopyPool (Size
, Src1
);
526 if (NewDevicePath
!= NULL
) {
529 // Over write Src1 EndNode and do the copy
531 SecondDevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*)((CHAR8
*)NewDevicePath
+ (Size1
- sizeof(EFI_DEVICE_PATH_PROTOCOL
)));
532 CopyMem (SecondDevicePath
, Src2
, Size2
);
535 return NewDevicePath
;
541 CoreCreateProtocolNotifyEvent (
542 IN EFI_GUID
*ProtocolGuid
,
543 IN EFI_TPL NotifyTpl
,
544 IN EFI_EVENT_NOTIFY NotifyFunction
,
545 IN VOID
*NotifyContext
,
546 OUT VOID
**Registration
,
547 IN BOOLEAN SignalFlag
553 Create a protocol notification event and return it.
557 ProtocolGuid - Protocol to register notification event on.
559 NotifyTpl - Maximum TPL to signal the NotifyFunction.
561 NotifyFuncition - EFI notification routine.
563 NotifyContext - Context passed into Event when it is created.
565 Registration - Registration key returned from RegisterProtocolNotify().
567 SignalFlag - Boolean value to decide whether kick the event after register or not.
571 The EFI_EVENT that has been registered to be signaled when a ProtocolGuid
572 is added to the system.
583 Status
= CoreCreateEvent (
584 EFI_EVENT_NOTIFY_SIGNAL
,
590 ASSERT_EFI_ERROR (Status
);
593 // Register for protocol notifactions on this event
596 Status
= CoreRegisterProtocolNotify (
601 ASSERT_EFI_ERROR (Status
);
605 // Kick the event so we will perform an initial pass of
606 // current installed drivers
608 CoreSignalEvent (Event
);