i915_drv.c 21 KB

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