i915_drv.c 47 KB

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