From nobody Tue Dec 2 01:25:31 2025 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 BC27E2D8764 for ; Fri, 21 Nov 2025 15:42:50 +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=1763739775; cv=none; b=kyHaClgDUWFBXuWslZefc/GfRVpcT+bEtZ6o6xScBYaT3Wgd0jbIHlPp+Skx9FWo7yNPoX+aCa9fRW0DVkLCQjQGpIBEbq2cQSPUiveAYjCXeMwm7juopO1yTU9VoabT33QfXzwTr5plPdpKLdHDU02ec7bjqStM+adRH0SMdKY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763739775; c=relaxed/simple; bh=R4Di4HnIicbPPtLbB8fde2op/ku0MJYw+GNztvpfabw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QrHlPvq6wlClfWRjGRc3nz9g3gF+bpqDUh1c8MTUTAfpJYsLsrfTleibpC2I3/y8f0CCGeFlp/xvOd0wrMyQwHBoeD7df9c8Bg2TdWcN6qaFRp++zVC65moVNkX8KgT7NIfLnxPobX8+P98cu5Y8lUQ6r6rcNtCtGWd7ESCGcdc= 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=cvmVBhT6; 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="cvmVBhT6" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id CBB0B1A1C97; Fri, 21 Nov 2025 15:42:46 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 9E51D60719; Fri, 21 Nov 2025 15:42:46 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id A793210372188; Fri, 21 Nov 2025 16:42:44 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1763739765; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=BTriyQZYYbnJqpQ9NHQXwg7JbzvLw55voRo8bIRkgF0=; b=cvmVBhT6OnVhWqrq/NM5dwpFkuXvXiRy+NzWEqJJOy1dNawbXqrlhyFSOExl1av7RgTWXV pWRRuJ25YYOIquXNd9ssNDDExXKSelGjameE8FGYnF45biWFSmLXHqd7NiRdfEUBkIq76I RuddAFVlYFKhIGyPdGXHVZ4A/S6uL7Gj7R3KqfpoSxfh9UJTQG8TXuYNEyh1rYYdm1Yo7X /i1Io1C8oJUV0ljSZZbRYVVbRlmdvAlQTYKATPKK0XFHTSO/MLb16BIY1vO5E5j4auqknt URLxal3XwSQOoUZ3rsexAtskjDkthSvpHJSr0R/ehNAJiNfrdJ8LF1yl8SL3vw== From: Gregory CLEMENT Date: Fri, 21 Nov 2025 16:42:37 +0100 Subject: [PATCH v2 3/3] 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: <20251121-mtd-memregion-v2-3-c5535fdcebe4@bootlin.com> References: <20251121-mtd-memregion-v2-0-c5535fdcebe4@bootlin.com> In-Reply-To: <20251121-mtd-memregion-v2-0-c5535fdcebe4@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 a memory-region phandle to reference the reserved RAM region instead of the reg property. Based on the work of Muhammad Musa Signed-off-by: Gregory CLEMENT --- drivers/mtd/maps/physmap-core.c | 56 ++++++++++++++++++++++++++++++++++---= ---- 1 file changed, 47 insertions(+), 9 deletions(-) diff --git a/drivers/mtd/maps/physmap-core.c b/drivers/mtd/maps/physmap-cor= e.c index 2bd7a1af898c9..f084f6f34d611 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); @@ -446,8 +455,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 +469,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 +517,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 +549,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 --=20 2.51.0