i915_irq.c 127 KB

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