i915_drv.c 47 KB

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