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: 36011 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f199.google.com (mail-ie0-f199.google.com [209.85.223.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 9F26E2054F for ; Tue, 26 Aug 2014 12:14:23 +0000 (UTC) Received: by mail-ie0-f199.google.com with SMTP id tr6sf47287700ieb.2 for ; Tue, 26 Aug 2014 05:14:23 -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: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=7SCBU3K2rt2qptmtLgFVDgGHbzMP9IE6gsYRnz6FCXU=; b=R3gTISyUkmnn5YQBm9XPp6VcvQVUb6tJfXZLXFm2dCXPiuyfQh41YpRXgs1xdEuUGx K/HkWvMVto5HvzkpYcKKWC+JrP8+ETeZcV1Sm3cFXMg6Jy0bdqsPc0NlSw25LZ4X+m9M ieJOxZGZiEDAcwOG7/8zz1Bdfn95OfCIcDgFW+zfwaWIJi3Zy/rY5GQ0URW3NxZHizUW sFf8yoaivhKptecS4NAMacE13bsG0gBcAGPmisenZCwXdhaIKGWwYPS1t/RIt3Vs//ur WfQbr2nyXAj4keDRyg3/gGq/ipxuIIDT/ULHhSi1JSPDRaJpclIuQAbor0uDMXBhKBRG oAag== X-Gm-Message-State: ALoCoQl/d9o/+lRbY4igy2+wcISyF5trwba0k8z3aFXO/FIn2TtApSKAcAGI3HGwLre7Sv64H20a X-Received: by 10.182.186.4 with SMTP id fg4mr18691731obc.9.1409055263022; Tue, 26 Aug 2014 05:14:23 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.25.148 with SMTP id 20ls2453054qgt.86.gmail; Tue, 26 Aug 2014 05:14:22 -0700 (PDT) X-Received: by 10.221.64.142 with SMTP id xi14mr11595782vcb.31.1409055262836; Tue, 26 Aug 2014 05:14:22 -0700 (PDT) Received: from mail-vc0-f172.google.com (mail-vc0-f172.google.com [209.85.220.172]) by mx.google.com with ESMTPS id d7si1304172vcs.15.2014.08.26.05.14.22 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 26 Aug 2014 05:14:22 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.172 as permitted sender) client-ip=209.85.220.172; Received: by mail-vc0-f172.google.com with SMTP id im17so16671122vcb.17 for ; Tue, 26 Aug 2014 05:14:22 -0700 (PDT) X-Received: by 10.220.172.8 with SMTP id j8mr11315637vcz.32.1409055262747; Tue, 26 Aug 2014 05:14:22 -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.45.67 with SMTP id uj3csp193582vcb; Tue, 26 Aug 2014 05:14:22 -0700 (PDT) X-Received: by 10.140.34.37 with SMTP id k34mr869025qgk.9.1409055262245; Tue, 26 Aug 2014 05:14:22 -0700 (PDT) Received: from ip-10-141-164-156.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id g6si3469981qam.102.2014.08.26.05.14.21 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 26 Aug 2014 05:14:22 -0700 (PDT) Received-SPF: none (google.com: linaro-mm-sig-bounces@lists.linaro.org does not designate permitted sender hosts) 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 1XMFdk-0007Dt-AA; Tue, 26 Aug 2014 12:14:20 +0000 Received: from mailout3.w1.samsung.com ([210.118.77.13]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XMFdO-0007C8-Ex for linaro-mm-sig@lists.linaro.org; Tue, 26 Aug 2014 12:13:58 +0000 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> for linaro-mm-sig@lists.linaro.org; 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 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= Cc: Arnd Bergmann , Tomasz Figa , Michal Nazarewicz , linaro-mm-sig@lists.linaro.org, Kyungmin Park , Grant Likely , Joonsoo Kim , Josh Cartwright , linux-media@vger.kernel.org Subject: [Linaro-mm-sig] [PATCH 2/7] drivers: of: add support for named memory regions 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=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.172 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 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); }