i915_drv.c 24 KB

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