i915_drv.c 50 KB

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