blob: 8bd80a46ba0a87115b18c8d09a1c863eeb9aa4c6 [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>
Chris Wilson0673ad42016-06-24 14:00:22 +010041
Maarten Lankhorsta667fb42016-12-15 15:29:44 +010042#include <drm/drm_atomic_helper.h>
Sam Ravnborgd0e93592019-01-26 13:25:24 +010043#include <drm/drm_ioctl.h>
44#include <drm/drm_irq.h>
Daniel Vetter7fb81e92020-03-23 15:49:07 +010045#include <drm/drm_managed.h>
Sam Ravnborgd0e93592019-01-26 13:25:24 +010046#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"
Jani Nikuladf0566a2019-06-13 11:44:16 +030049#include "display/intel_bw.h"
50#include "display/intel_cdclk.h"
Jani Nikula06d3ff62020-02-11 18:14:50 +020051#include "display/intel_csr.h"
Jani Nikula1d455f82019-08-06 14:39:33 +030052#include "display/intel_display_types.h"
Jani Nikula379bc102019-06-13 11:44:15 +030053#include "display/intel_dp.h"
Jani Nikuladf0566a2019-06-13 11:44:16 +030054#include "display/intel_fbdev.h"
Jani Nikuladf0566a2019-06-13 11:44:16 +030055#include "display/intel_hotplug.h"
56#include "display/intel_overlay.h"
57#include "display/intel_pipe_crc.h"
Jani Nikula0bf1e5a2021-01-20 12:18:32 +020058#include "display/intel_pps.h"
Jani Nikuladf0566a2019-06-13 11:44:16 +030059#include "display/intel_sprite.h"
Jani Nikula4fb87832019-10-01 18:25:06 +030060#include "display/intel_vga.h"
Jani Nikula379bc102019-06-13 11:44:15 +030061
Chris Wilson10be98a2019-05-28 10:29:49 +010062#include "gem/i915_gem_context.h"
Chris Wilsonafa13082019-05-28 10:29:43 +010063#include "gem/i915_gem_ioctls.h"
Abdiel Janulguecc662122019-12-04 12:00:32 +000064#include "gem/i915_gem_mman.h"
Chris Wilson29d88082021-01-23 14:55:43 +000065#include "gem/i915_gem_pm.h"
Tvrtko Ursulin24635c52019-06-21 08:07:41 +010066#include "gt/intel_gt.h"
Chris Wilson79ffac852019-04-24 21:07:17 +010067#include "gt/intel_gt_pm.h"
Imre Deak2248a282019-10-17 16:38:31 +030068#include "gt/intel_rc6.h"
Chris Wilson112ed2d2019-04-24 18:48:39 +010069
Jani Nikula2126d3e2019-05-02 18:02:43 +030070#include "i915_debugfs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070071#include "i915_drv.h"
Jani Nikula062705b2020-02-27 19:00:45 +020072#include "i915_ioc32.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"
Jani Nikula6e482b92020-02-27 16:44:08 +020083#include "intel_gvt.h"
Chris Wilson3fc794f2019-10-26 21:20:32 +010084#include "intel_memory_region.h"
Jani Nikula696173b2019-04-05 14:00:15 +030085#include "intel_pm.h"
Matt Roperf9c730ed2020-09-30 23:39:17 -070086#include "intel_sideband.h"
Jani Nikulafb5f4322020-02-12 16:40:57 +020087#include "vlv_suspend.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Daniel Vetter70a59dd2020-11-04 11:04:24 +010089static const struct drm_driver driver;
Kristian Høgsberg112b7152009-01-04 16:55:33 -050090
Tvrtko Ursulinda5f53b2016-12-01 14:16:40 +000091static int i915_get_bridge_dev(struct drm_i915_private *dev_priv)
Chris Wilson0673ad42016-06-24 14:00:22 +010092{
Thomas Zimmermann8ff54462021-01-28 14:31:23 +010093 int domain = pci_domain_nr(to_pci_dev(dev_priv->drm.dev)->bus);
Sinan Kaya57b296462017-11-27 11:57:46 -050094
95 dev_priv->bridge_dev =
96 pci_get_domain_bus_and_slot(domain, 0, PCI_DEVFN(0, 0));
Chris Wilson0673ad42016-06-24 14:00:22 +010097 if (!dev_priv->bridge_dev) {
Wambui Karuga00376cc2020-01-31 12:34:12 +030098 drm_err(&dev_priv->drm, "bridge device not found\n");
Chris Wilson0673ad42016-06-24 14:00:22 +010099 return -1;
100 }
101 return 0;
102}
103
104/* Allocate space for the MCH regs if needed, return nonzero on error */
105static int
Tvrtko Ursulinda5f53b2016-12-01 14:16:40 +0000106intel_alloc_mchbar_resource(struct drm_i915_private *dev_priv)
Chris Wilson0673ad42016-06-24 14:00:22 +0100107{
Tvrtko Ursulin514e1d62016-11-04 14:42:48 +0000108 int reg = INTEL_GEN(dev_priv) >= 4 ? MCHBAR_I965 : MCHBAR_I915;
Chris Wilson0673ad42016-06-24 14:00:22 +0100109 u32 temp_lo, temp_hi = 0;
110 u64 mchbar_addr;
111 int ret;
112
Tvrtko Ursulin514e1d62016-11-04 14:42:48 +0000113 if (INTEL_GEN(dev_priv) >= 4)
Chris Wilson0673ad42016-06-24 14:00:22 +0100114 pci_read_config_dword(dev_priv->bridge_dev, reg + 4, &temp_hi);
115 pci_read_config_dword(dev_priv->bridge_dev, reg, &temp_lo);
116 mchbar_addr = ((u64)temp_hi << 32) | temp_lo;
117
118 /* If ACPI doesn't have it, assume we need to allocate it ourselves */
119#ifdef CONFIG_PNP
120 if (mchbar_addr &&
121 pnp_range_reserved(mchbar_addr, mchbar_addr + MCHBAR_SIZE))
122 return 0;
123#endif
124
125 /* Get some space for it */
126 dev_priv->mch_res.name = "i915 MCHBAR";
127 dev_priv->mch_res.flags = IORESOURCE_MEM;
128 ret = pci_bus_alloc_resource(dev_priv->bridge_dev->bus,
129 &dev_priv->mch_res,
130 MCHBAR_SIZE, MCHBAR_SIZE,
131 PCIBIOS_MIN_MEM,
132 0, pcibios_align_resource,
133 dev_priv->bridge_dev);
134 if (ret) {
Wambui Karuga00376cc2020-01-31 12:34:12 +0300135 drm_dbg(&dev_priv->drm, "failed bus alloc: %d\n", ret);
Chris Wilson0673ad42016-06-24 14:00:22 +0100136 dev_priv->mch_res.start = 0;
137 return ret;
138 }
139
Tvrtko Ursulin514e1d62016-11-04 14:42:48 +0000140 if (INTEL_GEN(dev_priv) >= 4)
Chris Wilson0673ad42016-06-24 14:00:22 +0100141 pci_write_config_dword(dev_priv->bridge_dev, reg + 4,
142 upper_32_bits(dev_priv->mch_res.start));
143
144 pci_write_config_dword(dev_priv->bridge_dev, reg,
145 lower_32_bits(dev_priv->mch_res.start));
146 return 0;
147}
148
149/* Setup MCHBAR if possible, return true if we should disable it again */
150static void
Tvrtko Ursulinda5f53b2016-12-01 14:16:40 +0000151intel_setup_mchbar(struct drm_i915_private *dev_priv)
Chris Wilson0673ad42016-06-24 14:00:22 +0100152{
Tvrtko Ursulin514e1d62016-11-04 14:42:48 +0000153 int mchbar_reg = INTEL_GEN(dev_priv) >= 4 ? MCHBAR_I965 : MCHBAR_I915;
Chris Wilson0673ad42016-06-24 14:00:22 +0100154 u32 temp;
155 bool enabled;
156
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100157 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Chris Wilson0673ad42016-06-24 14:00:22 +0100158 return;
159
160 dev_priv->mchbar_need_disable = false;
161
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +0100162 if (IS_I915G(dev_priv) || IS_I915GM(dev_priv)) {
Chris Wilson0673ad42016-06-24 14:00:22 +0100163 pci_read_config_dword(dev_priv->bridge_dev, DEVEN, &temp);
164 enabled = !!(temp & DEVEN_MCHBAR_EN);
165 } else {
166 pci_read_config_dword(dev_priv->bridge_dev, mchbar_reg, &temp);
167 enabled = temp & 1;
168 }
169
170 /* If it's already enabled, don't have to do anything */
171 if (enabled)
172 return;
173
Tvrtko Ursulinda5f53b2016-12-01 14:16:40 +0000174 if (intel_alloc_mchbar_resource(dev_priv))
Chris Wilson0673ad42016-06-24 14:00:22 +0100175 return;
176
177 dev_priv->mchbar_need_disable = true;
178
179 /* Space is allocated or reserved, so enable it. */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +0100180 if (IS_I915G(dev_priv) || IS_I915GM(dev_priv)) {
Chris Wilson0673ad42016-06-24 14:00:22 +0100181 pci_write_config_dword(dev_priv->bridge_dev, DEVEN,
182 temp | DEVEN_MCHBAR_EN);
183 } else {
184 pci_read_config_dword(dev_priv->bridge_dev, mchbar_reg, &temp);
185 pci_write_config_dword(dev_priv->bridge_dev, mchbar_reg, temp | 1);
186 }
187}
188
189static void
Tvrtko Ursulinda5f53b2016-12-01 14:16:40 +0000190intel_teardown_mchbar(struct drm_i915_private *dev_priv)
Chris Wilson0673ad42016-06-24 14:00:22 +0100191{
Tvrtko Ursulin514e1d62016-11-04 14:42:48 +0000192 int mchbar_reg = INTEL_GEN(dev_priv) >= 4 ? MCHBAR_I965 : MCHBAR_I915;
Chris Wilson0673ad42016-06-24 14:00:22 +0100193
194 if (dev_priv->mchbar_need_disable) {
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +0100195 if (IS_I915G(dev_priv) || IS_I915GM(dev_priv)) {
Chris Wilson0673ad42016-06-24 14:00:22 +0100196 u32 deven_val;
197
198 pci_read_config_dword(dev_priv->bridge_dev, DEVEN,
199 &deven_val);
200 deven_val &= ~DEVEN_MCHBAR_EN;
201 pci_write_config_dword(dev_priv->bridge_dev, DEVEN,
202 deven_val);
203 } else {
204 u32 mchbar_val;
205
206 pci_read_config_dword(dev_priv->bridge_dev, mchbar_reg,
207 &mchbar_val);
208 mchbar_val &= ~1;
209 pci_write_config_dword(dev_priv->bridge_dev, mchbar_reg,
210 mchbar_val);
211 }
212 }
213
214 if (dev_priv->mch_res.start)
215 release_resource(&dev_priv->mch_res);
216}
217
Chris Wilson0673ad42016-06-24 14:00:22 +0100218static int i915_workqueues_init(struct drm_i915_private *dev_priv)
219{
220 /*
221 * The i915 workqueue is primarily used for batched retirement of
222 * requests (and thus managing bo) once the task has been completed
Chris Wilsone61e0f52018-02-21 09:56:36 +0000223 * by the GPU. i915_retire_requests() is called directly when we
Chris Wilson0673ad42016-06-24 14:00:22 +0100224 * need high-priority retirement, such as waiting for an explicit
225 * bo.
226 *
227 * It is also used for periodic low-priority events, such as
228 * idle-timers and recording error state.
229 *
230 * All tasks on the workqueue are expected to acquire the dev mutex
231 * so there is no point in running more than one instance of the
232 * workqueue at any time. Use an ordered one.
233 */
234 dev_priv->wq = alloc_ordered_workqueue("i915", 0);
235 if (dev_priv->wq == NULL)
236 goto out_err;
237
238 dev_priv->hotplug.dp_wq = alloc_ordered_workqueue("i915-dp", 0);
239 if (dev_priv->hotplug.dp_wq == NULL)
240 goto out_free_wq;
241
Chris Wilson0673ad42016-06-24 14:00:22 +0100242 return 0;
243
Chris Wilson0673ad42016-06-24 14:00:22 +0100244out_free_wq:
245 destroy_workqueue(dev_priv->wq);
246out_err:
Wambui Karuga00376cc2020-01-31 12:34:12 +0300247 drm_err(&dev_priv->drm, "Failed to allocate workqueues.\n");
Chris Wilson0673ad42016-06-24 14:00:22 +0100248
249 return -ENOMEM;
250}
251
252static void i915_workqueues_cleanup(struct drm_i915_private *dev_priv)
253{
Chris Wilson0673ad42016-06-24 14:00:22 +0100254 destroy_workqueue(dev_priv->hotplug.dp_wq);
255 destroy_workqueue(dev_priv->wq);
256}
257
Paulo Zanoni4fc7e842016-09-26 15:07:52 +0300258/*
259 * We don't keep the workarounds for pre-production hardware, so we expect our
260 * driver to fail on these machines in one way or another. A little warning on
261 * dmesg may help both the user and the bug triagers.
Chris Wilson6a7a6a92017-11-17 10:26:35 +0000262 *
263 * Our policy for removing pre-production workarounds is to keep the
264 * current gen workarounds as a guide to the bring-up of the next gen
265 * (workarounds have a habit of persisting!). Anything older than that
266 * should be removed along with the complications they introduce.
Paulo Zanoni4fc7e842016-09-26 15:07:52 +0300267 */
268static void intel_detect_preproduction_hw(struct drm_i915_private *dev_priv)
269{
Chris Wilson248a1242017-01-30 10:44:56 +0000270 bool pre = false;
271
272 pre |= IS_HSW_EARLY_SDV(dev_priv);
273 pre |= IS_SKL_REVID(dev_priv, 0, SKL_REVID_F0);
Chris Wilson0102ba12017-01-30 10:44:58 +0000274 pre |= IS_BXT_REVID(dev_priv, 0, BXT_REVID_B_LAST);
Jani Nikulaef47b7a2021-03-26 15:21:34 +0200275 pre |= IS_KBL_GT_STEP(dev_priv, 0, STEP_A0);
Ville Syrjälä834c6bb2020-01-28 17:51:52 +0200276 pre |= IS_GLK_REVID(dev_priv, 0, GLK_REVID_A2);
Chris Wilson248a1242017-01-30 10:44:56 +0000277
Chris Wilson7c5ff4a2017-01-30 10:44:57 +0000278 if (pre) {
Wambui Karuga00376cc2020-01-31 12:34:12 +0300279 drm_err(&dev_priv->drm, "This is a pre-production stepping. "
Paulo Zanoni4fc7e842016-09-26 15:07:52 +0300280 "It may not be fully functional.\n");
Chris Wilson7c5ff4a2017-01-30 10:44:57 +0000281 add_taint(TAINT_MACHINE_CHECK, LOCKDEP_STILL_OK);
282 }
Paulo Zanoni4fc7e842016-09-26 15:07:52 +0300283}
284
Chris Wilson640b50f2019-12-28 11:12:55 +0000285static void sanitize_gpu(struct drm_i915_private *i915)
286{
287 if (!INTEL_INFO(i915)->gpu_reset_clobbers_display)
288 __intel_gt_reset(&i915->gt, ALL_ENGINES);
289}
290
Chris Wilson0673ad42016-06-24 14:00:22 +0100291/**
Janusz Krzysztofik0b61b8b2019-07-12 13:24:30 +0200292 * i915_driver_early_probe - setup state not requiring device access
Chris Wilson0673ad42016-06-24 14:00:22 +0100293 * @dev_priv: device private
294 *
295 * Initialize everything that is a "SW-only" state, that is state not
296 * requiring accessing the device or exposing the driver via kernel internal
297 * or userspace interfaces. Example steps belonging here: lock initialization,
298 * system memory allocation, setting up device specific attributes and
299 * function hooks not requiring accessing the device.
300 */
Janusz Krzysztofik0b61b8b2019-07-12 13:24:30 +0200301static int i915_driver_early_probe(struct drm_i915_private *dev_priv)
Chris Wilson0673ad42016-06-24 14:00:22 +0100302{
Chris Wilson0673ad42016-06-24 14:00:22 +0100303 int ret = 0;
304
Michal Wajdeczko50d84412019-08-02 18:40:50 +0000305 if (i915_inject_probe_failure(dev_priv))
Chris Wilson0673ad42016-06-24 14:00:22 +0100306 return -ENODEV;
307
Tvrtko Ursulin805446c2019-03-27 14:23:28 +0000308 intel_device_info_subplatform_init(dev_priv);
Jani Nikulaef47b7a2021-03-26 15:21:34 +0200309 intel_step_init(dev_priv);
Tvrtko Ursulin805446c2019-03-27 14:23:28 +0000310
Daniele Ceraolo Spurio0a9b2632019-08-09 07:31:16 +0100311 intel_uncore_mmio_debug_init_early(&dev_priv->mmio_debug);
Daniele Ceraolo Spurio01385752019-06-19 18:00:18 -0700312 intel_uncore_init_early(&dev_priv->uncore, dev_priv);
Daniele Ceraolo Spurio6cbe88302019-04-02 13:10:31 -0700313
Chris Wilson0673ad42016-06-24 14:00:22 +0100314 spin_lock_init(&dev_priv->irq_lock);
315 spin_lock_init(&dev_priv->gpu_error.lock);
316 mutex_init(&dev_priv->backlight_lock);
Lyude317eaa92017-02-03 21:18:25 -0500317
Chris Wilson0673ad42016-06-24 14:00:22 +0100318 mutex_init(&dev_priv->sb_lock);
Rafael J. Wysocki4d4dda42020-02-12 00:12:10 +0100319 cpu_latency_qos_add_request(&dev_priv->sb_qos, PM_QOS_DEFAULT_VALUE);
Chris Wilsona75d0352019-04-26 09:17:18 +0100320
Chris Wilson0673ad42016-06-24 14:00:22 +0100321 mutex_init(&dev_priv->av_mutex);
322 mutex_init(&dev_priv->wm.wm_mutex);
323 mutex_init(&dev_priv->pps_mutex);
Ramalingam C9055aac2019-02-16 23:06:51 +0530324 mutex_init(&dev_priv->hdcp_comp_mutex);
Chris Wilson0673ad42016-06-24 14:00:22 +0100325
Chris Wilson0b1de5d2016-08-12 12:39:59 +0100326 i915_memcpy_init_early(dev_priv);
Daniele Ceraolo Spurio69c66352019-06-13 16:21:53 -0700327 intel_runtime_pm_init_early(&dev_priv->runtime_pm);
Chris Wilson0b1de5d2016-08-12 12:39:59 +0100328
Chris Wilson0673ad42016-06-24 14:00:22 +0100329 ret = i915_workqueues_init(dev_priv);
330 if (ret < 0)
Chris Wilsonf3bcb0c2019-07-18 08:00:10 +0100331 return ret;
Chris Wilson0673ad42016-06-24 14:00:22 +0100332
Jani Nikulafb5f4322020-02-12 16:40:57 +0200333 ret = vlv_suspend_init(dev_priv);
Daniele Ceraolo Spurio1bcd8682019-08-19 19:01:46 -0700334 if (ret < 0)
335 goto err_workqueues;
336
Daniele Ceraolo Spurio6f760982019-07-31 17:57:08 -0700337 intel_wopcm_init_early(&dev_priv->wopcm);
338
Tvrtko Ursulin724e9562019-06-21 08:07:42 +0100339 intel_gt_init_early(&dev_priv->gt, dev_priv);
Tvrtko Ursulin24635c52019-06-21 08:07:41 +0100340
Matthew Aulda3f356b2019-09-27 18:33:49 +0100341 i915_gem_init_early(dev_priv);
Michal Wajdeczkoa0de9082018-03-23 12:34:49 +0000342
Chris Wilson0673ad42016-06-24 14:00:22 +0100343 /* This must be called before any calls to HAS_PCH_* */
Tvrtko Ursulinda5f53b2016-12-01 14:16:40 +0000344 intel_detect_pch(dev_priv);
Chris Wilson0673ad42016-06-24 14:00:22 +0100345
Tvrtko Ursulin192aa182016-12-01 14:16:45 +0000346 intel_pm_setup(dev_priv);
Imre Deakf28ec6f2018-08-06 12:58:37 +0300347 ret = intel_power_domains_init(dev_priv);
348 if (ret < 0)
Daniele Ceraolo Spurio6f760982019-07-31 17:57:08 -0700349 goto err_gem;
Chris Wilson0673ad42016-06-24 14:00:22 +0100350 intel_irq_init(dev_priv);
351 intel_init_display_hooks(dev_priv);
352 intel_init_clock_gating_hooks(dev_priv);
Chris Wilson0673ad42016-06-24 14:00:22 +0100353
Paulo Zanoni4fc7e842016-09-26 15:07:52 +0300354 intel_detect_preproduction_hw(dev_priv);
Chris Wilson0673ad42016-06-24 14:00:22 +0100355
356 return 0;
357
Daniele Ceraolo Spurio6f760982019-07-31 17:57:08 -0700358err_gem:
Imre Deakf28ec6f2018-08-06 12:58:37 +0300359 i915_gem_cleanup_early(dev_priv);
Daniele Ceraolo Spurio6cf72db2019-07-31 17:57:07 -0700360 intel_gt_driver_late_release(&dev_priv->gt);
Jani Nikulafb5f4322020-02-12 16:40:57 +0200361 vlv_suspend_cleanup(dev_priv);
Daniele Ceraolo Spurio1bcd8682019-08-19 19:01:46 -0700362err_workqueues:
Chris Wilson0673ad42016-06-24 14:00:22 +0100363 i915_workqueues_cleanup(dev_priv);
364 return ret;
365}
366
367/**
Janusz Krzysztofik3b58a942019-07-12 13:24:28 +0200368 * i915_driver_late_release - cleanup the setup done in
Janusz Krzysztofik0b61b8b2019-07-12 13:24:30 +0200369 * i915_driver_early_probe()
Chris Wilson0673ad42016-06-24 14:00:22 +0100370 * @dev_priv: device private
371 */
Janusz Krzysztofik3b58a942019-07-12 13:24:28 +0200372static void i915_driver_late_release(struct drm_i915_private *dev_priv)
Chris Wilson0673ad42016-06-24 14:00:22 +0100373{
Joonas Lahtinencefcff82017-04-28 10:58:39 +0300374 intel_irq_fini(dev_priv);
Imre Deakf28ec6f2018-08-06 12:58:37 +0300375 intel_power_domains_cleanup(dev_priv);
Michal Wajdeczkoa0de9082018-03-23 12:34:49 +0000376 i915_gem_cleanup_early(dev_priv);
Daniele Ceraolo Spurio6cf72db2019-07-31 17:57:07 -0700377 intel_gt_driver_late_release(&dev_priv->gt);
Jani Nikulafb5f4322020-02-12 16:40:57 +0200378 vlv_suspend_cleanup(dev_priv);
Chris Wilson0673ad42016-06-24 14:00:22 +0100379 i915_workqueues_cleanup(dev_priv);
Chris Wilsona75d0352019-04-26 09:17:18 +0100380
Rafael J. Wysocki4d4dda42020-02-12 00:12:10 +0100381 cpu_latency_qos_remove_request(&dev_priv->sb_qos);
Chris Wilsona75d0352019-04-26 09:17:18 +0100382 mutex_destroy(&dev_priv->sb_lock);
Jani Nikula8a25c4b2020-06-18 18:04:02 +0300383
384 i915_params_free(&dev_priv->params);
Chris Wilson0673ad42016-06-24 14:00:22 +0100385}
386
Chris Wilson0673ad42016-06-24 14:00:22 +0100387/**
Janusz Krzysztofik0b61b8b2019-07-12 13:24:30 +0200388 * i915_driver_mmio_probe - setup device MMIO
Chris Wilson0673ad42016-06-24 14:00:22 +0100389 * @dev_priv: device private
390 *
391 * Setup minimal device state necessary for MMIO accesses later in the
392 * initialization sequence. The setup here should avoid any other device-wide
393 * side effects or exposing the driver via kernel internal or user space
394 * interfaces.
395 */
Janusz Krzysztofik0b61b8b2019-07-12 13:24:30 +0200396static int i915_driver_mmio_probe(struct drm_i915_private *dev_priv)
Chris Wilson0673ad42016-06-24 14:00:22 +0100397{
Chris Wilson0673ad42016-06-24 14:00:22 +0100398 int ret;
399
Michal Wajdeczko50d84412019-08-02 18:40:50 +0000400 if (i915_inject_probe_failure(dev_priv))
Chris Wilson0673ad42016-06-24 14:00:22 +0100401 return -ENODEV;
402
Tvrtko Ursulinda5f53b2016-12-01 14:16:40 +0000403 if (i915_get_bridge_dev(dev_priv))
Chris Wilson0673ad42016-06-24 14:00:22 +0100404 return -EIO;
405
Daniele Ceraolo Spurio3de6f852019-04-02 13:10:32 -0700406 ret = intel_uncore_init_mmio(&dev_priv->uncore);
Chris Wilson0673ad42016-06-24 14:00:22 +0100407 if (ret < 0)
Joonas Lahtinen63ffbcd2017-04-28 10:53:36 +0300408 goto err_bridge;
Chris Wilson0673ad42016-06-24 14:00:22 +0100409
Daniele Ceraolo Spurio25286aa2019-03-19 11:35:40 -0700410 /* Try to make sure MCHBAR is enabled before poking at it */
411 intel_setup_mchbar(dev_priv);
Chris Wilsonc864e9a2021-01-04 11:51:41 +0000412 intel_device_info_runtime_init(dev_priv);
Joonas Lahtinen63ffbcd2017-04-28 10:53:36 +0300413
Daniele Ceraolo Spuriod0eb6862020-07-07 17:39:48 -0700414 ret = intel_gt_init_mmio(&dev_priv->gt);
Joonas Lahtinen63ffbcd2017-04-28 10:53:36 +0300415 if (ret)
416 goto err_uncore;
417
Chris Wilson640b50f2019-12-28 11:12:55 +0000418 /* As early as possible, scrub existing GPU state before clobbering */
419 sanitize_gpu(dev_priv);
420
Chris Wilson0673ad42016-06-24 14:00:22 +0100421 return 0;
422
Joonas Lahtinen63ffbcd2017-04-28 10:53:36 +0300423err_uncore:
Daniele Ceraolo Spurio25286aa2019-03-19 11:35:40 -0700424 intel_teardown_mchbar(dev_priv);
Daniele Ceraolo Spurio3de6f852019-04-02 13:10:32 -0700425 intel_uncore_fini_mmio(&dev_priv->uncore);
Joonas Lahtinen63ffbcd2017-04-28 10:53:36 +0300426err_bridge:
Chris Wilson0673ad42016-06-24 14:00:22 +0100427 pci_dev_put(dev_priv->bridge_dev);
428
429 return ret;
430}
431
432/**
Janusz Krzysztofik0b61b8b2019-07-12 13:24:30 +0200433 * i915_driver_mmio_release - cleanup the setup done in i915_driver_mmio_probe()
Chris Wilson0673ad42016-06-24 14:00:22 +0100434 * @dev_priv: device private
435 */
Janusz Krzysztofik3b58a942019-07-12 13:24:28 +0200436static void i915_driver_mmio_release(struct drm_i915_private *dev_priv)
Chris Wilson0673ad42016-06-24 14:00:22 +0100437{
Daniele Ceraolo Spurio25286aa2019-03-19 11:35:40 -0700438 intel_teardown_mchbar(dev_priv);
Daniele Ceraolo Spurio3de6f852019-04-02 13:10:32 -0700439 intel_uncore_fini_mmio(&dev_priv->uncore);
Chris Wilson0673ad42016-06-24 14:00:22 +0100440 pci_dev_put(dev_priv->bridge_dev);
441}
442
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100443static void intel_sanitize_options(struct drm_i915_private *dev_priv)
444{
Chuanxiao Dong67b7f332017-05-27 17:44:17 +0800445 intel_gvt_sanitize_options(dev_priv);
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100446}
447
Chris Wilson0673ad42016-06-24 14:00:22 +0100448/**
Michael J. Ruhl31a02eb2020-04-17 15:51:07 -0400449 * i915_set_dma_info - set all relevant PCI dma info as configured for the
450 * platform
451 * @i915: valid i915 instance
452 *
453 * Set the dma max segment size, device and coherent masks. The dma mask set
454 * needs to occur before i915_ggtt_probe_hw.
455 *
456 * A couple of platforms have special needs. Address them as well.
457 *
458 */
459static int i915_set_dma_info(struct drm_i915_private *i915)
460{
Michael J. Ruhl31a02eb2020-04-17 15:51:07 -0400461 unsigned int mask_size = INTEL_INFO(i915)->dma_mask_size;
462 int ret;
463
464 GEM_BUG_ON(!mask_size);
465
466 /*
467 * We don't have a max segment size, so set it to the max so sg's
468 * debugging layer doesn't complain
469 */
Thomas Zimmermann8ff54462021-01-28 14:31:23 +0100470 dma_set_max_seg_size(i915->drm.dev, UINT_MAX);
Michael J. Ruhl31a02eb2020-04-17 15:51:07 -0400471
Thomas Zimmermann8ff54462021-01-28 14:31:23 +0100472 ret = dma_set_mask(i915->drm.dev, DMA_BIT_MASK(mask_size));
Michael J. Ruhl31a02eb2020-04-17 15:51:07 -0400473 if (ret)
474 goto mask_err;
475
476 /* overlay on gen2 is broken and can't address above 1G */
477 if (IS_GEN(i915, 2))
478 mask_size = 30;
479
480 /*
481 * 965GM sometimes incorrectly writes to hardware status page (HWS)
482 * using 32bit addressing, overwriting memory if HWS is located
483 * above 4GB.
484 *
485 * The documentation also mentions an issue with undefined
486 * behaviour if any general state is accessed within a page above 4GB,
487 * which also needs to be handled carefully.
488 */
489 if (IS_I965G(i915) || IS_I965GM(i915))
490 mask_size = 32;
491
Thomas Zimmermann8ff54462021-01-28 14:31:23 +0100492 ret = dma_set_coherent_mask(i915->drm.dev, DMA_BIT_MASK(mask_size));
Michael J. Ruhl31a02eb2020-04-17 15:51:07 -0400493 if (ret)
494 goto mask_err;
495
496 return 0;
497
498mask_err:
499 drm_err(&i915->drm, "Can't set DMA mask/consistent mask (%d)\n", ret);
500 return ret;
501}
502
503/**
Janusz Krzysztofik0b61b8b2019-07-12 13:24:30 +0200504 * i915_driver_hw_probe - setup state requiring device access
Chris Wilson0673ad42016-06-24 14:00:22 +0100505 * @dev_priv: device private
506 *
507 * Setup state that requires accessing the device, but doesn't require
508 * exposing the driver via kernel internal or userspace interfaces.
509 */
Janusz Krzysztofik0b61b8b2019-07-12 13:24:30 +0200510static int i915_driver_hw_probe(struct drm_i915_private *dev_priv)
Chris Wilson0673ad42016-06-24 14:00:22 +0100511{
Thomas Zimmermann8ff54462021-01-28 14:31:23 +0100512 struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev);
Chris Wilson0673ad42016-06-24 14:00:22 +0100513 int ret;
514
Michal Wajdeczko50d84412019-08-02 18:40:50 +0000515 if (i915_inject_probe_failure(dev_priv))
Chris Wilson0673ad42016-06-24 14:00:22 +0100516 return -ENODEV;
517
Chris Wilson4bdafb92018-09-26 21:12:22 +0100518 if (HAS_PPGTT(dev_priv)) {
519 if (intel_vgpu_active(dev_priv) &&
Chris Wilsonca6ac682019-03-14 22:38:35 +0000520 !intel_vgpu_has_full_ppgtt(dev_priv)) {
Chris Wilson4bdafb92018-09-26 21:12:22 +0100521 i915_report_error(dev_priv,
522 "incompatible vGPU found, support for isolated ppGTT required\n");
523 return -ENXIO;
524 }
525 }
526
Chris Wilson46592892018-11-30 12:59:54 +0000527 if (HAS_EXECLISTS(dev_priv)) {
528 /*
529 * Older GVT emulation depends upon intercepting CSB mmio,
530 * which we no longer use, preferring to use the HWSP cache
531 * instead.
532 */
533 if (intel_vgpu_active(dev_priv) &&
534 !intel_vgpu_has_hwsp_emulation(dev_priv)) {
535 i915_report_error(dev_priv,
536 "old vGPU host found, support for HWSP emulation required\n");
537 return -ENXIO;
538 }
539 }
540
Chris Wilson94b4f3b2016-07-05 10:40:20 +0100541 intel_sanitize_options(dev_priv);
Chris Wilson0673ad42016-06-24 14:00:22 +0100542
Daniele Ceraolo Spuriof6ac9932019-03-28 10:45:32 -0700543 /* needs to be done before ggtt probe */
Jani Nikulad28ae3b2020-02-25 13:15:07 +0200544 intel_dram_edram_detect(dev_priv);
Daniele Ceraolo Spuriof6ac9932019-03-28 10:45:32 -0700545
Michael J. Ruhl31a02eb2020-04-17 15:51:07 -0400546 ret = i915_set_dma_info(dev_priv);
547 if (ret)
548 return ret;
549
Lionel Landwerlin9f9b2792017-10-27 15:59:31 +0100550 i915_perf_init(dev_priv);
551
Chris Wilson97d6d7a2016-08-04 07:52:22 +0100552 ret = i915_ggtt_probe_hw(dev_priv);
Chris Wilson0673ad42016-06-24 14:00:22 +0100553 if (ret)
Chris Wilson9f172f62018-04-14 10:12:33 +0100554 goto err_perf;
Chris Wilson0673ad42016-06-24 14:00:22 +0100555
Gerd Hoffmannf2521f72019-08-22 11:06:45 +0200556 ret = drm_fb_helper_remove_conflicting_pci_framebuffers(pdev, "inteldrmfb");
557 if (ret)
Chris Wilson9f172f62018-04-14 10:12:33 +0100558 goto err_ggtt;
Chris Wilson0673ad42016-06-24 14:00:22 +0100559
Chris Wilson97d6d7a2016-08-04 07:52:22 +0100560 ret = i915_ggtt_init_hw(dev_priv);
Chris Wilson0088e522016-08-04 07:52:21 +0100561 if (ret)
Chris Wilson9f172f62018-04-14 10:12:33 +0100562 goto err_ggtt;
Chris Wilson0088e522016-08-04 07:52:21 +0100563
Chris Wilson3fc794f2019-10-26 21:20:32 +0100564 ret = intel_memory_regions_hw_probe(dev_priv);
565 if (ret)
566 goto err_ggtt;
567
Chris Wilson797a6152019-11-01 14:10:06 +0000568 intel_gt_init_hw_early(&dev_priv->gt, &dev_priv->ggtt);
Tvrtko Ursulind8a44242019-06-21 08:08:06 +0100569
Chris Wilson97d6d7a2016-08-04 07:52:22 +0100570 ret = i915_ggtt_enable_hw(dev_priv);
Chris Wilson0088e522016-08-04 07:52:21 +0100571 if (ret) {
Wambui Karuga00376cc2020-01-31 12:34:12 +0300572 drm_err(&dev_priv->drm, "failed to enable GGTT\n");
Chris Wilson3fc794f2019-10-26 21:20:32 +0100573 goto err_mem_regions;
Chris Wilson0088e522016-08-04 07:52:21 +0100574 }
575
David Weinehall52a05c32016-08-22 13:32:44 +0300576 pci_set_master(pdev);
Chris Wilson0673ad42016-06-24 14:00:22 +0100577
Tvrtko Ursulin25d140f2018-12-03 13:33:19 +0000578 intel_gt_init_workarounds(dev_priv);
Chris Wilson0673ad42016-06-24 14:00:22 +0100579
580 /* On the 945G/GM, the chipset reports the MSI capability on the
581 * integrated graphics even though the support isn't actually there
582 * according to the published specs. It doesn't appear to function
583 * correctly in testing on 945G.
584 * This may be a side effect of MSI having been made available for PEG
585 * and the registers being closely associated.
586 *
587 * According to chipset errata, on the 965GM, MSI interrupts may
Ville Syrjäläe38c2da2017-06-26 23:30:51 +0300588 * be lost or delayed, and was defeatured. MSI interrupts seem to
589 * get lost on g4x as well, and interrupt delivery seems to stay
590 * properly dead afterwards. So we'll just disable them for all
591 * pre-gen5 chipsets.
Lucas De Marchi8a29c772018-05-23 11:04:35 -0700592 *
593 * dp aux and gmbus irq on gen4 seems to be able to generate legacy
594 * interrupts even when in MSI mode. This results in spurious
595 * interrupt warnings if the legacy irq no. is shared with another
596 * device. The kernel then disables that interrupt source and so
597 * prevents the other device from working properly.
Chris Wilson0673ad42016-06-24 14:00:22 +0100598 */
Ville Syrjäläe38c2da2017-06-26 23:30:51 +0300599 if (INTEL_GEN(dev_priv) >= 5) {
David Weinehall52a05c32016-08-22 13:32:44 +0300600 if (pci_enable_msi(pdev) < 0)
Wambui Karuga00376cc2020-01-31 12:34:12 +0300601 drm_dbg(&dev_priv->drm, "can't enable MSI");
Chris Wilson0673ad42016-06-24 14:00:22 +0100602 }
603
Zhenyu Wang26f837e2017-01-13 10:46:09 +0800604 ret = intel_gvt_init(dev_priv);
605 if (ret)
Chris Wilson7ab87ed2018-07-10 15:38:21 +0100606 goto err_msi;
607
608 intel_opregion_setup(dev_priv);
José Roberto de Souza5d0c9382021-01-28 08:43:11 -0800609
610 intel_pcode_init(dev_priv);
611
Mahesh Kumarcbfa59d2018-08-24 15:02:21 +0530612 /*
José Roberto de Souzaf0b29702021-01-28 08:43:10 -0800613 * Fill the dram structure to get the system dram info. This will be
614 * used for memory latency calculation.
Mahesh Kumarcbfa59d2018-08-24 15:02:21 +0530615 */
Jani Nikulad28ae3b2020-02-25 13:15:07 +0200616 intel_dram_detect(dev_priv);
Mahesh Kumarcbfa59d2018-08-24 15:02:21 +0530617
Ville Syrjäläc457d9c2019-05-24 18:36:14 +0300618 intel_bw_init_hw(dev_priv);
Zhenyu Wang26f837e2017-01-13 10:46:09 +0800619
Chris Wilson0673ad42016-06-24 14:00:22 +0100620 return 0;
621
Chris Wilson7ab87ed2018-07-10 15:38:21 +0100622err_msi:
623 if (pdev->msi_enabled)
624 pci_disable_msi(pdev);
Chris Wilson3fc794f2019-10-26 21:20:32 +0100625err_mem_regions:
626 intel_memory_regions_driver_release(dev_priv);
Chris Wilson9f172f62018-04-14 10:12:33 +0100627err_ggtt:
Janusz Krzysztofik3b58a942019-07-12 13:24:28 +0200628 i915_ggtt_driver_release(dev_priv);
Chris Wilson9f172f62018-04-14 10:12:33 +0100629err_perf:
630 i915_perf_fini(dev_priv);
Chris Wilson0673ad42016-06-24 14:00:22 +0100631 return ret;
632}
633
634/**
Janusz Krzysztofik78dae1a2019-07-12 13:24:29 +0200635 * i915_driver_hw_remove - cleanup the setup done in i915_driver_hw_probe()
Chris Wilson0673ad42016-06-24 14:00:22 +0100636 * @dev_priv: device private
637 */
Janusz Krzysztofik78dae1a2019-07-12 13:24:29 +0200638static void i915_driver_hw_remove(struct drm_i915_private *dev_priv)
Chris Wilson0673ad42016-06-24 14:00:22 +0100639{
Thomas Zimmermann8ff54462021-01-28 14:31:23 +0100640 struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev);
Chris Wilson0673ad42016-06-24 14:00:22 +0100641
Lionel Landwerlin9f9b2792017-10-27 15:59:31 +0100642 i915_perf_fini(dev_priv);
643
David Weinehall52a05c32016-08-22 13:32:44 +0300644 if (pdev->msi_enabled)
645 pci_disable_msi(pdev);
Chris Wilson0673ad42016-06-24 14:00:22 +0100646}
647
648/**
649 * i915_driver_register - register the driver with the rest of the system
650 * @dev_priv: device private
651 *
652 * Perform any steps necessary to make the driver available via kernel
653 * internal or userspace interfaces.
654 */
655static void i915_driver_register(struct drm_i915_private *dev_priv)
656{
Chris Wilson91c8a322016-07-05 10:40:23 +0100657 struct drm_device *dev = &dev_priv->drm;
Chris Wilson0673ad42016-06-24 14:00:22 +0100658
Chris Wilsonc29579d2019-08-06 13:42:59 +0100659 i915_gem_driver_register(dev_priv);
Tvrtko Ursulinb46a33e2017-11-21 18:18:45 +0000660 i915_pmu_register(dev_priv);
Chris Wilson0673ad42016-06-24 14:00:22 +0100661
Jani Nikula9e859eb2020-02-27 16:44:06 +0200662 intel_vgpu_register(dev_priv);
Chris Wilson0673ad42016-06-24 14:00:22 +0100663
664 /* Reveal our presence to userspace */
Lucas De Marchiec3e00b2021-02-12 20:27:53 -0800665 if (drm_dev_register(dev, 0)) {
Wambui Karuga00376cc2020-01-31 12:34:12 +0300666 drm_err(&dev_priv->drm,
667 "Failed to register driver for userspace access!\n");
Lucas De Marchiec3e00b2021-02-12 20:27:53 -0800668 return;
669 }
670
671 i915_debugfs_register(dev_priv);
Lucas De Marchiec3e00b2021-02-12 20:27:53 -0800672 i915_setup_sysfs(dev_priv);
673
674 /* Depends on sysfs having been initialized */
675 i915_perf_register(dev_priv);
Chris Wilson0673ad42016-06-24 14:00:22 +0100676
Lucas De Marchief7eff12021-02-12 20:27:54 -0800677 intel_gt_driver_register(&dev_priv->gt);
678
Lucas De Marchi141b4152021-02-12 20:27:55 -0800679 intel_display_driver_register(dev_priv);
Chris Wilson07d80572018-08-16 15:37:56 +0300680
Imre Deak2cd9a682018-08-16 15:37:57 +0300681 intel_power_domains_enable(dev_priv);
Daniele Ceraolo Spurio69c66352019-06-13 16:21:53 -0700682 intel_runtime_pm_enable(&dev_priv->runtime_pm);
Jani Nikula46edcdb2020-02-11 18:28:01 +0200683
684 intel_register_dsm_handler();
685
686 if (i915_switcheroo_register(dev_priv))
687 drm_err(&dev_priv->drm, "Failed to register vga switcheroo!\n");
Chris Wilson0673ad42016-06-24 14:00:22 +0100688}
689
690/**
691 * i915_driver_unregister - cleanup the registration done in i915_driver_regiser()
692 * @dev_priv: device private
693 */
694static void i915_driver_unregister(struct drm_i915_private *dev_priv)
695{
Jani Nikula46edcdb2020-02-11 18:28:01 +0200696 i915_switcheroo_unregister(dev_priv);
697
698 intel_unregister_dsm_handler();
699
Daniele Ceraolo Spurio69c66352019-06-13 16:21:53 -0700700 intel_runtime_pm_disable(&dev_priv->runtime_pm);
Imre Deak2cd9a682018-08-16 15:37:57 +0300701 intel_power_domains_disable(dev_priv);
Chris Wilson07d80572018-08-16 15:37:56 +0300702
Lucas De Marchi141b4152021-02-12 20:27:55 -0800703 intel_display_driver_unregister(dev_priv);
Chris Wilson448aa912017-11-28 11:01:47 +0000704
Andi Shyti42014f62019-09-05 14:14:03 +0300705 intel_gt_driver_unregister(&dev_priv->gt);
Chris Wilson0673ad42016-06-24 14:00:22 +0100706
Robert Bragg442b8c02016-11-07 19:49:53 +0000707 i915_perf_unregister(dev_priv);
Tvrtko Ursulinb46a33e2017-11-21 18:18:45 +0000708 i915_pmu_unregister(dev_priv);
Robert Bragg442b8c02016-11-07 19:49:53 +0000709
David Weinehall694c2822016-08-22 13:32:43 +0300710 i915_teardown_sysfs(dev_priv);
Janusz Krzysztofikd69990e2019-04-05 15:02:34 +0200711 drm_dev_unplug(&dev_priv->drm);
Chris Wilson0673ad42016-06-24 14:00:22 +0100712
Chris Wilsonc29579d2019-08-06 13:42:59 +0100713 i915_gem_driver_unregister(dev_priv);
Chris Wilson0673ad42016-06-24 14:00:22 +0100714}
715
Michal Wajdeczko27d558a2017-12-21 21:57:35 +0000716static void i915_welcome_messages(struct drm_i915_private *dev_priv)
717{
Jani Nikulabdbf43d2019-10-28 12:38:15 +0200718 if (drm_debug_enabled(DRM_UT_DRIVER)) {
Michal Wajdeczko27d558a2017-12-21 21:57:35 +0000719 struct drm_printer p = drm_debug_printer("i915 device info:");
720
Tvrtko Ursulin805446c2019-03-27 14:23:28 +0000721 drm_printf(&p, "pciid=0x%04x rev=0x%02x platform=%s (subplatform=0x%x) gen=%i\n",
Jani Nikula1787a982018-12-31 16:56:45 +0200722 INTEL_DEVID(dev_priv),
723 INTEL_REVID(dev_priv),
724 intel_platform_name(INTEL_INFO(dev_priv)->platform),
Tvrtko Ursulin805446c2019-03-27 14:23:28 +0000725 intel_subplatform(RUNTIME_INFO(dev_priv),
726 INTEL_INFO(dev_priv)->platform),
Jani Nikula1787a982018-12-31 16:56:45 +0200727 INTEL_GEN(dev_priv));
728
Chris Wilson72404972019-12-07 18:29:37 +0000729 intel_device_info_print_static(INTEL_INFO(dev_priv), &p);
730 intel_device_info_print_runtime(RUNTIME_INFO(dev_priv), &p);
Daniele Ceraolo Spurio792592e2020-07-07 17:39:47 -0700731 intel_gt_info_print(&dev_priv->gt.info, &p);
Michal Wajdeczko27d558a2017-12-21 21:57:35 +0000732 }
733
734 if (IS_ENABLED(CONFIG_DRM_I915_DEBUG))
Wambui Karuga00376cc2020-01-31 12:34:12 +0300735 drm_info(&dev_priv->drm, "DRM_I915_DEBUG enabled\n");
Michal Wajdeczko27d558a2017-12-21 21:57:35 +0000736 if (IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM))
Wambui Karuga00376cc2020-01-31 12:34:12 +0300737 drm_info(&dev_priv->drm, "DRM_I915_DEBUG_GEM enabled\n");
Imre Deak6dfc4a82018-08-16 22:34:14 +0300738 if (IS_ENABLED(CONFIG_DRM_I915_DEBUG_RUNTIME_PM))
Wambui Karuga00376cc2020-01-31 12:34:12 +0300739 drm_info(&dev_priv->drm,
740 "DRM_I915_DEBUG_RUNTIME_PM enabled\n");
Michal Wajdeczko27d558a2017-12-21 21:57:35 +0000741}
742
Chris Wilson55ac5a12018-09-05 15:09:20 +0100743static struct drm_i915_private *
744i915_driver_create(struct pci_dev *pdev, const struct pci_device_id *ent)
745{
746 const struct intel_device_info *match_info =
747 (struct intel_device_info *)ent->driver_data;
748 struct intel_device_info *device_info;
749 struct drm_i915_private *i915;
750
Daniel Vetter274ed9e2020-04-15 09:40:13 +0200751 i915 = devm_drm_dev_alloc(&pdev->dev, &driver,
752 struct drm_i915_private, drm);
753 if (IS_ERR(i915))
754 return i915;
Chris Wilson55ac5a12018-09-05 15:09:20 +0100755
Chris Wilson361f9dc2019-08-06 08:42:19 +0100756 i915->drm.pdev = pdev;
757 pci_set_drvdata(pdev, i915);
Chris Wilson55ac5a12018-09-05 15:09:20 +0100758
Jani Nikula8a25c4b2020-06-18 18:04:02 +0300759 /* Device parameters start as a copy of module parameters. */
760 i915_params_copy(&i915->params, &i915_modparams);
761
Chris Wilson55ac5a12018-09-05 15:09:20 +0100762 /* Setup the write-once "constant" device info */
763 device_info = mkwrite_device_info(i915);
764 memcpy(device_info, match_info, sizeof(*device_info));
Jani Nikula02584042018-12-31 16:56:41 +0200765 RUNTIME_INFO(i915)->device_id = pdev->device;
Chris Wilson55ac5a12018-09-05 15:09:20 +0100766
Chris Wilson74f6e182018-09-26 11:47:07 +0100767 BUG_ON(device_info->gen > BITS_PER_TYPE(device_info->gen_mask));
Chris Wilson55ac5a12018-09-05 15:09:20 +0100768
769 return i915;
770}
771
Chris Wilson0673ad42016-06-24 14:00:22 +0100772/**
Janusz Krzysztofikb01558e2019-07-12 13:24:26 +0200773 * i915_driver_probe - setup chip and create an initial config
Joonas Lahtinend2ad3ae2016-11-10 15:36:34 +0200774 * @pdev: PCI device
775 * @ent: matching PCI ID entry
Chris Wilson0673ad42016-06-24 14:00:22 +0100776 *
Janusz Krzysztofikb01558e2019-07-12 13:24:26 +0200777 * The driver probe routine has to do several things:
Chris Wilson0673ad42016-06-24 14:00:22 +0100778 * - drive output discovery via intel_modeset_init()
779 * - initialize the memory manager
780 * - allocate initial config memory
781 * - setup the DRM framebuffer with the allocated memory
782 */
Janusz Krzysztofikb01558e2019-07-12 13:24:26 +0200783int i915_driver_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Chris Wilson0673ad42016-06-24 14:00:22 +0100784{
Maarten Lankhorst8d2b47d2017-02-02 08:41:42 +0100785 const struct intel_device_info *match_info =
786 (struct intel_device_info *)ent->driver_data;
Jani Nikula8eecfb32020-02-11 18:28:02 +0200787 struct drm_i915_private *i915;
Chris Wilson0673ad42016-06-24 14:00:22 +0100788 int ret;
789
Jani Nikula8eecfb32020-02-11 18:28:02 +0200790 i915 = i915_driver_create(pdev, ent);
791 if (IS_ERR(i915))
792 return PTR_ERR(i915);
Chris Wilson0673ad42016-06-24 14:00:22 +0100793
Ville Syrjälä1feb64c2018-09-13 16:16:22 +0300794 /* Disable nuclear pageflip by default on pre-ILK */
Jani Nikula8a25c4b2020-06-18 18:04:02 +0300795 if (!i915->params.nuclear_pageflip && match_info->gen < 5)
Jani Nikula8eecfb32020-02-11 18:28:02 +0200796 i915->drm.driver_features &= ~DRIVER_ATOMIC;
Ville Syrjälä1feb64c2018-09-13 16:16:22 +0300797
Matthew Auld16292242019-10-30 17:33:20 +0000798 /*
799 * Check if we support fake LMEM -- for now we only unleash this for
800 * the live selftests(test-and-exit).
801 */
Chris Wilson292a27b2019-11-01 09:51:47 +0000802#if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
Matthew Auld16292242019-10-30 17:33:20 +0000803 if (IS_ENABLED(CONFIG_DRM_I915_UNSTABLE_FAKE_LMEM)) {
Jani Nikula8eecfb32020-02-11 18:28:02 +0200804 if (INTEL_GEN(i915) >= 9 && i915_selftest.live < 0 &&
Jani Nikula8a25c4b2020-06-18 18:04:02 +0300805 i915->params.fake_lmem_start) {
Jani Nikula8eecfb32020-02-11 18:28:02 +0200806 mkwrite_device_info(i915)->memory_regions =
Matthew Auld16292242019-10-30 17:33:20 +0000807 REGION_SMEM | REGION_LMEM | REGION_STOLEN;
Jani Nikula8eecfb32020-02-11 18:28:02 +0200808 GEM_BUG_ON(!HAS_LMEM(i915));
Matthew Auld16292242019-10-30 17:33:20 +0000809 }
810 }
Chris Wilson292a27b2019-11-01 09:51:47 +0000811#endif
Matthew Auld16292242019-10-30 17:33:20 +0000812
Chris Wilson0673ad42016-06-24 14:00:22 +0100813 ret = pci_enable_device(pdev);
814 if (ret)
Chris Wilsoncad36882017-02-10 16:35:21 +0000815 goto out_fini;
Chris Wilson0673ad42016-06-24 14:00:22 +0100816
Jani Nikula8eecfb32020-02-11 18:28:02 +0200817 ret = i915_driver_early_probe(i915);
Chris Wilson0673ad42016-06-24 14:00:22 +0100818 if (ret < 0)
819 goto out_pci_disable;
820
Jani Nikula8eecfb32020-02-11 18:28:02 +0200821 disable_rpm_wakeref_asserts(&i915->runtime_pm);
Chris Wilson0673ad42016-06-24 14:00:22 +0100822
Jani Nikula9e859eb2020-02-27 16:44:06 +0200823 intel_vgpu_detect(i915);
Daniele Ceraolo Spurio9e138ea2019-06-19 18:00:21 -0700824
Jani Nikula8eecfb32020-02-11 18:28:02 +0200825 ret = i915_driver_mmio_probe(i915);
Chris Wilson0673ad42016-06-24 14:00:22 +0100826 if (ret < 0)
827 goto out_runtime_pm_put;
828
Jani Nikula8eecfb32020-02-11 18:28:02 +0200829 ret = i915_driver_hw_probe(i915);
Chris Wilson0673ad42016-06-24 14:00:22 +0100830 if (ret < 0)
831 goto out_cleanup_mmio;
832
Jani Nikulad6843dd2020-09-02 17:30:23 +0300833 ret = intel_modeset_init_noirq(i915);
Chris Wilson0673ad42016-06-24 14:00:22 +0100834 if (ret < 0)
Daniel Vetterbaf54382017-06-21 10:28:41 +0200835 goto out_cleanup_hw;
Chris Wilson0673ad42016-06-24 14:00:22 +0100836
Jani Nikulab6642592020-02-19 15:37:56 +0200837 ret = intel_irq_install(i915);
838 if (ret)
839 goto out_cleanup_modeset;
840
Jani Nikulad6843dd2020-09-02 17:30:23 +0300841 ret = intel_modeset_init_nogem(i915);
842 if (ret)
Jani Nikulab6642592020-02-19 15:37:56 +0200843 goto out_cleanup_irq;
844
Jani Nikulad6843dd2020-09-02 17:30:23 +0300845 ret = i915_gem_init(i915);
846 if (ret)
847 goto out_cleanup_modeset2;
848
849 ret = intel_modeset_init(i915);
850 if (ret)
851 goto out_cleanup_gem;
852
Jani Nikula8eecfb32020-02-11 18:28:02 +0200853 i915_driver_register(i915);
Chris Wilson0673ad42016-06-24 14:00:22 +0100854
Jani Nikula8eecfb32020-02-11 18:28:02 +0200855 enable_rpm_wakeref_asserts(&i915->runtime_pm);
Chris Wilson0673ad42016-06-24 14:00:22 +0100856
Jani Nikula8eecfb32020-02-11 18:28:02 +0200857 i915_welcome_messages(i915);
Michal Wajdeczko27d558a2017-12-21 21:57:35 +0000858
Daniel Vetter7fb81e92020-03-23 15:49:07 +0100859 i915->do_release = true;
860
Chris Wilson0673ad42016-06-24 14:00:22 +0100861 return 0;
862
Jani Nikulad6843dd2020-09-02 17:30:23 +0300863out_cleanup_gem:
864 i915_gem_suspend(i915);
865 i915_gem_driver_remove(i915);
866 i915_gem_driver_release(i915);
867out_cleanup_modeset2:
868 /* FIXME clean up the error path */
869 intel_modeset_driver_remove(i915);
870 intel_irq_uninstall(i915);
871 intel_modeset_driver_remove_noirq(i915);
872 goto out_cleanup_modeset;
Jani Nikulab6642592020-02-19 15:37:56 +0200873out_cleanup_irq:
874 intel_irq_uninstall(i915);
875out_cleanup_modeset:
Jani Nikulaeb4612d2020-09-02 17:30:22 +0300876 intel_modeset_driver_remove_nogem(i915);
Chris Wilson0673ad42016-06-24 14:00:22 +0100877out_cleanup_hw:
Jani Nikula8eecfb32020-02-11 18:28:02 +0200878 i915_driver_hw_remove(i915);
879 intel_memory_regions_driver_release(i915);
880 i915_ggtt_driver_release(i915);
Chris Wilson0673ad42016-06-24 14:00:22 +0100881out_cleanup_mmio:
Jani Nikula8eecfb32020-02-11 18:28:02 +0200882 i915_driver_mmio_release(i915);
Chris Wilson0673ad42016-06-24 14:00:22 +0100883out_runtime_pm_put:
Jani Nikula8eecfb32020-02-11 18:28:02 +0200884 enable_rpm_wakeref_asserts(&i915->runtime_pm);
885 i915_driver_late_release(i915);
Chris Wilson0673ad42016-06-24 14:00:22 +0100886out_pci_disable:
887 pci_disable_device(pdev);
Chris Wilsoncad36882017-02-10 16:35:21 +0000888out_fini:
Jani Nikula8eecfb32020-02-11 18:28:02 +0200889 i915_probe_error(i915, "Device initialization failed (%d)\n", ret);
Chris Wilson0673ad42016-06-24 14:00:22 +0100890 return ret;
891}
892
Chris Wilson361f9dc2019-08-06 08:42:19 +0100893void i915_driver_remove(struct drm_i915_private *i915)
Chris Wilson0673ad42016-06-24 14:00:22 +0100894{
Chris Wilson361f9dc2019-08-06 08:42:19 +0100895 disable_rpm_wakeref_asserts(&i915->runtime_pm);
Chris Wilson07d80572018-08-16 15:37:56 +0300896
Chris Wilson361f9dc2019-08-06 08:42:19 +0100897 i915_driver_unregister(i915);
Daniel Vetter99c539b2017-07-15 00:46:56 +0200898
Chris Wilson4a8ab5e2019-01-14 14:21:29 +0000899 /* Flush any external code that still may be under the RCU lock */
900 synchronize_rcu();
901
Chris Wilson361f9dc2019-08-06 08:42:19 +0100902 i915_gem_suspend(i915);
Chris Wilson0673ad42016-06-24 14:00:22 +0100903
Chris Wilson361f9dc2019-08-06 08:42:19 +0100904 intel_gvt_driver_remove(i915);
Zhenyu Wang26f837e2017-01-13 10:46:09 +0800905
Jani Nikulaeb4612d2020-09-02 17:30:22 +0300906 intel_modeset_driver_remove(i915);
Chris Wilson0673ad42016-06-24 14:00:22 +0100907
Jani Nikulaf20a60f2020-02-14 15:50:58 +0200908 intel_irq_uninstall(i915);
909
José Roberto de Souzac0ff9e52020-04-16 11:58:41 -0700910 intel_modeset_driver_remove_noirq(i915);
Jani Nikulaf20a60f2020-02-14 15:50:58 +0200911
Chris Wilson361f9dc2019-08-06 08:42:19 +0100912 i915_reset_error_state(i915);
Chris Wilson361f9dc2019-08-06 08:42:19 +0100913 i915_gem_driver_remove(i915);
Chris Wilson0673ad42016-06-24 14:00:22 +0100914
Jani Nikulaeb4612d2020-09-02 17:30:22 +0300915 intel_modeset_driver_remove_nogem(i915);
Chris Wilson0673ad42016-06-24 14:00:22 +0100916
Chris Wilson361f9dc2019-08-06 08:42:19 +0100917 i915_driver_hw_remove(i915);
Chris Wilson0673ad42016-06-24 14:00:22 +0100918
Chris Wilson361f9dc2019-08-06 08:42:19 +0100919 enable_rpm_wakeref_asserts(&i915->runtime_pm);
Chris Wilsoncad36882017-02-10 16:35:21 +0000920}
921
922static void i915_driver_release(struct drm_device *dev)
923{
924 struct drm_i915_private *dev_priv = to_i915(dev);
Daniele Ceraolo Spurio69c66352019-06-13 16:21:53 -0700925 struct intel_runtime_pm *rpm = &dev_priv->runtime_pm;
Chris Wilson0673ad42016-06-24 14:00:22 +0100926
Daniel Vetter7fb81e92020-03-23 15:49:07 +0100927 if (!dev_priv->do_release)
928 return;
929
Daniele Ceraolo Spurio69c66352019-06-13 16:21:53 -0700930 disable_rpm_wakeref_asserts(rpm);
Janusz Krzysztofik47bc28d2019-05-30 15:31:05 +0200931
Janusz Krzysztofik3b58a942019-07-12 13:24:28 +0200932 i915_gem_driver_release(dev_priv);
Janusz Krzysztofik47bc28d2019-05-30 15:31:05 +0200933
Chris Wilson3fc794f2019-10-26 21:20:32 +0100934 intel_memory_regions_driver_release(dev_priv);
Janusz Krzysztofik3b58a942019-07-12 13:24:28 +0200935 i915_ggtt_driver_release(dev_priv);
Chris Wilson89351922020-07-29 17:42:18 +0100936 i915_gem_drain_freed_objects(dev_priv);
Daniele Ceraolo Spurio19e0a8d2019-06-19 18:00:17 -0700937
Janusz Krzysztofik3b58a942019-07-12 13:24:28 +0200938 i915_driver_mmio_release(dev_priv);
Janusz Krzysztofik47bc28d2019-05-30 15:31:05 +0200939
Daniele Ceraolo Spurio69c66352019-06-13 16:21:53 -0700940 enable_rpm_wakeref_asserts(rpm);
Janusz Krzysztofik3b58a942019-07-12 13:24:28 +0200941 intel_runtime_pm_driver_release(rpm);
Janusz Krzysztofik47bc28d2019-05-30 15:31:05 +0200942
Janusz Krzysztofik3b58a942019-07-12 13:24:28 +0200943 i915_driver_late_release(dev_priv);
Chris Wilson0673ad42016-06-24 14:00:22 +0100944}
945
946static int i915_driver_open(struct drm_device *dev, struct drm_file *file)
947{
Chris Wilson829a0af2017-06-20 12:05:45 +0100948 struct drm_i915_private *i915 = to_i915(dev);
Chris Wilson0673ad42016-06-24 14:00:22 +0100949 int ret;
950
Chris Wilson829a0af2017-06-20 12:05:45 +0100951 ret = i915_gem_open(i915, file);
Chris Wilson0673ad42016-06-24 14:00:22 +0100952 if (ret)
953 return ret;
954
955 return 0;
956}
957
958/**
959 * i915_driver_lastclose - clean up after all DRM clients have exited
960 * @dev: DRM device
961 *
962 * Take care of cleaning up after all DRM clients have exited. In the
963 * mode setting case, we want to restore the kernel's initial mode (just
964 * in case the last client left us in a bad state).
965 *
966 * Additionally, in the non-mode setting case, we'll tear down the GTT
967 * and DMA structures, since the kernel won't be using them, and clea
968 * up any GEM state.
969 */
970static void i915_driver_lastclose(struct drm_device *dev)
971{
972 intel_fbdev_restore_mode(dev);
973 vga_switcheroo_process_delayed_switch();
974}
975
Daniel Vetter7d2ec882017-03-08 15:12:45 +0100976static void i915_driver_postclose(struct drm_device *dev, struct drm_file *file)
Chris Wilson0673ad42016-06-24 14:00:22 +0100977{
Daniel Vetter7d2ec882017-03-08 15:12:45 +0100978 struct drm_i915_file_private *file_priv = file->driver_priv;
979
Chris Wilson829a0af2017-06-20 12:05:45 +0100980 i915_gem_context_close(file);
Chris Wilson0673ad42016-06-24 14:00:22 +0100981
Chris Wilson77715902019-08-23 19:14:55 +0100982 kfree_rcu(file_priv, rcu);
Chris Wilson515b8b72019-08-02 22:21:37 +0100983
984 /* Catch up with all the deferred frees from "this" client */
985 i915_gem_flush_free_objects(to_i915(dev));
Chris Wilson0673ad42016-06-24 14:00:22 +0100986}
987
Imre Deak07f9cd02014-08-18 14:42:45 +0300988static void intel_suspend_encoders(struct drm_i915_private *dev_priv)
989{
Chris Wilson91c8a322016-07-05 10:40:23 +0100990 struct drm_device *dev = &dev_priv->drm;
Jani Nikula19c80542015-12-16 12:48:16 +0200991 struct intel_encoder *encoder;
Imre Deak07f9cd02014-08-18 14:42:45 +0300992
993 drm_modeset_lock_all(dev);
Jani Nikula19c80542015-12-16 12:48:16 +0200994 for_each_intel_encoder(dev, encoder)
995 if (encoder->suspend)
996 encoder->suspend(encoder);
Imre Deak07f9cd02014-08-18 14:42:45 +0300997 drm_modeset_unlock_all(dev);
998}
999
Ville Syrjälä100fe4c2020-10-01 18:16:36 +03001000static void intel_shutdown_encoders(struct drm_i915_private *dev_priv)
1001{
1002 struct drm_device *dev = &dev_priv->drm;
1003 struct intel_encoder *encoder;
1004
1005 drm_modeset_lock_all(dev);
1006 for_each_intel_encoder(dev, encoder)
1007 if (encoder->shutdown)
1008 encoder->shutdown(encoder);
1009 drm_modeset_unlock_all(dev);
1010}
1011
Ville Syrjäläfe0f1e32020-10-01 18:16:35 +03001012void i915_driver_shutdown(struct drm_i915_private *i915)
1013{
Chris Wilson19fe4ac2021-01-04 20:39:05 +00001014 disable_rpm_wakeref_asserts(&i915->runtime_pm);
Imre Deak79628932021-01-27 20:19:09 +02001015 intel_runtime_pm_disable(&i915->runtime_pm);
1016 intel_power_domains_disable(i915);
Chris Wilson19fe4ac2021-01-04 20:39:05 +00001017
Ville Syrjäläfe0f1e32020-10-01 18:16:35 +03001018 i915_gem_suspend(i915);
1019
1020 drm_kms_helper_poll_disable(&i915->drm);
1021
1022 drm_atomic_helper_shutdown(&i915->drm);
1023
1024 intel_dp_mst_suspend(i915);
1025
1026 intel_runtime_pm_disable_interrupts(i915);
1027 intel_hpd_cancel_work(i915);
1028
1029 intel_suspend_encoders(i915);
Ville Syrjälä100fe4c2020-10-01 18:16:36 +03001030 intel_shutdown_encoders(i915);
Chris Wilson19fe4ac2021-01-04 20:39:05 +00001031
Imre Deak79628932021-01-27 20:19:09 +02001032 /*
1033 * The only requirement is to reboot with display DC states disabled,
1034 * for now leaving all display power wells in the INIT power domain
1035 * enabled matching the driver reload sequence.
1036 */
1037 intel_power_domains_driver_remove(i915);
Chris Wilson19fe4ac2021-01-04 20:39:05 +00001038 enable_rpm_wakeref_asserts(&i915->runtime_pm);
Imre Deak79628932021-01-27 20:19:09 +02001039
1040 intel_runtime_pm_driver_release(&i915->runtime_pm);
Ville Syrjäläfe0f1e32020-10-01 18:16:35 +03001041}
1042
Imre Deakbc872292015-11-18 17:32:30 +02001043static bool suspend_to_idle(struct drm_i915_private *dev_priv)
1044{
1045#if IS_ENABLED(CONFIG_ACPI_SLEEP)
1046 if (acpi_target_system_state() < ACPI_STATE_S3)
1047 return true;
1048#endif
1049 return false;
1050}
Sagar Kambleebc32822014-08-13 23:07:05 +05301051
Chris Wilson73b66f82018-05-25 10:26:29 +01001052static int i915_drm_prepare(struct drm_device *dev)
1053{
1054 struct drm_i915_private *i915 = to_i915(dev);
Chris Wilson73b66f82018-05-25 10:26:29 +01001055
1056 /*
1057 * NB intel_display_suspend() may issue new requests after we've
1058 * ostensibly marked the GPU as ready-to-sleep here. We need to
1059 * split out that work and pull it forward so that after point,
1060 * the GPU is not woken again.
1061 */
Chris Wilson5861b012019-03-08 09:36:54 +00001062 i915_gem_suspend(i915);
Chris Wilson73b66f82018-05-25 10:26:29 +01001063
Chris Wilson5861b012019-03-08 09:36:54 +00001064 return 0;
Chris Wilson73b66f82018-05-25 10:26:29 +01001065}
1066
Imre Deak5e365c32014-10-23 19:23:25 +03001067static int i915_drm_suspend(struct drm_device *dev)
Rafael J. Wysocki84b79f82010-02-07 21:48:24 +01001068{
Chris Wilsonfac5e232016-07-04 11:34:36 +01001069 struct drm_i915_private *dev_priv = to_i915(dev);
Thomas Zimmermann8ff54462021-01-28 14:31:23 +01001070 struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev);
Jesse Barnese5747e32014-06-12 08:35:47 -07001071 pci_power_t opregion_target_state;
Rafael J. Wysocki61caf872010-02-18 23:06:27 +01001072
Daniele Ceraolo Spurio91026502019-06-13 16:21:51 -07001073 disable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
Imre Deak1f814da2015-12-16 02:52:19 +02001074
Paulo Zanonic67a4702013-08-19 13:18:09 -03001075 /* We do a lot of poking in a lot of registers, make sure they work
1076 * properly. */
Imre Deak2cd9a682018-08-16 15:37:57 +03001077 intel_power_domains_disable(dev_priv);
Paulo Zanonicb107992013-01-25 16:59:15 -02001078
Dave Airlie5bcf7192010-12-07 09:20:40 +10001079 drm_kms_helper_poll_disable(dev);
1080
David Weinehall52a05c32016-08-22 13:32:44 +03001081 pci_save_state(pdev);
Rafael J. Wysocki84b79f82010-02-07 21:48:24 +01001082
Maarten Lankhorst6b72d482015-06-01 12:49:47 +02001083 intel_display_suspend(dev);
Daniel Vetterd5818932015-02-23 12:03:26 +01001084
Ville Syrjälä1a4313d2018-07-05 19:43:52 +03001085 intel_dp_mst_suspend(dev_priv);
Daniel Vetterd5818932015-02-23 12:03:26 +01001086
1087 intel_runtime_pm_disable_interrupts(dev_priv);
1088 intel_hpd_cancel_work(dev_priv);
1089
1090 intel_suspend_encoders(dev_priv);
1091
Ville Syrjälä712bf362016-10-31 22:37:23 +02001092 intel_suspend_hw(dev_priv);
Daniel Vetterd5818932015-02-23 12:03:26 +01001093
Chris Wilsone9862092020-01-30 18:17:09 +00001094 i915_ggtt_suspend(&dev_priv->ggtt);
Ben Widawsky828c7902013-10-16 09:21:30 -07001095
Ville Syrjälä0f8d2a22020-10-05 20:14:41 +03001096 i915_save_display(dev_priv);
Rafael J. Wysocki84b79f82010-02-07 21:48:24 +01001097
Imre Deakbc872292015-11-18 17:32:30 +02001098 opregion_target_state = suspend_to_idle(dev_priv) ? PCI_D1 : PCI_D3cold;
Chris Wilsona950adc2018-10-30 11:05:54 +00001099 intel_opregion_suspend(dev_priv, opregion_target_state);
Rafael J. Wysocki84b79f82010-02-07 21:48:24 +01001100
Chris Wilson82e3b8c2014-08-13 13:09:46 +01001101 intel_fbdev_set_suspend(dev, FBINFO_STATE_SUSPENDED, true);
Dave Airlie3fa016a2012-03-28 10:48:49 +01001102
Mika Kuoppala62d5d692014-02-25 17:11:28 +02001103 dev_priv->suspend_count++;
1104
Imre Deakf74ed082016-04-18 14:48:21 +03001105 intel_csr_ucode_suspend(dev_priv);
Imre Deakf514c2d2015-10-28 23:59:06 +02001106
Daniele Ceraolo Spurio91026502019-06-13 16:21:51 -07001107 enable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
Imre Deak1f814da2015-12-16 02:52:19 +02001108
Chris Wilson73b66f82018-05-25 10:26:29 +01001109 return 0;
Rafael J. Wysocki84b79f82010-02-07 21:48:24 +01001110}
1111
Imre Deak2cd9a682018-08-16 15:37:57 +03001112static enum i915_drm_suspend_mode
1113get_suspend_mode(struct drm_i915_private *dev_priv, bool hibernate)
1114{
1115 if (hibernate)
1116 return I915_DRM_SUSPEND_HIBERNATE;
1117
1118 if (suspend_to_idle(dev_priv))
1119 return I915_DRM_SUSPEND_IDLE;
1120
1121 return I915_DRM_SUSPEND_MEM;
1122}
1123
David Weinehallc49d13e2016-08-22 13:32:42 +03001124static int i915_drm_suspend_late(struct drm_device *dev, bool hibernation)
Imre Deakc3c09c92014-10-23 19:23:15 +03001125{
David Weinehallc49d13e2016-08-22 13:32:42 +03001126 struct drm_i915_private *dev_priv = to_i915(dev);
Thomas Zimmermann8ff54462021-01-28 14:31:23 +01001127 struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev);
Daniele Ceraolo Spurio69c66352019-06-13 16:21:53 -07001128 struct intel_runtime_pm *rpm = &dev_priv->runtime_pm;
Jani Nikulafb5f4322020-02-12 16:40:57 +02001129 int ret;
Imre Deakc3c09c92014-10-23 19:23:15 +03001130
Daniele Ceraolo Spurio69c66352019-06-13 16:21:53 -07001131 disable_rpm_wakeref_asserts(rpm);
Imre Deak1f814da2015-12-16 02:52:19 +02001132
Chris Wilsonec92ad02018-05-31 09:22:46 +01001133 i915_gem_suspend_late(dev_priv);
1134
Daniele Ceraolo Spuriof7de5022019-03-19 11:35:37 -07001135 intel_uncore_suspend(&dev_priv->uncore);
Imre Deak4c494a52016-10-13 14:34:06 +03001136
Imre Deak2cd9a682018-08-16 15:37:57 +03001137 intel_power_domains_suspend(dev_priv,
1138 get_suspend_mode(dev_priv, hibernation));
Imre Deak73dfc222015-11-17 17:33:53 +02001139
Rodrigo Vivi071b68c2019-08-06 15:22:08 +03001140 intel_display_power_suspend_late(dev_priv);
1141
Jani Nikulafb5f4322020-02-12 16:40:57 +02001142 ret = vlv_suspend_complete(dev_priv);
Imre Deakc3c09c92014-10-23 19:23:15 +03001143 if (ret) {
Wambui Karuga00376cc2020-01-31 12:34:12 +03001144 drm_err(&dev_priv->drm, "Suspend complete failed: %d\n", ret);
Imre Deak2cd9a682018-08-16 15:37:57 +03001145 intel_power_domains_resume(dev_priv);
Imre Deakc3c09c92014-10-23 19:23:15 +03001146
Imre Deak1f814da2015-12-16 02:52:19 +02001147 goto out;
Imre Deakc3c09c92014-10-23 19:23:15 +03001148 }
1149
David Weinehall52a05c32016-08-22 13:32:44 +03001150 pci_disable_device(pdev);
Imre Deakab3be732015-03-02 13:04:41 +02001151 /*
Imre Deak54875572015-06-30 17:06:47 +03001152 * During hibernation on some platforms the BIOS may try to access
Imre Deakab3be732015-03-02 13:04:41 +02001153 * the device even though it's already in D3 and hang the machine. So
1154 * leave the device in D0 on those platforms and hope the BIOS will
Imre Deak54875572015-06-30 17:06:47 +03001155 * power down the device properly. The issue was seen on multiple old
1156 * GENs with different BIOS vendors, so having an explicit blacklist
1157 * is inpractical; apply the workaround on everything pre GEN6. The
1158 * platforms where the issue was seen:
1159 * Lenovo Thinkpad X301, X61s, X60, T60, X41
1160 * Fujitsu FSC S7110
1161 * Acer Aspire 1830T
Imre Deakab3be732015-03-02 13:04:41 +02001162 */
Tvrtko Ursulin514e1d62016-11-04 14:42:48 +00001163 if (!(hibernation && INTEL_GEN(dev_priv) < 6))
David Weinehall52a05c32016-08-22 13:32:44 +03001164 pci_set_power_state(pdev, PCI_D3hot);
Imre Deakc3c09c92014-10-23 19:23:15 +03001165
Imre Deak1f814da2015-12-16 02:52:19 +02001166out:
Daniele Ceraolo Spurio69c66352019-06-13 16:21:53 -07001167 enable_rpm_wakeref_asserts(rpm);
Daniele Ceraolo Spurio0a9b2632019-08-09 07:31:16 +01001168 if (!dev_priv->uncore.user_forcewake_count)
Janusz Krzysztofik3b58a942019-07-12 13:24:28 +02001169 intel_runtime_pm_driver_release(rpm);
Imre Deak1f814da2015-12-16 02:52:19 +02001170
1171 return ret;
Imre Deakc3c09c92014-10-23 19:23:15 +03001172}
1173
Jani Nikula63bf8302019-10-04 15:20:18 +03001174int i915_suspend_switcheroo(struct drm_i915_private *i915, pm_message_t state)
Rafael J. Wysocki84b79f82010-02-07 21:48:24 +01001175{
1176 int error;
1177
Pankaj Bharadiya48a1b8d2020-01-15 09:14:53 +05301178 if (drm_WARN_ON_ONCE(&i915->drm, state.event != PM_EVENT_SUSPEND &&
1179 state.event != PM_EVENT_FREEZE))
Imre Deak0b14cbd2014-09-10 18:16:55 +03001180 return -EINVAL;
Dave Airlie5bcf7192010-12-07 09:20:40 +10001181
Chris Wilson361f9dc2019-08-06 08:42:19 +01001182 if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF)
Dave Airlie5bcf7192010-12-07 09:20:40 +10001183 return 0;
Chris Wilson6eecba32010-09-08 09:45:11 +01001184
Chris Wilson361f9dc2019-08-06 08:42:19 +01001185 error = i915_drm_suspend(&i915->drm);
Rafael J. Wysocki84b79f82010-02-07 21:48:24 +01001186 if (error)
1187 return error;
Jesse Barnesba8bbcf2007-11-22 14:14:14 +10001188
Chris Wilson361f9dc2019-08-06 08:42:19 +01001189 return i915_drm_suspend_late(&i915->drm, false);
Jesse Barnesba8bbcf2007-11-22 14:14:14 +10001190}
1191
Imre Deak5e365c32014-10-23 19:23:25 +03001192static int i915_drm_resume(struct drm_device *dev)
Jesse Barnesba8bbcf2007-11-22 14:14:14 +10001193{
Chris Wilsonfac5e232016-07-04 11:34:36 +01001194 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläac840ae2016-05-06 21:35:55 +03001195 int ret;
Matthew Garrett8ee1c3d2008-08-05 19:37:25 +01001196
Daniele Ceraolo Spurio91026502019-06-13 16:21:51 -07001197 disable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
Imre Deak1f814da2015-12-16 02:52:19 +02001198
Chris Wilson640b50f2019-12-28 11:12:55 +00001199 sanitize_gpu(dev_priv);
1200
Chris Wilson97d6d7a2016-08-04 07:52:22 +01001201 ret = i915_ggtt_enable_hw(dev_priv);
Ville Syrjäläac840ae2016-05-06 21:35:55 +03001202 if (ret)
Wambui Karuga00376cc2020-01-31 12:34:12 +03001203 drm_err(&dev_priv->drm, "failed to re-enable GGTT\n");
Ville Syrjäläac840ae2016-05-06 21:35:55 +03001204
Chris Wilsone9862092020-01-30 18:17:09 +00001205 i915_ggtt_resume(&dev_priv->ggtt);
Chris Wilsoncec5ca02019-09-09 12:00:08 +01001206
Imre Deakf74ed082016-04-18 14:48:21 +03001207 intel_csr_ucode_resume(dev_priv);
1208
Ville Syrjälä0f8d2a22020-10-05 20:14:41 +03001209 i915_restore_display(dev_priv);
Imre Deak8090ba82016-08-10 14:07:33 +03001210 intel_pps_unlock_regs_wa(dev_priv);
Rafael J. Wysocki61caf872010-02-18 23:06:27 +01001211
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02001212 intel_init_pch_refclk(dev_priv);
Chris Wilson1833b132012-05-09 11:56:28 +01001213
Peter Antoine364aece2015-05-11 08:50:45 +01001214 /*
1215 * Interrupts have to be enabled before any batches are run. If not the
1216 * GPU will hang. i915_gem_init_hw() will initiate batches to
1217 * update/restore the context.
1218 *
Imre Deak908764f2016-11-29 21:40:29 +02001219 * drm_mode_config_reset() needs AUX interrupts.
1220 *
Peter Antoine364aece2015-05-11 08:50:45 +01001221 * Modeset enabling in intel_modeset_init_hw() also needs working
1222 * interrupts.
1223 */
1224 intel_runtime_pm_enable_interrupts(dev_priv);
1225
Imre Deak908764f2016-11-29 21:40:29 +02001226 drm_mode_config_reset(dev);
1227
Chris Wilson37cd3302017-11-12 11:27:38 +00001228 i915_gem_resume(dev_priv);
Daniel Vetterd5818932015-02-23 12:03:26 +01001229
Jani Nikula6cd02e72019-09-20 21:54:21 +03001230 intel_modeset_init_hw(dev_priv);
Ville Syrjälä675f7ff2017-11-16 18:02:15 +02001231 intel_init_clock_gating(dev_priv);
Ville Syrjälä4c8d4652020-10-13 21:11:37 +03001232 intel_hpd_init(dev_priv);
Daniel Vetterd5818932015-02-23 12:03:26 +01001233
Ville Syrjälä4c8d4652020-10-13 21:11:37 +03001234 /* MST sideband requires HPD interrupts enabled */
Ville Syrjälä1a4313d2018-07-05 19:43:52 +03001235 intel_dp_mst_resume(dev_priv);
Lyudea16b7652016-03-11 10:57:01 -05001236 intel_display_resume(dev);
1237
Ville Syrjälä4c8d4652020-10-13 21:11:37 +03001238 intel_hpd_poll_disable(dev_priv);
Lyudee0b70062016-11-01 21:06:30 -04001239 drm_kms_helper_poll_enable(dev);
1240
Chris Wilsona950adc2018-10-30 11:05:54 +00001241 intel_opregion_resume(dev_priv);
Chris Wilson44834a62010-08-19 16:09:23 +01001242
Chris Wilson82e3b8c2014-08-13 13:09:46 +01001243 intel_fbdev_set_suspend(dev, FBINFO_STATE_RUNNING, false);
Jesse Barnes073f34d2012-11-02 11:13:59 -07001244
Imre Deak2cd9a682018-08-16 15:37:57 +03001245 intel_power_domains_enable(dev_priv);
1246
Colin Xu385fc382020-10-27 12:54:06 +08001247 intel_gvt_resume(dev_priv);
1248
Daniele Ceraolo Spurio91026502019-06-13 16:21:51 -07001249 enable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
Imre Deak1f814da2015-12-16 02:52:19 +02001250
Chris Wilson074c6ad2014-04-09 09:19:43 +01001251 return 0;
Rafael J. Wysocki84b79f82010-02-07 21:48:24 +01001252}
1253
Imre Deak5e365c32014-10-23 19:23:25 +03001254static int i915_drm_resume_early(struct drm_device *dev)
Rafael J. Wysocki84b79f82010-02-07 21:48:24 +01001255{
Chris Wilsonfac5e232016-07-04 11:34:36 +01001256 struct drm_i915_private *dev_priv = to_i915(dev);
Thomas Zimmermann8ff54462021-01-28 14:31:23 +01001257 struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev);
Imre Deak44410cd2016-04-18 14:45:54 +03001258 int ret;
Imre Deak36d61e62014-10-23 19:23:24 +03001259
Imre Deak76c4b252014-04-01 19:55:22 +03001260 /*
1261 * We have a resume ordering issue with the snd-hda driver also
1262 * requiring our device to be power up. Due to the lack of a
1263 * parent/child relationship we currently solve this with an early
1264 * resume hook.
1265 *
1266 * FIXME: This should be solved with a special hdmi sink device or
1267 * similar so that power domains can be employed.
1268 */
Imre Deak44410cd2016-04-18 14:45:54 +03001269
1270 /*
1271 * Note that we need to set the power state explicitly, since we
1272 * powered off the device during freeze and the PCI core won't power
1273 * it back up for us during thaw. Powering off the device during
1274 * freeze is not a hard requirement though, and during the
1275 * suspend/resume phases the PCI core makes sure we get here with the
1276 * device powered on. So in case we change our freeze logic and keep
1277 * the device powered we can also remove the following set power state
1278 * call.
1279 */
David Weinehall52a05c32016-08-22 13:32:44 +03001280 ret = pci_set_power_state(pdev, PCI_D0);
Imre Deak44410cd2016-04-18 14:45:54 +03001281 if (ret) {
Wambui Karuga00376cc2020-01-31 12:34:12 +03001282 drm_err(&dev_priv->drm,
1283 "failed to set PCI D0 power state (%d)\n", ret);
Imre Deak2cd9a682018-08-16 15:37:57 +03001284 return ret;
Imre Deak44410cd2016-04-18 14:45:54 +03001285 }
1286
1287 /*
1288 * Note that pci_enable_device() first enables any parent bridge
1289 * device and only then sets the power state for this device. The
1290 * bridge enabling is a nop though, since bridge devices are resumed
1291 * first. The order of enabling power and enabling the device is
1292 * imposed by the PCI core as described above, so here we preserve the
1293 * same order for the freeze/thaw phases.
1294 *
1295 * TODO: eventually we should remove pci_disable_device() /
1296 * pci_enable_enable_device() from suspend/resume. Due to how they
1297 * depend on the device enable refcount we can't anyway depend on them
1298 * disabling/enabling the device.
1299 */
Imre Deak2cd9a682018-08-16 15:37:57 +03001300 if (pci_enable_device(pdev))
1301 return -EIO;
Rafael J. Wysocki84b79f82010-02-07 21:48:24 +01001302
David Weinehall52a05c32016-08-22 13:32:44 +03001303 pci_set_master(pdev);
Rafael J. Wysocki84b79f82010-02-07 21:48:24 +01001304
Daniele Ceraolo Spurio91026502019-06-13 16:21:51 -07001305 disable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
Imre Deak1f814da2015-12-16 02:52:19 +02001306
Jani Nikulafb5f4322020-02-12 16:40:57 +02001307 ret = vlv_resume_prepare(dev_priv, false);
Imre Deak36d61e62014-10-23 19:23:24 +03001308 if (ret)
Wambui Karuga00376cc2020-01-31 12:34:12 +03001309 drm_err(&dev_priv->drm,
Jani Nikulafb5f4322020-02-12 16:40:57 +02001310 "Resume prepare failed: %d, continuing anyway\n", ret);
Imre Deak36d61e62014-10-23 19:23:24 +03001311
Daniele Ceraolo Spuriof7de5022019-03-19 11:35:37 -07001312 intel_uncore_resume_early(&dev_priv->uncore);
1313
Tvrtko Ursulineaf522f2019-06-21 08:07:44 +01001314 intel_gt_check_and_clear_faults(&dev_priv->gt);
Paulo Zanoniefee8332014-10-27 17:54:33 -02001315
Rodrigo Vivi071b68c2019-08-06 15:22:08 +03001316 intel_display_power_resume_early(dev_priv);
Paulo Zanoniefee8332014-10-27 17:54:33 -02001317
Imre Deak2cd9a682018-08-16 15:37:57 +03001318 intel_power_domains_resume(dev_priv);
Imre Deakbc872292015-11-18 17:32:30 +02001319
Daniele Ceraolo Spurio91026502019-06-13 16:21:51 -07001320 enable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
Imre Deak6e35e8a2016-04-18 10:04:19 +03001321
Imre Deak36d61e62014-10-23 19:23:24 +03001322 return ret;
Imre Deak76c4b252014-04-01 19:55:22 +03001323}
1324
Jani Nikula63bf8302019-10-04 15:20:18 +03001325int i915_resume_switcheroo(struct drm_i915_private *i915)
Imre Deak76c4b252014-04-01 19:55:22 +03001326{
Imre Deak50a00722014-10-23 19:23:17 +03001327 int ret;
Imre Deak76c4b252014-04-01 19:55:22 +03001328
Chris Wilson361f9dc2019-08-06 08:42:19 +01001329 if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF)
Imre Deak097dd832014-10-23 19:23:19 +03001330 return 0;
1331
Chris Wilson361f9dc2019-08-06 08:42:19 +01001332 ret = i915_drm_resume_early(&i915->drm);
Imre Deak50a00722014-10-23 19:23:17 +03001333 if (ret)
1334 return ret;
1335
Chris Wilson361f9dc2019-08-06 08:42:19 +01001336 return i915_drm_resume(&i915->drm);
Imre Deak5a175142014-10-23 19:23:18 +03001337}
1338
Chris Wilson73b66f82018-05-25 10:26:29 +01001339static int i915_pm_prepare(struct device *kdev)
1340{
Chris Wilson361f9dc2019-08-06 08:42:19 +01001341 struct drm_i915_private *i915 = kdev_to_i915(kdev);
Chris Wilson73b66f82018-05-25 10:26:29 +01001342
Chris Wilson361f9dc2019-08-06 08:42:19 +01001343 if (!i915) {
Chris Wilson73b66f82018-05-25 10:26:29 +01001344 dev_err(kdev, "DRM not initialized, aborting suspend.\n");
1345 return -ENODEV;
1346 }
1347
Chris Wilson361f9dc2019-08-06 08:42:19 +01001348 if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF)
Chris Wilson73b66f82018-05-25 10:26:29 +01001349 return 0;
1350
Chris Wilson361f9dc2019-08-06 08:42:19 +01001351 return i915_drm_prepare(&i915->drm);
Chris Wilson73b66f82018-05-25 10:26:29 +01001352}
1353
David Weinehallc49d13e2016-08-22 13:32:42 +03001354static int i915_pm_suspend(struct device *kdev)
Kristian Høgsberg112b7152009-01-04 16:55:33 -05001355{
Chris Wilson361f9dc2019-08-06 08:42:19 +01001356 struct drm_i915_private *i915 = kdev_to_i915(kdev);
Kristian Høgsberg112b7152009-01-04 16:55:33 -05001357
Chris Wilson361f9dc2019-08-06 08:42:19 +01001358 if (!i915) {
David Weinehallc49d13e2016-08-22 13:32:42 +03001359 dev_err(kdev, "DRM not initialized, aborting suspend.\n");
Rafael J. Wysocki84b79f82010-02-07 21:48:24 +01001360 return -ENODEV;
1361 }
Kristian Høgsberg112b7152009-01-04 16:55:33 -05001362
Chris Wilson361f9dc2019-08-06 08:42:19 +01001363 if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF)
Dave Airlie5bcf7192010-12-07 09:20:40 +10001364 return 0;
1365
Chris Wilson361f9dc2019-08-06 08:42:19 +01001366 return i915_drm_suspend(&i915->drm);
Imre Deak76c4b252014-04-01 19:55:22 +03001367}
1368
David Weinehallc49d13e2016-08-22 13:32:42 +03001369static int i915_pm_suspend_late(struct device *kdev)
Imre Deak76c4b252014-04-01 19:55:22 +03001370{
Chris Wilson361f9dc2019-08-06 08:42:19 +01001371 struct drm_i915_private *i915 = kdev_to_i915(kdev);
Imre Deak76c4b252014-04-01 19:55:22 +03001372
1373 /*
Damien Lespiauc965d9952015-05-18 19:53:48 +01001374 * We have a suspend ordering issue with the snd-hda driver also
Imre Deak76c4b252014-04-01 19:55:22 +03001375 * requiring our device to be power up. Due to the lack of a
1376 * parent/child relationship we currently solve this with an late
1377 * suspend hook.
1378 *
1379 * FIXME: This should be solved with a special hdmi sink device or
1380 * similar so that power domains can be employed.
1381 */
Chris Wilson361f9dc2019-08-06 08:42:19 +01001382 if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF)
Imre Deak76c4b252014-04-01 19:55:22 +03001383 return 0;
Kristian Høgsberg112b7152009-01-04 16:55:33 -05001384
Chris Wilson361f9dc2019-08-06 08:42:19 +01001385 return i915_drm_suspend_late(&i915->drm, false);
Imre Deakab3be732015-03-02 13:04:41 +02001386}
1387
David Weinehallc49d13e2016-08-22 13:32:42 +03001388static int i915_pm_poweroff_late(struct device *kdev)
Imre Deakab3be732015-03-02 13:04:41 +02001389{
Chris Wilson361f9dc2019-08-06 08:42:19 +01001390 struct drm_i915_private *i915 = kdev_to_i915(kdev);
Imre Deakab3be732015-03-02 13:04:41 +02001391
Chris Wilson361f9dc2019-08-06 08:42:19 +01001392 if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF)
Imre Deakab3be732015-03-02 13:04:41 +02001393 return 0;
1394
Chris Wilson361f9dc2019-08-06 08:42:19 +01001395 return i915_drm_suspend_late(&i915->drm, true);
Zhenyu Wangcbda12d2009-12-16 13:36:10 +08001396}
1397
David Weinehallc49d13e2016-08-22 13:32:42 +03001398static int i915_pm_resume_early(struct device *kdev)
Imre Deak76c4b252014-04-01 19:55:22 +03001399{
Chris Wilson361f9dc2019-08-06 08:42:19 +01001400 struct drm_i915_private *i915 = kdev_to_i915(kdev);
Imre Deak76c4b252014-04-01 19:55:22 +03001401
Chris Wilson361f9dc2019-08-06 08:42:19 +01001402 if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF)
Imre Deak097dd832014-10-23 19:23:19 +03001403 return 0;
1404
Chris Wilson361f9dc2019-08-06 08:42:19 +01001405 return i915_drm_resume_early(&i915->drm);
Imre Deak76c4b252014-04-01 19:55:22 +03001406}
1407
David Weinehallc49d13e2016-08-22 13:32:42 +03001408static int i915_pm_resume(struct device *kdev)
Zhenyu Wangcbda12d2009-12-16 13:36:10 +08001409{
Chris Wilson361f9dc2019-08-06 08:42:19 +01001410 struct drm_i915_private *i915 = kdev_to_i915(kdev);
Rafael J. Wysocki84b79f82010-02-07 21:48:24 +01001411
Chris Wilson361f9dc2019-08-06 08:42:19 +01001412 if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF)
Imre Deak097dd832014-10-23 19:23:19 +03001413 return 0;
1414
Chris Wilson361f9dc2019-08-06 08:42:19 +01001415 return i915_drm_resume(&i915->drm);
Zhenyu Wangcbda12d2009-12-16 13:36:10 +08001416}
1417
Chris Wilson1f19ac22016-05-14 07:26:32 +01001418/* freeze: before creating the hibernation_image */
David Weinehallc49d13e2016-08-22 13:32:42 +03001419static int i915_pm_freeze(struct device *kdev)
Chris Wilson1f19ac22016-05-14 07:26:32 +01001420{
Chris Wilson361f9dc2019-08-06 08:42:19 +01001421 struct drm_i915_private *i915 = kdev_to_i915(kdev);
Chris Wilson6a800ea2016-09-21 14:51:07 +01001422 int ret;
1423
Chris Wilson361f9dc2019-08-06 08:42:19 +01001424 if (i915->drm.switch_power_state != DRM_SWITCH_POWER_OFF) {
1425 ret = i915_drm_suspend(&i915->drm);
Imre Deakdd9f31c2017-08-16 17:46:07 +03001426 if (ret)
1427 return ret;
1428 }
Chris Wilson6a800ea2016-09-21 14:51:07 +01001429
Chris Wilson361f9dc2019-08-06 08:42:19 +01001430 ret = i915_gem_freeze(i915);
Chris Wilson6a800ea2016-09-21 14:51:07 +01001431 if (ret)
1432 return ret;
1433
1434 return 0;
Chris Wilson1f19ac22016-05-14 07:26:32 +01001435}
1436
David Weinehallc49d13e2016-08-22 13:32:42 +03001437static int i915_pm_freeze_late(struct device *kdev)
Chris Wilson1f19ac22016-05-14 07:26:32 +01001438{
Chris Wilson361f9dc2019-08-06 08:42:19 +01001439 struct drm_i915_private *i915 = kdev_to_i915(kdev);
Chris Wilson461fb992016-05-14 07:26:33 +01001440 int ret;
1441
Chris Wilson361f9dc2019-08-06 08:42:19 +01001442 if (i915->drm.switch_power_state != DRM_SWITCH_POWER_OFF) {
1443 ret = i915_drm_suspend_late(&i915->drm, true);
Imre Deakdd9f31c2017-08-16 17:46:07 +03001444 if (ret)
1445 return ret;
1446 }
Chris Wilson461fb992016-05-14 07:26:33 +01001447
Chris Wilson361f9dc2019-08-06 08:42:19 +01001448 ret = i915_gem_freeze_late(i915);
Chris Wilson461fb992016-05-14 07:26:33 +01001449 if (ret)
1450 return ret;
1451
1452 return 0;
Chris Wilson1f19ac22016-05-14 07:26:32 +01001453}
1454
1455/* thaw: called after creating the hibernation image, but before turning off. */
David Weinehallc49d13e2016-08-22 13:32:42 +03001456static int i915_pm_thaw_early(struct device *kdev)
Chris Wilson1f19ac22016-05-14 07:26:32 +01001457{
David Weinehallc49d13e2016-08-22 13:32:42 +03001458 return i915_pm_resume_early(kdev);
Chris Wilson1f19ac22016-05-14 07:26:32 +01001459}
1460
David Weinehallc49d13e2016-08-22 13:32:42 +03001461static int i915_pm_thaw(struct device *kdev)
Chris Wilson1f19ac22016-05-14 07:26:32 +01001462{
David Weinehallc49d13e2016-08-22 13:32:42 +03001463 return i915_pm_resume(kdev);
Chris Wilson1f19ac22016-05-14 07:26:32 +01001464}
1465
1466/* restore: called after loading the hibernation image. */
David Weinehallc49d13e2016-08-22 13:32:42 +03001467static int i915_pm_restore_early(struct device *kdev)
Chris Wilson1f19ac22016-05-14 07:26:32 +01001468{
David Weinehallc49d13e2016-08-22 13:32:42 +03001469 return i915_pm_resume_early(kdev);
Chris Wilson1f19ac22016-05-14 07:26:32 +01001470}
1471
David Weinehallc49d13e2016-08-22 13:32:42 +03001472static int i915_pm_restore(struct device *kdev)
Chris Wilson1f19ac22016-05-14 07:26:32 +01001473{
David Weinehallc49d13e2016-08-22 13:32:42 +03001474 return i915_pm_resume(kdev);
Chris Wilson1f19ac22016-05-14 07:26:32 +01001475}
1476
David Weinehallc49d13e2016-08-22 13:32:42 +03001477static int intel_runtime_suspend(struct device *kdev)
Paulo Zanoni8a187452013-12-06 20:32:13 -02001478{
Chris Wilson361f9dc2019-08-06 08:42:19 +01001479 struct drm_i915_private *dev_priv = kdev_to_i915(kdev);
Daniele Ceraolo Spurio1bf676c2019-06-13 16:21:52 -07001480 struct intel_runtime_pm *rpm = &dev_priv->runtime_pm;
Jani Nikulafb5f4322020-02-12 16:40:57 +02001481 int ret;
Paulo Zanoni8a187452013-12-06 20:32:13 -02001482
Pankaj Bharadiya48a1b8d2020-01-15 09:14:53 +05301483 if (drm_WARN_ON_ONCE(&dev_priv->drm, !HAS_RUNTIME_PM(dev_priv)))
Imre Deak604effb2014-08-26 13:26:56 +03001484 return -ENODEV;
1485
Wambui Karuga00376cc2020-01-31 12:34:12 +03001486 drm_dbg_kms(&dev_priv->drm, "Suspending device\n");
Paulo Zanoni8a187452013-12-06 20:32:13 -02001487
Daniele Ceraolo Spurio91026502019-06-13 16:21:51 -07001488 disable_rpm_wakeref_asserts(rpm);
Imre Deak1f814da2015-12-16 02:52:19 +02001489
Imre Deakd6102972014-05-07 19:57:49 +03001490 /*
1491 * We are safe here against re-faults, since the fault handler takes
1492 * an RPM reference.
1493 */
Chris Wilson7c108fd2016-10-24 13:42:18 +01001494 i915_gem_runtime_suspend(dev_priv);
Imre Deakd6102972014-05-07 19:57:49 +03001495
Daniele Ceraolo Spurio9dfe3452019-07-31 17:57:09 -07001496 intel_gt_runtime_suspend(&dev_priv->gt);
Alex Daia1c41992015-09-30 09:46:37 -07001497
Imre Deak2eb52522014-11-19 15:30:05 +02001498 intel_runtime_pm_disable_interrupts(dev_priv);
Imre Deakb5478bc2014-04-14 20:24:37 +03001499
Daniele Ceraolo Spuriof7de5022019-03-19 11:35:37 -07001500 intel_uncore_suspend(&dev_priv->uncore);
Hans de Goede01c799c2017-11-14 14:55:18 +01001501
Rodrigo Vivi071b68c2019-08-06 15:22:08 +03001502 intel_display_power_suspend(dev_priv);
1503
Jani Nikulafb5f4322020-02-12 16:40:57 +02001504 ret = vlv_suspend_complete(dev_priv);
Imre Deak0ab9cfe2014-04-15 16:39:45 +03001505 if (ret) {
Wambui Karuga00376cc2020-01-31 12:34:12 +03001506 drm_err(&dev_priv->drm,
1507 "Runtime suspend failed, disabling it (%d)\n", ret);
Daniele Ceraolo Spuriof7de5022019-03-19 11:35:37 -07001508 intel_uncore_runtime_resume(&dev_priv->uncore);
Hans de Goede01c799c2017-11-14 14:55:18 +01001509
Daniel Vetterb9632912014-09-30 10:56:44 +02001510 intel_runtime_pm_enable_interrupts(dev_priv);
Imre Deak0ab9cfe2014-04-15 16:39:45 +03001511
Daniele Ceraolo Spurio9dfe3452019-07-31 17:57:09 -07001512 intel_gt_runtime_resume(&dev_priv->gt);
Sagar Arun Kamble1ed21cb2018-01-24 21:16:57 +05301513
Daniele Ceraolo Spurio91026502019-06-13 16:21:51 -07001514 enable_rpm_wakeref_asserts(rpm);
Imre Deak1f814da2015-12-16 02:52:19 +02001515
Imre Deak0ab9cfe2014-04-15 16:39:45 +03001516 return ret;
1517 }
Paulo Zanonia8a8bd52014-03-07 20:08:05 -03001518
Daniele Ceraolo Spurio91026502019-06-13 16:21:51 -07001519 enable_rpm_wakeref_asserts(rpm);
Janusz Krzysztofik3b58a942019-07-12 13:24:28 +02001520 intel_runtime_pm_driver_release(rpm);
Mika Kuoppala55ec45c2015-12-15 16:25:08 +02001521
Daniele Ceraolo Spurio2cf7bf62019-03-25 14:49:34 -07001522 if (intel_uncore_arm_unclaimed_mmio_detection(&dev_priv->uncore))
Wambui Karuga00376cc2020-01-31 12:34:12 +03001523 drm_err(&dev_priv->drm,
1524 "Unclaimed access detected prior to suspending\n");
Mika Kuoppala55ec45c2015-12-15 16:25:08 +02001525
Daniele Ceraolo Spurio91026502019-06-13 16:21:51 -07001526 rpm->suspended = true;
Kristen Carlson Accardi1fb23622014-01-14 15:36:15 -08001527
1528 /*
Paulo Zanonic8a0bd42014-08-21 17:09:38 -03001529 * FIXME: We really should find a document that references the arguments
1530 * used below!
Kristen Carlson Accardi1fb23622014-01-14 15:36:15 -08001531 */
Chris Wilson6f9f4b72016-05-23 15:08:09 +01001532 if (IS_BROADWELL(dev_priv)) {
Paulo Zanonid37ae192015-07-30 18:20:29 -03001533 /*
1534 * On Broadwell, if we use PCI_D1 the PCH DDI ports will stop
1535 * being detected, and the call we do at intel_runtime_resume()
1536 * won't be able to restore them. Since PCI_D3hot matches the
1537 * actual specification and appears to be working, use it.
1538 */
Chris Wilson6f9f4b72016-05-23 15:08:09 +01001539 intel_opregion_notify_adapter(dev_priv, PCI_D3hot);
Paulo Zanonid37ae192015-07-30 18:20:29 -03001540 } else {
Paulo Zanonic8a0bd42014-08-21 17:09:38 -03001541 /*
1542 * current versions of firmware which depend on this opregion
1543 * notification have repurposed the D1 definition to mean
1544 * "runtime suspended" vs. what you would normally expect (D3)
1545 * to distinguish it from notifications that might be sent via
1546 * the suspend path.
1547 */
Chris Wilson6f9f4b72016-05-23 15:08:09 +01001548 intel_opregion_notify_adapter(dev_priv, PCI_D1);
Paulo Zanonic8a0bd42014-08-21 17:09:38 -03001549 }
Paulo Zanoni8a187452013-12-06 20:32:13 -02001550
Daniele Ceraolo Spuriof568eee2019-03-19 11:35:35 -07001551 assert_forcewakes_inactive(&dev_priv->uncore);
Chris Wilsondc9fb092015-01-16 11:34:34 +02001552
Ander Conselvan de Oliveira21d6e0b2017-01-20 16:28:43 +02001553 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv))
Ville Syrjälä4c8d4652020-10-13 21:11:37 +03001554 intel_hpd_poll_enable(dev_priv);
Lyude19625e82016-06-21 17:03:44 -04001555
Wambui Karuga00376cc2020-01-31 12:34:12 +03001556 drm_dbg_kms(&dev_priv->drm, "Device suspended\n");
Paulo Zanoni8a187452013-12-06 20:32:13 -02001557 return 0;
1558}
1559
David Weinehallc49d13e2016-08-22 13:32:42 +03001560static int intel_runtime_resume(struct device *kdev)
Paulo Zanoni8a187452013-12-06 20:32:13 -02001561{
Chris Wilson361f9dc2019-08-06 08:42:19 +01001562 struct drm_i915_private *dev_priv = kdev_to_i915(kdev);
Daniele Ceraolo Spurio1bf676c2019-06-13 16:21:52 -07001563 struct intel_runtime_pm *rpm = &dev_priv->runtime_pm;
Jani Nikulafb5f4322020-02-12 16:40:57 +02001564 int ret;
Paulo Zanoni8a187452013-12-06 20:32:13 -02001565
Pankaj Bharadiya48a1b8d2020-01-15 09:14:53 +05301566 if (drm_WARN_ON_ONCE(&dev_priv->drm, !HAS_RUNTIME_PM(dev_priv)))
Imre Deak604effb2014-08-26 13:26:56 +03001567 return -ENODEV;
Paulo Zanoni8a187452013-12-06 20:32:13 -02001568
Wambui Karuga00376cc2020-01-31 12:34:12 +03001569 drm_dbg_kms(&dev_priv->drm, "Resuming device\n");
Paulo Zanoni8a187452013-12-06 20:32:13 -02001570
Pankaj Bharadiya48a1b8d2020-01-15 09:14:53 +05301571 drm_WARN_ON_ONCE(&dev_priv->drm, atomic_read(&rpm->wakeref_count));
Daniele Ceraolo Spurio91026502019-06-13 16:21:51 -07001572 disable_rpm_wakeref_asserts(rpm);
Imre Deak1f814da2015-12-16 02:52:19 +02001573
Chris Wilson6f9f4b72016-05-23 15:08:09 +01001574 intel_opregion_notify_adapter(dev_priv, PCI_D0);
Daniele Ceraolo Spurio91026502019-06-13 16:21:51 -07001575 rpm->suspended = false;
Daniele Ceraolo Spurio2cf7bf62019-03-25 14:49:34 -07001576 if (intel_uncore_unclaimed_mmio(&dev_priv->uncore))
Wambui Karuga00376cc2020-01-31 12:34:12 +03001577 drm_dbg(&dev_priv->drm,
1578 "Unclaimed access during suspend, bios?\n");
Paulo Zanoni8a187452013-12-06 20:32:13 -02001579
Rodrigo Vivi071b68c2019-08-06 15:22:08 +03001580 intel_display_power_resume(dev_priv);
1581
Jani Nikulafb5f4322020-02-12 16:40:57 +02001582 ret = vlv_resume_prepare(dev_priv, true);
Paulo Zanoni1a5df182014-10-27 17:54:32 -02001583
Daniele Ceraolo Spuriof7de5022019-03-19 11:35:37 -07001584 intel_uncore_runtime_resume(&dev_priv->uncore);
Hans de Goedebedf4d72017-11-14 14:55:17 +01001585
Sagar Arun Kamble1ed21cb2018-01-24 21:16:57 +05301586 intel_runtime_pm_enable_interrupts(dev_priv);
1587
Imre Deak0ab9cfe2014-04-15 16:39:45 +03001588 /*
1589 * No point of rolling back things in case of an error, as the best
1590 * we can do is to hope that things will still work (and disable RPM).
1591 */
Daniele Ceraolo Spurio9dfe3452019-07-31 17:57:09 -07001592 intel_gt_runtime_resume(&dev_priv->gt);
Imre Deak92b806d2014-04-14 20:24:39 +03001593
Ville Syrjälä08d8a232015-08-27 23:56:08 +03001594 /*
1595 * On VLV/CHV display interrupts are part of the display
1596 * power well, so hpd is reinitialized from there. For
1597 * everyone else do it here.
1598 */
Ville Syrjälä4c8d4652020-10-13 21:11:37 +03001599 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä08d8a232015-08-27 23:56:08 +03001600 intel_hpd_init(dev_priv);
Ville Syrjälä4c8d4652020-10-13 21:11:37 +03001601 intel_hpd_poll_disable(dev_priv);
1602 }
Ville Syrjälä08d8a232015-08-27 23:56:08 +03001603
Kumar, Mahesh2503a0f2017-08-17 19:15:28 +05301604 intel_enable_ipc(dev_priv);
1605
Daniele Ceraolo Spurio91026502019-06-13 16:21:51 -07001606 enable_rpm_wakeref_asserts(rpm);
Imre Deak1f814da2015-12-16 02:52:19 +02001607
Imre Deak0ab9cfe2014-04-15 16:39:45 +03001608 if (ret)
Wambui Karuga00376cc2020-01-31 12:34:12 +03001609 drm_err(&dev_priv->drm,
1610 "Runtime resume failed, disabling it (%d)\n", ret);
Imre Deak0ab9cfe2014-04-15 16:39:45 +03001611 else
Wambui Karuga00376cc2020-01-31 12:34:12 +03001612 drm_dbg_kms(&dev_priv->drm, "Device resumed\n");
Imre Deak0ab9cfe2014-04-15 16:39:45 +03001613
1614 return ret;
Paulo Zanoni8a187452013-12-06 20:32:13 -02001615}
1616
Chris Wilson42f55512016-06-24 14:00:26 +01001617const struct dev_pm_ops i915_pm_ops = {
Imre Deak5545dbb2014-10-23 19:23:28 +03001618 /*
1619 * S0ix (via system suspend) and S3 event handlers [PMSG_SUSPEND,
1620 * PMSG_RESUME]
1621 */
Chris Wilson73b66f82018-05-25 10:26:29 +01001622 .prepare = i915_pm_prepare,
Akshay Joshi0206e352011-08-16 15:34:10 -04001623 .suspend = i915_pm_suspend,
Imre Deak76c4b252014-04-01 19:55:22 +03001624 .suspend_late = i915_pm_suspend_late,
1625 .resume_early = i915_pm_resume_early,
Akshay Joshi0206e352011-08-16 15:34:10 -04001626 .resume = i915_pm_resume,
Imre Deak5545dbb2014-10-23 19:23:28 +03001627
1628 /*
1629 * S4 event handlers
1630 * @freeze, @freeze_late : called (1) before creating the
1631 * hibernation image [PMSG_FREEZE] and
1632 * (2) after rebooting, before restoring
1633 * the image [PMSG_QUIESCE]
1634 * @thaw, @thaw_early : called (1) after creating the hibernation
1635 * image, before writing it [PMSG_THAW]
1636 * and (2) after failing to create or
1637 * restore the image [PMSG_RECOVER]
1638 * @poweroff, @poweroff_late: called after writing the hibernation
1639 * image, before rebooting [PMSG_HIBERNATE]
1640 * @restore, @restore_early : called after rebooting and restoring the
1641 * hibernation image [PMSG_RESTORE]
1642 */
Chris Wilson1f19ac22016-05-14 07:26:32 +01001643 .freeze = i915_pm_freeze,
1644 .freeze_late = i915_pm_freeze_late,
1645 .thaw_early = i915_pm_thaw_early,
1646 .thaw = i915_pm_thaw,
Imre Deak36d61e62014-10-23 19:23:24 +03001647 .poweroff = i915_pm_suspend,
Imre Deakab3be732015-03-02 13:04:41 +02001648 .poweroff_late = i915_pm_poweroff_late,
Chris Wilson1f19ac22016-05-14 07:26:32 +01001649 .restore_early = i915_pm_restore_early,
1650 .restore = i915_pm_restore,
Imre Deak5545dbb2014-10-23 19:23:28 +03001651
1652 /* S0ix (via runtime suspend) event handlers */
Paulo Zanoni97bea202014-03-07 20:12:33 -03001653 .runtime_suspend = intel_runtime_suspend,
1654 .runtime_resume = intel_runtime_resume,
Zhenyu Wangcbda12d2009-12-16 13:36:10 +08001655};
1656
Arjan van de Vene08e96d2011-10-31 07:28:57 -07001657static const struct file_operations i915_driver_fops = {
1658 .owner = THIS_MODULE,
1659 .open = drm_open,
Chris Wilson7a2c65dd2020-01-24 12:56:26 +00001660 .release = drm_release_noglobal,
Arjan van de Vene08e96d2011-10-31 07:28:57 -07001661 .unlocked_ioctl = drm_ioctl,
Abdiel Janulguecc662122019-12-04 12:00:32 +00001662 .mmap = i915_gem_mmap,
Arjan van de Vene08e96d2011-10-31 07:28:57 -07001663 .poll = drm_poll,
Arjan van de Vene08e96d2011-10-31 07:28:57 -07001664 .read = drm_read,
Jani Nikula062705b2020-02-27 19:00:45 +02001665 .compat_ioctl = i915_ioc32_compat_ioctl,
Arjan van de Vene08e96d2011-10-31 07:28:57 -07001666 .llseek = noop_llseek,
1667};
1668
Chris Wilson0673ad42016-06-24 14:00:22 +01001669static int
1670i915_gem_reject_pin_ioctl(struct drm_device *dev, void *data,
1671 struct drm_file *file)
1672{
1673 return -ENODEV;
1674}
1675
1676static const struct drm_ioctl_desc i915_ioctls[] = {
1677 DRM_IOCTL_DEF_DRV(I915_INIT, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
1678 DRM_IOCTL_DEF_DRV(I915_FLUSH, drm_noop, DRM_AUTH),
1679 DRM_IOCTL_DEF_DRV(I915_FLIP, drm_noop, DRM_AUTH),
1680 DRM_IOCTL_DEF_DRV(I915_BATCHBUFFER, drm_noop, DRM_AUTH),
1681 DRM_IOCTL_DEF_DRV(I915_IRQ_EMIT, drm_noop, DRM_AUTH),
1682 DRM_IOCTL_DEF_DRV(I915_IRQ_WAIT, drm_noop, DRM_AUTH),
Christian Königb972fff2019-04-17 13:25:24 +02001683 DRM_IOCTL_DEF_DRV(I915_GETPARAM, i915_getparam_ioctl, DRM_RENDER_ALLOW),
Chris Wilson0673ad42016-06-24 14:00:22 +01001684 DRM_IOCTL_DEF_DRV(I915_SETPARAM, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
1685 DRM_IOCTL_DEF_DRV(I915_ALLOC, drm_noop, DRM_AUTH),
1686 DRM_IOCTL_DEF_DRV(I915_FREE, drm_noop, DRM_AUTH),
1687 DRM_IOCTL_DEF_DRV(I915_INIT_HEAP, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
1688 DRM_IOCTL_DEF_DRV(I915_CMDBUFFER, drm_noop, DRM_AUTH),
1689 DRM_IOCTL_DEF_DRV(I915_DESTROY_HEAP, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
1690 DRM_IOCTL_DEF_DRV(I915_SET_VBLANK_PIPE, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
1691 DRM_IOCTL_DEF_DRV(I915_GET_VBLANK_PIPE, drm_noop, DRM_AUTH),
1692 DRM_IOCTL_DEF_DRV(I915_VBLANK_SWAP, drm_noop, DRM_AUTH),
1693 DRM_IOCTL_DEF_DRV(I915_HWS_ADDR, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
1694 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 +02001695 DRM_IOCTL_DEF_DRV(I915_GEM_EXECBUFFER, i915_gem_execbuffer_ioctl, DRM_AUTH),
Christian Königb972fff2019-04-17 13:25:24 +02001696 DRM_IOCTL_DEF_DRV(I915_GEM_EXECBUFFER2_WR, i915_gem_execbuffer2_ioctl, DRM_RENDER_ALLOW),
Chris Wilson0673ad42016-06-24 14:00:22 +01001697 DRM_IOCTL_DEF_DRV(I915_GEM_PIN, i915_gem_reject_pin_ioctl, DRM_AUTH|DRM_ROOT_ONLY),
1698 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 +02001699 DRM_IOCTL_DEF_DRV(I915_GEM_BUSY, i915_gem_busy_ioctl, DRM_RENDER_ALLOW),
Chris Wilson0673ad42016-06-24 14:00:22 +01001700 DRM_IOCTL_DEF_DRV(I915_GEM_SET_CACHING, i915_gem_set_caching_ioctl, DRM_RENDER_ALLOW),
1701 DRM_IOCTL_DEF_DRV(I915_GEM_GET_CACHING, i915_gem_get_caching_ioctl, DRM_RENDER_ALLOW),
Christian Königb972fff2019-04-17 13:25:24 +02001702 DRM_IOCTL_DEF_DRV(I915_GEM_THROTTLE, i915_gem_throttle_ioctl, DRM_RENDER_ALLOW),
Chris Wilson0673ad42016-06-24 14:00:22 +01001703 DRM_IOCTL_DEF_DRV(I915_GEM_ENTERVT, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
1704 DRM_IOCTL_DEF_DRV(I915_GEM_LEAVEVT, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
1705 DRM_IOCTL_DEF_DRV(I915_GEM_CREATE, i915_gem_create_ioctl, DRM_RENDER_ALLOW),
1706 DRM_IOCTL_DEF_DRV(I915_GEM_PREAD, i915_gem_pread_ioctl, DRM_RENDER_ALLOW),
1707 DRM_IOCTL_DEF_DRV(I915_GEM_PWRITE, i915_gem_pwrite_ioctl, DRM_RENDER_ALLOW),
1708 DRM_IOCTL_DEF_DRV(I915_GEM_MMAP, i915_gem_mmap_ioctl, DRM_RENDER_ALLOW),
Abdiel Janulguecc662122019-12-04 12:00:32 +00001709 DRM_IOCTL_DEF_DRV(I915_GEM_MMAP_OFFSET, i915_gem_mmap_offset_ioctl, DRM_RENDER_ALLOW),
Chris Wilson0673ad42016-06-24 14:00:22 +01001710 DRM_IOCTL_DEF_DRV(I915_GEM_SET_DOMAIN, i915_gem_set_domain_ioctl, DRM_RENDER_ALLOW),
1711 DRM_IOCTL_DEF_DRV(I915_GEM_SW_FINISH, i915_gem_sw_finish_ioctl, DRM_RENDER_ALLOW),
Chris Wilson111dbca2017-01-10 12:10:44 +00001712 DRM_IOCTL_DEF_DRV(I915_GEM_SET_TILING, i915_gem_set_tiling_ioctl, DRM_RENDER_ALLOW),
1713 DRM_IOCTL_DEF_DRV(I915_GEM_GET_TILING, i915_gem_get_tiling_ioctl, DRM_RENDER_ALLOW),
Chris Wilson0673ad42016-06-24 14:00:22 +01001714 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 +02001715 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 +01001716 DRM_IOCTL_DEF_DRV(I915_GEM_MADVISE, i915_gem_madvise_ioctl, DRM_RENDER_ALLOW),
Daniel Vetter0cd54b02018-04-20 08:51:57 +02001717 DRM_IOCTL_DEF_DRV(I915_OVERLAY_PUT_IMAGE, intel_overlay_put_image_ioctl, DRM_MASTER),
1718 DRM_IOCTL_DEF_DRV(I915_OVERLAY_ATTRS, intel_overlay_attrs_ioctl, DRM_MASTER),
1719 DRM_IOCTL_DEF_DRV(I915_SET_SPRITE_COLORKEY, intel_sprite_set_colorkey_ioctl, DRM_MASTER),
1720 DRM_IOCTL_DEF_DRV(I915_GET_SPRITE_COLORKEY, drm_noop, DRM_MASTER),
Christian Königb972fff2019-04-17 13:25:24 +02001721 DRM_IOCTL_DEF_DRV(I915_GEM_WAIT, i915_gem_wait_ioctl, DRM_RENDER_ALLOW),
Chris Wilsonb9171542019-03-22 09:23:24 +00001722 DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_CREATE_EXT, i915_gem_context_create_ioctl, DRM_RENDER_ALLOW),
Chris Wilson0673ad42016-06-24 14:00:22 +01001723 DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_DESTROY, i915_gem_context_destroy_ioctl, DRM_RENDER_ALLOW),
1724 DRM_IOCTL_DEF_DRV(I915_REG_READ, i915_reg_read_ioctl, DRM_RENDER_ALLOW),
1725 DRM_IOCTL_DEF_DRV(I915_GET_RESET_STATS, i915_gem_context_reset_stats_ioctl, DRM_RENDER_ALLOW),
1726 DRM_IOCTL_DEF_DRV(I915_GEM_USERPTR, i915_gem_userptr_ioctl, DRM_RENDER_ALLOW),
1727 DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_GETPARAM, i915_gem_context_getparam_ioctl, DRM_RENDER_ALLOW),
1728 DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_SETPARAM, i915_gem_context_setparam_ioctl, DRM_RENDER_ALLOW),
Robert Braggeec688e2016-11-07 19:49:47 +00001729 DRM_IOCTL_DEF_DRV(I915_PERF_OPEN, i915_perf_open_ioctl, DRM_RENDER_ALLOW),
Emil Velikovb40237562019-05-22 16:47:01 +01001730 DRM_IOCTL_DEF_DRV(I915_PERF_ADD_CONFIG, i915_perf_add_config_ioctl, DRM_RENDER_ALLOW),
1731 DRM_IOCTL_DEF_DRV(I915_PERF_REMOVE_CONFIG, i915_perf_remove_config_ioctl, DRM_RENDER_ALLOW),
1732 DRM_IOCTL_DEF_DRV(I915_QUERY, i915_query_ioctl, DRM_RENDER_ALLOW),
Chris Wilson7f3f317a2019-05-21 22:11:25 +01001733 DRM_IOCTL_DEF_DRV(I915_GEM_VM_CREATE, i915_gem_vm_create_ioctl, DRM_RENDER_ALLOW),
1734 DRM_IOCTL_DEF_DRV(I915_GEM_VM_DESTROY, i915_gem_vm_destroy_ioctl, DRM_RENDER_ALLOW),
Chris Wilson0673ad42016-06-24 14:00:22 +01001735};
1736
Daniel Vetter70a59dd2020-11-04 11:04:24 +01001737static const struct drm_driver driver = {
Michael Witten0c547812011-08-25 17:55:54 +00001738 /* Don't use MTRRs here; the Xserver or userspace app should
1739 * deal with them for Intel hardware.
Dave Airlie792d2b92005-11-11 23:30:27 +11001740 */
Eric Anholt673a3942008-07-30 12:06:12 -07001741 .driver_features =
Daniel Vetter0424fda2019-06-17 17:39:24 +02001742 DRIVER_GEM |
Lionel Landwerlin13149e82020-08-04 11:59:54 +03001743 DRIVER_RENDER | DRIVER_MODESET | DRIVER_ATOMIC | DRIVER_SYNCOBJ |
1744 DRIVER_SYNCOBJ_TIMELINE,
Chris Wilsoncad36882017-02-10 16:35:21 +00001745 .release = i915_driver_release,
Eric Anholt673a3942008-07-30 12:06:12 -07001746 .open = i915_driver_open,
Dave Airlie22eae942005-11-10 22:16:34 +11001747 .lastclose = i915_driver_lastclose,
Eric Anholt673a3942008-07-30 12:06:12 -07001748 .postclose = i915_driver_postclose,
Rafael J. Wysockid8e29202010-01-09 00:45:33 +01001749
Daniel Vetter1286ff72012-05-10 15:25:09 +02001750 .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
1751 .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
Daniel Vetter1286ff72012-05-10 15:25:09 +02001752 .gem_prime_import = i915_gem_prime_import,
1753
Dave Airlieff72145b2011-02-07 12:16:14 +10001754 .dumb_create = i915_gem_dumb_create,
Abdiel Janulguecc662122019-12-04 12:00:32 +00001755 .dumb_map_offset = i915_gem_dumb_mmap_offset,
1756
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757 .ioctls = i915_ioctls,
Chris Wilson0673ad42016-06-24 14:00:22 +01001758 .num_ioctls = ARRAY_SIZE(i915_ioctls),
Arjan van de Vene08e96d2011-10-31 07:28:57 -07001759 .fops = &i915_driver_fops,
Dave Airlie22eae942005-11-10 22:16:34 +11001760 .name = DRIVER_NAME,
1761 .desc = DRIVER_DESC,
1762 .date = DRIVER_DATE,
1763 .major = DRIVER_MAJOR,
1764 .minor = DRIVER_MINOR,
1765 .patchlevel = DRIVER_PATCHLEVEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766};