i915_drv.c 45 KB

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