i915_drv.c 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321
  1. /* i915_drv.c -- i830,i845,i855,i865,i915 driver -*- linux-c -*-
  2. */
  3. /*
  4. *
  5. * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
  6. * All Rights Reserved.
  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. *
  28. */
  29. #include <linux/device.h>
  30. #include <drm/drmP.h>
  31. #include <drm/i915_drm.h>
  32. #include "i915_drv.h"
  33. #include "i915_trace.h"
  34. #include "intel_drv.h"
  35. #include <linux/console.h>
  36. #include <linux/module.h>
  37. #include <drm/drm_crtc_helper.h>
  38. static int i915_modeset __read_mostly = -1;
  39. module_param_named(modeset, i915_modeset, int, 0400);
  40. MODULE_PARM_DESC(modeset,
  41. "Use kernel modesetting [KMS] (0=DRM_I915_KMS from .config, "
  42. "1=on, -1=force vga console preference [default])");
  43. unsigned int i915_fbpercrtc __always_unused = 0;
  44. module_param_named(fbpercrtc, i915_fbpercrtc, int, 0400);
  45. int i915_panel_ignore_lid __read_mostly = 1;
  46. module_param_named(panel_ignore_lid, i915_panel_ignore_lid, int, 0600);
  47. MODULE_PARM_DESC(panel_ignore_lid,
  48. "Override lid status (0=autodetect, 1=autodetect disabled [default], "
  49. "-1=force lid closed, -2=force lid open)");
  50. unsigned int i915_powersave __read_mostly = 1;
  51. module_param_named(powersave, i915_powersave, int, 0600);
  52. MODULE_PARM_DESC(powersave,
  53. "Enable powersavings, fbc, downclocking, etc. (default: true)");
  54. int i915_semaphores __read_mostly = -1;
  55. module_param_named(semaphores, i915_semaphores, int, 0600);
  56. MODULE_PARM_DESC(semaphores,
  57. "Use semaphores for inter-ring sync (default: -1 (use per-chip defaults))");
  58. int i915_enable_rc6 __read_mostly = -1;
  59. module_param_named(i915_enable_rc6, i915_enable_rc6, int, 0400);
  60. MODULE_PARM_DESC(i915_enable_rc6,
  61. "Enable power-saving render C-state 6. "
  62. "Different stages can be selected via bitmask values "
  63. "(0 = disable; 1 = enable rc6; 2 = enable deep rc6; 4 = enable deepest rc6). "
  64. "For example, 3 would enable rc6 and deep rc6, and 7 would enable everything. "
  65. "default: -1 (use per-chip default)");
  66. int i915_enable_fbc __read_mostly = -1;
  67. module_param_named(i915_enable_fbc, i915_enable_fbc, int, 0600);
  68. MODULE_PARM_DESC(i915_enable_fbc,
  69. "Enable frame buffer compression for power savings "
  70. "(default: -1 (use per-chip default))");
  71. unsigned int i915_lvds_downclock __read_mostly = 0;
  72. module_param_named(lvds_downclock, i915_lvds_downclock, int, 0400);
  73. MODULE_PARM_DESC(lvds_downclock,
  74. "Use panel (LVDS/eDP) downclocking for power savings "
  75. "(default: false)");
  76. int i915_lvds_channel_mode __read_mostly;
  77. module_param_named(lvds_channel_mode, i915_lvds_channel_mode, int, 0600);
  78. MODULE_PARM_DESC(lvds_channel_mode,
  79. "Specify LVDS channel mode "
  80. "(0=probe BIOS [default], 1=single-channel, 2=dual-channel)");
  81. int i915_panel_use_ssc __read_mostly = -1;
  82. module_param_named(lvds_use_ssc, i915_panel_use_ssc, int, 0600);
  83. MODULE_PARM_DESC(lvds_use_ssc,
  84. "Use Spread Spectrum Clock with panels [LVDS/eDP] "
  85. "(default: auto from VBT)");
  86. int i915_vbt_sdvo_panel_type __read_mostly = -1;
  87. module_param_named(vbt_sdvo_panel_type, i915_vbt_sdvo_panel_type, int, 0600);
  88. MODULE_PARM_DESC(vbt_sdvo_panel_type,
  89. "Override/Ignore selection of SDVO panel mode in the VBT "
  90. "(-2=ignore, -1=auto [default], index in VBT BIOS table)");
  91. static bool i915_try_reset __read_mostly = true;
  92. module_param_named(reset, i915_try_reset, bool, 0600);
  93. MODULE_PARM_DESC(reset, "Attempt GPU resets (default: true)");
  94. bool i915_enable_hangcheck __read_mostly = true;
  95. module_param_named(enable_hangcheck, i915_enable_hangcheck, bool, 0644);
  96. MODULE_PARM_DESC(enable_hangcheck,
  97. "Periodically check GPU activity for detecting hangs. "
  98. "WARNING: Disabling this can cause system wide hangs. "
  99. "(default: true)");
  100. int i915_enable_ppgtt __read_mostly = -1;
  101. module_param_named(i915_enable_ppgtt, i915_enable_ppgtt, int, 0600);
  102. MODULE_PARM_DESC(i915_enable_ppgtt,
  103. "Enable PPGTT (default: true)");
  104. unsigned int i915_preliminary_hw_support __read_mostly = 0;
  105. module_param_named(preliminary_hw_support, i915_preliminary_hw_support, int, 0600);
  106. MODULE_PARM_DESC(preliminary_hw_support,
  107. "Enable preliminary hardware support. (default: false)");
  108. int i915_disable_power_well __read_mostly = 0;
  109. module_param_named(disable_power_well, i915_disable_power_well, int, 0600);
  110. MODULE_PARM_DESC(disable_power_well,
  111. "Disable the power well when possible (default: false)");
  112. static struct drm_driver driver;
  113. extern int intel_agp_enabled;
  114. #define INTEL_VGA_DEVICE(id, info) { \
  115. .class = PCI_BASE_CLASS_DISPLAY << 16, \
  116. .class_mask = 0xff0000, \
  117. .vendor = 0x8086, \
  118. .device = id, \
  119. .subvendor = PCI_ANY_ID, \
  120. .subdevice = PCI_ANY_ID, \
  121. .driver_data = (unsigned long) info }
  122. #define INTEL_QUANTA_VGA_DEVICE(info) { \
  123. .class = PCI_BASE_CLASS_DISPLAY << 16, \
  124. .class_mask = 0xff0000, \
  125. .vendor = 0x8086, \
  126. .device = 0x16a, \
  127. .subvendor = 0x152d, \
  128. .subdevice = 0x8990, \
  129. .driver_data = (unsigned long) info }
  130. static const struct intel_device_info intel_i830_info = {
  131. .gen = 2, .is_mobile = 1, .cursor_needs_physical = 1, .num_pipes = 2,
  132. .has_overlay = 1, .overlay_needs_physical = 1,
  133. };
  134. static const struct intel_device_info intel_845g_info = {
  135. .gen = 2, .num_pipes = 1,
  136. .has_overlay = 1, .overlay_needs_physical = 1,
  137. };
  138. static const struct intel_device_info intel_i85x_info = {
  139. .gen = 2, .is_i85x = 1, .is_mobile = 1, .num_pipes = 2,
  140. .cursor_needs_physical = 1,
  141. .has_overlay = 1, .overlay_needs_physical = 1,
  142. };
  143. static const struct intel_device_info intel_i865g_info = {
  144. .gen = 2, .num_pipes = 1,
  145. .has_overlay = 1, .overlay_needs_physical = 1,
  146. };
  147. static const struct intel_device_info intel_i915g_info = {
  148. .gen = 3, .is_i915g = 1, .cursor_needs_physical = 1, .num_pipes = 2,
  149. .has_overlay = 1, .overlay_needs_physical = 1,
  150. };
  151. static const struct intel_device_info intel_i915gm_info = {
  152. .gen = 3, .is_mobile = 1, .num_pipes = 2,
  153. .cursor_needs_physical = 1,
  154. .has_overlay = 1, .overlay_needs_physical = 1,
  155. .supports_tv = 1,
  156. };
  157. static const struct intel_device_info intel_i945g_info = {
  158. .gen = 3, .has_hotplug = 1, .cursor_needs_physical = 1, .num_pipes = 2,
  159. .has_overlay = 1, .overlay_needs_physical = 1,
  160. };
  161. static const struct intel_device_info intel_i945gm_info = {
  162. .gen = 3, .is_i945gm = 1, .is_mobile = 1, .num_pipes = 2,
  163. .has_hotplug = 1, .cursor_needs_physical = 1,
  164. .has_overlay = 1, .overlay_needs_physical = 1,
  165. .supports_tv = 1,
  166. };
  167. static const struct intel_device_info intel_i965g_info = {
  168. .gen = 4, .is_broadwater = 1, .num_pipes = 2,
  169. .has_hotplug = 1,
  170. .has_overlay = 1,
  171. };
  172. static const struct intel_device_info intel_i965gm_info = {
  173. .gen = 4, .is_crestline = 1, .num_pipes = 2,
  174. .is_mobile = 1, .has_fbc = 1, .has_hotplug = 1,
  175. .has_overlay = 1,
  176. .supports_tv = 1,
  177. };
  178. static const struct intel_device_info intel_g33_info = {
  179. .gen = 3, .is_g33 = 1, .num_pipes = 2,
  180. .need_gfx_hws = 1, .has_hotplug = 1,
  181. .has_overlay = 1,
  182. };
  183. static const struct intel_device_info intel_g45_info = {
  184. .gen = 4, .is_g4x = 1, .need_gfx_hws = 1, .num_pipes = 2,
  185. .has_pipe_cxsr = 1, .has_hotplug = 1,
  186. .has_bsd_ring = 1,
  187. };
  188. static const struct intel_device_info intel_gm45_info = {
  189. .gen = 4, .is_g4x = 1, .num_pipes = 2,
  190. .is_mobile = 1, .need_gfx_hws = 1, .has_fbc = 1,
  191. .has_pipe_cxsr = 1, .has_hotplug = 1,
  192. .supports_tv = 1,
  193. .has_bsd_ring = 1,
  194. };
  195. static const struct intel_device_info intel_pineview_info = {
  196. .gen = 3, .is_g33 = 1, .is_pineview = 1, .is_mobile = 1, .num_pipes = 2,
  197. .need_gfx_hws = 1, .has_hotplug = 1,
  198. .has_overlay = 1,
  199. };
  200. static const struct intel_device_info intel_ironlake_d_info = {
  201. .gen = 5, .num_pipes = 2,
  202. .need_gfx_hws = 1, .has_hotplug = 1,
  203. .has_bsd_ring = 1,
  204. };
  205. static const struct intel_device_info intel_ironlake_m_info = {
  206. .gen = 5, .is_mobile = 1, .num_pipes = 2,
  207. .need_gfx_hws = 1, .has_hotplug = 1,
  208. .has_fbc = 1,
  209. .has_bsd_ring = 1,
  210. };
  211. static const struct intel_device_info intel_sandybridge_d_info = {
  212. .gen = 6, .num_pipes = 2,
  213. .need_gfx_hws = 1, .has_hotplug = 1,
  214. .has_bsd_ring = 1,
  215. .has_blt_ring = 1,
  216. .has_llc = 1,
  217. .has_force_wake = 1,
  218. };
  219. static const struct intel_device_info intel_sandybridge_m_info = {
  220. .gen = 6, .is_mobile = 1, .num_pipes = 2,
  221. .need_gfx_hws = 1, .has_hotplug = 1,
  222. .has_fbc = 1,
  223. .has_bsd_ring = 1,
  224. .has_blt_ring = 1,
  225. .has_llc = 1,
  226. .has_force_wake = 1,
  227. };
  228. #define GEN7_FEATURES \
  229. .gen = 7, .num_pipes = 3, \
  230. .need_gfx_hws = 1, .has_hotplug = 1, \
  231. .has_bsd_ring = 1, \
  232. .has_blt_ring = 1, \
  233. .has_llc = 1, \
  234. .has_force_wake = 1
  235. static const struct intel_device_info intel_ivybridge_d_info = {
  236. GEN7_FEATURES,
  237. .is_ivybridge = 1,
  238. };
  239. static const struct intel_device_info intel_ivybridge_m_info = {
  240. GEN7_FEATURES,
  241. .is_ivybridge = 1,
  242. .is_mobile = 1,
  243. };
  244. static const struct intel_device_info intel_ivybridge_q_info = {
  245. GEN7_FEATURES,
  246. .is_ivybridge = 1,
  247. .num_pipes = 0, /* legal, last one wins */
  248. };
  249. static const struct intel_device_info intel_valleyview_m_info = {
  250. GEN7_FEATURES,
  251. .is_mobile = 1,
  252. .num_pipes = 2,
  253. .is_valleyview = 1,
  254. .display_mmio_offset = VLV_DISPLAY_BASE,
  255. .has_llc = 0, /* legal, last one wins */
  256. };
  257. static const struct intel_device_info intel_valleyview_d_info = {
  258. GEN7_FEATURES,
  259. .num_pipes = 2,
  260. .is_valleyview = 1,
  261. .display_mmio_offset = VLV_DISPLAY_BASE,
  262. .has_llc = 0, /* legal, last one wins */
  263. };
  264. static const struct intel_device_info intel_haswell_d_info = {
  265. GEN7_FEATURES,
  266. .is_haswell = 1,
  267. .has_ddi = 1,
  268. .has_fpga_dbg = 1,
  269. };
  270. static const struct intel_device_info intel_haswell_m_info = {
  271. GEN7_FEATURES,
  272. .is_haswell = 1,
  273. .is_mobile = 1,
  274. .has_ddi = 1,
  275. .has_fpga_dbg = 1,
  276. };
  277. static const struct pci_device_id pciidlist[] = { /* aka */
  278. INTEL_VGA_DEVICE(0x3577, &intel_i830_info), /* I830_M */
  279. INTEL_VGA_DEVICE(0x2562, &intel_845g_info), /* 845_G */
  280. INTEL_VGA_DEVICE(0x3582, &intel_i85x_info), /* I855_GM */
  281. INTEL_VGA_DEVICE(0x358e, &intel_i85x_info),
  282. INTEL_VGA_DEVICE(0x2572, &intel_i865g_info), /* I865_G */
  283. INTEL_VGA_DEVICE(0x2582, &intel_i915g_info), /* I915_G */
  284. INTEL_VGA_DEVICE(0x258a, &intel_i915g_info), /* E7221_G */
  285. INTEL_VGA_DEVICE(0x2592, &intel_i915gm_info), /* I915_GM */
  286. INTEL_VGA_DEVICE(0x2772, &intel_i945g_info), /* I945_G */
  287. INTEL_VGA_DEVICE(0x27a2, &intel_i945gm_info), /* I945_GM */
  288. INTEL_VGA_DEVICE(0x27ae, &intel_i945gm_info), /* I945_GME */
  289. INTEL_VGA_DEVICE(0x2972, &intel_i965g_info), /* I946_GZ */
  290. INTEL_VGA_DEVICE(0x2982, &intel_i965g_info), /* G35_G */
  291. INTEL_VGA_DEVICE(0x2992, &intel_i965g_info), /* I965_Q */
  292. INTEL_VGA_DEVICE(0x29a2, &intel_i965g_info), /* I965_G */
  293. INTEL_VGA_DEVICE(0x29b2, &intel_g33_info), /* Q35_G */
  294. INTEL_VGA_DEVICE(0x29c2, &intel_g33_info), /* G33_G */
  295. INTEL_VGA_DEVICE(0x29d2, &intel_g33_info), /* Q33_G */
  296. INTEL_VGA_DEVICE(0x2a02, &intel_i965gm_info), /* I965_GM */
  297. INTEL_VGA_DEVICE(0x2a12, &intel_i965gm_info), /* I965_GME */
  298. INTEL_VGA_DEVICE(0x2a42, &intel_gm45_info), /* GM45_G */
  299. INTEL_VGA_DEVICE(0x2e02, &intel_g45_info), /* IGD_E_G */
  300. INTEL_VGA_DEVICE(0x2e12, &intel_g45_info), /* Q45_G */
  301. INTEL_VGA_DEVICE(0x2e22, &intel_g45_info), /* G45_G */
  302. INTEL_VGA_DEVICE(0x2e32, &intel_g45_info), /* G41_G */
  303. INTEL_VGA_DEVICE(0x2e42, &intel_g45_info), /* B43_G */
  304. INTEL_VGA_DEVICE(0x2e92, &intel_g45_info), /* B43_G.1 */
  305. INTEL_VGA_DEVICE(0xa001, &intel_pineview_info),
  306. INTEL_VGA_DEVICE(0xa011, &intel_pineview_info),
  307. INTEL_VGA_DEVICE(0x0042, &intel_ironlake_d_info),
  308. INTEL_VGA_DEVICE(0x0046, &intel_ironlake_m_info),
  309. INTEL_VGA_DEVICE(0x0102, &intel_sandybridge_d_info),
  310. INTEL_VGA_DEVICE(0x0112, &intel_sandybridge_d_info),
  311. INTEL_VGA_DEVICE(0x0122, &intel_sandybridge_d_info),
  312. INTEL_VGA_DEVICE(0x0106, &intel_sandybridge_m_info),
  313. INTEL_VGA_DEVICE(0x0116, &intel_sandybridge_m_info),
  314. INTEL_VGA_DEVICE(0x0126, &intel_sandybridge_m_info),
  315. INTEL_VGA_DEVICE(0x010A, &intel_sandybridge_d_info),
  316. INTEL_VGA_DEVICE(0x0156, &intel_ivybridge_m_info), /* GT1 mobile */
  317. INTEL_VGA_DEVICE(0x0166, &intel_ivybridge_m_info), /* GT2 mobile */
  318. INTEL_VGA_DEVICE(0x0152, &intel_ivybridge_d_info), /* GT1 desktop */
  319. INTEL_VGA_DEVICE(0x0162, &intel_ivybridge_d_info), /* GT2 desktop */
  320. INTEL_VGA_DEVICE(0x015a, &intel_ivybridge_d_info), /* GT1 server */
  321. INTEL_QUANTA_VGA_DEVICE(&intel_ivybridge_q_info), /* Quanta transcode */
  322. INTEL_VGA_DEVICE(0x016a, &intel_ivybridge_d_info), /* GT2 server */
  323. INTEL_VGA_DEVICE(0x0402, &intel_haswell_d_info), /* GT1 desktop */
  324. INTEL_VGA_DEVICE(0x0412, &intel_haswell_d_info), /* GT2 desktop */
  325. INTEL_VGA_DEVICE(0x0422, &intel_haswell_d_info), /* GT2 desktop */
  326. INTEL_VGA_DEVICE(0x040a, &intel_haswell_d_info), /* GT1 server */
  327. INTEL_VGA_DEVICE(0x041a, &intel_haswell_d_info), /* GT2 server */
  328. INTEL_VGA_DEVICE(0x042a, &intel_haswell_d_info), /* GT2 server */
  329. INTEL_VGA_DEVICE(0x0406, &intel_haswell_m_info), /* GT1 mobile */
  330. INTEL_VGA_DEVICE(0x0416, &intel_haswell_m_info), /* GT2 mobile */
  331. INTEL_VGA_DEVICE(0x0426, &intel_haswell_m_info), /* GT2 mobile */
  332. INTEL_VGA_DEVICE(0x0C02, &intel_haswell_d_info), /* SDV GT1 desktop */
  333. INTEL_VGA_DEVICE(0x0C12, &intel_haswell_d_info), /* SDV GT2 desktop */
  334. INTEL_VGA_DEVICE(0x0C22, &intel_haswell_d_info), /* SDV GT2 desktop */
  335. INTEL_VGA_DEVICE(0x0C0A, &intel_haswell_d_info), /* SDV GT1 server */
  336. INTEL_VGA_DEVICE(0x0C1A, &intel_haswell_d_info), /* SDV GT2 server */
  337. INTEL_VGA_DEVICE(0x0C2A, &intel_haswell_d_info), /* SDV GT2 server */
  338. INTEL_VGA_DEVICE(0x0C06, &intel_haswell_m_info), /* SDV GT1 mobile */
  339. INTEL_VGA_DEVICE(0x0C16, &intel_haswell_m_info), /* SDV GT2 mobile */
  340. INTEL_VGA_DEVICE(0x0C26, &intel_haswell_m_info), /* SDV GT2 mobile */
  341. INTEL_VGA_DEVICE(0x0A02, &intel_haswell_d_info), /* ULT GT1 desktop */
  342. INTEL_VGA_DEVICE(0x0A12, &intel_haswell_d_info), /* ULT GT2 desktop */
  343. INTEL_VGA_DEVICE(0x0A22, &intel_haswell_d_info), /* ULT GT2 desktop */
  344. INTEL_VGA_DEVICE(0x0A0A, &intel_haswell_d_info), /* ULT GT1 server */
  345. INTEL_VGA_DEVICE(0x0A1A, &intel_haswell_d_info), /* ULT GT2 server */
  346. INTEL_VGA_DEVICE(0x0A2A, &intel_haswell_d_info), /* ULT GT2 server */
  347. INTEL_VGA_DEVICE(0x0A06, &intel_haswell_m_info), /* ULT GT1 mobile */
  348. INTEL_VGA_DEVICE(0x0A16, &intel_haswell_m_info), /* ULT GT2 mobile */
  349. INTEL_VGA_DEVICE(0x0A26, &intel_haswell_m_info), /* ULT GT2 mobile */
  350. INTEL_VGA_DEVICE(0x0D02, &intel_haswell_d_info), /* CRW GT1 desktop */
  351. INTEL_VGA_DEVICE(0x0D12, &intel_haswell_d_info), /* CRW GT2 desktop */
  352. INTEL_VGA_DEVICE(0x0D22, &intel_haswell_d_info), /* CRW GT2 desktop */
  353. INTEL_VGA_DEVICE(0x0D0A, &intel_haswell_d_info), /* CRW GT1 server */
  354. INTEL_VGA_DEVICE(0x0D1A, &intel_haswell_d_info), /* CRW GT2 server */
  355. INTEL_VGA_DEVICE(0x0D2A, &intel_haswell_d_info), /* CRW GT2 server */
  356. INTEL_VGA_DEVICE(0x0D06, &intel_haswell_m_info), /* CRW GT1 mobile */
  357. INTEL_VGA_DEVICE(0x0D16, &intel_haswell_m_info), /* CRW GT2 mobile */
  358. INTEL_VGA_DEVICE(0x0D26, &intel_haswell_m_info), /* CRW GT2 mobile */
  359. INTEL_VGA_DEVICE(0x0f30, &intel_valleyview_m_info),
  360. INTEL_VGA_DEVICE(0x0f31, &intel_valleyview_m_info),
  361. INTEL_VGA_DEVICE(0x0f32, &intel_valleyview_m_info),
  362. INTEL_VGA_DEVICE(0x0f33, &intel_valleyview_m_info),
  363. INTEL_VGA_DEVICE(0x0157, &intel_valleyview_m_info),
  364. INTEL_VGA_DEVICE(0x0155, &intel_valleyview_d_info),
  365. {0, 0, 0}
  366. };
  367. #if defined(CONFIG_DRM_I915_KMS)
  368. MODULE_DEVICE_TABLE(pci, pciidlist);
  369. #endif
  370. void intel_detect_pch(struct drm_device *dev)
  371. {
  372. struct drm_i915_private *dev_priv = dev->dev_private;
  373. struct pci_dev *pch;
  374. /* In all current cases, num_pipes is equivalent to the PCH_NOP setting
  375. * (which really amounts to a PCH but no South Display).
  376. */
  377. if (INTEL_INFO(dev)->num_pipes == 0) {
  378. dev_priv->pch_type = PCH_NOP;
  379. dev_priv->num_pch_pll = 0;
  380. return;
  381. }
  382. /*
  383. * The reason to probe ISA bridge instead of Dev31:Fun0 is to
  384. * make graphics device passthrough work easy for VMM, that only
  385. * need to expose ISA bridge to let driver know the real hardware
  386. * underneath. This is a requirement from virtualization team.
  387. */
  388. pch = pci_get_class(PCI_CLASS_BRIDGE_ISA << 8, NULL);
  389. if (pch) {
  390. if (pch->vendor == PCI_VENDOR_ID_INTEL) {
  391. unsigned short id;
  392. id = pch->device & INTEL_PCH_DEVICE_ID_MASK;
  393. dev_priv->pch_id = id;
  394. if (id == INTEL_PCH_IBX_DEVICE_ID_TYPE) {
  395. dev_priv->pch_type = PCH_IBX;
  396. dev_priv->num_pch_pll = 2;
  397. DRM_DEBUG_KMS("Found Ibex Peak PCH\n");
  398. WARN_ON(!IS_GEN5(dev));
  399. } else if (id == INTEL_PCH_CPT_DEVICE_ID_TYPE) {
  400. dev_priv->pch_type = PCH_CPT;
  401. dev_priv->num_pch_pll = 2;
  402. DRM_DEBUG_KMS("Found CougarPoint PCH\n");
  403. WARN_ON(!(IS_GEN6(dev) || IS_IVYBRIDGE(dev)));
  404. } else if (id == INTEL_PCH_PPT_DEVICE_ID_TYPE) {
  405. /* PantherPoint is CPT compatible */
  406. dev_priv->pch_type = PCH_CPT;
  407. dev_priv->num_pch_pll = 2;
  408. DRM_DEBUG_KMS("Found PatherPoint PCH\n");
  409. WARN_ON(!(IS_GEN6(dev) || IS_IVYBRIDGE(dev)));
  410. } else if (id == INTEL_PCH_LPT_DEVICE_ID_TYPE) {
  411. dev_priv->pch_type = PCH_LPT;
  412. dev_priv->num_pch_pll = 0;
  413. DRM_DEBUG_KMS("Found LynxPoint PCH\n");
  414. WARN_ON(!IS_HASWELL(dev));
  415. WARN_ON(IS_ULT(dev));
  416. } else if (id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) {
  417. dev_priv->pch_type = PCH_LPT;
  418. dev_priv->num_pch_pll = 0;
  419. DRM_DEBUG_KMS("Found LynxPoint LP PCH\n");
  420. WARN_ON(!IS_HASWELL(dev));
  421. WARN_ON(!IS_ULT(dev));
  422. }
  423. BUG_ON(dev_priv->num_pch_pll > I915_NUM_PLLS);
  424. }
  425. pci_dev_put(pch);
  426. }
  427. }
  428. bool i915_semaphore_is_enabled(struct drm_device *dev)
  429. {
  430. if (INTEL_INFO(dev)->gen < 6)
  431. return 0;
  432. if (i915_semaphores >= 0)
  433. return i915_semaphores;
  434. #ifdef CONFIG_INTEL_IOMMU
  435. /* Enable semaphores on SNB when IO remapping is off */
  436. if (INTEL_INFO(dev)->gen == 6 && intel_iommu_gfx_mapped)
  437. return false;
  438. #endif
  439. return 1;
  440. }
  441. static int i915_drm_freeze(struct drm_device *dev)
  442. {
  443. struct drm_i915_private *dev_priv = dev->dev_private;
  444. struct drm_crtc *crtc;
  445. /* ignore lid events during suspend */
  446. mutex_lock(&dev_priv->modeset_restore_lock);
  447. dev_priv->modeset_restore = MODESET_SUSPENDED;
  448. mutex_unlock(&dev_priv->modeset_restore_lock);
  449. intel_set_power_well(dev, true);
  450. drm_kms_helper_poll_disable(dev);
  451. pci_save_state(dev->pdev);
  452. /* If KMS is active, we do the leavevt stuff here */
  453. if (drm_core_check_feature(dev, DRIVER_MODESET)) {
  454. int error = i915_gem_idle(dev);
  455. if (error) {
  456. dev_err(&dev->pdev->dev,
  457. "GEM idle failed, resume might fail\n");
  458. return error;
  459. }
  460. cancel_delayed_work_sync(&dev_priv->rps.delayed_resume_work);
  461. drm_irq_uninstall(dev);
  462. dev_priv->enable_hotplug_processing = false;
  463. /*
  464. * Disable CRTCs directly since we want to preserve sw state
  465. * for _thaw.
  466. */
  467. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
  468. dev_priv->display.crtc_disable(crtc);
  469. }
  470. i915_save_state(dev);
  471. intel_opregion_fini(dev);
  472. console_lock();
  473. intel_fbdev_set_suspend(dev, 1);
  474. console_unlock();
  475. return 0;
  476. }
  477. int i915_suspend(struct drm_device *dev, pm_message_t state)
  478. {
  479. int error;
  480. if (!dev || !dev->dev_private) {
  481. DRM_ERROR("dev: %p\n", dev);
  482. DRM_ERROR("DRM not initialized, aborting suspend.\n");
  483. return -ENODEV;
  484. }
  485. if (state.event == PM_EVENT_PRETHAW)
  486. return 0;
  487. if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
  488. return 0;
  489. error = i915_drm_freeze(dev);
  490. if (error)
  491. return error;
  492. if (state.event == PM_EVENT_SUSPEND) {
  493. /* Shut down the device */
  494. pci_disable_device(dev->pdev);
  495. pci_set_power_state(dev->pdev, PCI_D3hot);
  496. }
  497. return 0;
  498. }
  499. void intel_console_resume(struct work_struct *work)
  500. {
  501. struct drm_i915_private *dev_priv =
  502. container_of(work, struct drm_i915_private,
  503. console_resume_work);
  504. struct drm_device *dev = dev_priv->dev;
  505. console_lock();
  506. intel_fbdev_set_suspend(dev, 0);
  507. console_unlock();
  508. }
  509. static void intel_resume_hotplug(struct drm_device *dev)
  510. {
  511. struct drm_mode_config *mode_config = &dev->mode_config;
  512. struct intel_encoder *encoder;
  513. mutex_lock(&mode_config->mutex);
  514. DRM_DEBUG_KMS("running encoder hotplug functions\n");
  515. list_for_each_entry(encoder, &mode_config->encoder_list, base.head)
  516. if (encoder->hot_plug)
  517. encoder->hot_plug(encoder);
  518. mutex_unlock(&mode_config->mutex);
  519. /* Just fire off a uevent and let userspace tell us what to do */
  520. drm_helper_hpd_irq_event(dev);
  521. }
  522. static int __i915_drm_thaw(struct drm_device *dev)
  523. {
  524. struct drm_i915_private *dev_priv = dev->dev_private;
  525. int error = 0;
  526. i915_restore_state(dev);
  527. intel_opregion_setup(dev);
  528. /* KMS EnterVT equivalent */
  529. if (drm_core_check_feature(dev, DRIVER_MODESET)) {
  530. intel_init_pch_refclk(dev);
  531. mutex_lock(&dev->struct_mutex);
  532. dev_priv->mm.suspended = 0;
  533. error = i915_gem_init_hw(dev);
  534. mutex_unlock(&dev->struct_mutex);
  535. /* We need working interrupts for modeset enabling ... */
  536. drm_irq_install(dev);
  537. intel_modeset_init_hw(dev);
  538. drm_modeset_lock_all(dev);
  539. intel_modeset_setup_hw_state(dev, true);
  540. drm_modeset_unlock_all(dev);
  541. /*
  542. * ... but also need to make sure that hotplug processing
  543. * doesn't cause havoc. Like in the driver load code we don't
  544. * bother with the tiny race here where we might loose hotplug
  545. * notifications.
  546. * */
  547. intel_hpd_init(dev);
  548. dev_priv->enable_hotplug_processing = true;
  549. /* Config may have changed between suspend and resume */
  550. intel_resume_hotplug(dev);
  551. }
  552. intel_opregion_init(dev);
  553. /*
  554. * The console lock can be pretty contented on resume due
  555. * to all the printk activity. Try to keep it out of the hot
  556. * path of resume if possible.
  557. */
  558. if (console_trylock()) {
  559. intel_fbdev_set_suspend(dev, 0);
  560. console_unlock();
  561. } else {
  562. schedule_work(&dev_priv->console_resume_work);
  563. }
  564. mutex_lock(&dev_priv->modeset_restore_lock);
  565. dev_priv->modeset_restore = MODESET_DONE;
  566. mutex_unlock(&dev_priv->modeset_restore_lock);
  567. return error;
  568. }
  569. static int i915_drm_thaw(struct drm_device *dev)
  570. {
  571. int error = 0;
  572. intel_gt_reset(dev);
  573. if (drm_core_check_feature(dev, DRIVER_MODESET)) {
  574. mutex_lock(&dev->struct_mutex);
  575. i915_gem_restore_gtt_mappings(dev);
  576. mutex_unlock(&dev->struct_mutex);
  577. }
  578. __i915_drm_thaw(dev);
  579. return error;
  580. }
  581. int i915_resume(struct drm_device *dev)
  582. {
  583. struct drm_i915_private *dev_priv = dev->dev_private;
  584. int ret;
  585. if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
  586. return 0;
  587. if (pci_enable_device(dev->pdev))
  588. return -EIO;
  589. pci_set_master(dev->pdev);
  590. intel_gt_reset(dev);
  591. /*
  592. * Platforms with opregion should have sane BIOS, older ones (gen3 and
  593. * earlier) need this since the BIOS might clear all our scratch PTEs.
  594. */
  595. if (drm_core_check_feature(dev, DRIVER_MODESET) &&
  596. !dev_priv->opregion.header) {
  597. mutex_lock(&dev->struct_mutex);
  598. i915_gem_restore_gtt_mappings(dev);
  599. mutex_unlock(&dev->struct_mutex);
  600. }
  601. ret = __i915_drm_thaw(dev);
  602. if (ret)
  603. return ret;
  604. drm_kms_helper_poll_enable(dev);
  605. return 0;
  606. }
  607. static int i8xx_do_reset(struct drm_device *dev)
  608. {
  609. struct drm_i915_private *dev_priv = dev->dev_private;
  610. if (IS_I85X(dev))
  611. return -ENODEV;
  612. I915_WRITE(D_STATE, I915_READ(D_STATE) | DSTATE_GFX_RESET_I830);
  613. POSTING_READ(D_STATE);
  614. if (IS_I830(dev) || IS_845G(dev)) {
  615. I915_WRITE(DEBUG_RESET_I830,
  616. DEBUG_RESET_DISPLAY |
  617. DEBUG_RESET_RENDER |
  618. DEBUG_RESET_FULL);
  619. POSTING_READ(DEBUG_RESET_I830);
  620. msleep(1);
  621. I915_WRITE(DEBUG_RESET_I830, 0);
  622. POSTING_READ(DEBUG_RESET_I830);
  623. }
  624. msleep(1);
  625. I915_WRITE(D_STATE, I915_READ(D_STATE) & ~DSTATE_GFX_RESET_I830);
  626. POSTING_READ(D_STATE);
  627. return 0;
  628. }
  629. static int i965_reset_complete(struct drm_device *dev)
  630. {
  631. u8 gdrst;
  632. pci_read_config_byte(dev->pdev, I965_GDRST, &gdrst);
  633. return (gdrst & GRDOM_RESET_ENABLE) == 0;
  634. }
  635. static int i965_do_reset(struct drm_device *dev)
  636. {
  637. int ret;
  638. u8 gdrst;
  639. /*
  640. * Set the domains we want to reset (GRDOM/bits 2 and 3) as
  641. * well as the reset bit (GR/bit 0). Setting the GR bit
  642. * triggers the reset; when done, the hardware will clear it.
  643. */
  644. pci_read_config_byte(dev->pdev, I965_GDRST, &gdrst);
  645. pci_write_config_byte(dev->pdev, I965_GDRST,
  646. gdrst | GRDOM_RENDER |
  647. GRDOM_RESET_ENABLE);
  648. ret = wait_for(i965_reset_complete(dev), 500);
  649. if (ret)
  650. return ret;
  651. /* We can't reset render&media without also resetting display ... */
  652. pci_read_config_byte(dev->pdev, I965_GDRST, &gdrst);
  653. pci_write_config_byte(dev->pdev, I965_GDRST,
  654. gdrst | GRDOM_MEDIA |
  655. GRDOM_RESET_ENABLE);
  656. return wait_for(i965_reset_complete(dev), 500);
  657. }
  658. static int ironlake_do_reset(struct drm_device *dev)
  659. {
  660. struct drm_i915_private *dev_priv = dev->dev_private;
  661. u32 gdrst;
  662. int ret;
  663. gdrst = I915_READ(MCHBAR_MIRROR_BASE + ILK_GDSR);
  664. gdrst &= ~GRDOM_MASK;
  665. I915_WRITE(MCHBAR_MIRROR_BASE + ILK_GDSR,
  666. gdrst | GRDOM_RENDER | GRDOM_RESET_ENABLE);
  667. ret = wait_for(I915_READ(MCHBAR_MIRROR_BASE + ILK_GDSR) & 0x1, 500);
  668. if (ret)
  669. return ret;
  670. /* We can't reset render&media without also resetting display ... */
  671. gdrst = I915_READ(MCHBAR_MIRROR_BASE + ILK_GDSR);
  672. gdrst &= ~GRDOM_MASK;
  673. I915_WRITE(MCHBAR_MIRROR_BASE + ILK_GDSR,
  674. gdrst | GRDOM_MEDIA | GRDOM_RESET_ENABLE);
  675. return wait_for(I915_READ(MCHBAR_MIRROR_BASE + ILK_GDSR) & 0x1, 500);
  676. }
  677. static int gen6_do_reset(struct drm_device *dev)
  678. {
  679. struct drm_i915_private *dev_priv = dev->dev_private;
  680. int ret;
  681. unsigned long irqflags;
  682. /* Hold gt_lock across reset to prevent any register access
  683. * with forcewake not set correctly
  684. */
  685. spin_lock_irqsave(&dev_priv->gt_lock, irqflags);
  686. /* Reset the chip */
  687. /* GEN6_GDRST is not in the gt power well, no need to check
  688. * for fifo space for the write or forcewake the chip for
  689. * the read
  690. */
  691. I915_WRITE_NOTRACE(GEN6_GDRST, GEN6_GRDOM_FULL);
  692. /* Spin waiting for the device to ack the reset request */
  693. ret = wait_for((I915_READ_NOTRACE(GEN6_GDRST) & GEN6_GRDOM_FULL) == 0, 500);
  694. /* If reset with a user forcewake, try to restore, otherwise turn it off */
  695. if (dev_priv->forcewake_count)
  696. dev_priv->gt.force_wake_get(dev_priv);
  697. else
  698. dev_priv->gt.force_wake_put(dev_priv);
  699. /* Restore fifo count */
  700. dev_priv->gt_fifo_count = I915_READ_NOTRACE(GT_FIFO_FREE_ENTRIES);
  701. spin_unlock_irqrestore(&dev_priv->gt_lock, irqflags);
  702. return ret;
  703. }
  704. int intel_gpu_reset(struct drm_device *dev)
  705. {
  706. struct drm_i915_private *dev_priv = dev->dev_private;
  707. int ret = -ENODEV;
  708. switch (INTEL_INFO(dev)->gen) {
  709. case 7:
  710. case 6:
  711. ret = gen6_do_reset(dev);
  712. break;
  713. case 5:
  714. ret = ironlake_do_reset(dev);
  715. break;
  716. case 4:
  717. ret = i965_do_reset(dev);
  718. break;
  719. case 2:
  720. ret = i8xx_do_reset(dev);
  721. break;
  722. }
  723. /* Also reset the gpu hangman. */
  724. if (dev_priv->gpu_error.stop_rings) {
  725. DRM_INFO("Simulated gpu hang, resetting stop_rings\n");
  726. dev_priv->gpu_error.stop_rings = 0;
  727. if (ret == -ENODEV) {
  728. DRM_ERROR("Reset not implemented, but ignoring "
  729. "error for simulated gpu hangs\n");
  730. ret = 0;
  731. }
  732. }
  733. return ret;
  734. }
  735. /**
  736. * i915_reset - reset chip after a hang
  737. * @dev: drm device to reset
  738. *
  739. * Reset the chip. Useful if a hang is detected. Returns zero on successful
  740. * reset or otherwise an error code.
  741. *
  742. * Procedure is fairly simple:
  743. * - reset the chip using the reset reg
  744. * - re-init context state
  745. * - re-init hardware status page
  746. * - re-init ring buffer
  747. * - re-init interrupt state
  748. * - re-init display
  749. */
  750. int i915_reset(struct drm_device *dev)
  751. {
  752. drm_i915_private_t *dev_priv = dev->dev_private;
  753. int ret;
  754. if (!i915_try_reset)
  755. return 0;
  756. mutex_lock(&dev->struct_mutex);
  757. i915_gem_reset(dev);
  758. ret = -ENODEV;
  759. if (get_seconds() - dev_priv->gpu_error.last_reset < 5)
  760. DRM_ERROR("GPU hanging too fast, declaring wedged!\n");
  761. else
  762. ret = intel_gpu_reset(dev);
  763. dev_priv->gpu_error.last_reset = get_seconds();
  764. if (ret) {
  765. DRM_ERROR("Failed to reset chip.\n");
  766. mutex_unlock(&dev->struct_mutex);
  767. return ret;
  768. }
  769. /* Ok, now get things going again... */
  770. /*
  771. * Everything depends on having the GTT running, so we need to start
  772. * there. Fortunately we don't need to do this unless we reset the
  773. * chip at a PCI level.
  774. *
  775. * Next we need to restore the context, but we don't use those
  776. * yet either...
  777. *
  778. * Ring buffer needs to be re-initialized in the KMS case, or if X
  779. * was running at the time of the reset (i.e. we weren't VT
  780. * switched away).
  781. */
  782. if (drm_core_check_feature(dev, DRIVER_MODESET) ||
  783. !dev_priv->mm.suspended) {
  784. struct intel_ring_buffer *ring;
  785. int i;
  786. dev_priv->mm.suspended = 0;
  787. i915_gem_init_swizzling(dev);
  788. for_each_ring(ring, dev_priv, i)
  789. ring->init(ring);
  790. i915_gem_context_init(dev);
  791. if (dev_priv->mm.aliasing_ppgtt) {
  792. ret = dev_priv->mm.aliasing_ppgtt->enable(dev);
  793. if (ret)
  794. i915_gem_cleanup_aliasing_ppgtt(dev);
  795. }
  796. /*
  797. * It would make sense to re-init all the other hw state, at
  798. * least the rps/rc6/emon init done within modeset_init_hw. For
  799. * some unknown reason, this blows up my ilk, so don't.
  800. */
  801. mutex_unlock(&dev->struct_mutex);
  802. drm_irq_uninstall(dev);
  803. drm_irq_install(dev);
  804. intel_hpd_init(dev);
  805. } else {
  806. mutex_unlock(&dev->struct_mutex);
  807. }
  808. return 0;
  809. }
  810. static int i915_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  811. {
  812. struct intel_device_info *intel_info =
  813. (struct intel_device_info *) ent->driver_data;
  814. if (intel_info->is_valleyview)
  815. if(!i915_preliminary_hw_support) {
  816. DRM_ERROR("Preliminary hardware support disabled\n");
  817. return -ENODEV;
  818. }
  819. /* Only bind to function 0 of the device. Early generations
  820. * used function 1 as a placeholder for multi-head. This causes
  821. * us confusion instead, especially on the systems where both
  822. * functions have the same PCI-ID!
  823. */
  824. if (PCI_FUNC(pdev->devfn))
  825. return -ENODEV;
  826. /* We've managed to ship a kms-enabled ddx that shipped with an XvMC
  827. * implementation for gen3 (and only gen3) that used legacy drm maps
  828. * (gasp!) to share buffers between X and the client. Hence we need to
  829. * keep around the fake agp stuff for gen3, even when kms is enabled. */
  830. if (intel_info->gen != 3) {
  831. driver.driver_features &=
  832. ~(DRIVER_USE_AGP | DRIVER_REQUIRE_AGP);
  833. } else if (!intel_agp_enabled) {
  834. DRM_ERROR("drm/i915 can't work without intel_agp module!\n");
  835. return -ENODEV;
  836. }
  837. return drm_get_pci_dev(pdev, ent, &driver);
  838. }
  839. static void
  840. i915_pci_remove(struct pci_dev *pdev)
  841. {
  842. struct drm_device *dev = pci_get_drvdata(pdev);
  843. drm_put_dev(dev);
  844. }
  845. static int i915_pm_suspend(struct device *dev)
  846. {
  847. struct pci_dev *pdev = to_pci_dev(dev);
  848. struct drm_device *drm_dev = pci_get_drvdata(pdev);
  849. int error;
  850. if (!drm_dev || !drm_dev->dev_private) {
  851. dev_err(dev, "DRM not initialized, aborting suspend.\n");
  852. return -ENODEV;
  853. }
  854. if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF)
  855. return 0;
  856. error = i915_drm_freeze(drm_dev);
  857. if (error)
  858. return error;
  859. pci_disable_device(pdev);
  860. pci_set_power_state(pdev, PCI_D3hot);
  861. return 0;
  862. }
  863. static int i915_pm_resume(struct device *dev)
  864. {
  865. struct pci_dev *pdev = to_pci_dev(dev);
  866. struct drm_device *drm_dev = pci_get_drvdata(pdev);
  867. return i915_resume(drm_dev);
  868. }
  869. static int i915_pm_freeze(struct device *dev)
  870. {
  871. struct pci_dev *pdev = to_pci_dev(dev);
  872. struct drm_device *drm_dev = pci_get_drvdata(pdev);
  873. if (!drm_dev || !drm_dev->dev_private) {
  874. dev_err(dev, "DRM not initialized, aborting suspend.\n");
  875. return -ENODEV;
  876. }
  877. return i915_drm_freeze(drm_dev);
  878. }
  879. static int i915_pm_thaw(struct device *dev)
  880. {
  881. struct pci_dev *pdev = to_pci_dev(dev);
  882. struct drm_device *drm_dev = pci_get_drvdata(pdev);
  883. return i915_drm_thaw(drm_dev);
  884. }
  885. static int i915_pm_poweroff(struct device *dev)
  886. {
  887. struct pci_dev *pdev = to_pci_dev(dev);
  888. struct drm_device *drm_dev = pci_get_drvdata(pdev);
  889. return i915_drm_freeze(drm_dev);
  890. }
  891. static const struct dev_pm_ops i915_pm_ops = {
  892. .suspend = i915_pm_suspend,
  893. .resume = i915_pm_resume,
  894. .freeze = i915_pm_freeze,
  895. .thaw = i915_pm_thaw,
  896. .poweroff = i915_pm_poweroff,
  897. .restore = i915_pm_resume,
  898. };
  899. static const struct vm_operations_struct i915_gem_vm_ops = {
  900. .fault = i915_gem_fault,
  901. .open = drm_gem_vm_open,
  902. .close = drm_gem_vm_close,
  903. };
  904. static const struct file_operations i915_driver_fops = {
  905. .owner = THIS_MODULE,
  906. .open = drm_open,
  907. .release = drm_release,
  908. .unlocked_ioctl = drm_ioctl,
  909. .mmap = drm_gem_mmap,
  910. .poll = drm_poll,
  911. .fasync = drm_fasync,
  912. .read = drm_read,
  913. #ifdef CONFIG_COMPAT
  914. .compat_ioctl = i915_compat_ioctl,
  915. #endif
  916. .llseek = noop_llseek,
  917. };
  918. static struct drm_driver driver = {
  919. /* Don't use MTRRs here; the Xserver or userspace app should
  920. * deal with them for Intel hardware.
  921. */
  922. .driver_features =
  923. DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | /* DRIVER_USE_MTRR |*/
  924. DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_GEM | DRIVER_PRIME,
  925. .load = i915_driver_load,
  926. .unload = i915_driver_unload,
  927. .open = i915_driver_open,
  928. .lastclose = i915_driver_lastclose,
  929. .preclose = i915_driver_preclose,
  930. .postclose = i915_driver_postclose,
  931. /* Used in place of i915_pm_ops for non-DRIVER_MODESET */
  932. .suspend = i915_suspend,
  933. .resume = i915_resume,
  934. .device_is_agp = i915_driver_device_is_agp,
  935. .master_create = i915_master_create,
  936. .master_destroy = i915_master_destroy,
  937. #if defined(CONFIG_DEBUG_FS)
  938. .debugfs_init = i915_debugfs_init,
  939. .debugfs_cleanup = i915_debugfs_cleanup,
  940. #endif
  941. .gem_init_object = i915_gem_init_object,
  942. .gem_free_object = i915_gem_free_object,
  943. .gem_vm_ops = &i915_gem_vm_ops,
  944. .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
  945. .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
  946. .gem_prime_export = i915_gem_prime_export,
  947. .gem_prime_import = i915_gem_prime_import,
  948. .dumb_create = i915_gem_dumb_create,
  949. .dumb_map_offset = i915_gem_mmap_gtt,
  950. .dumb_destroy = i915_gem_dumb_destroy,
  951. .ioctls = i915_ioctls,
  952. .fops = &i915_driver_fops,
  953. .name = DRIVER_NAME,
  954. .desc = DRIVER_DESC,
  955. .date = DRIVER_DATE,
  956. .major = DRIVER_MAJOR,
  957. .minor = DRIVER_MINOR,
  958. .patchlevel = DRIVER_PATCHLEVEL,
  959. };
  960. static struct pci_driver i915_pci_driver = {
  961. .name = DRIVER_NAME,
  962. .id_table = pciidlist,
  963. .probe = i915_pci_probe,
  964. .remove = i915_pci_remove,
  965. .driver.pm = &i915_pm_ops,
  966. };
  967. static int __init i915_init(void)
  968. {
  969. driver.num_ioctls = i915_max_ioctl;
  970. /*
  971. * If CONFIG_DRM_I915_KMS is set, default to KMS unless
  972. * explicitly disabled with the module pararmeter.
  973. *
  974. * Otherwise, just follow the parameter (defaulting to off).
  975. *
  976. * Allow optional vga_text_mode_force boot option to override
  977. * the default behavior.
  978. */
  979. #if defined(CONFIG_DRM_I915_KMS)
  980. if (i915_modeset != 0)
  981. driver.driver_features |= DRIVER_MODESET;
  982. #endif
  983. if (i915_modeset == 1)
  984. driver.driver_features |= DRIVER_MODESET;
  985. #ifdef CONFIG_VGA_CONSOLE
  986. if (vgacon_text_force() && i915_modeset == -1)
  987. driver.driver_features &= ~DRIVER_MODESET;
  988. #endif
  989. if (!(driver.driver_features & DRIVER_MODESET))
  990. driver.get_vblank_timestamp = NULL;
  991. return drm_pci_init(&driver, &i915_pci_driver);
  992. }
  993. static void __exit i915_exit(void)
  994. {
  995. drm_pci_exit(&driver, &i915_pci_driver);
  996. }
  997. module_init(i915_init);
  998. module_exit(i915_exit);
  999. MODULE_AUTHOR(DRIVER_AUTHOR);
  1000. MODULE_DESCRIPTION(DRIVER_DESC);
  1001. MODULE_LICENSE("GPL and additional rights");
  1002. /* We give fast paths for the really cool registers */
  1003. #define NEEDS_FORCE_WAKE(dev_priv, reg) \
  1004. ((HAS_FORCE_WAKE((dev_priv)->dev)) && \
  1005. ((reg) < 0x40000) && \
  1006. ((reg) != FORCEWAKE))
  1007. static void
  1008. ilk_dummy_write(struct drm_i915_private *dev_priv)
  1009. {
  1010. /* WaIssueDummyWriteToWakeupFromRC6:ilk Issue a dummy write to wake up
  1011. * the chip from rc6 before touching it for real. MI_MODE is masked,
  1012. * hence harmless to write 0 into. */
  1013. I915_WRITE_NOTRACE(MI_MODE, 0);
  1014. }
  1015. static void
  1016. hsw_unclaimed_reg_clear(struct drm_i915_private *dev_priv, u32 reg)
  1017. {
  1018. if (HAS_FPGA_DBG_UNCLAIMED(dev_priv->dev) &&
  1019. (I915_READ_NOTRACE(FPGA_DBG) & FPGA_DBG_RM_NOCLAIM)) {
  1020. DRM_ERROR("Unknown unclaimed register before writing to %x\n",
  1021. reg);
  1022. I915_WRITE_NOTRACE(FPGA_DBG, FPGA_DBG_RM_NOCLAIM);
  1023. }
  1024. }
  1025. static void
  1026. hsw_unclaimed_reg_check(struct drm_i915_private *dev_priv, u32 reg)
  1027. {
  1028. if (HAS_FPGA_DBG_UNCLAIMED(dev_priv->dev) &&
  1029. (I915_READ_NOTRACE(FPGA_DBG) & FPGA_DBG_RM_NOCLAIM)) {
  1030. DRM_ERROR("Unclaimed write to %x\n", reg);
  1031. I915_WRITE_NOTRACE(FPGA_DBG, FPGA_DBG_RM_NOCLAIM);
  1032. }
  1033. }
  1034. #define __i915_read(x, y) \
  1035. u##x i915_read##x(struct drm_i915_private *dev_priv, u32 reg) { \
  1036. u##x val = 0; \
  1037. if (IS_GEN5(dev_priv->dev)) \
  1038. ilk_dummy_write(dev_priv); \
  1039. if (NEEDS_FORCE_WAKE((dev_priv), (reg))) { \
  1040. unsigned long irqflags; \
  1041. spin_lock_irqsave(&dev_priv->gt_lock, irqflags); \
  1042. if (dev_priv->forcewake_count == 0) \
  1043. dev_priv->gt.force_wake_get(dev_priv); \
  1044. val = read##y(dev_priv->regs + reg); \
  1045. if (dev_priv->forcewake_count == 0) \
  1046. dev_priv->gt.force_wake_put(dev_priv); \
  1047. spin_unlock_irqrestore(&dev_priv->gt_lock, irqflags); \
  1048. } else { \
  1049. val = read##y(dev_priv->regs + reg); \
  1050. } \
  1051. trace_i915_reg_rw(false, reg, val, sizeof(val)); \
  1052. return val; \
  1053. }
  1054. __i915_read(8, b)
  1055. __i915_read(16, w)
  1056. __i915_read(32, l)
  1057. __i915_read(64, q)
  1058. #undef __i915_read
  1059. #define __i915_write(x, y) \
  1060. void i915_write##x(struct drm_i915_private *dev_priv, u32 reg, u##x val) { \
  1061. u32 __fifo_ret = 0; \
  1062. trace_i915_reg_rw(true, reg, val, sizeof(val)); \
  1063. if (NEEDS_FORCE_WAKE((dev_priv), (reg))) { \
  1064. __fifo_ret = __gen6_gt_wait_for_fifo(dev_priv); \
  1065. } \
  1066. if (IS_GEN5(dev_priv->dev)) \
  1067. ilk_dummy_write(dev_priv); \
  1068. hsw_unclaimed_reg_clear(dev_priv, reg); \
  1069. write##y(val, dev_priv->regs + reg); \
  1070. if (unlikely(__fifo_ret)) { \
  1071. gen6_gt_check_fifodbg(dev_priv); \
  1072. } \
  1073. hsw_unclaimed_reg_check(dev_priv, reg); \
  1074. }
  1075. __i915_write(8, b)
  1076. __i915_write(16, w)
  1077. __i915_write(32, l)
  1078. __i915_write(64, q)
  1079. #undef __i915_write
  1080. static const struct register_whitelist {
  1081. uint64_t offset;
  1082. uint32_t size;
  1083. uint32_t gen_bitmask; /* support gens, 0x10 for 4, 0x30 for 4 and 5, etc. */
  1084. } whitelist[] = {
  1085. { RING_TIMESTAMP(RENDER_RING_BASE), 8, 0xF0 },
  1086. };
  1087. int i915_reg_read_ioctl(struct drm_device *dev,
  1088. void *data, struct drm_file *file)
  1089. {
  1090. struct drm_i915_private *dev_priv = dev->dev_private;
  1091. struct drm_i915_reg_read *reg = data;
  1092. struct register_whitelist const *entry = whitelist;
  1093. int i;
  1094. for (i = 0; i < ARRAY_SIZE(whitelist); i++, entry++) {
  1095. if (entry->offset == reg->offset &&
  1096. (1 << INTEL_INFO(dev)->gen & entry->gen_bitmask))
  1097. break;
  1098. }
  1099. if (i == ARRAY_SIZE(whitelist))
  1100. return -EINVAL;
  1101. switch (entry->size) {
  1102. case 8:
  1103. reg->val = I915_READ64(reg->offset);
  1104. break;
  1105. case 4:
  1106. reg->val = I915_READ(reg->offset);
  1107. break;
  1108. case 2:
  1109. reg->val = I915_READ16(reg->offset);
  1110. break;
  1111. case 1:
  1112. reg->val = I915_READ8(reg->offset);
  1113. break;
  1114. default:
  1115. WARN_ON(1);
  1116. return -EINVAL;
  1117. }
  1118. return 0;
  1119. }