blob: 1bfac94adb34898ac6a461d405d464935fc02050 [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>
8#include <linux/vga_switcheroo.h>
9#include <acpi/acpi_drivers.h>
10
David Howells760285e2012-10-02 18:01:07 +010011#include <drm/drmP.h>
Ben Widawskyc43b5632012-04-16 14:07:40 -070012#include "i915_drv.h"
Jesse Barnes723bfd72010-10-07 16:01:13 -070013
14#define INTEL_DSM_REVISION_ID 1 /* For Calpella anyway... */
Jesse Barnes723bfd72010-10-07 16:01:13 -070015#define INTEL_DSM_FN_PLATFORM_MUX_INFO 1 /* No args */
16
17static struct intel_dsm_priv {
18 acpi_handle dhandle;
19} intel_dsm_priv;
20
21static const u8 intel_dsm_guid[] = {
22 0xd3, 0x73, 0xd8, 0x7e,
23 0xd0, 0xc2,
24 0x4f, 0x4e,
25 0xa8, 0x54,
26 0x0f, 0x13, 0x17, 0xb0, 0x1c, 0x2c
27};
28
Jesse Barnes723bfd72010-10-07 16:01:13 -070029static char *intel_dsm_port_name(u8 id)
30{
31 switch (id) {
32 case 0:
33 return "Reserved";
34 case 1:
35 return "Analog VGA";
36 case 2:
37 return "LVDS";
38 case 3:
39 return "Reserved";
40 case 4:
41 return "HDMI/DVI_B";
42 case 5:
43 return "HDMI/DVI_C";
44 case 6:
45 return "HDMI/DVI_D";
46 case 7:
47 return "DisplayPort_A";
48 case 8:
49 return "DisplayPort_B";
50 case 9:
51 return "DisplayPort_C";
52 case 0xa:
53 return "DisplayPort_D";
54 case 0xb:
55 case 0xc:
56 case 0xd:
57 return "Reserved";
58 case 0xe:
59 return "WiDi";
60 default:
61 return "bad type";
62 }
63}
64
65static char *intel_dsm_mux_type(u8 type)
66{
67 switch (type) {
68 case 0:
69 return "unknown";
70 case 1:
71 return "No MUX, iGPU only";
72 case 2:
73 return "No MUX, dGPU only";
74 case 3:
75 return "MUXed between iGPU and dGPU";
76 default:
77 return "bad type";
78 }
79}
80
81static void intel_dsm_platform_mux_info(void)
82{
Jiang Liud5c3d792013-12-19 20:38:20 +080083 int i;
84 union acpi_object *pkg, *connector_count;
Jesse Barnes723bfd72010-10-07 16:01:13 -070085
Jiang Liud5c3d792013-12-19 20:38:20 +080086 pkg = acpi_evaluate_dsm_typed(intel_dsm_priv.dhandle, intel_dsm_guid,
87 INTEL_DSM_REVISION_ID, INTEL_DSM_FN_PLATFORM_MUX_INFO,
88 NULL, ACPI_TYPE_PACKAGE);
89 if (!pkg) {
90 DRM_DEBUG_DRIVER("failed to evaluate _DSM\n");
91 return;
Jesse Barnes723bfd72010-10-07 16:01:13 -070092 }
93
Jiang Liud5c3d792013-12-19 20:38:20 +080094 connector_count = &pkg->package.elements[0];
95 DRM_DEBUG_DRIVER("MUX info connectors: %lld\n",
96 (unsigned long long)connector_count->integer.value);
97 for (i = 1; i < pkg->package.count; i++) {
98 union acpi_object *obj = &pkg->package.elements[i];
99 union acpi_object *connector_id = &obj->package.elements[0];
100 union acpi_object *info = &obj->package.elements[1];
101 DRM_DEBUG_DRIVER("Connector id: 0x%016llx\n",
102 (unsigned long long)connector_id->integer.value);
103 DRM_DEBUG_DRIVER(" port id: %s\n",
104 intel_dsm_port_name(info->buffer.pointer[0]));
105 DRM_DEBUG_DRIVER(" display mux info: %s\n",
106 intel_dsm_mux_type(info->buffer.pointer[1]));
107 DRM_DEBUG_DRIVER(" aux/dc mux info: %s\n",
108 intel_dsm_mux_type(info->buffer.pointer[2]));
109 DRM_DEBUG_DRIVER(" hpd mux info: %s\n",
110 intel_dsm_mux_type(info->buffer.pointer[3]));
Jesse Barnes723bfd72010-10-07 16:01:13 -0700111 }
112
Jiang Liud5c3d792013-12-19 20:38:20 +0800113 ACPI_FREE(pkg);
Jesse Barnes723bfd72010-10-07 16:01:13 -0700114}
115
Jesse Barnes723bfd72010-10-07 16:01:13 -0700116static bool intel_dsm_pci_probe(struct pci_dev *pdev)
117{
Zhang Rui2a3ca142013-09-03 08:31:59 +0800118 acpi_handle dhandle;
Jesse Barnes723bfd72010-10-07 16:01:13 -0700119
Rafael J. Wysocki3a83f992013-11-14 23:17:21 +0100120 dhandle = ACPI_HANDLE(&pdev->dev);
Jesse Barnes723bfd72010-10-07 16:01:13 -0700121 if (!dhandle)
122 return false;
123
Jiang Liud5c3d792013-12-19 20:38:20 +0800124 if (!acpi_check_dsm(dhandle, intel_dsm_guid, INTEL_DSM_REVISION_ID,
125 1 << INTEL_DSM_FN_PLATFORM_MUX_INFO)) {
Jesse Barnes723bfd72010-10-07 16:01:13 -0700126 DRM_DEBUG_KMS("no _DSM method for intel device\n");
127 return false;
128 }
129
Jesse Barnes723bfd72010-10-07 16:01:13 -0700130 intel_dsm_priv.dhandle = dhandle;
Jesse Barnes723bfd72010-10-07 16:01:13 -0700131 intel_dsm_platform_mux_info();
Jiang Liud5c3d792013-12-19 20:38:20 +0800132
Jesse Barnes723bfd72010-10-07 16:01:13 -0700133 return true;
134}
135
136static bool intel_dsm_detect(void)
137{
138 char acpi_method_name[255] = { 0 };
139 struct acpi_buffer buffer = {sizeof(acpi_method_name), acpi_method_name};
140 struct pci_dev *pdev = NULL;
141 bool has_dsm = false;
142 int vga_count = 0;
143
144 while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev)) != NULL) {
145 vga_count++;
146 has_dsm |= intel_dsm_pci_probe(pdev);
147 }
148
149 if (vga_count == 2 && has_dsm) {
150 acpi_get_name(intel_dsm_priv.dhandle, ACPI_FULL_PATHNAME, &buffer);
151 DRM_DEBUG_DRIVER("VGA switcheroo: detected DSM switching method %s handle\n",
152 acpi_method_name);
153 return true;
154 }
155
156 return false;
157}
158
159void intel_register_dsm_handler(void)
160{
161 if (!intel_dsm_detect())
162 return;
Jesse Barnes723bfd72010-10-07 16:01:13 -0700163}
164
165void intel_unregister_dsm_handler(void)
166{
Jesse Barnes723bfd72010-10-07 16:01:13 -0700167}