i915_drv.c 81 KB

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