1 // SPDX-License-Identifier: GPL-2.0
5 * _DSM related code stolen from nouveau_acpi.c.
9 #include <linux/acpi.h>
12 #include "intel_acpi.h"
13 #include "intel_display_types.h"
15 #define INTEL_DSM_REVISION_ID 1 /* For Calpella anyway... */
16 #define INTEL_DSM_FN_PLATFORM_MUX_INFO 1 /* No args */
18 static const guid_t intel_dsm_guid =
19 GUID_INIT(0x7ed873d3, 0xc2d0, 0x4e4f,
20 0xa8, 0x54, 0x0f, 0x13, 0x17, 0xb0, 0x1c, 0x2c);
22 #define INTEL_DSM_FN_GET_BIOS_DATA_FUNCS_SUPPORTED 0 /* No args */
24 static const guid_t intel_dsm_guid2 =
25 GUID_INIT(0x3e5b41c6, 0xeb1d, 0x4260,
26 0x9d, 0x15, 0xc7, 0x1f, 0xba, 0xda, 0xe4, 0x14);
28 static char *intel_dsm_port_name(u8 id)
46 return "DisplayPort_A";
48 return "DisplayPort_B";
50 return "DisplayPort_C";
52 return "DisplayPort_D";
64 static char *intel_dsm_mux_type(u8 type)
70 return "No MUX, iGPU only";
72 return "No MUX, dGPU only";
74 return "MUXed between iGPU and dGPU";
80 static void intel_dsm_platform_mux_info(acpi_handle dhandle)
83 union acpi_object *pkg, *connector_count;
85 pkg = acpi_evaluate_dsm_typed(dhandle, &intel_dsm_guid,
86 INTEL_DSM_REVISION_ID, INTEL_DSM_FN_PLATFORM_MUX_INFO,
87 NULL, ACPI_TYPE_PACKAGE);
89 DRM_DEBUG_DRIVER("failed to evaluate _DSM\n");
93 if (!pkg->package.count) {
94 DRM_DEBUG_DRIVER("no connection in _DSM\n");
98 connector_count = &pkg->package.elements[0];
99 DRM_DEBUG_DRIVER("MUX info connectors: %lld\n",
100 (unsigned long long)connector_count->integer.value);
101 for (i = 1; i < pkg->package.count; i++) {
102 union acpi_object *obj = &pkg->package.elements[i];
103 union acpi_object *connector_id;
104 union acpi_object *info;
106 if (obj->type != ACPI_TYPE_PACKAGE || obj->package.count < 2) {
107 DRM_DEBUG_DRIVER("Invalid object for MUX #%d\n", i);
111 connector_id = &obj->package.elements[0];
112 info = &obj->package.elements[1];
113 if (info->type != ACPI_TYPE_BUFFER || info->buffer.length < 4) {
114 DRM_DEBUG_DRIVER("Invalid info for MUX obj #%d\n", i);
118 DRM_DEBUG_DRIVER("Connector id: 0x%016llx\n",
119 (unsigned long long)connector_id->integer.value);
120 DRM_DEBUG_DRIVER(" port id: %s\n",
121 intel_dsm_port_name(info->buffer.pointer[0]));
122 DRM_DEBUG_DRIVER(" display mux info: %s\n",
123 intel_dsm_mux_type(info->buffer.pointer[1]));
124 DRM_DEBUG_DRIVER(" aux/dc mux info: %s\n",
125 intel_dsm_mux_type(info->buffer.pointer[2]));
126 DRM_DEBUG_DRIVER(" hpd mux info: %s\n",
127 intel_dsm_mux_type(info->buffer.pointer[3]));
133 static acpi_handle intel_dsm_pci_probe(struct pci_dev *pdev)
137 dhandle = ACPI_HANDLE(&pdev->dev);
141 if (!acpi_check_dsm(dhandle, &intel_dsm_guid, INTEL_DSM_REVISION_ID,
142 1 << INTEL_DSM_FN_PLATFORM_MUX_INFO)) {
143 DRM_DEBUG_KMS("no _DSM method for intel device\n");
147 intel_dsm_platform_mux_info(dhandle);
152 static bool intel_dsm_detect(void)
154 acpi_handle dhandle = NULL;
155 char acpi_method_name[255] = { 0 };
156 struct acpi_buffer buffer = {sizeof(acpi_method_name), acpi_method_name};
157 struct pci_dev *pdev = NULL;
160 while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev)) != NULL) {
162 dhandle = intel_dsm_pci_probe(pdev) ?: dhandle;
165 if (vga_count == 2 && dhandle) {
166 acpi_get_name(dhandle, ACPI_FULL_PATHNAME, &buffer);
167 DRM_DEBUG_DRIVER("vga_switcheroo: detected DSM switching method %s handle\n",
175 void intel_register_dsm_handler(void)
177 if (!intel_dsm_detect())
181 void intel_unregister_dsm_handler(void)
185 void intel_dsm_get_bios_data_funcs_supported(struct drm_i915_private *i915)
187 struct pci_dev *pdev = to_pci_dev(i915->drm.dev);
189 union acpi_object *obj;
191 dhandle = ACPI_HANDLE(&pdev->dev);
195 obj = acpi_evaluate_dsm(dhandle, &intel_dsm_guid2, INTEL_DSM_REVISION_ID,
196 INTEL_DSM_FN_GET_BIOS_DATA_FUNCS_SUPPORTED, NULL);
202 * ACPI Specification, Revision 5.0, Appendix B.3.2 _DOD (Enumerate All Devices
203 * Attached to the Display Adapter).
205 #define ACPI_DISPLAY_INDEX_SHIFT 0
206 #define ACPI_DISPLAY_INDEX_MASK (0xf << 0)
207 #define ACPI_DISPLAY_PORT_ATTACHMENT_SHIFT 4
208 #define ACPI_DISPLAY_PORT_ATTACHMENT_MASK (0xf << 4)
209 #define ACPI_DISPLAY_TYPE_SHIFT 8
210 #define ACPI_DISPLAY_TYPE_MASK (0xf << 8)
211 #define ACPI_DISPLAY_TYPE_OTHER (0 << 8)
212 #define ACPI_DISPLAY_TYPE_VGA (1 << 8)
213 #define ACPI_DISPLAY_TYPE_TV (2 << 8)
214 #define ACPI_DISPLAY_TYPE_EXTERNAL_DIGITAL (3 << 8)
215 #define ACPI_DISPLAY_TYPE_INTERNAL_DIGITAL (4 << 8)
216 #define ACPI_VENDOR_SPECIFIC_SHIFT 12
217 #define ACPI_VENDOR_SPECIFIC_MASK (0xf << 12)
218 #define ACPI_BIOS_CAN_DETECT (1 << 16)
219 #define ACPI_DEPENDS_ON_VGA (1 << 17)
220 #define ACPI_PIPE_ID_SHIFT 18
221 #define ACPI_PIPE_ID_MASK (7 << 18)
222 #define ACPI_DEVICE_ID_SCHEME (1ULL << 31)
224 static u32 acpi_display_type(struct intel_connector *connector)
228 switch (connector->base.connector_type) {
229 case DRM_MODE_CONNECTOR_VGA:
230 case DRM_MODE_CONNECTOR_DVIA:
231 display_type = ACPI_DISPLAY_TYPE_VGA;
233 case DRM_MODE_CONNECTOR_Composite:
234 case DRM_MODE_CONNECTOR_SVIDEO:
235 case DRM_MODE_CONNECTOR_Component:
236 case DRM_MODE_CONNECTOR_9PinDIN:
237 case DRM_MODE_CONNECTOR_TV:
238 display_type = ACPI_DISPLAY_TYPE_TV;
240 case DRM_MODE_CONNECTOR_DVII:
241 case DRM_MODE_CONNECTOR_DVID:
242 case DRM_MODE_CONNECTOR_DisplayPort:
243 case DRM_MODE_CONNECTOR_HDMIA:
244 case DRM_MODE_CONNECTOR_HDMIB:
245 display_type = ACPI_DISPLAY_TYPE_EXTERNAL_DIGITAL;
247 case DRM_MODE_CONNECTOR_LVDS:
248 case DRM_MODE_CONNECTOR_eDP:
249 case DRM_MODE_CONNECTOR_DSI:
250 display_type = ACPI_DISPLAY_TYPE_INTERNAL_DIGITAL;
252 case DRM_MODE_CONNECTOR_Unknown:
253 case DRM_MODE_CONNECTOR_VIRTUAL:
254 display_type = ACPI_DISPLAY_TYPE_OTHER;
257 MISSING_CASE(connector->base.connector_type);
258 display_type = ACPI_DISPLAY_TYPE_OTHER;
265 void intel_acpi_device_id_update(struct drm_i915_private *dev_priv)
267 struct drm_device *drm_dev = &dev_priv->drm;
268 struct intel_connector *connector;
269 struct drm_connector_list_iter conn_iter;
270 u8 display_index[16] = {};
272 /* Populate the ACPI IDs for all connectors for a given drm_device */
273 drm_connector_list_iter_begin(drm_dev, &conn_iter);
274 for_each_intel_connector_iter(connector, &conn_iter) {
277 device_id = acpi_display_type(connector);
279 /* Use display type specific display index. */
280 type = (device_id & ACPI_DISPLAY_TYPE_MASK)
281 >> ACPI_DISPLAY_TYPE_SHIFT;
282 device_id |= display_index[type]++ << ACPI_DISPLAY_INDEX_SHIFT;
284 connector->acpi_device_id = device_id;
286 drm_connector_list_iter_end(&conn_iter);