blob: 42fb436f6cdc9dc410681d4af0d5f4148b58dc07 [file] [log] [blame]
Jesse Barnes723bfd72010-10-07 16:01:13 -07001/*
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>
David Howells760285e2012-10-02 18:01:07 +01008#include <drm/drmP.h>
Ben Widawskyc43b5632012-04-16 14:07:40 -07009#include "i915_drv.h"
Jesse Barnes723bfd72010-10-07 16:01:13 -070010
11#define INTEL_DSM_REVISION_ID 1 /* For Calpella anyway... */
Jesse Barnes723bfd72010-10-07 16:01:13 -070012#define INTEL_DSM_FN_PLATFORM_MUX_INFO 1 /* No args */
13
14static struct intel_dsm_priv {
15 acpi_handle dhandle;
16} intel_dsm_priv;
17
Andy Shevchenko94116f82017-06-05 19:40:46 +030018static const guid_t intel_dsm_guid =
19 GUID_INIT(0x7ed873d3, 0xc2d0, 0x4e4f,
20 0xa8, 0x54, 0x0f, 0x13, 0x17, 0xb0, 0x1c, 0x2c);
Jesse Barnes723bfd72010-10-07 16:01:13 -070021
Jesse Barnes723bfd72010-10-07 16:01:13 -070022static 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
58static 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
74static void intel_dsm_platform_mux_info(void)
75{
Jiang Liud5c3d792013-12-19 20:38:20 +080076 int i;
77 union acpi_object *pkg, *connector_count;
Jesse Barnes723bfd72010-10-07 16:01:13 -070078
Andy Shevchenko94116f82017-06-05 19:40:46 +030079 pkg = acpi_evaluate_dsm_typed(intel_dsm_priv.dhandle, &intel_dsm_guid,
Jiang Liud5c3d792013-12-19 20:38:20 +080080 INTEL_DSM_REVISION_ID, INTEL_DSM_FN_PLATFORM_MUX_INFO,
81 NULL, ACPI_TYPE_PACKAGE);
82 if (!pkg) {
83 DRM_DEBUG_DRIVER("failed to evaluate _DSM\n");
84 return;
Jesse Barnes723bfd72010-10-07 16:01:13 -070085 }
86
Jiang Liud5c3d792013-12-19 20:38:20 +080087 connector_count = &pkg->package.elements[0];
88 DRM_DEBUG_DRIVER("MUX info connectors: %lld\n",
89 (unsigned long long)connector_count->integer.value);
90 for (i = 1; i < pkg->package.count; i++) {
91 union acpi_object *obj = &pkg->package.elements[i];
92 union acpi_object *connector_id = &obj->package.elements[0];
93 union acpi_object *info = &obj->package.elements[1];
94 DRM_DEBUG_DRIVER("Connector id: 0x%016llx\n",
95 (unsigned long long)connector_id->integer.value);
96 DRM_DEBUG_DRIVER(" port id: %s\n",
97 intel_dsm_port_name(info->buffer.pointer[0]));
98 DRM_DEBUG_DRIVER(" display mux info: %s\n",
99 intel_dsm_mux_type(info->buffer.pointer[1]));
100 DRM_DEBUG_DRIVER(" aux/dc mux info: %s\n",
101 intel_dsm_mux_type(info->buffer.pointer[2]));
102 DRM_DEBUG_DRIVER(" hpd mux info: %s\n",
103 intel_dsm_mux_type(info->buffer.pointer[3]));
Jesse Barnes723bfd72010-10-07 16:01:13 -0700104 }
105
Jiang Liud5c3d792013-12-19 20:38:20 +0800106 ACPI_FREE(pkg);
Jesse Barnes723bfd72010-10-07 16:01:13 -0700107}
108
Jesse Barnes723bfd72010-10-07 16:01:13 -0700109static bool intel_dsm_pci_probe(struct pci_dev *pdev)
110{
Zhang Rui2a3ca142013-09-03 08:31:59 +0800111 acpi_handle dhandle;
Jesse Barnes723bfd72010-10-07 16:01:13 -0700112
Rafael J. Wysocki3a83f992013-11-14 23:17:21 +0100113 dhandle = ACPI_HANDLE(&pdev->dev);
Jesse Barnes723bfd72010-10-07 16:01:13 -0700114 if (!dhandle)
115 return false;
116
Andy Shevchenko94116f82017-06-05 19:40:46 +0300117 if (!acpi_check_dsm(dhandle, &intel_dsm_guid, INTEL_DSM_REVISION_ID,
Jiang Liud5c3d792013-12-19 20:38:20 +0800118 1 << INTEL_DSM_FN_PLATFORM_MUX_INFO)) {
Jesse Barnes723bfd72010-10-07 16:01:13 -0700119 DRM_DEBUG_KMS("no _DSM method for intel device\n");
120 return false;
121 }
122
Jesse Barnes723bfd72010-10-07 16:01:13 -0700123 intel_dsm_priv.dhandle = dhandle;
Jesse Barnes723bfd72010-10-07 16:01:13 -0700124 intel_dsm_platform_mux_info();
Jiang Liud5c3d792013-12-19 20:38:20 +0800125
Jesse Barnes723bfd72010-10-07 16:01:13 -0700126 return true;
127}
128
129static bool intel_dsm_detect(void)
130{
131 char acpi_method_name[255] = { 0 };
132 struct acpi_buffer buffer = {sizeof(acpi_method_name), acpi_method_name};
133 struct pci_dev *pdev = NULL;
134 bool has_dsm = false;
135 int vga_count = 0;
136
137 while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev)) != NULL) {
138 vga_count++;
139 has_dsm |= intel_dsm_pci_probe(pdev);
140 }
141
142 if (vga_count == 2 && has_dsm) {
143 acpi_get_name(intel_dsm_priv.dhandle, ACPI_FULL_PATHNAME, &buffer);
Lukas Wunner5389e912015-09-04 21:06:15 +0200144 DRM_DEBUG_DRIVER("vga_switcheroo: detected DSM switching method %s handle\n",
Jesse Barnes723bfd72010-10-07 16:01:13 -0700145 acpi_method_name);
146 return true;
147 }
148
149 return false;
150}
151
152void intel_register_dsm_handler(void)
153{
154 if (!intel_dsm_detect())
155 return;
Jesse Barnes723bfd72010-10-07 16:01:13 -0700156}
157
158void intel_unregister_dsm_handler(void)
159{
Jesse Barnes723bfd72010-10-07 16:01:13 -0700160}