From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 97503D801DE for ; Fri, 3 Nov 2023 02:53:35 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=XyNEihT71R3egHrivNTJSoUZrD2Bc11o74NyTxWt3aY=; c=relaxed/simple; d=groups.io; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Type:Content-Transfer-Encoding; s=20140610; t=1698980014; v=1; b=L/dAqWwsqmMwrHDIUj6SwwXfbYTu0C+cbSFYjSiXL0JsavTeC4LJXq18aws+p0WYa5rZwf2c fAK1dU3IQq+k8nrvrYdVgynmBxjIg1FojmGRkOKewM9esKNoriLh+kQHUH/ljWHzJvNBJPjmL2u b/Jh/4Pbo37Qm7A3lvqnYhrA= X-Received: by 127.0.0.2 with SMTP id TzJKYY7687511x5eXNE6FpQc; Thu, 02 Nov 2023 19:53:34 -0700 X-Received: from ex01.ufhost.com (ex01.ufhost.com [61.152.239.75]) by mx.groups.io with SMTP id smtpd.web10.19652.1698980013432989963 for ; Thu, 02 Nov 2023 19:53:33 -0700 X-Received: from EXMBX165.cuchost.com (unknown [175.102.18.54]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "EXMBX165", Issuer "EXMBX165" (not verified)) by ex01.ufhost.com (Postfix) with ESMTP id 277C724E20A; Fri, 3 Nov 2023 10:53:32 +0800 (CST) X-Received: from EXMBX073.cuchost.com (172.16.6.83) by EXMBX165.cuchost.com (172.16.6.75) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Fri, 3 Nov 2023 10:53:32 +0800 X-Received: from localhost.localdomain (161.142.158.84) by EXMBX073.cuchost.com (172.16.6.83) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Fri, 3 Nov 2023 10:53:26 +0800 From: "John Chew" To: CC: John Chew , Sunil V L , Leif Lindholm , "Ard Biesheuvel" , Michael D Kinney , Li Yong Subject: [edk2-devel] [PATCH v3 5/5] DesignWare/DwEmmcDxe: Force DMA buffer to allocate below 4GB Date: Fri, 3 Nov 2023 10:51:31 +0800 Message-ID: <20231103025131.1643-6-yuinyee.chew@starfivetech.com> In-Reply-To: <20231103025131.1643-1-yuinyee.chew@starfivetech.com> References: <20231103025131.1643-1-yuinyee.chew@starfivetech.com> MIME-Version: 1.0 X-Originating-IP: [161.142.158.84] X-ClientProxiedBy: EXCAS062.cuchost.com (172.16.6.22) To EXMBX073.cuchost.com (172.16.6.83) X-YovoleRuleAgent: yovoleflag Precedence: Bulk List-Subscribe: List-Help: 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,yuinyee.chew@starfivetech.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: Padrc5NOSOskrJIUVcygqTkux7686176AA= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b="L/dAqWws"; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io; dmarc=none The buffer address passed into the read/write block function sometimes larger than 4GB. This driver only support 32-bit DMA addressing. MMC timeout will occur if DMA buffer is allocated in 64-bit address. Cc: Sunil V L Cc: Leif Lindholm Cc: Ard Biesheuvel Cc: Michael D Kinney Cc: Li Yong Signed-off-by: John Chew --- Silicon/Synopsys/DesignWare/Drivers/DwEmmcDxe/DwEmmcDxe.c | 79 +++++++++++= +++++---- 1 file changed, 64 insertions(+), 15 deletions(-) diff --git a/Silicon/Synopsys/DesignWare/Drivers/DwEmmcDxe/DwEmmcDxe.c b/Si= licon/Synopsys/DesignWare/Drivers/DwEmmcDxe/DwEmmcDxe.c index 39e4d994fcd4..8233639b0ce8 100644 --- a/Silicon/Synopsys/DesignWare/Drivers/DwEmmcDxe/DwEmmcDxe.c +++ b/Silicon/Synopsys/DesignWare/Drivers/DwEmmcDxe/DwEmmcDxe.c @@ -601,27 +601,57 @@ DwEmmcWaitDmaComplete ( return Status; } =20 +STATIC +UINT32 * +AllocateMemoryBelow4G ( + IN UINTN Size + ) +{ + UINTN Pages; + EFI_PHYSICAL_ADDRESS Address; + EFI_STATUS Status; + UINT32 *Buffer; + + Pages =3D EFI_SIZE_TO_PAGES (Size); + Address =3D 0xFFFFFFFF; + + Status =3D gBS->AllocatePages ( + AllocateMaxAddress, + EfiBootServicesData, + Pages, + &Address + ); + ASSERT_EFI_ERROR (Status); + + Buffer =3D (UINT32 *)(UINTN)Address; + ZeroMem (Buffer, Size); + + return Buffer; +} + EFI_STATUS DwEmmcReadBlockData ( - IN EFI_MMC_HOST_PROTOCOL *This, - IN EFI_LBA Lba, - IN UINTN Length, - IN UINT32* Buffer + IN EFI_MMC_HOST_PROTOCOL *This, + IN EFI_LBA Lba, + IN UINTN Length, + IN UINT32* Buffer ) { EFI_STATUS Status; UINT32 DescPages, CountPerPage, Count; EFI_TPL Tpl; + UINT32 *DmaBuf; =20 Tpl =3D gBS->RaiseTPL (TPL_NOTIFY); + DmaBuf =3D AllocateMemoryBelow4G(Length); =20 CountPerPage =3D EFI_PAGE_SIZE / 16; Count =3D (Length + DWEMMC_DMA_BUF_SIZE - 1) / DWEMMC_DMA_BUF_SIZE; DescPages =3D (Count + CountPerPage - 1) / CountPerPage; =20 - InvalidateDataCacheRange (Buffer, Length); + InvalidateDataCacheRange (DmaBuf, Length); =20 - Status =3D PrepareDmaData (gpIdmacDesc, Length, Buffer); + Status =3D PrepareDmaData (gpIdmacDesc, Length, DmaBuf); if (EFI_ERROR (Status)) { goto out; } @@ -637,11 +667,14 @@ DwEmmcReadBlockData ( Status =3D DwEmmcWaitDmaComplete(This, 1); =20 if (DWMCI_SD_READ_MASK(mDwEmmcArgument) && (FixedPcdGetBool (PcdDwEmmcDx= eCPULittleEndian))) { - Buffer[3] =3D SwapBytes32(Buffer[3]); - Buffer[4] =3D SwapBytes32(Buffer[4]); + DmaBuf[3] =3D SwapBytes32(DmaBuf[3]); + DmaBuf[4] =3D SwapBytes32(DmaBuf[4]); } =20 + CopyMem(Buffer, DmaBuf, Length); + out: + FreePages (DmaBuf, EFI_SIZE_TO_PAGES(Length)); // Restore Tpl gBS->RestoreTPL (Tpl); return Status; @@ -649,25 +682,29 @@ out: =20 EFI_STATUS DwEmmcWriteBlockData ( - IN EFI_MMC_HOST_PROTOCOL *This, - IN EFI_LBA Lba, - IN UINTN Length, - IN UINT32* Buffer + IN EFI_MMC_HOST_PROTOCOL *This, + IN EFI_LBA Lba, + IN UINTN Length, + IN UINT32* Buffer ) { EFI_STATUS Status; UINT32 DescPages, CountPerPage, Count; EFI_TPL Tpl; + UINT32 *DmaBuf; =20 Tpl =3D gBS->RaiseTPL (TPL_NOTIFY); =20 + DmaBuf =3D AllocateMemoryBelow4G(Length); + CopyMem(DmaBuf, Buffer, Length); + CountPerPage =3D EFI_PAGE_SIZE / 16; Count =3D (Length + DWEMMC_DMA_BUF_SIZE - 1) / DWEMMC_DMA_BUF_SIZE; DescPages =3D (Count + CountPerPage - 1) / CountPerPage; =20 - WriteBackDataCacheRange (Buffer, Length); + WriteBackDataCacheRange (DmaBuf, Length); =20 - Status =3D PrepareDmaData (gpIdmacDesc, Length, Buffer); + Status =3D PrepareDmaData (gpIdmacDesc, Length, DmaBuf); if (EFI_ERROR (Status)) { goto out; } @@ -683,6 +720,7 @@ DwEmmcWriteBlockData ( Status =3D DwEmmcWaitDmaComplete(This, 0); =20 out: + FreePages (DmaBuf, EFI_SIZE_TO_PAGES(Length)); // Restore Tpl gBS->RestoreTPL (Tpl); return Status; @@ -772,6 +810,7 @@ DwEmmcDxeInitialize ( { EFI_STATUS Status; EFI_HANDLE Handle; + EFI_PHYSICAL_ADDRESS Address; =20 if (!FixedPcdGetBool (PcdDwPermitObsoleteDrivers)) { ASSERT (FALSE); @@ -781,7 +820,17 @@ DwEmmcDxeInitialize ( Handle =3D NULL; =20 DwEmmcAdjustFifoThreshold (); - gpIdmacDesc =3D (DWEMMC_IDMAC_DESCRIPTOR *)AllocatePages (DWEMMC_MAX_DES= C_PAGES); + + Address =3D 0xffffffff; + Status =3D gBS->AllocatePages ( + AllocateMaxAddress, + EfiBootServicesData, + DWEMMC_MAX_DESC_PAGES, + &Address + ); + gpIdmacDesc =3D (DWEMMC_IDMAC_DESCRIPTOR *)(UINTN)Address; + ZeroMem (gpIdmacDesc, DWEMMC_MAX_DESC_PAGES); + if (gpIdmacDesc =3D=3D NULL) { return EFI_BUFFER_TOO_SMALL; } --=20 2.34.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 (#110600): https://edk2.groups.io/g/devel/message/110600 Mute This Topic: https://groups.io/mt/102357283/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-