From patchwork Tue Feb 4 12:09:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 24091 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vb0-f70.google.com (mail-vb0-f70.google.com [209.85.212.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E4E0820445 for ; Tue, 4 Feb 2014 12:10:26 +0000 (UTC) Received: by mail-vb0-f70.google.com with SMTP id w17sf21313429vbj.9 for ; Tue, 04 Feb 2014 04:10:25 -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=0H4Gi4LGdJShSRSiO7K6znzstOhcOWUugnP0yHyj884=; b=A9vbSydqeGP+moONfkxWQzL9hG1jL/aKEZF/EOiEU9JPEmpbLyLuNZE2lFGJbrhCCj eKyfThoee8rEGp/6ctPNUcY2ejnEngyF2dVIe7jr4JsgxNtycI316LthtaLw92Z/V9dl RsR54DNmRHmcZ2UrXoHIt7hKPwW4EqbLA3Nb8MRfg1aVmvxm124IGB4XipSbo6+W6Ko7 quRFsxo2cotUq9o91gJykd9DQrUByWHwfYUgbmRONAOSd1Z9BISCgqdZh7AjR2IWiZz9 dHNNCsrEgBU/qbgA1EC3z0ksnhsO8RnB5KAIejTxietfNBP74R0W4Eo7ZEw6zrv/l/Un JuTw== X-Gm-Message-State: ALoCoQmulvn1TyzExzEALNc7iT7QiGOv9NWOT6Qq1DZgYMWBaBk2+fmMMEzgFKa6X6Mgaf0IxoSY X-Received: by 10.236.78.232 with SMTP id g68mr14494116yhe.19.1391515825609; Tue, 04 Feb 2014 04:10:25 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.89.38 with SMTP id u35ls2388055qgd.60.gmail; Tue, 04 Feb 2014 04:10:25 -0800 (PST) X-Received: by 10.58.90.202 with SMTP id by10mr31472500veb.6.1391515825516; Tue, 04 Feb 2014 04:10:25 -0800 (PST) Received: from mail-vb0-f50.google.com (mail-vb0-f50.google.com [209.85.212.50]) by mx.google.com with ESMTPS id uo16si8034346veb.86.2014.02.04.04.10.25 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 04 Feb 2014 04:10:25 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.50 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.50; Received: by mail-vb0-f50.google.com with SMTP id w8so5634098vbj.37 for ; Tue, 04 Feb 2014 04:10:25 -0800 (PST) X-Received: by 10.52.121.113 with SMTP id lj17mr3269322vdb.21.1391515825421; Tue, 04 Feb 2014 04:10:25 -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 u4csp229324vcz; Tue, 4 Feb 2014 04:10:24 -0800 (PST) X-Received: by 10.180.219.66 with SMTP id pm2mr11826479wic.60.1391515824352; Tue, 04 Feb 2014 04:10:24 -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 pd8si6026348wic.87.2014.02.04.04.10.23 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 04 Feb 2014 04:10:24 -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 1WAeoe-0006H6-U4; Tue, 04 Feb 2014 12:09:24 +0000 Received: from mailout3.samsung.com ([203.254.224.33]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1WAeoY-0006GL-GF for linaro-mm-sig@lists.linaro.org; Tue, 04 Feb 2014 12:09:18 +0000 Received: from epcpsbgm1.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout3.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0N0H007F10GT9M70@mailout3.samsung.com> for linaro-mm-sig@lists.linaro.org; Tue, 04 Feb 2014 21:10:05 +0900 (KST) X-AuditID: cbfee61a-b7fb26d00000724f-73-52f0d89d717b Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id 71.0C.29263.D98D0F25; Tue, 04 Feb 2014 21:10:05 +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 <0N0H006N40FZEA91@mmp1.samsung.com>; Tue, 04 Feb 2014 21:10:05 +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 Date: Tue, 04 Feb 2014 13:09:30 +0100 Message-id: <1391515773-6112-3-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1391515773-6112-1-git-send-email-m.szyprowski@samsung.com> References: <1391515773-6112-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprNIsWRmVeSWpSXmKPExsVy+t9jAd25Nz4EGfyYoWTxd9IxdosPTa3M FvOPnGO16H+zkNXiwJ8djBZvejtYLHaue8docbbpDbvF9s4Z7BZfrjxkstj0+BqrxcK2JSwW l3fNYbNYe+Quu8WGlweZLJZev8hkseB4C6vFn+lyFqeuf2azmDB9LYvFpvtrGS3+bt/EYvHq YBuLxfoZr1ksVu36w+gg6bFm3hpGj9+/JjF6vJ48gdHjcl8vk8fOWXfZPXretLB63Lm2h81j 85J6j9v/HjN7XDnRxOqx7s8rJo/+vwYefVtWMXp83iTnsXFuaAB/FJdNSmpOZllqkb5dAlfG 3ndzmQq2K1Qsej2RsYGxS7qLkZNDQsBE4t2S3ywQtpjEhXvr2boYuTiEBBYxSpybtZcFwmll kjhx8S0zSBWbgKFE19suNhBbRGAho8TneWBFzALT2CQ+L3zJCpIQFvCXuN3QA9bAIqAq8ejK PnYQm1fAXeLN5qtMXYwcQOsUJOZMsgEJcwp4SKy4/Z8NJCwEVLJ+oecERt4FjAyrGEVTC5IL ipPScw31ihNzi0vz0vWS83M3MYKj7JnUDsaVDRaHGAU4GJV4eBVUPgQJsSaWFVfmHmKU4GBW EuE13wYU4k1JrKxKLcqPLyrNSS0+xCjNwaIkznug1TpQSCA9sSQ1OzW1ILUIJsvEwSnVwBi1 sdnyl5nPJJMvx8RPu5ecfx9ZtpEv6BzDrxkX76a59tesm+sq/zthZmhIqfnTCM83FZ8u7Qxc IJdSXNV5oP36bxGGuslGzrdaduz62XOp7moGh9/RjU1+f3oYTWqzz8yN+/Q0O6buvzBfN4PI 9/wJtr4xKoea3Tc4mVwJ2Dn71pz69DkLfyqxFGckGmoxFxUnAgCpAFsMrgIAAA== Cc: Mark Rutland , Pawel Moll , Arnd Bergmann , Stephen Warren , Josh Cartwright , Benjamin Herrenschmidt , Tomasz Figa , Olof Johansson , Tomasz Figa , Michal Nazarewicz , Rob Herring , Kyungmin Park , Kumar Gala , Grant Likely , Ian Campbell , Sascha Hauer Subject: [Linaro-mm-sig] [PATCH v2 2/5] drivers: of: implement reserved-memory handling for dma 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.212.50 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 From: Josh Cartwright Add support for handling 'shared-dma-pool' reserved-memory nodes using dma exclusive driver (dma_alloc_coherent()). Cc: Benjamin Herrenschmidt Cc: Laura Abbott Signed-off-by: Josh Cartwright Signed-off-by: Marek Szyprowski --- drivers/of/Kconfig | 7 ++++ drivers/of/Makefile | 1 + drivers/of/of_reserved_mem_dma.c | 78 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 drivers/of/of_reserved_mem_dma.c diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig index aba13df56f3a..7ac330473ec9 100644 --- a/drivers/of/Kconfig +++ b/drivers/of/Kconfig @@ -81,4 +81,11 @@ config OF_RESERVED_MEM help Helpers to allow for reservation of memory regions +config OF_RESERVED_MEM_DMA + depends on OF_RESERVED_MEM + depends on HAVE_GENERIC_DMA_COHERENT + def_bool y + help + Helpers for reserving memory regions for DMA use + endmenu # OF diff --git a/drivers/of/Makefile b/drivers/of/Makefile index ed9660adad77..6142227ca854 100644 --- a/drivers/of/Makefile +++ b/drivers/of/Makefile @@ -10,3 +10,4 @@ obj-$(CONFIG_OF_PCI) += of_pci.o obj-$(CONFIG_OF_PCI_IRQ) += of_pci_irq.o obj-$(CONFIG_OF_MTD) += of_mtd.o obj-$(CONFIG_OF_RESERVED_MEM) += of_reserved_mem.o +obj-$(CONFIG_OF_RESERVED_MEM_DMA) += of_reserved_mem_dma.o diff --git a/drivers/of/of_reserved_mem_dma.c b/drivers/of/of_reserved_mem_dma.c new file mode 100644 index 000000000000..53a4cac6084a --- /dev/null +++ b/drivers/of/of_reserved_mem_dma.c @@ -0,0 +1,78 @@ +/* + * Device tree based initialization code for DMA reserved regions. + * + * Copyright (c) 2013, The Linux Foundation. All Rights Reserved. + * Copyright (c) 2013 Samsung Electronics Co., Ltd. + * http://www.samsung.com + * Author: Marek Szyprowski + * Author: Josh Cartwright + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License or (at your optional) any later version of the license. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static void rmem_dma_device_init(struct reserved_mem *rmem, + struct device *dev, + struct of_phandle_args *args) +{ + dma_declare_coherent_memory(dev, rmem->base, rmem->base, + rmem->size, DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE); +} + +static void rmem_dma_device_release(struct reserved_mem *rmem, + struct device *dev) +{ + dma_release_declared_memory(dev); +} + +static const struct reserved_mem_ops rmem_dma_ops = { + .device_init = rmem_dma_device_init, + .device_release = rmem_dma_device_release, +}; + +static int __init rmem_dma_setup(struct reserved_mem *rmem, + unsigned long node, + const char *uname) +{ + int err; + + if (of_get_flat_dt_prop(node, "reusable", NULL)) + return -EINVAL; + + err = of_parse_flat_dt_reg(node, uname, &rmem->base, &rmem->size); + if (!err) + goto out_done; + + err = of_parse_flat_dt_size(node, uname, &rmem->size); + if (err) + goto out_err; + + rmem->base = memblock_alloc_base(rmem->size, PAGE_SIZE, + MEMBLOCK_ALLOC_ANYWHERE); + memblock_free(rmem->base, rmem->size); + +out_done: + rmem->ops = &rmem_dma_ops; + pr_info("Reserved memory: created DMA memory pool at %pa, size %ld MiB\n", + &rmem->base, (unsigned long)rmem->size / SZ_1M); + + return memblock_remove(rmem->base, rmem->size); + +out_err: + pr_err("Reserved memory: unable to setup '%s' memory region for DMA.\n", + uname); + return err; +} +RESERVEDMEM_OF_DECLARE(dma, "shared-dma-pool", rmem_dma_setup);