intel_acpi.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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 <acpi/acpi_drivers.h>
  10. #include "drmP.h"
  11. #define INTEL_DSM_REVISION_ID 1 /* For Calpella anyway... */
  12. #define INTEL_DSM_FN_SUPPORTED_FUNCTIONS 0 /* No args */
  13. #define INTEL_DSM_FN_PLATFORM_MUX_INFO 1 /* No args */
  14. static struct intel_dsm_priv {
  15. acpi_handle dhandle;
  16. } intel_dsm_priv;
  17. static const u8 intel_dsm_guid[] = {
  18. 0xd3, 0x73, 0xd8, 0x7e,
  19. 0xd0, 0xc2,
  20. 0x4f, 0x4e,
  21. 0xa8, 0x54,
  22. 0x0f, 0x13, 0x17, 0xb0, 0x1c, 0x2c
  23. };
  24. static int intel_dsm(acpi_handle handle, int func, int arg)
  25. {
  26. struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
  27. struct acpi_object_list input;
  28. union acpi_object params[4];
  29. union acpi_object *obj;
  30. u32 result;
  31. int ret = 0;
  32. input.count = 4;
  33. input.pointer = params;
  34. params[0].type = ACPI_TYPE_BUFFER;
  35. params[0].buffer.length = sizeof(intel_dsm_guid);
  36. params[0].buffer.pointer = (char *)intel_dsm_guid;
  37. params[1].type = ACPI_TYPE_INTEGER;
  38. params[1].integer.value = INTEL_DSM_REVISION_ID;
  39. params[2].type = ACPI_TYPE_INTEGER;
  40. params[2].integer.value = func;
  41. params[3].type = ACPI_TYPE_INTEGER;
  42. params[3].integer.value = arg;
  43. ret = acpi_evaluate_object(handle, "_DSM", &input, &output);
  44. if (ret) {
  45. DRM_DEBUG_DRIVER("failed to evaluate _DSM: %d\n", ret);
  46. return ret;
  47. }
  48. obj = (union acpi_object *)output.pointer;
  49. result = 0;
  50. switch (obj->type) {
  51. case ACPI_TYPE_INTEGER:
  52. result = obj->integer.value;
  53. break;
  54. case ACPI_TYPE_BUFFER:
  55. if (obj->buffer.length == 4) {
  56. result = (obj->buffer.pointer[0] |
  57. (obj->buffer.pointer[1] << 8) |
  58. (obj->buffer.pointer[2] << 16) |
  59. (obj->buffer.pointer[3] << 24));
  60. break;
  61. }
  62. default:
  63. ret = -EINVAL;
  64. break;
  65. }
  66. if (result == 0x80000002)
  67. ret = -ENODEV;
  68. kfree(output.pointer);
  69. return ret;
  70. }
  71. static char *intel_dsm_port_name(u8 id)
  72. {
  73. switch (id) {
  74. case 0:
  75. return "Reserved";
  76. case 1:
  77. return "Analog VGA";
  78. case 2:
  79. return "LVDS";
  80. case 3:
  81. return "Reserved";
  82. case 4:
  83. return "HDMI/DVI_B";
  84. case 5:
  85. return "HDMI/DVI_C";
  86. case 6:
  87. return "HDMI/DVI_D";
  88. case 7:
  89. return "DisplayPort_A";
  90. case 8:
  91. return "DisplayPort_B";
  92. case 9:
  93. return "DisplayPort_C";
  94. case 0xa:
  95. return "DisplayPort_D";
  96. case 0xb:
  97. case 0xc:
  98. case 0xd:
  99. return "Reserved";
  100. case 0xe:
  101. return "WiDi";
  102. default:
  103. return "bad type";
  104. }
  105. }
  106. static char *intel_dsm_mux_type(u8 type)
  107. {
  108. switch (type) {
  109. case 0:
  110. return "unknown";
  111. case 1:
  112. return "No MUX, iGPU only";
  113. case 2:
  114. return "No MUX, dGPU only";
  115. case 3:
  116. return "MUXed between iGPU and dGPU";
  117. default:
  118. return "bad type";
  119. }
  120. }
  121. static void intel_dsm_platform_mux_info(void)
  122. {
  123. struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
  124. struct acpi_object_list input;
  125. union acpi_object params[4];
  126. union acpi_object *pkg;
  127. int i, ret;
  128. input.count = 4;
  129. input.pointer = params;
  130. params[0].type = ACPI_TYPE_BUFFER;
  131. params[0].buffer.length = sizeof(intel_dsm_guid);
  132. params[0].buffer.pointer = (char *)intel_dsm_guid;
  133. params[1].type = ACPI_TYPE_INTEGER;
  134. params[1].integer.value = INTEL_DSM_REVISION_ID;
  135. params[2].type = ACPI_TYPE_INTEGER;
  136. params[2].integer.value = INTEL_DSM_FN_PLATFORM_MUX_INFO;
  137. params[3].type = ACPI_TYPE_INTEGER;
  138. params[3].integer.value = 0;
  139. ret = acpi_evaluate_object(intel_dsm_priv.dhandle, "_DSM", &input,
  140. &output);
  141. if (ret) {
  142. DRM_DEBUG_DRIVER("failed to evaluate _DSM: %d\n", ret);
  143. goto out;
  144. }
  145. pkg = (union acpi_object *)output.pointer;
  146. if (pkg->type == ACPI_TYPE_PACKAGE) {
  147. union acpi_object *connector_count = &pkg->package.elements[0];
  148. DRM_DEBUG_DRIVER("MUX info connectors: %lld\n",
  149. (unsigned long long)connector_count->integer.value);
  150. for (i = 1; i < pkg->package.count; i++) {
  151. union acpi_object *obj = &pkg->package.elements[i];
  152. union acpi_object *connector_id =
  153. &obj->package.elements[0];
  154. union acpi_object *info = &obj->package.elements[1];
  155. DRM_DEBUG_DRIVER("Connector id: 0x%016llx\n",
  156. (unsigned long long)connector_id->integer.value);
  157. DRM_DEBUG_DRIVER(" port id: %s\n",
  158. intel_dsm_port_name(info->buffer.pointer[0]));
  159. DRM_DEBUG_DRIVER(" display mux info: %s\n",
  160. intel_dsm_mux_type(info->buffer.pointer[1]));
  161. DRM_DEBUG_DRIVER(" aux/dc mux info: %s\n",
  162. intel_dsm_mux_type(info->buffer.pointer[2]));
  163. DRM_DEBUG_DRIVER(" hpd mux info: %s\n",
  164. intel_dsm_mux_type(info->buffer.pointer[3]));
  165. }
  166. } else {
  167. DRM_ERROR("MUX INFO call failed\n");
  168. }
  169. out:
  170. kfree(output.pointer);
  171. }
  172. static bool intel_dsm_pci_probe(struct pci_dev *pdev)
  173. {
  174. acpi_handle dhandle, intel_handle;
  175. acpi_status status;
  176. int ret;
  177. dhandle = DEVICE_ACPI_HANDLE(&pdev->dev);
  178. if (!dhandle)
  179. return false;
  180. status = acpi_get_handle(dhandle, "_DSM", &intel_handle);
  181. if (ACPI_FAILURE(status)) {
  182. DRM_DEBUG_KMS("no _DSM method for intel device\n");
  183. return false;
  184. }
  185. ret = intel_dsm(dhandle, INTEL_DSM_FN_SUPPORTED_FUNCTIONS, 0);
  186. if (ret < 0) {
  187. DRM_DEBUG_KMS("failed to get supported _DSM functions\n");
  188. return false;
  189. }
  190. intel_dsm_priv.dhandle = dhandle;
  191. intel_dsm_platform_mux_info();
  192. return true;
  193. }
  194. static bool intel_dsm_detect(void)
  195. {
  196. char acpi_method_name[255] = { 0 };
  197. struct acpi_buffer buffer = {sizeof(acpi_method_name), acpi_method_name};
  198. struct pci_dev *pdev = NULL;
  199. bool has_dsm = false;
  200. int vga_count = 0;
  201. while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev)) != NULL) {
  202. vga_count++;
  203. has_dsm |= intel_dsm_pci_probe(pdev);
  204. }
  205. if (vga_count == 2 && has_dsm) {
  206. acpi_get_name(intel_dsm_priv.dhandle, ACPI_FULL_PATHNAME, &buffer);
  207. DRM_DEBUG_DRIVER("VGA switcheroo: detected DSM switching method %s handle\n",
  208. acpi_method_name);
  209. return true;
  210. }
  211. return false;
  212. }
  213. void intel_register_dsm_handler(void)
  214. {
  215. if (!intel_dsm_detect())
  216. return;
  217. }
  218. void intel_unregister_dsm_handler(void)
  219. {
  220. }