i915_drv.c 47 KB

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