intel_display.c 445 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773
  1. /*
  2. * Copyright © 2006-2007 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21. * DEALINGS IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Eric Anholt <eric@anholt.net>
  25. */
  26. #include <linux/dmi.h>
  27. #include <linux/module.h>
  28. #include <linux/input.h>
  29. #include <linux/i2c.h>
  30. #include <linux/kernel.h>
  31. #include <linux/slab.h>
  32. #include <linux/vgaarb.h>
  33. #include <drm/drm_edid.h>
  34. #include <drm/drmP.h>
  35. #include "intel_drv.h"
  36. #include "intel_frontbuffer.h"
  37. #include <drm/i915_drm.h>
  38. #include "i915_drv.h"
  39. #include "i915_gem_clflush.h"
  40. #include "intel_dsi.h"
  41. #include "i915_trace.h"
  42. #include <drm/drm_atomic.h>
  43. #include <drm/drm_atomic_helper.h>
  44. #include <drm/drm_dp_helper.h>
  45. #include <drm/drm_crtc_helper.h>
  46. #include <drm/drm_plane_helper.h>
  47. #include <drm/drm_rect.h>
  48. #include <linux/dma_remapping.h>
  49. #include <linux/reservation.h>
  50. /* Primary plane formats for gen <= 3 */
  51. static const uint32_t i8xx_primary_formats[] = {
  52. DRM_FORMAT_C8,
  53. DRM_FORMAT_RGB565,
  54. DRM_FORMAT_XRGB1555,
  55. DRM_FORMAT_XRGB8888,
  56. };
  57. /* Primary plane formats for gen >= 4 */
  58. static const uint32_t i965_primary_formats[] = {
  59. DRM_FORMAT_C8,
  60. DRM_FORMAT_RGB565,
  61. DRM_FORMAT_XRGB8888,
  62. DRM_FORMAT_XBGR8888,
  63. DRM_FORMAT_XRGB2101010,
  64. DRM_FORMAT_XBGR2101010,
  65. };
  66. static const uint64_t i9xx_format_modifiers[] = {
  67. I915_FORMAT_MOD_X_TILED,
  68. DRM_FORMAT_MOD_LINEAR,
  69. DRM_FORMAT_MOD_INVALID
  70. };
  71. static const uint32_t skl_primary_formats[] = {
  72. DRM_FORMAT_C8,
  73. DRM_FORMAT_RGB565,
  74. DRM_FORMAT_XRGB8888,
  75. DRM_FORMAT_XBGR8888,
  76. DRM_FORMAT_ARGB8888,
  77. DRM_FORMAT_ABGR8888,
  78. DRM_FORMAT_XRGB2101010,
  79. DRM_FORMAT_XBGR2101010,
  80. DRM_FORMAT_YUYV,
  81. DRM_FORMAT_YVYU,
  82. DRM_FORMAT_UYVY,
  83. DRM_FORMAT_VYUY,
  84. };
  85. static const uint64_t skl_format_modifiers_noccs[] = {
  86. I915_FORMAT_MOD_Yf_TILED,
  87. I915_FORMAT_MOD_Y_TILED,
  88. I915_FORMAT_MOD_X_TILED,
  89. DRM_FORMAT_MOD_LINEAR,
  90. DRM_FORMAT_MOD_INVALID
  91. };
  92. static const uint64_t skl_format_modifiers_ccs[] = {
  93. I915_FORMAT_MOD_Yf_TILED_CCS,
  94. I915_FORMAT_MOD_Y_TILED_CCS,
  95. I915_FORMAT_MOD_Yf_TILED,
  96. I915_FORMAT_MOD_Y_TILED,
  97. I915_FORMAT_MOD_X_TILED,
  98. DRM_FORMAT_MOD_LINEAR,
  99. DRM_FORMAT_MOD_INVALID
  100. };
  101. /* Cursor formats */
  102. static const uint32_t intel_cursor_formats[] = {
  103. DRM_FORMAT_ARGB8888,
  104. };
  105. static const uint64_t cursor_format_modifiers[] = {
  106. DRM_FORMAT_MOD_LINEAR,
  107. DRM_FORMAT_MOD_INVALID
  108. };
  109. static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
  110. struct intel_crtc_state *pipe_config);
  111. static void ironlake_pch_clock_get(struct intel_crtc *crtc,
  112. struct intel_crtc_state *pipe_config);
  113. static int intel_framebuffer_init(struct intel_framebuffer *ifb,
  114. struct drm_i915_gem_object *obj,
  115. struct drm_mode_fb_cmd2 *mode_cmd);
  116. static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc);
  117. static void intel_set_pipe_timings(struct intel_crtc *intel_crtc);
  118. static void intel_set_pipe_src_size(struct intel_crtc *intel_crtc);
  119. static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc,
  120. struct intel_link_m_n *m_n,
  121. struct intel_link_m_n *m2_n2);
  122. static void ironlake_set_pipeconf(struct drm_crtc *crtc);
  123. static void haswell_set_pipeconf(struct drm_crtc *crtc);
  124. static void haswell_set_pipemisc(struct drm_crtc *crtc);
  125. static void vlv_prepare_pll(struct intel_crtc *crtc,
  126. const struct intel_crtc_state *pipe_config);
  127. static void chv_prepare_pll(struct intel_crtc *crtc,
  128. const struct intel_crtc_state *pipe_config);
  129. static void intel_begin_crtc_commit(struct drm_crtc *, struct drm_crtc_state *);
  130. static void intel_finish_crtc_commit(struct drm_crtc *, struct drm_crtc_state *);
  131. static void intel_crtc_init_scalers(struct intel_crtc *crtc,
  132. struct intel_crtc_state *crtc_state);
  133. static void skylake_pfit_enable(struct intel_crtc *crtc);
  134. static void ironlake_pfit_disable(struct intel_crtc *crtc, bool force);
  135. static void ironlake_pfit_enable(struct intel_crtc *crtc);
  136. static void intel_modeset_setup_hw_state(struct drm_device *dev,
  137. struct drm_modeset_acquire_ctx *ctx);
  138. static void intel_pre_disable_primary_noatomic(struct drm_crtc *crtc);
  139. struct intel_limit {
  140. struct {
  141. int min, max;
  142. } dot, vco, n, m, m1, m2, p, p1;
  143. struct {
  144. int dot_limit;
  145. int p2_slow, p2_fast;
  146. } p2;
  147. };
  148. /* returns HPLL frequency in kHz */
  149. int vlv_get_hpll_vco(struct drm_i915_private *dev_priv)
  150. {
  151. int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 };
  152. /* Obtain SKU information */
  153. mutex_lock(&dev_priv->sb_lock);
  154. hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) &
  155. CCK_FUSE_HPLL_FREQ_MASK;
  156. mutex_unlock(&dev_priv->sb_lock);
  157. return vco_freq[hpll_freq] * 1000;
  158. }
  159. int vlv_get_cck_clock(struct drm_i915_private *dev_priv,
  160. const char *name, u32 reg, int ref_freq)
  161. {
  162. u32 val;
  163. int divider;
  164. mutex_lock(&dev_priv->sb_lock);
  165. val = vlv_cck_read(dev_priv, reg);
  166. mutex_unlock(&dev_priv->sb_lock);
  167. divider = val & CCK_FREQUENCY_VALUES;
  168. WARN((val & CCK_FREQUENCY_STATUS) !=
  169. (divider << CCK_FREQUENCY_STATUS_SHIFT),
  170. "%s change in progress\n", name);
  171. return DIV_ROUND_CLOSEST(ref_freq << 1, divider + 1);
  172. }
  173. int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv,
  174. const char *name, u32 reg)
  175. {
  176. if (dev_priv->hpll_freq == 0)
  177. dev_priv->hpll_freq = vlv_get_hpll_vco(dev_priv);
  178. return vlv_get_cck_clock(dev_priv, name, reg,
  179. dev_priv->hpll_freq);
  180. }
  181. static void intel_update_czclk(struct drm_i915_private *dev_priv)
  182. {
  183. if (!(IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)))
  184. return;
  185. dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk",
  186. CCK_CZ_CLOCK_CONTROL);
  187. DRM_DEBUG_DRIVER("CZ clock rate: %d kHz\n", dev_priv->czclk_freq);
  188. }
  189. static inline u32 /* units of 100MHz */
  190. intel_fdi_link_freq(struct drm_i915_private *dev_priv,
  191. const struct intel_crtc_state *pipe_config)
  192. {
  193. if (HAS_DDI(dev_priv))
  194. return pipe_config->port_clock; /* SPLL */
  195. else
  196. return dev_priv->fdi_pll_freq;
  197. }
  198. static const struct intel_limit intel_limits_i8xx_dac = {
  199. .dot = { .min = 25000, .max = 350000 },
  200. .vco = { .min = 908000, .max = 1512000 },
  201. .n = { .min = 2, .max = 16 },
  202. .m = { .min = 96, .max = 140 },
  203. .m1 = { .min = 18, .max = 26 },
  204. .m2 = { .min = 6, .max = 16 },
  205. .p = { .min = 4, .max = 128 },
  206. .p1 = { .min = 2, .max = 33 },
  207. .p2 = { .dot_limit = 165000,
  208. .p2_slow = 4, .p2_fast = 2 },
  209. };
  210. static const struct intel_limit intel_limits_i8xx_dvo = {
  211. .dot = { .min = 25000, .max = 350000 },
  212. .vco = { .min = 908000, .max = 1512000 },
  213. .n = { .min = 2, .max = 16 },
  214. .m = { .min = 96, .max = 140 },
  215. .m1 = { .min = 18, .max = 26 },
  216. .m2 = { .min = 6, .max = 16 },
  217. .p = { .min = 4, .max = 128 },
  218. .p1 = { .min = 2, .max = 33 },
  219. .p2 = { .dot_limit = 165000,
  220. .p2_slow = 4, .p2_fast = 4 },
  221. };
  222. static const struct intel_limit intel_limits_i8xx_lvds = {
  223. .dot = { .min = 25000, .max = 350000 },
  224. .vco = { .min = 908000, .max = 1512000 },
  225. .n = { .min = 2, .max = 16 },
  226. .m = { .min = 96, .max = 140 },
  227. .m1 = { .min = 18, .max = 26 },
  228. .m2 = { .min = 6, .max = 16 },
  229. .p = { .min = 4, .max = 128 },
  230. .p1 = { .min = 1, .max = 6 },
  231. .p2 = { .dot_limit = 165000,
  232. .p2_slow = 14, .p2_fast = 7 },
  233. };
  234. static const struct intel_limit intel_limits_i9xx_sdvo = {
  235. .dot = { .min = 20000, .max = 400000 },
  236. .vco = { .min = 1400000, .max = 2800000 },
  237. .n = { .min = 1, .max = 6 },
  238. .m = { .min = 70, .max = 120 },
  239. .m1 = { .min = 8, .max = 18 },
  240. .m2 = { .min = 3, .max = 7 },
  241. .p = { .min = 5, .max = 80 },
  242. .p1 = { .min = 1, .max = 8 },
  243. .p2 = { .dot_limit = 200000,
  244. .p2_slow = 10, .p2_fast = 5 },
  245. };
  246. static const struct intel_limit intel_limits_i9xx_lvds = {
  247. .dot = { .min = 20000, .max = 400000 },
  248. .vco = { .min = 1400000, .max = 2800000 },
  249. .n = { .min = 1, .max = 6 },
  250. .m = { .min = 70, .max = 120 },
  251. .m1 = { .min = 8, .max = 18 },
  252. .m2 = { .min = 3, .max = 7 },
  253. .p = { .min = 7, .max = 98 },
  254. .p1 = { .min = 1, .max = 8 },
  255. .p2 = { .dot_limit = 112000,
  256. .p2_slow = 14, .p2_fast = 7 },
  257. };
  258. static const struct intel_limit intel_limits_g4x_sdvo = {
  259. .dot = { .min = 25000, .max = 270000 },
  260. .vco = { .min = 1750000, .max = 3500000},
  261. .n = { .min = 1, .max = 4 },
  262. .m = { .min = 104, .max = 138 },
  263. .m1 = { .min = 17, .max = 23 },
  264. .m2 = { .min = 5, .max = 11 },
  265. .p = { .min = 10, .max = 30 },
  266. .p1 = { .min = 1, .max = 3},
  267. .p2 = { .dot_limit = 270000,
  268. .p2_slow = 10,
  269. .p2_fast = 10
  270. },
  271. };
  272. static const struct intel_limit intel_limits_g4x_hdmi = {
  273. .dot = { .min = 22000, .max = 400000 },
  274. .vco = { .min = 1750000, .max = 3500000},
  275. .n = { .min = 1, .max = 4 },
  276. .m = { .min = 104, .max = 138 },
  277. .m1 = { .min = 16, .max = 23 },
  278. .m2 = { .min = 5, .max = 11 },
  279. .p = { .min = 5, .max = 80 },
  280. .p1 = { .min = 1, .max = 8},
  281. .p2 = { .dot_limit = 165000,
  282. .p2_slow = 10, .p2_fast = 5 },
  283. };
  284. static const struct intel_limit intel_limits_g4x_single_channel_lvds = {
  285. .dot = { .min = 20000, .max = 115000 },
  286. .vco = { .min = 1750000, .max = 3500000 },
  287. .n = { .min = 1, .max = 3 },
  288. .m = { .min = 104, .max = 138 },
  289. .m1 = { .min = 17, .max = 23 },
  290. .m2 = { .min = 5, .max = 11 },
  291. .p = { .min = 28, .max = 112 },
  292. .p1 = { .min = 2, .max = 8 },
  293. .p2 = { .dot_limit = 0,
  294. .p2_slow = 14, .p2_fast = 14
  295. },
  296. };
  297. static const struct intel_limit intel_limits_g4x_dual_channel_lvds = {
  298. .dot = { .min = 80000, .max = 224000 },
  299. .vco = { .min = 1750000, .max = 3500000 },
  300. .n = { .min = 1, .max = 3 },
  301. .m = { .min = 104, .max = 138 },
  302. .m1 = { .min = 17, .max = 23 },
  303. .m2 = { .min = 5, .max = 11 },
  304. .p = { .min = 14, .max = 42 },
  305. .p1 = { .min = 2, .max = 6 },
  306. .p2 = { .dot_limit = 0,
  307. .p2_slow = 7, .p2_fast = 7
  308. },
  309. };
  310. static const struct intel_limit intel_limits_pineview_sdvo = {
  311. .dot = { .min = 20000, .max = 400000},
  312. .vco = { .min = 1700000, .max = 3500000 },
  313. /* Pineview's Ncounter is a ring counter */
  314. .n = { .min = 3, .max = 6 },
  315. .m = { .min = 2, .max = 256 },
  316. /* Pineview only has one combined m divider, which we treat as m2. */
  317. .m1 = { .min = 0, .max = 0 },
  318. .m2 = { .min = 0, .max = 254 },
  319. .p = { .min = 5, .max = 80 },
  320. .p1 = { .min = 1, .max = 8 },
  321. .p2 = { .dot_limit = 200000,
  322. .p2_slow = 10, .p2_fast = 5 },
  323. };
  324. static const struct intel_limit intel_limits_pineview_lvds = {
  325. .dot = { .min = 20000, .max = 400000 },
  326. .vco = { .min = 1700000, .max = 3500000 },
  327. .n = { .min = 3, .max = 6 },
  328. .m = { .min = 2, .max = 256 },
  329. .m1 = { .min = 0, .max = 0 },
  330. .m2 = { .min = 0, .max = 254 },
  331. .p = { .min = 7, .max = 112 },
  332. .p1 = { .min = 1, .max = 8 },
  333. .p2 = { .dot_limit = 112000,
  334. .p2_slow = 14, .p2_fast = 14 },
  335. };
  336. /* Ironlake / Sandybridge
  337. *
  338. * We calculate clock using (register_value + 2) for N/M1/M2, so here
  339. * the range value for them is (actual_value - 2).
  340. */
  341. static const struct intel_limit intel_limits_ironlake_dac = {
  342. .dot = { .min = 25000, .max = 350000 },
  343. .vco = { .min = 1760000, .max = 3510000 },
  344. .n = { .min = 1, .max = 5 },
  345. .m = { .min = 79, .max = 127 },
  346. .m1 = { .min = 12, .max = 22 },
  347. .m2 = { .min = 5, .max = 9 },
  348. .p = { .min = 5, .max = 80 },
  349. .p1 = { .min = 1, .max = 8 },
  350. .p2 = { .dot_limit = 225000,
  351. .p2_slow = 10, .p2_fast = 5 },
  352. };
  353. static const struct intel_limit intel_limits_ironlake_single_lvds = {
  354. .dot = { .min = 25000, .max = 350000 },
  355. .vco = { .min = 1760000, .max = 3510000 },
  356. .n = { .min = 1, .max = 3 },
  357. .m = { .min = 79, .max = 118 },
  358. .m1 = { .min = 12, .max = 22 },
  359. .m2 = { .min = 5, .max = 9 },
  360. .p = { .min = 28, .max = 112 },
  361. .p1 = { .min = 2, .max = 8 },
  362. .p2 = { .dot_limit = 225000,
  363. .p2_slow = 14, .p2_fast = 14 },
  364. };
  365. static const struct intel_limit intel_limits_ironlake_dual_lvds = {
  366. .dot = { .min = 25000, .max = 350000 },
  367. .vco = { .min = 1760000, .max = 3510000 },
  368. .n = { .min = 1, .max = 3 },
  369. .m = { .min = 79, .max = 127 },
  370. .m1 = { .min = 12, .max = 22 },
  371. .m2 = { .min = 5, .max = 9 },
  372. .p = { .min = 14, .max = 56 },
  373. .p1 = { .min = 2, .max = 8 },
  374. .p2 = { .dot_limit = 225000,
  375. .p2_slow = 7, .p2_fast = 7 },
  376. };
  377. /* LVDS 100mhz refclk limits. */
  378. static const struct intel_limit intel_limits_ironlake_single_lvds_100m = {
  379. .dot = { .min = 25000, .max = 350000 },
  380. .vco = { .min = 1760000, .max = 3510000 },
  381. .n = { .min = 1, .max = 2 },
  382. .m = { .min = 79, .max = 126 },
  383. .m1 = { .min = 12, .max = 22 },
  384. .m2 = { .min = 5, .max = 9 },
  385. .p = { .min = 28, .max = 112 },
  386. .p1 = { .min = 2, .max = 8 },
  387. .p2 = { .dot_limit = 225000,
  388. .p2_slow = 14, .p2_fast = 14 },
  389. };
  390. static const struct intel_limit intel_limits_ironlake_dual_lvds_100m = {
  391. .dot = { .min = 25000, .max = 350000 },
  392. .vco = { .min = 1760000, .max = 3510000 },
  393. .n = { .min = 1, .max = 3 },
  394. .m = { .min = 79, .max = 126 },
  395. .m1 = { .min = 12, .max = 22 },
  396. .m2 = { .min = 5, .max = 9 },
  397. .p = { .min = 14, .max = 42 },
  398. .p1 = { .min = 2, .max = 6 },
  399. .p2 = { .dot_limit = 225000,
  400. .p2_slow = 7, .p2_fast = 7 },
  401. };
  402. static const struct intel_limit intel_limits_vlv = {
  403. /*
  404. * These are the data rate limits (measured in fast clocks)
  405. * since those are the strictest limits we have. The fast
  406. * clock and actual rate limits are more relaxed, so checking
  407. * them would make no difference.
  408. */
  409. .dot = { .min = 25000 * 5, .max = 270000 * 5 },
  410. .vco = { .min = 4000000, .max = 6000000 },
  411. .n = { .min = 1, .max = 7 },
  412. .m1 = { .min = 2, .max = 3 },
  413. .m2 = { .min = 11, .max = 156 },
  414. .p1 = { .min = 2, .max = 3 },
  415. .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */
  416. };
  417. static const struct intel_limit intel_limits_chv = {
  418. /*
  419. * These are the data rate limits (measured in fast clocks)
  420. * since those are the strictest limits we have. The fast
  421. * clock and actual rate limits are more relaxed, so checking
  422. * them would make no difference.
  423. */
  424. .dot = { .min = 25000 * 5, .max = 540000 * 5},
  425. .vco = { .min = 4800000, .max = 6480000 },
  426. .n = { .min = 1, .max = 1 },
  427. .m1 = { .min = 2, .max = 2 },
  428. .m2 = { .min = 24 << 22, .max = 175 << 22 },
  429. .p1 = { .min = 2, .max = 4 },
  430. .p2 = { .p2_slow = 1, .p2_fast = 14 },
  431. };
  432. static const struct intel_limit intel_limits_bxt = {
  433. /* FIXME: find real dot limits */
  434. .dot = { .min = 0, .max = INT_MAX },
  435. .vco = { .min = 4800000, .max = 6700000 },
  436. .n = { .min = 1, .max = 1 },
  437. .m1 = { .min = 2, .max = 2 },
  438. /* FIXME: find real m2 limits */
  439. .m2 = { .min = 2 << 22, .max = 255 << 22 },
  440. .p1 = { .min = 2, .max = 4 },
  441. .p2 = { .p2_slow = 1, .p2_fast = 20 },
  442. };
  443. static void
  444. skl_wa_clkgate(struct drm_i915_private *dev_priv, int pipe, bool enable)
  445. {
  446. if (IS_SKYLAKE(dev_priv))
  447. return;
  448. if (enable)
  449. I915_WRITE(CLKGATE_DIS_PSL(pipe),
  450. DUPS1_GATING_DIS | DUPS2_GATING_DIS);
  451. else
  452. I915_WRITE(CLKGATE_DIS_PSL(pipe),
  453. I915_READ(CLKGATE_DIS_PSL(pipe)) &
  454. ~(DUPS1_GATING_DIS | DUPS2_GATING_DIS));
  455. }
  456. static bool
  457. needs_modeset(const struct drm_crtc_state *state)
  458. {
  459. return drm_atomic_crtc_needs_modeset(state);
  460. }
  461. /*
  462. * Platform specific helpers to calculate the port PLL loopback- (clock.m),
  463. * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast
  464. * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic.
  465. * The helpers' return value is the rate of the clock that is fed to the
  466. * display engine's pipe which can be the above fast dot clock rate or a
  467. * divided-down version of it.
  468. */
  469. /* m1 is reserved as 0 in Pineview, n is a ring counter */
  470. static int pnv_calc_dpll_params(int refclk, struct dpll *clock)
  471. {
  472. clock->m = clock->m2 + 2;
  473. clock->p = clock->p1 * clock->p2;
  474. if (WARN_ON(clock->n == 0 || clock->p == 0))
  475. return 0;
  476. clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
  477. clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
  478. return clock->dot;
  479. }
  480. static uint32_t i9xx_dpll_compute_m(struct dpll *dpll)
  481. {
  482. return 5 * (dpll->m1 + 2) + (dpll->m2 + 2);
  483. }
  484. static int i9xx_calc_dpll_params(int refclk, struct dpll *clock)
  485. {
  486. clock->m = i9xx_dpll_compute_m(clock);
  487. clock->p = clock->p1 * clock->p2;
  488. if (WARN_ON(clock->n + 2 == 0 || clock->p == 0))
  489. return 0;
  490. clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2);
  491. clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
  492. return clock->dot;
  493. }
  494. static int vlv_calc_dpll_params(int refclk, struct dpll *clock)
  495. {
  496. clock->m = clock->m1 * clock->m2;
  497. clock->p = clock->p1 * clock->p2;
  498. if (WARN_ON(clock->n == 0 || clock->p == 0))
  499. return 0;
  500. clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
  501. clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
  502. return clock->dot / 5;
  503. }
  504. int chv_calc_dpll_params(int refclk, struct dpll *clock)
  505. {
  506. clock->m = clock->m1 * clock->m2;
  507. clock->p = clock->p1 * clock->p2;
  508. if (WARN_ON(clock->n == 0 || clock->p == 0))
  509. return 0;
  510. clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m,
  511. clock->n << 22);
  512. clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
  513. return clock->dot / 5;
  514. }
  515. #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
  516. /*
  517. * Returns whether the given set of divisors are valid for a given refclk with
  518. * the given connectors.
  519. */
  520. static bool intel_PLL_is_valid(struct drm_i915_private *dev_priv,
  521. const struct intel_limit *limit,
  522. const struct dpll *clock)
  523. {
  524. if (clock->n < limit->n.min || limit->n.max < clock->n)
  525. INTELPllInvalid("n out of range\n");
  526. if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
  527. INTELPllInvalid("p1 out of range\n");
  528. if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
  529. INTELPllInvalid("m2 out of range\n");
  530. if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
  531. INTELPllInvalid("m1 out of range\n");
  532. if (!IS_PINEVIEW(dev_priv) && !IS_VALLEYVIEW(dev_priv) &&
  533. !IS_CHERRYVIEW(dev_priv) && !IS_GEN9_LP(dev_priv))
  534. if (clock->m1 <= clock->m2)
  535. INTELPllInvalid("m1 <= m2\n");
  536. if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
  537. !IS_GEN9_LP(dev_priv)) {
  538. if (clock->p < limit->p.min || limit->p.max < clock->p)
  539. INTELPllInvalid("p out of range\n");
  540. if (clock->m < limit->m.min || limit->m.max < clock->m)
  541. INTELPllInvalid("m out of range\n");
  542. }
  543. if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
  544. INTELPllInvalid("vco out of range\n");
  545. /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
  546. * connector, etc., rather than just a single range.
  547. */
  548. if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
  549. INTELPllInvalid("dot out of range\n");
  550. return true;
  551. }
  552. static int
  553. i9xx_select_p2_div(const struct intel_limit *limit,
  554. const struct intel_crtc_state *crtc_state,
  555. int target)
  556. {
  557. struct drm_device *dev = crtc_state->base.crtc->dev;
  558. if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
  559. /*
  560. * For LVDS just rely on its current settings for dual-channel.
  561. * We haven't figured out how to reliably set up different
  562. * single/dual channel state, if we even can.
  563. */
  564. if (intel_is_dual_link_lvds(dev))
  565. return limit->p2.p2_fast;
  566. else
  567. return limit->p2.p2_slow;
  568. } else {
  569. if (target < limit->p2.dot_limit)
  570. return limit->p2.p2_slow;
  571. else
  572. return limit->p2.p2_fast;
  573. }
  574. }
  575. /*
  576. * Returns a set of divisors for the desired target clock with the given
  577. * refclk, or FALSE. The returned values represent the clock equation:
  578. * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
  579. *
  580. * Target and reference clocks are specified in kHz.
  581. *
  582. * If match_clock is provided, then best_clock P divider must match the P
  583. * divider from @match_clock used for LVDS downclocking.
  584. */
  585. static bool
  586. i9xx_find_best_dpll(const struct intel_limit *limit,
  587. struct intel_crtc_state *crtc_state,
  588. int target, int refclk, struct dpll *match_clock,
  589. struct dpll *best_clock)
  590. {
  591. struct drm_device *dev = crtc_state->base.crtc->dev;
  592. struct dpll clock;
  593. int err = target;
  594. memset(best_clock, 0, sizeof(*best_clock));
  595. clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
  596. for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
  597. clock.m1++) {
  598. for (clock.m2 = limit->m2.min;
  599. clock.m2 <= limit->m2.max; clock.m2++) {
  600. if (clock.m2 >= clock.m1)
  601. break;
  602. for (clock.n = limit->n.min;
  603. clock.n <= limit->n.max; clock.n++) {
  604. for (clock.p1 = limit->p1.min;
  605. clock.p1 <= limit->p1.max; clock.p1++) {
  606. int this_err;
  607. i9xx_calc_dpll_params(refclk, &clock);
  608. if (!intel_PLL_is_valid(to_i915(dev),
  609. limit,
  610. &clock))
  611. continue;
  612. if (match_clock &&
  613. clock.p != match_clock->p)
  614. continue;
  615. this_err = abs(clock.dot - target);
  616. if (this_err < err) {
  617. *best_clock = clock;
  618. err = this_err;
  619. }
  620. }
  621. }
  622. }
  623. }
  624. return (err != target);
  625. }
  626. /*
  627. * Returns a set of divisors for the desired target clock with the given
  628. * refclk, or FALSE. The returned values represent the clock equation:
  629. * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
  630. *
  631. * Target and reference clocks are specified in kHz.
  632. *
  633. * If match_clock is provided, then best_clock P divider must match the P
  634. * divider from @match_clock used for LVDS downclocking.
  635. */
  636. static bool
  637. pnv_find_best_dpll(const struct intel_limit *limit,
  638. struct intel_crtc_state *crtc_state,
  639. int target, int refclk, struct dpll *match_clock,
  640. struct dpll *best_clock)
  641. {
  642. struct drm_device *dev = crtc_state->base.crtc->dev;
  643. struct dpll clock;
  644. int err = target;
  645. memset(best_clock, 0, sizeof(*best_clock));
  646. clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
  647. for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
  648. clock.m1++) {
  649. for (clock.m2 = limit->m2.min;
  650. clock.m2 <= limit->m2.max; clock.m2++) {
  651. for (clock.n = limit->n.min;
  652. clock.n <= limit->n.max; clock.n++) {
  653. for (clock.p1 = limit->p1.min;
  654. clock.p1 <= limit->p1.max; clock.p1++) {
  655. int this_err;
  656. pnv_calc_dpll_params(refclk, &clock);
  657. if (!intel_PLL_is_valid(to_i915(dev),
  658. limit,
  659. &clock))
  660. continue;
  661. if (match_clock &&
  662. clock.p != match_clock->p)
  663. continue;
  664. this_err = abs(clock.dot - target);
  665. if (this_err < err) {
  666. *best_clock = clock;
  667. err = this_err;
  668. }
  669. }
  670. }
  671. }
  672. }
  673. return (err != target);
  674. }
  675. /*
  676. * Returns a set of divisors for the desired target clock with the given
  677. * refclk, or FALSE. The returned values represent the clock equation:
  678. * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
  679. *
  680. * Target and reference clocks are specified in kHz.
  681. *
  682. * If match_clock is provided, then best_clock P divider must match the P
  683. * divider from @match_clock used for LVDS downclocking.
  684. */
  685. static bool
  686. g4x_find_best_dpll(const struct intel_limit *limit,
  687. struct intel_crtc_state *crtc_state,
  688. int target, int refclk, struct dpll *match_clock,
  689. struct dpll *best_clock)
  690. {
  691. struct drm_device *dev = crtc_state->base.crtc->dev;
  692. struct dpll clock;
  693. int max_n;
  694. bool found = false;
  695. /* approximately equals target * 0.00585 */
  696. int err_most = (target >> 8) + (target >> 9);
  697. memset(best_clock, 0, sizeof(*best_clock));
  698. clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
  699. max_n = limit->n.max;
  700. /* based on hardware requirement, prefer smaller n to precision */
  701. for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
  702. /* based on hardware requirement, prefere larger m1,m2 */
  703. for (clock.m1 = limit->m1.max;
  704. clock.m1 >= limit->m1.min; clock.m1--) {
  705. for (clock.m2 = limit->m2.max;
  706. clock.m2 >= limit->m2.min; clock.m2--) {
  707. for (clock.p1 = limit->p1.max;
  708. clock.p1 >= limit->p1.min; clock.p1--) {
  709. int this_err;
  710. i9xx_calc_dpll_params(refclk, &clock);
  711. if (!intel_PLL_is_valid(to_i915(dev),
  712. limit,
  713. &clock))
  714. continue;
  715. this_err = abs(clock.dot - target);
  716. if (this_err < err_most) {
  717. *best_clock = clock;
  718. err_most = this_err;
  719. max_n = clock.n;
  720. found = true;
  721. }
  722. }
  723. }
  724. }
  725. }
  726. return found;
  727. }
  728. /*
  729. * Check if the calculated PLL configuration is more optimal compared to the
  730. * best configuration and error found so far. Return the calculated error.
  731. */
  732. static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq,
  733. const struct dpll *calculated_clock,
  734. const struct dpll *best_clock,
  735. unsigned int best_error_ppm,
  736. unsigned int *error_ppm)
  737. {
  738. /*
  739. * For CHV ignore the error and consider only the P value.
  740. * Prefer a bigger P value based on HW requirements.
  741. */
  742. if (IS_CHERRYVIEW(to_i915(dev))) {
  743. *error_ppm = 0;
  744. return calculated_clock->p > best_clock->p;
  745. }
  746. if (WARN_ON_ONCE(!target_freq))
  747. return false;
  748. *error_ppm = div_u64(1000000ULL *
  749. abs(target_freq - calculated_clock->dot),
  750. target_freq);
  751. /*
  752. * Prefer a better P value over a better (smaller) error if the error
  753. * is small. Ensure this preference for future configurations too by
  754. * setting the error to 0.
  755. */
  756. if (*error_ppm < 100 && calculated_clock->p > best_clock->p) {
  757. *error_ppm = 0;
  758. return true;
  759. }
  760. return *error_ppm + 10 < best_error_ppm;
  761. }
  762. /*
  763. * Returns a set of divisors for the desired target clock with the given
  764. * refclk, or FALSE. The returned values represent the clock equation:
  765. * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
  766. */
  767. static bool
  768. vlv_find_best_dpll(const struct intel_limit *limit,
  769. struct intel_crtc_state *crtc_state,
  770. int target, int refclk, struct dpll *match_clock,
  771. struct dpll *best_clock)
  772. {
  773. struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
  774. struct drm_device *dev = crtc->base.dev;
  775. struct dpll clock;
  776. unsigned int bestppm = 1000000;
  777. /* min update 19.2 MHz */
  778. int max_n = min(limit->n.max, refclk / 19200);
  779. bool found = false;
  780. target *= 5; /* fast clock */
  781. memset(best_clock, 0, sizeof(*best_clock));
  782. /* based on hardware requirement, prefer smaller n to precision */
  783. for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
  784. for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
  785. for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow;
  786. clock.p2 -= clock.p2 > 10 ? 2 : 1) {
  787. clock.p = clock.p1 * clock.p2;
  788. /* based on hardware requirement, prefer bigger m1,m2 values */
  789. for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) {
  790. unsigned int ppm;
  791. clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n,
  792. refclk * clock.m1);
  793. vlv_calc_dpll_params(refclk, &clock);
  794. if (!intel_PLL_is_valid(to_i915(dev),
  795. limit,
  796. &clock))
  797. continue;
  798. if (!vlv_PLL_is_optimal(dev, target,
  799. &clock,
  800. best_clock,
  801. bestppm, &ppm))
  802. continue;
  803. *best_clock = clock;
  804. bestppm = ppm;
  805. found = true;
  806. }
  807. }
  808. }
  809. }
  810. return found;
  811. }
  812. /*
  813. * Returns a set of divisors for the desired target clock with the given
  814. * refclk, or FALSE. The returned values represent the clock equation:
  815. * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
  816. */
  817. static bool
  818. chv_find_best_dpll(const struct intel_limit *limit,
  819. struct intel_crtc_state *crtc_state,
  820. int target, int refclk, struct dpll *match_clock,
  821. struct dpll *best_clock)
  822. {
  823. struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
  824. struct drm_device *dev = crtc->base.dev;
  825. unsigned int best_error_ppm;
  826. struct dpll clock;
  827. uint64_t m2;
  828. int found = false;
  829. memset(best_clock, 0, sizeof(*best_clock));
  830. best_error_ppm = 1000000;
  831. /*
  832. * Based on hardware doc, the n always set to 1, and m1 always
  833. * set to 2. If requires to support 200Mhz refclk, we need to
  834. * revisit this because n may not 1 anymore.
  835. */
  836. clock.n = 1, clock.m1 = 2;
  837. target *= 5; /* fast clock */
  838. for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
  839. for (clock.p2 = limit->p2.p2_fast;
  840. clock.p2 >= limit->p2.p2_slow;
  841. clock.p2 -= clock.p2 > 10 ? 2 : 1) {
  842. unsigned int error_ppm;
  843. clock.p = clock.p1 * clock.p2;
  844. m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p *
  845. clock.n) << 22, refclk * clock.m1);
  846. if (m2 > INT_MAX/clock.m1)
  847. continue;
  848. clock.m2 = m2;
  849. chv_calc_dpll_params(refclk, &clock);
  850. if (!intel_PLL_is_valid(to_i915(dev), limit, &clock))
  851. continue;
  852. if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock,
  853. best_error_ppm, &error_ppm))
  854. continue;
  855. *best_clock = clock;
  856. best_error_ppm = error_ppm;
  857. found = true;
  858. }
  859. }
  860. return found;
  861. }
  862. bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state, int target_clock,
  863. struct dpll *best_clock)
  864. {
  865. int refclk = 100000;
  866. const struct intel_limit *limit = &intel_limits_bxt;
  867. return chv_find_best_dpll(limit, crtc_state,
  868. target_clock, refclk, NULL, best_clock);
  869. }
  870. bool intel_crtc_active(struct intel_crtc *crtc)
  871. {
  872. /* Be paranoid as we can arrive here with only partial
  873. * state retrieved from the hardware during setup.
  874. *
  875. * We can ditch the adjusted_mode.crtc_clock check as soon
  876. * as Haswell has gained clock readout/fastboot support.
  877. *
  878. * We can ditch the crtc->primary->fb check as soon as we can
  879. * properly reconstruct framebuffers.
  880. *
  881. * FIXME: The intel_crtc->active here should be switched to
  882. * crtc->state->active once we have proper CRTC states wired up
  883. * for atomic.
  884. */
  885. return crtc->active && crtc->base.primary->state->fb &&
  886. crtc->config->base.adjusted_mode.crtc_clock;
  887. }
  888. enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv,
  889. enum pipe pipe)
  890. {
  891. struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
  892. return crtc->config->cpu_transcoder;
  893. }
  894. static bool pipe_scanline_is_moving(struct drm_i915_private *dev_priv,
  895. enum pipe pipe)
  896. {
  897. i915_reg_t reg = PIPEDSL(pipe);
  898. u32 line1, line2;
  899. u32 line_mask;
  900. if (IS_GEN2(dev_priv))
  901. line_mask = DSL_LINEMASK_GEN2;
  902. else
  903. line_mask = DSL_LINEMASK_GEN3;
  904. line1 = I915_READ(reg) & line_mask;
  905. msleep(5);
  906. line2 = I915_READ(reg) & line_mask;
  907. return line1 != line2;
  908. }
  909. static void wait_for_pipe_scanline_moving(struct intel_crtc *crtc, bool state)
  910. {
  911. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  912. enum pipe pipe = crtc->pipe;
  913. /* Wait for the display line to settle/start moving */
  914. if (wait_for(pipe_scanline_is_moving(dev_priv, pipe) == state, 100))
  915. DRM_ERROR("pipe %c scanline %s wait timed out\n",
  916. pipe_name(pipe), onoff(state));
  917. }
  918. static void intel_wait_for_pipe_scanline_stopped(struct intel_crtc *crtc)
  919. {
  920. wait_for_pipe_scanline_moving(crtc, false);
  921. }
  922. static void intel_wait_for_pipe_scanline_moving(struct intel_crtc *crtc)
  923. {
  924. wait_for_pipe_scanline_moving(crtc, true);
  925. }
  926. static void
  927. intel_wait_for_pipe_off(const struct intel_crtc_state *old_crtc_state)
  928. {
  929. struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
  930. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  931. if (INTEL_GEN(dev_priv) >= 4) {
  932. enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
  933. i915_reg_t reg = PIPECONF(cpu_transcoder);
  934. /* Wait for the Pipe State to go off */
  935. if (intel_wait_for_register(dev_priv,
  936. reg, I965_PIPECONF_ACTIVE, 0,
  937. 100))
  938. WARN(1, "pipe_off wait timed out\n");
  939. } else {
  940. intel_wait_for_pipe_scanline_stopped(crtc);
  941. }
  942. }
  943. /* Only for pre-ILK configs */
  944. void assert_pll(struct drm_i915_private *dev_priv,
  945. enum pipe pipe, bool state)
  946. {
  947. u32 val;
  948. bool cur_state;
  949. val = I915_READ(DPLL(pipe));
  950. cur_state = !!(val & DPLL_VCO_ENABLE);
  951. I915_STATE_WARN(cur_state != state,
  952. "PLL state assertion failure (expected %s, current %s)\n",
  953. onoff(state), onoff(cur_state));
  954. }
  955. /* XXX: the dsi pll is shared between MIPI DSI ports */
  956. void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state)
  957. {
  958. u32 val;
  959. bool cur_state;
  960. mutex_lock(&dev_priv->sb_lock);
  961. val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
  962. mutex_unlock(&dev_priv->sb_lock);
  963. cur_state = val & DSI_PLL_VCO_EN;
  964. I915_STATE_WARN(cur_state != state,
  965. "DSI PLL state assertion failure (expected %s, current %s)\n",
  966. onoff(state), onoff(cur_state));
  967. }
  968. static void assert_fdi_tx(struct drm_i915_private *dev_priv,
  969. enum pipe pipe, bool state)
  970. {
  971. bool cur_state;
  972. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  973. pipe);
  974. if (HAS_DDI(dev_priv)) {
  975. /* DDI does not have a specific FDI_TX register */
  976. u32 val = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
  977. cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
  978. } else {
  979. u32 val = I915_READ(FDI_TX_CTL(pipe));
  980. cur_state = !!(val & FDI_TX_ENABLE);
  981. }
  982. I915_STATE_WARN(cur_state != state,
  983. "FDI TX state assertion failure (expected %s, current %s)\n",
  984. onoff(state), onoff(cur_state));
  985. }
  986. #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
  987. #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
  988. static void assert_fdi_rx(struct drm_i915_private *dev_priv,
  989. enum pipe pipe, bool state)
  990. {
  991. u32 val;
  992. bool cur_state;
  993. val = I915_READ(FDI_RX_CTL(pipe));
  994. cur_state = !!(val & FDI_RX_ENABLE);
  995. I915_STATE_WARN(cur_state != state,
  996. "FDI RX state assertion failure (expected %s, current %s)\n",
  997. onoff(state), onoff(cur_state));
  998. }
  999. #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
  1000. #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
  1001. static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
  1002. enum pipe pipe)
  1003. {
  1004. u32 val;
  1005. /* ILK FDI PLL is always enabled */
  1006. if (IS_GEN5(dev_priv))
  1007. return;
  1008. /* On Haswell, DDI ports are responsible for the FDI PLL setup */
  1009. if (HAS_DDI(dev_priv))
  1010. return;
  1011. val = I915_READ(FDI_TX_CTL(pipe));
  1012. I915_STATE_WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n");
  1013. }
  1014. void assert_fdi_rx_pll(struct drm_i915_private *dev_priv,
  1015. enum pipe pipe, bool state)
  1016. {
  1017. u32 val;
  1018. bool cur_state;
  1019. val = I915_READ(FDI_RX_CTL(pipe));
  1020. cur_state = !!(val & FDI_RX_PLL_ENABLE);
  1021. I915_STATE_WARN(cur_state != state,
  1022. "FDI RX PLL assertion failure (expected %s, current %s)\n",
  1023. onoff(state), onoff(cur_state));
  1024. }
  1025. void assert_panel_unlocked(struct drm_i915_private *dev_priv, enum pipe pipe)
  1026. {
  1027. i915_reg_t pp_reg;
  1028. u32 val;
  1029. enum pipe panel_pipe = PIPE_A;
  1030. bool locked = true;
  1031. if (WARN_ON(HAS_DDI(dev_priv)))
  1032. return;
  1033. if (HAS_PCH_SPLIT(dev_priv)) {
  1034. u32 port_sel;
  1035. pp_reg = PP_CONTROL(0);
  1036. port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
  1037. if (port_sel == PANEL_PORT_SELECT_LVDS &&
  1038. I915_READ(PCH_LVDS) & LVDS_PIPEB_SELECT)
  1039. panel_pipe = PIPE_B;
  1040. /* XXX: else fix for eDP */
  1041. } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
  1042. /* presumably write lock depends on pipe, not port select */
  1043. pp_reg = PP_CONTROL(pipe);
  1044. panel_pipe = pipe;
  1045. } else {
  1046. pp_reg = PP_CONTROL(0);
  1047. if (I915_READ(LVDS) & LVDS_PIPEB_SELECT)
  1048. panel_pipe = PIPE_B;
  1049. }
  1050. val = I915_READ(pp_reg);
  1051. if (!(val & PANEL_POWER_ON) ||
  1052. ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS))
  1053. locked = false;
  1054. I915_STATE_WARN(panel_pipe == pipe && locked,
  1055. "panel assertion failure, pipe %c regs locked\n",
  1056. pipe_name(pipe));
  1057. }
  1058. void assert_pipe(struct drm_i915_private *dev_priv,
  1059. enum pipe pipe, bool state)
  1060. {
  1061. bool cur_state;
  1062. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  1063. pipe);
  1064. enum intel_display_power_domain power_domain;
  1065. /* we keep both pipes enabled on 830 */
  1066. if (IS_I830(dev_priv))
  1067. state = true;
  1068. power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
  1069. if (intel_display_power_get_if_enabled(dev_priv, power_domain)) {
  1070. u32 val = I915_READ(PIPECONF(cpu_transcoder));
  1071. cur_state = !!(val & PIPECONF_ENABLE);
  1072. intel_display_power_put(dev_priv, power_domain);
  1073. } else {
  1074. cur_state = false;
  1075. }
  1076. I915_STATE_WARN(cur_state != state,
  1077. "pipe %c assertion failure (expected %s, current %s)\n",
  1078. pipe_name(pipe), onoff(state), onoff(cur_state));
  1079. }
  1080. static void assert_plane(struct intel_plane *plane, bool state)
  1081. {
  1082. bool cur_state = plane->get_hw_state(plane);
  1083. I915_STATE_WARN(cur_state != state,
  1084. "%s assertion failure (expected %s, current %s)\n",
  1085. plane->base.name, onoff(state), onoff(cur_state));
  1086. }
  1087. #define assert_plane_enabled(p) assert_plane(p, true)
  1088. #define assert_plane_disabled(p) assert_plane(p, false)
  1089. static void assert_planes_disabled(struct intel_crtc *crtc)
  1090. {
  1091. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  1092. struct intel_plane *plane;
  1093. for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane)
  1094. assert_plane_disabled(plane);
  1095. }
  1096. static void assert_vblank_disabled(struct drm_crtc *crtc)
  1097. {
  1098. if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0))
  1099. drm_crtc_vblank_put(crtc);
  1100. }
  1101. void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv,
  1102. enum pipe pipe)
  1103. {
  1104. u32 val;
  1105. bool enabled;
  1106. val = I915_READ(PCH_TRANSCONF(pipe));
  1107. enabled = !!(val & TRANS_ENABLE);
  1108. I915_STATE_WARN(enabled,
  1109. "transcoder assertion failed, should be off on pipe %c but is still active\n",
  1110. pipe_name(pipe));
  1111. }
  1112. static bool dp_pipe_enabled(struct drm_i915_private *dev_priv,
  1113. enum pipe pipe, u32 port_sel, u32 val)
  1114. {
  1115. if ((val & DP_PORT_EN) == 0)
  1116. return false;
  1117. if (HAS_PCH_CPT(dev_priv)) {
  1118. u32 trans_dp_ctl = I915_READ(TRANS_DP_CTL(pipe));
  1119. if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel)
  1120. return false;
  1121. } else if (IS_CHERRYVIEW(dev_priv)) {
  1122. if ((val & DP_PIPE_MASK_CHV) != DP_PIPE_SELECT_CHV(pipe))
  1123. return false;
  1124. } else {
  1125. if ((val & DP_PIPE_MASK) != (pipe << 30))
  1126. return false;
  1127. }
  1128. return true;
  1129. }
  1130. static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv,
  1131. enum pipe pipe, u32 val)
  1132. {
  1133. if ((val & SDVO_ENABLE) == 0)
  1134. return false;
  1135. if (HAS_PCH_CPT(dev_priv)) {
  1136. if ((val & SDVO_PIPE_SEL_MASK_CPT) != SDVO_PIPE_SEL_CPT(pipe))
  1137. return false;
  1138. } else if (IS_CHERRYVIEW(dev_priv)) {
  1139. if ((val & SDVO_PIPE_SEL_MASK_CHV) != SDVO_PIPE_SEL_CHV(pipe))
  1140. return false;
  1141. } else {
  1142. if ((val & SDVO_PIPE_SEL_MASK) != SDVO_PIPE_SEL(pipe))
  1143. return false;
  1144. }
  1145. return true;
  1146. }
  1147. static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv,
  1148. enum pipe pipe, u32 val)
  1149. {
  1150. if ((val & LVDS_PORT_EN) == 0)
  1151. return false;
  1152. if (HAS_PCH_CPT(dev_priv)) {
  1153. if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
  1154. return false;
  1155. } else {
  1156. if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe))
  1157. return false;
  1158. }
  1159. return true;
  1160. }
  1161. static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv,
  1162. enum pipe pipe, u32 val)
  1163. {
  1164. if ((val & ADPA_DAC_ENABLE) == 0)
  1165. return false;
  1166. if (HAS_PCH_CPT(dev_priv)) {
  1167. if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
  1168. return false;
  1169. } else {
  1170. if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe))
  1171. return false;
  1172. }
  1173. return true;
  1174. }
  1175. static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
  1176. enum pipe pipe, i915_reg_t reg,
  1177. u32 port_sel)
  1178. {
  1179. u32 val = I915_READ(reg);
  1180. I915_STATE_WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val),
  1181. "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
  1182. i915_mmio_reg_offset(reg), pipe_name(pipe));
  1183. I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && (val & DP_PORT_EN) == 0
  1184. && (val & DP_PIPEB_SELECT),
  1185. "IBX PCH dp port still using transcoder B\n");
  1186. }
  1187. static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
  1188. enum pipe pipe, i915_reg_t reg)
  1189. {
  1190. u32 val = I915_READ(reg);
  1191. I915_STATE_WARN(hdmi_pipe_enabled(dev_priv, pipe, val),
  1192. "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
  1193. i915_mmio_reg_offset(reg), pipe_name(pipe));
  1194. I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && (val & SDVO_ENABLE) == 0
  1195. && (val & SDVO_PIPE_B_SELECT),
  1196. "IBX PCH hdmi port still using transcoder B\n");
  1197. }
  1198. static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
  1199. enum pipe pipe)
  1200. {
  1201. u32 val;
  1202. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B);
  1203. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C);
  1204. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_D, TRANS_DP_PORT_SEL_D);
  1205. val = I915_READ(PCH_ADPA);
  1206. I915_STATE_WARN(adpa_pipe_enabled(dev_priv, pipe, val),
  1207. "PCH VGA enabled on transcoder %c, should be disabled\n",
  1208. pipe_name(pipe));
  1209. val = I915_READ(PCH_LVDS);
  1210. I915_STATE_WARN(lvds_pipe_enabled(dev_priv, pipe, val),
  1211. "PCH LVDS enabled on transcoder %c, should be disabled\n",
  1212. pipe_name(pipe));
  1213. assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIB);
  1214. assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIC);
  1215. assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMID);
  1216. }
  1217. static void _vlv_enable_pll(struct intel_crtc *crtc,
  1218. const struct intel_crtc_state *pipe_config)
  1219. {
  1220. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  1221. enum pipe pipe = crtc->pipe;
  1222. I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll);
  1223. POSTING_READ(DPLL(pipe));
  1224. udelay(150);
  1225. if (intel_wait_for_register(dev_priv,
  1226. DPLL(pipe),
  1227. DPLL_LOCK_VLV,
  1228. DPLL_LOCK_VLV,
  1229. 1))
  1230. DRM_ERROR("DPLL %d failed to lock\n", pipe);
  1231. }
  1232. static void vlv_enable_pll(struct intel_crtc *crtc,
  1233. const struct intel_crtc_state *pipe_config)
  1234. {
  1235. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  1236. enum pipe pipe = crtc->pipe;
  1237. assert_pipe_disabled(dev_priv, pipe);
  1238. /* PLL is protected by panel, make sure we can write it */
  1239. assert_panel_unlocked(dev_priv, pipe);
  1240. if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
  1241. _vlv_enable_pll(crtc, pipe_config);
  1242. I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md);
  1243. POSTING_READ(DPLL_MD(pipe));
  1244. }
  1245. static void _chv_enable_pll(struct intel_crtc *crtc,
  1246. const struct intel_crtc_state *pipe_config)
  1247. {
  1248. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  1249. enum pipe pipe = crtc->pipe;
  1250. enum dpio_channel port = vlv_pipe_to_channel(pipe);
  1251. u32 tmp;
  1252. mutex_lock(&dev_priv->sb_lock);
  1253. /* Enable back the 10bit clock to display controller */
  1254. tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
  1255. tmp |= DPIO_DCLKP_EN;
  1256. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp);
  1257. mutex_unlock(&dev_priv->sb_lock);
  1258. /*
  1259. * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
  1260. */
  1261. udelay(1);
  1262. /* Enable PLL */
  1263. I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll);
  1264. /* Check PLL is locked */
  1265. if (intel_wait_for_register(dev_priv,
  1266. DPLL(pipe), DPLL_LOCK_VLV, DPLL_LOCK_VLV,
  1267. 1))
  1268. DRM_ERROR("PLL %d failed to lock\n", pipe);
  1269. }
  1270. static void chv_enable_pll(struct intel_crtc *crtc,
  1271. const struct intel_crtc_state *pipe_config)
  1272. {
  1273. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  1274. enum pipe pipe = crtc->pipe;
  1275. assert_pipe_disabled(dev_priv, pipe);
  1276. /* PLL is protected by panel, make sure we can write it */
  1277. assert_panel_unlocked(dev_priv, pipe);
  1278. if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
  1279. _chv_enable_pll(crtc, pipe_config);
  1280. if (pipe != PIPE_A) {
  1281. /*
  1282. * WaPixelRepeatModeFixForC0:chv
  1283. *
  1284. * DPLLCMD is AWOL. Use chicken bits to propagate
  1285. * the value from DPLLBMD to either pipe B or C.
  1286. */
  1287. I915_WRITE(CBR4_VLV, CBR_DPLLBMD_PIPE(pipe));
  1288. I915_WRITE(DPLL_MD(PIPE_B), pipe_config->dpll_hw_state.dpll_md);
  1289. I915_WRITE(CBR4_VLV, 0);
  1290. dev_priv->chv_dpll_md[pipe] = pipe_config->dpll_hw_state.dpll_md;
  1291. /*
  1292. * DPLLB VGA mode also seems to cause problems.
  1293. * We should always have it disabled.
  1294. */
  1295. WARN_ON((I915_READ(DPLL(PIPE_B)) & DPLL_VGA_MODE_DIS) == 0);
  1296. } else {
  1297. I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md);
  1298. POSTING_READ(DPLL_MD(pipe));
  1299. }
  1300. }
  1301. static int intel_num_dvo_pipes(struct drm_i915_private *dev_priv)
  1302. {
  1303. struct intel_crtc *crtc;
  1304. int count = 0;
  1305. for_each_intel_crtc(&dev_priv->drm, crtc) {
  1306. count += crtc->base.state->active &&
  1307. intel_crtc_has_type(crtc->config, INTEL_OUTPUT_DVO);
  1308. }
  1309. return count;
  1310. }
  1311. static void i9xx_enable_pll(struct intel_crtc *crtc,
  1312. const struct intel_crtc_state *crtc_state)
  1313. {
  1314. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  1315. i915_reg_t reg = DPLL(crtc->pipe);
  1316. u32 dpll = crtc_state->dpll_hw_state.dpll;
  1317. int i;
  1318. assert_pipe_disabled(dev_priv, crtc->pipe);
  1319. /* PLL is protected by panel, make sure we can write it */
  1320. if (IS_MOBILE(dev_priv) && !IS_I830(dev_priv))
  1321. assert_panel_unlocked(dev_priv, crtc->pipe);
  1322. /* Enable DVO 2x clock on both PLLs if necessary */
  1323. if (IS_I830(dev_priv) && intel_num_dvo_pipes(dev_priv) > 0) {
  1324. /*
  1325. * It appears to be important that we don't enable this
  1326. * for the current pipe before otherwise configuring the
  1327. * PLL. No idea how this should be handled if multiple
  1328. * DVO outputs are enabled simultaneosly.
  1329. */
  1330. dpll |= DPLL_DVO_2X_MODE;
  1331. I915_WRITE(DPLL(!crtc->pipe),
  1332. I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE);
  1333. }
  1334. /*
  1335. * Apparently we need to have VGA mode enabled prior to changing
  1336. * the P1/P2 dividers. Otherwise the DPLL will keep using the old
  1337. * dividers, even though the register value does change.
  1338. */
  1339. I915_WRITE(reg, 0);
  1340. I915_WRITE(reg, dpll);
  1341. /* Wait for the clocks to stabilize. */
  1342. POSTING_READ(reg);
  1343. udelay(150);
  1344. if (INTEL_GEN(dev_priv) >= 4) {
  1345. I915_WRITE(DPLL_MD(crtc->pipe),
  1346. crtc_state->dpll_hw_state.dpll_md);
  1347. } else {
  1348. /* The pixel multiplier can only be updated once the
  1349. * DPLL is enabled and the clocks are stable.
  1350. *
  1351. * So write it again.
  1352. */
  1353. I915_WRITE(reg, dpll);
  1354. }
  1355. /* We do this three times for luck */
  1356. for (i = 0; i < 3; i++) {
  1357. I915_WRITE(reg, dpll);
  1358. POSTING_READ(reg);
  1359. udelay(150); /* wait for warmup */
  1360. }
  1361. }
  1362. static void i9xx_disable_pll(struct intel_crtc *crtc)
  1363. {
  1364. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  1365. enum pipe pipe = crtc->pipe;
  1366. /* Disable DVO 2x clock on both PLLs if necessary */
  1367. if (IS_I830(dev_priv) &&
  1368. intel_crtc_has_type(crtc->config, INTEL_OUTPUT_DVO) &&
  1369. !intel_num_dvo_pipes(dev_priv)) {
  1370. I915_WRITE(DPLL(PIPE_B),
  1371. I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE);
  1372. I915_WRITE(DPLL(PIPE_A),
  1373. I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE);
  1374. }
  1375. /* Don't disable pipe or pipe PLLs if needed */
  1376. if (IS_I830(dev_priv))
  1377. return;
  1378. /* Make sure the pipe isn't still relying on us */
  1379. assert_pipe_disabled(dev_priv, pipe);
  1380. I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
  1381. POSTING_READ(DPLL(pipe));
  1382. }
  1383. static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
  1384. {
  1385. u32 val;
  1386. /* Make sure the pipe isn't still relying on us */
  1387. assert_pipe_disabled(dev_priv, pipe);
  1388. val = DPLL_INTEGRATED_REF_CLK_VLV |
  1389. DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
  1390. if (pipe != PIPE_A)
  1391. val |= DPLL_INTEGRATED_CRI_CLK_VLV;
  1392. I915_WRITE(DPLL(pipe), val);
  1393. POSTING_READ(DPLL(pipe));
  1394. }
  1395. static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
  1396. {
  1397. enum dpio_channel port = vlv_pipe_to_channel(pipe);
  1398. u32 val;
  1399. /* Make sure the pipe isn't still relying on us */
  1400. assert_pipe_disabled(dev_priv, pipe);
  1401. val = DPLL_SSC_REF_CLK_CHV |
  1402. DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
  1403. if (pipe != PIPE_A)
  1404. val |= DPLL_INTEGRATED_CRI_CLK_VLV;
  1405. I915_WRITE(DPLL(pipe), val);
  1406. POSTING_READ(DPLL(pipe));
  1407. mutex_lock(&dev_priv->sb_lock);
  1408. /* Disable 10bit clock to display controller */
  1409. val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
  1410. val &= ~DPIO_DCLKP_EN;
  1411. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val);
  1412. mutex_unlock(&dev_priv->sb_lock);
  1413. }
  1414. void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
  1415. struct intel_digital_port *dport,
  1416. unsigned int expected_mask)
  1417. {
  1418. u32 port_mask;
  1419. i915_reg_t dpll_reg;
  1420. switch (dport->base.port) {
  1421. case PORT_B:
  1422. port_mask = DPLL_PORTB_READY_MASK;
  1423. dpll_reg = DPLL(0);
  1424. break;
  1425. case PORT_C:
  1426. port_mask = DPLL_PORTC_READY_MASK;
  1427. dpll_reg = DPLL(0);
  1428. expected_mask <<= 4;
  1429. break;
  1430. case PORT_D:
  1431. port_mask = DPLL_PORTD_READY_MASK;
  1432. dpll_reg = DPIO_PHY_STATUS;
  1433. break;
  1434. default:
  1435. BUG();
  1436. }
  1437. if (intel_wait_for_register(dev_priv,
  1438. dpll_reg, port_mask, expected_mask,
  1439. 1000))
  1440. WARN(1, "timed out waiting for port %c ready: got 0x%x, expected 0x%x\n",
  1441. port_name(dport->base.port),
  1442. I915_READ(dpll_reg) & port_mask, expected_mask);
  1443. }
  1444. static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv,
  1445. enum pipe pipe)
  1446. {
  1447. struct intel_crtc *intel_crtc = intel_get_crtc_for_pipe(dev_priv,
  1448. pipe);
  1449. i915_reg_t reg;
  1450. uint32_t val, pipeconf_val;
  1451. /* Make sure PCH DPLL is enabled */
  1452. assert_shared_dpll_enabled(dev_priv, intel_crtc->config->shared_dpll);
  1453. /* FDI must be feeding us bits for PCH ports */
  1454. assert_fdi_tx_enabled(dev_priv, pipe);
  1455. assert_fdi_rx_enabled(dev_priv, pipe);
  1456. if (HAS_PCH_CPT(dev_priv)) {
  1457. /* Workaround: Set the timing override bit before enabling the
  1458. * pch transcoder. */
  1459. reg = TRANS_CHICKEN2(pipe);
  1460. val = I915_READ(reg);
  1461. val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
  1462. I915_WRITE(reg, val);
  1463. }
  1464. reg = PCH_TRANSCONF(pipe);
  1465. val = I915_READ(reg);
  1466. pipeconf_val = I915_READ(PIPECONF(pipe));
  1467. if (HAS_PCH_IBX(dev_priv)) {
  1468. /*
  1469. * Make the BPC in transcoder be consistent with
  1470. * that in pipeconf reg. For HDMI we must use 8bpc
  1471. * here for both 8bpc and 12bpc.
  1472. */
  1473. val &= ~PIPECONF_BPC_MASK;
  1474. if (intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_HDMI))
  1475. val |= PIPECONF_8BPC;
  1476. else
  1477. val |= pipeconf_val & PIPECONF_BPC_MASK;
  1478. }
  1479. val &= ~TRANS_INTERLACE_MASK;
  1480. if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK)
  1481. if (HAS_PCH_IBX(dev_priv) &&
  1482. intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_SDVO))
  1483. val |= TRANS_LEGACY_INTERLACED_ILK;
  1484. else
  1485. val |= TRANS_INTERLACED;
  1486. else
  1487. val |= TRANS_PROGRESSIVE;
  1488. I915_WRITE(reg, val | TRANS_ENABLE);
  1489. if (intel_wait_for_register(dev_priv,
  1490. reg, TRANS_STATE_ENABLE, TRANS_STATE_ENABLE,
  1491. 100))
  1492. DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe));
  1493. }
  1494. static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
  1495. enum transcoder cpu_transcoder)
  1496. {
  1497. u32 val, pipeconf_val;
  1498. /* FDI must be feeding us bits for PCH ports */
  1499. assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder);
  1500. assert_fdi_rx_enabled(dev_priv, PIPE_A);
  1501. /* Workaround: set timing override bit. */
  1502. val = I915_READ(TRANS_CHICKEN2(PIPE_A));
  1503. val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
  1504. I915_WRITE(TRANS_CHICKEN2(PIPE_A), val);
  1505. val = TRANS_ENABLE;
  1506. pipeconf_val = I915_READ(PIPECONF(cpu_transcoder));
  1507. if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) ==
  1508. PIPECONF_INTERLACED_ILK)
  1509. val |= TRANS_INTERLACED;
  1510. else
  1511. val |= TRANS_PROGRESSIVE;
  1512. I915_WRITE(LPT_TRANSCONF, val);
  1513. if (intel_wait_for_register(dev_priv,
  1514. LPT_TRANSCONF,
  1515. TRANS_STATE_ENABLE,
  1516. TRANS_STATE_ENABLE,
  1517. 100))
  1518. DRM_ERROR("Failed to enable PCH transcoder\n");
  1519. }
  1520. static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv,
  1521. enum pipe pipe)
  1522. {
  1523. i915_reg_t reg;
  1524. uint32_t val;
  1525. /* FDI relies on the transcoder */
  1526. assert_fdi_tx_disabled(dev_priv, pipe);
  1527. assert_fdi_rx_disabled(dev_priv, pipe);
  1528. /* Ports must be off as well */
  1529. assert_pch_ports_disabled(dev_priv, pipe);
  1530. reg = PCH_TRANSCONF(pipe);
  1531. val = I915_READ(reg);
  1532. val &= ~TRANS_ENABLE;
  1533. I915_WRITE(reg, val);
  1534. /* wait for PCH transcoder off, transcoder state */
  1535. if (intel_wait_for_register(dev_priv,
  1536. reg, TRANS_STATE_ENABLE, 0,
  1537. 50))
  1538. DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe));
  1539. if (HAS_PCH_CPT(dev_priv)) {
  1540. /* Workaround: Clear the timing override chicken bit again. */
  1541. reg = TRANS_CHICKEN2(pipe);
  1542. val = I915_READ(reg);
  1543. val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
  1544. I915_WRITE(reg, val);
  1545. }
  1546. }
  1547. void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
  1548. {
  1549. u32 val;
  1550. val = I915_READ(LPT_TRANSCONF);
  1551. val &= ~TRANS_ENABLE;
  1552. I915_WRITE(LPT_TRANSCONF, val);
  1553. /* wait for PCH transcoder off, transcoder state */
  1554. if (intel_wait_for_register(dev_priv,
  1555. LPT_TRANSCONF, TRANS_STATE_ENABLE, 0,
  1556. 50))
  1557. DRM_ERROR("Failed to disable PCH transcoder\n");
  1558. /* Workaround: clear timing override bit. */
  1559. val = I915_READ(TRANS_CHICKEN2(PIPE_A));
  1560. val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
  1561. I915_WRITE(TRANS_CHICKEN2(PIPE_A), val);
  1562. }
  1563. enum pipe intel_crtc_pch_transcoder(struct intel_crtc *crtc)
  1564. {
  1565. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  1566. if (HAS_PCH_LPT(dev_priv))
  1567. return PIPE_A;
  1568. else
  1569. return crtc->pipe;
  1570. }
  1571. static void intel_enable_pipe(const struct intel_crtc_state *new_crtc_state)
  1572. {
  1573. struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
  1574. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  1575. enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
  1576. enum pipe pipe = crtc->pipe;
  1577. i915_reg_t reg;
  1578. u32 val;
  1579. DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe));
  1580. assert_planes_disabled(crtc);
  1581. /*
  1582. * A pipe without a PLL won't actually be able to drive bits from
  1583. * a plane. On ILK+ the pipe PLLs are integrated, so we don't
  1584. * need the check.
  1585. */
  1586. if (HAS_GMCH_DISPLAY(dev_priv)) {
  1587. if (intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI))
  1588. assert_dsi_pll_enabled(dev_priv);
  1589. else
  1590. assert_pll_enabled(dev_priv, pipe);
  1591. } else {
  1592. if (new_crtc_state->has_pch_encoder) {
  1593. /* if driving the PCH, we need FDI enabled */
  1594. assert_fdi_rx_pll_enabled(dev_priv,
  1595. intel_crtc_pch_transcoder(crtc));
  1596. assert_fdi_tx_pll_enabled(dev_priv,
  1597. (enum pipe) cpu_transcoder);
  1598. }
  1599. /* FIXME: assert CPU port conditions for SNB+ */
  1600. }
  1601. reg = PIPECONF(cpu_transcoder);
  1602. val = I915_READ(reg);
  1603. if (val & PIPECONF_ENABLE) {
  1604. /* we keep both pipes enabled on 830 */
  1605. WARN_ON(!IS_I830(dev_priv));
  1606. return;
  1607. }
  1608. I915_WRITE(reg, val | PIPECONF_ENABLE);
  1609. POSTING_READ(reg);
  1610. /*
  1611. * Until the pipe starts PIPEDSL reads will return a stale value,
  1612. * which causes an apparent vblank timestamp jump when PIPEDSL
  1613. * resets to its proper value. That also messes up the frame count
  1614. * when it's derived from the timestamps. So let's wait for the
  1615. * pipe to start properly before we call drm_crtc_vblank_on()
  1616. */
  1617. if (dev_priv->drm.max_vblank_count == 0)
  1618. intel_wait_for_pipe_scanline_moving(crtc);
  1619. }
  1620. static void intel_disable_pipe(const struct intel_crtc_state *old_crtc_state)
  1621. {
  1622. struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
  1623. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  1624. enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
  1625. enum pipe pipe = crtc->pipe;
  1626. i915_reg_t reg;
  1627. u32 val;
  1628. DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe));
  1629. /*
  1630. * Make sure planes won't keep trying to pump pixels to us,
  1631. * or we might hang the display.
  1632. */
  1633. assert_planes_disabled(crtc);
  1634. reg = PIPECONF(cpu_transcoder);
  1635. val = I915_READ(reg);
  1636. if ((val & PIPECONF_ENABLE) == 0)
  1637. return;
  1638. /*
  1639. * Double wide has implications for planes
  1640. * so best keep it disabled when not needed.
  1641. */
  1642. if (old_crtc_state->double_wide)
  1643. val &= ~PIPECONF_DOUBLE_WIDE;
  1644. /* Don't disable pipe or pipe PLLs if needed */
  1645. if (!IS_I830(dev_priv))
  1646. val &= ~PIPECONF_ENABLE;
  1647. I915_WRITE(reg, val);
  1648. if ((val & PIPECONF_ENABLE) == 0)
  1649. intel_wait_for_pipe_off(old_crtc_state);
  1650. }
  1651. static unsigned int intel_tile_size(const struct drm_i915_private *dev_priv)
  1652. {
  1653. return IS_GEN2(dev_priv) ? 2048 : 4096;
  1654. }
  1655. static unsigned int
  1656. intel_tile_width_bytes(const struct drm_framebuffer *fb, int plane)
  1657. {
  1658. struct drm_i915_private *dev_priv = to_i915(fb->dev);
  1659. unsigned int cpp = fb->format->cpp[plane];
  1660. switch (fb->modifier) {
  1661. case DRM_FORMAT_MOD_LINEAR:
  1662. return cpp;
  1663. case I915_FORMAT_MOD_X_TILED:
  1664. if (IS_GEN2(dev_priv))
  1665. return 128;
  1666. else
  1667. return 512;
  1668. case I915_FORMAT_MOD_Y_TILED_CCS:
  1669. if (plane == 1)
  1670. return 128;
  1671. /* fall through */
  1672. case I915_FORMAT_MOD_Y_TILED:
  1673. if (IS_GEN2(dev_priv) || HAS_128_BYTE_Y_TILING(dev_priv))
  1674. return 128;
  1675. else
  1676. return 512;
  1677. case I915_FORMAT_MOD_Yf_TILED_CCS:
  1678. if (plane == 1)
  1679. return 128;
  1680. /* fall through */
  1681. case I915_FORMAT_MOD_Yf_TILED:
  1682. switch (cpp) {
  1683. case 1:
  1684. return 64;
  1685. case 2:
  1686. case 4:
  1687. return 128;
  1688. case 8:
  1689. case 16:
  1690. return 256;
  1691. default:
  1692. MISSING_CASE(cpp);
  1693. return cpp;
  1694. }
  1695. break;
  1696. default:
  1697. MISSING_CASE(fb->modifier);
  1698. return cpp;
  1699. }
  1700. }
  1701. static unsigned int
  1702. intel_tile_height(const struct drm_framebuffer *fb, int plane)
  1703. {
  1704. if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
  1705. return 1;
  1706. else
  1707. return intel_tile_size(to_i915(fb->dev)) /
  1708. intel_tile_width_bytes(fb, plane);
  1709. }
  1710. /* Return the tile dimensions in pixel units */
  1711. static void intel_tile_dims(const struct drm_framebuffer *fb, int plane,
  1712. unsigned int *tile_width,
  1713. unsigned int *tile_height)
  1714. {
  1715. unsigned int tile_width_bytes = intel_tile_width_bytes(fb, plane);
  1716. unsigned int cpp = fb->format->cpp[plane];
  1717. *tile_width = tile_width_bytes / cpp;
  1718. *tile_height = intel_tile_size(to_i915(fb->dev)) / tile_width_bytes;
  1719. }
  1720. unsigned int
  1721. intel_fb_align_height(const struct drm_framebuffer *fb,
  1722. int plane, unsigned int height)
  1723. {
  1724. unsigned int tile_height = intel_tile_height(fb, plane);
  1725. return ALIGN(height, tile_height);
  1726. }
  1727. unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info)
  1728. {
  1729. unsigned int size = 0;
  1730. int i;
  1731. for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++)
  1732. size += rot_info->plane[i].width * rot_info->plane[i].height;
  1733. return size;
  1734. }
  1735. static void
  1736. intel_fill_fb_ggtt_view(struct i915_ggtt_view *view,
  1737. const struct drm_framebuffer *fb,
  1738. unsigned int rotation)
  1739. {
  1740. view->type = I915_GGTT_VIEW_NORMAL;
  1741. if (drm_rotation_90_or_270(rotation)) {
  1742. view->type = I915_GGTT_VIEW_ROTATED;
  1743. view->rotated = to_intel_framebuffer(fb)->rot_info;
  1744. }
  1745. }
  1746. static unsigned int intel_cursor_alignment(const struct drm_i915_private *dev_priv)
  1747. {
  1748. if (IS_I830(dev_priv))
  1749. return 16 * 1024;
  1750. else if (IS_I85X(dev_priv))
  1751. return 256;
  1752. else if (IS_I845G(dev_priv) || IS_I865G(dev_priv))
  1753. return 32;
  1754. else
  1755. return 4 * 1024;
  1756. }
  1757. static unsigned int intel_linear_alignment(const struct drm_i915_private *dev_priv)
  1758. {
  1759. if (INTEL_GEN(dev_priv) >= 9)
  1760. return 256 * 1024;
  1761. else if (IS_I965G(dev_priv) || IS_I965GM(dev_priv) ||
  1762. IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  1763. return 128 * 1024;
  1764. else if (INTEL_GEN(dev_priv) >= 4)
  1765. return 4 * 1024;
  1766. else
  1767. return 0;
  1768. }
  1769. static unsigned int intel_surf_alignment(const struct drm_framebuffer *fb,
  1770. int plane)
  1771. {
  1772. struct drm_i915_private *dev_priv = to_i915(fb->dev);
  1773. /* AUX_DIST needs only 4K alignment */
  1774. if (plane == 1)
  1775. return 4096;
  1776. switch (fb->modifier) {
  1777. case DRM_FORMAT_MOD_LINEAR:
  1778. return intel_linear_alignment(dev_priv);
  1779. case I915_FORMAT_MOD_X_TILED:
  1780. if (INTEL_GEN(dev_priv) >= 9)
  1781. return 256 * 1024;
  1782. return 0;
  1783. case I915_FORMAT_MOD_Y_TILED_CCS:
  1784. case I915_FORMAT_MOD_Yf_TILED_CCS:
  1785. case I915_FORMAT_MOD_Y_TILED:
  1786. case I915_FORMAT_MOD_Yf_TILED:
  1787. return 1 * 1024 * 1024;
  1788. default:
  1789. MISSING_CASE(fb->modifier);
  1790. return 0;
  1791. }
  1792. }
  1793. static bool intel_plane_uses_fence(const struct intel_plane_state *plane_state)
  1794. {
  1795. struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
  1796. struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
  1797. return INTEL_GEN(dev_priv) < 4 || plane->has_fbc;
  1798. }
  1799. struct i915_vma *
  1800. intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb,
  1801. unsigned int rotation,
  1802. bool uses_fence,
  1803. unsigned long *out_flags)
  1804. {
  1805. struct drm_device *dev = fb->dev;
  1806. struct drm_i915_private *dev_priv = to_i915(dev);
  1807. struct drm_i915_gem_object *obj = intel_fb_obj(fb);
  1808. struct i915_ggtt_view view;
  1809. struct i915_vma *vma;
  1810. unsigned int pinctl;
  1811. u32 alignment;
  1812. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  1813. alignment = intel_surf_alignment(fb, 0);
  1814. intel_fill_fb_ggtt_view(&view, fb, rotation);
  1815. /* Note that the w/a also requires 64 PTE of padding following the
  1816. * bo. We currently fill all unused PTE with the shadow page and so
  1817. * we should always have valid PTE following the scanout preventing
  1818. * the VT-d warning.
  1819. */
  1820. if (intel_scanout_needs_vtd_wa(dev_priv) && alignment < 256 * 1024)
  1821. alignment = 256 * 1024;
  1822. /*
  1823. * Global gtt pte registers are special registers which actually forward
  1824. * writes to a chunk of system memory. Which means that there is no risk
  1825. * that the register values disappear as soon as we call
  1826. * intel_runtime_pm_put(), so it is correct to wrap only the
  1827. * pin/unpin/fence and not more.
  1828. */
  1829. intel_runtime_pm_get(dev_priv);
  1830. atomic_inc(&dev_priv->gpu_error.pending_fb_pin);
  1831. pinctl = 0;
  1832. /* Valleyview is definitely limited to scanning out the first
  1833. * 512MiB. Lets presume this behaviour was inherited from the
  1834. * g4x display engine and that all earlier gen are similarly
  1835. * limited. Testing suggests that it is a little more
  1836. * complicated than this. For example, Cherryview appears quite
  1837. * happy to scanout from anywhere within its global aperture.
  1838. */
  1839. if (HAS_GMCH_DISPLAY(dev_priv))
  1840. pinctl |= PIN_MAPPABLE;
  1841. vma = i915_gem_object_pin_to_display_plane(obj,
  1842. alignment, &view, pinctl);
  1843. if (IS_ERR(vma))
  1844. goto err;
  1845. if (uses_fence && i915_vma_is_map_and_fenceable(vma)) {
  1846. int ret;
  1847. /* Install a fence for tiled scan-out. Pre-i965 always needs a
  1848. * fence, whereas 965+ only requires a fence if using
  1849. * framebuffer compression. For simplicity, we always, when
  1850. * possible, install a fence as the cost is not that onerous.
  1851. *
  1852. * If we fail to fence the tiled scanout, then either the
  1853. * modeset will reject the change (which is highly unlikely as
  1854. * the affected systems, all but one, do not have unmappable
  1855. * space) or we will not be able to enable full powersaving
  1856. * techniques (also likely not to apply due to various limits
  1857. * FBC and the like impose on the size of the buffer, which
  1858. * presumably we violated anyway with this unmappable buffer).
  1859. * Anyway, it is presumably better to stumble onwards with
  1860. * something and try to run the system in a "less than optimal"
  1861. * mode that matches the user configuration.
  1862. */
  1863. ret = i915_vma_pin_fence(vma);
  1864. if (ret != 0 && INTEL_GEN(dev_priv) < 4) {
  1865. i915_gem_object_unpin_from_display_plane(vma);
  1866. vma = ERR_PTR(ret);
  1867. goto err;
  1868. }
  1869. if (ret == 0 && vma->fence)
  1870. *out_flags |= PLANE_HAS_FENCE;
  1871. }
  1872. i915_vma_get(vma);
  1873. err:
  1874. atomic_dec(&dev_priv->gpu_error.pending_fb_pin);
  1875. intel_runtime_pm_put(dev_priv);
  1876. return vma;
  1877. }
  1878. void intel_unpin_fb_vma(struct i915_vma *vma, unsigned long flags)
  1879. {
  1880. lockdep_assert_held(&vma->vm->i915->drm.struct_mutex);
  1881. if (flags & PLANE_HAS_FENCE)
  1882. i915_vma_unpin_fence(vma);
  1883. i915_gem_object_unpin_from_display_plane(vma);
  1884. i915_vma_put(vma);
  1885. }
  1886. static int intel_fb_pitch(const struct drm_framebuffer *fb, int plane,
  1887. unsigned int rotation)
  1888. {
  1889. if (drm_rotation_90_or_270(rotation))
  1890. return to_intel_framebuffer(fb)->rotated[plane].pitch;
  1891. else
  1892. return fb->pitches[plane];
  1893. }
  1894. /*
  1895. * Convert the x/y offsets into a linear offset.
  1896. * Only valid with 0/180 degree rotation, which is fine since linear
  1897. * offset is only used with linear buffers on pre-hsw and tiled buffers
  1898. * with gen2/3, and 90/270 degree rotations isn't supported on any of them.
  1899. */
  1900. u32 intel_fb_xy_to_linear(int x, int y,
  1901. const struct intel_plane_state *state,
  1902. int plane)
  1903. {
  1904. const struct drm_framebuffer *fb = state->base.fb;
  1905. unsigned int cpp = fb->format->cpp[plane];
  1906. unsigned int pitch = fb->pitches[plane];
  1907. return y * pitch + x * cpp;
  1908. }
  1909. /*
  1910. * Add the x/y offsets derived from fb->offsets[] to the user
  1911. * specified plane src x/y offsets. The resulting x/y offsets
  1912. * specify the start of scanout from the beginning of the gtt mapping.
  1913. */
  1914. void intel_add_fb_offsets(int *x, int *y,
  1915. const struct intel_plane_state *state,
  1916. int plane)
  1917. {
  1918. const struct intel_framebuffer *intel_fb = to_intel_framebuffer(state->base.fb);
  1919. unsigned int rotation = state->base.rotation;
  1920. if (drm_rotation_90_or_270(rotation)) {
  1921. *x += intel_fb->rotated[plane].x;
  1922. *y += intel_fb->rotated[plane].y;
  1923. } else {
  1924. *x += intel_fb->normal[plane].x;
  1925. *y += intel_fb->normal[plane].y;
  1926. }
  1927. }
  1928. static u32 __intel_adjust_tile_offset(int *x, int *y,
  1929. unsigned int tile_width,
  1930. unsigned int tile_height,
  1931. unsigned int tile_size,
  1932. unsigned int pitch_tiles,
  1933. u32 old_offset,
  1934. u32 new_offset)
  1935. {
  1936. unsigned int pitch_pixels = pitch_tiles * tile_width;
  1937. unsigned int tiles;
  1938. WARN_ON(old_offset & (tile_size - 1));
  1939. WARN_ON(new_offset & (tile_size - 1));
  1940. WARN_ON(new_offset > old_offset);
  1941. tiles = (old_offset - new_offset) / tile_size;
  1942. *y += tiles / pitch_tiles * tile_height;
  1943. *x += tiles % pitch_tiles * tile_width;
  1944. /* minimize x in case it got needlessly big */
  1945. *y += *x / pitch_pixels * tile_height;
  1946. *x %= pitch_pixels;
  1947. return new_offset;
  1948. }
  1949. static u32 _intel_adjust_tile_offset(int *x, int *y,
  1950. const struct drm_framebuffer *fb, int plane,
  1951. unsigned int rotation,
  1952. u32 old_offset, u32 new_offset)
  1953. {
  1954. const struct drm_i915_private *dev_priv = to_i915(fb->dev);
  1955. unsigned int cpp = fb->format->cpp[plane];
  1956. unsigned int pitch = intel_fb_pitch(fb, plane, rotation);
  1957. WARN_ON(new_offset > old_offset);
  1958. if (fb->modifier != DRM_FORMAT_MOD_LINEAR) {
  1959. unsigned int tile_size, tile_width, tile_height;
  1960. unsigned int pitch_tiles;
  1961. tile_size = intel_tile_size(dev_priv);
  1962. intel_tile_dims(fb, plane, &tile_width, &tile_height);
  1963. if (drm_rotation_90_or_270(rotation)) {
  1964. pitch_tiles = pitch / tile_height;
  1965. swap(tile_width, tile_height);
  1966. } else {
  1967. pitch_tiles = pitch / (tile_width * cpp);
  1968. }
  1969. __intel_adjust_tile_offset(x, y, tile_width, tile_height,
  1970. tile_size, pitch_tiles,
  1971. old_offset, new_offset);
  1972. } else {
  1973. old_offset += *y * pitch + *x * cpp;
  1974. *y = (old_offset - new_offset) / pitch;
  1975. *x = ((old_offset - new_offset) - *y * pitch) / cpp;
  1976. }
  1977. return new_offset;
  1978. }
  1979. /*
  1980. * Adjust the tile offset by moving the difference into
  1981. * the x/y offsets.
  1982. */
  1983. static u32 intel_adjust_tile_offset(int *x, int *y,
  1984. const struct intel_plane_state *state, int plane,
  1985. u32 old_offset, u32 new_offset)
  1986. {
  1987. return _intel_adjust_tile_offset(x, y, state->base.fb, plane,
  1988. state->base.rotation,
  1989. old_offset, new_offset);
  1990. }
  1991. /*
  1992. * Computes the linear offset to the base tile and adjusts
  1993. * x, y. bytes per pixel is assumed to be a power-of-two.
  1994. *
  1995. * In the 90/270 rotated case, x and y are assumed
  1996. * to be already rotated to match the rotated GTT view, and
  1997. * pitch is the tile_height aligned framebuffer height.
  1998. *
  1999. * This function is used when computing the derived information
  2000. * under intel_framebuffer, so using any of that information
  2001. * here is not allowed. Anything under drm_framebuffer can be
  2002. * used. This is why the user has to pass in the pitch since it
  2003. * is specified in the rotated orientation.
  2004. */
  2005. static u32 _intel_compute_tile_offset(const struct drm_i915_private *dev_priv,
  2006. int *x, int *y,
  2007. const struct drm_framebuffer *fb, int plane,
  2008. unsigned int pitch,
  2009. unsigned int rotation,
  2010. u32 alignment)
  2011. {
  2012. uint64_t fb_modifier = fb->modifier;
  2013. unsigned int cpp = fb->format->cpp[plane];
  2014. u32 offset, offset_aligned;
  2015. if (alignment)
  2016. alignment--;
  2017. if (fb_modifier != DRM_FORMAT_MOD_LINEAR) {
  2018. unsigned int tile_size, tile_width, tile_height;
  2019. unsigned int tile_rows, tiles, pitch_tiles;
  2020. tile_size = intel_tile_size(dev_priv);
  2021. intel_tile_dims(fb, plane, &tile_width, &tile_height);
  2022. if (drm_rotation_90_or_270(rotation)) {
  2023. pitch_tiles = pitch / tile_height;
  2024. swap(tile_width, tile_height);
  2025. } else {
  2026. pitch_tiles = pitch / (tile_width * cpp);
  2027. }
  2028. tile_rows = *y / tile_height;
  2029. *y %= tile_height;
  2030. tiles = *x / tile_width;
  2031. *x %= tile_width;
  2032. offset = (tile_rows * pitch_tiles + tiles) * tile_size;
  2033. offset_aligned = offset & ~alignment;
  2034. __intel_adjust_tile_offset(x, y, tile_width, tile_height,
  2035. tile_size, pitch_tiles,
  2036. offset, offset_aligned);
  2037. } else {
  2038. offset = *y * pitch + *x * cpp;
  2039. offset_aligned = offset & ~alignment;
  2040. *y = (offset & alignment) / pitch;
  2041. *x = ((offset & alignment) - *y * pitch) / cpp;
  2042. }
  2043. return offset_aligned;
  2044. }
  2045. u32 intel_compute_tile_offset(int *x, int *y,
  2046. const struct intel_plane_state *state,
  2047. int plane)
  2048. {
  2049. struct intel_plane *intel_plane = to_intel_plane(state->base.plane);
  2050. struct drm_i915_private *dev_priv = to_i915(intel_plane->base.dev);
  2051. const struct drm_framebuffer *fb = state->base.fb;
  2052. unsigned int rotation = state->base.rotation;
  2053. int pitch = intel_fb_pitch(fb, plane, rotation);
  2054. u32 alignment;
  2055. if (intel_plane->id == PLANE_CURSOR)
  2056. alignment = intel_cursor_alignment(dev_priv);
  2057. else
  2058. alignment = intel_surf_alignment(fb, plane);
  2059. return _intel_compute_tile_offset(dev_priv, x, y, fb, plane, pitch,
  2060. rotation, alignment);
  2061. }
  2062. /* Convert the fb->offset[] into x/y offsets */
  2063. static int intel_fb_offset_to_xy(int *x, int *y,
  2064. const struct drm_framebuffer *fb, int plane)
  2065. {
  2066. struct drm_i915_private *dev_priv = to_i915(fb->dev);
  2067. if (fb->modifier != DRM_FORMAT_MOD_LINEAR &&
  2068. fb->offsets[plane] % intel_tile_size(dev_priv))
  2069. return -EINVAL;
  2070. *x = 0;
  2071. *y = 0;
  2072. _intel_adjust_tile_offset(x, y,
  2073. fb, plane, DRM_MODE_ROTATE_0,
  2074. fb->offsets[plane], 0);
  2075. return 0;
  2076. }
  2077. static unsigned int intel_fb_modifier_to_tiling(uint64_t fb_modifier)
  2078. {
  2079. switch (fb_modifier) {
  2080. case I915_FORMAT_MOD_X_TILED:
  2081. return I915_TILING_X;
  2082. case I915_FORMAT_MOD_Y_TILED:
  2083. case I915_FORMAT_MOD_Y_TILED_CCS:
  2084. return I915_TILING_Y;
  2085. default:
  2086. return I915_TILING_NONE;
  2087. }
  2088. }
  2089. /*
  2090. * From the Sky Lake PRM:
  2091. * "The Color Control Surface (CCS) contains the compression status of
  2092. * the cache-line pairs. The compression state of the cache-line pair
  2093. * is specified by 2 bits in the CCS. Each CCS cache-line represents
  2094. * an area on the main surface of 16 x16 sets of 128 byte Y-tiled
  2095. * cache-line-pairs. CCS is always Y tiled."
  2096. *
  2097. * Since cache line pairs refers to horizontally adjacent cache lines,
  2098. * each cache line in the CCS corresponds to an area of 32x16 cache
  2099. * lines on the main surface. Since each pixel is 4 bytes, this gives
  2100. * us a ratio of one byte in the CCS for each 8x16 pixels in the
  2101. * main surface.
  2102. */
  2103. static const struct drm_format_info ccs_formats[] = {
  2104. { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
  2105. { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
  2106. { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
  2107. { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
  2108. };
  2109. static const struct drm_format_info *
  2110. lookup_format_info(const struct drm_format_info formats[],
  2111. int num_formats, u32 format)
  2112. {
  2113. int i;
  2114. for (i = 0; i < num_formats; i++) {
  2115. if (formats[i].format == format)
  2116. return &formats[i];
  2117. }
  2118. return NULL;
  2119. }
  2120. static const struct drm_format_info *
  2121. intel_get_format_info(const struct drm_mode_fb_cmd2 *cmd)
  2122. {
  2123. switch (cmd->modifier[0]) {
  2124. case I915_FORMAT_MOD_Y_TILED_CCS:
  2125. case I915_FORMAT_MOD_Yf_TILED_CCS:
  2126. return lookup_format_info(ccs_formats,
  2127. ARRAY_SIZE(ccs_formats),
  2128. cmd->pixel_format);
  2129. default:
  2130. return NULL;
  2131. }
  2132. }
  2133. static int
  2134. intel_fill_fb_info(struct drm_i915_private *dev_priv,
  2135. struct drm_framebuffer *fb)
  2136. {
  2137. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  2138. struct intel_rotation_info *rot_info = &intel_fb->rot_info;
  2139. u32 gtt_offset_rotated = 0;
  2140. unsigned int max_size = 0;
  2141. int i, num_planes = fb->format->num_planes;
  2142. unsigned int tile_size = intel_tile_size(dev_priv);
  2143. for (i = 0; i < num_planes; i++) {
  2144. unsigned int width, height;
  2145. unsigned int cpp, size;
  2146. u32 offset;
  2147. int x, y;
  2148. int ret;
  2149. cpp = fb->format->cpp[i];
  2150. width = drm_framebuffer_plane_width(fb->width, fb, i);
  2151. height = drm_framebuffer_plane_height(fb->height, fb, i);
  2152. ret = intel_fb_offset_to_xy(&x, &y, fb, i);
  2153. if (ret) {
  2154. DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
  2155. i, fb->offsets[i]);
  2156. return ret;
  2157. }
  2158. if ((fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
  2159. fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS) && i == 1) {
  2160. int hsub = fb->format->hsub;
  2161. int vsub = fb->format->vsub;
  2162. int tile_width, tile_height;
  2163. int main_x, main_y;
  2164. int ccs_x, ccs_y;
  2165. intel_tile_dims(fb, i, &tile_width, &tile_height);
  2166. tile_width *= hsub;
  2167. tile_height *= vsub;
  2168. ccs_x = (x * hsub) % tile_width;
  2169. ccs_y = (y * vsub) % tile_height;
  2170. main_x = intel_fb->normal[0].x % tile_width;
  2171. main_y = intel_fb->normal[0].y % tile_height;
  2172. /*
  2173. * CCS doesn't have its own x/y offset register, so the intra CCS tile
  2174. * x/y offsets must match between CCS and the main surface.
  2175. */
  2176. if (main_x != ccs_x || main_y != ccs_y) {
  2177. DRM_DEBUG_KMS("Bad CCS x/y (main %d,%d ccs %d,%d) full (main %d,%d ccs %d,%d)\n",
  2178. main_x, main_y,
  2179. ccs_x, ccs_y,
  2180. intel_fb->normal[0].x,
  2181. intel_fb->normal[0].y,
  2182. x, y);
  2183. return -EINVAL;
  2184. }
  2185. }
  2186. /*
  2187. * The fence (if used) is aligned to the start of the object
  2188. * so having the framebuffer wrap around across the edge of the
  2189. * fenced region doesn't really work. We have no API to configure
  2190. * the fence start offset within the object (nor could we probably
  2191. * on gen2/3). So it's just easier if we just require that the
  2192. * fb layout agrees with the fence layout. We already check that the
  2193. * fb stride matches the fence stride elsewhere.
  2194. */
  2195. if (i == 0 && i915_gem_object_is_tiled(intel_fb->obj) &&
  2196. (x + width) * cpp > fb->pitches[i]) {
  2197. DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
  2198. i, fb->offsets[i]);
  2199. return -EINVAL;
  2200. }
  2201. /*
  2202. * First pixel of the framebuffer from
  2203. * the start of the normal gtt mapping.
  2204. */
  2205. intel_fb->normal[i].x = x;
  2206. intel_fb->normal[i].y = y;
  2207. offset = _intel_compute_tile_offset(dev_priv, &x, &y,
  2208. fb, i, fb->pitches[i],
  2209. DRM_MODE_ROTATE_0, tile_size);
  2210. offset /= tile_size;
  2211. if (fb->modifier != DRM_FORMAT_MOD_LINEAR) {
  2212. unsigned int tile_width, tile_height;
  2213. unsigned int pitch_tiles;
  2214. struct drm_rect r;
  2215. intel_tile_dims(fb, i, &tile_width, &tile_height);
  2216. rot_info->plane[i].offset = offset;
  2217. rot_info->plane[i].stride = DIV_ROUND_UP(fb->pitches[i], tile_width * cpp);
  2218. rot_info->plane[i].width = DIV_ROUND_UP(x + width, tile_width);
  2219. rot_info->plane[i].height = DIV_ROUND_UP(y + height, tile_height);
  2220. intel_fb->rotated[i].pitch =
  2221. rot_info->plane[i].height * tile_height;
  2222. /* how many tiles does this plane need */
  2223. size = rot_info->plane[i].stride * rot_info->plane[i].height;
  2224. /*
  2225. * If the plane isn't horizontally tile aligned,
  2226. * we need one more tile.
  2227. */
  2228. if (x != 0)
  2229. size++;
  2230. /* rotate the x/y offsets to match the GTT view */
  2231. r.x1 = x;
  2232. r.y1 = y;
  2233. r.x2 = x + width;
  2234. r.y2 = y + height;
  2235. drm_rect_rotate(&r,
  2236. rot_info->plane[i].width * tile_width,
  2237. rot_info->plane[i].height * tile_height,
  2238. DRM_MODE_ROTATE_270);
  2239. x = r.x1;
  2240. y = r.y1;
  2241. /* rotate the tile dimensions to match the GTT view */
  2242. pitch_tiles = intel_fb->rotated[i].pitch / tile_height;
  2243. swap(tile_width, tile_height);
  2244. /*
  2245. * We only keep the x/y offsets, so push all of the
  2246. * gtt offset into the x/y offsets.
  2247. */
  2248. __intel_adjust_tile_offset(&x, &y,
  2249. tile_width, tile_height,
  2250. tile_size, pitch_tiles,
  2251. gtt_offset_rotated * tile_size, 0);
  2252. gtt_offset_rotated += rot_info->plane[i].width * rot_info->plane[i].height;
  2253. /*
  2254. * First pixel of the framebuffer from
  2255. * the start of the rotated gtt mapping.
  2256. */
  2257. intel_fb->rotated[i].x = x;
  2258. intel_fb->rotated[i].y = y;
  2259. } else {
  2260. size = DIV_ROUND_UP((y + height) * fb->pitches[i] +
  2261. x * cpp, tile_size);
  2262. }
  2263. /* how many tiles in total needed in the bo */
  2264. max_size = max(max_size, offset + size);
  2265. }
  2266. if (max_size * tile_size > intel_fb->obj->base.size) {
  2267. DRM_DEBUG_KMS("fb too big for bo (need %u bytes, have %zu bytes)\n",
  2268. max_size * tile_size, intel_fb->obj->base.size);
  2269. return -EINVAL;
  2270. }
  2271. return 0;
  2272. }
  2273. static int i9xx_format_to_fourcc(int format)
  2274. {
  2275. switch (format) {
  2276. case DISPPLANE_8BPP:
  2277. return DRM_FORMAT_C8;
  2278. case DISPPLANE_BGRX555:
  2279. return DRM_FORMAT_XRGB1555;
  2280. case DISPPLANE_BGRX565:
  2281. return DRM_FORMAT_RGB565;
  2282. default:
  2283. case DISPPLANE_BGRX888:
  2284. return DRM_FORMAT_XRGB8888;
  2285. case DISPPLANE_RGBX888:
  2286. return DRM_FORMAT_XBGR8888;
  2287. case DISPPLANE_BGRX101010:
  2288. return DRM_FORMAT_XRGB2101010;
  2289. case DISPPLANE_RGBX101010:
  2290. return DRM_FORMAT_XBGR2101010;
  2291. }
  2292. }
  2293. int skl_format_to_fourcc(int format, bool rgb_order, bool alpha)
  2294. {
  2295. switch (format) {
  2296. case PLANE_CTL_FORMAT_RGB_565:
  2297. return DRM_FORMAT_RGB565;
  2298. case PLANE_CTL_FORMAT_NV12:
  2299. return DRM_FORMAT_NV12;
  2300. default:
  2301. case PLANE_CTL_FORMAT_XRGB_8888:
  2302. if (rgb_order) {
  2303. if (alpha)
  2304. return DRM_FORMAT_ABGR8888;
  2305. else
  2306. return DRM_FORMAT_XBGR8888;
  2307. } else {
  2308. if (alpha)
  2309. return DRM_FORMAT_ARGB8888;
  2310. else
  2311. return DRM_FORMAT_XRGB8888;
  2312. }
  2313. case PLANE_CTL_FORMAT_XRGB_2101010:
  2314. if (rgb_order)
  2315. return DRM_FORMAT_XBGR2101010;
  2316. else
  2317. return DRM_FORMAT_XRGB2101010;
  2318. }
  2319. }
  2320. static bool
  2321. intel_alloc_initial_plane_obj(struct intel_crtc *crtc,
  2322. struct intel_initial_plane_config *plane_config)
  2323. {
  2324. struct drm_device *dev = crtc->base.dev;
  2325. struct drm_i915_private *dev_priv = to_i915(dev);
  2326. struct drm_i915_gem_object *obj = NULL;
  2327. struct drm_mode_fb_cmd2 mode_cmd = { 0 };
  2328. struct drm_framebuffer *fb = &plane_config->fb->base;
  2329. u32 base_aligned = round_down(plane_config->base, PAGE_SIZE);
  2330. u32 size_aligned = round_up(plane_config->base + plane_config->size,
  2331. PAGE_SIZE);
  2332. size_aligned -= base_aligned;
  2333. if (plane_config->size == 0)
  2334. return false;
  2335. /* If the FB is too big, just don't use it since fbdev is not very
  2336. * important and we should probably use that space with FBC or other
  2337. * features. */
  2338. if (size_aligned * 2 > dev_priv->stolen_usable_size)
  2339. return false;
  2340. mutex_lock(&dev->struct_mutex);
  2341. obj = i915_gem_object_create_stolen_for_preallocated(dev_priv,
  2342. base_aligned,
  2343. base_aligned,
  2344. size_aligned);
  2345. mutex_unlock(&dev->struct_mutex);
  2346. if (!obj)
  2347. return false;
  2348. if (plane_config->tiling == I915_TILING_X)
  2349. obj->tiling_and_stride = fb->pitches[0] | I915_TILING_X;
  2350. mode_cmd.pixel_format = fb->format->format;
  2351. mode_cmd.width = fb->width;
  2352. mode_cmd.height = fb->height;
  2353. mode_cmd.pitches[0] = fb->pitches[0];
  2354. mode_cmd.modifier[0] = fb->modifier;
  2355. mode_cmd.flags = DRM_MODE_FB_MODIFIERS;
  2356. if (intel_framebuffer_init(to_intel_framebuffer(fb), obj, &mode_cmd)) {
  2357. DRM_DEBUG_KMS("intel fb init failed\n");
  2358. goto out_unref_obj;
  2359. }
  2360. DRM_DEBUG_KMS("initial plane fb obj %p\n", obj);
  2361. return true;
  2362. out_unref_obj:
  2363. i915_gem_object_put(obj);
  2364. return false;
  2365. }
  2366. static void
  2367. intel_set_plane_visible(struct intel_crtc_state *crtc_state,
  2368. struct intel_plane_state *plane_state,
  2369. bool visible)
  2370. {
  2371. struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
  2372. plane_state->base.visible = visible;
  2373. /* FIXME pre-g4x don't work like this */
  2374. if (visible) {
  2375. crtc_state->base.plane_mask |= BIT(drm_plane_index(&plane->base));
  2376. crtc_state->active_planes |= BIT(plane->id);
  2377. } else {
  2378. crtc_state->base.plane_mask &= ~BIT(drm_plane_index(&plane->base));
  2379. crtc_state->active_planes &= ~BIT(plane->id);
  2380. }
  2381. DRM_DEBUG_KMS("%s active planes 0x%x\n",
  2382. crtc_state->base.crtc->name,
  2383. crtc_state->active_planes);
  2384. }
  2385. static void intel_plane_disable_noatomic(struct intel_crtc *crtc,
  2386. struct intel_plane *plane)
  2387. {
  2388. struct intel_crtc_state *crtc_state =
  2389. to_intel_crtc_state(crtc->base.state);
  2390. struct intel_plane_state *plane_state =
  2391. to_intel_plane_state(plane->base.state);
  2392. intel_set_plane_visible(crtc_state, plane_state, false);
  2393. if (plane->id == PLANE_PRIMARY)
  2394. intel_pre_disable_primary_noatomic(&crtc->base);
  2395. trace_intel_disable_plane(&plane->base, crtc);
  2396. plane->disable_plane(plane, crtc);
  2397. }
  2398. static void
  2399. intel_find_initial_plane_obj(struct intel_crtc *intel_crtc,
  2400. struct intel_initial_plane_config *plane_config)
  2401. {
  2402. struct drm_device *dev = intel_crtc->base.dev;
  2403. struct drm_i915_private *dev_priv = to_i915(dev);
  2404. struct drm_crtc *c;
  2405. struct drm_i915_gem_object *obj;
  2406. struct drm_plane *primary = intel_crtc->base.primary;
  2407. struct drm_plane_state *plane_state = primary->state;
  2408. struct drm_crtc_state *crtc_state = intel_crtc->base.state;
  2409. struct intel_plane *intel_plane = to_intel_plane(primary);
  2410. struct intel_plane_state *intel_state =
  2411. to_intel_plane_state(plane_state);
  2412. struct drm_framebuffer *fb;
  2413. if (!plane_config->fb)
  2414. return;
  2415. if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) {
  2416. fb = &plane_config->fb->base;
  2417. goto valid_fb;
  2418. }
  2419. kfree(plane_config->fb);
  2420. /*
  2421. * Failed to alloc the obj, check to see if we should share
  2422. * an fb with another CRTC instead
  2423. */
  2424. for_each_crtc(dev, c) {
  2425. struct intel_plane_state *state;
  2426. if (c == &intel_crtc->base)
  2427. continue;
  2428. if (!to_intel_crtc(c)->active)
  2429. continue;
  2430. state = to_intel_plane_state(c->primary->state);
  2431. if (!state->vma)
  2432. continue;
  2433. if (intel_plane_ggtt_offset(state) == plane_config->base) {
  2434. fb = c->primary->fb;
  2435. drm_framebuffer_get(fb);
  2436. goto valid_fb;
  2437. }
  2438. }
  2439. /*
  2440. * We've failed to reconstruct the BIOS FB. Current display state
  2441. * indicates that the primary plane is visible, but has a NULL FB,
  2442. * which will lead to problems later if we don't fix it up. The
  2443. * simplest solution is to just disable the primary plane now and
  2444. * pretend the BIOS never had it enabled.
  2445. */
  2446. intel_plane_disable_noatomic(intel_crtc, intel_plane);
  2447. return;
  2448. valid_fb:
  2449. mutex_lock(&dev->struct_mutex);
  2450. intel_state->vma =
  2451. intel_pin_and_fence_fb_obj(fb,
  2452. primary->state->rotation,
  2453. intel_plane_uses_fence(intel_state),
  2454. &intel_state->flags);
  2455. mutex_unlock(&dev->struct_mutex);
  2456. if (IS_ERR(intel_state->vma)) {
  2457. DRM_ERROR("failed to pin boot fb on pipe %d: %li\n",
  2458. intel_crtc->pipe, PTR_ERR(intel_state->vma));
  2459. intel_state->vma = NULL;
  2460. drm_framebuffer_put(fb);
  2461. return;
  2462. }
  2463. obj = intel_fb_obj(fb);
  2464. intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
  2465. plane_state->src_x = 0;
  2466. plane_state->src_y = 0;
  2467. plane_state->src_w = fb->width << 16;
  2468. plane_state->src_h = fb->height << 16;
  2469. plane_state->crtc_x = 0;
  2470. plane_state->crtc_y = 0;
  2471. plane_state->crtc_w = fb->width;
  2472. plane_state->crtc_h = fb->height;
  2473. intel_state->base.src = drm_plane_state_src(plane_state);
  2474. intel_state->base.dst = drm_plane_state_dest(plane_state);
  2475. if (i915_gem_object_is_tiled(obj))
  2476. dev_priv->preserve_bios_swizzle = true;
  2477. drm_framebuffer_get(fb);
  2478. primary->fb = primary->state->fb = fb;
  2479. primary->crtc = primary->state->crtc = &intel_crtc->base;
  2480. intel_set_plane_visible(to_intel_crtc_state(crtc_state),
  2481. to_intel_plane_state(plane_state),
  2482. true);
  2483. atomic_or(to_intel_plane(primary)->frontbuffer_bit,
  2484. &obj->frontbuffer_bits);
  2485. }
  2486. static int skl_max_plane_width(const struct drm_framebuffer *fb, int plane,
  2487. unsigned int rotation)
  2488. {
  2489. int cpp = fb->format->cpp[plane];
  2490. switch (fb->modifier) {
  2491. case DRM_FORMAT_MOD_LINEAR:
  2492. case I915_FORMAT_MOD_X_TILED:
  2493. switch (cpp) {
  2494. case 8:
  2495. return 4096;
  2496. case 4:
  2497. case 2:
  2498. case 1:
  2499. return 8192;
  2500. default:
  2501. MISSING_CASE(cpp);
  2502. break;
  2503. }
  2504. break;
  2505. case I915_FORMAT_MOD_Y_TILED_CCS:
  2506. case I915_FORMAT_MOD_Yf_TILED_CCS:
  2507. /* FIXME AUX plane? */
  2508. case I915_FORMAT_MOD_Y_TILED:
  2509. case I915_FORMAT_MOD_Yf_TILED:
  2510. switch (cpp) {
  2511. case 8:
  2512. return 2048;
  2513. case 4:
  2514. return 4096;
  2515. case 2:
  2516. case 1:
  2517. return 8192;
  2518. default:
  2519. MISSING_CASE(cpp);
  2520. break;
  2521. }
  2522. break;
  2523. default:
  2524. MISSING_CASE(fb->modifier);
  2525. }
  2526. return 2048;
  2527. }
  2528. static bool skl_check_main_ccs_coordinates(struct intel_plane_state *plane_state,
  2529. int main_x, int main_y, u32 main_offset)
  2530. {
  2531. const struct drm_framebuffer *fb = plane_state->base.fb;
  2532. int hsub = fb->format->hsub;
  2533. int vsub = fb->format->vsub;
  2534. int aux_x = plane_state->aux.x;
  2535. int aux_y = plane_state->aux.y;
  2536. u32 aux_offset = plane_state->aux.offset;
  2537. u32 alignment = intel_surf_alignment(fb, 1);
  2538. while (aux_offset >= main_offset && aux_y <= main_y) {
  2539. int x, y;
  2540. if (aux_x == main_x && aux_y == main_y)
  2541. break;
  2542. if (aux_offset == 0)
  2543. break;
  2544. x = aux_x / hsub;
  2545. y = aux_y / vsub;
  2546. aux_offset = intel_adjust_tile_offset(&x, &y, plane_state, 1,
  2547. aux_offset, aux_offset - alignment);
  2548. aux_x = x * hsub + aux_x % hsub;
  2549. aux_y = y * vsub + aux_y % vsub;
  2550. }
  2551. if (aux_x != main_x || aux_y != main_y)
  2552. return false;
  2553. plane_state->aux.offset = aux_offset;
  2554. plane_state->aux.x = aux_x;
  2555. plane_state->aux.y = aux_y;
  2556. return true;
  2557. }
  2558. static int skl_check_main_surface(const struct intel_crtc_state *crtc_state,
  2559. struct intel_plane_state *plane_state)
  2560. {
  2561. struct drm_i915_private *dev_priv =
  2562. to_i915(plane_state->base.plane->dev);
  2563. const struct drm_framebuffer *fb = plane_state->base.fb;
  2564. unsigned int rotation = plane_state->base.rotation;
  2565. int x = plane_state->base.src.x1 >> 16;
  2566. int y = plane_state->base.src.y1 >> 16;
  2567. int w = drm_rect_width(&plane_state->base.src) >> 16;
  2568. int h = drm_rect_height(&plane_state->base.src) >> 16;
  2569. int dst_x = plane_state->base.dst.x1;
  2570. int pipe_src_w = crtc_state->pipe_src_w;
  2571. int max_width = skl_max_plane_width(fb, 0, rotation);
  2572. int max_height = 4096;
  2573. u32 alignment, offset, aux_offset = plane_state->aux.offset;
  2574. if (w > max_width || h > max_height) {
  2575. DRM_DEBUG_KMS("requested Y/RGB source size %dx%d too big (limit %dx%d)\n",
  2576. w, h, max_width, max_height);
  2577. return -EINVAL;
  2578. }
  2579. /*
  2580. * Display WA #1175: cnl,glk
  2581. * Planes other than the cursor may cause FIFO underflow and display
  2582. * corruption if starting less than 4 pixels from the right edge of
  2583. * the screen.
  2584. * Besides the above WA fix the similar problem, where planes other
  2585. * than the cursor ending less than 4 pixels from the left edge of the
  2586. * screen may cause FIFO underflow and display corruption.
  2587. */
  2588. if ((IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) &&
  2589. (dst_x + w < 4 || dst_x > pipe_src_w - 4)) {
  2590. DRM_DEBUG_KMS("requested plane X %s position %d invalid (valid range %d-%d)\n",
  2591. dst_x + w < 4 ? "end" : "start",
  2592. dst_x + w < 4 ? dst_x + w : dst_x,
  2593. 4, pipe_src_w - 4);
  2594. return -ERANGE;
  2595. }
  2596. intel_add_fb_offsets(&x, &y, plane_state, 0);
  2597. offset = intel_compute_tile_offset(&x, &y, plane_state, 0);
  2598. alignment = intel_surf_alignment(fb, 0);
  2599. /*
  2600. * AUX surface offset is specified as the distance from the
  2601. * main surface offset, and it must be non-negative. Make
  2602. * sure that is what we will get.
  2603. */
  2604. if (offset > aux_offset)
  2605. offset = intel_adjust_tile_offset(&x, &y, plane_state, 0,
  2606. offset, aux_offset & ~(alignment - 1));
  2607. /*
  2608. * When using an X-tiled surface, the plane blows up
  2609. * if the x offset + width exceed the stride.
  2610. *
  2611. * TODO: linear and Y-tiled seem fine, Yf untested,
  2612. */
  2613. if (fb->modifier == I915_FORMAT_MOD_X_TILED) {
  2614. int cpp = fb->format->cpp[0];
  2615. while ((x + w) * cpp > fb->pitches[0]) {
  2616. if (offset == 0) {
  2617. DRM_DEBUG_KMS("Unable to find suitable display surface offset due to X-tiling\n");
  2618. return -EINVAL;
  2619. }
  2620. offset = intel_adjust_tile_offset(&x, &y, plane_state, 0,
  2621. offset, offset - alignment);
  2622. }
  2623. }
  2624. /*
  2625. * CCS AUX surface doesn't have its own x/y offsets, we must make sure
  2626. * they match with the main surface x/y offsets.
  2627. */
  2628. if (fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
  2629. fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS) {
  2630. while (!skl_check_main_ccs_coordinates(plane_state, x, y, offset)) {
  2631. if (offset == 0)
  2632. break;
  2633. offset = intel_adjust_tile_offset(&x, &y, plane_state, 0,
  2634. offset, offset - alignment);
  2635. }
  2636. if (x != plane_state->aux.x || y != plane_state->aux.y) {
  2637. DRM_DEBUG_KMS("Unable to find suitable display surface offset due to CCS\n");
  2638. return -EINVAL;
  2639. }
  2640. }
  2641. plane_state->main.offset = offset;
  2642. plane_state->main.x = x;
  2643. plane_state->main.y = y;
  2644. return 0;
  2645. }
  2646. static int skl_check_nv12_aux_surface(struct intel_plane_state *plane_state)
  2647. {
  2648. const struct drm_framebuffer *fb = plane_state->base.fb;
  2649. unsigned int rotation = plane_state->base.rotation;
  2650. int max_width = skl_max_plane_width(fb, 1, rotation);
  2651. int max_height = 4096;
  2652. int x = plane_state->base.src.x1 >> 17;
  2653. int y = plane_state->base.src.y1 >> 17;
  2654. int w = drm_rect_width(&plane_state->base.src) >> 17;
  2655. int h = drm_rect_height(&plane_state->base.src) >> 17;
  2656. u32 offset;
  2657. intel_add_fb_offsets(&x, &y, plane_state, 1);
  2658. offset = intel_compute_tile_offset(&x, &y, plane_state, 1);
  2659. /* FIXME not quite sure how/if these apply to the chroma plane */
  2660. if (w > max_width || h > max_height) {
  2661. DRM_DEBUG_KMS("CbCr source size %dx%d too big (limit %dx%d)\n",
  2662. w, h, max_width, max_height);
  2663. return -EINVAL;
  2664. }
  2665. plane_state->aux.offset = offset;
  2666. plane_state->aux.x = x;
  2667. plane_state->aux.y = y;
  2668. return 0;
  2669. }
  2670. static int skl_check_ccs_aux_surface(struct intel_plane_state *plane_state)
  2671. {
  2672. const struct drm_framebuffer *fb = plane_state->base.fb;
  2673. int src_x = plane_state->base.src.x1 >> 16;
  2674. int src_y = plane_state->base.src.y1 >> 16;
  2675. int hsub = fb->format->hsub;
  2676. int vsub = fb->format->vsub;
  2677. int x = src_x / hsub;
  2678. int y = src_y / vsub;
  2679. u32 offset;
  2680. if (plane_state->base.rotation & ~(DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180)) {
  2681. DRM_DEBUG_KMS("RC support only with 0/180 degree rotation %x\n",
  2682. plane_state->base.rotation);
  2683. return -EINVAL;
  2684. }
  2685. intel_add_fb_offsets(&x, &y, plane_state, 1);
  2686. offset = intel_compute_tile_offset(&x, &y, plane_state, 1);
  2687. plane_state->aux.offset = offset;
  2688. plane_state->aux.x = x * hsub + src_x % hsub;
  2689. plane_state->aux.y = y * vsub + src_y % vsub;
  2690. return 0;
  2691. }
  2692. int skl_check_plane_surface(const struct intel_crtc_state *crtc_state,
  2693. struct intel_plane_state *plane_state)
  2694. {
  2695. const struct drm_framebuffer *fb = plane_state->base.fb;
  2696. unsigned int rotation = plane_state->base.rotation;
  2697. int ret;
  2698. if (rotation & DRM_MODE_REFLECT_X &&
  2699. fb->modifier == DRM_FORMAT_MOD_LINEAR) {
  2700. DRM_DEBUG_KMS("horizontal flip is not supported with linear surface formats\n");
  2701. return -EINVAL;
  2702. }
  2703. if (!plane_state->base.visible)
  2704. return 0;
  2705. /* Rotate src coordinates to match rotated GTT view */
  2706. if (drm_rotation_90_or_270(rotation))
  2707. drm_rect_rotate(&plane_state->base.src,
  2708. fb->width << 16, fb->height << 16,
  2709. DRM_MODE_ROTATE_270);
  2710. /*
  2711. * Handle the AUX surface first since
  2712. * the main surface setup depends on it.
  2713. */
  2714. if (fb->format->format == DRM_FORMAT_NV12) {
  2715. ret = skl_check_nv12_aux_surface(plane_state);
  2716. if (ret)
  2717. return ret;
  2718. } else if (fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
  2719. fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS) {
  2720. ret = skl_check_ccs_aux_surface(plane_state);
  2721. if (ret)
  2722. return ret;
  2723. } else {
  2724. plane_state->aux.offset = ~0xfff;
  2725. plane_state->aux.x = 0;
  2726. plane_state->aux.y = 0;
  2727. }
  2728. ret = skl_check_main_surface(crtc_state, plane_state);
  2729. if (ret)
  2730. return ret;
  2731. return 0;
  2732. }
  2733. static u32 i9xx_plane_ctl(const struct intel_crtc_state *crtc_state,
  2734. const struct intel_plane_state *plane_state)
  2735. {
  2736. struct drm_i915_private *dev_priv =
  2737. to_i915(plane_state->base.plane->dev);
  2738. struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
  2739. const struct drm_framebuffer *fb = plane_state->base.fb;
  2740. unsigned int rotation = plane_state->base.rotation;
  2741. u32 dspcntr;
  2742. dspcntr = DISPLAY_PLANE_ENABLE | DISPPLANE_GAMMA_ENABLE;
  2743. if (IS_G4X(dev_priv) || IS_GEN5(dev_priv) ||
  2744. IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv))
  2745. dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
  2746. if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
  2747. dspcntr |= DISPPLANE_PIPE_CSC_ENABLE;
  2748. if (INTEL_GEN(dev_priv) < 5)
  2749. dspcntr |= DISPPLANE_SEL_PIPE(crtc->pipe);
  2750. switch (fb->format->format) {
  2751. case DRM_FORMAT_C8:
  2752. dspcntr |= DISPPLANE_8BPP;
  2753. break;
  2754. case DRM_FORMAT_XRGB1555:
  2755. dspcntr |= DISPPLANE_BGRX555;
  2756. break;
  2757. case DRM_FORMAT_RGB565:
  2758. dspcntr |= DISPPLANE_BGRX565;
  2759. break;
  2760. case DRM_FORMAT_XRGB8888:
  2761. dspcntr |= DISPPLANE_BGRX888;
  2762. break;
  2763. case DRM_FORMAT_XBGR8888:
  2764. dspcntr |= DISPPLANE_RGBX888;
  2765. break;
  2766. case DRM_FORMAT_XRGB2101010:
  2767. dspcntr |= DISPPLANE_BGRX101010;
  2768. break;
  2769. case DRM_FORMAT_XBGR2101010:
  2770. dspcntr |= DISPPLANE_RGBX101010;
  2771. break;
  2772. default:
  2773. MISSING_CASE(fb->format->format);
  2774. return 0;
  2775. }
  2776. if (INTEL_GEN(dev_priv) >= 4 &&
  2777. fb->modifier == I915_FORMAT_MOD_X_TILED)
  2778. dspcntr |= DISPPLANE_TILED;
  2779. if (rotation & DRM_MODE_ROTATE_180)
  2780. dspcntr |= DISPPLANE_ROTATE_180;
  2781. if (rotation & DRM_MODE_REFLECT_X)
  2782. dspcntr |= DISPPLANE_MIRROR;
  2783. return dspcntr;
  2784. }
  2785. int i9xx_check_plane_surface(struct intel_plane_state *plane_state)
  2786. {
  2787. struct drm_i915_private *dev_priv =
  2788. to_i915(plane_state->base.plane->dev);
  2789. int src_x = plane_state->base.src.x1 >> 16;
  2790. int src_y = plane_state->base.src.y1 >> 16;
  2791. u32 offset;
  2792. intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
  2793. if (INTEL_GEN(dev_priv) >= 4)
  2794. offset = intel_compute_tile_offset(&src_x, &src_y,
  2795. plane_state, 0);
  2796. else
  2797. offset = 0;
  2798. /* HSW/BDW do this automagically in hardware */
  2799. if (!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv)) {
  2800. unsigned int rotation = plane_state->base.rotation;
  2801. int src_w = drm_rect_width(&plane_state->base.src) >> 16;
  2802. int src_h = drm_rect_height(&plane_state->base.src) >> 16;
  2803. if (rotation & DRM_MODE_ROTATE_180) {
  2804. src_x += src_w - 1;
  2805. src_y += src_h - 1;
  2806. } else if (rotation & DRM_MODE_REFLECT_X) {
  2807. src_x += src_w - 1;
  2808. }
  2809. }
  2810. plane_state->main.offset = offset;
  2811. plane_state->main.x = src_x;
  2812. plane_state->main.y = src_y;
  2813. return 0;
  2814. }
  2815. static void i9xx_update_plane(struct intel_plane *plane,
  2816. const struct intel_crtc_state *crtc_state,
  2817. const struct intel_plane_state *plane_state)
  2818. {
  2819. struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
  2820. const struct drm_framebuffer *fb = plane_state->base.fb;
  2821. enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
  2822. u32 linear_offset;
  2823. u32 dspcntr = plane_state->ctl;
  2824. i915_reg_t reg = DSPCNTR(i9xx_plane);
  2825. int x = plane_state->main.x;
  2826. int y = plane_state->main.y;
  2827. unsigned long irqflags;
  2828. u32 dspaddr_offset;
  2829. linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
  2830. if (INTEL_GEN(dev_priv) >= 4)
  2831. dspaddr_offset = plane_state->main.offset;
  2832. else
  2833. dspaddr_offset = linear_offset;
  2834. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  2835. if (INTEL_GEN(dev_priv) < 4) {
  2836. /* pipesrc and dspsize control the size that is scaled from,
  2837. * which should always be the user's requested size.
  2838. */
  2839. I915_WRITE_FW(DSPSIZE(i9xx_plane),
  2840. ((crtc_state->pipe_src_h - 1) << 16) |
  2841. (crtc_state->pipe_src_w - 1));
  2842. I915_WRITE_FW(DSPPOS(i9xx_plane), 0);
  2843. } else if (IS_CHERRYVIEW(dev_priv) && i9xx_plane == PLANE_B) {
  2844. I915_WRITE_FW(PRIMSIZE(i9xx_plane),
  2845. ((crtc_state->pipe_src_h - 1) << 16) |
  2846. (crtc_state->pipe_src_w - 1));
  2847. I915_WRITE_FW(PRIMPOS(i9xx_plane), 0);
  2848. I915_WRITE_FW(PRIMCNSTALPHA(i9xx_plane), 0);
  2849. }
  2850. I915_WRITE_FW(reg, dspcntr);
  2851. I915_WRITE_FW(DSPSTRIDE(i9xx_plane), fb->pitches[0]);
  2852. if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
  2853. I915_WRITE_FW(DSPSURF(i9xx_plane),
  2854. intel_plane_ggtt_offset(plane_state) +
  2855. dspaddr_offset);
  2856. I915_WRITE_FW(DSPOFFSET(i9xx_plane), (y << 16) | x);
  2857. } else if (INTEL_GEN(dev_priv) >= 4) {
  2858. I915_WRITE_FW(DSPSURF(i9xx_plane),
  2859. intel_plane_ggtt_offset(plane_state) +
  2860. dspaddr_offset);
  2861. I915_WRITE_FW(DSPTILEOFF(i9xx_plane), (y << 16) | x);
  2862. I915_WRITE_FW(DSPLINOFF(i9xx_plane), linear_offset);
  2863. } else {
  2864. I915_WRITE_FW(DSPADDR(i9xx_plane),
  2865. intel_plane_ggtt_offset(plane_state) +
  2866. dspaddr_offset);
  2867. }
  2868. POSTING_READ_FW(reg);
  2869. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  2870. }
  2871. static void i9xx_disable_plane(struct intel_plane *plane,
  2872. struct intel_crtc *crtc)
  2873. {
  2874. struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
  2875. enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
  2876. unsigned long irqflags;
  2877. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  2878. I915_WRITE_FW(DSPCNTR(i9xx_plane), 0);
  2879. if (INTEL_GEN(dev_priv) >= 4)
  2880. I915_WRITE_FW(DSPSURF(i9xx_plane), 0);
  2881. else
  2882. I915_WRITE_FW(DSPADDR(i9xx_plane), 0);
  2883. POSTING_READ_FW(DSPCNTR(i9xx_plane));
  2884. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  2885. }
  2886. static bool i9xx_plane_get_hw_state(struct intel_plane *plane)
  2887. {
  2888. struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
  2889. enum intel_display_power_domain power_domain;
  2890. enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
  2891. enum pipe pipe = plane->pipe;
  2892. bool ret;
  2893. /*
  2894. * Not 100% correct for planes that can move between pipes,
  2895. * but that's only the case for gen2-4 which don't have any
  2896. * display power wells.
  2897. */
  2898. power_domain = POWER_DOMAIN_PIPE(pipe);
  2899. if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
  2900. return false;
  2901. ret = I915_READ(DSPCNTR(i9xx_plane)) & DISPLAY_PLANE_ENABLE;
  2902. intel_display_power_put(dev_priv, power_domain);
  2903. return ret;
  2904. }
  2905. static u32
  2906. intel_fb_stride_alignment(const struct drm_framebuffer *fb, int plane)
  2907. {
  2908. if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
  2909. return 64;
  2910. else
  2911. return intel_tile_width_bytes(fb, plane);
  2912. }
  2913. static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id)
  2914. {
  2915. struct drm_device *dev = intel_crtc->base.dev;
  2916. struct drm_i915_private *dev_priv = to_i915(dev);
  2917. I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0);
  2918. I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0);
  2919. I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0);
  2920. }
  2921. /*
  2922. * This function detaches (aka. unbinds) unused scalers in hardware
  2923. */
  2924. static void skl_detach_scalers(struct intel_crtc *intel_crtc)
  2925. {
  2926. struct intel_crtc_scaler_state *scaler_state;
  2927. int i;
  2928. scaler_state = &intel_crtc->config->scaler_state;
  2929. /* loop through and disable scalers that aren't in use */
  2930. for (i = 0; i < intel_crtc->num_scalers; i++) {
  2931. if (!scaler_state->scalers[i].in_use)
  2932. skl_detach_scaler(intel_crtc, i);
  2933. }
  2934. }
  2935. u32 skl_plane_stride(const struct drm_framebuffer *fb, int plane,
  2936. unsigned int rotation)
  2937. {
  2938. u32 stride;
  2939. if (plane >= fb->format->num_planes)
  2940. return 0;
  2941. stride = intel_fb_pitch(fb, plane, rotation);
  2942. /*
  2943. * The stride is either expressed as a multiple of 64 bytes chunks for
  2944. * linear buffers or in number of tiles for tiled buffers.
  2945. */
  2946. if (drm_rotation_90_or_270(rotation))
  2947. stride /= intel_tile_height(fb, plane);
  2948. else
  2949. stride /= intel_fb_stride_alignment(fb, plane);
  2950. return stride;
  2951. }
  2952. static u32 skl_plane_ctl_format(uint32_t pixel_format)
  2953. {
  2954. switch (pixel_format) {
  2955. case DRM_FORMAT_C8:
  2956. return PLANE_CTL_FORMAT_INDEXED;
  2957. case DRM_FORMAT_RGB565:
  2958. return PLANE_CTL_FORMAT_RGB_565;
  2959. case DRM_FORMAT_XBGR8888:
  2960. case DRM_FORMAT_ABGR8888:
  2961. return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX;
  2962. case DRM_FORMAT_XRGB8888:
  2963. case DRM_FORMAT_ARGB8888:
  2964. return PLANE_CTL_FORMAT_XRGB_8888;
  2965. case DRM_FORMAT_XRGB2101010:
  2966. return PLANE_CTL_FORMAT_XRGB_2101010;
  2967. case DRM_FORMAT_XBGR2101010:
  2968. return PLANE_CTL_ORDER_RGBX | PLANE_CTL_FORMAT_XRGB_2101010;
  2969. case DRM_FORMAT_YUYV:
  2970. return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV;
  2971. case DRM_FORMAT_YVYU:
  2972. return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU;
  2973. case DRM_FORMAT_UYVY:
  2974. return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY;
  2975. case DRM_FORMAT_VYUY:
  2976. return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY;
  2977. case DRM_FORMAT_NV12:
  2978. return PLANE_CTL_FORMAT_NV12;
  2979. default:
  2980. MISSING_CASE(pixel_format);
  2981. }
  2982. return 0;
  2983. }
  2984. /*
  2985. * XXX: For ARBG/ABGR formats we default to expecting scanout buffers
  2986. * to be already pre-multiplied. We need to add a knob (or a different
  2987. * DRM_FORMAT) for user-space to configure that.
  2988. */
  2989. static u32 skl_plane_ctl_alpha(uint32_t pixel_format)
  2990. {
  2991. switch (pixel_format) {
  2992. case DRM_FORMAT_ABGR8888:
  2993. case DRM_FORMAT_ARGB8888:
  2994. return PLANE_CTL_ALPHA_SW_PREMULTIPLY;
  2995. default:
  2996. return PLANE_CTL_ALPHA_DISABLE;
  2997. }
  2998. }
  2999. static u32 glk_plane_color_ctl_alpha(uint32_t pixel_format)
  3000. {
  3001. switch (pixel_format) {
  3002. case DRM_FORMAT_ABGR8888:
  3003. case DRM_FORMAT_ARGB8888:
  3004. return PLANE_COLOR_ALPHA_SW_PREMULTIPLY;
  3005. default:
  3006. return PLANE_COLOR_ALPHA_DISABLE;
  3007. }
  3008. }
  3009. static u32 skl_plane_ctl_tiling(uint64_t fb_modifier)
  3010. {
  3011. switch (fb_modifier) {
  3012. case DRM_FORMAT_MOD_LINEAR:
  3013. break;
  3014. case I915_FORMAT_MOD_X_TILED:
  3015. return PLANE_CTL_TILED_X;
  3016. case I915_FORMAT_MOD_Y_TILED:
  3017. return PLANE_CTL_TILED_Y;
  3018. case I915_FORMAT_MOD_Y_TILED_CCS:
  3019. return PLANE_CTL_TILED_Y | PLANE_CTL_DECOMPRESSION_ENABLE;
  3020. case I915_FORMAT_MOD_Yf_TILED:
  3021. return PLANE_CTL_TILED_YF;
  3022. case I915_FORMAT_MOD_Yf_TILED_CCS:
  3023. return PLANE_CTL_TILED_YF | PLANE_CTL_DECOMPRESSION_ENABLE;
  3024. default:
  3025. MISSING_CASE(fb_modifier);
  3026. }
  3027. return 0;
  3028. }
  3029. static u32 skl_plane_ctl_rotate(unsigned int rotate)
  3030. {
  3031. switch (rotate) {
  3032. case DRM_MODE_ROTATE_0:
  3033. break;
  3034. /*
  3035. * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
  3036. * while i915 HW rotation is clockwise, thats why this swapping.
  3037. */
  3038. case DRM_MODE_ROTATE_90:
  3039. return PLANE_CTL_ROTATE_270;
  3040. case DRM_MODE_ROTATE_180:
  3041. return PLANE_CTL_ROTATE_180;
  3042. case DRM_MODE_ROTATE_270:
  3043. return PLANE_CTL_ROTATE_90;
  3044. default:
  3045. MISSING_CASE(rotate);
  3046. }
  3047. return 0;
  3048. }
  3049. static u32 cnl_plane_ctl_flip(unsigned int reflect)
  3050. {
  3051. switch (reflect) {
  3052. case 0:
  3053. break;
  3054. case DRM_MODE_REFLECT_X:
  3055. return PLANE_CTL_FLIP_HORIZONTAL;
  3056. case DRM_MODE_REFLECT_Y:
  3057. default:
  3058. MISSING_CASE(reflect);
  3059. }
  3060. return 0;
  3061. }
  3062. u32 skl_plane_ctl(const struct intel_crtc_state *crtc_state,
  3063. const struct intel_plane_state *plane_state)
  3064. {
  3065. struct drm_i915_private *dev_priv =
  3066. to_i915(plane_state->base.plane->dev);
  3067. const struct drm_framebuffer *fb = plane_state->base.fb;
  3068. unsigned int rotation = plane_state->base.rotation;
  3069. const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
  3070. u32 plane_ctl;
  3071. plane_ctl = PLANE_CTL_ENABLE;
  3072. if (INTEL_GEN(dev_priv) < 10 && !IS_GEMINILAKE(dev_priv)) {
  3073. plane_ctl |= skl_plane_ctl_alpha(fb->format->format);
  3074. plane_ctl |=
  3075. PLANE_CTL_PIPE_GAMMA_ENABLE |
  3076. PLANE_CTL_PIPE_CSC_ENABLE |
  3077. PLANE_CTL_PLANE_GAMMA_DISABLE;
  3078. if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
  3079. plane_ctl |= PLANE_CTL_YUV_TO_RGB_CSC_FORMAT_BT709;
  3080. if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
  3081. plane_ctl |= PLANE_CTL_YUV_RANGE_CORRECTION_DISABLE;
  3082. }
  3083. plane_ctl |= skl_plane_ctl_format(fb->format->format);
  3084. plane_ctl |= skl_plane_ctl_tiling(fb->modifier);
  3085. plane_ctl |= skl_plane_ctl_rotate(rotation & DRM_MODE_ROTATE_MASK);
  3086. if (INTEL_GEN(dev_priv) >= 10)
  3087. plane_ctl |= cnl_plane_ctl_flip(rotation &
  3088. DRM_MODE_REFLECT_MASK);
  3089. if (key->flags & I915_SET_COLORKEY_DESTINATION)
  3090. plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION;
  3091. else if (key->flags & I915_SET_COLORKEY_SOURCE)
  3092. plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE;
  3093. return plane_ctl;
  3094. }
  3095. u32 glk_plane_color_ctl(const struct intel_crtc_state *crtc_state,
  3096. const struct intel_plane_state *plane_state)
  3097. {
  3098. const struct drm_framebuffer *fb = plane_state->base.fb;
  3099. u32 plane_color_ctl = 0;
  3100. plane_color_ctl |= PLANE_COLOR_PIPE_GAMMA_ENABLE;
  3101. plane_color_ctl |= PLANE_COLOR_PIPE_CSC_ENABLE;
  3102. plane_color_ctl |= PLANE_COLOR_PLANE_GAMMA_DISABLE;
  3103. plane_color_ctl |= glk_plane_color_ctl_alpha(fb->format->format);
  3104. if (intel_format_is_yuv(fb->format->format)) {
  3105. if (fb->format->format == DRM_FORMAT_NV12) {
  3106. plane_color_ctl |=
  3107. PLANE_COLOR_CSC_MODE_YUV709_TO_RGB709;
  3108. goto out;
  3109. }
  3110. if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
  3111. plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV709_TO_RGB709;
  3112. else
  3113. plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV601_TO_RGB709;
  3114. if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
  3115. plane_color_ctl |= PLANE_COLOR_YUV_RANGE_CORRECTION_DISABLE;
  3116. }
  3117. out:
  3118. return plane_color_ctl;
  3119. }
  3120. static int
  3121. __intel_display_resume(struct drm_device *dev,
  3122. struct drm_atomic_state *state,
  3123. struct drm_modeset_acquire_ctx *ctx)
  3124. {
  3125. struct drm_crtc_state *crtc_state;
  3126. struct drm_crtc *crtc;
  3127. int i, ret;
  3128. intel_modeset_setup_hw_state(dev, ctx);
  3129. i915_redisable_vga(to_i915(dev));
  3130. if (!state)
  3131. return 0;
  3132. /*
  3133. * We've duplicated the state, pointers to the old state are invalid.
  3134. *
  3135. * Don't attempt to use the old state until we commit the duplicated state.
  3136. */
  3137. for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
  3138. /*
  3139. * Force recalculation even if we restore
  3140. * current state. With fast modeset this may not result
  3141. * in a modeset when the state is compatible.
  3142. */
  3143. crtc_state->mode_changed = true;
  3144. }
  3145. /* ignore any reset values/BIOS leftovers in the WM registers */
  3146. if (!HAS_GMCH_DISPLAY(to_i915(dev)))
  3147. to_intel_atomic_state(state)->skip_intermediate_wm = true;
  3148. ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
  3149. WARN_ON(ret == -EDEADLK);
  3150. return ret;
  3151. }
  3152. static bool gpu_reset_clobbers_display(struct drm_i915_private *dev_priv)
  3153. {
  3154. return intel_has_gpu_reset(dev_priv) &&
  3155. INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv);
  3156. }
  3157. void intel_prepare_reset(struct drm_i915_private *dev_priv)
  3158. {
  3159. struct drm_device *dev = &dev_priv->drm;
  3160. struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
  3161. struct drm_atomic_state *state;
  3162. int ret;
  3163. /* reset doesn't touch the display */
  3164. if (!i915_modparams.force_reset_modeset_test &&
  3165. !gpu_reset_clobbers_display(dev_priv))
  3166. return;
  3167. /* We have a modeset vs reset deadlock, defensively unbreak it. */
  3168. set_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags);
  3169. wake_up_all(&dev_priv->gpu_error.wait_queue);
  3170. if (atomic_read(&dev_priv->gpu_error.pending_fb_pin)) {
  3171. DRM_DEBUG_KMS("Modeset potentially stuck, unbreaking through wedging\n");
  3172. i915_gem_set_wedged(dev_priv);
  3173. }
  3174. /*
  3175. * Need mode_config.mutex so that we don't
  3176. * trample ongoing ->detect() and whatnot.
  3177. */
  3178. mutex_lock(&dev->mode_config.mutex);
  3179. drm_modeset_acquire_init(ctx, 0);
  3180. while (1) {
  3181. ret = drm_modeset_lock_all_ctx(dev, ctx);
  3182. if (ret != -EDEADLK)
  3183. break;
  3184. drm_modeset_backoff(ctx);
  3185. }
  3186. /*
  3187. * Disabling the crtcs gracefully seems nicer. Also the
  3188. * g33 docs say we should at least disable all the planes.
  3189. */
  3190. state = drm_atomic_helper_duplicate_state(dev, ctx);
  3191. if (IS_ERR(state)) {
  3192. ret = PTR_ERR(state);
  3193. DRM_ERROR("Duplicating state failed with %i\n", ret);
  3194. return;
  3195. }
  3196. ret = drm_atomic_helper_disable_all(dev, ctx);
  3197. if (ret) {
  3198. DRM_ERROR("Suspending crtc's failed with %i\n", ret);
  3199. drm_atomic_state_put(state);
  3200. return;
  3201. }
  3202. dev_priv->modeset_restore_state = state;
  3203. state->acquire_ctx = ctx;
  3204. }
  3205. void intel_finish_reset(struct drm_i915_private *dev_priv)
  3206. {
  3207. struct drm_device *dev = &dev_priv->drm;
  3208. struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
  3209. struct drm_atomic_state *state;
  3210. int ret;
  3211. /* reset doesn't touch the display */
  3212. if (!test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags))
  3213. return;
  3214. state = fetch_and_zero(&dev_priv->modeset_restore_state);
  3215. if (!state)
  3216. goto unlock;
  3217. /* reset doesn't touch the display */
  3218. if (!gpu_reset_clobbers_display(dev_priv)) {
  3219. /* for testing only restore the display */
  3220. ret = __intel_display_resume(dev, state, ctx);
  3221. if (ret)
  3222. DRM_ERROR("Restoring old state failed with %i\n", ret);
  3223. } else {
  3224. /*
  3225. * The display has been reset as well,
  3226. * so need a full re-initialization.
  3227. */
  3228. intel_runtime_pm_disable_interrupts(dev_priv);
  3229. intel_runtime_pm_enable_interrupts(dev_priv);
  3230. intel_pps_unlock_regs_wa(dev_priv);
  3231. intel_modeset_init_hw(dev);
  3232. intel_init_clock_gating(dev_priv);
  3233. spin_lock_irq(&dev_priv->irq_lock);
  3234. if (dev_priv->display.hpd_irq_setup)
  3235. dev_priv->display.hpd_irq_setup(dev_priv);
  3236. spin_unlock_irq(&dev_priv->irq_lock);
  3237. ret = __intel_display_resume(dev, state, ctx);
  3238. if (ret)
  3239. DRM_ERROR("Restoring old state failed with %i\n", ret);
  3240. intel_hpd_init(dev_priv);
  3241. }
  3242. drm_atomic_state_put(state);
  3243. unlock:
  3244. drm_modeset_drop_locks(ctx);
  3245. drm_modeset_acquire_fini(ctx);
  3246. mutex_unlock(&dev->mode_config.mutex);
  3247. clear_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags);
  3248. }
  3249. static void intel_update_pipe_config(const struct intel_crtc_state *old_crtc_state,
  3250. const struct intel_crtc_state *new_crtc_state)
  3251. {
  3252. struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
  3253. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  3254. /* drm_atomic_helper_update_legacy_modeset_state might not be called. */
  3255. crtc->base.mode = new_crtc_state->base.mode;
  3256. /*
  3257. * Update pipe size and adjust fitter if needed: the reason for this is
  3258. * that in compute_mode_changes we check the native mode (not the pfit
  3259. * mode) to see if we can flip rather than do a full mode set. In the
  3260. * fastboot case, we'll flip, but if we don't update the pipesrc and
  3261. * pfit state, we'll end up with a big fb scanned out into the wrong
  3262. * sized surface.
  3263. */
  3264. I915_WRITE(PIPESRC(crtc->pipe),
  3265. ((new_crtc_state->pipe_src_w - 1) << 16) |
  3266. (new_crtc_state->pipe_src_h - 1));
  3267. /* on skylake this is done by detaching scalers */
  3268. if (INTEL_GEN(dev_priv) >= 9) {
  3269. skl_detach_scalers(crtc);
  3270. if (new_crtc_state->pch_pfit.enabled)
  3271. skylake_pfit_enable(crtc);
  3272. } else if (HAS_PCH_SPLIT(dev_priv)) {
  3273. if (new_crtc_state->pch_pfit.enabled)
  3274. ironlake_pfit_enable(crtc);
  3275. else if (old_crtc_state->pch_pfit.enabled)
  3276. ironlake_pfit_disable(crtc, true);
  3277. }
  3278. }
  3279. static void intel_fdi_normal_train(struct intel_crtc *crtc)
  3280. {
  3281. struct drm_device *dev = crtc->base.dev;
  3282. struct drm_i915_private *dev_priv = to_i915(dev);
  3283. int pipe = crtc->pipe;
  3284. i915_reg_t reg;
  3285. u32 temp;
  3286. /* enable normal train */
  3287. reg = FDI_TX_CTL(pipe);
  3288. temp = I915_READ(reg);
  3289. if (IS_IVYBRIDGE(dev_priv)) {
  3290. temp &= ~FDI_LINK_TRAIN_NONE_IVB;
  3291. temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
  3292. } else {
  3293. temp &= ~FDI_LINK_TRAIN_NONE;
  3294. temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
  3295. }
  3296. I915_WRITE(reg, temp);
  3297. reg = FDI_RX_CTL(pipe);
  3298. temp = I915_READ(reg);
  3299. if (HAS_PCH_CPT(dev_priv)) {
  3300. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  3301. temp |= FDI_LINK_TRAIN_NORMAL_CPT;
  3302. } else {
  3303. temp &= ~FDI_LINK_TRAIN_NONE;
  3304. temp |= FDI_LINK_TRAIN_NONE;
  3305. }
  3306. I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
  3307. /* wait one idle pattern time */
  3308. POSTING_READ(reg);
  3309. udelay(1000);
  3310. /* IVB wants error correction enabled */
  3311. if (IS_IVYBRIDGE(dev_priv))
  3312. I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
  3313. FDI_FE_ERRC_ENABLE);
  3314. }
  3315. /* The FDI link training functions for ILK/Ibexpeak. */
  3316. static void ironlake_fdi_link_train(struct intel_crtc *crtc,
  3317. const struct intel_crtc_state *crtc_state)
  3318. {
  3319. struct drm_device *dev = crtc->base.dev;
  3320. struct drm_i915_private *dev_priv = to_i915(dev);
  3321. int pipe = crtc->pipe;
  3322. i915_reg_t reg;
  3323. u32 temp, tries;
  3324. /* FDI needs bits from pipe first */
  3325. assert_pipe_enabled(dev_priv, pipe);
  3326. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  3327. for train result */
  3328. reg = FDI_RX_IMR(pipe);
  3329. temp = I915_READ(reg);
  3330. temp &= ~FDI_RX_SYMBOL_LOCK;
  3331. temp &= ~FDI_RX_BIT_LOCK;
  3332. I915_WRITE(reg, temp);
  3333. I915_READ(reg);
  3334. udelay(150);
  3335. /* enable CPU FDI TX and PCH FDI RX */
  3336. reg = FDI_TX_CTL(pipe);
  3337. temp = I915_READ(reg);
  3338. temp &= ~FDI_DP_PORT_WIDTH_MASK;
  3339. temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
  3340. temp &= ~FDI_LINK_TRAIN_NONE;
  3341. temp |= FDI_LINK_TRAIN_PATTERN_1;
  3342. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  3343. reg = FDI_RX_CTL(pipe);
  3344. temp = I915_READ(reg);
  3345. temp &= ~FDI_LINK_TRAIN_NONE;
  3346. temp |= FDI_LINK_TRAIN_PATTERN_1;
  3347. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  3348. POSTING_READ(reg);
  3349. udelay(150);
  3350. /* Ironlake workaround, enable clock pointer after FDI enable*/
  3351. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
  3352. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
  3353. FDI_RX_PHASE_SYNC_POINTER_EN);
  3354. reg = FDI_RX_IIR(pipe);
  3355. for (tries = 0; tries < 5; tries++) {
  3356. temp = I915_READ(reg);
  3357. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  3358. if ((temp & FDI_RX_BIT_LOCK)) {
  3359. DRM_DEBUG_KMS("FDI train 1 done.\n");
  3360. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  3361. break;
  3362. }
  3363. }
  3364. if (tries == 5)
  3365. DRM_ERROR("FDI train 1 fail!\n");
  3366. /* Train 2 */
  3367. reg = FDI_TX_CTL(pipe);
  3368. temp = I915_READ(reg);
  3369. temp &= ~FDI_LINK_TRAIN_NONE;
  3370. temp |= FDI_LINK_TRAIN_PATTERN_2;
  3371. I915_WRITE(reg, temp);
  3372. reg = FDI_RX_CTL(pipe);
  3373. temp = I915_READ(reg);
  3374. temp &= ~FDI_LINK_TRAIN_NONE;
  3375. temp |= FDI_LINK_TRAIN_PATTERN_2;
  3376. I915_WRITE(reg, temp);
  3377. POSTING_READ(reg);
  3378. udelay(150);
  3379. reg = FDI_RX_IIR(pipe);
  3380. for (tries = 0; tries < 5; tries++) {
  3381. temp = I915_READ(reg);
  3382. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  3383. if (temp & FDI_RX_SYMBOL_LOCK) {
  3384. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  3385. DRM_DEBUG_KMS("FDI train 2 done.\n");
  3386. break;
  3387. }
  3388. }
  3389. if (tries == 5)
  3390. DRM_ERROR("FDI train 2 fail!\n");
  3391. DRM_DEBUG_KMS("FDI train done\n");
  3392. }
  3393. static const int snb_b_fdi_train_param[] = {
  3394. FDI_LINK_TRAIN_400MV_0DB_SNB_B,
  3395. FDI_LINK_TRAIN_400MV_6DB_SNB_B,
  3396. FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
  3397. FDI_LINK_TRAIN_800MV_0DB_SNB_B,
  3398. };
  3399. /* The FDI link training functions for SNB/Cougarpoint. */
  3400. static void gen6_fdi_link_train(struct intel_crtc *crtc,
  3401. const struct intel_crtc_state *crtc_state)
  3402. {
  3403. struct drm_device *dev = crtc->base.dev;
  3404. struct drm_i915_private *dev_priv = to_i915(dev);
  3405. int pipe = crtc->pipe;
  3406. i915_reg_t reg;
  3407. u32 temp, i, retry;
  3408. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  3409. for train result */
  3410. reg = FDI_RX_IMR(pipe);
  3411. temp = I915_READ(reg);
  3412. temp &= ~FDI_RX_SYMBOL_LOCK;
  3413. temp &= ~FDI_RX_BIT_LOCK;
  3414. I915_WRITE(reg, temp);
  3415. POSTING_READ(reg);
  3416. udelay(150);
  3417. /* enable CPU FDI TX and PCH FDI RX */
  3418. reg = FDI_TX_CTL(pipe);
  3419. temp = I915_READ(reg);
  3420. temp &= ~FDI_DP_PORT_WIDTH_MASK;
  3421. temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
  3422. temp &= ~FDI_LINK_TRAIN_NONE;
  3423. temp |= FDI_LINK_TRAIN_PATTERN_1;
  3424. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  3425. /* SNB-B */
  3426. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  3427. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  3428. I915_WRITE(FDI_RX_MISC(pipe),
  3429. FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
  3430. reg = FDI_RX_CTL(pipe);
  3431. temp = I915_READ(reg);
  3432. if (HAS_PCH_CPT(dev_priv)) {
  3433. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  3434. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  3435. } else {
  3436. temp &= ~FDI_LINK_TRAIN_NONE;
  3437. temp |= FDI_LINK_TRAIN_PATTERN_1;
  3438. }
  3439. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  3440. POSTING_READ(reg);
  3441. udelay(150);
  3442. for (i = 0; i < 4; i++) {
  3443. reg = FDI_TX_CTL(pipe);
  3444. temp = I915_READ(reg);
  3445. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  3446. temp |= snb_b_fdi_train_param[i];
  3447. I915_WRITE(reg, temp);
  3448. POSTING_READ(reg);
  3449. udelay(500);
  3450. for (retry = 0; retry < 5; retry++) {
  3451. reg = FDI_RX_IIR(pipe);
  3452. temp = I915_READ(reg);
  3453. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  3454. if (temp & FDI_RX_BIT_LOCK) {
  3455. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  3456. DRM_DEBUG_KMS("FDI train 1 done.\n");
  3457. break;
  3458. }
  3459. udelay(50);
  3460. }
  3461. if (retry < 5)
  3462. break;
  3463. }
  3464. if (i == 4)
  3465. DRM_ERROR("FDI train 1 fail!\n");
  3466. /* Train 2 */
  3467. reg = FDI_TX_CTL(pipe);
  3468. temp = I915_READ(reg);
  3469. temp &= ~FDI_LINK_TRAIN_NONE;
  3470. temp |= FDI_LINK_TRAIN_PATTERN_2;
  3471. if (IS_GEN6(dev_priv)) {
  3472. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  3473. /* SNB-B */
  3474. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  3475. }
  3476. I915_WRITE(reg, temp);
  3477. reg = FDI_RX_CTL(pipe);
  3478. temp = I915_READ(reg);
  3479. if (HAS_PCH_CPT(dev_priv)) {
  3480. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  3481. temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
  3482. } else {
  3483. temp &= ~FDI_LINK_TRAIN_NONE;
  3484. temp |= FDI_LINK_TRAIN_PATTERN_2;
  3485. }
  3486. I915_WRITE(reg, temp);
  3487. POSTING_READ(reg);
  3488. udelay(150);
  3489. for (i = 0; i < 4; i++) {
  3490. reg = FDI_TX_CTL(pipe);
  3491. temp = I915_READ(reg);
  3492. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  3493. temp |= snb_b_fdi_train_param[i];
  3494. I915_WRITE(reg, temp);
  3495. POSTING_READ(reg);
  3496. udelay(500);
  3497. for (retry = 0; retry < 5; retry++) {
  3498. reg = FDI_RX_IIR(pipe);
  3499. temp = I915_READ(reg);
  3500. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  3501. if (temp & FDI_RX_SYMBOL_LOCK) {
  3502. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  3503. DRM_DEBUG_KMS("FDI train 2 done.\n");
  3504. break;
  3505. }
  3506. udelay(50);
  3507. }
  3508. if (retry < 5)
  3509. break;
  3510. }
  3511. if (i == 4)
  3512. DRM_ERROR("FDI train 2 fail!\n");
  3513. DRM_DEBUG_KMS("FDI train done.\n");
  3514. }
  3515. /* Manual link training for Ivy Bridge A0 parts */
  3516. static void ivb_manual_fdi_link_train(struct intel_crtc *crtc,
  3517. const struct intel_crtc_state *crtc_state)
  3518. {
  3519. struct drm_device *dev = crtc->base.dev;
  3520. struct drm_i915_private *dev_priv = to_i915(dev);
  3521. int pipe = crtc->pipe;
  3522. i915_reg_t reg;
  3523. u32 temp, i, j;
  3524. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  3525. for train result */
  3526. reg = FDI_RX_IMR(pipe);
  3527. temp = I915_READ(reg);
  3528. temp &= ~FDI_RX_SYMBOL_LOCK;
  3529. temp &= ~FDI_RX_BIT_LOCK;
  3530. I915_WRITE(reg, temp);
  3531. POSTING_READ(reg);
  3532. udelay(150);
  3533. DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
  3534. I915_READ(FDI_RX_IIR(pipe)));
  3535. /* Try each vswing and preemphasis setting twice before moving on */
  3536. for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) {
  3537. /* disable first in case we need to retry */
  3538. reg = FDI_TX_CTL(pipe);
  3539. temp = I915_READ(reg);
  3540. temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
  3541. temp &= ~FDI_TX_ENABLE;
  3542. I915_WRITE(reg, temp);
  3543. reg = FDI_RX_CTL(pipe);
  3544. temp = I915_READ(reg);
  3545. temp &= ~FDI_LINK_TRAIN_AUTO;
  3546. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  3547. temp &= ~FDI_RX_ENABLE;
  3548. I915_WRITE(reg, temp);
  3549. /* enable CPU FDI TX and PCH FDI RX */
  3550. reg = FDI_TX_CTL(pipe);
  3551. temp = I915_READ(reg);
  3552. temp &= ~FDI_DP_PORT_WIDTH_MASK;
  3553. temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
  3554. temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
  3555. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  3556. temp |= snb_b_fdi_train_param[j/2];
  3557. temp |= FDI_COMPOSITE_SYNC;
  3558. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  3559. I915_WRITE(FDI_RX_MISC(pipe),
  3560. FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
  3561. reg = FDI_RX_CTL(pipe);
  3562. temp = I915_READ(reg);
  3563. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  3564. temp |= FDI_COMPOSITE_SYNC;
  3565. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  3566. POSTING_READ(reg);
  3567. udelay(1); /* should be 0.5us */
  3568. for (i = 0; i < 4; i++) {
  3569. reg = FDI_RX_IIR(pipe);
  3570. temp = I915_READ(reg);
  3571. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  3572. if (temp & FDI_RX_BIT_LOCK ||
  3573. (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
  3574. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  3575. DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
  3576. i);
  3577. break;
  3578. }
  3579. udelay(1); /* should be 0.5us */
  3580. }
  3581. if (i == 4) {
  3582. DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2);
  3583. continue;
  3584. }
  3585. /* Train 2 */
  3586. reg = FDI_TX_CTL(pipe);
  3587. temp = I915_READ(reg);
  3588. temp &= ~FDI_LINK_TRAIN_NONE_IVB;
  3589. temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
  3590. I915_WRITE(reg, temp);
  3591. reg = FDI_RX_CTL(pipe);
  3592. temp = I915_READ(reg);
  3593. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  3594. temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
  3595. I915_WRITE(reg, temp);
  3596. POSTING_READ(reg);
  3597. udelay(2); /* should be 1.5us */
  3598. for (i = 0; i < 4; i++) {
  3599. reg = FDI_RX_IIR(pipe);
  3600. temp = I915_READ(reg);
  3601. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  3602. if (temp & FDI_RX_SYMBOL_LOCK ||
  3603. (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) {
  3604. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  3605. DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
  3606. i);
  3607. goto train_done;
  3608. }
  3609. udelay(2); /* should be 1.5us */
  3610. }
  3611. if (i == 4)
  3612. DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2);
  3613. }
  3614. train_done:
  3615. DRM_DEBUG_KMS("FDI train done.\n");
  3616. }
  3617. static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc)
  3618. {
  3619. struct drm_device *dev = intel_crtc->base.dev;
  3620. struct drm_i915_private *dev_priv = to_i915(dev);
  3621. int pipe = intel_crtc->pipe;
  3622. i915_reg_t reg;
  3623. u32 temp;
  3624. /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
  3625. reg = FDI_RX_CTL(pipe);
  3626. temp = I915_READ(reg);
  3627. temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16));
  3628. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes);
  3629. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  3630. I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
  3631. POSTING_READ(reg);
  3632. udelay(200);
  3633. /* Switch from Rawclk to PCDclk */
  3634. temp = I915_READ(reg);
  3635. I915_WRITE(reg, temp | FDI_PCDCLK);
  3636. POSTING_READ(reg);
  3637. udelay(200);
  3638. /* Enable CPU FDI TX PLL, always on for Ironlake */
  3639. reg = FDI_TX_CTL(pipe);
  3640. temp = I915_READ(reg);
  3641. if ((temp & FDI_TX_PLL_ENABLE) == 0) {
  3642. I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
  3643. POSTING_READ(reg);
  3644. udelay(100);
  3645. }
  3646. }
  3647. static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
  3648. {
  3649. struct drm_device *dev = intel_crtc->base.dev;
  3650. struct drm_i915_private *dev_priv = to_i915(dev);
  3651. int pipe = intel_crtc->pipe;
  3652. i915_reg_t reg;
  3653. u32 temp;
  3654. /* Switch from PCDclk to Rawclk */
  3655. reg = FDI_RX_CTL(pipe);
  3656. temp = I915_READ(reg);
  3657. I915_WRITE(reg, temp & ~FDI_PCDCLK);
  3658. /* Disable CPU FDI TX PLL */
  3659. reg = FDI_TX_CTL(pipe);
  3660. temp = I915_READ(reg);
  3661. I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
  3662. POSTING_READ(reg);
  3663. udelay(100);
  3664. reg = FDI_RX_CTL(pipe);
  3665. temp = I915_READ(reg);
  3666. I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
  3667. /* Wait for the clocks to turn off. */
  3668. POSTING_READ(reg);
  3669. udelay(100);
  3670. }
  3671. static void ironlake_fdi_disable(struct drm_crtc *crtc)
  3672. {
  3673. struct drm_device *dev = crtc->dev;
  3674. struct drm_i915_private *dev_priv = to_i915(dev);
  3675. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3676. int pipe = intel_crtc->pipe;
  3677. i915_reg_t reg;
  3678. u32 temp;
  3679. /* disable CPU FDI tx and PCH FDI rx */
  3680. reg = FDI_TX_CTL(pipe);
  3681. temp = I915_READ(reg);
  3682. I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
  3683. POSTING_READ(reg);
  3684. reg = FDI_RX_CTL(pipe);
  3685. temp = I915_READ(reg);
  3686. temp &= ~(0x7 << 16);
  3687. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  3688. I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
  3689. POSTING_READ(reg);
  3690. udelay(100);
  3691. /* Ironlake workaround, disable clock pointer after downing FDI */
  3692. if (HAS_PCH_IBX(dev_priv))
  3693. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
  3694. /* still set train pattern 1 */
  3695. reg = FDI_TX_CTL(pipe);
  3696. temp = I915_READ(reg);
  3697. temp &= ~FDI_LINK_TRAIN_NONE;
  3698. temp |= FDI_LINK_TRAIN_PATTERN_1;
  3699. I915_WRITE(reg, temp);
  3700. reg = FDI_RX_CTL(pipe);
  3701. temp = I915_READ(reg);
  3702. if (HAS_PCH_CPT(dev_priv)) {
  3703. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  3704. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  3705. } else {
  3706. temp &= ~FDI_LINK_TRAIN_NONE;
  3707. temp |= FDI_LINK_TRAIN_PATTERN_1;
  3708. }
  3709. /* BPC in FDI rx is consistent with that in PIPECONF */
  3710. temp &= ~(0x07 << 16);
  3711. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  3712. I915_WRITE(reg, temp);
  3713. POSTING_READ(reg);
  3714. udelay(100);
  3715. }
  3716. bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv)
  3717. {
  3718. struct drm_crtc *crtc;
  3719. bool cleanup_done;
  3720. drm_for_each_crtc(crtc, &dev_priv->drm) {
  3721. struct drm_crtc_commit *commit;
  3722. spin_lock(&crtc->commit_lock);
  3723. commit = list_first_entry_or_null(&crtc->commit_list,
  3724. struct drm_crtc_commit, commit_entry);
  3725. cleanup_done = commit ?
  3726. try_wait_for_completion(&commit->cleanup_done) : true;
  3727. spin_unlock(&crtc->commit_lock);
  3728. if (cleanup_done)
  3729. continue;
  3730. drm_crtc_wait_one_vblank(crtc);
  3731. return true;
  3732. }
  3733. return false;
  3734. }
  3735. void lpt_disable_iclkip(struct drm_i915_private *dev_priv)
  3736. {
  3737. u32 temp;
  3738. I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
  3739. mutex_lock(&dev_priv->sb_lock);
  3740. temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
  3741. temp |= SBI_SSCCTL_DISABLE;
  3742. intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
  3743. mutex_unlock(&dev_priv->sb_lock);
  3744. }
  3745. /* Program iCLKIP clock to the desired frequency */
  3746. static void lpt_program_iclkip(struct intel_crtc *crtc)
  3747. {
  3748. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  3749. int clock = crtc->config->base.adjusted_mode.crtc_clock;
  3750. u32 divsel, phaseinc, auxdiv, phasedir = 0;
  3751. u32 temp;
  3752. lpt_disable_iclkip(dev_priv);
  3753. /* The iCLK virtual clock root frequency is in MHz,
  3754. * but the adjusted_mode->crtc_clock in in KHz. To get the
  3755. * divisors, it is necessary to divide one by another, so we
  3756. * convert the virtual clock precision to KHz here for higher
  3757. * precision.
  3758. */
  3759. for (auxdiv = 0; auxdiv < 2; auxdiv++) {
  3760. u32 iclk_virtual_root_freq = 172800 * 1000;
  3761. u32 iclk_pi_range = 64;
  3762. u32 desired_divisor;
  3763. desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
  3764. clock << auxdiv);
  3765. divsel = (desired_divisor / iclk_pi_range) - 2;
  3766. phaseinc = desired_divisor % iclk_pi_range;
  3767. /*
  3768. * Near 20MHz is a corner case which is
  3769. * out of range for the 7-bit divisor
  3770. */
  3771. if (divsel <= 0x7f)
  3772. break;
  3773. }
  3774. /* This should not happen with any sane values */
  3775. WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
  3776. ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
  3777. WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) &
  3778. ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
  3779. DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
  3780. clock,
  3781. auxdiv,
  3782. divsel,
  3783. phasedir,
  3784. phaseinc);
  3785. mutex_lock(&dev_priv->sb_lock);
  3786. /* Program SSCDIVINTPHASE6 */
  3787. temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
  3788. temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
  3789. temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
  3790. temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
  3791. temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
  3792. temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
  3793. temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
  3794. intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
  3795. /* Program SSCAUXDIV */
  3796. temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
  3797. temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
  3798. temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
  3799. intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
  3800. /* Enable modulator and associated divider */
  3801. temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
  3802. temp &= ~SBI_SSCCTL_DISABLE;
  3803. intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
  3804. mutex_unlock(&dev_priv->sb_lock);
  3805. /* Wait for initialization time */
  3806. udelay(24);
  3807. I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE);
  3808. }
  3809. int lpt_get_iclkip(struct drm_i915_private *dev_priv)
  3810. {
  3811. u32 divsel, phaseinc, auxdiv;
  3812. u32 iclk_virtual_root_freq = 172800 * 1000;
  3813. u32 iclk_pi_range = 64;
  3814. u32 desired_divisor;
  3815. u32 temp;
  3816. if ((I915_READ(PIXCLK_GATE) & PIXCLK_GATE_UNGATE) == 0)
  3817. return 0;
  3818. mutex_lock(&dev_priv->sb_lock);
  3819. temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
  3820. if (temp & SBI_SSCCTL_DISABLE) {
  3821. mutex_unlock(&dev_priv->sb_lock);
  3822. return 0;
  3823. }
  3824. temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
  3825. divsel = (temp & SBI_SSCDIVINTPHASE_DIVSEL_MASK) >>
  3826. SBI_SSCDIVINTPHASE_DIVSEL_SHIFT;
  3827. phaseinc = (temp & SBI_SSCDIVINTPHASE_INCVAL_MASK) >>
  3828. SBI_SSCDIVINTPHASE_INCVAL_SHIFT;
  3829. temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
  3830. auxdiv = (temp & SBI_SSCAUXDIV_FINALDIV2SEL_MASK) >>
  3831. SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT;
  3832. mutex_unlock(&dev_priv->sb_lock);
  3833. desired_divisor = (divsel + 2) * iclk_pi_range + phaseinc;
  3834. return DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
  3835. desired_divisor << auxdiv);
  3836. }
  3837. static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc,
  3838. enum pipe pch_transcoder)
  3839. {
  3840. struct drm_device *dev = crtc->base.dev;
  3841. struct drm_i915_private *dev_priv = to_i915(dev);
  3842. enum transcoder cpu_transcoder = crtc->config->cpu_transcoder;
  3843. I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder),
  3844. I915_READ(HTOTAL(cpu_transcoder)));
  3845. I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder),
  3846. I915_READ(HBLANK(cpu_transcoder)));
  3847. I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder),
  3848. I915_READ(HSYNC(cpu_transcoder)));
  3849. I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder),
  3850. I915_READ(VTOTAL(cpu_transcoder)));
  3851. I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder),
  3852. I915_READ(VBLANK(cpu_transcoder)));
  3853. I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder),
  3854. I915_READ(VSYNC(cpu_transcoder)));
  3855. I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder),
  3856. I915_READ(VSYNCSHIFT(cpu_transcoder)));
  3857. }
  3858. static void cpt_set_fdi_bc_bifurcation(struct drm_device *dev, bool enable)
  3859. {
  3860. struct drm_i915_private *dev_priv = to_i915(dev);
  3861. uint32_t temp;
  3862. temp = I915_READ(SOUTH_CHICKEN1);
  3863. if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable)
  3864. return;
  3865. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
  3866. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
  3867. temp &= ~FDI_BC_BIFURCATION_SELECT;
  3868. if (enable)
  3869. temp |= FDI_BC_BIFURCATION_SELECT;
  3870. DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis");
  3871. I915_WRITE(SOUTH_CHICKEN1, temp);
  3872. POSTING_READ(SOUTH_CHICKEN1);
  3873. }
  3874. static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc)
  3875. {
  3876. struct drm_device *dev = intel_crtc->base.dev;
  3877. switch (intel_crtc->pipe) {
  3878. case PIPE_A:
  3879. break;
  3880. case PIPE_B:
  3881. if (intel_crtc->config->fdi_lanes > 2)
  3882. cpt_set_fdi_bc_bifurcation(dev, false);
  3883. else
  3884. cpt_set_fdi_bc_bifurcation(dev, true);
  3885. break;
  3886. case PIPE_C:
  3887. cpt_set_fdi_bc_bifurcation(dev, true);
  3888. break;
  3889. default:
  3890. BUG();
  3891. }
  3892. }
  3893. /* Return which DP Port should be selected for Transcoder DP control */
  3894. static enum port
  3895. intel_trans_dp_port_sel(struct intel_crtc *crtc)
  3896. {
  3897. struct drm_device *dev = crtc->base.dev;
  3898. struct intel_encoder *encoder;
  3899. for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
  3900. if (encoder->type == INTEL_OUTPUT_DP ||
  3901. encoder->type == INTEL_OUTPUT_EDP)
  3902. return encoder->port;
  3903. }
  3904. return -1;
  3905. }
  3906. /*
  3907. * Enable PCH resources required for PCH ports:
  3908. * - PCH PLLs
  3909. * - FDI training & RX/TX
  3910. * - update transcoder timings
  3911. * - DP transcoding bits
  3912. * - transcoder
  3913. */
  3914. static void ironlake_pch_enable(const struct intel_crtc_state *crtc_state)
  3915. {
  3916. struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
  3917. struct drm_device *dev = crtc->base.dev;
  3918. struct drm_i915_private *dev_priv = to_i915(dev);
  3919. int pipe = crtc->pipe;
  3920. u32 temp;
  3921. assert_pch_transcoder_disabled(dev_priv, pipe);
  3922. if (IS_IVYBRIDGE(dev_priv))
  3923. ivybridge_update_fdi_bc_bifurcation(crtc);
  3924. /* Write the TU size bits before fdi link training, so that error
  3925. * detection works. */
  3926. I915_WRITE(FDI_RX_TUSIZE1(pipe),
  3927. I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
  3928. /* For PCH output, training FDI link */
  3929. dev_priv->display.fdi_link_train(crtc, crtc_state);
  3930. /* We need to program the right clock selection before writing the pixel
  3931. * mutliplier into the DPLL. */
  3932. if (HAS_PCH_CPT(dev_priv)) {
  3933. u32 sel;
  3934. temp = I915_READ(PCH_DPLL_SEL);
  3935. temp |= TRANS_DPLL_ENABLE(pipe);
  3936. sel = TRANS_DPLLB_SEL(pipe);
  3937. if (crtc_state->shared_dpll ==
  3938. intel_get_shared_dpll_by_id(dev_priv, DPLL_ID_PCH_PLL_B))
  3939. temp |= sel;
  3940. else
  3941. temp &= ~sel;
  3942. I915_WRITE(PCH_DPLL_SEL, temp);
  3943. }
  3944. /* XXX: pch pll's can be enabled any time before we enable the PCH
  3945. * transcoder, and we actually should do this to not upset any PCH
  3946. * transcoder that already use the clock when we share it.
  3947. *
  3948. * Note that enable_shared_dpll tries to do the right thing, but
  3949. * get_shared_dpll unconditionally resets the pll - we need that to have
  3950. * the right LVDS enable sequence. */
  3951. intel_enable_shared_dpll(crtc);
  3952. /* set transcoder timing, panel must allow it */
  3953. assert_panel_unlocked(dev_priv, pipe);
  3954. ironlake_pch_transcoder_set_timings(crtc, pipe);
  3955. intel_fdi_normal_train(crtc);
  3956. /* For PCH DP, enable TRANS_DP_CTL */
  3957. if (HAS_PCH_CPT(dev_priv) &&
  3958. intel_crtc_has_dp_encoder(crtc_state)) {
  3959. const struct drm_display_mode *adjusted_mode =
  3960. &crtc_state->base.adjusted_mode;
  3961. u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
  3962. i915_reg_t reg = TRANS_DP_CTL(pipe);
  3963. temp = I915_READ(reg);
  3964. temp &= ~(TRANS_DP_PORT_SEL_MASK |
  3965. TRANS_DP_SYNC_MASK |
  3966. TRANS_DP_BPC_MASK);
  3967. temp |= TRANS_DP_OUTPUT_ENABLE;
  3968. temp |= bpc << 9; /* same format but at 11:9 */
  3969. if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
  3970. temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
  3971. if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
  3972. temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
  3973. switch (intel_trans_dp_port_sel(crtc)) {
  3974. case PORT_B:
  3975. temp |= TRANS_DP_PORT_SEL_B;
  3976. break;
  3977. case PORT_C:
  3978. temp |= TRANS_DP_PORT_SEL_C;
  3979. break;
  3980. case PORT_D:
  3981. temp |= TRANS_DP_PORT_SEL_D;
  3982. break;
  3983. default:
  3984. BUG();
  3985. }
  3986. I915_WRITE(reg, temp);
  3987. }
  3988. ironlake_enable_pch_transcoder(dev_priv, pipe);
  3989. }
  3990. static void lpt_pch_enable(const struct intel_crtc_state *crtc_state)
  3991. {
  3992. struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
  3993. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  3994. enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
  3995. assert_pch_transcoder_disabled(dev_priv, PIPE_A);
  3996. lpt_program_iclkip(crtc);
  3997. /* Set transcoder timing. */
  3998. ironlake_pch_transcoder_set_timings(crtc, PIPE_A);
  3999. lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
  4000. }
  4001. static void cpt_verify_modeset(struct drm_device *dev, int pipe)
  4002. {
  4003. struct drm_i915_private *dev_priv = to_i915(dev);
  4004. i915_reg_t dslreg = PIPEDSL(pipe);
  4005. u32 temp;
  4006. temp = I915_READ(dslreg);
  4007. udelay(500);
  4008. if (wait_for(I915_READ(dslreg) != temp, 5)) {
  4009. if (wait_for(I915_READ(dslreg) != temp, 5))
  4010. DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe));
  4011. }
  4012. }
  4013. static int
  4014. skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach,
  4015. unsigned int scaler_user, int *scaler_id,
  4016. int src_w, int src_h, int dst_w, int dst_h,
  4017. bool plane_scaler_check,
  4018. uint32_t pixel_format)
  4019. {
  4020. struct intel_crtc_scaler_state *scaler_state =
  4021. &crtc_state->scaler_state;
  4022. struct intel_crtc *intel_crtc =
  4023. to_intel_crtc(crtc_state->base.crtc);
  4024. struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
  4025. const struct drm_display_mode *adjusted_mode =
  4026. &crtc_state->base.adjusted_mode;
  4027. int need_scaling;
  4028. /*
  4029. * Src coordinates are already rotated by 270 degrees for
  4030. * the 90/270 degree plane rotation cases (to match the
  4031. * GTT mapping), hence no need to account for rotation here.
  4032. */
  4033. need_scaling = src_w != dst_w || src_h != dst_h;
  4034. if (plane_scaler_check)
  4035. if (pixel_format == DRM_FORMAT_NV12)
  4036. need_scaling = true;
  4037. if (crtc_state->ycbcr420 && scaler_user == SKL_CRTC_INDEX)
  4038. need_scaling = true;
  4039. /*
  4040. * Scaling/fitting not supported in IF-ID mode in GEN9+
  4041. * TODO: Interlace fetch mode doesn't support YUV420 planar formats.
  4042. * Once NV12 is enabled, handle it here while allocating scaler
  4043. * for NV12.
  4044. */
  4045. if (INTEL_GEN(dev_priv) >= 9 && crtc_state->base.enable &&
  4046. need_scaling && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
  4047. DRM_DEBUG_KMS("Pipe/Plane scaling not supported with IF-ID mode\n");
  4048. return -EINVAL;
  4049. }
  4050. /*
  4051. * if plane is being disabled or scaler is no more required or force detach
  4052. * - free scaler binded to this plane/crtc
  4053. * - in order to do this, update crtc->scaler_usage
  4054. *
  4055. * Here scaler state in crtc_state is set free so that
  4056. * scaler can be assigned to other user. Actual register
  4057. * update to free the scaler is done in plane/panel-fit programming.
  4058. * For this purpose crtc/plane_state->scaler_id isn't reset here.
  4059. */
  4060. if (force_detach || !need_scaling) {
  4061. if (*scaler_id >= 0) {
  4062. scaler_state->scaler_users &= ~(1 << scaler_user);
  4063. scaler_state->scalers[*scaler_id].in_use = 0;
  4064. DRM_DEBUG_KMS("scaler_user index %u.%u: "
  4065. "Staged freeing scaler id %d scaler_users = 0x%x\n",
  4066. intel_crtc->pipe, scaler_user, *scaler_id,
  4067. scaler_state->scaler_users);
  4068. *scaler_id = -1;
  4069. }
  4070. return 0;
  4071. }
  4072. if (plane_scaler_check && pixel_format == DRM_FORMAT_NV12 &&
  4073. (src_h < SKL_MIN_YUV_420_SRC_H || (src_w % 4) != 0 ||
  4074. (src_h % 4) != 0)) {
  4075. DRM_DEBUG_KMS("NV12: src dimensions not met\n");
  4076. return -EINVAL;
  4077. }
  4078. /* range checks */
  4079. if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H ||
  4080. dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H ||
  4081. (IS_GEN11(dev_priv) &&
  4082. (src_w > ICL_MAX_SRC_W || src_h > ICL_MAX_SRC_H ||
  4083. dst_w > ICL_MAX_DST_W || dst_h > ICL_MAX_DST_H)) ||
  4084. (!IS_GEN11(dev_priv) &&
  4085. (src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H ||
  4086. dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H))) {
  4087. DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u "
  4088. "size is out of scaler range\n",
  4089. intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h);
  4090. return -EINVAL;
  4091. }
  4092. /* mark this plane as a scaler user in crtc_state */
  4093. scaler_state->scaler_users |= (1 << scaler_user);
  4094. DRM_DEBUG_KMS("scaler_user index %u.%u: "
  4095. "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n",
  4096. intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h,
  4097. scaler_state->scaler_users);
  4098. return 0;
  4099. }
  4100. /**
  4101. * skl_update_scaler_crtc - Stages update to scaler state for a given crtc.
  4102. *
  4103. * @state: crtc's scaler state
  4104. *
  4105. * Return
  4106. * 0 - scaler_usage updated successfully
  4107. * error - requested scaling cannot be supported or other error condition
  4108. */
  4109. int skl_update_scaler_crtc(struct intel_crtc_state *state)
  4110. {
  4111. const struct drm_display_mode *adjusted_mode = &state->base.adjusted_mode;
  4112. return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX,
  4113. &state->scaler_state.scaler_id,
  4114. state->pipe_src_w, state->pipe_src_h,
  4115. adjusted_mode->crtc_hdisplay,
  4116. adjusted_mode->crtc_vdisplay, false, 0);
  4117. }
  4118. /**
  4119. * skl_update_scaler_plane - Stages update to scaler state for a given plane.
  4120. * @crtc_state: crtc's scaler state
  4121. * @plane_state: atomic plane state to update
  4122. *
  4123. * Return
  4124. * 0 - scaler_usage updated successfully
  4125. * error - requested scaling cannot be supported or other error condition
  4126. */
  4127. static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state,
  4128. struct intel_plane_state *plane_state)
  4129. {
  4130. struct intel_plane *intel_plane =
  4131. to_intel_plane(plane_state->base.plane);
  4132. struct drm_framebuffer *fb = plane_state->base.fb;
  4133. int ret;
  4134. bool force_detach = !fb || !plane_state->base.visible;
  4135. ret = skl_update_scaler(crtc_state, force_detach,
  4136. drm_plane_index(&intel_plane->base),
  4137. &plane_state->scaler_id,
  4138. drm_rect_width(&plane_state->base.src) >> 16,
  4139. drm_rect_height(&plane_state->base.src) >> 16,
  4140. drm_rect_width(&plane_state->base.dst),
  4141. drm_rect_height(&plane_state->base.dst),
  4142. fb ? true : false, fb ? fb->format->format : 0);
  4143. if (ret || plane_state->scaler_id < 0)
  4144. return ret;
  4145. /* check colorkey */
  4146. if (plane_state->ckey.flags) {
  4147. DRM_DEBUG_KMS("[PLANE:%d:%s] scaling with color key not allowed",
  4148. intel_plane->base.base.id,
  4149. intel_plane->base.name);
  4150. return -EINVAL;
  4151. }
  4152. /* Check src format */
  4153. switch (fb->format->format) {
  4154. case DRM_FORMAT_RGB565:
  4155. case DRM_FORMAT_XBGR8888:
  4156. case DRM_FORMAT_XRGB8888:
  4157. case DRM_FORMAT_ABGR8888:
  4158. case DRM_FORMAT_ARGB8888:
  4159. case DRM_FORMAT_XRGB2101010:
  4160. case DRM_FORMAT_XBGR2101010:
  4161. case DRM_FORMAT_YUYV:
  4162. case DRM_FORMAT_YVYU:
  4163. case DRM_FORMAT_UYVY:
  4164. case DRM_FORMAT_VYUY:
  4165. case DRM_FORMAT_NV12:
  4166. break;
  4167. default:
  4168. DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n",
  4169. intel_plane->base.base.id, intel_plane->base.name,
  4170. fb->base.id, fb->format->format);
  4171. return -EINVAL;
  4172. }
  4173. return 0;
  4174. }
  4175. static void skylake_scaler_disable(struct intel_crtc *crtc)
  4176. {
  4177. int i;
  4178. for (i = 0; i < crtc->num_scalers; i++)
  4179. skl_detach_scaler(crtc, i);
  4180. }
  4181. static void skylake_pfit_enable(struct intel_crtc *crtc)
  4182. {
  4183. struct drm_device *dev = crtc->base.dev;
  4184. struct drm_i915_private *dev_priv = to_i915(dev);
  4185. int pipe = crtc->pipe;
  4186. struct intel_crtc_scaler_state *scaler_state =
  4187. &crtc->config->scaler_state;
  4188. if (crtc->config->pch_pfit.enabled) {
  4189. int id;
  4190. if (WARN_ON(crtc->config->scaler_state.scaler_id < 0))
  4191. return;
  4192. id = scaler_state->scaler_id;
  4193. I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN |
  4194. PS_FILTER_MEDIUM | scaler_state->scalers[id].mode);
  4195. I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc->config->pch_pfit.pos);
  4196. I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc->config->pch_pfit.size);
  4197. }
  4198. }
  4199. static void ironlake_pfit_enable(struct intel_crtc *crtc)
  4200. {
  4201. struct drm_device *dev = crtc->base.dev;
  4202. struct drm_i915_private *dev_priv = to_i915(dev);
  4203. int pipe = crtc->pipe;
  4204. if (crtc->config->pch_pfit.enabled) {
  4205. /* Force use of hard-coded filter coefficients
  4206. * as some pre-programmed values are broken,
  4207. * e.g. x201.
  4208. */
  4209. if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv))
  4210. I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
  4211. PF_PIPE_SEL_IVB(pipe));
  4212. else
  4213. I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
  4214. I915_WRITE(PF_WIN_POS(pipe), crtc->config->pch_pfit.pos);
  4215. I915_WRITE(PF_WIN_SZ(pipe), crtc->config->pch_pfit.size);
  4216. }
  4217. }
  4218. void hsw_enable_ips(const struct intel_crtc_state *crtc_state)
  4219. {
  4220. struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
  4221. struct drm_device *dev = crtc->base.dev;
  4222. struct drm_i915_private *dev_priv = to_i915(dev);
  4223. if (!crtc_state->ips_enabled)
  4224. return;
  4225. /*
  4226. * We can only enable IPS after we enable a plane and wait for a vblank
  4227. * This function is called from post_plane_update, which is run after
  4228. * a vblank wait.
  4229. */
  4230. WARN_ON(!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)));
  4231. if (IS_BROADWELL(dev_priv)) {
  4232. mutex_lock(&dev_priv->pcu_lock);
  4233. WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL,
  4234. IPS_ENABLE | IPS_PCODE_CONTROL));
  4235. mutex_unlock(&dev_priv->pcu_lock);
  4236. /* Quoting Art Runyan: "its not safe to expect any particular
  4237. * value in IPS_CTL bit 31 after enabling IPS through the
  4238. * mailbox." Moreover, the mailbox may return a bogus state,
  4239. * so we need to just enable it and continue on.
  4240. */
  4241. } else {
  4242. I915_WRITE(IPS_CTL, IPS_ENABLE);
  4243. /* The bit only becomes 1 in the next vblank, so this wait here
  4244. * is essentially intel_wait_for_vblank. If we don't have this
  4245. * and don't wait for vblanks until the end of crtc_enable, then
  4246. * the HW state readout code will complain that the expected
  4247. * IPS_CTL value is not the one we read. */
  4248. if (intel_wait_for_register(dev_priv,
  4249. IPS_CTL, IPS_ENABLE, IPS_ENABLE,
  4250. 50))
  4251. DRM_ERROR("Timed out waiting for IPS enable\n");
  4252. }
  4253. }
  4254. void hsw_disable_ips(const struct intel_crtc_state *crtc_state)
  4255. {
  4256. struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
  4257. struct drm_device *dev = crtc->base.dev;
  4258. struct drm_i915_private *dev_priv = to_i915(dev);
  4259. if (!crtc_state->ips_enabled)
  4260. return;
  4261. if (IS_BROADWELL(dev_priv)) {
  4262. mutex_lock(&dev_priv->pcu_lock);
  4263. WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0));
  4264. mutex_unlock(&dev_priv->pcu_lock);
  4265. /* wait for pcode to finish disabling IPS, which may take up to 42ms */
  4266. if (intel_wait_for_register(dev_priv,
  4267. IPS_CTL, IPS_ENABLE, 0,
  4268. 42))
  4269. DRM_ERROR("Timed out waiting for IPS disable\n");
  4270. } else {
  4271. I915_WRITE(IPS_CTL, 0);
  4272. POSTING_READ(IPS_CTL);
  4273. }
  4274. /* We need to wait for a vblank before we can disable the plane. */
  4275. intel_wait_for_vblank(dev_priv, crtc->pipe);
  4276. }
  4277. static void intel_crtc_dpms_overlay_disable(struct intel_crtc *intel_crtc)
  4278. {
  4279. if (intel_crtc->overlay) {
  4280. struct drm_device *dev = intel_crtc->base.dev;
  4281. mutex_lock(&dev->struct_mutex);
  4282. (void) intel_overlay_switch_off(intel_crtc->overlay);
  4283. mutex_unlock(&dev->struct_mutex);
  4284. }
  4285. /* Let userspace switch the overlay on again. In most cases userspace
  4286. * has to recompute where to put it anyway.
  4287. */
  4288. }
  4289. /**
  4290. * intel_post_enable_primary - Perform operations after enabling primary plane
  4291. * @crtc: the CRTC whose primary plane was just enabled
  4292. * @new_crtc_state: the enabling state
  4293. *
  4294. * Performs potentially sleeping operations that must be done after the primary
  4295. * plane is enabled, such as updating FBC and IPS. Note that this may be
  4296. * called due to an explicit primary plane update, or due to an implicit
  4297. * re-enable that is caused when a sprite plane is updated to no longer
  4298. * completely hide the primary plane.
  4299. */
  4300. static void
  4301. intel_post_enable_primary(struct drm_crtc *crtc,
  4302. const struct intel_crtc_state *new_crtc_state)
  4303. {
  4304. struct drm_device *dev = crtc->dev;
  4305. struct drm_i915_private *dev_priv = to_i915(dev);
  4306. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4307. int pipe = intel_crtc->pipe;
  4308. /*
  4309. * Gen2 reports pipe underruns whenever all planes are disabled.
  4310. * So don't enable underrun reporting before at least some planes
  4311. * are enabled.
  4312. * FIXME: Need to fix the logic to work when we turn off all planes
  4313. * but leave the pipe running.
  4314. */
  4315. if (IS_GEN2(dev_priv))
  4316. intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
  4317. /* Underruns don't always raise interrupts, so check manually. */
  4318. intel_check_cpu_fifo_underruns(dev_priv);
  4319. intel_check_pch_fifo_underruns(dev_priv);
  4320. }
  4321. /* FIXME get rid of this and use pre_plane_update */
  4322. static void
  4323. intel_pre_disable_primary_noatomic(struct drm_crtc *crtc)
  4324. {
  4325. struct drm_device *dev = crtc->dev;
  4326. struct drm_i915_private *dev_priv = to_i915(dev);
  4327. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4328. int pipe = intel_crtc->pipe;
  4329. /*
  4330. * Gen2 reports pipe underruns whenever all planes are disabled.
  4331. * So disable underrun reporting before all the planes get disabled.
  4332. */
  4333. if (IS_GEN2(dev_priv))
  4334. intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
  4335. hsw_disable_ips(to_intel_crtc_state(crtc->state));
  4336. /*
  4337. * Vblank time updates from the shadow to live plane control register
  4338. * are blocked if the memory self-refresh mode is active at that
  4339. * moment. So to make sure the plane gets truly disabled, disable
  4340. * first the self-refresh mode. The self-refresh enable bit in turn
  4341. * will be checked/applied by the HW only at the next frame start
  4342. * event which is after the vblank start event, so we need to have a
  4343. * wait-for-vblank between disabling the plane and the pipe.
  4344. */
  4345. if (HAS_GMCH_DISPLAY(dev_priv) &&
  4346. intel_set_memory_cxsr(dev_priv, false))
  4347. intel_wait_for_vblank(dev_priv, pipe);
  4348. }
  4349. static bool hsw_pre_update_disable_ips(const struct intel_crtc_state *old_crtc_state,
  4350. const struct intel_crtc_state *new_crtc_state)
  4351. {
  4352. if (!old_crtc_state->ips_enabled)
  4353. return false;
  4354. if (needs_modeset(&new_crtc_state->base))
  4355. return true;
  4356. return !new_crtc_state->ips_enabled;
  4357. }
  4358. static bool hsw_post_update_enable_ips(const struct intel_crtc_state *old_crtc_state,
  4359. const struct intel_crtc_state *new_crtc_state)
  4360. {
  4361. if (!new_crtc_state->ips_enabled)
  4362. return false;
  4363. if (needs_modeset(&new_crtc_state->base))
  4364. return true;
  4365. /*
  4366. * We can't read out IPS on broadwell, assume the worst and
  4367. * forcibly enable IPS on the first fastset.
  4368. */
  4369. if (new_crtc_state->update_pipe &&
  4370. old_crtc_state->base.adjusted_mode.private_flags & I915_MODE_FLAG_INHERITED)
  4371. return true;
  4372. return !old_crtc_state->ips_enabled;
  4373. }
  4374. static void intel_post_plane_update(struct intel_crtc_state *old_crtc_state)
  4375. {
  4376. struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
  4377. struct drm_device *dev = crtc->base.dev;
  4378. struct drm_i915_private *dev_priv = to_i915(dev);
  4379. struct drm_atomic_state *old_state = old_crtc_state->base.state;
  4380. struct intel_crtc_state *pipe_config =
  4381. intel_atomic_get_new_crtc_state(to_intel_atomic_state(old_state),
  4382. crtc);
  4383. struct drm_plane *primary = crtc->base.primary;
  4384. struct drm_plane_state *old_primary_state =
  4385. drm_atomic_get_old_plane_state(old_state, primary);
  4386. intel_frontbuffer_flip(to_i915(crtc->base.dev), pipe_config->fb_bits);
  4387. if (pipe_config->update_wm_post && pipe_config->base.active)
  4388. intel_update_watermarks(crtc);
  4389. if (hsw_post_update_enable_ips(old_crtc_state, pipe_config))
  4390. hsw_enable_ips(pipe_config);
  4391. if (old_primary_state) {
  4392. struct drm_plane_state *new_primary_state =
  4393. drm_atomic_get_new_plane_state(old_state, primary);
  4394. struct drm_framebuffer *fb = new_primary_state->fb;
  4395. intel_fbc_post_update(crtc);
  4396. if (new_primary_state->visible &&
  4397. (needs_modeset(&pipe_config->base) ||
  4398. !old_primary_state->visible))
  4399. intel_post_enable_primary(&crtc->base, pipe_config);
  4400. /* Display WA 827 */
  4401. if ((INTEL_GEN(dev_priv) == 9 && !IS_GEMINILAKE(dev_priv)) ||
  4402. IS_CANNONLAKE(dev_priv)) {
  4403. if (fb && fb->format->format == DRM_FORMAT_NV12)
  4404. skl_wa_clkgate(dev_priv, crtc->pipe, false);
  4405. }
  4406. }
  4407. }
  4408. static void intel_pre_plane_update(struct intel_crtc_state *old_crtc_state,
  4409. struct intel_crtc_state *pipe_config)
  4410. {
  4411. struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
  4412. struct drm_device *dev = crtc->base.dev;
  4413. struct drm_i915_private *dev_priv = to_i915(dev);
  4414. struct drm_atomic_state *old_state = old_crtc_state->base.state;
  4415. struct drm_plane *primary = crtc->base.primary;
  4416. struct drm_plane_state *old_primary_state =
  4417. drm_atomic_get_old_plane_state(old_state, primary);
  4418. bool modeset = needs_modeset(&pipe_config->base);
  4419. struct intel_atomic_state *old_intel_state =
  4420. to_intel_atomic_state(old_state);
  4421. if (hsw_pre_update_disable_ips(old_crtc_state, pipe_config))
  4422. hsw_disable_ips(old_crtc_state);
  4423. if (old_primary_state) {
  4424. struct intel_plane_state *new_primary_state =
  4425. intel_atomic_get_new_plane_state(old_intel_state,
  4426. to_intel_plane(primary));
  4427. struct drm_framebuffer *fb = new_primary_state->base.fb;
  4428. /* Display WA 827 */
  4429. if ((INTEL_GEN(dev_priv) == 9 && !IS_GEMINILAKE(dev_priv)) ||
  4430. IS_CANNONLAKE(dev_priv)) {
  4431. if (fb && fb->format->format == DRM_FORMAT_NV12)
  4432. skl_wa_clkgate(dev_priv, crtc->pipe, true);
  4433. }
  4434. intel_fbc_pre_update(crtc, pipe_config, new_primary_state);
  4435. /*
  4436. * Gen2 reports pipe underruns whenever all planes are disabled.
  4437. * So disable underrun reporting before all the planes get disabled.
  4438. */
  4439. if (IS_GEN2(dev_priv) && old_primary_state->visible &&
  4440. (modeset || !new_primary_state->base.visible))
  4441. intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
  4442. }
  4443. /*
  4444. * Vblank time updates from the shadow to live plane control register
  4445. * are blocked if the memory self-refresh mode is active at that
  4446. * moment. So to make sure the plane gets truly disabled, disable
  4447. * first the self-refresh mode. The self-refresh enable bit in turn
  4448. * will be checked/applied by the HW only at the next frame start
  4449. * event which is after the vblank start event, so we need to have a
  4450. * wait-for-vblank between disabling the plane and the pipe.
  4451. */
  4452. if (HAS_GMCH_DISPLAY(dev_priv) && old_crtc_state->base.active &&
  4453. pipe_config->disable_cxsr && intel_set_memory_cxsr(dev_priv, false))
  4454. intel_wait_for_vblank(dev_priv, crtc->pipe);
  4455. /*
  4456. * IVB workaround: must disable low power watermarks for at least
  4457. * one frame before enabling scaling. LP watermarks can be re-enabled
  4458. * when scaling is disabled.
  4459. *
  4460. * WaCxSRDisabledForSpriteScaling:ivb
  4461. */
  4462. if (pipe_config->disable_lp_wm && ilk_disable_lp_wm(dev))
  4463. intel_wait_for_vblank(dev_priv, crtc->pipe);
  4464. /*
  4465. * If we're doing a modeset, we're done. No need to do any pre-vblank
  4466. * watermark programming here.
  4467. */
  4468. if (needs_modeset(&pipe_config->base))
  4469. return;
  4470. /*
  4471. * For platforms that support atomic watermarks, program the
  4472. * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
  4473. * will be the intermediate values that are safe for both pre- and
  4474. * post- vblank; when vblank happens, the 'active' values will be set
  4475. * to the final 'target' values and we'll do this again to get the
  4476. * optimal watermarks. For gen9+ platforms, the values we program here
  4477. * will be the final target values which will get automatically latched
  4478. * at vblank time; no further programming will be necessary.
  4479. *
  4480. * If a platform hasn't been transitioned to atomic watermarks yet,
  4481. * we'll continue to update watermarks the old way, if flags tell
  4482. * us to.
  4483. */
  4484. if (dev_priv->display.initial_watermarks != NULL)
  4485. dev_priv->display.initial_watermarks(old_intel_state,
  4486. pipe_config);
  4487. else if (pipe_config->update_wm_pre)
  4488. intel_update_watermarks(crtc);
  4489. }
  4490. static void intel_crtc_disable_planes(struct drm_crtc *crtc, unsigned plane_mask)
  4491. {
  4492. struct drm_device *dev = crtc->dev;
  4493. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4494. struct drm_plane *p;
  4495. int pipe = intel_crtc->pipe;
  4496. intel_crtc_dpms_overlay_disable(intel_crtc);
  4497. drm_for_each_plane_mask(p, dev, plane_mask)
  4498. to_intel_plane(p)->disable_plane(to_intel_plane(p), intel_crtc);
  4499. /*
  4500. * FIXME: Once we grow proper nuclear flip support out of this we need
  4501. * to compute the mask of flip planes precisely. For the time being
  4502. * consider this a flip to a NULL plane.
  4503. */
  4504. intel_frontbuffer_flip(to_i915(dev), INTEL_FRONTBUFFER_ALL_MASK(pipe));
  4505. }
  4506. static void intel_encoders_pre_pll_enable(struct drm_crtc *crtc,
  4507. struct intel_crtc_state *crtc_state,
  4508. struct drm_atomic_state *old_state)
  4509. {
  4510. struct drm_connector_state *conn_state;
  4511. struct drm_connector *conn;
  4512. int i;
  4513. for_each_new_connector_in_state(old_state, conn, conn_state, i) {
  4514. struct intel_encoder *encoder =
  4515. to_intel_encoder(conn_state->best_encoder);
  4516. if (conn_state->crtc != crtc)
  4517. continue;
  4518. if (encoder->pre_pll_enable)
  4519. encoder->pre_pll_enable(encoder, crtc_state, conn_state);
  4520. }
  4521. }
  4522. static void intel_encoders_pre_enable(struct drm_crtc *crtc,
  4523. struct intel_crtc_state *crtc_state,
  4524. struct drm_atomic_state *old_state)
  4525. {
  4526. struct drm_connector_state *conn_state;
  4527. struct drm_connector *conn;
  4528. int i;
  4529. for_each_new_connector_in_state(old_state, conn, conn_state, i) {
  4530. struct intel_encoder *encoder =
  4531. to_intel_encoder(conn_state->best_encoder);
  4532. if (conn_state->crtc != crtc)
  4533. continue;
  4534. if (encoder->pre_enable)
  4535. encoder->pre_enable(encoder, crtc_state, conn_state);
  4536. }
  4537. }
  4538. static void intel_encoders_enable(struct drm_crtc *crtc,
  4539. struct intel_crtc_state *crtc_state,
  4540. struct drm_atomic_state *old_state)
  4541. {
  4542. struct drm_connector_state *conn_state;
  4543. struct drm_connector *conn;
  4544. int i;
  4545. for_each_new_connector_in_state(old_state, conn, conn_state, i) {
  4546. struct intel_encoder *encoder =
  4547. to_intel_encoder(conn_state->best_encoder);
  4548. if (conn_state->crtc != crtc)
  4549. continue;
  4550. encoder->enable(encoder, crtc_state, conn_state);
  4551. intel_opregion_notify_encoder(encoder, true);
  4552. }
  4553. }
  4554. static void intel_encoders_disable(struct drm_crtc *crtc,
  4555. struct intel_crtc_state *old_crtc_state,
  4556. struct drm_atomic_state *old_state)
  4557. {
  4558. struct drm_connector_state *old_conn_state;
  4559. struct drm_connector *conn;
  4560. int i;
  4561. for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
  4562. struct intel_encoder *encoder =
  4563. to_intel_encoder(old_conn_state->best_encoder);
  4564. if (old_conn_state->crtc != crtc)
  4565. continue;
  4566. intel_opregion_notify_encoder(encoder, false);
  4567. encoder->disable(encoder, old_crtc_state, old_conn_state);
  4568. }
  4569. }
  4570. static void intel_encoders_post_disable(struct drm_crtc *crtc,
  4571. struct intel_crtc_state *old_crtc_state,
  4572. struct drm_atomic_state *old_state)
  4573. {
  4574. struct drm_connector_state *old_conn_state;
  4575. struct drm_connector *conn;
  4576. int i;
  4577. for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
  4578. struct intel_encoder *encoder =
  4579. to_intel_encoder(old_conn_state->best_encoder);
  4580. if (old_conn_state->crtc != crtc)
  4581. continue;
  4582. if (encoder->post_disable)
  4583. encoder->post_disable(encoder, old_crtc_state, old_conn_state);
  4584. }
  4585. }
  4586. static void intel_encoders_post_pll_disable(struct drm_crtc *crtc,
  4587. struct intel_crtc_state *old_crtc_state,
  4588. struct drm_atomic_state *old_state)
  4589. {
  4590. struct drm_connector_state *old_conn_state;
  4591. struct drm_connector *conn;
  4592. int i;
  4593. for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
  4594. struct intel_encoder *encoder =
  4595. to_intel_encoder(old_conn_state->best_encoder);
  4596. if (old_conn_state->crtc != crtc)
  4597. continue;
  4598. if (encoder->post_pll_disable)
  4599. encoder->post_pll_disable(encoder, old_crtc_state, old_conn_state);
  4600. }
  4601. }
  4602. static void ironlake_crtc_enable(struct intel_crtc_state *pipe_config,
  4603. struct drm_atomic_state *old_state)
  4604. {
  4605. struct drm_crtc *crtc = pipe_config->base.crtc;
  4606. struct drm_device *dev = crtc->dev;
  4607. struct drm_i915_private *dev_priv = to_i915(dev);
  4608. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4609. int pipe = intel_crtc->pipe;
  4610. struct intel_atomic_state *old_intel_state =
  4611. to_intel_atomic_state(old_state);
  4612. if (WARN_ON(intel_crtc->active))
  4613. return;
  4614. /*
  4615. * Sometimes spurious CPU pipe underruns happen during FDI
  4616. * training, at least with VGA+HDMI cloning. Suppress them.
  4617. *
  4618. * On ILK we get an occasional spurious CPU pipe underruns
  4619. * between eDP port A enable and vdd enable. Also PCH port
  4620. * enable seems to result in the occasional CPU pipe underrun.
  4621. *
  4622. * Spurious PCH underruns also occur during PCH enabling.
  4623. */
  4624. if (intel_crtc->config->has_pch_encoder || IS_GEN5(dev_priv))
  4625. intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
  4626. if (intel_crtc->config->has_pch_encoder)
  4627. intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
  4628. if (intel_crtc->config->has_pch_encoder)
  4629. intel_prepare_shared_dpll(intel_crtc);
  4630. if (intel_crtc_has_dp_encoder(intel_crtc->config))
  4631. intel_dp_set_m_n(intel_crtc, M1_N1);
  4632. intel_set_pipe_timings(intel_crtc);
  4633. intel_set_pipe_src_size(intel_crtc);
  4634. if (intel_crtc->config->has_pch_encoder) {
  4635. intel_cpu_transcoder_set_m_n(intel_crtc,
  4636. &intel_crtc->config->fdi_m_n, NULL);
  4637. }
  4638. ironlake_set_pipeconf(crtc);
  4639. intel_crtc->active = true;
  4640. intel_encoders_pre_enable(crtc, pipe_config, old_state);
  4641. if (intel_crtc->config->has_pch_encoder) {
  4642. /* Note: FDI PLL enabling _must_ be done before we enable the
  4643. * cpu pipes, hence this is separate from all the other fdi/pch
  4644. * enabling. */
  4645. ironlake_fdi_pll_enable(intel_crtc);
  4646. } else {
  4647. assert_fdi_tx_disabled(dev_priv, pipe);
  4648. assert_fdi_rx_disabled(dev_priv, pipe);
  4649. }
  4650. ironlake_pfit_enable(intel_crtc);
  4651. /*
  4652. * On ILK+ LUT must be loaded before the pipe is running but with
  4653. * clocks enabled
  4654. */
  4655. intel_color_load_luts(&pipe_config->base);
  4656. if (dev_priv->display.initial_watermarks != NULL)
  4657. dev_priv->display.initial_watermarks(old_intel_state, intel_crtc->config);
  4658. intel_enable_pipe(pipe_config);
  4659. if (intel_crtc->config->has_pch_encoder)
  4660. ironlake_pch_enable(pipe_config);
  4661. assert_vblank_disabled(crtc);
  4662. drm_crtc_vblank_on(crtc);
  4663. intel_encoders_enable(crtc, pipe_config, old_state);
  4664. if (HAS_PCH_CPT(dev_priv))
  4665. cpt_verify_modeset(dev, intel_crtc->pipe);
  4666. /* Must wait for vblank to avoid spurious PCH FIFO underruns */
  4667. if (intel_crtc->config->has_pch_encoder)
  4668. intel_wait_for_vblank(dev_priv, pipe);
  4669. intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
  4670. intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
  4671. }
  4672. /* IPS only exists on ULT machines and is tied to pipe A. */
  4673. static bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
  4674. {
  4675. return HAS_IPS(to_i915(crtc->base.dev)) && crtc->pipe == PIPE_A;
  4676. }
  4677. static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private *dev_priv,
  4678. enum pipe pipe, bool apply)
  4679. {
  4680. u32 val = I915_READ(CLKGATE_DIS_PSL(pipe));
  4681. u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS;
  4682. if (apply)
  4683. val |= mask;
  4684. else
  4685. val &= ~mask;
  4686. I915_WRITE(CLKGATE_DIS_PSL(pipe), val);
  4687. }
  4688. static void icl_pipe_mbus_enable(struct intel_crtc *crtc)
  4689. {
  4690. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  4691. enum pipe pipe = crtc->pipe;
  4692. uint32_t val;
  4693. val = MBUS_DBOX_BW_CREDIT(1) | MBUS_DBOX_A_CREDIT(2);
  4694. /* Program B credit equally to all pipes */
  4695. val |= MBUS_DBOX_B_CREDIT(24 / INTEL_INFO(dev_priv)->num_pipes);
  4696. I915_WRITE(PIPE_MBUS_DBOX_CTL(pipe), val);
  4697. }
  4698. static void haswell_crtc_enable(struct intel_crtc_state *pipe_config,
  4699. struct drm_atomic_state *old_state)
  4700. {
  4701. struct drm_crtc *crtc = pipe_config->base.crtc;
  4702. struct drm_i915_private *dev_priv = to_i915(crtc->dev);
  4703. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4704. int pipe = intel_crtc->pipe, hsw_workaround_pipe;
  4705. enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
  4706. struct intel_atomic_state *old_intel_state =
  4707. to_intel_atomic_state(old_state);
  4708. bool psl_clkgate_wa;
  4709. if (WARN_ON(intel_crtc->active))
  4710. return;
  4711. intel_encoders_pre_pll_enable(crtc, pipe_config, old_state);
  4712. if (intel_crtc->config->shared_dpll)
  4713. intel_enable_shared_dpll(intel_crtc);
  4714. if (intel_crtc_has_dp_encoder(intel_crtc->config))
  4715. intel_dp_set_m_n(intel_crtc, M1_N1);
  4716. if (!transcoder_is_dsi(cpu_transcoder))
  4717. intel_set_pipe_timings(intel_crtc);
  4718. intel_set_pipe_src_size(intel_crtc);
  4719. if (cpu_transcoder != TRANSCODER_EDP &&
  4720. !transcoder_is_dsi(cpu_transcoder)) {
  4721. I915_WRITE(PIPE_MULT(cpu_transcoder),
  4722. intel_crtc->config->pixel_multiplier - 1);
  4723. }
  4724. if (intel_crtc->config->has_pch_encoder) {
  4725. intel_cpu_transcoder_set_m_n(intel_crtc,
  4726. &intel_crtc->config->fdi_m_n, NULL);
  4727. }
  4728. if (!transcoder_is_dsi(cpu_transcoder))
  4729. haswell_set_pipeconf(crtc);
  4730. haswell_set_pipemisc(crtc);
  4731. intel_color_set_csc(&pipe_config->base);
  4732. intel_crtc->active = true;
  4733. intel_encoders_pre_enable(crtc, pipe_config, old_state);
  4734. if (!transcoder_is_dsi(cpu_transcoder))
  4735. intel_ddi_enable_pipe_clock(pipe_config);
  4736. /* Display WA #1180: WaDisableScalarClockGating: glk, cnl */
  4737. psl_clkgate_wa = (IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) &&
  4738. intel_crtc->config->pch_pfit.enabled;
  4739. if (psl_clkgate_wa)
  4740. glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true);
  4741. if (INTEL_GEN(dev_priv) >= 9)
  4742. skylake_pfit_enable(intel_crtc);
  4743. else
  4744. ironlake_pfit_enable(intel_crtc);
  4745. /*
  4746. * On ILK+ LUT must be loaded before the pipe is running but with
  4747. * clocks enabled
  4748. */
  4749. intel_color_load_luts(&pipe_config->base);
  4750. intel_ddi_set_pipe_settings(pipe_config);
  4751. if (!transcoder_is_dsi(cpu_transcoder))
  4752. intel_ddi_enable_transcoder_func(pipe_config);
  4753. if (dev_priv->display.initial_watermarks != NULL)
  4754. dev_priv->display.initial_watermarks(old_intel_state, pipe_config);
  4755. if (INTEL_GEN(dev_priv) >= 11)
  4756. icl_pipe_mbus_enable(intel_crtc);
  4757. /* XXX: Do the pipe assertions at the right place for BXT DSI. */
  4758. if (!transcoder_is_dsi(cpu_transcoder))
  4759. intel_enable_pipe(pipe_config);
  4760. if (intel_crtc->config->has_pch_encoder)
  4761. lpt_pch_enable(pipe_config);
  4762. if (intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_DP_MST))
  4763. intel_ddi_set_vc_payload_alloc(pipe_config, true);
  4764. assert_vblank_disabled(crtc);
  4765. drm_crtc_vblank_on(crtc);
  4766. intel_encoders_enable(crtc, pipe_config, old_state);
  4767. if (psl_clkgate_wa) {
  4768. intel_wait_for_vblank(dev_priv, pipe);
  4769. glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, false);
  4770. }
  4771. /* If we change the relative order between pipe/planes enabling, we need
  4772. * to change the workaround. */
  4773. hsw_workaround_pipe = pipe_config->hsw_workaround_pipe;
  4774. if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) {
  4775. intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
  4776. intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
  4777. }
  4778. }
  4779. static void ironlake_pfit_disable(struct intel_crtc *crtc, bool force)
  4780. {
  4781. struct drm_device *dev = crtc->base.dev;
  4782. struct drm_i915_private *dev_priv = to_i915(dev);
  4783. int pipe = crtc->pipe;
  4784. /* To avoid upsetting the power well on haswell only disable the pfit if
  4785. * it's in use. The hw state code will make sure we get this right. */
  4786. if (force || crtc->config->pch_pfit.enabled) {
  4787. I915_WRITE(PF_CTL(pipe), 0);
  4788. I915_WRITE(PF_WIN_POS(pipe), 0);
  4789. I915_WRITE(PF_WIN_SZ(pipe), 0);
  4790. }
  4791. }
  4792. static void ironlake_crtc_disable(struct intel_crtc_state *old_crtc_state,
  4793. struct drm_atomic_state *old_state)
  4794. {
  4795. struct drm_crtc *crtc = old_crtc_state->base.crtc;
  4796. struct drm_device *dev = crtc->dev;
  4797. struct drm_i915_private *dev_priv = to_i915(dev);
  4798. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4799. int pipe = intel_crtc->pipe;
  4800. /*
  4801. * Sometimes spurious CPU pipe underruns happen when the
  4802. * pipe is already disabled, but FDI RX/TX is still enabled.
  4803. * Happens at least with VGA+HDMI cloning. Suppress them.
  4804. */
  4805. if (intel_crtc->config->has_pch_encoder) {
  4806. intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
  4807. intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
  4808. }
  4809. intel_encoders_disable(crtc, old_crtc_state, old_state);
  4810. drm_crtc_vblank_off(crtc);
  4811. assert_vblank_disabled(crtc);
  4812. intel_disable_pipe(old_crtc_state);
  4813. ironlake_pfit_disable(intel_crtc, false);
  4814. if (intel_crtc->config->has_pch_encoder)
  4815. ironlake_fdi_disable(crtc);
  4816. intel_encoders_post_disable(crtc, old_crtc_state, old_state);
  4817. if (intel_crtc->config->has_pch_encoder) {
  4818. ironlake_disable_pch_transcoder(dev_priv, pipe);
  4819. if (HAS_PCH_CPT(dev_priv)) {
  4820. i915_reg_t reg;
  4821. u32 temp;
  4822. /* disable TRANS_DP_CTL */
  4823. reg = TRANS_DP_CTL(pipe);
  4824. temp = I915_READ(reg);
  4825. temp &= ~(TRANS_DP_OUTPUT_ENABLE |
  4826. TRANS_DP_PORT_SEL_MASK);
  4827. temp |= TRANS_DP_PORT_SEL_NONE;
  4828. I915_WRITE(reg, temp);
  4829. /* disable DPLL_SEL */
  4830. temp = I915_READ(PCH_DPLL_SEL);
  4831. temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe));
  4832. I915_WRITE(PCH_DPLL_SEL, temp);
  4833. }
  4834. ironlake_fdi_pll_disable(intel_crtc);
  4835. }
  4836. intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
  4837. intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
  4838. }
  4839. static void haswell_crtc_disable(struct intel_crtc_state *old_crtc_state,
  4840. struct drm_atomic_state *old_state)
  4841. {
  4842. struct drm_crtc *crtc = old_crtc_state->base.crtc;
  4843. struct drm_i915_private *dev_priv = to_i915(crtc->dev);
  4844. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4845. enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
  4846. intel_encoders_disable(crtc, old_crtc_state, old_state);
  4847. drm_crtc_vblank_off(crtc);
  4848. assert_vblank_disabled(crtc);
  4849. /* XXX: Do the pipe assertions at the right place for BXT DSI. */
  4850. if (!transcoder_is_dsi(cpu_transcoder))
  4851. intel_disable_pipe(old_crtc_state);
  4852. if (intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_DP_MST))
  4853. intel_ddi_set_vc_payload_alloc(intel_crtc->config, false);
  4854. if (!transcoder_is_dsi(cpu_transcoder))
  4855. intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder);
  4856. if (INTEL_GEN(dev_priv) >= 9)
  4857. skylake_scaler_disable(intel_crtc);
  4858. else
  4859. ironlake_pfit_disable(intel_crtc, false);
  4860. if (!transcoder_is_dsi(cpu_transcoder))
  4861. intel_ddi_disable_pipe_clock(intel_crtc->config);
  4862. intel_encoders_post_disable(crtc, old_crtc_state, old_state);
  4863. }
  4864. static void i9xx_pfit_enable(struct intel_crtc *crtc)
  4865. {
  4866. struct drm_device *dev = crtc->base.dev;
  4867. struct drm_i915_private *dev_priv = to_i915(dev);
  4868. struct intel_crtc_state *pipe_config = crtc->config;
  4869. if (!pipe_config->gmch_pfit.control)
  4870. return;
  4871. /*
  4872. * The panel fitter should only be adjusted whilst the pipe is disabled,
  4873. * according to register description and PRM.
  4874. */
  4875. WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE);
  4876. assert_pipe_disabled(dev_priv, crtc->pipe);
  4877. I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios);
  4878. I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control);
  4879. /* Border color in case we don't scale up to the full screen. Black by
  4880. * default, change to something else for debugging. */
  4881. I915_WRITE(BCLRPAT(crtc->pipe), 0);
  4882. }
  4883. enum intel_display_power_domain intel_port_to_power_domain(enum port port)
  4884. {
  4885. switch (port) {
  4886. case PORT_A:
  4887. return POWER_DOMAIN_PORT_DDI_A_LANES;
  4888. case PORT_B:
  4889. return POWER_DOMAIN_PORT_DDI_B_LANES;
  4890. case PORT_C:
  4891. return POWER_DOMAIN_PORT_DDI_C_LANES;
  4892. case PORT_D:
  4893. return POWER_DOMAIN_PORT_DDI_D_LANES;
  4894. case PORT_E:
  4895. return POWER_DOMAIN_PORT_DDI_E_LANES;
  4896. case PORT_F:
  4897. return POWER_DOMAIN_PORT_DDI_F_LANES;
  4898. default:
  4899. MISSING_CASE(port);
  4900. return POWER_DOMAIN_PORT_OTHER;
  4901. }
  4902. }
  4903. static u64 get_crtc_power_domains(struct drm_crtc *crtc,
  4904. struct intel_crtc_state *crtc_state)
  4905. {
  4906. struct drm_device *dev = crtc->dev;
  4907. struct drm_i915_private *dev_priv = to_i915(dev);
  4908. struct drm_encoder *encoder;
  4909. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4910. enum pipe pipe = intel_crtc->pipe;
  4911. u64 mask;
  4912. enum transcoder transcoder = crtc_state->cpu_transcoder;
  4913. if (!crtc_state->base.active)
  4914. return 0;
  4915. mask = BIT_ULL(POWER_DOMAIN_PIPE(pipe));
  4916. mask |= BIT_ULL(POWER_DOMAIN_TRANSCODER(transcoder));
  4917. if (crtc_state->pch_pfit.enabled ||
  4918. crtc_state->pch_pfit.force_thru)
  4919. mask |= BIT_ULL(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe));
  4920. drm_for_each_encoder_mask(encoder, dev, crtc_state->base.encoder_mask) {
  4921. struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
  4922. mask |= BIT_ULL(intel_encoder->power_domain);
  4923. }
  4924. if (HAS_DDI(dev_priv) && crtc_state->has_audio)
  4925. mask |= BIT_ULL(POWER_DOMAIN_AUDIO);
  4926. if (crtc_state->shared_dpll)
  4927. mask |= BIT_ULL(POWER_DOMAIN_PLLS);
  4928. return mask;
  4929. }
  4930. static u64
  4931. modeset_get_crtc_power_domains(struct drm_crtc *crtc,
  4932. struct intel_crtc_state *crtc_state)
  4933. {
  4934. struct drm_i915_private *dev_priv = to_i915(crtc->dev);
  4935. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4936. enum intel_display_power_domain domain;
  4937. u64 domains, new_domains, old_domains;
  4938. old_domains = intel_crtc->enabled_power_domains;
  4939. intel_crtc->enabled_power_domains = new_domains =
  4940. get_crtc_power_domains(crtc, crtc_state);
  4941. domains = new_domains & ~old_domains;
  4942. for_each_power_domain(domain, domains)
  4943. intel_display_power_get(dev_priv, domain);
  4944. return old_domains & ~new_domains;
  4945. }
  4946. static void modeset_put_power_domains(struct drm_i915_private *dev_priv,
  4947. u64 domains)
  4948. {
  4949. enum intel_display_power_domain domain;
  4950. for_each_power_domain(domain, domains)
  4951. intel_display_power_put(dev_priv, domain);
  4952. }
  4953. static void valleyview_crtc_enable(struct intel_crtc_state *pipe_config,
  4954. struct drm_atomic_state *old_state)
  4955. {
  4956. struct intel_atomic_state *old_intel_state =
  4957. to_intel_atomic_state(old_state);
  4958. struct drm_crtc *crtc = pipe_config->base.crtc;
  4959. struct drm_device *dev = crtc->dev;
  4960. struct drm_i915_private *dev_priv = to_i915(dev);
  4961. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4962. int pipe = intel_crtc->pipe;
  4963. if (WARN_ON(intel_crtc->active))
  4964. return;
  4965. if (intel_crtc_has_dp_encoder(intel_crtc->config))
  4966. intel_dp_set_m_n(intel_crtc, M1_N1);
  4967. intel_set_pipe_timings(intel_crtc);
  4968. intel_set_pipe_src_size(intel_crtc);
  4969. if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
  4970. struct drm_i915_private *dev_priv = to_i915(dev);
  4971. I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY);
  4972. I915_WRITE(CHV_CANVAS(pipe), 0);
  4973. }
  4974. i9xx_set_pipeconf(intel_crtc);
  4975. intel_crtc->active = true;
  4976. intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
  4977. intel_encoders_pre_pll_enable(crtc, pipe_config, old_state);
  4978. if (IS_CHERRYVIEW(dev_priv)) {
  4979. chv_prepare_pll(intel_crtc, intel_crtc->config);
  4980. chv_enable_pll(intel_crtc, intel_crtc->config);
  4981. } else {
  4982. vlv_prepare_pll(intel_crtc, intel_crtc->config);
  4983. vlv_enable_pll(intel_crtc, intel_crtc->config);
  4984. }
  4985. intel_encoders_pre_enable(crtc, pipe_config, old_state);
  4986. i9xx_pfit_enable(intel_crtc);
  4987. intel_color_load_luts(&pipe_config->base);
  4988. dev_priv->display.initial_watermarks(old_intel_state,
  4989. pipe_config);
  4990. intel_enable_pipe(pipe_config);
  4991. assert_vblank_disabled(crtc);
  4992. drm_crtc_vblank_on(crtc);
  4993. intel_encoders_enable(crtc, pipe_config, old_state);
  4994. }
  4995. static void i9xx_set_pll_dividers(struct intel_crtc *crtc)
  4996. {
  4997. struct drm_device *dev = crtc->base.dev;
  4998. struct drm_i915_private *dev_priv = to_i915(dev);
  4999. I915_WRITE(FP0(crtc->pipe), crtc->config->dpll_hw_state.fp0);
  5000. I915_WRITE(FP1(crtc->pipe), crtc->config->dpll_hw_state.fp1);
  5001. }
  5002. static void i9xx_crtc_enable(struct intel_crtc_state *pipe_config,
  5003. struct drm_atomic_state *old_state)
  5004. {
  5005. struct intel_atomic_state *old_intel_state =
  5006. to_intel_atomic_state(old_state);
  5007. struct drm_crtc *crtc = pipe_config->base.crtc;
  5008. struct drm_device *dev = crtc->dev;
  5009. struct drm_i915_private *dev_priv = to_i915(dev);
  5010. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5011. enum pipe pipe = intel_crtc->pipe;
  5012. if (WARN_ON(intel_crtc->active))
  5013. return;
  5014. i9xx_set_pll_dividers(intel_crtc);
  5015. if (intel_crtc_has_dp_encoder(intel_crtc->config))
  5016. intel_dp_set_m_n(intel_crtc, M1_N1);
  5017. intel_set_pipe_timings(intel_crtc);
  5018. intel_set_pipe_src_size(intel_crtc);
  5019. i9xx_set_pipeconf(intel_crtc);
  5020. intel_crtc->active = true;
  5021. if (!IS_GEN2(dev_priv))
  5022. intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
  5023. intel_encoders_pre_enable(crtc, pipe_config, old_state);
  5024. i9xx_enable_pll(intel_crtc, pipe_config);
  5025. i9xx_pfit_enable(intel_crtc);
  5026. intel_color_load_luts(&pipe_config->base);
  5027. if (dev_priv->display.initial_watermarks != NULL)
  5028. dev_priv->display.initial_watermarks(old_intel_state,
  5029. intel_crtc->config);
  5030. else
  5031. intel_update_watermarks(intel_crtc);
  5032. intel_enable_pipe(pipe_config);
  5033. assert_vblank_disabled(crtc);
  5034. drm_crtc_vblank_on(crtc);
  5035. intel_encoders_enable(crtc, pipe_config, old_state);
  5036. }
  5037. static void i9xx_pfit_disable(struct intel_crtc *crtc)
  5038. {
  5039. struct drm_device *dev = crtc->base.dev;
  5040. struct drm_i915_private *dev_priv = to_i915(dev);
  5041. if (!crtc->config->gmch_pfit.control)
  5042. return;
  5043. assert_pipe_disabled(dev_priv, crtc->pipe);
  5044. DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n",
  5045. I915_READ(PFIT_CONTROL));
  5046. I915_WRITE(PFIT_CONTROL, 0);
  5047. }
  5048. static void i9xx_crtc_disable(struct intel_crtc_state *old_crtc_state,
  5049. struct drm_atomic_state *old_state)
  5050. {
  5051. struct drm_crtc *crtc = old_crtc_state->base.crtc;
  5052. struct drm_device *dev = crtc->dev;
  5053. struct drm_i915_private *dev_priv = to_i915(dev);
  5054. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5055. int pipe = intel_crtc->pipe;
  5056. /*
  5057. * On gen2 planes are double buffered but the pipe isn't, so we must
  5058. * wait for planes to fully turn off before disabling the pipe.
  5059. */
  5060. if (IS_GEN2(dev_priv))
  5061. intel_wait_for_vblank(dev_priv, pipe);
  5062. intel_encoders_disable(crtc, old_crtc_state, old_state);
  5063. drm_crtc_vblank_off(crtc);
  5064. assert_vblank_disabled(crtc);
  5065. intel_disable_pipe(old_crtc_state);
  5066. i9xx_pfit_disable(intel_crtc);
  5067. intel_encoders_post_disable(crtc, old_crtc_state, old_state);
  5068. if (!intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_DSI)) {
  5069. if (IS_CHERRYVIEW(dev_priv))
  5070. chv_disable_pll(dev_priv, pipe);
  5071. else if (IS_VALLEYVIEW(dev_priv))
  5072. vlv_disable_pll(dev_priv, pipe);
  5073. else
  5074. i9xx_disable_pll(intel_crtc);
  5075. }
  5076. intel_encoders_post_pll_disable(crtc, old_crtc_state, old_state);
  5077. if (!IS_GEN2(dev_priv))
  5078. intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
  5079. if (!dev_priv->display.initial_watermarks)
  5080. intel_update_watermarks(intel_crtc);
  5081. /* clock the pipe down to 640x480@60 to potentially save power */
  5082. if (IS_I830(dev_priv))
  5083. i830_enable_pipe(dev_priv, pipe);
  5084. }
  5085. static void intel_crtc_disable_noatomic(struct drm_crtc *crtc,
  5086. struct drm_modeset_acquire_ctx *ctx)
  5087. {
  5088. struct intel_encoder *encoder;
  5089. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5090. struct drm_i915_private *dev_priv = to_i915(crtc->dev);
  5091. enum intel_display_power_domain domain;
  5092. struct intel_plane *plane;
  5093. u64 domains;
  5094. struct drm_atomic_state *state;
  5095. struct intel_crtc_state *crtc_state;
  5096. int ret;
  5097. if (!intel_crtc->active)
  5098. return;
  5099. for_each_intel_plane_on_crtc(&dev_priv->drm, intel_crtc, plane) {
  5100. const struct intel_plane_state *plane_state =
  5101. to_intel_plane_state(plane->base.state);
  5102. if (plane_state->base.visible)
  5103. intel_plane_disable_noatomic(intel_crtc, plane);
  5104. }
  5105. state = drm_atomic_state_alloc(crtc->dev);
  5106. if (!state) {
  5107. DRM_DEBUG_KMS("failed to disable [CRTC:%d:%s], out of memory",
  5108. crtc->base.id, crtc->name);
  5109. return;
  5110. }
  5111. state->acquire_ctx = ctx;
  5112. /* Everything's already locked, -EDEADLK can't happen. */
  5113. crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
  5114. ret = drm_atomic_add_affected_connectors(state, crtc);
  5115. WARN_ON(IS_ERR(crtc_state) || ret);
  5116. dev_priv->display.crtc_disable(crtc_state, state);
  5117. drm_atomic_state_put(state);
  5118. DRM_DEBUG_KMS("[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n",
  5119. crtc->base.id, crtc->name);
  5120. WARN_ON(drm_atomic_set_mode_for_crtc(crtc->state, NULL) < 0);
  5121. crtc->state->active = false;
  5122. intel_crtc->active = false;
  5123. crtc->enabled = false;
  5124. crtc->state->connector_mask = 0;
  5125. crtc->state->encoder_mask = 0;
  5126. for_each_encoder_on_crtc(crtc->dev, crtc, encoder)
  5127. encoder->base.crtc = NULL;
  5128. intel_fbc_disable(intel_crtc);
  5129. intel_update_watermarks(intel_crtc);
  5130. intel_disable_shared_dpll(intel_crtc);
  5131. domains = intel_crtc->enabled_power_domains;
  5132. for_each_power_domain(domain, domains)
  5133. intel_display_power_put(dev_priv, domain);
  5134. intel_crtc->enabled_power_domains = 0;
  5135. dev_priv->active_crtcs &= ~(1 << intel_crtc->pipe);
  5136. dev_priv->min_cdclk[intel_crtc->pipe] = 0;
  5137. dev_priv->min_voltage_level[intel_crtc->pipe] = 0;
  5138. }
  5139. /*
  5140. * turn all crtc's off, but do not adjust state
  5141. * This has to be paired with a call to intel_modeset_setup_hw_state.
  5142. */
  5143. int intel_display_suspend(struct drm_device *dev)
  5144. {
  5145. struct drm_i915_private *dev_priv = to_i915(dev);
  5146. struct drm_atomic_state *state;
  5147. int ret;
  5148. state = drm_atomic_helper_suspend(dev);
  5149. ret = PTR_ERR_OR_ZERO(state);
  5150. if (ret)
  5151. DRM_ERROR("Suspending crtc's failed with %i\n", ret);
  5152. else
  5153. dev_priv->modeset_restore_state = state;
  5154. return ret;
  5155. }
  5156. void intel_encoder_destroy(struct drm_encoder *encoder)
  5157. {
  5158. struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
  5159. drm_encoder_cleanup(encoder);
  5160. kfree(intel_encoder);
  5161. }
  5162. /* Cross check the actual hw state with our own modeset state tracking (and it's
  5163. * internal consistency). */
  5164. static void intel_connector_verify_state(struct drm_crtc_state *crtc_state,
  5165. struct drm_connector_state *conn_state)
  5166. {
  5167. struct intel_connector *connector = to_intel_connector(conn_state->connector);
  5168. DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
  5169. connector->base.base.id,
  5170. connector->base.name);
  5171. if (connector->get_hw_state(connector)) {
  5172. struct intel_encoder *encoder = connector->encoder;
  5173. I915_STATE_WARN(!crtc_state,
  5174. "connector enabled without attached crtc\n");
  5175. if (!crtc_state)
  5176. return;
  5177. I915_STATE_WARN(!crtc_state->active,
  5178. "connector is active, but attached crtc isn't\n");
  5179. if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST)
  5180. return;
  5181. I915_STATE_WARN(conn_state->best_encoder != &encoder->base,
  5182. "atomic encoder doesn't match attached encoder\n");
  5183. I915_STATE_WARN(conn_state->crtc != encoder->base.crtc,
  5184. "attached encoder crtc differs from connector crtc\n");
  5185. } else {
  5186. I915_STATE_WARN(crtc_state && crtc_state->active,
  5187. "attached crtc is active, but connector isn't\n");
  5188. I915_STATE_WARN(!crtc_state && conn_state->best_encoder,
  5189. "best encoder set without crtc!\n");
  5190. }
  5191. }
  5192. int intel_connector_init(struct intel_connector *connector)
  5193. {
  5194. struct intel_digital_connector_state *conn_state;
  5195. /*
  5196. * Allocate enough memory to hold intel_digital_connector_state,
  5197. * This might be a few bytes too many, but for connectors that don't
  5198. * need it we'll free the state and allocate a smaller one on the first
  5199. * succesful commit anyway.
  5200. */
  5201. conn_state = kzalloc(sizeof(*conn_state), GFP_KERNEL);
  5202. if (!conn_state)
  5203. return -ENOMEM;
  5204. __drm_atomic_helper_connector_reset(&connector->base,
  5205. &conn_state->base);
  5206. return 0;
  5207. }
  5208. struct intel_connector *intel_connector_alloc(void)
  5209. {
  5210. struct intel_connector *connector;
  5211. connector = kzalloc(sizeof *connector, GFP_KERNEL);
  5212. if (!connector)
  5213. return NULL;
  5214. if (intel_connector_init(connector) < 0) {
  5215. kfree(connector);
  5216. return NULL;
  5217. }
  5218. return connector;
  5219. }
  5220. /*
  5221. * Free the bits allocated by intel_connector_alloc.
  5222. * This should only be used after intel_connector_alloc has returned
  5223. * successfully, and before drm_connector_init returns successfully.
  5224. * Otherwise the destroy callbacks for the connector and the state should
  5225. * take care of proper cleanup/free
  5226. */
  5227. void intel_connector_free(struct intel_connector *connector)
  5228. {
  5229. kfree(to_intel_digital_connector_state(connector->base.state));
  5230. kfree(connector);
  5231. }
  5232. /* Simple connector->get_hw_state implementation for encoders that support only
  5233. * one connector and no cloning and hence the encoder state determines the state
  5234. * of the connector. */
  5235. bool intel_connector_get_hw_state(struct intel_connector *connector)
  5236. {
  5237. enum pipe pipe = 0;
  5238. struct intel_encoder *encoder = connector->encoder;
  5239. return encoder->get_hw_state(encoder, &pipe);
  5240. }
  5241. static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state)
  5242. {
  5243. if (crtc_state->base.enable && crtc_state->has_pch_encoder)
  5244. return crtc_state->fdi_lanes;
  5245. return 0;
  5246. }
  5247. static int ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe,
  5248. struct intel_crtc_state *pipe_config)
  5249. {
  5250. struct drm_i915_private *dev_priv = to_i915(dev);
  5251. struct drm_atomic_state *state = pipe_config->base.state;
  5252. struct intel_crtc *other_crtc;
  5253. struct intel_crtc_state *other_crtc_state;
  5254. DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
  5255. pipe_name(pipe), pipe_config->fdi_lanes);
  5256. if (pipe_config->fdi_lanes > 4) {
  5257. DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
  5258. pipe_name(pipe), pipe_config->fdi_lanes);
  5259. return -EINVAL;
  5260. }
  5261. if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
  5262. if (pipe_config->fdi_lanes > 2) {
  5263. DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
  5264. pipe_config->fdi_lanes);
  5265. return -EINVAL;
  5266. } else {
  5267. return 0;
  5268. }
  5269. }
  5270. if (INTEL_INFO(dev_priv)->num_pipes == 2)
  5271. return 0;
  5272. /* Ivybridge 3 pipe is really complicated */
  5273. switch (pipe) {
  5274. case PIPE_A:
  5275. return 0;
  5276. case PIPE_B:
  5277. if (pipe_config->fdi_lanes <= 2)
  5278. return 0;
  5279. other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_C);
  5280. other_crtc_state =
  5281. intel_atomic_get_crtc_state(state, other_crtc);
  5282. if (IS_ERR(other_crtc_state))
  5283. return PTR_ERR(other_crtc_state);
  5284. if (pipe_required_fdi_lanes(other_crtc_state) > 0) {
  5285. DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
  5286. pipe_name(pipe), pipe_config->fdi_lanes);
  5287. return -EINVAL;
  5288. }
  5289. return 0;
  5290. case PIPE_C:
  5291. if (pipe_config->fdi_lanes > 2) {
  5292. DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n",
  5293. pipe_name(pipe), pipe_config->fdi_lanes);
  5294. return -EINVAL;
  5295. }
  5296. other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_B);
  5297. other_crtc_state =
  5298. intel_atomic_get_crtc_state(state, other_crtc);
  5299. if (IS_ERR(other_crtc_state))
  5300. return PTR_ERR(other_crtc_state);
  5301. if (pipe_required_fdi_lanes(other_crtc_state) > 2) {
  5302. DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
  5303. return -EINVAL;
  5304. }
  5305. return 0;
  5306. default:
  5307. BUG();
  5308. }
  5309. }
  5310. #define RETRY 1
  5311. static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc,
  5312. struct intel_crtc_state *pipe_config)
  5313. {
  5314. struct drm_device *dev = intel_crtc->base.dev;
  5315. const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
  5316. int lane, link_bw, fdi_dotclock, ret;
  5317. bool needs_recompute = false;
  5318. retry:
  5319. /* FDI is a binary signal running at ~2.7GHz, encoding
  5320. * each output octet as 10 bits. The actual frequency
  5321. * is stored as a divider into a 100MHz clock, and the
  5322. * mode pixel clock is stored in units of 1KHz.
  5323. * Hence the bw of each lane in terms of the mode signal
  5324. * is:
  5325. */
  5326. link_bw = intel_fdi_link_freq(to_i915(dev), pipe_config);
  5327. fdi_dotclock = adjusted_mode->crtc_clock;
  5328. lane = ironlake_get_lanes_required(fdi_dotclock, link_bw,
  5329. pipe_config->pipe_bpp);
  5330. pipe_config->fdi_lanes = lane;
  5331. intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock,
  5332. link_bw, &pipe_config->fdi_m_n, false);
  5333. ret = ironlake_check_fdi_lanes(dev, intel_crtc->pipe, pipe_config);
  5334. if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) {
  5335. pipe_config->pipe_bpp -= 2*3;
  5336. DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
  5337. pipe_config->pipe_bpp);
  5338. needs_recompute = true;
  5339. pipe_config->bw_constrained = true;
  5340. goto retry;
  5341. }
  5342. if (needs_recompute)
  5343. return RETRY;
  5344. return ret;
  5345. }
  5346. bool hsw_crtc_state_ips_capable(const struct intel_crtc_state *crtc_state)
  5347. {
  5348. struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
  5349. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  5350. /* IPS only exists on ULT machines and is tied to pipe A. */
  5351. if (!hsw_crtc_supports_ips(crtc))
  5352. return false;
  5353. if (!i915_modparams.enable_ips)
  5354. return false;
  5355. if (crtc_state->pipe_bpp > 24)
  5356. return false;
  5357. /*
  5358. * We compare against max which means we must take
  5359. * the increased cdclk requirement into account when
  5360. * calculating the new cdclk.
  5361. *
  5362. * Should measure whether using a lower cdclk w/o IPS
  5363. */
  5364. if (IS_BROADWELL(dev_priv) &&
  5365. crtc_state->pixel_rate > dev_priv->max_cdclk_freq * 95 / 100)
  5366. return false;
  5367. return true;
  5368. }
  5369. static bool hsw_compute_ips_config(struct intel_crtc_state *crtc_state)
  5370. {
  5371. struct drm_i915_private *dev_priv =
  5372. to_i915(crtc_state->base.crtc->dev);
  5373. struct intel_atomic_state *intel_state =
  5374. to_intel_atomic_state(crtc_state->base.state);
  5375. if (!hsw_crtc_state_ips_capable(crtc_state))
  5376. return false;
  5377. if (crtc_state->ips_force_disable)
  5378. return false;
  5379. /* IPS should be fine as long as at least one plane is enabled. */
  5380. if (!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)))
  5381. return false;
  5382. /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
  5383. if (IS_BROADWELL(dev_priv) &&
  5384. crtc_state->pixel_rate > intel_state->cdclk.logical.cdclk * 95 / 100)
  5385. return false;
  5386. return true;
  5387. }
  5388. static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc)
  5389. {
  5390. const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  5391. /* GDG double wide on either pipe, otherwise pipe A only */
  5392. return INTEL_GEN(dev_priv) < 4 &&
  5393. (crtc->pipe == PIPE_A || IS_I915G(dev_priv));
  5394. }
  5395. static uint32_t ilk_pipe_pixel_rate(const struct intel_crtc_state *pipe_config)
  5396. {
  5397. uint32_t pixel_rate;
  5398. pixel_rate = pipe_config->base.adjusted_mode.crtc_clock;
  5399. /*
  5400. * We only use IF-ID interlacing. If we ever use
  5401. * PF-ID we'll need to adjust the pixel_rate here.
  5402. */
  5403. if (pipe_config->pch_pfit.enabled) {
  5404. uint64_t pipe_w, pipe_h, pfit_w, pfit_h;
  5405. uint32_t pfit_size = pipe_config->pch_pfit.size;
  5406. pipe_w = pipe_config->pipe_src_w;
  5407. pipe_h = pipe_config->pipe_src_h;
  5408. pfit_w = (pfit_size >> 16) & 0xFFFF;
  5409. pfit_h = pfit_size & 0xFFFF;
  5410. if (pipe_w < pfit_w)
  5411. pipe_w = pfit_w;
  5412. if (pipe_h < pfit_h)
  5413. pipe_h = pfit_h;
  5414. if (WARN_ON(!pfit_w || !pfit_h))
  5415. return pixel_rate;
  5416. pixel_rate = div_u64((uint64_t) pixel_rate * pipe_w * pipe_h,
  5417. pfit_w * pfit_h);
  5418. }
  5419. return pixel_rate;
  5420. }
  5421. static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state)
  5422. {
  5423. struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
  5424. if (HAS_GMCH_DISPLAY(dev_priv))
  5425. /* FIXME calculate proper pipe pixel rate for GMCH pfit */
  5426. crtc_state->pixel_rate =
  5427. crtc_state->base.adjusted_mode.crtc_clock;
  5428. else
  5429. crtc_state->pixel_rate =
  5430. ilk_pipe_pixel_rate(crtc_state);
  5431. }
  5432. static int intel_crtc_compute_config(struct intel_crtc *crtc,
  5433. struct intel_crtc_state *pipe_config)
  5434. {
  5435. struct drm_device *dev = crtc->base.dev;
  5436. struct drm_i915_private *dev_priv = to_i915(dev);
  5437. const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
  5438. int clock_limit = dev_priv->max_dotclk_freq;
  5439. if (INTEL_GEN(dev_priv) < 4) {
  5440. clock_limit = dev_priv->max_cdclk_freq * 9 / 10;
  5441. /*
  5442. * Enable double wide mode when the dot clock
  5443. * is > 90% of the (display) core speed.
  5444. */
  5445. if (intel_crtc_supports_double_wide(crtc) &&
  5446. adjusted_mode->crtc_clock > clock_limit) {
  5447. clock_limit = dev_priv->max_dotclk_freq;
  5448. pipe_config->double_wide = true;
  5449. }
  5450. }
  5451. if (adjusted_mode->crtc_clock > clock_limit) {
  5452. DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
  5453. adjusted_mode->crtc_clock, clock_limit,
  5454. yesno(pipe_config->double_wide));
  5455. return -EINVAL;
  5456. }
  5457. if (pipe_config->ycbcr420 && pipe_config->base.ctm) {
  5458. /*
  5459. * There is only one pipe CSC unit per pipe, and we need that
  5460. * for output conversion from RGB->YCBCR. So if CTM is already
  5461. * applied we can't support YCBCR420 output.
  5462. */
  5463. DRM_DEBUG_KMS("YCBCR420 and CTM together are not possible\n");
  5464. return -EINVAL;
  5465. }
  5466. /*
  5467. * Pipe horizontal size must be even in:
  5468. * - DVO ganged mode
  5469. * - LVDS dual channel mode
  5470. * - Double wide pipe
  5471. */
  5472. if (pipe_config->pipe_src_w & 1) {
  5473. if (pipe_config->double_wide) {
  5474. DRM_DEBUG_KMS("Odd pipe source width not supported with double wide pipe\n");
  5475. return -EINVAL;
  5476. }
  5477. if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_LVDS) &&
  5478. intel_is_dual_link_lvds(dev)) {
  5479. DRM_DEBUG_KMS("Odd pipe source width not supported with dual link LVDS\n");
  5480. return -EINVAL;
  5481. }
  5482. }
  5483. /* Cantiga+ cannot handle modes with a hsync front porch of 0.
  5484. * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
  5485. */
  5486. if ((INTEL_GEN(dev_priv) > 4 || IS_G4X(dev_priv)) &&
  5487. adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay)
  5488. return -EINVAL;
  5489. intel_crtc_compute_pixel_rate(pipe_config);
  5490. if (pipe_config->has_pch_encoder)
  5491. return ironlake_fdi_compute_config(crtc, pipe_config);
  5492. return 0;
  5493. }
  5494. static void
  5495. intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den)
  5496. {
  5497. while (*num > DATA_LINK_M_N_MASK ||
  5498. *den > DATA_LINK_M_N_MASK) {
  5499. *num >>= 1;
  5500. *den >>= 1;
  5501. }
  5502. }
  5503. static void compute_m_n(unsigned int m, unsigned int n,
  5504. uint32_t *ret_m, uint32_t *ret_n,
  5505. bool reduce_m_n)
  5506. {
  5507. /*
  5508. * Reduce M/N as much as possible without loss in precision. Several DP
  5509. * dongles in particular seem to be fussy about too large *link* M/N
  5510. * values. The passed in values are more likely to have the least
  5511. * significant bits zero than M after rounding below, so do this first.
  5512. */
  5513. if (reduce_m_n) {
  5514. while ((m & 1) == 0 && (n & 1) == 0) {
  5515. m >>= 1;
  5516. n >>= 1;
  5517. }
  5518. }
  5519. *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
  5520. *ret_m = div_u64((uint64_t) m * *ret_n, n);
  5521. intel_reduce_m_n_ratio(ret_m, ret_n);
  5522. }
  5523. void
  5524. intel_link_compute_m_n(int bits_per_pixel, int nlanes,
  5525. int pixel_clock, int link_clock,
  5526. struct intel_link_m_n *m_n,
  5527. bool reduce_m_n)
  5528. {
  5529. m_n->tu = 64;
  5530. compute_m_n(bits_per_pixel * pixel_clock,
  5531. link_clock * nlanes * 8,
  5532. &m_n->gmch_m, &m_n->gmch_n,
  5533. reduce_m_n);
  5534. compute_m_n(pixel_clock, link_clock,
  5535. &m_n->link_m, &m_n->link_n,
  5536. reduce_m_n);
  5537. }
  5538. static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
  5539. {
  5540. if (i915_modparams.panel_use_ssc >= 0)
  5541. return i915_modparams.panel_use_ssc != 0;
  5542. return dev_priv->vbt.lvds_use_ssc
  5543. && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
  5544. }
  5545. static uint32_t pnv_dpll_compute_fp(struct dpll *dpll)
  5546. {
  5547. return (1 << dpll->n) << 16 | dpll->m2;
  5548. }
  5549. static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll)
  5550. {
  5551. return dpll->n << 16 | dpll->m1 << 8 | dpll->m2;
  5552. }
  5553. static void i9xx_update_pll_dividers(struct intel_crtc *crtc,
  5554. struct intel_crtc_state *crtc_state,
  5555. struct dpll *reduced_clock)
  5556. {
  5557. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  5558. u32 fp, fp2 = 0;
  5559. if (IS_PINEVIEW(dev_priv)) {
  5560. fp = pnv_dpll_compute_fp(&crtc_state->dpll);
  5561. if (reduced_clock)
  5562. fp2 = pnv_dpll_compute_fp(reduced_clock);
  5563. } else {
  5564. fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
  5565. if (reduced_clock)
  5566. fp2 = i9xx_dpll_compute_fp(reduced_clock);
  5567. }
  5568. crtc_state->dpll_hw_state.fp0 = fp;
  5569. if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
  5570. reduced_clock) {
  5571. crtc_state->dpll_hw_state.fp1 = fp2;
  5572. } else {
  5573. crtc_state->dpll_hw_state.fp1 = fp;
  5574. }
  5575. }
  5576. static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe
  5577. pipe)
  5578. {
  5579. u32 reg_val;
  5580. /*
  5581. * PLLB opamp always calibrates to max value of 0x3f, force enable it
  5582. * and set it to a reasonable value instead.
  5583. */
  5584. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
  5585. reg_val &= 0xffffff00;
  5586. reg_val |= 0x00000030;
  5587. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
  5588. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
  5589. reg_val &= 0x00ffffff;
  5590. reg_val |= 0x8c000000;
  5591. vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
  5592. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
  5593. reg_val &= 0xffffff00;
  5594. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
  5595. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
  5596. reg_val &= 0x00ffffff;
  5597. reg_val |= 0xb0000000;
  5598. vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
  5599. }
  5600. static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc,
  5601. struct intel_link_m_n *m_n)
  5602. {
  5603. struct drm_device *dev = crtc->base.dev;
  5604. struct drm_i915_private *dev_priv = to_i915(dev);
  5605. int pipe = crtc->pipe;
  5606. I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
  5607. I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n);
  5608. I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m);
  5609. I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n);
  5610. }
  5611. static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc,
  5612. struct intel_link_m_n *m_n,
  5613. struct intel_link_m_n *m2_n2)
  5614. {
  5615. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  5616. int pipe = crtc->pipe;
  5617. enum transcoder transcoder = crtc->config->cpu_transcoder;
  5618. if (INTEL_GEN(dev_priv) >= 5) {
  5619. I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m);
  5620. I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n);
  5621. I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m);
  5622. I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n);
  5623. /* M2_N2 registers to be set only for gen < 8 (M2_N2 available
  5624. * for gen < 8) and if DRRS is supported (to make sure the
  5625. * registers are not unnecessarily accessed).
  5626. */
  5627. if (m2_n2 && (IS_CHERRYVIEW(dev_priv) ||
  5628. INTEL_GEN(dev_priv) < 8) && crtc->config->has_drrs) {
  5629. I915_WRITE(PIPE_DATA_M2(transcoder),
  5630. TU_SIZE(m2_n2->tu) | m2_n2->gmch_m);
  5631. I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n);
  5632. I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m);
  5633. I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n);
  5634. }
  5635. } else {
  5636. I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
  5637. I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n);
  5638. I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m);
  5639. I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n);
  5640. }
  5641. }
  5642. void intel_dp_set_m_n(struct intel_crtc *crtc, enum link_m_n_set m_n)
  5643. {
  5644. struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL;
  5645. if (m_n == M1_N1) {
  5646. dp_m_n = &crtc->config->dp_m_n;
  5647. dp_m2_n2 = &crtc->config->dp_m2_n2;
  5648. } else if (m_n == M2_N2) {
  5649. /*
  5650. * M2_N2 registers are not supported. Hence m2_n2 divider value
  5651. * needs to be programmed into M1_N1.
  5652. */
  5653. dp_m_n = &crtc->config->dp_m2_n2;
  5654. } else {
  5655. DRM_ERROR("Unsupported divider value\n");
  5656. return;
  5657. }
  5658. if (crtc->config->has_pch_encoder)
  5659. intel_pch_transcoder_set_m_n(crtc, &crtc->config->dp_m_n);
  5660. else
  5661. intel_cpu_transcoder_set_m_n(crtc, dp_m_n, dp_m2_n2);
  5662. }
  5663. static void vlv_compute_dpll(struct intel_crtc *crtc,
  5664. struct intel_crtc_state *pipe_config)
  5665. {
  5666. pipe_config->dpll_hw_state.dpll = DPLL_INTEGRATED_REF_CLK_VLV |
  5667. DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
  5668. if (crtc->pipe != PIPE_A)
  5669. pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
  5670. /* DPLL not used with DSI, but still need the rest set up */
  5671. if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
  5672. pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE |
  5673. DPLL_EXT_BUFFER_ENABLE_VLV;
  5674. pipe_config->dpll_hw_state.dpll_md =
  5675. (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  5676. }
  5677. static void chv_compute_dpll(struct intel_crtc *crtc,
  5678. struct intel_crtc_state *pipe_config)
  5679. {
  5680. pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV |
  5681. DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
  5682. if (crtc->pipe != PIPE_A)
  5683. pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
  5684. /* DPLL not used with DSI, but still need the rest set up */
  5685. if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
  5686. pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE;
  5687. pipe_config->dpll_hw_state.dpll_md =
  5688. (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  5689. }
  5690. static void vlv_prepare_pll(struct intel_crtc *crtc,
  5691. const struct intel_crtc_state *pipe_config)
  5692. {
  5693. struct drm_device *dev = crtc->base.dev;
  5694. struct drm_i915_private *dev_priv = to_i915(dev);
  5695. enum pipe pipe = crtc->pipe;
  5696. u32 mdiv;
  5697. u32 bestn, bestm1, bestm2, bestp1, bestp2;
  5698. u32 coreclk, reg_val;
  5699. /* Enable Refclk */
  5700. I915_WRITE(DPLL(pipe),
  5701. pipe_config->dpll_hw_state.dpll &
  5702. ~(DPLL_VCO_ENABLE | DPLL_EXT_BUFFER_ENABLE_VLV));
  5703. /* No need to actually set up the DPLL with DSI */
  5704. if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
  5705. return;
  5706. mutex_lock(&dev_priv->sb_lock);
  5707. bestn = pipe_config->dpll.n;
  5708. bestm1 = pipe_config->dpll.m1;
  5709. bestm2 = pipe_config->dpll.m2;
  5710. bestp1 = pipe_config->dpll.p1;
  5711. bestp2 = pipe_config->dpll.p2;
  5712. /* See eDP HDMI DPIO driver vbios notes doc */
  5713. /* PLL B needs special handling */
  5714. if (pipe == PIPE_B)
  5715. vlv_pllb_recal_opamp(dev_priv, pipe);
  5716. /* Set up Tx target for periodic Rcomp update */
  5717. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f);
  5718. /* Disable target IRef on PLL */
  5719. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe));
  5720. reg_val &= 0x00ffffff;
  5721. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val);
  5722. /* Disable fast lock */
  5723. vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610);
  5724. /* Set idtafcrecal before PLL is enabled */
  5725. mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
  5726. mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
  5727. mdiv |= ((bestn << DPIO_N_SHIFT));
  5728. mdiv |= (1 << DPIO_K_SHIFT);
  5729. /*
  5730. * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
  5731. * but we don't support that).
  5732. * Note: don't use the DAC post divider as it seems unstable.
  5733. */
  5734. mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
  5735. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
  5736. mdiv |= DPIO_ENABLE_CALIBRATION;
  5737. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
  5738. /* Set HBR and RBR LPF coefficients */
  5739. if (pipe_config->port_clock == 162000 ||
  5740. intel_crtc_has_type(crtc->config, INTEL_OUTPUT_ANALOG) ||
  5741. intel_crtc_has_type(crtc->config, INTEL_OUTPUT_HDMI))
  5742. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
  5743. 0x009f0003);
  5744. else
  5745. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
  5746. 0x00d0000f);
  5747. if (intel_crtc_has_dp_encoder(pipe_config)) {
  5748. /* Use SSC source */
  5749. if (pipe == PIPE_A)
  5750. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  5751. 0x0df40000);
  5752. else
  5753. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  5754. 0x0df70000);
  5755. } else { /* HDMI or VGA */
  5756. /* Use bend source */
  5757. if (pipe == PIPE_A)
  5758. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  5759. 0x0df70000);
  5760. else
  5761. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  5762. 0x0df40000);
  5763. }
  5764. coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe));
  5765. coreclk = (coreclk & 0x0000ff00) | 0x01c00000;
  5766. if (intel_crtc_has_dp_encoder(crtc->config))
  5767. coreclk |= 0x01000000;
  5768. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk);
  5769. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000);
  5770. mutex_unlock(&dev_priv->sb_lock);
  5771. }
  5772. static void chv_prepare_pll(struct intel_crtc *crtc,
  5773. const struct intel_crtc_state *pipe_config)
  5774. {
  5775. struct drm_device *dev = crtc->base.dev;
  5776. struct drm_i915_private *dev_priv = to_i915(dev);
  5777. enum pipe pipe = crtc->pipe;
  5778. enum dpio_channel port = vlv_pipe_to_channel(pipe);
  5779. u32 loopfilter, tribuf_calcntr;
  5780. u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac;
  5781. u32 dpio_val;
  5782. int vco;
  5783. /* Enable Refclk and SSC */
  5784. I915_WRITE(DPLL(pipe),
  5785. pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE);
  5786. /* No need to actually set up the DPLL with DSI */
  5787. if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
  5788. return;
  5789. bestn = pipe_config->dpll.n;
  5790. bestm2_frac = pipe_config->dpll.m2 & 0x3fffff;
  5791. bestm1 = pipe_config->dpll.m1;
  5792. bestm2 = pipe_config->dpll.m2 >> 22;
  5793. bestp1 = pipe_config->dpll.p1;
  5794. bestp2 = pipe_config->dpll.p2;
  5795. vco = pipe_config->dpll.vco;
  5796. dpio_val = 0;
  5797. loopfilter = 0;
  5798. mutex_lock(&dev_priv->sb_lock);
  5799. /* p1 and p2 divider */
  5800. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port),
  5801. 5 << DPIO_CHV_S1_DIV_SHIFT |
  5802. bestp1 << DPIO_CHV_P1_DIV_SHIFT |
  5803. bestp2 << DPIO_CHV_P2_DIV_SHIFT |
  5804. 1 << DPIO_CHV_K_DIV_SHIFT);
  5805. /* Feedback post-divider - m2 */
  5806. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2);
  5807. /* Feedback refclk divider - n and m1 */
  5808. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port),
  5809. DPIO_CHV_M1_DIV_BY_2 |
  5810. 1 << DPIO_CHV_N_DIV_SHIFT);
  5811. /* M2 fraction division */
  5812. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac);
  5813. /* M2 fraction division enable */
  5814. dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
  5815. dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN);
  5816. dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT);
  5817. if (bestm2_frac)
  5818. dpio_val |= DPIO_CHV_FRAC_DIV_EN;
  5819. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val);
  5820. /* Program digital lock detect threshold */
  5821. dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port));
  5822. dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK |
  5823. DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE);
  5824. dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT);
  5825. if (!bestm2_frac)
  5826. dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE;
  5827. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val);
  5828. /* Loop filter */
  5829. if (vco == 5400000) {
  5830. loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT);
  5831. loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT);
  5832. loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT);
  5833. tribuf_calcntr = 0x9;
  5834. } else if (vco <= 6200000) {
  5835. loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT);
  5836. loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT);
  5837. loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
  5838. tribuf_calcntr = 0x9;
  5839. } else if (vco <= 6480000) {
  5840. loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
  5841. loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
  5842. loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
  5843. tribuf_calcntr = 0x8;
  5844. } else {
  5845. /* Not supported. Apply the same limits as in the max case */
  5846. loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
  5847. loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
  5848. loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
  5849. tribuf_calcntr = 0;
  5850. }
  5851. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter);
  5852. dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port));
  5853. dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK;
  5854. dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT);
  5855. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val);
  5856. /* AFC Recal */
  5857. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port),
  5858. vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) |
  5859. DPIO_AFC_RECAL);
  5860. mutex_unlock(&dev_priv->sb_lock);
  5861. }
  5862. /**
  5863. * vlv_force_pll_on - forcibly enable just the PLL
  5864. * @dev_priv: i915 private structure
  5865. * @pipe: pipe PLL to enable
  5866. * @dpll: PLL configuration
  5867. *
  5868. * Enable the PLL for @pipe using the supplied @dpll config. To be used
  5869. * in cases where we need the PLL enabled even when @pipe is not going to
  5870. * be enabled.
  5871. */
  5872. int vlv_force_pll_on(struct drm_i915_private *dev_priv, enum pipe pipe,
  5873. const struct dpll *dpll)
  5874. {
  5875. struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
  5876. struct intel_crtc_state *pipe_config;
  5877. pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL);
  5878. if (!pipe_config)
  5879. return -ENOMEM;
  5880. pipe_config->base.crtc = &crtc->base;
  5881. pipe_config->pixel_multiplier = 1;
  5882. pipe_config->dpll = *dpll;
  5883. if (IS_CHERRYVIEW(dev_priv)) {
  5884. chv_compute_dpll(crtc, pipe_config);
  5885. chv_prepare_pll(crtc, pipe_config);
  5886. chv_enable_pll(crtc, pipe_config);
  5887. } else {
  5888. vlv_compute_dpll(crtc, pipe_config);
  5889. vlv_prepare_pll(crtc, pipe_config);
  5890. vlv_enable_pll(crtc, pipe_config);
  5891. }
  5892. kfree(pipe_config);
  5893. return 0;
  5894. }
  5895. /**
  5896. * vlv_force_pll_off - forcibly disable just the PLL
  5897. * @dev_priv: i915 private structure
  5898. * @pipe: pipe PLL to disable
  5899. *
  5900. * Disable the PLL for @pipe. To be used in cases where we need
  5901. * the PLL enabled even when @pipe is not going to be enabled.
  5902. */
  5903. void vlv_force_pll_off(struct drm_i915_private *dev_priv, enum pipe pipe)
  5904. {
  5905. if (IS_CHERRYVIEW(dev_priv))
  5906. chv_disable_pll(dev_priv, pipe);
  5907. else
  5908. vlv_disable_pll(dev_priv, pipe);
  5909. }
  5910. static void i9xx_compute_dpll(struct intel_crtc *crtc,
  5911. struct intel_crtc_state *crtc_state,
  5912. struct dpll *reduced_clock)
  5913. {
  5914. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  5915. u32 dpll;
  5916. struct dpll *clock = &crtc_state->dpll;
  5917. i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
  5918. dpll = DPLL_VGA_MODE_DIS;
  5919. if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
  5920. dpll |= DPLLB_MODE_LVDS;
  5921. else
  5922. dpll |= DPLLB_MODE_DAC_SERIAL;
  5923. if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
  5924. IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
  5925. dpll |= (crtc_state->pixel_multiplier - 1)
  5926. << SDVO_MULTIPLIER_SHIFT_HIRES;
  5927. }
  5928. if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
  5929. intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
  5930. dpll |= DPLL_SDVO_HIGH_SPEED;
  5931. if (intel_crtc_has_dp_encoder(crtc_state))
  5932. dpll |= DPLL_SDVO_HIGH_SPEED;
  5933. /* compute bitmask from p1 value */
  5934. if (IS_PINEVIEW(dev_priv))
  5935. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
  5936. else {
  5937. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  5938. if (IS_G4X(dev_priv) && reduced_clock)
  5939. dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  5940. }
  5941. switch (clock->p2) {
  5942. case 5:
  5943. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  5944. break;
  5945. case 7:
  5946. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  5947. break;
  5948. case 10:
  5949. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  5950. break;
  5951. case 14:
  5952. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  5953. break;
  5954. }
  5955. if (INTEL_GEN(dev_priv) >= 4)
  5956. dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
  5957. if (crtc_state->sdvo_tv_clock)
  5958. dpll |= PLL_REF_INPUT_TVCLKINBC;
  5959. else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
  5960. intel_panel_use_ssc(dev_priv))
  5961. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  5962. else
  5963. dpll |= PLL_REF_INPUT_DREFCLK;
  5964. dpll |= DPLL_VCO_ENABLE;
  5965. crtc_state->dpll_hw_state.dpll = dpll;
  5966. if (INTEL_GEN(dev_priv) >= 4) {
  5967. u32 dpll_md = (crtc_state->pixel_multiplier - 1)
  5968. << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  5969. crtc_state->dpll_hw_state.dpll_md = dpll_md;
  5970. }
  5971. }
  5972. static void i8xx_compute_dpll(struct intel_crtc *crtc,
  5973. struct intel_crtc_state *crtc_state,
  5974. struct dpll *reduced_clock)
  5975. {
  5976. struct drm_device *dev = crtc->base.dev;
  5977. struct drm_i915_private *dev_priv = to_i915(dev);
  5978. u32 dpll;
  5979. struct dpll *clock = &crtc_state->dpll;
  5980. i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
  5981. dpll = DPLL_VGA_MODE_DIS;
  5982. if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
  5983. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  5984. } else {
  5985. if (clock->p1 == 2)
  5986. dpll |= PLL_P1_DIVIDE_BY_TWO;
  5987. else
  5988. dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  5989. if (clock->p2 == 4)
  5990. dpll |= PLL_P2_DIVIDE_BY_4;
  5991. }
  5992. if (!IS_I830(dev_priv) &&
  5993. intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO))
  5994. dpll |= DPLL_DVO_2X_MODE;
  5995. if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
  5996. intel_panel_use_ssc(dev_priv))
  5997. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  5998. else
  5999. dpll |= PLL_REF_INPUT_DREFCLK;
  6000. dpll |= DPLL_VCO_ENABLE;
  6001. crtc_state->dpll_hw_state.dpll = dpll;
  6002. }
  6003. static void intel_set_pipe_timings(struct intel_crtc *intel_crtc)
  6004. {
  6005. struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
  6006. enum pipe pipe = intel_crtc->pipe;
  6007. enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
  6008. const struct drm_display_mode *adjusted_mode = &intel_crtc->config->base.adjusted_mode;
  6009. uint32_t crtc_vtotal, crtc_vblank_end;
  6010. int vsyncshift = 0;
  6011. /* We need to be careful not to changed the adjusted mode, for otherwise
  6012. * the hw state checker will get angry at the mismatch. */
  6013. crtc_vtotal = adjusted_mode->crtc_vtotal;
  6014. crtc_vblank_end = adjusted_mode->crtc_vblank_end;
  6015. if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
  6016. /* the chip adds 2 halflines automatically */
  6017. crtc_vtotal -= 1;
  6018. crtc_vblank_end -= 1;
  6019. if (intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_SDVO))
  6020. vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
  6021. else
  6022. vsyncshift = adjusted_mode->crtc_hsync_start -
  6023. adjusted_mode->crtc_htotal / 2;
  6024. if (vsyncshift < 0)
  6025. vsyncshift += adjusted_mode->crtc_htotal;
  6026. }
  6027. if (INTEL_GEN(dev_priv) > 3)
  6028. I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
  6029. I915_WRITE(HTOTAL(cpu_transcoder),
  6030. (adjusted_mode->crtc_hdisplay - 1) |
  6031. ((adjusted_mode->crtc_htotal - 1) << 16));
  6032. I915_WRITE(HBLANK(cpu_transcoder),
  6033. (adjusted_mode->crtc_hblank_start - 1) |
  6034. ((adjusted_mode->crtc_hblank_end - 1) << 16));
  6035. I915_WRITE(HSYNC(cpu_transcoder),
  6036. (adjusted_mode->crtc_hsync_start - 1) |
  6037. ((adjusted_mode->crtc_hsync_end - 1) << 16));
  6038. I915_WRITE(VTOTAL(cpu_transcoder),
  6039. (adjusted_mode->crtc_vdisplay - 1) |
  6040. ((crtc_vtotal - 1) << 16));
  6041. I915_WRITE(VBLANK(cpu_transcoder),
  6042. (adjusted_mode->crtc_vblank_start - 1) |
  6043. ((crtc_vblank_end - 1) << 16));
  6044. I915_WRITE(VSYNC(cpu_transcoder),
  6045. (adjusted_mode->crtc_vsync_start - 1) |
  6046. ((adjusted_mode->crtc_vsync_end - 1) << 16));
  6047. /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
  6048. * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
  6049. * documented on the DDI_FUNC_CTL register description, EDP Input Select
  6050. * bits. */
  6051. if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP &&
  6052. (pipe == PIPE_B || pipe == PIPE_C))
  6053. I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
  6054. }
  6055. static void intel_set_pipe_src_size(struct intel_crtc *intel_crtc)
  6056. {
  6057. struct drm_device *dev = intel_crtc->base.dev;
  6058. struct drm_i915_private *dev_priv = to_i915(dev);
  6059. enum pipe pipe = intel_crtc->pipe;
  6060. /* pipesrc controls the size that is scaled from, which should
  6061. * always be the user's requested size.
  6062. */
  6063. I915_WRITE(PIPESRC(pipe),
  6064. ((intel_crtc->config->pipe_src_w - 1) << 16) |
  6065. (intel_crtc->config->pipe_src_h - 1));
  6066. }
  6067. static void intel_get_pipe_timings(struct intel_crtc *crtc,
  6068. struct intel_crtc_state *pipe_config)
  6069. {
  6070. struct drm_device *dev = crtc->base.dev;
  6071. struct drm_i915_private *dev_priv = to_i915(dev);
  6072. enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
  6073. uint32_t tmp;
  6074. tmp = I915_READ(HTOTAL(cpu_transcoder));
  6075. pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
  6076. pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
  6077. tmp = I915_READ(HBLANK(cpu_transcoder));
  6078. pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1;
  6079. pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1;
  6080. tmp = I915_READ(HSYNC(cpu_transcoder));
  6081. pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
  6082. pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
  6083. tmp = I915_READ(VTOTAL(cpu_transcoder));
  6084. pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
  6085. pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
  6086. tmp = I915_READ(VBLANK(cpu_transcoder));
  6087. pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1;
  6088. pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1;
  6089. tmp = I915_READ(VSYNC(cpu_transcoder));
  6090. pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
  6091. pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
  6092. if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) {
  6093. pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
  6094. pipe_config->base.adjusted_mode.crtc_vtotal += 1;
  6095. pipe_config->base.adjusted_mode.crtc_vblank_end += 1;
  6096. }
  6097. }
  6098. static void intel_get_pipe_src_size(struct intel_crtc *crtc,
  6099. struct intel_crtc_state *pipe_config)
  6100. {
  6101. struct drm_device *dev = crtc->base.dev;
  6102. struct drm_i915_private *dev_priv = to_i915(dev);
  6103. u32 tmp;
  6104. tmp = I915_READ(PIPESRC(crtc->pipe));
  6105. pipe_config->pipe_src_h = (tmp & 0xffff) + 1;
  6106. pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1;
  6107. pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h;
  6108. pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w;
  6109. }
  6110. void intel_mode_from_pipe_config(struct drm_display_mode *mode,
  6111. struct intel_crtc_state *pipe_config)
  6112. {
  6113. mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay;
  6114. mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal;
  6115. mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start;
  6116. mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end;
  6117. mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay;
  6118. mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal;
  6119. mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start;
  6120. mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end;
  6121. mode->flags = pipe_config->base.adjusted_mode.flags;
  6122. mode->type = DRM_MODE_TYPE_DRIVER;
  6123. mode->clock = pipe_config->base.adjusted_mode.crtc_clock;
  6124. mode->hsync = drm_mode_hsync(mode);
  6125. mode->vrefresh = drm_mode_vrefresh(mode);
  6126. drm_mode_set_name(mode);
  6127. }
  6128. static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc)
  6129. {
  6130. struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
  6131. uint32_t pipeconf;
  6132. pipeconf = 0;
  6133. /* we keep both pipes enabled on 830 */
  6134. if (IS_I830(dev_priv))
  6135. pipeconf |= I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE;
  6136. if (intel_crtc->config->double_wide)
  6137. pipeconf |= PIPECONF_DOUBLE_WIDE;
  6138. /* only g4x and later have fancy bpc/dither controls */
  6139. if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
  6140. IS_CHERRYVIEW(dev_priv)) {
  6141. /* Bspec claims that we can't use dithering for 30bpp pipes. */
  6142. if (intel_crtc->config->dither && intel_crtc->config->pipe_bpp != 30)
  6143. pipeconf |= PIPECONF_DITHER_EN |
  6144. PIPECONF_DITHER_TYPE_SP;
  6145. switch (intel_crtc->config->pipe_bpp) {
  6146. case 18:
  6147. pipeconf |= PIPECONF_6BPC;
  6148. break;
  6149. case 24:
  6150. pipeconf |= PIPECONF_8BPC;
  6151. break;
  6152. case 30:
  6153. pipeconf |= PIPECONF_10BPC;
  6154. break;
  6155. default:
  6156. /* Case prevented by intel_choose_pipe_bpp_dither. */
  6157. BUG();
  6158. }
  6159. }
  6160. if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
  6161. if (INTEL_GEN(dev_priv) < 4 ||
  6162. intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_SDVO))
  6163. pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
  6164. else
  6165. pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT;
  6166. } else
  6167. pipeconf |= PIPECONF_PROGRESSIVE;
  6168. if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
  6169. intel_crtc->config->limited_color_range)
  6170. pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
  6171. I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf);
  6172. POSTING_READ(PIPECONF(intel_crtc->pipe));
  6173. }
  6174. static int i8xx_crtc_compute_clock(struct intel_crtc *crtc,
  6175. struct intel_crtc_state *crtc_state)
  6176. {
  6177. struct drm_device *dev = crtc->base.dev;
  6178. struct drm_i915_private *dev_priv = to_i915(dev);
  6179. const struct intel_limit *limit;
  6180. int refclk = 48000;
  6181. memset(&crtc_state->dpll_hw_state, 0,
  6182. sizeof(crtc_state->dpll_hw_state));
  6183. if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
  6184. if (intel_panel_use_ssc(dev_priv)) {
  6185. refclk = dev_priv->vbt.lvds_ssc_freq;
  6186. DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
  6187. }
  6188. limit = &intel_limits_i8xx_lvds;
  6189. } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO)) {
  6190. limit = &intel_limits_i8xx_dvo;
  6191. } else {
  6192. limit = &intel_limits_i8xx_dac;
  6193. }
  6194. if (!crtc_state->clock_set &&
  6195. !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
  6196. refclk, NULL, &crtc_state->dpll)) {
  6197. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  6198. return -EINVAL;
  6199. }
  6200. i8xx_compute_dpll(crtc, crtc_state, NULL);
  6201. return 0;
  6202. }
  6203. static int g4x_crtc_compute_clock(struct intel_crtc *crtc,
  6204. struct intel_crtc_state *crtc_state)
  6205. {
  6206. struct drm_device *dev = crtc->base.dev;
  6207. struct drm_i915_private *dev_priv = to_i915(dev);
  6208. const struct intel_limit *limit;
  6209. int refclk = 96000;
  6210. memset(&crtc_state->dpll_hw_state, 0,
  6211. sizeof(crtc_state->dpll_hw_state));
  6212. if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
  6213. if (intel_panel_use_ssc(dev_priv)) {
  6214. refclk = dev_priv->vbt.lvds_ssc_freq;
  6215. DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
  6216. }
  6217. if (intel_is_dual_link_lvds(dev))
  6218. limit = &intel_limits_g4x_dual_channel_lvds;
  6219. else
  6220. limit = &intel_limits_g4x_single_channel_lvds;
  6221. } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI) ||
  6222. intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) {
  6223. limit = &intel_limits_g4x_hdmi;
  6224. } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) {
  6225. limit = &intel_limits_g4x_sdvo;
  6226. } else {
  6227. /* The option is for other outputs */
  6228. limit = &intel_limits_i9xx_sdvo;
  6229. }
  6230. if (!crtc_state->clock_set &&
  6231. !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
  6232. refclk, NULL, &crtc_state->dpll)) {
  6233. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  6234. return -EINVAL;
  6235. }
  6236. i9xx_compute_dpll(crtc, crtc_state, NULL);
  6237. return 0;
  6238. }
  6239. static int pnv_crtc_compute_clock(struct intel_crtc *crtc,
  6240. struct intel_crtc_state *crtc_state)
  6241. {
  6242. struct drm_device *dev = crtc->base.dev;
  6243. struct drm_i915_private *dev_priv = to_i915(dev);
  6244. const struct intel_limit *limit;
  6245. int refclk = 96000;
  6246. memset(&crtc_state->dpll_hw_state, 0,
  6247. sizeof(crtc_state->dpll_hw_state));
  6248. if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
  6249. if (intel_panel_use_ssc(dev_priv)) {
  6250. refclk = dev_priv->vbt.lvds_ssc_freq;
  6251. DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
  6252. }
  6253. limit = &intel_limits_pineview_lvds;
  6254. } else {
  6255. limit = &intel_limits_pineview_sdvo;
  6256. }
  6257. if (!crtc_state->clock_set &&
  6258. !pnv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
  6259. refclk, NULL, &crtc_state->dpll)) {
  6260. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  6261. return -EINVAL;
  6262. }
  6263. i9xx_compute_dpll(crtc, crtc_state, NULL);
  6264. return 0;
  6265. }
  6266. static int i9xx_crtc_compute_clock(struct intel_crtc *crtc,
  6267. struct intel_crtc_state *crtc_state)
  6268. {
  6269. struct drm_device *dev = crtc->base.dev;
  6270. struct drm_i915_private *dev_priv = to_i915(dev);
  6271. const struct intel_limit *limit;
  6272. int refclk = 96000;
  6273. memset(&crtc_state->dpll_hw_state, 0,
  6274. sizeof(crtc_state->dpll_hw_state));
  6275. if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
  6276. if (intel_panel_use_ssc(dev_priv)) {
  6277. refclk = dev_priv->vbt.lvds_ssc_freq;
  6278. DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
  6279. }
  6280. limit = &intel_limits_i9xx_lvds;
  6281. } else {
  6282. limit = &intel_limits_i9xx_sdvo;
  6283. }
  6284. if (!crtc_state->clock_set &&
  6285. !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
  6286. refclk, NULL, &crtc_state->dpll)) {
  6287. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  6288. return -EINVAL;
  6289. }
  6290. i9xx_compute_dpll(crtc, crtc_state, NULL);
  6291. return 0;
  6292. }
  6293. static int chv_crtc_compute_clock(struct intel_crtc *crtc,
  6294. struct intel_crtc_state *crtc_state)
  6295. {
  6296. int refclk = 100000;
  6297. const struct intel_limit *limit = &intel_limits_chv;
  6298. memset(&crtc_state->dpll_hw_state, 0,
  6299. sizeof(crtc_state->dpll_hw_state));
  6300. if (!crtc_state->clock_set &&
  6301. !chv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
  6302. refclk, NULL, &crtc_state->dpll)) {
  6303. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  6304. return -EINVAL;
  6305. }
  6306. chv_compute_dpll(crtc, crtc_state);
  6307. return 0;
  6308. }
  6309. static int vlv_crtc_compute_clock(struct intel_crtc *crtc,
  6310. struct intel_crtc_state *crtc_state)
  6311. {
  6312. int refclk = 100000;
  6313. const struct intel_limit *limit = &intel_limits_vlv;
  6314. memset(&crtc_state->dpll_hw_state, 0,
  6315. sizeof(crtc_state->dpll_hw_state));
  6316. if (!crtc_state->clock_set &&
  6317. !vlv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
  6318. refclk, NULL, &crtc_state->dpll)) {
  6319. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  6320. return -EINVAL;
  6321. }
  6322. vlv_compute_dpll(crtc, crtc_state);
  6323. return 0;
  6324. }
  6325. static void i9xx_get_pfit_config(struct intel_crtc *crtc,
  6326. struct intel_crtc_state *pipe_config)
  6327. {
  6328. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  6329. uint32_t tmp;
  6330. if (INTEL_GEN(dev_priv) <= 3 &&
  6331. (IS_I830(dev_priv) || !IS_MOBILE(dev_priv)))
  6332. return;
  6333. tmp = I915_READ(PFIT_CONTROL);
  6334. if (!(tmp & PFIT_ENABLE))
  6335. return;
  6336. /* Check whether the pfit is attached to our pipe. */
  6337. if (INTEL_GEN(dev_priv) < 4) {
  6338. if (crtc->pipe != PIPE_B)
  6339. return;
  6340. } else {
  6341. if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
  6342. return;
  6343. }
  6344. pipe_config->gmch_pfit.control = tmp;
  6345. pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS);
  6346. }
  6347. static void vlv_crtc_clock_get(struct intel_crtc *crtc,
  6348. struct intel_crtc_state *pipe_config)
  6349. {
  6350. struct drm_device *dev = crtc->base.dev;
  6351. struct drm_i915_private *dev_priv = to_i915(dev);
  6352. int pipe = pipe_config->cpu_transcoder;
  6353. struct dpll clock;
  6354. u32 mdiv;
  6355. int refclk = 100000;
  6356. /* In case of DSI, DPLL will not be used */
  6357. if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
  6358. return;
  6359. mutex_lock(&dev_priv->sb_lock);
  6360. mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
  6361. mutex_unlock(&dev_priv->sb_lock);
  6362. clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
  6363. clock.m2 = mdiv & DPIO_M2DIV_MASK;
  6364. clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
  6365. clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
  6366. clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
  6367. pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock);
  6368. }
  6369. static void
  6370. i9xx_get_initial_plane_config(struct intel_crtc *crtc,
  6371. struct intel_initial_plane_config *plane_config)
  6372. {
  6373. struct drm_device *dev = crtc->base.dev;
  6374. struct drm_i915_private *dev_priv = to_i915(dev);
  6375. struct intel_plane *plane = to_intel_plane(crtc->base.primary);
  6376. enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
  6377. enum pipe pipe = crtc->pipe;
  6378. u32 val, base, offset;
  6379. int fourcc, pixel_format;
  6380. unsigned int aligned_height;
  6381. struct drm_framebuffer *fb;
  6382. struct intel_framebuffer *intel_fb;
  6383. if (!plane->get_hw_state(plane))
  6384. return;
  6385. intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
  6386. if (!intel_fb) {
  6387. DRM_DEBUG_KMS("failed to alloc fb\n");
  6388. return;
  6389. }
  6390. fb = &intel_fb->base;
  6391. fb->dev = dev;
  6392. val = I915_READ(DSPCNTR(i9xx_plane));
  6393. if (INTEL_GEN(dev_priv) >= 4) {
  6394. if (val & DISPPLANE_TILED) {
  6395. plane_config->tiling = I915_TILING_X;
  6396. fb->modifier = I915_FORMAT_MOD_X_TILED;
  6397. }
  6398. }
  6399. pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
  6400. fourcc = i9xx_format_to_fourcc(pixel_format);
  6401. fb->format = drm_format_info(fourcc);
  6402. if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
  6403. offset = I915_READ(DSPOFFSET(i9xx_plane));
  6404. base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
  6405. } else if (INTEL_GEN(dev_priv) >= 4) {
  6406. if (plane_config->tiling)
  6407. offset = I915_READ(DSPTILEOFF(i9xx_plane));
  6408. else
  6409. offset = I915_READ(DSPLINOFF(i9xx_plane));
  6410. base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
  6411. } else {
  6412. base = I915_READ(DSPADDR(i9xx_plane));
  6413. }
  6414. plane_config->base = base;
  6415. val = I915_READ(PIPESRC(pipe));
  6416. fb->width = ((val >> 16) & 0xfff) + 1;
  6417. fb->height = ((val >> 0) & 0xfff) + 1;
  6418. val = I915_READ(DSPSTRIDE(i9xx_plane));
  6419. fb->pitches[0] = val & 0xffffffc0;
  6420. aligned_height = intel_fb_align_height(fb, 0, fb->height);
  6421. plane_config->size = fb->pitches[0] * aligned_height;
  6422. DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
  6423. crtc->base.name, plane->base.name, fb->width, fb->height,
  6424. fb->format->cpp[0] * 8, base, fb->pitches[0],
  6425. plane_config->size);
  6426. plane_config->fb = intel_fb;
  6427. }
  6428. static void chv_crtc_clock_get(struct intel_crtc *crtc,
  6429. struct intel_crtc_state *pipe_config)
  6430. {
  6431. struct drm_device *dev = crtc->base.dev;
  6432. struct drm_i915_private *dev_priv = to_i915(dev);
  6433. int pipe = pipe_config->cpu_transcoder;
  6434. enum dpio_channel port = vlv_pipe_to_channel(pipe);
  6435. struct dpll clock;
  6436. u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3;
  6437. int refclk = 100000;
  6438. /* In case of DSI, DPLL will not be used */
  6439. if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
  6440. return;
  6441. mutex_lock(&dev_priv->sb_lock);
  6442. cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
  6443. pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
  6444. pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
  6445. pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
  6446. pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
  6447. mutex_unlock(&dev_priv->sb_lock);
  6448. clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
  6449. clock.m2 = (pll_dw0 & 0xff) << 22;
  6450. if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN)
  6451. clock.m2 |= pll_dw2 & 0x3fffff;
  6452. clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
  6453. clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
  6454. clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
  6455. pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock);
  6456. }
  6457. static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
  6458. struct intel_crtc_state *pipe_config)
  6459. {
  6460. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  6461. enum intel_display_power_domain power_domain;
  6462. uint32_t tmp;
  6463. bool ret;
  6464. power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
  6465. if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
  6466. return false;
  6467. pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
  6468. pipe_config->shared_dpll = NULL;
  6469. ret = false;
  6470. tmp = I915_READ(PIPECONF(crtc->pipe));
  6471. if (!(tmp & PIPECONF_ENABLE))
  6472. goto out;
  6473. if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
  6474. IS_CHERRYVIEW(dev_priv)) {
  6475. switch (tmp & PIPECONF_BPC_MASK) {
  6476. case PIPECONF_6BPC:
  6477. pipe_config->pipe_bpp = 18;
  6478. break;
  6479. case PIPECONF_8BPC:
  6480. pipe_config->pipe_bpp = 24;
  6481. break;
  6482. case PIPECONF_10BPC:
  6483. pipe_config->pipe_bpp = 30;
  6484. break;
  6485. default:
  6486. break;
  6487. }
  6488. }
  6489. if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
  6490. (tmp & PIPECONF_COLOR_RANGE_SELECT))
  6491. pipe_config->limited_color_range = true;
  6492. if (INTEL_GEN(dev_priv) < 4)
  6493. pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
  6494. intel_get_pipe_timings(crtc, pipe_config);
  6495. intel_get_pipe_src_size(crtc, pipe_config);
  6496. i9xx_get_pfit_config(crtc, pipe_config);
  6497. if (INTEL_GEN(dev_priv) >= 4) {
  6498. /* No way to read it out on pipes B and C */
  6499. if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A)
  6500. tmp = dev_priv->chv_dpll_md[crtc->pipe];
  6501. else
  6502. tmp = I915_READ(DPLL_MD(crtc->pipe));
  6503. pipe_config->pixel_multiplier =
  6504. ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
  6505. >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
  6506. pipe_config->dpll_hw_state.dpll_md = tmp;
  6507. } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
  6508. IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
  6509. tmp = I915_READ(DPLL(crtc->pipe));
  6510. pipe_config->pixel_multiplier =
  6511. ((tmp & SDVO_MULTIPLIER_MASK)
  6512. >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
  6513. } else {
  6514. /* Note that on i915G/GM the pixel multiplier is in the sdvo
  6515. * port and will be fixed up in the encoder->get_config
  6516. * function. */
  6517. pipe_config->pixel_multiplier = 1;
  6518. }
  6519. pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe));
  6520. if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
  6521. /*
  6522. * DPLL_DVO_2X_MODE must be enabled for both DPLLs
  6523. * on 830. Filter it out here so that we don't
  6524. * report errors due to that.
  6525. */
  6526. if (IS_I830(dev_priv))
  6527. pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE;
  6528. pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe));
  6529. pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe));
  6530. } else {
  6531. /* Mask out read-only status bits. */
  6532. pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
  6533. DPLL_PORTC_READY_MASK |
  6534. DPLL_PORTB_READY_MASK);
  6535. }
  6536. if (IS_CHERRYVIEW(dev_priv))
  6537. chv_crtc_clock_get(crtc, pipe_config);
  6538. else if (IS_VALLEYVIEW(dev_priv))
  6539. vlv_crtc_clock_get(crtc, pipe_config);
  6540. else
  6541. i9xx_crtc_clock_get(crtc, pipe_config);
  6542. /*
  6543. * Normally the dotclock is filled in by the encoder .get_config()
  6544. * but in case the pipe is enabled w/o any ports we need a sane
  6545. * default.
  6546. */
  6547. pipe_config->base.adjusted_mode.crtc_clock =
  6548. pipe_config->port_clock / pipe_config->pixel_multiplier;
  6549. ret = true;
  6550. out:
  6551. intel_display_power_put(dev_priv, power_domain);
  6552. return ret;
  6553. }
  6554. static void ironlake_init_pch_refclk(struct drm_i915_private *dev_priv)
  6555. {
  6556. struct intel_encoder *encoder;
  6557. int i;
  6558. u32 val, final;
  6559. bool has_lvds = false;
  6560. bool has_cpu_edp = false;
  6561. bool has_panel = false;
  6562. bool has_ck505 = false;
  6563. bool can_ssc = false;
  6564. bool using_ssc_source = false;
  6565. /* We need to take the global config into account */
  6566. for_each_intel_encoder(&dev_priv->drm, encoder) {
  6567. switch (encoder->type) {
  6568. case INTEL_OUTPUT_LVDS:
  6569. has_panel = true;
  6570. has_lvds = true;
  6571. break;
  6572. case INTEL_OUTPUT_EDP:
  6573. has_panel = true;
  6574. if (encoder->port == PORT_A)
  6575. has_cpu_edp = true;
  6576. break;
  6577. default:
  6578. break;
  6579. }
  6580. }
  6581. if (HAS_PCH_IBX(dev_priv)) {
  6582. has_ck505 = dev_priv->vbt.display_clock_mode;
  6583. can_ssc = has_ck505;
  6584. } else {
  6585. has_ck505 = false;
  6586. can_ssc = true;
  6587. }
  6588. /* Check if any DPLLs are using the SSC source */
  6589. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  6590. u32 temp = I915_READ(PCH_DPLL(i));
  6591. if (!(temp & DPLL_VCO_ENABLE))
  6592. continue;
  6593. if ((temp & PLL_REF_INPUT_MASK) ==
  6594. PLLB_REF_INPUT_SPREADSPECTRUMIN) {
  6595. using_ssc_source = true;
  6596. break;
  6597. }
  6598. }
  6599. DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n",
  6600. has_panel, has_lvds, has_ck505, using_ssc_source);
  6601. /* Ironlake: try to setup display ref clock before DPLL
  6602. * enabling. This is only under driver's control after
  6603. * PCH B stepping, previous chipset stepping should be
  6604. * ignoring this setting.
  6605. */
  6606. val = I915_READ(PCH_DREF_CONTROL);
  6607. /* As we must carefully and slowly disable/enable each source in turn,
  6608. * compute the final state we want first and check if we need to
  6609. * make any changes at all.
  6610. */
  6611. final = val;
  6612. final &= ~DREF_NONSPREAD_SOURCE_MASK;
  6613. if (has_ck505)
  6614. final |= DREF_NONSPREAD_CK505_ENABLE;
  6615. else
  6616. final |= DREF_NONSPREAD_SOURCE_ENABLE;
  6617. final &= ~DREF_SSC_SOURCE_MASK;
  6618. final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  6619. final &= ~DREF_SSC1_ENABLE;
  6620. if (has_panel) {
  6621. final |= DREF_SSC_SOURCE_ENABLE;
  6622. if (intel_panel_use_ssc(dev_priv) && can_ssc)
  6623. final |= DREF_SSC1_ENABLE;
  6624. if (has_cpu_edp) {
  6625. if (intel_panel_use_ssc(dev_priv) && can_ssc)
  6626. final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
  6627. else
  6628. final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
  6629. } else
  6630. final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  6631. } else if (using_ssc_source) {
  6632. final |= DREF_SSC_SOURCE_ENABLE;
  6633. final |= DREF_SSC1_ENABLE;
  6634. }
  6635. if (final == val)
  6636. return;
  6637. /* Always enable nonspread source */
  6638. val &= ~DREF_NONSPREAD_SOURCE_MASK;
  6639. if (has_ck505)
  6640. val |= DREF_NONSPREAD_CK505_ENABLE;
  6641. else
  6642. val |= DREF_NONSPREAD_SOURCE_ENABLE;
  6643. if (has_panel) {
  6644. val &= ~DREF_SSC_SOURCE_MASK;
  6645. val |= DREF_SSC_SOURCE_ENABLE;
  6646. /* SSC must be turned on before enabling the CPU output */
  6647. if (intel_panel_use_ssc(dev_priv) && can_ssc) {
  6648. DRM_DEBUG_KMS("Using SSC on panel\n");
  6649. val |= DREF_SSC1_ENABLE;
  6650. } else
  6651. val &= ~DREF_SSC1_ENABLE;
  6652. /* Get SSC going before enabling the outputs */
  6653. I915_WRITE(PCH_DREF_CONTROL, val);
  6654. POSTING_READ(PCH_DREF_CONTROL);
  6655. udelay(200);
  6656. val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  6657. /* Enable CPU source on CPU attached eDP */
  6658. if (has_cpu_edp) {
  6659. if (intel_panel_use_ssc(dev_priv) && can_ssc) {
  6660. DRM_DEBUG_KMS("Using SSC on eDP\n");
  6661. val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
  6662. } else
  6663. val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
  6664. } else
  6665. val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  6666. I915_WRITE(PCH_DREF_CONTROL, val);
  6667. POSTING_READ(PCH_DREF_CONTROL);
  6668. udelay(200);
  6669. } else {
  6670. DRM_DEBUG_KMS("Disabling CPU source output\n");
  6671. val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  6672. /* Turn off CPU output */
  6673. val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  6674. I915_WRITE(PCH_DREF_CONTROL, val);
  6675. POSTING_READ(PCH_DREF_CONTROL);
  6676. udelay(200);
  6677. if (!using_ssc_source) {
  6678. DRM_DEBUG_KMS("Disabling SSC source\n");
  6679. /* Turn off the SSC source */
  6680. val &= ~DREF_SSC_SOURCE_MASK;
  6681. val |= DREF_SSC_SOURCE_DISABLE;
  6682. /* Turn off SSC1 */
  6683. val &= ~DREF_SSC1_ENABLE;
  6684. I915_WRITE(PCH_DREF_CONTROL, val);
  6685. POSTING_READ(PCH_DREF_CONTROL);
  6686. udelay(200);
  6687. }
  6688. }
  6689. BUG_ON(val != final);
  6690. }
  6691. static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv)
  6692. {
  6693. uint32_t tmp;
  6694. tmp = I915_READ(SOUTH_CHICKEN2);
  6695. tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
  6696. I915_WRITE(SOUTH_CHICKEN2, tmp);
  6697. if (wait_for_us(I915_READ(SOUTH_CHICKEN2) &
  6698. FDI_MPHY_IOSFSB_RESET_STATUS, 100))
  6699. DRM_ERROR("FDI mPHY reset assert timeout\n");
  6700. tmp = I915_READ(SOUTH_CHICKEN2);
  6701. tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
  6702. I915_WRITE(SOUTH_CHICKEN2, tmp);
  6703. if (wait_for_us((I915_READ(SOUTH_CHICKEN2) &
  6704. FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100))
  6705. DRM_ERROR("FDI mPHY reset de-assert timeout\n");
  6706. }
  6707. /* WaMPhyProgramming:hsw */
  6708. static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv)
  6709. {
  6710. uint32_t tmp;
  6711. tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
  6712. tmp &= ~(0xFF << 24);
  6713. tmp |= (0x12 << 24);
  6714. intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
  6715. tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
  6716. tmp |= (1 << 11);
  6717. intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
  6718. tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
  6719. tmp |= (1 << 11);
  6720. intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
  6721. tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
  6722. tmp |= (1 << 24) | (1 << 21) | (1 << 18);
  6723. intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
  6724. tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
  6725. tmp |= (1 << 24) | (1 << 21) | (1 << 18);
  6726. intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
  6727. tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
  6728. tmp &= ~(7 << 13);
  6729. tmp |= (5 << 13);
  6730. intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
  6731. tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
  6732. tmp &= ~(7 << 13);
  6733. tmp |= (5 << 13);
  6734. intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
  6735. tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
  6736. tmp &= ~0xFF;
  6737. tmp |= 0x1C;
  6738. intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
  6739. tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
  6740. tmp &= ~0xFF;
  6741. tmp |= 0x1C;
  6742. intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
  6743. tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
  6744. tmp &= ~(0xFF << 16);
  6745. tmp |= (0x1C << 16);
  6746. intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
  6747. tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
  6748. tmp &= ~(0xFF << 16);
  6749. tmp |= (0x1C << 16);
  6750. intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
  6751. tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
  6752. tmp |= (1 << 27);
  6753. intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
  6754. tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
  6755. tmp |= (1 << 27);
  6756. intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
  6757. tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
  6758. tmp &= ~(0xF << 28);
  6759. tmp |= (4 << 28);
  6760. intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
  6761. tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
  6762. tmp &= ~(0xF << 28);
  6763. tmp |= (4 << 28);
  6764. intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
  6765. }
  6766. /* Implements 3 different sequences from BSpec chapter "Display iCLK
  6767. * Programming" based on the parameters passed:
  6768. * - Sequence to enable CLKOUT_DP
  6769. * - Sequence to enable CLKOUT_DP without spread
  6770. * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
  6771. */
  6772. static void lpt_enable_clkout_dp(struct drm_i915_private *dev_priv,
  6773. bool with_spread, bool with_fdi)
  6774. {
  6775. uint32_t reg, tmp;
  6776. if (WARN(with_fdi && !with_spread, "FDI requires downspread\n"))
  6777. with_spread = true;
  6778. if (WARN(HAS_PCH_LPT_LP(dev_priv) &&
  6779. with_fdi, "LP PCH doesn't have FDI\n"))
  6780. with_fdi = false;
  6781. mutex_lock(&dev_priv->sb_lock);
  6782. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  6783. tmp &= ~SBI_SSCCTL_DISABLE;
  6784. tmp |= SBI_SSCCTL_PATHALT;
  6785. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  6786. udelay(24);
  6787. if (with_spread) {
  6788. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  6789. tmp &= ~SBI_SSCCTL_PATHALT;
  6790. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  6791. if (with_fdi) {
  6792. lpt_reset_fdi_mphy(dev_priv);
  6793. lpt_program_fdi_mphy(dev_priv);
  6794. }
  6795. }
  6796. reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
  6797. tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
  6798. tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE;
  6799. intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
  6800. mutex_unlock(&dev_priv->sb_lock);
  6801. }
  6802. /* Sequence to disable CLKOUT_DP */
  6803. static void lpt_disable_clkout_dp(struct drm_i915_private *dev_priv)
  6804. {
  6805. uint32_t reg, tmp;
  6806. mutex_lock(&dev_priv->sb_lock);
  6807. reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
  6808. tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
  6809. tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE;
  6810. intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
  6811. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  6812. if (!(tmp & SBI_SSCCTL_DISABLE)) {
  6813. if (!(tmp & SBI_SSCCTL_PATHALT)) {
  6814. tmp |= SBI_SSCCTL_PATHALT;
  6815. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  6816. udelay(32);
  6817. }
  6818. tmp |= SBI_SSCCTL_DISABLE;
  6819. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  6820. }
  6821. mutex_unlock(&dev_priv->sb_lock);
  6822. }
  6823. #define BEND_IDX(steps) ((50 + (steps)) / 5)
  6824. static const uint16_t sscdivintphase[] = {
  6825. [BEND_IDX( 50)] = 0x3B23,
  6826. [BEND_IDX( 45)] = 0x3B23,
  6827. [BEND_IDX( 40)] = 0x3C23,
  6828. [BEND_IDX( 35)] = 0x3C23,
  6829. [BEND_IDX( 30)] = 0x3D23,
  6830. [BEND_IDX( 25)] = 0x3D23,
  6831. [BEND_IDX( 20)] = 0x3E23,
  6832. [BEND_IDX( 15)] = 0x3E23,
  6833. [BEND_IDX( 10)] = 0x3F23,
  6834. [BEND_IDX( 5)] = 0x3F23,
  6835. [BEND_IDX( 0)] = 0x0025,
  6836. [BEND_IDX( -5)] = 0x0025,
  6837. [BEND_IDX(-10)] = 0x0125,
  6838. [BEND_IDX(-15)] = 0x0125,
  6839. [BEND_IDX(-20)] = 0x0225,
  6840. [BEND_IDX(-25)] = 0x0225,
  6841. [BEND_IDX(-30)] = 0x0325,
  6842. [BEND_IDX(-35)] = 0x0325,
  6843. [BEND_IDX(-40)] = 0x0425,
  6844. [BEND_IDX(-45)] = 0x0425,
  6845. [BEND_IDX(-50)] = 0x0525,
  6846. };
  6847. /*
  6848. * Bend CLKOUT_DP
  6849. * steps -50 to 50 inclusive, in steps of 5
  6850. * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz)
  6851. * change in clock period = -(steps / 10) * 5.787 ps
  6852. */
  6853. static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps)
  6854. {
  6855. uint32_t tmp;
  6856. int idx = BEND_IDX(steps);
  6857. if (WARN_ON(steps % 5 != 0))
  6858. return;
  6859. if (WARN_ON(idx >= ARRAY_SIZE(sscdivintphase)))
  6860. return;
  6861. mutex_lock(&dev_priv->sb_lock);
  6862. if (steps % 10 != 0)
  6863. tmp = 0xAAAAAAAB;
  6864. else
  6865. tmp = 0x00000000;
  6866. intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK);
  6867. tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK);
  6868. tmp &= 0xffff0000;
  6869. tmp |= sscdivintphase[idx];
  6870. intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK);
  6871. mutex_unlock(&dev_priv->sb_lock);
  6872. }
  6873. #undef BEND_IDX
  6874. static void lpt_init_pch_refclk(struct drm_i915_private *dev_priv)
  6875. {
  6876. struct intel_encoder *encoder;
  6877. bool has_vga = false;
  6878. for_each_intel_encoder(&dev_priv->drm, encoder) {
  6879. switch (encoder->type) {
  6880. case INTEL_OUTPUT_ANALOG:
  6881. has_vga = true;
  6882. break;
  6883. default:
  6884. break;
  6885. }
  6886. }
  6887. if (has_vga) {
  6888. lpt_bend_clkout_dp(dev_priv, 0);
  6889. lpt_enable_clkout_dp(dev_priv, true, true);
  6890. } else {
  6891. lpt_disable_clkout_dp(dev_priv);
  6892. }
  6893. }
  6894. /*
  6895. * Initialize reference clocks when the driver loads
  6896. */
  6897. void intel_init_pch_refclk(struct drm_i915_private *dev_priv)
  6898. {
  6899. if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv))
  6900. ironlake_init_pch_refclk(dev_priv);
  6901. else if (HAS_PCH_LPT(dev_priv))
  6902. lpt_init_pch_refclk(dev_priv);
  6903. }
  6904. static void ironlake_set_pipeconf(struct drm_crtc *crtc)
  6905. {
  6906. struct drm_i915_private *dev_priv = to_i915(crtc->dev);
  6907. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6908. int pipe = intel_crtc->pipe;
  6909. uint32_t val;
  6910. val = 0;
  6911. switch (intel_crtc->config->pipe_bpp) {
  6912. case 18:
  6913. val |= PIPECONF_6BPC;
  6914. break;
  6915. case 24:
  6916. val |= PIPECONF_8BPC;
  6917. break;
  6918. case 30:
  6919. val |= PIPECONF_10BPC;
  6920. break;
  6921. case 36:
  6922. val |= PIPECONF_12BPC;
  6923. break;
  6924. default:
  6925. /* Case prevented by intel_choose_pipe_bpp_dither. */
  6926. BUG();
  6927. }
  6928. if (intel_crtc->config->dither)
  6929. val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
  6930. if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
  6931. val |= PIPECONF_INTERLACED_ILK;
  6932. else
  6933. val |= PIPECONF_PROGRESSIVE;
  6934. if (intel_crtc->config->limited_color_range)
  6935. val |= PIPECONF_COLOR_RANGE_SELECT;
  6936. I915_WRITE(PIPECONF(pipe), val);
  6937. POSTING_READ(PIPECONF(pipe));
  6938. }
  6939. static void haswell_set_pipeconf(struct drm_crtc *crtc)
  6940. {
  6941. struct drm_i915_private *dev_priv = to_i915(crtc->dev);
  6942. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6943. enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
  6944. u32 val = 0;
  6945. if (IS_HASWELL(dev_priv) && intel_crtc->config->dither)
  6946. val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
  6947. if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
  6948. val |= PIPECONF_INTERLACED_ILK;
  6949. else
  6950. val |= PIPECONF_PROGRESSIVE;
  6951. I915_WRITE(PIPECONF(cpu_transcoder), val);
  6952. POSTING_READ(PIPECONF(cpu_transcoder));
  6953. }
  6954. static void haswell_set_pipemisc(struct drm_crtc *crtc)
  6955. {
  6956. struct drm_i915_private *dev_priv = to_i915(crtc->dev);
  6957. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6958. struct intel_crtc_state *config = intel_crtc->config;
  6959. if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) {
  6960. u32 val = 0;
  6961. switch (intel_crtc->config->pipe_bpp) {
  6962. case 18:
  6963. val |= PIPEMISC_DITHER_6_BPC;
  6964. break;
  6965. case 24:
  6966. val |= PIPEMISC_DITHER_8_BPC;
  6967. break;
  6968. case 30:
  6969. val |= PIPEMISC_DITHER_10_BPC;
  6970. break;
  6971. case 36:
  6972. val |= PIPEMISC_DITHER_12_BPC;
  6973. break;
  6974. default:
  6975. /* Case prevented by pipe_config_set_bpp. */
  6976. BUG();
  6977. }
  6978. if (intel_crtc->config->dither)
  6979. val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
  6980. if (config->ycbcr420) {
  6981. val |= PIPEMISC_OUTPUT_COLORSPACE_YUV |
  6982. PIPEMISC_YUV420_ENABLE |
  6983. PIPEMISC_YUV420_MODE_FULL_BLEND;
  6984. }
  6985. I915_WRITE(PIPEMISC(intel_crtc->pipe), val);
  6986. }
  6987. }
  6988. int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
  6989. {
  6990. /*
  6991. * Account for spread spectrum to avoid
  6992. * oversubscribing the link. Max center spread
  6993. * is 2.5%; use 5% for safety's sake.
  6994. */
  6995. u32 bps = target_clock * bpp * 21 / 20;
  6996. return DIV_ROUND_UP(bps, link_bw * 8);
  6997. }
  6998. static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor)
  6999. {
  7000. return i9xx_dpll_compute_m(dpll) < factor * dpll->n;
  7001. }
  7002. static void ironlake_compute_dpll(struct intel_crtc *intel_crtc,
  7003. struct intel_crtc_state *crtc_state,
  7004. struct dpll *reduced_clock)
  7005. {
  7006. struct drm_crtc *crtc = &intel_crtc->base;
  7007. struct drm_device *dev = crtc->dev;
  7008. struct drm_i915_private *dev_priv = to_i915(dev);
  7009. u32 dpll, fp, fp2;
  7010. int factor;
  7011. /* Enable autotuning of the PLL clock (if permissible) */
  7012. factor = 21;
  7013. if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
  7014. if ((intel_panel_use_ssc(dev_priv) &&
  7015. dev_priv->vbt.lvds_ssc_freq == 100000) ||
  7016. (HAS_PCH_IBX(dev_priv) && intel_is_dual_link_lvds(dev)))
  7017. factor = 25;
  7018. } else if (crtc_state->sdvo_tv_clock)
  7019. factor = 20;
  7020. fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
  7021. if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor))
  7022. fp |= FP_CB_TUNE;
  7023. if (reduced_clock) {
  7024. fp2 = i9xx_dpll_compute_fp(reduced_clock);
  7025. if (reduced_clock->m < factor * reduced_clock->n)
  7026. fp2 |= FP_CB_TUNE;
  7027. } else {
  7028. fp2 = fp;
  7029. }
  7030. dpll = 0;
  7031. if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
  7032. dpll |= DPLLB_MODE_LVDS;
  7033. else
  7034. dpll |= DPLLB_MODE_DAC_SERIAL;
  7035. dpll |= (crtc_state->pixel_multiplier - 1)
  7036. << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
  7037. if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
  7038. intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
  7039. dpll |= DPLL_SDVO_HIGH_SPEED;
  7040. if (intel_crtc_has_dp_encoder(crtc_state))
  7041. dpll |= DPLL_SDVO_HIGH_SPEED;
  7042. /*
  7043. * The high speed IO clock is only really required for
  7044. * SDVO/HDMI/DP, but we also enable it for CRT to make it
  7045. * possible to share the DPLL between CRT and HDMI. Enabling
  7046. * the clock needlessly does no real harm, except use up a
  7047. * bit of power potentially.
  7048. *
  7049. * We'll limit this to IVB with 3 pipes, since it has only two
  7050. * DPLLs and so DPLL sharing is the only way to get three pipes
  7051. * driving PCH ports at the same time. On SNB we could do this,
  7052. * and potentially avoid enabling the second DPLL, but it's not
  7053. * clear if it''s a win or loss power wise. No point in doing
  7054. * this on ILK at all since it has a fixed DPLL<->pipe mapping.
  7055. */
  7056. if (INTEL_INFO(dev_priv)->num_pipes == 3 &&
  7057. intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG))
  7058. dpll |= DPLL_SDVO_HIGH_SPEED;
  7059. /* compute bitmask from p1 value */
  7060. dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  7061. /* also FPA1 */
  7062. dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  7063. switch (crtc_state->dpll.p2) {
  7064. case 5:
  7065. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  7066. break;
  7067. case 7:
  7068. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  7069. break;
  7070. case 10:
  7071. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  7072. break;
  7073. case 14:
  7074. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  7075. break;
  7076. }
  7077. if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
  7078. intel_panel_use_ssc(dev_priv))
  7079. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  7080. else
  7081. dpll |= PLL_REF_INPUT_DREFCLK;
  7082. dpll |= DPLL_VCO_ENABLE;
  7083. crtc_state->dpll_hw_state.dpll = dpll;
  7084. crtc_state->dpll_hw_state.fp0 = fp;
  7085. crtc_state->dpll_hw_state.fp1 = fp2;
  7086. }
  7087. static int ironlake_crtc_compute_clock(struct intel_crtc *crtc,
  7088. struct intel_crtc_state *crtc_state)
  7089. {
  7090. struct drm_device *dev = crtc->base.dev;
  7091. struct drm_i915_private *dev_priv = to_i915(dev);
  7092. const struct intel_limit *limit;
  7093. int refclk = 120000;
  7094. memset(&crtc_state->dpll_hw_state, 0,
  7095. sizeof(crtc_state->dpll_hw_state));
  7096. /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
  7097. if (!crtc_state->has_pch_encoder)
  7098. return 0;
  7099. if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
  7100. if (intel_panel_use_ssc(dev_priv)) {
  7101. DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
  7102. dev_priv->vbt.lvds_ssc_freq);
  7103. refclk = dev_priv->vbt.lvds_ssc_freq;
  7104. }
  7105. if (intel_is_dual_link_lvds(dev)) {
  7106. if (refclk == 100000)
  7107. limit = &intel_limits_ironlake_dual_lvds_100m;
  7108. else
  7109. limit = &intel_limits_ironlake_dual_lvds;
  7110. } else {
  7111. if (refclk == 100000)
  7112. limit = &intel_limits_ironlake_single_lvds_100m;
  7113. else
  7114. limit = &intel_limits_ironlake_single_lvds;
  7115. }
  7116. } else {
  7117. limit = &intel_limits_ironlake_dac;
  7118. }
  7119. if (!crtc_state->clock_set &&
  7120. !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
  7121. refclk, NULL, &crtc_state->dpll)) {
  7122. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  7123. return -EINVAL;
  7124. }
  7125. ironlake_compute_dpll(crtc, crtc_state, NULL);
  7126. if (!intel_get_shared_dpll(crtc, crtc_state, NULL)) {
  7127. DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
  7128. pipe_name(crtc->pipe));
  7129. return -EINVAL;
  7130. }
  7131. return 0;
  7132. }
  7133. static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc,
  7134. struct intel_link_m_n *m_n)
  7135. {
  7136. struct drm_device *dev = crtc->base.dev;
  7137. struct drm_i915_private *dev_priv = to_i915(dev);
  7138. enum pipe pipe = crtc->pipe;
  7139. m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe));
  7140. m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe));
  7141. m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe))
  7142. & ~TU_SIZE_MASK;
  7143. m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe));
  7144. m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe))
  7145. & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
  7146. }
  7147. static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc,
  7148. enum transcoder transcoder,
  7149. struct intel_link_m_n *m_n,
  7150. struct intel_link_m_n *m2_n2)
  7151. {
  7152. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  7153. enum pipe pipe = crtc->pipe;
  7154. if (INTEL_GEN(dev_priv) >= 5) {
  7155. m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder));
  7156. m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder));
  7157. m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder))
  7158. & ~TU_SIZE_MASK;
  7159. m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder));
  7160. m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder))
  7161. & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
  7162. /* Read M2_N2 registers only for gen < 8 (M2_N2 available for
  7163. * gen < 8) and if DRRS is supported (to make sure the
  7164. * registers are not unnecessarily read).
  7165. */
  7166. if (m2_n2 && INTEL_GEN(dev_priv) < 8 &&
  7167. crtc->config->has_drrs) {
  7168. m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder));
  7169. m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder));
  7170. m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder))
  7171. & ~TU_SIZE_MASK;
  7172. m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder));
  7173. m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder))
  7174. & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
  7175. }
  7176. } else {
  7177. m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe));
  7178. m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe));
  7179. m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe))
  7180. & ~TU_SIZE_MASK;
  7181. m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe));
  7182. m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe))
  7183. & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
  7184. }
  7185. }
  7186. void intel_dp_get_m_n(struct intel_crtc *crtc,
  7187. struct intel_crtc_state *pipe_config)
  7188. {
  7189. if (pipe_config->has_pch_encoder)
  7190. intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n);
  7191. else
  7192. intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
  7193. &pipe_config->dp_m_n,
  7194. &pipe_config->dp_m2_n2);
  7195. }
  7196. static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc,
  7197. struct intel_crtc_state *pipe_config)
  7198. {
  7199. intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
  7200. &pipe_config->fdi_m_n, NULL);
  7201. }
  7202. static void skylake_get_pfit_config(struct intel_crtc *crtc,
  7203. struct intel_crtc_state *pipe_config)
  7204. {
  7205. struct drm_device *dev = crtc->base.dev;
  7206. struct drm_i915_private *dev_priv = to_i915(dev);
  7207. struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state;
  7208. uint32_t ps_ctrl = 0;
  7209. int id = -1;
  7210. int i;
  7211. /* find scaler attached to this pipe */
  7212. for (i = 0; i < crtc->num_scalers; i++) {
  7213. ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i));
  7214. if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) {
  7215. id = i;
  7216. pipe_config->pch_pfit.enabled = true;
  7217. pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i));
  7218. pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i));
  7219. break;
  7220. }
  7221. }
  7222. scaler_state->scaler_id = id;
  7223. if (id >= 0) {
  7224. scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX);
  7225. } else {
  7226. scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX);
  7227. }
  7228. }
  7229. static void
  7230. skylake_get_initial_plane_config(struct intel_crtc *crtc,
  7231. struct intel_initial_plane_config *plane_config)
  7232. {
  7233. struct drm_device *dev = crtc->base.dev;
  7234. struct drm_i915_private *dev_priv = to_i915(dev);
  7235. struct intel_plane *plane = to_intel_plane(crtc->base.primary);
  7236. enum plane_id plane_id = plane->id;
  7237. enum pipe pipe = crtc->pipe;
  7238. u32 val, base, offset, stride_mult, tiling, alpha;
  7239. int fourcc, pixel_format;
  7240. unsigned int aligned_height;
  7241. struct drm_framebuffer *fb;
  7242. struct intel_framebuffer *intel_fb;
  7243. if (!plane->get_hw_state(plane))
  7244. return;
  7245. intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
  7246. if (!intel_fb) {
  7247. DRM_DEBUG_KMS("failed to alloc fb\n");
  7248. return;
  7249. }
  7250. fb = &intel_fb->base;
  7251. fb->dev = dev;
  7252. val = I915_READ(PLANE_CTL(pipe, plane_id));
  7253. if (INTEL_GEN(dev_priv) >= 11)
  7254. pixel_format = val & ICL_PLANE_CTL_FORMAT_MASK;
  7255. else
  7256. pixel_format = val & PLANE_CTL_FORMAT_MASK;
  7257. if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) {
  7258. alpha = I915_READ(PLANE_COLOR_CTL(pipe, plane_id));
  7259. alpha &= PLANE_COLOR_ALPHA_MASK;
  7260. } else {
  7261. alpha = val & PLANE_CTL_ALPHA_MASK;
  7262. }
  7263. fourcc = skl_format_to_fourcc(pixel_format,
  7264. val & PLANE_CTL_ORDER_RGBX, alpha);
  7265. fb->format = drm_format_info(fourcc);
  7266. tiling = val & PLANE_CTL_TILED_MASK;
  7267. switch (tiling) {
  7268. case PLANE_CTL_TILED_LINEAR:
  7269. fb->modifier = DRM_FORMAT_MOD_LINEAR;
  7270. break;
  7271. case PLANE_CTL_TILED_X:
  7272. plane_config->tiling = I915_TILING_X;
  7273. fb->modifier = I915_FORMAT_MOD_X_TILED;
  7274. break;
  7275. case PLANE_CTL_TILED_Y:
  7276. if (val & PLANE_CTL_DECOMPRESSION_ENABLE)
  7277. fb->modifier = I915_FORMAT_MOD_Y_TILED_CCS;
  7278. else
  7279. fb->modifier = I915_FORMAT_MOD_Y_TILED;
  7280. break;
  7281. case PLANE_CTL_TILED_YF:
  7282. if (val & PLANE_CTL_DECOMPRESSION_ENABLE)
  7283. fb->modifier = I915_FORMAT_MOD_Yf_TILED_CCS;
  7284. else
  7285. fb->modifier = I915_FORMAT_MOD_Yf_TILED;
  7286. break;
  7287. default:
  7288. MISSING_CASE(tiling);
  7289. goto error;
  7290. }
  7291. base = I915_READ(PLANE_SURF(pipe, plane_id)) & 0xfffff000;
  7292. plane_config->base = base;
  7293. offset = I915_READ(PLANE_OFFSET(pipe, plane_id));
  7294. val = I915_READ(PLANE_SIZE(pipe, plane_id));
  7295. fb->height = ((val >> 16) & 0xfff) + 1;
  7296. fb->width = ((val >> 0) & 0x1fff) + 1;
  7297. val = I915_READ(PLANE_STRIDE(pipe, plane_id));
  7298. stride_mult = intel_fb_stride_alignment(fb, 0);
  7299. fb->pitches[0] = (val & 0x3ff) * stride_mult;
  7300. aligned_height = intel_fb_align_height(fb, 0, fb->height);
  7301. plane_config->size = fb->pitches[0] * aligned_height;
  7302. DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
  7303. crtc->base.name, plane->base.name, fb->width, fb->height,
  7304. fb->format->cpp[0] * 8, base, fb->pitches[0],
  7305. plane_config->size);
  7306. plane_config->fb = intel_fb;
  7307. return;
  7308. error:
  7309. kfree(intel_fb);
  7310. }
  7311. static void ironlake_get_pfit_config(struct intel_crtc *crtc,
  7312. struct intel_crtc_state *pipe_config)
  7313. {
  7314. struct drm_device *dev = crtc->base.dev;
  7315. struct drm_i915_private *dev_priv = to_i915(dev);
  7316. uint32_t tmp;
  7317. tmp = I915_READ(PF_CTL(crtc->pipe));
  7318. if (tmp & PF_ENABLE) {
  7319. pipe_config->pch_pfit.enabled = true;
  7320. pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe));
  7321. pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe));
  7322. /* We currently do not free assignements of panel fitters on
  7323. * ivb/hsw (since we don't use the higher upscaling modes which
  7324. * differentiates them) so just WARN about this case for now. */
  7325. if (IS_GEN7(dev_priv)) {
  7326. WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) !=
  7327. PF_PIPE_SEL_IVB(crtc->pipe));
  7328. }
  7329. }
  7330. }
  7331. static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
  7332. struct intel_crtc_state *pipe_config)
  7333. {
  7334. struct drm_device *dev = crtc->base.dev;
  7335. struct drm_i915_private *dev_priv = to_i915(dev);
  7336. enum intel_display_power_domain power_domain;
  7337. uint32_t tmp;
  7338. bool ret;
  7339. power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
  7340. if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
  7341. return false;
  7342. pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
  7343. pipe_config->shared_dpll = NULL;
  7344. ret = false;
  7345. tmp = I915_READ(PIPECONF(crtc->pipe));
  7346. if (!(tmp & PIPECONF_ENABLE))
  7347. goto out;
  7348. switch (tmp & PIPECONF_BPC_MASK) {
  7349. case PIPECONF_6BPC:
  7350. pipe_config->pipe_bpp = 18;
  7351. break;
  7352. case PIPECONF_8BPC:
  7353. pipe_config->pipe_bpp = 24;
  7354. break;
  7355. case PIPECONF_10BPC:
  7356. pipe_config->pipe_bpp = 30;
  7357. break;
  7358. case PIPECONF_12BPC:
  7359. pipe_config->pipe_bpp = 36;
  7360. break;
  7361. default:
  7362. break;
  7363. }
  7364. if (tmp & PIPECONF_COLOR_RANGE_SELECT)
  7365. pipe_config->limited_color_range = true;
  7366. if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) {
  7367. struct intel_shared_dpll *pll;
  7368. enum intel_dpll_id pll_id;
  7369. pipe_config->has_pch_encoder = true;
  7370. tmp = I915_READ(FDI_RX_CTL(crtc->pipe));
  7371. pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
  7372. FDI_DP_PORT_WIDTH_SHIFT) + 1;
  7373. ironlake_get_fdi_m_n_config(crtc, pipe_config);
  7374. if (HAS_PCH_IBX(dev_priv)) {
  7375. /*
  7376. * The pipe->pch transcoder and pch transcoder->pll
  7377. * mapping is fixed.
  7378. */
  7379. pll_id = (enum intel_dpll_id) crtc->pipe;
  7380. } else {
  7381. tmp = I915_READ(PCH_DPLL_SEL);
  7382. if (tmp & TRANS_DPLLB_SEL(crtc->pipe))
  7383. pll_id = DPLL_ID_PCH_PLL_B;
  7384. else
  7385. pll_id= DPLL_ID_PCH_PLL_A;
  7386. }
  7387. pipe_config->shared_dpll =
  7388. intel_get_shared_dpll_by_id(dev_priv, pll_id);
  7389. pll = pipe_config->shared_dpll;
  7390. WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll,
  7391. &pipe_config->dpll_hw_state));
  7392. tmp = pipe_config->dpll_hw_state.dpll;
  7393. pipe_config->pixel_multiplier =
  7394. ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK)
  7395. >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1;
  7396. ironlake_pch_clock_get(crtc, pipe_config);
  7397. } else {
  7398. pipe_config->pixel_multiplier = 1;
  7399. }
  7400. intel_get_pipe_timings(crtc, pipe_config);
  7401. intel_get_pipe_src_size(crtc, pipe_config);
  7402. ironlake_get_pfit_config(crtc, pipe_config);
  7403. ret = true;
  7404. out:
  7405. intel_display_power_put(dev_priv, power_domain);
  7406. return ret;
  7407. }
  7408. static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv)
  7409. {
  7410. struct drm_device *dev = &dev_priv->drm;
  7411. struct intel_crtc *crtc;
  7412. for_each_intel_crtc(dev, crtc)
  7413. I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n",
  7414. pipe_name(crtc->pipe));
  7415. I915_STATE_WARN(I915_READ(HSW_PWR_WELL_CTL_DRIVER(HSW_DISP_PW_GLOBAL)),
  7416. "Display power well on\n");
  7417. I915_STATE_WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n");
  7418. I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n");
  7419. I915_STATE_WARN(I915_READ(WRPLL_CTL(1)) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n");
  7420. I915_STATE_WARN(I915_READ(PP_STATUS(0)) & PP_ON, "Panel power on\n");
  7421. I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE,
  7422. "CPU PWM1 enabled\n");
  7423. if (IS_HASWELL(dev_priv))
  7424. I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE,
  7425. "CPU PWM2 enabled\n");
  7426. I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE,
  7427. "PCH PWM1 enabled\n");
  7428. I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
  7429. "Utility pin enabled\n");
  7430. I915_STATE_WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n");
  7431. /*
  7432. * In theory we can still leave IRQs enabled, as long as only the HPD
  7433. * interrupts remain enabled. We used to check for that, but since it's
  7434. * gen-specific and since we only disable LCPLL after we fully disable
  7435. * the interrupts, the check below should be enough.
  7436. */
  7437. I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n");
  7438. }
  7439. static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv)
  7440. {
  7441. if (IS_HASWELL(dev_priv))
  7442. return I915_READ(D_COMP_HSW);
  7443. else
  7444. return I915_READ(D_COMP_BDW);
  7445. }
  7446. static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val)
  7447. {
  7448. if (IS_HASWELL(dev_priv)) {
  7449. mutex_lock(&dev_priv->pcu_lock);
  7450. if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP,
  7451. val))
  7452. DRM_DEBUG_KMS("Failed to write to D_COMP\n");
  7453. mutex_unlock(&dev_priv->pcu_lock);
  7454. } else {
  7455. I915_WRITE(D_COMP_BDW, val);
  7456. POSTING_READ(D_COMP_BDW);
  7457. }
  7458. }
  7459. /*
  7460. * This function implements pieces of two sequences from BSpec:
  7461. * - Sequence for display software to disable LCPLL
  7462. * - Sequence for display software to allow package C8+
  7463. * The steps implemented here are just the steps that actually touch the LCPLL
  7464. * register. Callers should take care of disabling all the display engine
  7465. * functions, doing the mode unset, fixing interrupts, etc.
  7466. */
  7467. static void hsw_disable_lcpll(struct drm_i915_private *dev_priv,
  7468. bool switch_to_fclk, bool allow_power_down)
  7469. {
  7470. uint32_t val;
  7471. assert_can_disable_lcpll(dev_priv);
  7472. val = I915_READ(LCPLL_CTL);
  7473. if (switch_to_fclk) {
  7474. val |= LCPLL_CD_SOURCE_FCLK;
  7475. I915_WRITE(LCPLL_CTL, val);
  7476. if (wait_for_us(I915_READ(LCPLL_CTL) &
  7477. LCPLL_CD_SOURCE_FCLK_DONE, 1))
  7478. DRM_ERROR("Switching to FCLK failed\n");
  7479. val = I915_READ(LCPLL_CTL);
  7480. }
  7481. val |= LCPLL_PLL_DISABLE;
  7482. I915_WRITE(LCPLL_CTL, val);
  7483. POSTING_READ(LCPLL_CTL);
  7484. if (intel_wait_for_register(dev_priv, LCPLL_CTL, LCPLL_PLL_LOCK, 0, 1))
  7485. DRM_ERROR("LCPLL still locked\n");
  7486. val = hsw_read_dcomp(dev_priv);
  7487. val |= D_COMP_COMP_DISABLE;
  7488. hsw_write_dcomp(dev_priv, val);
  7489. ndelay(100);
  7490. if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0,
  7491. 1))
  7492. DRM_ERROR("D_COMP RCOMP still in progress\n");
  7493. if (allow_power_down) {
  7494. val = I915_READ(LCPLL_CTL);
  7495. val |= LCPLL_POWER_DOWN_ALLOW;
  7496. I915_WRITE(LCPLL_CTL, val);
  7497. POSTING_READ(LCPLL_CTL);
  7498. }
  7499. }
  7500. /*
  7501. * Fully restores LCPLL, disallowing power down and switching back to LCPLL
  7502. * source.
  7503. */
  7504. static void hsw_restore_lcpll(struct drm_i915_private *dev_priv)
  7505. {
  7506. uint32_t val;
  7507. val = I915_READ(LCPLL_CTL);
  7508. if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK |
  7509. LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK)
  7510. return;
  7511. /*
  7512. * Make sure we're not on PC8 state before disabling PC8, otherwise
  7513. * we'll hang the machine. To prevent PC8 state, just enable force_wake.
  7514. */
  7515. intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
  7516. if (val & LCPLL_POWER_DOWN_ALLOW) {
  7517. val &= ~LCPLL_POWER_DOWN_ALLOW;
  7518. I915_WRITE(LCPLL_CTL, val);
  7519. POSTING_READ(LCPLL_CTL);
  7520. }
  7521. val = hsw_read_dcomp(dev_priv);
  7522. val |= D_COMP_COMP_FORCE;
  7523. val &= ~D_COMP_COMP_DISABLE;
  7524. hsw_write_dcomp(dev_priv, val);
  7525. val = I915_READ(LCPLL_CTL);
  7526. val &= ~LCPLL_PLL_DISABLE;
  7527. I915_WRITE(LCPLL_CTL, val);
  7528. if (intel_wait_for_register(dev_priv,
  7529. LCPLL_CTL, LCPLL_PLL_LOCK, LCPLL_PLL_LOCK,
  7530. 5))
  7531. DRM_ERROR("LCPLL not locked yet\n");
  7532. if (val & LCPLL_CD_SOURCE_FCLK) {
  7533. val = I915_READ(LCPLL_CTL);
  7534. val &= ~LCPLL_CD_SOURCE_FCLK;
  7535. I915_WRITE(LCPLL_CTL, val);
  7536. if (wait_for_us((I915_READ(LCPLL_CTL) &
  7537. LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1))
  7538. DRM_ERROR("Switching back to LCPLL failed\n");
  7539. }
  7540. intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
  7541. intel_update_cdclk(dev_priv);
  7542. intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK");
  7543. }
  7544. /*
  7545. * Package states C8 and deeper are really deep PC states that can only be
  7546. * reached when all the devices on the system allow it, so even if the graphics
  7547. * device allows PC8+, it doesn't mean the system will actually get to these
  7548. * states. Our driver only allows PC8+ when going into runtime PM.
  7549. *
  7550. * The requirements for PC8+ are that all the outputs are disabled, the power
  7551. * well is disabled and most interrupts are disabled, and these are also
  7552. * requirements for runtime PM. When these conditions are met, we manually do
  7553. * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
  7554. * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
  7555. * hang the machine.
  7556. *
  7557. * When we really reach PC8 or deeper states (not just when we allow it) we lose
  7558. * the state of some registers, so when we come back from PC8+ we need to
  7559. * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
  7560. * need to take care of the registers kept by RC6. Notice that this happens even
  7561. * if we don't put the device in PCI D3 state (which is what currently happens
  7562. * because of the runtime PM support).
  7563. *
  7564. * For more, read "Display Sequences for Package C8" on the hardware
  7565. * documentation.
  7566. */
  7567. void hsw_enable_pc8(struct drm_i915_private *dev_priv)
  7568. {
  7569. uint32_t val;
  7570. DRM_DEBUG_KMS("Enabling package C8+\n");
  7571. if (HAS_PCH_LPT_LP(dev_priv)) {
  7572. val = I915_READ(SOUTH_DSPCLK_GATE_D);
  7573. val &= ~PCH_LP_PARTITION_LEVEL_DISABLE;
  7574. I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
  7575. }
  7576. lpt_disable_clkout_dp(dev_priv);
  7577. hsw_disable_lcpll(dev_priv, true, true);
  7578. }
  7579. void hsw_disable_pc8(struct drm_i915_private *dev_priv)
  7580. {
  7581. uint32_t val;
  7582. DRM_DEBUG_KMS("Disabling package C8+\n");
  7583. hsw_restore_lcpll(dev_priv);
  7584. lpt_init_pch_refclk(dev_priv);
  7585. if (HAS_PCH_LPT_LP(dev_priv)) {
  7586. val = I915_READ(SOUTH_DSPCLK_GATE_D);
  7587. val |= PCH_LP_PARTITION_LEVEL_DISABLE;
  7588. I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
  7589. }
  7590. }
  7591. static int haswell_crtc_compute_clock(struct intel_crtc *crtc,
  7592. struct intel_crtc_state *crtc_state)
  7593. {
  7594. if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DSI)) {
  7595. struct intel_encoder *encoder =
  7596. intel_ddi_get_crtc_new_encoder(crtc_state);
  7597. if (!intel_get_shared_dpll(crtc, crtc_state, encoder)) {
  7598. DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
  7599. pipe_name(crtc->pipe));
  7600. return -EINVAL;
  7601. }
  7602. }
  7603. return 0;
  7604. }
  7605. static void cannonlake_get_ddi_pll(struct drm_i915_private *dev_priv,
  7606. enum port port,
  7607. struct intel_crtc_state *pipe_config)
  7608. {
  7609. enum intel_dpll_id id;
  7610. u32 temp;
  7611. temp = I915_READ(DPCLKA_CFGCR0) & DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port);
  7612. id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port);
  7613. if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL2))
  7614. return;
  7615. pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
  7616. }
  7617. static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv,
  7618. enum port port,
  7619. struct intel_crtc_state *pipe_config)
  7620. {
  7621. enum intel_dpll_id id;
  7622. switch (port) {
  7623. case PORT_A:
  7624. id = DPLL_ID_SKL_DPLL0;
  7625. break;
  7626. case PORT_B:
  7627. id = DPLL_ID_SKL_DPLL1;
  7628. break;
  7629. case PORT_C:
  7630. id = DPLL_ID_SKL_DPLL2;
  7631. break;
  7632. default:
  7633. DRM_ERROR("Incorrect port type\n");
  7634. return;
  7635. }
  7636. pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
  7637. }
  7638. static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv,
  7639. enum port port,
  7640. struct intel_crtc_state *pipe_config)
  7641. {
  7642. enum intel_dpll_id id;
  7643. u32 temp;
  7644. temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port);
  7645. id = temp >> (port * 3 + 1);
  7646. if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL3))
  7647. return;
  7648. pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
  7649. }
  7650. static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv,
  7651. enum port port,
  7652. struct intel_crtc_state *pipe_config)
  7653. {
  7654. enum intel_dpll_id id;
  7655. uint32_t ddi_pll_sel = I915_READ(PORT_CLK_SEL(port));
  7656. switch (ddi_pll_sel) {
  7657. case PORT_CLK_SEL_WRPLL1:
  7658. id = DPLL_ID_WRPLL1;
  7659. break;
  7660. case PORT_CLK_SEL_WRPLL2:
  7661. id = DPLL_ID_WRPLL2;
  7662. break;
  7663. case PORT_CLK_SEL_SPLL:
  7664. id = DPLL_ID_SPLL;
  7665. break;
  7666. case PORT_CLK_SEL_LCPLL_810:
  7667. id = DPLL_ID_LCPLL_810;
  7668. break;
  7669. case PORT_CLK_SEL_LCPLL_1350:
  7670. id = DPLL_ID_LCPLL_1350;
  7671. break;
  7672. case PORT_CLK_SEL_LCPLL_2700:
  7673. id = DPLL_ID_LCPLL_2700;
  7674. break;
  7675. default:
  7676. MISSING_CASE(ddi_pll_sel);
  7677. /* fall through */
  7678. case PORT_CLK_SEL_NONE:
  7679. return;
  7680. }
  7681. pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
  7682. }
  7683. static bool hsw_get_transcoder_state(struct intel_crtc *crtc,
  7684. struct intel_crtc_state *pipe_config,
  7685. u64 *power_domain_mask)
  7686. {
  7687. struct drm_device *dev = crtc->base.dev;
  7688. struct drm_i915_private *dev_priv = to_i915(dev);
  7689. enum intel_display_power_domain power_domain;
  7690. u32 tmp;
  7691. /*
  7692. * The pipe->transcoder mapping is fixed with the exception of the eDP
  7693. * transcoder handled below.
  7694. */
  7695. pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
  7696. /*
  7697. * XXX: Do intel_display_power_get_if_enabled before reading this (for
  7698. * consistency and less surprising code; it's in always on power).
  7699. */
  7700. tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
  7701. if (tmp & TRANS_DDI_FUNC_ENABLE) {
  7702. enum pipe trans_edp_pipe;
  7703. switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
  7704. default:
  7705. WARN(1, "unknown pipe linked to edp transcoder\n");
  7706. case TRANS_DDI_EDP_INPUT_A_ONOFF:
  7707. case TRANS_DDI_EDP_INPUT_A_ON:
  7708. trans_edp_pipe = PIPE_A;
  7709. break;
  7710. case TRANS_DDI_EDP_INPUT_B_ONOFF:
  7711. trans_edp_pipe = PIPE_B;
  7712. break;
  7713. case TRANS_DDI_EDP_INPUT_C_ONOFF:
  7714. trans_edp_pipe = PIPE_C;
  7715. break;
  7716. }
  7717. if (trans_edp_pipe == crtc->pipe)
  7718. pipe_config->cpu_transcoder = TRANSCODER_EDP;
  7719. }
  7720. power_domain = POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder);
  7721. if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
  7722. return false;
  7723. *power_domain_mask |= BIT_ULL(power_domain);
  7724. tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder));
  7725. return tmp & PIPECONF_ENABLE;
  7726. }
  7727. static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc,
  7728. struct intel_crtc_state *pipe_config,
  7729. u64 *power_domain_mask)
  7730. {
  7731. struct drm_device *dev = crtc->base.dev;
  7732. struct drm_i915_private *dev_priv = to_i915(dev);
  7733. enum intel_display_power_domain power_domain;
  7734. enum port port;
  7735. enum transcoder cpu_transcoder;
  7736. u32 tmp;
  7737. for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) {
  7738. if (port == PORT_A)
  7739. cpu_transcoder = TRANSCODER_DSI_A;
  7740. else
  7741. cpu_transcoder = TRANSCODER_DSI_C;
  7742. power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
  7743. if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
  7744. continue;
  7745. *power_domain_mask |= BIT_ULL(power_domain);
  7746. /*
  7747. * The PLL needs to be enabled with a valid divider
  7748. * configuration, otherwise accessing DSI registers will hang
  7749. * the machine. See BSpec North Display Engine
  7750. * registers/MIPI[BXT]. We can break out here early, since we
  7751. * need the same DSI PLL to be enabled for both DSI ports.
  7752. */
  7753. if (!intel_dsi_pll_is_enabled(dev_priv))
  7754. break;
  7755. /* XXX: this works for video mode only */
  7756. tmp = I915_READ(BXT_MIPI_PORT_CTRL(port));
  7757. if (!(tmp & DPI_ENABLE))
  7758. continue;
  7759. tmp = I915_READ(MIPI_CTRL(port));
  7760. if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe))
  7761. continue;
  7762. pipe_config->cpu_transcoder = cpu_transcoder;
  7763. break;
  7764. }
  7765. return transcoder_is_dsi(pipe_config->cpu_transcoder);
  7766. }
  7767. static void haswell_get_ddi_port_state(struct intel_crtc *crtc,
  7768. struct intel_crtc_state *pipe_config)
  7769. {
  7770. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  7771. struct intel_shared_dpll *pll;
  7772. enum port port;
  7773. uint32_t tmp;
  7774. tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder));
  7775. port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT;
  7776. if (IS_CANNONLAKE(dev_priv))
  7777. cannonlake_get_ddi_pll(dev_priv, port, pipe_config);
  7778. else if (IS_GEN9_BC(dev_priv))
  7779. skylake_get_ddi_pll(dev_priv, port, pipe_config);
  7780. else if (IS_GEN9_LP(dev_priv))
  7781. bxt_get_ddi_pll(dev_priv, port, pipe_config);
  7782. else
  7783. haswell_get_ddi_pll(dev_priv, port, pipe_config);
  7784. pll = pipe_config->shared_dpll;
  7785. if (pll) {
  7786. WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll,
  7787. &pipe_config->dpll_hw_state));
  7788. }
  7789. /*
  7790. * Haswell has only FDI/PCH transcoder A. It is which is connected to
  7791. * DDI E. So just check whether this pipe is wired to DDI E and whether
  7792. * the PCH transcoder is on.
  7793. */
  7794. if (INTEL_GEN(dev_priv) < 9 &&
  7795. (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) {
  7796. pipe_config->has_pch_encoder = true;
  7797. tmp = I915_READ(FDI_RX_CTL(PIPE_A));
  7798. pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
  7799. FDI_DP_PORT_WIDTH_SHIFT) + 1;
  7800. ironlake_get_fdi_m_n_config(crtc, pipe_config);
  7801. }
  7802. }
  7803. static bool haswell_get_pipe_config(struct intel_crtc *crtc,
  7804. struct intel_crtc_state *pipe_config)
  7805. {
  7806. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  7807. enum intel_display_power_domain power_domain;
  7808. u64 power_domain_mask;
  7809. bool active;
  7810. intel_crtc_init_scalers(crtc, pipe_config);
  7811. power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
  7812. if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
  7813. return false;
  7814. power_domain_mask = BIT_ULL(power_domain);
  7815. pipe_config->shared_dpll = NULL;
  7816. active = hsw_get_transcoder_state(crtc, pipe_config, &power_domain_mask);
  7817. if (IS_GEN9_LP(dev_priv) &&
  7818. bxt_get_dsi_transcoder_state(crtc, pipe_config, &power_domain_mask)) {
  7819. WARN_ON(active);
  7820. active = true;
  7821. }
  7822. if (!active)
  7823. goto out;
  7824. if (!transcoder_is_dsi(pipe_config->cpu_transcoder)) {
  7825. haswell_get_ddi_port_state(crtc, pipe_config);
  7826. intel_get_pipe_timings(crtc, pipe_config);
  7827. }
  7828. intel_get_pipe_src_size(crtc, pipe_config);
  7829. pipe_config->gamma_mode =
  7830. I915_READ(GAMMA_MODE(crtc->pipe)) & GAMMA_MODE_MODE_MASK;
  7831. if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) {
  7832. u32 tmp = I915_READ(PIPEMISC(crtc->pipe));
  7833. bool clrspace_yuv = tmp & PIPEMISC_OUTPUT_COLORSPACE_YUV;
  7834. if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 10) {
  7835. bool blend_mode_420 = tmp &
  7836. PIPEMISC_YUV420_MODE_FULL_BLEND;
  7837. pipe_config->ycbcr420 = tmp & PIPEMISC_YUV420_ENABLE;
  7838. if (pipe_config->ycbcr420 != clrspace_yuv ||
  7839. pipe_config->ycbcr420 != blend_mode_420)
  7840. DRM_DEBUG_KMS("Bad 4:2:0 mode (%08x)\n", tmp);
  7841. } else if (clrspace_yuv) {
  7842. DRM_DEBUG_KMS("YCbCr 4:2:0 Unsupported\n");
  7843. }
  7844. }
  7845. power_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe);
  7846. if (intel_display_power_get_if_enabled(dev_priv, power_domain)) {
  7847. power_domain_mask |= BIT_ULL(power_domain);
  7848. if (INTEL_GEN(dev_priv) >= 9)
  7849. skylake_get_pfit_config(crtc, pipe_config);
  7850. else
  7851. ironlake_get_pfit_config(crtc, pipe_config);
  7852. }
  7853. if (hsw_crtc_supports_ips(crtc)) {
  7854. if (IS_HASWELL(dev_priv))
  7855. pipe_config->ips_enabled = I915_READ(IPS_CTL) & IPS_ENABLE;
  7856. else {
  7857. /*
  7858. * We cannot readout IPS state on broadwell, set to
  7859. * true so we can set it to a defined state on first
  7860. * commit.
  7861. */
  7862. pipe_config->ips_enabled = true;
  7863. }
  7864. }
  7865. if (pipe_config->cpu_transcoder != TRANSCODER_EDP &&
  7866. !transcoder_is_dsi(pipe_config->cpu_transcoder)) {
  7867. pipe_config->pixel_multiplier =
  7868. I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1;
  7869. } else {
  7870. pipe_config->pixel_multiplier = 1;
  7871. }
  7872. out:
  7873. for_each_power_domain(power_domain, power_domain_mask)
  7874. intel_display_power_put(dev_priv, power_domain);
  7875. return active;
  7876. }
  7877. static u32 intel_cursor_base(const struct intel_plane_state *plane_state)
  7878. {
  7879. struct drm_i915_private *dev_priv =
  7880. to_i915(plane_state->base.plane->dev);
  7881. const struct drm_framebuffer *fb = plane_state->base.fb;
  7882. const struct drm_i915_gem_object *obj = intel_fb_obj(fb);
  7883. u32 base;
  7884. if (INTEL_INFO(dev_priv)->cursor_needs_physical)
  7885. base = obj->phys_handle->busaddr;
  7886. else
  7887. base = intel_plane_ggtt_offset(plane_state);
  7888. base += plane_state->main.offset;
  7889. /* ILK+ do this automagically */
  7890. if (HAS_GMCH_DISPLAY(dev_priv) &&
  7891. plane_state->base.rotation & DRM_MODE_ROTATE_180)
  7892. base += (plane_state->base.crtc_h *
  7893. plane_state->base.crtc_w - 1) * fb->format->cpp[0];
  7894. return base;
  7895. }
  7896. static u32 intel_cursor_position(const struct intel_plane_state *plane_state)
  7897. {
  7898. int x = plane_state->base.crtc_x;
  7899. int y = plane_state->base.crtc_y;
  7900. u32 pos = 0;
  7901. if (x < 0) {
  7902. pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
  7903. x = -x;
  7904. }
  7905. pos |= x << CURSOR_X_SHIFT;
  7906. if (y < 0) {
  7907. pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
  7908. y = -y;
  7909. }
  7910. pos |= y << CURSOR_Y_SHIFT;
  7911. return pos;
  7912. }
  7913. static bool intel_cursor_size_ok(const struct intel_plane_state *plane_state)
  7914. {
  7915. const struct drm_mode_config *config =
  7916. &plane_state->base.plane->dev->mode_config;
  7917. int width = plane_state->base.crtc_w;
  7918. int height = plane_state->base.crtc_h;
  7919. return width > 0 && width <= config->cursor_width &&
  7920. height > 0 && height <= config->cursor_height;
  7921. }
  7922. static int intel_check_cursor(struct intel_crtc_state *crtc_state,
  7923. struct intel_plane_state *plane_state)
  7924. {
  7925. const struct drm_framebuffer *fb = plane_state->base.fb;
  7926. int src_x, src_y;
  7927. u32 offset;
  7928. int ret;
  7929. ret = drm_atomic_helper_check_plane_state(&plane_state->base,
  7930. &crtc_state->base,
  7931. DRM_PLANE_HELPER_NO_SCALING,
  7932. DRM_PLANE_HELPER_NO_SCALING,
  7933. true, true);
  7934. if (ret)
  7935. return ret;
  7936. if (!fb)
  7937. return 0;
  7938. if (fb->modifier != DRM_FORMAT_MOD_LINEAR) {
  7939. DRM_DEBUG_KMS("cursor cannot be tiled\n");
  7940. return -EINVAL;
  7941. }
  7942. src_x = plane_state->base.src_x >> 16;
  7943. src_y = plane_state->base.src_y >> 16;
  7944. intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
  7945. offset = intel_compute_tile_offset(&src_x, &src_y, plane_state, 0);
  7946. if (src_x != 0 || src_y != 0) {
  7947. DRM_DEBUG_KMS("Arbitrary cursor panning not supported\n");
  7948. return -EINVAL;
  7949. }
  7950. plane_state->main.offset = offset;
  7951. return 0;
  7952. }
  7953. static u32 i845_cursor_ctl(const struct intel_crtc_state *crtc_state,
  7954. const struct intel_plane_state *plane_state)
  7955. {
  7956. const struct drm_framebuffer *fb = plane_state->base.fb;
  7957. return CURSOR_ENABLE |
  7958. CURSOR_GAMMA_ENABLE |
  7959. CURSOR_FORMAT_ARGB |
  7960. CURSOR_STRIDE(fb->pitches[0]);
  7961. }
  7962. static bool i845_cursor_size_ok(const struct intel_plane_state *plane_state)
  7963. {
  7964. int width = plane_state->base.crtc_w;
  7965. /*
  7966. * 845g/865g are only limited by the width of their cursors,
  7967. * the height is arbitrary up to the precision of the register.
  7968. */
  7969. return intel_cursor_size_ok(plane_state) && IS_ALIGNED(width, 64);
  7970. }
  7971. static int i845_check_cursor(struct intel_plane *plane,
  7972. struct intel_crtc_state *crtc_state,
  7973. struct intel_plane_state *plane_state)
  7974. {
  7975. const struct drm_framebuffer *fb = plane_state->base.fb;
  7976. int ret;
  7977. ret = intel_check_cursor(crtc_state, plane_state);
  7978. if (ret)
  7979. return ret;
  7980. /* if we want to turn off the cursor ignore width and height */
  7981. if (!fb)
  7982. return 0;
  7983. /* Check for which cursor types we support */
  7984. if (!i845_cursor_size_ok(plane_state)) {
  7985. DRM_DEBUG("Cursor dimension %dx%d not supported\n",
  7986. plane_state->base.crtc_w,
  7987. plane_state->base.crtc_h);
  7988. return -EINVAL;
  7989. }
  7990. switch (fb->pitches[0]) {
  7991. case 256:
  7992. case 512:
  7993. case 1024:
  7994. case 2048:
  7995. break;
  7996. default:
  7997. DRM_DEBUG_KMS("Invalid cursor stride (%u)\n",
  7998. fb->pitches[0]);
  7999. return -EINVAL;
  8000. }
  8001. plane_state->ctl = i845_cursor_ctl(crtc_state, plane_state);
  8002. return 0;
  8003. }
  8004. static void i845_update_cursor(struct intel_plane *plane,
  8005. const struct intel_crtc_state *crtc_state,
  8006. const struct intel_plane_state *plane_state)
  8007. {
  8008. struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
  8009. u32 cntl = 0, base = 0, pos = 0, size = 0;
  8010. unsigned long irqflags;
  8011. if (plane_state && plane_state->base.visible) {
  8012. unsigned int width = plane_state->base.crtc_w;
  8013. unsigned int height = plane_state->base.crtc_h;
  8014. cntl = plane_state->ctl;
  8015. size = (height << 12) | width;
  8016. base = intel_cursor_base(plane_state);
  8017. pos = intel_cursor_position(plane_state);
  8018. }
  8019. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  8020. /* On these chipsets we can only modify the base/size/stride
  8021. * whilst the cursor is disabled.
  8022. */
  8023. if (plane->cursor.base != base ||
  8024. plane->cursor.size != size ||
  8025. plane->cursor.cntl != cntl) {
  8026. I915_WRITE_FW(CURCNTR(PIPE_A), 0);
  8027. I915_WRITE_FW(CURBASE(PIPE_A), base);
  8028. I915_WRITE_FW(CURSIZE, size);
  8029. I915_WRITE_FW(CURPOS(PIPE_A), pos);
  8030. I915_WRITE_FW(CURCNTR(PIPE_A), cntl);
  8031. plane->cursor.base = base;
  8032. plane->cursor.size = size;
  8033. plane->cursor.cntl = cntl;
  8034. } else {
  8035. I915_WRITE_FW(CURPOS(PIPE_A), pos);
  8036. }
  8037. POSTING_READ_FW(CURCNTR(PIPE_A));
  8038. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  8039. }
  8040. static void i845_disable_cursor(struct intel_plane *plane,
  8041. struct intel_crtc *crtc)
  8042. {
  8043. i845_update_cursor(plane, NULL, NULL);
  8044. }
  8045. static bool i845_cursor_get_hw_state(struct intel_plane *plane)
  8046. {
  8047. struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
  8048. enum intel_display_power_domain power_domain;
  8049. bool ret;
  8050. power_domain = POWER_DOMAIN_PIPE(PIPE_A);
  8051. if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
  8052. return false;
  8053. ret = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
  8054. intel_display_power_put(dev_priv, power_domain);
  8055. return ret;
  8056. }
  8057. static u32 i9xx_cursor_ctl(const struct intel_crtc_state *crtc_state,
  8058. const struct intel_plane_state *plane_state)
  8059. {
  8060. struct drm_i915_private *dev_priv =
  8061. to_i915(plane_state->base.plane->dev);
  8062. struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
  8063. u32 cntl;
  8064. cntl = MCURSOR_GAMMA_ENABLE;
  8065. if (HAS_DDI(dev_priv))
  8066. cntl |= CURSOR_PIPE_CSC_ENABLE;
  8067. if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
  8068. cntl |= MCURSOR_PIPE_SELECT(crtc->pipe);
  8069. switch (plane_state->base.crtc_w) {
  8070. case 64:
  8071. cntl |= CURSOR_MODE_64_ARGB_AX;
  8072. break;
  8073. case 128:
  8074. cntl |= CURSOR_MODE_128_ARGB_AX;
  8075. break;
  8076. case 256:
  8077. cntl |= CURSOR_MODE_256_ARGB_AX;
  8078. break;
  8079. default:
  8080. MISSING_CASE(plane_state->base.crtc_w);
  8081. return 0;
  8082. }
  8083. if (plane_state->base.rotation & DRM_MODE_ROTATE_180)
  8084. cntl |= CURSOR_ROTATE_180;
  8085. return cntl;
  8086. }
  8087. static bool i9xx_cursor_size_ok(const struct intel_plane_state *plane_state)
  8088. {
  8089. struct drm_i915_private *dev_priv =
  8090. to_i915(plane_state->base.plane->dev);
  8091. int width = plane_state->base.crtc_w;
  8092. int height = plane_state->base.crtc_h;
  8093. if (!intel_cursor_size_ok(plane_state))
  8094. return false;
  8095. /* Cursor width is limited to a few power-of-two sizes */
  8096. switch (width) {
  8097. case 256:
  8098. case 128:
  8099. case 64:
  8100. break;
  8101. default:
  8102. return false;
  8103. }
  8104. /*
  8105. * IVB+ have CUR_FBC_CTL which allows an arbitrary cursor
  8106. * height from 8 lines up to the cursor width, when the
  8107. * cursor is not rotated. Everything else requires square
  8108. * cursors.
  8109. */
  8110. if (HAS_CUR_FBC(dev_priv) &&
  8111. plane_state->base.rotation & DRM_MODE_ROTATE_0) {
  8112. if (height < 8 || height > width)
  8113. return false;
  8114. } else {
  8115. if (height != width)
  8116. return false;
  8117. }
  8118. return true;
  8119. }
  8120. static int i9xx_check_cursor(struct intel_plane *plane,
  8121. struct intel_crtc_state *crtc_state,
  8122. struct intel_plane_state *plane_state)
  8123. {
  8124. struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
  8125. const struct drm_framebuffer *fb = plane_state->base.fb;
  8126. enum pipe pipe = plane->pipe;
  8127. int ret;
  8128. ret = intel_check_cursor(crtc_state, plane_state);
  8129. if (ret)
  8130. return ret;
  8131. /* if we want to turn off the cursor ignore width and height */
  8132. if (!fb)
  8133. return 0;
  8134. /* Check for which cursor types we support */
  8135. if (!i9xx_cursor_size_ok(plane_state)) {
  8136. DRM_DEBUG("Cursor dimension %dx%d not supported\n",
  8137. plane_state->base.crtc_w,
  8138. plane_state->base.crtc_h);
  8139. return -EINVAL;
  8140. }
  8141. if (fb->pitches[0] != plane_state->base.crtc_w * fb->format->cpp[0]) {
  8142. DRM_DEBUG_KMS("Invalid cursor stride (%u) (cursor width %d)\n",
  8143. fb->pitches[0], plane_state->base.crtc_w);
  8144. return -EINVAL;
  8145. }
  8146. /*
  8147. * There's something wrong with the cursor on CHV pipe C.
  8148. * If it straddles the left edge of the screen then
  8149. * moving it away from the edge or disabling it often
  8150. * results in a pipe underrun, and often that can lead to
  8151. * dead pipe (constant underrun reported, and it scans
  8152. * out just a solid color). To recover from that, the
  8153. * display power well must be turned off and on again.
  8154. * Refuse the put the cursor into that compromised position.
  8155. */
  8156. if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_C &&
  8157. plane_state->base.visible && plane_state->base.crtc_x < 0) {
  8158. DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n");
  8159. return -EINVAL;
  8160. }
  8161. plane_state->ctl = i9xx_cursor_ctl(crtc_state, plane_state);
  8162. return 0;
  8163. }
  8164. static void i9xx_update_cursor(struct intel_plane *plane,
  8165. const struct intel_crtc_state *crtc_state,
  8166. const struct intel_plane_state *plane_state)
  8167. {
  8168. struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
  8169. enum pipe pipe = plane->pipe;
  8170. u32 cntl = 0, base = 0, pos = 0, fbc_ctl = 0;
  8171. unsigned long irqflags;
  8172. if (plane_state && plane_state->base.visible) {
  8173. cntl = plane_state->ctl;
  8174. if (plane_state->base.crtc_h != plane_state->base.crtc_w)
  8175. fbc_ctl = CUR_FBC_CTL_EN | (plane_state->base.crtc_h - 1);
  8176. base = intel_cursor_base(plane_state);
  8177. pos = intel_cursor_position(plane_state);
  8178. }
  8179. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  8180. /*
  8181. * On some platforms writing CURCNTR first will also
  8182. * cause CURPOS to be armed by the CURBASE write.
  8183. * Without the CURCNTR write the CURPOS write would
  8184. * arm itself. Thus we always start the full update
  8185. * with a CURCNTR write.
  8186. *
  8187. * On other platforms CURPOS always requires the
  8188. * CURBASE write to arm the update. Additonally
  8189. * a write to any of the cursor register will cancel
  8190. * an already armed cursor update. Thus leaving out
  8191. * the CURBASE write after CURPOS could lead to a
  8192. * cursor that doesn't appear to move, or even change
  8193. * shape. Thus we always write CURBASE.
  8194. *
  8195. * CURCNTR and CUR_FBC_CTL are always
  8196. * armed by the CURBASE write only.
  8197. */
  8198. if (plane->cursor.base != base ||
  8199. plane->cursor.size != fbc_ctl ||
  8200. plane->cursor.cntl != cntl) {
  8201. I915_WRITE_FW(CURCNTR(pipe), cntl);
  8202. if (HAS_CUR_FBC(dev_priv))
  8203. I915_WRITE_FW(CUR_FBC_CTL(pipe), fbc_ctl);
  8204. I915_WRITE_FW(CURPOS(pipe), pos);
  8205. I915_WRITE_FW(CURBASE(pipe), base);
  8206. plane->cursor.base = base;
  8207. plane->cursor.size = fbc_ctl;
  8208. plane->cursor.cntl = cntl;
  8209. } else {
  8210. I915_WRITE_FW(CURPOS(pipe), pos);
  8211. I915_WRITE_FW(CURBASE(pipe), base);
  8212. }
  8213. POSTING_READ_FW(CURBASE(pipe));
  8214. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  8215. }
  8216. static void i9xx_disable_cursor(struct intel_plane *plane,
  8217. struct intel_crtc *crtc)
  8218. {
  8219. i9xx_update_cursor(plane, NULL, NULL);
  8220. }
  8221. static bool i9xx_cursor_get_hw_state(struct intel_plane *plane)
  8222. {
  8223. struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
  8224. enum intel_display_power_domain power_domain;
  8225. enum pipe pipe = plane->pipe;
  8226. bool ret;
  8227. /*
  8228. * Not 100% correct for planes that can move between pipes,
  8229. * but that's only the case for gen2-3 which don't have any
  8230. * display power wells.
  8231. */
  8232. power_domain = POWER_DOMAIN_PIPE(pipe);
  8233. if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
  8234. return false;
  8235. ret = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
  8236. intel_display_power_put(dev_priv, power_domain);
  8237. return ret;
  8238. }
  8239. /* VESA 640x480x72Hz mode to set on the pipe */
  8240. static const struct drm_display_mode load_detect_mode = {
  8241. DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
  8242. 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  8243. };
  8244. struct drm_framebuffer *
  8245. intel_framebuffer_create(struct drm_i915_gem_object *obj,
  8246. struct drm_mode_fb_cmd2 *mode_cmd)
  8247. {
  8248. struct intel_framebuffer *intel_fb;
  8249. int ret;
  8250. intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
  8251. if (!intel_fb)
  8252. return ERR_PTR(-ENOMEM);
  8253. ret = intel_framebuffer_init(intel_fb, obj, mode_cmd);
  8254. if (ret)
  8255. goto err;
  8256. return &intel_fb->base;
  8257. err:
  8258. kfree(intel_fb);
  8259. return ERR_PTR(ret);
  8260. }
  8261. static int intel_modeset_disable_planes(struct drm_atomic_state *state,
  8262. struct drm_crtc *crtc)
  8263. {
  8264. struct drm_plane *plane;
  8265. struct drm_plane_state *plane_state;
  8266. int ret, i;
  8267. ret = drm_atomic_add_affected_planes(state, crtc);
  8268. if (ret)
  8269. return ret;
  8270. for_each_new_plane_in_state(state, plane, plane_state, i) {
  8271. if (plane_state->crtc != crtc)
  8272. continue;
  8273. ret = drm_atomic_set_crtc_for_plane(plane_state, NULL);
  8274. if (ret)
  8275. return ret;
  8276. drm_atomic_set_fb_for_plane(plane_state, NULL);
  8277. }
  8278. return 0;
  8279. }
  8280. int intel_get_load_detect_pipe(struct drm_connector *connector,
  8281. const struct drm_display_mode *mode,
  8282. struct intel_load_detect_pipe *old,
  8283. struct drm_modeset_acquire_ctx *ctx)
  8284. {
  8285. struct intel_crtc *intel_crtc;
  8286. struct intel_encoder *intel_encoder =
  8287. intel_attached_encoder(connector);
  8288. struct drm_crtc *possible_crtc;
  8289. struct drm_encoder *encoder = &intel_encoder->base;
  8290. struct drm_crtc *crtc = NULL;
  8291. struct drm_device *dev = encoder->dev;
  8292. struct drm_i915_private *dev_priv = to_i915(dev);
  8293. struct drm_mode_config *config = &dev->mode_config;
  8294. struct drm_atomic_state *state = NULL, *restore_state = NULL;
  8295. struct drm_connector_state *connector_state;
  8296. struct intel_crtc_state *crtc_state;
  8297. int ret, i = -1;
  8298. DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  8299. connector->base.id, connector->name,
  8300. encoder->base.id, encoder->name);
  8301. old->restore_state = NULL;
  8302. WARN_ON(!drm_modeset_is_locked(&config->connection_mutex));
  8303. /*
  8304. * Algorithm gets a little messy:
  8305. *
  8306. * - if the connector already has an assigned crtc, use it (but make
  8307. * sure it's on first)
  8308. *
  8309. * - try to find the first unused crtc that can drive this connector,
  8310. * and use that if we find one
  8311. */
  8312. /* See if we already have a CRTC for this connector */
  8313. if (connector->state->crtc) {
  8314. crtc = connector->state->crtc;
  8315. ret = drm_modeset_lock(&crtc->mutex, ctx);
  8316. if (ret)
  8317. goto fail;
  8318. /* Make sure the crtc and connector are running */
  8319. goto found;
  8320. }
  8321. /* Find an unused one (if possible) */
  8322. for_each_crtc(dev, possible_crtc) {
  8323. i++;
  8324. if (!(encoder->possible_crtcs & (1 << i)))
  8325. continue;
  8326. ret = drm_modeset_lock(&possible_crtc->mutex, ctx);
  8327. if (ret)
  8328. goto fail;
  8329. if (possible_crtc->state->enable) {
  8330. drm_modeset_unlock(&possible_crtc->mutex);
  8331. continue;
  8332. }
  8333. crtc = possible_crtc;
  8334. break;
  8335. }
  8336. /*
  8337. * If we didn't find an unused CRTC, don't use any.
  8338. */
  8339. if (!crtc) {
  8340. DRM_DEBUG_KMS("no pipe available for load-detect\n");
  8341. ret = -ENODEV;
  8342. goto fail;
  8343. }
  8344. found:
  8345. intel_crtc = to_intel_crtc(crtc);
  8346. state = drm_atomic_state_alloc(dev);
  8347. restore_state = drm_atomic_state_alloc(dev);
  8348. if (!state || !restore_state) {
  8349. ret = -ENOMEM;
  8350. goto fail;
  8351. }
  8352. state->acquire_ctx = ctx;
  8353. restore_state->acquire_ctx = ctx;
  8354. connector_state = drm_atomic_get_connector_state(state, connector);
  8355. if (IS_ERR(connector_state)) {
  8356. ret = PTR_ERR(connector_state);
  8357. goto fail;
  8358. }
  8359. ret = drm_atomic_set_crtc_for_connector(connector_state, crtc);
  8360. if (ret)
  8361. goto fail;
  8362. crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
  8363. if (IS_ERR(crtc_state)) {
  8364. ret = PTR_ERR(crtc_state);
  8365. goto fail;
  8366. }
  8367. crtc_state->base.active = crtc_state->base.enable = true;
  8368. if (!mode)
  8369. mode = &load_detect_mode;
  8370. ret = drm_atomic_set_mode_for_crtc(&crtc_state->base, mode);
  8371. if (ret)
  8372. goto fail;
  8373. ret = intel_modeset_disable_planes(state, crtc);
  8374. if (ret)
  8375. goto fail;
  8376. ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector));
  8377. if (!ret)
  8378. ret = PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state, crtc));
  8379. if (ret) {
  8380. DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret);
  8381. goto fail;
  8382. }
  8383. ret = drm_atomic_commit(state);
  8384. if (ret) {
  8385. DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
  8386. goto fail;
  8387. }
  8388. old->restore_state = restore_state;
  8389. drm_atomic_state_put(state);
  8390. /* let the connector get through one full cycle before testing */
  8391. intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
  8392. return true;
  8393. fail:
  8394. if (state) {
  8395. drm_atomic_state_put(state);
  8396. state = NULL;
  8397. }
  8398. if (restore_state) {
  8399. drm_atomic_state_put(restore_state);
  8400. restore_state = NULL;
  8401. }
  8402. if (ret == -EDEADLK)
  8403. return ret;
  8404. return false;
  8405. }
  8406. void intel_release_load_detect_pipe(struct drm_connector *connector,
  8407. struct intel_load_detect_pipe *old,
  8408. struct drm_modeset_acquire_ctx *ctx)
  8409. {
  8410. struct intel_encoder *intel_encoder =
  8411. intel_attached_encoder(connector);
  8412. struct drm_encoder *encoder = &intel_encoder->base;
  8413. struct drm_atomic_state *state = old->restore_state;
  8414. int ret;
  8415. DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  8416. connector->base.id, connector->name,
  8417. encoder->base.id, encoder->name);
  8418. if (!state)
  8419. return;
  8420. ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
  8421. if (ret)
  8422. DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret);
  8423. drm_atomic_state_put(state);
  8424. }
  8425. static int i9xx_pll_refclk(struct drm_device *dev,
  8426. const struct intel_crtc_state *pipe_config)
  8427. {
  8428. struct drm_i915_private *dev_priv = to_i915(dev);
  8429. u32 dpll = pipe_config->dpll_hw_state.dpll;
  8430. if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
  8431. return dev_priv->vbt.lvds_ssc_freq;
  8432. else if (HAS_PCH_SPLIT(dev_priv))
  8433. return 120000;
  8434. else if (!IS_GEN2(dev_priv))
  8435. return 96000;
  8436. else
  8437. return 48000;
  8438. }
  8439. /* Returns the clock of the currently programmed mode of the given pipe. */
  8440. static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
  8441. struct intel_crtc_state *pipe_config)
  8442. {
  8443. struct drm_device *dev = crtc->base.dev;
  8444. struct drm_i915_private *dev_priv = to_i915(dev);
  8445. int pipe = pipe_config->cpu_transcoder;
  8446. u32 dpll = pipe_config->dpll_hw_state.dpll;
  8447. u32 fp;
  8448. struct dpll clock;
  8449. int port_clock;
  8450. int refclk = i9xx_pll_refclk(dev, pipe_config);
  8451. if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
  8452. fp = pipe_config->dpll_hw_state.fp0;
  8453. else
  8454. fp = pipe_config->dpll_hw_state.fp1;
  8455. clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
  8456. if (IS_PINEVIEW(dev_priv)) {
  8457. clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
  8458. clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
  8459. } else {
  8460. clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
  8461. clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
  8462. }
  8463. if (!IS_GEN2(dev_priv)) {
  8464. if (IS_PINEVIEW(dev_priv))
  8465. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
  8466. DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
  8467. else
  8468. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
  8469. DPLL_FPA01_P1_POST_DIV_SHIFT);
  8470. switch (dpll & DPLL_MODE_MASK) {
  8471. case DPLLB_MODE_DAC_SERIAL:
  8472. clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
  8473. 5 : 10;
  8474. break;
  8475. case DPLLB_MODE_LVDS:
  8476. clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
  8477. 7 : 14;
  8478. break;
  8479. default:
  8480. DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
  8481. "mode\n", (int)(dpll & DPLL_MODE_MASK));
  8482. return;
  8483. }
  8484. if (IS_PINEVIEW(dev_priv))
  8485. port_clock = pnv_calc_dpll_params(refclk, &clock);
  8486. else
  8487. port_clock = i9xx_calc_dpll_params(refclk, &clock);
  8488. } else {
  8489. u32 lvds = IS_I830(dev_priv) ? 0 : I915_READ(LVDS);
  8490. bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN);
  8491. if (is_lvds) {
  8492. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
  8493. DPLL_FPA01_P1_POST_DIV_SHIFT);
  8494. if (lvds & LVDS_CLKB_POWER_UP)
  8495. clock.p2 = 7;
  8496. else
  8497. clock.p2 = 14;
  8498. } else {
  8499. if (dpll & PLL_P1_DIVIDE_BY_TWO)
  8500. clock.p1 = 2;
  8501. else {
  8502. clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
  8503. DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
  8504. }
  8505. if (dpll & PLL_P2_DIVIDE_BY_4)
  8506. clock.p2 = 4;
  8507. else
  8508. clock.p2 = 2;
  8509. }
  8510. port_clock = i9xx_calc_dpll_params(refclk, &clock);
  8511. }
  8512. /*
  8513. * This value includes pixel_multiplier. We will use
  8514. * port_clock to compute adjusted_mode.crtc_clock in the
  8515. * encoder's get_config() function.
  8516. */
  8517. pipe_config->port_clock = port_clock;
  8518. }
  8519. int intel_dotclock_calculate(int link_freq,
  8520. const struct intel_link_m_n *m_n)
  8521. {
  8522. /*
  8523. * The calculation for the data clock is:
  8524. * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
  8525. * But we want to avoid losing precison if possible, so:
  8526. * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
  8527. *
  8528. * and the link clock is simpler:
  8529. * link_clock = (m * link_clock) / n
  8530. */
  8531. if (!m_n->link_n)
  8532. return 0;
  8533. return div_u64(mul_u32_u32(m_n->link_m, link_freq), m_n->link_n);
  8534. }
  8535. static void ironlake_pch_clock_get(struct intel_crtc *crtc,
  8536. struct intel_crtc_state *pipe_config)
  8537. {
  8538. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  8539. /* read out port_clock from the DPLL */
  8540. i9xx_crtc_clock_get(crtc, pipe_config);
  8541. /*
  8542. * In case there is an active pipe without active ports,
  8543. * we may need some idea for the dotclock anyway.
  8544. * Calculate one based on the FDI configuration.
  8545. */
  8546. pipe_config->base.adjusted_mode.crtc_clock =
  8547. intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
  8548. &pipe_config->fdi_m_n);
  8549. }
  8550. /* Returns the currently programmed mode of the given encoder. */
  8551. struct drm_display_mode *
  8552. intel_encoder_current_mode(struct intel_encoder *encoder)
  8553. {
  8554. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  8555. struct intel_crtc_state *crtc_state;
  8556. struct drm_display_mode *mode;
  8557. struct intel_crtc *crtc;
  8558. enum pipe pipe;
  8559. if (!encoder->get_hw_state(encoder, &pipe))
  8560. return NULL;
  8561. crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
  8562. mode = kzalloc(sizeof(*mode), GFP_KERNEL);
  8563. if (!mode)
  8564. return NULL;
  8565. crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
  8566. if (!crtc_state) {
  8567. kfree(mode);
  8568. return NULL;
  8569. }
  8570. crtc_state->base.crtc = &crtc->base;
  8571. if (!dev_priv->display.get_pipe_config(crtc, crtc_state)) {
  8572. kfree(crtc_state);
  8573. kfree(mode);
  8574. return NULL;
  8575. }
  8576. encoder->get_config(encoder, crtc_state);
  8577. intel_mode_from_pipe_config(mode, crtc_state);
  8578. kfree(crtc_state);
  8579. return mode;
  8580. }
  8581. static void intel_crtc_destroy(struct drm_crtc *crtc)
  8582. {
  8583. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  8584. drm_crtc_cleanup(crtc);
  8585. kfree(intel_crtc);
  8586. }
  8587. /**
  8588. * intel_wm_need_update - Check whether watermarks need updating
  8589. * @plane: drm plane
  8590. * @state: new plane state
  8591. *
  8592. * Check current plane state versus the new one to determine whether
  8593. * watermarks need to be recalculated.
  8594. *
  8595. * Returns true or false.
  8596. */
  8597. static bool intel_wm_need_update(struct drm_plane *plane,
  8598. struct drm_plane_state *state)
  8599. {
  8600. struct intel_plane_state *new = to_intel_plane_state(state);
  8601. struct intel_plane_state *cur = to_intel_plane_state(plane->state);
  8602. /* Update watermarks on tiling or size changes. */
  8603. if (new->base.visible != cur->base.visible)
  8604. return true;
  8605. if (!cur->base.fb || !new->base.fb)
  8606. return false;
  8607. if (cur->base.fb->modifier != new->base.fb->modifier ||
  8608. cur->base.rotation != new->base.rotation ||
  8609. drm_rect_width(&new->base.src) != drm_rect_width(&cur->base.src) ||
  8610. drm_rect_height(&new->base.src) != drm_rect_height(&cur->base.src) ||
  8611. drm_rect_width(&new->base.dst) != drm_rect_width(&cur->base.dst) ||
  8612. drm_rect_height(&new->base.dst) != drm_rect_height(&cur->base.dst))
  8613. return true;
  8614. return false;
  8615. }
  8616. static bool needs_scaling(const struct intel_plane_state *state)
  8617. {
  8618. int src_w = drm_rect_width(&state->base.src) >> 16;
  8619. int src_h = drm_rect_height(&state->base.src) >> 16;
  8620. int dst_w = drm_rect_width(&state->base.dst);
  8621. int dst_h = drm_rect_height(&state->base.dst);
  8622. return (src_w != dst_w || src_h != dst_h);
  8623. }
  8624. int intel_plane_atomic_calc_changes(const struct intel_crtc_state *old_crtc_state,
  8625. struct drm_crtc_state *crtc_state,
  8626. const struct intel_plane_state *old_plane_state,
  8627. struct drm_plane_state *plane_state)
  8628. {
  8629. struct intel_crtc_state *pipe_config = to_intel_crtc_state(crtc_state);
  8630. struct drm_crtc *crtc = crtc_state->crtc;
  8631. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  8632. struct intel_plane *plane = to_intel_plane(plane_state->plane);
  8633. struct drm_device *dev = crtc->dev;
  8634. struct drm_i915_private *dev_priv = to_i915(dev);
  8635. bool mode_changed = needs_modeset(crtc_state);
  8636. bool was_crtc_enabled = old_crtc_state->base.active;
  8637. bool is_crtc_enabled = crtc_state->active;
  8638. bool turn_off, turn_on, visible, was_visible;
  8639. struct drm_framebuffer *fb = plane_state->fb;
  8640. int ret;
  8641. if (INTEL_GEN(dev_priv) >= 9 && plane->id != PLANE_CURSOR) {
  8642. ret = skl_update_scaler_plane(
  8643. to_intel_crtc_state(crtc_state),
  8644. to_intel_plane_state(plane_state));
  8645. if (ret)
  8646. return ret;
  8647. }
  8648. was_visible = old_plane_state->base.visible;
  8649. visible = plane_state->visible;
  8650. if (!was_crtc_enabled && WARN_ON(was_visible))
  8651. was_visible = false;
  8652. /*
  8653. * Visibility is calculated as if the crtc was on, but
  8654. * after scaler setup everything depends on it being off
  8655. * when the crtc isn't active.
  8656. *
  8657. * FIXME this is wrong for watermarks. Watermarks should also
  8658. * be computed as if the pipe would be active. Perhaps move
  8659. * per-plane wm computation to the .check_plane() hook, and
  8660. * only combine the results from all planes in the current place?
  8661. */
  8662. if (!is_crtc_enabled) {
  8663. plane_state->visible = visible = false;
  8664. to_intel_crtc_state(crtc_state)->active_planes &= ~BIT(plane->id);
  8665. }
  8666. if (!was_visible && !visible)
  8667. return 0;
  8668. if (fb != old_plane_state->base.fb)
  8669. pipe_config->fb_changed = true;
  8670. turn_off = was_visible && (!visible || mode_changed);
  8671. turn_on = visible && (!was_visible || mode_changed);
  8672. DRM_DEBUG_ATOMIC("[CRTC:%d:%s] has [PLANE:%d:%s] with fb %i\n",
  8673. intel_crtc->base.base.id, intel_crtc->base.name,
  8674. plane->base.base.id, plane->base.name,
  8675. fb ? fb->base.id : -1);
  8676. DRM_DEBUG_ATOMIC("[PLANE:%d:%s] visible %i -> %i, off %i, on %i, ms %i\n",
  8677. plane->base.base.id, plane->base.name,
  8678. was_visible, visible,
  8679. turn_off, turn_on, mode_changed);
  8680. if (turn_on) {
  8681. if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
  8682. pipe_config->update_wm_pre = true;
  8683. /* must disable cxsr around plane enable/disable */
  8684. if (plane->id != PLANE_CURSOR)
  8685. pipe_config->disable_cxsr = true;
  8686. } else if (turn_off) {
  8687. if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
  8688. pipe_config->update_wm_post = true;
  8689. /* must disable cxsr around plane enable/disable */
  8690. if (plane->id != PLANE_CURSOR)
  8691. pipe_config->disable_cxsr = true;
  8692. } else if (intel_wm_need_update(&plane->base, plane_state)) {
  8693. if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) {
  8694. /* FIXME bollocks */
  8695. pipe_config->update_wm_pre = true;
  8696. pipe_config->update_wm_post = true;
  8697. }
  8698. }
  8699. if (visible || was_visible)
  8700. pipe_config->fb_bits |= plane->frontbuffer_bit;
  8701. /*
  8702. * WaCxSRDisabledForSpriteScaling:ivb
  8703. *
  8704. * cstate->update_wm was already set above, so this flag will
  8705. * take effect when we commit and program watermarks.
  8706. */
  8707. if (plane->id == PLANE_SPRITE0 && IS_IVYBRIDGE(dev_priv) &&
  8708. needs_scaling(to_intel_plane_state(plane_state)) &&
  8709. !needs_scaling(old_plane_state))
  8710. pipe_config->disable_lp_wm = true;
  8711. return 0;
  8712. }
  8713. static bool encoders_cloneable(const struct intel_encoder *a,
  8714. const struct intel_encoder *b)
  8715. {
  8716. /* masks could be asymmetric, so check both ways */
  8717. return a == b || (a->cloneable & (1 << b->type) &&
  8718. b->cloneable & (1 << a->type));
  8719. }
  8720. static bool check_single_encoder_cloning(struct drm_atomic_state *state,
  8721. struct intel_crtc *crtc,
  8722. struct intel_encoder *encoder)
  8723. {
  8724. struct intel_encoder *source_encoder;
  8725. struct drm_connector *connector;
  8726. struct drm_connector_state *connector_state;
  8727. int i;
  8728. for_each_new_connector_in_state(state, connector, connector_state, i) {
  8729. if (connector_state->crtc != &crtc->base)
  8730. continue;
  8731. source_encoder =
  8732. to_intel_encoder(connector_state->best_encoder);
  8733. if (!encoders_cloneable(encoder, source_encoder))
  8734. return false;
  8735. }
  8736. return true;
  8737. }
  8738. static int intel_crtc_atomic_check(struct drm_crtc *crtc,
  8739. struct drm_crtc_state *crtc_state)
  8740. {
  8741. struct drm_device *dev = crtc->dev;
  8742. struct drm_i915_private *dev_priv = to_i915(dev);
  8743. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  8744. struct intel_crtc_state *pipe_config =
  8745. to_intel_crtc_state(crtc_state);
  8746. struct drm_atomic_state *state = crtc_state->state;
  8747. int ret;
  8748. bool mode_changed = needs_modeset(crtc_state);
  8749. if (mode_changed && !crtc_state->active)
  8750. pipe_config->update_wm_post = true;
  8751. if (mode_changed && crtc_state->enable &&
  8752. dev_priv->display.crtc_compute_clock &&
  8753. !WARN_ON(pipe_config->shared_dpll)) {
  8754. ret = dev_priv->display.crtc_compute_clock(intel_crtc,
  8755. pipe_config);
  8756. if (ret)
  8757. return ret;
  8758. }
  8759. if (crtc_state->color_mgmt_changed) {
  8760. ret = intel_color_check(crtc, crtc_state);
  8761. if (ret)
  8762. return ret;
  8763. /*
  8764. * Changing color management on Intel hardware is
  8765. * handled as part of planes update.
  8766. */
  8767. crtc_state->planes_changed = true;
  8768. }
  8769. ret = 0;
  8770. if (dev_priv->display.compute_pipe_wm) {
  8771. ret = dev_priv->display.compute_pipe_wm(pipe_config);
  8772. if (ret) {
  8773. DRM_DEBUG_KMS("Target pipe watermarks are invalid\n");
  8774. return ret;
  8775. }
  8776. }
  8777. if (dev_priv->display.compute_intermediate_wm &&
  8778. !to_intel_atomic_state(state)->skip_intermediate_wm) {
  8779. if (WARN_ON(!dev_priv->display.compute_pipe_wm))
  8780. return 0;
  8781. /*
  8782. * Calculate 'intermediate' watermarks that satisfy both the
  8783. * old state and the new state. We can program these
  8784. * immediately.
  8785. */
  8786. ret = dev_priv->display.compute_intermediate_wm(dev,
  8787. intel_crtc,
  8788. pipe_config);
  8789. if (ret) {
  8790. DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n");
  8791. return ret;
  8792. }
  8793. } else if (dev_priv->display.compute_intermediate_wm) {
  8794. if (HAS_PCH_SPLIT(dev_priv) && INTEL_GEN(dev_priv) < 9)
  8795. pipe_config->wm.ilk.intermediate = pipe_config->wm.ilk.optimal;
  8796. }
  8797. if (INTEL_GEN(dev_priv) >= 9) {
  8798. if (mode_changed)
  8799. ret = skl_update_scaler_crtc(pipe_config);
  8800. if (!ret)
  8801. ret = skl_check_pipe_max_pixel_rate(intel_crtc,
  8802. pipe_config);
  8803. if (!ret)
  8804. ret = intel_atomic_setup_scalers(dev_priv, intel_crtc,
  8805. pipe_config);
  8806. }
  8807. if (HAS_IPS(dev_priv))
  8808. pipe_config->ips_enabled = hsw_compute_ips_config(pipe_config);
  8809. return ret;
  8810. }
  8811. static const struct drm_crtc_helper_funcs intel_helper_funcs = {
  8812. .atomic_begin = intel_begin_crtc_commit,
  8813. .atomic_flush = intel_finish_crtc_commit,
  8814. .atomic_check = intel_crtc_atomic_check,
  8815. };
  8816. static void intel_modeset_update_connector_atomic_state(struct drm_device *dev)
  8817. {
  8818. struct intel_connector *connector;
  8819. struct drm_connector_list_iter conn_iter;
  8820. drm_connector_list_iter_begin(dev, &conn_iter);
  8821. for_each_intel_connector_iter(connector, &conn_iter) {
  8822. if (connector->base.state->crtc)
  8823. drm_connector_unreference(&connector->base);
  8824. if (connector->base.encoder) {
  8825. connector->base.state->best_encoder =
  8826. connector->base.encoder;
  8827. connector->base.state->crtc =
  8828. connector->base.encoder->crtc;
  8829. drm_connector_reference(&connector->base);
  8830. } else {
  8831. connector->base.state->best_encoder = NULL;
  8832. connector->base.state->crtc = NULL;
  8833. }
  8834. }
  8835. drm_connector_list_iter_end(&conn_iter);
  8836. }
  8837. static void
  8838. connected_sink_compute_bpp(struct intel_connector *connector,
  8839. struct intel_crtc_state *pipe_config)
  8840. {
  8841. const struct drm_display_info *info = &connector->base.display_info;
  8842. int bpp = pipe_config->pipe_bpp;
  8843. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n",
  8844. connector->base.base.id,
  8845. connector->base.name);
  8846. /* Don't use an invalid EDID bpc value */
  8847. if (info->bpc != 0 && info->bpc * 3 < bpp) {
  8848. DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
  8849. bpp, info->bpc * 3);
  8850. pipe_config->pipe_bpp = info->bpc * 3;
  8851. }
  8852. /* Clamp bpp to 8 on screens without EDID 1.4 */
  8853. if (info->bpc == 0 && bpp > 24) {
  8854. DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n",
  8855. bpp);
  8856. pipe_config->pipe_bpp = 24;
  8857. }
  8858. }
  8859. static int
  8860. compute_baseline_pipe_bpp(struct intel_crtc *crtc,
  8861. struct intel_crtc_state *pipe_config)
  8862. {
  8863. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  8864. struct drm_atomic_state *state;
  8865. struct drm_connector *connector;
  8866. struct drm_connector_state *connector_state;
  8867. int bpp, i;
  8868. if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
  8869. IS_CHERRYVIEW(dev_priv)))
  8870. bpp = 10*3;
  8871. else if (INTEL_GEN(dev_priv) >= 5)
  8872. bpp = 12*3;
  8873. else
  8874. bpp = 8*3;
  8875. pipe_config->pipe_bpp = bpp;
  8876. state = pipe_config->base.state;
  8877. /* Clamp display bpp to EDID value */
  8878. for_each_new_connector_in_state(state, connector, connector_state, i) {
  8879. if (connector_state->crtc != &crtc->base)
  8880. continue;
  8881. connected_sink_compute_bpp(to_intel_connector(connector),
  8882. pipe_config);
  8883. }
  8884. return bpp;
  8885. }
  8886. static void intel_dump_crtc_timings(const struct drm_display_mode *mode)
  8887. {
  8888. DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
  8889. "type: 0x%x flags: 0x%x\n",
  8890. mode->crtc_clock,
  8891. mode->crtc_hdisplay, mode->crtc_hsync_start,
  8892. mode->crtc_hsync_end, mode->crtc_htotal,
  8893. mode->crtc_vdisplay, mode->crtc_vsync_start,
  8894. mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags);
  8895. }
  8896. static inline void
  8897. intel_dump_m_n_config(struct intel_crtc_state *pipe_config, char *id,
  8898. unsigned int lane_count, struct intel_link_m_n *m_n)
  8899. {
  8900. DRM_DEBUG_KMS("%s: lanes: %i; gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
  8901. id, lane_count,
  8902. m_n->gmch_m, m_n->gmch_n,
  8903. m_n->link_m, m_n->link_n, m_n->tu);
  8904. }
  8905. #define OUTPUT_TYPE(x) [INTEL_OUTPUT_ ## x] = #x
  8906. static const char * const output_type_str[] = {
  8907. OUTPUT_TYPE(UNUSED),
  8908. OUTPUT_TYPE(ANALOG),
  8909. OUTPUT_TYPE(DVO),
  8910. OUTPUT_TYPE(SDVO),
  8911. OUTPUT_TYPE(LVDS),
  8912. OUTPUT_TYPE(TVOUT),
  8913. OUTPUT_TYPE(HDMI),
  8914. OUTPUT_TYPE(DP),
  8915. OUTPUT_TYPE(EDP),
  8916. OUTPUT_TYPE(DSI),
  8917. OUTPUT_TYPE(DDI),
  8918. OUTPUT_TYPE(DP_MST),
  8919. };
  8920. #undef OUTPUT_TYPE
  8921. static void snprintf_output_types(char *buf, size_t len,
  8922. unsigned int output_types)
  8923. {
  8924. char *str = buf;
  8925. int i;
  8926. str[0] = '\0';
  8927. for (i = 0; i < ARRAY_SIZE(output_type_str); i++) {
  8928. int r;
  8929. if ((output_types & BIT(i)) == 0)
  8930. continue;
  8931. r = snprintf(str, len, "%s%s",
  8932. str != buf ? "," : "", output_type_str[i]);
  8933. if (r >= len)
  8934. break;
  8935. str += r;
  8936. len -= r;
  8937. output_types &= ~BIT(i);
  8938. }
  8939. WARN_ON_ONCE(output_types != 0);
  8940. }
  8941. static void intel_dump_pipe_config(struct intel_crtc *crtc,
  8942. struct intel_crtc_state *pipe_config,
  8943. const char *context)
  8944. {
  8945. struct drm_device *dev = crtc->base.dev;
  8946. struct drm_i915_private *dev_priv = to_i915(dev);
  8947. struct drm_plane *plane;
  8948. struct intel_plane *intel_plane;
  8949. struct intel_plane_state *state;
  8950. struct drm_framebuffer *fb;
  8951. char buf[64];
  8952. DRM_DEBUG_KMS("[CRTC:%d:%s]%s\n",
  8953. crtc->base.base.id, crtc->base.name, context);
  8954. snprintf_output_types(buf, sizeof(buf), pipe_config->output_types);
  8955. DRM_DEBUG_KMS("output_types: %s (0x%x)\n",
  8956. buf, pipe_config->output_types);
  8957. DRM_DEBUG_KMS("cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n",
  8958. transcoder_name(pipe_config->cpu_transcoder),
  8959. pipe_config->pipe_bpp, pipe_config->dither);
  8960. if (pipe_config->has_pch_encoder)
  8961. intel_dump_m_n_config(pipe_config, "fdi",
  8962. pipe_config->fdi_lanes,
  8963. &pipe_config->fdi_m_n);
  8964. if (pipe_config->ycbcr420)
  8965. DRM_DEBUG_KMS("YCbCr 4:2:0 output enabled\n");
  8966. if (intel_crtc_has_dp_encoder(pipe_config)) {
  8967. intel_dump_m_n_config(pipe_config, "dp m_n",
  8968. pipe_config->lane_count, &pipe_config->dp_m_n);
  8969. if (pipe_config->has_drrs)
  8970. intel_dump_m_n_config(pipe_config, "dp m2_n2",
  8971. pipe_config->lane_count,
  8972. &pipe_config->dp_m2_n2);
  8973. }
  8974. DRM_DEBUG_KMS("audio: %i, infoframes: %i\n",
  8975. pipe_config->has_audio, pipe_config->has_infoframe);
  8976. DRM_DEBUG_KMS("requested mode:\n");
  8977. drm_mode_debug_printmodeline(&pipe_config->base.mode);
  8978. DRM_DEBUG_KMS("adjusted mode:\n");
  8979. drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode);
  8980. intel_dump_crtc_timings(&pipe_config->base.adjusted_mode);
  8981. DRM_DEBUG_KMS("port clock: %d, pipe src size: %dx%d, pixel rate %d\n",
  8982. pipe_config->port_clock,
  8983. pipe_config->pipe_src_w, pipe_config->pipe_src_h,
  8984. pipe_config->pixel_rate);
  8985. if (INTEL_GEN(dev_priv) >= 9)
  8986. DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n",
  8987. crtc->num_scalers,
  8988. pipe_config->scaler_state.scaler_users,
  8989. pipe_config->scaler_state.scaler_id);
  8990. if (HAS_GMCH_DISPLAY(dev_priv))
  8991. DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
  8992. pipe_config->gmch_pfit.control,
  8993. pipe_config->gmch_pfit.pgm_ratios,
  8994. pipe_config->gmch_pfit.lvds_border_bits);
  8995. else
  8996. DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
  8997. pipe_config->pch_pfit.pos,
  8998. pipe_config->pch_pfit.size,
  8999. enableddisabled(pipe_config->pch_pfit.enabled));
  9000. DRM_DEBUG_KMS("ips: %i, double wide: %i\n",
  9001. pipe_config->ips_enabled, pipe_config->double_wide);
  9002. intel_dpll_dump_hw_state(dev_priv, &pipe_config->dpll_hw_state);
  9003. DRM_DEBUG_KMS("planes on this crtc\n");
  9004. list_for_each_entry(plane, &dev->mode_config.plane_list, head) {
  9005. struct drm_format_name_buf format_name;
  9006. intel_plane = to_intel_plane(plane);
  9007. if (intel_plane->pipe != crtc->pipe)
  9008. continue;
  9009. state = to_intel_plane_state(plane->state);
  9010. fb = state->base.fb;
  9011. if (!fb) {
  9012. DRM_DEBUG_KMS("[PLANE:%d:%s] disabled, scaler_id = %d\n",
  9013. plane->base.id, plane->name, state->scaler_id);
  9014. continue;
  9015. }
  9016. DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d, fb = %ux%u format = %s\n",
  9017. plane->base.id, plane->name,
  9018. fb->base.id, fb->width, fb->height,
  9019. drm_get_format_name(fb->format->format, &format_name));
  9020. if (INTEL_GEN(dev_priv) >= 9)
  9021. DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n",
  9022. state->scaler_id,
  9023. state->base.src.x1 >> 16,
  9024. state->base.src.y1 >> 16,
  9025. drm_rect_width(&state->base.src) >> 16,
  9026. drm_rect_height(&state->base.src) >> 16,
  9027. state->base.dst.x1, state->base.dst.y1,
  9028. drm_rect_width(&state->base.dst),
  9029. drm_rect_height(&state->base.dst));
  9030. }
  9031. }
  9032. static bool check_digital_port_conflicts(struct drm_atomic_state *state)
  9033. {
  9034. struct drm_device *dev = state->dev;
  9035. struct drm_connector *connector;
  9036. struct drm_connector_list_iter conn_iter;
  9037. unsigned int used_ports = 0;
  9038. unsigned int used_mst_ports = 0;
  9039. bool ret = true;
  9040. /*
  9041. * Walk the connector list instead of the encoder
  9042. * list to detect the problem on ddi platforms
  9043. * where there's just one encoder per digital port.
  9044. */
  9045. drm_connector_list_iter_begin(dev, &conn_iter);
  9046. drm_for_each_connector_iter(connector, &conn_iter) {
  9047. struct drm_connector_state *connector_state;
  9048. struct intel_encoder *encoder;
  9049. connector_state = drm_atomic_get_new_connector_state(state, connector);
  9050. if (!connector_state)
  9051. connector_state = connector->state;
  9052. if (!connector_state->best_encoder)
  9053. continue;
  9054. encoder = to_intel_encoder(connector_state->best_encoder);
  9055. WARN_ON(!connector_state->crtc);
  9056. switch (encoder->type) {
  9057. unsigned int port_mask;
  9058. case INTEL_OUTPUT_DDI:
  9059. if (WARN_ON(!HAS_DDI(to_i915(dev))))
  9060. break;
  9061. case INTEL_OUTPUT_DP:
  9062. case INTEL_OUTPUT_HDMI:
  9063. case INTEL_OUTPUT_EDP:
  9064. port_mask = 1 << encoder->port;
  9065. /* the same port mustn't appear more than once */
  9066. if (used_ports & port_mask)
  9067. ret = false;
  9068. used_ports |= port_mask;
  9069. break;
  9070. case INTEL_OUTPUT_DP_MST:
  9071. used_mst_ports |=
  9072. 1 << encoder->port;
  9073. break;
  9074. default:
  9075. break;
  9076. }
  9077. }
  9078. drm_connector_list_iter_end(&conn_iter);
  9079. /* can't mix MST and SST/HDMI on the same port */
  9080. if (used_ports & used_mst_ports)
  9081. return false;
  9082. return ret;
  9083. }
  9084. static void
  9085. clear_intel_crtc_state(struct intel_crtc_state *crtc_state)
  9086. {
  9087. struct drm_i915_private *dev_priv =
  9088. to_i915(crtc_state->base.crtc->dev);
  9089. struct intel_crtc_scaler_state scaler_state;
  9090. struct intel_dpll_hw_state dpll_hw_state;
  9091. struct intel_shared_dpll *shared_dpll;
  9092. struct intel_crtc_wm_state wm_state;
  9093. bool force_thru, ips_force_disable;
  9094. /* FIXME: before the switch to atomic started, a new pipe_config was
  9095. * kzalloc'd. Code that depends on any field being zero should be
  9096. * fixed, so that the crtc_state can be safely duplicated. For now,
  9097. * only fields that are know to not cause problems are preserved. */
  9098. scaler_state = crtc_state->scaler_state;
  9099. shared_dpll = crtc_state->shared_dpll;
  9100. dpll_hw_state = crtc_state->dpll_hw_state;
  9101. force_thru = crtc_state->pch_pfit.force_thru;
  9102. ips_force_disable = crtc_state->ips_force_disable;
  9103. if (IS_G4X(dev_priv) ||
  9104. IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  9105. wm_state = crtc_state->wm;
  9106. /* Keep base drm_crtc_state intact, only clear our extended struct */
  9107. BUILD_BUG_ON(offsetof(struct intel_crtc_state, base));
  9108. memset(&crtc_state->base + 1, 0,
  9109. sizeof(*crtc_state) - sizeof(crtc_state->base));
  9110. crtc_state->scaler_state = scaler_state;
  9111. crtc_state->shared_dpll = shared_dpll;
  9112. crtc_state->dpll_hw_state = dpll_hw_state;
  9113. crtc_state->pch_pfit.force_thru = force_thru;
  9114. crtc_state->ips_force_disable = ips_force_disable;
  9115. if (IS_G4X(dev_priv) ||
  9116. IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  9117. crtc_state->wm = wm_state;
  9118. }
  9119. static int
  9120. intel_modeset_pipe_config(struct drm_crtc *crtc,
  9121. struct intel_crtc_state *pipe_config)
  9122. {
  9123. struct drm_atomic_state *state = pipe_config->base.state;
  9124. struct intel_encoder *encoder;
  9125. struct drm_connector *connector;
  9126. struct drm_connector_state *connector_state;
  9127. int base_bpp, ret = -EINVAL;
  9128. int i;
  9129. bool retry = true;
  9130. clear_intel_crtc_state(pipe_config);
  9131. pipe_config->cpu_transcoder =
  9132. (enum transcoder) to_intel_crtc(crtc)->pipe;
  9133. /*
  9134. * Sanitize sync polarity flags based on requested ones. If neither
  9135. * positive or negative polarity is requested, treat this as meaning
  9136. * negative polarity.
  9137. */
  9138. if (!(pipe_config->base.adjusted_mode.flags &
  9139. (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
  9140. pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
  9141. if (!(pipe_config->base.adjusted_mode.flags &
  9142. (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
  9143. pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
  9144. base_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc),
  9145. pipe_config);
  9146. if (base_bpp < 0)
  9147. goto fail;
  9148. /*
  9149. * Determine the real pipe dimensions. Note that stereo modes can
  9150. * increase the actual pipe size due to the frame doubling and
  9151. * insertion of additional space for blanks between the frame. This
  9152. * is stored in the crtc timings. We use the requested mode to do this
  9153. * computation to clearly distinguish it from the adjusted mode, which
  9154. * can be changed by the connectors in the below retry loop.
  9155. */
  9156. drm_mode_get_hv_timing(&pipe_config->base.mode,
  9157. &pipe_config->pipe_src_w,
  9158. &pipe_config->pipe_src_h);
  9159. for_each_new_connector_in_state(state, connector, connector_state, i) {
  9160. if (connector_state->crtc != crtc)
  9161. continue;
  9162. encoder = to_intel_encoder(connector_state->best_encoder);
  9163. if (!check_single_encoder_cloning(state, to_intel_crtc(crtc), encoder)) {
  9164. DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
  9165. goto fail;
  9166. }
  9167. /*
  9168. * Determine output_types before calling the .compute_config()
  9169. * hooks so that the hooks can use this information safely.
  9170. */
  9171. if (encoder->compute_output_type)
  9172. pipe_config->output_types |=
  9173. BIT(encoder->compute_output_type(encoder, pipe_config,
  9174. connector_state));
  9175. else
  9176. pipe_config->output_types |= BIT(encoder->type);
  9177. }
  9178. encoder_retry:
  9179. /* Ensure the port clock defaults are reset when retrying. */
  9180. pipe_config->port_clock = 0;
  9181. pipe_config->pixel_multiplier = 1;
  9182. /* Fill in default crtc timings, allow encoders to overwrite them. */
  9183. drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode,
  9184. CRTC_STEREO_DOUBLE);
  9185. /* Pass our mode to the connectors and the CRTC to give them a chance to
  9186. * adjust it according to limitations or connector properties, and also
  9187. * a chance to reject the mode entirely.
  9188. */
  9189. for_each_new_connector_in_state(state, connector, connector_state, i) {
  9190. if (connector_state->crtc != crtc)
  9191. continue;
  9192. encoder = to_intel_encoder(connector_state->best_encoder);
  9193. if (!(encoder->compute_config(encoder, pipe_config, connector_state))) {
  9194. DRM_DEBUG_KMS("Encoder config failure\n");
  9195. goto fail;
  9196. }
  9197. }
  9198. /* Set default port clock if not overwritten by the encoder. Needs to be
  9199. * done afterwards in case the encoder adjusts the mode. */
  9200. if (!pipe_config->port_clock)
  9201. pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock
  9202. * pipe_config->pixel_multiplier;
  9203. ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config);
  9204. if (ret < 0) {
  9205. DRM_DEBUG_KMS("CRTC fixup failed\n");
  9206. goto fail;
  9207. }
  9208. if (ret == RETRY) {
  9209. if (WARN(!retry, "loop in pipe configuration computation\n")) {
  9210. ret = -EINVAL;
  9211. goto fail;
  9212. }
  9213. DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
  9214. retry = false;
  9215. goto encoder_retry;
  9216. }
  9217. /* Dithering seems to not pass-through bits correctly when it should, so
  9218. * only enable it on 6bpc panels and when its not a compliance
  9219. * test requesting 6bpc video pattern.
  9220. */
  9221. pipe_config->dither = (pipe_config->pipe_bpp == 6*3) &&
  9222. !pipe_config->dither_force_disable;
  9223. DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
  9224. base_bpp, pipe_config->pipe_bpp, pipe_config->dither);
  9225. fail:
  9226. return ret;
  9227. }
  9228. static bool intel_fuzzy_clock_check(int clock1, int clock2)
  9229. {
  9230. int diff;
  9231. if (clock1 == clock2)
  9232. return true;
  9233. if (!clock1 || !clock2)
  9234. return false;
  9235. diff = abs(clock1 - clock2);
  9236. if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
  9237. return true;
  9238. return false;
  9239. }
  9240. static bool
  9241. intel_compare_m_n(unsigned int m, unsigned int n,
  9242. unsigned int m2, unsigned int n2,
  9243. bool exact)
  9244. {
  9245. if (m == m2 && n == n2)
  9246. return true;
  9247. if (exact || !m || !n || !m2 || !n2)
  9248. return false;
  9249. BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX);
  9250. if (n > n2) {
  9251. while (n > n2) {
  9252. m2 <<= 1;
  9253. n2 <<= 1;
  9254. }
  9255. } else if (n < n2) {
  9256. while (n < n2) {
  9257. m <<= 1;
  9258. n <<= 1;
  9259. }
  9260. }
  9261. if (n != n2)
  9262. return false;
  9263. return intel_fuzzy_clock_check(m, m2);
  9264. }
  9265. static bool
  9266. intel_compare_link_m_n(const struct intel_link_m_n *m_n,
  9267. struct intel_link_m_n *m2_n2,
  9268. bool adjust)
  9269. {
  9270. if (m_n->tu == m2_n2->tu &&
  9271. intel_compare_m_n(m_n->gmch_m, m_n->gmch_n,
  9272. m2_n2->gmch_m, m2_n2->gmch_n, !adjust) &&
  9273. intel_compare_m_n(m_n->link_m, m_n->link_n,
  9274. m2_n2->link_m, m2_n2->link_n, !adjust)) {
  9275. if (adjust)
  9276. *m2_n2 = *m_n;
  9277. return true;
  9278. }
  9279. return false;
  9280. }
  9281. static void __printf(3, 4)
  9282. pipe_config_err(bool adjust, const char *name, const char *format, ...)
  9283. {
  9284. struct va_format vaf;
  9285. va_list args;
  9286. va_start(args, format);
  9287. vaf.fmt = format;
  9288. vaf.va = &args;
  9289. if (adjust)
  9290. drm_dbg(DRM_UT_KMS, "mismatch in %s %pV", name, &vaf);
  9291. else
  9292. drm_err("mismatch in %s %pV", name, &vaf);
  9293. va_end(args);
  9294. }
  9295. static bool
  9296. intel_pipe_config_compare(struct drm_i915_private *dev_priv,
  9297. struct intel_crtc_state *current_config,
  9298. struct intel_crtc_state *pipe_config,
  9299. bool adjust)
  9300. {
  9301. bool ret = true;
  9302. bool fixup_inherited = adjust &&
  9303. (current_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED) &&
  9304. !(pipe_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED);
  9305. #define PIPE_CONF_CHECK_X(name) do { \
  9306. if (current_config->name != pipe_config->name) { \
  9307. pipe_config_err(adjust, __stringify(name), \
  9308. "(expected 0x%08x, found 0x%08x)\n", \
  9309. current_config->name, \
  9310. pipe_config->name); \
  9311. ret = false; \
  9312. } \
  9313. } while (0)
  9314. #define PIPE_CONF_CHECK_I(name) do { \
  9315. if (current_config->name != pipe_config->name) { \
  9316. pipe_config_err(adjust, __stringify(name), \
  9317. "(expected %i, found %i)\n", \
  9318. current_config->name, \
  9319. pipe_config->name); \
  9320. ret = false; \
  9321. } \
  9322. } while (0)
  9323. #define PIPE_CONF_CHECK_BOOL(name) do { \
  9324. if (current_config->name != pipe_config->name) { \
  9325. pipe_config_err(adjust, __stringify(name), \
  9326. "(expected %s, found %s)\n", \
  9327. yesno(current_config->name), \
  9328. yesno(pipe_config->name)); \
  9329. ret = false; \
  9330. } \
  9331. } while (0)
  9332. /*
  9333. * Checks state where we only read out the enabling, but not the entire
  9334. * state itself (like full infoframes or ELD for audio). These states
  9335. * require a full modeset on bootup to fix up.
  9336. */
  9337. #define PIPE_CONF_CHECK_BOOL_INCOMPLETE(name) do { \
  9338. if (!fixup_inherited || (!current_config->name && !pipe_config->name)) { \
  9339. PIPE_CONF_CHECK_BOOL(name); \
  9340. } else { \
  9341. pipe_config_err(adjust, __stringify(name), \
  9342. "unable to verify whether state matches exactly, forcing modeset (expected %s, found %s)\n", \
  9343. yesno(current_config->name), \
  9344. yesno(pipe_config->name)); \
  9345. ret = false; \
  9346. } \
  9347. } while (0)
  9348. #define PIPE_CONF_CHECK_P(name) do { \
  9349. if (current_config->name != pipe_config->name) { \
  9350. pipe_config_err(adjust, __stringify(name), \
  9351. "(expected %p, found %p)\n", \
  9352. current_config->name, \
  9353. pipe_config->name); \
  9354. ret = false; \
  9355. } \
  9356. } while (0)
  9357. #define PIPE_CONF_CHECK_M_N(name) do { \
  9358. if (!intel_compare_link_m_n(&current_config->name, \
  9359. &pipe_config->name,\
  9360. adjust)) { \
  9361. pipe_config_err(adjust, __stringify(name), \
  9362. "(expected tu %i gmch %i/%i link %i/%i, " \
  9363. "found tu %i, gmch %i/%i link %i/%i)\n", \
  9364. current_config->name.tu, \
  9365. current_config->name.gmch_m, \
  9366. current_config->name.gmch_n, \
  9367. current_config->name.link_m, \
  9368. current_config->name.link_n, \
  9369. pipe_config->name.tu, \
  9370. pipe_config->name.gmch_m, \
  9371. pipe_config->name.gmch_n, \
  9372. pipe_config->name.link_m, \
  9373. pipe_config->name.link_n); \
  9374. ret = false; \
  9375. } \
  9376. } while (0)
  9377. /* This is required for BDW+ where there is only one set of registers for
  9378. * switching between high and low RR.
  9379. * This macro can be used whenever a comparison has to be made between one
  9380. * hw state and multiple sw state variables.
  9381. */
  9382. #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) do { \
  9383. if (!intel_compare_link_m_n(&current_config->name, \
  9384. &pipe_config->name, adjust) && \
  9385. !intel_compare_link_m_n(&current_config->alt_name, \
  9386. &pipe_config->name, adjust)) { \
  9387. pipe_config_err(adjust, __stringify(name), \
  9388. "(expected tu %i gmch %i/%i link %i/%i, " \
  9389. "or tu %i gmch %i/%i link %i/%i, " \
  9390. "found tu %i, gmch %i/%i link %i/%i)\n", \
  9391. current_config->name.tu, \
  9392. current_config->name.gmch_m, \
  9393. current_config->name.gmch_n, \
  9394. current_config->name.link_m, \
  9395. current_config->name.link_n, \
  9396. current_config->alt_name.tu, \
  9397. current_config->alt_name.gmch_m, \
  9398. current_config->alt_name.gmch_n, \
  9399. current_config->alt_name.link_m, \
  9400. current_config->alt_name.link_n, \
  9401. pipe_config->name.tu, \
  9402. pipe_config->name.gmch_m, \
  9403. pipe_config->name.gmch_n, \
  9404. pipe_config->name.link_m, \
  9405. pipe_config->name.link_n); \
  9406. ret = false; \
  9407. } \
  9408. } while (0)
  9409. #define PIPE_CONF_CHECK_FLAGS(name, mask) do { \
  9410. if ((current_config->name ^ pipe_config->name) & (mask)) { \
  9411. pipe_config_err(adjust, __stringify(name), \
  9412. "(%x) (expected %i, found %i)\n", \
  9413. (mask), \
  9414. current_config->name & (mask), \
  9415. pipe_config->name & (mask)); \
  9416. ret = false; \
  9417. } \
  9418. } while (0)
  9419. #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) do { \
  9420. if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
  9421. pipe_config_err(adjust, __stringify(name), \
  9422. "(expected %i, found %i)\n", \
  9423. current_config->name, \
  9424. pipe_config->name); \
  9425. ret = false; \
  9426. } \
  9427. } while (0)
  9428. #define PIPE_CONF_QUIRK(quirk) \
  9429. ((current_config->quirks | pipe_config->quirks) & (quirk))
  9430. PIPE_CONF_CHECK_I(cpu_transcoder);
  9431. PIPE_CONF_CHECK_BOOL(has_pch_encoder);
  9432. PIPE_CONF_CHECK_I(fdi_lanes);
  9433. PIPE_CONF_CHECK_M_N(fdi_m_n);
  9434. PIPE_CONF_CHECK_I(lane_count);
  9435. PIPE_CONF_CHECK_X(lane_lat_optim_mask);
  9436. if (INTEL_GEN(dev_priv) < 8) {
  9437. PIPE_CONF_CHECK_M_N(dp_m_n);
  9438. if (current_config->has_drrs)
  9439. PIPE_CONF_CHECK_M_N(dp_m2_n2);
  9440. } else
  9441. PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2);
  9442. PIPE_CONF_CHECK_X(output_types);
  9443. PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay);
  9444. PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal);
  9445. PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start);
  9446. PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end);
  9447. PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start);
  9448. PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end);
  9449. PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay);
  9450. PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal);
  9451. PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start);
  9452. PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end);
  9453. PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start);
  9454. PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end);
  9455. PIPE_CONF_CHECK_I(pixel_multiplier);
  9456. PIPE_CONF_CHECK_BOOL(has_hdmi_sink);
  9457. if ((INTEL_GEN(dev_priv) < 8 && !IS_HASWELL(dev_priv)) ||
  9458. IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  9459. PIPE_CONF_CHECK_BOOL(limited_color_range);
  9460. PIPE_CONF_CHECK_BOOL(hdmi_scrambling);
  9461. PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio);
  9462. PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_infoframe);
  9463. PIPE_CONF_CHECK_BOOL(ycbcr420);
  9464. PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_audio);
  9465. PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
  9466. DRM_MODE_FLAG_INTERLACE);
  9467. if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
  9468. PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
  9469. DRM_MODE_FLAG_PHSYNC);
  9470. PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
  9471. DRM_MODE_FLAG_NHSYNC);
  9472. PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
  9473. DRM_MODE_FLAG_PVSYNC);
  9474. PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
  9475. DRM_MODE_FLAG_NVSYNC);
  9476. }
  9477. PIPE_CONF_CHECK_X(gmch_pfit.control);
  9478. /* pfit ratios are autocomputed by the hw on gen4+ */
  9479. if (INTEL_GEN(dev_priv) < 4)
  9480. PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios);
  9481. PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits);
  9482. if (!adjust) {
  9483. PIPE_CONF_CHECK_I(pipe_src_w);
  9484. PIPE_CONF_CHECK_I(pipe_src_h);
  9485. PIPE_CONF_CHECK_BOOL(pch_pfit.enabled);
  9486. if (current_config->pch_pfit.enabled) {
  9487. PIPE_CONF_CHECK_X(pch_pfit.pos);
  9488. PIPE_CONF_CHECK_X(pch_pfit.size);
  9489. }
  9490. PIPE_CONF_CHECK_I(scaler_state.scaler_id);
  9491. PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate);
  9492. }
  9493. PIPE_CONF_CHECK_BOOL(double_wide);
  9494. PIPE_CONF_CHECK_P(shared_dpll);
  9495. PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
  9496. PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
  9497. PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
  9498. PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
  9499. PIPE_CONF_CHECK_X(dpll_hw_state.wrpll);
  9500. PIPE_CONF_CHECK_X(dpll_hw_state.spll);
  9501. PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1);
  9502. PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1);
  9503. PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2);
  9504. PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr0);
  9505. PIPE_CONF_CHECK_X(dpll_hw_state.ebb0);
  9506. PIPE_CONF_CHECK_X(dpll_hw_state.ebb4);
  9507. PIPE_CONF_CHECK_X(dpll_hw_state.pll0);
  9508. PIPE_CONF_CHECK_X(dpll_hw_state.pll1);
  9509. PIPE_CONF_CHECK_X(dpll_hw_state.pll2);
  9510. PIPE_CONF_CHECK_X(dpll_hw_state.pll3);
  9511. PIPE_CONF_CHECK_X(dpll_hw_state.pll6);
  9512. PIPE_CONF_CHECK_X(dpll_hw_state.pll8);
  9513. PIPE_CONF_CHECK_X(dpll_hw_state.pll9);
  9514. PIPE_CONF_CHECK_X(dpll_hw_state.pll10);
  9515. PIPE_CONF_CHECK_X(dpll_hw_state.pcsdw12);
  9516. PIPE_CONF_CHECK_X(dsi_pll.ctrl);
  9517. PIPE_CONF_CHECK_X(dsi_pll.div);
  9518. if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5)
  9519. PIPE_CONF_CHECK_I(pipe_bpp);
  9520. PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock);
  9521. PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock);
  9522. PIPE_CONF_CHECK_I(min_voltage_level);
  9523. #undef PIPE_CONF_CHECK_X
  9524. #undef PIPE_CONF_CHECK_I
  9525. #undef PIPE_CONF_CHECK_BOOL
  9526. #undef PIPE_CONF_CHECK_BOOL_INCOMPLETE
  9527. #undef PIPE_CONF_CHECK_P
  9528. #undef PIPE_CONF_CHECK_FLAGS
  9529. #undef PIPE_CONF_CHECK_CLOCK_FUZZY
  9530. #undef PIPE_CONF_QUIRK
  9531. return ret;
  9532. }
  9533. static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv,
  9534. const struct intel_crtc_state *pipe_config)
  9535. {
  9536. if (pipe_config->has_pch_encoder) {
  9537. int fdi_dotclock = intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
  9538. &pipe_config->fdi_m_n);
  9539. int dotclock = pipe_config->base.adjusted_mode.crtc_clock;
  9540. /*
  9541. * FDI already provided one idea for the dotclock.
  9542. * Yell if the encoder disagrees.
  9543. */
  9544. WARN(!intel_fuzzy_clock_check(fdi_dotclock, dotclock),
  9545. "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
  9546. fdi_dotclock, dotclock);
  9547. }
  9548. }
  9549. static void verify_wm_state(struct drm_crtc *crtc,
  9550. struct drm_crtc_state *new_state)
  9551. {
  9552. struct drm_i915_private *dev_priv = to_i915(crtc->dev);
  9553. struct skl_ddb_allocation hw_ddb, *sw_ddb;
  9554. struct skl_pipe_wm hw_wm, *sw_wm;
  9555. struct skl_plane_wm *hw_plane_wm, *sw_plane_wm;
  9556. struct skl_ddb_entry *hw_ddb_entry, *sw_ddb_entry;
  9557. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  9558. const enum pipe pipe = intel_crtc->pipe;
  9559. int plane, level, max_level = ilk_wm_max_level(dev_priv);
  9560. if (INTEL_GEN(dev_priv) < 9 || !new_state->active)
  9561. return;
  9562. skl_pipe_wm_get_hw_state(crtc, &hw_wm);
  9563. sw_wm = &to_intel_crtc_state(new_state)->wm.skl.optimal;
  9564. skl_ddb_get_hw_state(dev_priv, &hw_ddb);
  9565. sw_ddb = &dev_priv->wm.skl_hw.ddb;
  9566. /* planes */
  9567. for_each_universal_plane(dev_priv, pipe, plane) {
  9568. hw_plane_wm = &hw_wm.planes[plane];
  9569. sw_plane_wm = &sw_wm->planes[plane];
  9570. /* Watermarks */
  9571. for (level = 0; level <= max_level; level++) {
  9572. if (skl_wm_level_equals(&hw_plane_wm->wm[level],
  9573. &sw_plane_wm->wm[level]))
  9574. continue;
  9575. DRM_ERROR("mismatch in WM pipe %c plane %d level %d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
  9576. pipe_name(pipe), plane + 1, level,
  9577. sw_plane_wm->wm[level].plane_en,
  9578. sw_plane_wm->wm[level].plane_res_b,
  9579. sw_plane_wm->wm[level].plane_res_l,
  9580. hw_plane_wm->wm[level].plane_en,
  9581. hw_plane_wm->wm[level].plane_res_b,
  9582. hw_plane_wm->wm[level].plane_res_l);
  9583. }
  9584. if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
  9585. &sw_plane_wm->trans_wm)) {
  9586. DRM_ERROR("mismatch in trans WM pipe %c plane %d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
  9587. pipe_name(pipe), plane + 1,
  9588. sw_plane_wm->trans_wm.plane_en,
  9589. sw_plane_wm->trans_wm.plane_res_b,
  9590. sw_plane_wm->trans_wm.plane_res_l,
  9591. hw_plane_wm->trans_wm.plane_en,
  9592. hw_plane_wm->trans_wm.plane_res_b,
  9593. hw_plane_wm->trans_wm.plane_res_l);
  9594. }
  9595. /* DDB */
  9596. hw_ddb_entry = &hw_ddb.plane[pipe][plane];
  9597. sw_ddb_entry = &sw_ddb->plane[pipe][plane];
  9598. if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
  9599. DRM_ERROR("mismatch in DDB state pipe %c plane %d (expected (%u,%u), found (%u,%u))\n",
  9600. pipe_name(pipe), plane + 1,
  9601. sw_ddb_entry->start, sw_ddb_entry->end,
  9602. hw_ddb_entry->start, hw_ddb_entry->end);
  9603. }
  9604. }
  9605. /*
  9606. * cursor
  9607. * If the cursor plane isn't active, we may not have updated it's ddb
  9608. * allocation. In that case since the ddb allocation will be updated
  9609. * once the plane becomes visible, we can skip this check
  9610. */
  9611. if (1) {
  9612. hw_plane_wm = &hw_wm.planes[PLANE_CURSOR];
  9613. sw_plane_wm = &sw_wm->planes[PLANE_CURSOR];
  9614. /* Watermarks */
  9615. for (level = 0; level <= max_level; level++) {
  9616. if (skl_wm_level_equals(&hw_plane_wm->wm[level],
  9617. &sw_plane_wm->wm[level]))
  9618. continue;
  9619. DRM_ERROR("mismatch in WM pipe %c cursor level %d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
  9620. pipe_name(pipe), level,
  9621. sw_plane_wm->wm[level].plane_en,
  9622. sw_plane_wm->wm[level].plane_res_b,
  9623. sw_plane_wm->wm[level].plane_res_l,
  9624. hw_plane_wm->wm[level].plane_en,
  9625. hw_plane_wm->wm[level].plane_res_b,
  9626. hw_plane_wm->wm[level].plane_res_l);
  9627. }
  9628. if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
  9629. &sw_plane_wm->trans_wm)) {
  9630. DRM_ERROR("mismatch in trans WM pipe %c cursor (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
  9631. pipe_name(pipe),
  9632. sw_plane_wm->trans_wm.plane_en,
  9633. sw_plane_wm->trans_wm.plane_res_b,
  9634. sw_plane_wm->trans_wm.plane_res_l,
  9635. hw_plane_wm->trans_wm.plane_en,
  9636. hw_plane_wm->trans_wm.plane_res_b,
  9637. hw_plane_wm->trans_wm.plane_res_l);
  9638. }
  9639. /* DDB */
  9640. hw_ddb_entry = &hw_ddb.plane[pipe][PLANE_CURSOR];
  9641. sw_ddb_entry = &sw_ddb->plane[pipe][PLANE_CURSOR];
  9642. if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
  9643. DRM_ERROR("mismatch in DDB state pipe %c cursor (expected (%u,%u), found (%u,%u))\n",
  9644. pipe_name(pipe),
  9645. sw_ddb_entry->start, sw_ddb_entry->end,
  9646. hw_ddb_entry->start, hw_ddb_entry->end);
  9647. }
  9648. }
  9649. }
  9650. static void
  9651. verify_connector_state(struct drm_device *dev,
  9652. struct drm_atomic_state *state,
  9653. struct drm_crtc *crtc)
  9654. {
  9655. struct drm_connector *connector;
  9656. struct drm_connector_state *new_conn_state;
  9657. int i;
  9658. for_each_new_connector_in_state(state, connector, new_conn_state, i) {
  9659. struct drm_encoder *encoder = connector->encoder;
  9660. struct drm_crtc_state *crtc_state = NULL;
  9661. if (new_conn_state->crtc != crtc)
  9662. continue;
  9663. if (crtc)
  9664. crtc_state = drm_atomic_get_new_crtc_state(state, new_conn_state->crtc);
  9665. intel_connector_verify_state(crtc_state, new_conn_state);
  9666. I915_STATE_WARN(new_conn_state->best_encoder != encoder,
  9667. "connector's atomic encoder doesn't match legacy encoder\n");
  9668. }
  9669. }
  9670. static void
  9671. verify_encoder_state(struct drm_device *dev, struct drm_atomic_state *state)
  9672. {
  9673. struct intel_encoder *encoder;
  9674. struct drm_connector *connector;
  9675. struct drm_connector_state *old_conn_state, *new_conn_state;
  9676. int i;
  9677. for_each_intel_encoder(dev, encoder) {
  9678. bool enabled = false, found = false;
  9679. enum pipe pipe;
  9680. DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
  9681. encoder->base.base.id,
  9682. encoder->base.name);
  9683. for_each_oldnew_connector_in_state(state, connector, old_conn_state,
  9684. new_conn_state, i) {
  9685. if (old_conn_state->best_encoder == &encoder->base)
  9686. found = true;
  9687. if (new_conn_state->best_encoder != &encoder->base)
  9688. continue;
  9689. found = enabled = true;
  9690. I915_STATE_WARN(new_conn_state->crtc !=
  9691. encoder->base.crtc,
  9692. "connector's crtc doesn't match encoder crtc\n");
  9693. }
  9694. if (!found)
  9695. continue;
  9696. I915_STATE_WARN(!!encoder->base.crtc != enabled,
  9697. "encoder's enabled state mismatch "
  9698. "(expected %i, found %i)\n",
  9699. !!encoder->base.crtc, enabled);
  9700. if (!encoder->base.crtc) {
  9701. bool active;
  9702. active = encoder->get_hw_state(encoder, &pipe);
  9703. I915_STATE_WARN(active,
  9704. "encoder detached but still enabled on pipe %c.\n",
  9705. pipe_name(pipe));
  9706. }
  9707. }
  9708. }
  9709. static void
  9710. verify_crtc_state(struct drm_crtc *crtc,
  9711. struct drm_crtc_state *old_crtc_state,
  9712. struct drm_crtc_state *new_crtc_state)
  9713. {
  9714. struct drm_device *dev = crtc->dev;
  9715. struct drm_i915_private *dev_priv = to_i915(dev);
  9716. struct intel_encoder *encoder;
  9717. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  9718. struct intel_crtc_state *pipe_config, *sw_config;
  9719. struct drm_atomic_state *old_state;
  9720. bool active;
  9721. old_state = old_crtc_state->state;
  9722. __drm_atomic_helper_crtc_destroy_state(old_crtc_state);
  9723. pipe_config = to_intel_crtc_state(old_crtc_state);
  9724. memset(pipe_config, 0, sizeof(*pipe_config));
  9725. pipe_config->base.crtc = crtc;
  9726. pipe_config->base.state = old_state;
  9727. DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name);
  9728. active = dev_priv->display.get_pipe_config(intel_crtc, pipe_config);
  9729. /* we keep both pipes enabled on 830 */
  9730. if (IS_I830(dev_priv))
  9731. active = new_crtc_state->active;
  9732. I915_STATE_WARN(new_crtc_state->active != active,
  9733. "crtc active state doesn't match with hw state "
  9734. "(expected %i, found %i)\n", new_crtc_state->active, active);
  9735. I915_STATE_WARN(intel_crtc->active != new_crtc_state->active,
  9736. "transitional active state does not match atomic hw state "
  9737. "(expected %i, found %i)\n", new_crtc_state->active, intel_crtc->active);
  9738. for_each_encoder_on_crtc(dev, crtc, encoder) {
  9739. enum pipe pipe;
  9740. active = encoder->get_hw_state(encoder, &pipe);
  9741. I915_STATE_WARN(active != new_crtc_state->active,
  9742. "[ENCODER:%i] active %i with crtc active %i\n",
  9743. encoder->base.base.id, active, new_crtc_state->active);
  9744. I915_STATE_WARN(active && intel_crtc->pipe != pipe,
  9745. "Encoder connected to wrong pipe %c\n",
  9746. pipe_name(pipe));
  9747. if (active)
  9748. encoder->get_config(encoder, pipe_config);
  9749. }
  9750. intel_crtc_compute_pixel_rate(pipe_config);
  9751. if (!new_crtc_state->active)
  9752. return;
  9753. intel_pipe_config_sanity_check(dev_priv, pipe_config);
  9754. sw_config = to_intel_crtc_state(new_crtc_state);
  9755. if (!intel_pipe_config_compare(dev_priv, sw_config,
  9756. pipe_config, false)) {
  9757. I915_STATE_WARN(1, "pipe state doesn't match!\n");
  9758. intel_dump_pipe_config(intel_crtc, pipe_config,
  9759. "[hw state]");
  9760. intel_dump_pipe_config(intel_crtc, sw_config,
  9761. "[sw state]");
  9762. }
  9763. }
  9764. static void
  9765. intel_verify_planes(struct intel_atomic_state *state)
  9766. {
  9767. struct intel_plane *plane;
  9768. const struct intel_plane_state *plane_state;
  9769. int i;
  9770. for_each_new_intel_plane_in_state(state, plane,
  9771. plane_state, i)
  9772. assert_plane(plane, plane_state->base.visible);
  9773. }
  9774. static void
  9775. verify_single_dpll_state(struct drm_i915_private *dev_priv,
  9776. struct intel_shared_dpll *pll,
  9777. struct drm_crtc *crtc,
  9778. struct drm_crtc_state *new_state)
  9779. {
  9780. struct intel_dpll_hw_state dpll_hw_state;
  9781. unsigned crtc_mask;
  9782. bool active;
  9783. memset(&dpll_hw_state, 0, sizeof(dpll_hw_state));
  9784. DRM_DEBUG_KMS("%s\n", pll->info->name);
  9785. active = pll->info->funcs->get_hw_state(dev_priv, pll, &dpll_hw_state);
  9786. if (!(pll->info->flags & INTEL_DPLL_ALWAYS_ON)) {
  9787. I915_STATE_WARN(!pll->on && pll->active_mask,
  9788. "pll in active use but not on in sw tracking\n");
  9789. I915_STATE_WARN(pll->on && !pll->active_mask,
  9790. "pll is on but not used by any active crtc\n");
  9791. I915_STATE_WARN(pll->on != active,
  9792. "pll on state mismatch (expected %i, found %i)\n",
  9793. pll->on, active);
  9794. }
  9795. if (!crtc) {
  9796. I915_STATE_WARN(pll->active_mask & ~pll->state.crtc_mask,
  9797. "more active pll users than references: %x vs %x\n",
  9798. pll->active_mask, pll->state.crtc_mask);
  9799. return;
  9800. }
  9801. crtc_mask = 1 << drm_crtc_index(crtc);
  9802. if (new_state->active)
  9803. I915_STATE_WARN(!(pll->active_mask & crtc_mask),
  9804. "pll active mismatch (expected pipe %c in active mask 0x%02x)\n",
  9805. pipe_name(drm_crtc_index(crtc)), pll->active_mask);
  9806. else
  9807. I915_STATE_WARN(pll->active_mask & crtc_mask,
  9808. "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n",
  9809. pipe_name(drm_crtc_index(crtc)), pll->active_mask);
  9810. I915_STATE_WARN(!(pll->state.crtc_mask & crtc_mask),
  9811. "pll enabled crtcs mismatch (expected 0x%x in 0x%02x)\n",
  9812. crtc_mask, pll->state.crtc_mask);
  9813. I915_STATE_WARN(pll->on && memcmp(&pll->state.hw_state,
  9814. &dpll_hw_state,
  9815. sizeof(dpll_hw_state)),
  9816. "pll hw state mismatch\n");
  9817. }
  9818. static void
  9819. verify_shared_dpll_state(struct drm_device *dev, struct drm_crtc *crtc,
  9820. struct drm_crtc_state *old_crtc_state,
  9821. struct drm_crtc_state *new_crtc_state)
  9822. {
  9823. struct drm_i915_private *dev_priv = to_i915(dev);
  9824. struct intel_crtc_state *old_state = to_intel_crtc_state(old_crtc_state);
  9825. struct intel_crtc_state *new_state = to_intel_crtc_state(new_crtc_state);
  9826. if (new_state->shared_dpll)
  9827. verify_single_dpll_state(dev_priv, new_state->shared_dpll, crtc, new_crtc_state);
  9828. if (old_state->shared_dpll &&
  9829. old_state->shared_dpll != new_state->shared_dpll) {
  9830. unsigned crtc_mask = 1 << drm_crtc_index(crtc);
  9831. struct intel_shared_dpll *pll = old_state->shared_dpll;
  9832. I915_STATE_WARN(pll->active_mask & crtc_mask,
  9833. "pll active mismatch (didn't expect pipe %c in active mask)\n",
  9834. pipe_name(drm_crtc_index(crtc)));
  9835. I915_STATE_WARN(pll->state.crtc_mask & crtc_mask,
  9836. "pll enabled crtcs mismatch (found %x in enabled mask)\n",
  9837. pipe_name(drm_crtc_index(crtc)));
  9838. }
  9839. }
  9840. static void
  9841. intel_modeset_verify_crtc(struct drm_crtc *crtc,
  9842. struct drm_atomic_state *state,
  9843. struct drm_crtc_state *old_state,
  9844. struct drm_crtc_state *new_state)
  9845. {
  9846. if (!needs_modeset(new_state) &&
  9847. !to_intel_crtc_state(new_state)->update_pipe)
  9848. return;
  9849. verify_wm_state(crtc, new_state);
  9850. verify_connector_state(crtc->dev, state, crtc);
  9851. verify_crtc_state(crtc, old_state, new_state);
  9852. verify_shared_dpll_state(crtc->dev, crtc, old_state, new_state);
  9853. }
  9854. static void
  9855. verify_disabled_dpll_state(struct drm_device *dev)
  9856. {
  9857. struct drm_i915_private *dev_priv = to_i915(dev);
  9858. int i;
  9859. for (i = 0; i < dev_priv->num_shared_dpll; i++)
  9860. verify_single_dpll_state(dev_priv, &dev_priv->shared_dplls[i], NULL, NULL);
  9861. }
  9862. static void
  9863. intel_modeset_verify_disabled(struct drm_device *dev,
  9864. struct drm_atomic_state *state)
  9865. {
  9866. verify_encoder_state(dev, state);
  9867. verify_connector_state(dev, state, NULL);
  9868. verify_disabled_dpll_state(dev);
  9869. }
  9870. static void update_scanline_offset(struct intel_crtc *crtc)
  9871. {
  9872. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  9873. /*
  9874. * The scanline counter increments at the leading edge of hsync.
  9875. *
  9876. * On most platforms it starts counting from vtotal-1 on the
  9877. * first active line. That means the scanline counter value is
  9878. * always one less than what we would expect. Ie. just after
  9879. * start of vblank, which also occurs at start of hsync (on the
  9880. * last active line), the scanline counter will read vblank_start-1.
  9881. *
  9882. * On gen2 the scanline counter starts counting from 1 instead
  9883. * of vtotal-1, so we have to subtract one (or rather add vtotal-1
  9884. * to keep the value positive), instead of adding one.
  9885. *
  9886. * On HSW+ the behaviour of the scanline counter depends on the output
  9887. * type. For DP ports it behaves like most other platforms, but on HDMI
  9888. * there's an extra 1 line difference. So we need to add two instead of
  9889. * one to the value.
  9890. *
  9891. * On VLV/CHV DSI the scanline counter would appear to increment
  9892. * approx. 1/3 of a scanline before start of vblank. Unfortunately
  9893. * that means we can't tell whether we're in vblank or not while
  9894. * we're on that particular line. We must still set scanline_offset
  9895. * to 1 so that the vblank timestamps come out correct when we query
  9896. * the scanline counter from within the vblank interrupt handler.
  9897. * However if queried just before the start of vblank we'll get an
  9898. * answer that's slightly in the future.
  9899. */
  9900. if (IS_GEN2(dev_priv)) {
  9901. const struct drm_display_mode *adjusted_mode = &crtc->config->base.adjusted_mode;
  9902. int vtotal;
  9903. vtotal = adjusted_mode->crtc_vtotal;
  9904. if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
  9905. vtotal /= 2;
  9906. crtc->scanline_offset = vtotal - 1;
  9907. } else if (HAS_DDI(dev_priv) &&
  9908. intel_crtc_has_type(crtc->config, INTEL_OUTPUT_HDMI)) {
  9909. crtc->scanline_offset = 2;
  9910. } else
  9911. crtc->scanline_offset = 1;
  9912. }
  9913. static void intel_modeset_clear_plls(struct drm_atomic_state *state)
  9914. {
  9915. struct drm_device *dev = state->dev;
  9916. struct drm_i915_private *dev_priv = to_i915(dev);
  9917. struct drm_crtc *crtc;
  9918. struct drm_crtc_state *old_crtc_state, *new_crtc_state;
  9919. int i;
  9920. if (!dev_priv->display.crtc_compute_clock)
  9921. return;
  9922. for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
  9923. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  9924. struct intel_shared_dpll *old_dpll =
  9925. to_intel_crtc_state(old_crtc_state)->shared_dpll;
  9926. if (!needs_modeset(new_crtc_state))
  9927. continue;
  9928. to_intel_crtc_state(new_crtc_state)->shared_dpll = NULL;
  9929. if (!old_dpll)
  9930. continue;
  9931. intel_release_shared_dpll(old_dpll, intel_crtc, state);
  9932. }
  9933. }
  9934. /*
  9935. * This implements the workaround described in the "notes" section of the mode
  9936. * set sequence documentation. When going from no pipes or single pipe to
  9937. * multiple pipes, and planes are enabled after the pipe, we need to wait at
  9938. * least 2 vblanks on the first pipe before enabling planes on the second pipe.
  9939. */
  9940. static int haswell_mode_set_planes_workaround(struct drm_atomic_state *state)
  9941. {
  9942. struct drm_crtc_state *crtc_state;
  9943. struct intel_crtc *intel_crtc;
  9944. struct drm_crtc *crtc;
  9945. struct intel_crtc_state *first_crtc_state = NULL;
  9946. struct intel_crtc_state *other_crtc_state = NULL;
  9947. enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE;
  9948. int i;
  9949. /* look at all crtc's that are going to be enabled in during modeset */
  9950. for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
  9951. intel_crtc = to_intel_crtc(crtc);
  9952. if (!crtc_state->active || !needs_modeset(crtc_state))
  9953. continue;
  9954. if (first_crtc_state) {
  9955. other_crtc_state = to_intel_crtc_state(crtc_state);
  9956. break;
  9957. } else {
  9958. first_crtc_state = to_intel_crtc_state(crtc_state);
  9959. first_pipe = intel_crtc->pipe;
  9960. }
  9961. }
  9962. /* No workaround needed? */
  9963. if (!first_crtc_state)
  9964. return 0;
  9965. /* w/a possibly needed, check how many crtc's are already enabled. */
  9966. for_each_intel_crtc(state->dev, intel_crtc) {
  9967. struct intel_crtc_state *pipe_config;
  9968. pipe_config = intel_atomic_get_crtc_state(state, intel_crtc);
  9969. if (IS_ERR(pipe_config))
  9970. return PTR_ERR(pipe_config);
  9971. pipe_config->hsw_workaround_pipe = INVALID_PIPE;
  9972. if (!pipe_config->base.active ||
  9973. needs_modeset(&pipe_config->base))
  9974. continue;
  9975. /* 2 or more enabled crtcs means no need for w/a */
  9976. if (enabled_pipe != INVALID_PIPE)
  9977. return 0;
  9978. enabled_pipe = intel_crtc->pipe;
  9979. }
  9980. if (enabled_pipe != INVALID_PIPE)
  9981. first_crtc_state->hsw_workaround_pipe = enabled_pipe;
  9982. else if (other_crtc_state)
  9983. other_crtc_state->hsw_workaround_pipe = first_pipe;
  9984. return 0;
  9985. }
  9986. static int intel_lock_all_pipes(struct drm_atomic_state *state)
  9987. {
  9988. struct drm_crtc *crtc;
  9989. /* Add all pipes to the state */
  9990. for_each_crtc(state->dev, crtc) {
  9991. struct drm_crtc_state *crtc_state;
  9992. crtc_state = drm_atomic_get_crtc_state(state, crtc);
  9993. if (IS_ERR(crtc_state))
  9994. return PTR_ERR(crtc_state);
  9995. }
  9996. return 0;
  9997. }
  9998. static int intel_modeset_all_pipes(struct drm_atomic_state *state)
  9999. {
  10000. struct drm_crtc *crtc;
  10001. /*
  10002. * Add all pipes to the state, and force
  10003. * a modeset on all the active ones.
  10004. */
  10005. for_each_crtc(state->dev, crtc) {
  10006. struct drm_crtc_state *crtc_state;
  10007. int ret;
  10008. crtc_state = drm_atomic_get_crtc_state(state, crtc);
  10009. if (IS_ERR(crtc_state))
  10010. return PTR_ERR(crtc_state);
  10011. if (!crtc_state->active || needs_modeset(crtc_state))
  10012. continue;
  10013. crtc_state->mode_changed = true;
  10014. ret = drm_atomic_add_affected_connectors(state, crtc);
  10015. if (ret)
  10016. return ret;
  10017. ret = drm_atomic_add_affected_planes(state, crtc);
  10018. if (ret)
  10019. return ret;
  10020. }
  10021. return 0;
  10022. }
  10023. static int intel_modeset_checks(struct drm_atomic_state *state)
  10024. {
  10025. struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
  10026. struct drm_i915_private *dev_priv = to_i915(state->dev);
  10027. struct drm_crtc *crtc;
  10028. struct drm_crtc_state *old_crtc_state, *new_crtc_state;
  10029. int ret = 0, i;
  10030. if (!check_digital_port_conflicts(state)) {
  10031. DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n");
  10032. return -EINVAL;
  10033. }
  10034. intel_state->modeset = true;
  10035. intel_state->active_crtcs = dev_priv->active_crtcs;
  10036. intel_state->cdclk.logical = dev_priv->cdclk.logical;
  10037. intel_state->cdclk.actual = dev_priv->cdclk.actual;
  10038. for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
  10039. if (new_crtc_state->active)
  10040. intel_state->active_crtcs |= 1 << i;
  10041. else
  10042. intel_state->active_crtcs &= ~(1 << i);
  10043. if (old_crtc_state->active != new_crtc_state->active)
  10044. intel_state->active_pipe_changes |= drm_crtc_mask(crtc);
  10045. }
  10046. /*
  10047. * See if the config requires any additional preparation, e.g.
  10048. * to adjust global state with pipes off. We need to do this
  10049. * here so we can get the modeset_pipe updated config for the new
  10050. * mode set on this crtc. For other crtcs we need to use the
  10051. * adjusted_mode bits in the crtc directly.
  10052. */
  10053. if (dev_priv->display.modeset_calc_cdclk) {
  10054. ret = dev_priv->display.modeset_calc_cdclk(state);
  10055. if (ret < 0)
  10056. return ret;
  10057. /*
  10058. * Writes to dev_priv->cdclk.logical must protected by
  10059. * holding all the crtc locks, even if we don't end up
  10060. * touching the hardware
  10061. */
  10062. if (intel_cdclk_changed(&dev_priv->cdclk.logical,
  10063. &intel_state->cdclk.logical)) {
  10064. ret = intel_lock_all_pipes(state);
  10065. if (ret < 0)
  10066. return ret;
  10067. }
  10068. /* All pipes must be switched off while we change the cdclk. */
  10069. if (intel_cdclk_needs_modeset(&dev_priv->cdclk.actual,
  10070. &intel_state->cdclk.actual)) {
  10071. ret = intel_modeset_all_pipes(state);
  10072. if (ret < 0)
  10073. return ret;
  10074. }
  10075. DRM_DEBUG_KMS("New cdclk calculated to be logical %u kHz, actual %u kHz\n",
  10076. intel_state->cdclk.logical.cdclk,
  10077. intel_state->cdclk.actual.cdclk);
  10078. DRM_DEBUG_KMS("New voltage level calculated to be logical %u, actual %u\n",
  10079. intel_state->cdclk.logical.voltage_level,
  10080. intel_state->cdclk.actual.voltage_level);
  10081. } else {
  10082. to_intel_atomic_state(state)->cdclk.logical = dev_priv->cdclk.logical;
  10083. }
  10084. intel_modeset_clear_plls(state);
  10085. if (IS_HASWELL(dev_priv))
  10086. return haswell_mode_set_planes_workaround(state);
  10087. return 0;
  10088. }
  10089. /*
  10090. * Handle calculation of various watermark data at the end of the atomic check
  10091. * phase. The code here should be run after the per-crtc and per-plane 'check'
  10092. * handlers to ensure that all derived state has been updated.
  10093. */
  10094. static int calc_watermark_data(struct drm_atomic_state *state)
  10095. {
  10096. struct drm_device *dev = state->dev;
  10097. struct drm_i915_private *dev_priv = to_i915(dev);
  10098. /* Is there platform-specific watermark information to calculate? */
  10099. if (dev_priv->display.compute_global_watermarks)
  10100. return dev_priv->display.compute_global_watermarks(state);
  10101. return 0;
  10102. }
  10103. /**
  10104. * intel_atomic_check - validate state object
  10105. * @dev: drm device
  10106. * @state: state to validate
  10107. */
  10108. static int intel_atomic_check(struct drm_device *dev,
  10109. struct drm_atomic_state *state)
  10110. {
  10111. struct drm_i915_private *dev_priv = to_i915(dev);
  10112. struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
  10113. struct drm_crtc *crtc;
  10114. struct drm_crtc_state *old_crtc_state, *crtc_state;
  10115. int ret, i;
  10116. bool any_ms = false;
  10117. /* Catch I915_MODE_FLAG_INHERITED */
  10118. for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state,
  10119. crtc_state, i) {
  10120. if (crtc_state->mode.private_flags !=
  10121. old_crtc_state->mode.private_flags)
  10122. crtc_state->mode_changed = true;
  10123. }
  10124. ret = drm_atomic_helper_check_modeset(dev, state);
  10125. if (ret)
  10126. return ret;
  10127. for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, crtc_state, i) {
  10128. struct intel_crtc_state *pipe_config =
  10129. to_intel_crtc_state(crtc_state);
  10130. if (!needs_modeset(crtc_state))
  10131. continue;
  10132. if (!crtc_state->enable) {
  10133. any_ms = true;
  10134. continue;
  10135. }
  10136. ret = intel_modeset_pipe_config(crtc, pipe_config);
  10137. if (ret) {
  10138. intel_dump_pipe_config(to_intel_crtc(crtc),
  10139. pipe_config, "[failed]");
  10140. return ret;
  10141. }
  10142. if (i915_modparams.fastboot &&
  10143. intel_pipe_config_compare(dev_priv,
  10144. to_intel_crtc_state(old_crtc_state),
  10145. pipe_config, true)) {
  10146. crtc_state->mode_changed = false;
  10147. pipe_config->update_pipe = true;
  10148. }
  10149. if (needs_modeset(crtc_state))
  10150. any_ms = true;
  10151. intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config,
  10152. needs_modeset(crtc_state) ?
  10153. "[modeset]" : "[fastset]");
  10154. }
  10155. if (any_ms) {
  10156. ret = intel_modeset_checks(state);
  10157. if (ret)
  10158. return ret;
  10159. } else {
  10160. intel_state->cdclk.logical = dev_priv->cdclk.logical;
  10161. }
  10162. ret = drm_atomic_helper_check_planes(dev, state);
  10163. if (ret)
  10164. return ret;
  10165. intel_fbc_choose_crtc(dev_priv, intel_state);
  10166. return calc_watermark_data(state);
  10167. }
  10168. static int intel_atomic_prepare_commit(struct drm_device *dev,
  10169. struct drm_atomic_state *state)
  10170. {
  10171. return drm_atomic_helper_prepare_planes(dev, state);
  10172. }
  10173. u32 intel_crtc_get_vblank_counter(struct intel_crtc *crtc)
  10174. {
  10175. struct drm_device *dev = crtc->base.dev;
  10176. if (!dev->max_vblank_count)
  10177. return (u32)drm_crtc_accurate_vblank_count(&crtc->base);
  10178. return dev->driver->get_vblank_counter(dev, crtc->pipe);
  10179. }
  10180. static void intel_update_crtc(struct drm_crtc *crtc,
  10181. struct drm_atomic_state *state,
  10182. struct drm_crtc_state *old_crtc_state,
  10183. struct drm_crtc_state *new_crtc_state)
  10184. {
  10185. struct drm_device *dev = crtc->dev;
  10186. struct drm_i915_private *dev_priv = to_i915(dev);
  10187. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  10188. struct intel_crtc_state *pipe_config = to_intel_crtc_state(new_crtc_state);
  10189. bool modeset = needs_modeset(new_crtc_state);
  10190. struct intel_plane_state *new_plane_state =
  10191. intel_atomic_get_new_plane_state(to_intel_atomic_state(state),
  10192. to_intel_plane(crtc->primary));
  10193. if (modeset) {
  10194. update_scanline_offset(intel_crtc);
  10195. dev_priv->display.crtc_enable(pipe_config, state);
  10196. /* vblanks work again, re-enable pipe CRC. */
  10197. intel_crtc_enable_pipe_crc(intel_crtc);
  10198. } else {
  10199. intel_pre_plane_update(to_intel_crtc_state(old_crtc_state),
  10200. pipe_config);
  10201. }
  10202. if (new_plane_state)
  10203. intel_fbc_enable(intel_crtc, pipe_config, new_plane_state);
  10204. drm_atomic_helper_commit_planes_on_crtc(old_crtc_state);
  10205. }
  10206. static void intel_update_crtcs(struct drm_atomic_state *state)
  10207. {
  10208. struct drm_crtc *crtc;
  10209. struct drm_crtc_state *old_crtc_state, *new_crtc_state;
  10210. int i;
  10211. for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
  10212. if (!new_crtc_state->active)
  10213. continue;
  10214. intel_update_crtc(crtc, state, old_crtc_state,
  10215. new_crtc_state);
  10216. }
  10217. }
  10218. static void skl_update_crtcs(struct drm_atomic_state *state)
  10219. {
  10220. struct drm_i915_private *dev_priv = to_i915(state->dev);
  10221. struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
  10222. struct drm_crtc *crtc;
  10223. struct intel_crtc *intel_crtc;
  10224. struct drm_crtc_state *old_crtc_state, *new_crtc_state;
  10225. struct intel_crtc_state *cstate;
  10226. unsigned int updated = 0;
  10227. bool progress;
  10228. enum pipe pipe;
  10229. int i;
  10230. const struct skl_ddb_entry *entries[I915_MAX_PIPES] = {};
  10231. for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i)
  10232. /* ignore allocations for crtc's that have been turned off. */
  10233. if (new_crtc_state->active)
  10234. entries[i] = &to_intel_crtc_state(old_crtc_state)->wm.skl.ddb;
  10235. /*
  10236. * Whenever the number of active pipes changes, we need to make sure we
  10237. * update the pipes in the right order so that their ddb allocations
  10238. * never overlap with eachother inbetween CRTC updates. Otherwise we'll
  10239. * cause pipe underruns and other bad stuff.
  10240. */
  10241. do {
  10242. progress = false;
  10243. for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
  10244. bool vbl_wait = false;
  10245. unsigned int cmask = drm_crtc_mask(crtc);
  10246. intel_crtc = to_intel_crtc(crtc);
  10247. cstate = to_intel_crtc_state(new_crtc_state);
  10248. pipe = intel_crtc->pipe;
  10249. if (updated & cmask || !cstate->base.active)
  10250. continue;
  10251. if (skl_ddb_allocation_overlaps(dev_priv,
  10252. entries,
  10253. &cstate->wm.skl.ddb,
  10254. i))
  10255. continue;
  10256. updated |= cmask;
  10257. entries[i] = &cstate->wm.skl.ddb;
  10258. /*
  10259. * If this is an already active pipe, it's DDB changed,
  10260. * and this isn't the last pipe that needs updating
  10261. * then we need to wait for a vblank to pass for the
  10262. * new ddb allocation to take effect.
  10263. */
  10264. if (!skl_ddb_entry_equal(&cstate->wm.skl.ddb,
  10265. &to_intel_crtc_state(old_crtc_state)->wm.skl.ddb) &&
  10266. !new_crtc_state->active_changed &&
  10267. intel_state->wm_results.dirty_pipes != updated)
  10268. vbl_wait = true;
  10269. intel_update_crtc(crtc, state, old_crtc_state,
  10270. new_crtc_state);
  10271. if (vbl_wait)
  10272. intel_wait_for_vblank(dev_priv, pipe);
  10273. progress = true;
  10274. }
  10275. } while (progress);
  10276. }
  10277. static void intel_atomic_helper_free_state(struct drm_i915_private *dev_priv)
  10278. {
  10279. struct intel_atomic_state *state, *next;
  10280. struct llist_node *freed;
  10281. freed = llist_del_all(&dev_priv->atomic_helper.free_list);
  10282. llist_for_each_entry_safe(state, next, freed, freed)
  10283. drm_atomic_state_put(&state->base);
  10284. }
  10285. static void intel_atomic_helper_free_state_worker(struct work_struct *work)
  10286. {
  10287. struct drm_i915_private *dev_priv =
  10288. container_of(work, typeof(*dev_priv), atomic_helper.free_work);
  10289. intel_atomic_helper_free_state(dev_priv);
  10290. }
  10291. static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state)
  10292. {
  10293. struct wait_queue_entry wait_fence, wait_reset;
  10294. struct drm_i915_private *dev_priv = to_i915(intel_state->base.dev);
  10295. init_wait_entry(&wait_fence, 0);
  10296. init_wait_entry(&wait_reset, 0);
  10297. for (;;) {
  10298. prepare_to_wait(&intel_state->commit_ready.wait,
  10299. &wait_fence, TASK_UNINTERRUPTIBLE);
  10300. prepare_to_wait(&dev_priv->gpu_error.wait_queue,
  10301. &wait_reset, TASK_UNINTERRUPTIBLE);
  10302. if (i915_sw_fence_done(&intel_state->commit_ready)
  10303. || test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags))
  10304. break;
  10305. schedule();
  10306. }
  10307. finish_wait(&intel_state->commit_ready.wait, &wait_fence);
  10308. finish_wait(&dev_priv->gpu_error.wait_queue, &wait_reset);
  10309. }
  10310. static void intel_atomic_commit_tail(struct drm_atomic_state *state)
  10311. {
  10312. struct drm_device *dev = state->dev;
  10313. struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
  10314. struct drm_i915_private *dev_priv = to_i915(dev);
  10315. struct drm_crtc_state *old_crtc_state, *new_crtc_state;
  10316. struct drm_crtc *crtc;
  10317. struct intel_crtc_state *intel_cstate;
  10318. u64 put_domains[I915_MAX_PIPES] = {};
  10319. int i;
  10320. intel_atomic_commit_fence_wait(intel_state);
  10321. drm_atomic_helper_wait_for_dependencies(state);
  10322. if (intel_state->modeset)
  10323. intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET);
  10324. for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
  10325. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  10326. if (needs_modeset(new_crtc_state) ||
  10327. to_intel_crtc_state(new_crtc_state)->update_pipe) {
  10328. put_domains[to_intel_crtc(crtc)->pipe] =
  10329. modeset_get_crtc_power_domains(crtc,
  10330. to_intel_crtc_state(new_crtc_state));
  10331. }
  10332. if (!needs_modeset(new_crtc_state))
  10333. continue;
  10334. intel_pre_plane_update(to_intel_crtc_state(old_crtc_state),
  10335. to_intel_crtc_state(new_crtc_state));
  10336. if (old_crtc_state->active) {
  10337. intel_crtc_disable_planes(crtc, old_crtc_state->plane_mask);
  10338. /*
  10339. * We need to disable pipe CRC before disabling the pipe,
  10340. * or we race against vblank off.
  10341. */
  10342. intel_crtc_disable_pipe_crc(intel_crtc);
  10343. dev_priv->display.crtc_disable(to_intel_crtc_state(old_crtc_state), state);
  10344. intel_crtc->active = false;
  10345. intel_fbc_disable(intel_crtc);
  10346. intel_disable_shared_dpll(intel_crtc);
  10347. /*
  10348. * Underruns don't always raise
  10349. * interrupts, so check manually.
  10350. */
  10351. intel_check_cpu_fifo_underruns(dev_priv);
  10352. intel_check_pch_fifo_underruns(dev_priv);
  10353. if (!new_crtc_state->active) {
  10354. /*
  10355. * Make sure we don't call initial_watermarks
  10356. * for ILK-style watermark updates.
  10357. *
  10358. * No clue what this is supposed to achieve.
  10359. */
  10360. if (INTEL_GEN(dev_priv) >= 9)
  10361. dev_priv->display.initial_watermarks(intel_state,
  10362. to_intel_crtc_state(new_crtc_state));
  10363. }
  10364. }
  10365. }
  10366. /* FIXME: Eventually get rid of our intel_crtc->config pointer */
  10367. for_each_new_crtc_in_state(state, crtc, new_crtc_state, i)
  10368. to_intel_crtc(crtc)->config = to_intel_crtc_state(new_crtc_state);
  10369. if (intel_state->modeset) {
  10370. drm_atomic_helper_update_legacy_modeset_state(state->dev, state);
  10371. intel_set_cdclk(dev_priv, &dev_priv->cdclk.actual);
  10372. /*
  10373. * SKL workaround: bspec recommends we disable the SAGV when we
  10374. * have more then one pipe enabled
  10375. */
  10376. if (!intel_can_enable_sagv(state))
  10377. intel_disable_sagv(dev_priv);
  10378. intel_modeset_verify_disabled(dev, state);
  10379. }
  10380. /* Complete the events for pipes that have now been disabled */
  10381. for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
  10382. bool modeset = needs_modeset(new_crtc_state);
  10383. /* Complete events for now disable pipes here. */
  10384. if (modeset && !new_crtc_state->active && new_crtc_state->event) {
  10385. spin_lock_irq(&dev->event_lock);
  10386. drm_crtc_send_vblank_event(crtc, new_crtc_state->event);
  10387. spin_unlock_irq(&dev->event_lock);
  10388. new_crtc_state->event = NULL;
  10389. }
  10390. }
  10391. /* Now enable the clocks, plane, pipe, and connectors that we set up. */
  10392. dev_priv->display.update_crtcs(state);
  10393. /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
  10394. * already, but still need the state for the delayed optimization. To
  10395. * fix this:
  10396. * - wrap the optimization/post_plane_update stuff into a per-crtc work.
  10397. * - schedule that vblank worker _before_ calling hw_done
  10398. * - at the start of commit_tail, cancel it _synchrously
  10399. * - switch over to the vblank wait helper in the core after that since
  10400. * we don't need out special handling any more.
  10401. */
  10402. drm_atomic_helper_wait_for_flip_done(dev, state);
  10403. /*
  10404. * Now that the vblank has passed, we can go ahead and program the
  10405. * optimal watermarks on platforms that need two-step watermark
  10406. * programming.
  10407. *
  10408. * TODO: Move this (and other cleanup) to an async worker eventually.
  10409. */
  10410. for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
  10411. intel_cstate = to_intel_crtc_state(new_crtc_state);
  10412. if (dev_priv->display.optimize_watermarks)
  10413. dev_priv->display.optimize_watermarks(intel_state,
  10414. intel_cstate);
  10415. }
  10416. for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
  10417. intel_post_plane_update(to_intel_crtc_state(old_crtc_state));
  10418. if (put_domains[i])
  10419. modeset_put_power_domains(dev_priv, put_domains[i]);
  10420. intel_modeset_verify_crtc(crtc, state, old_crtc_state, new_crtc_state);
  10421. }
  10422. if (intel_state->modeset)
  10423. intel_verify_planes(intel_state);
  10424. if (intel_state->modeset && intel_can_enable_sagv(state))
  10425. intel_enable_sagv(dev_priv);
  10426. drm_atomic_helper_commit_hw_done(state);
  10427. if (intel_state->modeset) {
  10428. /* As one of the primary mmio accessors, KMS has a high
  10429. * likelihood of triggering bugs in unclaimed access. After we
  10430. * finish modesetting, see if an error has been flagged, and if
  10431. * so enable debugging for the next modeset - and hope we catch
  10432. * the culprit.
  10433. */
  10434. intel_uncore_arm_unclaimed_mmio_detection(dev_priv);
  10435. intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET);
  10436. }
  10437. drm_atomic_helper_cleanup_planes(dev, state);
  10438. drm_atomic_helper_commit_cleanup_done(state);
  10439. drm_atomic_state_put(state);
  10440. intel_atomic_helper_free_state(dev_priv);
  10441. }
  10442. static void intel_atomic_commit_work(struct work_struct *work)
  10443. {
  10444. struct drm_atomic_state *state =
  10445. container_of(work, struct drm_atomic_state, commit_work);
  10446. intel_atomic_commit_tail(state);
  10447. }
  10448. static int __i915_sw_fence_call
  10449. intel_atomic_commit_ready(struct i915_sw_fence *fence,
  10450. enum i915_sw_fence_notify notify)
  10451. {
  10452. struct intel_atomic_state *state =
  10453. container_of(fence, struct intel_atomic_state, commit_ready);
  10454. switch (notify) {
  10455. case FENCE_COMPLETE:
  10456. /* we do blocking waits in the worker, nothing to do here */
  10457. break;
  10458. case FENCE_FREE:
  10459. {
  10460. struct intel_atomic_helper *helper =
  10461. &to_i915(state->base.dev)->atomic_helper;
  10462. if (llist_add(&state->freed, &helper->free_list))
  10463. schedule_work(&helper->free_work);
  10464. break;
  10465. }
  10466. }
  10467. return NOTIFY_DONE;
  10468. }
  10469. static void intel_atomic_track_fbs(struct drm_atomic_state *state)
  10470. {
  10471. struct drm_plane_state *old_plane_state, *new_plane_state;
  10472. struct drm_plane *plane;
  10473. int i;
  10474. for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i)
  10475. i915_gem_track_fb(intel_fb_obj(old_plane_state->fb),
  10476. intel_fb_obj(new_plane_state->fb),
  10477. to_intel_plane(plane)->frontbuffer_bit);
  10478. }
  10479. /**
  10480. * intel_atomic_commit - commit validated state object
  10481. * @dev: DRM device
  10482. * @state: the top-level driver state object
  10483. * @nonblock: nonblocking commit
  10484. *
  10485. * This function commits a top-level state object that has been validated
  10486. * with drm_atomic_helper_check().
  10487. *
  10488. * RETURNS
  10489. * Zero for success or -errno.
  10490. */
  10491. static int intel_atomic_commit(struct drm_device *dev,
  10492. struct drm_atomic_state *state,
  10493. bool nonblock)
  10494. {
  10495. struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
  10496. struct drm_i915_private *dev_priv = to_i915(dev);
  10497. int ret = 0;
  10498. drm_atomic_state_get(state);
  10499. i915_sw_fence_init(&intel_state->commit_ready,
  10500. intel_atomic_commit_ready);
  10501. /*
  10502. * The intel_legacy_cursor_update() fast path takes care
  10503. * of avoiding the vblank waits for simple cursor
  10504. * movement and flips. For cursor on/off and size changes,
  10505. * we want to perform the vblank waits so that watermark
  10506. * updates happen during the correct frames. Gen9+ have
  10507. * double buffered watermarks and so shouldn't need this.
  10508. *
  10509. * Unset state->legacy_cursor_update before the call to
  10510. * drm_atomic_helper_setup_commit() because otherwise
  10511. * drm_atomic_helper_wait_for_flip_done() is a noop and
  10512. * we get FIFO underruns because we didn't wait
  10513. * for vblank.
  10514. *
  10515. * FIXME doing watermarks and fb cleanup from a vblank worker
  10516. * (assuming we had any) would solve these problems.
  10517. */
  10518. if (INTEL_GEN(dev_priv) < 9 && state->legacy_cursor_update) {
  10519. struct intel_crtc_state *new_crtc_state;
  10520. struct intel_crtc *crtc;
  10521. int i;
  10522. for_each_new_intel_crtc_in_state(intel_state, crtc, new_crtc_state, i)
  10523. if (new_crtc_state->wm.need_postvbl_update ||
  10524. new_crtc_state->update_wm_post)
  10525. state->legacy_cursor_update = false;
  10526. }
  10527. ret = intel_atomic_prepare_commit(dev, state);
  10528. if (ret) {
  10529. DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret);
  10530. i915_sw_fence_commit(&intel_state->commit_ready);
  10531. return ret;
  10532. }
  10533. ret = drm_atomic_helper_setup_commit(state, nonblock);
  10534. if (!ret)
  10535. ret = drm_atomic_helper_swap_state(state, true);
  10536. if (ret) {
  10537. i915_sw_fence_commit(&intel_state->commit_ready);
  10538. drm_atomic_helper_cleanup_planes(dev, state);
  10539. return ret;
  10540. }
  10541. dev_priv->wm.distrust_bios_wm = false;
  10542. intel_shared_dpll_swap_state(state);
  10543. intel_atomic_track_fbs(state);
  10544. if (intel_state->modeset) {
  10545. memcpy(dev_priv->min_cdclk, intel_state->min_cdclk,
  10546. sizeof(intel_state->min_cdclk));
  10547. memcpy(dev_priv->min_voltage_level,
  10548. intel_state->min_voltage_level,
  10549. sizeof(intel_state->min_voltage_level));
  10550. dev_priv->active_crtcs = intel_state->active_crtcs;
  10551. dev_priv->cdclk.logical = intel_state->cdclk.logical;
  10552. dev_priv->cdclk.actual = intel_state->cdclk.actual;
  10553. }
  10554. drm_atomic_state_get(state);
  10555. INIT_WORK(&state->commit_work, intel_atomic_commit_work);
  10556. i915_sw_fence_commit(&intel_state->commit_ready);
  10557. if (nonblock && intel_state->modeset) {
  10558. queue_work(dev_priv->modeset_wq, &state->commit_work);
  10559. } else if (nonblock) {
  10560. queue_work(system_unbound_wq, &state->commit_work);
  10561. } else {
  10562. if (intel_state->modeset)
  10563. flush_workqueue(dev_priv->modeset_wq);
  10564. intel_atomic_commit_tail(state);
  10565. }
  10566. return 0;
  10567. }
  10568. static const struct drm_crtc_funcs intel_crtc_funcs = {
  10569. .gamma_set = drm_atomic_helper_legacy_gamma_set,
  10570. .set_config = drm_atomic_helper_set_config,
  10571. .destroy = intel_crtc_destroy,
  10572. .page_flip = drm_atomic_helper_page_flip,
  10573. .atomic_duplicate_state = intel_crtc_duplicate_state,
  10574. .atomic_destroy_state = intel_crtc_destroy_state,
  10575. .set_crc_source = intel_crtc_set_crc_source,
  10576. };
  10577. struct wait_rps_boost {
  10578. struct wait_queue_entry wait;
  10579. struct drm_crtc *crtc;
  10580. struct i915_request *request;
  10581. };
  10582. static int do_rps_boost(struct wait_queue_entry *_wait,
  10583. unsigned mode, int sync, void *key)
  10584. {
  10585. struct wait_rps_boost *wait = container_of(_wait, typeof(*wait), wait);
  10586. struct i915_request *rq = wait->request;
  10587. /*
  10588. * If we missed the vblank, but the request is already running it
  10589. * is reasonable to assume that it will complete before the next
  10590. * vblank without our intervention, so leave RPS alone.
  10591. */
  10592. if (!i915_request_started(rq))
  10593. gen6_rps_boost(rq, NULL);
  10594. i915_request_put(rq);
  10595. drm_crtc_vblank_put(wait->crtc);
  10596. list_del(&wait->wait.entry);
  10597. kfree(wait);
  10598. return 1;
  10599. }
  10600. static void add_rps_boost_after_vblank(struct drm_crtc *crtc,
  10601. struct dma_fence *fence)
  10602. {
  10603. struct wait_rps_boost *wait;
  10604. if (!dma_fence_is_i915(fence))
  10605. return;
  10606. if (INTEL_GEN(to_i915(crtc->dev)) < 6)
  10607. return;
  10608. if (drm_crtc_vblank_get(crtc))
  10609. return;
  10610. wait = kmalloc(sizeof(*wait), GFP_KERNEL);
  10611. if (!wait) {
  10612. drm_crtc_vblank_put(crtc);
  10613. return;
  10614. }
  10615. wait->request = to_request(dma_fence_get(fence));
  10616. wait->crtc = crtc;
  10617. wait->wait.func = do_rps_boost;
  10618. wait->wait.flags = 0;
  10619. add_wait_queue(drm_crtc_vblank_waitqueue(crtc), &wait->wait);
  10620. }
  10621. static int intel_plane_pin_fb(struct intel_plane_state *plane_state)
  10622. {
  10623. struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
  10624. struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
  10625. struct drm_framebuffer *fb = plane_state->base.fb;
  10626. struct i915_vma *vma;
  10627. if (plane->id == PLANE_CURSOR &&
  10628. INTEL_INFO(dev_priv)->cursor_needs_physical) {
  10629. struct drm_i915_gem_object *obj = intel_fb_obj(fb);
  10630. const int align = intel_cursor_alignment(dev_priv);
  10631. return i915_gem_object_attach_phys(obj, align);
  10632. }
  10633. vma = intel_pin_and_fence_fb_obj(fb,
  10634. plane_state->base.rotation,
  10635. intel_plane_uses_fence(plane_state),
  10636. &plane_state->flags);
  10637. if (IS_ERR(vma))
  10638. return PTR_ERR(vma);
  10639. plane_state->vma = vma;
  10640. return 0;
  10641. }
  10642. static void intel_plane_unpin_fb(struct intel_plane_state *old_plane_state)
  10643. {
  10644. struct i915_vma *vma;
  10645. vma = fetch_and_zero(&old_plane_state->vma);
  10646. if (vma)
  10647. intel_unpin_fb_vma(vma, old_plane_state->flags);
  10648. }
  10649. static void fb_obj_bump_render_priority(struct drm_i915_gem_object *obj)
  10650. {
  10651. struct i915_sched_attr attr = {
  10652. .priority = I915_PRIORITY_DISPLAY,
  10653. };
  10654. i915_gem_object_wait_priority(obj, 0, &attr);
  10655. }
  10656. /**
  10657. * intel_prepare_plane_fb - Prepare fb for usage on plane
  10658. * @plane: drm plane to prepare for
  10659. * @new_state: the plane state being prepared
  10660. *
  10661. * Prepares a framebuffer for usage on a display plane. Generally this
  10662. * involves pinning the underlying object and updating the frontbuffer tracking
  10663. * bits. Some older platforms need special physical address handling for
  10664. * cursor planes.
  10665. *
  10666. * Must be called with struct_mutex held.
  10667. *
  10668. * Returns 0 on success, negative error code on failure.
  10669. */
  10670. int
  10671. intel_prepare_plane_fb(struct drm_plane *plane,
  10672. struct drm_plane_state *new_state)
  10673. {
  10674. struct intel_atomic_state *intel_state =
  10675. to_intel_atomic_state(new_state->state);
  10676. struct drm_i915_private *dev_priv = to_i915(plane->dev);
  10677. struct drm_framebuffer *fb = new_state->fb;
  10678. struct drm_i915_gem_object *obj = intel_fb_obj(fb);
  10679. struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->state->fb);
  10680. int ret;
  10681. if (old_obj) {
  10682. struct drm_crtc_state *crtc_state =
  10683. drm_atomic_get_new_crtc_state(new_state->state,
  10684. plane->state->crtc);
  10685. /* Big Hammer, we also need to ensure that any pending
  10686. * MI_WAIT_FOR_EVENT inside a user batch buffer on the
  10687. * current scanout is retired before unpinning the old
  10688. * framebuffer. Note that we rely on userspace rendering
  10689. * into the buffer attached to the pipe they are waiting
  10690. * on. If not, userspace generates a GPU hang with IPEHR
  10691. * point to the MI_WAIT_FOR_EVENT.
  10692. *
  10693. * This should only fail upon a hung GPU, in which case we
  10694. * can safely continue.
  10695. */
  10696. if (needs_modeset(crtc_state)) {
  10697. ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
  10698. old_obj->resv, NULL,
  10699. false, 0,
  10700. GFP_KERNEL);
  10701. if (ret < 0)
  10702. return ret;
  10703. }
  10704. }
  10705. if (new_state->fence) { /* explicit fencing */
  10706. ret = i915_sw_fence_await_dma_fence(&intel_state->commit_ready,
  10707. new_state->fence,
  10708. I915_FENCE_TIMEOUT,
  10709. GFP_KERNEL);
  10710. if (ret < 0)
  10711. return ret;
  10712. }
  10713. if (!obj)
  10714. return 0;
  10715. ret = i915_gem_object_pin_pages(obj);
  10716. if (ret)
  10717. return ret;
  10718. ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
  10719. if (ret) {
  10720. i915_gem_object_unpin_pages(obj);
  10721. return ret;
  10722. }
  10723. ret = intel_plane_pin_fb(to_intel_plane_state(new_state));
  10724. fb_obj_bump_render_priority(obj);
  10725. mutex_unlock(&dev_priv->drm.struct_mutex);
  10726. i915_gem_object_unpin_pages(obj);
  10727. if (ret)
  10728. return ret;
  10729. intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
  10730. if (!new_state->fence) { /* implicit fencing */
  10731. struct dma_fence *fence;
  10732. ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
  10733. obj->resv, NULL,
  10734. false, I915_FENCE_TIMEOUT,
  10735. GFP_KERNEL);
  10736. if (ret < 0)
  10737. return ret;
  10738. fence = reservation_object_get_excl_rcu(obj->resv);
  10739. if (fence) {
  10740. add_rps_boost_after_vblank(new_state->crtc, fence);
  10741. dma_fence_put(fence);
  10742. }
  10743. } else {
  10744. add_rps_boost_after_vblank(new_state->crtc, new_state->fence);
  10745. }
  10746. return 0;
  10747. }
  10748. /**
  10749. * intel_cleanup_plane_fb - Cleans up an fb after plane use
  10750. * @plane: drm plane to clean up for
  10751. * @old_state: the state from the previous modeset
  10752. *
  10753. * Cleans up a framebuffer that has just been removed from a plane.
  10754. *
  10755. * Must be called with struct_mutex held.
  10756. */
  10757. void
  10758. intel_cleanup_plane_fb(struct drm_plane *plane,
  10759. struct drm_plane_state *old_state)
  10760. {
  10761. struct drm_i915_private *dev_priv = to_i915(plane->dev);
  10762. /* Should only be called after a successful intel_prepare_plane_fb()! */
  10763. mutex_lock(&dev_priv->drm.struct_mutex);
  10764. intel_plane_unpin_fb(to_intel_plane_state(old_state));
  10765. mutex_unlock(&dev_priv->drm.struct_mutex);
  10766. }
  10767. int
  10768. skl_max_scale(struct intel_crtc *intel_crtc,
  10769. struct intel_crtc_state *crtc_state,
  10770. uint32_t pixel_format)
  10771. {
  10772. struct drm_i915_private *dev_priv;
  10773. int max_scale, mult;
  10774. int crtc_clock, max_dotclk, tmpclk1, tmpclk2;
  10775. if (!intel_crtc || !crtc_state->base.enable)
  10776. return DRM_PLANE_HELPER_NO_SCALING;
  10777. dev_priv = to_i915(intel_crtc->base.dev);
  10778. crtc_clock = crtc_state->base.adjusted_mode.crtc_clock;
  10779. max_dotclk = to_intel_atomic_state(crtc_state->base.state)->cdclk.logical.cdclk;
  10780. if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 10)
  10781. max_dotclk *= 2;
  10782. if (WARN_ON_ONCE(!crtc_clock || max_dotclk < crtc_clock))
  10783. return DRM_PLANE_HELPER_NO_SCALING;
  10784. /*
  10785. * skl max scale is lower of:
  10786. * close to 3 but not 3, -1 is for that purpose
  10787. * or
  10788. * cdclk/crtc_clock
  10789. */
  10790. mult = pixel_format == DRM_FORMAT_NV12 ? 2 : 3;
  10791. tmpclk1 = (1 << 16) * mult - 1;
  10792. tmpclk2 = (1 << 8) * ((max_dotclk << 8) / crtc_clock);
  10793. max_scale = min(tmpclk1, tmpclk2);
  10794. return max_scale;
  10795. }
  10796. static int
  10797. intel_check_primary_plane(struct intel_plane *plane,
  10798. struct intel_crtc_state *crtc_state,
  10799. struct intel_plane_state *state)
  10800. {
  10801. struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
  10802. struct drm_crtc *crtc = state->base.crtc;
  10803. int min_scale = DRM_PLANE_HELPER_NO_SCALING;
  10804. int max_scale = DRM_PLANE_HELPER_NO_SCALING;
  10805. bool can_position = false;
  10806. int ret;
  10807. uint32_t pixel_format = 0;
  10808. if (INTEL_GEN(dev_priv) >= 9) {
  10809. /* use scaler when colorkey is not required */
  10810. if (!state->ckey.flags) {
  10811. min_scale = 1;
  10812. if (state->base.fb)
  10813. pixel_format = state->base.fb->format->format;
  10814. max_scale = skl_max_scale(to_intel_crtc(crtc),
  10815. crtc_state, pixel_format);
  10816. }
  10817. can_position = true;
  10818. }
  10819. ret = drm_atomic_helper_check_plane_state(&state->base,
  10820. &crtc_state->base,
  10821. min_scale, max_scale,
  10822. can_position, true);
  10823. if (ret)
  10824. return ret;
  10825. if (!state->base.fb)
  10826. return 0;
  10827. if (INTEL_GEN(dev_priv) >= 9) {
  10828. ret = skl_check_plane_surface(crtc_state, state);
  10829. if (ret)
  10830. return ret;
  10831. state->ctl = skl_plane_ctl(crtc_state, state);
  10832. } else {
  10833. ret = i9xx_check_plane_surface(state);
  10834. if (ret)
  10835. return ret;
  10836. state->ctl = i9xx_plane_ctl(crtc_state, state);
  10837. }
  10838. if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
  10839. state->color_ctl = glk_plane_color_ctl(crtc_state, state);
  10840. return 0;
  10841. }
  10842. static void intel_begin_crtc_commit(struct drm_crtc *crtc,
  10843. struct drm_crtc_state *old_crtc_state)
  10844. {
  10845. struct drm_device *dev = crtc->dev;
  10846. struct drm_i915_private *dev_priv = to_i915(dev);
  10847. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  10848. struct intel_crtc_state *old_intel_cstate =
  10849. to_intel_crtc_state(old_crtc_state);
  10850. struct intel_atomic_state *old_intel_state =
  10851. to_intel_atomic_state(old_crtc_state->state);
  10852. struct intel_crtc_state *intel_cstate =
  10853. intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc);
  10854. bool modeset = needs_modeset(&intel_cstate->base);
  10855. if (!modeset &&
  10856. (intel_cstate->base.color_mgmt_changed ||
  10857. intel_cstate->update_pipe)) {
  10858. intel_color_set_csc(&intel_cstate->base);
  10859. intel_color_load_luts(&intel_cstate->base);
  10860. }
  10861. /* Perform vblank evasion around commit operation */
  10862. intel_pipe_update_start(intel_cstate);
  10863. if (modeset)
  10864. goto out;
  10865. if (intel_cstate->update_pipe)
  10866. intel_update_pipe_config(old_intel_cstate, intel_cstate);
  10867. else if (INTEL_GEN(dev_priv) >= 9)
  10868. skl_detach_scalers(intel_crtc);
  10869. out:
  10870. if (dev_priv->display.atomic_update_watermarks)
  10871. dev_priv->display.atomic_update_watermarks(old_intel_state,
  10872. intel_cstate);
  10873. }
  10874. void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc,
  10875. struct intel_crtc_state *crtc_state)
  10876. {
  10877. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  10878. if (!IS_GEN2(dev_priv))
  10879. intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
  10880. if (crtc_state->has_pch_encoder) {
  10881. enum pipe pch_transcoder =
  10882. intel_crtc_pch_transcoder(crtc);
  10883. intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true);
  10884. }
  10885. }
  10886. static void intel_finish_crtc_commit(struct drm_crtc *crtc,
  10887. struct drm_crtc_state *old_crtc_state)
  10888. {
  10889. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  10890. struct intel_atomic_state *old_intel_state =
  10891. to_intel_atomic_state(old_crtc_state->state);
  10892. struct intel_crtc_state *new_crtc_state =
  10893. intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc);
  10894. intel_pipe_update_end(new_crtc_state);
  10895. if (new_crtc_state->update_pipe &&
  10896. !needs_modeset(&new_crtc_state->base) &&
  10897. old_crtc_state->mode.private_flags & I915_MODE_FLAG_INHERITED)
  10898. intel_crtc_arm_fifo_underrun(intel_crtc, new_crtc_state);
  10899. }
  10900. /**
  10901. * intel_plane_destroy - destroy a plane
  10902. * @plane: plane to destroy
  10903. *
  10904. * Common destruction function for all types of planes (primary, cursor,
  10905. * sprite).
  10906. */
  10907. void intel_plane_destroy(struct drm_plane *plane)
  10908. {
  10909. drm_plane_cleanup(plane);
  10910. kfree(to_intel_plane(plane));
  10911. }
  10912. static bool i8xx_mod_supported(uint32_t format, uint64_t modifier)
  10913. {
  10914. switch (format) {
  10915. case DRM_FORMAT_C8:
  10916. case DRM_FORMAT_RGB565:
  10917. case DRM_FORMAT_XRGB1555:
  10918. case DRM_FORMAT_XRGB8888:
  10919. return modifier == DRM_FORMAT_MOD_LINEAR ||
  10920. modifier == I915_FORMAT_MOD_X_TILED;
  10921. default:
  10922. return false;
  10923. }
  10924. }
  10925. static bool i965_mod_supported(uint32_t format, uint64_t modifier)
  10926. {
  10927. switch (format) {
  10928. case DRM_FORMAT_C8:
  10929. case DRM_FORMAT_RGB565:
  10930. case DRM_FORMAT_XRGB8888:
  10931. case DRM_FORMAT_XBGR8888:
  10932. case DRM_FORMAT_XRGB2101010:
  10933. case DRM_FORMAT_XBGR2101010:
  10934. return modifier == DRM_FORMAT_MOD_LINEAR ||
  10935. modifier == I915_FORMAT_MOD_X_TILED;
  10936. default:
  10937. return false;
  10938. }
  10939. }
  10940. static bool skl_mod_supported(uint32_t format, uint64_t modifier)
  10941. {
  10942. switch (format) {
  10943. case DRM_FORMAT_XRGB8888:
  10944. case DRM_FORMAT_XBGR8888:
  10945. case DRM_FORMAT_ARGB8888:
  10946. case DRM_FORMAT_ABGR8888:
  10947. if (modifier == I915_FORMAT_MOD_Yf_TILED_CCS ||
  10948. modifier == I915_FORMAT_MOD_Y_TILED_CCS)
  10949. return true;
  10950. /* fall through */
  10951. case DRM_FORMAT_RGB565:
  10952. case DRM_FORMAT_XRGB2101010:
  10953. case DRM_FORMAT_XBGR2101010:
  10954. case DRM_FORMAT_YUYV:
  10955. case DRM_FORMAT_YVYU:
  10956. case DRM_FORMAT_UYVY:
  10957. case DRM_FORMAT_VYUY:
  10958. if (modifier == I915_FORMAT_MOD_Yf_TILED)
  10959. return true;
  10960. /* fall through */
  10961. case DRM_FORMAT_C8:
  10962. if (modifier == DRM_FORMAT_MOD_LINEAR ||
  10963. modifier == I915_FORMAT_MOD_X_TILED ||
  10964. modifier == I915_FORMAT_MOD_Y_TILED)
  10965. return true;
  10966. /* fall through */
  10967. default:
  10968. return false;
  10969. }
  10970. }
  10971. static bool intel_primary_plane_format_mod_supported(struct drm_plane *plane,
  10972. uint32_t format,
  10973. uint64_t modifier)
  10974. {
  10975. struct drm_i915_private *dev_priv = to_i915(plane->dev);
  10976. if (WARN_ON(modifier == DRM_FORMAT_MOD_INVALID))
  10977. return false;
  10978. if ((modifier >> 56) != DRM_FORMAT_MOD_VENDOR_INTEL &&
  10979. modifier != DRM_FORMAT_MOD_LINEAR)
  10980. return false;
  10981. if (INTEL_GEN(dev_priv) >= 9)
  10982. return skl_mod_supported(format, modifier);
  10983. else if (INTEL_GEN(dev_priv) >= 4)
  10984. return i965_mod_supported(format, modifier);
  10985. else
  10986. return i8xx_mod_supported(format, modifier);
  10987. }
  10988. static bool intel_cursor_plane_format_mod_supported(struct drm_plane *plane,
  10989. uint32_t format,
  10990. uint64_t modifier)
  10991. {
  10992. if (WARN_ON(modifier == DRM_FORMAT_MOD_INVALID))
  10993. return false;
  10994. return modifier == DRM_FORMAT_MOD_LINEAR && format == DRM_FORMAT_ARGB8888;
  10995. }
  10996. static struct drm_plane_funcs intel_plane_funcs = {
  10997. .update_plane = drm_atomic_helper_update_plane,
  10998. .disable_plane = drm_atomic_helper_disable_plane,
  10999. .destroy = intel_plane_destroy,
  11000. .atomic_get_property = intel_plane_atomic_get_property,
  11001. .atomic_set_property = intel_plane_atomic_set_property,
  11002. .atomic_duplicate_state = intel_plane_duplicate_state,
  11003. .atomic_destroy_state = intel_plane_destroy_state,
  11004. .format_mod_supported = intel_primary_plane_format_mod_supported,
  11005. };
  11006. static int
  11007. intel_legacy_cursor_update(struct drm_plane *plane,
  11008. struct drm_crtc *crtc,
  11009. struct drm_framebuffer *fb,
  11010. int crtc_x, int crtc_y,
  11011. unsigned int crtc_w, unsigned int crtc_h,
  11012. uint32_t src_x, uint32_t src_y,
  11013. uint32_t src_w, uint32_t src_h,
  11014. struct drm_modeset_acquire_ctx *ctx)
  11015. {
  11016. struct drm_i915_private *dev_priv = to_i915(crtc->dev);
  11017. int ret;
  11018. struct drm_plane_state *old_plane_state, *new_plane_state;
  11019. struct intel_plane *intel_plane = to_intel_plane(plane);
  11020. struct drm_framebuffer *old_fb;
  11021. struct drm_crtc_state *crtc_state = crtc->state;
  11022. /*
  11023. * When crtc is inactive or there is a modeset pending,
  11024. * wait for it to complete in the slowpath
  11025. */
  11026. if (!crtc_state->active || needs_modeset(crtc_state) ||
  11027. to_intel_crtc_state(crtc_state)->update_pipe)
  11028. goto slow;
  11029. old_plane_state = plane->state;
  11030. /*
  11031. * Don't do an async update if there is an outstanding commit modifying
  11032. * the plane. This prevents our async update's changes from getting
  11033. * overridden by a previous synchronous update's state.
  11034. */
  11035. if (old_plane_state->commit &&
  11036. !try_wait_for_completion(&old_plane_state->commit->hw_done))
  11037. goto slow;
  11038. /*
  11039. * If any parameters change that may affect watermarks,
  11040. * take the slowpath. Only changing fb or position should be
  11041. * in the fastpath.
  11042. */
  11043. if (old_plane_state->crtc != crtc ||
  11044. old_plane_state->src_w != src_w ||
  11045. old_plane_state->src_h != src_h ||
  11046. old_plane_state->crtc_w != crtc_w ||
  11047. old_plane_state->crtc_h != crtc_h ||
  11048. !old_plane_state->fb != !fb)
  11049. goto slow;
  11050. new_plane_state = intel_plane_duplicate_state(plane);
  11051. if (!new_plane_state)
  11052. return -ENOMEM;
  11053. drm_atomic_set_fb_for_plane(new_plane_state, fb);
  11054. new_plane_state->src_x = src_x;
  11055. new_plane_state->src_y = src_y;
  11056. new_plane_state->src_w = src_w;
  11057. new_plane_state->src_h = src_h;
  11058. new_plane_state->crtc_x = crtc_x;
  11059. new_plane_state->crtc_y = crtc_y;
  11060. new_plane_state->crtc_w = crtc_w;
  11061. new_plane_state->crtc_h = crtc_h;
  11062. ret = intel_plane_atomic_check_with_state(to_intel_crtc_state(crtc->state),
  11063. to_intel_crtc_state(crtc->state), /* FIXME need a new crtc state? */
  11064. to_intel_plane_state(plane->state),
  11065. to_intel_plane_state(new_plane_state));
  11066. if (ret)
  11067. goto out_free;
  11068. ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
  11069. if (ret)
  11070. goto out_free;
  11071. ret = intel_plane_pin_fb(to_intel_plane_state(new_plane_state));
  11072. if (ret)
  11073. goto out_unlock;
  11074. intel_fb_obj_flush(intel_fb_obj(fb), ORIGIN_FLIP);
  11075. old_fb = old_plane_state->fb;
  11076. i915_gem_track_fb(intel_fb_obj(old_fb), intel_fb_obj(fb),
  11077. intel_plane->frontbuffer_bit);
  11078. /* Swap plane state */
  11079. plane->state = new_plane_state;
  11080. if (plane->state->visible) {
  11081. trace_intel_update_plane(plane, to_intel_crtc(crtc));
  11082. intel_plane->update_plane(intel_plane,
  11083. to_intel_crtc_state(crtc->state),
  11084. to_intel_plane_state(plane->state));
  11085. } else {
  11086. trace_intel_disable_plane(plane, to_intel_crtc(crtc));
  11087. intel_plane->disable_plane(intel_plane, to_intel_crtc(crtc));
  11088. }
  11089. intel_plane_unpin_fb(to_intel_plane_state(old_plane_state));
  11090. out_unlock:
  11091. mutex_unlock(&dev_priv->drm.struct_mutex);
  11092. out_free:
  11093. if (ret)
  11094. intel_plane_destroy_state(plane, new_plane_state);
  11095. else
  11096. intel_plane_destroy_state(plane, old_plane_state);
  11097. return ret;
  11098. slow:
  11099. return drm_atomic_helper_update_plane(plane, crtc, fb,
  11100. crtc_x, crtc_y, crtc_w, crtc_h,
  11101. src_x, src_y, src_w, src_h, ctx);
  11102. }
  11103. static const struct drm_plane_funcs intel_cursor_plane_funcs = {
  11104. .update_plane = intel_legacy_cursor_update,
  11105. .disable_plane = drm_atomic_helper_disable_plane,
  11106. .destroy = intel_plane_destroy,
  11107. .atomic_get_property = intel_plane_atomic_get_property,
  11108. .atomic_set_property = intel_plane_atomic_set_property,
  11109. .atomic_duplicate_state = intel_plane_duplicate_state,
  11110. .atomic_destroy_state = intel_plane_destroy_state,
  11111. .format_mod_supported = intel_cursor_plane_format_mod_supported,
  11112. };
  11113. static bool i9xx_plane_has_fbc(struct drm_i915_private *dev_priv,
  11114. enum i9xx_plane_id i9xx_plane)
  11115. {
  11116. if (!HAS_FBC(dev_priv))
  11117. return false;
  11118. if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
  11119. return i9xx_plane == PLANE_A; /* tied to pipe A */
  11120. else if (IS_IVYBRIDGE(dev_priv))
  11121. return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B ||
  11122. i9xx_plane == PLANE_C;
  11123. else if (INTEL_GEN(dev_priv) >= 4)
  11124. return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B;
  11125. else
  11126. return i9xx_plane == PLANE_A;
  11127. }
  11128. static bool skl_plane_has_fbc(struct drm_i915_private *dev_priv,
  11129. enum pipe pipe, enum plane_id plane_id)
  11130. {
  11131. if (!HAS_FBC(dev_priv))
  11132. return false;
  11133. return pipe == PIPE_A && plane_id == PLANE_PRIMARY;
  11134. }
  11135. static struct intel_plane *
  11136. intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe)
  11137. {
  11138. struct intel_plane *primary = NULL;
  11139. struct intel_plane_state *state = NULL;
  11140. const uint32_t *intel_primary_formats;
  11141. unsigned int supported_rotations;
  11142. unsigned int num_formats;
  11143. const uint64_t *modifiers;
  11144. int ret;
  11145. primary = kzalloc(sizeof(*primary), GFP_KERNEL);
  11146. if (!primary) {
  11147. ret = -ENOMEM;
  11148. goto fail;
  11149. }
  11150. state = intel_create_plane_state(&primary->base);
  11151. if (!state) {
  11152. ret = -ENOMEM;
  11153. goto fail;
  11154. }
  11155. primary->base.state = &state->base;
  11156. primary->can_scale = false;
  11157. primary->max_downscale = 1;
  11158. if (INTEL_GEN(dev_priv) >= 9) {
  11159. primary->can_scale = true;
  11160. state->scaler_id = -1;
  11161. }
  11162. primary->pipe = pipe;
  11163. /*
  11164. * On gen2/3 only plane A can do FBC, but the panel fitter and LVDS
  11165. * port is hooked to pipe B. Hence we want plane A feeding pipe B.
  11166. */
  11167. if (HAS_FBC(dev_priv) && INTEL_GEN(dev_priv) < 4)
  11168. primary->i9xx_plane = (enum i9xx_plane_id) !pipe;
  11169. else
  11170. primary->i9xx_plane = (enum i9xx_plane_id) pipe;
  11171. primary->id = PLANE_PRIMARY;
  11172. primary->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, primary->id);
  11173. if (INTEL_GEN(dev_priv) >= 9)
  11174. primary->has_fbc = skl_plane_has_fbc(dev_priv,
  11175. primary->pipe,
  11176. primary->id);
  11177. else
  11178. primary->has_fbc = i9xx_plane_has_fbc(dev_priv,
  11179. primary->i9xx_plane);
  11180. if (primary->has_fbc) {
  11181. struct intel_fbc *fbc = &dev_priv->fbc;
  11182. fbc->possible_framebuffer_bits |= primary->frontbuffer_bit;
  11183. }
  11184. primary->check_plane = intel_check_primary_plane;
  11185. if (INTEL_GEN(dev_priv) >= 9) {
  11186. intel_primary_formats = skl_primary_formats;
  11187. num_formats = ARRAY_SIZE(skl_primary_formats);
  11188. if (skl_plane_has_ccs(dev_priv, pipe, PLANE_PRIMARY))
  11189. modifiers = skl_format_modifiers_ccs;
  11190. else
  11191. modifiers = skl_format_modifiers_noccs;
  11192. primary->update_plane = skl_update_plane;
  11193. primary->disable_plane = skl_disable_plane;
  11194. primary->get_hw_state = skl_plane_get_hw_state;
  11195. } else if (INTEL_GEN(dev_priv) >= 4) {
  11196. intel_primary_formats = i965_primary_formats;
  11197. num_formats = ARRAY_SIZE(i965_primary_formats);
  11198. modifiers = i9xx_format_modifiers;
  11199. primary->update_plane = i9xx_update_plane;
  11200. primary->disable_plane = i9xx_disable_plane;
  11201. primary->get_hw_state = i9xx_plane_get_hw_state;
  11202. } else {
  11203. intel_primary_formats = i8xx_primary_formats;
  11204. num_formats = ARRAY_SIZE(i8xx_primary_formats);
  11205. modifiers = i9xx_format_modifiers;
  11206. primary->update_plane = i9xx_update_plane;
  11207. primary->disable_plane = i9xx_disable_plane;
  11208. primary->get_hw_state = i9xx_plane_get_hw_state;
  11209. }
  11210. if (INTEL_GEN(dev_priv) >= 9)
  11211. ret = drm_universal_plane_init(&dev_priv->drm, &primary->base,
  11212. 0, &intel_plane_funcs,
  11213. intel_primary_formats, num_formats,
  11214. modifiers,
  11215. DRM_PLANE_TYPE_PRIMARY,
  11216. "plane 1%c", pipe_name(pipe));
  11217. else if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
  11218. ret = drm_universal_plane_init(&dev_priv->drm, &primary->base,
  11219. 0, &intel_plane_funcs,
  11220. intel_primary_formats, num_formats,
  11221. modifiers,
  11222. DRM_PLANE_TYPE_PRIMARY,
  11223. "primary %c", pipe_name(pipe));
  11224. else
  11225. ret = drm_universal_plane_init(&dev_priv->drm, &primary->base,
  11226. 0, &intel_plane_funcs,
  11227. intel_primary_formats, num_formats,
  11228. modifiers,
  11229. DRM_PLANE_TYPE_PRIMARY,
  11230. "plane %c",
  11231. plane_name(primary->i9xx_plane));
  11232. if (ret)
  11233. goto fail;
  11234. if (INTEL_GEN(dev_priv) >= 10) {
  11235. supported_rotations =
  11236. DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_90 |
  11237. DRM_MODE_ROTATE_180 | DRM_MODE_ROTATE_270 |
  11238. DRM_MODE_REFLECT_X;
  11239. } else if (INTEL_GEN(dev_priv) >= 9) {
  11240. supported_rotations =
  11241. DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_90 |
  11242. DRM_MODE_ROTATE_180 | DRM_MODE_ROTATE_270;
  11243. } else if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
  11244. supported_rotations =
  11245. DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 |
  11246. DRM_MODE_REFLECT_X;
  11247. } else if (INTEL_GEN(dev_priv) >= 4) {
  11248. supported_rotations =
  11249. DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180;
  11250. } else {
  11251. supported_rotations = DRM_MODE_ROTATE_0;
  11252. }
  11253. if (INTEL_GEN(dev_priv) >= 4)
  11254. drm_plane_create_rotation_property(&primary->base,
  11255. DRM_MODE_ROTATE_0,
  11256. supported_rotations);
  11257. if (INTEL_GEN(dev_priv) >= 9)
  11258. drm_plane_create_color_properties(&primary->base,
  11259. BIT(DRM_COLOR_YCBCR_BT601) |
  11260. BIT(DRM_COLOR_YCBCR_BT709),
  11261. BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) |
  11262. BIT(DRM_COLOR_YCBCR_FULL_RANGE),
  11263. DRM_COLOR_YCBCR_BT709,
  11264. DRM_COLOR_YCBCR_LIMITED_RANGE);
  11265. drm_plane_helper_add(&primary->base, &intel_plane_helper_funcs);
  11266. return primary;
  11267. fail:
  11268. kfree(state);
  11269. kfree(primary);
  11270. return ERR_PTR(ret);
  11271. }
  11272. static struct intel_plane *
  11273. intel_cursor_plane_create(struct drm_i915_private *dev_priv,
  11274. enum pipe pipe)
  11275. {
  11276. struct intel_plane *cursor = NULL;
  11277. struct intel_plane_state *state = NULL;
  11278. int ret;
  11279. cursor = kzalloc(sizeof(*cursor), GFP_KERNEL);
  11280. if (!cursor) {
  11281. ret = -ENOMEM;
  11282. goto fail;
  11283. }
  11284. state = intel_create_plane_state(&cursor->base);
  11285. if (!state) {
  11286. ret = -ENOMEM;
  11287. goto fail;
  11288. }
  11289. cursor->base.state = &state->base;
  11290. cursor->can_scale = false;
  11291. cursor->max_downscale = 1;
  11292. cursor->pipe = pipe;
  11293. cursor->i9xx_plane = (enum i9xx_plane_id) pipe;
  11294. cursor->id = PLANE_CURSOR;
  11295. cursor->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, cursor->id);
  11296. if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
  11297. cursor->update_plane = i845_update_cursor;
  11298. cursor->disable_plane = i845_disable_cursor;
  11299. cursor->get_hw_state = i845_cursor_get_hw_state;
  11300. cursor->check_plane = i845_check_cursor;
  11301. } else {
  11302. cursor->update_plane = i9xx_update_cursor;
  11303. cursor->disable_plane = i9xx_disable_cursor;
  11304. cursor->get_hw_state = i9xx_cursor_get_hw_state;
  11305. cursor->check_plane = i9xx_check_cursor;
  11306. }
  11307. cursor->cursor.base = ~0;
  11308. cursor->cursor.cntl = ~0;
  11309. if (IS_I845G(dev_priv) || IS_I865G(dev_priv) || HAS_CUR_FBC(dev_priv))
  11310. cursor->cursor.size = ~0;
  11311. ret = drm_universal_plane_init(&dev_priv->drm, &cursor->base,
  11312. 0, &intel_cursor_plane_funcs,
  11313. intel_cursor_formats,
  11314. ARRAY_SIZE(intel_cursor_formats),
  11315. cursor_format_modifiers,
  11316. DRM_PLANE_TYPE_CURSOR,
  11317. "cursor %c", pipe_name(pipe));
  11318. if (ret)
  11319. goto fail;
  11320. if (INTEL_GEN(dev_priv) >= 4)
  11321. drm_plane_create_rotation_property(&cursor->base,
  11322. DRM_MODE_ROTATE_0,
  11323. DRM_MODE_ROTATE_0 |
  11324. DRM_MODE_ROTATE_180);
  11325. if (INTEL_GEN(dev_priv) >= 9)
  11326. state->scaler_id = -1;
  11327. drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs);
  11328. return cursor;
  11329. fail:
  11330. kfree(state);
  11331. kfree(cursor);
  11332. return ERR_PTR(ret);
  11333. }
  11334. static void intel_crtc_init_scalers(struct intel_crtc *crtc,
  11335. struct intel_crtc_state *crtc_state)
  11336. {
  11337. struct intel_crtc_scaler_state *scaler_state =
  11338. &crtc_state->scaler_state;
  11339. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  11340. int i;
  11341. crtc->num_scalers = dev_priv->info.num_scalers[crtc->pipe];
  11342. if (!crtc->num_scalers)
  11343. return;
  11344. for (i = 0; i < crtc->num_scalers; i++) {
  11345. struct intel_scaler *scaler = &scaler_state->scalers[i];
  11346. scaler->in_use = 0;
  11347. scaler->mode = PS_SCALER_MODE_DYN;
  11348. }
  11349. scaler_state->scaler_id = -1;
  11350. }
  11351. static int intel_crtc_init(struct drm_i915_private *dev_priv, enum pipe pipe)
  11352. {
  11353. struct intel_crtc *intel_crtc;
  11354. struct intel_crtc_state *crtc_state = NULL;
  11355. struct intel_plane *primary = NULL;
  11356. struct intel_plane *cursor = NULL;
  11357. int sprite, ret;
  11358. intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL);
  11359. if (!intel_crtc)
  11360. return -ENOMEM;
  11361. crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
  11362. if (!crtc_state) {
  11363. ret = -ENOMEM;
  11364. goto fail;
  11365. }
  11366. intel_crtc->config = crtc_state;
  11367. intel_crtc->base.state = &crtc_state->base;
  11368. crtc_state->base.crtc = &intel_crtc->base;
  11369. primary = intel_primary_plane_create(dev_priv, pipe);
  11370. if (IS_ERR(primary)) {
  11371. ret = PTR_ERR(primary);
  11372. goto fail;
  11373. }
  11374. intel_crtc->plane_ids_mask |= BIT(primary->id);
  11375. for_each_sprite(dev_priv, pipe, sprite) {
  11376. struct intel_plane *plane;
  11377. plane = intel_sprite_plane_create(dev_priv, pipe, sprite);
  11378. if (IS_ERR(plane)) {
  11379. ret = PTR_ERR(plane);
  11380. goto fail;
  11381. }
  11382. intel_crtc->plane_ids_mask |= BIT(plane->id);
  11383. }
  11384. cursor = intel_cursor_plane_create(dev_priv, pipe);
  11385. if (IS_ERR(cursor)) {
  11386. ret = PTR_ERR(cursor);
  11387. goto fail;
  11388. }
  11389. intel_crtc->plane_ids_mask |= BIT(cursor->id);
  11390. ret = drm_crtc_init_with_planes(&dev_priv->drm, &intel_crtc->base,
  11391. &primary->base, &cursor->base,
  11392. &intel_crtc_funcs,
  11393. "pipe %c", pipe_name(pipe));
  11394. if (ret)
  11395. goto fail;
  11396. intel_crtc->pipe = pipe;
  11397. /* initialize shared scalers */
  11398. intel_crtc_init_scalers(intel_crtc, crtc_state);
  11399. BUG_ON(pipe >= ARRAY_SIZE(dev_priv->pipe_to_crtc_mapping) ||
  11400. dev_priv->pipe_to_crtc_mapping[pipe] != NULL);
  11401. dev_priv->pipe_to_crtc_mapping[pipe] = intel_crtc;
  11402. if (INTEL_GEN(dev_priv) < 9) {
  11403. enum i9xx_plane_id i9xx_plane = primary->i9xx_plane;
  11404. BUG_ON(i9xx_plane >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
  11405. dev_priv->plane_to_crtc_mapping[i9xx_plane] != NULL);
  11406. dev_priv->plane_to_crtc_mapping[i9xx_plane] = intel_crtc;
  11407. }
  11408. drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
  11409. intel_color_init(&intel_crtc->base);
  11410. WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe);
  11411. return 0;
  11412. fail:
  11413. /*
  11414. * drm_mode_config_cleanup() will free up any
  11415. * crtcs/planes already initialized.
  11416. */
  11417. kfree(crtc_state);
  11418. kfree(intel_crtc);
  11419. return ret;
  11420. }
  11421. enum pipe intel_get_pipe_from_connector(struct intel_connector *connector)
  11422. {
  11423. struct drm_device *dev = connector->base.dev;
  11424. WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
  11425. if (!connector->base.state->crtc)
  11426. return INVALID_PIPE;
  11427. return to_intel_crtc(connector->base.state->crtc)->pipe;
  11428. }
  11429. int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data,
  11430. struct drm_file *file)
  11431. {
  11432. struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
  11433. struct drm_crtc *drmmode_crtc;
  11434. struct intel_crtc *crtc;
  11435. drmmode_crtc = drm_crtc_find(dev, file, pipe_from_crtc_id->crtc_id);
  11436. if (!drmmode_crtc)
  11437. return -ENOENT;
  11438. crtc = to_intel_crtc(drmmode_crtc);
  11439. pipe_from_crtc_id->pipe = crtc->pipe;
  11440. return 0;
  11441. }
  11442. static int intel_encoder_clones(struct intel_encoder *encoder)
  11443. {
  11444. struct drm_device *dev = encoder->base.dev;
  11445. struct intel_encoder *source_encoder;
  11446. int index_mask = 0;
  11447. int entry = 0;
  11448. for_each_intel_encoder(dev, source_encoder) {
  11449. if (encoders_cloneable(encoder, source_encoder))
  11450. index_mask |= (1 << entry);
  11451. entry++;
  11452. }
  11453. return index_mask;
  11454. }
  11455. static bool has_edp_a(struct drm_i915_private *dev_priv)
  11456. {
  11457. if (!IS_MOBILE(dev_priv))
  11458. return false;
  11459. if ((I915_READ(DP_A) & DP_DETECTED) == 0)
  11460. return false;
  11461. if (IS_GEN5(dev_priv) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE))
  11462. return false;
  11463. return true;
  11464. }
  11465. static bool intel_crt_present(struct drm_i915_private *dev_priv)
  11466. {
  11467. if (INTEL_GEN(dev_priv) >= 9)
  11468. return false;
  11469. if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv))
  11470. return false;
  11471. if (IS_CHERRYVIEW(dev_priv))
  11472. return false;
  11473. if (HAS_PCH_LPT_H(dev_priv) &&
  11474. I915_READ(SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED)
  11475. return false;
  11476. /* DDI E can't be used if DDI A requires 4 lanes */
  11477. if (HAS_DDI(dev_priv) && I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)
  11478. return false;
  11479. if (!dev_priv->vbt.int_crt_support)
  11480. return false;
  11481. return true;
  11482. }
  11483. void intel_pps_unlock_regs_wa(struct drm_i915_private *dev_priv)
  11484. {
  11485. int pps_num;
  11486. int pps_idx;
  11487. if (HAS_DDI(dev_priv))
  11488. return;
  11489. /*
  11490. * This w/a is needed at least on CPT/PPT, but to be sure apply it
  11491. * everywhere where registers can be write protected.
  11492. */
  11493. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  11494. pps_num = 2;
  11495. else
  11496. pps_num = 1;
  11497. for (pps_idx = 0; pps_idx < pps_num; pps_idx++) {
  11498. u32 val = I915_READ(PP_CONTROL(pps_idx));
  11499. val = (val & ~PANEL_UNLOCK_MASK) | PANEL_UNLOCK_REGS;
  11500. I915_WRITE(PP_CONTROL(pps_idx), val);
  11501. }
  11502. }
  11503. static void intel_pps_init(struct drm_i915_private *dev_priv)
  11504. {
  11505. if (HAS_PCH_SPLIT(dev_priv) || IS_GEN9_LP(dev_priv))
  11506. dev_priv->pps_mmio_base = PCH_PPS_BASE;
  11507. else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  11508. dev_priv->pps_mmio_base = VLV_PPS_BASE;
  11509. else
  11510. dev_priv->pps_mmio_base = PPS_BASE;
  11511. intel_pps_unlock_regs_wa(dev_priv);
  11512. }
  11513. static void intel_setup_outputs(struct drm_i915_private *dev_priv)
  11514. {
  11515. struct intel_encoder *encoder;
  11516. bool dpd_is_edp = false;
  11517. intel_pps_init(dev_priv);
  11518. /*
  11519. * intel_edp_init_connector() depends on this completing first, to
  11520. * prevent the registeration of both eDP and LVDS and the incorrect
  11521. * sharing of the PPS.
  11522. */
  11523. intel_lvds_init(dev_priv);
  11524. if (intel_crt_present(dev_priv))
  11525. intel_crt_init(dev_priv);
  11526. if (IS_GEN9_LP(dev_priv)) {
  11527. /*
  11528. * FIXME: Broxton doesn't support port detection via the
  11529. * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to
  11530. * detect the ports.
  11531. */
  11532. intel_ddi_init(dev_priv, PORT_A);
  11533. intel_ddi_init(dev_priv, PORT_B);
  11534. intel_ddi_init(dev_priv, PORT_C);
  11535. intel_dsi_init(dev_priv);
  11536. } else if (HAS_DDI(dev_priv)) {
  11537. int found;
  11538. /*
  11539. * Haswell uses DDI functions to detect digital outputs.
  11540. * On SKL pre-D0 the strap isn't connected, so we assume
  11541. * it's there.
  11542. */
  11543. found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED;
  11544. /* WaIgnoreDDIAStrap: skl */
  11545. if (found || IS_GEN9_BC(dev_priv))
  11546. intel_ddi_init(dev_priv, PORT_A);
  11547. /* DDI B, C, D, and F detection is indicated by the SFUSE_STRAP
  11548. * register */
  11549. found = I915_READ(SFUSE_STRAP);
  11550. if (found & SFUSE_STRAP_DDIB_DETECTED)
  11551. intel_ddi_init(dev_priv, PORT_B);
  11552. if (found & SFUSE_STRAP_DDIC_DETECTED)
  11553. intel_ddi_init(dev_priv, PORT_C);
  11554. if (found & SFUSE_STRAP_DDID_DETECTED)
  11555. intel_ddi_init(dev_priv, PORT_D);
  11556. if (found & SFUSE_STRAP_DDIF_DETECTED)
  11557. intel_ddi_init(dev_priv, PORT_F);
  11558. /*
  11559. * On SKL we don't have a way to detect DDI-E so we rely on VBT.
  11560. */
  11561. if (IS_GEN9_BC(dev_priv) &&
  11562. (dev_priv->vbt.ddi_port_info[PORT_E].supports_dp ||
  11563. dev_priv->vbt.ddi_port_info[PORT_E].supports_dvi ||
  11564. dev_priv->vbt.ddi_port_info[PORT_E].supports_hdmi))
  11565. intel_ddi_init(dev_priv, PORT_E);
  11566. } else if (HAS_PCH_SPLIT(dev_priv)) {
  11567. int found;
  11568. dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D);
  11569. if (has_edp_a(dev_priv))
  11570. intel_dp_init(dev_priv, DP_A, PORT_A);
  11571. if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) {
  11572. /* PCH SDVOB multiplex with HDMIB */
  11573. found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B);
  11574. if (!found)
  11575. intel_hdmi_init(dev_priv, PCH_HDMIB, PORT_B);
  11576. if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
  11577. intel_dp_init(dev_priv, PCH_DP_B, PORT_B);
  11578. }
  11579. if (I915_READ(PCH_HDMIC) & SDVO_DETECTED)
  11580. intel_hdmi_init(dev_priv, PCH_HDMIC, PORT_C);
  11581. if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED)
  11582. intel_hdmi_init(dev_priv, PCH_HDMID, PORT_D);
  11583. if (I915_READ(PCH_DP_C) & DP_DETECTED)
  11584. intel_dp_init(dev_priv, PCH_DP_C, PORT_C);
  11585. if (I915_READ(PCH_DP_D) & DP_DETECTED)
  11586. intel_dp_init(dev_priv, PCH_DP_D, PORT_D);
  11587. } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
  11588. bool has_edp, has_port;
  11589. /*
  11590. * The DP_DETECTED bit is the latched state of the DDC
  11591. * SDA pin at boot. However since eDP doesn't require DDC
  11592. * (no way to plug in a DP->HDMI dongle) the DDC pins for
  11593. * eDP ports may have been muxed to an alternate function.
  11594. * Thus we can't rely on the DP_DETECTED bit alone to detect
  11595. * eDP ports. Consult the VBT as well as DP_DETECTED to
  11596. * detect eDP ports.
  11597. *
  11598. * Sadly the straps seem to be missing sometimes even for HDMI
  11599. * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
  11600. * and VBT for the presence of the port. Additionally we can't
  11601. * trust the port type the VBT declares as we've seen at least
  11602. * HDMI ports that the VBT claim are DP or eDP.
  11603. */
  11604. has_edp = intel_dp_is_port_edp(dev_priv, PORT_B);
  11605. has_port = intel_bios_is_port_present(dev_priv, PORT_B);
  11606. if (I915_READ(VLV_DP_B) & DP_DETECTED || has_port)
  11607. has_edp &= intel_dp_init(dev_priv, VLV_DP_B, PORT_B);
  11608. if ((I915_READ(VLV_HDMIB) & SDVO_DETECTED || has_port) && !has_edp)
  11609. intel_hdmi_init(dev_priv, VLV_HDMIB, PORT_B);
  11610. has_edp = intel_dp_is_port_edp(dev_priv, PORT_C);
  11611. has_port = intel_bios_is_port_present(dev_priv, PORT_C);
  11612. if (I915_READ(VLV_DP_C) & DP_DETECTED || has_port)
  11613. has_edp &= intel_dp_init(dev_priv, VLV_DP_C, PORT_C);
  11614. if ((I915_READ(VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp)
  11615. intel_hdmi_init(dev_priv, VLV_HDMIC, PORT_C);
  11616. if (IS_CHERRYVIEW(dev_priv)) {
  11617. /*
  11618. * eDP not supported on port D,
  11619. * so no need to worry about it
  11620. */
  11621. has_port = intel_bios_is_port_present(dev_priv, PORT_D);
  11622. if (I915_READ(CHV_DP_D) & DP_DETECTED || has_port)
  11623. intel_dp_init(dev_priv, CHV_DP_D, PORT_D);
  11624. if (I915_READ(CHV_HDMID) & SDVO_DETECTED || has_port)
  11625. intel_hdmi_init(dev_priv, CHV_HDMID, PORT_D);
  11626. }
  11627. intel_dsi_init(dev_priv);
  11628. } else if (!IS_GEN2(dev_priv) && !IS_PINEVIEW(dev_priv)) {
  11629. bool found = false;
  11630. if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
  11631. DRM_DEBUG_KMS("probing SDVOB\n");
  11632. found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B);
  11633. if (!found && IS_G4X(dev_priv)) {
  11634. DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
  11635. intel_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B);
  11636. }
  11637. if (!found && IS_G4X(dev_priv))
  11638. intel_dp_init(dev_priv, DP_B, PORT_B);
  11639. }
  11640. /* Before G4X SDVOC doesn't have its own detect register */
  11641. if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
  11642. DRM_DEBUG_KMS("probing SDVOC\n");
  11643. found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C);
  11644. }
  11645. if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) {
  11646. if (IS_G4X(dev_priv)) {
  11647. DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
  11648. intel_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C);
  11649. }
  11650. if (IS_G4X(dev_priv))
  11651. intel_dp_init(dev_priv, DP_C, PORT_C);
  11652. }
  11653. if (IS_G4X(dev_priv) && (I915_READ(DP_D) & DP_DETECTED))
  11654. intel_dp_init(dev_priv, DP_D, PORT_D);
  11655. } else if (IS_GEN2(dev_priv))
  11656. intel_dvo_init(dev_priv);
  11657. if (SUPPORTS_TV(dev_priv))
  11658. intel_tv_init(dev_priv);
  11659. intel_psr_init(dev_priv);
  11660. for_each_intel_encoder(&dev_priv->drm, encoder) {
  11661. encoder->base.possible_crtcs = encoder->crtc_mask;
  11662. encoder->base.possible_clones =
  11663. intel_encoder_clones(encoder);
  11664. }
  11665. intel_init_pch_refclk(dev_priv);
  11666. drm_helper_move_panel_connectors_to_head(&dev_priv->drm);
  11667. }
  11668. static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
  11669. {
  11670. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  11671. drm_framebuffer_cleanup(fb);
  11672. i915_gem_object_lock(intel_fb->obj);
  11673. WARN_ON(!intel_fb->obj->framebuffer_references--);
  11674. i915_gem_object_unlock(intel_fb->obj);
  11675. i915_gem_object_put(intel_fb->obj);
  11676. kfree(intel_fb);
  11677. }
  11678. static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
  11679. struct drm_file *file,
  11680. unsigned int *handle)
  11681. {
  11682. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  11683. struct drm_i915_gem_object *obj = intel_fb->obj;
  11684. if (obj->userptr.mm) {
  11685. DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n");
  11686. return -EINVAL;
  11687. }
  11688. return drm_gem_handle_create(file, &obj->base, handle);
  11689. }
  11690. static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb,
  11691. struct drm_file *file,
  11692. unsigned flags, unsigned color,
  11693. struct drm_clip_rect *clips,
  11694. unsigned num_clips)
  11695. {
  11696. struct drm_i915_gem_object *obj = intel_fb_obj(fb);
  11697. i915_gem_object_flush_if_display(obj);
  11698. intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
  11699. return 0;
  11700. }
  11701. static const struct drm_framebuffer_funcs intel_fb_funcs = {
  11702. .destroy = intel_user_framebuffer_destroy,
  11703. .create_handle = intel_user_framebuffer_create_handle,
  11704. .dirty = intel_user_framebuffer_dirty,
  11705. };
  11706. static
  11707. u32 intel_fb_pitch_limit(struct drm_i915_private *dev_priv,
  11708. uint64_t fb_modifier, uint32_t pixel_format)
  11709. {
  11710. u32 gen = INTEL_GEN(dev_priv);
  11711. if (gen >= 9) {
  11712. int cpp = drm_format_plane_cpp(pixel_format, 0);
  11713. /* "The stride in bytes must not exceed the of the size of 8K
  11714. * pixels and 32K bytes."
  11715. */
  11716. return min(8192 * cpp, 32768);
  11717. } else if (gen >= 5 && !HAS_GMCH_DISPLAY(dev_priv)) {
  11718. return 32*1024;
  11719. } else if (gen >= 4) {
  11720. if (fb_modifier == I915_FORMAT_MOD_X_TILED)
  11721. return 16*1024;
  11722. else
  11723. return 32*1024;
  11724. } else if (gen >= 3) {
  11725. if (fb_modifier == I915_FORMAT_MOD_X_TILED)
  11726. return 8*1024;
  11727. else
  11728. return 16*1024;
  11729. } else {
  11730. /* XXX DSPC is limited to 4k tiled */
  11731. return 8*1024;
  11732. }
  11733. }
  11734. static int intel_framebuffer_init(struct intel_framebuffer *intel_fb,
  11735. struct drm_i915_gem_object *obj,
  11736. struct drm_mode_fb_cmd2 *mode_cmd)
  11737. {
  11738. struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
  11739. struct drm_framebuffer *fb = &intel_fb->base;
  11740. struct drm_format_name_buf format_name;
  11741. u32 pitch_limit;
  11742. unsigned int tiling, stride;
  11743. int ret = -EINVAL;
  11744. int i;
  11745. i915_gem_object_lock(obj);
  11746. obj->framebuffer_references++;
  11747. tiling = i915_gem_object_get_tiling(obj);
  11748. stride = i915_gem_object_get_stride(obj);
  11749. i915_gem_object_unlock(obj);
  11750. if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) {
  11751. /*
  11752. * If there's a fence, enforce that
  11753. * the fb modifier and tiling mode match.
  11754. */
  11755. if (tiling != I915_TILING_NONE &&
  11756. tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
  11757. DRM_DEBUG_KMS("tiling_mode doesn't match fb modifier\n");
  11758. goto err;
  11759. }
  11760. } else {
  11761. if (tiling == I915_TILING_X) {
  11762. mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED;
  11763. } else if (tiling == I915_TILING_Y) {
  11764. DRM_DEBUG_KMS("No Y tiling for legacy addfb\n");
  11765. goto err;
  11766. }
  11767. }
  11768. /* Passed in modifier sanity checking. */
  11769. switch (mode_cmd->modifier[0]) {
  11770. case I915_FORMAT_MOD_Y_TILED_CCS:
  11771. case I915_FORMAT_MOD_Yf_TILED_CCS:
  11772. switch (mode_cmd->pixel_format) {
  11773. case DRM_FORMAT_XBGR8888:
  11774. case DRM_FORMAT_ABGR8888:
  11775. case DRM_FORMAT_XRGB8888:
  11776. case DRM_FORMAT_ARGB8888:
  11777. break;
  11778. default:
  11779. DRM_DEBUG_KMS("RC supported only with RGB8888 formats\n");
  11780. goto err;
  11781. }
  11782. /* fall through */
  11783. case I915_FORMAT_MOD_Y_TILED:
  11784. case I915_FORMAT_MOD_Yf_TILED:
  11785. if (INTEL_GEN(dev_priv) < 9) {
  11786. DRM_DEBUG_KMS("Unsupported tiling 0x%llx!\n",
  11787. mode_cmd->modifier[0]);
  11788. goto err;
  11789. }
  11790. case DRM_FORMAT_MOD_LINEAR:
  11791. case I915_FORMAT_MOD_X_TILED:
  11792. break;
  11793. default:
  11794. DRM_DEBUG_KMS("Unsupported fb modifier 0x%llx!\n",
  11795. mode_cmd->modifier[0]);
  11796. goto err;
  11797. }
  11798. /*
  11799. * gen2/3 display engine uses the fence if present,
  11800. * so the tiling mode must match the fb modifier exactly.
  11801. */
  11802. if (INTEL_GEN(dev_priv) < 4 &&
  11803. tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
  11804. DRM_DEBUG_KMS("tiling_mode must match fb modifier exactly on gen2/3\n");
  11805. goto err;
  11806. }
  11807. pitch_limit = intel_fb_pitch_limit(dev_priv, mode_cmd->modifier[0],
  11808. mode_cmd->pixel_format);
  11809. if (mode_cmd->pitches[0] > pitch_limit) {
  11810. DRM_DEBUG_KMS("%s pitch (%u) must be at most %d\n",
  11811. mode_cmd->modifier[0] != DRM_FORMAT_MOD_LINEAR ?
  11812. "tiled" : "linear",
  11813. mode_cmd->pitches[0], pitch_limit);
  11814. goto err;
  11815. }
  11816. /*
  11817. * If there's a fence, enforce that
  11818. * the fb pitch and fence stride match.
  11819. */
  11820. if (tiling != I915_TILING_NONE && mode_cmd->pitches[0] != stride) {
  11821. DRM_DEBUG_KMS("pitch (%d) must match tiling stride (%d)\n",
  11822. mode_cmd->pitches[0], stride);
  11823. goto err;
  11824. }
  11825. /* Reject formats not supported by any plane early. */
  11826. switch (mode_cmd->pixel_format) {
  11827. case DRM_FORMAT_C8:
  11828. case DRM_FORMAT_RGB565:
  11829. case DRM_FORMAT_XRGB8888:
  11830. case DRM_FORMAT_ARGB8888:
  11831. break;
  11832. case DRM_FORMAT_XRGB1555:
  11833. if (INTEL_GEN(dev_priv) > 3) {
  11834. DRM_DEBUG_KMS("unsupported pixel format: %s\n",
  11835. drm_get_format_name(mode_cmd->pixel_format, &format_name));
  11836. goto err;
  11837. }
  11838. break;
  11839. case DRM_FORMAT_ABGR8888:
  11840. if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
  11841. INTEL_GEN(dev_priv) < 9) {
  11842. DRM_DEBUG_KMS("unsupported pixel format: %s\n",
  11843. drm_get_format_name(mode_cmd->pixel_format, &format_name));
  11844. goto err;
  11845. }
  11846. break;
  11847. case DRM_FORMAT_XBGR8888:
  11848. case DRM_FORMAT_XRGB2101010:
  11849. case DRM_FORMAT_XBGR2101010:
  11850. if (INTEL_GEN(dev_priv) < 4) {
  11851. DRM_DEBUG_KMS("unsupported pixel format: %s\n",
  11852. drm_get_format_name(mode_cmd->pixel_format, &format_name));
  11853. goto err;
  11854. }
  11855. break;
  11856. case DRM_FORMAT_ABGR2101010:
  11857. if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
  11858. DRM_DEBUG_KMS("unsupported pixel format: %s\n",
  11859. drm_get_format_name(mode_cmd->pixel_format, &format_name));
  11860. goto err;
  11861. }
  11862. break;
  11863. case DRM_FORMAT_YUYV:
  11864. case DRM_FORMAT_UYVY:
  11865. case DRM_FORMAT_YVYU:
  11866. case DRM_FORMAT_VYUY:
  11867. if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) {
  11868. DRM_DEBUG_KMS("unsupported pixel format: %s\n",
  11869. drm_get_format_name(mode_cmd->pixel_format, &format_name));
  11870. goto err;
  11871. }
  11872. break;
  11873. default:
  11874. DRM_DEBUG_KMS("unsupported pixel format: %s\n",
  11875. drm_get_format_name(mode_cmd->pixel_format, &format_name));
  11876. goto err;
  11877. }
  11878. /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
  11879. if (mode_cmd->offsets[0] != 0)
  11880. goto err;
  11881. drm_helper_mode_fill_fb_struct(&dev_priv->drm, fb, mode_cmd);
  11882. for (i = 0; i < fb->format->num_planes; i++) {
  11883. u32 stride_alignment;
  11884. if (mode_cmd->handles[i] != mode_cmd->handles[0]) {
  11885. DRM_DEBUG_KMS("bad plane %d handle\n", i);
  11886. goto err;
  11887. }
  11888. stride_alignment = intel_fb_stride_alignment(fb, i);
  11889. /*
  11890. * Display WA #0531: skl,bxt,kbl,glk
  11891. *
  11892. * Render decompression and plane width > 3840
  11893. * combined with horizontal panning requires the
  11894. * plane stride to be a multiple of 4. We'll just
  11895. * require the entire fb to accommodate that to avoid
  11896. * potential runtime errors at plane configuration time.
  11897. */
  11898. if (IS_GEN9(dev_priv) && i == 0 && fb->width > 3840 &&
  11899. (fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
  11900. fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS))
  11901. stride_alignment *= 4;
  11902. if (fb->pitches[i] & (stride_alignment - 1)) {
  11903. DRM_DEBUG_KMS("plane %d pitch (%d) must be at least %u byte aligned\n",
  11904. i, fb->pitches[i], stride_alignment);
  11905. goto err;
  11906. }
  11907. }
  11908. intel_fb->obj = obj;
  11909. ret = intel_fill_fb_info(dev_priv, fb);
  11910. if (ret)
  11911. goto err;
  11912. ret = drm_framebuffer_init(&dev_priv->drm, fb, &intel_fb_funcs);
  11913. if (ret) {
  11914. DRM_ERROR("framebuffer init failed %d\n", ret);
  11915. goto err;
  11916. }
  11917. return 0;
  11918. err:
  11919. i915_gem_object_lock(obj);
  11920. obj->framebuffer_references--;
  11921. i915_gem_object_unlock(obj);
  11922. return ret;
  11923. }
  11924. static struct drm_framebuffer *
  11925. intel_user_framebuffer_create(struct drm_device *dev,
  11926. struct drm_file *filp,
  11927. const struct drm_mode_fb_cmd2 *user_mode_cmd)
  11928. {
  11929. struct drm_framebuffer *fb;
  11930. struct drm_i915_gem_object *obj;
  11931. struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd;
  11932. obj = i915_gem_object_lookup(filp, mode_cmd.handles[0]);
  11933. if (!obj)
  11934. return ERR_PTR(-ENOENT);
  11935. fb = intel_framebuffer_create(obj, &mode_cmd);
  11936. if (IS_ERR(fb))
  11937. i915_gem_object_put(obj);
  11938. return fb;
  11939. }
  11940. static void intel_atomic_state_free(struct drm_atomic_state *state)
  11941. {
  11942. struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
  11943. drm_atomic_state_default_release(state);
  11944. i915_sw_fence_fini(&intel_state->commit_ready);
  11945. kfree(state);
  11946. }
  11947. static enum drm_mode_status
  11948. intel_mode_valid(struct drm_device *dev,
  11949. const struct drm_display_mode *mode)
  11950. {
  11951. if (mode->vscan > 1)
  11952. return MODE_NO_VSCAN;
  11953. if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
  11954. return MODE_NO_DBLESCAN;
  11955. if (mode->flags & DRM_MODE_FLAG_HSKEW)
  11956. return MODE_H_ILLEGAL;
  11957. if (mode->flags & (DRM_MODE_FLAG_CSYNC |
  11958. DRM_MODE_FLAG_NCSYNC |
  11959. DRM_MODE_FLAG_PCSYNC))
  11960. return MODE_HSYNC;
  11961. if (mode->flags & (DRM_MODE_FLAG_BCAST |
  11962. DRM_MODE_FLAG_PIXMUX |
  11963. DRM_MODE_FLAG_CLKDIV2))
  11964. return MODE_BAD;
  11965. return MODE_OK;
  11966. }
  11967. static const struct drm_mode_config_funcs intel_mode_funcs = {
  11968. .fb_create = intel_user_framebuffer_create,
  11969. .get_format_info = intel_get_format_info,
  11970. .output_poll_changed = intel_fbdev_output_poll_changed,
  11971. .mode_valid = intel_mode_valid,
  11972. .atomic_check = intel_atomic_check,
  11973. .atomic_commit = intel_atomic_commit,
  11974. .atomic_state_alloc = intel_atomic_state_alloc,
  11975. .atomic_state_clear = intel_atomic_state_clear,
  11976. .atomic_state_free = intel_atomic_state_free,
  11977. };
  11978. /**
  11979. * intel_init_display_hooks - initialize the display modesetting hooks
  11980. * @dev_priv: device private
  11981. */
  11982. void intel_init_display_hooks(struct drm_i915_private *dev_priv)
  11983. {
  11984. intel_init_cdclk_hooks(dev_priv);
  11985. if (INTEL_GEN(dev_priv) >= 9) {
  11986. dev_priv->display.get_pipe_config = haswell_get_pipe_config;
  11987. dev_priv->display.get_initial_plane_config =
  11988. skylake_get_initial_plane_config;
  11989. dev_priv->display.crtc_compute_clock =
  11990. haswell_crtc_compute_clock;
  11991. dev_priv->display.crtc_enable = haswell_crtc_enable;
  11992. dev_priv->display.crtc_disable = haswell_crtc_disable;
  11993. } else if (HAS_DDI(dev_priv)) {
  11994. dev_priv->display.get_pipe_config = haswell_get_pipe_config;
  11995. dev_priv->display.get_initial_plane_config =
  11996. i9xx_get_initial_plane_config;
  11997. dev_priv->display.crtc_compute_clock =
  11998. haswell_crtc_compute_clock;
  11999. dev_priv->display.crtc_enable = haswell_crtc_enable;
  12000. dev_priv->display.crtc_disable = haswell_crtc_disable;
  12001. } else if (HAS_PCH_SPLIT(dev_priv)) {
  12002. dev_priv->display.get_pipe_config = ironlake_get_pipe_config;
  12003. dev_priv->display.get_initial_plane_config =
  12004. i9xx_get_initial_plane_config;
  12005. dev_priv->display.crtc_compute_clock =
  12006. ironlake_crtc_compute_clock;
  12007. dev_priv->display.crtc_enable = ironlake_crtc_enable;
  12008. dev_priv->display.crtc_disable = ironlake_crtc_disable;
  12009. } else if (IS_CHERRYVIEW(dev_priv)) {
  12010. dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
  12011. dev_priv->display.get_initial_plane_config =
  12012. i9xx_get_initial_plane_config;
  12013. dev_priv->display.crtc_compute_clock = chv_crtc_compute_clock;
  12014. dev_priv->display.crtc_enable = valleyview_crtc_enable;
  12015. dev_priv->display.crtc_disable = i9xx_crtc_disable;
  12016. } else if (IS_VALLEYVIEW(dev_priv)) {
  12017. dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
  12018. dev_priv->display.get_initial_plane_config =
  12019. i9xx_get_initial_plane_config;
  12020. dev_priv->display.crtc_compute_clock = vlv_crtc_compute_clock;
  12021. dev_priv->display.crtc_enable = valleyview_crtc_enable;
  12022. dev_priv->display.crtc_disable = i9xx_crtc_disable;
  12023. } else if (IS_G4X(dev_priv)) {
  12024. dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
  12025. dev_priv->display.get_initial_plane_config =
  12026. i9xx_get_initial_plane_config;
  12027. dev_priv->display.crtc_compute_clock = g4x_crtc_compute_clock;
  12028. dev_priv->display.crtc_enable = i9xx_crtc_enable;
  12029. dev_priv->display.crtc_disable = i9xx_crtc_disable;
  12030. } else if (IS_PINEVIEW(dev_priv)) {
  12031. dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
  12032. dev_priv->display.get_initial_plane_config =
  12033. i9xx_get_initial_plane_config;
  12034. dev_priv->display.crtc_compute_clock = pnv_crtc_compute_clock;
  12035. dev_priv->display.crtc_enable = i9xx_crtc_enable;
  12036. dev_priv->display.crtc_disable = i9xx_crtc_disable;
  12037. } else if (!IS_GEN2(dev_priv)) {
  12038. dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
  12039. dev_priv->display.get_initial_plane_config =
  12040. i9xx_get_initial_plane_config;
  12041. dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock;
  12042. dev_priv->display.crtc_enable = i9xx_crtc_enable;
  12043. dev_priv->display.crtc_disable = i9xx_crtc_disable;
  12044. } else {
  12045. dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
  12046. dev_priv->display.get_initial_plane_config =
  12047. i9xx_get_initial_plane_config;
  12048. dev_priv->display.crtc_compute_clock = i8xx_crtc_compute_clock;
  12049. dev_priv->display.crtc_enable = i9xx_crtc_enable;
  12050. dev_priv->display.crtc_disable = i9xx_crtc_disable;
  12051. }
  12052. if (IS_GEN5(dev_priv)) {
  12053. dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
  12054. } else if (IS_GEN6(dev_priv)) {
  12055. dev_priv->display.fdi_link_train = gen6_fdi_link_train;
  12056. } else if (IS_IVYBRIDGE(dev_priv)) {
  12057. /* FIXME: detect B0+ stepping and use auto training */
  12058. dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
  12059. } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
  12060. dev_priv->display.fdi_link_train = hsw_fdi_link_train;
  12061. }
  12062. if (INTEL_GEN(dev_priv) >= 9)
  12063. dev_priv->display.update_crtcs = skl_update_crtcs;
  12064. else
  12065. dev_priv->display.update_crtcs = intel_update_crtcs;
  12066. }
  12067. /*
  12068. * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
  12069. */
  12070. static void quirk_ssc_force_disable(struct drm_device *dev)
  12071. {
  12072. struct drm_i915_private *dev_priv = to_i915(dev);
  12073. dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE;
  12074. DRM_INFO("applying lvds SSC disable quirk\n");
  12075. }
  12076. /*
  12077. * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
  12078. * brightness value
  12079. */
  12080. static void quirk_invert_brightness(struct drm_device *dev)
  12081. {
  12082. struct drm_i915_private *dev_priv = to_i915(dev);
  12083. dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS;
  12084. DRM_INFO("applying inverted panel brightness quirk\n");
  12085. }
  12086. /* Some VBT's incorrectly indicate no backlight is present */
  12087. static void quirk_backlight_present(struct drm_device *dev)
  12088. {
  12089. struct drm_i915_private *dev_priv = to_i915(dev);
  12090. dev_priv->quirks |= QUIRK_BACKLIGHT_PRESENT;
  12091. DRM_INFO("applying backlight present quirk\n");
  12092. }
  12093. /* Toshiba Satellite P50-C-18C requires T12 delay to be min 800ms
  12094. * which is 300 ms greater than eDP spec T12 min.
  12095. */
  12096. static void quirk_increase_t12_delay(struct drm_device *dev)
  12097. {
  12098. struct drm_i915_private *dev_priv = to_i915(dev);
  12099. dev_priv->quirks |= QUIRK_INCREASE_T12_DELAY;
  12100. DRM_INFO("Applying T12 delay quirk\n");
  12101. }
  12102. struct intel_quirk {
  12103. int device;
  12104. int subsystem_vendor;
  12105. int subsystem_device;
  12106. void (*hook)(struct drm_device *dev);
  12107. };
  12108. /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
  12109. struct intel_dmi_quirk {
  12110. void (*hook)(struct drm_device *dev);
  12111. const struct dmi_system_id (*dmi_id_list)[];
  12112. };
  12113. static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
  12114. {
  12115. DRM_INFO("Backlight polarity reversed on %s\n", id->ident);
  12116. return 1;
  12117. }
  12118. static const struct intel_dmi_quirk intel_dmi_quirks[] = {
  12119. {
  12120. .dmi_id_list = &(const struct dmi_system_id[]) {
  12121. {
  12122. .callback = intel_dmi_reverse_brightness,
  12123. .ident = "NCR Corporation",
  12124. .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
  12125. DMI_MATCH(DMI_PRODUCT_NAME, ""),
  12126. },
  12127. },
  12128. { } /* terminating entry */
  12129. },
  12130. .hook = quirk_invert_brightness,
  12131. },
  12132. };
  12133. static struct intel_quirk intel_quirks[] = {
  12134. /* Lenovo U160 cannot use SSC on LVDS */
  12135. { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable },
  12136. /* Sony Vaio Y cannot use SSC on LVDS */
  12137. { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable },
  12138. /* Acer Aspire 5734Z must invert backlight brightness */
  12139. { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness },
  12140. /* Acer/eMachines G725 */
  12141. { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness },
  12142. /* Acer/eMachines e725 */
  12143. { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness },
  12144. /* Acer/Packard Bell NCL20 */
  12145. { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness },
  12146. /* Acer Aspire 4736Z */
  12147. { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness },
  12148. /* Acer Aspire 5336 */
  12149. { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness },
  12150. /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */
  12151. { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present },
  12152. /* Acer C720 Chromebook (Core i3 4005U) */
  12153. { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present },
  12154. /* Apple Macbook 2,1 (Core 2 T7400) */
  12155. { 0x27a2, 0x8086, 0x7270, quirk_backlight_present },
  12156. /* Apple Macbook 4,1 */
  12157. { 0x2a02, 0x106b, 0x00a1, quirk_backlight_present },
  12158. /* Toshiba CB35 Chromebook (Celeron 2955U) */
  12159. { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present },
  12160. /* HP Chromebook 14 (Celeron 2955U) */
  12161. { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present },
  12162. /* Dell Chromebook 11 */
  12163. { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present },
  12164. /* Dell Chromebook 11 (2015 version) */
  12165. { 0x0a16, 0x1028, 0x0a35, quirk_backlight_present },
  12166. /* Toshiba Satellite P50-C-18C */
  12167. { 0x191B, 0x1179, 0xF840, quirk_increase_t12_delay },
  12168. };
  12169. static void intel_init_quirks(struct drm_device *dev)
  12170. {
  12171. struct pci_dev *d = dev->pdev;
  12172. int i;
  12173. for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) {
  12174. struct intel_quirk *q = &intel_quirks[i];
  12175. if (d->device == q->device &&
  12176. (d->subsystem_vendor == q->subsystem_vendor ||
  12177. q->subsystem_vendor == PCI_ANY_ID) &&
  12178. (d->subsystem_device == q->subsystem_device ||
  12179. q->subsystem_device == PCI_ANY_ID))
  12180. q->hook(dev);
  12181. }
  12182. for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) {
  12183. if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0)
  12184. intel_dmi_quirks[i].hook(dev);
  12185. }
  12186. }
  12187. /* Disable the VGA plane that we never use */
  12188. static void i915_disable_vga(struct drm_i915_private *dev_priv)
  12189. {
  12190. struct pci_dev *pdev = dev_priv->drm.pdev;
  12191. u8 sr1;
  12192. i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv);
  12193. /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
  12194. vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
  12195. outb(SR01, VGA_SR_INDEX);
  12196. sr1 = inb(VGA_SR_DATA);
  12197. outb(sr1 | 1<<5, VGA_SR_DATA);
  12198. vga_put(pdev, VGA_RSRC_LEGACY_IO);
  12199. udelay(300);
  12200. I915_WRITE(vga_reg, VGA_DISP_DISABLE);
  12201. POSTING_READ(vga_reg);
  12202. }
  12203. void intel_modeset_init_hw(struct drm_device *dev)
  12204. {
  12205. struct drm_i915_private *dev_priv = to_i915(dev);
  12206. intel_update_cdclk(dev_priv);
  12207. intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK");
  12208. dev_priv->cdclk.logical = dev_priv->cdclk.actual = dev_priv->cdclk.hw;
  12209. }
  12210. /*
  12211. * Calculate what we think the watermarks should be for the state we've read
  12212. * out of the hardware and then immediately program those watermarks so that
  12213. * we ensure the hardware settings match our internal state.
  12214. *
  12215. * We can calculate what we think WM's should be by creating a duplicate of the
  12216. * current state (which was constructed during hardware readout) and running it
  12217. * through the atomic check code to calculate new watermark values in the
  12218. * state object.
  12219. */
  12220. static void sanitize_watermarks(struct drm_device *dev)
  12221. {
  12222. struct drm_i915_private *dev_priv = to_i915(dev);
  12223. struct drm_atomic_state *state;
  12224. struct intel_atomic_state *intel_state;
  12225. struct drm_crtc *crtc;
  12226. struct drm_crtc_state *cstate;
  12227. struct drm_modeset_acquire_ctx ctx;
  12228. int ret;
  12229. int i;
  12230. /* Only supported on platforms that use atomic watermark design */
  12231. if (!dev_priv->display.optimize_watermarks)
  12232. return;
  12233. /*
  12234. * We need to hold connection_mutex before calling duplicate_state so
  12235. * that the connector loop is protected.
  12236. */
  12237. drm_modeset_acquire_init(&ctx, 0);
  12238. retry:
  12239. ret = drm_modeset_lock_all_ctx(dev, &ctx);
  12240. if (ret == -EDEADLK) {
  12241. drm_modeset_backoff(&ctx);
  12242. goto retry;
  12243. } else if (WARN_ON(ret)) {
  12244. goto fail;
  12245. }
  12246. state = drm_atomic_helper_duplicate_state(dev, &ctx);
  12247. if (WARN_ON(IS_ERR(state)))
  12248. goto fail;
  12249. intel_state = to_intel_atomic_state(state);
  12250. /*
  12251. * Hardware readout is the only time we don't want to calculate
  12252. * intermediate watermarks (since we don't trust the current
  12253. * watermarks).
  12254. */
  12255. if (!HAS_GMCH_DISPLAY(dev_priv))
  12256. intel_state->skip_intermediate_wm = true;
  12257. ret = intel_atomic_check(dev, state);
  12258. if (ret) {
  12259. /*
  12260. * If we fail here, it means that the hardware appears to be
  12261. * programmed in a way that shouldn't be possible, given our
  12262. * understanding of watermark requirements. This might mean a
  12263. * mistake in the hardware readout code or a mistake in the
  12264. * watermark calculations for a given platform. Raise a WARN
  12265. * so that this is noticeable.
  12266. *
  12267. * If this actually happens, we'll have to just leave the
  12268. * BIOS-programmed watermarks untouched and hope for the best.
  12269. */
  12270. WARN(true, "Could not determine valid watermarks for inherited state\n");
  12271. goto put_state;
  12272. }
  12273. /* Write calculated watermark values back */
  12274. for_each_new_crtc_in_state(state, crtc, cstate, i) {
  12275. struct intel_crtc_state *cs = to_intel_crtc_state(cstate);
  12276. cs->wm.need_postvbl_update = true;
  12277. dev_priv->display.optimize_watermarks(intel_state, cs);
  12278. to_intel_crtc_state(crtc->state)->wm = cs->wm;
  12279. }
  12280. put_state:
  12281. drm_atomic_state_put(state);
  12282. fail:
  12283. drm_modeset_drop_locks(&ctx);
  12284. drm_modeset_acquire_fini(&ctx);
  12285. }
  12286. static void intel_update_fdi_pll_freq(struct drm_i915_private *dev_priv)
  12287. {
  12288. if (IS_GEN5(dev_priv)) {
  12289. u32 fdi_pll_clk =
  12290. I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK;
  12291. dev_priv->fdi_pll_freq = (fdi_pll_clk + 2) * 10000;
  12292. } else if (IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv)) {
  12293. dev_priv->fdi_pll_freq = 270000;
  12294. } else {
  12295. return;
  12296. }
  12297. DRM_DEBUG_DRIVER("FDI PLL freq=%d\n", dev_priv->fdi_pll_freq);
  12298. }
  12299. int intel_modeset_init(struct drm_device *dev)
  12300. {
  12301. struct drm_i915_private *dev_priv = to_i915(dev);
  12302. struct i915_ggtt *ggtt = &dev_priv->ggtt;
  12303. enum pipe pipe;
  12304. struct intel_crtc *crtc;
  12305. dev_priv->modeset_wq = alloc_ordered_workqueue("i915_modeset", 0);
  12306. drm_mode_config_init(dev);
  12307. dev->mode_config.min_width = 0;
  12308. dev->mode_config.min_height = 0;
  12309. dev->mode_config.preferred_depth = 24;
  12310. dev->mode_config.prefer_shadow = 1;
  12311. dev->mode_config.allow_fb_modifiers = true;
  12312. dev->mode_config.funcs = &intel_mode_funcs;
  12313. init_llist_head(&dev_priv->atomic_helper.free_list);
  12314. INIT_WORK(&dev_priv->atomic_helper.free_work,
  12315. intel_atomic_helper_free_state_worker);
  12316. intel_init_quirks(dev);
  12317. intel_init_pm(dev_priv);
  12318. if (INTEL_INFO(dev_priv)->num_pipes == 0)
  12319. return 0;
  12320. /*
  12321. * There may be no VBT; and if the BIOS enabled SSC we can
  12322. * just keep using it to avoid unnecessary flicker. Whereas if the
  12323. * BIOS isn't using it, don't assume it will work even if the VBT
  12324. * indicates as much.
  12325. */
  12326. if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
  12327. bool bios_lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) &
  12328. DREF_SSC1_ENABLE);
  12329. if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) {
  12330. DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n",
  12331. bios_lvds_use_ssc ? "en" : "dis",
  12332. dev_priv->vbt.lvds_use_ssc ? "en" : "dis");
  12333. dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc;
  12334. }
  12335. }
  12336. if (IS_GEN2(dev_priv)) {
  12337. dev->mode_config.max_width = 2048;
  12338. dev->mode_config.max_height = 2048;
  12339. } else if (IS_GEN3(dev_priv)) {
  12340. dev->mode_config.max_width = 4096;
  12341. dev->mode_config.max_height = 4096;
  12342. } else {
  12343. dev->mode_config.max_width = 8192;
  12344. dev->mode_config.max_height = 8192;
  12345. }
  12346. if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
  12347. dev->mode_config.cursor_width = IS_I845G(dev_priv) ? 64 : 512;
  12348. dev->mode_config.cursor_height = 1023;
  12349. } else if (IS_GEN2(dev_priv)) {
  12350. dev->mode_config.cursor_width = GEN2_CURSOR_WIDTH;
  12351. dev->mode_config.cursor_height = GEN2_CURSOR_HEIGHT;
  12352. } else {
  12353. dev->mode_config.cursor_width = MAX_CURSOR_WIDTH;
  12354. dev->mode_config.cursor_height = MAX_CURSOR_HEIGHT;
  12355. }
  12356. dev->mode_config.fb_base = ggtt->gmadr.start;
  12357. DRM_DEBUG_KMS("%d display pipe%s available.\n",
  12358. INTEL_INFO(dev_priv)->num_pipes,
  12359. INTEL_INFO(dev_priv)->num_pipes > 1 ? "s" : "");
  12360. for_each_pipe(dev_priv, pipe) {
  12361. int ret;
  12362. ret = intel_crtc_init(dev_priv, pipe);
  12363. if (ret) {
  12364. drm_mode_config_cleanup(dev);
  12365. return ret;
  12366. }
  12367. }
  12368. intel_shared_dpll_init(dev);
  12369. intel_update_fdi_pll_freq(dev_priv);
  12370. intel_update_czclk(dev_priv);
  12371. intel_modeset_init_hw(dev);
  12372. if (dev_priv->max_cdclk_freq == 0)
  12373. intel_update_max_cdclk(dev_priv);
  12374. /* Just disable it once at startup */
  12375. i915_disable_vga(dev_priv);
  12376. intel_setup_outputs(dev_priv);
  12377. drm_modeset_lock_all(dev);
  12378. intel_modeset_setup_hw_state(dev, dev->mode_config.acquire_ctx);
  12379. drm_modeset_unlock_all(dev);
  12380. for_each_intel_crtc(dev, crtc) {
  12381. struct intel_initial_plane_config plane_config = {};
  12382. if (!crtc->active)
  12383. continue;
  12384. /*
  12385. * Note that reserving the BIOS fb up front prevents us
  12386. * from stuffing other stolen allocations like the ring
  12387. * on top. This prevents some ugliness at boot time, and
  12388. * can even allow for smooth boot transitions if the BIOS
  12389. * fb is large enough for the active pipe configuration.
  12390. */
  12391. dev_priv->display.get_initial_plane_config(crtc,
  12392. &plane_config);
  12393. /*
  12394. * If the fb is shared between multiple heads, we'll
  12395. * just get the first one.
  12396. */
  12397. intel_find_initial_plane_obj(crtc, &plane_config);
  12398. }
  12399. /*
  12400. * Make sure hardware watermarks really match the state we read out.
  12401. * Note that we need to do this after reconstructing the BIOS fb's
  12402. * since the watermark calculation done here will use pstate->fb.
  12403. */
  12404. if (!HAS_GMCH_DISPLAY(dev_priv))
  12405. sanitize_watermarks(dev);
  12406. return 0;
  12407. }
  12408. void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
  12409. {
  12410. struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
  12411. /* 640x480@60Hz, ~25175 kHz */
  12412. struct dpll clock = {
  12413. .m1 = 18,
  12414. .m2 = 7,
  12415. .p1 = 13,
  12416. .p2 = 4,
  12417. .n = 2,
  12418. };
  12419. u32 dpll, fp;
  12420. int i;
  12421. WARN_ON(i9xx_calc_dpll_params(48000, &clock) != 25154);
  12422. DRM_DEBUG_KMS("enabling pipe %c due to force quirk (vco=%d dot=%d)\n",
  12423. pipe_name(pipe), clock.vco, clock.dot);
  12424. fp = i9xx_dpll_compute_fp(&clock);
  12425. dpll = (I915_READ(DPLL(pipe)) & DPLL_DVO_2X_MODE) |
  12426. DPLL_VGA_MODE_DIS |
  12427. ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) |
  12428. PLL_P2_DIVIDE_BY_4 |
  12429. PLL_REF_INPUT_DREFCLK |
  12430. DPLL_VCO_ENABLE;
  12431. I915_WRITE(FP0(pipe), fp);
  12432. I915_WRITE(FP1(pipe), fp);
  12433. I915_WRITE(HTOTAL(pipe), (640 - 1) | ((800 - 1) << 16));
  12434. I915_WRITE(HBLANK(pipe), (640 - 1) | ((800 - 1) << 16));
  12435. I915_WRITE(HSYNC(pipe), (656 - 1) | ((752 - 1) << 16));
  12436. I915_WRITE(VTOTAL(pipe), (480 - 1) | ((525 - 1) << 16));
  12437. I915_WRITE(VBLANK(pipe), (480 - 1) | ((525 - 1) << 16));
  12438. I915_WRITE(VSYNC(pipe), (490 - 1) | ((492 - 1) << 16));
  12439. I915_WRITE(PIPESRC(pipe), ((640 - 1) << 16) | (480 - 1));
  12440. /*
  12441. * Apparently we need to have VGA mode enabled prior to changing
  12442. * the P1/P2 dividers. Otherwise the DPLL will keep using the old
  12443. * dividers, even though the register value does change.
  12444. */
  12445. I915_WRITE(DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS);
  12446. I915_WRITE(DPLL(pipe), dpll);
  12447. /* Wait for the clocks to stabilize. */
  12448. POSTING_READ(DPLL(pipe));
  12449. udelay(150);
  12450. /* The pixel multiplier can only be updated once the
  12451. * DPLL is enabled and the clocks are stable.
  12452. *
  12453. * So write it again.
  12454. */
  12455. I915_WRITE(DPLL(pipe), dpll);
  12456. /* We do this three times for luck */
  12457. for (i = 0; i < 3 ; i++) {
  12458. I915_WRITE(DPLL(pipe), dpll);
  12459. POSTING_READ(DPLL(pipe));
  12460. udelay(150); /* wait for warmup */
  12461. }
  12462. I915_WRITE(PIPECONF(pipe), PIPECONF_ENABLE | PIPECONF_PROGRESSIVE);
  12463. POSTING_READ(PIPECONF(pipe));
  12464. intel_wait_for_pipe_scanline_moving(crtc);
  12465. }
  12466. void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
  12467. {
  12468. struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
  12469. DRM_DEBUG_KMS("disabling pipe %c due to force quirk\n",
  12470. pipe_name(pipe));
  12471. WARN_ON(I915_READ(DSPCNTR(PLANE_A)) & DISPLAY_PLANE_ENABLE);
  12472. WARN_ON(I915_READ(DSPCNTR(PLANE_B)) & DISPLAY_PLANE_ENABLE);
  12473. WARN_ON(I915_READ(DSPCNTR(PLANE_C)) & DISPLAY_PLANE_ENABLE);
  12474. WARN_ON(I915_READ(CURCNTR(PIPE_A)) & CURSOR_MODE);
  12475. WARN_ON(I915_READ(CURCNTR(PIPE_B)) & CURSOR_MODE);
  12476. I915_WRITE(PIPECONF(pipe), 0);
  12477. POSTING_READ(PIPECONF(pipe));
  12478. intel_wait_for_pipe_scanline_stopped(crtc);
  12479. I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
  12480. POSTING_READ(DPLL(pipe));
  12481. }
  12482. static bool intel_plane_mapping_ok(struct intel_crtc *crtc,
  12483. struct intel_plane *plane)
  12484. {
  12485. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  12486. enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
  12487. u32 val = I915_READ(DSPCNTR(i9xx_plane));
  12488. return (val & DISPLAY_PLANE_ENABLE) == 0 ||
  12489. (val & DISPPLANE_SEL_PIPE_MASK) == DISPPLANE_SEL_PIPE(crtc->pipe);
  12490. }
  12491. static void
  12492. intel_sanitize_plane_mapping(struct drm_i915_private *dev_priv)
  12493. {
  12494. struct intel_crtc *crtc;
  12495. if (INTEL_GEN(dev_priv) >= 4)
  12496. return;
  12497. for_each_intel_crtc(&dev_priv->drm, crtc) {
  12498. struct intel_plane *plane =
  12499. to_intel_plane(crtc->base.primary);
  12500. if (intel_plane_mapping_ok(crtc, plane))
  12501. continue;
  12502. DRM_DEBUG_KMS("%s attached to the wrong pipe, disabling plane\n",
  12503. plane->base.name);
  12504. intel_plane_disable_noatomic(crtc, plane);
  12505. }
  12506. }
  12507. static bool intel_crtc_has_encoders(struct intel_crtc *crtc)
  12508. {
  12509. struct drm_device *dev = crtc->base.dev;
  12510. struct intel_encoder *encoder;
  12511. for_each_encoder_on_crtc(dev, &crtc->base, encoder)
  12512. return true;
  12513. return false;
  12514. }
  12515. static struct intel_connector *intel_encoder_find_connector(struct intel_encoder *encoder)
  12516. {
  12517. struct drm_device *dev = encoder->base.dev;
  12518. struct intel_connector *connector;
  12519. for_each_connector_on_encoder(dev, &encoder->base, connector)
  12520. return connector;
  12521. return NULL;
  12522. }
  12523. static bool has_pch_trancoder(struct drm_i915_private *dev_priv,
  12524. enum pipe pch_transcoder)
  12525. {
  12526. return HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) ||
  12527. (HAS_PCH_LPT_H(dev_priv) && pch_transcoder == PIPE_A);
  12528. }
  12529. static void intel_sanitize_crtc(struct intel_crtc *crtc,
  12530. struct drm_modeset_acquire_ctx *ctx)
  12531. {
  12532. struct drm_device *dev = crtc->base.dev;
  12533. struct drm_i915_private *dev_priv = to_i915(dev);
  12534. enum transcoder cpu_transcoder = crtc->config->cpu_transcoder;
  12535. /* Clear any frame start delays used for debugging left by the BIOS */
  12536. if (crtc->active && !transcoder_is_dsi(cpu_transcoder)) {
  12537. i915_reg_t reg = PIPECONF(cpu_transcoder);
  12538. I915_WRITE(reg,
  12539. I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
  12540. }
  12541. /* restore vblank interrupts to correct state */
  12542. drm_crtc_vblank_reset(&crtc->base);
  12543. if (crtc->active) {
  12544. struct intel_plane *plane;
  12545. drm_crtc_vblank_on(&crtc->base);
  12546. /* Disable everything but the primary plane */
  12547. for_each_intel_plane_on_crtc(dev, crtc, plane) {
  12548. const struct intel_plane_state *plane_state =
  12549. to_intel_plane_state(plane->base.state);
  12550. if (plane_state->base.visible &&
  12551. plane->base.type != DRM_PLANE_TYPE_PRIMARY)
  12552. intel_plane_disable_noatomic(crtc, plane);
  12553. }
  12554. }
  12555. /* Adjust the state of the output pipe according to whether we
  12556. * have active connectors/encoders. */
  12557. if (crtc->active && !intel_crtc_has_encoders(crtc))
  12558. intel_crtc_disable_noatomic(&crtc->base, ctx);
  12559. if (crtc->active || HAS_GMCH_DISPLAY(dev_priv)) {
  12560. /*
  12561. * We start out with underrun reporting disabled to avoid races.
  12562. * For correct bookkeeping mark this on active crtcs.
  12563. *
  12564. * Also on gmch platforms we dont have any hardware bits to
  12565. * disable the underrun reporting. Which means we need to start
  12566. * out with underrun reporting disabled also on inactive pipes,
  12567. * since otherwise we'll complain about the garbage we read when
  12568. * e.g. coming up after runtime pm.
  12569. *
  12570. * No protection against concurrent access is required - at
  12571. * worst a fifo underrun happens which also sets this to false.
  12572. */
  12573. crtc->cpu_fifo_underrun_disabled = true;
  12574. /*
  12575. * We track the PCH trancoder underrun reporting state
  12576. * within the crtc. With crtc for pipe A housing the underrun
  12577. * reporting state for PCH transcoder A, crtc for pipe B housing
  12578. * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A,
  12579. * and marking underrun reporting as disabled for the non-existing
  12580. * PCH transcoders B and C would prevent enabling the south
  12581. * error interrupt (see cpt_can_enable_serr_int()).
  12582. */
  12583. if (has_pch_trancoder(dev_priv, crtc->pipe))
  12584. crtc->pch_fifo_underrun_disabled = true;
  12585. }
  12586. }
  12587. static void intel_sanitize_encoder(struct intel_encoder *encoder)
  12588. {
  12589. struct intel_connector *connector;
  12590. /* We need to check both for a crtc link (meaning that the
  12591. * encoder is active and trying to read from a pipe) and the
  12592. * pipe itself being active. */
  12593. bool has_active_crtc = encoder->base.crtc &&
  12594. to_intel_crtc(encoder->base.crtc)->active;
  12595. connector = intel_encoder_find_connector(encoder);
  12596. if (connector && !has_active_crtc) {
  12597. DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
  12598. encoder->base.base.id,
  12599. encoder->base.name);
  12600. /* Connector is active, but has no active pipe. This is
  12601. * fallout from our resume register restoring. Disable
  12602. * the encoder manually again. */
  12603. if (encoder->base.crtc) {
  12604. struct drm_crtc_state *crtc_state = encoder->base.crtc->state;
  12605. DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
  12606. encoder->base.base.id,
  12607. encoder->base.name);
  12608. encoder->disable(encoder, to_intel_crtc_state(crtc_state), connector->base.state);
  12609. if (encoder->post_disable)
  12610. encoder->post_disable(encoder, to_intel_crtc_state(crtc_state), connector->base.state);
  12611. }
  12612. encoder->base.crtc = NULL;
  12613. /* Inconsistent output/port/pipe state happens presumably due to
  12614. * a bug in one of the get_hw_state functions. Or someplace else
  12615. * in our code, like the register restore mess on resume. Clamp
  12616. * things to off as a safer default. */
  12617. connector->base.dpms = DRM_MODE_DPMS_OFF;
  12618. connector->base.encoder = NULL;
  12619. }
  12620. }
  12621. void i915_redisable_vga_power_on(struct drm_i915_private *dev_priv)
  12622. {
  12623. i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv);
  12624. if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) {
  12625. DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
  12626. i915_disable_vga(dev_priv);
  12627. }
  12628. }
  12629. void i915_redisable_vga(struct drm_i915_private *dev_priv)
  12630. {
  12631. /* This function can be called both from intel_modeset_setup_hw_state or
  12632. * at a very early point in our resume sequence, where the power well
  12633. * structures are not yet restored. Since this function is at a very
  12634. * paranoid "someone might have enabled VGA while we were not looking"
  12635. * level, just check if the power well is enabled instead of trying to
  12636. * follow the "don't touch the power well if we don't need it" policy
  12637. * the rest of the driver uses. */
  12638. if (!intel_display_power_get_if_enabled(dev_priv, POWER_DOMAIN_VGA))
  12639. return;
  12640. i915_redisable_vga_power_on(dev_priv);
  12641. intel_display_power_put(dev_priv, POWER_DOMAIN_VGA);
  12642. }
  12643. /* FIXME read out full plane state for all planes */
  12644. static void readout_plane_state(struct intel_crtc *crtc)
  12645. {
  12646. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  12647. struct intel_crtc_state *crtc_state =
  12648. to_intel_crtc_state(crtc->base.state);
  12649. struct intel_plane *plane;
  12650. for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
  12651. struct intel_plane_state *plane_state =
  12652. to_intel_plane_state(plane->base.state);
  12653. bool visible = plane->get_hw_state(plane);
  12654. intel_set_plane_visible(crtc_state, plane_state, visible);
  12655. }
  12656. }
  12657. static void intel_modeset_readout_hw_state(struct drm_device *dev)
  12658. {
  12659. struct drm_i915_private *dev_priv = to_i915(dev);
  12660. enum pipe pipe;
  12661. struct intel_crtc *crtc;
  12662. struct intel_encoder *encoder;
  12663. struct intel_connector *connector;
  12664. struct drm_connector_list_iter conn_iter;
  12665. int i;
  12666. dev_priv->active_crtcs = 0;
  12667. for_each_intel_crtc(dev, crtc) {
  12668. struct intel_crtc_state *crtc_state =
  12669. to_intel_crtc_state(crtc->base.state);
  12670. __drm_atomic_helper_crtc_destroy_state(&crtc_state->base);
  12671. memset(crtc_state, 0, sizeof(*crtc_state));
  12672. crtc_state->base.crtc = &crtc->base;
  12673. crtc_state->base.active = crtc_state->base.enable =
  12674. dev_priv->display.get_pipe_config(crtc, crtc_state);
  12675. crtc->base.enabled = crtc_state->base.enable;
  12676. crtc->active = crtc_state->base.active;
  12677. if (crtc_state->base.active)
  12678. dev_priv->active_crtcs |= 1 << crtc->pipe;
  12679. readout_plane_state(crtc);
  12680. DRM_DEBUG_KMS("[CRTC:%d:%s] hw state readout: %s\n",
  12681. crtc->base.base.id, crtc->base.name,
  12682. enableddisabled(crtc_state->base.active));
  12683. }
  12684. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  12685. struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
  12686. pll->on = pll->info->funcs->get_hw_state(dev_priv, pll,
  12687. &pll->state.hw_state);
  12688. pll->state.crtc_mask = 0;
  12689. for_each_intel_crtc(dev, crtc) {
  12690. struct intel_crtc_state *crtc_state =
  12691. to_intel_crtc_state(crtc->base.state);
  12692. if (crtc_state->base.active &&
  12693. crtc_state->shared_dpll == pll)
  12694. pll->state.crtc_mask |= 1 << crtc->pipe;
  12695. }
  12696. pll->active_mask = pll->state.crtc_mask;
  12697. DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n",
  12698. pll->info->name, pll->state.crtc_mask, pll->on);
  12699. }
  12700. for_each_intel_encoder(dev, encoder) {
  12701. pipe = 0;
  12702. if (encoder->get_hw_state(encoder, &pipe)) {
  12703. struct intel_crtc_state *crtc_state;
  12704. crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
  12705. crtc_state = to_intel_crtc_state(crtc->base.state);
  12706. encoder->base.crtc = &crtc->base;
  12707. encoder->get_config(encoder, crtc_state);
  12708. } else {
  12709. encoder->base.crtc = NULL;
  12710. }
  12711. DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
  12712. encoder->base.base.id, encoder->base.name,
  12713. enableddisabled(encoder->base.crtc),
  12714. pipe_name(pipe));
  12715. }
  12716. drm_connector_list_iter_begin(dev, &conn_iter);
  12717. for_each_intel_connector_iter(connector, &conn_iter) {
  12718. if (connector->get_hw_state(connector)) {
  12719. connector->base.dpms = DRM_MODE_DPMS_ON;
  12720. encoder = connector->encoder;
  12721. connector->base.encoder = &encoder->base;
  12722. if (encoder->base.crtc &&
  12723. encoder->base.crtc->state->active) {
  12724. /*
  12725. * This has to be done during hardware readout
  12726. * because anything calling .crtc_disable may
  12727. * rely on the connector_mask being accurate.
  12728. */
  12729. encoder->base.crtc->state->connector_mask |=
  12730. 1 << drm_connector_index(&connector->base);
  12731. encoder->base.crtc->state->encoder_mask |=
  12732. 1 << drm_encoder_index(&encoder->base);
  12733. }
  12734. } else {
  12735. connector->base.dpms = DRM_MODE_DPMS_OFF;
  12736. connector->base.encoder = NULL;
  12737. }
  12738. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
  12739. connector->base.base.id, connector->base.name,
  12740. enableddisabled(connector->base.encoder));
  12741. }
  12742. drm_connector_list_iter_end(&conn_iter);
  12743. for_each_intel_crtc(dev, crtc) {
  12744. struct intel_crtc_state *crtc_state =
  12745. to_intel_crtc_state(crtc->base.state);
  12746. int min_cdclk = 0;
  12747. memset(&crtc->base.mode, 0, sizeof(crtc->base.mode));
  12748. if (crtc_state->base.active) {
  12749. intel_mode_from_pipe_config(&crtc->base.mode, crtc_state);
  12750. intel_mode_from_pipe_config(&crtc_state->base.adjusted_mode, crtc_state);
  12751. WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode));
  12752. /*
  12753. * The initial mode needs to be set in order to keep
  12754. * the atomic core happy. It wants a valid mode if the
  12755. * crtc's enabled, so we do the above call.
  12756. *
  12757. * But we don't set all the derived state fully, hence
  12758. * set a flag to indicate that a full recalculation is
  12759. * needed on the next commit.
  12760. */
  12761. crtc_state->base.mode.private_flags = I915_MODE_FLAG_INHERITED;
  12762. intel_crtc_compute_pixel_rate(crtc_state);
  12763. if (dev_priv->display.modeset_calc_cdclk) {
  12764. min_cdclk = intel_crtc_compute_min_cdclk(crtc_state);
  12765. if (WARN_ON(min_cdclk < 0))
  12766. min_cdclk = 0;
  12767. }
  12768. drm_calc_timestamping_constants(&crtc->base,
  12769. &crtc_state->base.adjusted_mode);
  12770. update_scanline_offset(crtc);
  12771. }
  12772. dev_priv->min_cdclk[crtc->pipe] = min_cdclk;
  12773. dev_priv->min_voltage_level[crtc->pipe] =
  12774. crtc_state->min_voltage_level;
  12775. intel_pipe_config_sanity_check(dev_priv, crtc_state);
  12776. }
  12777. }
  12778. static void
  12779. get_encoder_power_domains(struct drm_i915_private *dev_priv)
  12780. {
  12781. struct intel_encoder *encoder;
  12782. for_each_intel_encoder(&dev_priv->drm, encoder) {
  12783. u64 get_domains;
  12784. enum intel_display_power_domain domain;
  12785. if (!encoder->get_power_domains)
  12786. continue;
  12787. get_domains = encoder->get_power_domains(encoder);
  12788. for_each_power_domain(domain, get_domains)
  12789. intel_display_power_get(dev_priv, domain);
  12790. }
  12791. }
  12792. static void intel_early_display_was(struct drm_i915_private *dev_priv)
  12793. {
  12794. /* Display WA #1185 WaDisableDARBFClkGating:cnl,glk */
  12795. if (IS_CANNONLAKE(dev_priv) || IS_GEMINILAKE(dev_priv))
  12796. I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) |
  12797. DARBF_GATING_DIS);
  12798. if (IS_HASWELL(dev_priv)) {
  12799. /*
  12800. * WaRsPkgCStateDisplayPMReq:hsw
  12801. * System hang if this isn't done before disabling all planes!
  12802. */
  12803. I915_WRITE(CHICKEN_PAR1_1,
  12804. I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES);
  12805. }
  12806. }
  12807. /* Scan out the current hw modeset state,
  12808. * and sanitizes it to the current state
  12809. */
  12810. static void
  12811. intel_modeset_setup_hw_state(struct drm_device *dev,
  12812. struct drm_modeset_acquire_ctx *ctx)
  12813. {
  12814. struct drm_i915_private *dev_priv = to_i915(dev);
  12815. enum pipe pipe;
  12816. struct intel_crtc *crtc;
  12817. struct intel_encoder *encoder;
  12818. int i;
  12819. intel_early_display_was(dev_priv);
  12820. intel_modeset_readout_hw_state(dev);
  12821. /* HW state is read out, now we need to sanitize this mess. */
  12822. get_encoder_power_domains(dev_priv);
  12823. intel_sanitize_plane_mapping(dev_priv);
  12824. for_each_intel_encoder(dev, encoder) {
  12825. intel_sanitize_encoder(encoder);
  12826. }
  12827. for_each_pipe(dev_priv, pipe) {
  12828. crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
  12829. intel_sanitize_crtc(crtc, ctx);
  12830. intel_dump_pipe_config(crtc, crtc->config,
  12831. "[setup_hw_state]");
  12832. }
  12833. intel_modeset_update_connector_atomic_state(dev);
  12834. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  12835. struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
  12836. if (!pll->on || pll->active_mask)
  12837. continue;
  12838. DRM_DEBUG_KMS("%s enabled but not in use, disabling\n",
  12839. pll->info->name);
  12840. pll->info->funcs->disable(dev_priv, pll);
  12841. pll->on = false;
  12842. }
  12843. if (IS_G4X(dev_priv)) {
  12844. g4x_wm_get_hw_state(dev);
  12845. g4x_wm_sanitize(dev_priv);
  12846. } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
  12847. vlv_wm_get_hw_state(dev);
  12848. vlv_wm_sanitize(dev_priv);
  12849. } else if (INTEL_GEN(dev_priv) >= 9) {
  12850. skl_wm_get_hw_state(dev);
  12851. } else if (HAS_PCH_SPLIT(dev_priv)) {
  12852. ilk_wm_get_hw_state(dev);
  12853. }
  12854. for_each_intel_crtc(dev, crtc) {
  12855. u64 put_domains;
  12856. put_domains = modeset_get_crtc_power_domains(&crtc->base, crtc->config);
  12857. if (WARN_ON(put_domains))
  12858. modeset_put_power_domains(dev_priv, put_domains);
  12859. }
  12860. intel_display_set_init_power(dev_priv, false);
  12861. intel_power_domains_verify_state(dev_priv);
  12862. intel_fbc_init_pipe_state(dev_priv);
  12863. }
  12864. void intel_display_resume(struct drm_device *dev)
  12865. {
  12866. struct drm_i915_private *dev_priv = to_i915(dev);
  12867. struct drm_atomic_state *state = dev_priv->modeset_restore_state;
  12868. struct drm_modeset_acquire_ctx ctx;
  12869. int ret;
  12870. dev_priv->modeset_restore_state = NULL;
  12871. if (state)
  12872. state->acquire_ctx = &ctx;
  12873. drm_modeset_acquire_init(&ctx, 0);
  12874. while (1) {
  12875. ret = drm_modeset_lock_all_ctx(dev, &ctx);
  12876. if (ret != -EDEADLK)
  12877. break;
  12878. drm_modeset_backoff(&ctx);
  12879. }
  12880. if (!ret)
  12881. ret = __intel_display_resume(dev, state, &ctx);
  12882. intel_enable_ipc(dev_priv);
  12883. drm_modeset_drop_locks(&ctx);
  12884. drm_modeset_acquire_fini(&ctx);
  12885. if (ret)
  12886. DRM_ERROR("Restoring old state failed with %i\n", ret);
  12887. if (state)
  12888. drm_atomic_state_put(state);
  12889. }
  12890. int intel_connector_register(struct drm_connector *connector)
  12891. {
  12892. struct intel_connector *intel_connector = to_intel_connector(connector);
  12893. int ret;
  12894. ret = intel_backlight_device_register(intel_connector);
  12895. if (ret)
  12896. goto err;
  12897. return 0;
  12898. err:
  12899. return ret;
  12900. }
  12901. void intel_connector_unregister(struct drm_connector *connector)
  12902. {
  12903. struct intel_connector *intel_connector = to_intel_connector(connector);
  12904. intel_backlight_device_unregister(intel_connector);
  12905. intel_panel_destroy_backlight(connector);
  12906. }
  12907. static void intel_hpd_poll_fini(struct drm_device *dev)
  12908. {
  12909. struct intel_connector *connector;
  12910. struct drm_connector_list_iter conn_iter;
  12911. /* Kill all the work that may have been queued by hpd. */
  12912. drm_connector_list_iter_begin(dev, &conn_iter);
  12913. for_each_intel_connector_iter(connector, &conn_iter) {
  12914. if (connector->modeset_retry_work.func)
  12915. cancel_work_sync(&connector->modeset_retry_work);
  12916. if (connector->hdcp_shim) {
  12917. cancel_delayed_work_sync(&connector->hdcp_check_work);
  12918. cancel_work_sync(&connector->hdcp_prop_work);
  12919. }
  12920. }
  12921. drm_connector_list_iter_end(&conn_iter);
  12922. }
  12923. void intel_modeset_cleanup(struct drm_device *dev)
  12924. {
  12925. struct drm_i915_private *dev_priv = to_i915(dev);
  12926. flush_work(&dev_priv->atomic_helper.free_work);
  12927. WARN_ON(!llist_empty(&dev_priv->atomic_helper.free_list));
  12928. intel_disable_gt_powersave(dev_priv);
  12929. /*
  12930. * Interrupts and polling as the first thing to avoid creating havoc.
  12931. * Too much stuff here (turning of connectors, ...) would
  12932. * experience fancy races otherwise.
  12933. */
  12934. intel_irq_uninstall(dev_priv);
  12935. /*
  12936. * Due to the hpd irq storm handling the hotplug work can re-arm the
  12937. * poll handlers. Hence disable polling after hpd handling is shut down.
  12938. */
  12939. intel_hpd_poll_fini(dev);
  12940. /* poll work can call into fbdev, hence clean that up afterwards */
  12941. intel_fbdev_fini(dev_priv);
  12942. intel_unregister_dsm_handler();
  12943. intel_fbc_global_disable(dev_priv);
  12944. /* flush any delayed tasks or pending work */
  12945. flush_scheduled_work();
  12946. drm_mode_config_cleanup(dev);
  12947. intel_cleanup_overlay(dev_priv);
  12948. intel_cleanup_gt_powersave(dev_priv);
  12949. intel_teardown_gmbus(dev_priv);
  12950. destroy_workqueue(dev_priv->modeset_wq);
  12951. }
  12952. void intel_connector_attach_encoder(struct intel_connector *connector,
  12953. struct intel_encoder *encoder)
  12954. {
  12955. connector->encoder = encoder;
  12956. drm_mode_connector_attach_encoder(&connector->base,
  12957. &encoder->base);
  12958. }
  12959. /*
  12960. * set vga decode state - true == enable VGA decode
  12961. */
  12962. int intel_modeset_vga_set_state(struct drm_i915_private *dev_priv, bool state)
  12963. {
  12964. unsigned reg = INTEL_GEN(dev_priv) >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL;
  12965. u16 gmch_ctrl;
  12966. if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) {
  12967. DRM_ERROR("failed to read control word\n");
  12968. return -EIO;
  12969. }
  12970. if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state)
  12971. return 0;
  12972. if (state)
  12973. gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
  12974. else
  12975. gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
  12976. if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) {
  12977. DRM_ERROR("failed to write control word\n");
  12978. return -EIO;
  12979. }
  12980. return 0;
  12981. }
  12982. #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
  12983. struct intel_display_error_state {
  12984. u32 power_well_driver;
  12985. int num_transcoders;
  12986. struct intel_cursor_error_state {
  12987. u32 control;
  12988. u32 position;
  12989. u32 base;
  12990. u32 size;
  12991. } cursor[I915_MAX_PIPES];
  12992. struct intel_pipe_error_state {
  12993. bool power_domain_on;
  12994. u32 source;
  12995. u32 stat;
  12996. } pipe[I915_MAX_PIPES];
  12997. struct intel_plane_error_state {
  12998. u32 control;
  12999. u32 stride;
  13000. u32 size;
  13001. u32 pos;
  13002. u32 addr;
  13003. u32 surface;
  13004. u32 tile_offset;
  13005. } plane[I915_MAX_PIPES];
  13006. struct intel_transcoder_error_state {
  13007. bool power_domain_on;
  13008. enum transcoder cpu_transcoder;
  13009. u32 conf;
  13010. u32 htotal;
  13011. u32 hblank;
  13012. u32 hsync;
  13013. u32 vtotal;
  13014. u32 vblank;
  13015. u32 vsync;
  13016. } transcoder[4];
  13017. };
  13018. struct intel_display_error_state *
  13019. intel_display_capture_error_state(struct drm_i915_private *dev_priv)
  13020. {
  13021. struct intel_display_error_state *error;
  13022. int transcoders[] = {
  13023. TRANSCODER_A,
  13024. TRANSCODER_B,
  13025. TRANSCODER_C,
  13026. TRANSCODER_EDP,
  13027. };
  13028. int i;
  13029. if (INTEL_INFO(dev_priv)->num_pipes == 0)
  13030. return NULL;
  13031. error = kzalloc(sizeof(*error), GFP_ATOMIC);
  13032. if (error == NULL)
  13033. return NULL;
  13034. if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
  13035. error->power_well_driver =
  13036. I915_READ(HSW_PWR_WELL_CTL_DRIVER(HSW_DISP_PW_GLOBAL));
  13037. for_each_pipe(dev_priv, i) {
  13038. error->pipe[i].power_domain_on =
  13039. __intel_display_power_is_enabled(dev_priv,
  13040. POWER_DOMAIN_PIPE(i));
  13041. if (!error->pipe[i].power_domain_on)
  13042. continue;
  13043. error->cursor[i].control = I915_READ(CURCNTR(i));
  13044. error->cursor[i].position = I915_READ(CURPOS(i));
  13045. error->cursor[i].base = I915_READ(CURBASE(i));
  13046. error->plane[i].control = I915_READ(DSPCNTR(i));
  13047. error->plane[i].stride = I915_READ(DSPSTRIDE(i));
  13048. if (INTEL_GEN(dev_priv) <= 3) {
  13049. error->plane[i].size = I915_READ(DSPSIZE(i));
  13050. error->plane[i].pos = I915_READ(DSPPOS(i));
  13051. }
  13052. if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
  13053. error->plane[i].addr = I915_READ(DSPADDR(i));
  13054. if (INTEL_GEN(dev_priv) >= 4) {
  13055. error->plane[i].surface = I915_READ(DSPSURF(i));
  13056. error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
  13057. }
  13058. error->pipe[i].source = I915_READ(PIPESRC(i));
  13059. if (HAS_GMCH_DISPLAY(dev_priv))
  13060. error->pipe[i].stat = I915_READ(PIPESTAT(i));
  13061. }
  13062. /* Note: this does not include DSI transcoders. */
  13063. error->num_transcoders = INTEL_INFO(dev_priv)->num_pipes;
  13064. if (HAS_DDI(dev_priv))
  13065. error->num_transcoders++; /* Account for eDP. */
  13066. for (i = 0; i < error->num_transcoders; i++) {
  13067. enum transcoder cpu_transcoder = transcoders[i];
  13068. error->transcoder[i].power_domain_on =
  13069. __intel_display_power_is_enabled(dev_priv,
  13070. POWER_DOMAIN_TRANSCODER(cpu_transcoder));
  13071. if (!error->transcoder[i].power_domain_on)
  13072. continue;
  13073. error->transcoder[i].cpu_transcoder = cpu_transcoder;
  13074. error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder));
  13075. error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder));
  13076. error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder));
  13077. error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder));
  13078. error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder));
  13079. error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder));
  13080. error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder));
  13081. }
  13082. return error;
  13083. }
  13084. #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
  13085. void
  13086. intel_display_print_error_state(struct drm_i915_error_state_buf *m,
  13087. struct intel_display_error_state *error)
  13088. {
  13089. struct drm_i915_private *dev_priv = m->i915;
  13090. int i;
  13091. if (!error)
  13092. return;
  13093. err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev_priv)->num_pipes);
  13094. if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
  13095. err_printf(m, "PWR_WELL_CTL2: %08x\n",
  13096. error->power_well_driver);
  13097. for_each_pipe(dev_priv, i) {
  13098. err_printf(m, "Pipe [%d]:\n", i);
  13099. err_printf(m, " Power: %s\n",
  13100. onoff(error->pipe[i].power_domain_on));
  13101. err_printf(m, " SRC: %08x\n", error->pipe[i].source);
  13102. err_printf(m, " STAT: %08x\n", error->pipe[i].stat);
  13103. err_printf(m, "Plane [%d]:\n", i);
  13104. err_printf(m, " CNTR: %08x\n", error->plane[i].control);
  13105. err_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
  13106. if (INTEL_GEN(dev_priv) <= 3) {
  13107. err_printf(m, " SIZE: %08x\n", error->plane[i].size);
  13108. err_printf(m, " POS: %08x\n", error->plane[i].pos);
  13109. }
  13110. if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
  13111. err_printf(m, " ADDR: %08x\n", error->plane[i].addr);
  13112. if (INTEL_GEN(dev_priv) >= 4) {
  13113. err_printf(m, " SURF: %08x\n", error->plane[i].surface);
  13114. err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
  13115. }
  13116. err_printf(m, "Cursor [%d]:\n", i);
  13117. err_printf(m, " CNTR: %08x\n", error->cursor[i].control);
  13118. err_printf(m, " POS: %08x\n", error->cursor[i].position);
  13119. err_printf(m, " BASE: %08x\n", error->cursor[i].base);
  13120. }
  13121. for (i = 0; i < error->num_transcoders; i++) {
  13122. err_printf(m, "CPU transcoder: %s\n",
  13123. transcoder_name(error->transcoder[i].cpu_transcoder));
  13124. err_printf(m, " Power: %s\n",
  13125. onoff(error->transcoder[i].power_domain_on));
  13126. err_printf(m, " CONF: %08x\n", error->transcoder[i].conf);
  13127. err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal);
  13128. err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank);
  13129. err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync);
  13130. err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal);
  13131. err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank);
  13132. err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync);
  13133. }
  13134. }
  13135. #endif