From patchwork Thu Aug 3 02:57:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 109290 Delivered-To: patch@linaro.org Received: by 10.140.101.6 with SMTP id t6csp213301qge; Wed, 2 Aug 2017 19:58:45 -0700 (PDT) X-Received: by 10.84.208.227 with SMTP id c32mr181424plj.281.1501729125036; Wed, 02 Aug 2017 19:58:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501729125; cv=none; d=google.com; s=arc-20160816; b=O/dJvkZiq5uNgTERMY7C1R97jTZUZZ1BJx2Yy6YhSZtpOCfWysdo9bfhgfXMDsQSjX XamKENlhISedFrNy//3/A9eqHmCy//I5rGRv0ULapRNX91Oh7lBu1MSaVPWvpHY/0b4v TlJDjfm7TZcr/8qKwTOzKGrx50Wez2c0OqBRytiDR6DADYZUhFsxmva2ddJb/fWmJJyv MCnlTtU5cnqJXVLApblOmZSMh3KbvYdmlP+ETDhbCuAEosDLWu66amrKILbaf6YKGkCx PPTHBjhz6TfFDB2d/OzTihaEYUC4JfzuLMgUPyFdGbSUAtHd75AKvv1pfKpnrYmBRHVf xTew== 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=ut2l3JQHCN/sqG0k4p57VWZEQUy2msWXF1eETHbZvlc=; b=iFvZXjzdtKF18WFPEHqVgwBkqE55clb4Y73vgQwzT4ascKXzV6k1pZZxCYNYawglTt 8z+KyY5HEpmsuSmo9Fly8Sl0iGnmxy6rK6XOsgOdH1aR2Mhih8bGdHBxM0/Ei41bO5eM oSIH8qlqFSOY2fqiG0mON0gNTpqWEpMHubxnCA+cxG3aoVr4Aj0sNsys0s0CLcqBndYD 21KuegUSqYu4QorFhiXmTb2znWzaEKdk6QUbVDP2vWo8IewzuV+k6AYm8ah4AgHRzEji wakpuTF8QdHH1Scirs/UqffbFxMrOwXTEpXZJK54BFx3ebRnGd7hygld/nud5Z3kRYZy 5WLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=IfcbjljI; 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 i63si7110424pgc.373.2017.08.02.19.58.44; Wed, 02 Aug 2017 19:58:45 -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.b=IfcbjljI; 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 S1752263AbdHCC6l (ORCPT + 25 others); Wed, 2 Aug 2017 22:58:41 -0400 Received: from mail-pg0-f54.google.com ([74.125.83.54]:37208 "EHLO mail-pg0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752086AbdHCC6C (ORCPT ); Wed, 2 Aug 2017 22:58:02 -0400 Received: by mail-pg0-f54.google.com with SMTP id y129so732302pgy.4 for ; Wed, 02 Aug 2017 19:58:02 -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=ut2l3JQHCN/sqG0k4p57VWZEQUy2msWXF1eETHbZvlc=; b=IfcbjljIbGLkalXegZmPWDyptEqYUzg3axFl+0Mc1vhLJQsfr0WcFcE7IpHyImpQ5m t9/jMIY8sjn1E5UPoZ8+CXxrp9kSnrYYytIjMVxIgpWXD98bQMZdtuuGyHUOUAnJuFew bQ6Rj2Yk0xCKRLi05fxTmh2q1j6lOB2kJ30JM= 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=ut2l3JQHCN/sqG0k4p57VWZEQUy2msWXF1eETHbZvlc=; b=e17TnIMVNWa+05YsdHU+EAaQOOGPOe98Hhlk8fBujOrDa2u6Z0XpqUjBsAxB5GkHlf ijK9/7FXsqYdhCCxp8b2qpTdcdSqCgw5sqhDKoj1i+6SWaRlf2cDmXhSKn5oOTcdIhwX FrDBj79fzcjtSriUWYG3Z86Ucts1rCfuI7uTtABfB7qWBcjjbTuQKdVNuXA8JSBwXw2R GtpcdaA8sd+ByJZnJMdldm7yoybp0uMPSvQekhHcO5Pe2YiyWzN5iJ0GdoAkF47aVE+M lLaOcLre1zGrx0cyYjc5lQPrrxmecxJfNzxfDV8HUUM8c/QjCJZ9OWxBKL4ycOnXEtVE Wzxw== X-Gm-Message-State: AIVw111Na4/RjZQtWMWNIjeRDxXI30GneVbNq6j38869/WB9faY5IztL /Wcd5yBQCJJfasTX X-Received: by 10.84.193.101 with SMTP id e92mr188043pld.209.1501729081687; Wed, 02 Aug 2017 19:58:01 -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 z83sm10722573pfd.10.2017.08.02.19.58.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Aug 2017 19:58:01 -0700 (PDT) From: Bjorn Andersson To: Rob Herring , Frank Rowand , Andy Gross , David Brown Cc: Mark Rutland , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-soc@vger.kernel.org Subject: [PATCH v2 2/5] of: reserved_mem: Accessor for acquiring reserved_mem Date: Wed, 2 Aug 2017 19:57:51 -0700 Message-Id: <20170803025754.19101-3-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170803025754.19101-1-bjorn.andersson@linaro.org> References: <20170803025754.19101-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. Signed-off-by: Bjorn Andersson --- 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..b40cfce68fd4 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_get() - 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_get(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_get); diff --git a/include/linux/of_reserved_mem.h b/include/linux/of_reserved_mem.h index f8e1992d6423..91b1eb5076e4 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_get(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_get(struct device_node *np) +{ + return NULL; +} #endif /**