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 2A598AC128C for ; Wed, 22 Nov 2023 15:49:50 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=vke+NE7uc8JO5nnJfBOxTMIOtQ33HMvIHDVb1dnQuiA=; c=relaxed/simple; d=groups.io; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject:To:Cc:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Type; s=20140610; t=1700668188; v=1; b=u6xm8EKs7lwQjnFj7nP8gS6SYitAzrHzSmJJ4NShSZCU7yLePW1YcaQoN4dFFAMP3hhii3oj //K8diI3rj+eaGBec3a8a9g6ZzW0qVjnLat4lv/OamiXHiS7A2SM1YmfgfLr0sHcqjYD8DbXOp+ kunQCHzuGL4zic4JGJYBeqdg= X-Received: by 127.0.0.2 with SMTP id RhIFYY7687511xLev1GHCshS; Wed, 22 Nov 2023 07:49:48 -0800 X-Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by mx.groups.io with SMTP id smtpd.web11.22912.1700668187969480417 for ; Wed, 22 Nov 2023 07:49:48 -0800 X-Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by ams.source.kernel.org (Postfix) with ESMTP id 3E339B82898 for ; Wed, 22 Nov 2023 15:49:46 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 98756C433CA for ; Wed, 22 Nov 2023 15:49:45 +0000 (UTC) X-Received: by mail-lj1-f173.google.com with SMTP id 38308e7fff4ca-2c887d1fb8fso35574511fa.0 for ; Wed, 22 Nov 2023 07:49:45 -0800 (PST) X-Gm-Message-State: 3kh6D4NSB8WaOZbqUt1iXb90x7686176AA= X-Google-Smtp-Source: AGHT+IGzerpzm1FhCUy50dG1YjQHp2ZOOIs8Rcse+t9L2diOR7u0YeyrFMC0CpPjbKMJNJod1hMMwKekNGT4PU4GbKA= X-Received: by 2002:a2e:98c2:0:b0:2c5:2132:24f6 with SMTP id s2-20020a2e98c2000000b002c5213224f6mr2054315ljj.12.1700668183832; Wed, 22 Nov 2023 07:49:43 -0800 (PST) MIME-Version: 1.0 References: <20231103025131.1643-1-yuinyee.chew@starfivetech.com> <20231103025131.1643-6-yuinyee.chew@starfivetech.com> In-Reply-To: <20231103025131.1643-6-yuinyee.chew@starfivetech.com> From: "Ard Biesheuvel" Date: Wed, 22 Nov 2023 16:49:32 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [edk2-devel] [PATCH v3 5/5] DesignWare/DwEmmcDxe: Force DMA buffer to allocate below 4GB To: devel@edk2.groups.io, yuinyee.chew@starfivetech.com Cc: Sunil V L , Leif Lindholm , Ard Biesheuvel , Michael D Kinney , Li Yong 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,ardb@kernel.org List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Type: text/plain; charset="UTF-8" X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=u6xm8EKs; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=kernel.org (policy=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 On Fri, 3 Nov 2023 at 03:53, John Chew wrote: > > 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 This logic does not belong in the driver. Please investigate whether it is possible to migrate this driver to the DMA libraries in EmbeddedPkg, which already support DMA address limits and translation. That should allow you to remove all explicit cache maintenance, and potentially reuse this IP with coherent DMA too. > --- > 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/Silicon/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; > } > > +STATIC > +UINT32 * > +AllocateMemoryBelow4G ( > + IN UINTN Size > + ) > +{ > + UINTN Pages; > + EFI_PHYSICAL_ADDRESS Address; > + EFI_STATUS Status; > + UINT32 *Buffer; > + > + Pages = EFI_SIZE_TO_PAGES (Size); > + Address = 0xFFFFFFFF; > + > + Status = gBS->AllocatePages ( > + AllocateMaxAddress, > + EfiBootServicesData, > + Pages, > + &Address > + ); > + ASSERT_EFI_ERROR (Status); > + > + Buffer = (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; > > Tpl = gBS->RaiseTPL (TPL_NOTIFY); > + DmaBuf = AllocateMemoryBelow4G(Length); > > CountPerPage = EFI_PAGE_SIZE / 16; > Count = (Length + DWEMMC_DMA_BUF_SIZE - 1) / DWEMMC_DMA_BUF_SIZE; > DescPages = (Count + CountPerPage - 1) / CountPerPage; > > - InvalidateDataCacheRange (Buffer, Length); > + InvalidateDataCacheRange (DmaBuf, Length); > > - Status = PrepareDmaData (gpIdmacDesc, Length, Buffer); > + Status = PrepareDmaData (gpIdmacDesc, Length, DmaBuf); > if (EFI_ERROR (Status)) { > goto out; > } > @@ -637,11 +667,14 @@ DwEmmcReadBlockData ( > Status = DwEmmcWaitDmaComplete(This, 1); > > if (DWMCI_SD_READ_MASK(mDwEmmcArgument) && (FixedPcdGetBool (PcdDwEmmcDxeCPULittleEndian))) { > - Buffer[3] = SwapBytes32(Buffer[3]); > - Buffer[4] = SwapBytes32(Buffer[4]); > + DmaBuf[3] = SwapBytes32(DmaBuf[3]); > + DmaBuf[4] = SwapBytes32(DmaBuf[4]); > } > > + CopyMem(Buffer, DmaBuf, Length); > + > out: > + FreePages (DmaBuf, EFI_SIZE_TO_PAGES(Length)); > // Restore Tpl > gBS->RestoreTPL (Tpl); > return Status; > @@ -649,25 +682,29 @@ out: > > 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; > > Tpl = gBS->RaiseTPL (TPL_NOTIFY); > > + DmaBuf = AllocateMemoryBelow4G(Length); > + CopyMem(DmaBuf, Buffer, Length); > + > CountPerPage = EFI_PAGE_SIZE / 16; > Count = (Length + DWEMMC_DMA_BUF_SIZE - 1) / DWEMMC_DMA_BUF_SIZE; > DescPages = (Count + CountPerPage - 1) / CountPerPage; > > - WriteBackDataCacheRange (Buffer, Length); > + WriteBackDataCacheRange (DmaBuf, Length); > > - Status = PrepareDmaData (gpIdmacDesc, Length, Buffer); > + Status = PrepareDmaData (gpIdmacDesc, Length, DmaBuf); > if (EFI_ERROR (Status)) { > goto out; > } > @@ -683,6 +720,7 @@ DwEmmcWriteBlockData ( > Status = DwEmmcWaitDmaComplete(This, 0); > > 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; > > if (!FixedPcdGetBool (PcdDwPermitObsoleteDrivers)) { > ASSERT (FALSE); > @@ -781,7 +820,17 @@ DwEmmcDxeInitialize ( > Handle = NULL; > > DwEmmcAdjustFifoThreshold (); > - gpIdmacDesc = (DWEMMC_IDMAC_DESCRIPTOR *)AllocatePages (DWEMMC_MAX_DESC_PAGES); > + > + Address = 0xffffffff; > + Status = gBS->AllocatePages ( > + AllocateMaxAddress, > + EfiBootServicesData, > + DWEMMC_MAX_DESC_PAGES, > + &Address > + ); > + gpIdmacDesc = (DWEMMC_IDMAC_DESCRIPTOR *)(UINTN)Address; > + ZeroMem (gpIdmacDesc, DWEMMC_MAX_DESC_PAGES); > + > if (gpIdmacDesc == NULL) { > return EFI_BUFFER_TOO_SMALL; > } > -- > 2.34.1 > > > > > > -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#111612): https://edk2.groups.io/g/devel/message/111612 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] -=-=-=-=-=-=-=-=-=-=-=-