i915_drv.c 81 KB

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