From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A094620966B for ; Tue, 18 Mar 2025 11:12:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.176.79.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742296374; cv=none; b=ZrIqDlDQtVY1QDFDKq3wQFIV7luF+X3tdhSrHMRgViQEC8xNLD/xCCYfKwczfIFCX7YauPdrFI1szW5mkRiRPmvvbSN7Rk75qjploinCnxUcrlgO3M9ZPo09xABNiDl6i1h1ZKXFRcxekcIk2sE6/TcPs/poyOsibBIT5Uesgsc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742296374; c=relaxed/simple; bh=9UrIRnOEexJiEpGUNEC3ds5vz80G5i/X5dIiR7KUgko=; h=Date:From:To:CC:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Ih0tXfYQHkNWSjtmeW77W7ZNV+pgMHyyPrCrlBBiViO+3m+sfYP1/MjJWldnCCOie8IpsyWjFwSx+a6JKKLYx6JOYMpb926LtFFNsBzn2AAkfZoEqGvwi5CzA/Quk4oiUInky/4EoTmLPjCskduh3THaarciZ+pHESNuvkbLrQE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=185.176.79.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.18.186.31]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4ZH8HW4vxNz6LDCB; Tue, 18 Mar 2025 19:09:27 +0800 (CST) Received: from frapeml500008.china.huawei.com (unknown [7.182.85.71]) by mail.maildlp.com (Postfix) with ESMTPS id 8F53214050C; Tue, 18 Mar 2025 19:12:44 +0800 (CST) Received: from localhost (10.203.177.66) by frapeml500008.china.huawei.com (7.182.85.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Tue, 18 Mar 2025 12:12:43 +0100 Date: Tue, 18 Mar 2025 11:12:42 +0000 From: Jonathan Cameron To: "Rob Herring (Arm)" CC: Saravana Kannan , Bjorn Andersson , Mathieu Poirier , "Shawn Guo" , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Patrice Chotard , "Maxime Coquelin" , Alexandre Torgue , , , , , , , Subject: Re: [PATCH 1/3] of: reserved_mem: Add functions to parse "memory-region" Message-ID: <20250318111242.00007457@huawei.com> In-Reply-To: <20250317232426.952188-2-robh@kernel.org> References: <20250317232426.952188-1-robh@kernel.org> <20250317232426.952188-2-robh@kernel.org> X-Mailer: Claws Mail 4.3.0 (GTK 3.24.42; x86_64-w64-mingw32) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-ClientProxiedBy: lhrpeml100003.china.huawei.com (7.191.160.210) To frapeml500008.china.huawei.com (7.182.85.71) On Mon, 17 Mar 2025 18:24:21 -0500 "Rob Herring (Arm)" wrote: > Drivers with "memory-region" properties currently have to do their own > parsing of "memory-region" properties. The result is all the drivers > have similar patterns of a call to parse "memory-region" and then get > the region's address and size. As this is a standard property, it should > have common functions for drivers to use. Add new functions to count the > number of regions and retrieve the region's address as a resource. > > Signed-off-by: Rob Herring (Arm) > --- > drivers/of/of_reserved_mem.c | 77 +++++++++++++++++++++++++++++++++ > include/linux/of_reserved_mem.h | 26 +++++++++++ > 2 files changed, 103 insertions(+) > > diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c > index 75e819f66a56..fd50038dff76 100644 > --- a/drivers/of/of_reserved_mem.c > +++ b/drivers/of/of_reserved_mem.c > @@ -12,6 +12,7 @@ > #define pr_fmt(fmt) "OF: reserved mem: " fmt > > #include > +#include > #include > #include > #include > @@ -740,3 +741,79 @@ struct reserved_mem *of_reserved_mem_lookup(struct device_node *np) > return NULL; > } > EXPORT_SYMBOL_GPL(of_reserved_mem_lookup); > + > +/** > + * of_reserved_mem_region_to_resource() - Get a reserved memory region as a resource > + * @np: node containing 'memory-region' property > + * @idx: index of 'memory-region' property to lookup > + * @res: Pointer to a struct resource to fill in with reserved region > + * > + * This function allows drivers to lookup a node's 'memory-region' property > + * entries by index and return a struct resource for the entry. > + * > + * Returns 0 on success with @res filled in. Returns -ENODEV if 'memory-region' > + * is missing or unavailable, -EINVAL for any other error. > + */ > +int of_reserved_mem_region_to_resource(const struct device_node *np, unsigned int idx, struct resource *res) Maybe wrap? > +{