From nobody Sun Feb 8 19:44:26 2026 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (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 5BDE031AAA3 for ; Wed, 7 Jan 2026 13:05:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767791120; cv=none; b=kobzq8kJG2Hry30N+8vyEAx4SAZWLN4gXJR9Sff7swnp0yhO+3eBbBSGZUkYGglc8ktz81Dvu4iB3Srh49b56YtxmIDimL2wboo/xorXah30s+pd3z3oYb5M5aaepbq3Xf1e+QZgr2x/YXVmBlOQxm7APXHiX195dBN+V5yeSdA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767791120; c=relaxed/simple; bh=8L7BEeLSyAGZr88Hz5hZv2yOvdC/hTQ7EyJ6GMOjePs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=brzE5XWbQVWErYGM731f2OxZqZ4+wD4aDHCnRTipVjgRitBKPvMjv1dxnyozq1haiSUh0X8AoEsCkecUFOM5bdy/cpa0SUsOvpr8+mvDXPNLR4+jDRVJHOo4agmOzKI9A6uvQr9HOwUVBOK8kPLzI3CMzNj+S+bhufj9juqvU7k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=0ivL6Xob; arc=none smtp.client-ip=185.246.85.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="0ivL6Xob" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id A7C4F4E41FDE; Wed, 7 Jan 2026 13:05:16 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 7E1E9606F8; Wed, 7 Jan 2026 13:05:16 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id B697C103C872C; Wed, 7 Jan 2026 14:05:13 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1767791115; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=28/kVheK1lvYqLZuz6cxLCTZassa/8QL++w4LyvFy3Q=; b=0ivL6Xobw/RkGwwLITYh6UfvAOWLChYOicSsB1GAPA7BgL4XvR3hFeZucfosgi42g7iQzI c6HbaFj+SUfm0P8qi5lzLqWntM+3yAi48Tnf82GD1iNuqSkDFWuOaN1saaSFTvALAMoFSO 27T2ubyCtpFxA8zG3M0X/tW0AqvLBW1+FJs1FW7QY6/2iAI4AYlIsdrshFAI081/7LLAx5 9waryOXNoT4ssZOoi4zIzQqLCIKRe0sWlaD7BZ/cwLU9M4qnjJcObELdDzvW8Bk0jvoIZz +qKOFd5i+8NCHP8KroYRt+0ur0/xt/3Ti0EsyQEv0Pb0BZO+BHceHr5VR7gU+Q== From: Gregory CLEMENT Date: Wed, 07 Jan 2026 14:04:52 +0100 Subject: [PATCH v3 1/4] of: reserved_mem: Fix placement of __free() annotation Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260107-mtd-memregion-v3-1-f9fc9107b992@bootlin.com> References: <20260107-mtd-memregion-v3-0-f9fc9107b992@bootlin.com> In-Reply-To: <20260107-mtd-memregion-v3-0-f9fc9107b992@bootlin.com> To: Rob Herring , Linus Walleij , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Krzysztof Kozlowski , Conor Dooley Cc: Thomas Petazzoni , Vladimir Kondratiev , =?utf-8?q?Beno=C3=AEt_Monin?= , =?utf-8?q?Th=C3=A9o_Lebrun?= , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mtd@lists.infradead.org, Gregory CLEMENT X-Mailer: b4 0.14.3 X-Last-TLS-Session-Version: TLSv1.3 The __free() annotation was incorrectly placed before the variable name instead of after it, which resulted in the following checkpatch errors: ERROR: need consistent spacing around '*' (ctx:WxV) + struct device_node __free(device_node) *target =3D of_parse_phandle= (np, "memory-region", idx); ^ WARNING: function definition argument 'idx' should also have an identifier = name + struct device_node __free(device_node) *target =3D of_parse_phandle= (np, "memory-region", idx); As part of this cleanup, also remove the useless return statement flagged by checkpatch. Signed-off-by: Gregory CLEMENT --- drivers/of/of_reserved_mem.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 5619ec9178587..1ab8f4153600b 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -127,7 +127,6 @@ static void __init fdt_reserved_mem_save_node(unsigned = long node, const char *un fdt_init_reserved_mem_node(rmem); =20 reserved_mem_count++; - return; } =20 static int __init early_init_dt_reserve_memory(phys_addr_t base, @@ -747,7 +746,7 @@ int of_reserved_mem_region_to_resource(const struct dev= ice_node *np, if (!np) return -EINVAL; =20 - struct device_node __free(device_node) *target =3D of_parse_phandle(np, "= memory-region", idx); + struct device_node *target __free(device_node) =3D of_parse_phandle(np, "= memory-region", idx); if (!target || !of_device_is_available(target)) return -ENODEV; =20 --=20 2.51.0 From nobody Sun Feb 8 19:44:26 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.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 EA5B5315D2A; Wed, 7 Jan 2026 13:05:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767791122; cv=none; b=XyRCCZow3VArHhA+T4dQx+qQsYP0yQpx2vYfLTJOZUN6uSz1T/JcEeZqNXet1V+HIOw7Wa2dI5RaKyJgTUhnlk3xC2yDOlm0jJ1fkMnq621s3ipMNrIKUnhR/Naeojz3smYC1HM4XJkxRoeUrnLj11Oak21FTGejNrGyMpOqun8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767791122; c=relaxed/simple; bh=yTyrj5QoFsGABNaD50sMrBTfi0UxSYpQmgtQqsF91IQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=V5/KvTbiZp+y13wTWVOAgggg9VSYQ4bhJB4Ksepk3aQvF+GBcGn6/L1T+UruMhg8IekCjFL6rYWtQiQLAQpNnJjGCk1ulmr8a8LUX9b5s6IxrFjiQylnxq1L0iUCjsnqoSaUhKonZnBBzd2JvXzzbRVmnMgJFXoT2r/PQN23bm8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=UuENz/RQ; arc=none smtp.client-ip=185.246.84.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="UuENz/RQ" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 7F3D71A26CD; Wed, 7 Jan 2026 13:05:18 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 552FB606F8; Wed, 7 Jan 2026 13:05:18 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 087BF103C873B; Wed, 7 Jan 2026 14:05:15 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1767791117; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=XMo0yKviCSls+Xrv3kwTnjITS8GQtx4OexQnCkfHofE=; b=UuENz/RQwtv9wgkzp85Tr6QLFxQOs22jCliOiild6uFJD47o64iojbXqggSC2Xp+FGTAIK xOJe36VxoJ7UQezuQrBpnmBXIPXugHhTltZPcrEliN54Uv5KDE/i7k/PTYx7gWszNhDCsz BjmBYJ0tVs/Jp25SUJ2U65+iD1S/5qA6wcmctOsb/wvZ9lKSM3P5R0fe+kBd3V2wnA38F2 XdShzZWO+EqWf1mAim3q+LglcI/G9iOeEJDDiBZqLxEkCzViMEqH/gS6e9aSgR7anZCwcG GltrftUgbGWUzZLGzN/z6QZtOE49aqcauTVB7bDAXJ88wELVqUkqnaSQj6wKAw== From: Gregory CLEMENT Date: Wed, 07 Jan 2026 14:04:53 +0100 Subject: [PATCH v3 2/4] of: reserved_mem: Support multiple 'reg' entries for memory-region Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260107-mtd-memregion-v3-2-f9fc9107b992@bootlin.com> References: <20260107-mtd-memregion-v3-0-f9fc9107b992@bootlin.com> In-Reply-To: <20260107-mtd-memregion-v3-0-f9fc9107b992@bootlin.com> To: Rob Herring , Linus Walleij , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Krzysztof Kozlowski , Conor Dooley Cc: Thomas Petazzoni , Vladimir Kondratiev , =?utf-8?q?Beno=C3=AEt_Monin?= , =?utf-8?q?Th=C3=A9o_Lebrun?= , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mtd@lists.infradead.org, Gregory CLEMENT X-Mailer: b4 0.14.3 X-Last-TLS-Session-Version: TLSv1.3 X-Rspamd-Fuzzy: 4424144f4218900c354d6490f15d7fd89bd74a90c2a7348481eaef86083880102d8c77ac236285b683c0bd37638dc6a3f0301a0bc431696a6ae2fe169c719249 The Device Tree specification allows a "memory-region" node to have multiple 'reg' entries, but the current kernel implementation only processes the first entry. This can lead to drivers not being able to access all the reserved memory regions specified in the Device Tree. This patch extends the reserved memory handling to support multiple 'reg' entries for a single "memory-region" node. The existing exported functions remain unchanged for backward compatibility, but new APIs are introduced to allow drivers to access all reserved memory regions. Signed-off-by: Gregory CLEMENT --- drivers/of/of_reserved_mem.c | 147 ++++++++++++++++++++++++++++++++++++= ---- include/linux/of_reserved_mem.h | 4 ++ 2 files changed, 137 insertions(+), 14 deletions(-) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 1ab8f4153600b..c9cef279260e7 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -157,6 +157,7 @@ static int __init __reserved_mem_reserve_reg(unsigned l= ong node, int i, len; const __be32 *prop; bool nomap; + int count =3D 0; =20 prop =3D of_flat_dt_get_addr_size_prop(node, "reg", &len); if (!prop) @@ -179,12 +180,13 @@ static int __init __reserved_mem_reserve_reg(unsigned= long node, dma_contiguous_early_fixup(base, size); pr_debug("Reserved memory: reserved region for node '%s': base %pa, siz= e %lu MiB\n", uname, &base, (unsigned long)(size / SZ_1M)); + count++; } else { pr_err("Reserved memory: failed to reserve memory for node '%s': base %= pa, size %lu MiB\n", uname, &base, (unsigned long)(size / SZ_1M)); } } - return 0; + return count; } =20 /* @@ -247,20 +249,24 @@ void __init fdt_scan_reserved_mem_reg_nodes(void) =20 fdt_for_each_subnode(child, fdt, node) { const char *uname; + const __be32 *reg; u64 b, s; + int i, l; =20 if (!of_fdt_device_is_available(fdt, child)) continue; - - if (!of_flat_dt_get_addr_size(child, "reg", &b, &s)) + reg =3D of_flat_dt_get_addr_size_prop(child, "reg", &l); + if (!reg) continue; - - base =3D b; - size =3D s; - - if (size) { - uname =3D fdt_get_name(fdt, child, NULL); - fdt_reserved_mem_save_node(child, uname, base, size); + for (i =3D 0; i < l; i++) { + of_flat_dt_read_addr_size(reg, i, &b, &s); + base =3D b; + size =3D s; + + if (size) { + uname =3D fdt_get_name(fdt, child, NULL); + fdt_reserved_mem_save_node(child, uname, base, size); + } } } =20 @@ -291,16 +297,16 @@ int __init fdt_scan_reserved_mem(void) =20 fdt_for_each_subnode(child, fdt, node) { const char *uname; - int err; + int err, ret; =20 if (!of_fdt_device_is_available(fdt, child)) continue; =20 uname =3D fdt_get_name(fdt, child, NULL); =20 - err =3D __reserved_mem_reserve_reg(child, uname); - if (!err) - count++; + ret =3D __reserved_mem_reserve_reg(child, uname); + if (ret > 0) + count +=3D ret; /* * Save the nodes for the dynamically-placed regions * into an array which will be used for allocation right @@ -726,6 +732,35 @@ struct reserved_mem *of_reserved_mem_lookup(struct dev= ice_node *np) } EXPORT_SYMBOL_GPL(of_reserved_mem_lookup); =20 +/** + * of_reserved_mem_array_lookup() - acquire reserved_mem array from a devi= ce node + * @np: node pointer of the desired reserved-memory region + * @rmrm: pointer to the first elemennt of the reserved_mem struct of the = memory region + * + * This function allows drivers to acquire a reference to the array of the + * reserved_mem struct based on a device node handle. + * + * Returns the number reserved_mem elements + */ +int of_reserved_mem_array_lookup(struct device_node *np, + struct reserved_mem **rmem) +{ + const char *name; + int i, count =3D 0; + + if (!np->full_name) + return 0; + + name =3D kbasename(np->full_name); + + for (i =3D 0; i < reserved_mem_count; i++) + if (!strcmp(reserved_mem[i].name, name)) + rmem[count++] =3D &reserved_mem[i]; + + return count; +} +EXPORT_SYMBOL_GPL(of_reserved_mem_array_lookup); + /** * of_reserved_mem_region_to_resource() - Get a reserved memory region as = a resource * @np: node containing 'memory-region' property @@ -761,6 +796,49 @@ int of_reserved_mem_region_to_resource(const struct de= vice_node *np, } EXPORT_SYMBOL_GPL(of_reserved_mem_region_to_resource); =20 +/** + * of_reserved_mem_region_to_resource_array() - Get a reserved memory regi= on as a resources + * @dev: device associated to the node + * @np: node containing 'memory-region' property + * @idx: index of 'memory-region' property to lookup + * @res: Pointer to an array of struct resource pointers to fill in with r= eserved regions + * + * This function allows drivers to lookup a node's 'memory-region' property + * entries by index and fill an array of struct resource pointers for the = entries. + * + * Returns the number of resources filled in @res on success. + * Returns -ENODEV if 'memory-region' is missing or unavailable, + * -EINVAL for any other error. + */ +int of_reserved_mem_region_to_resource_array(struct device *dev, const str= uct device_node *np, + unsigned int idx, struct resource **res) +{ + struct reserved_mem *rmem[MAX_RESERVED_REGIONS]; + int count, i; + struct resource *r; + + if (!np) + return -EINVAL; + + struct device_node *target __free(device_node) =3D of_parse_phandle(np, "= memory-region", idx); + if (!target || !of_device_is_available(target)) + return -ENODEV; + + count =3D of_reserved_mem_array_lookup(target, rmem); + if (count <=3D 0) + return -EINVAL; + + *res =3D devm_kzalloc(dev, count * sizeof(struct resource), GFP_KERNEL); + r =3D res[0]; + for (i =3D 0; i < count; i++) { + resource_set_range(&r[i], rmem[i]->base, rmem[i]->size); + r[i].flags =3D IORESOURCE_MEM; + r[i].name =3D rmem[i]->name; + } + return count; +} +EXPORT_SYMBOL_GPL(of_reserved_mem_region_to_resource_array); + /** * of_reserved_mem_region_to_resource_byname() - Get a reserved memory reg= ion as a resource * @np: node containing 'memory-region' property @@ -805,3 +883,44 @@ int of_reserved_mem_region_count(const struct device_n= ode *np) return of_count_phandle_with_args(np, "memory-region", NULL); } EXPORT_SYMBOL_GPL(of_reserved_mem_region_count); + +/** + * of_reserved_mem_region_count() - Return the total number of reserved me= mory regions + * @np: node containing 'memory-region' property + * + * This function counts the total number of reserved memory regions refere= nced + * by a node's 'memory-region' property. It iterates over each phandle and= sums + * the number of regions found in each referenced reserved memory node. + * + * Returns the total number of reserved memory regions on success. + * This function allows drivers to retrieve the number of entries for a no= de's + * 'memory-region' property. + * + * Returns total number of reserved memory regions on success, or negative= error + * code on a malformed property. + */ +int of_reserved_mem_region_total_count(const struct device_node *np) +{ + int nregion =3D of_count_phandle_with_args(np, "memory-region", NULL); + struct device_node *target; + int i, nregs =3D 0; + + for (i =3D 0; i < nregion; i++) { + struct reserved_mem *rmem; + + target =3D of_parse_phandle(np, "memory-region", i); + if (!target) + return -ENODEV; + + if (!of_device_is_available(target)) { + of_node_put(target); + return 0; + } + + nregs +=3D of_reserved_mem_array_lookup(target, &rmem); + + of_node_put(target); + }; + return nregs; +} +EXPORT_SYMBOL_GPL(of_reserved_mem_region_total_count); diff --git a/include/linux/of_reserved_mem.h b/include/linux/of_reserved_me= m.h index f573423359f48..1e0c6afddd812 100644 --- a/include/linux/of_reserved_mem.h +++ b/include/linux/of_reserved_mem.h @@ -40,11 +40,15 @@ int of_reserved_mem_device_init_by_name(struct device *= dev, void of_reserved_mem_device_release(struct device *dev); =20 struct reserved_mem *of_reserved_mem_lookup(struct device_node *np); +int of_reserved_mem_array_lookup(struct device_node *np, struct reserved_m= em **rmem); int of_reserved_mem_region_to_resource(const struct device_node *np, unsigned int idx, struct resource *res); +int of_reserved_mem_region_to_resource_array(struct device *dev, const str= uct device_node *np, + unsigned int idx, struct resource **res); int of_reserved_mem_region_to_resource_byname(const struct device_node *np, const char *name, struct resource *res); int of_reserved_mem_region_count(const struct device_node *np); +int of_reserved_mem_region_total_count(const struct device_node *np); =20 #else =20 --=20 2.51.0 From nobody Sun Feb 8 19:44:26 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.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 EF49C31AAA3 for ; Wed, 7 Jan 2026 13:05:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767791124; cv=none; b=NeQmq1aQRZbd0T9cg0aYXr4yLBgpC/EK3gzfqr7hiRXp185DIhH94GvZdV2xDs9daZLukEe6bjsnaDTOD/Ifwune2gND/417fcf97sXR4j9l5/hGpvvbAwfH9gHBwXEor3sV3S7SsEoFvOnbtU4ZNxtx/OXgkN9EgW4zI7sGBW8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767791124; c=relaxed/simple; bh=XCP/FOFK72L8E2QDh/6XCwQgAkV01L+/PzWMTRRC2G8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CYVG6l9F8TqYzPusOKJIexWQnqGCnNnzaD2DLc/4kksVGxUwJf8Czo7ie5JscT+lTtc1BR7Pr+IfYYw/KBeEtrvb2R4aQed2IYK7x+BPmQFsa67928rKVCIvToX7B3coCSb5g8+6smFW4ObLwkw2ZqWNfyRWP0CiUu9xH0+CRnQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=ewS7wwGI; arc=none smtp.client-ip=185.246.84.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="ewS7wwGI" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 58FDE1A267D; Wed, 7 Jan 2026 13:05:21 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 293AC606F8; Wed, 7 Jan 2026 13:05:21 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 1DC51103C821A; Wed, 7 Jan 2026 14:05:18 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1767791120; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=v86K00C2fNx5hWbvxkan6t0DbijjMzvVsdWXGbU7/lY=; b=ewS7wwGIxnLGvlW1n7rbyYVE272yKtFwMLpXA5dQxwBgkXDCDIjJ/00Crbfj/yjvQoF3KO Tx11D+DGgmI67oFQcEmX+DLOztgWjbGAhymtnaevZ/myz5iv283sMxkj7DacsQAV4NEdVC nBRLthQpl9T4htROsyNVba4lV3jZbja1UpM5F/XhsaEeDHxzwnPPzt2CBAlpzfU7JrGBr5 fuhxbzmg80sngjZygGzgi8Usi8M9d/2iqtt0Ua/gkP6KNf8aAtw82k6Ff+QZgxrkxijLu/ FJnMWcTNqpIBmus89VnLtyDYJww8qXlPXa7us9UgAMbcfqPZtc96NXcaVqYQ0g== From: Gregory CLEMENT Date: Wed, 07 Jan 2026 14:04:54 +0100 Subject: [PATCH v3 3/4] dt-bindings: mtd: physmap: Allow using memory-region to access memory resources Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260107-mtd-memregion-v3-3-f9fc9107b992@bootlin.com> References: <20260107-mtd-memregion-v3-0-f9fc9107b992@bootlin.com> In-Reply-To: <20260107-mtd-memregion-v3-0-f9fc9107b992@bootlin.com> To: Rob Herring , Linus Walleij , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Krzysztof Kozlowski , Conor Dooley Cc: Thomas Petazzoni , Vladimir Kondratiev , =?utf-8?q?Beno=C3=AEt_Monin?= , =?utf-8?q?Th=C3=A9o_Lebrun?= , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mtd@lists.infradead.org, Gregory CLEMENT X-Mailer: b4 0.14.3 X-Last-TLS-Session-Version: TLSv1.3 Enable access to memory resources not only via I/O address using reg, but also through a portion of main memory using memory-region. To achieve this, new compatible strings have been introduced: mtd-mem and mtd-memro. Signed-off-by: Gregory CLEMENT --- .../devicetree/bindings/mtd/mtd-physmap.yaml | 69 ++++++++++++++++--= ---- 1 file changed, 52 insertions(+), 17 deletions(-) diff --git a/Documentation/devicetree/bindings/mtd/mtd-physmap.yaml b/Docum= entation/devicetree/bindings/mtd/mtd-physmap.yaml index a9ec3ca002c7d..98d45982d8eb9 100644 --- a/Documentation/devicetree/bindings/mtd/mtd-physmap.yaml +++ b/Documentation/devicetree/bindings/mtd/mtd-physmap.yaml @@ -13,10 +13,6 @@ description: | Flash chips (Memory Technology Devices) are often used for solid state file systems on embedded devices. =20 -allOf: - - $ref: mtd.yaml# - - $ref: /schemas/memory-controllers/mc-peripheral-props.yaml# - properties: compatible: oneOf: @@ -61,6 +57,8 @@ properties: - jedec-flash - mtd-ram - mtd-rom + - mtd-mem + - mtd-memro =20 reg: description: | @@ -141,19 +139,37 @@ required: - compatible - reg =20 -if: - properties: - compatible: - contains: - const: cortina,gemini-flash -then: - properties: - syscon: - $ref: /schemas/types.yaml#/definitions/phandle - description: - Phandle to the syscon controller - required: - - syscon +allOf: + - if: + properties: + compatible: + contains: + const: cortina,gemini-flash + then: + properties: + syscon: + $ref: /schemas/types.yaml#/definitions/phandle + description: + Phandle to the syscon controller + required: + - syscon + - if: + properties: + compatible: + contains: + enum: + - mtd-mem + - mtd-memro + then: + $ref: /schemas/reserved-memory/reserved-memory.yaml + required: + - no-map + properties: + addr-gpios: false + else: + allOf: + - $ref: /schemas/mtd/mtd.yaml + - $ref: /schemas/memory-controllers/mc-peripheral-props.yaml# =20 unevaluatedProperties: false =20 @@ -233,4 +249,23 @@ examples: reg =3D <0 0x04000000>; }; }; + + - | + /* An example using mtd-mem/mtd-memro */ + reserved-memory { + #address-cells =3D <2>; + #size-cells =3D <2>; + + bm_logs_reserved: bm_logs_reserved@10000800 { + compatible =3D "mtd-mem"; + reg =3D <0x1 0x0000800 0x0 0x0010000>; + no-map; + }; + + sys_logs_reserved: sys_logs_reserved@100120000 { + compatible =3D "mtd-memro"; + reg =3D <0x1 0x00120000 0x0 0x0010000>; + no-map; + }; + }; ... --=20 2.51.0 From nobody Sun Feb 8 19:44:26 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.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 332AD3242C2 for ; Wed, 7 Jan 2026 13:05:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767791126; cv=none; b=RbvbjU6vTYo+IeujUYA75fiAGfG9vEliVETPWTlBXT3Eh0mAKSHgJrPkvzFUYC4fhicl4ljL1WVpu7meej7iWC/F97TosMhetYQrfNIV8+5qUvgZvApxI3g/cHyqcFDfJkyoPsP2U17gSU/lCWlMN/BVI7puKb6wAbTvHSU8ARg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767791126; c=relaxed/simple; bh=jNiohkw8WHKcjgp8E4YtNg8lqzzvPeJEXSyUoCZnSE8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KKjV9aNTJv1ExotSMMjGANJiVWXEd9EfYNC/WRA4cMld6s2EHxMunqoU8+jUNd1s3SSFbfZ14UMuWE4o08zINcHxlOuEkBqKSazJj4lRXgYAGKQet3P4F6tvE6vZNvRocdFrLg0JytF/OkV650xvuXWGnRPR6ClhaI4qnOTuQsE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=lWrkF9GS; arc=none smtp.client-ip=185.246.84.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="lWrkF9GS" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id C98FF1A26D8; Wed, 7 Jan 2026 13:05:22 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 9F772606F8; Wed, 7 Jan 2026 13:05:22 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id BA835103C873E; Wed, 7 Jan 2026 14:05:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1767791121; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=zbeN6veyBsnJXwhFnHq/E++8EqnB+Vxb96PGx9jh/pQ=; b=lWrkF9GSBlwT5WwjIrJ9TOFk3IsntDlxprTL54vzRz54XOAtyuJZi3klPX5atMpEEmvOyk El0roSJp5z20SqmXU3oyLxnth8Zqe3alS2KduFKQBQjR26nh+brdhA3TpmhJuv68BS3o+a nRCyP8+eVuQqEWrHz4BEV2h/gdtxUIZ4Q0Ro6SAduQSfWSD4Lz2X+NtQTqQDxhCGT53vQ2 GAnfoGmhkXOXbQDbwRzXwQSw8voIFDuDEUwEiU1Z/1egq0Wp8AB01D3c+kpcCuwrUgj2dR PLZSDL/p4qF6xbk/N/4cOlhexrRJYw+ovoCEK297up3OMPsb5ZjwyC8tFgoNMA== From: Gregory CLEMENT Date: Wed, 07 Jan 2026 14:04:55 +0100 Subject: [PATCH v3 4/4] mtd: physmap: Add support for RAM reserved memory regions Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260107-mtd-memregion-v3-4-f9fc9107b992@bootlin.com> References: <20260107-mtd-memregion-v3-0-f9fc9107b992@bootlin.com> In-Reply-To: <20260107-mtd-memregion-v3-0-f9fc9107b992@bootlin.com> To: Rob Herring , Linus Walleij , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Krzysztof Kozlowski , Conor Dooley Cc: Thomas Petazzoni , Vladimir Kondratiev , =?utf-8?q?Beno=C3=AEt_Monin?= , =?utf-8?q?Th=C3=A9o_Lebrun?= , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mtd@lists.infradead.org, Gregory CLEMENT X-Mailer: b4 0.14.3 X-Last-TLS-Session-Version: TLSv1.3 MTD fixed-partitions can now be exposed for reserved RAM regions, not just ROM reg regions. This is achieved by using the new compatible property (mtd-mem or mtd-memro) previously introduced in the reserved memory region node. Based on the work of Muhammad Musa Signed-off-by: Gregory CLEMENT --- drivers/mtd/maps/physmap-core.c | 73 +++++++++++++++++++++++++++++++++----= ---- drivers/of/platform.c | 2 ++ 2 files changed, 62 insertions(+), 13 deletions(-) diff --git a/drivers/mtd/maps/physmap-core.c b/drivers/mtd/maps/physmap-cor= e.c index 2bd7a1af898c9..cc7d08a413c78 100644 --- a/drivers/mtd/maps/physmap-core.c +++ b/drivers/mtd/maps/physmap-core.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include =20 @@ -263,6 +264,14 @@ static const struct of_device_id of_flash_match[] =3D { .type =3D "rom", .compatible =3D "direct-mapped" }, + { + .compatible =3D "mtd-mem", + .data =3D "map_ram", + }, + { + .compatible =3D "mtd-memro", + .data =3D "map_rom", + }, { /* sentinel */ }, }; MODULE_DEVICE_TABLE(of, of_flash_match); @@ -348,10 +357,19 @@ static int physmap_flash_of_init(struct platform_devi= ce *dev) =20 map_indirect =3D of_property_read_bool(dp, "no-unaligned-direct-access"); =20 - err =3D of_property_read_u32(dp, "bank-width", &bankwidth); - if (err) { - dev_err(&dev->dev, "Can't get bank width from device tree\n"); - return err; + if ((of_device_is_compatible(dp, "mtd-mem")) || + (of_device_is_compatible(dp, "mtd-memro"))) { + /* + * When using reserved memory region from DRAM we use + * the defaullt 32 bits acces + */ + bankwidth =3D 4; + } else { + err =3D of_property_read_u32(dp, "bank-width", &bankwidth); + if (err) { + dev_err(&dev->dev, "Can't get bank width from device tree\n"); + return err; + } } =20 if (of_property_read_bool(dp, "big-endian")) @@ -446,8 +464,9 @@ static int physmap_flash_pdata_init(struct platform_dev= ice *dev) static int physmap_flash_probe(struct platform_device *dev) { struct physmap_flash_info *info; - int err =3D 0; - int i; + struct resource *res_array; + int err =3D 0, is_rsvd_mem =3D 0, nreg =3D 0; + int i, curr_reg; =20 if (!dev->dev.of_node && !dev_get_platdata(&dev->dev)) return -EINVAL; @@ -459,9 +478,13 @@ static int physmap_flash_probe(struct platform_device = *dev) while (platform_get_resource(dev, IORESOURCE_MEM, info->nmaps)) info->nmaps++; =20 - if (!info->nmaps) - return -ENODEV; - + if (!info->nmaps) { + info->nmaps =3D of_reserved_mem_region_total_count(dev->dev.of_node); + if (info->nmaps > 0) + is_rsvd_mem =3D 1; + else + return -ENODEV; + } info->maps =3D devm_kzalloc(&dev->dev, sizeof(*info->maps) * info->nmaps, GFP_KERNEL); @@ -503,7 +526,23 @@ static int physmap_flash_probe(struct platform_device = *dev) for (i =3D 0; i < info->nmaps; i++) { struct resource *res; =20 - info->maps[i].virt =3D devm_platform_get_and_ioremap_resource(dev, i, &r= es); + if (is_rsvd_mem) { + if (nreg <=3D i) { + int cnt =3D of_reserved_mem_region_to_resource_array(&dev->dev, + dev->dev.of_node, i, &res_array); + if (cnt < 0) { + err =3D cnt; + goto err_out; + } + nreg +=3D cnt; + curr_reg =3D 0; + } + res =3D &res_array[curr_reg++]; + info->maps[i].virt =3D devm_ioremap_resource(&dev->dev, res); + } else { + info->maps[i].virt =3D devm_platform_get_and_ioremap_resource(dev, i, &= res); + } + if (IS_ERR(info->maps[i].virt)) { err =3D PTR_ERR(info->maps[i].virt); goto err_out; @@ -519,9 +558,17 @@ static int physmap_flash_probe(struct platform_device = *dev) info->maps[i].phys =3D res->start; =20 info->win_order =3D fls64(resource_size(res)) - 1; - info->maps[i].size =3D BIT(info->win_order + - (info->gpios ? - info->gpios->ndescs : 0)); + /* When using a memory region, the size is not necessarily a + * power of 2, so win_order is not applicable. Since GPIOs are + * unavailable in this context, directly using the region's size + * is safe. + */ + if (is_rsvd_mem) + info->maps[i].size =3D resource_size(res); + else + info->maps[i].size =3D BIT(info->win_order + + (info->gpios ? + info->gpios->ndescs : 0)); =20 info->maps[i].map_priv_1 =3D (unsigned long)dev; =20 diff --git a/drivers/of/platform.c b/drivers/of/platform.c index f77cb19973a5d..23ea5a723aa7f 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -496,6 +496,8 @@ static const struct of_device_id reserved_mem_matches[]= =3D { { .compatible =3D "ramoops" }, { .compatible =3D "nvmem-rmem" }, { .compatible =3D "google,open-dice" }, + { .compatible =3D "mtd-memro" }, + { .compatible =3D "mtd-mem" }, {} }; =20 --=20 2.51.0