From patchwork Wed Jul 2 10:48:52 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 32968 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f199.google.com (mail-ve0-f199.google.com [209.85.128.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 77DCA20560 for ; Wed, 2 Jul 2014 10:51:27 +0000 (UTC) Received: by mail-ve0-f199.google.com with SMTP id oy12sf28070022veb.2 for ; Wed, 02 Jul 2014 03:51:27 -0700 (PDT) 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:subject:date:message-id :in-reply-to:references:cc:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:content-type:content-transfer-encoding; bh=JpsWiFqmO3IVp1M9IyC09/mLwq+pA9mB+d3VS4+njoQ=; b=jBYGn/CDQRqhasw5qy3upTb9I7X/td7hX9rI+x5NrGTc2RVuVNgj1Ypd2WQLhKRf+2 +KLBN0LBr/Tsu2R9a1FRXw4m3u0U/gfT909bhA++sLGuG0K+BKE7chn8RlMqMfEmD6EG T+H82Gv0EGeIHd2qj9isw3d/5gxHMIh+LktYsNf+ItbvQ/XbPwF5KdRR/DyFJsUEuwiD bDhOYC/Isgr4FSBcquUi0Gdn+ilqDVQwbTzWripGzjylJ/Gi8fA+ldOKSfpjkfk7Nj73 Owq1a0O5NXvdySNk1it0LKHqXLLzmhxARDD7ppBXMsnFVsOEpECI7H/uhps0LwkkUOH0 nRkw== X-Gm-Message-State: ALoCoQnWLGtz0sEaw0AL3tz0lBUS0dv0M9TCEjYjRHLlmHZMnsJRL8YVy8hN7msOaYWyiAiTzmip X-Received: by 10.224.13.67 with SMTP id b3mr27918968qaa.2.1404298287281; Wed, 02 Jul 2014 03:51:27 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.93.166 with SMTP id d35ls2429746qge.3.gmail; Wed, 02 Jul 2014 03:51:27 -0700 (PDT) X-Received: by 10.58.39.42 with SMTP id m10mr47684250vek.29.1404298287167; Wed, 02 Jul 2014 03:51:27 -0700 (PDT) Received: from mail-vc0-f174.google.com (mail-vc0-f174.google.com [209.85.220.174]) by mx.google.com with ESMTPS id ut6si12752971veb.11.2014.07.02.03.51.27 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 02 Jul 2014 03:51:27 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.174 as permitted sender) client-ip=209.85.220.174; Received: by mail-vc0-f174.google.com with SMTP id hy4so10230221vcb.33 for ; Wed, 02 Jul 2014 03:51:27 -0700 (PDT) X-Received: by 10.220.92.135 with SMTP id r7mr48798709vcm.11.1404298287065; Wed, 02 Jul 2014 03:51:27 -0700 (PDT) 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.221.37.5 with SMTP id tc5csp283811vcb; Wed, 2 Jul 2014 03:51:26 -0700 (PDT) X-Received: by 10.66.142.135 with SMTP id rw7mr3215680pab.71.1404298286292; Wed, 02 Jul 2014 03:51:26 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id ff7si29847907pad.240.2014.07.02.03.51.26 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Jul 2014 03:51:26 -0700 (PDT) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) client-ip=2001:1868:205::9; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1X2I6p-0000HU-O6; Wed, 02 Jul 2014 10:49:51 +0000 Received: from mailout4.w1.samsung.com ([210.118.77.14]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1X2I6R-0008Pj-C7 for linux-arm-kernel@lists.infradead.org; Wed, 02 Jul 2014 10:49:28 +0000 Received: from eucpsbgm2.samsung.com (unknown [203.254.199.245]) by mailout4.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0N8200K2WZDKZLA0@mailout4.w1.samsung.com> for linux-arm-kernel@lists.infradead.org; Wed, 02 Jul 2014 11:48:56 +0100 (BST) X-AuditID: cbfec7f5-b7f626d000004b39-3b-53b3e39f7c84 Received: from eusync3.samsung.com ( [203.254.199.213]) by eucpsbgm2.samsung.com (EUCPMTA) with SMTP id 16.F9.19257.F93E3B35; Wed, 02 Jul 2014 11:49:03 +0100 (BST) Received: from amdc1339.digital.local ([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 <0N82004J1ZDILZA0@eusync3.samsung.com>; Wed, 02 Jul 2014 11:49:03 +0100 (BST) 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 Subject: [PATCH 4/4] drivers: dma-contiguous: add initialization from device tree Date: Wed, 02 Jul 2014 12:48:52 +0200 Message-id: <1404298132-6050-5-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.2 In-reply-to: <1404298132-6050-1-git-send-email-m.szyprowski@samsung.com> References: <1404298132-6050-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAAyXRW0iTYRgH8N7ve/d9Uxx9TpMPKRPLpPJcwkOUdWH5XkQEVkQX1tSllqe2 NBUj85TOTZdBkzJ1pKYyNbYLDyk0nQfsZGgqeEgblYeZ5QEiN43p3Y//w5//xSOkxfXYXRif dFcqS5IkeDGO+N1m/xe/KrMhIlCt8YGKFh0D5sVKDLayPhZ+5+TTsFynRFBl+iiAUotWAG+t bQgainMZsKgKMbQ3/0LwIcfCQmtROQtrI7MU6M2jAtAW1GAY7qhgoMk0xcLreSMFtWOfKaju zxOAVeMBg2OrDOhML1lQa5ow5HeZWLC16jEsGAswtJQvYtBWfWWhscOKYP7PAD7jSXSVOkQ2 /pUhsvhEjchwiYoi7c+mWKK05AmIvrGIIYqlEYpMjnYyZKB8A5OZbgMmhpoHZGLTTJORgRwB abYuUKTUFnjR9ZrjyRhpQnyaVBYQesMx7sXDISplKDh9qFzLZKO2wwrkIOS547ymuoresRs/ NN3CKJCjUMzVIn6pdgXbD2KuhOJNbVF2M1wQr1hSMHa7clrEr1Zie4HmVEJ+7s3f7YILF8Fv WH+wdmPOm+/q2aDsFnHhvLHuPbOz5sFvzddv5w4c4V91fkM7Y+G8ybJMq5GoGu1qRHukqdEp 8qjYxGB/uSRRnpoU6x+dnKhHO99db0O1fSe6ESdEXk6iuQB9hFggSZNnJHYjXkh7uYpKxw0R YlGMJCNTKku+LktNkMq7ESV0cM9G7DmYiPzu4a2qD73cUKyK1OTdXDnQFxNqqIDb5obHh8LS Dk6OhVwYiNMtOM1y61370E9n2x3j6HhPzaV2l/3iHuWt508He8Nmdm8ZcYhvurr1apbzadP9 rPj2XqlN6Xf+6N7cK0HH3Hyeq5en1acsnmfRo7V7xmnIpD8pC8t8vbA8ThJ0hJbJJf8BEH9u yrsCAAA= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140702_034927_578104_7A79F8E7 X-CRM114-Status: GOOD ( 18.40 ) X-Spam-Score: -5.0 (-----) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-5.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [210.118.77.14 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [210.118.77.14 listed in wl.mailspike.net] -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders Cc: Mark Rutland , Jon Medhurst , Benjamin Herrenschmidt , Tomasz Figa , Will Deacon , Tomasz Figa , Paul Mackerras , Marek Szyprowski , Arnd Bergmann , Josh Cartwright , Catalin Marinas , Grant Likely , Laura Abbott , Ian Campbell , Pawel Moll , Stephen Warren , Sascha Hauer , Michal Nazarewicz , Marc , Nishanth Peethambaran , Rob Herring , Andrew Morton , "Aneesh Kumar K.V." , Kumar Gala , Olof Johansson , Joonsoo Kim X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: m.szyprowski@samsung.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.174 as permitted sender) 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 Add a code to create CMA region from reserved memory and add support for handling 'shared-dma-pool' reserved-memory device tree nodes. Signed-off-by: Marek Szyprowski --- drivers/base/dma-contiguous.c | 67 +++++++++++++++++++++++++++++++++++++++++ include/linux/cma.h | 3 ++ mm/cma.c | 69 ++++++++++++++++++++++++++++++++----------- 3 files changed, 122 insertions(+), 17 deletions(-) diff --git a/drivers/base/dma-contiguous.c b/drivers/base/dma-contiguous.c index 6606abdf880c..b77ea8bac176 100644 --- a/drivers/base/dma-contiguous.c +++ b/drivers/base/dma-contiguous.c @@ -211,3 +211,70 @@ bool dma_release_from_contiguous(struct device *dev, struct page *pages, { return cma_release(dev_get_cma_area(dev), pages, count); } + +/* + * 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 void rmem_cma_device_release(struct reserved_mem *rmem, + struct device *dev) +{ + dev_set_cma_area(dev, NULL); +} + +static const struct reserved_mem_ops rmem_cma_ops = { + .device_init = rmem_cma_device_init, + .device_release = rmem_cma_device_release, +}; + +static int __init rmem_cma_setup(struct reserved_mem *rmem) +{ + phys_addr_t align = PAGE_SIZE << max(MAX_ORDER - 1, pageblock_order); + phys_addr_t mask = align - 1; + unsigned long node = rmem->fdt_node; + struct cma *cma; + int err; + + if (!of_get_flat_dt_prop(node, "reusable", NULL) || + of_get_flat_dt_prop(node, "no-map", NULL)) + return -EINVAL; + + if ((rmem->base & mask) || (rmem->size & mask)) { + pr_err("Reserved memory: incorrect alignment of CMA region\n"); + return -EINVAL; + } + + err = cma_init_reserved_mem(rmem->base, rmem->size, 0, &cma); + if (err) { + pr_err("Reserved memory: unable to setup CMA region\n"); + return err; + } + /* Architecture specific contiguous memory fixup. */ + dma_contiguous_early_fixup(rmem->base, rmem->size); + + 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 diff --git a/include/linux/cma.h b/include/linux/cma.h index 32cab7a425f9..9a18a2b1934c 100644 --- a/include/linux/cma.h +++ b/include/linux/cma.h @@ -16,6 +16,9 @@ extern int __init cma_declare_contiguous(phys_addr_t size, phys_addr_t base, phys_addr_t limit, phys_addr_t alignment, unsigned int order_per_bit, bool fixed, struct cma **res_cma); +extern int cma_init_reserved_mem(phys_addr_t size, + phys_addr_t base, int order_per_bit, + struct cma **res_cma); extern struct page *cma_alloc(struct cma *cma, int count, unsigned int align); extern bool cma_release(struct cma *cma, struct page *pages, int count); #endif diff --git a/mm/cma.c b/mm/cma.c index 4b251b037e1b..c3d84016d432 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -140,6 +140,54 @@ static int __init cma_init_reserved_areas(void) core_initcall(cma_init_reserved_areas); /** + * cma_init_reserved_mem() - create custom contiguous area from reserved memory + * @base: Base address of the reserved area + * @size: Size of the reserved area (in bytes), + * @order_per_bit: Order of pages represented by one bit on bitmap. + * @res_cma: Pointer to store the created cma region. + * + * This function creates custom contiguous area from already reserved memory. + */ +int __init cma_init_reserved_mem(phys_addr_t base, phys_addr_t size, + int order_per_bit, struct cma **res_cma) +{ + struct cma *cma; + 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; + + /* ensure minimal alignment requied by mm core */ + alignment = PAGE_SIZE << max(MAX_ORDER - 1, pageblock_order); + + /* alignment should be aligned with order_per_bit */ + if (!IS_ALIGNED(alignment >> PAGE_SHIFT, 1 << order_per_bit)) + return -EINVAL; + + if (ALIGN(base, alignment) != base || ALIGN(size, alignment) != size) + return -EINVAL; + + /* + * Each reserved area must be initialised later, when more kernel + * subsystems (like slab allocator) are available. + */ + cma = &cma_areas[cma_area_count]; + cma->base_pfn = PFN_DOWN(base); + cma->count = size >> PAGE_SHIFT; + cma->order_per_bit = order_per_bit; + *res_cma = cma; + cma_area_count++; + + return 0; +} + +/** * cma_declare_contiguous() - reserve custom contiguous area * @base: Base address of the reserved area optional, use 0 for any * @size: Size of the reserved area (in bytes), @@ -162,18 +210,12 @@ int __init cma_declare_contiguous(phys_addr_t base, phys_addr_t alignment, unsigned int order_per_bit, bool fixed, struct cma **res_cma) { - struct cma *cma; - int ret = 0; + int ret; pr_debug("%s(size %lx, base %08lx, limit %08lx alignment %08lx)\n", __func__, (unsigned long)size, (unsigned long)base, (unsigned long)limit, (unsigned long)alignment); - if (cma_area_count == ARRAY_SIZE(cma_areas)) { - pr_err("Not enough slots for CMA reserved regions!\n"); - return -ENOSPC; - } - if (!size) return -EINVAL; @@ -214,16 +256,9 @@ int __init cma_declare_contiguous(phys_addr_t base, } } - /* - * Each reserved area must be initialised later, when more kernel - * subsystems (like slab allocator) are available. - */ - cma = &cma_areas[cma_area_count]; - cma->base_pfn = PFN_DOWN(base); - cma->count = size >> PAGE_SHIFT; - cma->order_per_bit = order_per_bit; - *res_cma = cma; - cma_area_count++; + ret = cma_init_reserved_mem(base, size, order_per_bit, res_cma); + if (ret) + goto err; pr_info("Reserved %ld MiB at %08lx\n", (unsigned long)size / SZ_1M, (unsigned long)base);