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: 9998691 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 72C4E60230 for ; Wed, 11 Oct 2017 05:20:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 65CB6288B8 for ; Wed, 11 Oct 2017 05:20:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5A773288BD; Wed, 11 Oct 2017 05:20:55 +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 BB799288B8 for ; Wed, 11 Oct 2017 05:20:54 +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=PQumzS6LebEVn/tNIH1WaoL4UJFsrUFXhElnwsNNztk=; b=jwGQaxWbyeoFL5/zcoeM/VpJag zgG9zSx7Xd4/5yLaoseWfXq2cDRIdu20Gj2/eQK8nYmJtzjQz3ehGL9BnZEhfnvWaJ11cNx8OaWsw lw9MfeWhuJ0MQfGbvRxD+R3ECJQ9q0EM8MJRbrf/AuSR3rF7XFlwjvQBjEdNmhFKXJ5MNvRDvJW7I mMVDhvbpyGUAw4rPrT6iRrtPVtEpoQBqCBMA0952nvAGDimSyl3qqf71zFPb7AwP4UjvWj9UzjwNi PO875WA3q1I/kkHHpLBTtt4EcyUdAmv5Hd5l4t7vl1HMIklykTORNC0nZB3Zazteg8Blp09HKJK1b CHgEFwPA==; 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 1e29Rt-0002Ay-MA; Wed, 11 Oct 2017 05:20:53 +0000 Received: from mail-pf0-x236.google.com ([2607:f8b0:400e:c00::236]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e29Gq-00036f-JD for linux-arm-kernel@lists.infradead.org; Wed, 11 Oct 2017 05:09:30 +0000 Received: by mail-pf0-x236.google.com with SMTP id n14so540162pfh.8 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=YF9/l7kgfPLgb+cCgGbx7SEIttkyGOD1a3q5tZI3K9P4VEI2H8rjPOXwOcsVjT2dZ5 Ja7WEzvuhg8ciBDSOyY4fslvuaJhqz4llbH3Jju09Fq6/guNm7/9Hc4VCn10ymcFnQdH UspZRz7lJPoBmWQ8jvAHFwvAwJ+juHDiGTV0abLZHI45FWrDzIGnqjH5PEKxRN9IfwxI /SV9SXB3obTcxvwtNRmM3zzzVWj7mhZLFwy4ItdfD6KLBaKY6T/htTkmmD+YszDvSDi5 /U0WUHaG2Bxz1cOYmMJIv6pR+n5zfbGuIPgBxPNrTBkT2YMBMTI3098bpkIo+O/gyiQ+ 9F0w== X-Gm-Message-State: AMCzsaVhU6kqzQO8AC92bQznLgA5gLHdRAECkaba9xXmRN9bsCaej1R5 li/tx9ZSXErFWjz89O/WLpOXuA== 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171010_220928_738126_C07EFCB0 X-CRM114-Status: GOOD ( 16.06 ) 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. 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(+) 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 /**