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: 9986363 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6DDF260247 for ; Thu, 5 Oct 2017 03:35:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 61AEF28C02 for ; Thu, 5 Oct 2017 03:35:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 547F528C45; Thu, 5 Oct 2017 03:35:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9EF5526E16 for ; Thu, 5 Oct 2017 03:35:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=UHH0YsCobxNj4mVYzTFPhTKfc0ixbNOflX9XgzdPTGI=; b=arwmcFeV0mJf0C4/g+vQthcMeb CIv4Mr01IPrvsWVlmdrLI6j5lzlh1Yc13zqrHjqGy0jtkZn5P415G4hfxnHRPsgnliJ2UcD380Gx6 Qa7zY/wRzrz/Hxja28Pngf+xg/zJE8se/ZyW/uP0ObN8gv2WPweF3Xs4zDj7XGPXG5h6iOEIL7E1O S2Ea2Aigppvtm9iOk53SqwtojTpzvXSZ+woLiiGIvuRlQ6zgE+2+6c9mPETLnbflP+ePDXVEqckxo V4JvzigNCTsqWi1LdpPhwMJyCovKWUr1NK/NIqou4zDdUkwJ6GM2JhuMHDecFhuYOjg7DKeeO32Lz qXJBPYsw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dzww3-0001hg-3c; Thu, 05 Oct 2017 03:34:55 +0000 Received: from mail-pf0-x230.google.com ([2607:f8b0:400e:c00::230]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dzwuc-0000JI-Ua for linux-arm-kernel@lists.infradead.org; Thu, 05 Oct 2017 03:33:30 +0000 Received: by mail-pf0-x230.google.com with SMTP id u12so7310853pfl.4 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=SK0YRX2emqio0il9Msnp4Mxw+S8REVAOtdePYHa3/Vj9trq/Md0Jl7iApCq6fHw+tb HVpIWNudjwrkJKRAVDpLieZLzzuftyOUtnbsTTPXj7E+k3e0qM13VYwMwiie1fOxJ4jK 3VLQqkiGqVx0x51afzNppmfu9ZtD9NE3ts+TNDWnCtfFKmh+doFOdaGCKAgEpgLW6G0T 1tCJ4Y1imLHyILM4zjLqcbOQxN6A4cQZajkd1kbVGPG7RVaJNlgBy6BWj0yhFxD5W8kk 9B8PG3CVPcFR/kABmnPsSURguLMGvnwdWptXtS0vi6dEjUYk7CtHRlv78C4glydcAkaT NhpA== X-Gm-Message-State: AHPjjUjqRQ0h525XFbdmLOPvISdBgtOwPXHthq40XldRavNfPHfGgoFp gYk1wm2mz5ds6flR+raLdWqoPw== 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171004_203327_034237_177DEA19 X-CRM114-Status: GOOD ( 15.70 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Tony Luck , Kees Cook , linux-arm-msm@vger.kernel.org, Anton Vorontsov , linux-kernel@vger.kernel.org, David Brown , Colin Cross , linux-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Rob Herring --- 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(+) 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 /**