]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPkg/ArmScmiDxe: Fix ASSERT error in SCMI DXE
authorGirish Pathak <girish.pathak@arm.com>
Tue, 19 Jun 2018 13:53:52 +0000 (14:53 +0100)
committerArd Biesheuvel <ard.biesheuvel@linaro.org>
Fri, 22 Jun 2018 06:21:30 +0000 (08:21 +0200)
This change fixes a bug in the SCMI DXE which is observed with the
upcoming release of the SCP firmware.

The PROTOCOL_ID_MASK (0xF) which is used to generate an index in
the ProtocolInitFxns is wrong because protocol ids can be
anywhere in 0x10 - 15 or 0x80 - FF range. This mask generates
the same index for two different protocols e.g. for protocol ids
0x10 and 0x90, which causes duplicate initialization of a protocol
resulting in a failure.

This change removes the use of PROTOCOL_ID_MASK and instead
uses a list of protocol ids and their initialization functions
to identify a supported protocol and initialize it.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Girish Pathak <girish.pathak@arm.com>
Tested-by: Sudeep Holla <sudeep.holla@arm.com>
Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
ArmPkg/Drivers/ArmScmiDxe/ScmiDxe.c
ArmPkg/Drivers/ArmScmiDxe/ScmiDxe.h

index 2920c6f6f33c5bb8ac00c903a0b199ba5f06f4de..a56c7b21d5f09d41a110826b7b9db14ac34451de 100644 (file)
 #include "ScmiDxe.h"\r
 #include "ScmiPrivate.h"\r
 \r
-STATIC CONST SCMI_PROTOCOL_INIT_TABLE ProtocolInitFxns[MAX_PROTOCOLS] = {\r
-  { ScmiBaseProtocolInit },\r
-  { NULL },\r
-  { NULL },\r
-  { ScmiPerformanceProtocolInit },\r
-  { ScmiClockProtocolInit },\r
-  { NULL }\r
+STATIC CONST SCMI_PROTOCOL_ENTRY Protocols[] = {\r
+  { SCMI_PROTOCOL_ID_BASE, ScmiBaseProtocolInit },\r
+  { SCMI_PROTOCOL_ID_PERFORMANCE, ScmiPerformanceProtocolInit },\r
+  { SCMI_PROTOCOL_ID_CLOCK, ScmiClockProtocolInit }\r
 };\r
 \r
 /** ARM SCMI driver entry point function.\r
@@ -65,14 +62,14 @@ ArmScmiDxeEntryPoint (
   UINT32              Version;\r
   UINT32              Index;\r
   UINT32              NumProtocols;\r
-  UINT32              ProtocolNo;\r
+  UINT32              ProtocolIndex;\r
   UINT8               SupportedList[MAX_PROTOCOLS];\r
   UINT32              SupportedListSize = sizeof (SupportedList);\r
 \r
-  ProtocolNo = SCMI_PROTOCOL_ID_BASE & PROTOCOL_ID_MASK;\r
-\r
   // Every SCMI implementation must implement the base protocol.\r
-  Status = ProtocolInitFxns[ProtocolNo].Init (&ImageHandle);\r
+  ASSERT (Protocols[0].Id == SCMI_PROTOCOL_ID_BASE);\r
+\r
+  Status = ScmiBaseProtocolInit (&ImageHandle);\r
   if (EFI_ERROR (Status)) {\r
     ASSERT (FALSE);\r
     return Status;\r
@@ -123,13 +120,16 @@ ArmScmiDxeEntryPoint (
   }\r
 \r
   // Install supported protocol on ImageHandle.\r
-  for (Index = 0; Index < NumProtocols; Index++) {\r
-    ProtocolNo = SupportedList[Index] & PROTOCOL_ID_MASK;\r
-    if (ProtocolInitFxns[ProtocolNo].Init != NULL) {\r
-      Status = ProtocolInitFxns[ProtocolNo].Init (&ImageHandle);\r
-      if (EFI_ERROR (Status)) {\r
-        ASSERT (FALSE);\r
-        return Status;\r
+  for (ProtocolIndex = 1; ProtocolIndex < ARRAY_SIZE (Protocols);\r
+       ProtocolIndex++) {\r
+    for (Index = 0; Index < NumProtocols; Index++) {\r
+      if (Protocols[ProtocolIndex].Id == SupportedList[Index]) {\r
+        Status = Protocols[ProtocolIndex].InitFn (&ImageHandle);\r
+        if (EFI_ERROR (Status)) {\r
+          ASSERT_EFI_ERROR (Status);\r
+          return Status;\r
+        }\r
+        break;\r
       }\r
     }\r
   }\r
index 29cdde173659c701116b021a3c437a92b473e4e5..222e54f4dca558d9b1fedddf3f96fd977898c7b2 100644 (file)
@@ -17,8 +17,9 @@
 #ifndef SCMI_DXE_H_\r
 #define SCMI_DXE_H_\r
 \r
+#include "ScmiPrivate.h"\r
+\r
 #define MAX_PROTOCOLS        6\r
-#define PROTOCOL_ID_MASK     0xF\r
 #define MAX_VENDOR_LEN       SCMI_MAX_STR_LEN\r
 \r
 /** Pointer to protocol initialization function.\r
@@ -35,7 +36,8 @@ EFI_STATUS
   );\r
 \r
 typedef struct {\r
-  SCMI_PROTOCOL_INIT_FXN Init;\r
-} SCMI_PROTOCOL_INIT_TABLE;\r
+  SCMI_PROTOCOL_ID Id;            // Protocol Id.\r
+  SCMI_PROTOCOL_INIT_FXN InitFn;  // Protocol init function.\r
+} SCMI_PROTOCOL_ENTRY;\r
 \r
 #endif /* SCMI_DXE_H_ */\r