intel_acpi.c 3.6 KB

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