i915_drv.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663
  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 <linux/acpi.h>
  31. #include <drm/drmP.h>
  32. #include <drm/i915_drm.h>
  33. #include "i915_drv.h"
  34. #include "i915_trace.h"
  35. #include "intel_drv.h"
  36. #include <linux/console.h>
  37. #include <linux/module.h>
  38. #include <linux/pm_runtime.h>
  39. #include <drm/drm_crtc_helper.h>
  40. static struct drm_driver driver;
  41. #define GEN_DEFAULT_PIPEOFFSETS \
  42. .pipe_offsets = { PIPE_A_OFFSET, PIPE_B_OFFSET, \
  43. PIPE_C_OFFSET, PIPE_EDP_OFFSET }, \
  44. .trans_offsets = { TRANSCODER_A_OFFSET, TRANSCODER_B_OFFSET, \
  45. TRANSCODER_C_OFFSET, TRANSCODER_EDP_OFFSET }, \
  46. .palette_offsets = { PALETTE_A_OFFSET, PALETTE_B_OFFSET }
  47. #define GEN_CHV_PIPEOFFSETS \
  48. .pipe_offsets = { PIPE_A_OFFSET, PIPE_B_OFFSET, \
  49. CHV_PIPE_C_OFFSET }, \
  50. .trans_offsets = { TRANSCODER_A_OFFSET, TRANSCODER_B_OFFSET, \
  51. CHV_TRANSCODER_C_OFFSET, }, \
  52. .palette_offsets = { PALETTE_A_OFFSET, PALETTE_B_OFFSET, \
  53. CHV_PALETTE_C_OFFSET }
  54. #define CURSOR_OFFSETS \
  55. .cursor_offsets = { CURSOR_A_OFFSET, CURSOR_B_OFFSET, CHV_CURSOR_C_OFFSET }
  56. #define IVB_CURSOR_OFFSETS \
  57. .cursor_offsets = { CURSOR_A_OFFSET, IVB_CURSOR_B_OFFSET, IVB_CURSOR_C_OFFSET }
  58. static const struct intel_device_info intel_i830_info = {
  59. .gen = 2, .is_mobile = 1, .cursor_needs_physical = 1, .num_pipes = 2,
  60. .has_overlay = 1, .overlay_needs_physical = 1,
  61. .ring_mask = RENDER_RING,
  62. GEN_DEFAULT_PIPEOFFSETS,
  63. CURSOR_OFFSETS,
  64. };
  65. static const struct intel_device_info intel_845g_info = {
  66. .gen = 2, .num_pipes = 1,
  67. .has_overlay = 1, .overlay_needs_physical = 1,
  68. .ring_mask = RENDER_RING,
  69. GEN_DEFAULT_PIPEOFFSETS,
  70. CURSOR_OFFSETS,
  71. };
  72. static const struct intel_device_info intel_i85x_info = {
  73. .gen = 2, .is_i85x = 1, .is_mobile = 1, .num_pipes = 2,
  74. .cursor_needs_physical = 1,
  75. .has_overlay = 1, .overlay_needs_physical = 1,
  76. .has_fbc = 1,
  77. .ring_mask = RENDER_RING,
  78. GEN_DEFAULT_PIPEOFFSETS,
  79. CURSOR_OFFSETS,
  80. };
  81. static const struct intel_device_info intel_i865g_info = {
  82. .gen = 2, .num_pipes = 1,
  83. .has_overlay = 1, .overlay_needs_physical = 1,
  84. .ring_mask = RENDER_RING,
  85. GEN_DEFAULT_PIPEOFFSETS,
  86. CURSOR_OFFSETS,
  87. };
  88. static const struct intel_device_info intel_i915g_info = {
  89. .gen = 3, .is_i915g = 1, .cursor_needs_physical = 1, .num_pipes = 2,
  90. .has_overlay = 1, .overlay_needs_physical = 1,
  91. .ring_mask = RENDER_RING,
  92. GEN_DEFAULT_PIPEOFFSETS,
  93. CURSOR_OFFSETS,
  94. };
  95. static const struct intel_device_info intel_i915gm_info = {
  96. .gen = 3, .is_mobile = 1, .num_pipes = 2,
  97. .cursor_needs_physical = 1,
  98. .has_overlay = 1, .overlay_needs_physical = 1,
  99. .supports_tv = 1,
  100. .has_fbc = 1,
  101. .ring_mask = RENDER_RING,
  102. GEN_DEFAULT_PIPEOFFSETS,
  103. CURSOR_OFFSETS,
  104. };
  105. static const struct intel_device_info intel_i945g_info = {
  106. .gen = 3, .has_hotplug = 1, .cursor_needs_physical = 1, .num_pipes = 2,
  107. .has_overlay = 1, .overlay_needs_physical = 1,
  108. .ring_mask = RENDER_RING,
  109. GEN_DEFAULT_PIPEOFFSETS,
  110. CURSOR_OFFSETS,
  111. };
  112. static const struct intel_device_info intel_i945gm_info = {
  113. .gen = 3, .is_i945gm = 1, .is_mobile = 1, .num_pipes = 2,
  114. .has_hotplug = 1, .cursor_needs_physical = 1,
  115. .has_overlay = 1, .overlay_needs_physical = 1,
  116. .supports_tv = 1,
  117. .has_fbc = 1,
  118. .ring_mask = RENDER_RING,
  119. GEN_DEFAULT_PIPEOFFSETS,
  120. CURSOR_OFFSETS,
  121. };
  122. static const struct intel_device_info intel_i965g_info = {
  123. .gen = 4, .is_broadwater = 1, .num_pipes = 2,
  124. .has_hotplug = 1,
  125. .has_overlay = 1,
  126. .ring_mask = RENDER_RING,
  127. GEN_DEFAULT_PIPEOFFSETS,
  128. CURSOR_OFFSETS,
  129. };
  130. static const struct intel_device_info intel_i965gm_info = {
  131. .gen = 4, .is_crestline = 1, .num_pipes = 2,
  132. .is_mobile = 1, .has_fbc = 1, .has_hotplug = 1,
  133. .has_overlay = 1,
  134. .supports_tv = 1,
  135. .ring_mask = RENDER_RING,
  136. GEN_DEFAULT_PIPEOFFSETS,
  137. CURSOR_OFFSETS,
  138. };
  139. static const struct intel_device_info intel_g33_info = {
  140. .gen = 3, .is_g33 = 1, .num_pipes = 2,
  141. .need_gfx_hws = 1, .has_hotplug = 1,
  142. .has_overlay = 1,
  143. .ring_mask = RENDER_RING,
  144. GEN_DEFAULT_PIPEOFFSETS,
  145. CURSOR_OFFSETS,
  146. };
  147. static const struct intel_device_info intel_g45_info = {
  148. .gen = 4, .is_g4x = 1, .need_gfx_hws = 1, .num_pipes = 2,
  149. .has_pipe_cxsr = 1, .has_hotplug = 1,
  150. .ring_mask = RENDER_RING | BSD_RING,
  151. GEN_DEFAULT_PIPEOFFSETS,
  152. CURSOR_OFFSETS,
  153. };
  154. static const struct intel_device_info intel_gm45_info = {
  155. .gen = 4, .is_g4x = 1, .num_pipes = 2,
  156. .is_mobile = 1, .need_gfx_hws = 1, .has_fbc = 1,
  157. .has_pipe_cxsr = 1, .has_hotplug = 1,
  158. .supports_tv = 1,
  159. .ring_mask = RENDER_RING | BSD_RING,
  160. GEN_DEFAULT_PIPEOFFSETS,
  161. CURSOR_OFFSETS,
  162. };
  163. static const struct intel_device_info intel_pineview_info = {
  164. .gen = 3, .is_g33 = 1, .is_pineview = 1, .is_mobile = 1, .num_pipes = 2,
  165. .need_gfx_hws = 1, .has_hotplug = 1,
  166. .has_overlay = 1,
  167. GEN_DEFAULT_PIPEOFFSETS,
  168. CURSOR_OFFSETS,
  169. };
  170. static const struct intel_device_info intel_ironlake_d_info = {
  171. .gen = 5, .num_pipes = 2,
  172. .need_gfx_hws = 1, .has_hotplug = 1,
  173. .ring_mask = RENDER_RING | BSD_RING,
  174. GEN_DEFAULT_PIPEOFFSETS,
  175. CURSOR_OFFSETS,
  176. };
  177. static const struct intel_device_info intel_ironlake_m_info = {
  178. .gen = 5, .is_mobile = 1, .num_pipes = 2,
  179. .need_gfx_hws = 1, .has_hotplug = 1,
  180. .has_fbc = 1,
  181. .ring_mask = RENDER_RING | BSD_RING,
  182. GEN_DEFAULT_PIPEOFFSETS,
  183. CURSOR_OFFSETS,
  184. };
  185. static const struct intel_device_info intel_sandybridge_d_info = {
  186. .gen = 6, .num_pipes = 2,
  187. .need_gfx_hws = 1, .has_hotplug = 1,
  188. .has_fbc = 1,
  189. .ring_mask = RENDER_RING | BSD_RING | BLT_RING,
  190. .has_llc = 1,
  191. GEN_DEFAULT_PIPEOFFSETS,
  192. CURSOR_OFFSETS,
  193. };
  194. static const struct intel_device_info intel_sandybridge_m_info = {
  195. .gen = 6, .is_mobile = 1, .num_pipes = 2,
  196. .need_gfx_hws = 1, .has_hotplug = 1,
  197. .has_fbc = 1,
  198. .ring_mask = RENDER_RING | BSD_RING | BLT_RING,
  199. .has_llc = 1,
  200. GEN_DEFAULT_PIPEOFFSETS,
  201. CURSOR_OFFSETS,
  202. };
  203. #define GEN7_FEATURES \
  204. .gen = 7, .num_pipes = 3, \
  205. .need_gfx_hws = 1, .has_hotplug = 1, \
  206. .has_fbc = 1, \
  207. .ring_mask = RENDER_RING | BSD_RING | BLT_RING, \
  208. .has_llc = 1
  209. static const struct intel_device_info intel_ivybridge_d_info = {
  210. GEN7_FEATURES,
  211. .is_ivybridge = 1,
  212. GEN_DEFAULT_PIPEOFFSETS,
  213. IVB_CURSOR_OFFSETS,
  214. };
  215. static const struct intel_device_info intel_ivybridge_m_info = {
  216. GEN7_FEATURES,
  217. .is_ivybridge = 1,
  218. .is_mobile = 1,
  219. GEN_DEFAULT_PIPEOFFSETS,
  220. IVB_CURSOR_OFFSETS,
  221. };
  222. static const struct intel_device_info intel_ivybridge_q_info = {
  223. GEN7_FEATURES,
  224. .is_ivybridge = 1,
  225. .num_pipes = 0, /* legal, last one wins */
  226. GEN_DEFAULT_PIPEOFFSETS,
  227. IVB_CURSOR_OFFSETS,
  228. };
  229. static const struct intel_device_info intel_valleyview_m_info = {
  230. GEN7_FEATURES,
  231. .is_mobile = 1,
  232. .num_pipes = 2,
  233. .is_valleyview = 1,
  234. .display_mmio_offset = VLV_DISPLAY_BASE,
  235. .has_fbc = 0, /* legal, last one wins */
  236. .has_llc = 0, /* legal, last one wins */
  237. GEN_DEFAULT_PIPEOFFSETS,
  238. CURSOR_OFFSETS,
  239. };
  240. static const struct intel_device_info intel_valleyview_d_info = {
  241. GEN7_FEATURES,
  242. .num_pipes = 2,
  243. .is_valleyview = 1,
  244. .display_mmio_offset = VLV_DISPLAY_BASE,
  245. .has_fbc = 0, /* legal, last one wins */
  246. .has_llc = 0, /* legal, last one wins */
  247. GEN_DEFAULT_PIPEOFFSETS,
  248. CURSOR_OFFSETS,
  249. };
  250. static const struct intel_device_info intel_haswell_d_info = {
  251. GEN7_FEATURES,
  252. .is_haswell = 1,
  253. .has_ddi = 1,
  254. .has_fpga_dbg = 1,
  255. .ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING,
  256. GEN_DEFAULT_PIPEOFFSETS,
  257. IVB_CURSOR_OFFSETS,
  258. };
  259. static const struct intel_device_info intel_haswell_m_info = {
  260. GEN7_FEATURES,
  261. .is_haswell = 1,
  262. .is_mobile = 1,
  263. .has_ddi = 1,
  264. .has_fpga_dbg = 1,
  265. .ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING,
  266. GEN_DEFAULT_PIPEOFFSETS,
  267. IVB_CURSOR_OFFSETS,
  268. };
  269. static const struct intel_device_info intel_broadwell_d_info = {
  270. .gen = 8, .num_pipes = 3,
  271. .need_gfx_hws = 1, .has_hotplug = 1,
  272. .ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING,
  273. .has_llc = 1,
  274. .has_ddi = 1,
  275. .has_fpga_dbg = 1,
  276. .has_fbc = 1,
  277. GEN_DEFAULT_PIPEOFFSETS,
  278. IVB_CURSOR_OFFSETS,
  279. };
  280. static const struct intel_device_info intel_broadwell_m_info = {
  281. .gen = 8, .is_mobile = 1, .num_pipes = 3,
  282. .need_gfx_hws = 1, .has_hotplug = 1,
  283. .ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING,
  284. .has_llc = 1,
  285. .has_ddi = 1,
  286. .has_fpga_dbg = 1,
  287. .has_fbc = 1,
  288. GEN_DEFAULT_PIPEOFFSETS,
  289. IVB_CURSOR_OFFSETS,
  290. };
  291. static const struct intel_device_info intel_broadwell_gt3d_info = {
  292. .gen = 8, .num_pipes = 3,
  293. .need_gfx_hws = 1, .has_hotplug = 1,
  294. .ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING | BSD2_RING,
  295. .has_llc = 1,
  296. .has_ddi = 1,
  297. .has_fpga_dbg = 1,
  298. .has_fbc = 1,
  299. GEN_DEFAULT_PIPEOFFSETS,
  300. IVB_CURSOR_OFFSETS,
  301. };
  302. static const struct intel_device_info intel_broadwell_gt3m_info = {
  303. .gen = 8, .is_mobile = 1, .num_pipes = 3,
  304. .need_gfx_hws = 1, .has_hotplug = 1,
  305. .ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING | BSD2_RING,
  306. .has_llc = 1,
  307. .has_ddi = 1,
  308. .has_fpga_dbg = 1,
  309. .has_fbc = 1,
  310. GEN_DEFAULT_PIPEOFFSETS,
  311. IVB_CURSOR_OFFSETS,
  312. };
  313. static const struct intel_device_info intel_cherryview_info = {
  314. .is_preliminary = 1,
  315. .gen = 8, .num_pipes = 3,
  316. .need_gfx_hws = 1, .has_hotplug = 1,
  317. .ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING,
  318. .is_valleyview = 1,
  319. .display_mmio_offset = VLV_DISPLAY_BASE,
  320. GEN_CHV_PIPEOFFSETS,
  321. CURSOR_OFFSETS,
  322. };
  323. static const struct intel_device_info intel_skylake_info = {
  324. .is_preliminary = 1,
  325. .is_skylake = 1,
  326. .gen = 9, .num_pipes = 3,
  327. .need_gfx_hws = 1, .has_hotplug = 1,
  328. .ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING,
  329. .has_llc = 1,
  330. .has_ddi = 1,
  331. .has_fbc = 1,
  332. GEN_DEFAULT_PIPEOFFSETS,
  333. IVB_CURSOR_OFFSETS,
  334. };
  335. /*
  336. * Make sure any device matches here are from most specific to most
  337. * general. For example, since the Quanta match is based on the subsystem
  338. * and subvendor IDs, we need it to come before the more general IVB
  339. * PCI ID matches, otherwise we'll use the wrong info struct above.
  340. */
  341. #define INTEL_PCI_IDS \
  342. INTEL_I830_IDS(&intel_i830_info), \
  343. INTEL_I845G_IDS(&intel_845g_info), \
  344. INTEL_I85X_IDS(&intel_i85x_info), \
  345. INTEL_I865G_IDS(&intel_i865g_info), \
  346. INTEL_I915G_IDS(&intel_i915g_info), \
  347. INTEL_I915GM_IDS(&intel_i915gm_info), \
  348. INTEL_I945G_IDS(&intel_i945g_info), \
  349. INTEL_I945GM_IDS(&intel_i945gm_info), \
  350. INTEL_I965G_IDS(&intel_i965g_info), \
  351. INTEL_G33_IDS(&intel_g33_info), \
  352. INTEL_I965GM_IDS(&intel_i965gm_info), \
  353. INTEL_GM45_IDS(&intel_gm45_info), \
  354. INTEL_G45_IDS(&intel_g45_info), \
  355. INTEL_PINEVIEW_IDS(&intel_pineview_info), \
  356. INTEL_IRONLAKE_D_IDS(&intel_ironlake_d_info), \
  357. INTEL_IRONLAKE_M_IDS(&intel_ironlake_m_info), \
  358. INTEL_SNB_D_IDS(&intel_sandybridge_d_info), \
  359. INTEL_SNB_M_IDS(&intel_sandybridge_m_info), \
  360. INTEL_IVB_Q_IDS(&intel_ivybridge_q_info), /* must be first IVB */ \
  361. INTEL_IVB_M_IDS(&intel_ivybridge_m_info), \
  362. INTEL_IVB_D_IDS(&intel_ivybridge_d_info), \
  363. INTEL_HSW_D_IDS(&intel_haswell_d_info), \
  364. INTEL_HSW_M_IDS(&intel_haswell_m_info), \
  365. INTEL_VLV_M_IDS(&intel_valleyview_m_info), \
  366. INTEL_VLV_D_IDS(&intel_valleyview_d_info), \
  367. INTEL_BDW_GT12M_IDS(&intel_broadwell_m_info), \
  368. INTEL_BDW_GT12D_IDS(&intel_broadwell_d_info), \
  369. INTEL_BDW_GT3M_IDS(&intel_broadwell_gt3m_info), \
  370. INTEL_BDW_GT3D_IDS(&intel_broadwell_gt3d_info), \
  371. INTEL_CHV_IDS(&intel_cherryview_info), \
  372. INTEL_SKL_IDS(&intel_skylake_info)
  373. static const struct pci_device_id pciidlist[] = { /* aka */
  374. INTEL_PCI_IDS,
  375. {0, 0, 0}
  376. };
  377. #if defined(CONFIG_DRM_I915_KMS)
  378. MODULE_DEVICE_TABLE(pci, pciidlist);
  379. #endif
  380. void intel_detect_pch(struct drm_device *dev)
  381. {
  382. struct drm_i915_private *dev_priv = dev->dev_private;
  383. struct pci_dev *pch = NULL;
  384. /* In all current cases, num_pipes is equivalent to the PCH_NOP setting
  385. * (which really amounts to a PCH but no South Display).
  386. */
  387. if (INTEL_INFO(dev)->num_pipes == 0) {
  388. dev_priv->pch_type = PCH_NOP;
  389. return;
  390. }
  391. /*
  392. * The reason to probe ISA bridge instead of Dev31:Fun0 is to
  393. * make graphics device passthrough work easy for VMM, that only
  394. * need to expose ISA bridge to let driver know the real hardware
  395. * underneath. This is a requirement from virtualization team.
  396. *
  397. * In some virtualized environments (e.g. XEN), there is irrelevant
  398. * ISA bridge in the system. To work reliably, we should scan trhough
  399. * all the ISA bridge devices and check for the first match, instead
  400. * of only checking the first one.
  401. */
  402. while ((pch = pci_get_class(PCI_CLASS_BRIDGE_ISA << 8, pch))) {
  403. if (pch->vendor == PCI_VENDOR_ID_INTEL) {
  404. unsigned short id = pch->device & INTEL_PCH_DEVICE_ID_MASK;
  405. dev_priv->pch_id = id;
  406. if (id == INTEL_PCH_IBX_DEVICE_ID_TYPE) {
  407. dev_priv->pch_type = PCH_IBX;
  408. DRM_DEBUG_KMS("Found Ibex Peak PCH\n");
  409. WARN_ON(!IS_GEN5(dev));
  410. } else if (id == INTEL_PCH_CPT_DEVICE_ID_TYPE) {
  411. dev_priv->pch_type = PCH_CPT;
  412. DRM_DEBUG_KMS("Found CougarPoint PCH\n");
  413. WARN_ON(!(IS_GEN6(dev) || IS_IVYBRIDGE(dev)));
  414. } else if (id == INTEL_PCH_PPT_DEVICE_ID_TYPE) {
  415. /* PantherPoint is CPT compatible */
  416. dev_priv->pch_type = PCH_CPT;
  417. DRM_DEBUG_KMS("Found PantherPoint PCH\n");
  418. WARN_ON(!(IS_GEN6(dev) || IS_IVYBRIDGE(dev)));
  419. } else if (id == INTEL_PCH_LPT_DEVICE_ID_TYPE) {
  420. dev_priv->pch_type = PCH_LPT;
  421. DRM_DEBUG_KMS("Found LynxPoint PCH\n");
  422. WARN_ON(!IS_HASWELL(dev));
  423. WARN_ON(IS_HSW_ULT(dev));
  424. } else if (IS_BROADWELL(dev)) {
  425. dev_priv->pch_type = PCH_LPT;
  426. dev_priv->pch_id =
  427. INTEL_PCH_LPT_LP_DEVICE_ID_TYPE;
  428. DRM_DEBUG_KMS("This is Broadwell, assuming "
  429. "LynxPoint LP PCH\n");
  430. } else if (id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) {
  431. dev_priv->pch_type = PCH_LPT;
  432. DRM_DEBUG_KMS("Found LynxPoint LP PCH\n");
  433. WARN_ON(!IS_HASWELL(dev));
  434. WARN_ON(!IS_HSW_ULT(dev));
  435. } else if (id == INTEL_PCH_SPT_DEVICE_ID_TYPE) {
  436. dev_priv->pch_type = PCH_SPT;
  437. DRM_DEBUG_KMS("Found SunrisePoint PCH\n");
  438. WARN_ON(!IS_SKYLAKE(dev));
  439. } else if (id == INTEL_PCH_SPT_LP_DEVICE_ID_TYPE) {
  440. dev_priv->pch_type = PCH_SPT;
  441. DRM_DEBUG_KMS("Found SunrisePoint LP PCH\n");
  442. WARN_ON(!IS_SKYLAKE(dev));
  443. } else
  444. continue;
  445. break;
  446. }
  447. }
  448. if (!pch)
  449. DRM_DEBUG_KMS("No PCH found.\n");
  450. pci_dev_put(pch);
  451. }
  452. bool i915_semaphore_is_enabled(struct drm_device *dev)
  453. {
  454. if (INTEL_INFO(dev)->gen < 6)
  455. return false;
  456. if (i915.semaphores >= 0)
  457. return i915.semaphores;
  458. /* TODO: make semaphores and Execlists play nicely together */
  459. if (i915.enable_execlists)
  460. return false;
  461. /* Until we get further testing... */
  462. if (IS_GEN8(dev))
  463. return false;
  464. #ifdef CONFIG_INTEL_IOMMU
  465. /* Enable semaphores on SNB when IO remapping is off */
  466. if (INTEL_INFO(dev)->gen == 6 && intel_iommu_gfx_mapped)
  467. return false;
  468. #endif
  469. return true;
  470. }
  471. void intel_hpd_cancel_work(struct drm_i915_private *dev_priv)
  472. {
  473. spin_lock_irq(&dev_priv->irq_lock);
  474. dev_priv->long_hpd_port_mask = 0;
  475. dev_priv->short_hpd_port_mask = 0;
  476. dev_priv->hpd_event_bits = 0;
  477. spin_unlock_irq(&dev_priv->irq_lock);
  478. cancel_work_sync(&dev_priv->dig_port_work);
  479. cancel_work_sync(&dev_priv->hotplug_work);
  480. cancel_delayed_work_sync(&dev_priv->hotplug_reenable_work);
  481. }
  482. static void intel_suspend_encoders(struct drm_i915_private *dev_priv)
  483. {
  484. struct drm_device *dev = dev_priv->dev;
  485. struct drm_encoder *encoder;
  486. drm_modeset_lock_all(dev);
  487. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  488. struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
  489. if (intel_encoder->suspend)
  490. intel_encoder->suspend(intel_encoder);
  491. }
  492. drm_modeset_unlock_all(dev);
  493. }
  494. static int intel_suspend_complete(struct drm_i915_private *dev_priv);
  495. static int vlv_resume_prepare(struct drm_i915_private *dev_priv,
  496. bool rpm_resume);
  497. static int i915_drm_suspend(struct drm_device *dev)
  498. {
  499. struct drm_i915_private *dev_priv = dev->dev_private;
  500. struct drm_crtc *crtc;
  501. pci_power_t opregion_target_state;
  502. /* ignore lid events during suspend */
  503. mutex_lock(&dev_priv->modeset_restore_lock);
  504. dev_priv->modeset_restore = MODESET_SUSPENDED;
  505. mutex_unlock(&dev_priv->modeset_restore_lock);
  506. /* We do a lot of poking in a lot of registers, make sure they work
  507. * properly. */
  508. intel_display_set_init_power(dev_priv, true);
  509. drm_kms_helper_poll_disable(dev);
  510. pci_save_state(dev->pdev);
  511. /* If KMS is active, we do the leavevt stuff here */
  512. if (drm_core_check_feature(dev, DRIVER_MODESET)) {
  513. int error;
  514. error = i915_gem_suspend(dev);
  515. if (error) {
  516. dev_err(&dev->pdev->dev,
  517. "GEM idle failed, resume might fail\n");
  518. return error;
  519. }
  520. intel_suspend_gt_powersave(dev);
  521. /*
  522. * Disable CRTCs directly since we want to preserve sw state
  523. * for _thaw. Also, power gate the CRTC power wells.
  524. */
  525. drm_modeset_lock_all(dev);
  526. for_each_crtc(dev, crtc)
  527. intel_crtc_control(crtc, false);
  528. drm_modeset_unlock_all(dev);
  529. intel_dp_mst_suspend(dev);
  530. intel_runtime_pm_disable_interrupts(dev_priv);
  531. intel_hpd_cancel_work(dev_priv);
  532. intel_suspend_encoders(dev_priv);
  533. intel_suspend_hw(dev);
  534. }
  535. i915_gem_suspend_gtt_mappings(dev);
  536. i915_save_state(dev);
  537. opregion_target_state = PCI_D3cold;
  538. #if IS_ENABLED(CONFIG_ACPI_SLEEP)
  539. if (acpi_target_system_state() < ACPI_STATE_S3)
  540. opregion_target_state = PCI_D1;
  541. #endif
  542. intel_opregion_notify_adapter(dev, opregion_target_state);
  543. intel_uncore_forcewake_reset(dev, false);
  544. intel_opregion_fini(dev);
  545. intel_fbdev_set_suspend(dev, FBINFO_STATE_SUSPENDED, true);
  546. dev_priv->suspend_count++;
  547. intel_display_set_init_power(dev_priv, false);
  548. return 0;
  549. }
  550. static int i915_drm_suspend_late(struct drm_device *drm_dev)
  551. {
  552. struct drm_i915_private *dev_priv = drm_dev->dev_private;
  553. int ret;
  554. ret = intel_suspend_complete(dev_priv);
  555. if (ret) {
  556. DRM_ERROR("Suspend complete failed: %d\n", ret);
  557. return ret;
  558. }
  559. pci_disable_device(drm_dev->pdev);
  560. pci_set_power_state(drm_dev->pdev, PCI_D3hot);
  561. return 0;
  562. }
  563. int i915_suspend_legacy(struct drm_device *dev, pm_message_t state)
  564. {
  565. int error;
  566. if (!dev || !dev->dev_private) {
  567. DRM_ERROR("dev: %p\n", dev);
  568. DRM_ERROR("DRM not initialized, aborting suspend.\n");
  569. return -ENODEV;
  570. }
  571. if (WARN_ON_ONCE(state.event != PM_EVENT_SUSPEND &&
  572. state.event != PM_EVENT_FREEZE))
  573. return -EINVAL;
  574. if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
  575. return 0;
  576. error = i915_drm_suspend(dev);
  577. if (error)
  578. return error;
  579. return i915_drm_suspend_late(dev);
  580. }
  581. static int i915_drm_resume(struct drm_device *dev)
  582. {
  583. struct drm_i915_private *dev_priv = dev->dev_private;
  584. if (drm_core_check_feature(dev, DRIVER_MODESET)) {
  585. mutex_lock(&dev->struct_mutex);
  586. i915_gem_restore_gtt_mappings(dev);
  587. mutex_unlock(&dev->struct_mutex);
  588. }
  589. i915_restore_state(dev);
  590. intel_opregion_setup(dev);
  591. /* KMS EnterVT equivalent */
  592. if (drm_core_check_feature(dev, DRIVER_MODESET)) {
  593. intel_init_pch_refclk(dev);
  594. drm_mode_config_reset(dev);
  595. mutex_lock(&dev->struct_mutex);
  596. if (i915_gem_init_hw(dev)) {
  597. DRM_ERROR("failed to re-initialize GPU, declaring wedged!\n");
  598. atomic_set_mask(I915_WEDGED, &dev_priv->gpu_error.reset_counter);
  599. }
  600. mutex_unlock(&dev->struct_mutex);
  601. /* We need working interrupts for modeset enabling ... */
  602. intel_runtime_pm_enable_interrupts(dev_priv);
  603. intel_modeset_init_hw(dev);
  604. spin_lock_irq(&dev_priv->irq_lock);
  605. if (dev_priv->display.hpd_irq_setup)
  606. dev_priv->display.hpd_irq_setup(dev);
  607. spin_unlock_irq(&dev_priv->irq_lock);
  608. drm_modeset_lock_all(dev);
  609. intel_modeset_setup_hw_state(dev, true);
  610. drm_modeset_unlock_all(dev);
  611. intel_dp_mst_resume(dev);
  612. /*
  613. * ... but also need to make sure that hotplug processing
  614. * doesn't cause havoc. Like in the driver load code we don't
  615. * bother with the tiny race here where we might loose hotplug
  616. * notifications.
  617. * */
  618. intel_hpd_init(dev_priv);
  619. /* Config may have changed between suspend and resume */
  620. drm_helper_hpd_irq_event(dev);
  621. }
  622. intel_opregion_init(dev);
  623. intel_fbdev_set_suspend(dev, FBINFO_STATE_RUNNING, false);
  624. mutex_lock(&dev_priv->modeset_restore_lock);
  625. dev_priv->modeset_restore = MODESET_DONE;
  626. mutex_unlock(&dev_priv->modeset_restore_lock);
  627. intel_opregion_notify_adapter(dev, PCI_D0);
  628. drm_kms_helper_poll_enable(dev);
  629. return 0;
  630. }
  631. static int i915_drm_resume_early(struct drm_device *dev)
  632. {
  633. struct drm_i915_private *dev_priv = dev->dev_private;
  634. int ret = 0;
  635. /*
  636. * We have a resume ordering issue with the snd-hda driver also
  637. * requiring our device to be power up. Due to the lack of a
  638. * parent/child relationship we currently solve this with an early
  639. * resume hook.
  640. *
  641. * FIXME: This should be solved with a special hdmi sink device or
  642. * similar so that power domains can be employed.
  643. */
  644. if (pci_enable_device(dev->pdev))
  645. return -EIO;
  646. pci_set_master(dev->pdev);
  647. if (IS_VALLEYVIEW(dev_priv))
  648. ret = vlv_resume_prepare(dev_priv, false);
  649. if (ret)
  650. DRM_ERROR("Resume prepare failed: %d,Continuing resume\n", ret);
  651. intel_uncore_early_sanitize(dev, true);
  652. if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
  653. hsw_disable_pc8(dev_priv);
  654. intel_uncore_sanitize(dev);
  655. intel_power_domains_init_hw(dev_priv);
  656. return ret;
  657. }
  658. int i915_resume_legacy(struct drm_device *dev)
  659. {
  660. int ret;
  661. if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
  662. return 0;
  663. ret = i915_drm_resume_early(dev);
  664. if (ret)
  665. return ret;
  666. return i915_drm_resume(dev);
  667. }
  668. /**
  669. * i915_reset - reset chip after a hang
  670. * @dev: drm device to reset
  671. *
  672. * Reset the chip. Useful if a hang is detected. Returns zero on successful
  673. * reset or otherwise an error code.
  674. *
  675. * Procedure is fairly simple:
  676. * - reset the chip using the reset reg
  677. * - re-init context state
  678. * - re-init hardware status page
  679. * - re-init ring buffer
  680. * - re-init interrupt state
  681. * - re-init display
  682. */
  683. int i915_reset(struct drm_device *dev)
  684. {
  685. struct drm_i915_private *dev_priv = dev->dev_private;
  686. bool simulated;
  687. int ret;
  688. if (!i915.reset)
  689. return 0;
  690. intel_reset_gt_powersave(dev);
  691. mutex_lock(&dev->struct_mutex);
  692. i915_gem_reset(dev);
  693. simulated = dev_priv->gpu_error.stop_rings != 0;
  694. ret = intel_gpu_reset(dev);
  695. /* Also reset the gpu hangman. */
  696. if (simulated) {
  697. DRM_INFO("Simulated gpu hang, resetting stop_rings\n");
  698. dev_priv->gpu_error.stop_rings = 0;
  699. if (ret == -ENODEV) {
  700. DRM_INFO("Reset not implemented, but ignoring "
  701. "error for simulated gpu hangs\n");
  702. ret = 0;
  703. }
  704. }
  705. if (i915_stop_ring_allow_warn(dev_priv))
  706. pr_notice("drm/i915: Resetting chip after gpu hang\n");
  707. if (ret) {
  708. DRM_ERROR("Failed to reset chip: %i\n", ret);
  709. mutex_unlock(&dev->struct_mutex);
  710. return ret;
  711. }
  712. /* Ok, now get things going again... */
  713. /*
  714. * Everything depends on having the GTT running, so we need to start
  715. * there. Fortunately we don't need to do this unless we reset the
  716. * chip at a PCI level.
  717. *
  718. * Next we need to restore the context, but we don't use those
  719. * yet either...
  720. *
  721. * Ring buffer needs to be re-initialized in the KMS case, or if X
  722. * was running at the time of the reset (i.e. we weren't VT
  723. * switched away).
  724. */
  725. if (drm_core_check_feature(dev, DRIVER_MODESET)) {
  726. /* Used to prevent gem_check_wedged returning -EAGAIN during gpu reset */
  727. dev_priv->gpu_error.reload_in_reset = true;
  728. ret = i915_gem_init_hw(dev);
  729. dev_priv->gpu_error.reload_in_reset = false;
  730. mutex_unlock(&dev->struct_mutex);
  731. if (ret) {
  732. DRM_ERROR("Failed hw init on reset %d\n", ret);
  733. return ret;
  734. }
  735. /*
  736. * FIXME: This races pretty badly against concurrent holders of
  737. * ring interrupts. This is possible since we've started to drop
  738. * dev->struct_mutex in select places when waiting for the gpu.
  739. */
  740. /*
  741. * rps/rc6 re-init is necessary to restore state lost after the
  742. * reset and the re-install of gt irqs. Skip for ironlake per
  743. * previous concerns that it doesn't respond well to some forms
  744. * of re-init after reset.
  745. */
  746. if (INTEL_INFO(dev)->gen > 5)
  747. intel_enable_gt_powersave(dev);
  748. } else {
  749. mutex_unlock(&dev->struct_mutex);
  750. }
  751. return 0;
  752. }
  753. static int i915_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  754. {
  755. struct intel_device_info *intel_info =
  756. (struct intel_device_info *) ent->driver_data;
  757. if (IS_PRELIMINARY_HW(intel_info) && !i915.preliminary_hw_support) {
  758. DRM_INFO("This hardware requires preliminary hardware support.\n"
  759. "See CONFIG_DRM_I915_PRELIMINARY_HW_SUPPORT, and/or modparam preliminary_hw_support\n");
  760. return -ENODEV;
  761. }
  762. /* Only bind to function 0 of the device. Early generations
  763. * used function 1 as a placeholder for multi-head. This causes
  764. * us confusion instead, especially on the systems where both
  765. * functions have the same PCI-ID!
  766. */
  767. if (PCI_FUNC(pdev->devfn))
  768. return -ENODEV;
  769. driver.driver_features &= ~(DRIVER_USE_AGP);
  770. return drm_get_pci_dev(pdev, ent, &driver);
  771. }
  772. static void
  773. i915_pci_remove(struct pci_dev *pdev)
  774. {
  775. struct drm_device *dev = pci_get_drvdata(pdev);
  776. drm_put_dev(dev);
  777. }
  778. static int i915_pm_suspend(struct device *dev)
  779. {
  780. struct pci_dev *pdev = to_pci_dev(dev);
  781. struct drm_device *drm_dev = pci_get_drvdata(pdev);
  782. if (!drm_dev || !drm_dev->dev_private) {
  783. dev_err(dev, "DRM not initialized, aborting suspend.\n");
  784. return -ENODEV;
  785. }
  786. if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF)
  787. return 0;
  788. return i915_drm_suspend(drm_dev);
  789. }
  790. static int i915_pm_suspend_late(struct device *dev)
  791. {
  792. struct pci_dev *pdev = to_pci_dev(dev);
  793. struct drm_device *drm_dev = pci_get_drvdata(pdev);
  794. /*
  795. * We have a suspedn ordering issue with the snd-hda driver also
  796. * requiring our device to be power up. Due to the lack of a
  797. * parent/child relationship we currently solve this with an late
  798. * suspend hook.
  799. *
  800. * FIXME: This should be solved with a special hdmi sink device or
  801. * similar so that power domains can be employed.
  802. */
  803. if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF)
  804. return 0;
  805. return i915_drm_suspend_late(drm_dev);
  806. }
  807. static int i915_pm_resume_early(struct device *dev)
  808. {
  809. struct pci_dev *pdev = to_pci_dev(dev);
  810. struct drm_device *drm_dev = pci_get_drvdata(pdev);
  811. if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF)
  812. return 0;
  813. return i915_drm_resume_early(drm_dev);
  814. }
  815. static int i915_pm_resume(struct device *dev)
  816. {
  817. struct pci_dev *pdev = to_pci_dev(dev);
  818. struct drm_device *drm_dev = pci_get_drvdata(pdev);
  819. if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF)
  820. return 0;
  821. return i915_drm_resume(drm_dev);
  822. }
  823. static int hsw_suspend_complete(struct drm_i915_private *dev_priv)
  824. {
  825. hsw_enable_pc8(dev_priv);
  826. return 0;
  827. }
  828. /*
  829. * Save all Gunit registers that may be lost after a D3 and a subsequent
  830. * S0i[R123] transition. The list of registers needing a save/restore is
  831. * defined in the VLV2_S0IXRegs document. This documents marks all Gunit
  832. * registers in the following way:
  833. * - Driver: saved/restored by the driver
  834. * - Punit : saved/restored by the Punit firmware
  835. * - No, w/o marking: no need to save/restore, since the register is R/O or
  836. * used internally by the HW in a way that doesn't depend
  837. * keeping the content across a suspend/resume.
  838. * - Debug : used for debugging
  839. *
  840. * We save/restore all registers marked with 'Driver', with the following
  841. * exceptions:
  842. * - Registers out of use, including also registers marked with 'Debug'.
  843. * These have no effect on the driver's operation, so we don't save/restore
  844. * them to reduce the overhead.
  845. * - Registers that are fully setup by an initialization function called from
  846. * the resume path. For example many clock gating and RPS/RC6 registers.
  847. * - Registers that provide the right functionality with their reset defaults.
  848. *
  849. * TODO: Except for registers that based on the above 3 criteria can be safely
  850. * ignored, we save/restore all others, practically treating the HW context as
  851. * a black-box for the driver. Further investigation is needed to reduce the
  852. * saved/restored registers even further, by following the same 3 criteria.
  853. */
  854. static void vlv_save_gunit_s0ix_state(struct drm_i915_private *dev_priv)
  855. {
  856. struct vlv_s0ix_state *s = &dev_priv->vlv_s0ix_state;
  857. int i;
  858. /* GAM 0x4000-0x4770 */
  859. s->wr_watermark = I915_READ(GEN7_WR_WATERMARK);
  860. s->gfx_prio_ctrl = I915_READ(GEN7_GFX_PRIO_CTRL);
  861. s->arb_mode = I915_READ(ARB_MODE);
  862. s->gfx_pend_tlb0 = I915_READ(GEN7_GFX_PEND_TLB0);
  863. s->gfx_pend_tlb1 = I915_READ(GEN7_GFX_PEND_TLB1);
  864. for (i = 0; i < ARRAY_SIZE(s->lra_limits); i++)
  865. s->lra_limits[i] = I915_READ(GEN7_LRA_LIMITS_BASE + i * 4);
  866. s->media_max_req_count = I915_READ(GEN7_MEDIA_MAX_REQ_COUNT);
  867. s->gfx_max_req_count = I915_READ(GEN7_MEDIA_MAX_REQ_COUNT);
  868. s->render_hwsp = I915_READ(RENDER_HWS_PGA_GEN7);
  869. s->ecochk = I915_READ(GAM_ECOCHK);
  870. s->bsd_hwsp = I915_READ(BSD_HWS_PGA_GEN7);
  871. s->blt_hwsp = I915_READ(BLT_HWS_PGA_GEN7);
  872. s->tlb_rd_addr = I915_READ(GEN7_TLB_RD_ADDR);
  873. /* MBC 0x9024-0x91D0, 0x8500 */
  874. s->g3dctl = I915_READ(VLV_G3DCTL);
  875. s->gsckgctl = I915_READ(VLV_GSCKGCTL);
  876. s->mbctl = I915_READ(GEN6_MBCTL);
  877. /* GCP 0x9400-0x9424, 0x8100-0x810C */
  878. s->ucgctl1 = I915_READ(GEN6_UCGCTL1);
  879. s->ucgctl3 = I915_READ(GEN6_UCGCTL3);
  880. s->rcgctl1 = I915_READ(GEN6_RCGCTL1);
  881. s->rcgctl2 = I915_READ(GEN6_RCGCTL2);
  882. s->rstctl = I915_READ(GEN6_RSTCTL);
  883. s->misccpctl = I915_READ(GEN7_MISCCPCTL);
  884. /* GPM 0xA000-0xAA84, 0x8000-0x80FC */
  885. s->gfxpause = I915_READ(GEN6_GFXPAUSE);
  886. s->rpdeuhwtc = I915_READ(GEN6_RPDEUHWTC);
  887. s->rpdeuc = I915_READ(GEN6_RPDEUC);
  888. s->ecobus = I915_READ(ECOBUS);
  889. s->pwrdwnupctl = I915_READ(VLV_PWRDWNUPCTL);
  890. s->rp_down_timeout = I915_READ(GEN6_RP_DOWN_TIMEOUT);
  891. s->rp_deucsw = I915_READ(GEN6_RPDEUCSW);
  892. s->rcubmabdtmr = I915_READ(GEN6_RCUBMABDTMR);
  893. s->rcedata = I915_READ(VLV_RCEDATA);
  894. s->spare2gh = I915_READ(VLV_SPAREG2H);
  895. /* Display CZ domain, 0x4400C-0x4402C, 0x4F000-0x4F11F */
  896. s->gt_imr = I915_READ(GTIMR);
  897. s->gt_ier = I915_READ(GTIER);
  898. s->pm_imr = I915_READ(GEN6_PMIMR);
  899. s->pm_ier = I915_READ(GEN6_PMIER);
  900. for (i = 0; i < ARRAY_SIZE(s->gt_scratch); i++)
  901. s->gt_scratch[i] = I915_READ(GEN7_GT_SCRATCH_BASE + i * 4);
  902. /* GT SA CZ domain, 0x100000-0x138124 */
  903. s->tilectl = I915_READ(TILECTL);
  904. s->gt_fifoctl = I915_READ(GTFIFOCTL);
  905. s->gtlc_wake_ctrl = I915_READ(VLV_GTLC_WAKE_CTRL);
  906. s->gtlc_survive = I915_READ(VLV_GTLC_SURVIVABILITY_REG);
  907. s->pmwgicz = I915_READ(VLV_PMWGICZ);
  908. /* Gunit-Display CZ domain, 0x182028-0x1821CF */
  909. s->gu_ctl0 = I915_READ(VLV_GU_CTL0);
  910. s->gu_ctl1 = I915_READ(VLV_GU_CTL1);
  911. s->clock_gate_dis2 = I915_READ(VLV_GUNIT_CLOCK_GATE2);
  912. /*
  913. * Not saving any of:
  914. * DFT, 0x9800-0x9EC0
  915. * SARB, 0xB000-0xB1FC
  916. * GAC, 0x5208-0x524C, 0x14000-0x14C000
  917. * PCI CFG
  918. */
  919. }
  920. static void vlv_restore_gunit_s0ix_state(struct drm_i915_private *dev_priv)
  921. {
  922. struct vlv_s0ix_state *s = &dev_priv->vlv_s0ix_state;
  923. u32 val;
  924. int i;
  925. /* GAM 0x4000-0x4770 */
  926. I915_WRITE(GEN7_WR_WATERMARK, s->wr_watermark);
  927. I915_WRITE(GEN7_GFX_PRIO_CTRL, s->gfx_prio_ctrl);
  928. I915_WRITE(ARB_MODE, s->arb_mode | (0xffff << 16));
  929. I915_WRITE(GEN7_GFX_PEND_TLB0, s->gfx_pend_tlb0);
  930. I915_WRITE(GEN7_GFX_PEND_TLB1, s->gfx_pend_tlb1);
  931. for (i = 0; i < ARRAY_SIZE(s->lra_limits); i++)
  932. I915_WRITE(GEN7_LRA_LIMITS_BASE + i * 4, s->lra_limits[i]);
  933. I915_WRITE(GEN7_MEDIA_MAX_REQ_COUNT, s->media_max_req_count);
  934. I915_WRITE(GEN7_MEDIA_MAX_REQ_COUNT, s->gfx_max_req_count);
  935. I915_WRITE(RENDER_HWS_PGA_GEN7, s->render_hwsp);
  936. I915_WRITE(GAM_ECOCHK, s->ecochk);
  937. I915_WRITE(BSD_HWS_PGA_GEN7, s->bsd_hwsp);
  938. I915_WRITE(BLT_HWS_PGA_GEN7, s->blt_hwsp);
  939. I915_WRITE(GEN7_TLB_RD_ADDR, s->tlb_rd_addr);
  940. /* MBC 0x9024-0x91D0, 0x8500 */
  941. I915_WRITE(VLV_G3DCTL, s->g3dctl);
  942. I915_WRITE(VLV_GSCKGCTL, s->gsckgctl);
  943. I915_WRITE(GEN6_MBCTL, s->mbctl);
  944. /* GCP 0x9400-0x9424, 0x8100-0x810C */
  945. I915_WRITE(GEN6_UCGCTL1, s->ucgctl1);
  946. I915_WRITE(GEN6_UCGCTL3, s->ucgctl3);
  947. I915_WRITE(GEN6_RCGCTL1, s->rcgctl1);
  948. I915_WRITE(GEN6_RCGCTL2, s->rcgctl2);
  949. I915_WRITE(GEN6_RSTCTL, s->rstctl);
  950. I915_WRITE(GEN7_MISCCPCTL, s->misccpctl);
  951. /* GPM 0xA000-0xAA84, 0x8000-0x80FC */
  952. I915_WRITE(GEN6_GFXPAUSE, s->gfxpause);
  953. I915_WRITE(GEN6_RPDEUHWTC, s->rpdeuhwtc);
  954. I915_WRITE(GEN6_RPDEUC, s->rpdeuc);
  955. I915_WRITE(ECOBUS, s->ecobus);
  956. I915_WRITE(VLV_PWRDWNUPCTL, s->pwrdwnupctl);
  957. I915_WRITE(GEN6_RP_DOWN_TIMEOUT,s->rp_down_timeout);
  958. I915_WRITE(GEN6_RPDEUCSW, s->rp_deucsw);
  959. I915_WRITE(GEN6_RCUBMABDTMR, s->rcubmabdtmr);
  960. I915_WRITE(VLV_RCEDATA, s->rcedata);
  961. I915_WRITE(VLV_SPAREG2H, s->spare2gh);
  962. /* Display CZ domain, 0x4400C-0x4402C, 0x4F000-0x4F11F */
  963. I915_WRITE(GTIMR, s->gt_imr);
  964. I915_WRITE(GTIER, s->gt_ier);
  965. I915_WRITE(GEN6_PMIMR, s->pm_imr);
  966. I915_WRITE(GEN6_PMIER, s->pm_ier);
  967. for (i = 0; i < ARRAY_SIZE(s->gt_scratch); i++)
  968. I915_WRITE(GEN7_GT_SCRATCH_BASE + i * 4, s->gt_scratch[i]);
  969. /* GT SA CZ domain, 0x100000-0x138124 */
  970. I915_WRITE(TILECTL, s->tilectl);
  971. I915_WRITE(GTFIFOCTL, s->gt_fifoctl);
  972. /*
  973. * Preserve the GT allow wake and GFX force clock bit, they are not
  974. * be restored, as they are used to control the s0ix suspend/resume
  975. * sequence by the caller.
  976. */
  977. val = I915_READ(VLV_GTLC_WAKE_CTRL);
  978. val &= VLV_GTLC_ALLOWWAKEREQ;
  979. val |= s->gtlc_wake_ctrl & ~VLV_GTLC_ALLOWWAKEREQ;
  980. I915_WRITE(VLV_GTLC_WAKE_CTRL, val);
  981. val = I915_READ(VLV_GTLC_SURVIVABILITY_REG);
  982. val &= VLV_GFX_CLK_FORCE_ON_BIT;
  983. val |= s->gtlc_survive & ~VLV_GFX_CLK_FORCE_ON_BIT;
  984. I915_WRITE(VLV_GTLC_SURVIVABILITY_REG, val);
  985. I915_WRITE(VLV_PMWGICZ, s->pmwgicz);
  986. /* Gunit-Display CZ domain, 0x182028-0x1821CF */
  987. I915_WRITE(VLV_GU_CTL0, s->gu_ctl0);
  988. I915_WRITE(VLV_GU_CTL1, s->gu_ctl1);
  989. I915_WRITE(VLV_GUNIT_CLOCK_GATE2, s->clock_gate_dis2);
  990. }
  991. int vlv_force_gfx_clock(struct drm_i915_private *dev_priv, bool force_on)
  992. {
  993. u32 val;
  994. int err;
  995. val = I915_READ(VLV_GTLC_SURVIVABILITY_REG);
  996. WARN_ON(!!(val & VLV_GFX_CLK_FORCE_ON_BIT) == force_on);
  997. #define COND (I915_READ(VLV_GTLC_SURVIVABILITY_REG) & VLV_GFX_CLK_STATUS_BIT)
  998. /* Wait for a previous force-off to settle */
  999. if (force_on) {
  1000. err = wait_for(!COND, 20);
  1001. if (err) {
  1002. DRM_ERROR("timeout waiting for GFX clock force-off (%08x)\n",
  1003. I915_READ(VLV_GTLC_SURVIVABILITY_REG));
  1004. return err;
  1005. }
  1006. }
  1007. val = I915_READ(VLV_GTLC_SURVIVABILITY_REG);
  1008. val &= ~VLV_GFX_CLK_FORCE_ON_BIT;
  1009. if (force_on)
  1010. val |= VLV_GFX_CLK_FORCE_ON_BIT;
  1011. I915_WRITE(VLV_GTLC_SURVIVABILITY_REG, val);
  1012. if (!force_on)
  1013. return 0;
  1014. err = wait_for(COND, 20);
  1015. if (err)
  1016. DRM_ERROR("timeout waiting for GFX clock force-on (%08x)\n",
  1017. I915_READ(VLV_GTLC_SURVIVABILITY_REG));
  1018. return err;
  1019. #undef COND
  1020. }
  1021. static int vlv_allow_gt_wake(struct drm_i915_private *dev_priv, bool allow)
  1022. {
  1023. u32 val;
  1024. int err = 0;
  1025. val = I915_READ(VLV_GTLC_WAKE_CTRL);
  1026. val &= ~VLV_GTLC_ALLOWWAKEREQ;
  1027. if (allow)
  1028. val |= VLV_GTLC_ALLOWWAKEREQ;
  1029. I915_WRITE(VLV_GTLC_WAKE_CTRL, val);
  1030. POSTING_READ(VLV_GTLC_WAKE_CTRL);
  1031. #define COND (!!(I915_READ(VLV_GTLC_PW_STATUS) & VLV_GTLC_ALLOWWAKEACK) == \
  1032. allow)
  1033. err = wait_for(COND, 1);
  1034. if (err)
  1035. DRM_ERROR("timeout disabling GT waking\n");
  1036. return err;
  1037. #undef COND
  1038. }
  1039. static int vlv_wait_for_gt_wells(struct drm_i915_private *dev_priv,
  1040. bool wait_for_on)
  1041. {
  1042. u32 mask;
  1043. u32 val;
  1044. int err;
  1045. mask = VLV_GTLC_PW_MEDIA_STATUS_MASK | VLV_GTLC_PW_RENDER_STATUS_MASK;
  1046. val = wait_for_on ? mask : 0;
  1047. #define COND ((I915_READ(VLV_GTLC_PW_STATUS) & mask) == val)
  1048. if (COND)
  1049. return 0;
  1050. DRM_DEBUG_KMS("waiting for GT wells to go %s (%08x)\n",
  1051. wait_for_on ? "on" : "off",
  1052. I915_READ(VLV_GTLC_PW_STATUS));
  1053. /*
  1054. * RC6 transitioning can be delayed up to 2 msec (see
  1055. * valleyview_enable_rps), use 3 msec for safety.
  1056. */
  1057. err = wait_for(COND, 3);
  1058. if (err)
  1059. DRM_ERROR("timeout waiting for GT wells to go %s\n",
  1060. wait_for_on ? "on" : "off");
  1061. return err;
  1062. #undef COND
  1063. }
  1064. static void vlv_check_no_gt_access(struct drm_i915_private *dev_priv)
  1065. {
  1066. if (!(I915_READ(VLV_GTLC_PW_STATUS) & VLV_GTLC_ALLOWWAKEERR))
  1067. return;
  1068. DRM_ERROR("GT register access while GT waking disabled\n");
  1069. I915_WRITE(VLV_GTLC_PW_STATUS, VLV_GTLC_ALLOWWAKEERR);
  1070. }
  1071. static int vlv_suspend_complete(struct drm_i915_private *dev_priv)
  1072. {
  1073. u32 mask;
  1074. int err;
  1075. /*
  1076. * Bspec defines the following GT well on flags as debug only, so
  1077. * don't treat them as hard failures.
  1078. */
  1079. (void)vlv_wait_for_gt_wells(dev_priv, false);
  1080. mask = VLV_GTLC_RENDER_CTX_EXISTS | VLV_GTLC_MEDIA_CTX_EXISTS;
  1081. WARN_ON((I915_READ(VLV_GTLC_WAKE_CTRL) & mask) != mask);
  1082. vlv_check_no_gt_access(dev_priv);
  1083. err = vlv_force_gfx_clock(dev_priv, true);
  1084. if (err)
  1085. goto err1;
  1086. err = vlv_allow_gt_wake(dev_priv, false);
  1087. if (err)
  1088. goto err2;
  1089. vlv_save_gunit_s0ix_state(dev_priv);
  1090. err = vlv_force_gfx_clock(dev_priv, false);
  1091. if (err)
  1092. goto err2;
  1093. return 0;
  1094. err2:
  1095. /* For safety always re-enable waking and disable gfx clock forcing */
  1096. vlv_allow_gt_wake(dev_priv, true);
  1097. err1:
  1098. vlv_force_gfx_clock(dev_priv, false);
  1099. return err;
  1100. }
  1101. static int vlv_resume_prepare(struct drm_i915_private *dev_priv,
  1102. bool rpm_resume)
  1103. {
  1104. struct drm_device *dev = dev_priv->dev;
  1105. int err;
  1106. int ret;
  1107. /*
  1108. * If any of the steps fail just try to continue, that's the best we
  1109. * can do at this point. Return the first error code (which will also
  1110. * leave RPM permanently disabled).
  1111. */
  1112. ret = vlv_force_gfx_clock(dev_priv, true);
  1113. vlv_restore_gunit_s0ix_state(dev_priv);
  1114. err = vlv_allow_gt_wake(dev_priv, true);
  1115. if (!ret)
  1116. ret = err;
  1117. err = vlv_force_gfx_clock(dev_priv, false);
  1118. if (!ret)
  1119. ret = err;
  1120. vlv_check_no_gt_access(dev_priv);
  1121. if (rpm_resume) {
  1122. intel_init_clock_gating(dev);
  1123. i915_gem_restore_fences(dev);
  1124. }
  1125. return ret;
  1126. }
  1127. static int intel_runtime_suspend(struct device *device)
  1128. {
  1129. struct pci_dev *pdev = to_pci_dev(device);
  1130. struct drm_device *dev = pci_get_drvdata(pdev);
  1131. struct drm_i915_private *dev_priv = dev->dev_private;
  1132. int ret;
  1133. if (WARN_ON_ONCE(!(dev_priv->rps.enabled && intel_enable_rc6(dev))))
  1134. return -ENODEV;
  1135. if (WARN_ON_ONCE(!HAS_RUNTIME_PM(dev)))
  1136. return -ENODEV;
  1137. assert_force_wake_inactive(dev_priv);
  1138. DRM_DEBUG_KMS("Suspending device\n");
  1139. /*
  1140. * We could deadlock here in case another thread holding struct_mutex
  1141. * calls RPM suspend concurrently, since the RPM suspend will wait
  1142. * first for this RPM suspend to finish. In this case the concurrent
  1143. * RPM resume will be followed by its RPM suspend counterpart. Still
  1144. * for consistency return -EAGAIN, which will reschedule this suspend.
  1145. */
  1146. if (!mutex_trylock(&dev->struct_mutex)) {
  1147. DRM_DEBUG_KMS("device lock contention, deffering suspend\n");
  1148. /*
  1149. * Bump the expiration timestamp, otherwise the suspend won't
  1150. * be rescheduled.
  1151. */
  1152. pm_runtime_mark_last_busy(device);
  1153. return -EAGAIN;
  1154. }
  1155. /*
  1156. * We are safe here against re-faults, since the fault handler takes
  1157. * an RPM reference.
  1158. */
  1159. i915_gem_release_all_mmaps(dev_priv);
  1160. mutex_unlock(&dev->struct_mutex);
  1161. intel_suspend_gt_powersave(dev);
  1162. intel_runtime_pm_disable_interrupts(dev_priv);
  1163. ret = intel_suspend_complete(dev_priv);
  1164. if (ret) {
  1165. DRM_ERROR("Runtime suspend failed, disabling it (%d)\n", ret);
  1166. intel_runtime_pm_enable_interrupts(dev_priv);
  1167. return ret;
  1168. }
  1169. del_timer_sync(&dev_priv->gpu_error.hangcheck_timer);
  1170. dev_priv->pm.suspended = true;
  1171. /*
  1172. * FIXME: We really should find a document that references the arguments
  1173. * used below!
  1174. */
  1175. if (IS_HASWELL(dev)) {
  1176. /*
  1177. * current versions of firmware which depend on this opregion
  1178. * notification have repurposed the D1 definition to mean
  1179. * "runtime suspended" vs. what you would normally expect (D3)
  1180. * to distinguish it from notifications that might be sent via
  1181. * the suspend path.
  1182. */
  1183. intel_opregion_notify_adapter(dev, PCI_D1);
  1184. } else {
  1185. /*
  1186. * On Broadwell, if we use PCI_D1 the PCH DDI ports will stop
  1187. * being detected, and the call we do at intel_runtime_resume()
  1188. * won't be able to restore them. Since PCI_D3hot matches the
  1189. * actual specification and appears to be working, use it. Let's
  1190. * assume the other non-Haswell platforms will stay the same as
  1191. * Broadwell.
  1192. */
  1193. intel_opregion_notify_adapter(dev, PCI_D3hot);
  1194. }
  1195. DRM_DEBUG_KMS("Device suspended\n");
  1196. return 0;
  1197. }
  1198. static int intel_runtime_resume(struct device *device)
  1199. {
  1200. struct pci_dev *pdev = to_pci_dev(device);
  1201. struct drm_device *dev = pci_get_drvdata(pdev);
  1202. struct drm_i915_private *dev_priv = dev->dev_private;
  1203. int ret = 0;
  1204. if (WARN_ON_ONCE(!HAS_RUNTIME_PM(dev)))
  1205. return -ENODEV;
  1206. DRM_DEBUG_KMS("Resuming device\n");
  1207. intel_opregion_notify_adapter(dev, PCI_D0);
  1208. dev_priv->pm.suspended = false;
  1209. if (IS_GEN6(dev_priv))
  1210. intel_init_pch_refclk(dev);
  1211. else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
  1212. hsw_disable_pc8(dev_priv);
  1213. else if (IS_VALLEYVIEW(dev_priv))
  1214. ret = vlv_resume_prepare(dev_priv, true);
  1215. /*
  1216. * No point of rolling back things in case of an error, as the best
  1217. * we can do is to hope that things will still work (and disable RPM).
  1218. */
  1219. i915_gem_init_swizzling(dev);
  1220. gen6_update_ring_freq(dev);
  1221. intel_runtime_pm_enable_interrupts(dev_priv);
  1222. intel_enable_gt_powersave(dev);
  1223. if (ret)
  1224. DRM_ERROR("Runtime resume failed, disabling it (%d)\n", ret);
  1225. else
  1226. DRM_DEBUG_KMS("Device resumed\n");
  1227. return ret;
  1228. }
  1229. /*
  1230. * This function implements common functionality of runtime and system
  1231. * suspend sequence.
  1232. */
  1233. static int intel_suspend_complete(struct drm_i915_private *dev_priv)
  1234. {
  1235. struct drm_device *dev = dev_priv->dev;
  1236. int ret;
  1237. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  1238. ret = hsw_suspend_complete(dev_priv);
  1239. else if (IS_VALLEYVIEW(dev))
  1240. ret = vlv_suspend_complete(dev_priv);
  1241. else
  1242. ret = 0;
  1243. return ret;
  1244. }
  1245. static const struct dev_pm_ops i915_pm_ops = {
  1246. /*
  1247. * S0ix (via system suspend) and S3 event handlers [PMSG_SUSPEND,
  1248. * PMSG_RESUME]
  1249. */
  1250. .suspend = i915_pm_suspend,
  1251. .suspend_late = i915_pm_suspend_late,
  1252. .resume_early = i915_pm_resume_early,
  1253. .resume = i915_pm_resume,
  1254. /*
  1255. * S4 event handlers
  1256. * @freeze, @freeze_late : called (1) before creating the
  1257. * hibernation image [PMSG_FREEZE] and
  1258. * (2) after rebooting, before restoring
  1259. * the image [PMSG_QUIESCE]
  1260. * @thaw, @thaw_early : called (1) after creating the hibernation
  1261. * image, before writing it [PMSG_THAW]
  1262. * and (2) after failing to create or
  1263. * restore the image [PMSG_RECOVER]
  1264. * @poweroff, @poweroff_late: called after writing the hibernation
  1265. * image, before rebooting [PMSG_HIBERNATE]
  1266. * @restore, @restore_early : called after rebooting and restoring the
  1267. * hibernation image [PMSG_RESTORE]
  1268. */
  1269. .freeze = i915_pm_suspend,
  1270. .freeze_late = i915_pm_suspend_late,
  1271. .thaw_early = i915_pm_resume_early,
  1272. .thaw = i915_pm_resume,
  1273. .poweroff = i915_pm_suspend,
  1274. .poweroff_late = i915_pm_suspend_late,
  1275. .restore_early = i915_pm_resume_early,
  1276. .restore = i915_pm_resume,
  1277. /* S0ix (via runtime suspend) event handlers */
  1278. .runtime_suspend = intel_runtime_suspend,
  1279. .runtime_resume = intel_runtime_resume,
  1280. };
  1281. static const struct vm_operations_struct i915_gem_vm_ops = {
  1282. .fault = i915_gem_fault,
  1283. .open = drm_gem_vm_open,
  1284. .close = drm_gem_vm_close,
  1285. };
  1286. static const struct file_operations i915_driver_fops = {
  1287. .owner = THIS_MODULE,
  1288. .open = drm_open,
  1289. .release = drm_release,
  1290. .unlocked_ioctl = drm_ioctl,
  1291. .mmap = drm_gem_mmap,
  1292. .poll = drm_poll,
  1293. .read = drm_read,
  1294. #ifdef CONFIG_COMPAT
  1295. .compat_ioctl = i915_compat_ioctl,
  1296. #endif
  1297. .llseek = noop_llseek,
  1298. };
  1299. static struct drm_driver driver = {
  1300. /* Don't use MTRRs here; the Xserver or userspace app should
  1301. * deal with them for Intel hardware.
  1302. */
  1303. .driver_features =
  1304. DRIVER_USE_AGP |
  1305. DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_GEM | DRIVER_PRIME |
  1306. DRIVER_RENDER,
  1307. .load = i915_driver_load,
  1308. .unload = i915_driver_unload,
  1309. .open = i915_driver_open,
  1310. .lastclose = i915_driver_lastclose,
  1311. .preclose = i915_driver_preclose,
  1312. .postclose = i915_driver_postclose,
  1313. .set_busid = drm_pci_set_busid,
  1314. /* Used in place of i915_pm_ops for non-DRIVER_MODESET */
  1315. .suspend = i915_suspend_legacy,
  1316. .resume = i915_resume_legacy,
  1317. .device_is_agp = i915_driver_device_is_agp,
  1318. #if defined(CONFIG_DEBUG_FS)
  1319. .debugfs_init = i915_debugfs_init,
  1320. .debugfs_cleanup = i915_debugfs_cleanup,
  1321. #endif
  1322. .gem_free_object = i915_gem_free_object,
  1323. .gem_vm_ops = &i915_gem_vm_ops,
  1324. .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
  1325. .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
  1326. .gem_prime_export = i915_gem_prime_export,
  1327. .gem_prime_import = i915_gem_prime_import,
  1328. .dumb_create = i915_gem_dumb_create,
  1329. .dumb_map_offset = i915_gem_mmap_gtt,
  1330. .dumb_destroy = drm_gem_dumb_destroy,
  1331. .ioctls = i915_ioctls,
  1332. .fops = &i915_driver_fops,
  1333. .name = DRIVER_NAME,
  1334. .desc = DRIVER_DESC,
  1335. .date = DRIVER_DATE,
  1336. .major = DRIVER_MAJOR,
  1337. .minor = DRIVER_MINOR,
  1338. .patchlevel = DRIVER_PATCHLEVEL,
  1339. };
  1340. static struct pci_driver i915_pci_driver = {
  1341. .name = DRIVER_NAME,
  1342. .id_table = pciidlist,
  1343. .probe = i915_pci_probe,
  1344. .remove = i915_pci_remove,
  1345. .driver.pm = &i915_pm_ops,
  1346. };
  1347. static int __init i915_init(void)
  1348. {
  1349. driver.num_ioctls = i915_max_ioctl;
  1350. /*
  1351. * If CONFIG_DRM_I915_KMS is set, default to KMS unless
  1352. * explicitly disabled with the module pararmeter.
  1353. *
  1354. * Otherwise, just follow the parameter (defaulting to off).
  1355. *
  1356. * Allow optional vga_text_mode_force boot option to override
  1357. * the default behavior.
  1358. */
  1359. #if defined(CONFIG_DRM_I915_KMS)
  1360. if (i915.modeset != 0)
  1361. driver.driver_features |= DRIVER_MODESET;
  1362. #endif
  1363. if (i915.modeset == 1)
  1364. driver.driver_features |= DRIVER_MODESET;
  1365. #ifdef CONFIG_VGA_CONSOLE
  1366. if (vgacon_text_force() && i915.modeset == -1)
  1367. driver.driver_features &= ~DRIVER_MODESET;
  1368. #endif
  1369. if (!(driver.driver_features & DRIVER_MODESET)) {
  1370. driver.get_vblank_timestamp = NULL;
  1371. #ifndef CONFIG_DRM_I915_UMS
  1372. /* Silently fail loading to not upset userspace. */
  1373. DRM_DEBUG_DRIVER("KMS and UMS disabled.\n");
  1374. return 0;
  1375. #endif
  1376. }
  1377. return drm_pci_init(&driver, &i915_pci_driver);
  1378. }
  1379. static void __exit i915_exit(void)
  1380. {
  1381. #ifndef CONFIG_DRM_I915_UMS
  1382. if (!(driver.driver_features & DRIVER_MODESET))
  1383. return; /* Never loaded a driver. */
  1384. #endif
  1385. drm_pci_exit(&driver, &i915_pci_driver);
  1386. }
  1387. module_init(i915_init);
  1388. module_exit(i915_exit);
  1389. MODULE_AUTHOR("Tungsten Graphics, Inc.");
  1390. MODULE_AUTHOR("Intel Corporation");
  1391. MODULE_DESCRIPTION(DRIVER_DESC);
  1392. MODULE_LICENSE("GPL and additional rights");