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; 41*ba46e42eSHans de Goede const char *path; 421a68b346SHans de Goede unsigned long long status; 43b7ecf663SHans de Goede }; 44b7ecf663SHans de Goede 45*ba46e42eSHans 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, \ 50*ba46e42eSHans 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...) \ 55*ba46e42eSHans 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...) \ 58*ba46e42eSHans de Goede ENTRY(0, hid, uid, NULL, cpu_model, dmi) 59*ba46e42eSHans de Goede 60*ba46e42eSHans de Goede #define PRESENT_ENTRY_PATH(path, cpu_model, dmi...) \ 61*ba46e42eSHans de Goede ENTRY(ACPI_STA_DEFAULT, "", NULL, path, cpu_model, dmi) 62*ba46e42eSHans de Goede 63*ba46e42eSHans de Goede #define NOT_PRESENT_ENTRY_PATH(path, cpu_model, dmi...) \ 64*ba46e42eSHans 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 97906dc284SHans de Goede * manufacturer has solved this :| Note that the the DMI data is less 98906dc284SHans de Goede * generic then it seems, a board_vendor of "AMI Corporation" is quite 99906dc284SHans de Goede * rare and a board_name of "Default String" also is rare. 1001c3b44c0SHans de Goede * 1011c3b44c0SHans de Goede * Unfortunately the GPD pocket also uses these strings and its BIOS 1021c3b44c0SHans de Goede * was copy-pasted from the GPD win, so it has a disabled KIOX000A 1031c3b44c0SHans de Goede * node which we should not enable, thus we also check the BIOS date. 104906dc284SHans de Goede */ 1051a68b346SHans de Goede PRESENT_ENTRY_HID("KIOX000A", "1", ATOM_AIRMONT, { 106906dc284SHans de Goede DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"), 107906dc284SHans de Goede DMI_MATCH(DMI_BOARD_NAME, "Default string"), 108906dc284SHans de Goede DMI_MATCH(DMI_PRODUCT_NAME, "Default string"), 1091c3b44c0SHans de Goede DMI_MATCH(DMI_BIOS_DATE, "02/21/2017") 1101c3b44c0SHans de Goede }), 1111a68b346SHans de Goede PRESENT_ENTRY_HID("KIOX000A", "1", ATOM_AIRMONT, { 1121c3b44c0SHans de Goede DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"), 1131c3b44c0SHans de Goede DMI_MATCH(DMI_BOARD_NAME, "Default string"), 1141c3b44c0SHans de Goede DMI_MATCH(DMI_PRODUCT_NAME, "Default string"), 115906dc284SHans de Goede DMI_MATCH(DMI_BIOS_DATE, "03/20/2017") 116906dc284SHans de Goede }), 1171a68b346SHans de Goede PRESENT_ENTRY_HID("KIOX000A", "1", ATOM_AIRMONT, { 1181c3b44c0SHans de Goede DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"), 1191c3b44c0SHans de Goede DMI_MATCH(DMI_BOARD_NAME, "Default string"), 1201c3b44c0SHans de Goede DMI_MATCH(DMI_PRODUCT_NAME, "Default string"), 1211c3b44c0SHans de Goede DMI_MATCH(DMI_BIOS_DATE, "05/25/2017") 1221c3b44c0SHans de Goede }), 123b7ecf663SHans de Goede }; 124b7ecf663SHans de Goede 1251a68b346SHans de Goede bool acpi_device_override_status(struct acpi_device *adev, unsigned long long *status) 126b7ecf663SHans de Goede { 127b7ecf663SHans de Goede bool ret = false; 128b7ecf663SHans de Goede unsigned int i; 129b7ecf663SHans de Goede 1301a68b346SHans de Goede for (i = 0; i < ARRAY_SIZE(override_status_ids); i++) { 1311a68b346SHans de Goede if (!x86_match_cpu(override_status_ids[i].cpu_ids)) 132b7ecf663SHans de Goede continue; 133b7ecf663SHans de Goede 1341a68b346SHans de Goede if (override_status_ids[i].dmi_ids[0].matches[0].slot && 1351a68b346SHans de Goede !dmi_check_system(override_status_ids[i].dmi_ids)) 1363b6a70beSHans de Goede continue; 1373b6a70beSHans de Goede 138*ba46e42eSHans de Goede if (override_status_ids[i].path) { 139*ba46e42eSHans de Goede struct acpi_buffer path = { ACPI_ALLOCATE_BUFFER, NULL }; 140*ba46e42eSHans de Goede bool match; 141*ba46e42eSHans de Goede 142*ba46e42eSHans de Goede if (acpi_get_name(adev->handle, ACPI_FULL_PATHNAME, &path)) 143*ba46e42eSHans de Goede continue; 144*ba46e42eSHans de Goede 145*ba46e42eSHans de Goede match = strcmp((char *)path.pointer, override_status_ids[i].path) == 0; 146*ba46e42eSHans de Goede kfree(path.pointer); 147*ba46e42eSHans de Goede 148*ba46e42eSHans de Goede if (!match) 149*ba46e42eSHans de Goede continue; 150*ba46e42eSHans de Goede } else { 151*ba46e42eSHans de Goede if (acpi_match_device_ids(adev, override_status_ids[i].hid)) 152*ba46e42eSHans de Goede continue; 153*ba46e42eSHans de Goede 154*ba46e42eSHans de Goede if (!adev->pnp.unique_id || 155*ba46e42eSHans de Goede strcmp(adev->pnp.unique_id, override_status_ids[i].uid)) 156*ba46e42eSHans de Goede continue; 157*ba46e42eSHans de Goede } 158*ba46e42eSHans de Goede 1591a68b346SHans de Goede *status = override_status_ids[i].status; 160b7ecf663SHans de Goede ret = true; 161b7ecf663SHans de Goede break; 162b7ecf663SHans de Goede } 163b7ecf663SHans de Goede 164b7ecf663SHans de Goede return ret; 165b7ecf663SHans de Goede } 1666485fc18SMario Limonciello 1676485fc18SMario Limonciello /* 1686485fc18SMario Limonciello * AMD systems from Renoir and Lucienne *require* that the NVME controller 1696485fc18SMario Limonciello * is put into D3 over a Modern Standby / suspend-to-idle cycle. 1706485fc18SMario Limonciello * 1716485fc18SMario Limonciello * This is "typically" accomplished using the `StorageD3Enable` 1726485fc18SMario Limonciello * property in the _DSD that is checked via the `acpi_storage_d3` function 1736485fc18SMario Limonciello * but this property was introduced after many of these systems launched 1746485fc18SMario Limonciello * and most OEM systems don't have it in their BIOS. 1756485fc18SMario Limonciello * 1766485fc18SMario Limonciello * The Microsoft documentation for StorageD3Enable mentioned that Windows has 1776485fc18SMario Limonciello * a hardcoded allowlist for D3 support, which was used for these platforms. 1786485fc18SMario Limonciello * 1796485fc18SMario Limonciello * This allows quirking on Linux in a similar fashion. 1806485fc18SMario Limonciello */ 1816485fc18SMario Limonciello static const struct x86_cpu_id storage_d3_cpu_ids[] = { 1826485fc18SMario Limonciello X86_MATCH_VENDOR_FAM_MODEL(AMD, 23, 96, NULL), /* Renoir */ 1836485fc18SMario Limonciello X86_MATCH_VENDOR_FAM_MODEL(AMD, 23, 104, NULL), /* Lucienne */ 1846485fc18SMario Limonciello {} 1856485fc18SMario Limonciello }; 1866485fc18SMario Limonciello 1876485fc18SMario Limonciello bool force_storage_d3(void) 1886485fc18SMario Limonciello { 1896485fc18SMario Limonciello return x86_match_cpu(storage_d3_cpu_ids); 1906485fc18SMario Limonciello } 191