i915_irq.c 126 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531
  1. /* i915_irq.c -- IRQ support for the I915 -*- linux-c -*-
  2. */
  3. /*
  4. * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
  5. * All Rights Reserved.
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the
  9. * "Software"), to deal in the Software without restriction, including
  10. * without limitation the rights to use, copy, modify, merge, publish,
  11. * distribute, sub license, and/or sell copies of the Software, and to
  12. * permit persons to whom the Software is furnished to do so, subject to
  13. * the following conditions:
  14. *
  15. * The above copyright notice and this permission notice (including the
  16. * next paragraph) shall be included in all copies or substantial portions
  17. * of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  20. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  21. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  22. * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
  23. * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  24. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  25. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  26. *
  27. */
  28. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  29. #include <linux/sysrq.h>
  30. #include <linux/slab.h>
  31. #include <linux/circ_buf.h>
  32. #include <drm/drmP.h>
  33. #include <drm/i915_drm.h>
  34. #include "i915_drv.h"
  35. #include "i915_trace.h"
  36. #include "intel_drv.h"
  37. /**
  38. * DOC: interrupt handling
  39. *
  40. * These functions provide the basic support for enabling and disabling the
  41. * interrupt handling support. There's a lot more functionality in i915_irq.c
  42. * and related files, but that will be described in separate chapters.
  43. */
  44. static const u32 hpd_ilk[HPD_NUM_PINS] = {
  45. [HPD_PORT_A] = DE_DP_A_HOTPLUG,
  46. };
  47. static const u32 hpd_ivb[HPD_NUM_PINS] = {
  48. [HPD_PORT_A] = DE_DP_A_HOTPLUG_IVB,
  49. };
  50. static const u32 hpd_bdw[HPD_NUM_PINS] = {
  51. [HPD_PORT_A] = GEN8_PORT_DP_A_HOTPLUG,
  52. };
  53. static const u32 hpd_ibx[HPD_NUM_PINS] = {
  54. [HPD_CRT] = SDE_CRT_HOTPLUG,
  55. [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG,
  56. [HPD_PORT_B] = SDE_PORTB_HOTPLUG,
  57. [HPD_PORT_C] = SDE_PORTC_HOTPLUG,
  58. [HPD_PORT_D] = SDE_PORTD_HOTPLUG
  59. };
  60. static const u32 hpd_cpt[HPD_NUM_PINS] = {
  61. [HPD_CRT] = SDE_CRT_HOTPLUG_CPT,
  62. [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG_CPT,
  63. [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT,
  64. [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT,
  65. [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT
  66. };
  67. static const u32 hpd_spt[HPD_NUM_PINS] = {
  68. [HPD_PORT_A] = SDE_PORTA_HOTPLUG_SPT,
  69. [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT,
  70. [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT,
  71. [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT,
  72. [HPD_PORT_E] = SDE_PORTE_HOTPLUG_SPT
  73. };
  74. static const u32 hpd_mask_i915[HPD_NUM_PINS] = {
  75. [HPD_CRT] = CRT_HOTPLUG_INT_EN,
  76. [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_EN,
  77. [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_EN,
  78. [HPD_PORT_B] = PORTB_HOTPLUG_INT_EN,
  79. [HPD_PORT_C] = PORTC_HOTPLUG_INT_EN,
  80. [HPD_PORT_D] = PORTD_HOTPLUG_INT_EN
  81. };
  82. static const u32 hpd_status_g4x[HPD_NUM_PINS] = {
  83. [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
  84. [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_G4X,
  85. [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_G4X,
  86. [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
  87. [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
  88. [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
  89. };
  90. static const u32 hpd_status_i915[HPD_NUM_PINS] = {
  91. [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
  92. [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_I915,
  93. [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_I915,
  94. [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
  95. [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
  96. [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
  97. };
  98. /* BXT hpd list */
  99. static const u32 hpd_bxt[HPD_NUM_PINS] = {
  100. [HPD_PORT_A] = BXT_DE_PORT_HP_DDIA,
  101. [HPD_PORT_B] = BXT_DE_PORT_HP_DDIB,
  102. [HPD_PORT_C] = BXT_DE_PORT_HP_DDIC
  103. };
  104. /* IIR can theoretically queue up two events. Be paranoid. */
  105. #define GEN8_IRQ_RESET_NDX(type, which) do { \
  106. I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \
  107. POSTING_READ(GEN8_##type##_IMR(which)); \
  108. I915_WRITE(GEN8_##type##_IER(which), 0); \
  109. I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
  110. POSTING_READ(GEN8_##type##_IIR(which)); \
  111. I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
  112. POSTING_READ(GEN8_##type##_IIR(which)); \
  113. } while (0)
  114. #define GEN5_IRQ_RESET(type) do { \
  115. I915_WRITE(type##IMR, 0xffffffff); \
  116. POSTING_READ(type##IMR); \
  117. I915_WRITE(type##IER, 0); \
  118. I915_WRITE(type##IIR, 0xffffffff); \
  119. POSTING_READ(type##IIR); \
  120. I915_WRITE(type##IIR, 0xffffffff); \
  121. POSTING_READ(type##IIR); \
  122. } while (0)
  123. /*
  124. * We should clear IMR at preinstall/uninstall, and just check at postinstall.
  125. */
  126. static void gen5_assert_iir_is_zero(struct drm_i915_private *dev_priv, u32 reg)
  127. {
  128. u32 val = I915_READ(reg);
  129. if (val == 0)
  130. return;
  131. WARN(1, "Interrupt register 0x%x is not zero: 0x%08x\n",
  132. reg, val);
  133. I915_WRITE(reg, 0xffffffff);
  134. POSTING_READ(reg);
  135. I915_WRITE(reg, 0xffffffff);
  136. POSTING_READ(reg);
  137. }
  138. #define GEN8_IRQ_INIT_NDX(type, which, imr_val, ier_val) do { \
  139. gen5_assert_iir_is_zero(dev_priv, GEN8_##type##_IIR(which)); \
  140. I915_WRITE(GEN8_##type##_IER(which), (ier_val)); \
  141. I915_WRITE(GEN8_##type##_IMR(which), (imr_val)); \
  142. POSTING_READ(GEN8_##type##_IMR(which)); \
  143. } while (0)
  144. #define GEN5_IRQ_INIT(type, imr_val, ier_val) do { \
  145. gen5_assert_iir_is_zero(dev_priv, type##IIR); \
  146. I915_WRITE(type##IER, (ier_val)); \
  147. I915_WRITE(type##IMR, (imr_val)); \
  148. POSTING_READ(type##IMR); \
  149. } while (0)
  150. static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir);
  151. /* For display hotplug interrupt */
  152. static inline void
  153. i915_hotplug_interrupt_update_locked(struct drm_i915_private *dev_priv,
  154. uint32_t mask,
  155. uint32_t bits)
  156. {
  157. uint32_t val;
  158. assert_spin_locked(&dev_priv->irq_lock);
  159. WARN_ON(bits & ~mask);
  160. val = I915_READ(PORT_HOTPLUG_EN);
  161. val &= ~mask;
  162. val |= bits;
  163. I915_WRITE(PORT_HOTPLUG_EN, val);
  164. }
  165. /**
  166. * i915_hotplug_interrupt_update - update hotplug interrupt enable
  167. * @dev_priv: driver private
  168. * @mask: bits to update
  169. * @bits: bits to enable
  170. * NOTE: the HPD enable bits are modified both inside and outside
  171. * of an interrupt context. To avoid that read-modify-write cycles
  172. * interfer, these bits are protected by a spinlock. Since this
  173. * function is usually not called from a context where the lock is
  174. * held already, this function acquires the lock itself. A non-locking
  175. * version is also available.
  176. */
  177. void i915_hotplug_interrupt_update(struct drm_i915_private *dev_priv,
  178. uint32_t mask,
  179. uint32_t bits)
  180. {
  181. spin_lock_irq(&dev_priv->irq_lock);
  182. i915_hotplug_interrupt_update_locked(dev_priv, mask, bits);
  183. spin_unlock_irq(&dev_priv->irq_lock);
  184. }
  185. /**
  186. * ilk_update_display_irq - update DEIMR
  187. * @dev_priv: driver private
  188. * @interrupt_mask: mask of interrupt bits to update
  189. * @enabled_irq_mask: mask of interrupt bits to enable
  190. */
  191. static void ilk_update_display_irq(struct drm_i915_private *dev_priv,
  192. uint32_t interrupt_mask,
  193. uint32_t enabled_irq_mask)
  194. {
  195. uint32_t new_val;
  196. assert_spin_locked(&dev_priv->irq_lock);
  197. WARN_ON(enabled_irq_mask & ~interrupt_mask);
  198. if (WARN_ON(!intel_irqs_enabled(dev_priv)))
  199. return;
  200. new_val = dev_priv->irq_mask;
  201. new_val &= ~interrupt_mask;
  202. new_val |= (~enabled_irq_mask & interrupt_mask);
  203. if (new_val != dev_priv->irq_mask) {
  204. dev_priv->irq_mask = new_val;
  205. I915_WRITE(DEIMR, dev_priv->irq_mask);
  206. POSTING_READ(DEIMR);
  207. }
  208. }
  209. void
  210. ironlake_enable_display_irq(struct drm_i915_private *dev_priv, u32 mask)
  211. {
  212. ilk_update_display_irq(dev_priv, mask, mask);
  213. }
  214. void
  215. ironlake_disable_display_irq(struct drm_i915_private *dev_priv, u32 mask)
  216. {
  217. ilk_update_display_irq(dev_priv, mask, 0);
  218. }
  219. /**
  220. * ilk_update_gt_irq - update GTIMR
  221. * @dev_priv: driver private
  222. * @interrupt_mask: mask of interrupt bits to update
  223. * @enabled_irq_mask: mask of interrupt bits to enable
  224. */
  225. static void ilk_update_gt_irq(struct drm_i915_private *dev_priv,
  226. uint32_t interrupt_mask,
  227. uint32_t enabled_irq_mask)
  228. {
  229. assert_spin_locked(&dev_priv->irq_lock);
  230. WARN_ON(enabled_irq_mask & ~interrupt_mask);
  231. if (WARN_ON(!intel_irqs_enabled(dev_priv)))
  232. return;
  233. dev_priv->gt_irq_mask &= ~interrupt_mask;
  234. dev_priv->gt_irq_mask |= (~enabled_irq_mask & interrupt_mask);
  235. I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
  236. POSTING_READ(GTIMR);
  237. }
  238. void gen5_enable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
  239. {
  240. ilk_update_gt_irq(dev_priv, mask, mask);
  241. }
  242. void gen5_disable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
  243. {
  244. ilk_update_gt_irq(dev_priv, mask, 0);
  245. }
  246. static u32 gen6_pm_iir(struct drm_i915_private *dev_priv)
  247. {
  248. return INTEL_INFO(dev_priv)->gen >= 8 ? GEN8_GT_IIR(2) : GEN6_PMIIR;
  249. }
  250. static u32 gen6_pm_imr(struct drm_i915_private *dev_priv)
  251. {
  252. return INTEL_INFO(dev_priv)->gen >= 8 ? GEN8_GT_IMR(2) : GEN6_PMIMR;
  253. }
  254. static u32 gen6_pm_ier(struct drm_i915_private *dev_priv)
  255. {
  256. return INTEL_INFO(dev_priv)->gen >= 8 ? GEN8_GT_IER(2) : GEN6_PMIER;
  257. }
  258. /**
  259. * snb_update_pm_irq - update GEN6_PMIMR
  260. * @dev_priv: driver private
  261. * @interrupt_mask: mask of interrupt bits to update
  262. * @enabled_irq_mask: mask of interrupt bits to enable
  263. */
  264. static void snb_update_pm_irq(struct drm_i915_private *dev_priv,
  265. uint32_t interrupt_mask,
  266. uint32_t enabled_irq_mask)
  267. {
  268. uint32_t new_val;
  269. WARN_ON(enabled_irq_mask & ~interrupt_mask);
  270. assert_spin_locked(&dev_priv->irq_lock);
  271. new_val = dev_priv->pm_irq_mask;
  272. new_val &= ~interrupt_mask;
  273. new_val |= (~enabled_irq_mask & interrupt_mask);
  274. if (new_val != dev_priv->pm_irq_mask) {
  275. dev_priv->pm_irq_mask = new_val;
  276. I915_WRITE(gen6_pm_imr(dev_priv), dev_priv->pm_irq_mask);
  277. POSTING_READ(gen6_pm_imr(dev_priv));
  278. }
  279. }
  280. void gen6_enable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
  281. {
  282. if (WARN_ON(!intel_irqs_enabled(dev_priv)))
  283. return;
  284. snb_update_pm_irq(dev_priv, mask, mask);
  285. }
  286. static void __gen6_disable_pm_irq(struct drm_i915_private *dev_priv,
  287. uint32_t mask)
  288. {
  289. snb_update_pm_irq(dev_priv, mask, 0);
  290. }
  291. void gen6_disable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
  292. {
  293. if (WARN_ON(!intel_irqs_enabled(dev_priv)))
  294. return;
  295. __gen6_disable_pm_irq(dev_priv, mask);
  296. }
  297. void gen6_reset_rps_interrupts(struct drm_device *dev)
  298. {
  299. struct drm_i915_private *dev_priv = dev->dev_private;
  300. uint32_t reg = gen6_pm_iir(dev_priv);
  301. spin_lock_irq(&dev_priv->irq_lock);
  302. I915_WRITE(reg, dev_priv->pm_rps_events);
  303. I915_WRITE(reg, dev_priv->pm_rps_events);
  304. POSTING_READ(reg);
  305. dev_priv->rps.pm_iir = 0;
  306. spin_unlock_irq(&dev_priv->irq_lock);
  307. }
  308. void gen6_enable_rps_interrupts(struct drm_device *dev)
  309. {
  310. struct drm_i915_private *dev_priv = dev->dev_private;
  311. spin_lock_irq(&dev_priv->irq_lock);
  312. WARN_ON(dev_priv->rps.pm_iir);
  313. WARN_ON(I915_READ(gen6_pm_iir(dev_priv)) & dev_priv->pm_rps_events);
  314. dev_priv->rps.interrupts_enabled = true;
  315. I915_WRITE(gen6_pm_ier(dev_priv), I915_READ(gen6_pm_ier(dev_priv)) |
  316. dev_priv->pm_rps_events);
  317. gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
  318. spin_unlock_irq(&dev_priv->irq_lock);
  319. }
  320. u32 gen6_sanitize_rps_pm_mask(struct drm_i915_private *dev_priv, u32 mask)
  321. {
  322. /*
  323. * SNB,IVB can while VLV,CHV may hard hang on looping batchbuffer
  324. * if GEN6_PM_UP_EI_EXPIRED is masked.
  325. *
  326. * TODO: verify if this can be reproduced on VLV,CHV.
  327. */
  328. if (INTEL_INFO(dev_priv)->gen <= 7 && !IS_HASWELL(dev_priv))
  329. mask &= ~GEN6_PM_RP_UP_EI_EXPIRED;
  330. if (INTEL_INFO(dev_priv)->gen >= 8)
  331. mask &= ~GEN8_PMINTR_REDIRECT_TO_NON_DISP;
  332. return mask;
  333. }
  334. void gen6_disable_rps_interrupts(struct drm_device *dev)
  335. {
  336. struct drm_i915_private *dev_priv = dev->dev_private;
  337. spin_lock_irq(&dev_priv->irq_lock);
  338. dev_priv->rps.interrupts_enabled = false;
  339. spin_unlock_irq(&dev_priv->irq_lock);
  340. cancel_work_sync(&dev_priv->rps.work);
  341. spin_lock_irq(&dev_priv->irq_lock);
  342. I915_WRITE(GEN6_PMINTRMSK, gen6_sanitize_rps_pm_mask(dev_priv, ~0));
  343. __gen6_disable_pm_irq(dev_priv, dev_priv->pm_rps_events);
  344. I915_WRITE(gen6_pm_ier(dev_priv), I915_READ(gen6_pm_ier(dev_priv)) &
  345. ~dev_priv->pm_rps_events);
  346. spin_unlock_irq(&dev_priv->irq_lock);
  347. synchronize_irq(dev->irq);
  348. }
  349. /**
  350. * bdw_update_port_irq - update DE port interrupt
  351. * @dev_priv: driver private
  352. * @interrupt_mask: mask of interrupt bits to update
  353. * @enabled_irq_mask: mask of interrupt bits to enable
  354. */
  355. static void bdw_update_port_irq(struct drm_i915_private *dev_priv,
  356. uint32_t interrupt_mask,
  357. uint32_t enabled_irq_mask)
  358. {
  359. uint32_t new_val;
  360. uint32_t old_val;
  361. assert_spin_locked(&dev_priv->irq_lock);
  362. WARN_ON(enabled_irq_mask & ~interrupt_mask);
  363. if (WARN_ON(!intel_irqs_enabled(dev_priv)))
  364. return;
  365. old_val = I915_READ(GEN8_DE_PORT_IMR);
  366. new_val = old_val;
  367. new_val &= ~interrupt_mask;
  368. new_val |= (~enabled_irq_mask & interrupt_mask);
  369. if (new_val != old_val) {
  370. I915_WRITE(GEN8_DE_PORT_IMR, new_val);
  371. POSTING_READ(GEN8_DE_PORT_IMR);
  372. }
  373. }
  374. /**
  375. * ibx_display_interrupt_update - update SDEIMR
  376. * @dev_priv: driver private
  377. * @interrupt_mask: mask of interrupt bits to update
  378. * @enabled_irq_mask: mask of interrupt bits to enable
  379. */
  380. void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
  381. uint32_t interrupt_mask,
  382. uint32_t enabled_irq_mask)
  383. {
  384. uint32_t sdeimr = I915_READ(SDEIMR);
  385. sdeimr &= ~interrupt_mask;
  386. sdeimr |= (~enabled_irq_mask & interrupt_mask);
  387. WARN_ON(enabled_irq_mask & ~interrupt_mask);
  388. assert_spin_locked(&dev_priv->irq_lock);
  389. if (WARN_ON(!intel_irqs_enabled(dev_priv)))
  390. return;
  391. I915_WRITE(SDEIMR, sdeimr);
  392. POSTING_READ(SDEIMR);
  393. }
  394. static void
  395. __i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
  396. u32 enable_mask, u32 status_mask)
  397. {
  398. u32 reg = PIPESTAT(pipe);
  399. u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
  400. assert_spin_locked(&dev_priv->irq_lock);
  401. WARN_ON(!intel_irqs_enabled(dev_priv));
  402. if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
  403. status_mask & ~PIPESTAT_INT_STATUS_MASK,
  404. "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
  405. pipe_name(pipe), enable_mask, status_mask))
  406. return;
  407. if ((pipestat & enable_mask) == enable_mask)
  408. return;
  409. dev_priv->pipestat_irq_mask[pipe] |= status_mask;
  410. /* Enable the interrupt, clear any pending status */
  411. pipestat |= enable_mask | status_mask;
  412. I915_WRITE(reg, pipestat);
  413. POSTING_READ(reg);
  414. }
  415. static void
  416. __i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
  417. u32 enable_mask, u32 status_mask)
  418. {
  419. u32 reg = PIPESTAT(pipe);
  420. u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
  421. assert_spin_locked(&dev_priv->irq_lock);
  422. WARN_ON(!intel_irqs_enabled(dev_priv));
  423. if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
  424. status_mask & ~PIPESTAT_INT_STATUS_MASK,
  425. "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
  426. pipe_name(pipe), enable_mask, status_mask))
  427. return;
  428. if ((pipestat & enable_mask) == 0)
  429. return;
  430. dev_priv->pipestat_irq_mask[pipe] &= ~status_mask;
  431. pipestat &= ~enable_mask;
  432. I915_WRITE(reg, pipestat);
  433. POSTING_READ(reg);
  434. }
  435. static u32 vlv_get_pipestat_enable_mask(struct drm_device *dev, u32 status_mask)
  436. {
  437. u32 enable_mask = status_mask << 16;
  438. /*
  439. * On pipe A we don't support the PSR interrupt yet,
  440. * on pipe B and C the same bit MBZ.
  441. */
  442. if (WARN_ON_ONCE(status_mask & PIPE_A_PSR_STATUS_VLV))
  443. return 0;
  444. /*
  445. * On pipe B and C we don't support the PSR interrupt yet, on pipe
  446. * A the same bit is for perf counters which we don't use either.
  447. */
  448. if (WARN_ON_ONCE(status_mask & PIPE_B_PSR_STATUS_VLV))
  449. return 0;
  450. enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS |
  451. SPRITE0_FLIP_DONE_INT_EN_VLV |
  452. SPRITE1_FLIP_DONE_INT_EN_VLV);
  453. if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV)
  454. enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV;
  455. if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV)
  456. enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV;
  457. return enable_mask;
  458. }
  459. void
  460. i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
  461. u32 status_mask)
  462. {
  463. u32 enable_mask;
  464. if (IS_VALLEYVIEW(dev_priv->dev))
  465. enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev,
  466. status_mask);
  467. else
  468. enable_mask = status_mask << 16;
  469. __i915_enable_pipestat(dev_priv, pipe, enable_mask, status_mask);
  470. }
  471. void
  472. i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
  473. u32 status_mask)
  474. {
  475. u32 enable_mask;
  476. if (IS_VALLEYVIEW(dev_priv->dev))
  477. enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev,
  478. status_mask);
  479. else
  480. enable_mask = status_mask << 16;
  481. __i915_disable_pipestat(dev_priv, pipe, enable_mask, status_mask);
  482. }
  483. /**
  484. * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
  485. * @dev: drm device
  486. */
  487. static void i915_enable_asle_pipestat(struct drm_device *dev)
  488. {
  489. struct drm_i915_private *dev_priv = dev->dev_private;
  490. if (!dev_priv->opregion.asle || !IS_MOBILE(dev))
  491. return;
  492. spin_lock_irq(&dev_priv->irq_lock);
  493. i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS);
  494. if (INTEL_INFO(dev)->gen >= 4)
  495. i915_enable_pipestat(dev_priv, PIPE_A,
  496. PIPE_LEGACY_BLC_EVENT_STATUS);
  497. spin_unlock_irq(&dev_priv->irq_lock);
  498. }
  499. /*
  500. * This timing diagram depicts the video signal in and
  501. * around the vertical blanking period.
  502. *
  503. * Assumptions about the fictitious mode used in this example:
  504. * vblank_start >= 3
  505. * vsync_start = vblank_start + 1
  506. * vsync_end = vblank_start + 2
  507. * vtotal = vblank_start + 3
  508. *
  509. * start of vblank:
  510. * latch double buffered registers
  511. * increment frame counter (ctg+)
  512. * generate start of vblank interrupt (gen4+)
  513. * |
  514. * | frame start:
  515. * | generate frame start interrupt (aka. vblank interrupt) (gmch)
  516. * | may be shifted forward 1-3 extra lines via PIPECONF
  517. * | |
  518. * | | start of vsync:
  519. * | | generate vsync interrupt
  520. * | | |
  521. * ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx
  522. * . \hs/ . \hs/ \hs/ \hs/ . \hs/
  523. * ----va---> <-----------------vb--------------------> <--------va-------------
  524. * | | <----vs-----> |
  525. * -vbs-----> <---vbs+1---> <---vbs+2---> <-----0-----> <-----1-----> <-----2--- (scanline counter gen2)
  526. * -vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2---> <-----0--- (scanline counter gen3+)
  527. * -vbs-2---> <---vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2- (scanline counter hsw+ hdmi)
  528. * | | |
  529. * last visible pixel first visible pixel
  530. * | increment frame counter (gen3/4)
  531. * pixel counter = vblank_start * htotal pixel counter = 0 (gen3/4)
  532. *
  533. * x = horizontal active
  534. * _ = horizontal blanking
  535. * hs = horizontal sync
  536. * va = vertical active
  537. * vb = vertical blanking
  538. * vs = vertical sync
  539. * vbs = vblank_start (number)
  540. *
  541. * Summary:
  542. * - most events happen at the start of horizontal sync
  543. * - frame start happens at the start of horizontal blank, 1-4 lines
  544. * (depending on PIPECONF settings) after the start of vblank
  545. * - gen3/4 pixel and frame counter are synchronized with the start
  546. * of horizontal active on the first line of vertical active
  547. */
  548. static u32 i8xx_get_vblank_counter(struct drm_device *dev, unsigned int pipe)
  549. {
  550. /* Gen2 doesn't have a hardware frame counter */
  551. return 0;
  552. }
  553. /* Called from drm generic code, passed a 'crtc', which
  554. * we use as a pipe index
  555. */
  556. static u32 i915_get_vblank_counter(struct drm_device *dev, unsigned int pipe)
  557. {
  558. struct drm_i915_private *dev_priv = dev->dev_private;
  559. unsigned long high_frame;
  560. unsigned long low_frame;
  561. u32 high1, high2, low, pixel, vbl_start, hsync_start, htotal;
  562. struct intel_crtc *intel_crtc =
  563. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  564. const struct drm_display_mode *mode = &intel_crtc->base.hwmode;
  565. htotal = mode->crtc_htotal;
  566. hsync_start = mode->crtc_hsync_start;
  567. vbl_start = mode->crtc_vblank_start;
  568. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  569. vbl_start = DIV_ROUND_UP(vbl_start, 2);
  570. /* Convert to pixel count */
  571. vbl_start *= htotal;
  572. /* Start of vblank event occurs at start of hsync */
  573. vbl_start -= htotal - hsync_start;
  574. high_frame = PIPEFRAME(pipe);
  575. low_frame = PIPEFRAMEPIXEL(pipe);
  576. /*
  577. * High & low register fields aren't synchronized, so make sure
  578. * we get a low value that's stable across two reads of the high
  579. * register.
  580. */
  581. do {
  582. high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
  583. low = I915_READ(low_frame);
  584. high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
  585. } while (high1 != high2);
  586. high1 >>= PIPE_FRAME_HIGH_SHIFT;
  587. pixel = low & PIPE_PIXEL_MASK;
  588. low >>= PIPE_FRAME_LOW_SHIFT;
  589. /*
  590. * The frame counter increments at beginning of active.
  591. * Cook up a vblank counter by also checking the pixel
  592. * counter against vblank start.
  593. */
  594. return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff;
  595. }
  596. static u32 g4x_get_vblank_counter(struct drm_device *dev, unsigned int pipe)
  597. {
  598. struct drm_i915_private *dev_priv = dev->dev_private;
  599. return I915_READ(PIPE_FRMCOUNT_G4X(pipe));
  600. }
  601. /* raw reads, only for fast reads of display block, no need for forcewake etc. */
  602. #define __raw_i915_read32(dev_priv__, reg__) readl((dev_priv__)->regs + (reg__))
  603. static int __intel_get_crtc_scanline(struct intel_crtc *crtc)
  604. {
  605. struct drm_device *dev = crtc->base.dev;
  606. struct drm_i915_private *dev_priv = dev->dev_private;
  607. const struct drm_display_mode *mode = &crtc->base.hwmode;
  608. enum pipe pipe = crtc->pipe;
  609. int position, vtotal;
  610. vtotal = mode->crtc_vtotal;
  611. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  612. vtotal /= 2;
  613. if (IS_GEN2(dev))
  614. position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
  615. else
  616. position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
  617. /*
  618. * On HSW, the DSL reg (0x70000) appears to return 0 if we
  619. * read it just before the start of vblank. So try it again
  620. * so we don't accidentally end up spanning a vblank frame
  621. * increment, causing the pipe_update_end() code to squak at us.
  622. *
  623. * The nature of this problem means we can't simply check the ISR
  624. * bit and return the vblank start value; nor can we use the scanline
  625. * debug register in the transcoder as it appears to have the same
  626. * problem. We may need to extend this to include other platforms,
  627. * but so far testing only shows the problem on HSW.
  628. */
  629. if (HAS_DDI(dev) && !position) {
  630. int i, temp;
  631. for (i = 0; i < 100; i++) {
  632. udelay(1);
  633. temp = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) &
  634. DSL_LINEMASK_GEN3;
  635. if (temp != position) {
  636. position = temp;
  637. break;
  638. }
  639. }
  640. }
  641. /*
  642. * See update_scanline_offset() for the details on the
  643. * scanline_offset adjustment.
  644. */
  645. return (position + crtc->scanline_offset) % vtotal;
  646. }
  647. static int i915_get_crtc_scanoutpos(struct drm_device *dev, unsigned int pipe,
  648. unsigned int flags, int *vpos, int *hpos,
  649. ktime_t *stime, ktime_t *etime,
  650. const struct drm_display_mode *mode)
  651. {
  652. struct drm_i915_private *dev_priv = dev->dev_private;
  653. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  654. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  655. int position;
  656. int vbl_start, vbl_end, hsync_start, htotal, vtotal;
  657. bool in_vbl = true;
  658. int ret = 0;
  659. unsigned long irqflags;
  660. if (WARN_ON(!mode->crtc_clock)) {
  661. DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
  662. "pipe %c\n", pipe_name(pipe));
  663. return 0;
  664. }
  665. htotal = mode->crtc_htotal;
  666. hsync_start = mode->crtc_hsync_start;
  667. vtotal = mode->crtc_vtotal;
  668. vbl_start = mode->crtc_vblank_start;
  669. vbl_end = mode->crtc_vblank_end;
  670. if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
  671. vbl_start = DIV_ROUND_UP(vbl_start, 2);
  672. vbl_end /= 2;
  673. vtotal /= 2;
  674. }
  675. ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE;
  676. /*
  677. * Lock uncore.lock, as we will do multiple timing critical raw
  678. * register reads, potentially with preemption disabled, so the
  679. * following code must not block on uncore.lock.
  680. */
  681. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  682. /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
  683. /* Get optional system timestamp before query. */
  684. if (stime)
  685. *stime = ktime_get();
  686. if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
  687. /* No obvious pixelcount register. Only query vertical
  688. * scanout position from Display scan line register.
  689. */
  690. position = __intel_get_crtc_scanline(intel_crtc);
  691. } else {
  692. /* Have access to pixelcount since start of frame.
  693. * We can split this into vertical and horizontal
  694. * scanout position.
  695. */
  696. position = (__raw_i915_read32(dev_priv, PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
  697. /* convert to pixel counts */
  698. vbl_start *= htotal;
  699. vbl_end *= htotal;
  700. vtotal *= htotal;
  701. /*
  702. * In interlaced modes, the pixel counter counts all pixels,
  703. * so one field will have htotal more pixels. In order to avoid
  704. * the reported position from jumping backwards when the pixel
  705. * counter is beyond the length of the shorter field, just
  706. * clamp the position the length of the shorter field. This
  707. * matches how the scanline counter based position works since
  708. * the scanline counter doesn't count the two half lines.
  709. */
  710. if (position >= vtotal)
  711. position = vtotal - 1;
  712. /*
  713. * Start of vblank interrupt is triggered at start of hsync,
  714. * just prior to the first active line of vblank. However we
  715. * consider lines to start at the leading edge of horizontal
  716. * active. So, should we get here before we've crossed into
  717. * the horizontal active of the first line in vblank, we would
  718. * not set the DRM_SCANOUTPOS_INVBL flag. In order to fix that,
  719. * always add htotal-hsync_start to the current pixel position.
  720. */
  721. position = (position + htotal - hsync_start) % vtotal;
  722. }
  723. /* Get optional system timestamp after query. */
  724. if (etime)
  725. *etime = ktime_get();
  726. /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
  727. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  728. in_vbl = position >= vbl_start && position < vbl_end;
  729. /*
  730. * While in vblank, position will be negative
  731. * counting up towards 0 at vbl_end. And outside
  732. * vblank, position will be positive counting
  733. * up since vbl_end.
  734. */
  735. if (position >= vbl_start)
  736. position -= vbl_end;
  737. else
  738. position += vtotal - vbl_end;
  739. if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
  740. *vpos = position;
  741. *hpos = 0;
  742. } else {
  743. *vpos = position / htotal;
  744. *hpos = position - (*vpos * htotal);
  745. }
  746. /* In vblank? */
  747. if (in_vbl)
  748. ret |= DRM_SCANOUTPOS_IN_VBLANK;
  749. return ret;
  750. }
  751. int intel_get_crtc_scanline(struct intel_crtc *crtc)
  752. {
  753. struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
  754. unsigned long irqflags;
  755. int position;
  756. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  757. position = __intel_get_crtc_scanline(crtc);
  758. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  759. return position;
  760. }
  761. static int i915_get_vblank_timestamp(struct drm_device *dev, unsigned int pipe,
  762. int *max_error,
  763. struct timeval *vblank_time,
  764. unsigned flags)
  765. {
  766. struct drm_crtc *crtc;
  767. if (pipe >= INTEL_INFO(dev)->num_pipes) {
  768. DRM_ERROR("Invalid crtc %u\n", pipe);
  769. return -EINVAL;
  770. }
  771. /* Get drm_crtc to timestamp: */
  772. crtc = intel_get_crtc_for_pipe(dev, pipe);
  773. if (crtc == NULL) {
  774. DRM_ERROR("Invalid crtc %u\n", pipe);
  775. return -EINVAL;
  776. }
  777. if (!crtc->hwmode.crtc_clock) {
  778. DRM_DEBUG_KMS("crtc %u is disabled\n", pipe);
  779. return -EBUSY;
  780. }
  781. /* Helper routine in DRM core does all the work: */
  782. return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
  783. vblank_time, flags,
  784. &crtc->hwmode);
  785. }
  786. static void ironlake_rps_change_irq_handler(struct drm_device *dev)
  787. {
  788. struct drm_i915_private *dev_priv = dev->dev_private;
  789. u32 busy_up, busy_down, max_avg, min_avg;
  790. u8 new_delay;
  791. spin_lock(&mchdev_lock);
  792. I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
  793. new_delay = dev_priv->ips.cur_delay;
  794. I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
  795. busy_up = I915_READ(RCPREVBSYTUPAVG);
  796. busy_down = I915_READ(RCPREVBSYTDNAVG);
  797. max_avg = I915_READ(RCBMAXAVG);
  798. min_avg = I915_READ(RCBMINAVG);
  799. /* Handle RCS change request from hw */
  800. if (busy_up > max_avg) {
  801. if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
  802. new_delay = dev_priv->ips.cur_delay - 1;
  803. if (new_delay < dev_priv->ips.max_delay)
  804. new_delay = dev_priv->ips.max_delay;
  805. } else if (busy_down < min_avg) {
  806. if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
  807. new_delay = dev_priv->ips.cur_delay + 1;
  808. if (new_delay > dev_priv->ips.min_delay)
  809. new_delay = dev_priv->ips.min_delay;
  810. }
  811. if (ironlake_set_drps(dev, new_delay))
  812. dev_priv->ips.cur_delay = new_delay;
  813. spin_unlock(&mchdev_lock);
  814. return;
  815. }
  816. static void notify_ring(struct intel_engine_cs *ring)
  817. {
  818. if (!intel_ring_initialized(ring))
  819. return;
  820. trace_i915_gem_request_notify(ring);
  821. wake_up_all(&ring->irq_queue);
  822. }
  823. static void vlv_c0_read(struct drm_i915_private *dev_priv,
  824. struct intel_rps_ei *ei)
  825. {
  826. ei->cz_clock = vlv_punit_read(dev_priv, PUNIT_REG_CZ_TIMESTAMP);
  827. ei->render_c0 = I915_READ(VLV_RENDER_C0_COUNT);
  828. ei->media_c0 = I915_READ(VLV_MEDIA_C0_COUNT);
  829. }
  830. void gen6_rps_reset_ei(struct drm_i915_private *dev_priv)
  831. {
  832. memset(&dev_priv->rps.ei, 0, sizeof(dev_priv->rps.ei));
  833. }
  834. static u32 vlv_wa_c0_ei(struct drm_i915_private *dev_priv, u32 pm_iir)
  835. {
  836. const struct intel_rps_ei *prev = &dev_priv->rps.ei;
  837. struct intel_rps_ei now;
  838. u32 events = 0;
  839. if ((pm_iir & GEN6_PM_RP_UP_EI_EXPIRED) == 0)
  840. return 0;
  841. vlv_c0_read(dev_priv, &now);
  842. if (now.cz_clock == 0)
  843. return 0;
  844. if (prev->cz_clock) {
  845. u64 time, c0;
  846. unsigned int mul;
  847. mul = VLV_CZ_CLOCK_TO_MILLI_SEC * 100; /* scale to threshold% */
  848. if (I915_READ(VLV_COUNTER_CONTROL) & VLV_COUNT_RANGE_HIGH)
  849. mul <<= 8;
  850. time = now.cz_clock - prev->cz_clock;
  851. time *= dev_priv->czclk_freq;
  852. /* Workload can be split between render + media,
  853. * e.g. SwapBuffers being blitted in X after being rendered in
  854. * mesa. To account for this we need to combine both engines
  855. * into our activity counter.
  856. */
  857. c0 = now.render_c0 - prev->render_c0;
  858. c0 += now.media_c0 - prev->media_c0;
  859. c0 *= mul;
  860. if (c0 > time * dev_priv->rps.up_threshold)
  861. events = GEN6_PM_RP_UP_THRESHOLD;
  862. else if (c0 < time * dev_priv->rps.down_threshold)
  863. events = GEN6_PM_RP_DOWN_THRESHOLD;
  864. }
  865. dev_priv->rps.ei = now;
  866. return events;
  867. }
  868. static bool any_waiters(struct drm_i915_private *dev_priv)
  869. {
  870. struct intel_engine_cs *ring;
  871. int i;
  872. for_each_ring(ring, dev_priv, i)
  873. if (ring->irq_refcount)
  874. return true;
  875. return false;
  876. }
  877. static void gen6_pm_rps_work(struct work_struct *work)
  878. {
  879. struct drm_i915_private *dev_priv =
  880. container_of(work, struct drm_i915_private, rps.work);
  881. bool client_boost;
  882. int new_delay, adj, min, max;
  883. u32 pm_iir;
  884. spin_lock_irq(&dev_priv->irq_lock);
  885. /* Speed up work cancelation during disabling rps interrupts. */
  886. if (!dev_priv->rps.interrupts_enabled) {
  887. spin_unlock_irq(&dev_priv->irq_lock);
  888. return;
  889. }
  890. pm_iir = dev_priv->rps.pm_iir;
  891. dev_priv->rps.pm_iir = 0;
  892. /* Make sure not to corrupt PMIMR state used by ringbuffer on GEN6 */
  893. gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
  894. client_boost = dev_priv->rps.client_boost;
  895. dev_priv->rps.client_boost = false;
  896. spin_unlock_irq(&dev_priv->irq_lock);
  897. /* Make sure we didn't queue anything we're not going to process. */
  898. WARN_ON(pm_iir & ~dev_priv->pm_rps_events);
  899. if ((pm_iir & dev_priv->pm_rps_events) == 0 && !client_boost)
  900. return;
  901. mutex_lock(&dev_priv->rps.hw_lock);
  902. pm_iir |= vlv_wa_c0_ei(dev_priv, pm_iir);
  903. adj = dev_priv->rps.last_adj;
  904. new_delay = dev_priv->rps.cur_freq;
  905. min = dev_priv->rps.min_freq_softlimit;
  906. max = dev_priv->rps.max_freq_softlimit;
  907. if (client_boost) {
  908. new_delay = dev_priv->rps.max_freq_softlimit;
  909. adj = 0;
  910. } else if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
  911. if (adj > 0)
  912. adj *= 2;
  913. else /* CHV needs even encode values */
  914. adj = IS_CHERRYVIEW(dev_priv) ? 2 : 1;
  915. /*
  916. * For better performance, jump directly
  917. * to RPe if we're below it.
  918. */
  919. if (new_delay < dev_priv->rps.efficient_freq - adj) {
  920. new_delay = dev_priv->rps.efficient_freq;
  921. adj = 0;
  922. }
  923. } else if (any_waiters(dev_priv)) {
  924. adj = 0;
  925. } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) {
  926. if (dev_priv->rps.cur_freq > dev_priv->rps.efficient_freq)
  927. new_delay = dev_priv->rps.efficient_freq;
  928. else
  929. new_delay = dev_priv->rps.min_freq_softlimit;
  930. adj = 0;
  931. } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
  932. if (adj < 0)
  933. adj *= 2;
  934. else /* CHV needs even encode values */
  935. adj = IS_CHERRYVIEW(dev_priv) ? -2 : -1;
  936. } else { /* unknown event */
  937. adj = 0;
  938. }
  939. dev_priv->rps.last_adj = adj;
  940. /* sysfs frequency interfaces may have snuck in while servicing the
  941. * interrupt
  942. */
  943. new_delay += adj;
  944. new_delay = clamp_t(int, new_delay, min, max);
  945. intel_set_rps(dev_priv->dev, new_delay);
  946. mutex_unlock(&dev_priv->rps.hw_lock);
  947. }
  948. /**
  949. * ivybridge_parity_work - Workqueue called when a parity error interrupt
  950. * occurred.
  951. * @work: workqueue struct
  952. *
  953. * Doesn't actually do anything except notify userspace. As a consequence of
  954. * this event, userspace should try to remap the bad rows since statistically
  955. * it is likely the same row is more likely to go bad again.
  956. */
  957. static void ivybridge_parity_work(struct work_struct *work)
  958. {
  959. struct drm_i915_private *dev_priv =
  960. container_of(work, struct drm_i915_private, l3_parity.error_work);
  961. u32 error_status, row, bank, subbank;
  962. char *parity_event[6];
  963. uint32_t misccpctl;
  964. uint8_t slice = 0;
  965. /* We must turn off DOP level clock gating to access the L3 registers.
  966. * In order to prevent a get/put style interface, acquire struct mutex
  967. * any time we access those registers.
  968. */
  969. mutex_lock(&dev_priv->dev->struct_mutex);
  970. /* If we've screwed up tracking, just let the interrupt fire again */
  971. if (WARN_ON(!dev_priv->l3_parity.which_slice))
  972. goto out;
  973. misccpctl = I915_READ(GEN7_MISCCPCTL);
  974. I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
  975. POSTING_READ(GEN7_MISCCPCTL);
  976. while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
  977. u32 reg;
  978. slice--;
  979. if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv->dev)))
  980. break;
  981. dev_priv->l3_parity.which_slice &= ~(1<<slice);
  982. reg = GEN7_L3CDERRST1 + (slice * 0x200);
  983. error_status = I915_READ(reg);
  984. row = GEN7_PARITY_ERROR_ROW(error_status);
  985. bank = GEN7_PARITY_ERROR_BANK(error_status);
  986. subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
  987. I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
  988. POSTING_READ(reg);
  989. parity_event[0] = I915_L3_PARITY_UEVENT "=1";
  990. parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
  991. parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
  992. parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
  993. parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
  994. parity_event[5] = NULL;
  995. kobject_uevent_env(&dev_priv->dev->primary->kdev->kobj,
  996. KOBJ_CHANGE, parity_event);
  997. DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
  998. slice, row, bank, subbank);
  999. kfree(parity_event[4]);
  1000. kfree(parity_event[3]);
  1001. kfree(parity_event[2]);
  1002. kfree(parity_event[1]);
  1003. }
  1004. I915_WRITE(GEN7_MISCCPCTL, misccpctl);
  1005. out:
  1006. WARN_ON(dev_priv->l3_parity.which_slice);
  1007. spin_lock_irq(&dev_priv->irq_lock);
  1008. gen5_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv->dev));
  1009. spin_unlock_irq(&dev_priv->irq_lock);
  1010. mutex_unlock(&dev_priv->dev->struct_mutex);
  1011. }
  1012. static void ivybridge_parity_error_irq_handler(struct drm_device *dev, u32 iir)
  1013. {
  1014. struct drm_i915_private *dev_priv = dev->dev_private;
  1015. if (!HAS_L3_DPF(dev))
  1016. return;
  1017. spin_lock(&dev_priv->irq_lock);
  1018. gen5_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev));
  1019. spin_unlock(&dev_priv->irq_lock);
  1020. iir &= GT_PARITY_ERROR(dev);
  1021. if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1)
  1022. dev_priv->l3_parity.which_slice |= 1 << 1;
  1023. if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
  1024. dev_priv->l3_parity.which_slice |= 1 << 0;
  1025. queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
  1026. }
  1027. static void ilk_gt_irq_handler(struct drm_device *dev,
  1028. struct drm_i915_private *dev_priv,
  1029. u32 gt_iir)
  1030. {
  1031. if (gt_iir &
  1032. (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
  1033. notify_ring(&dev_priv->ring[RCS]);
  1034. if (gt_iir & ILK_BSD_USER_INTERRUPT)
  1035. notify_ring(&dev_priv->ring[VCS]);
  1036. }
  1037. static void snb_gt_irq_handler(struct drm_device *dev,
  1038. struct drm_i915_private *dev_priv,
  1039. u32 gt_iir)
  1040. {
  1041. if (gt_iir &
  1042. (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
  1043. notify_ring(&dev_priv->ring[RCS]);
  1044. if (gt_iir & GT_BSD_USER_INTERRUPT)
  1045. notify_ring(&dev_priv->ring[VCS]);
  1046. if (gt_iir & GT_BLT_USER_INTERRUPT)
  1047. notify_ring(&dev_priv->ring[BCS]);
  1048. if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
  1049. GT_BSD_CS_ERROR_INTERRUPT |
  1050. GT_RENDER_CS_MASTER_ERROR_INTERRUPT))
  1051. DRM_DEBUG("Command parser error, gt_iir 0x%08x\n", gt_iir);
  1052. if (gt_iir & GT_PARITY_ERROR(dev))
  1053. ivybridge_parity_error_irq_handler(dev, gt_iir);
  1054. }
  1055. static irqreturn_t gen8_gt_irq_handler(struct drm_i915_private *dev_priv,
  1056. u32 master_ctl)
  1057. {
  1058. irqreturn_t ret = IRQ_NONE;
  1059. if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
  1060. u32 tmp = I915_READ_FW(GEN8_GT_IIR(0));
  1061. if (tmp) {
  1062. I915_WRITE_FW(GEN8_GT_IIR(0), tmp);
  1063. ret = IRQ_HANDLED;
  1064. if (tmp & (GT_CONTEXT_SWITCH_INTERRUPT << GEN8_RCS_IRQ_SHIFT))
  1065. intel_lrc_irq_handler(&dev_priv->ring[RCS]);
  1066. if (tmp & (GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT))
  1067. notify_ring(&dev_priv->ring[RCS]);
  1068. if (tmp & (GT_CONTEXT_SWITCH_INTERRUPT << GEN8_BCS_IRQ_SHIFT))
  1069. intel_lrc_irq_handler(&dev_priv->ring[BCS]);
  1070. if (tmp & (GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT))
  1071. notify_ring(&dev_priv->ring[BCS]);
  1072. } else
  1073. DRM_ERROR("The master control interrupt lied (GT0)!\n");
  1074. }
  1075. if (master_ctl & (GEN8_GT_VCS1_IRQ | GEN8_GT_VCS2_IRQ)) {
  1076. u32 tmp = I915_READ_FW(GEN8_GT_IIR(1));
  1077. if (tmp) {
  1078. I915_WRITE_FW(GEN8_GT_IIR(1), tmp);
  1079. ret = IRQ_HANDLED;
  1080. if (tmp & (GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS1_IRQ_SHIFT))
  1081. intel_lrc_irq_handler(&dev_priv->ring[VCS]);
  1082. if (tmp & (GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT))
  1083. notify_ring(&dev_priv->ring[VCS]);
  1084. if (tmp & (GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS2_IRQ_SHIFT))
  1085. intel_lrc_irq_handler(&dev_priv->ring[VCS2]);
  1086. if (tmp & (GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT))
  1087. notify_ring(&dev_priv->ring[VCS2]);
  1088. } else
  1089. DRM_ERROR("The master control interrupt lied (GT1)!\n");
  1090. }
  1091. if (master_ctl & GEN8_GT_VECS_IRQ) {
  1092. u32 tmp = I915_READ_FW(GEN8_GT_IIR(3));
  1093. if (tmp) {
  1094. I915_WRITE_FW(GEN8_GT_IIR(3), tmp);
  1095. ret = IRQ_HANDLED;
  1096. if (tmp & (GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VECS_IRQ_SHIFT))
  1097. intel_lrc_irq_handler(&dev_priv->ring[VECS]);
  1098. if (tmp & (GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT))
  1099. notify_ring(&dev_priv->ring[VECS]);
  1100. } else
  1101. DRM_ERROR("The master control interrupt lied (GT3)!\n");
  1102. }
  1103. if (master_ctl & GEN8_GT_PM_IRQ) {
  1104. u32 tmp = I915_READ_FW(GEN8_GT_IIR(2));
  1105. if (tmp & dev_priv->pm_rps_events) {
  1106. I915_WRITE_FW(GEN8_GT_IIR(2),
  1107. tmp & dev_priv->pm_rps_events);
  1108. ret = IRQ_HANDLED;
  1109. gen6_rps_irq_handler(dev_priv, tmp);
  1110. } else
  1111. DRM_ERROR("The master control interrupt lied (PM)!\n");
  1112. }
  1113. return ret;
  1114. }
  1115. static bool bxt_port_hotplug_long_detect(enum port port, u32 val)
  1116. {
  1117. switch (port) {
  1118. case PORT_A:
  1119. return val & PORTA_HOTPLUG_LONG_DETECT;
  1120. case PORT_B:
  1121. return val & PORTB_HOTPLUG_LONG_DETECT;
  1122. case PORT_C:
  1123. return val & PORTC_HOTPLUG_LONG_DETECT;
  1124. default:
  1125. return false;
  1126. }
  1127. }
  1128. static bool spt_port_hotplug2_long_detect(enum port port, u32 val)
  1129. {
  1130. switch (port) {
  1131. case PORT_E:
  1132. return val & PORTE_HOTPLUG_LONG_DETECT;
  1133. default:
  1134. return false;
  1135. }
  1136. }
  1137. static bool spt_port_hotplug_long_detect(enum port port, u32 val)
  1138. {
  1139. switch (port) {
  1140. case PORT_A:
  1141. return val & PORTA_HOTPLUG_LONG_DETECT;
  1142. case PORT_B:
  1143. return val & PORTB_HOTPLUG_LONG_DETECT;
  1144. case PORT_C:
  1145. return val & PORTC_HOTPLUG_LONG_DETECT;
  1146. case PORT_D:
  1147. return val & PORTD_HOTPLUG_LONG_DETECT;
  1148. default:
  1149. return false;
  1150. }
  1151. }
  1152. static bool ilk_port_hotplug_long_detect(enum port port, u32 val)
  1153. {
  1154. switch (port) {
  1155. case PORT_A:
  1156. return val & DIGITAL_PORTA_HOTPLUG_LONG_DETECT;
  1157. default:
  1158. return false;
  1159. }
  1160. }
  1161. static bool pch_port_hotplug_long_detect(enum port port, u32 val)
  1162. {
  1163. switch (port) {
  1164. case PORT_B:
  1165. return val & PORTB_HOTPLUG_LONG_DETECT;
  1166. case PORT_C:
  1167. return val & PORTC_HOTPLUG_LONG_DETECT;
  1168. case PORT_D:
  1169. return val & PORTD_HOTPLUG_LONG_DETECT;
  1170. default:
  1171. return false;
  1172. }
  1173. }
  1174. static bool i9xx_port_hotplug_long_detect(enum port port, u32 val)
  1175. {
  1176. switch (port) {
  1177. case PORT_B:
  1178. return val & PORTB_HOTPLUG_INT_LONG_PULSE;
  1179. case PORT_C:
  1180. return val & PORTC_HOTPLUG_INT_LONG_PULSE;
  1181. case PORT_D:
  1182. return val & PORTD_HOTPLUG_INT_LONG_PULSE;
  1183. default:
  1184. return false;
  1185. }
  1186. }
  1187. /*
  1188. * Get a bit mask of pins that have triggered, and which ones may be long.
  1189. * This can be called multiple times with the same masks to accumulate
  1190. * hotplug detection results from several registers.
  1191. *
  1192. * Note that the caller is expected to zero out the masks initially.
  1193. */
  1194. static void intel_get_hpd_pins(u32 *pin_mask, u32 *long_mask,
  1195. u32 hotplug_trigger, u32 dig_hotplug_reg,
  1196. const u32 hpd[HPD_NUM_PINS],
  1197. bool long_pulse_detect(enum port port, u32 val))
  1198. {
  1199. enum port port;
  1200. int i;
  1201. for_each_hpd_pin(i) {
  1202. if ((hpd[i] & hotplug_trigger) == 0)
  1203. continue;
  1204. *pin_mask |= BIT(i);
  1205. if (!intel_hpd_pin_to_port(i, &port))
  1206. continue;
  1207. if (long_pulse_detect(port, dig_hotplug_reg))
  1208. *long_mask |= BIT(i);
  1209. }
  1210. DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x, dig 0x%08x, pins 0x%08x\n",
  1211. hotplug_trigger, dig_hotplug_reg, *pin_mask);
  1212. }
  1213. static void gmbus_irq_handler(struct drm_device *dev)
  1214. {
  1215. struct drm_i915_private *dev_priv = dev->dev_private;
  1216. wake_up_all(&dev_priv->gmbus_wait_queue);
  1217. }
  1218. static void dp_aux_irq_handler(struct drm_device *dev)
  1219. {
  1220. struct drm_i915_private *dev_priv = dev->dev_private;
  1221. wake_up_all(&dev_priv->gmbus_wait_queue);
  1222. }
  1223. #if defined(CONFIG_DEBUG_FS)
  1224. static void display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
  1225. uint32_t crc0, uint32_t crc1,
  1226. uint32_t crc2, uint32_t crc3,
  1227. uint32_t crc4)
  1228. {
  1229. struct drm_i915_private *dev_priv = dev->dev_private;
  1230. struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
  1231. struct intel_pipe_crc_entry *entry;
  1232. int head, tail;
  1233. spin_lock(&pipe_crc->lock);
  1234. if (!pipe_crc->entries) {
  1235. spin_unlock(&pipe_crc->lock);
  1236. DRM_DEBUG_KMS("spurious interrupt\n");
  1237. return;
  1238. }
  1239. head = pipe_crc->head;
  1240. tail = pipe_crc->tail;
  1241. if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) {
  1242. spin_unlock(&pipe_crc->lock);
  1243. DRM_ERROR("CRC buffer overflowing\n");
  1244. return;
  1245. }
  1246. entry = &pipe_crc->entries[head];
  1247. entry->frame = dev->driver->get_vblank_counter(dev, pipe);
  1248. entry->crc[0] = crc0;
  1249. entry->crc[1] = crc1;
  1250. entry->crc[2] = crc2;
  1251. entry->crc[3] = crc3;
  1252. entry->crc[4] = crc4;
  1253. head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
  1254. pipe_crc->head = head;
  1255. spin_unlock(&pipe_crc->lock);
  1256. wake_up_interruptible(&pipe_crc->wq);
  1257. }
  1258. #else
  1259. static inline void
  1260. display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
  1261. uint32_t crc0, uint32_t crc1,
  1262. uint32_t crc2, uint32_t crc3,
  1263. uint32_t crc4) {}
  1264. #endif
  1265. static void hsw_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
  1266. {
  1267. struct drm_i915_private *dev_priv = dev->dev_private;
  1268. display_pipe_crc_irq_handler(dev, pipe,
  1269. I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
  1270. 0, 0, 0, 0);
  1271. }
  1272. static void ivb_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
  1273. {
  1274. struct drm_i915_private *dev_priv = dev->dev_private;
  1275. display_pipe_crc_irq_handler(dev, pipe,
  1276. I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
  1277. I915_READ(PIPE_CRC_RES_2_IVB(pipe)),
  1278. I915_READ(PIPE_CRC_RES_3_IVB(pipe)),
  1279. I915_READ(PIPE_CRC_RES_4_IVB(pipe)),
  1280. I915_READ(PIPE_CRC_RES_5_IVB(pipe)));
  1281. }
  1282. static void i9xx_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
  1283. {
  1284. struct drm_i915_private *dev_priv = dev->dev_private;
  1285. uint32_t res1, res2;
  1286. if (INTEL_INFO(dev)->gen >= 3)
  1287. res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe));
  1288. else
  1289. res1 = 0;
  1290. if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
  1291. res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe));
  1292. else
  1293. res2 = 0;
  1294. display_pipe_crc_irq_handler(dev, pipe,
  1295. I915_READ(PIPE_CRC_RES_RED(pipe)),
  1296. I915_READ(PIPE_CRC_RES_GREEN(pipe)),
  1297. I915_READ(PIPE_CRC_RES_BLUE(pipe)),
  1298. res1, res2);
  1299. }
  1300. /* The RPS events need forcewake, so we add them to a work queue and mask their
  1301. * IMR bits until the work is done. Other interrupts can be processed without
  1302. * the work queue. */
  1303. static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
  1304. {
  1305. if (pm_iir & dev_priv->pm_rps_events) {
  1306. spin_lock(&dev_priv->irq_lock);
  1307. gen6_disable_pm_irq(dev_priv, pm_iir & dev_priv->pm_rps_events);
  1308. if (dev_priv->rps.interrupts_enabled) {
  1309. dev_priv->rps.pm_iir |= pm_iir & dev_priv->pm_rps_events;
  1310. queue_work(dev_priv->wq, &dev_priv->rps.work);
  1311. }
  1312. spin_unlock(&dev_priv->irq_lock);
  1313. }
  1314. if (INTEL_INFO(dev_priv)->gen >= 8)
  1315. return;
  1316. if (HAS_VEBOX(dev_priv->dev)) {
  1317. if (pm_iir & PM_VEBOX_USER_INTERRUPT)
  1318. notify_ring(&dev_priv->ring[VECS]);
  1319. if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT)
  1320. DRM_DEBUG("Command parser error, pm_iir 0x%08x\n", pm_iir);
  1321. }
  1322. }
  1323. static bool intel_pipe_handle_vblank(struct drm_device *dev, enum pipe pipe)
  1324. {
  1325. if (!drm_handle_vblank(dev, pipe))
  1326. return false;
  1327. return true;
  1328. }
  1329. static void valleyview_pipestat_irq_handler(struct drm_device *dev, u32 iir)
  1330. {
  1331. struct drm_i915_private *dev_priv = dev->dev_private;
  1332. u32 pipe_stats[I915_MAX_PIPES] = { };
  1333. int pipe;
  1334. spin_lock(&dev_priv->irq_lock);
  1335. for_each_pipe(dev_priv, pipe) {
  1336. int reg;
  1337. u32 mask, iir_bit = 0;
  1338. /*
  1339. * PIPESTAT bits get signalled even when the interrupt is
  1340. * disabled with the mask bits, and some of the status bits do
  1341. * not generate interrupts at all (like the underrun bit). Hence
  1342. * we need to be careful that we only handle what we want to
  1343. * handle.
  1344. */
  1345. /* fifo underruns are filterered in the underrun handler. */
  1346. mask = PIPE_FIFO_UNDERRUN_STATUS;
  1347. switch (pipe) {
  1348. case PIPE_A:
  1349. iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
  1350. break;
  1351. case PIPE_B:
  1352. iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
  1353. break;
  1354. case PIPE_C:
  1355. iir_bit = I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
  1356. break;
  1357. }
  1358. if (iir & iir_bit)
  1359. mask |= dev_priv->pipestat_irq_mask[pipe];
  1360. if (!mask)
  1361. continue;
  1362. reg = PIPESTAT(pipe);
  1363. mask |= PIPESTAT_INT_ENABLE_MASK;
  1364. pipe_stats[pipe] = I915_READ(reg) & mask;
  1365. /*
  1366. * Clear the PIPE*STAT regs before the IIR
  1367. */
  1368. if (pipe_stats[pipe] & (PIPE_FIFO_UNDERRUN_STATUS |
  1369. PIPESTAT_INT_STATUS_MASK))
  1370. I915_WRITE(reg, pipe_stats[pipe]);
  1371. }
  1372. spin_unlock(&dev_priv->irq_lock);
  1373. for_each_pipe(dev_priv, pipe) {
  1374. if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
  1375. intel_pipe_handle_vblank(dev, pipe))
  1376. intel_check_page_flip(dev, pipe);
  1377. if (pipe_stats[pipe] & PLANE_FLIP_DONE_INT_STATUS_VLV) {
  1378. intel_prepare_page_flip(dev, pipe);
  1379. intel_finish_page_flip(dev, pipe);
  1380. }
  1381. if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
  1382. i9xx_pipe_crc_irq_handler(dev, pipe);
  1383. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  1384. intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
  1385. }
  1386. if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
  1387. gmbus_irq_handler(dev);
  1388. }
  1389. static void i9xx_hpd_irq_handler(struct drm_device *dev)
  1390. {
  1391. struct drm_i915_private *dev_priv = dev->dev_private;
  1392. u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
  1393. u32 pin_mask = 0, long_mask = 0;
  1394. if (!hotplug_status)
  1395. return;
  1396. I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
  1397. /*
  1398. * Make sure hotplug status is cleared before we clear IIR, or else we
  1399. * may miss hotplug events.
  1400. */
  1401. POSTING_READ(PORT_HOTPLUG_STAT);
  1402. if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) {
  1403. u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X;
  1404. if (hotplug_trigger) {
  1405. intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
  1406. hotplug_trigger, hpd_status_g4x,
  1407. i9xx_port_hotplug_long_detect);
  1408. intel_hpd_irq_handler(dev, pin_mask, long_mask);
  1409. }
  1410. if (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
  1411. dp_aux_irq_handler(dev);
  1412. } else {
  1413. u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
  1414. if (hotplug_trigger) {
  1415. intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
  1416. hotplug_trigger, hpd_status_i915,
  1417. i9xx_port_hotplug_long_detect);
  1418. intel_hpd_irq_handler(dev, pin_mask, long_mask);
  1419. }
  1420. }
  1421. }
  1422. static irqreturn_t valleyview_irq_handler(int irq, void *arg)
  1423. {
  1424. struct drm_device *dev = arg;
  1425. struct drm_i915_private *dev_priv = dev->dev_private;
  1426. u32 iir, gt_iir, pm_iir;
  1427. irqreturn_t ret = IRQ_NONE;
  1428. if (!intel_irqs_enabled(dev_priv))
  1429. return IRQ_NONE;
  1430. while (true) {
  1431. /* Find, clear, then process each source of interrupt */
  1432. gt_iir = I915_READ(GTIIR);
  1433. if (gt_iir)
  1434. I915_WRITE(GTIIR, gt_iir);
  1435. pm_iir = I915_READ(GEN6_PMIIR);
  1436. if (pm_iir)
  1437. I915_WRITE(GEN6_PMIIR, pm_iir);
  1438. iir = I915_READ(VLV_IIR);
  1439. if (iir) {
  1440. /* Consume port before clearing IIR or we'll miss events */
  1441. if (iir & I915_DISPLAY_PORT_INTERRUPT)
  1442. i9xx_hpd_irq_handler(dev);
  1443. I915_WRITE(VLV_IIR, iir);
  1444. }
  1445. if (gt_iir == 0 && pm_iir == 0 && iir == 0)
  1446. goto out;
  1447. ret = IRQ_HANDLED;
  1448. if (gt_iir)
  1449. snb_gt_irq_handler(dev, dev_priv, gt_iir);
  1450. if (pm_iir)
  1451. gen6_rps_irq_handler(dev_priv, pm_iir);
  1452. /* Call regardless, as some status bits might not be
  1453. * signalled in iir */
  1454. valleyview_pipestat_irq_handler(dev, iir);
  1455. }
  1456. out:
  1457. return ret;
  1458. }
  1459. static irqreturn_t cherryview_irq_handler(int irq, void *arg)
  1460. {
  1461. struct drm_device *dev = arg;
  1462. struct drm_i915_private *dev_priv = dev->dev_private;
  1463. u32 master_ctl, iir;
  1464. irqreturn_t ret = IRQ_NONE;
  1465. if (!intel_irqs_enabled(dev_priv))
  1466. return IRQ_NONE;
  1467. for (;;) {
  1468. master_ctl = I915_READ(GEN8_MASTER_IRQ) & ~GEN8_MASTER_IRQ_CONTROL;
  1469. iir = I915_READ(VLV_IIR);
  1470. if (master_ctl == 0 && iir == 0)
  1471. break;
  1472. ret = IRQ_HANDLED;
  1473. I915_WRITE(GEN8_MASTER_IRQ, 0);
  1474. /* Find, clear, then process each source of interrupt */
  1475. if (iir) {
  1476. /* Consume port before clearing IIR or we'll miss events */
  1477. if (iir & I915_DISPLAY_PORT_INTERRUPT)
  1478. i9xx_hpd_irq_handler(dev);
  1479. I915_WRITE(VLV_IIR, iir);
  1480. }
  1481. gen8_gt_irq_handler(dev_priv, master_ctl);
  1482. /* Call regardless, as some status bits might not be
  1483. * signalled in iir */
  1484. valleyview_pipestat_irq_handler(dev, iir);
  1485. I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL);
  1486. POSTING_READ(GEN8_MASTER_IRQ);
  1487. }
  1488. return ret;
  1489. }
  1490. static void ibx_hpd_irq_handler(struct drm_device *dev, u32 hotplug_trigger,
  1491. const u32 hpd[HPD_NUM_PINS])
  1492. {
  1493. struct drm_i915_private *dev_priv = to_i915(dev);
  1494. u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
  1495. dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
  1496. I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
  1497. intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
  1498. dig_hotplug_reg, hpd,
  1499. pch_port_hotplug_long_detect);
  1500. intel_hpd_irq_handler(dev, pin_mask, long_mask);
  1501. }
  1502. static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir)
  1503. {
  1504. struct drm_i915_private *dev_priv = dev->dev_private;
  1505. int pipe;
  1506. u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
  1507. if (hotplug_trigger)
  1508. ibx_hpd_irq_handler(dev, hotplug_trigger, hpd_ibx);
  1509. if (pch_iir & SDE_AUDIO_POWER_MASK) {
  1510. int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
  1511. SDE_AUDIO_POWER_SHIFT);
  1512. DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
  1513. port_name(port));
  1514. }
  1515. if (pch_iir & SDE_AUX_MASK)
  1516. dp_aux_irq_handler(dev);
  1517. if (pch_iir & SDE_GMBUS)
  1518. gmbus_irq_handler(dev);
  1519. if (pch_iir & SDE_AUDIO_HDCP_MASK)
  1520. DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
  1521. if (pch_iir & SDE_AUDIO_TRANS_MASK)
  1522. DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
  1523. if (pch_iir & SDE_POISON)
  1524. DRM_ERROR("PCH poison interrupt\n");
  1525. if (pch_iir & SDE_FDI_MASK)
  1526. for_each_pipe(dev_priv, pipe)
  1527. DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
  1528. pipe_name(pipe),
  1529. I915_READ(FDI_RX_IIR(pipe)));
  1530. if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
  1531. DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
  1532. if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
  1533. DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
  1534. if (pch_iir & SDE_TRANSA_FIFO_UNDER)
  1535. intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_A);
  1536. if (pch_iir & SDE_TRANSB_FIFO_UNDER)
  1537. intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_B);
  1538. }
  1539. static void ivb_err_int_handler(struct drm_device *dev)
  1540. {
  1541. struct drm_i915_private *dev_priv = dev->dev_private;
  1542. u32 err_int = I915_READ(GEN7_ERR_INT);
  1543. enum pipe pipe;
  1544. if (err_int & ERR_INT_POISON)
  1545. DRM_ERROR("Poison interrupt\n");
  1546. for_each_pipe(dev_priv, pipe) {
  1547. if (err_int & ERR_INT_FIFO_UNDERRUN(pipe))
  1548. intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
  1549. if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
  1550. if (IS_IVYBRIDGE(dev))
  1551. ivb_pipe_crc_irq_handler(dev, pipe);
  1552. else
  1553. hsw_pipe_crc_irq_handler(dev, pipe);
  1554. }
  1555. }
  1556. I915_WRITE(GEN7_ERR_INT, err_int);
  1557. }
  1558. static void cpt_serr_int_handler(struct drm_device *dev)
  1559. {
  1560. struct drm_i915_private *dev_priv = dev->dev_private;
  1561. u32 serr_int = I915_READ(SERR_INT);
  1562. if (serr_int & SERR_INT_POISON)
  1563. DRM_ERROR("PCH poison interrupt\n");
  1564. if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
  1565. intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_A);
  1566. if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
  1567. intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_B);
  1568. if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
  1569. intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_C);
  1570. I915_WRITE(SERR_INT, serr_int);
  1571. }
  1572. static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir)
  1573. {
  1574. struct drm_i915_private *dev_priv = dev->dev_private;
  1575. int pipe;
  1576. u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
  1577. if (hotplug_trigger)
  1578. ibx_hpd_irq_handler(dev, hotplug_trigger, hpd_cpt);
  1579. if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
  1580. int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
  1581. SDE_AUDIO_POWER_SHIFT_CPT);
  1582. DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
  1583. port_name(port));
  1584. }
  1585. if (pch_iir & SDE_AUX_MASK_CPT)
  1586. dp_aux_irq_handler(dev);
  1587. if (pch_iir & SDE_GMBUS_CPT)
  1588. gmbus_irq_handler(dev);
  1589. if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
  1590. DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
  1591. if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
  1592. DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
  1593. if (pch_iir & SDE_FDI_MASK_CPT)
  1594. for_each_pipe(dev_priv, pipe)
  1595. DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
  1596. pipe_name(pipe),
  1597. I915_READ(FDI_RX_IIR(pipe)));
  1598. if (pch_iir & SDE_ERROR_CPT)
  1599. cpt_serr_int_handler(dev);
  1600. }
  1601. static void spt_irq_handler(struct drm_device *dev, u32 pch_iir)
  1602. {
  1603. struct drm_i915_private *dev_priv = dev->dev_private;
  1604. u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_SPT &
  1605. ~SDE_PORTE_HOTPLUG_SPT;
  1606. u32 hotplug2_trigger = pch_iir & SDE_PORTE_HOTPLUG_SPT;
  1607. u32 pin_mask = 0, long_mask = 0;
  1608. if (hotplug_trigger) {
  1609. u32 dig_hotplug_reg;
  1610. dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
  1611. I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
  1612. intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
  1613. dig_hotplug_reg, hpd_spt,
  1614. spt_port_hotplug_long_detect);
  1615. }
  1616. if (hotplug2_trigger) {
  1617. u32 dig_hotplug_reg;
  1618. dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG2);
  1619. I915_WRITE(PCH_PORT_HOTPLUG2, dig_hotplug_reg);
  1620. intel_get_hpd_pins(&pin_mask, &long_mask, hotplug2_trigger,
  1621. dig_hotplug_reg, hpd_spt,
  1622. spt_port_hotplug2_long_detect);
  1623. }
  1624. if (pin_mask)
  1625. intel_hpd_irq_handler(dev, pin_mask, long_mask);
  1626. if (pch_iir & SDE_GMBUS_CPT)
  1627. gmbus_irq_handler(dev);
  1628. }
  1629. static void ilk_hpd_irq_handler(struct drm_device *dev, u32 hotplug_trigger,
  1630. const u32 hpd[HPD_NUM_PINS])
  1631. {
  1632. struct drm_i915_private *dev_priv = to_i915(dev);
  1633. u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
  1634. dig_hotplug_reg = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL);
  1635. I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, dig_hotplug_reg);
  1636. intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
  1637. dig_hotplug_reg, hpd,
  1638. ilk_port_hotplug_long_detect);
  1639. intel_hpd_irq_handler(dev, pin_mask, long_mask);
  1640. }
  1641. static void ilk_display_irq_handler(struct drm_device *dev, u32 de_iir)
  1642. {
  1643. struct drm_i915_private *dev_priv = dev->dev_private;
  1644. enum pipe pipe;
  1645. u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG;
  1646. if (hotplug_trigger)
  1647. ilk_hpd_irq_handler(dev, hotplug_trigger, hpd_ilk);
  1648. if (de_iir & DE_AUX_CHANNEL_A)
  1649. dp_aux_irq_handler(dev);
  1650. if (de_iir & DE_GSE)
  1651. intel_opregion_asle_intr(dev);
  1652. if (de_iir & DE_POISON)
  1653. DRM_ERROR("Poison interrupt\n");
  1654. for_each_pipe(dev_priv, pipe) {
  1655. if (de_iir & DE_PIPE_VBLANK(pipe) &&
  1656. intel_pipe_handle_vblank(dev, pipe))
  1657. intel_check_page_flip(dev, pipe);
  1658. if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
  1659. intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
  1660. if (de_iir & DE_PIPE_CRC_DONE(pipe))
  1661. i9xx_pipe_crc_irq_handler(dev, pipe);
  1662. /* plane/pipes map 1:1 on ilk+ */
  1663. if (de_iir & DE_PLANE_FLIP_DONE(pipe)) {
  1664. intel_prepare_page_flip(dev, pipe);
  1665. intel_finish_page_flip_plane(dev, pipe);
  1666. }
  1667. }
  1668. /* check event from PCH */
  1669. if (de_iir & DE_PCH_EVENT) {
  1670. u32 pch_iir = I915_READ(SDEIIR);
  1671. if (HAS_PCH_CPT(dev))
  1672. cpt_irq_handler(dev, pch_iir);
  1673. else
  1674. ibx_irq_handler(dev, pch_iir);
  1675. /* should clear PCH hotplug event before clear CPU irq */
  1676. I915_WRITE(SDEIIR, pch_iir);
  1677. }
  1678. if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT)
  1679. ironlake_rps_change_irq_handler(dev);
  1680. }
  1681. static void ivb_display_irq_handler(struct drm_device *dev, u32 de_iir)
  1682. {
  1683. struct drm_i915_private *dev_priv = dev->dev_private;
  1684. enum pipe pipe;
  1685. u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG_IVB;
  1686. if (hotplug_trigger)
  1687. ilk_hpd_irq_handler(dev, hotplug_trigger, hpd_ivb);
  1688. if (de_iir & DE_ERR_INT_IVB)
  1689. ivb_err_int_handler(dev);
  1690. if (de_iir & DE_AUX_CHANNEL_A_IVB)
  1691. dp_aux_irq_handler(dev);
  1692. if (de_iir & DE_GSE_IVB)
  1693. intel_opregion_asle_intr(dev);
  1694. for_each_pipe(dev_priv, pipe) {
  1695. if (de_iir & (DE_PIPE_VBLANK_IVB(pipe)) &&
  1696. intel_pipe_handle_vblank(dev, pipe))
  1697. intel_check_page_flip(dev, pipe);
  1698. /* plane/pipes map 1:1 on ilk+ */
  1699. if (de_iir & DE_PLANE_FLIP_DONE_IVB(pipe)) {
  1700. intel_prepare_page_flip(dev, pipe);
  1701. intel_finish_page_flip_plane(dev, pipe);
  1702. }
  1703. }
  1704. /* check event from PCH */
  1705. if (!HAS_PCH_NOP(dev) && (de_iir & DE_PCH_EVENT_IVB)) {
  1706. u32 pch_iir = I915_READ(SDEIIR);
  1707. cpt_irq_handler(dev, pch_iir);
  1708. /* clear PCH hotplug event before clear CPU irq */
  1709. I915_WRITE(SDEIIR, pch_iir);
  1710. }
  1711. }
  1712. /*
  1713. * To handle irqs with the minimum potential races with fresh interrupts, we:
  1714. * 1 - Disable Master Interrupt Control.
  1715. * 2 - Find the source(s) of the interrupt.
  1716. * 3 - Clear the Interrupt Identity bits (IIR).
  1717. * 4 - Process the interrupt(s) that had bits set in the IIRs.
  1718. * 5 - Re-enable Master Interrupt Control.
  1719. */
  1720. static irqreturn_t ironlake_irq_handler(int irq, void *arg)
  1721. {
  1722. struct drm_device *dev = arg;
  1723. struct drm_i915_private *dev_priv = dev->dev_private;
  1724. u32 de_iir, gt_iir, de_ier, sde_ier = 0;
  1725. irqreturn_t ret = IRQ_NONE;
  1726. if (!intel_irqs_enabled(dev_priv))
  1727. return IRQ_NONE;
  1728. /* We get interrupts on unclaimed registers, so check for this before we
  1729. * do any I915_{READ,WRITE}. */
  1730. intel_uncore_check_errors(dev);
  1731. /* disable master interrupt before clearing iir */
  1732. de_ier = I915_READ(DEIER);
  1733. I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
  1734. POSTING_READ(DEIER);
  1735. /* Disable south interrupts. We'll only write to SDEIIR once, so further
  1736. * interrupts will will be stored on its back queue, and then we'll be
  1737. * able to process them after we restore SDEIER (as soon as we restore
  1738. * it, we'll get an interrupt if SDEIIR still has something to process
  1739. * due to its back queue). */
  1740. if (!HAS_PCH_NOP(dev)) {
  1741. sde_ier = I915_READ(SDEIER);
  1742. I915_WRITE(SDEIER, 0);
  1743. POSTING_READ(SDEIER);
  1744. }
  1745. /* Find, clear, then process each source of interrupt */
  1746. gt_iir = I915_READ(GTIIR);
  1747. if (gt_iir) {
  1748. I915_WRITE(GTIIR, gt_iir);
  1749. ret = IRQ_HANDLED;
  1750. if (INTEL_INFO(dev)->gen >= 6)
  1751. snb_gt_irq_handler(dev, dev_priv, gt_iir);
  1752. else
  1753. ilk_gt_irq_handler(dev, dev_priv, gt_iir);
  1754. }
  1755. de_iir = I915_READ(DEIIR);
  1756. if (de_iir) {
  1757. I915_WRITE(DEIIR, de_iir);
  1758. ret = IRQ_HANDLED;
  1759. if (INTEL_INFO(dev)->gen >= 7)
  1760. ivb_display_irq_handler(dev, de_iir);
  1761. else
  1762. ilk_display_irq_handler(dev, de_iir);
  1763. }
  1764. if (INTEL_INFO(dev)->gen >= 6) {
  1765. u32 pm_iir = I915_READ(GEN6_PMIIR);
  1766. if (pm_iir) {
  1767. I915_WRITE(GEN6_PMIIR, pm_iir);
  1768. ret = IRQ_HANDLED;
  1769. gen6_rps_irq_handler(dev_priv, pm_iir);
  1770. }
  1771. }
  1772. I915_WRITE(DEIER, de_ier);
  1773. POSTING_READ(DEIER);
  1774. if (!HAS_PCH_NOP(dev)) {
  1775. I915_WRITE(SDEIER, sde_ier);
  1776. POSTING_READ(SDEIER);
  1777. }
  1778. return ret;
  1779. }
  1780. static void bxt_hpd_irq_handler(struct drm_device *dev, u32 hotplug_trigger,
  1781. const u32 hpd[HPD_NUM_PINS])
  1782. {
  1783. struct drm_i915_private *dev_priv = to_i915(dev);
  1784. u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
  1785. dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
  1786. I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
  1787. intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
  1788. dig_hotplug_reg, hpd,
  1789. bxt_port_hotplug_long_detect);
  1790. intel_hpd_irq_handler(dev, pin_mask, long_mask);
  1791. }
  1792. static irqreturn_t gen8_irq_handler(int irq, void *arg)
  1793. {
  1794. struct drm_device *dev = arg;
  1795. struct drm_i915_private *dev_priv = dev->dev_private;
  1796. u32 master_ctl;
  1797. irqreturn_t ret = IRQ_NONE;
  1798. uint32_t tmp = 0;
  1799. enum pipe pipe;
  1800. u32 aux_mask = GEN8_AUX_CHANNEL_A;
  1801. if (!intel_irqs_enabled(dev_priv))
  1802. return IRQ_NONE;
  1803. if (INTEL_INFO(dev_priv)->gen >= 9)
  1804. aux_mask |= GEN9_AUX_CHANNEL_B | GEN9_AUX_CHANNEL_C |
  1805. GEN9_AUX_CHANNEL_D;
  1806. master_ctl = I915_READ_FW(GEN8_MASTER_IRQ);
  1807. master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
  1808. if (!master_ctl)
  1809. return IRQ_NONE;
  1810. I915_WRITE_FW(GEN8_MASTER_IRQ, 0);
  1811. /* Find, clear, then process each source of interrupt */
  1812. ret = gen8_gt_irq_handler(dev_priv, master_ctl);
  1813. if (master_ctl & GEN8_DE_MISC_IRQ) {
  1814. tmp = I915_READ(GEN8_DE_MISC_IIR);
  1815. if (tmp) {
  1816. I915_WRITE(GEN8_DE_MISC_IIR, tmp);
  1817. ret = IRQ_HANDLED;
  1818. if (tmp & GEN8_DE_MISC_GSE)
  1819. intel_opregion_asle_intr(dev);
  1820. else
  1821. DRM_ERROR("Unexpected DE Misc interrupt\n");
  1822. }
  1823. else
  1824. DRM_ERROR("The master control interrupt lied (DE MISC)!\n");
  1825. }
  1826. if (master_ctl & GEN8_DE_PORT_IRQ) {
  1827. tmp = I915_READ(GEN8_DE_PORT_IIR);
  1828. if (tmp) {
  1829. bool found = false;
  1830. u32 hotplug_trigger = 0;
  1831. if (IS_BROXTON(dev_priv))
  1832. hotplug_trigger = tmp & BXT_DE_PORT_HOTPLUG_MASK;
  1833. else if (IS_BROADWELL(dev_priv))
  1834. hotplug_trigger = tmp & GEN8_PORT_DP_A_HOTPLUG;
  1835. I915_WRITE(GEN8_DE_PORT_IIR, tmp);
  1836. ret = IRQ_HANDLED;
  1837. if (tmp & aux_mask) {
  1838. dp_aux_irq_handler(dev);
  1839. found = true;
  1840. }
  1841. if (hotplug_trigger) {
  1842. if (IS_BROXTON(dev))
  1843. bxt_hpd_irq_handler(dev, hotplug_trigger, hpd_bxt);
  1844. else
  1845. ilk_hpd_irq_handler(dev, hotplug_trigger, hpd_bdw);
  1846. found = true;
  1847. }
  1848. if (IS_BROXTON(dev) && (tmp & BXT_DE_PORT_GMBUS)) {
  1849. gmbus_irq_handler(dev);
  1850. found = true;
  1851. }
  1852. if (!found)
  1853. DRM_ERROR("Unexpected DE Port interrupt\n");
  1854. }
  1855. else
  1856. DRM_ERROR("The master control interrupt lied (DE PORT)!\n");
  1857. }
  1858. for_each_pipe(dev_priv, pipe) {
  1859. uint32_t pipe_iir, flip_done = 0, fault_errors = 0;
  1860. if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
  1861. continue;
  1862. pipe_iir = I915_READ(GEN8_DE_PIPE_IIR(pipe));
  1863. if (pipe_iir) {
  1864. ret = IRQ_HANDLED;
  1865. I915_WRITE(GEN8_DE_PIPE_IIR(pipe), pipe_iir);
  1866. if (pipe_iir & GEN8_PIPE_VBLANK &&
  1867. intel_pipe_handle_vblank(dev, pipe))
  1868. intel_check_page_flip(dev, pipe);
  1869. if (INTEL_INFO(dev_priv)->gen >= 9)
  1870. flip_done = pipe_iir & GEN9_PIPE_PLANE1_FLIP_DONE;
  1871. else
  1872. flip_done = pipe_iir & GEN8_PIPE_PRIMARY_FLIP_DONE;
  1873. if (flip_done) {
  1874. intel_prepare_page_flip(dev, pipe);
  1875. intel_finish_page_flip_plane(dev, pipe);
  1876. }
  1877. if (pipe_iir & GEN8_PIPE_CDCLK_CRC_DONE)
  1878. hsw_pipe_crc_irq_handler(dev, pipe);
  1879. if (pipe_iir & GEN8_PIPE_FIFO_UNDERRUN)
  1880. intel_cpu_fifo_underrun_irq_handler(dev_priv,
  1881. pipe);
  1882. if (INTEL_INFO(dev_priv)->gen >= 9)
  1883. fault_errors = pipe_iir & GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
  1884. else
  1885. fault_errors = pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
  1886. if (fault_errors)
  1887. DRM_ERROR("Fault errors on pipe %c\n: 0x%08x",
  1888. pipe_name(pipe),
  1889. pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS);
  1890. } else
  1891. DRM_ERROR("The master control interrupt lied (DE PIPE)!\n");
  1892. }
  1893. if (HAS_PCH_SPLIT(dev) && !HAS_PCH_NOP(dev) &&
  1894. master_ctl & GEN8_DE_PCH_IRQ) {
  1895. /*
  1896. * FIXME(BDW): Assume for now that the new interrupt handling
  1897. * scheme also closed the SDE interrupt handling race we've seen
  1898. * on older pch-split platforms. But this needs testing.
  1899. */
  1900. u32 pch_iir = I915_READ(SDEIIR);
  1901. if (pch_iir) {
  1902. I915_WRITE(SDEIIR, pch_iir);
  1903. ret = IRQ_HANDLED;
  1904. if (HAS_PCH_SPT(dev_priv))
  1905. spt_irq_handler(dev, pch_iir);
  1906. else
  1907. cpt_irq_handler(dev, pch_iir);
  1908. } else {
  1909. /*
  1910. * Like on previous PCH there seems to be something
  1911. * fishy going on with forwarding PCH interrupts.
  1912. */
  1913. DRM_DEBUG_DRIVER("The master control interrupt lied (SDE)!\n");
  1914. }
  1915. }
  1916. I915_WRITE_FW(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
  1917. POSTING_READ_FW(GEN8_MASTER_IRQ);
  1918. return ret;
  1919. }
  1920. static void i915_error_wake_up(struct drm_i915_private *dev_priv,
  1921. bool reset_completed)
  1922. {
  1923. struct intel_engine_cs *ring;
  1924. int i;
  1925. /*
  1926. * Notify all waiters for GPU completion events that reset state has
  1927. * been changed, and that they need to restart their wait after
  1928. * checking for potential errors (and bail out to drop locks if there is
  1929. * a gpu reset pending so that i915_error_work_func can acquire them).
  1930. */
  1931. /* Wake up __wait_seqno, potentially holding dev->struct_mutex. */
  1932. for_each_ring(ring, dev_priv, i)
  1933. wake_up_all(&ring->irq_queue);
  1934. /* Wake up intel_crtc_wait_for_pending_flips, holding crtc->mutex. */
  1935. wake_up_all(&dev_priv->pending_flip_queue);
  1936. /*
  1937. * Signal tasks blocked in i915_gem_wait_for_error that the pending
  1938. * reset state is cleared.
  1939. */
  1940. if (reset_completed)
  1941. wake_up_all(&dev_priv->gpu_error.reset_queue);
  1942. }
  1943. /**
  1944. * i915_reset_and_wakeup - do process context error handling work
  1945. * @dev: drm device
  1946. *
  1947. * Fire an error uevent so userspace can see that a hang or error
  1948. * was detected.
  1949. */
  1950. static void i915_reset_and_wakeup(struct drm_device *dev)
  1951. {
  1952. struct drm_i915_private *dev_priv = to_i915(dev);
  1953. struct i915_gpu_error *error = &dev_priv->gpu_error;
  1954. char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
  1955. char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
  1956. char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
  1957. int ret;
  1958. kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE, error_event);
  1959. /*
  1960. * Note that there's only one work item which does gpu resets, so we
  1961. * need not worry about concurrent gpu resets potentially incrementing
  1962. * error->reset_counter twice. We only need to take care of another
  1963. * racing irq/hangcheck declaring the gpu dead for a second time. A
  1964. * quick check for that is good enough: schedule_work ensures the
  1965. * correct ordering between hang detection and this work item, and since
  1966. * the reset in-progress bit is only ever set by code outside of this
  1967. * work we don't need to worry about any other races.
  1968. */
  1969. if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) {
  1970. DRM_DEBUG_DRIVER("resetting chip\n");
  1971. kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE,
  1972. reset_event);
  1973. /*
  1974. * In most cases it's guaranteed that we get here with an RPM
  1975. * reference held, for example because there is a pending GPU
  1976. * request that won't finish until the reset is done. This
  1977. * isn't the case at least when we get here by doing a
  1978. * simulated reset via debugs, so get an RPM reference.
  1979. */
  1980. intel_runtime_pm_get(dev_priv);
  1981. intel_prepare_reset(dev);
  1982. /*
  1983. * All state reset _must_ be completed before we update the
  1984. * reset counter, for otherwise waiters might miss the reset
  1985. * pending state and not properly drop locks, resulting in
  1986. * deadlocks with the reset work.
  1987. */
  1988. ret = i915_reset(dev);
  1989. intel_finish_reset(dev);
  1990. intel_runtime_pm_put(dev_priv);
  1991. if (ret == 0) {
  1992. /*
  1993. * After all the gem state is reset, increment the reset
  1994. * counter and wake up everyone waiting for the reset to
  1995. * complete.
  1996. *
  1997. * Since unlock operations are a one-sided barrier only,
  1998. * we need to insert a barrier here to order any seqno
  1999. * updates before
  2000. * the counter increment.
  2001. */
  2002. smp_mb__before_atomic();
  2003. atomic_inc(&dev_priv->gpu_error.reset_counter);
  2004. kobject_uevent_env(&dev->primary->kdev->kobj,
  2005. KOBJ_CHANGE, reset_done_event);
  2006. } else {
  2007. atomic_or(I915_WEDGED, &error->reset_counter);
  2008. }
  2009. /*
  2010. * Note: The wake_up also serves as a memory barrier so that
  2011. * waiters see the update value of the reset counter atomic_t.
  2012. */
  2013. i915_error_wake_up(dev_priv, true);
  2014. }
  2015. }
  2016. static void i915_report_and_clear_eir(struct drm_device *dev)
  2017. {
  2018. struct drm_i915_private *dev_priv = dev->dev_private;
  2019. uint32_t instdone[I915_NUM_INSTDONE_REG];
  2020. u32 eir = I915_READ(EIR);
  2021. int pipe, i;
  2022. if (!eir)
  2023. return;
  2024. pr_err("render error detected, EIR: 0x%08x\n", eir);
  2025. i915_get_extra_instdone(dev, instdone);
  2026. if (IS_G4X(dev)) {
  2027. if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
  2028. u32 ipeir = I915_READ(IPEIR_I965);
  2029. pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
  2030. pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
  2031. for (i = 0; i < ARRAY_SIZE(instdone); i++)
  2032. pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
  2033. pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
  2034. pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
  2035. I915_WRITE(IPEIR_I965, ipeir);
  2036. POSTING_READ(IPEIR_I965);
  2037. }
  2038. if (eir & GM45_ERROR_PAGE_TABLE) {
  2039. u32 pgtbl_err = I915_READ(PGTBL_ER);
  2040. pr_err("page table error\n");
  2041. pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
  2042. I915_WRITE(PGTBL_ER, pgtbl_err);
  2043. POSTING_READ(PGTBL_ER);
  2044. }
  2045. }
  2046. if (!IS_GEN2(dev)) {
  2047. if (eir & I915_ERROR_PAGE_TABLE) {
  2048. u32 pgtbl_err = I915_READ(PGTBL_ER);
  2049. pr_err("page table error\n");
  2050. pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
  2051. I915_WRITE(PGTBL_ER, pgtbl_err);
  2052. POSTING_READ(PGTBL_ER);
  2053. }
  2054. }
  2055. if (eir & I915_ERROR_MEMORY_REFRESH) {
  2056. pr_err("memory refresh error:\n");
  2057. for_each_pipe(dev_priv, pipe)
  2058. pr_err("pipe %c stat: 0x%08x\n",
  2059. pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
  2060. /* pipestat has already been acked */
  2061. }
  2062. if (eir & I915_ERROR_INSTRUCTION) {
  2063. pr_err("instruction error\n");
  2064. pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM));
  2065. for (i = 0; i < ARRAY_SIZE(instdone); i++)
  2066. pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
  2067. if (INTEL_INFO(dev)->gen < 4) {
  2068. u32 ipeir = I915_READ(IPEIR);
  2069. pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR));
  2070. pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR));
  2071. pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD));
  2072. I915_WRITE(IPEIR, ipeir);
  2073. POSTING_READ(IPEIR);
  2074. } else {
  2075. u32 ipeir = I915_READ(IPEIR_I965);
  2076. pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
  2077. pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
  2078. pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
  2079. pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
  2080. I915_WRITE(IPEIR_I965, ipeir);
  2081. POSTING_READ(IPEIR_I965);
  2082. }
  2083. }
  2084. I915_WRITE(EIR, eir);
  2085. POSTING_READ(EIR);
  2086. eir = I915_READ(EIR);
  2087. if (eir) {
  2088. /*
  2089. * some errors might have become stuck,
  2090. * mask them.
  2091. */
  2092. DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
  2093. I915_WRITE(EMR, I915_READ(EMR) | eir);
  2094. I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  2095. }
  2096. }
  2097. /**
  2098. * i915_handle_error - handle a gpu error
  2099. * @dev: drm device
  2100. *
  2101. * Do some basic checking of register state at error time and
  2102. * dump it to the syslog. Also call i915_capture_error_state() to make
  2103. * sure we get a record and make it available in debugfs. Fire a uevent
  2104. * so userspace knows something bad happened (should trigger collection
  2105. * of a ring dump etc.).
  2106. */
  2107. void i915_handle_error(struct drm_device *dev, bool wedged,
  2108. const char *fmt, ...)
  2109. {
  2110. struct drm_i915_private *dev_priv = dev->dev_private;
  2111. va_list args;
  2112. char error_msg[80];
  2113. va_start(args, fmt);
  2114. vscnprintf(error_msg, sizeof(error_msg), fmt, args);
  2115. va_end(args);
  2116. i915_capture_error_state(dev, wedged, error_msg);
  2117. i915_report_and_clear_eir(dev);
  2118. if (wedged) {
  2119. atomic_or(I915_RESET_IN_PROGRESS_FLAG,
  2120. &dev_priv->gpu_error.reset_counter);
  2121. /*
  2122. * Wakeup waiting processes so that the reset function
  2123. * i915_reset_and_wakeup doesn't deadlock trying to grab
  2124. * various locks. By bumping the reset counter first, the woken
  2125. * processes will see a reset in progress and back off,
  2126. * releasing their locks and then wait for the reset completion.
  2127. * We must do this for _all_ gpu waiters that might hold locks
  2128. * that the reset work needs to acquire.
  2129. *
  2130. * Note: The wake_up serves as the required memory barrier to
  2131. * ensure that the waiters see the updated value of the reset
  2132. * counter atomic_t.
  2133. */
  2134. i915_error_wake_up(dev_priv, false);
  2135. }
  2136. i915_reset_and_wakeup(dev);
  2137. }
  2138. /* Called from drm generic code, passed 'crtc' which
  2139. * we use as a pipe index
  2140. */
  2141. static int i915_enable_vblank(struct drm_device *dev, unsigned int pipe)
  2142. {
  2143. struct drm_i915_private *dev_priv = dev->dev_private;
  2144. unsigned long irqflags;
  2145. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2146. if (INTEL_INFO(dev)->gen >= 4)
  2147. i915_enable_pipestat(dev_priv, pipe,
  2148. PIPE_START_VBLANK_INTERRUPT_STATUS);
  2149. else
  2150. i915_enable_pipestat(dev_priv, pipe,
  2151. PIPE_VBLANK_INTERRUPT_STATUS);
  2152. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2153. return 0;
  2154. }
  2155. static int ironlake_enable_vblank(struct drm_device *dev, unsigned int pipe)
  2156. {
  2157. struct drm_i915_private *dev_priv = dev->dev_private;
  2158. unsigned long irqflags;
  2159. uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
  2160. DE_PIPE_VBLANK(pipe);
  2161. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2162. ironlake_enable_display_irq(dev_priv, bit);
  2163. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2164. return 0;
  2165. }
  2166. static int valleyview_enable_vblank(struct drm_device *dev, unsigned int pipe)
  2167. {
  2168. struct drm_i915_private *dev_priv = dev->dev_private;
  2169. unsigned long irqflags;
  2170. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2171. i915_enable_pipestat(dev_priv, pipe,
  2172. PIPE_START_VBLANK_INTERRUPT_STATUS);
  2173. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2174. return 0;
  2175. }
  2176. static int gen8_enable_vblank(struct drm_device *dev, unsigned int pipe)
  2177. {
  2178. struct drm_i915_private *dev_priv = dev->dev_private;
  2179. unsigned long irqflags;
  2180. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2181. dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_VBLANK;
  2182. I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
  2183. POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
  2184. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2185. return 0;
  2186. }
  2187. /* Called from drm generic code, passed 'crtc' which
  2188. * we use as a pipe index
  2189. */
  2190. static void i915_disable_vblank(struct drm_device *dev, unsigned int pipe)
  2191. {
  2192. struct drm_i915_private *dev_priv = dev->dev_private;
  2193. unsigned long irqflags;
  2194. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2195. i915_disable_pipestat(dev_priv, pipe,
  2196. PIPE_VBLANK_INTERRUPT_STATUS |
  2197. PIPE_START_VBLANK_INTERRUPT_STATUS);
  2198. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2199. }
  2200. static void ironlake_disable_vblank(struct drm_device *dev, unsigned int pipe)
  2201. {
  2202. struct drm_i915_private *dev_priv = dev->dev_private;
  2203. unsigned long irqflags;
  2204. uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
  2205. DE_PIPE_VBLANK(pipe);
  2206. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2207. ironlake_disable_display_irq(dev_priv, bit);
  2208. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2209. }
  2210. static void valleyview_disable_vblank(struct drm_device *dev, unsigned int pipe)
  2211. {
  2212. struct drm_i915_private *dev_priv = dev->dev_private;
  2213. unsigned long irqflags;
  2214. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2215. i915_disable_pipestat(dev_priv, pipe,
  2216. PIPE_START_VBLANK_INTERRUPT_STATUS);
  2217. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2218. }
  2219. static void gen8_disable_vblank(struct drm_device *dev, unsigned int pipe)
  2220. {
  2221. struct drm_i915_private *dev_priv = dev->dev_private;
  2222. unsigned long irqflags;
  2223. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2224. dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_VBLANK;
  2225. I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
  2226. POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
  2227. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2228. }
  2229. static bool
  2230. ring_idle(struct intel_engine_cs *ring, u32 seqno)
  2231. {
  2232. return (list_empty(&ring->request_list) ||
  2233. i915_seqno_passed(seqno, ring->last_submitted_seqno));
  2234. }
  2235. static bool
  2236. ipehr_is_semaphore_wait(struct drm_device *dev, u32 ipehr)
  2237. {
  2238. if (INTEL_INFO(dev)->gen >= 8) {
  2239. return (ipehr >> 23) == 0x1c;
  2240. } else {
  2241. ipehr &= ~MI_SEMAPHORE_SYNC_MASK;
  2242. return ipehr == (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE |
  2243. MI_SEMAPHORE_REGISTER);
  2244. }
  2245. }
  2246. static struct intel_engine_cs *
  2247. semaphore_wait_to_signaller_ring(struct intel_engine_cs *ring, u32 ipehr, u64 offset)
  2248. {
  2249. struct drm_i915_private *dev_priv = ring->dev->dev_private;
  2250. struct intel_engine_cs *signaller;
  2251. int i;
  2252. if (INTEL_INFO(dev_priv->dev)->gen >= 8) {
  2253. for_each_ring(signaller, dev_priv, i) {
  2254. if (ring == signaller)
  2255. continue;
  2256. if (offset == signaller->semaphore.signal_ggtt[ring->id])
  2257. return signaller;
  2258. }
  2259. } else {
  2260. u32 sync_bits = ipehr & MI_SEMAPHORE_SYNC_MASK;
  2261. for_each_ring(signaller, dev_priv, i) {
  2262. if(ring == signaller)
  2263. continue;
  2264. if (sync_bits == signaller->semaphore.mbox.wait[ring->id])
  2265. return signaller;
  2266. }
  2267. }
  2268. DRM_ERROR("No signaller ring found for ring %i, ipehr 0x%08x, offset 0x%016llx\n",
  2269. ring->id, ipehr, offset);
  2270. return NULL;
  2271. }
  2272. static struct intel_engine_cs *
  2273. semaphore_waits_for(struct intel_engine_cs *ring, u32 *seqno)
  2274. {
  2275. struct drm_i915_private *dev_priv = ring->dev->dev_private;
  2276. u32 cmd, ipehr, head;
  2277. u64 offset = 0;
  2278. int i, backwards;
  2279. /*
  2280. * This function does not support execlist mode - any attempt to
  2281. * proceed further into this function will result in a kernel panic
  2282. * when dereferencing ring->buffer, which is not set up in execlist
  2283. * mode.
  2284. *
  2285. * The correct way of doing it would be to derive the currently
  2286. * executing ring buffer from the current context, which is derived
  2287. * from the currently running request. Unfortunately, to get the
  2288. * current request we would have to grab the struct_mutex before doing
  2289. * anything else, which would be ill-advised since some other thread
  2290. * might have grabbed it already and managed to hang itself, causing
  2291. * the hang checker to deadlock.
  2292. *
  2293. * Therefore, this function does not support execlist mode in its
  2294. * current form. Just return NULL and move on.
  2295. */
  2296. if (ring->buffer == NULL)
  2297. return NULL;
  2298. ipehr = I915_READ(RING_IPEHR(ring->mmio_base));
  2299. if (!ipehr_is_semaphore_wait(ring->dev, ipehr))
  2300. return NULL;
  2301. /*
  2302. * HEAD is likely pointing to the dword after the actual command,
  2303. * so scan backwards until we find the MBOX. But limit it to just 3
  2304. * or 4 dwords depending on the semaphore wait command size.
  2305. * Note that we don't care about ACTHD here since that might
  2306. * point at at batch, and semaphores are always emitted into the
  2307. * ringbuffer itself.
  2308. */
  2309. head = I915_READ_HEAD(ring) & HEAD_ADDR;
  2310. backwards = (INTEL_INFO(ring->dev)->gen >= 8) ? 5 : 4;
  2311. for (i = backwards; i; --i) {
  2312. /*
  2313. * Be paranoid and presume the hw has gone off into the wild -
  2314. * our ring is smaller than what the hardware (and hence
  2315. * HEAD_ADDR) allows. Also handles wrap-around.
  2316. */
  2317. head &= ring->buffer->size - 1;
  2318. /* This here seems to blow up */
  2319. cmd = ioread32(ring->buffer->virtual_start + head);
  2320. if (cmd == ipehr)
  2321. break;
  2322. head -= 4;
  2323. }
  2324. if (!i)
  2325. return NULL;
  2326. *seqno = ioread32(ring->buffer->virtual_start + head + 4) + 1;
  2327. if (INTEL_INFO(ring->dev)->gen >= 8) {
  2328. offset = ioread32(ring->buffer->virtual_start + head + 12);
  2329. offset <<= 32;
  2330. offset = ioread32(ring->buffer->virtual_start + head + 8);
  2331. }
  2332. return semaphore_wait_to_signaller_ring(ring, ipehr, offset);
  2333. }
  2334. static int semaphore_passed(struct intel_engine_cs *ring)
  2335. {
  2336. struct drm_i915_private *dev_priv = ring->dev->dev_private;
  2337. struct intel_engine_cs *signaller;
  2338. u32 seqno;
  2339. ring->hangcheck.deadlock++;
  2340. signaller = semaphore_waits_for(ring, &seqno);
  2341. if (signaller == NULL)
  2342. return -1;
  2343. /* Prevent pathological recursion due to driver bugs */
  2344. if (signaller->hangcheck.deadlock >= I915_NUM_RINGS)
  2345. return -1;
  2346. if (i915_seqno_passed(signaller->get_seqno(signaller, false), seqno))
  2347. return 1;
  2348. /* cursory check for an unkickable deadlock */
  2349. if (I915_READ_CTL(signaller) & RING_WAIT_SEMAPHORE &&
  2350. semaphore_passed(signaller) < 0)
  2351. return -1;
  2352. return 0;
  2353. }
  2354. static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv)
  2355. {
  2356. struct intel_engine_cs *ring;
  2357. int i;
  2358. for_each_ring(ring, dev_priv, i)
  2359. ring->hangcheck.deadlock = 0;
  2360. }
  2361. static enum intel_ring_hangcheck_action
  2362. ring_stuck(struct intel_engine_cs *ring, u64 acthd)
  2363. {
  2364. struct drm_device *dev = ring->dev;
  2365. struct drm_i915_private *dev_priv = dev->dev_private;
  2366. u32 tmp;
  2367. if (acthd != ring->hangcheck.acthd) {
  2368. if (acthd > ring->hangcheck.max_acthd) {
  2369. ring->hangcheck.max_acthd = acthd;
  2370. return HANGCHECK_ACTIVE;
  2371. }
  2372. return HANGCHECK_ACTIVE_LOOP;
  2373. }
  2374. if (IS_GEN2(dev))
  2375. return HANGCHECK_HUNG;
  2376. /* Is the chip hanging on a WAIT_FOR_EVENT?
  2377. * If so we can simply poke the RB_WAIT bit
  2378. * and break the hang. This should work on
  2379. * all but the second generation chipsets.
  2380. */
  2381. tmp = I915_READ_CTL(ring);
  2382. if (tmp & RING_WAIT) {
  2383. i915_handle_error(dev, false,
  2384. "Kicking stuck wait on %s",
  2385. ring->name);
  2386. I915_WRITE_CTL(ring, tmp);
  2387. return HANGCHECK_KICK;
  2388. }
  2389. if (INTEL_INFO(dev)->gen >= 6 && tmp & RING_WAIT_SEMAPHORE) {
  2390. switch (semaphore_passed(ring)) {
  2391. default:
  2392. return HANGCHECK_HUNG;
  2393. case 1:
  2394. i915_handle_error(dev, false,
  2395. "Kicking stuck semaphore on %s",
  2396. ring->name);
  2397. I915_WRITE_CTL(ring, tmp);
  2398. return HANGCHECK_KICK;
  2399. case 0:
  2400. return HANGCHECK_WAIT;
  2401. }
  2402. }
  2403. return HANGCHECK_HUNG;
  2404. }
  2405. /*
  2406. * This is called when the chip hasn't reported back with completed
  2407. * batchbuffers in a long time. We keep track per ring seqno progress and
  2408. * if there are no progress, hangcheck score for that ring is increased.
  2409. * Further, acthd is inspected to see if the ring is stuck. On stuck case
  2410. * we kick the ring. If we see no progress on three subsequent calls
  2411. * we assume chip is wedged and try to fix it by resetting the chip.
  2412. */
  2413. static void i915_hangcheck_elapsed(struct work_struct *work)
  2414. {
  2415. struct drm_i915_private *dev_priv =
  2416. container_of(work, typeof(*dev_priv),
  2417. gpu_error.hangcheck_work.work);
  2418. struct drm_device *dev = dev_priv->dev;
  2419. struct intel_engine_cs *ring;
  2420. int i;
  2421. int busy_count = 0, rings_hung = 0;
  2422. bool stuck[I915_NUM_RINGS] = { 0 };
  2423. #define BUSY 1
  2424. #define KICK 5
  2425. #define HUNG 20
  2426. if (!i915.enable_hangcheck)
  2427. return;
  2428. for_each_ring(ring, dev_priv, i) {
  2429. u64 acthd;
  2430. u32 seqno;
  2431. bool busy = true;
  2432. semaphore_clear_deadlocks(dev_priv);
  2433. seqno = ring->get_seqno(ring, false);
  2434. acthd = intel_ring_get_active_head(ring);
  2435. if (ring->hangcheck.seqno == seqno) {
  2436. if (ring_idle(ring, seqno)) {
  2437. ring->hangcheck.action = HANGCHECK_IDLE;
  2438. if (waitqueue_active(&ring->irq_queue)) {
  2439. /* Issue a wake-up to catch stuck h/w. */
  2440. if (!test_and_set_bit(ring->id, &dev_priv->gpu_error.missed_irq_rings)) {
  2441. if (!(dev_priv->gpu_error.test_irq_rings & intel_ring_flag(ring)))
  2442. DRM_ERROR("Hangcheck timer elapsed... %s idle\n",
  2443. ring->name);
  2444. else
  2445. DRM_INFO("Fake missed irq on %s\n",
  2446. ring->name);
  2447. wake_up_all(&ring->irq_queue);
  2448. }
  2449. /* Safeguard against driver failure */
  2450. ring->hangcheck.score += BUSY;
  2451. } else
  2452. busy = false;
  2453. } else {
  2454. /* We always increment the hangcheck score
  2455. * if the ring is busy and still processing
  2456. * the same request, so that no single request
  2457. * can run indefinitely (such as a chain of
  2458. * batches). The only time we do not increment
  2459. * the hangcheck score on this ring, if this
  2460. * ring is in a legitimate wait for another
  2461. * ring. In that case the waiting ring is a
  2462. * victim and we want to be sure we catch the
  2463. * right culprit. Then every time we do kick
  2464. * the ring, add a small increment to the
  2465. * score so that we can catch a batch that is
  2466. * being repeatedly kicked and so responsible
  2467. * for stalling the machine.
  2468. */
  2469. ring->hangcheck.action = ring_stuck(ring,
  2470. acthd);
  2471. switch (ring->hangcheck.action) {
  2472. case HANGCHECK_IDLE:
  2473. case HANGCHECK_WAIT:
  2474. case HANGCHECK_ACTIVE:
  2475. break;
  2476. case HANGCHECK_ACTIVE_LOOP:
  2477. ring->hangcheck.score += BUSY;
  2478. break;
  2479. case HANGCHECK_KICK:
  2480. ring->hangcheck.score += KICK;
  2481. break;
  2482. case HANGCHECK_HUNG:
  2483. ring->hangcheck.score += HUNG;
  2484. stuck[i] = true;
  2485. break;
  2486. }
  2487. }
  2488. } else {
  2489. ring->hangcheck.action = HANGCHECK_ACTIVE;
  2490. /* Gradually reduce the count so that we catch DoS
  2491. * attempts across multiple batches.
  2492. */
  2493. if (ring->hangcheck.score > 0)
  2494. ring->hangcheck.score--;
  2495. ring->hangcheck.acthd = ring->hangcheck.max_acthd = 0;
  2496. }
  2497. ring->hangcheck.seqno = seqno;
  2498. ring->hangcheck.acthd = acthd;
  2499. busy_count += busy;
  2500. }
  2501. for_each_ring(ring, dev_priv, i) {
  2502. if (ring->hangcheck.score >= HANGCHECK_SCORE_RING_HUNG) {
  2503. DRM_INFO("%s on %s\n",
  2504. stuck[i] ? "stuck" : "no progress",
  2505. ring->name);
  2506. rings_hung++;
  2507. }
  2508. }
  2509. if (rings_hung)
  2510. return i915_handle_error(dev, true, "Ring hung");
  2511. if (busy_count)
  2512. /* Reset timer case chip hangs without another request
  2513. * being added */
  2514. i915_queue_hangcheck(dev);
  2515. }
  2516. void i915_queue_hangcheck(struct drm_device *dev)
  2517. {
  2518. struct i915_gpu_error *e = &to_i915(dev)->gpu_error;
  2519. if (!i915.enable_hangcheck)
  2520. return;
  2521. /* Don't continually defer the hangcheck so that it is always run at
  2522. * least once after work has been scheduled on any ring. Otherwise,
  2523. * we will ignore a hung ring if a second ring is kept busy.
  2524. */
  2525. queue_delayed_work(e->hangcheck_wq, &e->hangcheck_work,
  2526. round_jiffies_up_relative(DRM_I915_HANGCHECK_JIFFIES));
  2527. }
  2528. static void ibx_irq_reset(struct drm_device *dev)
  2529. {
  2530. struct drm_i915_private *dev_priv = dev->dev_private;
  2531. if (HAS_PCH_NOP(dev))
  2532. return;
  2533. GEN5_IRQ_RESET(SDE);
  2534. if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev))
  2535. I915_WRITE(SERR_INT, 0xffffffff);
  2536. }
  2537. /*
  2538. * SDEIER is also touched by the interrupt handler to work around missed PCH
  2539. * interrupts. Hence we can't update it after the interrupt handler is enabled -
  2540. * instead we unconditionally enable all PCH interrupt sources here, but then
  2541. * only unmask them as needed with SDEIMR.
  2542. *
  2543. * This function needs to be called before interrupts are enabled.
  2544. */
  2545. static void ibx_irq_pre_postinstall(struct drm_device *dev)
  2546. {
  2547. struct drm_i915_private *dev_priv = dev->dev_private;
  2548. if (HAS_PCH_NOP(dev))
  2549. return;
  2550. WARN_ON(I915_READ(SDEIER) != 0);
  2551. I915_WRITE(SDEIER, 0xffffffff);
  2552. POSTING_READ(SDEIER);
  2553. }
  2554. static void gen5_gt_irq_reset(struct drm_device *dev)
  2555. {
  2556. struct drm_i915_private *dev_priv = dev->dev_private;
  2557. GEN5_IRQ_RESET(GT);
  2558. if (INTEL_INFO(dev)->gen >= 6)
  2559. GEN5_IRQ_RESET(GEN6_PM);
  2560. }
  2561. /* drm_dma.h hooks
  2562. */
  2563. static void ironlake_irq_reset(struct drm_device *dev)
  2564. {
  2565. struct drm_i915_private *dev_priv = dev->dev_private;
  2566. I915_WRITE(HWSTAM, 0xffffffff);
  2567. GEN5_IRQ_RESET(DE);
  2568. if (IS_GEN7(dev))
  2569. I915_WRITE(GEN7_ERR_INT, 0xffffffff);
  2570. gen5_gt_irq_reset(dev);
  2571. ibx_irq_reset(dev);
  2572. }
  2573. static void vlv_display_irq_reset(struct drm_i915_private *dev_priv)
  2574. {
  2575. enum pipe pipe;
  2576. i915_hotplug_interrupt_update(dev_priv, 0xFFFFFFFF, 0);
  2577. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  2578. for_each_pipe(dev_priv, pipe)
  2579. I915_WRITE(PIPESTAT(pipe), 0xffff);
  2580. GEN5_IRQ_RESET(VLV_);
  2581. }
  2582. static void valleyview_irq_preinstall(struct drm_device *dev)
  2583. {
  2584. struct drm_i915_private *dev_priv = dev->dev_private;
  2585. /* VLV magic */
  2586. I915_WRITE(VLV_IMR, 0);
  2587. I915_WRITE(RING_IMR(RENDER_RING_BASE), 0);
  2588. I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0);
  2589. I915_WRITE(RING_IMR(BLT_RING_BASE), 0);
  2590. gen5_gt_irq_reset(dev);
  2591. I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
  2592. vlv_display_irq_reset(dev_priv);
  2593. }
  2594. static void gen8_gt_irq_reset(struct drm_i915_private *dev_priv)
  2595. {
  2596. GEN8_IRQ_RESET_NDX(GT, 0);
  2597. GEN8_IRQ_RESET_NDX(GT, 1);
  2598. GEN8_IRQ_RESET_NDX(GT, 2);
  2599. GEN8_IRQ_RESET_NDX(GT, 3);
  2600. }
  2601. static void gen8_irq_reset(struct drm_device *dev)
  2602. {
  2603. struct drm_i915_private *dev_priv = dev->dev_private;
  2604. int pipe;
  2605. I915_WRITE(GEN8_MASTER_IRQ, 0);
  2606. POSTING_READ(GEN8_MASTER_IRQ);
  2607. gen8_gt_irq_reset(dev_priv);
  2608. for_each_pipe(dev_priv, pipe)
  2609. if (intel_display_power_is_enabled(dev_priv,
  2610. POWER_DOMAIN_PIPE(pipe)))
  2611. GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
  2612. GEN5_IRQ_RESET(GEN8_DE_PORT_);
  2613. GEN5_IRQ_RESET(GEN8_DE_MISC_);
  2614. GEN5_IRQ_RESET(GEN8_PCU_);
  2615. if (HAS_PCH_SPLIT(dev))
  2616. ibx_irq_reset(dev);
  2617. }
  2618. void gen8_irq_power_well_post_enable(struct drm_i915_private *dev_priv,
  2619. unsigned int pipe_mask)
  2620. {
  2621. uint32_t extra_ier = GEN8_PIPE_VBLANK | GEN8_PIPE_FIFO_UNDERRUN;
  2622. spin_lock_irq(&dev_priv->irq_lock);
  2623. if (pipe_mask & 1 << PIPE_A)
  2624. GEN8_IRQ_INIT_NDX(DE_PIPE, PIPE_A,
  2625. dev_priv->de_irq_mask[PIPE_A],
  2626. ~dev_priv->de_irq_mask[PIPE_A] | extra_ier);
  2627. if (pipe_mask & 1 << PIPE_B)
  2628. GEN8_IRQ_INIT_NDX(DE_PIPE, PIPE_B,
  2629. dev_priv->de_irq_mask[PIPE_B],
  2630. ~dev_priv->de_irq_mask[PIPE_B] | extra_ier);
  2631. if (pipe_mask & 1 << PIPE_C)
  2632. GEN8_IRQ_INIT_NDX(DE_PIPE, PIPE_C,
  2633. dev_priv->de_irq_mask[PIPE_C],
  2634. ~dev_priv->de_irq_mask[PIPE_C] | extra_ier);
  2635. spin_unlock_irq(&dev_priv->irq_lock);
  2636. }
  2637. static void cherryview_irq_preinstall(struct drm_device *dev)
  2638. {
  2639. struct drm_i915_private *dev_priv = dev->dev_private;
  2640. I915_WRITE(GEN8_MASTER_IRQ, 0);
  2641. POSTING_READ(GEN8_MASTER_IRQ);
  2642. gen8_gt_irq_reset(dev_priv);
  2643. GEN5_IRQ_RESET(GEN8_PCU_);
  2644. I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK_CHV);
  2645. vlv_display_irq_reset(dev_priv);
  2646. }
  2647. static u32 intel_hpd_enabled_irqs(struct drm_device *dev,
  2648. const u32 hpd[HPD_NUM_PINS])
  2649. {
  2650. struct drm_i915_private *dev_priv = to_i915(dev);
  2651. struct intel_encoder *encoder;
  2652. u32 enabled_irqs = 0;
  2653. for_each_intel_encoder(dev, encoder)
  2654. if (dev_priv->hotplug.stats[encoder->hpd_pin].state == HPD_ENABLED)
  2655. enabled_irqs |= hpd[encoder->hpd_pin];
  2656. return enabled_irqs;
  2657. }
  2658. static void ibx_hpd_irq_setup(struct drm_device *dev)
  2659. {
  2660. struct drm_i915_private *dev_priv = dev->dev_private;
  2661. u32 hotplug_irqs, hotplug, enabled_irqs;
  2662. if (HAS_PCH_IBX(dev)) {
  2663. hotplug_irqs = SDE_HOTPLUG_MASK;
  2664. enabled_irqs = intel_hpd_enabled_irqs(dev, hpd_ibx);
  2665. } else {
  2666. hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
  2667. enabled_irqs = intel_hpd_enabled_irqs(dev, hpd_cpt);
  2668. }
  2669. ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
  2670. /*
  2671. * Enable digital hotplug on the PCH, and configure the DP short pulse
  2672. * duration to 2ms (which is the minimum in the Display Port spec).
  2673. * The pulse duration bits are reserved on LPT+.
  2674. */
  2675. hotplug = I915_READ(PCH_PORT_HOTPLUG);
  2676. hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK);
  2677. hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
  2678. hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
  2679. hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
  2680. /*
  2681. * When CPU and PCH are on the same package, port A
  2682. * HPD must be enabled in both north and south.
  2683. */
  2684. if (HAS_PCH_LPT_LP(dev))
  2685. hotplug |= PORTA_HOTPLUG_ENABLE;
  2686. I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
  2687. }
  2688. static void spt_hpd_irq_setup(struct drm_device *dev)
  2689. {
  2690. struct drm_i915_private *dev_priv = dev->dev_private;
  2691. u32 hotplug_irqs, hotplug, enabled_irqs;
  2692. hotplug_irqs = SDE_HOTPLUG_MASK_SPT;
  2693. enabled_irqs = intel_hpd_enabled_irqs(dev, hpd_spt);
  2694. ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
  2695. /* Enable digital hotplug on the PCH */
  2696. hotplug = I915_READ(PCH_PORT_HOTPLUG);
  2697. hotplug |= PORTD_HOTPLUG_ENABLE | PORTC_HOTPLUG_ENABLE |
  2698. PORTB_HOTPLUG_ENABLE | PORTA_HOTPLUG_ENABLE;
  2699. I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
  2700. hotplug = I915_READ(PCH_PORT_HOTPLUG2);
  2701. hotplug |= PORTE_HOTPLUG_ENABLE;
  2702. I915_WRITE(PCH_PORT_HOTPLUG2, hotplug);
  2703. }
  2704. static void ilk_hpd_irq_setup(struct drm_device *dev)
  2705. {
  2706. struct drm_i915_private *dev_priv = dev->dev_private;
  2707. u32 hotplug_irqs, hotplug, enabled_irqs;
  2708. if (INTEL_INFO(dev)->gen >= 8) {
  2709. hotplug_irqs = GEN8_PORT_DP_A_HOTPLUG;
  2710. enabled_irqs = intel_hpd_enabled_irqs(dev, hpd_bdw);
  2711. bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
  2712. } else if (INTEL_INFO(dev)->gen >= 7) {
  2713. hotplug_irqs = DE_DP_A_HOTPLUG_IVB;
  2714. enabled_irqs = intel_hpd_enabled_irqs(dev, hpd_ivb);
  2715. ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
  2716. } else {
  2717. hotplug_irqs = DE_DP_A_HOTPLUG;
  2718. enabled_irqs = intel_hpd_enabled_irqs(dev, hpd_ilk);
  2719. ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
  2720. }
  2721. /*
  2722. * Enable digital hotplug on the CPU, and configure the DP short pulse
  2723. * duration to 2ms (which is the minimum in the Display Port spec)
  2724. * The pulse duration bits are reserved on HSW+.
  2725. */
  2726. hotplug = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL);
  2727. hotplug &= ~DIGITAL_PORTA_PULSE_DURATION_MASK;
  2728. hotplug |= DIGITAL_PORTA_HOTPLUG_ENABLE | DIGITAL_PORTA_PULSE_DURATION_2ms;
  2729. I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, hotplug);
  2730. ibx_hpd_irq_setup(dev);
  2731. }
  2732. static void bxt_hpd_irq_setup(struct drm_device *dev)
  2733. {
  2734. struct drm_i915_private *dev_priv = dev->dev_private;
  2735. u32 hotplug_irqs, hotplug, enabled_irqs;
  2736. enabled_irqs = intel_hpd_enabled_irqs(dev, hpd_bxt);
  2737. hotplug_irqs = BXT_DE_PORT_HOTPLUG_MASK;
  2738. bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
  2739. hotplug = I915_READ(PCH_PORT_HOTPLUG);
  2740. hotplug |= PORTC_HOTPLUG_ENABLE | PORTB_HOTPLUG_ENABLE |
  2741. PORTA_HOTPLUG_ENABLE;
  2742. I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
  2743. }
  2744. static void ibx_irq_postinstall(struct drm_device *dev)
  2745. {
  2746. struct drm_i915_private *dev_priv = dev->dev_private;
  2747. u32 mask;
  2748. if (HAS_PCH_NOP(dev))
  2749. return;
  2750. if (HAS_PCH_IBX(dev))
  2751. mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON;
  2752. else
  2753. mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT;
  2754. gen5_assert_iir_is_zero(dev_priv, SDEIIR);
  2755. I915_WRITE(SDEIMR, ~mask);
  2756. }
  2757. static void gen5_gt_irq_postinstall(struct drm_device *dev)
  2758. {
  2759. struct drm_i915_private *dev_priv = dev->dev_private;
  2760. u32 pm_irqs, gt_irqs;
  2761. pm_irqs = gt_irqs = 0;
  2762. dev_priv->gt_irq_mask = ~0;
  2763. if (HAS_L3_DPF(dev)) {
  2764. /* L3 parity interrupt is always unmasked. */
  2765. dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev);
  2766. gt_irqs |= GT_PARITY_ERROR(dev);
  2767. }
  2768. gt_irqs |= GT_RENDER_USER_INTERRUPT;
  2769. if (IS_GEN5(dev)) {
  2770. gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT |
  2771. ILK_BSD_USER_INTERRUPT;
  2772. } else {
  2773. gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
  2774. }
  2775. GEN5_IRQ_INIT(GT, dev_priv->gt_irq_mask, gt_irqs);
  2776. if (INTEL_INFO(dev)->gen >= 6) {
  2777. /*
  2778. * RPS interrupts will get enabled/disabled on demand when RPS
  2779. * itself is enabled/disabled.
  2780. */
  2781. if (HAS_VEBOX(dev))
  2782. pm_irqs |= PM_VEBOX_USER_INTERRUPT;
  2783. dev_priv->pm_irq_mask = 0xffffffff;
  2784. GEN5_IRQ_INIT(GEN6_PM, dev_priv->pm_irq_mask, pm_irqs);
  2785. }
  2786. }
  2787. static int ironlake_irq_postinstall(struct drm_device *dev)
  2788. {
  2789. struct drm_i915_private *dev_priv = dev->dev_private;
  2790. u32 display_mask, extra_mask;
  2791. if (INTEL_INFO(dev)->gen >= 7) {
  2792. display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
  2793. DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB |
  2794. DE_PLANEB_FLIP_DONE_IVB |
  2795. DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB);
  2796. extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
  2797. DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB |
  2798. DE_DP_A_HOTPLUG_IVB);
  2799. } else {
  2800. display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
  2801. DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE |
  2802. DE_AUX_CHANNEL_A |
  2803. DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE |
  2804. DE_POISON);
  2805. extra_mask = (DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT |
  2806. DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN |
  2807. DE_DP_A_HOTPLUG);
  2808. }
  2809. dev_priv->irq_mask = ~display_mask;
  2810. I915_WRITE(HWSTAM, 0xeffe);
  2811. ibx_irq_pre_postinstall(dev);
  2812. GEN5_IRQ_INIT(DE, dev_priv->irq_mask, display_mask | extra_mask);
  2813. gen5_gt_irq_postinstall(dev);
  2814. ibx_irq_postinstall(dev);
  2815. if (IS_IRONLAKE_M(dev)) {
  2816. /* Enable PCU event interrupts
  2817. *
  2818. * spinlocking not required here for correctness since interrupt
  2819. * setup is guaranteed to run in single-threaded context. But we
  2820. * need it to make the assert_spin_locked happy. */
  2821. spin_lock_irq(&dev_priv->irq_lock);
  2822. ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT);
  2823. spin_unlock_irq(&dev_priv->irq_lock);
  2824. }
  2825. return 0;
  2826. }
  2827. static void valleyview_display_irqs_install(struct drm_i915_private *dev_priv)
  2828. {
  2829. u32 pipestat_mask;
  2830. u32 iir_mask;
  2831. enum pipe pipe;
  2832. pipestat_mask = PIPESTAT_INT_STATUS_MASK |
  2833. PIPE_FIFO_UNDERRUN_STATUS;
  2834. for_each_pipe(dev_priv, pipe)
  2835. I915_WRITE(PIPESTAT(pipe), pipestat_mask);
  2836. POSTING_READ(PIPESTAT(PIPE_A));
  2837. pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV |
  2838. PIPE_CRC_DONE_INTERRUPT_STATUS;
  2839. i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
  2840. for_each_pipe(dev_priv, pipe)
  2841. i915_enable_pipestat(dev_priv, pipe, pipestat_mask);
  2842. iir_mask = I915_DISPLAY_PORT_INTERRUPT |
  2843. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  2844. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
  2845. if (IS_CHERRYVIEW(dev_priv))
  2846. iir_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
  2847. dev_priv->irq_mask &= ~iir_mask;
  2848. I915_WRITE(VLV_IIR, iir_mask);
  2849. I915_WRITE(VLV_IIR, iir_mask);
  2850. I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
  2851. I915_WRITE(VLV_IMR, dev_priv->irq_mask);
  2852. POSTING_READ(VLV_IMR);
  2853. }
  2854. static void valleyview_display_irqs_uninstall(struct drm_i915_private *dev_priv)
  2855. {
  2856. u32 pipestat_mask;
  2857. u32 iir_mask;
  2858. enum pipe pipe;
  2859. iir_mask = I915_DISPLAY_PORT_INTERRUPT |
  2860. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  2861. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
  2862. if (IS_CHERRYVIEW(dev_priv))
  2863. iir_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
  2864. dev_priv->irq_mask |= iir_mask;
  2865. I915_WRITE(VLV_IMR, dev_priv->irq_mask);
  2866. I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
  2867. I915_WRITE(VLV_IIR, iir_mask);
  2868. I915_WRITE(VLV_IIR, iir_mask);
  2869. POSTING_READ(VLV_IIR);
  2870. pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV |
  2871. PIPE_CRC_DONE_INTERRUPT_STATUS;
  2872. i915_disable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
  2873. for_each_pipe(dev_priv, pipe)
  2874. i915_disable_pipestat(dev_priv, pipe, pipestat_mask);
  2875. pipestat_mask = PIPESTAT_INT_STATUS_MASK |
  2876. PIPE_FIFO_UNDERRUN_STATUS;
  2877. for_each_pipe(dev_priv, pipe)
  2878. I915_WRITE(PIPESTAT(pipe), pipestat_mask);
  2879. POSTING_READ(PIPESTAT(PIPE_A));
  2880. }
  2881. void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv)
  2882. {
  2883. assert_spin_locked(&dev_priv->irq_lock);
  2884. if (dev_priv->display_irqs_enabled)
  2885. return;
  2886. dev_priv->display_irqs_enabled = true;
  2887. if (intel_irqs_enabled(dev_priv))
  2888. valleyview_display_irqs_install(dev_priv);
  2889. }
  2890. void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv)
  2891. {
  2892. assert_spin_locked(&dev_priv->irq_lock);
  2893. if (!dev_priv->display_irqs_enabled)
  2894. return;
  2895. dev_priv->display_irqs_enabled = false;
  2896. if (intel_irqs_enabled(dev_priv))
  2897. valleyview_display_irqs_uninstall(dev_priv);
  2898. }
  2899. static void vlv_display_irq_postinstall(struct drm_i915_private *dev_priv)
  2900. {
  2901. dev_priv->irq_mask = ~0;
  2902. i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
  2903. POSTING_READ(PORT_HOTPLUG_EN);
  2904. I915_WRITE(VLV_IIR, 0xffffffff);
  2905. I915_WRITE(VLV_IIR, 0xffffffff);
  2906. I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
  2907. I915_WRITE(VLV_IMR, dev_priv->irq_mask);
  2908. POSTING_READ(VLV_IMR);
  2909. /* Interrupt setup is already guaranteed to be single-threaded, this is
  2910. * just to make the assert_spin_locked check happy. */
  2911. spin_lock_irq(&dev_priv->irq_lock);
  2912. if (dev_priv->display_irqs_enabled)
  2913. valleyview_display_irqs_install(dev_priv);
  2914. spin_unlock_irq(&dev_priv->irq_lock);
  2915. }
  2916. static int valleyview_irq_postinstall(struct drm_device *dev)
  2917. {
  2918. struct drm_i915_private *dev_priv = dev->dev_private;
  2919. vlv_display_irq_postinstall(dev_priv);
  2920. gen5_gt_irq_postinstall(dev);
  2921. /* ack & enable invalid PTE error interrupts */
  2922. #if 0 /* FIXME: add support to irq handler for checking these bits */
  2923. I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
  2924. I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK);
  2925. #endif
  2926. I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
  2927. return 0;
  2928. }
  2929. static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)
  2930. {
  2931. /* These are interrupts we'll toggle with the ring mask register */
  2932. uint32_t gt_interrupts[] = {
  2933. GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
  2934. GT_CONTEXT_SWITCH_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
  2935. GT_RENDER_L3_PARITY_ERROR_INTERRUPT |
  2936. GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT |
  2937. GT_CONTEXT_SWITCH_INTERRUPT << GEN8_BCS_IRQ_SHIFT,
  2938. GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
  2939. GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
  2940. GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT |
  2941. GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS2_IRQ_SHIFT,
  2942. 0,
  2943. GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT |
  2944. GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VECS_IRQ_SHIFT
  2945. };
  2946. dev_priv->pm_irq_mask = 0xffffffff;
  2947. GEN8_IRQ_INIT_NDX(GT, 0, ~gt_interrupts[0], gt_interrupts[0]);
  2948. GEN8_IRQ_INIT_NDX(GT, 1, ~gt_interrupts[1], gt_interrupts[1]);
  2949. /*
  2950. * RPS interrupts will get enabled/disabled on demand when RPS itself
  2951. * is enabled/disabled.
  2952. */
  2953. GEN8_IRQ_INIT_NDX(GT, 2, dev_priv->pm_irq_mask, 0);
  2954. GEN8_IRQ_INIT_NDX(GT, 3, ~gt_interrupts[3], gt_interrupts[3]);
  2955. }
  2956. static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
  2957. {
  2958. uint32_t de_pipe_masked = GEN8_PIPE_CDCLK_CRC_DONE;
  2959. uint32_t de_pipe_enables;
  2960. u32 de_port_masked = GEN8_AUX_CHANNEL_A;
  2961. u32 de_port_enables;
  2962. enum pipe pipe;
  2963. if (INTEL_INFO(dev_priv)->gen >= 9) {
  2964. de_pipe_masked |= GEN9_PIPE_PLANE1_FLIP_DONE |
  2965. GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
  2966. de_port_masked |= GEN9_AUX_CHANNEL_B | GEN9_AUX_CHANNEL_C |
  2967. GEN9_AUX_CHANNEL_D;
  2968. if (IS_BROXTON(dev_priv))
  2969. de_port_masked |= BXT_DE_PORT_GMBUS;
  2970. } else {
  2971. de_pipe_masked |= GEN8_PIPE_PRIMARY_FLIP_DONE |
  2972. GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
  2973. }
  2974. de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK |
  2975. GEN8_PIPE_FIFO_UNDERRUN;
  2976. de_port_enables = de_port_masked;
  2977. if (IS_BROXTON(dev_priv))
  2978. de_port_enables |= BXT_DE_PORT_HOTPLUG_MASK;
  2979. else if (IS_BROADWELL(dev_priv))
  2980. de_port_enables |= GEN8_PORT_DP_A_HOTPLUG;
  2981. dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked;
  2982. dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked;
  2983. dev_priv->de_irq_mask[PIPE_C] = ~de_pipe_masked;
  2984. for_each_pipe(dev_priv, pipe)
  2985. if (intel_display_power_is_enabled(dev_priv,
  2986. POWER_DOMAIN_PIPE(pipe)))
  2987. GEN8_IRQ_INIT_NDX(DE_PIPE, pipe,
  2988. dev_priv->de_irq_mask[pipe],
  2989. de_pipe_enables);
  2990. GEN5_IRQ_INIT(GEN8_DE_PORT_, ~de_port_masked, de_port_enables);
  2991. }
  2992. static int gen8_irq_postinstall(struct drm_device *dev)
  2993. {
  2994. struct drm_i915_private *dev_priv = dev->dev_private;
  2995. if (HAS_PCH_SPLIT(dev))
  2996. ibx_irq_pre_postinstall(dev);
  2997. gen8_gt_irq_postinstall(dev_priv);
  2998. gen8_de_irq_postinstall(dev_priv);
  2999. if (HAS_PCH_SPLIT(dev))
  3000. ibx_irq_postinstall(dev);
  3001. I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL);
  3002. POSTING_READ(GEN8_MASTER_IRQ);
  3003. return 0;
  3004. }
  3005. static int cherryview_irq_postinstall(struct drm_device *dev)
  3006. {
  3007. struct drm_i915_private *dev_priv = dev->dev_private;
  3008. vlv_display_irq_postinstall(dev_priv);
  3009. gen8_gt_irq_postinstall(dev_priv);
  3010. I915_WRITE(GEN8_MASTER_IRQ, MASTER_INTERRUPT_ENABLE);
  3011. POSTING_READ(GEN8_MASTER_IRQ);
  3012. return 0;
  3013. }
  3014. static void gen8_irq_uninstall(struct drm_device *dev)
  3015. {
  3016. struct drm_i915_private *dev_priv = dev->dev_private;
  3017. if (!dev_priv)
  3018. return;
  3019. gen8_irq_reset(dev);
  3020. }
  3021. static void vlv_display_irq_uninstall(struct drm_i915_private *dev_priv)
  3022. {
  3023. /* Interrupt setup is already guaranteed to be single-threaded, this is
  3024. * just to make the assert_spin_locked check happy. */
  3025. spin_lock_irq(&dev_priv->irq_lock);
  3026. if (dev_priv->display_irqs_enabled)
  3027. valleyview_display_irqs_uninstall(dev_priv);
  3028. spin_unlock_irq(&dev_priv->irq_lock);
  3029. vlv_display_irq_reset(dev_priv);
  3030. dev_priv->irq_mask = ~0;
  3031. }
  3032. static void valleyview_irq_uninstall(struct drm_device *dev)
  3033. {
  3034. struct drm_i915_private *dev_priv = dev->dev_private;
  3035. if (!dev_priv)
  3036. return;
  3037. I915_WRITE(VLV_MASTER_IER, 0);
  3038. gen5_gt_irq_reset(dev);
  3039. I915_WRITE(HWSTAM, 0xffffffff);
  3040. vlv_display_irq_uninstall(dev_priv);
  3041. }
  3042. static void cherryview_irq_uninstall(struct drm_device *dev)
  3043. {
  3044. struct drm_i915_private *dev_priv = dev->dev_private;
  3045. if (!dev_priv)
  3046. return;
  3047. I915_WRITE(GEN8_MASTER_IRQ, 0);
  3048. POSTING_READ(GEN8_MASTER_IRQ);
  3049. gen8_gt_irq_reset(dev_priv);
  3050. GEN5_IRQ_RESET(GEN8_PCU_);
  3051. vlv_display_irq_uninstall(dev_priv);
  3052. }
  3053. static void ironlake_irq_uninstall(struct drm_device *dev)
  3054. {
  3055. struct drm_i915_private *dev_priv = dev->dev_private;
  3056. if (!dev_priv)
  3057. return;
  3058. ironlake_irq_reset(dev);
  3059. }
  3060. static void i8xx_irq_preinstall(struct drm_device * dev)
  3061. {
  3062. struct drm_i915_private *dev_priv = dev->dev_private;
  3063. int pipe;
  3064. for_each_pipe(dev_priv, pipe)
  3065. I915_WRITE(PIPESTAT(pipe), 0);
  3066. I915_WRITE16(IMR, 0xffff);
  3067. I915_WRITE16(IER, 0x0);
  3068. POSTING_READ16(IER);
  3069. }
  3070. static int i8xx_irq_postinstall(struct drm_device *dev)
  3071. {
  3072. struct drm_i915_private *dev_priv = dev->dev_private;
  3073. I915_WRITE16(EMR,
  3074. ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
  3075. /* Unmask the interrupts that we always want on. */
  3076. dev_priv->irq_mask =
  3077. ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  3078. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  3079. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  3080. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
  3081. I915_WRITE16(IMR, dev_priv->irq_mask);
  3082. I915_WRITE16(IER,
  3083. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  3084. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  3085. I915_USER_INTERRUPT);
  3086. POSTING_READ16(IER);
  3087. /* Interrupt setup is already guaranteed to be single-threaded, this is
  3088. * just to make the assert_spin_locked check happy. */
  3089. spin_lock_irq(&dev_priv->irq_lock);
  3090. i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
  3091. i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
  3092. spin_unlock_irq(&dev_priv->irq_lock);
  3093. return 0;
  3094. }
  3095. /*
  3096. * Returns true when a page flip has completed.
  3097. */
  3098. static bool i8xx_handle_vblank(struct drm_device *dev,
  3099. int plane, int pipe, u32 iir)
  3100. {
  3101. struct drm_i915_private *dev_priv = dev->dev_private;
  3102. u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
  3103. if (!intel_pipe_handle_vblank(dev, pipe))
  3104. return false;
  3105. if ((iir & flip_pending) == 0)
  3106. goto check_page_flip;
  3107. /* We detect FlipDone by looking for the change in PendingFlip from '1'
  3108. * to '0' on the following vblank, i.e. IIR has the Pendingflip
  3109. * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
  3110. * the flip is completed (no longer pending). Since this doesn't raise
  3111. * an interrupt per se, we watch for the change at vblank.
  3112. */
  3113. if (I915_READ16(ISR) & flip_pending)
  3114. goto check_page_flip;
  3115. intel_prepare_page_flip(dev, plane);
  3116. intel_finish_page_flip(dev, pipe);
  3117. return true;
  3118. check_page_flip:
  3119. intel_check_page_flip(dev, pipe);
  3120. return false;
  3121. }
  3122. static irqreturn_t i8xx_irq_handler(int irq, void *arg)
  3123. {
  3124. struct drm_device *dev = arg;
  3125. struct drm_i915_private *dev_priv = dev->dev_private;
  3126. u16 iir, new_iir;
  3127. u32 pipe_stats[2];
  3128. int pipe;
  3129. u16 flip_mask =
  3130. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  3131. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
  3132. if (!intel_irqs_enabled(dev_priv))
  3133. return IRQ_NONE;
  3134. iir = I915_READ16(IIR);
  3135. if (iir == 0)
  3136. return IRQ_NONE;
  3137. while (iir & ~flip_mask) {
  3138. /* Can't rely on pipestat interrupt bit in iir as it might
  3139. * have been cleared after the pipestat interrupt was received.
  3140. * It doesn't set the bit in iir again, but it still produces
  3141. * interrupts (for non-MSI).
  3142. */
  3143. spin_lock(&dev_priv->irq_lock);
  3144. if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
  3145. DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
  3146. for_each_pipe(dev_priv, pipe) {
  3147. int reg = PIPESTAT(pipe);
  3148. pipe_stats[pipe] = I915_READ(reg);
  3149. /*
  3150. * Clear the PIPE*STAT regs before the IIR
  3151. */
  3152. if (pipe_stats[pipe] & 0x8000ffff)
  3153. I915_WRITE(reg, pipe_stats[pipe]);
  3154. }
  3155. spin_unlock(&dev_priv->irq_lock);
  3156. I915_WRITE16(IIR, iir & ~flip_mask);
  3157. new_iir = I915_READ16(IIR); /* Flush posted writes */
  3158. if (iir & I915_USER_INTERRUPT)
  3159. notify_ring(&dev_priv->ring[RCS]);
  3160. for_each_pipe(dev_priv, pipe) {
  3161. int plane = pipe;
  3162. if (HAS_FBC(dev))
  3163. plane = !plane;
  3164. if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
  3165. i8xx_handle_vblank(dev, plane, pipe, iir))
  3166. flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
  3167. if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
  3168. i9xx_pipe_crc_irq_handler(dev, pipe);
  3169. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  3170. intel_cpu_fifo_underrun_irq_handler(dev_priv,
  3171. pipe);
  3172. }
  3173. iir = new_iir;
  3174. }
  3175. return IRQ_HANDLED;
  3176. }
  3177. static void i8xx_irq_uninstall(struct drm_device * dev)
  3178. {
  3179. struct drm_i915_private *dev_priv = dev->dev_private;
  3180. int pipe;
  3181. for_each_pipe(dev_priv, pipe) {
  3182. /* Clear enable bits; then clear status bits */
  3183. I915_WRITE(PIPESTAT(pipe), 0);
  3184. I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
  3185. }
  3186. I915_WRITE16(IMR, 0xffff);
  3187. I915_WRITE16(IER, 0x0);
  3188. I915_WRITE16(IIR, I915_READ16(IIR));
  3189. }
  3190. static void i915_irq_preinstall(struct drm_device * dev)
  3191. {
  3192. struct drm_i915_private *dev_priv = dev->dev_private;
  3193. int pipe;
  3194. if (I915_HAS_HOTPLUG(dev)) {
  3195. i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
  3196. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  3197. }
  3198. I915_WRITE16(HWSTAM, 0xeffe);
  3199. for_each_pipe(dev_priv, pipe)
  3200. I915_WRITE(PIPESTAT(pipe), 0);
  3201. I915_WRITE(IMR, 0xffffffff);
  3202. I915_WRITE(IER, 0x0);
  3203. POSTING_READ(IER);
  3204. }
  3205. static int i915_irq_postinstall(struct drm_device *dev)
  3206. {
  3207. struct drm_i915_private *dev_priv = dev->dev_private;
  3208. u32 enable_mask;
  3209. I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
  3210. /* Unmask the interrupts that we always want on. */
  3211. dev_priv->irq_mask =
  3212. ~(I915_ASLE_INTERRUPT |
  3213. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  3214. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  3215. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  3216. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
  3217. enable_mask =
  3218. I915_ASLE_INTERRUPT |
  3219. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  3220. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  3221. I915_USER_INTERRUPT;
  3222. if (I915_HAS_HOTPLUG(dev)) {
  3223. i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
  3224. POSTING_READ(PORT_HOTPLUG_EN);
  3225. /* Enable in IER... */
  3226. enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
  3227. /* and unmask in IMR */
  3228. dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
  3229. }
  3230. I915_WRITE(IMR, dev_priv->irq_mask);
  3231. I915_WRITE(IER, enable_mask);
  3232. POSTING_READ(IER);
  3233. i915_enable_asle_pipestat(dev);
  3234. /* Interrupt setup is already guaranteed to be single-threaded, this is
  3235. * just to make the assert_spin_locked check happy. */
  3236. spin_lock_irq(&dev_priv->irq_lock);
  3237. i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
  3238. i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
  3239. spin_unlock_irq(&dev_priv->irq_lock);
  3240. return 0;
  3241. }
  3242. /*
  3243. * Returns true when a page flip has completed.
  3244. */
  3245. static bool i915_handle_vblank(struct drm_device *dev,
  3246. int plane, int pipe, u32 iir)
  3247. {
  3248. struct drm_i915_private *dev_priv = dev->dev_private;
  3249. u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
  3250. if (!intel_pipe_handle_vblank(dev, pipe))
  3251. return false;
  3252. if ((iir & flip_pending) == 0)
  3253. goto check_page_flip;
  3254. /* We detect FlipDone by looking for the change in PendingFlip from '1'
  3255. * to '0' on the following vblank, i.e. IIR has the Pendingflip
  3256. * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
  3257. * the flip is completed (no longer pending). Since this doesn't raise
  3258. * an interrupt per se, we watch for the change at vblank.
  3259. */
  3260. if (I915_READ(ISR) & flip_pending)
  3261. goto check_page_flip;
  3262. intel_prepare_page_flip(dev, plane);
  3263. intel_finish_page_flip(dev, pipe);
  3264. return true;
  3265. check_page_flip:
  3266. intel_check_page_flip(dev, pipe);
  3267. return false;
  3268. }
  3269. static irqreturn_t i915_irq_handler(int irq, void *arg)
  3270. {
  3271. struct drm_device *dev = arg;
  3272. struct drm_i915_private *dev_priv = dev->dev_private;
  3273. u32 iir, new_iir, pipe_stats[I915_MAX_PIPES];
  3274. u32 flip_mask =
  3275. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  3276. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
  3277. int pipe, ret = IRQ_NONE;
  3278. if (!intel_irqs_enabled(dev_priv))
  3279. return IRQ_NONE;
  3280. iir = I915_READ(IIR);
  3281. do {
  3282. bool irq_received = (iir & ~flip_mask) != 0;
  3283. bool blc_event = false;
  3284. /* Can't rely on pipestat interrupt bit in iir as it might
  3285. * have been cleared after the pipestat interrupt was received.
  3286. * It doesn't set the bit in iir again, but it still produces
  3287. * interrupts (for non-MSI).
  3288. */
  3289. spin_lock(&dev_priv->irq_lock);
  3290. if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
  3291. DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
  3292. for_each_pipe(dev_priv, pipe) {
  3293. int reg = PIPESTAT(pipe);
  3294. pipe_stats[pipe] = I915_READ(reg);
  3295. /* Clear the PIPE*STAT regs before the IIR */
  3296. if (pipe_stats[pipe] & 0x8000ffff) {
  3297. I915_WRITE(reg, pipe_stats[pipe]);
  3298. irq_received = true;
  3299. }
  3300. }
  3301. spin_unlock(&dev_priv->irq_lock);
  3302. if (!irq_received)
  3303. break;
  3304. /* Consume port. Then clear IIR or we'll miss events */
  3305. if (I915_HAS_HOTPLUG(dev) &&
  3306. iir & I915_DISPLAY_PORT_INTERRUPT)
  3307. i9xx_hpd_irq_handler(dev);
  3308. I915_WRITE(IIR, iir & ~flip_mask);
  3309. new_iir = I915_READ(IIR); /* Flush posted writes */
  3310. if (iir & I915_USER_INTERRUPT)
  3311. notify_ring(&dev_priv->ring[RCS]);
  3312. for_each_pipe(dev_priv, pipe) {
  3313. int plane = pipe;
  3314. if (HAS_FBC(dev))
  3315. plane = !plane;
  3316. if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
  3317. i915_handle_vblank(dev, plane, pipe, iir))
  3318. flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
  3319. if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
  3320. blc_event = true;
  3321. if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
  3322. i9xx_pipe_crc_irq_handler(dev, pipe);
  3323. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  3324. intel_cpu_fifo_underrun_irq_handler(dev_priv,
  3325. pipe);
  3326. }
  3327. if (blc_event || (iir & I915_ASLE_INTERRUPT))
  3328. intel_opregion_asle_intr(dev);
  3329. /* With MSI, interrupts are only generated when iir
  3330. * transitions from zero to nonzero. If another bit got
  3331. * set while we were handling the existing iir bits, then
  3332. * we would never get another interrupt.
  3333. *
  3334. * This is fine on non-MSI as well, as if we hit this path
  3335. * we avoid exiting the interrupt handler only to generate
  3336. * another one.
  3337. *
  3338. * Note that for MSI this could cause a stray interrupt report
  3339. * if an interrupt landed in the time between writing IIR and
  3340. * the posting read. This should be rare enough to never
  3341. * trigger the 99% of 100,000 interrupts test for disabling
  3342. * stray interrupts.
  3343. */
  3344. ret = IRQ_HANDLED;
  3345. iir = new_iir;
  3346. } while (iir & ~flip_mask);
  3347. return ret;
  3348. }
  3349. static void i915_irq_uninstall(struct drm_device * dev)
  3350. {
  3351. struct drm_i915_private *dev_priv = dev->dev_private;
  3352. int pipe;
  3353. if (I915_HAS_HOTPLUG(dev)) {
  3354. i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
  3355. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  3356. }
  3357. I915_WRITE16(HWSTAM, 0xffff);
  3358. for_each_pipe(dev_priv, pipe) {
  3359. /* Clear enable bits; then clear status bits */
  3360. I915_WRITE(PIPESTAT(pipe), 0);
  3361. I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
  3362. }
  3363. I915_WRITE(IMR, 0xffffffff);
  3364. I915_WRITE(IER, 0x0);
  3365. I915_WRITE(IIR, I915_READ(IIR));
  3366. }
  3367. static void i965_irq_preinstall(struct drm_device * dev)
  3368. {
  3369. struct drm_i915_private *dev_priv = dev->dev_private;
  3370. int pipe;
  3371. i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
  3372. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  3373. I915_WRITE(HWSTAM, 0xeffe);
  3374. for_each_pipe(dev_priv, pipe)
  3375. I915_WRITE(PIPESTAT(pipe), 0);
  3376. I915_WRITE(IMR, 0xffffffff);
  3377. I915_WRITE(IER, 0x0);
  3378. POSTING_READ(IER);
  3379. }
  3380. static int i965_irq_postinstall(struct drm_device *dev)
  3381. {
  3382. struct drm_i915_private *dev_priv = dev->dev_private;
  3383. u32 enable_mask;
  3384. u32 error_mask;
  3385. /* Unmask the interrupts that we always want on. */
  3386. dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT |
  3387. I915_DISPLAY_PORT_INTERRUPT |
  3388. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  3389. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  3390. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  3391. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
  3392. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  3393. enable_mask = ~dev_priv->irq_mask;
  3394. enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  3395. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
  3396. enable_mask |= I915_USER_INTERRUPT;
  3397. if (IS_G4X(dev))
  3398. enable_mask |= I915_BSD_USER_INTERRUPT;
  3399. /* Interrupt setup is already guaranteed to be single-threaded, this is
  3400. * just to make the assert_spin_locked check happy. */
  3401. spin_lock_irq(&dev_priv->irq_lock);
  3402. i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
  3403. i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
  3404. i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
  3405. spin_unlock_irq(&dev_priv->irq_lock);
  3406. /*
  3407. * Enable some error detection, note the instruction error mask
  3408. * bit is reserved, so we leave it masked.
  3409. */
  3410. if (IS_G4X(dev)) {
  3411. error_mask = ~(GM45_ERROR_PAGE_TABLE |
  3412. GM45_ERROR_MEM_PRIV |
  3413. GM45_ERROR_CP_PRIV |
  3414. I915_ERROR_MEMORY_REFRESH);
  3415. } else {
  3416. error_mask = ~(I915_ERROR_PAGE_TABLE |
  3417. I915_ERROR_MEMORY_REFRESH);
  3418. }
  3419. I915_WRITE(EMR, error_mask);
  3420. I915_WRITE(IMR, dev_priv->irq_mask);
  3421. I915_WRITE(IER, enable_mask);
  3422. POSTING_READ(IER);
  3423. i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
  3424. POSTING_READ(PORT_HOTPLUG_EN);
  3425. i915_enable_asle_pipestat(dev);
  3426. return 0;
  3427. }
  3428. static void i915_hpd_irq_setup(struct drm_device *dev)
  3429. {
  3430. struct drm_i915_private *dev_priv = dev->dev_private;
  3431. u32 hotplug_en;
  3432. assert_spin_locked(&dev_priv->irq_lock);
  3433. /* Note HDMI and DP share hotplug bits */
  3434. /* enable bits are the same for all generations */
  3435. hotplug_en = intel_hpd_enabled_irqs(dev, hpd_mask_i915);
  3436. /* Programming the CRT detection parameters tends
  3437. to generate a spurious hotplug event about three
  3438. seconds later. So just do it once.
  3439. */
  3440. if (IS_G4X(dev))
  3441. hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
  3442. hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
  3443. /* Ignore TV since it's buggy */
  3444. i915_hotplug_interrupt_update_locked(dev_priv,
  3445. HOTPLUG_INT_EN_MASK |
  3446. CRT_HOTPLUG_VOLTAGE_COMPARE_MASK |
  3447. CRT_HOTPLUG_ACTIVATION_PERIOD_64,
  3448. hotplug_en);
  3449. }
  3450. static irqreturn_t i965_irq_handler(int irq, void *arg)
  3451. {
  3452. struct drm_device *dev = arg;
  3453. struct drm_i915_private *dev_priv = dev->dev_private;
  3454. u32 iir, new_iir;
  3455. u32 pipe_stats[I915_MAX_PIPES];
  3456. int ret = IRQ_NONE, pipe;
  3457. u32 flip_mask =
  3458. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  3459. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
  3460. if (!intel_irqs_enabled(dev_priv))
  3461. return IRQ_NONE;
  3462. iir = I915_READ(IIR);
  3463. for (;;) {
  3464. bool irq_received = (iir & ~flip_mask) != 0;
  3465. bool blc_event = false;
  3466. /* Can't rely on pipestat interrupt bit in iir as it might
  3467. * have been cleared after the pipestat interrupt was received.
  3468. * It doesn't set the bit in iir again, but it still produces
  3469. * interrupts (for non-MSI).
  3470. */
  3471. spin_lock(&dev_priv->irq_lock);
  3472. if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
  3473. DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
  3474. for_each_pipe(dev_priv, pipe) {
  3475. int reg = PIPESTAT(pipe);
  3476. pipe_stats[pipe] = I915_READ(reg);
  3477. /*
  3478. * Clear the PIPE*STAT regs before the IIR
  3479. */
  3480. if (pipe_stats[pipe] & 0x8000ffff) {
  3481. I915_WRITE(reg, pipe_stats[pipe]);
  3482. irq_received = true;
  3483. }
  3484. }
  3485. spin_unlock(&dev_priv->irq_lock);
  3486. if (!irq_received)
  3487. break;
  3488. ret = IRQ_HANDLED;
  3489. /* Consume port. Then clear IIR or we'll miss events */
  3490. if (iir & I915_DISPLAY_PORT_INTERRUPT)
  3491. i9xx_hpd_irq_handler(dev);
  3492. I915_WRITE(IIR, iir & ~flip_mask);
  3493. new_iir = I915_READ(IIR); /* Flush posted writes */
  3494. if (iir & I915_USER_INTERRUPT)
  3495. notify_ring(&dev_priv->ring[RCS]);
  3496. if (iir & I915_BSD_USER_INTERRUPT)
  3497. notify_ring(&dev_priv->ring[VCS]);
  3498. for_each_pipe(dev_priv, pipe) {
  3499. if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
  3500. i915_handle_vblank(dev, pipe, pipe, iir))
  3501. flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe);
  3502. if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
  3503. blc_event = true;
  3504. if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
  3505. i9xx_pipe_crc_irq_handler(dev, pipe);
  3506. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  3507. intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
  3508. }
  3509. if (blc_event || (iir & I915_ASLE_INTERRUPT))
  3510. intel_opregion_asle_intr(dev);
  3511. if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
  3512. gmbus_irq_handler(dev);
  3513. /* With MSI, interrupts are only generated when iir
  3514. * transitions from zero to nonzero. If another bit got
  3515. * set while we were handling the existing iir bits, then
  3516. * we would never get another interrupt.
  3517. *
  3518. * This is fine on non-MSI as well, as if we hit this path
  3519. * we avoid exiting the interrupt handler only to generate
  3520. * another one.
  3521. *
  3522. * Note that for MSI this could cause a stray interrupt report
  3523. * if an interrupt landed in the time between writing IIR and
  3524. * the posting read. This should be rare enough to never
  3525. * trigger the 99% of 100,000 interrupts test for disabling
  3526. * stray interrupts.
  3527. */
  3528. iir = new_iir;
  3529. }
  3530. return ret;
  3531. }
  3532. static void i965_irq_uninstall(struct drm_device * dev)
  3533. {
  3534. struct drm_i915_private *dev_priv = dev->dev_private;
  3535. int pipe;
  3536. if (!dev_priv)
  3537. return;
  3538. i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
  3539. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  3540. I915_WRITE(HWSTAM, 0xffffffff);
  3541. for_each_pipe(dev_priv, pipe)
  3542. I915_WRITE(PIPESTAT(pipe), 0);
  3543. I915_WRITE(IMR, 0xffffffff);
  3544. I915_WRITE(IER, 0x0);
  3545. for_each_pipe(dev_priv, pipe)
  3546. I915_WRITE(PIPESTAT(pipe),
  3547. I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
  3548. I915_WRITE(IIR, I915_READ(IIR));
  3549. }
  3550. /**
  3551. * intel_irq_init - initializes irq support
  3552. * @dev_priv: i915 device instance
  3553. *
  3554. * This function initializes all the irq support including work items, timers
  3555. * and all the vtables. It does not setup the interrupt itself though.
  3556. */
  3557. void intel_irq_init(struct drm_i915_private *dev_priv)
  3558. {
  3559. struct drm_device *dev = dev_priv->dev;
  3560. intel_hpd_init_work(dev_priv);
  3561. INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
  3562. INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
  3563. /* Let's track the enabled rps events */
  3564. if (IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv))
  3565. /* WaGsvRC0ResidencyMethod:vlv */
  3566. dev_priv->pm_rps_events = GEN6_PM_RP_UP_EI_EXPIRED;
  3567. else
  3568. dev_priv->pm_rps_events = GEN6_PM_RPS_EVENTS;
  3569. INIT_DELAYED_WORK(&dev_priv->gpu_error.hangcheck_work,
  3570. i915_hangcheck_elapsed);
  3571. pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);
  3572. if (IS_GEN2(dev_priv)) {
  3573. dev->max_vblank_count = 0;
  3574. dev->driver->get_vblank_counter = i8xx_get_vblank_counter;
  3575. } else if (IS_G4X(dev_priv) || INTEL_INFO(dev_priv)->gen >= 5) {
  3576. dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
  3577. dev->driver->get_vblank_counter = g4x_get_vblank_counter;
  3578. } else {
  3579. dev->driver->get_vblank_counter = i915_get_vblank_counter;
  3580. dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
  3581. }
  3582. /*
  3583. * Opt out of the vblank disable timer on everything except gen2.
  3584. * Gen2 doesn't have a hardware frame counter and so depends on
  3585. * vblank interrupts to produce sane vblank seuquence numbers.
  3586. */
  3587. if (!IS_GEN2(dev_priv))
  3588. dev->vblank_disable_immediate = true;
  3589. dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
  3590. dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
  3591. if (IS_CHERRYVIEW(dev_priv)) {
  3592. dev->driver->irq_handler = cherryview_irq_handler;
  3593. dev->driver->irq_preinstall = cherryview_irq_preinstall;
  3594. dev->driver->irq_postinstall = cherryview_irq_postinstall;
  3595. dev->driver->irq_uninstall = cherryview_irq_uninstall;
  3596. dev->driver->enable_vblank = valleyview_enable_vblank;
  3597. dev->driver->disable_vblank = valleyview_disable_vblank;
  3598. dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
  3599. } else if (IS_VALLEYVIEW(dev_priv)) {
  3600. dev->driver->irq_handler = valleyview_irq_handler;
  3601. dev->driver->irq_preinstall = valleyview_irq_preinstall;
  3602. dev->driver->irq_postinstall = valleyview_irq_postinstall;
  3603. dev->driver->irq_uninstall = valleyview_irq_uninstall;
  3604. dev->driver->enable_vblank = valleyview_enable_vblank;
  3605. dev->driver->disable_vblank = valleyview_disable_vblank;
  3606. dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
  3607. } else if (INTEL_INFO(dev_priv)->gen >= 8) {
  3608. dev->driver->irq_handler = gen8_irq_handler;
  3609. dev->driver->irq_preinstall = gen8_irq_reset;
  3610. dev->driver->irq_postinstall = gen8_irq_postinstall;
  3611. dev->driver->irq_uninstall = gen8_irq_uninstall;
  3612. dev->driver->enable_vblank = gen8_enable_vblank;
  3613. dev->driver->disable_vblank = gen8_disable_vblank;
  3614. if (IS_BROXTON(dev))
  3615. dev_priv->display.hpd_irq_setup = bxt_hpd_irq_setup;
  3616. else if (HAS_PCH_SPT(dev))
  3617. dev_priv->display.hpd_irq_setup = spt_hpd_irq_setup;
  3618. else
  3619. dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup;
  3620. } else if (HAS_PCH_SPLIT(dev)) {
  3621. dev->driver->irq_handler = ironlake_irq_handler;
  3622. dev->driver->irq_preinstall = ironlake_irq_reset;
  3623. dev->driver->irq_postinstall = ironlake_irq_postinstall;
  3624. dev->driver->irq_uninstall = ironlake_irq_uninstall;
  3625. dev->driver->enable_vblank = ironlake_enable_vblank;
  3626. dev->driver->disable_vblank = ironlake_disable_vblank;
  3627. dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup;
  3628. } else {
  3629. if (INTEL_INFO(dev_priv)->gen == 2) {
  3630. dev->driver->irq_preinstall = i8xx_irq_preinstall;
  3631. dev->driver->irq_postinstall = i8xx_irq_postinstall;
  3632. dev->driver->irq_handler = i8xx_irq_handler;
  3633. dev->driver->irq_uninstall = i8xx_irq_uninstall;
  3634. } else if (INTEL_INFO(dev_priv)->gen == 3) {
  3635. dev->driver->irq_preinstall = i915_irq_preinstall;
  3636. dev->driver->irq_postinstall = i915_irq_postinstall;
  3637. dev->driver->irq_uninstall = i915_irq_uninstall;
  3638. dev->driver->irq_handler = i915_irq_handler;
  3639. } else {
  3640. dev->driver->irq_preinstall = i965_irq_preinstall;
  3641. dev->driver->irq_postinstall = i965_irq_postinstall;
  3642. dev->driver->irq_uninstall = i965_irq_uninstall;
  3643. dev->driver->irq_handler = i965_irq_handler;
  3644. }
  3645. if (I915_HAS_HOTPLUG(dev_priv))
  3646. dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
  3647. dev->driver->enable_vblank = i915_enable_vblank;
  3648. dev->driver->disable_vblank = i915_disable_vblank;
  3649. }
  3650. }
  3651. /**
  3652. * intel_irq_install - enables the hardware interrupt
  3653. * @dev_priv: i915 device instance
  3654. *
  3655. * This function enables the hardware interrupt handling, but leaves the hotplug
  3656. * handling still disabled. It is called after intel_irq_init().
  3657. *
  3658. * In the driver load and resume code we need working interrupts in a few places
  3659. * but don't want to deal with the hassle of concurrent probe and hotplug
  3660. * workers. Hence the split into this two-stage approach.
  3661. */
  3662. int intel_irq_install(struct drm_i915_private *dev_priv)
  3663. {
  3664. /*
  3665. * We enable some interrupt sources in our postinstall hooks, so mark
  3666. * interrupts as enabled _before_ actually enabling them to avoid
  3667. * special cases in our ordering checks.
  3668. */
  3669. dev_priv->pm.irqs_enabled = true;
  3670. return drm_irq_install(dev_priv->dev, dev_priv->dev->pdev->irq);
  3671. }
  3672. /**
  3673. * intel_irq_uninstall - finilizes all irq handling
  3674. * @dev_priv: i915 device instance
  3675. *
  3676. * This stops interrupt and hotplug handling and unregisters and frees all
  3677. * resources acquired in the init functions.
  3678. */
  3679. void intel_irq_uninstall(struct drm_i915_private *dev_priv)
  3680. {
  3681. drm_irq_uninstall(dev_priv->dev);
  3682. intel_hpd_cancel_work(dev_priv);
  3683. dev_priv->pm.irqs_enabled = false;
  3684. }
  3685. /**
  3686. * intel_runtime_pm_disable_interrupts - runtime interrupt disabling
  3687. * @dev_priv: i915 device instance
  3688. *
  3689. * This function is used to disable interrupts at runtime, both in the runtime
  3690. * pm and the system suspend/resume code.
  3691. */
  3692. void intel_runtime_pm_disable_interrupts(struct drm_i915_private *dev_priv)
  3693. {
  3694. dev_priv->dev->driver->irq_uninstall(dev_priv->dev);
  3695. dev_priv->pm.irqs_enabled = false;
  3696. synchronize_irq(dev_priv->dev->irq);
  3697. }
  3698. /**
  3699. * intel_runtime_pm_enable_interrupts - runtime interrupt enabling
  3700. * @dev_priv: i915 device instance
  3701. *
  3702. * This function is used to enable interrupts at runtime, both in the runtime
  3703. * pm and the system suspend/resume code.
  3704. */
  3705. void intel_runtime_pm_enable_interrupts(struct drm_i915_private *dev_priv)
  3706. {
  3707. dev_priv->pm.irqs_enabled = true;
  3708. dev_priv->dev->driver->irq_preinstall(dev_priv->dev);
  3709. dev_priv->dev->driver->irq_postinstall(dev_priv->dev);
  3710. }