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 72177740058 for ; Mon, 23 Oct 2023 07:19:06 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=Wy+aVtOA5OiAWoOr4epmFnLX8Z/pfH485f8AaXgoRJs=; 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-Transfer-Encoding:Content-Type; s=20140610; t=1698045545; v=1; b=dTbPaFGPkZROupToqU0XEuk75ThlxxxsTYRRJeg8fxO7NNe1GYzZ/Ycby1NaPTf9uRyFaWNZ rh2KwkNxJSzg0Hohds1Cxgo9ihd3d9/dGoxLNWab2UxpphopxuF9UGzEP88PZuZNUeL0uop0zoi +hL/KpXH4gUWYyW2WUvz+2bA= X-Received: by 127.0.0.2 with SMTP id pYG5YY7687511xiIqYN6792c; Mon, 23 Oct 2023 00:19:05 -0700 X-Received: from ex01.ufhost.com (ex01.ufhost.com [61.152.239.75]) by mx.groups.io with SMTP id smtpd.web10.115217.1698045542613260142 for ; Mon, 23 Oct 2023 00:19:04 -0700 X-Received: from EXMBX166.cuchost.com (unknown [175.102.18.54]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "EXMBX166", Issuer "EXMBX166" (not verified)) by ex01.ufhost.com (Postfix) with ESMTP id 540DA24E20F; Mon, 23 Oct 2023 15:18:39 +0800 (CST) X-Received: from EXMBX073.cuchost.com (172.16.6.83) by EXMBX166.cuchost.com (172.16.6.76) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Mon, 23 Oct 2023 15:18:39 +0800 X-Received: from localhost.localdomain (202.188.176.82) by EXMBX073.cuchost.com (172.16.6.83) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Mon, 23 Oct 2023 15:18:36 +0800 From: "John Chew" To: CC: John Chew , Sunil V L , Leif Lindholm , Michael D Kinney , "Cc : Li Yong" Subject: [edk2-devel] [PATCH v2 5/5] DesignWare/DwEmmcDxe: Force DMA buffer to allocate below 4GB Date: Mon, 23 Oct 2023 15:17:15 +0800 Message-ID: <20231023071715.777-6-yuinyee.chew@starfivetech.com> In-Reply-To: <20231023071715.777-1-yuinyee.chew@starfivetech.com> References: <20231023071715.777-1-yuinyee.chew@starfivetech.com> MIME-Version: 1.0 X-Originating-IP: [202.188.176.82] X-ClientProxiedBy: EXCAS066.cuchost.com (172.16.6.26) 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: H2tZJfRiMVxqYGcFJ3bHB9jUx7686176AA= Content-Transfer-Encoding: quoted-printable Content-Type: text/plain X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=dTbPaFGP; dmarc=none; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io 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: Michael D Kinney Cc: 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 (#109895): https://edk2.groups.io/g/devel/message/109895 Mute This Topic: https://groups.io/mt/102130696/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-