i915_drv.c 47 KB

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