i915_debugfs.c 132 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855
  1. /*
  2. * Copyright © 2008 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. * IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Eric Anholt <eric@anholt.net>
  25. * Keith Packard <keithp@keithp.com>
  26. *
  27. */
  28. #include <linux/debugfs.h>
  29. #include <linux/sort.h>
  30. #include <linux/sched/mm.h>
  31. #include "intel_drv.h"
  32. #include "intel_guc_submission.h"
  33. static inline struct drm_i915_private *node_to_i915(struct drm_info_node *node)
  34. {
  35. return to_i915(node->minor->dev);
  36. }
  37. static int i915_capabilities(struct seq_file *m, void *data)
  38. {
  39. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  40. const struct intel_device_info *info = INTEL_INFO(dev_priv);
  41. struct drm_printer p = drm_seq_file_printer(m);
  42. seq_printf(m, "gen: %d\n", INTEL_GEN(dev_priv));
  43. seq_printf(m, "platform: %s\n", intel_platform_name(info->platform));
  44. seq_printf(m, "pch: %d\n", INTEL_PCH_TYPE(dev_priv));
  45. intel_device_info_dump_flags(info, &p);
  46. intel_device_info_dump_runtime(info, &p);
  47. kernel_param_lock(THIS_MODULE);
  48. i915_params_dump(&i915_modparams, &p);
  49. kernel_param_unlock(THIS_MODULE);
  50. return 0;
  51. }
  52. static char get_active_flag(struct drm_i915_gem_object *obj)
  53. {
  54. return i915_gem_object_is_active(obj) ? '*' : ' ';
  55. }
  56. static char get_pin_flag(struct drm_i915_gem_object *obj)
  57. {
  58. return obj->pin_global ? 'p' : ' ';
  59. }
  60. static char get_tiling_flag(struct drm_i915_gem_object *obj)
  61. {
  62. switch (i915_gem_object_get_tiling(obj)) {
  63. default:
  64. case I915_TILING_NONE: return ' ';
  65. case I915_TILING_X: return 'X';
  66. case I915_TILING_Y: return 'Y';
  67. }
  68. }
  69. static char get_global_flag(struct drm_i915_gem_object *obj)
  70. {
  71. return obj->userfault_count ? 'g' : ' ';
  72. }
  73. static char get_pin_mapped_flag(struct drm_i915_gem_object *obj)
  74. {
  75. return obj->mm.mapping ? 'M' : ' ';
  76. }
  77. static u64 i915_gem_obj_total_ggtt_size(struct drm_i915_gem_object *obj)
  78. {
  79. u64 size = 0;
  80. struct i915_vma *vma;
  81. for_each_ggtt_vma(vma, obj) {
  82. if (drm_mm_node_allocated(&vma->node))
  83. size += vma->node.size;
  84. }
  85. return size;
  86. }
  87. static const char *
  88. stringify_page_sizes(unsigned int page_sizes, char *buf, size_t len)
  89. {
  90. size_t x = 0;
  91. switch (page_sizes) {
  92. case 0:
  93. return "";
  94. case I915_GTT_PAGE_SIZE_4K:
  95. return "4K";
  96. case I915_GTT_PAGE_SIZE_64K:
  97. return "64K";
  98. case I915_GTT_PAGE_SIZE_2M:
  99. return "2M";
  100. default:
  101. if (!buf)
  102. return "M";
  103. if (page_sizes & I915_GTT_PAGE_SIZE_2M)
  104. x += snprintf(buf + x, len - x, "2M, ");
  105. if (page_sizes & I915_GTT_PAGE_SIZE_64K)
  106. x += snprintf(buf + x, len - x, "64K, ");
  107. if (page_sizes & I915_GTT_PAGE_SIZE_4K)
  108. x += snprintf(buf + x, len - x, "4K, ");
  109. buf[x-2] = '\0';
  110. return buf;
  111. }
  112. }
  113. static void
  114. describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
  115. {
  116. struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
  117. struct intel_engine_cs *engine;
  118. struct i915_vma *vma;
  119. unsigned int frontbuffer_bits;
  120. int pin_count = 0;
  121. lockdep_assert_held(&obj->base.dev->struct_mutex);
  122. seq_printf(m, "%pK: %c%c%c%c%c %8zdKiB %02x %02x %s%s%s",
  123. &obj->base,
  124. get_active_flag(obj),
  125. get_pin_flag(obj),
  126. get_tiling_flag(obj),
  127. get_global_flag(obj),
  128. get_pin_mapped_flag(obj),
  129. obj->base.size / 1024,
  130. obj->base.read_domains,
  131. obj->base.write_domain,
  132. i915_cache_level_str(dev_priv, obj->cache_level),
  133. obj->mm.dirty ? " dirty" : "",
  134. obj->mm.madv == I915_MADV_DONTNEED ? " purgeable" : "");
  135. if (obj->base.name)
  136. seq_printf(m, " (name: %d)", obj->base.name);
  137. list_for_each_entry(vma, &obj->vma_list, obj_link) {
  138. if (i915_vma_is_pinned(vma))
  139. pin_count++;
  140. }
  141. seq_printf(m, " (pinned x %d)", pin_count);
  142. if (obj->pin_global)
  143. seq_printf(m, " (global)");
  144. list_for_each_entry(vma, &obj->vma_list, obj_link) {
  145. if (!drm_mm_node_allocated(&vma->node))
  146. continue;
  147. seq_printf(m, " (%sgtt offset: %08llx, size: %08llx, pages: %s",
  148. i915_vma_is_ggtt(vma) ? "g" : "pp",
  149. vma->node.start, vma->node.size,
  150. stringify_page_sizes(vma->page_sizes.gtt, NULL, 0));
  151. if (i915_vma_is_ggtt(vma)) {
  152. switch (vma->ggtt_view.type) {
  153. case I915_GGTT_VIEW_NORMAL:
  154. seq_puts(m, ", normal");
  155. break;
  156. case I915_GGTT_VIEW_PARTIAL:
  157. seq_printf(m, ", partial [%08llx+%x]",
  158. vma->ggtt_view.partial.offset << PAGE_SHIFT,
  159. vma->ggtt_view.partial.size << PAGE_SHIFT);
  160. break;
  161. case I915_GGTT_VIEW_ROTATED:
  162. seq_printf(m, ", rotated [(%ux%u, stride=%u, offset=%u), (%ux%u, stride=%u, offset=%u)]",
  163. vma->ggtt_view.rotated.plane[0].width,
  164. vma->ggtt_view.rotated.plane[0].height,
  165. vma->ggtt_view.rotated.plane[0].stride,
  166. vma->ggtt_view.rotated.plane[0].offset,
  167. vma->ggtt_view.rotated.plane[1].width,
  168. vma->ggtt_view.rotated.plane[1].height,
  169. vma->ggtt_view.rotated.plane[1].stride,
  170. vma->ggtt_view.rotated.plane[1].offset);
  171. break;
  172. default:
  173. MISSING_CASE(vma->ggtt_view.type);
  174. break;
  175. }
  176. }
  177. if (vma->fence)
  178. seq_printf(m, " , fence: %d%s",
  179. vma->fence->id,
  180. i915_gem_active_isset(&vma->last_fence) ? "*" : "");
  181. seq_puts(m, ")");
  182. }
  183. if (obj->stolen)
  184. seq_printf(m, " (stolen: %08llx)", obj->stolen->start);
  185. engine = i915_gem_object_last_write_engine(obj);
  186. if (engine)
  187. seq_printf(m, " (%s)", engine->name);
  188. frontbuffer_bits = atomic_read(&obj->frontbuffer_bits);
  189. if (frontbuffer_bits)
  190. seq_printf(m, " (frontbuffer: 0x%03x)", frontbuffer_bits);
  191. }
  192. static int obj_rank_by_stolen(const void *A, const void *B)
  193. {
  194. const struct drm_i915_gem_object *a =
  195. *(const struct drm_i915_gem_object **)A;
  196. const struct drm_i915_gem_object *b =
  197. *(const struct drm_i915_gem_object **)B;
  198. if (a->stolen->start < b->stolen->start)
  199. return -1;
  200. if (a->stolen->start > b->stolen->start)
  201. return 1;
  202. return 0;
  203. }
  204. static int i915_gem_stolen_list_info(struct seq_file *m, void *data)
  205. {
  206. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  207. struct drm_device *dev = &dev_priv->drm;
  208. struct drm_i915_gem_object **objects;
  209. struct drm_i915_gem_object *obj;
  210. u64 total_obj_size, total_gtt_size;
  211. unsigned long total, count, n;
  212. int ret;
  213. total = READ_ONCE(dev_priv->mm.object_count);
  214. objects = kvmalloc_array(total, sizeof(*objects), GFP_KERNEL);
  215. if (!objects)
  216. return -ENOMEM;
  217. ret = mutex_lock_interruptible(&dev->struct_mutex);
  218. if (ret)
  219. goto out;
  220. total_obj_size = total_gtt_size = count = 0;
  221. spin_lock(&dev_priv->mm.obj_lock);
  222. list_for_each_entry(obj, &dev_priv->mm.bound_list, mm.link) {
  223. if (count == total)
  224. break;
  225. if (obj->stolen == NULL)
  226. continue;
  227. objects[count++] = obj;
  228. total_obj_size += obj->base.size;
  229. total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
  230. }
  231. list_for_each_entry(obj, &dev_priv->mm.unbound_list, mm.link) {
  232. if (count == total)
  233. break;
  234. if (obj->stolen == NULL)
  235. continue;
  236. objects[count++] = obj;
  237. total_obj_size += obj->base.size;
  238. }
  239. spin_unlock(&dev_priv->mm.obj_lock);
  240. sort(objects, count, sizeof(*objects), obj_rank_by_stolen, NULL);
  241. seq_puts(m, "Stolen:\n");
  242. for (n = 0; n < count; n++) {
  243. seq_puts(m, " ");
  244. describe_obj(m, objects[n]);
  245. seq_putc(m, '\n');
  246. }
  247. seq_printf(m, "Total %lu objects, %llu bytes, %llu GTT size\n",
  248. count, total_obj_size, total_gtt_size);
  249. mutex_unlock(&dev->struct_mutex);
  250. out:
  251. kvfree(objects);
  252. return ret;
  253. }
  254. struct file_stats {
  255. struct drm_i915_file_private *file_priv;
  256. unsigned long count;
  257. u64 total, unbound;
  258. u64 global, shared;
  259. u64 active, inactive;
  260. };
  261. static int per_file_stats(int id, void *ptr, void *data)
  262. {
  263. struct drm_i915_gem_object *obj = ptr;
  264. struct file_stats *stats = data;
  265. struct i915_vma *vma;
  266. lockdep_assert_held(&obj->base.dev->struct_mutex);
  267. stats->count++;
  268. stats->total += obj->base.size;
  269. if (!obj->bind_count)
  270. stats->unbound += obj->base.size;
  271. if (obj->base.name || obj->base.dma_buf)
  272. stats->shared += obj->base.size;
  273. list_for_each_entry(vma, &obj->vma_list, obj_link) {
  274. if (!drm_mm_node_allocated(&vma->node))
  275. continue;
  276. if (i915_vma_is_ggtt(vma)) {
  277. stats->global += vma->node.size;
  278. } else {
  279. struct i915_hw_ppgtt *ppgtt = i915_vm_to_ppgtt(vma->vm);
  280. if (ppgtt->base.file != stats->file_priv)
  281. continue;
  282. }
  283. if (i915_vma_is_active(vma))
  284. stats->active += vma->node.size;
  285. else
  286. stats->inactive += vma->node.size;
  287. }
  288. return 0;
  289. }
  290. #define print_file_stats(m, name, stats) do { \
  291. if (stats.count) \
  292. seq_printf(m, "%s: %lu objects, %llu bytes (%llu active, %llu inactive, %llu global, %llu shared, %llu unbound)\n", \
  293. name, \
  294. stats.count, \
  295. stats.total, \
  296. stats.active, \
  297. stats.inactive, \
  298. stats.global, \
  299. stats.shared, \
  300. stats.unbound); \
  301. } while (0)
  302. static void print_batch_pool_stats(struct seq_file *m,
  303. struct drm_i915_private *dev_priv)
  304. {
  305. struct drm_i915_gem_object *obj;
  306. struct file_stats stats;
  307. struct intel_engine_cs *engine;
  308. enum intel_engine_id id;
  309. int j;
  310. memset(&stats, 0, sizeof(stats));
  311. for_each_engine(engine, dev_priv, id) {
  312. for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
  313. list_for_each_entry(obj,
  314. &engine->batch_pool.cache_list[j],
  315. batch_pool_link)
  316. per_file_stats(0, obj, &stats);
  317. }
  318. }
  319. print_file_stats(m, "[k]batch pool", stats);
  320. }
  321. static int per_file_ctx_stats(int id, void *ptr, void *data)
  322. {
  323. struct i915_gem_context *ctx = ptr;
  324. int n;
  325. for (n = 0; n < ARRAY_SIZE(ctx->engine); n++) {
  326. if (ctx->engine[n].state)
  327. per_file_stats(0, ctx->engine[n].state->obj, data);
  328. if (ctx->engine[n].ring)
  329. per_file_stats(0, ctx->engine[n].ring->vma->obj, data);
  330. }
  331. return 0;
  332. }
  333. static void print_context_stats(struct seq_file *m,
  334. struct drm_i915_private *dev_priv)
  335. {
  336. struct drm_device *dev = &dev_priv->drm;
  337. struct file_stats stats;
  338. struct drm_file *file;
  339. memset(&stats, 0, sizeof(stats));
  340. mutex_lock(&dev->struct_mutex);
  341. if (dev_priv->kernel_context)
  342. per_file_ctx_stats(0, dev_priv->kernel_context, &stats);
  343. list_for_each_entry(file, &dev->filelist, lhead) {
  344. struct drm_i915_file_private *fpriv = file->driver_priv;
  345. idr_for_each(&fpriv->context_idr, per_file_ctx_stats, &stats);
  346. }
  347. mutex_unlock(&dev->struct_mutex);
  348. print_file_stats(m, "[k]contexts", stats);
  349. }
  350. static int i915_gem_object_info(struct seq_file *m, void *data)
  351. {
  352. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  353. struct drm_device *dev = &dev_priv->drm;
  354. struct i915_ggtt *ggtt = &dev_priv->ggtt;
  355. u32 count, mapped_count, purgeable_count, dpy_count, huge_count;
  356. u64 size, mapped_size, purgeable_size, dpy_size, huge_size;
  357. struct drm_i915_gem_object *obj;
  358. unsigned int page_sizes = 0;
  359. struct drm_file *file;
  360. char buf[80];
  361. int ret;
  362. ret = mutex_lock_interruptible(&dev->struct_mutex);
  363. if (ret)
  364. return ret;
  365. seq_printf(m, "%u objects, %llu bytes\n",
  366. dev_priv->mm.object_count,
  367. dev_priv->mm.object_memory);
  368. size = count = 0;
  369. mapped_size = mapped_count = 0;
  370. purgeable_size = purgeable_count = 0;
  371. huge_size = huge_count = 0;
  372. spin_lock(&dev_priv->mm.obj_lock);
  373. list_for_each_entry(obj, &dev_priv->mm.unbound_list, mm.link) {
  374. size += obj->base.size;
  375. ++count;
  376. if (obj->mm.madv == I915_MADV_DONTNEED) {
  377. purgeable_size += obj->base.size;
  378. ++purgeable_count;
  379. }
  380. if (obj->mm.mapping) {
  381. mapped_count++;
  382. mapped_size += obj->base.size;
  383. }
  384. if (obj->mm.page_sizes.sg > I915_GTT_PAGE_SIZE) {
  385. huge_count++;
  386. huge_size += obj->base.size;
  387. page_sizes |= obj->mm.page_sizes.sg;
  388. }
  389. }
  390. seq_printf(m, "%u unbound objects, %llu bytes\n", count, size);
  391. size = count = dpy_size = dpy_count = 0;
  392. list_for_each_entry(obj, &dev_priv->mm.bound_list, mm.link) {
  393. size += obj->base.size;
  394. ++count;
  395. if (obj->pin_global) {
  396. dpy_size += obj->base.size;
  397. ++dpy_count;
  398. }
  399. if (obj->mm.madv == I915_MADV_DONTNEED) {
  400. purgeable_size += obj->base.size;
  401. ++purgeable_count;
  402. }
  403. if (obj->mm.mapping) {
  404. mapped_count++;
  405. mapped_size += obj->base.size;
  406. }
  407. if (obj->mm.page_sizes.sg > I915_GTT_PAGE_SIZE) {
  408. huge_count++;
  409. huge_size += obj->base.size;
  410. page_sizes |= obj->mm.page_sizes.sg;
  411. }
  412. }
  413. spin_unlock(&dev_priv->mm.obj_lock);
  414. seq_printf(m, "%u bound objects, %llu bytes\n",
  415. count, size);
  416. seq_printf(m, "%u purgeable objects, %llu bytes\n",
  417. purgeable_count, purgeable_size);
  418. seq_printf(m, "%u mapped objects, %llu bytes\n",
  419. mapped_count, mapped_size);
  420. seq_printf(m, "%u huge-paged objects (%s) %llu bytes\n",
  421. huge_count,
  422. stringify_page_sizes(page_sizes, buf, sizeof(buf)),
  423. huge_size);
  424. seq_printf(m, "%u display objects (globally pinned), %llu bytes\n",
  425. dpy_count, dpy_size);
  426. seq_printf(m, "%llu [%pa] gtt total\n",
  427. ggtt->base.total, &ggtt->mappable_end);
  428. seq_printf(m, "Supported page sizes: %s\n",
  429. stringify_page_sizes(INTEL_INFO(dev_priv)->page_sizes,
  430. buf, sizeof(buf)));
  431. seq_putc(m, '\n');
  432. print_batch_pool_stats(m, dev_priv);
  433. mutex_unlock(&dev->struct_mutex);
  434. mutex_lock(&dev->filelist_mutex);
  435. print_context_stats(m, dev_priv);
  436. list_for_each_entry_reverse(file, &dev->filelist, lhead) {
  437. struct file_stats stats;
  438. struct drm_i915_file_private *file_priv = file->driver_priv;
  439. struct drm_i915_gem_request *request;
  440. struct task_struct *task;
  441. mutex_lock(&dev->struct_mutex);
  442. memset(&stats, 0, sizeof(stats));
  443. stats.file_priv = file->driver_priv;
  444. spin_lock(&file->table_lock);
  445. idr_for_each(&file->object_idr, per_file_stats, &stats);
  446. spin_unlock(&file->table_lock);
  447. /*
  448. * Although we have a valid reference on file->pid, that does
  449. * not guarantee that the task_struct who called get_pid() is
  450. * still alive (e.g. get_pid(current) => fork() => exit()).
  451. * Therefore, we need to protect this ->comm access using RCU.
  452. */
  453. request = list_first_entry_or_null(&file_priv->mm.request_list,
  454. struct drm_i915_gem_request,
  455. client_link);
  456. rcu_read_lock();
  457. task = pid_task(request && request->ctx->pid ?
  458. request->ctx->pid : file->pid,
  459. PIDTYPE_PID);
  460. print_file_stats(m, task ? task->comm : "<unknown>", stats);
  461. rcu_read_unlock();
  462. mutex_unlock(&dev->struct_mutex);
  463. }
  464. mutex_unlock(&dev->filelist_mutex);
  465. return 0;
  466. }
  467. static int i915_gem_gtt_info(struct seq_file *m, void *data)
  468. {
  469. struct drm_info_node *node = m->private;
  470. struct drm_i915_private *dev_priv = node_to_i915(node);
  471. struct drm_device *dev = &dev_priv->drm;
  472. struct drm_i915_gem_object **objects;
  473. struct drm_i915_gem_object *obj;
  474. u64 total_obj_size, total_gtt_size;
  475. unsigned long nobject, n;
  476. int count, ret;
  477. nobject = READ_ONCE(dev_priv->mm.object_count);
  478. objects = kvmalloc_array(nobject, sizeof(*objects), GFP_KERNEL);
  479. if (!objects)
  480. return -ENOMEM;
  481. ret = mutex_lock_interruptible(&dev->struct_mutex);
  482. if (ret)
  483. return ret;
  484. count = 0;
  485. spin_lock(&dev_priv->mm.obj_lock);
  486. list_for_each_entry(obj, &dev_priv->mm.bound_list, mm.link) {
  487. objects[count++] = obj;
  488. if (count == nobject)
  489. break;
  490. }
  491. spin_unlock(&dev_priv->mm.obj_lock);
  492. total_obj_size = total_gtt_size = 0;
  493. for (n = 0; n < count; n++) {
  494. obj = objects[n];
  495. seq_puts(m, " ");
  496. describe_obj(m, obj);
  497. seq_putc(m, '\n');
  498. total_obj_size += obj->base.size;
  499. total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
  500. }
  501. mutex_unlock(&dev->struct_mutex);
  502. seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
  503. count, total_obj_size, total_gtt_size);
  504. kvfree(objects);
  505. return 0;
  506. }
  507. static int i915_gem_batch_pool_info(struct seq_file *m, void *data)
  508. {
  509. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  510. struct drm_device *dev = &dev_priv->drm;
  511. struct drm_i915_gem_object *obj;
  512. struct intel_engine_cs *engine;
  513. enum intel_engine_id id;
  514. int total = 0;
  515. int ret, j;
  516. ret = mutex_lock_interruptible(&dev->struct_mutex);
  517. if (ret)
  518. return ret;
  519. for_each_engine(engine, dev_priv, id) {
  520. for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
  521. int count;
  522. count = 0;
  523. list_for_each_entry(obj,
  524. &engine->batch_pool.cache_list[j],
  525. batch_pool_link)
  526. count++;
  527. seq_printf(m, "%s cache[%d]: %d objects\n",
  528. engine->name, j, count);
  529. list_for_each_entry(obj,
  530. &engine->batch_pool.cache_list[j],
  531. batch_pool_link) {
  532. seq_puts(m, " ");
  533. describe_obj(m, obj);
  534. seq_putc(m, '\n');
  535. }
  536. total += count;
  537. }
  538. }
  539. seq_printf(m, "total: %d\n", total);
  540. mutex_unlock(&dev->struct_mutex);
  541. return 0;
  542. }
  543. static int i915_interrupt_info(struct seq_file *m, void *data)
  544. {
  545. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  546. struct intel_engine_cs *engine;
  547. enum intel_engine_id id;
  548. int i, pipe;
  549. intel_runtime_pm_get(dev_priv);
  550. if (IS_CHERRYVIEW(dev_priv)) {
  551. seq_printf(m, "Master Interrupt Control:\t%08x\n",
  552. I915_READ(GEN8_MASTER_IRQ));
  553. seq_printf(m, "Display IER:\t%08x\n",
  554. I915_READ(VLV_IER));
  555. seq_printf(m, "Display IIR:\t%08x\n",
  556. I915_READ(VLV_IIR));
  557. seq_printf(m, "Display IIR_RW:\t%08x\n",
  558. I915_READ(VLV_IIR_RW));
  559. seq_printf(m, "Display IMR:\t%08x\n",
  560. I915_READ(VLV_IMR));
  561. for_each_pipe(dev_priv, pipe) {
  562. enum intel_display_power_domain power_domain;
  563. power_domain = POWER_DOMAIN_PIPE(pipe);
  564. if (!intel_display_power_get_if_enabled(dev_priv,
  565. power_domain)) {
  566. seq_printf(m, "Pipe %c power disabled\n",
  567. pipe_name(pipe));
  568. continue;
  569. }
  570. seq_printf(m, "Pipe %c stat:\t%08x\n",
  571. pipe_name(pipe),
  572. I915_READ(PIPESTAT(pipe)));
  573. intel_display_power_put(dev_priv, power_domain);
  574. }
  575. intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
  576. seq_printf(m, "Port hotplug:\t%08x\n",
  577. I915_READ(PORT_HOTPLUG_EN));
  578. seq_printf(m, "DPFLIPSTAT:\t%08x\n",
  579. I915_READ(VLV_DPFLIPSTAT));
  580. seq_printf(m, "DPINVGTT:\t%08x\n",
  581. I915_READ(DPINVGTT));
  582. intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
  583. for (i = 0; i < 4; i++) {
  584. seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
  585. i, I915_READ(GEN8_GT_IMR(i)));
  586. seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
  587. i, I915_READ(GEN8_GT_IIR(i)));
  588. seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
  589. i, I915_READ(GEN8_GT_IER(i)));
  590. }
  591. seq_printf(m, "PCU interrupt mask:\t%08x\n",
  592. I915_READ(GEN8_PCU_IMR));
  593. seq_printf(m, "PCU interrupt identity:\t%08x\n",
  594. I915_READ(GEN8_PCU_IIR));
  595. seq_printf(m, "PCU interrupt enable:\t%08x\n",
  596. I915_READ(GEN8_PCU_IER));
  597. } else if (INTEL_GEN(dev_priv) >= 8) {
  598. seq_printf(m, "Master Interrupt Control:\t%08x\n",
  599. I915_READ(GEN8_MASTER_IRQ));
  600. for (i = 0; i < 4; i++) {
  601. seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
  602. i, I915_READ(GEN8_GT_IMR(i)));
  603. seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
  604. i, I915_READ(GEN8_GT_IIR(i)));
  605. seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
  606. i, I915_READ(GEN8_GT_IER(i)));
  607. }
  608. for_each_pipe(dev_priv, pipe) {
  609. enum intel_display_power_domain power_domain;
  610. power_domain = POWER_DOMAIN_PIPE(pipe);
  611. if (!intel_display_power_get_if_enabled(dev_priv,
  612. power_domain)) {
  613. seq_printf(m, "Pipe %c power disabled\n",
  614. pipe_name(pipe));
  615. continue;
  616. }
  617. seq_printf(m, "Pipe %c IMR:\t%08x\n",
  618. pipe_name(pipe),
  619. I915_READ(GEN8_DE_PIPE_IMR(pipe)));
  620. seq_printf(m, "Pipe %c IIR:\t%08x\n",
  621. pipe_name(pipe),
  622. I915_READ(GEN8_DE_PIPE_IIR(pipe)));
  623. seq_printf(m, "Pipe %c IER:\t%08x\n",
  624. pipe_name(pipe),
  625. I915_READ(GEN8_DE_PIPE_IER(pipe)));
  626. intel_display_power_put(dev_priv, power_domain);
  627. }
  628. seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
  629. I915_READ(GEN8_DE_PORT_IMR));
  630. seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
  631. I915_READ(GEN8_DE_PORT_IIR));
  632. seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
  633. I915_READ(GEN8_DE_PORT_IER));
  634. seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
  635. I915_READ(GEN8_DE_MISC_IMR));
  636. seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
  637. I915_READ(GEN8_DE_MISC_IIR));
  638. seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
  639. I915_READ(GEN8_DE_MISC_IER));
  640. seq_printf(m, "PCU interrupt mask:\t%08x\n",
  641. I915_READ(GEN8_PCU_IMR));
  642. seq_printf(m, "PCU interrupt identity:\t%08x\n",
  643. I915_READ(GEN8_PCU_IIR));
  644. seq_printf(m, "PCU interrupt enable:\t%08x\n",
  645. I915_READ(GEN8_PCU_IER));
  646. } else if (IS_VALLEYVIEW(dev_priv)) {
  647. seq_printf(m, "Display IER:\t%08x\n",
  648. I915_READ(VLV_IER));
  649. seq_printf(m, "Display IIR:\t%08x\n",
  650. I915_READ(VLV_IIR));
  651. seq_printf(m, "Display IIR_RW:\t%08x\n",
  652. I915_READ(VLV_IIR_RW));
  653. seq_printf(m, "Display IMR:\t%08x\n",
  654. I915_READ(VLV_IMR));
  655. for_each_pipe(dev_priv, pipe) {
  656. enum intel_display_power_domain power_domain;
  657. power_domain = POWER_DOMAIN_PIPE(pipe);
  658. if (!intel_display_power_get_if_enabled(dev_priv,
  659. power_domain)) {
  660. seq_printf(m, "Pipe %c power disabled\n",
  661. pipe_name(pipe));
  662. continue;
  663. }
  664. seq_printf(m, "Pipe %c stat:\t%08x\n",
  665. pipe_name(pipe),
  666. I915_READ(PIPESTAT(pipe)));
  667. intel_display_power_put(dev_priv, power_domain);
  668. }
  669. seq_printf(m, "Master IER:\t%08x\n",
  670. I915_READ(VLV_MASTER_IER));
  671. seq_printf(m, "Render IER:\t%08x\n",
  672. I915_READ(GTIER));
  673. seq_printf(m, "Render IIR:\t%08x\n",
  674. I915_READ(GTIIR));
  675. seq_printf(m, "Render IMR:\t%08x\n",
  676. I915_READ(GTIMR));
  677. seq_printf(m, "PM IER:\t\t%08x\n",
  678. I915_READ(GEN6_PMIER));
  679. seq_printf(m, "PM IIR:\t\t%08x\n",
  680. I915_READ(GEN6_PMIIR));
  681. seq_printf(m, "PM IMR:\t\t%08x\n",
  682. I915_READ(GEN6_PMIMR));
  683. seq_printf(m, "Port hotplug:\t%08x\n",
  684. I915_READ(PORT_HOTPLUG_EN));
  685. seq_printf(m, "DPFLIPSTAT:\t%08x\n",
  686. I915_READ(VLV_DPFLIPSTAT));
  687. seq_printf(m, "DPINVGTT:\t%08x\n",
  688. I915_READ(DPINVGTT));
  689. } else if (!HAS_PCH_SPLIT(dev_priv)) {
  690. seq_printf(m, "Interrupt enable: %08x\n",
  691. I915_READ(IER));
  692. seq_printf(m, "Interrupt identity: %08x\n",
  693. I915_READ(IIR));
  694. seq_printf(m, "Interrupt mask: %08x\n",
  695. I915_READ(IMR));
  696. for_each_pipe(dev_priv, pipe)
  697. seq_printf(m, "Pipe %c stat: %08x\n",
  698. pipe_name(pipe),
  699. I915_READ(PIPESTAT(pipe)));
  700. } else {
  701. seq_printf(m, "North Display Interrupt enable: %08x\n",
  702. I915_READ(DEIER));
  703. seq_printf(m, "North Display Interrupt identity: %08x\n",
  704. I915_READ(DEIIR));
  705. seq_printf(m, "North Display Interrupt mask: %08x\n",
  706. I915_READ(DEIMR));
  707. seq_printf(m, "South Display Interrupt enable: %08x\n",
  708. I915_READ(SDEIER));
  709. seq_printf(m, "South Display Interrupt identity: %08x\n",
  710. I915_READ(SDEIIR));
  711. seq_printf(m, "South Display Interrupt mask: %08x\n",
  712. I915_READ(SDEIMR));
  713. seq_printf(m, "Graphics Interrupt enable: %08x\n",
  714. I915_READ(GTIER));
  715. seq_printf(m, "Graphics Interrupt identity: %08x\n",
  716. I915_READ(GTIIR));
  717. seq_printf(m, "Graphics Interrupt mask: %08x\n",
  718. I915_READ(GTIMR));
  719. }
  720. if (INTEL_GEN(dev_priv) >= 6) {
  721. for_each_engine(engine, dev_priv, id) {
  722. seq_printf(m,
  723. "Graphics Interrupt mask (%s): %08x\n",
  724. engine->name, I915_READ_IMR(engine));
  725. }
  726. }
  727. intel_runtime_pm_put(dev_priv);
  728. return 0;
  729. }
  730. static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
  731. {
  732. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  733. struct drm_device *dev = &dev_priv->drm;
  734. int i, ret;
  735. ret = mutex_lock_interruptible(&dev->struct_mutex);
  736. if (ret)
  737. return ret;
  738. seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
  739. for (i = 0; i < dev_priv->num_fence_regs; i++) {
  740. struct i915_vma *vma = dev_priv->fence_regs[i].vma;
  741. seq_printf(m, "Fence %d, pin count = %d, object = ",
  742. i, dev_priv->fence_regs[i].pin_count);
  743. if (!vma)
  744. seq_puts(m, "unused");
  745. else
  746. describe_obj(m, vma->obj);
  747. seq_putc(m, '\n');
  748. }
  749. mutex_unlock(&dev->struct_mutex);
  750. return 0;
  751. }
  752. #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
  753. static ssize_t gpu_state_read(struct file *file, char __user *ubuf,
  754. size_t count, loff_t *pos)
  755. {
  756. struct i915_gpu_state *error = file->private_data;
  757. struct drm_i915_error_state_buf str;
  758. ssize_t ret;
  759. loff_t tmp;
  760. if (!error)
  761. return 0;
  762. ret = i915_error_state_buf_init(&str, error->i915, count, *pos);
  763. if (ret)
  764. return ret;
  765. ret = i915_error_state_to_str(&str, error);
  766. if (ret)
  767. goto out;
  768. tmp = 0;
  769. ret = simple_read_from_buffer(ubuf, count, &tmp, str.buf, str.bytes);
  770. if (ret < 0)
  771. goto out;
  772. *pos = str.start + ret;
  773. out:
  774. i915_error_state_buf_release(&str);
  775. return ret;
  776. }
  777. static int gpu_state_release(struct inode *inode, struct file *file)
  778. {
  779. i915_gpu_state_put(file->private_data);
  780. return 0;
  781. }
  782. static int i915_gpu_info_open(struct inode *inode, struct file *file)
  783. {
  784. struct drm_i915_private *i915 = inode->i_private;
  785. struct i915_gpu_state *gpu;
  786. intel_runtime_pm_get(i915);
  787. gpu = i915_capture_gpu_state(i915);
  788. intel_runtime_pm_put(i915);
  789. if (!gpu)
  790. return -ENOMEM;
  791. file->private_data = gpu;
  792. return 0;
  793. }
  794. static const struct file_operations i915_gpu_info_fops = {
  795. .owner = THIS_MODULE,
  796. .open = i915_gpu_info_open,
  797. .read = gpu_state_read,
  798. .llseek = default_llseek,
  799. .release = gpu_state_release,
  800. };
  801. static ssize_t
  802. i915_error_state_write(struct file *filp,
  803. const char __user *ubuf,
  804. size_t cnt,
  805. loff_t *ppos)
  806. {
  807. struct i915_gpu_state *error = filp->private_data;
  808. if (!error)
  809. return 0;
  810. DRM_DEBUG_DRIVER("Resetting error state\n");
  811. i915_reset_error_state(error->i915);
  812. return cnt;
  813. }
  814. static int i915_error_state_open(struct inode *inode, struct file *file)
  815. {
  816. file->private_data = i915_first_error_state(inode->i_private);
  817. return 0;
  818. }
  819. static const struct file_operations i915_error_state_fops = {
  820. .owner = THIS_MODULE,
  821. .open = i915_error_state_open,
  822. .read = gpu_state_read,
  823. .write = i915_error_state_write,
  824. .llseek = default_llseek,
  825. .release = gpu_state_release,
  826. };
  827. #endif
  828. static int
  829. i915_next_seqno_set(void *data, u64 val)
  830. {
  831. struct drm_i915_private *dev_priv = data;
  832. struct drm_device *dev = &dev_priv->drm;
  833. int ret;
  834. ret = mutex_lock_interruptible(&dev->struct_mutex);
  835. if (ret)
  836. return ret;
  837. ret = i915_gem_set_global_seqno(dev, val);
  838. mutex_unlock(&dev->struct_mutex);
  839. return ret;
  840. }
  841. DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
  842. NULL, i915_next_seqno_set,
  843. "0x%llx\n");
  844. static int i915_frequency_info(struct seq_file *m, void *unused)
  845. {
  846. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  847. struct intel_rps *rps = &dev_priv->gt_pm.rps;
  848. int ret = 0;
  849. intel_runtime_pm_get(dev_priv);
  850. if (IS_GEN5(dev_priv)) {
  851. u16 rgvswctl = I915_READ16(MEMSWCTL);
  852. u16 rgvstat = I915_READ16(MEMSTAT_ILK);
  853. seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
  854. seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
  855. seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
  856. MEMSTAT_VID_SHIFT);
  857. seq_printf(m, "Current P-state: %d\n",
  858. (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
  859. } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
  860. u32 rpmodectl, freq_sts;
  861. mutex_lock(&dev_priv->pcu_lock);
  862. rpmodectl = I915_READ(GEN6_RP_CONTROL);
  863. seq_printf(m, "Video Turbo Mode: %s\n",
  864. yesno(rpmodectl & GEN6_RP_MEDIA_TURBO));
  865. seq_printf(m, "HW control enabled: %s\n",
  866. yesno(rpmodectl & GEN6_RP_ENABLE));
  867. seq_printf(m, "SW control enabled: %s\n",
  868. yesno((rpmodectl & GEN6_RP_MEDIA_MODE_MASK) ==
  869. GEN6_RP_MEDIA_SW_MODE));
  870. freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
  871. seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
  872. seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
  873. seq_printf(m, "actual GPU freq: %d MHz\n",
  874. intel_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
  875. seq_printf(m, "current GPU freq: %d MHz\n",
  876. intel_gpu_freq(dev_priv, rps->cur_freq));
  877. seq_printf(m, "max GPU freq: %d MHz\n",
  878. intel_gpu_freq(dev_priv, rps->max_freq));
  879. seq_printf(m, "min GPU freq: %d MHz\n",
  880. intel_gpu_freq(dev_priv, rps->min_freq));
  881. seq_printf(m, "idle GPU freq: %d MHz\n",
  882. intel_gpu_freq(dev_priv, rps->idle_freq));
  883. seq_printf(m,
  884. "efficient (RPe) frequency: %d MHz\n",
  885. intel_gpu_freq(dev_priv, rps->efficient_freq));
  886. mutex_unlock(&dev_priv->pcu_lock);
  887. } else if (INTEL_GEN(dev_priv) >= 6) {
  888. u32 rp_state_limits;
  889. u32 gt_perf_status;
  890. u32 rp_state_cap;
  891. u32 rpmodectl, rpinclimit, rpdeclimit;
  892. u32 rpstat, cagf, reqf;
  893. u32 rpupei, rpcurup, rpprevup;
  894. u32 rpdownei, rpcurdown, rpprevdown;
  895. u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
  896. int max_freq;
  897. rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
  898. if (IS_GEN9_LP(dev_priv)) {
  899. rp_state_cap = I915_READ(BXT_RP_STATE_CAP);
  900. gt_perf_status = I915_READ(BXT_GT_PERF_STATUS);
  901. } else {
  902. rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
  903. gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
  904. }
  905. /* RPSTAT1 is in the GT power well */
  906. intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
  907. reqf = I915_READ(GEN6_RPNSWREQ);
  908. if (INTEL_GEN(dev_priv) >= 9)
  909. reqf >>= 23;
  910. else {
  911. reqf &= ~GEN6_TURBO_DISABLE;
  912. if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
  913. reqf >>= 24;
  914. else
  915. reqf >>= 25;
  916. }
  917. reqf = intel_gpu_freq(dev_priv, reqf);
  918. rpmodectl = I915_READ(GEN6_RP_CONTROL);
  919. rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
  920. rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
  921. rpstat = I915_READ(GEN6_RPSTAT1);
  922. rpupei = I915_READ(GEN6_RP_CUR_UP_EI) & GEN6_CURICONT_MASK;
  923. rpcurup = I915_READ(GEN6_RP_CUR_UP) & GEN6_CURBSYTAVG_MASK;
  924. rpprevup = I915_READ(GEN6_RP_PREV_UP) & GEN6_CURBSYTAVG_MASK;
  925. rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI) & GEN6_CURIAVG_MASK;
  926. rpcurdown = I915_READ(GEN6_RP_CUR_DOWN) & GEN6_CURBSYTAVG_MASK;
  927. rpprevdown = I915_READ(GEN6_RP_PREV_DOWN) & GEN6_CURBSYTAVG_MASK;
  928. cagf = intel_gpu_freq(dev_priv,
  929. intel_get_cagf(dev_priv, rpstat));
  930. intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
  931. if (IS_GEN6(dev_priv) || IS_GEN7(dev_priv)) {
  932. pm_ier = I915_READ(GEN6_PMIER);
  933. pm_imr = I915_READ(GEN6_PMIMR);
  934. pm_isr = I915_READ(GEN6_PMISR);
  935. pm_iir = I915_READ(GEN6_PMIIR);
  936. pm_mask = I915_READ(GEN6_PMINTRMSK);
  937. } else {
  938. pm_ier = I915_READ(GEN8_GT_IER(2));
  939. pm_imr = I915_READ(GEN8_GT_IMR(2));
  940. pm_isr = I915_READ(GEN8_GT_ISR(2));
  941. pm_iir = I915_READ(GEN8_GT_IIR(2));
  942. pm_mask = I915_READ(GEN6_PMINTRMSK);
  943. }
  944. seq_printf(m, "Video Turbo Mode: %s\n",
  945. yesno(rpmodectl & GEN6_RP_MEDIA_TURBO));
  946. seq_printf(m, "HW control enabled: %s\n",
  947. yesno(rpmodectl & GEN6_RP_ENABLE));
  948. seq_printf(m, "SW control enabled: %s\n",
  949. yesno((rpmodectl & GEN6_RP_MEDIA_MODE_MASK) ==
  950. GEN6_RP_MEDIA_SW_MODE));
  951. seq_printf(m, "PM IER=0x%08x IMR=0x%08x ISR=0x%08x IIR=0x%08x, MASK=0x%08x\n",
  952. pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
  953. seq_printf(m, "pm_intrmsk_mbz: 0x%08x\n",
  954. rps->pm_intrmsk_mbz);
  955. seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
  956. seq_printf(m, "Render p-state ratio: %d\n",
  957. (gt_perf_status & (INTEL_GEN(dev_priv) >= 9 ? 0x1ff00 : 0xff00)) >> 8);
  958. seq_printf(m, "Render p-state VID: %d\n",
  959. gt_perf_status & 0xff);
  960. seq_printf(m, "Render p-state limit: %d\n",
  961. rp_state_limits & 0xff);
  962. seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
  963. seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
  964. seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
  965. seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
  966. seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
  967. seq_printf(m, "CAGF: %dMHz\n", cagf);
  968. seq_printf(m, "RP CUR UP EI: %d (%dus)\n",
  969. rpupei, GT_PM_INTERVAL_TO_US(dev_priv, rpupei));
  970. seq_printf(m, "RP CUR UP: %d (%dus)\n",
  971. rpcurup, GT_PM_INTERVAL_TO_US(dev_priv, rpcurup));
  972. seq_printf(m, "RP PREV UP: %d (%dus)\n",
  973. rpprevup, GT_PM_INTERVAL_TO_US(dev_priv, rpprevup));
  974. seq_printf(m, "Up threshold: %d%%\n", rps->up_threshold);
  975. seq_printf(m, "RP CUR DOWN EI: %d (%dus)\n",
  976. rpdownei, GT_PM_INTERVAL_TO_US(dev_priv, rpdownei));
  977. seq_printf(m, "RP CUR DOWN: %d (%dus)\n",
  978. rpcurdown, GT_PM_INTERVAL_TO_US(dev_priv, rpcurdown));
  979. seq_printf(m, "RP PREV DOWN: %d (%dus)\n",
  980. rpprevdown, GT_PM_INTERVAL_TO_US(dev_priv, rpprevdown));
  981. seq_printf(m, "Down threshold: %d%%\n", rps->down_threshold);
  982. max_freq = (IS_GEN9_LP(dev_priv) ? rp_state_cap >> 0 :
  983. rp_state_cap >> 16) & 0xff;
  984. max_freq *= (IS_GEN9_BC(dev_priv) ||
  985. IS_CANNONLAKE(dev_priv) ? GEN9_FREQ_SCALER : 1);
  986. seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
  987. intel_gpu_freq(dev_priv, max_freq));
  988. max_freq = (rp_state_cap & 0xff00) >> 8;
  989. max_freq *= (IS_GEN9_BC(dev_priv) ||
  990. IS_CANNONLAKE(dev_priv) ? GEN9_FREQ_SCALER : 1);
  991. seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
  992. intel_gpu_freq(dev_priv, max_freq));
  993. max_freq = (IS_GEN9_LP(dev_priv) ? rp_state_cap >> 16 :
  994. rp_state_cap >> 0) & 0xff;
  995. max_freq *= (IS_GEN9_BC(dev_priv) ||
  996. IS_CANNONLAKE(dev_priv) ? GEN9_FREQ_SCALER : 1);
  997. seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
  998. intel_gpu_freq(dev_priv, max_freq));
  999. seq_printf(m, "Max overclocked frequency: %dMHz\n",
  1000. intel_gpu_freq(dev_priv, rps->max_freq));
  1001. seq_printf(m, "Current freq: %d MHz\n",
  1002. intel_gpu_freq(dev_priv, rps->cur_freq));
  1003. seq_printf(m, "Actual freq: %d MHz\n", cagf);
  1004. seq_printf(m, "Idle freq: %d MHz\n",
  1005. intel_gpu_freq(dev_priv, rps->idle_freq));
  1006. seq_printf(m, "Min freq: %d MHz\n",
  1007. intel_gpu_freq(dev_priv, rps->min_freq));
  1008. seq_printf(m, "Boost freq: %d MHz\n",
  1009. intel_gpu_freq(dev_priv, rps->boost_freq));
  1010. seq_printf(m, "Max freq: %d MHz\n",
  1011. intel_gpu_freq(dev_priv, rps->max_freq));
  1012. seq_printf(m,
  1013. "efficient (RPe) frequency: %d MHz\n",
  1014. intel_gpu_freq(dev_priv, rps->efficient_freq));
  1015. } else {
  1016. seq_puts(m, "no P-state info available\n");
  1017. }
  1018. seq_printf(m, "Current CD clock frequency: %d kHz\n", dev_priv->cdclk.hw.cdclk);
  1019. seq_printf(m, "Max CD clock frequency: %d kHz\n", dev_priv->max_cdclk_freq);
  1020. seq_printf(m, "Max pixel clock frequency: %d kHz\n", dev_priv->max_dotclk_freq);
  1021. intel_runtime_pm_put(dev_priv);
  1022. return ret;
  1023. }
  1024. static void i915_instdone_info(struct drm_i915_private *dev_priv,
  1025. struct seq_file *m,
  1026. struct intel_instdone *instdone)
  1027. {
  1028. int slice;
  1029. int subslice;
  1030. seq_printf(m, "\t\tINSTDONE: 0x%08x\n",
  1031. instdone->instdone);
  1032. if (INTEL_GEN(dev_priv) <= 3)
  1033. return;
  1034. seq_printf(m, "\t\tSC_INSTDONE: 0x%08x\n",
  1035. instdone->slice_common);
  1036. if (INTEL_GEN(dev_priv) <= 6)
  1037. return;
  1038. for_each_instdone_slice_subslice(dev_priv, slice, subslice)
  1039. seq_printf(m, "\t\tSAMPLER_INSTDONE[%d][%d]: 0x%08x\n",
  1040. slice, subslice, instdone->sampler[slice][subslice]);
  1041. for_each_instdone_slice_subslice(dev_priv, slice, subslice)
  1042. seq_printf(m, "\t\tROW_INSTDONE[%d][%d]: 0x%08x\n",
  1043. slice, subslice, instdone->row[slice][subslice]);
  1044. }
  1045. static int i915_hangcheck_info(struct seq_file *m, void *unused)
  1046. {
  1047. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1048. struct intel_engine_cs *engine;
  1049. u64 acthd[I915_NUM_ENGINES];
  1050. u32 seqno[I915_NUM_ENGINES];
  1051. struct intel_instdone instdone;
  1052. enum intel_engine_id id;
  1053. if (test_bit(I915_WEDGED, &dev_priv->gpu_error.flags))
  1054. seq_puts(m, "Wedged\n");
  1055. if (test_bit(I915_RESET_BACKOFF, &dev_priv->gpu_error.flags))
  1056. seq_puts(m, "Reset in progress: struct_mutex backoff\n");
  1057. if (test_bit(I915_RESET_HANDOFF, &dev_priv->gpu_error.flags))
  1058. seq_puts(m, "Reset in progress: reset handoff to waiter\n");
  1059. if (waitqueue_active(&dev_priv->gpu_error.wait_queue))
  1060. seq_puts(m, "Waiter holding struct mutex\n");
  1061. if (waitqueue_active(&dev_priv->gpu_error.reset_queue))
  1062. seq_puts(m, "struct_mutex blocked for reset\n");
  1063. if (!i915_modparams.enable_hangcheck) {
  1064. seq_puts(m, "Hangcheck disabled\n");
  1065. return 0;
  1066. }
  1067. intel_runtime_pm_get(dev_priv);
  1068. for_each_engine(engine, dev_priv, id) {
  1069. acthd[id] = intel_engine_get_active_head(engine);
  1070. seqno[id] = intel_engine_get_seqno(engine);
  1071. }
  1072. intel_engine_get_instdone(dev_priv->engine[RCS], &instdone);
  1073. intel_runtime_pm_put(dev_priv);
  1074. if (timer_pending(&dev_priv->gpu_error.hangcheck_work.timer))
  1075. seq_printf(m, "Hangcheck active, timer fires in %dms\n",
  1076. jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
  1077. jiffies));
  1078. else if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work))
  1079. seq_puts(m, "Hangcheck active, work pending\n");
  1080. else
  1081. seq_puts(m, "Hangcheck inactive\n");
  1082. seq_printf(m, "GT active? %s\n", yesno(dev_priv->gt.awake));
  1083. for_each_engine(engine, dev_priv, id) {
  1084. struct intel_breadcrumbs *b = &engine->breadcrumbs;
  1085. struct rb_node *rb;
  1086. seq_printf(m, "%s:\n", engine->name);
  1087. seq_printf(m, "\tseqno = %x [current %x, last %x], inflight %d\n",
  1088. engine->hangcheck.seqno, seqno[id],
  1089. intel_engine_last_submit(engine),
  1090. engine->timeline->inflight_seqnos);
  1091. seq_printf(m, "\twaiters? %s, fake irq active? %s, stalled? %s\n",
  1092. yesno(intel_engine_has_waiter(engine)),
  1093. yesno(test_bit(engine->id,
  1094. &dev_priv->gpu_error.missed_irq_rings)),
  1095. yesno(engine->hangcheck.stalled));
  1096. spin_lock_irq(&b->rb_lock);
  1097. for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
  1098. struct intel_wait *w = rb_entry(rb, typeof(*w), node);
  1099. seq_printf(m, "\t%s [%d] waiting for %x\n",
  1100. w->tsk->comm, w->tsk->pid, w->seqno);
  1101. }
  1102. spin_unlock_irq(&b->rb_lock);
  1103. seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
  1104. (long long)engine->hangcheck.acthd,
  1105. (long long)acthd[id]);
  1106. seq_printf(m, "\taction = %s(%d) %d ms ago\n",
  1107. hangcheck_action_to_str(engine->hangcheck.action),
  1108. engine->hangcheck.action,
  1109. jiffies_to_msecs(jiffies -
  1110. engine->hangcheck.action_timestamp));
  1111. if (engine->id == RCS) {
  1112. seq_puts(m, "\tinstdone read =\n");
  1113. i915_instdone_info(dev_priv, m, &instdone);
  1114. seq_puts(m, "\tinstdone accu =\n");
  1115. i915_instdone_info(dev_priv, m,
  1116. &engine->hangcheck.instdone);
  1117. }
  1118. }
  1119. return 0;
  1120. }
  1121. static int i915_reset_info(struct seq_file *m, void *unused)
  1122. {
  1123. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1124. struct i915_gpu_error *error = &dev_priv->gpu_error;
  1125. struct intel_engine_cs *engine;
  1126. enum intel_engine_id id;
  1127. seq_printf(m, "full gpu reset = %u\n", i915_reset_count(error));
  1128. for_each_engine(engine, dev_priv, id) {
  1129. seq_printf(m, "%s = %u\n", engine->name,
  1130. i915_reset_engine_count(error, engine));
  1131. }
  1132. return 0;
  1133. }
  1134. static int ironlake_drpc_info(struct seq_file *m)
  1135. {
  1136. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1137. u32 rgvmodectl, rstdbyctl;
  1138. u16 crstandvid;
  1139. rgvmodectl = I915_READ(MEMMODECTL);
  1140. rstdbyctl = I915_READ(RSTDBYCTL);
  1141. crstandvid = I915_READ16(CRSTANDVID);
  1142. seq_printf(m, "HD boost: %s\n", yesno(rgvmodectl & MEMMODE_BOOST_EN));
  1143. seq_printf(m, "Boost freq: %d\n",
  1144. (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
  1145. MEMMODE_BOOST_FREQ_SHIFT);
  1146. seq_printf(m, "HW control enabled: %s\n",
  1147. yesno(rgvmodectl & MEMMODE_HWIDLE_EN));
  1148. seq_printf(m, "SW control enabled: %s\n",
  1149. yesno(rgvmodectl & MEMMODE_SWMODE_EN));
  1150. seq_printf(m, "Gated voltage change: %s\n",
  1151. yesno(rgvmodectl & MEMMODE_RCLK_GATE));
  1152. seq_printf(m, "Starting frequency: P%d\n",
  1153. (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
  1154. seq_printf(m, "Max P-state: P%d\n",
  1155. (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
  1156. seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
  1157. seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
  1158. seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
  1159. seq_printf(m, "Render standby enabled: %s\n",
  1160. yesno(!(rstdbyctl & RCX_SW_EXIT)));
  1161. seq_puts(m, "Current RS state: ");
  1162. switch (rstdbyctl & RSX_STATUS_MASK) {
  1163. case RSX_STATUS_ON:
  1164. seq_puts(m, "on\n");
  1165. break;
  1166. case RSX_STATUS_RC1:
  1167. seq_puts(m, "RC1\n");
  1168. break;
  1169. case RSX_STATUS_RC1E:
  1170. seq_puts(m, "RC1E\n");
  1171. break;
  1172. case RSX_STATUS_RS1:
  1173. seq_puts(m, "RS1\n");
  1174. break;
  1175. case RSX_STATUS_RS2:
  1176. seq_puts(m, "RS2 (RC6)\n");
  1177. break;
  1178. case RSX_STATUS_RS3:
  1179. seq_puts(m, "RC3 (RC6+)\n");
  1180. break;
  1181. default:
  1182. seq_puts(m, "unknown\n");
  1183. break;
  1184. }
  1185. return 0;
  1186. }
  1187. static int i915_forcewake_domains(struct seq_file *m, void *data)
  1188. {
  1189. struct drm_i915_private *i915 = node_to_i915(m->private);
  1190. struct intel_uncore_forcewake_domain *fw_domain;
  1191. unsigned int tmp;
  1192. seq_printf(m, "user.bypass_count = %u\n",
  1193. i915->uncore.user_forcewake.count);
  1194. for_each_fw_domain(fw_domain, i915, tmp)
  1195. seq_printf(m, "%s.wake_count = %u\n",
  1196. intel_uncore_forcewake_domain_to_str(fw_domain->id),
  1197. READ_ONCE(fw_domain->wake_count));
  1198. return 0;
  1199. }
  1200. static void print_rc6_res(struct seq_file *m,
  1201. const char *title,
  1202. const i915_reg_t reg)
  1203. {
  1204. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1205. seq_printf(m, "%s %u (%llu us)\n",
  1206. title, I915_READ(reg),
  1207. intel_rc6_residency_us(dev_priv, reg));
  1208. }
  1209. static int vlv_drpc_info(struct seq_file *m)
  1210. {
  1211. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1212. u32 rcctl1, pw_status;
  1213. pw_status = I915_READ(VLV_GTLC_PW_STATUS);
  1214. rcctl1 = I915_READ(GEN6_RC_CONTROL);
  1215. seq_printf(m, "RC6 Enabled: %s\n",
  1216. yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
  1217. GEN6_RC_CTL_EI_MODE(1))));
  1218. seq_printf(m, "Render Power Well: %s\n",
  1219. (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
  1220. seq_printf(m, "Media Power Well: %s\n",
  1221. (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
  1222. print_rc6_res(m, "Render RC6 residency since boot:", VLV_GT_RENDER_RC6);
  1223. print_rc6_res(m, "Media RC6 residency since boot:", VLV_GT_MEDIA_RC6);
  1224. return i915_forcewake_domains(m, NULL);
  1225. }
  1226. static int gen6_drpc_info(struct seq_file *m)
  1227. {
  1228. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1229. u32 gt_core_status, rcctl1, rc6vids = 0;
  1230. u32 gen9_powergate_enable = 0, gen9_powergate_status = 0;
  1231. unsigned forcewake_count;
  1232. int count = 0;
  1233. forcewake_count = READ_ONCE(dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count);
  1234. if (forcewake_count) {
  1235. seq_puts(m, "RC information inaccurate because somebody "
  1236. "holds a forcewake reference \n");
  1237. } else {
  1238. /* NB: we cannot use forcewake, else we read the wrong values */
  1239. while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
  1240. udelay(10);
  1241. seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
  1242. }
  1243. gt_core_status = I915_READ_FW(GEN6_GT_CORE_STATUS);
  1244. trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
  1245. rcctl1 = I915_READ(GEN6_RC_CONTROL);
  1246. if (INTEL_GEN(dev_priv) >= 9) {
  1247. gen9_powergate_enable = I915_READ(GEN9_PG_ENABLE);
  1248. gen9_powergate_status = I915_READ(GEN9_PWRGT_DOMAIN_STATUS);
  1249. }
  1250. mutex_lock(&dev_priv->pcu_lock);
  1251. sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
  1252. mutex_unlock(&dev_priv->pcu_lock);
  1253. seq_printf(m, "RC1e Enabled: %s\n",
  1254. yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
  1255. seq_printf(m, "RC6 Enabled: %s\n",
  1256. yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
  1257. if (INTEL_GEN(dev_priv) >= 9) {
  1258. seq_printf(m, "Render Well Gating Enabled: %s\n",
  1259. yesno(gen9_powergate_enable & GEN9_RENDER_PG_ENABLE));
  1260. seq_printf(m, "Media Well Gating Enabled: %s\n",
  1261. yesno(gen9_powergate_enable & GEN9_MEDIA_PG_ENABLE));
  1262. }
  1263. seq_printf(m, "Deep RC6 Enabled: %s\n",
  1264. yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
  1265. seq_printf(m, "Deepest RC6 Enabled: %s\n",
  1266. yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
  1267. seq_puts(m, "Current RC state: ");
  1268. switch (gt_core_status & GEN6_RCn_MASK) {
  1269. case GEN6_RC0:
  1270. if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
  1271. seq_puts(m, "Core Power Down\n");
  1272. else
  1273. seq_puts(m, "on\n");
  1274. break;
  1275. case GEN6_RC3:
  1276. seq_puts(m, "RC3\n");
  1277. break;
  1278. case GEN6_RC6:
  1279. seq_puts(m, "RC6\n");
  1280. break;
  1281. case GEN6_RC7:
  1282. seq_puts(m, "RC7\n");
  1283. break;
  1284. default:
  1285. seq_puts(m, "Unknown\n");
  1286. break;
  1287. }
  1288. seq_printf(m, "Core Power Down: %s\n",
  1289. yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
  1290. if (INTEL_GEN(dev_priv) >= 9) {
  1291. seq_printf(m, "Render Power Well: %s\n",
  1292. (gen9_powergate_status &
  1293. GEN9_PWRGT_RENDER_STATUS_MASK) ? "Up" : "Down");
  1294. seq_printf(m, "Media Power Well: %s\n",
  1295. (gen9_powergate_status &
  1296. GEN9_PWRGT_MEDIA_STATUS_MASK) ? "Up" : "Down");
  1297. }
  1298. /* Not exactly sure what this is */
  1299. print_rc6_res(m, "RC6 \"Locked to RPn\" residency since boot:",
  1300. GEN6_GT_GFX_RC6_LOCKED);
  1301. print_rc6_res(m, "RC6 residency since boot:", GEN6_GT_GFX_RC6);
  1302. print_rc6_res(m, "RC6+ residency since boot:", GEN6_GT_GFX_RC6p);
  1303. print_rc6_res(m, "RC6++ residency since boot:", GEN6_GT_GFX_RC6pp);
  1304. seq_printf(m, "RC6 voltage: %dmV\n",
  1305. GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
  1306. seq_printf(m, "RC6+ voltage: %dmV\n",
  1307. GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
  1308. seq_printf(m, "RC6++ voltage: %dmV\n",
  1309. GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
  1310. return i915_forcewake_domains(m, NULL);
  1311. }
  1312. static int i915_drpc_info(struct seq_file *m, void *unused)
  1313. {
  1314. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1315. int err;
  1316. intel_runtime_pm_get(dev_priv);
  1317. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  1318. err = vlv_drpc_info(m);
  1319. else if (INTEL_GEN(dev_priv) >= 6)
  1320. err = gen6_drpc_info(m);
  1321. else
  1322. err = ironlake_drpc_info(m);
  1323. intel_runtime_pm_put(dev_priv);
  1324. return err;
  1325. }
  1326. static int i915_frontbuffer_tracking(struct seq_file *m, void *unused)
  1327. {
  1328. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1329. seq_printf(m, "FB tracking busy bits: 0x%08x\n",
  1330. dev_priv->fb_tracking.busy_bits);
  1331. seq_printf(m, "FB tracking flip bits: 0x%08x\n",
  1332. dev_priv->fb_tracking.flip_bits);
  1333. return 0;
  1334. }
  1335. static int i915_fbc_status(struct seq_file *m, void *unused)
  1336. {
  1337. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1338. struct intel_fbc *fbc = &dev_priv->fbc;
  1339. if (!HAS_FBC(dev_priv))
  1340. return -ENODEV;
  1341. intel_runtime_pm_get(dev_priv);
  1342. mutex_lock(&fbc->lock);
  1343. if (intel_fbc_is_active(dev_priv))
  1344. seq_puts(m, "FBC enabled\n");
  1345. else
  1346. seq_printf(m, "FBC disabled: %s\n", fbc->no_fbc_reason);
  1347. if (fbc->work.scheduled)
  1348. seq_printf(m, "FBC worker scheduled on vblank %u, now %llu\n",
  1349. fbc->work.scheduled_vblank,
  1350. drm_crtc_vblank_count(&fbc->crtc->base));
  1351. if (intel_fbc_is_active(dev_priv)) {
  1352. u32 mask;
  1353. if (INTEL_GEN(dev_priv) >= 8)
  1354. mask = I915_READ(IVB_FBC_STATUS2) & BDW_FBC_COMP_SEG_MASK;
  1355. else if (INTEL_GEN(dev_priv) >= 7)
  1356. mask = I915_READ(IVB_FBC_STATUS2) & IVB_FBC_COMP_SEG_MASK;
  1357. else if (INTEL_GEN(dev_priv) >= 5)
  1358. mask = I915_READ(ILK_DPFC_STATUS) & ILK_DPFC_COMP_SEG_MASK;
  1359. else if (IS_G4X(dev_priv))
  1360. mask = I915_READ(DPFC_STATUS) & DPFC_COMP_SEG_MASK;
  1361. else
  1362. mask = I915_READ(FBC_STATUS) & (FBC_STAT_COMPRESSING |
  1363. FBC_STAT_COMPRESSED);
  1364. seq_printf(m, "Compressing: %s\n", yesno(mask));
  1365. }
  1366. mutex_unlock(&fbc->lock);
  1367. intel_runtime_pm_put(dev_priv);
  1368. return 0;
  1369. }
  1370. static int i915_fbc_false_color_get(void *data, u64 *val)
  1371. {
  1372. struct drm_i915_private *dev_priv = data;
  1373. if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
  1374. return -ENODEV;
  1375. *val = dev_priv->fbc.false_color;
  1376. return 0;
  1377. }
  1378. static int i915_fbc_false_color_set(void *data, u64 val)
  1379. {
  1380. struct drm_i915_private *dev_priv = data;
  1381. u32 reg;
  1382. if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
  1383. return -ENODEV;
  1384. mutex_lock(&dev_priv->fbc.lock);
  1385. reg = I915_READ(ILK_DPFC_CONTROL);
  1386. dev_priv->fbc.false_color = val;
  1387. I915_WRITE(ILK_DPFC_CONTROL, val ?
  1388. (reg | FBC_CTL_FALSE_COLOR) :
  1389. (reg & ~FBC_CTL_FALSE_COLOR));
  1390. mutex_unlock(&dev_priv->fbc.lock);
  1391. return 0;
  1392. }
  1393. DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_false_color_fops,
  1394. i915_fbc_false_color_get, i915_fbc_false_color_set,
  1395. "%llu\n");
  1396. static int i915_ips_status(struct seq_file *m, void *unused)
  1397. {
  1398. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1399. if (!HAS_IPS(dev_priv))
  1400. return -ENODEV;
  1401. intel_runtime_pm_get(dev_priv);
  1402. seq_printf(m, "Enabled by kernel parameter: %s\n",
  1403. yesno(i915_modparams.enable_ips));
  1404. if (INTEL_GEN(dev_priv) >= 8) {
  1405. seq_puts(m, "Currently: unknown\n");
  1406. } else {
  1407. if (I915_READ(IPS_CTL) & IPS_ENABLE)
  1408. seq_puts(m, "Currently: enabled\n");
  1409. else
  1410. seq_puts(m, "Currently: disabled\n");
  1411. }
  1412. intel_runtime_pm_put(dev_priv);
  1413. return 0;
  1414. }
  1415. static int i915_sr_status(struct seq_file *m, void *unused)
  1416. {
  1417. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1418. bool sr_enabled = false;
  1419. intel_runtime_pm_get(dev_priv);
  1420. intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
  1421. if (INTEL_GEN(dev_priv) >= 9)
  1422. /* no global SR status; inspect per-plane WM */;
  1423. else if (HAS_PCH_SPLIT(dev_priv))
  1424. sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
  1425. else if (IS_I965GM(dev_priv) || IS_G4X(dev_priv) ||
  1426. IS_I945G(dev_priv) || IS_I945GM(dev_priv))
  1427. sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
  1428. else if (IS_I915GM(dev_priv))
  1429. sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
  1430. else if (IS_PINEVIEW(dev_priv))
  1431. sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
  1432. else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  1433. sr_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
  1434. intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
  1435. intel_runtime_pm_put(dev_priv);
  1436. seq_printf(m, "self-refresh: %s\n", enableddisabled(sr_enabled));
  1437. return 0;
  1438. }
  1439. static int i915_emon_status(struct seq_file *m, void *unused)
  1440. {
  1441. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1442. struct drm_device *dev = &dev_priv->drm;
  1443. unsigned long temp, chipset, gfx;
  1444. int ret;
  1445. if (!IS_GEN5(dev_priv))
  1446. return -ENODEV;
  1447. ret = mutex_lock_interruptible(&dev->struct_mutex);
  1448. if (ret)
  1449. return ret;
  1450. temp = i915_mch_val(dev_priv);
  1451. chipset = i915_chipset_val(dev_priv);
  1452. gfx = i915_gfx_val(dev_priv);
  1453. mutex_unlock(&dev->struct_mutex);
  1454. seq_printf(m, "GMCH temp: %ld\n", temp);
  1455. seq_printf(m, "Chipset power: %ld\n", chipset);
  1456. seq_printf(m, "GFX power: %ld\n", gfx);
  1457. seq_printf(m, "Total power: %ld\n", chipset + gfx);
  1458. return 0;
  1459. }
  1460. static int i915_ring_freq_table(struct seq_file *m, void *unused)
  1461. {
  1462. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1463. struct intel_rps *rps = &dev_priv->gt_pm.rps;
  1464. int ret = 0;
  1465. int gpu_freq, ia_freq;
  1466. unsigned int max_gpu_freq, min_gpu_freq;
  1467. if (!HAS_LLC(dev_priv))
  1468. return -ENODEV;
  1469. intel_runtime_pm_get(dev_priv);
  1470. ret = mutex_lock_interruptible(&dev_priv->pcu_lock);
  1471. if (ret)
  1472. goto out;
  1473. if (IS_GEN9_BC(dev_priv) || IS_CANNONLAKE(dev_priv)) {
  1474. /* Convert GT frequency to 50 HZ units */
  1475. min_gpu_freq = rps->min_freq_softlimit / GEN9_FREQ_SCALER;
  1476. max_gpu_freq = rps->max_freq_softlimit / GEN9_FREQ_SCALER;
  1477. } else {
  1478. min_gpu_freq = rps->min_freq_softlimit;
  1479. max_gpu_freq = rps->max_freq_softlimit;
  1480. }
  1481. seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
  1482. for (gpu_freq = min_gpu_freq; gpu_freq <= max_gpu_freq; gpu_freq++) {
  1483. ia_freq = gpu_freq;
  1484. sandybridge_pcode_read(dev_priv,
  1485. GEN6_PCODE_READ_MIN_FREQ_TABLE,
  1486. &ia_freq);
  1487. seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
  1488. intel_gpu_freq(dev_priv, (gpu_freq *
  1489. (IS_GEN9_BC(dev_priv) ||
  1490. IS_CANNONLAKE(dev_priv) ?
  1491. GEN9_FREQ_SCALER : 1))),
  1492. ((ia_freq >> 0) & 0xff) * 100,
  1493. ((ia_freq >> 8) & 0xff) * 100);
  1494. }
  1495. mutex_unlock(&dev_priv->pcu_lock);
  1496. out:
  1497. intel_runtime_pm_put(dev_priv);
  1498. return ret;
  1499. }
  1500. static int i915_opregion(struct seq_file *m, void *unused)
  1501. {
  1502. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1503. struct drm_device *dev = &dev_priv->drm;
  1504. struct intel_opregion *opregion = &dev_priv->opregion;
  1505. int ret;
  1506. ret = mutex_lock_interruptible(&dev->struct_mutex);
  1507. if (ret)
  1508. goto out;
  1509. if (opregion->header)
  1510. seq_write(m, opregion->header, OPREGION_SIZE);
  1511. mutex_unlock(&dev->struct_mutex);
  1512. out:
  1513. return 0;
  1514. }
  1515. static int i915_vbt(struct seq_file *m, void *unused)
  1516. {
  1517. struct intel_opregion *opregion = &node_to_i915(m->private)->opregion;
  1518. if (opregion->vbt)
  1519. seq_write(m, opregion->vbt, opregion->vbt_size);
  1520. return 0;
  1521. }
  1522. static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
  1523. {
  1524. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1525. struct drm_device *dev = &dev_priv->drm;
  1526. struct intel_framebuffer *fbdev_fb = NULL;
  1527. struct drm_framebuffer *drm_fb;
  1528. int ret;
  1529. ret = mutex_lock_interruptible(&dev->struct_mutex);
  1530. if (ret)
  1531. return ret;
  1532. #ifdef CONFIG_DRM_FBDEV_EMULATION
  1533. if (dev_priv->fbdev && dev_priv->fbdev->helper.fb) {
  1534. fbdev_fb = to_intel_framebuffer(dev_priv->fbdev->helper.fb);
  1535. seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
  1536. fbdev_fb->base.width,
  1537. fbdev_fb->base.height,
  1538. fbdev_fb->base.format->depth,
  1539. fbdev_fb->base.format->cpp[0] * 8,
  1540. fbdev_fb->base.modifier,
  1541. drm_framebuffer_read_refcount(&fbdev_fb->base));
  1542. describe_obj(m, fbdev_fb->obj);
  1543. seq_putc(m, '\n');
  1544. }
  1545. #endif
  1546. mutex_lock(&dev->mode_config.fb_lock);
  1547. drm_for_each_fb(drm_fb, dev) {
  1548. struct intel_framebuffer *fb = to_intel_framebuffer(drm_fb);
  1549. if (fb == fbdev_fb)
  1550. continue;
  1551. seq_printf(m, "user size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
  1552. fb->base.width,
  1553. fb->base.height,
  1554. fb->base.format->depth,
  1555. fb->base.format->cpp[0] * 8,
  1556. fb->base.modifier,
  1557. drm_framebuffer_read_refcount(&fb->base));
  1558. describe_obj(m, fb->obj);
  1559. seq_putc(m, '\n');
  1560. }
  1561. mutex_unlock(&dev->mode_config.fb_lock);
  1562. mutex_unlock(&dev->struct_mutex);
  1563. return 0;
  1564. }
  1565. static void describe_ctx_ring(struct seq_file *m, struct intel_ring *ring)
  1566. {
  1567. seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u)",
  1568. ring->space, ring->head, ring->tail);
  1569. }
  1570. static int i915_context_status(struct seq_file *m, void *unused)
  1571. {
  1572. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1573. struct drm_device *dev = &dev_priv->drm;
  1574. struct intel_engine_cs *engine;
  1575. struct i915_gem_context *ctx;
  1576. enum intel_engine_id id;
  1577. int ret;
  1578. ret = mutex_lock_interruptible(&dev->struct_mutex);
  1579. if (ret)
  1580. return ret;
  1581. list_for_each_entry(ctx, &dev_priv->contexts.list, link) {
  1582. seq_printf(m, "HW context %u ", ctx->hw_id);
  1583. if (ctx->pid) {
  1584. struct task_struct *task;
  1585. task = get_pid_task(ctx->pid, PIDTYPE_PID);
  1586. if (task) {
  1587. seq_printf(m, "(%s [%d]) ",
  1588. task->comm, task->pid);
  1589. put_task_struct(task);
  1590. }
  1591. } else if (IS_ERR(ctx->file_priv)) {
  1592. seq_puts(m, "(deleted) ");
  1593. } else {
  1594. seq_puts(m, "(kernel) ");
  1595. }
  1596. seq_putc(m, ctx->remap_slice ? 'R' : 'r');
  1597. seq_putc(m, '\n');
  1598. for_each_engine(engine, dev_priv, id) {
  1599. struct intel_context *ce = &ctx->engine[engine->id];
  1600. seq_printf(m, "%s: ", engine->name);
  1601. if (ce->state)
  1602. describe_obj(m, ce->state->obj);
  1603. if (ce->ring)
  1604. describe_ctx_ring(m, ce->ring);
  1605. seq_putc(m, '\n');
  1606. }
  1607. seq_putc(m, '\n');
  1608. }
  1609. mutex_unlock(&dev->struct_mutex);
  1610. return 0;
  1611. }
  1612. static const char *swizzle_string(unsigned swizzle)
  1613. {
  1614. switch (swizzle) {
  1615. case I915_BIT_6_SWIZZLE_NONE:
  1616. return "none";
  1617. case I915_BIT_6_SWIZZLE_9:
  1618. return "bit9";
  1619. case I915_BIT_6_SWIZZLE_9_10:
  1620. return "bit9/bit10";
  1621. case I915_BIT_6_SWIZZLE_9_11:
  1622. return "bit9/bit11";
  1623. case I915_BIT_6_SWIZZLE_9_10_11:
  1624. return "bit9/bit10/bit11";
  1625. case I915_BIT_6_SWIZZLE_9_17:
  1626. return "bit9/bit17";
  1627. case I915_BIT_6_SWIZZLE_9_10_17:
  1628. return "bit9/bit10/bit17";
  1629. case I915_BIT_6_SWIZZLE_UNKNOWN:
  1630. return "unknown";
  1631. }
  1632. return "bug";
  1633. }
  1634. static int i915_swizzle_info(struct seq_file *m, void *data)
  1635. {
  1636. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1637. intel_runtime_pm_get(dev_priv);
  1638. seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
  1639. swizzle_string(dev_priv->mm.bit_6_swizzle_x));
  1640. seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
  1641. swizzle_string(dev_priv->mm.bit_6_swizzle_y));
  1642. if (IS_GEN3(dev_priv) || IS_GEN4(dev_priv)) {
  1643. seq_printf(m, "DDC = 0x%08x\n",
  1644. I915_READ(DCC));
  1645. seq_printf(m, "DDC2 = 0x%08x\n",
  1646. I915_READ(DCC2));
  1647. seq_printf(m, "C0DRB3 = 0x%04x\n",
  1648. I915_READ16(C0DRB3));
  1649. seq_printf(m, "C1DRB3 = 0x%04x\n",
  1650. I915_READ16(C1DRB3));
  1651. } else if (INTEL_GEN(dev_priv) >= 6) {
  1652. seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
  1653. I915_READ(MAD_DIMM_C0));
  1654. seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
  1655. I915_READ(MAD_DIMM_C1));
  1656. seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
  1657. I915_READ(MAD_DIMM_C2));
  1658. seq_printf(m, "TILECTL = 0x%08x\n",
  1659. I915_READ(TILECTL));
  1660. if (INTEL_GEN(dev_priv) >= 8)
  1661. seq_printf(m, "GAMTARBMODE = 0x%08x\n",
  1662. I915_READ(GAMTARBMODE));
  1663. else
  1664. seq_printf(m, "ARB_MODE = 0x%08x\n",
  1665. I915_READ(ARB_MODE));
  1666. seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
  1667. I915_READ(DISP_ARB_CTL));
  1668. }
  1669. if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
  1670. seq_puts(m, "L-shaped memory detected\n");
  1671. intel_runtime_pm_put(dev_priv);
  1672. return 0;
  1673. }
  1674. static int per_file_ctx(int id, void *ptr, void *data)
  1675. {
  1676. struct i915_gem_context *ctx = ptr;
  1677. struct seq_file *m = data;
  1678. struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
  1679. if (!ppgtt) {
  1680. seq_printf(m, " no ppgtt for context %d\n",
  1681. ctx->user_handle);
  1682. return 0;
  1683. }
  1684. if (i915_gem_context_is_default(ctx))
  1685. seq_puts(m, " default context:\n");
  1686. else
  1687. seq_printf(m, " context %d:\n", ctx->user_handle);
  1688. ppgtt->debug_dump(ppgtt, m);
  1689. return 0;
  1690. }
  1691. static void gen8_ppgtt_info(struct seq_file *m,
  1692. struct drm_i915_private *dev_priv)
  1693. {
  1694. struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
  1695. struct intel_engine_cs *engine;
  1696. enum intel_engine_id id;
  1697. int i;
  1698. if (!ppgtt)
  1699. return;
  1700. for_each_engine(engine, dev_priv, id) {
  1701. seq_printf(m, "%s\n", engine->name);
  1702. for (i = 0; i < 4; i++) {
  1703. u64 pdp = I915_READ(GEN8_RING_PDP_UDW(engine, i));
  1704. pdp <<= 32;
  1705. pdp |= I915_READ(GEN8_RING_PDP_LDW(engine, i));
  1706. seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
  1707. }
  1708. }
  1709. }
  1710. static void gen6_ppgtt_info(struct seq_file *m,
  1711. struct drm_i915_private *dev_priv)
  1712. {
  1713. struct intel_engine_cs *engine;
  1714. enum intel_engine_id id;
  1715. if (IS_GEN6(dev_priv))
  1716. seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
  1717. for_each_engine(engine, dev_priv, id) {
  1718. seq_printf(m, "%s\n", engine->name);
  1719. if (IS_GEN7(dev_priv))
  1720. seq_printf(m, "GFX_MODE: 0x%08x\n",
  1721. I915_READ(RING_MODE_GEN7(engine)));
  1722. seq_printf(m, "PP_DIR_BASE: 0x%08x\n",
  1723. I915_READ(RING_PP_DIR_BASE(engine)));
  1724. seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n",
  1725. I915_READ(RING_PP_DIR_BASE_READ(engine)));
  1726. seq_printf(m, "PP_DIR_DCLV: 0x%08x\n",
  1727. I915_READ(RING_PP_DIR_DCLV(engine)));
  1728. }
  1729. if (dev_priv->mm.aliasing_ppgtt) {
  1730. struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
  1731. seq_puts(m, "aliasing PPGTT:\n");
  1732. seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.base.ggtt_offset);
  1733. ppgtt->debug_dump(ppgtt, m);
  1734. }
  1735. seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
  1736. }
  1737. static int i915_ppgtt_info(struct seq_file *m, void *data)
  1738. {
  1739. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1740. struct drm_device *dev = &dev_priv->drm;
  1741. struct drm_file *file;
  1742. int ret;
  1743. mutex_lock(&dev->filelist_mutex);
  1744. ret = mutex_lock_interruptible(&dev->struct_mutex);
  1745. if (ret)
  1746. goto out_unlock;
  1747. intel_runtime_pm_get(dev_priv);
  1748. if (INTEL_GEN(dev_priv) >= 8)
  1749. gen8_ppgtt_info(m, dev_priv);
  1750. else if (INTEL_GEN(dev_priv) >= 6)
  1751. gen6_ppgtt_info(m, dev_priv);
  1752. list_for_each_entry_reverse(file, &dev->filelist, lhead) {
  1753. struct drm_i915_file_private *file_priv = file->driver_priv;
  1754. struct task_struct *task;
  1755. task = get_pid_task(file->pid, PIDTYPE_PID);
  1756. if (!task) {
  1757. ret = -ESRCH;
  1758. goto out_rpm;
  1759. }
  1760. seq_printf(m, "\nproc: %s\n", task->comm);
  1761. put_task_struct(task);
  1762. idr_for_each(&file_priv->context_idr, per_file_ctx,
  1763. (void *)(unsigned long)m);
  1764. }
  1765. out_rpm:
  1766. intel_runtime_pm_put(dev_priv);
  1767. mutex_unlock(&dev->struct_mutex);
  1768. out_unlock:
  1769. mutex_unlock(&dev->filelist_mutex);
  1770. return ret;
  1771. }
  1772. static int count_irq_waiters(struct drm_i915_private *i915)
  1773. {
  1774. struct intel_engine_cs *engine;
  1775. enum intel_engine_id id;
  1776. int count = 0;
  1777. for_each_engine(engine, i915, id)
  1778. count += intel_engine_has_waiter(engine);
  1779. return count;
  1780. }
  1781. static const char *rps_power_to_str(unsigned int power)
  1782. {
  1783. static const char * const strings[] = {
  1784. [LOW_POWER] = "low power",
  1785. [BETWEEN] = "mixed",
  1786. [HIGH_POWER] = "high power",
  1787. };
  1788. if (power >= ARRAY_SIZE(strings) || !strings[power])
  1789. return "unknown";
  1790. return strings[power];
  1791. }
  1792. static int i915_rps_boost_info(struct seq_file *m, void *data)
  1793. {
  1794. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1795. struct drm_device *dev = &dev_priv->drm;
  1796. struct intel_rps *rps = &dev_priv->gt_pm.rps;
  1797. struct drm_file *file;
  1798. seq_printf(m, "RPS enabled? %d\n", rps->enabled);
  1799. seq_printf(m, "GPU busy? %s [%d requests]\n",
  1800. yesno(dev_priv->gt.awake), dev_priv->gt.active_requests);
  1801. seq_printf(m, "CPU waiting? %d\n", count_irq_waiters(dev_priv));
  1802. seq_printf(m, "Boosts outstanding? %d\n",
  1803. atomic_read(&rps->num_waiters));
  1804. seq_printf(m, "Frequency requested %d\n",
  1805. intel_gpu_freq(dev_priv, rps->cur_freq));
  1806. seq_printf(m, " min hard:%d, soft:%d; max soft:%d, hard:%d\n",
  1807. intel_gpu_freq(dev_priv, rps->min_freq),
  1808. intel_gpu_freq(dev_priv, rps->min_freq_softlimit),
  1809. intel_gpu_freq(dev_priv, rps->max_freq_softlimit),
  1810. intel_gpu_freq(dev_priv, rps->max_freq));
  1811. seq_printf(m, " idle:%d, efficient:%d, boost:%d\n",
  1812. intel_gpu_freq(dev_priv, rps->idle_freq),
  1813. intel_gpu_freq(dev_priv, rps->efficient_freq),
  1814. intel_gpu_freq(dev_priv, rps->boost_freq));
  1815. mutex_lock(&dev->filelist_mutex);
  1816. list_for_each_entry_reverse(file, &dev->filelist, lhead) {
  1817. struct drm_i915_file_private *file_priv = file->driver_priv;
  1818. struct task_struct *task;
  1819. rcu_read_lock();
  1820. task = pid_task(file->pid, PIDTYPE_PID);
  1821. seq_printf(m, "%s [%d]: %d boosts\n",
  1822. task ? task->comm : "<unknown>",
  1823. task ? task->pid : -1,
  1824. atomic_read(&file_priv->rps_client.boosts));
  1825. rcu_read_unlock();
  1826. }
  1827. seq_printf(m, "Kernel (anonymous) boosts: %d\n",
  1828. atomic_read(&rps->boosts));
  1829. mutex_unlock(&dev->filelist_mutex);
  1830. if (INTEL_GEN(dev_priv) >= 6 &&
  1831. rps->enabled &&
  1832. dev_priv->gt.active_requests) {
  1833. u32 rpup, rpupei;
  1834. u32 rpdown, rpdownei;
  1835. intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
  1836. rpup = I915_READ_FW(GEN6_RP_CUR_UP) & GEN6_RP_EI_MASK;
  1837. rpupei = I915_READ_FW(GEN6_RP_CUR_UP_EI) & GEN6_RP_EI_MASK;
  1838. rpdown = I915_READ_FW(GEN6_RP_CUR_DOWN) & GEN6_RP_EI_MASK;
  1839. rpdownei = I915_READ_FW(GEN6_RP_CUR_DOWN_EI) & GEN6_RP_EI_MASK;
  1840. intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
  1841. seq_printf(m, "\nRPS Autotuning (current \"%s\" window):\n",
  1842. rps_power_to_str(rps->power));
  1843. seq_printf(m, " Avg. up: %d%% [above threshold? %d%%]\n",
  1844. rpup && rpupei ? 100 * rpup / rpupei : 0,
  1845. rps->up_threshold);
  1846. seq_printf(m, " Avg. down: %d%% [below threshold? %d%%]\n",
  1847. rpdown && rpdownei ? 100 * rpdown / rpdownei : 0,
  1848. rps->down_threshold);
  1849. } else {
  1850. seq_puts(m, "\nRPS Autotuning inactive\n");
  1851. }
  1852. return 0;
  1853. }
  1854. static int i915_llc(struct seq_file *m, void *data)
  1855. {
  1856. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1857. const bool edram = INTEL_GEN(dev_priv) > 8;
  1858. seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev_priv)));
  1859. seq_printf(m, "%s: %lluMB\n", edram ? "eDRAM" : "eLLC",
  1860. intel_uncore_edram_size(dev_priv)/1024/1024);
  1861. return 0;
  1862. }
  1863. static int i915_huc_load_status_info(struct seq_file *m, void *data)
  1864. {
  1865. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1866. struct drm_printer p;
  1867. if (!HAS_HUC(dev_priv))
  1868. return -ENODEV;
  1869. p = drm_seq_file_printer(m);
  1870. intel_uc_fw_dump(&dev_priv->huc.fw, &p);
  1871. intel_runtime_pm_get(dev_priv);
  1872. seq_printf(m, "\nHuC status 0x%08x:\n", I915_READ(HUC_STATUS2));
  1873. intel_runtime_pm_put(dev_priv);
  1874. return 0;
  1875. }
  1876. static int i915_guc_load_status_info(struct seq_file *m, void *data)
  1877. {
  1878. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1879. struct drm_printer p;
  1880. u32 tmp, i;
  1881. if (!HAS_GUC(dev_priv))
  1882. return -ENODEV;
  1883. p = drm_seq_file_printer(m);
  1884. intel_uc_fw_dump(&dev_priv->guc.fw, &p);
  1885. intel_runtime_pm_get(dev_priv);
  1886. tmp = I915_READ(GUC_STATUS);
  1887. seq_printf(m, "\nGuC status 0x%08x:\n", tmp);
  1888. seq_printf(m, "\tBootrom status = 0x%x\n",
  1889. (tmp & GS_BOOTROM_MASK) >> GS_BOOTROM_SHIFT);
  1890. seq_printf(m, "\tuKernel status = 0x%x\n",
  1891. (tmp & GS_UKERNEL_MASK) >> GS_UKERNEL_SHIFT);
  1892. seq_printf(m, "\tMIA Core status = 0x%x\n",
  1893. (tmp & GS_MIA_MASK) >> GS_MIA_SHIFT);
  1894. seq_puts(m, "\nScratch registers:\n");
  1895. for (i = 0; i < 16; i++)
  1896. seq_printf(m, "\t%2d: \t0x%x\n", i, I915_READ(SOFT_SCRATCH(i)));
  1897. intel_runtime_pm_put(dev_priv);
  1898. return 0;
  1899. }
  1900. static void i915_guc_log_info(struct seq_file *m,
  1901. struct drm_i915_private *dev_priv)
  1902. {
  1903. struct intel_guc *guc = &dev_priv->guc;
  1904. seq_puts(m, "\nGuC logging stats:\n");
  1905. seq_printf(m, "\tISR: flush count %10u, overflow count %10u\n",
  1906. guc->log.flush_count[GUC_ISR_LOG_BUFFER],
  1907. guc->log.total_overflow_count[GUC_ISR_LOG_BUFFER]);
  1908. seq_printf(m, "\tDPC: flush count %10u, overflow count %10u\n",
  1909. guc->log.flush_count[GUC_DPC_LOG_BUFFER],
  1910. guc->log.total_overflow_count[GUC_DPC_LOG_BUFFER]);
  1911. seq_printf(m, "\tCRASH: flush count %10u, overflow count %10u\n",
  1912. guc->log.flush_count[GUC_CRASH_DUMP_LOG_BUFFER],
  1913. guc->log.total_overflow_count[GUC_CRASH_DUMP_LOG_BUFFER]);
  1914. seq_printf(m, "\tTotal flush interrupt count: %u\n",
  1915. guc->log.flush_interrupt_count);
  1916. seq_printf(m, "\tCapture miss count: %u\n",
  1917. guc->log.capture_miss_count);
  1918. }
  1919. static void i915_guc_client_info(struct seq_file *m,
  1920. struct drm_i915_private *dev_priv,
  1921. struct intel_guc_client *client)
  1922. {
  1923. struct intel_engine_cs *engine;
  1924. enum intel_engine_id id;
  1925. uint64_t tot = 0;
  1926. seq_printf(m, "\tPriority %d, GuC stage index: %u, PD offset 0x%x\n",
  1927. client->priority, client->stage_id, client->proc_desc_offset);
  1928. seq_printf(m, "\tDoorbell id %d, offset: 0x%lx\n",
  1929. client->doorbell_id, client->doorbell_offset);
  1930. for_each_engine(engine, dev_priv, id) {
  1931. u64 submissions = client->submissions[id];
  1932. tot += submissions;
  1933. seq_printf(m, "\tSubmissions: %llu %s\n",
  1934. submissions, engine->name);
  1935. }
  1936. seq_printf(m, "\tTotal: %llu\n", tot);
  1937. }
  1938. static int i915_guc_info(struct seq_file *m, void *data)
  1939. {
  1940. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1941. const struct intel_guc *guc = &dev_priv->guc;
  1942. if (!USES_GUC_SUBMISSION(dev_priv))
  1943. return -ENODEV;
  1944. GEM_BUG_ON(!guc->execbuf_client);
  1945. GEM_BUG_ON(!guc->preempt_client);
  1946. seq_printf(m, "Doorbell map:\n");
  1947. seq_printf(m, "\t%*pb\n", GUC_NUM_DOORBELLS, guc->doorbell_bitmap);
  1948. seq_printf(m, "Doorbell next cacheline: 0x%x\n\n", guc->db_cacheline);
  1949. seq_printf(m, "\nGuC execbuf client @ %p:\n", guc->execbuf_client);
  1950. i915_guc_client_info(m, dev_priv, guc->execbuf_client);
  1951. seq_printf(m, "\nGuC preempt client @ %p:\n", guc->preempt_client);
  1952. i915_guc_client_info(m, dev_priv, guc->preempt_client);
  1953. i915_guc_log_info(m, dev_priv);
  1954. /* Add more as required ... */
  1955. return 0;
  1956. }
  1957. static int i915_guc_stage_pool(struct seq_file *m, void *data)
  1958. {
  1959. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1960. const struct intel_guc *guc = &dev_priv->guc;
  1961. struct guc_stage_desc *desc = guc->stage_desc_pool_vaddr;
  1962. struct intel_guc_client *client = guc->execbuf_client;
  1963. unsigned int tmp;
  1964. int index;
  1965. if (!USES_GUC_SUBMISSION(dev_priv))
  1966. return -ENODEV;
  1967. for (index = 0; index < GUC_MAX_STAGE_DESCRIPTORS; index++, desc++) {
  1968. struct intel_engine_cs *engine;
  1969. if (!(desc->attribute & GUC_STAGE_DESC_ATTR_ACTIVE))
  1970. continue;
  1971. seq_printf(m, "GuC stage descriptor %u:\n", index);
  1972. seq_printf(m, "\tIndex: %u\n", desc->stage_id);
  1973. seq_printf(m, "\tAttribute: 0x%x\n", desc->attribute);
  1974. seq_printf(m, "\tPriority: %d\n", desc->priority);
  1975. seq_printf(m, "\tDoorbell id: %d\n", desc->db_id);
  1976. seq_printf(m, "\tEngines used: 0x%x\n",
  1977. desc->engines_used);
  1978. seq_printf(m, "\tDoorbell trigger phy: 0x%llx, cpu: 0x%llx, uK: 0x%x\n",
  1979. desc->db_trigger_phy,
  1980. desc->db_trigger_cpu,
  1981. desc->db_trigger_uk);
  1982. seq_printf(m, "\tProcess descriptor: 0x%x\n",
  1983. desc->process_desc);
  1984. seq_printf(m, "\tWorkqueue address: 0x%x, size: 0x%x\n",
  1985. desc->wq_addr, desc->wq_size);
  1986. seq_putc(m, '\n');
  1987. for_each_engine_masked(engine, dev_priv, client->engines, tmp) {
  1988. u32 guc_engine_id = engine->guc_id;
  1989. struct guc_execlist_context *lrc =
  1990. &desc->lrc[guc_engine_id];
  1991. seq_printf(m, "\t%s LRC:\n", engine->name);
  1992. seq_printf(m, "\t\tContext desc: 0x%x\n",
  1993. lrc->context_desc);
  1994. seq_printf(m, "\t\tContext id: 0x%x\n", lrc->context_id);
  1995. seq_printf(m, "\t\tLRCA: 0x%x\n", lrc->ring_lrca);
  1996. seq_printf(m, "\t\tRing begin: 0x%x\n", lrc->ring_begin);
  1997. seq_printf(m, "\t\tRing end: 0x%x\n", lrc->ring_end);
  1998. seq_putc(m, '\n');
  1999. }
  2000. }
  2001. return 0;
  2002. }
  2003. static int i915_guc_log_dump(struct seq_file *m, void *data)
  2004. {
  2005. struct drm_info_node *node = m->private;
  2006. struct drm_i915_private *dev_priv = node_to_i915(node);
  2007. bool dump_load_err = !!node->info_ent->data;
  2008. struct drm_i915_gem_object *obj = NULL;
  2009. u32 *log;
  2010. int i = 0;
  2011. if (!HAS_GUC(dev_priv))
  2012. return -ENODEV;
  2013. if (dump_load_err)
  2014. obj = dev_priv->guc.load_err_log;
  2015. else if (dev_priv->guc.log.vma)
  2016. obj = dev_priv->guc.log.vma->obj;
  2017. if (!obj)
  2018. return 0;
  2019. log = i915_gem_object_pin_map(obj, I915_MAP_WC);
  2020. if (IS_ERR(log)) {
  2021. DRM_DEBUG("Failed to pin object\n");
  2022. seq_puts(m, "(log data unaccessible)\n");
  2023. return PTR_ERR(log);
  2024. }
  2025. for (i = 0; i < obj->base.size / sizeof(u32); i += 4)
  2026. seq_printf(m, "0x%08x 0x%08x 0x%08x 0x%08x\n",
  2027. *(log + i), *(log + i + 1),
  2028. *(log + i + 2), *(log + i + 3));
  2029. seq_putc(m, '\n');
  2030. i915_gem_object_unpin_map(obj);
  2031. return 0;
  2032. }
  2033. static int i915_guc_log_control_get(void *data, u64 *val)
  2034. {
  2035. struct drm_i915_private *dev_priv = data;
  2036. if (!HAS_GUC(dev_priv))
  2037. return -ENODEV;
  2038. if (!dev_priv->guc.log.vma)
  2039. return -EINVAL;
  2040. *val = i915_modparams.guc_log_level;
  2041. return 0;
  2042. }
  2043. static int i915_guc_log_control_set(void *data, u64 val)
  2044. {
  2045. struct drm_i915_private *dev_priv = data;
  2046. int ret;
  2047. if (!HAS_GUC(dev_priv))
  2048. return -ENODEV;
  2049. if (!dev_priv->guc.log.vma)
  2050. return -EINVAL;
  2051. ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
  2052. if (ret)
  2053. return ret;
  2054. intel_runtime_pm_get(dev_priv);
  2055. ret = i915_guc_log_control(dev_priv, val);
  2056. intel_runtime_pm_put(dev_priv);
  2057. mutex_unlock(&dev_priv->drm.struct_mutex);
  2058. return ret;
  2059. }
  2060. DEFINE_SIMPLE_ATTRIBUTE(i915_guc_log_control_fops,
  2061. i915_guc_log_control_get, i915_guc_log_control_set,
  2062. "%lld\n");
  2063. static const char *psr2_live_status(u32 val)
  2064. {
  2065. static const char * const live_status[] = {
  2066. "IDLE",
  2067. "CAPTURE",
  2068. "CAPTURE_FS",
  2069. "SLEEP",
  2070. "BUFON_FW",
  2071. "ML_UP",
  2072. "SU_STANDBY",
  2073. "FAST_SLEEP",
  2074. "DEEP_SLEEP",
  2075. "BUF_ON",
  2076. "TG_ON"
  2077. };
  2078. val = (val & EDP_PSR2_STATUS_STATE_MASK) >> EDP_PSR2_STATUS_STATE_SHIFT;
  2079. if (val < ARRAY_SIZE(live_status))
  2080. return live_status[val];
  2081. return "unknown";
  2082. }
  2083. static int i915_edp_psr_status(struct seq_file *m, void *data)
  2084. {
  2085. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  2086. u32 psrperf = 0;
  2087. u32 stat[3];
  2088. enum pipe pipe;
  2089. bool enabled = false;
  2090. if (!HAS_PSR(dev_priv))
  2091. return -ENODEV;
  2092. intel_runtime_pm_get(dev_priv);
  2093. mutex_lock(&dev_priv->psr.lock);
  2094. seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
  2095. seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
  2096. seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
  2097. seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
  2098. seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
  2099. dev_priv->psr.busy_frontbuffer_bits);
  2100. seq_printf(m, "Re-enable work scheduled: %s\n",
  2101. yesno(work_busy(&dev_priv->psr.work.work)));
  2102. if (HAS_DDI(dev_priv)) {
  2103. if (dev_priv->psr.psr2_support)
  2104. enabled = I915_READ(EDP_PSR2_CTL) & EDP_PSR2_ENABLE;
  2105. else
  2106. enabled = I915_READ(EDP_PSR_CTL) & EDP_PSR_ENABLE;
  2107. } else {
  2108. for_each_pipe(dev_priv, pipe) {
  2109. enum transcoder cpu_transcoder =
  2110. intel_pipe_to_cpu_transcoder(dev_priv, pipe);
  2111. enum intel_display_power_domain power_domain;
  2112. power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
  2113. if (!intel_display_power_get_if_enabled(dev_priv,
  2114. power_domain))
  2115. continue;
  2116. stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
  2117. VLV_EDP_PSR_CURR_STATE_MASK;
  2118. if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
  2119. (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
  2120. enabled = true;
  2121. intel_display_power_put(dev_priv, power_domain);
  2122. }
  2123. }
  2124. seq_printf(m, "Main link in standby mode: %s\n",
  2125. yesno(dev_priv->psr.link_standby));
  2126. seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
  2127. if (!HAS_DDI(dev_priv))
  2128. for_each_pipe(dev_priv, pipe) {
  2129. if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
  2130. (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
  2131. seq_printf(m, " pipe %c", pipe_name(pipe));
  2132. }
  2133. seq_puts(m, "\n");
  2134. /*
  2135. * VLV/CHV PSR has no kind of performance counter
  2136. * SKL+ Perf counter is reset to 0 everytime DC state is entered
  2137. */
  2138. if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
  2139. psrperf = I915_READ(EDP_PSR_PERF_CNT) &
  2140. EDP_PSR_PERF_CNT_MASK;
  2141. seq_printf(m, "Performance_Counter: %u\n", psrperf);
  2142. }
  2143. if (dev_priv->psr.psr2_support) {
  2144. u32 psr2 = I915_READ(EDP_PSR2_STATUS_CTL);
  2145. seq_printf(m, "EDP_PSR2_STATUS_CTL: %x [%s]\n",
  2146. psr2, psr2_live_status(psr2));
  2147. }
  2148. mutex_unlock(&dev_priv->psr.lock);
  2149. intel_runtime_pm_put(dev_priv);
  2150. return 0;
  2151. }
  2152. static int i915_sink_crc(struct seq_file *m, void *data)
  2153. {
  2154. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  2155. struct drm_device *dev = &dev_priv->drm;
  2156. struct intel_connector *connector;
  2157. struct drm_connector_list_iter conn_iter;
  2158. struct intel_dp *intel_dp = NULL;
  2159. struct drm_modeset_acquire_ctx ctx;
  2160. int ret;
  2161. u8 crc[6];
  2162. drm_modeset_acquire_init(&ctx, DRM_MODESET_ACQUIRE_INTERRUPTIBLE);
  2163. drm_connector_list_iter_begin(dev, &conn_iter);
  2164. for_each_intel_connector_iter(connector, &conn_iter) {
  2165. struct drm_crtc *crtc;
  2166. struct drm_connector_state *state;
  2167. struct intel_crtc_state *crtc_state;
  2168. if (connector->base.connector_type != DRM_MODE_CONNECTOR_eDP)
  2169. continue;
  2170. retry:
  2171. ret = drm_modeset_lock(&dev->mode_config.connection_mutex, &ctx);
  2172. if (ret)
  2173. goto err;
  2174. state = connector->base.state;
  2175. if (!state->best_encoder)
  2176. continue;
  2177. crtc = state->crtc;
  2178. ret = drm_modeset_lock(&crtc->mutex, &ctx);
  2179. if (ret)
  2180. goto err;
  2181. crtc_state = to_intel_crtc_state(crtc->state);
  2182. if (!crtc_state->base.active)
  2183. continue;
  2184. /*
  2185. * We need to wait for all crtc updates to complete, to make
  2186. * sure any pending modesets and plane updates are completed.
  2187. */
  2188. if (crtc_state->base.commit) {
  2189. ret = wait_for_completion_interruptible(&crtc_state->base.commit->hw_done);
  2190. if (ret)
  2191. goto err;
  2192. }
  2193. intel_dp = enc_to_intel_dp(state->best_encoder);
  2194. ret = intel_dp_sink_crc(intel_dp, crtc_state, crc);
  2195. if (ret)
  2196. goto err;
  2197. seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
  2198. crc[0], crc[1], crc[2],
  2199. crc[3], crc[4], crc[5]);
  2200. goto out;
  2201. err:
  2202. if (ret == -EDEADLK) {
  2203. ret = drm_modeset_backoff(&ctx);
  2204. if (!ret)
  2205. goto retry;
  2206. }
  2207. goto out;
  2208. }
  2209. ret = -ENODEV;
  2210. out:
  2211. drm_connector_list_iter_end(&conn_iter);
  2212. drm_modeset_drop_locks(&ctx);
  2213. drm_modeset_acquire_fini(&ctx);
  2214. return ret;
  2215. }
  2216. static int i915_energy_uJ(struct seq_file *m, void *data)
  2217. {
  2218. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  2219. unsigned long long power;
  2220. u32 units;
  2221. if (INTEL_GEN(dev_priv) < 6)
  2222. return -ENODEV;
  2223. intel_runtime_pm_get(dev_priv);
  2224. if (rdmsrl_safe(MSR_RAPL_POWER_UNIT, &power)) {
  2225. intel_runtime_pm_put(dev_priv);
  2226. return -ENODEV;
  2227. }
  2228. units = (power & 0x1f00) >> 8;
  2229. power = I915_READ(MCH_SECP_NRG_STTS);
  2230. power = (1000000 * power) >> units; /* convert to uJ */
  2231. intel_runtime_pm_put(dev_priv);
  2232. seq_printf(m, "%llu", power);
  2233. return 0;
  2234. }
  2235. static int i915_runtime_pm_status(struct seq_file *m, void *unused)
  2236. {
  2237. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  2238. struct pci_dev *pdev = dev_priv->drm.pdev;
  2239. if (!HAS_RUNTIME_PM(dev_priv))
  2240. seq_puts(m, "Runtime power management not supported\n");
  2241. seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->gt.awake));
  2242. seq_printf(m, "IRQs disabled: %s\n",
  2243. yesno(!intel_irqs_enabled(dev_priv)));
  2244. #ifdef CONFIG_PM
  2245. seq_printf(m, "Usage count: %d\n",
  2246. atomic_read(&dev_priv->drm.dev->power.usage_count));
  2247. #else
  2248. seq_printf(m, "Device Power Management (CONFIG_PM) disabled\n");
  2249. #endif
  2250. seq_printf(m, "PCI device power state: %s [%d]\n",
  2251. pci_power_name(pdev->current_state),
  2252. pdev->current_state);
  2253. return 0;
  2254. }
  2255. static int i915_power_domain_info(struct seq_file *m, void *unused)
  2256. {
  2257. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  2258. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  2259. int i;
  2260. mutex_lock(&power_domains->lock);
  2261. seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
  2262. for (i = 0; i < power_domains->power_well_count; i++) {
  2263. struct i915_power_well *power_well;
  2264. enum intel_display_power_domain power_domain;
  2265. power_well = &power_domains->power_wells[i];
  2266. seq_printf(m, "%-25s %d\n", power_well->name,
  2267. power_well->count);
  2268. for_each_power_domain(power_domain, power_well->domains)
  2269. seq_printf(m, " %-23s %d\n",
  2270. intel_display_power_domain_str(power_domain),
  2271. power_domains->domain_use_count[power_domain]);
  2272. }
  2273. mutex_unlock(&power_domains->lock);
  2274. return 0;
  2275. }
  2276. static int i915_dmc_info(struct seq_file *m, void *unused)
  2277. {
  2278. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  2279. struct intel_csr *csr;
  2280. if (!HAS_CSR(dev_priv))
  2281. return -ENODEV;
  2282. csr = &dev_priv->csr;
  2283. intel_runtime_pm_get(dev_priv);
  2284. seq_printf(m, "fw loaded: %s\n", yesno(csr->dmc_payload != NULL));
  2285. seq_printf(m, "path: %s\n", csr->fw_path);
  2286. if (!csr->dmc_payload)
  2287. goto out;
  2288. seq_printf(m, "version: %d.%d\n", CSR_VERSION_MAJOR(csr->version),
  2289. CSR_VERSION_MINOR(csr->version));
  2290. if (IS_KABYLAKE(dev_priv) ||
  2291. (IS_SKYLAKE(dev_priv) && csr->version >= CSR_VERSION(1, 6))) {
  2292. seq_printf(m, "DC3 -> DC5 count: %d\n",
  2293. I915_READ(SKL_CSR_DC3_DC5_COUNT));
  2294. seq_printf(m, "DC5 -> DC6 count: %d\n",
  2295. I915_READ(SKL_CSR_DC5_DC6_COUNT));
  2296. } else if (IS_BROXTON(dev_priv) && csr->version >= CSR_VERSION(1, 4)) {
  2297. seq_printf(m, "DC3 -> DC5 count: %d\n",
  2298. I915_READ(BXT_CSR_DC3_DC5_COUNT));
  2299. }
  2300. out:
  2301. seq_printf(m, "program base: 0x%08x\n", I915_READ(CSR_PROGRAM(0)));
  2302. seq_printf(m, "ssp base: 0x%08x\n", I915_READ(CSR_SSP_BASE));
  2303. seq_printf(m, "htp: 0x%08x\n", I915_READ(CSR_HTP_SKL));
  2304. intel_runtime_pm_put(dev_priv);
  2305. return 0;
  2306. }
  2307. static void intel_seq_print_mode(struct seq_file *m, int tabs,
  2308. struct drm_display_mode *mode)
  2309. {
  2310. int i;
  2311. for (i = 0; i < tabs; i++)
  2312. seq_putc(m, '\t');
  2313. seq_printf(m, "id %d:\"%s\" freq %d clock %d hdisp %d hss %d hse %d htot %d vdisp %d vss %d vse %d vtot %d type 0x%x flags 0x%x\n",
  2314. mode->base.id, mode->name,
  2315. mode->vrefresh, mode->clock,
  2316. mode->hdisplay, mode->hsync_start,
  2317. mode->hsync_end, mode->htotal,
  2318. mode->vdisplay, mode->vsync_start,
  2319. mode->vsync_end, mode->vtotal,
  2320. mode->type, mode->flags);
  2321. }
  2322. static void intel_encoder_info(struct seq_file *m,
  2323. struct intel_crtc *intel_crtc,
  2324. struct intel_encoder *intel_encoder)
  2325. {
  2326. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  2327. struct drm_device *dev = &dev_priv->drm;
  2328. struct drm_crtc *crtc = &intel_crtc->base;
  2329. struct intel_connector *intel_connector;
  2330. struct drm_encoder *encoder;
  2331. encoder = &intel_encoder->base;
  2332. seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
  2333. encoder->base.id, encoder->name);
  2334. for_each_connector_on_encoder(dev, encoder, intel_connector) {
  2335. struct drm_connector *connector = &intel_connector->base;
  2336. seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
  2337. connector->base.id,
  2338. connector->name,
  2339. drm_get_connector_status_name(connector->status));
  2340. if (connector->status == connector_status_connected) {
  2341. struct drm_display_mode *mode = &crtc->mode;
  2342. seq_printf(m, ", mode:\n");
  2343. intel_seq_print_mode(m, 2, mode);
  2344. } else {
  2345. seq_putc(m, '\n');
  2346. }
  2347. }
  2348. }
  2349. static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
  2350. {
  2351. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  2352. struct drm_device *dev = &dev_priv->drm;
  2353. struct drm_crtc *crtc = &intel_crtc->base;
  2354. struct intel_encoder *intel_encoder;
  2355. struct drm_plane_state *plane_state = crtc->primary->state;
  2356. struct drm_framebuffer *fb = plane_state->fb;
  2357. if (fb)
  2358. seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
  2359. fb->base.id, plane_state->src_x >> 16,
  2360. plane_state->src_y >> 16, fb->width, fb->height);
  2361. else
  2362. seq_puts(m, "\tprimary plane disabled\n");
  2363. for_each_encoder_on_crtc(dev, crtc, intel_encoder)
  2364. intel_encoder_info(m, intel_crtc, intel_encoder);
  2365. }
  2366. static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
  2367. {
  2368. struct drm_display_mode *mode = panel->fixed_mode;
  2369. seq_printf(m, "\tfixed mode:\n");
  2370. intel_seq_print_mode(m, 2, mode);
  2371. }
  2372. static void intel_dp_info(struct seq_file *m,
  2373. struct intel_connector *intel_connector)
  2374. {
  2375. struct intel_encoder *intel_encoder = intel_connector->encoder;
  2376. struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
  2377. seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
  2378. seq_printf(m, "\taudio support: %s\n", yesno(intel_dp->has_audio));
  2379. if (intel_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)
  2380. intel_panel_info(m, &intel_connector->panel);
  2381. drm_dp_downstream_debug(m, intel_dp->dpcd, intel_dp->downstream_ports,
  2382. &intel_dp->aux);
  2383. }
  2384. static void intel_dp_mst_info(struct seq_file *m,
  2385. struct intel_connector *intel_connector)
  2386. {
  2387. struct intel_encoder *intel_encoder = intel_connector->encoder;
  2388. struct intel_dp_mst_encoder *intel_mst =
  2389. enc_to_mst(&intel_encoder->base);
  2390. struct intel_digital_port *intel_dig_port = intel_mst->primary;
  2391. struct intel_dp *intel_dp = &intel_dig_port->dp;
  2392. bool has_audio = drm_dp_mst_port_has_audio(&intel_dp->mst_mgr,
  2393. intel_connector->port);
  2394. seq_printf(m, "\taudio support: %s\n", yesno(has_audio));
  2395. }
  2396. static void intel_hdmi_info(struct seq_file *m,
  2397. struct intel_connector *intel_connector)
  2398. {
  2399. struct intel_encoder *intel_encoder = intel_connector->encoder;
  2400. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
  2401. seq_printf(m, "\taudio support: %s\n", yesno(intel_hdmi->has_audio));
  2402. }
  2403. static void intel_lvds_info(struct seq_file *m,
  2404. struct intel_connector *intel_connector)
  2405. {
  2406. intel_panel_info(m, &intel_connector->panel);
  2407. }
  2408. static void intel_connector_info(struct seq_file *m,
  2409. struct drm_connector *connector)
  2410. {
  2411. struct intel_connector *intel_connector = to_intel_connector(connector);
  2412. struct intel_encoder *intel_encoder = intel_connector->encoder;
  2413. struct drm_display_mode *mode;
  2414. seq_printf(m, "connector %d: type %s, status: %s\n",
  2415. connector->base.id, connector->name,
  2416. drm_get_connector_status_name(connector->status));
  2417. if (connector->status == connector_status_connected) {
  2418. seq_printf(m, "\tname: %s\n", connector->display_info.name);
  2419. seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
  2420. connector->display_info.width_mm,
  2421. connector->display_info.height_mm);
  2422. seq_printf(m, "\tsubpixel order: %s\n",
  2423. drm_get_subpixel_order_name(connector->display_info.subpixel_order));
  2424. seq_printf(m, "\tCEA rev: %d\n",
  2425. connector->display_info.cea_rev);
  2426. }
  2427. if (!intel_encoder)
  2428. return;
  2429. switch (connector->connector_type) {
  2430. case DRM_MODE_CONNECTOR_DisplayPort:
  2431. case DRM_MODE_CONNECTOR_eDP:
  2432. if (intel_encoder->type == INTEL_OUTPUT_DP_MST)
  2433. intel_dp_mst_info(m, intel_connector);
  2434. else
  2435. intel_dp_info(m, intel_connector);
  2436. break;
  2437. case DRM_MODE_CONNECTOR_LVDS:
  2438. if (intel_encoder->type == INTEL_OUTPUT_LVDS)
  2439. intel_lvds_info(m, intel_connector);
  2440. break;
  2441. case DRM_MODE_CONNECTOR_HDMIA:
  2442. if (intel_encoder->type == INTEL_OUTPUT_HDMI ||
  2443. intel_encoder->type == INTEL_OUTPUT_DDI)
  2444. intel_hdmi_info(m, intel_connector);
  2445. break;
  2446. default:
  2447. break;
  2448. }
  2449. seq_printf(m, "\tmodes:\n");
  2450. list_for_each_entry(mode, &connector->modes, head)
  2451. intel_seq_print_mode(m, 2, mode);
  2452. }
  2453. static const char *plane_type(enum drm_plane_type type)
  2454. {
  2455. switch (type) {
  2456. case DRM_PLANE_TYPE_OVERLAY:
  2457. return "OVL";
  2458. case DRM_PLANE_TYPE_PRIMARY:
  2459. return "PRI";
  2460. case DRM_PLANE_TYPE_CURSOR:
  2461. return "CUR";
  2462. /*
  2463. * Deliberately omitting default: to generate compiler warnings
  2464. * when a new drm_plane_type gets added.
  2465. */
  2466. }
  2467. return "unknown";
  2468. }
  2469. static const char *plane_rotation(unsigned int rotation)
  2470. {
  2471. static char buf[48];
  2472. /*
  2473. * According to doc only one DRM_MODE_ROTATE_ is allowed but this
  2474. * will print them all to visualize if the values are misused
  2475. */
  2476. snprintf(buf, sizeof(buf),
  2477. "%s%s%s%s%s%s(0x%08x)",
  2478. (rotation & DRM_MODE_ROTATE_0) ? "0 " : "",
  2479. (rotation & DRM_MODE_ROTATE_90) ? "90 " : "",
  2480. (rotation & DRM_MODE_ROTATE_180) ? "180 " : "",
  2481. (rotation & DRM_MODE_ROTATE_270) ? "270 " : "",
  2482. (rotation & DRM_MODE_REFLECT_X) ? "FLIPX " : "",
  2483. (rotation & DRM_MODE_REFLECT_Y) ? "FLIPY " : "",
  2484. rotation);
  2485. return buf;
  2486. }
  2487. static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
  2488. {
  2489. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  2490. struct drm_device *dev = &dev_priv->drm;
  2491. struct intel_plane *intel_plane;
  2492. for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
  2493. struct drm_plane_state *state;
  2494. struct drm_plane *plane = &intel_plane->base;
  2495. struct drm_format_name_buf format_name;
  2496. if (!plane->state) {
  2497. seq_puts(m, "plane->state is NULL!\n");
  2498. continue;
  2499. }
  2500. state = plane->state;
  2501. if (state->fb) {
  2502. drm_get_format_name(state->fb->format->format,
  2503. &format_name);
  2504. } else {
  2505. sprintf(format_name.str, "N/A");
  2506. }
  2507. seq_printf(m, "\t--Plane id %d: type=%s, crtc_pos=%4dx%4d, crtc_size=%4dx%4d, src_pos=%d.%04ux%d.%04u, src_size=%d.%04ux%d.%04u, format=%s, rotation=%s\n",
  2508. plane->base.id,
  2509. plane_type(intel_plane->base.type),
  2510. state->crtc_x, state->crtc_y,
  2511. state->crtc_w, state->crtc_h,
  2512. (state->src_x >> 16),
  2513. ((state->src_x & 0xffff) * 15625) >> 10,
  2514. (state->src_y >> 16),
  2515. ((state->src_y & 0xffff) * 15625) >> 10,
  2516. (state->src_w >> 16),
  2517. ((state->src_w & 0xffff) * 15625) >> 10,
  2518. (state->src_h >> 16),
  2519. ((state->src_h & 0xffff) * 15625) >> 10,
  2520. format_name.str,
  2521. plane_rotation(state->rotation));
  2522. }
  2523. }
  2524. static void intel_scaler_info(struct seq_file *m, struct intel_crtc *intel_crtc)
  2525. {
  2526. struct intel_crtc_state *pipe_config;
  2527. int num_scalers = intel_crtc->num_scalers;
  2528. int i;
  2529. pipe_config = to_intel_crtc_state(intel_crtc->base.state);
  2530. /* Not all platformas have a scaler */
  2531. if (num_scalers) {
  2532. seq_printf(m, "\tnum_scalers=%d, scaler_users=%x scaler_id=%d",
  2533. num_scalers,
  2534. pipe_config->scaler_state.scaler_users,
  2535. pipe_config->scaler_state.scaler_id);
  2536. for (i = 0; i < num_scalers; i++) {
  2537. struct intel_scaler *sc =
  2538. &pipe_config->scaler_state.scalers[i];
  2539. seq_printf(m, ", scalers[%d]: use=%s, mode=%x",
  2540. i, yesno(sc->in_use), sc->mode);
  2541. }
  2542. seq_puts(m, "\n");
  2543. } else {
  2544. seq_puts(m, "\tNo scalers available on this platform\n");
  2545. }
  2546. }
  2547. static int i915_display_info(struct seq_file *m, void *unused)
  2548. {
  2549. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  2550. struct drm_device *dev = &dev_priv->drm;
  2551. struct intel_crtc *crtc;
  2552. struct drm_connector *connector;
  2553. struct drm_connector_list_iter conn_iter;
  2554. intel_runtime_pm_get(dev_priv);
  2555. seq_printf(m, "CRTC info\n");
  2556. seq_printf(m, "---------\n");
  2557. for_each_intel_crtc(dev, crtc) {
  2558. struct intel_crtc_state *pipe_config;
  2559. drm_modeset_lock(&crtc->base.mutex, NULL);
  2560. pipe_config = to_intel_crtc_state(crtc->base.state);
  2561. seq_printf(m, "CRTC %d: pipe: %c, active=%s, (size=%dx%d), dither=%s, bpp=%d\n",
  2562. crtc->base.base.id, pipe_name(crtc->pipe),
  2563. yesno(pipe_config->base.active),
  2564. pipe_config->pipe_src_w, pipe_config->pipe_src_h,
  2565. yesno(pipe_config->dither), pipe_config->pipe_bpp);
  2566. if (pipe_config->base.active) {
  2567. struct intel_plane *cursor =
  2568. to_intel_plane(crtc->base.cursor);
  2569. intel_crtc_info(m, crtc);
  2570. seq_printf(m, "\tcursor visible? %s, position (%d, %d), size %dx%d, addr 0x%08x\n",
  2571. yesno(cursor->base.state->visible),
  2572. cursor->base.state->crtc_x,
  2573. cursor->base.state->crtc_y,
  2574. cursor->base.state->crtc_w,
  2575. cursor->base.state->crtc_h,
  2576. cursor->cursor.base);
  2577. intel_scaler_info(m, crtc);
  2578. intel_plane_info(m, crtc);
  2579. }
  2580. seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
  2581. yesno(!crtc->cpu_fifo_underrun_disabled),
  2582. yesno(!crtc->pch_fifo_underrun_disabled));
  2583. drm_modeset_unlock(&crtc->base.mutex);
  2584. }
  2585. seq_printf(m, "\n");
  2586. seq_printf(m, "Connector info\n");
  2587. seq_printf(m, "--------------\n");
  2588. mutex_lock(&dev->mode_config.mutex);
  2589. drm_connector_list_iter_begin(dev, &conn_iter);
  2590. drm_for_each_connector_iter(connector, &conn_iter)
  2591. intel_connector_info(m, connector);
  2592. drm_connector_list_iter_end(&conn_iter);
  2593. mutex_unlock(&dev->mode_config.mutex);
  2594. intel_runtime_pm_put(dev_priv);
  2595. return 0;
  2596. }
  2597. static int i915_engine_info(struct seq_file *m, void *unused)
  2598. {
  2599. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  2600. struct intel_engine_cs *engine;
  2601. enum intel_engine_id id;
  2602. struct drm_printer p;
  2603. intel_runtime_pm_get(dev_priv);
  2604. seq_printf(m, "GT awake? %s\n",
  2605. yesno(dev_priv->gt.awake));
  2606. seq_printf(m, "Global active requests: %d\n",
  2607. dev_priv->gt.active_requests);
  2608. seq_printf(m, "CS timestamp frequency: %u kHz\n",
  2609. dev_priv->info.cs_timestamp_frequency_khz);
  2610. p = drm_seq_file_printer(m);
  2611. for_each_engine(engine, dev_priv, id)
  2612. intel_engine_dump(engine, &p, "%s\n", engine->name);
  2613. intel_runtime_pm_put(dev_priv);
  2614. return 0;
  2615. }
  2616. static int i915_shrinker_info(struct seq_file *m, void *unused)
  2617. {
  2618. struct drm_i915_private *i915 = node_to_i915(m->private);
  2619. seq_printf(m, "seeks = %d\n", i915->mm.shrinker.seeks);
  2620. seq_printf(m, "batch = %lu\n", i915->mm.shrinker.batch);
  2621. return 0;
  2622. }
  2623. static int i915_shared_dplls_info(struct seq_file *m, void *unused)
  2624. {
  2625. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  2626. struct drm_device *dev = &dev_priv->drm;
  2627. int i;
  2628. drm_modeset_lock_all(dev);
  2629. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  2630. struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
  2631. seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
  2632. seq_printf(m, " crtc_mask: 0x%08x, active: 0x%x, on: %s\n",
  2633. pll->state.crtc_mask, pll->active_mask, yesno(pll->on));
  2634. seq_printf(m, " tracked hardware state:\n");
  2635. seq_printf(m, " dpll: 0x%08x\n", pll->state.hw_state.dpll);
  2636. seq_printf(m, " dpll_md: 0x%08x\n",
  2637. pll->state.hw_state.dpll_md);
  2638. seq_printf(m, " fp0: 0x%08x\n", pll->state.hw_state.fp0);
  2639. seq_printf(m, " fp1: 0x%08x\n", pll->state.hw_state.fp1);
  2640. seq_printf(m, " wrpll: 0x%08x\n", pll->state.hw_state.wrpll);
  2641. }
  2642. drm_modeset_unlock_all(dev);
  2643. return 0;
  2644. }
  2645. static int i915_wa_registers(struct seq_file *m, void *unused)
  2646. {
  2647. int i;
  2648. int ret;
  2649. struct intel_engine_cs *engine;
  2650. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  2651. struct drm_device *dev = &dev_priv->drm;
  2652. struct i915_workarounds *workarounds = &dev_priv->workarounds;
  2653. enum intel_engine_id id;
  2654. ret = mutex_lock_interruptible(&dev->struct_mutex);
  2655. if (ret)
  2656. return ret;
  2657. intel_runtime_pm_get(dev_priv);
  2658. seq_printf(m, "Workarounds applied: %d\n", workarounds->count);
  2659. for_each_engine(engine, dev_priv, id)
  2660. seq_printf(m, "HW whitelist count for %s: %d\n",
  2661. engine->name, workarounds->hw_whitelist_count[id]);
  2662. for (i = 0; i < workarounds->count; ++i) {
  2663. i915_reg_t addr;
  2664. u32 mask, value, read;
  2665. bool ok;
  2666. addr = workarounds->reg[i].addr;
  2667. mask = workarounds->reg[i].mask;
  2668. value = workarounds->reg[i].value;
  2669. read = I915_READ(addr);
  2670. ok = (value & mask) == (read & mask);
  2671. seq_printf(m, "0x%X: 0x%08X, mask: 0x%08X, read: 0x%08x, status: %s\n",
  2672. i915_mmio_reg_offset(addr), value, mask, read, ok ? "OK" : "FAIL");
  2673. }
  2674. intel_runtime_pm_put(dev_priv);
  2675. mutex_unlock(&dev->struct_mutex);
  2676. return 0;
  2677. }
  2678. static int i915_ipc_status_show(struct seq_file *m, void *data)
  2679. {
  2680. struct drm_i915_private *dev_priv = m->private;
  2681. seq_printf(m, "Isochronous Priority Control: %s\n",
  2682. yesno(dev_priv->ipc_enabled));
  2683. return 0;
  2684. }
  2685. static int i915_ipc_status_open(struct inode *inode, struct file *file)
  2686. {
  2687. struct drm_i915_private *dev_priv = inode->i_private;
  2688. if (!HAS_IPC(dev_priv))
  2689. return -ENODEV;
  2690. return single_open(file, i915_ipc_status_show, dev_priv);
  2691. }
  2692. static ssize_t i915_ipc_status_write(struct file *file, const char __user *ubuf,
  2693. size_t len, loff_t *offp)
  2694. {
  2695. struct seq_file *m = file->private_data;
  2696. struct drm_i915_private *dev_priv = m->private;
  2697. int ret;
  2698. bool enable;
  2699. ret = kstrtobool_from_user(ubuf, len, &enable);
  2700. if (ret < 0)
  2701. return ret;
  2702. intel_runtime_pm_get(dev_priv);
  2703. if (!dev_priv->ipc_enabled && enable)
  2704. DRM_INFO("Enabling IPC: WM will be proper only after next commit\n");
  2705. dev_priv->wm.distrust_bios_wm = true;
  2706. dev_priv->ipc_enabled = enable;
  2707. intel_enable_ipc(dev_priv);
  2708. intel_runtime_pm_put(dev_priv);
  2709. return len;
  2710. }
  2711. static const struct file_operations i915_ipc_status_fops = {
  2712. .owner = THIS_MODULE,
  2713. .open = i915_ipc_status_open,
  2714. .read = seq_read,
  2715. .llseek = seq_lseek,
  2716. .release = single_release,
  2717. .write = i915_ipc_status_write
  2718. };
  2719. static int i915_ddb_info(struct seq_file *m, void *unused)
  2720. {
  2721. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  2722. struct drm_device *dev = &dev_priv->drm;
  2723. struct skl_ddb_allocation *ddb;
  2724. struct skl_ddb_entry *entry;
  2725. enum pipe pipe;
  2726. int plane;
  2727. if (INTEL_GEN(dev_priv) < 9)
  2728. return -ENODEV;
  2729. drm_modeset_lock_all(dev);
  2730. ddb = &dev_priv->wm.skl_hw.ddb;
  2731. seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
  2732. for_each_pipe(dev_priv, pipe) {
  2733. seq_printf(m, "Pipe %c\n", pipe_name(pipe));
  2734. for_each_universal_plane(dev_priv, pipe, plane) {
  2735. entry = &ddb->plane[pipe][plane];
  2736. seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
  2737. entry->start, entry->end,
  2738. skl_ddb_entry_size(entry));
  2739. }
  2740. entry = &ddb->plane[pipe][PLANE_CURSOR];
  2741. seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
  2742. entry->end, skl_ddb_entry_size(entry));
  2743. }
  2744. drm_modeset_unlock_all(dev);
  2745. return 0;
  2746. }
  2747. static void drrs_status_per_crtc(struct seq_file *m,
  2748. struct drm_device *dev,
  2749. struct intel_crtc *intel_crtc)
  2750. {
  2751. struct drm_i915_private *dev_priv = to_i915(dev);
  2752. struct i915_drrs *drrs = &dev_priv->drrs;
  2753. int vrefresh = 0;
  2754. struct drm_connector *connector;
  2755. struct drm_connector_list_iter conn_iter;
  2756. drm_connector_list_iter_begin(dev, &conn_iter);
  2757. drm_for_each_connector_iter(connector, &conn_iter) {
  2758. if (connector->state->crtc != &intel_crtc->base)
  2759. continue;
  2760. seq_printf(m, "%s:\n", connector->name);
  2761. }
  2762. drm_connector_list_iter_end(&conn_iter);
  2763. if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
  2764. seq_puts(m, "\tVBT: DRRS_type: Static");
  2765. else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
  2766. seq_puts(m, "\tVBT: DRRS_type: Seamless");
  2767. else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
  2768. seq_puts(m, "\tVBT: DRRS_type: None");
  2769. else
  2770. seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
  2771. seq_puts(m, "\n\n");
  2772. if (to_intel_crtc_state(intel_crtc->base.state)->has_drrs) {
  2773. struct intel_panel *panel;
  2774. mutex_lock(&drrs->mutex);
  2775. /* DRRS Supported */
  2776. seq_puts(m, "\tDRRS Supported: Yes\n");
  2777. /* disable_drrs() will make drrs->dp NULL */
  2778. if (!drrs->dp) {
  2779. seq_puts(m, "Idleness DRRS: Disabled");
  2780. mutex_unlock(&drrs->mutex);
  2781. return;
  2782. }
  2783. panel = &drrs->dp->attached_connector->panel;
  2784. seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
  2785. drrs->busy_frontbuffer_bits);
  2786. seq_puts(m, "\n\t\t");
  2787. if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
  2788. seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
  2789. vrefresh = panel->fixed_mode->vrefresh;
  2790. } else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
  2791. seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
  2792. vrefresh = panel->downclock_mode->vrefresh;
  2793. } else {
  2794. seq_printf(m, "DRRS_State: Unknown(%d)\n",
  2795. drrs->refresh_rate_type);
  2796. mutex_unlock(&drrs->mutex);
  2797. return;
  2798. }
  2799. seq_printf(m, "\t\tVrefresh: %d", vrefresh);
  2800. seq_puts(m, "\n\t\t");
  2801. mutex_unlock(&drrs->mutex);
  2802. } else {
  2803. /* DRRS not supported. Print the VBT parameter*/
  2804. seq_puts(m, "\tDRRS Supported : No");
  2805. }
  2806. seq_puts(m, "\n");
  2807. }
  2808. static int i915_drrs_status(struct seq_file *m, void *unused)
  2809. {
  2810. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  2811. struct drm_device *dev = &dev_priv->drm;
  2812. struct intel_crtc *intel_crtc;
  2813. int active_crtc_cnt = 0;
  2814. drm_modeset_lock_all(dev);
  2815. for_each_intel_crtc(dev, intel_crtc) {
  2816. if (intel_crtc->base.state->active) {
  2817. active_crtc_cnt++;
  2818. seq_printf(m, "\nCRTC %d: ", active_crtc_cnt);
  2819. drrs_status_per_crtc(m, dev, intel_crtc);
  2820. }
  2821. }
  2822. drm_modeset_unlock_all(dev);
  2823. if (!active_crtc_cnt)
  2824. seq_puts(m, "No active crtc found\n");
  2825. return 0;
  2826. }
  2827. static int i915_dp_mst_info(struct seq_file *m, void *unused)
  2828. {
  2829. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  2830. struct drm_device *dev = &dev_priv->drm;
  2831. struct intel_encoder *intel_encoder;
  2832. struct intel_digital_port *intel_dig_port;
  2833. struct drm_connector *connector;
  2834. struct drm_connector_list_iter conn_iter;
  2835. drm_connector_list_iter_begin(dev, &conn_iter);
  2836. drm_for_each_connector_iter(connector, &conn_iter) {
  2837. if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
  2838. continue;
  2839. intel_encoder = intel_attached_encoder(connector);
  2840. if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
  2841. continue;
  2842. intel_dig_port = enc_to_dig_port(&intel_encoder->base);
  2843. if (!intel_dig_port->dp.can_mst)
  2844. continue;
  2845. seq_printf(m, "MST Source Port %c\n",
  2846. port_name(intel_dig_port->base.port));
  2847. drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
  2848. }
  2849. drm_connector_list_iter_end(&conn_iter);
  2850. return 0;
  2851. }
  2852. static ssize_t i915_displayport_test_active_write(struct file *file,
  2853. const char __user *ubuf,
  2854. size_t len, loff_t *offp)
  2855. {
  2856. char *input_buffer;
  2857. int status = 0;
  2858. struct drm_device *dev;
  2859. struct drm_connector *connector;
  2860. struct drm_connector_list_iter conn_iter;
  2861. struct intel_dp *intel_dp;
  2862. int val = 0;
  2863. dev = ((struct seq_file *)file->private_data)->private;
  2864. if (len == 0)
  2865. return 0;
  2866. input_buffer = memdup_user_nul(ubuf, len);
  2867. if (IS_ERR(input_buffer))
  2868. return PTR_ERR(input_buffer);
  2869. DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
  2870. drm_connector_list_iter_begin(dev, &conn_iter);
  2871. drm_for_each_connector_iter(connector, &conn_iter) {
  2872. struct intel_encoder *encoder;
  2873. if (connector->connector_type !=
  2874. DRM_MODE_CONNECTOR_DisplayPort)
  2875. continue;
  2876. encoder = to_intel_encoder(connector->encoder);
  2877. if (encoder && encoder->type == INTEL_OUTPUT_DP_MST)
  2878. continue;
  2879. if (encoder && connector->status == connector_status_connected) {
  2880. intel_dp = enc_to_intel_dp(&encoder->base);
  2881. status = kstrtoint(input_buffer, 10, &val);
  2882. if (status < 0)
  2883. break;
  2884. DRM_DEBUG_DRIVER("Got %d for test active\n", val);
  2885. /* To prevent erroneous activation of the compliance
  2886. * testing code, only accept an actual value of 1 here
  2887. */
  2888. if (val == 1)
  2889. intel_dp->compliance.test_active = 1;
  2890. else
  2891. intel_dp->compliance.test_active = 0;
  2892. }
  2893. }
  2894. drm_connector_list_iter_end(&conn_iter);
  2895. kfree(input_buffer);
  2896. if (status < 0)
  2897. return status;
  2898. *offp += len;
  2899. return len;
  2900. }
  2901. static int i915_displayport_test_active_show(struct seq_file *m, void *data)
  2902. {
  2903. struct drm_device *dev = m->private;
  2904. struct drm_connector *connector;
  2905. struct drm_connector_list_iter conn_iter;
  2906. struct intel_dp *intel_dp;
  2907. drm_connector_list_iter_begin(dev, &conn_iter);
  2908. drm_for_each_connector_iter(connector, &conn_iter) {
  2909. struct intel_encoder *encoder;
  2910. if (connector->connector_type !=
  2911. DRM_MODE_CONNECTOR_DisplayPort)
  2912. continue;
  2913. encoder = to_intel_encoder(connector->encoder);
  2914. if (encoder && encoder->type == INTEL_OUTPUT_DP_MST)
  2915. continue;
  2916. if (encoder && connector->status == connector_status_connected) {
  2917. intel_dp = enc_to_intel_dp(&encoder->base);
  2918. if (intel_dp->compliance.test_active)
  2919. seq_puts(m, "1");
  2920. else
  2921. seq_puts(m, "0");
  2922. } else
  2923. seq_puts(m, "0");
  2924. }
  2925. drm_connector_list_iter_end(&conn_iter);
  2926. return 0;
  2927. }
  2928. static int i915_displayport_test_active_open(struct inode *inode,
  2929. struct file *file)
  2930. {
  2931. struct drm_i915_private *dev_priv = inode->i_private;
  2932. return single_open(file, i915_displayport_test_active_show,
  2933. &dev_priv->drm);
  2934. }
  2935. static const struct file_operations i915_displayport_test_active_fops = {
  2936. .owner = THIS_MODULE,
  2937. .open = i915_displayport_test_active_open,
  2938. .read = seq_read,
  2939. .llseek = seq_lseek,
  2940. .release = single_release,
  2941. .write = i915_displayport_test_active_write
  2942. };
  2943. static int i915_displayport_test_data_show(struct seq_file *m, void *data)
  2944. {
  2945. struct drm_device *dev = m->private;
  2946. struct drm_connector *connector;
  2947. struct drm_connector_list_iter conn_iter;
  2948. struct intel_dp *intel_dp;
  2949. drm_connector_list_iter_begin(dev, &conn_iter);
  2950. drm_for_each_connector_iter(connector, &conn_iter) {
  2951. struct intel_encoder *encoder;
  2952. if (connector->connector_type !=
  2953. DRM_MODE_CONNECTOR_DisplayPort)
  2954. continue;
  2955. encoder = to_intel_encoder(connector->encoder);
  2956. if (encoder && encoder->type == INTEL_OUTPUT_DP_MST)
  2957. continue;
  2958. if (encoder && connector->status == connector_status_connected) {
  2959. intel_dp = enc_to_intel_dp(&encoder->base);
  2960. if (intel_dp->compliance.test_type ==
  2961. DP_TEST_LINK_EDID_READ)
  2962. seq_printf(m, "%lx",
  2963. intel_dp->compliance.test_data.edid);
  2964. else if (intel_dp->compliance.test_type ==
  2965. DP_TEST_LINK_VIDEO_PATTERN) {
  2966. seq_printf(m, "hdisplay: %d\n",
  2967. intel_dp->compliance.test_data.hdisplay);
  2968. seq_printf(m, "vdisplay: %d\n",
  2969. intel_dp->compliance.test_data.vdisplay);
  2970. seq_printf(m, "bpc: %u\n",
  2971. intel_dp->compliance.test_data.bpc);
  2972. }
  2973. } else
  2974. seq_puts(m, "0");
  2975. }
  2976. drm_connector_list_iter_end(&conn_iter);
  2977. return 0;
  2978. }
  2979. static int i915_displayport_test_data_open(struct inode *inode,
  2980. struct file *file)
  2981. {
  2982. struct drm_i915_private *dev_priv = inode->i_private;
  2983. return single_open(file, i915_displayport_test_data_show,
  2984. &dev_priv->drm);
  2985. }
  2986. static const struct file_operations i915_displayport_test_data_fops = {
  2987. .owner = THIS_MODULE,
  2988. .open = i915_displayport_test_data_open,
  2989. .read = seq_read,
  2990. .llseek = seq_lseek,
  2991. .release = single_release
  2992. };
  2993. static int i915_displayport_test_type_show(struct seq_file *m, void *data)
  2994. {
  2995. struct drm_device *dev = m->private;
  2996. struct drm_connector *connector;
  2997. struct drm_connector_list_iter conn_iter;
  2998. struct intel_dp *intel_dp;
  2999. drm_connector_list_iter_begin(dev, &conn_iter);
  3000. drm_for_each_connector_iter(connector, &conn_iter) {
  3001. struct intel_encoder *encoder;
  3002. if (connector->connector_type !=
  3003. DRM_MODE_CONNECTOR_DisplayPort)
  3004. continue;
  3005. encoder = to_intel_encoder(connector->encoder);
  3006. if (encoder && encoder->type == INTEL_OUTPUT_DP_MST)
  3007. continue;
  3008. if (encoder && connector->status == connector_status_connected) {
  3009. intel_dp = enc_to_intel_dp(&encoder->base);
  3010. seq_printf(m, "%02lx", intel_dp->compliance.test_type);
  3011. } else
  3012. seq_puts(m, "0");
  3013. }
  3014. drm_connector_list_iter_end(&conn_iter);
  3015. return 0;
  3016. }
  3017. static int i915_displayport_test_type_open(struct inode *inode,
  3018. struct file *file)
  3019. {
  3020. struct drm_i915_private *dev_priv = inode->i_private;
  3021. return single_open(file, i915_displayport_test_type_show,
  3022. &dev_priv->drm);
  3023. }
  3024. static const struct file_operations i915_displayport_test_type_fops = {
  3025. .owner = THIS_MODULE,
  3026. .open = i915_displayport_test_type_open,
  3027. .read = seq_read,
  3028. .llseek = seq_lseek,
  3029. .release = single_release
  3030. };
  3031. static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
  3032. {
  3033. struct drm_i915_private *dev_priv = m->private;
  3034. struct drm_device *dev = &dev_priv->drm;
  3035. int level;
  3036. int num_levels;
  3037. if (IS_CHERRYVIEW(dev_priv))
  3038. num_levels = 3;
  3039. else if (IS_VALLEYVIEW(dev_priv))
  3040. num_levels = 1;
  3041. else if (IS_G4X(dev_priv))
  3042. num_levels = 3;
  3043. else
  3044. num_levels = ilk_wm_max_level(dev_priv) + 1;
  3045. drm_modeset_lock_all(dev);
  3046. for (level = 0; level < num_levels; level++) {
  3047. unsigned int latency = wm[level];
  3048. /*
  3049. * - WM1+ latency values in 0.5us units
  3050. * - latencies are in us on gen9/vlv/chv
  3051. */
  3052. if (INTEL_GEN(dev_priv) >= 9 ||
  3053. IS_VALLEYVIEW(dev_priv) ||
  3054. IS_CHERRYVIEW(dev_priv) ||
  3055. IS_G4X(dev_priv))
  3056. latency *= 10;
  3057. else if (level > 0)
  3058. latency *= 5;
  3059. seq_printf(m, "WM%d %u (%u.%u usec)\n",
  3060. level, wm[level], latency / 10, latency % 10);
  3061. }
  3062. drm_modeset_unlock_all(dev);
  3063. }
  3064. static int pri_wm_latency_show(struct seq_file *m, void *data)
  3065. {
  3066. struct drm_i915_private *dev_priv = m->private;
  3067. const uint16_t *latencies;
  3068. if (INTEL_GEN(dev_priv) >= 9)
  3069. latencies = dev_priv->wm.skl_latency;
  3070. else
  3071. latencies = dev_priv->wm.pri_latency;
  3072. wm_latency_show(m, latencies);
  3073. return 0;
  3074. }
  3075. static int spr_wm_latency_show(struct seq_file *m, void *data)
  3076. {
  3077. struct drm_i915_private *dev_priv = m->private;
  3078. const uint16_t *latencies;
  3079. if (INTEL_GEN(dev_priv) >= 9)
  3080. latencies = dev_priv->wm.skl_latency;
  3081. else
  3082. latencies = dev_priv->wm.spr_latency;
  3083. wm_latency_show(m, latencies);
  3084. return 0;
  3085. }
  3086. static int cur_wm_latency_show(struct seq_file *m, void *data)
  3087. {
  3088. struct drm_i915_private *dev_priv = m->private;
  3089. const uint16_t *latencies;
  3090. if (INTEL_GEN(dev_priv) >= 9)
  3091. latencies = dev_priv->wm.skl_latency;
  3092. else
  3093. latencies = dev_priv->wm.cur_latency;
  3094. wm_latency_show(m, latencies);
  3095. return 0;
  3096. }
  3097. static int pri_wm_latency_open(struct inode *inode, struct file *file)
  3098. {
  3099. struct drm_i915_private *dev_priv = inode->i_private;
  3100. if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
  3101. return -ENODEV;
  3102. return single_open(file, pri_wm_latency_show, dev_priv);
  3103. }
  3104. static int spr_wm_latency_open(struct inode *inode, struct file *file)
  3105. {
  3106. struct drm_i915_private *dev_priv = inode->i_private;
  3107. if (HAS_GMCH_DISPLAY(dev_priv))
  3108. return -ENODEV;
  3109. return single_open(file, spr_wm_latency_show, dev_priv);
  3110. }
  3111. static int cur_wm_latency_open(struct inode *inode, struct file *file)
  3112. {
  3113. struct drm_i915_private *dev_priv = inode->i_private;
  3114. if (HAS_GMCH_DISPLAY(dev_priv))
  3115. return -ENODEV;
  3116. return single_open(file, cur_wm_latency_show, dev_priv);
  3117. }
  3118. static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
  3119. size_t len, loff_t *offp, uint16_t wm[8])
  3120. {
  3121. struct seq_file *m = file->private_data;
  3122. struct drm_i915_private *dev_priv = m->private;
  3123. struct drm_device *dev = &dev_priv->drm;
  3124. uint16_t new[8] = { 0 };
  3125. int num_levels;
  3126. int level;
  3127. int ret;
  3128. char tmp[32];
  3129. if (IS_CHERRYVIEW(dev_priv))
  3130. num_levels = 3;
  3131. else if (IS_VALLEYVIEW(dev_priv))
  3132. num_levels = 1;
  3133. else if (IS_G4X(dev_priv))
  3134. num_levels = 3;
  3135. else
  3136. num_levels = ilk_wm_max_level(dev_priv) + 1;
  3137. if (len >= sizeof(tmp))
  3138. return -EINVAL;
  3139. if (copy_from_user(tmp, ubuf, len))
  3140. return -EFAULT;
  3141. tmp[len] = '\0';
  3142. ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
  3143. &new[0], &new[1], &new[2], &new[3],
  3144. &new[4], &new[5], &new[6], &new[7]);
  3145. if (ret != num_levels)
  3146. return -EINVAL;
  3147. drm_modeset_lock_all(dev);
  3148. for (level = 0; level < num_levels; level++)
  3149. wm[level] = new[level];
  3150. drm_modeset_unlock_all(dev);
  3151. return len;
  3152. }
  3153. static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
  3154. size_t len, loff_t *offp)
  3155. {
  3156. struct seq_file *m = file->private_data;
  3157. struct drm_i915_private *dev_priv = m->private;
  3158. uint16_t *latencies;
  3159. if (INTEL_GEN(dev_priv) >= 9)
  3160. latencies = dev_priv->wm.skl_latency;
  3161. else
  3162. latencies = dev_priv->wm.pri_latency;
  3163. return wm_latency_write(file, ubuf, len, offp, latencies);
  3164. }
  3165. static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
  3166. size_t len, loff_t *offp)
  3167. {
  3168. struct seq_file *m = file->private_data;
  3169. struct drm_i915_private *dev_priv = m->private;
  3170. uint16_t *latencies;
  3171. if (INTEL_GEN(dev_priv) >= 9)
  3172. latencies = dev_priv->wm.skl_latency;
  3173. else
  3174. latencies = dev_priv->wm.spr_latency;
  3175. return wm_latency_write(file, ubuf, len, offp, latencies);
  3176. }
  3177. static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
  3178. size_t len, loff_t *offp)
  3179. {
  3180. struct seq_file *m = file->private_data;
  3181. struct drm_i915_private *dev_priv = m->private;
  3182. uint16_t *latencies;
  3183. if (INTEL_GEN(dev_priv) >= 9)
  3184. latencies = dev_priv->wm.skl_latency;
  3185. else
  3186. latencies = dev_priv->wm.cur_latency;
  3187. return wm_latency_write(file, ubuf, len, offp, latencies);
  3188. }
  3189. static const struct file_operations i915_pri_wm_latency_fops = {
  3190. .owner = THIS_MODULE,
  3191. .open = pri_wm_latency_open,
  3192. .read = seq_read,
  3193. .llseek = seq_lseek,
  3194. .release = single_release,
  3195. .write = pri_wm_latency_write
  3196. };
  3197. static const struct file_operations i915_spr_wm_latency_fops = {
  3198. .owner = THIS_MODULE,
  3199. .open = spr_wm_latency_open,
  3200. .read = seq_read,
  3201. .llseek = seq_lseek,
  3202. .release = single_release,
  3203. .write = spr_wm_latency_write
  3204. };
  3205. static const struct file_operations i915_cur_wm_latency_fops = {
  3206. .owner = THIS_MODULE,
  3207. .open = cur_wm_latency_open,
  3208. .read = seq_read,
  3209. .llseek = seq_lseek,
  3210. .release = single_release,
  3211. .write = cur_wm_latency_write
  3212. };
  3213. static int
  3214. i915_wedged_get(void *data, u64 *val)
  3215. {
  3216. struct drm_i915_private *dev_priv = data;
  3217. *val = i915_terminally_wedged(&dev_priv->gpu_error);
  3218. return 0;
  3219. }
  3220. static int
  3221. i915_wedged_set(void *data, u64 val)
  3222. {
  3223. struct drm_i915_private *i915 = data;
  3224. struct intel_engine_cs *engine;
  3225. unsigned int tmp;
  3226. /*
  3227. * There is no safeguard against this debugfs entry colliding
  3228. * with the hangcheck calling same i915_handle_error() in
  3229. * parallel, causing an explosion. For now we assume that the
  3230. * test harness is responsible enough not to inject gpu hangs
  3231. * while it is writing to 'i915_wedged'
  3232. */
  3233. if (i915_reset_backoff(&i915->gpu_error))
  3234. return -EAGAIN;
  3235. for_each_engine_masked(engine, i915, val, tmp) {
  3236. engine->hangcheck.seqno = intel_engine_get_seqno(engine);
  3237. engine->hangcheck.stalled = true;
  3238. }
  3239. i915_handle_error(i915, val, "Manually setting wedged to %llu", val);
  3240. wait_on_bit(&i915->gpu_error.flags,
  3241. I915_RESET_HANDOFF,
  3242. TASK_UNINTERRUPTIBLE);
  3243. return 0;
  3244. }
  3245. DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
  3246. i915_wedged_get, i915_wedged_set,
  3247. "%llu\n");
  3248. static int
  3249. fault_irq_set(struct drm_i915_private *i915,
  3250. unsigned long *irq,
  3251. unsigned long val)
  3252. {
  3253. int err;
  3254. err = mutex_lock_interruptible(&i915->drm.struct_mutex);
  3255. if (err)
  3256. return err;
  3257. err = i915_gem_wait_for_idle(i915,
  3258. I915_WAIT_LOCKED |
  3259. I915_WAIT_INTERRUPTIBLE);
  3260. if (err)
  3261. goto err_unlock;
  3262. *irq = val;
  3263. mutex_unlock(&i915->drm.struct_mutex);
  3264. /* Flush idle worker to disarm irq */
  3265. drain_delayed_work(&i915->gt.idle_work);
  3266. return 0;
  3267. err_unlock:
  3268. mutex_unlock(&i915->drm.struct_mutex);
  3269. return err;
  3270. }
  3271. static int
  3272. i915_ring_missed_irq_get(void *data, u64 *val)
  3273. {
  3274. struct drm_i915_private *dev_priv = data;
  3275. *val = dev_priv->gpu_error.missed_irq_rings;
  3276. return 0;
  3277. }
  3278. static int
  3279. i915_ring_missed_irq_set(void *data, u64 val)
  3280. {
  3281. struct drm_i915_private *i915 = data;
  3282. return fault_irq_set(i915, &i915->gpu_error.missed_irq_rings, val);
  3283. }
  3284. DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
  3285. i915_ring_missed_irq_get, i915_ring_missed_irq_set,
  3286. "0x%08llx\n");
  3287. static int
  3288. i915_ring_test_irq_get(void *data, u64 *val)
  3289. {
  3290. struct drm_i915_private *dev_priv = data;
  3291. *val = dev_priv->gpu_error.test_irq_rings;
  3292. return 0;
  3293. }
  3294. static int
  3295. i915_ring_test_irq_set(void *data, u64 val)
  3296. {
  3297. struct drm_i915_private *i915 = data;
  3298. val &= INTEL_INFO(i915)->ring_mask;
  3299. DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
  3300. return fault_irq_set(i915, &i915->gpu_error.test_irq_rings, val);
  3301. }
  3302. DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
  3303. i915_ring_test_irq_get, i915_ring_test_irq_set,
  3304. "0x%08llx\n");
  3305. #define DROP_UNBOUND BIT(0)
  3306. #define DROP_BOUND BIT(1)
  3307. #define DROP_RETIRE BIT(2)
  3308. #define DROP_ACTIVE BIT(3)
  3309. #define DROP_FREED BIT(4)
  3310. #define DROP_SHRINK_ALL BIT(5)
  3311. #define DROP_IDLE BIT(6)
  3312. #define DROP_ALL (DROP_UNBOUND | \
  3313. DROP_BOUND | \
  3314. DROP_RETIRE | \
  3315. DROP_ACTIVE | \
  3316. DROP_FREED | \
  3317. DROP_SHRINK_ALL |\
  3318. DROP_IDLE)
  3319. static int
  3320. i915_drop_caches_get(void *data, u64 *val)
  3321. {
  3322. *val = DROP_ALL;
  3323. return 0;
  3324. }
  3325. static int
  3326. i915_drop_caches_set(void *data, u64 val)
  3327. {
  3328. struct drm_i915_private *dev_priv = data;
  3329. struct drm_device *dev = &dev_priv->drm;
  3330. int ret = 0;
  3331. DRM_DEBUG("Dropping caches: 0x%08llx [0x%08llx]\n",
  3332. val, val & DROP_ALL);
  3333. /* No need to check and wait for gpu resets, only libdrm auto-restarts
  3334. * on ioctls on -EAGAIN. */
  3335. if (val & (DROP_ACTIVE | DROP_RETIRE)) {
  3336. ret = mutex_lock_interruptible(&dev->struct_mutex);
  3337. if (ret)
  3338. return ret;
  3339. if (val & DROP_ACTIVE)
  3340. ret = i915_gem_wait_for_idle(dev_priv,
  3341. I915_WAIT_INTERRUPTIBLE |
  3342. I915_WAIT_LOCKED);
  3343. if (val & DROP_RETIRE)
  3344. i915_gem_retire_requests(dev_priv);
  3345. mutex_unlock(&dev->struct_mutex);
  3346. }
  3347. fs_reclaim_acquire(GFP_KERNEL);
  3348. if (val & DROP_BOUND)
  3349. i915_gem_shrink(dev_priv, LONG_MAX, NULL, I915_SHRINK_BOUND);
  3350. if (val & DROP_UNBOUND)
  3351. i915_gem_shrink(dev_priv, LONG_MAX, NULL, I915_SHRINK_UNBOUND);
  3352. if (val & DROP_SHRINK_ALL)
  3353. i915_gem_shrink_all(dev_priv);
  3354. fs_reclaim_release(GFP_KERNEL);
  3355. if (val & DROP_IDLE)
  3356. drain_delayed_work(&dev_priv->gt.idle_work);
  3357. if (val & DROP_FREED) {
  3358. synchronize_rcu();
  3359. i915_gem_drain_freed_objects(dev_priv);
  3360. }
  3361. return ret;
  3362. }
  3363. DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
  3364. i915_drop_caches_get, i915_drop_caches_set,
  3365. "0x%08llx\n");
  3366. static int
  3367. i915_max_freq_get(void *data, u64 *val)
  3368. {
  3369. struct drm_i915_private *dev_priv = data;
  3370. if (INTEL_GEN(dev_priv) < 6)
  3371. return -ENODEV;
  3372. *val = intel_gpu_freq(dev_priv, dev_priv->gt_pm.rps.max_freq_softlimit);
  3373. return 0;
  3374. }
  3375. static int
  3376. i915_max_freq_set(void *data, u64 val)
  3377. {
  3378. struct drm_i915_private *dev_priv = data;
  3379. struct intel_rps *rps = &dev_priv->gt_pm.rps;
  3380. u32 hw_max, hw_min;
  3381. int ret;
  3382. if (INTEL_GEN(dev_priv) < 6)
  3383. return -ENODEV;
  3384. DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
  3385. ret = mutex_lock_interruptible(&dev_priv->pcu_lock);
  3386. if (ret)
  3387. return ret;
  3388. /*
  3389. * Turbo will still be enabled, but won't go above the set value.
  3390. */
  3391. val = intel_freq_opcode(dev_priv, val);
  3392. hw_max = rps->max_freq;
  3393. hw_min = rps->min_freq;
  3394. if (val < hw_min || val > hw_max || val < rps->min_freq_softlimit) {
  3395. mutex_unlock(&dev_priv->pcu_lock);
  3396. return -EINVAL;
  3397. }
  3398. rps->max_freq_softlimit = val;
  3399. if (intel_set_rps(dev_priv, val))
  3400. DRM_DEBUG_DRIVER("failed to update RPS to new softlimit\n");
  3401. mutex_unlock(&dev_priv->pcu_lock);
  3402. return 0;
  3403. }
  3404. DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
  3405. i915_max_freq_get, i915_max_freq_set,
  3406. "%llu\n");
  3407. static int
  3408. i915_min_freq_get(void *data, u64 *val)
  3409. {
  3410. struct drm_i915_private *dev_priv = data;
  3411. if (INTEL_GEN(dev_priv) < 6)
  3412. return -ENODEV;
  3413. *val = intel_gpu_freq(dev_priv, dev_priv->gt_pm.rps.min_freq_softlimit);
  3414. return 0;
  3415. }
  3416. static int
  3417. i915_min_freq_set(void *data, u64 val)
  3418. {
  3419. struct drm_i915_private *dev_priv = data;
  3420. struct intel_rps *rps = &dev_priv->gt_pm.rps;
  3421. u32 hw_max, hw_min;
  3422. int ret;
  3423. if (INTEL_GEN(dev_priv) < 6)
  3424. return -ENODEV;
  3425. DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
  3426. ret = mutex_lock_interruptible(&dev_priv->pcu_lock);
  3427. if (ret)
  3428. return ret;
  3429. /*
  3430. * Turbo will still be enabled, but won't go below the set value.
  3431. */
  3432. val = intel_freq_opcode(dev_priv, val);
  3433. hw_max = rps->max_freq;
  3434. hw_min = rps->min_freq;
  3435. if (val < hw_min ||
  3436. val > hw_max || val > rps->max_freq_softlimit) {
  3437. mutex_unlock(&dev_priv->pcu_lock);
  3438. return -EINVAL;
  3439. }
  3440. rps->min_freq_softlimit = val;
  3441. if (intel_set_rps(dev_priv, val))
  3442. DRM_DEBUG_DRIVER("failed to update RPS to new softlimit\n");
  3443. mutex_unlock(&dev_priv->pcu_lock);
  3444. return 0;
  3445. }
  3446. DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
  3447. i915_min_freq_get, i915_min_freq_set,
  3448. "%llu\n");
  3449. static int
  3450. i915_cache_sharing_get(void *data, u64 *val)
  3451. {
  3452. struct drm_i915_private *dev_priv = data;
  3453. u32 snpcr;
  3454. if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
  3455. return -ENODEV;
  3456. intel_runtime_pm_get(dev_priv);
  3457. snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
  3458. intel_runtime_pm_put(dev_priv);
  3459. *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
  3460. return 0;
  3461. }
  3462. static int
  3463. i915_cache_sharing_set(void *data, u64 val)
  3464. {
  3465. struct drm_i915_private *dev_priv = data;
  3466. u32 snpcr;
  3467. if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
  3468. return -ENODEV;
  3469. if (val > 3)
  3470. return -EINVAL;
  3471. intel_runtime_pm_get(dev_priv);
  3472. DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
  3473. /* Update the cache sharing policy here as well */
  3474. snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
  3475. snpcr &= ~GEN6_MBC_SNPCR_MASK;
  3476. snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
  3477. I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
  3478. intel_runtime_pm_put(dev_priv);
  3479. return 0;
  3480. }
  3481. DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
  3482. i915_cache_sharing_get, i915_cache_sharing_set,
  3483. "%llu\n");
  3484. static void cherryview_sseu_device_status(struct drm_i915_private *dev_priv,
  3485. struct sseu_dev_info *sseu)
  3486. {
  3487. int ss_max = 2;
  3488. int ss;
  3489. u32 sig1[ss_max], sig2[ss_max];
  3490. sig1[0] = I915_READ(CHV_POWER_SS0_SIG1);
  3491. sig1[1] = I915_READ(CHV_POWER_SS1_SIG1);
  3492. sig2[0] = I915_READ(CHV_POWER_SS0_SIG2);
  3493. sig2[1] = I915_READ(CHV_POWER_SS1_SIG2);
  3494. for (ss = 0; ss < ss_max; ss++) {
  3495. unsigned int eu_cnt;
  3496. if (sig1[ss] & CHV_SS_PG_ENABLE)
  3497. /* skip disabled subslice */
  3498. continue;
  3499. sseu->slice_mask = BIT(0);
  3500. sseu->subslice_mask |= BIT(ss);
  3501. eu_cnt = ((sig1[ss] & CHV_EU08_PG_ENABLE) ? 0 : 2) +
  3502. ((sig1[ss] & CHV_EU19_PG_ENABLE) ? 0 : 2) +
  3503. ((sig1[ss] & CHV_EU210_PG_ENABLE) ? 0 : 2) +
  3504. ((sig2[ss] & CHV_EU311_PG_ENABLE) ? 0 : 2);
  3505. sseu->eu_total += eu_cnt;
  3506. sseu->eu_per_subslice = max_t(unsigned int,
  3507. sseu->eu_per_subslice, eu_cnt);
  3508. }
  3509. }
  3510. static void gen10_sseu_device_status(struct drm_i915_private *dev_priv,
  3511. struct sseu_dev_info *sseu)
  3512. {
  3513. const struct intel_device_info *info = INTEL_INFO(dev_priv);
  3514. int s_max = 6, ss_max = 4;
  3515. int s, ss;
  3516. u32 s_reg[s_max], eu_reg[2 * s_max], eu_mask[2];
  3517. for (s = 0; s < s_max; s++) {
  3518. /*
  3519. * FIXME: Valid SS Mask respects the spec and read
  3520. * only valid bits for those registers, excluding reserverd
  3521. * although this seems wrong because it would leave many
  3522. * subslices without ACK.
  3523. */
  3524. s_reg[s] = I915_READ(GEN10_SLICE_PGCTL_ACK(s)) &
  3525. GEN10_PGCTL_VALID_SS_MASK(s);
  3526. eu_reg[2 * s] = I915_READ(GEN10_SS01_EU_PGCTL_ACK(s));
  3527. eu_reg[2 * s + 1] = I915_READ(GEN10_SS23_EU_PGCTL_ACK(s));
  3528. }
  3529. eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
  3530. GEN9_PGCTL_SSA_EU19_ACK |
  3531. GEN9_PGCTL_SSA_EU210_ACK |
  3532. GEN9_PGCTL_SSA_EU311_ACK;
  3533. eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
  3534. GEN9_PGCTL_SSB_EU19_ACK |
  3535. GEN9_PGCTL_SSB_EU210_ACK |
  3536. GEN9_PGCTL_SSB_EU311_ACK;
  3537. for (s = 0; s < s_max; s++) {
  3538. if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
  3539. /* skip disabled slice */
  3540. continue;
  3541. sseu->slice_mask |= BIT(s);
  3542. sseu->subslice_mask = info->sseu.subslice_mask;
  3543. for (ss = 0; ss < ss_max; ss++) {
  3544. unsigned int eu_cnt;
  3545. if (!(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
  3546. /* skip disabled subslice */
  3547. continue;
  3548. eu_cnt = 2 * hweight32(eu_reg[2 * s + ss / 2] &
  3549. eu_mask[ss % 2]);
  3550. sseu->eu_total += eu_cnt;
  3551. sseu->eu_per_subslice = max_t(unsigned int,
  3552. sseu->eu_per_subslice,
  3553. eu_cnt);
  3554. }
  3555. }
  3556. }
  3557. static void gen9_sseu_device_status(struct drm_i915_private *dev_priv,
  3558. struct sseu_dev_info *sseu)
  3559. {
  3560. int s_max = 3, ss_max = 4;
  3561. int s, ss;
  3562. u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
  3563. /* BXT has a single slice and at most 3 subslices. */
  3564. if (IS_GEN9_LP(dev_priv)) {
  3565. s_max = 1;
  3566. ss_max = 3;
  3567. }
  3568. for (s = 0; s < s_max; s++) {
  3569. s_reg[s] = I915_READ(GEN9_SLICE_PGCTL_ACK(s));
  3570. eu_reg[2*s] = I915_READ(GEN9_SS01_EU_PGCTL_ACK(s));
  3571. eu_reg[2*s + 1] = I915_READ(GEN9_SS23_EU_PGCTL_ACK(s));
  3572. }
  3573. eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
  3574. GEN9_PGCTL_SSA_EU19_ACK |
  3575. GEN9_PGCTL_SSA_EU210_ACK |
  3576. GEN9_PGCTL_SSA_EU311_ACK;
  3577. eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
  3578. GEN9_PGCTL_SSB_EU19_ACK |
  3579. GEN9_PGCTL_SSB_EU210_ACK |
  3580. GEN9_PGCTL_SSB_EU311_ACK;
  3581. for (s = 0; s < s_max; s++) {
  3582. if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
  3583. /* skip disabled slice */
  3584. continue;
  3585. sseu->slice_mask |= BIT(s);
  3586. if (IS_GEN9_BC(dev_priv))
  3587. sseu->subslice_mask =
  3588. INTEL_INFO(dev_priv)->sseu.subslice_mask;
  3589. for (ss = 0; ss < ss_max; ss++) {
  3590. unsigned int eu_cnt;
  3591. if (IS_GEN9_LP(dev_priv)) {
  3592. if (!(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
  3593. /* skip disabled subslice */
  3594. continue;
  3595. sseu->subslice_mask |= BIT(ss);
  3596. }
  3597. eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
  3598. eu_mask[ss%2]);
  3599. sseu->eu_total += eu_cnt;
  3600. sseu->eu_per_subslice = max_t(unsigned int,
  3601. sseu->eu_per_subslice,
  3602. eu_cnt);
  3603. }
  3604. }
  3605. }
  3606. static void broadwell_sseu_device_status(struct drm_i915_private *dev_priv,
  3607. struct sseu_dev_info *sseu)
  3608. {
  3609. u32 slice_info = I915_READ(GEN8_GT_SLICE_INFO);
  3610. int s;
  3611. sseu->slice_mask = slice_info & GEN8_LSLICESTAT_MASK;
  3612. if (sseu->slice_mask) {
  3613. sseu->subslice_mask = INTEL_INFO(dev_priv)->sseu.subslice_mask;
  3614. sseu->eu_per_subslice =
  3615. INTEL_INFO(dev_priv)->sseu.eu_per_subslice;
  3616. sseu->eu_total = sseu->eu_per_subslice *
  3617. sseu_subslice_total(sseu);
  3618. /* subtract fused off EU(s) from enabled slice(s) */
  3619. for (s = 0; s < fls(sseu->slice_mask); s++) {
  3620. u8 subslice_7eu =
  3621. INTEL_INFO(dev_priv)->sseu.subslice_7eu[s];
  3622. sseu->eu_total -= hweight8(subslice_7eu);
  3623. }
  3624. }
  3625. }
  3626. static void i915_print_sseu_info(struct seq_file *m, bool is_available_info,
  3627. const struct sseu_dev_info *sseu)
  3628. {
  3629. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  3630. const char *type = is_available_info ? "Available" : "Enabled";
  3631. seq_printf(m, " %s Slice Mask: %04x\n", type,
  3632. sseu->slice_mask);
  3633. seq_printf(m, " %s Slice Total: %u\n", type,
  3634. hweight8(sseu->slice_mask));
  3635. seq_printf(m, " %s Subslice Total: %u\n", type,
  3636. sseu_subslice_total(sseu));
  3637. seq_printf(m, " %s Subslice Mask: %04x\n", type,
  3638. sseu->subslice_mask);
  3639. seq_printf(m, " %s Subslice Per Slice: %u\n", type,
  3640. hweight8(sseu->subslice_mask));
  3641. seq_printf(m, " %s EU Total: %u\n", type,
  3642. sseu->eu_total);
  3643. seq_printf(m, " %s EU Per Subslice: %u\n", type,
  3644. sseu->eu_per_subslice);
  3645. if (!is_available_info)
  3646. return;
  3647. seq_printf(m, " Has Pooled EU: %s\n", yesno(HAS_POOLED_EU(dev_priv)));
  3648. if (HAS_POOLED_EU(dev_priv))
  3649. seq_printf(m, " Min EU in pool: %u\n", sseu->min_eu_in_pool);
  3650. seq_printf(m, " Has Slice Power Gating: %s\n",
  3651. yesno(sseu->has_slice_pg));
  3652. seq_printf(m, " Has Subslice Power Gating: %s\n",
  3653. yesno(sseu->has_subslice_pg));
  3654. seq_printf(m, " Has EU Power Gating: %s\n",
  3655. yesno(sseu->has_eu_pg));
  3656. }
  3657. static int i915_sseu_status(struct seq_file *m, void *unused)
  3658. {
  3659. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  3660. struct sseu_dev_info sseu;
  3661. if (INTEL_GEN(dev_priv) < 8)
  3662. return -ENODEV;
  3663. seq_puts(m, "SSEU Device Info\n");
  3664. i915_print_sseu_info(m, true, &INTEL_INFO(dev_priv)->sseu);
  3665. seq_puts(m, "SSEU Device Status\n");
  3666. memset(&sseu, 0, sizeof(sseu));
  3667. intel_runtime_pm_get(dev_priv);
  3668. if (IS_CHERRYVIEW(dev_priv)) {
  3669. cherryview_sseu_device_status(dev_priv, &sseu);
  3670. } else if (IS_BROADWELL(dev_priv)) {
  3671. broadwell_sseu_device_status(dev_priv, &sseu);
  3672. } else if (IS_GEN9(dev_priv)) {
  3673. gen9_sseu_device_status(dev_priv, &sseu);
  3674. } else if (INTEL_GEN(dev_priv) >= 10) {
  3675. gen10_sseu_device_status(dev_priv, &sseu);
  3676. }
  3677. intel_runtime_pm_put(dev_priv);
  3678. i915_print_sseu_info(m, false, &sseu);
  3679. return 0;
  3680. }
  3681. static int i915_forcewake_open(struct inode *inode, struct file *file)
  3682. {
  3683. struct drm_i915_private *i915 = inode->i_private;
  3684. if (INTEL_GEN(i915) < 6)
  3685. return 0;
  3686. intel_runtime_pm_get(i915);
  3687. intel_uncore_forcewake_user_get(i915);
  3688. return 0;
  3689. }
  3690. static int i915_forcewake_release(struct inode *inode, struct file *file)
  3691. {
  3692. struct drm_i915_private *i915 = inode->i_private;
  3693. if (INTEL_GEN(i915) < 6)
  3694. return 0;
  3695. intel_uncore_forcewake_user_put(i915);
  3696. intel_runtime_pm_put(i915);
  3697. return 0;
  3698. }
  3699. static const struct file_operations i915_forcewake_fops = {
  3700. .owner = THIS_MODULE,
  3701. .open = i915_forcewake_open,
  3702. .release = i915_forcewake_release,
  3703. };
  3704. static int i915_hpd_storm_ctl_show(struct seq_file *m, void *data)
  3705. {
  3706. struct drm_i915_private *dev_priv = m->private;
  3707. struct i915_hotplug *hotplug = &dev_priv->hotplug;
  3708. seq_printf(m, "Threshold: %d\n", hotplug->hpd_storm_threshold);
  3709. seq_printf(m, "Detected: %s\n",
  3710. yesno(delayed_work_pending(&hotplug->reenable_work)));
  3711. return 0;
  3712. }
  3713. static ssize_t i915_hpd_storm_ctl_write(struct file *file,
  3714. const char __user *ubuf, size_t len,
  3715. loff_t *offp)
  3716. {
  3717. struct seq_file *m = file->private_data;
  3718. struct drm_i915_private *dev_priv = m->private;
  3719. struct i915_hotplug *hotplug = &dev_priv->hotplug;
  3720. unsigned int new_threshold;
  3721. int i;
  3722. char *newline;
  3723. char tmp[16];
  3724. if (len >= sizeof(tmp))
  3725. return -EINVAL;
  3726. if (copy_from_user(tmp, ubuf, len))
  3727. return -EFAULT;
  3728. tmp[len] = '\0';
  3729. /* Strip newline, if any */
  3730. newline = strchr(tmp, '\n');
  3731. if (newline)
  3732. *newline = '\0';
  3733. if (strcmp(tmp, "reset") == 0)
  3734. new_threshold = HPD_STORM_DEFAULT_THRESHOLD;
  3735. else if (kstrtouint(tmp, 10, &new_threshold) != 0)
  3736. return -EINVAL;
  3737. if (new_threshold > 0)
  3738. DRM_DEBUG_KMS("Setting HPD storm detection threshold to %d\n",
  3739. new_threshold);
  3740. else
  3741. DRM_DEBUG_KMS("Disabling HPD storm detection\n");
  3742. spin_lock_irq(&dev_priv->irq_lock);
  3743. hotplug->hpd_storm_threshold = new_threshold;
  3744. /* Reset the HPD storm stats so we don't accidentally trigger a storm */
  3745. for_each_hpd_pin(i)
  3746. hotplug->stats[i].count = 0;
  3747. spin_unlock_irq(&dev_priv->irq_lock);
  3748. /* Re-enable hpd immediately if we were in an irq storm */
  3749. flush_delayed_work(&dev_priv->hotplug.reenable_work);
  3750. return len;
  3751. }
  3752. static int i915_hpd_storm_ctl_open(struct inode *inode, struct file *file)
  3753. {
  3754. return single_open(file, i915_hpd_storm_ctl_show, inode->i_private);
  3755. }
  3756. static const struct file_operations i915_hpd_storm_ctl_fops = {
  3757. .owner = THIS_MODULE,
  3758. .open = i915_hpd_storm_ctl_open,
  3759. .read = seq_read,
  3760. .llseek = seq_lseek,
  3761. .release = single_release,
  3762. .write = i915_hpd_storm_ctl_write
  3763. };
  3764. static const struct drm_info_list i915_debugfs_list[] = {
  3765. {"i915_capabilities", i915_capabilities, 0},
  3766. {"i915_gem_objects", i915_gem_object_info, 0},
  3767. {"i915_gem_gtt", i915_gem_gtt_info, 0},
  3768. {"i915_gem_stolen", i915_gem_stolen_list_info },
  3769. {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
  3770. {"i915_gem_interrupt", i915_interrupt_info, 0},
  3771. {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
  3772. {"i915_guc_info", i915_guc_info, 0},
  3773. {"i915_guc_load_status", i915_guc_load_status_info, 0},
  3774. {"i915_guc_log_dump", i915_guc_log_dump, 0},
  3775. {"i915_guc_load_err_log_dump", i915_guc_log_dump, 0, (void *)1},
  3776. {"i915_guc_stage_pool", i915_guc_stage_pool, 0},
  3777. {"i915_huc_load_status", i915_huc_load_status_info, 0},
  3778. {"i915_frequency_info", i915_frequency_info, 0},
  3779. {"i915_hangcheck_info", i915_hangcheck_info, 0},
  3780. {"i915_reset_info", i915_reset_info, 0},
  3781. {"i915_drpc_info", i915_drpc_info, 0},
  3782. {"i915_emon_status", i915_emon_status, 0},
  3783. {"i915_ring_freq_table", i915_ring_freq_table, 0},
  3784. {"i915_frontbuffer_tracking", i915_frontbuffer_tracking, 0},
  3785. {"i915_fbc_status", i915_fbc_status, 0},
  3786. {"i915_ips_status", i915_ips_status, 0},
  3787. {"i915_sr_status", i915_sr_status, 0},
  3788. {"i915_opregion", i915_opregion, 0},
  3789. {"i915_vbt", i915_vbt, 0},
  3790. {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
  3791. {"i915_context_status", i915_context_status, 0},
  3792. {"i915_forcewake_domains", i915_forcewake_domains, 0},
  3793. {"i915_swizzle_info", i915_swizzle_info, 0},
  3794. {"i915_ppgtt_info", i915_ppgtt_info, 0},
  3795. {"i915_llc", i915_llc, 0},
  3796. {"i915_edp_psr_status", i915_edp_psr_status, 0},
  3797. {"i915_sink_crc_eDP1", i915_sink_crc, 0},
  3798. {"i915_energy_uJ", i915_energy_uJ, 0},
  3799. {"i915_runtime_pm_status", i915_runtime_pm_status, 0},
  3800. {"i915_power_domain_info", i915_power_domain_info, 0},
  3801. {"i915_dmc_info", i915_dmc_info, 0},
  3802. {"i915_display_info", i915_display_info, 0},
  3803. {"i915_engine_info", i915_engine_info, 0},
  3804. {"i915_shrinker_info", i915_shrinker_info, 0},
  3805. {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
  3806. {"i915_dp_mst_info", i915_dp_mst_info, 0},
  3807. {"i915_wa_registers", i915_wa_registers, 0},
  3808. {"i915_ddb_info", i915_ddb_info, 0},
  3809. {"i915_sseu_status", i915_sseu_status, 0},
  3810. {"i915_drrs_status", i915_drrs_status, 0},
  3811. {"i915_rps_boost_info", i915_rps_boost_info, 0},
  3812. };
  3813. #define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
  3814. static const struct i915_debugfs_files {
  3815. const char *name;
  3816. const struct file_operations *fops;
  3817. } i915_debugfs_files[] = {
  3818. {"i915_wedged", &i915_wedged_fops},
  3819. {"i915_max_freq", &i915_max_freq_fops},
  3820. {"i915_min_freq", &i915_min_freq_fops},
  3821. {"i915_cache_sharing", &i915_cache_sharing_fops},
  3822. {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
  3823. {"i915_ring_test_irq", &i915_ring_test_irq_fops},
  3824. {"i915_gem_drop_caches", &i915_drop_caches_fops},
  3825. #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
  3826. {"i915_error_state", &i915_error_state_fops},
  3827. {"i915_gpu_info", &i915_gpu_info_fops},
  3828. #endif
  3829. {"i915_next_seqno", &i915_next_seqno_fops},
  3830. {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
  3831. {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
  3832. {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
  3833. {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
  3834. {"i915_fbc_false_color", &i915_fbc_false_color_fops},
  3835. {"i915_dp_test_data", &i915_displayport_test_data_fops},
  3836. {"i915_dp_test_type", &i915_displayport_test_type_fops},
  3837. {"i915_dp_test_active", &i915_displayport_test_active_fops},
  3838. {"i915_guc_log_control", &i915_guc_log_control_fops},
  3839. {"i915_hpd_storm_ctl", &i915_hpd_storm_ctl_fops},
  3840. {"i915_ipc_status", &i915_ipc_status_fops}
  3841. };
  3842. int i915_debugfs_register(struct drm_i915_private *dev_priv)
  3843. {
  3844. struct drm_minor *minor = dev_priv->drm.primary;
  3845. struct dentry *ent;
  3846. int ret, i;
  3847. ent = debugfs_create_file("i915_forcewake_user", S_IRUSR,
  3848. minor->debugfs_root, to_i915(minor->dev),
  3849. &i915_forcewake_fops);
  3850. if (!ent)
  3851. return -ENOMEM;
  3852. ret = intel_pipe_crc_create(minor);
  3853. if (ret)
  3854. return ret;
  3855. for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
  3856. ent = debugfs_create_file(i915_debugfs_files[i].name,
  3857. S_IRUGO | S_IWUSR,
  3858. minor->debugfs_root,
  3859. to_i915(minor->dev),
  3860. i915_debugfs_files[i].fops);
  3861. if (!ent)
  3862. return -ENOMEM;
  3863. }
  3864. return drm_debugfs_create_files(i915_debugfs_list,
  3865. I915_DEBUGFS_ENTRIES,
  3866. minor->debugfs_root, minor);
  3867. }
  3868. struct dpcd_block {
  3869. /* DPCD dump start address. */
  3870. unsigned int offset;
  3871. /* DPCD dump end address, inclusive. If unset, .size will be used. */
  3872. unsigned int end;
  3873. /* DPCD dump size. Used if .end is unset. If unset, defaults to 1. */
  3874. size_t size;
  3875. /* Only valid for eDP. */
  3876. bool edp;
  3877. };
  3878. static const struct dpcd_block i915_dpcd_debug[] = {
  3879. { .offset = DP_DPCD_REV, .size = DP_RECEIVER_CAP_SIZE },
  3880. { .offset = DP_PSR_SUPPORT, .end = DP_PSR_CAPS },
  3881. { .offset = DP_DOWNSTREAM_PORT_0, .size = 16 },
  3882. { .offset = DP_LINK_BW_SET, .end = DP_EDP_CONFIGURATION_SET },
  3883. { .offset = DP_SINK_COUNT, .end = DP_ADJUST_REQUEST_LANE2_3 },
  3884. { .offset = DP_SET_POWER },
  3885. { .offset = DP_EDP_DPCD_REV },
  3886. { .offset = DP_EDP_GENERAL_CAP_1, .end = DP_EDP_GENERAL_CAP_3 },
  3887. { .offset = DP_EDP_DISPLAY_CONTROL_REGISTER, .end = DP_EDP_BACKLIGHT_FREQ_CAP_MAX_LSB },
  3888. { .offset = DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET, .end = DP_EDP_DBC_MAXIMUM_BRIGHTNESS_SET },
  3889. };
  3890. static int i915_dpcd_show(struct seq_file *m, void *data)
  3891. {
  3892. struct drm_connector *connector = m->private;
  3893. struct intel_dp *intel_dp =
  3894. enc_to_intel_dp(&intel_attached_encoder(connector)->base);
  3895. uint8_t buf[16];
  3896. ssize_t err;
  3897. int i;
  3898. if (connector->status != connector_status_connected)
  3899. return -ENODEV;
  3900. for (i = 0; i < ARRAY_SIZE(i915_dpcd_debug); i++) {
  3901. const struct dpcd_block *b = &i915_dpcd_debug[i];
  3902. size_t size = b->end ? b->end - b->offset + 1 : (b->size ?: 1);
  3903. if (b->edp &&
  3904. connector->connector_type != DRM_MODE_CONNECTOR_eDP)
  3905. continue;
  3906. /* low tech for now */
  3907. if (WARN_ON(size > sizeof(buf)))
  3908. continue;
  3909. err = drm_dp_dpcd_read(&intel_dp->aux, b->offset, buf, size);
  3910. if (err <= 0) {
  3911. DRM_ERROR("dpcd read (%zu bytes at %u) failed (%zd)\n",
  3912. size, b->offset, err);
  3913. continue;
  3914. }
  3915. seq_printf(m, "%04x: %*ph\n", b->offset, (int) size, buf);
  3916. }
  3917. return 0;
  3918. }
  3919. static int i915_dpcd_open(struct inode *inode, struct file *file)
  3920. {
  3921. return single_open(file, i915_dpcd_show, inode->i_private);
  3922. }
  3923. static const struct file_operations i915_dpcd_fops = {
  3924. .owner = THIS_MODULE,
  3925. .open = i915_dpcd_open,
  3926. .read = seq_read,
  3927. .llseek = seq_lseek,
  3928. .release = single_release,
  3929. };
  3930. static int i915_panel_show(struct seq_file *m, void *data)
  3931. {
  3932. struct drm_connector *connector = m->private;
  3933. struct intel_dp *intel_dp =
  3934. enc_to_intel_dp(&intel_attached_encoder(connector)->base);
  3935. if (connector->status != connector_status_connected)
  3936. return -ENODEV;
  3937. seq_printf(m, "Panel power up delay: %d\n",
  3938. intel_dp->panel_power_up_delay);
  3939. seq_printf(m, "Panel power down delay: %d\n",
  3940. intel_dp->panel_power_down_delay);
  3941. seq_printf(m, "Backlight on delay: %d\n",
  3942. intel_dp->backlight_on_delay);
  3943. seq_printf(m, "Backlight off delay: %d\n",
  3944. intel_dp->backlight_off_delay);
  3945. return 0;
  3946. }
  3947. static int i915_panel_open(struct inode *inode, struct file *file)
  3948. {
  3949. return single_open(file, i915_panel_show, inode->i_private);
  3950. }
  3951. static const struct file_operations i915_panel_fops = {
  3952. .owner = THIS_MODULE,
  3953. .open = i915_panel_open,
  3954. .read = seq_read,
  3955. .llseek = seq_lseek,
  3956. .release = single_release,
  3957. };
  3958. /**
  3959. * i915_debugfs_connector_add - add i915 specific connector debugfs files
  3960. * @connector: pointer to a registered drm_connector
  3961. *
  3962. * Cleanup will be done by drm_connector_unregister() through a call to
  3963. * drm_debugfs_connector_remove().
  3964. *
  3965. * Returns 0 on success, negative error codes on error.
  3966. */
  3967. int i915_debugfs_connector_add(struct drm_connector *connector)
  3968. {
  3969. struct dentry *root = connector->debugfs_entry;
  3970. /* The connector must have been registered beforehands. */
  3971. if (!root)
  3972. return -ENODEV;
  3973. if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
  3974. connector->connector_type == DRM_MODE_CONNECTOR_eDP)
  3975. debugfs_create_file("i915_dpcd", S_IRUGO, root,
  3976. connector, &i915_dpcd_fops);
  3977. if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
  3978. debugfs_create_file("i915_panel_timings", S_IRUGO, root,
  3979. connector, &i915_panel_fops);
  3980. return 0;
  3981. }