From patchwork Tue Feb 18 13:37:56 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 24840 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f200.google.com (mail-qc0-f200.google.com [209.85.216.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4203F202B2 for ; Tue, 18 Feb 2014 13:39:27 +0000 (UTC) Received: by mail-qc0-f200.google.com with SMTP id e9sf31907613qcy.3 for ; Tue, 18 Feb 2014 05:39:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=XldD+ZbLRdakzY6MtkTCq3Ncy9h+WGim9jP7JrAji5M=; b=U1v4qCCl+/PyxcL+PUVZSfd5Spa/FozsVXioj+mt8EiKbxqZCUGO4/7uac5+eDwzZQ HTCRn/D/ximxSHSIDAHaXrces4dXd6gMGcO2oDDKVT5KJFSoWDIrBpfzsHT9aPkQT7dS 5+/u21DHW627KOX+cwlolWrmIw38vXW0KEVaSWnXAkjnT6GSgG2yTWtG1YME9k2PXzr7 sOGMu4kxHbzzNNXziy3KQVxwLeylSpE9AhzkJpNrnbAUxnRTMU9SjrTHfl/HIldHmXWe HaEwDAqItiL/nfWz7HTCSdK5GdmbW78gJ+GVOnzQbEccjIU0EtBUtdOdIsGfKPLi1Hd9 gkEg== X-Gm-Message-State: ALoCoQl5jO3P/LlMwqVmBZm/lB2/7eaMDz1IGVqAmAAkXimoah3inPX6PNqa0BJHHRwVWqhQt66s X-Received: by 10.52.94.47 with SMTP id cz15mr11142194vdb.0.1392730767001; Tue, 18 Feb 2014 05:39:27 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.51.130 with SMTP id u2ls1331743qga.34.gmail; Tue, 18 Feb 2014 05:39:26 -0800 (PST) X-Received: by 10.220.114.135 with SMTP id e7mr5450475vcq.39.1392730766907; Tue, 18 Feb 2014 05:39:26 -0800 (PST) Received: from mail-ve0-f171.google.com (mail-ve0-f171.google.com [209.85.128.171]) by mx.google.com with ESMTPS id cl8si5501306vcb.76.2014.02.18.05.39.26 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 18 Feb 2014 05:39:26 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.171 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.171; Received: by mail-ve0-f171.google.com with SMTP id pa12so13330663veb.2 for ; Tue, 18 Feb 2014 05:39:26 -0800 (PST) X-Received: by 10.220.110.210 with SMTP id o18mr557801vcp.49.1392730766819; Tue, 18 Feb 2014 05:39:26 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.174.196 with SMTP id u4csp217081vcz; Tue, 18 Feb 2014 05:39:26 -0800 (PST) X-Received: by 10.68.40.138 with SMTP id x10mr21799450pbk.8.1392730765995; Tue, 18 Feb 2014 05:39:25 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id oq9si18350302pac.209.2014.02.18.05.39.25; Tue, 18 Feb 2014 05:39:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755252AbaBRNjY (ORCPT + 9 others); Tue, 18 Feb 2014 08:39:24 -0500 Received: from mailout2.samsung.com ([203.254.224.25]:21979 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753505AbaBRNjX (ORCPT ); Tue, 18 Feb 2014 08:39:23 -0500 Received: from epcpsbgm1.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout2.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0N1700AL21XLSQD0@mailout2.samsung.com>; Tue, 18 Feb 2014 22:39:21 +0900 (KST) X-AuditID: cbfee61a-b7fb26d00000724f-ef-530362899658 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id F6.65.29263.98263035; Tue, 18 Feb 2014 22:39:21 +0900 (KST) Received: from amdc1339.mshome.net ([106.116.147.30]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0N17001N61VOJ880@mmp1.samsung.com>; Tue, 18 Feb 2014 22:39:21 +0900 (KST) From: Marek Szyprowski To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linaro-mm-sig@lists.linaro.org, devicetree@vger.kernel.org, linux-doc@vger.kernel.org Cc: Marek Szyprowski , Kyungmin Park , Benjamin Herrenschmidt , Arnd Bergmann , Michal Nazarewicz , Grant Likely , Tomasz Figa , Sascha Hauer , Laura Abbott , Rob Herring , Olof Johansson , Pawel Moll , Mark Rutland , Stephen Warren , Ian Campbell , Tomasz Figa , Kumar Gala , Nishanth Peethambaran , Marc , Josh Cartwright Subject: [PATCH v3 1/6] base: dma-contiguous: add dma_contiguous_init_reserved_mem() function Date: Tue, 18 Feb 2014 14:37:56 +0100 Message-id: <1392730681-14695-2-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1392730681-14695-1-git-send-email-m.szyprowski@samsung.com> References: <1392730681-14695-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrAIsWRmVeSWpSXmKPExsVy+t9jAd3OJOZggxXNYhZ/Jx1jt/jQ1Mps Mf/IOVaL/jcLWS0O/NnBaPGmt4PFYue6d4wWZ5vesFts75zBbvHlykMmi02Pr7FaLGxbwmJx edccNou1R+6yW2x4eZDJYun1i0wWC463sFr8mS5ncer6ZzaLCdPXsli07j3CbvF3+yYWi1cH 21gs1s94zWKxatcfRgdJjzXz1jB6/P41idHj9eQJjB6X+3qZPHbOusvu0fOmhdVj06pONo87 1/aweWxeUu9x+99jZo8rJ5pYPdb9ecXk0f/XwKNvyypGj8+b5Dw2zg0NEIjisklJzcksSy3S t0vgyvg+9xlzwW21irP7P7E1MD6W72Lk5JAQMJF4PnkxG4QtJnHh3nogm4tDSGARo8TVv3eg nFYmiSvfprOAVLEJGEp0ve0C6xARWMgo8XkeC0gRs8B0NonFW9+DJYQF4iXer77BDmKzCKhK zNkyEczmFfCQaL0/B6iGA2idgsScSTYgJqeAp8SX6zogFUJAFVvvP2aewMi7gJFhFaNoakFy QXFSeq6hXnFibnFpXrpecn7uJkZwvD2T2sG4ssHiEKMAB6MSD+8HZaZgIdbEsuLK3EOMEhzM SiK8mlHMwUK8KYmVValF+fFFpTmpxYcYpTlYlMR5D7RaBwoJpCeWpGanphakFsFkmTg4pRoY z/w93O5fdtipLEorWWOf0Pv9wS92z/0QfJQz8tNXj/daLfGcUvZZ384b+18/GCc01/jsPB8V VxfV9yvPeL7YzqqvP7XF33R5kYb1vFd9Qpm6jMcu7JmwN+WKXmZ3peg5N4sFhnx9pcoCqbtk VvX+e3Jyd83ZFRcSP/3T7gx8EWPoJDAz4MhTJZbijERDLeai4kQAKfMYibMCAAA= Sender: devicetree-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: devicetree@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: m.szyprowski@samsung.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.171 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Add new dma_contiguous_init_reserved_mem() function, which creates CMA area from previously reserved memory region. Signed-off-by: Marek Szyprowski --- drivers/base/dma-contiguous.c | 70 +++++++++++++++++++++++++++------------- include/linux/dma-contiguous.h | 7 ++++ 2 files changed, 55 insertions(+), 22 deletions(-) diff --git a/drivers/base/dma-contiguous.c b/drivers/base/dma-contiguous.c index 165c2c299e57..ece82e8f3a8b 100644 --- a/drivers/base/dma-contiguous.c +++ b/drivers/base/dma-contiguous.c @@ -182,6 +182,53 @@ static int __init cma_init_reserved_areas(void) core_initcall(cma_init_reserved_areas); /** + * dma_contiguous_init_reserved_mem() - reserve custom contiguous area + * @size: Size of the reserved area (in bytes), + * @base: Base address of the reserved area optional, use 0 for any + * @limit: End address of the reserved memory (optional, 0 for any). + * @res_cma: Pointer to store the created cma region. + * + * This function reserves memory from early allocator. It should be + * called by arch specific code once the early allocator (memblock or bootmem) + * has been activated and all other subsystems have already allocated/reserved + * memory. This function allows to create custom reserved areas for specific + * devices. + */ +int __init dma_contiguous_init_reserved_mem(phys_addr_t size, phys_addr_t base, + struct cma **res_cma) +{ + struct cma *cma = &cma_areas[cma_area_count]; + phys_addr_t alignment; + + /* Sanity checks */ + if (cma_area_count == ARRAY_SIZE(cma_areas)) { + pr_err("Not enough slots for CMA reserved regions!\n"); + return -ENOSPC; + } + + if (!size || !memblock_is_region_reserved(base, size)) + return -EINVAL; + + /* Sanitise input arguments */ + alignment = PAGE_SIZE << max(MAX_ORDER - 1, pageblock_order); + if (ALIGN(base, alignment) != base || ALIGN(size, alignment) != size) + return -EINVAL; + + cma->base_pfn = PFN_DOWN(base); + cma->count = size >> PAGE_SHIFT; + *res_cma = cma; + cma_area_count++; + + pr_info("CMA: reserved %ld MiB at %08lx\n", (unsigned long)size / SZ_1M, + (unsigned long)base); + + /* Architecture specific contiguous memory fixup. */ + dma_contiguous_early_fixup(base, size); + return 0; +} + + +/** * dma_contiguous_reserve_area() - reserve custom contiguous area * @size: Size of the reserved area (in bytes), * @base: Base address of the reserved area optional, use 0 for any @@ -197,7 +244,6 @@ core_initcall(cma_init_reserved_areas); int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base, phys_addr_t limit, struct cma **res_cma) { - struct cma *cma = &cma_areas[cma_area_count]; phys_addr_t alignment; int ret = 0; @@ -205,12 +251,6 @@ int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base, (unsigned long)size, (unsigned long)base, (unsigned long)limit); - /* Sanity checks */ - if (cma_area_count == ARRAY_SIZE(cma_areas)) { - pr_err("Not enough slots for CMA reserved regions!\n"); - return -ENOSPC; - } - if (!size) return -EINVAL; @@ -241,21 +281,7 @@ int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base, } } - /* - * Each reserved area must be initialised later, when more kernel - * subsystems (like slab allocator) are available. - */ - cma->base_pfn = PFN_DOWN(base); - cma->count = size >> PAGE_SHIFT; - *res_cma = cma; - cma_area_count++; - - pr_info("CMA: reserved %ld MiB at %08lx\n", (unsigned long)size / SZ_1M, - (unsigned long)base); - - /* Architecture specific contiguous memory fixup. */ - dma_contiguous_early_fixup(base, size); - return 0; + return dma_contiguous_init_reserved_mem(size, base, res_cma); err: pr_err("CMA: failed to reserve %ld MiB\n", (unsigned long)size / SZ_1M); return ret; diff --git a/include/linux/dma-contiguous.h b/include/linux/dma-contiguous.h index 3b28f937d959..550497393ae7 100644 --- a/include/linux/dma-contiguous.h +++ b/include/linux/dma-contiguous.h @@ -90,6 +90,8 @@ void dma_contiguous_reserve(phys_addr_t addr_limit); int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base, phys_addr_t limit, struct cma **res_cma); +int dma_contiguous_init_reserved_mem(phys_addr_t size, phys_addr_t base, + struct cma **res_cma); /** * dma_declare_contiguous() - reserve area for contiguous memory handling * for particular device @@ -140,6 +142,11 @@ static inline int dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base return -ENOSYS; } +static inline int dma_contiguous_init_reserved_mem(phys_addr_t size, + phys_addr_t base, struct cma **res_cma) { + return -ENOSYS; +} + static inline int dma_declare_contiguous(struct device *dev, phys_addr_t size, phys_addr_t base, phys_addr_t limit)