blob: 4e1fcee1d0f0e951c3688ee857f12e85664c9b2c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* i915_drv.c -- i830,i845,i855,i865,i915 driver -*- linux-c -*-
2 */
Dave Airlie0d6aa602006-01-02 20:14:23 +11003/*
Dave Airliebc54fd12005-06-23 22:46:46 +10004 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * All Rights Reserved.
Dave Airliebc54fd12005-06-23 22:46:46 +10007 *
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 *
Dave Airlie0d6aa602006-01-02 20:14:23 +110028 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Jesse Barnese5747e32014-06-12 08:35:47 -070030#include <linux/acpi.h>
Chris Wilson0673ad42016-06-24 14:00:22 +010031#include <linux/device.h>
32#include <linux/oom.h>
33#include <linux/module.h>
34#include <linux/pci.h>
35#include <linux/pm.h>
36#include <linux/pm_runtime.h>
37#include <linux/pnp.h>
38#include <linux/slab.h>
Chris Wilson0673ad42016-06-24 14:00:22 +010039#include <linux/vga_switcheroo.h>
40#include <linux/vt.h>
41#include <acpi/video.h>
42
Maarten Lankhorsta667fb42016-12-15 15:29:44 +010043#include <drm/drm_atomic_helper.h>
Sam Ravnborgd0e93592019-01-26 13:25:24 +010044#include <drm/drm_ioctl.h>
45#include <drm/drm_irq.h>
46#include <drm/drm_probe_helper.h>
Chris Wilson0673ad42016-06-24 14:00:22 +010047
Jani Nikuladf0566a2019-06-13 11:44:16 +030048#include "display/intel_acpi.h"
49#include "display/intel_audio.h"
50#include "display/intel_bw.h"
51#include "display/intel_cdclk.h"
Jani Nikula06d3ff62020-02-11 18:14:50 +020052#include "display/intel_csr.h"
Jani Nikula926b0052020-02-11 18:14:51 +020053#include "display/intel_display_debugfs.h"
Jani Nikula1d455f82019-08-06 14:39:33 +030054#include "display/intel_display_types.h"
Jani Nikula379bc102019-06-13 11:44:15 +030055#include "display/intel_dp.h"
Jani Nikuladf0566a2019-06-13 11:44:16 +030056#include "display/intel_fbdev.h"
Jani Nikuladf0566a2019-06-13 11:44:16 +030057#include "display/intel_hotplug.h"
58#include "display/intel_overlay.h"
59#include "display/intel_pipe_crc.h"
José Roberto de Souzadf1a5bf2020-02-21 13:26:35 -080060#include "display/intel_psr.h"
Jani Nikuladf0566a2019-06-13 11:44:16 +030061#include "display/intel_sprite.h"
Jani Nikula4fb87832019-10-01 18:25:06 +030062#include "display/intel_vga.h"
Jani Nikula379bc102019-06-13 11:44:15 +030063
Chris Wilson10be98a2019-05-28 10:29:49 +010064#include "gem/i915_gem_context.h"
Chris Wilsonafa13082019-05-28 10:29:43 +010065#include "gem/i915_gem_ioctls.h"
Abdiel Janulguecc662122019-12-04 12:00:32 +000066#include "gem/i915_gem_mman.h"
Tvrtko Ursulin24635c52019-06-21 08:07:41 +010067#include "gt/intel_gt.h"
Chris Wilson79ffac852019-04-24 21:07:17 +010068#include "gt/intel_gt_pm.h"
Imre Deak2248a282019-10-17 16:38:31 +030069#include "gt/intel_rc6.h"
Chris Wilson112ed2d2019-04-24 18:48:39 +010070
Jani Nikula2126d3e2019-05-02 18:02:43 +030071#include "i915_debugfs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070072#include "i915_drv.h"
Jani Nikula440e2b32019-04-29 15:29:27 +030073#include "i915_irq.h"
Jani Nikula9c9082b2019-08-08 16:42:47 +030074#include "i915_memcpy.h"
Jani Nikuladb94e9f2019-08-08 16:42:44 +030075#include "i915_perf.h"
Lionel Landwerlina446ae22018-03-06 12:28:56 +000076#include "i915_query.h"
Jani Nikulabdd15102019-08-08 16:42:46 +030077#include "i915_suspend.h"
Jani Nikula63bf8302019-10-04 15:20:18 +030078#include "i915_switcheroo.h"
Jani Nikulabe682612019-08-08 16:42:45 +030079#include "i915_sysfs.h"
Jani Nikula331c2012019-04-05 14:00:03 +030080#include "i915_trace.h"
Chris Wilson0673ad42016-06-24 14:00:22 +010081#include "i915_vgpu.h"
Jani Nikulad28ae3b2020-02-25 13:15:07 +020082#include "intel_dram.h"
Chris Wilson3fc794f2019-10-26 21:20:32 +010083#include "intel_memory_region.h"
Jani Nikula696173b2019-04-05 14:00:15 +030084#include "intel_pm.h"
Jani Nikulafb5f4322020-02-12 16:40:57 +020085#include "vlv_suspend.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
Kristian Høgsberg112b7152009-01-04 16:55:33 -050087static struct drm_driver driver;
88
Tvrtko Ursulinda5f53b2016-12-01 14:16:40 +000089static int i915_get_bridge_dev(struct drm_i915_private *dev_priv)
Chris Wilson0673ad42016-06-24 14:00:22 +010090{
Sinan Kaya57b296462017-11-27 11:57:46 -050091 int domain = pci_domain_nr(dev_priv->drm.pdev->bus);
92
93 dev_priv->bridge_dev =
94 pci_get_domain_bus_and_slot(domain, 0, PCI_DEVFN(0, 0));
Chris Wilson0673ad42016-06-24 14:00:22 +010095 if (!dev_priv->bridge_dev) {
Wambui Karuga00376cc2020-01-31 12:34:12 +030096 drm_err(&dev_priv->drm, "bridge device not found\n");
Chris Wilson0673ad42016-06-24 14:00:22 +010097 return -1;
98 }
99 return 0;
100}
101
102/* Allocate space for the MCH regs if needed, return nonzero on error */
103static int
Tvrtko Ursulinda5f53b2016-12-01 14:16:40 +0000104intel_alloc_mchbar_resource(struct drm_i915_private *dev_priv)
Chris Wilson0673ad42016-06-24 14:00:22 +0100105{
Tvrtko Ursulin514e1d62016-11-04 14:42:48 +0000106 int reg = INTEL_GEN(dev_priv) >= 4 ? MCHBAR_I965 : MCHBAR_I915;
Chris Wilson0673ad42016-06-24 14:00:22 +0100107 u32 temp_lo, temp_hi = 0;
108 u64 mchbar_addr;
109 int ret;
110
Tvrtko Ursulin514e1d62016-11-04 14:42:48 +0000111 if (INTEL_GEN(dev_priv) >= 4)
Chris Wilson0673ad42016-06-24 14:00:22 +0100112 pci_read_config_dword(dev_priv->bridge_dev, reg + 4, &temp_hi);
113 pci_read_config_dword(dev_priv->bridge_dev, reg, &temp_lo);
114 mchbar_addr = ((u64)temp_hi << 32) | temp_lo;
115
116 /* If ACPI doesn't have it, assume we need to allocate it ourselves */
117#ifdef CONFIG_PNP
118 if (mchbar_addr &&
119 pnp_range_reserved(mchbar_addr, mchbar_addr + MCHBAR_SIZE))
120 return 0;
121#endif
122
123 /* Get some space for it */
124 dev_priv->mch_res.name = "i915 MCHBAR";
125 dev_priv->mch_res.flags = IORESOURCE_MEM;
126 ret = pci_bus_alloc_resource(dev_priv->bridge_dev->bus,
127 &dev_priv->mch_res,
128 MCHBAR_SIZE, MCHBAR_SIZE,
129 PCIBIOS_MIN_MEM,
130 0, pcibios_align_resource,
131 dev_priv->bridge_dev);
132 if (ret) {
Wambui Karuga00376cc2020-01-31 12:34:12 +0300133 drm_dbg(&dev_priv->drm, "failed bus alloc: %d\n", ret);
Chris Wilson0673ad42016-06-24 14:00:22 +0100134 dev_priv->mch_res.start = 0;
135 return ret;
136 }
137
Tvrtko Ursulin514e1d62016-11-04 14:42:48 +0000138 if (INTEL_GEN(dev_priv) >= 4)
Chris Wilson0673ad42016-06-24 14:00:22 +0100139 pci_write_config_dword(dev_priv->bridge_dev, reg + 4,
140 upper_32_bits(dev_priv->mch_res.start));
141
142 pci_write_config_dword(dev_priv->bridge_dev, reg,
143 lower_32_bits(dev_priv->mch_res.start));
144 return 0;
145}
146
147/* Setup MCHBAR if possible, return true if we should disable it again */
148static void
Tvrtko Ursulinda5f53b2016-12-01 14:16:40 +0000149intel_setup_mchbar(struct drm_i915_private *dev_priv)
Chris Wilson0673ad42016-06-24 14:00:22 +0100150{
Tvrtko Ursulin514e1d62016-11-04 14:42:48 +0000151 int mchbar_reg = INTEL_GEN(dev_priv) >= 4 ? MCHBAR_I965 : MCHBAR_I915;
Chris Wilson0673ad42016-06-24 14:00:22 +0100152 u32 temp;
153 bool enabled;
154
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100155 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Chris Wilson0673ad42016-06-24 14:00:22 +0100156 return;
157
158 dev_priv->mchbar_need_disable = false;
159
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +0100160 if (IS_I915G(dev_priv) || IS_I915GM(dev_priv)) {
Chris Wilson0673ad42016-06-24 14:00:22 +0100161 pci_read_config_dword(dev_priv->bridge_dev, DEVEN, &temp);
162 enabled = !!(temp & DEVEN_MCHBAR_EN);
163 } else {
164 pci_read_config_dword(dev_priv->bridge_dev, mchbar_reg, &temp);
165 enabled = temp & 1;
166 }
167
168 /* If it's already enabled, don't have to do anything */
169 if (enabled)
170 return;
171
Tvrtko Ursulinda5f53b2016-12-01 14:16:40 +0000172 if (intel_alloc_mchbar_resource(dev_priv))
Chris Wilson0673ad42016-06-24 14:00:22 +0100173 return;
174
175 dev_priv->mchbar_need_disable = true;
176
177 /* Space is allocated or reserved, so enable it. */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +0100178 if (IS_I915G(dev_priv) || IS_I915GM(dev_priv)) {
Chris Wilson0673ad42016-06-24 14:00:22 +0100179 pci_write_config_dword(dev_priv->bridge_dev, DEVEN,
180 temp | DEVEN_MCHBAR_EN);
181 } else {
182 pci_read_config_dword(dev_priv->bridge_dev, mchbar_reg, &temp);
183 pci_write_config_dword(dev_priv->bridge_dev, mchbar_reg, temp | 1);
184 }
185}
186
187static void
Tvrtko Ursulinda5f53b2016-12-01 14:16:40 +0000188intel_teardown_mchbar(struct drm_i915_private *dev_priv)
Chris Wilson0673ad42016-06-24 14:00:22 +0100189{
Tvrtko Ursulin514e1d62016-11-04 14:42:48 +0000190 int mchbar_reg = INTEL_GEN(dev_priv) >= 4 ? MCHBAR_I965 : MCHBAR_I915;
Chris Wilson0673ad42016-06-24 14:00:22 +0100191
192 if (dev_priv->mchbar_need_disable) {
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +0100193 if (IS_I915G(dev_priv) || IS_I915GM(dev_priv)) {
Chris Wilson0673ad42016-06-24 14:00:22 +0100194 u32 deven_val;
195
196 pci_read_config_dword(dev_priv->bridge_dev, DEVEN,
197 &deven_val);
198 deven_val &= ~DEVEN_MCHBAR_EN;
199 pci_write_config_dword(dev_priv->bridge_dev, DEVEN,
200 deven_val);
201 } else {
202 u32 mchbar_val;
203
204 pci_read_config_dword(dev_priv->bridge_dev, mchbar_reg,
205 &mchbar_val);
206 mchbar_val &= ~1;
207 pci_write_config_dword(dev_priv->bridge_dev, mchbar_reg,
208 mchbar_val);
209 }
210 }
211
212 if (dev_priv->mch_res.start)
213 release_resource(&dev_priv->mch_res);
214}
215
Jani Nikulab6642592020-02-19 15:37:56 +0200216/* part #1: call before irq install */
217static int i915_driver_modeset_probe_noirq(struct drm_i915_private *i915)
Chris Wilson0673ad42016-06-24 14:00:22 +0100218{
Chris Wilson0673ad42016-06-24 14:00:22 +0100219 int ret;
220
Jani Nikula5bcd53a2019-09-20 21:54:17 +0300221 if (i915_inject_probe_failure(i915))
Chris Wilson0673ad42016-06-24 14:00:22 +0100222 return -ENODEV;
223
Jani Nikula5bcd53a2019-09-20 21:54:17 +0300224 if (HAS_DISPLAY(i915) && INTEL_DISPLAY_ENABLED(i915)) {
225 ret = drm_vblank_init(&i915->drm,
226 INTEL_NUM_PIPES(i915));
José Roberto de Souza8d3bf1a2018-11-07 16:16:44 -0800227 if (ret)
228 goto out;
229 }
230
Jani Nikula5bcd53a2019-09-20 21:54:17 +0300231 intel_bios_init(i915);
Chris Wilson0673ad42016-06-24 14:00:22 +0100232
Jani Nikula4fb87832019-10-01 18:25:06 +0300233 ret = intel_vga_register(i915);
234 if (ret)
Chris Wilson0673ad42016-06-24 14:00:22 +0100235 goto out;
236
Jani Nikula5bcd53a2019-09-20 21:54:17 +0300237 intel_power_domains_init_hw(i915, false);
Chris Wilson0673ad42016-06-24 14:00:22 +0100238
Jani Nikula5bcd53a2019-09-20 21:54:17 +0300239 intel_csr_ucode_init(i915);
Chris Wilson0673ad42016-06-24 14:00:22 +0100240
Jani Nikula80f286a2020-02-24 14:08:28 +0200241 ret = intel_modeset_init_noirq(i915);
242 if (ret)
243 goto cleanup_vga_client;
244
Jani Nikulab6642592020-02-19 15:37:56 +0200245 return 0;
246
Jani Nikula80f286a2020-02-24 14:08:28 +0200247cleanup_vga_client:
248 intel_vga_unregister(i915);
Jani Nikulab6642592020-02-19 15:37:56 +0200249out:
250 return ret;
251}
252
253/* part #2: call after irq install */
254static int i915_driver_modeset_probe(struct drm_i915_private *i915)
255{
256 int ret;
Chris Wilson0673ad42016-06-24 14:00:22 +0100257
Chris Wilson0673ad42016-06-24 14:00:22 +0100258 /* Important: The output setup functions called by modeset_init need
259 * working irqs for e.g. gmbus and dp aux transfers. */
Jani Nikula6cd02e72019-09-20 21:54:21 +0300260 ret = intel_modeset_init(i915);
Ville Syrjäläb079bd172016-10-25 18:58:02 +0300261 if (ret)
Jani Nikulab6642592020-02-19 15:37:56 +0200262 goto out;
Chris Wilson0673ad42016-06-24 14:00:22 +0100263
Jani Nikula5bcd53a2019-09-20 21:54:17 +0300264 ret = i915_gem_init(i915);
Chris Wilson0673ad42016-06-24 14:00:22 +0100265 if (ret)
Chris Wilson73bad7c2018-07-10 10:44:21 +0100266 goto cleanup_modeset;
Chris Wilson0673ad42016-06-24 14:00:22 +0100267
Jani Nikula5bcd53a2019-09-20 21:54:17 +0300268 intel_overlay_setup(i915);
Chris Wilson0673ad42016-06-24 14:00:22 +0100269
Jani Nikula5bcd53a2019-09-20 21:54:17 +0300270 if (!HAS_DISPLAY(i915) || !INTEL_DISPLAY_ENABLED(i915))
Chris Wilson0673ad42016-06-24 14:00:22 +0100271 return 0;
272
Jani Nikula5bcd53a2019-09-20 21:54:17 +0300273 ret = intel_fbdev_init(&i915->drm);
Chris Wilson0673ad42016-06-24 14:00:22 +0100274 if (ret)
275 goto cleanup_gem;
276
277 /* Only enable hotplug handling once the fbdev is fully set up. */
Jani Nikula5bcd53a2019-09-20 21:54:17 +0300278 intel_hpd_init(i915);
Chris Wilson0673ad42016-06-24 14:00:22 +0100279
Jani Nikula5bcd53a2019-09-20 21:54:17 +0300280 intel_init_ipc(i915);
José Roberto de Souzaa8147d02018-11-07 16:16:46 -0800281
José Roberto de Souzadf1a5bf2020-02-21 13:26:35 -0800282 intel_psr_set_force_mode_changed(i915->psr.dp);
283
Chris Wilson0673ad42016-06-24 14:00:22 +0100284 return 0;
285
286cleanup_gem:
Jani Nikula5bcd53a2019-09-20 21:54:17 +0300287 i915_gem_suspend(i915);
288 i915_gem_driver_remove(i915);
289 i915_gem_driver_release(i915);
Chris Wilson73bad7c2018-07-10 10:44:21 +0100290cleanup_modeset:
Jani Nikulab6642592020-02-19 15:37:56 +0200291 /* FIXME */
Jani Nikula9980c3c2019-09-20 21:54:18 +0300292 intel_modeset_driver_remove(i915);
Jani Nikula93a0ed62020-02-14 15:50:57 +0200293 intel_irq_uninstall(i915);
294 intel_modeset_driver_remove_noirq(i915);
Chris Wilson0673ad42016-06-24 14:00:22 +0100295out:
296 return ret;
297}
298
Jani Nikulaf20a60f2020-02-14 15:50:58 +0200299/* part #1: call before irq uninstall */
Jani Nikula2d6f6f32019-09-20 21:54:16 +0300300static void i915_driver_modeset_remove(struct drm_i915_private *i915)
301{
Jani Nikula9980c3c2019-09-20 21:54:18 +0300302 intel_modeset_driver_remove(i915);
Jani Nikulaf20a60f2020-02-14 15:50:58 +0200303}
Jani Nikula2d6f6f32019-09-20 21:54:16 +0300304
Jani Nikulaf20a60f2020-02-14 15:50:58 +0200305/* part #2: call after irq uninstall */
306static void i915_driver_modeset_remove_noirq(struct drm_i915_private *i915)
307{
Jani Nikula93a0ed62020-02-14 15:50:57 +0200308 intel_modeset_driver_remove_noirq(i915);
309
Jani Nikula2d6f6f32019-09-20 21:54:16 +0300310 intel_bios_driver_remove(i915);
311
Jani Nikula4fb87832019-10-01 18:25:06 +0300312 intel_vga_unregister(i915);
Jani Nikula2d6f6f32019-09-20 21:54:16 +0300313
314 intel_csr_ucode_fini(i915);
315}
316
Chris Wilson0673ad42016-06-24 14:00:22 +0100317static void intel_init_dpio(struct drm_i915_private *dev_priv)
318{
319 /*
320 * IOSF_PORT_DPIO is used for VLV x2 PHY (DP/HDMI B and C),
321 * CHV x1 PHY (DP/HDMI D)
322 * IOSF_PORT_DPIO_2 is used for CHV x2 PHY (DP/HDMI B and C)
323 */
324 if (IS_CHERRYVIEW(dev_priv)) {
325 DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO_2;
326 DPIO_PHY_IOSF_PORT(DPIO_PHY1) = IOSF_PORT_DPIO;
327 } else if (IS_VALLEYVIEW(dev_priv)) {
328 DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO;
329 }
330}
331
332static int i915_workqueues_init(struct drm_i915_private *dev_priv)
333{
334 /*
335 * The i915 workqueue is primarily used for batched retirement of
336 * requests (and thus managing bo) once the task has been completed
Chris Wilsone61e0f52018-02-21 09:56:36 +0000337 * by the GPU. i915_retire_requests() is called directly when we
Chris Wilson0673ad42016-06-24 14:00:22 +0100338 * need high-priority retirement, such as waiting for an explicit
339 * bo.
340 *
341 * It is also used for periodic low-priority events, such as
342 * idle-timers and recording error state.
343 *
344 * All tasks on the workqueue are expected to acquire the dev mutex
345 * so there is no point in running more than one instance of the
346 * workqueue at any time. Use an ordered one.
347 */
348 dev_priv->wq = alloc_ordered_workqueue("i915", 0);
349 if (dev_priv->wq == NULL)
350 goto out_err;
351
352 dev_priv->hotplug.dp_wq = alloc_ordered_workqueue("i915-dp", 0);
353 if (dev_priv->hotplug.dp_wq == NULL)
354 goto out_free_wq;
355
Chris Wilson0673ad42016-06-24 14:00:22 +0100356 return 0;
357
Chris Wilson0673ad42016-06-24 14:00:22 +0100358out_free_wq:
359 destroy_workqueue(dev_priv->wq);
360out_err:
Wambui Karuga00376cc2020-01-31 12:34:12 +0300361 drm_err(&dev_priv->drm, "Failed to allocate workqueues.\n");
Chris Wilson0673ad42016-06-24 14:00:22 +0100362
363 return -ENOMEM;
364}
365
366static void i915_workqueues_cleanup(struct drm_i915_private *dev_priv)
367{
Chris Wilson0673ad42016-06-24 14:00:22 +0100368 destroy_workqueue(dev_priv->hotplug.dp_wq);
369 destroy_workqueue(dev_priv->wq);
370}
371
Paulo Zanoni4fc7e842016-09-26 15:07:52 +0300372/*
373 * We don't keep the workarounds for pre-production hardware, so we expect our
374 * driver to fail on these machines in one way or another. A little warning on
375 * dmesg may help both the user and the bug triagers.
Chris Wilson6a7a6a92017-11-17 10:26:35 +0000376 *
377 * Our policy for removing pre-production workarounds is to keep the
378 * current gen workarounds as a guide to the bring-up of the next gen
379 * (workarounds have a habit of persisting!). Anything older than that
380 * should be removed along with the complications they introduce.
Paulo Zanoni4fc7e842016-09-26 15:07:52 +0300381 */
382static void intel_detect_preproduction_hw(struct drm_i915_private *dev_priv)
383{
Chris Wilson248a1242017-01-30 10:44:56 +0000384 bool pre = false;
385
386 pre |= IS_HSW_EARLY_SDV(dev_priv);
387 pre |= IS_SKL_REVID(dev_priv, 0, SKL_REVID_F0);
Chris Wilson0102ba12017-01-30 10:44:58 +0000388 pre |= IS_BXT_REVID(dev_priv, 0, BXT_REVID_B_LAST);
Chris Wilson1aca96c2018-11-28 13:53:25 +0000389 pre |= IS_KBL_REVID(dev_priv, 0, KBL_REVID_A0);
Chris Wilson248a1242017-01-30 10:44:56 +0000390
Chris Wilson7c5ff4a2017-01-30 10:44:57 +0000391 if (pre) {
Wambui Karuga00376cc2020-01-31 12:34:12 +0300392 drm_err(&dev_priv->drm, "This is a pre-production stepping. "
Paulo Zanoni4fc7e842016-09-26 15:07:52 +0300393 "It may not be fully functional.\n");
Chris Wilson7c5ff4a2017-01-30 10:44:57 +0000394 add_taint(TAINT_MACHINE_CHECK, LOCKDEP_STILL_OK);
395 }
Paulo Zanoni4fc7e842016-09-26 15:07:52 +0300396}
397
Chris Wilson640b50f2019-12-28 11:12:55 +0000398static void sanitize_gpu(struct drm_i915_private *i915)
399{
400 if (!INTEL_INFO(i915)->gpu_reset_clobbers_display)
401 __intel_gt_reset(&i915->gt, ALL_ENGINES);
402}
403
Chris Wilson0673ad42016-06-24 14:00:22 +0100404/**
Janusz Krzysztofik0b61b8b2019-07-12 13:24:30 +0200405 * i915_driver_early_probe - setup state not requiring device access
Chris Wilson0673ad42016-06-24 14:00:22 +0100406 * @dev_priv: device private
407 *
408 * Initialize everything that is a "SW-only" state, that is state not
409 * requiring accessing the device or exposing the driver via kernel internal
410 * or userspace interfaces. Example steps belonging here: lock initialization,
411 * system memory allocation, setting up device specific attributes and
412 * function hooks not requiring accessing the device.
413 */
Janusz Krzysztofik0b61b8b2019-07-12 13:24:30 +0200414static int i915_driver_early_probe(struct drm_i915_private *dev_priv)
Chris Wilson0673ad42016-06-24 14:00:22 +0100415{
Chris Wilson0673ad42016-06-24 14:00:22 +0100416 int ret = 0;
417
Michal Wajdeczko50d84412019-08-02 18:40:50 +0000418 if (i915_inject_probe_failure(dev_priv))
Chris Wilson0673ad42016-06-24 14:00:22 +0100419 return -ENODEV;
420
Tvrtko Ursulin805446c2019-03-27 14:23:28 +0000421 intel_device_info_subplatform_init(dev_priv);
422
Daniele Ceraolo Spurio0a9b2632019-08-09 07:31:16 +0100423 intel_uncore_mmio_debug_init_early(&dev_priv->mmio_debug);
Daniele Ceraolo Spurio01385752019-06-19 18:00:18 -0700424 intel_uncore_init_early(&dev_priv->uncore, dev_priv);
Daniele Ceraolo Spurio6cbe88302019-04-02 13:10:31 -0700425
Chris Wilson0673ad42016-06-24 14:00:22 +0100426 spin_lock_init(&dev_priv->irq_lock);
427 spin_lock_init(&dev_priv->gpu_error.lock);
428 mutex_init(&dev_priv->backlight_lock);
Lyude317eaa92017-02-03 21:18:25 -0500429
Chris Wilson0673ad42016-06-24 14:00:22 +0100430 mutex_init(&dev_priv->sb_lock);
Chris Wilsona75d0352019-04-26 09:17:18 +0100431 pm_qos_add_request(&dev_priv->sb_qos,
432 PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);
433
Chris Wilson0673ad42016-06-24 14:00:22 +0100434 mutex_init(&dev_priv->av_mutex);
435 mutex_init(&dev_priv->wm.wm_mutex);
436 mutex_init(&dev_priv->pps_mutex);
Ramalingam C9055aac2019-02-16 23:06:51 +0530437 mutex_init(&dev_priv->hdcp_comp_mutex);
Chris Wilson0673ad42016-06-24 14:00:22 +0100438
Chris Wilson0b1de5d2016-08-12 12:39:59 +0100439 i915_memcpy_init_early(dev_priv);
Daniele Ceraolo Spurio69c66352019-06-13 16:21:53 -0700440 intel_runtime_pm_init_early(&dev_priv->runtime_pm);
Chris Wilson0b1de5d2016-08-12 12:39:59 +0100441
Chris Wilson0673ad42016-06-24 14:00:22 +0100442 ret = i915_workqueues_init(dev_priv);
443 if (ret < 0)
Chris Wilsonf3bcb0c2019-07-18 08:00:10 +0100444 return ret;
Chris Wilson0673ad42016-06-24 14:00:22 +0100445
Jani Nikulafb5f4322020-02-12 16:40:57 +0200446 ret = vlv_suspend_init(dev_priv);
Daniele Ceraolo Spurio1bcd8682019-08-19 19:01:46 -0700447 if (ret < 0)
448 goto err_workqueues;
449
Daniele Ceraolo Spurio6f760982019-07-31 17:57:08 -0700450 intel_wopcm_init_early(&dev_priv->wopcm);
451
Tvrtko Ursulin724e9562019-06-21 08:07:42 +0100452 intel_gt_init_early(&dev_priv->gt, dev_priv);
Tvrtko Ursulin24635c52019-06-21 08:07:41 +0100453
Matthew Aulda3f356b2019-09-27 18:33:49 +0100454 i915_gem_init_early(dev_priv);
Michal Wajdeczkoa0de9082018-03-23 12:34:49 +0000455
Chris Wilson0673ad42016-06-24 14:00:22 +0100456 /* This must be called before any calls to HAS_PCH_* */
Tvrtko Ursulinda5f53b2016-12-01 14:16:40 +0000457 intel_detect_pch(dev_priv);
Chris Wilson0673ad42016-06-24 14:00:22 +0100458
Tvrtko Ursulin192aa182016-12-01 14:16:45 +0000459 intel_pm_setup(dev_priv);
Chris Wilson0673ad42016-06-24 14:00:22 +0100460 intel_init_dpio(dev_priv);
Imre Deakf28ec6f2018-08-06 12:58:37 +0300461 ret = intel_power_domains_init(dev_priv);
462 if (ret < 0)
Daniele Ceraolo Spurio6f760982019-07-31 17:57:08 -0700463 goto err_gem;
Chris Wilson0673ad42016-06-24 14:00:22 +0100464 intel_irq_init(dev_priv);
465 intel_init_display_hooks(dev_priv);
466 intel_init_clock_gating_hooks(dev_priv);
467 intel_init_audio_hooks(dev_priv);
David Weinehall36cdd012016-08-22 13:59:31 +0300468 intel_display_crc_init(dev_priv);
Chris Wilson0673ad42016-06-24 14:00:22 +0100469
Paulo Zanoni4fc7e842016-09-26 15:07:52 +0300470 intel_detect_preproduction_hw(dev_priv);
Chris Wilson0673ad42016-06-24 14:00:22 +0100471
472 return 0;
473
Daniele Ceraolo Spurio6f760982019-07-31 17:57:08 -0700474err_gem:
Imre Deakf28ec6f2018-08-06 12:58:37 +0300475 i915_gem_cleanup_early(dev_priv);
Daniele Ceraolo Spurio6cf72db2019-07-31 17:57:07 -0700476 intel_gt_driver_late_release(&dev_priv->gt);
Jani Nikulafb5f4322020-02-12 16:40:57 +0200477 vlv_suspend_cleanup(dev_priv);
Daniele Ceraolo Spurio1bcd8682019-08-19 19:01:46 -0700478err_workqueues:
Chris Wilson0673ad42016-06-24 14:00:22 +0100479 i915_workqueues_cleanup(dev_priv);
480 return ret;
481}
482
483/**
Janusz Krzysztofik3b58a942019-07-12 13:24:28 +0200484 * i915_driver_late_release - cleanup the setup done in
Janusz Krzysztofik0b61b8b2019-07-12 13:24:30 +0200485 * i915_driver_early_probe()
Chris Wilson0673ad42016-06-24 14:00:22 +0100486 * @dev_priv: device private
487 */
Janusz Krzysztofik3b58a942019-07-12 13:24:28 +0200488static void i915_driver_late_release(struct drm_i915_private *dev_priv)
Chris Wilson0673ad42016-06-24 14:00:22 +0100489{
Joonas Lahtinencefcff82017-04-28 10:58:39 +0300490 intel_irq_fini(dev_priv);
Imre Deakf28ec6f2018-08-06 12:58:37 +0300491 intel_power_domains_cleanup(dev_priv);
Michal Wajdeczkoa0de9082018-03-23 12:34:49 +0000492 i915_gem_cleanup_early(dev_priv);
Daniele Ceraolo Spurio6cf72db2019-07-31 17:57:07 -0700493 intel_gt_driver_late_release(&dev_priv->gt);
Jani Nikulafb5f4322020-02-12 16:40:57 +0200494 vlv_suspend_cleanup(dev_priv);
Chris Wilson0673ad42016-06-24 14:00:22 +0100495 i915_workqueues_cleanup(dev_priv);
Chris Wilsona75d0352019-04-26 09:17:18 +0100496
497 pm_qos_remove_request(&dev_priv->sb_qos);
498 mutex_destroy(&dev_priv->sb_lock);
Chris Wilson0673ad42016-06-24 14:00:22 +0100499}
500
Chris Wilson0673ad42016-06-24 14:00:22 +0100501/**
Janusz Krzysztofik0b61b8b2019-07-12 13:24:30 +0200502 * i915_driver_mmio_probe - setup device MMIO
Chris Wilson0673ad42016-06-24 14:00:22 +0100503 * @dev_priv: device private
504 *
505 * Setup minimal device state necessary for MMIO accesses later in the
506 * initialization sequence. The setup here should avoid any other device-wide
507 * side effects or exposing the driver via kernel internal or user space
508 * interfaces.
509 */
Janusz Krzysztofik0b61b8b2019-07-12 13:24:30 +0200510static int i915_driver_mmio_probe(struct drm_i915_private *dev_priv)
Chris Wilson0673ad42016-06-24 14:00:22 +0100511{
Chris Wilson0673ad42016-06-24 14:00:22 +0100512 int ret;
513
Michal Wajdeczko50d84412019-08-02 18:40:50 +0000514 if (i915_inject_probe_failure(dev_priv))
Chris Wilson0673ad42016-06-24 14:00:22 +0100515 return -ENODEV;
516
Tvrtko Ursulinda5f53b2016-12-01 14:16:40 +0000517 if (i915_get_bridge_dev(dev_priv))
Chris Wilson0673ad42016-06-24 14:00:22 +0100518 return -EIO;
519
Daniele Ceraolo Spurio3de6f852019-04-02 13:10:32 -0700520 ret = intel_uncore_init_mmio(&dev_priv->uncore);
Chris Wilson0673ad42016-06-24 14:00:22 +0100521 if (ret < 0)
Joonas Lahtinen63ffbcd2017-04-28 10:53:36 +0300522 goto err_bridge;
Chris Wilson0673ad42016-06-24 14:00:22 +0100523
Daniele Ceraolo Spurio25286aa2019-03-19 11:35:40 -0700524 /* Try to make sure MCHBAR is enabled before poking at it */
525 intel_setup_mchbar(dev_priv);
Joonas Lahtinen63ffbcd2017-04-28 10:53:36 +0300526
Oscar Mateo26376a72018-03-16 14:14:49 +0200527 intel_device_info_init_mmio(dev_priv);
528
Daniele Ceraolo Spurio3de6f852019-04-02 13:10:32 -0700529 intel_uncore_prune_mmio_domains(&dev_priv->uncore);
Oscar Mateo26376a72018-03-16 14:14:49 +0200530
Daniele Ceraolo Spurioca7b2c12019-07-13 11:00:13 +0100531 intel_uc_init_mmio(&dev_priv->gt.uc);
Sagar Arun Kamble1fc556f2017-10-04 15:33:24 +0000532
Tvrtko Ursulinadcb5262019-10-22 10:47:15 +0100533 ret = intel_engines_init_mmio(&dev_priv->gt);
Joonas Lahtinen63ffbcd2017-04-28 10:53:36 +0300534 if (ret)
535 goto err_uncore;
536
Chris Wilson640b50f2019-12-28 11:12:55 +0000537 /* As early as possible, scrub existing GPU state before clobbering */
538 sanitize_gpu(dev_priv);
539
Chris Wilson0673ad42016-06-24 14:00:22 +0100540 return 0;
541
Joonas Lahtinen63ffbcd2017-04-28 10:53:36 +0300542err_uncore:
Daniele Ceraolo Spurio25286aa2019-03-19 11:35:40 -0700543 intel_teardown_mchbar(dev_priv);
Daniele Ceraolo Spurio3de6f852019-04-02 13:10:32 -0700544 intel_uncore_fini_mmio(&dev_priv->uncore);
Joonas Lahtinen63ffbcd2017-04-28 10:53:36 +0300545err_bridge:
Chris Wilson0673ad42016-06-24 14:00:22 +0100546 pci_dev_put(dev_priv->bridge_dev);
547
548 return ret;
549}
550
551/**
Janusz Krzysztofik0b61b8b2019-07-12 13:24:30 +0200552 * i915_driver_mmio_release - cleanup the setup done in i915_driver_mmio_probe()
Chris Wilson0673ad42016-06-24 14:00:22 +0100553 * @dev_priv: device private
554 */
Janusz Krzysztofik3b58a942019-07-12 13:24:28 +0200555static void i915_driver_mmio_release(struct drm_i915_private *dev_priv)
Chris Wilson0673ad42016-06-24 14:00:22 +0100556{
Daniele Ceraolo Spurio25286aa2019-03-19 11:35:40 -0700557 intel_teardown_mchbar(dev_priv);
Daniele Ceraolo Spurio3de6f852019-04-02 13:10:32 -0700558 intel_uncore_fini_mmio(&dev_priv->uncore);
Chris Wilson0673ad42016-06-24 14:00:22 +0100559 pci_dev_put(dev_priv->bridge_dev);
560}
561
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100562static void intel_sanitize_options(struct drm_i915_private *dev_priv)
563{
Chuanxiao Dong67b7f332017-05-27 17:44:17 +0800564 intel_gvt_sanitize_options(dev_priv);
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100565}
566
Chris Wilson0673ad42016-06-24 14:00:22 +0100567/**
Janusz Krzysztofik0b61b8b2019-07-12 13:24:30 +0200568 * i915_driver_hw_probe - setup state requiring device access
Chris Wilson0673ad42016-06-24 14:00:22 +0100569 * @dev_priv: device private
570 *
571 * Setup state that requires accessing the device, but doesn't require
572 * exposing the driver via kernel internal or userspace interfaces.
573 */
Janusz Krzysztofik0b61b8b2019-07-12 13:24:30 +0200574static int i915_driver_hw_probe(struct drm_i915_private *dev_priv)
Chris Wilson0673ad42016-06-24 14:00:22 +0100575{
David Weinehall52a05c32016-08-22 13:32:44 +0300576 struct pci_dev *pdev = dev_priv->drm.pdev;
Chris Wilson0673ad42016-06-24 14:00:22 +0100577 int ret;
578
Michal Wajdeczko50d84412019-08-02 18:40:50 +0000579 if (i915_inject_probe_failure(dev_priv))
Chris Wilson0673ad42016-06-24 14:00:22 +0100580 return -ENODEV;
581
Jani Nikula1400cc72018-12-31 16:56:43 +0200582 intel_device_info_runtime_init(dev_priv);
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100583
Chris Wilson4bdafb92018-09-26 21:12:22 +0100584 if (HAS_PPGTT(dev_priv)) {
585 if (intel_vgpu_active(dev_priv) &&
Chris Wilsonca6ac682019-03-14 22:38:35 +0000586 !intel_vgpu_has_full_ppgtt(dev_priv)) {
Chris Wilson4bdafb92018-09-26 21:12:22 +0100587 i915_report_error(dev_priv,
588 "incompatible vGPU found, support for isolated ppGTT required\n");
589 return -ENXIO;
590 }
591 }
592
Chris Wilson46592892018-11-30 12:59:54 +0000593 if (HAS_EXECLISTS(dev_priv)) {
594 /*
595 * Older GVT emulation depends upon intercepting CSB mmio,
596 * which we no longer use, preferring to use the HWSP cache
597 * instead.
598 */
599 if (intel_vgpu_active(dev_priv) &&
600 !intel_vgpu_has_hwsp_emulation(dev_priv)) {
601 i915_report_error(dev_priv,
602 "old vGPU host found, support for HWSP emulation required\n");
603 return -ENXIO;
604 }
605 }
606
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100607 intel_sanitize_options(dev_priv);
Chris Wilson0673ad42016-06-24 14:00:22 +0100608
Daniele Ceraolo Spuriof6ac9932019-03-28 10:45:32 -0700609 /* needs to be done before ggtt probe */
Jani Nikulad28ae3b2020-02-25 13:15:07 +0200610 intel_dram_edram_detect(dev_priv);
Daniele Ceraolo Spuriof6ac9932019-03-28 10:45:32 -0700611
Lionel Landwerlin9f9b2792017-10-27 15:59:31 +0100612 i915_perf_init(dev_priv);
613
Chris Wilson97d6d7a2016-08-04 07:52:22 +0100614 ret = i915_ggtt_probe_hw(dev_priv);
Chris Wilson0673ad42016-06-24 14:00:22 +0100615 if (ret)
Chris Wilson9f172f62018-04-14 10:12:33 +0100616 goto err_perf;
Chris Wilson0673ad42016-06-24 14:00:22 +0100617
Gerd Hoffmannf2521f72019-08-22 11:06:45 +0200618 ret = drm_fb_helper_remove_conflicting_pci_framebuffers(pdev, "inteldrmfb");
619 if (ret)
Chris Wilson9f172f62018-04-14 10:12:33 +0100620 goto err_ggtt;
Chris Wilson0673ad42016-06-24 14:00:22 +0100621
Chris Wilson97d6d7a2016-08-04 07:52:22 +0100622 ret = i915_ggtt_init_hw(dev_priv);
Chris Wilson0088e522016-08-04 07:52:21 +0100623 if (ret)
Chris Wilson9f172f62018-04-14 10:12:33 +0100624 goto err_ggtt;
Chris Wilson0088e522016-08-04 07:52:21 +0100625
Chris Wilson3fc794f2019-10-26 21:20:32 +0100626 ret = intel_memory_regions_hw_probe(dev_priv);
627 if (ret)
628 goto err_ggtt;
629
Chris Wilson797a6152019-11-01 14:10:06 +0000630 intel_gt_init_hw_early(&dev_priv->gt, &dev_priv->ggtt);
Tvrtko Ursulind8a44242019-06-21 08:08:06 +0100631
Chris Wilson97d6d7a2016-08-04 07:52:22 +0100632 ret = i915_ggtt_enable_hw(dev_priv);
Chris Wilson0088e522016-08-04 07:52:21 +0100633 if (ret) {
Wambui Karuga00376cc2020-01-31 12:34:12 +0300634 drm_err(&dev_priv->drm, "failed to enable GGTT\n");
Chris Wilson3fc794f2019-10-26 21:20:32 +0100635 goto err_mem_regions;
Chris Wilson0088e522016-08-04 07:52:21 +0100636 }
637
David Weinehall52a05c32016-08-22 13:32:44 +0300638 pci_set_master(pdev);
Chris Wilson0673ad42016-06-24 14:00:22 +0100639
Lyude Paulacd674a2019-08-23 16:52:51 -0400640 /*
641 * We don't have a max segment size, so set it to the max so sg's
642 * debugging layer doesn't complain
643 */
644 dma_set_max_seg_size(&pdev->dev, UINT_MAX);
645
Chris Wilson0673ad42016-06-24 14:00:22 +0100646 /* overlay on gen2 is broken and can't address above 1G */
Lucas De Marchicf819ef2018-12-12 10:10:43 -0800647 if (IS_GEN(dev_priv, 2)) {
David Weinehall52a05c32016-08-22 13:32:44 +0300648 ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(30));
Chris Wilson0673ad42016-06-24 14:00:22 +0100649 if (ret) {
Wambui Karuga00376cc2020-01-31 12:34:12 +0300650 drm_err(&dev_priv->drm, "failed to set DMA mask\n");
Chris Wilson0673ad42016-06-24 14:00:22 +0100651
Chris Wilson3fc794f2019-10-26 21:20:32 +0100652 goto err_mem_regions;
Chris Wilson0673ad42016-06-24 14:00:22 +0100653 }
654 }
655
Chris Wilson0673ad42016-06-24 14:00:22 +0100656 /* 965GM sometimes incorrectly writes to hardware status page (HWS)
657 * using 32bit addressing, overwriting memory if HWS is located
658 * above 4GB.
659 *
660 * The documentation also mentions an issue with undefined
661 * behaviour if any general state is accessed within a page above 4GB,
662 * which also needs to be handled carefully.
663 */
Jani Nikulac0f86832016-12-07 12:13:04 +0200664 if (IS_I965G(dev_priv) || IS_I965GM(dev_priv)) {
David Weinehall52a05c32016-08-22 13:32:44 +0300665 ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
Chris Wilson0673ad42016-06-24 14:00:22 +0100666
667 if (ret) {
Wambui Karuga00376cc2020-01-31 12:34:12 +0300668 drm_err(&dev_priv->drm, "failed to set DMA mask\n");
Chris Wilson0673ad42016-06-24 14:00:22 +0100669
Chris Wilson3fc794f2019-10-26 21:20:32 +0100670 goto err_mem_regions;
Chris Wilson0673ad42016-06-24 14:00:22 +0100671 }
672 }
673
Chris Wilson0673ad42016-06-24 14:00:22 +0100674 pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY,
675 PM_QOS_DEFAULT_VALUE);
676
Tvrtko Ursulin25d140f2018-12-03 13:33:19 +0000677 intel_gt_init_workarounds(dev_priv);
Chris Wilson0673ad42016-06-24 14:00:22 +0100678
679 /* On the 945G/GM, the chipset reports the MSI capability on the
680 * integrated graphics even though the support isn't actually there
681 * according to the published specs. It doesn't appear to function
682 * correctly in testing on 945G.
683 * This may be a side effect of MSI having been made available for PEG
684 * and the registers being closely associated.
685 *
686 * According to chipset errata, on the 965GM, MSI interrupts may
Ville Syrjäläe38c2da2017-06-26 23:30:51 +0300687 * be lost or delayed, and was defeatured. MSI interrupts seem to
688 * get lost on g4x as well, and interrupt delivery seems to stay
689 * properly dead afterwards. So we'll just disable them for all
690 * pre-gen5 chipsets.
Lucas De Marchi8a29c772018-05-23 11:04:35 -0700691 *
692 * dp aux and gmbus irq on gen4 seems to be able to generate legacy
693 * interrupts even when in MSI mode. This results in spurious
694 * interrupt warnings if the legacy irq no. is shared with another
695 * device. The kernel then disables that interrupt source and so
696 * prevents the other device from working properly.
Chris Wilson0673ad42016-06-24 14:00:22 +0100697 */
Ville Syrjäläe38c2da2017-06-26 23:30:51 +0300698 if (INTEL_GEN(dev_priv) >= 5) {
David Weinehall52a05c32016-08-22 13:32:44 +0300699 if (pci_enable_msi(pdev) < 0)
Wambui Karuga00376cc2020-01-31 12:34:12 +0300700 drm_dbg(&dev_priv->drm, "can't enable MSI");
Chris Wilson0673ad42016-06-24 14:00:22 +0100701 }
702
Zhenyu Wang26f837e2017-01-13 10:46:09 +0800703 ret = intel_gvt_init(dev_priv);
704 if (ret)
Chris Wilson7ab87ed2018-07-10 15:38:21 +0100705 goto err_msi;
706
707 intel_opregion_setup(dev_priv);
Mahesh Kumarcbfa59d2018-08-24 15:02:21 +0530708 /*
709 * Fill the dram structure to get the system raw bandwidth and
710 * dram info. This will be used for memory latency calculation.
711 */
Jani Nikulad28ae3b2020-02-25 13:15:07 +0200712 intel_dram_detect(dev_priv);
Mahesh Kumarcbfa59d2018-08-24 15:02:21 +0530713
Ville Syrjäläc457d9c2019-05-24 18:36:14 +0300714 intel_bw_init_hw(dev_priv);
Zhenyu Wang26f837e2017-01-13 10:46:09 +0800715
Chris Wilson0673ad42016-06-24 14:00:22 +0100716 return 0;
717
Chris Wilson7ab87ed2018-07-10 15:38:21 +0100718err_msi:
719 if (pdev->msi_enabled)
720 pci_disable_msi(pdev);
721 pm_qos_remove_request(&dev_priv->pm_qos);
Chris Wilson3fc794f2019-10-26 21:20:32 +0100722err_mem_regions:
723 intel_memory_regions_driver_release(dev_priv);
Chris Wilson9f172f62018-04-14 10:12:33 +0100724err_ggtt:
Janusz Krzysztofik3b58a942019-07-12 13:24:28 +0200725 i915_ggtt_driver_release(dev_priv);
Chris Wilson9f172f62018-04-14 10:12:33 +0100726err_perf:
727 i915_perf_fini(dev_priv);
Chris Wilson0673ad42016-06-24 14:00:22 +0100728 return ret;
729}
730
731/**
Janusz Krzysztofik78dae1a2019-07-12 13:24:29 +0200732 * i915_driver_hw_remove - cleanup the setup done in i915_driver_hw_probe()
Chris Wilson0673ad42016-06-24 14:00:22 +0100733 * @dev_priv: device private
734 */
Janusz Krzysztofik78dae1a2019-07-12 13:24:29 +0200735static void i915_driver_hw_remove(struct drm_i915_private *dev_priv)
Chris Wilson0673ad42016-06-24 14:00:22 +0100736{
David Weinehall52a05c32016-08-22 13:32:44 +0300737 struct pci_dev *pdev = dev_priv->drm.pdev;
Chris Wilson0673ad42016-06-24 14:00:22 +0100738
Lionel Landwerlin9f9b2792017-10-27 15:59:31 +0100739 i915_perf_fini(dev_priv);
740
David Weinehall52a05c32016-08-22 13:32:44 +0300741 if (pdev->msi_enabled)
742 pci_disable_msi(pdev);
Chris Wilson0673ad42016-06-24 14:00:22 +0100743
744 pm_qos_remove_request(&dev_priv->pm_qos);
Chris Wilson0673ad42016-06-24 14:00:22 +0100745}
746
747/**
748 * i915_driver_register - register the driver with the rest of the system
749 * @dev_priv: device private
750 *
751 * Perform any steps necessary to make the driver available via kernel
752 * internal or userspace interfaces.
753 */
754static void i915_driver_register(struct drm_i915_private *dev_priv)
755{
Chris Wilson91c8a322016-07-05 10:40:23 +0100756 struct drm_device *dev = &dev_priv->drm;
Chris Wilson0673ad42016-06-24 14:00:22 +0100757
Chris Wilsonc29579d2019-08-06 13:42:59 +0100758 i915_gem_driver_register(dev_priv);
Tvrtko Ursulinb46a33e2017-11-21 18:18:45 +0000759 i915_pmu_register(dev_priv);
Chris Wilson0673ad42016-06-24 14:00:22 +0100760
761 /*
762 * Notify a valid surface after modesetting,
763 * when running inside a VM.
764 */
765 if (intel_vgpu_active(dev_priv))
766 I915_WRITE(vgtif_reg(display_ready), VGT_DRV_DISPLAY_READY);
767
768 /* Reveal our presence to userspace */
769 if (drm_dev_register(dev, 0) == 0) {
770 i915_debugfs_register(dev_priv);
Jani Nikula926b0052020-02-11 18:14:51 +0200771 intel_display_debugfs_register(dev_priv);
David Weinehall694c2822016-08-22 13:32:43 +0300772 i915_setup_sysfs(dev_priv);
Robert Bragg442b8c02016-11-07 19:49:53 +0000773
774 /* Depends on sysfs having been initialized */
775 i915_perf_register(dev_priv);
Chris Wilson0673ad42016-06-24 14:00:22 +0100776 } else
Wambui Karuga00376cc2020-01-31 12:34:12 +0300777 drm_err(&dev_priv->drm,
778 "Failed to register driver for userspace access!\n");
Chris Wilson0673ad42016-06-24 14:00:22 +0100779
Jani Nikulaa2b69ea2019-09-13 13:04:07 +0300780 if (HAS_DISPLAY(dev_priv) && INTEL_DISPLAY_ENABLED(dev_priv)) {
Chris Wilson0673ad42016-06-24 14:00:22 +0100781 /* Must be done after probing outputs */
782 intel_opregion_register(dev_priv);
783 acpi_video_register();
784 }
785
Andi Shyti42014f62019-09-05 14:14:03 +0300786 intel_gt_driver_register(&dev_priv->gt);
Chris Wilson0673ad42016-06-24 14:00:22 +0100787
Jerome Anandeef57322017-01-25 04:27:49 +0530788 intel_audio_init(dev_priv);
Chris Wilson0673ad42016-06-24 14:00:22 +0100789
790 /*
791 * Some ports require correctly set-up hpd registers for detection to
792 * work properly (leading to ghost connected connector status), e.g. VGA
793 * on gm45. Hence we can only set up the initial fbdev config after hpd
794 * irqs are fully enabled. We do it last so that the async config
795 * cannot run before the connectors are registered.
796 */
797 intel_fbdev_initial_config_async(dev);
Chris Wilson448aa912017-11-28 11:01:47 +0000798
799 /*
800 * We need to coordinate the hotplugs with the asynchronous fbdev
801 * configuration, for which we use the fbdev->async_cookie.
802 */
Jani Nikulaa2b69ea2019-09-13 13:04:07 +0300803 if (HAS_DISPLAY(dev_priv) && INTEL_DISPLAY_ENABLED(dev_priv))
Chris Wilson448aa912017-11-28 11:01:47 +0000804 drm_kms_helper_poll_init(dev);
Chris Wilson07d80572018-08-16 15:37:56 +0300805
Imre Deak2cd9a682018-08-16 15:37:57 +0300806 intel_power_domains_enable(dev_priv);
Daniele Ceraolo Spurio69c66352019-06-13 16:21:53 -0700807 intel_runtime_pm_enable(&dev_priv->runtime_pm);
Jani Nikula46edcdb2020-02-11 18:28:01 +0200808
809 intel_register_dsm_handler();
810
811 if (i915_switcheroo_register(dev_priv))
812 drm_err(&dev_priv->drm, "Failed to register vga switcheroo!\n");
Chris Wilson0673ad42016-06-24 14:00:22 +0100813}
814
815/**
816 * i915_driver_unregister - cleanup the registration done in i915_driver_regiser()
817 * @dev_priv: device private
818 */
819static void i915_driver_unregister(struct drm_i915_private *dev_priv)
820{
Jani Nikula46edcdb2020-02-11 18:28:01 +0200821 i915_switcheroo_unregister(dev_priv);
822
823 intel_unregister_dsm_handler();
824
Daniele Ceraolo Spurio69c66352019-06-13 16:21:53 -0700825 intel_runtime_pm_disable(&dev_priv->runtime_pm);
Imre Deak2cd9a682018-08-16 15:37:57 +0300826 intel_power_domains_disable(dev_priv);
Chris Wilson07d80572018-08-16 15:37:56 +0300827
Daniel Vetter4f256d82017-07-15 00:46:55 +0200828 intel_fbdev_unregister(dev_priv);
Jerome Anandeef57322017-01-25 04:27:49 +0530829 intel_audio_deinit(dev_priv);
Chris Wilson0673ad42016-06-24 14:00:22 +0100830
Chris Wilson448aa912017-11-28 11:01:47 +0000831 /*
832 * After flushing the fbdev (incl. a late async config which will
833 * have delayed queuing of a hotplug event), then flush the hotplug
834 * events.
835 */
836 drm_kms_helper_poll_fini(&dev_priv->drm);
837
Andi Shyti42014f62019-09-05 14:14:03 +0300838 intel_gt_driver_unregister(&dev_priv->gt);
Chris Wilson0673ad42016-06-24 14:00:22 +0100839 acpi_video_unregister();
840 intel_opregion_unregister(dev_priv);
841
Robert Bragg442b8c02016-11-07 19:49:53 +0000842 i915_perf_unregister(dev_priv);
Tvrtko Ursulinb46a33e2017-11-21 18:18:45 +0000843 i915_pmu_unregister(dev_priv);
Robert Bragg442b8c02016-11-07 19:49:53 +0000844
David Weinehall694c2822016-08-22 13:32:43 +0300845 i915_teardown_sysfs(dev_priv);
Janusz Krzysztofikd69990e2019-04-05 15:02:34 +0200846 drm_dev_unplug(&dev_priv->drm);
Chris Wilson0673ad42016-06-24 14:00:22 +0100847
Chris Wilsonc29579d2019-08-06 13:42:59 +0100848 i915_gem_driver_unregister(dev_priv);
Chris Wilson0673ad42016-06-24 14:00:22 +0100849}
850
Michal Wajdeczko27d558a2017-12-21 21:57:35 +0000851static void i915_welcome_messages(struct drm_i915_private *dev_priv)
852{
Jani Nikulabdbf43d2019-10-28 12:38:15 +0200853 if (drm_debug_enabled(DRM_UT_DRIVER)) {
Michal Wajdeczko27d558a2017-12-21 21:57:35 +0000854 struct drm_printer p = drm_debug_printer("i915 device info:");
855
Tvrtko Ursulin805446c2019-03-27 14:23:28 +0000856 drm_printf(&p, "pciid=0x%04x rev=0x%02x platform=%s (subplatform=0x%x) gen=%i\n",
Jani Nikula1787a982018-12-31 16:56:45 +0200857 INTEL_DEVID(dev_priv),
858 INTEL_REVID(dev_priv),
859 intel_platform_name(INTEL_INFO(dev_priv)->platform),
Tvrtko Ursulin805446c2019-03-27 14:23:28 +0000860 intel_subplatform(RUNTIME_INFO(dev_priv),
861 INTEL_INFO(dev_priv)->platform),
Jani Nikula1787a982018-12-31 16:56:45 +0200862 INTEL_GEN(dev_priv));
863
Chris Wilson72404972019-12-07 18:29:37 +0000864 intel_device_info_print_static(INTEL_INFO(dev_priv), &p);
865 intel_device_info_print_runtime(RUNTIME_INFO(dev_priv), &p);
Michal Wajdeczko27d558a2017-12-21 21:57:35 +0000866 }
867
868 if (IS_ENABLED(CONFIG_DRM_I915_DEBUG))
Wambui Karuga00376cc2020-01-31 12:34:12 +0300869 drm_info(&dev_priv->drm, "DRM_I915_DEBUG enabled\n");
Michal Wajdeczko27d558a2017-12-21 21:57:35 +0000870 if (IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM))
Wambui Karuga00376cc2020-01-31 12:34:12 +0300871 drm_info(&dev_priv->drm, "DRM_I915_DEBUG_GEM enabled\n");
Imre Deak6dfc4a82018-08-16 22:34:14 +0300872 if (IS_ENABLED(CONFIG_DRM_I915_DEBUG_RUNTIME_PM))
Wambui Karuga00376cc2020-01-31 12:34:12 +0300873 drm_info(&dev_priv->drm,
874 "DRM_I915_DEBUG_RUNTIME_PM enabled\n");
Michal Wajdeczko27d558a2017-12-21 21:57:35 +0000875}
876
Chris Wilson55ac5a12018-09-05 15:09:20 +0100877static struct drm_i915_private *
878i915_driver_create(struct pci_dev *pdev, const struct pci_device_id *ent)
879{
880 const struct intel_device_info *match_info =
881 (struct intel_device_info *)ent->driver_data;
882 struct intel_device_info *device_info;
883 struct drm_i915_private *i915;
Andi Shyti2ddcc982018-10-02 12:20:47 +0300884 int err;
Chris Wilson55ac5a12018-09-05 15:09:20 +0100885
886 i915 = kzalloc(sizeof(*i915), GFP_KERNEL);
887 if (!i915)
Andi Shyti2ddcc982018-10-02 12:20:47 +0300888 return ERR_PTR(-ENOMEM);
Chris Wilson55ac5a12018-09-05 15:09:20 +0100889
Andi Shyti2ddcc982018-10-02 12:20:47 +0300890 err = drm_dev_init(&i915->drm, &driver, &pdev->dev);
891 if (err) {
Chris Wilson55ac5a12018-09-05 15:09:20 +0100892 kfree(i915);
Andi Shyti2ddcc982018-10-02 12:20:47 +0300893 return ERR_PTR(err);
Chris Wilson55ac5a12018-09-05 15:09:20 +0100894 }
895
Chris Wilson361f9dc2019-08-06 08:42:19 +0100896 i915->drm.pdev = pdev;
897 pci_set_drvdata(pdev, i915);
Chris Wilson55ac5a12018-09-05 15:09:20 +0100898
899 /* Setup the write-once "constant" device info */
900 device_info = mkwrite_device_info(i915);
901 memcpy(device_info, match_info, sizeof(*device_info));
Jani Nikula02584042018-12-31 16:56:41 +0200902 RUNTIME_INFO(i915)->device_id = pdev->device;
Chris Wilson55ac5a12018-09-05 15:09:20 +0100903
Chris Wilson74f6e182018-09-26 11:47:07 +0100904 BUG_ON(device_info->gen > BITS_PER_TYPE(device_info->gen_mask));
Chris Wilson55ac5a12018-09-05 15:09:20 +0100905
906 return i915;
907}
908
Chris Wilson31962ca2018-09-05 15:09:21 +0100909static void i915_driver_destroy(struct drm_i915_private *i915)
910{
911 struct pci_dev *pdev = i915->drm.pdev;
912
913 drm_dev_fini(&i915->drm);
914 kfree(i915);
915
916 /* And make sure we never chase our dangling pointer from pci_dev */
917 pci_set_drvdata(pdev, NULL);
918}
919
Chris Wilson0673ad42016-06-24 14:00:22 +0100920/**
Janusz Krzysztofikb01558e2019-07-12 13:24:26 +0200921 * i915_driver_probe - setup chip and create an initial config
Joonas Lahtinend2ad3ae2016-11-10 15:36:34 +0200922 * @pdev: PCI device
923 * @ent: matching PCI ID entry
Chris Wilson0673ad42016-06-24 14:00:22 +0100924 *
Janusz Krzysztofikb01558e2019-07-12 13:24:26 +0200925 * The driver probe routine has to do several things:
Chris Wilson0673ad42016-06-24 14:00:22 +0100926 * - drive output discovery via intel_modeset_init()
927 * - initialize the memory manager
928 * - allocate initial config memory
929 * - setup the DRM framebuffer with the allocated memory
930 */
Janusz Krzysztofikb01558e2019-07-12 13:24:26 +0200931int i915_driver_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Chris Wilson0673ad42016-06-24 14:00:22 +0100932{
Maarten Lankhorst8d2b47d2017-02-02 08:41:42 +0100933 const struct intel_device_info *match_info =
934 (struct intel_device_info *)ent->driver_data;
Jani Nikula8eecfb32020-02-11 18:28:02 +0200935 struct drm_i915_private *i915;
Chris Wilson0673ad42016-06-24 14:00:22 +0100936 int ret;
937
Jani Nikula8eecfb32020-02-11 18:28:02 +0200938 i915 = i915_driver_create(pdev, ent);
939 if (IS_ERR(i915))
940 return PTR_ERR(i915);
Chris Wilson0673ad42016-06-24 14:00:22 +0100941
Ville Syrjälä1feb64c2018-09-13 16:16:22 +0300942 /* Disable nuclear pageflip by default on pre-ILK */
943 if (!i915_modparams.nuclear_pageflip && match_info->gen < 5)
Jani Nikula8eecfb32020-02-11 18:28:02 +0200944 i915->drm.driver_features &= ~DRIVER_ATOMIC;
Ville Syrjälä1feb64c2018-09-13 16:16:22 +0300945
Matthew Auld16292242019-10-30 17:33:20 +0000946 /*
947 * Check if we support fake LMEM -- for now we only unleash this for
948 * the live selftests(test-and-exit).
949 */
Chris Wilson292a27b2019-11-01 09:51:47 +0000950#if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
Matthew Auld16292242019-10-30 17:33:20 +0000951 if (IS_ENABLED(CONFIG_DRM_I915_UNSTABLE_FAKE_LMEM)) {
Jani Nikula8eecfb32020-02-11 18:28:02 +0200952 if (INTEL_GEN(i915) >= 9 && i915_selftest.live < 0 &&
Matthew Auld16292242019-10-30 17:33:20 +0000953 i915_modparams.fake_lmem_start) {
Jani Nikula8eecfb32020-02-11 18:28:02 +0200954 mkwrite_device_info(i915)->memory_regions =
Matthew Auld16292242019-10-30 17:33:20 +0000955 REGION_SMEM | REGION_LMEM | REGION_STOLEN;
Jani Nikula8eecfb32020-02-11 18:28:02 +0200956 mkwrite_device_info(i915)->is_dgfx = true;
957 GEM_BUG_ON(!HAS_LMEM(i915));
958 GEM_BUG_ON(!IS_DGFX(i915));
Matthew Auld16292242019-10-30 17:33:20 +0000959 }
960 }
Chris Wilson292a27b2019-11-01 09:51:47 +0000961#endif
Matthew Auld16292242019-10-30 17:33:20 +0000962
Chris Wilson0673ad42016-06-24 14:00:22 +0100963 ret = pci_enable_device(pdev);
964 if (ret)
Chris Wilsoncad36882017-02-10 16:35:21 +0000965 goto out_fini;
Chris Wilson0673ad42016-06-24 14:00:22 +0100966
Jani Nikula8eecfb32020-02-11 18:28:02 +0200967 ret = i915_driver_early_probe(i915);
Chris Wilson0673ad42016-06-24 14:00:22 +0100968 if (ret < 0)
969 goto out_pci_disable;
970
Jani Nikula8eecfb32020-02-11 18:28:02 +0200971 disable_rpm_wakeref_asserts(&i915->runtime_pm);
Chris Wilson0673ad42016-06-24 14:00:22 +0100972
Jani Nikula8eecfb32020-02-11 18:28:02 +0200973 i915_detect_vgpu(i915);
Daniele Ceraolo Spurio9e138ea2019-06-19 18:00:21 -0700974
Jani Nikula8eecfb32020-02-11 18:28:02 +0200975 ret = i915_driver_mmio_probe(i915);
Chris Wilson0673ad42016-06-24 14:00:22 +0100976 if (ret < 0)
977 goto out_runtime_pm_put;
978
Jani Nikula8eecfb32020-02-11 18:28:02 +0200979 ret = i915_driver_hw_probe(i915);
Chris Wilson0673ad42016-06-24 14:00:22 +0100980 if (ret < 0)
981 goto out_cleanup_mmio;
982
Jani Nikulab6642592020-02-19 15:37:56 +0200983 ret = i915_driver_modeset_probe_noirq(i915);
Chris Wilson0673ad42016-06-24 14:00:22 +0100984 if (ret < 0)
Daniel Vetterbaf54382017-06-21 10:28:41 +0200985 goto out_cleanup_hw;
Chris Wilson0673ad42016-06-24 14:00:22 +0100986
Jani Nikulab6642592020-02-19 15:37:56 +0200987 ret = intel_irq_install(i915);
988 if (ret)
989 goto out_cleanup_modeset;
990
991 ret = i915_driver_modeset_probe(i915);
992 if (ret < 0)
993 goto out_cleanup_irq;
994
Jani Nikula8eecfb32020-02-11 18:28:02 +0200995 i915_driver_register(i915);
Chris Wilson0673ad42016-06-24 14:00:22 +0100996
Jani Nikula8eecfb32020-02-11 18:28:02 +0200997 enable_rpm_wakeref_asserts(&i915->runtime_pm);
Chris Wilson0673ad42016-06-24 14:00:22 +0100998
Jani Nikula8eecfb32020-02-11 18:28:02 +0200999 i915_welcome_messages(i915);
Michal Wajdeczko27d558a2017-12-21 21:57:35 +00001000
Chris Wilson0673ad42016-06-24 14:00:22 +01001001 return 0;
1002
Jani Nikulab6642592020-02-19 15:37:56 +02001003out_cleanup_irq:
1004 intel_irq_uninstall(i915);
1005out_cleanup_modeset:
1006 /* FIXME */
Chris Wilson0673ad42016-06-24 14:00:22 +01001007out_cleanup_hw:
Jani Nikula8eecfb32020-02-11 18:28:02 +02001008 i915_driver_hw_remove(i915);
1009 intel_memory_regions_driver_release(i915);
1010 i915_ggtt_driver_release(i915);
Chris Wilson0673ad42016-06-24 14:00:22 +01001011out_cleanup_mmio:
Jani Nikula8eecfb32020-02-11 18:28:02 +02001012 i915_driver_mmio_release(i915);
Chris Wilson0673ad42016-06-24 14:00:22 +01001013out_runtime_pm_put:
Jani Nikula8eecfb32020-02-11 18:28:02 +02001014 enable_rpm_wakeref_asserts(&i915->runtime_pm);
1015 i915_driver_late_release(i915);
Chris Wilson0673ad42016-06-24 14:00:22 +01001016out_pci_disable:
1017 pci_disable_device(pdev);
Chris Wilsoncad36882017-02-10 16:35:21 +00001018out_fini:
Jani Nikula8eecfb32020-02-11 18:28:02 +02001019 i915_probe_error(i915, "Device initialization failed (%d)\n", ret);
1020 i915_driver_destroy(i915);
Chris Wilson0673ad42016-06-24 14:00:22 +01001021 return ret;
1022}
1023
Chris Wilson361f9dc2019-08-06 08:42:19 +01001024void i915_driver_remove(struct drm_i915_private *i915)
Chris Wilson0673ad42016-06-24 14:00:22 +01001025{
Chris Wilson361f9dc2019-08-06 08:42:19 +01001026 disable_rpm_wakeref_asserts(&i915->runtime_pm);
Chris Wilson07d80572018-08-16 15:37:56 +03001027
Chris Wilson361f9dc2019-08-06 08:42:19 +01001028 i915_driver_unregister(i915);
Daniel Vetter99c539b2017-07-15 00:46:56 +02001029
Chris Wilson4a8ab5e2019-01-14 14:21:29 +00001030 /* Flush any external code that still may be under the RCU lock */
1031 synchronize_rcu();
1032
Chris Wilson361f9dc2019-08-06 08:42:19 +01001033 i915_gem_suspend(i915);
Chris Wilson0673ad42016-06-24 14:00:22 +01001034
Chris Wilson361f9dc2019-08-06 08:42:19 +01001035 drm_atomic_helper_shutdown(&i915->drm);
Maarten Lankhorsta667fb42016-12-15 15:29:44 +01001036
Chris Wilson361f9dc2019-08-06 08:42:19 +01001037 intel_gvt_driver_remove(i915);
Zhenyu Wang26f837e2017-01-13 10:46:09 +08001038
Jani Nikula2d6f6f32019-09-20 21:54:16 +03001039 i915_driver_modeset_remove(i915);
Chris Wilson0673ad42016-06-24 14:00:22 +01001040
Jani Nikulaf20a60f2020-02-14 15:50:58 +02001041 intel_irq_uninstall(i915);
1042
1043 i915_driver_modeset_remove_noirq(i915);
1044
Chris Wilson361f9dc2019-08-06 08:42:19 +01001045 i915_reset_error_state(i915);
Chris Wilson361f9dc2019-08-06 08:42:19 +01001046 i915_gem_driver_remove(i915);
Chris Wilson0673ad42016-06-24 14:00:22 +01001047
Chris Wilson361f9dc2019-08-06 08:42:19 +01001048 intel_power_domains_driver_remove(i915);
Chris Wilson0673ad42016-06-24 14:00:22 +01001049
Chris Wilson361f9dc2019-08-06 08:42:19 +01001050 i915_driver_hw_remove(i915);
Chris Wilson0673ad42016-06-24 14:00:22 +01001051
Chris Wilson361f9dc2019-08-06 08:42:19 +01001052 enable_rpm_wakeref_asserts(&i915->runtime_pm);
Chris Wilsoncad36882017-02-10 16:35:21 +00001053}
1054
1055static void i915_driver_release(struct drm_device *dev)
1056{
1057 struct drm_i915_private *dev_priv = to_i915(dev);
Daniele Ceraolo Spurio69c66352019-06-13 16:21:53 -07001058 struct intel_runtime_pm *rpm = &dev_priv->runtime_pm;
Chris Wilson0673ad42016-06-24 14:00:22 +01001059
Daniele Ceraolo Spurio69c66352019-06-13 16:21:53 -07001060 disable_rpm_wakeref_asserts(rpm);
Janusz Krzysztofik47bc28d2019-05-30 15:31:05 +02001061
Janusz Krzysztofik3b58a942019-07-12 13:24:28 +02001062 i915_gem_driver_release(dev_priv);
Janusz Krzysztofik47bc28d2019-05-30 15:31:05 +02001063
Chris Wilson3fc794f2019-10-26 21:20:32 +01001064 intel_memory_regions_driver_release(dev_priv);
Janusz Krzysztofik3b58a942019-07-12 13:24:28 +02001065 i915_ggtt_driver_release(dev_priv);
Daniele Ceraolo Spurio19e0a8d2019-06-19 18:00:17 -07001066
Janusz Krzysztofik3b58a942019-07-12 13:24:28 +02001067 i915_driver_mmio_release(dev_priv);
Janusz Krzysztofik47bc28d2019-05-30 15:31:05 +02001068
Daniele Ceraolo Spurio69c66352019-06-13 16:21:53 -07001069 enable_rpm_wakeref_asserts(rpm);
Janusz Krzysztofik3b58a942019-07-12 13:24:28 +02001070 intel_runtime_pm_driver_release(rpm);
Janusz Krzysztofik47bc28d2019-05-30 15:31:05 +02001071
Janusz Krzysztofik3b58a942019-07-12 13:24:28 +02001072 i915_driver_late_release(dev_priv);
Chris Wilson31962ca2018-09-05 15:09:21 +01001073 i915_driver_destroy(dev_priv);
Chris Wilson0673ad42016-06-24 14:00:22 +01001074}
1075
1076static int i915_driver_open(struct drm_device *dev, struct drm_file *file)
1077{
Chris Wilson829a0af2017-06-20 12:05:45 +01001078 struct drm_i915_private *i915 = to_i915(dev);
Chris Wilson0673ad42016-06-24 14:00:22 +01001079 int ret;
1080
Chris Wilson829a0af2017-06-20 12:05:45 +01001081 ret = i915_gem_open(i915, file);
Chris Wilson0673ad42016-06-24 14:00:22 +01001082 if (ret)
1083 return ret;
1084
1085 return 0;
1086}
1087
1088/**
1089 * i915_driver_lastclose - clean up after all DRM clients have exited
1090 * @dev: DRM device
1091 *
1092 * Take care of cleaning up after all DRM clients have exited. In the
1093 * mode setting case, we want to restore the kernel's initial mode (just
1094 * in case the last client left us in a bad state).
1095 *
1096 * Additionally, in the non-mode setting case, we'll tear down the GTT
1097 * and DMA structures, since the kernel won't be using them, and clea
1098 * up any GEM state.
1099 */
1100static void i915_driver_lastclose(struct drm_device *dev)
1101{
1102 intel_fbdev_restore_mode(dev);
1103 vga_switcheroo_process_delayed_switch();
1104}
1105
Daniel Vetter7d2ec882017-03-08 15:12:45 +01001106static void i915_driver_postclose(struct drm_device *dev, struct drm_file *file)
Chris Wilson0673ad42016-06-24 14:00:22 +01001107{
Daniel Vetter7d2ec882017-03-08 15:12:45 +01001108 struct drm_i915_file_private *file_priv = file->driver_priv;
1109
Chris Wilson829a0af2017-06-20 12:05:45 +01001110 i915_gem_context_close(file);
Chris Wilson0673ad42016-06-24 14:00:22 +01001111 i915_gem_release(dev, file);
Chris Wilson0673ad42016-06-24 14:00:22 +01001112
Chris Wilson77715902019-08-23 19:14:55 +01001113 kfree_rcu(file_priv, rcu);
Chris Wilson515b8b72019-08-02 22:21:37 +01001114
1115 /* Catch up with all the deferred frees from "this" client */
1116 i915_gem_flush_free_objects(to_i915(dev));
Chris Wilson0673ad42016-06-24 14:00:22 +01001117}
1118
Imre Deak07f9cd02014-08-18 14:42:45 +03001119static void intel_suspend_encoders(struct drm_i915_private *dev_priv)
1120{
Chris Wilson91c8a322016-07-05 10:40:23 +01001121 struct drm_device *dev = &dev_priv->drm;
Jani Nikula19c80542015-12-16 12:48:16 +02001122 struct intel_encoder *encoder;
Imre Deak07f9cd02014-08-18 14:42:45 +03001123
1124 drm_modeset_lock_all(dev);
Jani Nikula19c80542015-12-16 12:48:16 +02001125 for_each_intel_encoder(dev, encoder)
1126 if (encoder->suspend)
1127 encoder->suspend(encoder);
Imre Deak07f9cd02014-08-18 14:42:45 +03001128 drm_modeset_unlock_all(dev);
1129}
1130
Imre Deakbc872292015-11-18 17:32:30 +02001131static bool suspend_to_idle(struct drm_i915_private *dev_priv)
1132{
1133#if IS_ENABLED(CONFIG_ACPI_SLEEP)
1134 if (acpi_target_system_state() < ACPI_STATE_S3)
1135 return true;
1136#endif
1137 return false;
1138}
Sagar Kambleebc32822014-08-13 23:07:05 +05301139
Chris Wilson73b66f82018-05-25 10:26:29 +01001140static int i915_drm_prepare(struct drm_device *dev)
1141{
1142 struct drm_i915_private *i915 = to_i915(dev);
Chris Wilson73b66f82018-05-25 10:26:29 +01001143
1144 /*
1145 * NB intel_display_suspend() may issue new requests after we've
1146 * ostensibly marked the GPU as ready-to-sleep here. We need to
1147 * split out that work and pull it forward so that after point,
1148 * the GPU is not woken again.
1149 */
Chris Wilson5861b012019-03-08 09:36:54 +00001150 i915_gem_suspend(i915);
Chris Wilson73b66f82018-05-25 10:26:29 +01001151
Chris Wilson5861b012019-03-08 09:36:54 +00001152 return 0;
Chris Wilson73b66f82018-05-25 10:26:29 +01001153}
1154
Imre Deak5e365c32014-10-23 19:23:25 +03001155static int i915_drm_suspend(struct drm_device *dev)
Rafael J. Wysocki84b79f82010-02-07 21:48:24 +01001156{
Chris Wilsonfac5e232016-07-04 11:34:36 +01001157 struct drm_i915_private *dev_priv = to_i915(dev);
David Weinehall52a05c32016-08-22 13:32:44 +03001158 struct pci_dev *pdev = dev_priv->drm.pdev;
Jesse Barnese5747e32014-06-12 08:35:47 -07001159 pci_power_t opregion_target_state;
Rafael J. Wysocki61caf872010-02-18 23:06:27 +01001160
Daniele Ceraolo Spurio91026502019-06-13 16:21:51 -07001161 disable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
Imre Deak1f814da2015-12-16 02:52:19 +02001162
Paulo Zanonic67a4702013-08-19 13:18:09 -03001163 /* We do a lot of poking in a lot of registers, make sure they work
1164 * properly. */
Imre Deak2cd9a682018-08-16 15:37:57 +03001165 intel_power_domains_disable(dev_priv);
Paulo Zanonicb107992013-01-25 16:59:15 -02001166
Dave Airlie5bcf7192010-12-07 09:20:40 +10001167 drm_kms_helper_poll_disable(dev);
1168
David Weinehall52a05c32016-08-22 13:32:44 +03001169 pci_save_state(pdev);
Rafael J. Wysocki84b79f82010-02-07 21:48:24 +01001170
Maarten Lankhorst6b72d482015-06-01 12:49:47 +02001171 intel_display_suspend(dev);
Daniel Vetterd5818932015-02-23 12:03:26 +01001172
Ville Syrjälä1a4313d2018-07-05 19:43:52 +03001173 intel_dp_mst_suspend(dev_priv);
Daniel Vetterd5818932015-02-23 12:03:26 +01001174
1175 intel_runtime_pm_disable_interrupts(dev_priv);
1176 intel_hpd_cancel_work(dev_priv);
1177
1178 intel_suspend_encoders(dev_priv);
1179
Ville Syrjälä712bf362016-10-31 22:37:23 +02001180 intel_suspend_hw(dev_priv);
Daniel Vetterd5818932015-02-23 12:03:26 +01001181
Chris Wilsone9862092020-01-30 18:17:09 +00001182 i915_ggtt_suspend(&dev_priv->ggtt);
Ben Widawsky828c7902013-10-16 09:21:30 -07001183
Tvrtko Ursulinaf6dc742016-12-01 14:16:44 +00001184 i915_save_state(dev_priv);
Rafael J. Wysocki84b79f82010-02-07 21:48:24 +01001185
Imre Deakbc872292015-11-18 17:32:30 +02001186 opregion_target_state = suspend_to_idle(dev_priv) ? PCI_D1 : PCI_D3cold;
Chris Wilsona950adc2018-10-30 11:05:54 +00001187 intel_opregion_suspend(dev_priv, opregion_target_state);
Rafael J. Wysocki84b79f82010-02-07 21:48:24 +01001188
Chris Wilson82e3b8c2014-08-13 13:09:46 +01001189 intel_fbdev_set_suspend(dev, FBINFO_STATE_SUSPENDED, true);
Dave Airlie3fa016a2012-03-28 10:48:49 +01001190
Mika Kuoppala62d5d692014-02-25 17:11:28 +02001191 dev_priv->suspend_count++;
1192
Imre Deakf74ed082016-04-18 14:48:21 +03001193 intel_csr_ucode_suspend(dev_priv);
Imre Deakf514c2d2015-10-28 23:59:06 +02001194
Daniele Ceraolo Spurio91026502019-06-13 16:21:51 -07001195 enable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
Imre Deak1f814da2015-12-16 02:52:19 +02001196
Chris Wilson73b66f82018-05-25 10:26:29 +01001197 return 0;
Rafael J. Wysocki84b79f82010-02-07 21:48:24 +01001198}
1199
Imre Deak2cd9a682018-08-16 15:37:57 +03001200static enum i915_drm_suspend_mode
1201get_suspend_mode(struct drm_i915_private *dev_priv, bool hibernate)
1202{
1203 if (hibernate)
1204 return I915_DRM_SUSPEND_HIBERNATE;
1205
1206 if (suspend_to_idle(dev_priv))
1207 return I915_DRM_SUSPEND_IDLE;
1208
1209 return I915_DRM_SUSPEND_MEM;
1210}
1211
David Weinehallc49d13e2016-08-22 13:32:42 +03001212static int i915_drm_suspend_late(struct drm_device *dev, bool hibernation)
Imre Deakc3c09c92014-10-23 19:23:15 +03001213{
David Weinehallc49d13e2016-08-22 13:32:42 +03001214 struct drm_i915_private *dev_priv = to_i915(dev);
David Weinehall52a05c32016-08-22 13:32:44 +03001215 struct pci_dev *pdev = dev_priv->drm.pdev;
Daniele Ceraolo Spurio69c66352019-06-13 16:21:53 -07001216 struct intel_runtime_pm *rpm = &dev_priv->runtime_pm;
Jani Nikulafb5f4322020-02-12 16:40:57 +02001217 int ret;
Imre Deakc3c09c92014-10-23 19:23:15 +03001218
Daniele Ceraolo Spurio69c66352019-06-13 16:21:53 -07001219 disable_rpm_wakeref_asserts(rpm);
Imre Deak1f814da2015-12-16 02:52:19 +02001220
Chris Wilsonec92ad02018-05-31 09:22:46 +01001221 i915_gem_suspend_late(dev_priv);
1222
Daniele Ceraolo Spuriof7de5022019-03-19 11:35:37 -07001223 intel_uncore_suspend(&dev_priv->uncore);
Imre Deak4c494a52016-10-13 14:34:06 +03001224
Imre Deak2cd9a682018-08-16 15:37:57 +03001225 intel_power_domains_suspend(dev_priv,
1226 get_suspend_mode(dev_priv, hibernation));
Imre Deak73dfc222015-11-17 17:33:53 +02001227
Rodrigo Vivi071b68c2019-08-06 15:22:08 +03001228 intel_display_power_suspend_late(dev_priv);
1229
Jani Nikulafb5f4322020-02-12 16:40:57 +02001230 ret = vlv_suspend_complete(dev_priv);
Imre Deakc3c09c92014-10-23 19:23:15 +03001231 if (ret) {
Wambui Karuga00376cc2020-01-31 12:34:12 +03001232 drm_err(&dev_priv->drm, "Suspend complete failed: %d\n", ret);
Imre Deak2cd9a682018-08-16 15:37:57 +03001233 intel_power_domains_resume(dev_priv);
Imre Deakc3c09c92014-10-23 19:23:15 +03001234
Imre Deak1f814da2015-12-16 02:52:19 +02001235 goto out;
Imre Deakc3c09c92014-10-23 19:23:15 +03001236 }
1237
David Weinehall52a05c32016-08-22 13:32:44 +03001238 pci_disable_device(pdev);
Imre Deakab3be732015-03-02 13:04:41 +02001239 /*
Imre Deak54875572015-06-30 17:06:47 +03001240 * During hibernation on some platforms the BIOS may try to access
Imre Deakab3be732015-03-02 13:04:41 +02001241 * the device even though it's already in D3 and hang the machine. So
1242 * leave the device in D0 on those platforms and hope the BIOS will
Imre Deak54875572015-06-30 17:06:47 +03001243 * power down the device properly. The issue was seen on multiple old
1244 * GENs with different BIOS vendors, so having an explicit blacklist
1245 * is inpractical; apply the workaround on everything pre GEN6. The
1246 * platforms where the issue was seen:
1247 * Lenovo Thinkpad X301, X61s, X60, T60, X41
1248 * Fujitsu FSC S7110
1249 * Acer Aspire 1830T
Imre Deakab3be732015-03-02 13:04:41 +02001250 */
Tvrtko Ursulin514e1d62016-11-04 14:42:48 +00001251 if (!(hibernation && INTEL_GEN(dev_priv) < 6))
David Weinehall52a05c32016-08-22 13:32:44 +03001252 pci_set_power_state(pdev, PCI_D3hot);
Imre Deakc3c09c92014-10-23 19:23:15 +03001253
Imre Deak1f814da2015-12-16 02:52:19 +02001254out:
Daniele Ceraolo Spurio69c66352019-06-13 16:21:53 -07001255 enable_rpm_wakeref_asserts(rpm);
Daniele Ceraolo Spurio0a9b2632019-08-09 07:31:16 +01001256 if (!dev_priv->uncore.user_forcewake_count)
Janusz Krzysztofik3b58a942019-07-12 13:24:28 +02001257 intel_runtime_pm_driver_release(rpm);
Imre Deak1f814da2015-12-16 02:52:19 +02001258
1259 return ret;
Imre Deakc3c09c92014-10-23 19:23:15 +03001260}
1261
Jani Nikula63bf8302019-10-04 15:20:18 +03001262int i915_suspend_switcheroo(struct drm_i915_private *i915, pm_message_t state)
Rafael J. Wysocki84b79f82010-02-07 21:48:24 +01001263{
1264 int error;
1265
Pankaj Bharadiya48a1b8d2020-01-15 09:14:53 +05301266 if (drm_WARN_ON_ONCE(&i915->drm, state.event != PM_EVENT_SUSPEND &&
1267 state.event != PM_EVENT_FREEZE))
Imre Deak0b14cbd2014-09-10 18:16:55 +03001268 return -EINVAL;
Dave Airlie5bcf7192010-12-07 09:20:40 +10001269
Chris Wilson361f9dc2019-08-06 08:42:19 +01001270 if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF)
Dave Airlie5bcf7192010-12-07 09:20:40 +10001271 return 0;
Chris Wilson6eecba32010-09-08 09:45:11 +01001272
Chris Wilson361f9dc2019-08-06 08:42:19 +01001273 error = i915_drm_suspend(&i915->drm);
Rafael J. Wysocki84b79f82010-02-07 21:48:24 +01001274 if (error)
1275 return error;
Jesse Barnesba8bbcf2007-11-22 14:14:14 +10001276
Chris Wilson361f9dc2019-08-06 08:42:19 +01001277 return i915_drm_suspend_late(&i915->drm, false);
Jesse Barnesba8bbcf2007-11-22 14:14:14 +10001278}
1279
Imre Deak5e365c32014-10-23 19:23:25 +03001280static int i915_drm_resume(struct drm_device *dev)
Jesse Barnesba8bbcf2007-11-22 14:14:14 +10001281{
Chris Wilsonfac5e232016-07-04 11:34:36 +01001282 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläac840ae2016-05-06 21:35:55 +03001283 int ret;
Matthew Garrett8ee1c3d2008-08-05 19:37:25 +01001284
Daniele Ceraolo Spurio91026502019-06-13 16:21:51 -07001285 disable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
Imre Deak1f814da2015-12-16 02:52:19 +02001286
Chris Wilson640b50f2019-12-28 11:12:55 +00001287 sanitize_gpu(dev_priv);
1288
Chris Wilson97d6d7a2016-08-04 07:52:22 +01001289 ret = i915_ggtt_enable_hw(dev_priv);
Ville Syrjäläac840ae2016-05-06 21:35:55 +03001290 if (ret)
Wambui Karuga00376cc2020-01-31 12:34:12 +03001291 drm_err(&dev_priv->drm, "failed to re-enable GGTT\n");
Ville Syrjäläac840ae2016-05-06 21:35:55 +03001292
Chris Wilsone9862092020-01-30 18:17:09 +00001293 i915_ggtt_resume(&dev_priv->ggtt);
Chris Wilsone9d4c922019-10-16 15:32:33 +01001294 i915_gem_restore_fences(&dev_priv->ggtt);
Chris Wilsoncec5ca02019-09-09 12:00:08 +01001295
Imre Deakf74ed082016-04-18 14:48:21 +03001296 intel_csr_ucode_resume(dev_priv);
1297
Tvrtko Ursulinaf6dc742016-12-01 14:16:44 +00001298 i915_restore_state(dev_priv);
Imre Deak8090ba82016-08-10 14:07:33 +03001299 intel_pps_unlock_regs_wa(dev_priv);
Rafael J. Wysocki61caf872010-02-18 23:06:27 +01001300
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02001301 intel_init_pch_refclk(dev_priv);
Chris Wilson1833b132012-05-09 11:56:28 +01001302
Peter Antoine364aece2015-05-11 08:50:45 +01001303 /*
1304 * Interrupts have to be enabled before any batches are run. If not the
1305 * GPU will hang. i915_gem_init_hw() will initiate batches to
1306 * update/restore the context.
1307 *
Imre Deak908764f2016-11-29 21:40:29 +02001308 * drm_mode_config_reset() needs AUX interrupts.
1309 *
Peter Antoine364aece2015-05-11 08:50:45 +01001310 * Modeset enabling in intel_modeset_init_hw() also needs working
1311 * interrupts.
1312 */
1313 intel_runtime_pm_enable_interrupts(dev_priv);
1314
Imre Deak908764f2016-11-29 21:40:29 +02001315 drm_mode_config_reset(dev);
1316
Chris Wilson37cd3302017-11-12 11:27:38 +00001317 i915_gem_resume(dev_priv);
Daniel Vetterd5818932015-02-23 12:03:26 +01001318
Jani Nikula6cd02e72019-09-20 21:54:21 +03001319 intel_modeset_init_hw(dev_priv);
Ville Syrjälä675f7ff2017-11-16 18:02:15 +02001320 intel_init_clock_gating(dev_priv);
Daniel Vetterd5818932015-02-23 12:03:26 +01001321
1322 spin_lock_irq(&dev_priv->irq_lock);
1323 if (dev_priv->display.hpd_irq_setup)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001324 dev_priv->display.hpd_irq_setup(dev_priv);
Daniel Vetterd5818932015-02-23 12:03:26 +01001325 spin_unlock_irq(&dev_priv->irq_lock);
1326
Ville Syrjälä1a4313d2018-07-05 19:43:52 +03001327 intel_dp_mst_resume(dev_priv);
Daniel Vetterd5818932015-02-23 12:03:26 +01001328
Lyudea16b7652016-03-11 10:57:01 -05001329 intel_display_resume(dev);
1330
Lyudee0b70062016-11-01 21:06:30 -04001331 drm_kms_helper_poll_enable(dev);
1332
Daniel Vetterd5818932015-02-23 12:03:26 +01001333 /*
1334 * ... but also need to make sure that hotplug processing
1335 * doesn't cause havoc. Like in the driver load code we don't
Gwan-gyeong Munc444ad72018-08-03 19:41:50 +03001336 * bother with the tiny race here where we might lose hotplug
Daniel Vetterd5818932015-02-23 12:03:26 +01001337 * notifications.
1338 * */
1339 intel_hpd_init(dev_priv);
Jesse Barnes1daed3f2011-01-05 12:01:25 -08001340
Chris Wilsona950adc2018-10-30 11:05:54 +00001341 intel_opregion_resume(dev_priv);
Chris Wilson44834a62010-08-19 16:09:23 +01001342
Chris Wilson82e3b8c2014-08-13 13:09:46 +01001343 intel_fbdev_set_suspend(dev, FBINFO_STATE_RUNNING, false);
Jesse Barnes073f34d2012-11-02 11:13:59 -07001344
Imre Deak2cd9a682018-08-16 15:37:57 +03001345 intel_power_domains_enable(dev_priv);
1346
Daniele Ceraolo Spurio91026502019-06-13 16:21:51 -07001347 enable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
Imre Deak1f814da2015-12-16 02:52:19 +02001348
Chris Wilson074c6ad2014-04-09 09:19:43 +01001349 return 0;
Rafael J. Wysocki84b79f82010-02-07 21:48:24 +01001350}
1351
Imre Deak5e365c32014-10-23 19:23:25 +03001352static int i915_drm_resume_early(struct drm_device *dev)
Rafael J. Wysocki84b79f82010-02-07 21:48:24 +01001353{
Chris Wilsonfac5e232016-07-04 11:34:36 +01001354 struct drm_i915_private *dev_priv = to_i915(dev);
David Weinehall52a05c32016-08-22 13:32:44 +03001355 struct pci_dev *pdev = dev_priv->drm.pdev;
Imre Deak44410cd2016-04-18 14:45:54 +03001356 int ret;
Imre Deak36d61e62014-10-23 19:23:24 +03001357
Imre Deak76c4b252014-04-01 19:55:22 +03001358 /*
1359 * We have a resume ordering issue with the snd-hda driver also
1360 * requiring our device to be power up. Due to the lack of a
1361 * parent/child relationship we currently solve this with an early
1362 * resume hook.
1363 *
1364 * FIXME: This should be solved with a special hdmi sink device or
1365 * similar so that power domains can be employed.
1366 */
Imre Deak44410cd2016-04-18 14:45:54 +03001367
1368 /*
1369 * Note that we need to set the power state explicitly, since we
1370 * powered off the device during freeze and the PCI core won't power
1371 * it back up for us during thaw. Powering off the device during
1372 * freeze is not a hard requirement though, and during the
1373 * suspend/resume phases the PCI core makes sure we get here with the
1374 * device powered on. So in case we change our freeze logic and keep
1375 * the device powered we can also remove the following set power state
1376 * call.
1377 */
David Weinehall52a05c32016-08-22 13:32:44 +03001378 ret = pci_set_power_state(pdev, PCI_D0);
Imre Deak44410cd2016-04-18 14:45:54 +03001379 if (ret) {
Wambui Karuga00376cc2020-01-31 12:34:12 +03001380 drm_err(&dev_priv->drm,
1381 "failed to set PCI D0 power state (%d)\n", ret);
Imre Deak2cd9a682018-08-16 15:37:57 +03001382 return ret;
Imre Deak44410cd2016-04-18 14:45:54 +03001383 }
1384
1385 /*
1386 * Note that pci_enable_device() first enables any parent bridge
1387 * device and only then sets the power state for this device. The
1388 * bridge enabling is a nop though, since bridge devices are resumed
1389 * first. The order of enabling power and enabling the device is
1390 * imposed by the PCI core as described above, so here we preserve the
1391 * same order for the freeze/thaw phases.
1392 *
1393 * TODO: eventually we should remove pci_disable_device() /
1394 * pci_enable_enable_device() from suspend/resume. Due to how they
1395 * depend on the device enable refcount we can't anyway depend on them
1396 * disabling/enabling the device.
1397 */
Imre Deak2cd9a682018-08-16 15:37:57 +03001398 if (pci_enable_device(pdev))
1399 return -EIO;
Rafael J. Wysocki84b79f82010-02-07 21:48:24 +01001400
David Weinehall52a05c32016-08-22 13:32:44 +03001401 pci_set_master(pdev);
Rafael J. Wysocki84b79f82010-02-07 21:48:24 +01001402
Daniele Ceraolo Spurio91026502019-06-13 16:21:51 -07001403 disable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
Imre Deak1f814da2015-12-16 02:52:19 +02001404
Jani Nikulafb5f4322020-02-12 16:40:57 +02001405 ret = vlv_resume_prepare(dev_priv, false);
Imre Deak36d61e62014-10-23 19:23:24 +03001406 if (ret)
Wambui Karuga00376cc2020-01-31 12:34:12 +03001407 drm_err(&dev_priv->drm,
Jani Nikulafb5f4322020-02-12 16:40:57 +02001408 "Resume prepare failed: %d, continuing anyway\n", ret);
Imre Deak36d61e62014-10-23 19:23:24 +03001409
Daniele Ceraolo Spuriof7de5022019-03-19 11:35:37 -07001410 intel_uncore_resume_early(&dev_priv->uncore);
1411
Tvrtko Ursulineaf522f2019-06-21 08:07:44 +01001412 intel_gt_check_and_clear_faults(&dev_priv->gt);
Paulo Zanoniefee8332014-10-27 17:54:33 -02001413
Rodrigo Vivi071b68c2019-08-06 15:22:08 +03001414 intel_display_power_resume_early(dev_priv);
Paulo Zanoniefee8332014-10-27 17:54:33 -02001415
Imre Deak2cd9a682018-08-16 15:37:57 +03001416 intel_power_domains_resume(dev_priv);
Imre Deakbc872292015-11-18 17:32:30 +02001417
Daniele Ceraolo Spurio91026502019-06-13 16:21:51 -07001418 enable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
Imre Deak6e35e8a2016-04-18 10:04:19 +03001419
Imre Deak36d61e62014-10-23 19:23:24 +03001420 return ret;
Imre Deak76c4b252014-04-01 19:55:22 +03001421}
1422
Jani Nikula63bf8302019-10-04 15:20:18 +03001423int i915_resume_switcheroo(struct drm_i915_private *i915)
Imre Deak76c4b252014-04-01 19:55:22 +03001424{
Imre Deak50a00722014-10-23 19:23:17 +03001425 int ret;
Imre Deak76c4b252014-04-01 19:55:22 +03001426
Chris Wilson361f9dc2019-08-06 08:42:19 +01001427 if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF)
Imre Deak097dd832014-10-23 19:23:19 +03001428 return 0;
1429
Chris Wilson361f9dc2019-08-06 08:42:19 +01001430 ret = i915_drm_resume_early(&i915->drm);
Imre Deak50a00722014-10-23 19:23:17 +03001431 if (ret)
1432 return ret;
1433
Chris Wilson361f9dc2019-08-06 08:42:19 +01001434 return i915_drm_resume(&i915->drm);
Imre Deak5a175142014-10-23 19:23:18 +03001435}
1436
Chris Wilson73b66f82018-05-25 10:26:29 +01001437static int i915_pm_prepare(struct device *kdev)
1438{
Chris Wilson361f9dc2019-08-06 08:42:19 +01001439 struct drm_i915_private *i915 = kdev_to_i915(kdev);
Chris Wilson73b66f82018-05-25 10:26:29 +01001440
Chris Wilson361f9dc2019-08-06 08:42:19 +01001441 if (!i915) {
Chris Wilson73b66f82018-05-25 10:26:29 +01001442 dev_err(kdev, "DRM not initialized, aborting suspend.\n");
1443 return -ENODEV;
1444 }
1445
Chris Wilson361f9dc2019-08-06 08:42:19 +01001446 if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF)
Chris Wilson73b66f82018-05-25 10:26:29 +01001447 return 0;
1448
Chris Wilson361f9dc2019-08-06 08:42:19 +01001449 return i915_drm_prepare(&i915->drm);
Chris Wilson73b66f82018-05-25 10:26:29 +01001450}
1451
David Weinehallc49d13e2016-08-22 13:32:42 +03001452static int i915_pm_suspend(struct device *kdev)
Kristian Høgsberg112b7152009-01-04 16:55:33 -05001453{
Chris Wilson361f9dc2019-08-06 08:42:19 +01001454 struct drm_i915_private *i915 = kdev_to_i915(kdev);
Kristian Høgsberg112b7152009-01-04 16:55:33 -05001455
Chris Wilson361f9dc2019-08-06 08:42:19 +01001456 if (!i915) {
David Weinehallc49d13e2016-08-22 13:32:42 +03001457 dev_err(kdev, "DRM not initialized, aborting suspend.\n");
Rafael J. Wysocki84b79f82010-02-07 21:48:24 +01001458 return -ENODEV;
1459 }
Kristian Høgsberg112b7152009-01-04 16:55:33 -05001460
Chris Wilson361f9dc2019-08-06 08:42:19 +01001461 if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF)
Dave Airlie5bcf7192010-12-07 09:20:40 +10001462 return 0;
1463
Chris Wilson361f9dc2019-08-06 08:42:19 +01001464 return i915_drm_suspend(&i915->drm);
Imre Deak76c4b252014-04-01 19:55:22 +03001465}
1466
David Weinehallc49d13e2016-08-22 13:32:42 +03001467static int i915_pm_suspend_late(struct device *kdev)
Imre Deak76c4b252014-04-01 19:55:22 +03001468{
Chris Wilson361f9dc2019-08-06 08:42:19 +01001469 struct drm_i915_private *i915 = kdev_to_i915(kdev);
Imre Deak76c4b252014-04-01 19:55:22 +03001470
1471 /*
Damien Lespiauc965d9952015-05-18 19:53:48 +01001472 * We have a suspend ordering issue with the snd-hda driver also
Imre Deak76c4b252014-04-01 19:55:22 +03001473 * requiring our device to be power up. Due to the lack of a
1474 * parent/child relationship we currently solve this with an late
1475 * suspend hook.
1476 *
1477 * FIXME: This should be solved with a special hdmi sink device or
1478 * similar so that power domains can be employed.
1479 */
Chris Wilson361f9dc2019-08-06 08:42:19 +01001480 if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF)
Imre Deak76c4b252014-04-01 19:55:22 +03001481 return 0;
Kristian Høgsberg112b7152009-01-04 16:55:33 -05001482
Chris Wilson361f9dc2019-08-06 08:42:19 +01001483 return i915_drm_suspend_late(&i915->drm, false);
Imre Deakab3be732015-03-02 13:04:41 +02001484}
1485
David Weinehallc49d13e2016-08-22 13:32:42 +03001486static int i915_pm_poweroff_late(struct device *kdev)
Imre Deakab3be732015-03-02 13:04:41 +02001487{
Chris Wilson361f9dc2019-08-06 08:42:19 +01001488 struct drm_i915_private *i915 = kdev_to_i915(kdev);
Imre Deakab3be732015-03-02 13:04:41 +02001489
Chris Wilson361f9dc2019-08-06 08:42:19 +01001490 if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF)
Imre Deakab3be732015-03-02 13:04:41 +02001491 return 0;
1492
Chris Wilson361f9dc2019-08-06 08:42:19 +01001493 return i915_drm_suspend_late(&i915->drm, true);
Zhenyu Wangcbda12d2009-12-16 13:36:10 +08001494}
1495
David Weinehallc49d13e2016-08-22 13:32:42 +03001496static int i915_pm_resume_early(struct device *kdev)
Imre Deak76c4b252014-04-01 19:55:22 +03001497{
Chris Wilson361f9dc2019-08-06 08:42:19 +01001498 struct drm_i915_private *i915 = kdev_to_i915(kdev);
Imre Deak76c4b252014-04-01 19:55:22 +03001499
Chris Wilson361f9dc2019-08-06 08:42:19 +01001500 if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF)
Imre Deak097dd832014-10-23 19:23:19 +03001501 return 0;
1502
Chris Wilson361f9dc2019-08-06 08:42:19 +01001503 return i915_drm_resume_early(&i915->drm);
Imre Deak76c4b252014-04-01 19:55:22 +03001504}
1505
David Weinehallc49d13e2016-08-22 13:32:42 +03001506static int i915_pm_resume(struct device *kdev)
Zhenyu Wangcbda12d2009-12-16 13:36:10 +08001507{
Chris Wilson361f9dc2019-08-06 08:42:19 +01001508 struct drm_i915_private *i915 = kdev_to_i915(kdev);
Rafael J. Wysocki84b79f82010-02-07 21:48:24 +01001509
Chris Wilson361f9dc2019-08-06 08:42:19 +01001510 if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF)
Imre Deak097dd832014-10-23 19:23:19 +03001511 return 0;
1512
Chris Wilson361f9dc2019-08-06 08:42:19 +01001513 return i915_drm_resume(&i915->drm);
Zhenyu Wangcbda12d2009-12-16 13:36:10 +08001514}
1515
Chris Wilson1f19ac22016-05-14 07:26:32 +01001516/* freeze: before creating the hibernation_image */
David Weinehallc49d13e2016-08-22 13:32:42 +03001517static int i915_pm_freeze(struct device *kdev)
Chris Wilson1f19ac22016-05-14 07:26:32 +01001518{
Chris Wilson361f9dc2019-08-06 08:42:19 +01001519 struct drm_i915_private *i915 = kdev_to_i915(kdev);
Chris Wilson6a800ea2016-09-21 14:51:07 +01001520 int ret;
1521
Chris Wilson361f9dc2019-08-06 08:42:19 +01001522 if (i915->drm.switch_power_state != DRM_SWITCH_POWER_OFF) {
1523 ret = i915_drm_suspend(&i915->drm);
Imre Deakdd9f31c2017-08-16 17:46:07 +03001524 if (ret)
1525 return ret;
1526 }
Chris Wilson6a800ea2016-09-21 14:51:07 +01001527
Chris Wilson361f9dc2019-08-06 08:42:19 +01001528 ret = i915_gem_freeze(i915);
Chris Wilson6a800ea2016-09-21 14:51:07 +01001529 if (ret)
1530 return ret;
1531
1532 return 0;
Chris Wilson1f19ac22016-05-14 07:26:32 +01001533}
1534
David Weinehallc49d13e2016-08-22 13:32:42 +03001535static int i915_pm_freeze_late(struct device *kdev)
Chris Wilson1f19ac22016-05-14 07:26:32 +01001536{
Chris Wilson361f9dc2019-08-06 08:42:19 +01001537 struct drm_i915_private *i915 = kdev_to_i915(kdev);
Chris Wilson461fb992016-05-14 07:26:33 +01001538 int ret;
1539
Chris Wilson361f9dc2019-08-06 08:42:19 +01001540 if (i915->drm.switch_power_state != DRM_SWITCH_POWER_OFF) {
1541 ret = i915_drm_suspend_late(&i915->drm, true);
Imre Deakdd9f31c2017-08-16 17:46:07 +03001542 if (ret)
1543 return ret;
1544 }
Chris Wilson461fb992016-05-14 07:26:33 +01001545
Chris Wilson361f9dc2019-08-06 08:42:19 +01001546 ret = i915_gem_freeze_late(i915);
Chris Wilson461fb992016-05-14 07:26:33 +01001547 if (ret)
1548 return ret;
1549
1550 return 0;
Chris Wilson1f19ac22016-05-14 07:26:32 +01001551}
1552
1553/* thaw: called after creating the hibernation image, but before turning off. */
David Weinehallc49d13e2016-08-22 13:32:42 +03001554static int i915_pm_thaw_early(struct device *kdev)
Chris Wilson1f19ac22016-05-14 07:26:32 +01001555{
David Weinehallc49d13e2016-08-22 13:32:42 +03001556 return i915_pm_resume_early(kdev);
Chris Wilson1f19ac22016-05-14 07:26:32 +01001557}
1558
David Weinehallc49d13e2016-08-22 13:32:42 +03001559static int i915_pm_thaw(struct device *kdev)
Chris Wilson1f19ac22016-05-14 07:26:32 +01001560{
David Weinehallc49d13e2016-08-22 13:32:42 +03001561 return i915_pm_resume(kdev);
Chris Wilson1f19ac22016-05-14 07:26:32 +01001562}
1563
1564/* restore: called after loading the hibernation image. */
David Weinehallc49d13e2016-08-22 13:32:42 +03001565static int i915_pm_restore_early(struct device *kdev)
Chris Wilson1f19ac22016-05-14 07:26:32 +01001566{
David Weinehallc49d13e2016-08-22 13:32:42 +03001567 return i915_pm_resume_early(kdev);
Chris Wilson1f19ac22016-05-14 07:26:32 +01001568}
1569
David Weinehallc49d13e2016-08-22 13:32:42 +03001570static int i915_pm_restore(struct device *kdev)
Chris Wilson1f19ac22016-05-14 07:26:32 +01001571{
David Weinehallc49d13e2016-08-22 13:32:42 +03001572 return i915_pm_resume(kdev);
Chris Wilson1f19ac22016-05-14 07:26:32 +01001573}
1574
David Weinehallc49d13e2016-08-22 13:32:42 +03001575static int intel_runtime_suspend(struct device *kdev)
Paulo Zanoni8a187452013-12-06 20:32:13 -02001576{
Chris Wilson361f9dc2019-08-06 08:42:19 +01001577 struct drm_i915_private *dev_priv = kdev_to_i915(kdev);
Daniele Ceraolo Spurio1bf676c2019-06-13 16:21:52 -07001578 struct intel_runtime_pm *rpm = &dev_priv->runtime_pm;
Jani Nikulafb5f4322020-02-12 16:40:57 +02001579 int ret;
Paulo Zanoni8a187452013-12-06 20:32:13 -02001580
Pankaj Bharadiya48a1b8d2020-01-15 09:14:53 +05301581 if (drm_WARN_ON_ONCE(&dev_priv->drm, !HAS_RUNTIME_PM(dev_priv)))
Imre Deak604effb2014-08-26 13:26:56 +03001582 return -ENODEV;
1583
Wambui Karuga00376cc2020-01-31 12:34:12 +03001584 drm_dbg_kms(&dev_priv->drm, "Suspending device\n");
Paulo Zanoni8a187452013-12-06 20:32:13 -02001585
Daniele Ceraolo Spurio91026502019-06-13 16:21:51 -07001586 disable_rpm_wakeref_asserts(rpm);
Imre Deak1f814da2015-12-16 02:52:19 +02001587
Imre Deakd6102972014-05-07 19:57:49 +03001588 /*
1589 * We are safe here against re-faults, since the fault handler takes
1590 * an RPM reference.
1591 */
Chris Wilson7c108fd2016-10-24 13:42:18 +01001592 i915_gem_runtime_suspend(dev_priv);
Imre Deakd6102972014-05-07 19:57:49 +03001593
Daniele Ceraolo Spurio9dfe3452019-07-31 17:57:09 -07001594 intel_gt_runtime_suspend(&dev_priv->gt);
Alex Daia1c41992015-09-30 09:46:37 -07001595
Imre Deak2eb52522014-11-19 15:30:05 +02001596 intel_runtime_pm_disable_interrupts(dev_priv);
Imre Deakb5478bc2014-04-14 20:24:37 +03001597
Daniele Ceraolo Spuriof7de5022019-03-19 11:35:37 -07001598 intel_uncore_suspend(&dev_priv->uncore);
Hans de Goede01c799c2017-11-14 14:55:18 +01001599
Rodrigo Vivi071b68c2019-08-06 15:22:08 +03001600 intel_display_power_suspend(dev_priv);
1601
Jani Nikulafb5f4322020-02-12 16:40:57 +02001602 ret = vlv_suspend_complete(dev_priv);
Imre Deak0ab9cfe2014-04-15 16:39:45 +03001603 if (ret) {
Wambui Karuga00376cc2020-01-31 12:34:12 +03001604 drm_err(&dev_priv->drm,
1605 "Runtime suspend failed, disabling it (%d)\n", ret);
Daniele Ceraolo Spuriof7de5022019-03-19 11:35:37 -07001606 intel_uncore_runtime_resume(&dev_priv->uncore);
Hans de Goede01c799c2017-11-14 14:55:18 +01001607
Daniel Vetterb9632912014-09-30 10:56:44 +02001608 intel_runtime_pm_enable_interrupts(dev_priv);
Imre Deak0ab9cfe2014-04-15 16:39:45 +03001609
Daniele Ceraolo Spurio9dfe3452019-07-31 17:57:09 -07001610 intel_gt_runtime_resume(&dev_priv->gt);
Sagar Arun Kamble1ed21cb2018-01-24 21:16:57 +05301611
Chris Wilsone9d4c922019-10-16 15:32:33 +01001612 i915_gem_restore_fences(&dev_priv->ggtt);
Sagar Arun Kamble1ed21cb2018-01-24 21:16:57 +05301613
Daniele Ceraolo Spurio91026502019-06-13 16:21:51 -07001614 enable_rpm_wakeref_asserts(rpm);
Imre Deak1f814da2015-12-16 02:52:19 +02001615
Imre Deak0ab9cfe2014-04-15 16:39:45 +03001616 return ret;
1617 }
Paulo Zanonia8a8bd52014-03-07 20:08:05 -03001618
Daniele Ceraolo Spurio91026502019-06-13 16:21:51 -07001619 enable_rpm_wakeref_asserts(rpm);
Janusz Krzysztofik3b58a942019-07-12 13:24:28 +02001620 intel_runtime_pm_driver_release(rpm);
Mika Kuoppala55ec45c2015-12-15 16:25:08 +02001621
Daniele Ceraolo Spurio2cf7bf62019-03-25 14:49:34 -07001622 if (intel_uncore_arm_unclaimed_mmio_detection(&dev_priv->uncore))
Wambui Karuga00376cc2020-01-31 12:34:12 +03001623 drm_err(&dev_priv->drm,
1624 "Unclaimed access detected prior to suspending\n");
Mika Kuoppala55ec45c2015-12-15 16:25:08 +02001625
Daniele Ceraolo Spurio91026502019-06-13 16:21:51 -07001626 rpm->suspended = true;
Kristen Carlson Accardi1fb23622014-01-14 15:36:15 -08001627
1628 /*
Paulo Zanonic8a0bd42014-08-21 17:09:38 -03001629 * FIXME: We really should find a document that references the arguments
1630 * used below!
Kristen Carlson Accardi1fb23622014-01-14 15:36:15 -08001631 */
Chris Wilson6f9f4b72016-05-23 15:08:09 +01001632 if (IS_BROADWELL(dev_priv)) {
Paulo Zanonid37ae192015-07-30 18:20:29 -03001633 /*
1634 * On Broadwell, if we use PCI_D1 the PCH DDI ports will stop
1635 * being detected, and the call we do at intel_runtime_resume()
1636 * won't be able to restore them. Since PCI_D3hot matches the
1637 * actual specification and appears to be working, use it.
1638 */
Chris Wilson6f9f4b72016-05-23 15:08:09 +01001639 intel_opregion_notify_adapter(dev_priv, PCI_D3hot);
Paulo Zanonid37ae192015-07-30 18:20:29 -03001640 } else {
Paulo Zanonic8a0bd42014-08-21 17:09:38 -03001641 /*
1642 * current versions of firmware which depend on this opregion
1643 * notification have repurposed the D1 definition to mean
1644 * "runtime suspended" vs. what you would normally expect (D3)
1645 * to distinguish it from notifications that might be sent via
1646 * the suspend path.
1647 */
Chris Wilson6f9f4b72016-05-23 15:08:09 +01001648 intel_opregion_notify_adapter(dev_priv, PCI_D1);
Paulo Zanonic8a0bd42014-08-21 17:09:38 -03001649 }
Paulo Zanoni8a187452013-12-06 20:32:13 -02001650
Daniele Ceraolo Spuriof568eee2019-03-19 11:35:35 -07001651 assert_forcewakes_inactive(&dev_priv->uncore);
Chris Wilsondc9fb092015-01-16 11:34:34 +02001652
Ander Conselvan de Oliveira21d6e0b2017-01-20 16:28:43 +02001653 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv))
Lyude19625e82016-06-21 17:03:44 -04001654 intel_hpd_poll_init(dev_priv);
1655
Wambui Karuga00376cc2020-01-31 12:34:12 +03001656 drm_dbg_kms(&dev_priv->drm, "Device suspended\n");
Paulo Zanoni8a187452013-12-06 20:32:13 -02001657 return 0;
1658}
1659
David Weinehallc49d13e2016-08-22 13:32:42 +03001660static int intel_runtime_resume(struct device *kdev)
Paulo Zanoni8a187452013-12-06 20:32:13 -02001661{
Chris Wilson361f9dc2019-08-06 08:42:19 +01001662 struct drm_i915_private *dev_priv = kdev_to_i915(kdev);
Daniele Ceraolo Spurio1bf676c2019-06-13 16:21:52 -07001663 struct intel_runtime_pm *rpm = &dev_priv->runtime_pm;
Jani Nikulafb5f4322020-02-12 16:40:57 +02001664 int ret;
Paulo Zanoni8a187452013-12-06 20:32:13 -02001665
Pankaj Bharadiya48a1b8d2020-01-15 09:14:53 +05301666 if (drm_WARN_ON_ONCE(&dev_priv->drm, !HAS_RUNTIME_PM(dev_priv)))
Imre Deak604effb2014-08-26 13:26:56 +03001667 return -ENODEV;
Paulo Zanoni8a187452013-12-06 20:32:13 -02001668
Wambui Karuga00376cc2020-01-31 12:34:12 +03001669 drm_dbg_kms(&dev_priv->drm, "Resuming device\n");
Paulo Zanoni8a187452013-12-06 20:32:13 -02001670
Pankaj Bharadiya48a1b8d2020-01-15 09:14:53 +05301671 drm_WARN_ON_ONCE(&dev_priv->drm, atomic_read(&rpm->wakeref_count));
Daniele Ceraolo Spurio91026502019-06-13 16:21:51 -07001672 disable_rpm_wakeref_asserts(rpm);
Imre Deak1f814da2015-12-16 02:52:19 +02001673
Chris Wilson6f9f4b72016-05-23 15:08:09 +01001674 intel_opregion_notify_adapter(dev_priv, PCI_D0);
Daniele Ceraolo Spurio91026502019-06-13 16:21:51 -07001675 rpm->suspended = false;
Daniele Ceraolo Spurio2cf7bf62019-03-25 14:49:34 -07001676 if (intel_uncore_unclaimed_mmio(&dev_priv->uncore))
Wambui Karuga00376cc2020-01-31 12:34:12 +03001677 drm_dbg(&dev_priv->drm,
1678 "Unclaimed access during suspend, bios?\n");
Paulo Zanoni8a187452013-12-06 20:32:13 -02001679
Rodrigo Vivi071b68c2019-08-06 15:22:08 +03001680 intel_display_power_resume(dev_priv);
1681
Jani Nikulafb5f4322020-02-12 16:40:57 +02001682 ret = vlv_resume_prepare(dev_priv, true);
Paulo Zanoni1a5df182014-10-27 17:54:32 -02001683
Daniele Ceraolo Spuriof7de5022019-03-19 11:35:37 -07001684 intel_uncore_runtime_resume(&dev_priv->uncore);
Hans de Goedebedf4d72017-11-14 14:55:17 +01001685
Sagar Arun Kamble1ed21cb2018-01-24 21:16:57 +05301686 intel_runtime_pm_enable_interrupts(dev_priv);
1687
Imre Deak0ab9cfe2014-04-15 16:39:45 +03001688 /*
1689 * No point of rolling back things in case of an error, as the best
1690 * we can do is to hope that things will still work (and disable RPM).
1691 */
Daniele Ceraolo Spurio9dfe3452019-07-31 17:57:09 -07001692 intel_gt_runtime_resume(&dev_priv->gt);
Chris Wilsone9d4c922019-10-16 15:32:33 +01001693 i915_gem_restore_fences(&dev_priv->ggtt);
Imre Deak92b806d2014-04-14 20:24:39 +03001694
Ville Syrjälä08d8a232015-08-27 23:56:08 +03001695 /*
1696 * On VLV/CHV display interrupts are part of the display
1697 * power well, so hpd is reinitialized from there. For
1698 * everyone else do it here.
1699 */
Wayne Boyer666a4532015-12-09 12:29:35 -08001700 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv))
Ville Syrjälä08d8a232015-08-27 23:56:08 +03001701 intel_hpd_init(dev_priv);
1702
Kumar, Mahesh2503a0f2017-08-17 19:15:28 +05301703 intel_enable_ipc(dev_priv);
1704
Daniele Ceraolo Spurio91026502019-06-13 16:21:51 -07001705 enable_rpm_wakeref_asserts(rpm);
Imre Deak1f814da2015-12-16 02:52:19 +02001706
Imre Deak0ab9cfe2014-04-15 16:39:45 +03001707 if (ret)
Wambui Karuga00376cc2020-01-31 12:34:12 +03001708 drm_err(&dev_priv->drm,
1709 "Runtime resume failed, disabling it (%d)\n", ret);
Imre Deak0ab9cfe2014-04-15 16:39:45 +03001710 else
Wambui Karuga00376cc2020-01-31 12:34:12 +03001711 drm_dbg_kms(&dev_priv->drm, "Device resumed\n");
Imre Deak0ab9cfe2014-04-15 16:39:45 +03001712
1713 return ret;
Paulo Zanoni8a187452013-12-06 20:32:13 -02001714}
1715
Chris Wilson42f55512016-06-24 14:00:26 +01001716const struct dev_pm_ops i915_pm_ops = {
Imre Deak5545dbb2014-10-23 19:23:28 +03001717 /*
1718 * S0ix (via system suspend) and S3 event handlers [PMSG_SUSPEND,
1719 * PMSG_RESUME]
1720 */
Chris Wilson73b66f82018-05-25 10:26:29 +01001721 .prepare = i915_pm_prepare,
Akshay Joshi0206e352011-08-16 15:34:10 -04001722 .suspend = i915_pm_suspend,
Imre Deak76c4b252014-04-01 19:55:22 +03001723 .suspend_late = i915_pm_suspend_late,
1724 .resume_early = i915_pm_resume_early,
Akshay Joshi0206e352011-08-16 15:34:10 -04001725 .resume = i915_pm_resume,
Imre Deak5545dbb2014-10-23 19:23:28 +03001726
1727 /*
1728 * S4 event handlers
1729 * @freeze, @freeze_late : called (1) before creating the
1730 * hibernation image [PMSG_FREEZE] and
1731 * (2) after rebooting, before restoring
1732 * the image [PMSG_QUIESCE]
1733 * @thaw, @thaw_early : called (1) after creating the hibernation
1734 * image, before writing it [PMSG_THAW]
1735 * and (2) after failing to create or
1736 * restore the image [PMSG_RECOVER]
1737 * @poweroff, @poweroff_late: called after writing the hibernation
1738 * image, before rebooting [PMSG_HIBERNATE]
1739 * @restore, @restore_early : called after rebooting and restoring the
1740 * hibernation image [PMSG_RESTORE]
1741 */
Chris Wilson1f19ac22016-05-14 07:26:32 +01001742 .freeze = i915_pm_freeze,
1743 .freeze_late = i915_pm_freeze_late,
1744 .thaw_early = i915_pm_thaw_early,
1745 .thaw = i915_pm_thaw,
Imre Deak36d61e62014-10-23 19:23:24 +03001746 .poweroff = i915_pm_suspend,
Imre Deakab3be732015-03-02 13:04:41 +02001747 .poweroff_late = i915_pm_poweroff_late,
Chris Wilson1f19ac22016-05-14 07:26:32 +01001748 .restore_early = i915_pm_restore_early,
1749 .restore = i915_pm_restore,
Imre Deak5545dbb2014-10-23 19:23:28 +03001750
1751 /* S0ix (via runtime suspend) event handlers */
Paulo Zanoni97bea202014-03-07 20:12:33 -03001752 .runtime_suspend = intel_runtime_suspend,
1753 .runtime_resume = intel_runtime_resume,
Zhenyu Wangcbda12d2009-12-16 13:36:10 +08001754};
1755
Arjan van de Vene08e96d2011-10-31 07:28:57 -07001756static const struct file_operations i915_driver_fops = {
1757 .owner = THIS_MODULE,
1758 .open = drm_open,
Chris Wilson7a2c65dd2020-01-24 12:56:26 +00001759 .release = drm_release_noglobal,
Arjan van de Vene08e96d2011-10-31 07:28:57 -07001760 .unlocked_ioctl = drm_ioctl,
Abdiel Janulguecc662122019-12-04 12:00:32 +00001761 .mmap = i915_gem_mmap,
Arjan van de Vene08e96d2011-10-31 07:28:57 -07001762 .poll = drm_poll,
Arjan van de Vene08e96d2011-10-31 07:28:57 -07001763 .read = drm_read,
Arjan van de Vene08e96d2011-10-31 07:28:57 -07001764 .compat_ioctl = i915_compat_ioctl,
Arjan van de Vene08e96d2011-10-31 07:28:57 -07001765 .llseek = noop_llseek,
1766};
1767
Chris Wilson0673ad42016-06-24 14:00:22 +01001768static int
1769i915_gem_reject_pin_ioctl(struct drm_device *dev, void *data,
1770 struct drm_file *file)
1771{
1772 return -ENODEV;
1773}
1774
1775static const struct drm_ioctl_desc i915_ioctls[] = {
1776 DRM_IOCTL_DEF_DRV(I915_INIT, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
1777 DRM_IOCTL_DEF_DRV(I915_FLUSH, drm_noop, DRM_AUTH),
1778 DRM_IOCTL_DEF_DRV(I915_FLIP, drm_noop, DRM_AUTH),
1779 DRM_IOCTL_DEF_DRV(I915_BATCHBUFFER, drm_noop, DRM_AUTH),
1780 DRM_IOCTL_DEF_DRV(I915_IRQ_EMIT, drm_noop, DRM_AUTH),
1781 DRM_IOCTL_DEF_DRV(I915_IRQ_WAIT, drm_noop, DRM_AUTH),
Christian Königb972fff2019-04-17 13:25:24 +02001782 DRM_IOCTL_DEF_DRV(I915_GETPARAM, i915_getparam_ioctl, DRM_RENDER_ALLOW),
Chris Wilson0673ad42016-06-24 14:00:22 +01001783 DRM_IOCTL_DEF_DRV(I915_SETPARAM, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
1784 DRM_IOCTL_DEF_DRV(I915_ALLOC, drm_noop, DRM_AUTH),
1785 DRM_IOCTL_DEF_DRV(I915_FREE, drm_noop, DRM_AUTH),
1786 DRM_IOCTL_DEF_DRV(I915_INIT_HEAP, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
1787 DRM_IOCTL_DEF_DRV(I915_CMDBUFFER, drm_noop, DRM_AUTH),
1788 DRM_IOCTL_DEF_DRV(I915_DESTROY_HEAP, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
1789 DRM_IOCTL_DEF_DRV(I915_SET_VBLANK_PIPE, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
1790 DRM_IOCTL_DEF_DRV(I915_GET_VBLANK_PIPE, drm_noop, DRM_AUTH),
1791 DRM_IOCTL_DEF_DRV(I915_VBLANK_SWAP, drm_noop, DRM_AUTH),
1792 DRM_IOCTL_DEF_DRV(I915_HWS_ADDR, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
1793 DRM_IOCTL_DEF_DRV(I915_GEM_INIT, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
Ville Syrjälä6a20fe72018-02-07 18:48:41 +02001794 DRM_IOCTL_DEF_DRV(I915_GEM_EXECBUFFER, i915_gem_execbuffer_ioctl, DRM_AUTH),
Christian Königb972fff2019-04-17 13:25:24 +02001795 DRM_IOCTL_DEF_DRV(I915_GEM_EXECBUFFER2_WR, i915_gem_execbuffer2_ioctl, DRM_RENDER_ALLOW),
Chris Wilson0673ad42016-06-24 14:00:22 +01001796 DRM_IOCTL_DEF_DRV(I915_GEM_PIN, i915_gem_reject_pin_ioctl, DRM_AUTH|DRM_ROOT_ONLY),
1797 DRM_IOCTL_DEF_DRV(I915_GEM_UNPIN, i915_gem_reject_pin_ioctl, DRM_AUTH|DRM_ROOT_ONLY),
Christian Königb972fff2019-04-17 13:25:24 +02001798 DRM_IOCTL_DEF_DRV(I915_GEM_BUSY, i915_gem_busy_ioctl, DRM_RENDER_ALLOW),
Chris Wilson0673ad42016-06-24 14:00:22 +01001799 DRM_IOCTL_DEF_DRV(I915_GEM_SET_CACHING, i915_gem_set_caching_ioctl, DRM_RENDER_ALLOW),
1800 DRM_IOCTL_DEF_DRV(I915_GEM_GET_CACHING, i915_gem_get_caching_ioctl, DRM_RENDER_ALLOW),
Christian Königb972fff2019-04-17 13:25:24 +02001801 DRM_IOCTL_DEF_DRV(I915_GEM_THROTTLE, i915_gem_throttle_ioctl, DRM_RENDER_ALLOW),
Chris Wilson0673ad42016-06-24 14:00:22 +01001802 DRM_IOCTL_DEF_DRV(I915_GEM_ENTERVT, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
1803 DRM_IOCTL_DEF_DRV(I915_GEM_LEAVEVT, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
1804 DRM_IOCTL_DEF_DRV(I915_GEM_CREATE, i915_gem_create_ioctl, DRM_RENDER_ALLOW),
1805 DRM_IOCTL_DEF_DRV(I915_GEM_PREAD, i915_gem_pread_ioctl, DRM_RENDER_ALLOW),
1806 DRM_IOCTL_DEF_DRV(I915_GEM_PWRITE, i915_gem_pwrite_ioctl, DRM_RENDER_ALLOW),
1807 DRM_IOCTL_DEF_DRV(I915_GEM_MMAP, i915_gem_mmap_ioctl, DRM_RENDER_ALLOW),
Abdiel Janulguecc662122019-12-04 12:00:32 +00001808 DRM_IOCTL_DEF_DRV(I915_GEM_MMAP_OFFSET, i915_gem_mmap_offset_ioctl, DRM_RENDER_ALLOW),
Chris Wilson0673ad42016-06-24 14:00:22 +01001809 DRM_IOCTL_DEF_DRV(I915_GEM_SET_DOMAIN, i915_gem_set_domain_ioctl, DRM_RENDER_ALLOW),
1810 DRM_IOCTL_DEF_DRV(I915_GEM_SW_FINISH, i915_gem_sw_finish_ioctl, DRM_RENDER_ALLOW),
Chris Wilson111dbca2017-01-10 12:10:44 +00001811 DRM_IOCTL_DEF_DRV(I915_GEM_SET_TILING, i915_gem_set_tiling_ioctl, DRM_RENDER_ALLOW),
1812 DRM_IOCTL_DEF_DRV(I915_GEM_GET_TILING, i915_gem_get_tiling_ioctl, DRM_RENDER_ALLOW),
Chris Wilson0673ad42016-06-24 14:00:22 +01001813 DRM_IOCTL_DEF_DRV(I915_GEM_GET_APERTURE, i915_gem_get_aperture_ioctl, DRM_RENDER_ALLOW),
Ville Syrjälä6a20fe72018-02-07 18:48:41 +02001814 DRM_IOCTL_DEF_DRV(I915_GET_PIPE_FROM_CRTC_ID, intel_get_pipe_from_crtc_id_ioctl, 0),
Chris Wilson0673ad42016-06-24 14:00:22 +01001815 DRM_IOCTL_DEF_DRV(I915_GEM_MADVISE, i915_gem_madvise_ioctl, DRM_RENDER_ALLOW),
Daniel Vetter0cd54b02018-04-20 08:51:57 +02001816 DRM_IOCTL_DEF_DRV(I915_OVERLAY_PUT_IMAGE, intel_overlay_put_image_ioctl, DRM_MASTER),
1817 DRM_IOCTL_DEF_DRV(I915_OVERLAY_ATTRS, intel_overlay_attrs_ioctl, DRM_MASTER),
1818 DRM_IOCTL_DEF_DRV(I915_SET_SPRITE_COLORKEY, intel_sprite_set_colorkey_ioctl, DRM_MASTER),
1819 DRM_IOCTL_DEF_DRV(I915_GET_SPRITE_COLORKEY, drm_noop, DRM_MASTER),
Christian Königb972fff2019-04-17 13:25:24 +02001820 DRM_IOCTL_DEF_DRV(I915_GEM_WAIT, i915_gem_wait_ioctl, DRM_RENDER_ALLOW),
Chris Wilsonb9171542019-03-22 09:23:24 +00001821 DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_CREATE_EXT, i915_gem_context_create_ioctl, DRM_RENDER_ALLOW),
Chris Wilson0673ad42016-06-24 14:00:22 +01001822 DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_DESTROY, i915_gem_context_destroy_ioctl, DRM_RENDER_ALLOW),
1823 DRM_IOCTL_DEF_DRV(I915_REG_READ, i915_reg_read_ioctl, DRM_RENDER_ALLOW),
1824 DRM_IOCTL_DEF_DRV(I915_GET_RESET_STATS, i915_gem_context_reset_stats_ioctl, DRM_RENDER_ALLOW),
1825 DRM_IOCTL_DEF_DRV(I915_GEM_USERPTR, i915_gem_userptr_ioctl, DRM_RENDER_ALLOW),
1826 DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_GETPARAM, i915_gem_context_getparam_ioctl, DRM_RENDER_ALLOW),
1827 DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_SETPARAM, i915_gem_context_setparam_ioctl, DRM_RENDER_ALLOW),
Robert Braggeec688e2016-11-07 19:49:47 +00001828 DRM_IOCTL_DEF_DRV(I915_PERF_OPEN, i915_perf_open_ioctl, DRM_RENDER_ALLOW),
Emil Velikovb40237562019-05-22 16:47:01 +01001829 DRM_IOCTL_DEF_DRV(I915_PERF_ADD_CONFIG, i915_perf_add_config_ioctl, DRM_RENDER_ALLOW),
1830 DRM_IOCTL_DEF_DRV(I915_PERF_REMOVE_CONFIG, i915_perf_remove_config_ioctl, DRM_RENDER_ALLOW),
1831 DRM_IOCTL_DEF_DRV(I915_QUERY, i915_query_ioctl, DRM_RENDER_ALLOW),
Chris Wilson7f3f317a2019-05-21 22:11:25 +01001832 DRM_IOCTL_DEF_DRV(I915_GEM_VM_CREATE, i915_gem_vm_create_ioctl, DRM_RENDER_ALLOW),
1833 DRM_IOCTL_DEF_DRV(I915_GEM_VM_DESTROY, i915_gem_vm_destroy_ioctl, DRM_RENDER_ALLOW),
Chris Wilson0673ad42016-06-24 14:00:22 +01001834};
1835
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836static struct drm_driver driver = {
Michael Witten0c547812011-08-25 17:55:54 +00001837 /* Don't use MTRRs here; the Xserver or userspace app should
1838 * deal with them for Intel hardware.
Dave Airlie792d2b92005-11-11 23:30:27 +11001839 */
Eric Anholt673a3942008-07-30 12:06:12 -07001840 .driver_features =
Daniel Vetter0424fda2019-06-17 17:39:24 +02001841 DRIVER_GEM |
Jason Ekstrandcf6e7ba2017-08-15 15:57:33 +01001842 DRIVER_RENDER | DRIVER_MODESET | DRIVER_ATOMIC | DRIVER_SYNCOBJ,
Chris Wilsoncad36882017-02-10 16:35:21 +00001843 .release = i915_driver_release,
Eric Anholt673a3942008-07-30 12:06:12 -07001844 .open = i915_driver_open,
Dave Airlie22eae942005-11-10 22:16:34 +11001845 .lastclose = i915_driver_lastclose,
Eric Anholt673a3942008-07-30 12:06:12 -07001846 .postclose = i915_driver_postclose,
Rafael J. Wysockid8e29202010-01-09 00:45:33 +01001847
Chris Wilsonb1f788c2016-08-04 07:52:45 +01001848 .gem_close_object = i915_gem_close_object,
Chris Wilsonf0cd5182016-10-28 13:58:43 +01001849 .gem_free_object_unlocked = i915_gem_free_object,
Daniel Vetter1286ff72012-05-10 15:25:09 +02001850
1851 .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
1852 .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
1853 .gem_prime_export = i915_gem_prime_export,
1854 .gem_prime_import = i915_gem_prime_import,
1855
Ville Syrjälä7d23e592019-06-19 20:08:42 +03001856 .get_vblank_timestamp = drm_calc_vbltimestamp_from_scanoutpos,
1857 .get_scanout_position = i915_get_crtc_scanoutpos,
1858
Dave Airlieff72145b2011-02-07 12:16:14 +10001859 .dumb_create = i915_gem_dumb_create,
Abdiel Janulguecc662122019-12-04 12:00:32 +00001860 .dumb_map_offset = i915_gem_dumb_mmap_offset,
1861
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862 .ioctls = i915_ioctls,
Chris Wilson0673ad42016-06-24 14:00:22 +01001863 .num_ioctls = ARRAY_SIZE(i915_ioctls),
Arjan van de Vene08e96d2011-10-31 07:28:57 -07001864 .fops = &i915_driver_fops,
Dave Airlie22eae942005-11-10 22:16:34 +11001865 .name = DRIVER_NAME,
1866 .desc = DRIVER_DESC,
1867 .date = DRIVER_DATE,
1868 .major = DRIVER_MAJOR,
1869 .minor = DRIVER_MINOR,
1870 .patchlevel = DRIVER_PATCHLEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871};