From patchwork Wed Jul 2 10:48:49 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 32965 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f198.google.com (mail-vc0-f198.google.com [209.85.220.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id F3F9D20560 for ; Wed, 2 Jul 2014 10:51:18 +0000 (UTC) Received: by mail-vc0-f198.google.com with SMTP id hy10sf25003755vcb.1 for ; Wed, 02 Jul 2014 03:51:18 -0700 (PDT) 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:subject:date:message-id :in-reply-to:references:cc:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:content-type:content-transfer-encoding; bh=UWaM6QRzARcVf4PoSXbzb8dd+vCDc04g+L/iBIPfhhk=; b=frBrPWgaH8dNvBEWf1gKy7E6h24DhEJiMZU2VWOxrHTW76rN0atazJgxwfluYcVMhq RnnNjDzyMfL4jGlar5G154qIkCdl0IoPNW4wCsOyGd6xoopPRzVlmnV6XdVc/1X0rGOH FkC4O2+k77RCd7lwvK64xEIgbjEmMUQthqlMNDY0mGfWvkyg5VP/YRUKK/lYFDQb5hQd gv1VqJL4q0w4wT1UHs4/G1T8JTYBUx5FDCQ47Ruv/6D+tGUp+Q2bnRAMganbNmsD2xQh TRYK+vVyQ9J1NYTjX8YGzzO96LAlQ2EA6UW0z0+1SsMrsGyOBlZ8DRVUvrXgCaM/PYCM LHNg== X-Gm-Message-State: ALoCoQnw1QlKFQh2qGC9U6gjTQa8jctb6WA9s68V2+ilkutt/uTh/5JzHoN7jN6JeXwqPeOfe66G X-Received: by 10.224.172.193 with SMTP id m1mr15603507qaz.8.1404298278561; Wed, 02 Jul 2014 03:51:18 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.19.173 with SMTP id 42ls2381908qgh.27.gmail; Wed, 02 Jul 2014 03:51:18 -0700 (PDT) X-Received: by 10.52.119.179 with SMTP id kv19mr41079581vdb.3.1404298278484; Wed, 02 Jul 2014 03:51:18 -0700 (PDT) Received: from mail-ve0-f182.google.com (mail-ve0-f182.google.com [209.85.128.182]) by mx.google.com with ESMTPS id zu9si12698793vdc.75.2014.07.02.03.51.18 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 02 Jul 2014 03:51:18 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.182 as permitted sender) client-ip=209.85.128.182; Received: by mail-ve0-f182.google.com with SMTP id oy12so11207272veb.27 for ; Wed, 02 Jul 2014 03:51:18 -0700 (PDT) X-Received: by 10.52.92.82 with SMTP id ck18mr4023690vdb.6.1404298278316; Wed, 02 Jul 2014 03:51:18 -0700 (PDT) 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.221.37.5 with SMTP id tc5csp283799vcb; Wed, 2 Jul 2014 03:51:17 -0700 (PDT) X-Received: by 10.68.162.34 with SMTP id xx2mr68866136pbb.120.1404298277555; Wed, 02 Jul 2014 03:51:17 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id fm4si29893790pab.142.2014.07.02.03.51.17 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Jul 2014 03:51:17 -0700 (PDT) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) client-ip=2001:1868:205::9; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1X2I6b-0000BF-0p; Wed, 02 Jul 2014 10:49:37 +0000 Received: from mailout4.w1.samsung.com ([210.118.77.14]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1X2I6Q-0008Pj-31 for linux-arm-kernel@lists.infradead.org; Wed, 02 Jul 2014 10:49:27 +0000 Received: from eucpsbgm2.samsung.com (unknown [203.254.199.245]) by mailout4.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0N82008DTZDGK5A0@mailout4.w1.samsung.com> for linux-arm-kernel@lists.infradead.org; Wed, 02 Jul 2014 11:48:52 +0100 (BST) X-AuditID: cbfec7f5-b7f626d000004b39-26-53b3e39b64fe Received: from eusync3.samsung.com ( [203.254.199.213]) by eucpsbgm2.samsung.com (EUCPMTA) with SMTP id BC.E9.19257.B93E3B35; Wed, 02 Jul 2014 11:48:59 +0100 (BST) Received: from amdc1339.digital.local ([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 <0N82004J1ZDILZA0@eusync3.samsung.com>; Wed, 02 Jul 2014 11:48:59 +0100 (BST) 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 1/4] drivers: of: add automated assignment of reserved regions to client devices Date: Wed, 02 Jul 2014 12:48:49 +0200 Message-id: <1404298132-6050-2-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.2 In-reply-to: <1404298132-6050-1-git-send-email-m.szyprowski@samsung.com> References: <1404298132-6050-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAAyXRW0iTcRjH8f7vca4WL8viRUFsEYHhKbp4iLAiw79YUEoUgdWmQw2nsrdJ FpR5Qpcn9MIjHtKVramxQZ4px3DT0BKdGmWag/CwqaVC5dSa3n0e+MLv4hGR0hbKR5SUcl+p TpEnyxgx9WHbag+scZhiQlZ6gqC23cCAY6mOgq2yARZWs3JJWHlRiKDeMkJDibORhvfuTgSv nmUz4CzKp6CrbRnBcJaThY6CShbWx78TYHRM0NCY10zBWHctA62WaRbeLPQToJscJaDBmkOD u8IPhibXGDBYmlgorWilILfPwsJWh5GCxf48CtorlyhorJ9hQd/tRrDw00ad98eGOgPCm3/L EF4qL0V4rLiIwF3V0ywudObQ2KgvYLDWNU7grxO9DLZVblJ41myisKn5Cf6y7SDxuC2Lxm3u RQKXbIVc9b4lPhuvTE5KV6qDw+6KE00luUSaw/9Bq/lEJqrw1SIvEc+d5vWGKnLPR/hP39oZ LRKLpJwO8Y6+MrR3FBO8bmaY8lQMF8prXVrGY2+uEfFrdZQnIrkiET/f83s3OsQpeNvQO9Zj ijvOf6yfQh5LuAi+ayef3pvz43cWWgiPvTjMv+yd222k/xuLc4UsRZIGtE+PDis1cWmCIkF1 KkiQqwRNSkJQXKrKiPa+u9GJdANnzIgTIdkByXywMUZKy9OFDJUZ8SJS5i0pmTLFSCXx8oyH SnXqHbUmWSmYESHy8slEwi8h4fbQCJ8aEr7f9xpkaOpHo7Wa3tWNtsijNS0vY7eKr0fcoG+a xdNx638+Y7HLydrL9dEndQ2d2XmrfdWv/dvsTW+bWrVXnlYpYu1Rxh+P3PPHnl/oOGfumnos 8VUMXgyIigyPJVWBYf3WS6Hhs5cPrs9ZB++pqlxklHlZRgmJ8tAAUi3I/wFVgSsxuwIAAA== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140702_034926_308889_1E35D0B3 X-CRM114-Status: GOOD ( 16.57 ) X-Spam-Score: -5.0 (-----) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-5.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [210.118.77.14 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [210.118.77.14 listed in wl.mailspike.net] -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders Cc: Mark Rutland , Jon Medhurst , Benjamin Herrenschmidt , Tomasz Figa , Will Deacon , Tomasz Figa , Paul Mackerras , Marek Szyprowski , Arnd Bergmann , Josh Cartwright , Catalin Marinas , Grant Likely , Laura Abbott , Ian Campbell , Pawel Moll , Stephen Warren , Sascha Hauer , Michal Nazarewicz , Marc , Nishanth Peethambaran , Rob Herring , Andrew Morton , "Aneesh Kumar K.V." , Kumar Gala , Olof Johansson , Joonsoo Kim X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 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+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: m.szyprowski@samsung.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.182 as permitted sender) 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 632aae861375..59fb12e84e6b 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; + int len; + const __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 4669ddfdd5af..5b5efae09135 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; @@ -27,10 +28,16 @@ typedef int (*reservedmem_of_init_fn)(struct reserved_mem *rmem); _OF_DECLARE(reservedmem, name, compat, init, reservedmem_of_init_fn) #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); #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) { }