i915_drv.c 49 KB

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