[edk2] [PATCH v1 2/2] ArmPkg/ArmScmiDxe: Dynamically allocate buffer for protocol ids

Girish Pathak posted 2 patches 6 years, 2 months ago
There is a newer version of this series
[edk2] [PATCH v1 2/2] ArmPkg/ArmScmiDxe: Dynamically allocate buffer for protocol ids
Posted by Girish Pathak 6 years, 2 months ago
Dynamically allocate the buffer to receive the SCMI protocol list.
This makes MAX_PROTOCOLS redundant, so it is removed.
It also fixes one minor code alignment issue and removes an unused
macro PROTOCOL_MASK.

Change-Id: Idc5880d4fb7b5c674f5fb7dce1198a7cad0303a7
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Girish Pathak <girish.pathak@arm.com>
---
 ArmPkg/Drivers/ArmScmiDxe/Scmi.c    |  5 ----
 ArmPkg/Drivers/ArmScmiDxe/ScmiDxe.c | 27 +++++++++++++++-----
 ArmPkg/Drivers/ArmScmiDxe/ScmiDxe.h |  1 -
 3 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/ArmPkg/Drivers/ArmScmiDxe/Scmi.c b/ArmPkg/Drivers/ArmScmiDxe/Scmi.c
index 1e279f69cf615428dbb6477b8ac7de3258628df3..d247d3a932fe9f197460a95e9afa88681742e4b4 100644
--- a/ArmPkg/Drivers/ArmScmiDxe/Scmi.c
+++ b/ArmPkg/Drivers/ArmScmiDxe/Scmi.c
@@ -22,11 +22,6 @@
 
 #include "ScmiPrivate.h"
 
-// SCMI Specification 1.0
-#define  MAX_PROTOCOLS       6
-
-#define  PROTOCOL_MASK     0xF
-
 // Arbitrary timeout value 20ms.
 #define  RESPONSE_TIMEOUT  20000
 
diff --git a/ArmPkg/Drivers/ArmScmiDxe/ScmiDxe.c b/ArmPkg/Drivers/ArmScmiDxe/ScmiDxe.c
index cc68cbc922fcc06bff8f7e0aa8b6bf64a9932874..e7b9feca5e1b565fc031385bfe2f2dc0ca53aab0 100644
--- a/ArmPkg/Drivers/ArmScmiDxe/ScmiDxe.c
+++ b/ArmPkg/Drivers/ArmScmiDxe/ScmiDxe.c
@@ -63,8 +63,8 @@ ArmScmiDxeEntryPoint (
   UINT32              Index;
   UINT32              NumProtocols;
   UINT32              ProtocolIndex = 0;
-  UINT8               SupportedList[MAX_PROTOCOLS];
-  UINT32              SupportedListSize = sizeof (SupportedList);
+  UINT8               *SupportedList;
+  UINT32              SupportedListSize;
 
   // Every SCMI implementation must implement the base protocol.
   ASSERT (Protocols[ProtocolIndex].Id == SCMI_PROTOCOL_ID_BASE);
@@ -108,13 +108,26 @@ ArmScmiDxeEntryPoint (
 
   ASSERT (NumProtocols != 0);
 
+  SupportedListSize = (NumProtocols * sizeof (*SupportedList));
+
+  Status = gBS->AllocatePool (
+                  EfiBootServicesData,
+                  SupportedListSize,
+                  (VOID**)&SupportedList
+                  );
+  if (EFI_ERROR (Status)) {
+    ASSERT (FALSE);
+    return Status;
+  }
+
   // Get the list of protocols supported by SCP firmware on the platform.
   Status = BaseProtocol->DiscoverListProtocols (
-             BaseProtocol,
-             &SupportedListSize,
-             SupportedList
-             );
+                           BaseProtocol,
+                           &SupportedListSize,
+                           SupportedList
+                           );
   if (EFI_ERROR (Status)) {
+    gBS->FreePool (SupportedList);
     ASSERT (FALSE);
     return Status;
   }
@@ -133,5 +146,7 @@ ArmScmiDxeEntryPoint (
     }
   }
 
+  gBS->FreePool (SupportedList);
+
   return EFI_SUCCESS;
 }
diff --git a/ArmPkg/Drivers/ArmScmiDxe/ScmiDxe.h b/ArmPkg/Drivers/ArmScmiDxe/ScmiDxe.h
index 5815e1e78074067760b6f618e248526ee25e59c8..b50a52a01d47efbbccec8c97bf44041c47ff8b38 100644
--- a/ArmPkg/Drivers/ArmScmiDxe/ScmiDxe.h
+++ b/ArmPkg/Drivers/ArmScmiDxe/ScmiDxe.h
@@ -19,7 +19,6 @@
 
 #include "ScmiPrivate.h"
 
