i915_drv.c 21 KB

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