From patchwork Thu Feb 20 10:52:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 25005 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f199.google.com (mail-ob0-f199.google.com [209.85.214.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E4EF62066E for ; Thu, 20 Feb 2014 10:53:34 +0000 (UTC) Received: by mail-ob0-f199.google.com with SMTP id uz6sf6324674obc.6 for ; Thu, 20 Feb 2014 02:53:34 -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=drXxCCsuARGs08gfpn9m9HPIAcOIxY2PLXfkcNYEguk=; b=cvAexOeWNH1qHI8FLXZEDZpDrXpl+MLxJnPAFyHuyuR4XnvqlHaw82Ez64tjFa7Znl IpHLXkpIZVKYEzZzQkksA9SRqfWwLy36bFylBgl4I31gWHOaO4Inw43wtadYQm/vl/50 F38cEA32T++Fe5/hcWoULcHLkEKhymv79p3i61e3edJUFGe6LY8XpNRiebE+t5bAt0tT ziDrkocXm4ERCHPrNPuA0beSzugNURnTBfMbuIJjCBWVlUz4ufRnnwp4RSK+zeUSqIDG TfUa2A5A1qN6jAF4KU1KeE9zQgdbHP/Ew0TOCUJfKMfTyavjRJzLerR70xnyS3SubjWe AByw== X-Gm-Message-State: ALoCoQl1UbyWp48QsNn8ePRW8L7gXmJjtYCdDB/Ju/4FOFmThkyfQI0gE6g/1Z0FafK7EjyWcEnF X-Received: by 10.182.87.2 with SMTP id t2mr486927obz.2.1392893614341; Thu, 20 Feb 2014 02:53:34 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.42.14 with SMTP id b14ls481046qga.47.gmail; Thu, 20 Feb 2014 02:53:34 -0800 (PST) X-Received: by 10.220.110.69 with SMTP id m5mr576532vcp.55.1392893614214; Thu, 20 Feb 2014 02:53:34 -0800 (PST) Received: from mail-ve0-f170.google.com (mail-ve0-f170.google.com [209.85.128.170]) by mx.google.com with ESMTPS id b2si1309163vcy.85.2014.02.20.02.53.34 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 20 Feb 2014 02:53:34 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.170 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.170; Received: by mail-ve0-f170.google.com with SMTP id oz11so1674848veb.29 for ; Thu, 20 Feb 2014 02:53:34 -0800 (PST) X-Received: by 10.52.246.227 with SMTP id xz3mr472732vdc.95.1392893614124; Thu, 20 Feb 2014 02:53:34 -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 u4csp48383vcz; Thu, 20 Feb 2014 02:53:33 -0800 (PST) X-Received: by 10.15.52.66 with SMTP id o42mr1073223eew.89.1392893613098; Thu, 20 Feb 2014 02:53:33 -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 a41si7678384eef.155.2014.02.20.02.53.32 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 20 Feb 2014 02:53:33 -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 1WGREj-0007VX-Bn; Thu, 20 Feb 2014 10:52:13 +0000 Received: from mailout3.w1.samsung.com ([210.118.77.13]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1WGREL-0007TP-DR for linaro-mm-sig@lists.linaro.org; Thu, 20 Feb 2014 10:51:49 +0000 Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout3.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0N1A000FEJKA1O00@mailout3.w1.samsung.com> for linaro-mm-sig@lists.linaro.org; Thu, 20 Feb 2014 10:52:58 +0000 (GMT) X-AuditID: cbfec7f4-b7f796d000005a13-4e-5305de8935c1 Received: from eusync2.samsung.com ( [203.254.199.212]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id 3E.4C.23059.98ED5035; Thu, 20 Feb 2014 10:52:57 +0000 (GMT) Received: from amdc1339.mshome.net ([106.116.147.30]) by eusync2.samsung.com (Oracle Communications Messaging Server 7u4-23.01 (7.0.4.23.0) 64bit (built Aug 10 2011)) with ESMTPA id <0N1A005WSJK1HXB0@eusync2.samsung.com>; Thu, 20 Feb 2014 10:52:57 +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: Thu, 20 Feb 2014 11:52:43 +0100 Message-id: <1392893567-31623-4-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1392893567-31623-1-git-send-email-m.szyprowski@samsung.com> References: <1392893567-31623-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAAyXRa0iTYRjG8Z7tPTkavC6NNwmTlXRC0wh7MokIiSciCSYhgeScSyU3ZWvS gkh0mpvnhTjE1obahzG1ZngYRW4utaSYeVimTsvRUJenSVlOyeG338X9/3ZTbF4dFkHlSu+L ZVJhHp/gYMM7g2MxajcuiJusPw+3tQMkXC0uZcOVF5UAPnd8xmGNz4jDvkAPgL6qcgz2ti8D +KnYR8JutY6EG2PfWdAyP4FDY1kLBketTQRsc8yQ8OWCjQVbXSMsaBhU4TDQEAk/uvwENDua SVjb0IbB0rcOEm53WzC4aCvDYIduCYMmawDAhbUh7PJhZNabAdr6pwVo6WktQKPVVSzU2zhD okqfCkcWk5pA0xNvCNTZ8hhN7cyz0dhQMY7aA4ssVLMdh55ZqwGqfm0CyG+JvBl6m5OUJc7L LRTLzlzK4OS0fp0jC3QxD0o+GEARUEVrQAjF0OeYLz+6sD0fZJzuDkIDOBSPbgWMba4C3xsV LMZZ5yGDFUHHM5pfGiLoMNoIGL8eC0ZsepZgykcqWcHDAfoWszLu3TVFYXQ0s2yVBsmlEfN+ LS1Iho5imrRJwTiEvsaUuGfwoHm7hbVxFK8FXAPYZwLhYoWoQJ6ZLYmPlQslcoU0O1aUL7GA vTdu9IDmgUQ7oCnA389Nc2ECHi4slCsldsBQbH4Yt2sSF/C4WULlQ7Es/45MkSeW2wGLCoko AsfOKqwXRSZPYjK9eiHVcCJrqdXu1FccCeOZQzfv1aScDK9r8xolx3sUdj0pULrT/mRrlTa2 c0rc59MVqW78XuV3P/EPpwYcjZ3J6un+aM/fn5lXEqI207lJ7fId5aPT7zIO3TV883r7jVvL 40dF7Ospr9br1696ZksD6QkuPibPEcafYsvkwv+Hdgt3pAIAAA== 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 v4 3/7] 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.128.170 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 | 130 ++++++++++++++++++++++++++++++++++------- 1 file changed, 108 insertions(+), 22 deletions(-) diff --git a/drivers/base/dma-contiguous.c b/drivers/base/dma-contiguous.c index 165c2c299e57..5dfcc3743d9b 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,62 @@ 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 of_phandle_args *args) +{ + 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