i915_drv.c 19 KB

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