From nobody Fri Dec 27 03:35:03 2024 Delivered-To: importer@patchew.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; Authentication-Results: mx.zohomail.com; dkim=fail; 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 1503663030153887.6002970079536; Fri, 25 Aug 2017 05:10:30 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 998C72095B9C1; Fri, 25 Aug 2017 05:07:51 -0700 (PDT) Received: from mail-wm0-x233.google.com (mail-wm0-x233.google.com [IPv6:2a00:1450:400c:c09::233]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id EB95821D1E2FD for ; Fri, 25 Aug 2017 05:07:49 -0700 (PDT) Received: by mail-wm0-x233.google.com with SMTP id y71so1270500wmd.0 for ; Fri, 25 Aug 2017 05:10:26 -0700 (PDT) Received: from localhost.localdomain ([105.137.125.182]) by smtp.gmail.com with ESMTPSA id 9sm1996137wmo.35.2017.08.25.05.10.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 Aug 2017 05:10:23 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Y1sSqGmfUOfPbY32xGHgfLILD2DZ7QTKNifTerqPotA=; b=DcFP/L5WeUqFw1k60Zd/zu7Xs6fYAockClUYgsYUXF4VuEgVwKjK/cL5/bhGLitV61 LgdJ94lVHFdyiKY8m8IXZ79URk0K0Kebte/QRxZInswnFXuc5uMqoyahCDW1TfF25Fqz fyunsTusGIy3plsruWRqTKYXcuABUG4Nx+h+A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Y1sSqGmfUOfPbY32xGHgfLILD2DZ7QTKNifTerqPotA=; b=U0AHhI04MmuU8GDHiElxKX05HaH0ZrOebvLtomptIKtiqv0lt+E5y7wdW/nyfUSfnw UbN4W0IKSTOmkKorZoTQxJ/GX26inFCVNhBJsZTfh/NTL8QicIlE05FzSnpz0Bh+pwNV GMySgaKps9lO9VRgv+m9wVf3JFQQDoV5LFtvWOqgsvJwikOSJ6YDmYUrIWM7VSUaHUj9 HS+7rRpoSVtn2Lg7vi4YNwvvR+iPENhUIBN9ARrxXQ9Eut7S/x6NRfZ7Ctawf+iMrvux v51qKWw0PkbnNCpUmTPHTgRJqblN4ZLb/LyddGiS+Jlk+hOd8fJnvk+VPbgTmNIonbXq AaWg== X-Gm-Message-State: AHYfb5gm5LJLnfbx+qJRELH+KGmtsnETPkvEX3UMW6BrnWTd5nP0dDGv f5rThdmOH4hesXWGjpVgqw== X-Received: by 10.28.97.132 with SMTP id v126mr1279543wmb.18.1503663024151; Fri, 25 Aug 2017 05:10:24 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org, leif.lindholm@linaro.org Date: Fri, 25 Aug 2017 13:10:10 +0100 Message-Id: <20170825121014.15739-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170825121014.15739-1-ard.biesheuvel@linaro.org> References: <20170825121014.15739-1-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH 1/5] EmbeddedPkg/DmaLib: add routine to allocate aligned buffers X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ard Biesheuvel MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" DmaLib's purpose is to manage memory that is shared between the host and DMA capable devices. In some cases, this requires a larger alignment than page size, and we currently don't cater for that in DmaLib. So add a variant of DmaAllocateBuffer () that takes an alignment parameter. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- EmbeddedPkg/Include/Library/DmaLib.h | 30 +++++++++++- EmbeddedPkg/Library/NullDmaLib/NullDmaLib.c | 48 ++++++++++++++++++-- 2 files changed, 72 insertions(+), 6 deletions(-) diff --git a/EmbeddedPkg/Include/Library/DmaLib.h b/EmbeddedPkg/Include/Lib= rary/DmaLib.h index 3814291c2875..1843814c65ca 100644 --- a/EmbeddedPkg/Include/Library/DmaLib.h +++ b/EmbeddedPkg/Include/Library/DmaLib.h @@ -155,5 +155,33 @@ DmaFreeBuffer ( ); =20 =20 -#endif +/** + Allocates pages that are suitable for an DmaMap() of type + MapOperationBusMasterCommonBuffer mapping, at the requested alignment. + + @param MemoryType The type of memory to allocate, EfiBootSer= vicesData or + EfiRuntimeServicesData. + @param Pages The number of pages to allocate. + @param Alignment Alignment in bytes of the base of the retu= rned + buffer (must be a power of 2) + @param HostAddress A pointer to store the base system memory = address of the + allocated range. =20 + @retval EFI_SUCCESS The requested memory pages were allocated. + @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal = attribute bits are + MEMORY_WRITE_COMBINE and MEMORY_CACHED. + @retval EFI_INVALID_PARAMETER One or more parameters are invalid. + @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated. + +**/ +EFI_STATUS +EFIAPI +DmaAllocateAlignedBuffer ( + IN EFI_MEMORY_TYPE MemoryType, + IN UINTN Pages, + IN UINTN Alignment, + OUT VOID **HostAddress + ); + + +#endif diff --git a/EmbeddedPkg/Library/NullDmaLib/NullDmaLib.c b/EmbeddedPkg/Libr= ary/NullDmaLib/NullDmaLib.c index a0bb57541d60..4cbe349190a9 100644 --- a/EmbeddedPkg/Library/NullDmaLib/NullDmaLib.c +++ b/EmbeddedPkg/Library/NullDmaLib/NullDmaLib.c @@ -100,23 +100,61 @@ DmaAllocateBuffer ( OUT VOID **HostAddress ) { - if (HostAddress =3D=3D NULL) { + return DmaAllocateAlignedBuffer (MemoryType, Pages, 0, HostAddress); +} + + +/** + Allocates pages that are suitable for an DmaMap() of type + MapOperationBusMasterCommonBuffer mapping, at the requested alignment. + + @param MemoryType The type of memory to allocate, EfiBootSer= vicesData or + EfiRuntimeServicesData. + @param Pages The number of pages to allocate. + @param Alignment Alignment in bytes of the base of the retu= rned + buffer (must be a power of 2) + @param HostAddress A pointer to store the base system memory = address of the + allocated range. + + @retval EFI_SUCCESS The requested memory pages were allocated. + @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal = attribute bits are + MEMORY_WRITE_COMBINE and MEMORY_CACHED. + @retval EFI_INVALID_PARAMETER One or more parameters are invalid. + @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated. + +**/ +EFI_STATUS +EFIAPI +DmaAllocateAlignedBuffer ( + IN EFI_MEMORY_TYPE MemoryType, + IN UINTN Pages, + IN UINTN Alignment, + OUT VOID **HostAddress + ) +{ + if (Alignment =3D=3D 0) { + Alignment =3D EFI_PAGE_SIZE; + } + + if (HostAddress =3D=3D NULL || + (Alignment & (Alignment - 1)) !=3D 0) { return EFI_INVALID_PARAMETER; } =20 // // The only valid memory types are EfiBootServicesData and EfiRuntimeSer= vicesData // - // We used uncached memory to keep coherency - // if (MemoryType =3D=3D EfiBootServicesData) { - *HostAddress =3D AllocatePages (Pages); + *HostAddress =3D AllocateAlignedPages (Pages, Alignment); } else if (MemoryType !=3D EfiRuntimeServicesData) { - *HostAddress =3D AllocateRuntimePages (Pages); + *HostAddress =3D AllocateAlignedRuntimePages (Pages, Alignment); } else { return EFI_INVALID_PARAMETER; } =20 + if (*HostAddress =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } return EFI_SUCCESS; } =20 --=20 2.11.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel