+++ /dev/null
-/*++\r
-\r
-Copyright (c) 2006, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution. The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-Module Name:\r
-\r
- Library.c\r
-\r
-Abstract:\r
-\r
- DXE Core library services.\r
-\r
---*/\r
-\r
-#include <DxeMain.h>\r
-\r
-UINTN mErrorLevel = EFI_D_ERROR | EFI_D_LOAD;\r
-\r
-EFI_DEVICE_HANDLE_EXTENDED_DATA mStatusCodeData = {\r
- {\r
- sizeof (EFI_STATUS_CODE_DATA),\r
- 0,\r
- EFI_STATUS_CODE_SPECIFIC_DATA_GUID\r
- },\r
- NULL\r
-};\r
-\r
-VOID\r
-CoreReportProgressCodeSpecific (\r
- IN EFI_STATUS_CODE_VALUE Value,\r
- IN EFI_HANDLE Handle\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Report status code of type EFI_PROGRESS_CODE by caller ID gEfiDxeServicesTableGuid,\r
- with a handle as additional information.\r
-\r
-Arguments:\r
-\r
- Value - Describes the class/subclass/operation of the hardware or software entity\r
- that the Status Code relates to.\r
-\r
- Handle - Additional information.\r
-\r
-Returns:\r
-\r
- None\r
-\r
---*/\r
-{\r
- mStatusCodeData.DataHeader.Size = sizeof (EFI_DEVICE_HANDLE_EXTENDED_DATA) - sizeof (EFI_STATUS_CODE_DATA);\r
- mStatusCodeData.Handle = Handle;\r
-\r
- if ((gStatusCode != NULL) && (gStatusCode->ReportStatusCode != NULL) ) {\r
- gStatusCode->ReportStatusCode (\r
- EFI_PROGRESS_CODE,\r
- Value,\r
- 0,\r
- &gEfiDxeServicesTableGuid,\r
- (EFI_STATUS_CODE_DATA *) &mStatusCodeData\r
- );\r
- }\r
-}\r
-\r
-VOID\r
-CoreReportProgressCode (\r
- IN EFI_STATUS_CODE_VALUE Value\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Report status code of type EFI_PROGRESS_CODE by caller ID gEfiDxeServicesTableGuid.\r
-\r
-Arguments:\r
-\r
- Value - Describes the class/subclass/operation of the hardware or software entity\r
- that the Status Code relates to.\r
-\r
-Returns:\r
-\r
- None\r
-\r
---*/\r
-{\r
- if ((gStatusCode != NULL) && (gStatusCode->ReportStatusCode != NULL) ) {\r
- gStatusCode->ReportStatusCode (\r
- EFI_PROGRESS_CODE,\r
- Value,\r
- 0,\r
- &gEfiDxeServicesTableGuid,\r
- NULL\r
- );\r
- }\r
-}\r
-\r
-\r
-VOID *\r
-CoreAllocateBootServicesPool (\r
- IN UINTN AllocationSize\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Allocate pool of type EfiBootServicesData, the size is specified with AllocationSize.\r
-\r
-Arguments:\r
-\r
- AllocationSize - Size to allocate.\r
-\r
-Returns:\r
-\r
- Pointer of the allocated pool.\r
-\r
---*/\r
-{\r
- VOID *Memory;\r
-\r
- CoreAllocatePool (EfiBootServicesData, AllocationSize, &Memory);\r
- return Memory;\r
-}\r
-\r
-\r
-VOID *\r
-CoreAllocateZeroBootServicesPool (\r
- IN UINTN AllocationSize\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Allocate pool of type EfiBootServicesData and zero it, the size is specified with AllocationSize.\r
-\r
-Arguments:\r
-\r
- AllocationSize - Size to allocate.\r
-\r
-Returns:\r
-\r
- Pointer of the allocated pool.\r
-\r
---*/\r
-{\r
- VOID *Memory;\r
-\r
- Memory = CoreAllocateBootServicesPool (AllocationSize);\r
- SetMem (Memory, (Memory == NULL) ? 0 : AllocationSize, 0);\r
- return Memory;\r
-}\r
-\r
-\r
-VOID *\r
-CoreAllocateCopyPool (\r
- IN UINTN AllocationSize,\r
- IN VOID *Buffer\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Allocate pool of specified size with EfiBootServicesData type, and copy specified buffer to this pool.\r
-\r
-Arguments:\r
-\r
- AllocationSize - Size to allocate.\r
-\r
- Buffer - Specified buffer that will be copy to the allocated pool\r
-\r
-Returns:\r
-\r
- Pointer of the allocated pool.\r
-\r
---*/\r
-{\r
- VOID *Memory;\r
-\r
- Memory = CoreAllocateBootServicesPool (AllocationSize);\r
- CopyMem (Memory, Buffer, (Memory == NULL) ? 0 : AllocationSize);\r
-\r
- return Memory;\r
-}\r
-\r
-\r
-\r
-VOID *\r
-CoreAllocateRuntimePool (\r
- IN UINTN AllocationSize\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Allocate pool of type EfiRuntimeServicesData, the size is specified with AllocationSize.\r
-\r
-Arguments:\r
-\r
- AllocationSize - Size to allocate.\r
-\r
-Returns:\r
-\r
- Pointer of the allocated pool.\r
-\r
---*/\r
-{\r
- VOID *Memory;\r
-\r
- CoreAllocatePool (EfiRuntimeServicesData, AllocationSize, &Memory);\r
- return Memory;\r
-}\r
-\r
-VOID *\r
-CoreAllocateRuntimeCopyPool (\r
- IN UINTN AllocationSize,\r
- IN VOID *Buffer\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Allocate pool of specified size with EfiRuntimeServicesData type, and copy specified buffer to this pool.\r
-\r
-Arguments:\r
-\r
- AllocationSize - Size to allocate.\r
-\r
- Buffer - Specified buffer that will be copy to the allocated pool\r
-\r
-Returns:\r
-\r
- Pointer of the allocated pool.\r
-\r
---*/\r
-\r
-{\r
- VOID *Memory;\r
-\r
- Memory = CoreAllocateRuntimePool (AllocationSize);\r
- CopyMem (Memory, Buffer, (Memory == NULL) ? 0 : AllocationSize);\r
-\r
- return Memory;\r
-}\r
-\r
-\r
-\r
-//\r
-// Lock Stuff\r
-//\r
-\r
-\r
-\r
-EFI_STATUS\r
-CoreAcquireLockOrFail (\r
- IN EFI_LOCK *Lock\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Initialize a basic mutual exclusion lock. Each lock\r
- provides mutual exclusion access at it's task priority\r
- level. Since there is no-premption (at any TPL) or\r
- multiprocessor support, acquiring the lock only consists\r
- of raising to the locks TPL.\r
-\r
-Arguments:\r
-\r
- Lock - The EFI_LOCK structure to initialize\r
-\r
-Returns:\r
-\r
- EFI_SUCCESS - Lock Owned.\r
- EFI_ACCESS_DENIED - Reentrant Lock Acquisition, Lock not Owned.\r
-\r
---*/\r
-{\r
- ASSERT (Lock != NULL);\r
- ASSERT (Lock->Lock != EfiLockUninitialized);\r
-\r
- if (Lock->Lock == EfiLockAcquired) {\r
- //\r
- // Lock is already owned, so bail out\r
- //\r
- return EFI_ACCESS_DENIED;\r
- }\r
-\r
- Lock->OwnerTpl = CoreRaiseTpl (Lock->Tpl);\r
-\r
- Lock->Lock = EfiLockAcquired;\r
- return EFI_SUCCESS;\r
-}\r
-\r
-\r
-VOID\r
-CoreAcquireLock (\r
- IN EFI_LOCK *Lock\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Raising to the task priority level of the mutual exclusion\r
- lock, and then acquires ownership of the lock.\r
-\r
-Arguments:\r
-\r
- Lock - The lock to acquire\r
-\r
-Returns:\r
-\r
- Lock owned\r
-\r
---*/\r
-{\r
- ASSERT (Lock != NULL);\r
- ASSERT (Lock->Lock == EfiLockReleased);\r
-\r
- Lock->OwnerTpl = CoreRaiseTpl (Lock->Tpl);\r
- Lock->Lock = EfiLockAcquired;\r
-}\r
-\r
-\r
-VOID\r
-CoreReleaseLock (\r
- IN EFI_LOCK *Lock\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Releases ownership of the mutual exclusion lock, and\r
- restores the previous task priority level.\r
-\r
-Arguments:\r
-\r
- Lock - The lock to release\r
-\r
-Returns:\r
-\r
- Lock unowned\r
-\r
---*/\r
-{\r
- EFI_TPL Tpl;\r
-\r
- ASSERT (Lock != NULL);\r
- ASSERT (Lock->Lock == EfiLockAcquired);\r
-\r
- Tpl = Lock->OwnerTpl;\r
-\r
- Lock->Lock = EfiLockReleased;\r
-\r
- CoreRestoreTpl (Tpl);\r
-}\r
-\r
-\r
-UINTN\r
-CoreDevicePathSize (\r
- IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Calculate the size of a whole device path.\r
-\r
-Arguments:\r
-\r
- DevicePath - The pointer to the device path data.\r
-\r
-Returns:\r
-\r
- Size of device path data structure..\r
-\r
---*/\r
-{\r
- EFI_DEVICE_PATH_PROTOCOL *Start;\r
-\r
- if (DevicePath == NULL) {\r
- return 0;\r
- }\r
-\r
- //\r
- // Search for the end of the device path structure\r
- //\r
- Start = DevicePath;\r
- while (!EfiIsDevicePathEnd (DevicePath)) {\r
- DevicePath = EfiNextDevicePathNode (DevicePath);\r
- }\r
-\r
- //\r
- // Compute the size and add back in the size of the end device path structure\r
- //\r
- return ((UINTN)DevicePath - (UINTN)Start) + sizeof(EFI_DEVICE_PATH_PROTOCOL);\r
-}\r
-\r
-\r
-BOOLEAN\r
-CoreIsDevicePathMultiInstance (\r
- IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- Return TRUE is this is a multi instance device path.\r
-\r
-Arguments:\r
- DevicePath - A pointer to a device path data structure.\r
-\r
-\r
-Returns:\r
- TRUE - If DevicePath is multi instance. FALSE - If DevicePath is not multi\r
- instance.\r
-\r
---*/\r
-{\r
- EFI_DEVICE_PATH_PROTOCOL *Node;\r
-\r
- if (DevicePath == NULL) {\r
- return FALSE;\r
- }\r
-\r
- Node = DevicePath;\r
- while (!EfiIsDevicePathEnd (Node)) {\r
- if (EfiIsDevicePathEndInstance (Node)) {\r
- return TRUE;\r
- }\r
- Node = EfiNextDevicePathNode (Node);\r
- }\r
- return FALSE;\r
-}\r
-\r
-\r
-\r
-EFI_DEVICE_PATH_PROTOCOL *\r
-CoreDuplicateDevicePath (\r
- IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- Duplicate a new device path data structure from the old one.\r
-\r
-Arguments:\r
- DevicePath - A pointer to a device path data structure.\r
-\r
-Returns:\r
- A pointer to the new allocated device path data.\r
- Caller must free the memory used by DevicePath if it is no longer needed.\r
-\r
---*/\r
-{\r
- EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;\r
- UINTN Size;\r
-\r
- if (DevicePath == NULL) {\r
- return NULL;\r
- }\r
-\r
- //\r
- // Compute the size\r
- //\r
- Size = CoreDevicePathSize (DevicePath);\r
-\r
- //\r
- // Allocate space for duplicate device path\r
- //\r
- NewDevicePath = CoreAllocateCopyPool (Size, DevicePath);\r
-\r
- return NewDevicePath;\r
-}\r
-\r
-\r
-\r
-EFI_DEVICE_PATH_PROTOCOL *\r
-CoreAppendDevicePath (\r
- IN EFI_DEVICE_PATH_PROTOCOL *Src1,\r
- IN EFI_DEVICE_PATH_PROTOCOL *Src2\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- Function is used to append a Src1 and Src2 together.\r
-\r
-Arguments:\r
- Src1 - A pointer to a device path data structure.\r
-\r
- Src2 - A pointer to a device path data structure.\r
-\r
-Returns:\r
-\r
- A pointer to the new device path is returned.\r
- NULL is returned if space for the new device path could not be allocated from pool.\r
- It is up to the caller to free the memory used by Src1 and Src2 if they are no longer needed.\r
-\r
---*/\r
-{\r
- UINTN Size;\r
- UINTN Size1;\r
- UINTN Size2;\r
- EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;\r
- EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath;\r
-\r
- if (Src1 == NULL && Src2 == NULL) {\r
- return NULL;\r
- }\r
-\r
- //\r
- // Allocate space for the combined device path. It only has one end node of\r
- // length EFI_DEVICE_PATH_PROTOCOL\r
- //\r
- Size1 = CoreDevicePathSize (Src1);\r
- Size2 = CoreDevicePathSize (Src2);\r
- Size = Size1 + Size2 - sizeof(EFI_DEVICE_PATH_PROTOCOL);\r
-\r
- NewDevicePath = CoreAllocateCopyPool (Size, Src1);\r
- if (NewDevicePath != NULL) {\r
-\r
- //\r
- // Over write Src1 EndNode and do the copy\r
- //\r
- SecondDevicePath = (EFI_DEVICE_PATH_PROTOCOL *)((CHAR8 *)NewDevicePath + (Size1 - sizeof(EFI_DEVICE_PATH_PROTOCOL)));\r
- CopyMem (SecondDevicePath, Src2, Size2);\r
- }\r
-\r
- return NewDevicePath;\r
-}\r
-\r
-\r
-\r
-EFI_EVENT\r
-CoreCreateProtocolNotifyEvent (\r
- IN EFI_GUID *ProtocolGuid,\r
- IN EFI_TPL NotifyTpl,\r
- IN EFI_EVENT_NOTIFY NotifyFunction,\r
- IN VOID *NotifyContext,\r
- OUT VOID **Registration,\r
- IN BOOLEAN SignalFlag\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Create a protocol notification event and return it.\r
-\r
-Arguments:\r
-\r
- ProtocolGuid - Protocol to register notification event on.\r
-\r
- NotifyTpl - Maximum TPL to signal the NotifyFunction.\r
-\r
- NotifyFuncition - EFI notification routine.\r
-\r
- NotifyContext - Context passed into Event when it is created.\r
-\r
- Registration - Registration key returned from RegisterProtocolNotify().\r
-\r
- SignalFlag - Boolean value to decide whether kick the event after register or not.\r
-\r
-Returns:\r
-\r
- The EFI_EVENT that has been registered to be signaled when a ProtocolGuid\r
- is added to the system.\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
- EFI_EVENT Event;\r
-\r
- //\r
- // Create the event\r
- //\r
-\r
- Status = CoreCreateEvent (\r
- EVT_NOTIFY_SIGNAL,\r
- NotifyTpl,\r
- NotifyFunction,\r
- NotifyContext,\r
- &Event\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- //\r
- // Register for protocol notifactions on this event\r
- //\r
-\r
- Status = CoreRegisterProtocolNotify (\r
- ProtocolGuid,\r
- Event,\r
- Registration\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- if (SignalFlag) {\r
- //\r
- // Kick the event so we will perform an initial pass of\r
- // current installed drivers\r
- //\r
- CoreSignalEvent (Event);\r
- }\r
-\r
- return Event;\r
-}\r
-\r