From patchwork Tue Feb 18 13:37:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 3670531 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id ECDD2BF13A for ; Tue, 18 Feb 2014 13:41:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5EF6D20176 for ; Tue, 18 Feb 2014 13:41:43 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5840C20163 for ; Tue, 18 Feb 2014 13:41:42 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WFkvK-00039S-4N; Tue, 18 Feb 2014 13:41:22 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WFkv9-0003iZ-Te; Tue, 18 Feb 2014 13:41:11 +0000 Received: from mailout1.samsung.com ([203.254.224.24]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WFkv7-0003hG-2s for linux-arm-kernel@lists.infradead.org; Tue, 18 Feb 2014 13:41:10 +0000 Received: from epcpsbgm2.samsung.com (epcpsbgm2 [203.254.230.27]) by mailout1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0N1700JZC1ZYORB0@mailout1.samsung.com> for linux-arm-kernel@lists.infradead.org; Tue, 18 Feb 2014 22:40:46 +0900 (KST) X-AuditID: cbfee61b-b7f456d000006dfd-97-530362de2f2c Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id A8.D3.28157.ED263035; Tue, 18 Feb 2014 22:40:46 +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:40:46 +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 Subject: [PATCH v3 3/6] drivers: of: implement reserved-memory handling for dma Date: Tue, 18 Feb 2014 14:37:58 +0100 Message-id: <1392730681-14695-4-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: H4sIAAAAAAAAAzWRa0hTYQCG+845OzsbLk7L6uhQamG1UHPajw+0sB/F168KiUDoMvWgK6dz U9EIGrZpW3lhJl6wualBDC+5aVOxcHPZzSQvKZQaMirUVeKkxDbNGf17Xt4H3h8vhQvNRDgl z8lnVTmybDHJJ95ueOiYuTQ8JW7t3mEYMA5z4XKJDodN7lEOrPRaOHDQ3wugt/wuAfs6fgD4 rsTLhQ59HReuTs5j0OaZ4kBLaSsBJ/obSdjunuXCJwtODD6aHsOg+aWWA/21kfDNtI+EVbXt BNQ9c3NhwGEj4KKzlICddUsEtPb7QXIYajO1AfRn3QjQUnUVQBMV5Rjqa5jlovteLQfZrHoS zUwNkMjeeht92vDgaPJVCQd1+BcxVBmIQxXdVoB8tkjU9fDieTqVn5TBZssLWdWxk9f4Wa/n A6SyLqLow0gNpgEWxgB4FEMfZ3w14+Af72Xez3WSBsCnhHQzYLrMQ/i/oMOYO8PNeNAiaSlj +G4ggxxKWwDjMxFBCadrSaal5+d2sZs+x3Tr27hBJugoZnZ8BQuygEaM9vcUxwCorbn9TKMx KYg8+iyzOh0dNIRbRs9nD14FBGawwwr2sMp0pTotUxEfq5Yp1AU5mbHpuQob2P7tq6gXWDXQ BWgKiEMEywexFCFHVqguVrgAQ+HiUIEkFU8RCjJkxTdZVe5VVUE2q3YBEUWI9wmcusQLQjpT ls/eYFklq/rfYhQvXAMa8s7YE+z1Ubd6/KKyvBh/9QBbFv8ibMKh2ilMOfCLJ5EnPq0fOcSN cC7bo3axYfmW5oV1icJkON1EmcbpsZlk5eCmXPtYuhaSJxkdcogScskHK7aELlh0qkZvvOyK 1LqjKxtaoKYPPzJ0qUn6zXHl4/Pr1Sbe5gmdl/4iJtRZMulRXKWW/QXgox3lswIAAA== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140218_084109_370972_D6643BA7 X-CRM114-Status: GOOD ( 16.14 ) X-Spam-Score: -4.6 (----) Cc: Mark Rutland , Laura Abbott , Pawel Moll , Arnd Bergmann , Stephen Warren , Josh Cartwright , Benjamin Herrenschmidt , Tomasz Figa , Tomasz Figa , Michal Nazarewicz , Olof Johansson , Kyungmin Park , Rob Herring , Kumar Gala , Grant Likely , Ian Campbell , Nishanth Peethambaran , Sascha Hauer , Marc , Marek Szyprowski X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 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+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,KHOP_BIG_TO_CC, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Josh Cartwright Add support for handling 'shared-dma-pool' reserved-memory nodes using dma exclusive driver (dma_alloc_coherent()). 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 | 65 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 drivers/of/of_reserved_mem_dma.c diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig index f25931dfc6db..7f00b801bcd2 100644 --- a/drivers/of/Kconfig +++ b/drivers/of/Kconfig @@ -80,4 +80,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..a3e596d1091d --- /dev/null +++ b/drivers/of/of_reserved_mem_dma.c @@ -0,0 +1,65 @@ +/* + * Device tree based initialization code for DMA reserved regions. + * + * Copyright (c) 2013, The Linux Foundation. All Rights Reserved. + * Copyright (c) 2013,2014 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 = memblock_remove(rmem->base, rmem->size); + if (err == 0) { + 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); + } else { + 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);