i915_drv.c 82 KB

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