Skip to contentSkip to conversation

ACPI / bus: Introduce a list of ids for "always present" devices

PATCH Superseded Hans de Goede 3 participants 8 messages Apr 18, 2017 – Apr 19, 2017

Subsystems (2)

v6 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

PATCH v6 1/3 ACPI / bus: Introduce a list of ids for "always present" devices

Several Cherry Trail devices (all of which ship with Windows 10) hide the LPSS PWM controller in ACPI, typically the _STA method looks like this:

    Method (_STA, 0, NotSerialized)  // _STA: Status
    {
        If (OSID == One)
        {
            Return (Zero)
        }

        Return (0x0F)
    }

Where OSID is some dark magic seen in all Cherry Trail ACPI tables making the machine behave differently depending on which OS it *thinks* it is booting, this gets set in a number of ways which we cannot control, on some newer machines it simple hardcoded to "One" aka win10.

This causes the PWM controller to get hidden, which means Linux cannot control the backlight level on cht based tablets / laptops.

Since loading the driver for this does no harm (the only in kernel user of it is the i915 driver, which will only use it when it needs it), this commit makes acpi_bus_get_status() always set status to ACPI_STA_DEFAULT for the 80862288 device, fixing the lack of backlight control.

---
Changes in v2:
-Use pr_debug instead of ACPI_DEBUG_PRINT
Changes in v3:
-Un-inline acpi_set_device_status and do the always_present_device_ids
table check inside the un-inlined version of it
Changes in v4:
-Use dev_info instead of pr_debug
-Not only check for ACPI HID but also for CPU (SoC) model so as to not
for devices present on other models then for which the quirk is intended and to avoid enabling unrelated ACPI devices which happen to use the same HID
Changes in v5:
-Only do the dev_info once per device (acpi_set_device_status gets called
multiple times per device during boot)
Changes in v6:
-Allow specifying more then one CPU-model for a single HID
-Not only match the HID but also the UID, like on Cherry Trail, on some Bay
Trail Windows 10 tablets we need to enable the PWM controller to get working backlight even though _STA returns 0. The Bay Trail SoC has 2 PWM controllers and we only need the first one. UID matching will allows adding an entry for Bay Trail which only enables the first PWM controller

---
 drivers/acpi/bus.c      | 65 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/acpi/acpi_bus.h |  6 +----
 2 files changed, 66 insertions(+), 5 deletions(-)
drivers/acpi/bus.c +65 -0
index 34fbe02..eb30630 100644
@@ -34,6 +34,8 @@
 #include <linux/reboot.h>
 #include <linux/delay.h>
 #ifdef CONFIG_X86
+#include <asm/cpu_device_id.h>
+#include <asm/intel-family.h>
 #include <asm/mpspec.h>
 #endif
 #include <linux/acpi_iort.h>
@@ -132,6 +134,69 @@ int acpi_bus_get_status(struct acpi_device *device)
 }
 EXPORT_SYMBOL(acpi_bus_get_status);
 
