From patchwork Thu Oct 5 03:32:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 114829 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp132546qgn; Wed, 4 Oct 2017 20:33:28 -0700 (PDT) X-Received: by 10.159.254.20 with SMTP id r20mr9772665pls.16.1507174408303; Wed, 04 Oct 2017 20:33:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507174408; cv=none; d=google.com; s=arc-20160816; b=uUzL+GnmK8YkonyFjqyL2WnmMTCyw8WJQX39IyNm9SCu0hrKETYGX9azNXgjNlt9sQ IeFWzKcGLtDazcdIheb2wDTppcG8/di5QUHV7L5OdyWpy7KocfbEX151bjUUi7R7qs1r 3VR2yLjsbu9TkaQ/Axmlm3ktANfH63sKNpk4G25kj9ySI1O0Rok4zHwm1pr5wZktZKMZ Cub9c/wAxtHhQ55+ihcqagVpJ0NE/6U6EDeK014NIvnYEUqpbcIzldNZNab1rAslSMbO TUQh8PZmr+4FU9SrD5CcRJSgGDur59yEcgWX+y+PdluI0P/nAfqsWM+xhEwtzCkBWh+R pojQ== 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=ewV4Qimsn6CENQjx46gnZva1PgFePn704g2zhdN+j6w=; b=kI78W/LN1pmn2u6PBbc2cUDrkC4k6Xsv+LBT1PlCzJvaq30F5I0q+s1U8P639FLPTS zeA6hSLmwGdeOIthCCAwYQgd3cMivD+qulUTS8S4wTYqEUzyP2t+P7GHqVMCQAQlA1f5 8R4TRcwK/749crZLF8ZjS8+S7lAmi3613Ypr9N8pEn8blnVhOLpqPc2TgTSIgkltbNgo X3jF2GT5CThY3mlDE4NEWEcIHAPecCqAu2mQ6kaU029pdnDNBOkhtiw51GRt4oyIBS+F nX+aFolUCrNPSRvs37aSvGA6LKoSFteSyOnDMrlJFeM7C5KUIn3df5pshNs8DwqH6uzV EOWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Usby7NsO; 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 n2si128312pgp.47.2017.10.04.20.33.28; Wed, 04 Oct 2017 20:33:28 -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=Usby7NsO; 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 S1751474AbdJEDdL (ORCPT + 26 others); Wed, 4 Oct 2017 23:33:11 -0400 Received: from mail-pf0-f170.google.com ([209.85.192.170]:48185 "EHLO mail-pf0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751260AbdJEDdG (ORCPT ); Wed, 4 Oct 2017 23:33:06 -0400 Received: by mail-pf0-f170.google.com with SMTP id n24so7300380pfk.5 for ; Wed, 04 Oct 2017 20:33:06 -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=ewV4Qimsn6CENQjx46gnZva1PgFePn704g2zhdN+j6w=; b=Usby7NsO9vQKe03KQ03oEZX/QGueQnU74rINJVfbyPBOGrCiejsrEpA/5oZSl1JhLn BYQP2oc9u4jS0FmXa6MB0My5IoyzI0vNDX8d4lDeG2oKCKiN/QEv8AuGm2oD1abLZKdh rNxTRycCEjl76Nhq6uJV4xykYxfLc6APTee3k= 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=ewV4Qimsn6CENQjx46gnZva1PgFePn704g2zhdN+j6w=; b=F2txFdAJFbkAgbRdjyLKV03WTX0EuqVGBPT+yAD0oSwQla69E+XoCY/o+mXxvWNxSL RHPx4jWszTYYgll92Z6r+JeASTDvAOO9EaVLDnvsjsRbPpHQqU2PUbBGyPMliWW3QhyU yyu4SE/qoqsqFK7hkW1IbttoaBSVk2zV+NPik6ErFB5LzaH41Emei9rUeqeJdFxk6pRv +e1fKvMhDWWVnZDUZcvJTYNBN1odc9tBH5QFYnubc8db5RdHSH+sotbsxCuEOV4adrBD N89ycDs/4WbMQbx5+WjTCLBD3V1KurN+eDlavGaBRNFFcpNmRzsJS/bb05JZKwjRl7dp OuXQ== X-Gm-Message-State: AHPjjUgonFRmS8clXGC94u9BzDPEBzFGKe12+4I7cL3la+83ybSLBbNS 3VyXg6V7NQsP7NN9JfiHOVP1BA== X-Google-Smtp-Source: AOwi7QB4nM0uLEAkoiv3dzhjvB9MLQdZc6xko3/p7tKXCuZjJhd+QP5H6Pi2k78ieTkZFRsVKN1vAA== X-Received: by 10.84.143.131 with SMTP id 3mr22097010plz.224.1507174385731; Wed, 04 Oct 2017 20:33: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 h70sm28945700pfc.51.2017.10.04.20.33.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Oct 2017 20:33:05 -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 v3 2/5] of: reserved_mem: Accessor for acquiring reserved_mem Date: Wed, 4 Oct 2017 20:32:55 -0700 Message-Id: <20171005033258.12825-3-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20171005033258.12825-1-bjorn.andersson@linaro.org> References: <20171005033258.12825-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 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..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 /**