i915_debugfs.c 147 KB

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