i915_drv.c 51 KB

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