| 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 | #include <acpi/video.h> | 
|---|
| 11 |  | 
|---|
| 12 | #include <drm/drm_print.h> | 
|---|
| 13 |  | 
|---|
| 14 | #include "i915_utils.h" | 
|---|
| 15 | #include "intel_acpi.h" | 
|---|
| 16 | #include "intel_display_core.h" | 
|---|
| 17 | #include "intel_display_types.h" | 
|---|
| 18 |  | 
|---|
| 19 | #define INTEL_DSM_REVISION_ID 1 /* For Calpella anyway... */ | 
|---|
| 20 | #define INTEL_DSM_FN_PLATFORM_MUX_INFO 1 /* No args */ | 
|---|
| 21 |  | 
|---|
| 22 | static const guid_t intel_dsm_guid = | 
|---|
| 23 | GUID_INIT(0x7ed873d3, 0xc2d0, 0x4e4f, | 
|---|
| 24 | 0xa8, 0x54, 0x0f, 0x13, 0x17, 0xb0, 0x1c, 0x2c); | 
|---|
| 25 |  | 
|---|
| 26 | #define INTEL_DSM_FN_GET_BIOS_DATA_FUNCS_SUPPORTED 0 /* No args */ | 
|---|
| 27 |  | 
|---|
| 28 | static const guid_t intel_dsm_guid2 = | 
|---|
| 29 | GUID_INIT(0x3e5b41c6, 0xeb1d, 0x4260, | 
|---|
| 30 | 0x9d, 0x15, 0xc7, 0x1f, 0xba, 0xda, 0xe4, 0x14); | 
|---|
| 31 |  | 
|---|
| 32 | static char *intel_dsm_port_name(u8 id) | 
|---|
| 33 | { | 
|---|
| 34 | switch (id) { | 
|---|
| 35 | case 0: | 
|---|
| 36 | return "Reserved"; | 
|---|
| 37 | case 1: | 
|---|
| 38 | return "Analog VGA"; | 
|---|
| 39 | case 2: | 
|---|
| 40 | return "LVDS"; | 
|---|
| 41 | case 3: | 
|---|
| 42 | return "Reserved"; | 
|---|
| 43 | case 4: | 
|---|
| 44 | return "HDMI/DVI_B"; | 
|---|
| 45 | case 5: | 
|---|
| 46 | return "HDMI/DVI_C"; | 
|---|
| 47 | case 6: | 
|---|
| 48 | return "HDMI/DVI_D"; | 
|---|
| 49 | case 7: | 
|---|
| 50 | return "DisplayPort_A"; | 
|---|
| 51 | case 8: | 
|---|
| 52 | return "DisplayPort_B"; | 
|---|
| 53 | case 9: | 
|---|
| 54 | return "DisplayPort_C"; | 
|---|
| 55 | case 0xa: | 
|---|
| 56 | return "DisplayPort_D"; | 
|---|
| 57 | case 0xb: | 
|---|
| 58 | case 0xc: | 
|---|
| 59 | case 0xd: | 
|---|
| 60 | return "Reserved"; | 
|---|
| 61 | case 0xe: | 
|---|
| 62 | return "WiDi"; | 
|---|
| 63 | default: | 
|---|
| 64 | return "bad type"; | 
|---|
| 65 | } | 
|---|
| 66 | } | 
|---|
| 67 |  | 
|---|
| 68 | static char *intel_dsm_mux_type(u8 type) | 
|---|
| 69 | { | 
|---|
| 70 | switch (type) { | 
|---|
| 71 | case 0: | 
|---|
| 72 | return "unknown"; | 
|---|
| 73 | case 1: | 
|---|
| 74 | return "No MUX, iGPU only"; | 
|---|
| 75 | case 2: | 
|---|
| 76 | return "No MUX, dGPU only"; | 
|---|
| 77 | case 3: | 
|---|
| 78 | return "MUXed between iGPU and dGPU"; | 
|---|
| 79 | default: | 
|---|
| 80 | return "bad type"; | 
|---|
| 81 | } | 
|---|
| 82 | } | 
|---|
| 83 |  | 
|---|
| 84 | static void intel_dsm_platform_mux_info(acpi_handle dhandle) | 
|---|
| 85 | { | 
|---|
| 86 | int i; | 
|---|
| 87 | union acpi_object *pkg, *connector_count; | 
|---|
| 88 |  | 
|---|
| 89 | pkg = acpi_evaluate_dsm_typed(handle: dhandle, guid: &intel_dsm_guid, | 
|---|
| 90 | INTEL_DSM_REVISION_ID, INTEL_DSM_FN_PLATFORM_MUX_INFO, | 
|---|
| 91 | NULL, ACPI_TYPE_PACKAGE); | 
|---|
| 92 | if (!pkg) { | 
|---|
| 93 | DRM_DEBUG_DRIVER( "failed to evaluate _DSM\n"); | 
|---|
| 94 | return; | 
|---|
| 95 | } | 
|---|
| 96 |  | 
|---|
| 97 | if (!pkg->package.count) { | 
|---|
| 98 | DRM_DEBUG_DRIVER( "no connection in _DSM\n"); | 
|---|
| 99 | return; | 
|---|
| 100 | } | 
|---|
| 101 |  | 
|---|
| 102 | connector_count = &pkg->package.elements[0]; | 
|---|
| 103 | DRM_DEBUG_DRIVER( "MUX info connectors: %lld\n", | 
|---|
| 104 | (unsigned long long)connector_count->integer.value); | 
|---|
| 105 | for (i = 1; i < pkg->package.count; i++) { | 
|---|
| 106 | union acpi_object *obj = &pkg->package.elements[i]; | 
|---|
| 107 | union acpi_object *connector_id; | 
|---|
| 108 | union acpi_object *info; | 
|---|
| 109 |  | 
|---|
| 110 | if (obj->type != ACPI_TYPE_PACKAGE || obj->package.count < 2) { | 
|---|
| 111 | DRM_DEBUG_DRIVER( "Invalid object for MUX #%d\n", i); | 
|---|
| 112 | continue; | 
|---|
| 113 | } | 
|---|
| 114 |  | 
|---|
| 115 | connector_id = &obj->package.elements[0]; | 
|---|
| 116 | info = &obj->package.elements[1]; | 
|---|
| 117 | if (info->type != ACPI_TYPE_BUFFER || info->buffer.length < 4) { | 
|---|
| 118 | DRM_DEBUG_DRIVER( "Invalid info for MUX obj #%d\n", i); | 
|---|
| 119 | continue; | 
|---|
| 120 | } | 
|---|
| 121 |  | 
|---|
| 122 | DRM_DEBUG_DRIVER( "Connector id: 0x%016llx\n", | 
|---|
| 123 | (unsigned long long)connector_id->integer.value); | 
|---|
| 124 | DRM_DEBUG_DRIVER( "  port id: %s\n", | 
|---|
| 125 | intel_dsm_port_name(info->buffer.pointer[0])); | 
|---|
| 126 | DRM_DEBUG_DRIVER( "  display mux info: %s\n", | 
|---|
| 127 | intel_dsm_mux_type(info->buffer.pointer[1])); | 
|---|
| 128 | DRM_DEBUG_DRIVER( "  aux/dc mux info: %s\n", | 
|---|
| 129 | intel_dsm_mux_type(info->buffer.pointer[2])); | 
|---|
| 130 | DRM_DEBUG_DRIVER( "  hpd mux info: %s\n", | 
|---|
| 131 | intel_dsm_mux_type(info->buffer.pointer[3])); | 
|---|
| 132 | } | 
|---|
| 133 |  | 
|---|
| 134 | ACPI_FREE(pkg); | 
|---|
| 135 | } | 
|---|
| 136 |  | 
|---|
| 137 | static acpi_handle intel_dsm_pci_probe(struct pci_dev *pdev) | 
|---|
| 138 | { | 
|---|
| 139 | acpi_handle dhandle; | 
|---|
| 140 |  | 
|---|
| 141 | dhandle = ACPI_HANDLE(&pdev->dev); | 
|---|
| 142 | if (!dhandle) | 
|---|
| 143 | return NULL; | 
|---|
| 144 |  | 
|---|
| 145 | if (!acpi_check_dsm(handle: dhandle, guid: &intel_dsm_guid, INTEL_DSM_REVISION_ID, | 
|---|
| 146 | funcs: 1 << INTEL_DSM_FN_PLATFORM_MUX_INFO)) { | 
|---|
| 147 | DRM_DEBUG_KMS( "no _DSM method for intel device\n"); | 
|---|
| 148 | return NULL; | 
|---|
| 149 | } | 
|---|
| 150 |  | 
|---|
| 151 | intel_dsm_platform_mux_info(dhandle); | 
|---|
| 152 |  | 
|---|
| 153 | return dhandle; | 
|---|
| 154 | } | 
|---|
| 155 |  | 
|---|
| 156 | static bool intel_dsm_detect(void) | 
|---|
| 157 | { | 
|---|
| 158 | acpi_handle dhandle = NULL; | 
|---|
| 159 | char acpi_method_name[255] = {}; | 
|---|
| 160 | struct acpi_buffer buffer = {sizeof(acpi_method_name), acpi_method_name}; | 
|---|
| 161 | struct pci_dev *pdev = NULL; | 
|---|
| 162 | int vga_count = 0; | 
|---|
| 163 |  | 
|---|
| 164 | while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, from: pdev)) != NULL) { | 
|---|
| 165 | vga_count++; | 
|---|
| 166 | dhandle = intel_dsm_pci_probe(pdev) ?: dhandle; | 
|---|
| 167 | } | 
|---|
| 168 |  | 
|---|
| 169 | if (vga_count == 2 && dhandle) { | 
|---|
| 170 | acpi_get_name(object: dhandle, ACPI_FULL_PATHNAME, ret_path_ptr: &buffer); | 
|---|
| 171 | DRM_DEBUG_DRIVER( "vga_switcheroo: detected DSM switching method %s handle\n", | 
|---|
| 172 | acpi_method_name); | 
|---|
| 173 | return true; | 
|---|
| 174 | } | 
|---|
| 175 |  | 
|---|
| 176 | return false; | 
|---|
| 177 | } | 
|---|
| 178 |  | 
|---|
| 179 | void intel_register_dsm_handler(void) | 
|---|
| 180 | { | 
|---|
| 181 | if (!intel_dsm_detect()) | 
|---|
| 182 | return; | 
|---|
| 183 | } | 
|---|
| 184 |  | 
|---|
| 185 | void intel_unregister_dsm_handler(void) | 
|---|
| 186 | { | 
|---|
| 187 | } | 
|---|
| 188 |  | 
|---|
| 189 | void intel_dsm_get_bios_data_funcs_supported(struct intel_display *display) | 
|---|
| 190 | { | 
|---|
| 191 | struct pci_dev *pdev = to_pci_dev(display->drm->dev); | 
|---|
| 192 | acpi_handle dhandle; | 
|---|
| 193 | union acpi_object *obj; | 
|---|
| 194 |  | 
|---|
| 195 | dhandle = ACPI_HANDLE(&pdev->dev); | 
|---|
| 196 | if (!dhandle) | 
|---|
| 197 | return; | 
|---|
| 198 |  | 
|---|
| 199 | obj = acpi_evaluate_dsm(handle: dhandle, guid: &intel_dsm_guid2, INTEL_DSM_REVISION_ID, | 
|---|
| 200 | INTEL_DSM_FN_GET_BIOS_DATA_FUNCS_SUPPORTED, NULL); | 
|---|
| 201 | if (obj) | 
|---|
| 202 | ACPI_FREE(obj); | 
|---|
| 203 | } | 
|---|
| 204 |  | 
|---|
| 205 | /* | 
|---|
| 206 | * ACPI Specification, Revision 5.0, Appendix B.3.2 _DOD (Enumerate All Devices | 
|---|
| 207 | * Attached to the Display Adapter). | 
|---|
| 208 | */ | 
|---|
| 209 | #define ACPI_DISPLAY_INDEX_SHIFT		0 | 
|---|
| 210 | #define ACPI_DISPLAY_INDEX_MASK			(0xf << 0) | 
|---|
| 211 | #define ACPI_DISPLAY_PORT_ATTACHMENT_SHIFT	4 | 
|---|
| 212 | #define ACPI_DISPLAY_PORT_ATTACHMENT_MASK	(0xf << 4) | 
|---|
| 213 | #define ACPI_DISPLAY_TYPE_SHIFT			8 | 
|---|
| 214 | #define ACPI_DISPLAY_TYPE_MASK			(0xf << 8) | 
|---|
| 215 | #define ACPI_DISPLAY_TYPE_OTHER			(0 << 8) | 
|---|
| 216 | #define ACPI_DISPLAY_TYPE_VGA			(1 << 8) | 
|---|
| 217 | #define ACPI_DISPLAY_TYPE_TV			(2 << 8) | 
|---|
| 218 | #define ACPI_DISPLAY_TYPE_EXTERNAL_DIGITAL	(3 << 8) | 
|---|
| 219 | #define ACPI_DISPLAY_TYPE_INTERNAL_DIGITAL	(4 << 8) | 
|---|
| 220 | #define ACPI_VENDOR_SPECIFIC_SHIFT		12 | 
|---|
| 221 | #define ACPI_VENDOR_SPECIFIC_MASK		(0xf << 12) | 
|---|
| 222 | #define ACPI_BIOS_CAN_DETECT			(1 << 16) | 
|---|
| 223 | #define ACPI_DEPENDS_ON_VGA			(1 << 17) | 
|---|
| 224 | #define ACPI_PIPE_ID_SHIFT			18 | 
|---|
| 225 | #define ACPI_PIPE_ID_MASK			(7 << 18) | 
|---|
| 226 | #define ACPI_DEVICE_ID_SCHEME			(1ULL << 31) | 
|---|
| 227 |  | 
|---|
| 228 | static u32 acpi_display_type(struct intel_connector *connector) | 
|---|
| 229 | { | 
|---|
| 230 | u32 display_type; | 
|---|
| 231 |  | 
|---|
| 232 | switch (connector->base.connector_type) { | 
|---|
| 233 | case DRM_MODE_CONNECTOR_VGA: | 
|---|
| 234 | case DRM_MODE_CONNECTOR_DVIA: | 
|---|
| 235 | display_type = ACPI_DISPLAY_TYPE_VGA; | 
|---|
| 236 | break; | 
|---|
| 237 | case DRM_MODE_CONNECTOR_Composite: | 
|---|
| 238 | case DRM_MODE_CONNECTOR_SVIDEO: | 
|---|
| 239 | case DRM_MODE_CONNECTOR_Component: | 
|---|
| 240 | case DRM_MODE_CONNECTOR_9PinDIN: | 
|---|
| 241 | case DRM_MODE_CONNECTOR_TV: | 
|---|
| 242 | display_type = ACPI_DISPLAY_TYPE_TV; | 
|---|
| 243 | break; | 
|---|
| 244 | case DRM_MODE_CONNECTOR_DVII: | 
|---|
| 245 | case DRM_MODE_CONNECTOR_DVID: | 
|---|
| 246 | case DRM_MODE_CONNECTOR_DisplayPort: | 
|---|
| 247 | case DRM_MODE_CONNECTOR_HDMIA: | 
|---|
| 248 | case DRM_MODE_CONNECTOR_HDMIB: | 
|---|
| 249 | display_type = ACPI_DISPLAY_TYPE_EXTERNAL_DIGITAL; | 
|---|
| 250 | break; | 
|---|
| 251 | case DRM_MODE_CONNECTOR_LVDS: | 
|---|
| 252 | case DRM_MODE_CONNECTOR_eDP: | 
|---|
| 253 | case DRM_MODE_CONNECTOR_DSI: | 
|---|
| 254 | display_type = ACPI_DISPLAY_TYPE_INTERNAL_DIGITAL; | 
|---|
| 255 | break; | 
|---|
| 256 | case DRM_MODE_CONNECTOR_Unknown: | 
|---|
| 257 | case DRM_MODE_CONNECTOR_VIRTUAL: | 
|---|
| 258 | display_type = ACPI_DISPLAY_TYPE_OTHER; | 
|---|
| 259 | break; | 
|---|
| 260 | default: | 
|---|
| 261 | MISSING_CASE(connector->base.connector_type); | 
|---|
| 262 | display_type = ACPI_DISPLAY_TYPE_OTHER; | 
|---|
| 263 | break; | 
|---|
| 264 | } | 
|---|
| 265 |  | 
|---|
| 266 | return display_type; | 
|---|
| 267 | } | 
|---|
| 268 |  | 
|---|
| 269 | void intel_acpi_device_id_update(struct intel_display *display) | 
|---|
| 270 | { | 
|---|
| 271 | struct intel_connector *connector; | 
|---|
| 272 | struct drm_connector_list_iter conn_iter; | 
|---|
| 273 | u8 display_index[16] = {}; | 
|---|
| 274 |  | 
|---|
| 275 | /* Populate the ACPI IDs for all connectors for a given drm_device */ | 
|---|
| 276 | drm_connector_list_iter_begin(dev: display->drm, iter: &conn_iter); | 
|---|
| 277 | for_each_intel_connector_iter(connector, &conn_iter) { | 
|---|
| 278 | u32 device_id, type; | 
|---|
| 279 |  | 
|---|
| 280 | device_id = acpi_display_type(connector); | 
|---|
| 281 |  | 
|---|
| 282 | /* Use display type specific display index. */ | 
|---|
| 283 | type = (device_id & ACPI_DISPLAY_TYPE_MASK) | 
|---|
| 284 | >> ACPI_DISPLAY_TYPE_SHIFT; | 
|---|
| 285 | device_id |= display_index[type]++ << ACPI_DISPLAY_INDEX_SHIFT; | 
|---|
| 286 |  | 
|---|
| 287 | connector->acpi_device_id = device_id; | 
|---|
| 288 | } | 
|---|
| 289 | drm_connector_list_iter_end(iter: &conn_iter); | 
|---|
| 290 | } | 
|---|
| 291 |  | 
|---|
| 292 | /* NOTE: The connector order must be final before this is called. */ | 
|---|
| 293 | void intel_acpi_assign_connector_fwnodes(struct intel_display *display) | 
|---|
| 294 | { | 
|---|
| 295 | struct drm_device *drm_dev = display->drm; | 
|---|
| 296 | struct drm_connector_list_iter conn_iter; | 
|---|
| 297 | struct fwnode_handle *fwnode = NULL; | 
|---|
| 298 | struct drm_connector *connector; | 
|---|
| 299 | struct acpi_device *adev; | 
|---|
| 300 |  | 
|---|
| 301 | drm_connector_list_iter_begin(dev: drm_dev, iter: &conn_iter); | 
|---|
| 302 | drm_for_each_connector_iter(connector, &conn_iter) { | 
|---|
| 303 | /* Always getting the next, even when the last was not used. */ | 
|---|
| 304 | fwnode = device_get_next_child_node(dev: drm_dev->dev, child: fwnode); | 
|---|
| 305 | if (!fwnode) | 
|---|
| 306 | break; | 
|---|
| 307 |  | 
|---|
| 308 | switch (connector->connector_type) { | 
|---|
| 309 | case DRM_MODE_CONNECTOR_LVDS: | 
|---|
| 310 | case DRM_MODE_CONNECTOR_eDP: | 
|---|
| 311 | case DRM_MODE_CONNECTOR_DSI: | 
|---|
| 312 | /* | 
|---|
| 313 | * Integrated displays have a specific address 0x1f on | 
|---|
| 314 | * most Intel platforms, but not on all of them. | 
|---|
| 315 | */ | 
|---|
| 316 | adev = acpi_find_child_device(ACPI_COMPANION(drm_dev->dev), | 
|---|
| 317 | address: 0x1f, check_children: 0); | 
|---|
| 318 | if (adev) { | 
|---|
| 319 | connector->fwnode = | 
|---|
| 320 | fwnode_handle_get(fwnode: acpi_fwnode_handle(adev)); | 
|---|
| 321 | break; | 
|---|
| 322 | } | 
|---|
| 323 | fallthrough; | 
|---|
| 324 | default: | 
|---|
| 325 | connector->fwnode = fwnode_handle_get(fwnode); | 
|---|
| 326 | break; | 
|---|
| 327 | } | 
|---|
| 328 | } | 
|---|
| 329 | drm_connector_list_iter_end(iter: &conn_iter); | 
|---|
| 330 | /* | 
|---|
| 331 | * device_get_next_child_node() takes a reference on the fwnode, if | 
|---|
| 332 | * we stopped iterating because we are out of connectors we need to | 
|---|
| 333 | * put this, otherwise fwnode is NULL and the put is a no-op. | 
|---|
| 334 | */ | 
|---|
| 335 | fwnode_handle_put(fwnode); | 
|---|
| 336 | } | 
|---|
| 337 |  | 
|---|
| 338 | void intel_acpi_video_register(struct intel_display *display) | 
|---|
| 339 | { | 
|---|
| 340 | struct drm_connector_list_iter conn_iter; | 
|---|
| 341 | struct drm_connector *connector; | 
|---|
| 342 |  | 
|---|
| 343 | acpi_video_register(); | 
|---|
| 344 |  | 
|---|
| 345 | /* | 
|---|
| 346 | * If i915 is driving an internal panel without registering its native | 
|---|
| 347 | * backlight handler try to register the acpi_video backlight. | 
|---|
| 348 | * For panels not driven by i915 another GPU driver may still register | 
|---|
| 349 | * a native backlight later and acpi_video_register_backlight() should | 
|---|
| 350 | * only be called after any native backlights have been registered. | 
|---|
| 351 | */ | 
|---|
| 352 | drm_connector_list_iter_begin(dev: display->drm, iter: &conn_iter); | 
|---|
| 353 | drm_for_each_connector_iter(connector, &conn_iter) { | 
|---|
| 354 | struct intel_panel *panel = &to_intel_connector(connector)->panel; | 
|---|
| 355 |  | 
|---|
| 356 | if (panel->backlight.funcs && !panel->backlight.device) { | 
|---|
| 357 | acpi_video_register_backlight(); | 
|---|
| 358 | break; | 
|---|
| 359 | } | 
|---|
| 360 | } | 
|---|
| 361 | drm_connector_list_iter_end(iter: &conn_iter); | 
|---|
| 362 | } | 
|---|
| 363 |  | 
|---|