i915_drv.c 78 KB

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