intel_acpi.c 5.7 KB

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