From patchwork Fri Feb 21 12:25:21 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 25103 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f70.google.com (mail-pa0-f70.google.com [209.85.220.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 71CCF20143 for ; Fri, 21 Feb 2014 12:26:37 +0000 (UTC) Received: by mail-pa0-f70.google.com with SMTP id kq14sf8808133pab.5 for ; Fri, 21 Feb 2014 04:26:36 -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=yiRoQVxHbv5CRo8nZmNXT40bXBfyXC6endaXTIBuAYU=; b=c6WvblLswPj8v1R9iy196mCz+qBqrjl3jo4YEV4qCVM2LJGt4VIWUvJ67WBXb18VXI OBfsi5NaKNQJLmyAgz1wevRbTaxDWXthKCjTCOTaEy2JKmM1hDBDL7eJ8iHZ2Fx1ZoTC Jg8uycsaNZkL5JIL09o/53zhNQjfu1U0snkmeI1d1LYic1LoGaI49i5Xy7eoz3Q/GHhB 2req1391BHfEXltvl3ujTZZbhViBITnAIC0OkWDo3dvRP5cfF7JrZpupQNys4ahpYlEz McEzKvWeA8LpnjpThu+rUVHuvEF6zD+7v0cJRd9aqOsPTVO92eOPfyVljzBXEjewRlAB og4A== X-Gm-Message-State: ALoCoQmT8NlK2VEPAkHx/+x3eFbwzp5sVk1RgfIHIZ7sUEDfQ/sjlCgRmv/ZUxoFSlfbbluIbood X-Received: by 10.66.141.231 with SMTP id rr7mr3263068pab.47.1392985596710; Fri, 21 Feb 2014 04:26:36 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.82.148 with SMTP id h20ls926399qgd.36.gmail; Fri, 21 Feb 2014 04:26:36 -0800 (PST) X-Received: by 10.220.112.75 with SMTP id v11mr4590333vcp.74.1392985596530; Fri, 21 Feb 2014 04:26:36 -0800 (PST) Received: from mail-ve0-f181.google.com (mail-ve0-f181.google.com [209.85.128.181]) by mx.google.com with ESMTPS id wz4si2912851vdc.46.2014.02.21.04.26.36 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 21 Feb 2014 04:26:36 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.181 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.181; Received: by mail-ve0-f181.google.com with SMTP id jw12so3201773veb.12 for ; Fri, 21 Feb 2014 04:26:36 -0800 (PST) X-Received: by 10.220.106.84 with SMTP id w20mr4634091vco.18.1392985596439; Fri, 21 Feb 2014 04:26:36 -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 u4csp30033vcz; Fri, 21 Feb 2014 04:26:35 -0800 (PST) X-Received: by 10.180.164.174 with SMTP id yr14mr3010613wib.18.1392985595226; Fri, 21 Feb 2014 04:26:35 -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 dl9si8129634wjb.51.2014.02.21.04.26.34 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 21 Feb 2014 04:26:35 -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 1WGpAJ-0004FE-DL; Fri, 21 Feb 2014 12:25:15 +0000 Received: from mailout1.w1.samsung.com ([210.118.77.11]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1WGpA2-0004D6-Rf for linaro-mm-sig@lists.linaro.org; Fri, 21 Feb 2014 12:24:58 +0000 Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout1.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0N1C00FGTIJQXX90@mailout1.w1.samsung.com> for linaro-mm-sig@lists.linaro.org; Fri, 21 Feb 2014 12:26:14 +0000 (GMT) X-AuditID: cbfec7f4-b7f796d000005a13-98-530745e5c814 Received: from eusync3.samsung.com ( [203.254.199.213]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id A0.31.23059.5E547035; Fri, 21 Feb 2014 12:26:13 +0000 (GMT) Received: from amdc1339.mshome.net ([106.116.147.30]) by eusync3.samsung.com (Oracle Communications Messaging Server 7u4-23.01 (7.0.4.23.0) 64bit (built Aug 10 2011)) with ESMTPA id <0N1C001ZAIJD5M60@eusync3.samsung.com>; Fri, 21 Feb 2014 12:26:13 +0000 (GMT) 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: Fri, 21 Feb 2014 13:25:21 +0100 Message-id: <1392985527-6260-6-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1392985527-6260-1-git-send-email-m.szyprowski@samsung.com> References: <1392985527-6260-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAAyWRW0iTYRyHfb99+75vo8XnMn01sxrZReRhFfQiGtkB34siwTsvsqljKk7X ppKKZGuaztPSCyXUFF3FUicr8ICFk6WSFpnmKs+Ymbp5aKKVc9T07uH5P7+rP8MR6kg/Jjkt Q6pMk6SKKD455Br4HLRwjY4J1agFaLeyn0br6gIOWntaCtATywcuqrA1clGvsxMgW1kRibra VgF6r7bRqKO4hkabY3MEMs2Pc1FjYTOJRrtrKdRqmaJR+5KZQHrrCIEaBjRc5KwOQO+sDgq1 WJpopKtuJVHBawuNdjtMJFo2F5LIWLNCIkO3E6CljUHykj9uqW8BeOdvJcArVTqAR8vLCNz1 eIrGpTYNF5sMxRSeHO+h8Mvme3jCNc/BY4NqLm5zLhO4YjcU13WXA1z+ygCwwxQQ7RnLD0+U piZnSZUhF2/zk/TPOymF8eTdtw+KyHxgP6oFPAay5+Hc5Cy9z97w47SR0gI+I2T1AH7f+Eq5 D0K2hIBrcyluplgx1Nq1e96LbQTQUU+6Bxx2hoJFI6WEFjDMIVYGnRNh7oZkA+HsMz1ws4CN gt+2Jmh3AtnjsLYy3K15LIbDvYt7Wvg/aStK0QFBA/AwgMPSzASFKl4mFwerJHJVZposOCFd bgL7X9zsBE39YX2AZYDogEABqRghV5Klypb3AchwRF4CcwgdIxQkSrJzpMr0OGVmqlTVBwiG 55cPeH+mtl9w0NU3846ZBaNVbFrPk3HbDUEzPfZP+oexIhzVMf7jzrnMkvtVeUOrG1fih73O Rvgf3F7STn/Z8unPFdx0WRXiyAvXI4+dWfQ+RdYZq0XLq5aMW11xLs9e+095Tq7y96NAY1y0 OXErIn7nxCw84vvLw+h7g9AEOi77iEhVkkR8mqNUSf4BM+ug66MCAAA= Cc: Mark Rutland , Benjamin Herrenschmidt , Tomasz Figa , Will Deacon , Tomasz Figa , Paul Mackerras , Arnd Bergmann , Josh Cartwright , Catalin Marinas , Grant Likely , Ian Campbell , Pawel Moll , Stephen Warren , Sascha Hauer , Michal Nazarewicz , Rob Herring , Kumar Gala , Olof Johansson Subject: [Linaro-mm-sig] [PATCH v5 05/11] drivers: of: add automated assignment of reserved regions to client devices 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.181 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 This patch adds code for automated assignment of reserved memory regions to struct device. reserved_mem->ops->device_init()/device_cleanup() callbacks are called to perform reserved memory driver specific initialization and cleanup. The code looks for 'memory-region' property in the client device node and assigns region pointed by the found phandle. Based on previous code provided by Josh Cartwright Signed-off-by: Marek Szyprowski --- drivers/of/of_reserved_mem.c | 74 +++++++++++++++++++++++++++++++++++++++ include/linux/of_reserved_mem.h | 7 ++++ 2 files changed, 81 insertions(+) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 97de6f882f85..b02a7f0a54c8 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -206,8 +206,16 @@ void __init fdt_init_reserved_mem(void) for (i = 0; i < reserved_mem_count; i++) { struct reserved_mem *rmem = &reserved_mem[i]; unsigned long node = rmem->fdt_node; + unsigned long len; + __be32 *prop; int err = 0; + prop = of_get_flat_dt_prop(node, "phandle", &len); + if (!prop) + prop = of_get_flat_dt_prop(node, "linux,phandle", &len); + if (prop) + rmem->phandle = of_read_number(prop, len/4); + if (rmem->size == 0) err = __reserved_mem_alloc_size(node, rmem->name, &rmem->base, &rmem->size); @@ -215,3 +223,69 @@ void __init fdt_init_reserved_mem(void) __reserved_mem_init_node(rmem); } } + +static inline struct reserved_mem *__find_rmem(struct device_node *node) +{ + unsigned int i; + + if (!node->phandle) + return NULL; + + for (i = 0; i < reserved_mem_count; i++) + if (reserved_mem[i].phandle == node->phandle) + return &reserved_mem[i]; + return NULL; +} + +/** + * of_reserved_mem_device_init() - assign reserved memory region to given device + * + * This function assign memory region pointed by "memory-region" device tree + * property to the given device. + */ +void of_reserved_mem_device_init(struct device *dev) +{ + struct device_node *np = dev->of_node; + struct reserved_mem *rmem; + struct of_phandle_args s; + unsigned int i; + + for (i = 0; of_parse_phandle_with_args(np, "memory-region", + "#memory-region-cells", i, &s) == 0; i++) { + + rmem = __find_rmem(s.np); + if (!rmem || !rmem->ops || !rmem->ops->device_init) { + of_node_put(s.np); + continue; + } + + rmem->ops->device_init(rmem, dev, &s); + dev_info(dev, "assigned reserved memory node %s\n", rmem->name); + of_node_put(s.np); + break; + } +} + +/** + * of_reserved_mem_device_release() - release reserved memory device structures + * + * This function releases structures allocated for memory region handling for + * the given device. + */ +void of_reserved_mem_device_release(struct device *dev) +{ + struct device_node *np = dev->of_node; + struct reserved_mem *rmem; + struct of_phandle_args s; + unsigned int i; + + for (i = 0; of_parse_phandle_with_args(np, "memory-region", + "#memory-region-cells", i, &s) == 0; i++) { + + rmem = __find_rmem(s.np); + if (rmem && rmem->ops && rmem->ops->device_release) + rmem->ops->device_release(rmem, dev); + + of_node_put(s.np); + } +} diff --git a/include/linux/of_reserved_mem.h b/include/linux/of_reserved_mem.h index f707176619a3..a2a25de297de 100644 --- a/include/linux/of_reserved_mem.h +++ b/include/linux/of_reserved_mem.h @@ -8,6 +8,7 @@ struct reserved_mem_ops; struct reserved_mem { const char *name; unsigned long fdt_node; + unsigned long phandle; const struct reserved_mem_ops *ops; phys_addr_t base; phys_addr_t size; @@ -26,6 +27,9 @@ typedef int (*reservedmem_of_init_fn)(struct reserved_mem *rmem, unsigned long node, const char *uname); #ifdef CONFIG_OF_RESERVED_MEM +void of_reserved_mem_device_init(struct device *dev); +void of_reserved_mem_device_release(struct device *dev); + void fdt_init_reserved_mem(void); void fdt_reserved_mem_save_node(unsigned long node, const char *uname, phys_addr_t base, phys_addr_t size); @@ -38,6 +42,9 @@ void fdt_reserved_mem_save_node(unsigned long node, const char *uname, init : init } #else +static inline void of_reserved_mem_device_init(struct device *dev) { } +static inline void of_reserved_mem_device_release(struct device *pdev) { } + static inline void fdt_init_reserved_mem(void) { } static inline void fdt_reserved_mem_save_node(unsigned long node, const char *uname, phys_addr_t base, phys_addr_t size) { }