ACPI: Fix selecting wrong ACPI fwnode for the iGPU on some Dell laptops
authorHans de Goede <hdegoede@redhat.com>
Tue, 10 Jan 2023 15:30:28 +0000 (16:30 +0100)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 10 Jan 2023 19:23:48 +0000 (20:23 +0100)
The Dell Latitude E6430 both with and without the optional NVidia dGPU
has a bug in its ACPI tables which is causing Linux to assign the wrong
ACPI fwnode / companion to the pci_device for the i915 iGPU.

Specifically under the PCI root bridge there are these 2 ACPI Device()s :

 Scope (_SB.PCI0)
 {
     Device (GFX0)
     {
         Name (_ADR, 0x00020000)  // _ADR: Address
     }

     ...

     Device (VID)
     {
         Name (_ADR, 0x00020000)  // _ADR: Address
         ...

         Method (_DOS, 1, NotSerialized)  // _DOS: Disable Output Switching
         {
             VDP8 = Arg0
             VDP1 (One, VDP8)
         }

         Method (_DOD, 0, NotSerialized)  // _DOD: Display Output Devices
         {
             ...
         }
         ...
     }
 }

The non-functional GFX0 ACPI device is a problem, because this gets
returned as ACPI companion-device by acpi_find_child_device() for the iGPU.

This is a long standing problem and the i915 driver does use the ACPI
companion for some things, but works fine without it.

However since commit 63f534b8bad9 ("ACPI: PCI: Rework acpi_get_pci_dev()")
acpi_get_pci_dev() relies on the physical-node pointer in the acpi_device
and that is set on the wrong acpi_device because of the wrong
acpi_find_child_device() return. This breaks the ACPI video code,
leading to non working backlight control in some cases.

Add a type.backlight flag, mark ACPI video bus devices with this and make
find_child_checks() return a higher score for children with this flag set,
so that it picks the right companion-device.

Fixes: 63f534b8bad9 ("ACPI: PCI: Rework acpi_get_pci_dev()")
Co-developed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Cc: 6.1+ <stable@vger.kernel.org> # 6.1+
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/acpi/glue.c
drivers/acpi/scan.c
include/acpi/acpi_bus.h

index 204fe94c7e458c725627422f4eb7bea9a110cf1e..a194f30876c59a9f8d09fca5aec15b40e062546d 100644 (file)
@@ -75,7 +75,8 @@ static struct acpi_bus_type *acpi_get_bus_type(struct device *dev)
 }
 
 #define FIND_CHILD_MIN_SCORE   1
-#define FIND_CHILD_MAX_SCORE   2
+#define FIND_CHILD_MID_SCORE   2
+#define FIND_CHILD_MAX_SCORE   3
 
 static int match_any(struct acpi_device *adev, void *not_used)
 {
@@ -96,8 +97,17 @@ static int find_child_checks(struct acpi_device *adev, bool check_children)
                return -ENODEV;
 
        status = acpi_evaluate_integer(adev->handle, "_STA", NULL, &sta);
-       if (status == AE_NOT_FOUND)
+       if (status == AE_NOT_FOUND) {
+               /*
+                * Special case: backlight device objects without _STA are
+                * preferred to other objects with the same _ADR value, because
+                * it is more likely that they are actually useful.
+                */
+               if (adev->pnp.type.backlight)
+                       return FIND_CHILD_MID_SCORE;
+
                return FIND_CHILD_MIN_SCORE;
+       }
 
        if (ACPI_FAILURE(status) || !(sta & ACPI_STA_DEVICE_ENABLED))
                return -ENODEV;
index 274344434282ee8e2cc60d91130729270550f536..0c6f06abe3f47f2b77879b0fd051ffb5a043be58 100644 (file)
@@ -1370,9 +1370,12 @@ static void acpi_set_pnp_ids(acpi_handle handle, struct acpi_device_pnp *pnp,
                 * Some devices don't reliably have _HIDs & _CIDs, so add
                 * synthetic HIDs to make sure drivers can find them.
                 */
-               if (acpi_is_video_device(handle))
+               if (acpi_is_video_device(handle)) {
                        acpi_add_id(pnp, ACPI_VIDEO_HID);
-               else if (acpi_bay_match(handle))
+                       pnp->type.backlight = 1;
+                       break;
+               }
+               if (acpi_bay_match(handle))
                        acpi_add_id(pnp, ACPI_BAY_HID);
                else if (acpi_dock_match(handle))
                        acpi_add_id(pnp, ACPI_DOCK_HID);
index cd3b75e08ec3fa67d4b4bff40269ca49fa23a20f..e44be31115a6746f079b6a5cc86bbdc7e01cb659 100644 (file)
@@ -230,7 +230,8 @@ struct acpi_pnp_type {
        u32 hardware_id:1;
        u32 bus_address:1;
        u32 platform_id:1;
-       u32 reserved:29;
+       u32 backlight:1;
+       u32 reserved:28;
 };
 
 struct acpi_device_pnp {