From patchwork Fri Feb 28 13:42:50 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 25553 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f72.google.com (mail-yh0-f72.google.com [209.85.213.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 79CE920543 for ; Fri, 28 Feb 2014 13:43:46 +0000 (UTC) Received: by mail-yh0-f72.google.com with SMTP id f73sf1628017yha.3 for ; Fri, 28 Feb 2014 05:43:45 -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=vJ2t4tuR6vovd+9yVxoteAKtZY1yTImCrAZdCFJfpng=; b=aUEULCZaux5/7zzuCKDAaydfaV3KuCsKH/613mfR4+w7xWFtw+q76+D+Xb60PmSjle DVi1PbjEdTzUPyTzrdCXrvzY0t8PMbulMwiRA+ICT2TJYdBnkA14FjqwV2zo4GDqNbQb hbvuKlD27n/f5YrarOeWB+Lm3emK926wud7L3oUSRyYX4Za0dgT9/SjOC95LsI4gLwdw qhBi1d04F6euZ8i4LxXmTcFiZMzfSR7wMd1zomrd2cdca44DuU6jx0RQ+uHJgudA3MjP k9HEmAvTebxwIO3TmOOslHWfBkvhdcUaX2ejp9rseaTJL8O2p8S6uGA8tgIDsXiSR6Tl 4Ung== X-Gm-Message-State: ALoCoQmPV3f1FaVAfGwIMfDiaasXrwR0ag/CBTbx9gaCV8akw84S7kz16ogi5b/HzQFat3J0s3fn X-Received: by 10.236.102.8 with SMTP id c8mr1131209yhg.5.1393595025941; Fri, 28 Feb 2014 05:43:45 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.86.233 with SMTP id p96ls1038000qgd.33.gmail; Fri, 28 Feb 2014 05:43:45 -0800 (PST) X-Received: by 10.220.136.6 with SMTP id p6mr1580717vct.9.1393595025796; Fri, 28 Feb 2014 05:43:45 -0800 (PST) Received: from mail-ve0-f174.google.com (mail-ve0-f174.google.com [209.85.128.174]) by mx.google.com with ESMTPS id i1si1804902vcl.81.2014.02.28.05.43.45 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 28 Feb 2014 05:43:45 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.174 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.174; Received: by mail-ve0-f174.google.com with SMTP id oy12so732282veb.19 for ; Fri, 28 Feb 2014 05:43:45 -0800 (PST) X-Received: by 10.52.27.9 with SMTP id p9mr13425038vdg.28.1393595025677; Fri, 28 Feb 2014 05:43:45 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.130.193 with SMTP id u1csp54597vcs; Fri, 28 Feb 2014 05:43:45 -0800 (PST) X-Received: by 10.14.174.5 with SMTP id w5mr21771012eel.14.1393595024587; Fri, 28 Feb 2014 05:43:44 -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 n7si2763620eeu.250.2014.02.28.05.43.43 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 28 Feb 2014 05:43:44 -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 1WJNhe-0008Jl-AJ; Fri, 28 Feb 2014 13:42:14 +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 1WJNhF-0008HG-DU for linaro-mm-sig@lists.linaro.org; Fri, 28 Feb 2014 13:41:49 +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 <0N1P00M0PKS23080@mailout1.w1.samsung.com> for linaro-mm-sig@lists.linaro.org; Fri, 28 Feb 2014 13:43:14 +0000 (GMT) X-AuditID: cbfec7f4-b7f796d000005a13-13-531092719565 Received: from eusync3.samsung.com ( [203.254.199.213]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id B4.55.23059.17290135; Fri, 28 Feb 2014 13:43: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 <0N1P002ZJKROU750@eusync3.samsung.com>; Fri, 28 Feb 2014 13:43: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, 28 Feb 2014 14:42:50 +0100 Message-id: <1393594976-16728-6-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1393594976-16728-1-git-send-email-m.szyprowski@samsung.com> References: <1393594976-16728-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAAyWRXUhTYQCG+845O+dstDwtrQ8rsZkQSuZK5ENEgkA+oQvBiyKKWjr8yant pGmQzaFic9O1opnZUtTCtfkzBX8o0rFULKXhzy6cmlmR/5ZeWM1Vw7vnfXjuXpaUPKCC2cyc WwpVjjxbSouo976hyZM3jVxKdK0nFu0YBxm0oSkj0foLHUDPnWMCVL3SIED93h6AVvQVFOpt XQNoVLPCoO77NQzampgnkH1hSoAaypsoNN5XRyObc4ZB7YsDBGp2uwhUP1QqQF5TCBpxb9LI 6mxkkMFko1DZGyeDdrrtFFoaKKdQW80yhSx9XoAWfwxTZ49gq9kK8J/fRoCXHxoAHq/SE7i3 dobBupVSAbZb7tPYM/Waxp1N9/C0b4HEE8MaAW71LhG4eicaP+urAriqywLwpj0kef8lUXya IjuzQKE6lXBNlPHu5SMmz3mscM6uJ9TAdVgLhCzkYqBxrYPZ5YPw42wbrQUiVsI1A2iqV5O7 o5KAHT01wF/RnAxqV7W0nwO5BgA3zZQ/Irk5Gla4dIQWsOwBLh1O+6AfKS4clqwr/bmYw7Cl fYL0a8iFwjpjvF8LuSSoNs0J/Cz5n0xvu4EBiOvBHgsIUuSn5vHX05WyKF6u5PNz0qNSc5V2 sHvjVg9oHIxzAI4F0r1iQ1JAikQgL+CLlA4AWVIaKP6i4VIk4jR50R2FKveqKj9bwTsAwQqD 1UC26vrbn+oJo1WTl5vMvS1yEzh9NPx85VZJ3Mh43NqGLfJJ15jPErb9SnK3JHS0sDmw+Kmo IPGKKHbA/cnzGDPucyckWb/OGDvhoWGdXch81x9PcHy7GKbcCHibHBF/IYYvnpcqgryVXz+w VnPiz8jZrM/GG3iS32ey3eZVUorPkMsiSBUv/wcU+RLqpAIAAA== 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 v6 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.174 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 Based on previous code provided by Josh Cartwright Signed-off-by: Marek Szyprowski --- drivers/of/of_reserved_mem.c | 70 +++++++++++++++++++++++++++++++++++++++ include/linux/of_reserved_mem.h | 7 ++++ 2 files changed, 77 insertions(+) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index daaaf935911d..5c45016efd31 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,65 @@ 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 reserved_mem *rmem; + struct device_node *np; + + np = of_parse_phandle(dev->of_node, "memory-region", 0); + if (!np) + return; + + rmem = __find_rmem(np); + of_node_put(np); + + if (!rmem || !rmem->ops || !rmem->ops->device_init) + return; + + rmem->ops->device_init(rmem, dev); + dev_info(dev, "assigned reserved memory node %s\n", rmem->name); +} + +/** + * 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 reserved_mem *rmem; + struct device_node *np; + + np = of_parse_phandle(dev->of_node, "memory-region", 0); + if (!np) + return; + + rmem = __find_rmem(np); + of_node_put(np); + + if (!rmem || !rmem->ops || !rmem->ops->device_release) + return; + + rmem->ops->device_release(rmem, dev); +} diff --git a/include/linux/of_reserved_mem.h b/include/linux/of_reserved_mem.h index 9b1fbb7f29fc..6a54e6565b89 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; @@ -25,6 +26,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); @@ -37,6 +41,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) { }