i915_drv.c 44 KB

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