1 // SPDX-License-Identifier: MIT
3 * Copyright © 2023 Intel Corporation
6 #include "xe_display.h"
7 #include "regs/xe_regs.h"
11 #include <drm/drm_drv.h>
12 #include <drm/drm_managed.h>
13 #include <drm/xe_drm.h>
15 #include "soc/intel_dram.h"
16 #include "i915_drv.h" /* FIXME: HAS_DISPLAY() depends on this */
17 #include "intel_acpi.h"
18 #include "intel_audio.h"
20 #include "intel_display.h"
21 #include "intel_display_driver.h"
22 #include "intel_display_irq.h"
23 #include "intel_display_types.h"
24 #include "intel_dmc.h"
26 #include "intel_fbdev.h"
27 #include "intel_hdcp.h"
28 #include "intel_hotplug.h"
29 #include "intel_opregion.h"
30 #include "xe_module.h"
32 /* Xe device functions */
34 static bool has_display(struct xe_device *xe)
36 return HAS_DISPLAY(xe);
40 * xe_display_driver_probe_defer - Detect if we need to wait for other drivers
44 * Returns: true if probe needs to be deferred, false otherwise
46 bool xe_display_driver_probe_defer(struct pci_dev *pdev)
48 if (!xe_modparam.enable_display)
51 return intel_display_driver_probe_defer(pdev);
54 static void xe_display_last_close(struct drm_device *dev)
56 struct xe_device *xe = to_xe_device(dev);
58 if (xe->info.enable_display)
59 intel_fbdev_restore_mode(to_xe_device(dev));
63 * xe_display_driver_set_hooks - Add driver flags and hooks for display
64 * @driver: DRM device driver
66 * Set features and function hooks in @driver that are needed for driving the
67 * display IP. This sets the driver's capability of driving display, regardless
68 * if the device has it enabled
70 void xe_display_driver_set_hooks(struct drm_driver *driver)
72 if (!xe_modparam.enable_display)
75 driver->driver_features |= DRIVER_MODESET | DRIVER_ATOMIC;
76 driver->lastclose = xe_display_last_close;
79 static void unset_display_features(struct xe_device *xe)
81 xe->drm.driver_features &= ~(DRIVER_MODESET | DRIVER_ATOMIC);
84 static void display_destroy(struct drm_device *dev, void *dummy)
86 struct xe_device *xe = to_xe_device(dev);
88 destroy_workqueue(xe->display.hotplug.dp_wq);
92 * xe_display_create - create display struct
93 * @xe: XE device instance
95 * Initialize all fields used by the display part.
97 * TODO: once everything can be inside a single struct, make the struct opaque
98 * to the rest of xe and return it to be xe->display.
100 * Returns: 0 on success
102 int xe_display_create(struct xe_device *xe)
106 spin_lock_init(&xe->display.fb_tracking.lock);
108 xe->display.hotplug.dp_wq = alloc_ordered_workqueue("xe-dp", 0);
110 drmm_mutex_init(&xe->drm, &xe->sb_lock);
111 drmm_mutex_init(&xe->drm, &xe->display.backlight.lock);
112 drmm_mutex_init(&xe->drm, &xe->display.audio.mutex);
113 drmm_mutex_init(&xe->drm, &xe->display.wm.wm_mutex);
114 drmm_mutex_init(&xe->drm, &xe->display.pps.mutex);
115 drmm_mutex_init(&xe->drm, &xe->display.hdcp.hdcp_mutex);
116 xe->enabled_irq_mask = ~0;
118 err = drmm_add_action_or_reset(&xe->drm, display_destroy, NULL);
125 static void xe_display_fini_nommio(struct drm_device *dev, void *dummy)
127 struct xe_device *xe = to_xe_device(dev);
129 if (!xe->info.enable_display)
132 intel_power_domains_cleanup(xe);
135 int xe_display_init_nommio(struct xe_device *xe)
139 if (!xe->info.enable_display)
142 /* Fake uncore lock */
143 spin_lock_init(&xe->uncore.lock);
145 /* This must be called before any calls to HAS_PCH_* */
146 intel_detect_pch(xe);
148 err = intel_power_domains_init(xe);
152 return drmm_add_action_or_reset(&xe->drm, xe_display_fini_nommio, xe);
155 static void xe_display_fini_noirq(struct drm_device *dev, void *dummy)
157 struct xe_device *xe = to_xe_device(dev);
159 if (!xe->info.enable_display)
162 intel_display_driver_remove_noirq(xe);
163 intel_power_domains_driver_remove(xe);
166 int xe_display_init_noirq(struct xe_device *xe)
170 if (!xe->info.enable_display)
173 intel_display_driver_early_probe(xe);
175 /* Early display init.. */
176 intel_opregion_setup(xe);
179 * Fill the dram structure to get the system dram info. This will be
180 * used for memory latency calculation.
182 intel_dram_detect(xe);
184 intel_bw_init_hw(xe);
186 intel_display_device_info_runtime_init(xe);
188 err = intel_display_driver_probe_noirq(xe);
192 return drmm_add_action_or_reset(&xe->drm, xe_display_fini_noirq, NULL);
195 static void xe_display_fini_noaccel(struct drm_device *dev, void *dummy)
197 struct xe_device *xe = to_xe_device(dev);
199 if (!xe->info.enable_display)
202 intel_display_driver_remove_nogem(xe);
205 int xe_display_init_noaccel(struct xe_device *xe)
209 if (!xe->info.enable_display)
212 err = intel_display_driver_probe_nogem(xe);
216 return drmm_add_action_or_reset(&xe->drm, xe_display_fini_noaccel, NULL);
219 int xe_display_init(struct xe_device *xe)
221 if (!xe->info.enable_display)
224 return intel_display_driver_probe(xe);
227 void xe_display_fini(struct xe_device *xe)
229 if (!xe->info.enable_display)
232 /* poll work can call into fbdev, hence clean that up afterwards */
233 intel_hpd_poll_fini(xe);
234 intel_fbdev_fini(xe);
236 intel_hdcp_component_fini(xe);
237 intel_audio_deinit(xe);
240 void xe_display_register(struct xe_device *xe)
242 if (!xe->info.enable_display)
245 intel_display_driver_register(xe);
246 intel_register_dsm_handler();
247 intel_power_domains_enable(xe);
250 void xe_display_unregister(struct xe_device *xe)
252 if (!xe->info.enable_display)
255 intel_unregister_dsm_handler();
256 intel_power_domains_disable(xe);
257 intel_display_driver_unregister(xe);
260 void xe_display_driver_remove(struct xe_device *xe)
262 if (!xe->info.enable_display)
265 intel_display_driver_remove(xe);
267 intel_display_device_remove(xe);
270 /* IRQ-related functions */
272 void xe_display_irq_handler(struct xe_device *xe, u32 master_ctl)
274 if (!xe->info.enable_display)
277 if (master_ctl & DISPLAY_IRQ)
278 gen11_display_irq_handler(xe);
281 void xe_display_irq_enable(struct xe_device *xe, u32 gu_misc_iir)
283 if (!xe->info.enable_display)
286 if (gu_misc_iir & GU_MISC_GSE)
287 intel_opregion_asle_intr(xe);
290 void xe_display_irq_reset(struct xe_device *xe)
292 if (!xe->info.enable_display)
295 gen11_display_irq_reset(xe);
298 void xe_display_irq_postinstall(struct xe_device *xe, struct xe_gt *gt)
300 if (!xe->info.enable_display)
303 if (gt->info.id == XE_GT0)
304 gen11_de_irq_postinstall(xe);
307 static void intel_suspend_encoders(struct xe_device *xe)
309 struct drm_device *dev = &xe->drm;
310 struct intel_encoder *encoder;
315 drm_modeset_lock_all(dev);
316 for_each_intel_encoder(dev, encoder)
317 if (encoder->suspend)
318 encoder->suspend(encoder);
319 drm_modeset_unlock_all(dev);
322 static bool suspend_to_idle(void)
324 #if IS_ENABLED(CONFIG_ACPI_SLEEP)
325 if (acpi_target_system_state() < ACPI_STATE_S3)
331 void xe_display_pm_suspend(struct xe_device *xe)
333 bool s2idle = suspend_to_idle();
334 if (!xe->info.enable_display)
338 * We do a lot of poking in a lot of registers, make sure they work
341 intel_power_domains_disable(xe);
343 drm_kms_helper_poll_disable(&xe->drm);
345 intel_display_driver_suspend(xe);
347 intel_dp_mst_suspend(xe);
349 intel_hpd_cancel_work(xe);
351 intel_suspend_encoders(xe);
353 intel_opregion_suspend(xe, s2idle ? PCI_D1 : PCI_D3cold);
355 intel_fbdev_set_suspend(&xe->drm, FBINFO_STATE_SUSPENDED, true);
357 intel_dmc_suspend(xe);
360 void xe_display_pm_suspend_late(struct xe_device *xe)
362 bool s2idle = suspend_to_idle();
363 if (!xe->info.enable_display)
366 intel_power_domains_suspend(xe, s2idle);
368 intel_display_power_suspend_late(xe);
371 void xe_display_pm_resume_early(struct xe_device *xe)
373 if (!xe->info.enable_display)
376 intel_display_power_resume_early(xe);
378 intel_power_domains_resume(xe);
381 void xe_display_pm_resume(struct xe_device *xe)
383 if (!xe->info.enable_display)
386 intel_dmc_resume(xe);
389 drm_mode_config_reset(&xe->drm);
391 intel_display_driver_init_hw(xe);
394 /* MST sideband requires HPD interrupts enabled */
395 intel_dp_mst_resume(xe);
396 intel_display_driver_resume(xe);
398 intel_hpd_poll_disable(xe);
400 drm_kms_helper_poll_enable(&xe->drm);
402 intel_opregion_resume(xe);
404 intel_fbdev_set_suspend(&xe->drm, FBINFO_STATE_RUNNING, false);
406 intel_power_domains_enable(xe);
409 void xe_display_probe(struct xe_device *xe)
411 if (!xe->info.enable_display)
414 intel_display_device_probe(xe);
420 xe->info.enable_display = false;
421 unset_display_features(xe);