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 74*b72cd8e0SHans de Goede /* The Xiaomi Mi Pad 2 uses PWM2 for touchkeys backlight control */ 75*b72cd8e0SHans de Goede PRESENT_ENTRY_HID("80862289", "2", ATOM_AIRMONT, { 76*b72cd8e0SHans de Goede DMI_MATCH(DMI_SYS_VENDOR, "Xiaomi Inc"), 77*b72cd8e0SHans de Goede DMI_MATCH(DMI_PRODUCT_NAME, "Mipad2"), 78*b72cd8e0SHans de Goede }), 79*b72cd8e0SHans de Goede 80753a448cSHans de Goede /* 81753a448cSHans de Goede * The INT0002 device is necessary to clear wakeup interrupt sources 82753a448cSHans de Goede * on Cherry Trail devices, without it we get nobody cared IRQ msgs. 83753a448cSHans de Goede */ 841a68b346SHans de Goede PRESENT_ENTRY_HID("INT0002", "1", ATOM_AIRMONT, {}), 85b5cc1699SHans de Goede /* 8672a361a5STristian Celestin * On the Dell Venue 11 Pro 7130 and 7139, the DSDT hides 8772a361a5STristian Celestin * the touchscreen ACPI device until a certain time 8872a361a5STristian Celestin * after _SB.PCI0.GFX0.LCD.LCD1._ON gets called has passed 8972a361a5STristian Celestin * *and* _STA has been called at least 3 times since. 90b5cc1699SHans de Goede */ 911a68b346SHans de Goede PRESENT_ENTRY_HID("SYNA7500", "1", HASWELL_L, { 92b5cc1699SHans de Goede DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 93b5cc1699SHans de Goede DMI_MATCH(DMI_PRODUCT_NAME, "Venue 11 Pro 7130"), 94b5cc1699SHans de Goede }), 951a68b346SHans de Goede PRESENT_ENTRY_HID("SYNA7500", "1", HASWELL_L, { 9672a361a5STristian Celestin DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 9772a361a5STristian Celestin DMI_MATCH(DMI_PRODUCT_NAME, "Venue 11 Pro 7139"), 9872a361a5STristian Celestin }), 9972a361a5STristian Celestin 100906dc284SHans de Goede /* 1011c3b44c0SHans de Goede * The GPD win BIOS dated 20170221 has disabled the accelerometer, the 102906dc284SHans de Goede * drivers sometimes cause crashes under Windows and this is how the 10357d2dbf7SHans de Goede * manufacturer has solved this :| The DMI match may not seem unique, 10457d2dbf7SHans de Goede * but it is. In the 67000+ DMI decode dumps from linux-hardware.org 10557d2dbf7SHans de Goede * only 116 have board_vendor set to "AMI Corporation" and of those 116 10657d2dbf7SHans de Goede * only the GPD win and pocket entries' board_name is "Default string". 1071c3b44c0SHans de Goede * 1081c3b44c0SHans de Goede * Unfortunately the GPD pocket also uses these strings and its BIOS 1091c3b44c0SHans de Goede * was copy-pasted from the GPD win, so it has a disabled KIOX000A 1101c3b44c0SHans de Goede * node which we should not enable, thus we also check the BIOS date. 111906dc284SHans de Goede */ 1121a68b346SHans de Goede PRESENT_ENTRY_HID("KIOX000A", "1", ATOM_AIRMONT, { 113906dc284SHans de Goede DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"), 114906dc284SHans de Goede DMI_MATCH(DMI_BOARD_NAME, "Default string"), 115906dc284SHans de Goede DMI_MATCH(DMI_PRODUCT_NAME, "Default string"), 1161c3b44c0SHans de Goede DMI_MATCH(DMI_BIOS_DATE, "02/21/2017") 1171c3b44c0SHans 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"), 122906dc284SHans de Goede DMI_MATCH(DMI_BIOS_DATE, "03/20/2017") 123906dc284SHans de Goede }), 1241a68b346SHans de Goede PRESENT_ENTRY_HID("KIOX000A", "1", ATOM_AIRMONT, { 1251c3b44c0SHans de Goede DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"), 1261c3b44c0SHans de Goede DMI_MATCH(DMI_BOARD_NAME, "Default string"), 1271c3b44c0SHans de Goede DMI_MATCH(DMI_PRODUCT_NAME, "Default string"), 1281c3b44c0SHans de Goede DMI_MATCH(DMI_BIOS_DATE, "05/25/2017") 1291c3b44c0SHans de Goede }), 13057d2dbf7SHans de Goede 13157d2dbf7SHans de Goede /* 13257d2dbf7SHans de Goede * The GPD win/pocket have a PCI wifi card, but its DSDT has the SDIO 13357d2dbf7SHans de Goede * mmc controller enabled and that has a child-device which _PS3 13457d2dbf7SHans de Goede * method sets a GPIO causing the PCI wifi card to turn off. 13557d2dbf7SHans de Goede * See above remark about uniqueness of the DMI match. 13657d2dbf7SHans de Goede */ 13757d2dbf7SHans de Goede NOT_PRESENT_ENTRY_PATH("\\_SB_.PCI0.SDHB.BRC1", ATOM_AIRMONT, { 13857d2dbf7SHans de Goede DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"), 13957d2dbf7SHans de Goede DMI_EXACT_MATCH(DMI_BOARD_NAME, "Default string"), 14057d2dbf7SHans de Goede DMI_EXACT_MATCH(DMI_BOARD_SERIAL, "Default string"), 14157d2dbf7SHans de Goede DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Default string"), 14257d2dbf7SHans de Goede }), 143b7ecf663SHans de Goede }; 144b7ecf663SHans de Goede 1451a68b346SHans de Goede bool acpi_device_override_status(struct acpi_device *adev, unsigned long long *status) 146b7ecf663SHans de Goede { 147b7ecf663SHans de Goede bool ret = false; 148b7ecf663SHans de Goede unsigned int i; 149b7ecf663SHans de Goede 1501a68b346SHans de Goede for (i = 0; i < ARRAY_SIZE(override_status_ids); i++) { 1511a68b346SHans de Goede if (!x86_match_cpu(override_status_ids[i].cpu_ids)) 152b7ecf663SHans de Goede continue; 153b7ecf663SHans de Goede 1541a68b346SHans de Goede if (override_status_ids[i].dmi_ids[0].matches[0].slot && 1551a68b346SHans de Goede !dmi_check_system(override_status_ids[i].dmi_ids)) 1563b6a70beSHans de Goede continue; 1573b6a70beSHans de Goede 158ba46e42eSHans de Goede if (override_status_ids[i].path) { 159ba46e42eSHans de Goede struct acpi_buffer path = { ACPI_ALLOCATE_BUFFER, NULL }; 160ba46e42eSHans de Goede bool match; 161ba46e42eSHans de Goede 162ba46e42eSHans de Goede if (acpi_get_name(adev->handle, ACPI_FULL_PATHNAME, &path)) 163ba46e42eSHans de Goede continue; 164ba46e42eSHans de Goede 165ba46e42eSHans de Goede match = strcmp((char *)path.pointer, override_status_ids[i].path) == 0; 166ba46e42eSHans de Goede kfree(path.pointer); 167ba46e42eSHans de Goede 168ba46e42eSHans de Goede if (!match) 169ba46e42eSHans de Goede continue; 170ba46e42eSHans de Goede } else { 171ba46e42eSHans de Goede if (acpi_match_device_ids(adev, override_status_ids[i].hid)) 172ba46e42eSHans de Goede continue; 173ba46e42eSHans de Goede 174ba46e42eSHans de Goede if (!adev->pnp.unique_id || 175ba46e42eSHans de Goede strcmp(adev->pnp.unique_id, override_status_ids[i].uid)) 176ba46e42eSHans de Goede continue; 177ba46e42eSHans de Goede } 178ba46e42eSHans de Goede 1791a68b346SHans de Goede *status = override_status_ids[i].status; 180b7ecf663SHans de Goede ret = true; 181b7ecf663SHans de Goede break; 182b7ecf663SHans de Goede } 183b7ecf663SHans de Goede 184b7ecf663SHans de Goede return ret; 185b7ecf663SHans de Goede } 1866485fc18SMario Limonciello 1876485fc18SMario Limonciello /* 1886485fc18SMario Limonciello * AMD systems from Renoir and Lucienne *require* that the NVME controller 1896485fc18SMario Limonciello * is put into D3 over a Modern Standby / suspend-to-idle cycle. 1906485fc18SMario Limonciello * 1916485fc18SMario Limonciello * This is "typically" accomplished using the `StorageD3Enable` 1926485fc18SMario Limonciello * property in the _DSD that is checked via the `acpi_storage_d3` function 1936485fc18SMario Limonciello * but this property was introduced after many of these systems launched 1946485fc18SMario Limonciello * and most OEM systems don't have it in their BIOS. 1956485fc18SMario Limonciello * 1966485fc18SMario Limonciello * The Microsoft documentation for StorageD3Enable mentioned that Windows has 1976485fc18SMario Limonciello * a hardcoded allowlist for D3 support, which was used for these platforms. 1986485fc18SMario Limonciello * 1996485fc18SMario Limonciello * This allows quirking on Linux in a similar fashion. 2006485fc18SMario Limonciello */ 2016485fc18SMario Limonciello static const struct x86_cpu_id storage_d3_cpu_ids[] = { 2026485fc18SMario Limonciello X86_MATCH_VENDOR_FAM_MODEL(AMD, 23, 96, NULL), /* Renoir */ 2036485fc18SMario Limonciello X86_MATCH_VENDOR_FAM_MODEL(AMD, 23, 104, NULL), /* Lucienne */ 2046485fc18SMario Limonciello {} 2056485fc18SMario Limonciello }; 2066485fc18SMario Limonciello 2076485fc18SMario Limonciello bool force_storage_d3(void) 2086485fc18SMario Limonciello { 2096485fc18SMario Limonciello return x86_match_cpu(storage_d3_cpu_ids); 2106485fc18SMario Limonciello } 211