i915_drv.c 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786
  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. .gen = 8, .num_pipes = 3,
  315. .need_gfx_hws = 1, .has_hotplug = 1,
  316. .ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING,
  317. .is_valleyview = 1,
  318. .display_mmio_offset = VLV_DISPLAY_BASE,
  319. GEN_CHV_PIPEOFFSETS,
  320. CURSOR_OFFSETS,
  321. };
  322. static const struct intel_device_info intel_skylake_info = {
  323. .is_skylake = 1,
  324. .gen = 9, .num_pipes = 3,
  325. .need_gfx_hws = 1, .has_hotplug = 1,
  326. .ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING,
  327. .has_llc = 1,
  328. .has_ddi = 1,
  329. .has_fpga_dbg = 1,
  330. .has_fbc = 1,
  331. GEN_DEFAULT_PIPEOFFSETS,
  332. IVB_CURSOR_OFFSETS,
  333. };
  334. static const struct intel_device_info intel_skylake_gt3_info = {
  335. .is_skylake = 1,
  336. .gen = 9, .num_pipes = 3,
  337. .need_gfx_hws = 1, .has_hotplug = 1,
  338. .ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING | BSD2_RING,
  339. .has_llc = 1,
  340. .has_ddi = 1,
  341. .has_fpga_dbg = 1,
  342. .has_fbc = 1,
  343. GEN_DEFAULT_PIPEOFFSETS,
  344. IVB_CURSOR_OFFSETS,
  345. };
  346. static const struct intel_device_info intel_broxton_info = {
  347. .is_preliminary = 1,
  348. .gen = 9,
  349. .need_gfx_hws = 1, .has_hotplug = 1,
  350. .ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING,
  351. .num_pipes = 3,
  352. .has_ddi = 1,
  353. .has_fpga_dbg = 1,
  354. .has_fbc = 1,
  355. GEN_DEFAULT_PIPEOFFSETS,
  356. IVB_CURSOR_OFFSETS,
  357. };
  358. /*
  359. * Make sure any device matches here are from most specific to most
  360. * general. For example, since the Quanta match is based on the subsystem
  361. * and subvendor IDs, we need it to come before the more general IVB
  362. * PCI ID matches, otherwise we'll use the wrong info struct above.
  363. */
  364. #define INTEL_PCI_IDS \
  365. INTEL_I830_IDS(&intel_i830_info), \
  366. INTEL_I845G_IDS(&intel_845g_info), \
  367. INTEL_I85X_IDS(&intel_i85x_info), \
  368. INTEL_I865G_IDS(&intel_i865g_info), \
  369. INTEL_I915G_IDS(&intel_i915g_info), \
  370. INTEL_I915GM_IDS(&intel_i915gm_info), \
  371. INTEL_I945G_IDS(&intel_i945g_info), \
  372. INTEL_I945GM_IDS(&intel_i945gm_info), \
  373. INTEL_I965G_IDS(&intel_i965g_info), \
  374. INTEL_G33_IDS(&intel_g33_info), \
  375. INTEL_I965GM_IDS(&intel_i965gm_info), \
  376. INTEL_GM45_IDS(&intel_gm45_info), \
  377. INTEL_G45_IDS(&intel_g45_info), \
  378. INTEL_PINEVIEW_IDS(&intel_pineview_info), \
  379. INTEL_IRONLAKE_D_IDS(&intel_ironlake_d_info), \
  380. INTEL_IRONLAKE_M_IDS(&intel_ironlake_m_info), \
  381. INTEL_SNB_D_IDS(&intel_sandybridge_d_info), \
  382. INTEL_SNB_M_IDS(&intel_sandybridge_m_info), \
  383. INTEL_IVB_Q_IDS(&intel_ivybridge_q_info), /* must be first IVB */ \
  384. INTEL_IVB_M_IDS(&intel_ivybridge_m_info), \
  385. INTEL_IVB_D_IDS(&intel_ivybridge_d_info), \
  386. INTEL_HSW_D_IDS(&intel_haswell_d_info), \
  387. INTEL_HSW_M_IDS(&intel_haswell_m_info), \
  388. INTEL_VLV_M_IDS(&intel_valleyview_m_info), \
  389. INTEL_VLV_D_IDS(&intel_valleyview_d_info), \
  390. INTEL_BDW_GT12M_IDS(&intel_broadwell_m_info), \
  391. INTEL_BDW_GT12D_IDS(&intel_broadwell_d_info), \
  392. INTEL_BDW_GT3M_IDS(&intel_broadwell_gt3m_info), \
  393. INTEL_BDW_GT3D_IDS(&intel_broadwell_gt3d_info), \
  394. INTEL_CHV_IDS(&intel_cherryview_info), \
  395. INTEL_SKL_GT1_IDS(&intel_skylake_info), \
  396. INTEL_SKL_GT2_IDS(&intel_skylake_info), \
  397. INTEL_SKL_GT3_IDS(&intel_skylake_gt3_info), \
  398. INTEL_BXT_IDS(&intel_broxton_info)
  399. static const struct pci_device_id pciidlist[] = { /* aka */
  400. INTEL_PCI_IDS,
  401. {0, 0, 0}
  402. };
  403. MODULE_DEVICE_TABLE(pci, pciidlist);
  404. static enum intel_pch intel_virt_detect_pch(struct drm_device *dev)
  405. {
  406. enum intel_pch ret = PCH_NOP;
  407. /*
  408. * In a virtualized passthrough environment we can be in a
  409. * setup where the ISA bridge is not able to be passed through.
  410. * In this case, a south bridge can be emulated and we have to
  411. * make an educated guess as to which PCH is really there.
  412. */
  413. if (IS_GEN5(dev)) {
  414. ret = PCH_IBX;
  415. DRM_DEBUG_KMS("Assuming Ibex Peak PCH\n");
  416. } else if (IS_GEN6(dev) || IS_IVYBRIDGE(dev)) {
  417. ret = PCH_CPT;
  418. DRM_DEBUG_KMS("Assuming CouarPoint PCH\n");
  419. } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  420. ret = PCH_LPT;
  421. DRM_DEBUG_KMS("Assuming LynxPoint PCH\n");
  422. } else if (IS_SKYLAKE(dev)) {
  423. ret = PCH_SPT;
  424. DRM_DEBUG_KMS("Assuming SunrisePoint PCH\n");
  425. }
  426. return ret;
  427. }
  428. void intel_detect_pch(struct drm_device *dev)
  429. {
  430. struct drm_i915_private *dev_priv = dev->dev_private;
  431. struct pci_dev *pch = NULL;
  432. /* In all current cases, num_pipes is equivalent to the PCH_NOP setting
  433. * (which really amounts to a PCH but no South Display).
  434. */
  435. if (INTEL_INFO(dev)->num_pipes == 0) {
  436. dev_priv->pch_type = PCH_NOP;
  437. return;
  438. }
  439. /*
  440. * The reason to probe ISA bridge instead of Dev31:Fun0 is to
  441. * make graphics device passthrough work easy for VMM, that only
  442. * need to expose ISA bridge to let driver know the real hardware
  443. * underneath. This is a requirement from virtualization team.
  444. *
  445. * In some virtualized environments (e.g. XEN), there is irrelevant
  446. * ISA bridge in the system. To work reliably, we should scan trhough
  447. * all the ISA bridge devices and check for the first match, instead
  448. * of only checking the first one.
  449. */
  450. while ((pch = pci_get_class(PCI_CLASS_BRIDGE_ISA << 8, pch))) {
  451. if (pch->vendor == PCI_VENDOR_ID_INTEL) {
  452. unsigned short id = pch->device & INTEL_PCH_DEVICE_ID_MASK;
  453. dev_priv->pch_id = id;
  454. if (id == INTEL_PCH_IBX_DEVICE_ID_TYPE) {
  455. dev_priv->pch_type = PCH_IBX;
  456. DRM_DEBUG_KMS("Found Ibex Peak PCH\n");
  457. WARN_ON(!IS_GEN5(dev));
  458. } else if (id == INTEL_PCH_CPT_DEVICE_ID_TYPE) {
  459. dev_priv->pch_type = PCH_CPT;
  460. DRM_DEBUG_KMS("Found CougarPoint PCH\n");
  461. WARN_ON(!(IS_GEN6(dev) || IS_IVYBRIDGE(dev)));
  462. } else if (id == INTEL_PCH_PPT_DEVICE_ID_TYPE) {
  463. /* PantherPoint is CPT compatible */
  464. dev_priv->pch_type = PCH_CPT;
  465. DRM_DEBUG_KMS("Found PantherPoint PCH\n");
  466. WARN_ON(!(IS_GEN6(dev) || IS_IVYBRIDGE(dev)));
  467. } else if (id == INTEL_PCH_LPT_DEVICE_ID_TYPE) {
  468. dev_priv->pch_type = PCH_LPT;
  469. DRM_DEBUG_KMS("Found LynxPoint PCH\n");
  470. WARN_ON(!IS_HASWELL(dev) && !IS_BROADWELL(dev));
  471. WARN_ON(IS_HSW_ULT(dev) || IS_BDW_ULT(dev));
  472. } else if (id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) {
  473. dev_priv->pch_type = PCH_LPT;
  474. DRM_DEBUG_KMS("Found LynxPoint LP PCH\n");
  475. WARN_ON(!IS_HASWELL(dev) && !IS_BROADWELL(dev));
  476. WARN_ON(!IS_HSW_ULT(dev) && !IS_BDW_ULT(dev));
  477. } else if (id == INTEL_PCH_SPT_DEVICE_ID_TYPE) {
  478. dev_priv->pch_type = PCH_SPT;
  479. DRM_DEBUG_KMS("Found SunrisePoint PCH\n");
  480. WARN_ON(!IS_SKYLAKE(dev));
  481. } else if (id == INTEL_PCH_SPT_LP_DEVICE_ID_TYPE) {
  482. dev_priv->pch_type = PCH_SPT;
  483. DRM_DEBUG_KMS("Found SunrisePoint LP PCH\n");
  484. WARN_ON(!IS_SKYLAKE(dev));
  485. } else if ((id == INTEL_PCH_P2X_DEVICE_ID_TYPE) ||
  486. ((id == INTEL_PCH_QEMU_DEVICE_ID_TYPE) &&
  487. pch->subsystem_vendor == 0x1af4 &&
  488. pch->subsystem_device == 0x1100)) {
  489. dev_priv->pch_type = intel_virt_detect_pch(dev);
  490. } else
  491. continue;
  492. break;
  493. }
  494. }
  495. if (!pch)
  496. DRM_DEBUG_KMS("No PCH found.\n");
  497. pci_dev_put(pch);
  498. }
  499. bool i915_semaphore_is_enabled(struct drm_device *dev)
  500. {
  501. if (INTEL_INFO(dev)->gen < 6)
  502. return false;
  503. if (i915.semaphores >= 0)
  504. return i915.semaphores;
  505. /* TODO: make semaphores and Execlists play nicely together */
  506. if (i915.enable_execlists)
  507. return false;
  508. /* Until we get further testing... */
  509. if (IS_GEN8(dev))
  510. return false;
  511. #ifdef CONFIG_INTEL_IOMMU
  512. /* Enable semaphores on SNB when IO remapping is off */
  513. if (INTEL_INFO(dev)->gen == 6 && intel_iommu_gfx_mapped)
  514. return false;
  515. #endif
  516. return true;
  517. }
  518. void i915_firmware_load_error_print(const char *fw_path, int err)
  519. {
  520. DRM_ERROR("failed to load firmware %s (%d)\n", fw_path, err);
  521. /*
  522. * If the reason is not known assume -ENOENT since that's the most
  523. * usual failure mode.
  524. */
  525. if (!err)
  526. err = -ENOENT;
  527. if (!(IS_BUILTIN(CONFIG_DRM_I915) && err == -ENOENT))
  528. return;
  529. DRM_ERROR(
  530. "The driver is built-in, so to load the firmware you need to\n"
  531. "include it either in the kernel (see CONFIG_EXTRA_FIRMWARE) or\n"
  532. "in your initrd/initramfs image.\n");
  533. }
  534. static void intel_suspend_encoders(struct drm_i915_private *dev_priv)
  535. {
  536. struct drm_device *dev = dev_priv->dev;
  537. struct drm_encoder *encoder;
  538. drm_modeset_lock_all(dev);
  539. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  540. struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
  541. if (intel_encoder->suspend)
  542. intel_encoder->suspend(intel_encoder);
  543. }
  544. drm_modeset_unlock_all(dev);
  545. }
  546. static int intel_suspend_complete(struct drm_i915_private *dev_priv);
  547. static int vlv_resume_prepare(struct drm_i915_private *dev_priv,
  548. bool rpm_resume);
  549. static int skl_resume_prepare(struct drm_i915_private *dev_priv);
  550. static int bxt_resume_prepare(struct drm_i915_private *dev_priv);
  551. static int i915_drm_suspend(struct drm_device *dev)
  552. {
  553. struct drm_i915_private *dev_priv = dev->dev_private;
  554. pci_power_t opregion_target_state;
  555. int error;
  556. /* ignore lid events during suspend */
  557. mutex_lock(&dev_priv->modeset_restore_lock);
  558. dev_priv->modeset_restore = MODESET_SUSPENDED;
  559. mutex_unlock(&dev_priv->modeset_restore_lock);
  560. /* We do a lot of poking in a lot of registers, make sure they work
  561. * properly. */
  562. intel_display_set_init_power(dev_priv, true);
  563. drm_kms_helper_poll_disable(dev);
  564. pci_save_state(dev->pdev);
  565. error = i915_gem_suspend(dev);
  566. if (error) {
  567. dev_err(&dev->pdev->dev,
  568. "GEM idle failed, resume might fail\n");
  569. return error;
  570. }
  571. intel_guc_suspend(dev);
  572. intel_suspend_gt_powersave(dev);
  573. /*
  574. * Disable CRTCs directly since we want to preserve sw state
  575. * for _thaw. Also, power gate the CRTC power wells.
  576. */
  577. drm_modeset_lock_all(dev);
  578. intel_display_suspend(dev);
  579. drm_modeset_unlock_all(dev);
  580. intel_dp_mst_suspend(dev);
  581. intel_runtime_pm_disable_interrupts(dev_priv);
  582. intel_hpd_cancel_work(dev_priv);
  583. intel_suspend_encoders(dev_priv);
  584. intel_suspend_hw(dev);
  585. i915_gem_suspend_gtt_mappings(dev);
  586. i915_save_state(dev);
  587. opregion_target_state = PCI_D3cold;
  588. #if IS_ENABLED(CONFIG_ACPI_SLEEP)
  589. if (acpi_target_system_state() < ACPI_STATE_S3)
  590. opregion_target_state = PCI_D1;
  591. #endif
  592. intel_opregion_notify_adapter(dev, opregion_target_state);
  593. intel_uncore_forcewake_reset(dev, false);
  594. intel_opregion_fini(dev);
  595. intel_fbdev_set_suspend(dev, FBINFO_STATE_SUSPENDED, true);
  596. dev_priv->suspend_count++;
  597. intel_display_set_init_power(dev_priv, false);
  598. return 0;
  599. }
  600. static int i915_drm_suspend_late(struct drm_device *drm_dev, bool hibernation)
  601. {
  602. struct drm_i915_private *dev_priv = drm_dev->dev_private;
  603. int ret;
  604. ret = intel_suspend_complete(dev_priv);
  605. if (ret) {
  606. DRM_ERROR("Suspend complete failed: %d\n", ret);
  607. return ret;
  608. }
  609. pci_disable_device(drm_dev->pdev);
  610. /*
  611. * During hibernation on some platforms the BIOS may try to access
  612. * the device even though it's already in D3 and hang the machine. So
  613. * leave the device in D0 on those platforms and hope the BIOS will
  614. * power down the device properly. The issue was seen on multiple old
  615. * GENs with different BIOS vendors, so having an explicit blacklist
  616. * is inpractical; apply the workaround on everything pre GEN6. The
  617. * platforms where the issue was seen:
  618. * Lenovo Thinkpad X301, X61s, X60, T60, X41
  619. * Fujitsu FSC S7110
  620. * Acer Aspire 1830T
  621. */
  622. if (!(hibernation && INTEL_INFO(dev_priv)->gen < 6))
  623. pci_set_power_state(drm_dev->pdev, PCI_D3hot);
  624. return 0;
  625. }
  626. int i915_suspend_switcheroo(struct drm_device *dev, pm_message_t state)
  627. {
  628. int error;
  629. if (!dev || !dev->dev_private) {
  630. DRM_ERROR("dev: %p\n", dev);
  631. DRM_ERROR("DRM not initialized, aborting suspend.\n");
  632. return -ENODEV;
  633. }
  634. if (WARN_ON_ONCE(state.event != PM_EVENT_SUSPEND &&
  635. state.event != PM_EVENT_FREEZE))
  636. return -EINVAL;
  637. if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
  638. return 0;
  639. error = i915_drm_suspend(dev);
  640. if (error)
  641. return error;
  642. return i915_drm_suspend_late(dev, false);
  643. }
  644. static int i915_drm_resume(struct drm_device *dev)
  645. {
  646. struct drm_i915_private *dev_priv = dev->dev_private;
  647. mutex_lock(&dev->struct_mutex);
  648. i915_gem_restore_gtt_mappings(dev);
  649. mutex_unlock(&dev->struct_mutex);
  650. i915_restore_state(dev);
  651. intel_opregion_setup(dev);
  652. intel_init_pch_refclk(dev);
  653. drm_mode_config_reset(dev);
  654. /*
  655. * Interrupts have to be enabled before any batches are run. If not the
  656. * GPU will hang. i915_gem_init_hw() will initiate batches to
  657. * update/restore the context.
  658. *
  659. * Modeset enabling in intel_modeset_init_hw() also needs working
  660. * interrupts.
  661. */
  662. intel_runtime_pm_enable_interrupts(dev_priv);
  663. mutex_lock(&dev->struct_mutex);
  664. if (i915_gem_init_hw(dev)) {
  665. DRM_ERROR("failed to re-initialize GPU, declaring wedged!\n");
  666. atomic_or(I915_WEDGED, &dev_priv->gpu_error.reset_counter);
  667. }
  668. mutex_unlock(&dev->struct_mutex);
  669. intel_guc_resume(dev);
  670. intel_modeset_init_hw(dev);
  671. spin_lock_irq(&dev_priv->irq_lock);
  672. if (dev_priv->display.hpd_irq_setup)
  673. dev_priv->display.hpd_irq_setup(dev);
  674. spin_unlock_irq(&dev_priv->irq_lock);
  675. drm_modeset_lock_all(dev);
  676. intel_display_resume(dev);
  677. drm_modeset_unlock_all(dev);
  678. intel_dp_mst_resume(dev);
  679. /*
  680. * ... but also need to make sure that hotplug processing
  681. * doesn't cause havoc. Like in the driver load code we don't
  682. * bother with the tiny race here where we might loose hotplug
  683. * notifications.
  684. * */
  685. intel_hpd_init(dev_priv);
  686. /* Config may have changed between suspend and resume */
  687. drm_helper_hpd_irq_event(dev);
  688. intel_opregion_init(dev);
  689. intel_fbdev_set_suspend(dev, FBINFO_STATE_RUNNING, false);
  690. mutex_lock(&dev_priv->modeset_restore_lock);
  691. dev_priv->modeset_restore = MODESET_DONE;
  692. mutex_unlock(&dev_priv->modeset_restore_lock);
  693. intel_opregion_notify_adapter(dev, PCI_D0);
  694. drm_kms_helper_poll_enable(dev);
  695. return 0;
  696. }
  697. static int i915_drm_resume_early(struct drm_device *dev)
  698. {
  699. struct drm_i915_private *dev_priv = dev->dev_private;
  700. int ret = 0;
  701. /*
  702. * We have a resume ordering issue with the snd-hda driver also
  703. * requiring our device to be power up. Due to the lack of a
  704. * parent/child relationship we currently solve this with an early
  705. * resume hook.
  706. *
  707. * FIXME: This should be solved with a special hdmi sink device or
  708. * similar so that power domains can be employed.
  709. */
  710. if (pci_enable_device(dev->pdev))
  711. return -EIO;
  712. pci_set_master(dev->pdev);
  713. if (IS_VALLEYVIEW(dev_priv))
  714. ret = vlv_resume_prepare(dev_priv, false);
  715. if (ret)
  716. DRM_ERROR("Resume prepare failed: %d, continuing anyway\n",
  717. ret);
  718. intel_uncore_early_sanitize(dev, true);
  719. if (IS_BROXTON(dev))
  720. ret = bxt_resume_prepare(dev_priv);
  721. else if (IS_SKYLAKE(dev_priv))
  722. ret = skl_resume_prepare(dev_priv);
  723. else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
  724. hsw_disable_pc8(dev_priv);
  725. intel_uncore_sanitize(dev);
  726. intel_power_domains_init_hw(dev_priv);
  727. return ret;
  728. }
  729. int i915_resume_switcheroo(struct drm_device *dev)
  730. {
  731. int ret;
  732. if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
  733. return 0;
  734. ret = i915_drm_resume_early(dev);
  735. if (ret)
  736. return ret;
  737. return i915_drm_resume(dev);
  738. }
  739. /**
  740. * i915_reset - reset chip after a hang
  741. * @dev: drm device to reset
  742. *
  743. * Reset the chip. Useful if a hang is detected. Returns zero on successful
  744. * reset or otherwise an error code.
  745. *
  746. * Procedure is fairly simple:
  747. * - reset the chip using the reset reg
  748. * - re-init context state
  749. * - re-init hardware status page
  750. * - re-init ring buffer
  751. * - re-init interrupt state
  752. * - re-init display
  753. */
  754. int i915_reset(struct drm_device *dev)
  755. {
  756. struct drm_i915_private *dev_priv = dev->dev_private;
  757. bool simulated;
  758. int ret;
  759. intel_reset_gt_powersave(dev);
  760. mutex_lock(&dev->struct_mutex);
  761. i915_gem_reset(dev);
  762. simulated = dev_priv->gpu_error.stop_rings != 0;
  763. ret = intel_gpu_reset(dev);
  764. /* Also reset the gpu hangman. */
  765. if (simulated) {
  766. DRM_INFO("Simulated gpu hang, resetting stop_rings\n");
  767. dev_priv->gpu_error.stop_rings = 0;
  768. if (ret == -ENODEV) {
  769. DRM_INFO("Reset not implemented, but ignoring "
  770. "error for simulated gpu hangs\n");
  771. ret = 0;
  772. }
  773. }
  774. if (i915_stop_ring_allow_warn(dev_priv))
  775. pr_notice("drm/i915: Resetting chip after gpu hang\n");
  776. if (ret) {
  777. DRM_ERROR("Failed to reset chip: %i\n", ret);
  778. mutex_unlock(&dev->struct_mutex);
  779. return ret;
  780. }
  781. intel_overlay_reset(dev_priv);
  782. /* Ok, now get things going again... */
  783. /*
  784. * Everything depends on having the GTT running, so we need to start
  785. * there. Fortunately we don't need to do this unless we reset the
  786. * chip at a PCI level.
  787. *
  788. * Next we need to restore the context, but we don't use those
  789. * yet either...
  790. *
  791. * Ring buffer needs to be re-initialized in the KMS case, or if X
  792. * was running at the time of the reset (i.e. we weren't VT
  793. * switched away).
  794. */
  795. /* Used to prevent gem_check_wedged returning -EAGAIN during gpu reset */
  796. dev_priv->gpu_error.reload_in_reset = true;
  797. ret = i915_gem_init_hw(dev);
  798. dev_priv->gpu_error.reload_in_reset = false;
  799. mutex_unlock(&dev->struct_mutex);
  800. if (ret) {
  801. DRM_ERROR("Failed hw init on reset %d\n", ret);
  802. return ret;
  803. }
  804. /*
  805. * rps/rc6 re-init is necessary to restore state lost after the
  806. * reset and the re-install of gt irqs. Skip for ironlake per
  807. * previous concerns that it doesn't respond well to some forms
  808. * of re-init after reset.
  809. */
  810. if (INTEL_INFO(dev)->gen > 5)
  811. intel_enable_gt_powersave(dev);
  812. return 0;
  813. }
  814. static int i915_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  815. {
  816. struct intel_device_info *intel_info =
  817. (struct intel_device_info *) ent->driver_data;
  818. if (IS_PRELIMINARY_HW(intel_info) && !i915.preliminary_hw_support) {
  819. DRM_INFO("This hardware requires preliminary hardware support.\n"
  820. "See CONFIG_DRM_I915_PRELIMINARY_HW_SUPPORT, and/or modparam preliminary_hw_support\n");
  821. return -ENODEV;
  822. }
  823. /* Only bind to function 0 of the device. Early generations
  824. * used function 1 as a placeholder for multi-head. This causes
  825. * us confusion instead, especially on the systems where both
  826. * functions have the same PCI-ID!
  827. */
  828. if (PCI_FUNC(pdev->devfn))
  829. return -ENODEV;
  830. return drm_get_pci_dev(pdev, ent, &driver);
  831. }
  832. static void
  833. i915_pci_remove(struct pci_dev *pdev)
  834. {
  835. struct drm_device *dev = pci_get_drvdata(pdev);
  836. drm_put_dev(dev);
  837. }
  838. static int i915_pm_suspend(struct device *dev)
  839. {
  840. struct pci_dev *pdev = to_pci_dev(dev);
  841. struct drm_device *drm_dev = pci_get_drvdata(pdev);
  842. if (!drm_dev || !drm_dev->dev_private) {
  843. dev_err(dev, "DRM not initialized, aborting suspend.\n");
  844. return -ENODEV;
  845. }
  846. if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF)
  847. return 0;
  848. return i915_drm_suspend(drm_dev);
  849. }
  850. static int i915_pm_suspend_late(struct device *dev)
  851. {
  852. struct drm_device *drm_dev = dev_to_i915(dev)->dev;
  853. /*
  854. * We have a suspend ordering issue with the snd-hda driver also
  855. * requiring our device to be power up. Due to the lack of a
  856. * parent/child relationship we currently solve this with an late
  857. * suspend hook.
  858. *
  859. * FIXME: This should be solved with a special hdmi sink device or
  860. * similar so that power domains can be employed.
  861. */
  862. if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF)
  863. return 0;
  864. return i915_drm_suspend_late(drm_dev, false);
  865. }
  866. static int i915_pm_poweroff_late(struct device *dev)
  867. {
  868. struct drm_device *drm_dev = dev_to_i915(dev)->dev;
  869. if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF)
  870. return 0;
  871. return i915_drm_suspend_late(drm_dev, true);
  872. }
  873. static int i915_pm_resume_early(struct device *dev)
  874. {
  875. struct drm_device *drm_dev = dev_to_i915(dev)->dev;
  876. if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF)
  877. return 0;
  878. return i915_drm_resume_early(drm_dev);
  879. }
  880. static int i915_pm_resume(struct device *dev)
  881. {
  882. struct drm_device *drm_dev = dev_to_i915(dev)->dev;
  883. if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF)
  884. return 0;
  885. return i915_drm_resume(drm_dev);
  886. }
  887. static int skl_suspend_complete(struct drm_i915_private *dev_priv)
  888. {
  889. /* Enabling DC6 is not a hard requirement to enter runtime D3 */
  890. skl_uninit_cdclk(dev_priv);
  891. return 0;
  892. }
  893. static int hsw_suspend_complete(struct drm_i915_private *dev_priv)
  894. {
  895. hsw_enable_pc8(dev_priv);
  896. return 0;
  897. }
  898. static int bxt_suspend_complete(struct drm_i915_private *dev_priv)
  899. {
  900. struct drm_device *dev = dev_priv->dev;
  901. /* TODO: when DC5 support is added disable DC5 here. */
  902. broxton_ddi_phy_uninit(dev);
  903. broxton_uninit_cdclk(dev);
  904. bxt_enable_dc9(dev_priv);
  905. return 0;
  906. }
  907. static int bxt_resume_prepare(struct drm_i915_private *dev_priv)
  908. {
  909. struct drm_device *dev = dev_priv->dev;
  910. /* TODO: when CSR FW support is added make sure the FW is loaded */
  911. bxt_disable_dc9(dev_priv);
  912. /*
  913. * TODO: when DC5 support is added enable DC5 here if the CSR FW
  914. * is available.
  915. */
  916. broxton_init_cdclk(dev);
  917. broxton_ddi_phy_init(dev);
  918. intel_prepare_ddi(dev);
  919. return 0;
  920. }
  921. static int skl_resume_prepare(struct drm_i915_private *dev_priv)
  922. {
  923. struct drm_device *dev = dev_priv->dev;
  924. skl_init_cdclk(dev_priv);
  925. intel_csr_load_program(dev);
  926. return 0;
  927. }
  928. /*
  929. * Save all Gunit registers that may be lost after a D3 and a subsequent
  930. * S0i[R123] transition. The list of registers needing a save/restore is
  931. * defined in the VLV2_S0IXRegs document. This documents marks all Gunit
  932. * registers in the following way:
  933. * - Driver: saved/restored by the driver
  934. * - Punit : saved/restored by the Punit firmware
  935. * - No, w/o marking: no need to save/restore, since the register is R/O or
  936. * used internally by the HW in a way that doesn't depend
  937. * keeping the content across a suspend/resume.
  938. * - Debug : used for debugging
  939. *
  940. * We save/restore all registers marked with 'Driver', with the following
  941. * exceptions:
  942. * - Registers out of use, including also registers marked with 'Debug'.
  943. * These have no effect on the driver's operation, so we don't save/restore
  944. * them to reduce the overhead.
  945. * - Registers that are fully setup by an initialization function called from
  946. * the resume path. For example many clock gating and RPS/RC6 registers.
  947. * - Registers that provide the right functionality with their reset defaults.
  948. *
  949. * TODO: Except for registers that based on the above 3 criteria can be safely
  950. * ignored, we save/restore all others, practically treating the HW context as
  951. * a black-box for the driver. Further investigation is needed to reduce the
  952. * saved/restored registers even further, by following the same 3 criteria.
  953. */
  954. static void vlv_save_gunit_s0ix_state(struct drm_i915_private *dev_priv)
  955. {
  956. struct vlv_s0ix_state *s = &dev_priv->vlv_s0ix_state;
  957. int i;
  958. /* GAM 0x4000-0x4770 */
  959. s->wr_watermark = I915_READ(GEN7_WR_WATERMARK);
  960. s->gfx_prio_ctrl = I915_READ(GEN7_GFX_PRIO_CTRL);
  961. s->arb_mode = I915_READ(ARB_MODE);
  962. s->gfx_pend_tlb0 = I915_READ(GEN7_GFX_PEND_TLB0);
  963. s->gfx_pend_tlb1 = I915_READ(GEN7_GFX_PEND_TLB1);
  964. for (i = 0; i < ARRAY_SIZE(s->lra_limits); i++)
  965. s->lra_limits[i] = I915_READ(GEN7_LRA_LIMITS(i));
  966. s->media_max_req_count = I915_READ(GEN7_MEDIA_MAX_REQ_COUNT);
  967. s->gfx_max_req_count = I915_READ(GEN7_GFX_MAX_REQ_COUNT);
  968. s->render_hwsp = I915_READ(RENDER_HWS_PGA_GEN7);
  969. s->ecochk = I915_READ(GAM_ECOCHK);
  970. s->bsd_hwsp = I915_READ(BSD_HWS_PGA_GEN7);
  971. s->blt_hwsp = I915_READ(BLT_HWS_PGA_GEN7);
  972. s->tlb_rd_addr = I915_READ(GEN7_TLB_RD_ADDR);
  973. /* MBC 0x9024-0x91D0, 0x8500 */
  974. s->g3dctl = I915_READ(VLV_G3DCTL);
  975. s->gsckgctl = I915_READ(VLV_GSCKGCTL);
  976. s->mbctl = I915_READ(GEN6_MBCTL);
  977. /* GCP 0x9400-0x9424, 0x8100-0x810C */
  978. s->ucgctl1 = I915_READ(GEN6_UCGCTL1);
  979. s->ucgctl3 = I915_READ(GEN6_UCGCTL3);
  980. s->rcgctl1 = I915_READ(GEN6_RCGCTL1);
  981. s->rcgctl2 = I915_READ(GEN6_RCGCTL2);
  982. s->rstctl = I915_READ(GEN6_RSTCTL);
  983. s->misccpctl = I915_READ(GEN7_MISCCPCTL);
  984. /* GPM 0xA000-0xAA84, 0x8000-0x80FC */
  985. s->gfxpause = I915_READ(GEN6_GFXPAUSE);
  986. s->rpdeuhwtc = I915_READ(GEN6_RPDEUHWTC);
  987. s->rpdeuc = I915_READ(GEN6_RPDEUC);
  988. s->ecobus = I915_READ(ECOBUS);
  989. s->pwrdwnupctl = I915_READ(VLV_PWRDWNUPCTL);
  990. s->rp_down_timeout = I915_READ(GEN6_RP_DOWN_TIMEOUT);
  991. s->rp_deucsw = I915_READ(GEN6_RPDEUCSW);
  992. s->rcubmabdtmr = I915_READ(GEN6_RCUBMABDTMR);
  993. s->rcedata = I915_READ(VLV_RCEDATA);
  994. s->spare2gh = I915_READ(VLV_SPAREG2H);
  995. /* Display CZ domain, 0x4400C-0x4402C, 0x4F000-0x4F11F */
  996. s->gt_imr = I915_READ(GTIMR);
  997. s->gt_ier = I915_READ(GTIER);
  998. s->pm_imr = I915_READ(GEN6_PMIMR);
  999. s->pm_ier = I915_READ(GEN6_PMIER);
  1000. for (i = 0; i < ARRAY_SIZE(s->gt_scratch); i++)
  1001. s->gt_scratch[i] = I915_READ(GEN7_GT_SCRATCH(i));
  1002. /* GT SA CZ domain, 0x100000-0x138124 */
  1003. s->tilectl = I915_READ(TILECTL);
  1004. s->gt_fifoctl = I915_READ(GTFIFOCTL);
  1005. s->gtlc_wake_ctrl = I915_READ(VLV_GTLC_WAKE_CTRL);
  1006. s->gtlc_survive = I915_READ(VLV_GTLC_SURVIVABILITY_REG);
  1007. s->pmwgicz = I915_READ(VLV_PMWGICZ);
  1008. /* Gunit-Display CZ domain, 0x182028-0x1821CF */
  1009. s->gu_ctl0 = I915_READ(VLV_GU_CTL0);
  1010. s->gu_ctl1 = I915_READ(VLV_GU_CTL1);
  1011. s->pcbr = I915_READ(VLV_PCBR);
  1012. s->clock_gate_dis2 = I915_READ(VLV_GUNIT_CLOCK_GATE2);
  1013. /*
  1014. * Not saving any of:
  1015. * DFT, 0x9800-0x9EC0
  1016. * SARB, 0xB000-0xB1FC
  1017. * GAC, 0x5208-0x524C, 0x14000-0x14C000
  1018. * PCI CFG
  1019. */
  1020. }
  1021. static void vlv_restore_gunit_s0ix_state(struct drm_i915_private *dev_priv)
  1022. {
  1023. struct vlv_s0ix_state *s = &dev_priv->vlv_s0ix_state;
  1024. u32 val;
  1025. int i;
  1026. /* GAM 0x4000-0x4770 */
  1027. I915_WRITE(GEN7_WR_WATERMARK, s->wr_watermark);
  1028. I915_WRITE(GEN7_GFX_PRIO_CTRL, s->gfx_prio_ctrl);
  1029. I915_WRITE(ARB_MODE, s->arb_mode | (0xffff << 16));
  1030. I915_WRITE(GEN7_GFX_PEND_TLB0, s->gfx_pend_tlb0);
  1031. I915_WRITE(GEN7_GFX_PEND_TLB1, s->gfx_pend_tlb1);
  1032. for (i = 0; i < ARRAY_SIZE(s->lra_limits); i++)
  1033. I915_WRITE(GEN7_LRA_LIMITS(i), s->lra_limits[i]);
  1034. I915_WRITE(GEN7_MEDIA_MAX_REQ_COUNT, s->media_max_req_count);
  1035. I915_WRITE(GEN7_GFX_MAX_REQ_COUNT, s->gfx_max_req_count);
  1036. I915_WRITE(RENDER_HWS_PGA_GEN7, s->render_hwsp);
  1037. I915_WRITE(GAM_ECOCHK, s->ecochk);
  1038. I915_WRITE(BSD_HWS_PGA_GEN7, s->bsd_hwsp);
  1039. I915_WRITE(BLT_HWS_PGA_GEN7, s->blt_hwsp);
  1040. I915_WRITE(GEN7_TLB_RD_ADDR, s->tlb_rd_addr);
  1041. /* MBC 0x9024-0x91D0, 0x8500 */
  1042. I915_WRITE(VLV_G3DCTL, s->g3dctl);
  1043. I915_WRITE(VLV_GSCKGCTL, s->gsckgctl);
  1044. I915_WRITE(GEN6_MBCTL, s->mbctl);
  1045. /* GCP 0x9400-0x9424, 0x8100-0x810C */
  1046. I915_WRITE(GEN6_UCGCTL1, s->ucgctl1);
  1047. I915_WRITE(GEN6_UCGCTL3, s->ucgctl3);
  1048. I915_WRITE(GEN6_RCGCTL1, s->rcgctl1);
  1049. I915_WRITE(GEN6_RCGCTL2, s->rcgctl2);
  1050. I915_WRITE(GEN6_RSTCTL, s->rstctl);
  1051. I915_WRITE(GEN7_MISCCPCTL, s->misccpctl);
  1052. /* GPM 0xA000-0xAA84, 0x8000-0x80FC */
  1053. I915_WRITE(GEN6_GFXPAUSE, s->gfxpause);
  1054. I915_WRITE(GEN6_RPDEUHWTC, s->rpdeuhwtc);
  1055. I915_WRITE(GEN6_RPDEUC, s->rpdeuc);
  1056. I915_WRITE(ECOBUS, s->ecobus);
  1057. I915_WRITE(VLV_PWRDWNUPCTL, s->pwrdwnupctl);
  1058. I915_WRITE(GEN6_RP_DOWN_TIMEOUT,s->rp_down_timeout);
  1059. I915_WRITE(GEN6_RPDEUCSW, s->rp_deucsw);
  1060. I915_WRITE(GEN6_RCUBMABDTMR, s->rcubmabdtmr);
  1061. I915_WRITE(VLV_RCEDATA, s->rcedata);
  1062. I915_WRITE(VLV_SPAREG2H, s->spare2gh);
  1063. /* Display CZ domain, 0x4400C-0x4402C, 0x4F000-0x4F11F */
  1064. I915_WRITE(GTIMR, s->gt_imr);
  1065. I915_WRITE(GTIER, s->gt_ier);
  1066. I915_WRITE(GEN6_PMIMR, s->pm_imr);
  1067. I915_WRITE(GEN6_PMIER, s->pm_ier);
  1068. for (i = 0; i < ARRAY_SIZE(s->gt_scratch); i++)
  1069. I915_WRITE(GEN7_GT_SCRATCH(i), s->gt_scratch[i]);
  1070. /* GT SA CZ domain, 0x100000-0x138124 */
  1071. I915_WRITE(TILECTL, s->tilectl);
  1072. I915_WRITE(GTFIFOCTL, s->gt_fifoctl);
  1073. /*
  1074. * Preserve the GT allow wake and GFX force clock bit, they are not
  1075. * be restored, as they are used to control the s0ix suspend/resume
  1076. * sequence by the caller.
  1077. */
  1078. val = I915_READ(VLV_GTLC_WAKE_CTRL);
  1079. val &= VLV_GTLC_ALLOWWAKEREQ;
  1080. val |= s->gtlc_wake_ctrl & ~VLV_GTLC_ALLOWWAKEREQ;
  1081. I915_WRITE(VLV_GTLC_WAKE_CTRL, val);
  1082. val = I915_READ(VLV_GTLC_SURVIVABILITY_REG);
  1083. val &= VLV_GFX_CLK_FORCE_ON_BIT;
  1084. val |= s->gtlc_survive & ~VLV_GFX_CLK_FORCE_ON_BIT;
  1085. I915_WRITE(VLV_GTLC_SURVIVABILITY_REG, val);
  1086. I915_WRITE(VLV_PMWGICZ, s->pmwgicz);
  1087. /* Gunit-Display CZ domain, 0x182028-0x1821CF */
  1088. I915_WRITE(VLV_GU_CTL0, s->gu_ctl0);
  1089. I915_WRITE(VLV_GU_CTL1, s->gu_ctl1);
  1090. I915_WRITE(VLV_PCBR, s->pcbr);
  1091. I915_WRITE(VLV_GUNIT_CLOCK_GATE2, s->clock_gate_dis2);
  1092. }
  1093. int vlv_force_gfx_clock(struct drm_i915_private *dev_priv, bool force_on)
  1094. {
  1095. u32 val;
  1096. int err;
  1097. #define COND (I915_READ(VLV_GTLC_SURVIVABILITY_REG) & VLV_GFX_CLK_STATUS_BIT)
  1098. val = I915_READ(VLV_GTLC_SURVIVABILITY_REG);
  1099. val &= ~VLV_GFX_CLK_FORCE_ON_BIT;
  1100. if (force_on)
  1101. val |= VLV_GFX_CLK_FORCE_ON_BIT;
  1102. I915_WRITE(VLV_GTLC_SURVIVABILITY_REG, val);
  1103. if (!force_on)
  1104. return 0;
  1105. err = wait_for(COND, 20);
  1106. if (err)
  1107. DRM_ERROR("timeout waiting for GFX clock force-on (%08x)\n",
  1108. I915_READ(VLV_GTLC_SURVIVABILITY_REG));
  1109. return err;
  1110. #undef COND
  1111. }
  1112. static int vlv_allow_gt_wake(struct drm_i915_private *dev_priv, bool allow)
  1113. {
  1114. u32 val;
  1115. int err = 0;
  1116. val = I915_READ(VLV_GTLC_WAKE_CTRL);
  1117. val &= ~VLV_GTLC_ALLOWWAKEREQ;
  1118. if (allow)
  1119. val |= VLV_GTLC_ALLOWWAKEREQ;
  1120. I915_WRITE(VLV_GTLC_WAKE_CTRL, val);
  1121. POSTING_READ(VLV_GTLC_WAKE_CTRL);
  1122. #define COND (!!(I915_READ(VLV_GTLC_PW_STATUS) & VLV_GTLC_ALLOWWAKEACK) == \
  1123. allow)
  1124. err = wait_for(COND, 1);
  1125. if (err)
  1126. DRM_ERROR("timeout disabling GT waking\n");
  1127. return err;
  1128. #undef COND
  1129. }
  1130. static int vlv_wait_for_gt_wells(struct drm_i915_private *dev_priv,
  1131. bool wait_for_on)
  1132. {
  1133. u32 mask;
  1134. u32 val;
  1135. int err;
  1136. mask = VLV_GTLC_PW_MEDIA_STATUS_MASK | VLV_GTLC_PW_RENDER_STATUS_MASK;
  1137. val = wait_for_on ? mask : 0;
  1138. #define COND ((I915_READ(VLV_GTLC_PW_STATUS) & mask) == val)
  1139. if (COND)
  1140. return 0;
  1141. DRM_DEBUG_KMS("waiting for GT wells to go %s (%08x)\n",
  1142. wait_for_on ? "on" : "off",
  1143. I915_READ(VLV_GTLC_PW_STATUS));
  1144. /*
  1145. * RC6 transitioning can be delayed up to 2 msec (see
  1146. * valleyview_enable_rps), use 3 msec for safety.
  1147. */
  1148. err = wait_for(COND, 3);
  1149. if (err)
  1150. DRM_ERROR("timeout waiting for GT wells to go %s\n",
  1151. wait_for_on ? "on" : "off");
  1152. return err;
  1153. #undef COND
  1154. }
  1155. static void vlv_check_no_gt_access(struct drm_i915_private *dev_priv)
  1156. {
  1157. if (!(I915_READ(VLV_GTLC_PW_STATUS) & VLV_GTLC_ALLOWWAKEERR))
  1158. return;
  1159. DRM_ERROR("GT register access while GT waking disabled\n");
  1160. I915_WRITE(VLV_GTLC_PW_STATUS, VLV_GTLC_ALLOWWAKEERR);
  1161. }
  1162. static int vlv_suspend_complete(struct drm_i915_private *dev_priv)
  1163. {
  1164. u32 mask;
  1165. int err;
  1166. /*
  1167. * Bspec defines the following GT well on flags as debug only, so
  1168. * don't treat them as hard failures.
  1169. */
  1170. (void)vlv_wait_for_gt_wells(dev_priv, false);
  1171. mask = VLV_GTLC_RENDER_CTX_EXISTS | VLV_GTLC_MEDIA_CTX_EXISTS;
  1172. WARN_ON((I915_READ(VLV_GTLC_WAKE_CTRL) & mask) != mask);
  1173. vlv_check_no_gt_access(dev_priv);
  1174. err = vlv_force_gfx_clock(dev_priv, true);
  1175. if (err)
  1176. goto err1;
  1177. err = vlv_allow_gt_wake(dev_priv, false);
  1178. if (err)
  1179. goto err2;
  1180. if (!IS_CHERRYVIEW(dev_priv->dev))
  1181. vlv_save_gunit_s0ix_state(dev_priv);
  1182. err = vlv_force_gfx_clock(dev_priv, false);
  1183. if (err)
  1184. goto err2;
  1185. return 0;
  1186. err2:
  1187. /* For safety always re-enable waking and disable gfx clock forcing */
  1188. vlv_allow_gt_wake(dev_priv, true);
  1189. err1:
  1190. vlv_force_gfx_clock(dev_priv, false);
  1191. return err;
  1192. }
  1193. static int vlv_resume_prepare(struct drm_i915_private *dev_priv,
  1194. bool rpm_resume)
  1195. {
  1196. struct drm_device *dev = dev_priv->dev;
  1197. int err;
  1198. int ret;
  1199. /*
  1200. * If any of the steps fail just try to continue, that's the best we
  1201. * can do at this point. Return the first error code (which will also
  1202. * leave RPM permanently disabled).
  1203. */
  1204. ret = vlv_force_gfx_clock(dev_priv, true);
  1205. if (!IS_CHERRYVIEW(dev_priv->dev))
  1206. vlv_restore_gunit_s0ix_state(dev_priv);
  1207. err = vlv_allow_gt_wake(dev_priv, true);
  1208. if (!ret)
  1209. ret = err;
  1210. err = vlv_force_gfx_clock(dev_priv, false);
  1211. if (!ret)
  1212. ret = err;
  1213. vlv_check_no_gt_access(dev_priv);
  1214. if (rpm_resume) {
  1215. intel_init_clock_gating(dev);
  1216. i915_gem_restore_fences(dev);
  1217. }
  1218. return ret;
  1219. }
  1220. static int intel_runtime_suspend(struct device *device)
  1221. {
  1222. struct pci_dev *pdev = to_pci_dev(device);
  1223. struct drm_device *dev = pci_get_drvdata(pdev);
  1224. struct drm_i915_private *dev_priv = dev->dev_private;
  1225. int ret;
  1226. if (WARN_ON_ONCE(!(dev_priv->rps.enabled && intel_enable_rc6(dev))))
  1227. return -ENODEV;
  1228. if (WARN_ON_ONCE(!HAS_RUNTIME_PM(dev)))
  1229. return -ENODEV;
  1230. DRM_DEBUG_KMS("Suspending device\n");
  1231. /*
  1232. * We could deadlock here in case another thread holding struct_mutex
  1233. * calls RPM suspend concurrently, since the RPM suspend will wait
  1234. * first for this RPM suspend to finish. In this case the concurrent
  1235. * RPM resume will be followed by its RPM suspend counterpart. Still
  1236. * for consistency return -EAGAIN, which will reschedule this suspend.
  1237. */
  1238. if (!mutex_trylock(&dev->struct_mutex)) {
  1239. DRM_DEBUG_KMS("device lock contention, deffering suspend\n");
  1240. /*
  1241. * Bump the expiration timestamp, otherwise the suspend won't
  1242. * be rescheduled.
  1243. */
  1244. pm_runtime_mark_last_busy(device);
  1245. return -EAGAIN;
  1246. }
  1247. /*
  1248. * We are safe here against re-faults, since the fault handler takes
  1249. * an RPM reference.
  1250. */
  1251. i915_gem_release_all_mmaps(dev_priv);
  1252. mutex_unlock(&dev->struct_mutex);
  1253. intel_guc_suspend(dev);
  1254. intel_suspend_gt_powersave(dev);
  1255. intel_runtime_pm_disable_interrupts(dev_priv);
  1256. ret = intel_suspend_complete(dev_priv);
  1257. if (ret) {
  1258. DRM_ERROR("Runtime suspend failed, disabling it (%d)\n", ret);
  1259. intel_runtime_pm_enable_interrupts(dev_priv);
  1260. return ret;
  1261. }
  1262. cancel_delayed_work_sync(&dev_priv->gpu_error.hangcheck_work);
  1263. intel_uncore_forcewake_reset(dev, false);
  1264. dev_priv->pm.suspended = true;
  1265. /*
  1266. * FIXME: We really should find a document that references the arguments
  1267. * used below!
  1268. */
  1269. if (IS_BROADWELL(dev)) {
  1270. /*
  1271. * On Broadwell, if we use PCI_D1 the PCH DDI ports will stop
  1272. * being detected, and the call we do at intel_runtime_resume()
  1273. * won't be able to restore them. Since PCI_D3hot matches the
  1274. * actual specification and appears to be working, use it.
  1275. */
  1276. intel_opregion_notify_adapter(dev, PCI_D3hot);
  1277. } else {
  1278. /*
  1279. * current versions of firmware which depend on this opregion
  1280. * notification have repurposed the D1 definition to mean
  1281. * "runtime suspended" vs. what you would normally expect (D3)
  1282. * to distinguish it from notifications that might be sent via
  1283. * the suspend path.
  1284. */
  1285. intel_opregion_notify_adapter(dev, PCI_D1);
  1286. }
  1287. assert_forcewakes_inactive(dev_priv);
  1288. DRM_DEBUG_KMS("Device suspended\n");
  1289. return 0;
  1290. }
  1291. static int intel_runtime_resume(struct device *device)
  1292. {
  1293. struct pci_dev *pdev = to_pci_dev(device);
  1294. struct drm_device *dev = pci_get_drvdata(pdev);
  1295. struct drm_i915_private *dev_priv = dev->dev_private;
  1296. int ret = 0;
  1297. if (WARN_ON_ONCE(!HAS_RUNTIME_PM(dev)))
  1298. return -ENODEV;
  1299. DRM_DEBUG_KMS("Resuming device\n");
  1300. intel_opregion_notify_adapter(dev, PCI_D0);
  1301. dev_priv->pm.suspended = false;
  1302. intel_guc_resume(dev);
  1303. if (IS_GEN6(dev_priv))
  1304. intel_init_pch_refclk(dev);
  1305. if (IS_BROXTON(dev))
  1306. ret = bxt_resume_prepare(dev_priv);
  1307. else if (IS_SKYLAKE(dev))
  1308. ret = skl_resume_prepare(dev_priv);
  1309. else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
  1310. hsw_disable_pc8(dev_priv);
  1311. else if (IS_VALLEYVIEW(dev_priv))
  1312. ret = vlv_resume_prepare(dev_priv, true);
  1313. /*
  1314. * No point of rolling back things in case of an error, as the best
  1315. * we can do is to hope that things will still work (and disable RPM).
  1316. */
  1317. i915_gem_init_swizzling(dev);
  1318. gen6_update_ring_freq(dev);
  1319. intel_runtime_pm_enable_interrupts(dev_priv);
  1320. /*
  1321. * On VLV/CHV display interrupts are part of the display
  1322. * power well, so hpd is reinitialized from there. For
  1323. * everyone else do it here.
  1324. */
  1325. if (!IS_VALLEYVIEW(dev_priv))
  1326. intel_hpd_init(dev_priv);
  1327. intel_enable_gt_powersave(dev);
  1328. if (ret)
  1329. DRM_ERROR("Runtime resume failed, disabling it (%d)\n", ret);
  1330. else
  1331. DRM_DEBUG_KMS("Device resumed\n");
  1332. return ret;
  1333. }
  1334. /*
  1335. * This function implements common functionality of runtime and system
  1336. * suspend sequence.
  1337. */
  1338. static int intel_suspend_complete(struct drm_i915_private *dev_priv)
  1339. {
  1340. int ret;
  1341. if (IS_BROXTON(dev_priv))
  1342. ret = bxt_suspend_complete(dev_priv);
  1343. else if (IS_SKYLAKE(dev_priv))
  1344. ret = skl_suspend_complete(dev_priv);
  1345. else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
  1346. ret = hsw_suspend_complete(dev_priv);
  1347. else if (IS_VALLEYVIEW(dev_priv))
  1348. ret = vlv_suspend_complete(dev_priv);
  1349. else
  1350. ret = 0;
  1351. return ret;
  1352. }
  1353. static const struct dev_pm_ops i915_pm_ops = {
  1354. /*
  1355. * S0ix (via system suspend) and S3 event handlers [PMSG_SUSPEND,
  1356. * PMSG_RESUME]
  1357. */
  1358. .suspend = i915_pm_suspend,
  1359. .suspend_late = i915_pm_suspend_late,
  1360. .resume_early = i915_pm_resume_early,
  1361. .resume = i915_pm_resume,
  1362. /*
  1363. * S4 event handlers
  1364. * @freeze, @freeze_late : called (1) before creating the
  1365. * hibernation image [PMSG_FREEZE] and
  1366. * (2) after rebooting, before restoring
  1367. * the image [PMSG_QUIESCE]
  1368. * @thaw, @thaw_early : called (1) after creating the hibernation
  1369. * image, before writing it [PMSG_THAW]
  1370. * and (2) after failing to create or
  1371. * restore the image [PMSG_RECOVER]
  1372. * @poweroff, @poweroff_late: called after writing the hibernation
  1373. * image, before rebooting [PMSG_HIBERNATE]
  1374. * @restore, @restore_early : called after rebooting and restoring the
  1375. * hibernation image [PMSG_RESTORE]
  1376. */
  1377. .freeze = i915_pm_suspend,
  1378. .freeze_late = i915_pm_suspend_late,
  1379. .thaw_early = i915_pm_resume_early,
  1380. .thaw = i915_pm_resume,
  1381. .poweroff = i915_pm_suspend,
  1382. .poweroff_late = i915_pm_poweroff_late,
  1383. .restore_early = i915_pm_resume_early,
  1384. .restore = i915_pm_resume,
  1385. /* S0ix (via runtime suspend) event handlers */
  1386. .runtime_suspend = intel_runtime_suspend,
  1387. .runtime_resume = intel_runtime_resume,
  1388. };
  1389. static const struct vm_operations_struct i915_gem_vm_ops = {
  1390. .fault = i915_gem_fault,
  1391. .open = drm_gem_vm_open,
  1392. .close = drm_gem_vm_close,
  1393. };
  1394. static const struct file_operations i915_driver_fops = {
  1395. .owner = THIS_MODULE,
  1396. .open = drm_open,
  1397. .release = drm_release,
  1398. .unlocked_ioctl = drm_ioctl,
  1399. .mmap = drm_gem_mmap,
  1400. .poll = drm_poll,
  1401. .read = drm_read,
  1402. #ifdef CONFIG_COMPAT
  1403. .compat_ioctl = i915_compat_ioctl,
  1404. #endif
  1405. .llseek = noop_llseek,
  1406. };
  1407. static struct drm_driver driver = {
  1408. /* Don't use MTRRs here; the Xserver or userspace app should
  1409. * deal with them for Intel hardware.
  1410. */
  1411. .driver_features =
  1412. DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_GEM | DRIVER_PRIME |
  1413. DRIVER_RENDER | DRIVER_MODESET,
  1414. .load = i915_driver_load,
  1415. .unload = i915_driver_unload,
  1416. .open = i915_driver_open,
  1417. .lastclose = i915_driver_lastclose,
  1418. .preclose = i915_driver_preclose,
  1419. .postclose = i915_driver_postclose,
  1420. .set_busid = drm_pci_set_busid,
  1421. #if defined(CONFIG_DEBUG_FS)
  1422. .debugfs_init = i915_debugfs_init,
  1423. .debugfs_cleanup = i915_debugfs_cleanup,
  1424. #endif
  1425. .gem_free_object = i915_gem_free_object,
  1426. .gem_vm_ops = &i915_gem_vm_ops,
  1427. .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
  1428. .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
  1429. .gem_prime_export = i915_gem_prime_export,
  1430. .gem_prime_import = i915_gem_prime_import,
  1431. .dumb_create = i915_gem_dumb_create,
  1432. .dumb_map_offset = i915_gem_mmap_gtt,
  1433. .dumb_destroy = drm_gem_dumb_destroy,
  1434. .ioctls = i915_ioctls,
  1435. .fops = &i915_driver_fops,
  1436. .name = DRIVER_NAME,
  1437. .desc = DRIVER_DESC,
  1438. .date = DRIVER_DATE,
  1439. .major = DRIVER_MAJOR,
  1440. .minor = DRIVER_MINOR,
  1441. .patchlevel = DRIVER_PATCHLEVEL,
  1442. };
  1443. static struct pci_driver i915_pci_driver = {
  1444. .name = DRIVER_NAME,
  1445. .id_table = pciidlist,
  1446. .probe = i915_pci_probe,
  1447. .remove = i915_pci_remove,
  1448. .driver.pm = &i915_pm_ops,
  1449. };
  1450. static int __init i915_init(void)
  1451. {
  1452. driver.num_ioctls = i915_max_ioctl;
  1453. /*
  1454. * Enable KMS by default, unless explicitly overriden by
  1455. * either the i915.modeset prarameter or by the
  1456. * vga_text_mode_force boot option.
  1457. */
  1458. if (i915.modeset == 0)
  1459. driver.driver_features &= ~DRIVER_MODESET;
  1460. #ifdef CONFIG_VGA_CONSOLE
  1461. if (vgacon_text_force() && i915.modeset == -1)
  1462. driver.driver_features &= ~DRIVER_MODESET;
  1463. #endif
  1464. if (!(driver.driver_features & DRIVER_MODESET)) {
  1465. /* Silently fail loading to not upset userspace. */
  1466. DRM_DEBUG_DRIVER("KMS and UMS disabled.\n");
  1467. return 0;
  1468. }
  1469. if (i915.nuclear_pageflip)
  1470. driver.driver_features |= DRIVER_ATOMIC;
  1471. return drm_pci_init(&driver, &i915_pci_driver);
  1472. }
  1473. static void __exit i915_exit(void)
  1474. {
  1475. if (!(driver.driver_features & DRIVER_MODESET))
  1476. return; /* Never loaded a driver. */
  1477. drm_pci_exit(&driver, &i915_pci_driver);
  1478. }
  1479. module_init(i915_init);
  1480. module_exit(i915_exit);
  1481. MODULE_AUTHOR("Tungsten Graphics, Inc.");
  1482. MODULE_AUTHOR("Intel Corporation");
  1483. MODULE_DESCRIPTION(DRIVER_DESC);
  1484. MODULE_LICENSE("GPL and additional rights");