From patchwork Tue Feb 18 13:37:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 24843 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f200.google.com (mail-ie0-f200.google.com [209.85.223.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 45651202B2 for ; Tue, 18 Feb 2014 13:41:41 +0000 (UTC) Received: by mail-ie0-f200.google.com with SMTP id to1sf12877656ieb.3 for ; Tue, 18 Feb 2014 05:41:40 -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=qqqzGUiVURdynBfJN2B71QhVx79noaMg3MC6JreT7bU=; b=WnYDA5AAxoCfvI+mABbYgkHd25S0rrihm5jXqIuZ8whzdvl3HTM5uCLCtsTewnBKeM iTiAgyLdbCntSJ19XMjedpJX7ot/Pyonna4zO3qO1CSXdBV1VkuXluyXcG+S31nBQSx9 I56sWIToXUEnVSOX3/JR+kNbFevjRA4a/gqp5CrSXOiuV18VpSISRASZGu+rw/Z1JlY4 Ty0DAeh4nc16DcS004Nqoi7B6VhP6TpXZx3Zokeuq+DpE6ARGXTcqkIkT/h7JLlCYYec 5hS9T2FlrhTNs4V8bTpWyFYu1H8rdUcgf/QHRLGiqWNBTnFY1Fe9k6t6QabCPycjjG+U 4lIg== X-Gm-Message-State: ALoCoQm7jq6t1m+trdAkMjTyLURB3LRgqrKQpvAQ5dCnBdvMyh6vA01Vf4AVwGAJBaTz2Q9lB19g X-Received: by 10.50.20.71 with SMTP id l7mr11072344ige.5.1392730900441; Tue, 18 Feb 2014 05:41:40 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.89.136 with SMTP id v8ls1337425qgd.17.gmail; Tue, 18 Feb 2014 05:41:40 -0800 (PST) X-Received: by 10.52.101.135 with SMTP id fg7mr5267772vdb.17.1392730900280; Tue, 18 Feb 2014 05:41:40 -0800 (PST) Received: from mail-ve0-f177.google.com (mail-ve0-f177.google.com [209.85.128.177]) by mx.google.com with ESMTPS id wt4si5497100vcb.115.2014.02.18.05.41.39 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 18 Feb 2014 05:41:39 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.177 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.177; Received: by mail-ve0-f177.google.com with SMTP id jz11so13250781veb.22 for ; Tue, 18 Feb 2014 05:41:39 -0800 (PST) X-Received: by 10.220.106.84 with SMTP id w20mr21312614vco.18.1392730899907; Tue, 18 Feb 2014 05:41:39 -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 u4csp217212vcz; Tue, 18 Feb 2014 05:41:39 -0800 (PST) X-Received: by 10.15.81.196 with SMTP id x44mr33362604eey.31.1392730898516; Tue, 18 Feb 2014 05:41:38 -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 8si16122457eep.18.2014.02.18.05.41.37 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 18 Feb 2014 05:41:38 -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 1WFkuL-0001LU-KU; Tue, 18 Feb 2014 13:40:21 +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 1WFkuF-0001L8-2N for linaro-mm-sig@lists.linaro.org; Tue, 18 Feb 2014 13:40:15 +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 <0N17003O320XRE30@mailout3.samsung.com> for linaro-mm-sig@lists.linaro.org; Tue, 18 Feb 2014 22:41:21 +0900 (KST) X-AuditID: cbfee61a-b7fb26d00000724f-e9-530363010576 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id BD.A5.29263.10363035; Tue, 18 Feb 2014 22:41:21 +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:41:21 +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, 18 Feb 2014 14:37:59 +0100 Message-id: <1392730681-14695-5-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: H4sIAAAAAAAAAzWRa0hTYRzGe89tZ6PBaVodF0nNgiyvIfVCEtanNwpKl0R+qJYep7jp2lHT IJq6SUpT00oJ81IKtXTmvGvRFLug5XWoUCoyCXJLzUmRTcst+vb78/z4Px8eGpfUEFI6OTWd 06YqVDJKRAxu2JlgEI/Lw1zDQXC99K0ALucacFjdP0TCYmctCa3uTgCdxtsE7DIvAvgx1ymA HQUVArhqm8OgxT5Bwtr8OgKOd1dSsLF/WgBffO3FYP3kKAZr3ulJ6C73hwOTLgqWlDcS0PCq XwDXOywEXOjNJ2BThYOApm43iPJDDVUNAP1eKwXIUVYC0HiREUNdD6cF6I5TTyKLqYBCnyde Uqil7hb6tGHHke19LonM7gUMFa+HoaJWE0Auiz9qfhR7jokTRSZwquRMTht6/Iooaa3VTGpy /LMco3cJHfjFFgIhzTIRbPGIFfvHO9iRmSaqEIhoCfMYsD8Hzdi/w4CxLUVLpMeimHC28Fsh 5WFfphawrirCI+FMOcU+aVvyBj7MWdad88bLBLOfnXu+4mUxg9iRMcfmV3qzbg9bWRrpQSFz il2dDPIYkk2jbdaOlwBxDdhiAts5TbyGv6pUh4fwCjWfkaoMiU9TW4B3ty/STvBMB/sAQwPZ VvFyACaXkIpMPlvdB1gal/mKA+NwuUScoMi+wWnTLmszVBzfB3bRhGyn2Go4Fi1hlIp0LoXj NJz2f4rRQqkOqK4pqTbryaQTvqt7eyKiLzVrEmRRKxdjFqWVy/Vmp5Bnzqx1HrGP97QnHnq9 ZFVdIANvDseEfng6oyqbdz+Q+5y29UTv9hs6f/9ohC4gKy8v8PCU2Jp4YHzb2L4/fLt14J6r Wq/Ks113tZJiHszq6weMZd+Dh0zGH1PzsQEpMoJPUoQfxLW84i9ap9T5swIAAA== Cc: Mark Rutland , 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 , Sascha Hauer Subject: [Linaro-mm-sig] [PATCH v3 4/6] 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.128.177 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. 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 | 68 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 drivers/of/of_reserved_mem_cma.c diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig index 7f00b801bcd2..b0675c666bcd 100644 --- a/drivers/of/Kconfig +++ b/drivers/of/Kconfig @@ -80,6 +80,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..c93c665f06c9 --- /dev/null +++ b/drivers/of/of_reserved_mem_cma.c @@ -0,0 +1,68 @@ +/* + * 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 + +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; + + return 0; +} +RESERVEDMEM_OF_DECLARE(cma, "shared-dma-pool", rmem_cma_setup);