+#ifdef CONFIG_X86
+/*
+ * Some ACPI devices are hidden (status == 0x0) in recent BIOS-es because
+ * some recent Windows drivers bind to one device but poke at multiple
+ * devices at the same time, so the others get hidden.
+ * We work around this by always reporting ACPI_STA_DEFAULT for these
+ * devices. Note this MUST only be done for devices where this is safe.
+ *
+ * This forcing of devices to be present is limited to specific CPU (SoC)
+ * models both to avoid potentially causing trouble on other models and
+ * because some HIDs are re-used on different SoCs for completely
+ * different devices.
+ */
+struct always_present_device_id {
+	struct acpi_device_id hid[2];
+	struct x86_cpu_id cpu_ids[2];
+	const char *uid;
+};
+
+#define ICPU(model)	{ X86_VENDOR_INTEL, 6, model, X86_FEATURE_ANY, }
+
+#define ENTRY(hid, uid, cpu_models) {					\
+	{ { hid, }, {} },						\
+	{ cpu_models, {} },						\
+	uid,								\
+}
+
+static const struct always_present_device_id always_present_device_ids[] = {
+	/*
+	 * Cherry Trail PWM directly poked by GPU driver in win10,
+	 * but Linux uses a separate PWM driver, harmless if not used.
+	 */
+	ENTRY("80862288", "1", ICPU(INTEL_FAM6_ATOM_AIRMONT)),
+};
+#endif
+
+void acpi_set_device_status(struct acpi_device *adev, u32 sta)
+{
+	u32 *status = (u32 *)&adev->status;
+#ifdef CONFIG_X86
+	u32 old_status = *status;
+	int i;
+
+	/* acpi_match_device_ids checks status, so start with default */
+	*status = ACPI_STA_DEFAULT;
+	for (i = 0; i < ARRAY_SIZE(always_present_device_ids); i++) {
+		if (acpi_match_device_ids(adev,
+			always_present_device_ids[i].hid) == 0 &&
+		    adev->pnp.unique_id &&
+		    strcmp(adev->pnp.unique_id,
+			   always_present_device_ids[i].uid) == 0 &&
+		    x86_match_cpu(always_present_device_ids[i].cpu_ids)) {
+			if (old_status != ACPI_STA_DEFAULT)
+				dev_info(&adev->dev,
+					 "Device [%s] is in always present list setting status [%08x]\n",
+					 adev->pnp.bus_id, ACPI_STA_DEFAULT);
+			return;
+		}
+	}
+#endif
+	*status = sta;
+}
+
 void acpi_bus_private_data_handler(acpi_handle handle,
 				   void *context)
 {
include/acpi/acpi_bus.h +1 -5
index b53c058..ef0794a 100644
@@ -441,11 +441,6 @@ static inline void *acpi_driver_data(struct acpi_device *d)
 #define to_acpi_device(d)	container_of(d, struct acpi_device, dev)
 #define to_acpi_driver(d)	container_of(d, struct acpi_driver, drv)
 
-static inline void acpi_set_device_status(struct acpi_device *adev, u32 sta)
-{
-	*((u32 *)&adev->status) = sta;
-}
-
 static inline void acpi_set_hp_context(struct acpi_device *adev,
 				       struct acpi_hotplug_context *hp)
 {
@@ -494,6 +489,7 @@ void acpi_bus_put_acpi_device(struct acpi_device *adev);
 acpi_status acpi_bus_get_status_handle(acpi_handle handle,
 				       unsigned long long *sta);
 int acpi_bus_get_status(struct acpi_device *device);
+void acpi_set_device_status(struct acpi_device *adev, u32 sta);
 
 int acpi_bus_set_power(acpi_handle handle, int state);
 const char *acpi_power_state_string(int state);
Signature · 1 line
2.9.3
#1 lore raw

PATCH v6 2/3 ACPI / bus: Add INT0002 to list of always-present devices

The INT0002 device is necessary to clear wakeup interrupt sources on Cherry Trail devices, without it we get nobody cared IRQ msgs and some systems don't properly resume at all without it.

---
Changes in v6:
-This is a new patch in v6 of this patch-set

---
 drivers/acpi/bus.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/acpi/bus.c +5 -0
index eb30630..6fa177c 100644
@@ -167,6 +167,11 @@ static const struct always_present_device_id always_present_device_ids[] = {
 	 * but Linux uses a separate PWM driver, harmless if not used.
 	 */
 	ENTRY("80862288", "1", ICPU(INTEL_FAM6_ATOM_AIRMONT)),
+	/*
+	 * The INT0002 device is necessary to clear wakeup interrupt sources
+	 * on Cherry Trail devices, without it we get nobody cared IRQ msgs.
+	 */
+	ENTRY("INT0002", "1", ICPU(INTEL_FAM6_ATOM_AIRMONT)),
 };
 #endif
 
Signature · 1 line
2.9.3
#2 lore raw

PATCH v6 3/3 ACPI / bus: Add Bay Trail PWM controller to list of always-present devices

In reply to Hans de Goede

Just like on Cherry Trail, on some Bay Trail Windows 10 tablets we need to enable the PWM controller to get working backlight even though _STA returns 0.

Add an entry for the the Bay Trail PWM controller to list of always-present devices to fix backlight control not working on some Bay Trail devices.

---
Changes in v6:
-This is a new patch in v6 of this patch-set

---
 drivers/acpi/bus.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/acpi/bus.c +2 -1
index 6fa177c..5f9fe3f 100644
@@ -163,9 +163,10 @@ struct always_present_device_id {
 
 static const struct always_present_device_id always_present_device_ids[] = {
 	/*
-	 * Cherry Trail PWM directly poked by GPU driver in win10,
+	 * Bay / Cherry Trail PWM directly poked by GPU driver in win10,
 	 * but Linux uses a separate PWM driver, harmless if not used.
 	 */
+	ENTRY("80860F09", "1", ICPU(INTEL_FAM6_ATOM_SILVERMONT1)),
 	ENTRY("80862288", "1", ICPU(INTEL_FAM6_ATOM_AIRMONT)),
 	/*
 	 * The INT0002 device is necessary to clear wakeup interrupt sources
Signature · 1 line
2.9.3
#3 lore raw
In reply to Hans de Goede
Quoted 76 lines · Hans de Goede

Several Cherry Trail devices (all of which ship with Windows 10) hide the LPSS PWM controller in ACPI, typically the _STA method looks like this:

    Method (_STA, 0, NotSerialized)  // _STA: Status
    {
        If (OSID == One)
        {
            Return (Zero)
        }

        Return (0x0F)
    }

Where OSID is some dark magic seen in all Cherry Trail ACPI tables making the machine behave differently depending on which OS it *thinks* it is booting, this gets set in a number of ways which we cannot control, on some newer machines it simple hardcoded to "One" aka win10.

This causes the PWM controller to get hidden, which means Linux cannot control the backlight level on cht based tablets / laptops.

Since loading the driver for this does no harm (the only in kernel user of it is the i915 driver, which will only use it when it needs it), this commit makes acpi_bus_get_status() always set status to ACPI_STA_DEFAULT for the 80862288 device, fixing the lack of backlight control.

---
Changes in v2:
-Use pr_debug instead of ACPI_DEBUG_PRINT
Changes in v3:
-Un-inline acpi_set_device_status and do the always_present_device_ids
table check inside the un-inlined version of it
Changes in v4:

(quoted diff) +0 -2
-Use dev_info instead of pr_debug
-Not only check for ACPI HID but also for CPU (SoC) model so as to not
 for devices present on other models then for which the quirk is intended and
 to avoid enabling unrelated ACPI devices which happen to use the same HID

Changes in v5:
-Only do the dev_info once per device (acpi_set_device_status gets called
multiple times per device during boot)
Changes in v6:

(quoted diff) +0 -3
-Allow specifying more then one CPU-model for a single HID
-Not only match the HID but also the UID, like on Cherry Trail, on some Bay
 Trail Windows 10 tablets we need to enable the PWM controller to get working
 backlight even though _STA returns 0. The Bay Trail SoC has 2 PWM controllers
 and we only need the first one. UID matching will allows adding an entry for
 Bay Trail which only enables the first PWM controller
---
 drivers/acpi/bus.c      | 65 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/acpi/acpi_bus.h |  6 +----
 2 files changed, 66 insertions(+), 5 deletions(-)
drivers/acpi/bus.c +8 -0
index 34fbe02..eb30630 100644
@@ -34,6 +34,8 @@
 #include <linux/reboot.h>
 #include <linux/delay.h>
 #ifdef CONFIG_X86
+#include <asm/cpu_device_id.h>
+#include <asm/intel-family.h>
 #include <asm/mpspec.h>
 #endif
 #include <linux/acpi_iort.h>
@@ -132,6 +134,69 @@ int acpi_bus_get_status(struct acpi_device *device)
 }
 EXPORT_SYMBOL(acpi_bus_get_status);
 
+#ifdef CONFIG_X86
+/*
+ * Some ACPI devices are hidden (status == 0x0) in recent BIOS-es because
+ * some recent Windows drivers bind to one device but poke at multiple
+ * devices at the same time, so the others get hidden.
+ * We work around this by always reporting ACPI_STA_DEFAULT for these

drivers/acpi/bus.c int acpi_bus_get_status(struct acpi_device *device) · line 152

Quoted 10 lines
drivers/acpi/bus.c +10 -0
+ * devices. Note this MUST only be done for devices where this is safe.
+ *
+ * This forcing of devices to be present is limited to specific CPU (SoC)
+ * models both to avoid potentially causing trouble on other models and
+ * because some HIDs are re-used on different SoCs for completely
+ * different devices.
+ */
+struct always_present_device_id {
+       struct acpi_device_id hid[2];
+       struct x86_cpu_id cpu_ids[2];

This really is x86-specific, so it should go into somewhere like arch/x86/kernel/acpi/ or drivers/acpi/x86/ (not present yet).

Quoted 26 lines
drivers/acpi/bus.c +26 -0
+       const char *uid;
+};
+
+#define ICPU(model)    { X86_VENDOR_INTEL, 6, model, X86_FEATURE_ANY, }
+
+#define ENTRY(hid, uid, cpu_models) {                                  \
+       { { hid, }, {} },                                               \
+       { cpu_models, {} },                                             \
+       uid,                                                            \
+}
+
+static const struct always_present_device_id always_present_device_ids[] = {
+       /*
+        * Cherry Trail PWM directly poked by GPU driver in win10,
+        * but Linux uses a separate PWM driver, harmless if not used.
+        */
+       ENTRY("80862288", "1", ICPU(INTEL_FAM6_ATOM_AIRMONT)),
+};
+#endif
+
+void acpi_set_device_status(struct acpi_device *adev, u32 sta)
+{
+       u32 *status = (u32 *)&adev->status;
+#ifdef CONFIG_X86
+       u32 old_status = *status;
+       int i;

drivers/acpi/bus.c int acpi_bus_get_status(struct acpi_device *device) · line 188

Quoted 10 lines
drivers/acpi/bus.c +10 -0
+
+       /* acpi_match_device_ids checks status, so start with default */
+       *status = ACPI_STA_DEFAULT;
+       for (i = 0; i < ARRAY_SIZE(always_present_device_ids); i++) {
+               if (acpi_match_device_ids(adev,
+                       always_present_device_ids[i].hid) == 0 &&
+                   adev->pnp.unique_id &&
+                   strcmp(adev->pnp.unique_id,
+                          always_present_device_ids[i].uid) == 0 &&
+                   x86_match_cpu(always_present_device_ids[i].cpu_ids)) {

Split this condition please. It is almost unreadable as is.

Quoted 4 lines
drivers/acpi/bus.c +4 -0
+                       if (old_status != ACPI_STA_DEFAULT)
+                               dev_info(&adev->dev,
+                                        "Device [%s] is in always present list setting status [%08x]\n",
+                                        adev->pnp.bus_id, ACPI_STA_DEFAULT);

drivers/acpi/bus.c int acpi_bus_get_status(struct acpi_device *device) · line 202

Quoted 10 lines
drivers/acpi/bus.c +7 -0
+                       return;
+               }
+       }
+#endif
+       *status = sta;
+}
+
 void acpi_bus_private_data_handler(acpi_handle handle,
                                   void *context)
 {

Thanks,
Rafael
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#4 lore raw

Hi,

Quoted 82 lines · Rafael J. Wysocki
Quoted 81 lines · Hans de Goede

Several Cherry Trail devices (all of which ship with Windows 10) hide the LPSS PWM controller in ACPI, typically the _STA method looks like this:

    Method (_STA, 0, NotSerialized)  // _STA: Status
    {
        If (OSID == One)
        {
            Return (Zero)
        }

        Return (0x0F)
    }

Where OSID is some dark magic seen in all Cherry Trail ACPI tables making the machine behave differently depending on which OS it *thinks* it is booting, this gets set in a number of ways which we cannot control, on some newer machines it simple hardcoded to "One" aka win10.

This causes the PWM controller to get hidden, which means Linux cannot control the backlight level on cht based tablets / laptops.

Since loading the driver for this does no harm (the only in kernel user of it is the i915 driver, which will only use it when it needs it), this commit makes acpi_bus_get_status() always set status to ACPI_STA_DEFAULT for the 80862288 device, fixing the lack of backlight control.

---
Changes in v2:
-Use pr_debug instead of ACPI_DEBUG_PRINT
Changes in v3:
-Un-inline acpi_set_device_status and do the always_present_device_ids
table check inside the un-inlined version of it
Changes in v4:

(quoted diff) +0 -2
-Use dev_info instead of pr_debug
-Not only check for ACPI HID but also for CPU (SoC) model so as to not
 for devices present on other models then for which the quirk is intended and
 to avoid enabling unrelated ACPI devices which happen to use the same HID

Changes in v5:
-Only do the dev_info once per device (acpi_set_device_status gets called
multiple times per device during boot)
Changes in v6:

(quoted diff) +0 -3
-Allow specifying more then one CPU-model for a single HID
-Not only match the HID but also the UID, like on Cherry Trail, on some Bay
 Trail Windows 10 tablets we need to enable the PWM controller to get working
 backlight even though _STA returns 0. The Bay Trail SoC has 2 PWM controllers
 and we only need the first one. UID matching will allows adding an entry for
 Bay Trail which only enables the first PWM controller
---
 drivers/acpi/bus.c      | 65 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/acpi/acpi_bus.h |  6 +----
 2 files changed, 66 insertions(+), 5 deletions(-)
drivers/acpi/bus.c +13 -0
index 34fbe02..eb30630 100644
@@ -34,6 +34,8 @@
 #include <linux/reboot.h>
 #include <linux/delay.h>
 #ifdef CONFIG_X86
+#include <asm/cpu_device_id.h>
+#include <asm/intel-family.h>
 #include <asm/mpspec.h>
 #endif
 #include <linux/acpi_iort.h>
@@ -132,6 +134,69 @@ int acpi_bus_get_status(struct acpi_device *device)
 }
 EXPORT_SYMBOL(acpi_bus_get_status);
 
+#ifdef CONFIG_X86
+/*
+ * Some ACPI devices are hidden (status == 0x0) in recent BIOS-es because
+ * some recent Windows drivers bind to one device but poke at multiple
+ * devices at the same time, so the others get hidden.
+ * We work around this by always reporting ACPI_STA_DEFAULT for these
+ * devices. Note this MUST only be done for devices where this is safe.
+ *
+ * This forcing of devices to be present is limited to specific CPU (SoC)
+ * models both to avoid potentially causing trouble on other models and
+ * because some HIDs are re-used on different SoCs for completely
Quoted 8 lines

drivers/acpi/bus.c int acpi_bus_get_status(struct acpi_device *device) · line 152

Quoted 5 lines
drivers/acpi/bus.c +5 -0
+ * different devices.
+ */
+struct always_present_device_id {
+       struct acpi_device_id hid[2];
+       struct x86_cpu_id cpu_ids[2];

This really is x86-specific, so it should go into somewhere like arch/x86/kernel/acpi/ or drivers/acpi/x86/ (not present yet).

Ok, but then how do you want to hook this up, before you said that you wanted to deal with this in acpi_set_device_status(), which belongs in drivers/acpi/bus.c, do you want the x86 code to provide something like a

bool acpi_device_always_present(struct acpi_device *adev) { }

Helper function and use that in the drivers/acpi/bus.c acpi_set_device_status() implementation ?

Quoted 31 lines
Quoted 31 lines
drivers/acpi/bus.c +30 -0
+       const char *uid;
+};
+
+#define ICPU(model)    { X86_VENDOR_INTEL, 6, model, X86_FEATURE_ANY, }
+
+#define ENTRY(hid, uid, cpu_models) {                                  \
+       { { hid, }, {} },                                               \
+       { cpu_models, {} },                                             \
+       uid,                                                            \
+}
+
+static const struct always_present_device_id always_present_device_ids[] = {
+       /*
+        * Cherry Trail PWM directly poked by GPU driver in win10,
+        * but Linux uses a separate PWM driver, harmless if not used.
+        */
+       ENTRY("80862288", "1", ICPU(INTEL_FAM6_ATOM_AIRMONT)),
+};
+#endif
+
+void acpi_set_device_status(struct acpi_device *adev, u32 sta)
+{
+       u32 *status = (u32 *)&adev->status;
+#ifdef CONFIG_X86
+       u32 old_status = *status;
+       int i;
+
+       /* acpi_match_device_ids checks status, so start with default */
+       *status = ACPI_STA_DEFAULT;
+       for (i = 0; i < ARRAY_SIZE(always_present_device_ids); i++) {
Quoted 8 lines

drivers/acpi/bus.c int acpi_bus_get_status(struct acpi_device *device) · line 188

Quoted 6 lines
drivers/acpi/bus.c +6 -0
+               if (acpi_match_device_ids(adev,
+                       always_present_device_ids[i].hid) == 0 &&
+                   adev->pnp.unique_id &&
+                   strcmp(adev->pnp.unique_id,
+                          always_present_device_ids[i].uid) == 0 &&
+                   x86_match_cpu(always_present_device_ids[i].cpu_ids)) {

Split this condition please. It is almost unreadable as is.

Not sure what you want me to do here ? Use multiple if's with "continue" if the check fails, or add whitespace (empty lines) between the conditions, or ... ?

Quoted 10 lines
Quoted 10 lines
drivers/acpi/bus.c +9 -0
+                       if (old_status != ACPI_STA_DEFAULT)
+                               dev_info(&adev->dev,
+                                        "Device [%s] is in always present list setting status [%08x]\n",
+                                        adev->pnp.bus_id, ACPI_STA_DEFAULT);
+                       return;
+               }
+       }
+#endif
+       *status = sta;
Quoted 9 lines

drivers/acpi/bus.c int acpi_bus_get_status(struct acpi_device *device) · line 202

Quoted 5 lines
drivers/acpi/bus.c +2 -0
+}
+
 void acpi_bus_private_data_handler(acpi_handle handle,
                                   void *context)
 {

Thanks,
Rafael

Regards,

Hans

#5 lore raw
Quoted 114 lines · Hans de Goede

Hi,

Quoted 95 lines · Rafael J. Wysocki
Quoted 92 lines · Hans de Goede

Several Cherry Trail devices (all of which ship with Windows 10) hide the LPSS PWM controller in ACPI, typically the _STA method looks like this:

    Method (_STA, 0, NotSerialized)  // _STA: Status
    {
        If (OSID == One)
        {
            Return (Zero)
        }

        Return (0x0F)
    }

Where OSID is some dark magic seen in all Cherry Trail ACPI tables making the machine behave differently depending on which OS it *thinks* it is booting, this gets set in a number of ways which we cannot control, on some newer machines it simple hardcoded to "One" aka win10.

This causes the PWM controller to get hidden, which means Linux cannot control the backlight level on cht based tablets / laptops.

Since loading the driver for this does no harm (the only in kernel user of it is the i915 driver, which will only use it when it needs it), this commit makes acpi_bus_get_status() always set status to ACPI_STA_DEFAULT for the 80862288 device, fixing the lack of backlight control.

---
Changes in v2:
-Use pr_debug instead of ACPI_DEBUG_PRINT
Changes in v3:
-Un-inline acpi_set_device_status and do the always_present_device_ids
table check inside the un-inlined version of it
Changes in v4:

(quoted diff) +0 -2
-Use dev_info instead of pr_debug
-Not only check for ACPI HID but also for CPU (SoC) model so as to not
 for devices present on other models then for which the quirk is intended

and
to avoid enabling unrelated ACPI devices which happen to use the same
HID
Changes in v5:
-Only do the dev_info once per device (acpi_set_device_status gets called
multiple times per device during boot)
Changes in v6:

(quoted diff) +0 -2
-Allow specifying more then one CPU-model for a single HID
-Not only match the HID but also the UID, like on Cherry Trail, on some

Bay
Trail Windows 10 tablets we need to enable the PWM controller to get
working
backlight even though _STA returns 0. The Bay Trail SoC has 2 PWM
controllers
and we only need the first one. UID matching will allows adding an entry
for
Bay Trail which only enables the first PWM controller

---
 drivers/acpi/bus.c      | 65
+++++++++++++++++++++++++++++++++++++++++++++++++
 include/acpi/acpi_bus.h |  6 +----
 2 files changed, 66 insertions(+), 5 deletions(-)
drivers/acpi/bus.c +5 -0
index 34fbe02..eb30630 100644
@@ -34,6 +34,8 @@
 #include <linux/reboot.h>
 #include <linux/delay.h>
 #ifdef CONFIG_X86
+#include <asm/cpu_device_id.h>
+#include <asm/intel-family.h>
 #include <asm/mpspec.h>
 #endif
 #include <linux/acpi_iort.h>
@@ -132,6 +134,69 @@ int acpi_bus_get_status(struct acpi_device *device)
 }
 EXPORT_SYMBOL(acpi_bus_get_status);
 
+#ifdef CONFIG_X86
+/*
+ * Some ACPI devices are hidden (status == 0x0) in recent BIOS-es

because
+ * some recent Windows drivers bind to one device but poke at multiple
+ * devices at the same time, so the others get hidden.
+ * We work around this by always reporting ACPI_STA_DEFAULT for these
+ * devices. Note this MUST only be done for devices where this is safe.
+ *
+ * This forcing of devices to be present is limited to specific CPU (SoC)
+ * models both to avoid potentially causing trouble on other models and
+ * because some HIDs are re-used on different SoCs for completely
+ * different devices.

Quoted 8 lines

drivers/acpi/bus.c int acpi_bus_get_status(struct acpi_device *device) · line 152

Quoted 4 lines

+ */

drivers/acpi/bus.c +3 -0
+struct always_present_device_id {
+       struct acpi_device_id hid[2];
+       struct x86_cpu_id cpu_ids[2];

This really is x86-specific, so it should go into somewhere like arch/x86/kernel/acpi/ or drivers/acpi/x86/ (not present yet).

Ok, but then how do you want to hook this up, before you said that you wanted to deal with this in acpi_set_device_status(), which belongs in drivers/acpi/bus.c, do you want the x86 code to provide something like a

Quoted 5 lines

bool acpi_device_always_present(struct acpi_device *adev) { }

Helper function and use that in the drivers/acpi/bus.c acpi_set_device_status() implementation ?

Yes, something like that.

In a header file you can make it depend on CONFIG_X86 and provide and empty static inline stub for the "not defined" case.

Quoted 44 lines
Quoted 34 lines
Quoted 34 lines
drivers/acpi/bus.c +12 -0
+       const char *uid;
+};
+
+#define ICPU(model)    { X86_VENDOR_INTEL, 6, model, X86_FEATURE_ANY, }
+
+#define ENTRY(hid, uid, cpu_models) {                                  \
+       { { hid, }, {} },                                               \
+       { cpu_models, {} },                                             \
+       uid,                                                            \
+}
+
+static const struct always_present_device_id always_present_device_ids[]

= {

drivers/acpi/bus.c +20 -0
+       /*
+        * Cherry Trail PWM directly poked by GPU driver in win10,
+        * but Linux uses a separate PWM driver, harmless if not used.
+        */
+       ENTRY("80862288", "1", ICPU(INTEL_FAM6_ATOM_AIRMONT)),
+};
+#endif
+
+void acpi_set_device_status(struct acpi_device *adev, u32 sta)
+{
+       u32 *status = (u32 *)&adev->status;
+#ifdef CONFIG_X86
+       u32 old_status = *status;
+       int i;
+
+       /* acpi_match_device_ids checks status, so start with default */
+       *status = ACPI_STA_DEFAULT;
+       for (i = 0; i < ARRAY_SIZE(always_present_device_ids); i++) {
+               if (acpi_match_device_ids(adev,
+                       always_present_device_ids[i].hid) == 0 &&
Quoted 8 lines
Quoted 5 lines
drivers/acpi/bus.c +4 -0
+                   adev->pnp.unique_id &&
+                   strcmp(adev->pnp.unique_id,
+                          always_present_device_ids[i].uid) == 0 &&
+                   x86_match_cpu(always_present_device_ids[i].cpu_ids))

{

Split this condition please. It is almost unreadable as is.

Quoted 3 lines

Not sure what you want me to do here ? Use multiple if's with "continue" if the check fails, or add whitespace (empty lines) between the conditions, or ... ?

I would do the multiple if()s variant.

The compiler should coalesce them anyway if it is smart enough.

Thanks,
Rafael

#6 lore raw
Quoted 84 lines · Rafael J. Wysocki
Quoted 83 lines · Hans de Goede
Quoted 65 lines · Rafael J. Wysocki
Quoted 64 lines · Hans de Goede

Several Cherry Trail devices (all of which ship with Windows 10) hide the LPSS PWM controller in ACPI, typically the _STA method looks like this:

    Method (_STA, 0, NotSerialized)  // _STA: Status
    {
        If (OSID == One)
        {
            Return (Zero)
        }

        Return (0x0F)
    }

Where OSID is some dark magic seen in all Cherry Trail ACPI tables making the machine behave differently depending on which OS it *thinks* it is booting, this gets set in a number of ways which we cannot control, on some newer machines it simple hardcoded to "One" aka win10.

This causes the PWM controller to get hidden, which means Linux cannot control the backlight level on cht based tablets / laptops.

Since loading the driver for this does no harm (the only in kernel user of it is the i915 driver, which will only use it when it needs it), this commit makes acpi_bus_get_status() always set status to ACPI_STA_DEFAULT for the 80862288 device, fixing the lack of backlight control.

---
 drivers/acpi/bus.c      | 65
+++++++++++++++++++++++++++++++++++++++++++++++++
 include/acpi/acpi_bus.h |  6 +----
 2 files changed, 66 insertions(+), 5 deletions(-)
drivers/acpi/bus.c +5 -0
index 34fbe02..eb30630 100644
@@ -34,6 +34,8 @@
 #include <linux/reboot.h>
 #include <linux/delay.h>
 #ifdef CONFIG_X86
+#include <asm/cpu_device_id.h>
+#include <asm/intel-family.h>
 #include <asm/mpspec.h>
 #endif
 #include <linux/acpi_iort.h>
@@ -132,6 +134,69 @@ int acpi_bus_get_status(struct acpi_device *device)
 }
 EXPORT_SYMBOL(acpi_bus_get_status);
 
+#ifdef CONFIG_X86
+/*
+ * Some ACPI devices are hidden (status == 0x0) in recent BIOS-es

because
+ * some recent Windows drivers bind to one device but poke at multiple
+ * devices at the same time, so the others get hidden.
+ * We work around this by always reporting ACPI_STA_DEFAULT for these
+ * devices. Note this MUST only be done for devices where this is safe.
+ *
+ * This forcing of devices to be present is limited to specific CPU (SoC)
+ * models both to avoid potentially causing trouble on other models and
+ * because some HIDs are re-used on different SoCs for completely

Quoted 8 lines

drivers/acpi/bus.c int acpi_bus_get_status(struct acpi_device *device) · line 152

Quoted 5 lines

+ * different devices.
+ */

drivers/acpi/bus.c +3 -0
+struct always_present_device_id {
+       struct acpi_device_id hid[2];
+       struct x86_cpu_id cpu_ids[2];

This really is x86-specific, so it should go into somewhere like arch/x86/kernel/acpi/ or drivers/acpi/x86/ (not present yet).

Ok, but then how do you want to hook this up, before you said that you wanted to deal with this in acpi_set_device_status(), which belongs in drivers/acpi/bus.c, do you want the x86 code to provide something like a

bool acpi_device_always_present(struct acpi_device *adev) { }

Quoted 7 lines
Quoted 2 lines

Helper function and use that in the drivers/acpi/bus.c acpi_set_device_status() implementation ?

Yes, something like that.

In a header file you can make it depend on CONFIG_X86 and provide and empty static inline stub for the "not defined" case.

The PCI subsystem uses __weak stubs such as pcibios_add_bus() for arch- specific behaviour, or quirks which can be declared in arch/x86 to constrain them to this specific platform.

Perhaps it makes sense to introduce ACPI quirks which can be declared the same way as PCI quirks to avoid cluttering the generic code with arch- or device-specific special cases. So in this case we'd have something like:

DECLARE_ACPI_FIXUP_STATUS(const char *hid, const char *uid, hook);

And before calling _STA we'd check for presence of a fixup for the device in question. Any additional stuff such as _HRV, CPU ID, DMI data could be checked in the fixup hook. Thoughts?

By the way:

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/acpi/bus.c +9 -0
+void acpi_set_device_status(struct acpi_device *adev, u32 sta)
+{
+       u32 *status = (u32 *)&adev->status;
+#ifdef CONFIG_X86
+       u32 old_status = *status;
+       int i;
+
+       /* acpi_match_device_ids checks status, so start with default */
+       *status = ACPI_STA_DEFAULT;
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/acpi/bus.c +7 -0
+       for (i = 0; i < ARRAY_SIZE(always_present_device_ids); i++) {
+               if (acpi_match_device_ids(adev,
+                       always_present_device_ids[i].hid) == 0 &&
+                   adev->pnp.unique_id &&
+                   strcmp(adev->pnp.unique_id,
+                          always_present_device_ids[i].uid) == 0 &&
+                   x86_match_cpu(always_present_device_ids[i].cpu_ids))

{

Why is this added to acpi_set_device_status(), rather than acpi_bus_get_status_handle() ? That way you're gratuitously calling _STA even though you ignore its return value afterwards.

Thanks,

Lukas

#7 lore raw
Quoted 102 lines · Lukas Wunner
Quoted 84 lines · Rafael J. Wysocki
Quoted 83 lines · Hans de Goede
Quoted 65 lines · Rafael J. Wysocki
Quoted 64 lines · Hans de Goede

Several Cherry Trail devices (all of which ship with Windows 10) hide the LPSS PWM controller in ACPI, typically the _STA method looks like this:

    Method (_STA, 0, NotSerialized)  // _STA: Status
    {
        If (OSID == One)
        {
            Return (Zero)
        }

        Return (0x0F)
    }

Where OSID is some dark magic seen in all Cherry Trail ACPI tables making the machine behave differently depending on which OS it *thinks* it is booting, this gets set in a number of ways which we cannot control, on some newer machines it simple hardcoded to "One" aka win10.

This causes the PWM controller to get hidden, which means Linux cannot control the backlight level on cht based tablets / laptops.

Since loading the driver for this does no harm (the only in kernel user of it is the i915 driver, which will only use it when it needs it), this commit makes acpi_bus_get_status() always set status to ACPI_STA_DEFAULT for the 80862288 device, fixing the lack of backlight control.

---
 drivers/acpi/bus.c      | 65
+++++++++++++++++++++++++++++++++++++++++++++++++
 include/acpi/acpi_bus.h |  6 +----
 2 files changed, 66 insertions(+), 5 deletions(-)
drivers/acpi/bus.c +5 -0
index 34fbe02..eb30630 100644
@@ -34,6 +34,8 @@
 #include <linux/reboot.h>
 #include <linux/delay.h>
 #ifdef CONFIG_X86
+#include <asm/cpu_device_id.h>
+#include <asm/intel-family.h>
 #include <asm/mpspec.h>
 #endif
 #include <linux/acpi_iort.h>
@@ -132,6 +134,69 @@ int acpi_bus_get_status(struct acpi_device *device)
 }
 EXPORT_SYMBOL(acpi_bus_get_status);
 
+#ifdef CONFIG_X86
+/*
+ * Some ACPI devices are hidden (status == 0x0) in recent BIOS-es

because
+ * some recent Windows drivers bind to one device but poke at multiple
+ * devices at the same time, so the others get hidden.
+ * We work around this by always reporting ACPI_STA_DEFAULT for these
+ * devices. Note this MUST only be done for devices where this is safe.
+ *
+ * This forcing of devices to be present is limited to specific CPU (SoC)
+ * models both to avoid potentially causing trouble on other models and
+ * because some HIDs are re-used on different SoCs for completely

Quoted 8 lines

drivers/acpi/bus.c int acpi_bus_get_status(struct acpi_device *device) · line 152

Quoted 5 lines

+ * different devices.
+ */

drivers/acpi/bus.c +3 -0
+struct always_present_device_id {
+       struct acpi_device_id hid[2];
+       struct x86_cpu_id cpu_ids[2];

This really is x86-specific, so it should go into somewhere like arch/x86/kernel/acpi/ or drivers/acpi/x86/ (not present yet).

Ok, but then how do you want to hook this up, before you said that you wanted to deal with this in acpi_set_device_status(), which belongs in drivers/acpi/bus.c, do you want the x86 code to provide something like a

bool acpi_device_always_present(struct acpi_device *adev) { }

Quoted 7 lines
Quoted 2 lines

Helper function and use that in the drivers/acpi/bus.c acpi_set_device_status() implementation ?

Yes, something like that.

In a header file you can make it depend on CONFIG_X86 and provide and empty static inline stub for the "not defined" case.

The PCI subsystem uses __weak stubs such as pcibios_add_bus() for arch- specific behaviour, or quirks which can be declared in arch/x86 to constrain them to this specific platform.

Perhaps it makes sense to introduce ACPI quirks which can be declared the same way as PCI quirks to avoid cluttering the generic code with arch- or device-specific special cases. So in this case we'd have something like:

Quoted 5 lines

DECLARE_ACPI_FIXUP_STATUS(const char *hid, const char *uid, hook);

And before calling _STA we'd check for presence of a fixup for the device in question. Any additional stuff such as _HRV, CPU ID, DMI data could be checked in the fixup hook. Thoughts?

Why don't we do that later if need be?

BTW, I'm not a big fan of __weak declarations as they result in dead code being added to binaries.

Quoted 15 lines

By the way:

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
drivers/acpi/bus.c +13 -0
+void acpi_set_device_status(struct acpi_device *adev, u32 sta)
+{
+       u32 *status = (u32 *)&adev->status;
+#ifdef CONFIG_X86
+       u32 old_status = *status;
+       int i;
+
+       /* acpi_match_device_ids checks status, so start with default */
+       *status = ACPI_STA_DEFAULT;
+       for (i = 0; i < ARRAY_SIZE(always_present_device_ids); i++) {
+               if (acpi_match_device_ids(adev,
+                       always_present_device_ids[i].hid) == 0 &&
+                   adev->pnp.unique_id &&
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/acpi/bus.c +3 -0
+                   strcmp(adev->pnp.unique_id,
+                          always_present_device_ids[i].uid) == 0 &&
+                   x86_match_cpu(always_present_device_ids[i].cpu_ids))

{

Why is this added to acpi_set_device_status(), rather than acpi_bus_get_status_handle() ? That way you're gratuitously calling _STA even though you ignore its return value afterwards.

Because it doesn't make much sense for power resources.

Thanks,
Rafael