From nobody Mon Feb 9 23:39:04 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