From patchwork Tue Feb 4 12:09:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 3575571 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 32372C02DC for ; Tue, 4 Feb 2014 12:12:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4457B20163 for ; Tue, 4 Feb 2014 12:12:22 +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 3332B2015E for ; Tue, 4 Feb 2014 12:12:21 +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 1WAeqD-0007Jn-9s; Tue, 04 Feb 2014 12:11:01 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WAepy-0005wT-S1; Tue, 04 Feb 2014 12:10:46 +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 1WAepc-0005rB-RC for linux-arm-kernel@lists.infradead.org; Tue, 04 Feb 2014 12:10:26 +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 <0N0H00MMU0H24Q30@mailout1.samsung.com> for linux-arm-kernel@lists.infradead.org; Tue, 04 Feb 2014 21:10:14 +0900 (KST) X-AuditID: cbfee61b-b7f456d000006dfd-3b-52f0d8a5358b Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id E3.B0.28157.5A8D0F25; Tue, 04 Feb 2014 21:10:13 +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:13 +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 v2 3/5] drivers: of: implement reserved-memory handling for cma Date: Tue, 04 Feb 2014 13:09:31 +0100 Message-id: <1391515773-6112-4-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+NgFprJIsWRmVeSWpSXmKPExsVy+t9jAd2lNz4EGZy8Ym3xd9IxdosPTa3M FvOPnGO16H+zkNXiwJ8djBZvejtYLHaue8docbbpDbvF9s4Z7BZfrjxkstj0+BqrxcK2JSwW l3fNYbNYe+Quu8WGlweZLJZev8hkseB4C6vFn+lyFqeuf2azmDB9LYvFpvtrGS3+bt/EYvHq YBuLxfoZr1ksVu36w+gg6bFm3hpGj9+/JjF6vJ48gdHjcl8vk8fOWXfZPXretLB63Lm2h81j 85J6j9v/HjN7XDnRxOqx7s8rJo/+vwYefVtWMXp83iTnsXFuaAB/FJdNSmpOZllqkb5dAlfG jMYW5oJ58hWPj01iaWD8LdnFyMEhIWAisXi+WRcjJ5ApJnHh3nq2LkYuDiGBRYwSHXeWskI4 rUwSf57eZAOpYhMwlOh62wVmiwgsZJT4PI8FpIhZYBqbxOeFL1lBEsIC/hJnVjxmAdnAIqAq 0bZdAiTMK+AucazxPivEYgWJOZNsQMKcAh4SK27/ZwMJCwGVrF/oOYGRdwEjwypG0dSC5ILi pPRcI73ixNzi0rx0veT83E2M4Ah7Jr2DcVWDxSFGAQ5GJR5eBZUPQUKsiWXFlbmHGCU4mJVE eM23AYV4UxIrq1KL8uOLSnNSiw8xSnOwKInzHmy1DhQSSE8sSc1OTS1ILYLJMnFwSjUwqm74 V6OdIbkqLqDD88rxrTyHt6i9j3/F80zh3tYb8xekf9mbcFzp0ex7kVIuKb0Xyxr5Gfc2ZrQL dWa+X35yTVufSKql9rz9T5+9Di2YsX3tQkkpledH3TfNFRafxPUzYPfl07smN7koFbSwHmkK Nj5wWUVqbkK1ncp9rzNbz000KP1W3XtCQImlOCPRUIu5qDgRAEaq8AisAgAA X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140204_071025_138115_7A1D29D9 X-CRM114-Status: GOOD ( 16.69 ) X-Spam-Score: -7.5 (-------) Cc: Mark Rutland , Laura Abbott , 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 , 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=-4.8 required=5.0 tests=BAYES_00, 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 Contiguous Memory Allocator driver. 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_cma.c | 75 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 drivers/of/of_reserved_mem_cma.c diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig index 7ac330473ec9..5dd3a80910d2 100644 --- a/drivers/of/Kconfig +++ b/drivers/of/Kconfig @@ -81,6 +81,13 @@ config OF_RESERVED_MEM help Helpers to allow for reservation of memory regions +config OF_RESERVED_MEM_CMA + depends on OF_RESERVED_MEM + depends on DMA_CMA + def_bool y + help + Helpers for reserving memory regions for DMA use + config OF_RESERVED_MEM_DMA depends on OF_RESERVED_MEM depends on HAVE_GENERIC_DMA_COHERENT diff --git a/drivers/of/Makefile b/drivers/of/Makefile index 6142227ca854..49b9078637b8 100644 --- a/drivers/of/Makefile +++ b/drivers/of/Makefile @@ -10,4 +10,5 @@ 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_CMA) += of_reserved_mem_cma.o obj-$(CONFIG_OF_RESERVED_MEM_DMA) += of_reserved_mem_dma.o diff --git a/drivers/of/of_reserved_mem_cma.c b/drivers/of/of_reserved_mem_cma.c new file mode 100644 index 000000000000..601d80655102 --- /dev/null +++ b/drivers/of/of_reserved_mem_cma.c @@ -0,0 +1,75 @@ +/* + * 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 + +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) +{ + struct cma *cma; + 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; + + rmem->base = 0; + err = of_parse_flat_dt_size(node, uname, &rmem->size); + if (err) + goto out_err; + +out_done: + err = dma_contiguous_reserve_area(rmem->size, rmem->base, 0, + &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; + + return 0; +out_err: + pr_err("Reseved memory: malformed node '%s'.\n", uname); + return err; +} +RESERVEDMEM_OF_DECLARE(cma, "shared-dma-pool", rmem_cma_setup);