[PATCH v5 2/4] ACPI: of: match PRP0001 in of_match_device

Markus Probst via B4 Relay posted 4 patches 3 days, 16 hours ago
[PATCH v5 2/4] ACPI: of: match PRP0001 in of_match_device
Posted by Markus Probst via B4 Relay 3 days, 16 hours ago
From: Markus Probst <markus.probst@posteo.de>

Export `acpi_of_match_device` function and use it to match for PRP0001
in `of_match_device`, if the device does not have a device node.

This fixes the match data being NULL when using ACPI PRP0001, even though
the device was matched against an of device table.

Signed-off-by: Markus Probst <markus.probst@posteo.de>
---
 drivers/acpi/bus.c   |  7 ++++---
 drivers/of/device.c  |  9 +++++++--
 include/linux/acpi.h | 11 +++++++++++
 3 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index 2ec095e2009e..cd02f04cf685 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -831,9 +831,9 @@ const struct acpi_device *acpi_companion_match(const struct device *dev)
  * identifiers and a _DSD object with the "compatible" property, use that
  * property to match against the given list of identifiers.
  */
-static bool acpi_of_match_device(const struct acpi_device *adev,
-				 const struct of_device_id *of_match_table,
-				 const struct of_device_id **of_id)
+bool acpi_of_match_device(const struct acpi_device *adev,
+			  const struct of_device_id *of_match_table,
+			  const struct of_device_id **of_id)
 {
 	const union acpi_object *of_compatible, *obj;
 	int i, nval;
@@ -866,6 +866,7 @@ static bool acpi_of_match_device(const struct acpi_device *adev,
 
 	return false;
 }
+EXPORT_SYMBOL_GPL(acpi_of_match_device);
 
 static bool acpi_of_modalias(struct acpi_device *adev,
 			     char *modalias, size_t len)
diff --git a/drivers/of/device.c b/drivers/of/device.c
index f7e75e527667..128682390058 100644
--- a/drivers/of/device.c
+++ b/drivers/of/device.c
@@ -11,6 +11,7 @@
 #include <linux/mod_devicetable.h>
 #include <linux/slab.h>
 #include <linux/platform_device.h>
+#include <linux/acpi.h>
 
 #include <asm/errno.h>
 #include "of_private.h"
@@ -26,8 +27,12 @@
 const struct of_device_id *of_match_device(const struct of_device_id *matches,
 					   const struct device *dev)
 {
-	if (!matches || !dev->of_node || dev->of_node_reused)
-		return NULL;
+	if (!matches || !dev->of_node || dev->of_node_reused) {
+		const struct of_device_id *id = NULL;
+
+		acpi_of_match_device(ACPI_COMPANION(dev), matches, &id);
+		return id;
+	}
 	return of_match_node(matches, dev->of_node);
 }
 EXPORT_SYMBOL(of_match_device);
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 4d2f0bed7a06..1cf23edcbfbb 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -736,6 +736,10 @@ const struct acpi_device_id *acpi_match_acpi_device(const struct acpi_device_id
 const struct acpi_device_id *acpi_match_device(const struct acpi_device_id *ids,
 					       const struct device *dev);
 
+bool acpi_of_match_device(const struct acpi_device *adev,
+			  const struct of_device_id *of_match_table,
+			  const struct of_device_id **of_id);
+
 const void *acpi_device_get_match_data(const struct device *dev);
 extern bool acpi_driver_match_device(struct device *dev,
 				     const struct device_driver *drv);
@@ -965,6 +969,13 @@ static inline const struct acpi_device_id *acpi_match_device(
 	return NULL;
 }
 
+static inline bool acpi_of_match_device(const struct acpi_device *adev,
+					const struct of_device_id *of_match_table,
+					const struct of_device_id **of_id)
+{
+	return false;
+}
+
 static inline const void *acpi_device_get_match_data(const struct device *dev)
 {
 	return NULL;

-- 
2.52.0
Re: [PATCH v5 2/4] ACPI: of: match PRP0001 in of_match_device
Posted by Krzysztof Kozlowski 3 days, 3 hours ago
On Sun, Mar 29, 2026 at 08:02:16PM +0200, Markus Probst wrote:
> Export `acpi_of_match_device` function and use it to match for PRP0001
> in `of_match_device`, if the device does not have a device node.
> 
> This fixes the match data being NULL when using ACPI PRP0001, even though
> the device was matched against an of device table.

Fixes tag?

I don't see how this is going to fix !ACPI case - the
acpi_of_match_device() will just return false.


> 
> Signed-off-by: Markus Probst <markus.probst@posteo.de>
> ---
>  drivers/acpi/bus.c   |  7 ++++---
>  drivers/of/device.c  |  9 +++++++--
>  include/linux/acpi.h | 11 +++++++++++
>  3 files changed, 22 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
> index 2ec095e2009e..cd02f04cf685 100644
> --- a/drivers/acpi/bus.c
> +++ b/drivers/acpi/bus.c
> @@ -831,9 +831,9 @@ const struct acpi_device *acpi_companion_match(const struct device *dev)
>   * identifiers and a _DSD object with the "compatible" property, use that
>   * property to match against the given list of identifiers.
>   */
> -static bool acpi_of_match_device(const struct acpi_device *adev,
> -				 const struct of_device_id *of_match_table,
> -				 const struct of_device_id **of_id)
> +bool acpi_of_match_device(const struct acpi_device *adev,
> +			  const struct of_device_id *of_match_table,
> +			  const struct of_device_id **of_id)
>  {
>  	const union acpi_object *of_compatible, *obj;
>  	int i, nval;
> @@ -866,6 +866,7 @@ static bool acpi_of_match_device(const struct acpi_device *adev,
>  
>  	return false;
>  }
> +EXPORT_SYMBOL_GPL(acpi_of_match_device);
>  
>  static bool acpi_of_modalias(struct acpi_device *adev,
>  			     char *modalias, size_t len)
> diff --git a/drivers/of/device.c b/drivers/of/device.c
> index f7e75e527667..128682390058 100644
> --- a/drivers/of/device.c
> +++ b/drivers/of/device.c
> @@ -11,6 +11,7 @@
>  #include <linux/mod_devicetable.h>
>  #include <linux/slab.h>
>  #include <linux/platform_device.h>
> +#include <linux/acpi.h>
>  
>  #include <asm/errno.h>
>  #include "of_private.h"
> @@ -26,8 +27,12 @@
>  const struct of_device_id *of_match_device(const struct of_device_id *matches,
>  					   const struct device *dev)
>  {
> -	if (!matches || !dev->of_node || dev->of_node_reused)
> -		return NULL;
> +	if (!matches || !dev->of_node || dev->of_node_reused) {
> +		const struct of_device_id *id = NULL;
> +
> +		acpi_of_match_device(ACPI_COMPANION(dev), matches, &id);

I don't think this should be done from of_match_device. Yuo will have
soon recursive calls, because acpi_of_match_device() will call other
match, that will call of_match_device() and so on...

of_match_device() is supposed to match only against OF. Not ACPI. There
should be no ACPI header or code in this unit file.

Best regards,
Krzysztof
Re: [PATCH v5 2/4] ACPI: of: match PRP0001 in of_match_device
Posted by Markus Probst 2 days, 15 hours ago
On Mon, 2026-03-30 at 09:00 +0200, Krzysztof Kozlowski wrote:
> On Sun, Mar 29, 2026 at 08:02:16PM +0200, Markus Probst wrote:
> > Export `acpi_of_match_device` function and use it to match for PRP0001
> > in `of_match_device`, if the device does not have a device node.
> > 
> > This fixes the match data being NULL when using ACPI PRP0001, even though
> > the device was matched against an of device table.
> 
> Fixes tag?
> 
> I don't see how this is going to fix !ACPI case - the
> acpi_of_match_device() will just return false.
While trying to argue I found out that there already is
`device_get_match_data`, which takes PRP0001 into account.

I will now instead make a patch, which will make rust use this function
instead of calling `of_match_device` and `acpi_match_device`
individually, which ignores PRP0001.

There are still a lot of drivers only using `of_match_device`, which
makes it impossible to use PRP0001 with them. But this is not relevant
for this driver.

Thanks
- Markus Probst

> 
> 
> > 
> > Signed-off-by: Markus Probst <markus.probst@posteo.de>
> > ---
> >  drivers/acpi/bus.c   |  7 ++++---
> >  drivers/of/device.c  |  9 +++++++--
> >  include/linux/acpi.h | 11 +++++++++++
> >  3 files changed, 22 insertions(+), 5 deletions(-)
> > 
> > diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
> > index 2ec095e2009e..cd02f04cf685 100644
> > --- a/drivers/acpi/bus.c
> > +++ b/drivers/acpi/bus.c
> > @@ -831,9 +831,9 @@ const struct acpi_device *acpi_companion_match(const struct device *dev)
> >   * identifiers and a _DSD object with the "compatible" property, use that
> >   * property to match against the given list of identifiers.
> >   */
> > -static bool acpi_of_match_device(const struct acpi_device *adev,
> > -				 const struct of_device_id *of_match_table,
> > -				 const struct of_device_id **of_id)
> > +bool acpi_of_match_device(const struct acpi_device *adev,
> > +			  const struct of_device_id *of_match_table,
> > +			  const struct of_device_id **of_id)
> >  {
> >  	const union acpi_object *of_compatible, *obj;
> >  	int i, nval;
> > @@ -866,6 +866,7 @@ static bool acpi_of_match_device(const struct acpi_device *adev,
> >  
> >  	return false;
> >  }
> > +EXPORT_SYMBOL_GPL(acpi_of_match_device);
> >  
> >  static bool acpi_of_modalias(struct acpi_device *adev,
> >  			     char *modalias, size_t len)
> > diff --git a/drivers/of/device.c b/drivers/of/device.c
> > index f7e75e527667..128682390058 100644
> > --- a/drivers/of/device.c
> > +++ b/drivers/of/device.c
> > @@ -11,6 +11,7 @@
> >  #include <linux/mod_devicetable.h>
> >  #include <linux/slab.h>
> >  #include <linux/platform_device.h>
> > +#include <linux/acpi.h>
> >  
> >  #include <asm/errno.h>
> >  #include "of_private.h"
> > @@ -26,8 +27,12 @@
> >  const struct of_device_id *of_match_device(const struct of_device_id *matches,
> >  					   const struct device *dev)
> >  {
> > -	if (!matches || !dev->of_node || dev->of_node_reused)
> > -		return NULL;
> > +	if (!matches || !dev->of_node || dev->of_node_reused) {
> > +		const struct of_device_id *id = NULL;
> > +
> > +		acpi_of_match_device(ACPI_COMPANION(dev), matches, &id);
> 
> I don't think this should be done from of_match_device. Yuo will have
> soon recursive calls, because acpi_of_match_device() will call other
> match, that will call of_match_device() and so on...
> 
> of_match_device() is supposed to match only against OF. Not ACPI. There
> should be no ACPI header or code in this unit file.
> 
> Best regards,
> Krzysztof
Re: [PATCH v5 2/4] ACPI: of: match PRP0001 in of_match_device
Posted by Rob Herring 2 days, 15 hours ago
On Mon, Mar 30, 2026 at 07:04:21PM +0000, Markus Probst wrote:
> On Mon, 2026-03-30 at 09:00 +0200, Krzysztof Kozlowski wrote:
> > On Sun, Mar 29, 2026 at 08:02:16PM +0200, Markus Probst wrote:
> > > Export `acpi_of_match_device` function and use it to match for PRP0001
> > > in `of_match_device`, if the device does not have a device node.
> > > 
> > > This fixes the match data being NULL when using ACPI PRP0001, even though
> > > the device was matched against an of device table.
> > 
> > Fixes tag?
> > 
> > I don't see how this is going to fix !ACPI case - the
> > acpi_of_match_device() will just return false.
> While trying to argue I found out that there already is
> `device_get_match_data`, which takes PRP0001 into account.
> 
> I will now instead make a patch, which will make rust use this function
> instead of calling `of_match_device` and `acpi_match_device`
> individually, which ignores PRP0001.

IIRC, the rust binding already gives you the data pointer in probe.

> There are still a lot of drivers only using `of_match_device`, which
> makes it impossible to use PRP0001 with them. But this is not relevant
> for this driver.

Usually using of_match_device() in drivers is wrong. You generally just 
want the data pointer. There's a whole bunch of drivers still doing the 
old way.

Rob
Re: [PATCH v5 2/4] ACPI: of: match PRP0001 in of_match_device
Posted by Markus Probst 2 days, 15 hours ago
On Mon, 2026-03-30 at 14:22 -0500, Rob Herring wrote:
> On Mon, Mar 30, 2026 at 07:04:21PM +0000, Markus Probst wrote:
> > On Mon, 2026-03-30 at 09:00 +0200, Krzysztof Kozlowski wrote:
> > > On Sun, Mar 29, 2026 at 08:02:16PM +0200, Markus Probst wrote:
> > > > Export `acpi_of_match_device` function and use it to match for PRP0001
> > > > in `of_match_device`, if the device does not have a device node.
> > > > 
> > > > This fixes the match data being NULL when using ACPI PRP0001, even though
> > > > the device was matched against an of device table.
> > > 
> > > Fixes tag?
> > > 
> > > I don't see how this is going to fix !ACPI case - the
> > > acpi_of_match_device() will just return false.
> > While trying to argue I found out that there already is
> > `device_get_match_data`, which takes PRP0001 into account.
> > 
> > I will now instead make a patch, which will make rust use this function
> > instead of calling `of_match_device` and `acpi_match_device`
> > individually, which ignores PRP0001.
> 
> IIRC, the rust binding already gives you the data pointer in probe.
Yes, but that pointer is obtained by calling `acpi_match_device` and
`of_match_device` [1].

Thanks
- Markus Probst

[1]
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/rust/kernel/driver.rs?id=7aaa8047eafd0bd628065b15757d9b48c5f9c07d

> 
> > There are still a lot of drivers only using `of_match_device`, which
> > makes it impossible to use PRP0001 with them. But this is not relevant
> > for this driver.
> 
> Usually using of_match_device() in drivers is wrong. You generally just 
> want the data pointer. There's a whole bunch of drivers still doing the 
> old way.
> 
> Rob