drm/i915: Force CL2 off in CHV x1 PHY
[deliverable/linux.git] / drivers / gpu / drm / i915 / i915_drv.c
CommitLineData
1da177e4
LT
1/* i915_drv.c -- i830,i845,i855,i865,i915 driver -*- linux-c -*-
2 */
0d6aa60b 3/*
bc54fd1a 4 *
1da177e4
LT
5 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * All Rights Reserved.
bc54fd1a
DA
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sub license, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
15 *
16 * The above copyright notice and this permission notice (including the
17 * next paragraph) shall be included in all copies or substantial portions
18 * of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
23 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
24 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 *
0d6aa60b 28 */
1da177e4 29
5669fcac 30#include <linux/device.h>
e5747e3a 31#include <linux/acpi.h>
760285e7
DH
32#include <drm/drmP.h>
33#include <drm/i915_drm.h>
1da177e4 34#include "i915_drv.h"
990bbdad 35#include "i915_trace.h"
f49f0586 36#include "intel_drv.h"
1da177e4 37
79e53945 38#include <linux/console.h>
e0cd3608 39#include <linux/module.h>
d6102977 40#include <linux/pm_runtime.h>
760285e7 41#include <drm/drm_crtc_helper.h>
79e53945 42
112b715e
KH
43static struct drm_driver driver;
44
a57c774a
AK
45#define GEN_DEFAULT_PIPEOFFSETS \
46 .pipe_offsets = { PIPE_A_OFFSET, PIPE_B_OFFSET, \
47 PIPE_C_OFFSET, PIPE_EDP_OFFSET }, \
48 .trans_offsets = { TRANSCODER_A_OFFSET, TRANSCODER_B_OFFSET, \
49 TRANSCODER_C_OFFSET, TRANSCODER_EDP_OFFSET }, \
a57c774a
AK
50 .palette_offsets = { PALETTE_A_OFFSET, PALETTE_B_OFFSET }
51
84fd4f4e
RB
52#define GEN_CHV_PIPEOFFSETS \
53 .pipe_offsets = { PIPE_A_OFFSET, PIPE_B_OFFSET, \
54 CHV_PIPE_C_OFFSET }, \
55 .trans_offsets = { TRANSCODER_A_OFFSET, TRANSCODER_B_OFFSET, \
56 CHV_TRANSCODER_C_OFFSET, }, \
84fd4f4e
RB
57 .palette_offsets = { PALETTE_A_OFFSET, PALETTE_B_OFFSET, \
58 CHV_PALETTE_C_OFFSET }
a57c774a 59
5efb3e28
VS
60#define CURSOR_OFFSETS \
61 .cursor_offsets = { CURSOR_A_OFFSET, CURSOR_B_OFFSET, CHV_CURSOR_C_OFFSET }
62
63#define IVB_CURSOR_OFFSETS \
64 .cursor_offsets = { CURSOR_A_OFFSET, IVB_CURSOR_B_OFFSET, IVB_CURSOR_C_OFFSET }
65
9a7e8492 66static const struct intel_device_info intel_i830_info = {
7eb552ae 67 .gen = 2, .is_mobile = 1, .cursor_needs_physical = 1, .num_pipes = 2,
31578148 68 .has_overlay = 1, .overlay_needs_physical = 1,
73ae478c 69 .ring_mask = RENDER_RING,
a57c774a 70 GEN_DEFAULT_PIPEOFFSETS,
5efb3e28 71 CURSOR_OFFSETS,
cfdf1fa2
KH
72};
73
9a7e8492 74static const struct intel_device_info intel_845g_info = {
7eb552ae 75 .gen = 2, .num_pipes = 1,
31578148 76 .has_overlay = 1, .overlay_needs_physical = 1,
73ae478c 77 .ring_mask = RENDER_RING,
a57c774a 78 GEN_DEFAULT_PIPEOFFSETS,
5efb3e28 79 CURSOR_OFFSETS,
cfdf1fa2
KH
80};
81
9a7e8492 82static const struct intel_device_info intel_i85x_info = {
7eb552ae 83 .gen = 2, .is_i85x = 1, .is_mobile = 1, .num_pipes = 2,
5ce8ba7c 84 .cursor_needs_physical = 1,
31578148 85 .has_overlay = 1, .overlay_needs_physical = 1,
fd70d52a 86 .has_fbc = 1,
73ae478c 87 .ring_mask = RENDER_RING,
a57c774a 88 GEN_DEFAULT_PIPEOFFSETS,
5efb3e28 89 CURSOR_OFFSETS,
cfdf1fa2
KH
90};
91
9a7e8492 92static const struct intel_device_info intel_i865g_info = {
7eb552ae 93 .gen = 2, .num_pipes = 1,
31578148 94 .has_overlay = 1, .overlay_needs_physical = 1,
73ae478c 95 .ring_mask = RENDER_RING,
a57c774a 96 GEN_DEFAULT_PIPEOFFSETS,
5efb3e28 97 CURSOR_OFFSETS,
cfdf1fa2
KH
98};
99
9a7e8492 100static const struct intel_device_info intel_i915g_info = {
7eb552ae 101 .gen = 3, .is_i915g = 1, .cursor_needs_physical = 1, .num_pipes = 2,
31578148 102 .has_overlay = 1, .overlay_needs_physical = 1,
73ae478c 103 .ring_mask = RENDER_RING,
a57c774a 104 GEN_DEFAULT_PIPEOFFSETS,
5efb3e28 105 CURSOR_OFFSETS,
cfdf1fa2 106};
9a7e8492 107static const struct intel_device_info intel_i915gm_info = {
7eb552ae 108 .gen = 3, .is_mobile = 1, .num_pipes = 2,
b295d1b6 109 .cursor_needs_physical = 1,
31578148 110 .has_overlay = 1, .overlay_needs_physical = 1,
a6c45cf0 111 .supports_tv = 1,
fd70d52a 112 .has_fbc = 1,
73ae478c 113 .ring_mask = RENDER_RING,
a57c774a 114 GEN_DEFAULT_PIPEOFFSETS,
5efb3e28 115 CURSOR_OFFSETS,
cfdf1fa2 116};
9a7e8492 117static const struct intel_device_info intel_i945g_info = {
7eb552ae 118 .gen = 3, .has_hotplug = 1, .cursor_needs_physical = 1, .num_pipes = 2,
31578148 119 .has_overlay = 1, .overlay_needs_physical = 1,
73ae478c 120 .ring_mask = RENDER_RING,
a57c774a 121 GEN_DEFAULT_PIPEOFFSETS,
5efb3e28 122 CURSOR_OFFSETS,
cfdf1fa2 123};
9a7e8492 124static const struct intel_device_info intel_i945gm_info = {
7eb552ae 125 .gen = 3, .is_i945gm = 1, .is_mobile = 1, .num_pipes = 2,
b295d1b6 126 .has_hotplug = 1, .cursor_needs_physical = 1,
31578148 127 .has_overlay = 1, .overlay_needs_physical = 1,
a6c45cf0 128 .supports_tv = 1,
fd70d52a 129 .has_fbc = 1,
73ae478c 130 .ring_mask = RENDER_RING,
a57c774a 131 GEN_DEFAULT_PIPEOFFSETS,
5efb3e28 132 CURSOR_OFFSETS,
cfdf1fa2
KH
133};
134
9a7e8492 135static const struct intel_device_info intel_i965g_info = {
7eb552ae 136 .gen = 4, .is_broadwater = 1, .num_pipes = 2,
c96c3a8c 137 .has_hotplug = 1,
31578148 138 .has_overlay = 1,
73ae478c 139 .ring_mask = RENDER_RING,
a57c774a 140 GEN_DEFAULT_PIPEOFFSETS,
5efb3e28 141 CURSOR_OFFSETS,
cfdf1fa2
KH
142};
143
9a7e8492 144static const struct intel_device_info intel_i965gm_info = {
7eb552ae 145 .gen = 4, .is_crestline = 1, .num_pipes = 2,
e3c4e5dd 146 .is_mobile = 1, .has_fbc = 1, .has_hotplug = 1,
31578148 147 .has_overlay = 1,
a6c45cf0 148 .supports_tv = 1,
73ae478c 149 .ring_mask = RENDER_RING,
a57c774a 150 GEN_DEFAULT_PIPEOFFSETS,
5efb3e28 151 CURSOR_OFFSETS,
cfdf1fa2
KH
152};
153
9a7e8492 154static const struct intel_device_info intel_g33_info = {
7eb552ae 155 .gen = 3, .is_g33 = 1, .num_pipes = 2,
c96c3a8c 156 .need_gfx_hws = 1, .has_hotplug = 1,
31578148 157 .has_overlay = 1,
73ae478c 158 .ring_mask = RENDER_RING,
a57c774a 159 GEN_DEFAULT_PIPEOFFSETS,
5efb3e28 160 CURSOR_OFFSETS,
cfdf1fa2
KH
161};
162
9a7e8492 163static const struct intel_device_info intel_g45_info = {
7eb552ae 164 .gen = 4, .is_g4x = 1, .need_gfx_hws = 1, .num_pipes = 2,
c96c3a8c 165 .has_pipe_cxsr = 1, .has_hotplug = 1,
73ae478c 166 .ring_mask = RENDER_RING | BSD_RING,
a57c774a 167 GEN_DEFAULT_PIPEOFFSETS,
5efb3e28 168 CURSOR_OFFSETS,
cfdf1fa2
KH
169};
170
9a7e8492 171static const struct intel_device_info intel_gm45_info = {
7eb552ae 172 .gen = 4, .is_g4x = 1, .num_pipes = 2,
e3c4e5dd 173 .is_mobile = 1, .need_gfx_hws = 1, .has_fbc = 1,
c96c3a8c 174 .has_pipe_cxsr = 1, .has_hotplug = 1,
a6c45cf0 175 .supports_tv = 1,
73ae478c 176 .ring_mask = RENDER_RING | BSD_RING,
a57c774a 177 GEN_DEFAULT_PIPEOFFSETS,
5efb3e28 178 CURSOR_OFFSETS,
cfdf1fa2
KH
179};
180
9a7e8492 181static const struct intel_device_info intel_pineview_info = {
7eb552ae 182 .gen = 3, .is_g33 = 1, .is_pineview = 1, .is_mobile = 1, .num_pipes = 2,
c96c3a8c 183 .need_gfx_hws = 1, .has_hotplug = 1,
31578148 184 .has_overlay = 1,
a57c774a 185 GEN_DEFAULT_PIPEOFFSETS,
5efb3e28 186 CURSOR_OFFSETS,
cfdf1fa2
KH
187};
188
9a7e8492 189static const struct intel_device_info intel_ironlake_d_info = {
7eb552ae 190 .gen = 5, .num_pipes = 2,
5a117db7 191 .need_gfx_hws = 1, .has_hotplug = 1,
73ae478c 192 .ring_mask = RENDER_RING | BSD_RING,
a57c774a 193 GEN_DEFAULT_PIPEOFFSETS,
5efb3e28 194 CURSOR_OFFSETS,
cfdf1fa2
KH
195};
196
9a7e8492 197static const struct intel_device_info intel_ironlake_m_info = {
7eb552ae 198 .gen = 5, .is_mobile = 1, .num_pipes = 2,
e3c4e5dd 199 .need_gfx_hws = 1, .has_hotplug = 1,
c1a9f047 200 .has_fbc = 1,
73ae478c 201 .ring_mask = RENDER_RING | BSD_RING,
a57c774a 202 GEN_DEFAULT_PIPEOFFSETS,
5efb3e28 203 CURSOR_OFFSETS,
cfdf1fa2
KH
204};
205
9a7e8492 206static const struct intel_device_info intel_sandybridge_d_info = {
7eb552ae 207 .gen = 6, .num_pipes = 2,
c96c3a8c 208 .need_gfx_hws = 1, .has_hotplug = 1,
cbaef0f1 209 .has_fbc = 1,
73ae478c 210 .ring_mask = RENDER_RING | BSD_RING | BLT_RING,
3d29b842 211 .has_llc = 1,
a57c774a 212 GEN_DEFAULT_PIPEOFFSETS,
5efb3e28 213 CURSOR_OFFSETS,
f6e450a6
EA
214};
215
9a7e8492 216static const struct intel_device_info intel_sandybridge_m_info = {
7eb552ae 217 .gen = 6, .is_mobile = 1, .num_pipes = 2,
c96c3a8c 218 .need_gfx_hws = 1, .has_hotplug = 1,
9c04f015 219 .has_fbc = 1,
73ae478c 220 .ring_mask = RENDER_RING | BSD_RING | BLT_RING,
3d29b842 221 .has_llc = 1,
a57c774a 222 GEN_DEFAULT_PIPEOFFSETS,
5efb3e28 223 CURSOR_OFFSETS,
a13e4093
EA
224};
225
219f4fdb
BW
226#define GEN7_FEATURES \
227 .gen = 7, .num_pipes = 3, \
228 .need_gfx_hws = 1, .has_hotplug = 1, \
cbaef0f1 229 .has_fbc = 1, \
73ae478c 230 .ring_mask = RENDER_RING | BSD_RING | BLT_RING, \
ab484f8f 231 .has_llc = 1
219f4fdb 232
c76b615c 233static const struct intel_device_info intel_ivybridge_d_info = {
219f4fdb
BW
234 GEN7_FEATURES,
235 .is_ivybridge = 1,
a57c774a 236 GEN_DEFAULT_PIPEOFFSETS,
5efb3e28 237 IVB_CURSOR_OFFSETS,
c76b615c
JB
238};
239
240static const struct intel_device_info intel_ivybridge_m_info = {
219f4fdb
BW
241 GEN7_FEATURES,
242 .is_ivybridge = 1,
243 .is_mobile = 1,
a57c774a 244 GEN_DEFAULT_PIPEOFFSETS,
5efb3e28 245 IVB_CURSOR_OFFSETS,
c76b615c
JB
246};
247
999bcdea
BW
248static const struct intel_device_info intel_ivybridge_q_info = {
249 GEN7_FEATURES,
250 .is_ivybridge = 1,
251 .num_pipes = 0, /* legal, last one wins */
a57c774a 252 GEN_DEFAULT_PIPEOFFSETS,
5efb3e28 253 IVB_CURSOR_OFFSETS,
999bcdea
BW
254};
255
70a3eb7a 256static const struct intel_device_info intel_valleyview_m_info = {
219f4fdb
BW
257 GEN7_FEATURES,
258 .is_mobile = 1,
259 .num_pipes = 2,
70a3eb7a 260 .is_valleyview = 1,
fba5d532 261 .display_mmio_offset = VLV_DISPLAY_BASE,
cbaef0f1 262 .has_fbc = 0, /* legal, last one wins */
30ccd964 263 .has_llc = 0, /* legal, last one wins */
a57c774a 264 GEN_DEFAULT_PIPEOFFSETS,
5efb3e28 265 CURSOR_OFFSETS,
70a3eb7a
JB
266};
267
268static const struct intel_device_info intel_valleyview_d_info = {
219f4fdb
BW
269 GEN7_FEATURES,
270 .num_pipes = 2,
70a3eb7a 271 .is_valleyview = 1,
fba5d532 272 .display_mmio_offset = VLV_DISPLAY_BASE,
cbaef0f1 273 .has_fbc = 0, /* legal, last one wins */
30ccd964 274 .has_llc = 0, /* legal, last one wins */
a57c774a 275 GEN_DEFAULT_PIPEOFFSETS,
5efb3e28 276 CURSOR_OFFSETS,
70a3eb7a
JB
277};
278
4cae9ae0 279static const struct intel_device_info intel_haswell_d_info = {
219f4fdb
BW
280 GEN7_FEATURES,
281 .is_haswell = 1,
dd93be58 282 .has_ddi = 1,
30568c45 283 .has_fpga_dbg = 1,
73ae478c 284 .ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING,
a57c774a 285 GEN_DEFAULT_PIPEOFFSETS,
5efb3e28 286 IVB_CURSOR_OFFSETS,
4cae9ae0
ED
287};
288
289static const struct intel_device_info intel_haswell_m_info = {
219f4fdb
BW
290 GEN7_FEATURES,
291 .is_haswell = 1,
292 .is_mobile = 1,
dd93be58 293 .has_ddi = 1,
30568c45 294 .has_fpga_dbg = 1,
73ae478c 295 .ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING,
a57c774a 296 GEN_DEFAULT_PIPEOFFSETS,
5efb3e28 297 IVB_CURSOR_OFFSETS,
c76b615c
JB
298};
299
4d4dead6 300static const struct intel_device_info intel_broadwell_d_info = {
4b30553d 301 .gen = 8, .num_pipes = 3,
4d4dead6
BW
302 .need_gfx_hws = 1, .has_hotplug = 1,
303 .ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING,
304 .has_llc = 1,
305 .has_ddi = 1,
66bc2cab 306 .has_fpga_dbg = 1,
8f94d24b 307 .has_fbc = 1,
a57c774a 308 GEN_DEFAULT_PIPEOFFSETS,
5efb3e28 309 IVB_CURSOR_OFFSETS,
4d4dead6
BW
310};
311
312static const struct intel_device_info intel_broadwell_m_info = {
4b30553d 313 .gen = 8, .is_mobile = 1, .num_pipes = 3,
4d4dead6
BW
314 .need_gfx_hws = 1, .has_hotplug = 1,
315 .ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING,
316 .has_llc = 1,
317 .has_ddi = 1,
66bc2cab 318 .has_fpga_dbg = 1,
8f94d24b 319 .has_fbc = 1,
a57c774a 320 GEN_DEFAULT_PIPEOFFSETS,
15d24aa5 321 IVB_CURSOR_OFFSETS,
4d4dead6
BW
322};
323
fd3c269f
ZY
324static const struct intel_device_info intel_broadwell_gt3d_info = {
325 .gen = 8, .num_pipes = 3,
326 .need_gfx_hws = 1, .has_hotplug = 1,
845f74a7 327 .ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING | BSD2_RING,
fd3c269f
ZY
328 .has_llc = 1,
329 .has_ddi = 1,
66bc2cab 330 .has_fpga_dbg = 1,
fd3c269f
ZY
331 .has_fbc = 1,
332 GEN_DEFAULT_PIPEOFFSETS,
15d24aa5 333 IVB_CURSOR_OFFSETS,
fd3c269f
ZY
334};
335
336static const struct intel_device_info intel_broadwell_gt3m_info = {
337 .gen = 8, .is_mobile = 1, .num_pipes = 3,
338 .need_gfx_hws = 1, .has_hotplug = 1,
845f74a7 339 .ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING | BSD2_RING,
fd3c269f
ZY
340 .has_llc = 1,
341 .has_ddi = 1,
66bc2cab 342 .has_fpga_dbg = 1,
fd3c269f
ZY
343 .has_fbc = 1,
344 GEN_DEFAULT_PIPEOFFSETS,
5efb3e28 345 IVB_CURSOR_OFFSETS,
fd3c269f
ZY
346};
347
7d87a7f7 348static const struct intel_device_info intel_cherryview_info = {
07fddb14 349 .gen = 8, .num_pipes = 3,
7d87a7f7
VS
350 .need_gfx_hws = 1, .has_hotplug = 1,
351 .ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING,
352 .is_valleyview = 1,
353 .display_mmio_offset = VLV_DISPLAY_BASE,
84fd4f4e 354 GEN_CHV_PIPEOFFSETS,
5efb3e28 355 CURSOR_OFFSETS,
7d87a7f7
VS
356};
357
72bbf0af 358static const struct intel_device_info intel_skylake_info = {
7201c0b3 359 .is_skylake = 1,
72bbf0af
DL
360 .gen = 9, .num_pipes = 3,
361 .need_gfx_hws = 1, .has_hotplug = 1,
362 .ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING,
363 .has_llc = 1,
364 .has_ddi = 1,
043efb11 365 .has_fbc = 1,
72bbf0af
DL
366 GEN_DEFAULT_PIPEOFFSETS,
367 IVB_CURSOR_OFFSETS,
368};
369
719388e1 370static const struct intel_device_info intel_skylake_gt3_info = {
719388e1
DL
371 .is_skylake = 1,
372 .gen = 9, .num_pipes = 3,
373 .need_gfx_hws = 1, .has_hotplug = 1,
374 .ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING | BSD2_RING,
375 .has_llc = 1,
376 .has_ddi = 1,
377 .has_fbc = 1,
378 GEN_DEFAULT_PIPEOFFSETS,
379 IVB_CURSOR_OFFSETS,
380};
381
1347f5b4
DL
382static const struct intel_device_info intel_broxton_info = {
383 .is_preliminary = 1,
384 .gen = 9,
385 .need_gfx_hws = 1, .has_hotplug = 1,
386 .ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING,
387 .num_pipes = 3,
388 .has_ddi = 1,
ce89db2e 389 .has_fbc = 1,
1347f5b4
DL
390 GEN_DEFAULT_PIPEOFFSETS,
391 IVB_CURSOR_OFFSETS,
392};
393
a0a18075
JB
394/*
395 * Make sure any device matches here are from most specific to most
396 * general. For example, since the Quanta match is based on the subsystem
397 * and subvendor IDs, we need it to come before the more general IVB
398 * PCI ID matches, otherwise we'll use the wrong info struct above.
399 */
400#define INTEL_PCI_IDS \
401 INTEL_I830_IDS(&intel_i830_info), \
402 INTEL_I845G_IDS(&intel_845g_info), \
403 INTEL_I85X_IDS(&intel_i85x_info), \
404 INTEL_I865G_IDS(&intel_i865g_info), \
405 INTEL_I915G_IDS(&intel_i915g_info), \
406 INTEL_I915GM_IDS(&intel_i915gm_info), \
407 INTEL_I945G_IDS(&intel_i945g_info), \
408 INTEL_I945GM_IDS(&intel_i945gm_info), \
409 INTEL_I965G_IDS(&intel_i965g_info), \
410 INTEL_G33_IDS(&intel_g33_info), \
411 INTEL_I965GM_IDS(&intel_i965gm_info), \
412 INTEL_GM45_IDS(&intel_gm45_info), \
413 INTEL_G45_IDS(&intel_g45_info), \
414 INTEL_PINEVIEW_IDS(&intel_pineview_info), \
415 INTEL_IRONLAKE_D_IDS(&intel_ironlake_d_info), \
416 INTEL_IRONLAKE_M_IDS(&intel_ironlake_m_info), \
417 INTEL_SNB_D_IDS(&intel_sandybridge_d_info), \
418 INTEL_SNB_M_IDS(&intel_sandybridge_m_info), \
419 INTEL_IVB_Q_IDS(&intel_ivybridge_q_info), /* must be first IVB */ \
420 INTEL_IVB_M_IDS(&intel_ivybridge_m_info), \
421 INTEL_IVB_D_IDS(&intel_ivybridge_d_info), \
422 INTEL_HSW_D_IDS(&intel_haswell_d_info), \
423 INTEL_HSW_M_IDS(&intel_haswell_m_info), \
424 INTEL_VLV_M_IDS(&intel_valleyview_m_info), \
4d4dead6 425 INTEL_VLV_D_IDS(&intel_valleyview_d_info), \
fd3c269f
ZY
426 INTEL_BDW_GT12M_IDS(&intel_broadwell_m_info), \
427 INTEL_BDW_GT12D_IDS(&intel_broadwell_d_info), \
428 INTEL_BDW_GT3M_IDS(&intel_broadwell_gt3m_info), \
7d87a7f7 429 INTEL_BDW_GT3D_IDS(&intel_broadwell_gt3d_info), \
72bbf0af 430 INTEL_CHV_IDS(&intel_cherryview_info), \
719388e1
DL
431 INTEL_SKL_GT1_IDS(&intel_skylake_info), \
432 INTEL_SKL_GT2_IDS(&intel_skylake_info), \
1347f5b4
DL
433 INTEL_SKL_GT3_IDS(&intel_skylake_gt3_info), \
434 INTEL_BXT_IDS(&intel_broxton_info)
a0a18075 435
6103da0d 436static const struct pci_device_id pciidlist[] = { /* aka */
a0a18075 437 INTEL_PCI_IDS,
49ae35f2 438 {0, 0, 0}
1da177e4
LT
439};
440
79e53945 441MODULE_DEVICE_TABLE(pci, pciidlist);
79e53945 442
0206e353 443void intel_detect_pch(struct drm_device *dev)
3bad0781
ZW
444{
445 struct drm_i915_private *dev_priv = dev->dev_private;
bcdb72ac 446 struct pci_dev *pch = NULL;
3bad0781 447
ce1bb329
BW
448 /* In all current cases, num_pipes is equivalent to the PCH_NOP setting
449 * (which really amounts to a PCH but no South Display).
450 */
451 if (INTEL_INFO(dev)->num_pipes == 0) {
452 dev_priv->pch_type = PCH_NOP;
ce1bb329
BW
453 return;
454 }
455
3bad0781
ZW
456 /*
457 * The reason to probe ISA bridge instead of Dev31:Fun0 is to
458 * make graphics device passthrough work easy for VMM, that only
459 * need to expose ISA bridge to let driver know the real hardware
460 * underneath. This is a requirement from virtualization team.
6a9c4b35
RG
461 *
462 * In some virtualized environments (e.g. XEN), there is irrelevant
463 * ISA bridge in the system. To work reliably, we should scan trhough
464 * all the ISA bridge devices and check for the first match, instead
465 * of only checking the first one.
3bad0781 466 */
bcdb72ac 467 while ((pch = pci_get_class(PCI_CLASS_BRIDGE_ISA << 8, pch))) {
3bad0781 468 if (pch->vendor == PCI_VENDOR_ID_INTEL) {
bcdb72ac 469 unsigned short id = pch->device & INTEL_PCH_DEVICE_ID_MASK;
17a303ec 470 dev_priv->pch_id = id;
3bad0781 471
90711d50
JB
472 if (id == INTEL_PCH_IBX_DEVICE_ID_TYPE) {
473 dev_priv->pch_type = PCH_IBX;
474 DRM_DEBUG_KMS("Found Ibex Peak PCH\n");
7fcb83cd 475 WARN_ON(!IS_GEN5(dev));
90711d50 476 } else if (id == INTEL_PCH_CPT_DEVICE_ID_TYPE) {
3bad0781
ZW
477 dev_priv->pch_type = PCH_CPT;
478 DRM_DEBUG_KMS("Found CougarPoint PCH\n");
7fcb83cd 479 WARN_ON(!(IS_GEN6(dev) || IS_IVYBRIDGE(dev)));
c792513b
JB
480 } else if (id == INTEL_PCH_PPT_DEVICE_ID_TYPE) {
481 /* PantherPoint is CPT compatible */
482 dev_priv->pch_type = PCH_CPT;
492ab669 483 DRM_DEBUG_KMS("Found PantherPoint PCH\n");
7fcb83cd 484 WARN_ON(!(IS_GEN6(dev) || IS_IVYBRIDGE(dev)));
eb877ebf
ED
485 } else if (id == INTEL_PCH_LPT_DEVICE_ID_TYPE) {
486 dev_priv->pch_type = PCH_LPT;
487 DRM_DEBUG_KMS("Found LynxPoint PCH\n");
a35cc9d0
RV
488 WARN_ON(!IS_HASWELL(dev) && !IS_BROADWELL(dev));
489 WARN_ON(IS_HSW_ULT(dev) || IS_BDW_ULT(dev));
e76e0634
BW
490 } else if (id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) {
491 dev_priv->pch_type = PCH_LPT;
492 DRM_DEBUG_KMS("Found LynxPoint LP PCH\n");
a35cc9d0
RV
493 WARN_ON(!IS_HASWELL(dev) && !IS_BROADWELL(dev));
494 WARN_ON(!IS_HSW_ULT(dev) && !IS_BDW_ULT(dev));
e7e7ea20
S
495 } else if (id == INTEL_PCH_SPT_DEVICE_ID_TYPE) {
496 dev_priv->pch_type = PCH_SPT;
497 DRM_DEBUG_KMS("Found SunrisePoint PCH\n");
498 WARN_ON(!IS_SKYLAKE(dev));
e7e7ea20
S
499 } else if (id == INTEL_PCH_SPT_LP_DEVICE_ID_TYPE) {
500 dev_priv->pch_type = PCH_SPT;
501 DRM_DEBUG_KMS("Found SunrisePoint LP PCH\n");
502 WARN_ON(!IS_SKYLAKE(dev));
bcdb72ac
ID
503 } else
504 continue;
505
6a9c4b35 506 break;
3bad0781 507 }
3bad0781 508 }
6a9c4b35 509 if (!pch)
bcdb72ac
ID
510 DRM_DEBUG_KMS("No PCH found.\n");
511
512 pci_dev_put(pch);
3bad0781
ZW
513}
514
2911a35b
BW
515bool i915_semaphore_is_enabled(struct drm_device *dev)
516{
517 if (INTEL_INFO(dev)->gen < 6)
a08acaf2 518 return false;
2911a35b 519
d330a953
JN
520 if (i915.semaphores >= 0)
521 return i915.semaphores;
2911a35b 522
71386ef9
OM
523 /* TODO: make semaphores and Execlists play nicely together */
524 if (i915.enable_execlists)
525 return false;
526
be71eabe
RV
527 /* Until we get further testing... */
528 if (IS_GEN8(dev))
529 return false;
530
59de3295 531#ifdef CONFIG_INTEL_IOMMU
2911a35b 532 /* Enable semaphores on SNB when IO remapping is off */
59de3295
DV
533 if (INTEL_INFO(dev)->gen == 6 && intel_iommu_gfx_mapped)
534 return false;
535#endif
2911a35b 536
a08acaf2 537 return true;
2911a35b
BW
538}
539
eb805623
DV
540void i915_firmware_load_error_print(const char *fw_path, int err)
541{
542 DRM_ERROR("failed to load firmware %s (%d)\n", fw_path, err);
543
544 /*
545 * If the reason is not known assume -ENOENT since that's the most
546 * usual failure mode.
547 */
548 if (!err)
549 err = -ENOENT;
550
551 if (!(IS_BUILTIN(CONFIG_DRM_I915) && err == -ENOENT))
552 return;
553
554 DRM_ERROR(
555 "The driver is built-in, so to load the firmware you need to\n"
556 "include it either in the kernel (see CONFIG_EXTRA_FIRMWARE) or\n"
557 "in your initrd/initramfs image.\n");
558}
559
07f9cd0b
ID
560static void intel_suspend_encoders(struct drm_i915_private *dev_priv)
561{
562 struct drm_device *dev = dev_priv->dev;
563 struct drm_encoder *encoder;
564
565 drm_modeset_lock_all(dev);
566 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
567 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
568
569 if (intel_encoder->suspend)
570 intel_encoder->suspend(intel_encoder);
571 }
572 drm_modeset_unlock_all(dev);
573}
574
ebc32824 575static int intel_suspend_complete(struct drm_i915_private *dev_priv);
1a5df187
PZ
576static int vlv_resume_prepare(struct drm_i915_private *dev_priv,
577 bool rpm_resume);
f75a1985 578static int skl_resume_prepare(struct drm_i915_private *dev_priv);
a9a6b73a 579static int bxt_resume_prepare(struct drm_i915_private *dev_priv);
f75a1985 580
ebc32824 581
5e365c39 582static int i915_drm_suspend(struct drm_device *dev)
ba8bbcf6 583{
61caf87c 584 struct drm_i915_private *dev_priv = dev->dev_private;
e5747e3a 585 pci_power_t opregion_target_state;
d5818938 586 int error;
61caf87c 587
b8efb17b
ZR
588 /* ignore lid events during suspend */
589 mutex_lock(&dev_priv->modeset_restore_lock);
590 dev_priv->modeset_restore = MODESET_SUSPENDED;
591 mutex_unlock(&dev_priv->modeset_restore_lock);
592
c67a470b
PZ
593 /* We do a lot of poking in a lot of registers, make sure they work
594 * properly. */
da7e29bd 595 intel_display_set_init_power(dev_priv, true);
cb10799c 596
5bcf719b
DA
597 drm_kms_helper_poll_disable(dev);
598
ba8bbcf6 599 pci_save_state(dev->pdev);
ba8bbcf6 600
d5818938
DV
601 error = i915_gem_suspend(dev);
602 if (error) {
603 dev_err(&dev->pdev->dev,
604 "GEM idle failed, resume might fail\n");
605 return error;
606 }
db1b76ca 607
d5818938 608 intel_suspend_gt_powersave(dev);
a261b246 609
d5818938
DV
610 /*
611 * Disable CRTCs directly since we want to preserve sw state
612 * for _thaw. Also, power gate the CRTC power wells.
613 */
614 drm_modeset_lock_all(dev);
6b72d486 615 intel_display_suspend(dev);
d5818938 616 drm_modeset_unlock_all(dev);
2eb5252e 617
d5818938 618 intel_dp_mst_suspend(dev);
7d708ee4 619
d5818938
DV
620 intel_runtime_pm_disable_interrupts(dev_priv);
621 intel_hpd_cancel_work(dev_priv);
09b64267 622
d5818938 623 intel_suspend_encoders(dev_priv);
0e32b39c 624
d5818938 625 intel_suspend_hw(dev);
5669fcac 626
828c7908
BW
627 i915_gem_suspend_gtt_mappings(dev);
628
9e06dd39
JB
629 i915_save_state(dev);
630
95fa2eee
ID
631 opregion_target_state = PCI_D3cold;
632#if IS_ENABLED(CONFIG_ACPI_SLEEP)
633 if (acpi_target_system_state() < ACPI_STATE_S3)
e5747e3a 634 opregion_target_state = PCI_D1;
95fa2eee 635#endif
e5747e3a
JB
636 intel_opregion_notify_adapter(dev, opregion_target_state);
637
156c7ca0 638 intel_uncore_forcewake_reset(dev, false);
44834a67 639 intel_opregion_fini(dev);
8ee1c3db 640
82e3b8c1 641 intel_fbdev_set_suspend(dev, FBINFO_STATE_SUSPENDED, true);
3fa016a0 642
62d5d69b
MK
643 dev_priv->suspend_count++;
644
85e90679
KCA
645 intel_display_set_init_power(dev_priv, false);
646
61caf87c 647 return 0;
84b79f8d
RW
648}
649
ab3be73f 650static int i915_drm_suspend_late(struct drm_device *drm_dev, bool hibernation)
c3c09c95
ID
651{
652 struct drm_i915_private *dev_priv = drm_dev->dev_private;
653 int ret;
654
655 ret = intel_suspend_complete(dev_priv);
656
657 if (ret) {
658 DRM_ERROR("Suspend complete failed: %d\n", ret);
659
660 return ret;
661 }
662
663 pci_disable_device(drm_dev->pdev);
ab3be73f
ID
664 /*
665 * During hibernation on some GEN4 platforms the BIOS may try to access
666 * the device even though it's already in D3 and hang the machine. So
667 * leave the device in D0 on those platforms and hope the BIOS will
668 * power down the device properly. Platforms where this was seen:
669 * Lenovo Thinkpad X301, X61s
670 */
671 if (!(hibernation &&
672 drm_dev->pdev->subsystem_vendor == PCI_VENDOR_ID_LENOVO &&
673 INTEL_INFO(dev_priv)->gen == 4))
674 pci_set_power_state(drm_dev->pdev, PCI_D3hot);
c3c09c95
ID
675
676 return 0;
677}
678
fc49b3da 679int i915_suspend_legacy(struct drm_device *dev, pm_message_t state)
84b79f8d
RW
680{
681 int error;
682
683 if (!dev || !dev->dev_private) {
684 DRM_ERROR("dev: %p\n", dev);
685 DRM_ERROR("DRM not initialized, aborting suspend.\n");
686 return -ENODEV;
687 }
688
0b14cbd2
ID
689 if (WARN_ON_ONCE(state.event != PM_EVENT_SUSPEND &&
690 state.event != PM_EVENT_FREEZE))
691 return -EINVAL;
5bcf719b
DA
692
693 if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
694 return 0;
6eecba33 695
5e365c39 696 error = i915_drm_suspend(dev);
84b79f8d
RW
697 if (error)
698 return error;
699
ab3be73f 700 return i915_drm_suspend_late(dev, false);
ba8bbcf6
JB
701}
702
5e365c39 703static int i915_drm_resume(struct drm_device *dev)
76c4b250
ID
704{
705 struct drm_i915_private *dev_priv = dev->dev_private;
9d49c0ef 706
d5818938
DV
707 mutex_lock(&dev->struct_mutex);
708 i915_gem_restore_gtt_mappings(dev);
709 mutex_unlock(&dev->struct_mutex);
9d49c0ef 710
61caf87c 711 i915_restore_state(dev);
44834a67 712 intel_opregion_setup(dev);
61caf87c 713
d5818938
DV
714 intel_init_pch_refclk(dev);
715 drm_mode_config_reset(dev);
1833b134 716
364aece0
PA
717 /*
718 * Interrupts have to be enabled before any batches are run. If not the
719 * GPU will hang. i915_gem_init_hw() will initiate batches to
720 * update/restore the context.
721 *
722 * Modeset enabling in intel_modeset_init_hw() also needs working
723 * interrupts.
724 */
725 intel_runtime_pm_enable_interrupts(dev_priv);
726
d5818938
DV
727 mutex_lock(&dev->struct_mutex);
728 if (i915_gem_init_hw(dev)) {
729 DRM_ERROR("failed to re-initialize GPU, declaring wedged!\n");
730 atomic_set_mask(I915_WEDGED, &dev_priv->gpu_error.reset_counter);
731 }
732 mutex_unlock(&dev->struct_mutex);
226485e9 733
d5818938 734 intel_modeset_init_hw(dev);
24576d23 735
d5818938
DV
736 spin_lock_irq(&dev_priv->irq_lock);
737 if (dev_priv->display.hpd_irq_setup)
738 dev_priv->display.hpd_irq_setup(dev);
739 spin_unlock_irq(&dev_priv->irq_lock);
0e32b39c 740
d5818938 741 drm_modeset_lock_all(dev);
043e9bda 742 intel_display_resume(dev);
d5818938 743 drm_modeset_unlock_all(dev);
15239099 744
d5818938 745 intel_dp_mst_resume(dev);
e7d6f7d7 746
d5818938
DV
747 /*
748 * ... but also need to make sure that hotplug processing
749 * doesn't cause havoc. Like in the driver load code we don't
750 * bother with the tiny race here where we might loose hotplug
751 * notifications.
752 * */
753 intel_hpd_init(dev_priv);
754 /* Config may have changed between suspend and resume */
755 drm_helper_hpd_irq_event(dev);
1daed3fb 756
44834a67
CW
757 intel_opregion_init(dev);
758
82e3b8c1 759 intel_fbdev_set_suspend(dev, FBINFO_STATE_RUNNING, false);
073f34d9 760
b8efb17b
ZR
761 mutex_lock(&dev_priv->modeset_restore_lock);
762 dev_priv->modeset_restore = MODESET_DONE;
763 mutex_unlock(&dev_priv->modeset_restore_lock);
8a187455 764
e5747e3a
JB
765 intel_opregion_notify_adapter(dev, PCI_D0);
766
ee6f280e
ID
767 drm_kms_helper_poll_enable(dev);
768
074c6ada 769 return 0;
84b79f8d
RW
770}
771
5e365c39 772static int i915_drm_resume_early(struct drm_device *dev)
84b79f8d 773{
36d61e67 774 struct drm_i915_private *dev_priv = dev->dev_private;
1a5df187 775 int ret = 0;
36d61e67 776
76c4b250
ID
777 /*
778 * We have a resume ordering issue with the snd-hda driver also
779 * requiring our device to be power up. Due to the lack of a
780 * parent/child relationship we currently solve this with an early
781 * resume hook.
782 *
783 * FIXME: This should be solved with a special hdmi sink device or
784 * similar so that power domains can be employed.
785 */
84b79f8d
RW
786 if (pci_enable_device(dev->pdev))
787 return -EIO;
788
789 pci_set_master(dev->pdev);
790
efee833a 791 if (IS_VALLEYVIEW(dev_priv))
1a5df187 792 ret = vlv_resume_prepare(dev_priv, false);
36d61e67 793 if (ret)
ff0b187f
DL
794 DRM_ERROR("Resume prepare failed: %d, continuing anyway\n",
795 ret);
36d61e67
ID
796
797 intel_uncore_early_sanitize(dev, true);
efee833a 798
a9a6b73a
DL
799 if (IS_BROXTON(dev))
800 ret = bxt_resume_prepare(dev_priv);
f75a1985
SS
801 else if (IS_SKYLAKE(dev_priv))
802 ret = skl_resume_prepare(dev_priv);
a9a6b73a
DL
803 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
804 hsw_disable_pc8(dev_priv);
efee833a 805
36d61e67
ID
806 intel_uncore_sanitize(dev);
807 intel_power_domains_init_hw(dev_priv);
808
809 return ret;
76c4b250
ID
810}
811
fc49b3da 812int i915_resume_legacy(struct drm_device *dev)
76c4b250 813{
50a0072f 814 int ret;
76c4b250 815
097dd837
ID
816 if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
817 return 0;
818
5e365c39 819 ret = i915_drm_resume_early(dev);
50a0072f
ID
820 if (ret)
821 return ret;
822
5a17514e
ID
823 return i915_drm_resume(dev);
824}
825
11ed50ec 826/**
f3953dcb 827 * i915_reset - reset chip after a hang
11ed50ec 828 * @dev: drm device to reset
11ed50ec
BG
829 *
830 * Reset the chip. Useful if a hang is detected. Returns zero on successful
831 * reset or otherwise an error code.
832 *
833 * Procedure is fairly simple:
834 * - reset the chip using the reset reg
835 * - re-init context state
836 * - re-init hardware status page
837 * - re-init ring buffer
838 * - re-init interrupt state
839 * - re-init display
840 */
d4b8bb2a 841int i915_reset(struct drm_device *dev)
11ed50ec 842{
50227e1c 843 struct drm_i915_private *dev_priv = dev->dev_private;
2e7c8ee7 844 bool simulated;
0573ed4a 845 int ret;
11ed50ec 846
dbea3cea
ID
847 intel_reset_gt_powersave(dev);
848
d54a02c0 849 mutex_lock(&dev->struct_mutex);
11ed50ec 850
069efc1d 851 i915_gem_reset(dev);
77f01230 852
2e7c8ee7
CW
853 simulated = dev_priv->gpu_error.stop_rings != 0;
854
be62acb4
MK
855 ret = intel_gpu_reset(dev);
856
857 /* Also reset the gpu hangman. */
858 if (simulated) {
859 DRM_INFO("Simulated gpu hang, resetting stop_rings\n");
860 dev_priv->gpu_error.stop_rings = 0;
861 if (ret == -ENODEV) {
f2d91a2c
DV
862 DRM_INFO("Reset not implemented, but ignoring "
863 "error for simulated gpu hangs\n");
be62acb4
MK
864 ret = 0;
865 }
2e7c8ee7 866 }
be62acb4 867
d8f2716a
DV
868 if (i915_stop_ring_allow_warn(dev_priv))
869 pr_notice("drm/i915: Resetting chip after gpu hang\n");
870
0573ed4a 871 if (ret) {
f2d91a2c 872 DRM_ERROR("Failed to reset chip: %i\n", ret);
f953c935 873 mutex_unlock(&dev->struct_mutex);
f803aa55 874 return ret;
11ed50ec
BG
875 }
876
1362b776
VS
877 intel_overlay_reset(dev_priv);
878
11ed50ec
BG
879 /* Ok, now get things going again... */
880
881 /*
882 * Everything depends on having the GTT running, so we need to start
883 * there. Fortunately we don't need to do this unless we reset the
884 * chip at a PCI level.
885 *
886 * Next we need to restore the context, but we don't use those
887 * yet either...
888 *
889 * Ring buffer needs to be re-initialized in the KMS case, or if X
890 * was running at the time of the reset (i.e. we weren't VT
891 * switched away).
892 */
6689c167 893
33d30a9c
DV
894 /* Used to prevent gem_check_wedged returning -EAGAIN during gpu reset */
895 dev_priv->gpu_error.reload_in_reset = true;
6689c167 896
33d30a9c 897 ret = i915_gem_init_hw(dev);
6689c167 898
33d30a9c 899 dev_priv->gpu_error.reload_in_reset = false;
f817586c 900
33d30a9c
DV
901 mutex_unlock(&dev->struct_mutex);
902 if (ret) {
903 DRM_ERROR("Failed hw init on reset %d\n", ret);
904 return ret;
11ed50ec
BG
905 }
906
33d30a9c
DV
907 /*
908 * rps/rc6 re-init is necessary to restore state lost after the
909 * reset and the re-install of gt irqs. Skip for ironlake per
910 * previous concerns that it doesn't respond well to some forms
911 * of re-init after reset.
912 */
913 if (INTEL_INFO(dev)->gen > 5)
914 intel_enable_gt_powersave(dev);
915
11ed50ec
BG
916 return 0;
917}
918
56550d94 919static int i915_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
112b715e 920{
01a06850
DV
921 struct intel_device_info *intel_info =
922 (struct intel_device_info *) ent->driver_data;
923
d330a953 924 if (IS_PRELIMINARY_HW(intel_info) && !i915.preliminary_hw_support) {
b833d685
BW
925 DRM_INFO("This hardware requires preliminary hardware support.\n"
926 "See CONFIG_DRM_I915_PRELIMINARY_HW_SUPPORT, and/or modparam preliminary_hw_support\n");
927 return -ENODEV;
928 }
929
5fe49d86
CW
930 /* Only bind to function 0 of the device. Early generations
931 * used function 1 as a placeholder for multi-head. This causes
932 * us confusion instead, especially on the systems where both
933 * functions have the same PCI-ID!
934 */
935 if (PCI_FUNC(pdev->devfn))
936 return -ENODEV;
937
dcdb1674 938 return drm_get_pci_dev(pdev, ent, &driver);
112b715e
KH
939}
940
941static void
942i915_pci_remove(struct pci_dev *pdev)
943{
944 struct drm_device *dev = pci_get_drvdata(pdev);
945
946 drm_put_dev(dev);
947}
948
84b79f8d 949static int i915_pm_suspend(struct device *dev)
112b715e 950{
84b79f8d
RW
951 struct pci_dev *pdev = to_pci_dev(dev);
952 struct drm_device *drm_dev = pci_get_drvdata(pdev);
112b715e 953
84b79f8d
RW
954 if (!drm_dev || !drm_dev->dev_private) {
955 dev_err(dev, "DRM not initialized, aborting suspend.\n");
956 return -ENODEV;
957 }
112b715e 958
5bcf719b
DA
959 if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF)
960 return 0;
961
5e365c39 962 return i915_drm_suspend(drm_dev);
76c4b250
ID
963}
964
965static int i915_pm_suspend_late(struct device *dev)
966{
888d0d42 967 struct drm_device *drm_dev = dev_to_i915(dev)->dev;
76c4b250
ID
968
969 /*
c965d995 970 * We have a suspend ordering issue with the snd-hda driver also
76c4b250
ID
971 * requiring our device to be power up. Due to the lack of a
972 * parent/child relationship we currently solve this with an late
973 * suspend hook.
974 *
975 * FIXME: This should be solved with a special hdmi sink device or
976 * similar so that power domains can be employed.
977 */
978 if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF)
979 return 0;
112b715e 980
ab3be73f
ID
981 return i915_drm_suspend_late(drm_dev, false);
982}
983
984static int i915_pm_poweroff_late(struct device *dev)
985{
986 struct drm_device *drm_dev = dev_to_i915(dev)->dev;
987
988 if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF)
989 return 0;
990
991 return i915_drm_suspend_late(drm_dev, true);
cbda12d7
ZW
992}
993
76c4b250
ID
994static int i915_pm_resume_early(struct device *dev)
995{
888d0d42 996 struct drm_device *drm_dev = dev_to_i915(dev)->dev;
76c4b250 997
097dd837
ID
998 if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF)
999 return 0;
1000
5e365c39 1001 return i915_drm_resume_early(drm_dev);
76c4b250
ID
1002}
1003
84b79f8d 1004static int i915_pm_resume(struct device *dev)
cbda12d7 1005{
888d0d42 1006 struct drm_device *drm_dev = dev_to_i915(dev)->dev;
84b79f8d 1007
097dd837
ID
1008 if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF)
1009 return 0;
1010
5a17514e 1011 return i915_drm_resume(drm_dev);
cbda12d7
ZW
1012}
1013
f75a1985
SS
1014static int skl_suspend_complete(struct drm_i915_private *dev_priv)
1015{
1016 /* Enabling DC6 is not a hard requirement to enter runtime D3 */
1017
1018 /*
1019 * This is to ensure that CSR isn't identified as loaded before
1020 * CSR-loading program is called during runtime-resume.
1021 */
1022 intel_csr_load_status_set(dev_priv, FW_UNINITIALIZED);
1023
5d96d8af
DL
1024 skl_uninit_cdclk(dev_priv);
1025
f75a1985
SS
1026 return 0;
1027}
1028
ebc32824 1029static int hsw_suspend_complete(struct drm_i915_private *dev_priv)
97bea207 1030{
414de7a0 1031 hsw_enable_pc8(dev_priv);
0ab9cfeb
ID
1032
1033 return 0;
97bea207
PZ
1034}
1035
31335cec
SS
1036static int bxt_suspend_complete(struct drm_i915_private *dev_priv)
1037{
1038 struct drm_device *dev = dev_priv->dev;
1039
1040 /* TODO: when DC5 support is added disable DC5 here. */
1041
1042 broxton_ddi_phy_uninit(dev);
1043 broxton_uninit_cdclk(dev);
1044 bxt_enable_dc9(dev_priv);
1045
1046 return 0;
1047}
1048
1049static int bxt_resume_prepare(struct drm_i915_private *dev_priv)
1050{
1051 struct drm_device *dev = dev_priv->dev;
1052
1053 /* TODO: when CSR FW support is added make sure the FW is loaded */
1054
1055 bxt_disable_dc9(dev_priv);
1056
1057 /*
1058 * TODO: when DC5 support is added enable DC5 here if the CSR FW
1059 * is available.
1060 */
1061 broxton_init_cdclk(dev);
1062 broxton_ddi_phy_init(dev);
1063 intel_prepare_ddi(dev);
1064
1065 return 0;
1066}
1067
f75a1985
SS
1068static int skl_resume_prepare(struct drm_i915_private *dev_priv)
1069{
1070 struct drm_device *dev = dev_priv->dev;
1071
5d96d8af 1072 skl_init_cdclk(dev_priv);
f75a1985
SS
1073 intel_csr_load_program(dev);
1074
1075 return 0;
1076}
1077
ddeea5b0
ID
1078/*
1079 * Save all Gunit registers that may be lost after a D3 and a subsequent
1080 * S0i[R123] transition. The list of registers needing a save/restore is
1081 * defined in the VLV2_S0IXRegs document. This documents marks all Gunit
1082 * registers in the following way:
1083 * - Driver: saved/restored by the driver
1084 * - Punit : saved/restored by the Punit firmware
1085 * - No, w/o marking: no need to save/restore, since the register is R/O or
1086 * used internally by the HW in a way that doesn't depend
1087 * keeping the content across a suspend/resume.
1088 * - Debug : used for debugging
1089 *
1090 * We save/restore all registers marked with 'Driver', with the following
1091 * exceptions:
1092 * - Registers out of use, including also registers marked with 'Debug'.
1093 * These have no effect on the driver's operation, so we don't save/restore
1094 * them to reduce the overhead.
1095 * - Registers that are fully setup by an initialization function called from
1096 * the resume path. For example many clock gating and RPS/RC6 registers.
1097 * - Registers that provide the right functionality with their reset defaults.
1098 *
1099 * TODO: Except for registers that based on the above 3 criteria can be safely
1100 * ignored, we save/restore all others, practically treating the HW context as
1101 * a black-box for the driver. Further investigation is needed to reduce the
1102 * saved/restored registers even further, by following the same 3 criteria.
1103 */
1104static void vlv_save_gunit_s0ix_state(struct drm_i915_private *dev_priv)
1105{
1106 struct vlv_s0ix_state *s = &dev_priv->vlv_s0ix_state;
1107 int i;
1108
1109 /* GAM 0x4000-0x4770 */
1110 s->wr_watermark = I915_READ(GEN7_WR_WATERMARK);
1111 s->gfx_prio_ctrl = I915_READ(GEN7_GFX_PRIO_CTRL);
1112 s->arb_mode = I915_READ(ARB_MODE);
1113 s->gfx_pend_tlb0 = I915_READ(GEN7_GFX_PEND_TLB0);
1114 s->gfx_pend_tlb1 = I915_READ(GEN7_GFX_PEND_TLB1);
1115
1116 for (i = 0; i < ARRAY_SIZE(s->lra_limits); i++)
1117 s->lra_limits[i] = I915_READ(GEN7_LRA_LIMITS_BASE + i * 4);
1118
1119 s->media_max_req_count = I915_READ(GEN7_MEDIA_MAX_REQ_COUNT);
b5f1c97f 1120 s->gfx_max_req_count = I915_READ(GEN7_GFX_MAX_REQ_COUNT);
ddeea5b0
ID
1121
1122 s->render_hwsp = I915_READ(RENDER_HWS_PGA_GEN7);
1123 s->ecochk = I915_READ(GAM_ECOCHK);
1124 s->bsd_hwsp = I915_READ(BSD_HWS_PGA_GEN7);
1125 s->blt_hwsp = I915_READ(BLT_HWS_PGA_GEN7);
1126
1127 s->tlb_rd_addr = I915_READ(GEN7_TLB_RD_ADDR);
1128
1129 /* MBC 0x9024-0x91D0, 0x8500 */
1130 s->g3dctl = I915_READ(VLV_G3DCTL);
1131 s->gsckgctl = I915_READ(VLV_GSCKGCTL);
1132 s->mbctl = I915_READ(GEN6_MBCTL);
1133
1134 /* GCP 0x9400-0x9424, 0x8100-0x810C */
1135 s->ucgctl1 = I915_READ(GEN6_UCGCTL1);
1136 s->ucgctl3 = I915_READ(GEN6_UCGCTL3);
1137 s->rcgctl1 = I915_READ(GEN6_RCGCTL1);
1138 s->rcgctl2 = I915_READ(GEN6_RCGCTL2);
1139 s->rstctl = I915_READ(GEN6_RSTCTL);
1140 s->misccpctl = I915_READ(GEN7_MISCCPCTL);
1141
1142 /* GPM 0xA000-0xAA84, 0x8000-0x80FC */
1143 s->gfxpause = I915_READ(GEN6_GFXPAUSE);
1144 s->rpdeuhwtc = I915_READ(GEN6_RPDEUHWTC);
1145 s->rpdeuc = I915_READ(GEN6_RPDEUC);
1146 s->ecobus = I915_READ(ECOBUS);
1147 s->pwrdwnupctl = I915_READ(VLV_PWRDWNUPCTL);
1148 s->rp_down_timeout = I915_READ(GEN6_RP_DOWN_TIMEOUT);
1149 s->rp_deucsw = I915_READ(GEN6_RPDEUCSW);
1150 s->rcubmabdtmr = I915_READ(GEN6_RCUBMABDTMR);
1151 s->rcedata = I915_READ(VLV_RCEDATA);
1152 s->spare2gh = I915_READ(VLV_SPAREG2H);
1153
1154 /* Display CZ domain, 0x4400C-0x4402C, 0x4F000-0x4F11F */
1155 s->gt_imr = I915_READ(GTIMR);
1156 s->gt_ier = I915_READ(GTIER);
1157 s->pm_imr = I915_READ(GEN6_PMIMR);
1158 s->pm_ier = I915_READ(GEN6_PMIER);
1159
1160 for (i = 0; i < ARRAY_SIZE(s->gt_scratch); i++)
1161 s->gt_scratch[i] = I915_READ(GEN7_GT_SCRATCH_BASE + i * 4);
1162
1163 /* GT SA CZ domain, 0x100000-0x138124 */
1164 s->tilectl = I915_READ(TILECTL);
1165 s->gt_fifoctl = I915_READ(GTFIFOCTL);
1166 s->gtlc_wake_ctrl = I915_READ(VLV_GTLC_WAKE_CTRL);
1167 s->gtlc_survive = I915_READ(VLV_GTLC_SURVIVABILITY_REG);
1168 s->pmwgicz = I915_READ(VLV_PMWGICZ);
1169
1170 /* Gunit-Display CZ domain, 0x182028-0x1821CF */
1171 s->gu_ctl0 = I915_READ(VLV_GU_CTL0);
1172 s->gu_ctl1 = I915_READ(VLV_GU_CTL1);
9c25210f 1173 s->pcbr = I915_READ(VLV_PCBR);
ddeea5b0
ID
1174 s->clock_gate_dis2 = I915_READ(VLV_GUNIT_CLOCK_GATE2);
1175
1176 /*
1177 * Not saving any of:
1178 * DFT, 0x9800-0x9EC0
1179 * SARB, 0xB000-0xB1FC
1180 * GAC, 0x5208-0x524C, 0x14000-0x14C000
1181 * PCI CFG
1182 */
1183}
1184
1185static void vlv_restore_gunit_s0ix_state(struct drm_i915_private *dev_priv)
1186{
1187 struct vlv_s0ix_state *s = &dev_priv->vlv_s0ix_state;
1188 u32 val;
1189 int i;
1190
1191 /* GAM 0x4000-0x4770 */
1192 I915_WRITE(GEN7_WR_WATERMARK, s->wr_watermark);
1193 I915_WRITE(GEN7_GFX_PRIO_CTRL, s->gfx_prio_ctrl);
1194 I915_WRITE(ARB_MODE, s->arb_mode | (0xffff << 16));
1195 I915_WRITE(GEN7_GFX_PEND_TLB0, s->gfx_pend_tlb0);
1196 I915_WRITE(GEN7_GFX_PEND_TLB1, s->gfx_pend_tlb1);
1197
1198 for (i = 0; i < ARRAY_SIZE(s->lra_limits); i++)
1199 I915_WRITE(GEN7_LRA_LIMITS_BASE + i * 4, s->lra_limits[i]);
1200
1201 I915_WRITE(GEN7_MEDIA_MAX_REQ_COUNT, s->media_max_req_count);
b5f1c97f 1202 I915_WRITE(GEN7_GFX_MAX_REQ_COUNT, s->gfx_max_req_count);
ddeea5b0
ID
1203
1204 I915_WRITE(RENDER_HWS_PGA_GEN7, s->render_hwsp);
1205 I915_WRITE(GAM_ECOCHK, s->ecochk);
1206 I915_WRITE(BSD_HWS_PGA_GEN7, s->bsd_hwsp);
1207 I915_WRITE(BLT_HWS_PGA_GEN7, s->blt_hwsp);
1208
1209 I915_WRITE(GEN7_TLB_RD_ADDR, s->tlb_rd_addr);
1210
1211 /* MBC 0x9024-0x91D0, 0x8500 */
1212 I915_WRITE(VLV_G3DCTL, s->g3dctl);
1213 I915_WRITE(VLV_GSCKGCTL, s->gsckgctl);
1214 I915_WRITE(GEN6_MBCTL, s->mbctl);
1215
1216 /* GCP 0x9400-0x9424, 0x8100-0x810C */
1217 I915_WRITE(GEN6_UCGCTL1, s->ucgctl1);
1218 I915_WRITE(GEN6_UCGCTL3, s->ucgctl3);
1219 I915_WRITE(GEN6_RCGCTL1, s->rcgctl1);
1220 I915_WRITE(GEN6_RCGCTL2, s->rcgctl2);
1221 I915_WRITE(GEN6_RSTCTL, s->rstctl);
1222 I915_WRITE(GEN7_MISCCPCTL, s->misccpctl);
1223
1224 /* GPM 0xA000-0xAA84, 0x8000-0x80FC */
1225 I915_WRITE(GEN6_GFXPAUSE, s->gfxpause);
1226 I915_WRITE(GEN6_RPDEUHWTC, s->rpdeuhwtc);
1227 I915_WRITE(GEN6_RPDEUC, s->rpdeuc);
1228 I915_WRITE(ECOBUS, s->ecobus);
1229 I915_WRITE(VLV_PWRDWNUPCTL, s->pwrdwnupctl);
1230 I915_WRITE(GEN6_RP_DOWN_TIMEOUT,s->rp_down_timeout);
1231 I915_WRITE(GEN6_RPDEUCSW, s->rp_deucsw);
1232 I915_WRITE(GEN6_RCUBMABDTMR, s->rcubmabdtmr);
1233 I915_WRITE(VLV_RCEDATA, s->rcedata);
1234 I915_WRITE(VLV_SPAREG2H, s->spare2gh);
1235
1236 /* Display CZ domain, 0x4400C-0x4402C, 0x4F000-0x4F11F */
1237 I915_WRITE(GTIMR, s->gt_imr);
1238 I915_WRITE(GTIER, s->gt_ier);
1239 I915_WRITE(GEN6_PMIMR, s->pm_imr);
1240 I915_WRITE(GEN6_PMIER, s->pm_ier);
1241
1242 for (i = 0; i < ARRAY_SIZE(s->gt_scratch); i++)
1243 I915_WRITE(GEN7_GT_SCRATCH_BASE + i * 4, s->gt_scratch[i]);
1244
1245 /* GT SA CZ domain, 0x100000-0x138124 */
1246 I915_WRITE(TILECTL, s->tilectl);
1247 I915_WRITE(GTFIFOCTL, s->gt_fifoctl);
1248 /*
1249 * Preserve the GT allow wake and GFX force clock bit, they are not
1250 * be restored, as they are used to control the s0ix suspend/resume
1251 * sequence by the caller.
1252 */
1253 val = I915_READ(VLV_GTLC_WAKE_CTRL);
1254 val &= VLV_GTLC_ALLOWWAKEREQ;
1255 val |= s->gtlc_wake_ctrl & ~VLV_GTLC_ALLOWWAKEREQ;
1256 I915_WRITE(VLV_GTLC_WAKE_CTRL, val);
1257
1258 val = I915_READ(VLV_GTLC_SURVIVABILITY_REG);
1259 val &= VLV_GFX_CLK_FORCE_ON_BIT;
1260 val |= s->gtlc_survive & ~VLV_GFX_CLK_FORCE_ON_BIT;
1261 I915_WRITE(VLV_GTLC_SURVIVABILITY_REG, val);
1262
1263 I915_WRITE(VLV_PMWGICZ, s->pmwgicz);
1264
1265 /* Gunit-Display CZ domain, 0x182028-0x1821CF */
1266 I915_WRITE(VLV_GU_CTL0, s->gu_ctl0);
1267 I915_WRITE(VLV_GU_CTL1, s->gu_ctl1);
9c25210f 1268 I915_WRITE(VLV_PCBR, s->pcbr);
ddeea5b0
ID
1269 I915_WRITE(VLV_GUNIT_CLOCK_GATE2, s->clock_gate_dis2);
1270}
1271
650ad970
ID
1272int vlv_force_gfx_clock(struct drm_i915_private *dev_priv, bool force_on)
1273{
1274 u32 val;
1275 int err;
1276
650ad970 1277#define COND (I915_READ(VLV_GTLC_SURVIVABILITY_REG) & VLV_GFX_CLK_STATUS_BIT)
650ad970
ID
1278
1279 val = I915_READ(VLV_GTLC_SURVIVABILITY_REG);
1280 val &= ~VLV_GFX_CLK_FORCE_ON_BIT;
1281 if (force_on)
1282 val |= VLV_GFX_CLK_FORCE_ON_BIT;
1283 I915_WRITE(VLV_GTLC_SURVIVABILITY_REG, val);
1284
1285 if (!force_on)
1286 return 0;
1287
8d4eee9c 1288 err = wait_for(COND, 20);
650ad970
ID
1289 if (err)
1290 DRM_ERROR("timeout waiting for GFX clock force-on (%08x)\n",
1291 I915_READ(VLV_GTLC_SURVIVABILITY_REG));
1292
1293 return err;
1294#undef COND
1295}
1296
ddeea5b0
ID
1297static int vlv_allow_gt_wake(struct drm_i915_private *dev_priv, bool allow)
1298{
1299 u32 val;
1300 int err = 0;
1301
1302 val = I915_READ(VLV_GTLC_WAKE_CTRL);
1303 val &= ~VLV_GTLC_ALLOWWAKEREQ;
1304 if (allow)
1305 val |= VLV_GTLC_ALLOWWAKEREQ;
1306 I915_WRITE(VLV_GTLC_WAKE_CTRL, val);
1307 POSTING_READ(VLV_GTLC_WAKE_CTRL);
1308
1309#define COND (!!(I915_READ(VLV_GTLC_PW_STATUS) & VLV_GTLC_ALLOWWAKEACK) == \
1310 allow)
1311 err = wait_for(COND, 1);
1312 if (err)
1313 DRM_ERROR("timeout disabling GT waking\n");
1314 return err;
1315#undef COND
1316}
1317
1318static int vlv_wait_for_gt_wells(struct drm_i915_private *dev_priv,
1319 bool wait_for_on)
1320{
1321 u32 mask;
1322 u32 val;
1323 int err;
1324
1325 mask = VLV_GTLC_PW_MEDIA_STATUS_MASK | VLV_GTLC_PW_RENDER_STATUS_MASK;
1326 val = wait_for_on ? mask : 0;
1327#define COND ((I915_READ(VLV_GTLC_PW_STATUS) & mask) == val)
1328 if (COND)
1329 return 0;
1330
1331 DRM_DEBUG_KMS("waiting for GT wells to go %s (%08x)\n",
1332 wait_for_on ? "on" : "off",
1333 I915_READ(VLV_GTLC_PW_STATUS));
1334
1335 /*
1336 * RC6 transitioning can be delayed up to 2 msec (see
1337 * valleyview_enable_rps), use 3 msec for safety.
1338 */
1339 err = wait_for(COND, 3);
1340 if (err)
1341 DRM_ERROR("timeout waiting for GT wells to go %s\n",
1342 wait_for_on ? "on" : "off");
1343
1344 return err;
1345#undef COND
1346}
1347
1348static void vlv_check_no_gt_access(struct drm_i915_private *dev_priv)
1349{
1350 if (!(I915_READ(VLV_GTLC_PW_STATUS) & VLV_GTLC_ALLOWWAKEERR))
1351 return;
1352
1353 DRM_ERROR("GT register access while GT waking disabled\n");
1354 I915_WRITE(VLV_GTLC_PW_STATUS, VLV_GTLC_ALLOWWAKEERR);
1355}
1356
ebc32824 1357static int vlv_suspend_complete(struct drm_i915_private *dev_priv)
ddeea5b0
ID
1358{
1359 u32 mask;
1360 int err;
1361
1362 /*
1363 * Bspec defines the following GT well on flags as debug only, so
1364 * don't treat them as hard failures.
1365 */
1366 (void)vlv_wait_for_gt_wells(dev_priv, false);
1367
1368 mask = VLV_GTLC_RENDER_CTX_EXISTS | VLV_GTLC_MEDIA_CTX_EXISTS;
1369 WARN_ON((I915_READ(VLV_GTLC_WAKE_CTRL) & mask) != mask);
1370
1371 vlv_check_no_gt_access(dev_priv);
1372
1373 err = vlv_force_gfx_clock(dev_priv, true);
1374 if (err)
1375 goto err1;
1376
1377 err = vlv_allow_gt_wake(dev_priv, false);
1378 if (err)
1379 goto err2;
98711167
D
1380
1381 if (!IS_CHERRYVIEW(dev_priv->dev))
1382 vlv_save_gunit_s0ix_state(dev_priv);
ddeea5b0
ID
1383
1384 err = vlv_force_gfx_clock(dev_priv, false);
1385 if (err)
1386 goto err2;
1387
1388 return 0;
1389
1390err2:
1391 /* For safety always re-enable waking and disable gfx clock forcing */
1392 vlv_allow_gt_wake(dev_priv, true);
1393err1:
1394 vlv_force_gfx_clock(dev_priv, false);
1395
1396 return err;
1397}
1398
016970be
SK
1399static int vlv_resume_prepare(struct drm_i915_private *dev_priv,
1400 bool rpm_resume)
ddeea5b0
ID
1401{
1402 struct drm_device *dev = dev_priv->dev;
1403 int err;
1404 int ret;
1405
1406 /*
1407 * If any of the steps fail just try to continue, that's the best we
1408 * can do at this point. Return the first error code (which will also
1409 * leave RPM permanently disabled).
1410 */
1411 ret = vlv_force_gfx_clock(dev_priv, true);
1412
98711167
D
1413 if (!IS_CHERRYVIEW(dev_priv->dev))
1414 vlv_restore_gunit_s0ix_state(dev_priv);
ddeea5b0
ID
1415
1416 err = vlv_allow_gt_wake(dev_priv, true);
1417 if (!ret)
1418 ret = err;
1419
1420 err = vlv_force_gfx_clock(dev_priv, false);
1421 if (!ret)
1422 ret = err;
1423
1424 vlv_check_no_gt_access(dev_priv);
1425
016970be
SK
1426 if (rpm_resume) {
1427 intel_init_clock_gating(dev);
1428 i915_gem_restore_fences(dev);
1429 }
ddeea5b0
ID
1430
1431 return ret;
1432}
1433
97bea207 1434static int intel_runtime_suspend(struct device *device)
8a187455
PZ
1435{
1436 struct pci_dev *pdev = to_pci_dev(device);
1437 struct drm_device *dev = pci_get_drvdata(pdev);
1438 struct drm_i915_private *dev_priv = dev->dev_private;
0ab9cfeb 1439 int ret;
8a187455 1440
aeab0b5a 1441 if (WARN_ON_ONCE(!(dev_priv->rps.enabled && intel_enable_rc6(dev))))
c6df39b5
ID
1442 return -ENODEV;
1443
604effb7
ID
1444 if (WARN_ON_ONCE(!HAS_RUNTIME_PM(dev)))
1445 return -ENODEV;
1446
8a187455
PZ
1447 DRM_DEBUG_KMS("Suspending device\n");
1448
d6102977
ID
1449 /*
1450 * We could deadlock here in case another thread holding struct_mutex
1451 * calls RPM suspend concurrently, since the RPM suspend will wait
1452 * first for this RPM suspend to finish. In this case the concurrent
1453 * RPM resume will be followed by its RPM suspend counterpart. Still
1454 * for consistency return -EAGAIN, which will reschedule this suspend.
1455 */
1456 if (!mutex_trylock(&dev->struct_mutex)) {
1457 DRM_DEBUG_KMS("device lock contention, deffering suspend\n");
1458 /*
1459 * Bump the expiration timestamp, otherwise the suspend won't
1460 * be rescheduled.
1461 */
1462 pm_runtime_mark_last_busy(device);
1463
1464 return -EAGAIN;
1465 }
1466 /*
1467 * We are safe here against re-faults, since the fault handler takes
1468 * an RPM reference.
1469 */
1470 i915_gem_release_all_mmaps(dev_priv);
1471 mutex_unlock(&dev->struct_mutex);
1472
fac6adb0 1473 intel_suspend_gt_powersave(dev);
2eb5252e 1474 intel_runtime_pm_disable_interrupts(dev_priv);
b5478bcd 1475
ebc32824 1476 ret = intel_suspend_complete(dev_priv);
0ab9cfeb
ID
1477 if (ret) {
1478 DRM_ERROR("Runtime suspend failed, disabling it (%d)\n", ret);
b963291c 1479 intel_runtime_pm_enable_interrupts(dev_priv);
0ab9cfeb
ID
1480
1481 return ret;
1482 }
a8a8bd54 1483
737b1506 1484 cancel_delayed_work_sync(&dev_priv->gpu_error.hangcheck_work);
dc9fb09c 1485 intel_uncore_forcewake_reset(dev, false);
8a187455 1486 dev_priv->pm.suspended = true;
1fb2362b
KCA
1487
1488 /*
c8a0bd42
PZ
1489 * FIXME: We really should find a document that references the arguments
1490 * used below!
1fb2362b 1491 */
d37ae19a
PZ
1492 if (IS_BROADWELL(dev)) {
1493 /*
1494 * On Broadwell, if we use PCI_D1 the PCH DDI ports will stop
1495 * being detected, and the call we do at intel_runtime_resume()
1496 * won't be able to restore them. Since PCI_D3hot matches the
1497 * actual specification and appears to be working, use it.
1498 */
1499 intel_opregion_notify_adapter(dev, PCI_D3hot);
1500 } else {
c8a0bd42
PZ
1501 /*
1502 * current versions of firmware which depend on this opregion
1503 * notification have repurposed the D1 definition to mean
1504 * "runtime suspended" vs. what you would normally expect (D3)
1505 * to distinguish it from notifications that might be sent via
1506 * the suspend path.
1507 */
1508 intel_opregion_notify_adapter(dev, PCI_D1);
c8a0bd42 1509 }
8a187455 1510
59bad947 1511 assert_forcewakes_inactive(dev_priv);
dc9fb09c 1512
a8a8bd54 1513 DRM_DEBUG_KMS("Device suspended\n");
8a187455
PZ
1514 return 0;
1515}
1516
97bea207 1517static int intel_runtime_resume(struct device *device)
8a187455
PZ
1518{
1519 struct pci_dev *pdev = to_pci_dev(device);
1520 struct drm_device *dev = pci_get_drvdata(pdev);
1521 struct drm_i915_private *dev_priv = dev->dev_private;
1a5df187 1522 int ret = 0;
8a187455 1523
604effb7
ID
1524 if (WARN_ON_ONCE(!HAS_RUNTIME_PM(dev)))
1525 return -ENODEV;
8a187455
PZ
1526
1527 DRM_DEBUG_KMS("Resuming device\n");
1528
cd2e9e90 1529 intel_opregion_notify_adapter(dev, PCI_D0);
8a187455
PZ
1530 dev_priv->pm.suspended = false;
1531
1a5df187
PZ
1532 if (IS_GEN6(dev_priv))
1533 intel_init_pch_refclk(dev);
31335cec
SS
1534
1535 if (IS_BROXTON(dev))
1536 ret = bxt_resume_prepare(dev_priv);
f75a1985
SS
1537 else if (IS_SKYLAKE(dev))
1538 ret = skl_resume_prepare(dev_priv);
1a5df187
PZ
1539 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
1540 hsw_disable_pc8(dev_priv);
1541 else if (IS_VALLEYVIEW(dev_priv))
1542 ret = vlv_resume_prepare(dev_priv, true);
1543
0ab9cfeb
ID
1544 /*
1545 * No point of rolling back things in case of an error, as the best
1546 * we can do is to hope that things will still work (and disable RPM).
1547 */
92b806d3
ID
1548 i915_gem_init_swizzling(dev);
1549 gen6_update_ring_freq(dev);
1550
b963291c 1551 intel_runtime_pm_enable_interrupts(dev_priv);
fac6adb0 1552 intel_enable_gt_powersave(dev);
b5478bcd 1553
0ab9cfeb
ID
1554 if (ret)
1555 DRM_ERROR("Runtime resume failed, disabling it (%d)\n", ret);
1556 else
1557 DRM_DEBUG_KMS("Device resumed\n");
1558
1559 return ret;
8a187455
PZ
1560}
1561
016970be
SK
1562/*
1563 * This function implements common functionality of runtime and system
1564 * suspend sequence.
1565 */
ebc32824
SK
1566static int intel_suspend_complete(struct drm_i915_private *dev_priv)
1567{
ebc32824
SK
1568 int ret;
1569
16e44e3e 1570 if (IS_BROXTON(dev_priv))
31335cec 1571 ret = bxt_suspend_complete(dev_priv);
16e44e3e 1572 else if (IS_SKYLAKE(dev_priv))
f75a1985 1573 ret = skl_suspend_complete(dev_priv);
16e44e3e 1574 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
ebc32824 1575 ret = hsw_suspend_complete(dev_priv);
16e44e3e 1576 else if (IS_VALLEYVIEW(dev_priv))
ebc32824 1577 ret = vlv_suspend_complete(dev_priv);
604effb7
ID
1578 else
1579 ret = 0;
ebc32824
SK
1580
1581 return ret;
1582}
1583
b4b78d12 1584static const struct dev_pm_ops i915_pm_ops = {
5545dbbf
ID
1585 /*
1586 * S0ix (via system suspend) and S3 event handlers [PMSG_SUSPEND,
1587 * PMSG_RESUME]
1588 */
0206e353 1589 .suspend = i915_pm_suspend,
76c4b250
ID
1590 .suspend_late = i915_pm_suspend_late,
1591 .resume_early = i915_pm_resume_early,
0206e353 1592 .resume = i915_pm_resume,
5545dbbf
ID
1593
1594 /*
1595 * S4 event handlers
1596 * @freeze, @freeze_late : called (1) before creating the
1597 * hibernation image [PMSG_FREEZE] and
1598 * (2) after rebooting, before restoring
1599 * the image [PMSG_QUIESCE]
1600 * @thaw, @thaw_early : called (1) after creating the hibernation
1601 * image, before writing it [PMSG_THAW]
1602 * and (2) after failing to create or
1603 * restore the image [PMSG_RECOVER]
1604 * @poweroff, @poweroff_late: called after writing the hibernation
1605 * image, before rebooting [PMSG_HIBERNATE]
1606 * @restore, @restore_early : called after rebooting and restoring the
1607 * hibernation image [PMSG_RESTORE]
1608 */
36d61e67
ID
1609 .freeze = i915_pm_suspend,
1610 .freeze_late = i915_pm_suspend_late,
1611 .thaw_early = i915_pm_resume_early,
1612 .thaw = i915_pm_resume,
1613 .poweroff = i915_pm_suspend,
ab3be73f 1614 .poweroff_late = i915_pm_poweroff_late,
76c4b250 1615 .restore_early = i915_pm_resume_early,
0206e353 1616 .restore = i915_pm_resume,
5545dbbf
ID
1617
1618 /* S0ix (via runtime suspend) event handlers */
97bea207
PZ
1619 .runtime_suspend = intel_runtime_suspend,
1620 .runtime_resume = intel_runtime_resume,
cbda12d7
ZW
1621};
1622
78b68556 1623static const struct vm_operations_struct i915_gem_vm_ops = {
de151cf6 1624 .fault = i915_gem_fault,
ab00b3e5
JB
1625 .open = drm_gem_vm_open,
1626 .close = drm_gem_vm_close,
de151cf6
JB
1627};
1628
e08e96de
AV
1629static const struct file_operations i915_driver_fops = {
1630 .owner = THIS_MODULE,
1631 .open = drm_open,
1632 .release = drm_release,
1633 .unlocked_ioctl = drm_ioctl,
1634 .mmap = drm_gem_mmap,
1635 .poll = drm_poll,
e08e96de
AV
1636 .read = drm_read,
1637#ifdef CONFIG_COMPAT
1638 .compat_ioctl = i915_compat_ioctl,
1639#endif
1640 .llseek = noop_llseek,
1641};
1642
1da177e4 1643static struct drm_driver driver = {
0c54781b
MW
1644 /* Don't use MTRRs here; the Xserver or userspace app should
1645 * deal with them for Intel hardware.
792d2b9a 1646 */
673a394b 1647 .driver_features =
10ba5012
KH
1648 DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_GEM | DRIVER_PRIME |
1649 DRIVER_RENDER,
22eae947 1650 .load = i915_driver_load,
ba8bbcf6 1651 .unload = i915_driver_unload,
673a394b 1652 .open = i915_driver_open,
22eae947
DA
1653 .lastclose = i915_driver_lastclose,
1654 .preclose = i915_driver_preclose,
673a394b 1655 .postclose = i915_driver_postclose,
915b4d11 1656 .set_busid = drm_pci_set_busid,
d8e29209
RW
1657
1658 /* Used in place of i915_pm_ops for non-DRIVER_MODESET */
fc49b3da 1659 .suspend = i915_suspend_legacy,
76c4b250 1660 .resume = i915_resume_legacy,
d8e29209 1661
955b12de 1662#if defined(CONFIG_DEBUG_FS)
27c202ad
BG
1663 .debugfs_init = i915_debugfs_init,
1664 .debugfs_cleanup = i915_debugfs_cleanup,
955b12de 1665#endif
673a394b 1666 .gem_free_object = i915_gem_free_object,
de151cf6 1667 .gem_vm_ops = &i915_gem_vm_ops,
1286ff73
DV
1668
1669 .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
1670 .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
1671 .gem_prime_export = i915_gem_prime_export,
1672 .gem_prime_import = i915_gem_prime_import,
1673
ff72145b 1674 .dumb_create = i915_gem_dumb_create,
da6b51d0 1675 .dumb_map_offset = i915_gem_mmap_gtt,
43387b37 1676 .dumb_destroy = drm_gem_dumb_destroy,
1da177e4 1677 .ioctls = i915_ioctls,
e08e96de 1678 .fops = &i915_driver_fops,
22eae947
DA
1679 .name = DRIVER_NAME,
1680 .desc = DRIVER_DESC,
1681 .date = DRIVER_DATE,
1682 .major = DRIVER_MAJOR,
1683 .minor = DRIVER_MINOR,
1684 .patchlevel = DRIVER_PATCHLEVEL,
1da177e4
LT
1685};
1686
8410ea3b
DA
1687static struct pci_driver i915_pci_driver = {
1688 .name = DRIVER_NAME,
1689 .id_table = pciidlist,
1690 .probe = i915_pci_probe,
1691 .remove = i915_pci_remove,
1692 .driver.pm = &i915_pm_ops,
1693};
1694
1da177e4
LT
1695static int __init i915_init(void)
1696{
1697 driver.num_ioctls = i915_max_ioctl;
79e53945
JB
1698
1699 /*
fd930478
CW
1700 * Enable KMS by default, unless explicitly overriden by
1701 * either the i915.modeset prarameter or by the
1702 * vga_text_mode_force boot option.
79e53945 1703 */
fd930478
CW
1704 driver.driver_features |= DRIVER_MODESET;
1705
1706 if (i915.modeset == 0)
1707 driver.driver_features &= ~DRIVER_MODESET;
79e53945
JB
1708
1709#ifdef CONFIG_VGA_CONSOLE
d330a953 1710 if (vgacon_text_force() && i915.modeset == -1)
79e53945
JB
1711 driver.driver_features &= ~DRIVER_MODESET;
1712#endif
1713
b30324ad 1714 if (!(driver.driver_features & DRIVER_MODESET)) {
3885c6bb 1715 driver.get_vblank_timestamp = NULL;
b30324ad 1716 /* Silently fail loading to not upset userspace. */
c9cd7b65 1717 DRM_DEBUG_DRIVER("KMS and UMS disabled.\n");
b30324ad 1718 return 0;
b30324ad 1719 }
3885c6bb 1720
b2e7723b
MR
1721 /*
1722 * FIXME: Note that we're lying to the DRM core here so that we can get access
1723 * to the atomic ioctl and the atomic properties. Only plane operations on
1724 * a single CRTC will actually work.
1725 */
74c090b1 1726 if (driver.driver_features & DRIVER_MODESET)
b2e7723b
MR
1727 driver.driver_features |= DRIVER_ATOMIC;
1728
8410ea3b 1729 return drm_pci_init(&driver, &i915_pci_driver);
1da177e4
LT
1730}
1731
1732static void __exit i915_exit(void)
1733{
b33ecdd1
DV
1734 if (!(driver.driver_features & DRIVER_MODESET))
1735 return; /* Never loaded a driver. */
b33ecdd1 1736
8410ea3b 1737 drm_pci_exit(&driver, &i915_pci_driver);
1da177e4
LT
1738}
1739
1740module_init(i915_init);
1741module_exit(i915_exit);
1742
0a6d1631 1743MODULE_AUTHOR("Tungsten Graphics, Inc.");
1eab9234 1744MODULE_AUTHOR("Intel Corporation");
0a6d1631 1745
b5e89ed5 1746MODULE_DESCRIPTION(DRIVER_DESC);
1da177e4 1747MODULE_LICENSE("GPL and additional rights");
This page took 0.890171 seconds and 5 git commands to generate.