xref: /linux/drivers/gpu/drm/i915/i915_driver.c (revision fe7fad476ec8153a8b8767a08114e3e4a58a837e)
1 /* i915_drv.c -- i830,i845,i855,i865,i915 driver -*- linux-c -*-
2  */
3 /*
4  *
5  * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6  * All Rights Reserved.
7  *
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:
15  *
16  * The above copyright notice and this permission notice (including the
17  * next paragraph) shall be included in all copies or substantial portions
18  * of the Software.
19  *
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.
27  *
28  */
29 
30 #include <linux/aperture.h>
31 #include <linux/acpi.h>
32 #include <linux/device.h>
33 #include <linux/module.h>
34 #include <linux/oom.h>
35 #include <linux/pci.h>
36 #include <linux/pm.h>
37 #include <linux/pm_runtime.h>
38 #include <linux/slab.h>
39 #include <linux/string_helpers.h>
40 #include <linux/vga_switcheroo.h>
41 #include <linux/vt.h>
42 
43 #include <drm/drm_atomic_helper.h>
44 #include <drm/drm_ioctl.h>
45 #include <drm/drm_managed.h>
46 #include <drm/drm_probe_helper.h>
47 
48 #include "display/i9xx_display_sr.h"
49 #include "display/intel_bw.h"
50 #include "display/intel_cdclk.h"
51 #include "display/intel_crtc.h"
52 #include "display/intel_display_driver.h"
53 #include "display/intel_dmc.h"
54 #include "display/intel_dp.h"
55 #include "display/intel_dpt.h"
56 #include "display/intel_encoder.h"
57 #include "display/intel_fbdev.h"
58 #include "display/intel_hotplug.h"
59 #include "display/intel_overlay.h"
60 #include "display/intel_pch_refclk.h"
61 #include "display/intel_pps.h"
62 #include "display/intel_sprite_uapi.h"
63 #include "display/intel_vga.h"
64 #include "display/skl_watermark.h"
65 
66 #include "gem/i915_gem_context.h"
67 #include "gem/i915_gem_create.h"
68 #include "gem/i915_gem_dmabuf.h"
69 #include "gem/i915_gem_ioctls.h"
70 #include "gem/i915_gem_mman.h"
71 #include "gem/i915_gem_pm.h"
72 #include "gt/intel_gt.h"
73 #include "gt/intel_gt_pm.h"
74 #include "gt/intel_gt_print.h"
75 #include "gt/intel_rc6.h"
76 
77 #include "pxp/intel_pxp.h"
78 #include "pxp/intel_pxp_debugfs.h"
79 #include "pxp/intel_pxp_pm.h"
80 
81 #include "soc/intel_dram.h"
82 #include "soc/intel_gmch.h"
83 
84 #include "i915_debugfs.h"
85 #include "i915_driver.h"
86 #include "i915_drm_client.h"
87 #include "i915_drv.h"
88 #include "i915_file_private.h"
89 #include "i915_getparam.h"
90 #include "i915_hwmon.h"
91 #include "i915_ioc32.h"
92 #include "i915_ioctl.h"
93 #include "i915_irq.h"
94 #include "i915_memcpy.h"
95 #include "i915_perf.h"
96 #include "i915_query.h"
97 #include "i915_reg.h"
98 #include "i915_switcheroo.h"
99 #include "i915_sysfs.h"
100 #include "i915_utils.h"
101 #include "i915_vgpu.h"
102 #include "intel_clock_gating.h"
103 #include "intel_cpu_info.h"
104 #include "intel_gvt.h"
105 #include "intel_memory_region.h"
106 #include "intel_pci_config.h"
107 #include "intel_pcode.h"
108 #include "intel_region_ttm.h"
109 #include "intel_sbi.h"
110 #include "vlv_sideband.h"
111 #include "vlv_suspend.h"
112 
113 static const struct drm_driver i915_drm_driver;
114 
115 static int i915_workqueues_init(struct drm_i915_private *dev_priv)
116 {
117 	/*
118 	 * The i915 workqueue is primarily used for batched retirement of
119 	 * requests (and thus managing bo) once the task has been completed
120 	 * by the GPU. i915_retire_requests() is called directly when we
121 	 * need high-priority retirement, such as waiting for an explicit
122 	 * bo.
123 	 *
124 	 * It is also used for periodic low-priority events, such as
125 	 * idle-timers and recording error state.
126 	 *
127 	 * All tasks on the workqueue are expected to acquire the dev mutex
128 	 * so there is no point in running more than one instance of the
129 	 * workqueue at any time.  Use an ordered one.
130 	 */
131 	dev_priv->wq = alloc_ordered_workqueue("i915", 0);
132 	if (dev_priv->wq == NULL)
133 		goto out_err;
134 
135 	dev_priv->display.hotplug.dp_wq = alloc_ordered_workqueue("i915-dp", 0);
136 	if (dev_priv->display.hotplug.dp_wq == NULL)
137 		goto out_free_wq;
138 
139 	/*
140 	 * The unordered i915 workqueue should be used for all work
141 	 * scheduling that do not require running in order, which used
142 	 * to be scheduled on the system_wq before moving to a driver
143 	 * instance due deprecation of flush_scheduled_work().
144 	 */
145 	dev_priv->unordered_wq = alloc_workqueue("i915-unordered", 0, 0);
146 	if (dev_priv->unordered_wq == NULL)
147 		goto out_free_dp_wq;
148 
149 	return 0;
150 
151 out_free_dp_wq:
152 	destroy_workqueue(dev_priv->display.hotplug.dp_wq);
153 out_free_wq:
154 	destroy_workqueue(dev_priv->wq);
155 out_err:
156 	drm_err(&dev_priv->drm, "Failed to allocate workqueues.\n");
157 
158 	return -ENOMEM;
159 }
160 
161 static void i915_workqueues_cleanup(struct drm_i915_private *dev_priv)
162 {
163 	destroy_workqueue(dev_priv->unordered_wq);
164 	destroy_workqueue(dev_priv->display.hotplug.dp_wq);
165 	destroy_workqueue(dev_priv->wq);
166 }
167 
168 /*
169  * We don't keep the workarounds for pre-production hardware, so we expect our
170  * driver to fail on these machines in one way or another. A little warning on
171  * dmesg may help both the user and the bug triagers.
172  *
173  * Our policy for removing pre-production workarounds is to keep the
174  * current gen workarounds as a guide to the bring-up of the next gen
175  * (workarounds have a habit of persisting!). Anything older than that
176  * should be removed along with the complications they introduce.
177  */
178 static void intel_detect_preproduction_hw(struct drm_i915_private *dev_priv)
179 {
180 	bool pre = false;
181 
182 	pre |= IS_HASWELL_EARLY_SDV(dev_priv);
183 	pre |= IS_SKYLAKE(dev_priv) && INTEL_REVID(dev_priv) < 0x6;
184 	pre |= IS_BROXTON(dev_priv) && INTEL_REVID(dev_priv) < 0xA;
185 	pre |= IS_KABYLAKE(dev_priv) && INTEL_REVID(dev_priv) < 0x1;
186 	pre |= IS_GEMINILAKE(dev_priv) && INTEL_REVID(dev_priv) < 0x3;
187 	pre |= IS_ICELAKE(dev_priv) && INTEL_REVID(dev_priv) < 0x7;
188 	pre |= IS_TIGERLAKE(dev_priv) && INTEL_REVID(dev_priv) < 0x1;
189 	pre |= IS_DG1(dev_priv) && INTEL_REVID(dev_priv) < 0x1;
190 	pre |= IS_DG2_G10(dev_priv) && INTEL_REVID(dev_priv) < 0x8;
191 	pre |= IS_DG2_G11(dev_priv) && INTEL_REVID(dev_priv) < 0x5;
192 	pre |= IS_DG2_G12(dev_priv) && INTEL_REVID(dev_priv) < 0x1;
193 
194 	if (pre) {
195 		drm_err(&dev_priv->drm, "This is a pre-production stepping. "
196 			  "It may not be fully functional.\n");
197 		add_taint(TAINT_MACHINE_CHECK, LOCKDEP_STILL_OK);
198 	}
199 }
200 
201 static void sanitize_gpu(struct drm_i915_private *i915)
202 {
203 	if (!INTEL_INFO(i915)->gpu_reset_clobbers_display) {
204 		struct intel_gt *gt;
205 		unsigned int i;
206 
207 		for_each_gt(gt, i915, i)
208 			intel_gt_reset_all_engines(gt);
209 	}
210 }
211 
212 /**
213  * i915_driver_early_probe - setup state not requiring device access
214  * @dev_priv: device private
215  *
216  * Initialize everything that is a "SW-only" state, that is state not
217  * requiring accessing the device or exposing the driver via kernel internal
218  * or userspace interfaces. Example steps belonging here: lock initialization,
219  * system memory allocation, setting up device specific attributes and
220  * function hooks not requiring accessing the device.
221  */
222 static int i915_driver_early_probe(struct drm_i915_private *dev_priv)
223 {
224 	struct intel_display *display = &dev_priv->display;
225 	int ret = 0;
226 
227 	if (i915_inject_probe_failure(dev_priv))
228 		return -ENODEV;
229 
230 	intel_device_info_runtime_init_early(dev_priv);
231 
232 	intel_step_init(dev_priv);
233 
234 	intel_uncore_mmio_debug_init_early(dev_priv);
235 
236 	spin_lock_init(&dev_priv->irq_lock);
237 	spin_lock_init(&dev_priv->gpu_error.lock);
238 
239 	intel_sbi_init(dev_priv);
240 	vlv_iosf_sb_init(dev_priv);
241 	mutex_init(&dev_priv->sb_lock);
242 
243 	i915_memcpy_init_early(dev_priv);
244 	intel_runtime_pm_init_early(&dev_priv->runtime_pm);
245 
246 	ret = i915_workqueues_init(dev_priv);
247 	if (ret < 0)
248 		return ret;
249 
250 	ret = vlv_suspend_init(dev_priv);
251 	if (ret < 0)
252 		goto err_workqueues;
253 
254 	ret = intel_region_ttm_device_init(dev_priv);
255 	if (ret)
256 		goto err_ttm;
257 
258 	ret = intel_root_gt_init_early(dev_priv);
259 	if (ret < 0)
260 		goto err_rootgt;
261 
262 	i915_gem_init_early(dev_priv);
263 
264 	/* This must be called before any calls to HAS_PCH_* */
265 	intel_detect_pch(dev_priv);
266 
267 	intel_irq_init(dev_priv);
268 	intel_display_driver_early_probe(display);
269 	intel_clock_gating_hooks_init(dev_priv);
270 
271 	intel_detect_preproduction_hw(dev_priv);
272 
273 	return 0;
274 
275 err_rootgt:
276 	intel_region_ttm_device_fini(dev_priv);
277 err_ttm:
278 	vlv_suspend_cleanup(dev_priv);
279 err_workqueues:
280 	i915_workqueues_cleanup(dev_priv);
281 	return ret;
282 }
283 
284 /**
285  * i915_driver_late_release - cleanup the setup done in
286  *			       i915_driver_early_probe()
287  * @dev_priv: device private
288  */
289 static void i915_driver_late_release(struct drm_i915_private *dev_priv)
290 {
291 	struct intel_display *display = &dev_priv->display;
292 
293 	intel_irq_fini(dev_priv);
294 	intel_power_domains_cleanup(display);
295 	i915_gem_cleanup_early(dev_priv);
296 	intel_gt_driver_late_release_all(dev_priv);
297 	intel_region_ttm_device_fini(dev_priv);
298 	vlv_suspend_cleanup(dev_priv);
299 	i915_workqueues_cleanup(dev_priv);
300 
301 	mutex_destroy(&dev_priv->sb_lock);
302 	vlv_iosf_sb_fini(dev_priv);
303 	intel_sbi_fini(dev_priv);
304 
305 	i915_params_free(&dev_priv->params);
306 }
307 
308 /**
309  * i915_driver_mmio_probe - setup device MMIO
310  * @dev_priv: device private
311  *
312  * Setup minimal device state necessary for MMIO accesses later in the
313  * initialization sequence. The setup here should avoid any other device-wide
314  * side effects or exposing the driver via kernel internal or user space
315  * interfaces.
316  */
317 static int i915_driver_mmio_probe(struct drm_i915_private *dev_priv)
318 {
319 	struct intel_display *display = &dev_priv->display;
320 	struct intel_gt *gt;
321 	int ret, i;
322 
323 	if (i915_inject_probe_failure(dev_priv))
324 		return -ENODEV;
325 
326 	ret = intel_gmch_bridge_setup(dev_priv);
327 	if (ret < 0)
328 		return ret;
329 
330 	for_each_gt(gt, dev_priv, i) {
331 		ret = intel_uncore_init_mmio(gt->uncore);
332 		if (ret)
333 			return ret;
334 
335 		ret = drmm_add_action_or_reset(&dev_priv->drm,
336 					       intel_uncore_fini_mmio,
337 					       gt->uncore);
338 		if (ret)
339 			return ret;
340 	}
341 
342 	/* Try to make sure MCHBAR is enabled before poking at it */
343 	intel_gmch_bar_setup(dev_priv);
344 	intel_device_info_runtime_init(dev_priv);
345 	intel_display_device_info_runtime_init(display);
346 
347 	for_each_gt(gt, dev_priv, i) {
348 		ret = intel_gt_init_mmio(gt);
349 		if (ret)
350 			goto err_uncore;
351 	}
352 
353 	/* As early as possible, scrub existing GPU state before clobbering */
354 	sanitize_gpu(dev_priv);
355 
356 	return 0;
357 
358 err_uncore:
359 	intel_gmch_bar_teardown(dev_priv);
360 
361 	return ret;
362 }
363 
364 /**
365  * i915_driver_mmio_release - cleanup the setup done in i915_driver_mmio_probe()
366  * @dev_priv: device private
367  */
368 static void i915_driver_mmio_release(struct drm_i915_private *dev_priv)
369 {
370 	intel_gmch_bar_teardown(dev_priv);
371 }
372 
373 /**
374  * i915_set_dma_info - set all relevant PCI dma info as configured for the
375  * platform
376  * @i915: valid i915 instance
377  *
378  * Set the dma max segment size, device and coherent masks.  The dma mask set
379  * needs to occur before i915_ggtt_probe_hw.
380  *
381  * A couple of platforms have special needs.  Address them as well.
382  *
383  */
384 static int i915_set_dma_info(struct drm_i915_private *i915)
385 {
386 	unsigned int mask_size = INTEL_INFO(i915)->dma_mask_size;
387 	int ret;
388 
389 	GEM_BUG_ON(!mask_size);
390 
391 	/*
392 	 * We don't have a max segment size, so set it to the max so sg's
393 	 * debugging layer doesn't complain
394 	 */
395 	dma_set_max_seg_size(i915->drm.dev, UINT_MAX);
396 
397 	ret = dma_set_mask(i915->drm.dev, DMA_BIT_MASK(mask_size));
398 	if (ret)
399 		goto mask_err;
400 
401 	/* overlay on gen2 is broken and can't address above 1G */
402 	if (GRAPHICS_VER(i915) == 2)
403 		mask_size = 30;
404 
405 	/*
406 	 * 965GM sometimes incorrectly writes to hardware status page (HWS)
407 	 * using 32bit addressing, overwriting memory if HWS is located
408 	 * above 4GB.
409 	 *
410 	 * The documentation also mentions an issue with undefined
411 	 * behaviour if any general state is accessed within a page above 4GB,
412 	 * which also needs to be handled carefully.
413 	 */
414 	if (IS_I965G(i915) || IS_I965GM(i915))
415 		mask_size = 32;
416 
417 	ret = dma_set_coherent_mask(i915->drm.dev, DMA_BIT_MASK(mask_size));
418 	if (ret)
419 		goto mask_err;
420 
421 	return 0;
422 
423 mask_err:
424 	drm_err(&i915->drm, "Can't set DMA mask/consistent mask (%d)\n", ret);
425 	return ret;
426 }
427 
428 /* Wa_14022698537:dg2 */
429 static void i915_enable_g8(struct drm_i915_private *i915)
430 {
431 	if (IS_DG2(i915)) {
432 		if (IS_DG2_D(i915) && !intel_match_g8_cpu())
433 			return;
434 
435 		snb_pcode_write_p(&i915->uncore, PCODE_POWER_SETUP,
436 				  POWER_SETUP_SUBCOMMAND_G8_ENABLE, 0, 0);
437 	}
438 }
439 
440 static int i915_pcode_init(struct drm_i915_private *i915)
441 {
442 	struct intel_gt *gt;
443 	int id, ret;
444 
445 	for_each_gt(gt, i915, id) {
446 		ret = intel_pcode_init(gt->uncore);
447 		if (ret) {
448 			gt_err(gt, "intel_pcode_init failed %d\n", ret);
449 			return ret;
450 		}
451 	}
452 
453 	i915_enable_g8(i915);
454 	return 0;
455 }
456 
457 /**
458  * i915_driver_hw_probe - setup state requiring device access
459  * @dev_priv: device private
460  *
461  * Setup state that requires accessing the device, but doesn't require
462  * exposing the driver via kernel internal or userspace interfaces.
463  */
464 static int i915_driver_hw_probe(struct drm_i915_private *dev_priv)
465 {
466 	struct intel_display *display = &dev_priv->display;
467 	struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev);
468 	int ret;
469 
470 	if (i915_inject_probe_failure(dev_priv))
471 		return -ENODEV;
472 
473 	if (HAS_PPGTT(dev_priv)) {
474 		if (intel_vgpu_active(dev_priv) &&
475 		    !intel_vgpu_has_full_ppgtt(dev_priv)) {
476 			drm_err(&dev_priv->drm,
477 				"incompatible vGPU found, support for isolated ppGTT required\n");
478 			return -ENXIO;
479 		}
480 	}
481 
482 	if (HAS_EXECLISTS(dev_priv)) {
483 		/*
484 		 * Older GVT emulation depends upon intercepting CSB mmio,
485 		 * which we no longer use, preferring to use the HWSP cache
486 		 * instead.
487 		 */
488 		if (intel_vgpu_active(dev_priv) &&
489 		    !intel_vgpu_has_hwsp_emulation(dev_priv)) {
490 			drm_err(&dev_priv->drm,
491 				"old vGPU host found, support for HWSP emulation required\n");
492 			return -ENXIO;
493 		}
494 	}
495 
496 	/* needs to be done before ggtt probe */
497 	intel_dram_edram_detect(dev_priv);
498 
499 	ret = i915_set_dma_info(dev_priv);
500 	if (ret)
501 		return ret;
502 
503 	ret = i915_perf_init(dev_priv);
504 	if (ret)
505 		return ret;
506 
507 	ret = i915_ggtt_probe_hw(dev_priv);
508 	if (ret)
509 		goto err_perf;
510 
511 	ret = aperture_remove_conflicting_pci_devices(pdev, dev_priv->drm.driver->name);
512 	if (ret)
513 		goto err_ggtt;
514 
515 	ret = i915_ggtt_init_hw(dev_priv);
516 	if (ret)
517 		goto err_ggtt;
518 
519 	/*
520 	 * Make sure we probe lmem before we probe stolen-lmem. The BAR size
521 	 * might be different due to bar resizing.
522 	 */
523 	ret = intel_gt_tiles_init(dev_priv);
524 	if (ret)
525 		goto err_ggtt;
526 
527 	ret = intel_memory_regions_hw_probe(dev_priv);
528 	if (ret)
529 		goto err_ggtt;
530 
531 	ret = i915_ggtt_enable_hw(dev_priv);
532 	if (ret) {
533 		drm_err(&dev_priv->drm, "failed to enable GGTT\n");
534 		goto err_mem_regions;
535 	}
536 
537 	pci_set_master(pdev);
538 
539 	/* On the 945G/GM, the chipset reports the MSI capability on the
540 	 * integrated graphics even though the support isn't actually there
541 	 * according to the published specs.  It doesn't appear to function
542 	 * correctly in testing on 945G.
543 	 * This may be a side effect of MSI having been made available for PEG
544 	 * and the registers being closely associated.
545 	 *
546 	 * According to chipset errata, on the 965GM, MSI interrupts may
547 	 * be lost or delayed, and was defeatured. MSI interrupts seem to
548 	 * get lost on g4x as well, and interrupt delivery seems to stay
549 	 * properly dead afterwards. So we'll just disable them for all
550 	 * pre-gen5 chipsets.
551 	 *
552 	 * dp aux and gmbus irq on gen4 seems to be able to generate legacy
553 	 * interrupts even when in MSI mode. This results in spurious
554 	 * interrupt warnings if the legacy irq no. is shared with another
555 	 * device. The kernel then disables that interrupt source and so
556 	 * prevents the other device from working properly.
557 	 */
558 	if (GRAPHICS_VER(dev_priv) >= 5) {
559 		if (pci_enable_msi(pdev) < 0)
560 			drm_dbg(&dev_priv->drm, "can't enable MSI");
561 	}
562 
563 	ret = intel_gvt_init(dev_priv);
564 	if (ret)
565 		goto err_msi;
566 
567 	intel_opregion_setup(display);
568 
569 	ret = i915_pcode_init(dev_priv);
570 	if (ret)
571 		goto err_opregion;
572 
573 	/*
574 	 * Fill the dram structure to get the system dram info. This will be
575 	 * used for memory latency calculation.
576 	 */
577 	intel_dram_detect(dev_priv);
578 
579 	intel_bw_init_hw(dev_priv);
580 
581 	return 0;
582 
583 err_opregion:
584 	intel_opregion_cleanup(display);
585 err_msi:
586 	if (pdev->msi_enabled)
587 		pci_disable_msi(pdev);
588 err_mem_regions:
589 	intel_memory_regions_driver_release(dev_priv);
590 err_ggtt:
591 	i915_ggtt_driver_release(dev_priv);
592 	i915_gem_drain_freed_objects(dev_priv);
593 	i915_ggtt_driver_late_release(dev_priv);
594 err_perf:
595 	i915_perf_fini(dev_priv);
596 	return ret;
597 }
598 
599 /**
600  * i915_driver_hw_remove - cleanup the setup done in i915_driver_hw_probe()
601  * @dev_priv: device private
602  */
603 static void i915_driver_hw_remove(struct drm_i915_private *dev_priv)
604 {
605 	struct intel_display *display = &dev_priv->display;
606 	struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev);
607 
608 	i915_perf_fini(dev_priv);
609 
610 	intel_opregion_cleanup(display);
611 
612 	if (pdev->msi_enabled)
613 		pci_disable_msi(pdev);
614 }
615 
616 /**
617  * i915_driver_register - register the driver with the rest of the system
618  * @dev_priv: device private
619  *
620  * Perform any steps necessary to make the driver available via kernel
621  * internal or userspace interfaces.
622  */
623 static void i915_driver_register(struct drm_i915_private *dev_priv)
624 {
625 	struct intel_display *display = &dev_priv->display;
626 	struct intel_gt *gt;
627 	unsigned int i;
628 
629 	i915_gem_driver_register(dev_priv);
630 	i915_pmu_register(dev_priv);
631 
632 	intel_vgpu_register(dev_priv);
633 
634 	/* Reveal our presence to userspace */
635 	if (drm_dev_register(&dev_priv->drm, 0)) {
636 		drm_err(&dev_priv->drm,
637 			"Failed to register driver for userspace access!\n");
638 		return;
639 	}
640 
641 	i915_debugfs_register(dev_priv);
642 	i915_setup_sysfs(dev_priv);
643 
644 	/* Depends on sysfs having been initialized */
645 	i915_perf_register(dev_priv);
646 
647 	for_each_gt(gt, dev_priv, i)
648 		intel_gt_driver_register(gt);
649 
650 	intel_pxp_debugfs_register(dev_priv->pxp);
651 
652 	i915_hwmon_register(dev_priv);
653 
654 	intel_display_driver_register(display);
655 
656 	intel_power_domains_enable(display);
657 	intel_runtime_pm_enable(&dev_priv->runtime_pm);
658 
659 	if (i915_switcheroo_register(dev_priv))
660 		drm_err(&dev_priv->drm, "Failed to register vga switcheroo!\n");
661 }
662 
663 /**
664  * i915_driver_unregister - cleanup the registration done in i915_driver_regiser()
665  * @dev_priv: device private
666  */
667 static void i915_driver_unregister(struct drm_i915_private *dev_priv)
668 {
669 	struct intel_display *display = &dev_priv->display;
670 	struct intel_gt *gt;
671 	unsigned int i;
672 
673 	i915_switcheroo_unregister(dev_priv);
674 
675 	intel_runtime_pm_disable(&dev_priv->runtime_pm);
676 	intel_power_domains_disable(display);
677 
678 	intel_display_driver_unregister(display);
679 
680 	intel_pxp_fini(dev_priv);
681 
682 	for_each_gt(gt, dev_priv, i)
683 		intel_gt_driver_unregister(gt);
684 
685 	i915_hwmon_unregister(dev_priv);
686 
687 	i915_perf_unregister(dev_priv);
688 	i915_pmu_unregister(dev_priv);
689 
690 	i915_teardown_sysfs(dev_priv);
691 	drm_dev_unplug(&dev_priv->drm);
692 
693 	i915_gem_driver_unregister(dev_priv);
694 }
695 
696 void
697 i915_print_iommu_status(struct drm_i915_private *i915, struct drm_printer *p)
698 {
699 	drm_printf(p, "iommu: %s\n",
700 		   str_enabled_disabled(i915_vtd_active(i915)));
701 }
702 
703 static void i915_welcome_messages(struct drm_i915_private *dev_priv)
704 {
705 	if (drm_debug_enabled(DRM_UT_DRIVER)) {
706 		struct drm_printer p = drm_dbg_printer(&dev_priv->drm, DRM_UT_DRIVER,
707 						       "device info:");
708 		struct intel_gt *gt;
709 		unsigned int i;
710 
711 		drm_printf(&p, "pciid=0x%04x rev=0x%02x platform=%s (subplatform=0x%x) gen=%i\n",
712 			   INTEL_DEVID(dev_priv),
713 			   INTEL_REVID(dev_priv),
714 			   intel_platform_name(INTEL_INFO(dev_priv)->platform),
715 			   intel_subplatform(RUNTIME_INFO(dev_priv),
716 					     INTEL_INFO(dev_priv)->platform),
717 			   GRAPHICS_VER(dev_priv));
718 
719 		intel_device_info_print(INTEL_INFO(dev_priv),
720 					RUNTIME_INFO(dev_priv), &p);
721 		i915_print_iommu_status(dev_priv, &p);
722 		for_each_gt(gt, dev_priv, i)
723 			intel_gt_info_print(&gt->info, &p);
724 	}
725 
726 	if (IS_ENABLED(CONFIG_DRM_I915_DEBUG))
727 		drm_info(&dev_priv->drm, "DRM_I915_DEBUG enabled\n");
728 	if (IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM))
729 		drm_info(&dev_priv->drm, "DRM_I915_DEBUG_GEM enabled\n");
730 	if (IS_ENABLED(CONFIG_DRM_I915_DEBUG_RUNTIME_PM))
731 		drm_info(&dev_priv->drm,
732 			 "DRM_I915_DEBUG_RUNTIME_PM enabled\n");
733 }
734 
735 static struct drm_i915_private *
736 i915_driver_create(struct pci_dev *pdev, const struct pci_device_id *ent)
737 {
738 	const struct intel_device_info *match_info =
739 		(struct intel_device_info *)ent->driver_data;
740 	struct drm_i915_private *i915;
741 
742 	i915 = devm_drm_dev_alloc(&pdev->dev, &i915_drm_driver,
743 				  struct drm_i915_private, drm);
744 	if (IS_ERR(i915))
745 		return i915;
746 
747 	pci_set_drvdata(pdev, &i915->drm);
748 
749 	/* Device parameters start as a copy of module parameters. */
750 	i915_params_copy(&i915->params, &i915_modparams);
751 
752 	/* Set up device info and initial runtime info. */
753 	intel_device_info_driver_create(i915, pdev->device, match_info);
754 
755 	intel_display_device_probe(pdev);
756 
757 	return i915;
758 }
759 
760 /**
761  * i915_driver_probe - setup chip and create an initial config
762  * @pdev: PCI device
763  * @ent: matching PCI ID entry
764  *
765  * The driver probe routine has to do several things:
766  *   - drive output discovery via intel_display_driver_probe()
767  *   - initialize the memory manager
768  *   - allocate initial config memory
769  *   - setup the DRM framebuffer with the allocated memory
770  */
771 int i915_driver_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
772 {
773 	struct drm_i915_private *i915;
774 	struct intel_display *display;
775 	int ret;
776 
777 	ret = pci_enable_device(pdev);
778 	if (ret) {
779 		pr_err("Failed to enable graphics device: %pe\n", ERR_PTR(ret));
780 		return ret;
781 	}
782 
783 	i915 = i915_driver_create(pdev, ent);
784 	if (IS_ERR(i915)) {
785 		pci_disable_device(pdev);
786 		return PTR_ERR(i915);
787 	}
788 
789 	display = &i915->display;
790 
791 	ret = i915_driver_early_probe(i915);
792 	if (ret < 0)
793 		goto out_pci_disable;
794 
795 	disable_rpm_wakeref_asserts(&i915->runtime_pm);
796 
797 	intel_vgpu_detect(i915);
798 
799 	ret = intel_gt_probe_all(i915);
800 	if (ret < 0)
801 		goto out_runtime_pm_put;
802 
803 	ret = i915_driver_mmio_probe(i915);
804 	if (ret < 0)
805 		goto out_runtime_pm_put;
806 
807 	ret = i915_driver_hw_probe(i915);
808 	if (ret < 0)
809 		goto out_cleanup_mmio;
810 
811 	ret = intel_display_driver_probe_noirq(display);
812 	if (ret < 0)
813 		goto out_cleanup_hw;
814 
815 	ret = intel_irq_install(i915);
816 	if (ret)
817 		goto out_cleanup_modeset;
818 
819 	ret = intel_display_driver_probe_nogem(display);
820 	if (ret)
821 		goto out_cleanup_irq;
822 
823 	ret = i915_gem_init(i915);
824 	if (ret)
825 		goto out_cleanup_modeset2;
826 
827 	ret = intel_pxp_init(i915);
828 	if (ret && ret != -ENODEV)
829 		drm_dbg(&i915->drm, "pxp init failed with %d\n", ret);
830 
831 	ret = intel_display_driver_probe(display);
832 	if (ret)
833 		goto out_cleanup_gem;
834 
835 	i915_driver_register(i915);
836 
837 	enable_rpm_wakeref_asserts(&i915->runtime_pm);
838 
839 	i915_welcome_messages(i915);
840 
841 	i915->do_release = true;
842 
843 	return 0;
844 
845 out_cleanup_gem:
846 	i915_gem_suspend(i915);
847 	i915_gem_driver_remove(i915);
848 	i915_gem_driver_release(i915);
849 out_cleanup_modeset2:
850 	/* FIXME clean up the error path */
851 	intel_display_driver_remove(display);
852 	intel_irq_uninstall(i915);
853 	intel_display_driver_remove_noirq(display);
854 	goto out_cleanup_modeset;
855 out_cleanup_irq:
856 	intel_irq_uninstall(i915);
857 out_cleanup_modeset:
858 	intel_display_driver_remove_nogem(display);
859 out_cleanup_hw:
860 	i915_driver_hw_remove(i915);
861 	intel_memory_regions_driver_release(i915);
862 	i915_ggtt_driver_release(i915);
863 	i915_gem_drain_freed_objects(i915);
864 	i915_ggtt_driver_late_release(i915);
865 out_cleanup_mmio:
866 	i915_driver_mmio_release(i915);
867 out_runtime_pm_put:
868 	enable_rpm_wakeref_asserts(&i915->runtime_pm);
869 	i915_driver_late_release(i915);
870 out_pci_disable:
871 	pci_disable_device(pdev);
872 	i915_probe_error(i915, "Device initialization failed (%d)\n", ret);
873 	return ret;
874 }
875 
876 void i915_driver_remove(struct drm_i915_private *i915)
877 {
878 	struct intel_display *display = &i915->display;
879 	intel_wakeref_t wakeref;
880 
881 	wakeref = intel_runtime_pm_get(&i915->runtime_pm);
882 
883 	i915_driver_unregister(i915);
884 
885 	/* Flush any external code that still may be under the RCU lock */
886 	synchronize_rcu();
887 
888 	i915_gem_suspend(i915);
889 
890 	intel_gvt_driver_remove(i915);
891 
892 	intel_display_driver_remove(display);
893 
894 	intel_irq_uninstall(i915);
895 
896 	intel_display_driver_remove_noirq(display);
897 
898 	i915_reset_error_state(i915);
899 	i915_gem_driver_remove(i915);
900 
901 	intel_display_driver_remove_nogem(display);
902 
903 	i915_driver_hw_remove(i915);
904 
905 	intel_runtime_pm_put(&i915->runtime_pm, wakeref);
906 }
907 
908 static void i915_driver_release(struct drm_device *dev)
909 {
910 	struct drm_i915_private *dev_priv = to_i915(dev);
911 	struct intel_display *display = &dev_priv->display;
912 	struct intel_runtime_pm *rpm = &dev_priv->runtime_pm;
913 	intel_wakeref_t wakeref;
914 
915 	if (!dev_priv->do_release)
916 		return;
917 
918 	wakeref = intel_runtime_pm_get(rpm);
919 
920 	i915_gem_driver_release(dev_priv);
921 
922 	intel_memory_regions_driver_release(dev_priv);
923 	i915_ggtt_driver_release(dev_priv);
924 	i915_gem_drain_freed_objects(dev_priv);
925 	i915_ggtt_driver_late_release(dev_priv);
926 
927 	i915_driver_mmio_release(dev_priv);
928 
929 	intel_runtime_pm_put(rpm, wakeref);
930 
931 	intel_runtime_pm_driver_release(rpm);
932 
933 	i915_driver_late_release(dev_priv);
934 
935 	intel_display_device_remove(display);
936 }
937 
938 static int i915_driver_open(struct drm_device *dev, struct drm_file *file)
939 {
940 	struct drm_i915_private *i915 = to_i915(dev);
941 	int ret;
942 
943 	ret = i915_gem_open(i915, file);
944 	if (ret)
945 		return ret;
946 
947 	return 0;
948 }
949 
950 static void i915_driver_postclose(struct drm_device *dev, struct drm_file *file)
951 {
952 	struct drm_i915_file_private *file_priv = file->driver_priv;
953 
954 	i915_gem_context_close(file);
955 	i915_drm_client_put(file_priv->client);
956 
957 	kfree_rcu(file_priv, rcu);
958 
959 	/* Catch up with all the deferred frees from "this" client */
960 	i915_gem_flush_free_objects(to_i915(dev));
961 }
962 
963 void i915_driver_shutdown(struct drm_i915_private *i915)
964 {
965 	struct intel_display *display = &i915->display;
966 
967 	disable_rpm_wakeref_asserts(&i915->runtime_pm);
968 	intel_runtime_pm_disable(&i915->runtime_pm);
969 	intel_power_domains_disable(display);
970 
971 	intel_fbdev_set_suspend(&i915->drm, FBINFO_STATE_SUSPENDED, true);
972 	if (HAS_DISPLAY(i915)) {
973 		drm_kms_helper_poll_disable(&i915->drm);
974 		intel_display_driver_disable_user_access(display);
975 
976 		drm_atomic_helper_shutdown(&i915->drm);
977 	}
978 
979 	intel_dp_mst_suspend(display);
980 
981 	intel_irq_suspend(i915);
982 	intel_hpd_cancel_work(i915);
983 
984 	if (HAS_DISPLAY(i915))
985 		intel_display_driver_suspend_access(display);
986 
987 	intel_encoder_suspend_all(&i915->display);
988 	intel_encoder_shutdown_all(&i915->display);
989 
990 	intel_dmc_suspend(&i915->display);
991 
992 	i915_gem_suspend(i915);
993 
994 	/*
995 	 * The only requirement is to reboot with display DC states disabled,
996 	 * for now leaving all display power wells in the INIT power domain
997 	 * enabled.
998 	 *
999 	 * TODO:
1000 	 * - unify the pci_driver::shutdown sequence here with the
1001 	 *   pci_driver.driver.pm.poweroff,poweroff_late sequence.
1002 	 * - unify the driver remove and system/runtime suspend sequences with
1003 	 *   the above unified shutdown/poweroff sequence.
1004 	 */
1005 	intel_power_domains_driver_remove(display);
1006 	enable_rpm_wakeref_asserts(&i915->runtime_pm);
1007 
1008 	intel_runtime_pm_driver_last_release(&i915->runtime_pm);
1009 }
1010 
1011 static bool suspend_to_idle(struct drm_i915_private *dev_priv)
1012 {
1013 #if IS_ENABLED(CONFIG_ACPI_SLEEP)
1014 	if (acpi_target_system_state() < ACPI_STATE_S3)
1015 		return true;
1016 #endif
1017 	return false;
1018 }
1019 
1020 static void i915_drm_complete(struct drm_device *dev)
1021 {
1022 	struct drm_i915_private *i915 = to_i915(dev);
1023 
1024 	intel_pxp_resume_complete(i915->pxp);
1025 }
1026 
1027 static int i915_drm_prepare(struct drm_device *dev)
1028 {
1029 	struct drm_i915_private *i915 = to_i915(dev);
1030 
1031 	intel_pxp_suspend_prepare(i915->pxp);
1032 
1033 	/*
1034 	 * NB intel_display_driver_suspend() may issue new requests after we've
1035 	 * ostensibly marked the GPU as ready-to-sleep here. We need to
1036 	 * split out that work and pull it forward so that after point,
1037 	 * the GPU is not woken again.
1038 	 */
1039 	return i915_gem_backup_suspend(i915);
1040 }
1041 
1042 static int i915_drm_suspend(struct drm_device *dev)
1043 {
1044 	struct drm_i915_private *dev_priv = to_i915(dev);
1045 	struct intel_display *display = &dev_priv->display;
1046 	struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev);
1047 	pci_power_t opregion_target_state;
1048 
1049 	disable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
1050 
1051 	/* We do a lot of poking in a lot of registers, make sure they work
1052 	 * properly. */
1053 	intel_power_domains_disable(display);
1054 	intel_fbdev_set_suspend(dev, FBINFO_STATE_SUSPENDED, true);
1055 	if (HAS_DISPLAY(dev_priv)) {
1056 		drm_kms_helper_poll_disable(dev);
1057 		intel_display_driver_disable_user_access(display);
1058 	}
1059 
1060 	pci_save_state(pdev);
1061 
1062 	intel_display_driver_suspend(display);
1063 
1064 	intel_irq_suspend(dev_priv);
1065 	intel_hpd_cancel_work(dev_priv);
1066 
1067 	if (HAS_DISPLAY(dev_priv))
1068 		intel_display_driver_suspend_access(display);
1069 
1070 	intel_encoder_suspend_all(&dev_priv->display);
1071 
1072 	/* Must be called before GGTT is suspended. */
1073 	intel_dpt_suspend(display);
1074 	i915_ggtt_suspend(to_gt(dev_priv)->ggtt);
1075 
1076 	i9xx_display_sr_save(display);
1077 
1078 	opregion_target_state = suspend_to_idle(dev_priv) ? PCI_D1 : PCI_D3cold;
1079 	intel_opregion_suspend(display, opregion_target_state);
1080 
1081 	dev_priv->suspend_count++;
1082 
1083 	intel_dmc_suspend(display);
1084 
1085 	enable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
1086 
1087 	i915_gem_drain_freed_objects(dev_priv);
1088 
1089 	return 0;
1090 }
1091 
1092 static int i915_drm_suspend_late(struct drm_device *dev, bool hibernation)
1093 {
1094 	struct drm_i915_private *dev_priv = to_i915(dev);
1095 	struct intel_display *display = &dev_priv->display;
1096 	struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev);
1097 	struct intel_runtime_pm *rpm = &dev_priv->runtime_pm;
1098 	struct intel_gt *gt;
1099 	int ret, i;
1100 	bool s2idle = !hibernation && suspend_to_idle(dev_priv);
1101 
1102 	disable_rpm_wakeref_asserts(rpm);
1103 
1104 	intel_pxp_suspend(dev_priv->pxp);
1105 
1106 	i915_gem_suspend_late(dev_priv);
1107 
1108 	for_each_gt(gt, dev_priv, i)
1109 		intel_uncore_suspend(gt->uncore);
1110 
1111 	intel_display_power_suspend_late(display, s2idle);
1112 
1113 	ret = vlv_suspend_complete(dev_priv);
1114 	if (ret) {
1115 		drm_err(&dev_priv->drm, "Suspend complete failed: %d\n", ret);
1116 		intel_display_power_resume_early(display);
1117 
1118 		goto out;
1119 	}
1120 
1121 	pci_disable_device(pdev);
1122 	/*
1123 	 * During hibernation on some platforms the BIOS may try to access
1124 	 * the device even though it's already in D3 and hang the machine. So
1125 	 * leave the device in D0 on those platforms and hope the BIOS will
1126 	 * power down the device properly. The issue was seen on multiple old
1127 	 * GENs with different BIOS vendors, so having an explicit blacklist
1128 	 * is impractical; apply the workaround on everything pre GEN6. The
1129 	 * platforms where the issue was seen:
1130 	 * Lenovo Thinkpad X301, X61s, X60, T60, X41
1131 	 * Fujitsu FSC S7110
1132 	 * Acer Aspire 1830T
1133 	 */
1134 	if (!(hibernation && GRAPHICS_VER(dev_priv) < 6))
1135 		pci_set_power_state(pdev, PCI_D3hot);
1136 
1137 out:
1138 	enable_rpm_wakeref_asserts(rpm);
1139 	if (!dev_priv->uncore.user_forcewake_count)
1140 		intel_runtime_pm_driver_release(rpm);
1141 
1142 	return ret;
1143 }
1144 
1145 int i915_driver_suspend_switcheroo(struct drm_i915_private *i915,
1146 				   pm_message_t state)
1147 {
1148 	int error;
1149 
1150 	if (drm_WARN_ON_ONCE(&i915->drm, state.event != PM_EVENT_SUSPEND &&
1151 			     state.event != PM_EVENT_FREEZE))
1152 		return -EINVAL;
1153 
1154 	if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF)
1155 		return 0;
1156 
1157 	error = i915_drm_suspend(&i915->drm);
1158 	if (error)
1159 		return error;
1160 
1161 	return i915_drm_suspend_late(&i915->drm, false);
1162 }
1163 
1164 static int i915_drm_resume(struct drm_device *dev)
1165 {
1166 	struct drm_i915_private *dev_priv = to_i915(dev);
1167 	struct intel_display *display = &dev_priv->display;
1168 	struct intel_gt *gt;
1169 	int ret, i;
1170 
1171 	disable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
1172 
1173 	ret = i915_pcode_init(dev_priv);
1174 	if (ret)
1175 		return ret;
1176 
1177 	sanitize_gpu(dev_priv);
1178 
1179 	ret = i915_ggtt_enable_hw(dev_priv);
1180 	if (ret)
1181 		drm_err(&dev_priv->drm, "failed to re-enable GGTT\n");
1182 
1183 	i915_ggtt_resume(to_gt(dev_priv)->ggtt);
1184 
1185 	for_each_gt(gt, dev_priv, i)
1186 		if (GRAPHICS_VER(gt->i915) >= 8)
1187 			setup_private_pat(gt);
1188 
1189 	/* Must be called after GGTT is resumed. */
1190 	intel_dpt_resume(display);
1191 
1192 	intel_dmc_resume(display);
1193 
1194 	i9xx_display_sr_restore(display);
1195 
1196 	intel_vga_redisable(display);
1197 
1198 	intel_gmbus_reset(display);
1199 
1200 	intel_pps_unlock_regs_wa(display);
1201 
1202 	intel_init_pch_refclk(dev_priv);
1203 
1204 	/*
1205 	 * Interrupts have to be enabled before any batches are run. If not the
1206 	 * GPU will hang. i915_gem_init_hw() will initiate batches to
1207 	 * update/restore the context.
1208 	 *
1209 	 * drm_mode_config_reset() needs AUX interrupts.
1210 	 *
1211 	 * Modeset enabling in intel_display_driver_init_hw() also needs working
1212 	 * interrupts.
1213 	 */
1214 	intel_irq_resume(dev_priv);
1215 
1216 	if (HAS_DISPLAY(dev_priv))
1217 		drm_mode_config_reset(dev);
1218 
1219 	i915_gem_resume(dev_priv);
1220 
1221 	intel_display_driver_init_hw(display);
1222 
1223 	intel_clock_gating_init(dev_priv);
1224 
1225 	if (HAS_DISPLAY(dev_priv))
1226 		intel_display_driver_resume_access(display);
1227 
1228 	intel_hpd_init(dev_priv);
1229 
1230 	intel_display_driver_resume(display);
1231 
1232 	if (HAS_DISPLAY(dev_priv)) {
1233 		intel_display_driver_enable_user_access(display);
1234 		drm_kms_helper_poll_enable(dev);
1235 	}
1236 	intel_hpd_poll_disable(dev_priv);
1237 
1238 	intel_opregion_resume(display);
1239 
1240 	intel_fbdev_set_suspend(dev, FBINFO_STATE_RUNNING, false);
1241 
1242 	intel_power_domains_enable(display);
1243 
1244 	intel_gvt_resume(dev_priv);
1245 
1246 	enable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
1247 
1248 	return 0;
1249 }
1250 
1251 static int i915_drm_resume_early(struct drm_device *dev)
1252 {
1253 	struct drm_i915_private *dev_priv = to_i915(dev);
1254 	struct intel_display *display = &dev_priv->display;
1255 	struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev);
1256 	struct intel_gt *gt;
1257 	int ret, i;
1258 
1259 	/*
1260 	 * We have a resume ordering issue with the snd-hda driver also
1261 	 * requiring our device to be power up. Due to the lack of a
1262 	 * parent/child relationship we currently solve this with an early
1263 	 * resume hook.
1264 	 *
1265 	 * FIXME: This should be solved with a special hdmi sink device or
1266 	 * similar so that power domains can be employed.
1267 	 */
1268 
1269 	/*
1270 	 * Note that we need to set the power state explicitly, since we
1271 	 * powered off the device during freeze and the PCI core won't power
1272 	 * it back up for us during thaw. Powering off the device during
1273 	 * freeze is not a hard requirement though, and during the
1274 	 * suspend/resume phases the PCI core makes sure we get here with the
1275 	 * device powered on. So in case we change our freeze logic and keep
1276 	 * the device powered we can also remove the following set power state
1277 	 * call.
1278 	 */
1279 	ret = pci_set_power_state(pdev, PCI_D0);
1280 	if (ret) {
1281 		drm_err(&dev_priv->drm,
1282 			"failed to set PCI D0 power state (%d)\n", ret);
1283 		return ret;
1284 	}
1285 
1286 	/*
1287 	 * Note that pci_enable_device() first enables any parent bridge
1288 	 * device and only then sets the power state for this device. The
1289 	 * bridge enabling is a nop though, since bridge devices are resumed
1290 	 * first. The order of enabling power and enabling the device is
1291 	 * imposed by the PCI core as described above, so here we preserve the
1292 	 * same order for the freeze/thaw phases.
1293 	 *
1294 	 * TODO: eventually we should remove pci_disable_device() /
1295 	 * pci_enable_enable_device() from suspend/resume. Due to how they
1296 	 * depend on the device enable refcount we can't anyway depend on them
1297 	 * disabling/enabling the device.
1298 	 */
1299 	if (pci_enable_device(pdev))
1300 		return -EIO;
1301 
1302 	pci_set_master(pdev);
1303 
1304 	disable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
1305 
1306 	ret = vlv_resume_prepare(dev_priv, false);
1307 	if (ret)
1308 		drm_err(&dev_priv->drm,
1309 			"Resume prepare failed: %d, continuing anyway\n", ret);
1310 
1311 	for_each_gt(gt, dev_priv, i)
1312 		intel_gt_resume_early(gt);
1313 
1314 	intel_display_power_resume_early(display);
1315 
1316 	enable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
1317 
1318 	return ret;
1319 }
1320 
1321 int i915_driver_resume_switcheroo(struct drm_i915_private *i915)
1322 {
1323 	int ret;
1324 
1325 	if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF)
1326 		return 0;
1327 
1328 	ret = i915_drm_resume_early(&i915->drm);
1329 	if (ret)
1330 		return ret;
1331 
1332 	return i915_drm_resume(&i915->drm);
1333 }
1334 
1335 static int i915_pm_prepare(struct device *kdev)
1336 {
1337 	struct drm_i915_private *i915 = kdev_to_i915(kdev);
1338 
1339 	if (!i915) {
1340 		dev_err(kdev, "DRM not initialized, aborting suspend.\n");
1341 		return -ENODEV;
1342 	}
1343 
1344 	if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF)
1345 		return 0;
1346 
1347 	return i915_drm_prepare(&i915->drm);
1348 }
1349 
1350 static int i915_pm_suspend(struct device *kdev)
1351 {
1352 	struct drm_i915_private *i915 = kdev_to_i915(kdev);
1353 
1354 	if (!i915) {
1355 		dev_err(kdev, "DRM not initialized, aborting suspend.\n");
1356 		return -ENODEV;
1357 	}
1358 
1359 	if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF)
1360 		return 0;
1361 
1362 	return i915_drm_suspend(&i915->drm);
1363 }
1364 
1365 static int i915_pm_suspend_late(struct device *kdev)
1366 {
1367 	struct drm_i915_private *i915 = kdev_to_i915(kdev);
1368 
1369 	/*
1370 	 * We have a suspend ordering issue with the snd-hda driver also
1371 	 * requiring our device to be power up. Due to the lack of a
1372 	 * parent/child relationship we currently solve this with an late
1373 	 * suspend hook.
1374 	 *
1375 	 * FIXME: This should be solved with a special hdmi sink device or
1376 	 * similar so that power domains can be employed.
1377 	 */
1378 	if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF)
1379 		return 0;
1380 
1381 	return i915_drm_suspend_late(&i915->drm, false);
1382 }
1383 
1384 static int i915_pm_poweroff_late(struct device *kdev)
1385 {
1386 	struct drm_i915_private *i915 = kdev_to_i915(kdev);
1387 
1388 	if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF)
1389 		return 0;
1390 
1391 	return i915_drm_suspend_late(&i915->drm, true);
1392 }
1393 
1394 static int i915_pm_resume_early(struct device *kdev)
1395 {
1396 	struct drm_i915_private *i915 = kdev_to_i915(kdev);
1397 
1398 	if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF)
1399 		return 0;
1400 
1401 	return i915_drm_resume_early(&i915->drm);
1402 }
1403 
1404 static int i915_pm_resume(struct device *kdev)
1405 {
1406 	struct drm_i915_private *i915 = kdev_to_i915(kdev);
1407 
1408 	if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF)
1409 		return 0;
1410 
1411 	return i915_drm_resume(&i915->drm);
1412 }
1413 
1414 static void i915_pm_complete(struct device *kdev)
1415 {
1416 	struct drm_i915_private *i915 = kdev_to_i915(kdev);
1417 
1418 	if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF)
1419 		return;
1420 
1421 	i915_drm_complete(&i915->drm);
1422 }
1423 
1424 /* freeze: before creating the hibernation_image */
1425 static int i915_pm_freeze(struct device *kdev)
1426 {
1427 	struct drm_i915_private *i915 = kdev_to_i915(kdev);
1428 	int ret;
1429 
1430 	if (i915->drm.switch_power_state != DRM_SWITCH_POWER_OFF) {
1431 		ret = i915_drm_suspend(&i915->drm);
1432 		if (ret)
1433 			return ret;
1434 	}
1435 
1436 	ret = i915_gem_freeze(i915);
1437 	if (ret)
1438 		return ret;
1439 
1440 	return 0;
1441 }
1442 
1443 static int i915_pm_freeze_late(struct device *kdev)
1444 {
1445 	struct drm_i915_private *i915 = kdev_to_i915(kdev);
1446 	int ret;
1447 
1448 	if (i915->drm.switch_power_state != DRM_SWITCH_POWER_OFF) {
1449 		ret = i915_drm_suspend_late(&i915->drm, true);
1450 		if (ret)
1451 			return ret;
1452 	}
1453 
1454 	ret = i915_gem_freeze_late(i915);
1455 	if (ret)
1456 		return ret;
1457 
1458 	return 0;
1459 }
1460 
1461 /* thaw: called after creating the hibernation image, but before turning off. */
1462 static int i915_pm_thaw_early(struct device *kdev)
1463 {
1464 	return i915_pm_resume_early(kdev);
1465 }
1466 
1467 static int i915_pm_thaw(struct device *kdev)
1468 {
1469 	return i915_pm_resume(kdev);
1470 }
1471 
1472 /* restore: called after loading the hibernation image. */
1473 static int i915_pm_restore_early(struct device *kdev)
1474 {
1475 	return i915_pm_resume_early(kdev);
1476 }
1477 
1478 static int i915_pm_restore(struct device *kdev)
1479 {
1480 	return i915_pm_resume(kdev);
1481 }
1482 
1483 static int intel_runtime_suspend(struct device *kdev)
1484 {
1485 	struct drm_i915_private *dev_priv = kdev_to_i915(kdev);
1486 	struct intel_display *display = &dev_priv->display;
1487 	struct intel_runtime_pm *rpm = &dev_priv->runtime_pm;
1488 	struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev);
1489 	struct pci_dev *root_pdev;
1490 	struct intel_gt *gt;
1491 	int ret, i;
1492 
1493 	if (drm_WARN_ON_ONCE(&dev_priv->drm, !HAS_RUNTIME_PM(dev_priv)))
1494 		return -ENODEV;
1495 
1496 	drm_dbg(&dev_priv->drm, "Suspending device\n");
1497 
1498 	disable_rpm_wakeref_asserts(rpm);
1499 
1500 	/*
1501 	 * We are safe here against re-faults, since the fault handler takes
1502 	 * an RPM reference.
1503 	 */
1504 	i915_gem_runtime_suspend(dev_priv);
1505 
1506 	intel_pxp_runtime_suspend(dev_priv->pxp);
1507 
1508 	for_each_gt(gt, dev_priv, i)
1509 		intel_gt_runtime_suspend(gt);
1510 
1511 	intel_irq_suspend(dev_priv);
1512 
1513 	for_each_gt(gt, dev_priv, i)
1514 		intel_uncore_suspend(gt->uncore);
1515 
1516 	intel_display_power_suspend(display);
1517 
1518 	ret = vlv_suspend_complete(dev_priv);
1519 	if (ret) {
1520 		drm_err(&dev_priv->drm,
1521 			"Runtime suspend failed, disabling it (%d)\n", ret);
1522 		intel_uncore_runtime_resume(&dev_priv->uncore);
1523 
1524 		intel_irq_resume(dev_priv);
1525 
1526 		for_each_gt(gt, dev_priv, i)
1527 			intel_gt_runtime_resume(gt);
1528 
1529 		enable_rpm_wakeref_asserts(rpm);
1530 
1531 		return ret;
1532 	}
1533 
1534 	enable_rpm_wakeref_asserts(rpm);
1535 	intel_runtime_pm_driver_release(rpm);
1536 
1537 	if (intel_uncore_arm_unclaimed_mmio_detection(&dev_priv->uncore))
1538 		drm_err(&dev_priv->drm,
1539 			"Unclaimed access detected prior to suspending\n");
1540 
1541 	/*
1542 	 * FIXME: Temporary hammer to avoid freezing the machine on our DGFX
1543 	 * This should be totally removed when we handle the pci states properly
1544 	 * on runtime PM.
1545 	 */
1546 	root_pdev = pcie_find_root_port(pdev);
1547 	if (root_pdev)
1548 		pci_d3cold_disable(root_pdev);
1549 
1550 	/*
1551 	 * FIXME: We really should find a document that references the arguments
1552 	 * used below!
1553 	 */
1554 	if (IS_BROADWELL(dev_priv)) {
1555 		/*
1556 		 * On Broadwell, if we use PCI_D1 the PCH DDI ports will stop
1557 		 * being detected, and the call we do at intel_runtime_resume()
1558 		 * won't be able to restore them. Since PCI_D3hot matches the
1559 		 * actual specification and appears to be working, use it.
1560 		 */
1561 		intel_opregion_notify_adapter(display, PCI_D3hot);
1562 	} else {
1563 		/*
1564 		 * current versions of firmware which depend on this opregion
1565 		 * notification have repurposed the D1 definition to mean
1566 		 * "runtime suspended" vs. what you would normally expect (D3)
1567 		 * to distinguish it from notifications that might be sent via
1568 		 * the suspend path.
1569 		 */
1570 		intel_opregion_notify_adapter(display, PCI_D1);
1571 	}
1572 
1573 	assert_forcewakes_inactive(&dev_priv->uncore);
1574 
1575 	if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv))
1576 		intel_hpd_poll_enable(dev_priv);
1577 
1578 	drm_dbg(&dev_priv->drm, "Device suspended\n");
1579 	return 0;
1580 }
1581 
1582 static int intel_runtime_resume(struct device *kdev)
1583 {
1584 	struct drm_i915_private *dev_priv = kdev_to_i915(kdev);
1585 	struct intel_display *display = &dev_priv->display;
1586 	struct intel_runtime_pm *rpm = &dev_priv->runtime_pm;
1587 	struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev);
1588 	struct pci_dev *root_pdev;
1589 	struct intel_gt *gt;
1590 	int ret, i;
1591 
1592 	if (drm_WARN_ON_ONCE(&dev_priv->drm, !HAS_RUNTIME_PM(dev_priv)))
1593 		return -ENODEV;
1594 
1595 	drm_dbg(&dev_priv->drm, "Resuming device\n");
1596 
1597 	drm_WARN_ON_ONCE(&dev_priv->drm, atomic_read(&rpm->wakeref_count));
1598 	disable_rpm_wakeref_asserts(rpm);
1599 
1600 	intel_opregion_notify_adapter(display, PCI_D0);
1601 
1602 	root_pdev = pcie_find_root_port(pdev);
1603 	if (root_pdev)
1604 		pci_d3cold_enable(root_pdev);
1605 
1606 	if (intel_uncore_unclaimed_mmio(&dev_priv->uncore))
1607 		drm_dbg(&dev_priv->drm,
1608 			"Unclaimed access during suspend, bios?\n");
1609 
1610 	intel_display_power_resume(display);
1611 
1612 	ret = vlv_resume_prepare(dev_priv, true);
1613 
1614 	for_each_gt(gt, dev_priv, i)
1615 		intel_uncore_runtime_resume(gt->uncore);
1616 
1617 	intel_irq_resume(dev_priv);
1618 
1619 	/*
1620 	 * No point of rolling back things in case of an error, as the best
1621 	 * we can do is to hope that things will still work (and disable RPM).
1622 	 */
1623 	for_each_gt(gt, dev_priv, i)
1624 		intel_gt_runtime_resume(gt);
1625 
1626 	intel_pxp_runtime_resume(dev_priv->pxp);
1627 
1628 	/*
1629 	 * On VLV/CHV display interrupts are part of the display
1630 	 * power well, so hpd is reinitialized from there. For
1631 	 * everyone else do it here.
1632 	 */
1633 	if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
1634 		intel_hpd_init(dev_priv);
1635 		intel_hpd_poll_disable(dev_priv);
1636 	}
1637 
1638 	skl_watermark_ipc_update(dev_priv);
1639 
1640 	enable_rpm_wakeref_asserts(rpm);
1641 
1642 	if (ret)
1643 		drm_err(&dev_priv->drm,
1644 			"Runtime resume failed, disabling it (%d)\n", ret);
1645 	else
1646 		drm_dbg(&dev_priv->drm, "Device resumed\n");
1647 
1648 	return ret;
1649 }
1650 
1651 const struct dev_pm_ops i915_pm_ops = {
1652 	/*
1653 	 * S0ix (via system suspend) and S3 event handlers [PMSG_SUSPEND,
1654 	 * PMSG_RESUME]
1655 	 */
1656 	.prepare = i915_pm_prepare,
1657 	.suspend = i915_pm_suspend,
1658 	.suspend_late = i915_pm_suspend_late,
1659 	.resume_early = i915_pm_resume_early,
1660 	.resume = i915_pm_resume,
1661 	.complete = i915_pm_complete,
1662 
1663 	/*
1664 	 * S4 event handlers
1665 	 * @freeze, @freeze_late    : called (1) before creating the
1666 	 *                            hibernation image [PMSG_FREEZE] and
1667 	 *                            (2) after rebooting, before restoring
1668 	 *                            the image [PMSG_QUIESCE]
1669 	 * @thaw, @thaw_early       : called (1) after creating the hibernation
1670 	 *                            image, before writing it [PMSG_THAW]
1671 	 *                            and (2) after failing to create or
1672 	 *                            restore the image [PMSG_RECOVER]
1673 	 * @poweroff, @poweroff_late: called after writing the hibernation
1674 	 *                            image, before rebooting [PMSG_HIBERNATE]
1675 	 * @restore, @restore_early : called after rebooting and restoring the
1676 	 *                            hibernation image [PMSG_RESTORE]
1677 	 */
1678 	.freeze = i915_pm_freeze,
1679 	.freeze_late = i915_pm_freeze_late,
1680 	.thaw_early = i915_pm_thaw_early,
1681 	.thaw = i915_pm_thaw,
1682 	.poweroff = i915_pm_suspend,
1683 	.poweroff_late = i915_pm_poweroff_late,
1684 	.restore_early = i915_pm_restore_early,
1685 	.restore = i915_pm_restore,
1686 
1687 	/* S0ix (via runtime suspend) event handlers */
1688 	.runtime_suspend = intel_runtime_suspend,
1689 	.runtime_resume = intel_runtime_resume,
1690 };
1691 
1692 static const struct file_operations i915_driver_fops = {
1693 	.owner = THIS_MODULE,
1694 	.open = drm_open,
1695 	.release = drm_release_noglobal,
1696 	.unlocked_ioctl = drm_ioctl,
1697 	.mmap = i915_gem_mmap,
1698 	.poll = drm_poll,
1699 	.read = drm_read,
1700 	.compat_ioctl = i915_ioc32_compat_ioctl,
1701 	.llseek = noop_llseek,
1702 #ifdef CONFIG_PROC_FS
1703 	.show_fdinfo = drm_show_fdinfo,
1704 #endif
1705 	.fop_flags = FOP_UNSIGNED_OFFSET,
1706 };
1707 
1708 static int
1709 i915_gem_reject_pin_ioctl(struct drm_device *dev, void *data,
1710 			  struct drm_file *file)
1711 {
1712 	return -ENODEV;
1713 }
1714 
1715 static const struct drm_ioctl_desc i915_ioctls[] = {
1716 	DRM_IOCTL_DEF_DRV(I915_INIT, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
1717 	DRM_IOCTL_DEF_DRV(I915_FLUSH, drm_noop, DRM_AUTH),
1718 	DRM_IOCTL_DEF_DRV(I915_FLIP, drm_noop, DRM_AUTH),
1719 	DRM_IOCTL_DEF_DRV(I915_BATCHBUFFER, drm_noop, DRM_AUTH),
1720 	DRM_IOCTL_DEF_DRV(I915_IRQ_EMIT, drm_noop, DRM_AUTH),
1721 	DRM_IOCTL_DEF_DRV(I915_IRQ_WAIT, drm_noop, DRM_AUTH),
1722 	DRM_IOCTL_DEF_DRV(I915_GETPARAM, i915_getparam_ioctl, DRM_RENDER_ALLOW),
1723 	DRM_IOCTL_DEF_DRV(I915_SETPARAM, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
1724 	DRM_IOCTL_DEF_DRV(I915_ALLOC, drm_noop, DRM_AUTH),
1725 	DRM_IOCTL_DEF_DRV(I915_FREE, drm_noop, DRM_AUTH),
1726 	DRM_IOCTL_DEF_DRV(I915_INIT_HEAP, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
1727 	DRM_IOCTL_DEF_DRV(I915_CMDBUFFER, drm_noop, DRM_AUTH),
1728 	DRM_IOCTL_DEF_DRV(I915_DESTROY_HEAP, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
1729 	DRM_IOCTL_DEF_DRV(I915_SET_VBLANK_PIPE, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
1730 	DRM_IOCTL_DEF_DRV(I915_GET_VBLANK_PIPE, drm_noop, DRM_AUTH),
1731 	DRM_IOCTL_DEF_DRV(I915_VBLANK_SWAP, drm_noop, DRM_AUTH),
1732 	DRM_IOCTL_DEF_DRV(I915_HWS_ADDR, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
1733 	DRM_IOCTL_DEF_DRV(I915_GEM_INIT, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
1734 	DRM_IOCTL_DEF_DRV(I915_GEM_EXECBUFFER, drm_invalid_op, DRM_AUTH),
1735 	DRM_IOCTL_DEF_DRV(I915_GEM_EXECBUFFER2_WR, i915_gem_execbuffer2_ioctl, DRM_RENDER_ALLOW),
1736 	DRM_IOCTL_DEF_DRV(I915_GEM_PIN, i915_gem_reject_pin_ioctl, DRM_AUTH|DRM_ROOT_ONLY),
1737 	DRM_IOCTL_DEF_DRV(I915_GEM_UNPIN, i915_gem_reject_pin_ioctl, DRM_AUTH|DRM_ROOT_ONLY),
1738 	DRM_IOCTL_DEF_DRV(I915_GEM_BUSY, i915_gem_busy_ioctl, DRM_RENDER_ALLOW),
1739 	DRM_IOCTL_DEF_DRV(I915_GEM_SET_CACHING, i915_gem_set_caching_ioctl, DRM_RENDER_ALLOW),
1740 	DRM_IOCTL_DEF_DRV(I915_GEM_GET_CACHING, i915_gem_get_caching_ioctl, DRM_RENDER_ALLOW),
1741 	DRM_IOCTL_DEF_DRV(I915_GEM_THROTTLE, i915_gem_throttle_ioctl, DRM_RENDER_ALLOW),
1742 	DRM_IOCTL_DEF_DRV(I915_GEM_ENTERVT, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
1743 	DRM_IOCTL_DEF_DRV(I915_GEM_LEAVEVT, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
1744 	DRM_IOCTL_DEF_DRV(I915_GEM_CREATE, i915_gem_create_ioctl, DRM_RENDER_ALLOW),
1745 	DRM_IOCTL_DEF_DRV(I915_GEM_CREATE_EXT, i915_gem_create_ext_ioctl, DRM_RENDER_ALLOW),
1746 	DRM_IOCTL_DEF_DRV(I915_GEM_PREAD, i915_gem_pread_ioctl, DRM_RENDER_ALLOW),
1747 	DRM_IOCTL_DEF_DRV(I915_GEM_PWRITE, i915_gem_pwrite_ioctl, DRM_RENDER_ALLOW),
1748 	DRM_IOCTL_DEF_DRV(I915_GEM_MMAP, i915_gem_mmap_ioctl, DRM_RENDER_ALLOW),
1749 	DRM_IOCTL_DEF_DRV(I915_GEM_MMAP_OFFSET, i915_gem_mmap_offset_ioctl, DRM_RENDER_ALLOW),
1750 	DRM_IOCTL_DEF_DRV(I915_GEM_SET_DOMAIN, i915_gem_set_domain_ioctl, DRM_RENDER_ALLOW),
1751 	DRM_IOCTL_DEF_DRV(I915_GEM_SW_FINISH, i915_gem_sw_finish_ioctl, DRM_RENDER_ALLOW),
1752 	DRM_IOCTL_DEF_DRV(I915_GEM_SET_TILING, i915_gem_set_tiling_ioctl, DRM_RENDER_ALLOW),
1753 	DRM_IOCTL_DEF_DRV(I915_GEM_GET_TILING, i915_gem_get_tiling_ioctl, DRM_RENDER_ALLOW),
1754 	DRM_IOCTL_DEF_DRV(I915_GEM_GET_APERTURE, i915_gem_get_aperture_ioctl, DRM_RENDER_ALLOW),
1755 	DRM_IOCTL_DEF_DRV(I915_GET_PIPE_FROM_CRTC_ID, intel_crtc_get_pipe_from_crtc_id_ioctl, 0),
1756 	DRM_IOCTL_DEF_DRV(I915_GEM_MADVISE, i915_gem_madvise_ioctl, DRM_RENDER_ALLOW),
1757 	DRM_IOCTL_DEF_DRV(I915_OVERLAY_PUT_IMAGE, intel_overlay_put_image_ioctl, DRM_MASTER),
1758 	DRM_IOCTL_DEF_DRV(I915_OVERLAY_ATTRS, intel_overlay_attrs_ioctl, DRM_MASTER),
1759 	DRM_IOCTL_DEF_DRV(I915_SET_SPRITE_COLORKEY, intel_sprite_set_colorkey_ioctl, DRM_MASTER),
1760 	DRM_IOCTL_DEF_DRV(I915_GET_SPRITE_COLORKEY, drm_noop, DRM_MASTER),
1761 	DRM_IOCTL_DEF_DRV(I915_GEM_WAIT, i915_gem_wait_ioctl, DRM_RENDER_ALLOW),
1762 	DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_CREATE_EXT, i915_gem_context_create_ioctl, DRM_RENDER_ALLOW),
1763 	DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_DESTROY, i915_gem_context_destroy_ioctl, DRM_RENDER_ALLOW),
1764 	DRM_IOCTL_DEF_DRV(I915_REG_READ, i915_reg_read_ioctl, DRM_RENDER_ALLOW),
1765 	DRM_IOCTL_DEF_DRV(I915_GET_RESET_STATS, i915_gem_context_reset_stats_ioctl, DRM_RENDER_ALLOW),
1766 	DRM_IOCTL_DEF_DRV(I915_GEM_USERPTR, i915_gem_userptr_ioctl, DRM_RENDER_ALLOW),
1767 	DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_GETPARAM, i915_gem_context_getparam_ioctl, DRM_RENDER_ALLOW),
1768 	DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_SETPARAM, i915_gem_context_setparam_ioctl, DRM_RENDER_ALLOW),
1769 	DRM_IOCTL_DEF_DRV(I915_PERF_OPEN, i915_perf_open_ioctl, DRM_RENDER_ALLOW),
1770 	DRM_IOCTL_DEF_DRV(I915_PERF_ADD_CONFIG, i915_perf_add_config_ioctl, DRM_RENDER_ALLOW),
1771 	DRM_IOCTL_DEF_DRV(I915_PERF_REMOVE_CONFIG, i915_perf_remove_config_ioctl, DRM_RENDER_ALLOW),
1772 	DRM_IOCTL_DEF_DRV(I915_QUERY, i915_query_ioctl, DRM_RENDER_ALLOW),
1773 	DRM_IOCTL_DEF_DRV(I915_GEM_VM_CREATE, i915_gem_vm_create_ioctl, DRM_RENDER_ALLOW),
1774 	DRM_IOCTL_DEF_DRV(I915_GEM_VM_DESTROY, i915_gem_vm_destroy_ioctl, DRM_RENDER_ALLOW),
1775 };
1776 
1777 /*
1778  * Interface history:
1779  *
1780  * 1.1: Original.
1781  * 1.2: Add Power Management
1782  * 1.3: Add vblank support
1783  * 1.4: Fix cmdbuffer path, add heap destroy
1784  * 1.5: Add vblank pipe configuration
1785  * 1.6: - New ioctl for scheduling buffer swaps on vertical blank
1786  *      - Support vertical blank on secondary display pipe
1787  */
1788 #define DRIVER_MAJOR		1
1789 #define DRIVER_MINOR		6
1790 #define DRIVER_PATCHLEVEL	0
1791 
1792 static const struct drm_driver i915_drm_driver = {
1793 	/* Don't use MTRRs here; the Xserver or userspace app should
1794 	 * deal with them for Intel hardware.
1795 	 */
1796 	.driver_features =
1797 	    DRIVER_GEM |
1798 	    DRIVER_RENDER | DRIVER_MODESET | DRIVER_ATOMIC | DRIVER_SYNCOBJ |
1799 	    DRIVER_SYNCOBJ_TIMELINE,
1800 	.release = i915_driver_release,
1801 	.open = i915_driver_open,
1802 	.postclose = i915_driver_postclose,
1803 	.show_fdinfo = PTR_IF(IS_ENABLED(CONFIG_PROC_FS), i915_drm_client_fdinfo),
1804 
1805 	.gem_prime_import = i915_gem_prime_import,
1806 
1807 	.dumb_create = i915_gem_dumb_create,
1808 	.dumb_map_offset = i915_gem_dumb_mmap_offset,
1809 
1810 	.ioctls = i915_ioctls,
1811 	.num_ioctls = ARRAY_SIZE(i915_ioctls),
1812 	.fops = &i915_driver_fops,
1813 	.name = DRIVER_NAME,
1814 	.desc = DRIVER_DESC,
1815 	.major = DRIVER_MAJOR,
1816 	.minor = DRIVER_MINOR,
1817 	.patchlevel = DRIVER_PATCHLEVEL,
1818 };
1819