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: 24092 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f197.google.com (mail-qc0-f197.google.com [209.85.216.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 554E820445 for ; Tue, 4 Feb 2014 12:10:34 +0000 (UTC) Received: by mail-qc0-f197.google.com with SMTP id e16sf20939508qcx.8 for ; Tue, 04 Feb 2014 04:10:33 -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=aBfNfobwga1lrV56liTaoWDcc0NRtkb6zro9i7BZV1w=; b=M+vurSgpvErJUuuFcUuHZmyRaV03cagcxqN9VqQqOINhcAXF8hluhSu7CitHoxU5Bc M+jC2pVbKgoo1fOgi6/s6G/V1bg50m3ojyLhLW3TRctmTKYtWuUNHx7eL7DGTx0lAOOD kmRO5zKk2dlvVPUJNbOIHaUJIRHc6sfftsHIH9gw0vXOtBLEVqRP7RIJqmrqmesxOsWW mufDz49Pf1NypFbuAnfYWCJhT2DF1VfGM9wPlL9dRGCEeDbfi4fcKX6dZvToeDDVke3l eNZ8x6o2her/G86sG50ThdYSsMo1mHE1qdIz983L966CbOkwx2SEUrCHYx0/BZfAKSMs Mtow== X-Gm-Message-State: ALoCoQmrw4nLjcWaFvWsVWm5Nku4EKGOf6Dr/x9uHO36O0VWBCnU/ZK50SjpF1lL9zS64ikSRzcw X-Received: by 10.236.14.100 with SMTP id c64mr14620837yhc.38.1391515833154; Tue, 04 Feb 2014 04:10:33 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.102.49 with SMTP id v46ls2293518qge.6.gmail; Tue, 04 Feb 2014 04:10:33 -0800 (PST) X-Received: by 10.220.133.80 with SMTP id e16mr32812273vct.13.1391515833058; Tue, 04 Feb 2014 04:10:33 -0800 (PST) Received: from mail-vb0-f41.google.com (mail-vb0-f41.google.com [209.85.212.41]) by mx.google.com with ESMTPS id w5si8081101vcn.26.2014.02.04.04.10.33 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 04 Feb 2014 04:10:33 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.41 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.41; Received: by mail-vb0-f41.google.com with SMTP id g10so5836907vbg.28 for ; Tue, 04 Feb 2014 04:10:33 -0800 (PST) X-Received: by 10.220.2.199 with SMTP id 7mr32535742vck.4.1391515832934; Tue, 04 Feb 2014 04:10:32 -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 u4csp229334vcz; Tue, 4 Feb 2014 04:10:31 -0800 (PST) X-Received: by 10.14.183.132 with SMTP id q4mr2299717eem.91.1391515831153; Tue, 04 Feb 2014 04:10:31 -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 w2si41859402eeg.7.2014.02.04.04.10.29 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 04 Feb 2014 04:10:31 -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 1WAeon-0006Ht-Ez; Tue, 04 Feb 2014 12:09:33 +0000 Received: from mailout1.samsung.com ([203.254.224.24]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1WAeog-0006Gx-VC for linaro-mm-sig@lists.linaro.org; Tue, 04 Feb 2014 12:09:27 +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 linaro-mm-sig@lists.linaro.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 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 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 3/5] drivers: of: implement reserved-memory handling for cma 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.41 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 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);