i915_drv.c 46 KB

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