i915_debugfs.c 144 KB

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