From patchwork Wed Oct 11 05:08:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 115494 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp339359qgn; Tue, 10 Oct 2017 22:10:02 -0700 (PDT) X-Received: by 10.101.65.11 with SMTP id w11mr6948565pgp.207.1507698602220; Tue, 10 Oct 2017 22:10:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507698602; cv=none; d=google.com; s=arc-20160816; b=BDdJfzgB+leZdQxK3+SgHR5cDR0xmKddLKNOyn8CSXlHW0znBduit5VcCk3B9sb5Ui IRWazJAixokpLC5fwXNHkg7YdXXBdXWtKhasMIzkrh+PD2SHbssKXUnL0AzOMJCQJgQ/ N3pfUmJM7Ze8pC6Bna7dontkvDJaypkEAubVFK/UKid18ba9ygvwSTgUE39HJUFNRuin lwVC9QTbTByBRYMoALdxYgRIaJHiUoruAmhd/RcXPz/mAlE72EJeekump6LdYjP05/iT IxhrOH+/++A1yQqrA901JrDef1O28kmbx2lDsyJCcFOGa/5Kofq3e63j/WftSq5bdNs2 Mg9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=3HkPyj2Sf2NndRDkteoEYLrqkOYFD28lTS5yEyGB6qU=; b=JAaNOw1qbzdDLdIRUnwsBs/lK1QXBXHFqRqS4G07mVa2VMi+lswuGTZqfyJ3VXtD0q Q6DgMjPy/ijRtHMD9se+d/Sm/EUywTgvP5GFgsTMbSznc8lZfIrumdAllp7vUa9NFYok BKkKrYCNbZr4ID8U+WjCUUluSFiws4wQbedbsP/4805i+g2sQDmJDG0lkGsqCiUS6IyX bBV/HiVd18YVsaeEMA8bVkT16+LcvHEWb9BIqGn5Q5hgemSAO6fXFIeOjtZM6DZFoe5Z 36CfaHrX09Ygbk5Chx/gA5Y6ixkwEvxCUA5sjOxzbhbNMSbIY9ZD5Dxz5dHvnNPZ+cpO P9xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AKjVAU9V; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t8si497184plo.439.2017.10.10.22.10.01; Tue, 10 Oct 2017 22:10:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AKjVAU9V; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757204AbdJKFKA (ORCPT + 26 others); Wed, 11 Oct 2017 01:10:00 -0400 Received: from mail-pf0-f170.google.com ([209.85.192.170]:56780 "EHLO mail-pf0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932286AbdJKFJG (ORCPT ); Wed, 11 Oct 2017 01:09:06 -0400 Received: by mail-pf0-f170.google.com with SMTP id b85so528531pfj.13 for ; Tue, 10 Oct 2017 22:09:05 -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=3HkPyj2Sf2NndRDkteoEYLrqkOYFD28lTS5yEyGB6qU=; b=AKjVAU9VYZe0EToTCDcZoBLdKV+SpBkWwoxz6/Eb8+WEvBFbLMgWSdEI51etUmEeFT Jyk7OAI0E55HqzMpSiHxquJxipWHnX1k2fm/0h4uw3I40ihTAwcB2mIchGqSNnk66JvC q3+peEuj6O9bcpu2ioXKxgkVu85etN94yDw9Q= 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=3HkPyj2Sf2NndRDkteoEYLrqkOYFD28lTS5yEyGB6qU=; b=CIlDQ0qEgHpP90uUeNGWd6r2wl1Tw2BsqTGTfdMgfXWaCJuvRjaOtefu/0ZDlfhqdQ S0bOjLBSS/6EPoepVjXt27nXTUcBwGKY9uOvq0HOpDHLiqrghNUWveoI4A40uKB8rCyo RsVkw2IZAsuHpovmXDoQDNCwVmech26U5S9w7v2SuEBF8tdG0tCAdzNdaPj4BJqw/Chs PAA0nObb4y8EVMSRCPZsf3wQqL0dvxytYnIqXonLsa/DW8Xhibz5GvSluSafYyf1OAGi 1WfDGvTYfYM8CDUAMRxGGzqxJxMzu/bSAQPYWrGOtjVomwlGE30xU5vv9frjPJge9ghB IFBg== X-Gm-Message-State: AMCzsaWOhjO7ZPG3a/a4LH/n+OHlMl8NN0ayYO3MdP3X/b/OjrkcY8DV NCTqRh+WqkSJzYyRMNOHCgGc7A== X-Google-Smtp-Source: AOwi7QA1HzRW6MqU1GZHSOz4f6hvgMolWmTP82YhMGPGC3hJbBfAeI3Uexnx9y9LoybaKdzuVNRqlQ== X-Received: by 10.84.235.129 with SMTP id p1mr13979037plk.153.1507698545288; Tue, 10 Oct 2017 22:09:05 -0700 (PDT) Received: from localhost.localdomain (ip68-111-217-79.sd.sd.cox.net. [68.111.217.79]) by smtp.gmail.com with ESMTPSA id n29sm28336361pgd.74.2017.10.10.22.09.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Oct 2017 22:09:04 -0700 (PDT) From: Bjorn Andersson To: Andy Gross , Frank Rowand , Rob Herring Cc: Anton Vorontsov , Colin Cross , David Brown , Kees Cook , Tony Luck , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-soc@vger.kernel.org Subject: [PATCH v4 2/5] of: reserved_mem: Accessor for acquiring reserved_mem Date: Tue, 10 Oct 2017 22:08:54 -0700 Message-Id: <20171011050857.7588-3-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20171011050857.7588-1-bjorn.andersson@linaro.org> References: <20171011050857.7588-1-bjorn.andersson@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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. A complicating factor for the implementation is that the reserved_mem objects are created from the flattened DeviceTree, as such we can't use the device_node address for comparison. Fortunately the name of the node will be used as "name" of the reserved_mem and will be used when building the full_name, so we can compare the "name" with the basename of the full_name to find the match. Reviewed-by: Rob Herring Signed-off-by: Bjorn Andersson --- Changes since v3: - Renamed function from _get() to _lookup() - Picked up Rob's R-b Changes since v2: - None Changes since v1: - Previous patch provided interface to resolve memory-region reference, instead of direct lookup by device_node drivers/of/of_reserved_mem.c | 26 ++++++++++++++++++++++++++ include/linux/of_reserved_mem.h | 5 +++++ 2 files changed, 31 insertions(+) -- 2.12.0 diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index d507c3569a88..b108c7a1f74c 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_reserved_mem_lookup() - acquire reserved_mem from a device node + * @np: node pointer of the desired reserved-memory region + * + * This function allows drivers to acquire a reference to the reserved_mem + * struct based on a device node handle. + * + * Returns a reserved_mem reference, or NULL on error. + */ +struct reserved_mem *of_reserved_mem_lookup(struct device_node *np) +{ + const char *name; + int i; + + if (!np->full_name) + return NULL; + + name = kbasename(np->full_name); + for (i = 0; i < reserved_mem_count; i++) + if (!strcmp(reserved_mem[i].name, name)) + return &reserved_mem[i]; + + return NULL; +} +EXPORT_SYMBOL_GPL(of_reserved_mem_lookup); diff --git a/include/linux/of_reserved_mem.h b/include/linux/of_reserved_mem.h index f8e1992d6423..c58f780104f9 100644 --- a/include/linux/of_reserved_mem.h +++ b/include/linux/of_reserved_mem.h @@ -44,6 +44,7 @@ int early_init_dt_alloc_reserved_memory_arch(phys_addr_t size, 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); +struct reserved_mem *of_reserved_mem_lookup(struct device_node *np); #else static inline int of_reserved_mem_device_init_by_idx(struct device *dev, struct device_node *np, int idx) @@ -55,6 +56,10 @@ 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) { } +static inline struct reserved_mem *of_reserved_mem_lookup(struct device_node *np) +{ + return NULL; +} #endif /**