i915_irq.c 131 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648
  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/circ_buf.h>
  30. #include <linux/slab.h>
  31. #include <linux/sysrq.h>
  32. #include <drm/drm_drv.h>
  33. #include "display/icl_dsi_regs.h"
  34. #include "display/intel_de.h"
  35. #include "display/intel_display_trace.h"
  36. #include "display/intel_display_types.h"
  37. #include "display/intel_fifo_underrun.h"
  38. #include "display/intel_hotplug.h"
  39. #include "display/intel_lpe_audio.h"
  40. #include "display/intel_psr.h"
  41. #include "gt/intel_breadcrumbs.h"
  42. #include "gt/intel_gt.h"
  43. #include "gt/intel_gt_irq.h"
  44. #include "gt/intel_gt_pm_irq.h"
  45. #include "gt/intel_gt_regs.h"
  46. #include "gt/intel_rps.h"
  47. #include "i915_driver.h"
  48. #include "i915_drv.h"
  49. #include "i915_irq.h"
  50. #include "intel_pm.h"
  51. /**
  52. * DOC: interrupt handling
  53. *
  54. * These functions provide the basic support for enabling and disabling the
  55. * interrupt handling support. There's a lot more functionality in i915_irq.c
  56. * and related files, but that will be described in separate chapters.
  57. */
  58. /*
  59. * Interrupt statistic for PMU. Increments the counter only if the
  60. * interrupt originated from the GPU so interrupts from a device which
  61. * shares the interrupt line are not accounted.
  62. */
  63. static inline void pmu_irq_stats(struct drm_i915_private *i915,
  64. irqreturn_t res)
  65. {
  66. if (unlikely(res != IRQ_HANDLED))
  67. return;
  68. /*
  69. * A clever compiler translates that into INC. A not so clever one
  70. * should at least prevent store tearing.
  71. */
  72. WRITE_ONCE(i915->pmu.irq_count, i915->pmu.irq_count + 1);
  73. }
  74. typedef bool (*long_pulse_detect_func)(enum hpd_pin pin, u32 val);
  75. typedef u32 (*hotplug_enables_func)(struct drm_i915_private *i915,
  76. enum hpd_pin pin);
  77. static const u32 hpd_ilk[HPD_NUM_PINS] = {
  78. [HPD_PORT_A] = DE_DP_A_HOTPLUG,
  79. };
  80. static const u32 hpd_ivb[HPD_NUM_PINS] = {
  81. [HPD_PORT_A] = DE_DP_A_HOTPLUG_IVB,
  82. };
  83. static const u32 hpd_bdw[HPD_NUM_PINS] = {
  84. [HPD_PORT_A] = GEN8_DE_PORT_HOTPLUG(HPD_PORT_A),
  85. };
  86. static const u32 hpd_ibx[HPD_NUM_PINS] = {
  87. [HPD_CRT] = SDE_CRT_HOTPLUG,
  88. [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG,
  89. [HPD_PORT_B] = SDE_PORTB_HOTPLUG,
  90. [HPD_PORT_C] = SDE_PORTC_HOTPLUG,
  91. [HPD_PORT_D] = SDE_PORTD_HOTPLUG,
  92. };
  93. static const u32 hpd_cpt[HPD_NUM_PINS] = {
  94. [HPD_CRT] = SDE_CRT_HOTPLUG_CPT,
  95. [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG_CPT,
  96. [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT,
  97. [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT,
  98. [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT,
  99. };
  100. static const u32 hpd_spt[HPD_NUM_PINS] = {
  101. [HPD_PORT_A] = SDE_PORTA_HOTPLUG_SPT,
  102. [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT,
  103. [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT,
  104. [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT,
  105. [HPD_PORT_E] = SDE_PORTE_HOTPLUG_SPT,
  106. };
  107. static const u32 hpd_mask_i915[HPD_NUM_PINS] = {
  108. [HPD_CRT] = CRT_HOTPLUG_INT_EN,
  109. [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_EN,
  110. [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_EN,
  111. [HPD_PORT_B] = PORTB_HOTPLUG_INT_EN,
  112. [HPD_PORT_C] = PORTC_HOTPLUG_INT_EN,
  113. [HPD_PORT_D] = PORTD_HOTPLUG_INT_EN,
  114. };
  115. static const u32 hpd_status_g4x[HPD_NUM_PINS] = {
  116. [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
  117. [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_G4X,
  118. [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_G4X,
  119. [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
  120. [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
  121. [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS,
  122. };
  123. static const u32 hpd_status_i915[HPD_NUM_PINS] = {
  124. [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
  125. [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_I915,
  126. [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_I915,
  127. [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
  128. [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
  129. [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS,
  130. };
  131. static const u32 hpd_bxt[HPD_NUM_PINS] = {
  132. [HPD_PORT_A] = GEN8_DE_PORT_HOTPLUG(HPD_PORT_A),
  133. [HPD_PORT_B] = GEN8_DE_PORT_HOTPLUG(HPD_PORT_B),
  134. [HPD_PORT_C] = GEN8_DE_PORT_HOTPLUG(HPD_PORT_C),
  135. };
  136. static const u32 hpd_gen11[HPD_NUM_PINS] = {
  137. [HPD_PORT_TC1] = GEN11_TC_HOTPLUG(HPD_PORT_TC1) | GEN11_TBT_HOTPLUG(HPD_PORT_TC1),
  138. [HPD_PORT_TC2] = GEN11_TC_HOTPLUG(HPD_PORT_TC2) | GEN11_TBT_HOTPLUG(HPD_PORT_TC2),
  139. [HPD_PORT_TC3] = GEN11_TC_HOTPLUG(HPD_PORT_TC3) | GEN11_TBT_HOTPLUG(HPD_PORT_TC3),
  140. [HPD_PORT_TC4] = GEN11_TC_HOTPLUG(HPD_PORT_TC4) | GEN11_TBT_HOTPLUG(HPD_PORT_TC4),
  141. [HPD_PORT_TC5] = GEN11_TC_HOTPLUG(HPD_PORT_TC5) | GEN11_TBT_HOTPLUG(HPD_PORT_TC5),
  142. [HPD_PORT_TC6] = GEN11_TC_HOTPLUG(HPD_PORT_TC6) | GEN11_TBT_HOTPLUG(HPD_PORT_TC6),
  143. };
  144. static const u32 hpd_icp[HPD_NUM_PINS] = {
  145. [HPD_PORT_A] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_A),
  146. [HPD_PORT_B] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_B),
  147. [HPD_PORT_C] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_C),
  148. [HPD_PORT_TC1] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC1),
  149. [HPD_PORT_TC2] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC2),
  150. [HPD_PORT_TC3] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC3),
  151. [HPD_PORT_TC4] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC4),
  152. [HPD_PORT_TC5] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC5),
  153. [HPD_PORT_TC6] = SDE_TC_HOTPLUG_ICP(HPD_PORT_TC6),
  154. };
  155. static const u32 hpd_sde_dg1[HPD_NUM_PINS] = {
  156. [HPD_PORT_A] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_A),
  157. [HPD_PORT_B] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_B),
  158. [HPD_PORT_C] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_C),
  159. [HPD_PORT_D] = SDE_DDI_HOTPLUG_ICP(HPD_PORT_D),
  160. [HPD_PORT_TC1] = SDE_TC_HOTPLUG_DG2(HPD_PORT_TC1),
  161. };
  162. static void intel_hpd_init_pins(struct drm_i915_private *dev_priv)
  163. {
  164. struct intel_hotplug *hpd = &dev_priv->display.hotplug;
  165. if (HAS_GMCH(dev_priv)) {
  166. if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
  167. IS_CHERRYVIEW(dev_priv))
  168. hpd->hpd = hpd_status_g4x;
  169. else
  170. hpd->hpd = hpd_status_i915;
  171. return;
  172. }
  173. if (DISPLAY_VER(dev_priv) >= 11)
  174. hpd->hpd = hpd_gen11;
  175. else if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
  176. hpd->hpd = hpd_bxt;
  177. else if (DISPLAY_VER(dev_priv) >= 8)
  178. hpd->hpd = hpd_bdw;
  179. else if (DISPLAY_VER(dev_priv) >= 7)
  180. hpd->hpd = hpd_ivb;
  181. else
  182. hpd->hpd = hpd_ilk;
  183. if ((INTEL_PCH_TYPE(dev_priv) < PCH_DG1) &&
  184. (!HAS_PCH_SPLIT(dev_priv) || HAS_PCH_NOP(dev_priv)))
  185. return;
  186. if (INTEL_PCH_TYPE(dev_priv) >= PCH_DG1)
  187. hpd->pch_hpd = hpd_sde_dg1;
  188. else if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
  189. hpd->pch_hpd = hpd_icp;
  190. else if (HAS_PCH_CNP(dev_priv) || HAS_PCH_SPT(dev_priv))
  191. hpd->pch_hpd = hpd_spt;
  192. else if (HAS_PCH_LPT(dev_priv) || HAS_PCH_CPT(dev_priv))
  193. hpd->pch_hpd = hpd_cpt;
  194. else if (HAS_PCH_IBX(dev_priv))
  195. hpd->pch_hpd = hpd_ibx;
  196. else
  197. MISSING_CASE(INTEL_PCH_TYPE(dev_priv));
  198. }
  199. static void
  200. intel_handle_vblank(struct drm_i915_private *dev_priv, enum pipe pipe)
  201. {
  202. struct intel_crtc *crtc = intel_crtc_for_pipe(dev_priv, pipe);
  203. drm_crtc_handle_vblank(&crtc->base);
  204. }
  205. void gen3_irq_reset(struct intel_uncore *uncore, i915_reg_t imr,
  206. i915_reg_t iir, i915_reg_t ier)
  207. {
  208. intel_uncore_write(uncore, imr, 0xffffffff);
  209. intel_uncore_posting_read(uncore, imr);
  210. intel_uncore_write(uncore, ier, 0);
  211. /* IIR can theoretically queue up two events. Be paranoid. */
  212. intel_uncore_write(uncore, iir, 0xffffffff);
  213. intel_uncore_posting_read(uncore, iir);
  214. intel_uncore_write(uncore, iir, 0xffffffff);
  215. intel_uncore_posting_read(uncore, iir);
  216. }
  217. void gen2_irq_reset(struct intel_uncore *uncore)
  218. {
  219. intel_uncore_write16(uncore, GEN2_IMR, 0xffff);
  220. intel_uncore_posting_read16(uncore, GEN2_IMR);
  221. intel_uncore_write16(uncore, GEN2_IER, 0);
  222. /* IIR can theoretically queue up two events. Be paranoid. */
  223. intel_uncore_write16(uncore, GEN2_IIR, 0xffff);
  224. intel_uncore_posting_read16(uncore, GEN2_IIR);
  225. intel_uncore_write16(uncore, GEN2_IIR, 0xffff);
  226. intel_uncore_posting_read16(uncore, GEN2_IIR);
  227. }
  228. /*
  229. * We should clear IMR at preinstall/uninstall, and just check at postinstall.
  230. */
  231. static void gen3_assert_iir_is_zero(struct intel_uncore *uncore, i915_reg_t reg)
  232. {
  233. u32 val = intel_uncore_read(uncore, reg);
  234. if (val == 0)
  235. return;
  236. drm_WARN(&uncore->i915->drm, 1,
  237. "Interrupt register 0x%x is not zero: 0x%08x\n",
  238. i915_mmio_reg_offset(reg), val);
  239. intel_uncore_write(uncore, reg, 0xffffffff);
  240. intel_uncore_posting_read(uncore, reg);
  241. intel_uncore_write(uncore, reg, 0xffffffff);
  242. intel_uncore_posting_read(uncore, reg);
  243. }
  244. static void gen2_assert_iir_is_zero(struct intel_uncore *uncore)
  245. {
  246. u16 val = intel_uncore_read16(uncore, GEN2_IIR);
  247. if (val == 0)
  248. return;
  249. drm_WARN(&uncore->i915->drm, 1,
  250. "Interrupt register 0x%x is not zero: 0x%08x\n",
  251. i915_mmio_reg_offset(GEN2_IIR), val);
  252. intel_uncore_write16(uncore, GEN2_IIR, 0xffff);
  253. intel_uncore_posting_read16(uncore, GEN2_IIR);
  254. intel_uncore_write16(uncore, GEN2_IIR, 0xffff);
  255. intel_uncore_posting_read16(uncore, GEN2_IIR);
  256. }
  257. void gen3_irq_init(struct intel_uncore *uncore,
  258. i915_reg_t imr, u32 imr_val,
  259. i915_reg_t ier, u32 ier_val,
  260. i915_reg_t iir)
  261. {
  262. gen3_assert_iir_is_zero(uncore, iir);
  263. intel_uncore_write(uncore, ier, ier_val);
  264. intel_uncore_write(uncore, imr, imr_val);
  265. intel_uncore_posting_read(uncore, imr);
  266. }
  267. void gen2_irq_init(struct intel_uncore *uncore,
  268. u32 imr_val, u32 ier_val)
  269. {
  270. gen2_assert_iir_is_zero(uncore);
  271. intel_uncore_write16(uncore, GEN2_IER, ier_val);
  272. intel_uncore_write16(uncore, GEN2_IMR, imr_val);
  273. intel_uncore_posting_read16(uncore, GEN2_IMR);
  274. }
  275. /* For display hotplug interrupt */
  276. static inline void
  277. i915_hotplug_interrupt_update_locked(struct drm_i915_private *dev_priv,
  278. u32 mask,
  279. u32 bits)
  280. {
  281. u32 val;
  282. lockdep_assert_held(&dev_priv->irq_lock);
  283. drm_WARN_ON(&dev_priv->drm, bits & ~mask);
  284. val = intel_uncore_read(&dev_priv->uncore, PORT_HOTPLUG_EN);
  285. val &= ~mask;
  286. val |= bits;
  287. intel_uncore_write(&dev_priv->uncore, PORT_HOTPLUG_EN, val);
  288. }
  289. /**
  290. * i915_hotplug_interrupt_update - update hotplug interrupt enable
  291. * @dev_priv: driver private
  292. * @mask: bits to update
  293. * @bits: bits to enable
  294. * NOTE: the HPD enable bits are modified both inside and outside
  295. * of an interrupt context. To avoid that read-modify-write cycles
  296. * interfer, these bits are protected by a spinlock. Since this
  297. * function is usually not called from a context where the lock is
  298. * held already, this function acquires the lock itself. A non-locking
  299. * version is also available.
  300. */
  301. void i915_hotplug_interrupt_update(struct drm_i915_private *dev_priv,
  302. u32 mask,
  303. u32 bits)
  304. {
  305. spin_lock_irq(&dev_priv->irq_lock);
  306. i915_hotplug_interrupt_update_locked(dev_priv, mask, bits);
  307. spin_unlock_irq(&dev_priv->irq_lock);
  308. }
  309. /**
  310. * ilk_update_display_irq - update DEIMR
  311. * @dev_priv: driver private
  312. * @interrupt_mask: mask of interrupt bits to update
  313. * @enabled_irq_mask: mask of interrupt bits to enable
  314. */
  315. static void ilk_update_display_irq(struct drm_i915_private *dev_priv,
  316. u32 interrupt_mask, u32 enabled_irq_mask)
  317. {
  318. u32 new_val;
  319. lockdep_assert_held(&dev_priv->irq_lock);
  320. drm_WARN_ON(&dev_priv->drm, enabled_irq_mask & ~interrupt_mask);
  321. new_val = dev_priv->irq_mask;
  322. new_val &= ~interrupt_mask;
  323. new_val |= (~enabled_irq_mask & interrupt_mask);
  324. if (new_val != dev_priv->irq_mask &&
  325. !drm_WARN_ON(&dev_priv->drm, !intel_irqs_enabled(dev_priv))) {
  326. dev_priv->irq_mask = new_val;
  327. intel_uncore_write(&dev_priv->uncore, DEIMR, dev_priv->irq_mask);
  328. intel_uncore_posting_read(&dev_priv->uncore, DEIMR);
  329. }
  330. }
  331. void ilk_enable_display_irq(struct drm_i915_private *i915, u32 bits)
  332. {
  333. ilk_update_display_irq(i915, bits, bits);
  334. }
  335. void ilk_disable_display_irq(struct drm_i915_private *i915, u32 bits)
  336. {
  337. ilk_update_display_irq(i915, bits, 0);
  338. }
  339. /**
  340. * bdw_update_port_irq - update DE port interrupt
  341. * @dev_priv: driver private
  342. * @interrupt_mask: mask of interrupt bits to update
  343. * @enabled_irq_mask: mask of interrupt bits to enable
  344. */
  345. static void bdw_update_port_irq(struct drm_i915_private *dev_priv,
  346. u32 interrupt_mask,
  347. u32 enabled_irq_mask)
  348. {
  349. u32 new_val;
  350. u32 old_val;
  351. lockdep_assert_held(&dev_priv->irq_lock);
  352. drm_WARN_ON(&dev_priv->drm, enabled_irq_mask & ~interrupt_mask);
  353. if (drm_WARN_ON(&dev_priv->drm, !intel_irqs_enabled(dev_priv)))
  354. return;
  355. old_val = intel_uncore_read(&dev_priv->uncore, GEN8_DE_PORT_IMR);
  356. new_val = old_val;
  357. new_val &= ~interrupt_mask;
  358. new_val |= (~enabled_irq_mask & interrupt_mask);
  359. if (new_val != old_val) {
  360. intel_uncore_write(&dev_priv->uncore, GEN8_DE_PORT_IMR, new_val);
  361. intel_uncore_posting_read(&dev_priv->uncore, GEN8_DE_PORT_IMR);
  362. }
  363. }
  364. /**
  365. * bdw_update_pipe_irq - update DE pipe interrupt
  366. * @dev_priv: driver private
  367. * @pipe: pipe whose interrupt to update
  368. * @interrupt_mask: mask of interrupt bits to update
  369. * @enabled_irq_mask: mask of interrupt bits to enable
  370. */
  371. static void bdw_update_pipe_irq(struct drm_i915_private *dev_priv,
  372. enum pipe pipe, u32 interrupt_mask,
  373. u32 enabled_irq_mask)
  374. {
  375. u32 new_val;
  376. lockdep_assert_held(&dev_priv->irq_lock);
  377. drm_WARN_ON(&dev_priv->drm, enabled_irq_mask & ~interrupt_mask);
  378. if (drm_WARN_ON(&dev_priv->drm, !intel_irqs_enabled(dev_priv)))
  379. return;
  380. new_val = dev_priv->de_irq_mask[pipe];
  381. new_val &= ~interrupt_mask;
  382. new_val |= (~enabled_irq_mask & interrupt_mask);
  383. if (new_val != dev_priv->de_irq_mask[pipe]) {
  384. dev_priv->de_irq_mask[pipe] = new_val;
  385. intel_uncore_write(&dev_priv->uncore, GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
  386. intel_uncore_posting_read(&dev_priv->uncore, GEN8_DE_PIPE_IMR(pipe));
  387. }
  388. }
  389. void bdw_enable_pipe_irq(struct drm_i915_private *i915,
  390. enum pipe pipe, u32 bits)
  391. {
  392. bdw_update_pipe_irq(i915, pipe, bits, bits);
  393. }
  394. void bdw_disable_pipe_irq(struct drm_i915_private *i915,
  395. enum pipe pipe, u32 bits)
  396. {
  397. bdw_update_pipe_irq(i915, pipe, bits, 0);
  398. }
  399. /**
  400. * ibx_display_interrupt_update - update SDEIMR
  401. * @dev_priv: driver private
  402. * @interrupt_mask: mask of interrupt bits to update
  403. * @enabled_irq_mask: mask of interrupt bits to enable
  404. */
  405. static void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
  406. u32 interrupt_mask,
  407. u32 enabled_irq_mask)
  408. {
  409. u32 sdeimr = intel_uncore_read(&dev_priv->uncore, SDEIMR);
  410. sdeimr &= ~interrupt_mask;
  411. sdeimr |= (~enabled_irq_mask & interrupt_mask);
  412. drm_WARN_ON(&dev_priv->drm, enabled_irq_mask & ~interrupt_mask);
  413. lockdep_assert_held(&dev_priv->irq_lock);
  414. if (drm_WARN_ON(&dev_priv->drm, !intel_irqs_enabled(dev_priv)))
  415. return;
  416. intel_uncore_write(&dev_priv->uncore, SDEIMR, sdeimr);
  417. intel_uncore_posting_read(&dev_priv->uncore, SDEIMR);
  418. }
  419. void ibx_enable_display_interrupt(struct drm_i915_private *i915, u32 bits)
  420. {
  421. ibx_display_interrupt_update(i915, bits, bits);
  422. }
  423. void ibx_disable_display_interrupt(struct drm_i915_private *i915, u32 bits)
  424. {
  425. ibx_display_interrupt_update(i915, bits, 0);
  426. }
  427. u32 i915_pipestat_enable_mask(struct drm_i915_private *dev_priv,
  428. enum pipe pipe)
  429. {
  430. u32 status_mask = dev_priv->pipestat_irq_mask[pipe];
  431. u32 enable_mask = status_mask << 16;
  432. lockdep_assert_held(&dev_priv->irq_lock);
  433. if (DISPLAY_VER(dev_priv) < 5)
  434. goto out;
  435. /*
  436. * On pipe A we don't support the PSR interrupt yet,
  437. * on pipe B and C the same bit MBZ.
  438. */
  439. if (drm_WARN_ON_ONCE(&dev_priv->drm,
  440. status_mask & PIPE_A_PSR_STATUS_VLV))
  441. return 0;
  442. /*
  443. * On pipe B and C we don't support the PSR interrupt yet, on pipe
  444. * A the same bit is for perf counters which we don't use either.
  445. */
  446. if (drm_WARN_ON_ONCE(&dev_priv->drm,
  447. status_mask & PIPE_B_PSR_STATUS_VLV))
  448. return 0;
  449. enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS |
  450. SPRITE0_FLIP_DONE_INT_EN_VLV |
  451. SPRITE1_FLIP_DONE_INT_EN_VLV);
  452. if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV)
  453. enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV;
  454. if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV)
  455. enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV;
  456. out:
  457. drm_WARN_ONCE(&dev_priv->drm,
  458. enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
  459. status_mask & ~PIPESTAT_INT_STATUS_MASK,
  460. "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
  461. pipe_name(pipe), enable_mask, status_mask);
  462. return enable_mask;
  463. }
  464. void i915_enable_pipestat(struct drm_i915_private *dev_priv,
  465. enum pipe pipe, u32 status_mask)
  466. {
  467. i915_reg_t reg = PIPESTAT(pipe);
  468. u32 enable_mask;
  469. drm_WARN_ONCE(&dev_priv->drm, status_mask & ~PIPESTAT_INT_STATUS_MASK,
  470. "pipe %c: status_mask=0x%x\n",
  471. pipe_name(pipe), status_mask);
  472. lockdep_assert_held(&dev_priv->irq_lock);
  473. drm_WARN_ON(&dev_priv->drm, !intel_irqs_enabled(dev_priv));
  474. if ((dev_priv->pipestat_irq_mask[pipe] & status_mask) == status_mask)
  475. return;
  476. dev_priv->pipestat_irq_mask[pipe] |= status_mask;
  477. enable_mask = i915_pipestat_enable_mask(dev_priv, pipe);
  478. intel_uncore_write(&dev_priv->uncore, reg, enable_mask | status_mask);
  479. intel_uncore_posting_read(&dev_priv->uncore, reg);
  480. }
  481. void i915_disable_pipestat(struct drm_i915_private *dev_priv,
  482. enum pipe pipe, u32 status_mask)
  483. {
  484. i915_reg_t reg = PIPESTAT(pipe);
  485. u32 enable_mask;
  486. drm_WARN_ONCE(&dev_priv->drm, status_mask & ~PIPESTAT_INT_STATUS_MASK,
  487. "pipe %c: status_mask=0x%x\n",
  488. pipe_name(pipe), status_mask);
  489. lockdep_assert_held(&dev_priv->irq_lock);
  490. drm_WARN_ON(&dev_priv->drm, !intel_irqs_enabled(dev_priv));
  491. if ((dev_priv->pipestat_irq_mask[pipe] & status_mask) == 0)
  492. return;
  493. dev_priv->pipestat_irq_mask[pipe] &= ~status_mask;
  494. enable_mask = i915_pipestat_enable_mask(dev_priv, pipe);
  495. intel_uncore_write(&dev_priv->uncore, reg, enable_mask | status_mask);
  496. intel_uncore_posting_read(&dev_priv->uncore, reg);
  497. }
  498. static bool i915_has_asle(struct drm_i915_private *dev_priv)
  499. {
  500. if (!dev_priv->display.opregion.asle)
  501. return false;
  502. return IS_PINEVIEW(dev_priv) || IS_MOBILE(dev_priv);
  503. }
  504. /**
  505. * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
  506. * @dev_priv: i915 device private
  507. */
  508. static void i915_enable_asle_pipestat(struct drm_i915_private *dev_priv)
  509. {
  510. if (!i915_has_asle(dev_priv))
  511. return;
  512. spin_lock_irq(&dev_priv->irq_lock);
  513. i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS);
  514. if (DISPLAY_VER(dev_priv) >= 4)
  515. i915_enable_pipestat(dev_priv, PIPE_A,
  516. PIPE_LEGACY_BLC_EVENT_STATUS);
  517. spin_unlock_irq(&dev_priv->irq_lock);
  518. }
  519. /*
  520. * This timing diagram depicts the video signal in and
  521. * around the vertical blanking period.
  522. *
  523. * Assumptions about the fictitious mode used in this example:
  524. * vblank_start >= 3
  525. * vsync_start = vblank_start + 1
  526. * vsync_end = vblank_start + 2
  527. * vtotal = vblank_start + 3
  528. *
  529. * start of vblank:
  530. * latch double buffered registers
  531. * increment frame counter (ctg+)
  532. * generate start of vblank interrupt (gen4+)
  533. * |
  534. * | frame start:
  535. * | generate frame start interrupt (aka. vblank interrupt) (gmch)
  536. * | may be shifted forward 1-3 extra lines via PIPECONF
  537. * | |
  538. * | | start of vsync:
  539. * | | generate vsync interrupt
  540. * | | |
  541. * ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx
  542. * . \hs/ . \hs/ \hs/ \hs/ . \hs/
  543. * ----va---> <-----------------vb--------------------> <--------va-------------
  544. * | | <----vs-----> |
  545. * -vbs-----> <---vbs+1---> <---vbs+2---> <-----0-----> <-----1-----> <-----2--- (scanline counter gen2)
  546. * -vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2---> <-----0--- (scanline counter gen3+)
  547. * -vbs-2---> <---vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2- (scanline counter hsw+ hdmi)
  548. * | | |
  549. * last visible pixel first visible pixel
  550. * | increment frame counter (gen3/4)
  551. * pixel counter = vblank_start * htotal pixel counter = 0 (gen3/4)
  552. *
  553. * x = horizontal active
  554. * _ = horizontal blanking
  555. * hs = horizontal sync
  556. * va = vertical active
  557. * vb = vertical blanking
  558. * vs = vertical sync
  559. * vbs = vblank_start (number)
  560. *
  561. * Summary:
  562. * - most events happen at the start of horizontal sync
  563. * - frame start happens at the start of horizontal blank, 1-4 lines
  564. * (depending on PIPECONF settings) after the start of vblank
  565. * - gen3/4 pixel and frame counter are synchronized with the start
  566. * of horizontal active on the first line of vertical active
  567. */
  568. /* Called from drm generic code, passed a 'crtc', which
  569. * we use as a pipe index
  570. */
  571. u32 i915_get_vblank_counter(struct drm_crtc *crtc)
  572. {
  573. struct drm_i915_private *dev_priv = to_i915(crtc->dev);
  574. struct drm_vblank_crtc *vblank = &dev_priv->drm.vblank[drm_crtc_index(crtc)];
  575. const struct drm_display_mode *mode = &vblank->hwmode;
  576. enum pipe pipe = to_intel_crtc(crtc)->pipe;
  577. i915_reg_t high_frame, low_frame;
  578. u32 high1, high2, low, pixel, vbl_start, hsync_start, htotal;
  579. unsigned long irqflags;
  580. /*
  581. * On i965gm TV output the frame counter only works up to
  582. * the point when we enable the TV encoder. After that the
  583. * frame counter ceases to work and reads zero. We need a
  584. * vblank wait before enabling the TV encoder and so we
  585. * have to enable vblank interrupts while the frame counter
  586. * is still in a working state. However the core vblank code
  587. * does not like us returning non-zero frame counter values
  588. * when we've told it that we don't have a working frame
  589. * counter. Thus we must stop non-zero values leaking out.
  590. */
  591. if (!vblank->max_vblank_count)
  592. return 0;
  593. htotal = mode->crtc_htotal;
  594. hsync_start = mode->crtc_hsync_start;
  595. vbl_start = mode->crtc_vblank_start;
  596. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  597. vbl_start = DIV_ROUND_UP(vbl_start, 2);
  598. /* Convert to pixel count */
  599. vbl_start *= htotal;
  600. /* Start of vblank event occurs at start of hsync */
  601. vbl_start -= htotal - hsync_start;
  602. high_frame = PIPEFRAME(pipe);
  603. low_frame = PIPEFRAMEPIXEL(pipe);
  604. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  605. /*
  606. * High & low register fields aren't synchronized, so make sure
  607. * we get a low value that's stable across two reads of the high
  608. * register.
  609. */
  610. do {
  611. high1 = intel_de_read_fw(dev_priv, high_frame) & PIPE_FRAME_HIGH_MASK;
  612. low = intel_de_read_fw(dev_priv, low_frame);
  613. high2 = intel_de_read_fw(dev_priv, high_frame) & PIPE_FRAME_HIGH_MASK;
  614. } while (high1 != high2);
  615. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  616. high1 >>= PIPE_FRAME_HIGH_SHIFT;
  617. pixel = low & PIPE_PIXEL_MASK;
  618. low >>= PIPE_FRAME_LOW_SHIFT;
  619. /*
  620. * The frame counter increments at beginning of active.
  621. * Cook up a vblank counter by also checking the pixel
  622. * counter against vblank start.
  623. */
  624. return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff;
  625. }
  626. u32 g4x_get_vblank_counter(struct drm_crtc *crtc)
  627. {
  628. struct drm_i915_private *dev_priv = to_i915(crtc->dev);
  629. struct drm_vblank_crtc *vblank = &dev_priv->drm.vblank[drm_crtc_index(crtc)];
  630. enum pipe pipe = to_intel_crtc(crtc)->pipe;
  631. if (!vblank->max_vblank_count)
  632. return 0;
  633. return intel_uncore_read(&dev_priv->uncore, PIPE_FRMCOUNT_G4X(pipe));
  634. }
  635. static u32 intel_crtc_scanlines_since_frame_timestamp(struct intel_crtc *crtc)
  636. {
  637. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  638. struct drm_vblank_crtc *vblank =
  639. &crtc->base.dev->vblank[drm_crtc_index(&crtc->base)];
  640. const struct drm_display_mode *mode = &vblank->hwmode;
  641. u32 htotal = mode->crtc_htotal;
  642. u32 clock = mode->crtc_clock;
  643. u32 scan_prev_time, scan_curr_time, scan_post_time;
  644. /*
  645. * To avoid the race condition where we might cross into the
  646. * next vblank just between the PIPE_FRMTMSTMP and TIMESTAMP_CTR
  647. * reads. We make sure we read PIPE_FRMTMSTMP and TIMESTAMP_CTR
  648. * during the same frame.
  649. */
  650. do {
  651. /*
  652. * This field provides read back of the display
  653. * pipe frame time stamp. The time stamp value
  654. * is sampled at every start of vertical blank.
  655. */
  656. scan_prev_time = intel_de_read_fw(dev_priv,
  657. PIPE_FRMTMSTMP(crtc->pipe));
  658. /*
  659. * The TIMESTAMP_CTR register has the current
  660. * time stamp value.
  661. */
  662. scan_curr_time = intel_de_read_fw(dev_priv, IVB_TIMESTAMP_CTR);
  663. scan_post_time = intel_de_read_fw(dev_priv,
  664. PIPE_FRMTMSTMP(crtc->pipe));
  665. } while (scan_post_time != scan_prev_time);
  666. return div_u64(mul_u32_u32(scan_curr_time - scan_prev_time,
  667. clock), 1000 * htotal);
  668. }
  669. /*
  670. * On certain encoders on certain platforms, pipe
  671. * scanline register will not work to get the scanline,
  672. * since the timings are driven from the PORT or issues
  673. * with scanline register updates.
  674. * This function will use Framestamp and current
  675. * timestamp registers to calculate the scanline.
  676. */
  677. static u32 __intel_get_crtc_scanline_from_timestamp(struct intel_crtc *crtc)
  678. {
  679. struct drm_vblank_crtc *vblank =
  680. &crtc->base.dev->vblank[drm_crtc_index(&crtc->base)];
  681. const struct drm_display_mode *mode = &vblank->hwmode;
  682. u32 vblank_start = mode->crtc_vblank_start;
  683. u32 vtotal = mode->crtc_vtotal;
  684. u32 scanline;
  685. scanline = intel_crtc_scanlines_since_frame_timestamp(crtc);
  686. scanline = min(scanline, vtotal - 1);
  687. scanline = (scanline + vblank_start) % vtotal;
  688. return scanline;
  689. }
  690. /*
  691. * intel_de_read_fw(), only for fast reads of display block, no need for
  692. * forcewake etc.
  693. */
  694. static int __intel_get_crtc_scanline(struct intel_crtc *crtc)
  695. {
  696. struct drm_device *dev = crtc->base.dev;
  697. struct drm_i915_private *dev_priv = to_i915(dev);
  698. const struct drm_display_mode *mode;
  699. struct drm_vblank_crtc *vblank;
  700. enum pipe pipe = crtc->pipe;
  701. int position, vtotal;
  702. if (!crtc->active)
  703. return 0;
  704. vblank = &crtc->base.dev->vblank[drm_crtc_index(&crtc->base)];
  705. mode = &vblank->hwmode;
  706. if (crtc->mode_flags & I915_MODE_FLAG_GET_SCANLINE_FROM_TIMESTAMP)
  707. return __intel_get_crtc_scanline_from_timestamp(crtc);
  708. vtotal = mode->crtc_vtotal;
  709. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  710. vtotal /= 2;
  711. position = intel_de_read_fw(dev_priv, PIPEDSL(pipe)) & PIPEDSL_LINE_MASK;
  712. /*
  713. * On HSW, the DSL reg (0x70000) appears to return 0 if we
  714. * read it just before the start of vblank. So try it again
  715. * so we don't accidentally end up spanning a vblank frame
  716. * increment, causing the pipe_update_end() code to squak at us.
  717. *
  718. * The nature of this problem means we can't simply check the ISR
  719. * bit and return the vblank start value; nor can we use the scanline
  720. * debug register in the transcoder as it appears to have the same
  721. * problem. We may need to extend this to include other platforms,
  722. * but so far testing only shows the problem on HSW.
  723. */
  724. if (HAS_DDI(dev_priv) && !position) {
  725. int i, temp;
  726. for (i = 0; i < 100; i++) {
  727. udelay(1);
  728. temp = intel_de_read_fw(dev_priv, PIPEDSL(pipe)) & PIPEDSL_LINE_MASK;
  729. if (temp != position) {
  730. position = temp;
  731. break;
  732. }
  733. }
  734. }
  735. /*
  736. * See update_scanline_offset() for the details on the
  737. * scanline_offset adjustment.
  738. */
  739. return (position + crtc->scanline_offset) % vtotal;
  740. }
  741. static bool i915_get_crtc_scanoutpos(struct drm_crtc *_crtc,
  742. bool in_vblank_irq,
  743. int *vpos, int *hpos,
  744. ktime_t *stime, ktime_t *etime,
  745. const struct drm_display_mode *mode)
  746. {
  747. struct drm_device *dev = _crtc->dev;
  748. struct drm_i915_private *dev_priv = to_i915(dev);
  749. struct intel_crtc *crtc = to_intel_crtc(_crtc);
  750. enum pipe pipe = crtc->pipe;
  751. int position;
  752. int vbl_start, vbl_end, hsync_start, htotal, vtotal;
  753. unsigned long irqflags;
  754. bool use_scanline_counter = DISPLAY_VER(dev_priv) >= 5 ||
  755. IS_G4X(dev_priv) || DISPLAY_VER(dev_priv) == 2 ||
  756. crtc->mode_flags & I915_MODE_FLAG_USE_SCANLINE_COUNTER;
  757. if (drm_WARN_ON(&dev_priv->drm, !mode->crtc_clock)) {
  758. drm_dbg(&dev_priv->drm,
  759. "trying to get scanoutpos for disabled "
  760. "pipe %c\n", pipe_name(pipe));
  761. return false;
  762. }
  763. htotal = mode->crtc_htotal;
  764. hsync_start = mode->crtc_hsync_start;
  765. vtotal = mode->crtc_vtotal;
  766. vbl_start = mode->crtc_vblank_start;
  767. vbl_end = mode->crtc_vblank_end;
  768. if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
  769. vbl_start = DIV_ROUND_UP(vbl_start, 2);
  770. vbl_end /= 2;
  771. vtotal /= 2;
  772. }
  773. /*
  774. * Lock uncore.lock, as we will do multiple timing critical raw
  775. * register reads, potentially with preemption disabled, so the
  776. * following code must not block on uncore.lock.
  777. */
  778. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  779. /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
  780. /* Get optional system timestamp before query. */
  781. if (stime)
  782. *stime = ktime_get();
  783. if (crtc->mode_flags & I915_MODE_FLAG_VRR) {
  784. int scanlines = intel_crtc_scanlines_since_frame_timestamp(crtc);
  785. position = __intel_get_crtc_scanline(crtc);
  786. /*
  787. * Already exiting vblank? If so, shift our position
  788. * so it looks like we're already apporaching the full
  789. * vblank end. This should make the generated timestamp
  790. * more or less match when the active portion will start.
  791. */
  792. if (position >= vbl_start && scanlines < position)
  793. position = min(crtc->vmax_vblank_start + scanlines, vtotal - 1);
  794. } else if (use_scanline_counter) {
  795. /* No obvious pixelcount register. Only query vertical
  796. * scanout position from Display scan line register.
  797. */
  798. position = __intel_get_crtc_scanline(crtc);
  799. } else {
  800. /* Have access to pixelcount since start of frame.
  801. * We can split this into vertical and horizontal
  802. * scanout position.
  803. */
  804. position = (intel_de_read_fw(dev_priv, PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
  805. /* convert to pixel counts */
  806. vbl_start *= htotal;
  807. vbl_end *= htotal;
  808. vtotal *= htotal;
  809. /*
  810. * In interlaced modes, the pixel counter counts all pixels,
  811. * so one field will have htotal more pixels. In order to avoid
  812. * the reported position from jumping backwards when the pixel
  813. * counter is beyond the length of the shorter field, just
  814. * clamp the position the length of the shorter field. This
  815. * matches how the scanline counter based position works since
  816. * the scanline counter doesn't count the two half lines.
  817. */
  818. if (position >= vtotal)
  819. position = vtotal - 1;
  820. /*
  821. * Start of vblank interrupt is triggered at start of hsync,
  822. * just prior to the first active line of vblank. However we
  823. * consider lines to start at the leading edge of horizontal
  824. * active. So, should we get here before we've crossed into
  825. * the horizontal active of the first line in vblank, we would
  826. * not set the DRM_SCANOUTPOS_INVBL flag. In order to fix that,
  827. * always add htotal-hsync_start to the current pixel position.
  828. */
  829. position = (position + htotal - hsync_start) % vtotal;
  830. }
  831. /* Get optional system timestamp after query. */
  832. if (etime)
  833. *etime = ktime_get();
  834. /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
  835. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  836. /*
  837. * While in vblank, position will be negative
  838. * counting up towards 0 at vbl_end. And outside
  839. * vblank, position will be positive counting
  840. * up since vbl_end.
  841. */
  842. if (position >= vbl_start)
  843. position -= vbl_end;
  844. else
  845. position += vtotal - vbl_end;
  846. if (use_scanline_counter) {
  847. *vpos = position;
  848. *hpos = 0;
  849. } else {
  850. *vpos = position / htotal;
  851. *hpos = position - (*vpos * htotal);
  852. }
  853. return true;
  854. }
  855. bool intel_crtc_get_vblank_timestamp(struct drm_crtc *crtc, int *max_error,
  856. ktime_t *vblank_time, bool in_vblank_irq)
  857. {
  858. return drm_crtc_vblank_helper_get_vblank_timestamp_internal(
  859. crtc, max_error, vblank_time, in_vblank_irq,
  860. i915_get_crtc_scanoutpos);
  861. }
  862. int intel_get_crtc_scanline(struct intel_crtc *crtc)
  863. {
  864. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  865. unsigned long irqflags;
  866. int position;
  867. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  868. position = __intel_get_crtc_scanline(crtc);
  869. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  870. return position;
  871. }
  872. /**
  873. * ivb_parity_work - Workqueue called when a parity error interrupt
  874. * occurred.
  875. * @work: workqueue struct
  876. *
  877. * Doesn't actually do anything except notify userspace. As a consequence of
  878. * this event, userspace should try to remap the bad rows since statistically
  879. * it is likely the same row is more likely to go bad again.
  880. */
  881. static void ivb_parity_work(struct work_struct *work)
  882. {
  883. struct drm_i915_private *dev_priv =
  884. container_of(work, typeof(*dev_priv), l3_parity.error_work);
  885. struct intel_gt *gt = to_gt(dev_priv);
  886. u32 error_status, row, bank, subbank;
  887. char *parity_event[6];
  888. u32 misccpctl;
  889. u8 slice = 0;
  890. /* We must turn off DOP level clock gating to access the L3 registers.
  891. * In order to prevent a get/put style interface, acquire struct mutex
  892. * any time we access those registers.
  893. */
  894. mutex_lock(&dev_priv->drm.struct_mutex);
  895. /* If we've screwed up tracking, just let the interrupt fire again */
  896. if (drm_WARN_ON(&dev_priv->drm, !dev_priv->l3_parity.which_slice))
  897. goto out;
  898. misccpctl = intel_uncore_read(&dev_priv->uncore, GEN7_MISCCPCTL);
  899. intel_uncore_write(&dev_priv->uncore, GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
  900. intel_uncore_posting_read(&dev_priv->uncore, GEN7_MISCCPCTL);
  901. while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
  902. i915_reg_t reg;
  903. slice--;
  904. if (drm_WARN_ON_ONCE(&dev_priv->drm,
  905. slice >= NUM_L3_SLICES(dev_priv)))
  906. break;
  907. dev_priv->l3_parity.which_slice &= ~(1<<slice);
  908. reg = GEN7_L3CDERRST1(slice);
  909. error_status = intel_uncore_read(&dev_priv->uncore, reg);
  910. row = GEN7_PARITY_ERROR_ROW(error_status);
  911. bank = GEN7_PARITY_ERROR_BANK(error_status);
  912. subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
  913. intel_uncore_write(&dev_priv->uncore, reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
  914. intel_uncore_posting_read(&dev_priv->uncore, reg);
  915. parity_event[0] = I915_L3_PARITY_UEVENT "=1";
  916. parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
  917. parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
  918. parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
  919. parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
  920. parity_event[5] = NULL;
  921. kobject_uevent_env(&dev_priv->drm.primary->kdev->kobj,
  922. KOBJ_CHANGE, parity_event);
  923. DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
  924. slice, row, bank, subbank);
  925. kfree(parity_event[4]);
  926. kfree(parity_event[3]);
  927. kfree(parity_event[2]);
  928. kfree(parity_event[1]);
  929. }
  930. intel_uncore_write(&dev_priv->uncore, GEN7_MISCCPCTL, misccpctl);
  931. out:
  932. drm_WARN_ON(&dev_priv->drm, dev_priv->l3_parity.which_slice);
  933. spin_lock_irq(gt->irq_lock);
  934. gen5_gt_enable_irq(gt, GT_PARITY_ERROR(dev_priv));
  935. spin_unlock_irq(gt->irq_lock);
  936. mutex_unlock(&dev_priv->drm.struct_mutex);
  937. }
  938. static bool gen11_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
  939. {
  940. switch (pin) {
  941. case HPD_PORT_TC1:
  942. case HPD_PORT_TC2:
  943. case HPD_PORT_TC3:
  944. case HPD_PORT_TC4:
  945. case HPD_PORT_TC5:
  946. case HPD_PORT_TC6:
  947. return val & GEN11_HOTPLUG_CTL_LONG_DETECT(pin);
  948. default:
  949. return false;
  950. }
  951. }
  952. static bool bxt_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
  953. {
  954. switch (pin) {
  955. case HPD_PORT_A:
  956. return val & PORTA_HOTPLUG_LONG_DETECT;
  957. case HPD_PORT_B:
  958. return val & PORTB_HOTPLUG_LONG_DETECT;
  959. case HPD_PORT_C:
  960. return val & PORTC_HOTPLUG_LONG_DETECT;
  961. default:
  962. return false;
  963. }
  964. }
  965. static bool icp_ddi_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
  966. {
  967. switch (pin) {
  968. case HPD_PORT_A:
  969. case HPD_PORT_B:
  970. case HPD_PORT_C:
  971. case HPD_PORT_D:
  972. return val & SHOTPLUG_CTL_DDI_HPD_LONG_DETECT(pin);
  973. default:
  974. return false;
  975. }
  976. }
  977. static bool icp_tc_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
  978. {
  979. switch (pin) {
  980. case HPD_PORT_TC1:
  981. case HPD_PORT_TC2:
  982. case HPD_PORT_TC3:
  983. case HPD_PORT_TC4:
  984. case HPD_PORT_TC5:
  985. case HPD_PORT_TC6:
  986. return val & ICP_TC_HPD_LONG_DETECT(pin);
  987. default:
  988. return false;
  989. }
  990. }
  991. static bool spt_port_hotplug2_long_detect(enum hpd_pin pin, u32 val)
  992. {
  993. switch (pin) {
  994. case HPD_PORT_E:
  995. return val & PORTE_HOTPLUG_LONG_DETECT;
  996. default:
  997. return false;
  998. }
  999. }
  1000. static bool spt_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
  1001. {
  1002. switch (pin) {
  1003. case HPD_PORT_A:
  1004. return val & PORTA_HOTPLUG_LONG_DETECT;
  1005. case HPD_PORT_B:
  1006. return val & PORTB_HOTPLUG_LONG_DETECT;
  1007. case HPD_PORT_C:
  1008. return val & PORTC_HOTPLUG_LONG_DETECT;
  1009. case HPD_PORT_D:
  1010. return val & PORTD_HOTPLUG_LONG_DETECT;
  1011. default:
  1012. return false;
  1013. }
  1014. }
  1015. static bool ilk_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
  1016. {
  1017. switch (pin) {
  1018. case HPD_PORT_A:
  1019. return val & DIGITAL_PORTA_HOTPLUG_LONG_DETECT;
  1020. default:
  1021. return false;
  1022. }
  1023. }
  1024. static bool pch_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
  1025. {
  1026. switch (pin) {
  1027. case HPD_PORT_B:
  1028. return val & PORTB_HOTPLUG_LONG_DETECT;
  1029. case HPD_PORT_C:
  1030. return val & PORTC_HOTPLUG_LONG_DETECT;
  1031. case HPD_PORT_D:
  1032. return val & PORTD_HOTPLUG_LONG_DETECT;
  1033. default:
  1034. return false;
  1035. }
  1036. }
  1037. static bool i9xx_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
  1038. {
  1039. switch (pin) {
  1040. case HPD_PORT_B:
  1041. return val & PORTB_HOTPLUG_INT_LONG_PULSE;
  1042. case HPD_PORT_C:
  1043. return val & PORTC_HOTPLUG_INT_LONG_PULSE;
  1044. case HPD_PORT_D:
  1045. return val & PORTD_HOTPLUG_INT_LONG_PULSE;
  1046. default:
  1047. return false;
  1048. }
  1049. }
  1050. /*
  1051. * Get a bit mask of pins that have triggered, and which ones may be long.
  1052. * This can be called multiple times with the same masks to accumulate
  1053. * hotplug detection results from several registers.
  1054. *
  1055. * Note that the caller is expected to zero out the masks initially.
  1056. */
  1057. static void intel_get_hpd_pins(struct drm_i915_private *dev_priv,
  1058. u32 *pin_mask, u32 *long_mask,
  1059. u32 hotplug_trigger, u32 dig_hotplug_reg,
  1060. const u32 hpd[HPD_NUM_PINS],
  1061. bool long_pulse_detect(enum hpd_pin pin, u32 val))
  1062. {
  1063. enum hpd_pin pin;
  1064. BUILD_BUG_ON(BITS_PER_TYPE(*pin_mask) < HPD_NUM_PINS);
  1065. for_each_hpd_pin(pin) {
  1066. if ((hpd[pin] & hotplug_trigger) == 0)
  1067. continue;
  1068. *pin_mask |= BIT(pin);
  1069. if (long_pulse_detect(pin, dig_hotplug_reg))
  1070. *long_mask |= BIT(pin);
  1071. }
  1072. drm_dbg(&dev_priv->drm,
  1073. "hotplug event received, stat 0x%08x, dig 0x%08x, pins 0x%08x, long 0x%08x\n",
  1074. hotplug_trigger, dig_hotplug_reg, *pin_mask, *long_mask);
  1075. }
  1076. static u32 intel_hpd_enabled_irqs(struct drm_i915_private *dev_priv,
  1077. const u32 hpd[HPD_NUM_PINS])
  1078. {
  1079. struct intel_encoder *encoder;
  1080. u32 enabled_irqs = 0;
  1081. for_each_intel_encoder(&dev_priv->drm, encoder)
  1082. if (dev_priv->display.hotplug.stats[encoder->hpd_pin].state == HPD_ENABLED)
  1083. enabled_irqs |= hpd[encoder->hpd_pin];
  1084. return enabled_irqs;
  1085. }
  1086. static u32 intel_hpd_hotplug_irqs(struct drm_i915_private *dev_priv,
  1087. const u32 hpd[HPD_NUM_PINS])
  1088. {
  1089. struct intel_encoder *encoder;
  1090. u32 hotplug_irqs = 0;
  1091. for_each_intel_encoder(&dev_priv->drm, encoder)
  1092. hotplug_irqs |= hpd[encoder->hpd_pin];
  1093. return hotplug_irqs;
  1094. }
  1095. static u32 intel_hpd_hotplug_enables(struct drm_i915_private *i915,
  1096. hotplug_enables_func hotplug_enables)
  1097. {
  1098. struct intel_encoder *encoder;
  1099. u32 hotplug = 0;
  1100. for_each_intel_encoder(&i915->drm, encoder)
  1101. hotplug |= hotplug_enables(i915, encoder->hpd_pin);
  1102. return hotplug;
  1103. }
  1104. static void gmbus_irq_handler(struct drm_i915_private *dev_priv)
  1105. {
  1106. wake_up_all(&dev_priv->display.gmbus.wait_queue);
  1107. }
  1108. static void dp_aux_irq_handler(struct drm_i915_private *dev_priv)
  1109. {
  1110. wake_up_all(&dev_priv->display.gmbus.wait_queue);
  1111. }
  1112. #if defined(CONFIG_DEBUG_FS)
  1113. static void display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
  1114. enum pipe pipe,
  1115. u32 crc0, u32 crc1,
  1116. u32 crc2, u32 crc3,
  1117. u32 crc4)
  1118. {
  1119. struct intel_crtc *crtc = intel_crtc_for_pipe(dev_priv, pipe);
  1120. struct intel_pipe_crc *pipe_crc = &crtc->pipe_crc;
  1121. u32 crcs[5] = { crc0, crc1, crc2, crc3, crc4 };
  1122. trace_intel_pipe_crc(crtc, crcs);
  1123. spin_lock(&pipe_crc->lock);
  1124. /*
  1125. * For some not yet identified reason, the first CRC is
  1126. * bonkers. So let's just wait for the next vblank and read
  1127. * out the buggy result.
  1128. *
  1129. * On GEN8+ sometimes the second CRC is bonkers as well, so
  1130. * don't trust that one either.
  1131. */
  1132. if (pipe_crc->skipped <= 0 ||
  1133. (DISPLAY_VER(dev_priv) >= 8 && pipe_crc->skipped == 1)) {
  1134. pipe_crc->skipped++;
  1135. spin_unlock(&pipe_crc->lock);
  1136. return;
  1137. }
  1138. spin_unlock(&pipe_crc->lock);
  1139. drm_crtc_add_crc_entry(&crtc->base, true,
  1140. drm_crtc_accurate_vblank_count(&crtc->base),
  1141. crcs);
  1142. }
  1143. #else
  1144. static inline void
  1145. display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
  1146. enum pipe pipe,
  1147. u32 crc0, u32 crc1,
  1148. u32 crc2, u32 crc3,
  1149. u32 crc4) {}
  1150. #endif
  1151. static void flip_done_handler(struct drm_i915_private *i915,
  1152. enum pipe pipe)
  1153. {
  1154. struct intel_crtc *crtc = intel_crtc_for_pipe(i915, pipe);
  1155. struct drm_crtc_state *crtc_state = crtc->base.state;
  1156. struct drm_pending_vblank_event *e = crtc_state->event;
  1157. struct drm_device *dev = &i915->drm;
  1158. unsigned long irqflags;
  1159. spin_lock_irqsave(&dev->event_lock, irqflags);
  1160. crtc_state->event = NULL;
  1161. drm_crtc_send_vblank_event(&crtc->base, e);
  1162. spin_unlock_irqrestore(&dev->event_lock, irqflags);
  1163. }
  1164. static void hsw_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
  1165. enum pipe pipe)
  1166. {
  1167. display_pipe_crc_irq_handler(dev_priv, pipe,
  1168. intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_1_IVB(pipe)),
  1169. 0, 0, 0, 0);
  1170. }
  1171. static void ivb_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
  1172. enum pipe pipe)
  1173. {
  1174. display_pipe_crc_irq_handler(dev_priv, pipe,
  1175. intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_1_IVB(pipe)),
  1176. intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_2_IVB(pipe)),
  1177. intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_3_IVB(pipe)),
  1178. intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_4_IVB(pipe)),
  1179. intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_5_IVB(pipe)));
  1180. }
  1181. static void i9xx_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
  1182. enum pipe pipe)
  1183. {
  1184. u32 res1, res2;
  1185. if (DISPLAY_VER(dev_priv) >= 3)
  1186. res1 = intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_RES1_I915(pipe));
  1187. else
  1188. res1 = 0;
  1189. if (DISPLAY_VER(dev_priv) >= 5 || IS_G4X(dev_priv))
  1190. res2 = intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_RES2_G4X(pipe));
  1191. else
  1192. res2 = 0;
  1193. display_pipe_crc_irq_handler(dev_priv, pipe,
  1194. intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_RED(pipe)),
  1195. intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_GREEN(pipe)),
  1196. intel_uncore_read(&dev_priv->uncore, PIPE_CRC_RES_BLUE(pipe)),
  1197. res1, res2);
  1198. }
  1199. static void i9xx_pipestat_irq_reset(struct drm_i915_private *dev_priv)
  1200. {
  1201. enum pipe pipe;
  1202. for_each_pipe(dev_priv, pipe) {
  1203. intel_uncore_write(&dev_priv->uncore, PIPESTAT(pipe),
  1204. PIPESTAT_INT_STATUS_MASK |
  1205. PIPE_FIFO_UNDERRUN_STATUS);
  1206. dev_priv->pipestat_irq_mask[pipe] = 0;
  1207. }
  1208. }
  1209. static void i9xx_pipestat_irq_ack(struct drm_i915_private *dev_priv,
  1210. u32 iir, u32 pipe_stats[I915_MAX_PIPES])
  1211. {
  1212. enum pipe pipe;
  1213. spin_lock(&dev_priv->irq_lock);
  1214. if (!dev_priv->display_irqs_enabled) {
  1215. spin_unlock(&dev_priv->irq_lock);
  1216. return;
  1217. }
  1218. for_each_pipe(dev_priv, pipe) {
  1219. i915_reg_t reg;
  1220. u32 status_mask, enable_mask, iir_bit = 0;
  1221. /*
  1222. * PIPESTAT bits get signalled even when the interrupt is
  1223. * disabled with the mask bits, and some of the status bits do
  1224. * not generate interrupts at all (like the underrun bit). Hence
  1225. * we need to be careful that we only handle what we want to
  1226. * handle.
  1227. */
  1228. /* fifo underruns are filterered in the underrun handler. */
  1229. status_mask = PIPE_FIFO_UNDERRUN_STATUS;
  1230. switch (pipe) {
  1231. default:
  1232. case PIPE_A:
  1233. iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
  1234. break;
  1235. case PIPE_B:
  1236. iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
  1237. break;
  1238. case PIPE_C:
  1239. iir_bit = I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
  1240. break;
  1241. }
  1242. if (iir & iir_bit)
  1243. status_mask |= dev_priv->pipestat_irq_mask[pipe];
  1244. if (!status_mask)
  1245. continue;
  1246. reg = PIPESTAT(pipe);
  1247. pipe_stats[pipe] = intel_uncore_read(&dev_priv->uncore, reg) & status_mask;
  1248. enable_mask = i915_pipestat_enable_mask(dev_priv, pipe);
  1249. /*
  1250. * Clear the PIPE*STAT regs before the IIR
  1251. *
  1252. * Toggle the enable bits to make sure we get an
  1253. * edge in the ISR pipe event bit if we don't clear
  1254. * all the enabled status bits. Otherwise the edge
  1255. * triggered IIR on i965/g4x wouldn't notice that
  1256. * an interrupt is still pending.
  1257. */
  1258. if (pipe_stats[pipe]) {
  1259. intel_uncore_write(&dev_priv->uncore, reg, pipe_stats[pipe]);
  1260. intel_uncore_write(&dev_priv->uncore, reg, enable_mask);
  1261. }
  1262. }
  1263. spin_unlock(&dev_priv->irq_lock);
  1264. }
  1265. static void i8xx_pipestat_irq_handler(struct drm_i915_private *dev_priv,
  1266. u16 iir, u32 pipe_stats[I915_MAX_PIPES])
  1267. {
  1268. enum pipe pipe;
  1269. for_each_pipe(dev_priv, pipe) {
  1270. if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
  1271. intel_handle_vblank(dev_priv, pipe);
  1272. if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
  1273. i9xx_pipe_crc_irq_handler(dev_priv, pipe);
  1274. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  1275. intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
  1276. }
  1277. }
  1278. static void i915_pipestat_irq_handler(struct drm_i915_private *dev_priv,
  1279. u32 iir, u32 pipe_stats[I915_MAX_PIPES])
  1280. {
  1281. bool blc_event = false;
  1282. enum pipe pipe;
  1283. for_each_pipe(dev_priv, pipe) {
  1284. if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
  1285. intel_handle_vblank(dev_priv, pipe);
  1286. if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
  1287. blc_event = true;
  1288. if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
  1289. i9xx_pipe_crc_irq_handler(dev_priv, pipe);
  1290. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  1291. intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
  1292. }
  1293. if (blc_event || (iir & I915_ASLE_INTERRUPT))
  1294. intel_opregion_asle_intr(dev_priv);
  1295. }
  1296. static void i965_pipestat_irq_handler(struct drm_i915_private *dev_priv,
  1297. u32 iir, u32 pipe_stats[I915_MAX_PIPES])
  1298. {
  1299. bool blc_event = false;
  1300. enum pipe pipe;
  1301. for_each_pipe(dev_priv, pipe) {
  1302. if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
  1303. intel_handle_vblank(dev_priv, pipe);
  1304. if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
  1305. blc_event = true;
  1306. if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
  1307. i9xx_pipe_crc_irq_handler(dev_priv, pipe);
  1308. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  1309. intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
  1310. }
  1311. if (blc_event || (iir & I915_ASLE_INTERRUPT))
  1312. intel_opregion_asle_intr(dev_priv);
  1313. if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
  1314. gmbus_irq_handler(dev_priv);
  1315. }
  1316. static void valleyview_pipestat_irq_handler(struct drm_i915_private *dev_priv,
  1317. u32 pipe_stats[I915_MAX_PIPES])
  1318. {
  1319. enum pipe pipe;
  1320. for_each_pipe(dev_priv, pipe) {
  1321. if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
  1322. intel_handle_vblank(dev_priv, pipe);
  1323. if (pipe_stats[pipe] & PLANE_FLIP_DONE_INT_STATUS_VLV)
  1324. flip_done_handler(dev_priv, pipe);
  1325. if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
  1326. i9xx_pipe_crc_irq_handler(dev_priv, pipe);
  1327. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  1328. intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
  1329. }
  1330. if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
  1331. gmbus_irq_handler(dev_priv);
  1332. }
  1333. static u32 i9xx_hpd_irq_ack(struct drm_i915_private *dev_priv)
  1334. {
  1335. u32 hotplug_status = 0, hotplug_status_mask;
  1336. int i;
  1337. if (IS_G4X(dev_priv) ||
  1338. IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  1339. hotplug_status_mask = HOTPLUG_INT_STATUS_G4X |
  1340. DP_AUX_CHANNEL_MASK_INT_STATUS_G4X;
  1341. else
  1342. hotplug_status_mask = HOTPLUG_INT_STATUS_I915;
  1343. /*
  1344. * We absolutely have to clear all the pending interrupt
  1345. * bits in PORT_HOTPLUG_STAT. Otherwise the ISR port
  1346. * interrupt bit won't have an edge, and the i965/g4x
  1347. * edge triggered IIR will not notice that an interrupt
  1348. * is still pending. We can't use PORT_HOTPLUG_EN to
  1349. * guarantee the edge as the act of toggling the enable
  1350. * bits can itself generate a new hotplug interrupt :(
  1351. */
  1352. for (i = 0; i < 10; i++) {
  1353. u32 tmp = intel_uncore_read(&dev_priv->uncore, PORT_HOTPLUG_STAT) & hotplug_status_mask;
  1354. if (tmp == 0)
  1355. return hotplug_status;
  1356. hotplug_status |= tmp;
  1357. intel_uncore_write(&dev_priv->uncore, PORT_HOTPLUG_STAT, hotplug_status);
  1358. }
  1359. drm_WARN_ONCE(&dev_priv->drm, 1,
  1360. "PORT_HOTPLUG_STAT did not clear (0x%08x)\n",
  1361. intel_uncore_read(&dev_priv->uncore, PORT_HOTPLUG_STAT));
  1362. return hotplug_status;
  1363. }
  1364. static void i9xx_hpd_irq_handler(struct drm_i915_private *dev_priv,
  1365. u32 hotplug_status)
  1366. {
  1367. u32 pin_mask = 0, long_mask = 0;
  1368. u32 hotplug_trigger;
  1369. if (IS_G4X(dev_priv) ||
  1370. IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  1371. hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X;
  1372. else
  1373. hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
  1374. if (hotplug_trigger) {
  1375. intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
  1376. hotplug_trigger, hotplug_trigger,
  1377. dev_priv->display.hotplug.hpd,
  1378. i9xx_port_hotplug_long_detect);
  1379. intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
  1380. }
  1381. if ((IS_G4X(dev_priv) ||
  1382. IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
  1383. hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
  1384. dp_aux_irq_handler(dev_priv);
  1385. }
  1386. static irqreturn_t valleyview_irq_handler(int irq, void *arg)
  1387. {
  1388. struct drm_i915_private *dev_priv = arg;
  1389. irqreturn_t ret = IRQ_NONE;
  1390. if (!intel_irqs_enabled(dev_priv))
  1391. return IRQ_NONE;
  1392. /* IRQs are synced during runtime_suspend, we don't require a wakeref */
  1393. disable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
  1394. do {
  1395. u32 iir, gt_iir, pm_iir;
  1396. u32 pipe_stats[I915_MAX_PIPES] = {};
  1397. u32 hotplug_status = 0;
  1398. u32 ier = 0;
  1399. gt_iir = intel_uncore_read(&dev_priv->uncore, GTIIR);
  1400. pm_iir = intel_uncore_read(&dev_priv->uncore, GEN6_PMIIR);
  1401. iir = intel_uncore_read(&dev_priv->uncore, VLV_IIR);
  1402. if (gt_iir == 0 && pm_iir == 0 && iir == 0)
  1403. break;
  1404. ret = IRQ_HANDLED;
  1405. /*
  1406. * Theory on interrupt generation, based on empirical evidence:
  1407. *
  1408. * x = ((VLV_IIR & VLV_IER) ||
  1409. * (((GT_IIR & GT_IER) || (GEN6_PMIIR & GEN6_PMIER)) &&
  1410. * (VLV_MASTER_IER & MASTER_INTERRUPT_ENABLE)));
  1411. *
  1412. * A CPU interrupt will only be raised when 'x' has a 0->1 edge.
  1413. * Hence we clear MASTER_INTERRUPT_ENABLE and VLV_IER to
  1414. * guarantee the CPU interrupt will be raised again even if we
  1415. * don't end up clearing all the VLV_IIR, GT_IIR, GEN6_PMIIR
  1416. * bits this time around.
  1417. */
  1418. intel_uncore_write(&dev_priv->uncore, VLV_MASTER_IER, 0);
  1419. ier = intel_uncore_read(&dev_priv->uncore, VLV_IER);
  1420. intel_uncore_write(&dev_priv->uncore, VLV_IER, 0);
  1421. if (gt_iir)
  1422. intel_uncore_write(&dev_priv->uncore, GTIIR, gt_iir);
  1423. if (pm_iir)
  1424. intel_uncore_write(&dev_priv->uncore, GEN6_PMIIR, pm_iir);
  1425. if (iir & I915_DISPLAY_PORT_INTERRUPT)
  1426. hotplug_status = i9xx_hpd_irq_ack(dev_priv);
  1427. /* Call regardless, as some status bits might not be
  1428. * signalled in iir */
  1429. i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
  1430. if (iir & (I915_LPE_PIPE_A_INTERRUPT |
  1431. I915_LPE_PIPE_B_INTERRUPT))
  1432. intel_lpe_audio_irq_handler(dev_priv);
  1433. /*
  1434. * VLV_IIR is single buffered, and reflects the level
  1435. * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
  1436. */
  1437. if (iir)
  1438. intel_uncore_write(&dev_priv->uncore, VLV_IIR, iir);
  1439. intel_uncore_write(&dev_priv->uncore, VLV_IER, ier);
  1440. intel_uncore_write(&dev_priv->uncore, VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
  1441. if (gt_iir)
  1442. gen6_gt_irq_handler(to_gt(dev_priv), gt_iir);
  1443. if (pm_iir)
  1444. gen6_rps_irq_handler(&to_gt(dev_priv)->rps, pm_iir);
  1445. if (hotplug_status)
  1446. i9xx_hpd_irq_handler(dev_priv, hotplug_status);
  1447. valleyview_pipestat_irq_handler(dev_priv, pipe_stats);
  1448. } while (0);
  1449. pmu_irq_stats(dev_priv, ret);
  1450. enable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
  1451. return ret;
  1452. }
  1453. static irqreturn_t cherryview_irq_handler(int irq, void *arg)
  1454. {
  1455. struct drm_i915_private *dev_priv = arg;
  1456. irqreturn_t ret = IRQ_NONE;
  1457. if (!intel_irqs_enabled(dev_priv))
  1458. return IRQ_NONE;
  1459. /* IRQs are synced during runtime_suspend, we don't require a wakeref */
  1460. disable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
  1461. do {
  1462. u32 master_ctl, iir;
  1463. u32 pipe_stats[I915_MAX_PIPES] = {};
  1464. u32 hotplug_status = 0;
  1465. u32 ier = 0;
  1466. master_ctl = intel_uncore_read(&dev_priv->uncore, GEN8_MASTER_IRQ) & ~GEN8_MASTER_IRQ_CONTROL;
  1467. iir = intel_uncore_read(&dev_priv->uncore, VLV_IIR);
  1468. if (master_ctl == 0 && iir == 0)
  1469. break;
  1470. ret = IRQ_HANDLED;
  1471. /*
  1472. * Theory on interrupt generation, based on empirical evidence:
  1473. *
  1474. * x = ((VLV_IIR & VLV_IER) ||
  1475. * ((GEN8_MASTER_IRQ & ~GEN8_MASTER_IRQ_CONTROL) &&
  1476. * (GEN8_MASTER_IRQ & GEN8_MASTER_IRQ_CONTROL)));
  1477. *
  1478. * A CPU interrupt will only be raised when 'x' has a 0->1 edge.
  1479. * Hence we clear GEN8_MASTER_IRQ_CONTROL and VLV_IER to
  1480. * guarantee the CPU interrupt will be raised again even if we
  1481. * don't end up clearing all the VLV_IIR and GEN8_MASTER_IRQ_CONTROL
  1482. * bits this time around.
  1483. */
  1484. intel_uncore_write(&dev_priv->uncore, GEN8_MASTER_IRQ, 0);
  1485. ier = intel_uncore_read(&dev_priv->uncore, VLV_IER);
  1486. intel_uncore_write(&dev_priv->uncore, VLV_IER, 0);
  1487. gen8_gt_irq_handler(to_gt(dev_priv), master_ctl);
  1488. if (iir & I915_DISPLAY_PORT_INTERRUPT)
  1489. hotplug_status = i9xx_hpd_irq_ack(dev_priv);
  1490. /* Call regardless, as some status bits might not be
  1491. * signalled in iir */
  1492. i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
  1493. if (iir & (I915_LPE_PIPE_A_INTERRUPT |
  1494. I915_LPE_PIPE_B_INTERRUPT |
  1495. I915_LPE_PIPE_C_INTERRUPT))
  1496. intel_lpe_audio_irq_handler(dev_priv);
  1497. /*
  1498. * VLV_IIR is single buffered, and reflects the level
  1499. * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
  1500. */
  1501. if (iir)
  1502. intel_uncore_write(&dev_priv->uncore, VLV_IIR, iir);
  1503. intel_uncore_write(&dev_priv->uncore, VLV_IER, ier);
  1504. intel_uncore_write(&dev_priv->uncore, GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
  1505. if (hotplug_status)
  1506. i9xx_hpd_irq_handler(dev_priv, hotplug_status);
  1507. valleyview_pipestat_irq_handler(dev_priv, pipe_stats);
  1508. } while (0);
  1509. pmu_irq_stats(dev_priv, ret);
  1510. enable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
  1511. return ret;
  1512. }
  1513. static void ibx_hpd_irq_handler(struct drm_i915_private *dev_priv,
  1514. u32 hotplug_trigger)
  1515. {
  1516. u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
  1517. /*
  1518. * Somehow the PCH doesn't seem to really ack the interrupt to the CPU
  1519. * unless we touch the hotplug register, even if hotplug_trigger is
  1520. * zero. Not acking leads to "The master control interrupt lied (SDE)!"
  1521. * errors.
  1522. */
  1523. dig_hotplug_reg = intel_uncore_read(&dev_priv->uncore, PCH_PORT_HOTPLUG);
  1524. if (!hotplug_trigger) {
  1525. u32 mask = PORTA_HOTPLUG_STATUS_MASK |
  1526. PORTD_HOTPLUG_STATUS_MASK |
  1527. PORTC_HOTPLUG_STATUS_MASK |
  1528. PORTB_HOTPLUG_STATUS_MASK;
  1529. dig_hotplug_reg &= ~mask;
  1530. }
  1531. intel_uncore_write(&dev_priv->uncore, PCH_PORT_HOTPLUG, dig_hotplug_reg);
  1532. if (!hotplug_trigger)
  1533. return;
  1534. intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
  1535. hotplug_trigger, dig_hotplug_reg,
  1536. dev_priv->display.hotplug.pch_hpd,
  1537. pch_port_hotplug_long_detect);
  1538. intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
  1539. }
  1540. static void ibx_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
  1541. {
  1542. enum pipe pipe;
  1543. u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
  1544. ibx_hpd_irq_handler(dev_priv, hotplug_trigger);
  1545. if (pch_iir & SDE_AUDIO_POWER_MASK) {
  1546. int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
  1547. SDE_AUDIO_POWER_SHIFT);
  1548. drm_dbg(&dev_priv->drm, "PCH audio power change on port %d\n",
  1549. port_name(port));
  1550. }
  1551. if (pch_iir & SDE_AUX_MASK)
  1552. dp_aux_irq_handler(dev_priv);
  1553. if (pch_iir & SDE_GMBUS)
  1554. gmbus_irq_handler(dev_priv);
  1555. if (pch_iir & SDE_AUDIO_HDCP_MASK)
  1556. drm_dbg(&dev_priv->drm, "PCH HDCP audio interrupt\n");
  1557. if (pch_iir & SDE_AUDIO_TRANS_MASK)
  1558. drm_dbg(&dev_priv->drm, "PCH transcoder audio interrupt\n");
  1559. if (pch_iir & SDE_POISON)
  1560. drm_err(&dev_priv->drm, "PCH poison interrupt\n");
  1561. if (pch_iir & SDE_FDI_MASK) {
  1562. for_each_pipe(dev_priv, pipe)
  1563. drm_dbg(&dev_priv->drm, " pipe %c FDI IIR: 0x%08x\n",
  1564. pipe_name(pipe),
  1565. intel_uncore_read(&dev_priv->uncore, FDI_RX_IIR(pipe)));
  1566. }
  1567. if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
  1568. drm_dbg(&dev_priv->drm, "PCH transcoder CRC done interrupt\n");
  1569. if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
  1570. drm_dbg(&dev_priv->drm,
  1571. "PCH transcoder CRC error interrupt\n");
  1572. if (pch_iir & SDE_TRANSA_FIFO_UNDER)
  1573. intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_A);
  1574. if (pch_iir & SDE_TRANSB_FIFO_UNDER)
  1575. intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_B);
  1576. }
  1577. static void ivb_err_int_handler(struct drm_i915_private *dev_priv)
  1578. {
  1579. u32 err_int = intel_uncore_read(&dev_priv->uncore, GEN7_ERR_INT);
  1580. enum pipe pipe;
  1581. if (err_int & ERR_INT_POISON)
  1582. drm_err(&dev_priv->drm, "Poison interrupt\n");
  1583. for_each_pipe(dev_priv, pipe) {
  1584. if (err_int & ERR_INT_FIFO_UNDERRUN(pipe))
  1585. intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
  1586. if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
  1587. if (IS_IVYBRIDGE(dev_priv))
  1588. ivb_pipe_crc_irq_handler(dev_priv, pipe);
  1589. else
  1590. hsw_pipe_crc_irq_handler(dev_priv, pipe);
  1591. }
  1592. }
  1593. intel_uncore_write(&dev_priv->uncore, GEN7_ERR_INT, err_int);
  1594. }
  1595. static void cpt_serr_int_handler(struct drm_i915_private *dev_priv)
  1596. {
  1597. u32 serr_int = intel_uncore_read(&dev_priv->uncore, SERR_INT);
  1598. enum pipe pipe;
  1599. if (serr_int & SERR_INT_POISON)
  1600. drm_err(&dev_priv->drm, "PCH poison interrupt\n");
  1601. for_each_pipe(dev_priv, pipe)
  1602. if (serr_int & SERR_INT_TRANS_FIFO_UNDERRUN(pipe))
  1603. intel_pch_fifo_underrun_irq_handler(dev_priv, pipe);
  1604. intel_uncore_write(&dev_priv->uncore, SERR_INT, serr_int);
  1605. }
  1606. static void cpt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
  1607. {
  1608. enum pipe pipe;
  1609. u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
  1610. ibx_hpd_irq_handler(dev_priv, hotplug_trigger);
  1611. if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
  1612. int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
  1613. SDE_AUDIO_POWER_SHIFT_CPT);
  1614. drm_dbg(&dev_priv->drm, "PCH audio power change on port %c\n",
  1615. port_name(port));
  1616. }
  1617. if (pch_iir & SDE_AUX_MASK_CPT)
  1618. dp_aux_irq_handler(dev_priv);
  1619. if (pch_iir & SDE_GMBUS_CPT)
  1620. gmbus_irq_handler(dev_priv);
  1621. if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
  1622. drm_dbg(&dev_priv->drm, "Audio CP request interrupt\n");
  1623. if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
  1624. drm_dbg(&dev_priv->drm, "Audio CP change interrupt\n");
  1625. if (pch_iir & SDE_FDI_MASK_CPT) {
  1626. for_each_pipe(dev_priv, pipe)
  1627. drm_dbg(&dev_priv->drm, " pipe %c FDI IIR: 0x%08x\n",
  1628. pipe_name(pipe),
  1629. intel_uncore_read(&dev_priv->uncore, FDI_RX_IIR(pipe)));
  1630. }
  1631. if (pch_iir & SDE_ERROR_CPT)
  1632. cpt_serr_int_handler(dev_priv);
  1633. }
  1634. static void icp_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
  1635. {
  1636. u32 ddi_hotplug_trigger = pch_iir & SDE_DDI_HOTPLUG_MASK_ICP;
  1637. u32 tc_hotplug_trigger = pch_iir & SDE_TC_HOTPLUG_MASK_ICP;
  1638. u32 pin_mask = 0, long_mask = 0;
  1639. if (ddi_hotplug_trigger) {
  1640. u32 dig_hotplug_reg;
  1641. /* Locking due to DSI native GPIO sequences */
  1642. spin_lock(&dev_priv->irq_lock);
  1643. dig_hotplug_reg = intel_uncore_read(&dev_priv->uncore, SHOTPLUG_CTL_DDI);
  1644. intel_uncore_write(&dev_priv->uncore, SHOTPLUG_CTL_DDI, dig_hotplug_reg);
  1645. spin_unlock(&dev_priv->irq_lock);
  1646. intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
  1647. ddi_hotplug_trigger, dig_hotplug_reg,
  1648. dev_priv->display.hotplug.pch_hpd,
  1649. icp_ddi_port_hotplug_long_detect);
  1650. }
  1651. if (tc_hotplug_trigger) {
  1652. u32 dig_hotplug_reg;
  1653. dig_hotplug_reg = intel_uncore_read(&dev_priv->uncore, SHOTPLUG_CTL_TC);
  1654. intel_uncore_write(&dev_priv->uncore, SHOTPLUG_CTL_TC, dig_hotplug_reg);
  1655. intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
  1656. tc_hotplug_trigger, dig_hotplug_reg,
  1657. dev_priv->display.hotplug.pch_hpd,
  1658. icp_tc_port_hotplug_long_detect);
  1659. }
  1660. if (pin_mask)
  1661. intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
  1662. if (pch_iir & SDE_GMBUS_ICP)
  1663. gmbus_irq_handler(dev_priv);
  1664. }
  1665. static void spt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
  1666. {
  1667. u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_SPT &
  1668. ~SDE_PORTE_HOTPLUG_SPT;
  1669. u32 hotplug2_trigger = pch_iir & SDE_PORTE_HOTPLUG_SPT;
  1670. u32 pin_mask = 0, long_mask = 0;
  1671. if (hotplug_trigger) {
  1672. u32 dig_hotplug_reg;
  1673. dig_hotplug_reg = intel_uncore_read(&dev_priv->uncore, PCH_PORT_HOTPLUG);
  1674. intel_uncore_write(&dev_priv->uncore, PCH_PORT_HOTPLUG, dig_hotplug_reg);
  1675. intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
  1676. hotplug_trigger, dig_hotplug_reg,
  1677. dev_priv->display.hotplug.pch_hpd,
  1678. spt_port_hotplug_long_detect);
  1679. }
  1680. if (hotplug2_trigger) {
  1681. u32 dig_hotplug_reg;
  1682. dig_hotplug_reg = intel_uncore_read(&dev_priv->uncore, PCH_PORT_HOTPLUG2);
  1683. intel_uncore_write(&dev_priv->uncore, PCH_PORT_HOTPLUG2, dig_hotplug_reg);
  1684. intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
  1685. hotplug2_trigger, dig_hotplug_reg,
  1686. dev_priv->display.hotplug.pch_hpd,
  1687. spt_port_hotplug2_long_detect);
  1688. }
  1689. if (pin_mask)
  1690. intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
  1691. if (pch_iir & SDE_GMBUS_CPT)
  1692. gmbus_irq_handler(dev_priv);
  1693. }
  1694. static void ilk_hpd_irq_handler(struct drm_i915_private *dev_priv,
  1695. u32 hotplug_trigger)
  1696. {
  1697. u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
  1698. dig_hotplug_reg = intel_uncore_read(&dev_priv->uncore, DIGITAL_PORT_HOTPLUG_CNTRL);
  1699. intel_uncore_write(&dev_priv->uncore, DIGITAL_PORT_HOTPLUG_CNTRL, dig_hotplug_reg);
  1700. intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
  1701. hotplug_trigger, dig_hotplug_reg,
  1702. dev_priv->display.hotplug.hpd,
  1703. ilk_port_hotplug_long_detect);
  1704. intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
  1705. }
  1706. static void ilk_display_irq_handler(struct drm_i915_private *dev_priv,
  1707. u32 de_iir)
  1708. {
  1709. enum pipe pipe;
  1710. u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG;
  1711. if (hotplug_trigger)
  1712. ilk_hpd_irq_handler(dev_priv, hotplug_trigger);
  1713. if (de_iir & DE_AUX_CHANNEL_A)
  1714. dp_aux_irq_handler(dev_priv);
  1715. if (de_iir & DE_GSE)
  1716. intel_opregion_asle_intr(dev_priv);
  1717. if (de_iir & DE_POISON)
  1718. drm_err(&dev_priv->drm, "Poison interrupt\n");
  1719. for_each_pipe(dev_priv, pipe) {
  1720. if (de_iir & DE_PIPE_VBLANK(pipe))
  1721. intel_handle_vblank(dev_priv, pipe);
  1722. if (de_iir & DE_PLANE_FLIP_DONE(pipe))
  1723. flip_done_handler(dev_priv, pipe);
  1724. if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
  1725. intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
  1726. if (de_iir & DE_PIPE_CRC_DONE(pipe))
  1727. i9xx_pipe_crc_irq_handler(dev_priv, pipe);
  1728. }
  1729. /* check event from PCH */
  1730. if (de_iir & DE_PCH_EVENT) {
  1731. u32 pch_iir = intel_uncore_read(&dev_priv->uncore, SDEIIR);
  1732. if (HAS_PCH_CPT(dev_priv))
  1733. cpt_irq_handler(dev_priv, pch_iir);
  1734. else
  1735. ibx_irq_handler(dev_priv, pch_iir);
  1736. /* should clear PCH hotplug event before clear CPU irq */
  1737. intel_uncore_write(&dev_priv->uncore, SDEIIR, pch_iir);
  1738. }
  1739. if (DISPLAY_VER(dev_priv) == 5 && de_iir & DE_PCU_EVENT)
  1740. gen5_rps_irq_handler(&to_gt(dev_priv)->rps);
  1741. }
  1742. static void ivb_display_irq_handler(struct drm_i915_private *dev_priv,
  1743. u32 de_iir)
  1744. {
  1745. enum pipe pipe;
  1746. u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG_IVB;
  1747. if (hotplug_trigger)
  1748. ilk_hpd_irq_handler(dev_priv, hotplug_trigger);
  1749. if (de_iir & DE_ERR_INT_IVB)
  1750. ivb_err_int_handler(dev_priv);
  1751. if (de_iir & DE_AUX_CHANNEL_A_IVB)
  1752. dp_aux_irq_handler(dev_priv);
  1753. if (de_iir & DE_GSE_IVB)
  1754. intel_opregion_asle_intr(dev_priv);
  1755. for_each_pipe(dev_priv, pipe) {
  1756. if (de_iir & DE_PIPE_VBLANK_IVB(pipe))
  1757. intel_handle_vblank(dev_priv, pipe);
  1758. if (de_iir & DE_PLANE_FLIP_DONE_IVB(pipe))
  1759. flip_done_handler(dev_priv, pipe);
  1760. }
  1761. /* check event from PCH */
  1762. if (!HAS_PCH_NOP(dev_priv) && (de_iir & DE_PCH_EVENT_IVB)) {
  1763. u32 pch_iir = intel_uncore_read(&dev_priv->uncore, SDEIIR);
  1764. cpt_irq_handler(dev_priv, pch_iir);
  1765. /* clear PCH hotplug event before clear CPU irq */
  1766. intel_uncore_write(&dev_priv->uncore, SDEIIR, pch_iir);
  1767. }
  1768. }
  1769. /*
  1770. * To handle irqs with the minimum potential races with fresh interrupts, we:
  1771. * 1 - Disable Master Interrupt Control.
  1772. * 2 - Find the source(s) of the interrupt.
  1773. * 3 - Clear the Interrupt Identity bits (IIR).
  1774. * 4 - Process the interrupt(s) that had bits set in the IIRs.
  1775. * 5 - Re-enable Master Interrupt Control.
  1776. */
  1777. static irqreturn_t ilk_irq_handler(int irq, void *arg)
  1778. {
  1779. struct drm_i915_private *i915 = arg;
  1780. void __iomem * const regs = i915->uncore.regs;
  1781. u32 de_iir, gt_iir, de_ier, sde_ier = 0;
  1782. irqreturn_t ret = IRQ_NONE;
  1783. if (unlikely(!intel_irqs_enabled(i915)))
  1784. return IRQ_NONE;
  1785. /* IRQs are synced during runtime_suspend, we don't require a wakeref */
  1786. disable_rpm_wakeref_asserts(&i915->runtime_pm);
  1787. /* disable master interrupt before clearing iir */
  1788. de_ier = raw_reg_read(regs, DEIER);
  1789. raw_reg_write(regs, DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
  1790. /* Disable south interrupts. We'll only write to SDEIIR once, so further
  1791. * interrupts will will be stored on its back queue, and then we'll be
  1792. * able to process them after we restore SDEIER (as soon as we restore
  1793. * it, we'll get an interrupt if SDEIIR still has something to process
  1794. * due to its back queue). */
  1795. if (!HAS_PCH_NOP(i915)) {
  1796. sde_ier = raw_reg_read(regs, SDEIER);
  1797. raw_reg_write(regs, SDEIER, 0);
  1798. }
  1799. /* Find, clear, then process each source of interrupt */
  1800. gt_iir = raw_reg_read(regs, GTIIR);
  1801. if (gt_iir) {
  1802. raw_reg_write(regs, GTIIR, gt_iir);
  1803. if (GRAPHICS_VER(i915) >= 6)
  1804. gen6_gt_irq_handler(to_gt(i915), gt_iir);
  1805. else
  1806. gen5_gt_irq_handler(to_gt(i915), gt_iir);
  1807. ret = IRQ_HANDLED;
  1808. }
  1809. de_iir = raw_reg_read(regs, DEIIR);
  1810. if (de_iir) {
  1811. raw_reg_write(regs, DEIIR, de_iir);
  1812. if (DISPLAY_VER(i915) >= 7)
  1813. ivb_display_irq_handler(i915, de_iir);
  1814. else
  1815. ilk_display_irq_handler(i915, de_iir);
  1816. ret = IRQ_HANDLED;
  1817. }
  1818. if (GRAPHICS_VER(i915) >= 6) {
  1819. u32 pm_iir = raw_reg_read(regs, GEN6_PMIIR);
  1820. if (pm_iir) {
  1821. raw_reg_write(regs, GEN6_PMIIR, pm_iir);
  1822. gen6_rps_irq_handler(&to_gt(i915)->rps, pm_iir);
  1823. ret = IRQ_HANDLED;
  1824. }
  1825. }
  1826. raw_reg_write(regs, DEIER, de_ier);
  1827. if (sde_ier)
  1828. raw_reg_write(regs, SDEIER, sde_ier);
  1829. pmu_irq_stats(i915, ret);
  1830. /* IRQs are synced during runtime_suspend, we don't require a wakeref */
  1831. enable_rpm_wakeref_asserts(&i915->runtime_pm);
  1832. return ret;
  1833. }
  1834. static void bxt_hpd_irq_handler(struct drm_i915_private *dev_priv,
  1835. u32 hotplug_trigger)
  1836. {
  1837. u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
  1838. dig_hotplug_reg = intel_uncore_read(&dev_priv->uncore, PCH_PORT_HOTPLUG);
  1839. intel_uncore_write(&dev_priv->uncore, PCH_PORT_HOTPLUG, dig_hotplug_reg);
  1840. intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
  1841. hotplug_trigger, dig_hotplug_reg,
  1842. dev_priv->display.hotplug.hpd,
  1843. bxt_port_hotplug_long_detect);
  1844. intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
  1845. }
  1846. static void gen11_hpd_irq_handler(struct drm_i915_private *dev_priv, u32 iir)
  1847. {
  1848. u32 pin_mask = 0, long_mask = 0;
  1849. u32 trigger_tc = iir & GEN11_DE_TC_HOTPLUG_MASK;
  1850. u32 trigger_tbt = iir & GEN11_DE_TBT_HOTPLUG_MASK;
  1851. if (trigger_tc) {
  1852. u32 dig_hotplug_reg;
  1853. dig_hotplug_reg = intel_uncore_read(&dev_priv->uncore, GEN11_TC_HOTPLUG_CTL);
  1854. intel_uncore_write(&dev_priv->uncore, GEN11_TC_HOTPLUG_CTL, dig_hotplug_reg);
  1855. intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
  1856. trigger_tc, dig_hotplug_reg,
  1857. dev_priv->display.hotplug.hpd,
  1858. gen11_port_hotplug_long_detect);
  1859. }
  1860. if (trigger_tbt) {
  1861. u32 dig_hotplug_reg;
  1862. dig_hotplug_reg = intel_uncore_read(&dev_priv->uncore, GEN11_TBT_HOTPLUG_CTL);
  1863. intel_uncore_write(&dev_priv->uncore, GEN11_TBT_HOTPLUG_CTL, dig_hotplug_reg);
  1864. intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
  1865. trigger_tbt, dig_hotplug_reg,
  1866. dev_priv->display.hotplug.hpd,
  1867. gen11_port_hotplug_long_detect);
  1868. }
  1869. if (pin_mask)
  1870. intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
  1871. else
  1872. drm_err(&dev_priv->drm,
  1873. "Unexpected DE HPD interrupt 0x%08x\n", iir);
  1874. }
  1875. static u32 gen8_de_port_aux_mask(struct drm_i915_private *dev_priv)
  1876. {
  1877. u32 mask;
  1878. if (DISPLAY_VER(dev_priv) >= 13)
  1879. return TGL_DE_PORT_AUX_DDIA |
  1880. TGL_DE_PORT_AUX_DDIB |
  1881. TGL_DE_PORT_AUX_DDIC |
  1882. XELPD_DE_PORT_AUX_DDID |
  1883. XELPD_DE_PORT_AUX_DDIE |
  1884. TGL_DE_PORT_AUX_USBC1 |
  1885. TGL_DE_PORT_AUX_USBC2 |
  1886. TGL_DE_PORT_AUX_USBC3 |
  1887. TGL_DE_PORT_AUX_USBC4;
  1888. else if (DISPLAY_VER(dev_priv) >= 12)
  1889. return TGL_DE_PORT_AUX_DDIA |
  1890. TGL_DE_PORT_AUX_DDIB |
  1891. TGL_DE_PORT_AUX_DDIC |
  1892. TGL_DE_PORT_AUX_USBC1 |
  1893. TGL_DE_PORT_AUX_USBC2 |
  1894. TGL_DE_PORT_AUX_USBC3 |
  1895. TGL_DE_PORT_AUX_USBC4 |
  1896. TGL_DE_PORT_AUX_USBC5 |
  1897. TGL_DE_PORT_AUX_USBC6;
  1898. mask = GEN8_AUX_CHANNEL_A;
  1899. if (DISPLAY_VER(dev_priv) >= 9)
  1900. mask |= GEN9_AUX_CHANNEL_B |
  1901. GEN9_AUX_CHANNEL_C |
  1902. GEN9_AUX_CHANNEL_D;
  1903. if (DISPLAY_VER(dev_priv) == 11) {
  1904. mask |= ICL_AUX_CHANNEL_F;
  1905. mask |= ICL_AUX_CHANNEL_E;
  1906. }
  1907. return mask;
  1908. }
  1909. static u32 gen8_de_pipe_fault_mask(struct drm_i915_private *dev_priv)
  1910. {
  1911. if (DISPLAY_VER(dev_priv) >= 13 || HAS_D12_PLANE_MINIMIZATION(dev_priv))
  1912. return RKL_DE_PIPE_IRQ_FAULT_ERRORS;
  1913. else if (DISPLAY_VER(dev_priv) >= 11)
  1914. return GEN11_DE_PIPE_IRQ_FAULT_ERRORS;
  1915. else if (DISPLAY_VER(dev_priv) >= 9)
  1916. return GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
  1917. else
  1918. return GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
  1919. }
  1920. static void
  1921. gen8_de_misc_irq_handler(struct drm_i915_private *dev_priv, u32 iir)
  1922. {
  1923. bool found = false;
  1924. if (iir & GEN8_DE_MISC_GSE) {
  1925. intel_opregion_asle_intr(dev_priv);
  1926. found = true;
  1927. }
  1928. if (iir & GEN8_DE_EDP_PSR) {
  1929. struct intel_encoder *encoder;
  1930. u32 psr_iir;
  1931. i915_reg_t iir_reg;
  1932. for_each_intel_encoder_with_psr(&dev_priv->drm, encoder) {
  1933. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  1934. if (DISPLAY_VER(dev_priv) >= 12)
  1935. iir_reg = TRANS_PSR_IIR(intel_dp->psr.transcoder);
  1936. else
  1937. iir_reg = EDP_PSR_IIR;
  1938. psr_iir = intel_uncore_read(&dev_priv->uncore, iir_reg);
  1939. intel_uncore_write(&dev_priv->uncore, iir_reg, psr_iir);
  1940. if (psr_iir)
  1941. found = true;
  1942. intel_psr_irq_handler(intel_dp, psr_iir);
  1943. /* prior GEN12 only have one EDP PSR */
  1944. if (DISPLAY_VER(dev_priv) < 12)
  1945. break;
  1946. }
  1947. }
  1948. if (!found)
  1949. drm_err(&dev_priv->drm, "Unexpected DE Misc interrupt\n");
  1950. }
  1951. static void gen11_dsi_te_interrupt_handler(struct drm_i915_private *dev_priv,
  1952. u32 te_trigger)
  1953. {
  1954. enum pipe pipe = INVALID_PIPE;
  1955. enum transcoder dsi_trans;
  1956. enum port port;
  1957. u32 val, tmp;
  1958. /*
  1959. * Incase of dual link, TE comes from DSI_1
  1960. * this is to check if dual link is enabled
  1961. */
  1962. val = intel_uncore_read(&dev_priv->uncore, TRANS_DDI_FUNC_CTL2(TRANSCODER_DSI_0));
  1963. val &= PORT_SYNC_MODE_ENABLE;
  1964. /*
  1965. * if dual link is enabled, then read DSI_0
  1966. * transcoder registers
  1967. */
  1968. port = ((te_trigger & DSI1_TE && val) || (te_trigger & DSI0_TE)) ?
  1969. PORT_A : PORT_B;
  1970. dsi_trans = (port == PORT_A) ? TRANSCODER_DSI_0 : TRANSCODER_DSI_1;
  1971. /* Check if DSI configured in command mode */
  1972. val = intel_uncore_read(&dev_priv->uncore, DSI_TRANS_FUNC_CONF(dsi_trans));
  1973. val = val & OP_MODE_MASK;
  1974. if (val != CMD_MODE_NO_GATE && val != CMD_MODE_TE_GATE) {
  1975. drm_err(&dev_priv->drm, "DSI trancoder not configured in command mode\n");
  1976. return;
  1977. }
  1978. /* Get PIPE for handling VBLANK event */
  1979. val = intel_uncore_read(&dev_priv->uncore, TRANS_DDI_FUNC_CTL(dsi_trans));
  1980. switch (val & TRANS_DDI_EDP_INPUT_MASK) {
  1981. case TRANS_DDI_EDP_INPUT_A_ON:
  1982. pipe = PIPE_A;
  1983. break;
  1984. case TRANS_DDI_EDP_INPUT_B_ONOFF:
  1985. pipe = PIPE_B;
  1986. break;
  1987. case TRANS_DDI_EDP_INPUT_C_ONOFF:
  1988. pipe = PIPE_C;
  1989. break;
  1990. default:
  1991. drm_err(&dev_priv->drm, "Invalid PIPE\n");
  1992. return;
  1993. }
  1994. intel_handle_vblank(dev_priv, pipe);
  1995. /* clear TE in dsi IIR */
  1996. port = (te_trigger & DSI1_TE) ? PORT_B : PORT_A;
  1997. tmp = intel_uncore_read(&dev_priv->uncore, DSI_INTR_IDENT_REG(port));
  1998. intel_uncore_write(&dev_priv->uncore, DSI_INTR_IDENT_REG(port), tmp);
  1999. }
  2000. static u32 gen8_de_pipe_flip_done_mask(struct drm_i915_private *i915)
  2001. {
  2002. if (DISPLAY_VER(i915) >= 9)
  2003. return GEN9_PIPE_PLANE1_FLIP_DONE;
  2004. else
  2005. return GEN8_PIPE_PRIMARY_FLIP_DONE;
  2006. }
  2007. u32 gen8_de_pipe_underrun_mask(struct drm_i915_private *dev_priv)
  2008. {
  2009. u32 mask = GEN8_PIPE_FIFO_UNDERRUN;
  2010. if (DISPLAY_VER(dev_priv) >= 13)
  2011. mask |= XELPD_PIPE_SOFT_UNDERRUN |
  2012. XELPD_PIPE_HARD_UNDERRUN;
  2013. return mask;
  2014. }
  2015. static irqreturn_t
  2016. gen8_de_irq_handler(struct drm_i915_private *dev_priv, u32 master_ctl)
  2017. {
  2018. irqreturn_t ret = IRQ_NONE;
  2019. u32 iir;
  2020. enum pipe pipe;
  2021. drm_WARN_ON_ONCE(&dev_priv->drm, !HAS_DISPLAY(dev_priv));
  2022. if (master_ctl & GEN8_DE_MISC_IRQ) {
  2023. iir = intel_uncore_read(&dev_priv->uncore, GEN8_DE_MISC_IIR);
  2024. if (iir) {
  2025. intel_uncore_write(&dev_priv->uncore, GEN8_DE_MISC_IIR, iir);
  2026. ret = IRQ_HANDLED;
  2027. gen8_de_misc_irq_handler(dev_priv, iir);
  2028. } else {
  2029. drm_err(&dev_priv->drm,
  2030. "The master control interrupt lied (DE MISC)!\n");
  2031. }
  2032. }
  2033. if (DISPLAY_VER(dev_priv) >= 11 && (master_ctl & GEN11_DE_HPD_IRQ)) {
  2034. iir = intel_uncore_read(&dev_priv->uncore, GEN11_DE_HPD_IIR);
  2035. if (iir) {
  2036. intel_uncore_write(&dev_priv->uncore, GEN11_DE_HPD_IIR, iir);
  2037. ret = IRQ_HANDLED;
  2038. gen11_hpd_irq_handler(dev_priv, iir);
  2039. } else {
  2040. drm_err(&dev_priv->drm,
  2041. "The master control interrupt lied, (DE HPD)!\n");
  2042. }
  2043. }
  2044. if (master_ctl & GEN8_DE_PORT_IRQ) {
  2045. iir = intel_uncore_read(&dev_priv->uncore, GEN8_DE_PORT_IIR);
  2046. if (iir) {
  2047. bool found = false;
  2048. intel_uncore_write(&dev_priv->uncore, GEN8_DE_PORT_IIR, iir);
  2049. ret = IRQ_HANDLED;
  2050. if (iir & gen8_de_port_aux_mask(dev_priv)) {
  2051. dp_aux_irq_handler(dev_priv);
  2052. found = true;
  2053. }
  2054. if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) {
  2055. u32 hotplug_trigger = iir & BXT_DE_PORT_HOTPLUG_MASK;
  2056. if (hotplug_trigger) {
  2057. bxt_hpd_irq_handler(dev_priv, hotplug_trigger);
  2058. found = true;
  2059. }
  2060. } else if (IS_BROADWELL(dev_priv)) {
  2061. u32 hotplug_trigger = iir & BDW_DE_PORT_HOTPLUG_MASK;
  2062. if (hotplug_trigger) {
  2063. ilk_hpd_irq_handler(dev_priv, hotplug_trigger);
  2064. found = true;
  2065. }
  2066. }
  2067. if ((IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) &&
  2068. (iir & BXT_DE_PORT_GMBUS)) {
  2069. gmbus_irq_handler(dev_priv);
  2070. found = true;
  2071. }
  2072. if (DISPLAY_VER(dev_priv) >= 11) {
  2073. u32 te_trigger = iir & (DSI0_TE | DSI1_TE);
  2074. if (te_trigger) {
  2075. gen11_dsi_te_interrupt_handler(dev_priv, te_trigger);
  2076. found = true;
  2077. }
  2078. }
  2079. if (!found)
  2080. drm_err(&dev_priv->drm,
  2081. "Unexpected DE Port interrupt\n");
  2082. }
  2083. else
  2084. drm_err(&dev_priv->drm,
  2085. "The master control interrupt lied (DE PORT)!\n");
  2086. }
  2087. for_each_pipe(dev_priv, pipe) {
  2088. u32 fault_errors;
  2089. if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
  2090. continue;
  2091. iir = intel_uncore_read(&dev_priv->uncore, GEN8_DE_PIPE_IIR(pipe));
  2092. if (!iir) {
  2093. drm_err(&dev_priv->drm,
  2094. "The master control interrupt lied (DE PIPE)!\n");
  2095. continue;
  2096. }
  2097. ret = IRQ_HANDLED;
  2098. intel_uncore_write(&dev_priv->uncore, GEN8_DE_PIPE_IIR(pipe), iir);
  2099. if (iir & GEN8_PIPE_VBLANK)
  2100. intel_handle_vblank(dev_priv, pipe);
  2101. if (iir & gen8_de_pipe_flip_done_mask(dev_priv))
  2102. flip_done_handler(dev_priv, pipe);
  2103. if (iir & GEN8_PIPE_CDCLK_CRC_DONE)
  2104. hsw_pipe_crc_irq_handler(dev_priv, pipe);
  2105. if (iir & gen8_de_pipe_underrun_mask(dev_priv))
  2106. intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
  2107. fault_errors = iir & gen8_de_pipe_fault_mask(dev_priv);
  2108. if (fault_errors)
  2109. drm_err(&dev_priv->drm,
  2110. "Fault errors on pipe %c: 0x%08x\n",
  2111. pipe_name(pipe),
  2112. fault_errors);
  2113. }
  2114. if (HAS_PCH_SPLIT(dev_priv) && !HAS_PCH_NOP(dev_priv) &&
  2115. master_ctl & GEN8_DE_PCH_IRQ) {
  2116. /*
  2117. * FIXME(BDW): Assume for now that the new interrupt handling
  2118. * scheme also closed the SDE interrupt handling race we've seen
  2119. * on older pch-split platforms. But this needs testing.
  2120. */
  2121. iir = intel_uncore_read(&dev_priv->uncore, SDEIIR);
  2122. if (iir) {
  2123. intel_uncore_write(&dev_priv->uncore, SDEIIR, iir);
  2124. ret = IRQ_HANDLED;
  2125. if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
  2126. icp_irq_handler(dev_priv, iir);
  2127. else if (INTEL_PCH_TYPE(dev_priv) >= PCH_SPT)
  2128. spt_irq_handler(dev_priv, iir);
  2129. else
  2130. cpt_irq_handler(dev_priv, iir);
  2131. } else {
  2132. /*
  2133. * Like on previous PCH there seems to be something
  2134. * fishy going on with forwarding PCH interrupts.
  2135. */
  2136. drm_dbg(&dev_priv->drm,
  2137. "The master control interrupt lied (SDE)!\n");
  2138. }
  2139. }
  2140. return ret;
  2141. }
  2142. static inline u32 gen8_master_intr_disable(void __iomem * const regs)
  2143. {
  2144. raw_reg_write(regs, GEN8_MASTER_IRQ, 0);
  2145. /*
  2146. * Now with master disabled, get a sample of level indications
  2147. * for this interrupt. Indications will be cleared on related acks.
  2148. * New indications can and will light up during processing,
  2149. * and will generate new interrupt after enabling master.
  2150. */
  2151. return raw_reg_read(regs, GEN8_MASTER_IRQ);
  2152. }
  2153. static inline void gen8_master_intr_enable(void __iomem * const regs)
  2154. {
  2155. raw_reg_write(regs, GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
  2156. }
  2157. static irqreturn_t gen8_irq_handler(int irq, void *arg)
  2158. {
  2159. struct drm_i915_private *dev_priv = arg;
  2160. void __iomem * const regs = dev_priv->uncore.regs;
  2161. u32 master_ctl;
  2162. if (!intel_irqs_enabled(dev_priv))
  2163. return IRQ_NONE;
  2164. master_ctl = gen8_master_intr_disable(regs);
  2165. if (!master_ctl) {
  2166. gen8_master_intr_enable(regs);
  2167. return IRQ_NONE;
  2168. }
  2169. /* Find, queue (onto bottom-halves), then clear each source */
  2170. gen8_gt_irq_handler(to_gt(dev_priv), master_ctl);
  2171. /* IRQs are synced during runtime_suspend, we don't require a wakeref */
  2172. if (master_ctl & ~GEN8_GT_IRQS) {
  2173. disable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
  2174. gen8_de_irq_handler(dev_priv, master_ctl);
  2175. enable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
  2176. }
  2177. gen8_master_intr_enable(regs);
  2178. pmu_irq_stats(dev_priv, IRQ_HANDLED);
  2179. return IRQ_HANDLED;
  2180. }
  2181. static u32
  2182. gen11_gu_misc_irq_ack(struct drm_i915_private *i915, const u32 master_ctl)
  2183. {
  2184. void __iomem * const regs = i915->uncore.regs;
  2185. u32 iir;
  2186. if (!(master_ctl & GEN11_GU_MISC_IRQ))
  2187. return 0;
  2188. iir = raw_reg_read(regs, GEN11_GU_MISC_IIR);
  2189. if (likely(iir))
  2190. raw_reg_write(regs, GEN11_GU_MISC_IIR, iir);
  2191. return iir;
  2192. }
  2193. static void
  2194. gen11_gu_misc_irq_handler(struct drm_i915_private *i915, const u32 iir)
  2195. {
  2196. if (iir & GEN11_GU_MISC_GSE)
  2197. intel_opregion_asle_intr(i915);
  2198. }
  2199. static inline u32 gen11_master_intr_disable(void __iomem * const regs)
  2200. {
  2201. raw_reg_write(regs, GEN11_GFX_MSTR_IRQ, 0);
  2202. /*
  2203. * Now with master disabled, get a sample of level indications
  2204. * for this interrupt. Indications will be cleared on related acks.
  2205. * New indications can and will light up during processing,
  2206. * and will generate new interrupt after enabling master.
  2207. */
  2208. return raw_reg_read(regs, GEN11_GFX_MSTR_IRQ);
  2209. }
  2210. static inline void gen11_master_intr_enable(void __iomem * const regs)
  2211. {
  2212. raw_reg_write(regs, GEN11_GFX_MSTR_IRQ, GEN11_MASTER_IRQ);
  2213. }
  2214. static void
  2215. gen11_display_irq_handler(struct drm_i915_private *i915)
  2216. {
  2217. void __iomem * const regs = i915->uncore.regs;
  2218. const u32 disp_ctl = raw_reg_read(regs, GEN11_DISPLAY_INT_CTL);
  2219. disable_rpm_wakeref_asserts(&i915->runtime_pm);
  2220. /*
  2221. * GEN11_DISPLAY_INT_CTL has same format as GEN8_MASTER_IRQ
  2222. * for the display related bits.
  2223. */
  2224. raw_reg_write(regs, GEN11_DISPLAY_INT_CTL, 0x0);
  2225. gen8_de_irq_handler(i915, disp_ctl);
  2226. raw_reg_write(regs, GEN11_DISPLAY_INT_CTL,
  2227. GEN11_DISPLAY_IRQ_ENABLE);
  2228. enable_rpm_wakeref_asserts(&i915->runtime_pm);
  2229. }
  2230. static irqreturn_t gen11_irq_handler(int irq, void *arg)
  2231. {
  2232. struct drm_i915_private *i915 = arg;
  2233. void __iomem * const regs = i915->uncore.regs;
  2234. struct intel_gt *gt = to_gt(i915);
  2235. u32 master_ctl;
  2236. u32 gu_misc_iir;
  2237. if (!intel_irqs_enabled(i915))
  2238. return IRQ_NONE;
  2239. master_ctl = gen11_master_intr_disable(regs);
  2240. if (!master_ctl) {
  2241. gen11_master_intr_enable(regs);
  2242. return IRQ_NONE;
  2243. }
  2244. /* Find, queue (onto bottom-halves), then clear each source */
  2245. gen11_gt_irq_handler(gt, master_ctl);
  2246. /* IRQs are synced during runtime_suspend, we don't require a wakeref */
  2247. if (master_ctl & GEN11_DISPLAY_IRQ)
  2248. gen11_display_irq_handler(i915);
  2249. gu_misc_iir = gen11_gu_misc_irq_ack(i915, master_ctl);
  2250. gen11_master_intr_enable(regs);
  2251. gen11_gu_misc_irq_handler(i915, gu_misc_iir);
  2252. pmu_irq_stats(i915, IRQ_HANDLED);
  2253. return IRQ_HANDLED;
  2254. }
  2255. static inline u32 dg1_master_intr_disable(void __iomem * const regs)
  2256. {
  2257. u32 val;
  2258. /* First disable interrupts */
  2259. raw_reg_write(regs, DG1_MSTR_TILE_INTR, 0);
  2260. /* Get the indication levels and ack the master unit */
  2261. val = raw_reg_read(regs, DG1_MSTR_TILE_INTR);
  2262. if (unlikely(!val))
  2263. return 0;
  2264. raw_reg_write(regs, DG1_MSTR_TILE_INTR, val);
  2265. return val;
  2266. }
  2267. static inline void dg1_master_intr_enable(void __iomem * const regs)
  2268. {
  2269. raw_reg_write(regs, DG1_MSTR_TILE_INTR, DG1_MSTR_IRQ);
  2270. }
  2271. static irqreturn_t dg1_irq_handler(int irq, void *arg)
  2272. {
  2273. struct drm_i915_private * const i915 = arg;
  2274. struct intel_gt *gt = to_gt(i915);
  2275. void __iomem * const regs = gt->uncore->regs;
  2276. u32 master_tile_ctl, master_ctl;
  2277. u32 gu_misc_iir;
  2278. if (!intel_irqs_enabled(i915))
  2279. return IRQ_NONE;
  2280. master_tile_ctl = dg1_master_intr_disable(regs);
  2281. if (!master_tile_ctl) {
  2282. dg1_master_intr_enable(regs);
  2283. return IRQ_NONE;
  2284. }
  2285. /* FIXME: we only support tile 0 for now. */
  2286. if (master_tile_ctl & DG1_MSTR_TILE(0)) {
  2287. master_ctl = raw_reg_read(regs, GEN11_GFX_MSTR_IRQ);
  2288. raw_reg_write(regs, GEN11_GFX_MSTR_IRQ, master_ctl);
  2289. } else {
  2290. DRM_ERROR("Tile not supported: 0x%08x\n", master_tile_ctl);
  2291. dg1_master_intr_enable(regs);
  2292. return IRQ_NONE;
  2293. }
  2294. gen11_gt_irq_handler(gt, master_ctl);
  2295. if (master_ctl & GEN11_DISPLAY_IRQ)
  2296. gen11_display_irq_handler(i915);
  2297. gu_misc_iir = gen11_gu_misc_irq_ack(i915, master_ctl);
  2298. dg1_master_intr_enable(regs);
  2299. gen11_gu_misc_irq_handler(i915, gu_misc_iir);
  2300. pmu_irq_stats(i915, IRQ_HANDLED);
  2301. return IRQ_HANDLED;
  2302. }
  2303. /* Called from drm generic code, passed 'crtc' which
  2304. * we use as a pipe index
  2305. */
  2306. int i8xx_enable_vblank(struct drm_crtc *crtc)
  2307. {
  2308. struct drm_i915_private *dev_priv = to_i915(crtc->dev);
  2309. enum pipe pipe = to_intel_crtc(crtc)->pipe;
  2310. unsigned long irqflags;
  2311. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2312. i915_enable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_STATUS);
  2313. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2314. return 0;
  2315. }
  2316. int i915gm_enable_vblank(struct drm_crtc *crtc)
  2317. {
  2318. struct drm_i915_private *dev_priv = to_i915(crtc->dev);
  2319. /*
  2320. * Vblank interrupts fail to wake the device up from C2+.
  2321. * Disabling render clock gating during C-states avoids
  2322. * the problem. There is a small power cost so we do this
  2323. * only when vblank interrupts are actually enabled.
  2324. */
  2325. if (dev_priv->vblank_enabled++ == 0)
  2326. intel_uncore_write(&dev_priv->uncore, SCPD0, _MASKED_BIT_ENABLE(CSTATE_RENDER_CLOCK_GATE_DISABLE));
  2327. return i8xx_enable_vblank(crtc);
  2328. }
  2329. int i965_enable_vblank(struct drm_crtc *crtc)
  2330. {
  2331. struct drm_i915_private *dev_priv = to_i915(crtc->dev);
  2332. enum pipe pipe = to_intel_crtc(crtc)->pipe;
  2333. unsigned long irqflags;
  2334. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2335. i915_enable_pipestat(dev_priv, pipe,
  2336. PIPE_START_VBLANK_INTERRUPT_STATUS);
  2337. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2338. return 0;
  2339. }
  2340. int ilk_enable_vblank(struct drm_crtc *crtc)
  2341. {
  2342. struct drm_i915_private *dev_priv = to_i915(crtc->dev);
  2343. enum pipe pipe = to_intel_crtc(crtc)->pipe;
  2344. unsigned long irqflags;
  2345. u32 bit = DISPLAY_VER(dev_priv) >= 7 ?
  2346. DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe);
  2347. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2348. ilk_enable_display_irq(dev_priv, bit);
  2349. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2350. /* Even though there is no DMC, frame counter can get stuck when
  2351. * PSR is active as no frames are generated.
  2352. */
  2353. if (HAS_PSR(dev_priv))
  2354. drm_crtc_vblank_restore(crtc);
  2355. return 0;
  2356. }
  2357. static bool gen11_dsi_configure_te(struct intel_crtc *intel_crtc,
  2358. bool enable)
  2359. {
  2360. struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
  2361. enum port port;
  2362. u32 tmp;
  2363. if (!(intel_crtc->mode_flags &
  2364. (I915_MODE_FLAG_DSI_USE_TE1 | I915_MODE_FLAG_DSI_USE_TE0)))
  2365. return false;
  2366. /* for dual link cases we consider TE from slave */
  2367. if (intel_crtc->mode_flags & I915_MODE_FLAG_DSI_USE_TE1)
  2368. port = PORT_B;
  2369. else
  2370. port = PORT_A;
  2371. tmp = intel_uncore_read(&dev_priv->uncore, DSI_INTR_MASK_REG(port));
  2372. if (enable)
  2373. tmp &= ~DSI_TE_EVENT;
  2374. else
  2375. tmp |= DSI_TE_EVENT;
  2376. intel_uncore_write(&dev_priv->uncore, DSI_INTR_MASK_REG(port), tmp);
  2377. tmp = intel_uncore_read(&dev_priv->uncore, DSI_INTR_IDENT_REG(port));
  2378. intel_uncore_write(&dev_priv->uncore, DSI_INTR_IDENT_REG(port), tmp);
  2379. return true;
  2380. }
  2381. int bdw_enable_vblank(struct drm_crtc *_crtc)
  2382. {
  2383. struct intel_crtc *crtc = to_intel_crtc(_crtc);
  2384. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  2385. enum pipe pipe = crtc->pipe;
  2386. unsigned long irqflags;
  2387. if (gen11_dsi_configure_te(crtc, true))
  2388. return 0;
  2389. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2390. bdw_enable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK);
  2391. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2392. /* Even if there is no DMC, frame counter can get stuck when
  2393. * PSR is active as no frames are generated, so check only for PSR.
  2394. */
  2395. if (HAS_PSR(dev_priv))
  2396. drm_crtc_vblank_restore(&crtc->base);
  2397. return 0;
  2398. }
  2399. /* Called from drm generic code, passed 'crtc' which
  2400. * we use as a pipe index
  2401. */
  2402. void i8xx_disable_vblank(struct drm_crtc *crtc)
  2403. {
  2404. struct drm_i915_private *dev_priv = to_i915(crtc->dev);
  2405. enum pipe pipe = to_intel_crtc(crtc)->pipe;
  2406. unsigned long irqflags;
  2407. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2408. i915_disable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_STATUS);
  2409. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2410. }
  2411. void i915gm_disable_vblank(struct drm_crtc *crtc)
  2412. {
  2413. struct drm_i915_private *dev_priv = to_i915(crtc->dev);
  2414. i8xx_disable_vblank(crtc);
  2415. if (--dev_priv->vblank_enabled == 0)
  2416. intel_uncore_write(&dev_priv->uncore, SCPD0, _MASKED_BIT_DISABLE(CSTATE_RENDER_CLOCK_GATE_DISABLE));
  2417. }
  2418. void i965_disable_vblank(struct drm_crtc *crtc)
  2419. {
  2420. struct drm_i915_private *dev_priv = to_i915(crtc->dev);
  2421. enum pipe pipe = to_intel_crtc(crtc)->pipe;
  2422. unsigned long irqflags;
  2423. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2424. i915_disable_pipestat(dev_priv, pipe,
  2425. PIPE_START_VBLANK_INTERRUPT_STATUS);
  2426. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2427. }
  2428. void ilk_disable_vblank(struct drm_crtc *crtc)
  2429. {
  2430. struct drm_i915_private *dev_priv = to_i915(crtc->dev);
  2431. enum pipe pipe = to_intel_crtc(crtc)->pipe;
  2432. unsigned long irqflags;
  2433. u32 bit = DISPLAY_VER(dev_priv) >= 7 ?
  2434. DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe);
  2435. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2436. ilk_disable_display_irq(dev_priv, bit);
  2437. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2438. }
  2439. void bdw_disable_vblank(struct drm_crtc *_crtc)
  2440. {
  2441. struct intel_crtc *crtc = to_intel_crtc(_crtc);
  2442. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  2443. enum pipe pipe = crtc->pipe;
  2444. unsigned long irqflags;
  2445. if (gen11_dsi_configure_te(crtc, false))
  2446. return;
  2447. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2448. bdw_disable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK);
  2449. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2450. }
  2451. static void ibx_irq_reset(struct drm_i915_private *dev_priv)
  2452. {
  2453. struct intel_uncore *uncore = &dev_priv->uncore;
  2454. if (HAS_PCH_NOP(dev_priv))
  2455. return;
  2456. GEN3_IRQ_RESET(uncore, SDE);
  2457. if (HAS_PCH_CPT(dev_priv) || HAS_PCH_LPT(dev_priv))
  2458. intel_uncore_write(&dev_priv->uncore, SERR_INT, 0xffffffff);
  2459. }
  2460. static void vlv_display_irq_reset(struct drm_i915_private *dev_priv)
  2461. {
  2462. struct intel_uncore *uncore = &dev_priv->uncore;
  2463. if (IS_CHERRYVIEW(dev_priv))
  2464. intel_uncore_write(uncore, DPINVGTT, DPINVGTT_STATUS_MASK_CHV);
  2465. else
  2466. intel_uncore_write(uncore, DPINVGTT, DPINVGTT_STATUS_MASK_VLV);
  2467. i915_hotplug_interrupt_update_locked(dev_priv, 0xffffffff, 0);
  2468. intel_uncore_write(uncore, PORT_HOTPLUG_STAT, intel_uncore_read(&dev_priv->uncore, PORT_HOTPLUG_STAT));
  2469. i9xx_pipestat_irq_reset(dev_priv);
  2470. GEN3_IRQ_RESET(uncore, VLV_);
  2471. dev_priv->irq_mask = ~0u;
  2472. }
  2473. static void vlv_display_irq_postinstall(struct drm_i915_private *dev_priv)
  2474. {
  2475. struct intel_uncore *uncore = &dev_priv->uncore;
  2476. u32 pipestat_mask;
  2477. u32 enable_mask;
  2478. enum pipe pipe;
  2479. pipestat_mask = PIPE_CRC_DONE_INTERRUPT_STATUS;
  2480. i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
  2481. for_each_pipe(dev_priv, pipe)
  2482. i915_enable_pipestat(dev_priv, pipe, pipestat_mask);
  2483. enable_mask = I915_DISPLAY_PORT_INTERRUPT |
  2484. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  2485. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  2486. I915_LPE_PIPE_A_INTERRUPT |
  2487. I915_LPE_PIPE_B_INTERRUPT;
  2488. if (IS_CHERRYVIEW(dev_priv))
  2489. enable_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT |
  2490. I915_LPE_PIPE_C_INTERRUPT;
  2491. drm_WARN_ON(&dev_priv->drm, dev_priv->irq_mask != ~0u);
  2492. dev_priv->irq_mask = ~enable_mask;
  2493. GEN3_IRQ_INIT(uncore, VLV_, dev_priv->irq_mask, enable_mask);
  2494. }
  2495. /* drm_dma.h hooks
  2496. */
  2497. static void ilk_irq_reset(struct drm_i915_private *dev_priv)
  2498. {
  2499. struct intel_uncore *uncore = &dev_priv->uncore;
  2500. GEN3_IRQ_RESET(uncore, DE);
  2501. dev_priv->irq_mask = ~0u;
  2502. if (GRAPHICS_VER(dev_priv) == 7)
  2503. intel_uncore_write(uncore, GEN7_ERR_INT, 0xffffffff);
  2504. if (IS_HASWELL(dev_priv)) {
  2505. intel_uncore_write(uncore, EDP_PSR_IMR, 0xffffffff);
  2506. intel_uncore_write(uncore, EDP_PSR_IIR, 0xffffffff);
  2507. }
  2508. gen5_gt_irq_reset(to_gt(dev_priv));
  2509. ibx_irq_reset(dev_priv);
  2510. }
  2511. static void valleyview_irq_reset(struct drm_i915_private *dev_priv)
  2512. {
  2513. intel_uncore_write(&dev_priv->uncore, VLV_MASTER_IER, 0);
  2514. intel_uncore_posting_read(&dev_priv->uncore, VLV_MASTER_IER);
  2515. gen5_gt_irq_reset(to_gt(dev_priv));
  2516. spin_lock_irq(&dev_priv->irq_lock);
  2517. if (dev_priv->display_irqs_enabled)
  2518. vlv_display_irq_reset(dev_priv);
  2519. spin_unlock_irq(&dev_priv->irq_lock);
  2520. }
  2521. static void gen8_display_irq_reset(struct drm_i915_private *dev_priv)
  2522. {
  2523. struct intel_uncore *uncore = &dev_priv->uncore;
  2524. enum pipe pipe;
  2525. if (!HAS_DISPLAY(dev_priv))
  2526. return;
  2527. intel_uncore_write(uncore, EDP_PSR_IMR, 0xffffffff);
  2528. intel_uncore_write(uncore, EDP_PSR_IIR, 0xffffffff);
  2529. for_each_pipe(dev_priv, pipe)
  2530. if (intel_display_power_is_enabled(dev_priv,
  2531. POWER_DOMAIN_PIPE(pipe)))
  2532. GEN8_IRQ_RESET_NDX(uncore, DE_PIPE, pipe);
  2533. GEN3_IRQ_RESET(uncore, GEN8_DE_PORT_);
  2534. GEN3_IRQ_RESET(uncore, GEN8_DE_MISC_);
  2535. }
  2536. static void gen8_irq_reset(struct drm_i915_private *dev_priv)
  2537. {
  2538. struct intel_uncore *uncore = &dev_priv->uncore;
  2539. gen8_master_intr_disable(dev_priv->uncore.regs);
  2540. gen8_gt_irq_reset(to_gt(dev_priv));
  2541. gen8_display_irq_reset(dev_priv);
  2542. GEN3_IRQ_RESET(uncore, GEN8_PCU_);
  2543. if (HAS_PCH_SPLIT(dev_priv))
  2544. ibx_irq_reset(dev_priv);
  2545. }
  2546. static void gen11_display_irq_reset(struct drm_i915_private *dev_priv)
  2547. {
  2548. struct intel_uncore *uncore = &dev_priv->uncore;
  2549. enum pipe pipe;
  2550. u32 trans_mask = BIT(TRANSCODER_A) | BIT(TRANSCODER_B) |
  2551. BIT(TRANSCODER_C) | BIT(TRANSCODER_D);
  2552. if (!HAS_DISPLAY(dev_priv))
  2553. return;
  2554. intel_uncore_write(uncore, GEN11_DISPLAY_INT_CTL, 0);
  2555. if (DISPLAY_VER(dev_priv) >= 12) {
  2556. enum transcoder trans;
  2557. for_each_cpu_transcoder_masked(dev_priv, trans, trans_mask) {
  2558. enum intel_display_power_domain domain;
  2559. domain = POWER_DOMAIN_TRANSCODER(trans);
  2560. if (!intel_display_power_is_enabled(dev_priv, domain))
  2561. continue;
  2562. intel_uncore_write(uncore, TRANS_PSR_IMR(trans), 0xffffffff);
  2563. intel_uncore_write(uncore, TRANS_PSR_IIR(trans), 0xffffffff);
  2564. }
  2565. } else {
  2566. intel_uncore_write(uncore, EDP_PSR_IMR, 0xffffffff);
  2567. intel_uncore_write(uncore, EDP_PSR_IIR, 0xffffffff);
  2568. }
  2569. for_each_pipe(dev_priv, pipe)
  2570. if (intel_display_power_is_enabled(dev_priv,
  2571. POWER_DOMAIN_PIPE(pipe)))
  2572. GEN8_IRQ_RESET_NDX(uncore, DE_PIPE, pipe);
  2573. GEN3_IRQ_RESET(uncore, GEN8_DE_PORT_);
  2574. GEN3_IRQ_RESET(uncore, GEN8_DE_MISC_);
  2575. GEN3_IRQ_RESET(uncore, GEN11_DE_HPD_);
  2576. if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
  2577. GEN3_IRQ_RESET(uncore, SDE);
  2578. }
  2579. static void gen11_irq_reset(struct drm_i915_private *dev_priv)
  2580. {
  2581. struct intel_gt *gt = to_gt(dev_priv);
  2582. struct intel_uncore *uncore = gt->uncore;
  2583. gen11_master_intr_disable(dev_priv->uncore.regs);
  2584. gen11_gt_irq_reset(gt);
  2585. gen11_display_irq_reset(dev_priv);
  2586. GEN3_IRQ_RESET(uncore, GEN11_GU_MISC_);
  2587. GEN3_IRQ_RESET(uncore, GEN8_PCU_);
  2588. }
  2589. static void dg1_irq_reset(struct drm_i915_private *dev_priv)
  2590. {
  2591. struct intel_gt *gt = to_gt(dev_priv);
  2592. struct intel_uncore *uncore = gt->uncore;
  2593. dg1_master_intr_disable(dev_priv->uncore.regs);
  2594. gen11_gt_irq_reset(gt);
  2595. gen11_display_irq_reset(dev_priv);
  2596. GEN3_IRQ_RESET(uncore, GEN11_GU_MISC_);
  2597. GEN3_IRQ_RESET(uncore, GEN8_PCU_);
  2598. }
  2599. void gen8_irq_power_well_post_enable(struct drm_i915_private *dev_priv,
  2600. u8 pipe_mask)
  2601. {
  2602. struct intel_uncore *uncore = &dev_priv->uncore;
  2603. u32 extra_ier = GEN8_PIPE_VBLANK |
  2604. gen8_de_pipe_underrun_mask(dev_priv) |
  2605. gen8_de_pipe_flip_done_mask(dev_priv);
  2606. enum pipe pipe;
  2607. spin_lock_irq(&dev_priv->irq_lock);
  2608. if (!intel_irqs_enabled(dev_priv)) {
  2609. spin_unlock_irq(&dev_priv->irq_lock);
  2610. return;
  2611. }
  2612. for_each_pipe_masked(dev_priv, pipe, pipe_mask)
  2613. GEN8_IRQ_INIT_NDX(uncore, DE_PIPE, pipe,
  2614. dev_priv->de_irq_mask[pipe],
  2615. ~dev_priv->de_irq_mask[pipe] | extra_ier);
  2616. spin_unlock_irq(&dev_priv->irq_lock);
  2617. }
  2618. void gen8_irq_power_well_pre_disable(struct drm_i915_private *dev_priv,
  2619. u8 pipe_mask)
  2620. {
  2621. struct intel_uncore *uncore = &dev_priv->uncore;
  2622. enum pipe pipe;
  2623. spin_lock_irq(&dev_priv->irq_lock);
  2624. if (!intel_irqs_enabled(dev_priv)) {
  2625. spin_unlock_irq(&dev_priv->irq_lock);
  2626. return;
  2627. }
  2628. for_each_pipe_masked(dev_priv, pipe, pipe_mask)
  2629. GEN8_IRQ_RESET_NDX(uncore, DE_PIPE, pipe);
  2630. spin_unlock_irq(&dev_priv->irq_lock);
  2631. /* make sure we're done processing display irqs */
  2632. intel_synchronize_irq(dev_priv);
  2633. }
  2634. static void cherryview_irq_reset(struct drm_i915_private *dev_priv)
  2635. {
  2636. struct intel_uncore *uncore = &dev_priv->uncore;
  2637. intel_uncore_write(&dev_priv->uncore, GEN8_MASTER_IRQ, 0);
  2638. intel_uncore_posting_read(&dev_priv->uncore, GEN8_MASTER_IRQ);
  2639. gen8_gt_irq_reset(to_gt(dev_priv));
  2640. GEN3_IRQ_RESET(uncore, GEN8_PCU_);
  2641. spin_lock_irq(&dev_priv->irq_lock);
  2642. if (dev_priv->display_irqs_enabled)
  2643. vlv_display_irq_reset(dev_priv);
  2644. spin_unlock_irq(&dev_priv->irq_lock);
  2645. }
  2646. static u32 ibx_hotplug_enables(struct drm_i915_private *i915,
  2647. enum hpd_pin pin)
  2648. {
  2649. switch (pin) {
  2650. case HPD_PORT_A:
  2651. /*
  2652. * When CPU and PCH are on the same package, port A
  2653. * HPD must be enabled in both north and south.
  2654. */
  2655. return HAS_PCH_LPT_LP(i915) ?
  2656. PORTA_HOTPLUG_ENABLE : 0;
  2657. case HPD_PORT_B:
  2658. return PORTB_HOTPLUG_ENABLE |
  2659. PORTB_PULSE_DURATION_2ms;
  2660. case HPD_PORT_C:
  2661. return PORTC_HOTPLUG_ENABLE |
  2662. PORTC_PULSE_DURATION_2ms;
  2663. case HPD_PORT_D:
  2664. return PORTD_HOTPLUG_ENABLE |
  2665. PORTD_PULSE_DURATION_2ms;
  2666. default:
  2667. return 0;
  2668. }
  2669. }
  2670. static void ibx_hpd_detection_setup(struct drm_i915_private *dev_priv)
  2671. {
  2672. u32 hotplug;
  2673. /*
  2674. * Enable digital hotplug on the PCH, and configure the DP short pulse
  2675. * duration to 2ms (which is the minimum in the Display Port spec).
  2676. * The pulse duration bits are reserved on LPT+.
  2677. */
  2678. hotplug = intel_uncore_read(&dev_priv->uncore, PCH_PORT_HOTPLUG);
  2679. hotplug &= ~(PORTA_HOTPLUG_ENABLE |
  2680. PORTB_HOTPLUG_ENABLE |
  2681. PORTC_HOTPLUG_ENABLE |
  2682. PORTD_HOTPLUG_ENABLE |
  2683. PORTB_PULSE_DURATION_MASK |
  2684. PORTC_PULSE_DURATION_MASK |
  2685. PORTD_PULSE_DURATION_MASK);
  2686. hotplug |= intel_hpd_hotplug_enables(dev_priv, ibx_hotplug_enables);
  2687. intel_uncore_write(&dev_priv->uncore, PCH_PORT_HOTPLUG, hotplug);
  2688. }
  2689. static void ibx_hpd_irq_setup(struct drm_i915_private *dev_priv)
  2690. {
  2691. u32 hotplug_irqs, enabled_irqs;
  2692. enabled_irqs = intel_hpd_enabled_irqs(dev_priv, dev_priv->display.hotplug.pch_hpd);
  2693. hotplug_irqs = intel_hpd_hotplug_irqs(dev_priv, dev_priv->display.hotplug.pch_hpd);
  2694. ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
  2695. ibx_hpd_detection_setup(dev_priv);
  2696. }
  2697. static u32 icp_ddi_hotplug_enables(struct drm_i915_private *i915,
  2698. enum hpd_pin pin)
  2699. {
  2700. switch (pin) {
  2701. case HPD_PORT_A:
  2702. case HPD_PORT_B:
  2703. case HPD_PORT_C:
  2704. case HPD_PORT_D:
  2705. return SHOTPLUG_CTL_DDI_HPD_ENABLE(pin);
  2706. default:
  2707. return 0;
  2708. }
  2709. }
  2710. static u32 icp_tc_hotplug_enables(struct drm_i915_private *i915,
  2711. enum hpd_pin pin)
  2712. {
  2713. switch (pin) {
  2714. case HPD_PORT_TC1:
  2715. case HPD_PORT_TC2:
  2716. case HPD_PORT_TC3:
  2717. case HPD_PORT_TC4:
  2718. case HPD_PORT_TC5:
  2719. case HPD_PORT_TC6:
  2720. return ICP_TC_HPD_ENABLE(pin);
  2721. default:
  2722. return 0;
  2723. }
  2724. }
  2725. static void icp_ddi_hpd_detection_setup(struct drm_i915_private *dev_priv)
  2726. {
  2727. u32 hotplug;
  2728. hotplug = intel_uncore_read(&dev_priv->uncore, SHOTPLUG_CTL_DDI);
  2729. hotplug &= ~(SHOTPLUG_CTL_DDI_HPD_ENABLE(HPD_PORT_A) |
  2730. SHOTPLUG_CTL_DDI_HPD_ENABLE(HPD_PORT_B) |
  2731. SHOTPLUG_CTL_DDI_HPD_ENABLE(HPD_PORT_C) |
  2732. SHOTPLUG_CTL_DDI_HPD_ENABLE(HPD_PORT_D));
  2733. hotplug |= intel_hpd_hotplug_enables(dev_priv, icp_ddi_hotplug_enables);
  2734. intel_uncore_write(&dev_priv->uncore, SHOTPLUG_CTL_DDI, hotplug);
  2735. }
  2736. static void icp_tc_hpd_detection_setup(struct drm_i915_private *dev_priv)
  2737. {
  2738. u32 hotplug;
  2739. hotplug = intel_uncore_read(&dev_priv->uncore, SHOTPLUG_CTL_TC);
  2740. hotplug &= ~(ICP_TC_HPD_ENABLE(HPD_PORT_TC1) |
  2741. ICP_TC_HPD_ENABLE(HPD_PORT_TC2) |
  2742. ICP_TC_HPD_ENABLE(HPD_PORT_TC3) |
  2743. ICP_TC_HPD_ENABLE(HPD_PORT_TC4) |
  2744. ICP_TC_HPD_ENABLE(HPD_PORT_TC5) |
  2745. ICP_TC_HPD_ENABLE(HPD_PORT_TC6));
  2746. hotplug |= intel_hpd_hotplug_enables(dev_priv, icp_tc_hotplug_enables);
  2747. intel_uncore_write(&dev_priv->uncore, SHOTPLUG_CTL_TC, hotplug);
  2748. }
  2749. static void icp_hpd_irq_setup(struct drm_i915_private *dev_priv)
  2750. {
  2751. u32 hotplug_irqs, enabled_irqs;
  2752. enabled_irqs = intel_hpd_enabled_irqs(dev_priv, dev_priv->display.hotplug.pch_hpd);
  2753. hotplug_irqs = intel_hpd_hotplug_irqs(dev_priv, dev_priv->display.hotplug.pch_hpd);
  2754. if (INTEL_PCH_TYPE(dev_priv) <= PCH_TGP)
  2755. intel_uncore_write(&dev_priv->uncore, SHPD_FILTER_CNT, SHPD_FILTER_CNT_500_ADJ);
  2756. ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
  2757. icp_ddi_hpd_detection_setup(dev_priv);
  2758. icp_tc_hpd_detection_setup(dev_priv);
  2759. }
  2760. static u32 gen11_hotplug_enables(struct drm_i915_private *i915,
  2761. enum hpd_pin pin)
  2762. {
  2763. switch (pin) {
  2764. case HPD_PORT_TC1:
  2765. case HPD_PORT_TC2:
  2766. case HPD_PORT_TC3:
  2767. case HPD_PORT_TC4:
  2768. case HPD_PORT_TC5:
  2769. case HPD_PORT_TC6:
  2770. return GEN11_HOTPLUG_CTL_ENABLE(pin);
  2771. default:
  2772. return 0;
  2773. }
  2774. }
  2775. static void dg1_hpd_irq_setup(struct drm_i915_private *dev_priv)
  2776. {
  2777. u32 val;
  2778. val = intel_uncore_read(&dev_priv->uncore, SOUTH_CHICKEN1);
  2779. val |= (INVERT_DDIA_HPD |
  2780. INVERT_DDIB_HPD |
  2781. INVERT_DDIC_HPD |
  2782. INVERT_DDID_HPD);
  2783. intel_uncore_write(&dev_priv->uncore, SOUTH_CHICKEN1, val);
  2784. icp_hpd_irq_setup(dev_priv);
  2785. }
  2786. static void gen11_tc_hpd_detection_setup(struct drm_i915_private *dev_priv)
  2787. {
  2788. u32 hotplug;
  2789. hotplug = intel_uncore_read(&dev_priv->uncore, GEN11_TC_HOTPLUG_CTL);
  2790. hotplug &= ~(GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC1) |
  2791. GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC2) |
  2792. GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC3) |
  2793. GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC4) |
  2794. GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC5) |
  2795. GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC6));
  2796. hotplug |= intel_hpd_hotplug_enables(dev_priv, gen11_hotplug_enables);
  2797. intel_uncore_write(&dev_priv->uncore, GEN11_TC_HOTPLUG_CTL, hotplug);
  2798. }
  2799. static void gen11_tbt_hpd_detection_setup(struct drm_i915_private *dev_priv)
  2800. {
  2801. u32 hotplug;
  2802. hotplug = intel_uncore_read(&dev_priv->uncore, GEN11_TBT_HOTPLUG_CTL);
  2803. hotplug &= ~(GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC1) |
  2804. GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC2) |
  2805. GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC3) |
  2806. GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC4) |
  2807. GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC5) |
  2808. GEN11_HOTPLUG_CTL_ENABLE(HPD_PORT_TC6));
  2809. hotplug |= intel_hpd_hotplug_enables(dev_priv, gen11_hotplug_enables);
  2810. intel_uncore_write(&dev_priv->uncore, GEN11_TBT_HOTPLUG_CTL, hotplug);
  2811. }
  2812. static void gen11_hpd_irq_setup(struct drm_i915_private *dev_priv)
  2813. {
  2814. u32 hotplug_irqs, enabled_irqs;
  2815. u32 val;
  2816. enabled_irqs = intel_hpd_enabled_irqs(dev_priv, dev_priv->display.hotplug.hpd);
  2817. hotplug_irqs = intel_hpd_hotplug_irqs(dev_priv, dev_priv->display.hotplug.hpd);
  2818. val = intel_uncore_read(&dev_priv->uncore, GEN11_DE_HPD_IMR);
  2819. val &= ~hotplug_irqs;
  2820. val |= ~enabled_irqs & hotplug_irqs;
  2821. intel_uncore_write(&dev_priv->uncore, GEN11_DE_HPD_IMR, val);
  2822. intel_uncore_posting_read(&dev_priv->uncore, GEN11_DE_HPD_IMR);
  2823. gen11_tc_hpd_detection_setup(dev_priv);
  2824. gen11_tbt_hpd_detection_setup(dev_priv);
  2825. if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
  2826. icp_hpd_irq_setup(dev_priv);
  2827. }
  2828. static u32 spt_hotplug_enables(struct drm_i915_private *i915,
  2829. enum hpd_pin pin)
  2830. {
  2831. switch (pin) {
  2832. case HPD_PORT_A:
  2833. return PORTA_HOTPLUG_ENABLE;
  2834. case HPD_PORT_B:
  2835. return PORTB_HOTPLUG_ENABLE;
  2836. case HPD_PORT_C:
  2837. return PORTC_HOTPLUG_ENABLE;
  2838. case HPD_PORT_D:
  2839. return PORTD_HOTPLUG_ENABLE;
  2840. default:
  2841. return 0;
  2842. }
  2843. }
  2844. static u32 spt_hotplug2_enables(struct drm_i915_private *i915,
  2845. enum hpd_pin pin)
  2846. {
  2847. switch (pin) {
  2848. case HPD_PORT_E:
  2849. return PORTE_HOTPLUG_ENABLE;
  2850. default:
  2851. return 0;
  2852. }
  2853. }
  2854. static void spt_hpd_detection_setup(struct drm_i915_private *dev_priv)
  2855. {
  2856. u32 val, hotplug;
  2857. /* Display WA #1179 WaHardHangonHotPlug: cnp */
  2858. if (HAS_PCH_CNP(dev_priv)) {
  2859. val = intel_uncore_read(&dev_priv->uncore, SOUTH_CHICKEN1);
  2860. val &= ~CHASSIS_CLK_REQ_DURATION_MASK;
  2861. val |= CHASSIS_CLK_REQ_DURATION(0xf);
  2862. intel_uncore_write(&dev_priv->uncore, SOUTH_CHICKEN1, val);
  2863. }
  2864. /* Enable digital hotplug on the PCH */
  2865. hotplug = intel_uncore_read(&dev_priv->uncore, PCH_PORT_HOTPLUG);
  2866. hotplug &= ~(PORTA_HOTPLUG_ENABLE |
  2867. PORTB_HOTPLUG_ENABLE |
  2868. PORTC_HOTPLUG_ENABLE |
  2869. PORTD_HOTPLUG_ENABLE);
  2870. hotplug |= intel_hpd_hotplug_enables(dev_priv, spt_hotplug_enables);
  2871. intel_uncore_write(&dev_priv->uncore, PCH_PORT_HOTPLUG, hotplug);
  2872. hotplug = intel_uncore_read(&dev_priv->uncore, PCH_PORT_HOTPLUG2);
  2873. hotplug &= ~PORTE_HOTPLUG_ENABLE;
  2874. hotplug |= intel_hpd_hotplug_enables(dev_priv, spt_hotplug2_enables);
  2875. intel_uncore_write(&dev_priv->uncore, PCH_PORT_HOTPLUG2, hotplug);
  2876. }
  2877. static void spt_hpd_irq_setup(struct drm_i915_private *dev_priv)
  2878. {
  2879. u32 hotplug_irqs, enabled_irqs;
  2880. if (INTEL_PCH_TYPE(dev_priv) >= PCH_CNP)
  2881. intel_uncore_write(&dev_priv->uncore, SHPD_FILTER_CNT, SHPD_FILTER_CNT_500_ADJ);
  2882. enabled_irqs = intel_hpd_enabled_irqs(dev_priv, dev_priv->display.hotplug.pch_hpd);
  2883. hotplug_irqs = intel_hpd_hotplug_irqs(dev_priv, dev_priv->display.hotplug.pch_hpd);
  2884. ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
  2885. spt_hpd_detection_setup(dev_priv);
  2886. }
  2887. static u32 ilk_hotplug_enables(struct drm_i915_private *i915,
  2888. enum hpd_pin pin)
  2889. {
  2890. switch (pin) {
  2891. case HPD_PORT_A:
  2892. return DIGITAL_PORTA_HOTPLUG_ENABLE |
  2893. DIGITAL_PORTA_PULSE_DURATION_2ms;
  2894. default:
  2895. return 0;
  2896. }
  2897. }
  2898. static void ilk_hpd_detection_setup(struct drm_i915_private *dev_priv)
  2899. {
  2900. u32 hotplug;
  2901. /*
  2902. * Enable digital hotplug on the CPU, and configure the DP short pulse
  2903. * duration to 2ms (which is the minimum in the Display Port spec)
  2904. * The pulse duration bits are reserved on HSW+.
  2905. */
  2906. hotplug = intel_uncore_read(&dev_priv->uncore, DIGITAL_PORT_HOTPLUG_CNTRL);
  2907. hotplug &= ~(DIGITAL_PORTA_HOTPLUG_ENABLE |
  2908. DIGITAL_PORTA_PULSE_DURATION_MASK);
  2909. hotplug |= intel_hpd_hotplug_enables(dev_priv, ilk_hotplug_enables);
  2910. intel_uncore_write(&dev_priv->uncore, DIGITAL_PORT_HOTPLUG_CNTRL, hotplug);
  2911. }
  2912. static void ilk_hpd_irq_setup(struct drm_i915_private *dev_priv)
  2913. {
  2914. u32 hotplug_irqs, enabled_irqs;
  2915. enabled_irqs = intel_hpd_enabled_irqs(dev_priv, dev_priv->display.hotplug.hpd);
  2916. hotplug_irqs = intel_hpd_hotplug_irqs(dev_priv, dev_priv->display.hotplug.hpd);
  2917. if (DISPLAY_VER(dev_priv) >= 8)
  2918. bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
  2919. else
  2920. ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
  2921. ilk_hpd_detection_setup(dev_priv);
  2922. ibx_hpd_irq_setup(dev_priv);
  2923. }
  2924. static u32 bxt_hotplug_enables(struct drm_i915_private *i915,
  2925. enum hpd_pin pin)
  2926. {
  2927. u32 hotplug;
  2928. switch (pin) {
  2929. case HPD_PORT_A:
  2930. hotplug = PORTA_HOTPLUG_ENABLE;
  2931. if (intel_bios_is_port_hpd_inverted(i915, PORT_A))
  2932. hotplug |= BXT_DDIA_HPD_INVERT;
  2933. return hotplug;
  2934. case HPD_PORT_B:
  2935. hotplug = PORTB_HOTPLUG_ENABLE;
  2936. if (intel_bios_is_port_hpd_inverted(i915, PORT_B))
  2937. hotplug |= BXT_DDIB_HPD_INVERT;
  2938. return hotplug;
  2939. case HPD_PORT_C:
  2940. hotplug = PORTC_HOTPLUG_ENABLE;
  2941. if (intel_bios_is_port_hpd_inverted(i915, PORT_C))
  2942. hotplug |= BXT_DDIC_HPD_INVERT;
  2943. return hotplug;
  2944. default:
  2945. return 0;
  2946. }
  2947. }
  2948. static void bxt_hpd_detection_setup(struct drm_i915_private *dev_priv)
  2949. {
  2950. u32 hotplug;
  2951. hotplug = intel_uncore_read(&dev_priv->uncore, PCH_PORT_HOTPLUG);
  2952. hotplug &= ~(PORTA_HOTPLUG_ENABLE |
  2953. PORTB_HOTPLUG_ENABLE |
  2954. PORTC_HOTPLUG_ENABLE |
  2955. BXT_DDIA_HPD_INVERT |
  2956. BXT_DDIB_HPD_INVERT |
  2957. BXT_DDIC_HPD_INVERT);
  2958. hotplug |= intel_hpd_hotplug_enables(dev_priv, bxt_hotplug_enables);
  2959. intel_uncore_write(&dev_priv->uncore, PCH_PORT_HOTPLUG, hotplug);
  2960. }
  2961. static void bxt_hpd_irq_setup(struct drm_i915_private *dev_priv)
  2962. {
  2963. u32 hotplug_irqs, enabled_irqs;
  2964. enabled_irqs = intel_hpd_enabled_irqs(dev_priv, dev_priv->display.hotplug.hpd);
  2965. hotplug_irqs = intel_hpd_hotplug_irqs(dev_priv, dev_priv->display.hotplug.hpd);
  2966. bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
  2967. bxt_hpd_detection_setup(dev_priv);
  2968. }
  2969. /*
  2970. * SDEIER is also touched by the interrupt handler to work around missed PCH
  2971. * interrupts. Hence we can't update it after the interrupt handler is enabled -
  2972. * instead we unconditionally enable all PCH interrupt sources here, but then
  2973. * only unmask them as needed with SDEIMR.
  2974. *
  2975. * Note that we currently do this after installing the interrupt handler,
  2976. * but before we enable the master interrupt. That should be sufficient
  2977. * to avoid races with the irq handler, assuming we have MSI. Shared legacy
  2978. * interrupts could still race.
  2979. */
  2980. static void ibx_irq_postinstall(struct drm_i915_private *dev_priv)
  2981. {
  2982. struct intel_uncore *uncore = &dev_priv->uncore;
  2983. u32 mask;
  2984. if (HAS_PCH_NOP(dev_priv))
  2985. return;
  2986. if (HAS_PCH_IBX(dev_priv))
  2987. mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON;
  2988. else if (HAS_PCH_CPT(dev_priv) || HAS_PCH_LPT(dev_priv))
  2989. mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT;
  2990. else
  2991. mask = SDE_GMBUS_CPT;
  2992. GEN3_IRQ_INIT(uncore, SDE, ~mask, 0xffffffff);
  2993. }
  2994. static void ilk_irq_postinstall(struct drm_i915_private *dev_priv)
  2995. {
  2996. struct intel_uncore *uncore = &dev_priv->uncore;
  2997. u32 display_mask, extra_mask;
  2998. if (GRAPHICS_VER(dev_priv) >= 7) {
  2999. display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
  3000. DE_PCH_EVENT_IVB | DE_AUX_CHANNEL_A_IVB);
  3001. extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
  3002. DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB |
  3003. DE_PLANE_FLIP_DONE_IVB(PLANE_C) |
  3004. DE_PLANE_FLIP_DONE_IVB(PLANE_B) |
  3005. DE_PLANE_FLIP_DONE_IVB(PLANE_A) |
  3006. DE_DP_A_HOTPLUG_IVB);
  3007. } else {
  3008. display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
  3009. DE_AUX_CHANNEL_A | DE_PIPEB_CRC_DONE |
  3010. DE_PIPEA_CRC_DONE | DE_POISON);
  3011. extra_mask = (DE_PIPEA_VBLANK | DE_PIPEB_VBLANK |
  3012. DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN |
  3013. DE_PLANE_FLIP_DONE(PLANE_A) |
  3014. DE_PLANE_FLIP_DONE(PLANE_B) |
  3015. DE_DP_A_HOTPLUG);
  3016. }
  3017. if (IS_HASWELL(dev_priv)) {
  3018. gen3_assert_iir_is_zero(uncore, EDP_PSR_IIR);
  3019. display_mask |= DE_EDP_PSR_INT_HSW;
  3020. }
  3021. if (IS_IRONLAKE_M(dev_priv))
  3022. extra_mask |= DE_PCU_EVENT;
  3023. dev_priv->irq_mask = ~display_mask;
  3024. ibx_irq_postinstall(dev_priv);
  3025. gen5_gt_irq_postinstall(to_gt(dev_priv));
  3026. GEN3_IRQ_INIT(uncore, DE, dev_priv->irq_mask,
  3027. display_mask | extra_mask);
  3028. }
  3029. void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv)
  3030. {
  3031. lockdep_assert_held(&dev_priv->irq_lock);
  3032. if (dev_priv->display_irqs_enabled)
  3033. return;
  3034. dev_priv->display_irqs_enabled = true;
  3035. if (intel_irqs_enabled(dev_priv)) {
  3036. vlv_display_irq_reset(dev_priv);
  3037. vlv_display_irq_postinstall(dev_priv);
  3038. }
  3039. }
  3040. void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv)
  3041. {
  3042. lockdep_assert_held(&dev_priv->irq_lock);
  3043. if (!dev_priv->display_irqs_enabled)
  3044. return;
  3045. dev_priv->display_irqs_enabled = false;
  3046. if (intel_irqs_enabled(dev_priv))
  3047. vlv_display_irq_reset(dev_priv);
  3048. }
  3049. static void valleyview_irq_postinstall(struct drm_i915_private *dev_priv)
  3050. {
  3051. gen5_gt_irq_postinstall(to_gt(dev_priv));
  3052. spin_lock_irq(&dev_priv->irq_lock);
  3053. if (dev_priv->display_irqs_enabled)
  3054. vlv_display_irq_postinstall(dev_priv);
  3055. spin_unlock_irq(&dev_priv->irq_lock);
  3056. intel_uncore_write(&dev_priv->uncore, VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
  3057. intel_uncore_posting_read(&dev_priv->uncore, VLV_MASTER_IER);
  3058. }
  3059. static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
  3060. {
  3061. struct intel_uncore *uncore = &dev_priv->uncore;
  3062. u32 de_pipe_masked = gen8_de_pipe_fault_mask(dev_priv) |
  3063. GEN8_PIPE_CDCLK_CRC_DONE;
  3064. u32 de_pipe_enables;
  3065. u32 de_port_masked = gen8_de_port_aux_mask(dev_priv);
  3066. u32 de_port_enables;
  3067. u32 de_misc_masked = GEN8_DE_EDP_PSR;
  3068. u32 trans_mask = BIT(TRANSCODER_A) | BIT(TRANSCODER_B) |
  3069. BIT(TRANSCODER_C) | BIT(TRANSCODER_D);
  3070. enum pipe pipe;
  3071. if (!HAS_DISPLAY(dev_priv))
  3072. return;
  3073. if (DISPLAY_VER(dev_priv) <= 10)
  3074. de_misc_masked |= GEN8_DE_MISC_GSE;
  3075. if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
  3076. de_port_masked |= BXT_DE_PORT_GMBUS;
  3077. if (DISPLAY_VER(dev_priv) >= 11) {
  3078. enum port port;
  3079. if (intel_bios_is_dsi_present(dev_priv, &port))
  3080. de_port_masked |= DSI0_TE | DSI1_TE;
  3081. }
  3082. de_pipe_enables = de_pipe_masked |
  3083. GEN8_PIPE_VBLANK |
  3084. gen8_de_pipe_underrun_mask(dev_priv) |
  3085. gen8_de_pipe_flip_done_mask(dev_priv);
  3086. de_port_enables = de_port_masked;
  3087. if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
  3088. de_port_enables |= BXT_DE_PORT_HOTPLUG_MASK;
  3089. else if (IS_BROADWELL(dev_priv))
  3090. de_port_enables |= BDW_DE_PORT_HOTPLUG_MASK;
  3091. if (DISPLAY_VER(dev_priv) >= 12) {
  3092. enum transcoder trans;
  3093. for_each_cpu_transcoder_masked(dev_priv, trans, trans_mask) {
  3094. enum intel_display_power_domain domain;
  3095. domain = POWER_DOMAIN_TRANSCODER(trans);
  3096. if (!intel_display_power_is_enabled(dev_priv, domain))
  3097. continue;
  3098. gen3_assert_iir_is_zero(uncore, TRANS_PSR_IIR(trans));
  3099. }
  3100. } else {
  3101. gen3_assert_iir_is_zero(uncore, EDP_PSR_IIR);
  3102. }
  3103. for_each_pipe(dev_priv, pipe) {
  3104. dev_priv->de_irq_mask[pipe] = ~de_pipe_masked;
  3105. if (intel_display_power_is_enabled(dev_priv,
  3106. POWER_DOMAIN_PIPE(pipe)))
  3107. GEN8_IRQ_INIT_NDX(uncore, DE_PIPE, pipe,
  3108. dev_priv->de_irq_mask[pipe],
  3109. de_pipe_enables);
  3110. }
  3111. GEN3_IRQ_INIT(uncore, GEN8_DE_PORT_, ~de_port_masked, de_port_enables);
  3112. GEN3_IRQ_INIT(uncore, GEN8_DE_MISC_, ~de_misc_masked, de_misc_masked);
  3113. if (DISPLAY_VER(dev_priv) >= 11) {
  3114. u32 de_hpd_masked = 0;
  3115. u32 de_hpd_enables = GEN11_DE_TC_HOTPLUG_MASK |
  3116. GEN11_DE_TBT_HOTPLUG_MASK;
  3117. GEN3_IRQ_INIT(uncore, GEN11_DE_HPD_, ~de_hpd_masked,
  3118. de_hpd_enables);
  3119. }
  3120. }
  3121. static void icp_irq_postinstall(struct drm_i915_private *dev_priv)
  3122. {
  3123. struct intel_uncore *uncore = &dev_priv->uncore;
  3124. u32 mask = SDE_GMBUS_ICP;
  3125. GEN3_IRQ_INIT(uncore, SDE, ~mask, 0xffffffff);
  3126. }
  3127. static void gen8_irq_postinstall(struct drm_i915_private *dev_priv)
  3128. {
  3129. if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
  3130. icp_irq_postinstall(dev_priv);
  3131. else if (HAS_PCH_SPLIT(dev_priv))
  3132. ibx_irq_postinstall(dev_priv);
  3133. gen8_gt_irq_postinstall(to_gt(dev_priv));
  3134. gen8_de_irq_postinstall(dev_priv);
  3135. gen8_master_intr_enable(dev_priv->uncore.regs);
  3136. }
  3137. static void gen11_de_irq_postinstall(struct drm_i915_private *dev_priv)
  3138. {
  3139. if (!HAS_DISPLAY(dev_priv))
  3140. return;
  3141. gen8_de_irq_postinstall(dev_priv);
  3142. intel_uncore_write(&dev_priv->uncore, GEN11_DISPLAY_INT_CTL,
  3143. GEN11_DISPLAY_IRQ_ENABLE);
  3144. }
  3145. static void gen11_irq_postinstall(struct drm_i915_private *dev_priv)
  3146. {
  3147. struct intel_gt *gt = to_gt(dev_priv);
  3148. struct intel_uncore *uncore = gt->uncore;
  3149. u32 gu_misc_masked = GEN11_GU_MISC_GSE;
  3150. if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
  3151. icp_irq_postinstall(dev_priv);
  3152. gen11_gt_irq_postinstall(gt);
  3153. gen11_de_irq_postinstall(dev_priv);
  3154. GEN3_IRQ_INIT(uncore, GEN11_GU_MISC_, ~gu_misc_masked, gu_misc_masked);
  3155. gen11_master_intr_enable(uncore->regs);
  3156. intel_uncore_posting_read(&dev_priv->uncore, GEN11_GFX_MSTR_IRQ);
  3157. }
  3158. static void dg1_irq_postinstall(struct drm_i915_private *dev_priv)
  3159. {
  3160. struct intel_gt *gt = to_gt(dev_priv);
  3161. struct intel_uncore *uncore = gt->uncore;
  3162. u32 gu_misc_masked = GEN11_GU_MISC_GSE;
  3163. gen11_gt_irq_postinstall(gt);
  3164. GEN3_IRQ_INIT(uncore, GEN11_GU_MISC_, ~gu_misc_masked, gu_misc_masked);
  3165. if (HAS_DISPLAY(dev_priv)) {
  3166. icp_irq_postinstall(dev_priv);
  3167. gen8_de_irq_postinstall(dev_priv);
  3168. intel_uncore_write(&dev_priv->uncore, GEN11_DISPLAY_INT_CTL,
  3169. GEN11_DISPLAY_IRQ_ENABLE);
  3170. }
  3171. dg1_master_intr_enable(uncore->regs);
  3172. intel_uncore_posting_read(uncore, DG1_MSTR_TILE_INTR);
  3173. }
  3174. static void cherryview_irq_postinstall(struct drm_i915_private *dev_priv)
  3175. {
  3176. gen8_gt_irq_postinstall(to_gt(dev_priv));
  3177. spin_lock_irq(&dev_priv->irq_lock);
  3178. if (dev_priv->display_irqs_enabled)
  3179. vlv_display_irq_postinstall(dev_priv);
  3180. spin_unlock_irq(&dev_priv->irq_lock);
  3181. intel_uncore_write(&dev_priv->uncore, GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
  3182. intel_uncore_posting_read(&dev_priv->uncore, GEN8_MASTER_IRQ);
  3183. }
  3184. static void i8xx_irq_reset(struct drm_i915_private *dev_priv)
  3185. {
  3186. struct intel_uncore *uncore = &dev_priv->uncore;
  3187. i9xx_pipestat_irq_reset(dev_priv);
  3188. GEN2_IRQ_RESET(uncore);
  3189. dev_priv->irq_mask = ~0u;
  3190. }
  3191. static void i8xx_irq_postinstall(struct drm_i915_private *dev_priv)
  3192. {
  3193. struct intel_uncore *uncore = &dev_priv->uncore;
  3194. u16 enable_mask;
  3195. intel_uncore_write16(uncore,
  3196. EMR,
  3197. ~(I915_ERROR_PAGE_TABLE |
  3198. I915_ERROR_MEMORY_REFRESH));
  3199. /* Unmask the interrupts that we always want on. */
  3200. dev_priv->irq_mask =
  3201. ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  3202. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  3203. I915_MASTER_ERROR_INTERRUPT);
  3204. enable_mask =
  3205. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  3206. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  3207. I915_MASTER_ERROR_INTERRUPT |
  3208. I915_USER_INTERRUPT;
  3209. GEN2_IRQ_INIT(uncore, dev_priv->irq_mask, enable_mask);
  3210. /* Interrupt setup is already guaranteed to be single-threaded, this is
  3211. * just to make the assert_spin_locked check happy. */
  3212. spin_lock_irq(&dev_priv->irq_lock);
  3213. i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
  3214. i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
  3215. spin_unlock_irq(&dev_priv->irq_lock);
  3216. }
  3217. static void i8xx_error_irq_ack(struct drm_i915_private *i915,
  3218. u16 *eir, u16 *eir_stuck)
  3219. {
  3220. struct intel_uncore *uncore = &i915->uncore;
  3221. u16 emr;
  3222. *eir = intel_uncore_read16(uncore, EIR);
  3223. if (*eir)
  3224. intel_uncore_write16(uncore, EIR, *eir);
  3225. *eir_stuck = intel_uncore_read16(uncore, EIR);
  3226. if (*eir_stuck == 0)
  3227. return;
  3228. /*
  3229. * Toggle all EMR bits to make sure we get an edge
  3230. * in the ISR master error bit if we don't clear
  3231. * all the EIR bits. Otherwise the edge triggered
  3232. * IIR on i965/g4x wouldn't notice that an interrupt
  3233. * is still pending. Also some EIR bits can't be
  3234. * cleared except by handling the underlying error
  3235. * (or by a GPU reset) so we mask any bit that
  3236. * remains set.
  3237. */
  3238. emr = intel_uncore_read16(uncore, EMR);
  3239. intel_uncore_write16(uncore, EMR, 0xffff);
  3240. intel_uncore_write16(uncore, EMR, emr | *eir_stuck);
  3241. }
  3242. static void i8xx_error_irq_handler(struct drm_i915_private *dev_priv,
  3243. u16 eir, u16 eir_stuck)
  3244. {
  3245. DRM_DEBUG("Master Error: EIR 0x%04x\n", eir);
  3246. if (eir_stuck)
  3247. drm_dbg(&dev_priv->drm, "EIR stuck: 0x%04x, masked\n",
  3248. eir_stuck);
  3249. }
  3250. static void i9xx_error_irq_ack(struct drm_i915_private *dev_priv,
  3251. u32 *eir, u32 *eir_stuck)
  3252. {
  3253. u32 emr;
  3254. *eir = intel_uncore_read(&dev_priv->uncore, EIR);
  3255. intel_uncore_write(&dev_priv->uncore, EIR, *eir);
  3256. *eir_stuck = intel_uncore_read(&dev_priv->uncore, EIR);
  3257. if (*eir_stuck == 0)
  3258. return;
  3259. /*
  3260. * Toggle all EMR bits to make sure we get an edge
  3261. * in the ISR master error bit if we don't clear
  3262. * all the EIR bits. Otherwise the edge triggered
  3263. * IIR on i965/g4x wouldn't notice that an interrupt
  3264. * is still pending. Also some EIR bits can't be
  3265. * cleared except by handling the underlying error
  3266. * (or by a GPU reset) so we mask any bit that
  3267. * remains set.
  3268. */
  3269. emr = intel_uncore_read(&dev_priv->uncore, EMR);
  3270. intel_uncore_write(&dev_priv->uncore, EMR, 0xffffffff);
  3271. intel_uncore_write(&dev_priv->uncore, EMR, emr | *eir_stuck);
  3272. }
  3273. static void i9xx_error_irq_handler(struct drm_i915_private *dev_priv,
  3274. u32 eir, u32 eir_stuck)
  3275. {
  3276. DRM_DEBUG("Master Error, EIR 0x%08x\n", eir);
  3277. if (eir_stuck)
  3278. drm_dbg(&dev_priv->drm, "EIR stuck: 0x%08x, masked\n",
  3279. eir_stuck);
  3280. }
  3281. static irqreturn_t i8xx_irq_handler(int irq, void *arg)
  3282. {
  3283. struct drm_i915_private *dev_priv = arg;
  3284. irqreturn_t ret = IRQ_NONE;
  3285. if (!intel_irqs_enabled(dev_priv))
  3286. return IRQ_NONE;
  3287. /* IRQs are synced during runtime_suspend, we don't require a wakeref */
  3288. disable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
  3289. do {
  3290. u32 pipe_stats[I915_MAX_PIPES] = {};
  3291. u16 eir = 0, eir_stuck = 0;
  3292. u16 iir;
  3293. iir = intel_uncore_read16(&dev_priv->uncore, GEN2_IIR);
  3294. if (iir == 0)
  3295. break;
  3296. ret = IRQ_HANDLED;
  3297. /* Call regardless, as some status bits might not be
  3298. * signalled in iir */
  3299. i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
  3300. if (iir & I915_MASTER_ERROR_INTERRUPT)
  3301. i8xx_error_irq_ack(dev_priv, &eir, &eir_stuck);
  3302. intel_uncore_write16(&dev_priv->uncore, GEN2_IIR, iir);
  3303. if (iir & I915_USER_INTERRUPT)
  3304. intel_engine_cs_irq(to_gt(dev_priv)->engine[RCS0], iir);
  3305. if (iir & I915_MASTER_ERROR_INTERRUPT)
  3306. i8xx_error_irq_handler(dev_priv, eir, eir_stuck);
  3307. i8xx_pipestat_irq_handler(dev_priv, iir, pipe_stats);
  3308. } while (0);
  3309. pmu_irq_stats(dev_priv, ret);
  3310. enable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
  3311. return ret;
  3312. }
  3313. static void i915_irq_reset(struct drm_i915_private *dev_priv)
  3314. {
  3315. struct intel_uncore *uncore = &dev_priv->uncore;
  3316. if (I915_HAS_HOTPLUG(dev_priv)) {
  3317. i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
  3318. intel_uncore_write(&dev_priv->uncore, PORT_HOTPLUG_STAT, intel_uncore_read(&dev_priv->uncore, PORT_HOTPLUG_STAT));
  3319. }
  3320. i9xx_pipestat_irq_reset(dev_priv);
  3321. GEN3_IRQ_RESET(uncore, GEN2_);
  3322. dev_priv->irq_mask = ~0u;
  3323. }
  3324. static void i915_irq_postinstall(struct drm_i915_private *dev_priv)
  3325. {
  3326. struct intel_uncore *uncore = &dev_priv->uncore;
  3327. u32 enable_mask;
  3328. intel_uncore_write(&dev_priv->uncore, EMR, ~(I915_ERROR_PAGE_TABLE |
  3329. I915_ERROR_MEMORY_REFRESH));
  3330. /* Unmask the interrupts that we always want on. */
  3331. dev_priv->irq_mask =
  3332. ~(I915_ASLE_INTERRUPT |
  3333. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  3334. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  3335. I915_MASTER_ERROR_INTERRUPT);
  3336. enable_mask =
  3337. I915_ASLE_INTERRUPT |
  3338. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  3339. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  3340. I915_MASTER_ERROR_INTERRUPT |
  3341. I915_USER_INTERRUPT;
  3342. if (I915_HAS_HOTPLUG(dev_priv)) {
  3343. /* Enable in IER... */
  3344. enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
  3345. /* and unmask in IMR */
  3346. dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
  3347. }
  3348. GEN3_IRQ_INIT(uncore, GEN2_, dev_priv->irq_mask, enable_mask);
  3349. /* Interrupt setup is already guaranteed to be single-threaded, this is
  3350. * just to make the assert_spin_locked check happy. */
  3351. spin_lock_irq(&dev_priv->irq_lock);
  3352. i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
  3353. i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
  3354. spin_unlock_irq(&dev_priv->irq_lock);
  3355. i915_enable_asle_pipestat(dev_priv);
  3356. }
  3357. static irqreturn_t i915_irq_handler(int irq, void *arg)
  3358. {
  3359. struct drm_i915_private *dev_priv = arg;
  3360. irqreturn_t ret = IRQ_NONE;
  3361. if (!intel_irqs_enabled(dev_priv))
  3362. return IRQ_NONE;
  3363. /* IRQs are synced during runtime_suspend, we don't require a wakeref */
  3364. disable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
  3365. do {
  3366. u32 pipe_stats[I915_MAX_PIPES] = {};
  3367. u32 eir = 0, eir_stuck = 0;
  3368. u32 hotplug_status = 0;
  3369. u32 iir;
  3370. iir = intel_uncore_read(&dev_priv->uncore, GEN2_IIR);
  3371. if (iir == 0)
  3372. break;
  3373. ret = IRQ_HANDLED;
  3374. if (I915_HAS_HOTPLUG(dev_priv) &&
  3375. iir & I915_DISPLAY_PORT_INTERRUPT)
  3376. hotplug_status = i9xx_hpd_irq_ack(dev_priv);
  3377. /* Call regardless, as some status bits might not be
  3378. * signalled in iir */
  3379. i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
  3380. if (iir & I915_MASTER_ERROR_INTERRUPT)
  3381. i9xx_error_irq_ack(dev_priv, &eir, &eir_stuck);
  3382. intel_uncore_write(&dev_priv->uncore, GEN2_IIR, iir);
  3383. if (iir & I915_USER_INTERRUPT)
  3384. intel_engine_cs_irq(to_gt(dev_priv)->engine[RCS0], iir);
  3385. if (iir & I915_MASTER_ERROR_INTERRUPT)
  3386. i9xx_error_irq_handler(dev_priv, eir, eir_stuck);
  3387. if (hotplug_status)
  3388. i9xx_hpd_irq_handler(dev_priv, hotplug_status);
  3389. i915_pipestat_irq_handler(dev_priv, iir, pipe_stats);
  3390. } while (0);
  3391. pmu_irq_stats(dev_priv, ret);
  3392. enable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
  3393. return ret;
  3394. }
  3395. static void i965_irq_reset(struct drm_i915_private *dev_priv)
  3396. {
  3397. struct intel_uncore *uncore = &dev_priv->uncore;
  3398. i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
  3399. intel_uncore_write(&dev_priv->uncore, PORT_HOTPLUG_STAT, intel_uncore_read(&dev_priv->uncore, PORT_HOTPLUG_STAT));
  3400. i9xx_pipestat_irq_reset(dev_priv);
  3401. GEN3_IRQ_RESET(uncore, GEN2_);
  3402. dev_priv->irq_mask = ~0u;
  3403. }
  3404. static void i965_irq_postinstall(struct drm_i915_private *dev_priv)
  3405. {
  3406. struct intel_uncore *uncore = &dev_priv->uncore;
  3407. u32 enable_mask;
  3408. u32 error_mask;
  3409. /*
  3410. * Enable some error detection, note the instruction error mask
  3411. * bit is reserved, so we leave it masked.
  3412. */
  3413. if (IS_G4X(dev_priv)) {
  3414. error_mask = ~(GM45_ERROR_PAGE_TABLE |
  3415. GM45_ERROR_MEM_PRIV |
  3416. GM45_ERROR_CP_PRIV |
  3417. I915_ERROR_MEMORY_REFRESH);
  3418. } else {
  3419. error_mask = ~(I915_ERROR_PAGE_TABLE |
  3420. I915_ERROR_MEMORY_REFRESH);
  3421. }
  3422. intel_uncore_write(&dev_priv->uncore, EMR, error_mask);
  3423. /* Unmask the interrupts that we always want on. */
  3424. dev_priv->irq_mask =
  3425. ~(I915_ASLE_INTERRUPT |
  3426. I915_DISPLAY_PORT_INTERRUPT |
  3427. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  3428. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  3429. I915_MASTER_ERROR_INTERRUPT);
  3430. enable_mask =
  3431. I915_ASLE_INTERRUPT |
  3432. I915_DISPLAY_PORT_INTERRUPT |
  3433. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  3434. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  3435. I915_MASTER_ERROR_INTERRUPT |
  3436. I915_USER_INTERRUPT;
  3437. if (IS_G4X(dev_priv))
  3438. enable_mask |= I915_BSD_USER_INTERRUPT;
  3439. GEN3_IRQ_INIT(uncore, GEN2_, dev_priv->irq_mask, enable_mask);
  3440. /* Interrupt setup is already guaranteed to be single-threaded, this is
  3441. * just to make the assert_spin_locked check happy. */
  3442. spin_lock_irq(&dev_priv->irq_lock);
  3443. i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
  3444. i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
  3445. i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
  3446. spin_unlock_irq(&dev_priv->irq_lock);
  3447. i915_enable_asle_pipestat(dev_priv);
  3448. }
  3449. static void i915_hpd_irq_setup(struct drm_i915_private *dev_priv)
  3450. {
  3451. u32 hotplug_en;
  3452. lockdep_assert_held(&dev_priv->irq_lock);
  3453. /* Note HDMI and DP share hotplug bits */
  3454. /* enable bits are the same for all generations */
  3455. hotplug_en = intel_hpd_enabled_irqs(dev_priv, hpd_mask_i915);
  3456. /* Programming the CRT detection parameters tends
  3457. to generate a spurious hotplug event about three
  3458. seconds later. So just do it once.
  3459. */
  3460. if (IS_G4X(dev_priv))
  3461. hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
  3462. hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
  3463. /* Ignore TV since it's buggy */
  3464. i915_hotplug_interrupt_update_locked(dev_priv,
  3465. HOTPLUG_INT_EN_MASK |
  3466. CRT_HOTPLUG_VOLTAGE_COMPARE_MASK |
  3467. CRT_HOTPLUG_ACTIVATION_PERIOD_64,
  3468. hotplug_en);
  3469. }
  3470. static irqreturn_t i965_irq_handler(int irq, void *arg)
  3471. {
  3472. struct drm_i915_private *dev_priv = arg;
  3473. irqreturn_t ret = IRQ_NONE;
  3474. if (!intel_irqs_enabled(dev_priv))
  3475. return IRQ_NONE;
  3476. /* IRQs are synced during runtime_suspend, we don't require a wakeref */
  3477. disable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
  3478. do {
  3479. u32 pipe_stats[I915_MAX_PIPES] = {};
  3480. u32 eir = 0, eir_stuck = 0;
  3481. u32 hotplug_status = 0;
  3482. u32 iir;
  3483. iir = intel_uncore_read(&dev_priv->uncore, GEN2_IIR);
  3484. if (iir == 0)
  3485. break;
  3486. ret = IRQ_HANDLED;
  3487. if (iir & I915_DISPLAY_PORT_INTERRUPT)
  3488. hotplug_status = i9xx_hpd_irq_ack(dev_priv);
  3489. /* Call regardless, as some status bits might not be
  3490. * signalled in iir */
  3491. i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
  3492. if (iir & I915_MASTER_ERROR_INTERRUPT)
  3493. i9xx_error_irq_ack(dev_priv, &eir, &eir_stuck);
  3494. intel_uncore_write(&dev_priv->uncore, GEN2_IIR, iir);
  3495. if (iir & I915_USER_INTERRUPT)
  3496. intel_engine_cs_irq(to_gt(dev_priv)->engine[RCS0],
  3497. iir);
  3498. if (iir & I915_BSD_USER_INTERRUPT)
  3499. intel_engine_cs_irq(to_gt(dev_priv)->engine[VCS0],
  3500. iir >> 25);
  3501. if (iir & I915_MASTER_ERROR_INTERRUPT)
  3502. i9xx_error_irq_handler(dev_priv, eir, eir_stuck);
  3503. if (hotplug_status)
  3504. i9xx_hpd_irq_handler(dev_priv, hotplug_status);
  3505. i965_pipestat_irq_handler(dev_priv, iir, pipe_stats);
  3506. } while (0);
  3507. pmu_irq_stats(dev_priv, IRQ_HANDLED);
  3508. enable_rpm_wakeref_asserts(&dev_priv->runtime_pm);
  3509. return ret;
  3510. }
  3511. struct intel_hotplug_funcs {
  3512. void (*hpd_irq_setup)(struct drm_i915_private *i915);
  3513. };
  3514. #define HPD_FUNCS(platform) \
  3515. static const struct intel_hotplug_funcs platform##_hpd_funcs = { \
  3516. .hpd_irq_setup = platform##_hpd_irq_setup, \
  3517. }
  3518. HPD_FUNCS(i915);
  3519. HPD_FUNCS(dg1);
  3520. HPD_FUNCS(gen11);
  3521. HPD_FUNCS(bxt);
  3522. HPD_FUNCS(icp);
  3523. HPD_FUNCS(spt);
  3524. HPD_FUNCS(ilk);
  3525. #undef HPD_FUNCS
  3526. void intel_hpd_irq_setup(struct drm_i915_private *i915)
  3527. {
  3528. if (i915->display_irqs_enabled && i915->display.funcs.hotplug)
  3529. i915->display.funcs.hotplug->hpd_irq_setup(i915);
  3530. }
  3531. /**
  3532. * intel_irq_init - initializes irq support
  3533. * @dev_priv: i915 device instance
  3534. *
  3535. * This function initializes all the irq support including work items, timers
  3536. * and all the vtables. It does not setup the interrupt itself though.
  3537. */
  3538. void intel_irq_init(struct drm_i915_private *dev_priv)
  3539. {
  3540. struct drm_device *dev = &dev_priv->drm;
  3541. int i;
  3542. INIT_WORK(&dev_priv->l3_parity.error_work, ivb_parity_work);
  3543. for (i = 0; i < MAX_L3_SLICES; ++i)
  3544. dev_priv->l3_parity.remap_info[i] = NULL;
  3545. /* pre-gen11 the guc irqs bits are in the upper 16 bits of the pm reg */
  3546. if (HAS_GT_UC(dev_priv) && GRAPHICS_VER(dev_priv) < 11)
  3547. to_gt(dev_priv)->pm_guc_events = GUC_INTR_GUC2HOST << 16;
  3548. if (!HAS_DISPLAY(dev_priv))
  3549. return;
  3550. intel_hpd_init_pins(dev_priv);
  3551. intel_hpd_init_work(dev_priv);
  3552. dev->vblank_disable_immediate = true;
  3553. /* Most platforms treat the display irq block as an always-on
  3554. * power domain. vlv/chv can disable it at runtime and need
  3555. * special care to avoid writing any of the display block registers
  3556. * outside of the power domain. We defer setting up the display irqs
  3557. * in this case to the runtime pm.
  3558. */
  3559. dev_priv->display_irqs_enabled = true;
  3560. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  3561. dev_priv->display_irqs_enabled = false;
  3562. dev_priv->display.hotplug.hpd_storm_threshold = HPD_STORM_DEFAULT_THRESHOLD;
  3563. /* If we have MST support, we want to avoid doing short HPD IRQ storm
  3564. * detection, as short HPD storms will occur as a natural part of
  3565. * sideband messaging with MST.
  3566. * On older platforms however, IRQ storms can occur with both long and
  3567. * short pulses, as seen on some G4x systems.
  3568. */
  3569. dev_priv->display.hotplug.hpd_short_storm_enabled = !HAS_DP_MST(dev_priv);
  3570. if (HAS_GMCH(dev_priv)) {
  3571. if (I915_HAS_HOTPLUG(dev_priv))
  3572. dev_priv->display.funcs.hotplug = &i915_hpd_funcs;
  3573. } else {
  3574. if (HAS_PCH_DG2(dev_priv))
  3575. dev_priv->display.funcs.hotplug = &icp_hpd_funcs;
  3576. else if (HAS_PCH_DG1(dev_priv))
  3577. dev_priv->display.funcs.hotplug = &dg1_hpd_funcs;
  3578. else if (DISPLAY_VER(dev_priv) >= 11)
  3579. dev_priv->display.funcs.hotplug = &gen11_hpd_funcs;
  3580. else if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
  3581. dev_priv->display.funcs.hotplug = &bxt_hpd_funcs;
  3582. else if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
  3583. dev_priv->display.funcs.hotplug = &icp_hpd_funcs;
  3584. else if (INTEL_PCH_TYPE(dev_priv) >= PCH_SPT)
  3585. dev_priv->display.funcs.hotplug = &spt_hpd_funcs;
  3586. else
  3587. dev_priv->display.funcs.hotplug = &ilk_hpd_funcs;
  3588. }
  3589. }
  3590. /**
  3591. * intel_irq_fini - deinitializes IRQ support
  3592. * @i915: i915 device instance
  3593. *
  3594. * This function deinitializes all the IRQ support.
  3595. */
  3596. void intel_irq_fini(struct drm_i915_private *i915)
  3597. {
  3598. int i;
  3599. for (i = 0; i < MAX_L3_SLICES; ++i)
  3600. kfree(i915->l3_parity.remap_info[i]);
  3601. }
  3602. static irq_handler_t intel_irq_handler(struct drm_i915_private *dev_priv)
  3603. {
  3604. if (HAS_GMCH(dev_priv)) {
  3605. if (IS_CHERRYVIEW(dev_priv))
  3606. return cherryview_irq_handler;
  3607. else if (IS_VALLEYVIEW(dev_priv))
  3608. return valleyview_irq_handler;
  3609. else if (GRAPHICS_VER(dev_priv) == 4)
  3610. return i965_irq_handler;
  3611. else if (GRAPHICS_VER(dev_priv) == 3)
  3612. return i915_irq_handler;
  3613. else
  3614. return i8xx_irq_handler;
  3615. } else {
  3616. if (GRAPHICS_VER_FULL(dev_priv) >= IP_VER(12, 10))
  3617. return dg1_irq_handler;
  3618. else if (GRAPHICS_VER(dev_priv) >= 11)
  3619. return gen11_irq_handler;
  3620. else if (GRAPHICS_VER(dev_priv) >= 8)
  3621. return gen8_irq_handler;
  3622. else
  3623. return ilk_irq_handler;
  3624. }
  3625. }
  3626. static void intel_irq_reset(struct drm_i915_private *dev_priv)
  3627. {
  3628. if (HAS_GMCH(dev_priv)) {
  3629. if (IS_CHERRYVIEW(dev_priv))
  3630. cherryview_irq_reset(dev_priv);
  3631. else if (IS_VALLEYVIEW(dev_priv))
  3632. valleyview_irq_reset(dev_priv);
  3633. else if (GRAPHICS_VER(dev_priv) == 4)
  3634. i965_irq_reset(dev_priv);
  3635. else if (GRAPHICS_VER(dev_priv) == 3)
  3636. i915_irq_reset(dev_priv);
  3637. else
  3638. i8xx_irq_reset(dev_priv);
  3639. } else {
  3640. if (GRAPHICS_VER_FULL(dev_priv) >= IP_VER(12, 10))
  3641. dg1_irq_reset(dev_priv);
  3642. else if (GRAPHICS_VER(dev_priv) >= 11)
  3643. gen11_irq_reset(dev_priv);
  3644. else if (GRAPHICS_VER(dev_priv) >= 8)
  3645. gen8_irq_reset(dev_priv);
  3646. else
  3647. ilk_irq_reset(dev_priv);
  3648. }
  3649. }
  3650. static void intel_irq_postinstall(struct drm_i915_private *dev_priv)
  3651. {
  3652. if (HAS_GMCH(dev_priv)) {
  3653. if (IS_CHERRYVIEW(dev_priv))
  3654. cherryview_irq_postinstall(dev_priv);
  3655. else if (IS_VALLEYVIEW(dev_priv))
  3656. valleyview_irq_postinstall(dev_priv);
  3657. else if (GRAPHICS_VER(dev_priv) == 4)
  3658. i965_irq_postinstall(dev_priv);
  3659. else if (GRAPHICS_VER(dev_priv) == 3)
  3660. i915_irq_postinstall(dev_priv);
  3661. else
  3662. i8xx_irq_postinstall(dev_priv);
  3663. } else {
  3664. if (GRAPHICS_VER_FULL(dev_priv) >= IP_VER(12, 10))
  3665. dg1_irq_postinstall(dev_priv);
  3666. else if (GRAPHICS_VER(dev_priv) >= 11)
  3667. gen11_irq_postinstall(dev_priv);
  3668. else if (GRAPHICS_VER(dev_priv) >= 8)
  3669. gen8_irq_postinstall(dev_priv);
  3670. else
  3671. ilk_irq_postinstall(dev_priv);
  3672. }
  3673. }
  3674. /**
  3675. * intel_irq_install - enables the hardware interrupt
  3676. * @dev_priv: i915 device instance
  3677. *
  3678. * This function enables the hardware interrupt handling, but leaves the hotplug
  3679. * handling still disabled. It is called after intel_irq_init().
  3680. *
  3681. * In the driver load and resume code we need working interrupts in a few places
  3682. * but don't want to deal with the hassle of concurrent probe and hotplug
  3683. * workers. Hence the split into this two-stage approach.
  3684. */
  3685. int intel_irq_install(struct drm_i915_private *dev_priv)
  3686. {
  3687. int irq = to_pci_dev(dev_priv->drm.dev)->irq;
  3688. int ret;
  3689. /*
  3690. * We enable some interrupt sources in our postinstall hooks, so mark
  3691. * interrupts as enabled _before_ actually enabling them to avoid
  3692. * special cases in our ordering checks.
  3693. */
  3694. dev_priv->runtime_pm.irqs_enabled = true;
  3695. dev_priv->irq_enabled = true;
  3696. intel_irq_reset(dev_priv);
  3697. ret = request_irq(irq, intel_irq_handler(dev_priv),
  3698. IRQF_SHARED, DRIVER_NAME, dev_priv);
  3699. if (ret < 0) {
  3700. dev_priv->irq_enabled = false;
  3701. return ret;
  3702. }
  3703. intel_irq_postinstall(dev_priv);
  3704. return ret;
  3705. }
  3706. /**
  3707. * intel_irq_uninstall - finilizes all irq handling
  3708. * @dev_priv: i915 device instance
  3709. *
  3710. * This stops interrupt and hotplug handling and unregisters and frees all
  3711. * resources acquired in the init functions.
  3712. */
  3713. void intel_irq_uninstall(struct drm_i915_private *dev_priv)
  3714. {
  3715. int irq = to_pci_dev(dev_priv->drm.dev)->irq;
  3716. /*
  3717. * FIXME we can get called twice during driver probe
  3718. * error handling as well as during driver remove due to
  3719. * intel_modeset_driver_remove() calling us out of sequence.
  3720. * Would be nice if it didn't do that...
  3721. */
  3722. if (!dev_priv->irq_enabled)
  3723. return;
  3724. dev_priv->irq_enabled = false;
  3725. intel_irq_reset(dev_priv);
  3726. free_irq(irq, dev_priv);
  3727. intel_hpd_cancel_work(dev_priv);
  3728. dev_priv->runtime_pm.irqs_enabled = false;
  3729. }
  3730. /**
  3731. * intel_runtime_pm_disable_interrupts - runtime interrupt disabling
  3732. * @dev_priv: i915 device instance
  3733. *
  3734. * This function is used to disable interrupts at runtime, both in the runtime
  3735. * pm and the system suspend/resume code.
  3736. */
  3737. void intel_runtime_pm_disable_interrupts(struct drm_i915_private *dev_priv)
  3738. {
  3739. intel_irq_reset(dev_priv);
  3740. dev_priv->runtime_pm.irqs_enabled = false;
  3741. intel_synchronize_irq(dev_priv);
  3742. }
  3743. /**
  3744. * intel_runtime_pm_enable_interrupts - runtime interrupt enabling
  3745. * @dev_priv: i915 device instance
  3746. *
  3747. * This function is used to enable interrupts at runtime, both in the runtime
  3748. * pm and the system suspend/resume code.
  3749. */
  3750. void intel_runtime_pm_enable_interrupts(struct drm_i915_private *dev_priv)
  3751. {
  3752. dev_priv->runtime_pm.irqs_enabled = true;
  3753. intel_irq_reset(dev_priv);
  3754. intel_irq_postinstall(dev_priv);
  3755. }
  3756. bool intel_irqs_enabled(struct drm_i915_private *dev_priv)
  3757. {
  3758. return dev_priv->runtime_pm.irqs_enabled;
  3759. }
  3760. void intel_synchronize_irq(struct drm_i915_private *i915)
  3761. {
  3762. synchronize_irq(to_pci_dev(i915->drm.dev)->irq);
  3763. }
  3764. void intel_synchronize_hardirq(struct drm_i915_private *i915)
  3765. {
  3766. synchronize_hardirq(to_pci_dev(i915->drm.dev)->irq);
  3767. }