intel_acpi.c 3.6 KB

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