[PATCH] driver core: platform: use reg-names for named memory resource lookup

From: Bowen Yu

Date: Wed Nov 25 2026 - 22:05:43 EST


Not only platform devices described by OF have named memory resources;
devices described by ACPI, in particular those enumerated through the
PRP0001 DT namespace link, may provide the same "reg-names" property in
_DSD, following the respective Device Tree binding. However, resources
created from _CRS carry no names, so platform_get_resource_byname()
always fails for them, which prevents drivers shared between Device
Tree and ACPI from using by-name lookups on ACPI.

Teach platform_get_resource_byname() to resolve the "reg-names" device
property into an index onto the memory resources, in the same manner
as __platform_get_irq_byname() uses fwnode_irq_get_byname() for IRQs:
the i-th string of "reg-names" names the i-th memory resource of the
device, counting memory resources only ("reg" order on DT, _CRS order
on ACPI).

No agreement between the length of "reg-names" and the number of
memory resources is required: an index past the last memory resource
makes platform_get_resource() return NULL, and the existing
named-resource walk is kept as a fallback, so DT behavior is
unchanged and a mis-sized "reg-names" simply yields "resource not
found" for the names it cannot resolve instead of a wrong mapping.

This allows drivers shared between Device Tree and ACPI, e.g. the
Bosch M_CAN controller driver whose DT binding requires "reg-names",
to use platform_get_resource_byname() and
devm_platform_ioremap_resource_byname() unchanged on PRP0001 devices.

Signed-off-by: Bowen Yu <yubowen8@xxxxxxxxxx>
---
.../firmware-guide/acpi/dsd/reg-names.rst | 68 ++++++++++++++++++++++
Documentation/firmware-guide/acpi/index.rst | 1 +
drivers/base/platform.c | 17 ++++++
3 files changed, 86 insertions(+)

diff --git a/Documentation/firmware-guide/acpi/dsd/reg-names.rst b/Documentation/firmware-guide/acpi/dsd/reg-names.rst
new file mode 100644
index 000000000000..76c6363b8d57
--- /dev/null
+++ b/Documentation/firmware-guide/acpi/dsd/reg-names.rst
@@ -0,0 +1,68 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+==========================
+_DSD "reg-names" property
+==========================
+
+"reg-names" is a Device Tree binding property that assigns names to the
+memory regions listed in "reg", allowing drivers to look up resources by
+name with platform_get_resource_byname().
+
+The kernel resolves the same property for platform devices regardless of
+the firmware interface: the i-th string of a "reg-names" string array
+names the i-th memory resource of the device, in "reg" order on Device
+Tree and in _CRS order on ACPI. Only memory resources count toward
+the index; descriptors of other types in _CRS, e.g. interrupts, are
+skipped. platform_get_resource_byname() and
+devm_platform_ioremap_resource_byname() consult the property when a
+named memory resource is requested, and fall back to the named-resource
+lookup, so drivers shared between Device Tree and ACPI work unchanged
+on both.
+
+For ACPI devices the property is provided in the Device Properties UUID
+package of _DSD. This is the natural thing to do for devices described
+by a Device Tree binding, i.e. those enumerated through the PRP0001 DT
+namespace link: firmware following such a binding provides the binding's
+properties in _DSD. Resources created from _CRS carry no names, so
+without the property by-name lookups fail on ACPI.
+
+Note that IRQ resources are handled analogously through
+fwnode_irq_get_byname() (see "Named Interrupts" in
+Documentation/firmware-guide/acpi/enumeration.rst).
+
+Example - a PRP0001 device for a Bosch M_CAN controller, following
+Documentation/devicetree/bindings/net/can/bosch,m_can.yaml::
+
+ Device (CAN0)
+ {
+ Name (_HID, "PRP0001")
+ Name (_DSD, Package () {
+ ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
+ Package () {
+ Package () { "compatible", "bosch,m_can" },
+ Package () { "reg-names", Package () {
+ "m_can", "message_ram"
+ } },
+ }
+ })
+ Method (_CRS, 0, Serialized)
+ {
+ Name (RBUF, ResourceTemplate ()
+ {
+ QWordMemory (ResourceConsumer, PosDecode,
+ MinFixed, MaxFixed, NonCacheable,
+ ReadWrite,
+ 0x0, 0xF0000000, 0xF0000FFF,
+ 0x0, 0x1000)
+ QWordMemory (ResourceConsumer, PosDecode,
+ MinFixed, MaxFixed, NonCacheable,
+ ReadWrite,
+ 0x0, 0xF0001000, 0xF0001FFF,
+ 0x0, 0x1000)
+ })
+ Return (RBUF)
+ }
+ }
+
+Here "m_can" names the first and "message_ram" the second MEM resource
+in _CRS.
diff --git a/Documentation/firmware-guide/acpi/index.rst b/Documentation/firmware-guide/acpi/index.rst
index db9eb7229948..a6db8f327b7f 100644
--- a/Documentation/firmware-guide/acpi/index.rst
+++ b/Documentation/firmware-guide/acpi/index.rst
@@ -13,6 +13,7 @@ ACPI Support
dsd/leds
dsd/motorcomm-yt8xxx-phy
dsd/phy
+ dsd/reg-names
enumeration
osi
method-tracing
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 66f9ec73d47e..e697316b33c2 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -457,6 +457,10 @@ EXPORT_SYMBOL_GPL(devm_platform_get_irqs_affinity);
* @dev: platform device
* @type: resource type
* @name: resource name
+ *
+ * For memory resources, the name may also be resolved through the
+ * "reg-names" firmware device property, where the i-th string names the
+ * i-th memory resource of the device.
*/
struct resource *platform_get_resource_byname(struct platform_device *dev,
unsigned int type,
@@ -464,6 +468,19 @@ struct resource *platform_get_resource_byname(struct platform_device *dev,
{
u32 i;

+ if (type == IORESOURCE_MEM) {
+ int index = device_property_match_string(&dev->dev,
+ "reg-names", name);
+
+ if (index >= 0) {
+ struct resource *r = platform_get_resource(dev, type,
+ index);
+
+ if (r)
+ return r;
+ }
+ }
+
for (i = 0; i < dev->num_resources; i++) {
struct resource *r = &dev->resource[i];