i915_irq.c 128 KB

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