From nobody Fri Apr 19 00:01:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+51335+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+51335+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1574858244; cv=none; d=zohomail.com; s=zohoarc; b=RMnOvB3v/aAYFXY1bFp0B7dfwoFHA+0wGbnkIBs6cxolTR1HOiqebH0onWGFX6T6XE0WQMMvmsndD1E8LXVeBQ77sJJzL9nZS8QSKRUVd+nM4NULynja9U1l9OrLdtdbEFIIiYL51AyF7VzlrNblgHqxBIdw1aHKzQV/lBY4Y3o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1574858244; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=Fc6GLOtdJD5bg46HoGvR8DaR/9Hoi0iYRNag7z8rRzI=; b=FLVMh9fiVuc32KhW8sJP4BqZH4OuugwsQUdnQSpY12HxReK0LyMXFARZ6GUB7BujT3iAcFNsLxOZwoU9dTY/xhIkKSR+XpecFLTQsrHjJZV7GkSsrOAjoCui+PKE/73bG0mUsqEis6vWu9RkDAl7p7nwmCaBgDR148Rf1rlrseo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+51335+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 15748582449697.6127827445627645; Wed, 27 Nov 2019 04:37:24 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id aaaaYY1788612xaaaaaaaaaa; Wed, 27 Nov 2019 04:37:24 -0800 X-Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by mx.groups.io with SMTP id smtpd.web12.5471.1574858243138380965 for ; Wed, 27 Nov 2019 04:37:23 -0800 X-Received: by mail-wr1-f67.google.com with SMTP id c14so1877476wrn.7 for ; Wed, 27 Nov 2019 04:37:22 -0800 (PST) X-Gm-Message-State: aaaaaaaaaaaaaaaaaaaaaaaax1787277AA= X-Google-Smtp-Source: APXvYqyal+yi0UI4ZvP8HXZChIzONk2uA3La9LBOZNWNdfwix3Pp2KovTSUPwPbTyiUqa7Zg8JmrDA== X-Received: by 2002:adf:b746:: with SMTP id n6mr42104658wre.65.1574858241368; Wed, 27 Nov 2019 04:37:21 -0800 (PST) X-Received: from localhost.localdomain ([84.203.37.1]) by smtp.gmail.com with ESMTPSA id p9sm18847833wrs.55.2019.11.27.04.37.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Nov 2019 04:37:20 -0800 (PST) From: "Pete Batard" To: devel@edk2.groups.io Cc: ard.biesheuvel@linaro.org, leif.lindholm@linaro.org, philmd@redhat.com, samer.el-haj-mahmoud@arm.com, andrey.warkentin@gmail.com Subject: [edk2-devel] [edk2-platforms][PATCH 1/5] Silicon/Bcm283x: Clean up Bcm2836.h header Date: Wed, 27 Nov 2019 12:37:02 +0000 Message-Id: <20191127123706.4604-2-pete@akeo.ie> In-Reply-To: <20191127123706.4604-1-pete@akeo.ie> References: <20191127123706.4604-1-pete@akeo.ie> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pete@akeo.ie Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1574858244; bh=K4RJt4T9/pDlX9bJoDRV9cPjCh6AVlwRJRrTNr18xKQ=; h=Cc:Date:From:Reply-To:Subject:To; b=rqxDnQjZ2+Px9CEVkZlNYwJnv3m/NBsEtQyh+wRfCBNqw+sS5HTW8VOKAz+DDx+RRHH oITP/n4YxOVWk3duYlCZx+Xu7+7X94J/QduWz5ysiFU2WaXPVS5LvG2kY3F4TStvehjcd x4oQhURcswXF/vQ/Qg5KFmL6rdBJOBa/I9M= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Add missing RNG registers, prefer reusing shorter define's instead of PCDs and clean up spacing. Signed-off-by: Pete Batard --- Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h | 23 +++++++++= +++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h b/= Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h index 72c8e9dc4b14..744c7ac3b9f4 100644 --- a/Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h +++ b/Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h @@ -24,8 +24,7 @@ =20 /* watchdog constants */ #define BCM2836_WDOG_OFFSET 0x00100000 -#define BCM2836_WDOG_BASE_ADDRESS (FixedPcdGet64= (PcdBcm283xRegistersAddress) \ - + BCM2836_WDOG= _OFFSET) +#define BCM2836_WDOG_BASE_ADDRESS (BCM2836_SOC_R= EGISTERS + BCM2836_WDOG_OFFSET) #define BCM2836_WDOG_PASSWORD 0x5a000000 #define BCM2836_WDOG_RSTC_OFFSET 0x0000001c #define BCM2836_WDOG_WDOG_OFFSET 0x00000024 @@ -34,8 +33,7 @@ =20 /* mailbox interface constants */ #define BCM2836_MBOX_OFFSET 0x0000b880 -#define BCM2836_MBOX_BASE_ADDRESS (FixedPcdGet64= (PcdBcm283xRegistersAddress) \ - + BCM2836_MBOX= _OFFSET) +#define BCM2836_MBOX_BASE_ADDRESS (BCM2836_SOC_R= EGISTERS + BCM2836_MBOX_OFFSET) #define BCM2836_MBOX_READ_OFFSET 0x00000000 #define BCM2836_MBOX_STATUS_OFFSET 0x00000018 #define BCM2836_MBOX_CONFIG_OFFSET 0x0000001c @@ -51,12 +49,19 @@ #define BCM2836_INTC_TIMER_PENDING_OFFSET 0x00000060 =20 /* random number generator */ -#define RNG_BASE_ADDRESS (BCM2836_SOC_REGISTERS + 0x00104000) +#define BCM2836_RNG_OFFSET 0x00104000 +#define RNG_BASE_ADDRESS (BCM2836_SOC_R= EGISTERS + BCM2836_RNG_OFFSET) =20 -#define RNG_CTRL (RNG_BASE_ADDRESS + 0x0) -#define RNG_STATUS (RNG_BASE_ADDRESS + 0x4) -#define RNG_DATA (RNG_BASE_ADDRESS + 0x8) +#define RNG_CTRL (RNG_BASE_ADDR= ESS + 0x0) +#define RNG_STATUS (RNG_BASE_ADDR= ESS + 0x4) +#define RNG_DATA (RNG_BASE_ADDR= ESS + 0x8) +#define RNG_BIT_COUNT (RNG_BASE_ADDR= ESS + 0xc) +#define RNG_BIT_COUNT_THRESHOLD (RNG_BASE_ADDR= ESS + 0x10) +#define RNG_INT_STATUS (RNG_BASE_ADDR= ESS + 0x18) +#define RNG_INT_ENABLE (RNG_BASE_ADDR= ESS + 0x1c) +#define RNG_FIFO_DATA (RNG_BASE_ADDR= ESS + 0x20) +#define RNG_FIFO_COUNT (RNG_BASE_ADDR= ESS + 0x24) =20 -#define RNG_CTRL_ENABLE 0x1 +#define RNG_CTRL_ENABLE 0x1 =20 #endif /*__BCM2836_H__ */ --=20 2.21.0.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#51335): https://edk2.groups.io/g/devel/message/51335 Mute This Topic: https://groups.io/mt/62504739/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri Apr 19 00:01:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+51336+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+51336+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1574858245; cv=none; d=zohomail.com; s=zohoarc; b=WqSSkMM1mDya5AG0wFBwptcCLoDZ8z1MoGsCrGc1fq2d5z6hTVNiHexDScGtVAm5xCyzi/CaIRzpdmwVOetC/hds3i+twtWDUwbYwLAsZEBdQTpvXgTfH0Tx7quW1Y0ObjR7VWMcJoUgu4ABe6MLvRDMXDhTkLqEacyFNwCNTko= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1574858245; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=rOKjgO7/pO+F3RIZ/4i/RO0MaajWOS0RV0sGlS21zY4=; b=nLdogSIdBUHQ4FkWB8xk8ojB5LFkpgrQhxNiQVxbucsUhLDlq8vk7BK9UgT8Y5Wc7CiGSOU0KPRkoMXb/bMrAyIqyR42/16YSRsErXYJ0KqfPNCnOnA9XYRLRnqgwtCg3KkVhqltVq1FMaqIlb7jJmzmJKMPVx14qAJSHQ6tg9I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+51336+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1574858245936377.51856434476906; Wed, 27 Nov 2019 04:37:25 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id aaaaYY1788612xaaaaaaaaaa; Wed, 27 Nov 2019 04:37:25 -0800 X-Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by mx.groups.io with SMTP id smtpd.web12.5472.1574858244631684979 for ; Wed, 27 Nov 2019 04:37:24 -0800 X-Received: by mail-wm1-f68.google.com with SMTP id p17so1408445wma.1 for ; Wed, 27 Nov 2019 04:37:24 -0800 (PST) X-Gm-Message-State: aaaaaaaaaaaaaaaaaaaaaaaax1787277AA= X-Google-Smtp-Source: APXvYqz1J7YD1Tsqdb0jIS8tvWDVemDkimkA9YzUXJhSY09jX7WqivML5RuIjl603dNVtVqTlT60MQ== X-Received: by 2002:a1c:2e09:: with SMTP id u9mr4111508wmu.108.1574858242868; Wed, 27 Nov 2019 04:37:22 -0800 (PST) X-Received: from localhost.localdomain ([84.203.37.1]) by smtp.gmail.com with ESMTPSA id p9sm18847833wrs.55.2019.11.27.04.37.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Nov 2019 04:37:22 -0800 (PST) From: "Pete Batard" To: devel@edk2.groups.io Cc: ard.biesheuvel@linaro.org, leif.lindholm@linaro.org, philmd@redhat.com, samer.el-haj-mahmoud@arm.com, andrey.warkentin@gmail.com Subject: [edk2-devel] [edk2-platforms][PATCH 2/5] Silicon/Bcm283x: Add FIFO mode for RNG Date: Wed, 27 Nov 2019 12:37:03 +0000 Message-Id: <20191127123706.4604-3-pete@akeo.ie> In-Reply-To: <20191127123706.4604-1-pete@akeo.ie> References: <20191127123706.4604-1-pete@akeo.ie> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pete@akeo.ie Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1574858245; bh=nfFnxLMN7C1p8gpaHREd0umqJvVHYnb8oQMVZtgnP8Y=; h=Cc:Date:From:Reply-To:Subject:To; b=ZhTpQRLVzT2VYWIuVHnKYOtbubM/XCasTTsza3wrvVhN98HqfEzPe0imgoavVu6BuHh naSsXUQQJbmudR4KhOTk1NipR0ytm30m+ImNHQgBlydlMrBQBBuF+ROUU9csjB5g8nZYb ZNUQJI/tSNoUO5wBuOCw5ROm3y3v4xbZkUw= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" The Bcm283x Random Number Generator does not work in regular mode on the Bcm2711 powered Raspberry Pi 4. It does however work when using FIFO mode. So we add this new mode, which is governed by the use of the new PcdBcm283xRngUseFifo boolean PCD. Note that just as a Pi 4 doesn't seem to support regular mode, a Pi 3 doesn't seem to support FIFO mode, which is why we can't switch to simply using FIFO mode for both platforms. We also fix the register to which RNG_WARMUP_COUNT is written, which was incorrect. Signed-off-by: Pete Batard --- Silicon/Broadcom/Bcm283x/Bcm283x.dec | 1 + Silicon/Broadcom/Bcm283x/Drivers/RngDxe/RngDxe.c | 96 +++++++++++++++---= -- Silicon/Broadcom/Bcm283x/Drivers/RngDxe/RngDxe.inf | 2 + 3 files changed, 74 insertions(+), 25 deletions(-) diff --git a/Silicon/Broadcom/Bcm283x/Bcm283x.dec b/Silicon/Broadcom/Bcm283= x/Bcm283x.dec index 5b839b00d286..4a9be7b18c97 100644 --- a/Silicon/Broadcom/Bcm283x/Bcm283x.dec +++ b/Silicon/Broadcom/Bcm283x/Bcm283x.dec @@ -21,3 +21,4 @@ [Guids] =20 [PcdsFixedAtBuild.common] gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress|0x0|UINT32|0x00000001 + gBcm283xTokenSpaceGuid.PcdBcm283xRngUseFifo|0x0|BOOLEAN|0x00000002 diff --git a/Silicon/Broadcom/Bcm283x/Drivers/RngDxe/RngDxe.c b/Silicon/Bro= adcom/Bcm283x/Drivers/RngDxe/RngDxe.c index 722815d32f06..462a21a6f3c3 100644 --- a/Silicon/Broadcom/Bcm283x/Drivers/RngDxe/RngDxe.c +++ b/Silicon/Broadcom/Bcm283x/Drivers/RngDxe/RngDxe.c @@ -2,6 +2,7 @@ =20 This driver produces an EFI_RNG_PROTOCOL instance for the Broadcom 2836 = RNG =20 + Copyright (C) 2019, Pete Batard Copyright (C) 2019, Linaro Ltd. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent @@ -12,6 +13,8 @@ #include #include #include +#include +#include #include =20 #include @@ -20,6 +23,8 @@ =20 #define RNG_WARMUP_COUNT 0x40000 #define RNG_MAX_RETRIES 0x100 // arbitrary upper bound +#define RNG_FIFO_NUMVAL_MASK 0xff +#define RNG_STATUS_NUMVAL_SHIFT 24 =20 /** Returns information about the random number generation implementation. @@ -84,6 +89,54 @@ Bcm2836RngGetInfo ( return EFI_SUCCESS; } =20 +/** + Read a single random value, in either FIFO or regular mode. + + @param[in] Val A pointer to the 32-bit word that is= to + be filled with a random value. + + @retval EFI_SUCCESS A random value was successfully read. + @retval EFI_NOT_READY The number of retries elapsed before= a + random value was generated. + +**/ +STATIC +EFI_STATUS +EFIAPI +Bcm2836RngReadValue ( + IN OUT UINT32 *Val +) +{ + UINT32 Avail; + UINT32 i; + BOOLEAN UseFifo =3D FixedPcdGetBool (PcdBcm283xRngUseFifo); + + ASSERT (Val !=3D NULL); + + Avail =3D UseFifo ? + (MmioRead32 (RNG_FIFO_COUNT) & RNG_FIFO_NUMVAL_MASK) : + (MmioRead32 (RNG_STATUS) >> RNG_STATUS_NUMVAL_SHIFT); + + // + // If we don't have a value ready, wait 1 us and retry. + // + for (i =3D 0; Avail < 1 && i < RNG_MAX_RETRIES; i++) { + MicroSecondDelay (1); + Avail =3D UseFifo ? + (MmioRead32 (RNG_FIFO_COUNT) & RNG_FIFO_NUMVAL_MASK) : + (MmioRead32 (RNG_STATUS) >> RNG_STATUS_NUMVAL_SHIFT); + } + if (Avail < 1) { + return EFI_NOT_READY; + } + + *Val =3D UseFifo ? + MmioRead32 (RNG_FIFO_DATA): + MmioRead32 (RNG_DATA); + + return EFI_SUCCESS; +} + /** Produces and returns an RNG value using either the default or specified = RNG algorithm. @@ -123,9 +176,8 @@ Bcm2836RngGetRNG ( OUT UINT8 *RNGValue ) { - UINT32 Val; - UINT32 Num; - UINT32 Retries; + EFI_STATUS Status; + UINT32 Val; =20 if (This =3D=3D NULL || RNGValueLength =3D=3D 0 || RNGValue =3D=3D NULL)= { return EFI_INVALID_PARAMETER; @@ -139,30 +191,24 @@ Bcm2836RngGetRNG ( return EFI_UNSUPPORTED; } =20 - while (RNGValueLength > 0) { - Retries =3D RNG_MAX_RETRIES; - do { - Num =3D MmioRead32 (RNG_STATUS) >> 24; - MemoryFence (); - } while (!Num && Retries-- > 0); - - if (!Num) { - return EFI_DEVICE_ERROR; + while (RNGValueLength >=3D sizeof (UINT32)) { + Status =3D Bcm2836RngReadValue (&Val); + if (EFI_ERROR (Status)) { + return Status; } + WriteUnaligned32 ((VOID *)RNGValue, Val); + RNGValue +=3D sizeof (UINT32); + RNGValueLength -=3D sizeof (UINT32); + } =20 - while (RNGValueLength >=3D sizeof (UINT32) && Num > 0) { - WriteUnaligned32 ((VOID *)RNGValue, MmioRead32 (RNG_DATA)); - RNGValue +=3D sizeof (UINT32); - RNGValueLength -=3D sizeof (UINT32); - Num--; + if (RNGValueLength > 0) { + Status =3D Bcm2836RngReadValue (&Val); + if (EFI_ERROR (Status)) { + return Status; } - - if (RNGValueLength > 0 && Num > 0) { - Val =3D MmioRead32 (RNG_DATA); - while (RNGValueLength--) { - *RNGValue++ =3D (UINT8)Val; - Val >>=3D 8; - } + while (RNGValueLength--) { + *RNGValue++ =3D (UINT8)Val; + Val >>=3D 8; } } return EFI_SUCCESS; @@ -190,7 +236,7 @@ Bcm2836RngEntryPoint ( NULL); ASSERT_EFI_ERROR (Status); =20 - MmioWrite32 (RNG_STATUS, RNG_WARMUP_COUNT); + MmioWrite32 (RNG_BIT_COUNT_THRESHOLD, RNG_WARMUP_COUNT); MmioWrite32 (RNG_CTRL, RNG_CTRL_ENABLE); =20 return EFI_SUCCESS; diff --git a/Silicon/Broadcom/Bcm283x/Drivers/RngDxe/RngDxe.inf b/Silicon/B= roadcom/Bcm283x/Drivers/RngDxe/RngDxe.inf index 8eb90de85cfd..31415231ae0b 100644 --- a/Silicon/Broadcom/Bcm283x/Drivers/RngDxe/RngDxe.inf +++ b/Silicon/Broadcom/Bcm283x/Drivers/RngDxe/RngDxe.inf @@ -28,6 +28,7 @@ [LibraryClasses] DebugLib IoLib PcdLib + TimerLib UefiBootServicesTableLib UefiDriverEntryPoint =20 @@ -39,6 +40,7 @@ [Guids] =20 [FixedPcd] gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress + gBcm283xTokenSpaceGuid.PcdBcm283xRngUseFifo =20 [Depex] TRUE --=20 2.21.0.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#51336): https://edk2.groups.io/g/devel/message/51336 Mute This Topic: https://groups.io/mt/62504740/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri Apr 19 00:01:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+51337+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+51337+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1574858247; cv=none; d=zohomail.com; s=zohoarc; b=bdTWVbaDTMoEU6CYfkGNCZF+8KCOrHdbZX3HGcI8VEsyuIFD8OgPlin5HyiLF/lZPhPMQkIPFj5zM1yGq7Glqk9AukEFAi37F6DKOmQeiIBqAAi6GawPDT/d6TeJhVuJGFh4ZI1zTJdx/5H9exoRf72OS14A7F3lfl8CLSOqRP0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1574858247; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=TIvSqTdvT7Pa6k6b7TEa2uLWrISLlnDLHMjG2RXx2Sc=; b=XtJqW0WigxpwAgaox2qtX1VVU/u6WtsbUB9mGTTET8TWTQmTznTZxARS9Ge0vgwkuCUbfyPoycCkeWWYQqNQSEEExYyCu7yMeIi2vN2nWpszCw3LvaGLWQjGXCppnQsx8e0Jx1s5TyOXADR02OTTDSjekWXb4mprpQ11SfM3bmc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+51337+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1574858247495410.2133253025394; Wed, 27 Nov 2019 04:37:27 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id aaaaYY1788612xaaaaaaaaaa; Wed, 27 Nov 2019 04:37:27 -0800 X-Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by mx.groups.io with SMTP id smtpd.web11.5378.1574858246105427849 for ; Wed, 27 Nov 2019 04:37:26 -0800 X-Received: by mail-wm1-f66.google.com with SMTP id p17so1408583wma.1 for ; Wed, 27 Nov 2019 04:37:25 -0800 (PST) X-Gm-Message-State: aaaaaaaaaaaaaaaaaaaaaaaax1787277AA= X-Google-Smtp-Source: APXvYqxem01r+GxELYeZk6o0wKk5aljfmaezc2ftdjEWVd5fKiAJa670J70MNxCSwByrw0C9IO1mpQ== X-Received: by 2002:a1c:a743:: with SMTP id q64mr4201929wme.44.1574858244304; Wed, 27 Nov 2019 04:37:24 -0800 (PST) X-Received: from localhost.localdomain ([84.203.37.1]) by smtp.gmail.com with ESMTPSA id p9sm18847833wrs.55.2019.11.27.04.37.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Nov 2019 04:37:23 -0800 (PST) From: "Pete Batard" To: devel@edk2.groups.io Cc: ard.biesheuvel@linaro.org, leif.lindholm@linaro.org, philmd@redhat.com, samer.el-haj-mahmoud@arm.com, andrey.warkentin@gmail.com Subject: [edk2-devel] [edk2-platforms][PATCH 3/5] Platform/RPi/MmcDxe: Factorize SCR call and clean up MMC init Date: Wed, 27 Nov 2019 12:37:04 +0000 Message-Id: <20191127123706.4604-4-pete@akeo.ie> In-Reply-To: <20191127123706.4604-1-pete@akeo.ie> References: <20191127123706.4604-1-pete@akeo.ie> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pete@akeo.ie Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1574858247; bh=c0pgxiWN5jUFdLxEeZivt2s2W3kWnthrYcuXFG19+ro=; h=Cc:Date:From:Reply-To:Subject:To; b=iJyTh2Egyo1xfJQ0IRdA/k8gXR7QBOmCLhVTUJKceUIxUgtkc1zBotinio37T6uBSm1 i7m7MP2VNRWyhrNwhgAmseCVobgEdpRn9BWAmeQN+XHiz1FrSx71Xw37MkaqhEFcVlDb9 OZkFO//cxcQDQE4M8SZx786FsECo8SBmDbQ= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Andrei Warkentin This is mostly a maintainability improvement for the InitializeSdMmcDevice () call achieved by factorizing the code related to SCR execution into a new SdExecuteScr () call. Signed-off-by: Pete Batard --- Platform/RaspberryPi/Drivers/MmcDxe/MmcIdentification.c | 105 ++++++++++++= -------- 1 file changed, 62 insertions(+), 43 deletions(-) diff --git a/Platform/RaspberryPi/Drivers/MmcDxe/MmcIdentification.c b/Plat= form/RaspberryPi/Drivers/MmcDxe/MmcIdentification.c index 4ee5c5ca6fb2..34a97e954220 100644 --- a/Platform/RaspberryPi/Drivers/MmcDxe/MmcIdentification.c +++ b/Platform/RaspberryPi/Drivers/MmcDxe/MmcIdentification.c @@ -1,5 +1,6 @@ /** @file * + * Copyright (c) 2019, Andrei Warkentin * Copyright (c) 2011-2015, ARM Limited. All rights reserved. * * SPDX-License-Identifier: BSD-2-Clause-Patent @@ -567,6 +568,48 @@ SdSetSpeed ( return EFI_SUCCESS; } =20 +STATIC +EFI_STATUS +SdExecuteScr ( + IN MMC_HOST_INSTANCE *MmcHostInstance, + OUT SCR *Scr + ) +{ + EFI_STATUS Status; + UINT32 Response[4]; + EFI_MMC_HOST_PROTOCOL *MmcHost =3D MmcHostInstance->MmcHost; + + Status =3D MmcHost->SendCommand (MmcHost, MMC_CMD55, + MmcHostInstance->CardInfo.RCA << 16); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a (MMC_CMD55): Error and Status =3D %r\n", __FU= NCTION__, Status)); + return Status; + } + Status =3D MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_R1, Resp= onse); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a (MMC_CMD55): Error and Status =3D %r\n", __FU= NCTION__, Status)); + return Status; + } + if ((Response[0] & MMC_STATUS_APP_CMD) =3D=3D 0) { + return EFI_SUCCESS; + } + + /* SCR */ + Status =3D MmcHost->SendCommand (MmcHost, MMC_ACMD51, 0); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a(MMC_ACMD51): Error and Status =3D %r\n", __fu= nc__, Status)); + return Status; + } + + Status =3D MmcHost->ReadBlockData (MmcHost, 0, 8, (VOID *) Scr); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a(MMC_ACMD51): ReadBlockData Error and Status = =3D %r\n", __func__, Status)); + return Status; + } + + return EFI_SUCCESS; +} + STATIC EFI_STATUS InitializeSdMmcDevice ( @@ -574,7 +617,6 @@ InitializeSdMmcDevice ( ) { UINT32 Response[4]; - UINT32 Buffer[128]; UINTN BlockSize; UINTN CardSize; UINTN NumBlocks; @@ -621,58 +663,35 @@ InitializeSdMmcDevice ( return Status; } =20 - Status =3D MmcHost->SendCommand (MmcHost, MMC_CMD55, - MmcHostInstance->CardInfo.RCA << 16); + Status =3D SdExecuteScr (MmcHostInstance, &Scr); if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a (MMC_CMD55): Error and Status =3D %r\n", __FU= NCTION__, Status)); - return Status; - } - Status =3D MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_R1, Resp= onse); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a (MMC_CMD55): Error and Status =3D %r\n", __FU= NCTION__, Status)); - return Status; - } - if ((Response[0] & MMC_STATUS_APP_CMD) =3D=3D 0) { - return EFI_SUCCESS; + return Status; } =20 - /* SCR */ - Status =3D MmcHost->SendCommand (MmcHost, MMC_ACMD51, 0); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a(MMC_ACMD51): Error and Status =3D %r\n", __fu= nc__, Status)); - return Status; - } else { - Status =3D MmcHost->ReadBlockData (MmcHost, 0, 8, Buffer); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a(MMC_ACMD51): ReadBlockData Error and Status= =3D %r\n", __func__, Status)); - return Status; - } - CopyMem (&Scr, Buffer, 8); - if (Scr.SD_SPEC =3D=3D 2) { - if (Scr.SD_SPEC3 =3D=3D 1) { - if (Scr.SD_SPEC4 =3D=3D 1) { - DEBUG ((DEBUG_INFO, "Found SD Card for Spec Version 4.xx\n")); - } else { - DEBUG ((DEBUG_INFO, "Found SD Card for Spec Version 3.0x\n")); - } + if (Scr.SD_SPEC =3D=3D 2) { + if (Scr.SD_SPEC3 =3D=3D 1) { + if (Scr.SD_SPEC4 =3D=3D 1) { + DEBUG ((DEBUG_INFO, "Found SD Card for Spec Version 4.xx\n")); } else { - if (Scr.SD_SPEC4 =3D=3D 0) { - DEBUG ((DEBUG_INFO, "Found SD Card for Spec Version 2.0\n")); - } else { - DEBUG ((DEBUG_ERROR, "Found invalid SD Card\n")); - } + DEBUG ((DEBUG_INFO, "Found SD Card for Spec Version 3.0x\n")); } } else { - if ((Scr.SD_SPEC3 =3D=3D 0) && (Scr.SD_SPEC4 =3D=3D 0)) { - if (Scr.SD_SPEC =3D=3D 1) { - DEBUG ((DEBUG_INFO, "Found SD Card for Spec Version 1.10\n")); - } else { - DEBUG ((DEBUG_INFO, "Found SD Card for Spec Version 1.0\n")); - } + if (Scr.SD_SPEC4 =3D=3D 0) { + DEBUG ((DEBUG_INFO, "Found SD Card for Spec Version 2.0\n")); } else { DEBUG ((DEBUG_ERROR, "Found invalid SD Card\n")); } } + } else { + if ((Scr.SD_SPEC3 =3D=3D 0) && (Scr.SD_SPEC4 =3D=3D 0)) { + if (Scr.SD_SPEC =3D=3D 1) { + DEBUG ((DEBUG_INFO, "Found SD Card for Spec Version 1.10\n")); + } else { + DEBUG ((DEBUG_INFO, "Found SD Card for Spec Version 1.0\n")); + } + } else { + DEBUG ((DEBUG_ERROR, "Found invalid SD Card\n")); + } } =20 Status =3D SdSetSpeed (MmcHostInstance, CccSwitch); --=20 2.21.0.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#51337): https://edk2.groups.io/g/devel/message/51337 Mute This Topic: https://groups.io/mt/62504742/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri Apr 19 00:01:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+51338+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+51338+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1574858250; cv=none; d=zohomail.com; s=zohoarc; b=gA4JaCSV18UWeZ8LsFQMuQ7vhKxWhhTNFCi5N05dtn5n46Gzni9YeoF7SI0C+ZI6ZNzrO1Ifg4gbrD6dxStDkkdNsPwx45MYoGKS0Is/tRC4EiHgZWHkCBnEK3yldXaZWzoW7kMZrAR2O1qEMXzQymNNNLxrernfXwS9dgc7sbU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1574858250; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=8otUfH6L9c9tjPhfaVindMGdYXyO5k/Peu0gdtpk9pU=; b=nqJ6v1a+xbuKnpcRRAFE+8ugk5K1Y8kyjZva4n8qMMOmJRgg5nsvzg9IUqpXptTRjnrIxFmSQgTYA57PDsODsiQRJ/olmlyF83tvpORQZRB/ZmF5ZbrvLVAzmmSl1IqTQMV8++XMdYY+E8Oi6jRyiuE9Ig01QJ8MAVF4Esz+5n8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+51338+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1574858250086208.6480268548272; Wed, 27 Nov 2019 04:37:30 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id aaaaYY1788612xaaaaaaaaaa; Wed, 27 Nov 2019 04:37:29 -0800 X-Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by mx.groups.io with SMTP id smtpd.web12.5474.1574858248339824496 for ; Wed, 27 Nov 2019 04:37:28 -0800 X-Received: by mail-wr1-f67.google.com with SMTP id w9so26549184wrr.0 for ; Wed, 27 Nov 2019 04:37:28 -0800 (PST) X-Gm-Message-State: aaaaaaaaaaaaaaaaaaaaaaaax1787277AA= X-Google-Smtp-Source: APXvYqyfzUFqyJ0C0f4aMwAoMcRMrG/lmx9Ra03IY9qlAtFn52Fu3AuShMzb7XjVc23pHBiZafblbQ== X-Received: by 2002:adf:f282:: with SMTP id k2mr20210985wro.387.1574858246424; Wed, 27 Nov 2019 04:37:26 -0800 (PST) X-Received: from localhost.localdomain ([84.203.37.1]) by smtp.gmail.com with ESMTPSA id p9sm18847833wrs.55.2019.11.27.04.37.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Nov 2019 04:37:25 -0800 (PST) From: "Pete Batard" To: devel@edk2.groups.io Cc: ard.biesheuvel@linaro.org, leif.lindholm@linaro.org, philmd@redhat.com, samer.el-haj-mahmoud@arm.com, andrey.warkentin@gmail.com Subject: [edk2-devel] [edk2-platforms][PATCH 4/5] Platform/RPi/MmcDxe: Improve MMC driver stability Date: Wed, 27 Nov 2019 12:37:05 +0000 Message-Id: <20191127123706.4604-5-pete@akeo.ie> In-Reply-To: <20191127123706.4604-1-pete@akeo.ie> References: <20191127123706.4604-1-pete@akeo.ie> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pete@akeo.ie Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1574858249; bh=VNMZNhvM5bMk7uyEbcsBPvrI48S1vUg6uTAbW4OcBOk=; h=Cc:Date:From:Reply-To:Subject:To; b=BtSPfDF14OfSAfjGi60+tQ3BLgQgA4uW2BBPC5lAafTxnLbzWTf21ocKHLsWF5hyyjF FD1ooINRyb1yCk3nyxkq2FIK8DaG+AOvkjMocyr8eJZTFXqtkLxi8T5TFvFuybV9rHjNy UulEnJLesol4TLugSH9FiE8jqicU9aZBS9c= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Andrei Warkentin For reasons that aren't entirely understood, SCR reads can randomly fail on the Raspberry Pi 4. It can be on the first boot or during subsequent reboots. To alleviate this, and improve the overall behavior of the code, we modify CheckCardsCallback () to retry InitializeMmcDevice () in case of failure. Signed-off-by: Pete Batard --- Platform/RaspberryPi/Drivers/MmcDxe/Mmc.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Platform/RaspberryPi/Drivers/MmcDxe/Mmc.c b/Platform/Raspberry= Pi/Drivers/MmcDxe/Mmc.c index c3c7279e4707..f6c4cc7bc3a3 100644 --- a/Platform/RaspberryPi/Drivers/MmcDxe/Mmc.c +++ b/Platform/RaspberryPi/Drivers/MmcDxe/Mmc.c @@ -2,6 +2,7 @@ * * Main file of the MMC Dxe driver. The driver entrypoint is defined into= this file. * + * Copyright (c) 2019, Andrei Warkentin * Copyright (c) 2011-2013, ARM Limited. All rights reserved. * * SPDX-License-Identifier: BSD-2-Clause-Patent @@ -367,7 +368,11 @@ CheckCardsCallback ( MmcHostInstance->Initialized =3D !MmcHostInstance->Initialized; =20 if (MmcHostInstance->BlockIo.Media->MediaPresent) { - InitializeMmcDevice (MmcHostInstance); + Status =3D InitializeMmcDevice (MmcHostInstance); + if (EFI_ERROR (Status)) { + MmcHostInstance->Initialized =3D !MmcHostInstance->Initialized; + continue; + } } =20 Status =3D gBS->ReinstallProtocolInterface ( --=20 2.21.0.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#51338): https://edk2.groups.io/g/devel/message/51338 Mute This Topic: https://groups.io/mt/62504744/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri Apr 19 00:01:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+51339+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+51339+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1574858251; cv=none; d=zohomail.com; s=zohoarc; b=YWunZRlN/i7ixftsChRttSRJlYpEoNcTGEh0NGjQy2/psVIVpdjHssKXq07gZ7kJmeVP/EvfVY4ndozhE7oX47GNfu/O8jfQlbb4lGK5Vc0v4RvNt7PLfG1fXcYRVFw0Bz6oGmDDgsxcxt1crBmYFrzIFqPUSN0FDXgX0W+V4MQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1574858251; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=7kND2kx6vB7J/73IX70xkqgRw+5hrhdzlG9NEGZ03vQ=; b=lZAksYfVaTRkuI4/v1ql6eTqIisHCKTZUYxnU+XMOliPUO4piQP/D0KOA0HfXULEBqi/C/eGWQpZt+yVCQyRjeB1Ay6Ci0LvkapkA8Ve0+M6FT+fXX1RsTOBtibSh3znIBhDWMgbctx/CXK9+Ta7DdKR/rIHX6YIveBWXNurRx0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+51339+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 157485825145760.502968701211216; Wed, 27 Nov 2019 04:37:31 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id aaaaYY1788612xaaaaaaaaaa; Wed, 27 Nov 2019 04:37:31 -0800 X-Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by mx.groups.io with SMTP id smtpd.web10.5435.1574858250144410117 for ; Wed, 27 Nov 2019 04:37:30 -0800 X-Received: by mail-wr1-f68.google.com with SMTP id z3so26476895wru.3 for ; Wed, 27 Nov 2019 04:37:29 -0800 (PST) X-Gm-Message-State: aaaaaaaaaaaaaaaaaaaaaaaax1787277AA= X-Google-Smtp-Source: APXvYqzQh1lj1aBmdy6KioOTBBryt+VS/JEvef3wPWWnL9QoayCYqUXyc1nRWuVTv38HPofSFVXPUA== X-Received: by 2002:adf:e3c1:: with SMTP id k1mr1660166wrm.151.1574858248384; Wed, 27 Nov 2019 04:37:28 -0800 (PST) X-Received: from localhost.localdomain ([84.203.37.1]) by smtp.gmail.com with ESMTPSA id p9sm18847833wrs.55.2019.11.27.04.37.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Nov 2019 04:37:27 -0800 (PST) From: "Pete Batard" To: devel@edk2.groups.io Cc: ard.biesheuvel@linaro.org, leif.lindholm@linaro.org, philmd@redhat.com, samer.el-haj-mahmoud@arm.com, andrey.warkentin@gmail.com Subject: [edk2-devel] [edk2-platforms][PATCH 5/5] Platform/RPi: Set SD routing according to model Date: Wed, 27 Nov 2019 12:37:06 +0000 Message-Id: <20191127123706.4604-6-pete@akeo.ie> In-Reply-To: <20191127123706.4604-1-pete@akeo.ie> References: <20191127123706.4604-1-pete@akeo.ie> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pete@akeo.ie Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1574858251; bh=H4Lyduu0ch+yyKX46zDl1658ZIudvJU5IV4OjAq1C0E=; h=Cc:Date:From:Reply-To:Subject:To; b=tXCSFgC5SpNQR3LUXeN8vYhv/Ms9M8CFyxhWpwd0EVOq3uaXce4ZRcIIvgBApMwrNm+ gQu9htYXq7CQNBLWHX9XJ5OgeFtLUy4FIo8GWmHqo45DtAD4F0T1i+9qWqBB0gK+3igen TQCD5mks6/GIQ9PfSVGmTKsZg5BpRP6UDTs= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Samer El-Haj-Mahmoud The Raspberry Pi 4 has a new SD controller. As a result we must handle SD routing according to the model, which we perform in the Config driver by using the GetModelFamily () call that was recently introduced. Signed-off-by: Pete Batard --- Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c | 137 ++++++++++++++---= --- 1 file changed, 96 insertions(+), 41 deletions(-) diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c b/Platform/= RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c index 98e58a560ed4..26bc92f28185 100644 --- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c +++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c @@ -1,6 +1,7 @@ /** @file * - * Copyright (c) 2018, Andrei Warkentin + * Copyright (c) 2019, ARM Limited. All rights reserved. + * Copyright (c) 2018 - 2019, Andrei Warkentin * * SPDX-License-Identifier: BSD-2-Clause-Patent * @@ -9,10 +10,12 @@ #include #include #include +#include #include #include #include #include +#include #include #include #include @@ -212,6 +215,7 @@ ApplyVariables ( UINT32 CpuClock =3D PcdGet32 (PcdCpuClock); UINT32 CustomCpuClock =3D PcdGet32 (PcdCustomCpuClock); UINT32 Rate =3D 0; + UINT32 ModelFamily =3D 0; =20 if (CpuClock !=3D 0) { if (CpuClock =3D=3D 2) { @@ -245,51 +249,102 @@ ApplyVariables ( DEBUG ((DEBUG_INFO, "Current CPU speed is %uHz\n", Rate)); } =20 - /* - * Switching two groups around, so disable both first. - * - * No, I've not seen a problem, but having a group be - * routed to two sets of pins seems like asking for trouble. - */ - GpioPinFuncSet (34, GPIO_FSEL_INPUT); - GpioPinFuncSet (35, GPIO_FSEL_INPUT); - GpioPinFuncSet (36, GPIO_FSEL_INPUT); - GpioPinFuncSet (37, GPIO_FSEL_INPUT); - GpioPinFuncSet (38, GPIO_FSEL_INPUT); - GpioPinFuncSet (39, GPIO_FSEL_INPUT); - GpioPinFuncSet (48, GPIO_FSEL_INPUT); - GpioPinFuncSet (49, GPIO_FSEL_INPUT); - GpioPinFuncSet (50, GPIO_FSEL_INPUT); - GpioPinFuncSet (51, GPIO_FSEL_INPUT); - GpioPinFuncSet (52, GPIO_FSEL_INPUT); - GpioPinFuncSet (53, GPIO_FSEL_INPUT); - if (PcdGet32 (PcdSdIsArasan)) { - DEBUG ((DEBUG_INFO, "Routing SD to Arasan\n")); - Gpio48Group =3D GPIO_FSEL_ALT3; + Status =3D mFwProtocol->GetModelFamily (&ModelFamily); + if (Status !=3D EFI_SUCCESS) { + DEBUG ((DEBUG_ERROR, "Couldn't get the Raspberry Pi model family: %r\n= ", Status)); + } else { + DEBUG ((DEBUG_INFO, "Current Raspberry Pi model family is 0x%x\n", Mod= elFamily)); + } + + + if (ModelFamily =3D=3D 3) { /* - * Route SDIO to SdHost. + * Pi 3: either Arasan or SdHost goes to SD card. + * + * Switching two groups around, so disable both first. + * + * No, I've not seen a problem, but having a group be + * routed to two sets of pins seems like asking for trouble. */ - Gpio34Group =3D GPIO_FSEL_ALT0; - } else { - DEBUG ((DEBUG_INFO, "Routing SD to SdHost\n")); - Gpio48Group =3D GPIO_FSEL_ALT0; + GpioPinFuncSet (34, GPIO_FSEL_INPUT); + GpioPinFuncSet (35, GPIO_FSEL_INPUT); + GpioPinFuncSet (36, GPIO_FSEL_INPUT); + GpioPinFuncSet (37, GPIO_FSEL_INPUT); + GpioPinFuncSet (38, GPIO_FSEL_INPUT); + GpioPinFuncSet (39, GPIO_FSEL_INPUT); + GpioPinFuncSet (48, GPIO_FSEL_INPUT); + GpioPinFuncSet (49, GPIO_FSEL_INPUT); + GpioPinFuncSet (50, GPIO_FSEL_INPUT); + GpioPinFuncSet (51, GPIO_FSEL_INPUT); + GpioPinFuncSet (52, GPIO_FSEL_INPUT); + GpioPinFuncSet (53, GPIO_FSEL_INPUT); + + if (PcdGet32 (PcdSdIsArasan)) { + DEBUG ((DEBUG_INFO, "Routing SD to Arasan\n")); + Gpio48Group =3D GPIO_FSEL_ALT3; + /* + * Route SDIO to SdHost. + */ + Gpio34Group =3D GPIO_FSEL_ALT0; + } else { + DEBUG ((DEBUG_INFO, "Routing SD to SdHost\n")); + Gpio48Group =3D GPIO_FSEL_ALT0; + /* + * Route SDIO to Arasan. + */ + Gpio34Group =3D GPIO_FSEL_ALT3; + } + GpioPinFuncSet (34, Gpio34Group); + GpioPinFuncSet (35, Gpio34Group); + GpioPinFuncSet (36, Gpio34Group); + GpioPinFuncSet (37, Gpio34Group); + GpioPinFuncSet (38, Gpio34Group); + GpioPinFuncSet (39, Gpio34Group); + GpioPinFuncSet (48, Gpio48Group); + GpioPinFuncSet (49, Gpio48Group); + GpioPinFuncSet (50, Gpio48Group); + GpioPinFuncSet (51, Gpio48Group); + GpioPinFuncSet (52, Gpio48Group); + GpioPinFuncSet (53, Gpio48Group); + + } else if (ModelFamily =3D=3D 4){ /* - * Route SDIO to Arasan. + * Pi 4: either Arasan or eMMC2 goes to SD card. */ - Gpio34Group =3D GPIO_FSEL_ALT3; + if (PcdGet32 (PcdSdIsArasan)) { + /* + * WiFi disabled. + */ + GpioPinFuncSet (34, GPIO_FSEL_INPUT); + GpioPinFuncSet (35, GPIO_FSEL_INPUT); + GpioPinFuncSet (36, GPIO_FSEL_INPUT); + GpioPinFuncSet (37, GPIO_FSEL_INPUT); + GpioPinFuncSet (38, GPIO_FSEL_INPUT); + GpioPinFuncSet (39, GPIO_FSEL_INPUT); + /* + * SD card pins go to Arasan. + */ + MmioWrite32((GPIO_BASE_ADDRESS + 0xD0), + MmioRead32(GPIO_BASE_ADDRESS + 0xD0) | 0x2); + } else { + /* + * SD card pins back to eMMC2. + */ + MmioWrite32((GPIO_BASE_ADDRESS + 0xD0), + MmioRead32(GPIO_BASE_ADDRESS + 0xD0) & ~0x2); + /* + * WiFi back to Arasan. + */ + GpioPinFuncSet (34, GPIO_FSEL_ALT3); + GpioPinFuncSet (35, GPIO_FSEL_ALT3); + GpioPinFuncSet (36, GPIO_FSEL_ALT3); + GpioPinFuncSet (37, GPIO_FSEL_ALT3); + GpioPinFuncSet (38, GPIO_FSEL_ALT3); + GpioPinFuncSet (39, GPIO_FSEL_ALT3); + } + } else { + DEBUG ((DEBUG_ERROR, "Model Family %d not supported...\n", ModelFamily= )); } - GpioPinFuncSet (34, Gpio34Group); - GpioPinFuncSet (35, Gpio34Group); - GpioPinFuncSet (36, Gpio34Group); - GpioPinFuncSet (37, Gpio34Group); - GpioPinFuncSet (38, Gpio34Group); - GpioPinFuncSet (39, Gpio34Group); - GpioPinFuncSet (48, Gpio48Group); - GpioPinFuncSet (49, Gpio48Group); - GpioPinFuncSet (50, Gpio48Group); - GpioPinFuncSet (51, Gpio48Group); - GpioPinFuncSet (52, Gpio48Group); - GpioPinFuncSet (53, Gpio48Group); =20 /* * JTAG pin JTAG sig GPIO Mode Header pin --=20 2.21.0.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#51339): https://edk2.groups.io/g/devel/message/51339 Mute This Topic: https://groups.io/mt/62504750/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-