From patchwork Fri Feb 28 13:42:53 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 25557 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pb0-f69.google.com (mail-pb0-f69.google.com [209.85.160.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 15F1D20543 for ; Fri, 28 Feb 2014 13:44:05 +0000 (UTC) Received: by mail-pb0-f69.google.com with SMTP id md12sf1677630pbc.0 for ; Fri, 28 Feb 2014 05:44:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:cc:subject:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list:content-type :content-transfer-encoding; bh=OQeYqyYeu8sIiBBgPDG8x2wlqJdJhsdhRwl1Lzr8qtM=; b=FEz9uY8Sfi2q3IhXPGX3yO3y03yuBNH0GJ2DblrVUrCaVUVEcVCa2Ef4d+2mTYBKDl yunWCofD58Jo0DlPkrFjlyJimhixJiov5YoM/Sb31nfuCJ7dFSZJhu10PHkSqsiuqj1r XxpQDhN2FMuyR9Yl0S8MrYzbA2Z37AjwMRlYadVNWLpSuYseNt/IDhzre/1qphaXighW HU1VcgX+S4cLhcaZcgIw5m+apCJOxe2MtniVN5QyrMuO7728d9D0p7kb82//qBco47I2 h3OTnKjLRMIi2uqyf8jnjKlyjB+fiHHYvIdv+XzpJks+BUWlBs5gEAbLwTQfyONic2lX lEDg== X-Gm-Message-State: ALoCoQmoTtis08P8yIh84HLWG2XcAjap7HRTT6Wk9Q3jllSYkrQPjYlHLnu29tf7Z1G3vkq22Sbg X-Received: by 10.66.189.163 with SMTP id gj3mr1183069pac.32.1393595045186; Fri, 28 Feb 2014 05:44:05 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.104.142 with SMTP id a14ls1093745qgf.31.gmail; Fri, 28 Feb 2014 05:44:05 -0800 (PST) X-Received: by 10.58.49.129 with SMTP id u1mr2759703ven.0.1393595045024; Fri, 28 Feb 2014 05:44:05 -0800 (PST) Received: from mail-vc0-f172.google.com (mail-vc0-f172.google.com [209.85.220.172]) by mx.google.com with ESMTPS id gq1si266936vec.23.2014.02.28.05.44.04 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 28 Feb 2014 05:44:05 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.172 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.172; Received: by mail-vc0-f172.google.com with SMTP id lf12so721437vcb.31 for ; Fri, 28 Feb 2014 05:44:04 -0800 (PST) X-Received: by 10.220.147.16 with SMTP id j16mr2703352vcv.28.1393595044872; Fri, 28 Feb 2014 05:44:04 -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.130.193 with SMTP id u1csp54627vcs; Fri, 28 Feb 2014 05:44:04 -0800 (PST) X-Received: by 10.15.31.137 with SMTP id y9mr20912634eeu.12.1393595043777; Fri, 28 Feb 2014 05:44:03 -0800 (PST) Received: from ip-10-141-164-156.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id z8si6233783eee.83.2014.02.28.05.44.03 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 28 Feb 2014 05:44:03 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-141-164-156.ec2.internal) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1WJNhx-0008Lx-Mn; Fri, 28 Feb 2014 13:42:33 +0000 Received: from mailout2.w1.samsung.com ([210.118.77.12]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1WJNhL-0008Hn-Qa for linaro-mm-sig@lists.linaro.org; Fri, 28 Feb 2014 13:41:55 +0000 Received: from eucpsbgm2.samsung.com (unknown [203.254.199.245]) by mailout2.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0N1P00G3HKS0WO80@mailout2.w1.samsung.com> for linaro-mm-sig@lists.linaro.org; Fri, 28 Feb 2014 13:43:12 +0000 (GMT) X-AuditID: cbfec7f5-b7fc96d000004885-46-53109275fd4d Received: from eusync3.samsung.com ( [203.254.199.213]) by eucpsbgm2.samsung.com (EUCPMTA) with SMTP id 59.BE.18565.57290135; Fri, 28 Feb 2014 13:43:17 +0000 (GMT) Received: from amdc1339.mshome.net ([106.116.147.30]) by eusync3.samsung.com (Oracle Communications Messaging Server 7u4-23.01 (7.0.4.23.0) 64bit (built Aug 10 2011)) with ESMTPA id <0N1P002ZJKROU750@eusync3.samsung.com>; Fri, 28 Feb 2014 13:43:17 +0000 (GMT) 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 Date: Fri, 28 Feb 2014 14:42:53 +0100 Message-id: <1393594976-16728-9-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1393594976-16728-1-git-send-email-m.szyprowski@samsung.com> References: <1393594976-16728-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAAyXRXUhTYRzHcZ/tnLPjaHictp5MLFZ2IWqaXjyWZN09XgTSICJKWzpfyE3d 2kijlOX765qRJqaONi/WnLYSnSk4WWrKfM8RpiIKOZ2WaBA2JYd339+fz92fZvNfEkF0luyx RC4TZwspLjF+OPItQqllRFGO8lB0oB3moN/qEjb61V4NUKt9gkR1bh2JBj29ALlryglkNW8D 5FC7OainopGD9uZWWMiyOk8iXameQLN9zRTqsC9yUJfLxkIG5zQLtY0Uk8jTEILGnLsUMtnf cZCmoYNAJQN2DjrosRBow1ZKoM7GTQIZ+zwAuXZGievB2NRiAvjfvhbgzXoNwLO1NSxsbVrk 4Gp3MYktxgoK/5jvp/BHfSFeOFxl47lRNYnNng0WrjuIwm/7agGu/WQEeNcSkuR/lxufJsnO Uknkl6494GbaXHYydy/8iXuQXwTWL1QCXxoysdD6YoJ93AI4tdRJVQIuzWcMAO5sHZLHo4oF N0xlLK+imGhYuVVJeTuQ0QG420J4EZtZpmD5dPURoukA5g783FXoNQQTCrdLWzne5jEY7s8Y KC+BzDnYrI33nn2ZRFjUsEx6m39EFv46gQbw2oCPEZyUKFNzFQ8zpJcjFWKpQinLiEzNkVrA 8Rv/9ALD8JUhwNBAeIKnSfQT8UmxSpEvHQKQZgsDeWtqRsTnpYnzCyTynBS5MluiGAIs2jeo CBQkT94P+W5zr6SNL0bcyL/pQ9/Oi9FGmp3rgq9TZaYPmmTJKbFmckz/1BweDAfaZ+LONIV5 fracrlpLSFLkTqhkVk/nrXR9f17OVr2u+1GASh737H1s+vNX3TGiL/5+CcVLdZbX9wTBYVUX oxyhyGdS4BJdTZGtnK9zwLizb4SEIlMcHcaWK8T/AYvGBVakAgAA Cc: Mark Rutland , Benjamin Herrenschmidt , Tomasz Figa , Will Deacon , Tomasz Figa , Paul Mackerras , Arnd Bergmann , Josh Cartwright , Catalin Marinas , Grant Likely , Ian Campbell , Pawel Moll , Stephen Warren , Sascha Hauer , Michal Nazarewicz , Rob Herring , Kumar Gala , Olof Johansson Subject: [Linaro-mm-sig] [PATCH v6 08/11] drivers: dma-contiguous: add initialization from device tree X-BeenThere: linaro-mm-sig@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: linaro-mm-sig-bounces@lists.linaro.org Sender: linaro-mm-sig-bounces@lists.linaro.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.220.172 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 Refactor internal dma_contiguous_init_reserved_mem() function, which creates CMA area from previously reserved memory region and add support for handling 'shared-dma-pool' reserved-memory device tree nodes. Based on previous code provided by Josh Cartwright Signed-off-by: Marek Szyprowski --- drivers/base/dma-contiguous.c | 129 ++++++++++++++++++++++++++++++++++------- 1 file changed, 107 insertions(+), 22 deletions(-) diff --git a/drivers/base/dma-contiguous.c b/drivers/base/dma-contiguous.c index 165c2c299e57..0efdf1986990 100644 --- a/drivers/base/dma-contiguous.c +++ b/drivers/base/dma-contiguous.c @@ -182,6 +182,49 @@ 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. + */ +static 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++; + + /* 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 +240,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 +247,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 +277,12 @@ 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; + ret = dma_contiguous_init_reserved_mem(size, base, res_cma); + if (ret == 0) { + pr_info("CMA: reserved %ld MiB at %08lx\n", + (unsigned long)size / SZ_1M, (unsigned long)base); + return 0; + } err: pr_err("CMA: failed to reserve %ld MiB\n", (unsigned long)size / SZ_1M); return ret; @@ -357,3 +384,61 @@ bool dma_release_from_contiguous(struct device *dev, struct page *pages, return true; } + +/* + * Support for reserved memory regions defined in device tree + */ +#ifdef CONFIG_OF_RESERVED_MEM +#include +#include +#include + +#undef pr_fmt +#define pr_fmt(fmt) fmt + +static void rmem_cma_device_init(struct reserved_mem *rmem, struct device *dev) +{ + struct cma *cma = rmem->priv; + dev_set_cma_area(dev, cma); +} + +static const struct reserved_mem_ops rmem_cma_ops = { + .device_init = rmem_cma_device_init, +}; + +static int __init rmem_cma_setup(struct reserved_mem *rmem, + unsigned long node, + const char *uname) +{ + phys_addr_t align = PAGE_SIZE << max(MAX_ORDER - 1, pageblock_order); + phys_addr_t mask = align - 1; + struct cma *cma; + int err; + + if (!of_get_flat_dt_prop(node, "reusable", NULL)) + return -EINVAL; + + if ((rmem->base & mask) || (rmem->size & mask)) { + pr_err("Reserved memory: incorrect alignment of CMA region\n"); + return -EINVAL; + } + + err = dma_contiguous_init_reserved_mem(rmem->size, rmem->base, &cma); + if (err) { + pr_err("Reserved memory: unable to setup CMA region\n"); + return err; + } + + if (of_get_flat_dt_prop(node, "linux,cma-default", NULL)) + dma_contiguous_set_default(cma); + + rmem->ops = &rmem_cma_ops; + rmem->priv = cma; + + pr_info("Reserved memory: created CMA memory pool at %pa, size %ld MiB\n", + &rmem->base, (unsigned long)rmem->size / SZ_1M); + + return 0; +} +RESERVEDMEM_OF_DECLARE(cma, "shared-dma-pool", rmem_cma_setup); +#endif