xref: /openbmc/linux/drivers/acpi/x86/utils.c (revision 1a68b346a2c9969c05e80a3b99a9ab160b5655c0)
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  *
25*1a68b346SHans de Goede  * Likewise sometimes some not-actually present devices are sometimes
26*1a68b346SHans de Goede  * reported as present, which may cause issues.
27b7ecf663SHans de Goede  *
28*1a68b346SHans de Goede  * We work around this by using the below quirk list to override the status
29*1a68b346SHans de Goede  * reported by the _STA method with a fixed value (ACPI_STA_DEFAULT or 0).
30*1a68b346SHans de Goede  * Note this MUST only be done for devices where this is safe.
31*1a68b346SHans de Goede  *
32*1a68b346SHans de Goede  * This status overriding is limited to specific CPU (SoC) models both to
33*1a68b346SHans de Goede  * avoid potentially causing trouble on other models and because some HIDs
34*1a68b346SHans de Goede  * are re-used on different SoCs for completely different devices.
35b7ecf663SHans de Goede  */
36*1a68b346SHans 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*1a68b346SHans de Goede 	unsigned long long status;
42b7ecf663SHans de Goede };
43b7ecf663SHans de Goede 
44*1a68b346SHans de Goede #define ENTRY(status, hid, uid, cpu_model, dmi...) {			\
45b7ecf663SHans de Goede 	{ { hid, }, {} },						\
46*1a68b346SHans de Goede 	{ X86_MATCH_INTEL_FAM6_MODEL(cpu_model, NULL), {} },		\
473b6a70beSHans de Goede 	{ { .matches = dmi }, {} },					\
48b7ecf663SHans de Goede 	uid,								\
49*1a68b346SHans de Goede 	status,								\
50b7ecf663SHans de Goede }
51b7ecf663SHans de Goede 
52*1a68b346SHans de Goede #define PRESENT_ENTRY_HID(hid, uid, cpu_model, dmi...) \
53*1a68b346SHans de Goede 	ENTRY(ACPI_STA_DEFAULT, hid, uid, cpu_model, dmi)
54*1a68b346SHans de Goede 
55*1a68b346SHans de Goede #define NOT_PRESENT_ENTRY_HID(hid, uid, cpu_model, dmi...) \
56*1a68b346SHans de Goede 	ENTRY(0, hid, uid, cpu_model, dmi)
57*1a68b346SHans de Goede 
58*1a68b346SHans de Goede static const struct override_status_id override_status_ids[] = {
59b7ecf663SHans de Goede 	/*
60b7ecf663SHans de Goede 	 * Bay / Cherry Trail PWM directly poked by GPU driver in win10,
61b7ecf663SHans de Goede 	 * but Linux uses a separate PWM driver, harmless if not used.
62b7ecf663SHans de Goede 	 */
63*1a68b346SHans de Goede 	PRESENT_ENTRY_HID("80860F09", "1", ATOM_SILVERMONT, {}),
64*1a68b346SHans de Goede 	PRESENT_ENTRY_HID("80862288", "1", ATOM_AIRMONT, {}),
65ff6cdfd7SYauhen Kharuzhy 
66753a448cSHans de Goede 	/*
67753a448cSHans de Goede 	 * The INT0002 device is necessary to clear wakeup interrupt sources
68753a448cSHans de Goede 	 * on Cherry Trail devices, without it we get nobody cared IRQ msgs.
69753a448cSHans de Goede 	 */
70*1a68b346SHans de Goede 	PRESENT_ENTRY_HID("INT0002", "1", ATOM_AIRMONT, {}),
71b5cc1699SHans de Goede 	/*
7272a361a5STristian Celestin 	 * On the Dell Venue 11 Pro 7130 and 7139, the DSDT hides
7372a361a5STristian Celestin 	 * the touchscreen ACPI device until a certain time
7472a361a5STristian Celestin 	 * after _SB.PCI0.GFX0.LCD.LCD1._ON gets called has passed
7572a361a5STristian Celestin 	 * *and* _STA has been called at least 3 times since.
76b5cc1699SHans de Goede 	 */
77*1a68b346SHans de Goede 	PRESENT_ENTRY_HID("SYNA7500", "1", HASWELL_L, {
78b5cc1699SHans de Goede 		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
79b5cc1699SHans de Goede 		DMI_MATCH(DMI_PRODUCT_NAME, "Venue 11 Pro 7130"),
80b5cc1699SHans de Goede 	      }),
81*1a68b346SHans de Goede 	PRESENT_ENTRY_HID("SYNA7500", "1", HASWELL_L, {
8272a361a5STristian Celestin 		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
8372a361a5STristian Celestin 		DMI_MATCH(DMI_PRODUCT_NAME, "Venue 11 Pro 7139"),
8472a361a5STristian Celestin 	      }),
8572a361a5STristian Celestin 
86906dc284SHans de Goede 	/*
871c3b44c0SHans de Goede 	 * The GPD win BIOS dated 20170221 has disabled the accelerometer, the
88906dc284SHans de Goede 	 * drivers sometimes cause crashes under Windows and this is how the
89906dc284SHans de Goede 	 * manufacturer has solved this :| Note that the the DMI data is less
90906dc284SHans de Goede 	 * generic then it seems, a board_vendor of "AMI Corporation" is quite
91906dc284SHans de Goede 	 * rare and a board_name of "Default String" also is rare.
921c3b44c0SHans de Goede 	 *
931c3b44c0SHans de Goede 	 * Unfortunately the GPD pocket also uses these strings and its BIOS
941c3b44c0SHans de Goede 	 * was copy-pasted from the GPD win, so it has a disabled KIOX000A
951c3b44c0SHans de Goede 	 * node which we should not enable, thus we also check the BIOS date.
96906dc284SHans de Goede 	 */
97*1a68b346SHans de Goede 	PRESENT_ENTRY_HID("KIOX000A", "1", ATOM_AIRMONT, {
98906dc284SHans de Goede 		DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
99906dc284SHans de Goede 		DMI_MATCH(DMI_BOARD_NAME, "Default string"),
100906dc284SHans de Goede 		DMI_MATCH(DMI_PRODUCT_NAME, "Default string"),
1011c3b44c0SHans de Goede 		DMI_MATCH(DMI_BIOS_DATE, "02/21/2017")
1021c3b44c0SHans de Goede 	      }),
103*1a68b346SHans de Goede 	PRESENT_ENTRY_HID("KIOX000A", "1", ATOM_AIRMONT, {
1041c3b44c0SHans de Goede 		DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
1051c3b44c0SHans de Goede 		DMI_MATCH(DMI_BOARD_NAME, "Default string"),
1061c3b44c0SHans de Goede 		DMI_MATCH(DMI_PRODUCT_NAME, "Default string"),
107906dc284SHans de Goede 		DMI_MATCH(DMI_BIOS_DATE, "03/20/2017")
108906dc284SHans de Goede 	      }),
109*1a68b346SHans de Goede 	PRESENT_ENTRY_HID("KIOX000A", "1", ATOM_AIRMONT, {
1101c3b44c0SHans de Goede 		DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
1111c3b44c0SHans de Goede 		DMI_MATCH(DMI_BOARD_NAME, "Default string"),
1121c3b44c0SHans de Goede 		DMI_MATCH(DMI_PRODUCT_NAME, "Default string"),
1131c3b44c0SHans de Goede 		DMI_MATCH(DMI_BIOS_DATE, "05/25/2017")
1141c3b44c0SHans de Goede 	      }),
115b7ecf663SHans de Goede };
116b7ecf663SHans de Goede 
117*1a68b346SHans de Goede bool acpi_device_override_status(struct acpi_device *adev, unsigned long long *status)
118b7ecf663SHans de Goede {
119b7ecf663SHans de Goede 	bool ret = false;
120b7ecf663SHans de Goede 	unsigned int i;
121b7ecf663SHans de Goede 
122*1a68b346SHans de Goede 	for (i = 0; i < ARRAY_SIZE(override_status_ids); i++) {
123*1a68b346SHans de Goede 		if (acpi_match_device_ids(adev, override_status_ids[i].hid))
124b7ecf663SHans de Goede 			continue;
125b7ecf663SHans de Goede 
126b7ecf663SHans de Goede 		if (!adev->pnp.unique_id ||
127*1a68b346SHans de Goede 		    strcmp(adev->pnp.unique_id, override_status_ids[i].uid))
128b7ecf663SHans de Goede 			continue;
129b7ecf663SHans de Goede 
130*1a68b346SHans de Goede 		if (!x86_match_cpu(override_status_ids[i].cpu_ids))
131b7ecf663SHans de Goede 			continue;
132b7ecf663SHans de Goede 
133*1a68b346SHans de Goede 		if (override_status_ids[i].dmi_ids[0].matches[0].slot &&
134*1a68b346SHans de Goede 		    !dmi_check_system(override_status_ids[i].dmi_ids))
1353b6a70beSHans de Goede 			continue;
1363b6a70beSHans de Goede 
137*1a68b346SHans de Goede 		*status = override_status_ids[i].status;
138b7ecf663SHans de Goede 		ret = true;
139b7ecf663SHans de Goede 		break;
140b7ecf663SHans de Goede 	}
141b7ecf663SHans de Goede 
142b7ecf663SHans de Goede 	return ret;
143b7ecf663SHans de Goede }
1446485fc18SMario Limonciello 
1456485fc18SMario Limonciello /*
1466485fc18SMario Limonciello  * AMD systems from Renoir and Lucienne *require* that the NVME controller
1476485fc18SMario Limonciello  * is put into D3 over a Modern Standby / suspend-to-idle cycle.
1486485fc18SMario Limonciello  *
1496485fc18SMario Limonciello  * This is "typically" accomplished using the `StorageD3Enable`
1506485fc18SMario Limonciello  * property in the _DSD that is checked via the `acpi_storage_d3` function
1516485fc18SMario Limonciello  * but this property was introduced after many of these systems launched
1526485fc18SMario Limonciello  * and most OEM systems don't have it in their BIOS.
1536485fc18SMario Limonciello  *
1546485fc18SMario Limonciello  * The Microsoft documentation for StorageD3Enable mentioned that Windows has
1556485fc18SMario Limonciello  * a hardcoded allowlist for D3 support, which was used for these platforms.
1566485fc18SMario Limonciello  *
1576485fc18SMario Limonciello  * This allows quirking on Linux in a similar fashion.
1586485fc18SMario Limonciello  */
1596485fc18SMario Limonciello static const struct x86_cpu_id storage_d3_cpu_ids[] = {
1606485fc18SMario Limonciello 	X86_MATCH_VENDOR_FAM_MODEL(AMD, 23, 96, NULL),	/* Renoir */
1616485fc18SMario Limonciello 	X86_MATCH_VENDOR_FAM_MODEL(AMD, 23, 104, NULL),	/* Lucienne */
1626485fc18SMario Limonciello 	{}
1636485fc18SMario Limonciello };
1646485fc18SMario Limonciello 
1656485fc18SMario Limonciello bool force_storage_d3(void)
1666485fc18SMario Limonciello {
1676485fc18SMario Limonciello 	return x86_match_cpu(storage_d3_cpu_ids);
1686485fc18SMario Limonciello }
169