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);
55 * xe_display_driver_set_hooks - Add driver flags and hooks for display
56 * @driver: DRM device driver
58 * Set features and function hooks in @driver that are needed for driving the
59 * display IP. This sets the driver's capability of driving display, regardless
60 * if the device has it enabled
62 void xe_display_driver_set_hooks(struct drm_driver *driver)
64 if (!xe_modparam.enable_display)
67 driver->driver_features |= DRIVER_MODESET | DRIVER_ATOMIC;
70 static void unset_display_features(struct xe_device *xe)
72 xe->drm.driver_features &= ~(DRIVER_MODESET | DRIVER_ATOMIC);
75 static void display_destroy(struct drm_device *dev, void *dummy)
77 struct xe_device *xe = to_xe_device(dev);
79 destroy_workqueue(xe->display.hotplug.dp_wq);
83 * xe_display_create - create display struct
84 * @xe: XE device instance
86 * Initialize all fields used by the display part.
88 * TODO: once everything can be inside a single struct, make the struct opaque
89 * to the rest of xe and return it to be xe->display.
91 * Returns: 0 on success
93 int xe_display_create(struct xe_device *xe)
95 spin_lock_init(&xe->display.fb_tracking.lock);
97 xe->display.hotplug.dp_wq = alloc_ordered_workqueue("xe-dp", 0);
99 drmm_mutex_init(&xe->drm, &xe->sb_lock);
100 xe->enabled_irq_mask = ~0;
102 return drmm_add_action_or_reset(&xe->drm, display_destroy, NULL);
105 static void xe_display_fini_nommio(struct drm_device *dev, void *dummy)
107 struct xe_device *xe = to_xe_device(dev);
109 if (!xe->info.enable_display)
112 intel_power_domains_cleanup(xe);
115 int xe_display_init_nommio(struct xe_device *xe)
117 if (!xe->info.enable_display)
120 /* Fake uncore lock */
121 spin_lock_init(&xe->uncore.lock);
123 /* This must be called before any calls to HAS_PCH_* */
124 intel_detect_pch(xe);
126 return drmm_add_action_or_reset(&xe->drm, xe_display_fini_nommio, xe);
129 static void xe_display_fini_noirq(struct drm_device *dev, void *dummy)
131 struct xe_device *xe = to_xe_device(dev);
133 if (!xe->info.enable_display)
136 intel_display_driver_remove_noirq(xe);
137 intel_power_domains_driver_remove(xe);
140 int xe_display_init_noirq(struct xe_device *xe)
144 if (!xe->info.enable_display)
147 intel_display_driver_early_probe(xe);
149 /* Early display init.. */
150 intel_opregion_setup(xe);
153 * Fill the dram structure to get the system dram info. This will be
154 * used for memory latency calculation.
156 intel_dram_detect(xe);
158 intel_bw_init_hw(xe);
160 intel_display_device_info_runtime_init(xe);
162 err = intel_display_driver_probe_noirq(xe);
166 return drmm_add_action_or_reset(&xe->drm, xe_display_fini_noirq, NULL);
169 static void xe_display_fini_noaccel(struct drm_device *dev, void *dummy)
171 struct xe_device *xe = to_xe_device(dev);
173 if (!xe->info.enable_display)
176 intel_display_driver_remove_nogem(xe);
179 int xe_display_init_noaccel(struct xe_device *xe)
183 if (!xe->info.enable_display)
186 err = intel_display_driver_probe_nogem(xe);
190 return drmm_add_action_or_reset(&xe->drm, xe_display_fini_noaccel, NULL);
193 int xe_display_init(struct xe_device *xe)
195 if (!xe->info.enable_display)
198 return intel_display_driver_probe(xe);
201 void xe_display_fini(struct xe_device *xe)
203 if (!xe->info.enable_display)
206 intel_hpd_poll_fini(xe);
208 intel_hdcp_component_fini(xe);
209 intel_audio_deinit(xe);
212 void xe_display_register(struct xe_device *xe)
214 if (!xe->info.enable_display)
217 intel_display_driver_register(xe);
218 intel_register_dsm_handler();
219 intel_power_domains_enable(xe);
222 void xe_display_unregister(struct xe_device *xe)
224 if (!xe->info.enable_display)
227 intel_unregister_dsm_handler();
228 intel_power_domains_disable(xe);
229 intel_display_driver_unregister(xe);
232 void xe_display_driver_remove(struct xe_device *xe)
234 if (!xe->info.enable_display)
237 intel_display_driver_remove(xe);
239 intel_display_device_remove(xe);
242 /* IRQ-related functions */
244 void xe_display_irq_handler(struct xe_device *xe, u32 master_ctl)
246 if (!xe->info.enable_display)
249 if (master_ctl & DISPLAY_IRQ)
250 gen11_display_irq_handler(xe);
253 void xe_display_irq_enable(struct xe_device *xe, u32 gu_misc_iir)
255 if (!xe->info.enable_display)
258 if (gu_misc_iir & GU_MISC_GSE)
259 intel_opregion_asle_intr(xe);
262 void xe_display_irq_reset(struct xe_device *xe)
264 if (!xe->info.enable_display)
267 gen11_display_irq_reset(xe);
270 void xe_display_irq_postinstall(struct xe_device *xe, struct xe_gt *gt)
272 if (!xe->info.enable_display)
275 if (gt->info.id == XE_GT0)
276 gen11_de_irq_postinstall(xe);
279 static void intel_suspend_encoders(struct xe_device *xe)
281 struct drm_device *dev = &xe->drm;
282 struct intel_encoder *encoder;
287 drm_modeset_lock_all(dev);
288 for_each_intel_encoder(dev, encoder)
289 if (encoder->suspend)
290 encoder->suspend(encoder);
291 drm_modeset_unlock_all(dev);
294 static bool suspend_to_idle(void)
296 #if IS_ENABLED(CONFIG_ACPI_SLEEP)
297 if (acpi_target_system_state() < ACPI_STATE_S3)
303 void xe_display_pm_suspend(struct xe_device *xe)
305 bool s2idle = suspend_to_idle();
306 if (!xe->info.enable_display)
310 * We do a lot of poking in a lot of registers, make sure they work
313 intel_power_domains_disable(xe);
315 drm_kms_helper_poll_disable(&xe->drm);
317 intel_display_driver_suspend(xe);
319 intel_dp_mst_suspend(xe);
321 intel_hpd_cancel_work(xe);
323 intel_suspend_encoders(xe);
325 intel_opregion_suspend(xe, s2idle ? PCI_D1 : PCI_D3cold);
327 intel_fbdev_set_suspend(&xe->drm, FBINFO_STATE_SUSPENDED, true);
329 intel_dmc_suspend(xe);
332 void xe_display_pm_suspend_late(struct xe_device *xe)
334 bool s2idle = suspend_to_idle();
335 if (!xe->info.enable_display)
338 intel_power_domains_suspend(xe, s2idle);
340 intel_display_power_suspend_late(xe);
343 void xe_display_pm_resume_early(struct xe_device *xe)
345 if (!xe->info.enable_display)
348 intel_display_power_resume_early(xe);
350 intel_power_domains_resume(xe);
353 void xe_display_pm_resume(struct xe_device *xe)
355 if (!xe->info.enable_display)
358 intel_dmc_resume(xe);
361 drm_mode_config_reset(&xe->drm);
363 intel_display_driver_init_hw(xe);
366 /* MST sideband requires HPD interrupts enabled */
367 intel_dp_mst_resume(xe);
368 intel_display_driver_resume(xe);
370 intel_hpd_poll_disable(xe);
372 drm_kms_helper_poll_enable(&xe->drm);
374 intel_opregion_resume(xe);
376 intel_fbdev_set_suspend(&xe->drm, FBINFO_STATE_RUNNING, false);
378 intel_power_domains_enable(xe);
381 void xe_display_probe(struct xe_device *xe)
383 if (!xe->info.enable_display)
386 intel_display_device_probe(xe);
392 xe->info.enable_display = false;
393 unset_display_features(xe);