i915_drv.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107
  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 "drmP.h"
  31. #include "drm.h"
  32. #include "i915_drm.h"
  33. #include "i915_drv.h"
  34. #include "intel_drv.h"
  35. #include <linux/console.h>
  36. #include <linux/module.h>
  37. #include "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 = 0;
  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 [default], 1=lid open, "
  49. "-1=lid closed)");
  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, 0600);
  60. MODULE_PARM_DESC(i915_enable_rc6,
  61. "Enable power-saving render C-state 6 (default: -1 (use per-chip default)");
  62. int i915_enable_fbc __read_mostly = -1;
  63. module_param_named(i915_enable_fbc, i915_enable_fbc, int, 0600);
  64. MODULE_PARM_DESC(i915_enable_fbc,
  65. "Enable frame buffer compression for power savings "
  66. "(default: -1 (use per-chip default))");
  67. unsigned int i915_lvds_downclock __read_mostly = 0;
  68. module_param_named(lvds_downclock, i915_lvds_downclock, int, 0400);
  69. MODULE_PARM_DESC(lvds_downclock,
  70. "Use panel (LVDS/eDP) downclocking for power savings "
  71. "(default: false)");
  72. int i915_lvds_channel_mode __read_mostly;
  73. module_param_named(lvds_channel_mode, i915_lvds_channel_mode, int, 0600);
  74. MODULE_PARM_DESC(lvds_channel_mode,
  75. "Specify LVDS channel mode "
  76. "(0=probe BIOS [default], 1=single-channel, 2=dual-channel)");
  77. int i915_panel_use_ssc __read_mostly = -1;
  78. module_param_named(lvds_use_ssc, i915_panel_use_ssc, int, 0600);
  79. MODULE_PARM_DESC(lvds_use_ssc,
  80. "Use Spread Spectrum Clock with panels [LVDS/eDP] "
  81. "(default: auto from VBT)");
  82. int i915_vbt_sdvo_panel_type __read_mostly = -1;
  83. module_param_named(vbt_sdvo_panel_type, i915_vbt_sdvo_panel_type, int, 0600);
  84. MODULE_PARM_DESC(vbt_sdvo_panel_type,
  85. "Override/Ignore selection of SDVO panel mode in the VBT "
  86. "(-2=ignore, -1=auto [default], index in VBT BIOS table)");
  87. static bool i915_try_reset __read_mostly = true;
  88. module_param_named(reset, i915_try_reset, bool, 0600);
  89. MODULE_PARM_DESC(reset, "Attempt GPU resets (default: true)");
  90. bool i915_enable_hangcheck __read_mostly = true;
  91. module_param_named(enable_hangcheck, i915_enable_hangcheck, bool, 0644);
  92. MODULE_PARM_DESC(enable_hangcheck,
  93. "Periodically check GPU activity for detecting hangs. "
  94. "WARNING: Disabling this can cause system wide hangs. "
  95. "(default: true)");
  96. bool i915_enable_ppgtt __read_mostly = 1;
  97. module_param_named(i915_enable_ppgtt, i915_enable_ppgtt, bool, 0600);
  98. MODULE_PARM_DESC(i915_enable_ppgtt,
  99. "Enable PPGTT (default: true)");
  100. static struct drm_driver driver;
  101. extern int intel_agp_enabled;
  102. #define INTEL_VGA_DEVICE(id, info) { \
  103. .class = PCI_BASE_CLASS_DISPLAY << 16, \
  104. .class_mask = 0xff0000, \
  105. .vendor = 0x8086, \
  106. .device = id, \
  107. .subvendor = PCI_ANY_ID, \
  108. .subdevice = PCI_ANY_ID, \
  109. .driver_data = (unsigned long) info }
  110. static const struct intel_device_info intel_i830_info = {
  111. .gen = 2, .is_mobile = 1, .cursor_needs_physical = 1,
  112. .has_overlay = 1, .overlay_needs_physical = 1,
  113. };
  114. static const struct intel_device_info intel_845g_info = {
  115. .gen = 2,
  116. .has_overlay = 1, .overlay_needs_physical = 1,
  117. };
  118. static const struct intel_device_info intel_i85x_info = {
  119. .gen = 2, .is_i85x = 1, .is_mobile = 1,
  120. .cursor_needs_physical = 1,
  121. .has_overlay = 1, .overlay_needs_physical = 1,
  122. };
  123. static const struct intel_device_info intel_i865g_info = {
  124. .gen = 2,
  125. .has_overlay = 1, .overlay_needs_physical = 1,
  126. };
  127. static const struct intel_device_info intel_i915g_info = {
  128. .gen = 3, .is_i915g = 1, .cursor_needs_physical = 1,
  129. .has_overlay = 1, .overlay_needs_physical = 1,
  130. };
  131. static const struct intel_device_info intel_i915gm_info = {
  132. .gen = 3, .is_mobile = 1,
  133. .cursor_needs_physical = 1,
  134. .has_overlay = 1, .overlay_needs_physical = 1,
  135. .supports_tv = 1,
  136. };
  137. static const struct intel_device_info intel_i945g_info = {
  138. .gen = 3, .has_hotplug = 1, .cursor_needs_physical = 1,
  139. .has_overlay = 1, .overlay_needs_physical = 1,
  140. };
  141. static const struct intel_device_info intel_i945gm_info = {
  142. .gen = 3, .is_i945gm = 1, .is_mobile = 1,
  143. .has_hotplug = 1, .cursor_needs_physical = 1,
  144. .has_overlay = 1, .overlay_needs_physical = 1,
  145. .supports_tv = 1,
  146. };
  147. static const struct intel_device_info intel_i965g_info = {
  148. .gen = 4, .is_broadwater = 1,
  149. .has_hotplug = 1,
  150. .has_overlay = 1,
  151. };
  152. static const struct intel_device_info intel_i965gm_info = {
  153. .gen = 4, .is_crestline = 1,
  154. .is_mobile = 1, .has_fbc = 1, .has_hotplug = 1,
  155. .has_overlay = 1,
  156. .supports_tv = 1,
  157. };
  158. static const struct intel_device_info intel_g33_info = {
  159. .gen = 3, .is_g33 = 1,
  160. .need_gfx_hws = 1, .has_hotplug = 1,
  161. .has_overlay = 1,
  162. };
  163. static const struct intel_device_info intel_g45_info = {
  164. .gen = 4, .is_g4x = 1, .need_gfx_hws = 1,
  165. .has_pipe_cxsr = 1, .has_hotplug = 1,
  166. .has_bsd_ring = 1,
  167. };
  168. static const struct intel_device_info intel_gm45_info = {
  169. .gen = 4, .is_g4x = 1,
  170. .is_mobile = 1, .need_gfx_hws = 1, .has_fbc = 1,
  171. .has_pipe_cxsr = 1, .has_hotplug = 1,
  172. .supports_tv = 1,
  173. .has_bsd_ring = 1,
  174. };
  175. static const struct intel_device_info intel_pineview_info = {
  176. .gen = 3, .is_g33 = 1, .is_pineview = 1, .is_mobile = 1,
  177. .need_gfx_hws = 1, .has_hotplug = 1,
  178. .has_overlay = 1,
  179. };
  180. static const struct intel_device_info intel_ironlake_d_info = {
  181. .gen = 5,
  182. .need_gfx_hws = 1, .has_hotplug = 1,
  183. .has_bsd_ring = 1,
  184. .has_pch_split = 1,
  185. };
  186. static const struct intel_device_info intel_ironlake_m_info = {
  187. .gen = 5, .is_mobile = 1,
  188. .need_gfx_hws = 1, .has_hotplug = 1,
  189. .has_fbc = 1,
  190. .has_bsd_ring = 1,
  191. .has_pch_split = 1,
  192. };
  193. static const struct intel_device_info intel_sandybridge_d_info = {
  194. .gen = 6,
  195. .need_gfx_hws = 1, .has_hotplug = 1,
  196. .has_bsd_ring = 1,
  197. .has_blt_ring = 1,
  198. .has_llc = 1,
  199. .has_pch_split = 1,
  200. };
  201. static const struct intel_device_info intel_sandybridge_m_info = {
  202. .gen = 6, .is_mobile = 1,
  203. .need_gfx_hws = 1, .has_hotplug = 1,
  204. .has_fbc = 1,
  205. .has_bsd_ring = 1,
  206. .has_blt_ring = 1,
  207. .has_llc = 1,
  208. .has_pch_split = 1,
  209. };
  210. static const struct intel_device_info intel_ivybridge_d_info = {
  211. .is_ivybridge = 1, .gen = 7,
  212. .need_gfx_hws = 1, .has_hotplug = 1,
  213. .has_bsd_ring = 1,
  214. .has_blt_ring = 1,
  215. .has_llc = 1,
  216. .has_pch_split = 1,
  217. };
  218. static const struct intel_device_info intel_ivybridge_m_info = {
  219. .is_ivybridge = 1, .gen = 7, .is_mobile = 1,
  220. .need_gfx_hws = 1, .has_hotplug = 1,
  221. .has_fbc = 0, /* FBC is not enabled on Ivybridge mobile yet */
  222. .has_bsd_ring = 1,
  223. .has_blt_ring = 1,
  224. .has_llc = 1,
  225. .has_pch_split = 1,
  226. };
  227. static const struct intel_device_info intel_valleyview_m_info = {
  228. .gen = 7, .is_mobile = 1,
  229. .need_gfx_hws = 1, .has_hotplug = 1,
  230. .has_fbc = 0,
  231. .has_bsd_ring = 1,
  232. .has_blt_ring = 1,
  233. .is_valleyview = 1,
  234. };
  235. static const struct intel_device_info intel_valleyview_d_info = {
  236. .gen = 7,
  237. .need_gfx_hws = 1, .has_hotplug = 1,
  238. .has_fbc = 0,
  239. .has_bsd_ring = 1,
  240. .has_blt_ring = 1,
  241. .is_valleyview = 1,
  242. };
  243. static const struct intel_device_info intel_haswell_d_info = {
  244. .is_haswell = 1, .gen = 7,
  245. .need_gfx_hws = 1, .has_hotplug = 1,
  246. .has_bsd_ring = 1,
  247. .has_blt_ring = 1,
  248. .has_llc = 1,
  249. .has_pch_split = 1,
  250. };
  251. static const struct intel_device_info intel_haswell_m_info = {
  252. .is_haswell = 1, .gen = 7, .is_mobile = 1,
  253. .need_gfx_hws = 1, .has_hotplug = 1,
  254. .has_bsd_ring = 1,
  255. .has_blt_ring = 1,
  256. .has_llc = 1,
  257. .has_pch_split = 1,
  258. };
  259. static const struct pci_device_id pciidlist[] = { /* aka */
  260. INTEL_VGA_DEVICE(0x3577, &intel_i830_info), /* I830_M */
  261. INTEL_VGA_DEVICE(0x2562, &intel_845g_info), /* 845_G */
  262. INTEL_VGA_DEVICE(0x3582, &intel_i85x_info), /* I855_GM */
  263. INTEL_VGA_DEVICE(0x358e, &intel_i85x_info),
  264. INTEL_VGA_DEVICE(0x2572, &intel_i865g_info), /* I865_G */
  265. INTEL_VGA_DEVICE(0x2582, &intel_i915g_info), /* I915_G */
  266. INTEL_VGA_DEVICE(0x258a, &intel_i915g_info), /* E7221_G */
  267. INTEL_VGA_DEVICE(0x2592, &intel_i915gm_info), /* I915_GM */
  268. INTEL_VGA_DEVICE(0x2772, &intel_i945g_info), /* I945_G */
  269. INTEL_VGA_DEVICE(0x27a2, &intel_i945gm_info), /* I945_GM */
  270. INTEL_VGA_DEVICE(0x27ae, &intel_i945gm_info), /* I945_GME */
  271. INTEL_VGA_DEVICE(0x2972, &intel_i965g_info), /* I946_GZ */
  272. INTEL_VGA_DEVICE(0x2982, &intel_i965g_info), /* G35_G */
  273. INTEL_VGA_DEVICE(0x2992, &intel_i965g_info), /* I965_Q */
  274. INTEL_VGA_DEVICE(0x29a2, &intel_i965g_info), /* I965_G */
  275. INTEL_VGA_DEVICE(0x29b2, &intel_g33_info), /* Q35_G */
  276. INTEL_VGA_DEVICE(0x29c2, &intel_g33_info), /* G33_G */
  277. INTEL_VGA_DEVICE(0x29d2, &intel_g33_info), /* Q33_G */
  278. INTEL_VGA_DEVICE(0x2a02, &intel_i965gm_info), /* I965_GM */
  279. INTEL_VGA_DEVICE(0x2a12, &intel_i965gm_info), /* I965_GME */
  280. INTEL_VGA_DEVICE(0x2a42, &intel_gm45_info), /* GM45_G */
  281. INTEL_VGA_DEVICE(0x2e02, &intel_g45_info), /* IGD_E_G */
  282. INTEL_VGA_DEVICE(0x2e12, &intel_g45_info), /* Q45_G */
  283. INTEL_VGA_DEVICE(0x2e22, &intel_g45_info), /* G45_G */
  284. INTEL_VGA_DEVICE(0x2e32, &intel_g45_info), /* G41_G */
  285. INTEL_VGA_DEVICE(0x2e42, &intel_g45_info), /* B43_G */
  286. INTEL_VGA_DEVICE(0x2e92, &intel_g45_info), /* B43_G.1 */
  287. INTEL_VGA_DEVICE(0xa001, &intel_pineview_info),
  288. INTEL_VGA_DEVICE(0xa011, &intel_pineview_info),
  289. INTEL_VGA_DEVICE(0x0042, &intel_ironlake_d_info),
  290. INTEL_VGA_DEVICE(0x0046, &intel_ironlake_m_info),
  291. INTEL_VGA_DEVICE(0x0102, &intel_sandybridge_d_info),
  292. INTEL_VGA_DEVICE(0x0112, &intel_sandybridge_d_info),
  293. INTEL_VGA_DEVICE(0x0122, &intel_sandybridge_d_info),
  294. INTEL_VGA_DEVICE(0x0106, &intel_sandybridge_m_info),
  295. INTEL_VGA_DEVICE(0x0116, &intel_sandybridge_m_info),
  296. INTEL_VGA_DEVICE(0x0126, &intel_sandybridge_m_info),
  297. INTEL_VGA_DEVICE(0x010A, &intel_sandybridge_d_info),
  298. INTEL_VGA_DEVICE(0x0156, &intel_ivybridge_m_info), /* GT1 mobile */
  299. INTEL_VGA_DEVICE(0x0166, &intel_ivybridge_m_info), /* GT2 mobile */
  300. INTEL_VGA_DEVICE(0x0152, &intel_ivybridge_d_info), /* GT1 desktop */
  301. INTEL_VGA_DEVICE(0x0162, &intel_ivybridge_d_info), /* GT2 desktop */
  302. INTEL_VGA_DEVICE(0x015a, &intel_ivybridge_d_info), /* GT1 server */
  303. {0, 0, 0}
  304. };
  305. #if defined(CONFIG_DRM_I915_KMS)
  306. MODULE_DEVICE_TABLE(pci, pciidlist);
  307. #endif
  308. #define INTEL_PCH_DEVICE_ID_MASK 0xff00
  309. #define INTEL_PCH_IBX_DEVICE_ID_TYPE 0x3b00
  310. #define INTEL_PCH_CPT_DEVICE_ID_TYPE 0x1c00
  311. #define INTEL_PCH_PPT_DEVICE_ID_TYPE 0x1e00
  312. #define INTEL_PCH_LPT_DEVICE_ID_TYPE 0x8c00
  313. void intel_detect_pch(struct drm_device *dev)
  314. {
  315. struct drm_i915_private *dev_priv = dev->dev_private;
  316. struct pci_dev *pch;
  317. /*
  318. * The reason to probe ISA bridge instead of Dev31:Fun0 is to
  319. * make graphics device passthrough work easy for VMM, that only
  320. * need to expose ISA bridge to let driver know the real hardware
  321. * underneath. This is a requirement from virtualization team.
  322. */
  323. pch = pci_get_class(PCI_CLASS_BRIDGE_ISA << 8, NULL);
  324. if (pch) {
  325. if (pch->vendor == PCI_VENDOR_ID_INTEL) {
  326. int id;
  327. id = pch->device & INTEL_PCH_DEVICE_ID_MASK;
  328. if (id == INTEL_PCH_IBX_DEVICE_ID_TYPE) {
  329. dev_priv->pch_type = PCH_IBX;
  330. DRM_DEBUG_KMS("Found Ibex Peak PCH\n");
  331. } else if (id == INTEL_PCH_CPT_DEVICE_ID_TYPE) {
  332. dev_priv->pch_type = PCH_CPT;
  333. DRM_DEBUG_KMS("Found CougarPoint PCH\n");
  334. } else if (id == INTEL_PCH_PPT_DEVICE_ID_TYPE) {
  335. /* PantherPoint is CPT compatible */
  336. dev_priv->pch_type = PCH_CPT;
  337. DRM_DEBUG_KMS("Found PatherPoint PCH\n");
  338. } else if (id == INTEL_PCH_LPT_DEVICE_ID_TYPE) {
  339. dev_priv->pch_type = PCH_LPT;
  340. DRM_DEBUG_KMS("Found LynxPoint PCH\n");
  341. }
  342. }
  343. pci_dev_put(pch);
  344. }
  345. }
  346. void __gen6_gt_force_wake_get(struct drm_i915_private *dev_priv)
  347. {
  348. int count;
  349. count = 0;
  350. while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
  351. udelay(10);
  352. I915_WRITE_NOTRACE(FORCEWAKE, 1);
  353. POSTING_READ(FORCEWAKE);
  354. count = 0;
  355. while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1) == 0)
  356. udelay(10);
  357. }
  358. void __gen6_gt_force_wake_mt_get(struct drm_i915_private *dev_priv)
  359. {
  360. int count;
  361. count = 0;
  362. while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_MT_ACK) & 1))
  363. udelay(10);
  364. I915_WRITE_NOTRACE(FORCEWAKE_MT, (1<<16) | 1);
  365. POSTING_READ(FORCEWAKE_MT);
  366. count = 0;
  367. while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_MT_ACK) & 1) == 0)
  368. udelay(10);
  369. }
  370. /*
  371. * Generally this is called implicitly by the register read function. However,
  372. * if some sequence requires the GT to not power down then this function should
  373. * be called at the beginning of the sequence followed by a call to
  374. * gen6_gt_force_wake_put() at the end of the sequence.
  375. */
  376. void gen6_gt_force_wake_get(struct drm_i915_private *dev_priv)
  377. {
  378. unsigned long irqflags;
  379. spin_lock_irqsave(&dev_priv->gt_lock, irqflags);
  380. if (dev_priv->forcewake_count++ == 0)
  381. dev_priv->display.force_wake_get(dev_priv);
  382. spin_unlock_irqrestore(&dev_priv->gt_lock, irqflags);
  383. }
  384. static void gen6_gt_check_fifodbg(struct drm_i915_private *dev_priv)
  385. {
  386. u32 gtfifodbg;
  387. gtfifodbg = I915_READ_NOTRACE(GTFIFODBG);
  388. if (WARN(gtfifodbg & GT_FIFO_CPU_ERROR_MASK,
  389. "MMIO read or write has been dropped %x\n", gtfifodbg))
  390. I915_WRITE_NOTRACE(GTFIFODBG, GT_FIFO_CPU_ERROR_MASK);
  391. }
  392. void __gen6_gt_force_wake_put(struct drm_i915_private *dev_priv)
  393. {
  394. I915_WRITE_NOTRACE(FORCEWAKE, 0);
  395. /* The below doubles as a POSTING_READ */
  396. gen6_gt_check_fifodbg(dev_priv);
  397. }
  398. void __gen6_gt_force_wake_mt_put(struct drm_i915_private *dev_priv)
  399. {
  400. I915_WRITE_NOTRACE(FORCEWAKE_MT, (1<<16) | 0);
  401. /* The below doubles as a POSTING_READ */
  402. gen6_gt_check_fifodbg(dev_priv);
  403. }
  404. /*
  405. * see gen6_gt_force_wake_get()
  406. */
  407. void gen6_gt_force_wake_put(struct drm_i915_private *dev_priv)
  408. {
  409. unsigned long irqflags;
  410. spin_lock_irqsave(&dev_priv->gt_lock, irqflags);
  411. if (--dev_priv->forcewake_count == 0)
  412. dev_priv->display.force_wake_put(dev_priv);
  413. spin_unlock_irqrestore(&dev_priv->gt_lock, irqflags);
  414. }
  415. int __gen6_gt_wait_for_fifo(struct drm_i915_private *dev_priv)
  416. {
  417. int ret = 0;
  418. if (dev_priv->gt_fifo_count < GT_FIFO_NUM_RESERVED_ENTRIES) {
  419. int loop = 500;
  420. u32 fifo = I915_READ_NOTRACE(GT_FIFO_FREE_ENTRIES);
  421. while (fifo <= GT_FIFO_NUM_RESERVED_ENTRIES && loop--) {
  422. udelay(10);
  423. fifo = I915_READ_NOTRACE(GT_FIFO_FREE_ENTRIES);
  424. }
  425. if (WARN_ON(loop < 0 && fifo <= GT_FIFO_NUM_RESERVED_ENTRIES))
  426. ++ret;
  427. dev_priv->gt_fifo_count = fifo;
  428. }
  429. dev_priv->gt_fifo_count--;
  430. return ret;
  431. }
  432. void vlv_force_wake_get(struct drm_i915_private *dev_priv)
  433. {
  434. int count;
  435. count = 0;
  436. /* Already awake? */
  437. if ((I915_READ(0x130094) & 0xa1) == 0xa1)
  438. return;
  439. I915_WRITE_NOTRACE(FORCEWAKE_VLV, 0xffffffff);
  440. POSTING_READ(FORCEWAKE_VLV);
  441. count = 0;
  442. while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK_VLV) & 1) == 0)
  443. udelay(10);
  444. }
  445. void vlv_force_wake_put(struct drm_i915_private *dev_priv)
  446. {
  447. I915_WRITE_NOTRACE(FORCEWAKE_VLV, 0xffff0000);
  448. /* FIXME: confirm VLV behavior with Punit folks */
  449. POSTING_READ(FORCEWAKE_VLV);
  450. }
  451. static int i915_drm_freeze(struct drm_device *dev)
  452. {
  453. struct drm_i915_private *dev_priv = dev->dev_private;
  454. drm_kms_helper_poll_disable(dev);
  455. pci_save_state(dev->pdev);
  456. /* If KMS is active, we do the leavevt stuff here */
  457. if (drm_core_check_feature(dev, DRIVER_MODESET)) {
  458. int error = i915_gem_idle(dev);
  459. if (error) {
  460. dev_err(&dev->pdev->dev,
  461. "GEM idle failed, resume might fail\n");
  462. return error;
  463. }
  464. drm_irq_uninstall(dev);
  465. }
  466. i915_save_state(dev);
  467. intel_opregion_fini(dev);
  468. /* Modeset on resume, not lid events */
  469. dev_priv->modeset_on_lid = 0;
  470. return 0;
  471. }
  472. int i915_suspend(struct drm_device *dev, pm_message_t state)
  473. {
  474. int error;
  475. if (!dev || !dev->dev_private) {
  476. DRM_ERROR("dev: %p\n", dev);
  477. DRM_ERROR("DRM not initialized, aborting suspend.\n");
  478. return -ENODEV;
  479. }
  480. if (state.event == PM_EVENT_PRETHAW)
  481. return 0;
  482. if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
  483. return 0;
  484. error = i915_drm_freeze(dev);
  485. if (error)
  486. return error;
  487. if (state.event == PM_EVENT_SUSPEND) {
  488. /* Shut down the device */
  489. pci_disable_device(dev->pdev);
  490. pci_set_power_state(dev->pdev, PCI_D3hot);
  491. }
  492. return 0;
  493. }
  494. static int i915_drm_thaw(struct drm_device *dev)
  495. {
  496. struct drm_i915_private *dev_priv = dev->dev_private;
  497. int error = 0;
  498. if (drm_core_check_feature(dev, DRIVER_MODESET)) {
  499. mutex_lock(&dev->struct_mutex);
  500. i915_gem_restore_gtt_mappings(dev);
  501. mutex_unlock(&dev->struct_mutex);
  502. }
  503. i915_restore_state(dev);
  504. intel_opregion_setup(dev);
  505. /* KMS EnterVT equivalent */
  506. if (drm_core_check_feature(dev, DRIVER_MODESET)) {
  507. mutex_lock(&dev->struct_mutex);
  508. dev_priv->mm.suspended = 0;
  509. error = i915_gem_init_hw(dev);
  510. mutex_unlock(&dev->struct_mutex);
  511. if (HAS_PCH_SPLIT(dev))
  512. ironlake_init_pch_refclk(dev);
  513. drm_mode_config_reset(dev);
  514. drm_irq_install(dev);
  515. /* Resume the modeset for every activated CRTC */
  516. drm_helper_resume_force_mode(dev);
  517. if (IS_IRONLAKE_M(dev))
  518. ironlake_enable_rc6(dev);
  519. }
  520. intel_opregion_init(dev);
  521. dev_priv->modeset_on_lid = 0;
  522. return error;
  523. }
  524. int i915_resume(struct drm_device *dev)
  525. {
  526. int ret;
  527. if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
  528. return 0;
  529. if (pci_enable_device(dev->pdev))
  530. return -EIO;
  531. pci_set_master(dev->pdev);
  532. ret = i915_drm_thaw(dev);
  533. if (ret)
  534. return ret;
  535. drm_kms_helper_poll_enable(dev);
  536. return 0;
  537. }
  538. static int i8xx_do_reset(struct drm_device *dev, u8 flags)
  539. {
  540. struct drm_i915_private *dev_priv = dev->dev_private;
  541. if (IS_I85X(dev))
  542. return -ENODEV;
  543. I915_WRITE(D_STATE, I915_READ(D_STATE) | DSTATE_GFX_RESET_I830);
  544. POSTING_READ(D_STATE);
  545. if (IS_I830(dev) || IS_845G(dev)) {
  546. I915_WRITE(DEBUG_RESET_I830,
  547. DEBUG_RESET_DISPLAY |
  548. DEBUG_RESET_RENDER |
  549. DEBUG_RESET_FULL);
  550. POSTING_READ(DEBUG_RESET_I830);
  551. msleep(1);
  552. I915_WRITE(DEBUG_RESET_I830, 0);
  553. POSTING_READ(DEBUG_RESET_I830);
  554. }
  555. msleep(1);
  556. I915_WRITE(D_STATE, I915_READ(D_STATE) & ~DSTATE_GFX_RESET_I830);
  557. POSTING_READ(D_STATE);
  558. return 0;
  559. }
  560. static int i965_reset_complete(struct drm_device *dev)
  561. {
  562. u8 gdrst;
  563. pci_read_config_byte(dev->pdev, I965_GDRST, &gdrst);
  564. return gdrst & 0x1;
  565. }
  566. static int i965_do_reset(struct drm_device *dev, u8 flags)
  567. {
  568. u8 gdrst;
  569. /*
  570. * Set the domains we want to reset (GRDOM/bits 2 and 3) as
  571. * well as the reset bit (GR/bit 0). Setting the GR bit
  572. * triggers the reset; when done, the hardware will clear it.
  573. */
  574. pci_read_config_byte(dev->pdev, I965_GDRST, &gdrst);
  575. pci_write_config_byte(dev->pdev, I965_GDRST, gdrst | flags | 0x1);
  576. return wait_for(i965_reset_complete(dev), 500);
  577. }
  578. static int ironlake_do_reset(struct drm_device *dev, u8 flags)
  579. {
  580. struct drm_i915_private *dev_priv = dev->dev_private;
  581. u32 gdrst = I915_READ(MCHBAR_MIRROR_BASE + ILK_GDSR);
  582. I915_WRITE(MCHBAR_MIRROR_BASE + ILK_GDSR, gdrst | flags | 0x1);
  583. return wait_for(I915_READ(MCHBAR_MIRROR_BASE + ILK_GDSR) & 0x1, 500);
  584. }
  585. static int gen6_do_reset(struct drm_device *dev, u8 flags)
  586. {
  587. struct drm_i915_private *dev_priv = dev->dev_private;
  588. int ret;
  589. unsigned long irqflags;
  590. /* Hold gt_lock across reset to prevent any register access
  591. * with forcewake not set correctly
  592. */
  593. spin_lock_irqsave(&dev_priv->gt_lock, irqflags);
  594. /* Reset the chip */
  595. /* GEN6_GDRST is not in the gt power well, no need to check
  596. * for fifo space for the write or forcewake the chip for
  597. * the read
  598. */
  599. I915_WRITE_NOTRACE(GEN6_GDRST, GEN6_GRDOM_FULL);
  600. /* Spin waiting for the device to ack the reset request */
  601. ret = wait_for((I915_READ_NOTRACE(GEN6_GDRST) & GEN6_GRDOM_FULL) == 0, 500);
  602. /* If reset with a user forcewake, try to restore, otherwise turn it off */
  603. if (dev_priv->forcewake_count)
  604. dev_priv->display.force_wake_get(dev_priv);
  605. else
  606. dev_priv->display.force_wake_put(dev_priv);
  607. /* Restore fifo count */
  608. dev_priv->gt_fifo_count = I915_READ_NOTRACE(GT_FIFO_FREE_ENTRIES);
  609. spin_unlock_irqrestore(&dev_priv->gt_lock, irqflags);
  610. return ret;
  611. }
  612. /**
  613. * i915_reset - reset chip after a hang
  614. * @dev: drm device to reset
  615. * @flags: reset domains
  616. *
  617. * Reset the chip. Useful if a hang is detected. Returns zero on successful
  618. * reset or otherwise an error code.
  619. *
  620. * Procedure is fairly simple:
  621. * - reset the chip using the reset reg
  622. * - re-init context state
  623. * - re-init hardware status page
  624. * - re-init ring buffer
  625. * - re-init interrupt state
  626. * - re-init display
  627. */
  628. int i915_reset(struct drm_device *dev, u8 flags)
  629. {
  630. drm_i915_private_t *dev_priv = dev->dev_private;
  631. /*
  632. * We really should only reset the display subsystem if we actually
  633. * need to
  634. */
  635. bool need_display = true;
  636. int ret;
  637. if (!i915_try_reset)
  638. return 0;
  639. if (!mutex_trylock(&dev->struct_mutex))
  640. return -EBUSY;
  641. i915_gem_reset(dev);
  642. ret = -ENODEV;
  643. if (get_seconds() - dev_priv->last_gpu_reset < 5) {
  644. DRM_ERROR("GPU hanging too fast, declaring wedged!\n");
  645. } else switch (INTEL_INFO(dev)->gen) {
  646. case 7:
  647. case 6:
  648. ret = gen6_do_reset(dev, flags);
  649. break;
  650. case 5:
  651. ret = ironlake_do_reset(dev, flags);
  652. break;
  653. case 4:
  654. ret = i965_do_reset(dev, flags);
  655. break;
  656. case 2:
  657. ret = i8xx_do_reset(dev, flags);
  658. break;
  659. }
  660. dev_priv->last_gpu_reset = get_seconds();
  661. if (ret) {
  662. DRM_ERROR("Failed to reset chip.\n");
  663. mutex_unlock(&dev->struct_mutex);
  664. return ret;
  665. }
  666. /* Ok, now get things going again... */
  667. /*
  668. * Everything depends on having the GTT running, so we need to start
  669. * there. Fortunately we don't need to do this unless we reset the
  670. * chip at a PCI level.
  671. *
  672. * Next we need to restore the context, but we don't use those
  673. * yet either...
  674. *
  675. * Ring buffer needs to be re-initialized in the KMS case, or if X
  676. * was running at the time of the reset (i.e. we weren't VT
  677. * switched away).
  678. */
  679. if (drm_core_check_feature(dev, DRIVER_MODESET) ||
  680. !dev_priv->mm.suspended) {
  681. dev_priv->mm.suspended = 0;
  682. i915_gem_init_swizzling(dev);
  683. dev_priv->ring[RCS].init(&dev_priv->ring[RCS]);
  684. if (HAS_BSD(dev))
  685. dev_priv->ring[VCS].init(&dev_priv->ring[VCS]);
  686. if (HAS_BLT(dev))
  687. dev_priv->ring[BCS].init(&dev_priv->ring[BCS]);
  688. i915_gem_init_ppgtt(dev);
  689. mutex_unlock(&dev->struct_mutex);
  690. drm_irq_uninstall(dev);
  691. drm_mode_config_reset(dev);
  692. drm_irq_install(dev);
  693. mutex_lock(&dev->struct_mutex);
  694. }
  695. mutex_unlock(&dev->struct_mutex);
  696. /*
  697. * Perform a full modeset as on later generations, e.g. Ironlake, we may
  698. * need to retrain the display link and cannot just restore the register
  699. * values.
  700. */
  701. if (need_display) {
  702. mutex_lock(&dev->mode_config.mutex);
  703. drm_helper_resume_force_mode(dev);
  704. mutex_unlock(&dev->mode_config.mutex);
  705. }
  706. return 0;
  707. }
  708. static int __devinit
  709. i915_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  710. {
  711. /* Only bind to function 0 of the device. Early generations
  712. * used function 1 as a placeholder for multi-head. This causes
  713. * us confusion instead, especially on the systems where both
  714. * functions have the same PCI-ID!
  715. */
  716. if (PCI_FUNC(pdev->devfn))
  717. return -ENODEV;
  718. return drm_get_pci_dev(pdev, ent, &driver);
  719. }
  720. static void
  721. i915_pci_remove(struct pci_dev *pdev)
  722. {
  723. struct drm_device *dev = pci_get_drvdata(pdev);
  724. drm_put_dev(dev);
  725. }
  726. static int i915_pm_suspend(struct device *dev)
  727. {
  728. struct pci_dev *pdev = to_pci_dev(dev);
  729. struct drm_device *drm_dev = pci_get_drvdata(pdev);
  730. int error;
  731. if (!drm_dev || !drm_dev->dev_private) {
  732. dev_err(dev, "DRM not initialized, aborting suspend.\n");
  733. return -ENODEV;
  734. }
  735. if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF)
  736. return 0;
  737. error = i915_drm_freeze(drm_dev);
  738. if (error)
  739. return error;
  740. pci_disable_device(pdev);
  741. pci_set_power_state(pdev, PCI_D3hot);
  742. return 0;
  743. }
  744. static int i915_pm_resume(struct device *dev)
  745. {
  746. struct pci_dev *pdev = to_pci_dev(dev);
  747. struct drm_device *drm_dev = pci_get_drvdata(pdev);
  748. return i915_resume(drm_dev);
  749. }
  750. static int i915_pm_freeze(struct device *dev)
  751. {
  752. struct pci_dev *pdev = to_pci_dev(dev);
  753. struct drm_device *drm_dev = pci_get_drvdata(pdev);
  754. if (!drm_dev || !drm_dev->dev_private) {
  755. dev_err(dev, "DRM not initialized, aborting suspend.\n");
  756. return -ENODEV;
  757. }
  758. return i915_drm_freeze(drm_dev);
  759. }
  760. static int i915_pm_thaw(struct device *dev)
  761. {
  762. struct pci_dev *pdev = to_pci_dev(dev);
  763. struct drm_device *drm_dev = pci_get_drvdata(pdev);
  764. return i915_drm_thaw(drm_dev);
  765. }
  766. static int i915_pm_poweroff(struct device *dev)
  767. {
  768. struct pci_dev *pdev = to_pci_dev(dev);
  769. struct drm_device *drm_dev = pci_get_drvdata(pdev);
  770. return i915_drm_freeze(drm_dev);
  771. }
  772. static const struct dev_pm_ops i915_pm_ops = {
  773. .suspend = i915_pm_suspend,
  774. .resume = i915_pm_resume,
  775. .freeze = i915_pm_freeze,
  776. .thaw = i915_pm_thaw,
  777. .poweroff = i915_pm_poweroff,
  778. .restore = i915_pm_resume,
  779. };
  780. static struct vm_operations_struct i915_gem_vm_ops = {
  781. .fault = i915_gem_fault,
  782. .open = drm_gem_vm_open,
  783. .close = drm_gem_vm_close,
  784. };
  785. static const struct file_operations i915_driver_fops = {
  786. .owner = THIS_MODULE,
  787. .open = drm_open,
  788. .release = drm_release,
  789. .unlocked_ioctl = drm_ioctl,
  790. .mmap = drm_gem_mmap,
  791. .poll = drm_poll,
  792. .fasync = drm_fasync,
  793. .read = drm_read,
  794. #ifdef CONFIG_COMPAT
  795. .compat_ioctl = i915_compat_ioctl,
  796. #endif
  797. .llseek = noop_llseek,
  798. };
  799. static struct drm_driver driver = {
  800. /* Don't use MTRRs here; the Xserver or userspace app should
  801. * deal with them for Intel hardware.
  802. */
  803. .driver_features =
  804. DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | /* DRIVER_USE_MTRR |*/
  805. DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_GEM,
  806. .load = i915_driver_load,
  807. .unload = i915_driver_unload,
  808. .open = i915_driver_open,
  809. .lastclose = i915_driver_lastclose,
  810. .preclose = i915_driver_preclose,
  811. .postclose = i915_driver_postclose,
  812. /* Used in place of i915_pm_ops for non-DRIVER_MODESET */
  813. .suspend = i915_suspend,
  814. .resume = i915_resume,
  815. .device_is_agp = i915_driver_device_is_agp,
  816. .reclaim_buffers = drm_core_reclaim_buffers,
  817. .master_create = i915_master_create,
  818. .master_destroy = i915_master_destroy,
  819. #if defined(CONFIG_DEBUG_FS)
  820. .debugfs_init = i915_debugfs_init,
  821. .debugfs_cleanup = i915_debugfs_cleanup,
  822. #endif
  823. .gem_init_object = i915_gem_init_object,
  824. .gem_free_object = i915_gem_free_object,
  825. .gem_vm_ops = &i915_gem_vm_ops,
  826. .dumb_create = i915_gem_dumb_create,
  827. .dumb_map_offset = i915_gem_mmap_gtt,
  828. .dumb_destroy = i915_gem_dumb_destroy,
  829. .ioctls = i915_ioctls,
  830. .fops = &i915_driver_fops,
  831. .name = DRIVER_NAME,
  832. .desc = DRIVER_DESC,
  833. .date = DRIVER_DATE,
  834. .major = DRIVER_MAJOR,
  835. .minor = DRIVER_MINOR,
  836. .patchlevel = DRIVER_PATCHLEVEL,
  837. };
  838. static struct pci_driver i915_pci_driver = {
  839. .name = DRIVER_NAME,
  840. .id_table = pciidlist,
  841. .probe = i915_pci_probe,
  842. .remove = i915_pci_remove,
  843. .driver.pm = &i915_pm_ops,
  844. };
  845. static int __init i915_init(void)
  846. {
  847. if (!intel_agp_enabled) {
  848. DRM_ERROR("drm/i915 can't work without intel_agp module!\n");
  849. return -ENODEV;
  850. }
  851. driver.num_ioctls = i915_max_ioctl;
  852. /*
  853. * If CONFIG_DRM_I915_KMS is set, default to KMS unless
  854. * explicitly disabled with the module pararmeter.
  855. *
  856. * Otherwise, just follow the parameter (defaulting to off).
  857. *
  858. * Allow optional vga_text_mode_force boot option to override
  859. * the default behavior.
  860. */
  861. #if defined(CONFIG_DRM_I915_KMS)
  862. if (i915_modeset != 0)
  863. driver.driver_features |= DRIVER_MODESET;
  864. #endif
  865. if (i915_modeset == 1)
  866. driver.driver_features |= DRIVER_MODESET;
  867. #ifdef CONFIG_VGA_CONSOLE
  868. if (vgacon_text_force() && i915_modeset == -1)
  869. driver.driver_features &= ~DRIVER_MODESET;
  870. #endif
  871. if (!(driver.driver_features & DRIVER_MODESET))
  872. driver.get_vblank_timestamp = NULL;
  873. return drm_pci_init(&driver, &i915_pci_driver);
  874. }
  875. static void __exit i915_exit(void)
  876. {
  877. drm_pci_exit(&driver, &i915_pci_driver);
  878. }
  879. module_init(i915_init);
  880. module_exit(i915_exit);
  881. MODULE_AUTHOR(DRIVER_AUTHOR);
  882. MODULE_DESCRIPTION(DRIVER_DESC);
  883. MODULE_LICENSE("GPL and additional rights");
  884. /* We give fast paths for the really cool registers */
  885. #define NEEDS_FORCE_WAKE(dev_priv, reg) \
  886. (((dev_priv)->info->gen >= 6) && \
  887. ((reg) < 0x40000) && \
  888. ((reg) != FORCEWAKE)) && \
  889. (!IS_VALLEYVIEW((dev_priv)->dev))
  890. #define __i915_read(x, y) \
  891. u##x i915_read##x(struct drm_i915_private *dev_priv, u32 reg) { \
  892. u##x val = 0; \
  893. if (NEEDS_FORCE_WAKE((dev_priv), (reg))) { \
  894. unsigned long irqflags; \
  895. spin_lock_irqsave(&dev_priv->gt_lock, irqflags); \
  896. if (dev_priv->forcewake_count == 0) \
  897. dev_priv->display.force_wake_get(dev_priv); \
  898. val = read##y(dev_priv->regs + reg); \
  899. if (dev_priv->forcewake_count == 0) \
  900. dev_priv->display.force_wake_put(dev_priv); \
  901. spin_unlock_irqrestore(&dev_priv->gt_lock, irqflags); \
  902. } else { \
  903. val = read##y(dev_priv->regs + reg); \
  904. } \
  905. trace_i915_reg_rw(false, reg, val, sizeof(val)); \
  906. return val; \
  907. }
  908. __i915_read(8, b)
  909. __i915_read(16, w)
  910. __i915_read(32, l)
  911. __i915_read(64, q)
  912. #undef __i915_read
  913. #define __i915_write(x, y) \
  914. void i915_write##x(struct drm_i915_private *dev_priv, u32 reg, u##x val) { \
  915. u32 __fifo_ret = 0; \
  916. trace_i915_reg_rw(true, reg, val, sizeof(val)); \
  917. if (NEEDS_FORCE_WAKE((dev_priv), (reg))) { \
  918. __fifo_ret = __gen6_gt_wait_for_fifo(dev_priv); \
  919. } \
  920. write##y(val, dev_priv->regs + reg); \
  921. if (unlikely(__fifo_ret)) { \
  922. gen6_gt_check_fifodbg(dev_priv); \
  923. } \
  924. }
  925. __i915_write(8, b)
  926. __i915_write(16, w)
  927. __i915_write(32, l)
  928. __i915_write(64, q)
  929. #undef __i915_write