i915_drv.c 82 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888
  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/acpi.h>
  30. #include <linux/device.h>
  31. #include <linux/oom.h>
  32. #include <linux/module.h>
  33. #include <linux/pci.h>
  34. #include <linux/pm.h>
  35. #include <linux/pm_runtime.h>
  36. #include <linux/pnp.h>
  37. #include <linux/slab.h>
  38. #include <linux/vgaarb.h>
  39. #include <linux/vga_switcheroo.h>
  40. #include <linux/vt.h>
  41. #include <acpi/video.h>
  42. #include <drm/drmP.h>
  43. #include <drm/drm_crtc_helper.h>
  44. #include <drm/drm_atomic_helper.h>
  45. #include <drm/i915_drm.h>
  46. #include "i915_drv.h"
  47. #include "i915_trace.h"
  48. #include "i915_pmu.h"
  49. #include "i915_query.h"
  50. #include "i915_vgpu.h"
  51. #include "intel_drv.h"
  52. #include "intel_uc.h"
  53. static struct drm_driver driver;
  54. #if IS_ENABLED(CONFIG_DRM_I915_DEBUG)
  55. static unsigned int i915_load_fail_count;
  56. bool __i915_inject_load_failure(const char *func, int line)
  57. {
  58. if (i915_load_fail_count >= i915_modparams.inject_load_failure)
  59. return false;
  60. if (++i915_load_fail_count == i915_modparams.inject_load_failure) {
  61. DRM_INFO("Injecting failure at checkpoint %u [%s:%d]\n",
  62. i915_modparams.inject_load_failure, func, line);
  63. return true;
  64. }
  65. return false;
  66. }
  67. #endif
  68. #define FDO_BUG_URL "https://bugs.freedesktop.org/enter_bug.cgi?product=DRI"
  69. #define FDO_BUG_MSG "Please file a bug at " FDO_BUG_URL " against DRM/Intel " \
  70. "providing the dmesg log by booting with drm.debug=0xf"
  71. void
  72. __i915_printk(struct drm_i915_private *dev_priv, const char *level,
  73. const char *fmt, ...)
  74. {
  75. static bool shown_bug_once;
  76. struct device *kdev = dev_priv->drm.dev;
  77. bool is_error = level[1] <= KERN_ERR[1];
  78. bool is_debug = level[1] == KERN_DEBUG[1];
  79. struct va_format vaf;
  80. va_list args;
  81. if (is_debug && !(drm_debug & DRM_UT_DRIVER))
  82. return;
  83. va_start(args, fmt);
  84. vaf.fmt = fmt;
  85. vaf.va = &args;
  86. dev_printk(level, kdev, "[" DRM_NAME ":%ps] %pV",
  87. __builtin_return_address(0), &vaf);
  88. if (is_error && !shown_bug_once) {
  89. /*
  90. * Ask the user to file a bug report for the error, except
  91. * if they may have caused the bug by fiddling with unsafe
  92. * module parameters.
  93. */
  94. if (!test_taint(TAINT_USER))
  95. dev_notice(kdev, "%s", FDO_BUG_MSG);
  96. shown_bug_once = true;
  97. }
  98. va_end(args);
  99. }
  100. static bool i915_error_injected(struct drm_i915_private *dev_priv)
  101. {
  102. #if IS_ENABLED(CONFIG_DRM_I915_DEBUG)
  103. return i915_modparams.inject_load_failure &&
  104. i915_load_fail_count == i915_modparams.inject_load_failure;
  105. #else
  106. return false;
  107. #endif
  108. }
  109. #define i915_load_error(dev_priv, fmt, ...) \
  110. __i915_printk(dev_priv, \
  111. i915_error_injected(dev_priv) ? KERN_DEBUG : KERN_ERR, \
  112. fmt, ##__VA_ARGS__)
  113. /* Map PCH device id to PCH type, or PCH_NONE if unknown. */
  114. static enum intel_pch
  115. intel_pch_type(const struct drm_i915_private *dev_priv, unsigned short id)
  116. {
  117. switch (id) {
  118. case INTEL_PCH_IBX_DEVICE_ID_TYPE:
  119. DRM_DEBUG_KMS("Found Ibex Peak PCH\n");
  120. WARN_ON(!IS_GEN5(dev_priv));
  121. return PCH_IBX;
  122. case INTEL_PCH_CPT_DEVICE_ID_TYPE:
  123. DRM_DEBUG_KMS("Found CougarPoint PCH\n");
  124. WARN_ON(!IS_GEN6(dev_priv) && !IS_IVYBRIDGE(dev_priv));
  125. return PCH_CPT;
  126. case INTEL_PCH_PPT_DEVICE_ID_TYPE:
  127. DRM_DEBUG_KMS("Found PantherPoint PCH\n");
  128. WARN_ON(!IS_GEN6(dev_priv) && !IS_IVYBRIDGE(dev_priv));
  129. /* PantherPoint is CPT compatible */
  130. return PCH_CPT;
  131. case INTEL_PCH_LPT_DEVICE_ID_TYPE:
  132. DRM_DEBUG_KMS("Found LynxPoint PCH\n");
  133. WARN_ON(!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv));
  134. WARN_ON(IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv));
  135. return PCH_LPT;
  136. case INTEL_PCH_LPT_LP_DEVICE_ID_TYPE:
  137. DRM_DEBUG_KMS("Found LynxPoint LP PCH\n");
  138. WARN_ON(!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv));
  139. WARN_ON(!IS_HSW_ULT(dev_priv) && !IS_BDW_ULT(dev_priv));
  140. return PCH_LPT;
  141. case INTEL_PCH_WPT_DEVICE_ID_TYPE:
  142. DRM_DEBUG_KMS("Found WildcatPoint PCH\n");
  143. WARN_ON(!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv));
  144. WARN_ON(IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv));
  145. /* WildcatPoint is LPT compatible */
  146. return PCH_LPT;
  147. case INTEL_PCH_WPT_LP_DEVICE_ID_TYPE:
  148. DRM_DEBUG_KMS("Found WildcatPoint LP PCH\n");
  149. WARN_ON(!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv));
  150. WARN_ON(!IS_HSW_ULT(dev_priv) && !IS_BDW_ULT(dev_priv));
  151. /* WildcatPoint is LPT compatible */
  152. return PCH_LPT;
  153. case INTEL_PCH_SPT_DEVICE_ID_TYPE:
  154. DRM_DEBUG_KMS("Found SunrisePoint PCH\n");
  155. WARN_ON(!IS_SKYLAKE(dev_priv) && !IS_KABYLAKE(dev_priv));
  156. return PCH_SPT;
  157. case INTEL_PCH_SPT_LP_DEVICE_ID_TYPE:
  158. DRM_DEBUG_KMS("Found SunrisePoint LP PCH\n");
  159. WARN_ON(!IS_SKYLAKE(dev_priv) && !IS_KABYLAKE(dev_priv));
  160. return PCH_SPT;
  161. case INTEL_PCH_KBP_DEVICE_ID_TYPE:
  162. DRM_DEBUG_KMS("Found Kaby Lake PCH (KBP)\n");
  163. WARN_ON(!IS_SKYLAKE(dev_priv) && !IS_KABYLAKE(dev_priv) &&
  164. !IS_COFFEELAKE(dev_priv));
  165. return PCH_KBP;
  166. case INTEL_PCH_CNP_DEVICE_ID_TYPE:
  167. DRM_DEBUG_KMS("Found Cannon Lake PCH (CNP)\n");
  168. WARN_ON(!IS_CANNONLAKE(dev_priv) && !IS_COFFEELAKE(dev_priv));
  169. return PCH_CNP;
  170. case INTEL_PCH_CNP_LP_DEVICE_ID_TYPE:
  171. DRM_DEBUG_KMS("Found Cannon Lake LP PCH (CNP-LP)\n");
  172. WARN_ON(!IS_CANNONLAKE(dev_priv) && !IS_COFFEELAKE(dev_priv));
  173. return PCH_CNP;
  174. case INTEL_PCH_ICP_DEVICE_ID_TYPE:
  175. DRM_DEBUG_KMS("Found Ice Lake PCH\n");
  176. WARN_ON(!IS_ICELAKE(dev_priv));
  177. return PCH_ICP;
  178. default:
  179. return PCH_NONE;
  180. }
  181. }
  182. static bool intel_is_virt_pch(unsigned short id,
  183. unsigned short svendor, unsigned short sdevice)
  184. {
  185. return (id == INTEL_PCH_P2X_DEVICE_ID_TYPE ||
  186. id == INTEL_PCH_P3X_DEVICE_ID_TYPE ||
  187. (id == INTEL_PCH_QEMU_DEVICE_ID_TYPE &&
  188. svendor == PCI_SUBVENDOR_ID_REDHAT_QUMRANET &&
  189. sdevice == PCI_SUBDEVICE_ID_QEMU));
  190. }
  191. static unsigned short
  192. intel_virt_detect_pch(const struct drm_i915_private *dev_priv)
  193. {
  194. unsigned short id = 0;
  195. /*
  196. * In a virtualized passthrough environment we can be in a
  197. * setup where the ISA bridge is not able to be passed through.
  198. * In this case, a south bridge can be emulated and we have to
  199. * make an educated guess as to which PCH is really there.
  200. */
  201. if (IS_GEN5(dev_priv))
  202. id = INTEL_PCH_IBX_DEVICE_ID_TYPE;
  203. else if (IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv))
  204. id = INTEL_PCH_CPT_DEVICE_ID_TYPE;
  205. else if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv))
  206. id = INTEL_PCH_LPT_LP_DEVICE_ID_TYPE;
  207. else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
  208. id = INTEL_PCH_LPT_DEVICE_ID_TYPE;
  209. else if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))
  210. id = INTEL_PCH_SPT_DEVICE_ID_TYPE;
  211. else if (IS_COFFEELAKE(dev_priv) || IS_CANNONLAKE(dev_priv))
  212. id = INTEL_PCH_CNP_DEVICE_ID_TYPE;
  213. if (id)
  214. DRM_DEBUG_KMS("Assuming PCH ID %04x\n", id);
  215. else
  216. DRM_DEBUG_KMS("Assuming no PCH\n");
  217. return id;
  218. }
  219. static void intel_detect_pch(struct drm_i915_private *dev_priv)
  220. {
  221. struct pci_dev *pch = NULL;
  222. /* In all current cases, num_pipes is equivalent to the PCH_NOP setting
  223. * (which really amounts to a PCH but no South Display).
  224. */
  225. if (INTEL_INFO(dev_priv)->num_pipes == 0) {
  226. dev_priv->pch_type = PCH_NOP;
  227. return;
  228. }
  229. /*
  230. * The reason to probe ISA bridge instead of Dev31:Fun0 is to
  231. * make graphics device passthrough work easy for VMM, that only
  232. * need to expose ISA bridge to let driver know the real hardware
  233. * underneath. This is a requirement from virtualization team.
  234. *
  235. * In some virtualized environments (e.g. XEN), there is irrelevant
  236. * ISA bridge in the system. To work reliably, we should scan trhough
  237. * all the ISA bridge devices and check for the first match, instead
  238. * of only checking the first one.
  239. */
  240. while ((pch = pci_get_class(PCI_CLASS_BRIDGE_ISA << 8, pch))) {
  241. unsigned short id;
  242. enum intel_pch pch_type;
  243. if (pch->vendor != PCI_VENDOR_ID_INTEL)
  244. continue;
  245. id = pch->device & INTEL_PCH_DEVICE_ID_MASK;
  246. pch_type = intel_pch_type(dev_priv, id);
  247. if (pch_type != PCH_NONE) {
  248. dev_priv->pch_type = pch_type;
  249. dev_priv->pch_id = id;
  250. break;
  251. } else if (intel_is_virt_pch(id, pch->subsystem_vendor,
  252. pch->subsystem_device)) {
  253. id = intel_virt_detect_pch(dev_priv);
  254. if (id) {
  255. pch_type = intel_pch_type(dev_priv, id);
  256. if (WARN_ON(pch_type == PCH_NONE))
  257. pch_type = PCH_NOP;
  258. } else {
  259. pch_type = PCH_NOP;
  260. }
  261. dev_priv->pch_type = pch_type;
  262. dev_priv->pch_id = id;
  263. break;
  264. }
  265. }
  266. if (!pch)
  267. DRM_DEBUG_KMS("No PCH found.\n");
  268. pci_dev_put(pch);
  269. }
  270. static int i915_getparam_ioctl(struct drm_device *dev, void *data,
  271. struct drm_file *file_priv)
  272. {
  273. struct drm_i915_private *dev_priv = to_i915(dev);
  274. struct pci_dev *pdev = dev_priv->drm.pdev;
  275. drm_i915_getparam_t *param = data;
  276. int value;
  277. switch (param->param) {
  278. case I915_PARAM_IRQ_ACTIVE:
  279. case I915_PARAM_ALLOW_BATCHBUFFER:
  280. case I915_PARAM_LAST_DISPATCH:
  281. case I915_PARAM_HAS_EXEC_CONSTANTS:
  282. /* Reject all old ums/dri params. */
  283. return -ENODEV;
  284. case I915_PARAM_CHIPSET_ID:
  285. value = pdev->device;
  286. break;
  287. case I915_PARAM_REVISION:
  288. value = pdev->revision;
  289. break;
  290. case I915_PARAM_NUM_FENCES_AVAIL:
  291. value = dev_priv->num_fence_regs;
  292. break;
  293. case I915_PARAM_HAS_OVERLAY:
  294. value = dev_priv->overlay ? 1 : 0;
  295. break;
  296. case I915_PARAM_HAS_BSD:
  297. value = !!dev_priv->engine[VCS];
  298. break;
  299. case I915_PARAM_HAS_BLT:
  300. value = !!dev_priv->engine[BCS];
  301. break;
  302. case I915_PARAM_HAS_VEBOX:
  303. value = !!dev_priv->engine[VECS];
  304. break;
  305. case I915_PARAM_HAS_BSD2:
  306. value = !!dev_priv->engine[VCS2];
  307. break;
  308. case I915_PARAM_HAS_LLC:
  309. value = HAS_LLC(dev_priv);
  310. break;
  311. case I915_PARAM_HAS_WT:
  312. value = HAS_WT(dev_priv);
  313. break;
  314. case I915_PARAM_HAS_ALIASING_PPGTT:
  315. value = USES_PPGTT(dev_priv);
  316. break;
  317. case I915_PARAM_HAS_SEMAPHORES:
  318. value = HAS_LEGACY_SEMAPHORES(dev_priv);
  319. break;
  320. case I915_PARAM_HAS_SECURE_BATCHES:
  321. value = capable(CAP_SYS_ADMIN);
  322. break;
  323. case I915_PARAM_CMD_PARSER_VERSION:
  324. value = i915_cmd_parser_get_version(dev_priv);
  325. break;
  326. case I915_PARAM_SUBSLICE_TOTAL:
  327. value = sseu_subslice_total(&INTEL_INFO(dev_priv)->sseu);
  328. if (!value)
  329. return -ENODEV;
  330. break;
  331. case I915_PARAM_EU_TOTAL:
  332. value = INTEL_INFO(dev_priv)->sseu.eu_total;
  333. if (!value)
  334. return -ENODEV;
  335. break;
  336. case I915_PARAM_HAS_GPU_RESET:
  337. value = i915_modparams.enable_hangcheck &&
  338. intel_has_gpu_reset(dev_priv);
  339. if (value && intel_has_reset_engine(dev_priv))
  340. value = 2;
  341. break;
  342. case I915_PARAM_HAS_RESOURCE_STREAMER:
  343. value = HAS_RESOURCE_STREAMER(dev_priv);
  344. break;
  345. case I915_PARAM_HAS_POOLED_EU:
  346. value = HAS_POOLED_EU(dev_priv);
  347. break;
  348. case I915_PARAM_MIN_EU_IN_POOL:
  349. value = INTEL_INFO(dev_priv)->sseu.min_eu_in_pool;
  350. break;
  351. case I915_PARAM_HUC_STATUS:
  352. value = intel_huc_check_status(&dev_priv->huc);
  353. if (value < 0)
  354. return value;
  355. break;
  356. case I915_PARAM_MMAP_GTT_VERSION:
  357. /* Though we've started our numbering from 1, and so class all
  358. * earlier versions as 0, in effect their value is undefined as
  359. * the ioctl will report EINVAL for the unknown param!
  360. */
  361. value = i915_gem_mmap_gtt_version();
  362. break;
  363. case I915_PARAM_HAS_SCHEDULER:
  364. value = dev_priv->caps.scheduler;
  365. break;
  366. case I915_PARAM_MMAP_VERSION:
  367. /* Remember to bump this if the version changes! */
  368. case I915_PARAM_HAS_GEM:
  369. case I915_PARAM_HAS_PAGEFLIPPING:
  370. case I915_PARAM_HAS_EXECBUF2: /* depends on GEM */
  371. case I915_PARAM_HAS_RELAXED_FENCING:
  372. case I915_PARAM_HAS_COHERENT_RINGS:
  373. case I915_PARAM_HAS_RELAXED_DELTA:
  374. case I915_PARAM_HAS_GEN7_SOL_RESET:
  375. case I915_PARAM_HAS_WAIT_TIMEOUT:
  376. case I915_PARAM_HAS_PRIME_VMAP_FLUSH:
  377. case I915_PARAM_HAS_PINNED_BATCHES:
  378. case I915_PARAM_HAS_EXEC_NO_RELOC:
  379. case I915_PARAM_HAS_EXEC_HANDLE_LUT:
  380. case I915_PARAM_HAS_COHERENT_PHYS_GTT:
  381. case I915_PARAM_HAS_EXEC_SOFTPIN:
  382. case I915_PARAM_HAS_EXEC_ASYNC:
  383. case I915_PARAM_HAS_EXEC_FENCE:
  384. case I915_PARAM_HAS_EXEC_CAPTURE:
  385. case I915_PARAM_HAS_EXEC_BATCH_FIRST:
  386. case I915_PARAM_HAS_EXEC_FENCE_ARRAY:
  387. /* For the time being all of these are always true;
  388. * if some supported hardware does not have one of these
  389. * features this value needs to be provided from
  390. * INTEL_INFO(), a feature macro, or similar.
  391. */
  392. value = 1;
  393. break;
  394. case I915_PARAM_HAS_CONTEXT_ISOLATION:
  395. value = intel_engines_has_context_isolation(dev_priv);
  396. break;
  397. case I915_PARAM_SLICE_MASK:
  398. value = INTEL_INFO(dev_priv)->sseu.slice_mask;
  399. if (!value)
  400. return -ENODEV;
  401. break;
  402. case I915_PARAM_SUBSLICE_MASK:
  403. value = INTEL_INFO(dev_priv)->sseu.subslice_mask[0];
  404. if (!value)
  405. return -ENODEV;
  406. break;
  407. case I915_PARAM_CS_TIMESTAMP_FREQUENCY:
  408. value = 1000 * INTEL_INFO(dev_priv)->cs_timestamp_frequency_khz;
  409. break;
  410. default:
  411. DRM_DEBUG("Unknown parameter %d\n", param->param);
  412. return -EINVAL;
  413. }
  414. if (put_user(value, param->value))
  415. return -EFAULT;
  416. return 0;
  417. }
  418. static int i915_get_bridge_dev(struct drm_i915_private *dev_priv)
  419. {
  420. int domain = pci_domain_nr(dev_priv->drm.pdev->bus);
  421. dev_priv->bridge_dev =
  422. pci_get_domain_bus_and_slot(domain, 0, PCI_DEVFN(0, 0));
  423. if (!dev_priv->bridge_dev) {
  424. DRM_ERROR("bridge device not found\n");
  425. return -1;
  426. }
  427. return 0;
  428. }
  429. /* Allocate space for the MCH regs if needed, return nonzero on error */
  430. static int
  431. intel_alloc_mchbar_resource(struct drm_i915_private *dev_priv)
  432. {
  433. int reg = INTEL_GEN(dev_priv) >= 4 ? MCHBAR_I965 : MCHBAR_I915;
  434. u32 temp_lo, temp_hi = 0;
  435. u64 mchbar_addr;
  436. int ret;
  437. if (INTEL_GEN(dev_priv) >= 4)
  438. pci_read_config_dword(dev_priv->bridge_dev, reg + 4, &temp_hi);
  439. pci_read_config_dword(dev_priv->bridge_dev, reg, &temp_lo);
  440. mchbar_addr = ((u64)temp_hi << 32) | temp_lo;
  441. /* If ACPI doesn't have it, assume we need to allocate it ourselves */
  442. #ifdef CONFIG_PNP
  443. if (mchbar_addr &&
  444. pnp_range_reserved(mchbar_addr, mchbar_addr + MCHBAR_SIZE))
  445. return 0;
  446. #endif
  447. /* Get some space for it */
  448. dev_priv->mch_res.name = "i915 MCHBAR";
  449. dev_priv->mch_res.flags = IORESOURCE_MEM;
  450. ret = pci_bus_alloc_resource(dev_priv->bridge_dev->bus,
  451. &dev_priv->mch_res,
  452. MCHBAR_SIZE, MCHBAR_SIZE,
  453. PCIBIOS_MIN_MEM,
  454. 0, pcibios_align_resource,
  455. dev_priv->bridge_dev);
  456. if (ret) {
  457. DRM_DEBUG_DRIVER("failed bus alloc: %d\n", ret);
  458. dev_priv->mch_res.start = 0;
  459. return ret;
  460. }
  461. if (INTEL_GEN(dev_priv) >= 4)
  462. pci_write_config_dword(dev_priv->bridge_dev, reg + 4,
  463. upper_32_bits(dev_priv->mch_res.start));
  464. pci_write_config_dword(dev_priv->bridge_dev, reg,
  465. lower_32_bits(dev_priv->mch_res.start));
  466. return 0;
  467. }
  468. /* Setup MCHBAR if possible, return true if we should disable it again */
  469. static void
  470. intel_setup_mchbar(struct drm_i915_private *dev_priv)
  471. {
  472. int mchbar_reg = INTEL_GEN(dev_priv) >= 4 ? MCHBAR_I965 : MCHBAR_I915;
  473. u32 temp;
  474. bool enabled;
  475. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  476. return;
  477. dev_priv->mchbar_need_disable = false;
  478. if (IS_I915G(dev_priv) || IS_I915GM(dev_priv)) {
  479. pci_read_config_dword(dev_priv->bridge_dev, DEVEN, &temp);
  480. enabled = !!(temp & DEVEN_MCHBAR_EN);
  481. } else {
  482. pci_read_config_dword(dev_priv->bridge_dev, mchbar_reg, &temp);
  483. enabled = temp & 1;
  484. }
  485. /* If it's already enabled, don't have to do anything */
  486. if (enabled)
  487. return;
  488. if (intel_alloc_mchbar_resource(dev_priv))
  489. return;
  490. dev_priv->mchbar_need_disable = true;
  491. /* Space is allocated or reserved, so enable it. */
  492. if (IS_I915G(dev_priv) || IS_I915GM(dev_priv)) {
  493. pci_write_config_dword(dev_priv->bridge_dev, DEVEN,
  494. temp | DEVEN_MCHBAR_EN);
  495. } else {
  496. pci_read_config_dword(dev_priv->bridge_dev, mchbar_reg, &temp);
  497. pci_write_config_dword(dev_priv->bridge_dev, mchbar_reg, temp | 1);
  498. }
  499. }
  500. static void
  501. intel_teardown_mchbar(struct drm_i915_private *dev_priv)
  502. {
  503. int mchbar_reg = INTEL_GEN(dev_priv) >= 4 ? MCHBAR_I965 : MCHBAR_I915;
  504. if (dev_priv->mchbar_need_disable) {
  505. if (IS_I915G(dev_priv) || IS_I915GM(dev_priv)) {
  506. u32 deven_val;
  507. pci_read_config_dword(dev_priv->bridge_dev, DEVEN,
  508. &deven_val);
  509. deven_val &= ~DEVEN_MCHBAR_EN;
  510. pci_write_config_dword(dev_priv->bridge_dev, DEVEN,
  511. deven_val);
  512. } else {
  513. u32 mchbar_val;
  514. pci_read_config_dword(dev_priv->bridge_dev, mchbar_reg,
  515. &mchbar_val);
  516. mchbar_val &= ~1;
  517. pci_write_config_dword(dev_priv->bridge_dev, mchbar_reg,
  518. mchbar_val);
  519. }
  520. }
  521. if (dev_priv->mch_res.start)
  522. release_resource(&dev_priv->mch_res);
  523. }
  524. /* true = enable decode, false = disable decoder */
  525. static unsigned int i915_vga_set_decode(void *cookie, bool state)
  526. {
  527. struct drm_i915_private *dev_priv = cookie;
  528. intel_modeset_vga_set_state(dev_priv, state);
  529. if (state)
  530. return VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM |
  531. VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM;
  532. else
  533. return VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM;
  534. }
  535. static int i915_resume_switcheroo(struct drm_device *dev);
  536. static int i915_suspend_switcheroo(struct drm_device *dev, pm_message_t state);
  537. static void i915_switcheroo_set_state(struct pci_dev *pdev, enum vga_switcheroo_state state)
  538. {
  539. struct drm_device *dev = pci_get_drvdata(pdev);
  540. pm_message_t pmm = { .event = PM_EVENT_SUSPEND };
  541. if (state == VGA_SWITCHEROO_ON) {
  542. pr_info("switched on\n");
  543. dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
  544. /* i915 resume handler doesn't set to D0 */
  545. pci_set_power_state(pdev, PCI_D0);
  546. i915_resume_switcheroo(dev);
  547. dev->switch_power_state = DRM_SWITCH_POWER_ON;
  548. } else {
  549. pr_info("switched off\n");
  550. dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
  551. i915_suspend_switcheroo(dev, pmm);
  552. dev->switch_power_state = DRM_SWITCH_POWER_OFF;
  553. }
  554. }
  555. static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
  556. {
  557. struct drm_device *dev = pci_get_drvdata(pdev);
  558. /*
  559. * FIXME: open_count is protected by drm_global_mutex but that would lead to
  560. * locking inversion with the driver load path. And the access here is
  561. * completely racy anyway. So don't bother with locking for now.
  562. */
  563. return dev->open_count == 0;
  564. }
  565. static const struct vga_switcheroo_client_ops i915_switcheroo_ops = {
  566. .set_gpu_state = i915_switcheroo_set_state,
  567. .reprobe = NULL,
  568. .can_switch = i915_switcheroo_can_switch,
  569. };
  570. static void i915_gem_fini(struct drm_i915_private *dev_priv)
  571. {
  572. /* Flush any outstanding unpin_work. */
  573. i915_gem_drain_workqueue(dev_priv);
  574. mutex_lock(&dev_priv->drm.struct_mutex);
  575. intel_uc_fini_hw(dev_priv);
  576. intel_uc_fini(dev_priv);
  577. i915_gem_cleanup_engines(dev_priv);
  578. i915_gem_contexts_fini(dev_priv);
  579. mutex_unlock(&dev_priv->drm.struct_mutex);
  580. intel_uc_fini_misc(dev_priv);
  581. i915_gem_cleanup_userptr(dev_priv);
  582. i915_gem_drain_freed_objects(dev_priv);
  583. WARN_ON(!list_empty(&dev_priv->contexts.list));
  584. }
  585. static int i915_load_modeset_init(struct drm_device *dev)
  586. {
  587. struct drm_i915_private *dev_priv = to_i915(dev);
  588. struct pci_dev *pdev = dev_priv->drm.pdev;
  589. int ret;
  590. if (i915_inject_load_failure())
  591. return -ENODEV;
  592. intel_bios_init(dev_priv);
  593. /* If we have > 1 VGA cards, then we need to arbitrate access
  594. * to the common VGA resources.
  595. *
  596. * If we are a secondary display controller (!PCI_DISPLAY_CLASS_VGA),
  597. * then we do not take part in VGA arbitration and the
  598. * vga_client_register() fails with -ENODEV.
  599. */
  600. ret = vga_client_register(pdev, dev_priv, NULL, i915_vga_set_decode);
  601. if (ret && ret != -ENODEV)
  602. goto out;
  603. intel_register_dsm_handler();
  604. ret = vga_switcheroo_register_client(pdev, &i915_switcheroo_ops, false);
  605. if (ret)
  606. goto cleanup_vga_client;
  607. /* must happen before intel_power_domains_init_hw() on VLV/CHV */
  608. intel_update_rawclk(dev_priv);
  609. intel_power_domains_init_hw(dev_priv, false);
  610. intel_csr_ucode_init(dev_priv);
  611. ret = intel_irq_install(dev_priv);
  612. if (ret)
  613. goto cleanup_csr;
  614. intel_setup_gmbus(dev_priv);
  615. /* Important: The output setup functions called by modeset_init need
  616. * working irqs for e.g. gmbus and dp aux transfers. */
  617. ret = intel_modeset_init(dev);
  618. if (ret)
  619. goto cleanup_irq;
  620. ret = i915_gem_init(dev_priv);
  621. if (ret)
  622. goto cleanup_irq;
  623. intel_setup_overlay(dev_priv);
  624. if (INTEL_INFO(dev_priv)->num_pipes == 0)
  625. return 0;
  626. ret = intel_fbdev_init(dev);
  627. if (ret)
  628. goto cleanup_gem;
  629. /* Only enable hotplug handling once the fbdev is fully set up. */
  630. intel_hpd_init(dev_priv);
  631. return 0;
  632. cleanup_gem:
  633. if (i915_gem_suspend(dev_priv))
  634. DRM_ERROR("failed to idle hardware; continuing to unload!\n");
  635. i915_gem_fini(dev_priv);
  636. cleanup_irq:
  637. drm_irq_uninstall(dev);
  638. intel_teardown_gmbus(dev_priv);
  639. cleanup_csr:
  640. intel_csr_ucode_fini(dev_priv);
  641. intel_power_domains_fini(dev_priv);
  642. vga_switcheroo_unregister_client(pdev);
  643. cleanup_vga_client:
  644. vga_client_register(pdev, NULL, NULL, NULL);
  645. out:
  646. return ret;
  647. }
  648. static int i915_kick_out_firmware_fb(struct drm_i915_private *dev_priv)
  649. {
  650. struct apertures_struct *ap;
  651. struct pci_dev *pdev = dev_priv->drm.pdev;
  652. struct i915_ggtt *ggtt = &dev_priv->ggtt;
  653. bool primary;
  654. int ret;
  655. ap = alloc_apertures(1);
  656. if (!ap)
  657. return -ENOMEM;
  658. ap->ranges[0].base = ggtt->gmadr.start;
  659. ap->ranges[0].size = ggtt->mappable_end;
  660. primary =
  661. pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
  662. ret = drm_fb_helper_remove_conflicting_framebuffers(ap, "inteldrmfb", primary);
  663. kfree(ap);
  664. return ret;
  665. }
  666. #if !defined(CONFIG_VGA_CONSOLE)
  667. static int i915_kick_out_vgacon(struct drm_i915_private *dev_priv)
  668. {
  669. return 0;
  670. }
  671. #elif !defined(CONFIG_DUMMY_CONSOLE)
  672. static int i915_kick_out_vgacon(struct drm_i915_private *dev_priv)
  673. {
  674. return -ENODEV;
  675. }
  676. #else
  677. static int i915_kick_out_vgacon(struct drm_i915_private *dev_priv)
  678. {
  679. int ret = 0;
  680. DRM_INFO("Replacing VGA console driver\n");
  681. console_lock();
  682. if (con_is_bound(&vga_con))
  683. ret = do_take_over_console(&dummy_con, 0, MAX_NR_CONSOLES - 1, 1);
  684. if (ret == 0) {
  685. ret = do_unregister_con_driver(&vga_con);
  686. /* Ignore "already unregistered". */
  687. if (ret == -ENODEV)
  688. ret = 0;
  689. }
  690. console_unlock();
  691. return ret;
  692. }
  693. #endif
  694. static void intel_init_dpio(struct drm_i915_private *dev_priv)
  695. {
  696. /*
  697. * IOSF_PORT_DPIO is used for VLV x2 PHY (DP/HDMI B and C),
  698. * CHV x1 PHY (DP/HDMI D)
  699. * IOSF_PORT_DPIO_2 is used for CHV x2 PHY (DP/HDMI B and C)
  700. */
  701. if (IS_CHERRYVIEW(dev_priv)) {
  702. DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO_2;
  703. DPIO_PHY_IOSF_PORT(DPIO_PHY1) = IOSF_PORT_DPIO;
  704. } else if (IS_VALLEYVIEW(dev_priv)) {
  705. DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO;
  706. }
  707. }
  708. static int i915_workqueues_init(struct drm_i915_private *dev_priv)
  709. {
  710. /*
  711. * The i915 workqueue is primarily used for batched retirement of
  712. * requests (and thus managing bo) once the task has been completed
  713. * by the GPU. i915_retire_requests() is called directly when we
  714. * need high-priority retirement, such as waiting for an explicit
  715. * bo.
  716. *
  717. * It is also used for periodic low-priority events, such as
  718. * idle-timers and recording error state.
  719. *
  720. * All tasks on the workqueue are expected to acquire the dev mutex
  721. * so there is no point in running more than one instance of the
  722. * workqueue at any time. Use an ordered one.
  723. */
  724. dev_priv->wq = alloc_ordered_workqueue("i915", 0);
  725. if (dev_priv->wq == NULL)
  726. goto out_err;
  727. dev_priv->hotplug.dp_wq = alloc_ordered_workqueue("i915-dp", 0);
  728. if (dev_priv->hotplug.dp_wq == NULL)
  729. goto out_free_wq;
  730. return 0;
  731. out_free_wq:
  732. destroy_workqueue(dev_priv->wq);
  733. out_err:
  734. DRM_ERROR("Failed to allocate workqueues.\n");
  735. return -ENOMEM;
  736. }
  737. static void i915_engines_cleanup(struct drm_i915_private *i915)
  738. {
  739. struct intel_engine_cs *engine;
  740. enum intel_engine_id id;
  741. for_each_engine(engine, i915, id)
  742. kfree(engine);
  743. }
  744. static void i915_workqueues_cleanup(struct drm_i915_private *dev_priv)
  745. {
  746. destroy_workqueue(dev_priv->hotplug.dp_wq);
  747. destroy_workqueue(dev_priv->wq);
  748. }
  749. /*
  750. * We don't keep the workarounds for pre-production hardware, so we expect our
  751. * driver to fail on these machines in one way or another. A little warning on
  752. * dmesg may help both the user and the bug triagers.
  753. *
  754. * Our policy for removing pre-production workarounds is to keep the
  755. * current gen workarounds as a guide to the bring-up of the next gen
  756. * (workarounds have a habit of persisting!). Anything older than that
  757. * should be removed along with the complications they introduce.
  758. */
  759. static void intel_detect_preproduction_hw(struct drm_i915_private *dev_priv)
  760. {
  761. bool pre = false;
  762. pre |= IS_HSW_EARLY_SDV(dev_priv);
  763. pre |= IS_SKL_REVID(dev_priv, 0, SKL_REVID_F0);
  764. pre |= IS_BXT_REVID(dev_priv, 0, BXT_REVID_B_LAST);
  765. if (pre) {
  766. DRM_ERROR("This is a pre-production stepping. "
  767. "It may not be fully functional.\n");
  768. add_taint(TAINT_MACHINE_CHECK, LOCKDEP_STILL_OK);
  769. }
  770. }
  771. /**
  772. * i915_driver_init_early - setup state not requiring device access
  773. * @dev_priv: device private
  774. * @ent: the matching pci_device_id
  775. *
  776. * Initialize everything that is a "SW-only" state, that is state not
  777. * requiring accessing the device or exposing the driver via kernel internal
  778. * or userspace interfaces. Example steps belonging here: lock initialization,
  779. * system memory allocation, setting up device specific attributes and
  780. * function hooks not requiring accessing the device.
  781. */
  782. static int i915_driver_init_early(struct drm_i915_private *dev_priv,
  783. const struct pci_device_id *ent)
  784. {
  785. const struct intel_device_info *match_info =
  786. (struct intel_device_info *)ent->driver_data;
  787. struct intel_device_info *device_info;
  788. int ret = 0;
  789. if (i915_inject_load_failure())
  790. return -ENODEV;
  791. /* Setup the write-once "constant" device info */
  792. device_info = mkwrite_device_info(dev_priv);
  793. memcpy(device_info, match_info, sizeof(*device_info));
  794. device_info->device_id = dev_priv->drm.pdev->device;
  795. BUILD_BUG_ON(INTEL_MAX_PLATFORMS >
  796. sizeof(device_info->platform_mask) * BITS_PER_BYTE);
  797. BUG_ON(device_info->gen > sizeof(device_info->gen_mask) * BITS_PER_BYTE);
  798. spin_lock_init(&dev_priv->irq_lock);
  799. spin_lock_init(&dev_priv->gpu_error.lock);
  800. mutex_init(&dev_priv->backlight_lock);
  801. spin_lock_init(&dev_priv->uncore.lock);
  802. mutex_init(&dev_priv->sb_lock);
  803. mutex_init(&dev_priv->modeset_restore_lock);
  804. mutex_init(&dev_priv->av_mutex);
  805. mutex_init(&dev_priv->wm.wm_mutex);
  806. mutex_init(&dev_priv->pps_mutex);
  807. i915_memcpy_init_early(dev_priv);
  808. ret = i915_workqueues_init(dev_priv);
  809. if (ret < 0)
  810. goto err_engines;
  811. ret = i915_gem_init_early(dev_priv);
  812. if (ret < 0)
  813. goto err_workqueues;
  814. /* This must be called before any calls to HAS_PCH_* */
  815. intel_detect_pch(dev_priv);
  816. intel_wopcm_init_early(&dev_priv->wopcm);
  817. intel_uc_init_early(dev_priv);
  818. intel_pm_setup(dev_priv);
  819. intel_init_dpio(dev_priv);
  820. intel_power_domains_init(dev_priv);
  821. intel_irq_init(dev_priv);
  822. intel_hangcheck_init(dev_priv);
  823. intel_init_display_hooks(dev_priv);
  824. intel_init_clock_gating_hooks(dev_priv);
  825. intel_init_audio_hooks(dev_priv);
  826. intel_display_crc_init(dev_priv);
  827. intel_detect_preproduction_hw(dev_priv);
  828. return 0;
  829. err_workqueues:
  830. i915_workqueues_cleanup(dev_priv);
  831. err_engines:
  832. i915_engines_cleanup(dev_priv);
  833. return ret;
  834. }
  835. /**
  836. * i915_driver_cleanup_early - cleanup the setup done in i915_driver_init_early()
  837. * @dev_priv: device private
  838. */
  839. static void i915_driver_cleanup_early(struct drm_i915_private *dev_priv)
  840. {
  841. intel_irq_fini(dev_priv);
  842. intel_uc_cleanup_early(dev_priv);
  843. i915_gem_cleanup_early(dev_priv);
  844. i915_workqueues_cleanup(dev_priv);
  845. i915_engines_cleanup(dev_priv);
  846. }
  847. static int i915_mmio_setup(struct drm_i915_private *dev_priv)
  848. {
  849. struct pci_dev *pdev = dev_priv->drm.pdev;
  850. int mmio_bar;
  851. int mmio_size;
  852. mmio_bar = IS_GEN2(dev_priv) ? 1 : 0;
  853. /*
  854. * Before gen4, the registers and the GTT are behind different BARs.
  855. * However, from gen4 onwards, the registers and the GTT are shared
  856. * in the same BAR, so we want to restrict this ioremap from
  857. * clobbering the GTT which we want ioremap_wc instead. Fortunately,
  858. * the register BAR remains the same size for all the earlier
  859. * generations up to Ironlake.
  860. */
  861. if (INTEL_GEN(dev_priv) < 5)
  862. mmio_size = 512 * 1024;
  863. else
  864. mmio_size = 2 * 1024 * 1024;
  865. dev_priv->regs = pci_iomap(pdev, mmio_bar, mmio_size);
  866. if (dev_priv->regs == NULL) {
  867. DRM_ERROR("failed to map registers\n");
  868. return -EIO;
  869. }
  870. /* Try to make sure MCHBAR is enabled before poking at it */
  871. intel_setup_mchbar(dev_priv);
  872. return 0;
  873. }
  874. static void i915_mmio_cleanup(struct drm_i915_private *dev_priv)
  875. {
  876. struct pci_dev *pdev = dev_priv->drm.pdev;
  877. intel_teardown_mchbar(dev_priv);
  878. pci_iounmap(pdev, dev_priv->regs);
  879. }
  880. /**
  881. * i915_driver_init_mmio - setup device MMIO
  882. * @dev_priv: device private
  883. *
  884. * Setup minimal device state necessary for MMIO accesses later in the
  885. * initialization sequence. The setup here should avoid any other device-wide
  886. * side effects or exposing the driver via kernel internal or user space
  887. * interfaces.
  888. */
  889. static int i915_driver_init_mmio(struct drm_i915_private *dev_priv)
  890. {
  891. int ret;
  892. if (i915_inject_load_failure())
  893. return -ENODEV;
  894. if (i915_get_bridge_dev(dev_priv))
  895. return -EIO;
  896. ret = i915_mmio_setup(dev_priv);
  897. if (ret < 0)
  898. goto err_bridge;
  899. intel_uncore_init(dev_priv);
  900. intel_device_info_init_mmio(dev_priv);
  901. intel_uncore_prune(dev_priv);
  902. intel_uc_init_mmio(dev_priv);
  903. ret = intel_engines_init_mmio(dev_priv);
  904. if (ret)
  905. goto err_uncore;
  906. i915_gem_init_mmio(dev_priv);
  907. return 0;
  908. err_uncore:
  909. intel_uncore_fini(dev_priv);
  910. err_bridge:
  911. pci_dev_put(dev_priv->bridge_dev);
  912. return ret;
  913. }
  914. /**
  915. * i915_driver_cleanup_mmio - cleanup the setup done in i915_driver_init_mmio()
  916. * @dev_priv: device private
  917. */
  918. static void i915_driver_cleanup_mmio(struct drm_i915_private *dev_priv)
  919. {
  920. intel_uncore_fini(dev_priv);
  921. i915_mmio_cleanup(dev_priv);
  922. pci_dev_put(dev_priv->bridge_dev);
  923. }
  924. static void intel_sanitize_options(struct drm_i915_private *dev_priv)
  925. {
  926. /*
  927. * i915.enable_ppgtt is read-only, so do an early pass to validate the
  928. * user's requested state against the hardware/driver capabilities. We
  929. * do this now so that we can print out any log messages once rather
  930. * than every time we check intel_enable_ppgtt().
  931. */
  932. i915_modparams.enable_ppgtt =
  933. intel_sanitize_enable_ppgtt(dev_priv,
  934. i915_modparams.enable_ppgtt);
  935. DRM_DEBUG_DRIVER("ppgtt mode: %i\n", i915_modparams.enable_ppgtt);
  936. intel_gvt_sanitize_options(dev_priv);
  937. }
  938. /**
  939. * i915_driver_init_hw - setup state requiring device access
  940. * @dev_priv: device private
  941. *
  942. * Setup state that requires accessing the device, but doesn't require
  943. * exposing the driver via kernel internal or userspace interfaces.
  944. */
  945. static int i915_driver_init_hw(struct drm_i915_private *dev_priv)
  946. {
  947. struct pci_dev *pdev = dev_priv->drm.pdev;
  948. int ret;
  949. if (i915_inject_load_failure())
  950. return -ENODEV;
  951. intel_device_info_runtime_init(mkwrite_device_info(dev_priv));
  952. intel_sanitize_options(dev_priv);
  953. i915_perf_init(dev_priv);
  954. ret = i915_ggtt_probe_hw(dev_priv);
  955. if (ret)
  956. goto err_perf;
  957. /*
  958. * WARNING: Apparently we must kick fbdev drivers before vgacon,
  959. * otherwise the vga fbdev driver falls over.
  960. */
  961. ret = i915_kick_out_firmware_fb(dev_priv);
  962. if (ret) {
  963. DRM_ERROR("failed to remove conflicting framebuffer drivers\n");
  964. goto err_ggtt;
  965. }
  966. ret = i915_kick_out_vgacon(dev_priv);
  967. if (ret) {
  968. DRM_ERROR("failed to remove conflicting VGA console\n");
  969. goto err_ggtt;
  970. }
  971. ret = i915_ggtt_init_hw(dev_priv);
  972. if (ret)
  973. goto err_ggtt;
  974. ret = i915_ggtt_enable_hw(dev_priv);
  975. if (ret) {
  976. DRM_ERROR("failed to enable GGTT\n");
  977. goto err_ggtt;
  978. }
  979. pci_set_master(pdev);
  980. /* overlay on gen2 is broken and can't address above 1G */
  981. if (IS_GEN2(dev_priv)) {
  982. ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(30));
  983. if (ret) {
  984. DRM_ERROR("failed to set DMA mask\n");
  985. goto err_ggtt;
  986. }
  987. }
  988. /* 965GM sometimes incorrectly writes to hardware status page (HWS)
  989. * using 32bit addressing, overwriting memory if HWS is located
  990. * above 4GB.
  991. *
  992. * The documentation also mentions an issue with undefined
  993. * behaviour if any general state is accessed within a page above 4GB,
  994. * which also needs to be handled carefully.
  995. */
  996. if (IS_I965G(dev_priv) || IS_I965GM(dev_priv)) {
  997. ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
  998. if (ret) {
  999. DRM_ERROR("failed to set DMA mask\n");
  1000. goto err_ggtt;
  1001. }
  1002. }
  1003. pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY,
  1004. PM_QOS_DEFAULT_VALUE);
  1005. intel_uncore_sanitize(dev_priv);
  1006. intel_opregion_setup(dev_priv);
  1007. i915_gem_load_init_fences(dev_priv);
  1008. /* On the 945G/GM, the chipset reports the MSI capability on the
  1009. * integrated graphics even though the support isn't actually there
  1010. * according to the published specs. It doesn't appear to function
  1011. * correctly in testing on 945G.
  1012. * This may be a side effect of MSI having been made available for PEG
  1013. * and the registers being closely associated.
  1014. *
  1015. * According to chipset errata, on the 965GM, MSI interrupts may
  1016. * be lost or delayed, and was defeatured. MSI interrupts seem to
  1017. * get lost on g4x as well, and interrupt delivery seems to stay
  1018. * properly dead afterwards. So we'll just disable them for all
  1019. * pre-gen5 chipsets.
  1020. */
  1021. if (INTEL_GEN(dev_priv) >= 5) {
  1022. if (pci_enable_msi(pdev) < 0)
  1023. DRM_DEBUG_DRIVER("can't enable MSI");
  1024. }
  1025. ret = intel_gvt_init(dev_priv);
  1026. if (ret)
  1027. goto err_ggtt;
  1028. return 0;
  1029. err_ggtt:
  1030. i915_ggtt_cleanup_hw(dev_priv);
  1031. err_perf:
  1032. i915_perf_fini(dev_priv);
  1033. return ret;
  1034. }
  1035. /**
  1036. * i915_driver_cleanup_hw - cleanup the setup done in i915_driver_init_hw()
  1037. * @dev_priv: device private
  1038. */
  1039. static void i915_driver_cleanup_hw(struct drm_i915_private *dev_priv)
  1040. {
  1041. struct pci_dev *pdev = dev_priv->drm.pdev;
  1042. i915_perf_fini(dev_priv);
  1043. if (pdev->msi_enabled)
  1044. pci_disable_msi(pdev);
  1045. pm_qos_remove_request(&dev_priv->pm_qos);
  1046. i915_ggtt_cleanup_hw(dev_priv);
  1047. }
  1048. /**
  1049. * i915_driver_register - register the driver with the rest of the system
  1050. * @dev_priv: device private
  1051. *
  1052. * Perform any steps necessary to make the driver available via kernel
  1053. * internal or userspace interfaces.
  1054. */
  1055. static void i915_driver_register(struct drm_i915_private *dev_priv)
  1056. {
  1057. struct drm_device *dev = &dev_priv->drm;
  1058. i915_gem_shrinker_register(dev_priv);
  1059. i915_pmu_register(dev_priv);
  1060. /*
  1061. * Notify a valid surface after modesetting,
  1062. * when running inside a VM.
  1063. */
  1064. if (intel_vgpu_active(dev_priv))
  1065. I915_WRITE(vgtif_reg(display_ready), VGT_DRV_DISPLAY_READY);
  1066. /* Reveal our presence to userspace */
  1067. if (drm_dev_register(dev, 0) == 0) {
  1068. i915_debugfs_register(dev_priv);
  1069. i915_setup_sysfs(dev_priv);
  1070. /* Depends on sysfs having been initialized */
  1071. i915_perf_register(dev_priv);
  1072. } else
  1073. DRM_ERROR("Failed to register driver for userspace access!\n");
  1074. if (INTEL_INFO(dev_priv)->num_pipes) {
  1075. /* Must be done after probing outputs */
  1076. intel_opregion_register(dev_priv);
  1077. acpi_video_register();
  1078. }
  1079. if (IS_GEN5(dev_priv))
  1080. intel_gpu_ips_init(dev_priv);
  1081. intel_audio_init(dev_priv);
  1082. /*
  1083. * Some ports require correctly set-up hpd registers for detection to
  1084. * work properly (leading to ghost connected connector status), e.g. VGA
  1085. * on gm45. Hence we can only set up the initial fbdev config after hpd
  1086. * irqs are fully enabled. We do it last so that the async config
  1087. * cannot run before the connectors are registered.
  1088. */
  1089. intel_fbdev_initial_config_async(dev);
  1090. /*
  1091. * We need to coordinate the hotplugs with the asynchronous fbdev
  1092. * configuration, for which we use the fbdev->async_cookie.
  1093. */
  1094. if (INTEL_INFO(dev_priv)->num_pipes)
  1095. drm_kms_helper_poll_init(dev);
  1096. }
  1097. /**
  1098. * i915_driver_unregister - cleanup the registration done in i915_driver_regiser()
  1099. * @dev_priv: device private
  1100. */
  1101. static void i915_driver_unregister(struct drm_i915_private *dev_priv)
  1102. {
  1103. intel_fbdev_unregister(dev_priv);
  1104. intel_audio_deinit(dev_priv);
  1105. /*
  1106. * After flushing the fbdev (incl. a late async config which will
  1107. * have delayed queuing of a hotplug event), then flush the hotplug
  1108. * events.
  1109. */
  1110. drm_kms_helper_poll_fini(&dev_priv->drm);
  1111. intel_gpu_ips_teardown();
  1112. acpi_video_unregister();
  1113. intel_opregion_unregister(dev_priv);
  1114. i915_perf_unregister(dev_priv);
  1115. i915_pmu_unregister(dev_priv);
  1116. i915_teardown_sysfs(dev_priv);
  1117. drm_dev_unregister(&dev_priv->drm);
  1118. i915_gem_shrinker_unregister(dev_priv);
  1119. }
  1120. static void i915_welcome_messages(struct drm_i915_private *dev_priv)
  1121. {
  1122. if (drm_debug & DRM_UT_DRIVER) {
  1123. struct drm_printer p = drm_debug_printer("i915 device info:");
  1124. intel_device_info_dump(&dev_priv->info, &p);
  1125. intel_device_info_dump_runtime(&dev_priv->info, &p);
  1126. }
  1127. if (IS_ENABLED(CONFIG_DRM_I915_DEBUG))
  1128. DRM_INFO("DRM_I915_DEBUG enabled\n");
  1129. if (IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM))
  1130. DRM_INFO("DRM_I915_DEBUG_GEM enabled\n");
  1131. }
  1132. /**
  1133. * i915_driver_load - setup chip and create an initial config
  1134. * @pdev: PCI device
  1135. * @ent: matching PCI ID entry
  1136. *
  1137. * The driver load routine has to do several things:
  1138. * - drive output discovery via intel_modeset_init()
  1139. * - initialize the memory manager
  1140. * - allocate initial config memory
  1141. * - setup the DRM framebuffer with the allocated memory
  1142. */
  1143. int i915_driver_load(struct pci_dev *pdev, const struct pci_device_id *ent)
  1144. {
  1145. const struct intel_device_info *match_info =
  1146. (struct intel_device_info *)ent->driver_data;
  1147. struct drm_i915_private *dev_priv;
  1148. int ret;
  1149. /* Enable nuclear pageflip on ILK+ */
  1150. if (!i915_modparams.nuclear_pageflip && match_info->gen < 5)
  1151. driver.driver_features &= ~DRIVER_ATOMIC;
  1152. ret = -ENOMEM;
  1153. dev_priv = kzalloc(sizeof(*dev_priv), GFP_KERNEL);
  1154. if (dev_priv)
  1155. ret = drm_dev_init(&dev_priv->drm, &driver, &pdev->dev);
  1156. if (ret) {
  1157. DRM_DEV_ERROR(&pdev->dev, "allocation failed\n");
  1158. goto out_free;
  1159. }
  1160. dev_priv->drm.pdev = pdev;
  1161. dev_priv->drm.dev_private = dev_priv;
  1162. ret = pci_enable_device(pdev);
  1163. if (ret)
  1164. goto out_fini;
  1165. pci_set_drvdata(pdev, &dev_priv->drm);
  1166. /*
  1167. * Disable the system suspend direct complete optimization, which can
  1168. * leave the device suspended skipping the driver's suspend handlers
  1169. * if the device was already runtime suspended. This is needed due to
  1170. * the difference in our runtime and system suspend sequence and
  1171. * becaue the HDA driver may require us to enable the audio power
  1172. * domain during system suspend.
  1173. */
  1174. dev_pm_set_driver_flags(&pdev->dev, DPM_FLAG_NEVER_SKIP);
  1175. ret = i915_driver_init_early(dev_priv, ent);
  1176. if (ret < 0)
  1177. goto out_pci_disable;
  1178. intel_runtime_pm_get(dev_priv);
  1179. ret = i915_driver_init_mmio(dev_priv);
  1180. if (ret < 0)
  1181. goto out_runtime_pm_put;
  1182. ret = i915_driver_init_hw(dev_priv);
  1183. if (ret < 0)
  1184. goto out_cleanup_mmio;
  1185. /*
  1186. * TODO: move the vblank init and parts of modeset init steps into one
  1187. * of the i915_driver_init_/i915_driver_register functions according
  1188. * to the role/effect of the given init step.
  1189. */
  1190. if (INTEL_INFO(dev_priv)->num_pipes) {
  1191. ret = drm_vblank_init(&dev_priv->drm,
  1192. INTEL_INFO(dev_priv)->num_pipes);
  1193. if (ret)
  1194. goto out_cleanup_hw;
  1195. }
  1196. ret = i915_load_modeset_init(&dev_priv->drm);
  1197. if (ret < 0)
  1198. goto out_cleanup_hw;
  1199. i915_driver_register(dev_priv);
  1200. intel_runtime_pm_enable(dev_priv);
  1201. intel_init_ipc(dev_priv);
  1202. intel_runtime_pm_put(dev_priv);
  1203. i915_welcome_messages(dev_priv);
  1204. return 0;
  1205. out_cleanup_hw:
  1206. i915_driver_cleanup_hw(dev_priv);
  1207. out_cleanup_mmio:
  1208. i915_driver_cleanup_mmio(dev_priv);
  1209. out_runtime_pm_put:
  1210. intel_runtime_pm_put(dev_priv);
  1211. i915_driver_cleanup_early(dev_priv);
  1212. out_pci_disable:
  1213. pci_disable_device(pdev);
  1214. out_fini:
  1215. i915_load_error(dev_priv, "Device initialization failed (%d)\n", ret);
  1216. drm_dev_fini(&dev_priv->drm);
  1217. out_free:
  1218. kfree(dev_priv);
  1219. return ret;
  1220. }
  1221. void i915_driver_unload(struct drm_device *dev)
  1222. {
  1223. struct drm_i915_private *dev_priv = to_i915(dev);
  1224. struct pci_dev *pdev = dev_priv->drm.pdev;
  1225. i915_driver_unregister(dev_priv);
  1226. if (i915_gem_suspend(dev_priv))
  1227. DRM_ERROR("failed to idle hardware; continuing to unload!\n");
  1228. intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
  1229. drm_atomic_helper_shutdown(dev);
  1230. intel_gvt_cleanup(dev_priv);
  1231. intel_modeset_cleanup(dev);
  1232. intel_bios_cleanup(dev_priv);
  1233. vga_switcheroo_unregister_client(pdev);
  1234. vga_client_register(pdev, NULL, NULL, NULL);
  1235. intel_csr_ucode_fini(dev_priv);
  1236. /* Free error state after interrupts are fully disabled. */
  1237. cancel_delayed_work_sync(&dev_priv->gpu_error.hangcheck_work);
  1238. i915_reset_error_state(dev_priv);
  1239. i915_gem_fini(dev_priv);
  1240. intel_fbc_cleanup_cfb(dev_priv);
  1241. intel_power_domains_fini(dev_priv);
  1242. i915_driver_cleanup_hw(dev_priv);
  1243. i915_driver_cleanup_mmio(dev_priv);
  1244. intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
  1245. }
  1246. static void i915_driver_release(struct drm_device *dev)
  1247. {
  1248. struct drm_i915_private *dev_priv = to_i915(dev);
  1249. i915_driver_cleanup_early(dev_priv);
  1250. drm_dev_fini(&dev_priv->drm);
  1251. kfree(dev_priv);
  1252. }
  1253. static int i915_driver_open(struct drm_device *dev, struct drm_file *file)
  1254. {
  1255. struct drm_i915_private *i915 = to_i915(dev);
  1256. int ret;
  1257. ret = i915_gem_open(i915, file);
  1258. if (ret)
  1259. return ret;
  1260. return 0;
  1261. }
  1262. /**
  1263. * i915_driver_lastclose - clean up after all DRM clients have exited
  1264. * @dev: DRM device
  1265. *
  1266. * Take care of cleaning up after all DRM clients have exited. In the
  1267. * mode setting case, we want to restore the kernel's initial mode (just
  1268. * in case the last client left us in a bad state).
  1269. *
  1270. * Additionally, in the non-mode setting case, we'll tear down the GTT
  1271. * and DMA structures, since the kernel won't be using them, and clea
  1272. * up any GEM state.
  1273. */
  1274. static void i915_driver_lastclose(struct drm_device *dev)
  1275. {
  1276. intel_fbdev_restore_mode(dev);
  1277. vga_switcheroo_process_delayed_switch();
  1278. }
  1279. static void i915_driver_postclose(struct drm_device *dev, struct drm_file *file)
  1280. {
  1281. struct drm_i915_file_private *file_priv = file->driver_priv;
  1282. mutex_lock(&dev->struct_mutex);
  1283. i915_gem_context_close(file);
  1284. i915_gem_release(dev, file);
  1285. mutex_unlock(&dev->struct_mutex);
  1286. kfree(file_priv);
  1287. }
  1288. static void intel_suspend_encoders(struct drm_i915_private *dev_priv)
  1289. {
  1290. struct drm_device *dev = &dev_priv->drm;
  1291. struct intel_encoder *encoder;
  1292. drm_modeset_lock_all(dev);
  1293. for_each_intel_encoder(dev, encoder)
  1294. if (encoder->suspend)
  1295. encoder->suspend(encoder);
  1296. drm_modeset_unlock_all(dev);
  1297. }
  1298. static int vlv_resume_prepare(struct drm_i915_private *dev_priv,
  1299. bool rpm_resume);
  1300. static int vlv_suspend_complete(struct drm_i915_private *dev_priv);
  1301. static bool suspend_to_idle(struct drm_i915_private *dev_priv)
  1302. {
  1303. #if IS_ENABLED(CONFIG_ACPI_SLEEP)
  1304. if (acpi_target_system_state() < ACPI_STATE_S3)
  1305. return true;
  1306. #endif
  1307. return false;
  1308. }
  1309. static int i915_drm_suspend(struct drm_device *dev)
  1310. {
  1311. struct drm_i915_private *dev_priv = to_i915(dev);
  1312. struct pci_dev *pdev = dev_priv->drm.pdev;
  1313. pci_power_t opregion_target_state;
  1314. int error;
  1315. /* ignore lid events during suspend */
  1316. mutex_lock(&dev_priv->modeset_restore_lock);
  1317. dev_priv->modeset_restore = MODESET_SUSPENDED;
  1318. mutex_unlock(&dev_priv->modeset_restore_lock);
  1319. disable_rpm_wakeref_asserts(dev_priv);
  1320. /* We do a lot of poking in a lot of registers, make sure they work
  1321. * properly. */
  1322. intel_display_set_init_power(dev_priv, true);
  1323. drm_kms_helper_poll_disable(dev);
  1324. pci_save_state(pdev);
  1325. error = i915_gem_suspend(dev_priv);
  1326. if (error) {
  1327. dev_err(&pdev->dev,
  1328. "GEM idle failed, resume might fail\n");
  1329. goto out;
  1330. }
  1331. intel_display_suspend(dev);
  1332. intel_dp_mst_suspend(dev);
  1333. intel_runtime_pm_disable_interrupts(dev_priv);
  1334. intel_hpd_cancel_work(dev_priv);
  1335. intel_suspend_encoders(dev_priv);
  1336. intel_suspend_hw(dev_priv);
  1337. i915_gem_suspend_gtt_mappings(dev_priv);
  1338. i915_save_state(dev_priv);
  1339. opregion_target_state = suspend_to_idle(dev_priv) ? PCI_D1 : PCI_D3cold;
  1340. intel_opregion_notify_adapter(dev_priv, opregion_target_state);
  1341. intel_uncore_suspend(dev_priv);
  1342. intel_opregion_unregister(dev_priv);
  1343. intel_fbdev_set_suspend(dev, FBINFO_STATE_SUSPENDED, true);
  1344. dev_priv->suspend_count++;
  1345. intel_csr_ucode_suspend(dev_priv);
  1346. out:
  1347. enable_rpm_wakeref_asserts(dev_priv);
  1348. return error;
  1349. }
  1350. static int i915_drm_suspend_late(struct drm_device *dev, bool hibernation)
  1351. {
  1352. struct drm_i915_private *dev_priv = to_i915(dev);
  1353. struct pci_dev *pdev = dev_priv->drm.pdev;
  1354. int ret;
  1355. disable_rpm_wakeref_asserts(dev_priv);
  1356. intel_display_set_init_power(dev_priv, false);
  1357. /*
  1358. * In case of firmware assisted context save/restore don't manually
  1359. * deinit the power domains. This also means the CSR/DMC firmware will
  1360. * stay active, it will power down any HW resources as required and
  1361. * also enable deeper system power states that would be blocked if the
  1362. * firmware was inactive.
  1363. */
  1364. if (IS_GEN9_LP(dev_priv) || hibernation || !suspend_to_idle(dev_priv) ||
  1365. dev_priv->csr.dmc_payload == NULL) {
  1366. intel_power_domains_suspend(dev_priv);
  1367. dev_priv->power_domains_suspended = true;
  1368. }
  1369. ret = 0;
  1370. if (IS_GEN9_LP(dev_priv))
  1371. bxt_enable_dc9(dev_priv);
  1372. else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
  1373. hsw_enable_pc8(dev_priv);
  1374. else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  1375. ret = vlv_suspend_complete(dev_priv);
  1376. if (ret) {
  1377. DRM_ERROR("Suspend complete failed: %d\n", ret);
  1378. if (dev_priv->power_domains_suspended) {
  1379. intel_power_domains_init_hw(dev_priv, true);
  1380. dev_priv->power_domains_suspended = false;
  1381. }
  1382. goto out;
  1383. }
  1384. pci_disable_device(pdev);
  1385. /*
  1386. * During hibernation on some platforms the BIOS may try to access
  1387. * the device even though it's already in D3 and hang the machine. So
  1388. * leave the device in D0 on those platforms and hope the BIOS will
  1389. * power down the device properly. The issue was seen on multiple old
  1390. * GENs with different BIOS vendors, so having an explicit blacklist
  1391. * is inpractical; apply the workaround on everything pre GEN6. The
  1392. * platforms where the issue was seen:
  1393. * Lenovo Thinkpad X301, X61s, X60, T60, X41
  1394. * Fujitsu FSC S7110
  1395. * Acer Aspire 1830T
  1396. */
  1397. if (!(hibernation && INTEL_GEN(dev_priv) < 6))
  1398. pci_set_power_state(pdev, PCI_D3hot);
  1399. out:
  1400. enable_rpm_wakeref_asserts(dev_priv);
  1401. return ret;
  1402. }
  1403. static int i915_suspend_switcheroo(struct drm_device *dev, pm_message_t state)
  1404. {
  1405. int error;
  1406. if (!dev) {
  1407. DRM_ERROR("dev: %p\n", dev);
  1408. DRM_ERROR("DRM not initialized, aborting suspend.\n");
  1409. return -ENODEV;
  1410. }
  1411. if (WARN_ON_ONCE(state.event != PM_EVENT_SUSPEND &&
  1412. state.event != PM_EVENT_FREEZE))
  1413. return -EINVAL;
  1414. if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
  1415. return 0;
  1416. error = i915_drm_suspend(dev);
  1417. if (error)
  1418. return error;
  1419. return i915_drm_suspend_late(dev, false);
  1420. }
  1421. static int i915_drm_resume(struct drm_device *dev)
  1422. {
  1423. struct drm_i915_private *dev_priv = to_i915(dev);
  1424. int ret;
  1425. disable_rpm_wakeref_asserts(dev_priv);
  1426. intel_sanitize_gt_powersave(dev_priv);
  1427. ret = i915_ggtt_enable_hw(dev_priv);
  1428. if (ret)
  1429. DRM_ERROR("failed to re-enable GGTT\n");
  1430. intel_csr_ucode_resume(dev_priv);
  1431. i915_restore_state(dev_priv);
  1432. intel_pps_unlock_regs_wa(dev_priv);
  1433. intel_opregion_setup(dev_priv);
  1434. intel_init_pch_refclk(dev_priv);
  1435. /*
  1436. * Interrupts have to be enabled before any batches are run. If not the
  1437. * GPU will hang. i915_gem_init_hw() will initiate batches to
  1438. * update/restore the context.
  1439. *
  1440. * drm_mode_config_reset() needs AUX interrupts.
  1441. *
  1442. * Modeset enabling in intel_modeset_init_hw() also needs working
  1443. * interrupts.
  1444. */
  1445. intel_runtime_pm_enable_interrupts(dev_priv);
  1446. drm_mode_config_reset(dev);
  1447. i915_gem_resume(dev_priv);
  1448. intel_modeset_init_hw(dev);
  1449. intel_init_clock_gating(dev_priv);
  1450. spin_lock_irq(&dev_priv->irq_lock);
  1451. if (dev_priv->display.hpd_irq_setup)
  1452. dev_priv->display.hpd_irq_setup(dev_priv);
  1453. spin_unlock_irq(&dev_priv->irq_lock);
  1454. intel_dp_mst_resume(dev);
  1455. intel_display_resume(dev);
  1456. drm_kms_helper_poll_enable(dev);
  1457. /*
  1458. * ... but also need to make sure that hotplug processing
  1459. * doesn't cause havoc. Like in the driver load code we don't
  1460. * bother with the tiny race here where we might loose hotplug
  1461. * notifications.
  1462. * */
  1463. intel_hpd_init(dev_priv);
  1464. intel_opregion_register(dev_priv);
  1465. intel_fbdev_set_suspend(dev, FBINFO_STATE_RUNNING, false);
  1466. mutex_lock(&dev_priv->modeset_restore_lock);
  1467. dev_priv->modeset_restore = MODESET_DONE;
  1468. mutex_unlock(&dev_priv->modeset_restore_lock);
  1469. intel_opregion_notify_adapter(dev_priv, PCI_D0);
  1470. enable_rpm_wakeref_asserts(dev_priv);
  1471. return 0;
  1472. }
  1473. static int i915_drm_resume_early(struct drm_device *dev)
  1474. {
  1475. struct drm_i915_private *dev_priv = to_i915(dev);
  1476. struct pci_dev *pdev = dev_priv->drm.pdev;
  1477. int ret;
  1478. /*
  1479. * We have a resume ordering issue with the snd-hda driver also
  1480. * requiring our device to be power up. Due to the lack of a
  1481. * parent/child relationship we currently solve this with an early
  1482. * resume hook.
  1483. *
  1484. * FIXME: This should be solved with a special hdmi sink device or
  1485. * similar so that power domains can be employed.
  1486. */
  1487. /*
  1488. * Note that we need to set the power state explicitly, since we
  1489. * powered off the device during freeze and the PCI core won't power
  1490. * it back up for us during thaw. Powering off the device during
  1491. * freeze is not a hard requirement though, and during the
  1492. * suspend/resume phases the PCI core makes sure we get here with the
  1493. * device powered on. So in case we change our freeze logic and keep
  1494. * the device powered we can also remove the following set power state
  1495. * call.
  1496. */
  1497. ret = pci_set_power_state(pdev, PCI_D0);
  1498. if (ret) {
  1499. DRM_ERROR("failed to set PCI D0 power state (%d)\n", ret);
  1500. goto out;
  1501. }
  1502. /*
  1503. * Note that pci_enable_device() first enables any parent bridge
  1504. * device and only then sets the power state for this device. The
  1505. * bridge enabling is a nop though, since bridge devices are resumed
  1506. * first. The order of enabling power and enabling the device is
  1507. * imposed by the PCI core as described above, so here we preserve the
  1508. * same order for the freeze/thaw phases.
  1509. *
  1510. * TODO: eventually we should remove pci_disable_device() /
  1511. * pci_enable_enable_device() from suspend/resume. Due to how they
  1512. * depend on the device enable refcount we can't anyway depend on them
  1513. * disabling/enabling the device.
  1514. */
  1515. if (pci_enable_device(pdev)) {
  1516. ret = -EIO;
  1517. goto out;
  1518. }
  1519. pci_set_master(pdev);
  1520. disable_rpm_wakeref_asserts(dev_priv);
  1521. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  1522. ret = vlv_resume_prepare(dev_priv, false);
  1523. if (ret)
  1524. DRM_ERROR("Resume prepare failed: %d, continuing anyway\n",
  1525. ret);
  1526. intel_uncore_resume_early(dev_priv);
  1527. if (IS_GEN9_LP(dev_priv)) {
  1528. gen9_sanitize_dc_state(dev_priv);
  1529. bxt_disable_dc9(dev_priv);
  1530. } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
  1531. hsw_disable_pc8(dev_priv);
  1532. }
  1533. intel_uncore_sanitize(dev_priv);
  1534. if (dev_priv->power_domains_suspended)
  1535. intel_power_domains_init_hw(dev_priv, true);
  1536. else
  1537. intel_display_set_init_power(dev_priv, true);
  1538. i915_gem_sanitize(dev_priv);
  1539. enable_rpm_wakeref_asserts(dev_priv);
  1540. out:
  1541. dev_priv->power_domains_suspended = false;
  1542. return ret;
  1543. }
  1544. static int i915_resume_switcheroo(struct drm_device *dev)
  1545. {
  1546. int ret;
  1547. if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
  1548. return 0;
  1549. ret = i915_drm_resume_early(dev);
  1550. if (ret)
  1551. return ret;
  1552. return i915_drm_resume(dev);
  1553. }
  1554. /**
  1555. * i915_reset - reset chip after a hang
  1556. * @i915: #drm_i915_private to reset
  1557. * @stalled_mask: mask of the stalled engines with the guilty requests
  1558. * @reason: user error message for why we are resetting
  1559. *
  1560. * Reset the chip. Useful if a hang is detected. Marks the device as wedged
  1561. * on failure.
  1562. *
  1563. * Caller must hold the struct_mutex.
  1564. *
  1565. * Procedure is fairly simple:
  1566. * - reset the chip using the reset reg
  1567. * - re-init context state
  1568. * - re-init hardware status page
  1569. * - re-init ring buffer
  1570. * - re-init interrupt state
  1571. * - re-init display
  1572. */
  1573. void i915_reset(struct drm_i915_private *i915,
  1574. unsigned int stalled_mask,
  1575. const char *reason)
  1576. {
  1577. struct i915_gpu_error *error = &i915->gpu_error;
  1578. int ret;
  1579. int i;
  1580. GEM_TRACE("flags=%lx\n", error->flags);
  1581. might_sleep();
  1582. lockdep_assert_held(&i915->drm.struct_mutex);
  1583. GEM_BUG_ON(!test_bit(I915_RESET_BACKOFF, &error->flags));
  1584. if (!test_bit(I915_RESET_HANDOFF, &error->flags))
  1585. return;
  1586. /* Clear any previous failed attempts at recovery. Time to try again. */
  1587. if (!i915_gem_unset_wedged(i915))
  1588. goto wakeup;
  1589. if (reason)
  1590. dev_notice(i915->drm.dev, "Resetting chip for %s\n", reason);
  1591. error->reset_count++;
  1592. disable_irq(i915->drm.irq);
  1593. ret = i915_gem_reset_prepare(i915);
  1594. if (ret) {
  1595. dev_err(i915->drm.dev, "GPU recovery failed\n");
  1596. goto taint;
  1597. }
  1598. if (!intel_has_gpu_reset(i915)) {
  1599. if (i915_modparams.reset)
  1600. dev_err(i915->drm.dev, "GPU reset not supported\n");
  1601. else
  1602. DRM_DEBUG_DRIVER("GPU reset disabled\n");
  1603. goto error;
  1604. }
  1605. for (i = 0; i < 3; i++) {
  1606. ret = intel_gpu_reset(i915, ALL_ENGINES);
  1607. if (ret == 0)
  1608. break;
  1609. msleep(100);
  1610. }
  1611. if (ret) {
  1612. dev_err(i915->drm.dev, "Failed to reset chip\n");
  1613. goto taint;
  1614. }
  1615. /* Ok, now get things going again... */
  1616. /*
  1617. * Everything depends on having the GTT running, so we need to start
  1618. * there.
  1619. */
  1620. ret = i915_ggtt_enable_hw(i915);
  1621. if (ret) {
  1622. DRM_ERROR("Failed to re-enable GGTT following reset (%d)\n",
  1623. ret);
  1624. goto error;
  1625. }
  1626. i915_gem_reset(i915, stalled_mask);
  1627. intel_overlay_reset(i915);
  1628. /*
  1629. * Next we need to restore the context, but we don't use those
  1630. * yet either...
  1631. *
  1632. * Ring buffer needs to be re-initialized in the KMS case, or if X
  1633. * was running at the time of the reset (i.e. we weren't VT
  1634. * switched away).
  1635. */
  1636. ret = i915_gem_init_hw(i915);
  1637. if (ret) {
  1638. DRM_ERROR("Failed to initialise HW following reset (%d)\n",
  1639. ret);
  1640. goto error;
  1641. }
  1642. i915_queue_hangcheck(i915);
  1643. finish:
  1644. i915_gem_reset_finish(i915);
  1645. enable_irq(i915->drm.irq);
  1646. wakeup:
  1647. clear_bit(I915_RESET_HANDOFF, &error->flags);
  1648. wake_up_bit(&error->flags, I915_RESET_HANDOFF);
  1649. return;
  1650. taint:
  1651. /*
  1652. * History tells us that if we cannot reset the GPU now, we
  1653. * never will. This then impacts everything that is run
  1654. * subsequently. On failing the reset, we mark the driver
  1655. * as wedged, preventing further execution on the GPU.
  1656. * We also want to go one step further and add a taint to the
  1657. * kernel so that any subsequent faults can be traced back to
  1658. * this failure. This is important for CI, where if the
  1659. * GPU/driver fails we would like to reboot and restart testing
  1660. * rather than continue on into oblivion. For everyone else,
  1661. * the system should still plod along, but they have been warned!
  1662. */
  1663. add_taint(TAINT_WARN, LOCKDEP_STILL_OK);
  1664. error:
  1665. i915_gem_set_wedged(i915);
  1666. i915_retire_requests(i915);
  1667. goto finish;
  1668. }
  1669. static inline int intel_gt_reset_engine(struct drm_i915_private *dev_priv,
  1670. struct intel_engine_cs *engine)
  1671. {
  1672. return intel_gpu_reset(dev_priv, intel_engine_flag(engine));
  1673. }
  1674. /**
  1675. * i915_reset_engine - reset GPU engine to recover from a hang
  1676. * @engine: engine to reset
  1677. * @msg: reason for GPU reset; or NULL for no dev_notice()
  1678. *
  1679. * Reset a specific GPU engine. Useful if a hang is detected.
  1680. * Returns zero on successful reset or otherwise an error code.
  1681. *
  1682. * Procedure is:
  1683. * - identifies the request that caused the hang and it is dropped
  1684. * - reset engine (which will force the engine to idle)
  1685. * - re-init/configure engine
  1686. */
  1687. int i915_reset_engine(struct intel_engine_cs *engine, const char *msg)
  1688. {
  1689. struct i915_gpu_error *error = &engine->i915->gpu_error;
  1690. struct i915_request *active_request;
  1691. int ret;
  1692. GEM_TRACE("%s flags=%lx\n", engine->name, error->flags);
  1693. GEM_BUG_ON(!test_bit(I915_RESET_ENGINE + engine->id, &error->flags));
  1694. active_request = i915_gem_reset_prepare_engine(engine);
  1695. if (IS_ERR_OR_NULL(active_request)) {
  1696. /* Either the previous reset failed, or we pardon the reset. */
  1697. ret = PTR_ERR(active_request);
  1698. goto out;
  1699. }
  1700. if (msg)
  1701. dev_notice(engine->i915->drm.dev,
  1702. "Resetting %s for %s\n", engine->name, msg);
  1703. error->reset_engine_count[engine->id]++;
  1704. if (!engine->i915->guc.execbuf_client)
  1705. ret = intel_gt_reset_engine(engine->i915, engine);
  1706. else
  1707. ret = intel_guc_reset_engine(&engine->i915->guc, engine);
  1708. if (ret) {
  1709. /* If we fail here, we expect to fallback to a global reset */
  1710. DRM_DEBUG_DRIVER("%sFailed to reset %s, ret=%d\n",
  1711. engine->i915->guc.execbuf_client ? "GuC " : "",
  1712. engine->name, ret);
  1713. goto out;
  1714. }
  1715. /*
  1716. * The request that caused the hang is stuck on elsp, we know the
  1717. * active request and can drop it, adjust head to skip the offending
  1718. * request to resume executing remaining requests in the queue.
  1719. */
  1720. i915_gem_reset_engine(engine, active_request, true);
  1721. /*
  1722. * The engine and its registers (and workarounds in case of render)
  1723. * have been reset to their default values. Follow the init_ring
  1724. * process to program RING_MODE, HWSP and re-enable submission.
  1725. */
  1726. ret = engine->init_hw(engine);
  1727. if (ret)
  1728. goto out;
  1729. out:
  1730. i915_gem_reset_finish_engine(engine);
  1731. return ret;
  1732. }
  1733. static int i915_pm_suspend(struct device *kdev)
  1734. {
  1735. struct pci_dev *pdev = to_pci_dev(kdev);
  1736. struct drm_device *dev = pci_get_drvdata(pdev);
  1737. if (!dev) {
  1738. dev_err(kdev, "DRM not initialized, aborting suspend.\n");
  1739. return -ENODEV;
  1740. }
  1741. if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
  1742. return 0;
  1743. return i915_drm_suspend(dev);
  1744. }
  1745. static int i915_pm_suspend_late(struct device *kdev)
  1746. {
  1747. struct drm_device *dev = &kdev_to_i915(kdev)->drm;
  1748. /*
  1749. * We have a suspend ordering issue with the snd-hda driver also
  1750. * requiring our device to be power up. Due to the lack of a
  1751. * parent/child relationship we currently solve this with an late
  1752. * suspend hook.
  1753. *
  1754. * FIXME: This should be solved with a special hdmi sink device or
  1755. * similar so that power domains can be employed.
  1756. */
  1757. if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
  1758. return 0;
  1759. return i915_drm_suspend_late(dev, false);
  1760. }
  1761. static int i915_pm_poweroff_late(struct device *kdev)
  1762. {
  1763. struct drm_device *dev = &kdev_to_i915(kdev)->drm;
  1764. if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
  1765. return 0;
  1766. return i915_drm_suspend_late(dev, true);
  1767. }
  1768. static int i915_pm_resume_early(struct device *kdev)
  1769. {
  1770. struct drm_device *dev = &kdev_to_i915(kdev)->drm;
  1771. if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
  1772. return 0;
  1773. return i915_drm_resume_early(dev);
  1774. }
  1775. static int i915_pm_resume(struct device *kdev)
  1776. {
  1777. struct drm_device *dev = &kdev_to_i915(kdev)->drm;
  1778. if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
  1779. return 0;
  1780. return i915_drm_resume(dev);
  1781. }
  1782. /* freeze: before creating the hibernation_image */
  1783. static int i915_pm_freeze(struct device *kdev)
  1784. {
  1785. struct drm_device *dev = &kdev_to_i915(kdev)->drm;
  1786. int ret;
  1787. if (dev->switch_power_state != DRM_SWITCH_POWER_OFF) {
  1788. ret = i915_drm_suspend(dev);
  1789. if (ret)
  1790. return ret;
  1791. }
  1792. ret = i915_gem_freeze(kdev_to_i915(kdev));
  1793. if (ret)
  1794. return ret;
  1795. return 0;
  1796. }
  1797. static int i915_pm_freeze_late(struct device *kdev)
  1798. {
  1799. struct drm_device *dev = &kdev_to_i915(kdev)->drm;
  1800. int ret;
  1801. if (dev->switch_power_state != DRM_SWITCH_POWER_OFF) {
  1802. ret = i915_drm_suspend_late(dev, true);
  1803. if (ret)
  1804. return ret;
  1805. }
  1806. ret = i915_gem_freeze_late(kdev_to_i915(kdev));
  1807. if (ret)
  1808. return ret;
  1809. return 0;
  1810. }
  1811. /* thaw: called after creating the hibernation image, but before turning off. */
  1812. static int i915_pm_thaw_early(struct device *kdev)
  1813. {
  1814. return i915_pm_resume_early(kdev);
  1815. }
  1816. static int i915_pm_thaw(struct device *kdev)
  1817. {
  1818. return i915_pm_resume(kdev);
  1819. }
  1820. /* restore: called after loading the hibernation image. */
  1821. static int i915_pm_restore_early(struct device *kdev)
  1822. {
  1823. return i915_pm_resume_early(kdev);
  1824. }
  1825. static int i915_pm_restore(struct device *kdev)
  1826. {
  1827. return i915_pm_resume(kdev);
  1828. }
  1829. /*
  1830. * Save all Gunit registers that may be lost after a D3 and a subsequent
  1831. * S0i[R123] transition. The list of registers needing a save/restore is
  1832. * defined in the VLV2_S0IXRegs document. This documents marks all Gunit
  1833. * registers in the following way:
  1834. * - Driver: saved/restored by the driver
  1835. * - Punit : saved/restored by the Punit firmware
  1836. * - No, w/o marking: no need to save/restore, since the register is R/O or
  1837. * used internally by the HW in a way that doesn't depend
  1838. * keeping the content across a suspend/resume.
  1839. * - Debug : used for debugging
  1840. *
  1841. * We save/restore all registers marked with 'Driver', with the following
  1842. * exceptions:
  1843. * - Registers out of use, including also registers marked with 'Debug'.
  1844. * These have no effect on the driver's operation, so we don't save/restore
  1845. * them to reduce the overhead.
  1846. * - Registers that are fully setup by an initialization function called from
  1847. * the resume path. For example many clock gating and RPS/RC6 registers.
  1848. * - Registers that provide the right functionality with their reset defaults.
  1849. *
  1850. * TODO: Except for registers that based on the above 3 criteria can be safely
  1851. * ignored, we save/restore all others, practically treating the HW context as
  1852. * a black-box for the driver. Further investigation is needed to reduce the
  1853. * saved/restored registers even further, by following the same 3 criteria.
  1854. */
  1855. static void vlv_save_gunit_s0ix_state(struct drm_i915_private *dev_priv)
  1856. {
  1857. struct vlv_s0ix_state *s = &dev_priv->vlv_s0ix_state;
  1858. int i;
  1859. /* GAM 0x4000-0x4770 */
  1860. s->wr_watermark = I915_READ(GEN7_WR_WATERMARK);
  1861. s->gfx_prio_ctrl = I915_READ(GEN7_GFX_PRIO_CTRL);
  1862. s->arb_mode = I915_READ(ARB_MODE);
  1863. s->gfx_pend_tlb0 = I915_READ(GEN7_GFX_PEND_TLB0);
  1864. s->gfx_pend_tlb1 = I915_READ(GEN7_GFX_PEND_TLB1);
  1865. for (i = 0; i < ARRAY_SIZE(s->lra_limits); i++)
  1866. s->lra_limits[i] = I915_READ(GEN7_LRA_LIMITS(i));
  1867. s->media_max_req_count = I915_READ(GEN7_MEDIA_MAX_REQ_COUNT);
  1868. s->gfx_max_req_count = I915_READ(GEN7_GFX_MAX_REQ_COUNT);
  1869. s->render_hwsp = I915_READ(RENDER_HWS_PGA_GEN7);
  1870. s->ecochk = I915_READ(GAM_ECOCHK);
  1871. s->bsd_hwsp = I915_READ(BSD_HWS_PGA_GEN7);
  1872. s->blt_hwsp = I915_READ(BLT_HWS_PGA_GEN7);
  1873. s->tlb_rd_addr = I915_READ(GEN7_TLB_RD_ADDR);
  1874. /* MBC 0x9024-0x91D0, 0x8500 */
  1875. s->g3dctl = I915_READ(VLV_G3DCTL);
  1876. s->gsckgctl = I915_READ(VLV_GSCKGCTL);
  1877. s->mbctl = I915_READ(GEN6_MBCTL);
  1878. /* GCP 0x9400-0x9424, 0x8100-0x810C */
  1879. s->ucgctl1 = I915_READ(GEN6_UCGCTL1);
  1880. s->ucgctl3 = I915_READ(GEN6_UCGCTL3);
  1881. s->rcgctl1 = I915_READ(GEN6_RCGCTL1);
  1882. s->rcgctl2 = I915_READ(GEN6_RCGCTL2);
  1883. s->rstctl = I915_READ(GEN6_RSTCTL);
  1884. s->misccpctl = I915_READ(GEN7_MISCCPCTL);
  1885. /* GPM 0xA000-0xAA84, 0x8000-0x80FC */
  1886. s->gfxpause = I915_READ(GEN6_GFXPAUSE);
  1887. s->rpdeuhwtc = I915_READ(GEN6_RPDEUHWTC);
  1888. s->rpdeuc = I915_READ(GEN6_RPDEUC);
  1889. s->ecobus = I915_READ(ECOBUS);
  1890. s->pwrdwnupctl = I915_READ(VLV_PWRDWNUPCTL);
  1891. s->rp_down_timeout = I915_READ(GEN6_RP_DOWN_TIMEOUT);
  1892. s->rp_deucsw = I915_READ(GEN6_RPDEUCSW);
  1893. s->rcubmabdtmr = I915_READ(GEN6_RCUBMABDTMR);
  1894. s->rcedata = I915_READ(VLV_RCEDATA);
  1895. s->spare2gh = I915_READ(VLV_SPAREG2H);
  1896. /* Display CZ domain, 0x4400C-0x4402C, 0x4F000-0x4F11F */
  1897. s->gt_imr = I915_READ(GTIMR);
  1898. s->gt_ier = I915_READ(GTIER);
  1899. s->pm_imr = I915_READ(GEN6_PMIMR);
  1900. s->pm_ier = I915_READ(GEN6_PMIER);
  1901. for (i = 0; i < ARRAY_SIZE(s->gt_scratch); i++)
  1902. s->gt_scratch[i] = I915_READ(GEN7_GT_SCRATCH(i));
  1903. /* GT SA CZ domain, 0x100000-0x138124 */
  1904. s->tilectl = I915_READ(TILECTL);
  1905. s->gt_fifoctl = I915_READ(GTFIFOCTL);
  1906. s->gtlc_wake_ctrl = I915_READ(VLV_GTLC_WAKE_CTRL);
  1907. s->gtlc_survive = I915_READ(VLV_GTLC_SURVIVABILITY_REG);
  1908. s->pmwgicz = I915_READ(VLV_PMWGICZ);
  1909. /* Gunit-Display CZ domain, 0x182028-0x1821CF */
  1910. s->gu_ctl0 = I915_READ(VLV_GU_CTL0);
  1911. s->gu_ctl1 = I915_READ(VLV_GU_CTL1);
  1912. s->pcbr = I915_READ(VLV_PCBR);
  1913. s->clock_gate_dis2 = I915_READ(VLV_GUNIT_CLOCK_GATE2);
  1914. /*
  1915. * Not saving any of:
  1916. * DFT, 0x9800-0x9EC0
  1917. * SARB, 0xB000-0xB1FC
  1918. * GAC, 0x5208-0x524C, 0x14000-0x14C000
  1919. * PCI CFG
  1920. */
  1921. }
  1922. static void vlv_restore_gunit_s0ix_state(struct drm_i915_private *dev_priv)
  1923. {
  1924. struct vlv_s0ix_state *s = &dev_priv->vlv_s0ix_state;
  1925. u32 val;
  1926. int i;
  1927. /* GAM 0x4000-0x4770 */
  1928. I915_WRITE(GEN7_WR_WATERMARK, s->wr_watermark);
  1929. I915_WRITE(GEN7_GFX_PRIO_CTRL, s->gfx_prio_ctrl);
  1930. I915_WRITE(ARB_MODE, s->arb_mode | (0xffff << 16));
  1931. I915_WRITE(GEN7_GFX_PEND_TLB0, s->gfx_pend_tlb0);
  1932. I915_WRITE(GEN7_GFX_PEND_TLB1, s->gfx_pend_tlb1);
  1933. for (i = 0; i < ARRAY_SIZE(s->lra_limits); i++)
  1934. I915_WRITE(GEN7_LRA_LIMITS(i), s->lra_limits[i]);
  1935. I915_WRITE(GEN7_MEDIA_MAX_REQ_COUNT, s->media_max_req_count);
  1936. I915_WRITE(GEN7_GFX_MAX_REQ_COUNT, s->gfx_max_req_count);
  1937. I915_WRITE(RENDER_HWS_PGA_GEN7, s->render_hwsp);
  1938. I915_WRITE(GAM_ECOCHK, s->ecochk);
  1939. I915_WRITE(BSD_HWS_PGA_GEN7, s->bsd_hwsp);
  1940. I915_WRITE(BLT_HWS_PGA_GEN7, s->blt_hwsp);
  1941. I915_WRITE(GEN7_TLB_RD_ADDR, s->tlb_rd_addr);
  1942. /* MBC 0x9024-0x91D0, 0x8500 */
  1943. I915_WRITE(VLV_G3DCTL, s->g3dctl);
  1944. I915_WRITE(VLV_GSCKGCTL, s->gsckgctl);
  1945. I915_WRITE(GEN6_MBCTL, s->mbctl);
  1946. /* GCP 0x9400-0x9424, 0x8100-0x810C */
  1947. I915_WRITE(GEN6_UCGCTL1, s->ucgctl1);
  1948. I915_WRITE(GEN6_UCGCTL3, s->ucgctl3);
  1949. I915_WRITE(GEN6_RCGCTL1, s->rcgctl1);
  1950. I915_WRITE(GEN6_RCGCTL2, s->rcgctl2);
  1951. I915_WRITE(GEN6_RSTCTL, s->rstctl);
  1952. I915_WRITE(GEN7_MISCCPCTL, s->misccpctl);
  1953. /* GPM 0xA000-0xAA84, 0x8000-0x80FC */
  1954. I915_WRITE(GEN6_GFXPAUSE, s->gfxpause);
  1955. I915_WRITE(GEN6_RPDEUHWTC, s->rpdeuhwtc);
  1956. I915_WRITE(GEN6_RPDEUC, s->rpdeuc);
  1957. I915_WRITE(ECOBUS, s->ecobus);
  1958. I915_WRITE(VLV_PWRDWNUPCTL, s->pwrdwnupctl);
  1959. I915_WRITE(GEN6_RP_DOWN_TIMEOUT,s->rp_down_timeout);
  1960. I915_WRITE(GEN6_RPDEUCSW, s->rp_deucsw);
  1961. I915_WRITE(GEN6_RCUBMABDTMR, s->rcubmabdtmr);
  1962. I915_WRITE(VLV_RCEDATA, s->rcedata);
  1963. I915_WRITE(VLV_SPAREG2H, s->spare2gh);
  1964. /* Display CZ domain, 0x4400C-0x4402C, 0x4F000-0x4F11F */
  1965. I915_WRITE(GTIMR, s->gt_imr);
  1966. I915_WRITE(GTIER, s->gt_ier);
  1967. I915_WRITE(GEN6_PMIMR, s->pm_imr);
  1968. I915_WRITE(GEN6_PMIER, s->pm_ier);
  1969. for (i = 0; i < ARRAY_SIZE(s->gt_scratch); i++)
  1970. I915_WRITE(GEN7_GT_SCRATCH(i), s->gt_scratch[i]);
  1971. /* GT SA CZ domain, 0x100000-0x138124 */
  1972. I915_WRITE(TILECTL, s->tilectl);
  1973. I915_WRITE(GTFIFOCTL, s->gt_fifoctl);
  1974. /*
  1975. * Preserve the GT allow wake and GFX force clock bit, they are not
  1976. * be restored, as they are used to control the s0ix suspend/resume
  1977. * sequence by the caller.
  1978. */
  1979. val = I915_READ(VLV_GTLC_WAKE_CTRL);
  1980. val &= VLV_GTLC_ALLOWWAKEREQ;
  1981. val |= s->gtlc_wake_ctrl & ~VLV_GTLC_ALLOWWAKEREQ;
  1982. I915_WRITE(VLV_GTLC_WAKE_CTRL, val);
  1983. val = I915_READ(VLV_GTLC_SURVIVABILITY_REG);
  1984. val &= VLV_GFX_CLK_FORCE_ON_BIT;
  1985. val |= s->gtlc_survive & ~VLV_GFX_CLK_FORCE_ON_BIT;
  1986. I915_WRITE(VLV_GTLC_SURVIVABILITY_REG, val);
  1987. I915_WRITE(VLV_PMWGICZ, s->pmwgicz);
  1988. /* Gunit-Display CZ domain, 0x182028-0x1821CF */
  1989. I915_WRITE(VLV_GU_CTL0, s->gu_ctl0);
  1990. I915_WRITE(VLV_GU_CTL1, s->gu_ctl1);
  1991. I915_WRITE(VLV_PCBR, s->pcbr);
  1992. I915_WRITE(VLV_GUNIT_CLOCK_GATE2, s->clock_gate_dis2);
  1993. }
  1994. static int vlv_wait_for_pw_status(struct drm_i915_private *dev_priv,
  1995. u32 mask, u32 val)
  1996. {
  1997. /* The HW does not like us polling for PW_STATUS frequently, so
  1998. * use the sleeping loop rather than risk the busy spin within
  1999. * intel_wait_for_register().
  2000. *
  2001. * Transitioning between RC6 states should be at most 2ms (see
  2002. * valleyview_enable_rps) so use a 3ms timeout.
  2003. */
  2004. return wait_for((I915_READ_NOTRACE(VLV_GTLC_PW_STATUS) & mask) == val,
  2005. 3);
  2006. }
  2007. int vlv_force_gfx_clock(struct drm_i915_private *dev_priv, bool force_on)
  2008. {
  2009. u32 val;
  2010. int err;
  2011. val = I915_READ(VLV_GTLC_SURVIVABILITY_REG);
  2012. val &= ~VLV_GFX_CLK_FORCE_ON_BIT;
  2013. if (force_on)
  2014. val |= VLV_GFX_CLK_FORCE_ON_BIT;
  2015. I915_WRITE(VLV_GTLC_SURVIVABILITY_REG, val);
  2016. if (!force_on)
  2017. return 0;
  2018. err = intel_wait_for_register(dev_priv,
  2019. VLV_GTLC_SURVIVABILITY_REG,
  2020. VLV_GFX_CLK_STATUS_BIT,
  2021. VLV_GFX_CLK_STATUS_BIT,
  2022. 20);
  2023. if (err)
  2024. DRM_ERROR("timeout waiting for GFX clock force-on (%08x)\n",
  2025. I915_READ(VLV_GTLC_SURVIVABILITY_REG));
  2026. return err;
  2027. }
  2028. static int vlv_allow_gt_wake(struct drm_i915_private *dev_priv, bool allow)
  2029. {
  2030. u32 mask;
  2031. u32 val;
  2032. int err;
  2033. val = I915_READ(VLV_GTLC_WAKE_CTRL);
  2034. val &= ~VLV_GTLC_ALLOWWAKEREQ;
  2035. if (allow)
  2036. val |= VLV_GTLC_ALLOWWAKEREQ;
  2037. I915_WRITE(VLV_GTLC_WAKE_CTRL, val);
  2038. POSTING_READ(VLV_GTLC_WAKE_CTRL);
  2039. mask = VLV_GTLC_ALLOWWAKEACK;
  2040. val = allow ? mask : 0;
  2041. err = vlv_wait_for_pw_status(dev_priv, mask, val);
  2042. if (err)
  2043. DRM_ERROR("timeout disabling GT waking\n");
  2044. return err;
  2045. }
  2046. static void vlv_wait_for_gt_wells(struct drm_i915_private *dev_priv,
  2047. bool wait_for_on)
  2048. {
  2049. u32 mask;
  2050. u32 val;
  2051. mask = VLV_GTLC_PW_MEDIA_STATUS_MASK | VLV_GTLC_PW_RENDER_STATUS_MASK;
  2052. val = wait_for_on ? mask : 0;
  2053. /*
  2054. * RC6 transitioning can be delayed up to 2 msec (see
  2055. * valleyview_enable_rps), use 3 msec for safety.
  2056. *
  2057. * This can fail to turn off the rc6 if the GPU is stuck after a failed
  2058. * reset and we are trying to force the machine to sleep.
  2059. */
  2060. if (vlv_wait_for_pw_status(dev_priv, mask, val))
  2061. DRM_DEBUG_DRIVER("timeout waiting for GT wells to go %s\n",
  2062. onoff(wait_for_on));
  2063. }
  2064. static void vlv_check_no_gt_access(struct drm_i915_private *dev_priv)
  2065. {
  2066. if (!(I915_READ(VLV_GTLC_PW_STATUS) & VLV_GTLC_ALLOWWAKEERR))
  2067. return;
  2068. DRM_DEBUG_DRIVER("GT register access while GT waking disabled\n");
  2069. I915_WRITE(VLV_GTLC_PW_STATUS, VLV_GTLC_ALLOWWAKEERR);
  2070. }
  2071. static int vlv_suspend_complete(struct drm_i915_private *dev_priv)
  2072. {
  2073. u32 mask;
  2074. int err;
  2075. /*
  2076. * Bspec defines the following GT well on flags as debug only, so
  2077. * don't treat them as hard failures.
  2078. */
  2079. vlv_wait_for_gt_wells(dev_priv, false);
  2080. mask = VLV_GTLC_RENDER_CTX_EXISTS | VLV_GTLC_MEDIA_CTX_EXISTS;
  2081. WARN_ON((I915_READ(VLV_GTLC_WAKE_CTRL) & mask) != mask);
  2082. vlv_check_no_gt_access(dev_priv);
  2083. err = vlv_force_gfx_clock(dev_priv, true);
  2084. if (err)
  2085. goto err1;
  2086. err = vlv_allow_gt_wake(dev_priv, false);
  2087. if (err)
  2088. goto err2;
  2089. if (!IS_CHERRYVIEW(dev_priv))
  2090. vlv_save_gunit_s0ix_state(dev_priv);
  2091. err = vlv_force_gfx_clock(dev_priv, false);
  2092. if (err)
  2093. goto err2;
  2094. return 0;
  2095. err2:
  2096. /* For safety always re-enable waking and disable gfx clock forcing */
  2097. vlv_allow_gt_wake(dev_priv, true);
  2098. err1:
  2099. vlv_force_gfx_clock(dev_priv, false);
  2100. return err;
  2101. }
  2102. static int vlv_resume_prepare(struct drm_i915_private *dev_priv,
  2103. bool rpm_resume)
  2104. {
  2105. int err;
  2106. int ret;
  2107. /*
  2108. * If any of the steps fail just try to continue, that's the best we
  2109. * can do at this point. Return the first error code (which will also
  2110. * leave RPM permanently disabled).
  2111. */
  2112. ret = vlv_force_gfx_clock(dev_priv, true);
  2113. if (!IS_CHERRYVIEW(dev_priv))
  2114. vlv_restore_gunit_s0ix_state(dev_priv);
  2115. err = vlv_allow_gt_wake(dev_priv, true);
  2116. if (!ret)
  2117. ret = err;
  2118. err = vlv_force_gfx_clock(dev_priv, false);
  2119. if (!ret)
  2120. ret = err;
  2121. vlv_check_no_gt_access(dev_priv);
  2122. if (rpm_resume)
  2123. intel_init_clock_gating(dev_priv);
  2124. return ret;
  2125. }
  2126. static int intel_runtime_suspend(struct device *kdev)
  2127. {
  2128. struct pci_dev *pdev = to_pci_dev(kdev);
  2129. struct drm_device *dev = pci_get_drvdata(pdev);
  2130. struct drm_i915_private *dev_priv = to_i915(dev);
  2131. int ret;
  2132. if (WARN_ON_ONCE(!(dev_priv->gt_pm.rc6.enabled && HAS_RC6(dev_priv))))
  2133. return -ENODEV;
  2134. if (WARN_ON_ONCE(!HAS_RUNTIME_PM(dev_priv)))
  2135. return -ENODEV;
  2136. DRM_DEBUG_KMS("Suspending device\n");
  2137. disable_rpm_wakeref_asserts(dev_priv);
  2138. /*
  2139. * We are safe here against re-faults, since the fault handler takes
  2140. * an RPM reference.
  2141. */
  2142. i915_gem_runtime_suspend(dev_priv);
  2143. intel_uc_suspend(dev_priv);
  2144. intel_runtime_pm_disable_interrupts(dev_priv);
  2145. intel_uncore_suspend(dev_priv);
  2146. ret = 0;
  2147. if (IS_GEN9_LP(dev_priv)) {
  2148. bxt_display_core_uninit(dev_priv);
  2149. bxt_enable_dc9(dev_priv);
  2150. } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
  2151. hsw_enable_pc8(dev_priv);
  2152. } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
  2153. ret = vlv_suspend_complete(dev_priv);
  2154. }
  2155. if (ret) {
  2156. DRM_ERROR("Runtime suspend failed, disabling it (%d)\n", ret);
  2157. intel_uncore_runtime_resume(dev_priv);
  2158. intel_runtime_pm_enable_interrupts(dev_priv);
  2159. intel_uc_resume(dev_priv);
  2160. i915_gem_init_swizzling(dev_priv);
  2161. i915_gem_restore_fences(dev_priv);
  2162. enable_rpm_wakeref_asserts(dev_priv);
  2163. return ret;
  2164. }
  2165. enable_rpm_wakeref_asserts(dev_priv);
  2166. WARN_ON_ONCE(atomic_read(&dev_priv->runtime_pm.wakeref_count));
  2167. if (intel_uncore_arm_unclaimed_mmio_detection(dev_priv))
  2168. DRM_ERROR("Unclaimed access detected prior to suspending\n");
  2169. dev_priv->runtime_pm.suspended = true;
  2170. /*
  2171. * FIXME: We really should find a document that references the arguments
  2172. * used below!
  2173. */
  2174. if (IS_BROADWELL(dev_priv)) {
  2175. /*
  2176. * On Broadwell, if we use PCI_D1 the PCH DDI ports will stop
  2177. * being detected, and the call we do at intel_runtime_resume()
  2178. * won't be able to restore them. Since PCI_D3hot matches the
  2179. * actual specification and appears to be working, use it.
  2180. */
  2181. intel_opregion_notify_adapter(dev_priv, PCI_D3hot);
  2182. } else {
  2183. /*
  2184. * current versions of firmware which depend on this opregion
  2185. * notification have repurposed the D1 definition to mean
  2186. * "runtime suspended" vs. what you would normally expect (D3)
  2187. * to distinguish it from notifications that might be sent via
  2188. * the suspend path.
  2189. */
  2190. intel_opregion_notify_adapter(dev_priv, PCI_D1);
  2191. }
  2192. assert_forcewakes_inactive(dev_priv);
  2193. if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv))
  2194. intel_hpd_poll_init(dev_priv);
  2195. DRM_DEBUG_KMS("Device suspended\n");
  2196. return 0;
  2197. }
  2198. static int intel_runtime_resume(struct device *kdev)
  2199. {
  2200. struct pci_dev *pdev = to_pci_dev(kdev);
  2201. struct drm_device *dev = pci_get_drvdata(pdev);
  2202. struct drm_i915_private *dev_priv = to_i915(dev);
  2203. int ret = 0;
  2204. if (WARN_ON_ONCE(!HAS_RUNTIME_PM(dev_priv)))
  2205. return -ENODEV;
  2206. DRM_DEBUG_KMS("Resuming device\n");
  2207. WARN_ON_ONCE(atomic_read(&dev_priv->runtime_pm.wakeref_count));
  2208. disable_rpm_wakeref_asserts(dev_priv);
  2209. intel_opregion_notify_adapter(dev_priv, PCI_D0);
  2210. dev_priv->runtime_pm.suspended = false;
  2211. if (intel_uncore_unclaimed_mmio(dev_priv))
  2212. DRM_DEBUG_DRIVER("Unclaimed access during suspend, bios?\n");
  2213. if (IS_GEN9_LP(dev_priv)) {
  2214. bxt_disable_dc9(dev_priv);
  2215. bxt_display_core_init(dev_priv, true);
  2216. if (dev_priv->csr.dmc_payload &&
  2217. (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC5))
  2218. gen9_enable_dc5(dev_priv);
  2219. } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
  2220. hsw_disable_pc8(dev_priv);
  2221. } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
  2222. ret = vlv_resume_prepare(dev_priv, true);
  2223. }
  2224. intel_uncore_runtime_resume(dev_priv);
  2225. intel_runtime_pm_enable_interrupts(dev_priv);
  2226. intel_uc_resume(dev_priv);
  2227. /*
  2228. * No point of rolling back things in case of an error, as the best
  2229. * we can do is to hope that things will still work (and disable RPM).
  2230. */
  2231. i915_gem_init_swizzling(dev_priv);
  2232. i915_gem_restore_fences(dev_priv);
  2233. /*
  2234. * On VLV/CHV display interrupts are part of the display
  2235. * power well, so hpd is reinitialized from there. For
  2236. * everyone else do it here.
  2237. */
  2238. if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv))
  2239. intel_hpd_init(dev_priv);
  2240. intel_enable_ipc(dev_priv);
  2241. enable_rpm_wakeref_asserts(dev_priv);
  2242. if (ret)
  2243. DRM_ERROR("Runtime resume failed, disabling it (%d)\n", ret);
  2244. else
  2245. DRM_DEBUG_KMS("Device resumed\n");
  2246. return ret;
  2247. }
  2248. const struct dev_pm_ops i915_pm_ops = {
  2249. /*
  2250. * S0ix (via system suspend) and S3 event handlers [PMSG_SUSPEND,
  2251. * PMSG_RESUME]
  2252. */
  2253. .suspend = i915_pm_suspend,
  2254. .suspend_late = i915_pm_suspend_late,
  2255. .resume_early = i915_pm_resume_early,
  2256. .resume = i915_pm_resume,
  2257. /*
  2258. * S4 event handlers
  2259. * @freeze, @freeze_late : called (1) before creating the
  2260. * hibernation image [PMSG_FREEZE] and
  2261. * (2) after rebooting, before restoring
  2262. * the image [PMSG_QUIESCE]
  2263. * @thaw, @thaw_early : called (1) after creating the hibernation
  2264. * image, before writing it [PMSG_THAW]
  2265. * and (2) after failing to create or
  2266. * restore the image [PMSG_RECOVER]
  2267. * @poweroff, @poweroff_late: called after writing the hibernation
  2268. * image, before rebooting [PMSG_HIBERNATE]
  2269. * @restore, @restore_early : called after rebooting and restoring the
  2270. * hibernation image [PMSG_RESTORE]
  2271. */
  2272. .freeze = i915_pm_freeze,
  2273. .freeze_late = i915_pm_freeze_late,
  2274. .thaw_early = i915_pm_thaw_early,
  2275. .thaw = i915_pm_thaw,
  2276. .poweroff = i915_pm_suspend,
  2277. .poweroff_late = i915_pm_poweroff_late,
  2278. .restore_early = i915_pm_restore_early,
  2279. .restore = i915_pm_restore,
  2280. /* S0ix (via runtime suspend) event handlers */
  2281. .runtime_suspend = intel_runtime_suspend,
  2282. .runtime_resume = intel_runtime_resume,
  2283. };
  2284. static const struct vm_operations_struct i915_gem_vm_ops = {
  2285. .fault = i915_gem_fault,
  2286. .open = drm_gem_vm_open,
  2287. .close = drm_gem_vm_close,
  2288. };
  2289. static const struct file_operations i915_driver_fops = {
  2290. .owner = THIS_MODULE,
  2291. .open = drm_open,
  2292. .release = drm_release,
  2293. .unlocked_ioctl = drm_ioctl,
  2294. .mmap = drm_gem_mmap,
  2295. .poll = drm_poll,
  2296. .read = drm_read,
  2297. .compat_ioctl = i915_compat_ioctl,
  2298. .llseek = noop_llseek,
  2299. };
  2300. static int
  2301. i915_gem_reject_pin_ioctl(struct drm_device *dev, void *data,
  2302. struct drm_file *file)
  2303. {
  2304. return -ENODEV;
  2305. }
  2306. static const struct drm_ioctl_desc i915_ioctls[] = {
  2307. DRM_IOCTL_DEF_DRV(I915_INIT, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  2308. DRM_IOCTL_DEF_DRV(I915_FLUSH, drm_noop, DRM_AUTH),
  2309. DRM_IOCTL_DEF_DRV(I915_FLIP, drm_noop, DRM_AUTH),
  2310. DRM_IOCTL_DEF_DRV(I915_BATCHBUFFER, drm_noop, DRM_AUTH),
  2311. DRM_IOCTL_DEF_DRV(I915_IRQ_EMIT, drm_noop, DRM_AUTH),
  2312. DRM_IOCTL_DEF_DRV(I915_IRQ_WAIT, drm_noop, DRM_AUTH),
  2313. DRM_IOCTL_DEF_DRV(I915_GETPARAM, i915_getparam_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
  2314. DRM_IOCTL_DEF_DRV(I915_SETPARAM, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  2315. DRM_IOCTL_DEF_DRV(I915_ALLOC, drm_noop, DRM_AUTH),
  2316. DRM_IOCTL_DEF_DRV(I915_FREE, drm_noop, DRM_AUTH),
  2317. DRM_IOCTL_DEF_DRV(I915_INIT_HEAP, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  2318. DRM_IOCTL_DEF_DRV(I915_CMDBUFFER, drm_noop, DRM_AUTH),
  2319. DRM_IOCTL_DEF_DRV(I915_DESTROY_HEAP, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  2320. DRM_IOCTL_DEF_DRV(I915_SET_VBLANK_PIPE, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  2321. DRM_IOCTL_DEF_DRV(I915_GET_VBLANK_PIPE, drm_noop, DRM_AUTH),
  2322. DRM_IOCTL_DEF_DRV(I915_VBLANK_SWAP, drm_noop, DRM_AUTH),
  2323. DRM_IOCTL_DEF_DRV(I915_HWS_ADDR, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  2324. DRM_IOCTL_DEF_DRV(I915_GEM_INIT, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  2325. DRM_IOCTL_DEF_DRV(I915_GEM_EXECBUFFER, i915_gem_execbuffer_ioctl, DRM_AUTH),
  2326. DRM_IOCTL_DEF_DRV(I915_GEM_EXECBUFFER2_WR, i915_gem_execbuffer2_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
  2327. DRM_IOCTL_DEF_DRV(I915_GEM_PIN, i915_gem_reject_pin_ioctl, DRM_AUTH|DRM_ROOT_ONLY),
  2328. DRM_IOCTL_DEF_DRV(I915_GEM_UNPIN, i915_gem_reject_pin_ioctl, DRM_AUTH|DRM_ROOT_ONLY),
  2329. DRM_IOCTL_DEF_DRV(I915_GEM_BUSY, i915_gem_busy_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
  2330. DRM_IOCTL_DEF_DRV(I915_GEM_SET_CACHING, i915_gem_set_caching_ioctl, DRM_RENDER_ALLOW),
  2331. DRM_IOCTL_DEF_DRV(I915_GEM_GET_CACHING, i915_gem_get_caching_ioctl, DRM_RENDER_ALLOW),
  2332. DRM_IOCTL_DEF_DRV(I915_GEM_THROTTLE, i915_gem_throttle_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
  2333. DRM_IOCTL_DEF_DRV(I915_GEM_ENTERVT, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  2334. DRM_IOCTL_DEF_DRV(I915_GEM_LEAVEVT, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  2335. DRM_IOCTL_DEF_DRV(I915_GEM_CREATE, i915_gem_create_ioctl, DRM_RENDER_ALLOW),
  2336. DRM_IOCTL_DEF_DRV(I915_GEM_PREAD, i915_gem_pread_ioctl, DRM_RENDER_ALLOW),
  2337. DRM_IOCTL_DEF_DRV(I915_GEM_PWRITE, i915_gem_pwrite_ioctl, DRM_RENDER_ALLOW),
  2338. DRM_IOCTL_DEF_DRV(I915_GEM_MMAP, i915_gem_mmap_ioctl, DRM_RENDER_ALLOW),
  2339. DRM_IOCTL_DEF_DRV(I915_GEM_MMAP_GTT, i915_gem_mmap_gtt_ioctl, DRM_RENDER_ALLOW),
  2340. DRM_IOCTL_DEF_DRV(I915_GEM_SET_DOMAIN, i915_gem_set_domain_ioctl, DRM_RENDER_ALLOW),
  2341. DRM_IOCTL_DEF_DRV(I915_GEM_SW_FINISH, i915_gem_sw_finish_ioctl, DRM_RENDER_ALLOW),
  2342. DRM_IOCTL_DEF_DRV(I915_GEM_SET_TILING, i915_gem_set_tiling_ioctl, DRM_RENDER_ALLOW),
  2343. DRM_IOCTL_DEF_DRV(I915_GEM_GET_TILING, i915_gem_get_tiling_ioctl, DRM_RENDER_ALLOW),
  2344. DRM_IOCTL_DEF_DRV(I915_GEM_GET_APERTURE, i915_gem_get_aperture_ioctl, DRM_RENDER_ALLOW),
  2345. DRM_IOCTL_DEF_DRV(I915_GET_PIPE_FROM_CRTC_ID, intel_get_pipe_from_crtc_id_ioctl, 0),
  2346. DRM_IOCTL_DEF_DRV(I915_GEM_MADVISE, i915_gem_madvise_ioctl, DRM_RENDER_ALLOW),
  2347. DRM_IOCTL_DEF_DRV(I915_OVERLAY_PUT_IMAGE, intel_overlay_put_image_ioctl, DRM_MASTER),
  2348. DRM_IOCTL_DEF_DRV(I915_OVERLAY_ATTRS, intel_overlay_attrs_ioctl, DRM_MASTER),
  2349. DRM_IOCTL_DEF_DRV(I915_SET_SPRITE_COLORKEY, intel_sprite_set_colorkey_ioctl, DRM_MASTER),
  2350. DRM_IOCTL_DEF_DRV(I915_GET_SPRITE_COLORKEY, drm_noop, DRM_MASTER),
  2351. DRM_IOCTL_DEF_DRV(I915_GEM_WAIT, i915_gem_wait_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
  2352. DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_CREATE, i915_gem_context_create_ioctl, DRM_RENDER_ALLOW),
  2353. DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_DESTROY, i915_gem_context_destroy_ioctl, DRM_RENDER_ALLOW),
  2354. DRM_IOCTL_DEF_DRV(I915_REG_READ, i915_reg_read_ioctl, DRM_RENDER_ALLOW),
  2355. DRM_IOCTL_DEF_DRV(I915_GET_RESET_STATS, i915_gem_context_reset_stats_ioctl, DRM_RENDER_ALLOW),
  2356. DRM_IOCTL_DEF_DRV(I915_GEM_USERPTR, i915_gem_userptr_ioctl, DRM_RENDER_ALLOW),
  2357. DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_GETPARAM, i915_gem_context_getparam_ioctl, DRM_RENDER_ALLOW),
  2358. DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_SETPARAM, i915_gem_context_setparam_ioctl, DRM_RENDER_ALLOW),
  2359. DRM_IOCTL_DEF_DRV(I915_PERF_OPEN, i915_perf_open_ioctl, DRM_RENDER_ALLOW),
  2360. DRM_IOCTL_DEF_DRV(I915_PERF_ADD_CONFIG, i915_perf_add_config_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
  2361. DRM_IOCTL_DEF_DRV(I915_PERF_REMOVE_CONFIG, i915_perf_remove_config_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
  2362. DRM_IOCTL_DEF_DRV(I915_QUERY, i915_query_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
  2363. };
  2364. static struct drm_driver driver = {
  2365. /* Don't use MTRRs here; the Xserver or userspace app should
  2366. * deal with them for Intel hardware.
  2367. */
  2368. .driver_features =
  2369. DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_GEM | DRIVER_PRIME |
  2370. DRIVER_RENDER | DRIVER_MODESET | DRIVER_ATOMIC | DRIVER_SYNCOBJ,
  2371. .release = i915_driver_release,
  2372. .open = i915_driver_open,
  2373. .lastclose = i915_driver_lastclose,
  2374. .postclose = i915_driver_postclose,
  2375. .gem_close_object = i915_gem_close_object,
  2376. .gem_free_object_unlocked = i915_gem_free_object,
  2377. .gem_vm_ops = &i915_gem_vm_ops,
  2378. .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
  2379. .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
  2380. .gem_prime_export = i915_gem_prime_export,
  2381. .gem_prime_import = i915_gem_prime_import,
  2382. .dumb_create = i915_gem_dumb_create,
  2383. .dumb_map_offset = i915_gem_mmap_gtt,
  2384. .ioctls = i915_ioctls,
  2385. .num_ioctls = ARRAY_SIZE(i915_ioctls),
  2386. .fops = &i915_driver_fops,
  2387. .name = DRIVER_NAME,
  2388. .desc = DRIVER_DESC,
  2389. .date = DRIVER_DATE,
  2390. .major = DRIVER_MAJOR,
  2391. .minor = DRIVER_MINOR,
  2392. .patchlevel = DRIVER_PATCHLEVEL,
  2393. };
  2394. #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
  2395. #include "selftests/mock_drm.c"
  2396. #endif