From nobody Thu May 2 18:32:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1529416450179140.8022311549813; Tue, 19 Jun 2018 06:54:10 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 236AA21155D39; Tue, 19 Jun 2018 06:54:05 -0700 (PDT) Received: from cam-smtp0.cambridge.arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id C426F21155D2C for ; Tue, 19 Jun 2018 06:54:02 -0700 (PDT) Received: from E107875.Emea.Arm.com (E107875.Emea.Arm.com [10.1.206.50]) by cam-smtp0.cambridge.arm.com (8.13.8/8.13.8) with ESMTP id w5JDrxq2026015; Tue, 19 Jun 2018 14:53:59 +0100 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=217.140.96.140; helo=cam-smtp0.cambridge.arm.com; envelope-from=girish.pathak@arm.com; receiver=edk2-devel@lists.01.org From: Girish Pathak To: edk2-devel@lists.01.org Date: Tue, 19 Jun 2018 14:53:52 +0100 Message-Id: <20180619135353.40176-2-girish.pathak@arm.com> X-Mailer: git-send-email 2.13.3.windows.1 In-Reply-To: <20180619135353.40176-1-girish.pathak@arm.com> References: <20180619135353.40176-1-girish.pathak@arm.com> Subject: [edk2] [PATCH v2 1/2] ArmPkg/ArmScmiDxe: Fix ASSERT error in SCMI DXE X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stephanie.Hughes-Fitt@arm.com, ard.biesheuvel@linaro.org, leif.lindholm@linaro.org, Sudeep.Holla@arm.com, nd@arm.com MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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 Tested-by: Sudeep Holla Reviewed-by: Ard Biesheuvel --- Notes: v2: - We don't permit initialized automatic variables. [Ard] Fixed. [Girish] - Just use Protocols[0].Id. [Ard] Done. [Girish] - Call ScmiBaseProtocolInit() here. [Ard] Done. [Girish] - Please use a for () loop instead of while [Ard] Fixed. [Girish] - Replace ASSERT (FALSE) with ASSERT_EFI_ERROR () [Ard] Fixed. [Girish] - Rename InitFxn to InitFn [Ard] Fixed. [Girish] ArmPkg/Drivers/ArmScmiDxe/ScmiDxe.c | 36 ++++++++++---------- ArmPkg/Drivers/ArmScmiDxe/ScmiDxe.h | 8 +++-- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/ArmPkg/Drivers/ArmScmiDxe/ScmiDxe.c b/ArmPkg/Drivers/ArmScmiDx= e/ScmiDxe.c index 2920c6f6f33c5bb8ac00c903a0b199ba5f06f4de..a56c7b21d5f09d41a110826b7b9= db14ac34451de 100644 --- a/ArmPkg/Drivers/ArmScmiDxe/ScmiDxe.c +++ b/ArmPkg/Drivers/ArmScmiDxe/ScmiDxe.c @@ -29,13 +29,10 @@ #include "ScmiDxe.h" #include "ScmiPrivate.h" =20 -STATIC CONST SCMI_PROTOCOL_INIT_TABLE ProtocolInitFxns[MAX_PROTOCOLS] =3D { - { ScmiBaseProtocolInit }, - { NULL }, - { NULL }, - { ScmiPerformanceProtocolInit }, - { ScmiClockProtocolInit }, - { NULL } +STATIC CONST SCMI_PROTOCOL_ENTRY Protocols[] =3D { + { SCMI_PROTOCOL_ID_BASE, ScmiBaseProtocolInit }, + { SCMI_PROTOCOL_ID_PERFORMANCE, ScmiPerformanceProtocolInit }, + { SCMI_PROTOCOL_ID_CLOCK, ScmiClockProtocolInit } }; =20 /** ARM SCMI driver entry point function. @@ -65,14 +62,14 @@ ArmScmiDxeEntryPoint ( UINT32 Version; UINT32 Index; UINT32 NumProtocols; - UINT32 ProtocolNo; + UINT32 ProtocolIndex; UINT8 SupportedList[MAX_PROTOCOLS]; UINT32 SupportedListSize =3D sizeof (SupportedList); =20 - ProtocolNo =3D SCMI_PROTOCOL_ID_BASE & PROTOCOL_ID_MASK; - // Every SCMI implementation must implement the base protocol. - Status =3D ProtocolInitFxns[ProtocolNo].Init (&ImageHandle); + ASSERT (Protocols[0].Id =3D=3D SCMI_PROTOCOL_ID_BASE); + + Status =3D ScmiBaseProtocolInit (&ImageHandle); if (EFI_ERROR (Status)) { ASSERT (FALSE); return Status; @@ -123,13 +120,16 @@ ArmScmiDxeEntryPoint ( } =20 // Install supported protocol on ImageHandle. - for (Index =3D 0; Index < NumProtocols; Index++) { - ProtocolNo =3D SupportedList[Index] & PROTOCOL_ID_MASK; - if (ProtocolInitFxns[ProtocolNo].Init !=3D NULL) { - Status =3D ProtocolInitFxns[ProtocolNo].Init (&ImageHandle); - if (EFI_ERROR (Status)) { - ASSERT (FALSE); - return Status; + for (ProtocolIndex =3D 1; ProtocolIndex < ARRAY_SIZE (Protocols); + ProtocolIndex++) { + for (Index =3D 0; Index < NumProtocols; Index++) { + if (Protocols[ProtocolIndex].Id =3D=3D SupportedList[Index]) { + Status =3D Protocols[ProtocolIndex].InitFn (&ImageHandle); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + return Status; + } + break; } } } diff --git a/ArmPkg/Drivers/ArmScmiDxe/ScmiDxe.h b/ArmPkg/Drivers/ArmScmiDx= e/ScmiDxe.h index 29cdde173659c701116b021a3c437a92b473e4e5..222e54f4dca558d9b1fedddf3f9= 6fd977898c7b2 100644 --- a/ArmPkg/Drivers/ArmScmiDxe/ScmiDxe.h +++ b/ArmPkg/Drivers/ArmScmiDxe/ScmiDxe.h @@ -17,8 +17,9 @@ #ifndef SCMI_DXE_H_ #define SCMI_DXE_H_ =20 +#include "ScmiPrivate.h" + #define MAX_PROTOCOLS 6 -#define PROTOCOL_ID_MASK 0xF #define MAX_VENDOR_LEN SCMI_MAX_STR_LEN =20 /** Pointer to protocol initialization function. @@ -35,7 +36,8 @@ EFI_STATUS ); =20 typedef struct { - SCMI_PROTOCOL_INIT_FXN Init; -} SCMI_PROTOCOL_INIT_TABLE; + SCMI_PROTOCOL_ID Id; // Protocol Id. + SCMI_PROTOCOL_INIT_FXN InitFn; // Protocol init function. +} SCMI_PROTOCOL_ENTRY; =20 #endif /* SCMI_DXE_H_ */ --=20 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)' _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Thu May 2 18:32:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1529416445659340.904079502855; Tue, 19 Jun 2018 06:54:05 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id B0BE821155D2F; Tue, 19 Jun 2018 06:54:04 -0700 (PDT) Received: from cam-smtp0.cambridge.arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id C341C21155D2B for ; Tue, 19 Jun 2018 06:54:02 -0700 (PDT) Received: from E107875.Emea.Arm.com (E107875.Emea.Arm.com [10.1.206.50]) by cam-smtp0.cambridge.arm.com (8.13.8/8.13.8) with ESMTP id w5JDrxq3026015; Tue, 19 Jun 2018 14:54:00 +0100 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=217.140.96.140; helo=cam-smtp0.cambridge.arm.com; envelope-from=girish.pathak@arm.com; receiver=edk2-devel@lists.01.org From: Girish Pathak To: edk2-devel@lists.01.org Date: Tue, 19 Jun 2018 14:53:53 +0100 Message-Id: <20180619135353.40176-3-girish.pathak@arm.com> X-Mailer: git-send-email 2.13.3.windows.1 In-Reply-To: <20180619135353.40176-1-girish.pathak@arm.com> References: <20180619135353.40176-1-girish.pathak@arm.com> Subject: [edk2] [PATCH v2 2/2] ArmPkg/ArmScmiDxe: Dynamically allocate buffer for protocol ids X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stephanie.Hughes-Fitt@arm.com, ard.biesheuvel@linaro.org, leif.lindholm@linaro.org, Sudeep.Holla@arm.com, nd@arm.com MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Girish Pathak Tested-by: Sudeep Holla Reviewed-by: Ard Biesheuvel --- Notes: v2: - Remove change-id [Ard] Done [Girish] 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/S= cmi.c index 1e279f69cf615428dbb6477b8ac7de3258628df3..d247d3a932fe9f197460a95e9af= a88681742e4b4 100644 --- a/ArmPkg/Drivers/ArmScmiDxe/Scmi.c +++ b/ArmPkg/Drivers/ArmScmiDxe/Scmi.c @@ -22,11 +22,6 @@ =20 #include "ScmiPrivate.h" =20 -// SCMI Specification 1.0 -#define MAX_PROTOCOLS 6 - -#define PROTOCOL_MASK 0xF - // Arbitrary timeout value 20ms. #define RESPONSE_TIMEOUT 20000 =20 diff --git a/ArmPkg/Drivers/ArmScmiDxe/ScmiDxe.c b/ArmPkg/Drivers/ArmScmiDx= e/ScmiDxe.c index a56c7b21d5f09d41a110826b7b9db14ac34451de..0400799b5c521dcfa2ce866b0ff= d48530e8cf0d1 100644 --- a/ArmPkg/Drivers/ArmScmiDxe/ScmiDxe.c +++ b/ArmPkg/Drivers/ArmScmiDxe/ScmiDxe.c @@ -63,8 +63,8 @@ ArmScmiDxeEntryPoint ( UINT32 Index; UINT32 NumProtocols; UINT32 ProtocolIndex; - UINT8 SupportedList[MAX_PROTOCOLS]; - UINT32 SupportedListSize =3D sizeof (SupportedList); + UINT8 *SupportedList; + UINT32 SupportedListSize; =20 // Every SCMI implementation must implement the base protocol. ASSERT (Protocols[0].Id =3D=3D SCMI_PROTOCOL_ID_BASE); @@ -108,13 +108,26 @@ ArmScmiDxeEntryPoint ( =20 ASSERT (NumProtocols !=3D 0); =20 + SupportedListSize =3D (NumProtocols * sizeof (*SupportedList)); + + Status =3D 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 =3D BaseProtocol->DiscoverListProtocols ( - BaseProtocol, - &SupportedListSize, - SupportedList - ); + BaseProtocol, + &SupportedListSize, + SupportedList + ); if (EFI_ERROR (Status)) { + gBS->FreePool (SupportedList); ASSERT (FALSE); return Status; } @@ -134,5 +147,7 @@ ArmScmiDxeEntryPoint ( } } =20 + gBS->FreePool (SupportedList); + return EFI_SUCCESS; } diff --git a/ArmPkg/Drivers/ArmScmiDxe/ScmiDxe.h b/ArmPkg/Drivers/ArmScmiDx= e/ScmiDxe.h index 222e54f4dca558d9b1fedddf3f96fd977898c7b2..c9a9072579e32c06cc231d388fb= 3f2fe8d37eb21 100644 --- a/ArmPkg/Drivers/ArmScmiDxe/ScmiDxe.h +++ b/ArmPkg/Drivers/ArmScmiDxe/ScmiDxe.h @@ -19,7 +19,6 @@ =20 #include "ScmiPrivate.h" =20 -#define MAX_PROTOCOLS 6 #define MAX_VENDOR_LEN SCMI_MAX_STR_LEN =20 /** Pointer to protocol initialization function. --=20 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)' _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel