From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Cc: Ard Biesheuvel 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: [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: , X-List-Received-Date: Fri, 25 Aug 2017 12:07:52 -0000 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(-) 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; } -- 2.11.0