From patchwork Fri Aug 25 12:10:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 111014 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp909488qge; Fri, 25 Aug 2017 05:10:31 -0700 (PDT) X-Received: by 10.99.16.65 with SMTP id 1mr9599957pgq.208.1503663031586; Fri, 25 Aug 2017 05:10:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1503663031; cv=none; d=google.com; s=arc-20160816; b=DAJcnRVAGev3iuM/IQw5H5WuubcIAChnMbZTnvE0bqF/t1rkTumkca0DlOoRfxpA5l GfIi+7nAPzvlXGuQl0d5lXSlrrOA7PwHsLkCMbCuL8kTdSlFGAmci3vDdyQ6RM1COT5d YiOfntFb03yGZLjEG9hOkZ2QItEIBF6OwfijvSKbAwUOwqyRVximJQGMgWLMpeNIL5fh ZjvYJpWuydk23o9di6D6Ks7QyVjpNGWLjHCa6Pwz6j+JJWm4a3ltjDXGkQP5x9U4ws3J IAkwQzpQOHxHAIBjfT4IfIYMypEFqXo1bfQlvvrQA7xlLPtH4uOK4qznbS/nzcjDBpZE mc8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=2TEDk7ptHHEdpML5xkierx7aAO43GgsZnlM9hLdXWWA=; b=0Wo4U+IlntmuCTYBSOe/CtVKYk0MQ5IKPDg7HvgoXVdkOI/YjGfinWfnsdQQJCiOd5 KOLKIO0+sT/c448t/mdnVxHN9rLnzhlexp5emDUSMTuXiwfjIZV1YJw0eroPexFbhGsj bUOSmsPt4P+0ddxXOp5nr0ANOvK4V0spXJSg9v41jh0S/mVKg7kh2bYSpwM8f/YpU3Mx Yut3bFcEEnQLYvvvAbBGGCpuSsnIOXKB+tRvRhWpSP+i4nUPd3WOGyIRfjEsTiDNnINu 3eKnabWc8CbkjZTXYPPUlOgA6/vpRIorFtLvt5HM2Pfv3QuPE+3Xs6BpyW36Z+ZIWhZe PHhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=AQ5S6B9i; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [198.145.21.10]) by mx.google.com with ESMTPS id 3si4971872pll.202.2017.08.25.05.10.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 Aug 2017 05:10:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) client-ip=198.145.21.10; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=AQ5S6B9i; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id DD25D2095B9FD; Fri, 25 Aug 2017 05:07:53 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received: from mail-wr0-x232.google.com (mail-wr0-x232.google.com [IPv6:2a00:1450:400c:c0c::232]) (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 D72EF2095B9FD for ; Fri, 25 Aug 2017 05:07:51 -0700 (PDT) Received: by mail-wr0-x232.google.com with SMTP id a47so6763585wra.4 for ; Fri, 25 Aug 2017 05:10:27 -0700 (PDT) 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=rWygZacTeInJ9LG1E3+ZiW0wBGTA9q2MX6A864NVj2Q=; b=AQ5S6B9iN2Y9WkqQItQiCvGxJISaBGB82T1Ve4rC8ORK8v0H6VgD/hESugxxc8p//8 ttGK9qmFuX92epdJWPaJ+unzbTOyLGCJiGsU01kuc+pv4FEIA8SSFVuo4BaChvmoNSnL u+7LlQFYHM/6tsqxc4ItTaF/McrttOWddfhq4= 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=rWygZacTeInJ9LG1E3+ZiW0wBGTA9q2MX6A864NVj2Q=; b=KwarGP1Pka+3X/W5FBy3bTU09AD5boyBP8D1lWpjuoJrPGw9q6yMEXTWGdvxR61D6q SCXWB4gCy9xKw/ocjodcbnY5GNifTUA0rdD6GvFESxqlVh5j1QUnpyUoDQJCUh0nBclD EQXs6TSBx+XTUg2vFW87c3i8TWBVRx5pA+hwSa3HXI3jiq1s8ToVJOtOMiyFu0D2e1EG yFWC3EF8MoNAW4/NaSyhCTNGeyQhWwdeZJzHJsnN2YIjYOUH97cMEpxGoQqkwEvfRsqu UBnvMPru35fnrhvfy9TTeWe2oxObo7CqKUt+XWtQabKPyvMFnnK/7BaI6Kp9BLcJreKg +vCw== X-Gm-Message-State: AHYfb5gKaafqnMj2CGRzUQR7pArfMiJWUrYR7fgVhaKuEc6VdfRkxxVV Q0tlqdxNTjWktBVXteLmSA== X-Received: by 10.223.165.129 with SMTP id g1mr5432724wrc.108.1503663025830; Fri, 25 Aug 2017 05:10:25 -0700 (PDT) Received: from localhost.localdomain ([105.137.125.182]) by smtp.gmail.com with ESMTPSA id 9sm1996137wmo.35.2017.08.25.05.10.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 Aug 2017 05:10:25 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org, leif.lindholm@linaro.org Date: Fri, 25 Aug 2017 13:10:11 +0100 Message-Id: <20170825121014.15739-3-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 2/5] ArmPkg/ArmDmaLib: implement DmaAllocateAlignedBuffer() 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 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" Implement the new DmaLib routine that returns DMA'able buffers at a specified minimum alignment. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- ArmPkg/Library/ArmDmaLib/ArmDmaLib.c | 42 ++++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) -- 2.11.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c b/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c index e12bda4c2d33..2a8cf0fe21a4 100644 --- a/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c +++ b/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c @@ -285,20 +285,56 @@ DmaAllocateBuffer ( OUT VOID **HostAddress ) { + 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, EfiBootServicesData or + EfiRuntimeServicesData. + @param Pages The number of pages to allocate. + @param Alignment Alignment in bytes of the base of the returned + 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 + ) +{ EFI_GCD_MEMORY_SPACE_DESCRIPTOR GcdDescriptor; VOID *Allocation; UINT64 MemType; UNCACHED_ALLOCATION *Alloc; EFI_STATUS Status; - if (HostAddress == NULL) { + if (Alignment == 0) { + Alignment = EFI_PAGE_SIZE; + } + + if (HostAddress == NULL || + (Alignment & (Alignment - 1)) != 0) { return EFI_INVALID_PARAMETER; } if (MemoryType == EfiBootServicesData) { - Allocation = AllocatePages (Pages); + Allocation = AllocateAlignedPages (Pages, Alignment); } else if (MemoryType == EfiRuntimeServicesData) { - Allocation = AllocateRuntimePages (Pages); + Allocation = AllocateAlignedRuntimePages (Pages, Alignment); } else { return EFI_INVALID_PARAMETER; }