1 /* i915_drv.c -- i830,i845,i855,i865,i915 driver -*- linux-c -*-
5 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
16 * The above copyright notice and this permission notice (including the
17 * next paragraph) shall be included in all copies or substantial portions
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.
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
33 #include <dev/drm2/drmP.h>
34 #include <dev/drm2/drm_pciids.h>
35 #include <dev/drm2/i915/i915_drm.h>
36 #include "dev/drm2/i915/i915_drv.h"
38 #include "dev/drm2/i915/i915_trace.h"
40 #include "dev/drm2/i915/intel_drv.h"
42 #include <dev/drm2/drm_crtc_helper.h>
46 static int i915_modeset __read_mostly = 1;
47 TUNABLE_INT("drm.i915.modeset", &i915_modeset);
48 module_param_named(modeset, i915_modeset, int, 0400);
49 MODULE_PARM_DESC(modeset,
50 "Use kernel modesetting [KMS] (0=DRM_I915_KMS from .config, "
51 "1=on, -1=force vga console preference [default])");
54 unsigned int i915_fbpercrtc __always_unused = 0;
55 module_param_named(fbpercrtc, i915_fbpercrtc, int, 0400);
58 int i915_panel_ignore_lid __read_mostly = 1;
59 TUNABLE_INT("drm.i915.panel_ignore_lid", &i915_panel_ignore_lid);
60 module_param_named(panel_ignore_lid, i915_panel_ignore_lid, int, 0600);
61 MODULE_PARM_DESC(panel_ignore_lid,
62 "Override lid status (0=autodetect, 1=autodetect disabled [default], "
63 "-1=force lid closed, -2=force lid open)");
65 unsigned int i915_powersave __read_mostly = 1;
66 TUNABLE_INT("drm.i915.powersave", &i915_powersave);
67 module_param_named(powersave, i915_powersave, int, 0600);
68 MODULE_PARM_DESC(powersave,
69 "Enable powersavings, fbc, downclocking, etc. (default: true)");
71 int i915_semaphores __read_mostly = -1;
72 TUNABLE_INT("drm.i915.semaphores", &i915_semaphores);
73 module_param_named(semaphores, i915_semaphores, int, 0600);
74 MODULE_PARM_DESC(semaphores,
75 "Use semaphores for inter-ring sync (default: -1 (use per-chip defaults))");
77 int i915_enable_rc6 __read_mostly = -1;
78 TUNABLE_INT("drm.i915.enable_rc6", &i915_enable_rc6);
79 module_param_named(i915_enable_rc6, i915_enable_rc6, int, 0400);
80 MODULE_PARM_DESC(i915_enable_rc6,
81 "Enable power-saving render C-state 6. "
82 "Different stages can be selected via bitmask values "
83 "(0 = disable; 1 = enable rc6; 2 = enable deep rc6; 4 = enable deepest rc6). "
84 "For example, 3 would enable rc6 and deep rc6, and 7 would enable everything. "
85 "default: -1 (use per-chip default)");
87 int i915_enable_fbc __read_mostly = -1;
88 TUNABLE_INT("drm.i915.enable_fbc", &i915_enable_fbc);
89 module_param_named(i915_enable_fbc, i915_enable_fbc, int, 0600);
90 MODULE_PARM_DESC(i915_enable_fbc,
91 "Enable frame buffer compression for power savings "
92 "(default: -1 (use per-chip default))");
94 unsigned int i915_lvds_downclock __read_mostly = 0;
95 TUNABLE_INT("drm.i915.lvds_downclock", &i915_lvds_downclock);
96 module_param_named(lvds_downclock, i915_lvds_downclock, int, 0400);
97 MODULE_PARM_DESC(lvds_downclock,
98 "Use panel (LVDS/eDP) downclocking for power savings "
101 int i915_lvds_channel_mode __read_mostly;
102 TUNABLE_INT("drm.i915.lvds_channel_mode", &i915_lvds_channel_mode);
103 module_param_named(lvds_channel_mode, i915_lvds_channel_mode, int, 0600);
104 MODULE_PARM_DESC(lvds_channel_mode,
105 "Specify LVDS channel mode "
106 "(0=probe BIOS [default], 1=single-channel, 2=dual-channel)");
108 int i915_panel_use_ssc __read_mostly = -1;
109 TUNABLE_INT("drm.i915.panel_use_ssc", &i915_panel_use_ssc);
110 module_param_named(lvds_use_ssc, i915_panel_use_ssc, int, 0600);
111 MODULE_PARM_DESC(lvds_use_ssc,
112 "Use Spread Spectrum Clock with panels [LVDS/eDP] "
113 "(default: auto from VBT)");
115 int i915_vbt_sdvo_panel_type __read_mostly = -1;
116 TUNABLE_INT("drm.i915.vbt_sdvo_panel_type", &i915_vbt_sdvo_panel_type);
117 module_param_named(vbt_sdvo_panel_type, i915_vbt_sdvo_panel_type, int, 0600);
118 MODULE_PARM_DESC(vbt_sdvo_panel_type,
119 "Override/Ignore selection of SDVO panel mode in the VBT "
120 "(-2=ignore, -1=auto [default], index in VBT BIOS table)");
122 static int i915_try_reset __read_mostly = true;
123 TUNABLE_INT("drm.i915.try_reset", &i915_try_reset);
124 module_param_named(reset, i915_try_reset, bool, 0600);
125 MODULE_PARM_DESC(reset, "Attempt GPU resets (default: true)");
127 int i915_enable_hangcheck __read_mostly = true;
128 TUNABLE_INT("drm.i915.enable_hangcheck", &i915_enable_hangcheck);
129 module_param_named(enable_hangcheck, i915_enable_hangcheck, bool, 0644);
130 MODULE_PARM_DESC(enable_hangcheck,
131 "Periodically check GPU activity for detecting hangs. "
132 "WARNING: Disabling this can cause system wide hangs. "
135 int i915_enable_ppgtt __read_mostly = -1;
136 TUNABLE_INT("drm.i915.enable_ppgtt", &i915_enable_ppgtt);
137 module_param_named(i915_enable_ppgtt, i915_enable_ppgtt, int, 0600);
138 MODULE_PARM_DESC(i915_enable_ppgtt,
139 "Enable PPGTT (default: true)");
141 unsigned int i915_preliminary_hw_support __read_mostly = 0;
142 TUNABLE_INT("drm.i915.enable_unsupported", &i915_preliminary_hw_support);
143 module_param_named(preliminary_hw_support, i915_preliminary_hw_support, int, 0600);
144 MODULE_PARM_DESC(preliminary_hw_support,
145 "Enable preliminary hardware support. "
146 "Enable Haswell and ValleyView Support. "
149 int intel_iommu_gfx_mapped = 0;
150 TUNABLE_INT("drm.i915.intel_iommu_gfx_mapped", &intel_iommu_gfx_mapped);
152 static struct drm_driver driver;
153 int intel_agp_enabled = 1; /* On FreeBSD, agp is a required dependency. */
155 #define INTEL_VGA_DEVICE(id, info_) { \
160 static const struct intel_device_info intel_i830_info = {
161 .gen = 2, .is_mobile = 1, .cursor_needs_physical = 1,
162 .has_overlay = 1, .overlay_needs_physical = 1,
165 static const struct intel_device_info intel_845g_info = {
167 .has_overlay = 1, .overlay_needs_physical = 1,
170 static const struct intel_device_info intel_i85x_info = {
171 .gen = 2, .is_i85x = 1, .is_mobile = 1,
172 .cursor_needs_physical = 1,
173 .has_overlay = 1, .overlay_needs_physical = 1,
176 static const struct intel_device_info intel_i865g_info = {
178 .has_overlay = 1, .overlay_needs_physical = 1,
181 static const struct intel_device_info intel_i915g_info = {
182 .gen = 3, .is_i915g = 1, .cursor_needs_physical = 1,
183 .has_overlay = 1, .overlay_needs_physical = 1,
185 static const struct intel_device_info intel_i915gm_info = {
186 .gen = 3, .is_mobile = 1,
187 .cursor_needs_physical = 1,
188 .has_overlay = 1, .overlay_needs_physical = 1,
191 static const struct intel_device_info intel_i945g_info = {
192 .gen = 3, .has_hotplug = 1, .cursor_needs_physical = 1,
193 .has_overlay = 1, .overlay_needs_physical = 1,
195 static const struct intel_device_info intel_i945gm_info = {
196 .gen = 3, .is_i945gm = 1, .is_mobile = 1,
197 .has_hotplug = 1, .cursor_needs_physical = 1,
198 .has_overlay = 1, .overlay_needs_physical = 1,
202 static const struct intel_device_info intel_i965g_info = {
203 .gen = 4, .is_broadwater = 1,
208 static const struct intel_device_info intel_i965gm_info = {
209 .gen = 4, .is_crestline = 1,
210 .is_mobile = 1, .has_fbc = 1, .has_hotplug = 1,
215 static const struct intel_device_info intel_g33_info = {
216 .gen = 3, .is_g33 = 1,
217 .need_gfx_hws = 1, .has_hotplug = 1,
221 static const struct intel_device_info intel_g45_info = {
222 .gen = 4, .is_g4x = 1, .need_gfx_hws = 1,
223 .has_pipe_cxsr = 1, .has_hotplug = 1,
227 static const struct intel_device_info intel_gm45_info = {
228 .gen = 4, .is_g4x = 1,
229 .is_mobile = 1, .need_gfx_hws = 1, .has_fbc = 1,
230 .has_pipe_cxsr = 1, .has_hotplug = 1,
235 static const struct intel_device_info intel_pineview_info = {
236 .gen = 3, .is_g33 = 1, .is_pineview = 1, .is_mobile = 1,
237 .need_gfx_hws = 1, .has_hotplug = 1,
241 static const struct intel_device_info intel_ironlake_d_info = {
243 .need_gfx_hws = 1, .has_hotplug = 1,
247 static const struct intel_device_info intel_ironlake_m_info = {
248 .gen = 5, .is_mobile = 1,
249 .need_gfx_hws = 1, .has_hotplug = 1,
254 static const struct intel_device_info intel_sandybridge_d_info = {
256 .need_gfx_hws = 1, .has_hotplug = 1,
263 static const struct intel_device_info intel_sandybridge_m_info = {
264 .gen = 6, .is_mobile = 1,
265 .need_gfx_hws = 1, .has_hotplug = 1,
273 static const struct intel_device_info intel_ivybridge_d_info = {
274 .is_ivybridge = 1, .gen = 7,
275 .need_gfx_hws = 1, .has_hotplug = 1,
282 static const struct intel_device_info intel_ivybridge_m_info = {
283 .is_ivybridge = 1, .gen = 7, .is_mobile = 1,
284 .need_gfx_hws = 1, .has_hotplug = 1,
285 .has_fbc = 0, /* FBC is not enabled on Ivybridge mobile yet */
292 static const struct intel_device_info intel_valleyview_m_info = {
293 .gen = 7, .is_mobile = 1,
294 .need_gfx_hws = 1, .has_hotplug = 1,
301 static const struct intel_device_info intel_valleyview_d_info = {
303 .need_gfx_hws = 1, .has_hotplug = 1,
310 static const struct intel_device_info intel_haswell_d_info = {
311 .is_haswell = 1, .gen = 7,
312 .need_gfx_hws = 1, .has_hotplug = 1,
319 static const struct intel_device_info intel_haswell_m_info = {
320 .is_haswell = 1, .gen = 7, .is_mobile = 1,
321 .need_gfx_hws = 1, .has_hotplug = 1,
328 /* drv_PCI_IDs comes from drm_pciids.h, generated from drm_pciids.txt. */
329 static const drm_pci_id_list_t pciidlist[] = {
333 static const struct intel_gfx_device_id {
335 const struct intel_device_info *info;
336 } i915_infolist[] = { /* aka */
337 INTEL_VGA_DEVICE(0x3577, &intel_i830_info), /* I830_M */
338 INTEL_VGA_DEVICE(0x2562, &intel_845g_info), /* 845_G */
339 INTEL_VGA_DEVICE(0x3582, &intel_i85x_info), /* I855_GM */
340 INTEL_VGA_DEVICE(0x358e, &intel_i85x_info),
341 INTEL_VGA_DEVICE(0x2572, &intel_i865g_info), /* I865_G */
342 INTEL_VGA_DEVICE(0x2582, &intel_i915g_info), /* I915_G */
343 INTEL_VGA_DEVICE(0x258a, &intel_i915g_info), /* E7221_G */
344 INTEL_VGA_DEVICE(0x2592, &intel_i915gm_info), /* I915_GM */
345 INTEL_VGA_DEVICE(0x2772, &intel_i945g_info), /* I945_G */
346 INTEL_VGA_DEVICE(0x27a2, &intel_i945gm_info), /* I945_GM */
347 INTEL_VGA_DEVICE(0x27ae, &intel_i945gm_info), /* I945_GME */
348 INTEL_VGA_DEVICE(0x2972, &intel_i965g_info), /* I946_GZ */
349 INTEL_VGA_DEVICE(0x2982, &intel_i965g_info), /* G35_G */
350 INTEL_VGA_DEVICE(0x2992, &intel_i965g_info), /* I965_Q */
351 INTEL_VGA_DEVICE(0x29a2, &intel_i965g_info), /* I965_G */
352 INTEL_VGA_DEVICE(0x29b2, &intel_g33_info), /* Q35_G */
353 INTEL_VGA_DEVICE(0x29c2, &intel_g33_info), /* G33_G */
354 INTEL_VGA_DEVICE(0x29d2, &intel_g33_info), /* Q33_G */
355 INTEL_VGA_DEVICE(0x2a02, &intel_i965gm_info), /* I965_GM */
356 INTEL_VGA_DEVICE(0x2a12, &intel_i965gm_info), /* I965_GME */
357 INTEL_VGA_DEVICE(0x2a42, &intel_gm45_info), /* GM45_G */
358 INTEL_VGA_DEVICE(0x2e02, &intel_g45_info), /* IGD_E_G */
359 INTEL_VGA_DEVICE(0x2e12, &intel_g45_info), /* Q45_G */
360 INTEL_VGA_DEVICE(0x2e22, &intel_g45_info), /* G45_G */
361 INTEL_VGA_DEVICE(0x2e32, &intel_g45_info), /* G41_G */
362 INTEL_VGA_DEVICE(0x2e42, &intel_g45_info), /* B43_G */
363 INTEL_VGA_DEVICE(0x2e92, &intel_g45_info), /* B43_G.1 */
364 INTEL_VGA_DEVICE(0xa001, &intel_pineview_info),
365 INTEL_VGA_DEVICE(0xa011, &intel_pineview_info),
366 INTEL_VGA_DEVICE(0x0042, &intel_ironlake_d_info),
367 INTEL_VGA_DEVICE(0x0046, &intel_ironlake_m_info),
368 INTEL_VGA_DEVICE(0x0102, &intel_sandybridge_d_info),
369 INTEL_VGA_DEVICE(0x0112, &intel_sandybridge_d_info),
370 INTEL_VGA_DEVICE(0x0122, &intel_sandybridge_d_info),
371 INTEL_VGA_DEVICE(0x0106, &intel_sandybridge_m_info),
372 INTEL_VGA_DEVICE(0x0116, &intel_sandybridge_m_info),
373 INTEL_VGA_DEVICE(0x0126, &intel_sandybridge_m_info),
374 INTEL_VGA_DEVICE(0x010A, &intel_sandybridge_d_info),
375 INTEL_VGA_DEVICE(0x0156, &intel_ivybridge_m_info), /* GT1 mobile */
376 INTEL_VGA_DEVICE(0x0166, &intel_ivybridge_m_info), /* GT2 mobile */
377 INTEL_VGA_DEVICE(0x0152, &intel_ivybridge_d_info), /* GT1 desktop */
378 INTEL_VGA_DEVICE(0x0162, &intel_ivybridge_d_info), /* GT2 desktop */
379 INTEL_VGA_DEVICE(0x015a, &intel_ivybridge_d_info), /* GT1 server */
380 INTEL_VGA_DEVICE(0x016a, &intel_ivybridge_d_info), /* GT2 server */
381 INTEL_VGA_DEVICE(0x0402, &intel_haswell_d_info), /* GT1 desktop */
382 INTEL_VGA_DEVICE(0x0412, &intel_haswell_d_info), /* GT2 desktop */
383 INTEL_VGA_DEVICE(0x041e, &intel_haswell_d_info), /* GT2 desktop */
384 INTEL_VGA_DEVICE(0x0422, &intel_haswell_d_info), /* GT2 desktop */
385 INTEL_VGA_DEVICE(0x040a, &intel_haswell_d_info), /* GT1 server */
386 INTEL_VGA_DEVICE(0x041a, &intel_haswell_d_info), /* GT2 server */
387 INTEL_VGA_DEVICE(0x042a, &intel_haswell_d_info), /* GT2 server */
388 INTEL_VGA_DEVICE(0x0406, &intel_haswell_m_info), /* GT1 mobile */
389 INTEL_VGA_DEVICE(0x0416, &intel_haswell_m_info), /* GT2 mobile */
390 INTEL_VGA_DEVICE(0x0426, &intel_haswell_m_info), /* GT2 mobile */
391 INTEL_VGA_DEVICE(0x0C02, &intel_haswell_d_info), /* SDV GT1 desktop */
392 INTEL_VGA_DEVICE(0x0C12, &intel_haswell_d_info), /* SDV GT2 desktop */
393 INTEL_VGA_DEVICE(0x0C22, &intel_haswell_d_info), /* SDV GT2 desktop */
394 INTEL_VGA_DEVICE(0x0C0A, &intel_haswell_d_info), /* SDV GT1 server */
395 INTEL_VGA_DEVICE(0x0C1A, &intel_haswell_d_info), /* SDV GT2 server */
396 INTEL_VGA_DEVICE(0x0C2A, &intel_haswell_d_info), /* SDV GT2 server */
397 INTEL_VGA_DEVICE(0x0C06, &intel_haswell_m_info), /* SDV GT1 mobile */
398 INTEL_VGA_DEVICE(0x0C16, &intel_haswell_m_info), /* SDV GT2 mobile */
399 INTEL_VGA_DEVICE(0x0C26, &intel_haswell_m_info), /* SDV GT2 mobile */
400 INTEL_VGA_DEVICE(0x0A02, &intel_haswell_d_info), /* ULT GT1 desktop */
401 INTEL_VGA_DEVICE(0x0A12, &intel_haswell_d_info), /* ULT GT2 desktop */
402 INTEL_VGA_DEVICE(0x0A22, &intel_haswell_d_info), /* ULT GT2 desktop */
403 INTEL_VGA_DEVICE(0x0A0A, &intel_haswell_d_info), /* ULT GT1 server */
404 INTEL_VGA_DEVICE(0x0A1A, &intel_haswell_d_info), /* ULT GT2 server */
405 INTEL_VGA_DEVICE(0x0A2A, &intel_haswell_d_info), /* ULT GT2 server */
406 INTEL_VGA_DEVICE(0x0A06, &intel_haswell_m_info), /* ULT GT1 mobile */
407 INTEL_VGA_DEVICE(0x0A16, &intel_haswell_m_info), /* ULT GT2 mobile */
408 INTEL_VGA_DEVICE(0x0A26, &intel_haswell_m_info), /* ULT GT2 mobile */
409 INTEL_VGA_DEVICE(0x0D02, &intel_haswell_d_info), /* CRW GT1 desktop */
410 INTEL_VGA_DEVICE(0x0D12, &intel_haswell_d_info), /* CRW GT2 desktop */
411 INTEL_VGA_DEVICE(0x0D22, &intel_haswell_d_info), /* CRW GT2 desktop */
412 INTEL_VGA_DEVICE(0x0D0A, &intel_haswell_d_info), /* CRW GT1 server */
413 INTEL_VGA_DEVICE(0x0D1A, &intel_haswell_d_info), /* CRW GT2 server */
414 INTEL_VGA_DEVICE(0x0D2A, &intel_haswell_d_info), /* CRW GT2 server */
415 INTEL_VGA_DEVICE(0x0D06, &intel_haswell_m_info), /* CRW GT1 mobile */
416 INTEL_VGA_DEVICE(0x0D16, &intel_haswell_m_info), /* CRW GT2 mobile */
417 INTEL_VGA_DEVICE(0x0D26, &intel_haswell_m_info), /* CRW GT2 mobile */
418 INTEL_VGA_DEVICE(0x0f30, &intel_valleyview_m_info),
419 INTEL_VGA_DEVICE(0x0157, &intel_valleyview_m_info),
420 INTEL_VGA_DEVICE(0x0155, &intel_valleyview_d_info),
424 #if defined(CONFIG_DRM_I915_KMS)
425 MODULE_DEVICE_TABLE(pci, pciidlist);
428 void intel_detect_pch(struct drm_device *dev)
430 struct drm_i915_private *dev_priv = dev->dev_private;
434 * The reason to probe ISA bridge instead of Dev31:Fun0 is to
435 * make graphics device passthrough work easy for VMM, that only
436 * need to expose ISA bridge to let driver know the real hardware
437 * underneath. This is a requirement from virtualization team.
439 pch = pci_find_class(PCIC_BRIDGE, PCIS_BRIDGE_ISA);
441 if (pci_get_vendor(pch) == PCI_VENDOR_ID_INTEL) {
443 id = pci_get_device(pch) & INTEL_PCH_DEVICE_ID_MASK;
444 dev_priv->pch_id = id;
446 if (id == INTEL_PCH_IBX_DEVICE_ID_TYPE) {
447 dev_priv->pch_type = PCH_IBX;
448 dev_priv->num_pch_pll = 2;
449 DRM_DEBUG_KMS("Found Ibex Peak PCH\n");
450 WARN_ON(!IS_GEN5(dev));
451 } else if (id == INTEL_PCH_CPT_DEVICE_ID_TYPE) {
452 dev_priv->pch_type = PCH_CPT;
453 dev_priv->num_pch_pll = 2;
454 DRM_DEBUG_KMS("Found CougarPoint PCH\n");
455 WARN_ON(!(IS_GEN6(dev) || IS_IVYBRIDGE(dev)));
456 } else if (id == INTEL_PCH_PPT_DEVICE_ID_TYPE) {
457 /* PantherPoint is CPT compatible */
458 dev_priv->pch_type = PCH_CPT;
459 dev_priv->num_pch_pll = 2;
460 DRM_DEBUG_KMS("Found PatherPoint PCH\n");
461 WARN_ON(!(IS_GEN6(dev) || IS_IVYBRIDGE(dev)));
462 } else if (id == INTEL_PCH_LPT_DEVICE_ID_TYPE) {
463 dev_priv->pch_type = PCH_LPT;
464 dev_priv->num_pch_pll = 0;
465 DRM_DEBUG_KMS("Found LynxPoint PCH\n");
466 WARN_ON(!IS_HASWELL(dev));
467 } else if (id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) {
468 dev_priv->pch_type = PCH_LPT;
469 dev_priv->num_pch_pll = 0;
470 DRM_DEBUG_KMS("Found LynxPoint LP PCH\n");
471 WARN_ON(!IS_HASWELL(dev));
473 BUG_ON(dev_priv->num_pch_pll > I915_NUM_PLLS);
478 bool i915_semaphore_is_enabled(struct drm_device *dev)
480 if (INTEL_INFO(dev)->gen < 6)
483 if (i915_semaphores >= 0)
484 return i915_semaphores;
486 #ifdef CONFIG_INTEL_IOMMU
487 /* Enable semaphores on SNB when IO remapping is off */
488 if (INTEL_INFO(dev)->gen == 6 && intel_iommu_gfx_mapped)
495 static int i915_drm_freeze(struct drm_device *dev)
497 struct drm_i915_private *dev_priv = dev->dev_private;
499 drm_kms_helper_poll_disable(dev);
502 pci_save_state(dev->pdev);
505 /* If KMS is active, we do the leavevt stuff here */
506 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
507 int error = i915_gem_idle(dev);
510 "GEM idle failed, resume might fail\n");
514 taskqueue_cancel_timeout(dev_priv->wq,
515 &dev_priv->rps.delayed_resume_work, NULL);
517 intel_modeset_disable(dev);
519 drm_irq_uninstall(dev);
522 i915_save_state(dev);
524 intel_opregion_fini(dev);
526 /* Modeset on resume, not lid events */
527 dev_priv->modeset_on_lid = 0;
530 intel_fbdev_set_suspend(dev, 1);
536 int i915_suspend(struct drm_device *dev, pm_message_t state)
540 if (!dev || !dev->dev_private) {
541 DRM_ERROR("dev: %p\n", dev);
542 DRM_ERROR("DRM not initialized, aborting suspend.\n");
546 if (state.event == PM_EVENT_PRETHAW)
550 if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
553 error = i915_drm_freeze(dev);
557 if (state.event == PM_EVENT_SUSPEND) {
559 /* Shut down the device */
560 pci_disable_device(dev->pdev);
561 pci_set_power_state(dev->pdev, PCI_D3hot);
568 void intel_console_resume(void *arg, int pending)
570 struct drm_i915_private *dev_priv =
572 struct drm_device *dev = dev_priv->dev;
575 intel_fbdev_set_suspend(dev, 0);
579 static int __i915_drm_thaw(struct drm_device *dev)
581 struct drm_i915_private *dev_priv = dev->dev_private;
584 i915_restore_state(dev);
585 intel_opregion_setup(dev);
587 /* KMS EnterVT equivalent */
588 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
589 intel_init_pch_refclk(dev);
592 dev_priv->mm.suspended = 0;
594 error = i915_gem_init_hw(dev);
597 intel_modeset_init_hw(dev);
598 intel_modeset_setup_hw_state(dev, false);
599 drm_irq_install(dev);
602 intel_opregion_init(dev);
604 dev_priv->modeset_on_lid = 0;
607 * The console lock can be pretty contented on resume due
608 * to all the printk activity. Try to keep it out of the hot
609 * path of resume if possible.
611 if (console_trylock()) {
612 intel_fbdev_set_suspend(dev, 0);
615 taskqueue_enqueue(dev_priv->wq,
616 &dev_priv->console_resume_work);
623 static int i915_drm_thaw(struct drm_device *dev)
629 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
631 i915_gem_restore_gtt_mappings(dev);
635 __i915_drm_thaw(dev);
641 int i915_resume(struct drm_device *dev)
643 struct drm_i915_private *dev_priv = dev->dev_private;
646 if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
650 if (pci_enable_device(dev->pdev))
653 pci_set_master(dev->pdev);
659 * Platforms with opregion should have sane BIOS, older ones (gen3 and
660 * earlier) need this since the BIOS might clear all our scratch PTEs.
662 if (drm_core_check_feature(dev, DRIVER_MODESET) &&
663 !dev_priv->opregion.header) {
665 i915_gem_restore_gtt_mappings(dev);
669 ret = __i915_drm_thaw(dev);
673 drm_kms_helper_poll_enable(dev);
677 static int i8xx_do_reset(struct drm_device *dev)
679 struct drm_i915_private *dev_priv = dev->dev_private;
689 I915_WRITE(D_STATE, I915_READ(D_STATE) | DSTATE_GFX_RESET_I830);
690 POSTING_READ(D_STATE);
692 if (IS_I830(dev) || IS_845G(dev)) {
693 I915_WRITE(DEBUG_RESET_I830,
694 DEBUG_RESET_DISPLAY |
697 POSTING_READ(DEBUG_RESET_I830);
698 pause("i8xxrst1", onems);
700 I915_WRITE(DEBUG_RESET_I830, 0);
701 POSTING_READ(DEBUG_RESET_I830);
704 pause("i8xxrst2", onems);
706 I915_WRITE(D_STATE, I915_READ(D_STATE) & ~DSTATE_GFX_RESET_I830);
707 POSTING_READ(D_STATE);
712 static int i965_reset_complete(struct drm_device *dev)
715 pci_read_config_byte(dev->dev, I965_GDRST, &gdrst);
716 return (gdrst & GRDOM_RESET_ENABLE) == 0;
719 static int i965_do_reset(struct drm_device *dev)
725 * Set the domains we want to reset (GRDOM/bits 2 and 3) as
726 * well as the reset bit (GR/bit 0). Setting the GR bit
727 * triggers the reset; when done, the hardware will clear it.
729 pci_read_config_byte(dev->dev, I965_GDRST, &gdrst);
730 pci_write_config_byte(dev->dev, I965_GDRST,
731 gdrst | GRDOM_RENDER |
733 ret = wait_for(i965_reset_complete(dev), 500);
737 /* We can't reset render&media without also resetting display ... */
738 pci_read_config_byte(dev->dev, I965_GDRST, &gdrst);
739 pci_write_config_byte(dev->dev, I965_GDRST,
740 gdrst | GRDOM_MEDIA |
743 return wait_for(i965_reset_complete(dev), 500);
746 static int ironlake_do_reset(struct drm_device *dev)
748 struct drm_i915_private *dev_priv = dev->dev_private;
752 gdrst = I915_READ(MCHBAR_MIRROR_BASE + ILK_GDSR);
753 I915_WRITE(MCHBAR_MIRROR_BASE + ILK_GDSR,
754 gdrst | GRDOM_RENDER | GRDOM_RESET_ENABLE);
755 ret = wait_for(I915_READ(MCHBAR_MIRROR_BASE + ILK_GDSR) & 0x1, 500);
759 /* We can't reset render&media without also resetting display ... */
760 gdrst = I915_READ(MCHBAR_MIRROR_BASE + ILK_GDSR);
761 I915_WRITE(MCHBAR_MIRROR_BASE + ILK_GDSR,
762 gdrst | GRDOM_MEDIA | GRDOM_RESET_ENABLE);
763 return wait_for(I915_READ(MCHBAR_MIRROR_BASE + ILK_GDSR) & 0x1, 500);
766 static int gen6_do_reset(struct drm_device *dev)
768 struct drm_i915_private *dev_priv = dev->dev_private;
771 /* Hold gt_lock across reset to prevent any register access
772 * with forcewake not set correctly
774 mtx_lock(&dev_priv->gt_lock);
778 /* GEN6_GDRST is not in the gt power well, no need to check
779 * for fifo space for the write or forcewake the chip for
782 I915_WRITE_NOTRACE(GEN6_GDRST, GEN6_GRDOM_FULL);
784 /* Spin waiting for the device to ack the reset request */
786 * NOTE Linux<->FreeBSD: We use _intel_wait_for() instead of
787 * wait_for(), because we want to set the 4th argument to 0.
788 * This allows us to use a struct mtx for dev_priv->gt_lock and
791 ret = _intel_wait_for(dev,
792 (I915_READ_NOTRACE(GEN6_GDRST) & GEN6_GRDOM_FULL) == 0,
795 /* If reset with a user forcewake, try to restore, otherwise turn it off */
796 if (dev_priv->forcewake_count)
797 dev_priv->gt.force_wake_get(dev_priv);
799 dev_priv->gt.force_wake_put(dev_priv);
801 /* Restore fifo count */
802 dev_priv->gt_fifo_count = I915_READ_NOTRACE(GT_FIFO_FREE_ENTRIES);
804 mtx_unlock(&dev_priv->gt_lock);
808 int intel_gpu_reset(struct drm_device *dev)
810 struct drm_i915_private *dev_priv = dev->dev_private;
813 switch (INTEL_INFO(dev)->gen) {
816 ret = gen6_do_reset(dev);
819 ret = ironlake_do_reset(dev);
822 ret = i965_do_reset(dev);
825 ret = i8xx_do_reset(dev);
829 /* Also reset the gpu hangman. */
830 if (dev_priv->stop_rings) {
831 DRM_DEBUG("Simulated gpu hang, resetting stop_rings\n");
832 dev_priv->stop_rings = 0;
833 if (ret == -ENODEV) {
834 DRM_ERROR("Reset not implemented, but ignoring "
835 "error for simulated gpu hangs\n");
844 * i915_reset - reset chip after a hang
845 * @dev: drm device to reset
847 * Reset the chip. Useful if a hang is detected. Returns zero on successful
848 * reset or otherwise an error code.
850 * Procedure is fairly simple:
851 * - reset the chip using the reset reg
852 * - re-init context state
853 * - re-init hardware status page
854 * - re-init ring buffer
855 * - re-init interrupt state
858 int i915_reset(struct drm_device *dev)
860 drm_i915_private_t *dev_priv = dev->dev_private;
871 if (get_seconds() - dev_priv->last_gpu_reset < 5)
872 DRM_ERROR("GPU hanging too fast, declaring wedged!\n");
874 ret = intel_gpu_reset(dev);
876 dev_priv->last_gpu_reset = get_seconds();
878 DRM_ERROR("Failed to reset chip.\n");
883 /* Ok, now get things going again... */
886 * Everything depends on having the GTT running, so we need to start
887 * there. Fortunately we don't need to do this unless we reset the
888 * chip at a PCI level.
890 * Next we need to restore the context, but we don't use those
893 * Ring buffer needs to be re-initialized in the KMS case, or if X
894 * was running at the time of the reset (i.e. we weren't VT
897 if (drm_core_check_feature(dev, DRIVER_MODESET) ||
898 !dev_priv->mm.suspended) {
899 struct intel_ring_buffer *ring;
902 dev_priv->mm.suspended = 0;
904 i915_gem_init_swizzling(dev);
906 for_each_ring(ring, dev_priv, i)
909 i915_gem_context_init(dev);
910 i915_gem_init_ppgtt(dev);
913 * It would make sense to re-init all the other hw state, at
914 * least the rps/rc6/emon init done within modeset_init_hw. For
915 * some unknown reason, this blows up my ilk, so don't.
920 drm_irq_uninstall(dev);
921 drm_irq_install(dev);
929 const struct intel_device_info *
930 i915_get_device_id(int device)
932 const struct intel_gfx_device_id *did;
934 for (did = &i915_infolist[0]; did->device != 0; did++) {
935 if (did->device != device)
942 static int i915_probe(device_t kdev)
944 const struct intel_device_info *intel_info =
945 i915_get_device_id(pci_get_device(kdev));
947 if (intel_info == NULL)
949 if (intel_info->is_valleyview)
950 if(!i915_preliminary_hw_support) {
951 DRM_ERROR("Preliminary hardware support disabled\n");
955 /* Only bind to function 0 of the device. Early generations
956 * used function 1 as a placeholder for multi-head. This causes
957 * us confusion instead, especially on the systems where both
958 * functions have the same PCI-ID!
960 if (pci_get_function(kdev))
963 /* We've managed to ship a kms-enabled ddx that shipped with an XvMC
964 * implementation for gen3 (and only gen3) that used legacy drm maps
965 * (gasp!) to share buffers between X and the client. Hence we need to
966 * keep around the fake agp stuff for gen3, even when kms is enabled. */
967 if (intel_info->gen != 3) {
968 driver.driver_features &=
969 ~(DRIVER_USE_AGP | DRIVER_REQUIRE_AGP);
970 } else if (!intel_agp_enabled) {
971 DRM_ERROR("drm/i915 can't work without intel_agp module!\n");
975 return -drm_probe_helper(kdev, pciidlist);
980 i915_pci_remove(struct pci_dev *pdev)
982 struct drm_device *dev = pci_get_drvdata(pdev);
987 static int i915_pm_suspend(struct device *dev)
989 struct pci_dev *pdev = to_pci_dev(dev);
990 struct drm_device *drm_dev = pci_get_drvdata(pdev);
993 if (!drm_dev || !drm_dev->dev_private) {
994 dev_err(dev, "DRM not initialized, aborting suspend.\n");
998 if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF)
1001 error = i915_drm_freeze(drm_dev);
1005 pci_disable_device(pdev);
1006 pci_set_power_state(pdev, PCI_D3hot);
1011 static int i915_pm_resume(struct device *dev)
1013 struct pci_dev *pdev = to_pci_dev(dev);
1014 struct drm_device *drm_dev = pci_get_drvdata(pdev);
1016 return i915_resume(drm_dev);
1019 static int i915_pm_freeze(struct device *dev)
1021 struct pci_dev *pdev = to_pci_dev(dev);
1022 struct drm_device *drm_dev = pci_get_drvdata(pdev);
1024 if (!drm_dev || !drm_dev->dev_private) {
1025 dev_err(dev, "DRM not initialized, aborting suspend.\n");
1029 return i915_drm_freeze(drm_dev);
1032 static int i915_pm_thaw(struct device *dev)
1034 struct pci_dev *pdev = to_pci_dev(dev);
1035 struct drm_device *drm_dev = pci_get_drvdata(pdev);
1037 return i915_drm_thaw(drm_dev);
1040 static int i915_pm_poweroff(struct device *dev)
1042 struct pci_dev *pdev = to_pci_dev(dev);
1043 struct drm_device *drm_dev = pci_get_drvdata(pdev);
1045 return i915_drm_freeze(drm_dev);
1048 static const struct dev_pm_ops i915_pm_ops = {
1049 .suspend = i915_pm_suspend,
1050 .resume = i915_pm_resume,
1051 .freeze = i915_pm_freeze,
1052 .thaw = i915_pm_thaw,
1053 .poweroff = i915_pm_poweroff,
1054 .restore = i915_pm_resume,
1057 static const struct vm_operations_struct i915_gem_vm_ops = {
1058 .fault = i915_gem_fault,
1059 .open = drm_gem_vm_open,
1060 .close = drm_gem_vm_close,
1063 static const struct file_operations i915_driver_fops = {
1064 .owner = THIS_MODULE,
1066 .release = drm_release,
1067 .unlocked_ioctl = drm_ioctl,
1068 .mmap = drm_gem_mmap,
1070 .fasync = drm_fasync,
1072 #ifdef CONFIG_COMPAT
1073 .compat_ioctl = i915_compat_ioctl,
1075 .llseek = noop_llseek,
1077 #endif /* __linux__ */
1079 #ifdef COMPAT_FREEBSD32
1080 extern struct drm_ioctl_desc i915_compat_ioctls[];
1081 extern int i915_compat_ioctls_nr;
1084 static struct drm_driver driver = {
1085 /* Don't use MTRRs here; the Xserver or userspace app should
1086 * deal with them for Intel hardware.
1089 DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | /* DRIVER_USE_MTRR |*/
1090 DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_GEM | DRIVER_PRIME,
1091 .load = i915_driver_load,
1092 .unload = i915_driver_unload,
1093 .open = i915_driver_open,
1094 .lastclose = i915_driver_lastclose,
1095 .preclose = i915_driver_preclose,
1096 .postclose = i915_driver_postclose,
1098 /* Used in place of i915_pm_ops for non-DRIVER_MODESET */
1099 .suspend = i915_suspend,
1100 .resume = i915_resume,
1102 .device_is_agp = i915_driver_device_is_agp,
1103 .master_create = i915_master_create,
1104 .master_destroy = i915_master_destroy,
1105 #if defined(CONFIG_DEBUG_FS)
1106 .debugfs_init = i915_debugfs_init,
1107 .debugfs_cleanup = i915_debugfs_cleanup,
1109 .gem_init_object = i915_gem_init_object,
1110 .gem_free_object = i915_gem_free_object,
1111 #if defined(__linux__)
1112 .gem_vm_ops = &i915_gem_vm_ops,
1113 #elif defined(__FreeBSD__)
1114 .gem_pager_ops = &i915_gem_pager_ops,
1118 .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
1119 .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
1120 .gem_prime_export = i915_gem_prime_export,
1121 .gem_prime_import = i915_gem_prime_import,
1122 #endif /* FREEBSD_WIP */
1124 .dumb_create = i915_gem_dumb_create,
1125 .dumb_map_offset = i915_gem_mmap_gtt,
1126 .dumb_destroy = i915_gem_dumb_destroy,
1127 .ioctls = i915_ioctls,
1128 #ifdef COMPAT_FREEBSD32
1129 .compat_ioctls = i915_compat_ioctls,
1130 .num_compat_ioctls = &i915_compat_ioctls_nr,
1133 .fops = &i915_driver_fops,
1136 .sysctl_init = i915_sysctl_init,
1137 .sysctl_cleanup = i915_sysctl_cleanup,
1139 .name = DRIVER_NAME,
1140 .desc = DRIVER_DESC,
1141 .date = DRIVER_DATE,
1142 .major = DRIVER_MAJOR,
1143 .minor = DRIVER_MINOR,
1144 .patchlevel = DRIVER_PATCHLEVEL,
1148 static struct pci_driver i915_pci_driver = {
1149 .name = DRIVER_NAME,
1150 .id_table = pciidlist,
1151 .probe = i915_pci_probe,
1152 .remove = i915_pci_remove,
1153 .driver.pm = &i915_pm_ops,
1157 static int __init i915_attach(device_t kdev)
1159 driver.num_ioctls = i915_max_ioctl;
1162 * If CONFIG_DRM_I915_KMS is set, default to KMS unless
1163 * explicitly disabled with the module pararmeter.
1165 * Otherwise, just follow the parameter (defaulting to off).
1167 * Allow optional vga_text_mode_force boot option to override
1168 * the default behavior.
1170 #if defined(CONFIG_DRM_I915_KMS)
1171 if (i915_modeset != 0)
1172 driver.driver_features |= DRIVER_MODESET;
1174 if (i915_modeset == 1)
1175 driver.driver_features |= DRIVER_MODESET;
1177 #ifdef CONFIG_VGA_CONSOLE
1178 if (vgacon_text_force() && i915_modeset == -1)
1179 driver.driver_features &= ~DRIVER_MODESET;
1182 if (!(driver.driver_features & DRIVER_MODESET))
1183 driver.get_vblank_timestamp = NULL;
1185 return (-drm_attach_helper(kdev, pciidlist, &driver));
1188 static struct fb_info *
1189 i915_fb_helper_getinfo(device_t kdev)
1191 struct intel_fbdev *ifbdev;
1192 drm_i915_private_t *dev_priv;
1193 struct drm_device *dev;
1194 struct fb_info *info;
1196 dev = device_get_softc(kdev);
1197 dev_priv = dev->dev_private;
1198 ifbdev = dev_priv->fbdev;
1202 info = ifbdev->helper.fbdev;
1207 static device_method_t i915_methods[] = {
1208 /* Device interface */
1209 DEVMETHOD(device_probe, i915_probe),
1210 DEVMETHOD(device_attach, i915_attach),
1211 DEVMETHOD(device_suspend, drm_generic_suspend),
1212 DEVMETHOD(device_resume, drm_generic_resume),
1213 DEVMETHOD(device_detach, drm_generic_detach),
1215 /* Framebuffer service methods */
1216 DEVMETHOD(fb_getinfo, i915_fb_helper_getinfo),
1221 static driver_t i915_driver = {
1224 sizeof(struct drm_device)
1227 MODULE_AUTHOR(DRIVER_AUTHOR);
1228 MODULE_DESCRIPTION(DRIVER_DESC);
1229 MODULE_LICENSE("GPL and additional rights");
1231 extern devclass_t drm_devclass;
1232 DRIVER_MODULE_ORDERED(i915kms, vgapci, i915_driver, drm_devclass, 0, 0,
1234 MODULE_DEPEND(i915kms, drmn, 1, 1, 1);
1235 MODULE_DEPEND(i915kms, agp, 1, 1, 1);
1236 MODULE_DEPEND(i915kms, iicbus, 1, 1, 1);
1237 MODULE_DEPEND(i915kms, iic, 1, 1, 1);
1238 MODULE_DEPEND(i915kms, iicbb, 1, 1, 1);
1239 MODULE_PNP_INFO("U32:vendor;U32:device;P:#;D:human", vgapci, i915, pciidlist,
1240 sizeof(pciidlist[0]), nitems(pciidlist));
1242 /* We give fast paths for the really cool registers */
1243 #define NEEDS_FORCE_WAKE(dev_priv, reg) \
1244 ((HAS_FORCE_WAKE((dev_priv)->dev)) && \
1245 ((reg) < 0x40000) && \
1246 ((reg) != FORCEWAKE))
1248 static bool IS_DISPLAYREG(u32 reg)
1251 * This should make it easier to transition modules over to the
1252 * new register block scheme, since we can do it incrementally.
1254 if (reg >= VLV_DISPLAY_BASE)
1257 if (reg >= RENDER_RING_BASE &&
1258 reg < RENDER_RING_BASE + 0xff)
1260 if (reg >= GEN6_BSD_RING_BASE &&
1261 reg < GEN6_BSD_RING_BASE + 0xff)
1263 if (reg >= BLT_RING_BASE &&
1264 reg < BLT_RING_BASE + 0xff)
1267 if (reg == PGTBL_ER)
1270 if (reg >= IPEIR_I965 &&
1277 if (reg == GFX_MODE_GEN7)
1280 if (reg == RENDER_HWS_PGA_GEN7 ||
1281 reg == BSD_HWS_PGA_GEN7 ||
1282 reg == BLT_HWS_PGA_GEN7)
1285 if (reg == GEN6_BSD_SLEEP_PSMI_CONTROL ||
1286 reg == GEN6_BSD_RNCID)
1289 if (reg == GEN6_BLITTER_ECOSKPD)
1292 if (reg >= 0x4000c &&
1296 if (reg >= 0x4f000 &&
1300 if (reg >= 0x4f100 &&
1304 if (reg >= VLV_MASTER_IER &&
1308 if (reg >= FENCE_REG_SANDYBRIDGE_0 &&
1309 reg < (FENCE_REG_SANDYBRIDGE_0 + (16*8)))
1312 if (reg >= VLV_IIR_RW &&
1316 if (reg == FORCEWAKE_VLV ||
1317 reg == FORCEWAKE_ACK_VLV)
1320 if (reg == GEN6_GDRST)
1326 case GEN7_COMMON_SLICE_CHICKEN1:
1327 case GEN7_L3CNTLREG1:
1328 case GEN7_L3_CHICKEN_MODE_REGISTER:
1329 case GEN7_ROW_CHICKEN2:
1330 case GEN7_L3SQCREG4:
1331 case GEN7_SQ_CHICKEN_MBCUNIT_CONFIG:
1332 case GEN7_HALF_SLICE_CHICKEN1:
1344 ilk_dummy_write(struct drm_i915_private *dev_priv)
1346 /* WaIssueDummyWriteToWakeupFromRC6: Issue a dummy write to wake up the
1347 * chip from rc6 before touching it for real. MI_MODE is masked, hence
1348 * harmless to write 0 into. */
1349 I915_WRITE_NOTRACE(MI_MODE, 0);
1352 #define __i915_read(x, y) \
1353 u##x i915_read##x(struct drm_i915_private *dev_priv, u32 reg) { \
1355 if (IS_GEN5(dev_priv->dev)) \
1356 ilk_dummy_write(dev_priv); \
1357 if (NEEDS_FORCE_WAKE((dev_priv), (reg))) { \
1358 mtx_lock(&dev_priv->gt_lock); \
1359 if (dev_priv->forcewake_count == 0) \
1360 dev_priv->gt.force_wake_get(dev_priv); \
1361 val = DRM_READ##x(dev_priv->mmio_map, reg); \
1362 if (dev_priv->forcewake_count == 0) \
1363 dev_priv->gt.force_wake_put(dev_priv); \
1364 mtx_unlock(&dev_priv->gt_lock); \
1365 } else if (IS_VALLEYVIEW(dev_priv->dev) && IS_DISPLAYREG(reg)) { \
1366 val = DRM_READ##x(dev_priv->mmio_map, reg + 0x180000); \
1368 val = DRM_READ##x(dev_priv->mmio_map, reg); \
1370 trace_i915_reg_rw(false, reg, val, sizeof(val)); \
1380 #define __i915_write(x, y) \
1381 void i915_write##x(struct drm_i915_private *dev_priv, u32 reg, u##x val) { \
1382 u32 __fifo_ret = 0; \
1383 trace_i915_reg_rw(true, reg, val, sizeof(val)); \
1384 if (NEEDS_FORCE_WAKE((dev_priv), (reg))) { \
1385 __fifo_ret = __gen6_gt_wait_for_fifo(dev_priv); \
1387 if (IS_GEN5(dev_priv->dev)) \
1388 ilk_dummy_write(dev_priv); \
1389 if (IS_HASWELL(dev_priv->dev) && (I915_READ_NOTRACE(GEN7_ERR_INT) & ERR_INT_MMIO_UNCLAIMED)) { \
1390 DRM_ERROR("Unknown unclaimed register before writing to %x\n", reg); \
1391 I915_WRITE_NOTRACE(GEN7_ERR_INT, ERR_INT_MMIO_UNCLAIMED); \
1393 if (IS_VALLEYVIEW(dev_priv->dev) && IS_DISPLAYREG(reg)) { \
1394 DRM_WRITE##x(dev_priv->mmio_map, reg + 0x180000, val); \
1396 DRM_WRITE##x(dev_priv->mmio_map, reg, val); \
1398 if (unlikely(__fifo_ret)) { \
1399 gen6_gt_check_fifodbg(dev_priv); \
1401 if (IS_HASWELL(dev_priv->dev) && (I915_READ_NOTRACE(GEN7_ERR_INT) & ERR_INT_MMIO_UNCLAIMED)) { \
1402 DRM_ERROR("Unclaimed write to %x\n", reg); \
1403 DRM_WRITE32(dev_priv->mmio_map, GEN7_ERR_INT, ERR_INT_MMIO_UNCLAIMED); \
1412 static const struct register_whitelist {
1415 uint32_t gen_bitmask; /* support gens, 0x10 for 4, 0x30 for 4 and 5, etc. */
1417 { RING_TIMESTAMP(RENDER_RING_BASE), 8, 0xF0 },
1420 int i915_reg_read_ioctl(struct drm_device *dev,
1421 void *data, struct drm_file *file)
1423 struct drm_i915_private *dev_priv = dev->dev_private;
1424 struct drm_i915_reg_read *reg = data;
1425 struct register_whitelist const *entry = whitelist;
1428 for (i = 0; i < ARRAY_SIZE(whitelist); i++, entry++) {
1429 if (entry->offset == reg->offset &&
1430 (1 << INTEL_INFO(dev)->gen & entry->gen_bitmask))
1434 if (i == ARRAY_SIZE(whitelist))
1437 switch (entry->size) {
1439 reg->val = I915_READ64(reg->offset);
1442 reg->val = I915_READ(reg->offset);
1445 reg->val = I915_READ16(reg->offset);
1448 reg->val = I915_READ8(reg->offset);