intel_acpi.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Intel ACPI functions
  4. *
  5. * _DSM related code stolen from nouveau_acpi.c.
  6. */
  7. #include <linux/pci.h>
  8. #include <linux/acpi.h>
  9. #include <drm/drmP.h>
  10. #include "i915_drv.h"
  11. #define INTEL_DSM_REVISION_ID 1 /* For Calpella anyway... */
  12. #define INTEL_DSM_FN_PLATFORM_MUX_INFO 1 /* No args */
  13. static const guid_t intel_dsm_guid =
  14. GUID_INIT(0x7ed873d3, 0xc2d0, 0x4e4f,
  15. 0xa8, 0x54, 0x0f, 0x13, 0x17, 0xb0, 0x1c, 0x2c);
  16. static char *intel_dsm_port_name(u8 id)
  17. {
  18. switch (id) {
  19. case 0:
  20. return "Reserved";
  21. case 1:
  22. return "Analog VGA";
  23. case 2:
  24. return "LVDS";
  25. case 3:
  26. return "Reserved";
  27. case 4:
  28. return "HDMI/DVI_B";
  29. case 5:
  30. return "HDMI/DVI_C";
  31. case 6:
  32. return "HDMI/DVI_D";
  33. case 7:
  34. return "DisplayPort_A";
  35. case 8:
  36. return "DisplayPort_B";
  37. case 9:
  38. return "DisplayPort_C";
  39. case 0xa:
  40. return "DisplayPort_D";
  41. case 0xb:
  42. case 0xc:
  43. case 0xd:
  44. return "Reserved";
  45. case 0xe:
  46. return "WiDi";
  47. default:
  48. return "bad type";
  49. }
  50. }
  51. static char *intel_dsm_mux_type(u8 type)
  52. {
  53. switch (type) {
  54. case 0:
  55. return "unknown";
  56. case 1:
  57. return "No MUX, iGPU only";
  58. case 2:
  59. return "No MUX, dGPU only";
  60. case 3:
  61. return "MUXed between iGPU and dGPU";
  62. default:
  63. return "bad type";
  64. }
  65. }
  66. static void intel_dsm_platform_mux_info(acpi_handle dhandle)
  67. {
  68. int i;
  69. union acpi_object *pkg, *connector_count;
  70. pkg = acpi_evaluate_dsm_typed(dhandle, &intel_dsm_guid,
  71. INTEL_DSM_REVISION_ID, INTEL_DSM_FN_PLATFORM_MUX_INFO,
  72. NULL, ACPI_TYPE_PACKAGE);
  73. if (!pkg) {
  74. DRM_DEBUG_DRIVER("failed to evaluate _DSM\n");
  75. return;
  76. }
  77. connector_count = &pkg->package.elements[0];
  78. DRM_DEBUG_DRIVER("MUX info connectors: %lld\n",
  79. (unsigned long long)connector_count->integer.value);
  80. for (i = 1; i < pkg->package.count; i++) {
  81. union acpi_object *obj = &pkg->package.elements[i];
  82. union acpi_object *connector_id = &obj->package.elements[0];
  83. union acpi_object *info = &obj->package.elements[1];
  84. DRM_DEBUG_DRIVER("Connector id: 0x%016llx\n",
  85. (unsigned long long)connector_id->integer.value);
  86. DRM_DEBUG_DRIVER(" port id: %s\n",
  87. intel_dsm_port_name(info->buffer.pointer[0]));
  88. DRM_DEBUG_DRIVER(" display mux info: %s\n",
  89. intel_dsm_mux_type(info->buffer.pointer[1]));
  90. DRM_DEBUG_DRIVER(" aux/dc mux info: %s\n",
  91. intel_dsm_mux_type(info->buffer.pointer[2]));
  92. DRM_DEBUG_DRIVER(" hpd mux info: %s\n",
  93. intel_dsm_mux_type(info->buffer.pointer[3]));
  94. }
  95. ACPI_FREE(pkg);
  96. }
  97. static acpi_handle intel_dsm_pci_probe(struct pci_dev *pdev)
  98. {
  99. acpi_handle dhandle;
  100. dhandle = ACPI_HANDLE(&pdev->dev);
  101. if (!dhandle)
  102. return NULL;
  103. if (!acpi_check_dsm(dhandle, &intel_dsm_guid, INTEL_DSM_REVISION_ID,
  104. 1 << INTEL_DSM_FN_PLATFORM_MUX_INFO)) {
  105. DRM_DEBUG_KMS("no _DSM method for intel device\n");
  106. return NULL;
  107. }
  108. intel_dsm_platform_mux_info(dhandle);
  109. return dhandle;
  110. }
  111. static bool intel_dsm_detect(void)
  112. {
  113. acpi_handle dhandle = NULL;
  114. char acpi_method_name[255] = { 0 };
  115. struct acpi_buffer buffer = {sizeof(acpi_method_name), acpi_method_name};
  116. struct pci_dev *pdev = NULL;
  117. int vga_count = 0;
  118. while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev)) != NULL) {
  119. vga_count++;
  120. dhandle = intel_dsm_pci_probe(pdev) ?: dhandle;
  121. }
  122. if (vga_count == 2 && dhandle) {
  123. acpi_get_name(dhandle, ACPI_FULL_PATHNAME, &buffer);
  124. DRM_DEBUG_DRIVER("vga_switcheroo: detected DSM switching method %s handle\n",
  125. acpi_method_name);
  126. return true;
  127. }
  128. return false;
  129. }
  130. void intel_register_dsm_handler(void)
  131. {
  132. if (!intel_dsm_detect())
  133. return;
  134. }
  135. void intel_unregister_dsm_handler(void)
  136. {
  137. }