i915_debugfs.c 152 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670
  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/seq_file.h>
  29. #include <linux/circ_buf.h>
  30. #include <linux/ctype.h>
  31. #include <linux/debugfs.h>
  32. #include <linux/slab.h>
  33. #include <linux/export.h>
  34. #include <linux/list_sort.h>
  35. #include <asm/msr-index.h>
  36. #include <drm/drmP.h>
  37. #include "intel_drv.h"
  38. #include "intel_ringbuffer.h"
  39. #include <drm/i915_drm.h>
  40. #include "i915_drv.h"
  41. static inline struct drm_i915_private *node_to_i915(struct drm_info_node *node)
  42. {
  43. return to_i915(node->minor->dev);
  44. }
  45. /* As the drm_debugfs_init() routines are called before dev->dev_private is
  46. * allocated we need to hook into the minor for release. */
  47. static int
  48. drm_add_fake_info_node(struct drm_minor *minor,
  49. struct dentry *ent,
  50. const void *key)
  51. {
  52. struct drm_info_node *node;
  53. node = kmalloc(sizeof(*node), GFP_KERNEL);
  54. if (node == NULL) {
  55. debugfs_remove(ent);
  56. return -ENOMEM;
  57. }
  58. node->minor = minor;
  59. node->dent = ent;
  60. node->info_ent = (void *)key;
  61. mutex_lock(&minor->debugfs_lock);
  62. list_add(&node->list, &minor->debugfs_list);
  63. mutex_unlock(&minor->debugfs_lock);
  64. return 0;
  65. }
  66. static int i915_capabilities(struct seq_file *m, void *data)
  67. {
  68. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  69. const struct intel_device_info *info = INTEL_INFO(dev_priv);
  70. seq_printf(m, "gen: %d\n", INTEL_GEN(dev_priv));
  71. seq_printf(m, "pch: %d\n", INTEL_PCH_TYPE(dev_priv));
  72. #define PRINT_FLAG(x) seq_printf(m, #x ": %s\n", yesno(info->x))
  73. DEV_INFO_FOR_EACH_FLAG(PRINT_FLAG);
  74. #undef PRINT_FLAG
  75. return 0;
  76. }
  77. static char get_active_flag(struct drm_i915_gem_object *obj)
  78. {
  79. return i915_gem_object_is_active(obj) ? '*' : ' ';
  80. }
  81. static char get_pin_flag(struct drm_i915_gem_object *obj)
  82. {
  83. return obj->pin_display ? 'p' : ' ';
  84. }
  85. static char get_tiling_flag(struct drm_i915_gem_object *obj)
  86. {
  87. switch (i915_gem_object_get_tiling(obj)) {
  88. default:
  89. case I915_TILING_NONE: return ' ';
  90. case I915_TILING_X: return 'X';
  91. case I915_TILING_Y: return 'Y';
  92. }
  93. }
  94. static char get_global_flag(struct drm_i915_gem_object *obj)
  95. {
  96. return !list_empty(&obj->userfault_link) ? 'g' : ' ';
  97. }
  98. static char get_pin_mapped_flag(struct drm_i915_gem_object *obj)
  99. {
  100. return obj->mm.mapping ? 'M' : ' ';
  101. }
  102. static u64 i915_gem_obj_total_ggtt_size(struct drm_i915_gem_object *obj)
  103. {
  104. u64 size = 0;
  105. struct i915_vma *vma;
  106. list_for_each_entry(vma, &obj->vma_list, obj_link) {
  107. if (i915_vma_is_ggtt(vma) && drm_mm_node_allocated(&vma->node))
  108. size += vma->node.size;
  109. }
  110. return size;
  111. }
  112. static void
  113. describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
  114. {
  115. struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
  116. struct intel_engine_cs *engine;
  117. struct i915_vma *vma;
  118. unsigned int frontbuffer_bits;
  119. int pin_count = 0;
  120. lockdep_assert_held(&obj->base.dev->struct_mutex);
  121. seq_printf(m, "%pK: %c%c%c%c%c %8zdKiB %02x %02x %s%s%s",
  122. &obj->base,
  123. get_active_flag(obj),
  124. get_pin_flag(obj),
  125. get_tiling_flag(obj),
  126. get_global_flag(obj),
  127. get_pin_mapped_flag(obj),
  128. obj->base.size / 1024,
  129. obj->base.read_domains,
  130. obj->base.write_domain,
  131. i915_cache_level_str(dev_priv, obj->cache_level),
  132. obj->mm.dirty ? " dirty" : "",
  133. obj->mm.madv == I915_MADV_DONTNEED ? " purgeable" : "");
  134. if (obj->base.name)
  135. seq_printf(m, " (name: %d)", obj->base.name);
  136. list_for_each_entry(vma, &obj->vma_list, obj_link) {
  137. if (i915_vma_is_pinned(vma))
  138. pin_count++;
  139. }
  140. seq_printf(m, " (pinned x %d)", pin_count);
  141. if (obj->pin_display)
  142. seq_printf(m, " (display)");
  143. list_for_each_entry(vma, &obj->vma_list, obj_link) {
  144. if (!drm_mm_node_allocated(&vma->node))
  145. continue;
  146. seq_printf(m, " (%sgtt offset: %08llx, size: %08llx",
  147. i915_vma_is_ggtt(vma) ? "g" : "pp",
  148. vma->node.start, vma->node.size);
  149. if (i915_vma_is_ggtt(vma))
  150. seq_printf(m, ", type: %u", vma->ggtt_view.type);
  151. if (vma->fence)
  152. seq_printf(m, " , fence: %d%s",
  153. vma->fence->id,
  154. i915_gem_active_isset(&vma->last_fence) ? "*" : "");
  155. seq_puts(m, ")");
  156. }
  157. if (obj->stolen)
  158. seq_printf(m, " (stolen: %08llx)", obj->stolen->start);
  159. engine = i915_gem_object_last_write_engine(obj);
  160. if (engine)
  161. seq_printf(m, " (%s)", engine->name);
  162. frontbuffer_bits = atomic_read(&obj->frontbuffer_bits);
  163. if (frontbuffer_bits)
  164. seq_printf(m, " (frontbuffer: 0x%03x)", frontbuffer_bits);
  165. }
  166. static int obj_rank_by_stolen(void *priv,
  167. struct list_head *A, struct list_head *B)
  168. {
  169. struct drm_i915_gem_object *a =
  170. container_of(A, struct drm_i915_gem_object, obj_exec_link);
  171. struct drm_i915_gem_object *b =
  172. container_of(B, struct drm_i915_gem_object, obj_exec_link);
  173. if (a->stolen->start < b->stolen->start)
  174. return -1;
  175. if (a->stolen->start > b->stolen->start)
  176. return 1;
  177. return 0;
  178. }
  179. static int i915_gem_stolen_list_info(struct seq_file *m, void *data)
  180. {
  181. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  182. struct drm_device *dev = &dev_priv->drm;
  183. struct drm_i915_gem_object *obj;
  184. u64 total_obj_size, total_gtt_size;
  185. LIST_HEAD(stolen);
  186. int count, ret;
  187. ret = mutex_lock_interruptible(&dev->struct_mutex);
  188. if (ret)
  189. return ret;
  190. total_obj_size = total_gtt_size = count = 0;
  191. list_for_each_entry(obj, &dev_priv->mm.bound_list, global_link) {
  192. if (obj->stolen == NULL)
  193. continue;
  194. list_add(&obj->obj_exec_link, &stolen);
  195. total_obj_size += obj->base.size;
  196. total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
  197. count++;
  198. }
  199. list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_link) {
  200. if (obj->stolen == NULL)
  201. continue;
  202. list_add(&obj->obj_exec_link, &stolen);
  203. total_obj_size += obj->base.size;
  204. count++;
  205. }
  206. list_sort(NULL, &stolen, obj_rank_by_stolen);
  207. seq_puts(m, "Stolen:\n");
  208. while (!list_empty(&stolen)) {
  209. obj = list_first_entry(&stolen, typeof(*obj), obj_exec_link);
  210. seq_puts(m, " ");
  211. describe_obj(m, obj);
  212. seq_putc(m, '\n');
  213. list_del_init(&obj->obj_exec_link);
  214. }
  215. mutex_unlock(&dev->struct_mutex);
  216. seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
  217. count, total_obj_size, total_gtt_size);
  218. return 0;
  219. }
  220. struct file_stats {
  221. struct drm_i915_file_private *file_priv;
  222. unsigned long count;
  223. u64 total, unbound;
  224. u64 global, shared;
  225. u64 active, inactive;
  226. };
  227. static int per_file_stats(int id, void *ptr, void *data)
  228. {
  229. struct drm_i915_gem_object *obj = ptr;
  230. struct file_stats *stats = data;
  231. struct i915_vma *vma;
  232. stats->count++;
  233. stats->total += obj->base.size;
  234. if (!obj->bind_count)
  235. stats->unbound += obj->base.size;
  236. if (obj->base.name || obj->base.dma_buf)
  237. stats->shared += obj->base.size;
  238. list_for_each_entry(vma, &obj->vma_list, obj_link) {
  239. if (!drm_mm_node_allocated(&vma->node))
  240. continue;
  241. if (i915_vma_is_ggtt(vma)) {
  242. stats->global += vma->node.size;
  243. } else {
  244. struct i915_hw_ppgtt *ppgtt = i915_vm_to_ppgtt(vma->vm);
  245. if (ppgtt->base.file != stats->file_priv)
  246. continue;
  247. }
  248. if (i915_vma_is_active(vma))
  249. stats->active += vma->node.size;
  250. else
  251. stats->inactive += vma->node.size;
  252. }
  253. return 0;
  254. }
  255. #define print_file_stats(m, name, stats) do { \
  256. if (stats.count) \
  257. seq_printf(m, "%s: %lu objects, %llu bytes (%llu active, %llu inactive, %llu global, %llu shared, %llu unbound)\n", \
  258. name, \
  259. stats.count, \
  260. stats.total, \
  261. stats.active, \
  262. stats.inactive, \
  263. stats.global, \
  264. stats.shared, \
  265. stats.unbound); \
  266. } while (0)
  267. static void print_batch_pool_stats(struct seq_file *m,
  268. struct drm_i915_private *dev_priv)
  269. {
  270. struct drm_i915_gem_object *obj;
  271. struct file_stats stats;
  272. struct intel_engine_cs *engine;
  273. enum intel_engine_id id;
  274. int j;
  275. memset(&stats, 0, sizeof(stats));
  276. for_each_engine(engine, dev_priv, id) {
  277. for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
  278. list_for_each_entry(obj,
  279. &engine->batch_pool.cache_list[j],
  280. batch_pool_link)
  281. per_file_stats(0, obj, &stats);
  282. }
  283. }
  284. print_file_stats(m, "[k]batch pool", stats);
  285. }
  286. static int per_file_ctx_stats(int id, void *ptr, void *data)
  287. {
  288. struct i915_gem_context *ctx = ptr;
  289. int n;
  290. for (n = 0; n < ARRAY_SIZE(ctx->engine); n++) {
  291. if (ctx->engine[n].state)
  292. per_file_stats(0, ctx->engine[n].state->obj, data);
  293. if (ctx->engine[n].ring)
  294. per_file_stats(0, ctx->engine[n].ring->vma->obj, data);
  295. }
  296. return 0;
  297. }
  298. static void print_context_stats(struct seq_file *m,
  299. struct drm_i915_private *dev_priv)
  300. {
  301. struct drm_device *dev = &dev_priv->drm;
  302. struct file_stats stats;
  303. struct drm_file *file;
  304. memset(&stats, 0, sizeof(stats));
  305. mutex_lock(&dev->struct_mutex);
  306. if (dev_priv->kernel_context)
  307. per_file_ctx_stats(0, dev_priv->kernel_context, &stats);
  308. list_for_each_entry(file, &dev->filelist, lhead) {
  309. struct drm_i915_file_private *fpriv = file->driver_priv;
  310. idr_for_each(&fpriv->context_idr, per_file_ctx_stats, &stats);
  311. }
  312. mutex_unlock(&dev->struct_mutex);
  313. print_file_stats(m, "[k]contexts", stats);
  314. }
  315. static int i915_gem_object_info(struct seq_file *m, void *data)
  316. {
  317. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  318. struct drm_device *dev = &dev_priv->drm;
  319. struct i915_ggtt *ggtt = &dev_priv->ggtt;
  320. u32 count, mapped_count, purgeable_count, dpy_count;
  321. u64 size, mapped_size, purgeable_size, dpy_size;
  322. struct drm_i915_gem_object *obj;
  323. struct drm_file *file;
  324. int ret;
  325. ret = mutex_lock_interruptible(&dev->struct_mutex);
  326. if (ret)
  327. return ret;
  328. seq_printf(m, "%u objects, %llu bytes\n",
  329. dev_priv->mm.object_count,
  330. dev_priv->mm.object_memory);
  331. size = count = 0;
  332. mapped_size = mapped_count = 0;
  333. purgeable_size = purgeable_count = 0;
  334. list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_link) {
  335. size += obj->base.size;
  336. ++count;
  337. if (obj->mm.madv == I915_MADV_DONTNEED) {
  338. purgeable_size += obj->base.size;
  339. ++purgeable_count;
  340. }
  341. if (obj->mm.mapping) {
  342. mapped_count++;
  343. mapped_size += obj->base.size;
  344. }
  345. }
  346. seq_printf(m, "%u unbound objects, %llu bytes\n", count, size);
  347. size = count = dpy_size = dpy_count = 0;
  348. list_for_each_entry(obj, &dev_priv->mm.bound_list, global_link) {
  349. size += obj->base.size;
  350. ++count;
  351. if (obj->pin_display) {
  352. dpy_size += obj->base.size;
  353. ++dpy_count;
  354. }
  355. if (obj->mm.madv == I915_MADV_DONTNEED) {
  356. purgeable_size += obj->base.size;
  357. ++purgeable_count;
  358. }
  359. if (obj->mm.mapping) {
  360. mapped_count++;
  361. mapped_size += obj->base.size;
  362. }
  363. }
  364. seq_printf(m, "%u bound objects, %llu bytes\n",
  365. count, size);
  366. seq_printf(m, "%u purgeable objects, %llu bytes\n",
  367. purgeable_count, purgeable_size);
  368. seq_printf(m, "%u mapped objects, %llu bytes\n",
  369. mapped_count, mapped_size);
  370. seq_printf(m, "%u display objects (pinned), %llu bytes\n",
  371. dpy_count, dpy_size);
  372. seq_printf(m, "%llu [%llu] gtt total\n",
  373. ggtt->base.total, ggtt->mappable_end - ggtt->base.start);
  374. seq_putc(m, '\n');
  375. print_batch_pool_stats(m, dev_priv);
  376. mutex_unlock(&dev->struct_mutex);
  377. mutex_lock(&dev->filelist_mutex);
  378. print_context_stats(m, dev_priv);
  379. list_for_each_entry_reverse(file, &dev->filelist, lhead) {
  380. struct file_stats stats;
  381. struct drm_i915_file_private *file_priv = file->driver_priv;
  382. struct drm_i915_gem_request *request;
  383. struct task_struct *task;
  384. memset(&stats, 0, sizeof(stats));
  385. stats.file_priv = file->driver_priv;
  386. spin_lock(&file->table_lock);
  387. idr_for_each(&file->object_idr, per_file_stats, &stats);
  388. spin_unlock(&file->table_lock);
  389. /*
  390. * Although we have a valid reference on file->pid, that does
  391. * not guarantee that the task_struct who called get_pid() is
  392. * still alive (e.g. get_pid(current) => fork() => exit()).
  393. * Therefore, we need to protect this ->comm access using RCU.
  394. */
  395. mutex_lock(&dev->struct_mutex);
  396. request = list_first_entry_or_null(&file_priv->mm.request_list,
  397. struct drm_i915_gem_request,
  398. client_list);
  399. rcu_read_lock();
  400. task = pid_task(request && request->ctx->pid ?
  401. request->ctx->pid : file->pid,
  402. PIDTYPE_PID);
  403. print_file_stats(m, task ? task->comm : "<unknown>", stats);
  404. rcu_read_unlock();
  405. mutex_unlock(&dev->struct_mutex);
  406. }
  407. mutex_unlock(&dev->filelist_mutex);
  408. return 0;
  409. }
  410. static int i915_gem_gtt_info(struct seq_file *m, void *data)
  411. {
  412. struct drm_info_node *node = m->private;
  413. struct drm_i915_private *dev_priv = node_to_i915(node);
  414. struct drm_device *dev = &dev_priv->drm;
  415. bool show_pin_display_only = !!node->info_ent->data;
  416. struct drm_i915_gem_object *obj;
  417. u64 total_obj_size, total_gtt_size;
  418. int count, ret;
  419. ret = mutex_lock_interruptible(&dev->struct_mutex);
  420. if (ret)
  421. return ret;
  422. total_obj_size = total_gtt_size = count = 0;
  423. list_for_each_entry(obj, &dev_priv->mm.bound_list, global_link) {
  424. if (show_pin_display_only && !obj->pin_display)
  425. continue;
  426. seq_puts(m, " ");
  427. describe_obj(m, obj);
  428. seq_putc(m, '\n');
  429. total_obj_size += obj->base.size;
  430. total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
  431. count++;
  432. }
  433. mutex_unlock(&dev->struct_mutex);
  434. seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
  435. count, total_obj_size, total_gtt_size);
  436. return 0;
  437. }
  438. static int i915_gem_pageflip_info(struct seq_file *m, void *data)
  439. {
  440. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  441. struct drm_device *dev = &dev_priv->drm;
  442. struct intel_crtc *crtc;
  443. int ret;
  444. ret = mutex_lock_interruptible(&dev->struct_mutex);
  445. if (ret)
  446. return ret;
  447. for_each_intel_crtc(dev, crtc) {
  448. const char pipe = pipe_name(crtc->pipe);
  449. const char plane = plane_name(crtc->plane);
  450. struct intel_flip_work *work;
  451. spin_lock_irq(&dev->event_lock);
  452. work = crtc->flip_work;
  453. if (work == NULL) {
  454. seq_printf(m, "No flip due on pipe %c (plane %c)\n",
  455. pipe, plane);
  456. } else {
  457. u32 pending;
  458. u32 addr;
  459. pending = atomic_read(&work->pending);
  460. if (pending) {
  461. seq_printf(m, "Flip ioctl preparing on pipe %c (plane %c)\n",
  462. pipe, plane);
  463. } else {
  464. seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
  465. pipe, plane);
  466. }
  467. if (work->flip_queued_req) {
  468. struct intel_engine_cs *engine = work->flip_queued_req->engine;
  469. seq_printf(m, "Flip queued on %s at seqno %x, last submitted seqno %x [current breadcrumb %x], completed? %d\n",
  470. engine->name,
  471. work->flip_queued_req->global_seqno,
  472. intel_engine_last_submit(engine),
  473. intel_engine_get_seqno(engine),
  474. i915_gem_request_completed(work->flip_queued_req));
  475. } else
  476. seq_printf(m, "Flip not associated with any ring\n");
  477. seq_printf(m, "Flip queued on frame %d, (was ready on frame %d), now %d\n",
  478. work->flip_queued_vblank,
  479. work->flip_ready_vblank,
  480. intel_crtc_get_vblank_counter(crtc));
  481. seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
  482. if (INTEL_GEN(dev_priv) >= 4)
  483. addr = I915_HI_DISPBASE(I915_READ(DSPSURF(crtc->plane)));
  484. else
  485. addr = I915_READ(DSPADDR(crtc->plane));
  486. seq_printf(m, "Current scanout address 0x%08x\n", addr);
  487. if (work->pending_flip_obj) {
  488. seq_printf(m, "New framebuffer address 0x%08lx\n", (long)work->gtt_offset);
  489. seq_printf(m, "MMIO update completed? %d\n", addr == work->gtt_offset);
  490. }
  491. }
  492. spin_unlock_irq(&dev->event_lock);
  493. }
  494. mutex_unlock(&dev->struct_mutex);
  495. return 0;
  496. }
  497. static int i915_gem_batch_pool_info(struct seq_file *m, void *data)
  498. {
  499. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  500. struct drm_device *dev = &dev_priv->drm;
  501. struct drm_i915_gem_object *obj;
  502. struct intel_engine_cs *engine;
  503. enum intel_engine_id id;
  504. int total = 0;
  505. int ret, j;
  506. ret = mutex_lock_interruptible(&dev->struct_mutex);
  507. if (ret)
  508. return ret;
  509. for_each_engine(engine, dev_priv, id) {
  510. for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
  511. int count;
  512. count = 0;
  513. list_for_each_entry(obj,
  514. &engine->batch_pool.cache_list[j],
  515. batch_pool_link)
  516. count++;
  517. seq_printf(m, "%s cache[%d]: %d objects\n",
  518. engine->name, j, count);
  519. list_for_each_entry(obj,
  520. &engine->batch_pool.cache_list[j],
  521. batch_pool_link) {
  522. seq_puts(m, " ");
  523. describe_obj(m, obj);
  524. seq_putc(m, '\n');
  525. }
  526. total += count;
  527. }
  528. }
  529. seq_printf(m, "total: %d\n", total);
  530. mutex_unlock(&dev->struct_mutex);
  531. return 0;
  532. }
  533. static void print_request(struct seq_file *m,
  534. struct drm_i915_gem_request *rq,
  535. const char *prefix)
  536. {
  537. seq_printf(m, "%s%x [%x:%x] prio=%d @ %dms: %s\n", prefix,
  538. rq->global_seqno, rq->ctx->hw_id, rq->fence.seqno,
  539. rq->priotree.priority,
  540. jiffies_to_msecs(jiffies - rq->emitted_jiffies),
  541. rq->timeline->common->name);
  542. }
  543. static int i915_gem_request_info(struct seq_file *m, void *data)
  544. {
  545. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  546. struct drm_device *dev = &dev_priv->drm;
  547. struct drm_i915_gem_request *req;
  548. struct intel_engine_cs *engine;
  549. enum intel_engine_id id;
  550. int ret, any;
  551. ret = mutex_lock_interruptible(&dev->struct_mutex);
  552. if (ret)
  553. return ret;
  554. any = 0;
  555. for_each_engine(engine, dev_priv, id) {
  556. int count;
  557. count = 0;
  558. list_for_each_entry(req, &engine->timeline->requests, link)
  559. count++;
  560. if (count == 0)
  561. continue;
  562. seq_printf(m, "%s requests: %d\n", engine->name, count);
  563. list_for_each_entry(req, &engine->timeline->requests, link)
  564. print_request(m, req, " ");
  565. any++;
  566. }
  567. mutex_unlock(&dev->struct_mutex);
  568. if (any == 0)
  569. seq_puts(m, "No requests\n");
  570. return 0;
  571. }
  572. static void i915_ring_seqno_info(struct seq_file *m,
  573. struct intel_engine_cs *engine)
  574. {
  575. struct intel_breadcrumbs *b = &engine->breadcrumbs;
  576. struct rb_node *rb;
  577. seq_printf(m, "Current sequence (%s): %x\n",
  578. engine->name, intel_engine_get_seqno(engine));
  579. spin_lock_irq(&b->lock);
  580. for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
  581. struct intel_wait *w = container_of(rb, typeof(*w), node);
  582. seq_printf(m, "Waiting (%s): %s [%d] on %x\n",
  583. engine->name, w->tsk->comm, w->tsk->pid, w->seqno);
  584. }
  585. spin_unlock_irq(&b->lock);
  586. }
  587. static int i915_gem_seqno_info(struct seq_file *m, void *data)
  588. {
  589. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  590. struct intel_engine_cs *engine;
  591. enum intel_engine_id id;
  592. for_each_engine(engine, dev_priv, id)
  593. i915_ring_seqno_info(m, engine);
  594. return 0;
  595. }
  596. static int i915_interrupt_info(struct seq_file *m, void *data)
  597. {
  598. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  599. struct intel_engine_cs *engine;
  600. enum intel_engine_id id;
  601. int i, pipe;
  602. intel_runtime_pm_get(dev_priv);
  603. if (IS_CHERRYVIEW(dev_priv)) {
  604. seq_printf(m, "Master Interrupt Control:\t%08x\n",
  605. I915_READ(GEN8_MASTER_IRQ));
  606. seq_printf(m, "Display IER:\t%08x\n",
  607. I915_READ(VLV_IER));
  608. seq_printf(m, "Display IIR:\t%08x\n",
  609. I915_READ(VLV_IIR));
  610. seq_printf(m, "Display IIR_RW:\t%08x\n",
  611. I915_READ(VLV_IIR_RW));
  612. seq_printf(m, "Display IMR:\t%08x\n",
  613. I915_READ(VLV_IMR));
  614. for_each_pipe(dev_priv, pipe) {
  615. enum intel_display_power_domain power_domain;
  616. power_domain = POWER_DOMAIN_PIPE(pipe);
  617. if (!intel_display_power_get_if_enabled(dev_priv,
  618. power_domain)) {
  619. seq_printf(m, "Pipe %c power disabled\n",
  620. pipe_name(pipe));
  621. continue;
  622. }
  623. seq_printf(m, "Pipe %c stat:\t%08x\n",
  624. pipe_name(pipe),
  625. I915_READ(PIPESTAT(pipe)));
  626. intel_display_power_put(dev_priv, power_domain);
  627. }
  628. intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
  629. seq_printf(m, "Port hotplug:\t%08x\n",
  630. I915_READ(PORT_HOTPLUG_EN));
  631. seq_printf(m, "DPFLIPSTAT:\t%08x\n",
  632. I915_READ(VLV_DPFLIPSTAT));
  633. seq_printf(m, "DPINVGTT:\t%08x\n",
  634. I915_READ(DPINVGTT));
  635. intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
  636. for (i = 0; i < 4; i++) {
  637. seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
  638. i, I915_READ(GEN8_GT_IMR(i)));
  639. seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
  640. i, I915_READ(GEN8_GT_IIR(i)));
  641. seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
  642. i, I915_READ(GEN8_GT_IER(i)));
  643. }
  644. seq_printf(m, "PCU interrupt mask:\t%08x\n",
  645. I915_READ(GEN8_PCU_IMR));
  646. seq_printf(m, "PCU interrupt identity:\t%08x\n",
  647. I915_READ(GEN8_PCU_IIR));
  648. seq_printf(m, "PCU interrupt enable:\t%08x\n",
  649. I915_READ(GEN8_PCU_IER));
  650. } else if (INTEL_GEN(dev_priv) >= 8) {
  651. seq_printf(m, "Master Interrupt Control:\t%08x\n",
  652. I915_READ(GEN8_MASTER_IRQ));
  653. for (i = 0; i < 4; i++) {
  654. seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
  655. i, I915_READ(GEN8_GT_IMR(i)));
  656. seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
  657. i, I915_READ(GEN8_GT_IIR(i)));
  658. seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
  659. i, I915_READ(GEN8_GT_IER(i)));
  660. }
  661. for_each_pipe(dev_priv, pipe) {
  662. enum intel_display_power_domain power_domain;
  663. power_domain = POWER_DOMAIN_PIPE(pipe);
  664. if (!intel_display_power_get_if_enabled(dev_priv,
  665. power_domain)) {
  666. seq_printf(m, "Pipe %c power disabled\n",
  667. pipe_name(pipe));
  668. continue;
  669. }
  670. seq_printf(m, "Pipe %c IMR:\t%08x\n",
  671. pipe_name(pipe),
  672. I915_READ(GEN8_DE_PIPE_IMR(pipe)));
  673. seq_printf(m, "Pipe %c IIR:\t%08x\n",
  674. pipe_name(pipe),
  675. I915_READ(GEN8_DE_PIPE_IIR(pipe)));
  676. seq_printf(m, "Pipe %c IER:\t%08x\n",
  677. pipe_name(pipe),
  678. I915_READ(GEN8_DE_PIPE_IER(pipe)));
  679. intel_display_power_put(dev_priv, power_domain);
  680. }
  681. seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
  682. I915_READ(GEN8_DE_PORT_IMR));
  683. seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
  684. I915_READ(GEN8_DE_PORT_IIR));
  685. seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
  686. I915_READ(GEN8_DE_PORT_IER));
  687. seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
  688. I915_READ(GEN8_DE_MISC_IMR));
  689. seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
  690. I915_READ(GEN8_DE_MISC_IIR));
  691. seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
  692. I915_READ(GEN8_DE_MISC_IER));
  693. seq_printf(m, "PCU interrupt mask:\t%08x\n",
  694. I915_READ(GEN8_PCU_IMR));
  695. seq_printf(m, "PCU interrupt identity:\t%08x\n",
  696. I915_READ(GEN8_PCU_IIR));
  697. seq_printf(m, "PCU interrupt enable:\t%08x\n",
  698. I915_READ(GEN8_PCU_IER));
  699. } else if (IS_VALLEYVIEW(dev_priv)) {
  700. seq_printf(m, "Display IER:\t%08x\n",
  701. I915_READ(VLV_IER));
  702. seq_printf(m, "Display IIR:\t%08x\n",
  703. I915_READ(VLV_IIR));
  704. seq_printf(m, "Display IIR_RW:\t%08x\n",
  705. I915_READ(VLV_IIR_RW));
  706. seq_printf(m, "Display IMR:\t%08x\n",
  707. I915_READ(VLV_IMR));
  708. for_each_pipe(dev_priv, pipe)
  709. seq_printf(m, "Pipe %c stat:\t%08x\n",
  710. pipe_name(pipe),
  711. I915_READ(PIPESTAT(pipe)));
  712. seq_printf(m, "Master IER:\t%08x\n",
  713. I915_READ(VLV_MASTER_IER));
  714. seq_printf(m, "Render IER:\t%08x\n",
  715. I915_READ(GTIER));
  716. seq_printf(m, "Render IIR:\t%08x\n",
  717. I915_READ(GTIIR));
  718. seq_printf(m, "Render IMR:\t%08x\n",
  719. I915_READ(GTIMR));
  720. seq_printf(m, "PM IER:\t\t%08x\n",
  721. I915_READ(GEN6_PMIER));
  722. seq_printf(m, "PM IIR:\t\t%08x\n",
  723. I915_READ(GEN6_PMIIR));
  724. seq_printf(m, "PM IMR:\t\t%08x\n",
  725. I915_READ(GEN6_PMIMR));
  726. seq_printf(m, "Port hotplug:\t%08x\n",
  727. I915_READ(PORT_HOTPLUG_EN));
  728. seq_printf(m, "DPFLIPSTAT:\t%08x\n",
  729. I915_READ(VLV_DPFLIPSTAT));
  730. seq_printf(m, "DPINVGTT:\t%08x\n",
  731. I915_READ(DPINVGTT));
  732. } else if (!HAS_PCH_SPLIT(dev_priv)) {
  733. seq_printf(m, "Interrupt enable: %08x\n",
  734. I915_READ(IER));
  735. seq_printf(m, "Interrupt identity: %08x\n",
  736. I915_READ(IIR));
  737. seq_printf(m, "Interrupt mask: %08x\n",
  738. I915_READ(IMR));
  739. for_each_pipe(dev_priv, pipe)
  740. seq_printf(m, "Pipe %c stat: %08x\n",
  741. pipe_name(pipe),
  742. I915_READ(PIPESTAT(pipe)));
  743. } else {
  744. seq_printf(m, "North Display Interrupt enable: %08x\n",
  745. I915_READ(DEIER));
  746. seq_printf(m, "North Display Interrupt identity: %08x\n",
  747. I915_READ(DEIIR));
  748. seq_printf(m, "North Display Interrupt mask: %08x\n",
  749. I915_READ(DEIMR));
  750. seq_printf(m, "South Display Interrupt enable: %08x\n",
  751. I915_READ(SDEIER));
  752. seq_printf(m, "South Display Interrupt identity: %08x\n",
  753. I915_READ(SDEIIR));
  754. seq_printf(m, "South Display Interrupt mask: %08x\n",
  755. I915_READ(SDEIMR));
  756. seq_printf(m, "Graphics Interrupt enable: %08x\n",
  757. I915_READ(GTIER));
  758. seq_printf(m, "Graphics Interrupt identity: %08x\n",
  759. I915_READ(GTIIR));
  760. seq_printf(m, "Graphics Interrupt mask: %08x\n",
  761. I915_READ(GTIMR));
  762. }
  763. for_each_engine(engine, dev_priv, id) {
  764. if (INTEL_GEN(dev_priv) >= 6) {
  765. seq_printf(m,
  766. "Graphics Interrupt mask (%s): %08x\n",
  767. engine->name, I915_READ_IMR(engine));
  768. }
  769. i915_ring_seqno_info(m, engine);
  770. }
  771. intel_runtime_pm_put(dev_priv);
  772. return 0;
  773. }
  774. static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
  775. {
  776. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  777. struct drm_device *dev = &dev_priv->drm;
  778. int i, ret;
  779. ret = mutex_lock_interruptible(&dev->struct_mutex);
  780. if (ret)
  781. return ret;
  782. seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
  783. for (i = 0; i < dev_priv->num_fence_regs; i++) {
  784. struct i915_vma *vma = dev_priv->fence_regs[i].vma;
  785. seq_printf(m, "Fence %d, pin count = %d, object = ",
  786. i, dev_priv->fence_regs[i].pin_count);
  787. if (!vma)
  788. seq_puts(m, "unused");
  789. else
  790. describe_obj(m, vma->obj);
  791. seq_putc(m, '\n');
  792. }
  793. mutex_unlock(&dev->struct_mutex);
  794. return 0;
  795. }
  796. #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
  797. static ssize_t
  798. i915_error_state_write(struct file *filp,
  799. const char __user *ubuf,
  800. size_t cnt,
  801. loff_t *ppos)
  802. {
  803. struct i915_error_state_file_priv *error_priv = filp->private_data;
  804. DRM_DEBUG_DRIVER("Resetting error state\n");
  805. i915_destroy_error_state(error_priv->dev);
  806. return cnt;
  807. }
  808. static int i915_error_state_open(struct inode *inode, struct file *file)
  809. {
  810. struct drm_i915_private *dev_priv = inode->i_private;
  811. struct i915_error_state_file_priv *error_priv;
  812. error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
  813. if (!error_priv)
  814. return -ENOMEM;
  815. error_priv->dev = &dev_priv->drm;
  816. i915_error_state_get(&dev_priv->drm, error_priv);
  817. file->private_data = error_priv;
  818. return 0;
  819. }
  820. static int i915_error_state_release(struct inode *inode, struct file *file)
  821. {
  822. struct i915_error_state_file_priv *error_priv = file->private_data;
  823. i915_error_state_put(error_priv);
  824. kfree(error_priv);
  825. return 0;
  826. }
  827. static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
  828. size_t count, loff_t *pos)
  829. {
  830. struct i915_error_state_file_priv *error_priv = file->private_data;
  831. struct drm_i915_error_state_buf error_str;
  832. loff_t tmp_pos = 0;
  833. ssize_t ret_count = 0;
  834. int ret;
  835. ret = i915_error_state_buf_init(&error_str,
  836. to_i915(error_priv->dev), count, *pos);
  837. if (ret)
  838. return ret;
  839. ret = i915_error_state_to_str(&error_str, error_priv);
  840. if (ret)
  841. goto out;
  842. ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
  843. error_str.buf,
  844. error_str.bytes);
  845. if (ret_count < 0)
  846. ret = ret_count;
  847. else
  848. *pos = error_str.start + ret_count;
  849. out:
  850. i915_error_state_buf_release(&error_str);
  851. return ret ?: ret_count;
  852. }
  853. static const struct file_operations i915_error_state_fops = {
  854. .owner = THIS_MODULE,
  855. .open = i915_error_state_open,
  856. .read = i915_error_state_read,
  857. .write = i915_error_state_write,
  858. .llseek = default_llseek,
  859. .release = i915_error_state_release,
  860. };
  861. #endif
  862. static int
  863. i915_next_seqno_get(void *data, u64 *val)
  864. {
  865. struct drm_i915_private *dev_priv = data;
  866. *val = 1 + atomic_read(&dev_priv->gt.global_timeline.seqno);
  867. return 0;
  868. }
  869. static int
  870. i915_next_seqno_set(void *data, u64 val)
  871. {
  872. struct drm_i915_private *dev_priv = data;
  873. struct drm_device *dev = &dev_priv->drm;
  874. int ret;
  875. ret = mutex_lock_interruptible(&dev->struct_mutex);
  876. if (ret)
  877. return ret;
  878. ret = i915_gem_set_global_seqno(dev, val);
  879. mutex_unlock(&dev->struct_mutex);
  880. return ret;
  881. }
  882. DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
  883. i915_next_seqno_get, i915_next_seqno_set,
  884. "0x%llx\n");
  885. static int i915_frequency_info(struct seq_file *m, void *unused)
  886. {
  887. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  888. struct drm_device *dev = &dev_priv->drm;
  889. int ret = 0;
  890. intel_runtime_pm_get(dev_priv);
  891. if (IS_GEN5(dev_priv)) {
  892. u16 rgvswctl = I915_READ16(MEMSWCTL);
  893. u16 rgvstat = I915_READ16(MEMSTAT_ILK);
  894. seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
  895. seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
  896. seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
  897. MEMSTAT_VID_SHIFT);
  898. seq_printf(m, "Current P-state: %d\n",
  899. (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
  900. } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
  901. u32 freq_sts;
  902. mutex_lock(&dev_priv->rps.hw_lock);
  903. freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
  904. seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
  905. seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
  906. seq_printf(m, "actual GPU freq: %d MHz\n",
  907. intel_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
  908. seq_printf(m, "current GPU freq: %d MHz\n",
  909. intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
  910. seq_printf(m, "max GPU freq: %d MHz\n",
  911. intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
  912. seq_printf(m, "min GPU freq: %d MHz\n",
  913. intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
  914. seq_printf(m, "idle GPU freq: %d MHz\n",
  915. intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
  916. seq_printf(m,
  917. "efficient (RPe) frequency: %d MHz\n",
  918. intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
  919. mutex_unlock(&dev_priv->rps.hw_lock);
  920. } else if (INTEL_GEN(dev_priv) >= 6) {
  921. u32 rp_state_limits;
  922. u32 gt_perf_status;
  923. u32 rp_state_cap;
  924. u32 rpmodectl, rpinclimit, rpdeclimit;
  925. u32 rpstat, cagf, reqf;
  926. u32 rpupei, rpcurup, rpprevup;
  927. u32 rpdownei, rpcurdown, rpprevdown;
  928. u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
  929. int max_freq;
  930. rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
  931. if (IS_BROXTON(dev_priv)) {
  932. rp_state_cap = I915_READ(BXT_RP_STATE_CAP);
  933. gt_perf_status = I915_READ(BXT_GT_PERF_STATUS);
  934. } else {
  935. rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
  936. gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
  937. }
  938. /* RPSTAT1 is in the GT power well */
  939. ret = mutex_lock_interruptible(&dev->struct_mutex);
  940. if (ret)
  941. goto out;
  942. intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
  943. reqf = I915_READ(GEN6_RPNSWREQ);
  944. if (IS_GEN9(dev_priv))
  945. reqf >>= 23;
  946. else {
  947. reqf &= ~GEN6_TURBO_DISABLE;
  948. if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
  949. reqf >>= 24;
  950. else
  951. reqf >>= 25;
  952. }
  953. reqf = intel_gpu_freq(dev_priv, reqf);
  954. rpmodectl = I915_READ(GEN6_RP_CONTROL);
  955. rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
  956. rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
  957. rpstat = I915_READ(GEN6_RPSTAT1);
  958. rpupei = I915_READ(GEN6_RP_CUR_UP_EI) & GEN6_CURICONT_MASK;
  959. rpcurup = I915_READ(GEN6_RP_CUR_UP) & GEN6_CURBSYTAVG_MASK;
  960. rpprevup = I915_READ(GEN6_RP_PREV_UP) & GEN6_CURBSYTAVG_MASK;
  961. rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI) & GEN6_CURIAVG_MASK;
  962. rpcurdown = I915_READ(GEN6_RP_CUR_DOWN) & GEN6_CURBSYTAVG_MASK;
  963. rpprevdown = I915_READ(GEN6_RP_PREV_DOWN) & GEN6_CURBSYTAVG_MASK;
  964. if (IS_GEN9(dev_priv))
  965. cagf = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT;
  966. else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
  967. cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
  968. else
  969. cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
  970. cagf = intel_gpu_freq(dev_priv, cagf);
  971. intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
  972. mutex_unlock(&dev->struct_mutex);
  973. if (IS_GEN6(dev_priv) || IS_GEN7(dev_priv)) {
  974. pm_ier = I915_READ(GEN6_PMIER);
  975. pm_imr = I915_READ(GEN6_PMIMR);
  976. pm_isr = I915_READ(GEN6_PMISR);
  977. pm_iir = I915_READ(GEN6_PMIIR);
  978. pm_mask = I915_READ(GEN6_PMINTRMSK);
  979. } else {
  980. pm_ier = I915_READ(GEN8_GT_IER(2));
  981. pm_imr = I915_READ(GEN8_GT_IMR(2));
  982. pm_isr = I915_READ(GEN8_GT_ISR(2));
  983. pm_iir = I915_READ(GEN8_GT_IIR(2));
  984. pm_mask = I915_READ(GEN6_PMINTRMSK);
  985. }
  986. seq_printf(m, "PM IER=0x%08x IMR=0x%08x ISR=0x%08x IIR=0x%08x, MASK=0x%08x\n",
  987. pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
  988. seq_printf(m, "pm_intr_keep: 0x%08x\n", dev_priv->rps.pm_intr_keep);
  989. seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
  990. seq_printf(m, "Render p-state ratio: %d\n",
  991. (gt_perf_status & (IS_GEN9(dev_priv) ? 0x1ff00 : 0xff00)) >> 8);
  992. seq_printf(m, "Render p-state VID: %d\n",
  993. gt_perf_status & 0xff);
  994. seq_printf(m, "Render p-state limit: %d\n",
  995. rp_state_limits & 0xff);
  996. seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
  997. seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
  998. seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
  999. seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
  1000. seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
  1001. seq_printf(m, "CAGF: %dMHz\n", cagf);
  1002. seq_printf(m, "RP CUR UP EI: %d (%dus)\n",
  1003. rpupei, GT_PM_INTERVAL_TO_US(dev_priv, rpupei));
  1004. seq_printf(m, "RP CUR UP: %d (%dus)\n",
  1005. rpcurup, GT_PM_INTERVAL_TO_US(dev_priv, rpcurup));
  1006. seq_printf(m, "RP PREV UP: %d (%dus)\n",
  1007. rpprevup, GT_PM_INTERVAL_TO_US(dev_priv, rpprevup));
  1008. seq_printf(m, "Up threshold: %d%%\n",
  1009. dev_priv->rps.up_threshold);
  1010. seq_printf(m, "RP CUR DOWN EI: %d (%dus)\n",
  1011. rpdownei, GT_PM_INTERVAL_TO_US(dev_priv, rpdownei));
  1012. seq_printf(m, "RP CUR DOWN: %d (%dus)\n",
  1013. rpcurdown, GT_PM_INTERVAL_TO_US(dev_priv, rpcurdown));
  1014. seq_printf(m, "RP PREV DOWN: %d (%dus)\n",
  1015. rpprevdown, GT_PM_INTERVAL_TO_US(dev_priv, rpprevdown));
  1016. seq_printf(m, "Down threshold: %d%%\n",
  1017. dev_priv->rps.down_threshold);
  1018. max_freq = (IS_BROXTON(dev_priv) ? rp_state_cap >> 0 :
  1019. rp_state_cap >> 16) & 0xff;
  1020. max_freq *= (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
  1021. GEN9_FREQ_SCALER : 1);
  1022. seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
  1023. intel_gpu_freq(dev_priv, max_freq));
  1024. max_freq = (rp_state_cap & 0xff00) >> 8;
  1025. max_freq *= (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
  1026. GEN9_FREQ_SCALER : 1);
  1027. seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
  1028. intel_gpu_freq(dev_priv, max_freq));
  1029. max_freq = (IS_BROXTON(dev_priv) ? rp_state_cap >> 16 :
  1030. rp_state_cap >> 0) & 0xff;
  1031. max_freq *= (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
  1032. GEN9_FREQ_SCALER : 1);
  1033. seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
  1034. intel_gpu_freq(dev_priv, max_freq));
  1035. seq_printf(m, "Max overclocked frequency: %dMHz\n",
  1036. intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
  1037. seq_printf(m, "Current freq: %d MHz\n",
  1038. intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
  1039. seq_printf(m, "Actual freq: %d MHz\n", cagf);
  1040. seq_printf(m, "Idle freq: %d MHz\n",
  1041. intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
  1042. seq_printf(m, "Min freq: %d MHz\n",
  1043. intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
  1044. seq_printf(m, "Boost freq: %d MHz\n",
  1045. intel_gpu_freq(dev_priv, dev_priv->rps.boost_freq));
  1046. seq_printf(m, "Max freq: %d MHz\n",
  1047. intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
  1048. seq_printf(m,
  1049. "efficient (RPe) frequency: %d MHz\n",
  1050. intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
  1051. } else {
  1052. seq_puts(m, "no P-state info available\n");
  1053. }
  1054. seq_printf(m, "Current CD clock frequency: %d kHz\n", dev_priv->cdclk_freq);
  1055. seq_printf(m, "Max CD clock frequency: %d kHz\n", dev_priv->max_cdclk_freq);
  1056. seq_printf(m, "Max pixel clock frequency: %d kHz\n", dev_priv->max_dotclk_freq);
  1057. out:
  1058. intel_runtime_pm_put(dev_priv);
  1059. return ret;
  1060. }
  1061. static void i915_instdone_info(struct drm_i915_private *dev_priv,
  1062. struct seq_file *m,
  1063. struct intel_instdone *instdone)
  1064. {
  1065. int slice;
  1066. int subslice;
  1067. seq_printf(m, "\t\tINSTDONE: 0x%08x\n",
  1068. instdone->instdone);
  1069. if (INTEL_GEN(dev_priv) <= 3)
  1070. return;
  1071. seq_printf(m, "\t\tSC_INSTDONE: 0x%08x\n",
  1072. instdone->slice_common);
  1073. if (INTEL_GEN(dev_priv) <= 6)
  1074. return;
  1075. for_each_instdone_slice_subslice(dev_priv, slice, subslice)
  1076. seq_printf(m, "\t\tSAMPLER_INSTDONE[%d][%d]: 0x%08x\n",
  1077. slice, subslice, instdone->sampler[slice][subslice]);
  1078. for_each_instdone_slice_subslice(dev_priv, slice, subslice)
  1079. seq_printf(m, "\t\tROW_INSTDONE[%d][%d]: 0x%08x\n",
  1080. slice, subslice, instdone->row[slice][subslice]);
  1081. }
  1082. static int i915_hangcheck_info(struct seq_file *m, void *unused)
  1083. {
  1084. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1085. struct intel_engine_cs *engine;
  1086. u64 acthd[I915_NUM_ENGINES];
  1087. u32 seqno[I915_NUM_ENGINES];
  1088. struct intel_instdone instdone;
  1089. enum intel_engine_id id;
  1090. if (test_bit(I915_WEDGED, &dev_priv->gpu_error.flags))
  1091. seq_printf(m, "Wedged\n");
  1092. if (test_bit(I915_RESET_IN_PROGRESS, &dev_priv->gpu_error.flags))
  1093. seq_printf(m, "Reset in progress\n");
  1094. if (waitqueue_active(&dev_priv->gpu_error.wait_queue))
  1095. seq_printf(m, "Waiter holding struct mutex\n");
  1096. if (waitqueue_active(&dev_priv->gpu_error.reset_queue))
  1097. seq_printf(m, "struct_mutex blocked for reset\n");
  1098. if (!i915.enable_hangcheck) {
  1099. seq_printf(m, "Hangcheck disabled\n");
  1100. return 0;
  1101. }
  1102. intel_runtime_pm_get(dev_priv);
  1103. for_each_engine(engine, dev_priv, id) {
  1104. acthd[id] = intel_engine_get_active_head(engine);
  1105. seqno[id] = intel_engine_get_seqno(engine);
  1106. }
  1107. intel_engine_get_instdone(dev_priv->engine[RCS], &instdone);
  1108. intel_runtime_pm_put(dev_priv);
  1109. if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work)) {
  1110. seq_printf(m, "Hangcheck active, fires in %dms\n",
  1111. jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
  1112. jiffies));
  1113. } else
  1114. seq_printf(m, "Hangcheck inactive\n");
  1115. for_each_engine(engine, dev_priv, id) {
  1116. struct intel_breadcrumbs *b = &engine->breadcrumbs;
  1117. struct rb_node *rb;
  1118. seq_printf(m, "%s:\n", engine->name);
  1119. seq_printf(m, "\tseqno = %x [current %x, last %x]\n",
  1120. engine->hangcheck.seqno, seqno[id],
  1121. intel_engine_last_submit(engine));
  1122. seq_printf(m, "\twaiters? %s, fake irq active? %s, stalled? %s\n",
  1123. yesno(intel_engine_has_waiter(engine)),
  1124. yesno(test_bit(engine->id,
  1125. &dev_priv->gpu_error.missed_irq_rings)),
  1126. yesno(engine->hangcheck.stalled));
  1127. spin_lock_irq(&b->lock);
  1128. for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
  1129. struct intel_wait *w = container_of(rb, typeof(*w), node);
  1130. seq_printf(m, "\t%s [%d] waiting for %x\n",
  1131. w->tsk->comm, w->tsk->pid, w->seqno);
  1132. }
  1133. spin_unlock_irq(&b->lock);
  1134. seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
  1135. (long long)engine->hangcheck.acthd,
  1136. (long long)acthd[id]);
  1137. seq_printf(m, "\taction = %s(%d) %d ms ago\n",
  1138. hangcheck_action_to_str(engine->hangcheck.action),
  1139. engine->hangcheck.action,
  1140. jiffies_to_msecs(jiffies -
  1141. engine->hangcheck.action_timestamp));
  1142. if (engine->id == RCS) {
  1143. seq_puts(m, "\tinstdone read =\n");
  1144. i915_instdone_info(dev_priv, m, &instdone);
  1145. seq_puts(m, "\tinstdone accu =\n");
  1146. i915_instdone_info(dev_priv, m,
  1147. &engine->hangcheck.instdone);
  1148. }
  1149. }
  1150. return 0;
  1151. }
  1152. static int ironlake_drpc_info(struct seq_file *m)
  1153. {
  1154. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1155. u32 rgvmodectl, rstdbyctl;
  1156. u16 crstandvid;
  1157. intel_runtime_pm_get(dev_priv);
  1158. rgvmodectl = I915_READ(MEMMODECTL);
  1159. rstdbyctl = I915_READ(RSTDBYCTL);
  1160. crstandvid = I915_READ16(CRSTANDVID);
  1161. intel_runtime_pm_put(dev_priv);
  1162. seq_printf(m, "HD boost: %s\n", yesno(rgvmodectl & MEMMODE_BOOST_EN));
  1163. seq_printf(m, "Boost freq: %d\n",
  1164. (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
  1165. MEMMODE_BOOST_FREQ_SHIFT);
  1166. seq_printf(m, "HW control enabled: %s\n",
  1167. yesno(rgvmodectl & MEMMODE_HWIDLE_EN));
  1168. seq_printf(m, "SW control enabled: %s\n",
  1169. yesno(rgvmodectl & MEMMODE_SWMODE_EN));
  1170. seq_printf(m, "Gated voltage change: %s\n",
  1171. yesno(rgvmodectl & MEMMODE_RCLK_GATE));
  1172. seq_printf(m, "Starting frequency: P%d\n",
  1173. (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
  1174. seq_printf(m, "Max P-state: P%d\n",
  1175. (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
  1176. seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
  1177. seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
  1178. seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
  1179. seq_printf(m, "Render standby enabled: %s\n",
  1180. yesno(!(rstdbyctl & RCX_SW_EXIT)));
  1181. seq_puts(m, "Current RS state: ");
  1182. switch (rstdbyctl & RSX_STATUS_MASK) {
  1183. case RSX_STATUS_ON:
  1184. seq_puts(m, "on\n");
  1185. break;
  1186. case RSX_STATUS_RC1:
  1187. seq_puts(m, "RC1\n");
  1188. break;
  1189. case RSX_STATUS_RC1E:
  1190. seq_puts(m, "RC1E\n");
  1191. break;
  1192. case RSX_STATUS_RS1:
  1193. seq_puts(m, "RS1\n");
  1194. break;
  1195. case RSX_STATUS_RS2:
  1196. seq_puts(m, "RS2 (RC6)\n");
  1197. break;
  1198. case RSX_STATUS_RS3:
  1199. seq_puts(m, "RC3 (RC6+)\n");
  1200. break;
  1201. default:
  1202. seq_puts(m, "unknown\n");
  1203. break;
  1204. }
  1205. return 0;
  1206. }
  1207. static int i915_forcewake_domains(struct seq_file *m, void *data)
  1208. {
  1209. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1210. struct intel_uncore_forcewake_domain *fw_domain;
  1211. spin_lock_irq(&dev_priv->uncore.lock);
  1212. for_each_fw_domain(fw_domain, dev_priv) {
  1213. seq_printf(m, "%s.wake_count = %u\n",
  1214. intel_uncore_forcewake_domain_to_str(fw_domain->id),
  1215. fw_domain->wake_count);
  1216. }
  1217. spin_unlock_irq(&dev_priv->uncore.lock);
  1218. return 0;
  1219. }
  1220. static int vlv_drpc_info(struct seq_file *m)
  1221. {
  1222. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1223. u32 rpmodectl1, rcctl1, pw_status;
  1224. intel_runtime_pm_get(dev_priv);
  1225. pw_status = I915_READ(VLV_GTLC_PW_STATUS);
  1226. rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
  1227. rcctl1 = I915_READ(GEN6_RC_CONTROL);
  1228. intel_runtime_pm_put(dev_priv);
  1229. seq_printf(m, "Video Turbo Mode: %s\n",
  1230. yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
  1231. seq_printf(m, "Turbo enabled: %s\n",
  1232. yesno(rpmodectl1 & GEN6_RP_ENABLE));
  1233. seq_printf(m, "HW control enabled: %s\n",
  1234. yesno(rpmodectl1 & GEN6_RP_ENABLE));
  1235. seq_printf(m, "SW control enabled: %s\n",
  1236. yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
  1237. GEN6_RP_MEDIA_SW_MODE));
  1238. seq_printf(m, "RC6 Enabled: %s\n",
  1239. yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
  1240. GEN6_RC_CTL_EI_MODE(1))));
  1241. seq_printf(m, "Render Power Well: %s\n",
  1242. (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
  1243. seq_printf(m, "Media Power Well: %s\n",
  1244. (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
  1245. seq_printf(m, "Render RC6 residency since boot: %u\n",
  1246. I915_READ(VLV_GT_RENDER_RC6));
  1247. seq_printf(m, "Media RC6 residency since boot: %u\n",
  1248. I915_READ(VLV_GT_MEDIA_RC6));
  1249. return i915_forcewake_domains(m, NULL);
  1250. }
  1251. static int gen6_drpc_info(struct seq_file *m)
  1252. {
  1253. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1254. struct drm_device *dev = &dev_priv->drm;
  1255. u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
  1256. u32 gen9_powergate_enable = 0, gen9_powergate_status = 0;
  1257. unsigned forcewake_count;
  1258. int count = 0, ret;
  1259. ret = mutex_lock_interruptible(&dev->struct_mutex);
  1260. if (ret)
  1261. return ret;
  1262. intel_runtime_pm_get(dev_priv);
  1263. spin_lock_irq(&dev_priv->uncore.lock);
  1264. forcewake_count = dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count;
  1265. spin_unlock_irq(&dev_priv->uncore.lock);
  1266. if (forcewake_count) {
  1267. seq_puts(m, "RC information inaccurate because somebody "
  1268. "holds a forcewake reference \n");
  1269. } else {
  1270. /* NB: we cannot use forcewake, else we read the wrong values */
  1271. while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
  1272. udelay(10);
  1273. seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
  1274. }
  1275. gt_core_status = I915_READ_FW(GEN6_GT_CORE_STATUS);
  1276. trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
  1277. rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
  1278. rcctl1 = I915_READ(GEN6_RC_CONTROL);
  1279. if (INTEL_GEN(dev_priv) >= 9) {
  1280. gen9_powergate_enable = I915_READ(GEN9_PG_ENABLE);
  1281. gen9_powergate_status = I915_READ(GEN9_PWRGT_DOMAIN_STATUS);
  1282. }
  1283. mutex_unlock(&dev->struct_mutex);
  1284. mutex_lock(&dev_priv->rps.hw_lock);
  1285. sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
  1286. mutex_unlock(&dev_priv->rps.hw_lock);
  1287. intel_runtime_pm_put(dev_priv);
  1288. seq_printf(m, "Video Turbo Mode: %s\n",
  1289. yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
  1290. seq_printf(m, "HW control enabled: %s\n",
  1291. yesno(rpmodectl1 & GEN6_RP_ENABLE));
  1292. seq_printf(m, "SW control enabled: %s\n",
  1293. yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
  1294. GEN6_RP_MEDIA_SW_MODE));
  1295. seq_printf(m, "RC1e Enabled: %s\n",
  1296. yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
  1297. seq_printf(m, "RC6 Enabled: %s\n",
  1298. yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
  1299. if (INTEL_GEN(dev_priv) >= 9) {
  1300. seq_printf(m, "Render Well Gating Enabled: %s\n",
  1301. yesno(gen9_powergate_enable & GEN9_RENDER_PG_ENABLE));
  1302. seq_printf(m, "Media Well Gating Enabled: %s\n",
  1303. yesno(gen9_powergate_enable & GEN9_MEDIA_PG_ENABLE));
  1304. }
  1305. seq_printf(m, "Deep RC6 Enabled: %s\n",
  1306. yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
  1307. seq_printf(m, "Deepest RC6 Enabled: %s\n",
  1308. yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
  1309. seq_puts(m, "Current RC state: ");
  1310. switch (gt_core_status & GEN6_RCn_MASK) {
  1311. case GEN6_RC0:
  1312. if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
  1313. seq_puts(m, "Core Power Down\n");
  1314. else
  1315. seq_puts(m, "on\n");
  1316. break;
  1317. case GEN6_RC3:
  1318. seq_puts(m, "RC3\n");
  1319. break;
  1320. case GEN6_RC6:
  1321. seq_puts(m, "RC6\n");
  1322. break;
  1323. case GEN6_RC7:
  1324. seq_puts(m, "RC7\n");
  1325. break;
  1326. default:
  1327. seq_puts(m, "Unknown\n");
  1328. break;
  1329. }
  1330. seq_printf(m, "Core Power Down: %s\n",
  1331. yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
  1332. if (INTEL_GEN(dev_priv) >= 9) {
  1333. seq_printf(m, "Render Power Well: %s\n",
  1334. (gen9_powergate_status &
  1335. GEN9_PWRGT_RENDER_STATUS_MASK) ? "Up" : "Down");
  1336. seq_printf(m, "Media Power Well: %s\n",
  1337. (gen9_powergate_status &
  1338. GEN9_PWRGT_MEDIA_STATUS_MASK) ? "Up" : "Down");
  1339. }
  1340. /* Not exactly sure what this is */
  1341. seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
  1342. I915_READ(GEN6_GT_GFX_RC6_LOCKED));
  1343. seq_printf(m, "RC6 residency since boot: %u\n",
  1344. I915_READ(GEN6_GT_GFX_RC6));
  1345. seq_printf(m, "RC6+ residency since boot: %u\n",
  1346. I915_READ(GEN6_GT_GFX_RC6p));
  1347. seq_printf(m, "RC6++ residency since boot: %u\n",
  1348. I915_READ(GEN6_GT_GFX_RC6pp));
  1349. seq_printf(m, "RC6 voltage: %dmV\n",
  1350. GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
  1351. seq_printf(m, "RC6+ voltage: %dmV\n",
  1352. GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
  1353. seq_printf(m, "RC6++ voltage: %dmV\n",
  1354. GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
  1355. return i915_forcewake_domains(m, NULL);
  1356. }
  1357. static int i915_drpc_info(struct seq_file *m, void *unused)
  1358. {
  1359. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1360. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  1361. return vlv_drpc_info(m);
  1362. else if (INTEL_GEN(dev_priv) >= 6)
  1363. return gen6_drpc_info(m);
  1364. else
  1365. return ironlake_drpc_info(m);
  1366. }
  1367. static int i915_frontbuffer_tracking(struct seq_file *m, void *unused)
  1368. {
  1369. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1370. seq_printf(m, "FB tracking busy bits: 0x%08x\n",
  1371. dev_priv->fb_tracking.busy_bits);
  1372. seq_printf(m, "FB tracking flip bits: 0x%08x\n",
  1373. dev_priv->fb_tracking.flip_bits);
  1374. return 0;
  1375. }
  1376. static int i915_fbc_status(struct seq_file *m, void *unused)
  1377. {
  1378. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1379. if (!HAS_FBC(dev_priv)) {
  1380. seq_puts(m, "FBC unsupported on this chipset\n");
  1381. return 0;
  1382. }
  1383. intel_runtime_pm_get(dev_priv);
  1384. mutex_lock(&dev_priv->fbc.lock);
  1385. if (intel_fbc_is_active(dev_priv))
  1386. seq_puts(m, "FBC enabled\n");
  1387. else
  1388. seq_printf(m, "FBC disabled: %s\n",
  1389. dev_priv->fbc.no_fbc_reason);
  1390. if (intel_fbc_is_active(dev_priv) && INTEL_GEN(dev_priv) >= 7) {
  1391. uint32_t mask = INTEL_GEN(dev_priv) >= 8 ?
  1392. BDW_FBC_COMPRESSION_MASK :
  1393. IVB_FBC_COMPRESSION_MASK;
  1394. seq_printf(m, "Compressing: %s\n",
  1395. yesno(I915_READ(FBC_STATUS2) & mask));
  1396. }
  1397. mutex_unlock(&dev_priv->fbc.lock);
  1398. intel_runtime_pm_put(dev_priv);
  1399. return 0;
  1400. }
  1401. static int i915_fbc_fc_get(void *data, u64 *val)
  1402. {
  1403. struct drm_i915_private *dev_priv = data;
  1404. if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
  1405. return -ENODEV;
  1406. *val = dev_priv->fbc.false_color;
  1407. return 0;
  1408. }
  1409. static int i915_fbc_fc_set(void *data, u64 val)
  1410. {
  1411. struct drm_i915_private *dev_priv = data;
  1412. u32 reg;
  1413. if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
  1414. return -ENODEV;
  1415. mutex_lock(&dev_priv->fbc.lock);
  1416. reg = I915_READ(ILK_DPFC_CONTROL);
  1417. dev_priv->fbc.false_color = val;
  1418. I915_WRITE(ILK_DPFC_CONTROL, val ?
  1419. (reg | FBC_CTL_FALSE_COLOR) :
  1420. (reg & ~FBC_CTL_FALSE_COLOR));
  1421. mutex_unlock(&dev_priv->fbc.lock);
  1422. return 0;
  1423. }
  1424. DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_fc_fops,
  1425. i915_fbc_fc_get, i915_fbc_fc_set,
  1426. "%llu\n");
  1427. static int i915_ips_status(struct seq_file *m, void *unused)
  1428. {
  1429. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1430. if (!HAS_IPS(dev_priv)) {
  1431. seq_puts(m, "not supported\n");
  1432. return 0;
  1433. }
  1434. intel_runtime_pm_get(dev_priv);
  1435. seq_printf(m, "Enabled by kernel parameter: %s\n",
  1436. yesno(i915.enable_ips));
  1437. if (INTEL_GEN(dev_priv) >= 8) {
  1438. seq_puts(m, "Currently: unknown\n");
  1439. } else {
  1440. if (I915_READ(IPS_CTL) & IPS_ENABLE)
  1441. seq_puts(m, "Currently: enabled\n");
  1442. else
  1443. seq_puts(m, "Currently: disabled\n");
  1444. }
  1445. intel_runtime_pm_put(dev_priv);
  1446. return 0;
  1447. }
  1448. static int i915_sr_status(struct seq_file *m, void *unused)
  1449. {
  1450. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1451. bool sr_enabled = false;
  1452. intel_runtime_pm_get(dev_priv);
  1453. intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
  1454. if (HAS_PCH_SPLIT(dev_priv))
  1455. sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
  1456. else if (IS_CRESTLINE(dev_priv) || IS_G4X(dev_priv) ||
  1457. IS_I945G(dev_priv) || IS_I945GM(dev_priv))
  1458. sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
  1459. else if (IS_I915GM(dev_priv))
  1460. sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
  1461. else if (IS_PINEVIEW(dev_priv))
  1462. sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
  1463. else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  1464. sr_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
  1465. intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
  1466. intel_runtime_pm_put(dev_priv);
  1467. seq_printf(m, "self-refresh: %s\n", enableddisabled(sr_enabled));
  1468. return 0;
  1469. }
  1470. static int i915_emon_status(struct seq_file *m, void *unused)
  1471. {
  1472. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1473. struct drm_device *dev = &dev_priv->drm;
  1474. unsigned long temp, chipset, gfx;
  1475. int ret;
  1476. if (!IS_GEN5(dev_priv))
  1477. return -ENODEV;
  1478. ret = mutex_lock_interruptible(&dev->struct_mutex);
  1479. if (ret)
  1480. return ret;
  1481. temp = i915_mch_val(dev_priv);
  1482. chipset = i915_chipset_val(dev_priv);
  1483. gfx = i915_gfx_val(dev_priv);
  1484. mutex_unlock(&dev->struct_mutex);
  1485. seq_printf(m, "GMCH temp: %ld\n", temp);
  1486. seq_printf(m, "Chipset power: %ld\n", chipset);
  1487. seq_printf(m, "GFX power: %ld\n", gfx);
  1488. seq_printf(m, "Total power: %ld\n", chipset + gfx);
  1489. return 0;
  1490. }
  1491. static int i915_ring_freq_table(struct seq_file *m, void *unused)
  1492. {
  1493. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1494. int ret = 0;
  1495. int gpu_freq, ia_freq;
  1496. unsigned int max_gpu_freq, min_gpu_freq;
  1497. if (!HAS_LLC(dev_priv)) {
  1498. seq_puts(m, "unsupported on this chipset\n");
  1499. return 0;
  1500. }
  1501. intel_runtime_pm_get(dev_priv);
  1502. ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
  1503. if (ret)
  1504. goto out;
  1505. if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) {
  1506. /* Convert GT frequency to 50 HZ units */
  1507. min_gpu_freq =
  1508. dev_priv->rps.min_freq_softlimit / GEN9_FREQ_SCALER;
  1509. max_gpu_freq =
  1510. dev_priv->rps.max_freq_softlimit / GEN9_FREQ_SCALER;
  1511. } else {
  1512. min_gpu_freq = dev_priv->rps.min_freq_softlimit;
  1513. max_gpu_freq = dev_priv->rps.max_freq_softlimit;
  1514. }
  1515. seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
  1516. for (gpu_freq = min_gpu_freq; gpu_freq <= max_gpu_freq; gpu_freq++) {
  1517. ia_freq = gpu_freq;
  1518. sandybridge_pcode_read(dev_priv,
  1519. GEN6_PCODE_READ_MIN_FREQ_TABLE,
  1520. &ia_freq);
  1521. seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
  1522. intel_gpu_freq(dev_priv, (gpu_freq *
  1523. (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ?
  1524. GEN9_FREQ_SCALER : 1))),
  1525. ((ia_freq >> 0) & 0xff) * 100,
  1526. ((ia_freq >> 8) & 0xff) * 100);
  1527. }
  1528. mutex_unlock(&dev_priv->rps.hw_lock);
  1529. out:
  1530. intel_runtime_pm_put(dev_priv);
  1531. return ret;
  1532. }
  1533. static int i915_opregion(struct seq_file *m, void *unused)
  1534. {
  1535. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1536. struct drm_device *dev = &dev_priv->drm;
  1537. struct intel_opregion *opregion = &dev_priv->opregion;
  1538. int ret;
  1539. ret = mutex_lock_interruptible(&dev->struct_mutex);
  1540. if (ret)
  1541. goto out;
  1542. if (opregion->header)
  1543. seq_write(m, opregion->header, OPREGION_SIZE);
  1544. mutex_unlock(&dev->struct_mutex);
  1545. out:
  1546. return 0;
  1547. }
  1548. static int i915_vbt(struct seq_file *m, void *unused)
  1549. {
  1550. struct intel_opregion *opregion = &node_to_i915(m->private)->opregion;
  1551. if (opregion->vbt)
  1552. seq_write(m, opregion->vbt, opregion->vbt_size);
  1553. return 0;
  1554. }
  1555. static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
  1556. {
  1557. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1558. struct drm_device *dev = &dev_priv->drm;
  1559. struct intel_framebuffer *fbdev_fb = NULL;
  1560. struct drm_framebuffer *drm_fb;
  1561. int ret;
  1562. ret = mutex_lock_interruptible(&dev->struct_mutex);
  1563. if (ret)
  1564. return ret;
  1565. #ifdef CONFIG_DRM_FBDEV_EMULATION
  1566. if (dev_priv->fbdev) {
  1567. fbdev_fb = to_intel_framebuffer(dev_priv->fbdev->helper.fb);
  1568. seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
  1569. fbdev_fb->base.width,
  1570. fbdev_fb->base.height,
  1571. fbdev_fb->base.depth,
  1572. fbdev_fb->base.bits_per_pixel,
  1573. fbdev_fb->base.modifier[0],
  1574. drm_framebuffer_read_refcount(&fbdev_fb->base));
  1575. describe_obj(m, fbdev_fb->obj);
  1576. seq_putc(m, '\n');
  1577. }
  1578. #endif
  1579. mutex_lock(&dev->mode_config.fb_lock);
  1580. drm_for_each_fb(drm_fb, dev) {
  1581. struct intel_framebuffer *fb = to_intel_framebuffer(drm_fb);
  1582. if (fb == fbdev_fb)
  1583. continue;
  1584. seq_printf(m, "user size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
  1585. fb->base.width,
  1586. fb->base.height,
  1587. fb->base.depth,
  1588. fb->base.bits_per_pixel,
  1589. fb->base.modifier[0],
  1590. drm_framebuffer_read_refcount(&fb->base));
  1591. describe_obj(m, fb->obj);
  1592. seq_putc(m, '\n');
  1593. }
  1594. mutex_unlock(&dev->mode_config.fb_lock);
  1595. mutex_unlock(&dev->struct_mutex);
  1596. return 0;
  1597. }
  1598. static void describe_ctx_ring(struct seq_file *m, struct intel_ring *ring)
  1599. {
  1600. seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u, last head: %d)",
  1601. ring->space, ring->head, ring->tail,
  1602. ring->last_retired_head);
  1603. }
  1604. static int i915_context_status(struct seq_file *m, void *unused)
  1605. {
  1606. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1607. struct drm_device *dev = &dev_priv->drm;
  1608. struct intel_engine_cs *engine;
  1609. struct i915_gem_context *ctx;
  1610. enum intel_engine_id id;
  1611. int ret;
  1612. ret = mutex_lock_interruptible(&dev->struct_mutex);
  1613. if (ret)
  1614. return ret;
  1615. list_for_each_entry(ctx, &dev_priv->context_list, link) {
  1616. seq_printf(m, "HW context %u ", ctx->hw_id);
  1617. if (ctx->pid) {
  1618. struct task_struct *task;
  1619. task = get_pid_task(ctx->pid, PIDTYPE_PID);
  1620. if (task) {
  1621. seq_printf(m, "(%s [%d]) ",
  1622. task->comm, task->pid);
  1623. put_task_struct(task);
  1624. }
  1625. } else if (IS_ERR(ctx->file_priv)) {
  1626. seq_puts(m, "(deleted) ");
  1627. } else {
  1628. seq_puts(m, "(kernel) ");
  1629. }
  1630. seq_putc(m, ctx->remap_slice ? 'R' : 'r');
  1631. seq_putc(m, '\n');
  1632. for_each_engine(engine, dev_priv, id) {
  1633. struct intel_context *ce = &ctx->engine[engine->id];
  1634. seq_printf(m, "%s: ", engine->name);
  1635. seq_putc(m, ce->initialised ? 'I' : 'i');
  1636. if (ce->state)
  1637. describe_obj(m, ce->state->obj);
  1638. if (ce->ring)
  1639. describe_ctx_ring(m, ce->ring);
  1640. seq_putc(m, '\n');
  1641. }
  1642. seq_putc(m, '\n');
  1643. }
  1644. mutex_unlock(&dev->struct_mutex);
  1645. return 0;
  1646. }
  1647. static void i915_dump_lrc_obj(struct seq_file *m,
  1648. struct i915_gem_context *ctx,
  1649. struct intel_engine_cs *engine)
  1650. {
  1651. struct i915_vma *vma = ctx->engine[engine->id].state;
  1652. struct page *page;
  1653. int j;
  1654. seq_printf(m, "CONTEXT: %s %u\n", engine->name, ctx->hw_id);
  1655. if (!vma) {
  1656. seq_puts(m, "\tFake context\n");
  1657. return;
  1658. }
  1659. if (vma->flags & I915_VMA_GLOBAL_BIND)
  1660. seq_printf(m, "\tBound in GGTT at 0x%08x\n",
  1661. i915_ggtt_offset(vma));
  1662. if (i915_gem_object_pin_pages(vma->obj)) {
  1663. seq_puts(m, "\tFailed to get pages for context object\n\n");
  1664. return;
  1665. }
  1666. page = i915_gem_object_get_page(vma->obj, LRC_STATE_PN);
  1667. if (page) {
  1668. u32 *reg_state = kmap_atomic(page);
  1669. for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
  1670. seq_printf(m,
  1671. "\t[0x%04x] 0x%08x 0x%08x 0x%08x 0x%08x\n",
  1672. j * 4,
  1673. reg_state[j], reg_state[j + 1],
  1674. reg_state[j + 2], reg_state[j + 3]);
  1675. }
  1676. kunmap_atomic(reg_state);
  1677. }
  1678. i915_gem_object_unpin_pages(vma->obj);
  1679. seq_putc(m, '\n');
  1680. }
  1681. static int i915_dump_lrc(struct seq_file *m, void *unused)
  1682. {
  1683. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1684. struct drm_device *dev = &dev_priv->drm;
  1685. struct intel_engine_cs *engine;
  1686. struct i915_gem_context *ctx;
  1687. enum intel_engine_id id;
  1688. int ret;
  1689. if (!i915.enable_execlists) {
  1690. seq_printf(m, "Logical Ring Contexts are disabled\n");
  1691. return 0;
  1692. }
  1693. ret = mutex_lock_interruptible(&dev->struct_mutex);
  1694. if (ret)
  1695. return ret;
  1696. list_for_each_entry(ctx, &dev_priv->context_list, link)
  1697. for_each_engine(engine, dev_priv, id)
  1698. i915_dump_lrc_obj(m, ctx, engine);
  1699. mutex_unlock(&dev->struct_mutex);
  1700. return 0;
  1701. }
  1702. static const char *swizzle_string(unsigned swizzle)
  1703. {
  1704. switch (swizzle) {
  1705. case I915_BIT_6_SWIZZLE_NONE:
  1706. return "none";
  1707. case I915_BIT_6_SWIZZLE_9:
  1708. return "bit9";
  1709. case I915_BIT_6_SWIZZLE_9_10:
  1710. return "bit9/bit10";
  1711. case I915_BIT_6_SWIZZLE_9_11:
  1712. return "bit9/bit11";
  1713. case I915_BIT_6_SWIZZLE_9_10_11:
  1714. return "bit9/bit10/bit11";
  1715. case I915_BIT_6_SWIZZLE_9_17:
  1716. return "bit9/bit17";
  1717. case I915_BIT_6_SWIZZLE_9_10_17:
  1718. return "bit9/bit10/bit17";
  1719. case I915_BIT_6_SWIZZLE_UNKNOWN:
  1720. return "unknown";
  1721. }
  1722. return "bug";
  1723. }
  1724. static int i915_swizzle_info(struct seq_file *m, void *data)
  1725. {
  1726. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1727. intel_runtime_pm_get(dev_priv);
  1728. seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
  1729. swizzle_string(dev_priv->mm.bit_6_swizzle_x));
  1730. seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
  1731. swizzle_string(dev_priv->mm.bit_6_swizzle_y));
  1732. if (IS_GEN3(dev_priv) || IS_GEN4(dev_priv)) {
  1733. seq_printf(m, "DDC = 0x%08x\n",
  1734. I915_READ(DCC));
  1735. seq_printf(m, "DDC2 = 0x%08x\n",
  1736. I915_READ(DCC2));
  1737. seq_printf(m, "C0DRB3 = 0x%04x\n",
  1738. I915_READ16(C0DRB3));
  1739. seq_printf(m, "C1DRB3 = 0x%04x\n",
  1740. I915_READ16(C1DRB3));
  1741. } else if (INTEL_GEN(dev_priv) >= 6) {
  1742. seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
  1743. I915_READ(MAD_DIMM_C0));
  1744. seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
  1745. I915_READ(MAD_DIMM_C1));
  1746. seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
  1747. I915_READ(MAD_DIMM_C2));
  1748. seq_printf(m, "TILECTL = 0x%08x\n",
  1749. I915_READ(TILECTL));
  1750. if (INTEL_GEN(dev_priv) >= 8)
  1751. seq_printf(m, "GAMTARBMODE = 0x%08x\n",
  1752. I915_READ(GAMTARBMODE));
  1753. else
  1754. seq_printf(m, "ARB_MODE = 0x%08x\n",
  1755. I915_READ(ARB_MODE));
  1756. seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
  1757. I915_READ(DISP_ARB_CTL));
  1758. }
  1759. if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
  1760. seq_puts(m, "L-shaped memory detected\n");
  1761. intel_runtime_pm_put(dev_priv);
  1762. return 0;
  1763. }
  1764. static int per_file_ctx(int id, void *ptr, void *data)
  1765. {
  1766. struct i915_gem_context *ctx = ptr;
  1767. struct seq_file *m = data;
  1768. struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
  1769. if (!ppgtt) {
  1770. seq_printf(m, " no ppgtt for context %d\n",
  1771. ctx->user_handle);
  1772. return 0;
  1773. }
  1774. if (i915_gem_context_is_default(ctx))
  1775. seq_puts(m, " default context:\n");
  1776. else
  1777. seq_printf(m, " context %d:\n", ctx->user_handle);
  1778. ppgtt->debug_dump(ppgtt, m);
  1779. return 0;
  1780. }
  1781. static void gen8_ppgtt_info(struct seq_file *m,
  1782. struct drm_i915_private *dev_priv)
  1783. {
  1784. struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
  1785. struct intel_engine_cs *engine;
  1786. enum intel_engine_id id;
  1787. int i;
  1788. if (!ppgtt)
  1789. return;
  1790. for_each_engine(engine, dev_priv, id) {
  1791. seq_printf(m, "%s\n", engine->name);
  1792. for (i = 0; i < 4; i++) {
  1793. u64 pdp = I915_READ(GEN8_RING_PDP_UDW(engine, i));
  1794. pdp <<= 32;
  1795. pdp |= I915_READ(GEN8_RING_PDP_LDW(engine, i));
  1796. seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
  1797. }
  1798. }
  1799. }
  1800. static void gen6_ppgtt_info(struct seq_file *m,
  1801. struct drm_i915_private *dev_priv)
  1802. {
  1803. struct intel_engine_cs *engine;
  1804. enum intel_engine_id id;
  1805. if (IS_GEN6(dev_priv))
  1806. seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
  1807. for_each_engine(engine, dev_priv, id) {
  1808. seq_printf(m, "%s\n", engine->name);
  1809. if (IS_GEN7(dev_priv))
  1810. seq_printf(m, "GFX_MODE: 0x%08x\n",
  1811. I915_READ(RING_MODE_GEN7(engine)));
  1812. seq_printf(m, "PP_DIR_BASE: 0x%08x\n",
  1813. I915_READ(RING_PP_DIR_BASE(engine)));
  1814. seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n",
  1815. I915_READ(RING_PP_DIR_BASE_READ(engine)));
  1816. seq_printf(m, "PP_DIR_DCLV: 0x%08x\n",
  1817. I915_READ(RING_PP_DIR_DCLV(engine)));
  1818. }
  1819. if (dev_priv->mm.aliasing_ppgtt) {
  1820. struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
  1821. seq_puts(m, "aliasing PPGTT:\n");
  1822. seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.base.ggtt_offset);
  1823. ppgtt->debug_dump(ppgtt, m);
  1824. }
  1825. seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
  1826. }
  1827. static int i915_ppgtt_info(struct seq_file *m, void *data)
  1828. {
  1829. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1830. struct drm_device *dev = &dev_priv->drm;
  1831. struct drm_file *file;
  1832. int ret;
  1833. mutex_lock(&dev->filelist_mutex);
  1834. ret = mutex_lock_interruptible(&dev->struct_mutex);
  1835. if (ret)
  1836. goto out_unlock;
  1837. intel_runtime_pm_get(dev_priv);
  1838. if (INTEL_GEN(dev_priv) >= 8)
  1839. gen8_ppgtt_info(m, dev_priv);
  1840. else if (INTEL_GEN(dev_priv) >= 6)
  1841. gen6_ppgtt_info(m, dev_priv);
  1842. list_for_each_entry_reverse(file, &dev->filelist, lhead) {
  1843. struct drm_i915_file_private *file_priv = file->driver_priv;
  1844. struct task_struct *task;
  1845. task = get_pid_task(file->pid, PIDTYPE_PID);
  1846. if (!task) {
  1847. ret = -ESRCH;
  1848. goto out_rpm;
  1849. }
  1850. seq_printf(m, "\nproc: %s\n", task->comm);
  1851. put_task_struct(task);
  1852. idr_for_each(&file_priv->context_idr, per_file_ctx,
  1853. (void *)(unsigned long)m);
  1854. }
  1855. out_rpm:
  1856. intel_runtime_pm_put(dev_priv);
  1857. mutex_unlock(&dev->struct_mutex);
  1858. out_unlock:
  1859. mutex_unlock(&dev->filelist_mutex);
  1860. return ret;
  1861. }
  1862. static int count_irq_waiters(struct drm_i915_private *i915)
  1863. {
  1864. struct intel_engine_cs *engine;
  1865. enum intel_engine_id id;
  1866. int count = 0;
  1867. for_each_engine(engine, i915, id)
  1868. count += intel_engine_has_waiter(engine);
  1869. return count;
  1870. }
  1871. static const char *rps_power_to_str(unsigned int power)
  1872. {
  1873. static const char * const strings[] = {
  1874. [LOW_POWER] = "low power",
  1875. [BETWEEN] = "mixed",
  1876. [HIGH_POWER] = "high power",
  1877. };
  1878. if (power >= ARRAY_SIZE(strings) || !strings[power])
  1879. return "unknown";
  1880. return strings[power];
  1881. }
  1882. static int i915_rps_boost_info(struct seq_file *m, void *data)
  1883. {
  1884. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1885. struct drm_device *dev = &dev_priv->drm;
  1886. struct drm_file *file;
  1887. seq_printf(m, "RPS enabled? %d\n", dev_priv->rps.enabled);
  1888. seq_printf(m, "GPU busy? %s [%d requests]\n",
  1889. yesno(dev_priv->gt.awake), dev_priv->gt.active_requests);
  1890. seq_printf(m, "CPU waiting? %d\n", count_irq_waiters(dev_priv));
  1891. seq_printf(m, "Frequency requested %d\n",
  1892. intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
  1893. seq_printf(m, " min hard:%d, soft:%d; max soft:%d, hard:%d\n",
  1894. intel_gpu_freq(dev_priv, dev_priv->rps.min_freq),
  1895. intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit),
  1896. intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit),
  1897. intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
  1898. seq_printf(m, " idle:%d, efficient:%d, boost:%d\n",
  1899. intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq),
  1900. intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq),
  1901. intel_gpu_freq(dev_priv, dev_priv->rps.boost_freq));
  1902. mutex_lock(&dev->filelist_mutex);
  1903. spin_lock(&dev_priv->rps.client_lock);
  1904. list_for_each_entry_reverse(file, &dev->filelist, lhead) {
  1905. struct drm_i915_file_private *file_priv = file->driver_priv;
  1906. struct task_struct *task;
  1907. rcu_read_lock();
  1908. task = pid_task(file->pid, PIDTYPE_PID);
  1909. seq_printf(m, "%s [%d]: %d boosts%s\n",
  1910. task ? task->comm : "<unknown>",
  1911. task ? task->pid : -1,
  1912. file_priv->rps.boosts,
  1913. list_empty(&file_priv->rps.link) ? "" : ", active");
  1914. rcu_read_unlock();
  1915. }
  1916. seq_printf(m, "Kernel (anonymous) boosts: %d\n", dev_priv->rps.boosts);
  1917. spin_unlock(&dev_priv->rps.client_lock);
  1918. mutex_unlock(&dev->filelist_mutex);
  1919. if (INTEL_GEN(dev_priv) >= 6 &&
  1920. dev_priv->rps.enabled &&
  1921. dev_priv->gt.active_requests) {
  1922. u32 rpup, rpupei;
  1923. u32 rpdown, rpdownei;
  1924. intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
  1925. rpup = I915_READ_FW(GEN6_RP_CUR_UP) & GEN6_RP_EI_MASK;
  1926. rpupei = I915_READ_FW(GEN6_RP_CUR_UP_EI) & GEN6_RP_EI_MASK;
  1927. rpdown = I915_READ_FW(GEN6_RP_CUR_DOWN) & GEN6_RP_EI_MASK;
  1928. rpdownei = I915_READ_FW(GEN6_RP_CUR_DOWN_EI) & GEN6_RP_EI_MASK;
  1929. intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
  1930. seq_printf(m, "\nRPS Autotuning (current \"%s\" window):\n",
  1931. rps_power_to_str(dev_priv->rps.power));
  1932. seq_printf(m, " Avg. up: %d%% [above threshold? %d%%]\n",
  1933. 100 * rpup / rpupei,
  1934. dev_priv->rps.up_threshold);
  1935. seq_printf(m, " Avg. down: %d%% [below threshold? %d%%]\n",
  1936. 100 * rpdown / rpdownei,
  1937. dev_priv->rps.down_threshold);
  1938. } else {
  1939. seq_puts(m, "\nRPS Autotuning inactive\n");
  1940. }
  1941. return 0;
  1942. }
  1943. static int i915_llc(struct seq_file *m, void *data)
  1944. {
  1945. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1946. const bool edram = INTEL_GEN(dev_priv) > 8;
  1947. seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev_priv)));
  1948. seq_printf(m, "%s: %lluMB\n", edram ? "eDRAM" : "eLLC",
  1949. intel_uncore_edram_size(dev_priv)/1024/1024);
  1950. return 0;
  1951. }
  1952. static int i915_guc_load_status_info(struct seq_file *m, void *data)
  1953. {
  1954. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  1955. struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw;
  1956. u32 tmp, i;
  1957. if (!HAS_GUC_UCODE(dev_priv))
  1958. return 0;
  1959. seq_printf(m, "GuC firmware status:\n");
  1960. seq_printf(m, "\tpath: %s\n",
  1961. guc_fw->guc_fw_path);
  1962. seq_printf(m, "\tfetch: %s\n",
  1963. intel_guc_fw_status_repr(guc_fw->guc_fw_fetch_status));
  1964. seq_printf(m, "\tload: %s\n",
  1965. intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));
  1966. seq_printf(m, "\tversion wanted: %d.%d\n",
  1967. guc_fw->guc_fw_major_wanted, guc_fw->guc_fw_minor_wanted);
  1968. seq_printf(m, "\tversion found: %d.%d\n",
  1969. guc_fw->guc_fw_major_found, guc_fw->guc_fw_minor_found);
  1970. seq_printf(m, "\theader: offset is %d; size = %d\n",
  1971. guc_fw->header_offset, guc_fw->header_size);
  1972. seq_printf(m, "\tuCode: offset is %d; size = %d\n",
  1973. guc_fw->ucode_offset, guc_fw->ucode_size);
  1974. seq_printf(m, "\tRSA: offset is %d; size = %d\n",
  1975. guc_fw->rsa_offset, guc_fw->rsa_size);
  1976. tmp = I915_READ(GUC_STATUS);
  1977. seq_printf(m, "\nGuC status 0x%08x:\n", tmp);
  1978. seq_printf(m, "\tBootrom status = 0x%x\n",
  1979. (tmp & GS_BOOTROM_MASK) >> GS_BOOTROM_SHIFT);
  1980. seq_printf(m, "\tuKernel status = 0x%x\n",
  1981. (tmp & GS_UKERNEL_MASK) >> GS_UKERNEL_SHIFT);
  1982. seq_printf(m, "\tMIA Core status = 0x%x\n",
  1983. (tmp & GS_MIA_MASK) >> GS_MIA_SHIFT);
  1984. seq_puts(m, "\nScratch registers:\n");
  1985. for (i = 0; i < 16; i++)
  1986. seq_printf(m, "\t%2d: \t0x%x\n", i, I915_READ(SOFT_SCRATCH(i)));
  1987. return 0;
  1988. }
  1989. static void i915_guc_log_info(struct seq_file *m,
  1990. struct drm_i915_private *dev_priv)
  1991. {
  1992. struct intel_guc *guc = &dev_priv->guc;
  1993. seq_puts(m, "\nGuC logging stats:\n");
  1994. seq_printf(m, "\tISR: flush count %10u, overflow count %10u\n",
  1995. guc->log.flush_count[GUC_ISR_LOG_BUFFER],
  1996. guc->log.total_overflow_count[GUC_ISR_LOG_BUFFER]);
  1997. seq_printf(m, "\tDPC: flush count %10u, overflow count %10u\n",
  1998. guc->log.flush_count[GUC_DPC_LOG_BUFFER],
  1999. guc->log.total_overflow_count[GUC_DPC_LOG_BUFFER]);
  2000. seq_printf(m, "\tCRASH: flush count %10u, overflow count %10u\n",
  2001. guc->log.flush_count[GUC_CRASH_DUMP_LOG_BUFFER],
  2002. guc->log.total_overflow_count[GUC_CRASH_DUMP_LOG_BUFFER]);
  2003. seq_printf(m, "\tTotal flush interrupt count: %u\n",
  2004. guc->log.flush_interrupt_count);
  2005. seq_printf(m, "\tCapture miss count: %u\n",
  2006. guc->log.capture_miss_count);
  2007. }
  2008. static void i915_guc_client_info(struct seq_file *m,
  2009. struct drm_i915_private *dev_priv,
  2010. struct i915_guc_client *client)
  2011. {
  2012. struct intel_engine_cs *engine;
  2013. enum intel_engine_id id;
  2014. uint64_t tot = 0;
  2015. seq_printf(m, "\tPriority %d, GuC ctx index: %u, PD offset 0x%x\n",
  2016. client->priority, client->ctx_index, client->proc_desc_offset);
  2017. seq_printf(m, "\tDoorbell id %d, offset: 0x%x, cookie 0x%x\n",
  2018. client->doorbell_id, client->doorbell_offset, client->doorbell_cookie);
  2019. seq_printf(m, "\tWQ size %d, offset: 0x%x, tail %d\n",
  2020. client->wq_size, client->wq_offset, client->wq_tail);
  2021. seq_printf(m, "\tWork queue full: %u\n", client->no_wq_space);
  2022. seq_printf(m, "\tFailed doorbell: %u\n", client->b_fail);
  2023. seq_printf(m, "\tLast submission result: %d\n", client->retcode);
  2024. for_each_engine(engine, dev_priv, id) {
  2025. u64 submissions = client->submissions[id];
  2026. tot += submissions;
  2027. seq_printf(m, "\tSubmissions: %llu %s\n",
  2028. submissions, engine->name);
  2029. }
  2030. seq_printf(m, "\tTotal: %llu\n", tot);
  2031. }
  2032. static int i915_guc_info(struct seq_file *m, void *data)
  2033. {
  2034. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  2035. const struct intel_guc *guc = &dev_priv->guc;
  2036. struct intel_engine_cs *engine;
  2037. enum intel_engine_id id;
  2038. u64 total;
  2039. if (!guc->execbuf_client) {
  2040. seq_printf(m, "GuC submission %s\n",
  2041. HAS_GUC_SCHED(dev_priv) ?
  2042. "disabled" :
  2043. "not supported");
  2044. return 0;
  2045. }
  2046. seq_printf(m, "Doorbell map:\n");
  2047. seq_printf(m, "\t%*pb\n", GUC_MAX_DOORBELLS, guc->doorbell_bitmap);
  2048. seq_printf(m, "Doorbell next cacheline: 0x%x\n\n", guc->db_cacheline);
  2049. seq_printf(m, "GuC total action count: %llu\n", guc->action_count);
  2050. seq_printf(m, "GuC action failure count: %u\n", guc->action_fail);
  2051. seq_printf(m, "GuC last action command: 0x%x\n", guc->action_cmd);
  2052. seq_printf(m, "GuC last action status: 0x%x\n", guc->action_status);
  2053. seq_printf(m, "GuC last action error code: %d\n", guc->action_err);
  2054. total = 0;
  2055. seq_printf(m, "\nGuC submissions:\n");
  2056. for_each_engine(engine, dev_priv, id) {
  2057. u64 submissions = guc->submissions[id];
  2058. total += submissions;
  2059. seq_printf(m, "\t%-24s: %10llu, last seqno 0x%08x\n",
  2060. engine->name, submissions, guc->last_seqno[id]);
  2061. }
  2062. seq_printf(m, "\t%s: %llu\n", "Total", total);
  2063. seq_printf(m, "\nGuC execbuf client @ %p:\n", guc->execbuf_client);
  2064. i915_guc_client_info(m, dev_priv, guc->execbuf_client);
  2065. i915_guc_log_info(m, dev_priv);
  2066. /* Add more as required ... */
  2067. return 0;
  2068. }
  2069. static int i915_guc_log_dump(struct seq_file *m, void *data)
  2070. {
  2071. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  2072. struct drm_i915_gem_object *obj;
  2073. int i = 0, pg;
  2074. if (!dev_priv->guc.log.vma)
  2075. return 0;
  2076. obj = dev_priv->guc.log.vma->obj;
  2077. for (pg = 0; pg < obj->base.size / PAGE_SIZE; pg++) {
  2078. u32 *log = kmap_atomic(i915_gem_object_get_page(obj, pg));
  2079. for (i = 0; i < PAGE_SIZE / sizeof(u32); i += 4)
  2080. seq_printf(m, "0x%08x 0x%08x 0x%08x 0x%08x\n",
  2081. *(log + i), *(log + i + 1),
  2082. *(log + i + 2), *(log + i + 3));
  2083. kunmap_atomic(log);
  2084. }
  2085. seq_putc(m, '\n');
  2086. return 0;
  2087. }
  2088. static int i915_guc_log_control_get(void *data, u64 *val)
  2089. {
  2090. struct drm_device *dev = data;
  2091. struct drm_i915_private *dev_priv = to_i915(dev);
  2092. if (!dev_priv->guc.log.vma)
  2093. return -EINVAL;
  2094. *val = i915.guc_log_level;
  2095. return 0;
  2096. }
  2097. static int i915_guc_log_control_set(void *data, u64 val)
  2098. {
  2099. struct drm_device *dev = data;
  2100. struct drm_i915_private *dev_priv = to_i915(dev);
  2101. int ret;
  2102. if (!dev_priv->guc.log.vma)
  2103. return -EINVAL;
  2104. ret = mutex_lock_interruptible(&dev->struct_mutex);
  2105. if (ret)
  2106. return ret;
  2107. intel_runtime_pm_get(dev_priv);
  2108. ret = i915_guc_log_control(dev_priv, val);
  2109. intel_runtime_pm_put(dev_priv);
  2110. mutex_unlock(&dev->struct_mutex);
  2111. return ret;
  2112. }
  2113. DEFINE_SIMPLE_ATTRIBUTE(i915_guc_log_control_fops,
  2114. i915_guc_log_control_get, i915_guc_log_control_set,
  2115. "%lld\n");
  2116. static int i915_edp_psr_status(struct seq_file *m, void *data)
  2117. {
  2118. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  2119. u32 psrperf = 0;
  2120. u32 stat[3];
  2121. enum pipe pipe;
  2122. bool enabled = false;
  2123. if (!HAS_PSR(dev_priv)) {
  2124. seq_puts(m, "PSR not supported\n");
  2125. return 0;
  2126. }
  2127. intel_runtime_pm_get(dev_priv);
  2128. mutex_lock(&dev_priv->psr.lock);
  2129. seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
  2130. seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
  2131. seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
  2132. seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
  2133. seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
  2134. dev_priv->psr.busy_frontbuffer_bits);
  2135. seq_printf(m, "Re-enable work scheduled: %s\n",
  2136. yesno(work_busy(&dev_priv->psr.work.work)));
  2137. if (HAS_DDI(dev_priv))
  2138. enabled = I915_READ(EDP_PSR_CTL) & EDP_PSR_ENABLE;
  2139. else {
  2140. for_each_pipe(dev_priv, pipe) {
  2141. enum transcoder cpu_transcoder =
  2142. intel_pipe_to_cpu_transcoder(dev_priv, pipe);
  2143. enum intel_display_power_domain power_domain;
  2144. power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
  2145. if (!intel_display_power_get_if_enabled(dev_priv,
  2146. power_domain))
  2147. continue;
  2148. stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
  2149. VLV_EDP_PSR_CURR_STATE_MASK;
  2150. if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
  2151. (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
  2152. enabled = true;
  2153. intel_display_power_put(dev_priv, power_domain);
  2154. }
  2155. }
  2156. seq_printf(m, "Main link in standby mode: %s\n",
  2157. yesno(dev_priv->psr.link_standby));
  2158. seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
  2159. if (!HAS_DDI(dev_priv))
  2160. for_each_pipe(dev_priv, pipe) {
  2161. if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
  2162. (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
  2163. seq_printf(m, " pipe %c", pipe_name(pipe));
  2164. }
  2165. seq_puts(m, "\n");
  2166. /*
  2167. * VLV/CHV PSR has no kind of performance counter
  2168. * SKL+ Perf counter is reset to 0 everytime DC state is entered
  2169. */
  2170. if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
  2171. psrperf = I915_READ(EDP_PSR_PERF_CNT) &
  2172. EDP_PSR_PERF_CNT_MASK;
  2173. seq_printf(m, "Performance_Counter: %u\n", psrperf);
  2174. }
  2175. mutex_unlock(&dev_priv->psr.lock);
  2176. intel_runtime_pm_put(dev_priv);
  2177. return 0;
  2178. }
  2179. static int i915_sink_crc(struct seq_file *m, void *data)
  2180. {
  2181. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  2182. struct drm_device *dev = &dev_priv->drm;
  2183. struct intel_connector *connector;
  2184. struct intel_dp *intel_dp = NULL;
  2185. int ret;
  2186. u8 crc[6];
  2187. drm_modeset_lock_all(dev);
  2188. for_each_intel_connector(dev, connector) {
  2189. struct drm_crtc *crtc;
  2190. if (!connector->base.state->best_encoder)
  2191. continue;
  2192. crtc = connector->base.state->crtc;
  2193. if (!crtc->state->active)
  2194. continue;
  2195. if (connector->base.connector_type != DRM_MODE_CONNECTOR_eDP)
  2196. continue;
  2197. intel_dp = enc_to_intel_dp(connector->base.state->best_encoder);
  2198. ret = intel_dp_sink_crc(intel_dp, crc);
  2199. if (ret)
  2200. goto out;
  2201. seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
  2202. crc[0], crc[1], crc[2],
  2203. crc[3], crc[4], crc[5]);
  2204. goto out;
  2205. }
  2206. ret = -ENODEV;
  2207. out:
  2208. drm_modeset_unlock_all(dev);
  2209. return ret;
  2210. }
  2211. static int i915_energy_uJ(struct seq_file *m, void *data)
  2212. {
  2213. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  2214. u64 power;
  2215. u32 units;
  2216. if (INTEL_GEN(dev_priv) < 6)
  2217. return -ENODEV;
  2218. intel_runtime_pm_get(dev_priv);
  2219. rdmsrl(MSR_RAPL_POWER_UNIT, power);
  2220. power = (power & 0x1f00) >> 8;
  2221. units = 1000000 / (1 << power); /* convert to uJ */
  2222. power = I915_READ(MCH_SECP_NRG_STTS);
  2223. power *= units;
  2224. intel_runtime_pm_put(dev_priv);
  2225. seq_printf(m, "%llu", (long long unsigned)power);
  2226. return 0;
  2227. }
  2228. static int i915_runtime_pm_status(struct seq_file *m, void *unused)
  2229. {
  2230. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  2231. struct pci_dev *pdev = dev_priv->drm.pdev;
  2232. if (!HAS_RUNTIME_PM(dev_priv))
  2233. seq_puts(m, "Runtime power management not supported\n");
  2234. seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->gt.awake));
  2235. seq_printf(m, "IRQs disabled: %s\n",
  2236. yesno(!intel_irqs_enabled(dev_priv)));
  2237. #ifdef CONFIG_PM
  2238. seq_printf(m, "Usage count: %d\n",
  2239. atomic_read(&dev_priv->drm.dev->power.usage_count));
  2240. #else
  2241. seq_printf(m, "Device Power Management (CONFIG_PM) disabled\n");
  2242. #endif
  2243. seq_printf(m, "PCI device power state: %s [%d]\n",
  2244. pci_power_name(pdev->current_state),
  2245. pdev->current_state);
  2246. return 0;
  2247. }
  2248. static int i915_power_domain_info(struct seq_file *m, void *unused)
  2249. {
  2250. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  2251. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  2252. int i;
  2253. mutex_lock(&power_domains->lock);
  2254. seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
  2255. for (i = 0; i < power_domains->power_well_count; i++) {
  2256. struct i915_power_well *power_well;
  2257. enum intel_display_power_domain power_domain;
  2258. power_well = &power_domains->power_wells[i];
  2259. seq_printf(m, "%-25s %d\n", power_well->name,
  2260. power_well->count);
  2261. for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
  2262. power_domain++) {
  2263. if (!(BIT(power_domain) & power_well->domains))
  2264. continue;
  2265. seq_printf(m, " %-23s %d\n",
  2266. intel_display_power_domain_str(power_domain),
  2267. power_domains->domain_use_count[power_domain]);
  2268. }
  2269. }
  2270. mutex_unlock(&power_domains->lock);
  2271. return 0;
  2272. }
  2273. static int i915_dmc_info(struct seq_file *m, void *unused)
  2274. {
  2275. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  2276. struct intel_csr *csr;
  2277. if (!HAS_CSR(dev_priv)) {
  2278. seq_puts(m, "not supported\n");
  2279. return 0;
  2280. }
  2281. csr = &dev_priv->csr;
  2282. intel_runtime_pm_get(dev_priv);
  2283. seq_printf(m, "fw loaded: %s\n", yesno(csr->dmc_payload != NULL));
  2284. seq_printf(m, "path: %s\n", csr->fw_path);
  2285. if (!csr->dmc_payload)
  2286. goto out;
  2287. seq_printf(m, "version: %d.%d\n", CSR_VERSION_MAJOR(csr->version),
  2288. CSR_VERSION_MINOR(csr->version));
  2289. if (IS_SKYLAKE(dev_priv) && csr->version >= CSR_VERSION(1, 6)) {
  2290. seq_printf(m, "DC3 -> DC5 count: %d\n",
  2291. I915_READ(SKL_CSR_DC3_DC5_COUNT));
  2292. seq_printf(m, "DC5 -> DC6 count: %d\n",
  2293. I915_READ(SKL_CSR_DC5_DC6_COUNT));
  2294. } else if (IS_BROXTON(dev_priv) && csr->version >= CSR_VERSION(1, 4)) {
  2295. seq_printf(m, "DC3 -> DC5 count: %d\n",
  2296. I915_READ(BXT_CSR_DC3_DC5_COUNT));
  2297. }
  2298. out:
  2299. seq_printf(m, "program base: 0x%08x\n", I915_READ(CSR_PROGRAM(0)));
  2300. seq_printf(m, "ssp base: 0x%08x\n", I915_READ(CSR_SSP_BASE));
  2301. seq_printf(m, "htp: 0x%08x\n", I915_READ(CSR_HTP_SKL));
  2302. intel_runtime_pm_put(dev_priv);
  2303. return 0;
  2304. }
  2305. static void intel_seq_print_mode(struct seq_file *m, int tabs,
  2306. struct drm_display_mode *mode)
  2307. {
  2308. int i;
  2309. for (i = 0; i < tabs; i++)
  2310. seq_putc(m, '\t');
  2311. 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",
  2312. mode->base.id, mode->name,
  2313. mode->vrefresh, mode->clock,
  2314. mode->hdisplay, mode->hsync_start,
  2315. mode->hsync_end, mode->htotal,
  2316. mode->vdisplay, mode->vsync_start,
  2317. mode->vsync_end, mode->vtotal,
  2318. mode->type, mode->flags);
  2319. }
  2320. static void intel_encoder_info(struct seq_file *m,
  2321. struct intel_crtc *intel_crtc,
  2322. struct intel_encoder *intel_encoder)
  2323. {
  2324. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  2325. struct drm_device *dev = &dev_priv->drm;
  2326. struct drm_crtc *crtc = &intel_crtc->base;
  2327. struct intel_connector *intel_connector;
  2328. struct drm_encoder *encoder;
  2329. encoder = &intel_encoder->base;
  2330. seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
  2331. encoder->base.id, encoder->name);
  2332. for_each_connector_on_encoder(dev, encoder, intel_connector) {
  2333. struct drm_connector *connector = &intel_connector->base;
  2334. seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
  2335. connector->base.id,
  2336. connector->name,
  2337. drm_get_connector_status_name(connector->status));
  2338. if (connector->status == connector_status_connected) {
  2339. struct drm_display_mode *mode = &crtc->mode;
  2340. seq_printf(m, ", mode:\n");
  2341. intel_seq_print_mode(m, 2, mode);
  2342. } else {
  2343. seq_putc(m, '\n');
  2344. }
  2345. }
  2346. }
  2347. static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
  2348. {
  2349. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  2350. struct drm_device *dev = &dev_priv->drm;
  2351. struct drm_crtc *crtc = &intel_crtc->base;
  2352. struct intel_encoder *intel_encoder;
  2353. struct drm_plane_state *plane_state = crtc->primary->state;
  2354. struct drm_framebuffer *fb = plane_state->fb;
  2355. if (fb)
  2356. seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
  2357. fb->base.id, plane_state->src_x >> 16,
  2358. plane_state->src_y >> 16, fb->width, fb->height);
  2359. else
  2360. seq_puts(m, "\tprimary plane disabled\n");
  2361. for_each_encoder_on_crtc(dev, crtc, intel_encoder)
  2362. intel_encoder_info(m, intel_crtc, intel_encoder);
  2363. }
  2364. static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
  2365. {
  2366. struct drm_display_mode *mode = panel->fixed_mode;
  2367. seq_printf(m, "\tfixed mode:\n");
  2368. intel_seq_print_mode(m, 2, mode);
  2369. }
  2370. static void intel_dp_info(struct seq_file *m,
  2371. struct intel_connector *intel_connector)
  2372. {
  2373. struct intel_encoder *intel_encoder = intel_connector->encoder;
  2374. struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
  2375. seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
  2376. seq_printf(m, "\taudio support: %s\n", yesno(intel_dp->has_audio));
  2377. if (intel_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)
  2378. intel_panel_info(m, &intel_connector->panel);
  2379. drm_dp_downstream_debug(m, intel_dp->dpcd, intel_dp->downstream_ports,
  2380. &intel_dp->aux);
  2381. }
  2382. static void intel_dp_mst_info(struct seq_file *m,
  2383. struct intel_connector *intel_connector)
  2384. {
  2385. struct intel_encoder *intel_encoder = intel_connector->encoder;
  2386. struct intel_dp_mst_encoder *intel_mst =
  2387. enc_to_mst(&intel_encoder->base);
  2388. struct intel_digital_port *intel_dig_port = intel_mst->primary;
  2389. struct intel_dp *intel_dp = &intel_dig_port->dp;
  2390. bool has_audio = drm_dp_mst_port_has_audio(&intel_dp->mst_mgr,
  2391. intel_connector->port);
  2392. seq_printf(m, "\taudio support: %s\n", yesno(has_audio));
  2393. }
  2394. static void intel_hdmi_info(struct seq_file *m,
  2395. struct intel_connector *intel_connector)
  2396. {
  2397. struct intel_encoder *intel_encoder = intel_connector->encoder;
  2398. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
  2399. seq_printf(m, "\taudio support: %s\n", yesno(intel_hdmi->has_audio));
  2400. }
  2401. static void intel_lvds_info(struct seq_file *m,
  2402. struct intel_connector *intel_connector)
  2403. {
  2404. intel_panel_info(m, &intel_connector->panel);
  2405. }
  2406. static void intel_connector_info(struct seq_file *m,
  2407. struct drm_connector *connector)
  2408. {
  2409. struct intel_connector *intel_connector = to_intel_connector(connector);
  2410. struct intel_encoder *intel_encoder = intel_connector->encoder;
  2411. struct drm_display_mode *mode;
  2412. seq_printf(m, "connector %d: type %s, status: %s\n",
  2413. connector->base.id, connector->name,
  2414. drm_get_connector_status_name(connector->status));
  2415. if (connector->status == connector_status_connected) {
  2416. seq_printf(m, "\tname: %s\n", connector->display_info.name);
  2417. seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
  2418. connector->display_info.width_mm,
  2419. connector->display_info.height_mm);
  2420. seq_printf(m, "\tsubpixel order: %s\n",
  2421. drm_get_subpixel_order_name(connector->display_info.subpixel_order));
  2422. seq_printf(m, "\tCEA rev: %d\n",
  2423. connector->display_info.cea_rev);
  2424. }
  2425. if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
  2426. return;
  2427. switch (connector->connector_type) {
  2428. case DRM_MODE_CONNECTOR_DisplayPort:
  2429. case DRM_MODE_CONNECTOR_eDP:
  2430. if (intel_encoder->type == INTEL_OUTPUT_DP_MST)
  2431. intel_dp_mst_info(m, intel_connector);
  2432. else
  2433. intel_dp_info(m, intel_connector);
  2434. break;
  2435. case DRM_MODE_CONNECTOR_LVDS:
  2436. if (intel_encoder->type == INTEL_OUTPUT_LVDS)
  2437. intel_lvds_info(m, intel_connector);
  2438. break;
  2439. case DRM_MODE_CONNECTOR_HDMIA:
  2440. if (intel_encoder->type == INTEL_OUTPUT_HDMI ||
  2441. intel_encoder->type == INTEL_OUTPUT_UNKNOWN)
  2442. intel_hdmi_info(m, intel_connector);
  2443. break;
  2444. default:
  2445. break;
  2446. }
  2447. seq_printf(m, "\tmodes:\n");
  2448. list_for_each_entry(mode, &connector->modes, head)
  2449. intel_seq_print_mode(m, 2, mode);
  2450. }
  2451. static bool cursor_active(struct drm_i915_private *dev_priv, int pipe)
  2452. {
  2453. u32 state;
  2454. if (IS_845G(dev_priv) || IS_I865G(dev_priv))
  2455. state = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
  2456. else
  2457. state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
  2458. return state;
  2459. }
  2460. static bool cursor_position(struct drm_i915_private *dev_priv,
  2461. int pipe, int *x, int *y)
  2462. {
  2463. u32 pos;
  2464. pos = I915_READ(CURPOS(pipe));
  2465. *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
  2466. if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
  2467. *x = -*x;
  2468. *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
  2469. if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
  2470. *y = -*y;
  2471. return cursor_active(dev_priv, pipe);
  2472. }
  2473. static const char *plane_type(enum drm_plane_type type)
  2474. {
  2475. switch (type) {
  2476. case DRM_PLANE_TYPE_OVERLAY:
  2477. return "OVL";
  2478. case DRM_PLANE_TYPE_PRIMARY:
  2479. return "PRI";
  2480. case DRM_PLANE_TYPE_CURSOR:
  2481. return "CUR";
  2482. /*
  2483. * Deliberately omitting default: to generate compiler warnings
  2484. * when a new drm_plane_type gets added.
  2485. */
  2486. }
  2487. return "unknown";
  2488. }
  2489. static const char *plane_rotation(unsigned int rotation)
  2490. {
  2491. static char buf[48];
  2492. /*
  2493. * According to doc only one DRM_ROTATE_ is allowed but this
  2494. * will print them all to visualize if the values are misused
  2495. */
  2496. snprintf(buf, sizeof(buf),
  2497. "%s%s%s%s%s%s(0x%08x)",
  2498. (rotation & DRM_ROTATE_0) ? "0 " : "",
  2499. (rotation & DRM_ROTATE_90) ? "90 " : "",
  2500. (rotation & DRM_ROTATE_180) ? "180 " : "",
  2501. (rotation & DRM_ROTATE_270) ? "270 " : "",
  2502. (rotation & DRM_REFLECT_X) ? "FLIPX " : "",
  2503. (rotation & DRM_REFLECT_Y) ? "FLIPY " : "",
  2504. rotation);
  2505. return buf;
  2506. }
  2507. static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
  2508. {
  2509. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  2510. struct drm_device *dev = &dev_priv->drm;
  2511. struct intel_plane *intel_plane;
  2512. for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
  2513. struct drm_plane_state *state;
  2514. struct drm_plane *plane = &intel_plane->base;
  2515. struct drm_format_name_buf format_name;
  2516. if (!plane->state) {
  2517. seq_puts(m, "plane->state is NULL!\n");
  2518. continue;
  2519. }
  2520. state = plane->state;
  2521. if (state->fb) {
  2522. drm_get_format_name(state->fb->pixel_format, &format_name);
  2523. } else {
  2524. sprintf(format_name.str, "N/A");
  2525. }
  2526. 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",
  2527. plane->base.id,
  2528. plane_type(intel_plane->base.type),
  2529. state->crtc_x, state->crtc_y,
  2530. state->crtc_w, state->crtc_h,
  2531. (state->src_x >> 16),
  2532. ((state->src_x & 0xffff) * 15625) >> 10,
  2533. (state->src_y >> 16),
  2534. ((state->src_y & 0xffff) * 15625) >> 10,
  2535. (state->src_w >> 16),
  2536. ((state->src_w & 0xffff) * 15625) >> 10,
  2537. (state->src_h >> 16),
  2538. ((state->src_h & 0xffff) * 15625) >> 10,
  2539. format_name.str,
  2540. plane_rotation(state->rotation));
  2541. }
  2542. }
  2543. static void intel_scaler_info(struct seq_file *m, struct intel_crtc *intel_crtc)
  2544. {
  2545. struct intel_crtc_state *pipe_config;
  2546. int num_scalers = intel_crtc->num_scalers;
  2547. int i;
  2548. pipe_config = to_intel_crtc_state(intel_crtc->base.state);
  2549. /* Not all platformas have a scaler */
  2550. if (num_scalers) {
  2551. seq_printf(m, "\tnum_scalers=%d, scaler_users=%x scaler_id=%d",
  2552. num_scalers,
  2553. pipe_config->scaler_state.scaler_users,
  2554. pipe_config->scaler_state.scaler_id);
  2555. for (i = 0; i < num_scalers; i++) {
  2556. struct intel_scaler *sc =
  2557. &pipe_config->scaler_state.scalers[i];
  2558. seq_printf(m, ", scalers[%d]: use=%s, mode=%x",
  2559. i, yesno(sc->in_use), sc->mode);
  2560. }
  2561. seq_puts(m, "\n");
  2562. } else {
  2563. seq_puts(m, "\tNo scalers available on this platform\n");
  2564. }
  2565. }
  2566. static int i915_display_info(struct seq_file *m, void *unused)
  2567. {
  2568. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  2569. struct drm_device *dev = &dev_priv->drm;
  2570. struct intel_crtc *crtc;
  2571. struct drm_connector *connector;
  2572. intel_runtime_pm_get(dev_priv);
  2573. drm_modeset_lock_all(dev);
  2574. seq_printf(m, "CRTC info\n");
  2575. seq_printf(m, "---------\n");
  2576. for_each_intel_crtc(dev, crtc) {
  2577. bool active;
  2578. struct intel_crtc_state *pipe_config;
  2579. int x, y;
  2580. pipe_config = to_intel_crtc_state(crtc->base.state);
  2581. seq_printf(m, "CRTC %d: pipe: %c, active=%s, (size=%dx%d), dither=%s, bpp=%d\n",
  2582. crtc->base.base.id, pipe_name(crtc->pipe),
  2583. yesno(pipe_config->base.active),
  2584. pipe_config->pipe_src_w, pipe_config->pipe_src_h,
  2585. yesno(pipe_config->dither), pipe_config->pipe_bpp);
  2586. if (pipe_config->base.active) {
  2587. intel_crtc_info(m, crtc);
  2588. active = cursor_position(dev_priv, crtc->pipe, &x, &y);
  2589. seq_printf(m, "\tcursor visible? %s, position (%d, %d), size %dx%d, addr 0x%08x, active? %s\n",
  2590. yesno(crtc->cursor_base),
  2591. x, y, crtc->base.cursor->state->crtc_w,
  2592. crtc->base.cursor->state->crtc_h,
  2593. crtc->cursor_addr, yesno(active));
  2594. intel_scaler_info(m, crtc);
  2595. intel_plane_info(m, crtc);
  2596. }
  2597. seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
  2598. yesno(!crtc->cpu_fifo_underrun_disabled),
  2599. yesno(!crtc->pch_fifo_underrun_disabled));
  2600. }
  2601. seq_printf(m, "\n");
  2602. seq_printf(m, "Connector info\n");
  2603. seq_printf(m, "--------------\n");
  2604. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  2605. intel_connector_info(m, connector);
  2606. }
  2607. drm_modeset_unlock_all(dev);
  2608. intel_runtime_pm_put(dev_priv);
  2609. return 0;
  2610. }
  2611. static int i915_engine_info(struct seq_file *m, void *unused)
  2612. {
  2613. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  2614. struct intel_engine_cs *engine;
  2615. enum intel_engine_id id;
  2616. intel_runtime_pm_get(dev_priv);
  2617. for_each_engine(engine, dev_priv, id) {
  2618. struct intel_breadcrumbs *b = &engine->breadcrumbs;
  2619. struct drm_i915_gem_request *rq;
  2620. struct rb_node *rb;
  2621. u64 addr;
  2622. seq_printf(m, "%s\n", engine->name);
  2623. seq_printf(m, "\tcurrent seqno %x, last %x, hangcheck %x [%d ms]\n",
  2624. intel_engine_get_seqno(engine),
  2625. intel_engine_last_submit(engine),
  2626. engine->hangcheck.seqno,
  2627. jiffies_to_msecs(jiffies - engine->hangcheck.action_timestamp));
  2628. rcu_read_lock();
  2629. seq_printf(m, "\tRequests:\n");
  2630. rq = list_first_entry(&engine->timeline->requests,
  2631. struct drm_i915_gem_request, link);
  2632. if (&rq->link != &engine->timeline->requests)
  2633. print_request(m, rq, "\t\tfirst ");
  2634. rq = list_last_entry(&engine->timeline->requests,
  2635. struct drm_i915_gem_request, link);
  2636. if (&rq->link != &engine->timeline->requests)
  2637. print_request(m, rq, "\t\tlast ");
  2638. rq = i915_gem_find_active_request(engine);
  2639. if (rq) {
  2640. print_request(m, rq, "\t\tactive ");
  2641. seq_printf(m,
  2642. "\t\t[head %04x, postfix %04x, tail %04x, batch 0x%08x_%08x]\n",
  2643. rq->head, rq->postfix, rq->tail,
  2644. rq->batch ? upper_32_bits(rq->batch->node.start) : ~0u,
  2645. rq->batch ? lower_32_bits(rq->batch->node.start) : ~0u);
  2646. }
  2647. seq_printf(m, "\tRING_START: 0x%08x [0x%08x]\n",
  2648. I915_READ(RING_START(engine->mmio_base)),
  2649. rq ? i915_ggtt_offset(rq->ring->vma) : 0);
  2650. seq_printf(m, "\tRING_HEAD: 0x%08x [0x%08x]\n",
  2651. I915_READ(RING_HEAD(engine->mmio_base)) & HEAD_ADDR,
  2652. rq ? rq->ring->head : 0);
  2653. seq_printf(m, "\tRING_TAIL: 0x%08x [0x%08x]\n",
  2654. I915_READ(RING_TAIL(engine->mmio_base)) & TAIL_ADDR,
  2655. rq ? rq->ring->tail : 0);
  2656. seq_printf(m, "\tRING_CTL: 0x%08x [%s]\n",
  2657. I915_READ(RING_CTL(engine->mmio_base)),
  2658. I915_READ(RING_CTL(engine->mmio_base)) & (RING_WAIT | RING_WAIT_SEMAPHORE) ? "waiting" : "");
  2659. rcu_read_unlock();
  2660. addr = intel_engine_get_active_head(engine);
  2661. seq_printf(m, "\tACTHD: 0x%08x_%08x\n",
  2662. upper_32_bits(addr), lower_32_bits(addr));
  2663. addr = intel_engine_get_last_batch_head(engine);
  2664. seq_printf(m, "\tBBADDR: 0x%08x_%08x\n",
  2665. upper_32_bits(addr), lower_32_bits(addr));
  2666. if (i915.enable_execlists) {
  2667. u32 ptr, read, write;
  2668. struct rb_node *rb;
  2669. seq_printf(m, "\tExeclist status: 0x%08x %08x\n",
  2670. I915_READ(RING_EXECLIST_STATUS_LO(engine)),
  2671. I915_READ(RING_EXECLIST_STATUS_HI(engine)));
  2672. ptr = I915_READ(RING_CONTEXT_STATUS_PTR(engine));
  2673. read = GEN8_CSB_READ_PTR(ptr);
  2674. write = GEN8_CSB_WRITE_PTR(ptr);
  2675. seq_printf(m, "\tExeclist CSB read %d, write %d\n",
  2676. read, write);
  2677. if (read >= GEN8_CSB_ENTRIES)
  2678. read = 0;
  2679. if (write >= GEN8_CSB_ENTRIES)
  2680. write = 0;
  2681. if (read > write)
  2682. write += GEN8_CSB_ENTRIES;
  2683. while (read < write) {
  2684. unsigned int idx = ++read % GEN8_CSB_ENTRIES;
  2685. seq_printf(m, "\tExeclist CSB[%d]: 0x%08x, context: %d\n",
  2686. idx,
  2687. I915_READ(RING_CONTEXT_STATUS_BUF_LO(engine, idx)),
  2688. I915_READ(RING_CONTEXT_STATUS_BUF_HI(engine, idx)));
  2689. }
  2690. rcu_read_lock();
  2691. rq = READ_ONCE(engine->execlist_port[0].request);
  2692. if (rq)
  2693. print_request(m, rq, "\t\tELSP[0] ");
  2694. else
  2695. seq_printf(m, "\t\tELSP[0] idle\n");
  2696. rq = READ_ONCE(engine->execlist_port[1].request);
  2697. if (rq)
  2698. print_request(m, rq, "\t\tELSP[1] ");
  2699. else
  2700. seq_printf(m, "\t\tELSP[1] idle\n");
  2701. rcu_read_unlock();
  2702. spin_lock_irq(&engine->timeline->lock);
  2703. for (rb = engine->execlist_first; rb; rb = rb_next(rb)) {
  2704. rq = rb_entry(rb, typeof(*rq), priotree.node);
  2705. print_request(m, rq, "\t\tQ ");
  2706. }
  2707. spin_unlock_irq(&engine->timeline->lock);
  2708. } else if (INTEL_GEN(dev_priv) > 6) {
  2709. seq_printf(m, "\tPP_DIR_BASE: 0x%08x\n",
  2710. I915_READ(RING_PP_DIR_BASE(engine)));
  2711. seq_printf(m, "\tPP_DIR_BASE_READ: 0x%08x\n",
  2712. I915_READ(RING_PP_DIR_BASE_READ(engine)));
  2713. seq_printf(m, "\tPP_DIR_DCLV: 0x%08x\n",
  2714. I915_READ(RING_PP_DIR_DCLV(engine)));
  2715. }
  2716. spin_lock_irq(&b->lock);
  2717. for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
  2718. struct intel_wait *w = container_of(rb, typeof(*w), node);
  2719. seq_printf(m, "\t%s [%d] waiting for %x\n",
  2720. w->tsk->comm, w->tsk->pid, w->seqno);
  2721. }
  2722. spin_unlock_irq(&b->lock);
  2723. seq_puts(m, "\n");
  2724. }
  2725. intel_runtime_pm_put(dev_priv);
  2726. return 0;
  2727. }
  2728. static int i915_semaphore_status(struct seq_file *m, void *unused)
  2729. {
  2730. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  2731. struct drm_device *dev = &dev_priv->drm;
  2732. struct intel_engine_cs *engine;
  2733. int num_rings = INTEL_INFO(dev_priv)->num_rings;
  2734. enum intel_engine_id id;
  2735. int j, ret;
  2736. if (!i915.semaphores) {
  2737. seq_puts(m, "Semaphores are disabled\n");
  2738. return 0;
  2739. }
  2740. ret = mutex_lock_interruptible(&dev->struct_mutex);
  2741. if (ret)
  2742. return ret;
  2743. intel_runtime_pm_get(dev_priv);
  2744. if (IS_BROADWELL(dev_priv)) {
  2745. struct page *page;
  2746. uint64_t *seqno;
  2747. page = i915_gem_object_get_page(dev_priv->semaphore->obj, 0);
  2748. seqno = (uint64_t *)kmap_atomic(page);
  2749. for_each_engine(engine, dev_priv, id) {
  2750. uint64_t offset;
  2751. seq_printf(m, "%s\n", engine->name);
  2752. seq_puts(m, " Last signal:");
  2753. for (j = 0; j < num_rings; j++) {
  2754. offset = id * I915_NUM_ENGINES + j;
  2755. seq_printf(m, "0x%08llx (0x%02llx) ",
  2756. seqno[offset], offset * 8);
  2757. }
  2758. seq_putc(m, '\n');
  2759. seq_puts(m, " Last wait: ");
  2760. for (j = 0; j < num_rings; j++) {
  2761. offset = id + (j * I915_NUM_ENGINES);
  2762. seq_printf(m, "0x%08llx (0x%02llx) ",
  2763. seqno[offset], offset * 8);
  2764. }
  2765. seq_putc(m, '\n');
  2766. }
  2767. kunmap_atomic(seqno);
  2768. } else {
  2769. seq_puts(m, " Last signal:");
  2770. for_each_engine(engine, dev_priv, id)
  2771. for (j = 0; j < num_rings; j++)
  2772. seq_printf(m, "0x%08x\n",
  2773. I915_READ(engine->semaphore.mbox.signal[j]));
  2774. seq_putc(m, '\n');
  2775. }
  2776. intel_runtime_pm_put(dev_priv);
  2777. mutex_unlock(&dev->struct_mutex);
  2778. return 0;
  2779. }
  2780. static int i915_shared_dplls_info(struct seq_file *m, void *unused)
  2781. {
  2782. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  2783. struct drm_device *dev = &dev_priv->drm;
  2784. int i;
  2785. drm_modeset_lock_all(dev);
  2786. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  2787. struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
  2788. seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
  2789. seq_printf(m, " crtc_mask: 0x%08x, active: 0x%x, on: %s\n",
  2790. pll->config.crtc_mask, pll->active_mask, yesno(pll->on));
  2791. seq_printf(m, " tracked hardware state:\n");
  2792. seq_printf(m, " dpll: 0x%08x\n", pll->config.hw_state.dpll);
  2793. seq_printf(m, " dpll_md: 0x%08x\n",
  2794. pll->config.hw_state.dpll_md);
  2795. seq_printf(m, " fp0: 0x%08x\n", pll->config.hw_state.fp0);
  2796. seq_printf(m, " fp1: 0x%08x\n", pll->config.hw_state.fp1);
  2797. seq_printf(m, " wrpll: 0x%08x\n", pll->config.hw_state.wrpll);
  2798. }
  2799. drm_modeset_unlock_all(dev);
  2800. return 0;
  2801. }
  2802. static int i915_wa_registers(struct seq_file *m, void *unused)
  2803. {
  2804. int i;
  2805. int ret;
  2806. struct intel_engine_cs *engine;
  2807. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  2808. struct drm_device *dev = &dev_priv->drm;
  2809. struct i915_workarounds *workarounds = &dev_priv->workarounds;
  2810. enum intel_engine_id id;
  2811. ret = mutex_lock_interruptible(&dev->struct_mutex);
  2812. if (ret)
  2813. return ret;
  2814. intel_runtime_pm_get(dev_priv);
  2815. seq_printf(m, "Workarounds applied: %d\n", workarounds->count);
  2816. for_each_engine(engine, dev_priv, id)
  2817. seq_printf(m, "HW whitelist count for %s: %d\n",
  2818. engine->name, workarounds->hw_whitelist_count[id]);
  2819. for (i = 0; i < workarounds->count; ++i) {
  2820. i915_reg_t addr;
  2821. u32 mask, value, read;
  2822. bool ok;
  2823. addr = workarounds->reg[i].addr;
  2824. mask = workarounds->reg[i].mask;
  2825. value = workarounds->reg[i].value;
  2826. read = I915_READ(addr);
  2827. ok = (value & mask) == (read & mask);
  2828. seq_printf(m, "0x%X: 0x%08X, mask: 0x%08X, read: 0x%08x, status: %s\n",
  2829. i915_mmio_reg_offset(addr), value, mask, read, ok ? "OK" : "FAIL");
  2830. }
  2831. intel_runtime_pm_put(dev_priv);
  2832. mutex_unlock(&dev->struct_mutex);
  2833. return 0;
  2834. }
  2835. static int i915_ddb_info(struct seq_file *m, void *unused)
  2836. {
  2837. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  2838. struct drm_device *dev = &dev_priv->drm;
  2839. struct skl_ddb_allocation *ddb;
  2840. struct skl_ddb_entry *entry;
  2841. enum pipe pipe;
  2842. int plane;
  2843. if (INTEL_GEN(dev_priv) < 9)
  2844. return 0;
  2845. drm_modeset_lock_all(dev);
  2846. ddb = &dev_priv->wm.skl_hw.ddb;
  2847. seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
  2848. for_each_pipe(dev_priv, pipe) {
  2849. seq_printf(m, "Pipe %c\n", pipe_name(pipe));
  2850. for_each_universal_plane(dev_priv, pipe, plane) {
  2851. entry = &ddb->plane[pipe][plane];
  2852. seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
  2853. entry->start, entry->end,
  2854. skl_ddb_entry_size(entry));
  2855. }
  2856. entry = &ddb->plane[pipe][PLANE_CURSOR];
  2857. seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
  2858. entry->end, skl_ddb_entry_size(entry));
  2859. }
  2860. drm_modeset_unlock_all(dev);
  2861. return 0;
  2862. }
  2863. static void drrs_status_per_crtc(struct seq_file *m,
  2864. struct drm_device *dev,
  2865. struct intel_crtc *intel_crtc)
  2866. {
  2867. struct drm_i915_private *dev_priv = to_i915(dev);
  2868. struct i915_drrs *drrs = &dev_priv->drrs;
  2869. int vrefresh = 0;
  2870. struct drm_connector *connector;
  2871. drm_for_each_connector(connector, dev) {
  2872. if (connector->state->crtc != &intel_crtc->base)
  2873. continue;
  2874. seq_printf(m, "%s:\n", connector->name);
  2875. }
  2876. if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
  2877. seq_puts(m, "\tVBT: DRRS_type: Static");
  2878. else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
  2879. seq_puts(m, "\tVBT: DRRS_type: Seamless");
  2880. else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
  2881. seq_puts(m, "\tVBT: DRRS_type: None");
  2882. else
  2883. seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
  2884. seq_puts(m, "\n\n");
  2885. if (to_intel_crtc_state(intel_crtc->base.state)->has_drrs) {
  2886. struct intel_panel *panel;
  2887. mutex_lock(&drrs->mutex);
  2888. /* DRRS Supported */
  2889. seq_puts(m, "\tDRRS Supported: Yes\n");
  2890. /* disable_drrs() will make drrs->dp NULL */
  2891. if (!drrs->dp) {
  2892. seq_puts(m, "Idleness DRRS: Disabled");
  2893. mutex_unlock(&drrs->mutex);
  2894. return;
  2895. }
  2896. panel = &drrs->dp->attached_connector->panel;
  2897. seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
  2898. drrs->busy_frontbuffer_bits);
  2899. seq_puts(m, "\n\t\t");
  2900. if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
  2901. seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
  2902. vrefresh = panel->fixed_mode->vrefresh;
  2903. } else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
  2904. seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
  2905. vrefresh = panel->downclock_mode->vrefresh;
  2906. } else {
  2907. seq_printf(m, "DRRS_State: Unknown(%d)\n",
  2908. drrs->refresh_rate_type);
  2909. mutex_unlock(&drrs->mutex);
  2910. return;
  2911. }
  2912. seq_printf(m, "\t\tVrefresh: %d", vrefresh);
  2913. seq_puts(m, "\n\t\t");
  2914. mutex_unlock(&drrs->mutex);
  2915. } else {
  2916. /* DRRS not supported. Print the VBT parameter*/
  2917. seq_puts(m, "\tDRRS Supported : No");
  2918. }
  2919. seq_puts(m, "\n");
  2920. }
  2921. static int i915_drrs_status(struct seq_file *m, void *unused)
  2922. {
  2923. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  2924. struct drm_device *dev = &dev_priv->drm;
  2925. struct intel_crtc *intel_crtc;
  2926. int active_crtc_cnt = 0;
  2927. drm_modeset_lock_all(dev);
  2928. for_each_intel_crtc(dev, intel_crtc) {
  2929. if (intel_crtc->base.state->active) {
  2930. active_crtc_cnt++;
  2931. seq_printf(m, "\nCRTC %d: ", active_crtc_cnt);
  2932. drrs_status_per_crtc(m, dev, intel_crtc);
  2933. }
  2934. }
  2935. drm_modeset_unlock_all(dev);
  2936. if (!active_crtc_cnt)
  2937. seq_puts(m, "No active crtc found\n");
  2938. return 0;
  2939. }
  2940. struct pipe_crc_info {
  2941. const char *name;
  2942. struct drm_i915_private *dev_priv;
  2943. enum pipe pipe;
  2944. };
  2945. static int i915_dp_mst_info(struct seq_file *m, void *unused)
  2946. {
  2947. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  2948. struct drm_device *dev = &dev_priv->drm;
  2949. struct intel_encoder *intel_encoder;
  2950. struct intel_digital_port *intel_dig_port;
  2951. struct drm_connector *connector;
  2952. drm_modeset_lock_all(dev);
  2953. drm_for_each_connector(connector, dev) {
  2954. if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
  2955. continue;
  2956. intel_encoder = intel_attached_encoder(connector);
  2957. if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
  2958. continue;
  2959. intel_dig_port = enc_to_dig_port(&intel_encoder->base);
  2960. if (!intel_dig_port->dp.can_mst)
  2961. continue;
  2962. seq_printf(m, "MST Source Port %c\n",
  2963. port_name(intel_dig_port->port));
  2964. drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
  2965. }
  2966. drm_modeset_unlock_all(dev);
  2967. return 0;
  2968. }
  2969. static int i915_pipe_crc_open(struct inode *inode, struct file *filep)
  2970. {
  2971. struct pipe_crc_info *info = inode->i_private;
  2972. struct drm_i915_private *dev_priv = info->dev_priv;
  2973. struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
  2974. if (info->pipe >= INTEL_INFO(dev_priv)->num_pipes)
  2975. return -ENODEV;
  2976. spin_lock_irq(&pipe_crc->lock);
  2977. if (pipe_crc->opened) {
  2978. spin_unlock_irq(&pipe_crc->lock);
  2979. return -EBUSY; /* already open */
  2980. }
  2981. pipe_crc->opened = true;
  2982. filep->private_data = inode->i_private;
  2983. spin_unlock_irq(&pipe_crc->lock);
  2984. return 0;
  2985. }
  2986. static int i915_pipe_crc_release(struct inode *inode, struct file *filep)
  2987. {
  2988. struct pipe_crc_info *info = inode->i_private;
  2989. struct drm_i915_private *dev_priv = info->dev_priv;
  2990. struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
  2991. spin_lock_irq(&pipe_crc->lock);
  2992. pipe_crc->opened = false;
  2993. spin_unlock_irq(&pipe_crc->lock);
  2994. return 0;
  2995. }
  2996. /* (6 fields, 8 chars each, space separated (5) + '\n') */
  2997. #define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
  2998. /* account for \'0' */
  2999. #define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
  3000. static int pipe_crc_data_count(struct intel_pipe_crc *pipe_crc)
  3001. {
  3002. assert_spin_locked(&pipe_crc->lock);
  3003. return CIRC_CNT(pipe_crc->head, pipe_crc->tail,
  3004. INTEL_PIPE_CRC_ENTRIES_NR);
  3005. }
  3006. static ssize_t
  3007. i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,
  3008. loff_t *pos)
  3009. {
  3010. struct pipe_crc_info *info = filep->private_data;
  3011. struct drm_i915_private *dev_priv = info->dev_priv;
  3012. struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
  3013. char buf[PIPE_CRC_BUFFER_LEN];
  3014. int n_entries;
  3015. ssize_t bytes_read;
  3016. /*
  3017. * Don't allow user space to provide buffers not big enough to hold
  3018. * a line of data.
  3019. */
  3020. if (count < PIPE_CRC_LINE_LEN)
  3021. return -EINVAL;
  3022. if (pipe_crc->source == INTEL_PIPE_CRC_SOURCE_NONE)
  3023. return 0;
  3024. /* nothing to read */
  3025. spin_lock_irq(&pipe_crc->lock);
  3026. while (pipe_crc_data_count(pipe_crc) == 0) {
  3027. int ret;
  3028. if (filep->f_flags & O_NONBLOCK) {
  3029. spin_unlock_irq(&pipe_crc->lock);
  3030. return -EAGAIN;
  3031. }
  3032. ret = wait_event_interruptible_lock_irq(pipe_crc->wq,
  3033. pipe_crc_data_count(pipe_crc), pipe_crc->lock);
  3034. if (ret) {
  3035. spin_unlock_irq(&pipe_crc->lock);
  3036. return ret;
  3037. }
  3038. }
  3039. /* We now have one or more entries to read */
  3040. n_entries = count / PIPE_CRC_LINE_LEN;
  3041. bytes_read = 0;
  3042. while (n_entries > 0) {
  3043. struct intel_pipe_crc_entry *entry =
  3044. &pipe_crc->entries[pipe_crc->tail];
  3045. if (CIRC_CNT(pipe_crc->head, pipe_crc->tail,
  3046. INTEL_PIPE_CRC_ENTRIES_NR) < 1)
  3047. break;
  3048. BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
  3049. pipe_crc->tail = (pipe_crc->tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
  3050. bytes_read += snprintf(buf, PIPE_CRC_BUFFER_LEN,
  3051. "%8u %8x %8x %8x %8x %8x\n",
  3052. entry->frame, entry->crc[0],
  3053. entry->crc[1], entry->crc[2],
  3054. entry->crc[3], entry->crc[4]);
  3055. spin_unlock_irq(&pipe_crc->lock);
  3056. if (copy_to_user(user_buf, buf, PIPE_CRC_LINE_LEN))
  3057. return -EFAULT;
  3058. user_buf += PIPE_CRC_LINE_LEN;
  3059. n_entries--;
  3060. spin_lock_irq(&pipe_crc->lock);
  3061. }
  3062. spin_unlock_irq(&pipe_crc->lock);
  3063. return bytes_read;
  3064. }
  3065. static const struct file_operations i915_pipe_crc_fops = {
  3066. .owner = THIS_MODULE,
  3067. .open = i915_pipe_crc_open,
  3068. .read = i915_pipe_crc_read,
  3069. .release = i915_pipe_crc_release,
  3070. };
  3071. static struct pipe_crc_info i915_pipe_crc_data[I915_MAX_PIPES] = {
  3072. {
  3073. .name = "i915_pipe_A_crc",
  3074. .pipe = PIPE_A,
  3075. },
  3076. {
  3077. .name = "i915_pipe_B_crc",
  3078. .pipe = PIPE_B,
  3079. },
  3080. {
  3081. .name = "i915_pipe_C_crc",
  3082. .pipe = PIPE_C,
  3083. },
  3084. };
  3085. static int i915_pipe_crc_create(struct dentry *root, struct drm_minor *minor,
  3086. enum pipe pipe)
  3087. {
  3088. struct drm_i915_private *dev_priv = to_i915(minor->dev);
  3089. struct dentry *ent;
  3090. struct pipe_crc_info *info = &i915_pipe_crc_data[pipe];
  3091. info->dev_priv = dev_priv;
  3092. ent = debugfs_create_file(info->name, S_IRUGO, root, info,
  3093. &i915_pipe_crc_fops);
  3094. if (!ent)
  3095. return -ENOMEM;
  3096. return drm_add_fake_info_node(minor, ent, info);
  3097. }
  3098. static const char * const pipe_crc_sources[] = {
  3099. "none",
  3100. "plane1",
  3101. "plane2",
  3102. "pf",
  3103. "pipe",
  3104. "TV",
  3105. "DP-B",
  3106. "DP-C",
  3107. "DP-D",
  3108. "auto",
  3109. };
  3110. static const char *pipe_crc_source_name(enum intel_pipe_crc_source source)
  3111. {
  3112. BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources) != INTEL_PIPE_CRC_SOURCE_MAX);
  3113. return pipe_crc_sources[source];
  3114. }
  3115. static int display_crc_ctl_show(struct seq_file *m, void *data)
  3116. {
  3117. struct drm_i915_private *dev_priv = m->private;
  3118. int i;
  3119. for (i = 0; i < I915_MAX_PIPES; i++)
  3120. seq_printf(m, "%c %s\n", pipe_name(i),
  3121. pipe_crc_source_name(dev_priv->pipe_crc[i].source));
  3122. return 0;
  3123. }
  3124. static int display_crc_ctl_open(struct inode *inode, struct file *file)
  3125. {
  3126. return single_open(file, display_crc_ctl_show, inode->i_private);
  3127. }
  3128. static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
  3129. uint32_t *val)
  3130. {
  3131. if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
  3132. *source = INTEL_PIPE_CRC_SOURCE_PIPE;
  3133. switch (*source) {
  3134. case INTEL_PIPE_CRC_SOURCE_PIPE:
  3135. *val = PIPE_CRC_ENABLE | PIPE_CRC_INCLUDE_BORDER_I8XX;
  3136. break;
  3137. case INTEL_PIPE_CRC_SOURCE_NONE:
  3138. *val = 0;
  3139. break;
  3140. default:
  3141. return -EINVAL;
  3142. }
  3143. return 0;
  3144. }
  3145. static int i9xx_pipe_crc_auto_source(struct drm_i915_private *dev_priv,
  3146. enum pipe pipe,
  3147. enum intel_pipe_crc_source *source)
  3148. {
  3149. struct drm_device *dev = &dev_priv->drm;
  3150. struct intel_encoder *encoder;
  3151. struct intel_crtc *crtc;
  3152. struct intel_digital_port *dig_port;
  3153. int ret = 0;
  3154. *source = INTEL_PIPE_CRC_SOURCE_PIPE;
  3155. drm_modeset_lock_all(dev);
  3156. for_each_intel_encoder(dev, encoder) {
  3157. if (!encoder->base.crtc)
  3158. continue;
  3159. crtc = to_intel_crtc(encoder->base.crtc);
  3160. if (crtc->pipe != pipe)
  3161. continue;
  3162. switch (encoder->type) {
  3163. case INTEL_OUTPUT_TVOUT:
  3164. *source = INTEL_PIPE_CRC_SOURCE_TV;
  3165. break;
  3166. case INTEL_OUTPUT_DP:
  3167. case INTEL_OUTPUT_EDP:
  3168. dig_port = enc_to_dig_port(&encoder->base);
  3169. switch (dig_port->port) {
  3170. case PORT_B:
  3171. *source = INTEL_PIPE_CRC_SOURCE_DP_B;
  3172. break;
  3173. case PORT_C:
  3174. *source = INTEL_PIPE_CRC_SOURCE_DP_C;
  3175. break;
  3176. case PORT_D:
  3177. *source = INTEL_PIPE_CRC_SOURCE_DP_D;
  3178. break;
  3179. default:
  3180. WARN(1, "nonexisting DP port %c\n",
  3181. port_name(dig_port->port));
  3182. break;
  3183. }
  3184. break;
  3185. default:
  3186. break;
  3187. }
  3188. }
  3189. drm_modeset_unlock_all(dev);
  3190. return ret;
  3191. }
  3192. static int vlv_pipe_crc_ctl_reg(struct drm_i915_private *dev_priv,
  3193. enum pipe pipe,
  3194. enum intel_pipe_crc_source *source,
  3195. uint32_t *val)
  3196. {
  3197. bool need_stable_symbols = false;
  3198. if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
  3199. int ret = i9xx_pipe_crc_auto_source(dev_priv, pipe, source);
  3200. if (ret)
  3201. return ret;
  3202. }
  3203. switch (*source) {
  3204. case INTEL_PIPE_CRC_SOURCE_PIPE:
  3205. *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_VLV;
  3206. break;
  3207. case INTEL_PIPE_CRC_SOURCE_DP_B:
  3208. *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_VLV;
  3209. need_stable_symbols = true;
  3210. break;
  3211. case INTEL_PIPE_CRC_SOURCE_DP_C:
  3212. *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_VLV;
  3213. need_stable_symbols = true;
  3214. break;
  3215. case INTEL_PIPE_CRC_SOURCE_DP_D:
  3216. if (!IS_CHERRYVIEW(dev_priv))
  3217. return -EINVAL;
  3218. *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_VLV;
  3219. need_stable_symbols = true;
  3220. break;
  3221. case INTEL_PIPE_CRC_SOURCE_NONE:
  3222. *val = 0;
  3223. break;
  3224. default:
  3225. return -EINVAL;
  3226. }
  3227. /*
  3228. * When the pipe CRC tap point is after the transcoders we need
  3229. * to tweak symbol-level features to produce a deterministic series of
  3230. * symbols for a given frame. We need to reset those features only once
  3231. * a frame (instead of every nth symbol):
  3232. * - DC-balance: used to ensure a better clock recovery from the data
  3233. * link (SDVO)
  3234. * - DisplayPort scrambling: used for EMI reduction
  3235. */
  3236. if (need_stable_symbols) {
  3237. uint32_t tmp = I915_READ(PORT_DFT2_G4X);
  3238. tmp |= DC_BALANCE_RESET_VLV;
  3239. switch (pipe) {
  3240. case PIPE_A:
  3241. tmp |= PIPE_A_SCRAMBLE_RESET;
  3242. break;
  3243. case PIPE_B:
  3244. tmp |= PIPE_B_SCRAMBLE_RESET;
  3245. break;
  3246. case PIPE_C:
  3247. tmp |= PIPE_C_SCRAMBLE_RESET;
  3248. break;
  3249. default:
  3250. return -EINVAL;
  3251. }
  3252. I915_WRITE(PORT_DFT2_G4X, tmp);
  3253. }
  3254. return 0;
  3255. }
  3256. static int i9xx_pipe_crc_ctl_reg(struct drm_i915_private *dev_priv,
  3257. enum pipe pipe,
  3258. enum intel_pipe_crc_source *source,
  3259. uint32_t *val)
  3260. {
  3261. bool need_stable_symbols = false;
  3262. if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
  3263. int ret = i9xx_pipe_crc_auto_source(dev_priv, pipe, source);
  3264. if (ret)
  3265. return ret;
  3266. }
  3267. switch (*source) {
  3268. case INTEL_PIPE_CRC_SOURCE_PIPE:
  3269. *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_I9XX;
  3270. break;
  3271. case INTEL_PIPE_CRC_SOURCE_TV:
  3272. if (!SUPPORTS_TV(dev_priv))
  3273. return -EINVAL;
  3274. *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_TV_PRE;
  3275. break;
  3276. case INTEL_PIPE_CRC_SOURCE_DP_B:
  3277. if (!IS_G4X(dev_priv))
  3278. return -EINVAL;
  3279. *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_G4X;
  3280. need_stable_symbols = true;
  3281. break;
  3282. case INTEL_PIPE_CRC_SOURCE_DP_C:
  3283. if (!IS_G4X(dev_priv))
  3284. return -EINVAL;
  3285. *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_G4X;
  3286. need_stable_symbols = true;
  3287. break;
  3288. case INTEL_PIPE_CRC_SOURCE_DP_D:
  3289. if (!IS_G4X(dev_priv))
  3290. return -EINVAL;
  3291. *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_G4X;
  3292. need_stable_symbols = true;
  3293. break;
  3294. case INTEL_PIPE_CRC_SOURCE_NONE:
  3295. *val = 0;
  3296. break;
  3297. default:
  3298. return -EINVAL;
  3299. }
  3300. /*
  3301. * When the pipe CRC tap point is after the transcoders we need
  3302. * to tweak symbol-level features to produce a deterministic series of
  3303. * symbols for a given frame. We need to reset those features only once
  3304. * a frame (instead of every nth symbol):
  3305. * - DC-balance: used to ensure a better clock recovery from the data
  3306. * link (SDVO)
  3307. * - DisplayPort scrambling: used for EMI reduction
  3308. */
  3309. if (need_stable_symbols) {
  3310. uint32_t tmp = I915_READ(PORT_DFT2_G4X);
  3311. WARN_ON(!IS_G4X(dev_priv));
  3312. I915_WRITE(PORT_DFT_I9XX,
  3313. I915_READ(PORT_DFT_I9XX) | DC_BALANCE_RESET);
  3314. if (pipe == PIPE_A)
  3315. tmp |= PIPE_A_SCRAMBLE_RESET;
  3316. else
  3317. tmp |= PIPE_B_SCRAMBLE_RESET;
  3318. I915_WRITE(PORT_DFT2_G4X, tmp);
  3319. }
  3320. return 0;
  3321. }
  3322. static void vlv_undo_pipe_scramble_reset(struct drm_i915_private *dev_priv,
  3323. enum pipe pipe)
  3324. {
  3325. uint32_t tmp = I915_READ(PORT_DFT2_G4X);
  3326. switch (pipe) {
  3327. case PIPE_A:
  3328. tmp &= ~PIPE_A_SCRAMBLE_RESET;
  3329. break;
  3330. case PIPE_B:
  3331. tmp &= ~PIPE_B_SCRAMBLE_RESET;
  3332. break;
  3333. case PIPE_C:
  3334. tmp &= ~PIPE_C_SCRAMBLE_RESET;
  3335. break;
  3336. default:
  3337. return;
  3338. }
  3339. if (!(tmp & PIPE_SCRAMBLE_RESET_MASK))
  3340. tmp &= ~DC_BALANCE_RESET_VLV;
  3341. I915_WRITE(PORT_DFT2_G4X, tmp);
  3342. }
  3343. static void g4x_undo_pipe_scramble_reset(struct drm_i915_private *dev_priv,
  3344. enum pipe pipe)
  3345. {
  3346. uint32_t tmp = I915_READ(PORT_DFT2_G4X);
  3347. if (pipe == PIPE_A)
  3348. tmp &= ~PIPE_A_SCRAMBLE_RESET;
  3349. else
  3350. tmp &= ~PIPE_B_SCRAMBLE_RESET;
  3351. I915_WRITE(PORT_DFT2_G4X, tmp);
  3352. if (!(tmp & PIPE_SCRAMBLE_RESET_MASK)) {
  3353. I915_WRITE(PORT_DFT_I9XX,
  3354. I915_READ(PORT_DFT_I9XX) & ~DC_BALANCE_RESET);
  3355. }
  3356. }
  3357. static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
  3358. uint32_t *val)
  3359. {
  3360. if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
  3361. *source = INTEL_PIPE_CRC_SOURCE_PIPE;
  3362. switch (*source) {
  3363. case INTEL_PIPE_CRC_SOURCE_PLANE1:
  3364. *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_ILK;
  3365. break;
  3366. case INTEL_PIPE_CRC_SOURCE_PLANE2:
  3367. *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_ILK;
  3368. break;
  3369. case INTEL_PIPE_CRC_SOURCE_PIPE:
  3370. *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_ILK;
  3371. break;
  3372. case INTEL_PIPE_CRC_SOURCE_NONE:
  3373. *val = 0;
  3374. break;
  3375. default:
  3376. return -EINVAL;
  3377. }
  3378. return 0;
  3379. }
  3380. static void hsw_trans_edp_pipe_A_crc_wa(struct drm_i915_private *dev_priv,
  3381. bool enable)
  3382. {
  3383. struct drm_device *dev = &dev_priv->drm;
  3384. struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_A);
  3385. struct intel_crtc_state *pipe_config;
  3386. struct drm_atomic_state *state;
  3387. int ret = 0;
  3388. drm_modeset_lock_all(dev);
  3389. state = drm_atomic_state_alloc(dev);
  3390. if (!state) {
  3391. ret = -ENOMEM;
  3392. goto out;
  3393. }
  3394. state->acquire_ctx = drm_modeset_legacy_acquire_ctx(&crtc->base);
  3395. pipe_config = intel_atomic_get_crtc_state(state, crtc);
  3396. if (IS_ERR(pipe_config)) {
  3397. ret = PTR_ERR(pipe_config);
  3398. goto out;
  3399. }
  3400. pipe_config->pch_pfit.force_thru = enable;
  3401. if (pipe_config->cpu_transcoder == TRANSCODER_EDP &&
  3402. pipe_config->pch_pfit.enabled != enable)
  3403. pipe_config->base.connectors_changed = true;
  3404. ret = drm_atomic_commit(state);
  3405. out:
  3406. WARN(ret, "Toggling workaround to %i returns %i\n", enable, ret);
  3407. drm_modeset_unlock_all(dev);
  3408. drm_atomic_state_put(state);
  3409. }
  3410. static int ivb_pipe_crc_ctl_reg(struct drm_i915_private *dev_priv,
  3411. enum pipe pipe,
  3412. enum intel_pipe_crc_source *source,
  3413. uint32_t *val)
  3414. {
  3415. if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
  3416. *source = INTEL_PIPE_CRC_SOURCE_PF;
  3417. switch (*source) {
  3418. case INTEL_PIPE_CRC_SOURCE_PLANE1:
  3419. *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_IVB;
  3420. break;
  3421. case INTEL_PIPE_CRC_SOURCE_PLANE2:
  3422. *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_IVB;
  3423. break;
  3424. case INTEL_PIPE_CRC_SOURCE_PF:
  3425. if (IS_HASWELL(dev_priv) && pipe == PIPE_A)
  3426. hsw_trans_edp_pipe_A_crc_wa(dev_priv, true);
  3427. *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PF_IVB;
  3428. break;
  3429. case INTEL_PIPE_CRC_SOURCE_NONE:
  3430. *val = 0;
  3431. break;
  3432. default:
  3433. return -EINVAL;
  3434. }
  3435. return 0;
  3436. }
  3437. static int pipe_crc_set_source(struct drm_i915_private *dev_priv,
  3438. enum pipe pipe,
  3439. enum intel_pipe_crc_source source)
  3440. {
  3441. struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
  3442. struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
  3443. enum intel_display_power_domain power_domain;
  3444. u32 val = 0; /* shut up gcc */
  3445. int ret;
  3446. if (pipe_crc->source == source)
  3447. return 0;
  3448. /* forbid changing the source without going back to 'none' */
  3449. if (pipe_crc->source && source)
  3450. return -EINVAL;
  3451. power_domain = POWER_DOMAIN_PIPE(pipe);
  3452. if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) {
  3453. DRM_DEBUG_KMS("Trying to capture CRC while pipe is off\n");
  3454. return -EIO;
  3455. }
  3456. if (IS_GEN2(dev_priv))
  3457. ret = i8xx_pipe_crc_ctl_reg(&source, &val);
  3458. else if (INTEL_GEN(dev_priv) < 5)
  3459. ret = i9xx_pipe_crc_ctl_reg(dev_priv, pipe, &source, &val);
  3460. else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  3461. ret = vlv_pipe_crc_ctl_reg(dev_priv, pipe, &source, &val);
  3462. else if (IS_GEN5(dev_priv) || IS_GEN6(dev_priv))
  3463. ret = ilk_pipe_crc_ctl_reg(&source, &val);
  3464. else
  3465. ret = ivb_pipe_crc_ctl_reg(dev_priv, pipe, &source, &val);
  3466. if (ret != 0)
  3467. goto out;
  3468. /* none -> real source transition */
  3469. if (source) {
  3470. struct intel_pipe_crc_entry *entries;
  3471. DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
  3472. pipe_name(pipe), pipe_crc_source_name(source));
  3473. entries = kcalloc(INTEL_PIPE_CRC_ENTRIES_NR,
  3474. sizeof(pipe_crc->entries[0]),
  3475. GFP_KERNEL);
  3476. if (!entries) {
  3477. ret = -ENOMEM;
  3478. goto out;
  3479. }
  3480. /*
  3481. * When IPS gets enabled, the pipe CRC changes. Since IPS gets
  3482. * enabled and disabled dynamically based on package C states,
  3483. * user space can't make reliable use of the CRCs, so let's just
  3484. * completely disable it.
  3485. */
  3486. hsw_disable_ips(crtc);
  3487. spin_lock_irq(&pipe_crc->lock);
  3488. kfree(pipe_crc->entries);
  3489. pipe_crc->entries = entries;
  3490. pipe_crc->head = 0;
  3491. pipe_crc->tail = 0;
  3492. spin_unlock_irq(&pipe_crc->lock);
  3493. }
  3494. pipe_crc->source = source;
  3495. I915_WRITE(PIPE_CRC_CTL(pipe), val);
  3496. POSTING_READ(PIPE_CRC_CTL(pipe));
  3497. /* real source -> none transition */
  3498. if (source == INTEL_PIPE_CRC_SOURCE_NONE) {
  3499. struct intel_pipe_crc_entry *entries;
  3500. struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv,
  3501. pipe);
  3502. DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
  3503. pipe_name(pipe));
  3504. drm_modeset_lock(&crtc->base.mutex, NULL);
  3505. if (crtc->base.state->active)
  3506. intel_wait_for_vblank(dev_priv, pipe);
  3507. drm_modeset_unlock(&crtc->base.mutex);
  3508. spin_lock_irq(&pipe_crc->lock);
  3509. entries = pipe_crc->entries;
  3510. pipe_crc->entries = NULL;
  3511. pipe_crc->head = 0;
  3512. pipe_crc->tail = 0;
  3513. spin_unlock_irq(&pipe_crc->lock);
  3514. kfree(entries);
  3515. if (IS_G4X(dev_priv))
  3516. g4x_undo_pipe_scramble_reset(dev_priv, pipe);
  3517. else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  3518. vlv_undo_pipe_scramble_reset(dev_priv, pipe);
  3519. else if (IS_HASWELL(dev_priv) && pipe == PIPE_A)
  3520. hsw_trans_edp_pipe_A_crc_wa(dev_priv, false);
  3521. hsw_enable_ips(crtc);
  3522. }
  3523. ret = 0;
  3524. out:
  3525. intel_display_power_put(dev_priv, power_domain);
  3526. return ret;
  3527. }
  3528. /*
  3529. * Parse pipe CRC command strings:
  3530. * command: wsp* object wsp+ name wsp+ source wsp*
  3531. * object: 'pipe'
  3532. * name: (A | B | C)
  3533. * source: (none | plane1 | plane2 | pf)
  3534. * wsp: (#0x20 | #0x9 | #0xA)+
  3535. *
  3536. * eg.:
  3537. * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
  3538. * "pipe A none" -> Stop CRC
  3539. */
  3540. static int display_crc_ctl_tokenize(char *buf, char *words[], int max_words)
  3541. {
  3542. int n_words = 0;
  3543. while (*buf) {
  3544. char *end;
  3545. /* skip leading white space */
  3546. buf = skip_spaces(buf);
  3547. if (!*buf)
  3548. break; /* end of buffer */
  3549. /* find end of word */
  3550. for (end = buf; *end && !isspace(*end); end++)
  3551. ;
  3552. if (n_words == max_words) {
  3553. DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
  3554. max_words);
  3555. return -EINVAL; /* ran out of words[] before bytes */
  3556. }
  3557. if (*end)
  3558. *end++ = '\0';
  3559. words[n_words++] = buf;
  3560. buf = end;
  3561. }
  3562. return n_words;
  3563. }
  3564. enum intel_pipe_crc_object {
  3565. PIPE_CRC_OBJECT_PIPE,
  3566. };
  3567. static const char * const pipe_crc_objects[] = {
  3568. "pipe",
  3569. };
  3570. static int
  3571. display_crc_ctl_parse_object(const char *buf, enum intel_pipe_crc_object *o)
  3572. {
  3573. int i;
  3574. for (i = 0; i < ARRAY_SIZE(pipe_crc_objects); i++)
  3575. if (!strcmp(buf, pipe_crc_objects[i])) {
  3576. *o = i;
  3577. return 0;
  3578. }
  3579. return -EINVAL;
  3580. }
  3581. static int display_crc_ctl_parse_pipe(const char *buf, enum pipe *pipe)
  3582. {
  3583. const char name = buf[0];
  3584. if (name < 'A' || name >= pipe_name(I915_MAX_PIPES))
  3585. return -EINVAL;
  3586. *pipe = name - 'A';
  3587. return 0;
  3588. }
  3589. static int
  3590. display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s)
  3591. {
  3592. int i;
  3593. for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
  3594. if (!strcmp(buf, pipe_crc_sources[i])) {
  3595. *s = i;
  3596. return 0;
  3597. }
  3598. return -EINVAL;
  3599. }
  3600. static int display_crc_ctl_parse(struct drm_i915_private *dev_priv,
  3601. char *buf, size_t len)
  3602. {
  3603. #define N_WORDS 3
  3604. int n_words;
  3605. char *words[N_WORDS];
  3606. enum pipe pipe;
  3607. enum intel_pipe_crc_object object;
  3608. enum intel_pipe_crc_source source;
  3609. n_words = display_crc_ctl_tokenize(buf, words, N_WORDS);
  3610. if (n_words != N_WORDS) {
  3611. DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
  3612. N_WORDS);
  3613. return -EINVAL;
  3614. }
  3615. if (display_crc_ctl_parse_object(words[0], &object) < 0) {
  3616. DRM_DEBUG_DRIVER("unknown object %s\n", words[0]);
  3617. return -EINVAL;
  3618. }
  3619. if (display_crc_ctl_parse_pipe(words[1], &pipe) < 0) {
  3620. DRM_DEBUG_DRIVER("unknown pipe %s\n", words[1]);
  3621. return -EINVAL;
  3622. }
  3623. if (display_crc_ctl_parse_source(words[2], &source) < 0) {
  3624. DRM_DEBUG_DRIVER("unknown source %s\n", words[2]);
  3625. return -EINVAL;
  3626. }
  3627. return pipe_crc_set_source(dev_priv, pipe, source);
  3628. }
  3629. static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf,
  3630. size_t len, loff_t *offp)
  3631. {
  3632. struct seq_file *m = file->private_data;
  3633. struct drm_i915_private *dev_priv = m->private;
  3634. char *tmpbuf;
  3635. int ret;
  3636. if (len == 0)
  3637. return 0;
  3638. if (len > PAGE_SIZE - 1) {
  3639. DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
  3640. PAGE_SIZE);
  3641. return -E2BIG;
  3642. }
  3643. tmpbuf = kmalloc(len + 1, GFP_KERNEL);
  3644. if (!tmpbuf)
  3645. return -ENOMEM;
  3646. if (copy_from_user(tmpbuf, ubuf, len)) {
  3647. ret = -EFAULT;
  3648. goto out;
  3649. }
  3650. tmpbuf[len] = '\0';
  3651. ret = display_crc_ctl_parse(dev_priv, tmpbuf, len);
  3652. out:
  3653. kfree(tmpbuf);
  3654. if (ret < 0)
  3655. return ret;
  3656. *offp += len;
  3657. return len;
  3658. }
  3659. static const struct file_operations i915_display_crc_ctl_fops = {
  3660. .owner = THIS_MODULE,
  3661. .open = display_crc_ctl_open,
  3662. .read = seq_read,
  3663. .llseek = seq_lseek,
  3664. .release = single_release,
  3665. .write = display_crc_ctl_write
  3666. };
  3667. static ssize_t i915_displayport_test_active_write(struct file *file,
  3668. const char __user *ubuf,
  3669. size_t len, loff_t *offp)
  3670. {
  3671. char *input_buffer;
  3672. int status = 0;
  3673. struct drm_device *dev;
  3674. struct drm_connector *connector;
  3675. struct list_head *connector_list;
  3676. struct intel_dp *intel_dp;
  3677. int val = 0;
  3678. dev = ((struct seq_file *)file->private_data)->private;
  3679. connector_list = &dev->mode_config.connector_list;
  3680. if (len == 0)
  3681. return 0;
  3682. input_buffer = kmalloc(len + 1, GFP_KERNEL);
  3683. if (!input_buffer)
  3684. return -ENOMEM;
  3685. if (copy_from_user(input_buffer, ubuf, len)) {
  3686. status = -EFAULT;
  3687. goto out;
  3688. }
  3689. input_buffer[len] = '\0';
  3690. DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
  3691. list_for_each_entry(connector, connector_list, head) {
  3692. if (connector->connector_type !=
  3693. DRM_MODE_CONNECTOR_DisplayPort)
  3694. continue;
  3695. if (connector->status == connector_status_connected &&
  3696. connector->encoder != NULL) {
  3697. intel_dp = enc_to_intel_dp(connector->encoder);
  3698. status = kstrtoint(input_buffer, 10, &val);
  3699. if (status < 0)
  3700. goto out;
  3701. DRM_DEBUG_DRIVER("Got %d for test active\n", val);
  3702. /* To prevent erroneous activation of the compliance
  3703. * testing code, only accept an actual value of 1 here
  3704. */
  3705. if (val == 1)
  3706. intel_dp->compliance_test_active = 1;
  3707. else
  3708. intel_dp->compliance_test_active = 0;
  3709. }
  3710. }
  3711. out:
  3712. kfree(input_buffer);
  3713. if (status < 0)
  3714. return status;
  3715. *offp += len;
  3716. return len;
  3717. }
  3718. static int i915_displayport_test_active_show(struct seq_file *m, void *data)
  3719. {
  3720. struct drm_device *dev = m->private;
  3721. struct drm_connector *connector;
  3722. struct list_head *connector_list = &dev->mode_config.connector_list;
  3723. struct intel_dp *intel_dp;
  3724. list_for_each_entry(connector, connector_list, head) {
  3725. if (connector->connector_type !=
  3726. DRM_MODE_CONNECTOR_DisplayPort)
  3727. continue;
  3728. if (connector->status == connector_status_connected &&
  3729. connector->encoder != NULL) {
  3730. intel_dp = enc_to_intel_dp(connector->encoder);
  3731. if (intel_dp->compliance_test_active)
  3732. seq_puts(m, "1");
  3733. else
  3734. seq_puts(m, "0");
  3735. } else
  3736. seq_puts(m, "0");
  3737. }
  3738. return 0;
  3739. }
  3740. static int i915_displayport_test_active_open(struct inode *inode,
  3741. struct file *file)
  3742. {
  3743. struct drm_i915_private *dev_priv = inode->i_private;
  3744. return single_open(file, i915_displayport_test_active_show,
  3745. &dev_priv->drm);
  3746. }
  3747. static const struct file_operations i915_displayport_test_active_fops = {
  3748. .owner = THIS_MODULE,
  3749. .open = i915_displayport_test_active_open,
  3750. .read = seq_read,
  3751. .llseek = seq_lseek,
  3752. .release = single_release,
  3753. .write = i915_displayport_test_active_write
  3754. };
  3755. static int i915_displayport_test_data_show(struct seq_file *m, void *data)
  3756. {
  3757. struct drm_device *dev = m->private;
  3758. struct drm_connector *connector;
  3759. struct list_head *connector_list = &dev->mode_config.connector_list;
  3760. struct intel_dp *intel_dp;
  3761. list_for_each_entry(connector, connector_list, head) {
  3762. if (connector->connector_type !=
  3763. DRM_MODE_CONNECTOR_DisplayPort)
  3764. continue;
  3765. if (connector->status == connector_status_connected &&
  3766. connector->encoder != NULL) {
  3767. intel_dp = enc_to_intel_dp(connector->encoder);
  3768. seq_printf(m, "%lx", intel_dp->compliance_test_data);
  3769. } else
  3770. seq_puts(m, "0");
  3771. }
  3772. return 0;
  3773. }
  3774. static int i915_displayport_test_data_open(struct inode *inode,
  3775. struct file *file)
  3776. {
  3777. struct drm_i915_private *dev_priv = inode->i_private;
  3778. return single_open(file, i915_displayport_test_data_show,
  3779. &dev_priv->drm);
  3780. }
  3781. static const struct file_operations i915_displayport_test_data_fops = {
  3782. .owner = THIS_MODULE,
  3783. .open = i915_displayport_test_data_open,
  3784. .read = seq_read,
  3785. .llseek = seq_lseek,
  3786. .release = single_release
  3787. };
  3788. static int i915_displayport_test_type_show(struct seq_file *m, void *data)
  3789. {
  3790. struct drm_device *dev = m->private;
  3791. struct drm_connector *connector;
  3792. struct list_head *connector_list = &dev->mode_config.connector_list;
  3793. struct intel_dp *intel_dp;
  3794. list_for_each_entry(connector, connector_list, head) {
  3795. if (connector->connector_type !=
  3796. DRM_MODE_CONNECTOR_DisplayPort)
  3797. continue;
  3798. if (connector->status == connector_status_connected &&
  3799. connector->encoder != NULL) {
  3800. intel_dp = enc_to_intel_dp(connector->encoder);
  3801. seq_printf(m, "%02lx", intel_dp->compliance_test_type);
  3802. } else
  3803. seq_puts(m, "0");
  3804. }
  3805. return 0;
  3806. }
  3807. static int i915_displayport_test_type_open(struct inode *inode,
  3808. struct file *file)
  3809. {
  3810. struct drm_i915_private *dev_priv = inode->i_private;
  3811. return single_open(file, i915_displayport_test_type_show,
  3812. &dev_priv->drm);
  3813. }
  3814. static const struct file_operations i915_displayport_test_type_fops = {
  3815. .owner = THIS_MODULE,
  3816. .open = i915_displayport_test_type_open,
  3817. .read = seq_read,
  3818. .llseek = seq_lseek,
  3819. .release = single_release
  3820. };
  3821. static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
  3822. {
  3823. struct drm_i915_private *dev_priv = m->private;
  3824. struct drm_device *dev = &dev_priv->drm;
  3825. int level;
  3826. int num_levels;
  3827. if (IS_CHERRYVIEW(dev_priv))
  3828. num_levels = 3;
  3829. else if (IS_VALLEYVIEW(dev_priv))
  3830. num_levels = 1;
  3831. else
  3832. num_levels = ilk_wm_max_level(dev_priv) + 1;
  3833. drm_modeset_lock_all(dev);
  3834. for (level = 0; level < num_levels; level++) {
  3835. unsigned int latency = wm[level];
  3836. /*
  3837. * - WM1+ latency values in 0.5us units
  3838. * - latencies are in us on gen9/vlv/chv
  3839. */
  3840. if (INTEL_GEN(dev_priv) >= 9 || IS_VALLEYVIEW(dev_priv) ||
  3841. IS_CHERRYVIEW(dev_priv))
  3842. latency *= 10;
  3843. else if (level > 0)
  3844. latency *= 5;
  3845. seq_printf(m, "WM%d %u (%u.%u usec)\n",
  3846. level, wm[level], latency / 10, latency % 10);
  3847. }
  3848. drm_modeset_unlock_all(dev);
  3849. }
  3850. static int pri_wm_latency_show(struct seq_file *m, void *data)
  3851. {
  3852. struct drm_i915_private *dev_priv = m->private;
  3853. const uint16_t *latencies;
  3854. if (INTEL_GEN(dev_priv) >= 9)
  3855. latencies = dev_priv->wm.skl_latency;
  3856. else
  3857. latencies = dev_priv->wm.pri_latency;
  3858. wm_latency_show(m, latencies);
  3859. return 0;
  3860. }
  3861. static int spr_wm_latency_show(struct seq_file *m, void *data)
  3862. {
  3863. struct drm_i915_private *dev_priv = m->private;
  3864. const uint16_t *latencies;
  3865. if (INTEL_GEN(dev_priv) >= 9)
  3866. latencies = dev_priv->wm.skl_latency;
  3867. else
  3868. latencies = dev_priv->wm.spr_latency;
  3869. wm_latency_show(m, latencies);
  3870. return 0;
  3871. }
  3872. static int cur_wm_latency_show(struct seq_file *m, void *data)
  3873. {
  3874. struct drm_i915_private *dev_priv = m->private;
  3875. const uint16_t *latencies;
  3876. if (INTEL_GEN(dev_priv) >= 9)
  3877. latencies = dev_priv->wm.skl_latency;
  3878. else
  3879. latencies = dev_priv->wm.cur_latency;
  3880. wm_latency_show(m, latencies);
  3881. return 0;
  3882. }
  3883. static int pri_wm_latency_open(struct inode *inode, struct file *file)
  3884. {
  3885. struct drm_i915_private *dev_priv = inode->i_private;
  3886. if (INTEL_GEN(dev_priv) < 5)
  3887. return -ENODEV;
  3888. return single_open(file, pri_wm_latency_show, dev_priv);
  3889. }
  3890. static int spr_wm_latency_open(struct inode *inode, struct file *file)
  3891. {
  3892. struct drm_i915_private *dev_priv = inode->i_private;
  3893. if (HAS_GMCH_DISPLAY(dev_priv))
  3894. return -ENODEV;
  3895. return single_open(file, spr_wm_latency_show, dev_priv);
  3896. }
  3897. static int cur_wm_latency_open(struct inode *inode, struct file *file)
  3898. {
  3899. struct drm_i915_private *dev_priv = inode->i_private;
  3900. if (HAS_GMCH_DISPLAY(dev_priv))
  3901. return -ENODEV;
  3902. return single_open(file, cur_wm_latency_show, dev_priv);
  3903. }
  3904. static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
  3905. size_t len, loff_t *offp, uint16_t wm[8])
  3906. {
  3907. struct seq_file *m = file->private_data;
  3908. struct drm_i915_private *dev_priv = m->private;
  3909. struct drm_device *dev = &dev_priv->drm;
  3910. uint16_t new[8] = { 0 };
  3911. int num_levels;
  3912. int level;
  3913. int ret;
  3914. char tmp[32];
  3915. if (IS_CHERRYVIEW(dev_priv))
  3916. num_levels = 3;
  3917. else if (IS_VALLEYVIEW(dev_priv))
  3918. num_levels = 1;
  3919. else
  3920. num_levels = ilk_wm_max_level(dev_priv) + 1;
  3921. if (len >= sizeof(tmp))
  3922. return -EINVAL;
  3923. if (copy_from_user(tmp, ubuf, len))
  3924. return -EFAULT;
  3925. tmp[len] = '\0';
  3926. ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
  3927. &new[0], &new[1], &new[2], &new[3],
  3928. &new[4], &new[5], &new[6], &new[7]);
  3929. if (ret != num_levels)
  3930. return -EINVAL;
  3931. drm_modeset_lock_all(dev);
  3932. for (level = 0; level < num_levels; level++)
  3933. wm[level] = new[level];
  3934. drm_modeset_unlock_all(dev);
  3935. return len;
  3936. }
  3937. static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
  3938. size_t len, loff_t *offp)
  3939. {
  3940. struct seq_file *m = file->private_data;
  3941. struct drm_i915_private *dev_priv = m->private;
  3942. uint16_t *latencies;
  3943. if (INTEL_GEN(dev_priv) >= 9)
  3944. latencies = dev_priv->wm.skl_latency;
  3945. else
  3946. latencies = dev_priv->wm.pri_latency;
  3947. return wm_latency_write(file, ubuf, len, offp, latencies);
  3948. }
  3949. static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
  3950. size_t len, loff_t *offp)
  3951. {
  3952. struct seq_file *m = file->private_data;
  3953. struct drm_i915_private *dev_priv = m->private;
  3954. uint16_t *latencies;
  3955. if (INTEL_GEN(dev_priv) >= 9)
  3956. latencies = dev_priv->wm.skl_latency;
  3957. else
  3958. latencies = dev_priv->wm.spr_latency;
  3959. return wm_latency_write(file, ubuf, len, offp, latencies);
  3960. }
  3961. static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
  3962. size_t len, loff_t *offp)
  3963. {
  3964. struct seq_file *m = file->private_data;
  3965. struct drm_i915_private *dev_priv = m->private;
  3966. uint16_t *latencies;
  3967. if (INTEL_GEN(dev_priv) >= 9)
  3968. latencies = dev_priv->wm.skl_latency;
  3969. else
  3970. latencies = dev_priv->wm.cur_latency;
  3971. return wm_latency_write(file, ubuf, len, offp, latencies);
  3972. }
  3973. static const struct file_operations i915_pri_wm_latency_fops = {
  3974. .owner = THIS_MODULE,
  3975. .open = pri_wm_latency_open,
  3976. .read = seq_read,
  3977. .llseek = seq_lseek,
  3978. .release = single_release,
  3979. .write = pri_wm_latency_write
  3980. };
  3981. static const struct file_operations i915_spr_wm_latency_fops = {
  3982. .owner = THIS_MODULE,
  3983. .open = spr_wm_latency_open,
  3984. .read = seq_read,
  3985. .llseek = seq_lseek,
  3986. .release = single_release,
  3987. .write = spr_wm_latency_write
  3988. };
  3989. static const struct file_operations i915_cur_wm_latency_fops = {
  3990. .owner = THIS_MODULE,
  3991. .open = cur_wm_latency_open,
  3992. .read = seq_read,
  3993. .llseek = seq_lseek,
  3994. .release = single_release,
  3995. .write = cur_wm_latency_write
  3996. };
  3997. static int
  3998. i915_wedged_get(void *data, u64 *val)
  3999. {
  4000. struct drm_i915_private *dev_priv = data;
  4001. *val = i915_terminally_wedged(&dev_priv->gpu_error);
  4002. return 0;
  4003. }
  4004. static int
  4005. i915_wedged_set(void *data, u64 val)
  4006. {
  4007. struct drm_i915_private *dev_priv = data;
  4008. /*
  4009. * There is no safeguard against this debugfs entry colliding
  4010. * with the hangcheck calling same i915_handle_error() in
  4011. * parallel, causing an explosion. For now we assume that the
  4012. * test harness is responsible enough not to inject gpu hangs
  4013. * while it is writing to 'i915_wedged'
  4014. */
  4015. if (i915_reset_in_progress(&dev_priv->gpu_error))
  4016. return -EAGAIN;
  4017. i915_handle_error(dev_priv, val,
  4018. "Manually setting wedged to %llu", val);
  4019. return 0;
  4020. }
  4021. DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
  4022. i915_wedged_get, i915_wedged_set,
  4023. "%llu\n");
  4024. static int
  4025. i915_ring_missed_irq_get(void *data, u64 *val)
  4026. {
  4027. struct drm_i915_private *dev_priv = data;
  4028. *val = dev_priv->gpu_error.missed_irq_rings;
  4029. return 0;
  4030. }
  4031. static int
  4032. i915_ring_missed_irq_set(void *data, u64 val)
  4033. {
  4034. struct drm_i915_private *dev_priv = data;
  4035. struct drm_device *dev = &dev_priv->drm;
  4036. int ret;
  4037. /* Lock against concurrent debugfs callers */
  4038. ret = mutex_lock_interruptible(&dev->struct_mutex);
  4039. if (ret)
  4040. return ret;
  4041. dev_priv->gpu_error.missed_irq_rings = val;
  4042. mutex_unlock(&dev->struct_mutex);
  4043. return 0;
  4044. }
  4045. DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
  4046. i915_ring_missed_irq_get, i915_ring_missed_irq_set,
  4047. "0x%08llx\n");
  4048. static int
  4049. i915_ring_test_irq_get(void *data, u64 *val)
  4050. {
  4051. struct drm_i915_private *dev_priv = data;
  4052. *val = dev_priv->gpu_error.test_irq_rings;
  4053. return 0;
  4054. }
  4055. static int
  4056. i915_ring_test_irq_set(void *data, u64 val)
  4057. {
  4058. struct drm_i915_private *dev_priv = data;
  4059. val &= INTEL_INFO(dev_priv)->ring_mask;
  4060. DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
  4061. dev_priv->gpu_error.test_irq_rings = val;
  4062. return 0;
  4063. }
  4064. DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
  4065. i915_ring_test_irq_get, i915_ring_test_irq_set,
  4066. "0x%08llx\n");
  4067. #define DROP_UNBOUND 0x1
  4068. #define DROP_BOUND 0x2
  4069. #define DROP_RETIRE 0x4
  4070. #define DROP_ACTIVE 0x8
  4071. #define DROP_FREED 0x10
  4072. #define DROP_ALL (DROP_UNBOUND | \
  4073. DROP_BOUND | \
  4074. DROP_RETIRE | \
  4075. DROP_ACTIVE | \
  4076. DROP_FREED)
  4077. static int
  4078. i915_drop_caches_get(void *data, u64 *val)
  4079. {
  4080. *val = DROP_ALL;
  4081. return 0;
  4082. }
  4083. static int
  4084. i915_drop_caches_set(void *data, u64 val)
  4085. {
  4086. struct drm_i915_private *dev_priv = data;
  4087. struct drm_device *dev = &dev_priv->drm;
  4088. int ret;
  4089. DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
  4090. /* No need to check and wait for gpu resets, only libdrm auto-restarts
  4091. * on ioctls on -EAGAIN. */
  4092. ret = mutex_lock_interruptible(&dev->struct_mutex);
  4093. if (ret)
  4094. return ret;
  4095. if (val & DROP_ACTIVE) {
  4096. ret = i915_gem_wait_for_idle(dev_priv,
  4097. I915_WAIT_INTERRUPTIBLE |
  4098. I915_WAIT_LOCKED);
  4099. if (ret)
  4100. goto unlock;
  4101. }
  4102. if (val & (DROP_RETIRE | DROP_ACTIVE))
  4103. i915_gem_retire_requests(dev_priv);
  4104. if (val & DROP_BOUND)
  4105. i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_BOUND);
  4106. if (val & DROP_UNBOUND)
  4107. i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_UNBOUND);
  4108. unlock:
  4109. mutex_unlock(&dev->struct_mutex);
  4110. if (val & DROP_FREED) {
  4111. synchronize_rcu();
  4112. flush_work(&dev_priv->mm.free_work);
  4113. }
  4114. return ret;
  4115. }
  4116. DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
  4117. i915_drop_caches_get, i915_drop_caches_set,
  4118. "0x%08llx\n");
  4119. static int
  4120. i915_max_freq_get(void *data, u64 *val)
  4121. {
  4122. struct drm_i915_private *dev_priv = data;
  4123. if (INTEL_GEN(dev_priv) < 6)
  4124. return -ENODEV;
  4125. *val = intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
  4126. return 0;
  4127. }
  4128. static int
  4129. i915_max_freq_set(void *data, u64 val)
  4130. {
  4131. struct drm_i915_private *dev_priv = data;
  4132. u32 hw_max, hw_min;
  4133. int ret;
  4134. if (INTEL_GEN(dev_priv) < 6)
  4135. return -ENODEV;
  4136. DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
  4137. ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
  4138. if (ret)
  4139. return ret;
  4140. /*
  4141. * Turbo will still be enabled, but won't go above the set value.
  4142. */
  4143. val = intel_freq_opcode(dev_priv, val);
  4144. hw_max = dev_priv->rps.max_freq;
  4145. hw_min = dev_priv->rps.min_freq;
  4146. if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
  4147. mutex_unlock(&dev_priv->rps.hw_lock);
  4148. return -EINVAL;
  4149. }
  4150. dev_priv->rps.max_freq_softlimit = val;
  4151. intel_set_rps(dev_priv, val);
  4152. mutex_unlock(&dev_priv->rps.hw_lock);
  4153. return 0;
  4154. }
  4155. DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
  4156. i915_max_freq_get, i915_max_freq_set,
  4157. "%llu\n");
  4158. static int
  4159. i915_min_freq_get(void *data, u64 *val)
  4160. {
  4161. struct drm_i915_private *dev_priv = data;
  4162. if (INTEL_GEN(dev_priv) < 6)
  4163. return -ENODEV;
  4164. *val = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
  4165. return 0;
  4166. }
  4167. static int
  4168. i915_min_freq_set(void *data, u64 val)
  4169. {
  4170. struct drm_i915_private *dev_priv = data;
  4171. u32 hw_max, hw_min;
  4172. int ret;
  4173. if (INTEL_GEN(dev_priv) < 6)
  4174. return -ENODEV;
  4175. DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
  4176. ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
  4177. if (ret)
  4178. return ret;
  4179. /*
  4180. * Turbo will still be enabled, but won't go below the set value.
  4181. */
  4182. val = intel_freq_opcode(dev_priv, val);
  4183. hw_max = dev_priv->rps.max_freq;
  4184. hw_min = dev_priv->rps.min_freq;
  4185. if (val < hw_min ||
  4186. val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
  4187. mutex_unlock(&dev_priv->rps.hw_lock);
  4188. return -EINVAL;
  4189. }
  4190. dev_priv->rps.min_freq_softlimit = val;
  4191. intel_set_rps(dev_priv, val);
  4192. mutex_unlock(&dev_priv->rps.hw_lock);
  4193. return 0;
  4194. }
  4195. DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
  4196. i915_min_freq_get, i915_min_freq_set,
  4197. "%llu\n");
  4198. static int
  4199. i915_cache_sharing_get(void *data, u64 *val)
  4200. {
  4201. struct drm_i915_private *dev_priv = data;
  4202. u32 snpcr;
  4203. if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
  4204. return -ENODEV;
  4205. intel_runtime_pm_get(dev_priv);
  4206. snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
  4207. intel_runtime_pm_put(dev_priv);
  4208. *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
  4209. return 0;
  4210. }
  4211. static int
  4212. i915_cache_sharing_set(void *data, u64 val)
  4213. {
  4214. struct drm_i915_private *dev_priv = data;
  4215. u32 snpcr;
  4216. if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
  4217. return -ENODEV;
  4218. if (val > 3)
  4219. return -EINVAL;
  4220. intel_runtime_pm_get(dev_priv);
  4221. DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
  4222. /* Update the cache sharing policy here as well */
  4223. snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
  4224. snpcr &= ~GEN6_MBC_SNPCR_MASK;
  4225. snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
  4226. I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
  4227. intel_runtime_pm_put(dev_priv);
  4228. return 0;
  4229. }
  4230. DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
  4231. i915_cache_sharing_get, i915_cache_sharing_set,
  4232. "%llu\n");
  4233. static void cherryview_sseu_device_status(struct drm_i915_private *dev_priv,
  4234. struct sseu_dev_info *sseu)
  4235. {
  4236. int ss_max = 2;
  4237. int ss;
  4238. u32 sig1[ss_max], sig2[ss_max];
  4239. sig1[0] = I915_READ(CHV_POWER_SS0_SIG1);
  4240. sig1[1] = I915_READ(CHV_POWER_SS1_SIG1);
  4241. sig2[0] = I915_READ(CHV_POWER_SS0_SIG2);
  4242. sig2[1] = I915_READ(CHV_POWER_SS1_SIG2);
  4243. for (ss = 0; ss < ss_max; ss++) {
  4244. unsigned int eu_cnt;
  4245. if (sig1[ss] & CHV_SS_PG_ENABLE)
  4246. /* skip disabled subslice */
  4247. continue;
  4248. sseu->slice_mask = BIT(0);
  4249. sseu->subslice_mask |= BIT(ss);
  4250. eu_cnt = ((sig1[ss] & CHV_EU08_PG_ENABLE) ? 0 : 2) +
  4251. ((sig1[ss] & CHV_EU19_PG_ENABLE) ? 0 : 2) +
  4252. ((sig1[ss] & CHV_EU210_PG_ENABLE) ? 0 : 2) +
  4253. ((sig2[ss] & CHV_EU311_PG_ENABLE) ? 0 : 2);
  4254. sseu->eu_total += eu_cnt;
  4255. sseu->eu_per_subslice = max_t(unsigned int,
  4256. sseu->eu_per_subslice, eu_cnt);
  4257. }
  4258. }
  4259. static void gen9_sseu_device_status(struct drm_i915_private *dev_priv,
  4260. struct sseu_dev_info *sseu)
  4261. {
  4262. int s_max = 3, ss_max = 4;
  4263. int s, ss;
  4264. u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
  4265. /* BXT has a single slice and at most 3 subslices. */
  4266. if (IS_BROXTON(dev_priv)) {
  4267. s_max = 1;
  4268. ss_max = 3;
  4269. }
  4270. for (s = 0; s < s_max; s++) {
  4271. s_reg[s] = I915_READ(GEN9_SLICE_PGCTL_ACK(s));
  4272. eu_reg[2*s] = I915_READ(GEN9_SS01_EU_PGCTL_ACK(s));
  4273. eu_reg[2*s + 1] = I915_READ(GEN9_SS23_EU_PGCTL_ACK(s));
  4274. }
  4275. eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
  4276. GEN9_PGCTL_SSA_EU19_ACK |
  4277. GEN9_PGCTL_SSA_EU210_ACK |
  4278. GEN9_PGCTL_SSA_EU311_ACK;
  4279. eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
  4280. GEN9_PGCTL_SSB_EU19_ACK |
  4281. GEN9_PGCTL_SSB_EU210_ACK |
  4282. GEN9_PGCTL_SSB_EU311_ACK;
  4283. for (s = 0; s < s_max; s++) {
  4284. if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
  4285. /* skip disabled slice */
  4286. continue;
  4287. sseu->slice_mask |= BIT(s);
  4288. if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))
  4289. sseu->subslice_mask =
  4290. INTEL_INFO(dev_priv)->sseu.subslice_mask;
  4291. for (ss = 0; ss < ss_max; ss++) {
  4292. unsigned int eu_cnt;
  4293. if (IS_BROXTON(dev_priv)) {
  4294. if (!(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
  4295. /* skip disabled subslice */
  4296. continue;
  4297. sseu->subslice_mask |= BIT(ss);
  4298. }
  4299. eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
  4300. eu_mask[ss%2]);
  4301. sseu->eu_total += eu_cnt;
  4302. sseu->eu_per_subslice = max_t(unsigned int,
  4303. sseu->eu_per_subslice,
  4304. eu_cnt);
  4305. }
  4306. }
  4307. }
  4308. static void broadwell_sseu_device_status(struct drm_i915_private *dev_priv,
  4309. struct sseu_dev_info *sseu)
  4310. {
  4311. u32 slice_info = I915_READ(GEN8_GT_SLICE_INFO);
  4312. int s;
  4313. sseu->slice_mask = slice_info & GEN8_LSLICESTAT_MASK;
  4314. if (sseu->slice_mask) {
  4315. sseu->subslice_mask = INTEL_INFO(dev_priv)->sseu.subslice_mask;
  4316. sseu->eu_per_subslice =
  4317. INTEL_INFO(dev_priv)->sseu.eu_per_subslice;
  4318. sseu->eu_total = sseu->eu_per_subslice *
  4319. sseu_subslice_total(sseu);
  4320. /* subtract fused off EU(s) from enabled slice(s) */
  4321. for (s = 0; s < fls(sseu->slice_mask); s++) {
  4322. u8 subslice_7eu =
  4323. INTEL_INFO(dev_priv)->sseu.subslice_7eu[s];
  4324. sseu->eu_total -= hweight8(subslice_7eu);
  4325. }
  4326. }
  4327. }
  4328. static void i915_print_sseu_info(struct seq_file *m, bool is_available_info,
  4329. const struct sseu_dev_info *sseu)
  4330. {
  4331. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  4332. const char *type = is_available_info ? "Available" : "Enabled";
  4333. seq_printf(m, " %s Slice Mask: %04x\n", type,
  4334. sseu->slice_mask);
  4335. seq_printf(m, " %s Slice Total: %u\n", type,
  4336. hweight8(sseu->slice_mask));
  4337. seq_printf(m, " %s Subslice Total: %u\n", type,
  4338. sseu_subslice_total(sseu));
  4339. seq_printf(m, " %s Subslice Mask: %04x\n", type,
  4340. sseu->subslice_mask);
  4341. seq_printf(m, " %s Subslice Per Slice: %u\n", type,
  4342. hweight8(sseu->subslice_mask));
  4343. seq_printf(m, " %s EU Total: %u\n", type,
  4344. sseu->eu_total);
  4345. seq_printf(m, " %s EU Per Subslice: %u\n", type,
  4346. sseu->eu_per_subslice);
  4347. if (!is_available_info)
  4348. return;
  4349. seq_printf(m, " Has Pooled EU: %s\n", yesno(HAS_POOLED_EU(dev_priv)));
  4350. if (HAS_POOLED_EU(dev_priv))
  4351. seq_printf(m, " Min EU in pool: %u\n", sseu->min_eu_in_pool);
  4352. seq_printf(m, " Has Slice Power Gating: %s\n",
  4353. yesno(sseu->has_slice_pg));
  4354. seq_printf(m, " Has Subslice Power Gating: %s\n",
  4355. yesno(sseu->has_subslice_pg));
  4356. seq_printf(m, " Has EU Power Gating: %s\n",
  4357. yesno(sseu->has_eu_pg));
  4358. }
  4359. static int i915_sseu_status(struct seq_file *m, void *unused)
  4360. {
  4361. struct drm_i915_private *dev_priv = node_to_i915(m->private);
  4362. struct sseu_dev_info sseu;
  4363. if (INTEL_GEN(dev_priv) < 8)
  4364. return -ENODEV;
  4365. seq_puts(m, "SSEU Device Info\n");
  4366. i915_print_sseu_info(m, true, &INTEL_INFO(dev_priv)->sseu);
  4367. seq_puts(m, "SSEU Device Status\n");
  4368. memset(&sseu, 0, sizeof(sseu));
  4369. intel_runtime_pm_get(dev_priv);
  4370. if (IS_CHERRYVIEW(dev_priv)) {
  4371. cherryview_sseu_device_status(dev_priv, &sseu);
  4372. } else if (IS_BROADWELL(dev_priv)) {
  4373. broadwell_sseu_device_status(dev_priv, &sseu);
  4374. } else if (INTEL_GEN(dev_priv) >= 9) {
  4375. gen9_sseu_device_status(dev_priv, &sseu);
  4376. }
  4377. intel_runtime_pm_put(dev_priv);
  4378. i915_print_sseu_info(m, false, &sseu);
  4379. return 0;
  4380. }
  4381. static int i915_forcewake_open(struct inode *inode, struct file *file)
  4382. {
  4383. struct drm_i915_private *dev_priv = inode->i_private;
  4384. if (INTEL_GEN(dev_priv) < 6)
  4385. return 0;
  4386. intel_runtime_pm_get(dev_priv);
  4387. intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
  4388. return 0;
  4389. }
  4390. static int i915_forcewake_release(struct inode *inode, struct file *file)
  4391. {
  4392. struct drm_i915_private *dev_priv = inode->i_private;
  4393. if (INTEL_GEN(dev_priv) < 6)
  4394. return 0;
  4395. intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
  4396. intel_runtime_pm_put(dev_priv);
  4397. return 0;
  4398. }
  4399. static const struct file_operations i915_forcewake_fops = {
  4400. .owner = THIS_MODULE,
  4401. .open = i915_forcewake_open,
  4402. .release = i915_forcewake_release,
  4403. };
  4404. static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
  4405. {
  4406. struct dentry *ent;
  4407. ent = debugfs_create_file("i915_forcewake_user",
  4408. S_IRUSR,
  4409. root, to_i915(minor->dev),
  4410. &i915_forcewake_fops);
  4411. if (!ent)
  4412. return -ENOMEM;
  4413. return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
  4414. }
  4415. static int i915_debugfs_create(struct dentry *root,
  4416. struct drm_minor *minor,
  4417. const char *name,
  4418. const struct file_operations *fops)
  4419. {
  4420. struct dentry *ent;
  4421. ent = debugfs_create_file(name,
  4422. S_IRUGO | S_IWUSR,
  4423. root, to_i915(minor->dev),
  4424. fops);
  4425. if (!ent)
  4426. return -ENOMEM;
  4427. return drm_add_fake_info_node(minor, ent, fops);
  4428. }
  4429. static const struct drm_info_list i915_debugfs_list[] = {
  4430. {"i915_capabilities", i915_capabilities, 0},
  4431. {"i915_gem_objects", i915_gem_object_info, 0},
  4432. {"i915_gem_gtt", i915_gem_gtt_info, 0},
  4433. {"i915_gem_pin_display", i915_gem_gtt_info, 0, (void *)1},
  4434. {"i915_gem_stolen", i915_gem_stolen_list_info },
  4435. {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
  4436. {"i915_gem_request", i915_gem_request_info, 0},
  4437. {"i915_gem_seqno", i915_gem_seqno_info, 0},
  4438. {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
  4439. {"i915_gem_interrupt", i915_interrupt_info, 0},
  4440. {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
  4441. {"i915_guc_info", i915_guc_info, 0},
  4442. {"i915_guc_load_status", i915_guc_load_status_info, 0},
  4443. {"i915_guc_log_dump", i915_guc_log_dump, 0},
  4444. {"i915_frequency_info", i915_frequency_info, 0},
  4445. {"i915_hangcheck_info", i915_hangcheck_info, 0},
  4446. {"i915_drpc_info", i915_drpc_info, 0},
  4447. {"i915_emon_status", i915_emon_status, 0},
  4448. {"i915_ring_freq_table", i915_ring_freq_table, 0},
  4449. {"i915_frontbuffer_tracking", i915_frontbuffer_tracking, 0},
  4450. {"i915_fbc_status", i915_fbc_status, 0},
  4451. {"i915_ips_status", i915_ips_status, 0},
  4452. {"i915_sr_status", i915_sr_status, 0},
  4453. {"i915_opregion", i915_opregion, 0},
  4454. {"i915_vbt", i915_vbt, 0},
  4455. {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
  4456. {"i915_context_status", i915_context_status, 0},
  4457. {"i915_dump_lrc", i915_dump_lrc, 0},
  4458. {"i915_forcewake_domains", i915_forcewake_domains, 0},
  4459. {"i915_swizzle_info", i915_swizzle_info, 0},
  4460. {"i915_ppgtt_info", i915_ppgtt_info, 0},
  4461. {"i915_llc", i915_llc, 0},
  4462. {"i915_edp_psr_status", i915_edp_psr_status, 0},
  4463. {"i915_sink_crc_eDP1", i915_sink_crc, 0},
  4464. {"i915_energy_uJ", i915_energy_uJ, 0},
  4465. {"i915_runtime_pm_status", i915_runtime_pm_status, 0},
  4466. {"i915_power_domain_info", i915_power_domain_info, 0},
  4467. {"i915_dmc_info", i915_dmc_info, 0},
  4468. {"i915_display_info", i915_display_info, 0},
  4469. {"i915_engine_info", i915_engine_info, 0},
  4470. {"i915_semaphore_status", i915_semaphore_status, 0},
  4471. {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
  4472. {"i915_dp_mst_info", i915_dp_mst_info, 0},
  4473. {"i915_wa_registers", i915_wa_registers, 0},
  4474. {"i915_ddb_info", i915_ddb_info, 0},
  4475. {"i915_sseu_status", i915_sseu_status, 0},
  4476. {"i915_drrs_status", i915_drrs_status, 0},
  4477. {"i915_rps_boost_info", i915_rps_boost_info, 0},
  4478. };
  4479. #define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
  4480. static const struct i915_debugfs_files {
  4481. const char *name;
  4482. const struct file_operations *fops;
  4483. } i915_debugfs_files[] = {
  4484. {"i915_wedged", &i915_wedged_fops},
  4485. {"i915_max_freq", &i915_max_freq_fops},
  4486. {"i915_min_freq", &i915_min_freq_fops},
  4487. {"i915_cache_sharing", &i915_cache_sharing_fops},
  4488. {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
  4489. {"i915_ring_test_irq", &i915_ring_test_irq_fops},
  4490. {"i915_gem_drop_caches", &i915_drop_caches_fops},
  4491. #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
  4492. {"i915_error_state", &i915_error_state_fops},
  4493. #endif
  4494. {"i915_next_seqno", &i915_next_seqno_fops},
  4495. {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
  4496. {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
  4497. {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
  4498. {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
  4499. {"i915_fbc_false_color", &i915_fbc_fc_fops},
  4500. {"i915_dp_test_data", &i915_displayport_test_data_fops},
  4501. {"i915_dp_test_type", &i915_displayport_test_type_fops},
  4502. {"i915_dp_test_active", &i915_displayport_test_active_fops},
  4503. {"i915_guc_log_control", &i915_guc_log_control_fops}
  4504. };
  4505. void intel_display_crc_init(struct drm_i915_private *dev_priv)
  4506. {
  4507. enum pipe pipe;
  4508. for_each_pipe(dev_priv, pipe) {
  4509. struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
  4510. pipe_crc->opened = false;
  4511. spin_lock_init(&pipe_crc->lock);
  4512. init_waitqueue_head(&pipe_crc->wq);
  4513. }
  4514. }
  4515. int i915_debugfs_register(struct drm_i915_private *dev_priv)
  4516. {
  4517. struct drm_minor *minor = dev_priv->drm.primary;
  4518. int ret, i;
  4519. ret = i915_forcewake_create(minor->debugfs_root, minor);
  4520. if (ret)
  4521. return ret;
  4522. for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
  4523. ret = i915_pipe_crc_create(minor->debugfs_root, minor, i);
  4524. if (ret)
  4525. return ret;
  4526. }
  4527. for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
  4528. ret = i915_debugfs_create(minor->debugfs_root, minor,
  4529. i915_debugfs_files[i].name,
  4530. i915_debugfs_files[i].fops);
  4531. if (ret)
  4532. return ret;
  4533. }
  4534. return drm_debugfs_create_files(i915_debugfs_list,
  4535. I915_DEBUGFS_ENTRIES,
  4536. minor->debugfs_root, minor);
  4537. }
  4538. void i915_debugfs_unregister(struct drm_i915_private *dev_priv)
  4539. {
  4540. struct drm_minor *minor = dev_priv->drm.primary;
  4541. int i;
  4542. drm_debugfs_remove_files(i915_debugfs_list,
  4543. I915_DEBUGFS_ENTRIES, minor);
  4544. drm_debugfs_remove_files((struct drm_info_list *)&i915_forcewake_fops,
  4545. 1, minor);
  4546. for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
  4547. struct drm_info_list *info_list =
  4548. (struct drm_info_list *)&i915_pipe_crc_data[i];
  4549. drm_debugfs_remove_files(info_list, 1, minor);
  4550. }
  4551. for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
  4552. struct drm_info_list *info_list =
  4553. (struct drm_info_list *)i915_debugfs_files[i].fops;
  4554. drm_debugfs_remove_files(info_list, 1, minor);
  4555. }
  4556. }
  4557. struct dpcd_block {
  4558. /* DPCD dump start address. */
  4559. unsigned int offset;
  4560. /* DPCD dump end address, inclusive. If unset, .size will be used. */
  4561. unsigned int end;
  4562. /* DPCD dump size. Used if .end is unset. If unset, defaults to 1. */
  4563. size_t size;
  4564. /* Only valid for eDP. */
  4565. bool edp;
  4566. };
  4567. static const struct dpcd_block i915_dpcd_debug[] = {
  4568. { .offset = DP_DPCD_REV, .size = DP_RECEIVER_CAP_SIZE },
  4569. { .offset = DP_PSR_SUPPORT, .end = DP_PSR_CAPS },
  4570. { .offset = DP_DOWNSTREAM_PORT_0, .size = 16 },
  4571. { .offset = DP_LINK_BW_SET, .end = DP_EDP_CONFIGURATION_SET },
  4572. { .offset = DP_SINK_COUNT, .end = DP_ADJUST_REQUEST_LANE2_3 },
  4573. { .offset = DP_SET_POWER },
  4574. { .offset = DP_EDP_DPCD_REV },
  4575. { .offset = DP_EDP_GENERAL_CAP_1, .end = DP_EDP_GENERAL_CAP_3 },
  4576. { .offset = DP_EDP_DISPLAY_CONTROL_REGISTER, .end = DP_EDP_BACKLIGHT_FREQ_CAP_MAX_LSB },
  4577. { .offset = DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET, .end = DP_EDP_DBC_MAXIMUM_BRIGHTNESS_SET },
  4578. };
  4579. static int i915_dpcd_show(struct seq_file *m, void *data)
  4580. {
  4581. struct drm_connector *connector = m->private;
  4582. struct intel_dp *intel_dp =
  4583. enc_to_intel_dp(&intel_attached_encoder(connector)->base);
  4584. uint8_t buf[16];
  4585. ssize_t err;
  4586. int i;
  4587. if (connector->status != connector_status_connected)
  4588. return -ENODEV;
  4589. for (i = 0; i < ARRAY_SIZE(i915_dpcd_debug); i++) {
  4590. const struct dpcd_block *b = &i915_dpcd_debug[i];
  4591. size_t size = b->end ? b->end - b->offset + 1 : (b->size ?: 1);
  4592. if (b->edp &&
  4593. connector->connector_type != DRM_MODE_CONNECTOR_eDP)
  4594. continue;
  4595. /* low tech for now */
  4596. if (WARN_ON(size > sizeof(buf)))
  4597. continue;
  4598. err = drm_dp_dpcd_read(&intel_dp->aux, b->offset, buf, size);
  4599. if (err <= 0) {
  4600. DRM_ERROR("dpcd read (%zu bytes at %u) failed (%zd)\n",
  4601. size, b->offset, err);
  4602. continue;
  4603. }
  4604. seq_printf(m, "%04x: %*ph\n", b->offset, (int) size, buf);
  4605. }
  4606. return 0;
  4607. }
  4608. static int i915_dpcd_open(struct inode *inode, struct file *file)
  4609. {
  4610. return single_open(file, i915_dpcd_show, inode->i_private);
  4611. }
  4612. static const struct file_operations i915_dpcd_fops = {
  4613. .owner = THIS_MODULE,
  4614. .open = i915_dpcd_open,
  4615. .read = seq_read,
  4616. .llseek = seq_lseek,
  4617. .release = single_release,
  4618. };
  4619. static int i915_panel_show(struct seq_file *m, void *data)
  4620. {
  4621. struct drm_connector *connector = m->private;
  4622. struct intel_dp *intel_dp =
  4623. enc_to_intel_dp(&intel_attached_encoder(connector)->base);
  4624. if (connector->status != connector_status_connected)
  4625. return -ENODEV;
  4626. seq_printf(m, "Panel power up delay: %d\n",
  4627. intel_dp->panel_power_up_delay);
  4628. seq_printf(m, "Panel power down delay: %d\n",
  4629. intel_dp->panel_power_down_delay);
  4630. seq_printf(m, "Backlight on delay: %d\n",
  4631. intel_dp->backlight_on_delay);
  4632. seq_printf(m, "Backlight off delay: %d\n",
  4633. intel_dp->backlight_off_delay);
  4634. return 0;
  4635. }
  4636. static int i915_panel_open(struct inode *inode, struct file *file)
  4637. {
  4638. return single_open(file, i915_panel_show, inode->i_private);
  4639. }
  4640. static const struct file_operations i915_panel_fops = {
  4641. .owner = THIS_MODULE,
  4642. .open = i915_panel_open,
  4643. .read = seq_read,
  4644. .llseek = seq_lseek,
  4645. .release = single_release,
  4646. };
  4647. /**
  4648. * i915_debugfs_connector_add - add i915 specific connector debugfs files
  4649. * @connector: pointer to a registered drm_connector
  4650. *
  4651. * Cleanup will be done by drm_connector_unregister() through a call to
  4652. * drm_debugfs_connector_remove().
  4653. *
  4654. * Returns 0 on success, negative error codes on error.
  4655. */
  4656. int i915_debugfs_connector_add(struct drm_connector *connector)
  4657. {
  4658. struct dentry *root = connector->debugfs_entry;
  4659. /* The connector must have been registered beforehands. */
  4660. if (!root)
  4661. return -ENODEV;
  4662. if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
  4663. connector->connector_type == DRM_MODE_CONNECTOR_eDP)
  4664. debugfs_create_file("i915_dpcd", S_IRUGO, root,
  4665. connector, &i915_dpcd_fops);
  4666. if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
  4667. debugfs_create_file("i915_panel_timings", S_IRUGO, root,
  4668. connector, &i915_panel_fops);
  4669. return 0;
  4670. }