From patchwork Mon Jul 14 07:12:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 33552 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f70.google.com (mail-oa0-f70.google.com [209.85.219.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A8A7120CAD for ; Mon, 14 Jul 2014 07:33:52 +0000 (UTC) Received: by mail-oa0-f70.google.com with SMTP id eb12sf17827789oac.1 for ; Mon, 14 Jul 2014 00:33:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=ixn0RV8VE9Ung2MbWYVwvEklLcO4BPGLoJn2EFGMC3c=; b=FDHE7robvnv4uCrfBrgpPozlaKMLIaF1+I7aX665NNfLaOdat32ZOgFlBaxYIiI8jx QTnoYeWKEbXoEnLl9Yuzuffscjo3vMunDjf4JfyTfuDsMyoaj8a1vJZGzsjjBC/j0DbB fjNab2p5KcB//EfG4hNuwhHErLb1h23oS2s/Fyp5yuivsz34qdEokALz+N/rgXQXn4+0 TjzWGnqIqMm9bliSbRYSXYIxYvo/TgV0OysGGXT2fZS8PiPzPqOacL1CUVA1IGXAPMvh LB/4BKeIpo2nP0XisTUVKvThswpc4kCGnyLTgQ4u6F3Fro5MwOrA1Nqh2RCxWbvSCNYH wt0g== X-Gm-Message-State: ALoCoQky9Icx/npPW0ovakWBfGVFWE77/wy7UqrW8ZqDJDYZCgSJ5ABFrt5vCbB7qNTIu/vA6utx X-Received: by 10.182.241.1 with SMTP id we1mr6787272obc.37.1405323232041; Mon, 14 Jul 2014 00:33:52 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.23.210 with SMTP id 76ls972663qgp.33.gmail; Mon, 14 Jul 2014 00:33:51 -0700 (PDT) X-Received: by 10.52.163.136 with SMTP id yi8mr8736614vdb.14.1405323231927; Mon, 14 Jul 2014 00:33:51 -0700 (PDT) Received: from mail-vc0-f174.google.com (mail-vc0-f174.google.com [209.85.220.174]) by mx.google.com with ESMTPS id d3si5087301vck.42.2014.07.14.00.33.51 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 14 Jul 2014 00:33:51 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.174 as permitted sender) client-ip=209.85.220.174; Received: by mail-vc0-f174.google.com with SMTP id la4so1333945vcb.19 for ; Mon, 14 Jul 2014 00:33:51 -0700 (PDT) X-Received: by 10.220.174.137 with SMTP id t9mr15145162vcz.12.1405323231789; Mon, 14 Jul 2014 00:33:51 -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 tc5csp112924vcb; Mon, 14 Jul 2014 00:33:51 -0700 (PDT) X-Received: by 10.66.141.37 with SMTP id rl5mr1830021pab.103.1405323230887; Mon, 14 Jul 2014 00:33:50 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id wm6si8547651pab.102.2014.07.14.00.33.50; Mon, 14 Jul 2014 00:33:50 -0700 (PDT) Received-SPF: none (google.com: devicetree-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753360AbaGNHdn (ORCPT + 8 others); Mon, 14 Jul 2014 03:33:43 -0400 Received: from mailout2.w1.samsung.com ([210.118.77.12]:18067 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753272AbaGNHde (ORCPT ); Mon, 14 Jul 2014 03:33:34 -0400 Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout2.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0N8O00A9HYBAUH90@mailout2.w1.samsung.com>; Mon, 14 Jul 2014 08:33:10 +0100 (BST) X-AuditID: cbfec7f4-b7fac6d000006cfe-72-53c387c6ca41 Received: from eusync3.samsung.com ( [203.254.199.213]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id 8E.74.27902.6C783C35; Mon, 14 Jul 2014 08:33:26 +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 <0N8O00FFGYBLTX50@eusync3.samsung.com>; Mon, 14 Jul 2014 08:33:26 +0100 (BST) From: Marek Szyprowski To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Marek Szyprowski , Benjamin Herrenschmidt , linaro-mm-sig@lists.linaro.org, devicetree@vger.kernel.org, Arnd Bergmann , Michal Nazarewicz , Grant Likely , Tomasz Figa , Sascha Hauer , Laura Abbott , Nishanth Peethambaran , Marc , Josh Cartwright , Catalin Marinas , Will Deacon , Paul Mackerras , Jon Medhurst , Joonsoo Kim , "Aneesh Kumar K.V." , Andrew Morton Subject: [PATCH v2 1/4] drivers: of: add automated assignment of reserved regions to client devices Date: Mon, 14 Jul 2014 09:12:43 +0200 Message-id: <1405321966-28184-2-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.2 In-reply-to: <1405321966-28184-1-git-send-email-m.szyprowski@samsung.com> References: <1405321966-28184-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrFLMWRmVeSWpSXmKPExsVy+t/xq7rH2g8HG5xvM7OYs34Nm8Xj1/NY LP5OOsZu8aGpldni/bIeRov5R86xWhz4s4PRYmV3M5vFznXvGC3ONr1ht9jeOYPd4suVh0wW mx5fY7W4vGsOm8XaI3fZLTa8PMhkseB4C6vFn+lyFmuOLGa3+Lt9E4vF+hmvWSwWzr/PbvHy 4wkWB3GPNfPWMHr8/jWJ0eNyXy+Tx85Zd9k9et60sHp0vb3C5HHn2h42jxMzfrN4PDi0mcVj 85J6j9v/HjN7rPvzismj/6+Bx9xdfYwefVtWMXp83iQXIBDFZZOSmpNZllqkb5fAlbG5v5Wp 4LFCxdpD6g2M06W7GDk5JARMJK49W8sKYYtJXLi3nq2LkYtDSGApo8S9g0cYIZw+Jome7gMs IFVsAoYSXW+72EBsEQE3iX/rDoF1MAssYJM4+v8HI0hCWCBV4s35vewgNouAqkTjl3vMIDav gIfE72vXmCHWyUn8f7mCCcTmFPCU2Dj5G9gZQkA1h/ftYZzAyLuAkWEVo2hqaXJBcVJ6rqFe cWJucWleul5yfu4mRkh8fdnBuPiY1SFGAQ5GJR7eCrHDwUKsiWXFlbmHGCU4mJVEeMPdgEK8 KYmVValF+fFFpTmpxYcYmTg4pRoY19/22/eePSBF9JTX1C8ZR00ub87kbcv/t/z80282f4r9 tv+r4+Xs+ha8r8f84BvBjUYLNBLS5s3Z/f7QB4ViNdXw7MCw71xhsltu8N1lNz9u+cmoo+V4 ZLqgZ4b8Np8k7SN356/PadH99uA+z83w+d+y7mmtEfts+u5a8oLaVQ5WYrXSn+Y/U2Ipzkg0 1GIuKk4EAKEBuvaNAgAA Sender: devicetree-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: devicetree@vger.kernel.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.220.174 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 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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) { }