Re: [edk2] [PATCH] MdePkg/UefiLib: Simplify protocol un/installation abstraction
Mike, Do you have any update on this change yet? Thanks Ashish -Original Message- From: Kinney, Michael D Sent: Tuesday, February 19, 2019 12:56 PM To: Ashish Singhal ; edk2-devel@lists.01.org; Kinney, Michael D Cc: Gao, Liming Subject: RE: [PATCH] MdePkg/UefiLib: Simplify protocol un/installation abstraction Ashish, Thanks for looking at simplifying this logic again. I have not had a chance to run the size analysis yet. I will get back to you in a couple of days. Thanks, Mike > -Original Message- > From: Ashish Singhal [mailto:ashishsin...@nvidia.com] > Sent: Tuesday, February 19, 2019 8:19 AM > To: edk2-devel@lists.01.org > Cc: Kinney, Michael D ; > Gao, Liming > Subject: RE: [PATCH] MdePkg/UefiLib: Simplify protocol > un/installation abstraction > > Hello Mike/Lao, > > Were you able to have a look at this? > > Thanks > Ashish > > -Original Message- > From: Ashish Singhal > Sent: Monday, February 4, 2019 1:16 PM > To: edk2-devel@lists.01.org > Cc: michael.d.kin...@intel.com; liming@intel.com; > Ashish Singhal > Subject: [PATCH] MdePkg/UefiLib: Simplify protocol > un/installation abstraction > > Add helper functions to operate upon protocol > installation and > uninstallation instead of every function doing it by > itself. > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Ashish Singhal > --- > MdePkg/Library/UefiLib/UefiDriverModel.c | 2040 +- > > 1 file changed, 342 insertions(+), 1698 deletions(-) > > diff --git a/MdePkg/Library/UefiLib/UefiDriverModel.c > b/MdePkg/Library/UefiLib/UefiDriverModel.c > index 262d8bc..268edf7 100644 > --- a/MdePkg/Library/UefiLib/UefiDriverModel.c > +++ b/MdePkg/Library/UefiLib/UefiDriverModel.c > @@ -17,6 +17,290 @@ > > #include "UefiLibInternal.h" > > + > +#define MAX_SUPPORTED_PROTOCOLS 7 > +typedef struct { > + EFI_GUID *Guid; > + VOID *Interface; > +} EFI_PROCESS_PROTOCOL; > + > + > +static > +EFI_STATUS > +EFIAPI > +EfiLibProcessProtocols ( > + IN CONST EFI_HANDLE > ImageHandle, > + IN EFI_DRIVER_BINDING_PROTOCOL > *DriverBinding, > + IN EFI_HANDLE > DriverBindingHandle, > + IN BOOLEAN Install, > + IN CONST EFI_PROCESS_PROTOCOL > *ProtocolArray > + ) > +{ > + ASSERT (DriverBinding != NULL); > + ASSERT (ProtocolArray != NULL); > + > + if (Install) { > +// > +// Update the ImageHandle and DriverBindingHandle > fields of the Driver Binding Protocol > +// > +DriverBinding->ImageHandle = ImageHandle; > +DriverBinding->DriverBindingHandle = > DriverBindingHandle; > + > +return gBS->InstallMultipleProtocolInterfaces ( > + >DriverBindingHandle, > + ProtocolArray[0].Guid, > ProtocolArray[0].Interface, > + ProtocolArray[1].Guid, > ProtocolArray[1].Interface, > + ProtocolArray[2].Guid, > ProtocolArray[2].Interface, > + ProtocolArray[3].Guid, > ProtocolArray[3].Interface, > + ProtocolArray[4].Guid, > ProtocolArray[4].Interface, > + ProtocolArray[5].Guid, > ProtocolArray[5].Interface, > + ProtocolArray[6].Guid, > ProtocolArray[6].Interface, > + NULL > + ); > + } else { > +return gBS->UninstallMultipleProtocolInterfaces ( > + DriverBinding->DriverBindingHandle, > + ProtocolArray[0].Guid, > ProtocolArray[0].Interface, > + ProtocolArray[1].Guid, > ProtocolArray[1].Interface, > + ProtocolArray[2].Guid, > ProtocolArray[2].Interface, > + ProtocolArray[3].Guid, > ProtocolArray[3].Interface, > + ProtocolArray[4].Guid, > ProtocolArray[4].Interface, > + ProtocolArray[5].Guid, > ProtocolArray[5].Interface, > + ProtocolArray[6].Guid, > ProtocolArray[6].Interface, > + NULL > + ); > + } > +} > + > + > + > +static > +EFI_STATUS > +EFIAPI > +EfiLibProcessAllDriverProtocols ( > + IN CONST EFI_HANDLE > ImageHandle, > + IN EFI_DRIVER_BINDING_PROTOCOL > *DriverBinding, > + IN EFI_HANDLE > DriverBindingHandle, > + IN BOOLEAN Install, > + IN CONST EFI_COMPONENT_NAME_PROTOCOL > *ComponentName, > + IN CONST EFI_DRIVER_CONFIGURATION_PROTOCOL > *DriverConfiguration, > + IN CONST EFI_DRIVER_DIAGNOSTICS_PROTOCOL > *DriverDiagnostics > + ) > +{ > + EFI_STATUS Status; > + EFI_PROCESS_PROTOCOL > ProtocolArray[MAX_SUPPORTED_PROTOCOLS]; > + UINT8ProtocolCount; > + > + ASSERT (DriverBinding != NULL); > + > + // > + // ZI the ProtocolArray structure. Both > InstallMultipleProtocolInterfaces > + // and UninstallMultipleProtocolInterfaces would > stop processing ProtocolArray > + // elements as soon as they encounter a NULL. > + // > + ZeroMem(ProtocolArray, sizeof(ProtocolArray)); > + ProtocolCount = 0; >
Re: [edk2] [PATCH] MdePkg/UefiLib: Simplify protocol un/installation abstraction
Ashish, Thanks for looking at simplifying this logic again. I have not had a chance to run the size analysis yet. I will get back to you in a couple of days. Thanks, Mike > -Original Message- > From: Ashish Singhal [mailto:ashishsin...@nvidia.com] > Sent: Tuesday, February 19, 2019 8:19 AM > To: edk2-devel@lists.01.org > Cc: Kinney, Michael D ; > Gao, Liming > Subject: RE: [PATCH] MdePkg/UefiLib: Simplify protocol > un/installation abstraction > > Hello Mike/Lao, > > Were you able to have a look at this? > > Thanks > Ashish > > -Original Message- > From: Ashish Singhal > Sent: Monday, February 4, 2019 1:16 PM > To: edk2-devel@lists.01.org > Cc: michael.d.kin...@intel.com; liming@intel.com; > Ashish Singhal > Subject: [PATCH] MdePkg/UefiLib: Simplify protocol > un/installation abstraction > > Add helper functions to operate upon protocol > installation and > uninstallation instead of every function doing it by > itself. > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Ashish Singhal > --- > MdePkg/Library/UefiLib/UefiDriverModel.c | 2040 +- > > 1 file changed, 342 insertions(+), 1698 deletions(-) > > diff --git a/MdePkg/Library/UefiLib/UefiDriverModel.c > b/MdePkg/Library/UefiLib/UefiDriverModel.c > index 262d8bc..268edf7 100644 > --- a/MdePkg/Library/UefiLib/UefiDriverModel.c > +++ b/MdePkg/Library/UefiLib/UefiDriverModel.c > @@ -17,6 +17,290 @@ > > #include "UefiLibInternal.h" > > + > +#define MAX_SUPPORTED_PROTOCOLS 7 > +typedef struct { > + EFI_GUID *Guid; > + VOID *Interface; > +} EFI_PROCESS_PROTOCOL; > + > + > +static > +EFI_STATUS > +EFIAPI > +EfiLibProcessProtocols ( > + IN CONST EFI_HANDLE > ImageHandle, > + IN EFI_DRIVER_BINDING_PROTOCOL > *DriverBinding, > + IN EFI_HANDLE > DriverBindingHandle, > + IN BOOLEAN Install, > + IN CONST EFI_PROCESS_PROTOCOL > *ProtocolArray > + ) > +{ > + ASSERT (DriverBinding != NULL); > + ASSERT (ProtocolArray != NULL); > + > + if (Install) { > +// > +// Update the ImageHandle and DriverBindingHandle > fields of the Driver Binding Protocol > +// > +DriverBinding->ImageHandle = ImageHandle; > +DriverBinding->DriverBindingHandle = > DriverBindingHandle; > + > +return gBS->InstallMultipleProtocolInterfaces ( > + >DriverBindingHandle, > + ProtocolArray[0].Guid, > ProtocolArray[0].Interface, > + ProtocolArray[1].Guid, > ProtocolArray[1].Interface, > + ProtocolArray[2].Guid, > ProtocolArray[2].Interface, > + ProtocolArray[3].Guid, > ProtocolArray[3].Interface, > + ProtocolArray[4].Guid, > ProtocolArray[4].Interface, > + ProtocolArray[5].Guid, > ProtocolArray[5].Interface, > + ProtocolArray[6].Guid, > ProtocolArray[6].Interface, > + NULL > + ); > + } else { > +return gBS->UninstallMultipleProtocolInterfaces ( > + DriverBinding->DriverBindingHandle, > + ProtocolArray[0].Guid, > ProtocolArray[0].Interface, > + ProtocolArray[1].Guid, > ProtocolArray[1].Interface, > + ProtocolArray[2].Guid, > ProtocolArray[2].Interface, > + ProtocolArray[3].Guid, > ProtocolArray[3].Interface, > + ProtocolArray[4].Guid, > ProtocolArray[4].Interface, > + ProtocolArray[5].Guid, > ProtocolArray[5].Interface, > + ProtocolArray[6].Guid, > ProtocolArray[6].Interface, > + NULL > + ); > + } > +} > + > + > + > +static > +EFI_STATUS > +EFIAPI > +EfiLibProcessAllDriverProtocols ( > + IN CONST EFI_HANDLE > ImageHandle, > + IN EFI_DRIVER_BINDING_PROTOCOL > *DriverBinding, > + IN EFI_HANDLE > DriverBindingHandle, > + IN BOOLEAN Install, > + IN CONST EFI_COMPONENT_NAME_PROTOCOL > *ComponentName, > + IN CONST EFI_DRIVER_CONFIGURATION_PROTOCOL > *DriverConfiguration, > + IN CONST EFI_DRIVER_DIAGNOSTICS_PROTOCOL > *DriverDiagnostics > + ) > +{ > + EFI_STATUS Status; > + EFI_PROCESS_PROTOCOL > ProtocolArray[MAX_SUPPORTED_PROTOCOLS]; > + UINT8ProtocolCount; > + > + ASSERT (DriverBinding != NULL); > + > + // > + // ZI the ProtocolArray structure. Both > InstallMultipleProtocolInterfaces > + // and UninstallMultipleProtocolInterfaces would > stop processing ProtocolArray > + // elements as soon as they encounter a NULL. > + // > + ZeroMem(ProtocolArray, sizeof(ProtocolArray)); > + ProtocolCount = 0; > + > + // > + // Populate ProtocolArray with valid protocol > interfaces. > + // > + ProtocolArray[ProtocolCount].Guid = > > + ProtocolArray[ProtocolCount].Interface = > DriverBinding; > + ProtocolCount++; > + > + if (ComponentName != NULL && > !FeaturePcdGet(PcdComponentNameDisable)) { > +
Re: [edk2] [PATCH] MdePkg/UefiLib: Simplify protocol un/installation abstraction
Hello Mike/Lao, Were you able to have a look at this? Thanks Ashish -Original Message- From: Ashish Singhal Sent: Monday, February 4, 2019 1:16 PM To: edk2-devel@lists.01.org Cc: michael.d.kin...@intel.com; liming@intel.com; Ashish Singhal Subject: [PATCH] MdePkg/UefiLib: Simplify protocol un/installation abstraction Add helper functions to operate upon protocol installation and uninstallation instead of every function doing it by itself. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ashish Singhal --- MdePkg/Library/UefiLib/UefiDriverModel.c | 2040 +- 1 file changed, 342 insertions(+), 1698 deletions(-) diff --git a/MdePkg/Library/UefiLib/UefiDriverModel.c b/MdePkg/Library/UefiLib/UefiDriverModel.c index 262d8bc..268edf7 100644 --- a/MdePkg/Library/UefiLib/UefiDriverModel.c +++ b/MdePkg/Library/UefiLib/UefiDriverModel.c @@ -17,6 +17,290 @@ #include "UefiLibInternal.h" + +#define MAX_SUPPORTED_PROTOCOLS 7 +typedef struct { + EFI_GUID *Guid; + VOID *Interface; +} EFI_PROCESS_PROTOCOL; + + +static +EFI_STATUS +EFIAPI +EfiLibProcessProtocols ( + IN CONST EFI_HANDLE ImageHandle, + IN EFI_DRIVER_BINDING_PROTOCOL *DriverBinding, + IN EFI_HANDLE DriverBindingHandle, + IN BOOLEAN Install, + IN CONST EFI_PROCESS_PROTOCOL *ProtocolArray + ) +{ + ASSERT (DriverBinding != NULL); + ASSERT (ProtocolArray != NULL); + + if (Install) { +// +// Update the ImageHandle and DriverBindingHandle fields of the Driver Binding Protocol +// +DriverBinding->ImageHandle = ImageHandle; +DriverBinding->DriverBindingHandle = DriverBindingHandle; + +return gBS->InstallMultipleProtocolInterfaces ( + >DriverBindingHandle, + ProtocolArray[0].Guid, ProtocolArray[0].Interface, + ProtocolArray[1].Guid, ProtocolArray[1].Interface, + ProtocolArray[2].Guid, ProtocolArray[2].Interface, + ProtocolArray[3].Guid, ProtocolArray[3].Interface, + ProtocolArray[4].Guid, ProtocolArray[4].Interface, + ProtocolArray[5].Guid, ProtocolArray[5].Interface, + ProtocolArray[6].Guid, ProtocolArray[6].Interface, + NULL + ); + } else { +return gBS->UninstallMultipleProtocolInterfaces ( + DriverBinding->DriverBindingHandle, + ProtocolArray[0].Guid, ProtocolArray[0].Interface, + ProtocolArray[1].Guid, ProtocolArray[1].Interface, + ProtocolArray[2].Guid, ProtocolArray[2].Interface, + ProtocolArray[3].Guid, ProtocolArray[3].Interface, + ProtocolArray[4].Guid, ProtocolArray[4].Interface, + ProtocolArray[5].Guid, ProtocolArray[5].Interface, + ProtocolArray[6].Guid, ProtocolArray[6].Interface, + NULL + ); + } +} + + + +static +EFI_STATUS +EFIAPI +EfiLibProcessAllDriverProtocols ( + IN CONST EFI_HANDLE ImageHandle, + IN EFI_DRIVER_BINDING_PROTOCOL *DriverBinding, + IN EFI_HANDLE DriverBindingHandle, + IN BOOLEAN Install, + IN CONST EFI_COMPONENT_NAME_PROTOCOL*ComponentName, + IN CONST EFI_DRIVER_CONFIGURATION_PROTOCOL *DriverConfiguration, + IN CONST EFI_DRIVER_DIAGNOSTICS_PROTOCOL*DriverDiagnostics + ) +{ + EFI_STATUS Status; + EFI_PROCESS_PROTOCOL ProtocolArray[MAX_SUPPORTED_PROTOCOLS]; + UINT8ProtocolCount; + + ASSERT (DriverBinding != NULL); + + // + // ZI the ProtocolArray structure. Both InstallMultipleProtocolInterfaces + // and UninstallMultipleProtocolInterfaces would stop processing ProtocolArray + // elements as soon as they encounter a NULL. + // + ZeroMem(ProtocolArray, sizeof(ProtocolArray)); + ProtocolCount = 0; + + // + // Populate ProtocolArray with valid protocol interfaces. + // + ProtocolArray[ProtocolCount].Guid = + ProtocolArray[ProtocolCount].Interface = DriverBinding; + ProtocolCount++; + + if (ComponentName != NULL && !FeaturePcdGet(PcdComponentNameDisable)) { +ProtocolArray[ProtocolCount].Guid = +ProtocolArray[ProtocolCount].Interface = (VOID *)ComponentName; +ProtocolCount++; + } + + if (DriverConfiguration != NULL) { +ProtocolArray[ProtocolCount].Guid = +ProtocolArray[ProtocolCount].Interface = (VOID *)DriverConfiguration; +ProtocolCount++; + } + + if (DriverDiagnostics != NULL && !FeaturePcdGet(PcdDriverDiagnosticsDisable)) { +ProtocolArray[ProtocolCount].Guid = +ProtocolArray[ProtocolCount].Interface = (VOID *)DriverDiagnostics; +ProtocolCount++; + } + + Status = EfiLibProcessProtocols ( + ImageHandle, + DriverBinding, +
[edk2] [PATCH] MdePkg/UefiLib: Simplify protocol un/installation abstraction
Add helper functions to operate upon protocol installation and uninstallation instead of every function doing it by itself. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ashish Singhal --- MdePkg/Library/UefiLib/UefiDriverModel.c | 2040 +- 1 file changed, 342 insertions(+), 1698 deletions(-) diff --git a/MdePkg/Library/UefiLib/UefiDriverModel.c b/MdePkg/Library/UefiLib/UefiDriverModel.c index 262d8bc..268edf7 100644 --- a/MdePkg/Library/UefiLib/UefiDriverModel.c +++ b/MdePkg/Library/UefiLib/UefiDriverModel.c @@ -17,6 +17,290 @@ #include "UefiLibInternal.h" + +#define MAX_SUPPORTED_PROTOCOLS 7 +typedef struct { + EFI_GUID *Guid; + VOID *Interface; +} EFI_PROCESS_PROTOCOL; + + +static +EFI_STATUS +EFIAPI +EfiLibProcessProtocols ( + IN CONST EFI_HANDLE ImageHandle, + IN EFI_DRIVER_BINDING_PROTOCOL *DriverBinding, + IN EFI_HANDLE DriverBindingHandle, + IN BOOLEAN Install, + IN CONST EFI_PROCESS_PROTOCOL *ProtocolArray + ) +{ + ASSERT (DriverBinding != NULL); + ASSERT (ProtocolArray != NULL); + + if (Install) { +// +// Update the ImageHandle and DriverBindingHandle fields of the Driver Binding Protocol +// +DriverBinding->ImageHandle = ImageHandle; +DriverBinding->DriverBindingHandle = DriverBindingHandle; + +return gBS->InstallMultipleProtocolInterfaces ( + >DriverBindingHandle, + ProtocolArray[0].Guid, ProtocolArray[0].Interface, + ProtocolArray[1].Guid, ProtocolArray[1].Interface, + ProtocolArray[2].Guid, ProtocolArray[2].Interface, + ProtocolArray[3].Guid, ProtocolArray[3].Interface, + ProtocolArray[4].Guid, ProtocolArray[4].Interface, + ProtocolArray[5].Guid, ProtocolArray[5].Interface, + ProtocolArray[6].Guid, ProtocolArray[6].Interface, + NULL + ); + } else { +return gBS->UninstallMultipleProtocolInterfaces ( + DriverBinding->DriverBindingHandle, + ProtocolArray[0].Guid, ProtocolArray[0].Interface, + ProtocolArray[1].Guid, ProtocolArray[1].Interface, + ProtocolArray[2].Guid, ProtocolArray[2].Interface, + ProtocolArray[3].Guid, ProtocolArray[3].Interface, + ProtocolArray[4].Guid, ProtocolArray[4].Interface, + ProtocolArray[5].Guid, ProtocolArray[5].Interface, + ProtocolArray[6].Guid, ProtocolArray[6].Interface, + NULL + ); + } +} + + + +static +EFI_STATUS +EFIAPI +EfiLibProcessAllDriverProtocols ( + IN CONST EFI_HANDLE ImageHandle, + IN EFI_DRIVER_BINDING_PROTOCOL *DriverBinding, + IN EFI_HANDLE DriverBindingHandle, + IN BOOLEAN Install, + IN CONST EFI_COMPONENT_NAME_PROTOCOL*ComponentName, + IN CONST EFI_DRIVER_CONFIGURATION_PROTOCOL *DriverConfiguration, + IN CONST EFI_DRIVER_DIAGNOSTICS_PROTOCOL*DriverDiagnostics + ) +{ + EFI_STATUS Status; + EFI_PROCESS_PROTOCOL ProtocolArray[MAX_SUPPORTED_PROTOCOLS]; + UINT8ProtocolCount; + + ASSERT (DriverBinding != NULL); + + // + // ZI the ProtocolArray structure. Both InstallMultipleProtocolInterfaces + // and UninstallMultipleProtocolInterfaces would stop processing ProtocolArray + // elements as soon as they encounter a NULL. + // + ZeroMem(ProtocolArray, sizeof(ProtocolArray)); + ProtocolCount = 0; + + // + // Populate ProtocolArray with valid protocol interfaces. + // + ProtocolArray[ProtocolCount].Guid = + ProtocolArray[ProtocolCount].Interface = DriverBinding; + ProtocolCount++; + + if (ComponentName != NULL && !FeaturePcdGet(PcdComponentNameDisable)) { +ProtocolArray[ProtocolCount].Guid = +ProtocolArray[ProtocolCount].Interface = (VOID *)ComponentName; +ProtocolCount++; + } + + if (DriverConfiguration != NULL) { +ProtocolArray[ProtocolCount].Guid = +ProtocolArray[ProtocolCount].Interface = (VOID *)DriverConfiguration; +ProtocolCount++; + } + + if (DriverDiagnostics != NULL && !FeaturePcdGet(PcdDriverDiagnosticsDisable)) { +ProtocolArray[ProtocolCount].Guid = +ProtocolArray[ProtocolCount].Interface = (VOID *)DriverDiagnostics; +ProtocolCount++; + } + + Status = EfiLibProcessProtocols ( + ImageHandle, + DriverBinding, + DriverBindingHandle, + Install, + ProtocolArray + ); + + // + // ASSERT if the call to InstallMultipleProtocolInterfaces() or + // UninstallMultipleProtocolInterfaces() failed + // + ASSERT_EFI_ERROR (Status); + + return Status; +} + + + +static +EFI_STATUS +EFIAPI