From patchwork Sat Apr 22 17:35:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 97955 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp814327qgf; Sat, 22 Apr 2017 10:35:56 -0700 (PDT) X-Received: by 10.84.209.167 with SMTP id y36mr22668913plh.78.1492882556685; Sat, 22 Apr 2017 10:35:56 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o13si13825668pfg.277.2017.04.22.10.35.56; Sat, 22 Apr 2017 10:35:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1044000AbdDVRfz (ORCPT + 7 others); Sat, 22 Apr 2017 13:35:55 -0400 Received: from mail-it0-f50.google.com ([209.85.214.50]:34959 "EHLO mail-it0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1043999AbdDVRf0 (ORCPT ); Sat, 22 Apr 2017 13:35:26 -0400 Received: by mail-it0-f50.google.com with SMTP id 70so18110768ita.0 for ; Sat, 22 Apr 2017 10:35:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=nRCWhyZZVO8/+dsydHueTae9K5EiQMooiLS/8V1WhOw=; b=jelasMpD3AYSZYa51xf2myZd2PexG6bDddM3fsPqLtxhU4Wqy/Pm5gVM95qUM9MnoW QTgdOVv0pTM6ERcPvwXfdEfCTBtavMI8zRg62gsahBz6dUh4MmtFlddApLR7aFHXPsNP 2rOkDM2aprd3AWdVojQXozElr2f7Jyovj7N1Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=nRCWhyZZVO8/+dsydHueTae9K5EiQMooiLS/8V1WhOw=; b=kRUjVUktt9V7FLPX5D2wpGZSWL0lDc4u3MM4QuYdJmGIsgrdrfcE/1BK9g8Sk7GabP iOsET1kNas4DsbO74XIa3YHD+RfTQcs/yhxfWvMQ2JxVrojYWDFQh78ZKl4y6lFFxQhH p233Ae+fEtHn7TJQtBG0jw5rToy4ClMttIQBnZrVNY4BMYRSmJMzCQou/3DqClaBws0z 5WCUbBz0OHGN5AaxEkhqNVlHw3YDHnA7yLKPdRIC7Lx7jKFPxOULNTfUQ+ESyxeVr8sO gBde+jSrgB9a6vZKHdJ6/HaNowfSUXU18QKpAa60Ve1rehxE5bCvx6TUvZg9uy5akpzU 0yIg== X-Gm-Message-State: AN3rC/5KYq60/Nqkv1mZnlXp2eaoCai+19xHg+mgpvX8oXLfqtBDuCk5 SLYi2UvrmqbrlmMf X-Received: by 10.84.143.1 with SMTP id 1mr22663120ply.70.1492882525551; Sat, 22 Apr 2017 10:35:25 -0700 (PDT) Received: from localhost.localdomain (ip68-111-223-48.sd.sd.cox.net. [68.111.223.48]) by smtp.gmail.com with ESMTPSA id r73sm22477462pfa.65.2017.04.22.10.35.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 22 Apr 2017 10:35:24 -0700 (PDT) From: Bjorn Andersson To: Andy Gross , David Brown , Frank Rowand , Rob Herring , Mark Rutland Cc: linux-arm-msm@vger.kernel.org, linux-soc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC 2/3] of: reserved_mem: Accessor for acquiring reserved_mem Date: Sat, 22 Apr 2017 10:35:18 -0700 Message-Id: <20170422173519.5782-2-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170422173519.5782-1-bjorn.andersson@linaro.org> References: <20170422173519.5782-1-bjorn.andersson@linaro.org> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org In some cases drivers referencing a reserved-memory region might want to remap the entire region, but when defining the reserved-memory by "size" the client driver has no means to know the associated base address of the reserved memory region. This patch adds an accessor for such drivers to acquire a handle to their associated reserved-memory for this purpose. Signed-off-by: Bjorn Andersson --- I would have preferred if we could provide a mechanism for drivers to find the reserved_mem of their own device_node, but without a phandle I have not been able to figure out a sane way to make the match. Suggestions are very welcome. drivers/of/of_reserved_mem.c | 26 ++++++++++++++++++++++++++ include/linux/of_reserved_mem.h | 8 ++++++++ 2 files changed, 34 insertions(+) -- 2.12.0 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Reviewed-by: Frank Rowand diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index d507c3569a88..aa69c9590a5c 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -397,3 +397,29 @@ void of_reserved_mem_device_release(struct device *dev) rmem->ops->device_release(rmem, dev); } EXPORT_SYMBOL_GPL(of_reserved_mem_device_release); + +/** + * of_get_reserved_mem_by_idx() - acquire reserved_mem from memory-region + * @np: node pointer containing the "memory-region" + * @idx: index within memory-region + * + * This function allows drivers to acquire a reference to the reserved_mem + * struct which is referenced by their memory-region. + * + * Returns a reserved_mem reference, or NULL on error. + */ +struct reserved_mem *of_get_reserved_mem_by_idx(struct device_node *np, int idx) +{ + struct device_node *target; + struct reserved_mem *rmem; + + target = of_parse_phandle(np, "memory-region", idx); + if (!target) + return NULL; + + rmem = __find_rmem(target); + of_node_put(target); + + return rmem; +} +EXPORT_SYMBOL_GPL(of_get_reserved_mem_by_idx); diff --git a/include/linux/of_reserved_mem.h b/include/linux/of_reserved_mem.h index f8e1992d6423..a9abbe7dd3de 100644 --- a/include/linux/of_reserved_mem.h +++ b/include/linux/of_reserved_mem.h @@ -34,6 +34,8 @@ int of_reserved_mem_device_init_by_idx(struct device *dev, struct device_node *np, int idx); void of_reserved_mem_device_release(struct device *dev); +struct reserved_mem *of_get_reserved_mem_by_idx(struct device_node *np, int idx); + int early_init_dt_alloc_reserved_memory_arch(phys_addr_t size, phys_addr_t align, phys_addr_t start, @@ -52,6 +54,12 @@ static inline int of_reserved_mem_device_init_by_idx(struct device *dev, } static inline void of_reserved_mem_device_release(struct device *pdev) { } +static inline struct reserved_mem *of_get_reserved_mem_by_idx(struct device_node *np, + int idx); +{ + return NULL; +} + 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) { }