utils.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * X86 ACPI Utility Functions
  4. *
  5. * Copyright (C) 2017 Hans de Goede <hdegoede@redhat.com>
  6. *
  7. * Based on various non upstream patches to support the CHT Whiskey Cove PMIC:
  8. * Copyright (C) 2013-2015 Intel Corporation. All rights reserved.
  9. */
  10. #include <linux/acpi.h>
  11. #include <linux/dmi.h>
  12. #include <asm/cpu_device_id.h>
  13. #include <asm/intel-family.h>
  14. #include "../internal.h"
  15. /*
  16. * Some ACPI devices are hidden (status == 0x0) in recent BIOS-es because
  17. * some recent Windows drivers bind to one device but poke at multiple
  18. * devices at the same time, so the others get hidden.
  19. *
  20. * Some BIOS-es (temporarily) hide specific APCI devices to work around Windows
  21. * driver bugs. We use DMI matching to match known cases of this.
  22. *
  23. * Likewise sometimes some not-actually present devices are sometimes
  24. * reported as present, which may cause issues.
  25. *
  26. * We work around this by using the below quirk list to override the status
  27. * reported by the _STA method with a fixed value (ACPI_STA_DEFAULT or 0).
  28. * Note this MUST only be done for devices where this is safe.
  29. *
  30. * This status overriding is limited to specific CPU (SoC) models both to
  31. * avoid potentially causing trouble on other models and because some HIDs
  32. * are re-used on different SoCs for completely different devices.
  33. */
  34. struct override_status_id {
  35. struct acpi_device_id hid[2];
  36. struct x86_cpu_id cpu_ids[2];
  37. struct dmi_system_id dmi_ids[2]; /* Optional */
  38. const char *uid;
  39. const char *path;
  40. unsigned long long status;
  41. };
  42. #define ENTRY(status, hid, uid, path, cpu_model, dmi...) { \
  43. { { hid, }, {} }, \
  44. { X86_MATCH_INTEL_FAM6_MODEL(cpu_model, NULL), {} }, \
  45. { { .matches = dmi }, {} }, \
  46. uid, \
  47. path, \
  48. status, \
  49. }
  50. #define PRESENT_ENTRY_HID(hid, uid, cpu_model, dmi...) \
  51. ENTRY(ACPI_STA_DEFAULT, hid, uid, NULL, cpu_model, dmi)
  52. #define NOT_PRESENT_ENTRY_HID(hid, uid, cpu_model, dmi...) \
  53. ENTRY(0, hid, uid, NULL, cpu_model, dmi)
  54. #define PRESENT_ENTRY_PATH(path, cpu_model, dmi...) \
  55. ENTRY(ACPI_STA_DEFAULT, "", NULL, path, cpu_model, dmi)
  56. #define NOT_PRESENT_ENTRY_PATH(path, cpu_model, dmi...) \
  57. ENTRY(0, "", NULL, path, cpu_model, dmi)
  58. static const struct override_status_id override_status_ids[] = {
  59. /*
  60. * Bay / Cherry Trail PWM directly poked by GPU driver in win10,
  61. * but Linux uses a separate PWM driver, harmless if not used.
  62. */
  63. PRESENT_ENTRY_HID("80860F09", "1", ATOM_SILVERMONT, {}),
  64. PRESENT_ENTRY_HID("80862288", "1", ATOM_AIRMONT, {}),
  65. /*
  66. * The INT0002 device is necessary to clear wakeup interrupt sources
  67. * on Cherry Trail devices, without it we get nobody cared IRQ msgs.
  68. */
  69. PRESENT_ENTRY_HID("INT0002", "1", ATOM_AIRMONT, {}),
  70. /*
  71. * On the Dell Venue 11 Pro 7130 and 7139, the DSDT hides
  72. * the touchscreen ACPI device until a certain time
  73. * after _SB.PCI0.GFX0.LCD.LCD1._ON gets called has passed
  74. * *and* _STA has been called at least 3 times since.
  75. */
  76. PRESENT_ENTRY_HID("SYNA7500", "1", HASWELL_L, {
  77. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  78. DMI_MATCH(DMI_PRODUCT_NAME, "Venue 11 Pro 7130"),
  79. }),
  80. PRESENT_ENTRY_HID("SYNA7500", "1", HASWELL_L, {
  81. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  82. DMI_MATCH(DMI_PRODUCT_NAME, "Venue 11 Pro 7139"),
  83. }),
  84. /*
  85. * The GPD win BIOS dated 20170221 has disabled the accelerometer, the
  86. * drivers sometimes cause crashes under Windows and this is how the
  87. * manufacturer has solved this :| The DMI match may not seem unique,
  88. * but it is. In the 67000+ DMI decode dumps from linux-hardware.org
  89. * only 116 have board_vendor set to "AMI Corporation" and of those 116
  90. * only the GPD win and pocket entries' board_name is "Default string".
  91. *
  92. * Unfortunately the GPD pocket also uses these strings and its BIOS
  93. * was copy-pasted from the GPD win, so it has a disabled KIOX000A
  94. * node which we should not enable, thus we also check the BIOS date.
  95. */
  96. PRESENT_ENTRY_HID("KIOX000A", "1", ATOM_AIRMONT, {
  97. DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
  98. DMI_MATCH(DMI_BOARD_NAME, "Default string"),
  99. DMI_MATCH(DMI_PRODUCT_NAME, "Default string"),
  100. DMI_MATCH(DMI_BIOS_DATE, "02/21/2017")
  101. }),
  102. PRESENT_ENTRY_HID("KIOX000A", "1", ATOM_AIRMONT, {
  103. DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
  104. DMI_MATCH(DMI_BOARD_NAME, "Default string"),
  105. DMI_MATCH(DMI_PRODUCT_NAME, "Default string"),
  106. DMI_MATCH(DMI_BIOS_DATE, "03/20/2017")
  107. }),
  108. PRESENT_ENTRY_HID("KIOX000A", "1", ATOM_AIRMONT, {
  109. DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
  110. DMI_MATCH(DMI_BOARD_NAME, "Default string"),
  111. DMI_MATCH(DMI_PRODUCT_NAME, "Default string"),
  112. DMI_MATCH(DMI_BIOS_DATE, "05/25/2017")
  113. }),
  114. /*
  115. * The GPD win/pocket have a PCI wifi card, but its DSDT has the SDIO
  116. * mmc controller enabled and that has a child-device which _PS3
  117. * method sets a GPIO causing the PCI wifi card to turn off.
  118. * See above remark about uniqueness of the DMI match.
  119. */
  120. NOT_PRESENT_ENTRY_PATH("\\_SB_.PCI0.SDHB.BRC1", ATOM_AIRMONT, {
  121. DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
  122. DMI_EXACT_MATCH(DMI_BOARD_NAME, "Default string"),
  123. DMI_EXACT_MATCH(DMI_BOARD_SERIAL, "Default string"),
  124. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Default string"),
  125. }),
  126. };
  127. bool acpi_device_override_status(struct acpi_device *adev, unsigned long long *status)
  128. {
  129. bool ret = false;
  130. unsigned int i;
  131. for (i = 0; i < ARRAY_SIZE(override_status_ids); i++) {
  132. if (!x86_match_cpu(override_status_ids[i].cpu_ids))
  133. continue;
  134. if (override_status_ids[i].dmi_ids[0].matches[0].slot &&
  135. !dmi_check_system(override_status_ids[i].dmi_ids))
  136. continue;
  137. if (override_status_ids[i].path) {
  138. struct acpi_buffer path = { ACPI_ALLOCATE_BUFFER, NULL };
  139. bool match;
  140. if (acpi_get_name(adev->handle, ACPI_FULL_PATHNAME, &path))
  141. continue;
  142. match = strcmp((char *)path.pointer, override_status_ids[i].path) == 0;
  143. kfree(path.pointer);
  144. if (!match)
  145. continue;
  146. } else {
  147. if (acpi_match_device_ids(adev, override_status_ids[i].hid))
  148. continue;
  149. if (!adev->pnp.unique_id ||
  150. strcmp(adev->pnp.unique_id, override_status_ids[i].uid))
  151. continue;
  152. }
  153. *status = override_status_ids[i].status;
  154. ret = true;
  155. break;
  156. }
  157. return ret;
  158. }