ACPI: bus: Use OF match data for PRP0001 matched devices
PATCH v3 1/1 ACPI: bus: Use OF match data for PRP0001 matched devices
During pre-production development, drivers may provide both ACPI and OF match tables while a formal ACPI HID for the device is not yet allocated. Such devices are enumerated via PRP0001. In this case, acpi_device_get_match_data() consults only the driver’s ACPI match table and returns NULL, even though the device was successfully matched via PRP0001.
This behavior also risks breaking existing PRP0001 setups if a driver later gains an ACPI HID, as the presence of an ACPI match table changes the match-data lookup path.
Explicitly detect PRP0001 and fetch match data from the driver's OF match table via acpi_of_device_get_match_data().
---
Changes in v3:
* Swap arguments while comparing HID against PRP0001.
* Check value of adev against NULL.
* Declare variables in reversed xmas tree order.
* Update commit message.
Changes in v2:
* Fix build errors.
--- drivers/acpi/bus.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/acpi/bus.c +5 -1
@@ -1030,9 +1030,13 @@ static const void *acpi_of_device_get_match_data(const struct device *dev)const void *acpi_device_get_match_data (const struct device *dev) {const struct acpi_device_id *acpi_ids = dev->driver->acpi_match_table; +struct acpi_device *adev =ACPI_COMPANION (dev);const struct acpi_device_id *match; -if (!acpi_ids) +if (!adev) +return NULL ; + +if (!strcmp (acpi_device_hid (adev),ACPI_DT_NAMESPACE_HID ))return acpi_of_device_get_match_data (dev); match =acpi_match_device (acpi_ids, dev);
Signature · 1 line
2.43.0
Quoted 36 lines · Kartik Rajput
During pre-production development, drivers may provide both ACPI and OF match tables while a formal ACPI HID for the device is not yet allocated. Such devices are enumerated via PRP0001. In this case,
acpi_device_get_match_data()consults only the driver’s ACPI match table and returns NULL, even though the device was successfully matched via PRP0001.This behavior also risks breaking existing PRP0001 setups if a driver later gains an ACPI HID, as the presence of an ACPI match table changes the match-data lookup path.
Explicitly detect PRP0001 and fetch match data from the driver's OF match table via
acpi_of_device_get_match_data().Signed-off-by Kartik Rajput <[email protected]>---
Changes in v3:
* Swap arguments while comparing HID against PRP0001.
* Check value of adev against NULL.
* Declare variables in reversed xmas tree order.
* Update commit message.
Changes in v2:
* Fix build errors.--- drivers/acpi/bus.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/acpi/bus.c +1
-0@@ -1030,9 +1030,13 @@ static const void *acpi_of_device_get_match_data(const struct device *dev)const void *acpi_device_get_match_data (const struct device *dev) {const struct acpi_device_id *acpi_ids = dev->driver->acpi_match_table; +struct acpi_device *adev =ACPI_COMPANION (dev);
drivers/acpi/bus.c static const void *acpi_of_device_get_match_data(const struct device *dev) · line 1042
Quoted 10 lines
drivers/acpi/bus.c +4
-1const struct acpi_device_id *match; -if (!acpi_ids) +if (!adev) +return NULL ; + +if (!strcmp (acpi_device_hid (adev),ACPI_DT_NAMESPACE_HID ))return acpi_of_device_get_match_data (dev); match =acpi_match_device (acpi_ids, dev);
Should you check with !acpi_ids still here?
Quoted 2 lines
Signature · 1 line
2.43.0
Quoted 14 lines · Mika Westerberg
Quoted 13 lines · Kartik Rajput
During pre-production development, drivers may provide both ACPI and OF match tables while a formal ACPI HID for the device is not yet allocated. Such devices are enumerated via PRP0001. In this case,
acpi_device_get_match_data()consults only the driver’s ACPI match table and returns NULL, even though the device was successfully matched via PRP0001.This behavior also risks breaking existing PRP0001 setups if a driver later gains an ACPI HID, as the presence of an ACPI match table changes the match-data lookup path.
Explicitly detect PRP0001 and fetch match data from the driver's OF match table via
acpi_of_device_get_match_data().
...
Quoted 10 lines
drivers/acpi/bus.c static const void *acpi_of_device_get_match_data(const struct device *dev) · line 1040
Quoted 10 lines
drivers/acpi/bus.c +5
-1const struct acpi_device_id *acpi_ids = dev->driver->acpi_match_table; +struct acpi_device *adev =ACPI_COMPANION (dev);const struct acpi_device_id *match; -if (!acpi_ids) +if (!adev) +return NULL ; + +if (!strcmp (acpi_device_hid (adev),ACPI_DT_NAMESPACE_HID ))return acpi_of_device_get_match_data (dev);
On top of what Mika asked, shouldn't we check CID as well? Theoretically it's possible that some device may have HID "blablabla" and CID PRP0001, I don't remember what documentation says about this case, though.
Quoted 3 lines
Quoted 1 line
match =
acpi_match_device(acpi_ids, dev);Should you check with !acpi_ids still here?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi Andy,
Quoted 22 lines · Andy Shevchenko
Quoted 14 lines · Mika Westerberg
Quoted 13 lines · Kartik Rajput
During pre-production development, drivers may provide both ACPI and OF match tables while a formal ACPI HID for the device is not yet allocated. Such devices are enumerated via PRP0001. In this case,
acpi_device_get_match_data()consults only the driver’s ACPI match table and returns NULL, even though the device was successfully matched via PRP0001.This behavior also risks breaking existing PRP0001 setups if a driver later gains an ACPI HID, as the presence of an ACPI match table changes the match-data lookup path.
Explicitly detect PRP0001 and fetch match data from the driver's OF match table via
acpi_of_device_get_match_data()....
Quoted 4 lines
Quoted 4 lines
drivers/acpi/bus.c +1
-0const struct acpi_device_id *acpi_ids = dev->driver->acpi_match_table; +struct acpi_device *adev =ACPI_COMPANION (dev);const struct acpi_device_id *match;
Quoted 10 lines
Quoted 6 lines
drivers/acpi/bus.c static const void *acpi_of_device_get_match_data(const struct device *dev) · line 1040
Quoted 6 lines
drivers/acpi/bus.c +4
-1-if (!acpi_ids) +if (!adev) +return NULL ; + +if (!strcmp (acpi_device_hid (adev),ACPI_DT_NAMESPACE_HID ))return acpi_of_device_get_match_data (dev);On top of what Mika asked, shouldn't we check CID as well? Theoretically it's possible that some device may have HID "blablabla" and CID PRP0001, I don't remember what documentation says about this case, though.
According to Documentation/firmware-guide/acpi/enumeration.rst PRP0001 is also valid for _CID. So yes, I think this should be checked as well -- I'd loop over the &device->pnp.ids list.
Signature · 3 lines
Regards, Sakari Ailus
Quoted 16 lines · Sakari Ailus
Quoted 15 lines · Andy Shevchenko
Quoted 14 lines · Mika Westerberg
Quoted 13 lines · Kartik Rajput
During pre-production development, drivers may provide both ACPI and OF match tables while a formal ACPI HID for the device is not yet allocated. Such devices are enumerated via PRP0001. In this case,
acpi_device_get_match_data()consults only the driver’s ACPI match table and returns NULL, even though the device was successfully matched via PRP0001.This behavior also risks breaking existing PRP0001 setups if a driver later gains an ACPI HID, as the presence of an ACPI match table changes the match-data lookup path.
Explicitly detect PRP0001 and fetch match data from the driver's OF match table via
acpi_of_device_get_match_data().
...
Quoted 15 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/acpi/bus.c +1
-0const struct acpi_device_id *acpi_ids = dev->driver->acpi_match_table; +struct acpi_device *adev =ACPI_COMPANION (dev);const struct acpi_device_id *match;Quoted 10 lines
Quoted 6 lines
drivers/acpi/bus.c static const void *acpi_of_device_get_match_data(const struct device *dev) · line 1040
Quoted 6 lines
drivers/acpi/bus.c +4
-1-if (!acpi_ids) +if (!adev) +return NULL ; + +if (!strcmp (acpi_device_hid (adev),ACPI_DT_NAMESPACE_HID ))return acpi_of_device_get_match_data (dev);On top of what Mika asked, shouldn't we check CID as well? Theoretically it's possible that some device may have HID "blablabla" and CID PRP0001, I don't remember what documentation says about this case, though.
Quoted 3 lines
According to
Documentation/firmware-guide/acpi/enumeration.rstPRP0001 is also valid for_CID. So yes, I think this should be checked as well -- I'd loop over the&device->pnp.idslist.
Yeah, but if we have a device with
HID "blablabla"
CID "PRP0001"
and at the same time the driver has ACPI ID listed, we should probably use that one as HID should have higher weight for matching. Logic here is not just as simple as looping over pnp.ids how I see it.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Rafael J. Wysocki
maintainerQuoted 40 lines · Andy Shevchenko
Quoted 16 lines · Sakari Ailus
Quoted 15 lines · Andy Shevchenko
Quoted 14 lines · Mika Westerberg
Quoted 13 lines · Kartik Rajput
During pre-production development, drivers may provide both ACPI and OF match tables while a formal ACPI HID for the device is not yet allocated. Such devices are enumerated via PRP0001. In this case,
acpi_device_get_match_data()consults only the driver’s ACPI match table and returns NULL, even though the device was successfully matched via PRP0001.This behavior also risks breaking existing PRP0001 setups if a driver later gains an ACPI HID, as the presence of an ACPI match table changes the match-data lookup path.
Explicitly detect PRP0001 and fetch match data from the driver's OF match table via
acpi_of_device_get_match_data()....
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 10 lines
const struct acpi_device_id *acpi_ids = dev->driver->acpi_match_table;drivers/acpi/bus.c +5
-1+struct acpi_device *adev =ACPI_COMPANION (dev);const struct acpi_device_id *match; -if (!acpi_ids) +if (!adev) +return NULL ; + +if (!strcmp (acpi_device_hid (adev),ACPI_DT_NAMESPACE_HID ))return acpi_of_device_get_match_data (dev);Quoted 7 lines
Quoted 3 lines
On top of what Mika asked, shouldn't we check CID as well? Theoretically it's possible that some device may have HID "blablabla" and CID PRP0001, I don't remember what documentation says about this case, though.
According to
Documentation/firmware-guide/acpi/enumeration.rstPRP0001 is also valid for_CID. So yes, I think this should be checked as well -- I'd loop over the&device->pnp.idslist.
Quoted 8 lines
Yeah, but if we have a device with
HID "blablabla"
CID "PRP0001"and at the same time the driver has ACPI ID listed, we should probably use that one as HID should have higher weight for matching. Logic here is not just as simple as looping over pnp.ids how I see it.
Right.
What about:
if (acpi_ids) {
match = acpi_match_device(acpi_ids, dev);
if (match)
return (const void *)match->driver_data;
}return acpi_of_device_get_match_data(dev);
Hi Rafael, Andy,
Quoted 53 lines · Rafael J. Wysocki
Quoted 40 lines · Andy Shevchenko
Quoted 16 lines · Sakari Ailus
Quoted 15 lines · Andy Shevchenko
Quoted 14 lines · Mika Westerberg
Quoted 13 lines · Kartik Rajput
During pre-production development, drivers may provide both ACPI and OF match tables while a formal ACPI HID for the device is not yet allocated. Such devices are enumerated via PRP0001. In this case,
acpi_device_get_match_data()consults only the driver’s ACPI match table and returns NULL, even though the device was successfully matched via PRP0001.This behavior also risks breaking existing PRP0001 setups if a driver later gains an ACPI HID, as the presence of an ACPI match table changes the match-data lookup path.
Explicitly detect PRP0001 and fetch match data from the driver's OF match table via
acpi_of_device_get_match_data()....
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 10 lines
const struct acpi_device_id *acpi_ids = dev->driver->acpi_match_table;drivers/acpi/bus.c +5
-1+struct acpi_device *adev =ACPI_COMPANION (dev);const struct acpi_device_id *match; -if (!acpi_ids) +if (!adev) +return NULL ; + +if (!strcmp (acpi_device_hid (adev),ACPI_DT_NAMESPACE_HID ))return acpi_of_device_get_match_data (dev);Quoted 7 lines
Quoted 3 lines
On top of what Mika asked, shouldn't we check CID as well? Theoretically it's possible that some device may have HID "blablabla" and CID PRP0001, I don't remember what documentation says about this case, though.
According to
Documentation/firmware-guide/acpi/enumeration.rstPRP0001 is also valid for_CID. So yes, I think this should be checked as well -- I'd loop over the&device->pnp.idslist.Quoted 8 lines
Yeah, but if we have a device with
HID "blablabla"
CID "PRP0001"and at the same time the driver has ACPI ID listed, we should probably use that one as HID should have higher weight for matching. Logic here is not just as simple as looping over pnp.ids how I see it.
Right.
Quoted 8 lines
What about:
if (acpi_ids) { match = acpi_match_device(acpi_ids, dev); if (match) return (const void *)match->driver_data; }return
acpi_of_device_get_match_data(dev);
That would mean that any ACPI (or PNP) ID has priority over compatible matching, wouldn't it? AFAIU the documentation says effectively that _HID/_CID priority is upheld, whether matching with PRP0001 or without.
Signature · 3 lines
Regards, Sakari Ailus
Quoted 68 lines · Sakari Ailus
External email: Use caution opening links or attachments
Hi Rafael, Andy,
Quoted 53 lines · Rafael J. Wysocki
Quoted 40 lines · Andy Shevchenko
Quoted 16 lines · Sakari Ailus
Quoted 15 lines · Andy Shevchenko
Quoted 14 lines · Mika Westerberg
Quoted 13 lines · Kartik Rajput
During pre-production development, drivers may provide both ACPI and OF match tables while a formal ACPI HID for the device is not yet allocated. Such devices are enumerated via PRP0001. In this case,
acpi_device_get_match_data()consults only the driver’s ACPI match table and returns NULL, even though the device was successfully matched via PRP0001.This behavior also risks breaking existing PRP0001 setups if a driver later gains an ACPI HID, as the presence of an ACPI match table changes the match-data lookup path.
Explicitly detect PRP0001 and fetch match data from the driver's OF match table via
acpi_of_device_get_match_data()....
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 10 lines
const struct acpi_device_id *acpi_ids = dev->driver->acpi_match_table;(quoted diff) +5
-1+ struct acpi_device *adev = ACPI_COMPANION(dev); const struct acpi_device_id *match; - if (!acpi_ids) + if (!adev) + return NULL; + + if (!strcmp(acpi_device_hid(adev), ACPI_DT_NAMESPACE_HID)) return acpi_of_device_get_match_data(dev);Quoted 7 lines
Quoted 3 lines
On top of what Mika asked, shouldn't we check CID as well? Theoretically it's possible that some device may have HID "blablabla" and CID PRP0001, I don't remember what documentation says about this case, though.
According to
Documentation/firmware-guide/acpi/enumeration.rstPRP0001 is also valid for_CID. So yes, I think this should be checked as well -- I'd loop over the&device->pnp.idslist.Quoted 8 lines
Yeah, but if we have a device with
HID "blablabla"
CID "PRP0001"and at the same time the driver has ACPI ID listed, we should probably use that one as HID should have higher weight for matching. Logic here is not just as simple as looping over pnp.ids how I see it.
Right.
Quoted 8 lines
What about:
if (acpi_ids) { match = acpi_match_device(acpi_ids, dev); if (match) return (const void *)match->driver_data; }return
acpi_of_device_get_match_data(dev);
Quoted 8 lines
That would mean that any ACPI (or PNP) ID has priority over compatible matching, wouldn't it? AFAIU the documentation says effectively that _HID/_CID priority is upheld, whether matching with PRP0001 or without.
--
Regards,Sakari Ailus
Hi Rafael, Sakari, Andy,
Since we seem to be using __acpi_match_device() match the device. What if we directly utilise __acpi_match_device() here?
Something like:
if (!__acpi_match_device(adev, acpi_ids, of_ids, &acpi_id, &of_id)) return NULL; if (acpi_id) return (const void *)acpi_id->driver_data; if (of_id) return of_id->data; return NULL;
Then, we can also remove acpi_of_device_get_match_data()?
Thanks,
Kartik
Quoted 8 lines · Kartik Rajput
Quoted 7 lines · Sakari Ailus
Quoted 6 lines · Rafael J. Wysocki
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Sakari Ailus
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Mika Westerberg
On Fri, Jan 09, 2026 at 03:23:58PM +0530, Kartik Rajput wrote:
...
Quoted 48 lines
Quoted 28 lines
Quoted 19 lines
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
On top of what Mika asked, shouldn't we check CID as well? Theoretically it's possible that some device may have HID "blablabla" and CID PRP0001, I don't remember what documentation says about this case, though.
According to
Documentation/firmware-guide/acpi/enumeration.rstPRP0001 is also valid for_CID. So yes, I think this should be checked as well -- I'd loop over the&device->pnp.idslist.Quoted 8 lines
Yeah, but if we have a device with
HID "blablabla"
CID "PRP0001"and at the same time the driver has ACPI ID listed, we should probably use that one as HID should have higher weight for matching. Logic here is not just as simple as looping over pnp.ids how I see it.
Right.
Quoted 8 lines
What about:
if (acpi_ids) { match = acpi_match_device(acpi_ids, dev); if (match) return (const void *)match->driver_data; }return
acpi_of_device_get_match_data(dev);Quoted 3 lines
That would mean that any ACPI (or PNP) ID has priority over compatible matching, wouldn't it? AFAIU the documentation says effectively that _HID/_CID priority is upheld, whether matching with PRP0001 or without.
Since we seem to be using
__acpi_match_device()match the device. What if we directly utilise__acpi_match_device()here?Something like:
if (!__acpi_match_device(adev, acpi_ids, of_ids, &acpi_id, &of_id)) return NULL; if (acpi_id) return (const void *)acpi_id->driver_data; if (of_id) return of_id->data; return NULL;
Quoted 1 line
Then, we can also remove
acpi_of_device_get_match_data()?
At brief look it's indeed seems to be a good optimisation as well.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi Kartik, Andy,
Quoted 6 lines · Andy Shevchenko
Quoted 6 lines
if (!__acpi_match_device(adev, acpi_ids, of_ids, &acpi_id, &of_id)) return NULL; if (acpi_id) return (const void *)acpi_id->driver_data;
Quoted 8 lines
Quoted 6 lines
if (of_id) return of_id->data; return NULL;Then, we can also remove
acpi_of_device_get_match_data()?At brief look it's indeed seems to be a good optimisation as well.
Looks good to me, too!
Signature · 1 line
Sakari Ailus