i915_irq.c 127 KB

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