From patchwork Tue Aug 26 12:09: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: 4781251 Return-Path: X-Original-To: patchwork-linux-samsung-soc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 49F01C0338 for ; Tue, 26 Aug 2014 12:16:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1681C201C0 for ; Tue, 26 Aug 2014 12:16:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1643C20142 for ; Tue, 26 Aug 2014 12:16:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934458AbaHZMQR (ORCPT ); Tue, 26 Aug 2014 08:16:17 -0400 Received: from mailout3.w1.samsung.com ([210.118.77.13]:30501 "EHLO mailout3.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754687AbaHZMNy (ORCPT ); Tue, 26 Aug 2014 08:13:54 -0400 Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout3.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0NAW00315Y3UC640@mailout3.w1.samsung.com>; Tue, 26 Aug 2014 13:16:42 +0100 (BST) X-AuditID: cbfec7f4-b7f156d0000063c7-7f-53fc79ffca9d Received: from eusync4.samsung.com ( [203.254.199.214]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id 9D.48.25543.FF97CF35; Tue, 26 Aug 2014 13:13:51 +0100 (BST) Received: from amdc1339.digital.local ([106.116.147.30]) by eusync4.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0NAW00F45XYW5O50@eusync4.samsung.com>; Tue, 26 Aug 2014 13:13:51 +0100 (BST) From: Marek Szyprowski To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org Cc: Marek Szyprowski , Kyungmin Park , linaro-mm-sig@lists.linaro.org, linux-media@vger.kernel.org, Arnd Bergmann , Michal Nazarewicz , Grant Likely , Tomasz Figa , Laura Abbott , Josh Cartwright , Joonsoo Kim Subject: [PATCH 2/7] drivers: of: add support for named memory regions Date: Tue, 26 Aug 2014 14:09:43 +0200 Message-id: <1409054988-32758-3-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.2 In-reply-to: <1409054988-32758-1-git-send-email-m.szyprowski@samsung.com> References: <1409054988-32758-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrNLMWRmVeSWpSXmKPExsVy+t/xa7r/K/8EGyx8IWDxd9IxdosDf3Yw Wqzsbmaz2LnuHaPF2aY37BbbO2ewW3y58pDJYtPja6wWl3fNYbPo2bCV1WLG+X1MFmuP3GW3 WHC8hdVi/YzXLA58Hr9/TWL0uNzXy+TR9fYKk8eda3vYPDYvqfe4/e8xs8e6P6+YPPq2rGL0 +LxJLoAzissmJTUnsyy1SN8ugStj0qke1oLT6hUL3rxkb2Dcr9DFyMkhIWAicXf7RyYIW0zi wr31bF2MXBxCAksZJY4uf8oC4fQxSSzffIcdpIpNwFCi620XG4gtIpAt8ePbZBYQm1lgKbPE vFlSILawgJvE72ldYPUsAqoSb5bvB6vhFfCQuHf8DxvENjmJ/y9XAG3m4OAU8JQ4N6UaJCwE VLJx+nuWCYy8CxgZVjGKppYmFxQnpeca6hUn5haX5qXrJefnbmKEBPCXHYyLj1kdYhTgYFTi 4f1Q8jtYiDWxrLgy9xCjBAezkgjvj6Q/wUK8KYmVValF+fFFpTmpxYcYmTg4pRoYBXNf5bxY xFpxLedWp+ADz5ZNMSu/XfhwypP/6tlXxWeylv5kPi9v+fcF94v/EdlTjDdWCIccWVpT/SiA /6VV+XoZ6zk7zfs5zVZecpzkbKB5zemlUfxcsf5zRlJpJ5KX6zhMFw4/t/eU5uZrajqGS46w t9z7flahZ2FdV3i9lVHhiqtCHhVSSizFGYmGWsxFxYkAAa4p+D4CAAA= Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds a code to initialize memory regions also for child devices if parent device has "memory-region" and "memory-region-names" device tree properties and given device's name matches ":" template. Signed-off-by: Marek Szyprowski --- .../bindings/reserved-memory/reserved-memory.txt | 6 +- drivers/of/of_reserved_mem.c | 101 ++++++++++++++------- 2 files changed, 74 insertions(+), 33 deletions(-) diff --git a/Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt b/Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt index 3da0ebdba8d9..69d28288ed37 100644 --- a/Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt +++ b/Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt @@ -73,7 +73,11 @@ Device node references to reserved memory Regions in the /reserved-memory node may be referenced by other device nodes by adding a memory-region property to the device node. -memory-region (optional) - phandle, specifier pairs to children of /reserved-memory +memory-region (optional) - arrays of phandles, specifier pairs to children + of /reserved-memory, first phandle is used as a default memory + region +memory-region-names (optional) - array of strings with names of memory + regions, used when more than one region has been defined Example ------- diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 7e7de03585f9..3ab9446ffa43 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -237,32 +237,82 @@ static inline struct reserved_mem *__find_rmem(struct device_node *node) 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. - */ -int of_reserved_mem_device_init(struct device *dev) +static int __rmem_dev_init(struct device *dev, struct device_node *np) { - 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); - + struct reserved_mem *rmem = __find_rmem(np); if (!rmem || !rmem->ops || !rmem->ops->device_init) - return; + return -EINVAL; rmem->ops->device_init(rmem, dev); dev_info(dev, "assigned reserved memory node %s\n", rmem->name); return 0; } +static int __rmem_dev_release(struct device *dev, struct device_node *np) +{ + struct reserved_mem *rmem = __find_rmem(np); + if (!rmem || !rmem->ops) + return -EINVAL; + + if (rmem->ops->device_release) + rmem->ops->device_release(rmem, dev); + return 0; +} + +static int __rmem_dev_call(struct device *dev, + int (*func)(struct device *dev, struct device_node *np)) +{ + int ret = -ENODEV; + if (of_get_property(dev->of_node, "memory-region", NULL)) { + struct device_node *np; + np = of_parse_phandle(dev->of_node, "memory-region", 0); + if (!np) + return -ENODEV; + ret = func(dev, np); + of_node_put(np); + } else if (dev->parent && + of_get_property(dev->parent->of_node, "memory-region", + NULL)) { + struct device *parent = dev->parent; + struct device_node *np; + char *name; + int idx; + + name = strrchr(dev_name(dev), ':'); + if (!name) + return -ENODEV; + name++; + + idx = of_property_match_string(parent->of_node, + "memory-region-names", name); + if (idx < 0) + return -ENODEV; + + np = of_parse_phandle(parent->of_node, "memory-region", idx); + if (!np) + return -ENODEV; + + ret = func(dev, np); + of_node_put(np); + } + return ret; +} + +/** + * of_reserved_mem_device_init() - assign reserved memory region to given device + * + * This function assigns default memory region pointed by first entry of + * "memory-region" device tree property (if available) to the given device or + * checks if the given device can be used to give access to named memory region + * if parent device has "memory-region" and "memory-region-names" device tree + * properties and given device's name matches ":" + * template. + */ +int of_reserved_mem_device_init(struct device *dev) +{ + return __rmem_dev_call(dev, __rmem_dev_init); +} + /** * of_reserved_mem_device_release() - release reserved memory device structures * @@ -271,18 +321,5 @@ int of_reserved_mem_device_init(struct device *dev) */ 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); + __rmem_dev_call(dev, __rmem_dev_release); }