i915_drv.c 48 KB

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