1 /* i915_drv.c -- i830,i845,i855,i865,i915 driver -*- linux-c -*-
5 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sub license, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
16 * The above copyright notice and this permission notice (including the
17 * next paragraph) shall be included in all copies or substantial portions
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
23 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
24 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 #include <linux/acpi.h>
31 #include <linux/device.h>
32 #include <linux/oom.h>
33 #include <linux/module.h>
34 #include <linux/pci.h>
36 #include <linux/pm_runtime.h>
37 #include <linux/pnp.h>
38 #include <linux/slab.h>
39 #include <linux/vga_switcheroo.h>
41 #include <acpi/video.h>
43 #include <drm/drm_atomic_helper.h>
44 #include <drm/drm_ioctl.h>
45 #include <drm/drm_irq.h>
46 #include <drm/drm_managed.h>
47 #include <drm/drm_probe_helper.h>
49 #include "display/intel_acpi.h"
50 #include "display/intel_audio.h"
51 #include "display/intel_bw.h"
52 #include "display/intel_cdclk.h"
53 #include "display/intel_csr.h"
54 #include "display/intel_display_debugfs.h"
55 #include "display/intel_display_types.h"
56 #include "display/intel_dp.h"
57 #include "display/intel_fbdev.h"
58 #include "display/intel_hotplug.h"
59 #include "display/intel_overlay.h"
60 #include "display/intel_pipe_crc.h"
61 #include "display/intel_sprite.h"
62 #include "display/intel_vga.h"
64 #include "gem/i915_gem_context.h"
65 #include "gem/i915_gem_ioctls.h"
66 #include "gem/i915_gem_mman.h"
67 #include "gt/intel_gt.h"
68 #include "gt/intel_gt_pm.h"
69 #include "gt/intel_rc6.h"
71 #include "i915_debugfs.h"
73 #include "i915_ioc32.h"
75 #include "i915_memcpy.h"
76 #include "i915_perf.h"
77 #include "i915_query.h"
78 #include "i915_suspend.h"
79 #include "i915_switcheroo.h"
80 #include "i915_sysfs.h"
81 #include "i915_trace.h"
82 #include "i915_vgpu.h"
83 #include "intel_dram.h"
84 #include "intel_gvt.h"
85 #include "intel_memory_region.h"
87 #include "intel_sideband.h"
88 #include "vlv_suspend.h"
90 static const struct drm_driver driver
;
92 static int i915_get_bridge_dev(struct drm_i915_private
*dev_priv
)
94 int domain
= pci_domain_nr(dev_priv
->drm
.pdev
->bus
);
96 dev_priv
->bridge_dev
=
97 pci_get_domain_bus_and_slot(domain
, 0, PCI_DEVFN(0, 0));
98 if (!dev_priv
->bridge_dev
) {
99 drm_err(&dev_priv
->drm
, "bridge device not found\n");
105 /* Allocate space for the MCH regs if needed, return nonzero on error */
107 intel_alloc_mchbar_resource(struct drm_i915_private
*dev_priv
)
109 int reg
= INTEL_GEN(dev_priv
) >= 4 ? MCHBAR_I965
: MCHBAR_I915
;
110 u32 temp_lo
, temp_hi
= 0;
114 if (INTEL_GEN(dev_priv
) >= 4)
115 pci_read_config_dword(dev_priv
->bridge_dev
, reg
+ 4, &temp_hi
);
116 pci_read_config_dword(dev_priv
->bridge_dev
, reg
, &temp_lo
);
117 mchbar_addr
= ((u64
)temp_hi
<< 32) | temp_lo
;
119 /* If ACPI doesn't have it, assume we need to allocate it ourselves */
122 pnp_range_reserved(mchbar_addr
, mchbar_addr
+ MCHBAR_SIZE
))
126 /* Get some space for it */
127 dev_priv
->mch_res
.name
= "i915 MCHBAR";
128 dev_priv
->mch_res
.flags
= IORESOURCE_MEM
;
129 ret
= pci_bus_alloc_resource(dev_priv
->bridge_dev
->bus
,
131 MCHBAR_SIZE
, MCHBAR_SIZE
,
133 0, pcibios_align_resource
,
134 dev_priv
->bridge_dev
);
136 drm_dbg(&dev_priv
->drm
, "failed bus alloc: %d\n", ret
);
137 dev_priv
->mch_res
.start
= 0;
141 if (INTEL_GEN(dev_priv
) >= 4)
142 pci_write_config_dword(dev_priv
->bridge_dev
, reg
+ 4,
143 upper_32_bits(dev_priv
->mch_res
.start
));
145 pci_write_config_dword(dev_priv
->bridge_dev
, reg
,
146 lower_32_bits(dev_priv
->mch_res
.start
));
150 /* Setup MCHBAR if possible, return true if we should disable it again */
152 intel_setup_mchbar(struct drm_i915_private
*dev_priv
)
154 int mchbar_reg
= INTEL_GEN(dev_priv
) >= 4 ? MCHBAR_I965
: MCHBAR_I915
;
158 if (IS_VALLEYVIEW(dev_priv
) || IS_CHERRYVIEW(dev_priv
))
161 dev_priv
->mchbar_need_disable
= false;
163 if (IS_I915G(dev_priv
) || IS_I915GM(dev_priv
)) {
164 pci_read_config_dword(dev_priv
->bridge_dev
, DEVEN
, &temp
);
165 enabled
= !!(temp
& DEVEN_MCHBAR_EN
);
167 pci_read_config_dword(dev_priv
->bridge_dev
, mchbar_reg
, &temp
);
171 /* If it's already enabled, don't have to do anything */
175 if (intel_alloc_mchbar_resource(dev_priv
))
178 dev_priv
->mchbar_need_disable
= true;
180 /* Space is allocated or reserved, so enable it. */
181 if (IS_I915G(dev_priv
) || IS_I915GM(dev_priv
)) {
182 pci_write_config_dword(dev_priv
->bridge_dev
, DEVEN
,
183 temp
| DEVEN_MCHBAR_EN
);
185 pci_read_config_dword(dev_priv
->bridge_dev
, mchbar_reg
, &temp
);
186 pci_write_config_dword(dev_priv
->bridge_dev
, mchbar_reg
, temp
| 1);
191 intel_teardown_mchbar(struct drm_i915_private
*dev_priv
)
193 int mchbar_reg
= INTEL_GEN(dev_priv
) >= 4 ? MCHBAR_I965
: MCHBAR_I915
;
195 if (dev_priv
->mchbar_need_disable
) {
196 if (IS_I915G(dev_priv
) || IS_I915GM(dev_priv
)) {
199 pci_read_config_dword(dev_priv
->bridge_dev
, DEVEN
,
201 deven_val
&= ~DEVEN_MCHBAR_EN
;
202 pci_write_config_dword(dev_priv
->bridge_dev
, DEVEN
,
207 pci_read_config_dword(dev_priv
->bridge_dev
, mchbar_reg
,
210 pci_write_config_dword(dev_priv
->bridge_dev
, mchbar_reg
,
215 if (dev_priv
->mch_res
.start
)
216 release_resource(&dev_priv
->mch_res
);
219 static int i915_workqueues_init(struct drm_i915_private
*dev_priv
)
222 * The i915 workqueue is primarily used for batched retirement of
223 * requests (and thus managing bo) once the task has been completed
224 * by the GPU. i915_retire_requests() is called directly when we
225 * need high-priority retirement, such as waiting for an explicit
228 * It is also used for periodic low-priority events, such as
229 * idle-timers and recording error state.
231 * All tasks on the workqueue are expected to acquire the dev mutex
232 * so there is no point in running more than one instance of the
233 * workqueue at any time. Use an ordered one.
235 dev_priv
->wq
= alloc_ordered_workqueue("i915", 0);
236 if (dev_priv
->wq
== NULL
)
239 dev_priv
->hotplug
.dp_wq
= alloc_ordered_workqueue("i915-dp", 0);
240 if (dev_priv
->hotplug
.dp_wq
== NULL
)
246 destroy_workqueue(dev_priv
->wq
);
248 drm_err(&dev_priv
->drm
, "Failed to allocate workqueues.\n");
253 static void i915_workqueues_cleanup(struct drm_i915_private
*dev_priv
)
255 destroy_workqueue(dev_priv
->hotplug
.dp_wq
);
256 destroy_workqueue(dev_priv
->wq
);
260 * We don't keep the workarounds for pre-production hardware, so we expect our
261 * driver to fail on these machines in one way or another. A little warning on
262 * dmesg may help both the user and the bug triagers.
264 * Our policy for removing pre-production workarounds is to keep the
265 * current gen workarounds as a guide to the bring-up of the next gen
266 * (workarounds have a habit of persisting!). Anything older than that
267 * should be removed along with the complications they introduce.
269 static void intel_detect_preproduction_hw(struct drm_i915_private
*dev_priv
)
273 pre
|= IS_HSW_EARLY_SDV(dev_priv
);
274 pre
|= IS_SKL_REVID(dev_priv
, 0, SKL_REVID_F0
);
275 pre
|= IS_BXT_REVID(dev_priv
, 0, BXT_REVID_B_LAST
);
276 pre
|= IS_KBL_GT_REVID(dev_priv
, 0, KBL_REVID_A0
);
277 pre
|= IS_GLK_REVID(dev_priv
, 0, GLK_REVID_A2
);
280 drm_err(&dev_priv
->drm
, "This is a pre-production stepping. "
281 "It may not be fully functional.\n");
282 add_taint(TAINT_MACHINE_CHECK
, LOCKDEP_STILL_OK
);
286 static void sanitize_gpu(struct drm_i915_private
*i915
)
288 if (!INTEL_INFO(i915
)->gpu_reset_clobbers_display
)
289 __intel_gt_reset(&i915
->gt
, ALL_ENGINES
);
293 * i915_driver_early_probe - setup state not requiring device access
294 * @dev_priv: device private
296 * Initialize everything that is a "SW-only" state, that is state not
297 * requiring accessing the device or exposing the driver via kernel internal
298 * or userspace interfaces. Example steps belonging here: lock initialization,
299 * system memory allocation, setting up device specific attributes and
300 * function hooks not requiring accessing the device.
302 static int i915_driver_early_probe(struct drm_i915_private
*dev_priv
)
306 if (i915_inject_probe_failure(dev_priv
))
309 intel_device_info_subplatform_init(dev_priv
);
311 intel_uncore_mmio_debug_init_early(&dev_priv
->mmio_debug
);
312 intel_uncore_init_early(&dev_priv
->uncore
, dev_priv
);
314 spin_lock_init(&dev_priv
->irq_lock
);
315 spin_lock_init(&dev_priv
->gpu_error
.lock
);
316 mutex_init(&dev_priv
->backlight_lock
);
318 mutex_init(&dev_priv
->sb_lock
);
319 cpu_latency_qos_add_request(&dev_priv
->sb_qos
, PM_QOS_DEFAULT_VALUE
);
321 mutex_init(&dev_priv
->av_mutex
);
322 mutex_init(&dev_priv
->wm
.wm_mutex
);
323 mutex_init(&dev_priv
->pps_mutex
);
324 mutex_init(&dev_priv
->hdcp_comp_mutex
);
326 i915_memcpy_init_early(dev_priv
);
327 intel_runtime_pm_init_early(&dev_priv
->runtime_pm
);
329 ret
= i915_workqueues_init(dev_priv
);
333 ret
= vlv_suspend_init(dev_priv
);
337 intel_wopcm_init_early(&dev_priv
->wopcm
);
339 intel_gt_init_early(&dev_priv
->gt
, dev_priv
);
341 i915_gem_init_early(dev_priv
);
343 /* This must be called before any calls to HAS_PCH_* */
344 intel_detect_pch(dev_priv
);
346 intel_pm_setup(dev_priv
);
347 ret
= intel_power_domains_init(dev_priv
);
350 intel_irq_init(dev_priv
);
351 intel_init_display_hooks(dev_priv
);
352 intel_init_clock_gating_hooks(dev_priv
);
353 intel_init_audio_hooks(dev_priv
);
355 intel_detect_preproduction_hw(dev_priv
);
360 i915_gem_cleanup_early(dev_priv
);
361 intel_gt_driver_late_release(&dev_priv
->gt
);
362 vlv_suspend_cleanup(dev_priv
);
364 i915_workqueues_cleanup(dev_priv
);
369 * i915_driver_late_release - cleanup the setup done in
370 * i915_driver_early_probe()
371 * @dev_priv: device private
373 static void i915_driver_late_release(struct drm_i915_private
*dev_priv
)
375 intel_irq_fini(dev_priv
);
376 intel_power_domains_cleanup(dev_priv
);
377 i915_gem_cleanup_early(dev_priv
);
378 intel_gt_driver_late_release(&dev_priv
->gt
);
379 vlv_suspend_cleanup(dev_priv
);
380 i915_workqueues_cleanup(dev_priv
);
382 cpu_latency_qos_remove_request(&dev_priv
->sb_qos
);
383 mutex_destroy(&dev_priv
->sb_lock
);
385 i915_params_free(&dev_priv
->params
);
389 * i915_driver_mmio_probe - setup device MMIO
390 * @dev_priv: device private
392 * Setup minimal device state necessary for MMIO accesses later in the
393 * initialization sequence. The setup here should avoid any other device-wide
394 * side effects or exposing the driver via kernel internal or user space
397 static int i915_driver_mmio_probe(struct drm_i915_private
*dev_priv
)
401 if (i915_inject_probe_failure(dev_priv
))
404 if (i915_get_bridge_dev(dev_priv
))
407 ret
= intel_uncore_init_mmio(&dev_priv
->uncore
);
411 /* Try to make sure MCHBAR is enabled before poking at it */
412 intel_setup_mchbar(dev_priv
);
414 ret
= intel_gt_init_mmio(&dev_priv
->gt
);
418 /* As early as possible, scrub existing GPU state before clobbering */
419 sanitize_gpu(dev_priv
);
424 intel_teardown_mchbar(dev_priv
);
425 intel_uncore_fini_mmio(&dev_priv
->uncore
);
427 pci_dev_put(dev_priv
->bridge_dev
);
433 * i915_driver_mmio_release - cleanup the setup done in i915_driver_mmio_probe()
434 * @dev_priv: device private
436 static void i915_driver_mmio_release(struct drm_i915_private
*dev_priv
)
438 intel_teardown_mchbar(dev_priv
);
439 intel_uncore_fini_mmio(&dev_priv
->uncore
);
440 pci_dev_put(dev_priv
->bridge_dev
);
443 static void intel_sanitize_options(struct drm_i915_private
*dev_priv
)
445 intel_gvt_sanitize_options(dev_priv
);
449 * i915_set_dma_info - set all relevant PCI dma info as configured for the
451 * @i915: valid i915 instance
453 * Set the dma max segment size, device and coherent masks. The dma mask set
454 * needs to occur before i915_ggtt_probe_hw.
456 * A couple of platforms have special needs. Address them as well.
459 static int i915_set_dma_info(struct drm_i915_private
*i915
)
461 struct pci_dev
*pdev
= i915
->drm
.pdev
;
462 unsigned int mask_size
= INTEL_INFO(i915
)->dma_mask_size
;
465 GEM_BUG_ON(!mask_size
);
468 * We don't have a max segment size, so set it to the max so sg's
469 * debugging layer doesn't complain
471 dma_set_max_seg_size(&pdev
->dev
, UINT_MAX
);
473 ret
= dma_set_mask(&pdev
->dev
, DMA_BIT_MASK(mask_size
));
477 /* overlay on gen2 is broken and can't address above 1G */
482 * 965GM sometimes incorrectly writes to hardware status page (HWS)
483 * using 32bit addressing, overwriting memory if HWS is located
486 * The documentation also mentions an issue with undefined
487 * behaviour if any general state is accessed within a page above 4GB,
488 * which also needs to be handled carefully.
490 if (IS_I965G(i915
) || IS_I965GM(i915
))
493 ret
= dma_set_coherent_mask(&pdev
->dev
, DMA_BIT_MASK(mask_size
));
500 drm_err(&i915
->drm
, "Can't set DMA mask/consistent mask (%d)\n", ret
);
505 * i915_driver_hw_probe - setup state requiring device access
506 * @dev_priv: device private
508 * Setup state that requires accessing the device, but doesn't require
509 * exposing the driver via kernel internal or userspace interfaces.
511 static int i915_driver_hw_probe(struct drm_i915_private
*dev_priv
)
513 struct pci_dev
*pdev
= dev_priv
->drm
.pdev
;
516 if (i915_inject_probe_failure(dev_priv
))
519 intel_device_info_runtime_init(dev_priv
);
521 if (HAS_PPGTT(dev_priv
)) {
522 if (intel_vgpu_active(dev_priv
) &&
523 !intel_vgpu_has_full_ppgtt(dev_priv
)) {
524 i915_report_error(dev_priv
,
525 "incompatible vGPU found, support for isolated ppGTT required\n");
530 if (HAS_EXECLISTS(dev_priv
)) {
532 * Older GVT emulation depends upon intercepting CSB mmio,
533 * which we no longer use, preferring to use the HWSP cache
536 if (intel_vgpu_active(dev_priv
) &&
537 !intel_vgpu_has_hwsp_emulation(dev_priv
)) {
538 i915_report_error(dev_priv
,
539 "old vGPU host found, support for HWSP emulation required\n");
544 intel_sanitize_options(dev_priv
);
546 /* needs to be done before ggtt probe */
547 intel_dram_edram_detect(dev_priv
);
549 ret
= i915_set_dma_info(dev_priv
);
553 i915_perf_init(dev_priv
);
555 ret
= i915_ggtt_probe_hw(dev_priv
);
559 ret
= drm_fb_helper_remove_conflicting_pci_framebuffers(pdev
, "inteldrmfb");
563 ret
= i915_ggtt_init_hw(dev_priv
);
567 ret
= intel_memory_regions_hw_probe(dev_priv
);
571 intel_gt_init_hw_early(&dev_priv
->gt
, &dev_priv
->ggtt
);
573 ret
= i915_ggtt_enable_hw(dev_priv
);
575 drm_err(&dev_priv
->drm
, "failed to enable GGTT\n");
576 goto err_mem_regions
;
579 pci_set_master(pdev
);
581 intel_gt_init_workarounds(dev_priv
);
583 /* On the 945G/GM, the chipset reports the MSI capability on the
584 * integrated graphics even though the support isn't actually there
585 * according to the published specs. It doesn't appear to function
586 * correctly in testing on 945G.
587 * This may be a side effect of MSI having been made available for PEG
588 * and the registers being closely associated.
590 * According to chipset errata, on the 965GM, MSI interrupts may
591 * be lost or delayed, and was defeatured. MSI interrupts seem to
592 * get lost on g4x as well, and interrupt delivery seems to stay
593 * properly dead afterwards. So we'll just disable them for all
596 * dp aux and gmbus irq on gen4 seems to be able to generate legacy
597 * interrupts even when in MSI mode. This results in spurious
598 * interrupt warnings if the legacy irq no. is shared with another
599 * device. The kernel then disables that interrupt source and so
600 * prevents the other device from working properly.
602 if (INTEL_GEN(dev_priv
) >= 5) {
603 if (pci_enable_msi(pdev
) < 0)
604 drm_dbg(&dev_priv
->drm
, "can't enable MSI");
607 ret
= intel_gvt_init(dev_priv
);
611 intel_opregion_setup(dev_priv
);
613 * Fill the dram structure to get the system raw bandwidth and
614 * dram info. This will be used for memory latency calculation.
616 intel_dram_detect(dev_priv
);
618 intel_pcode_init(dev_priv
);
620 intel_bw_init_hw(dev_priv
);
625 if (pdev
->msi_enabled
)
626 pci_disable_msi(pdev
);
628 intel_memory_regions_driver_release(dev_priv
);
630 i915_ggtt_driver_release(dev_priv
);
632 i915_perf_fini(dev_priv
);
637 * i915_driver_hw_remove - cleanup the setup done in i915_driver_hw_probe()
638 * @dev_priv: device private
640 static void i915_driver_hw_remove(struct drm_i915_private
*dev_priv
)
642 struct pci_dev
*pdev
= dev_priv
->drm
.pdev
;
644 i915_perf_fini(dev_priv
);
646 if (pdev
->msi_enabled
)
647 pci_disable_msi(pdev
);
651 * i915_driver_register - register the driver with the rest of the system
652 * @dev_priv: device private
654 * Perform any steps necessary to make the driver available via kernel
655 * internal or userspace interfaces.
657 static void i915_driver_register(struct drm_i915_private
*dev_priv
)
659 struct drm_device
*dev
= &dev_priv
->drm
;
661 i915_gem_driver_register(dev_priv
);
662 i915_pmu_register(dev_priv
);
664 intel_vgpu_register(dev_priv
);
666 /* Reveal our presence to userspace */
667 if (drm_dev_register(dev
, 0) == 0) {
668 i915_debugfs_register(dev_priv
);
669 if (HAS_DISPLAY(dev_priv
))
670 intel_display_debugfs_register(dev_priv
);
671 i915_setup_sysfs(dev_priv
);
673 /* Depends on sysfs having been initialized */
674 i915_perf_register(dev_priv
);
676 drm_err(&dev_priv
->drm
,
677 "Failed to register driver for userspace access!\n");
679 if (HAS_DISPLAY(dev_priv
)) {
680 /* Must be done after probing outputs */
681 intel_opregion_register(dev_priv
);
682 acpi_video_register();
685 intel_gt_driver_register(&dev_priv
->gt
);
687 intel_audio_init(dev_priv
);
690 * Some ports require correctly set-up hpd registers for detection to
691 * work properly (leading to ghost connected connector status), e.g. VGA
692 * on gm45. Hence we can only set up the initial fbdev config after hpd
693 * irqs are fully enabled. We do it last so that the async config
694 * cannot run before the connectors are registered.
696 intel_fbdev_initial_config_async(dev
);
699 * We need to coordinate the hotplugs with the asynchronous fbdev
700 * configuration, for which we use the fbdev->async_cookie.
702 if (HAS_DISPLAY(dev_priv
))
703 drm_kms_helper_poll_init(dev
);
705 intel_power_domains_enable(dev_priv
);
706 intel_runtime_pm_enable(&dev_priv
->runtime_pm
);
708 intel_register_dsm_handler();
710 if (i915_switcheroo_register(dev_priv
))
711 drm_err(&dev_priv
->drm
, "Failed to register vga switcheroo!\n");
715 * i915_driver_unregister - cleanup the registration done in i915_driver_regiser()
716 * @dev_priv: device private
718 static void i915_driver_unregister(struct drm_i915_private
*dev_priv
)
720 i915_switcheroo_unregister(dev_priv
);
722 intel_unregister_dsm_handler();
724 intel_runtime_pm_disable(&dev_priv
->runtime_pm
);
725 intel_power_domains_disable(dev_priv
);
727 intel_fbdev_unregister(dev_priv
);
728 intel_audio_deinit(dev_priv
);
731 * After flushing the fbdev (incl. a late async config which will
732 * have delayed queuing of a hotplug event), then flush the hotplug
735 drm_kms_helper_poll_fini(&dev_priv
->drm
);
737 intel_gt_driver_unregister(&dev_priv
->gt
);
738 acpi_video_unregister();
739 intel_opregion_unregister(dev_priv
);
741 i915_perf_unregister(dev_priv
);
742 i915_pmu_unregister(dev_priv
);
744 i915_teardown_sysfs(dev_priv
);
745 drm_dev_unplug(&dev_priv
->drm
);
747 i915_gem_driver_unregister(dev_priv
);
750 static void i915_welcome_messages(struct drm_i915_private
*dev_priv
)
752 if (drm_debug_enabled(DRM_UT_DRIVER
)) {
753 struct drm_printer p
= drm_debug_printer("i915 device info:");
755 drm_printf(&p
, "pciid=0x%04x rev=0x%02x platform=%s (subplatform=0x%x) gen=%i\n",
756 INTEL_DEVID(dev_priv
),
757 INTEL_REVID(dev_priv
),
758 intel_platform_name(INTEL_INFO(dev_priv
)->platform
),
759 intel_subplatform(RUNTIME_INFO(dev_priv
),
760 INTEL_INFO(dev_priv
)->platform
),
761 INTEL_GEN(dev_priv
));
763 intel_device_info_print_static(INTEL_INFO(dev_priv
), &p
);
764 intel_device_info_print_runtime(RUNTIME_INFO(dev_priv
), &p
);
765 intel_gt_info_print(&dev_priv
->gt
.info
, &p
);
768 if (IS_ENABLED(CONFIG_DRM_I915_DEBUG
))
769 drm_info(&dev_priv
->drm
, "DRM_I915_DEBUG enabled\n");
770 if (IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM
))
771 drm_info(&dev_priv
->drm
, "DRM_I915_DEBUG_GEM enabled\n");
772 if (IS_ENABLED(CONFIG_DRM_I915_DEBUG_RUNTIME_PM
))
773 drm_info(&dev_priv
->drm
,
774 "DRM_I915_DEBUG_RUNTIME_PM enabled\n");
777 static struct drm_i915_private
*
778 i915_driver_create(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
780 const struct intel_device_info
*match_info
=
781 (struct intel_device_info
*)ent
->driver_data
;
782 struct intel_device_info
*device_info
;
783 struct drm_i915_private
*i915
;
785 i915
= devm_drm_dev_alloc(&pdev
->dev
, &driver
,
786 struct drm_i915_private
, drm
);
790 i915
->drm
.pdev
= pdev
;
791 pci_set_drvdata(pdev
, i915
);
793 /* Device parameters start as a copy of module parameters. */
794 i915_params_copy(&i915
->params
, &i915_modparams
);
796 /* Setup the write-once "constant" device info */
797 device_info
= mkwrite_device_info(i915
);
798 memcpy(device_info
, match_info
, sizeof(*device_info
));
799 RUNTIME_INFO(i915
)->device_id
= pdev
->device
;
801 BUG_ON(device_info
->gen
> BITS_PER_TYPE(device_info
->gen_mask
));
807 * i915_driver_probe - setup chip and create an initial config
809 * @ent: matching PCI ID entry
811 * The driver probe routine has to do several things:
812 * - drive output discovery via intel_modeset_init()
813 * - initialize the memory manager
814 * - allocate initial config memory
815 * - setup the DRM framebuffer with the allocated memory
817 int i915_driver_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
819 const struct intel_device_info
*match_info
=
820 (struct intel_device_info
*)ent
->driver_data
;
821 struct drm_i915_private
*i915
;
824 i915
= i915_driver_create(pdev
, ent
);
826 return PTR_ERR(i915
);
828 /* Disable nuclear pageflip by default on pre-ILK */
829 if (!i915
->params
.nuclear_pageflip
&& match_info
->gen
< 5)
830 i915
->drm
.driver_features
&= ~DRIVER_ATOMIC
;
833 * Check if we support fake LMEM -- for now we only unleash this for
834 * the live selftests(test-and-exit).
836 #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
837 if (IS_ENABLED(CONFIG_DRM_I915_UNSTABLE_FAKE_LMEM
)) {
838 if (INTEL_GEN(i915
) >= 9 && i915_selftest
.live
< 0 &&
839 i915
->params
.fake_lmem_start
) {
840 mkwrite_device_info(i915
)->memory_regions
=
841 REGION_SMEM
| REGION_LMEM
| REGION_STOLEN
;
842 GEM_BUG_ON(!HAS_LMEM(i915
));
847 ret
= pci_enable_device(pdev
);
851 ret
= i915_driver_early_probe(i915
);
853 goto out_pci_disable
;
855 disable_rpm_wakeref_asserts(&i915
->runtime_pm
);
857 intel_vgpu_detect(i915
);
859 ret
= i915_driver_mmio_probe(i915
);
861 goto out_runtime_pm_put
;
863 ret
= i915_driver_hw_probe(i915
);
865 goto out_cleanup_mmio
;
867 ret
= intel_modeset_init_noirq(i915
);
871 ret
= intel_irq_install(i915
);
873 goto out_cleanup_modeset
;
875 ret
= intel_modeset_init_nogem(i915
);
877 goto out_cleanup_irq
;
879 ret
= i915_gem_init(i915
);
881 goto out_cleanup_modeset2
;
883 ret
= intel_modeset_init(i915
);
885 goto out_cleanup_gem
;
887 i915_driver_register(i915
);
889 enable_rpm_wakeref_asserts(&i915
->runtime_pm
);
891 i915_welcome_messages(i915
);
893 i915
->do_release
= true;
898 i915_gem_suspend(i915
);
899 i915_gem_driver_remove(i915
);
900 i915_gem_driver_release(i915
);
901 out_cleanup_modeset2
:
902 /* FIXME clean up the error path */
903 intel_modeset_driver_remove(i915
);
904 intel_irq_uninstall(i915
);
905 intel_modeset_driver_remove_noirq(i915
);
906 goto out_cleanup_modeset
;
908 intel_irq_uninstall(i915
);
910 intel_modeset_driver_remove_nogem(i915
);
912 i915_driver_hw_remove(i915
);
913 intel_memory_regions_driver_release(i915
);
914 i915_ggtt_driver_release(i915
);
916 i915_driver_mmio_release(i915
);
918 enable_rpm_wakeref_asserts(&i915
->runtime_pm
);
919 i915_driver_late_release(i915
);
921 pci_disable_device(pdev
);
923 i915_probe_error(i915
, "Device initialization failed (%d)\n", ret
);
927 void i915_driver_remove(struct drm_i915_private
*i915
)
929 disable_rpm_wakeref_asserts(&i915
->runtime_pm
);
931 i915_driver_unregister(i915
);
933 /* Flush any external code that still may be under the RCU lock */
936 i915_gem_suspend(i915
);
938 drm_atomic_helper_shutdown(&i915
->drm
);
940 intel_gvt_driver_remove(i915
);
942 intel_modeset_driver_remove(i915
);
944 intel_irq_uninstall(i915
);
946 intel_modeset_driver_remove_noirq(i915
);
948 i915_reset_error_state(i915
);
949 i915_gem_driver_remove(i915
);
951 intel_modeset_driver_remove_nogem(i915
);
953 i915_driver_hw_remove(i915
);
955 enable_rpm_wakeref_asserts(&i915
->runtime_pm
);
958 static void i915_driver_release(struct drm_device
*dev
)
960 struct drm_i915_private
*dev_priv
= to_i915(dev
);
961 struct intel_runtime_pm
*rpm
= &dev_priv
->runtime_pm
;
963 if (!dev_priv
->do_release
)
966 disable_rpm_wakeref_asserts(rpm
);
968 i915_gem_driver_release(dev_priv
);
970 intel_memory_regions_driver_release(dev_priv
);
971 i915_ggtt_driver_release(dev_priv
);
972 i915_gem_drain_freed_objects(dev_priv
);
974 i915_driver_mmio_release(dev_priv
);
976 enable_rpm_wakeref_asserts(rpm
);
977 intel_runtime_pm_driver_release(rpm
);
979 i915_driver_late_release(dev_priv
);
982 static int i915_driver_open(struct drm_device
*dev
, struct drm_file
*file
)
984 struct drm_i915_private
*i915
= to_i915(dev
);
987 ret
= i915_gem_open(i915
, file
);
995 * i915_driver_lastclose - clean up after all DRM clients have exited
998 * Take care of cleaning up after all DRM clients have exited. In the
999 * mode setting case, we want to restore the kernel's initial mode (just
1000 * in case the last client left us in a bad state).
1002 * Additionally, in the non-mode setting case, we'll tear down the GTT
1003 * and DMA structures, since the kernel won't be using them, and clea
1006 static void i915_driver_lastclose(struct drm_device
*dev
)
1008 intel_fbdev_restore_mode(dev
);
1009 vga_switcheroo_process_delayed_switch();
1012 static void i915_driver_postclose(struct drm_device
*dev
, struct drm_file
*file
)
1014 struct drm_i915_file_private
*file_priv
= file
->driver_priv
;
1016 i915_gem_context_close(file
);
1018 kfree_rcu(file_priv
, rcu
);
1020 /* Catch up with all the deferred frees from "this" client */
1021 i915_gem_flush_free_objects(to_i915(dev
));
1024 static void intel_suspend_encoders(struct drm_i915_private
*dev_priv
)
1026 struct drm_device
*dev
= &dev_priv
->drm
;
1027 struct intel_encoder
*encoder
;
1029 drm_modeset_lock_all(dev
);
1030 for_each_intel_encoder(dev
, encoder
)
1031 if (encoder
->suspend
)
1032 encoder
->suspend(encoder
);
1033 drm_modeset_unlock_all(dev
);
1036 static void intel_shutdown_encoders(struct drm_i915_private
*dev_priv
)
1038 struct drm_device
*dev
= &dev_priv
->drm
;
1039 struct intel_encoder
*encoder
;
1041 drm_modeset_lock_all(dev
);
1042 for_each_intel_encoder(dev
, encoder
)
1043 if (encoder
->shutdown
)
1044 encoder
->shutdown(encoder
);
1045 drm_modeset_unlock_all(dev
);
1048 void i915_driver_shutdown(struct drm_i915_private
*i915
)
1050 disable_rpm_wakeref_asserts(&i915
->runtime_pm
);
1052 i915_gem_suspend(i915
);
1054 drm_kms_helper_poll_disable(&i915
->drm
);
1056 drm_atomic_helper_shutdown(&i915
->drm
);
1058 intel_dp_mst_suspend(i915
);
1060 intel_runtime_pm_disable_interrupts(i915
);
1061 intel_hpd_cancel_work(i915
);
1063 intel_suspend_encoders(i915
);
1064 intel_shutdown_encoders(i915
);
1066 enable_rpm_wakeref_asserts(&i915
->runtime_pm
);
1069 static bool suspend_to_idle(struct drm_i915_private
*dev_priv
)
1071 #if IS_ENABLED(CONFIG_ACPI_SLEEP)
1072 if (acpi_target_system_state() < ACPI_STATE_S3
)
1078 static int i915_drm_prepare(struct drm_device
*dev
)
1080 struct drm_i915_private
*i915
= to_i915(dev
);
1083 * NB intel_display_suspend() may issue new requests after we've
1084 * ostensibly marked the GPU as ready-to-sleep here. We need to
1085 * split out that work and pull it forward so that after point,
1086 * the GPU is not woken again.
1088 i915_gem_suspend(i915
);
1093 static int i915_drm_suspend(struct drm_device
*dev
)
1095 struct drm_i915_private
*dev_priv
= to_i915(dev
);
1096 struct pci_dev
*pdev
= dev_priv
->drm
.pdev
;
1097 pci_power_t opregion_target_state
;
1099 disable_rpm_wakeref_asserts(&dev_priv
->runtime_pm
);
1101 /* We do a lot of poking in a lot of registers, make sure they work
1103 intel_power_domains_disable(dev_priv
);
1105 drm_kms_helper_poll_disable(dev
);
1107 pci_save_state(pdev
);
1109 intel_display_suspend(dev
);
1111 intel_dp_mst_suspend(dev_priv
);
1113 intel_runtime_pm_disable_interrupts(dev_priv
);
1114 intel_hpd_cancel_work(dev_priv
);
1116 intel_suspend_encoders(dev_priv
);
1118 intel_suspend_hw(dev_priv
);
1120 i915_ggtt_suspend(&dev_priv
->ggtt
);
1122 i915_save_display(dev_priv
);
1124 opregion_target_state
= suspend_to_idle(dev_priv
) ? PCI_D1
: PCI_D3cold
;
1125 intel_opregion_suspend(dev_priv
, opregion_target_state
);
1127 intel_fbdev_set_suspend(dev
, FBINFO_STATE_SUSPENDED
, true);
1129 dev_priv
->suspend_count
++;
1131 intel_csr_ucode_suspend(dev_priv
);
1133 enable_rpm_wakeref_asserts(&dev_priv
->runtime_pm
);
1138 static enum i915_drm_suspend_mode
1139 get_suspend_mode(struct drm_i915_private
*dev_priv
, bool hibernate
)
1142 return I915_DRM_SUSPEND_HIBERNATE
;
1144 if (suspend_to_idle(dev_priv
))
1145 return I915_DRM_SUSPEND_IDLE
;
1147 return I915_DRM_SUSPEND_MEM
;
1150 static int i915_drm_suspend_late(struct drm_device
*dev
, bool hibernation
)
1152 struct drm_i915_private
*dev_priv
= to_i915(dev
);
1153 struct pci_dev
*pdev
= dev_priv
->drm
.pdev
;
1154 struct intel_runtime_pm
*rpm
= &dev_priv
->runtime_pm
;
1157 disable_rpm_wakeref_asserts(rpm
);
1159 i915_gem_suspend_late(dev_priv
);
1161 intel_uncore_suspend(&dev_priv
->uncore
);
1163 intel_power_domains_suspend(dev_priv
,
1164 get_suspend_mode(dev_priv
, hibernation
));
1166 intel_display_power_suspend_late(dev_priv
);
1168 ret
= vlv_suspend_complete(dev_priv
);
1170 drm_err(&dev_priv
->drm
, "Suspend complete failed: %d\n", ret
);
1171 intel_power_domains_resume(dev_priv
);
1176 pci_disable_device(pdev
);
1178 * During hibernation on some platforms the BIOS may try to access
1179 * the device even though it's already in D3 and hang the machine. So
1180 * leave the device in D0 on those platforms and hope the BIOS will
1181 * power down the device properly. The issue was seen on multiple old
1182 * GENs with different BIOS vendors, so having an explicit blacklist
1183 * is inpractical; apply the workaround on everything pre GEN6. The
1184 * platforms where the issue was seen:
1185 * Lenovo Thinkpad X301, X61s, X60, T60, X41
1189 if (!(hibernation
&& INTEL_GEN(dev_priv
) < 6))
1190 pci_set_power_state(pdev
, PCI_D3hot
);
1193 enable_rpm_wakeref_asserts(rpm
);
1194 if (!dev_priv
->uncore
.user_forcewake_count
)
1195 intel_runtime_pm_driver_release(rpm
);
1200 int i915_suspend_switcheroo(struct drm_i915_private
*i915
, pm_message_t state
)
1204 if (drm_WARN_ON_ONCE(&i915
->drm
, state
.event
!= PM_EVENT_SUSPEND
&&
1205 state
.event
!= PM_EVENT_FREEZE
))
1208 if (i915
->drm
.switch_power_state
== DRM_SWITCH_POWER_OFF
)
1211 error
= i915_drm_suspend(&i915
->drm
);
1215 return i915_drm_suspend_late(&i915
->drm
, false);
1218 static int i915_drm_resume(struct drm_device
*dev
)
1220 struct drm_i915_private
*dev_priv
= to_i915(dev
);
1223 disable_rpm_wakeref_asserts(&dev_priv
->runtime_pm
);
1225 sanitize_gpu(dev_priv
);
1227 ret
= i915_ggtt_enable_hw(dev_priv
);
1229 drm_err(&dev_priv
->drm
, "failed to re-enable GGTT\n");
1231 i915_ggtt_resume(&dev_priv
->ggtt
);
1233 intel_csr_ucode_resume(dev_priv
);
1235 i915_restore_display(dev_priv
);
1236 intel_pps_unlock_regs_wa(dev_priv
);
1238 intel_init_pch_refclk(dev_priv
);
1241 * Interrupts have to be enabled before any batches are run. If not the
1242 * GPU will hang. i915_gem_init_hw() will initiate batches to
1243 * update/restore the context.
1245 * drm_mode_config_reset() needs AUX interrupts.
1247 * Modeset enabling in intel_modeset_init_hw() also needs working
1250 intel_runtime_pm_enable_interrupts(dev_priv
);
1252 drm_mode_config_reset(dev
);
1254 i915_gem_resume(dev_priv
);
1256 intel_modeset_init_hw(dev_priv
);
1257 intel_init_clock_gating(dev_priv
);
1258 intel_hpd_init(dev_priv
);
1260 /* MST sideband requires HPD interrupts enabled */
1261 intel_dp_mst_resume(dev_priv
);
1262 intel_display_resume(dev
);
1264 intel_hpd_poll_disable(dev_priv
);
1265 drm_kms_helper_poll_enable(dev
);
1267 intel_opregion_resume(dev_priv
);
1269 intel_fbdev_set_suspend(dev
, FBINFO_STATE_RUNNING
, false);
1271 intel_power_domains_enable(dev_priv
);
1273 intel_gvt_resume(dev_priv
);
1275 enable_rpm_wakeref_asserts(&dev_priv
->runtime_pm
);
1280 static int i915_drm_resume_early(struct drm_device
*dev
)
1282 struct drm_i915_private
*dev_priv
= to_i915(dev
);
1283 struct pci_dev
*pdev
= dev_priv
->drm
.pdev
;
1287 * We have a resume ordering issue with the snd-hda driver also
1288 * requiring our device to be power up. Due to the lack of a
1289 * parent/child relationship we currently solve this with an early
1292 * FIXME: This should be solved with a special hdmi sink device or
1293 * similar so that power domains can be employed.
1297 * Note that we need to set the power state explicitly, since we
1298 * powered off the device during freeze and the PCI core won't power
1299 * it back up for us during thaw. Powering off the device during
1300 * freeze is not a hard requirement though, and during the
1301 * suspend/resume phases the PCI core makes sure we get here with the
1302 * device powered on. So in case we change our freeze logic and keep
1303 * the device powered we can also remove the following set power state
1306 ret
= pci_set_power_state(pdev
, PCI_D0
);
1308 drm_err(&dev_priv
->drm
,
1309 "failed to set PCI D0 power state (%d)\n", ret
);
1314 * Note that pci_enable_device() first enables any parent bridge
1315 * device and only then sets the power state for this device. The
1316 * bridge enabling is a nop though, since bridge devices are resumed
1317 * first. The order of enabling power and enabling the device is
1318 * imposed by the PCI core as described above, so here we preserve the
1319 * same order for the freeze/thaw phases.
1321 * TODO: eventually we should remove pci_disable_device() /
1322 * pci_enable_enable_device() from suspend/resume. Due to how they
1323 * depend on the device enable refcount we can't anyway depend on them
1324 * disabling/enabling the device.
1326 if (pci_enable_device(pdev
))
1329 pci_set_master(pdev
);
1331 disable_rpm_wakeref_asserts(&dev_priv
->runtime_pm
);
1333 ret
= vlv_resume_prepare(dev_priv
, false);
1335 drm_err(&dev_priv
->drm
,
1336 "Resume prepare failed: %d, continuing anyway\n", ret
);
1338 intel_uncore_resume_early(&dev_priv
->uncore
);
1340 intel_gt_check_and_clear_faults(&dev_priv
->gt
);
1342 intel_display_power_resume_early(dev_priv
);
1344 intel_power_domains_resume(dev_priv
);
1346 enable_rpm_wakeref_asserts(&dev_priv
->runtime_pm
);
1351 int i915_resume_switcheroo(struct drm_i915_private
*i915
)
1355 if (i915
->drm
.switch_power_state
== DRM_SWITCH_POWER_OFF
)
1358 ret
= i915_drm_resume_early(&i915
->drm
);
1362 return i915_drm_resume(&i915
->drm
);
1365 static int i915_pm_prepare(struct device
*kdev
)
1367 struct drm_i915_private
*i915
= kdev_to_i915(kdev
);
1370 dev_err(kdev
, "DRM not initialized, aborting suspend.\n");
1374 if (i915
->drm
.switch_power_state
== DRM_SWITCH_POWER_OFF
)
1377 return i915_drm_prepare(&i915
->drm
);
1380 static int i915_pm_suspend(struct device
*kdev
)
1382 struct drm_i915_private
*i915
= kdev_to_i915(kdev
);
1385 dev_err(kdev
, "DRM not initialized, aborting suspend.\n");
1389 if (i915
->drm
.switch_power_state
== DRM_SWITCH_POWER_OFF
)
1392 return i915_drm_suspend(&i915
->drm
);
1395 static int i915_pm_suspend_late(struct device
*kdev
)
1397 struct drm_i915_private
*i915
= kdev_to_i915(kdev
);
1400 * We have a suspend ordering issue with the snd-hda driver also
1401 * requiring our device to be power up. Due to the lack of a
1402 * parent/child relationship we currently solve this with an late
1405 * FIXME: This should be solved with a special hdmi sink device or
1406 * similar so that power domains can be employed.
1408 if (i915
->drm
.switch_power_state
== DRM_SWITCH_POWER_OFF
)
1411 return i915_drm_suspend_late(&i915
->drm
, false);
1414 static int i915_pm_poweroff_late(struct device
*kdev
)
1416 struct drm_i915_private
*i915
= kdev_to_i915(kdev
);
1418 if (i915
->drm
.switch_power_state
== DRM_SWITCH_POWER_OFF
)
1421 return i915_drm_suspend_late(&i915
->drm
, true);
1424 static int i915_pm_resume_early(struct device
*kdev
)
1426 struct drm_i915_private
*i915
= kdev_to_i915(kdev
);
1428 if (i915
->drm
.switch_power_state
== DRM_SWITCH_POWER_OFF
)
1431 return i915_drm_resume_early(&i915
->drm
);
1434 static int i915_pm_resume(struct device
*kdev
)
1436 struct drm_i915_private
*i915
= kdev_to_i915(kdev
);
1438 if (i915
->drm
.switch_power_state
== DRM_SWITCH_POWER_OFF
)
1441 return i915_drm_resume(&i915
->drm
);
1444 /* freeze: before creating the hibernation_image */
1445 static int i915_pm_freeze(struct device
*kdev
)
1447 struct drm_i915_private
*i915
= kdev_to_i915(kdev
);
1450 if (i915
->drm
.switch_power_state
!= DRM_SWITCH_POWER_OFF
) {
1451 ret
= i915_drm_suspend(&i915
->drm
);
1456 ret
= i915_gem_freeze(i915
);
1463 static int i915_pm_freeze_late(struct device
*kdev
)
1465 struct drm_i915_private
*i915
= kdev_to_i915(kdev
);
1468 if (i915
->drm
.switch_power_state
!= DRM_SWITCH_POWER_OFF
) {
1469 ret
= i915_drm_suspend_late(&i915
->drm
, true);
1474 ret
= i915_gem_freeze_late(i915
);
1481 /* thaw: called after creating the hibernation image, but before turning off. */
1482 static int i915_pm_thaw_early(struct device
*kdev
)
1484 return i915_pm_resume_early(kdev
);
1487 static int i915_pm_thaw(struct device
*kdev
)
1489 return i915_pm_resume(kdev
);
1492 /* restore: called after loading the hibernation image. */
1493 static int i915_pm_restore_early(struct device
*kdev
)
1495 return i915_pm_resume_early(kdev
);
1498 static int i915_pm_restore(struct device
*kdev
)
1500 return i915_pm_resume(kdev
);
1503 static int intel_runtime_suspend(struct device
*kdev
)
1505 struct drm_i915_private
*dev_priv
= kdev_to_i915(kdev
);
1506 struct intel_runtime_pm
*rpm
= &dev_priv
->runtime_pm
;
1509 if (drm_WARN_ON_ONCE(&dev_priv
->drm
, !HAS_RUNTIME_PM(dev_priv
)))
1512 drm_dbg_kms(&dev_priv
->drm
, "Suspending device\n");
1514 disable_rpm_wakeref_asserts(rpm
);
1517 * We are safe here against re-faults, since the fault handler takes
1520 i915_gem_runtime_suspend(dev_priv
);
1522 intel_gt_runtime_suspend(&dev_priv
->gt
);
1524 intel_runtime_pm_disable_interrupts(dev_priv
);
1526 intel_uncore_suspend(&dev_priv
->uncore
);
1528 intel_display_power_suspend(dev_priv
);
1530 ret
= vlv_suspend_complete(dev_priv
);
1532 drm_err(&dev_priv
->drm
,
1533 "Runtime suspend failed, disabling it (%d)\n", ret
);
1534 intel_uncore_runtime_resume(&dev_priv
->uncore
);
1536 intel_runtime_pm_enable_interrupts(dev_priv
);
1538 intel_gt_runtime_resume(&dev_priv
->gt
);
1540 enable_rpm_wakeref_asserts(rpm
);
1545 enable_rpm_wakeref_asserts(rpm
);
1546 intel_runtime_pm_driver_release(rpm
);
1548 if (intel_uncore_arm_unclaimed_mmio_detection(&dev_priv
->uncore
))
1549 drm_err(&dev_priv
->drm
,
1550 "Unclaimed access detected prior to suspending\n");
1552 rpm
->suspended
= true;
1555 * FIXME: We really should find a document that references the arguments
1558 if (IS_BROADWELL(dev_priv
)) {
1560 * On Broadwell, if we use PCI_D1 the PCH DDI ports will stop
1561 * being detected, and the call we do at intel_runtime_resume()
1562 * won't be able to restore them. Since PCI_D3hot matches the
1563 * actual specification and appears to be working, use it.
1565 intel_opregion_notify_adapter(dev_priv
, PCI_D3hot
);
1568 * current versions of firmware which depend on this opregion
1569 * notification have repurposed the D1 definition to mean
1570 * "runtime suspended" vs. what you would normally expect (D3)
1571 * to distinguish it from notifications that might be sent via
1574 intel_opregion_notify_adapter(dev_priv
, PCI_D1
);
1577 assert_forcewakes_inactive(&dev_priv
->uncore
);
1579 if (!IS_VALLEYVIEW(dev_priv
) && !IS_CHERRYVIEW(dev_priv
))
1580 intel_hpd_poll_enable(dev_priv
);
1582 drm_dbg_kms(&dev_priv
->drm
, "Device suspended\n");
1586 static int intel_runtime_resume(struct device
*kdev
)
1588 struct drm_i915_private
*dev_priv
= kdev_to_i915(kdev
);
1589 struct intel_runtime_pm
*rpm
= &dev_priv
->runtime_pm
;
1592 if (drm_WARN_ON_ONCE(&dev_priv
->drm
, !HAS_RUNTIME_PM(dev_priv
)))
1595 drm_dbg_kms(&dev_priv
->drm
, "Resuming device\n");
1597 drm_WARN_ON_ONCE(&dev_priv
->drm
, atomic_read(&rpm
->wakeref_count
));
1598 disable_rpm_wakeref_asserts(rpm
);
1600 intel_opregion_notify_adapter(dev_priv
, PCI_D0
);
1601 rpm
->suspended
= false;
1602 if (intel_uncore_unclaimed_mmio(&dev_priv
->uncore
))
1603 drm_dbg(&dev_priv
->drm
,
1604 "Unclaimed access during suspend, bios?\n");
1606 intel_display_power_resume(dev_priv
);
1608 ret
= vlv_resume_prepare(dev_priv
, true);
1610 intel_uncore_runtime_resume(&dev_priv
->uncore
);
1612 intel_runtime_pm_enable_interrupts(dev_priv
);
1615 * No point of rolling back things in case of an error, as the best
1616 * we can do is to hope that things will still work (and disable RPM).
1618 intel_gt_runtime_resume(&dev_priv
->gt
);
1621 * On VLV/CHV display interrupts are part of the display
1622 * power well, so hpd is reinitialized from there. For
1623 * everyone else do it here.
1625 if (!IS_VALLEYVIEW(dev_priv
) && !IS_CHERRYVIEW(dev_priv
)) {
1626 intel_hpd_init(dev_priv
);
1627 intel_hpd_poll_disable(dev_priv
);
1630 intel_enable_ipc(dev_priv
);
1632 enable_rpm_wakeref_asserts(rpm
);
1635 drm_err(&dev_priv
->drm
,
1636 "Runtime resume failed, disabling it (%d)\n", ret
);
1638 drm_dbg_kms(&dev_priv
->drm
, "Device resumed\n");
1643 const struct dev_pm_ops i915_pm_ops
= {
1645 * S0ix (via system suspend) and S3 event handlers [PMSG_SUSPEND,
1648 .prepare
= i915_pm_prepare
,
1649 .suspend
= i915_pm_suspend
,
1650 .suspend_late
= i915_pm_suspend_late
,
1651 .resume_early
= i915_pm_resume_early
,
1652 .resume
= i915_pm_resume
,
1656 * @freeze, @freeze_late : called (1) before creating the
1657 * hibernation image [PMSG_FREEZE] and
1658 * (2) after rebooting, before restoring
1659 * the image [PMSG_QUIESCE]
1660 * @thaw, @thaw_early : called (1) after creating the hibernation
1661 * image, before writing it [PMSG_THAW]
1662 * and (2) after failing to create or
1663 * restore the image [PMSG_RECOVER]
1664 * @poweroff, @poweroff_late: called after writing the hibernation
1665 * image, before rebooting [PMSG_HIBERNATE]
1666 * @restore, @restore_early : called after rebooting and restoring the
1667 * hibernation image [PMSG_RESTORE]
1669 .freeze
= i915_pm_freeze
,
1670 .freeze_late
= i915_pm_freeze_late
,
1671 .thaw_early
= i915_pm_thaw_early
,
1672 .thaw
= i915_pm_thaw
,
1673 .poweroff
= i915_pm_suspend
,
1674 .poweroff_late
= i915_pm_poweroff_late
,
1675 .restore_early
= i915_pm_restore_early
,
1676 .restore
= i915_pm_restore
,
1678 /* S0ix (via runtime suspend) event handlers */
1679 .runtime_suspend
= intel_runtime_suspend
,
1680 .runtime_resume
= intel_runtime_resume
,
1683 static const struct file_operations i915_driver_fops
= {
1684 .owner
= THIS_MODULE
,
1686 .release
= drm_release_noglobal
,
1687 .unlocked_ioctl
= drm_ioctl
,
1688 .mmap
= i915_gem_mmap
,
1691 .compat_ioctl
= i915_ioc32_compat_ioctl
,
1692 .llseek
= noop_llseek
,
1696 i915_gem_reject_pin_ioctl(struct drm_device
*dev
, void *data
,
1697 struct drm_file
*file
)
1702 static const struct drm_ioctl_desc i915_ioctls
[] = {
1703 DRM_IOCTL_DEF_DRV(I915_INIT
, drm_noop
, DRM_AUTH
|DRM_MASTER
|DRM_ROOT_ONLY
),
1704 DRM_IOCTL_DEF_DRV(I915_FLUSH
, drm_noop
, DRM_AUTH
),
1705 DRM_IOCTL_DEF_DRV(I915_FLIP
, drm_noop
, DRM_AUTH
),
1706 DRM_IOCTL_DEF_DRV(I915_BATCHBUFFER
, drm_noop
, DRM_AUTH
),
1707 DRM_IOCTL_DEF_DRV(I915_IRQ_EMIT
, drm_noop
, DRM_AUTH
),
1708 DRM_IOCTL_DEF_DRV(I915_IRQ_WAIT
, drm_noop
, DRM_AUTH
),
1709 DRM_IOCTL_DEF_DRV(I915_GETPARAM
, i915_getparam_ioctl
, DRM_RENDER_ALLOW
),
1710 DRM_IOCTL_DEF_DRV(I915_SETPARAM
, drm_noop
, DRM_AUTH
|DRM_MASTER
|DRM_ROOT_ONLY
),
1711 DRM_IOCTL_DEF_DRV(I915_ALLOC
, drm_noop
, DRM_AUTH
),
1712 DRM_IOCTL_DEF_DRV(I915_FREE
, drm_noop
, DRM_AUTH
),
1713 DRM_IOCTL_DEF_DRV(I915_INIT_HEAP
, drm_noop
, DRM_AUTH
|DRM_MASTER
|DRM_ROOT_ONLY
),
1714 DRM_IOCTL_DEF_DRV(I915_CMDBUFFER
, drm_noop
, DRM_AUTH
),
1715 DRM_IOCTL_DEF_DRV(I915_DESTROY_HEAP
, drm_noop
, DRM_AUTH
|DRM_MASTER
|DRM_ROOT_ONLY
),
1716 DRM_IOCTL_DEF_DRV(I915_SET_VBLANK_PIPE
, drm_noop
, DRM_AUTH
|DRM_MASTER
|DRM_ROOT_ONLY
),
1717 DRM_IOCTL_DEF_DRV(I915_GET_VBLANK_PIPE
, drm_noop
, DRM_AUTH
),
1718 DRM_IOCTL_DEF_DRV(I915_VBLANK_SWAP
, drm_noop
, DRM_AUTH
),
1719 DRM_IOCTL_DEF_DRV(I915_HWS_ADDR
, drm_noop
, DRM_AUTH
|DRM_MASTER
|DRM_ROOT_ONLY
),
1720 DRM_IOCTL_DEF_DRV(I915_GEM_INIT
, drm_noop
, DRM_AUTH
|DRM_MASTER
|DRM_ROOT_ONLY
),
1721 DRM_IOCTL_DEF_DRV(I915_GEM_EXECBUFFER
, i915_gem_execbuffer_ioctl
, DRM_AUTH
),
1722 DRM_IOCTL_DEF_DRV(I915_GEM_EXECBUFFER2_WR
, i915_gem_execbuffer2_ioctl
, DRM_RENDER_ALLOW
),
1723 DRM_IOCTL_DEF_DRV(I915_GEM_PIN
, i915_gem_reject_pin_ioctl
, DRM_AUTH
|DRM_ROOT_ONLY
),
1724 DRM_IOCTL_DEF_DRV(I915_GEM_UNPIN
, i915_gem_reject_pin_ioctl
, DRM_AUTH
|DRM_ROOT_ONLY
),
1725 DRM_IOCTL_DEF_DRV(I915_GEM_BUSY
, i915_gem_busy_ioctl
, DRM_RENDER_ALLOW
),
1726 DRM_IOCTL_DEF_DRV(I915_GEM_SET_CACHING
, i915_gem_set_caching_ioctl
, DRM_RENDER_ALLOW
),
1727 DRM_IOCTL_DEF_DRV(I915_GEM_GET_CACHING
, i915_gem_get_caching_ioctl
, DRM_RENDER_ALLOW
),
1728 DRM_IOCTL_DEF_DRV(I915_GEM_THROTTLE
, i915_gem_throttle_ioctl
, DRM_RENDER_ALLOW
),
1729 DRM_IOCTL_DEF_DRV(I915_GEM_ENTERVT
, drm_noop
, DRM_AUTH
|DRM_MASTER
|DRM_ROOT_ONLY
),
1730 DRM_IOCTL_DEF_DRV(I915_GEM_LEAVEVT
, drm_noop
, DRM_AUTH
|DRM_MASTER
|DRM_ROOT_ONLY
),
1731 DRM_IOCTL_DEF_DRV(I915_GEM_CREATE
, i915_gem_create_ioctl
, DRM_RENDER_ALLOW
),
1732 DRM_IOCTL_DEF_DRV(I915_GEM_PREAD
, i915_gem_pread_ioctl
, DRM_RENDER_ALLOW
),
1733 DRM_IOCTL_DEF_DRV(I915_GEM_PWRITE
, i915_gem_pwrite_ioctl
, DRM_RENDER_ALLOW
),
1734 DRM_IOCTL_DEF_DRV(I915_GEM_MMAP
, i915_gem_mmap_ioctl
, DRM_RENDER_ALLOW
),
1735 DRM_IOCTL_DEF_DRV(I915_GEM_MMAP_OFFSET
, i915_gem_mmap_offset_ioctl
, DRM_RENDER_ALLOW
),
1736 DRM_IOCTL_DEF_DRV(I915_GEM_SET_DOMAIN
, i915_gem_set_domain_ioctl
, DRM_RENDER_ALLOW
),
1737 DRM_IOCTL_DEF_DRV(I915_GEM_SW_FINISH
, i915_gem_sw_finish_ioctl
, DRM_RENDER_ALLOW
),
1738 DRM_IOCTL_DEF_DRV(I915_GEM_SET_TILING
, i915_gem_set_tiling_ioctl
, DRM_RENDER_ALLOW
),
1739 DRM_IOCTL_DEF_DRV(I915_GEM_GET_TILING
, i915_gem_get_tiling_ioctl
, DRM_RENDER_ALLOW
),
1740 DRM_IOCTL_DEF_DRV(I915_GEM_GET_APERTURE
, i915_gem_get_aperture_ioctl
, DRM_RENDER_ALLOW
),
1741 DRM_IOCTL_DEF_DRV(I915_GET_PIPE_FROM_CRTC_ID
, intel_get_pipe_from_crtc_id_ioctl
, 0),
1742 DRM_IOCTL_DEF_DRV(I915_GEM_MADVISE
, i915_gem_madvise_ioctl
, DRM_RENDER_ALLOW
),
1743 DRM_IOCTL_DEF_DRV(I915_OVERLAY_PUT_IMAGE
, intel_overlay_put_image_ioctl
, DRM_MASTER
),
1744 DRM_IOCTL_DEF_DRV(I915_OVERLAY_ATTRS
, intel_overlay_attrs_ioctl
, DRM_MASTER
),
1745 DRM_IOCTL_DEF_DRV(I915_SET_SPRITE_COLORKEY
, intel_sprite_set_colorkey_ioctl
, DRM_MASTER
),
1746 DRM_IOCTL_DEF_DRV(I915_GET_SPRITE_COLORKEY
, drm_noop
, DRM_MASTER
),
1747 DRM_IOCTL_DEF_DRV(I915_GEM_WAIT
, i915_gem_wait_ioctl
, DRM_RENDER_ALLOW
),
1748 DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_CREATE_EXT
, i915_gem_context_create_ioctl
, DRM_RENDER_ALLOW
),
1749 DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_DESTROY
, i915_gem_context_destroy_ioctl
, DRM_RENDER_ALLOW
),
1750 DRM_IOCTL_DEF_DRV(I915_REG_READ
, i915_reg_read_ioctl
, DRM_RENDER_ALLOW
),
1751 DRM_IOCTL_DEF_DRV(I915_GET_RESET_STATS
, i915_gem_context_reset_stats_ioctl
, DRM_RENDER_ALLOW
),
1752 DRM_IOCTL_DEF_DRV(I915_GEM_USERPTR
, i915_gem_userptr_ioctl
, DRM_RENDER_ALLOW
),
1753 DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_GETPARAM
, i915_gem_context_getparam_ioctl
, DRM_RENDER_ALLOW
),
1754 DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_SETPARAM
, i915_gem_context_setparam_ioctl
, DRM_RENDER_ALLOW
),
1755 DRM_IOCTL_DEF_DRV(I915_PERF_OPEN
, i915_perf_open_ioctl
, DRM_RENDER_ALLOW
),
1756 DRM_IOCTL_DEF_DRV(I915_PERF_ADD_CONFIG
, i915_perf_add_config_ioctl
, DRM_RENDER_ALLOW
),
1757 DRM_IOCTL_DEF_DRV(I915_PERF_REMOVE_CONFIG
, i915_perf_remove_config_ioctl
, DRM_RENDER_ALLOW
),
1758 DRM_IOCTL_DEF_DRV(I915_QUERY
, i915_query_ioctl
, DRM_RENDER_ALLOW
),
1759 DRM_IOCTL_DEF_DRV(I915_GEM_VM_CREATE
, i915_gem_vm_create_ioctl
, DRM_RENDER_ALLOW
),
1760 DRM_IOCTL_DEF_DRV(I915_GEM_VM_DESTROY
, i915_gem_vm_destroy_ioctl
, DRM_RENDER_ALLOW
),
1763 static const struct drm_driver driver
= {
1764 /* Don't use MTRRs here; the Xserver or userspace app should
1765 * deal with them for Intel hardware.
1769 DRIVER_RENDER
| DRIVER_MODESET
| DRIVER_ATOMIC
| DRIVER_SYNCOBJ
|
1770 DRIVER_SYNCOBJ_TIMELINE
,
1771 .release
= i915_driver_release
,
1772 .open
= i915_driver_open
,
1773 .lastclose
= i915_driver_lastclose
,
1774 .postclose
= i915_driver_postclose
,
1776 .prime_handle_to_fd
= drm_gem_prime_handle_to_fd
,
1777 .prime_fd_to_handle
= drm_gem_prime_fd_to_handle
,
1778 .gem_prime_import
= i915_gem_prime_import
,
1780 .dumb_create
= i915_gem_dumb_create
,
1781 .dumb_map_offset
= i915_gem_dumb_mmap_offset
,
1783 .ioctls
= i915_ioctls
,
1784 .num_ioctls
= ARRAY_SIZE(i915_ioctls
),
1785 .fops
= &i915_driver_fops
,
1786 .name
= DRIVER_NAME
,
1787 .desc
= DRIVER_DESC
,
1788 .date
= DRIVER_DATE
,
1789 .major
= DRIVER_MAJOR
,
1790 .minor
= DRIVER_MINOR
,
1791 .patchlevel
= DRIVER_PATCHLEVEL
,