i915_drv.c 90 KB

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