-#define MAX_PROTOCOLS        6
 #define MAX_VENDOR_LEN       SCMI_MAX_STR_LEN
 
 /** Pointer to protocol initialization function.
-- 
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'


_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH v1 0/2] ArmPkg/ArmScmiDxe: Fix a bug uncovered with the new SCP firmware
Posted by Sudeep Holla 6 years, 2 months ago
Hi Girish,

On Fri, Jun 15, 2018 at 03:10:52PM +0100, Girish Pathak wrote:
> This series fixes a bug in the ArmScmiDxe which was revealed while testing
> with the new SCP firmware.
>
> The changes can be seen at https://github.com/girishpathak/edk2/tree/281_scmi_fix_v1
>

Thanks for the fix. This fixes the issue I originally reported. So, FWIW

Tested-by: Sudeep Holla <sudeep.holla@arm.com>

--
Regards,
Sudeep
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH v1 2/2] ArmPkg/ArmScmiDxe: Dynamically allocate buffer for protocol ids
Posted by Ard Biesheuvel 6 years, 2 months ago
On 15 June 2018 at 16:10, Girish Pathak <girish.pathak@arm.com> wrote:
> Dynamically allocate the buffer to receive the SCMI protocol list.
> This makes MAX_PROTOCOLS redundant, so it is removed.
> It also fixes one minor code alignment issue and removes an unused
> macro PROTOCOL_MASK.
>
> Change-Id: Idc5880d4fb7b5c674f5fb7dce1198a7cad0303a7

Can you please get rid of these change IDs? They have no meaning in
the context of the upstream repo.

> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Girish Pathak <girish.pathak@arm.com>
> ---
>  ArmPkg/Drivers/ArmScmiDxe/Scmi.c    |  5 ----
>  ArmPkg/Drivers/ArmScmiDxe/ScmiDxe.c | 27 +++++++++++++++-----
>  ArmPkg/Drivers/ArmScmiDxe/ScmiDxe.h |  1 -
>  3 files changed, 21 insertions(+), 12 deletions(-)
>
> diff --git a/ArmPkg/Drivers/ArmScmiDxe/Scmi.c b/ArmPkg/Drivers/ArmScmiDxe/Scmi.c
> index 1e279f69cf615428dbb6477b8ac7de3258628df3..d247d3a932fe9f197460a95e9afa88681742e4b4 100644
> --- a/ArmPkg/Drivers/ArmScmiDxe/Scmi.c
> +++ b/ArmPkg/Drivers/ArmScmiDxe/Scmi.c
> @@ -22,11 +22,6 @@
>
>  #include "ScmiPrivate.h"
>
> -// SCMI Specification 1.0
> -#define  MAX_PROTOCOLS       6
> -
> -#define  PROTOCOL_MASK     0xF
> -
>  // Arbitrary timeout value 20ms.
>  #define  RESPONSE_TIMEOUT  20000
>
> diff --git a/ArmPkg/Drivers/ArmScmiDxe/ScmiDxe.c b/ArmPkg/Drivers/ArmScmiDxe/ScmiDxe.c
> index cc68cbc922fcc06bff8f7e0aa8b6bf64a9932874..e7b9feca5e1b565fc031385bfe2f2dc0ca53aab0 100644
> --- a/ArmPkg/Drivers/ArmScmiDxe/ScmiDxe.c
> +++ b/ArmPkg/Drivers/ArmScmiDxe/ScmiDxe.c
> @@ -63,8 +63,8 @@ ArmScmiDxeEntryPoint (
>    UINT32              Index;
>    UINT32              NumProtocols;
>    UINT32              ProtocolIndex = 0;
> -  UINT8               SupportedList[MAX_PROTOCOLS];
> -  UINT32              SupportedListSize = sizeof (SupportedList);

Ah excellent. Forget what I said about this line in the previous message.

> +  UINT8               *SupportedList;
> +  UINT32              SupportedListSize;
>
>    // Every SCMI implementation must implement the base protocol.
>    ASSERT (Protocols[ProtocolIndex].Id == SCMI_PROTOCOL_ID_BASE);
> @@ -108,13 +108,26 @@ ArmScmiDxeEntryPoint (
>
>    ASSERT (NumProtocols != 0);
>
> +  SupportedListSize = (NumProtocols * sizeof (*SupportedList));
> +
> +  Status = gBS->AllocatePool (
> +                  EfiBootServicesData,
> +                  SupportedListSize,
> +                  (VOID**)&SupportedList
> +                  );
> +  if (EFI_ERROR (Status)) {
> +    ASSERT (FALSE);
> +    return Status;
> +  }
> +
>    // Get the list of protocols supported by SCP firmware on the platform.
>    Status = BaseProtocol->DiscoverListProtocols (
> -             BaseProtocol,
> -             &SupportedListSize,
> -             SupportedList
> -             );
> +                           BaseProtocol,
> +                           &SupportedListSize,
> +                           SupportedList
> +                           );
>    if (EFI_ERROR (Status)) {
> +    gBS->FreePool (SupportedList);
>      ASSERT (FALSE);
>      return Status;
>    }
> @@ -133,5 +146,7 @@ ArmScmiDxeEntryPoint (
>      }
>    }
>
> +  gBS->FreePool (SupportedList);
> +
>    return EFI_SUCCESS;
>  }
> diff --git a/ArmPkg/Drivers/ArmScmiDxe/ScmiDxe.h b/ArmPkg/Drivers/ArmScmiDxe/ScmiDxe.h
> index 5815e1e78074067760b6f618e248526ee25e59c8..b50a52a01d47efbbccec8c97bf44041c47ff8b38 100644
> --- a/ArmPkg/Drivers/ArmScmiDxe/ScmiDxe.h
> +++ b/ArmPkg/Drivers/ArmScmiDxe/ScmiDxe.h
> @@ -19,7 +19,6 @@
>
>  #include "ScmiPrivate.h"
>
> -#define MAX_PROTOCOLS        6
>  #define MAX_VENDOR_LEN       SCMI_MAX_STR_LEN
>
>  /** Pointer to protocol initialization function.
> --
> 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'
>
>
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel