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