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> |
1da177e4 LT |
31 | #include "drmP.h" |
32 | #include "drm.h" | |
33 | #include "i915_drm.h" | |
34 | #include "i915_drv.h" | |
f49f0586 | 35 | #include "intel_drv.h" |
1da177e4 | 36 | |
79e53945 | 37 | #include <linux/console.h> |
354ff967 | 38 | #include "drm_crtc_helper.h" |
79e53945 | 39 | |
d6073d77 | 40 | static int i915_modeset = -1; |
79e53945 JB |
41 | module_param_named(modeset, i915_modeset, int, 0400); |
42 | ||
43 | unsigned int i915_fbpercrtc = 0; | |
44 | module_param_named(fbpercrtc, i915_fbpercrtc, int, 0400); | |
1da177e4 | 45 | |
fca87409 CW |
46 | int i915_panel_ignore_lid = 0; |
47 | module_param_named(panel_ignore_lid, i915_panel_ignore_lid, int, 0600); | |
48 | ||
652c393a | 49 | unsigned int i915_powersave = 1; |
0aa99277 | 50 | module_param_named(powersave, i915_powersave, int, 0600); |
652c393a | 51 | |
ac668088 CW |
52 | unsigned int i915_enable_rc6 = 0; |
53 | module_param_named(i915_enable_rc6, i915_enable_rc6, int, 0600); | |
54 | ||
33814341 JB |
55 | unsigned int i915_lvds_downclock = 0; |
56 | module_param_named(lvds_downclock, i915_lvds_downclock, int, 0400); | |
57 | ||
a7615030 CW |
58 | unsigned int i915_panel_use_ssc = 1; |
59 | module_param_named(lvds_use_ssc, i915_panel_use_ssc, int, 0600); | |
60 | ||
5a1e5b6c CW |
61 | int i915_vbt_sdvo_panel_type = -1; |
62 | module_param_named(vbt_sdvo_panel_type, i915_vbt_sdvo_panel_type, int, 0600); | |
63 | ||
311bd68e | 64 | static bool i915_try_reset = true; |
d78cb50b CW |
65 | module_param_named(reset, i915_try_reset, bool, 0600); |
66 | ||
112b715e | 67 | static struct drm_driver driver; |
1f7a6e37 | 68 | extern int intel_agp_enabled; |
112b715e | 69 | |
cfdf1fa2 | 70 | #define INTEL_VGA_DEVICE(id, info) { \ |
49ae35f2 | 71 | .class = PCI_CLASS_DISPLAY_VGA << 8, \ |
934f992c | 72 | .class_mask = 0xff0000, \ |
49ae35f2 KH |
73 | .vendor = 0x8086, \ |
74 | .device = id, \ | |
75 | .subvendor = PCI_ANY_ID, \ | |
76 | .subdevice = PCI_ANY_ID, \ | |
cfdf1fa2 KH |
77 | .driver_data = (unsigned long) info } |
78 | ||
9a7e8492 | 79 | static const struct intel_device_info intel_i830_info = { |
a6c45cf0 | 80 | .gen = 2, .is_mobile = 1, .cursor_needs_physical = 1, |
31578148 | 81 | .has_overlay = 1, .overlay_needs_physical = 1, |
cfdf1fa2 KH |
82 | }; |
83 | ||
9a7e8492 | 84 | static const struct intel_device_info intel_845g_info = { |
a6c45cf0 | 85 | .gen = 2, |
31578148 | 86 | .has_overlay = 1, .overlay_needs_physical = 1, |
cfdf1fa2 KH |
87 | }; |
88 | ||
9a7e8492 | 89 | static const struct intel_device_info intel_i85x_info = { |
a6c45cf0 | 90 | .gen = 2, .is_i85x = 1, .is_mobile = 1, |
5ce8ba7c | 91 | .cursor_needs_physical = 1, |
31578148 | 92 | .has_overlay = 1, .overlay_needs_physical = 1, |
cfdf1fa2 KH |
93 | }; |
94 | ||
9a7e8492 | 95 | static const struct intel_device_info intel_i865g_info = { |
a6c45cf0 | 96 | .gen = 2, |
31578148 | 97 | .has_overlay = 1, .overlay_needs_physical = 1, |
cfdf1fa2 KH |
98 | }; |
99 | ||
9a7e8492 | 100 | static const struct intel_device_info intel_i915g_info = { |
a6c45cf0 | 101 | .gen = 3, .is_i915g = 1, .cursor_needs_physical = 1, |
31578148 | 102 | .has_overlay = 1, .overlay_needs_physical = 1, |
cfdf1fa2 | 103 | }; |
9a7e8492 | 104 | static const struct intel_device_info intel_i915gm_info = { |
a6c45cf0 | 105 | .gen = 3, .is_mobile = 1, |
b295d1b6 | 106 | .cursor_needs_physical = 1, |
31578148 | 107 | .has_overlay = 1, .overlay_needs_physical = 1, |
a6c45cf0 | 108 | .supports_tv = 1, |
cfdf1fa2 | 109 | }; |
9a7e8492 | 110 | static const struct intel_device_info intel_i945g_info = { |
a6c45cf0 | 111 | .gen = 3, .has_hotplug = 1, .cursor_needs_physical = 1, |
31578148 | 112 | .has_overlay = 1, .overlay_needs_physical = 1, |
cfdf1fa2 | 113 | }; |
9a7e8492 | 114 | static const struct intel_device_info intel_i945gm_info = { |
a6c45cf0 | 115 | .gen = 3, .is_i945gm = 1, .is_mobile = 1, |
b295d1b6 | 116 | .has_hotplug = 1, .cursor_needs_physical = 1, |
31578148 | 117 | .has_overlay = 1, .overlay_needs_physical = 1, |
a6c45cf0 | 118 | .supports_tv = 1, |
cfdf1fa2 KH |
119 | }; |
120 | ||
9a7e8492 | 121 | static const struct intel_device_info intel_i965g_info = { |
a6c45cf0 | 122 | .gen = 4, .is_broadwater = 1, |
c96c3a8c | 123 | .has_hotplug = 1, |
31578148 | 124 | .has_overlay = 1, |
cfdf1fa2 KH |
125 | }; |
126 | ||
9a7e8492 | 127 | static const struct intel_device_info intel_i965gm_info = { |
a6c45cf0 | 128 | .gen = 4, .is_crestline = 1, |
e3c4e5dd | 129 | .is_mobile = 1, .has_fbc = 1, .has_hotplug = 1, |
31578148 | 130 | .has_overlay = 1, |
a6c45cf0 | 131 | .supports_tv = 1, |
cfdf1fa2 KH |
132 | }; |
133 | ||
9a7e8492 | 134 | static const struct intel_device_info intel_g33_info = { |
a6c45cf0 | 135 | .gen = 3, .is_g33 = 1, |
c96c3a8c | 136 | .need_gfx_hws = 1, .has_hotplug = 1, |
31578148 | 137 | .has_overlay = 1, |
cfdf1fa2 KH |
138 | }; |
139 | ||
9a7e8492 | 140 | static const struct intel_device_info intel_g45_info = { |
a6c45cf0 | 141 | .gen = 4, .is_g4x = 1, .need_gfx_hws = 1, |
c96c3a8c | 142 | .has_pipe_cxsr = 1, .has_hotplug = 1, |
92f49d9c | 143 | .has_bsd_ring = 1, |
cfdf1fa2 KH |
144 | }; |
145 | ||
9a7e8492 | 146 | static const struct intel_device_info intel_gm45_info = { |
a6c45cf0 | 147 | .gen = 4, .is_g4x = 1, |
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, |
92f49d9c | 151 | .has_bsd_ring = 1, |
cfdf1fa2 KH |
152 | }; |
153 | ||
9a7e8492 | 154 | static const struct intel_device_info intel_pineview_info = { |
a6c45cf0 | 155 | .gen = 3, .is_g33 = 1, .is_pineview = 1, .is_mobile = 1, |
c96c3a8c | 156 | .need_gfx_hws = 1, .has_hotplug = 1, |
31578148 | 157 | .has_overlay = 1, |
cfdf1fa2 KH |
158 | }; |
159 | ||
9a7e8492 | 160 | static const struct intel_device_info intel_ironlake_d_info = { |
f00a3ddf | 161 | .gen = 5, |
c96c3a8c | 162 | .need_gfx_hws = 1, .has_pipe_cxsr = 1, .has_hotplug = 1, |
92f49d9c | 163 | .has_bsd_ring = 1, |
cfdf1fa2 KH |
164 | }; |
165 | ||
9a7e8492 | 166 | static const struct intel_device_info intel_ironlake_m_info = { |
f00a3ddf | 167 | .gen = 5, .is_mobile = 1, |
e3c4e5dd | 168 | .need_gfx_hws = 1, .has_hotplug = 1, |
16c59ef3 | 169 | .has_fbc = 0, /* disabled due to buggy hardware */ |
92f49d9c | 170 | .has_bsd_ring = 1, |
cfdf1fa2 KH |
171 | }; |
172 | ||
9a7e8492 | 173 | static const struct intel_device_info intel_sandybridge_d_info = { |
a6c45cf0 | 174 | .gen = 6, |
c96c3a8c | 175 | .need_gfx_hws = 1, .has_hotplug = 1, |
881f47b6 | 176 | .has_bsd_ring = 1, |
549f7365 | 177 | .has_blt_ring = 1, |
f6e450a6 EA |
178 | }; |
179 | ||
9a7e8492 | 180 | static const struct intel_device_info intel_sandybridge_m_info = { |
a6c45cf0 | 181 | .gen = 6, .is_mobile = 1, |
c96c3a8c | 182 | .need_gfx_hws = 1, .has_hotplug = 1, |
9c04f015 | 183 | .has_fbc = 1, |
881f47b6 | 184 | .has_bsd_ring = 1, |
549f7365 | 185 | .has_blt_ring = 1, |
a13e4093 EA |
186 | }; |
187 | ||
6103da0d CW |
188 | static const struct pci_device_id pciidlist[] = { /* aka */ |
189 | INTEL_VGA_DEVICE(0x3577, &intel_i830_info), /* I830_M */ | |
190 | INTEL_VGA_DEVICE(0x2562, &intel_845g_info), /* 845_G */ | |
191 | INTEL_VGA_DEVICE(0x3582, &intel_i85x_info), /* I855_GM */ | |
5ce8ba7c | 192 | INTEL_VGA_DEVICE(0x358e, &intel_i85x_info), |
6103da0d CW |
193 | INTEL_VGA_DEVICE(0x2572, &intel_i865g_info), /* I865_G */ |
194 | INTEL_VGA_DEVICE(0x2582, &intel_i915g_info), /* I915_G */ | |
195 | INTEL_VGA_DEVICE(0x258a, &intel_i915g_info), /* E7221_G */ | |
196 | INTEL_VGA_DEVICE(0x2592, &intel_i915gm_info), /* I915_GM */ | |
197 | INTEL_VGA_DEVICE(0x2772, &intel_i945g_info), /* I945_G */ | |
198 | INTEL_VGA_DEVICE(0x27a2, &intel_i945gm_info), /* I945_GM */ | |
199 | INTEL_VGA_DEVICE(0x27ae, &intel_i945gm_info), /* I945_GME */ | |
200 | INTEL_VGA_DEVICE(0x2972, &intel_i965g_info), /* I946_GZ */ | |
201 | INTEL_VGA_DEVICE(0x2982, &intel_i965g_info), /* G35_G */ | |
202 | INTEL_VGA_DEVICE(0x2992, &intel_i965g_info), /* I965_Q */ | |
203 | INTEL_VGA_DEVICE(0x29a2, &intel_i965g_info), /* I965_G */ | |
204 | INTEL_VGA_DEVICE(0x29b2, &intel_g33_info), /* Q35_G */ | |
205 | INTEL_VGA_DEVICE(0x29c2, &intel_g33_info), /* G33_G */ | |
206 | INTEL_VGA_DEVICE(0x29d2, &intel_g33_info), /* Q33_G */ | |
207 | INTEL_VGA_DEVICE(0x2a02, &intel_i965gm_info), /* I965_GM */ | |
208 | INTEL_VGA_DEVICE(0x2a12, &intel_i965gm_info), /* I965_GME */ | |
209 | INTEL_VGA_DEVICE(0x2a42, &intel_gm45_info), /* GM45_G */ | |
210 | INTEL_VGA_DEVICE(0x2e02, &intel_g45_info), /* IGD_E_G */ | |
211 | INTEL_VGA_DEVICE(0x2e12, &intel_g45_info), /* Q45_G */ | |
212 | INTEL_VGA_DEVICE(0x2e22, &intel_g45_info), /* G45_G */ | |
213 | INTEL_VGA_DEVICE(0x2e32, &intel_g45_info), /* G41_G */ | |
214 | INTEL_VGA_DEVICE(0x2e42, &intel_g45_info), /* B43_G */ | |
41a51428 | 215 | INTEL_VGA_DEVICE(0x2e92, &intel_g45_info), /* B43_G.1 */ |
cfdf1fa2 KH |
216 | INTEL_VGA_DEVICE(0xa001, &intel_pineview_info), |
217 | INTEL_VGA_DEVICE(0xa011, &intel_pineview_info), | |
218 | INTEL_VGA_DEVICE(0x0042, &intel_ironlake_d_info), | |
219 | INTEL_VGA_DEVICE(0x0046, &intel_ironlake_m_info), | |
f6e450a6 | 220 | INTEL_VGA_DEVICE(0x0102, &intel_sandybridge_d_info), |
85540480 ZW |
221 | INTEL_VGA_DEVICE(0x0112, &intel_sandybridge_d_info), |
222 | INTEL_VGA_DEVICE(0x0122, &intel_sandybridge_d_info), | |
a13e4093 | 223 | INTEL_VGA_DEVICE(0x0106, &intel_sandybridge_m_info), |
85540480 | 224 | INTEL_VGA_DEVICE(0x0116, &intel_sandybridge_m_info), |
4fefe435 | 225 | INTEL_VGA_DEVICE(0x0126, &intel_sandybridge_m_info), |
85540480 | 226 | INTEL_VGA_DEVICE(0x010A, &intel_sandybridge_d_info), |
49ae35f2 | 227 | {0, 0, 0} |
1da177e4 LT |
228 | }; |
229 | ||
79e53945 JB |
230 | #if defined(CONFIG_DRM_I915_KMS) |
231 | MODULE_DEVICE_TABLE(pci, pciidlist); | |
232 | #endif | |
233 | ||
3bad0781 ZW |
234 | #define INTEL_PCH_DEVICE_ID_MASK 0xff00 |
235 | #define INTEL_PCH_CPT_DEVICE_ID_TYPE 0x1c00 | |
236 | ||
237 | void intel_detect_pch (struct drm_device *dev) | |
238 | { | |
239 | struct drm_i915_private *dev_priv = dev->dev_private; | |
240 | struct pci_dev *pch; | |
241 | ||
242 | /* | |
243 | * The reason to probe ISA bridge instead of Dev31:Fun0 is to | |
244 | * make graphics device passthrough work easy for VMM, that only | |
245 | * need to expose ISA bridge to let driver know the real hardware | |
246 | * underneath. This is a requirement from virtualization team. | |
247 | */ | |
248 | pch = pci_get_class(PCI_CLASS_BRIDGE_ISA << 8, NULL); | |
249 | if (pch) { | |
250 | if (pch->vendor == PCI_VENDOR_ID_INTEL) { | |
251 | int id; | |
252 | id = pch->device & INTEL_PCH_DEVICE_ID_MASK; | |
253 | ||
254 | if (id == INTEL_PCH_CPT_DEVICE_ID_TYPE) { | |
255 | dev_priv->pch_type = PCH_CPT; | |
256 | DRM_DEBUG_KMS("Found CougarPoint PCH\n"); | |
257 | } | |
258 | } | |
259 | pci_dev_put(pch); | |
260 | } | |
261 | } | |
262 | ||
eb43f4af CW |
263 | void __gen6_force_wake_get(struct drm_i915_private *dev_priv) |
264 | { | |
265 | int count; | |
266 | ||
267 | count = 0; | |
268 | while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1)) | |
269 | udelay(10); | |
270 | ||
271 | I915_WRITE_NOTRACE(FORCEWAKE, 1); | |
272 | POSTING_READ(FORCEWAKE); | |
273 | ||
274 | count = 0; | |
275 | while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1) == 0) | |
276 | udelay(10); | |
277 | } | |
278 | ||
279 | void __gen6_force_wake_put(struct drm_i915_private *dev_priv) | |
280 | { | |
281 | I915_WRITE_NOTRACE(FORCEWAKE, 0); | |
282 | POSTING_READ(FORCEWAKE); | |
283 | } | |
284 | ||
84b79f8d | 285 | static int i915_drm_freeze(struct drm_device *dev) |
ba8bbcf6 | 286 | { |
61caf87c RW |
287 | struct drm_i915_private *dev_priv = dev->dev_private; |
288 | ||
5bcf719b DA |
289 | drm_kms_helper_poll_disable(dev); |
290 | ||
ba8bbcf6 | 291 | pci_save_state(dev->pdev); |
ba8bbcf6 | 292 | |
5669fcac | 293 | /* If KMS is active, we do the leavevt stuff here */ |
226485e9 | 294 | if (drm_core_check_feature(dev, DRIVER_MODESET)) { |
84b79f8d RW |
295 | int error = i915_gem_idle(dev); |
296 | if (error) { | |
226485e9 | 297 | dev_err(&dev->pdev->dev, |
84b79f8d RW |
298 | "GEM idle failed, resume might fail\n"); |
299 | return error; | |
300 | } | |
226485e9 | 301 | drm_irq_uninstall(dev); |
5669fcac JB |
302 | } |
303 | ||
9e06dd39 JB |
304 | i915_save_state(dev); |
305 | ||
44834a67 | 306 | intel_opregion_fini(dev); |
8ee1c3db | 307 | |
84b79f8d RW |
308 | /* Modeset on resume, not lid events */ |
309 | dev_priv->modeset_on_lid = 0; | |
61caf87c RW |
310 | |
311 | return 0; | |
84b79f8d RW |
312 | } |
313 | ||
6a9ee8af | 314 | int i915_suspend(struct drm_device *dev, pm_message_t state) |
84b79f8d RW |
315 | { |
316 | int error; | |
317 | ||
318 | if (!dev || !dev->dev_private) { | |
319 | DRM_ERROR("dev: %p\n", dev); | |
320 | DRM_ERROR("DRM not initialized, aborting suspend.\n"); | |
321 | return -ENODEV; | |
322 | } | |
323 | ||
324 | if (state.event == PM_EVENT_PRETHAW) | |
325 | return 0; | |
326 | ||
5bcf719b DA |
327 | |
328 | if (dev->switch_power_state == DRM_SWITCH_POWER_OFF) | |
329 | return 0; | |
6eecba33 | 330 | |
84b79f8d RW |
331 | error = i915_drm_freeze(dev); |
332 | if (error) | |
333 | return error; | |
334 | ||
b932ccb5 DA |
335 | if (state.event == PM_EVENT_SUSPEND) { |
336 | /* Shut down the device */ | |
337 | pci_disable_device(dev->pdev); | |
338 | pci_set_power_state(dev->pdev, PCI_D3hot); | |
339 | } | |
ba8bbcf6 JB |
340 | |
341 | return 0; | |
342 | } | |
343 | ||
84b79f8d | 344 | static int i915_drm_thaw(struct drm_device *dev) |
ba8bbcf6 | 345 | { |
5669fcac | 346 | struct drm_i915_private *dev_priv = dev->dev_private; |
84b79f8d | 347 | int error = 0; |
8ee1c3db | 348 | |
d1c3b177 CW |
349 | if (drm_core_check_feature(dev, DRIVER_MODESET)) { |
350 | mutex_lock(&dev->struct_mutex); | |
351 | i915_gem_restore_gtt_mappings(dev); | |
352 | mutex_unlock(&dev->struct_mutex); | |
353 | } | |
354 | ||
61caf87c | 355 | i915_restore_state(dev); |
44834a67 | 356 | intel_opregion_setup(dev); |
61caf87c | 357 | |
5669fcac JB |
358 | /* KMS EnterVT equivalent */ |
359 | if (drm_core_check_feature(dev, DRIVER_MODESET)) { | |
360 | mutex_lock(&dev->struct_mutex); | |
361 | dev_priv->mm.suspended = 0; | |
362 | ||
84b79f8d | 363 | error = i915_gem_init_ringbuffer(dev); |
5669fcac | 364 | mutex_unlock(&dev->struct_mutex); |
226485e9 | 365 | |
500f7147 | 366 | drm_mode_config_reset(dev); |
226485e9 | 367 | drm_irq_install(dev); |
84b79f8d | 368 | |
354ff967 ZY |
369 | /* Resume the modeset for every activated CRTC */ |
370 | drm_helper_resume_force_mode(dev); | |
5669fcac | 371 | |
ac668088 | 372 | if (IS_IRONLAKE_M(dev)) |
d5bb081b JB |
373 | ironlake_enable_rc6(dev); |
374 | } | |
1daed3fb | 375 | |
44834a67 CW |
376 | intel_opregion_init(dev); |
377 | ||
c9354c85 | 378 | dev_priv->modeset_on_lid = 0; |
06891e27 | 379 | |
84b79f8d RW |
380 | return error; |
381 | } | |
382 | ||
6a9ee8af | 383 | int i915_resume(struct drm_device *dev) |
84b79f8d | 384 | { |
6eecba33 CW |
385 | int ret; |
386 | ||
5bcf719b DA |
387 | if (dev->switch_power_state == DRM_SWITCH_POWER_OFF) |
388 | return 0; | |
389 | ||
84b79f8d RW |
390 | if (pci_enable_device(dev->pdev)) |
391 | return -EIO; | |
392 | ||
393 | pci_set_master(dev->pdev); | |
394 | ||
6eecba33 CW |
395 | ret = i915_drm_thaw(dev); |
396 | if (ret) | |
397 | return ret; | |
398 | ||
399 | drm_kms_helper_poll_enable(dev); | |
400 | return 0; | |
ba8bbcf6 JB |
401 | } |
402 | ||
dc96e9b8 CW |
403 | static int i8xx_do_reset(struct drm_device *dev, u8 flags) |
404 | { | |
405 | struct drm_i915_private *dev_priv = dev->dev_private; | |
406 | ||
407 | if (IS_I85X(dev)) | |
408 | return -ENODEV; | |
409 | ||
410 | I915_WRITE(D_STATE, I915_READ(D_STATE) | DSTATE_GFX_RESET_I830); | |
411 | POSTING_READ(D_STATE); | |
412 | ||
413 | if (IS_I830(dev) || IS_845G(dev)) { | |
414 | I915_WRITE(DEBUG_RESET_I830, | |
415 | DEBUG_RESET_DISPLAY | | |
416 | DEBUG_RESET_RENDER | | |
417 | DEBUG_RESET_FULL); | |
418 | POSTING_READ(DEBUG_RESET_I830); | |
419 | msleep(1); | |
420 | ||
421 | I915_WRITE(DEBUG_RESET_I830, 0); | |
422 | POSTING_READ(DEBUG_RESET_I830); | |
423 | } | |
424 | ||
425 | msleep(1); | |
426 | ||
427 | I915_WRITE(D_STATE, I915_READ(D_STATE) & ~DSTATE_GFX_RESET_I830); | |
428 | POSTING_READ(D_STATE); | |
429 | ||
430 | return 0; | |
431 | } | |
432 | ||
f49f0586 KG |
433 | static int i965_reset_complete(struct drm_device *dev) |
434 | { | |
435 | u8 gdrst; | |
eeccdcac | 436 | pci_read_config_byte(dev->pdev, I965_GDRST, &gdrst); |
f49f0586 KG |
437 | return gdrst & 0x1; |
438 | } | |
439 | ||
0573ed4a KG |
440 | static int i965_do_reset(struct drm_device *dev, u8 flags) |
441 | { | |
442 | u8 gdrst; | |
443 | ||
ae681d96 CW |
444 | /* |
445 | * Set the domains we want to reset (GRDOM/bits 2 and 3) as | |
446 | * well as the reset bit (GR/bit 0). Setting the GR bit | |
447 | * triggers the reset; when done, the hardware will clear it. | |
448 | */ | |
0573ed4a KG |
449 | pci_read_config_byte(dev->pdev, I965_GDRST, &gdrst); |
450 | pci_write_config_byte(dev->pdev, I965_GDRST, gdrst | flags | 0x1); | |
451 | ||
452 | return wait_for(i965_reset_complete(dev), 500); | |
453 | } | |
454 | ||
455 | static int ironlake_do_reset(struct drm_device *dev, u8 flags) | |
456 | { | |
457 | struct drm_i915_private *dev_priv = dev->dev_private; | |
458 | u32 gdrst = I915_READ(MCHBAR_MIRROR_BASE + ILK_GDSR); | |
459 | I915_WRITE(MCHBAR_MIRROR_BASE + ILK_GDSR, gdrst | flags | 0x1); | |
460 | return wait_for(I915_READ(MCHBAR_MIRROR_BASE + ILK_GDSR) & 0x1, 500); | |
ba8bbcf6 JB |
461 | } |
462 | ||
cff458c2 EA |
463 | static int gen6_do_reset(struct drm_device *dev, u8 flags) |
464 | { | |
465 | struct drm_i915_private *dev_priv = dev->dev_private; | |
466 | ||
467 | I915_WRITE(GEN6_GDRST, GEN6_GRDOM_FULL); | |
468 | return wait_for((I915_READ(GEN6_GDRST) & GEN6_GRDOM_FULL) == 0, 500); | |
469 | } | |
470 | ||
11ed50ec BG |
471 | /** |
472 | * i965_reset - reset chip after a hang | |
473 | * @dev: drm device to reset | |
474 | * @flags: reset domains | |
475 | * | |
476 | * Reset the chip. Useful if a hang is detected. Returns zero on successful | |
477 | * reset or otherwise an error code. | |
478 | * | |
479 | * Procedure is fairly simple: | |
480 | * - reset the chip using the reset reg | |
481 | * - re-init context state | |
482 | * - re-init hardware status page | |
483 | * - re-init ring buffer | |
484 | * - re-init interrupt state | |
485 | * - re-init display | |
486 | */ | |
f803aa55 | 487 | int i915_reset(struct drm_device *dev, u8 flags) |
11ed50ec BG |
488 | { |
489 | drm_i915_private_t *dev_priv = dev->dev_private; | |
11ed50ec BG |
490 | /* |
491 | * We really should only reset the display subsystem if we actually | |
492 | * need to | |
493 | */ | |
494 | bool need_display = true; | |
0573ed4a | 495 | int ret; |
11ed50ec | 496 | |
d78cb50b CW |
497 | if (!i915_try_reset) |
498 | return 0; | |
499 | ||
340479aa CW |
500 | if (!mutex_trylock(&dev->struct_mutex)) |
501 | return -EBUSY; | |
11ed50ec | 502 | |
069efc1d | 503 | i915_gem_reset(dev); |
77f01230 | 504 | |
f803aa55 | 505 | ret = -ENODEV; |
ae681d96 CW |
506 | if (get_seconds() - dev_priv->last_gpu_reset < 5) { |
507 | DRM_ERROR("GPU hanging too fast, declaring wedged!\n"); | |
508 | } else switch (INTEL_INFO(dev)->gen) { | |
cff458c2 EA |
509 | case 6: |
510 | ret = gen6_do_reset(dev, flags); | |
511 | break; | |
f803aa55 | 512 | case 5: |
0573ed4a | 513 | ret = ironlake_do_reset(dev, flags); |
f803aa55 CW |
514 | break; |
515 | case 4: | |
0573ed4a | 516 | ret = i965_do_reset(dev, flags); |
f803aa55 | 517 | break; |
dc96e9b8 CW |
518 | case 2: |
519 | ret = i8xx_do_reset(dev, flags); | |
520 | break; | |
f803aa55 | 521 | } |
ae681d96 | 522 | dev_priv->last_gpu_reset = get_seconds(); |
0573ed4a | 523 | if (ret) { |
f803aa55 | 524 | DRM_ERROR("Failed to reset chip.\n"); |
f953c935 | 525 | mutex_unlock(&dev->struct_mutex); |
f803aa55 | 526 | return ret; |
11ed50ec BG |
527 | } |
528 | ||
529 | /* Ok, now get things going again... */ | |
530 | ||
531 | /* | |
532 | * Everything depends on having the GTT running, so we need to start | |
533 | * there. Fortunately we don't need to do this unless we reset the | |
534 | * chip at a PCI level. | |
535 | * | |
536 | * Next we need to restore the context, but we don't use those | |
537 | * yet either... | |
538 | * | |
539 | * Ring buffer needs to be re-initialized in the KMS case, or if X | |
540 | * was running at the time of the reset (i.e. we weren't VT | |
541 | * switched away). | |
542 | */ | |
543 | if (drm_core_check_feature(dev, DRIVER_MODESET) || | |
8187a2b7 | 544 | !dev_priv->mm.suspended) { |
11ed50ec | 545 | dev_priv->mm.suspended = 0; |
75a6898f | 546 | |
1ec14ad3 | 547 | dev_priv->ring[RCS].init(&dev_priv->ring[RCS]); |
75a6898f | 548 | if (HAS_BSD(dev)) |
1ec14ad3 | 549 | dev_priv->ring[VCS].init(&dev_priv->ring[VCS]); |
75a6898f | 550 | if (HAS_BLT(dev)) |
1ec14ad3 | 551 | dev_priv->ring[BCS].init(&dev_priv->ring[BCS]); |
75a6898f | 552 | |
11ed50ec BG |
553 | mutex_unlock(&dev->struct_mutex); |
554 | drm_irq_uninstall(dev); | |
500f7147 | 555 | drm_mode_config_reset(dev); |
11ed50ec BG |
556 | drm_irq_install(dev); |
557 | mutex_lock(&dev->struct_mutex); | |
558 | } | |
559 | ||
9fd98141 CW |
560 | mutex_unlock(&dev->struct_mutex); |
561 | ||
11ed50ec | 562 | /* |
9fd98141 CW |
563 | * Perform a full modeset as on later generations, e.g. Ironlake, we may |
564 | * need to retrain the display link and cannot just restore the register | |
565 | * values. | |
11ed50ec | 566 | */ |
9fd98141 CW |
567 | if (need_display) { |
568 | mutex_lock(&dev->mode_config.mutex); | |
569 | drm_helper_resume_force_mode(dev); | |
570 | mutex_unlock(&dev->mode_config.mutex); | |
571 | } | |
11ed50ec | 572 | |
11ed50ec BG |
573 | return 0; |
574 | } | |
575 | ||
576 | ||
112b715e KH |
577 | static int __devinit |
578 | i915_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) | |
579 | { | |
5fe49d86 CW |
580 | /* Only bind to function 0 of the device. Early generations |
581 | * used function 1 as a placeholder for multi-head. This causes | |
582 | * us confusion instead, especially on the systems where both | |
583 | * functions have the same PCI-ID! | |
584 | */ | |
585 | if (PCI_FUNC(pdev->devfn)) | |
586 | return -ENODEV; | |
587 | ||
dcdb1674 | 588 | return drm_get_pci_dev(pdev, ent, &driver); |
112b715e KH |
589 | } |
590 | ||
591 | static void | |
592 | i915_pci_remove(struct pci_dev *pdev) | |
593 | { | |
594 | struct drm_device *dev = pci_get_drvdata(pdev); | |
595 | ||
596 | drm_put_dev(dev); | |
597 | } | |
598 | ||
84b79f8d | 599 | static int i915_pm_suspend(struct device *dev) |
112b715e | 600 | { |
84b79f8d RW |
601 | struct pci_dev *pdev = to_pci_dev(dev); |
602 | struct drm_device *drm_dev = pci_get_drvdata(pdev); | |
603 | int error; | |
112b715e | 604 | |
84b79f8d RW |
605 | if (!drm_dev || !drm_dev->dev_private) { |
606 | dev_err(dev, "DRM not initialized, aborting suspend.\n"); | |
607 | return -ENODEV; | |
608 | } | |
112b715e | 609 | |
5bcf719b DA |
610 | if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF) |
611 | return 0; | |
612 | ||
84b79f8d RW |
613 | error = i915_drm_freeze(drm_dev); |
614 | if (error) | |
615 | return error; | |
112b715e | 616 | |
84b79f8d RW |
617 | pci_disable_device(pdev); |
618 | pci_set_power_state(pdev, PCI_D3hot); | |
cbda12d7 | 619 | |
84b79f8d | 620 | return 0; |
cbda12d7 ZW |
621 | } |
622 | ||
84b79f8d | 623 | static int i915_pm_resume(struct device *dev) |
cbda12d7 | 624 | { |
84b79f8d RW |
625 | struct pci_dev *pdev = to_pci_dev(dev); |
626 | struct drm_device *drm_dev = pci_get_drvdata(pdev); | |
627 | ||
628 | return i915_resume(drm_dev); | |
cbda12d7 ZW |
629 | } |
630 | ||
84b79f8d | 631 | static int i915_pm_freeze(struct device *dev) |
cbda12d7 | 632 | { |
84b79f8d RW |
633 | struct pci_dev *pdev = to_pci_dev(dev); |
634 | struct drm_device *drm_dev = pci_get_drvdata(pdev); | |
635 | ||
636 | if (!drm_dev || !drm_dev->dev_private) { | |
637 | dev_err(dev, "DRM not initialized, aborting suspend.\n"); | |
638 | return -ENODEV; | |
639 | } | |
640 | ||
641 | return i915_drm_freeze(drm_dev); | |
cbda12d7 ZW |
642 | } |
643 | ||
84b79f8d | 644 | static int i915_pm_thaw(struct device *dev) |
cbda12d7 | 645 | { |
84b79f8d RW |
646 | struct pci_dev *pdev = to_pci_dev(dev); |
647 | struct drm_device *drm_dev = pci_get_drvdata(pdev); | |
648 | ||
649 | return i915_drm_thaw(drm_dev); | |
cbda12d7 ZW |
650 | } |
651 | ||
84b79f8d | 652 | static int i915_pm_poweroff(struct device *dev) |
cbda12d7 | 653 | { |
84b79f8d RW |
654 | struct pci_dev *pdev = to_pci_dev(dev); |
655 | struct drm_device *drm_dev = pci_get_drvdata(pdev); | |
84b79f8d | 656 | |
61caf87c | 657 | return i915_drm_freeze(drm_dev); |
cbda12d7 ZW |
658 | } |
659 | ||
b4b78d12 | 660 | static const struct dev_pm_ops i915_pm_ops = { |
cbda12d7 ZW |
661 | .suspend = i915_pm_suspend, |
662 | .resume = i915_pm_resume, | |
663 | .freeze = i915_pm_freeze, | |
664 | .thaw = i915_pm_thaw, | |
665 | .poweroff = i915_pm_poweroff, | |
84b79f8d | 666 | .restore = i915_pm_resume, |
cbda12d7 ZW |
667 | }; |
668 | ||
de151cf6 JB |
669 | static struct vm_operations_struct i915_gem_vm_ops = { |
670 | .fault = i915_gem_fault, | |
ab00b3e5 JB |
671 | .open = drm_gem_vm_open, |
672 | .close = drm_gem_vm_close, | |
de151cf6 JB |
673 | }; |
674 | ||
1da177e4 | 675 | static struct drm_driver driver = { |
792d2b9a DA |
676 | /* don't use mtrr's here, the Xserver or user space app should |
677 | * deal with them for intel hardware. | |
678 | */ | |
673a394b EA |
679 | .driver_features = |
680 | DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | /* DRIVER_USE_MTRR |*/ | |
681 | DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_GEM, | |
22eae947 | 682 | .load = i915_driver_load, |
ba8bbcf6 | 683 | .unload = i915_driver_unload, |
673a394b | 684 | .open = i915_driver_open, |
22eae947 DA |
685 | .lastclose = i915_driver_lastclose, |
686 | .preclose = i915_driver_preclose, | |
673a394b | 687 | .postclose = i915_driver_postclose, |
d8e29209 RW |
688 | |
689 | /* Used in place of i915_pm_ops for non-DRIVER_MODESET */ | |
690 | .suspend = i915_suspend, | |
691 | .resume = i915_resume, | |
692 | ||
cda17380 | 693 | .device_is_agp = i915_driver_device_is_agp, |
0a3e67a4 JB |
694 | .enable_vblank = i915_enable_vblank, |
695 | .disable_vblank = i915_disable_vblank, | |
0af7e4df MK |
696 | .get_vblank_timestamp = i915_get_vblank_timestamp, |
697 | .get_scanout_position = i915_get_crtc_scanoutpos, | |
1da177e4 LT |
698 | .irq_preinstall = i915_driver_irq_preinstall, |
699 | .irq_postinstall = i915_driver_irq_postinstall, | |
700 | .irq_uninstall = i915_driver_irq_uninstall, | |
701 | .irq_handler = i915_driver_irq_handler, | |
702 | .reclaim_buffers = drm_core_reclaim_buffers, | |
7c1c2871 DA |
703 | .master_create = i915_master_create, |
704 | .master_destroy = i915_master_destroy, | |
955b12de | 705 | #if defined(CONFIG_DEBUG_FS) |
27c202ad BG |
706 | .debugfs_init = i915_debugfs_init, |
707 | .debugfs_cleanup = i915_debugfs_cleanup, | |
955b12de | 708 | #endif |
673a394b EA |
709 | .gem_init_object = i915_gem_init_object, |
710 | .gem_free_object = i915_gem_free_object, | |
de151cf6 | 711 | .gem_vm_ops = &i915_gem_vm_ops, |
1da177e4 LT |
712 | .ioctls = i915_ioctls, |
713 | .fops = { | |
b5e89ed5 DA |
714 | .owner = THIS_MODULE, |
715 | .open = drm_open, | |
716 | .release = drm_release, | |
ed8b6704 | 717 | .unlocked_ioctl = drm_ioctl, |
de151cf6 | 718 | .mmap = drm_gem_mmap, |
b5e89ed5 DA |
719 | .poll = drm_poll, |
720 | .fasync = drm_fasync, | |
c9a9c5e0 | 721 | .read = drm_read, |
8ca7c1df | 722 | #ifdef CONFIG_COMPAT |
b5e89ed5 | 723 | .compat_ioctl = i915_compat_ioctl, |
8ca7c1df | 724 | #endif |
dc880abe | 725 | .llseek = noop_llseek, |
22eae947 DA |
726 | }, |
727 | ||
1da177e4 | 728 | .pci_driver = { |
22eae947 DA |
729 | .name = DRIVER_NAME, |
730 | .id_table = pciidlist, | |
112b715e KH |
731 | .probe = i915_pci_probe, |
732 | .remove = i915_pci_remove, | |
cbda12d7 | 733 | .driver.pm = &i915_pm_ops, |
22eae947 | 734 | }, |
bc5f4523 | 735 | |
22eae947 DA |
736 | .name = DRIVER_NAME, |
737 | .desc = DRIVER_DESC, | |
738 | .date = DRIVER_DATE, | |
739 | .major = DRIVER_MAJOR, | |
740 | .minor = DRIVER_MINOR, | |
741 | .patchlevel = DRIVER_PATCHLEVEL, | |
1da177e4 LT |
742 | }; |
743 | ||
744 | static int __init i915_init(void) | |
745 | { | |
1f7a6e37 ZW |
746 | if (!intel_agp_enabled) { |
747 | DRM_ERROR("drm/i915 can't work without intel_agp module!\n"); | |
748 | return -ENODEV; | |
749 | } | |
750 | ||
1da177e4 | 751 | driver.num_ioctls = i915_max_ioctl; |
79e53945 JB |
752 | |
753 | /* | |
754 | * If CONFIG_DRM_I915_KMS is set, default to KMS unless | |
755 | * explicitly disabled with the module pararmeter. | |
756 | * | |
757 | * Otherwise, just follow the parameter (defaulting to off). | |
758 | * | |
759 | * Allow optional vga_text_mode_force boot option to override | |
760 | * the default behavior. | |
761 | */ | |
762 | #if defined(CONFIG_DRM_I915_KMS) | |
763 | if (i915_modeset != 0) | |
764 | driver.driver_features |= DRIVER_MODESET; | |
765 | #endif | |
766 | if (i915_modeset == 1) | |
767 | driver.driver_features |= DRIVER_MODESET; | |
768 | ||
769 | #ifdef CONFIG_VGA_CONSOLE | |
770 | if (vgacon_text_force() && i915_modeset == -1) | |
771 | driver.driver_features &= ~DRIVER_MODESET; | |
772 | #endif | |
773 | ||
3885c6bb CW |
774 | if (!(driver.driver_features & DRIVER_MODESET)) |
775 | driver.get_vblank_timestamp = NULL; | |
776 | ||
1da177e4 LT |
777 | return drm_init(&driver); |
778 | } | |
779 | ||
780 | static void __exit i915_exit(void) | |
781 | { | |
782 | drm_exit(&driver); | |
783 | } | |
784 | ||
785 | module_init(i915_init); | |
786 | module_exit(i915_exit); | |
787 | ||
b5e89ed5 DA |
788 | MODULE_AUTHOR(DRIVER_AUTHOR); |
789 | MODULE_DESCRIPTION(DRIVER_DESC); | |
1da177e4 | 790 | MODULE_LICENSE("GPL and additional rights"); |