Commit | Line | Data |
---|---|---|
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> |
760285e7 DH |
31 | #include <drm/drmP.h> |
32 | #include <drm/i915_drm.h> | |
1da177e4 | 33 | #include "i915_drv.h" |
990bbdad | 34 | #include "i915_trace.h" |
f49f0586 | 35 | #include "intel_drv.h" |
1da177e4 | 36 | |
79e53945 | 37 | #include <linux/console.h> |
e0cd3608 | 38 | #include <linux/module.h> |
760285e7 | 39 | #include <drm/drm_crtc_helper.h> |
79e53945 | 40 | |
112b715e KH |
41 | static struct drm_driver driver; |
42 | ||
a57c774a AK |
43 | #define GEN_DEFAULT_PIPEOFFSETS \ |
44 | .pipe_offsets = { PIPE_A_OFFSET, PIPE_B_OFFSET, \ | |
45 | PIPE_C_OFFSET, PIPE_EDP_OFFSET }, \ | |
46 | .trans_offsets = { TRANSCODER_A_OFFSET, TRANSCODER_B_OFFSET, \ | |
47 | TRANSCODER_C_OFFSET, TRANSCODER_EDP_OFFSET }, \ | |
48 | .dpll_offsets = { DPLL_A_OFFSET, DPLL_B_OFFSET }, \ | |
49 | .dpll_md_offsets = { DPLL_A_MD_OFFSET, DPLL_B_MD_OFFSET }, \ | |
50 | .palette_offsets = { PALETTE_A_OFFSET, PALETTE_B_OFFSET } | |
51 | ||
52 | ||
9a7e8492 | 53 | static const struct intel_device_info intel_i830_info = { |
7eb552ae | 54 | .gen = 2, .is_mobile = 1, .cursor_needs_physical = 1, .num_pipes = 2, |
31578148 | 55 | .has_overlay = 1, .overlay_needs_physical = 1, |
73ae478c | 56 | .ring_mask = RENDER_RING, |
a57c774a | 57 | GEN_DEFAULT_PIPEOFFSETS, |
cfdf1fa2 KH |
58 | }; |
59 | ||
9a7e8492 | 60 | static const struct intel_device_info intel_845g_info = { |
7eb552ae | 61 | .gen = 2, .num_pipes = 1, |
31578148 | 62 | .has_overlay = 1, .overlay_needs_physical = 1, |
73ae478c | 63 | .ring_mask = RENDER_RING, |
a57c774a | 64 | GEN_DEFAULT_PIPEOFFSETS, |
cfdf1fa2 KH |
65 | }; |
66 | ||
9a7e8492 | 67 | static const struct intel_device_info intel_i85x_info = { |
7eb552ae | 68 | .gen = 2, .is_i85x = 1, .is_mobile = 1, .num_pipes = 2, |
5ce8ba7c | 69 | .cursor_needs_physical = 1, |
31578148 | 70 | .has_overlay = 1, .overlay_needs_physical = 1, |
fd70d52a | 71 | .has_fbc = 1, |
73ae478c | 72 | .ring_mask = RENDER_RING, |
a57c774a | 73 | GEN_DEFAULT_PIPEOFFSETS, |
cfdf1fa2 KH |
74 | }; |
75 | ||
9a7e8492 | 76 | static const struct intel_device_info intel_i865g_info = { |
7eb552ae | 77 | .gen = 2, .num_pipes = 1, |
31578148 | 78 | .has_overlay = 1, .overlay_needs_physical = 1, |
73ae478c | 79 | .ring_mask = RENDER_RING, |
a57c774a | 80 | GEN_DEFAULT_PIPEOFFSETS, |
cfdf1fa2 KH |
81 | }; |
82 | ||
9a7e8492 | 83 | static const struct intel_device_info intel_i915g_info = { |
7eb552ae | 84 | .gen = 3, .is_i915g = 1, .cursor_needs_physical = 1, .num_pipes = 2, |
31578148 | 85 | .has_overlay = 1, .overlay_needs_physical = 1, |
73ae478c | 86 | .ring_mask = RENDER_RING, |
a57c774a | 87 | GEN_DEFAULT_PIPEOFFSETS, |
cfdf1fa2 | 88 | }; |
9a7e8492 | 89 | static const struct intel_device_info intel_i915gm_info = { |
7eb552ae | 90 | .gen = 3, .is_mobile = 1, .num_pipes = 2, |
b295d1b6 | 91 | .cursor_needs_physical = 1, |
31578148 | 92 | .has_overlay = 1, .overlay_needs_physical = 1, |
a6c45cf0 | 93 | .supports_tv = 1, |
fd70d52a | 94 | .has_fbc = 1, |
73ae478c | 95 | .ring_mask = RENDER_RING, |
a57c774a | 96 | GEN_DEFAULT_PIPEOFFSETS, |
cfdf1fa2 | 97 | }; |
9a7e8492 | 98 | static const struct intel_device_info intel_i945g_info = { |
7eb552ae | 99 | .gen = 3, .has_hotplug = 1, .cursor_needs_physical = 1, .num_pipes = 2, |
31578148 | 100 | .has_overlay = 1, .overlay_needs_physical = 1, |
73ae478c | 101 | .ring_mask = RENDER_RING, |
a57c774a | 102 | GEN_DEFAULT_PIPEOFFSETS, |
cfdf1fa2 | 103 | }; |
9a7e8492 | 104 | static const struct intel_device_info intel_i945gm_info = { |
7eb552ae | 105 | .gen = 3, .is_i945gm = 1, .is_mobile = 1, .num_pipes = 2, |
b295d1b6 | 106 | .has_hotplug = 1, .cursor_needs_physical = 1, |
31578148 | 107 | .has_overlay = 1, .overlay_needs_physical = 1, |
a6c45cf0 | 108 | .supports_tv = 1, |
fd70d52a | 109 | .has_fbc = 1, |
73ae478c | 110 | .ring_mask = RENDER_RING, |
a57c774a | 111 | GEN_DEFAULT_PIPEOFFSETS, |
cfdf1fa2 KH |
112 | }; |
113 | ||
9a7e8492 | 114 | static const struct intel_device_info intel_i965g_info = { |
7eb552ae | 115 | .gen = 4, .is_broadwater = 1, .num_pipes = 2, |
c96c3a8c | 116 | .has_hotplug = 1, |
31578148 | 117 | .has_overlay = 1, |
73ae478c | 118 | .ring_mask = RENDER_RING, |
a57c774a | 119 | GEN_DEFAULT_PIPEOFFSETS, |
cfdf1fa2 KH |
120 | }; |
121 | ||
9a7e8492 | 122 | static const struct intel_device_info intel_i965gm_info = { |
7eb552ae | 123 | .gen = 4, .is_crestline = 1, .num_pipes = 2, |
e3c4e5dd | 124 | .is_mobile = 1, .has_fbc = 1, .has_hotplug = 1, |
31578148 | 125 | .has_overlay = 1, |
a6c45cf0 | 126 | .supports_tv = 1, |
73ae478c | 127 | .ring_mask = RENDER_RING, |
a57c774a | 128 | GEN_DEFAULT_PIPEOFFSETS, |
cfdf1fa2 KH |
129 | }; |
130 | ||
9a7e8492 | 131 | static const struct intel_device_info intel_g33_info = { |
7eb552ae | 132 | .gen = 3, .is_g33 = 1, .num_pipes = 2, |
c96c3a8c | 133 | .need_gfx_hws = 1, .has_hotplug = 1, |
31578148 | 134 | .has_overlay = 1, |
73ae478c | 135 | .ring_mask = RENDER_RING, |
a57c774a | 136 | GEN_DEFAULT_PIPEOFFSETS, |
cfdf1fa2 KH |
137 | }; |
138 | ||
9a7e8492 | 139 | static const struct intel_device_info intel_g45_info = { |
7eb552ae | 140 | .gen = 4, .is_g4x = 1, .need_gfx_hws = 1, .num_pipes = 2, |
c96c3a8c | 141 | .has_pipe_cxsr = 1, .has_hotplug = 1, |
73ae478c | 142 | .ring_mask = RENDER_RING | BSD_RING, |
a57c774a | 143 | GEN_DEFAULT_PIPEOFFSETS, |
cfdf1fa2 KH |
144 | }; |
145 | ||
9a7e8492 | 146 | static const struct intel_device_info intel_gm45_info = { |
7eb552ae | 147 | .gen = 4, .is_g4x = 1, .num_pipes = 2, |
e3c4e5dd | 148 | .is_mobile = 1, .need_gfx_hws = 1, .has_fbc = 1, |
c96c3a8c | 149 | .has_pipe_cxsr = 1, .has_hotplug = 1, |
a6c45cf0 | 150 | .supports_tv = 1, |
73ae478c | 151 | .ring_mask = RENDER_RING | BSD_RING, |
a57c774a | 152 | GEN_DEFAULT_PIPEOFFSETS, |
cfdf1fa2 KH |
153 | }; |
154 | ||
9a7e8492 | 155 | static const struct intel_device_info intel_pineview_info = { |
7eb552ae | 156 | .gen = 3, .is_g33 = 1, .is_pineview = 1, .is_mobile = 1, .num_pipes = 2, |
c96c3a8c | 157 | .need_gfx_hws = 1, .has_hotplug = 1, |
31578148 | 158 | .has_overlay = 1, |
a57c774a | 159 | GEN_DEFAULT_PIPEOFFSETS, |
cfdf1fa2 KH |
160 | }; |
161 | ||
9a7e8492 | 162 | static const struct intel_device_info intel_ironlake_d_info = { |
7eb552ae | 163 | .gen = 5, .num_pipes = 2, |
5a117db7 | 164 | .need_gfx_hws = 1, .has_hotplug = 1, |
73ae478c | 165 | .ring_mask = RENDER_RING | BSD_RING, |
a57c774a | 166 | GEN_DEFAULT_PIPEOFFSETS, |
cfdf1fa2 KH |
167 | }; |
168 | ||
9a7e8492 | 169 | static const struct intel_device_info intel_ironlake_m_info = { |
7eb552ae | 170 | .gen = 5, .is_mobile = 1, .num_pipes = 2, |
e3c4e5dd | 171 | .need_gfx_hws = 1, .has_hotplug = 1, |
c1a9f047 | 172 | .has_fbc = 1, |
73ae478c | 173 | .ring_mask = RENDER_RING | BSD_RING, |
a57c774a | 174 | GEN_DEFAULT_PIPEOFFSETS, |
cfdf1fa2 KH |
175 | }; |
176 | ||
9a7e8492 | 177 | static const struct intel_device_info intel_sandybridge_d_info = { |
7eb552ae | 178 | .gen = 6, .num_pipes = 2, |
c96c3a8c | 179 | .need_gfx_hws = 1, .has_hotplug = 1, |
cbaef0f1 | 180 | .has_fbc = 1, |
73ae478c | 181 | .ring_mask = RENDER_RING | BSD_RING | BLT_RING, |
3d29b842 | 182 | .has_llc = 1, |
a57c774a | 183 | GEN_DEFAULT_PIPEOFFSETS, |
f6e450a6 EA |
184 | }; |
185 | ||
9a7e8492 | 186 | static const struct intel_device_info intel_sandybridge_m_info = { |
7eb552ae | 187 | .gen = 6, .is_mobile = 1, .num_pipes = 2, |
c96c3a8c | 188 | .need_gfx_hws = 1, .has_hotplug = 1, |
9c04f015 | 189 | .has_fbc = 1, |
73ae478c | 190 | .ring_mask = RENDER_RING | BSD_RING | BLT_RING, |
3d29b842 | 191 | .has_llc = 1, |
a57c774a | 192 | GEN_DEFAULT_PIPEOFFSETS, |
a13e4093 EA |
193 | }; |
194 | ||
219f4fdb BW |
195 | #define GEN7_FEATURES \ |
196 | .gen = 7, .num_pipes = 3, \ | |
197 | .need_gfx_hws = 1, .has_hotplug = 1, \ | |
cbaef0f1 | 198 | .has_fbc = 1, \ |
73ae478c | 199 | .ring_mask = RENDER_RING | BSD_RING | BLT_RING, \ |
ab484f8f | 200 | .has_llc = 1 |
219f4fdb | 201 | |
c76b615c | 202 | static const struct intel_device_info intel_ivybridge_d_info = { |
219f4fdb BW |
203 | GEN7_FEATURES, |
204 | .is_ivybridge = 1, | |
a57c774a | 205 | GEN_DEFAULT_PIPEOFFSETS, |
c76b615c JB |
206 | }; |
207 | ||
208 | static const struct intel_device_info intel_ivybridge_m_info = { | |
219f4fdb BW |
209 | GEN7_FEATURES, |
210 | .is_ivybridge = 1, | |
211 | .is_mobile = 1, | |
a57c774a | 212 | GEN_DEFAULT_PIPEOFFSETS, |
c76b615c JB |
213 | }; |
214 | ||
999bcdea BW |
215 | static const struct intel_device_info intel_ivybridge_q_info = { |
216 | GEN7_FEATURES, | |
217 | .is_ivybridge = 1, | |
218 | .num_pipes = 0, /* legal, last one wins */ | |
a57c774a | 219 | GEN_DEFAULT_PIPEOFFSETS, |
999bcdea BW |
220 | }; |
221 | ||
70a3eb7a | 222 | static const struct intel_device_info intel_valleyview_m_info = { |
219f4fdb BW |
223 | GEN7_FEATURES, |
224 | .is_mobile = 1, | |
225 | .num_pipes = 2, | |
70a3eb7a | 226 | .is_valleyview = 1, |
fba5d532 | 227 | .display_mmio_offset = VLV_DISPLAY_BASE, |
cbaef0f1 | 228 | .has_fbc = 0, /* legal, last one wins */ |
30ccd964 | 229 | .has_llc = 0, /* legal, last one wins */ |
a57c774a | 230 | GEN_DEFAULT_PIPEOFFSETS, |
70a3eb7a JB |
231 | }; |
232 | ||
233 | static const struct intel_device_info intel_valleyview_d_info = { | |
219f4fdb BW |
234 | GEN7_FEATURES, |
235 | .num_pipes = 2, | |
70a3eb7a | 236 | .is_valleyview = 1, |
fba5d532 | 237 | .display_mmio_offset = VLV_DISPLAY_BASE, |
cbaef0f1 | 238 | .has_fbc = 0, /* legal, last one wins */ |
30ccd964 | 239 | .has_llc = 0, /* legal, last one wins */ |
a57c774a | 240 | GEN_DEFAULT_PIPEOFFSETS, |
70a3eb7a JB |
241 | }; |
242 | ||
4cae9ae0 | 243 | static const struct intel_device_info intel_haswell_d_info = { |
219f4fdb BW |
244 | GEN7_FEATURES, |
245 | .is_haswell = 1, | |
dd93be58 | 246 | .has_ddi = 1, |
30568c45 | 247 | .has_fpga_dbg = 1, |
73ae478c | 248 | .ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING, |
a57c774a | 249 | GEN_DEFAULT_PIPEOFFSETS, |
4cae9ae0 ED |
250 | }; |
251 | ||
252 | static const struct intel_device_info intel_haswell_m_info = { | |
219f4fdb BW |
253 | GEN7_FEATURES, |
254 | .is_haswell = 1, | |
255 | .is_mobile = 1, | |
dd93be58 | 256 | .has_ddi = 1, |
30568c45 | 257 | .has_fpga_dbg = 1, |
73ae478c | 258 | .ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING, |
a57c774a | 259 | GEN_DEFAULT_PIPEOFFSETS, |
c76b615c JB |
260 | }; |
261 | ||
4d4dead6 | 262 | static const struct intel_device_info intel_broadwell_d_info = { |
4b30553d | 263 | .gen = 8, .num_pipes = 3, |
4d4dead6 BW |
264 | .need_gfx_hws = 1, .has_hotplug = 1, |
265 | .ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING, | |
266 | .has_llc = 1, | |
267 | .has_ddi = 1, | |
8f94d24b | 268 | .has_fbc = 1, |
a57c774a | 269 | GEN_DEFAULT_PIPEOFFSETS, |
4d4dead6 BW |
270 | }; |
271 | ||
272 | static const struct intel_device_info intel_broadwell_m_info = { | |
4b30553d | 273 | .gen = 8, .is_mobile = 1, .num_pipes = 3, |
4d4dead6 BW |
274 | .need_gfx_hws = 1, .has_hotplug = 1, |
275 | .ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING, | |
276 | .has_llc = 1, | |
277 | .has_ddi = 1, | |
8f94d24b | 278 | .has_fbc = 1, |
a57c774a | 279 | GEN_DEFAULT_PIPEOFFSETS, |
4d4dead6 BW |
280 | }; |
281 | ||
fd3c269f ZY |
282 | static const struct intel_device_info intel_broadwell_gt3d_info = { |
283 | .gen = 8, .num_pipes = 3, | |
284 | .need_gfx_hws = 1, .has_hotplug = 1, | |
845f74a7 | 285 | .ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING | BSD2_RING, |
fd3c269f ZY |
286 | .has_llc = 1, |
287 | .has_ddi = 1, | |
288 | .has_fbc = 1, | |
289 | GEN_DEFAULT_PIPEOFFSETS, | |
290 | }; | |
291 | ||
292 | static const struct intel_device_info intel_broadwell_gt3m_info = { | |
293 | .gen = 8, .is_mobile = 1, .num_pipes = 3, | |
294 | .need_gfx_hws = 1, .has_hotplug = 1, | |
845f74a7 | 295 | .ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING | BSD2_RING, |
fd3c269f ZY |
296 | .has_llc = 1, |
297 | .has_ddi = 1, | |
298 | .has_fbc = 1, | |
299 | GEN_DEFAULT_PIPEOFFSETS, | |
300 | }; | |
301 | ||
7d87a7f7 VS |
302 | static const struct intel_device_info intel_cherryview_info = { |
303 | .is_preliminary = 1, | |
304 | .gen = 8, .num_pipes = 2, | |
305 | .need_gfx_hws = 1, .has_hotplug = 1, | |
306 | .ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING, | |
307 | .is_valleyview = 1, | |
308 | .display_mmio_offset = VLV_DISPLAY_BASE, | |
309 | }; | |
310 | ||
a0a18075 JB |
311 | /* |
312 | * Make sure any device matches here are from most specific to most | |
313 | * general. For example, since the Quanta match is based on the subsystem | |
314 | * and subvendor IDs, we need it to come before the more general IVB | |
315 | * PCI ID matches, otherwise we'll use the wrong info struct above. | |
316 | */ | |
317 | #define INTEL_PCI_IDS \ | |
318 | INTEL_I830_IDS(&intel_i830_info), \ | |
319 | INTEL_I845G_IDS(&intel_845g_info), \ | |
320 | INTEL_I85X_IDS(&intel_i85x_info), \ | |
321 | INTEL_I865G_IDS(&intel_i865g_info), \ | |
322 | INTEL_I915G_IDS(&intel_i915g_info), \ | |
323 | INTEL_I915GM_IDS(&intel_i915gm_info), \ | |
324 | INTEL_I945G_IDS(&intel_i945g_info), \ | |
325 | INTEL_I945GM_IDS(&intel_i945gm_info), \ | |
326 | INTEL_I965G_IDS(&intel_i965g_info), \ | |
327 | INTEL_G33_IDS(&intel_g33_info), \ | |
328 | INTEL_I965GM_IDS(&intel_i965gm_info), \ | |
329 | INTEL_GM45_IDS(&intel_gm45_info), \ | |
330 | INTEL_G45_IDS(&intel_g45_info), \ | |
331 | INTEL_PINEVIEW_IDS(&intel_pineview_info), \ | |
332 | INTEL_IRONLAKE_D_IDS(&intel_ironlake_d_info), \ | |
333 | INTEL_IRONLAKE_M_IDS(&intel_ironlake_m_info), \ | |
334 | INTEL_SNB_D_IDS(&intel_sandybridge_d_info), \ | |
335 | INTEL_SNB_M_IDS(&intel_sandybridge_m_info), \ | |
336 | INTEL_IVB_Q_IDS(&intel_ivybridge_q_info), /* must be first IVB */ \ | |
337 | INTEL_IVB_M_IDS(&intel_ivybridge_m_info), \ | |
338 | INTEL_IVB_D_IDS(&intel_ivybridge_d_info), \ | |
339 | INTEL_HSW_D_IDS(&intel_haswell_d_info), \ | |
340 | INTEL_HSW_M_IDS(&intel_haswell_m_info), \ | |
341 | INTEL_VLV_M_IDS(&intel_valleyview_m_info), \ | |
4d4dead6 | 342 | INTEL_VLV_D_IDS(&intel_valleyview_d_info), \ |
fd3c269f ZY |
343 | INTEL_BDW_GT12M_IDS(&intel_broadwell_m_info), \ |
344 | INTEL_BDW_GT12D_IDS(&intel_broadwell_d_info), \ | |
345 | INTEL_BDW_GT3M_IDS(&intel_broadwell_gt3m_info), \ | |
7d87a7f7 VS |
346 | INTEL_BDW_GT3D_IDS(&intel_broadwell_gt3d_info), \ |
347 | INTEL_CHV_IDS(&intel_cherryview_info) | |
a0a18075 | 348 | |
6103da0d | 349 | static const struct pci_device_id pciidlist[] = { /* aka */ |
a0a18075 | 350 | INTEL_PCI_IDS, |
49ae35f2 | 351 | {0, 0, 0} |
1da177e4 LT |
352 | }; |
353 | ||
79e53945 JB |
354 | #if defined(CONFIG_DRM_I915_KMS) |
355 | MODULE_DEVICE_TABLE(pci, pciidlist); | |
356 | #endif | |
357 | ||
0206e353 | 358 | void intel_detect_pch(struct drm_device *dev) |
3bad0781 ZW |
359 | { |
360 | struct drm_i915_private *dev_priv = dev->dev_private; | |
bcdb72ac | 361 | struct pci_dev *pch = NULL; |
3bad0781 | 362 | |
ce1bb329 BW |
363 | /* In all current cases, num_pipes is equivalent to the PCH_NOP setting |
364 | * (which really amounts to a PCH but no South Display). | |
365 | */ | |
366 | if (INTEL_INFO(dev)->num_pipes == 0) { | |
367 | dev_priv->pch_type = PCH_NOP; | |
ce1bb329 BW |
368 | return; |
369 | } | |
370 | ||
3bad0781 ZW |
371 | /* |
372 | * The reason to probe ISA bridge instead of Dev31:Fun0 is to | |
373 | * make graphics device passthrough work easy for VMM, that only | |
374 | * need to expose ISA bridge to let driver know the real hardware | |
375 | * underneath. This is a requirement from virtualization team. | |
6a9c4b35 RG |
376 | * |
377 | * In some virtualized environments (e.g. XEN), there is irrelevant | |
378 | * ISA bridge in the system. To work reliably, we should scan trhough | |
379 | * all the ISA bridge devices and check for the first match, instead | |
380 | * of only checking the first one. | |
3bad0781 | 381 | */ |
bcdb72ac | 382 | while ((pch = pci_get_class(PCI_CLASS_BRIDGE_ISA << 8, pch))) { |
3bad0781 | 383 | if (pch->vendor == PCI_VENDOR_ID_INTEL) { |
bcdb72ac | 384 | unsigned short id = pch->device & INTEL_PCH_DEVICE_ID_MASK; |
17a303ec | 385 | dev_priv->pch_id = id; |
3bad0781 | 386 | |
90711d50 JB |
387 | if (id == INTEL_PCH_IBX_DEVICE_ID_TYPE) { |
388 | dev_priv->pch_type = PCH_IBX; | |
389 | DRM_DEBUG_KMS("Found Ibex Peak PCH\n"); | |
7fcb83cd | 390 | WARN_ON(!IS_GEN5(dev)); |
90711d50 | 391 | } else if (id == INTEL_PCH_CPT_DEVICE_ID_TYPE) { |
3bad0781 ZW |
392 | dev_priv->pch_type = PCH_CPT; |
393 | DRM_DEBUG_KMS("Found CougarPoint PCH\n"); | |
7fcb83cd | 394 | WARN_ON(!(IS_GEN6(dev) || IS_IVYBRIDGE(dev))); |
c792513b JB |
395 | } else if (id == INTEL_PCH_PPT_DEVICE_ID_TYPE) { |
396 | /* PantherPoint is CPT compatible */ | |
397 | dev_priv->pch_type = PCH_CPT; | |
492ab669 | 398 | DRM_DEBUG_KMS("Found PantherPoint PCH\n"); |
7fcb83cd | 399 | WARN_ON(!(IS_GEN6(dev) || IS_IVYBRIDGE(dev))); |
eb877ebf ED |
400 | } else if (id == INTEL_PCH_LPT_DEVICE_ID_TYPE) { |
401 | dev_priv->pch_type = PCH_LPT; | |
402 | DRM_DEBUG_KMS("Found LynxPoint PCH\n"); | |
7fcb83cd | 403 | WARN_ON(!IS_HASWELL(dev)); |
08e1413d | 404 | WARN_ON(IS_ULT(dev)); |
018f52c9 PZ |
405 | } else if (IS_BROADWELL(dev)) { |
406 | dev_priv->pch_type = PCH_LPT; | |
407 | dev_priv->pch_id = | |
408 | INTEL_PCH_LPT_LP_DEVICE_ID_TYPE; | |
409 | DRM_DEBUG_KMS("This is Broadwell, assuming " | |
410 | "LynxPoint LP PCH\n"); | |
e76e0634 BW |
411 | } else if (id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) { |
412 | dev_priv->pch_type = PCH_LPT; | |
413 | DRM_DEBUG_KMS("Found LynxPoint LP PCH\n"); | |
414 | WARN_ON(!IS_HASWELL(dev)); | |
415 | WARN_ON(!IS_ULT(dev)); | |
bcdb72ac ID |
416 | } else |
417 | continue; | |
418 | ||
6a9c4b35 | 419 | break; |
3bad0781 | 420 | } |
3bad0781 | 421 | } |
6a9c4b35 | 422 | if (!pch) |
bcdb72ac ID |
423 | DRM_DEBUG_KMS("No PCH found.\n"); |
424 | ||
425 | pci_dev_put(pch); | |
3bad0781 ZW |
426 | } |
427 | ||
2911a35b BW |
428 | bool i915_semaphore_is_enabled(struct drm_device *dev) |
429 | { | |
430 | if (INTEL_INFO(dev)->gen < 6) | |
a08acaf2 | 431 | return false; |
2911a35b | 432 | |
d330a953 JN |
433 | if (i915.semaphores >= 0) |
434 | return i915.semaphores; | |
2911a35b | 435 | |
c923facd JN |
436 | /* Until we get further testing... */ |
437 | if (IS_GEN8(dev)) | |
438 | return false; | |
439 | ||
59de3295 | 440 | #ifdef CONFIG_INTEL_IOMMU |
2911a35b | 441 | /* Enable semaphores on SNB when IO remapping is off */ |
59de3295 DV |
442 | if (INTEL_INFO(dev)->gen == 6 && intel_iommu_gfx_mapped) |
443 | return false; | |
444 | #endif | |
2911a35b | 445 | |
a08acaf2 | 446 | return true; |
2911a35b BW |
447 | } |
448 | ||
84b79f8d | 449 | static int i915_drm_freeze(struct drm_device *dev) |
ba8bbcf6 | 450 | { |
61caf87c | 451 | struct drm_i915_private *dev_priv = dev->dev_private; |
24576d23 | 452 | struct drm_crtc *crtc; |
61caf87c | 453 | |
8a187455 PZ |
454 | intel_runtime_pm_get(dev_priv); |
455 | ||
b8efb17b ZR |
456 | /* ignore lid events during suspend */ |
457 | mutex_lock(&dev_priv->modeset_restore_lock); | |
458 | dev_priv->modeset_restore = MODESET_SUSPENDED; | |
459 | mutex_unlock(&dev_priv->modeset_restore_lock); | |
460 | ||
c67a470b PZ |
461 | /* We do a lot of poking in a lot of registers, make sure they work |
462 | * properly. */ | |
da7e29bd | 463 | intel_display_set_init_power(dev_priv, true); |
cb10799c | 464 | |
5bcf719b DA |
465 | drm_kms_helper_poll_disable(dev); |
466 | ||
ba8bbcf6 | 467 | pci_save_state(dev->pdev); |
ba8bbcf6 | 468 | |
5669fcac | 469 | /* If KMS is active, we do the leavevt stuff here */ |
226485e9 | 470 | if (drm_core_check_feature(dev, DRIVER_MODESET)) { |
db1b76ca DV |
471 | int error; |
472 | ||
45c5f202 | 473 | error = i915_gem_suspend(dev); |
84b79f8d | 474 | if (error) { |
226485e9 | 475 | dev_err(&dev->pdev->dev, |
84b79f8d RW |
476 | "GEM idle failed, resume might fail\n"); |
477 | return error; | |
478 | } | |
a261b246 | 479 | |
1a01ab3b JB |
480 | cancel_delayed_work_sync(&dev_priv->rps.delayed_resume_work); |
481 | ||
226485e9 | 482 | drm_irq_uninstall(dev); |
15239099 | 483 | dev_priv->enable_hotplug_processing = false; |
24576d23 JB |
484 | /* |
485 | * Disable CRTCs directly since we want to preserve sw state | |
486 | * for _thaw. | |
487 | */ | |
7c063c72 | 488 | mutex_lock(&dev->mode_config.mutex); |
70e1e0ec | 489 | for_each_crtc(dev, crtc) |
24576d23 | 490 | dev_priv->display.crtc_disable(crtc); |
7c063c72 | 491 | mutex_unlock(&dev->mode_config.mutex); |
7d708ee4 ID |
492 | |
493 | intel_modeset_suspend_hw(dev); | |
5669fcac JB |
494 | } |
495 | ||
828c7908 BW |
496 | i915_gem_suspend_gtt_mappings(dev); |
497 | ||
9e06dd39 JB |
498 | i915_save_state(dev); |
499 | ||
44834a67 | 500 | intel_opregion_fini(dev); |
28d85cd3 | 501 | intel_uncore_fini(dev); |
8ee1c3db | 502 | |
3fa016a0 | 503 | console_lock(); |
b6f3eff7 | 504 | intel_fbdev_set_suspend(dev, FBINFO_STATE_SUSPENDED); |
3fa016a0 DA |
505 | console_unlock(); |
506 | ||
62d5d69b MK |
507 | dev_priv->suspend_count++; |
508 | ||
61caf87c | 509 | return 0; |
84b79f8d RW |
510 | } |
511 | ||
6a9ee8af | 512 | int i915_suspend(struct drm_device *dev, pm_message_t state) |
84b79f8d RW |
513 | { |
514 | int error; | |
515 | ||
516 | if (!dev || !dev->dev_private) { | |
517 | DRM_ERROR("dev: %p\n", dev); | |
518 | DRM_ERROR("DRM not initialized, aborting suspend.\n"); | |
519 | return -ENODEV; | |
520 | } | |
521 | ||
522 | if (state.event == PM_EVENT_PRETHAW) | |
523 | return 0; | |
524 | ||
5bcf719b DA |
525 | |
526 | if (dev->switch_power_state == DRM_SWITCH_POWER_OFF) | |
527 | return 0; | |
6eecba33 | 528 | |
84b79f8d RW |
529 | error = i915_drm_freeze(dev); |
530 | if (error) | |
531 | return error; | |
532 | ||
b932ccb5 DA |
533 | if (state.event == PM_EVENT_SUSPEND) { |
534 | /* Shut down the device */ | |
535 | pci_disable_device(dev->pdev); | |
536 | pci_set_power_state(dev->pdev, PCI_D3hot); | |
537 | } | |
ba8bbcf6 JB |
538 | |
539 | return 0; | |
540 | } | |
541 | ||
073f34d9 JB |
542 | void intel_console_resume(struct work_struct *work) |
543 | { | |
544 | struct drm_i915_private *dev_priv = | |
545 | container_of(work, struct drm_i915_private, | |
546 | console_resume_work); | |
547 | struct drm_device *dev = dev_priv->dev; | |
548 | ||
549 | console_lock(); | |
b6f3eff7 | 550 | intel_fbdev_set_suspend(dev, FBINFO_STATE_RUNNING); |
073f34d9 JB |
551 | console_unlock(); |
552 | } | |
553 | ||
bb60b969 JB |
554 | static void intel_resume_hotplug(struct drm_device *dev) |
555 | { | |
556 | struct drm_mode_config *mode_config = &dev->mode_config; | |
557 | struct intel_encoder *encoder; | |
558 | ||
559 | mutex_lock(&mode_config->mutex); | |
560 | DRM_DEBUG_KMS("running encoder hotplug functions\n"); | |
561 | ||
562 | list_for_each_entry(encoder, &mode_config->encoder_list, base.head) | |
563 | if (encoder->hot_plug) | |
564 | encoder->hot_plug(encoder); | |
565 | ||
566 | mutex_unlock(&mode_config->mutex); | |
567 | ||
568 | /* Just fire off a uevent and let userspace tell us what to do */ | |
569 | drm_helper_hpd_irq_event(dev); | |
570 | } | |
571 | ||
76c4b250 | 572 | static int i915_drm_thaw_early(struct drm_device *dev) |
ba8bbcf6 | 573 | { |
5669fcac | 574 | struct drm_i915_private *dev_priv = dev->dev_private; |
8ee1c3db | 575 | |
c9f7fbf9 | 576 | intel_uncore_early_sanitize(dev); |
9d49c0ef | 577 | intel_uncore_sanitize(dev); |
76c4b250 ID |
578 | intel_power_domains_init_hw(dev_priv); |
579 | ||
580 | return 0; | |
581 | } | |
582 | ||
583 | static int __i915_drm_thaw(struct drm_device *dev, bool restore_gtt_mappings) | |
584 | { | |
585 | struct drm_i915_private *dev_priv = dev->dev_private; | |
9d49c0ef PZ |
586 | |
587 | if (drm_core_check_feature(dev, DRIVER_MODESET) && | |
588 | restore_gtt_mappings) { | |
589 | mutex_lock(&dev->struct_mutex); | |
590 | i915_gem_restore_gtt_mappings(dev); | |
591 | mutex_unlock(&dev->struct_mutex); | |
592 | } | |
593 | ||
61caf87c | 594 | i915_restore_state(dev); |
44834a67 | 595 | intel_opregion_setup(dev); |
61caf87c | 596 | |
5669fcac JB |
597 | /* KMS EnterVT equivalent */ |
598 | if (drm_core_check_feature(dev, DRIVER_MODESET)) { | |
dde86e2d | 599 | intel_init_pch_refclk(dev); |
754970ee | 600 | drm_mode_config_reset(dev); |
1833b134 | 601 | |
5669fcac | 602 | mutex_lock(&dev->struct_mutex); |
074c6ada CW |
603 | if (i915_gem_init_hw(dev)) { |
604 | DRM_ERROR("failed to re-initialize GPU, declaring wedged!\n"); | |
605 | atomic_set_mask(I915_WEDGED, &dev_priv->gpu_error.reset_counter); | |
606 | } | |
5669fcac | 607 | mutex_unlock(&dev->struct_mutex); |
226485e9 | 608 | |
15239099 | 609 | /* We need working interrupts for modeset enabling ... */ |
bb0f1b5c | 610 | drm_irq_install(dev, dev->pdev->irq); |
15239099 | 611 | |
1833b134 | 612 | intel_modeset_init_hw(dev); |
24576d23 JB |
613 | |
614 | drm_modeset_lock_all(dev); | |
615 | intel_modeset_setup_hw_state(dev, true); | |
616 | drm_modeset_unlock_all(dev); | |
15239099 DV |
617 | |
618 | /* | |
619 | * ... but also need to make sure that hotplug processing | |
620 | * doesn't cause havoc. Like in the driver load code we don't | |
621 | * bother with the tiny race here where we might loose hotplug | |
622 | * notifications. | |
623 | * */ | |
20afbda2 | 624 | intel_hpd_init(dev); |
15239099 | 625 | dev_priv->enable_hotplug_processing = true; |
bb60b969 JB |
626 | /* Config may have changed between suspend and resume */ |
627 | intel_resume_hotplug(dev); | |
d5bb081b | 628 | } |
1daed3fb | 629 | |
44834a67 CW |
630 | intel_opregion_init(dev); |
631 | ||
073f34d9 JB |
632 | /* |
633 | * The console lock can be pretty contented on resume due | |
634 | * to all the printk activity. Try to keep it out of the hot | |
635 | * path of resume if possible. | |
636 | */ | |
637 | if (console_trylock()) { | |
b6f3eff7 | 638 | intel_fbdev_set_suspend(dev, FBINFO_STATE_RUNNING); |
073f34d9 JB |
639 | console_unlock(); |
640 | } else { | |
641 | schedule_work(&dev_priv->console_resume_work); | |
642 | } | |
643 | ||
b8efb17b ZR |
644 | mutex_lock(&dev_priv->modeset_restore_lock); |
645 | dev_priv->modeset_restore = MODESET_DONE; | |
646 | mutex_unlock(&dev_priv->modeset_restore_lock); | |
8a187455 PZ |
647 | |
648 | intel_runtime_pm_put(dev_priv); | |
074c6ada | 649 | return 0; |
84b79f8d RW |
650 | } |
651 | ||
1abd02e2 JB |
652 | static int i915_drm_thaw(struct drm_device *dev) |
653 | { | |
7f16e5c1 | 654 | if (drm_core_check_feature(dev, DRIVER_MODESET)) |
828c7908 | 655 | i915_check_and_clear_faults(dev); |
1abd02e2 | 656 | |
9d49c0ef | 657 | return __i915_drm_thaw(dev, true); |
84b79f8d RW |
658 | } |
659 | ||
76c4b250 | 660 | static int i915_resume_early(struct drm_device *dev) |
84b79f8d | 661 | { |
5bcf719b DA |
662 | if (dev->switch_power_state == DRM_SWITCH_POWER_OFF) |
663 | return 0; | |
664 | ||
76c4b250 ID |
665 | /* |
666 | * We have a resume ordering issue with the snd-hda driver also | |
667 | * requiring our device to be power up. Due to the lack of a | |
668 | * parent/child relationship we currently solve this with an early | |
669 | * resume hook. | |
670 | * | |
671 | * FIXME: This should be solved with a special hdmi sink device or | |
672 | * similar so that power domains can be employed. | |
673 | */ | |
84b79f8d RW |
674 | if (pci_enable_device(dev->pdev)) |
675 | return -EIO; | |
676 | ||
677 | pci_set_master(dev->pdev); | |
678 | ||
76c4b250 ID |
679 | return i915_drm_thaw_early(dev); |
680 | } | |
681 | ||
682 | int i915_resume(struct drm_device *dev) | |
683 | { | |
684 | struct drm_i915_private *dev_priv = dev->dev_private; | |
685 | int ret; | |
686 | ||
1abd02e2 JB |
687 | /* |
688 | * Platforms with opregion should have sane BIOS, older ones (gen3 and | |
9d49c0ef PZ |
689 | * earlier) need to restore the GTT mappings since the BIOS might clear |
690 | * all our scratch PTEs. | |
1abd02e2 | 691 | */ |
9d49c0ef | 692 | ret = __i915_drm_thaw(dev, !dev_priv->opregion.header); |
6eecba33 CW |
693 | if (ret) |
694 | return ret; | |
695 | ||
696 | drm_kms_helper_poll_enable(dev); | |
697 | return 0; | |
ba8bbcf6 JB |
698 | } |
699 | ||
76c4b250 ID |
700 | static int i915_resume_legacy(struct drm_device *dev) |
701 | { | |
702 | i915_resume_early(dev); | |
703 | i915_resume(dev); | |
704 | ||
705 | return 0; | |
706 | } | |
707 | ||
11ed50ec | 708 | /** |
f3953dcb | 709 | * i915_reset - reset chip after a hang |
11ed50ec | 710 | * @dev: drm device to reset |
11ed50ec BG |
711 | * |
712 | * Reset the chip. Useful if a hang is detected. Returns zero on successful | |
713 | * reset or otherwise an error code. | |
714 | * | |
715 | * Procedure is fairly simple: | |
716 | * - reset the chip using the reset reg | |
717 | * - re-init context state | |
718 | * - re-init hardware status page | |
719 | * - re-init ring buffer | |
720 | * - re-init interrupt state | |
721 | * - re-init display | |
722 | */ | |
d4b8bb2a | 723 | int i915_reset(struct drm_device *dev) |
11ed50ec | 724 | { |
50227e1c | 725 | struct drm_i915_private *dev_priv = dev->dev_private; |
2e7c8ee7 | 726 | bool simulated; |
0573ed4a | 727 | int ret; |
11ed50ec | 728 | |
d330a953 | 729 | if (!i915.reset) |
d78cb50b CW |
730 | return 0; |
731 | ||
d54a02c0 | 732 | mutex_lock(&dev->struct_mutex); |
11ed50ec | 733 | |
069efc1d | 734 | i915_gem_reset(dev); |
77f01230 | 735 | |
2e7c8ee7 CW |
736 | simulated = dev_priv->gpu_error.stop_rings != 0; |
737 | ||
be62acb4 MK |
738 | ret = intel_gpu_reset(dev); |
739 | ||
740 | /* Also reset the gpu hangman. */ | |
741 | if (simulated) { | |
742 | DRM_INFO("Simulated gpu hang, resetting stop_rings\n"); | |
743 | dev_priv->gpu_error.stop_rings = 0; | |
744 | if (ret == -ENODEV) { | |
f2d91a2c DV |
745 | DRM_INFO("Reset not implemented, but ignoring " |
746 | "error for simulated gpu hangs\n"); | |
be62acb4 MK |
747 | ret = 0; |
748 | } | |
2e7c8ee7 | 749 | } |
be62acb4 | 750 | |
0573ed4a | 751 | if (ret) { |
f2d91a2c | 752 | DRM_ERROR("Failed to reset chip: %i\n", ret); |
f953c935 | 753 | mutex_unlock(&dev->struct_mutex); |
f803aa55 | 754 | return ret; |
11ed50ec BG |
755 | } |
756 | ||
757 | /* Ok, now get things going again... */ | |
758 | ||
759 | /* | |
760 | * Everything depends on having the GTT running, so we need to start | |
761 | * there. Fortunately we don't need to do this unless we reset the | |
762 | * chip at a PCI level. | |
763 | * | |
764 | * Next we need to restore the context, but we don't use those | |
765 | * yet either... | |
766 | * | |
767 | * Ring buffer needs to be re-initialized in the KMS case, or if X | |
768 | * was running at the time of the reset (i.e. we weren't VT | |
769 | * switched away). | |
770 | */ | |
771 | if (drm_core_check_feature(dev, DRIVER_MODESET) || | |
db1b76ca | 772 | !dev_priv->ums.mm_suspended) { |
db1b76ca | 773 | dev_priv->ums.mm_suspended = 0; |
75a6898f | 774 | |
3d57e5bd | 775 | ret = i915_gem_init_hw(dev); |
8e88a2bd | 776 | mutex_unlock(&dev->struct_mutex); |
3d57e5bd BW |
777 | if (ret) { |
778 | DRM_ERROR("Failed hw init on reset %d\n", ret); | |
779 | return ret; | |
780 | } | |
f817586c | 781 | |
e090c53b DV |
782 | /* |
783 | * FIXME: This is horribly race against concurrent pageflip and | |
784 | * vblank wait ioctls since they can observe dev->irqs_disabled | |
785 | * being false when they shouldn't be able to. | |
786 | */ | |
11ed50ec | 787 | drm_irq_uninstall(dev); |
bb0f1b5c | 788 | drm_irq_install(dev, dev->pdev->irq); |
dd0a1aa1 JM |
789 | |
790 | /* rps/rc6 re-init is necessary to restore state lost after the | |
791 | * reset and the re-install of drm irq. Skip for ironlake per | |
792 | * previous concerns that it doesn't respond well to some forms | |
793 | * of re-init after reset. */ | |
dc1d0136 | 794 | if (INTEL_INFO(dev)->gen > 5) |
c6df39b5 | 795 | intel_reset_gt_powersave(dev); |
dd0a1aa1 | 796 | |
20afbda2 | 797 | intel_hpd_init(dev); |
bcbc324a DV |
798 | } else { |
799 | mutex_unlock(&dev->struct_mutex); | |
11ed50ec BG |
800 | } |
801 | ||
11ed50ec BG |
802 | return 0; |
803 | } | |
804 | ||
56550d94 | 805 | static int i915_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
112b715e | 806 | { |
01a06850 DV |
807 | struct intel_device_info *intel_info = |
808 | (struct intel_device_info *) ent->driver_data; | |
809 | ||
d330a953 | 810 | if (IS_PRELIMINARY_HW(intel_info) && !i915.preliminary_hw_support) { |
b833d685 BW |
811 | DRM_INFO("This hardware requires preliminary hardware support.\n" |
812 | "See CONFIG_DRM_I915_PRELIMINARY_HW_SUPPORT, and/or modparam preliminary_hw_support\n"); | |
813 | return -ENODEV; | |
814 | } | |
815 | ||
5fe49d86 CW |
816 | /* Only bind to function 0 of the device. Early generations |
817 | * used function 1 as a placeholder for multi-head. This causes | |
818 | * us confusion instead, especially on the systems where both | |
819 | * functions have the same PCI-ID! | |
820 | */ | |
821 | if (PCI_FUNC(pdev->devfn)) | |
822 | return -ENODEV; | |
823 | ||
24986ee0 | 824 | driver.driver_features &= ~(DRIVER_USE_AGP); |
01a06850 | 825 | |
dcdb1674 | 826 | return drm_get_pci_dev(pdev, ent, &driver); |
112b715e KH |
827 | } |
828 | ||
829 | static void | |
830 | i915_pci_remove(struct pci_dev *pdev) | |
831 | { | |
832 | struct drm_device *dev = pci_get_drvdata(pdev); | |
833 | ||
834 | drm_put_dev(dev); | |
835 | } | |
836 | ||
84b79f8d | 837 | static int i915_pm_suspend(struct device *dev) |
112b715e | 838 | { |
84b79f8d RW |
839 | struct pci_dev *pdev = to_pci_dev(dev); |
840 | struct drm_device *drm_dev = pci_get_drvdata(pdev); | |
112b715e | 841 | |
84b79f8d RW |
842 | if (!drm_dev || !drm_dev->dev_private) { |
843 | dev_err(dev, "DRM not initialized, aborting suspend.\n"); | |
844 | return -ENODEV; | |
845 | } | |
112b715e | 846 | |
5bcf719b DA |
847 | if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF) |
848 | return 0; | |
849 | ||
76c4b250 ID |
850 | return i915_drm_freeze(drm_dev); |
851 | } | |
852 | ||
853 | static int i915_pm_suspend_late(struct device *dev) | |
854 | { | |
855 | struct pci_dev *pdev = to_pci_dev(dev); | |
856 | struct drm_device *drm_dev = pci_get_drvdata(pdev); | |
857 | ||
858 | /* | |
859 | * We have a suspedn ordering issue with the snd-hda driver also | |
860 | * requiring our device to be power up. Due to the lack of a | |
861 | * parent/child relationship we currently solve this with an late | |
862 | * suspend hook. | |
863 | * | |
864 | * FIXME: This should be solved with a special hdmi sink device or | |
865 | * similar so that power domains can be employed. | |
866 | */ | |
867 | if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF) | |
868 | return 0; | |
112b715e | 869 | |
84b79f8d RW |
870 | pci_disable_device(pdev); |
871 | pci_set_power_state(pdev, PCI_D3hot); | |
cbda12d7 | 872 | |
84b79f8d | 873 | return 0; |
cbda12d7 ZW |
874 | } |
875 | ||
76c4b250 ID |
876 | static int i915_pm_resume_early(struct device *dev) |
877 | { | |
878 | struct pci_dev *pdev = to_pci_dev(dev); | |
879 | struct drm_device *drm_dev = pci_get_drvdata(pdev); | |
880 | ||
881 | return i915_resume_early(drm_dev); | |
882 | } | |
883 | ||
84b79f8d | 884 | static int i915_pm_resume(struct device *dev) |
cbda12d7 | 885 | { |
84b79f8d RW |
886 | struct pci_dev *pdev = to_pci_dev(dev); |
887 | struct drm_device *drm_dev = pci_get_drvdata(pdev); | |
888 | ||
889 | return i915_resume(drm_dev); | |
cbda12d7 ZW |
890 | } |
891 | ||
84b79f8d | 892 | static int i915_pm_freeze(struct device *dev) |
cbda12d7 | 893 | { |
84b79f8d RW |
894 | struct pci_dev *pdev = to_pci_dev(dev); |
895 | struct drm_device *drm_dev = pci_get_drvdata(pdev); | |
896 | ||
897 | if (!drm_dev || !drm_dev->dev_private) { | |
898 | dev_err(dev, "DRM not initialized, aborting suspend.\n"); | |
899 | return -ENODEV; | |
900 | } | |
901 | ||
902 | return i915_drm_freeze(drm_dev); | |
cbda12d7 ZW |
903 | } |
904 | ||
76c4b250 ID |
905 | static int i915_pm_thaw_early(struct device *dev) |
906 | { | |
907 | struct pci_dev *pdev = to_pci_dev(dev); | |
908 | struct drm_device *drm_dev = pci_get_drvdata(pdev); | |
909 | ||
910 | return i915_drm_thaw_early(drm_dev); | |
911 | } | |
912 | ||
84b79f8d | 913 | static int i915_pm_thaw(struct device *dev) |
cbda12d7 | 914 | { |
84b79f8d RW |
915 | struct pci_dev *pdev = to_pci_dev(dev); |
916 | struct drm_device *drm_dev = pci_get_drvdata(pdev); | |
917 | ||
918 | return i915_drm_thaw(drm_dev); | |
cbda12d7 ZW |
919 | } |
920 | ||
84b79f8d | 921 | static int i915_pm_poweroff(struct device *dev) |
cbda12d7 | 922 | { |
84b79f8d RW |
923 | struct pci_dev *pdev = to_pci_dev(dev); |
924 | struct drm_device *drm_dev = pci_get_drvdata(pdev); | |
84b79f8d | 925 | |
61caf87c | 926 | return i915_drm_freeze(drm_dev); |
cbda12d7 ZW |
927 | } |
928 | ||
0ab9cfeb | 929 | static int hsw_runtime_suspend(struct drm_i915_private *dev_priv) |
97bea207 | 930 | { |
414de7a0 | 931 | hsw_enable_pc8(dev_priv); |
0ab9cfeb ID |
932 | |
933 | return 0; | |
97bea207 PZ |
934 | } |
935 | ||
0ab9cfeb | 936 | static int snb_runtime_resume(struct drm_i915_private *dev_priv) |
9a952a0d PZ |
937 | { |
938 | struct drm_device *dev = dev_priv->dev; | |
939 | ||
9a952a0d | 940 | intel_init_pch_refclk(dev); |
0ab9cfeb ID |
941 | |
942 | return 0; | |
9a952a0d PZ |
943 | } |
944 | ||
0ab9cfeb | 945 | static int hsw_runtime_resume(struct drm_i915_private *dev_priv) |
97bea207 | 946 | { |
414de7a0 | 947 | hsw_disable_pc8(dev_priv); |
0ab9cfeb ID |
948 | |
949 | return 0; | |
97bea207 PZ |
950 | } |
951 | ||
ddeea5b0 ID |
952 | /* |
953 | * Save all Gunit registers that may be lost after a D3 and a subsequent | |
954 | * S0i[R123] transition. The list of registers needing a save/restore is | |
955 | * defined in the VLV2_S0IXRegs document. This documents marks all Gunit | |
956 | * registers in the following way: | |
957 | * - Driver: saved/restored by the driver | |
958 | * - Punit : saved/restored by the Punit firmware | |
959 | * - No, w/o marking: no need to save/restore, since the register is R/O or | |
960 | * used internally by the HW in a way that doesn't depend | |
961 | * keeping the content across a suspend/resume. | |
962 | * - Debug : used for debugging | |
963 | * | |
964 | * We save/restore all registers marked with 'Driver', with the following | |
965 | * exceptions: | |
966 | * - Registers out of use, including also registers marked with 'Debug'. | |
967 | * These have no effect on the driver's operation, so we don't save/restore | |
968 | * them to reduce the overhead. | |
969 | * - Registers that are fully setup by an initialization function called from | |
970 | * the resume path. For example many clock gating and RPS/RC6 registers. | |
971 | * - Registers that provide the right functionality with their reset defaults. | |
972 | * | |
973 | * TODO: Except for registers that based on the above 3 criteria can be safely | |
974 | * ignored, we save/restore all others, practically treating the HW context as | |
975 | * a black-box for the driver. Further investigation is needed to reduce the | |
976 | * saved/restored registers even further, by following the same 3 criteria. | |
977 | */ | |
978 | static void vlv_save_gunit_s0ix_state(struct drm_i915_private *dev_priv) | |
979 | { | |
980 | struct vlv_s0ix_state *s = &dev_priv->vlv_s0ix_state; | |
981 | int i; | |
982 | ||
983 | /* GAM 0x4000-0x4770 */ | |
984 | s->wr_watermark = I915_READ(GEN7_WR_WATERMARK); | |
985 | s->gfx_prio_ctrl = I915_READ(GEN7_GFX_PRIO_CTRL); | |
986 | s->arb_mode = I915_READ(ARB_MODE); | |
987 | s->gfx_pend_tlb0 = I915_READ(GEN7_GFX_PEND_TLB0); | |
988 | s->gfx_pend_tlb1 = I915_READ(GEN7_GFX_PEND_TLB1); | |
989 | ||
990 | for (i = 0; i < ARRAY_SIZE(s->lra_limits); i++) | |
991 | s->lra_limits[i] = I915_READ(GEN7_LRA_LIMITS_BASE + i * 4); | |
992 | ||
993 | s->media_max_req_count = I915_READ(GEN7_MEDIA_MAX_REQ_COUNT); | |
994 | s->gfx_max_req_count = I915_READ(GEN7_MEDIA_MAX_REQ_COUNT); | |
995 | ||
996 | s->render_hwsp = I915_READ(RENDER_HWS_PGA_GEN7); | |
997 | s->ecochk = I915_READ(GAM_ECOCHK); | |
998 | s->bsd_hwsp = I915_READ(BSD_HWS_PGA_GEN7); | |
999 | s->blt_hwsp = I915_READ(BLT_HWS_PGA_GEN7); | |
1000 | ||
1001 | s->tlb_rd_addr = I915_READ(GEN7_TLB_RD_ADDR); | |
1002 | ||
1003 | /* MBC 0x9024-0x91D0, 0x8500 */ | |
1004 | s->g3dctl = I915_READ(VLV_G3DCTL); | |
1005 | s->gsckgctl = I915_READ(VLV_GSCKGCTL); | |
1006 | s->mbctl = I915_READ(GEN6_MBCTL); | |
1007 | ||
1008 | /* GCP 0x9400-0x9424, 0x8100-0x810C */ | |
1009 | s->ucgctl1 = I915_READ(GEN6_UCGCTL1); | |
1010 | s->ucgctl3 = I915_READ(GEN6_UCGCTL3); | |
1011 | s->rcgctl1 = I915_READ(GEN6_RCGCTL1); | |
1012 | s->rcgctl2 = I915_READ(GEN6_RCGCTL2); | |
1013 | s->rstctl = I915_READ(GEN6_RSTCTL); | |
1014 | s->misccpctl = I915_READ(GEN7_MISCCPCTL); | |
1015 | ||
1016 | /* GPM 0xA000-0xAA84, 0x8000-0x80FC */ | |
1017 | s->gfxpause = I915_READ(GEN6_GFXPAUSE); | |
1018 | s->rpdeuhwtc = I915_READ(GEN6_RPDEUHWTC); | |
1019 | s->rpdeuc = I915_READ(GEN6_RPDEUC); | |
1020 | s->ecobus = I915_READ(ECOBUS); | |
1021 | s->pwrdwnupctl = I915_READ(VLV_PWRDWNUPCTL); | |
1022 | s->rp_down_timeout = I915_READ(GEN6_RP_DOWN_TIMEOUT); | |
1023 | s->rp_deucsw = I915_READ(GEN6_RPDEUCSW); | |
1024 | s->rcubmabdtmr = I915_READ(GEN6_RCUBMABDTMR); | |
1025 | s->rcedata = I915_READ(VLV_RCEDATA); | |
1026 | s->spare2gh = I915_READ(VLV_SPAREG2H); | |
1027 | ||
1028 | /* Display CZ domain, 0x4400C-0x4402C, 0x4F000-0x4F11F */ | |
1029 | s->gt_imr = I915_READ(GTIMR); | |
1030 | s->gt_ier = I915_READ(GTIER); | |
1031 | s->pm_imr = I915_READ(GEN6_PMIMR); | |
1032 | s->pm_ier = I915_READ(GEN6_PMIER); | |
1033 | ||
1034 | for (i = 0; i < ARRAY_SIZE(s->gt_scratch); i++) | |
1035 | s->gt_scratch[i] = I915_READ(GEN7_GT_SCRATCH_BASE + i * 4); | |
1036 | ||
1037 | /* GT SA CZ domain, 0x100000-0x138124 */ | |
1038 | s->tilectl = I915_READ(TILECTL); | |
1039 | s->gt_fifoctl = I915_READ(GTFIFOCTL); | |
1040 | s->gtlc_wake_ctrl = I915_READ(VLV_GTLC_WAKE_CTRL); | |
1041 | s->gtlc_survive = I915_READ(VLV_GTLC_SURVIVABILITY_REG); | |
1042 | s->pmwgicz = I915_READ(VLV_PMWGICZ); | |
1043 | ||
1044 | /* Gunit-Display CZ domain, 0x182028-0x1821CF */ | |
1045 | s->gu_ctl0 = I915_READ(VLV_GU_CTL0); | |
1046 | s->gu_ctl1 = I915_READ(VLV_GU_CTL1); | |
1047 | s->clock_gate_dis2 = I915_READ(VLV_GUNIT_CLOCK_GATE2); | |
1048 | ||
1049 | /* | |
1050 | * Not saving any of: | |
1051 | * DFT, 0x9800-0x9EC0 | |
1052 | * SARB, 0xB000-0xB1FC | |
1053 | * GAC, 0x5208-0x524C, 0x14000-0x14C000 | |
1054 | * PCI CFG | |
1055 | */ | |
1056 | } | |
1057 | ||
1058 | static void vlv_restore_gunit_s0ix_state(struct drm_i915_private *dev_priv) | |
1059 | { | |
1060 | struct vlv_s0ix_state *s = &dev_priv->vlv_s0ix_state; | |
1061 | u32 val; | |
1062 | int i; | |
1063 | ||
1064 | /* GAM 0x4000-0x4770 */ | |
1065 | I915_WRITE(GEN7_WR_WATERMARK, s->wr_watermark); | |
1066 | I915_WRITE(GEN7_GFX_PRIO_CTRL, s->gfx_prio_ctrl); | |
1067 | I915_WRITE(ARB_MODE, s->arb_mode | (0xffff << 16)); | |
1068 | I915_WRITE(GEN7_GFX_PEND_TLB0, s->gfx_pend_tlb0); | |
1069 | I915_WRITE(GEN7_GFX_PEND_TLB1, s->gfx_pend_tlb1); | |
1070 | ||
1071 | for (i = 0; i < ARRAY_SIZE(s->lra_limits); i++) | |
1072 | I915_WRITE(GEN7_LRA_LIMITS_BASE + i * 4, s->lra_limits[i]); | |
1073 | ||
1074 | I915_WRITE(GEN7_MEDIA_MAX_REQ_COUNT, s->media_max_req_count); | |
1075 | I915_WRITE(GEN7_MEDIA_MAX_REQ_COUNT, s->gfx_max_req_count); | |
1076 | ||
1077 | I915_WRITE(RENDER_HWS_PGA_GEN7, s->render_hwsp); | |
1078 | I915_WRITE(GAM_ECOCHK, s->ecochk); | |
1079 | I915_WRITE(BSD_HWS_PGA_GEN7, s->bsd_hwsp); | |
1080 | I915_WRITE(BLT_HWS_PGA_GEN7, s->blt_hwsp); | |
1081 | ||
1082 | I915_WRITE(GEN7_TLB_RD_ADDR, s->tlb_rd_addr); | |
1083 | ||
1084 | /* MBC 0x9024-0x91D0, 0x8500 */ | |
1085 | I915_WRITE(VLV_G3DCTL, s->g3dctl); | |
1086 | I915_WRITE(VLV_GSCKGCTL, s->gsckgctl); | |
1087 | I915_WRITE(GEN6_MBCTL, s->mbctl); | |
1088 | ||
1089 | /* GCP 0x9400-0x9424, 0x8100-0x810C */ | |
1090 | I915_WRITE(GEN6_UCGCTL1, s->ucgctl1); | |
1091 | I915_WRITE(GEN6_UCGCTL3, s->ucgctl3); | |
1092 | I915_WRITE(GEN6_RCGCTL1, s->rcgctl1); | |
1093 | I915_WRITE(GEN6_RCGCTL2, s->rcgctl2); | |
1094 | I915_WRITE(GEN6_RSTCTL, s->rstctl); | |
1095 | I915_WRITE(GEN7_MISCCPCTL, s->misccpctl); | |
1096 | ||
1097 | /* GPM 0xA000-0xAA84, 0x8000-0x80FC */ | |
1098 | I915_WRITE(GEN6_GFXPAUSE, s->gfxpause); | |
1099 | I915_WRITE(GEN6_RPDEUHWTC, s->rpdeuhwtc); | |
1100 | I915_WRITE(GEN6_RPDEUC, s->rpdeuc); | |
1101 | I915_WRITE(ECOBUS, s->ecobus); | |
1102 | I915_WRITE(VLV_PWRDWNUPCTL, s->pwrdwnupctl); | |
1103 | I915_WRITE(GEN6_RP_DOWN_TIMEOUT,s->rp_down_timeout); | |
1104 | I915_WRITE(GEN6_RPDEUCSW, s->rp_deucsw); | |
1105 | I915_WRITE(GEN6_RCUBMABDTMR, s->rcubmabdtmr); | |
1106 | I915_WRITE(VLV_RCEDATA, s->rcedata); | |
1107 | I915_WRITE(VLV_SPAREG2H, s->spare2gh); | |
1108 | ||
1109 | /* Display CZ domain, 0x4400C-0x4402C, 0x4F000-0x4F11F */ | |
1110 | I915_WRITE(GTIMR, s->gt_imr); | |
1111 | I915_WRITE(GTIER, s->gt_ier); | |
1112 | I915_WRITE(GEN6_PMIMR, s->pm_imr); | |
1113 | I915_WRITE(GEN6_PMIER, s->pm_ier); | |
1114 | ||
1115 | for (i = 0; i < ARRAY_SIZE(s->gt_scratch); i++) | |
1116 | I915_WRITE(GEN7_GT_SCRATCH_BASE + i * 4, s->gt_scratch[i]); | |
1117 | ||
1118 | /* GT SA CZ domain, 0x100000-0x138124 */ | |
1119 | I915_WRITE(TILECTL, s->tilectl); | |
1120 | I915_WRITE(GTFIFOCTL, s->gt_fifoctl); | |
1121 | /* | |
1122 | * Preserve the GT allow wake and GFX force clock bit, they are not | |
1123 | * be restored, as they are used to control the s0ix suspend/resume | |
1124 | * sequence by the caller. | |
1125 | */ | |
1126 | val = I915_READ(VLV_GTLC_WAKE_CTRL); | |
1127 | val &= VLV_GTLC_ALLOWWAKEREQ; | |
1128 | val |= s->gtlc_wake_ctrl & ~VLV_GTLC_ALLOWWAKEREQ; | |
1129 | I915_WRITE(VLV_GTLC_WAKE_CTRL, val); | |
1130 | ||
1131 | val = I915_READ(VLV_GTLC_SURVIVABILITY_REG); | |
1132 | val &= VLV_GFX_CLK_FORCE_ON_BIT; | |
1133 | val |= s->gtlc_survive & ~VLV_GFX_CLK_FORCE_ON_BIT; | |
1134 | I915_WRITE(VLV_GTLC_SURVIVABILITY_REG, val); | |
1135 | ||
1136 | I915_WRITE(VLV_PMWGICZ, s->pmwgicz); | |
1137 | ||
1138 | /* Gunit-Display CZ domain, 0x182028-0x1821CF */ | |
1139 | I915_WRITE(VLV_GU_CTL0, s->gu_ctl0); | |
1140 | I915_WRITE(VLV_GU_CTL1, s->gu_ctl1); | |
1141 | I915_WRITE(VLV_GUNIT_CLOCK_GATE2, s->clock_gate_dis2); | |
1142 | } | |
1143 | ||
650ad970 ID |
1144 | int vlv_force_gfx_clock(struct drm_i915_private *dev_priv, bool force_on) |
1145 | { | |
1146 | u32 val; | |
1147 | int err; | |
1148 | ||
1149 | val = I915_READ(VLV_GTLC_SURVIVABILITY_REG); | |
1150 | WARN_ON(!!(val & VLV_GFX_CLK_FORCE_ON_BIT) == force_on); | |
1151 | ||
1152 | #define COND (I915_READ(VLV_GTLC_SURVIVABILITY_REG) & VLV_GFX_CLK_STATUS_BIT) | |
1153 | /* Wait for a previous force-off to settle */ | |
1154 | if (force_on) { | |
8d4eee9c | 1155 | err = wait_for(!COND, 20); |
650ad970 ID |
1156 | if (err) { |
1157 | DRM_ERROR("timeout waiting for GFX clock force-off (%08x)\n", | |
1158 | I915_READ(VLV_GTLC_SURVIVABILITY_REG)); | |
1159 | return err; | |
1160 | } | |
1161 | } | |
1162 | ||
1163 | val = I915_READ(VLV_GTLC_SURVIVABILITY_REG); | |
1164 | val &= ~VLV_GFX_CLK_FORCE_ON_BIT; | |
1165 | if (force_on) | |
1166 | val |= VLV_GFX_CLK_FORCE_ON_BIT; | |
1167 | I915_WRITE(VLV_GTLC_SURVIVABILITY_REG, val); | |
1168 | ||
1169 | if (!force_on) | |
1170 | return 0; | |
1171 | ||
8d4eee9c | 1172 | err = wait_for(COND, 20); |
650ad970 ID |
1173 | if (err) |
1174 | DRM_ERROR("timeout waiting for GFX clock force-on (%08x)\n", | |
1175 | I915_READ(VLV_GTLC_SURVIVABILITY_REG)); | |
1176 | ||
1177 | return err; | |
1178 | #undef COND | |
1179 | } | |
1180 | ||
ddeea5b0 ID |
1181 | static int vlv_allow_gt_wake(struct drm_i915_private *dev_priv, bool allow) |
1182 | { | |
1183 | u32 val; | |
1184 | int err = 0; | |
1185 | ||
1186 | val = I915_READ(VLV_GTLC_WAKE_CTRL); | |
1187 | val &= ~VLV_GTLC_ALLOWWAKEREQ; | |
1188 | if (allow) | |
1189 | val |= VLV_GTLC_ALLOWWAKEREQ; | |
1190 | I915_WRITE(VLV_GTLC_WAKE_CTRL, val); | |
1191 | POSTING_READ(VLV_GTLC_WAKE_CTRL); | |
1192 | ||
1193 | #define COND (!!(I915_READ(VLV_GTLC_PW_STATUS) & VLV_GTLC_ALLOWWAKEACK) == \ | |
1194 | allow) | |
1195 | err = wait_for(COND, 1); | |
1196 | if (err) | |
1197 | DRM_ERROR("timeout disabling GT waking\n"); | |
1198 | return err; | |
1199 | #undef COND | |
1200 | } | |
1201 | ||
1202 | static int vlv_wait_for_gt_wells(struct drm_i915_private *dev_priv, | |
1203 | bool wait_for_on) | |
1204 | { | |
1205 | u32 mask; | |
1206 | u32 val; | |
1207 | int err; | |
1208 | ||
1209 | mask = VLV_GTLC_PW_MEDIA_STATUS_MASK | VLV_GTLC_PW_RENDER_STATUS_MASK; | |
1210 | val = wait_for_on ? mask : 0; | |
1211 | #define COND ((I915_READ(VLV_GTLC_PW_STATUS) & mask) == val) | |
1212 | if (COND) | |
1213 | return 0; | |
1214 | ||
1215 | DRM_DEBUG_KMS("waiting for GT wells to go %s (%08x)\n", | |
1216 | wait_for_on ? "on" : "off", | |
1217 | I915_READ(VLV_GTLC_PW_STATUS)); | |
1218 | ||
1219 | /* | |
1220 | * RC6 transitioning can be delayed up to 2 msec (see | |
1221 | * valleyview_enable_rps), use 3 msec for safety. | |
1222 | */ | |
1223 | err = wait_for(COND, 3); | |
1224 | if (err) | |
1225 | DRM_ERROR("timeout waiting for GT wells to go %s\n", | |
1226 | wait_for_on ? "on" : "off"); | |
1227 | ||
1228 | return err; | |
1229 | #undef COND | |
1230 | } | |
1231 | ||
1232 | static void vlv_check_no_gt_access(struct drm_i915_private *dev_priv) | |
1233 | { | |
1234 | if (!(I915_READ(VLV_GTLC_PW_STATUS) & VLV_GTLC_ALLOWWAKEERR)) | |
1235 | return; | |
1236 | ||
1237 | DRM_ERROR("GT register access while GT waking disabled\n"); | |
1238 | I915_WRITE(VLV_GTLC_PW_STATUS, VLV_GTLC_ALLOWWAKEERR); | |
1239 | } | |
1240 | ||
1241 | static int vlv_runtime_suspend(struct drm_i915_private *dev_priv) | |
1242 | { | |
1243 | u32 mask; | |
1244 | int err; | |
1245 | ||
1246 | /* | |
1247 | * Bspec defines the following GT well on flags as debug only, so | |
1248 | * don't treat them as hard failures. | |
1249 | */ | |
1250 | (void)vlv_wait_for_gt_wells(dev_priv, false); | |
1251 | ||
1252 | mask = VLV_GTLC_RENDER_CTX_EXISTS | VLV_GTLC_MEDIA_CTX_EXISTS; | |
1253 | WARN_ON((I915_READ(VLV_GTLC_WAKE_CTRL) & mask) != mask); | |
1254 | ||
1255 | vlv_check_no_gt_access(dev_priv); | |
1256 | ||
1257 | err = vlv_force_gfx_clock(dev_priv, true); | |
1258 | if (err) | |
1259 | goto err1; | |
1260 | ||
1261 | err = vlv_allow_gt_wake(dev_priv, false); | |
1262 | if (err) | |
1263 | goto err2; | |
1264 | vlv_save_gunit_s0ix_state(dev_priv); | |
1265 | ||
1266 | err = vlv_force_gfx_clock(dev_priv, false); | |
1267 | if (err) | |
1268 | goto err2; | |
1269 | ||
1270 | return 0; | |
1271 | ||
1272 | err2: | |
1273 | /* For safety always re-enable waking and disable gfx clock forcing */ | |
1274 | vlv_allow_gt_wake(dev_priv, true); | |
1275 | err1: | |
1276 | vlv_force_gfx_clock(dev_priv, false); | |
1277 | ||
1278 | return err; | |
1279 | } | |
1280 | ||
1281 | static int vlv_runtime_resume(struct drm_i915_private *dev_priv) | |
1282 | { | |
1283 | struct drm_device *dev = dev_priv->dev; | |
1284 | int err; | |
1285 | int ret; | |
1286 | ||
1287 | /* | |
1288 | * If any of the steps fail just try to continue, that's the best we | |
1289 | * can do at this point. Return the first error code (which will also | |
1290 | * leave RPM permanently disabled). | |
1291 | */ | |
1292 | ret = vlv_force_gfx_clock(dev_priv, true); | |
1293 | ||
1294 | vlv_restore_gunit_s0ix_state(dev_priv); | |
1295 | ||
1296 | err = vlv_allow_gt_wake(dev_priv, true); | |
1297 | if (!ret) | |
1298 | ret = err; | |
1299 | ||
1300 | err = vlv_force_gfx_clock(dev_priv, false); | |
1301 | if (!ret) | |
1302 | ret = err; | |
1303 | ||
1304 | vlv_check_no_gt_access(dev_priv); | |
1305 | ||
1306 | intel_init_clock_gating(dev); | |
1307 | i915_gem_restore_fences(dev); | |
1308 | ||
1309 | return ret; | |
1310 | } | |
1311 | ||
97bea207 | 1312 | static int intel_runtime_suspend(struct device *device) |
8a187455 PZ |
1313 | { |
1314 | struct pci_dev *pdev = to_pci_dev(device); | |
1315 | struct drm_device *dev = pci_get_drvdata(pdev); | |
1316 | struct drm_i915_private *dev_priv = dev->dev_private; | |
0ab9cfeb | 1317 | int ret; |
8a187455 | 1318 | |
aeab0b5a | 1319 | if (WARN_ON_ONCE(!(dev_priv->rps.enabled && intel_enable_rc6(dev)))) |
c6df39b5 ID |
1320 | return -ENODEV; |
1321 | ||
8a187455 | 1322 | WARN_ON(!HAS_RUNTIME_PM(dev)); |
e998c40f | 1323 | assert_force_wake_inactive(dev_priv); |
8a187455 PZ |
1324 | |
1325 | DRM_DEBUG_KMS("Suspending device\n"); | |
1326 | ||
9486db61 ID |
1327 | /* |
1328 | * rps.work can't be rearmed here, since we get here only after making | |
1329 | * sure the GPU is idle and the RPS freq is set to the minimum. See | |
1330 | * intel_mark_idle(). | |
1331 | */ | |
1332 | cancel_work_sync(&dev_priv->rps.work); | |
b5478bcd ID |
1333 | intel_runtime_pm_disable_interrupts(dev); |
1334 | ||
0ab9cfeb ID |
1335 | if (IS_GEN6(dev)) { |
1336 | ret = 0; | |
1337 | } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { | |
1338 | ret = hsw_runtime_suspend(dev_priv); | |
ddeea5b0 ID |
1339 | } else if (IS_VALLEYVIEW(dev)) { |
1340 | ret = vlv_runtime_suspend(dev_priv); | |
0ab9cfeb ID |
1341 | } else { |
1342 | ret = -ENODEV; | |
6157d3c8 | 1343 | WARN_ON(1); |
0ab9cfeb ID |
1344 | } |
1345 | ||
1346 | if (ret) { | |
1347 | DRM_ERROR("Runtime suspend failed, disabling it (%d)\n", ret); | |
1348 | intel_runtime_pm_restore_interrupts(dev); | |
1349 | ||
1350 | return ret; | |
1351 | } | |
a8a8bd54 | 1352 | |
48018a57 PZ |
1353 | i915_gem_release_all_mmaps(dev_priv); |
1354 | ||
16a3d6ef | 1355 | del_timer_sync(&dev_priv->gpu_error.hangcheck_timer); |
8a187455 | 1356 | dev_priv->pm.suspended = true; |
1fb2362b KCA |
1357 | |
1358 | /* | |
1359 | * current versions of firmware which depend on this opregion | |
1360 | * notification have repurposed the D1 definition to mean | |
1361 | * "runtime suspended" vs. what you would normally expect (D3) | |
1362 | * to distinguish it from notifications that might be sent | |
1363 | * via the suspend path. | |
1364 | */ | |
1365 | intel_opregion_notify_adapter(dev, PCI_D1); | |
8a187455 | 1366 | |
a8a8bd54 | 1367 | DRM_DEBUG_KMS("Device suspended\n"); |
8a187455 PZ |
1368 | return 0; |
1369 | } | |
1370 | ||
97bea207 | 1371 | static int intel_runtime_resume(struct device *device) |
8a187455 PZ |
1372 | { |
1373 | struct pci_dev *pdev = to_pci_dev(device); | |
1374 | struct drm_device *dev = pci_get_drvdata(pdev); | |
1375 | struct drm_i915_private *dev_priv = dev->dev_private; | |
0ab9cfeb | 1376 | int ret; |
8a187455 PZ |
1377 | |
1378 | WARN_ON(!HAS_RUNTIME_PM(dev)); | |
1379 | ||
1380 | DRM_DEBUG_KMS("Resuming device\n"); | |
1381 | ||
cd2e9e90 | 1382 | intel_opregion_notify_adapter(dev, PCI_D0); |
8a187455 PZ |
1383 | dev_priv->pm.suspended = false; |
1384 | ||
0ab9cfeb ID |
1385 | if (IS_GEN6(dev)) { |
1386 | ret = snb_runtime_resume(dev_priv); | |
1387 | } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { | |
1388 | ret = hsw_runtime_resume(dev_priv); | |
ddeea5b0 ID |
1389 | } else if (IS_VALLEYVIEW(dev)) { |
1390 | ret = vlv_runtime_resume(dev_priv); | |
0ab9cfeb | 1391 | } else { |
6157d3c8 | 1392 | WARN_ON(1); |
0ab9cfeb ID |
1393 | ret = -ENODEV; |
1394 | } | |
a8a8bd54 | 1395 | |
0ab9cfeb ID |
1396 | /* |
1397 | * No point of rolling back things in case of an error, as the best | |
1398 | * we can do is to hope that things will still work (and disable RPM). | |
1399 | */ | |
92b806d3 ID |
1400 | i915_gem_init_swizzling(dev); |
1401 | gen6_update_ring_freq(dev); | |
1402 | ||
b5478bcd | 1403 | intel_runtime_pm_restore_interrupts(dev); |
9486db61 | 1404 | intel_reset_gt_powersave(dev); |
b5478bcd | 1405 | |
0ab9cfeb ID |
1406 | if (ret) |
1407 | DRM_ERROR("Runtime resume failed, disabling it (%d)\n", ret); | |
1408 | else | |
1409 | DRM_DEBUG_KMS("Device resumed\n"); | |
1410 | ||
1411 | return ret; | |
8a187455 PZ |
1412 | } |
1413 | ||
b4b78d12 | 1414 | static const struct dev_pm_ops i915_pm_ops = { |
0206e353 | 1415 | .suspend = i915_pm_suspend, |
76c4b250 ID |
1416 | .suspend_late = i915_pm_suspend_late, |
1417 | .resume_early = i915_pm_resume_early, | |
0206e353 AJ |
1418 | .resume = i915_pm_resume, |
1419 | .freeze = i915_pm_freeze, | |
76c4b250 | 1420 | .thaw_early = i915_pm_thaw_early, |
0206e353 AJ |
1421 | .thaw = i915_pm_thaw, |
1422 | .poweroff = i915_pm_poweroff, | |
76c4b250 | 1423 | .restore_early = i915_pm_resume_early, |
0206e353 | 1424 | .restore = i915_pm_resume, |
97bea207 PZ |
1425 | .runtime_suspend = intel_runtime_suspend, |
1426 | .runtime_resume = intel_runtime_resume, | |
cbda12d7 ZW |
1427 | }; |
1428 | ||
78b68556 | 1429 | static const struct vm_operations_struct i915_gem_vm_ops = { |
de151cf6 | 1430 | .fault = i915_gem_fault, |
ab00b3e5 JB |
1431 | .open = drm_gem_vm_open, |
1432 | .close = drm_gem_vm_close, | |
de151cf6 JB |
1433 | }; |
1434 | ||
e08e96de AV |
1435 | static const struct file_operations i915_driver_fops = { |
1436 | .owner = THIS_MODULE, | |
1437 | .open = drm_open, | |
1438 | .release = drm_release, | |
1439 | .unlocked_ioctl = drm_ioctl, | |
1440 | .mmap = drm_gem_mmap, | |
1441 | .poll = drm_poll, | |
e08e96de AV |
1442 | .read = drm_read, |
1443 | #ifdef CONFIG_COMPAT | |
1444 | .compat_ioctl = i915_compat_ioctl, | |
1445 | #endif | |
1446 | .llseek = noop_llseek, | |
1447 | }; | |
1448 | ||
1da177e4 | 1449 | static struct drm_driver driver = { |
0c54781b MW |
1450 | /* Don't use MTRRs here; the Xserver or userspace app should |
1451 | * deal with them for Intel hardware. | |
792d2b9a | 1452 | */ |
673a394b | 1453 | .driver_features = |
24986ee0 | 1454 | DRIVER_USE_AGP | |
10ba5012 KH |
1455 | DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_GEM | DRIVER_PRIME | |
1456 | DRIVER_RENDER, | |
22eae947 | 1457 | .load = i915_driver_load, |
ba8bbcf6 | 1458 | .unload = i915_driver_unload, |
673a394b | 1459 | .open = i915_driver_open, |
22eae947 DA |
1460 | .lastclose = i915_driver_lastclose, |
1461 | .preclose = i915_driver_preclose, | |
673a394b | 1462 | .postclose = i915_driver_postclose, |
d8e29209 RW |
1463 | |
1464 | /* Used in place of i915_pm_ops for non-DRIVER_MODESET */ | |
1465 | .suspend = i915_suspend, | |
76c4b250 | 1466 | .resume = i915_resume_legacy, |
d8e29209 | 1467 | |
cda17380 | 1468 | .device_is_agp = i915_driver_device_is_agp, |
7c1c2871 DA |
1469 | .master_create = i915_master_create, |
1470 | .master_destroy = i915_master_destroy, | |
955b12de | 1471 | #if defined(CONFIG_DEBUG_FS) |
27c202ad BG |
1472 | .debugfs_init = i915_debugfs_init, |
1473 | .debugfs_cleanup = i915_debugfs_cleanup, | |
955b12de | 1474 | #endif |
673a394b | 1475 | .gem_free_object = i915_gem_free_object, |
de151cf6 | 1476 | .gem_vm_ops = &i915_gem_vm_ops, |
1286ff73 DV |
1477 | |
1478 | .prime_handle_to_fd = drm_gem_prime_handle_to_fd, | |
1479 | .prime_fd_to_handle = drm_gem_prime_fd_to_handle, | |
1480 | .gem_prime_export = i915_gem_prime_export, | |
1481 | .gem_prime_import = i915_gem_prime_import, | |
1482 | ||
ff72145b DA |
1483 | .dumb_create = i915_gem_dumb_create, |
1484 | .dumb_map_offset = i915_gem_mmap_gtt, | |
43387b37 | 1485 | .dumb_destroy = drm_gem_dumb_destroy, |
1da177e4 | 1486 | .ioctls = i915_ioctls, |
e08e96de | 1487 | .fops = &i915_driver_fops, |
22eae947 DA |
1488 | .name = DRIVER_NAME, |
1489 | .desc = DRIVER_DESC, | |
1490 | .date = DRIVER_DATE, | |
1491 | .major = DRIVER_MAJOR, | |
1492 | .minor = DRIVER_MINOR, | |
1493 | .patchlevel = DRIVER_PATCHLEVEL, | |
1da177e4 LT |
1494 | }; |
1495 | ||
8410ea3b DA |
1496 | static struct pci_driver i915_pci_driver = { |
1497 | .name = DRIVER_NAME, | |
1498 | .id_table = pciidlist, | |
1499 | .probe = i915_pci_probe, | |
1500 | .remove = i915_pci_remove, | |
1501 | .driver.pm = &i915_pm_ops, | |
1502 | }; | |
1503 | ||
1da177e4 LT |
1504 | static int __init i915_init(void) |
1505 | { | |
1506 | driver.num_ioctls = i915_max_ioctl; | |
79e53945 JB |
1507 | |
1508 | /* | |
1509 | * If CONFIG_DRM_I915_KMS is set, default to KMS unless | |
1510 | * explicitly disabled with the module pararmeter. | |
1511 | * | |
1512 | * Otherwise, just follow the parameter (defaulting to off). | |
1513 | * | |
1514 | * Allow optional vga_text_mode_force boot option to override | |
1515 | * the default behavior. | |
1516 | */ | |
1517 | #if defined(CONFIG_DRM_I915_KMS) | |
d330a953 | 1518 | if (i915.modeset != 0) |
79e53945 JB |
1519 | driver.driver_features |= DRIVER_MODESET; |
1520 | #endif | |
d330a953 | 1521 | if (i915.modeset == 1) |
79e53945 JB |
1522 | driver.driver_features |= DRIVER_MODESET; |
1523 | ||
1524 | #ifdef CONFIG_VGA_CONSOLE | |
d330a953 | 1525 | if (vgacon_text_force() && i915.modeset == -1) |
79e53945 JB |
1526 | driver.driver_features &= ~DRIVER_MODESET; |
1527 | #endif | |
1528 | ||
b30324ad | 1529 | if (!(driver.driver_features & DRIVER_MODESET)) { |
3885c6bb | 1530 | driver.get_vblank_timestamp = NULL; |
b30324ad DV |
1531 | #ifndef CONFIG_DRM_I915_UMS |
1532 | /* Silently fail loading to not upset userspace. */ | |
1533 | return 0; | |
1534 | #endif | |
1535 | } | |
3885c6bb | 1536 | |
8410ea3b | 1537 | return drm_pci_init(&driver, &i915_pci_driver); |
1da177e4 LT |
1538 | } |
1539 | ||
1540 | static void __exit i915_exit(void) | |
1541 | { | |
b33ecdd1 DV |
1542 | #ifndef CONFIG_DRM_I915_UMS |
1543 | if (!(driver.driver_features & DRIVER_MODESET)) | |
1544 | return; /* Never loaded a driver. */ | |
1545 | #endif | |
1546 | ||
8410ea3b | 1547 | drm_pci_exit(&driver, &i915_pci_driver); |
1da177e4 LT |
1548 | } |
1549 | ||
1550 | module_init(i915_init); | |
1551 | module_exit(i915_exit); | |
1552 | ||
b5e89ed5 DA |
1553 | MODULE_AUTHOR(DRIVER_AUTHOR); |
1554 | MODULE_DESCRIPTION(DRIVER_DESC); | |
1da177e4 | 1555 | MODULE_LICENSE("GPL and additional rights"); |