i915_drv.c 78 KB

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