1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 2b7ecf663SHans de Goede /* 3b7ecf663SHans de Goede * X86 ACPI Utility Functions 4b7ecf663SHans de Goede * 5b7ecf663SHans de Goede * Copyright (C) 2017 Hans de Goede <hdegoede@redhat.com> 6b7ecf663SHans de Goede * 7b7ecf663SHans de Goede * Based on various non upstream patches to support the CHT Whiskey Cove PMIC: 8b7ecf663SHans de Goede * Copyright (C) 2013-2015 Intel Corporation. All rights reserved. 9b7ecf663SHans de Goede */ 10b7ecf663SHans de Goede 11b7ecf663SHans de Goede #include <linux/acpi.h> 123b6a70beSHans de Goede #include <linux/dmi.h> 13b7ecf663SHans de Goede #include <asm/cpu_device_id.h> 14b7ecf663SHans de Goede #include <asm/intel-family.h> 15b7ecf663SHans de Goede #include "../internal.h" 16b7ecf663SHans de Goede 17b7ecf663SHans de Goede /* 18b7ecf663SHans de Goede * Some ACPI devices are hidden (status == 0x0) in recent BIOS-es because 19b7ecf663SHans de Goede * some recent Windows drivers bind to one device but poke at multiple 20b7ecf663SHans de Goede * devices at the same time, so the others get hidden. 213b6a70beSHans de Goede * 223b6a70beSHans de Goede * Some BIOS-es (temporarily) hide specific APCI devices to work around Windows 233b6a70beSHans de Goede * driver bugs. We use DMI matching to match known cases of this. 243b6a70beSHans de Goede * 251a68b346SHans de Goede * Likewise sometimes some not-actually present devices are sometimes 261a68b346SHans de Goede * reported as present, which may cause issues. 27b7ecf663SHans de Goede * 281a68b346SHans de Goede * We work around this by using the below quirk list to override the status 291a68b346SHans de Goede * reported by the _STA method with a fixed value (ACPI_STA_DEFAULT or 0). 301a68b346SHans de Goede * Note this MUST only be done for devices where this is safe. 311a68b346SHans de Goede * 321a68b346SHans de Goede * This status overriding is limited to specific CPU (SoC) models both to 331a68b346SHans de Goede * avoid potentially causing trouble on other models and because some HIDs 341a68b346SHans de Goede * are re-used on different SoCs for completely different devices. 35b7ecf663SHans de Goede */ 361a68b346SHans de Goede struct override_status_id { 37b7ecf663SHans de Goede struct acpi_device_id hid[2]; 38b7ecf663SHans de Goede struct x86_cpu_id cpu_ids[2]; 393b6a70beSHans de Goede struct dmi_system_id dmi_ids[2]; /* Optional */ 40b7ecf663SHans de Goede const char *uid; 41ba46e42eSHans de Goede const char *path; 421a68b346SHans de Goede unsigned long long status; 43b7ecf663SHans de Goede }; 44b7ecf663SHans de Goede 45ba46e42eSHans de Goede #define ENTRY(status, hid, uid, path, cpu_model, dmi...) { \ 46b7ecf663SHans de Goede { { hid, }, {} }, \ 471a68b346SHans de Goede { X86_MATCH_INTEL_FAM6_MODEL(cpu_model, NULL), {} }, \ 483b6a70beSHans de Goede { { .matches = dmi }, {} }, \ 49b7ecf663SHans de Goede uid, \ 50ba46e42eSHans de Goede path, \ 511a68b346SHans de Goede status, \ 52b7ecf663SHans de Goede } 53b7ecf663SHans de Goede 541a68b346SHans de Goede #define PRESENT_ENTRY_HID(hid, uid, cpu_model, dmi...) \ 55ba46e42eSHans de Goede ENTRY(ACPI_STA_DEFAULT, hid, uid, NULL, cpu_model, dmi) 561a68b346SHans de Goede 571a68b346SHans de Goede #define NOT_PRESENT_ENTRY_HID(hid, uid, cpu_model, dmi...) \ 58ba46e42eSHans de Goede ENTRY(0, hid, uid, NULL, cpu_model, dmi) 59ba46e42eSHans de Goede 60ba46e42eSHans de Goede #define PRESENT_ENTRY_PATH(path, cpu_model, dmi...) \ 61ba46e42eSHans de Goede ENTRY(ACPI_STA_DEFAULT, "", NULL, path, cpu_model, dmi) 62ba46e42eSHans de Goede 63ba46e42eSHans de Goede #define NOT_PRESENT_ENTRY_PATH(path, cpu_model, dmi...) \ 64ba46e42eSHans de Goede ENTRY(0, "", NULL, path, cpu_model, dmi) 651a68b346SHans de Goede 661a68b346SHans de Goede static const struct override_status_id override_status_ids[] = { 67b7ecf663SHans de Goede /* 68b7ecf663SHans de Goede * Bay / Cherry Trail PWM directly poked by GPU driver in win10, 69b7ecf663SHans de Goede * but Linux uses a separate PWM driver, harmless if not used. 70b7ecf663SHans de Goede */ 711a68b346SHans de Goede PRESENT_ENTRY_HID("80860F09", "1", ATOM_SILVERMONT, {}), 721a68b346SHans de Goede PRESENT_ENTRY_HID("80862288", "1", ATOM_AIRMONT, {}), 73ff6cdfd7SYauhen Kharuzhy 74753a448cSHans de Goede /* 75753a448cSHans de Goede * The INT0002 device is necessary to clear wakeup interrupt sources 76753a448cSHans de Goede * on Cherry Trail devices, without it we get nobody cared IRQ msgs. 77753a448cSHans de Goede */ 781a68b346SHans de Goede PRESENT_ENTRY_HID("INT0002", "1", ATOM_AIRMONT, {}), 79b5cc1699SHans de Goede /* 8072a361a5STristian Celestin * On the Dell Venue 11 Pro 7130 and 7139, the DSDT hides 8172a361a5STristian Celestin * the touchscreen ACPI device until a certain time 8272a361a5STristian Celestin * after _SB.PCI0.GFX0.LCD.LCD1._ON gets called has passed 8372a361a5STristian Celestin * *and* _STA has been called at least 3 times since. 84b5cc1699SHans de Goede */ 851a68b346SHans de Goede PRESENT_ENTRY_HID("SYNA7500", "1", HASWELL_L, { 86b5cc1699SHans de Goede DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 87b5cc1699SHans de Goede DMI_MATCH(DMI_PRODUCT_NAME, "Venue 11 Pro 7130"), 88b5cc1699SHans de Goede }), 891a68b346SHans de Goede PRESENT_ENTRY_HID("SYNA7500", "1", HASWELL_L, { 9072a361a5STristian Celestin DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 9172a361a5STristian Celestin DMI_MATCH(DMI_PRODUCT_NAME, "Venue 11 Pro 7139"), 9272a361a5STristian Celestin }), 9372a361a5STristian Celestin 94906dc284SHans de Goede /* 951c3b44c0SHans de Goede * The GPD win BIOS dated 20170221 has disabled the accelerometer, the 96906dc284SHans de Goede * drivers sometimes cause crashes under Windows and this is how the 97*57d2dbf7SHans de Goede * manufacturer has solved this :| The DMI match may not seem unique, 98*57d2dbf7SHans de Goede * but it is. In the 67000+ DMI decode dumps from linux-hardware.org 99*57d2dbf7SHans de Goede * only 116 have board_vendor set to "AMI Corporation" and of those 116 100*57d2dbf7SHans de Goede * only the GPD win and pocket entries' board_name is "Default string". 1011c3b44c0SHans de Goede * 1021c3b44c0SHans de Goede * Unfortunately the GPD pocket also uses these strings and its BIOS 1031c3b44c0SHans de Goede * was copy-pasted from the GPD win, so it has a disabled KIOX000A 1041c3b44c0SHans de Goede * node which we should not enable, thus we also check the BIOS date. 105906dc284SHans de Goede */ 1061a68b346SHans de Goede PRESENT_ENTRY_HID("KIOX000A", "1", ATOM_AIRMONT, { 107906dc284SHans de Goede DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"), 108906dc284SHans de Goede DMI_MATCH(DMI_BOARD_NAME, "Default string"), 109906dc284SHans de Goede DMI_MATCH(DMI_PRODUCT_NAME, "Default string"), 1101c3b44c0SHans de Goede DMI_MATCH(DMI_BIOS_DATE, "02/21/2017") 1111c3b44c0SHans de Goede }), 1121a68b346SHans de Goede PRESENT_ENTRY_HID("KIOX000A", "1", ATOM_AIRMONT, { 1131c3b44c0SHans de Goede DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"), 1141c3b44c0SHans de Goede DMI_MATCH(DMI_BOARD_NAME, "Default string"), 1151c3b44c0SHans de Goede DMI_MATCH(DMI_PRODUCT_NAME, "Default string"), 116906dc284SHans de Goede DMI_MATCH(DMI_BIOS_DATE, "03/20/2017") 117906dc284SHans de Goede }), 1181a68b346SHans de Goede PRESENT_ENTRY_HID("KIOX000A", "1", ATOM_AIRMONT, { 1191c3b44c0SHans de Goede DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"), 1201c3b44c0SHans de Goede DMI_MATCH(DMI_BOARD_NAME, "Default string"), 1211c3b44c0SHans de Goede DMI_MATCH(DMI_PRODUCT_NAME, "Default string"), 1221c3b44c0SHans de Goede DMI_MATCH(DMI_BIOS_DATE, "05/25/2017") 1231c3b44c0SHans de Goede }), 124*57d2dbf7SHans de Goede 125*57d2dbf7SHans de Goede /* 126*57d2dbf7SHans de Goede * The GPD win/pocket have a PCI wifi card, but its DSDT has the SDIO 127*57d2dbf7SHans de Goede * mmc controller enabled and that has a child-device which _PS3 128*57d2dbf7SHans de Goede * method sets a GPIO causing the PCI wifi card to turn off. 129*57d2dbf7SHans de Goede * See above remark about uniqueness of the DMI match. 130*57d2dbf7SHans de Goede */ 131*57d2dbf7SHans de Goede NOT_PRESENT_ENTRY_PATH("\\_SB_.PCI0.SDHB.BRC1", ATOM_AIRMONT, { 132*57d2dbf7SHans de Goede DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"), 133*57d2dbf7SHans de Goede DMI_EXACT_MATCH(DMI_BOARD_NAME, "Default string"), 134*57d2dbf7SHans de Goede DMI_EXACT_MATCH(DMI_BOARD_SERIAL, "Default string"), 135*57d2dbf7SHans de Goede DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Default string"), 136*57d2dbf7SHans de Goede }), 137b7ecf663SHans de Goede }; 138b7ecf663SHans de Goede 1391a68b346SHans de Goede bool acpi_device_override_status(struct acpi_device *adev, unsigned long long *status) 140b7ecf663SHans de Goede { 141b7ecf663SHans de Goede bool ret = false; 142b7ecf663SHans de Goede unsigned int i; 143b7ecf663SHans de Goede 1441a68b346SHans de Goede for (i = 0; i < ARRAY_SIZE(override_status_ids); i++) { 1451a68b346SHans de Goede if (!x86_match_cpu(override_status_ids[i].cpu_ids)) 146b7ecf663SHans de Goede continue; 147b7ecf663SHans de Goede 1481a68b346SHans de Goede if (override_status_ids[i].dmi_ids[0].matches[0].slot && 1491a68b346SHans de Goede !dmi_check_system(override_status_ids[i].dmi_ids)) 1503b6a70beSHans de Goede continue; 1513b6a70beSHans de Goede 152ba46e42eSHans de Goede if (override_status_ids[i].path) { 153ba46e42eSHans de Goede struct acpi_buffer path = { ACPI_ALLOCATE_BUFFER, NULL }; 154ba46e42eSHans de Goede bool match; 155ba46e42eSHans de Goede 156ba46e42eSHans de Goede if (acpi_get_name(adev->handle, ACPI_FULL_PATHNAME, &path)) 157ba46e42eSHans de Goede continue; 158ba46e42eSHans de Goede 159ba46e42eSHans de Goede match = strcmp((char *)path.pointer, override_status_ids[i].path) == 0; 160ba46e42eSHans de Goede kfree(path.pointer); 161ba46e42eSHans de Goede 162ba46e42eSHans de Goede if (!match) 163ba46e42eSHans de Goede continue; 164ba46e42eSHans de Goede } else { 165ba46e42eSHans de Goede if (acpi_match_device_ids(adev, override_status_ids[i].hid)) 166ba46e42eSHans de Goede continue; 167ba46e42eSHans de Goede 168ba46e42eSHans de Goede if (!adev->pnp.unique_id || 169ba46e42eSHans de Goede strcmp(adev->pnp.unique_id, override_status_ids[i].uid)) 170ba46e42eSHans de Goede continue; 171ba46e42eSHans de Goede } 172ba46e42eSHans de Goede 1731a68b346SHans de Goede *status = override_status_ids[i].status; 174b7ecf663SHans de Goede ret = true; 175b7ecf663SHans de Goede break; 176b7ecf663SHans de Goede } 177b7ecf663SHans de Goede 178b7ecf663SHans de Goede return ret; 179b7ecf663SHans de Goede } 1806485fc18SMario Limonciello 1816485fc18SMario Limonciello /* 1826485fc18SMario Limonciello * AMD systems from Renoir and Lucienne *require* that the NVME controller 1836485fc18SMario Limonciello * is put into D3 over a Modern Standby / suspend-to-idle cycle. 1846485fc18SMario Limonciello * 1856485fc18SMario Limonciello * This is "typically" accomplished using the `StorageD3Enable` 1866485fc18SMario Limonciello * property in the _DSD that is checked via the `acpi_storage_d3` function 1876485fc18SMario Limonciello * but this property was introduced after many of these systems launched 1886485fc18SMario Limonciello * and most OEM systems don't have it in their BIOS. 1896485fc18SMario Limonciello * 1906485fc18SMario Limonciello * The Microsoft documentation for StorageD3Enable mentioned that Windows has 1916485fc18SMario Limonciello * a hardcoded allowlist for D3 support, which was used for these platforms. 1926485fc18SMario Limonciello * 1936485fc18SMario Limonciello * This allows quirking on Linux in a similar fashion. 1946485fc18SMario Limonciello */ 1956485fc18SMario Limonciello static const struct x86_cpu_id storage_d3_cpu_ids[] = { 1966485fc18SMario Limonciello X86_MATCH_VENDOR_FAM_MODEL(AMD, 23, 96, NULL), /* Renoir */ 1976485fc18SMario Limonciello X86_MATCH_VENDOR_FAM_MODEL(AMD, 23, 104, NULL), /* Lucienne */ 1986485fc18SMario Limonciello {} 1996485fc18SMario Limonciello }; 2006485fc18SMario Limonciello 2016485fc18SMario Limonciello bool force_storage_d3(void) 2026485fc18SMario Limonciello { 2036485fc18SMario Limonciello return x86_match_cpu(storage_d3_cpu_ids); 2046485fc18SMario Limonciello } 205