* [edk2-devel] [PATCH 1/1] MdeModulePkg: Optimize CoreInstallMultipleProtocolInterfaces @ 2023-11-09 1:46 Zhi Jin 2023-11-09 2:36 ` Ni, Ray 0 siblings, 1 reply; 4+ messages in thread From: Zhi Jin @ 2023-11-09 1:46 UTC (permalink / raw) To: devel; +Cc: Zhi Jin, Jian J Wang, Liming Gao, Dandan Bi, Ray Ni CoreLocateDevicePath is used in CoreInstallMultipleProtocolInterfaces to check if a Device Path Protocol instance with the same device path is alreay installed. CoreLocateDevicePath is a generic API, and would introduce some unnecessary overhead for such usage. The optimization is: 1. Implement IsDevicePathInstalled to loop all the Device Path Protocols installed and check if any of them matchs the given device path. 2. Replace CoreLocateDevicePath with IsDevicePathInstalled in CoreInstallMultipleProtocolInterfaces. This optimization could save several seconds in PCI enumeration on a system with many PCI devices. Cc: Jian J Wang <jian.j.wang@intel.com> Cc: Liming Gao <gaoliming@byosoft.com.cn> Cc: Dandan Bi <dandan.bi@intel.com> Cc: Ray Ni <ray.ni@intel.com> Signed-off-by: Zhi Jin <zhi.jin@intel.com> --- MdeModulePkg/Core/Dxe/Hand/Handle.c | 74 +++++++++++++++++++++++++---- 1 file changed, 64 insertions(+), 10 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Hand/Handle.c b/MdeModulePkg/Core/Dxe/Hand/Handle.c index bd6c57843e..a08cf19bfd 100644 --- a/MdeModulePkg/Core/Dxe/Hand/Handle.c +++ b/MdeModulePkg/Core/Dxe/Hand/Handle.c @@ -197,6 +197,66 @@ CoreFindProtocolInterface ( return Prot; } +/** + Check if the given device path is already installed + + @param DevicePath The given device path + + @retval TRUE The device path is already installed + @retval FALSE The device path is not installed + +**/ +BOOLEAN +IsDevicePathInstalled ( + IN EFI_DEVICE_PATH_PROTOCOL *DevicePath + ) +{ + UINTN SourceSize; + UINTN Size; + BOOLEAN Found; + LIST_ENTRY *Link; + PROTOCOL_ENTRY *ProtEntry; + PROTOCOL_INTERFACE *Prot; + + if (DevicePath == NULL) { + return FALSE; + } + + Found = FALSE; + SourceSize = GetDevicePathSize (DevicePath); + ASSERT (SourceSize >= END_DEVICE_PATH_LENGTH); + + CoreAcquireProtocolLock (); + // + // Look up the protocol entry + // + ProtEntry = CoreFindProtocolEntry (&gEfiDevicePathProtocolGuid, FALSE); + if (ProtEntry == NULL) { + goto Done; + } + + for (Link = ProtEntry->Protocols.ForwardLink; Link != &ProtEntry->Protocols; Link = Link->ForwardLink) { + // + // Loop on the DevicePathProtocol interfaces + // + Prot = CR (Link, PROTOCOL_INTERFACE, ByProtocol, PROTOCOL_INTERFACE_SIGNATURE); + + // + // Check if DevicePath is same as this interface + // + Size = GetDevicePathSize (Prot->Interface); + ASSERT (Size >= END_DEVICE_PATH_LENGTH); + if ((Size == SourceSize) && (CompareMem (DevicePath, Prot->Interface, Size - END_DEVICE_PATH_LENGTH) == 0)) { + Found = TRUE; + break; + } + } + +Done: + CoreReleaseProtocolLock (); + return Found; +} + /** Removes an event from a register protocol notify list on a protocol. @@ -517,8 +577,6 @@ CoreInstallMultipleProtocolInterfaces ( EFI_TPL OldTpl; UINTN Index; EFI_HANDLE OldHandle; - EFI_HANDLE DeviceHandle; - EFI_DEVICE_PATH_PROTOCOL *DevicePath; if (Handle == NULL) { return EFI_INVALID_PARAMETER; @@ -548,14 +606,10 @@ CoreInstallMultipleProtocolInterfaces ( // // Make sure you are installing on top a device path that has already been added. // - if (CompareGuid (Protocol, &gEfiDevicePathProtocolGuid)) { - DeviceHandle = NULL; - DevicePath = Interface; - Status = CoreLocateDevicePath (&gEfiDevicePathProtocolGuid, &DevicePath, &DeviceHandle); - if (!EFI_ERROR (Status) && (DeviceHandle != NULL) && IsDevicePathEnd (DevicePath)) { - Status = EFI_ALREADY_STARTED; - continue; - } + if (CompareGuid (Protocol, &gEfiDevicePathProtocolGuid) && + IsDevicePathInstalled (Interface)) { + Status = EFI_ALREADY_STARTED; + continue; } // -- 2.39.2 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#110945): https://edk2.groups.io/g/devel/message/110945 Mute This Topic: https://groups.io/mt/102478834/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=- ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [edk2-devel] [PATCH 1/1] MdeModulePkg: Optimize CoreInstallMultipleProtocolInterfaces 2023-11-09 1:46 [edk2-devel] [PATCH 1/1] MdeModulePkg: Optimize CoreInstallMultipleProtocolInterfaces Zhi Jin @ 2023-11-09 2:36 ` Ni, Ray 2023-11-27 6:53 ` Zhi Jin 0 siblings, 1 reply; 4+ messages in thread From: Ni, Ray @ 2023-11-09 2:36 UTC (permalink / raw) To: Jin, Zhi, devel@edk2.groups.io; +Cc: Wang, Jian J, Gao, Liming, Bi, Dandan [-- Attachment #1: Type: text/plain, Size: 4981 bytes --] Reviewed-by: Ray Ni <ray.ni@intel.com> Thanks, Ray ________________________________ From: Jin, Zhi <zhi.jin@intel.com> Sent: Thursday, November 9, 2023 9:46 AM To: devel@edk2.groups.io <devel@edk2.groups.io> Cc: Jin, Zhi <zhi.jin@intel.com>; Wang, Jian J <jian.j.wang@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>; Bi, Dandan <dandan.bi@intel.com>; Ni, Ray <ray.ni@intel.com> Subject: [PATCH 1/1] MdeModulePkg: Optimize CoreInstallMultipleProtocolInterfaces CoreLocateDevicePath is used in CoreInstallMultipleProtocolInterfaces to check if a Device Path Protocol instance with the same device path is alreay installed. CoreLocateDevicePath is a generic API, and would introduce some unnecessary overhead for such usage. The optimization is: 1. Implement IsDevicePathInstalled to loop all the Device Path Protocols installed and check if any of them matchs the given device path. 2. Replace CoreLocateDevicePath with IsDevicePathInstalled in CoreInstallMultipleProtocolInterfaces. This optimization could save several seconds in PCI enumeration on a system with many PCI devices. Cc: Jian J Wang <jian.j.wang@intel.com> Cc: Liming Gao <gaoliming@byosoft.com.cn> Cc: Dandan Bi <dandan.bi@intel.com> Cc: Ray Ni <ray.ni@intel.com> Signed-off-by: Zhi Jin <zhi.jin@intel.com> --- MdeModulePkg/Core/Dxe/Hand/Handle.c | 74 +++++++++++++++++++++++++---- 1 file changed, 64 insertions(+), 10 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Hand/Handle.c b/MdeModulePkg/Core/Dxe/Hand/Handle.c index bd6c57843e..a08cf19bfd 100644 --- a/MdeModulePkg/Core/Dxe/Hand/Handle.c +++ b/MdeModulePkg/Core/Dxe/Hand/Handle.c @@ -197,6 +197,66 @@ CoreFindProtocolInterface ( return Prot; } +/** + Check if the given device path is already installed + + @param DevicePath The given device path + + @retval TRUE The device path is already installed + @retval FALSE The device path is not installed + +**/ +BOOLEAN +IsDevicePathInstalled ( + IN EFI_DEVICE_PATH_PROTOCOL *DevicePath + ) +{ + UINTN SourceSize; + UINTN Size; + BOOLEAN Found; + LIST_ENTRY *Link; + PROTOCOL_ENTRY *ProtEntry; + PROTOCOL_INTERFACE *Prot; + + if (DevicePath == NULL) { + return FALSE; + } + + Found = FALSE; + SourceSize = GetDevicePathSize (DevicePath); + ASSERT (SourceSize >= END_DEVICE_PATH_LENGTH); + + CoreAcquireProtocolLock (); + // + // Look up the protocol entry + // + ProtEntry = CoreFindProtocolEntry (&gEfiDevicePathProtocolGuid, FALSE); + if (ProtEntry == NULL) { + goto Done; + } + + for (Link = ProtEntry->Protocols.ForwardLink; Link != &ProtEntry->Protocols; Link = Link->ForwardLink) { + // + // Loop on the DevicePathProtocol interfaces + // + Prot = CR (Link, PROTOCOL_INTERFACE, ByProtocol, PROTOCOL_INTERFACE_SIGNATURE); + + // + // Check if DevicePath is same as this interface + // + Size = GetDevicePathSize (Prot->Interface); + ASSERT (Size >= END_DEVICE_PATH_LENGTH); + if ((Size == SourceSize) && (CompareMem (DevicePath, Prot->Interface, Size - END_DEVICE_PATH_LENGTH) == 0)) { + Found = TRUE; + break; + } + } + +Done: + CoreReleaseProtocolLock (); + return Found; +} + /** Removes an event from a register protocol notify list on a protocol. @@ -517,8 +577,6 @@ CoreInstallMultipleProtocolInterfaces ( EFI_TPL OldTpl; UINTN Index; EFI_HANDLE OldHandle; - EFI_HANDLE DeviceHandle; - EFI_DEVICE_PATH_PROTOCOL *DevicePath; if (Handle == NULL) { return EFI_INVALID_PARAMETER; @@ -548,14 +606,10 @@ CoreInstallMultipleProtocolInterfaces ( // // Make sure you are installing on top a device path that has already been added. // - if (CompareGuid (Protocol, &gEfiDevicePathProtocolGuid)) { - DeviceHandle = NULL; - DevicePath = Interface; - Status = CoreLocateDevicePath (&gEfiDevicePathProtocolGuid, &DevicePath, &DeviceHandle); - if (!EFI_ERROR (Status) && (DeviceHandle != NULL) && IsDevicePathEnd (DevicePath)) { - Status = EFI_ALREADY_STARTED; - continue; - } + if (CompareGuid (Protocol, &gEfiDevicePathProtocolGuid) && + IsDevicePathInstalled (Interface)) { + Status = EFI_ALREADY_STARTED; + continue; } // -- 2.39.2 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#110937): https://edk2.groups.io/g/devel/message/110937 Mute This Topic: https://groups.io/mt/102478834/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/12367111/7686176/1913456212/xyzzy [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=- [-- Attachment #2: Type: text/html, Size: 9459 bytes --] ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [edk2-devel] [PATCH 1/1] MdeModulePkg: Optimize CoreInstallMultipleProtocolInterfaces 2023-11-09 2:36 ` Ni, Ray @ 2023-11-27 6:53 ` Zhi Jin 2023-11-28 15:16 ` 回复: " gaoliming via groups.io 0 siblings, 1 reply; 4+ messages in thread From: Zhi Jin @ 2023-11-27 6:53 UTC (permalink / raw) To: Ni, Ray, devel@edk2.groups.io, Gao, Liming; +Cc: Wang, Jian J, Bi, Dandan [-- Attachment #1: Type: text/plain, Size: 5814 bytes --] Hi @Liming Gao<mailto:gaoliming@byosoft.com.cn>, Would you please help to review this patch? Thanks! BRs Zhi Jin From: Ni, Ray <ray.ni@intel.com> Sent: Thursday, November 09, 2023 10:36 AM To: Jin, Zhi <zhi.jin@intel.com>; devel@edk2.groups.io Cc: Wang, Jian J <jian.j.wang@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>; Bi, Dandan <dandan.bi@intel.com> Subject: Re: [PATCH 1/1] MdeModulePkg: Optimize CoreInstallMultipleProtocolInterfaces Reviewed-by: Ray Ni <ray.ni@intel.com<mailto:ray.ni@intel.com>> Thanks, Ray ________________________________ From: Jin, Zhi <zhi.jin@intel.com<mailto:zhi.jin@intel.com>> Sent: Thursday, November 9, 2023 9:46 AM To: devel@edk2.groups.io<mailto:devel@edk2.groups.io> <devel@edk2.groups.io<mailto:devel@edk2.groups.io>> Cc: Jin, Zhi <zhi.jin@intel.com<mailto:zhi.jin@intel.com>>; Wang, Jian J <jian.j.wang@intel.com<mailto:jian.j.wang@intel.com>>; Gao, Liming <gaoliming@byosoft.com.cn<mailto:gaoliming@byosoft.com.cn>>; Bi, Dandan <dandan.bi@intel.com<mailto:dandan.bi@intel.com>>; Ni, Ray <ray.ni@intel.com<mailto:ray.ni@intel.com>> Subject: [PATCH 1/1] MdeModulePkg: Optimize CoreInstallMultipleProtocolInterfaces CoreLocateDevicePath is used in CoreInstallMultipleProtocolInterfaces to check if a Device Path Protocol instance with the same device path is alreay installed. CoreLocateDevicePath is a generic API, and would introduce some unnecessary overhead for such usage. The optimization is: 1. Implement IsDevicePathInstalled to loop all the Device Path Protocols installed and check if any of them matchs the given device path. 2. Replace CoreLocateDevicePath with IsDevicePathInstalled in CoreInstallMultipleProtocolInterfaces. This optimization could save several seconds in PCI enumeration on a system with many PCI devices. Cc: Jian J Wang <jian.j.wang@intel.com<mailto:jian.j.wang@intel.com>> Cc: Liming Gao <gaoliming@byosoft.com.cn<mailto:gaoliming@byosoft.com.cn>> Cc: Dandan Bi <dandan.bi@intel.com<mailto:dandan.bi@intel.com>> Cc: Ray Ni <ray.ni@intel.com<mailto:ray.ni@intel.com>> Signed-off-by: Zhi Jin <zhi.jin@intel.com<mailto:zhi.jin@intel.com>> --- MdeModulePkg/Core/Dxe/Hand/Handle.c | 74 +++++++++++++++++++++++++---- 1 file changed, 64 insertions(+), 10 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Hand/Handle.c b/MdeModulePkg/Core/Dxe/Hand/Handle.c index bd6c57843e..a08cf19bfd 100644 --- a/MdeModulePkg/Core/Dxe/Hand/Handle.c +++ b/MdeModulePkg/Core/Dxe/Hand/Handle.c @@ -197,6 +197,66 @@ CoreFindProtocolInterface ( return Prot; } +/** + Check if the given device path is already installed + + @param DevicePath The given device path + + @retval TRUE The device path is already installed + @retval FALSE The device path is not installed + +**/ +BOOLEAN +IsDevicePathInstalled ( + IN EFI_DEVICE_PATH_PROTOCOL *DevicePath + ) +{ + UINTN SourceSize; + UINTN Size; + BOOLEAN Found; + LIST_ENTRY *Link; + PROTOCOL_ENTRY *ProtEntry; + PROTOCOL_INTERFACE *Prot; + + if (DevicePath == NULL) { + return FALSE; + } + + Found = FALSE; + SourceSize = GetDevicePathSize (DevicePath); + ASSERT (SourceSize >= END_DEVICE_PATH_LENGTH); + + CoreAcquireProtocolLock (); + // + // Look up the protocol entry + // + ProtEntry = CoreFindProtocolEntry (&gEfiDevicePathProtocolGuid, FALSE); + if (ProtEntry == NULL) { + goto Done; + } + + for (Link = ProtEntry->Protocols.ForwardLink; Link != &ProtEntry->Protocols; Link = Link->ForwardLink) { + // + // Loop on the DevicePathProtocol interfaces + // + Prot = CR (Link, PROTOCOL_INTERFACE, ByProtocol, PROTOCOL_INTERFACE_SIGNATURE); + + // + // Check if DevicePath is same as this interface + // + Size = GetDevicePathSize (Prot->Interface); + ASSERT (Size >= END_DEVICE_PATH_LENGTH); + if ((Size == SourceSize) && (CompareMem (DevicePath, Prot->Interface, Size - END_DEVICE_PATH_LENGTH) == 0)) { + Found = TRUE; + break; + } + } + +Done: + CoreReleaseProtocolLock (); + return Found; +} + /** Removes an event from a register protocol notify list on a protocol. @@ -517,8 +577,6 @@ CoreInstallMultipleProtocolInterfaces ( EFI_TPL OldTpl; UINTN Index; EFI_HANDLE OldHandle; - EFI_HANDLE DeviceHandle; - EFI_DEVICE_PATH_PROTOCOL *DevicePath; if (Handle == NULL) { return EFI_INVALID_PARAMETER; @@ -548,14 +606,10 @@ CoreInstallMultipleProtocolInterfaces ( // // Make sure you are installing on top a device path that has already been added. // - if (CompareGuid (Protocol, &gEfiDevicePathProtocolGuid)) { - DeviceHandle = NULL; - DevicePath = Interface; - Status = CoreLocateDevicePath (&gEfiDevicePathProtocolGuid, &DevicePath, &DeviceHandle); - if (!EFI_ERROR (Status) && (DeviceHandle != NULL) && IsDevicePathEnd (DevicePath)) { - Status = EFI_ALREADY_STARTED; - continue; - } + if (CompareGuid (Protocol, &gEfiDevicePathProtocolGuid) && + IsDevicePathInstalled (Interface)) { + Status = EFI_ALREADY_STARTED; + continue; } // -- 2.39.2 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#111726): https://edk2.groups.io/g/devel/message/111726 Mute This Topic: https://groups.io/mt/102478834/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=- [-- Attachment #2: Type: text/html, Size: 12818 bytes --] ^ permalink raw reply related [flat|nested] 4+ messages in thread
* 回复: [edk2-devel] [PATCH 1/1] MdeModulePkg: Optimize CoreInstallMultipleProtocolInterfaces 2023-11-27 6:53 ` Zhi Jin @ 2023-11-28 15:16 ` gaoliming via groups.io 0 siblings, 0 replies; 4+ messages in thread From: gaoliming via groups.io @ 2023-11-28 15:16 UTC (permalink / raw) To: devel, zhi.jin, 'Ni, Ray' Cc: 'Wang, Jian J', 'Bi, Dandan' [-- Attachment #1: Type: text/plain, Size: 6567 bytes --] Jin: This change is good to me. Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn> Thanks Liming 发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表 Zhi Jin 发送时间: 2023年11月27日 14:54 收件人: Ni, Ray <ray.ni@intel.com>; devel@edk2.groups.io; Gao, Liming <gaoliming@byosoft.com.cn> 抄送: Wang, Jian J <jian.j.wang@intel.com>; Bi, Dandan <dandan.bi@intel.com> 主题: Re: [edk2-devel] [PATCH 1/1] MdeModulePkg: Optimize CoreInstallMultipleProtocolInterfaces Hi <mailto:gaoliming@byosoft.com.cn> @Liming Gao, Would you please help to review this patch? Thanks! BRs Zhi Jin From: Ni, Ray <ray.ni@intel.com <mailto:ray.ni@intel.com> > Sent: Thursday, November 09, 2023 10:36 AM To: Jin, Zhi <zhi.jin@intel.com <mailto:zhi.jin@intel.com> >; devel@edk2.groups.io <mailto:devel@edk2.groups.io> Cc: Wang, Jian J <jian.j.wang@intel.com <mailto:jian.j.wang@intel.com> >; Gao, Liming <gaoliming@byosoft.com.cn <mailto:gaoliming@byosoft.com.cn> >; Bi, Dandan <dandan.bi@intel.com <mailto:dandan.bi@intel.com> > Subject: Re: [PATCH 1/1] MdeModulePkg: Optimize CoreInstallMultipleProtocolInterfaces Reviewed-by: Ray Ni <ray.ni@intel.com <mailto:ray.ni@intel.com> > Thanks, Ray _____ From: Jin, Zhi <zhi.jin@intel.com <mailto:zhi.jin@intel.com> > Sent: Thursday, November 9, 2023 9:46 AM To: devel@edk2.groups.io <mailto:devel@edk2.groups.io> <devel@edk2.groups.io <mailto:devel@edk2.groups.io> > Cc: Jin, Zhi <zhi.jin@intel.com <mailto:zhi.jin@intel.com> >; Wang, Jian J <jian.j.wang@intel.com <mailto:jian.j.wang@intel.com> >; Gao, Liming <gaoliming@byosoft.com.cn <mailto:gaoliming@byosoft.com.cn> >; Bi, Dandan <dandan.bi@intel.com <mailto:dandan.bi@intel.com> >; Ni, Ray <ray.ni@intel.com <mailto:ray.ni@intel.com> > Subject: [PATCH 1/1] MdeModulePkg: Optimize CoreInstallMultipleProtocolInterfaces CoreLocateDevicePath is used in CoreInstallMultipleProtocolInterfaces to check if a Device Path Protocol instance with the same device path is alreay installed. CoreLocateDevicePath is a generic API, and would introduce some unnecessary overhead for such usage. The optimization is: 1. Implement IsDevicePathInstalled to loop all the Device Path Protocols installed and check if any of them matchs the given device path. 2. Replace CoreLocateDevicePath with IsDevicePathInstalled in CoreInstallMultipleProtocolInterfaces. This optimization could save several seconds in PCI enumeration on a system with many PCI devices. Cc: Jian J Wang <jian.j.wang@intel.com <mailto:jian.j.wang@intel.com> > Cc: Liming Gao <gaoliming@byosoft.com.cn <mailto:gaoliming@byosoft.com.cn> > Cc: Dandan Bi <dandan.bi@intel.com <mailto:dandan.bi@intel.com> > Cc: Ray Ni <ray.ni@intel.com <mailto:ray.ni@intel.com> > Signed-off-by: Zhi Jin <zhi.jin@intel.com <mailto:zhi.jin@intel.com> > --- MdeModulePkg/Core/Dxe/Hand/Handle.c | 74 +++++++++++++++++++++++++---- 1 file changed, 64 insertions(+), 10 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Hand/Handle.c b/MdeModulePkg/Core/Dxe/Hand/Handle.c index bd6c57843e..a08cf19bfd 100644 --- a/MdeModulePkg/Core/Dxe/Hand/Handle.c +++ b/MdeModulePkg/Core/Dxe/Hand/Handle.c @@ -197,6 +197,66 @@ CoreFindProtocolInterface ( return Prot; } +/** + Check if the given device path is already installed + + @param DevicePath The given device path + + @retval TRUE The device path is already installed + @retval FALSE The device path is not installed + +**/ +BOOLEAN +IsDevicePathInstalled ( + IN EFI_DEVICE_PATH_PROTOCOL *DevicePath + ) +{ + UINTN SourceSize; + UINTN Size; + BOOLEAN Found; + LIST_ENTRY *Link; + PROTOCOL_ENTRY *ProtEntry; + PROTOCOL_INTERFACE *Prot; + + if (DevicePath == NULL) { + return FALSE; + } + + Found = FALSE; + SourceSize = GetDevicePathSize (DevicePath); + ASSERT (SourceSize >= END_DEVICE_PATH_LENGTH); + + CoreAcquireProtocolLock (); + // + // Look up the protocol entry + // + ProtEntry = CoreFindProtocolEntry (&gEfiDevicePathProtocolGuid, FALSE); + if (ProtEntry == NULL) { + goto Done; + } + + for (Link = ProtEntry->Protocols.ForwardLink; Link != &ProtEntry->Protocols; Link = Link->ForwardLink) { + // + // Loop on the DevicePathProtocol interfaces + // + Prot = CR (Link, PROTOCOL_INTERFACE, ByProtocol, PROTOCOL_INTERFACE_SIGNATURE); + + // + // Check if DevicePath is same as this interface + // + Size = GetDevicePathSize (Prot->Interface); + ASSERT (Size >= END_DEVICE_PATH_LENGTH); + if ((Size == SourceSize) && (CompareMem (DevicePath, Prot->Interface, Size - END_DEVICE_PATH_LENGTH) == 0)) { + Found = TRUE; + break; + } + } + +Done: + CoreReleaseProtocolLock (); + return Found; +} + /** Removes an event from a register protocol notify list on a protocol. @@ -517,8 +577,6 @@ CoreInstallMultipleProtocolInterfaces ( EFI_TPL OldTpl; UINTN Index; EFI_HANDLE OldHandle; - EFI_HANDLE DeviceHandle; - EFI_DEVICE_PATH_PROTOCOL *DevicePath; if (Handle == NULL) { return EFI_INVALID_PARAMETER; @@ -548,14 +606,10 @@ CoreInstallMultipleProtocolInterfaces ( // // Make sure you are installing on top a device path that has already been added. // - if (CompareGuid (Protocol, &gEfiDevicePathProtocolGuid)) { - DeviceHandle = NULL; - DevicePath = Interface; - Status = CoreLocateDevicePath (&gEfiDevicePathProtocolGuid, &DevicePath, &DeviceHandle); - if (!EFI_ERROR (Status) && (DeviceHandle != NULL) && IsDevicePathEnd (DevicePath)) { - Status = EFI_ALREADY_STARTED; - continue; - } + if (CompareGuid (Protocol, &gEfiDevicePathProtocolGuid) && + IsDevicePathInstalled (Interface)) { + Status = EFI_ALREADY_STARTED; + continue; } // -- 2.39.2 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#111813): https://edk2.groups.io/g/devel/message/111813 Mute This Topic: https://groups.io/mt/102851994/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=- [-- Attachment #2: Type: text/html, Size: 14840 bytes --] ^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-11-28 15:16 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-11-09 1:46 [edk2-devel] [PATCH 1/1] MdeModulePkg: Optimize CoreInstallMultipleProtocolInterfaces Zhi Jin 2023-11-09 2:36 ` Ni, Ray 2023-11-27 6:53 ` Zhi Jin 2023-11-28 15:16 ` 回复: " gaoliming via groups.io
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox