-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