1 // SPDX-License-Identifier: MIT 2 /* 3 * Copyright © 2023 Intel Corporation 4 */ 5 6 #include "xe_display.h" 7 #include "regs/xe_irq_regs.h" 8 9 #include <linux/fb.h> 10 11 #include <drm/drm_client.h> 12 #include <drm/drm_client_event.h> 13 #include <drm/drm_drv.h> 14 #include <drm/drm_managed.h> 15 #include <drm/drm_probe_helper.h> 16 #include <drm/intel/display_member.h> 17 #include <drm/intel/display_parent_interface.h> 18 #include <uapi/drm/xe_drm.h> 19 20 #include "intel_acpi.h" 21 #include "intel_audio.h" 22 #include "intel_display.h" 23 #include "intel_display_core.h" 24 #include "intel_display_device.h" 25 #include "intel_display_driver.h" 26 #include "intel_display_irq.h" 27 #include "intel_display_types.h" 28 #include "intel_dmc.h" 29 #include "intel_dmc_wl.h" 30 #include "intel_dp.h" 31 #include "intel_fbdev.h" 32 #include "intel_hdcp.h" 33 #include "intel_hotplug.h" 34 #include "intel_opregion.h" 35 #include "skl_watermark.h" 36 #include "xe_device.h" 37 #include "xe_display_bo.h" 38 #include "xe_display_pcode.h" 39 #include "xe_display_rpm.h" 40 #include "xe_dsb_buffer.h" 41 #include "xe_fb_pin.h" 42 #include "xe_frontbuffer.h" 43 #include "xe_hdcp_gsc.h" 44 #include "xe_initial_plane.h" 45 #include "xe_module.h" 46 #include "xe_panic.h" 47 #include "xe_stolen.h" 48 49 /* Ensure drm and display members are placed properly. */ 50 INTEL_DISPLAY_MEMBER_STATIC_ASSERT(struct xe_device, drm, display); 51 52 /* Xe device functions */ 53 54 /** 55 * xe_display_driver_probe_defer - Detect if we need to wait for other drivers 56 * early on 57 * @pdev: PCI device 58 * 59 * Note: This is called before xe or display device creation. 60 * 61 * Returns: true if probe needs to be deferred, false otherwise 62 */ 63 bool xe_display_driver_probe_defer(struct pci_dev *pdev) 64 { 65 if (!xe_modparam.probe_display) 66 return 0; 67 68 return intel_display_driver_probe_defer(pdev); 69 } 70 71 static void unset_display_features(struct xe_device *xe) 72 { 73 xe->drm.driver_features &= ~XE_DISPLAY_DRIVER_FEATURES; 74 } 75 76 static void xe_display_fini_early(void *arg) 77 { 78 struct xe_device *xe = arg; 79 struct intel_display *display = xe->display; 80 81 if (!xe->info.probe_display) 82 return; 83 84 intel_display_driver_remove_noirq(display); 85 intel_display_driver_remove_nogem(display); 86 intel_display_power_cleanup(display); 87 } 88 89 int xe_display_init_early(struct xe_device *xe) 90 { 91 struct intel_display *display = xe->display; 92 int err; 93 94 if (!xe->info.probe_display) 95 return 0; 96 97 /* Fake uncore lock */ 98 spin_lock_init(&xe->uncore.lock); 99 100 intel_display_driver_early_probe(display); 101 102 intel_display_device_info_runtime_init(display); 103 104 /* Display may have been disabled at runtime init */ 105 if (!intel_display_device_present(display)) { 106 xe->info.probe_display = false; 107 unset_display_features(xe); 108 return 0; 109 } 110 111 err = intel_display_driver_probe_noirq(display); 112 if (err) 113 return err; 114 115 err = intel_display_driver_probe_nogem(display); 116 if (err) 117 goto err_noirq; 118 119 return devm_add_action_or_reset(xe->drm.dev, xe_display_fini_early, xe); 120 err_noirq: 121 intel_display_driver_remove_noirq(display); 122 intel_display_power_cleanup(display); 123 124 return err; 125 } 126 127 static void xe_display_fini(void *arg) 128 { 129 struct xe_device *xe = arg; 130 struct intel_display *display = xe->display; 131 132 intel_hpd_poll_fini(display); 133 intel_hdcp_component_fini(display); 134 intel_audio_deinit(display); 135 intel_display_driver_remove(display); 136 } 137 138 int xe_display_init(struct xe_device *xe) 139 { 140 struct intel_display *display = xe->display; 141 int err; 142 143 if (!xe->info.probe_display) 144 return 0; 145 146 err = intel_display_driver_probe(display); 147 if (err) 148 return err; 149 150 return devm_add_action_or_reset(xe->drm.dev, xe_display_fini, xe); 151 } 152 153 void xe_display_register(struct xe_device *xe) 154 { 155 struct intel_display *display = xe->display; 156 157 if (!xe->info.probe_display) 158 return; 159 160 intel_display_driver_register(display); 161 intel_display_driver_runtime_pm_enable(display); 162 } 163 164 void xe_display_unregister(struct xe_device *xe) 165 { 166 struct intel_display *display = xe->display; 167 168 if (!xe->info.probe_display) 169 return; 170 171 intel_display_driver_runtime_pm_disable(display); 172 intel_display_driver_unregister(display); 173 } 174 175 void xe_display_shutdown(struct xe_device *xe) 176 { 177 struct intel_display *display = xe->display; 178 179 if (!xe->info.probe_display) 180 return; 181 182 intel_display_driver_shutdown(display); 183 184 intel_opregion_suspend(display, PCI_D3cold); 185 186 intel_dmc_suspend(display); 187 } 188 189 void xe_display_shutdown_late(struct xe_device *xe) 190 { 191 struct intel_display *display = xe->display; 192 193 if (!xe->info.probe_display) 194 return; 195 196 intel_display_driver_shutdown_late(display); 197 } 198 199 /* IRQ-related functions */ 200 201 void xe_display_irq_handler(struct xe_device *xe, u32 master_ctl) 202 { 203 struct intel_display *display = xe->display; 204 205 if (!xe->info.probe_display) 206 return; 207 208 if (master_ctl & DISPLAY_IRQ) 209 intel_display_irq_handler(display, NULL); 210 } 211 212 void xe_display_irq_enable(struct xe_device *xe, u32 gu_misc_iir) 213 { 214 struct intel_display *display = xe->display; 215 216 if (!xe->info.probe_display) 217 return; 218 219 if (gu_misc_iir & GU_MISC_GSE) 220 intel_opregion_asle_intr(display); 221 } 222 223 void xe_display_irq_reset(struct xe_device *xe) 224 { 225 struct intel_display *display = xe->display; 226 227 if (!xe->info.probe_display) 228 return; 229 230 intel_display_irq_reset(display); 231 } 232 233 void xe_display_irq_postinstall(struct xe_device *xe) 234 { 235 struct intel_display *display = xe->display; 236 237 if (!xe->info.probe_display) 238 return; 239 240 intel_display_irq_postinstall(display); 241 } 242 243 static bool suspend_to_idle(void) 244 { 245 #if IS_ENABLED(CONFIG_ACPI_SLEEP) 246 if (acpi_target_system_state() < ACPI_STATE_S3) 247 return true; 248 #endif 249 return false; 250 } 251 252 void xe_display_pm_suspend(struct xe_device *xe) 253 { 254 struct intel_display *display = xe->display; 255 bool s2idle = suspend_to_idle(); 256 257 if (!xe->info.probe_display) 258 return; 259 260 intel_display_driver_pm_suspend(display); 261 262 intel_opregion_suspend(display, s2idle ? PCI_D1 : PCI_D3cold); 263 264 intel_dmc_suspend(display); 265 } 266 267 void xe_display_pm_suspend_late(struct xe_device *xe) 268 { 269 struct intel_display *display = xe->display; 270 bool s2idle = suspend_to_idle(); 271 272 if (!xe->info.probe_display) 273 return; 274 275 intel_display_driver_pm_suspend_late(display, s2idle); 276 } 277 278 void xe_display_pm_resume_early(struct xe_device *xe) 279 { 280 struct intel_display *display = xe->display; 281 282 if (!xe->info.probe_display) 283 return; 284 285 intel_display_driver_pm_resume_early(display); 286 } 287 288 void xe_display_pm_resume(struct xe_device *xe) 289 { 290 struct intel_display *display = xe->display; 291 292 if (!xe->info.probe_display) 293 return; 294 295 intel_dmc_resume(display); 296 297 if (intel_display_device_present(display)) 298 drm_mode_config_reset(&xe->drm); 299 300 intel_display_driver_init_hw(display); 301 302 intel_display_driver_pm_resume(display); 303 } 304 305 static void xe_display_enable_d3cold(struct xe_device *xe) 306 { 307 struct intel_display *display = xe->display; 308 309 if (!xe->info.probe_display) 310 return; 311 312 /* 313 * We do a lot of poking in a lot of registers, make sure they work 314 * properly. 315 */ 316 intel_display_driver_runtime_pm_disable(display); 317 318 intel_display_flush_cleanup_work(display); 319 320 intel_opregion_suspend(display, PCI_D3cold); 321 322 intel_dmc_suspend(display); 323 324 if (intel_display_device_present(display)) 325 intel_hpd_poll_enable(display); 326 } 327 328 static void xe_display_disable_d3cold(struct xe_device *xe) 329 { 330 struct intel_display *display = xe->display; 331 332 if (!xe->info.probe_display) 333 return; 334 335 intel_dmc_resume(display); 336 337 if (intel_display_device_present(display)) 338 drm_mode_config_reset(&xe->drm); 339 340 intel_display_driver_init_hw(display); 341 342 intel_hpd_init(display); 343 344 if (intel_display_device_present(display)) 345 intel_hpd_poll_disable(display); 346 347 intel_opregion_resume(display); 348 349 intel_display_driver_runtime_pm_enable(display); 350 } 351 352 /* before irq suspend */ 353 void xe_display_pm_runtime_suspend(struct xe_device *xe) 354 { 355 struct intel_display *display = xe->display; 356 357 if (!xe->info.probe_display) 358 return; 359 360 if (xe->d3cold.allowed) { 361 xe_display_enable_d3cold(xe); 362 return; 363 } 364 365 intel_display_driver_pm_runtime_suspend(display); 366 } 367 368 /* after irq suspend */ 369 void xe_display_pm_runtime_suspend_late(struct xe_device *xe) 370 { 371 struct intel_display *display = xe->display; 372 373 if (!xe->info.probe_display) 374 return; 375 376 if (xe->d3cold.allowed) { 377 xe_display_pm_suspend_late(xe); 378 /* Ensure the wakelock release work gets flushed */ 379 intel_dmc_wl_flush_release_work(display); 380 return; 381 } 382 383 intel_display_driver_pm_runtime_suspend_late(display); 384 } 385 386 /* before irq resume */ 387 void xe_display_pm_runtime_resume_early(struct xe_device *xe) 388 { 389 struct intel_display *display = xe->display; 390 391 if (!xe->info.probe_display) 392 return; 393 394 if (xe->d3cold.allowed) 395 return; 396 397 intel_display_driver_pm_runtime_resume_early(display); 398 } 399 400 /* after irq resume */ 401 void xe_display_pm_runtime_resume(struct xe_device *xe) 402 { 403 struct intel_display *display = xe->display; 404 405 if (!xe->info.probe_display) 406 return; 407 408 if (xe->d3cold.allowed) { 409 xe_display_disable_d3cold(xe); 410 return; 411 } 412 413 intel_display_driver_pm_runtime_resume(display); 414 } 415 416 417 static void display_device_remove(struct drm_device *dev, void *arg) 418 { 419 struct xe_device *xe = arg; 420 421 intel_display_device_remove(xe->display); 422 xe->display = NULL; 423 } 424 425 static bool irq_enabled(struct drm_device *drm) 426 { 427 struct xe_device *xe = to_xe_device(drm); 428 429 return atomic_read(&xe->irq.enabled); 430 } 431 432 static void irq_synchronize(struct drm_device *drm) 433 { 434 synchronize_irq(to_pci_dev(drm->dev)->irq); 435 } 436 437 static const struct intel_display_irq_interface xe_display_irq_interface = { 438 .enabled = irq_enabled, 439 .synchronize = irq_synchronize, 440 }; 441 442 static bool has_auxccs(struct drm_device *drm) 443 { 444 struct xe_device *xe = to_xe_device(drm); 445 446 return xe->info.platform == XE_ALDERLAKE_P; 447 } 448 449 static const struct intel_display_parent_interface parent = { 450 .bo = &xe_display_bo_interface, 451 .dsb = &xe_display_dsb_interface, 452 .fb_pin = &xe_display_fb_pin_interface, 453 .frontbuffer = &xe_display_frontbuffer_interface, 454 .hdcp = &xe_display_hdcp_interface, 455 .initial_plane = &xe_display_initial_plane_interface, 456 .irq = &xe_display_irq_interface, 457 .panic = &xe_display_panic_interface, 458 .pcode = &xe_display_pcode_interface, 459 .rpm = &xe_display_rpm_interface, 460 .stolen = &xe_display_stolen_interface, 461 .has_auxccs = has_auxccs, 462 }; 463 464 /** 465 * xe_display_probe - probe display and create display struct 466 * @xe: XE device instance 467 * 468 * Initialize all fields used by the display part. 469 * 470 * TODO: once everything can be inside a single struct, make the struct opaque 471 * to the rest of xe and return it to be xe->display. 472 * 473 * Returns: 0 on success 474 */ 475 int xe_display_probe(struct xe_device *xe) 476 { 477 struct pci_dev *pdev = to_pci_dev(xe->drm.dev); 478 struct intel_display *display; 479 int err; 480 481 if (!xe->info.probe_display) 482 goto no_display; 483 484 display = intel_display_device_probe(pdev, &parent); 485 if (IS_ERR(display)) 486 return PTR_ERR(display); 487 488 xe->display = display; 489 490 err = drmm_add_action_or_reset(&xe->drm, display_device_remove, xe); 491 if (err) 492 return err; 493 494 if (intel_display_device_present(display)) 495 return 0; 496 497 no_display: 498 xe->info.probe_display = false; 499 unset_display_features(xe); 500 return 0; 501 } 502 503 #ifdef CONFIG_DRM_FBDEV_EMULATION 504 int xe_display_driver_fbdev_probe(struct drm_fb_helper *fbh, 505 struct drm_fb_helper_surface_size *sizes) 506 { 507 return intel_fbdev_driver_fbdev_probe(fbh, sizes); 508 } 509 #endif 510