Merge tag 'meminit-v5.3-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/kees...
[linux-2.6-microblaze.git] / drivers / gpu / drm / i915 / display / intel_acpi.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Intel ACPI functions
4  *
5  * _DSM related code stolen from nouveau_acpi.c.
6  */
7
8 #include <linux/pci.h>
9 #include <linux/acpi.h>
10
11 #include "i915_drv.h"
12 #include "intel_acpi.h"
13
14 #define INTEL_DSM_REVISION_ID 1 /* For Calpella anyway... */
15 #define INTEL_DSM_FN_PLATFORM_MUX_INFO 1 /* No args */
16
17 static const guid_t intel_dsm_guid =
18         GUID_INIT(0x7ed873d3, 0xc2d0, 0x4e4f,
19                   0xa8, 0x54, 0x0f, 0x13, 0x17, 0xb0, 0x1c, 0x2c);
20
21 static char *intel_dsm_port_name(u8 id)
22 {
23         switch (id) {
24         case 0:
25                 return "Reserved";
26         case 1:
27                 return "Analog VGA";
28         case 2:
29                 return "LVDS";
30         case 3:
31                 return "Reserved";
32         case 4:
33                 return "HDMI/DVI_B";
34         case 5:
35                 return "HDMI/DVI_C";
36         case 6:
37                 return "HDMI/DVI_D";
38         case 7:
39                 return "DisplayPort_A";
40         case 8:
41                 return "DisplayPort_B";
42         case 9:
43                 return "DisplayPort_C";
44         case 0xa:
45                 return "DisplayPort_D";
46         case 0xb:
47         case 0xc:
48         case 0xd:
49                 return "Reserved";
50         case 0xe:
51                 return "WiDi";
52         default:
53                 return "bad type";
54         }
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
73 static void intel_dsm_platform_mux_info(acpi_handle dhandle)
74 {
75         int i;
76         union acpi_object *pkg, *connector_count;
77
78         pkg = acpi_evaluate_dsm_typed(dhandle, &intel_dsm_guid,
79                         INTEL_DSM_REVISION_ID, INTEL_DSM_FN_PLATFORM_MUX_INFO,
80                         NULL, ACPI_TYPE_PACKAGE);
81         if (!pkg) {
82                 DRM_DEBUG_DRIVER("failed to evaluate _DSM\n");
83                 return;
84         }
85
86         connector_count = &pkg->package.elements[0];
87         DRM_DEBUG_DRIVER("MUX info connectors: %lld\n",
88                   (unsigned long long)connector_count->integer.value);
89         for (i = 1; i < pkg->package.count; i++) {
90                 union acpi_object *obj = &pkg->package.elements[i];
91                 union acpi_object *connector_id = &obj->package.elements[0];
92                 union acpi_object *info = &obj->package.elements[1];
93                 DRM_DEBUG_DRIVER("Connector id: 0x%016llx\n",
94                           (unsigned long long)connector_id->integer.value);
95                 DRM_DEBUG_DRIVER("  port id: %s\n",
96                        intel_dsm_port_name(info->buffer.pointer[0]));
97                 DRM_DEBUG_DRIVER("  display mux info: %s\n",
98                        intel_dsm_mux_type(info->buffer.pointer[1]));
99                 DRM_DEBUG_DRIVER("  aux/dc mux info: %s\n",
100                        intel_dsm_mux_type(info->buffer.pointer[2]));
101                 DRM_DEBUG_DRIVER("  hpd mux info: %s\n",
102                        intel_dsm_mux_type(info->buffer.pointer[3]));
103         }
104
105         ACPI_FREE(pkg);
106 }
107
108 static acpi_handle intel_dsm_pci_probe(struct pci_dev *pdev)
109 {
110         acpi_handle dhandle;
111
112         dhandle = ACPI_HANDLE(&pdev->dev);
113         if (!dhandle)
114                 return NULL;
115
116         if (!acpi_check_dsm(dhandle, &intel_dsm_guid, INTEL_DSM_REVISION_ID,
117                             1 << INTEL_DSM_FN_PLATFORM_MUX_INFO)) {
118                 DRM_DEBUG_KMS("no _DSM method for intel device\n");
119                 return NULL;
120         }
121
122         intel_dsm_platform_mux_info(dhandle);
123
124         return dhandle;
125 }
126
127 static bool intel_dsm_detect(void)
128 {
129         acpi_handle dhandle = NULL;
130         char acpi_method_name[255] = { 0 };
131         struct acpi_buffer buffer = {sizeof(acpi_method_name), acpi_method_name};
132         struct pci_dev *pdev = NULL;
133         int vga_count = 0;
134
135         while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev)) != NULL) {
136                 vga_count++;
137                 dhandle = intel_dsm_pci_probe(pdev) ?: dhandle;
138         }
139
140         if (vga_count == 2 && dhandle) {
141                 acpi_get_name(dhandle, ACPI_FULL_PATHNAME, &buffer);
142                 DRM_DEBUG_DRIVER("vga_switcheroo: detected DSM switching method %s handle\n",
143                                  acpi_method_name);
144                 return true;
145         }
146
147         return false;
148 }
149
150 void intel_register_dsm_handler(void)
151 {
152         if (!intel_dsm_detect())
153                 return;
154 }
155
156 void intel_unregister_dsm_handler(void)
157 {
158 }