intel_display.c 365 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268
  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 <drm/i915_drm.h>
  37. #include "i915_drv.h"
  38. #include "i915_trace.h"
  39. #include <drm/drm_dp_helper.h>
  40. #include <drm/drm_crtc_helper.h>
  41. #include <drm/drm_plane_helper.h>
  42. #include <drm/drm_rect.h>
  43. #include <linux/dma_remapping.h>
  44. /* Primary plane formats supported by all gen */
  45. #define COMMON_PRIMARY_FORMATS \
  46. DRM_FORMAT_C8, \
  47. DRM_FORMAT_RGB565, \
  48. DRM_FORMAT_XRGB8888, \
  49. DRM_FORMAT_ARGB8888
  50. /* Primary plane formats for gen <= 3 */
  51. static const uint32_t intel_primary_formats_gen2[] = {
  52. COMMON_PRIMARY_FORMATS,
  53. DRM_FORMAT_XRGB1555,
  54. DRM_FORMAT_ARGB1555,
  55. };
  56. /* Primary plane formats for gen >= 4 */
  57. static const uint32_t intel_primary_formats_gen4[] = {
  58. COMMON_PRIMARY_FORMATS, \
  59. DRM_FORMAT_XBGR8888,
  60. DRM_FORMAT_ABGR8888,
  61. DRM_FORMAT_XRGB2101010,
  62. DRM_FORMAT_ARGB2101010,
  63. DRM_FORMAT_XBGR2101010,
  64. DRM_FORMAT_ABGR2101010,
  65. };
  66. /* Cursor formats */
  67. static const uint32_t intel_cursor_formats[] = {
  68. DRM_FORMAT_ARGB8888,
  69. };
  70. #define DIV_ROUND_CLOSEST_ULL(ll, d) \
  71. ({ unsigned long long _tmp = (ll)+(d)/2; do_div(_tmp, d); _tmp; })
  72. static void intel_increase_pllclock(struct drm_device *dev,
  73. enum pipe pipe);
  74. static void intel_crtc_update_cursor(struct drm_crtc *crtc, bool on);
  75. static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
  76. struct intel_crtc_config *pipe_config);
  77. static void ironlake_pch_clock_get(struct intel_crtc *crtc,
  78. struct intel_crtc_config *pipe_config);
  79. static int intel_set_mode(struct drm_crtc *crtc, struct drm_display_mode *mode,
  80. int x, int y, struct drm_framebuffer *old_fb);
  81. static int intel_framebuffer_init(struct drm_device *dev,
  82. struct intel_framebuffer *ifb,
  83. struct drm_mode_fb_cmd2 *mode_cmd,
  84. struct drm_i915_gem_object *obj);
  85. static void intel_dp_set_m_n(struct intel_crtc *crtc);
  86. static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc);
  87. static void intel_set_pipe_timings(struct intel_crtc *intel_crtc);
  88. static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc,
  89. struct intel_link_m_n *m_n);
  90. static void ironlake_set_pipeconf(struct drm_crtc *crtc);
  91. static void haswell_set_pipeconf(struct drm_crtc *crtc);
  92. static void intel_set_pipe_csc(struct drm_crtc *crtc);
  93. static void vlv_prepare_pll(struct intel_crtc *crtc);
  94. typedef struct {
  95. int min, max;
  96. } intel_range_t;
  97. typedef struct {
  98. int dot_limit;
  99. int p2_slow, p2_fast;
  100. } intel_p2_t;
  101. typedef struct intel_limit intel_limit_t;
  102. struct intel_limit {
  103. intel_range_t dot, vco, n, m, m1, m2, p, p1;
  104. intel_p2_t p2;
  105. };
  106. int
  107. intel_pch_rawclk(struct drm_device *dev)
  108. {
  109. struct drm_i915_private *dev_priv = dev->dev_private;
  110. WARN_ON(!HAS_PCH_SPLIT(dev));
  111. return I915_READ(PCH_RAWCLK_FREQ) & RAWCLK_FREQ_MASK;
  112. }
  113. static inline u32 /* units of 100MHz */
  114. intel_fdi_link_freq(struct drm_device *dev)
  115. {
  116. if (IS_GEN5(dev)) {
  117. struct drm_i915_private *dev_priv = dev->dev_private;
  118. return (I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK) + 2;
  119. } else
  120. return 27;
  121. }
  122. static const intel_limit_t intel_limits_i8xx_dac = {
  123. .dot = { .min = 25000, .max = 350000 },
  124. .vco = { .min = 908000, .max = 1512000 },
  125. .n = { .min = 2, .max = 16 },
  126. .m = { .min = 96, .max = 140 },
  127. .m1 = { .min = 18, .max = 26 },
  128. .m2 = { .min = 6, .max = 16 },
  129. .p = { .min = 4, .max = 128 },
  130. .p1 = { .min = 2, .max = 33 },
  131. .p2 = { .dot_limit = 165000,
  132. .p2_slow = 4, .p2_fast = 2 },
  133. };
  134. static const intel_limit_t intel_limits_i8xx_dvo = {
  135. .dot = { .min = 25000, .max = 350000 },
  136. .vco = { .min = 908000, .max = 1512000 },
  137. .n = { .min = 2, .max = 16 },
  138. .m = { .min = 96, .max = 140 },
  139. .m1 = { .min = 18, .max = 26 },
  140. .m2 = { .min = 6, .max = 16 },
  141. .p = { .min = 4, .max = 128 },
  142. .p1 = { .min = 2, .max = 33 },
  143. .p2 = { .dot_limit = 165000,
  144. .p2_slow = 4, .p2_fast = 4 },
  145. };
  146. static const intel_limit_t intel_limits_i8xx_lvds = {
  147. .dot = { .min = 25000, .max = 350000 },
  148. .vco = { .min = 908000, .max = 1512000 },
  149. .n = { .min = 2, .max = 16 },
  150. .m = { .min = 96, .max = 140 },
  151. .m1 = { .min = 18, .max = 26 },
  152. .m2 = { .min = 6, .max = 16 },
  153. .p = { .min = 4, .max = 128 },
  154. .p1 = { .min = 1, .max = 6 },
  155. .p2 = { .dot_limit = 165000,
  156. .p2_slow = 14, .p2_fast = 7 },
  157. };
  158. static const intel_limit_t intel_limits_i9xx_sdvo = {
  159. .dot = { .min = 20000, .max = 400000 },
  160. .vco = { .min = 1400000, .max = 2800000 },
  161. .n = { .min = 1, .max = 6 },
  162. .m = { .min = 70, .max = 120 },
  163. .m1 = { .min = 8, .max = 18 },
  164. .m2 = { .min = 3, .max = 7 },
  165. .p = { .min = 5, .max = 80 },
  166. .p1 = { .min = 1, .max = 8 },
  167. .p2 = { .dot_limit = 200000,
  168. .p2_slow = 10, .p2_fast = 5 },
  169. };
  170. static const intel_limit_t intel_limits_i9xx_lvds = {
  171. .dot = { .min = 20000, .max = 400000 },
  172. .vco = { .min = 1400000, .max = 2800000 },
  173. .n = { .min = 1, .max = 6 },
  174. .m = { .min = 70, .max = 120 },
  175. .m1 = { .min = 8, .max = 18 },
  176. .m2 = { .min = 3, .max = 7 },
  177. .p = { .min = 7, .max = 98 },
  178. .p1 = { .min = 1, .max = 8 },
  179. .p2 = { .dot_limit = 112000,
  180. .p2_slow = 14, .p2_fast = 7 },
  181. };
  182. static const intel_limit_t intel_limits_g4x_sdvo = {
  183. .dot = { .min = 25000, .max = 270000 },
  184. .vco = { .min = 1750000, .max = 3500000},
  185. .n = { .min = 1, .max = 4 },
  186. .m = { .min = 104, .max = 138 },
  187. .m1 = { .min = 17, .max = 23 },
  188. .m2 = { .min = 5, .max = 11 },
  189. .p = { .min = 10, .max = 30 },
  190. .p1 = { .min = 1, .max = 3},
  191. .p2 = { .dot_limit = 270000,
  192. .p2_slow = 10,
  193. .p2_fast = 10
  194. },
  195. };
  196. static const intel_limit_t intel_limits_g4x_hdmi = {
  197. .dot = { .min = 22000, .max = 400000 },
  198. .vco = { .min = 1750000, .max = 3500000},
  199. .n = { .min = 1, .max = 4 },
  200. .m = { .min = 104, .max = 138 },
  201. .m1 = { .min = 16, .max = 23 },
  202. .m2 = { .min = 5, .max = 11 },
  203. .p = { .min = 5, .max = 80 },
  204. .p1 = { .min = 1, .max = 8},
  205. .p2 = { .dot_limit = 165000,
  206. .p2_slow = 10, .p2_fast = 5 },
  207. };
  208. static const intel_limit_t intel_limits_g4x_single_channel_lvds = {
  209. .dot = { .min = 20000, .max = 115000 },
  210. .vco = { .min = 1750000, .max = 3500000 },
  211. .n = { .min = 1, .max = 3 },
  212. .m = { .min = 104, .max = 138 },
  213. .m1 = { .min = 17, .max = 23 },
  214. .m2 = { .min = 5, .max = 11 },
  215. .p = { .min = 28, .max = 112 },
  216. .p1 = { .min = 2, .max = 8 },
  217. .p2 = { .dot_limit = 0,
  218. .p2_slow = 14, .p2_fast = 14
  219. },
  220. };
  221. static const intel_limit_t intel_limits_g4x_dual_channel_lvds = {
  222. .dot = { .min = 80000, .max = 224000 },
  223. .vco = { .min = 1750000, .max = 3500000 },
  224. .n = { .min = 1, .max = 3 },
  225. .m = { .min = 104, .max = 138 },
  226. .m1 = { .min = 17, .max = 23 },
  227. .m2 = { .min = 5, .max = 11 },
  228. .p = { .min = 14, .max = 42 },
  229. .p1 = { .min = 2, .max = 6 },
  230. .p2 = { .dot_limit = 0,
  231. .p2_slow = 7, .p2_fast = 7
  232. },
  233. };
  234. static const intel_limit_t intel_limits_pineview_sdvo = {
  235. .dot = { .min = 20000, .max = 400000},
  236. .vco = { .min = 1700000, .max = 3500000 },
  237. /* Pineview's Ncounter is a ring counter */
  238. .n = { .min = 3, .max = 6 },
  239. .m = { .min = 2, .max = 256 },
  240. /* Pineview only has one combined m divider, which we treat as m2. */
  241. .m1 = { .min = 0, .max = 0 },
  242. .m2 = { .min = 0, .max = 254 },
  243. .p = { .min = 5, .max = 80 },
  244. .p1 = { .min = 1, .max = 8 },
  245. .p2 = { .dot_limit = 200000,
  246. .p2_slow = 10, .p2_fast = 5 },
  247. };
  248. static const intel_limit_t intel_limits_pineview_lvds = {
  249. .dot = { .min = 20000, .max = 400000 },
  250. .vco = { .min = 1700000, .max = 3500000 },
  251. .n = { .min = 3, .max = 6 },
  252. .m = { .min = 2, .max = 256 },
  253. .m1 = { .min = 0, .max = 0 },
  254. .m2 = { .min = 0, .max = 254 },
  255. .p = { .min = 7, .max = 112 },
  256. .p1 = { .min = 1, .max = 8 },
  257. .p2 = { .dot_limit = 112000,
  258. .p2_slow = 14, .p2_fast = 14 },
  259. };
  260. /* Ironlake / Sandybridge
  261. *
  262. * We calculate clock using (register_value + 2) for N/M1/M2, so here
  263. * the range value for them is (actual_value - 2).
  264. */
  265. static const intel_limit_t intel_limits_ironlake_dac = {
  266. .dot = { .min = 25000, .max = 350000 },
  267. .vco = { .min = 1760000, .max = 3510000 },
  268. .n = { .min = 1, .max = 5 },
  269. .m = { .min = 79, .max = 127 },
  270. .m1 = { .min = 12, .max = 22 },
  271. .m2 = { .min = 5, .max = 9 },
  272. .p = { .min = 5, .max = 80 },
  273. .p1 = { .min = 1, .max = 8 },
  274. .p2 = { .dot_limit = 225000,
  275. .p2_slow = 10, .p2_fast = 5 },
  276. };
  277. static const intel_limit_t intel_limits_ironlake_single_lvds = {
  278. .dot = { .min = 25000, .max = 350000 },
  279. .vco = { .min = 1760000, .max = 3510000 },
  280. .n = { .min = 1, .max = 3 },
  281. .m = { .min = 79, .max = 118 },
  282. .m1 = { .min = 12, .max = 22 },
  283. .m2 = { .min = 5, .max = 9 },
  284. .p = { .min = 28, .max = 112 },
  285. .p1 = { .min = 2, .max = 8 },
  286. .p2 = { .dot_limit = 225000,
  287. .p2_slow = 14, .p2_fast = 14 },
  288. };
  289. static const intel_limit_t intel_limits_ironlake_dual_lvds = {
  290. .dot = { .min = 25000, .max = 350000 },
  291. .vco = { .min = 1760000, .max = 3510000 },
  292. .n = { .min = 1, .max = 3 },
  293. .m = { .min = 79, .max = 127 },
  294. .m1 = { .min = 12, .max = 22 },
  295. .m2 = { .min = 5, .max = 9 },
  296. .p = { .min = 14, .max = 56 },
  297. .p1 = { .min = 2, .max = 8 },
  298. .p2 = { .dot_limit = 225000,
  299. .p2_slow = 7, .p2_fast = 7 },
  300. };
  301. /* LVDS 100mhz refclk limits. */
  302. static const intel_limit_t intel_limits_ironlake_single_lvds_100m = {
  303. .dot = { .min = 25000, .max = 350000 },
  304. .vco = { .min = 1760000, .max = 3510000 },
  305. .n = { .min = 1, .max = 2 },
  306. .m = { .min = 79, .max = 126 },
  307. .m1 = { .min = 12, .max = 22 },
  308. .m2 = { .min = 5, .max = 9 },
  309. .p = { .min = 28, .max = 112 },
  310. .p1 = { .min = 2, .max = 8 },
  311. .p2 = { .dot_limit = 225000,
  312. .p2_slow = 14, .p2_fast = 14 },
  313. };
  314. static const intel_limit_t intel_limits_ironlake_dual_lvds_100m = {
  315. .dot = { .min = 25000, .max = 350000 },
  316. .vco = { .min = 1760000, .max = 3510000 },
  317. .n = { .min = 1, .max = 3 },
  318. .m = { .min = 79, .max = 126 },
  319. .m1 = { .min = 12, .max = 22 },
  320. .m2 = { .min = 5, .max = 9 },
  321. .p = { .min = 14, .max = 42 },
  322. .p1 = { .min = 2, .max = 6 },
  323. .p2 = { .dot_limit = 225000,
  324. .p2_slow = 7, .p2_fast = 7 },
  325. };
  326. static const intel_limit_t intel_limits_vlv = {
  327. /*
  328. * These are the data rate limits (measured in fast clocks)
  329. * since those are the strictest limits we have. The fast
  330. * clock and actual rate limits are more relaxed, so checking
  331. * them would make no difference.
  332. */
  333. .dot = { .min = 25000 * 5, .max = 270000 * 5 },
  334. .vco = { .min = 4000000, .max = 6000000 },
  335. .n = { .min = 1, .max = 7 },
  336. .m1 = { .min = 2, .max = 3 },
  337. .m2 = { .min = 11, .max = 156 },
  338. .p1 = { .min = 2, .max = 3 },
  339. .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */
  340. };
  341. static const intel_limit_t intel_limits_chv = {
  342. /*
  343. * These are the data rate limits (measured in fast clocks)
  344. * since those are the strictest limits we have. The fast
  345. * clock and actual rate limits are more relaxed, so checking
  346. * them would make no difference.
  347. */
  348. .dot = { .min = 25000 * 5, .max = 540000 * 5},
  349. .vco = { .min = 4860000, .max = 6700000 },
  350. .n = { .min = 1, .max = 1 },
  351. .m1 = { .min = 2, .max = 2 },
  352. .m2 = { .min = 24 << 22, .max = 175 << 22 },
  353. .p1 = { .min = 2, .max = 4 },
  354. .p2 = { .p2_slow = 1, .p2_fast = 14 },
  355. };
  356. static void vlv_clock(int refclk, intel_clock_t *clock)
  357. {
  358. clock->m = clock->m1 * clock->m2;
  359. clock->p = clock->p1 * clock->p2;
  360. if (WARN_ON(clock->n == 0 || clock->p == 0))
  361. return;
  362. clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
  363. clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
  364. }
  365. /**
  366. * Returns whether any output on the specified pipe is of the specified type
  367. */
  368. static bool intel_pipe_has_type(struct drm_crtc *crtc, int type)
  369. {
  370. struct drm_device *dev = crtc->dev;
  371. struct intel_encoder *encoder;
  372. for_each_encoder_on_crtc(dev, crtc, encoder)
  373. if (encoder->type == type)
  374. return true;
  375. return false;
  376. }
  377. static const intel_limit_t *intel_ironlake_limit(struct drm_crtc *crtc,
  378. int refclk)
  379. {
  380. struct drm_device *dev = crtc->dev;
  381. const intel_limit_t *limit;
  382. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  383. if (intel_is_dual_link_lvds(dev)) {
  384. if (refclk == 100000)
  385. limit = &intel_limits_ironlake_dual_lvds_100m;
  386. else
  387. limit = &intel_limits_ironlake_dual_lvds;
  388. } else {
  389. if (refclk == 100000)
  390. limit = &intel_limits_ironlake_single_lvds_100m;
  391. else
  392. limit = &intel_limits_ironlake_single_lvds;
  393. }
  394. } else
  395. limit = &intel_limits_ironlake_dac;
  396. return limit;
  397. }
  398. static const intel_limit_t *intel_g4x_limit(struct drm_crtc *crtc)
  399. {
  400. struct drm_device *dev = crtc->dev;
  401. const intel_limit_t *limit;
  402. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  403. if (intel_is_dual_link_lvds(dev))
  404. limit = &intel_limits_g4x_dual_channel_lvds;
  405. else
  406. limit = &intel_limits_g4x_single_channel_lvds;
  407. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI) ||
  408. intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) {
  409. limit = &intel_limits_g4x_hdmi;
  410. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO)) {
  411. limit = &intel_limits_g4x_sdvo;
  412. } else /* The option is for other outputs */
  413. limit = &intel_limits_i9xx_sdvo;
  414. return limit;
  415. }
  416. static const intel_limit_t *intel_limit(struct drm_crtc *crtc, int refclk)
  417. {
  418. struct drm_device *dev = crtc->dev;
  419. const intel_limit_t *limit;
  420. if (HAS_PCH_SPLIT(dev))
  421. limit = intel_ironlake_limit(crtc, refclk);
  422. else if (IS_G4X(dev)) {
  423. limit = intel_g4x_limit(crtc);
  424. } else if (IS_PINEVIEW(dev)) {
  425. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  426. limit = &intel_limits_pineview_lvds;
  427. else
  428. limit = &intel_limits_pineview_sdvo;
  429. } else if (IS_CHERRYVIEW(dev)) {
  430. limit = &intel_limits_chv;
  431. } else if (IS_VALLEYVIEW(dev)) {
  432. limit = &intel_limits_vlv;
  433. } else if (!IS_GEN2(dev)) {
  434. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  435. limit = &intel_limits_i9xx_lvds;
  436. else
  437. limit = &intel_limits_i9xx_sdvo;
  438. } else {
  439. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  440. limit = &intel_limits_i8xx_lvds;
  441. else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO))
  442. limit = &intel_limits_i8xx_dvo;
  443. else
  444. limit = &intel_limits_i8xx_dac;
  445. }
  446. return limit;
  447. }
  448. /* m1 is reserved as 0 in Pineview, n is a ring counter */
  449. static void pineview_clock(int refclk, intel_clock_t *clock)
  450. {
  451. clock->m = clock->m2 + 2;
  452. clock->p = clock->p1 * clock->p2;
  453. if (WARN_ON(clock->n == 0 || clock->p == 0))
  454. return;
  455. clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
  456. clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
  457. }
  458. static uint32_t i9xx_dpll_compute_m(struct dpll *dpll)
  459. {
  460. return 5 * (dpll->m1 + 2) + (dpll->m2 + 2);
  461. }
  462. static void i9xx_clock(int refclk, intel_clock_t *clock)
  463. {
  464. clock->m = i9xx_dpll_compute_m(clock);
  465. clock->p = clock->p1 * clock->p2;
  466. if (WARN_ON(clock->n + 2 == 0 || clock->p == 0))
  467. return;
  468. clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2);
  469. clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
  470. }
  471. static void chv_clock(int refclk, intel_clock_t *clock)
  472. {
  473. clock->m = clock->m1 * clock->m2;
  474. clock->p = clock->p1 * clock->p2;
  475. if (WARN_ON(clock->n == 0 || clock->p == 0))
  476. return;
  477. clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m,
  478. clock->n << 22);
  479. clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
  480. }
  481. #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
  482. /**
  483. * Returns whether the given set of divisors are valid for a given refclk with
  484. * the given connectors.
  485. */
  486. static bool intel_PLL_is_valid(struct drm_device *dev,
  487. const intel_limit_t *limit,
  488. const intel_clock_t *clock)
  489. {
  490. if (clock->n < limit->n.min || limit->n.max < clock->n)
  491. INTELPllInvalid("n out of range\n");
  492. if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
  493. INTELPllInvalid("p1 out of range\n");
  494. if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
  495. INTELPllInvalid("m2 out of range\n");
  496. if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
  497. INTELPllInvalid("m1 out of range\n");
  498. if (!IS_PINEVIEW(dev) && !IS_VALLEYVIEW(dev))
  499. if (clock->m1 <= clock->m2)
  500. INTELPllInvalid("m1 <= m2\n");
  501. if (!IS_VALLEYVIEW(dev)) {
  502. if (clock->p < limit->p.min || limit->p.max < clock->p)
  503. INTELPllInvalid("p out of range\n");
  504. if (clock->m < limit->m.min || limit->m.max < clock->m)
  505. INTELPllInvalid("m out of range\n");
  506. }
  507. if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
  508. INTELPllInvalid("vco out of range\n");
  509. /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
  510. * connector, etc., rather than just a single range.
  511. */
  512. if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
  513. INTELPllInvalid("dot out of range\n");
  514. return true;
  515. }
  516. static bool
  517. i9xx_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc,
  518. int target, int refclk, intel_clock_t *match_clock,
  519. intel_clock_t *best_clock)
  520. {
  521. struct drm_device *dev = crtc->dev;
  522. intel_clock_t clock;
  523. int err = target;
  524. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  525. /*
  526. * For LVDS just rely on its current settings for dual-channel.
  527. * We haven't figured out how to reliably set up different
  528. * single/dual channel state, if we even can.
  529. */
  530. if (intel_is_dual_link_lvds(dev))
  531. clock.p2 = limit->p2.p2_fast;
  532. else
  533. clock.p2 = limit->p2.p2_slow;
  534. } else {
  535. if (target < limit->p2.dot_limit)
  536. clock.p2 = limit->p2.p2_slow;
  537. else
  538. clock.p2 = limit->p2.p2_fast;
  539. }
  540. memset(best_clock, 0, sizeof(*best_clock));
  541. for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
  542. clock.m1++) {
  543. for (clock.m2 = limit->m2.min;
  544. clock.m2 <= limit->m2.max; clock.m2++) {
  545. if (clock.m2 >= clock.m1)
  546. break;
  547. for (clock.n = limit->n.min;
  548. clock.n <= limit->n.max; clock.n++) {
  549. for (clock.p1 = limit->p1.min;
  550. clock.p1 <= limit->p1.max; clock.p1++) {
  551. int this_err;
  552. i9xx_clock(refclk, &clock);
  553. if (!intel_PLL_is_valid(dev, limit,
  554. &clock))
  555. continue;
  556. if (match_clock &&
  557. clock.p != match_clock->p)
  558. continue;
  559. this_err = abs(clock.dot - target);
  560. if (this_err < err) {
  561. *best_clock = clock;
  562. err = this_err;
  563. }
  564. }
  565. }
  566. }
  567. }
  568. return (err != target);
  569. }
  570. static bool
  571. pnv_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc,
  572. int target, int refclk, intel_clock_t *match_clock,
  573. intel_clock_t *best_clock)
  574. {
  575. struct drm_device *dev = crtc->dev;
  576. intel_clock_t clock;
  577. int err = target;
  578. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  579. /*
  580. * For LVDS just rely on its current settings for dual-channel.
  581. * We haven't figured out how to reliably set up different
  582. * single/dual channel state, if we even can.
  583. */
  584. if (intel_is_dual_link_lvds(dev))
  585. clock.p2 = limit->p2.p2_fast;
  586. else
  587. clock.p2 = limit->p2.p2_slow;
  588. } else {
  589. if (target < limit->p2.dot_limit)
  590. clock.p2 = limit->p2.p2_slow;
  591. else
  592. clock.p2 = limit->p2.p2_fast;
  593. }
  594. memset(best_clock, 0, sizeof(*best_clock));
  595. for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
  596. clock.m1++) {
  597. for (clock.m2 = limit->m2.min;
  598. clock.m2 <= limit->m2.max; clock.m2++) {
  599. for (clock.n = limit->n.min;
  600. clock.n <= limit->n.max; clock.n++) {
  601. for (clock.p1 = limit->p1.min;
  602. clock.p1 <= limit->p1.max; clock.p1++) {
  603. int this_err;
  604. pineview_clock(refclk, &clock);
  605. if (!intel_PLL_is_valid(dev, limit,
  606. &clock))
  607. continue;
  608. if (match_clock &&
  609. clock.p != match_clock->p)
  610. continue;
  611. this_err = abs(clock.dot - target);
  612. if (this_err < err) {
  613. *best_clock = clock;
  614. err = this_err;
  615. }
  616. }
  617. }
  618. }
  619. }
  620. return (err != target);
  621. }
  622. static bool
  623. g4x_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc,
  624. int target, int refclk, intel_clock_t *match_clock,
  625. intel_clock_t *best_clock)
  626. {
  627. struct drm_device *dev = crtc->dev;
  628. intel_clock_t clock;
  629. int max_n;
  630. bool found;
  631. /* approximately equals target * 0.00585 */
  632. int err_most = (target >> 8) + (target >> 9);
  633. found = false;
  634. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  635. if (intel_is_dual_link_lvds(dev))
  636. clock.p2 = limit->p2.p2_fast;
  637. else
  638. clock.p2 = limit->p2.p2_slow;
  639. } else {
  640. if (target < limit->p2.dot_limit)
  641. clock.p2 = limit->p2.p2_slow;
  642. else
  643. clock.p2 = limit->p2.p2_fast;
  644. }
  645. memset(best_clock, 0, sizeof(*best_clock));
  646. max_n = limit->n.max;
  647. /* based on hardware requirement, prefer smaller n to precision */
  648. for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
  649. /* based on hardware requirement, prefere larger m1,m2 */
  650. for (clock.m1 = limit->m1.max;
  651. clock.m1 >= limit->m1.min; clock.m1--) {
  652. for (clock.m2 = limit->m2.max;
  653. clock.m2 >= limit->m2.min; clock.m2--) {
  654. for (clock.p1 = limit->p1.max;
  655. clock.p1 >= limit->p1.min; clock.p1--) {
  656. int this_err;
  657. i9xx_clock(refclk, &clock);
  658. if (!intel_PLL_is_valid(dev, limit,
  659. &clock))
  660. continue;
  661. this_err = abs(clock.dot - target);
  662. if (this_err < err_most) {
  663. *best_clock = clock;
  664. err_most = this_err;
  665. max_n = clock.n;
  666. found = true;
  667. }
  668. }
  669. }
  670. }
  671. }
  672. return found;
  673. }
  674. static bool
  675. vlv_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc,
  676. int target, int refclk, intel_clock_t *match_clock,
  677. intel_clock_t *best_clock)
  678. {
  679. struct drm_device *dev = crtc->dev;
  680. intel_clock_t clock;
  681. unsigned int bestppm = 1000000;
  682. /* min update 19.2 MHz */
  683. int max_n = min(limit->n.max, refclk / 19200);
  684. bool found = false;
  685. target *= 5; /* fast clock */
  686. memset(best_clock, 0, sizeof(*best_clock));
  687. /* based on hardware requirement, prefer smaller n to precision */
  688. for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
  689. for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
  690. for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow;
  691. clock.p2 -= clock.p2 > 10 ? 2 : 1) {
  692. clock.p = clock.p1 * clock.p2;
  693. /* based on hardware requirement, prefer bigger m1,m2 values */
  694. for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) {
  695. unsigned int ppm, diff;
  696. clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n,
  697. refclk * clock.m1);
  698. vlv_clock(refclk, &clock);
  699. if (!intel_PLL_is_valid(dev, limit,
  700. &clock))
  701. continue;
  702. diff = abs(clock.dot - target);
  703. ppm = div_u64(1000000ULL * diff, target);
  704. if (ppm < 100 && clock.p > best_clock->p) {
  705. bestppm = 0;
  706. *best_clock = clock;
  707. found = true;
  708. }
  709. if (bestppm >= 10 && ppm < bestppm - 10) {
  710. bestppm = ppm;
  711. *best_clock = clock;
  712. found = true;
  713. }
  714. }
  715. }
  716. }
  717. }
  718. return found;
  719. }
  720. static bool
  721. chv_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc,
  722. int target, int refclk, intel_clock_t *match_clock,
  723. intel_clock_t *best_clock)
  724. {
  725. struct drm_device *dev = crtc->dev;
  726. intel_clock_t clock;
  727. uint64_t m2;
  728. int found = false;
  729. memset(best_clock, 0, sizeof(*best_clock));
  730. /*
  731. * Based on hardware doc, the n always set to 1, and m1 always
  732. * set to 2. If requires to support 200Mhz refclk, we need to
  733. * revisit this because n may not 1 anymore.
  734. */
  735. clock.n = 1, clock.m1 = 2;
  736. target *= 5; /* fast clock */
  737. for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
  738. for (clock.p2 = limit->p2.p2_fast;
  739. clock.p2 >= limit->p2.p2_slow;
  740. clock.p2 -= clock.p2 > 10 ? 2 : 1) {
  741. clock.p = clock.p1 * clock.p2;
  742. m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p *
  743. clock.n) << 22, refclk * clock.m1);
  744. if (m2 > INT_MAX/clock.m1)
  745. continue;
  746. clock.m2 = m2;
  747. chv_clock(refclk, &clock);
  748. if (!intel_PLL_is_valid(dev, limit, &clock))
  749. continue;
  750. /* based on hardware requirement, prefer bigger p
  751. */
  752. if (clock.p > best_clock->p) {
  753. *best_clock = clock;
  754. found = true;
  755. }
  756. }
  757. }
  758. return found;
  759. }
  760. bool intel_crtc_active(struct drm_crtc *crtc)
  761. {
  762. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  763. /* Be paranoid as we can arrive here with only partial
  764. * state retrieved from the hardware during setup.
  765. *
  766. * We can ditch the adjusted_mode.crtc_clock check as soon
  767. * as Haswell has gained clock readout/fastboot support.
  768. *
  769. * We can ditch the crtc->primary->fb check as soon as we can
  770. * properly reconstruct framebuffers.
  771. */
  772. return intel_crtc->active && crtc->primary->fb &&
  773. intel_crtc->config.adjusted_mode.crtc_clock;
  774. }
  775. enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv,
  776. enum pipe pipe)
  777. {
  778. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  779. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  780. return intel_crtc->config.cpu_transcoder;
  781. }
  782. static void g4x_wait_for_vblank(struct drm_device *dev, int pipe)
  783. {
  784. struct drm_i915_private *dev_priv = dev->dev_private;
  785. u32 frame, frame_reg = PIPE_FRMCOUNT_GM45(pipe);
  786. frame = I915_READ(frame_reg);
  787. if (wait_for(I915_READ_NOTRACE(frame_reg) != frame, 50))
  788. WARN(1, "vblank wait timed out\n");
  789. }
  790. /**
  791. * intel_wait_for_vblank - wait for vblank on a given pipe
  792. * @dev: drm device
  793. * @pipe: pipe to wait for
  794. *
  795. * Wait for vblank to occur on a given pipe. Needed for various bits of
  796. * mode setting code.
  797. */
  798. void intel_wait_for_vblank(struct drm_device *dev, int pipe)
  799. {
  800. struct drm_i915_private *dev_priv = dev->dev_private;
  801. int pipestat_reg = PIPESTAT(pipe);
  802. if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
  803. g4x_wait_for_vblank(dev, pipe);
  804. return;
  805. }
  806. /* Clear existing vblank status. Note this will clear any other
  807. * sticky status fields as well.
  808. *
  809. * This races with i915_driver_irq_handler() with the result
  810. * that either function could miss a vblank event. Here it is not
  811. * fatal, as we will either wait upon the next vblank interrupt or
  812. * timeout. Generally speaking intel_wait_for_vblank() is only
  813. * called during modeset at which time the GPU should be idle and
  814. * should *not* be performing page flips and thus not waiting on
  815. * vblanks...
  816. * Currently, the result of us stealing a vblank from the irq
  817. * handler is that a single frame will be skipped during swapbuffers.
  818. */
  819. I915_WRITE(pipestat_reg,
  820. I915_READ(pipestat_reg) | PIPE_VBLANK_INTERRUPT_STATUS);
  821. /* Wait for vblank interrupt bit to set */
  822. if (wait_for(I915_READ(pipestat_reg) &
  823. PIPE_VBLANK_INTERRUPT_STATUS,
  824. 50))
  825. DRM_DEBUG_KMS("vblank wait timed out\n");
  826. }
  827. static bool pipe_dsl_stopped(struct drm_device *dev, enum pipe pipe)
  828. {
  829. struct drm_i915_private *dev_priv = dev->dev_private;
  830. u32 reg = PIPEDSL(pipe);
  831. u32 line1, line2;
  832. u32 line_mask;
  833. if (IS_GEN2(dev))
  834. line_mask = DSL_LINEMASK_GEN2;
  835. else
  836. line_mask = DSL_LINEMASK_GEN3;
  837. line1 = I915_READ(reg) & line_mask;
  838. mdelay(5);
  839. line2 = I915_READ(reg) & line_mask;
  840. return line1 == line2;
  841. }
  842. /*
  843. * intel_wait_for_pipe_off - wait for pipe to turn off
  844. * @dev: drm device
  845. * @pipe: pipe to wait for
  846. *
  847. * After disabling a pipe, we can't wait for vblank in the usual way,
  848. * spinning on the vblank interrupt status bit, since we won't actually
  849. * see an interrupt when the pipe is disabled.
  850. *
  851. * On Gen4 and above:
  852. * wait for the pipe register state bit to turn off
  853. *
  854. * Otherwise:
  855. * wait for the display line value to settle (it usually
  856. * ends up stopping at the start of the next frame).
  857. *
  858. */
  859. void intel_wait_for_pipe_off(struct drm_device *dev, int pipe)
  860. {
  861. struct drm_i915_private *dev_priv = dev->dev_private;
  862. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  863. pipe);
  864. if (INTEL_INFO(dev)->gen >= 4) {
  865. int reg = PIPECONF(cpu_transcoder);
  866. /* Wait for the Pipe State to go off */
  867. if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0,
  868. 100))
  869. WARN(1, "pipe_off wait timed out\n");
  870. } else {
  871. /* Wait for the display line to settle */
  872. if (wait_for(pipe_dsl_stopped(dev, pipe), 100))
  873. WARN(1, "pipe_off wait timed out\n");
  874. }
  875. }
  876. /*
  877. * ibx_digital_port_connected - is the specified port connected?
  878. * @dev_priv: i915 private structure
  879. * @port: the port to test
  880. *
  881. * Returns true if @port is connected, false otherwise.
  882. */
  883. bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
  884. struct intel_digital_port *port)
  885. {
  886. u32 bit;
  887. if (HAS_PCH_IBX(dev_priv->dev)) {
  888. switch (port->port) {
  889. case PORT_B:
  890. bit = SDE_PORTB_HOTPLUG;
  891. break;
  892. case PORT_C:
  893. bit = SDE_PORTC_HOTPLUG;
  894. break;
  895. case PORT_D:
  896. bit = SDE_PORTD_HOTPLUG;
  897. break;
  898. default:
  899. return true;
  900. }
  901. } else {
  902. switch (port->port) {
  903. case PORT_B:
  904. bit = SDE_PORTB_HOTPLUG_CPT;
  905. break;
  906. case PORT_C:
  907. bit = SDE_PORTC_HOTPLUG_CPT;
  908. break;
  909. case PORT_D:
  910. bit = SDE_PORTD_HOTPLUG_CPT;
  911. break;
  912. default:
  913. return true;
  914. }
  915. }
  916. return I915_READ(SDEISR) & bit;
  917. }
  918. static const char *state_string(bool enabled)
  919. {
  920. return enabled ? "on" : "off";
  921. }
  922. /* Only for pre-ILK configs */
  923. void assert_pll(struct drm_i915_private *dev_priv,
  924. enum pipe pipe, bool state)
  925. {
  926. int reg;
  927. u32 val;
  928. bool cur_state;
  929. reg = DPLL(pipe);
  930. val = I915_READ(reg);
  931. cur_state = !!(val & DPLL_VCO_ENABLE);
  932. WARN(cur_state != state,
  933. "PLL state assertion failure (expected %s, current %s)\n",
  934. state_string(state), state_string(cur_state));
  935. }
  936. /* XXX: the dsi pll is shared between MIPI DSI ports */
  937. static void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state)
  938. {
  939. u32 val;
  940. bool cur_state;
  941. mutex_lock(&dev_priv->dpio_lock);
  942. val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
  943. mutex_unlock(&dev_priv->dpio_lock);
  944. cur_state = val & DSI_PLL_VCO_EN;
  945. WARN(cur_state != state,
  946. "DSI PLL state assertion failure (expected %s, current %s)\n",
  947. state_string(state), state_string(cur_state));
  948. }
  949. #define assert_dsi_pll_enabled(d) assert_dsi_pll(d, true)
  950. #define assert_dsi_pll_disabled(d) assert_dsi_pll(d, false)
  951. struct intel_shared_dpll *
  952. intel_crtc_to_shared_dpll(struct intel_crtc *crtc)
  953. {
  954. struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
  955. if (crtc->config.shared_dpll < 0)
  956. return NULL;
  957. return &dev_priv->shared_dplls[crtc->config.shared_dpll];
  958. }
  959. /* For ILK+ */
  960. void assert_shared_dpll(struct drm_i915_private *dev_priv,
  961. struct intel_shared_dpll *pll,
  962. bool state)
  963. {
  964. bool cur_state;
  965. struct intel_dpll_hw_state hw_state;
  966. if (HAS_PCH_LPT(dev_priv->dev)) {
  967. DRM_DEBUG_DRIVER("LPT detected: skipping PCH PLL test\n");
  968. return;
  969. }
  970. if (WARN (!pll,
  971. "asserting DPLL %s with no DPLL\n", state_string(state)))
  972. return;
  973. cur_state = pll->get_hw_state(dev_priv, pll, &hw_state);
  974. WARN(cur_state != state,
  975. "%s assertion failure (expected %s, current %s)\n",
  976. pll->name, state_string(state), state_string(cur_state));
  977. }
  978. static void assert_fdi_tx(struct drm_i915_private *dev_priv,
  979. enum pipe pipe, bool state)
  980. {
  981. int reg;
  982. u32 val;
  983. bool cur_state;
  984. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  985. pipe);
  986. if (HAS_DDI(dev_priv->dev)) {
  987. /* DDI does not have a specific FDI_TX register */
  988. reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
  989. val = I915_READ(reg);
  990. cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
  991. } else {
  992. reg = FDI_TX_CTL(pipe);
  993. val = I915_READ(reg);
  994. cur_state = !!(val & FDI_TX_ENABLE);
  995. }
  996. WARN(cur_state != state,
  997. "FDI TX state assertion failure (expected %s, current %s)\n",
  998. state_string(state), state_string(cur_state));
  999. }
  1000. #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
  1001. #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
  1002. static void assert_fdi_rx(struct drm_i915_private *dev_priv,
  1003. enum pipe pipe, bool state)
  1004. {
  1005. int reg;
  1006. u32 val;
  1007. bool cur_state;
  1008. reg = FDI_RX_CTL(pipe);
  1009. val = I915_READ(reg);
  1010. cur_state = !!(val & FDI_RX_ENABLE);
  1011. WARN(cur_state != state,
  1012. "FDI RX state assertion failure (expected %s, current %s)\n",
  1013. state_string(state), state_string(cur_state));
  1014. }
  1015. #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
  1016. #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
  1017. static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
  1018. enum pipe pipe)
  1019. {
  1020. int reg;
  1021. u32 val;
  1022. /* ILK FDI PLL is always enabled */
  1023. if (INTEL_INFO(dev_priv->dev)->gen == 5)
  1024. return;
  1025. /* On Haswell, DDI ports are responsible for the FDI PLL setup */
  1026. if (HAS_DDI(dev_priv->dev))
  1027. return;
  1028. reg = FDI_TX_CTL(pipe);
  1029. val = I915_READ(reg);
  1030. WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n");
  1031. }
  1032. void assert_fdi_rx_pll(struct drm_i915_private *dev_priv,
  1033. enum pipe pipe, bool state)
  1034. {
  1035. int reg;
  1036. u32 val;
  1037. bool cur_state;
  1038. reg = FDI_RX_CTL(pipe);
  1039. val = I915_READ(reg);
  1040. cur_state = !!(val & FDI_RX_PLL_ENABLE);
  1041. WARN(cur_state != state,
  1042. "FDI RX PLL assertion failure (expected %s, current %s)\n",
  1043. state_string(state), state_string(cur_state));
  1044. }
  1045. static void assert_panel_unlocked(struct drm_i915_private *dev_priv,
  1046. enum pipe pipe)
  1047. {
  1048. int pp_reg, lvds_reg;
  1049. u32 val;
  1050. enum pipe panel_pipe = PIPE_A;
  1051. bool locked = true;
  1052. if (HAS_PCH_SPLIT(dev_priv->dev)) {
  1053. pp_reg = PCH_PP_CONTROL;
  1054. lvds_reg = PCH_LVDS;
  1055. } else {
  1056. pp_reg = PP_CONTROL;
  1057. lvds_reg = LVDS;
  1058. }
  1059. val = I915_READ(pp_reg);
  1060. if (!(val & PANEL_POWER_ON) ||
  1061. ((val & PANEL_UNLOCK_REGS) == PANEL_UNLOCK_REGS))
  1062. locked = false;
  1063. if (I915_READ(lvds_reg) & LVDS_PIPEB_SELECT)
  1064. panel_pipe = PIPE_B;
  1065. WARN(panel_pipe == pipe && locked,
  1066. "panel assertion failure, pipe %c regs locked\n",
  1067. pipe_name(pipe));
  1068. }
  1069. static void assert_cursor(struct drm_i915_private *dev_priv,
  1070. enum pipe pipe, bool state)
  1071. {
  1072. struct drm_device *dev = dev_priv->dev;
  1073. bool cur_state;
  1074. if (IS_845G(dev) || IS_I865G(dev))
  1075. cur_state = I915_READ(_CURACNTR) & CURSOR_ENABLE;
  1076. else
  1077. cur_state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
  1078. WARN(cur_state != state,
  1079. "cursor on pipe %c assertion failure (expected %s, current %s)\n",
  1080. pipe_name(pipe), state_string(state), state_string(cur_state));
  1081. }
  1082. #define assert_cursor_enabled(d, p) assert_cursor(d, p, true)
  1083. #define assert_cursor_disabled(d, p) assert_cursor(d, p, false)
  1084. void assert_pipe(struct drm_i915_private *dev_priv,
  1085. enum pipe pipe, bool state)
  1086. {
  1087. int reg;
  1088. u32 val;
  1089. bool cur_state;
  1090. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  1091. pipe);
  1092. /* if we need the pipe A quirk it must be always on */
  1093. if (pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE)
  1094. state = true;
  1095. if (!intel_display_power_enabled(dev_priv,
  1096. POWER_DOMAIN_TRANSCODER(cpu_transcoder))) {
  1097. cur_state = false;
  1098. } else {
  1099. reg = PIPECONF(cpu_transcoder);
  1100. val = I915_READ(reg);
  1101. cur_state = !!(val & PIPECONF_ENABLE);
  1102. }
  1103. WARN(cur_state != state,
  1104. "pipe %c assertion failure (expected %s, current %s)\n",
  1105. pipe_name(pipe), state_string(state), state_string(cur_state));
  1106. }
  1107. static void assert_plane(struct drm_i915_private *dev_priv,
  1108. enum plane plane, bool state)
  1109. {
  1110. int reg;
  1111. u32 val;
  1112. bool cur_state;
  1113. reg = DSPCNTR(plane);
  1114. val = I915_READ(reg);
  1115. cur_state = !!(val & DISPLAY_PLANE_ENABLE);
  1116. WARN(cur_state != state,
  1117. "plane %c assertion failure (expected %s, current %s)\n",
  1118. plane_name(plane), state_string(state), state_string(cur_state));
  1119. }
  1120. #define assert_plane_enabled(d, p) assert_plane(d, p, true)
  1121. #define assert_plane_disabled(d, p) assert_plane(d, p, false)
  1122. static void assert_planes_disabled(struct drm_i915_private *dev_priv,
  1123. enum pipe pipe)
  1124. {
  1125. struct drm_device *dev = dev_priv->dev;
  1126. int reg, i;
  1127. u32 val;
  1128. int cur_pipe;
  1129. /* Primary planes are fixed to pipes on gen4+ */
  1130. if (INTEL_INFO(dev)->gen >= 4) {
  1131. reg = DSPCNTR(pipe);
  1132. val = I915_READ(reg);
  1133. WARN(val & DISPLAY_PLANE_ENABLE,
  1134. "plane %c assertion failure, should be disabled but not\n",
  1135. plane_name(pipe));
  1136. return;
  1137. }
  1138. /* Need to check both planes against the pipe */
  1139. for_each_pipe(i) {
  1140. reg = DSPCNTR(i);
  1141. val = I915_READ(reg);
  1142. cur_pipe = (val & DISPPLANE_SEL_PIPE_MASK) >>
  1143. DISPPLANE_SEL_PIPE_SHIFT;
  1144. WARN((val & DISPLAY_PLANE_ENABLE) && pipe == cur_pipe,
  1145. "plane %c assertion failure, should be off on pipe %c but is still active\n",
  1146. plane_name(i), pipe_name(pipe));
  1147. }
  1148. }
  1149. static void assert_sprites_disabled(struct drm_i915_private *dev_priv,
  1150. enum pipe pipe)
  1151. {
  1152. struct drm_device *dev = dev_priv->dev;
  1153. int reg, sprite;
  1154. u32 val;
  1155. if (IS_VALLEYVIEW(dev)) {
  1156. for_each_sprite(pipe, sprite) {
  1157. reg = SPCNTR(pipe, sprite);
  1158. val = I915_READ(reg);
  1159. WARN(val & SP_ENABLE,
  1160. "sprite %c assertion failure, should be off on pipe %c but is still active\n",
  1161. sprite_name(pipe, sprite), pipe_name(pipe));
  1162. }
  1163. } else if (INTEL_INFO(dev)->gen >= 7) {
  1164. reg = SPRCTL(pipe);
  1165. val = I915_READ(reg);
  1166. WARN(val & SPRITE_ENABLE,
  1167. "sprite %c assertion failure, should be off on pipe %c but is still active\n",
  1168. plane_name(pipe), pipe_name(pipe));
  1169. } else if (INTEL_INFO(dev)->gen >= 5) {
  1170. reg = DVSCNTR(pipe);
  1171. val = I915_READ(reg);
  1172. WARN(val & DVS_ENABLE,
  1173. "sprite %c assertion failure, should be off on pipe %c but is still active\n",
  1174. plane_name(pipe), pipe_name(pipe));
  1175. }
  1176. }
  1177. static void ibx_assert_pch_refclk_enabled(struct drm_i915_private *dev_priv)
  1178. {
  1179. u32 val;
  1180. bool enabled;
  1181. WARN_ON(!(HAS_PCH_IBX(dev_priv->dev) || HAS_PCH_CPT(dev_priv->dev)));
  1182. val = I915_READ(PCH_DREF_CONTROL);
  1183. enabled = !!(val & (DREF_SSC_SOURCE_MASK | DREF_NONSPREAD_SOURCE_MASK |
  1184. DREF_SUPERSPREAD_SOURCE_MASK));
  1185. WARN(!enabled, "PCH refclk assertion failure, should be active but is disabled\n");
  1186. }
  1187. static void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv,
  1188. enum pipe pipe)
  1189. {
  1190. int reg;
  1191. u32 val;
  1192. bool enabled;
  1193. reg = PCH_TRANSCONF(pipe);
  1194. val = I915_READ(reg);
  1195. enabled = !!(val & TRANS_ENABLE);
  1196. WARN(enabled,
  1197. "transcoder assertion failed, should be off on pipe %c but is still active\n",
  1198. pipe_name(pipe));
  1199. }
  1200. static bool dp_pipe_enabled(struct drm_i915_private *dev_priv,
  1201. enum pipe pipe, u32 port_sel, u32 val)
  1202. {
  1203. if ((val & DP_PORT_EN) == 0)
  1204. return false;
  1205. if (HAS_PCH_CPT(dev_priv->dev)) {
  1206. u32 trans_dp_ctl_reg = TRANS_DP_CTL(pipe);
  1207. u32 trans_dp_ctl = I915_READ(trans_dp_ctl_reg);
  1208. if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel)
  1209. return false;
  1210. } else if (IS_CHERRYVIEW(dev_priv->dev)) {
  1211. if ((val & DP_PIPE_MASK_CHV) != DP_PIPE_SELECT_CHV(pipe))
  1212. return false;
  1213. } else {
  1214. if ((val & DP_PIPE_MASK) != (pipe << 30))
  1215. return false;
  1216. }
  1217. return true;
  1218. }
  1219. static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv,
  1220. enum pipe pipe, u32 val)
  1221. {
  1222. if ((val & SDVO_ENABLE) == 0)
  1223. return false;
  1224. if (HAS_PCH_CPT(dev_priv->dev)) {
  1225. if ((val & SDVO_PIPE_SEL_MASK_CPT) != SDVO_PIPE_SEL_CPT(pipe))
  1226. return false;
  1227. } else if (IS_CHERRYVIEW(dev_priv->dev)) {
  1228. if ((val & SDVO_PIPE_SEL_MASK_CHV) != SDVO_PIPE_SEL_CHV(pipe))
  1229. return false;
  1230. } else {
  1231. if ((val & SDVO_PIPE_SEL_MASK) != SDVO_PIPE_SEL(pipe))
  1232. return false;
  1233. }
  1234. return true;
  1235. }
  1236. static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv,
  1237. enum pipe pipe, u32 val)
  1238. {
  1239. if ((val & LVDS_PORT_EN) == 0)
  1240. return false;
  1241. if (HAS_PCH_CPT(dev_priv->dev)) {
  1242. if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
  1243. return false;
  1244. } else {
  1245. if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe))
  1246. return false;
  1247. }
  1248. return true;
  1249. }
  1250. static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv,
  1251. enum pipe pipe, u32 val)
  1252. {
  1253. if ((val & ADPA_DAC_ENABLE) == 0)
  1254. return false;
  1255. if (HAS_PCH_CPT(dev_priv->dev)) {
  1256. if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
  1257. return false;
  1258. } else {
  1259. if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe))
  1260. return false;
  1261. }
  1262. return true;
  1263. }
  1264. static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
  1265. enum pipe pipe, int reg, u32 port_sel)
  1266. {
  1267. u32 val = I915_READ(reg);
  1268. WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val),
  1269. "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
  1270. reg, pipe_name(pipe));
  1271. WARN(HAS_PCH_IBX(dev_priv->dev) && (val & DP_PORT_EN) == 0
  1272. && (val & DP_PIPEB_SELECT),
  1273. "IBX PCH dp port still using transcoder B\n");
  1274. }
  1275. static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
  1276. enum pipe pipe, int reg)
  1277. {
  1278. u32 val = I915_READ(reg);
  1279. WARN(hdmi_pipe_enabled(dev_priv, pipe, val),
  1280. "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
  1281. reg, pipe_name(pipe));
  1282. WARN(HAS_PCH_IBX(dev_priv->dev) && (val & SDVO_ENABLE) == 0
  1283. && (val & SDVO_PIPE_B_SELECT),
  1284. "IBX PCH hdmi port still using transcoder B\n");
  1285. }
  1286. static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
  1287. enum pipe pipe)
  1288. {
  1289. int reg;
  1290. u32 val;
  1291. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B);
  1292. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C);
  1293. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_D, TRANS_DP_PORT_SEL_D);
  1294. reg = PCH_ADPA;
  1295. val = I915_READ(reg);
  1296. WARN(adpa_pipe_enabled(dev_priv, pipe, val),
  1297. "PCH VGA enabled on transcoder %c, should be disabled\n",
  1298. pipe_name(pipe));
  1299. reg = PCH_LVDS;
  1300. val = I915_READ(reg);
  1301. WARN(lvds_pipe_enabled(dev_priv, pipe, val),
  1302. "PCH LVDS enabled on transcoder %c, should be disabled\n",
  1303. pipe_name(pipe));
  1304. assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIB);
  1305. assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIC);
  1306. assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMID);
  1307. }
  1308. static void intel_init_dpio(struct drm_device *dev)
  1309. {
  1310. struct drm_i915_private *dev_priv = dev->dev_private;
  1311. if (!IS_VALLEYVIEW(dev))
  1312. return;
  1313. /*
  1314. * IOSF_PORT_DPIO is used for VLV x2 PHY (DP/HDMI B and C),
  1315. * CHV x1 PHY (DP/HDMI D)
  1316. * IOSF_PORT_DPIO_2 is used for CHV x2 PHY (DP/HDMI B and C)
  1317. */
  1318. if (IS_CHERRYVIEW(dev)) {
  1319. DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO_2;
  1320. DPIO_PHY_IOSF_PORT(DPIO_PHY1) = IOSF_PORT_DPIO;
  1321. } else {
  1322. DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO;
  1323. }
  1324. }
  1325. static void intel_reset_dpio(struct drm_device *dev)
  1326. {
  1327. struct drm_i915_private *dev_priv = dev->dev_private;
  1328. if (!IS_VALLEYVIEW(dev))
  1329. return;
  1330. if (IS_CHERRYVIEW(dev)) {
  1331. enum dpio_phy phy;
  1332. u32 val;
  1333. for (phy = DPIO_PHY0; phy < I915_NUM_PHYS_VLV; phy++) {
  1334. /* Poll for phypwrgood signal */
  1335. if (wait_for(I915_READ(DISPLAY_PHY_STATUS) &
  1336. PHY_POWERGOOD(phy), 1))
  1337. DRM_ERROR("Display PHY %d is not power up\n", phy);
  1338. /*
  1339. * Deassert common lane reset for PHY.
  1340. *
  1341. * This should only be done on init and resume from S3
  1342. * with both PLLs disabled, or we risk losing DPIO and
  1343. * PLL synchronization.
  1344. */
  1345. val = I915_READ(DISPLAY_PHY_CONTROL);
  1346. I915_WRITE(DISPLAY_PHY_CONTROL,
  1347. PHY_COM_LANE_RESET_DEASSERT(phy, val));
  1348. }
  1349. } else {
  1350. /*
  1351. * If DPIO has already been reset, e.g. by BIOS, just skip all
  1352. * this.
  1353. */
  1354. if (I915_READ(DPIO_CTL) & DPIO_CMNRST)
  1355. return;
  1356. /*
  1357. * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx:
  1358. * Need to assert and de-assert PHY SB reset by gating the
  1359. * common lane power, then un-gating it.
  1360. * Simply ungating isn't enough to reset the PHY enough to get
  1361. * ports and lanes running.
  1362. */
  1363. __vlv_set_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC,
  1364. false);
  1365. __vlv_set_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC,
  1366. true);
  1367. }
  1368. }
  1369. static void vlv_enable_pll(struct intel_crtc *crtc)
  1370. {
  1371. struct drm_device *dev = crtc->base.dev;
  1372. struct drm_i915_private *dev_priv = dev->dev_private;
  1373. int reg = DPLL(crtc->pipe);
  1374. u32 dpll = crtc->config.dpll_hw_state.dpll;
  1375. assert_pipe_disabled(dev_priv, crtc->pipe);
  1376. /* No really, not for ILK+ */
  1377. BUG_ON(!IS_VALLEYVIEW(dev_priv->dev));
  1378. /* PLL is protected by panel, make sure we can write it */
  1379. if (IS_MOBILE(dev_priv->dev) && !IS_I830(dev_priv->dev))
  1380. assert_panel_unlocked(dev_priv, crtc->pipe);
  1381. I915_WRITE(reg, dpll);
  1382. POSTING_READ(reg);
  1383. udelay(150);
  1384. if (wait_for(((I915_READ(reg) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1))
  1385. DRM_ERROR("DPLL %d failed to lock\n", crtc->pipe);
  1386. I915_WRITE(DPLL_MD(crtc->pipe), crtc->config.dpll_hw_state.dpll_md);
  1387. POSTING_READ(DPLL_MD(crtc->pipe));
  1388. /* We do this three times for luck */
  1389. I915_WRITE(reg, dpll);
  1390. POSTING_READ(reg);
  1391. udelay(150); /* wait for warmup */
  1392. I915_WRITE(reg, dpll);
  1393. POSTING_READ(reg);
  1394. udelay(150); /* wait for warmup */
  1395. I915_WRITE(reg, dpll);
  1396. POSTING_READ(reg);
  1397. udelay(150); /* wait for warmup */
  1398. }
  1399. static void chv_enable_pll(struct intel_crtc *crtc)
  1400. {
  1401. struct drm_device *dev = crtc->base.dev;
  1402. struct drm_i915_private *dev_priv = dev->dev_private;
  1403. int pipe = crtc->pipe;
  1404. enum dpio_channel port = vlv_pipe_to_channel(pipe);
  1405. u32 tmp;
  1406. assert_pipe_disabled(dev_priv, crtc->pipe);
  1407. BUG_ON(!IS_CHERRYVIEW(dev_priv->dev));
  1408. mutex_lock(&dev_priv->dpio_lock);
  1409. /* Enable back the 10bit clock to display controller */
  1410. tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
  1411. tmp |= DPIO_DCLKP_EN;
  1412. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp);
  1413. /*
  1414. * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
  1415. */
  1416. udelay(1);
  1417. /* Enable PLL */
  1418. I915_WRITE(DPLL(pipe), crtc->config.dpll_hw_state.dpll);
  1419. /* Check PLL is locked */
  1420. if (wait_for(((I915_READ(DPLL(pipe)) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1))
  1421. DRM_ERROR("PLL %d failed to lock\n", pipe);
  1422. /* not sure when this should be written */
  1423. I915_WRITE(DPLL_MD(pipe), crtc->config.dpll_hw_state.dpll_md);
  1424. POSTING_READ(DPLL_MD(pipe));
  1425. mutex_unlock(&dev_priv->dpio_lock);
  1426. }
  1427. static void i9xx_enable_pll(struct intel_crtc *crtc)
  1428. {
  1429. struct drm_device *dev = crtc->base.dev;
  1430. struct drm_i915_private *dev_priv = dev->dev_private;
  1431. int reg = DPLL(crtc->pipe);
  1432. u32 dpll = crtc->config.dpll_hw_state.dpll;
  1433. assert_pipe_disabled(dev_priv, crtc->pipe);
  1434. /* No really, not for ILK+ */
  1435. BUG_ON(INTEL_INFO(dev)->gen >= 5);
  1436. /* PLL is protected by panel, make sure we can write it */
  1437. if (IS_MOBILE(dev) && !IS_I830(dev))
  1438. assert_panel_unlocked(dev_priv, crtc->pipe);
  1439. I915_WRITE(reg, dpll);
  1440. /* Wait for the clocks to stabilize. */
  1441. POSTING_READ(reg);
  1442. udelay(150);
  1443. if (INTEL_INFO(dev)->gen >= 4) {
  1444. I915_WRITE(DPLL_MD(crtc->pipe),
  1445. crtc->config.dpll_hw_state.dpll_md);
  1446. } else {
  1447. /* The pixel multiplier can only be updated once the
  1448. * DPLL is enabled and the clocks are stable.
  1449. *
  1450. * So write it again.
  1451. */
  1452. I915_WRITE(reg, dpll);
  1453. }
  1454. /* We do this three times for luck */
  1455. I915_WRITE(reg, dpll);
  1456. POSTING_READ(reg);
  1457. udelay(150); /* wait for warmup */
  1458. I915_WRITE(reg, dpll);
  1459. POSTING_READ(reg);
  1460. udelay(150); /* wait for warmup */
  1461. I915_WRITE(reg, dpll);
  1462. POSTING_READ(reg);
  1463. udelay(150); /* wait for warmup */
  1464. }
  1465. /**
  1466. * i9xx_disable_pll - disable a PLL
  1467. * @dev_priv: i915 private structure
  1468. * @pipe: pipe PLL to disable
  1469. *
  1470. * Disable the PLL for @pipe, making sure the pipe is off first.
  1471. *
  1472. * Note! This is for pre-ILK only.
  1473. */
  1474. static void i9xx_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
  1475. {
  1476. /* Don't disable pipe A or pipe A PLLs if needed */
  1477. if (pipe == PIPE_A && (dev_priv->quirks & QUIRK_PIPEA_FORCE))
  1478. return;
  1479. /* Make sure the pipe isn't still relying on us */
  1480. assert_pipe_disabled(dev_priv, pipe);
  1481. I915_WRITE(DPLL(pipe), 0);
  1482. POSTING_READ(DPLL(pipe));
  1483. }
  1484. static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
  1485. {
  1486. u32 val = 0;
  1487. /* Make sure the pipe isn't still relying on us */
  1488. assert_pipe_disabled(dev_priv, pipe);
  1489. /*
  1490. * Leave integrated clock source and reference clock enabled for pipe B.
  1491. * The latter is needed for VGA hotplug / manual detection.
  1492. */
  1493. if (pipe == PIPE_B)
  1494. val = DPLL_INTEGRATED_CRI_CLK_VLV | DPLL_REFA_CLK_ENABLE_VLV;
  1495. I915_WRITE(DPLL(pipe), val);
  1496. POSTING_READ(DPLL(pipe));
  1497. }
  1498. static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
  1499. {
  1500. enum dpio_channel port = vlv_pipe_to_channel(pipe);
  1501. u32 val;
  1502. /* Make sure the pipe isn't still relying on us */
  1503. assert_pipe_disabled(dev_priv, pipe);
  1504. /* Set PLL en = 0 */
  1505. val = DPLL_SSC_REF_CLOCK_CHV;
  1506. if (pipe != PIPE_A)
  1507. val |= DPLL_INTEGRATED_CRI_CLK_VLV;
  1508. I915_WRITE(DPLL(pipe), val);
  1509. POSTING_READ(DPLL(pipe));
  1510. mutex_lock(&dev_priv->dpio_lock);
  1511. /* Disable 10bit clock to display controller */
  1512. val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
  1513. val &= ~DPIO_DCLKP_EN;
  1514. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val);
  1515. /* disable left/right clock distribution */
  1516. if (pipe != PIPE_B) {
  1517. val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0);
  1518. val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK);
  1519. vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val);
  1520. } else {
  1521. val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1);
  1522. val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK);
  1523. vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val);
  1524. }
  1525. mutex_unlock(&dev_priv->dpio_lock);
  1526. }
  1527. void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
  1528. struct intel_digital_port *dport)
  1529. {
  1530. u32 port_mask;
  1531. int dpll_reg;
  1532. switch (dport->port) {
  1533. case PORT_B:
  1534. port_mask = DPLL_PORTB_READY_MASK;
  1535. dpll_reg = DPLL(0);
  1536. break;
  1537. case PORT_C:
  1538. port_mask = DPLL_PORTC_READY_MASK;
  1539. dpll_reg = DPLL(0);
  1540. break;
  1541. case PORT_D:
  1542. port_mask = DPLL_PORTD_READY_MASK;
  1543. dpll_reg = DPIO_PHY_STATUS;
  1544. break;
  1545. default:
  1546. BUG();
  1547. }
  1548. if (wait_for((I915_READ(dpll_reg) & port_mask) == 0, 1000))
  1549. WARN(1, "timed out waiting for port %c ready: 0x%08x\n",
  1550. port_name(dport->port), I915_READ(dpll_reg));
  1551. }
  1552. static void intel_prepare_shared_dpll(struct intel_crtc *crtc)
  1553. {
  1554. struct drm_device *dev = crtc->base.dev;
  1555. struct drm_i915_private *dev_priv = dev->dev_private;
  1556. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  1557. if (WARN_ON(pll == NULL))
  1558. return;
  1559. WARN_ON(!pll->refcount);
  1560. if (pll->active == 0) {
  1561. DRM_DEBUG_DRIVER("setting up %s\n", pll->name);
  1562. WARN_ON(pll->on);
  1563. assert_shared_dpll_disabled(dev_priv, pll);
  1564. pll->mode_set(dev_priv, pll);
  1565. }
  1566. }
  1567. /**
  1568. * intel_enable_shared_dpll - enable PCH PLL
  1569. * @dev_priv: i915 private structure
  1570. * @pipe: pipe PLL to enable
  1571. *
  1572. * The PCH PLL needs to be enabled before the PCH transcoder, since it
  1573. * drives the transcoder clock.
  1574. */
  1575. static void intel_enable_shared_dpll(struct intel_crtc *crtc)
  1576. {
  1577. struct drm_device *dev = crtc->base.dev;
  1578. struct drm_i915_private *dev_priv = dev->dev_private;
  1579. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  1580. if (WARN_ON(pll == NULL))
  1581. return;
  1582. if (WARN_ON(pll->refcount == 0))
  1583. return;
  1584. DRM_DEBUG_KMS("enable %s (active %d, on? %d)for crtc %d\n",
  1585. pll->name, pll->active, pll->on,
  1586. crtc->base.base.id);
  1587. if (pll->active++) {
  1588. WARN_ON(!pll->on);
  1589. assert_shared_dpll_enabled(dev_priv, pll);
  1590. return;
  1591. }
  1592. WARN_ON(pll->on);
  1593. DRM_DEBUG_KMS("enabling %s\n", pll->name);
  1594. pll->enable(dev_priv, pll);
  1595. pll->on = true;
  1596. }
  1597. static void intel_disable_shared_dpll(struct intel_crtc *crtc)
  1598. {
  1599. struct drm_device *dev = crtc->base.dev;
  1600. struct drm_i915_private *dev_priv = dev->dev_private;
  1601. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  1602. /* PCH only available on ILK+ */
  1603. BUG_ON(INTEL_INFO(dev)->gen < 5);
  1604. if (WARN_ON(pll == NULL))
  1605. return;
  1606. if (WARN_ON(pll->refcount == 0))
  1607. return;
  1608. DRM_DEBUG_KMS("disable %s (active %d, on? %d) for crtc %d\n",
  1609. pll->name, pll->active, pll->on,
  1610. crtc->base.base.id);
  1611. if (WARN_ON(pll->active == 0)) {
  1612. assert_shared_dpll_disabled(dev_priv, pll);
  1613. return;
  1614. }
  1615. assert_shared_dpll_enabled(dev_priv, pll);
  1616. WARN_ON(!pll->on);
  1617. if (--pll->active)
  1618. return;
  1619. DRM_DEBUG_KMS("disabling %s\n", pll->name);
  1620. pll->disable(dev_priv, pll);
  1621. pll->on = false;
  1622. }
  1623. static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv,
  1624. enum pipe pipe)
  1625. {
  1626. struct drm_device *dev = dev_priv->dev;
  1627. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  1628. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1629. uint32_t reg, val, pipeconf_val;
  1630. /* PCH only available on ILK+ */
  1631. BUG_ON(INTEL_INFO(dev)->gen < 5);
  1632. /* Make sure PCH DPLL is enabled */
  1633. assert_shared_dpll_enabled(dev_priv,
  1634. intel_crtc_to_shared_dpll(intel_crtc));
  1635. /* FDI must be feeding us bits for PCH ports */
  1636. assert_fdi_tx_enabled(dev_priv, pipe);
  1637. assert_fdi_rx_enabled(dev_priv, pipe);
  1638. if (HAS_PCH_CPT(dev)) {
  1639. /* Workaround: Set the timing override bit before enabling the
  1640. * pch transcoder. */
  1641. reg = TRANS_CHICKEN2(pipe);
  1642. val = I915_READ(reg);
  1643. val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
  1644. I915_WRITE(reg, val);
  1645. }
  1646. reg = PCH_TRANSCONF(pipe);
  1647. val = I915_READ(reg);
  1648. pipeconf_val = I915_READ(PIPECONF(pipe));
  1649. if (HAS_PCH_IBX(dev_priv->dev)) {
  1650. /*
  1651. * make the BPC in transcoder be consistent with
  1652. * that in pipeconf reg.
  1653. */
  1654. val &= ~PIPECONF_BPC_MASK;
  1655. val |= pipeconf_val & PIPECONF_BPC_MASK;
  1656. }
  1657. val &= ~TRANS_INTERLACE_MASK;
  1658. if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK)
  1659. if (HAS_PCH_IBX(dev_priv->dev) &&
  1660. intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO))
  1661. val |= TRANS_LEGACY_INTERLACED_ILK;
  1662. else
  1663. val |= TRANS_INTERLACED;
  1664. else
  1665. val |= TRANS_PROGRESSIVE;
  1666. I915_WRITE(reg, val | TRANS_ENABLE);
  1667. if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100))
  1668. DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe));
  1669. }
  1670. static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
  1671. enum transcoder cpu_transcoder)
  1672. {
  1673. u32 val, pipeconf_val;
  1674. /* PCH only available on ILK+ */
  1675. BUG_ON(INTEL_INFO(dev_priv->dev)->gen < 5);
  1676. /* FDI must be feeding us bits for PCH ports */
  1677. assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder);
  1678. assert_fdi_rx_enabled(dev_priv, TRANSCODER_A);
  1679. /* Workaround: set timing override bit. */
  1680. val = I915_READ(_TRANSA_CHICKEN2);
  1681. val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
  1682. I915_WRITE(_TRANSA_CHICKEN2, val);
  1683. val = TRANS_ENABLE;
  1684. pipeconf_val = I915_READ(PIPECONF(cpu_transcoder));
  1685. if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) ==
  1686. PIPECONF_INTERLACED_ILK)
  1687. val |= TRANS_INTERLACED;
  1688. else
  1689. val |= TRANS_PROGRESSIVE;
  1690. I915_WRITE(LPT_TRANSCONF, val);
  1691. if (wait_for(I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE, 100))
  1692. DRM_ERROR("Failed to enable PCH transcoder\n");
  1693. }
  1694. static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv,
  1695. enum pipe pipe)
  1696. {
  1697. struct drm_device *dev = dev_priv->dev;
  1698. uint32_t reg, val;
  1699. /* FDI relies on the transcoder */
  1700. assert_fdi_tx_disabled(dev_priv, pipe);
  1701. assert_fdi_rx_disabled(dev_priv, pipe);
  1702. /* Ports must be off as well */
  1703. assert_pch_ports_disabled(dev_priv, pipe);
  1704. reg = PCH_TRANSCONF(pipe);
  1705. val = I915_READ(reg);
  1706. val &= ~TRANS_ENABLE;
  1707. I915_WRITE(reg, val);
  1708. /* wait for PCH transcoder off, transcoder state */
  1709. if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50))
  1710. DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe));
  1711. if (!HAS_PCH_IBX(dev)) {
  1712. /* Workaround: Clear the timing override chicken bit again. */
  1713. reg = TRANS_CHICKEN2(pipe);
  1714. val = I915_READ(reg);
  1715. val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
  1716. I915_WRITE(reg, val);
  1717. }
  1718. }
  1719. static void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
  1720. {
  1721. u32 val;
  1722. val = I915_READ(LPT_TRANSCONF);
  1723. val &= ~TRANS_ENABLE;
  1724. I915_WRITE(LPT_TRANSCONF, val);
  1725. /* wait for PCH transcoder off, transcoder state */
  1726. if (wait_for((I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE) == 0, 50))
  1727. DRM_ERROR("Failed to disable PCH transcoder\n");
  1728. /* Workaround: clear timing override bit. */
  1729. val = I915_READ(_TRANSA_CHICKEN2);
  1730. val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
  1731. I915_WRITE(_TRANSA_CHICKEN2, val);
  1732. }
  1733. /**
  1734. * intel_enable_pipe - enable a pipe, asserting requirements
  1735. * @crtc: crtc responsible for the pipe
  1736. *
  1737. * Enable @crtc's pipe, making sure that various hardware specific requirements
  1738. * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc.
  1739. */
  1740. static void intel_enable_pipe(struct intel_crtc *crtc)
  1741. {
  1742. struct drm_device *dev = crtc->base.dev;
  1743. struct drm_i915_private *dev_priv = dev->dev_private;
  1744. enum pipe pipe = crtc->pipe;
  1745. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  1746. pipe);
  1747. enum pipe pch_transcoder;
  1748. int reg;
  1749. u32 val;
  1750. assert_planes_disabled(dev_priv, pipe);
  1751. assert_cursor_disabled(dev_priv, pipe);
  1752. assert_sprites_disabled(dev_priv, pipe);
  1753. if (HAS_PCH_LPT(dev_priv->dev))
  1754. pch_transcoder = TRANSCODER_A;
  1755. else
  1756. pch_transcoder = pipe;
  1757. /*
  1758. * A pipe without a PLL won't actually be able to drive bits from
  1759. * a plane. On ILK+ the pipe PLLs are integrated, so we don't
  1760. * need the check.
  1761. */
  1762. if (!HAS_PCH_SPLIT(dev_priv->dev))
  1763. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DSI))
  1764. assert_dsi_pll_enabled(dev_priv);
  1765. else
  1766. assert_pll_enabled(dev_priv, pipe);
  1767. else {
  1768. if (crtc->config.has_pch_encoder) {
  1769. /* if driving the PCH, we need FDI enabled */
  1770. assert_fdi_rx_pll_enabled(dev_priv, pch_transcoder);
  1771. assert_fdi_tx_pll_enabled(dev_priv,
  1772. (enum pipe) cpu_transcoder);
  1773. }
  1774. /* FIXME: assert CPU port conditions for SNB+ */
  1775. }
  1776. reg = PIPECONF(cpu_transcoder);
  1777. val = I915_READ(reg);
  1778. if (val & PIPECONF_ENABLE) {
  1779. WARN_ON(!(pipe == PIPE_A &&
  1780. dev_priv->quirks & QUIRK_PIPEA_FORCE));
  1781. return;
  1782. }
  1783. I915_WRITE(reg, val | PIPECONF_ENABLE);
  1784. POSTING_READ(reg);
  1785. }
  1786. /**
  1787. * intel_disable_pipe - disable a pipe, asserting requirements
  1788. * @dev_priv: i915 private structure
  1789. * @pipe: pipe to disable
  1790. *
  1791. * Disable @pipe, making sure that various hardware specific requirements
  1792. * are met, if applicable, e.g. plane disabled, panel fitter off, etc.
  1793. *
  1794. * @pipe should be %PIPE_A or %PIPE_B.
  1795. *
  1796. * Will wait until the pipe has shut down before returning.
  1797. */
  1798. static void intel_disable_pipe(struct drm_i915_private *dev_priv,
  1799. enum pipe pipe)
  1800. {
  1801. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  1802. pipe);
  1803. int reg;
  1804. u32 val;
  1805. /*
  1806. * Make sure planes won't keep trying to pump pixels to us,
  1807. * or we might hang the display.
  1808. */
  1809. assert_planes_disabled(dev_priv, pipe);
  1810. assert_cursor_disabled(dev_priv, pipe);
  1811. assert_sprites_disabled(dev_priv, pipe);
  1812. /* Don't disable pipe A or pipe A PLLs if needed */
  1813. if (pipe == PIPE_A && (dev_priv->quirks & QUIRK_PIPEA_FORCE))
  1814. return;
  1815. reg = PIPECONF(cpu_transcoder);
  1816. val = I915_READ(reg);
  1817. if ((val & PIPECONF_ENABLE) == 0)
  1818. return;
  1819. I915_WRITE(reg, val & ~PIPECONF_ENABLE);
  1820. intel_wait_for_pipe_off(dev_priv->dev, pipe);
  1821. }
  1822. /*
  1823. * Plane regs are double buffered, going from enabled->disabled needs a
  1824. * trigger in order to latch. The display address reg provides this.
  1825. */
  1826. void intel_flush_primary_plane(struct drm_i915_private *dev_priv,
  1827. enum plane plane)
  1828. {
  1829. struct drm_device *dev = dev_priv->dev;
  1830. u32 reg = INTEL_INFO(dev)->gen >= 4 ? DSPSURF(plane) : DSPADDR(plane);
  1831. I915_WRITE(reg, I915_READ(reg));
  1832. POSTING_READ(reg);
  1833. }
  1834. /**
  1835. * intel_enable_primary_hw_plane - enable the primary plane on a given pipe
  1836. * @dev_priv: i915 private structure
  1837. * @plane: plane to enable
  1838. * @pipe: pipe being fed
  1839. *
  1840. * Enable @plane on @pipe, making sure that @pipe is running first.
  1841. */
  1842. static void intel_enable_primary_hw_plane(struct drm_i915_private *dev_priv,
  1843. enum plane plane, enum pipe pipe)
  1844. {
  1845. struct drm_device *dev = dev_priv->dev;
  1846. struct intel_crtc *intel_crtc =
  1847. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  1848. int reg;
  1849. u32 val;
  1850. /* If the pipe isn't enabled, we can't pump pixels and may hang */
  1851. assert_pipe_enabled(dev_priv, pipe);
  1852. if (intel_crtc->primary_enabled)
  1853. return;
  1854. intel_crtc->primary_enabled = true;
  1855. reg = DSPCNTR(plane);
  1856. val = I915_READ(reg);
  1857. WARN_ON(val & DISPLAY_PLANE_ENABLE);
  1858. I915_WRITE(reg, val | DISPLAY_PLANE_ENABLE);
  1859. intel_flush_primary_plane(dev_priv, plane);
  1860. /*
  1861. * BDW signals flip done immediately if the plane
  1862. * is disabled, even if the plane enable is already
  1863. * armed to occur at the next vblank :(
  1864. */
  1865. if (IS_BROADWELL(dev))
  1866. intel_wait_for_vblank(dev, intel_crtc->pipe);
  1867. }
  1868. /**
  1869. * intel_disable_primary_hw_plane - disable the primary hardware plane
  1870. * @dev_priv: i915 private structure
  1871. * @plane: plane to disable
  1872. * @pipe: pipe consuming the data
  1873. *
  1874. * Disable @plane; should be an independent operation.
  1875. */
  1876. static void intel_disable_primary_hw_plane(struct drm_i915_private *dev_priv,
  1877. enum plane plane, enum pipe pipe)
  1878. {
  1879. struct intel_crtc *intel_crtc =
  1880. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  1881. int reg;
  1882. u32 val;
  1883. if (!intel_crtc->primary_enabled)
  1884. return;
  1885. intel_crtc->primary_enabled = false;
  1886. reg = DSPCNTR(plane);
  1887. val = I915_READ(reg);
  1888. WARN_ON((val & DISPLAY_PLANE_ENABLE) == 0);
  1889. I915_WRITE(reg, val & ~DISPLAY_PLANE_ENABLE);
  1890. intel_flush_primary_plane(dev_priv, plane);
  1891. }
  1892. static bool need_vtd_wa(struct drm_device *dev)
  1893. {
  1894. #ifdef CONFIG_INTEL_IOMMU
  1895. if (INTEL_INFO(dev)->gen >= 6 && intel_iommu_gfx_mapped)
  1896. return true;
  1897. #endif
  1898. return false;
  1899. }
  1900. static int intel_align_height(struct drm_device *dev, int height, bool tiled)
  1901. {
  1902. int tile_height;
  1903. tile_height = tiled ? (IS_GEN2(dev) ? 16 : 8) : 1;
  1904. return ALIGN(height, tile_height);
  1905. }
  1906. int
  1907. intel_pin_and_fence_fb_obj(struct drm_device *dev,
  1908. struct drm_i915_gem_object *obj,
  1909. struct intel_engine_cs *pipelined)
  1910. {
  1911. struct drm_i915_private *dev_priv = dev->dev_private;
  1912. u32 alignment;
  1913. int ret;
  1914. switch (obj->tiling_mode) {
  1915. case I915_TILING_NONE:
  1916. if (IS_BROADWATER(dev) || IS_CRESTLINE(dev))
  1917. alignment = 128 * 1024;
  1918. else if (INTEL_INFO(dev)->gen >= 4)
  1919. alignment = 4 * 1024;
  1920. else
  1921. alignment = 64 * 1024;
  1922. break;
  1923. case I915_TILING_X:
  1924. /* pin() will align the object as required by fence */
  1925. alignment = 0;
  1926. break;
  1927. case I915_TILING_Y:
  1928. WARN(1, "Y tiled bo slipped through, driver bug!\n");
  1929. return -EINVAL;
  1930. default:
  1931. BUG();
  1932. }
  1933. /* Note that the w/a also requires 64 PTE of padding following the
  1934. * bo. We currently fill all unused PTE with the shadow page and so
  1935. * we should always have valid PTE following the scanout preventing
  1936. * the VT-d warning.
  1937. */
  1938. if (need_vtd_wa(dev) && alignment < 256 * 1024)
  1939. alignment = 256 * 1024;
  1940. dev_priv->mm.interruptible = false;
  1941. ret = i915_gem_object_pin_to_display_plane(obj, alignment, pipelined);
  1942. if (ret)
  1943. goto err_interruptible;
  1944. /* Install a fence for tiled scan-out. Pre-i965 always needs a
  1945. * fence, whereas 965+ only requires a fence if using
  1946. * framebuffer compression. For simplicity, we always install
  1947. * a fence as the cost is not that onerous.
  1948. */
  1949. ret = i915_gem_object_get_fence(obj);
  1950. if (ret)
  1951. goto err_unpin;
  1952. i915_gem_object_pin_fence(obj);
  1953. dev_priv->mm.interruptible = true;
  1954. return 0;
  1955. err_unpin:
  1956. i915_gem_object_unpin_from_display_plane(obj);
  1957. err_interruptible:
  1958. dev_priv->mm.interruptible = true;
  1959. return ret;
  1960. }
  1961. void intel_unpin_fb_obj(struct drm_i915_gem_object *obj)
  1962. {
  1963. i915_gem_object_unpin_fence(obj);
  1964. i915_gem_object_unpin_from_display_plane(obj);
  1965. }
  1966. /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel
  1967. * is assumed to be a power-of-two. */
  1968. unsigned long intel_gen4_compute_page_offset(int *x, int *y,
  1969. unsigned int tiling_mode,
  1970. unsigned int cpp,
  1971. unsigned int pitch)
  1972. {
  1973. if (tiling_mode != I915_TILING_NONE) {
  1974. unsigned int tile_rows, tiles;
  1975. tile_rows = *y / 8;
  1976. *y %= 8;
  1977. tiles = *x / (512/cpp);
  1978. *x %= 512/cpp;
  1979. return tile_rows * pitch * 8 + tiles * 4096;
  1980. } else {
  1981. unsigned int offset;
  1982. offset = *y * pitch + *x * cpp;
  1983. *y = 0;
  1984. *x = (offset & 4095) / cpp;
  1985. return offset & -4096;
  1986. }
  1987. }
  1988. int intel_format_to_fourcc(int format)
  1989. {
  1990. switch (format) {
  1991. case DISPPLANE_8BPP:
  1992. return DRM_FORMAT_C8;
  1993. case DISPPLANE_BGRX555:
  1994. return DRM_FORMAT_XRGB1555;
  1995. case DISPPLANE_BGRX565:
  1996. return DRM_FORMAT_RGB565;
  1997. default:
  1998. case DISPPLANE_BGRX888:
  1999. return DRM_FORMAT_XRGB8888;
  2000. case DISPPLANE_RGBX888:
  2001. return DRM_FORMAT_XBGR8888;
  2002. case DISPPLANE_BGRX101010:
  2003. return DRM_FORMAT_XRGB2101010;
  2004. case DISPPLANE_RGBX101010:
  2005. return DRM_FORMAT_XBGR2101010;
  2006. }
  2007. }
  2008. static bool intel_alloc_plane_obj(struct intel_crtc *crtc,
  2009. struct intel_plane_config *plane_config)
  2010. {
  2011. struct drm_device *dev = crtc->base.dev;
  2012. struct drm_i915_gem_object *obj = NULL;
  2013. struct drm_mode_fb_cmd2 mode_cmd = { 0 };
  2014. u32 base = plane_config->base;
  2015. if (plane_config->size == 0)
  2016. return false;
  2017. obj = i915_gem_object_create_stolen_for_preallocated(dev, base, base,
  2018. plane_config->size);
  2019. if (!obj)
  2020. return false;
  2021. if (plane_config->tiled) {
  2022. obj->tiling_mode = I915_TILING_X;
  2023. obj->stride = crtc->base.primary->fb->pitches[0];
  2024. }
  2025. mode_cmd.pixel_format = crtc->base.primary->fb->pixel_format;
  2026. mode_cmd.width = crtc->base.primary->fb->width;
  2027. mode_cmd.height = crtc->base.primary->fb->height;
  2028. mode_cmd.pitches[0] = crtc->base.primary->fb->pitches[0];
  2029. mutex_lock(&dev->struct_mutex);
  2030. if (intel_framebuffer_init(dev, to_intel_framebuffer(crtc->base.primary->fb),
  2031. &mode_cmd, obj)) {
  2032. DRM_DEBUG_KMS("intel fb init failed\n");
  2033. goto out_unref_obj;
  2034. }
  2035. obj->frontbuffer_bits = INTEL_FRONTBUFFER_PRIMARY(crtc->pipe);
  2036. mutex_unlock(&dev->struct_mutex);
  2037. DRM_DEBUG_KMS("plane fb obj %p\n", obj);
  2038. return true;
  2039. out_unref_obj:
  2040. drm_gem_object_unreference(&obj->base);
  2041. mutex_unlock(&dev->struct_mutex);
  2042. return false;
  2043. }
  2044. static void intel_find_plane_obj(struct intel_crtc *intel_crtc,
  2045. struct intel_plane_config *plane_config)
  2046. {
  2047. struct drm_device *dev = intel_crtc->base.dev;
  2048. struct drm_crtc *c;
  2049. struct intel_crtc *i;
  2050. struct intel_framebuffer *fb;
  2051. if (!intel_crtc->base.primary->fb)
  2052. return;
  2053. if (intel_alloc_plane_obj(intel_crtc, plane_config))
  2054. return;
  2055. kfree(intel_crtc->base.primary->fb);
  2056. intel_crtc->base.primary->fb = NULL;
  2057. /*
  2058. * Failed to alloc the obj, check to see if we should share
  2059. * an fb with another CRTC instead
  2060. */
  2061. for_each_crtc(dev, c) {
  2062. i = to_intel_crtc(c);
  2063. if (c == &intel_crtc->base)
  2064. continue;
  2065. if (!i->active || !c->primary->fb)
  2066. continue;
  2067. fb = to_intel_framebuffer(c->primary->fb);
  2068. if (i915_gem_obj_ggtt_offset(fb->obj) == plane_config->base) {
  2069. drm_framebuffer_reference(c->primary->fb);
  2070. intel_crtc->base.primary->fb = c->primary->fb;
  2071. fb->obj->frontbuffer_bits |= INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe);
  2072. break;
  2073. }
  2074. }
  2075. }
  2076. static void i9xx_update_primary_plane(struct drm_crtc *crtc,
  2077. struct drm_framebuffer *fb,
  2078. int x, int y)
  2079. {
  2080. struct drm_device *dev = crtc->dev;
  2081. struct drm_i915_private *dev_priv = dev->dev_private;
  2082. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2083. struct intel_framebuffer *intel_fb;
  2084. struct drm_i915_gem_object *obj;
  2085. int plane = intel_crtc->plane;
  2086. unsigned long linear_offset;
  2087. u32 dspcntr;
  2088. u32 reg;
  2089. intel_fb = to_intel_framebuffer(fb);
  2090. obj = intel_fb->obj;
  2091. reg = DSPCNTR(plane);
  2092. dspcntr = I915_READ(reg);
  2093. /* Mask out pixel format bits in case we change it */
  2094. dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
  2095. switch (fb->pixel_format) {
  2096. case DRM_FORMAT_C8:
  2097. dspcntr |= DISPPLANE_8BPP;
  2098. break;
  2099. case DRM_FORMAT_XRGB1555:
  2100. case DRM_FORMAT_ARGB1555:
  2101. dspcntr |= DISPPLANE_BGRX555;
  2102. break;
  2103. case DRM_FORMAT_RGB565:
  2104. dspcntr |= DISPPLANE_BGRX565;
  2105. break;
  2106. case DRM_FORMAT_XRGB8888:
  2107. case DRM_FORMAT_ARGB8888:
  2108. dspcntr |= DISPPLANE_BGRX888;
  2109. break;
  2110. case DRM_FORMAT_XBGR8888:
  2111. case DRM_FORMAT_ABGR8888:
  2112. dspcntr |= DISPPLANE_RGBX888;
  2113. break;
  2114. case DRM_FORMAT_XRGB2101010:
  2115. case DRM_FORMAT_ARGB2101010:
  2116. dspcntr |= DISPPLANE_BGRX101010;
  2117. break;
  2118. case DRM_FORMAT_XBGR2101010:
  2119. case DRM_FORMAT_ABGR2101010:
  2120. dspcntr |= DISPPLANE_RGBX101010;
  2121. break;
  2122. default:
  2123. BUG();
  2124. }
  2125. if (INTEL_INFO(dev)->gen >= 4) {
  2126. if (obj->tiling_mode != I915_TILING_NONE)
  2127. dspcntr |= DISPPLANE_TILED;
  2128. else
  2129. dspcntr &= ~DISPPLANE_TILED;
  2130. }
  2131. if (IS_G4X(dev))
  2132. dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
  2133. I915_WRITE(reg, dspcntr);
  2134. linear_offset = y * fb->pitches[0] + x * (fb->bits_per_pixel / 8);
  2135. if (INTEL_INFO(dev)->gen >= 4) {
  2136. intel_crtc->dspaddr_offset =
  2137. intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
  2138. fb->bits_per_pixel / 8,
  2139. fb->pitches[0]);
  2140. linear_offset -= intel_crtc->dspaddr_offset;
  2141. } else {
  2142. intel_crtc->dspaddr_offset = linear_offset;
  2143. }
  2144. DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n",
  2145. i915_gem_obj_ggtt_offset(obj), linear_offset, x, y,
  2146. fb->pitches[0]);
  2147. I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
  2148. if (INTEL_INFO(dev)->gen >= 4) {
  2149. I915_WRITE(DSPSURF(plane),
  2150. i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset);
  2151. I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
  2152. I915_WRITE(DSPLINOFF(plane), linear_offset);
  2153. } else
  2154. I915_WRITE(DSPADDR(plane), i915_gem_obj_ggtt_offset(obj) + linear_offset);
  2155. POSTING_READ(reg);
  2156. }
  2157. static void ironlake_update_primary_plane(struct drm_crtc *crtc,
  2158. struct drm_framebuffer *fb,
  2159. int x, int y)
  2160. {
  2161. struct drm_device *dev = crtc->dev;
  2162. struct drm_i915_private *dev_priv = dev->dev_private;
  2163. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2164. struct intel_framebuffer *intel_fb;
  2165. struct drm_i915_gem_object *obj;
  2166. int plane = intel_crtc->plane;
  2167. unsigned long linear_offset;
  2168. u32 dspcntr;
  2169. u32 reg;
  2170. intel_fb = to_intel_framebuffer(fb);
  2171. obj = intel_fb->obj;
  2172. reg = DSPCNTR(plane);
  2173. dspcntr = I915_READ(reg);
  2174. /* Mask out pixel format bits in case we change it */
  2175. dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
  2176. switch (fb->pixel_format) {
  2177. case DRM_FORMAT_C8:
  2178. dspcntr |= DISPPLANE_8BPP;
  2179. break;
  2180. case DRM_FORMAT_RGB565:
  2181. dspcntr |= DISPPLANE_BGRX565;
  2182. break;
  2183. case DRM_FORMAT_XRGB8888:
  2184. case DRM_FORMAT_ARGB8888:
  2185. dspcntr |= DISPPLANE_BGRX888;
  2186. break;
  2187. case DRM_FORMAT_XBGR8888:
  2188. case DRM_FORMAT_ABGR8888:
  2189. dspcntr |= DISPPLANE_RGBX888;
  2190. break;
  2191. case DRM_FORMAT_XRGB2101010:
  2192. case DRM_FORMAT_ARGB2101010:
  2193. dspcntr |= DISPPLANE_BGRX101010;
  2194. break;
  2195. case DRM_FORMAT_XBGR2101010:
  2196. case DRM_FORMAT_ABGR2101010:
  2197. dspcntr |= DISPPLANE_RGBX101010;
  2198. break;
  2199. default:
  2200. BUG();
  2201. }
  2202. if (obj->tiling_mode != I915_TILING_NONE)
  2203. dspcntr |= DISPPLANE_TILED;
  2204. else
  2205. dspcntr &= ~DISPPLANE_TILED;
  2206. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  2207. dspcntr &= ~DISPPLANE_TRICKLE_FEED_DISABLE;
  2208. else
  2209. dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
  2210. I915_WRITE(reg, dspcntr);
  2211. linear_offset = y * fb->pitches[0] + x * (fb->bits_per_pixel / 8);
  2212. intel_crtc->dspaddr_offset =
  2213. intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
  2214. fb->bits_per_pixel / 8,
  2215. fb->pitches[0]);
  2216. linear_offset -= intel_crtc->dspaddr_offset;
  2217. DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n",
  2218. i915_gem_obj_ggtt_offset(obj), linear_offset, x, y,
  2219. fb->pitches[0]);
  2220. I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
  2221. I915_WRITE(DSPSURF(plane),
  2222. i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset);
  2223. if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  2224. I915_WRITE(DSPOFFSET(plane), (y << 16) | x);
  2225. } else {
  2226. I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
  2227. I915_WRITE(DSPLINOFF(plane), linear_offset);
  2228. }
  2229. POSTING_READ(reg);
  2230. }
  2231. /* Assume fb object is pinned & idle & fenced and just update base pointers */
  2232. static int
  2233. intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb,
  2234. int x, int y, enum mode_set_atomic state)
  2235. {
  2236. struct drm_device *dev = crtc->dev;
  2237. struct drm_i915_private *dev_priv = dev->dev_private;
  2238. if (dev_priv->display.disable_fbc)
  2239. dev_priv->display.disable_fbc(dev);
  2240. intel_increase_pllclock(dev, to_intel_crtc(crtc)->pipe);
  2241. dev_priv->display.update_primary_plane(crtc, fb, x, y);
  2242. return 0;
  2243. }
  2244. void intel_display_handle_reset(struct drm_device *dev)
  2245. {
  2246. struct drm_i915_private *dev_priv = dev->dev_private;
  2247. struct drm_crtc *crtc;
  2248. /*
  2249. * Flips in the rings have been nuked by the reset,
  2250. * so complete all pending flips so that user space
  2251. * will get its events and not get stuck.
  2252. *
  2253. * Also update the base address of all primary
  2254. * planes to the the last fb to make sure we're
  2255. * showing the correct fb after a reset.
  2256. *
  2257. * Need to make two loops over the crtcs so that we
  2258. * don't try to grab a crtc mutex before the
  2259. * pending_flip_queue really got woken up.
  2260. */
  2261. for_each_crtc(dev, crtc) {
  2262. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2263. enum plane plane = intel_crtc->plane;
  2264. intel_prepare_page_flip(dev, plane);
  2265. intel_finish_page_flip_plane(dev, plane);
  2266. }
  2267. for_each_crtc(dev, crtc) {
  2268. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2269. drm_modeset_lock(&crtc->mutex, NULL);
  2270. /*
  2271. * FIXME: Once we have proper support for primary planes (and
  2272. * disabling them without disabling the entire crtc) allow again
  2273. * a NULL crtc->primary->fb.
  2274. */
  2275. if (intel_crtc->active && crtc->primary->fb)
  2276. dev_priv->display.update_primary_plane(crtc,
  2277. crtc->primary->fb,
  2278. crtc->x,
  2279. crtc->y);
  2280. drm_modeset_unlock(&crtc->mutex);
  2281. }
  2282. }
  2283. static int
  2284. intel_finish_fb(struct drm_framebuffer *old_fb)
  2285. {
  2286. struct drm_i915_gem_object *obj = to_intel_framebuffer(old_fb)->obj;
  2287. struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
  2288. bool was_interruptible = dev_priv->mm.interruptible;
  2289. int ret;
  2290. /* Big Hammer, we also need to ensure that any pending
  2291. * MI_WAIT_FOR_EVENT inside a user batch buffer on the
  2292. * current scanout is retired before unpinning the old
  2293. * framebuffer.
  2294. *
  2295. * This should only fail upon a hung GPU, in which case we
  2296. * can safely continue.
  2297. */
  2298. dev_priv->mm.interruptible = false;
  2299. ret = i915_gem_object_finish_gpu(obj);
  2300. dev_priv->mm.interruptible = was_interruptible;
  2301. return ret;
  2302. }
  2303. static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc)
  2304. {
  2305. struct drm_device *dev = crtc->dev;
  2306. struct drm_i915_private *dev_priv = dev->dev_private;
  2307. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2308. unsigned long flags;
  2309. bool pending;
  2310. if (i915_reset_in_progress(&dev_priv->gpu_error) ||
  2311. intel_crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter))
  2312. return false;
  2313. spin_lock_irqsave(&dev->event_lock, flags);
  2314. pending = to_intel_crtc(crtc)->unpin_work != NULL;
  2315. spin_unlock_irqrestore(&dev->event_lock, flags);
  2316. return pending;
  2317. }
  2318. static int
  2319. intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
  2320. struct drm_framebuffer *fb)
  2321. {
  2322. struct drm_device *dev = crtc->dev;
  2323. struct drm_i915_private *dev_priv = dev->dev_private;
  2324. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2325. enum pipe pipe = intel_crtc->pipe;
  2326. struct drm_framebuffer *old_fb;
  2327. struct drm_i915_gem_object *obj = to_intel_framebuffer(fb)->obj;
  2328. struct drm_i915_gem_object *old_obj;
  2329. int ret;
  2330. if (intel_crtc_has_pending_flip(crtc)) {
  2331. DRM_ERROR("pipe is still busy with an old pageflip\n");
  2332. return -EBUSY;
  2333. }
  2334. /* no fb bound */
  2335. if (!fb) {
  2336. DRM_ERROR("No FB bound\n");
  2337. return 0;
  2338. }
  2339. if (intel_crtc->plane > INTEL_INFO(dev)->num_pipes) {
  2340. DRM_ERROR("no plane for crtc: plane %c, num_pipes %d\n",
  2341. plane_name(intel_crtc->plane),
  2342. INTEL_INFO(dev)->num_pipes);
  2343. return -EINVAL;
  2344. }
  2345. old_fb = crtc->primary->fb;
  2346. old_obj = old_fb ? to_intel_framebuffer(old_fb)->obj : NULL;
  2347. mutex_lock(&dev->struct_mutex);
  2348. ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
  2349. if (ret == 0)
  2350. i915_gem_track_fb(old_obj, obj,
  2351. INTEL_FRONTBUFFER_PRIMARY(pipe));
  2352. mutex_unlock(&dev->struct_mutex);
  2353. if (ret != 0) {
  2354. DRM_ERROR("pin & fence failed\n");
  2355. return ret;
  2356. }
  2357. /*
  2358. * Update pipe size and adjust fitter if needed: the reason for this is
  2359. * that in compute_mode_changes we check the native mode (not the pfit
  2360. * mode) to see if we can flip rather than do a full mode set. In the
  2361. * fastboot case, we'll flip, but if we don't update the pipesrc and
  2362. * pfit state, we'll end up with a big fb scanned out into the wrong
  2363. * sized surface.
  2364. *
  2365. * To fix this properly, we need to hoist the checks up into
  2366. * compute_mode_changes (or above), check the actual pfit state and
  2367. * whether the platform allows pfit disable with pipe active, and only
  2368. * then update the pipesrc and pfit state, even on the flip path.
  2369. */
  2370. if (i915.fastboot) {
  2371. const struct drm_display_mode *adjusted_mode =
  2372. &intel_crtc->config.adjusted_mode;
  2373. I915_WRITE(PIPESRC(intel_crtc->pipe),
  2374. ((adjusted_mode->crtc_hdisplay - 1) << 16) |
  2375. (adjusted_mode->crtc_vdisplay - 1));
  2376. if (!intel_crtc->config.pch_pfit.enabled &&
  2377. (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) ||
  2378. intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) {
  2379. I915_WRITE(PF_CTL(intel_crtc->pipe), 0);
  2380. I915_WRITE(PF_WIN_POS(intel_crtc->pipe), 0);
  2381. I915_WRITE(PF_WIN_SZ(intel_crtc->pipe), 0);
  2382. }
  2383. intel_crtc->config.pipe_src_w = adjusted_mode->crtc_hdisplay;
  2384. intel_crtc->config.pipe_src_h = adjusted_mode->crtc_vdisplay;
  2385. }
  2386. dev_priv->display.update_primary_plane(crtc, fb, x, y);
  2387. if (intel_crtc->active)
  2388. intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_PRIMARY(pipe));
  2389. crtc->primary->fb = fb;
  2390. crtc->x = x;
  2391. crtc->y = y;
  2392. if (old_fb) {
  2393. if (intel_crtc->active && old_fb != fb)
  2394. intel_wait_for_vblank(dev, intel_crtc->pipe);
  2395. mutex_lock(&dev->struct_mutex);
  2396. intel_unpin_fb_obj(to_intel_framebuffer(old_fb)->obj);
  2397. mutex_unlock(&dev->struct_mutex);
  2398. }
  2399. mutex_lock(&dev->struct_mutex);
  2400. intel_update_fbc(dev);
  2401. mutex_unlock(&dev->struct_mutex);
  2402. return 0;
  2403. }
  2404. static void intel_fdi_normal_train(struct drm_crtc *crtc)
  2405. {
  2406. struct drm_device *dev = crtc->dev;
  2407. struct drm_i915_private *dev_priv = dev->dev_private;
  2408. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2409. int pipe = intel_crtc->pipe;
  2410. u32 reg, temp;
  2411. /* enable normal train */
  2412. reg = FDI_TX_CTL(pipe);
  2413. temp = I915_READ(reg);
  2414. if (IS_IVYBRIDGE(dev)) {
  2415. temp &= ~FDI_LINK_TRAIN_NONE_IVB;
  2416. temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
  2417. } else {
  2418. temp &= ~FDI_LINK_TRAIN_NONE;
  2419. temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
  2420. }
  2421. I915_WRITE(reg, temp);
  2422. reg = FDI_RX_CTL(pipe);
  2423. temp = I915_READ(reg);
  2424. if (HAS_PCH_CPT(dev)) {
  2425. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2426. temp |= FDI_LINK_TRAIN_NORMAL_CPT;
  2427. } else {
  2428. temp &= ~FDI_LINK_TRAIN_NONE;
  2429. temp |= FDI_LINK_TRAIN_NONE;
  2430. }
  2431. I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
  2432. /* wait one idle pattern time */
  2433. POSTING_READ(reg);
  2434. udelay(1000);
  2435. /* IVB wants error correction enabled */
  2436. if (IS_IVYBRIDGE(dev))
  2437. I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
  2438. FDI_FE_ERRC_ENABLE);
  2439. }
  2440. static bool pipe_has_enabled_pch(struct intel_crtc *crtc)
  2441. {
  2442. return crtc->base.enabled && crtc->active &&
  2443. crtc->config.has_pch_encoder;
  2444. }
  2445. static void ivb_modeset_global_resources(struct drm_device *dev)
  2446. {
  2447. struct drm_i915_private *dev_priv = dev->dev_private;
  2448. struct intel_crtc *pipe_B_crtc =
  2449. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]);
  2450. struct intel_crtc *pipe_C_crtc =
  2451. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_C]);
  2452. uint32_t temp;
  2453. /*
  2454. * When everything is off disable fdi C so that we could enable fdi B
  2455. * with all lanes. Note that we don't care about enabled pipes without
  2456. * an enabled pch encoder.
  2457. */
  2458. if (!pipe_has_enabled_pch(pipe_B_crtc) &&
  2459. !pipe_has_enabled_pch(pipe_C_crtc)) {
  2460. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
  2461. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
  2462. temp = I915_READ(SOUTH_CHICKEN1);
  2463. temp &= ~FDI_BC_BIFURCATION_SELECT;
  2464. DRM_DEBUG_KMS("disabling fdi C rx\n");
  2465. I915_WRITE(SOUTH_CHICKEN1, temp);
  2466. }
  2467. }
  2468. /* The FDI link training functions for ILK/Ibexpeak. */
  2469. static void ironlake_fdi_link_train(struct drm_crtc *crtc)
  2470. {
  2471. struct drm_device *dev = crtc->dev;
  2472. struct drm_i915_private *dev_priv = dev->dev_private;
  2473. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2474. int pipe = intel_crtc->pipe;
  2475. u32 reg, temp, tries;
  2476. /* FDI needs bits from pipe first */
  2477. assert_pipe_enabled(dev_priv, pipe);
  2478. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2479. for train result */
  2480. reg = FDI_RX_IMR(pipe);
  2481. temp = I915_READ(reg);
  2482. temp &= ~FDI_RX_SYMBOL_LOCK;
  2483. temp &= ~FDI_RX_BIT_LOCK;
  2484. I915_WRITE(reg, temp);
  2485. I915_READ(reg);
  2486. udelay(150);
  2487. /* enable CPU FDI TX and PCH FDI RX */
  2488. reg = FDI_TX_CTL(pipe);
  2489. temp = I915_READ(reg);
  2490. temp &= ~FDI_DP_PORT_WIDTH_MASK;
  2491. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2492. temp &= ~FDI_LINK_TRAIN_NONE;
  2493. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2494. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2495. reg = FDI_RX_CTL(pipe);
  2496. temp = I915_READ(reg);
  2497. temp &= ~FDI_LINK_TRAIN_NONE;
  2498. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2499. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2500. POSTING_READ(reg);
  2501. udelay(150);
  2502. /* Ironlake workaround, enable clock pointer after FDI enable*/
  2503. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
  2504. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
  2505. FDI_RX_PHASE_SYNC_POINTER_EN);
  2506. reg = FDI_RX_IIR(pipe);
  2507. for (tries = 0; tries < 5; tries++) {
  2508. temp = I915_READ(reg);
  2509. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2510. if ((temp & FDI_RX_BIT_LOCK)) {
  2511. DRM_DEBUG_KMS("FDI train 1 done.\n");
  2512. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2513. break;
  2514. }
  2515. }
  2516. if (tries == 5)
  2517. DRM_ERROR("FDI train 1 fail!\n");
  2518. /* Train 2 */
  2519. reg = FDI_TX_CTL(pipe);
  2520. temp = I915_READ(reg);
  2521. temp &= ~FDI_LINK_TRAIN_NONE;
  2522. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2523. I915_WRITE(reg, temp);
  2524. reg = FDI_RX_CTL(pipe);
  2525. temp = I915_READ(reg);
  2526. temp &= ~FDI_LINK_TRAIN_NONE;
  2527. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2528. I915_WRITE(reg, temp);
  2529. POSTING_READ(reg);
  2530. udelay(150);
  2531. reg = FDI_RX_IIR(pipe);
  2532. for (tries = 0; tries < 5; tries++) {
  2533. temp = I915_READ(reg);
  2534. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2535. if (temp & FDI_RX_SYMBOL_LOCK) {
  2536. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2537. DRM_DEBUG_KMS("FDI train 2 done.\n");
  2538. break;
  2539. }
  2540. }
  2541. if (tries == 5)
  2542. DRM_ERROR("FDI train 2 fail!\n");
  2543. DRM_DEBUG_KMS("FDI train done\n");
  2544. }
  2545. static const int snb_b_fdi_train_param[] = {
  2546. FDI_LINK_TRAIN_400MV_0DB_SNB_B,
  2547. FDI_LINK_TRAIN_400MV_6DB_SNB_B,
  2548. FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
  2549. FDI_LINK_TRAIN_800MV_0DB_SNB_B,
  2550. };
  2551. /* The FDI link training functions for SNB/Cougarpoint. */
  2552. static void gen6_fdi_link_train(struct drm_crtc *crtc)
  2553. {
  2554. struct drm_device *dev = crtc->dev;
  2555. struct drm_i915_private *dev_priv = dev->dev_private;
  2556. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2557. int pipe = intel_crtc->pipe;
  2558. u32 reg, temp, i, retry;
  2559. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2560. for train result */
  2561. reg = FDI_RX_IMR(pipe);
  2562. temp = I915_READ(reg);
  2563. temp &= ~FDI_RX_SYMBOL_LOCK;
  2564. temp &= ~FDI_RX_BIT_LOCK;
  2565. I915_WRITE(reg, temp);
  2566. POSTING_READ(reg);
  2567. udelay(150);
  2568. /* enable CPU FDI TX and PCH FDI RX */
  2569. reg = FDI_TX_CTL(pipe);
  2570. temp = I915_READ(reg);
  2571. temp &= ~FDI_DP_PORT_WIDTH_MASK;
  2572. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2573. temp &= ~FDI_LINK_TRAIN_NONE;
  2574. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2575. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2576. /* SNB-B */
  2577. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2578. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2579. I915_WRITE(FDI_RX_MISC(pipe),
  2580. FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
  2581. reg = FDI_RX_CTL(pipe);
  2582. temp = I915_READ(reg);
  2583. if (HAS_PCH_CPT(dev)) {
  2584. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2585. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2586. } else {
  2587. temp &= ~FDI_LINK_TRAIN_NONE;
  2588. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2589. }
  2590. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2591. POSTING_READ(reg);
  2592. udelay(150);
  2593. for (i = 0; i < 4; i++) {
  2594. reg = FDI_TX_CTL(pipe);
  2595. temp = I915_READ(reg);
  2596. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2597. temp |= snb_b_fdi_train_param[i];
  2598. I915_WRITE(reg, temp);
  2599. POSTING_READ(reg);
  2600. udelay(500);
  2601. for (retry = 0; retry < 5; retry++) {
  2602. reg = FDI_RX_IIR(pipe);
  2603. temp = I915_READ(reg);
  2604. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2605. if (temp & FDI_RX_BIT_LOCK) {
  2606. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2607. DRM_DEBUG_KMS("FDI train 1 done.\n");
  2608. break;
  2609. }
  2610. udelay(50);
  2611. }
  2612. if (retry < 5)
  2613. break;
  2614. }
  2615. if (i == 4)
  2616. DRM_ERROR("FDI train 1 fail!\n");
  2617. /* Train 2 */
  2618. reg = FDI_TX_CTL(pipe);
  2619. temp = I915_READ(reg);
  2620. temp &= ~FDI_LINK_TRAIN_NONE;
  2621. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2622. if (IS_GEN6(dev)) {
  2623. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2624. /* SNB-B */
  2625. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2626. }
  2627. I915_WRITE(reg, temp);
  2628. reg = FDI_RX_CTL(pipe);
  2629. temp = I915_READ(reg);
  2630. if (HAS_PCH_CPT(dev)) {
  2631. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2632. temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
  2633. } else {
  2634. temp &= ~FDI_LINK_TRAIN_NONE;
  2635. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2636. }
  2637. I915_WRITE(reg, temp);
  2638. POSTING_READ(reg);
  2639. udelay(150);
  2640. for (i = 0; i < 4; i++) {
  2641. reg = FDI_TX_CTL(pipe);
  2642. temp = I915_READ(reg);
  2643. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2644. temp |= snb_b_fdi_train_param[i];
  2645. I915_WRITE(reg, temp);
  2646. POSTING_READ(reg);
  2647. udelay(500);
  2648. for (retry = 0; retry < 5; retry++) {
  2649. reg = FDI_RX_IIR(pipe);
  2650. temp = I915_READ(reg);
  2651. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2652. if (temp & FDI_RX_SYMBOL_LOCK) {
  2653. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2654. DRM_DEBUG_KMS("FDI train 2 done.\n");
  2655. break;
  2656. }
  2657. udelay(50);
  2658. }
  2659. if (retry < 5)
  2660. break;
  2661. }
  2662. if (i == 4)
  2663. DRM_ERROR("FDI train 2 fail!\n");
  2664. DRM_DEBUG_KMS("FDI train done.\n");
  2665. }
  2666. /* Manual link training for Ivy Bridge A0 parts */
  2667. static void ivb_manual_fdi_link_train(struct drm_crtc *crtc)
  2668. {
  2669. struct drm_device *dev = crtc->dev;
  2670. struct drm_i915_private *dev_priv = dev->dev_private;
  2671. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2672. int pipe = intel_crtc->pipe;
  2673. u32 reg, temp, i, j;
  2674. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2675. for train result */
  2676. reg = FDI_RX_IMR(pipe);
  2677. temp = I915_READ(reg);
  2678. temp &= ~FDI_RX_SYMBOL_LOCK;
  2679. temp &= ~FDI_RX_BIT_LOCK;
  2680. I915_WRITE(reg, temp);
  2681. POSTING_READ(reg);
  2682. udelay(150);
  2683. DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
  2684. I915_READ(FDI_RX_IIR(pipe)));
  2685. /* Try each vswing and preemphasis setting twice before moving on */
  2686. for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) {
  2687. /* disable first in case we need to retry */
  2688. reg = FDI_TX_CTL(pipe);
  2689. temp = I915_READ(reg);
  2690. temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
  2691. temp &= ~FDI_TX_ENABLE;
  2692. I915_WRITE(reg, temp);
  2693. reg = FDI_RX_CTL(pipe);
  2694. temp = I915_READ(reg);
  2695. temp &= ~FDI_LINK_TRAIN_AUTO;
  2696. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2697. temp &= ~FDI_RX_ENABLE;
  2698. I915_WRITE(reg, temp);
  2699. /* enable CPU FDI TX and PCH FDI RX */
  2700. reg = FDI_TX_CTL(pipe);
  2701. temp = I915_READ(reg);
  2702. temp &= ~FDI_DP_PORT_WIDTH_MASK;
  2703. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2704. temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
  2705. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2706. temp |= snb_b_fdi_train_param[j/2];
  2707. temp |= FDI_COMPOSITE_SYNC;
  2708. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2709. I915_WRITE(FDI_RX_MISC(pipe),
  2710. FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
  2711. reg = FDI_RX_CTL(pipe);
  2712. temp = I915_READ(reg);
  2713. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2714. temp |= FDI_COMPOSITE_SYNC;
  2715. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2716. POSTING_READ(reg);
  2717. udelay(1); /* should be 0.5us */
  2718. for (i = 0; i < 4; i++) {
  2719. reg = FDI_RX_IIR(pipe);
  2720. temp = I915_READ(reg);
  2721. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2722. if (temp & FDI_RX_BIT_LOCK ||
  2723. (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
  2724. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2725. DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
  2726. i);
  2727. break;
  2728. }
  2729. udelay(1); /* should be 0.5us */
  2730. }
  2731. if (i == 4) {
  2732. DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2);
  2733. continue;
  2734. }
  2735. /* Train 2 */
  2736. reg = FDI_TX_CTL(pipe);
  2737. temp = I915_READ(reg);
  2738. temp &= ~FDI_LINK_TRAIN_NONE_IVB;
  2739. temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
  2740. I915_WRITE(reg, temp);
  2741. reg = FDI_RX_CTL(pipe);
  2742. temp = I915_READ(reg);
  2743. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2744. temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
  2745. I915_WRITE(reg, temp);
  2746. POSTING_READ(reg);
  2747. udelay(2); /* should be 1.5us */
  2748. for (i = 0; i < 4; i++) {
  2749. reg = FDI_RX_IIR(pipe);
  2750. temp = I915_READ(reg);
  2751. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2752. if (temp & FDI_RX_SYMBOL_LOCK ||
  2753. (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) {
  2754. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2755. DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
  2756. i);
  2757. goto train_done;
  2758. }
  2759. udelay(2); /* should be 1.5us */
  2760. }
  2761. if (i == 4)
  2762. DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2);
  2763. }
  2764. train_done:
  2765. DRM_DEBUG_KMS("FDI train done.\n");
  2766. }
  2767. static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc)
  2768. {
  2769. struct drm_device *dev = intel_crtc->base.dev;
  2770. struct drm_i915_private *dev_priv = dev->dev_private;
  2771. int pipe = intel_crtc->pipe;
  2772. u32 reg, temp;
  2773. /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
  2774. reg = FDI_RX_CTL(pipe);
  2775. temp = I915_READ(reg);
  2776. temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16));
  2777. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2778. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2779. I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
  2780. POSTING_READ(reg);
  2781. udelay(200);
  2782. /* Switch from Rawclk to PCDclk */
  2783. temp = I915_READ(reg);
  2784. I915_WRITE(reg, temp | FDI_PCDCLK);
  2785. POSTING_READ(reg);
  2786. udelay(200);
  2787. /* Enable CPU FDI TX PLL, always on for Ironlake */
  2788. reg = FDI_TX_CTL(pipe);
  2789. temp = I915_READ(reg);
  2790. if ((temp & FDI_TX_PLL_ENABLE) == 0) {
  2791. I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
  2792. POSTING_READ(reg);
  2793. udelay(100);
  2794. }
  2795. }
  2796. static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
  2797. {
  2798. struct drm_device *dev = intel_crtc->base.dev;
  2799. struct drm_i915_private *dev_priv = dev->dev_private;
  2800. int pipe = intel_crtc->pipe;
  2801. u32 reg, temp;
  2802. /* Switch from PCDclk to Rawclk */
  2803. reg = FDI_RX_CTL(pipe);
  2804. temp = I915_READ(reg);
  2805. I915_WRITE(reg, temp & ~FDI_PCDCLK);
  2806. /* Disable CPU FDI TX PLL */
  2807. reg = FDI_TX_CTL(pipe);
  2808. temp = I915_READ(reg);
  2809. I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
  2810. POSTING_READ(reg);
  2811. udelay(100);
  2812. reg = FDI_RX_CTL(pipe);
  2813. temp = I915_READ(reg);
  2814. I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
  2815. /* Wait for the clocks to turn off. */
  2816. POSTING_READ(reg);
  2817. udelay(100);
  2818. }
  2819. static void ironlake_fdi_disable(struct drm_crtc *crtc)
  2820. {
  2821. struct drm_device *dev = crtc->dev;
  2822. struct drm_i915_private *dev_priv = dev->dev_private;
  2823. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2824. int pipe = intel_crtc->pipe;
  2825. u32 reg, temp;
  2826. /* disable CPU FDI tx and PCH FDI rx */
  2827. reg = FDI_TX_CTL(pipe);
  2828. temp = I915_READ(reg);
  2829. I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
  2830. POSTING_READ(reg);
  2831. reg = FDI_RX_CTL(pipe);
  2832. temp = I915_READ(reg);
  2833. temp &= ~(0x7 << 16);
  2834. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2835. I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
  2836. POSTING_READ(reg);
  2837. udelay(100);
  2838. /* Ironlake workaround, disable clock pointer after downing FDI */
  2839. if (HAS_PCH_IBX(dev))
  2840. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
  2841. /* still set train pattern 1 */
  2842. reg = FDI_TX_CTL(pipe);
  2843. temp = I915_READ(reg);
  2844. temp &= ~FDI_LINK_TRAIN_NONE;
  2845. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2846. I915_WRITE(reg, temp);
  2847. reg = FDI_RX_CTL(pipe);
  2848. temp = I915_READ(reg);
  2849. if (HAS_PCH_CPT(dev)) {
  2850. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2851. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2852. } else {
  2853. temp &= ~FDI_LINK_TRAIN_NONE;
  2854. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2855. }
  2856. /* BPC in FDI rx is consistent with that in PIPECONF */
  2857. temp &= ~(0x07 << 16);
  2858. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2859. I915_WRITE(reg, temp);
  2860. POSTING_READ(reg);
  2861. udelay(100);
  2862. }
  2863. bool intel_has_pending_fb_unpin(struct drm_device *dev)
  2864. {
  2865. struct intel_crtc *crtc;
  2866. /* Note that we don't need to be called with mode_config.lock here
  2867. * as our list of CRTC objects is static for the lifetime of the
  2868. * device and so cannot disappear as we iterate. Similarly, we can
  2869. * happily treat the predicates as racy, atomic checks as userspace
  2870. * cannot claim and pin a new fb without at least acquring the
  2871. * struct_mutex and so serialising with us.
  2872. */
  2873. for_each_intel_crtc(dev, crtc) {
  2874. if (atomic_read(&crtc->unpin_work_count) == 0)
  2875. continue;
  2876. if (crtc->unpin_work)
  2877. intel_wait_for_vblank(dev, crtc->pipe);
  2878. return true;
  2879. }
  2880. return false;
  2881. }
  2882. void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
  2883. {
  2884. struct drm_device *dev = crtc->dev;
  2885. struct drm_i915_private *dev_priv = dev->dev_private;
  2886. if (crtc->primary->fb == NULL)
  2887. return;
  2888. WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue));
  2889. WARN_ON(wait_event_timeout(dev_priv->pending_flip_queue,
  2890. !intel_crtc_has_pending_flip(crtc),
  2891. 60*HZ) == 0);
  2892. mutex_lock(&dev->struct_mutex);
  2893. intel_finish_fb(crtc->primary->fb);
  2894. mutex_unlock(&dev->struct_mutex);
  2895. }
  2896. /* Program iCLKIP clock to the desired frequency */
  2897. static void lpt_program_iclkip(struct drm_crtc *crtc)
  2898. {
  2899. struct drm_device *dev = crtc->dev;
  2900. struct drm_i915_private *dev_priv = dev->dev_private;
  2901. int clock = to_intel_crtc(crtc)->config.adjusted_mode.crtc_clock;
  2902. u32 divsel, phaseinc, auxdiv, phasedir = 0;
  2903. u32 temp;
  2904. mutex_lock(&dev_priv->dpio_lock);
  2905. /* It is necessary to ungate the pixclk gate prior to programming
  2906. * the divisors, and gate it back when it is done.
  2907. */
  2908. I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
  2909. /* Disable SSCCTL */
  2910. intel_sbi_write(dev_priv, SBI_SSCCTL6,
  2911. intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK) |
  2912. SBI_SSCCTL_DISABLE,
  2913. SBI_ICLK);
  2914. /* 20MHz is a corner case which is out of range for the 7-bit divisor */
  2915. if (clock == 20000) {
  2916. auxdiv = 1;
  2917. divsel = 0x41;
  2918. phaseinc = 0x20;
  2919. } else {
  2920. /* The iCLK virtual clock root frequency is in MHz,
  2921. * but the adjusted_mode->crtc_clock in in KHz. To get the
  2922. * divisors, it is necessary to divide one by another, so we
  2923. * convert the virtual clock precision to KHz here for higher
  2924. * precision.
  2925. */
  2926. u32 iclk_virtual_root_freq = 172800 * 1000;
  2927. u32 iclk_pi_range = 64;
  2928. u32 desired_divisor, msb_divisor_value, pi_value;
  2929. desired_divisor = (iclk_virtual_root_freq / clock);
  2930. msb_divisor_value = desired_divisor / iclk_pi_range;
  2931. pi_value = desired_divisor % iclk_pi_range;
  2932. auxdiv = 0;
  2933. divsel = msb_divisor_value - 2;
  2934. phaseinc = pi_value;
  2935. }
  2936. /* This should not happen with any sane values */
  2937. WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
  2938. ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
  2939. WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) &
  2940. ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
  2941. DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
  2942. clock,
  2943. auxdiv,
  2944. divsel,
  2945. phasedir,
  2946. phaseinc);
  2947. /* Program SSCDIVINTPHASE6 */
  2948. temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
  2949. temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
  2950. temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
  2951. temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
  2952. temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
  2953. temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
  2954. temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
  2955. intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
  2956. /* Program SSCAUXDIV */
  2957. temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
  2958. temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
  2959. temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
  2960. intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
  2961. /* Enable modulator and associated divider */
  2962. temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
  2963. temp &= ~SBI_SSCCTL_DISABLE;
  2964. intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
  2965. /* Wait for initialization time */
  2966. udelay(24);
  2967. I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE);
  2968. mutex_unlock(&dev_priv->dpio_lock);
  2969. }
  2970. static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc,
  2971. enum pipe pch_transcoder)
  2972. {
  2973. struct drm_device *dev = crtc->base.dev;
  2974. struct drm_i915_private *dev_priv = dev->dev_private;
  2975. enum transcoder cpu_transcoder = crtc->config.cpu_transcoder;
  2976. I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder),
  2977. I915_READ(HTOTAL(cpu_transcoder)));
  2978. I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder),
  2979. I915_READ(HBLANK(cpu_transcoder)));
  2980. I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder),
  2981. I915_READ(HSYNC(cpu_transcoder)));
  2982. I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder),
  2983. I915_READ(VTOTAL(cpu_transcoder)));
  2984. I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder),
  2985. I915_READ(VBLANK(cpu_transcoder)));
  2986. I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder),
  2987. I915_READ(VSYNC(cpu_transcoder)));
  2988. I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder),
  2989. I915_READ(VSYNCSHIFT(cpu_transcoder)));
  2990. }
  2991. static void cpt_enable_fdi_bc_bifurcation(struct drm_device *dev)
  2992. {
  2993. struct drm_i915_private *dev_priv = dev->dev_private;
  2994. uint32_t temp;
  2995. temp = I915_READ(SOUTH_CHICKEN1);
  2996. if (temp & FDI_BC_BIFURCATION_SELECT)
  2997. return;
  2998. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
  2999. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
  3000. temp |= FDI_BC_BIFURCATION_SELECT;
  3001. DRM_DEBUG_KMS("enabling fdi C rx\n");
  3002. I915_WRITE(SOUTH_CHICKEN1, temp);
  3003. POSTING_READ(SOUTH_CHICKEN1);
  3004. }
  3005. static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc)
  3006. {
  3007. struct drm_device *dev = intel_crtc->base.dev;
  3008. struct drm_i915_private *dev_priv = dev->dev_private;
  3009. switch (intel_crtc->pipe) {
  3010. case PIPE_A:
  3011. break;
  3012. case PIPE_B:
  3013. if (intel_crtc->config.fdi_lanes > 2)
  3014. WARN_ON(I915_READ(SOUTH_CHICKEN1) & FDI_BC_BIFURCATION_SELECT);
  3015. else
  3016. cpt_enable_fdi_bc_bifurcation(dev);
  3017. break;
  3018. case PIPE_C:
  3019. cpt_enable_fdi_bc_bifurcation(dev);
  3020. break;
  3021. default:
  3022. BUG();
  3023. }
  3024. }
  3025. /*
  3026. * Enable PCH resources required for PCH ports:
  3027. * - PCH PLLs
  3028. * - FDI training & RX/TX
  3029. * - update transcoder timings
  3030. * - DP transcoding bits
  3031. * - transcoder
  3032. */
  3033. static void ironlake_pch_enable(struct drm_crtc *crtc)
  3034. {
  3035. struct drm_device *dev = crtc->dev;
  3036. struct drm_i915_private *dev_priv = dev->dev_private;
  3037. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3038. int pipe = intel_crtc->pipe;
  3039. u32 reg, temp;
  3040. assert_pch_transcoder_disabled(dev_priv, pipe);
  3041. if (IS_IVYBRIDGE(dev))
  3042. ivybridge_update_fdi_bc_bifurcation(intel_crtc);
  3043. /* Write the TU size bits before fdi link training, so that error
  3044. * detection works. */
  3045. I915_WRITE(FDI_RX_TUSIZE1(pipe),
  3046. I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
  3047. /* For PCH output, training FDI link */
  3048. dev_priv->display.fdi_link_train(crtc);
  3049. /* We need to program the right clock selection before writing the pixel
  3050. * mutliplier into the DPLL. */
  3051. if (HAS_PCH_CPT(dev)) {
  3052. u32 sel;
  3053. temp = I915_READ(PCH_DPLL_SEL);
  3054. temp |= TRANS_DPLL_ENABLE(pipe);
  3055. sel = TRANS_DPLLB_SEL(pipe);
  3056. if (intel_crtc->config.shared_dpll == DPLL_ID_PCH_PLL_B)
  3057. temp |= sel;
  3058. else
  3059. temp &= ~sel;
  3060. I915_WRITE(PCH_DPLL_SEL, temp);
  3061. }
  3062. /* XXX: pch pll's can be enabled any time before we enable the PCH
  3063. * transcoder, and we actually should do this to not upset any PCH
  3064. * transcoder that already use the clock when we share it.
  3065. *
  3066. * Note that enable_shared_dpll tries to do the right thing, but
  3067. * get_shared_dpll unconditionally resets the pll - we need that to have
  3068. * the right LVDS enable sequence. */
  3069. intel_enable_shared_dpll(intel_crtc);
  3070. /* set transcoder timing, panel must allow it */
  3071. assert_panel_unlocked(dev_priv, pipe);
  3072. ironlake_pch_transcoder_set_timings(intel_crtc, pipe);
  3073. intel_fdi_normal_train(crtc);
  3074. /* For PCH DP, enable TRANS_DP_CTL */
  3075. if (HAS_PCH_CPT(dev) &&
  3076. (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) ||
  3077. intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) {
  3078. u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
  3079. reg = TRANS_DP_CTL(pipe);
  3080. temp = I915_READ(reg);
  3081. temp &= ~(TRANS_DP_PORT_SEL_MASK |
  3082. TRANS_DP_SYNC_MASK |
  3083. TRANS_DP_BPC_MASK);
  3084. temp |= (TRANS_DP_OUTPUT_ENABLE |
  3085. TRANS_DP_ENH_FRAMING);
  3086. temp |= bpc << 9; /* same format but at 11:9 */
  3087. if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC)
  3088. temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
  3089. if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC)
  3090. temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
  3091. switch (intel_trans_dp_port_sel(crtc)) {
  3092. case PCH_DP_B:
  3093. temp |= TRANS_DP_PORT_SEL_B;
  3094. break;
  3095. case PCH_DP_C:
  3096. temp |= TRANS_DP_PORT_SEL_C;
  3097. break;
  3098. case PCH_DP_D:
  3099. temp |= TRANS_DP_PORT_SEL_D;
  3100. break;
  3101. default:
  3102. BUG();
  3103. }
  3104. I915_WRITE(reg, temp);
  3105. }
  3106. ironlake_enable_pch_transcoder(dev_priv, pipe);
  3107. }
  3108. static void lpt_pch_enable(struct drm_crtc *crtc)
  3109. {
  3110. struct drm_device *dev = crtc->dev;
  3111. struct drm_i915_private *dev_priv = dev->dev_private;
  3112. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3113. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  3114. assert_pch_transcoder_disabled(dev_priv, TRANSCODER_A);
  3115. lpt_program_iclkip(crtc);
  3116. /* Set transcoder timing. */
  3117. ironlake_pch_transcoder_set_timings(intel_crtc, PIPE_A);
  3118. lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
  3119. }
  3120. static void intel_put_shared_dpll(struct intel_crtc *crtc)
  3121. {
  3122. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  3123. if (pll == NULL)
  3124. return;
  3125. if (pll->refcount == 0) {
  3126. WARN(1, "bad %s refcount\n", pll->name);
  3127. return;
  3128. }
  3129. if (--pll->refcount == 0) {
  3130. WARN_ON(pll->on);
  3131. WARN_ON(pll->active);
  3132. }
  3133. crtc->config.shared_dpll = DPLL_ID_PRIVATE;
  3134. }
  3135. static struct intel_shared_dpll *intel_get_shared_dpll(struct intel_crtc *crtc)
  3136. {
  3137. struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
  3138. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  3139. enum intel_dpll_id i;
  3140. if (pll) {
  3141. DRM_DEBUG_KMS("CRTC:%d dropping existing %s\n",
  3142. crtc->base.base.id, pll->name);
  3143. intel_put_shared_dpll(crtc);
  3144. }
  3145. if (HAS_PCH_IBX(dev_priv->dev)) {
  3146. /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */
  3147. i = (enum intel_dpll_id) crtc->pipe;
  3148. pll = &dev_priv->shared_dplls[i];
  3149. DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n",
  3150. crtc->base.base.id, pll->name);
  3151. WARN_ON(pll->refcount);
  3152. goto found;
  3153. }
  3154. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  3155. pll = &dev_priv->shared_dplls[i];
  3156. /* Only want to check enabled timings first */
  3157. if (pll->refcount == 0)
  3158. continue;
  3159. if (memcmp(&crtc->config.dpll_hw_state, &pll->hw_state,
  3160. sizeof(pll->hw_state)) == 0) {
  3161. DRM_DEBUG_KMS("CRTC:%d sharing existing %s (refcount %d, ative %d)\n",
  3162. crtc->base.base.id,
  3163. pll->name, pll->refcount, pll->active);
  3164. goto found;
  3165. }
  3166. }
  3167. /* Ok no matching timings, maybe there's a free one? */
  3168. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  3169. pll = &dev_priv->shared_dplls[i];
  3170. if (pll->refcount == 0) {
  3171. DRM_DEBUG_KMS("CRTC:%d allocated %s\n",
  3172. crtc->base.base.id, pll->name);
  3173. goto found;
  3174. }
  3175. }
  3176. return NULL;
  3177. found:
  3178. if (pll->refcount == 0)
  3179. pll->hw_state = crtc->config.dpll_hw_state;
  3180. crtc->config.shared_dpll = i;
  3181. DRM_DEBUG_DRIVER("using %s for pipe %c\n", pll->name,
  3182. pipe_name(crtc->pipe));
  3183. pll->refcount++;
  3184. return pll;
  3185. }
  3186. static void cpt_verify_modeset(struct drm_device *dev, int pipe)
  3187. {
  3188. struct drm_i915_private *dev_priv = dev->dev_private;
  3189. int dslreg = PIPEDSL(pipe);
  3190. u32 temp;
  3191. temp = I915_READ(dslreg);
  3192. udelay(500);
  3193. if (wait_for(I915_READ(dslreg) != temp, 5)) {
  3194. if (wait_for(I915_READ(dslreg) != temp, 5))
  3195. DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe));
  3196. }
  3197. }
  3198. static void ironlake_pfit_enable(struct intel_crtc *crtc)
  3199. {
  3200. struct drm_device *dev = crtc->base.dev;
  3201. struct drm_i915_private *dev_priv = dev->dev_private;
  3202. int pipe = crtc->pipe;
  3203. if (crtc->config.pch_pfit.enabled) {
  3204. /* Force use of hard-coded filter coefficients
  3205. * as some pre-programmed values are broken,
  3206. * e.g. x201.
  3207. */
  3208. if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev))
  3209. I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
  3210. PF_PIPE_SEL_IVB(pipe));
  3211. else
  3212. I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
  3213. I915_WRITE(PF_WIN_POS(pipe), crtc->config.pch_pfit.pos);
  3214. I915_WRITE(PF_WIN_SZ(pipe), crtc->config.pch_pfit.size);
  3215. }
  3216. }
  3217. static void intel_enable_planes(struct drm_crtc *crtc)
  3218. {
  3219. struct drm_device *dev = crtc->dev;
  3220. enum pipe pipe = to_intel_crtc(crtc)->pipe;
  3221. struct drm_plane *plane;
  3222. struct intel_plane *intel_plane;
  3223. drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) {
  3224. intel_plane = to_intel_plane(plane);
  3225. if (intel_plane->pipe == pipe)
  3226. intel_plane_restore(&intel_plane->base);
  3227. }
  3228. }
  3229. static void intel_disable_planes(struct drm_crtc *crtc)
  3230. {
  3231. struct drm_device *dev = crtc->dev;
  3232. enum pipe pipe = to_intel_crtc(crtc)->pipe;
  3233. struct drm_plane *plane;
  3234. struct intel_plane *intel_plane;
  3235. drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) {
  3236. intel_plane = to_intel_plane(plane);
  3237. if (intel_plane->pipe == pipe)
  3238. intel_plane_disable(&intel_plane->base);
  3239. }
  3240. }
  3241. void hsw_enable_ips(struct intel_crtc *crtc)
  3242. {
  3243. struct drm_device *dev = crtc->base.dev;
  3244. struct drm_i915_private *dev_priv = dev->dev_private;
  3245. if (!crtc->config.ips_enabled)
  3246. return;
  3247. /* We can only enable IPS after we enable a plane and wait for a vblank */
  3248. intel_wait_for_vblank(dev, crtc->pipe);
  3249. assert_plane_enabled(dev_priv, crtc->plane);
  3250. if (IS_BROADWELL(dev)) {
  3251. mutex_lock(&dev_priv->rps.hw_lock);
  3252. WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0xc0000000));
  3253. mutex_unlock(&dev_priv->rps.hw_lock);
  3254. /* Quoting Art Runyan: "its not safe to expect any particular
  3255. * value in IPS_CTL bit 31 after enabling IPS through the
  3256. * mailbox." Moreover, the mailbox may return a bogus state,
  3257. * so we need to just enable it and continue on.
  3258. */
  3259. } else {
  3260. I915_WRITE(IPS_CTL, IPS_ENABLE);
  3261. /* The bit only becomes 1 in the next vblank, so this wait here
  3262. * is essentially intel_wait_for_vblank. If we don't have this
  3263. * and don't wait for vblanks until the end of crtc_enable, then
  3264. * the HW state readout code will complain that the expected
  3265. * IPS_CTL value is not the one we read. */
  3266. if (wait_for(I915_READ_NOTRACE(IPS_CTL) & IPS_ENABLE, 50))
  3267. DRM_ERROR("Timed out waiting for IPS enable\n");
  3268. }
  3269. }
  3270. void hsw_disable_ips(struct intel_crtc *crtc)
  3271. {
  3272. struct drm_device *dev = crtc->base.dev;
  3273. struct drm_i915_private *dev_priv = dev->dev_private;
  3274. if (!crtc->config.ips_enabled)
  3275. return;
  3276. assert_plane_enabled(dev_priv, crtc->plane);
  3277. if (IS_BROADWELL(dev)) {
  3278. mutex_lock(&dev_priv->rps.hw_lock);
  3279. WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0));
  3280. mutex_unlock(&dev_priv->rps.hw_lock);
  3281. /* wait for pcode to finish disabling IPS, which may take up to 42ms */
  3282. if (wait_for((I915_READ(IPS_CTL) & IPS_ENABLE) == 0, 42))
  3283. DRM_ERROR("Timed out waiting for IPS disable\n");
  3284. } else {
  3285. I915_WRITE(IPS_CTL, 0);
  3286. POSTING_READ(IPS_CTL);
  3287. }
  3288. /* We need to wait for a vblank before we can disable the plane. */
  3289. intel_wait_for_vblank(dev, crtc->pipe);
  3290. }
  3291. /** Loads the palette/gamma unit for the CRTC with the prepared values */
  3292. static void intel_crtc_load_lut(struct drm_crtc *crtc)
  3293. {
  3294. struct drm_device *dev = crtc->dev;
  3295. struct drm_i915_private *dev_priv = dev->dev_private;
  3296. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3297. enum pipe pipe = intel_crtc->pipe;
  3298. int palreg = PALETTE(pipe);
  3299. int i;
  3300. bool reenable_ips = false;
  3301. /* The clocks have to be on to load the palette. */
  3302. if (!crtc->enabled || !intel_crtc->active)
  3303. return;
  3304. if (!HAS_PCH_SPLIT(dev_priv->dev)) {
  3305. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI))
  3306. assert_dsi_pll_enabled(dev_priv);
  3307. else
  3308. assert_pll_enabled(dev_priv, pipe);
  3309. }
  3310. /* use legacy palette for Ironlake */
  3311. if (HAS_PCH_SPLIT(dev))
  3312. palreg = LGC_PALETTE(pipe);
  3313. /* Workaround : Do not read or write the pipe palette/gamma data while
  3314. * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
  3315. */
  3316. if (IS_HASWELL(dev) && intel_crtc->config.ips_enabled &&
  3317. ((I915_READ(GAMMA_MODE(pipe)) & GAMMA_MODE_MODE_MASK) ==
  3318. GAMMA_MODE_MODE_SPLIT)) {
  3319. hsw_disable_ips(intel_crtc);
  3320. reenable_ips = true;
  3321. }
  3322. for (i = 0; i < 256; i++) {
  3323. I915_WRITE(palreg + 4 * i,
  3324. (intel_crtc->lut_r[i] << 16) |
  3325. (intel_crtc->lut_g[i] << 8) |
  3326. intel_crtc->lut_b[i]);
  3327. }
  3328. if (reenable_ips)
  3329. hsw_enable_ips(intel_crtc);
  3330. }
  3331. static void intel_crtc_dpms_overlay(struct intel_crtc *intel_crtc, bool enable)
  3332. {
  3333. if (!enable && intel_crtc->overlay) {
  3334. struct drm_device *dev = intel_crtc->base.dev;
  3335. struct drm_i915_private *dev_priv = dev->dev_private;
  3336. mutex_lock(&dev->struct_mutex);
  3337. dev_priv->mm.interruptible = false;
  3338. (void) intel_overlay_switch_off(intel_crtc->overlay);
  3339. dev_priv->mm.interruptible = true;
  3340. mutex_unlock(&dev->struct_mutex);
  3341. }
  3342. /* Let userspace switch the overlay on again. In most cases userspace
  3343. * has to recompute where to put it anyway.
  3344. */
  3345. }
  3346. /**
  3347. * i9xx_fixup_plane - ugly workaround for G45 to fire up the hardware
  3348. * cursor plane briefly if not already running after enabling the display
  3349. * plane.
  3350. * This workaround avoids occasional blank screens when self refresh is
  3351. * enabled.
  3352. */
  3353. static void
  3354. g4x_fixup_plane(struct drm_i915_private *dev_priv, enum pipe pipe)
  3355. {
  3356. u32 cntl = I915_READ(CURCNTR(pipe));
  3357. if ((cntl & CURSOR_MODE) == 0) {
  3358. u32 fw_bcl_self = I915_READ(FW_BLC_SELF);
  3359. I915_WRITE(FW_BLC_SELF, fw_bcl_self & ~FW_BLC_SELF_EN);
  3360. I915_WRITE(CURCNTR(pipe), CURSOR_MODE_64_ARGB_AX);
  3361. intel_wait_for_vblank(dev_priv->dev, pipe);
  3362. I915_WRITE(CURCNTR(pipe), cntl);
  3363. I915_WRITE(CURBASE(pipe), I915_READ(CURBASE(pipe)));
  3364. I915_WRITE(FW_BLC_SELF, fw_bcl_self);
  3365. }
  3366. }
  3367. static void intel_crtc_enable_planes(struct drm_crtc *crtc)
  3368. {
  3369. struct drm_device *dev = crtc->dev;
  3370. struct drm_i915_private *dev_priv = dev->dev_private;
  3371. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3372. int pipe = intel_crtc->pipe;
  3373. int plane = intel_crtc->plane;
  3374. drm_vblank_on(dev, pipe);
  3375. intel_enable_primary_hw_plane(dev_priv, plane, pipe);
  3376. intel_enable_planes(crtc);
  3377. /* The fixup needs to happen before cursor is enabled */
  3378. if (IS_G4X(dev))
  3379. g4x_fixup_plane(dev_priv, pipe);
  3380. intel_crtc_update_cursor(crtc, true);
  3381. intel_crtc_dpms_overlay(intel_crtc, true);
  3382. hsw_enable_ips(intel_crtc);
  3383. mutex_lock(&dev->struct_mutex);
  3384. intel_update_fbc(dev);
  3385. mutex_unlock(&dev->struct_mutex);
  3386. /*
  3387. * FIXME: Once we grow proper nuclear flip support out of this we need
  3388. * to compute the mask of flip planes precisely. For the time being
  3389. * consider this a flip from a NULL plane.
  3390. */
  3391. intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe));
  3392. }
  3393. static void intel_crtc_disable_planes(struct drm_crtc *crtc)
  3394. {
  3395. struct drm_device *dev = crtc->dev;
  3396. struct drm_i915_private *dev_priv = dev->dev_private;
  3397. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3398. int pipe = intel_crtc->pipe;
  3399. int plane = intel_crtc->plane;
  3400. intel_crtc_wait_for_pending_flips(crtc);
  3401. if (dev_priv->fbc.plane == plane)
  3402. intel_disable_fbc(dev);
  3403. hsw_disable_ips(intel_crtc);
  3404. intel_crtc_dpms_overlay(intel_crtc, false);
  3405. intel_crtc_update_cursor(crtc, false);
  3406. intel_disable_planes(crtc);
  3407. intel_disable_primary_hw_plane(dev_priv, plane, pipe);
  3408. /*
  3409. * FIXME: Once we grow proper nuclear flip support out of this we need
  3410. * to compute the mask of flip planes precisely. For the time being
  3411. * consider this a flip to a NULL plane.
  3412. */
  3413. intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe));
  3414. drm_vblank_off(dev, pipe);
  3415. }
  3416. static void ironlake_crtc_enable(struct drm_crtc *crtc)
  3417. {
  3418. struct drm_device *dev = crtc->dev;
  3419. struct drm_i915_private *dev_priv = dev->dev_private;
  3420. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3421. struct intel_encoder *encoder;
  3422. int pipe = intel_crtc->pipe;
  3423. enum plane plane = intel_crtc->plane;
  3424. WARN_ON(!crtc->enabled);
  3425. if (intel_crtc->active)
  3426. return;
  3427. if (intel_crtc->config.has_pch_encoder)
  3428. intel_prepare_shared_dpll(intel_crtc);
  3429. if (intel_crtc->config.has_dp_encoder)
  3430. intel_dp_set_m_n(intel_crtc);
  3431. intel_set_pipe_timings(intel_crtc);
  3432. if (intel_crtc->config.has_pch_encoder) {
  3433. intel_cpu_transcoder_set_m_n(intel_crtc,
  3434. &intel_crtc->config.fdi_m_n);
  3435. }
  3436. ironlake_set_pipeconf(crtc);
  3437. /* Set up the display plane register */
  3438. I915_WRITE(DSPCNTR(plane), DISPPLANE_GAMMA_ENABLE);
  3439. POSTING_READ(DSPCNTR(plane));
  3440. dev_priv->display.update_primary_plane(crtc, crtc->primary->fb,
  3441. crtc->x, crtc->y);
  3442. intel_crtc->active = true;
  3443. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  3444. intel_set_pch_fifo_underrun_reporting(dev, pipe, true);
  3445. for_each_encoder_on_crtc(dev, crtc, encoder)
  3446. if (encoder->pre_enable)
  3447. encoder->pre_enable(encoder);
  3448. if (intel_crtc->config.has_pch_encoder) {
  3449. /* Note: FDI PLL enabling _must_ be done before we enable the
  3450. * cpu pipes, hence this is separate from all the other fdi/pch
  3451. * enabling. */
  3452. ironlake_fdi_pll_enable(intel_crtc);
  3453. } else {
  3454. assert_fdi_tx_disabled(dev_priv, pipe);
  3455. assert_fdi_rx_disabled(dev_priv, pipe);
  3456. }
  3457. ironlake_pfit_enable(intel_crtc);
  3458. /*
  3459. * On ILK+ LUT must be loaded before the pipe is running but with
  3460. * clocks enabled
  3461. */
  3462. intel_crtc_load_lut(crtc);
  3463. intel_update_watermarks(crtc);
  3464. intel_enable_pipe(intel_crtc);
  3465. if (intel_crtc->config.has_pch_encoder)
  3466. ironlake_pch_enable(crtc);
  3467. for_each_encoder_on_crtc(dev, crtc, encoder)
  3468. encoder->enable(encoder);
  3469. if (HAS_PCH_CPT(dev))
  3470. cpt_verify_modeset(dev, intel_crtc->pipe);
  3471. intel_crtc_enable_planes(crtc);
  3472. }
  3473. /* IPS only exists on ULT machines and is tied to pipe A. */
  3474. static bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
  3475. {
  3476. return HAS_IPS(crtc->base.dev) && crtc->pipe == PIPE_A;
  3477. }
  3478. /*
  3479. * This implements the workaround described in the "notes" section of the mode
  3480. * set sequence documentation. When going from no pipes or single pipe to
  3481. * multiple pipes, and planes are enabled after the pipe, we need to wait at
  3482. * least 2 vblanks on the first pipe before enabling planes on the second pipe.
  3483. */
  3484. static void haswell_mode_set_planes_workaround(struct intel_crtc *crtc)
  3485. {
  3486. struct drm_device *dev = crtc->base.dev;
  3487. struct intel_crtc *crtc_it, *other_active_crtc = NULL;
  3488. /* We want to get the other_active_crtc only if there's only 1 other
  3489. * active crtc. */
  3490. for_each_intel_crtc(dev, crtc_it) {
  3491. if (!crtc_it->active || crtc_it == crtc)
  3492. continue;
  3493. if (other_active_crtc)
  3494. return;
  3495. other_active_crtc = crtc_it;
  3496. }
  3497. if (!other_active_crtc)
  3498. return;
  3499. intel_wait_for_vblank(dev, other_active_crtc->pipe);
  3500. intel_wait_for_vblank(dev, other_active_crtc->pipe);
  3501. }
  3502. static void haswell_crtc_enable(struct drm_crtc *crtc)
  3503. {
  3504. struct drm_device *dev = crtc->dev;
  3505. struct drm_i915_private *dev_priv = dev->dev_private;
  3506. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3507. struct intel_encoder *encoder;
  3508. int pipe = intel_crtc->pipe;
  3509. enum plane plane = intel_crtc->plane;
  3510. WARN_ON(!crtc->enabled);
  3511. if (intel_crtc->active)
  3512. return;
  3513. if (intel_crtc->config.has_dp_encoder)
  3514. intel_dp_set_m_n(intel_crtc);
  3515. intel_set_pipe_timings(intel_crtc);
  3516. if (intel_crtc->config.has_pch_encoder) {
  3517. intel_cpu_transcoder_set_m_n(intel_crtc,
  3518. &intel_crtc->config.fdi_m_n);
  3519. }
  3520. haswell_set_pipeconf(crtc);
  3521. intel_set_pipe_csc(crtc);
  3522. /* Set up the display plane register */
  3523. I915_WRITE(DSPCNTR(plane), DISPPLANE_GAMMA_ENABLE | DISPPLANE_PIPE_CSC_ENABLE);
  3524. POSTING_READ(DSPCNTR(plane));
  3525. dev_priv->display.update_primary_plane(crtc, crtc->primary->fb,
  3526. crtc->x, crtc->y);
  3527. intel_crtc->active = true;
  3528. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  3529. if (intel_crtc->config.has_pch_encoder)
  3530. intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, true);
  3531. if (intel_crtc->config.has_pch_encoder)
  3532. dev_priv->display.fdi_link_train(crtc);
  3533. for_each_encoder_on_crtc(dev, crtc, encoder)
  3534. if (encoder->pre_enable)
  3535. encoder->pre_enable(encoder);
  3536. intel_ddi_enable_pipe_clock(intel_crtc);
  3537. ironlake_pfit_enable(intel_crtc);
  3538. /*
  3539. * On ILK+ LUT must be loaded before the pipe is running but with
  3540. * clocks enabled
  3541. */
  3542. intel_crtc_load_lut(crtc);
  3543. intel_ddi_set_pipe_settings(crtc);
  3544. intel_ddi_enable_transcoder_func(crtc);
  3545. intel_update_watermarks(crtc);
  3546. intel_enable_pipe(intel_crtc);
  3547. if (intel_crtc->config.has_pch_encoder)
  3548. lpt_pch_enable(crtc);
  3549. for_each_encoder_on_crtc(dev, crtc, encoder) {
  3550. encoder->enable(encoder);
  3551. intel_opregion_notify_encoder(encoder, true);
  3552. }
  3553. /* If we change the relative order between pipe/planes enabling, we need
  3554. * to change the workaround. */
  3555. haswell_mode_set_planes_workaround(intel_crtc);
  3556. intel_crtc_enable_planes(crtc);
  3557. }
  3558. static void ironlake_pfit_disable(struct intel_crtc *crtc)
  3559. {
  3560. struct drm_device *dev = crtc->base.dev;
  3561. struct drm_i915_private *dev_priv = dev->dev_private;
  3562. int pipe = crtc->pipe;
  3563. /* To avoid upsetting the power well on haswell only disable the pfit if
  3564. * it's in use. The hw state code will make sure we get this right. */
  3565. if (crtc->config.pch_pfit.enabled) {
  3566. I915_WRITE(PF_CTL(pipe), 0);
  3567. I915_WRITE(PF_WIN_POS(pipe), 0);
  3568. I915_WRITE(PF_WIN_SZ(pipe), 0);
  3569. }
  3570. }
  3571. static void ironlake_crtc_disable(struct drm_crtc *crtc)
  3572. {
  3573. struct drm_device *dev = crtc->dev;
  3574. struct drm_i915_private *dev_priv = dev->dev_private;
  3575. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3576. struct intel_encoder *encoder;
  3577. int pipe = intel_crtc->pipe;
  3578. u32 reg, temp;
  3579. if (!intel_crtc->active)
  3580. return;
  3581. intel_crtc_disable_planes(crtc);
  3582. for_each_encoder_on_crtc(dev, crtc, encoder)
  3583. encoder->disable(encoder);
  3584. if (intel_crtc->config.has_pch_encoder)
  3585. intel_set_pch_fifo_underrun_reporting(dev, pipe, false);
  3586. intel_disable_pipe(dev_priv, pipe);
  3587. ironlake_pfit_disable(intel_crtc);
  3588. for_each_encoder_on_crtc(dev, crtc, encoder)
  3589. if (encoder->post_disable)
  3590. encoder->post_disable(encoder);
  3591. if (intel_crtc->config.has_pch_encoder) {
  3592. ironlake_fdi_disable(crtc);
  3593. ironlake_disable_pch_transcoder(dev_priv, pipe);
  3594. intel_set_pch_fifo_underrun_reporting(dev, pipe, true);
  3595. if (HAS_PCH_CPT(dev)) {
  3596. /* disable TRANS_DP_CTL */
  3597. reg = TRANS_DP_CTL(pipe);
  3598. temp = I915_READ(reg);
  3599. temp &= ~(TRANS_DP_OUTPUT_ENABLE |
  3600. TRANS_DP_PORT_SEL_MASK);
  3601. temp |= TRANS_DP_PORT_SEL_NONE;
  3602. I915_WRITE(reg, temp);
  3603. /* disable DPLL_SEL */
  3604. temp = I915_READ(PCH_DPLL_SEL);
  3605. temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe));
  3606. I915_WRITE(PCH_DPLL_SEL, temp);
  3607. }
  3608. /* disable PCH DPLL */
  3609. intel_disable_shared_dpll(intel_crtc);
  3610. ironlake_fdi_pll_disable(intel_crtc);
  3611. }
  3612. intel_crtc->active = false;
  3613. intel_update_watermarks(crtc);
  3614. mutex_lock(&dev->struct_mutex);
  3615. intel_update_fbc(dev);
  3616. mutex_unlock(&dev->struct_mutex);
  3617. }
  3618. static void haswell_crtc_disable(struct drm_crtc *crtc)
  3619. {
  3620. struct drm_device *dev = crtc->dev;
  3621. struct drm_i915_private *dev_priv = dev->dev_private;
  3622. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3623. struct intel_encoder *encoder;
  3624. int pipe = intel_crtc->pipe;
  3625. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  3626. if (!intel_crtc->active)
  3627. return;
  3628. intel_crtc_disable_planes(crtc);
  3629. for_each_encoder_on_crtc(dev, crtc, encoder) {
  3630. intel_opregion_notify_encoder(encoder, false);
  3631. encoder->disable(encoder);
  3632. }
  3633. if (intel_crtc->config.has_pch_encoder)
  3634. intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, false);
  3635. intel_disable_pipe(dev_priv, pipe);
  3636. intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder);
  3637. ironlake_pfit_disable(intel_crtc);
  3638. intel_ddi_disable_pipe_clock(intel_crtc);
  3639. for_each_encoder_on_crtc(dev, crtc, encoder)
  3640. if (encoder->post_disable)
  3641. encoder->post_disable(encoder);
  3642. if (intel_crtc->config.has_pch_encoder) {
  3643. lpt_disable_pch_transcoder(dev_priv);
  3644. intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, true);
  3645. intel_ddi_fdi_disable(crtc);
  3646. }
  3647. intel_crtc->active = false;
  3648. intel_update_watermarks(crtc);
  3649. mutex_lock(&dev->struct_mutex);
  3650. intel_update_fbc(dev);
  3651. mutex_unlock(&dev->struct_mutex);
  3652. }
  3653. static void ironlake_crtc_off(struct drm_crtc *crtc)
  3654. {
  3655. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3656. intel_put_shared_dpll(intel_crtc);
  3657. }
  3658. static void haswell_crtc_off(struct drm_crtc *crtc)
  3659. {
  3660. intel_ddi_put_crtc_pll(crtc);
  3661. }
  3662. static void i9xx_pfit_enable(struct intel_crtc *crtc)
  3663. {
  3664. struct drm_device *dev = crtc->base.dev;
  3665. struct drm_i915_private *dev_priv = dev->dev_private;
  3666. struct intel_crtc_config *pipe_config = &crtc->config;
  3667. if (!crtc->config.gmch_pfit.control)
  3668. return;
  3669. /*
  3670. * The panel fitter should only be adjusted whilst the pipe is disabled,
  3671. * according to register description and PRM.
  3672. */
  3673. WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE);
  3674. assert_pipe_disabled(dev_priv, crtc->pipe);
  3675. I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios);
  3676. I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control);
  3677. /* Border color in case we don't scale up to the full screen. Black by
  3678. * default, change to something else for debugging. */
  3679. I915_WRITE(BCLRPAT(crtc->pipe), 0);
  3680. }
  3681. #define for_each_power_domain(domain, mask) \
  3682. for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \
  3683. if ((1 << (domain)) & (mask))
  3684. enum intel_display_power_domain
  3685. intel_display_port_power_domain(struct intel_encoder *intel_encoder)
  3686. {
  3687. struct drm_device *dev = intel_encoder->base.dev;
  3688. struct intel_digital_port *intel_dig_port;
  3689. switch (intel_encoder->type) {
  3690. case INTEL_OUTPUT_UNKNOWN:
  3691. /* Only DDI platforms should ever use this output type */
  3692. WARN_ON_ONCE(!HAS_DDI(dev));
  3693. case INTEL_OUTPUT_DISPLAYPORT:
  3694. case INTEL_OUTPUT_HDMI:
  3695. case INTEL_OUTPUT_EDP:
  3696. intel_dig_port = enc_to_dig_port(&intel_encoder->base);
  3697. switch (intel_dig_port->port) {
  3698. case PORT_A:
  3699. return POWER_DOMAIN_PORT_DDI_A_4_LANES;
  3700. case PORT_B:
  3701. return POWER_DOMAIN_PORT_DDI_B_4_LANES;
  3702. case PORT_C:
  3703. return POWER_DOMAIN_PORT_DDI_C_4_LANES;
  3704. case PORT_D:
  3705. return POWER_DOMAIN_PORT_DDI_D_4_LANES;
  3706. default:
  3707. WARN_ON_ONCE(1);
  3708. return POWER_DOMAIN_PORT_OTHER;
  3709. }
  3710. case INTEL_OUTPUT_ANALOG:
  3711. return POWER_DOMAIN_PORT_CRT;
  3712. case INTEL_OUTPUT_DSI:
  3713. return POWER_DOMAIN_PORT_DSI;
  3714. default:
  3715. return POWER_DOMAIN_PORT_OTHER;
  3716. }
  3717. }
  3718. static unsigned long get_crtc_power_domains(struct drm_crtc *crtc)
  3719. {
  3720. struct drm_device *dev = crtc->dev;
  3721. struct intel_encoder *intel_encoder;
  3722. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3723. enum pipe pipe = intel_crtc->pipe;
  3724. bool pfit_enabled = intel_crtc->config.pch_pfit.enabled;
  3725. unsigned long mask;
  3726. enum transcoder transcoder;
  3727. transcoder = intel_pipe_to_cpu_transcoder(dev->dev_private, pipe);
  3728. mask = BIT(POWER_DOMAIN_PIPE(pipe));
  3729. mask |= BIT(POWER_DOMAIN_TRANSCODER(transcoder));
  3730. if (pfit_enabled)
  3731. mask |= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe));
  3732. for_each_encoder_on_crtc(dev, crtc, intel_encoder)
  3733. mask |= BIT(intel_display_port_power_domain(intel_encoder));
  3734. return mask;
  3735. }
  3736. void intel_display_set_init_power(struct drm_i915_private *dev_priv,
  3737. bool enable)
  3738. {
  3739. if (dev_priv->power_domains.init_power_on == enable)
  3740. return;
  3741. if (enable)
  3742. intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
  3743. else
  3744. intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
  3745. dev_priv->power_domains.init_power_on = enable;
  3746. }
  3747. static void modeset_update_crtc_power_domains(struct drm_device *dev)
  3748. {
  3749. struct drm_i915_private *dev_priv = dev->dev_private;
  3750. unsigned long pipe_domains[I915_MAX_PIPES] = { 0, };
  3751. struct intel_crtc *crtc;
  3752. /*
  3753. * First get all needed power domains, then put all unneeded, to avoid
  3754. * any unnecessary toggling of the power wells.
  3755. */
  3756. for_each_intel_crtc(dev, crtc) {
  3757. enum intel_display_power_domain domain;
  3758. if (!crtc->base.enabled)
  3759. continue;
  3760. pipe_domains[crtc->pipe] = get_crtc_power_domains(&crtc->base);
  3761. for_each_power_domain(domain, pipe_domains[crtc->pipe])
  3762. intel_display_power_get(dev_priv, domain);
  3763. }
  3764. for_each_intel_crtc(dev, crtc) {
  3765. enum intel_display_power_domain domain;
  3766. for_each_power_domain(domain, crtc->enabled_power_domains)
  3767. intel_display_power_put(dev_priv, domain);
  3768. crtc->enabled_power_domains = pipe_domains[crtc->pipe];
  3769. }
  3770. intel_display_set_init_power(dev_priv, false);
  3771. }
  3772. /* returns HPLL frequency in kHz */
  3773. int valleyview_get_vco(struct drm_i915_private *dev_priv)
  3774. {
  3775. int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 };
  3776. /* Obtain SKU information */
  3777. mutex_lock(&dev_priv->dpio_lock);
  3778. hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) &
  3779. CCK_FUSE_HPLL_FREQ_MASK;
  3780. mutex_unlock(&dev_priv->dpio_lock);
  3781. return vco_freq[hpll_freq] * 1000;
  3782. }
  3783. /* Adjust CDclk dividers to allow high res or save power if possible */
  3784. static void valleyview_set_cdclk(struct drm_device *dev, int cdclk)
  3785. {
  3786. struct drm_i915_private *dev_priv = dev->dev_private;
  3787. u32 val, cmd;
  3788. WARN_ON(dev_priv->display.get_display_clock_speed(dev) != dev_priv->vlv_cdclk_freq);
  3789. dev_priv->vlv_cdclk_freq = cdclk;
  3790. if (cdclk >= 320000) /* jump to highest voltage for 400MHz too */
  3791. cmd = 2;
  3792. else if (cdclk == 266667)
  3793. cmd = 1;
  3794. else
  3795. cmd = 0;
  3796. mutex_lock(&dev_priv->rps.hw_lock);
  3797. val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
  3798. val &= ~DSPFREQGUAR_MASK;
  3799. val |= (cmd << DSPFREQGUAR_SHIFT);
  3800. vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val);
  3801. if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) &
  3802. DSPFREQSTAT_MASK) == (cmd << DSPFREQSTAT_SHIFT),
  3803. 50)) {
  3804. DRM_ERROR("timed out waiting for CDclk change\n");
  3805. }
  3806. mutex_unlock(&dev_priv->rps.hw_lock);
  3807. if (cdclk == 400000) {
  3808. u32 divider, vco;
  3809. vco = valleyview_get_vco(dev_priv);
  3810. divider = DIV_ROUND_CLOSEST(vco << 1, cdclk) - 1;
  3811. mutex_lock(&dev_priv->dpio_lock);
  3812. /* adjust cdclk divider */
  3813. val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL);
  3814. val &= ~DISPLAY_FREQUENCY_VALUES;
  3815. val |= divider;
  3816. vlv_cck_write(dev_priv, CCK_DISPLAY_CLOCK_CONTROL, val);
  3817. mutex_unlock(&dev_priv->dpio_lock);
  3818. }
  3819. mutex_lock(&dev_priv->dpio_lock);
  3820. /* adjust self-refresh exit latency value */
  3821. val = vlv_bunit_read(dev_priv, BUNIT_REG_BISOC);
  3822. val &= ~0x7f;
  3823. /*
  3824. * For high bandwidth configs, we set a higher latency in the bunit
  3825. * so that the core display fetch happens in time to avoid underruns.
  3826. */
  3827. if (cdclk == 400000)
  3828. val |= 4500 / 250; /* 4.5 usec */
  3829. else
  3830. val |= 3000 / 250; /* 3.0 usec */
  3831. vlv_bunit_write(dev_priv, BUNIT_REG_BISOC, val);
  3832. mutex_unlock(&dev_priv->dpio_lock);
  3833. /* Since we changed the CDclk, we need to update the GMBUSFREQ too */
  3834. intel_i2c_reset(dev);
  3835. }
  3836. static int valleyview_calc_cdclk(struct drm_i915_private *dev_priv,
  3837. int max_pixclk)
  3838. {
  3839. int vco = valleyview_get_vco(dev_priv);
  3840. int freq_320 = (vco << 1) % 320000 != 0 ? 333333 : 320000;
  3841. /*
  3842. * Really only a few cases to deal with, as only 4 CDclks are supported:
  3843. * 200MHz
  3844. * 267MHz
  3845. * 320/333MHz (depends on HPLL freq)
  3846. * 400MHz
  3847. * So we check to see whether we're above 90% of the lower bin and
  3848. * adjust if needed.
  3849. *
  3850. * We seem to get an unstable or solid color picture at 200MHz.
  3851. * Not sure what's wrong. For now use 200MHz only when all pipes
  3852. * are off.
  3853. */
  3854. if (max_pixclk > freq_320*9/10)
  3855. return 400000;
  3856. else if (max_pixclk > 266667*9/10)
  3857. return freq_320;
  3858. else if (max_pixclk > 0)
  3859. return 266667;
  3860. else
  3861. return 200000;
  3862. }
  3863. /* compute the max pixel clock for new configuration */
  3864. static int intel_mode_max_pixclk(struct drm_i915_private *dev_priv)
  3865. {
  3866. struct drm_device *dev = dev_priv->dev;
  3867. struct intel_crtc *intel_crtc;
  3868. int max_pixclk = 0;
  3869. for_each_intel_crtc(dev, intel_crtc) {
  3870. if (intel_crtc->new_enabled)
  3871. max_pixclk = max(max_pixclk,
  3872. intel_crtc->new_config->adjusted_mode.crtc_clock);
  3873. }
  3874. return max_pixclk;
  3875. }
  3876. static void valleyview_modeset_global_pipes(struct drm_device *dev,
  3877. unsigned *prepare_pipes)
  3878. {
  3879. struct drm_i915_private *dev_priv = dev->dev_private;
  3880. struct intel_crtc *intel_crtc;
  3881. int max_pixclk = intel_mode_max_pixclk(dev_priv);
  3882. if (valleyview_calc_cdclk(dev_priv, max_pixclk) ==
  3883. dev_priv->vlv_cdclk_freq)
  3884. return;
  3885. /* disable/enable all currently active pipes while we change cdclk */
  3886. for_each_intel_crtc(dev, intel_crtc)
  3887. if (intel_crtc->base.enabled)
  3888. *prepare_pipes |= (1 << intel_crtc->pipe);
  3889. }
  3890. static void valleyview_modeset_global_resources(struct drm_device *dev)
  3891. {
  3892. struct drm_i915_private *dev_priv = dev->dev_private;
  3893. int max_pixclk = intel_mode_max_pixclk(dev_priv);
  3894. int req_cdclk = valleyview_calc_cdclk(dev_priv, max_pixclk);
  3895. if (req_cdclk != dev_priv->vlv_cdclk_freq)
  3896. valleyview_set_cdclk(dev, req_cdclk);
  3897. modeset_update_crtc_power_domains(dev);
  3898. }
  3899. static void valleyview_crtc_enable(struct drm_crtc *crtc)
  3900. {
  3901. struct drm_device *dev = crtc->dev;
  3902. struct drm_i915_private *dev_priv = dev->dev_private;
  3903. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3904. struct intel_encoder *encoder;
  3905. int pipe = intel_crtc->pipe;
  3906. int plane = intel_crtc->plane;
  3907. bool is_dsi;
  3908. u32 dspcntr;
  3909. WARN_ON(!crtc->enabled);
  3910. if (intel_crtc->active)
  3911. return;
  3912. is_dsi = intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI);
  3913. if (!is_dsi && !IS_CHERRYVIEW(dev))
  3914. vlv_prepare_pll(intel_crtc);
  3915. /* Set up the display plane register */
  3916. dspcntr = DISPPLANE_GAMMA_ENABLE;
  3917. if (intel_crtc->config.has_dp_encoder)
  3918. intel_dp_set_m_n(intel_crtc);
  3919. intel_set_pipe_timings(intel_crtc);
  3920. /* pipesrc and dspsize control the size that is scaled from,
  3921. * which should always be the user's requested size.
  3922. */
  3923. I915_WRITE(DSPSIZE(plane),
  3924. ((intel_crtc->config.pipe_src_h - 1) << 16) |
  3925. (intel_crtc->config.pipe_src_w - 1));
  3926. I915_WRITE(DSPPOS(plane), 0);
  3927. i9xx_set_pipeconf(intel_crtc);
  3928. I915_WRITE(DSPCNTR(plane), dspcntr);
  3929. POSTING_READ(DSPCNTR(plane));
  3930. dev_priv->display.update_primary_plane(crtc, crtc->primary->fb,
  3931. crtc->x, crtc->y);
  3932. intel_crtc->active = true;
  3933. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  3934. for_each_encoder_on_crtc(dev, crtc, encoder)
  3935. if (encoder->pre_pll_enable)
  3936. encoder->pre_pll_enable(encoder);
  3937. if (!is_dsi) {
  3938. if (IS_CHERRYVIEW(dev))
  3939. chv_enable_pll(intel_crtc);
  3940. else
  3941. vlv_enable_pll(intel_crtc);
  3942. }
  3943. for_each_encoder_on_crtc(dev, crtc, encoder)
  3944. if (encoder->pre_enable)
  3945. encoder->pre_enable(encoder);
  3946. i9xx_pfit_enable(intel_crtc);
  3947. intel_crtc_load_lut(crtc);
  3948. intel_update_watermarks(crtc);
  3949. intel_enable_pipe(intel_crtc);
  3950. for_each_encoder_on_crtc(dev, crtc, encoder)
  3951. encoder->enable(encoder);
  3952. intel_crtc_enable_planes(crtc);
  3953. /* Underruns don't raise interrupts, so check manually. */
  3954. i9xx_check_fifo_underruns(dev);
  3955. }
  3956. static void i9xx_set_pll_dividers(struct intel_crtc *crtc)
  3957. {
  3958. struct drm_device *dev = crtc->base.dev;
  3959. struct drm_i915_private *dev_priv = dev->dev_private;
  3960. I915_WRITE(FP0(crtc->pipe), crtc->config.dpll_hw_state.fp0);
  3961. I915_WRITE(FP1(crtc->pipe), crtc->config.dpll_hw_state.fp1);
  3962. }
  3963. static void i9xx_crtc_enable(struct drm_crtc *crtc)
  3964. {
  3965. struct drm_device *dev = crtc->dev;
  3966. struct drm_i915_private *dev_priv = dev->dev_private;
  3967. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3968. struct intel_encoder *encoder;
  3969. int pipe = intel_crtc->pipe;
  3970. int plane = intel_crtc->plane;
  3971. u32 dspcntr;
  3972. WARN_ON(!crtc->enabled);
  3973. if (intel_crtc->active)
  3974. return;
  3975. i9xx_set_pll_dividers(intel_crtc);
  3976. /* Set up the display plane register */
  3977. dspcntr = DISPPLANE_GAMMA_ENABLE;
  3978. if (pipe == 0)
  3979. dspcntr &= ~DISPPLANE_SEL_PIPE_MASK;
  3980. else
  3981. dspcntr |= DISPPLANE_SEL_PIPE_B;
  3982. if (intel_crtc->config.has_dp_encoder)
  3983. intel_dp_set_m_n(intel_crtc);
  3984. intel_set_pipe_timings(intel_crtc);
  3985. /* pipesrc and dspsize control the size that is scaled from,
  3986. * which should always be the user's requested size.
  3987. */
  3988. I915_WRITE(DSPSIZE(plane),
  3989. ((intel_crtc->config.pipe_src_h - 1) << 16) |
  3990. (intel_crtc->config.pipe_src_w - 1));
  3991. I915_WRITE(DSPPOS(plane), 0);
  3992. i9xx_set_pipeconf(intel_crtc);
  3993. I915_WRITE(DSPCNTR(plane), dspcntr);
  3994. POSTING_READ(DSPCNTR(plane));
  3995. dev_priv->display.update_primary_plane(crtc, crtc->primary->fb,
  3996. crtc->x, crtc->y);
  3997. intel_crtc->active = true;
  3998. if (!IS_GEN2(dev))
  3999. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  4000. for_each_encoder_on_crtc(dev, crtc, encoder)
  4001. if (encoder->pre_enable)
  4002. encoder->pre_enable(encoder);
  4003. i9xx_enable_pll(intel_crtc);
  4004. i9xx_pfit_enable(intel_crtc);
  4005. intel_crtc_load_lut(crtc);
  4006. intel_update_watermarks(crtc);
  4007. intel_enable_pipe(intel_crtc);
  4008. for_each_encoder_on_crtc(dev, crtc, encoder)
  4009. encoder->enable(encoder);
  4010. intel_crtc_enable_planes(crtc);
  4011. /*
  4012. * Gen2 reports pipe underruns whenever all planes are disabled.
  4013. * So don't enable underrun reporting before at least some planes
  4014. * are enabled.
  4015. * FIXME: Need to fix the logic to work when we turn off all planes
  4016. * but leave the pipe running.
  4017. */
  4018. if (IS_GEN2(dev))
  4019. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  4020. /* Underruns don't raise interrupts, so check manually. */
  4021. i9xx_check_fifo_underruns(dev);
  4022. }
  4023. static void i9xx_pfit_disable(struct intel_crtc *crtc)
  4024. {
  4025. struct drm_device *dev = crtc->base.dev;
  4026. struct drm_i915_private *dev_priv = dev->dev_private;
  4027. if (!crtc->config.gmch_pfit.control)
  4028. return;
  4029. assert_pipe_disabled(dev_priv, crtc->pipe);
  4030. DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n",
  4031. I915_READ(PFIT_CONTROL));
  4032. I915_WRITE(PFIT_CONTROL, 0);
  4033. }
  4034. static void i9xx_crtc_disable(struct drm_crtc *crtc)
  4035. {
  4036. struct drm_device *dev = crtc->dev;
  4037. struct drm_i915_private *dev_priv = dev->dev_private;
  4038. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4039. struct intel_encoder *encoder;
  4040. int pipe = intel_crtc->pipe;
  4041. if (!intel_crtc->active)
  4042. return;
  4043. /*
  4044. * Gen2 reports pipe underruns whenever all planes are disabled.
  4045. * So diasble underrun reporting before all the planes get disabled.
  4046. * FIXME: Need to fix the logic to work when we turn off all planes
  4047. * but leave the pipe running.
  4048. */
  4049. if (IS_GEN2(dev))
  4050. intel_set_cpu_fifo_underrun_reporting(dev, pipe, false);
  4051. intel_crtc_disable_planes(crtc);
  4052. for_each_encoder_on_crtc(dev, crtc, encoder)
  4053. encoder->disable(encoder);
  4054. /*
  4055. * On gen2 planes are double buffered but the pipe isn't, so we must
  4056. * wait for planes to fully turn off before disabling the pipe.
  4057. */
  4058. if (IS_GEN2(dev))
  4059. intel_wait_for_vblank(dev, pipe);
  4060. intel_disable_pipe(dev_priv, pipe);
  4061. i9xx_pfit_disable(intel_crtc);
  4062. for_each_encoder_on_crtc(dev, crtc, encoder)
  4063. if (encoder->post_disable)
  4064. encoder->post_disable(encoder);
  4065. if (!intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI)) {
  4066. if (IS_CHERRYVIEW(dev))
  4067. chv_disable_pll(dev_priv, pipe);
  4068. else if (IS_VALLEYVIEW(dev))
  4069. vlv_disable_pll(dev_priv, pipe);
  4070. else
  4071. i9xx_disable_pll(dev_priv, pipe);
  4072. }
  4073. if (!IS_GEN2(dev))
  4074. intel_set_cpu_fifo_underrun_reporting(dev, pipe, false);
  4075. intel_crtc->active = false;
  4076. intel_update_watermarks(crtc);
  4077. mutex_lock(&dev->struct_mutex);
  4078. intel_update_fbc(dev);
  4079. mutex_unlock(&dev->struct_mutex);
  4080. }
  4081. static void i9xx_crtc_off(struct drm_crtc *crtc)
  4082. {
  4083. }
  4084. static void intel_crtc_update_sarea(struct drm_crtc *crtc,
  4085. bool enabled)
  4086. {
  4087. struct drm_device *dev = crtc->dev;
  4088. struct drm_i915_master_private *master_priv;
  4089. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4090. int pipe = intel_crtc->pipe;
  4091. if (!dev->primary->master)
  4092. return;
  4093. master_priv = dev->primary->master->driver_priv;
  4094. if (!master_priv->sarea_priv)
  4095. return;
  4096. switch (pipe) {
  4097. case 0:
  4098. master_priv->sarea_priv->pipeA_w = enabled ? crtc->mode.hdisplay : 0;
  4099. master_priv->sarea_priv->pipeA_h = enabled ? crtc->mode.vdisplay : 0;
  4100. break;
  4101. case 1:
  4102. master_priv->sarea_priv->pipeB_w = enabled ? crtc->mode.hdisplay : 0;
  4103. master_priv->sarea_priv->pipeB_h = enabled ? crtc->mode.vdisplay : 0;
  4104. break;
  4105. default:
  4106. DRM_ERROR("Can't update pipe %c in SAREA\n", pipe_name(pipe));
  4107. break;
  4108. }
  4109. }
  4110. /**
  4111. * Sets the power management mode of the pipe and plane.
  4112. */
  4113. void intel_crtc_update_dpms(struct drm_crtc *crtc)
  4114. {
  4115. struct drm_device *dev = crtc->dev;
  4116. struct drm_i915_private *dev_priv = dev->dev_private;
  4117. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4118. struct intel_encoder *intel_encoder;
  4119. enum intel_display_power_domain domain;
  4120. unsigned long domains;
  4121. bool enable = false;
  4122. for_each_encoder_on_crtc(dev, crtc, intel_encoder)
  4123. enable |= intel_encoder->connectors_active;
  4124. if (enable) {
  4125. if (!intel_crtc->active) {
  4126. /*
  4127. * FIXME: DDI plls and relevant code isn't converted
  4128. * yet, so do runtime PM for DPMS only for all other
  4129. * platforms for now.
  4130. */
  4131. if (!HAS_DDI(dev)) {
  4132. domains = get_crtc_power_domains(crtc);
  4133. for_each_power_domain(domain, domains)
  4134. intel_display_power_get(dev_priv, domain);
  4135. intel_crtc->enabled_power_domains = domains;
  4136. }
  4137. dev_priv->display.crtc_enable(crtc);
  4138. }
  4139. } else {
  4140. if (intel_crtc->active) {
  4141. dev_priv->display.crtc_disable(crtc);
  4142. if (!HAS_DDI(dev)) {
  4143. domains = intel_crtc->enabled_power_domains;
  4144. for_each_power_domain(domain, domains)
  4145. intel_display_power_put(dev_priv, domain);
  4146. intel_crtc->enabled_power_domains = 0;
  4147. }
  4148. }
  4149. }
  4150. intel_crtc_update_sarea(crtc, enable);
  4151. }
  4152. static void intel_crtc_disable(struct drm_crtc *crtc)
  4153. {
  4154. struct drm_device *dev = crtc->dev;
  4155. struct drm_connector *connector;
  4156. struct drm_i915_private *dev_priv = dev->dev_private;
  4157. struct drm_i915_gem_object *old_obj;
  4158. enum pipe pipe = to_intel_crtc(crtc)->pipe;
  4159. /* crtc should still be enabled when we disable it. */
  4160. WARN_ON(!crtc->enabled);
  4161. dev_priv->display.crtc_disable(crtc);
  4162. intel_crtc_update_sarea(crtc, false);
  4163. dev_priv->display.off(crtc);
  4164. assert_plane_disabled(dev->dev_private, to_intel_crtc(crtc)->plane);
  4165. assert_cursor_disabled(dev_priv, pipe);
  4166. assert_pipe_disabled(dev->dev_private, pipe);
  4167. if (crtc->primary->fb) {
  4168. old_obj = to_intel_framebuffer(crtc->primary->fb)->obj;
  4169. mutex_lock(&dev->struct_mutex);
  4170. intel_unpin_fb_obj(old_obj);
  4171. i915_gem_track_fb(old_obj, NULL,
  4172. INTEL_FRONTBUFFER_PRIMARY(pipe));
  4173. mutex_unlock(&dev->struct_mutex);
  4174. crtc->primary->fb = NULL;
  4175. }
  4176. /* Update computed state. */
  4177. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  4178. if (!connector->encoder || !connector->encoder->crtc)
  4179. continue;
  4180. if (connector->encoder->crtc != crtc)
  4181. continue;
  4182. connector->dpms = DRM_MODE_DPMS_OFF;
  4183. to_intel_encoder(connector->encoder)->connectors_active = false;
  4184. }
  4185. }
  4186. void intel_encoder_destroy(struct drm_encoder *encoder)
  4187. {
  4188. struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
  4189. drm_encoder_cleanup(encoder);
  4190. kfree(intel_encoder);
  4191. }
  4192. /* Simple dpms helper for encoders with just one connector, no cloning and only
  4193. * one kind of off state. It clamps all !ON modes to fully OFF and changes the
  4194. * state of the entire output pipe. */
  4195. static void intel_encoder_dpms(struct intel_encoder *encoder, int mode)
  4196. {
  4197. if (mode == DRM_MODE_DPMS_ON) {
  4198. encoder->connectors_active = true;
  4199. intel_crtc_update_dpms(encoder->base.crtc);
  4200. } else {
  4201. encoder->connectors_active = false;
  4202. intel_crtc_update_dpms(encoder->base.crtc);
  4203. }
  4204. }
  4205. /* Cross check the actual hw state with our own modeset state tracking (and it's
  4206. * internal consistency). */
  4207. static void intel_connector_check_state(struct intel_connector *connector)
  4208. {
  4209. if (connector->get_hw_state(connector)) {
  4210. struct intel_encoder *encoder = connector->encoder;
  4211. struct drm_crtc *crtc;
  4212. bool encoder_enabled;
  4213. enum pipe pipe;
  4214. DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
  4215. connector->base.base.id,
  4216. connector->base.name);
  4217. WARN(connector->base.dpms == DRM_MODE_DPMS_OFF,
  4218. "wrong connector dpms state\n");
  4219. WARN(connector->base.encoder != &encoder->base,
  4220. "active connector not linked to encoder\n");
  4221. WARN(!encoder->connectors_active,
  4222. "encoder->connectors_active not set\n");
  4223. encoder_enabled = encoder->get_hw_state(encoder, &pipe);
  4224. WARN(!encoder_enabled, "encoder not enabled\n");
  4225. if (WARN_ON(!encoder->base.crtc))
  4226. return;
  4227. crtc = encoder->base.crtc;
  4228. WARN(!crtc->enabled, "crtc not enabled\n");
  4229. WARN(!to_intel_crtc(crtc)->active, "crtc not active\n");
  4230. WARN(pipe != to_intel_crtc(crtc)->pipe,
  4231. "encoder active on the wrong pipe\n");
  4232. }
  4233. }
  4234. /* Even simpler default implementation, if there's really no special case to
  4235. * consider. */
  4236. void intel_connector_dpms(struct drm_connector *connector, int mode)
  4237. {
  4238. /* All the simple cases only support two dpms states. */
  4239. if (mode != DRM_MODE_DPMS_ON)
  4240. mode = DRM_MODE_DPMS_OFF;
  4241. if (mode == connector->dpms)
  4242. return;
  4243. connector->dpms = mode;
  4244. /* Only need to change hw state when actually enabled */
  4245. if (connector->encoder)
  4246. intel_encoder_dpms(to_intel_encoder(connector->encoder), mode);
  4247. intel_modeset_check_state(connector->dev);
  4248. }
  4249. /* Simple connector->get_hw_state implementation for encoders that support only
  4250. * one connector and no cloning and hence the encoder state determines the state
  4251. * of the connector. */
  4252. bool intel_connector_get_hw_state(struct intel_connector *connector)
  4253. {
  4254. enum pipe pipe = 0;
  4255. struct intel_encoder *encoder = connector->encoder;
  4256. return encoder->get_hw_state(encoder, &pipe);
  4257. }
  4258. static bool ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe,
  4259. struct intel_crtc_config *pipe_config)
  4260. {
  4261. struct drm_i915_private *dev_priv = dev->dev_private;
  4262. struct intel_crtc *pipe_B_crtc =
  4263. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]);
  4264. DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
  4265. pipe_name(pipe), pipe_config->fdi_lanes);
  4266. if (pipe_config->fdi_lanes > 4) {
  4267. DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
  4268. pipe_name(pipe), pipe_config->fdi_lanes);
  4269. return false;
  4270. }
  4271. if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  4272. if (pipe_config->fdi_lanes > 2) {
  4273. DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
  4274. pipe_config->fdi_lanes);
  4275. return false;
  4276. } else {
  4277. return true;
  4278. }
  4279. }
  4280. if (INTEL_INFO(dev)->num_pipes == 2)
  4281. return true;
  4282. /* Ivybridge 3 pipe is really complicated */
  4283. switch (pipe) {
  4284. case PIPE_A:
  4285. return true;
  4286. case PIPE_B:
  4287. if (dev_priv->pipe_to_crtc_mapping[PIPE_C]->enabled &&
  4288. pipe_config->fdi_lanes > 2) {
  4289. DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
  4290. pipe_name(pipe), pipe_config->fdi_lanes);
  4291. return false;
  4292. }
  4293. return true;
  4294. case PIPE_C:
  4295. if (!pipe_has_enabled_pch(pipe_B_crtc) ||
  4296. pipe_B_crtc->config.fdi_lanes <= 2) {
  4297. if (pipe_config->fdi_lanes > 2) {
  4298. DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
  4299. pipe_name(pipe), pipe_config->fdi_lanes);
  4300. return false;
  4301. }
  4302. } else {
  4303. DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
  4304. return false;
  4305. }
  4306. return true;
  4307. default:
  4308. BUG();
  4309. }
  4310. }
  4311. #define RETRY 1
  4312. static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc,
  4313. struct intel_crtc_config *pipe_config)
  4314. {
  4315. struct drm_device *dev = intel_crtc->base.dev;
  4316. struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
  4317. int lane, link_bw, fdi_dotclock;
  4318. bool setup_ok, needs_recompute = false;
  4319. retry:
  4320. /* FDI is a binary signal running at ~2.7GHz, encoding
  4321. * each output octet as 10 bits. The actual frequency
  4322. * is stored as a divider into a 100MHz clock, and the
  4323. * mode pixel clock is stored in units of 1KHz.
  4324. * Hence the bw of each lane in terms of the mode signal
  4325. * is:
  4326. */
  4327. link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10;
  4328. fdi_dotclock = adjusted_mode->crtc_clock;
  4329. lane = ironlake_get_lanes_required(fdi_dotclock, link_bw,
  4330. pipe_config->pipe_bpp);
  4331. pipe_config->fdi_lanes = lane;
  4332. intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock,
  4333. link_bw, &pipe_config->fdi_m_n);
  4334. setup_ok = ironlake_check_fdi_lanes(intel_crtc->base.dev,
  4335. intel_crtc->pipe, pipe_config);
  4336. if (!setup_ok && pipe_config->pipe_bpp > 6*3) {
  4337. pipe_config->pipe_bpp -= 2*3;
  4338. DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
  4339. pipe_config->pipe_bpp);
  4340. needs_recompute = true;
  4341. pipe_config->bw_constrained = true;
  4342. goto retry;
  4343. }
  4344. if (needs_recompute)
  4345. return RETRY;
  4346. return setup_ok ? 0 : -EINVAL;
  4347. }
  4348. static void hsw_compute_ips_config(struct intel_crtc *crtc,
  4349. struct intel_crtc_config *pipe_config)
  4350. {
  4351. pipe_config->ips_enabled = i915.enable_ips &&
  4352. hsw_crtc_supports_ips(crtc) &&
  4353. pipe_config->pipe_bpp <= 24;
  4354. }
  4355. static int intel_crtc_compute_config(struct intel_crtc *crtc,
  4356. struct intel_crtc_config *pipe_config)
  4357. {
  4358. struct drm_device *dev = crtc->base.dev;
  4359. struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
  4360. /* FIXME should check pixel clock limits on all platforms */
  4361. if (INTEL_INFO(dev)->gen < 4) {
  4362. struct drm_i915_private *dev_priv = dev->dev_private;
  4363. int clock_limit =
  4364. dev_priv->display.get_display_clock_speed(dev);
  4365. /*
  4366. * Enable pixel doubling when the dot clock
  4367. * is > 90% of the (display) core speed.
  4368. *
  4369. * GDG double wide on either pipe,
  4370. * otherwise pipe A only.
  4371. */
  4372. if ((crtc->pipe == PIPE_A || IS_I915G(dev)) &&
  4373. adjusted_mode->crtc_clock > clock_limit * 9 / 10) {
  4374. clock_limit *= 2;
  4375. pipe_config->double_wide = true;
  4376. }
  4377. if (adjusted_mode->crtc_clock > clock_limit * 9 / 10)
  4378. return -EINVAL;
  4379. }
  4380. /*
  4381. * Pipe horizontal size must be even in:
  4382. * - DVO ganged mode
  4383. * - LVDS dual channel mode
  4384. * - Double wide pipe
  4385. */
  4386. if ((intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
  4387. intel_is_dual_link_lvds(dev)) || pipe_config->double_wide)
  4388. pipe_config->pipe_src_w &= ~1;
  4389. /* Cantiga+ cannot handle modes with a hsync front porch of 0.
  4390. * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
  4391. */
  4392. if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) &&
  4393. adjusted_mode->hsync_start == adjusted_mode->hdisplay)
  4394. return -EINVAL;
  4395. if ((IS_G4X(dev) || IS_VALLEYVIEW(dev)) && pipe_config->pipe_bpp > 10*3) {
  4396. pipe_config->pipe_bpp = 10*3; /* 12bpc is gen5+ */
  4397. } else if (INTEL_INFO(dev)->gen <= 4 && pipe_config->pipe_bpp > 8*3) {
  4398. /* only a 8bpc pipe, with 6bpc dither through the panel fitter
  4399. * for lvds. */
  4400. pipe_config->pipe_bpp = 8*3;
  4401. }
  4402. if (HAS_IPS(dev))
  4403. hsw_compute_ips_config(crtc, pipe_config);
  4404. /* XXX: PCH clock sharing is done in ->mode_set, so make sure the old
  4405. * clock survives for now. */
  4406. if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
  4407. pipe_config->shared_dpll = crtc->config.shared_dpll;
  4408. if (pipe_config->has_pch_encoder)
  4409. return ironlake_fdi_compute_config(crtc, pipe_config);
  4410. return 0;
  4411. }
  4412. static int valleyview_get_display_clock_speed(struct drm_device *dev)
  4413. {
  4414. struct drm_i915_private *dev_priv = dev->dev_private;
  4415. int vco = valleyview_get_vco(dev_priv);
  4416. u32 val;
  4417. int divider;
  4418. mutex_lock(&dev_priv->dpio_lock);
  4419. val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL);
  4420. mutex_unlock(&dev_priv->dpio_lock);
  4421. divider = val & DISPLAY_FREQUENCY_VALUES;
  4422. return DIV_ROUND_CLOSEST(vco << 1, divider + 1);
  4423. }
  4424. static int i945_get_display_clock_speed(struct drm_device *dev)
  4425. {
  4426. return 400000;
  4427. }
  4428. static int i915_get_display_clock_speed(struct drm_device *dev)
  4429. {
  4430. return 333000;
  4431. }
  4432. static int i9xx_misc_get_display_clock_speed(struct drm_device *dev)
  4433. {
  4434. return 200000;
  4435. }
  4436. static int pnv_get_display_clock_speed(struct drm_device *dev)
  4437. {
  4438. u16 gcfgc = 0;
  4439. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  4440. switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
  4441. case GC_DISPLAY_CLOCK_267_MHZ_PNV:
  4442. return 267000;
  4443. case GC_DISPLAY_CLOCK_333_MHZ_PNV:
  4444. return 333000;
  4445. case GC_DISPLAY_CLOCK_444_MHZ_PNV:
  4446. return 444000;
  4447. case GC_DISPLAY_CLOCK_200_MHZ_PNV:
  4448. return 200000;
  4449. default:
  4450. DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc);
  4451. case GC_DISPLAY_CLOCK_133_MHZ_PNV:
  4452. return 133000;
  4453. case GC_DISPLAY_CLOCK_167_MHZ_PNV:
  4454. return 167000;
  4455. }
  4456. }
  4457. static int i915gm_get_display_clock_speed(struct drm_device *dev)
  4458. {
  4459. u16 gcfgc = 0;
  4460. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  4461. if (gcfgc & GC_LOW_FREQUENCY_ENABLE)
  4462. return 133000;
  4463. else {
  4464. switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
  4465. case GC_DISPLAY_CLOCK_333_MHZ:
  4466. return 333000;
  4467. default:
  4468. case GC_DISPLAY_CLOCK_190_200_MHZ:
  4469. return 190000;
  4470. }
  4471. }
  4472. }
  4473. static int i865_get_display_clock_speed(struct drm_device *dev)
  4474. {
  4475. return 266000;
  4476. }
  4477. static int i855_get_display_clock_speed(struct drm_device *dev)
  4478. {
  4479. u16 hpllcc = 0;
  4480. /* Assume that the hardware is in the high speed state. This
  4481. * should be the default.
  4482. */
  4483. switch (hpllcc & GC_CLOCK_CONTROL_MASK) {
  4484. case GC_CLOCK_133_200:
  4485. case GC_CLOCK_100_200:
  4486. return 200000;
  4487. case GC_CLOCK_166_250:
  4488. return 250000;
  4489. case GC_CLOCK_100_133:
  4490. return 133000;
  4491. }
  4492. /* Shouldn't happen */
  4493. return 0;
  4494. }
  4495. static int i830_get_display_clock_speed(struct drm_device *dev)
  4496. {
  4497. return 133000;
  4498. }
  4499. static void
  4500. intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den)
  4501. {
  4502. while (*num > DATA_LINK_M_N_MASK ||
  4503. *den > DATA_LINK_M_N_MASK) {
  4504. *num >>= 1;
  4505. *den >>= 1;
  4506. }
  4507. }
  4508. static void compute_m_n(unsigned int m, unsigned int n,
  4509. uint32_t *ret_m, uint32_t *ret_n)
  4510. {
  4511. *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
  4512. *ret_m = div_u64((uint64_t) m * *ret_n, n);
  4513. intel_reduce_m_n_ratio(ret_m, ret_n);
  4514. }
  4515. void
  4516. intel_link_compute_m_n(int bits_per_pixel, int nlanes,
  4517. int pixel_clock, int link_clock,
  4518. struct intel_link_m_n *m_n)
  4519. {
  4520. m_n->tu = 64;
  4521. compute_m_n(bits_per_pixel * pixel_clock,
  4522. link_clock * nlanes * 8,
  4523. &m_n->gmch_m, &m_n->gmch_n);
  4524. compute_m_n(pixel_clock, link_clock,
  4525. &m_n->link_m, &m_n->link_n);
  4526. }
  4527. static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
  4528. {
  4529. if (i915.panel_use_ssc >= 0)
  4530. return i915.panel_use_ssc != 0;
  4531. return dev_priv->vbt.lvds_use_ssc
  4532. && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
  4533. }
  4534. static int i9xx_get_refclk(struct drm_crtc *crtc, int num_connectors)
  4535. {
  4536. struct drm_device *dev = crtc->dev;
  4537. struct drm_i915_private *dev_priv = dev->dev_private;
  4538. int refclk;
  4539. if (IS_VALLEYVIEW(dev)) {
  4540. refclk = 100000;
  4541. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  4542. intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
  4543. refclk = dev_priv->vbt.lvds_ssc_freq;
  4544. DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
  4545. } else if (!IS_GEN2(dev)) {
  4546. refclk = 96000;
  4547. } else {
  4548. refclk = 48000;
  4549. }
  4550. return refclk;
  4551. }
  4552. static uint32_t pnv_dpll_compute_fp(struct dpll *dpll)
  4553. {
  4554. return (1 << dpll->n) << 16 | dpll->m2;
  4555. }
  4556. static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll)
  4557. {
  4558. return dpll->n << 16 | dpll->m1 << 8 | dpll->m2;
  4559. }
  4560. static void i9xx_update_pll_dividers(struct intel_crtc *crtc,
  4561. intel_clock_t *reduced_clock)
  4562. {
  4563. struct drm_device *dev = crtc->base.dev;
  4564. u32 fp, fp2 = 0;
  4565. if (IS_PINEVIEW(dev)) {
  4566. fp = pnv_dpll_compute_fp(&crtc->config.dpll);
  4567. if (reduced_clock)
  4568. fp2 = pnv_dpll_compute_fp(reduced_clock);
  4569. } else {
  4570. fp = i9xx_dpll_compute_fp(&crtc->config.dpll);
  4571. if (reduced_clock)
  4572. fp2 = i9xx_dpll_compute_fp(reduced_clock);
  4573. }
  4574. crtc->config.dpll_hw_state.fp0 = fp;
  4575. crtc->lowfreq_avail = false;
  4576. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
  4577. reduced_clock && i915.powersave) {
  4578. crtc->config.dpll_hw_state.fp1 = fp2;
  4579. crtc->lowfreq_avail = true;
  4580. } else {
  4581. crtc->config.dpll_hw_state.fp1 = fp;
  4582. }
  4583. }
  4584. static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe
  4585. pipe)
  4586. {
  4587. u32 reg_val;
  4588. /*
  4589. * PLLB opamp always calibrates to max value of 0x3f, force enable it
  4590. * and set it to a reasonable value instead.
  4591. */
  4592. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
  4593. reg_val &= 0xffffff00;
  4594. reg_val |= 0x00000030;
  4595. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
  4596. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
  4597. reg_val &= 0x8cffffff;
  4598. reg_val = 0x8c000000;
  4599. vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
  4600. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
  4601. reg_val &= 0xffffff00;
  4602. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
  4603. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
  4604. reg_val &= 0x00ffffff;
  4605. reg_val |= 0xb0000000;
  4606. vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
  4607. }
  4608. static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc,
  4609. struct intel_link_m_n *m_n)
  4610. {
  4611. struct drm_device *dev = crtc->base.dev;
  4612. struct drm_i915_private *dev_priv = dev->dev_private;
  4613. int pipe = crtc->pipe;
  4614. I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
  4615. I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n);
  4616. I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m);
  4617. I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n);
  4618. }
  4619. static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc,
  4620. struct intel_link_m_n *m_n)
  4621. {
  4622. struct drm_device *dev = crtc->base.dev;
  4623. struct drm_i915_private *dev_priv = dev->dev_private;
  4624. int pipe = crtc->pipe;
  4625. enum transcoder transcoder = crtc->config.cpu_transcoder;
  4626. if (INTEL_INFO(dev)->gen >= 5) {
  4627. I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m);
  4628. I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n);
  4629. I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m);
  4630. I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n);
  4631. } else {
  4632. I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
  4633. I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n);
  4634. I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m);
  4635. I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n);
  4636. }
  4637. }
  4638. static void intel_dp_set_m_n(struct intel_crtc *crtc)
  4639. {
  4640. if (crtc->config.has_pch_encoder)
  4641. intel_pch_transcoder_set_m_n(crtc, &crtc->config.dp_m_n);
  4642. else
  4643. intel_cpu_transcoder_set_m_n(crtc, &crtc->config.dp_m_n);
  4644. }
  4645. static void vlv_update_pll(struct intel_crtc *crtc)
  4646. {
  4647. u32 dpll, dpll_md;
  4648. /*
  4649. * Enable DPIO clock input. We should never disable the reference
  4650. * clock for pipe B, since VGA hotplug / manual detection depends
  4651. * on it.
  4652. */
  4653. dpll = DPLL_EXT_BUFFER_ENABLE_VLV | DPLL_REFA_CLK_ENABLE_VLV |
  4654. DPLL_VGA_MODE_DIS | DPLL_INTEGRATED_CLOCK_VLV;
  4655. /* We should never disable this, set it here for state tracking */
  4656. if (crtc->pipe == PIPE_B)
  4657. dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
  4658. dpll |= DPLL_VCO_ENABLE;
  4659. crtc->config.dpll_hw_state.dpll = dpll;
  4660. dpll_md = (crtc->config.pixel_multiplier - 1)
  4661. << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  4662. crtc->config.dpll_hw_state.dpll_md = dpll_md;
  4663. }
  4664. static void vlv_prepare_pll(struct intel_crtc *crtc)
  4665. {
  4666. struct drm_device *dev = crtc->base.dev;
  4667. struct drm_i915_private *dev_priv = dev->dev_private;
  4668. int pipe = crtc->pipe;
  4669. u32 mdiv;
  4670. u32 bestn, bestm1, bestm2, bestp1, bestp2;
  4671. u32 coreclk, reg_val;
  4672. mutex_lock(&dev_priv->dpio_lock);
  4673. bestn = crtc->config.dpll.n;
  4674. bestm1 = crtc->config.dpll.m1;
  4675. bestm2 = crtc->config.dpll.m2;
  4676. bestp1 = crtc->config.dpll.p1;
  4677. bestp2 = crtc->config.dpll.p2;
  4678. /* See eDP HDMI DPIO driver vbios notes doc */
  4679. /* PLL B needs special handling */
  4680. if (pipe == PIPE_B)
  4681. vlv_pllb_recal_opamp(dev_priv, pipe);
  4682. /* Set up Tx target for periodic Rcomp update */
  4683. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f);
  4684. /* Disable target IRef on PLL */
  4685. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe));
  4686. reg_val &= 0x00ffffff;
  4687. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val);
  4688. /* Disable fast lock */
  4689. vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610);
  4690. /* Set idtafcrecal before PLL is enabled */
  4691. mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
  4692. mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
  4693. mdiv |= ((bestn << DPIO_N_SHIFT));
  4694. mdiv |= (1 << DPIO_K_SHIFT);
  4695. /*
  4696. * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
  4697. * but we don't support that).
  4698. * Note: don't use the DAC post divider as it seems unstable.
  4699. */
  4700. mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
  4701. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
  4702. mdiv |= DPIO_ENABLE_CALIBRATION;
  4703. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
  4704. /* Set HBR and RBR LPF coefficients */
  4705. if (crtc->config.port_clock == 162000 ||
  4706. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_ANALOG) ||
  4707. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI))
  4708. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
  4709. 0x009f0003);
  4710. else
  4711. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
  4712. 0x00d0000f);
  4713. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_EDP) ||
  4714. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT)) {
  4715. /* Use SSC source */
  4716. if (pipe == PIPE_A)
  4717. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4718. 0x0df40000);
  4719. else
  4720. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4721. 0x0df70000);
  4722. } else { /* HDMI or VGA */
  4723. /* Use bend source */
  4724. if (pipe == PIPE_A)
  4725. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4726. 0x0df70000);
  4727. else
  4728. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4729. 0x0df40000);
  4730. }
  4731. coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe));
  4732. coreclk = (coreclk & 0x0000ff00) | 0x01c00000;
  4733. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT) ||
  4734. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_EDP))
  4735. coreclk |= 0x01000000;
  4736. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk);
  4737. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000);
  4738. mutex_unlock(&dev_priv->dpio_lock);
  4739. }
  4740. static void chv_update_pll(struct intel_crtc *crtc)
  4741. {
  4742. struct drm_device *dev = crtc->base.dev;
  4743. struct drm_i915_private *dev_priv = dev->dev_private;
  4744. int pipe = crtc->pipe;
  4745. int dpll_reg = DPLL(crtc->pipe);
  4746. enum dpio_channel port = vlv_pipe_to_channel(pipe);
  4747. u32 loopfilter, intcoeff;
  4748. u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac;
  4749. int refclk;
  4750. crtc->config.dpll_hw_state.dpll = DPLL_SSC_REF_CLOCK_CHV |
  4751. DPLL_REFA_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS |
  4752. DPLL_VCO_ENABLE;
  4753. if (pipe != PIPE_A)
  4754. crtc->config.dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
  4755. crtc->config.dpll_hw_state.dpll_md =
  4756. (crtc->config.pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  4757. bestn = crtc->config.dpll.n;
  4758. bestm2_frac = crtc->config.dpll.m2 & 0x3fffff;
  4759. bestm1 = crtc->config.dpll.m1;
  4760. bestm2 = crtc->config.dpll.m2 >> 22;
  4761. bestp1 = crtc->config.dpll.p1;
  4762. bestp2 = crtc->config.dpll.p2;
  4763. /*
  4764. * Enable Refclk and SSC
  4765. */
  4766. I915_WRITE(dpll_reg,
  4767. crtc->config.dpll_hw_state.dpll & ~DPLL_VCO_ENABLE);
  4768. mutex_lock(&dev_priv->dpio_lock);
  4769. /* p1 and p2 divider */
  4770. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port),
  4771. 5 << DPIO_CHV_S1_DIV_SHIFT |
  4772. bestp1 << DPIO_CHV_P1_DIV_SHIFT |
  4773. bestp2 << DPIO_CHV_P2_DIV_SHIFT |
  4774. 1 << DPIO_CHV_K_DIV_SHIFT);
  4775. /* Feedback post-divider - m2 */
  4776. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2);
  4777. /* Feedback refclk divider - n and m1 */
  4778. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port),
  4779. DPIO_CHV_M1_DIV_BY_2 |
  4780. 1 << DPIO_CHV_N_DIV_SHIFT);
  4781. /* M2 fraction division */
  4782. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac);
  4783. /* M2 fraction division enable */
  4784. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port),
  4785. DPIO_CHV_FRAC_DIV_EN |
  4786. (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT));
  4787. /* Loop filter */
  4788. refclk = i9xx_get_refclk(&crtc->base, 0);
  4789. loopfilter = 5 << DPIO_CHV_PROP_COEFF_SHIFT |
  4790. 2 << DPIO_CHV_GAIN_CTRL_SHIFT;
  4791. if (refclk == 100000)
  4792. intcoeff = 11;
  4793. else if (refclk == 38400)
  4794. intcoeff = 10;
  4795. else
  4796. intcoeff = 9;
  4797. loopfilter |= intcoeff << DPIO_CHV_INT_COEFF_SHIFT;
  4798. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter);
  4799. /* AFC Recal */
  4800. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port),
  4801. vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) |
  4802. DPIO_AFC_RECAL);
  4803. mutex_unlock(&dev_priv->dpio_lock);
  4804. }
  4805. static void i9xx_update_pll(struct intel_crtc *crtc,
  4806. intel_clock_t *reduced_clock,
  4807. int num_connectors)
  4808. {
  4809. struct drm_device *dev = crtc->base.dev;
  4810. struct drm_i915_private *dev_priv = dev->dev_private;
  4811. u32 dpll;
  4812. bool is_sdvo;
  4813. struct dpll *clock = &crtc->config.dpll;
  4814. i9xx_update_pll_dividers(crtc, reduced_clock);
  4815. is_sdvo = intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_SDVO) ||
  4816. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI);
  4817. dpll = DPLL_VGA_MODE_DIS;
  4818. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS))
  4819. dpll |= DPLLB_MODE_LVDS;
  4820. else
  4821. dpll |= DPLLB_MODE_DAC_SERIAL;
  4822. if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) {
  4823. dpll |= (crtc->config.pixel_multiplier - 1)
  4824. << SDVO_MULTIPLIER_SHIFT_HIRES;
  4825. }
  4826. if (is_sdvo)
  4827. dpll |= DPLL_SDVO_HIGH_SPEED;
  4828. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT))
  4829. dpll |= DPLL_SDVO_HIGH_SPEED;
  4830. /* compute bitmask from p1 value */
  4831. if (IS_PINEVIEW(dev))
  4832. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
  4833. else {
  4834. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  4835. if (IS_G4X(dev) && reduced_clock)
  4836. dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  4837. }
  4838. switch (clock->p2) {
  4839. case 5:
  4840. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  4841. break;
  4842. case 7:
  4843. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  4844. break;
  4845. case 10:
  4846. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  4847. break;
  4848. case 14:
  4849. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  4850. break;
  4851. }
  4852. if (INTEL_INFO(dev)->gen >= 4)
  4853. dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
  4854. if (crtc->config.sdvo_tv_clock)
  4855. dpll |= PLL_REF_INPUT_TVCLKINBC;
  4856. else if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
  4857. intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  4858. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  4859. else
  4860. dpll |= PLL_REF_INPUT_DREFCLK;
  4861. dpll |= DPLL_VCO_ENABLE;
  4862. crtc->config.dpll_hw_state.dpll = dpll;
  4863. if (INTEL_INFO(dev)->gen >= 4) {
  4864. u32 dpll_md = (crtc->config.pixel_multiplier - 1)
  4865. << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  4866. crtc->config.dpll_hw_state.dpll_md = dpll_md;
  4867. }
  4868. }
  4869. static void i8xx_update_pll(struct intel_crtc *crtc,
  4870. intel_clock_t *reduced_clock,
  4871. int num_connectors)
  4872. {
  4873. struct drm_device *dev = crtc->base.dev;
  4874. struct drm_i915_private *dev_priv = dev->dev_private;
  4875. u32 dpll;
  4876. struct dpll *clock = &crtc->config.dpll;
  4877. i9xx_update_pll_dividers(crtc, reduced_clock);
  4878. dpll = DPLL_VGA_MODE_DIS;
  4879. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS)) {
  4880. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  4881. } else {
  4882. if (clock->p1 == 2)
  4883. dpll |= PLL_P1_DIVIDE_BY_TWO;
  4884. else
  4885. dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  4886. if (clock->p2 == 4)
  4887. dpll |= PLL_P2_DIVIDE_BY_4;
  4888. }
  4889. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DVO))
  4890. dpll |= DPLL_DVO_2X_MODE;
  4891. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
  4892. intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  4893. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  4894. else
  4895. dpll |= PLL_REF_INPUT_DREFCLK;
  4896. dpll |= DPLL_VCO_ENABLE;
  4897. crtc->config.dpll_hw_state.dpll = dpll;
  4898. }
  4899. static void intel_set_pipe_timings(struct intel_crtc *intel_crtc)
  4900. {
  4901. struct drm_device *dev = intel_crtc->base.dev;
  4902. struct drm_i915_private *dev_priv = dev->dev_private;
  4903. enum pipe pipe = intel_crtc->pipe;
  4904. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  4905. struct drm_display_mode *adjusted_mode =
  4906. &intel_crtc->config.adjusted_mode;
  4907. uint32_t crtc_vtotal, crtc_vblank_end;
  4908. int vsyncshift = 0;
  4909. /* We need to be careful not to changed the adjusted mode, for otherwise
  4910. * the hw state checker will get angry at the mismatch. */
  4911. crtc_vtotal = adjusted_mode->crtc_vtotal;
  4912. crtc_vblank_end = adjusted_mode->crtc_vblank_end;
  4913. if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
  4914. /* the chip adds 2 halflines automatically */
  4915. crtc_vtotal -= 1;
  4916. crtc_vblank_end -= 1;
  4917. if (intel_pipe_has_type(&intel_crtc->base, INTEL_OUTPUT_SDVO))
  4918. vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
  4919. else
  4920. vsyncshift = adjusted_mode->crtc_hsync_start -
  4921. adjusted_mode->crtc_htotal / 2;
  4922. if (vsyncshift < 0)
  4923. vsyncshift += adjusted_mode->crtc_htotal;
  4924. }
  4925. if (INTEL_INFO(dev)->gen > 3)
  4926. I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
  4927. I915_WRITE(HTOTAL(cpu_transcoder),
  4928. (adjusted_mode->crtc_hdisplay - 1) |
  4929. ((adjusted_mode->crtc_htotal - 1) << 16));
  4930. I915_WRITE(HBLANK(cpu_transcoder),
  4931. (adjusted_mode->crtc_hblank_start - 1) |
  4932. ((adjusted_mode->crtc_hblank_end - 1) << 16));
  4933. I915_WRITE(HSYNC(cpu_transcoder),
  4934. (adjusted_mode->crtc_hsync_start - 1) |
  4935. ((adjusted_mode->crtc_hsync_end - 1) << 16));
  4936. I915_WRITE(VTOTAL(cpu_transcoder),
  4937. (adjusted_mode->crtc_vdisplay - 1) |
  4938. ((crtc_vtotal - 1) << 16));
  4939. I915_WRITE(VBLANK(cpu_transcoder),
  4940. (adjusted_mode->crtc_vblank_start - 1) |
  4941. ((crtc_vblank_end - 1) << 16));
  4942. I915_WRITE(VSYNC(cpu_transcoder),
  4943. (adjusted_mode->crtc_vsync_start - 1) |
  4944. ((adjusted_mode->crtc_vsync_end - 1) << 16));
  4945. /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
  4946. * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
  4947. * documented on the DDI_FUNC_CTL register description, EDP Input Select
  4948. * bits. */
  4949. if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP &&
  4950. (pipe == PIPE_B || pipe == PIPE_C))
  4951. I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
  4952. /* pipesrc controls the size that is scaled from, which should
  4953. * always be the user's requested size.
  4954. */
  4955. I915_WRITE(PIPESRC(pipe),
  4956. ((intel_crtc->config.pipe_src_w - 1) << 16) |
  4957. (intel_crtc->config.pipe_src_h - 1));
  4958. }
  4959. static void intel_get_pipe_timings(struct intel_crtc *crtc,
  4960. struct intel_crtc_config *pipe_config)
  4961. {
  4962. struct drm_device *dev = crtc->base.dev;
  4963. struct drm_i915_private *dev_priv = dev->dev_private;
  4964. enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
  4965. uint32_t tmp;
  4966. tmp = I915_READ(HTOTAL(cpu_transcoder));
  4967. pipe_config->adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
  4968. pipe_config->adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
  4969. tmp = I915_READ(HBLANK(cpu_transcoder));
  4970. pipe_config->adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1;
  4971. pipe_config->adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1;
  4972. tmp = I915_READ(HSYNC(cpu_transcoder));
  4973. pipe_config->adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
  4974. pipe_config->adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
  4975. tmp = I915_READ(VTOTAL(cpu_transcoder));
  4976. pipe_config->adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
  4977. pipe_config->adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
  4978. tmp = I915_READ(VBLANK(cpu_transcoder));
  4979. pipe_config->adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1;
  4980. pipe_config->adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1;
  4981. tmp = I915_READ(VSYNC(cpu_transcoder));
  4982. pipe_config->adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
  4983. pipe_config->adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
  4984. if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) {
  4985. pipe_config->adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
  4986. pipe_config->adjusted_mode.crtc_vtotal += 1;
  4987. pipe_config->adjusted_mode.crtc_vblank_end += 1;
  4988. }
  4989. tmp = I915_READ(PIPESRC(crtc->pipe));
  4990. pipe_config->pipe_src_h = (tmp & 0xffff) + 1;
  4991. pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1;
  4992. pipe_config->requested_mode.vdisplay = pipe_config->pipe_src_h;
  4993. pipe_config->requested_mode.hdisplay = pipe_config->pipe_src_w;
  4994. }
  4995. void intel_mode_from_pipe_config(struct drm_display_mode *mode,
  4996. struct intel_crtc_config *pipe_config)
  4997. {
  4998. mode->hdisplay = pipe_config->adjusted_mode.crtc_hdisplay;
  4999. mode->htotal = pipe_config->adjusted_mode.crtc_htotal;
  5000. mode->hsync_start = pipe_config->adjusted_mode.crtc_hsync_start;
  5001. mode->hsync_end = pipe_config->adjusted_mode.crtc_hsync_end;
  5002. mode->vdisplay = pipe_config->adjusted_mode.crtc_vdisplay;
  5003. mode->vtotal = pipe_config->adjusted_mode.crtc_vtotal;
  5004. mode->vsync_start = pipe_config->adjusted_mode.crtc_vsync_start;
  5005. mode->vsync_end = pipe_config->adjusted_mode.crtc_vsync_end;
  5006. mode->flags = pipe_config->adjusted_mode.flags;
  5007. mode->clock = pipe_config->adjusted_mode.crtc_clock;
  5008. mode->flags |= pipe_config->adjusted_mode.flags;
  5009. }
  5010. static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc)
  5011. {
  5012. struct drm_device *dev = intel_crtc->base.dev;
  5013. struct drm_i915_private *dev_priv = dev->dev_private;
  5014. uint32_t pipeconf;
  5015. pipeconf = 0;
  5016. if (dev_priv->quirks & QUIRK_PIPEA_FORCE &&
  5017. I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE)
  5018. pipeconf |= PIPECONF_ENABLE;
  5019. if (intel_crtc->config.double_wide)
  5020. pipeconf |= PIPECONF_DOUBLE_WIDE;
  5021. /* only g4x and later have fancy bpc/dither controls */
  5022. if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) {
  5023. /* Bspec claims that we can't use dithering for 30bpp pipes. */
  5024. if (intel_crtc->config.dither && intel_crtc->config.pipe_bpp != 30)
  5025. pipeconf |= PIPECONF_DITHER_EN |
  5026. PIPECONF_DITHER_TYPE_SP;
  5027. switch (intel_crtc->config.pipe_bpp) {
  5028. case 18:
  5029. pipeconf |= PIPECONF_6BPC;
  5030. break;
  5031. case 24:
  5032. pipeconf |= PIPECONF_8BPC;
  5033. break;
  5034. case 30:
  5035. pipeconf |= PIPECONF_10BPC;
  5036. break;
  5037. default:
  5038. /* Case prevented by intel_choose_pipe_bpp_dither. */
  5039. BUG();
  5040. }
  5041. }
  5042. if (HAS_PIPE_CXSR(dev)) {
  5043. if (intel_crtc->lowfreq_avail) {
  5044. DRM_DEBUG_KMS("enabling CxSR downclocking\n");
  5045. pipeconf |= PIPECONF_CXSR_DOWNCLOCK;
  5046. } else {
  5047. DRM_DEBUG_KMS("disabling CxSR downclocking\n");
  5048. }
  5049. }
  5050. if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
  5051. if (INTEL_INFO(dev)->gen < 4 ||
  5052. intel_pipe_has_type(&intel_crtc->base, INTEL_OUTPUT_SDVO))
  5053. pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
  5054. else
  5055. pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT;
  5056. } else
  5057. pipeconf |= PIPECONF_PROGRESSIVE;
  5058. if (IS_VALLEYVIEW(dev) && intel_crtc->config.limited_color_range)
  5059. pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
  5060. I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf);
  5061. POSTING_READ(PIPECONF(intel_crtc->pipe));
  5062. }
  5063. static int i9xx_crtc_mode_set(struct drm_crtc *crtc,
  5064. int x, int y,
  5065. struct drm_framebuffer *fb)
  5066. {
  5067. struct drm_device *dev = crtc->dev;
  5068. struct drm_i915_private *dev_priv = dev->dev_private;
  5069. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5070. int refclk, num_connectors = 0;
  5071. intel_clock_t clock, reduced_clock;
  5072. bool ok, has_reduced_clock = false;
  5073. bool is_lvds = false, is_dsi = false;
  5074. struct intel_encoder *encoder;
  5075. const intel_limit_t *limit;
  5076. for_each_encoder_on_crtc(dev, crtc, encoder) {
  5077. switch (encoder->type) {
  5078. case INTEL_OUTPUT_LVDS:
  5079. is_lvds = true;
  5080. break;
  5081. case INTEL_OUTPUT_DSI:
  5082. is_dsi = true;
  5083. break;
  5084. }
  5085. num_connectors++;
  5086. }
  5087. if (is_dsi)
  5088. return 0;
  5089. if (!intel_crtc->config.clock_set) {
  5090. refclk = i9xx_get_refclk(crtc, num_connectors);
  5091. /*
  5092. * Returns a set of divisors for the desired target clock with
  5093. * the given refclk, or FALSE. The returned values represent
  5094. * the clock equation: reflck * (5 * (m1 + 2) + (m2 + 2)) / (n +
  5095. * 2) / p1 / p2.
  5096. */
  5097. limit = intel_limit(crtc, refclk);
  5098. ok = dev_priv->display.find_dpll(limit, crtc,
  5099. intel_crtc->config.port_clock,
  5100. refclk, NULL, &clock);
  5101. if (!ok) {
  5102. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  5103. return -EINVAL;
  5104. }
  5105. if (is_lvds && dev_priv->lvds_downclock_avail) {
  5106. /*
  5107. * Ensure we match the reduced clock's P to the target
  5108. * clock. If the clocks don't match, we can't switch
  5109. * the display clock by using the FP0/FP1. In such case
  5110. * we will disable the LVDS downclock feature.
  5111. */
  5112. has_reduced_clock =
  5113. dev_priv->display.find_dpll(limit, crtc,
  5114. dev_priv->lvds_downclock,
  5115. refclk, &clock,
  5116. &reduced_clock);
  5117. }
  5118. /* Compat-code for transition, will disappear. */
  5119. intel_crtc->config.dpll.n = clock.n;
  5120. intel_crtc->config.dpll.m1 = clock.m1;
  5121. intel_crtc->config.dpll.m2 = clock.m2;
  5122. intel_crtc->config.dpll.p1 = clock.p1;
  5123. intel_crtc->config.dpll.p2 = clock.p2;
  5124. }
  5125. if (IS_GEN2(dev)) {
  5126. i8xx_update_pll(intel_crtc,
  5127. has_reduced_clock ? &reduced_clock : NULL,
  5128. num_connectors);
  5129. } else if (IS_CHERRYVIEW(dev)) {
  5130. chv_update_pll(intel_crtc);
  5131. } else if (IS_VALLEYVIEW(dev)) {
  5132. vlv_update_pll(intel_crtc);
  5133. } else {
  5134. i9xx_update_pll(intel_crtc,
  5135. has_reduced_clock ? &reduced_clock : NULL,
  5136. num_connectors);
  5137. }
  5138. return 0;
  5139. }
  5140. static void i9xx_get_pfit_config(struct intel_crtc *crtc,
  5141. struct intel_crtc_config *pipe_config)
  5142. {
  5143. struct drm_device *dev = crtc->base.dev;
  5144. struct drm_i915_private *dev_priv = dev->dev_private;
  5145. uint32_t tmp;
  5146. if (INTEL_INFO(dev)->gen <= 3 && (IS_I830(dev) || !IS_MOBILE(dev)))
  5147. return;
  5148. tmp = I915_READ(PFIT_CONTROL);
  5149. if (!(tmp & PFIT_ENABLE))
  5150. return;
  5151. /* Check whether the pfit is attached to our pipe. */
  5152. if (INTEL_INFO(dev)->gen < 4) {
  5153. if (crtc->pipe != PIPE_B)
  5154. return;
  5155. } else {
  5156. if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
  5157. return;
  5158. }
  5159. pipe_config->gmch_pfit.control = tmp;
  5160. pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS);
  5161. if (INTEL_INFO(dev)->gen < 5)
  5162. pipe_config->gmch_pfit.lvds_border_bits =
  5163. I915_READ(LVDS) & LVDS_BORDER_ENABLE;
  5164. }
  5165. static void vlv_crtc_clock_get(struct intel_crtc *crtc,
  5166. struct intel_crtc_config *pipe_config)
  5167. {
  5168. struct drm_device *dev = crtc->base.dev;
  5169. struct drm_i915_private *dev_priv = dev->dev_private;
  5170. int pipe = pipe_config->cpu_transcoder;
  5171. intel_clock_t clock;
  5172. u32 mdiv;
  5173. int refclk = 100000;
  5174. mutex_lock(&dev_priv->dpio_lock);
  5175. mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
  5176. mutex_unlock(&dev_priv->dpio_lock);
  5177. clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
  5178. clock.m2 = mdiv & DPIO_M2DIV_MASK;
  5179. clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
  5180. clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
  5181. clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
  5182. vlv_clock(refclk, &clock);
  5183. /* clock.dot is the fast clock */
  5184. pipe_config->port_clock = clock.dot / 5;
  5185. }
  5186. static void i9xx_get_plane_config(struct intel_crtc *crtc,
  5187. struct intel_plane_config *plane_config)
  5188. {
  5189. struct drm_device *dev = crtc->base.dev;
  5190. struct drm_i915_private *dev_priv = dev->dev_private;
  5191. u32 val, base, offset;
  5192. int pipe = crtc->pipe, plane = crtc->plane;
  5193. int fourcc, pixel_format;
  5194. int aligned_height;
  5195. crtc->base.primary->fb = kzalloc(sizeof(struct intel_framebuffer), GFP_KERNEL);
  5196. if (!crtc->base.primary->fb) {
  5197. DRM_DEBUG_KMS("failed to alloc fb\n");
  5198. return;
  5199. }
  5200. val = I915_READ(DSPCNTR(plane));
  5201. if (INTEL_INFO(dev)->gen >= 4)
  5202. if (val & DISPPLANE_TILED)
  5203. plane_config->tiled = true;
  5204. pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
  5205. fourcc = intel_format_to_fourcc(pixel_format);
  5206. crtc->base.primary->fb->pixel_format = fourcc;
  5207. crtc->base.primary->fb->bits_per_pixel =
  5208. drm_format_plane_cpp(fourcc, 0) * 8;
  5209. if (INTEL_INFO(dev)->gen >= 4) {
  5210. if (plane_config->tiled)
  5211. offset = I915_READ(DSPTILEOFF(plane));
  5212. else
  5213. offset = I915_READ(DSPLINOFF(plane));
  5214. base = I915_READ(DSPSURF(plane)) & 0xfffff000;
  5215. } else {
  5216. base = I915_READ(DSPADDR(plane));
  5217. }
  5218. plane_config->base = base;
  5219. val = I915_READ(PIPESRC(pipe));
  5220. crtc->base.primary->fb->width = ((val >> 16) & 0xfff) + 1;
  5221. crtc->base.primary->fb->height = ((val >> 0) & 0xfff) + 1;
  5222. val = I915_READ(DSPSTRIDE(pipe));
  5223. crtc->base.primary->fb->pitches[0] = val & 0xffffff80;
  5224. aligned_height = intel_align_height(dev, crtc->base.primary->fb->height,
  5225. plane_config->tiled);
  5226. plane_config->size = PAGE_ALIGN(crtc->base.primary->fb->pitches[0] *
  5227. aligned_height);
  5228. DRM_DEBUG_KMS("pipe/plane %d/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
  5229. pipe, plane, crtc->base.primary->fb->width,
  5230. crtc->base.primary->fb->height,
  5231. crtc->base.primary->fb->bits_per_pixel, base,
  5232. crtc->base.primary->fb->pitches[0],
  5233. plane_config->size);
  5234. }
  5235. static void chv_crtc_clock_get(struct intel_crtc *crtc,
  5236. struct intel_crtc_config *pipe_config)
  5237. {
  5238. struct drm_device *dev = crtc->base.dev;
  5239. struct drm_i915_private *dev_priv = dev->dev_private;
  5240. int pipe = pipe_config->cpu_transcoder;
  5241. enum dpio_channel port = vlv_pipe_to_channel(pipe);
  5242. intel_clock_t clock;
  5243. u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2;
  5244. int refclk = 100000;
  5245. mutex_lock(&dev_priv->dpio_lock);
  5246. cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
  5247. pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
  5248. pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
  5249. pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
  5250. mutex_unlock(&dev_priv->dpio_lock);
  5251. clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
  5252. clock.m2 = ((pll_dw0 & 0xff) << 22) | (pll_dw2 & 0x3fffff);
  5253. clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
  5254. clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
  5255. clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
  5256. chv_clock(refclk, &clock);
  5257. /* clock.dot is the fast clock */
  5258. pipe_config->port_clock = clock.dot / 5;
  5259. }
  5260. static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
  5261. struct intel_crtc_config *pipe_config)
  5262. {
  5263. struct drm_device *dev = crtc->base.dev;
  5264. struct drm_i915_private *dev_priv = dev->dev_private;
  5265. uint32_t tmp;
  5266. if (!intel_display_power_enabled(dev_priv,
  5267. POWER_DOMAIN_PIPE(crtc->pipe)))
  5268. return false;
  5269. pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
  5270. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  5271. tmp = I915_READ(PIPECONF(crtc->pipe));
  5272. if (!(tmp & PIPECONF_ENABLE))
  5273. return false;
  5274. if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) {
  5275. switch (tmp & PIPECONF_BPC_MASK) {
  5276. case PIPECONF_6BPC:
  5277. pipe_config->pipe_bpp = 18;
  5278. break;
  5279. case PIPECONF_8BPC:
  5280. pipe_config->pipe_bpp = 24;
  5281. break;
  5282. case PIPECONF_10BPC:
  5283. pipe_config->pipe_bpp = 30;
  5284. break;
  5285. default:
  5286. break;
  5287. }
  5288. }
  5289. if (IS_VALLEYVIEW(dev) && (tmp & PIPECONF_COLOR_RANGE_SELECT))
  5290. pipe_config->limited_color_range = true;
  5291. if (INTEL_INFO(dev)->gen < 4)
  5292. pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
  5293. intel_get_pipe_timings(crtc, pipe_config);
  5294. i9xx_get_pfit_config(crtc, pipe_config);
  5295. if (INTEL_INFO(dev)->gen >= 4) {
  5296. tmp = I915_READ(DPLL_MD(crtc->pipe));
  5297. pipe_config->pixel_multiplier =
  5298. ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
  5299. >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
  5300. pipe_config->dpll_hw_state.dpll_md = tmp;
  5301. } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) {
  5302. tmp = I915_READ(DPLL(crtc->pipe));
  5303. pipe_config->pixel_multiplier =
  5304. ((tmp & SDVO_MULTIPLIER_MASK)
  5305. >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
  5306. } else {
  5307. /* Note that on i915G/GM the pixel multiplier is in the sdvo
  5308. * port and will be fixed up in the encoder->get_config
  5309. * function. */
  5310. pipe_config->pixel_multiplier = 1;
  5311. }
  5312. pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe));
  5313. if (!IS_VALLEYVIEW(dev)) {
  5314. pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe));
  5315. pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe));
  5316. } else {
  5317. /* Mask out read-only status bits. */
  5318. pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
  5319. DPLL_PORTC_READY_MASK |
  5320. DPLL_PORTB_READY_MASK);
  5321. }
  5322. if (IS_CHERRYVIEW(dev))
  5323. chv_crtc_clock_get(crtc, pipe_config);
  5324. else if (IS_VALLEYVIEW(dev))
  5325. vlv_crtc_clock_get(crtc, pipe_config);
  5326. else
  5327. i9xx_crtc_clock_get(crtc, pipe_config);
  5328. return true;
  5329. }
  5330. static void ironlake_init_pch_refclk(struct drm_device *dev)
  5331. {
  5332. struct drm_i915_private *dev_priv = dev->dev_private;
  5333. struct drm_mode_config *mode_config = &dev->mode_config;
  5334. struct intel_encoder *encoder;
  5335. u32 val, final;
  5336. bool has_lvds = false;
  5337. bool has_cpu_edp = false;
  5338. bool has_panel = false;
  5339. bool has_ck505 = false;
  5340. bool can_ssc = false;
  5341. /* We need to take the global config into account */
  5342. list_for_each_entry(encoder, &mode_config->encoder_list,
  5343. base.head) {
  5344. switch (encoder->type) {
  5345. case INTEL_OUTPUT_LVDS:
  5346. has_panel = true;
  5347. has_lvds = true;
  5348. break;
  5349. case INTEL_OUTPUT_EDP:
  5350. has_panel = true;
  5351. if (enc_to_dig_port(&encoder->base)->port == PORT_A)
  5352. has_cpu_edp = true;
  5353. break;
  5354. }
  5355. }
  5356. if (HAS_PCH_IBX(dev)) {
  5357. has_ck505 = dev_priv->vbt.display_clock_mode;
  5358. can_ssc = has_ck505;
  5359. } else {
  5360. has_ck505 = false;
  5361. can_ssc = true;
  5362. }
  5363. DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n",
  5364. has_panel, has_lvds, has_ck505);
  5365. /* Ironlake: try to setup display ref clock before DPLL
  5366. * enabling. This is only under driver's control after
  5367. * PCH B stepping, previous chipset stepping should be
  5368. * ignoring this setting.
  5369. */
  5370. val = I915_READ(PCH_DREF_CONTROL);
  5371. /* As we must carefully and slowly disable/enable each source in turn,
  5372. * compute the final state we want first and check if we need to
  5373. * make any changes at all.
  5374. */
  5375. final = val;
  5376. final &= ~DREF_NONSPREAD_SOURCE_MASK;
  5377. if (has_ck505)
  5378. final |= DREF_NONSPREAD_CK505_ENABLE;
  5379. else
  5380. final |= DREF_NONSPREAD_SOURCE_ENABLE;
  5381. final &= ~DREF_SSC_SOURCE_MASK;
  5382. final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  5383. final &= ~DREF_SSC1_ENABLE;
  5384. if (has_panel) {
  5385. final |= DREF_SSC_SOURCE_ENABLE;
  5386. if (intel_panel_use_ssc(dev_priv) && can_ssc)
  5387. final |= DREF_SSC1_ENABLE;
  5388. if (has_cpu_edp) {
  5389. if (intel_panel_use_ssc(dev_priv) && can_ssc)
  5390. final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
  5391. else
  5392. final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
  5393. } else
  5394. final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  5395. } else {
  5396. final |= DREF_SSC_SOURCE_DISABLE;
  5397. final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  5398. }
  5399. if (final == val)
  5400. return;
  5401. /* Always enable nonspread source */
  5402. val &= ~DREF_NONSPREAD_SOURCE_MASK;
  5403. if (has_ck505)
  5404. val |= DREF_NONSPREAD_CK505_ENABLE;
  5405. else
  5406. val |= DREF_NONSPREAD_SOURCE_ENABLE;
  5407. if (has_panel) {
  5408. val &= ~DREF_SSC_SOURCE_MASK;
  5409. val |= DREF_SSC_SOURCE_ENABLE;
  5410. /* SSC must be turned on before enabling the CPU output */
  5411. if (intel_panel_use_ssc(dev_priv) && can_ssc) {
  5412. DRM_DEBUG_KMS("Using SSC on panel\n");
  5413. val |= DREF_SSC1_ENABLE;
  5414. } else
  5415. val &= ~DREF_SSC1_ENABLE;
  5416. /* Get SSC going before enabling the outputs */
  5417. I915_WRITE(PCH_DREF_CONTROL, val);
  5418. POSTING_READ(PCH_DREF_CONTROL);
  5419. udelay(200);
  5420. val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  5421. /* Enable CPU source on CPU attached eDP */
  5422. if (has_cpu_edp) {
  5423. if (intel_panel_use_ssc(dev_priv) && can_ssc) {
  5424. DRM_DEBUG_KMS("Using SSC on eDP\n");
  5425. val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
  5426. } else
  5427. val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
  5428. } else
  5429. val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  5430. I915_WRITE(PCH_DREF_CONTROL, val);
  5431. POSTING_READ(PCH_DREF_CONTROL);
  5432. udelay(200);
  5433. } else {
  5434. DRM_DEBUG_KMS("Disabling SSC entirely\n");
  5435. val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  5436. /* Turn off CPU output */
  5437. val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  5438. I915_WRITE(PCH_DREF_CONTROL, val);
  5439. POSTING_READ(PCH_DREF_CONTROL);
  5440. udelay(200);
  5441. /* Turn off the SSC source */
  5442. val &= ~DREF_SSC_SOURCE_MASK;
  5443. val |= DREF_SSC_SOURCE_DISABLE;
  5444. /* Turn off SSC1 */
  5445. val &= ~DREF_SSC1_ENABLE;
  5446. I915_WRITE(PCH_DREF_CONTROL, val);
  5447. POSTING_READ(PCH_DREF_CONTROL);
  5448. udelay(200);
  5449. }
  5450. BUG_ON(val != final);
  5451. }
  5452. static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv)
  5453. {
  5454. uint32_t tmp;
  5455. tmp = I915_READ(SOUTH_CHICKEN2);
  5456. tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
  5457. I915_WRITE(SOUTH_CHICKEN2, tmp);
  5458. if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) &
  5459. FDI_MPHY_IOSFSB_RESET_STATUS, 100))
  5460. DRM_ERROR("FDI mPHY reset assert timeout\n");
  5461. tmp = I915_READ(SOUTH_CHICKEN2);
  5462. tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
  5463. I915_WRITE(SOUTH_CHICKEN2, tmp);
  5464. if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) &
  5465. FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100))
  5466. DRM_ERROR("FDI mPHY reset de-assert timeout\n");
  5467. }
  5468. /* WaMPhyProgramming:hsw */
  5469. static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv)
  5470. {
  5471. uint32_t tmp;
  5472. tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
  5473. tmp &= ~(0xFF << 24);
  5474. tmp |= (0x12 << 24);
  5475. intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
  5476. tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
  5477. tmp |= (1 << 11);
  5478. intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
  5479. tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
  5480. tmp |= (1 << 11);
  5481. intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
  5482. tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
  5483. tmp |= (1 << 24) | (1 << 21) | (1 << 18);
  5484. intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
  5485. tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
  5486. tmp |= (1 << 24) | (1 << 21) | (1 << 18);
  5487. intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
  5488. tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
  5489. tmp &= ~(7 << 13);
  5490. tmp |= (5 << 13);
  5491. intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
  5492. tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
  5493. tmp &= ~(7 << 13);
  5494. tmp |= (5 << 13);
  5495. intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
  5496. tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
  5497. tmp &= ~0xFF;
  5498. tmp |= 0x1C;
  5499. intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
  5500. tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
  5501. tmp &= ~0xFF;
  5502. tmp |= 0x1C;
  5503. intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
  5504. tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
  5505. tmp &= ~(0xFF << 16);
  5506. tmp |= (0x1C << 16);
  5507. intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
  5508. tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
  5509. tmp &= ~(0xFF << 16);
  5510. tmp |= (0x1C << 16);
  5511. intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
  5512. tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
  5513. tmp |= (1 << 27);
  5514. intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
  5515. tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
  5516. tmp |= (1 << 27);
  5517. intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
  5518. tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
  5519. tmp &= ~(0xF << 28);
  5520. tmp |= (4 << 28);
  5521. intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
  5522. tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
  5523. tmp &= ~(0xF << 28);
  5524. tmp |= (4 << 28);
  5525. intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
  5526. }
  5527. /* Implements 3 different sequences from BSpec chapter "Display iCLK
  5528. * Programming" based on the parameters passed:
  5529. * - Sequence to enable CLKOUT_DP
  5530. * - Sequence to enable CLKOUT_DP without spread
  5531. * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
  5532. */
  5533. static void lpt_enable_clkout_dp(struct drm_device *dev, bool with_spread,
  5534. bool with_fdi)
  5535. {
  5536. struct drm_i915_private *dev_priv = dev->dev_private;
  5537. uint32_t reg, tmp;
  5538. if (WARN(with_fdi && !with_spread, "FDI requires downspread\n"))
  5539. with_spread = true;
  5540. if (WARN(dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE &&
  5541. with_fdi, "LP PCH doesn't have FDI\n"))
  5542. with_fdi = false;
  5543. mutex_lock(&dev_priv->dpio_lock);
  5544. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  5545. tmp &= ~SBI_SSCCTL_DISABLE;
  5546. tmp |= SBI_SSCCTL_PATHALT;
  5547. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  5548. udelay(24);
  5549. if (with_spread) {
  5550. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  5551. tmp &= ~SBI_SSCCTL_PATHALT;
  5552. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  5553. if (with_fdi) {
  5554. lpt_reset_fdi_mphy(dev_priv);
  5555. lpt_program_fdi_mphy(dev_priv);
  5556. }
  5557. }
  5558. reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ?
  5559. SBI_GEN0 : SBI_DBUFF0;
  5560. tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
  5561. tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE;
  5562. intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
  5563. mutex_unlock(&dev_priv->dpio_lock);
  5564. }
  5565. /* Sequence to disable CLKOUT_DP */
  5566. static void lpt_disable_clkout_dp(struct drm_device *dev)
  5567. {
  5568. struct drm_i915_private *dev_priv = dev->dev_private;
  5569. uint32_t reg, tmp;
  5570. mutex_lock(&dev_priv->dpio_lock);
  5571. reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ?
  5572. SBI_GEN0 : SBI_DBUFF0;
  5573. tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
  5574. tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE;
  5575. intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
  5576. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  5577. if (!(tmp & SBI_SSCCTL_DISABLE)) {
  5578. if (!(tmp & SBI_SSCCTL_PATHALT)) {
  5579. tmp |= SBI_SSCCTL_PATHALT;
  5580. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  5581. udelay(32);
  5582. }
  5583. tmp |= SBI_SSCCTL_DISABLE;
  5584. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  5585. }
  5586. mutex_unlock(&dev_priv->dpio_lock);
  5587. }
  5588. static void lpt_init_pch_refclk(struct drm_device *dev)
  5589. {
  5590. struct drm_mode_config *mode_config = &dev->mode_config;
  5591. struct intel_encoder *encoder;
  5592. bool has_vga = false;
  5593. list_for_each_entry(encoder, &mode_config->encoder_list, base.head) {
  5594. switch (encoder->type) {
  5595. case INTEL_OUTPUT_ANALOG:
  5596. has_vga = true;
  5597. break;
  5598. }
  5599. }
  5600. if (has_vga)
  5601. lpt_enable_clkout_dp(dev, true, true);
  5602. else
  5603. lpt_disable_clkout_dp(dev);
  5604. }
  5605. /*
  5606. * Initialize reference clocks when the driver loads
  5607. */
  5608. void intel_init_pch_refclk(struct drm_device *dev)
  5609. {
  5610. if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
  5611. ironlake_init_pch_refclk(dev);
  5612. else if (HAS_PCH_LPT(dev))
  5613. lpt_init_pch_refclk(dev);
  5614. }
  5615. static int ironlake_get_refclk(struct drm_crtc *crtc)
  5616. {
  5617. struct drm_device *dev = crtc->dev;
  5618. struct drm_i915_private *dev_priv = dev->dev_private;
  5619. struct intel_encoder *encoder;
  5620. int num_connectors = 0;
  5621. bool is_lvds = false;
  5622. for_each_encoder_on_crtc(dev, crtc, encoder) {
  5623. switch (encoder->type) {
  5624. case INTEL_OUTPUT_LVDS:
  5625. is_lvds = true;
  5626. break;
  5627. }
  5628. num_connectors++;
  5629. }
  5630. if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
  5631. DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
  5632. dev_priv->vbt.lvds_ssc_freq);
  5633. return dev_priv->vbt.lvds_ssc_freq;
  5634. }
  5635. return 120000;
  5636. }
  5637. static void ironlake_set_pipeconf(struct drm_crtc *crtc)
  5638. {
  5639. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  5640. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5641. int pipe = intel_crtc->pipe;
  5642. uint32_t val;
  5643. val = 0;
  5644. switch (intel_crtc->config.pipe_bpp) {
  5645. case 18:
  5646. val |= PIPECONF_6BPC;
  5647. break;
  5648. case 24:
  5649. val |= PIPECONF_8BPC;
  5650. break;
  5651. case 30:
  5652. val |= PIPECONF_10BPC;
  5653. break;
  5654. case 36:
  5655. val |= PIPECONF_12BPC;
  5656. break;
  5657. default:
  5658. /* Case prevented by intel_choose_pipe_bpp_dither. */
  5659. BUG();
  5660. }
  5661. if (intel_crtc->config.dither)
  5662. val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
  5663. if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
  5664. val |= PIPECONF_INTERLACED_ILK;
  5665. else
  5666. val |= PIPECONF_PROGRESSIVE;
  5667. if (intel_crtc->config.limited_color_range)
  5668. val |= PIPECONF_COLOR_RANGE_SELECT;
  5669. I915_WRITE(PIPECONF(pipe), val);
  5670. POSTING_READ(PIPECONF(pipe));
  5671. }
  5672. /*
  5673. * Set up the pipe CSC unit.
  5674. *
  5675. * Currently only full range RGB to limited range RGB conversion
  5676. * is supported, but eventually this should handle various
  5677. * RGB<->YCbCr scenarios as well.
  5678. */
  5679. static void intel_set_pipe_csc(struct drm_crtc *crtc)
  5680. {
  5681. struct drm_device *dev = crtc->dev;
  5682. struct drm_i915_private *dev_priv = dev->dev_private;
  5683. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5684. int pipe = intel_crtc->pipe;
  5685. uint16_t coeff = 0x7800; /* 1.0 */
  5686. /*
  5687. * TODO: Check what kind of values actually come out of the pipe
  5688. * with these coeff/postoff values and adjust to get the best
  5689. * accuracy. Perhaps we even need to take the bpc value into
  5690. * consideration.
  5691. */
  5692. if (intel_crtc->config.limited_color_range)
  5693. coeff = ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */
  5694. /*
  5695. * GY/GU and RY/RU should be the other way around according
  5696. * to BSpec, but reality doesn't agree. Just set them up in
  5697. * a way that results in the correct picture.
  5698. */
  5699. I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe), coeff << 16);
  5700. I915_WRITE(PIPE_CSC_COEFF_BY(pipe), 0);
  5701. I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe), coeff);
  5702. I915_WRITE(PIPE_CSC_COEFF_BU(pipe), 0);
  5703. I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe), 0);
  5704. I915_WRITE(PIPE_CSC_COEFF_BV(pipe), coeff << 16);
  5705. I915_WRITE(PIPE_CSC_PREOFF_HI(pipe), 0);
  5706. I915_WRITE(PIPE_CSC_PREOFF_ME(pipe), 0);
  5707. I915_WRITE(PIPE_CSC_PREOFF_LO(pipe), 0);
  5708. if (INTEL_INFO(dev)->gen > 6) {
  5709. uint16_t postoff = 0;
  5710. if (intel_crtc->config.limited_color_range)
  5711. postoff = (16 * (1 << 12) / 255) & 0x1fff;
  5712. I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe), postoff);
  5713. I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe), postoff);
  5714. I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe), postoff);
  5715. I915_WRITE(PIPE_CSC_MODE(pipe), 0);
  5716. } else {
  5717. uint32_t mode = CSC_MODE_YUV_TO_RGB;
  5718. if (intel_crtc->config.limited_color_range)
  5719. mode |= CSC_BLACK_SCREEN_OFFSET;
  5720. I915_WRITE(PIPE_CSC_MODE(pipe), mode);
  5721. }
  5722. }
  5723. static void haswell_set_pipeconf(struct drm_crtc *crtc)
  5724. {
  5725. struct drm_device *dev = crtc->dev;
  5726. struct drm_i915_private *dev_priv = dev->dev_private;
  5727. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5728. enum pipe pipe = intel_crtc->pipe;
  5729. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  5730. uint32_t val;
  5731. val = 0;
  5732. if (IS_HASWELL(dev) && intel_crtc->config.dither)
  5733. val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
  5734. if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
  5735. val |= PIPECONF_INTERLACED_ILK;
  5736. else
  5737. val |= PIPECONF_PROGRESSIVE;
  5738. I915_WRITE(PIPECONF(cpu_transcoder), val);
  5739. POSTING_READ(PIPECONF(cpu_transcoder));
  5740. I915_WRITE(GAMMA_MODE(intel_crtc->pipe), GAMMA_MODE_MODE_8BIT);
  5741. POSTING_READ(GAMMA_MODE(intel_crtc->pipe));
  5742. if (IS_BROADWELL(dev)) {
  5743. val = 0;
  5744. switch (intel_crtc->config.pipe_bpp) {
  5745. case 18:
  5746. val |= PIPEMISC_DITHER_6_BPC;
  5747. break;
  5748. case 24:
  5749. val |= PIPEMISC_DITHER_8_BPC;
  5750. break;
  5751. case 30:
  5752. val |= PIPEMISC_DITHER_10_BPC;
  5753. break;
  5754. case 36:
  5755. val |= PIPEMISC_DITHER_12_BPC;
  5756. break;
  5757. default:
  5758. /* Case prevented by pipe_config_set_bpp. */
  5759. BUG();
  5760. }
  5761. if (intel_crtc->config.dither)
  5762. val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
  5763. I915_WRITE(PIPEMISC(pipe), val);
  5764. }
  5765. }
  5766. static bool ironlake_compute_clocks(struct drm_crtc *crtc,
  5767. intel_clock_t *clock,
  5768. bool *has_reduced_clock,
  5769. intel_clock_t *reduced_clock)
  5770. {
  5771. struct drm_device *dev = crtc->dev;
  5772. struct drm_i915_private *dev_priv = dev->dev_private;
  5773. struct intel_encoder *intel_encoder;
  5774. int refclk;
  5775. const intel_limit_t *limit;
  5776. bool ret, is_lvds = false;
  5777. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  5778. switch (intel_encoder->type) {
  5779. case INTEL_OUTPUT_LVDS:
  5780. is_lvds = true;
  5781. break;
  5782. }
  5783. }
  5784. refclk = ironlake_get_refclk(crtc);
  5785. /*
  5786. * Returns a set of divisors for the desired target clock with the given
  5787. * refclk, or FALSE. The returned values represent the clock equation:
  5788. * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
  5789. */
  5790. limit = intel_limit(crtc, refclk);
  5791. ret = dev_priv->display.find_dpll(limit, crtc,
  5792. to_intel_crtc(crtc)->config.port_clock,
  5793. refclk, NULL, clock);
  5794. if (!ret)
  5795. return false;
  5796. if (is_lvds && dev_priv->lvds_downclock_avail) {
  5797. /*
  5798. * Ensure we match the reduced clock's P to the target clock.
  5799. * If the clocks don't match, we can't switch the display clock
  5800. * by using the FP0/FP1. In such case we will disable the LVDS
  5801. * downclock feature.
  5802. */
  5803. *has_reduced_clock =
  5804. dev_priv->display.find_dpll(limit, crtc,
  5805. dev_priv->lvds_downclock,
  5806. refclk, clock,
  5807. reduced_clock);
  5808. }
  5809. return true;
  5810. }
  5811. int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
  5812. {
  5813. /*
  5814. * Account for spread spectrum to avoid
  5815. * oversubscribing the link. Max center spread
  5816. * is 2.5%; use 5% for safety's sake.
  5817. */
  5818. u32 bps = target_clock * bpp * 21 / 20;
  5819. return DIV_ROUND_UP(bps, link_bw * 8);
  5820. }
  5821. static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor)
  5822. {
  5823. return i9xx_dpll_compute_m(dpll) < factor * dpll->n;
  5824. }
  5825. static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc,
  5826. u32 *fp,
  5827. intel_clock_t *reduced_clock, u32 *fp2)
  5828. {
  5829. struct drm_crtc *crtc = &intel_crtc->base;
  5830. struct drm_device *dev = crtc->dev;
  5831. struct drm_i915_private *dev_priv = dev->dev_private;
  5832. struct intel_encoder *intel_encoder;
  5833. uint32_t dpll;
  5834. int factor, num_connectors = 0;
  5835. bool is_lvds = false, is_sdvo = false;
  5836. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  5837. switch (intel_encoder->type) {
  5838. case INTEL_OUTPUT_LVDS:
  5839. is_lvds = true;
  5840. break;
  5841. case INTEL_OUTPUT_SDVO:
  5842. case INTEL_OUTPUT_HDMI:
  5843. is_sdvo = true;
  5844. break;
  5845. }
  5846. num_connectors++;
  5847. }
  5848. /* Enable autotuning of the PLL clock (if permissible) */
  5849. factor = 21;
  5850. if (is_lvds) {
  5851. if ((intel_panel_use_ssc(dev_priv) &&
  5852. dev_priv->vbt.lvds_ssc_freq == 100000) ||
  5853. (HAS_PCH_IBX(dev) && intel_is_dual_link_lvds(dev)))
  5854. factor = 25;
  5855. } else if (intel_crtc->config.sdvo_tv_clock)
  5856. factor = 20;
  5857. if (ironlake_needs_fb_cb_tune(&intel_crtc->config.dpll, factor))
  5858. *fp |= FP_CB_TUNE;
  5859. if (fp2 && (reduced_clock->m < factor * reduced_clock->n))
  5860. *fp2 |= FP_CB_TUNE;
  5861. dpll = 0;
  5862. if (is_lvds)
  5863. dpll |= DPLLB_MODE_LVDS;
  5864. else
  5865. dpll |= DPLLB_MODE_DAC_SERIAL;
  5866. dpll |= (intel_crtc->config.pixel_multiplier - 1)
  5867. << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
  5868. if (is_sdvo)
  5869. dpll |= DPLL_SDVO_HIGH_SPEED;
  5870. if (intel_crtc->config.has_dp_encoder)
  5871. dpll |= DPLL_SDVO_HIGH_SPEED;
  5872. /* compute bitmask from p1 value */
  5873. dpll |= (1 << (intel_crtc->config.dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  5874. /* also FPA1 */
  5875. dpll |= (1 << (intel_crtc->config.dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  5876. switch (intel_crtc->config.dpll.p2) {
  5877. case 5:
  5878. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  5879. break;
  5880. case 7:
  5881. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  5882. break;
  5883. case 10:
  5884. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  5885. break;
  5886. case 14:
  5887. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  5888. break;
  5889. }
  5890. if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  5891. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  5892. else
  5893. dpll |= PLL_REF_INPUT_DREFCLK;
  5894. return dpll | DPLL_VCO_ENABLE;
  5895. }
  5896. static int ironlake_crtc_mode_set(struct drm_crtc *crtc,
  5897. int x, int y,
  5898. struct drm_framebuffer *fb)
  5899. {
  5900. struct drm_device *dev = crtc->dev;
  5901. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5902. int num_connectors = 0;
  5903. intel_clock_t clock, reduced_clock;
  5904. u32 dpll = 0, fp = 0, fp2 = 0;
  5905. bool ok, has_reduced_clock = false;
  5906. bool is_lvds = false;
  5907. struct intel_encoder *encoder;
  5908. struct intel_shared_dpll *pll;
  5909. for_each_encoder_on_crtc(dev, crtc, encoder) {
  5910. switch (encoder->type) {
  5911. case INTEL_OUTPUT_LVDS:
  5912. is_lvds = true;
  5913. break;
  5914. }
  5915. num_connectors++;
  5916. }
  5917. WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)),
  5918. "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev));
  5919. ok = ironlake_compute_clocks(crtc, &clock,
  5920. &has_reduced_clock, &reduced_clock);
  5921. if (!ok && !intel_crtc->config.clock_set) {
  5922. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  5923. return -EINVAL;
  5924. }
  5925. /* Compat-code for transition, will disappear. */
  5926. if (!intel_crtc->config.clock_set) {
  5927. intel_crtc->config.dpll.n = clock.n;
  5928. intel_crtc->config.dpll.m1 = clock.m1;
  5929. intel_crtc->config.dpll.m2 = clock.m2;
  5930. intel_crtc->config.dpll.p1 = clock.p1;
  5931. intel_crtc->config.dpll.p2 = clock.p2;
  5932. }
  5933. /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
  5934. if (intel_crtc->config.has_pch_encoder) {
  5935. fp = i9xx_dpll_compute_fp(&intel_crtc->config.dpll);
  5936. if (has_reduced_clock)
  5937. fp2 = i9xx_dpll_compute_fp(&reduced_clock);
  5938. dpll = ironlake_compute_dpll(intel_crtc,
  5939. &fp, &reduced_clock,
  5940. has_reduced_clock ? &fp2 : NULL);
  5941. intel_crtc->config.dpll_hw_state.dpll = dpll;
  5942. intel_crtc->config.dpll_hw_state.fp0 = fp;
  5943. if (has_reduced_clock)
  5944. intel_crtc->config.dpll_hw_state.fp1 = fp2;
  5945. else
  5946. intel_crtc->config.dpll_hw_state.fp1 = fp;
  5947. pll = intel_get_shared_dpll(intel_crtc);
  5948. if (pll == NULL) {
  5949. DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
  5950. pipe_name(intel_crtc->pipe));
  5951. return -EINVAL;
  5952. }
  5953. } else
  5954. intel_put_shared_dpll(intel_crtc);
  5955. if (is_lvds && has_reduced_clock && i915.powersave)
  5956. intel_crtc->lowfreq_avail = true;
  5957. else
  5958. intel_crtc->lowfreq_avail = false;
  5959. return 0;
  5960. }
  5961. static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc,
  5962. struct intel_link_m_n *m_n)
  5963. {
  5964. struct drm_device *dev = crtc->base.dev;
  5965. struct drm_i915_private *dev_priv = dev->dev_private;
  5966. enum pipe pipe = crtc->pipe;
  5967. m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe));
  5968. m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe));
  5969. m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe))
  5970. & ~TU_SIZE_MASK;
  5971. m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe));
  5972. m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe))
  5973. & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
  5974. }
  5975. static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc,
  5976. enum transcoder transcoder,
  5977. struct intel_link_m_n *m_n)
  5978. {
  5979. struct drm_device *dev = crtc->base.dev;
  5980. struct drm_i915_private *dev_priv = dev->dev_private;
  5981. enum pipe pipe = crtc->pipe;
  5982. if (INTEL_INFO(dev)->gen >= 5) {
  5983. m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder));
  5984. m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder));
  5985. m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder))
  5986. & ~TU_SIZE_MASK;
  5987. m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder));
  5988. m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder))
  5989. & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
  5990. } else {
  5991. m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe));
  5992. m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe));
  5993. m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe))
  5994. & ~TU_SIZE_MASK;
  5995. m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe));
  5996. m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe))
  5997. & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
  5998. }
  5999. }
  6000. void intel_dp_get_m_n(struct intel_crtc *crtc,
  6001. struct intel_crtc_config *pipe_config)
  6002. {
  6003. if (crtc->config.has_pch_encoder)
  6004. intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n);
  6005. else
  6006. intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
  6007. &pipe_config->dp_m_n);
  6008. }
  6009. static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc,
  6010. struct intel_crtc_config *pipe_config)
  6011. {
  6012. intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
  6013. &pipe_config->fdi_m_n);
  6014. }
  6015. static void ironlake_get_pfit_config(struct intel_crtc *crtc,
  6016. struct intel_crtc_config *pipe_config)
  6017. {
  6018. struct drm_device *dev = crtc->base.dev;
  6019. struct drm_i915_private *dev_priv = dev->dev_private;
  6020. uint32_t tmp;
  6021. tmp = I915_READ(PF_CTL(crtc->pipe));
  6022. if (tmp & PF_ENABLE) {
  6023. pipe_config->pch_pfit.enabled = true;
  6024. pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe));
  6025. pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe));
  6026. /* We currently do not free assignements of panel fitters on
  6027. * ivb/hsw (since we don't use the higher upscaling modes which
  6028. * differentiates them) so just WARN about this case for now. */
  6029. if (IS_GEN7(dev)) {
  6030. WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) !=
  6031. PF_PIPE_SEL_IVB(crtc->pipe));
  6032. }
  6033. }
  6034. }
  6035. static void ironlake_get_plane_config(struct intel_crtc *crtc,
  6036. struct intel_plane_config *plane_config)
  6037. {
  6038. struct drm_device *dev = crtc->base.dev;
  6039. struct drm_i915_private *dev_priv = dev->dev_private;
  6040. u32 val, base, offset;
  6041. int pipe = crtc->pipe, plane = crtc->plane;
  6042. int fourcc, pixel_format;
  6043. int aligned_height;
  6044. crtc->base.primary->fb = kzalloc(sizeof(struct intel_framebuffer), GFP_KERNEL);
  6045. if (!crtc->base.primary->fb) {
  6046. DRM_DEBUG_KMS("failed to alloc fb\n");
  6047. return;
  6048. }
  6049. val = I915_READ(DSPCNTR(plane));
  6050. if (INTEL_INFO(dev)->gen >= 4)
  6051. if (val & DISPPLANE_TILED)
  6052. plane_config->tiled = true;
  6053. pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
  6054. fourcc = intel_format_to_fourcc(pixel_format);
  6055. crtc->base.primary->fb->pixel_format = fourcc;
  6056. crtc->base.primary->fb->bits_per_pixel =
  6057. drm_format_plane_cpp(fourcc, 0) * 8;
  6058. base = I915_READ(DSPSURF(plane)) & 0xfffff000;
  6059. if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  6060. offset = I915_READ(DSPOFFSET(plane));
  6061. } else {
  6062. if (plane_config->tiled)
  6063. offset = I915_READ(DSPTILEOFF(plane));
  6064. else
  6065. offset = I915_READ(DSPLINOFF(plane));
  6066. }
  6067. plane_config->base = base;
  6068. val = I915_READ(PIPESRC(pipe));
  6069. crtc->base.primary->fb->width = ((val >> 16) & 0xfff) + 1;
  6070. crtc->base.primary->fb->height = ((val >> 0) & 0xfff) + 1;
  6071. val = I915_READ(DSPSTRIDE(pipe));
  6072. crtc->base.primary->fb->pitches[0] = val & 0xffffff80;
  6073. aligned_height = intel_align_height(dev, crtc->base.primary->fb->height,
  6074. plane_config->tiled);
  6075. plane_config->size = PAGE_ALIGN(crtc->base.primary->fb->pitches[0] *
  6076. aligned_height);
  6077. DRM_DEBUG_KMS("pipe/plane %d/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
  6078. pipe, plane, crtc->base.primary->fb->width,
  6079. crtc->base.primary->fb->height,
  6080. crtc->base.primary->fb->bits_per_pixel, base,
  6081. crtc->base.primary->fb->pitches[0],
  6082. plane_config->size);
  6083. }
  6084. static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
  6085. struct intel_crtc_config *pipe_config)
  6086. {
  6087. struct drm_device *dev = crtc->base.dev;
  6088. struct drm_i915_private *dev_priv = dev->dev_private;
  6089. uint32_t tmp;
  6090. pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
  6091. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  6092. tmp = I915_READ(PIPECONF(crtc->pipe));
  6093. if (!(tmp & PIPECONF_ENABLE))
  6094. return false;
  6095. switch (tmp & PIPECONF_BPC_MASK) {
  6096. case PIPECONF_6BPC:
  6097. pipe_config->pipe_bpp = 18;
  6098. break;
  6099. case PIPECONF_8BPC:
  6100. pipe_config->pipe_bpp = 24;
  6101. break;
  6102. case PIPECONF_10BPC:
  6103. pipe_config->pipe_bpp = 30;
  6104. break;
  6105. case PIPECONF_12BPC:
  6106. pipe_config->pipe_bpp = 36;
  6107. break;
  6108. default:
  6109. break;
  6110. }
  6111. if (tmp & PIPECONF_COLOR_RANGE_SELECT)
  6112. pipe_config->limited_color_range = true;
  6113. if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) {
  6114. struct intel_shared_dpll *pll;
  6115. pipe_config->has_pch_encoder = true;
  6116. tmp = I915_READ(FDI_RX_CTL(crtc->pipe));
  6117. pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
  6118. FDI_DP_PORT_WIDTH_SHIFT) + 1;
  6119. ironlake_get_fdi_m_n_config(crtc, pipe_config);
  6120. if (HAS_PCH_IBX(dev_priv->dev)) {
  6121. pipe_config->shared_dpll =
  6122. (enum intel_dpll_id) crtc->pipe;
  6123. } else {
  6124. tmp = I915_READ(PCH_DPLL_SEL);
  6125. if (tmp & TRANS_DPLLB_SEL(crtc->pipe))
  6126. pipe_config->shared_dpll = DPLL_ID_PCH_PLL_B;
  6127. else
  6128. pipe_config->shared_dpll = DPLL_ID_PCH_PLL_A;
  6129. }
  6130. pll = &dev_priv->shared_dplls[pipe_config->shared_dpll];
  6131. WARN_ON(!pll->get_hw_state(dev_priv, pll,
  6132. &pipe_config->dpll_hw_state));
  6133. tmp = pipe_config->dpll_hw_state.dpll;
  6134. pipe_config->pixel_multiplier =
  6135. ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK)
  6136. >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1;
  6137. ironlake_pch_clock_get(crtc, pipe_config);
  6138. } else {
  6139. pipe_config->pixel_multiplier = 1;
  6140. }
  6141. intel_get_pipe_timings(crtc, pipe_config);
  6142. ironlake_get_pfit_config(crtc, pipe_config);
  6143. return true;
  6144. }
  6145. static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv)
  6146. {
  6147. struct drm_device *dev = dev_priv->dev;
  6148. struct intel_ddi_plls *plls = &dev_priv->ddi_plls;
  6149. struct intel_crtc *crtc;
  6150. for_each_intel_crtc(dev, crtc)
  6151. WARN(crtc->active, "CRTC for pipe %c enabled\n",
  6152. pipe_name(crtc->pipe));
  6153. WARN(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on\n");
  6154. WARN(plls->spll_refcount, "SPLL enabled\n");
  6155. WARN(plls->wrpll1_refcount, "WRPLL1 enabled\n");
  6156. WARN(plls->wrpll2_refcount, "WRPLL2 enabled\n");
  6157. WARN(I915_READ(PCH_PP_STATUS) & PP_ON, "Panel power on\n");
  6158. WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE,
  6159. "CPU PWM1 enabled\n");
  6160. WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE,
  6161. "CPU PWM2 enabled\n");
  6162. WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE,
  6163. "PCH PWM1 enabled\n");
  6164. WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
  6165. "Utility pin enabled\n");
  6166. WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n");
  6167. /*
  6168. * In theory we can still leave IRQs enabled, as long as only the HPD
  6169. * interrupts remain enabled. We used to check for that, but since it's
  6170. * gen-specific and since we only disable LCPLL after we fully disable
  6171. * the interrupts, the check below should be enough.
  6172. */
  6173. WARN(!dev_priv->pm.irqs_disabled, "IRQs enabled\n");
  6174. }
  6175. static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val)
  6176. {
  6177. struct drm_device *dev = dev_priv->dev;
  6178. if (IS_HASWELL(dev)) {
  6179. mutex_lock(&dev_priv->rps.hw_lock);
  6180. if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP,
  6181. val))
  6182. DRM_ERROR("Failed to disable D_COMP\n");
  6183. mutex_unlock(&dev_priv->rps.hw_lock);
  6184. } else {
  6185. I915_WRITE(D_COMP, val);
  6186. }
  6187. POSTING_READ(D_COMP);
  6188. }
  6189. /*
  6190. * This function implements pieces of two sequences from BSpec:
  6191. * - Sequence for display software to disable LCPLL
  6192. * - Sequence for display software to allow package C8+
  6193. * The steps implemented here are just the steps that actually touch the LCPLL
  6194. * register. Callers should take care of disabling all the display engine
  6195. * functions, doing the mode unset, fixing interrupts, etc.
  6196. */
  6197. static void hsw_disable_lcpll(struct drm_i915_private *dev_priv,
  6198. bool switch_to_fclk, bool allow_power_down)
  6199. {
  6200. uint32_t val;
  6201. assert_can_disable_lcpll(dev_priv);
  6202. val = I915_READ(LCPLL_CTL);
  6203. if (switch_to_fclk) {
  6204. val |= LCPLL_CD_SOURCE_FCLK;
  6205. I915_WRITE(LCPLL_CTL, val);
  6206. if (wait_for_atomic_us(I915_READ(LCPLL_CTL) &
  6207. LCPLL_CD_SOURCE_FCLK_DONE, 1))
  6208. DRM_ERROR("Switching to FCLK failed\n");
  6209. val = I915_READ(LCPLL_CTL);
  6210. }
  6211. val |= LCPLL_PLL_DISABLE;
  6212. I915_WRITE(LCPLL_CTL, val);
  6213. POSTING_READ(LCPLL_CTL);
  6214. if (wait_for((I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK) == 0, 1))
  6215. DRM_ERROR("LCPLL still locked\n");
  6216. val = I915_READ(D_COMP);
  6217. val |= D_COMP_COMP_DISABLE;
  6218. hsw_write_dcomp(dev_priv, val);
  6219. ndelay(100);
  6220. if (wait_for((I915_READ(D_COMP) & D_COMP_RCOMP_IN_PROGRESS) == 0, 1))
  6221. DRM_ERROR("D_COMP RCOMP still in progress\n");
  6222. if (allow_power_down) {
  6223. val = I915_READ(LCPLL_CTL);
  6224. val |= LCPLL_POWER_DOWN_ALLOW;
  6225. I915_WRITE(LCPLL_CTL, val);
  6226. POSTING_READ(LCPLL_CTL);
  6227. }
  6228. }
  6229. /*
  6230. * Fully restores LCPLL, disallowing power down and switching back to LCPLL
  6231. * source.
  6232. */
  6233. static void hsw_restore_lcpll(struct drm_i915_private *dev_priv)
  6234. {
  6235. uint32_t val;
  6236. unsigned long irqflags;
  6237. val = I915_READ(LCPLL_CTL);
  6238. if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK |
  6239. LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK)
  6240. return;
  6241. /*
  6242. * Make sure we're not on PC8 state before disabling PC8, otherwise
  6243. * we'll hang the machine. To prevent PC8 state, just enable force_wake.
  6244. *
  6245. * The other problem is that hsw_restore_lcpll() is called as part of
  6246. * the runtime PM resume sequence, so we can't just call
  6247. * gen6_gt_force_wake_get() because that function calls
  6248. * intel_runtime_pm_get(), and we can't change the runtime PM refcount
  6249. * while we are on the resume sequence. So to solve this problem we have
  6250. * to call special forcewake code that doesn't touch runtime PM and
  6251. * doesn't enable the forcewake delayed work.
  6252. */
  6253. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  6254. if (dev_priv->uncore.forcewake_count++ == 0)
  6255. dev_priv->uncore.funcs.force_wake_get(dev_priv, FORCEWAKE_ALL);
  6256. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  6257. if (val & LCPLL_POWER_DOWN_ALLOW) {
  6258. val &= ~LCPLL_POWER_DOWN_ALLOW;
  6259. I915_WRITE(LCPLL_CTL, val);
  6260. POSTING_READ(LCPLL_CTL);
  6261. }
  6262. val = I915_READ(D_COMP);
  6263. val |= D_COMP_COMP_FORCE;
  6264. val &= ~D_COMP_COMP_DISABLE;
  6265. hsw_write_dcomp(dev_priv, val);
  6266. val = I915_READ(LCPLL_CTL);
  6267. val &= ~LCPLL_PLL_DISABLE;
  6268. I915_WRITE(LCPLL_CTL, val);
  6269. if (wait_for(I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK, 5))
  6270. DRM_ERROR("LCPLL not locked yet\n");
  6271. if (val & LCPLL_CD_SOURCE_FCLK) {
  6272. val = I915_READ(LCPLL_CTL);
  6273. val &= ~LCPLL_CD_SOURCE_FCLK;
  6274. I915_WRITE(LCPLL_CTL, val);
  6275. if (wait_for_atomic_us((I915_READ(LCPLL_CTL) &
  6276. LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1))
  6277. DRM_ERROR("Switching back to LCPLL failed\n");
  6278. }
  6279. /* See the big comment above. */
  6280. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  6281. if (--dev_priv->uncore.forcewake_count == 0)
  6282. dev_priv->uncore.funcs.force_wake_put(dev_priv, FORCEWAKE_ALL);
  6283. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  6284. }
  6285. /*
  6286. * Package states C8 and deeper are really deep PC states that can only be
  6287. * reached when all the devices on the system allow it, so even if the graphics
  6288. * device allows PC8+, it doesn't mean the system will actually get to these
  6289. * states. Our driver only allows PC8+ when going into runtime PM.
  6290. *
  6291. * The requirements for PC8+ are that all the outputs are disabled, the power
  6292. * well is disabled and most interrupts are disabled, and these are also
  6293. * requirements for runtime PM. When these conditions are met, we manually do
  6294. * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
  6295. * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
  6296. * hang the machine.
  6297. *
  6298. * When we really reach PC8 or deeper states (not just when we allow it) we lose
  6299. * the state of some registers, so when we come back from PC8+ we need to
  6300. * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
  6301. * need to take care of the registers kept by RC6. Notice that this happens even
  6302. * if we don't put the device in PCI D3 state (which is what currently happens
  6303. * because of the runtime PM support).
  6304. *
  6305. * For more, read "Display Sequences for Package C8" on the hardware
  6306. * documentation.
  6307. */
  6308. void hsw_enable_pc8(struct drm_i915_private *dev_priv)
  6309. {
  6310. struct drm_device *dev = dev_priv->dev;
  6311. uint32_t val;
  6312. DRM_DEBUG_KMS("Enabling package C8+\n");
  6313. if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) {
  6314. val = I915_READ(SOUTH_DSPCLK_GATE_D);
  6315. val &= ~PCH_LP_PARTITION_LEVEL_DISABLE;
  6316. I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
  6317. }
  6318. lpt_disable_clkout_dp(dev);
  6319. hsw_disable_lcpll(dev_priv, true, true);
  6320. }
  6321. void hsw_disable_pc8(struct drm_i915_private *dev_priv)
  6322. {
  6323. struct drm_device *dev = dev_priv->dev;
  6324. uint32_t val;
  6325. DRM_DEBUG_KMS("Disabling package C8+\n");
  6326. hsw_restore_lcpll(dev_priv);
  6327. lpt_init_pch_refclk(dev);
  6328. if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) {
  6329. val = I915_READ(SOUTH_DSPCLK_GATE_D);
  6330. val |= PCH_LP_PARTITION_LEVEL_DISABLE;
  6331. I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
  6332. }
  6333. intel_prepare_ddi(dev);
  6334. }
  6335. static void snb_modeset_global_resources(struct drm_device *dev)
  6336. {
  6337. modeset_update_crtc_power_domains(dev);
  6338. }
  6339. static void haswell_modeset_global_resources(struct drm_device *dev)
  6340. {
  6341. modeset_update_crtc_power_domains(dev);
  6342. }
  6343. static int haswell_crtc_mode_set(struct drm_crtc *crtc,
  6344. int x, int y,
  6345. struct drm_framebuffer *fb)
  6346. {
  6347. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6348. if (!intel_ddi_pll_select(intel_crtc))
  6349. return -EINVAL;
  6350. intel_ddi_pll_enable(intel_crtc);
  6351. intel_crtc->lowfreq_avail = false;
  6352. return 0;
  6353. }
  6354. static bool haswell_get_pipe_config(struct intel_crtc *crtc,
  6355. struct intel_crtc_config *pipe_config)
  6356. {
  6357. struct drm_device *dev = crtc->base.dev;
  6358. struct drm_i915_private *dev_priv = dev->dev_private;
  6359. enum intel_display_power_domain pfit_domain;
  6360. uint32_t tmp;
  6361. if (!intel_display_power_enabled(dev_priv,
  6362. POWER_DOMAIN_PIPE(crtc->pipe)))
  6363. return false;
  6364. pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
  6365. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  6366. tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
  6367. if (tmp & TRANS_DDI_FUNC_ENABLE) {
  6368. enum pipe trans_edp_pipe;
  6369. switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
  6370. default:
  6371. WARN(1, "unknown pipe linked to edp transcoder\n");
  6372. case TRANS_DDI_EDP_INPUT_A_ONOFF:
  6373. case TRANS_DDI_EDP_INPUT_A_ON:
  6374. trans_edp_pipe = PIPE_A;
  6375. break;
  6376. case TRANS_DDI_EDP_INPUT_B_ONOFF:
  6377. trans_edp_pipe = PIPE_B;
  6378. break;
  6379. case TRANS_DDI_EDP_INPUT_C_ONOFF:
  6380. trans_edp_pipe = PIPE_C;
  6381. break;
  6382. }
  6383. if (trans_edp_pipe == crtc->pipe)
  6384. pipe_config->cpu_transcoder = TRANSCODER_EDP;
  6385. }
  6386. if (!intel_display_power_enabled(dev_priv,
  6387. POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder)))
  6388. return false;
  6389. tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder));
  6390. if (!(tmp & PIPECONF_ENABLE))
  6391. return false;
  6392. /*
  6393. * Haswell has only FDI/PCH transcoder A. It is which is connected to
  6394. * DDI E. So just check whether this pipe is wired to DDI E and whether
  6395. * the PCH transcoder is on.
  6396. */
  6397. tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder));
  6398. if ((tmp & TRANS_DDI_PORT_MASK) == TRANS_DDI_SELECT_PORT(PORT_E) &&
  6399. I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) {
  6400. pipe_config->has_pch_encoder = true;
  6401. tmp = I915_READ(FDI_RX_CTL(PIPE_A));
  6402. pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
  6403. FDI_DP_PORT_WIDTH_SHIFT) + 1;
  6404. ironlake_get_fdi_m_n_config(crtc, pipe_config);
  6405. }
  6406. intel_get_pipe_timings(crtc, pipe_config);
  6407. pfit_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe);
  6408. if (intel_display_power_enabled(dev_priv, pfit_domain))
  6409. ironlake_get_pfit_config(crtc, pipe_config);
  6410. if (IS_HASWELL(dev))
  6411. pipe_config->ips_enabled = hsw_crtc_supports_ips(crtc) &&
  6412. (I915_READ(IPS_CTL) & IPS_ENABLE);
  6413. pipe_config->pixel_multiplier = 1;
  6414. return true;
  6415. }
  6416. static struct {
  6417. int clock;
  6418. u32 config;
  6419. } hdmi_audio_clock[] = {
  6420. { DIV_ROUND_UP(25200 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_25175 },
  6421. { 25200, AUD_CONFIG_PIXEL_CLOCK_HDMI_25200 }, /* default per bspec */
  6422. { 27000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27000 },
  6423. { 27000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27027 },
  6424. { 54000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54000 },
  6425. { 54000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54054 },
  6426. { DIV_ROUND_UP(74250 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_74176 },
  6427. { 74250, AUD_CONFIG_PIXEL_CLOCK_HDMI_74250 },
  6428. { DIV_ROUND_UP(148500 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_148352 },
  6429. { 148500, AUD_CONFIG_PIXEL_CLOCK_HDMI_148500 },
  6430. };
  6431. /* get AUD_CONFIG_PIXEL_CLOCK_HDMI_* value for mode */
  6432. static u32 audio_config_hdmi_pixel_clock(struct drm_display_mode *mode)
  6433. {
  6434. int i;
  6435. for (i = 0; i < ARRAY_SIZE(hdmi_audio_clock); i++) {
  6436. if (mode->clock == hdmi_audio_clock[i].clock)
  6437. break;
  6438. }
  6439. if (i == ARRAY_SIZE(hdmi_audio_clock)) {
  6440. DRM_DEBUG_KMS("HDMI audio pixel clock setting for %d not found, falling back to defaults\n", mode->clock);
  6441. i = 1;
  6442. }
  6443. DRM_DEBUG_KMS("Configuring HDMI audio for pixel clock %d (0x%08x)\n",
  6444. hdmi_audio_clock[i].clock,
  6445. hdmi_audio_clock[i].config);
  6446. return hdmi_audio_clock[i].config;
  6447. }
  6448. static bool intel_eld_uptodate(struct drm_connector *connector,
  6449. int reg_eldv, uint32_t bits_eldv,
  6450. int reg_elda, uint32_t bits_elda,
  6451. int reg_edid)
  6452. {
  6453. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  6454. uint8_t *eld = connector->eld;
  6455. uint32_t i;
  6456. i = I915_READ(reg_eldv);
  6457. i &= bits_eldv;
  6458. if (!eld[0])
  6459. return !i;
  6460. if (!i)
  6461. return false;
  6462. i = I915_READ(reg_elda);
  6463. i &= ~bits_elda;
  6464. I915_WRITE(reg_elda, i);
  6465. for (i = 0; i < eld[2]; i++)
  6466. if (I915_READ(reg_edid) != *((uint32_t *)eld + i))
  6467. return false;
  6468. return true;
  6469. }
  6470. static void g4x_write_eld(struct drm_connector *connector,
  6471. struct drm_crtc *crtc,
  6472. struct drm_display_mode *mode)
  6473. {
  6474. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  6475. uint8_t *eld = connector->eld;
  6476. uint32_t eldv;
  6477. uint32_t len;
  6478. uint32_t i;
  6479. i = I915_READ(G4X_AUD_VID_DID);
  6480. if (i == INTEL_AUDIO_DEVBLC || i == INTEL_AUDIO_DEVCL)
  6481. eldv = G4X_ELDV_DEVCL_DEVBLC;
  6482. else
  6483. eldv = G4X_ELDV_DEVCTG;
  6484. if (intel_eld_uptodate(connector,
  6485. G4X_AUD_CNTL_ST, eldv,
  6486. G4X_AUD_CNTL_ST, G4X_ELD_ADDR,
  6487. G4X_HDMIW_HDMIEDID))
  6488. return;
  6489. i = I915_READ(G4X_AUD_CNTL_ST);
  6490. i &= ~(eldv | G4X_ELD_ADDR);
  6491. len = (i >> 9) & 0x1f; /* ELD buffer size */
  6492. I915_WRITE(G4X_AUD_CNTL_ST, i);
  6493. if (!eld[0])
  6494. return;
  6495. len = min_t(uint8_t, eld[2], len);
  6496. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  6497. for (i = 0; i < len; i++)
  6498. I915_WRITE(G4X_HDMIW_HDMIEDID, *((uint32_t *)eld + i));
  6499. i = I915_READ(G4X_AUD_CNTL_ST);
  6500. i |= eldv;
  6501. I915_WRITE(G4X_AUD_CNTL_ST, i);
  6502. }
  6503. static void haswell_write_eld(struct drm_connector *connector,
  6504. struct drm_crtc *crtc,
  6505. struct drm_display_mode *mode)
  6506. {
  6507. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  6508. uint8_t *eld = connector->eld;
  6509. uint32_t eldv;
  6510. uint32_t i;
  6511. int len;
  6512. int pipe = to_intel_crtc(crtc)->pipe;
  6513. int tmp;
  6514. int hdmiw_hdmiedid = HSW_AUD_EDID_DATA(pipe);
  6515. int aud_cntl_st = HSW_AUD_DIP_ELD_CTRL(pipe);
  6516. int aud_config = HSW_AUD_CFG(pipe);
  6517. int aud_cntrl_st2 = HSW_AUD_PIN_ELD_CP_VLD;
  6518. /* Audio output enable */
  6519. DRM_DEBUG_DRIVER("HDMI audio: enable codec\n");
  6520. tmp = I915_READ(aud_cntrl_st2);
  6521. tmp |= (AUDIO_OUTPUT_ENABLE_A << (pipe * 4));
  6522. I915_WRITE(aud_cntrl_st2, tmp);
  6523. POSTING_READ(aud_cntrl_st2);
  6524. assert_pipe_disabled(dev_priv, to_intel_crtc(crtc)->pipe);
  6525. /* Set ELD valid state */
  6526. tmp = I915_READ(aud_cntrl_st2);
  6527. DRM_DEBUG_DRIVER("HDMI audio: pin eld vld status=0x%08x\n", tmp);
  6528. tmp |= (AUDIO_ELD_VALID_A << (pipe * 4));
  6529. I915_WRITE(aud_cntrl_st2, tmp);
  6530. tmp = I915_READ(aud_cntrl_st2);
  6531. DRM_DEBUG_DRIVER("HDMI audio: eld vld status=0x%08x\n", tmp);
  6532. /* Enable HDMI mode */
  6533. tmp = I915_READ(aud_config);
  6534. DRM_DEBUG_DRIVER("HDMI audio: audio conf: 0x%08x\n", tmp);
  6535. /* clear N_programing_enable and N_value_index */
  6536. tmp &= ~(AUD_CONFIG_N_VALUE_INDEX | AUD_CONFIG_N_PROG_ENABLE);
  6537. I915_WRITE(aud_config, tmp);
  6538. DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe));
  6539. eldv = AUDIO_ELD_VALID_A << (pipe * 4);
  6540. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  6541. DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
  6542. eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
  6543. I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */
  6544. } else {
  6545. I915_WRITE(aud_config, audio_config_hdmi_pixel_clock(mode));
  6546. }
  6547. if (intel_eld_uptodate(connector,
  6548. aud_cntrl_st2, eldv,
  6549. aud_cntl_st, IBX_ELD_ADDRESS,
  6550. hdmiw_hdmiedid))
  6551. return;
  6552. i = I915_READ(aud_cntrl_st2);
  6553. i &= ~eldv;
  6554. I915_WRITE(aud_cntrl_st2, i);
  6555. if (!eld[0])
  6556. return;
  6557. i = I915_READ(aud_cntl_st);
  6558. i &= ~IBX_ELD_ADDRESS;
  6559. I915_WRITE(aud_cntl_st, i);
  6560. i = (i >> 29) & DIP_PORT_SEL_MASK; /* DIP_Port_Select, 0x1 = PortB */
  6561. DRM_DEBUG_DRIVER("port num:%d\n", i);
  6562. len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */
  6563. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  6564. for (i = 0; i < len; i++)
  6565. I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i));
  6566. i = I915_READ(aud_cntrl_st2);
  6567. i |= eldv;
  6568. I915_WRITE(aud_cntrl_st2, i);
  6569. }
  6570. static void ironlake_write_eld(struct drm_connector *connector,
  6571. struct drm_crtc *crtc,
  6572. struct drm_display_mode *mode)
  6573. {
  6574. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  6575. uint8_t *eld = connector->eld;
  6576. uint32_t eldv;
  6577. uint32_t i;
  6578. int len;
  6579. int hdmiw_hdmiedid;
  6580. int aud_config;
  6581. int aud_cntl_st;
  6582. int aud_cntrl_st2;
  6583. int pipe = to_intel_crtc(crtc)->pipe;
  6584. if (HAS_PCH_IBX(connector->dev)) {
  6585. hdmiw_hdmiedid = IBX_HDMIW_HDMIEDID(pipe);
  6586. aud_config = IBX_AUD_CFG(pipe);
  6587. aud_cntl_st = IBX_AUD_CNTL_ST(pipe);
  6588. aud_cntrl_st2 = IBX_AUD_CNTL_ST2;
  6589. } else if (IS_VALLEYVIEW(connector->dev)) {
  6590. hdmiw_hdmiedid = VLV_HDMIW_HDMIEDID(pipe);
  6591. aud_config = VLV_AUD_CFG(pipe);
  6592. aud_cntl_st = VLV_AUD_CNTL_ST(pipe);
  6593. aud_cntrl_st2 = VLV_AUD_CNTL_ST2;
  6594. } else {
  6595. hdmiw_hdmiedid = CPT_HDMIW_HDMIEDID(pipe);
  6596. aud_config = CPT_AUD_CFG(pipe);
  6597. aud_cntl_st = CPT_AUD_CNTL_ST(pipe);
  6598. aud_cntrl_st2 = CPT_AUD_CNTRL_ST2;
  6599. }
  6600. DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe));
  6601. if (IS_VALLEYVIEW(connector->dev)) {
  6602. struct intel_encoder *intel_encoder;
  6603. struct intel_digital_port *intel_dig_port;
  6604. intel_encoder = intel_attached_encoder(connector);
  6605. intel_dig_port = enc_to_dig_port(&intel_encoder->base);
  6606. i = intel_dig_port->port;
  6607. } else {
  6608. i = I915_READ(aud_cntl_st);
  6609. i = (i >> 29) & DIP_PORT_SEL_MASK;
  6610. /* DIP_Port_Select, 0x1 = PortB */
  6611. }
  6612. if (!i) {
  6613. DRM_DEBUG_DRIVER("Audio directed to unknown port\n");
  6614. /* operate blindly on all ports */
  6615. eldv = IBX_ELD_VALIDB;
  6616. eldv |= IBX_ELD_VALIDB << 4;
  6617. eldv |= IBX_ELD_VALIDB << 8;
  6618. } else {
  6619. DRM_DEBUG_DRIVER("ELD on port %c\n", port_name(i));
  6620. eldv = IBX_ELD_VALIDB << ((i - 1) * 4);
  6621. }
  6622. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  6623. DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
  6624. eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
  6625. I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */
  6626. } else {
  6627. I915_WRITE(aud_config, audio_config_hdmi_pixel_clock(mode));
  6628. }
  6629. if (intel_eld_uptodate(connector,
  6630. aud_cntrl_st2, eldv,
  6631. aud_cntl_st, IBX_ELD_ADDRESS,
  6632. hdmiw_hdmiedid))
  6633. return;
  6634. i = I915_READ(aud_cntrl_st2);
  6635. i &= ~eldv;
  6636. I915_WRITE(aud_cntrl_st2, i);
  6637. if (!eld[0])
  6638. return;
  6639. i = I915_READ(aud_cntl_st);
  6640. i &= ~IBX_ELD_ADDRESS;
  6641. I915_WRITE(aud_cntl_st, i);
  6642. len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */
  6643. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  6644. for (i = 0; i < len; i++)
  6645. I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i));
  6646. i = I915_READ(aud_cntrl_st2);
  6647. i |= eldv;
  6648. I915_WRITE(aud_cntrl_st2, i);
  6649. }
  6650. void intel_write_eld(struct drm_encoder *encoder,
  6651. struct drm_display_mode *mode)
  6652. {
  6653. struct drm_crtc *crtc = encoder->crtc;
  6654. struct drm_connector *connector;
  6655. struct drm_device *dev = encoder->dev;
  6656. struct drm_i915_private *dev_priv = dev->dev_private;
  6657. connector = drm_select_eld(encoder, mode);
  6658. if (!connector)
  6659. return;
  6660. DRM_DEBUG_DRIVER("ELD on [CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  6661. connector->base.id,
  6662. connector->name,
  6663. connector->encoder->base.id,
  6664. connector->encoder->name);
  6665. connector->eld[6] = drm_av_sync_delay(connector, mode) / 2;
  6666. if (dev_priv->display.write_eld)
  6667. dev_priv->display.write_eld(connector, crtc, mode);
  6668. }
  6669. static void i845_update_cursor(struct drm_crtc *crtc, u32 base)
  6670. {
  6671. struct drm_device *dev = crtc->dev;
  6672. struct drm_i915_private *dev_priv = dev->dev_private;
  6673. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6674. uint32_t cntl;
  6675. if (base != intel_crtc->cursor_base) {
  6676. /* On these chipsets we can only modify the base whilst
  6677. * the cursor is disabled.
  6678. */
  6679. if (intel_crtc->cursor_cntl) {
  6680. I915_WRITE(_CURACNTR, 0);
  6681. POSTING_READ(_CURACNTR);
  6682. intel_crtc->cursor_cntl = 0;
  6683. }
  6684. I915_WRITE(_CURABASE, base);
  6685. POSTING_READ(_CURABASE);
  6686. }
  6687. /* XXX width must be 64, stride 256 => 0x00 << 28 */
  6688. cntl = 0;
  6689. if (base)
  6690. cntl = (CURSOR_ENABLE |
  6691. CURSOR_GAMMA_ENABLE |
  6692. CURSOR_FORMAT_ARGB);
  6693. if (intel_crtc->cursor_cntl != cntl) {
  6694. I915_WRITE(_CURACNTR, cntl);
  6695. POSTING_READ(_CURACNTR);
  6696. intel_crtc->cursor_cntl = cntl;
  6697. }
  6698. }
  6699. static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base)
  6700. {
  6701. struct drm_device *dev = crtc->dev;
  6702. struct drm_i915_private *dev_priv = dev->dev_private;
  6703. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6704. int pipe = intel_crtc->pipe;
  6705. uint32_t cntl;
  6706. cntl = 0;
  6707. if (base) {
  6708. cntl = MCURSOR_GAMMA_ENABLE;
  6709. switch (intel_crtc->cursor_width) {
  6710. case 64:
  6711. cntl |= CURSOR_MODE_64_ARGB_AX;
  6712. break;
  6713. case 128:
  6714. cntl |= CURSOR_MODE_128_ARGB_AX;
  6715. break;
  6716. case 256:
  6717. cntl |= CURSOR_MODE_256_ARGB_AX;
  6718. break;
  6719. default:
  6720. WARN_ON(1);
  6721. return;
  6722. }
  6723. cntl |= pipe << 28; /* Connect to correct pipe */
  6724. }
  6725. if (intel_crtc->cursor_cntl != cntl) {
  6726. I915_WRITE(CURCNTR(pipe), cntl);
  6727. POSTING_READ(CURCNTR(pipe));
  6728. intel_crtc->cursor_cntl = cntl;
  6729. }
  6730. /* and commit changes on next vblank */
  6731. I915_WRITE(CURBASE(pipe), base);
  6732. POSTING_READ(CURBASE(pipe));
  6733. }
  6734. static void ivb_update_cursor(struct drm_crtc *crtc, u32 base)
  6735. {
  6736. struct drm_device *dev = crtc->dev;
  6737. struct drm_i915_private *dev_priv = dev->dev_private;
  6738. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6739. int pipe = intel_crtc->pipe;
  6740. uint32_t cntl;
  6741. cntl = 0;
  6742. if (base) {
  6743. cntl = MCURSOR_GAMMA_ENABLE;
  6744. switch (intel_crtc->cursor_width) {
  6745. case 64:
  6746. cntl |= CURSOR_MODE_64_ARGB_AX;
  6747. break;
  6748. case 128:
  6749. cntl |= CURSOR_MODE_128_ARGB_AX;
  6750. break;
  6751. case 256:
  6752. cntl |= CURSOR_MODE_256_ARGB_AX;
  6753. break;
  6754. default:
  6755. WARN_ON(1);
  6756. return;
  6757. }
  6758. }
  6759. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  6760. cntl |= CURSOR_PIPE_CSC_ENABLE;
  6761. if (intel_crtc->cursor_cntl != cntl) {
  6762. I915_WRITE(CURCNTR(pipe), cntl);
  6763. POSTING_READ(CURCNTR(pipe));
  6764. intel_crtc->cursor_cntl = cntl;
  6765. }
  6766. /* and commit changes on next vblank */
  6767. I915_WRITE(CURBASE(pipe), base);
  6768. POSTING_READ(CURBASE(pipe));
  6769. }
  6770. /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
  6771. static void intel_crtc_update_cursor(struct drm_crtc *crtc,
  6772. bool on)
  6773. {
  6774. struct drm_device *dev = crtc->dev;
  6775. struct drm_i915_private *dev_priv = dev->dev_private;
  6776. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6777. int pipe = intel_crtc->pipe;
  6778. int x = crtc->cursor_x;
  6779. int y = crtc->cursor_y;
  6780. u32 base = 0, pos = 0;
  6781. if (on)
  6782. base = intel_crtc->cursor_addr;
  6783. if (x >= intel_crtc->config.pipe_src_w)
  6784. base = 0;
  6785. if (y >= intel_crtc->config.pipe_src_h)
  6786. base = 0;
  6787. if (x < 0) {
  6788. if (x + intel_crtc->cursor_width <= 0)
  6789. base = 0;
  6790. pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
  6791. x = -x;
  6792. }
  6793. pos |= x << CURSOR_X_SHIFT;
  6794. if (y < 0) {
  6795. if (y + intel_crtc->cursor_height <= 0)
  6796. base = 0;
  6797. pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
  6798. y = -y;
  6799. }
  6800. pos |= y << CURSOR_Y_SHIFT;
  6801. if (base == 0 && intel_crtc->cursor_base == 0)
  6802. return;
  6803. I915_WRITE(CURPOS(pipe), pos);
  6804. if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev) || IS_BROADWELL(dev))
  6805. ivb_update_cursor(crtc, base);
  6806. else if (IS_845G(dev) || IS_I865G(dev))
  6807. i845_update_cursor(crtc, base);
  6808. else
  6809. i9xx_update_cursor(crtc, base);
  6810. intel_crtc->cursor_base = base;
  6811. }
  6812. /*
  6813. * intel_crtc_cursor_set_obj - Set cursor to specified GEM object
  6814. *
  6815. * Note that the object's reference will be consumed if the update fails. If
  6816. * the update succeeds, the reference of the old object (if any) will be
  6817. * consumed.
  6818. */
  6819. static int intel_crtc_cursor_set_obj(struct drm_crtc *crtc,
  6820. struct drm_i915_gem_object *obj,
  6821. uint32_t width, uint32_t height)
  6822. {
  6823. struct drm_device *dev = crtc->dev;
  6824. struct drm_i915_private *dev_priv = dev->dev_private;
  6825. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6826. enum pipe pipe = intel_crtc->pipe;
  6827. unsigned old_width;
  6828. uint32_t addr;
  6829. int ret;
  6830. /* if we want to turn off the cursor ignore width and height */
  6831. if (!obj) {
  6832. DRM_DEBUG_KMS("cursor off\n");
  6833. addr = 0;
  6834. obj = NULL;
  6835. mutex_lock(&dev->struct_mutex);
  6836. goto finish;
  6837. }
  6838. /* Check for which cursor types we support */
  6839. if (!((width == 64 && height == 64) ||
  6840. (width == 128 && height == 128 && !IS_GEN2(dev)) ||
  6841. (width == 256 && height == 256 && !IS_GEN2(dev)))) {
  6842. DRM_DEBUG("Cursor dimension not supported\n");
  6843. return -EINVAL;
  6844. }
  6845. if (obj->base.size < width * height * 4) {
  6846. DRM_DEBUG_KMS("buffer is too small\n");
  6847. ret = -ENOMEM;
  6848. goto fail;
  6849. }
  6850. /* we only need to pin inside GTT if cursor is non-phy */
  6851. mutex_lock(&dev->struct_mutex);
  6852. if (!INTEL_INFO(dev)->cursor_needs_physical) {
  6853. unsigned alignment;
  6854. if (obj->tiling_mode) {
  6855. DRM_DEBUG_KMS("cursor cannot be tiled\n");
  6856. ret = -EINVAL;
  6857. goto fail_locked;
  6858. }
  6859. /* Note that the w/a also requires 2 PTE of padding following
  6860. * the bo. We currently fill all unused PTE with the shadow
  6861. * page and so we should always have valid PTE following the
  6862. * cursor preventing the VT-d warning.
  6863. */
  6864. alignment = 0;
  6865. if (need_vtd_wa(dev))
  6866. alignment = 64*1024;
  6867. ret = i915_gem_object_pin_to_display_plane(obj, alignment, NULL);
  6868. if (ret) {
  6869. DRM_DEBUG_KMS("failed to move cursor bo into the GTT\n");
  6870. goto fail_locked;
  6871. }
  6872. ret = i915_gem_object_put_fence(obj);
  6873. if (ret) {
  6874. DRM_DEBUG_KMS("failed to release fence for cursor");
  6875. goto fail_unpin;
  6876. }
  6877. addr = i915_gem_obj_ggtt_offset(obj);
  6878. } else {
  6879. int align = IS_I830(dev) ? 16 * 1024 : 256;
  6880. ret = i915_gem_object_attach_phys(obj, align);
  6881. if (ret) {
  6882. DRM_DEBUG_KMS("failed to attach phys object\n");
  6883. goto fail_locked;
  6884. }
  6885. addr = obj->phys_handle->busaddr;
  6886. }
  6887. if (IS_GEN2(dev))
  6888. I915_WRITE(CURSIZE, (height << 12) | width);
  6889. finish:
  6890. if (intel_crtc->cursor_bo) {
  6891. if (!INTEL_INFO(dev)->cursor_needs_physical)
  6892. i915_gem_object_unpin_from_display_plane(intel_crtc->cursor_bo);
  6893. }
  6894. i915_gem_track_fb(intel_crtc->cursor_bo, obj,
  6895. INTEL_FRONTBUFFER_CURSOR(pipe));
  6896. mutex_unlock(&dev->struct_mutex);
  6897. old_width = intel_crtc->cursor_width;
  6898. intel_crtc->cursor_addr = addr;
  6899. intel_crtc->cursor_bo = obj;
  6900. intel_crtc->cursor_width = width;
  6901. intel_crtc->cursor_height = height;
  6902. if (intel_crtc->active) {
  6903. if (old_width != width)
  6904. intel_update_watermarks(crtc);
  6905. intel_crtc_update_cursor(crtc, intel_crtc->cursor_bo != NULL);
  6906. }
  6907. intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_CURSOR(pipe));
  6908. return 0;
  6909. fail_unpin:
  6910. i915_gem_object_unpin_from_display_plane(obj);
  6911. fail_locked:
  6912. mutex_unlock(&dev->struct_mutex);
  6913. fail:
  6914. drm_gem_object_unreference_unlocked(&obj->base);
  6915. return ret;
  6916. }
  6917. static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
  6918. u16 *blue, uint32_t start, uint32_t size)
  6919. {
  6920. int end = (start + size > 256) ? 256 : start + size, i;
  6921. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6922. for (i = start; i < end; i++) {
  6923. intel_crtc->lut_r[i] = red[i] >> 8;
  6924. intel_crtc->lut_g[i] = green[i] >> 8;
  6925. intel_crtc->lut_b[i] = blue[i] >> 8;
  6926. }
  6927. intel_crtc_load_lut(crtc);
  6928. }
  6929. /* VESA 640x480x72Hz mode to set on the pipe */
  6930. static struct drm_display_mode load_detect_mode = {
  6931. DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
  6932. 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  6933. };
  6934. struct drm_framebuffer *
  6935. __intel_framebuffer_create(struct drm_device *dev,
  6936. struct drm_mode_fb_cmd2 *mode_cmd,
  6937. struct drm_i915_gem_object *obj)
  6938. {
  6939. struct intel_framebuffer *intel_fb;
  6940. int ret;
  6941. intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
  6942. if (!intel_fb) {
  6943. drm_gem_object_unreference_unlocked(&obj->base);
  6944. return ERR_PTR(-ENOMEM);
  6945. }
  6946. ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj);
  6947. if (ret)
  6948. goto err;
  6949. return &intel_fb->base;
  6950. err:
  6951. drm_gem_object_unreference_unlocked(&obj->base);
  6952. kfree(intel_fb);
  6953. return ERR_PTR(ret);
  6954. }
  6955. static struct drm_framebuffer *
  6956. intel_framebuffer_create(struct drm_device *dev,
  6957. struct drm_mode_fb_cmd2 *mode_cmd,
  6958. struct drm_i915_gem_object *obj)
  6959. {
  6960. struct drm_framebuffer *fb;
  6961. int ret;
  6962. ret = i915_mutex_lock_interruptible(dev);
  6963. if (ret)
  6964. return ERR_PTR(ret);
  6965. fb = __intel_framebuffer_create(dev, mode_cmd, obj);
  6966. mutex_unlock(&dev->struct_mutex);
  6967. return fb;
  6968. }
  6969. static u32
  6970. intel_framebuffer_pitch_for_width(int width, int bpp)
  6971. {
  6972. u32 pitch = DIV_ROUND_UP(width * bpp, 8);
  6973. return ALIGN(pitch, 64);
  6974. }
  6975. static u32
  6976. intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp)
  6977. {
  6978. u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp);
  6979. return PAGE_ALIGN(pitch * mode->vdisplay);
  6980. }
  6981. static struct drm_framebuffer *
  6982. intel_framebuffer_create_for_mode(struct drm_device *dev,
  6983. struct drm_display_mode *mode,
  6984. int depth, int bpp)
  6985. {
  6986. struct drm_i915_gem_object *obj;
  6987. struct drm_mode_fb_cmd2 mode_cmd = { 0 };
  6988. obj = i915_gem_alloc_object(dev,
  6989. intel_framebuffer_size_for_mode(mode, bpp));
  6990. if (obj == NULL)
  6991. return ERR_PTR(-ENOMEM);
  6992. mode_cmd.width = mode->hdisplay;
  6993. mode_cmd.height = mode->vdisplay;
  6994. mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width,
  6995. bpp);
  6996. mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth);
  6997. return intel_framebuffer_create(dev, &mode_cmd, obj);
  6998. }
  6999. static struct drm_framebuffer *
  7000. mode_fits_in_fbdev(struct drm_device *dev,
  7001. struct drm_display_mode *mode)
  7002. {
  7003. #ifdef CONFIG_DRM_I915_FBDEV
  7004. struct drm_i915_private *dev_priv = dev->dev_private;
  7005. struct drm_i915_gem_object *obj;
  7006. struct drm_framebuffer *fb;
  7007. if (!dev_priv->fbdev)
  7008. return NULL;
  7009. if (!dev_priv->fbdev->fb)
  7010. return NULL;
  7011. obj = dev_priv->fbdev->fb->obj;
  7012. BUG_ON(!obj);
  7013. fb = &dev_priv->fbdev->fb->base;
  7014. if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay,
  7015. fb->bits_per_pixel))
  7016. return NULL;
  7017. if (obj->base.size < mode->vdisplay * fb->pitches[0])
  7018. return NULL;
  7019. return fb;
  7020. #else
  7021. return NULL;
  7022. #endif
  7023. }
  7024. bool intel_get_load_detect_pipe(struct drm_connector *connector,
  7025. struct drm_display_mode *mode,
  7026. struct intel_load_detect_pipe *old,
  7027. struct drm_modeset_acquire_ctx *ctx)
  7028. {
  7029. struct intel_crtc *intel_crtc;
  7030. struct intel_encoder *intel_encoder =
  7031. intel_attached_encoder(connector);
  7032. struct drm_crtc *possible_crtc;
  7033. struct drm_encoder *encoder = &intel_encoder->base;
  7034. struct drm_crtc *crtc = NULL;
  7035. struct drm_device *dev = encoder->dev;
  7036. struct drm_framebuffer *fb;
  7037. struct drm_mode_config *config = &dev->mode_config;
  7038. int ret, i = -1;
  7039. DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  7040. connector->base.id, connector->name,
  7041. encoder->base.id, encoder->name);
  7042. drm_modeset_acquire_init(ctx, 0);
  7043. retry:
  7044. ret = drm_modeset_lock(&config->connection_mutex, ctx);
  7045. if (ret)
  7046. goto fail_unlock;
  7047. /*
  7048. * Algorithm gets a little messy:
  7049. *
  7050. * - if the connector already has an assigned crtc, use it (but make
  7051. * sure it's on first)
  7052. *
  7053. * - try to find the first unused crtc that can drive this connector,
  7054. * and use that if we find one
  7055. */
  7056. /* See if we already have a CRTC for this connector */
  7057. if (encoder->crtc) {
  7058. crtc = encoder->crtc;
  7059. ret = drm_modeset_lock(&crtc->mutex, ctx);
  7060. if (ret)
  7061. goto fail_unlock;
  7062. old->dpms_mode = connector->dpms;
  7063. old->load_detect_temp = false;
  7064. /* Make sure the crtc and connector are running */
  7065. if (connector->dpms != DRM_MODE_DPMS_ON)
  7066. connector->funcs->dpms(connector, DRM_MODE_DPMS_ON);
  7067. return true;
  7068. }
  7069. /* Find an unused one (if possible) */
  7070. for_each_crtc(dev, possible_crtc) {
  7071. i++;
  7072. if (!(encoder->possible_crtcs & (1 << i)))
  7073. continue;
  7074. if (!possible_crtc->enabled) {
  7075. crtc = possible_crtc;
  7076. break;
  7077. }
  7078. }
  7079. /*
  7080. * If we didn't find an unused CRTC, don't use any.
  7081. */
  7082. if (!crtc) {
  7083. DRM_DEBUG_KMS("no pipe available for load-detect\n");
  7084. goto fail_unlock;
  7085. }
  7086. ret = drm_modeset_lock(&crtc->mutex, ctx);
  7087. if (ret)
  7088. goto fail_unlock;
  7089. intel_encoder->new_crtc = to_intel_crtc(crtc);
  7090. to_intel_connector(connector)->new_encoder = intel_encoder;
  7091. intel_crtc = to_intel_crtc(crtc);
  7092. intel_crtc->new_enabled = true;
  7093. intel_crtc->new_config = &intel_crtc->config;
  7094. old->dpms_mode = connector->dpms;
  7095. old->load_detect_temp = true;
  7096. old->release_fb = NULL;
  7097. if (!mode)
  7098. mode = &load_detect_mode;
  7099. /* We need a framebuffer large enough to accommodate all accesses
  7100. * that the plane may generate whilst we perform load detection.
  7101. * We can not rely on the fbcon either being present (we get called
  7102. * during its initialisation to detect all boot displays, or it may
  7103. * not even exist) or that it is large enough to satisfy the
  7104. * requested mode.
  7105. */
  7106. fb = mode_fits_in_fbdev(dev, mode);
  7107. if (fb == NULL) {
  7108. DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
  7109. fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32);
  7110. old->release_fb = fb;
  7111. } else
  7112. DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
  7113. if (IS_ERR(fb)) {
  7114. DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
  7115. goto fail;
  7116. }
  7117. if (intel_set_mode(crtc, mode, 0, 0, fb)) {
  7118. DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
  7119. if (old->release_fb)
  7120. old->release_fb->funcs->destroy(old->release_fb);
  7121. goto fail;
  7122. }
  7123. /* let the connector get through one full cycle before testing */
  7124. intel_wait_for_vblank(dev, intel_crtc->pipe);
  7125. return true;
  7126. fail:
  7127. intel_crtc->new_enabled = crtc->enabled;
  7128. if (intel_crtc->new_enabled)
  7129. intel_crtc->new_config = &intel_crtc->config;
  7130. else
  7131. intel_crtc->new_config = NULL;
  7132. fail_unlock:
  7133. if (ret == -EDEADLK) {
  7134. drm_modeset_backoff(ctx);
  7135. goto retry;
  7136. }
  7137. drm_modeset_drop_locks(ctx);
  7138. drm_modeset_acquire_fini(ctx);
  7139. return false;
  7140. }
  7141. void intel_release_load_detect_pipe(struct drm_connector *connector,
  7142. struct intel_load_detect_pipe *old,
  7143. struct drm_modeset_acquire_ctx *ctx)
  7144. {
  7145. struct intel_encoder *intel_encoder =
  7146. intel_attached_encoder(connector);
  7147. struct drm_encoder *encoder = &intel_encoder->base;
  7148. struct drm_crtc *crtc = encoder->crtc;
  7149. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7150. DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  7151. connector->base.id, connector->name,
  7152. encoder->base.id, encoder->name);
  7153. if (old->load_detect_temp) {
  7154. to_intel_connector(connector)->new_encoder = NULL;
  7155. intel_encoder->new_crtc = NULL;
  7156. intel_crtc->new_enabled = false;
  7157. intel_crtc->new_config = NULL;
  7158. intel_set_mode(crtc, NULL, 0, 0, NULL);
  7159. if (old->release_fb) {
  7160. drm_framebuffer_unregister_private(old->release_fb);
  7161. drm_framebuffer_unreference(old->release_fb);
  7162. }
  7163. goto unlock;
  7164. return;
  7165. }
  7166. /* Switch crtc and encoder back off if necessary */
  7167. if (old->dpms_mode != DRM_MODE_DPMS_ON)
  7168. connector->funcs->dpms(connector, old->dpms_mode);
  7169. unlock:
  7170. drm_modeset_drop_locks(ctx);
  7171. drm_modeset_acquire_fini(ctx);
  7172. }
  7173. static int i9xx_pll_refclk(struct drm_device *dev,
  7174. const struct intel_crtc_config *pipe_config)
  7175. {
  7176. struct drm_i915_private *dev_priv = dev->dev_private;
  7177. u32 dpll = pipe_config->dpll_hw_state.dpll;
  7178. if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
  7179. return dev_priv->vbt.lvds_ssc_freq;
  7180. else if (HAS_PCH_SPLIT(dev))
  7181. return 120000;
  7182. else if (!IS_GEN2(dev))
  7183. return 96000;
  7184. else
  7185. return 48000;
  7186. }
  7187. /* Returns the clock of the currently programmed mode of the given pipe. */
  7188. static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
  7189. struct intel_crtc_config *pipe_config)
  7190. {
  7191. struct drm_device *dev = crtc->base.dev;
  7192. struct drm_i915_private *dev_priv = dev->dev_private;
  7193. int pipe = pipe_config->cpu_transcoder;
  7194. u32 dpll = pipe_config->dpll_hw_state.dpll;
  7195. u32 fp;
  7196. intel_clock_t clock;
  7197. int refclk = i9xx_pll_refclk(dev, pipe_config);
  7198. if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
  7199. fp = pipe_config->dpll_hw_state.fp0;
  7200. else
  7201. fp = pipe_config->dpll_hw_state.fp1;
  7202. clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
  7203. if (IS_PINEVIEW(dev)) {
  7204. clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
  7205. clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
  7206. } else {
  7207. clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
  7208. clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
  7209. }
  7210. if (!IS_GEN2(dev)) {
  7211. if (IS_PINEVIEW(dev))
  7212. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
  7213. DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
  7214. else
  7215. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
  7216. DPLL_FPA01_P1_POST_DIV_SHIFT);
  7217. switch (dpll & DPLL_MODE_MASK) {
  7218. case DPLLB_MODE_DAC_SERIAL:
  7219. clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
  7220. 5 : 10;
  7221. break;
  7222. case DPLLB_MODE_LVDS:
  7223. clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
  7224. 7 : 14;
  7225. break;
  7226. default:
  7227. DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
  7228. "mode\n", (int)(dpll & DPLL_MODE_MASK));
  7229. return;
  7230. }
  7231. if (IS_PINEVIEW(dev))
  7232. pineview_clock(refclk, &clock);
  7233. else
  7234. i9xx_clock(refclk, &clock);
  7235. } else {
  7236. u32 lvds = IS_I830(dev) ? 0 : I915_READ(LVDS);
  7237. bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN);
  7238. if (is_lvds) {
  7239. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
  7240. DPLL_FPA01_P1_POST_DIV_SHIFT);
  7241. if (lvds & LVDS_CLKB_POWER_UP)
  7242. clock.p2 = 7;
  7243. else
  7244. clock.p2 = 14;
  7245. } else {
  7246. if (dpll & PLL_P1_DIVIDE_BY_TWO)
  7247. clock.p1 = 2;
  7248. else {
  7249. clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
  7250. DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
  7251. }
  7252. if (dpll & PLL_P2_DIVIDE_BY_4)
  7253. clock.p2 = 4;
  7254. else
  7255. clock.p2 = 2;
  7256. }
  7257. i9xx_clock(refclk, &clock);
  7258. }
  7259. /*
  7260. * This value includes pixel_multiplier. We will use
  7261. * port_clock to compute adjusted_mode.crtc_clock in the
  7262. * encoder's get_config() function.
  7263. */
  7264. pipe_config->port_clock = clock.dot;
  7265. }
  7266. int intel_dotclock_calculate(int link_freq,
  7267. const struct intel_link_m_n *m_n)
  7268. {
  7269. /*
  7270. * The calculation for the data clock is:
  7271. * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
  7272. * But we want to avoid losing precison if possible, so:
  7273. * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
  7274. *
  7275. * and the link clock is simpler:
  7276. * link_clock = (m * link_clock) / n
  7277. */
  7278. if (!m_n->link_n)
  7279. return 0;
  7280. return div_u64((u64)m_n->link_m * link_freq, m_n->link_n);
  7281. }
  7282. static void ironlake_pch_clock_get(struct intel_crtc *crtc,
  7283. struct intel_crtc_config *pipe_config)
  7284. {
  7285. struct drm_device *dev = crtc->base.dev;
  7286. /* read out port_clock from the DPLL */
  7287. i9xx_crtc_clock_get(crtc, pipe_config);
  7288. /*
  7289. * This value does not include pixel_multiplier.
  7290. * We will check that port_clock and adjusted_mode.crtc_clock
  7291. * agree once we know their relationship in the encoder's
  7292. * get_config() function.
  7293. */
  7294. pipe_config->adjusted_mode.crtc_clock =
  7295. intel_dotclock_calculate(intel_fdi_link_freq(dev) * 10000,
  7296. &pipe_config->fdi_m_n);
  7297. }
  7298. /** Returns the currently programmed mode of the given pipe. */
  7299. struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
  7300. struct drm_crtc *crtc)
  7301. {
  7302. struct drm_i915_private *dev_priv = dev->dev_private;
  7303. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7304. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  7305. struct drm_display_mode *mode;
  7306. struct intel_crtc_config pipe_config;
  7307. int htot = I915_READ(HTOTAL(cpu_transcoder));
  7308. int hsync = I915_READ(HSYNC(cpu_transcoder));
  7309. int vtot = I915_READ(VTOTAL(cpu_transcoder));
  7310. int vsync = I915_READ(VSYNC(cpu_transcoder));
  7311. enum pipe pipe = intel_crtc->pipe;
  7312. mode = kzalloc(sizeof(*mode), GFP_KERNEL);
  7313. if (!mode)
  7314. return NULL;
  7315. /*
  7316. * Construct a pipe_config sufficient for getting the clock info
  7317. * back out of crtc_clock_get.
  7318. *
  7319. * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need
  7320. * to use a real value here instead.
  7321. */
  7322. pipe_config.cpu_transcoder = (enum transcoder) pipe;
  7323. pipe_config.pixel_multiplier = 1;
  7324. pipe_config.dpll_hw_state.dpll = I915_READ(DPLL(pipe));
  7325. pipe_config.dpll_hw_state.fp0 = I915_READ(FP0(pipe));
  7326. pipe_config.dpll_hw_state.fp1 = I915_READ(FP1(pipe));
  7327. i9xx_crtc_clock_get(intel_crtc, &pipe_config);
  7328. mode->clock = pipe_config.port_clock / pipe_config.pixel_multiplier;
  7329. mode->hdisplay = (htot & 0xffff) + 1;
  7330. mode->htotal = ((htot & 0xffff0000) >> 16) + 1;
  7331. mode->hsync_start = (hsync & 0xffff) + 1;
  7332. mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1;
  7333. mode->vdisplay = (vtot & 0xffff) + 1;
  7334. mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1;
  7335. mode->vsync_start = (vsync & 0xffff) + 1;
  7336. mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1;
  7337. drm_mode_set_name(mode);
  7338. return mode;
  7339. }
  7340. static void intel_increase_pllclock(struct drm_device *dev,
  7341. enum pipe pipe)
  7342. {
  7343. struct drm_i915_private *dev_priv = dev->dev_private;
  7344. int dpll_reg = DPLL(pipe);
  7345. int dpll;
  7346. if (HAS_PCH_SPLIT(dev))
  7347. return;
  7348. if (!dev_priv->lvds_downclock_avail)
  7349. return;
  7350. dpll = I915_READ(dpll_reg);
  7351. if (!HAS_PIPE_CXSR(dev) && (dpll & DISPLAY_RATE_SELECT_FPA1)) {
  7352. DRM_DEBUG_DRIVER("upclocking LVDS\n");
  7353. assert_panel_unlocked(dev_priv, pipe);
  7354. dpll &= ~DISPLAY_RATE_SELECT_FPA1;
  7355. I915_WRITE(dpll_reg, dpll);
  7356. intel_wait_for_vblank(dev, pipe);
  7357. dpll = I915_READ(dpll_reg);
  7358. if (dpll & DISPLAY_RATE_SELECT_FPA1)
  7359. DRM_DEBUG_DRIVER("failed to upclock LVDS!\n");
  7360. }
  7361. }
  7362. static void intel_decrease_pllclock(struct drm_crtc *crtc)
  7363. {
  7364. struct drm_device *dev = crtc->dev;
  7365. struct drm_i915_private *dev_priv = dev->dev_private;
  7366. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7367. if (HAS_PCH_SPLIT(dev))
  7368. return;
  7369. if (!dev_priv->lvds_downclock_avail)
  7370. return;
  7371. /*
  7372. * Since this is called by a timer, we should never get here in
  7373. * the manual case.
  7374. */
  7375. if (!HAS_PIPE_CXSR(dev) && intel_crtc->lowfreq_avail) {
  7376. int pipe = intel_crtc->pipe;
  7377. int dpll_reg = DPLL(pipe);
  7378. int dpll;
  7379. DRM_DEBUG_DRIVER("downclocking LVDS\n");
  7380. assert_panel_unlocked(dev_priv, pipe);
  7381. dpll = I915_READ(dpll_reg);
  7382. dpll |= DISPLAY_RATE_SELECT_FPA1;
  7383. I915_WRITE(dpll_reg, dpll);
  7384. intel_wait_for_vblank(dev, pipe);
  7385. dpll = I915_READ(dpll_reg);
  7386. if (!(dpll & DISPLAY_RATE_SELECT_FPA1))
  7387. DRM_DEBUG_DRIVER("failed to downclock LVDS!\n");
  7388. }
  7389. }
  7390. void intel_mark_busy(struct drm_device *dev)
  7391. {
  7392. struct drm_i915_private *dev_priv = dev->dev_private;
  7393. if (dev_priv->mm.busy)
  7394. return;
  7395. intel_runtime_pm_get(dev_priv);
  7396. i915_update_gfx_val(dev_priv);
  7397. dev_priv->mm.busy = true;
  7398. }
  7399. void intel_mark_idle(struct drm_device *dev)
  7400. {
  7401. struct drm_i915_private *dev_priv = dev->dev_private;
  7402. struct drm_crtc *crtc;
  7403. if (!dev_priv->mm.busy)
  7404. return;
  7405. dev_priv->mm.busy = false;
  7406. if (!i915.powersave)
  7407. goto out;
  7408. for_each_crtc(dev, crtc) {
  7409. if (!crtc->primary->fb)
  7410. continue;
  7411. intel_decrease_pllclock(crtc);
  7412. }
  7413. if (INTEL_INFO(dev)->gen >= 6)
  7414. gen6_rps_idle(dev->dev_private);
  7415. out:
  7416. intel_runtime_pm_put(dev_priv);
  7417. }
  7418. /**
  7419. * intel_mark_fb_busy - mark given planes as busy
  7420. * @dev: DRM device
  7421. * @frontbuffer_bits: bits for the affected planes
  7422. * @ring: optional ring for asynchronous commands
  7423. *
  7424. * This function gets called every time the screen contents change. It can be
  7425. * used to keep e.g. the update rate at the nominal refresh rate with DRRS.
  7426. */
  7427. static void intel_mark_fb_busy(struct drm_device *dev,
  7428. unsigned frontbuffer_bits,
  7429. struct intel_engine_cs *ring)
  7430. {
  7431. enum pipe pipe;
  7432. if (!i915.powersave)
  7433. return;
  7434. for_each_pipe(pipe) {
  7435. if (!(frontbuffer_bits & INTEL_FRONTBUFFER_ALL_MASK(pipe)))
  7436. continue;
  7437. intel_increase_pllclock(dev, pipe);
  7438. if (ring && intel_fbc_enabled(dev))
  7439. ring->fbc_dirty = true;
  7440. }
  7441. }
  7442. /**
  7443. * intel_fb_obj_invalidate - invalidate frontbuffer object
  7444. * @obj: GEM object to invalidate
  7445. * @ring: set for asynchronous rendering
  7446. *
  7447. * This function gets called every time rendering on the given object starts and
  7448. * frontbuffer caching (fbc, low refresh rate for DRRS, panel self refresh) must
  7449. * be invalidated. If @ring is non-NULL any subsequent invalidation will be delayed
  7450. * until the rendering completes or a flip on this frontbuffer plane is
  7451. * scheduled.
  7452. */
  7453. void intel_fb_obj_invalidate(struct drm_i915_gem_object *obj,
  7454. struct intel_engine_cs *ring)
  7455. {
  7456. struct drm_device *dev = obj->base.dev;
  7457. struct drm_i915_private *dev_priv = dev->dev_private;
  7458. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  7459. if (!obj->frontbuffer_bits)
  7460. return;
  7461. if (ring) {
  7462. mutex_lock(&dev_priv->fb_tracking.lock);
  7463. dev_priv->fb_tracking.busy_bits
  7464. |= obj->frontbuffer_bits;
  7465. dev_priv->fb_tracking.flip_bits
  7466. &= ~obj->frontbuffer_bits;
  7467. mutex_unlock(&dev_priv->fb_tracking.lock);
  7468. }
  7469. intel_mark_fb_busy(dev, obj->frontbuffer_bits, ring);
  7470. intel_edp_psr_exit(dev);
  7471. }
  7472. /**
  7473. * intel_frontbuffer_flush - flush frontbuffer
  7474. * @dev: DRM device
  7475. * @frontbuffer_bits: frontbuffer plane tracking bits
  7476. *
  7477. * This function gets called every time rendering on the given planes has
  7478. * completed and frontbuffer caching can be started again. Flushes will get
  7479. * delayed if they're blocked by some oustanding asynchronous rendering.
  7480. *
  7481. * Can be called without any locks held.
  7482. */
  7483. void intel_frontbuffer_flush(struct drm_device *dev,
  7484. unsigned frontbuffer_bits)
  7485. {
  7486. struct drm_i915_private *dev_priv = dev->dev_private;
  7487. /* Delay flushing when rings are still busy.*/
  7488. mutex_lock(&dev_priv->fb_tracking.lock);
  7489. frontbuffer_bits &= ~dev_priv->fb_tracking.busy_bits;
  7490. mutex_unlock(&dev_priv->fb_tracking.lock);
  7491. intel_mark_fb_busy(dev, frontbuffer_bits, NULL);
  7492. intel_edp_psr_exit(dev);
  7493. }
  7494. /**
  7495. * intel_fb_obj_flush - flush frontbuffer object
  7496. * @obj: GEM object to flush
  7497. * @retire: set when retiring asynchronous rendering
  7498. *
  7499. * This function gets called every time rendering on the given object has
  7500. * completed and frontbuffer caching can be started again. If @retire is true
  7501. * then any delayed flushes will be unblocked.
  7502. */
  7503. void intel_fb_obj_flush(struct drm_i915_gem_object *obj,
  7504. bool retire)
  7505. {
  7506. struct drm_device *dev = obj->base.dev;
  7507. struct drm_i915_private *dev_priv = dev->dev_private;
  7508. unsigned frontbuffer_bits;
  7509. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  7510. if (!obj->frontbuffer_bits)
  7511. return;
  7512. frontbuffer_bits = obj->frontbuffer_bits;
  7513. if (retire) {
  7514. mutex_lock(&dev_priv->fb_tracking.lock);
  7515. /* Filter out new bits since rendering started. */
  7516. frontbuffer_bits &= dev_priv->fb_tracking.busy_bits;
  7517. dev_priv->fb_tracking.busy_bits &= ~frontbuffer_bits;
  7518. mutex_unlock(&dev_priv->fb_tracking.lock);
  7519. }
  7520. intel_frontbuffer_flush(dev, frontbuffer_bits);
  7521. }
  7522. /**
  7523. * intel_frontbuffer_flip_prepare - prepare asnychronous frontbuffer flip
  7524. * @dev: DRM device
  7525. * @frontbuffer_bits: frontbuffer plane tracking bits
  7526. *
  7527. * This function gets called after scheduling a flip on @obj. The actual
  7528. * frontbuffer flushing will be delayed until completion is signalled with
  7529. * intel_frontbuffer_flip_complete. If an invalidate happens in between this
  7530. * flush will be cancelled.
  7531. *
  7532. * Can be called without any locks held.
  7533. */
  7534. void intel_frontbuffer_flip_prepare(struct drm_device *dev,
  7535. unsigned frontbuffer_bits)
  7536. {
  7537. struct drm_i915_private *dev_priv = dev->dev_private;
  7538. mutex_lock(&dev_priv->fb_tracking.lock);
  7539. dev_priv->fb_tracking.flip_bits
  7540. |= frontbuffer_bits;
  7541. mutex_unlock(&dev_priv->fb_tracking.lock);
  7542. }
  7543. /**
  7544. * intel_frontbuffer_flip_complete - complete asynchronous frontbuffer flush
  7545. * @dev: DRM device
  7546. * @frontbuffer_bits: frontbuffer plane tracking bits
  7547. *
  7548. * This function gets called after the flip has been latched and will complete
  7549. * on the next vblank. It will execute the fush if it hasn't been cancalled yet.
  7550. *
  7551. * Can be called without any locks held.
  7552. */
  7553. void intel_frontbuffer_flip_complete(struct drm_device *dev,
  7554. unsigned frontbuffer_bits)
  7555. {
  7556. struct drm_i915_private *dev_priv = dev->dev_private;
  7557. mutex_lock(&dev_priv->fb_tracking.lock);
  7558. /* Mask any cancelled flips. */
  7559. frontbuffer_bits &= dev_priv->fb_tracking.flip_bits;
  7560. dev_priv->fb_tracking.flip_bits &= ~frontbuffer_bits;
  7561. mutex_unlock(&dev_priv->fb_tracking.lock);
  7562. intel_frontbuffer_flush(dev, frontbuffer_bits);
  7563. }
  7564. static void intel_crtc_destroy(struct drm_crtc *crtc)
  7565. {
  7566. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7567. struct drm_device *dev = crtc->dev;
  7568. struct intel_unpin_work *work;
  7569. unsigned long flags;
  7570. spin_lock_irqsave(&dev->event_lock, flags);
  7571. work = intel_crtc->unpin_work;
  7572. intel_crtc->unpin_work = NULL;
  7573. spin_unlock_irqrestore(&dev->event_lock, flags);
  7574. if (work) {
  7575. cancel_work_sync(&work->work);
  7576. kfree(work);
  7577. }
  7578. drm_crtc_cleanup(crtc);
  7579. kfree(intel_crtc);
  7580. }
  7581. static void intel_unpin_work_fn(struct work_struct *__work)
  7582. {
  7583. struct intel_unpin_work *work =
  7584. container_of(__work, struct intel_unpin_work, work);
  7585. struct drm_device *dev = work->crtc->dev;
  7586. enum pipe pipe = to_intel_crtc(work->crtc)->pipe;
  7587. mutex_lock(&dev->struct_mutex);
  7588. intel_unpin_fb_obj(work->old_fb_obj);
  7589. drm_gem_object_unreference(&work->pending_flip_obj->base);
  7590. drm_gem_object_unreference(&work->old_fb_obj->base);
  7591. intel_update_fbc(dev);
  7592. mutex_unlock(&dev->struct_mutex);
  7593. intel_frontbuffer_flip_complete(dev, INTEL_FRONTBUFFER_PRIMARY(pipe));
  7594. BUG_ON(atomic_read(&to_intel_crtc(work->crtc)->unpin_work_count) == 0);
  7595. atomic_dec(&to_intel_crtc(work->crtc)->unpin_work_count);
  7596. kfree(work);
  7597. }
  7598. static void do_intel_finish_page_flip(struct drm_device *dev,
  7599. struct drm_crtc *crtc)
  7600. {
  7601. struct drm_i915_private *dev_priv = dev->dev_private;
  7602. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7603. struct intel_unpin_work *work;
  7604. unsigned long flags;
  7605. /* Ignore early vblank irqs */
  7606. if (intel_crtc == NULL)
  7607. return;
  7608. spin_lock_irqsave(&dev->event_lock, flags);
  7609. work = intel_crtc->unpin_work;
  7610. /* Ensure we don't miss a work->pending update ... */
  7611. smp_rmb();
  7612. if (work == NULL || atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
  7613. spin_unlock_irqrestore(&dev->event_lock, flags);
  7614. return;
  7615. }
  7616. /* and that the unpin work is consistent wrt ->pending. */
  7617. smp_rmb();
  7618. intel_crtc->unpin_work = NULL;
  7619. if (work->event)
  7620. drm_send_vblank_event(dev, intel_crtc->pipe, work->event);
  7621. drm_crtc_vblank_put(crtc);
  7622. spin_unlock_irqrestore(&dev->event_lock, flags);
  7623. wake_up_all(&dev_priv->pending_flip_queue);
  7624. queue_work(dev_priv->wq, &work->work);
  7625. trace_i915_flip_complete(intel_crtc->plane, work->pending_flip_obj);
  7626. }
  7627. void intel_finish_page_flip(struct drm_device *dev, int pipe)
  7628. {
  7629. struct drm_i915_private *dev_priv = dev->dev_private;
  7630. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  7631. do_intel_finish_page_flip(dev, crtc);
  7632. }
  7633. void intel_finish_page_flip_plane(struct drm_device *dev, int plane)
  7634. {
  7635. struct drm_i915_private *dev_priv = dev->dev_private;
  7636. struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane];
  7637. do_intel_finish_page_flip(dev, crtc);
  7638. }
  7639. /* Is 'a' after or equal to 'b'? */
  7640. static bool g4x_flip_count_after_eq(u32 a, u32 b)
  7641. {
  7642. return !((a - b) & 0x80000000);
  7643. }
  7644. static bool page_flip_finished(struct intel_crtc *crtc)
  7645. {
  7646. struct drm_device *dev = crtc->base.dev;
  7647. struct drm_i915_private *dev_priv = dev->dev_private;
  7648. /*
  7649. * The relevant registers doen't exist on pre-ctg.
  7650. * As the flip done interrupt doesn't trigger for mmio
  7651. * flips on gmch platforms, a flip count check isn't
  7652. * really needed there. But since ctg has the registers,
  7653. * include it in the check anyway.
  7654. */
  7655. if (INTEL_INFO(dev)->gen < 5 && !IS_G4X(dev))
  7656. return true;
  7657. /*
  7658. * A DSPSURFLIVE check isn't enough in case the mmio and CS flips
  7659. * used the same base address. In that case the mmio flip might
  7660. * have completed, but the CS hasn't even executed the flip yet.
  7661. *
  7662. * A flip count check isn't enough as the CS might have updated
  7663. * the base address just after start of vblank, but before we
  7664. * managed to process the interrupt. This means we'd complete the
  7665. * CS flip too soon.
  7666. *
  7667. * Combining both checks should get us a good enough result. It may
  7668. * still happen that the CS flip has been executed, but has not
  7669. * yet actually completed. But in case the base address is the same
  7670. * anyway, we don't really care.
  7671. */
  7672. return (I915_READ(DSPSURFLIVE(crtc->plane)) & ~0xfff) ==
  7673. crtc->unpin_work->gtt_offset &&
  7674. g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_GM45(crtc->pipe)),
  7675. crtc->unpin_work->flip_count);
  7676. }
  7677. void intel_prepare_page_flip(struct drm_device *dev, int plane)
  7678. {
  7679. struct drm_i915_private *dev_priv = dev->dev_private;
  7680. struct intel_crtc *intel_crtc =
  7681. to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]);
  7682. unsigned long flags;
  7683. /* NB: An MMIO update of the plane base pointer will also
  7684. * generate a page-flip completion irq, i.e. every modeset
  7685. * is also accompanied by a spurious intel_prepare_page_flip().
  7686. */
  7687. spin_lock_irqsave(&dev->event_lock, flags);
  7688. if (intel_crtc->unpin_work && page_flip_finished(intel_crtc))
  7689. atomic_inc_not_zero(&intel_crtc->unpin_work->pending);
  7690. spin_unlock_irqrestore(&dev->event_lock, flags);
  7691. }
  7692. static inline void intel_mark_page_flip_active(struct intel_crtc *intel_crtc)
  7693. {
  7694. /* Ensure that the work item is consistent when activating it ... */
  7695. smp_wmb();
  7696. atomic_set(&intel_crtc->unpin_work->pending, INTEL_FLIP_PENDING);
  7697. /* and that it is marked active as soon as the irq could fire. */
  7698. smp_wmb();
  7699. }
  7700. static int intel_gen2_queue_flip(struct drm_device *dev,
  7701. struct drm_crtc *crtc,
  7702. struct drm_framebuffer *fb,
  7703. struct drm_i915_gem_object *obj,
  7704. struct intel_engine_cs *ring,
  7705. uint32_t flags)
  7706. {
  7707. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7708. u32 flip_mask;
  7709. int ret;
  7710. ret = intel_ring_begin(ring, 6);
  7711. if (ret)
  7712. return ret;
  7713. /* Can't queue multiple flips, so wait for the previous
  7714. * one to finish before executing the next.
  7715. */
  7716. if (intel_crtc->plane)
  7717. flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
  7718. else
  7719. flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
  7720. intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
  7721. intel_ring_emit(ring, MI_NOOP);
  7722. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  7723. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  7724. intel_ring_emit(ring, fb->pitches[0]);
  7725. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
  7726. intel_ring_emit(ring, 0); /* aux display base address, unused */
  7727. intel_mark_page_flip_active(intel_crtc);
  7728. __intel_ring_advance(ring);
  7729. return 0;
  7730. }
  7731. static int intel_gen3_queue_flip(struct drm_device *dev,
  7732. struct drm_crtc *crtc,
  7733. struct drm_framebuffer *fb,
  7734. struct drm_i915_gem_object *obj,
  7735. struct intel_engine_cs *ring,
  7736. uint32_t flags)
  7737. {
  7738. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7739. u32 flip_mask;
  7740. int ret;
  7741. ret = intel_ring_begin(ring, 6);
  7742. if (ret)
  7743. return ret;
  7744. if (intel_crtc->plane)
  7745. flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
  7746. else
  7747. flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
  7748. intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
  7749. intel_ring_emit(ring, MI_NOOP);
  7750. intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 |
  7751. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  7752. intel_ring_emit(ring, fb->pitches[0]);
  7753. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
  7754. intel_ring_emit(ring, MI_NOOP);
  7755. intel_mark_page_flip_active(intel_crtc);
  7756. __intel_ring_advance(ring);
  7757. return 0;
  7758. }
  7759. static int intel_gen4_queue_flip(struct drm_device *dev,
  7760. struct drm_crtc *crtc,
  7761. struct drm_framebuffer *fb,
  7762. struct drm_i915_gem_object *obj,
  7763. struct intel_engine_cs *ring,
  7764. uint32_t flags)
  7765. {
  7766. struct drm_i915_private *dev_priv = dev->dev_private;
  7767. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7768. uint32_t pf, pipesrc;
  7769. int ret;
  7770. ret = intel_ring_begin(ring, 4);
  7771. if (ret)
  7772. return ret;
  7773. /* i965+ uses the linear or tiled offsets from the
  7774. * Display Registers (which do not change across a page-flip)
  7775. * so we need only reprogram the base address.
  7776. */
  7777. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  7778. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  7779. intel_ring_emit(ring, fb->pitches[0]);
  7780. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset |
  7781. obj->tiling_mode);
  7782. /* XXX Enabling the panel-fitter across page-flip is so far
  7783. * untested on non-native modes, so ignore it for now.
  7784. * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
  7785. */
  7786. pf = 0;
  7787. pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
  7788. intel_ring_emit(ring, pf | pipesrc);
  7789. intel_mark_page_flip_active(intel_crtc);
  7790. __intel_ring_advance(ring);
  7791. return 0;
  7792. }
  7793. static int intel_gen6_queue_flip(struct drm_device *dev,
  7794. struct drm_crtc *crtc,
  7795. struct drm_framebuffer *fb,
  7796. struct drm_i915_gem_object *obj,
  7797. struct intel_engine_cs *ring,
  7798. uint32_t flags)
  7799. {
  7800. struct drm_i915_private *dev_priv = dev->dev_private;
  7801. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7802. uint32_t pf, pipesrc;
  7803. int ret;
  7804. ret = intel_ring_begin(ring, 4);
  7805. if (ret)
  7806. return ret;
  7807. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  7808. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  7809. intel_ring_emit(ring, fb->pitches[0] | obj->tiling_mode);
  7810. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
  7811. /* Contrary to the suggestions in the documentation,
  7812. * "Enable Panel Fitter" does not seem to be required when page
  7813. * flipping with a non-native mode, and worse causes a normal
  7814. * modeset to fail.
  7815. * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
  7816. */
  7817. pf = 0;
  7818. pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
  7819. intel_ring_emit(ring, pf | pipesrc);
  7820. intel_mark_page_flip_active(intel_crtc);
  7821. __intel_ring_advance(ring);
  7822. return 0;
  7823. }
  7824. static int intel_gen7_queue_flip(struct drm_device *dev,
  7825. struct drm_crtc *crtc,
  7826. struct drm_framebuffer *fb,
  7827. struct drm_i915_gem_object *obj,
  7828. struct intel_engine_cs *ring,
  7829. uint32_t flags)
  7830. {
  7831. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7832. uint32_t plane_bit = 0;
  7833. int len, ret;
  7834. switch (intel_crtc->plane) {
  7835. case PLANE_A:
  7836. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A;
  7837. break;
  7838. case PLANE_B:
  7839. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B;
  7840. break;
  7841. case PLANE_C:
  7842. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C;
  7843. break;
  7844. default:
  7845. WARN_ONCE(1, "unknown plane in flip command\n");
  7846. return -ENODEV;
  7847. }
  7848. len = 4;
  7849. if (ring->id == RCS) {
  7850. len += 6;
  7851. /*
  7852. * On Gen 8, SRM is now taking an extra dword to accommodate
  7853. * 48bits addresses, and we need a NOOP for the batch size to
  7854. * stay even.
  7855. */
  7856. if (IS_GEN8(dev))
  7857. len += 2;
  7858. }
  7859. /*
  7860. * BSpec MI_DISPLAY_FLIP for IVB:
  7861. * "The full packet must be contained within the same cache line."
  7862. *
  7863. * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same
  7864. * cacheline, if we ever start emitting more commands before
  7865. * the MI_DISPLAY_FLIP we may need to first emit everything else,
  7866. * then do the cacheline alignment, and finally emit the
  7867. * MI_DISPLAY_FLIP.
  7868. */
  7869. ret = intel_ring_cacheline_align(ring);
  7870. if (ret)
  7871. return ret;
  7872. ret = intel_ring_begin(ring, len);
  7873. if (ret)
  7874. return ret;
  7875. /* Unmask the flip-done completion message. Note that the bspec says that
  7876. * we should do this for both the BCS and RCS, and that we must not unmask
  7877. * more than one flip event at any time (or ensure that one flip message
  7878. * can be sent by waiting for flip-done prior to queueing new flips).
  7879. * Experimentation says that BCS works despite DERRMR masking all
  7880. * flip-done completion events and that unmasking all planes at once
  7881. * for the RCS also doesn't appear to drop events. Setting the DERRMR
  7882. * to zero does lead to lockups within MI_DISPLAY_FLIP.
  7883. */
  7884. if (ring->id == RCS) {
  7885. intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1));
  7886. intel_ring_emit(ring, DERRMR);
  7887. intel_ring_emit(ring, ~(DERRMR_PIPEA_PRI_FLIP_DONE |
  7888. DERRMR_PIPEB_PRI_FLIP_DONE |
  7889. DERRMR_PIPEC_PRI_FLIP_DONE));
  7890. if (IS_GEN8(dev))
  7891. intel_ring_emit(ring, MI_STORE_REGISTER_MEM_GEN8(1) |
  7892. MI_SRM_LRM_GLOBAL_GTT);
  7893. else
  7894. intel_ring_emit(ring, MI_STORE_REGISTER_MEM(1) |
  7895. MI_SRM_LRM_GLOBAL_GTT);
  7896. intel_ring_emit(ring, DERRMR);
  7897. intel_ring_emit(ring, ring->scratch.gtt_offset + 256);
  7898. if (IS_GEN8(dev)) {
  7899. intel_ring_emit(ring, 0);
  7900. intel_ring_emit(ring, MI_NOOP);
  7901. }
  7902. }
  7903. intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | plane_bit);
  7904. intel_ring_emit(ring, (fb->pitches[0] | obj->tiling_mode));
  7905. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
  7906. intel_ring_emit(ring, (MI_NOOP));
  7907. intel_mark_page_flip_active(intel_crtc);
  7908. __intel_ring_advance(ring);
  7909. return 0;
  7910. }
  7911. static bool use_mmio_flip(struct intel_engine_cs *ring,
  7912. struct drm_i915_gem_object *obj)
  7913. {
  7914. /*
  7915. * This is not being used for older platforms, because
  7916. * non-availability of flip done interrupt forces us to use
  7917. * CS flips. Older platforms derive flip done using some clever
  7918. * tricks involving the flip_pending status bits and vblank irqs.
  7919. * So using MMIO flips there would disrupt this mechanism.
  7920. */
  7921. if (INTEL_INFO(ring->dev)->gen < 5)
  7922. return false;
  7923. if (i915.use_mmio_flip < 0)
  7924. return false;
  7925. else if (i915.use_mmio_flip > 0)
  7926. return true;
  7927. else
  7928. return ring != obj->ring;
  7929. }
  7930. static void intel_do_mmio_flip(struct intel_crtc *intel_crtc)
  7931. {
  7932. struct drm_device *dev = intel_crtc->base.dev;
  7933. struct drm_i915_private *dev_priv = dev->dev_private;
  7934. struct intel_framebuffer *intel_fb =
  7935. to_intel_framebuffer(intel_crtc->base.primary->fb);
  7936. struct drm_i915_gem_object *obj = intel_fb->obj;
  7937. u32 dspcntr;
  7938. u32 reg;
  7939. intel_mark_page_flip_active(intel_crtc);
  7940. reg = DSPCNTR(intel_crtc->plane);
  7941. dspcntr = I915_READ(reg);
  7942. if (INTEL_INFO(dev)->gen >= 4) {
  7943. if (obj->tiling_mode != I915_TILING_NONE)
  7944. dspcntr |= DISPPLANE_TILED;
  7945. else
  7946. dspcntr &= ~DISPPLANE_TILED;
  7947. }
  7948. I915_WRITE(reg, dspcntr);
  7949. I915_WRITE(DSPSURF(intel_crtc->plane),
  7950. intel_crtc->unpin_work->gtt_offset);
  7951. POSTING_READ(DSPSURF(intel_crtc->plane));
  7952. }
  7953. static int intel_postpone_flip(struct drm_i915_gem_object *obj)
  7954. {
  7955. struct intel_engine_cs *ring;
  7956. int ret;
  7957. lockdep_assert_held(&obj->base.dev->struct_mutex);
  7958. if (!obj->last_write_seqno)
  7959. return 0;
  7960. ring = obj->ring;
  7961. if (i915_seqno_passed(ring->get_seqno(ring, true),
  7962. obj->last_write_seqno))
  7963. return 0;
  7964. ret = i915_gem_check_olr(ring, obj->last_write_seqno);
  7965. if (ret)
  7966. return ret;
  7967. if (WARN_ON(!ring->irq_get(ring)))
  7968. return 0;
  7969. return 1;
  7970. }
  7971. void intel_notify_mmio_flip(struct intel_engine_cs *ring)
  7972. {
  7973. struct drm_i915_private *dev_priv = to_i915(ring->dev);
  7974. struct intel_crtc *intel_crtc;
  7975. unsigned long irq_flags;
  7976. u32 seqno;
  7977. seqno = ring->get_seqno(ring, false);
  7978. spin_lock_irqsave(&dev_priv->mmio_flip_lock, irq_flags);
  7979. for_each_intel_crtc(ring->dev, intel_crtc) {
  7980. struct intel_mmio_flip *mmio_flip;
  7981. mmio_flip = &intel_crtc->mmio_flip;
  7982. if (mmio_flip->seqno == 0)
  7983. continue;
  7984. if (ring->id != mmio_flip->ring_id)
  7985. continue;
  7986. if (i915_seqno_passed(seqno, mmio_flip->seqno)) {
  7987. intel_do_mmio_flip(intel_crtc);
  7988. mmio_flip->seqno = 0;
  7989. ring->irq_put(ring);
  7990. }
  7991. }
  7992. spin_unlock_irqrestore(&dev_priv->mmio_flip_lock, irq_flags);
  7993. }
  7994. static int intel_queue_mmio_flip(struct drm_device *dev,
  7995. struct drm_crtc *crtc,
  7996. struct drm_framebuffer *fb,
  7997. struct drm_i915_gem_object *obj,
  7998. struct intel_engine_cs *ring,
  7999. uint32_t flags)
  8000. {
  8001. struct drm_i915_private *dev_priv = dev->dev_private;
  8002. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  8003. unsigned long irq_flags;
  8004. int ret;
  8005. if (WARN_ON(intel_crtc->mmio_flip.seqno))
  8006. return -EBUSY;
  8007. ret = intel_postpone_flip(obj);
  8008. if (ret < 0)
  8009. return ret;
  8010. if (ret == 0) {
  8011. intel_do_mmio_flip(intel_crtc);
  8012. return 0;
  8013. }
  8014. spin_lock_irqsave(&dev_priv->mmio_flip_lock, irq_flags);
  8015. intel_crtc->mmio_flip.seqno = obj->last_write_seqno;
  8016. intel_crtc->mmio_flip.ring_id = obj->ring->id;
  8017. spin_unlock_irqrestore(&dev_priv->mmio_flip_lock, irq_flags);
  8018. /*
  8019. * Double check to catch cases where irq fired before
  8020. * mmio flip data was ready
  8021. */
  8022. intel_notify_mmio_flip(obj->ring);
  8023. return 0;
  8024. }
  8025. static int intel_default_queue_flip(struct drm_device *dev,
  8026. struct drm_crtc *crtc,
  8027. struct drm_framebuffer *fb,
  8028. struct drm_i915_gem_object *obj,
  8029. struct intel_engine_cs *ring,
  8030. uint32_t flags)
  8031. {
  8032. return -ENODEV;
  8033. }
  8034. static int intel_crtc_page_flip(struct drm_crtc *crtc,
  8035. struct drm_framebuffer *fb,
  8036. struct drm_pending_vblank_event *event,
  8037. uint32_t page_flip_flags)
  8038. {
  8039. struct drm_device *dev = crtc->dev;
  8040. struct drm_i915_private *dev_priv = dev->dev_private;
  8041. struct drm_framebuffer *old_fb = crtc->primary->fb;
  8042. struct drm_i915_gem_object *obj = to_intel_framebuffer(fb)->obj;
  8043. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  8044. enum pipe pipe = intel_crtc->pipe;
  8045. struct intel_unpin_work *work;
  8046. struct intel_engine_cs *ring;
  8047. unsigned long flags;
  8048. int ret;
  8049. /* Can't change pixel format via MI display flips. */
  8050. if (fb->pixel_format != crtc->primary->fb->pixel_format)
  8051. return -EINVAL;
  8052. /*
  8053. * TILEOFF/LINOFF registers can't be changed via MI display flips.
  8054. * Note that pitch changes could also affect these register.
  8055. */
  8056. if (INTEL_INFO(dev)->gen > 3 &&
  8057. (fb->offsets[0] != crtc->primary->fb->offsets[0] ||
  8058. fb->pitches[0] != crtc->primary->fb->pitches[0]))
  8059. return -EINVAL;
  8060. if (i915_terminally_wedged(&dev_priv->gpu_error))
  8061. goto out_hang;
  8062. work = kzalloc(sizeof(*work), GFP_KERNEL);
  8063. if (work == NULL)
  8064. return -ENOMEM;
  8065. work->event = event;
  8066. work->crtc = crtc;
  8067. work->old_fb_obj = to_intel_framebuffer(old_fb)->obj;
  8068. INIT_WORK(&work->work, intel_unpin_work_fn);
  8069. ret = drm_crtc_vblank_get(crtc);
  8070. if (ret)
  8071. goto free_work;
  8072. /* We borrow the event spin lock for protecting unpin_work */
  8073. spin_lock_irqsave(&dev->event_lock, flags);
  8074. if (intel_crtc->unpin_work) {
  8075. spin_unlock_irqrestore(&dev->event_lock, flags);
  8076. kfree(work);
  8077. drm_crtc_vblank_put(crtc);
  8078. DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
  8079. return -EBUSY;
  8080. }
  8081. intel_crtc->unpin_work = work;
  8082. spin_unlock_irqrestore(&dev->event_lock, flags);
  8083. if (atomic_read(&intel_crtc->unpin_work_count) >= 2)
  8084. flush_workqueue(dev_priv->wq);
  8085. ret = i915_mutex_lock_interruptible(dev);
  8086. if (ret)
  8087. goto cleanup;
  8088. /* Reference the objects for the scheduled work. */
  8089. drm_gem_object_reference(&work->old_fb_obj->base);
  8090. drm_gem_object_reference(&obj->base);
  8091. crtc->primary->fb = fb;
  8092. work->pending_flip_obj = obj;
  8093. work->enable_stall_check = true;
  8094. atomic_inc(&intel_crtc->unpin_work_count);
  8095. intel_crtc->reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter);
  8096. if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
  8097. work->flip_count = I915_READ(PIPE_FLIPCOUNT_GM45(pipe)) + 1;
  8098. if (IS_VALLEYVIEW(dev)) {
  8099. ring = &dev_priv->ring[BCS];
  8100. } else if (INTEL_INFO(dev)->gen >= 7) {
  8101. ring = obj->ring;
  8102. if (ring == NULL || ring->id != RCS)
  8103. ring = &dev_priv->ring[BCS];
  8104. } else {
  8105. ring = &dev_priv->ring[RCS];
  8106. }
  8107. ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
  8108. if (ret)
  8109. goto cleanup_pending;
  8110. work->gtt_offset =
  8111. i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset;
  8112. if (use_mmio_flip(ring, obj))
  8113. ret = intel_queue_mmio_flip(dev, crtc, fb, obj, ring,
  8114. page_flip_flags);
  8115. else
  8116. ret = dev_priv->display.queue_flip(dev, crtc, fb, obj, ring,
  8117. page_flip_flags);
  8118. if (ret)
  8119. goto cleanup_unpin;
  8120. i915_gem_track_fb(work->old_fb_obj, obj,
  8121. INTEL_FRONTBUFFER_PRIMARY(pipe));
  8122. intel_disable_fbc(dev);
  8123. intel_frontbuffer_flip_prepare(dev, INTEL_FRONTBUFFER_PRIMARY(pipe));
  8124. mutex_unlock(&dev->struct_mutex);
  8125. trace_i915_flip_request(intel_crtc->plane, obj);
  8126. return 0;
  8127. cleanup_unpin:
  8128. intel_unpin_fb_obj(obj);
  8129. cleanup_pending:
  8130. atomic_dec(&intel_crtc->unpin_work_count);
  8131. crtc->primary->fb = old_fb;
  8132. drm_gem_object_unreference(&work->old_fb_obj->base);
  8133. drm_gem_object_unreference(&obj->base);
  8134. mutex_unlock(&dev->struct_mutex);
  8135. cleanup:
  8136. spin_lock_irqsave(&dev->event_lock, flags);
  8137. intel_crtc->unpin_work = NULL;
  8138. spin_unlock_irqrestore(&dev->event_lock, flags);
  8139. drm_crtc_vblank_put(crtc);
  8140. free_work:
  8141. kfree(work);
  8142. if (ret == -EIO) {
  8143. out_hang:
  8144. intel_crtc_wait_for_pending_flips(crtc);
  8145. ret = intel_pipe_set_base(crtc, crtc->x, crtc->y, fb);
  8146. if (ret == 0 && event)
  8147. drm_send_vblank_event(dev, pipe, event);
  8148. }
  8149. return ret;
  8150. }
  8151. static struct drm_crtc_helper_funcs intel_helper_funcs = {
  8152. .mode_set_base_atomic = intel_pipe_set_base_atomic,
  8153. .load_lut = intel_crtc_load_lut,
  8154. };
  8155. /**
  8156. * intel_modeset_update_staged_output_state
  8157. *
  8158. * Updates the staged output configuration state, e.g. after we've read out the
  8159. * current hw state.
  8160. */
  8161. static void intel_modeset_update_staged_output_state(struct drm_device *dev)
  8162. {
  8163. struct intel_crtc *crtc;
  8164. struct intel_encoder *encoder;
  8165. struct intel_connector *connector;
  8166. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8167. base.head) {
  8168. connector->new_encoder =
  8169. to_intel_encoder(connector->base.encoder);
  8170. }
  8171. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  8172. base.head) {
  8173. encoder->new_crtc =
  8174. to_intel_crtc(encoder->base.crtc);
  8175. }
  8176. for_each_intel_crtc(dev, crtc) {
  8177. crtc->new_enabled = crtc->base.enabled;
  8178. if (crtc->new_enabled)
  8179. crtc->new_config = &crtc->config;
  8180. else
  8181. crtc->new_config = NULL;
  8182. }
  8183. }
  8184. /**
  8185. * intel_modeset_commit_output_state
  8186. *
  8187. * This function copies the stage display pipe configuration to the real one.
  8188. */
  8189. static void intel_modeset_commit_output_state(struct drm_device *dev)
  8190. {
  8191. struct intel_crtc *crtc;
  8192. struct intel_encoder *encoder;
  8193. struct intel_connector *connector;
  8194. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8195. base.head) {
  8196. connector->base.encoder = &connector->new_encoder->base;
  8197. }
  8198. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  8199. base.head) {
  8200. encoder->base.crtc = &encoder->new_crtc->base;
  8201. }
  8202. for_each_intel_crtc(dev, crtc) {
  8203. crtc->base.enabled = crtc->new_enabled;
  8204. }
  8205. }
  8206. static void
  8207. connected_sink_compute_bpp(struct intel_connector *connector,
  8208. struct intel_crtc_config *pipe_config)
  8209. {
  8210. int bpp = pipe_config->pipe_bpp;
  8211. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n",
  8212. connector->base.base.id,
  8213. connector->base.name);
  8214. /* Don't use an invalid EDID bpc value */
  8215. if (connector->base.display_info.bpc &&
  8216. connector->base.display_info.bpc * 3 < bpp) {
  8217. DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
  8218. bpp, connector->base.display_info.bpc*3);
  8219. pipe_config->pipe_bpp = connector->base.display_info.bpc*3;
  8220. }
  8221. /* Clamp bpp to 8 on screens without EDID 1.4 */
  8222. if (connector->base.display_info.bpc == 0 && bpp > 24) {
  8223. DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n",
  8224. bpp);
  8225. pipe_config->pipe_bpp = 24;
  8226. }
  8227. }
  8228. static int
  8229. compute_baseline_pipe_bpp(struct intel_crtc *crtc,
  8230. struct drm_framebuffer *fb,
  8231. struct intel_crtc_config *pipe_config)
  8232. {
  8233. struct drm_device *dev = crtc->base.dev;
  8234. struct intel_connector *connector;
  8235. int bpp;
  8236. switch (fb->pixel_format) {
  8237. case DRM_FORMAT_C8:
  8238. bpp = 8*3; /* since we go through a colormap */
  8239. break;
  8240. case DRM_FORMAT_XRGB1555:
  8241. case DRM_FORMAT_ARGB1555:
  8242. /* checked in intel_framebuffer_init already */
  8243. if (WARN_ON(INTEL_INFO(dev)->gen > 3))
  8244. return -EINVAL;
  8245. case DRM_FORMAT_RGB565:
  8246. bpp = 6*3; /* min is 18bpp */
  8247. break;
  8248. case DRM_FORMAT_XBGR8888:
  8249. case DRM_FORMAT_ABGR8888:
  8250. /* checked in intel_framebuffer_init already */
  8251. if (WARN_ON(INTEL_INFO(dev)->gen < 4))
  8252. return -EINVAL;
  8253. case DRM_FORMAT_XRGB8888:
  8254. case DRM_FORMAT_ARGB8888:
  8255. bpp = 8*3;
  8256. break;
  8257. case DRM_FORMAT_XRGB2101010:
  8258. case DRM_FORMAT_ARGB2101010:
  8259. case DRM_FORMAT_XBGR2101010:
  8260. case DRM_FORMAT_ABGR2101010:
  8261. /* checked in intel_framebuffer_init already */
  8262. if (WARN_ON(INTEL_INFO(dev)->gen < 4))
  8263. return -EINVAL;
  8264. bpp = 10*3;
  8265. break;
  8266. /* TODO: gen4+ supports 16 bpc floating point, too. */
  8267. default:
  8268. DRM_DEBUG_KMS("unsupported depth\n");
  8269. return -EINVAL;
  8270. }
  8271. pipe_config->pipe_bpp = bpp;
  8272. /* Clamp display bpp to EDID value */
  8273. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8274. base.head) {
  8275. if (!connector->new_encoder ||
  8276. connector->new_encoder->new_crtc != crtc)
  8277. continue;
  8278. connected_sink_compute_bpp(connector, pipe_config);
  8279. }
  8280. return bpp;
  8281. }
  8282. static void intel_dump_crtc_timings(const struct drm_display_mode *mode)
  8283. {
  8284. DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
  8285. "type: 0x%x flags: 0x%x\n",
  8286. mode->crtc_clock,
  8287. mode->crtc_hdisplay, mode->crtc_hsync_start,
  8288. mode->crtc_hsync_end, mode->crtc_htotal,
  8289. mode->crtc_vdisplay, mode->crtc_vsync_start,
  8290. mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags);
  8291. }
  8292. static void intel_dump_pipe_config(struct intel_crtc *crtc,
  8293. struct intel_crtc_config *pipe_config,
  8294. const char *context)
  8295. {
  8296. DRM_DEBUG_KMS("[CRTC:%d]%s config for pipe %c\n", crtc->base.base.id,
  8297. context, pipe_name(crtc->pipe));
  8298. DRM_DEBUG_KMS("cpu_transcoder: %c\n", transcoder_name(pipe_config->cpu_transcoder));
  8299. DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n",
  8300. pipe_config->pipe_bpp, pipe_config->dither);
  8301. DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
  8302. pipe_config->has_pch_encoder,
  8303. pipe_config->fdi_lanes,
  8304. pipe_config->fdi_m_n.gmch_m, pipe_config->fdi_m_n.gmch_n,
  8305. pipe_config->fdi_m_n.link_m, pipe_config->fdi_m_n.link_n,
  8306. pipe_config->fdi_m_n.tu);
  8307. DRM_DEBUG_KMS("dp: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
  8308. pipe_config->has_dp_encoder,
  8309. pipe_config->dp_m_n.gmch_m, pipe_config->dp_m_n.gmch_n,
  8310. pipe_config->dp_m_n.link_m, pipe_config->dp_m_n.link_n,
  8311. pipe_config->dp_m_n.tu);
  8312. DRM_DEBUG_KMS("requested mode:\n");
  8313. drm_mode_debug_printmodeline(&pipe_config->requested_mode);
  8314. DRM_DEBUG_KMS("adjusted mode:\n");
  8315. drm_mode_debug_printmodeline(&pipe_config->adjusted_mode);
  8316. intel_dump_crtc_timings(&pipe_config->adjusted_mode);
  8317. DRM_DEBUG_KMS("port clock: %d\n", pipe_config->port_clock);
  8318. DRM_DEBUG_KMS("pipe src size: %dx%d\n",
  8319. pipe_config->pipe_src_w, pipe_config->pipe_src_h);
  8320. DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
  8321. pipe_config->gmch_pfit.control,
  8322. pipe_config->gmch_pfit.pgm_ratios,
  8323. pipe_config->gmch_pfit.lvds_border_bits);
  8324. DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
  8325. pipe_config->pch_pfit.pos,
  8326. pipe_config->pch_pfit.size,
  8327. pipe_config->pch_pfit.enabled ? "enabled" : "disabled");
  8328. DRM_DEBUG_KMS("ips: %i\n", pipe_config->ips_enabled);
  8329. DRM_DEBUG_KMS("double wide: %i\n", pipe_config->double_wide);
  8330. }
  8331. static bool encoders_cloneable(const struct intel_encoder *a,
  8332. const struct intel_encoder *b)
  8333. {
  8334. /* masks could be asymmetric, so check both ways */
  8335. return a == b || (a->cloneable & (1 << b->type) &&
  8336. b->cloneable & (1 << a->type));
  8337. }
  8338. static bool check_single_encoder_cloning(struct intel_crtc *crtc,
  8339. struct intel_encoder *encoder)
  8340. {
  8341. struct drm_device *dev = crtc->base.dev;
  8342. struct intel_encoder *source_encoder;
  8343. list_for_each_entry(source_encoder,
  8344. &dev->mode_config.encoder_list, base.head) {
  8345. if (source_encoder->new_crtc != crtc)
  8346. continue;
  8347. if (!encoders_cloneable(encoder, source_encoder))
  8348. return false;
  8349. }
  8350. return true;
  8351. }
  8352. static bool check_encoder_cloning(struct intel_crtc *crtc)
  8353. {
  8354. struct drm_device *dev = crtc->base.dev;
  8355. struct intel_encoder *encoder;
  8356. list_for_each_entry(encoder,
  8357. &dev->mode_config.encoder_list, base.head) {
  8358. if (encoder->new_crtc != crtc)
  8359. continue;
  8360. if (!check_single_encoder_cloning(crtc, encoder))
  8361. return false;
  8362. }
  8363. return true;
  8364. }
  8365. static struct intel_crtc_config *
  8366. intel_modeset_pipe_config(struct drm_crtc *crtc,
  8367. struct drm_framebuffer *fb,
  8368. struct drm_display_mode *mode)
  8369. {
  8370. struct drm_device *dev = crtc->dev;
  8371. struct intel_encoder *encoder;
  8372. struct intel_crtc_config *pipe_config;
  8373. int plane_bpp, ret = -EINVAL;
  8374. bool retry = true;
  8375. if (!check_encoder_cloning(to_intel_crtc(crtc))) {
  8376. DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
  8377. return ERR_PTR(-EINVAL);
  8378. }
  8379. pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL);
  8380. if (!pipe_config)
  8381. return ERR_PTR(-ENOMEM);
  8382. drm_mode_copy(&pipe_config->adjusted_mode, mode);
  8383. drm_mode_copy(&pipe_config->requested_mode, mode);
  8384. pipe_config->cpu_transcoder =
  8385. (enum transcoder) to_intel_crtc(crtc)->pipe;
  8386. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  8387. /*
  8388. * Sanitize sync polarity flags based on requested ones. If neither
  8389. * positive or negative polarity is requested, treat this as meaning
  8390. * negative polarity.
  8391. */
  8392. if (!(pipe_config->adjusted_mode.flags &
  8393. (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
  8394. pipe_config->adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
  8395. if (!(pipe_config->adjusted_mode.flags &
  8396. (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
  8397. pipe_config->adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
  8398. /* Compute a starting value for pipe_config->pipe_bpp taking the source
  8399. * plane pixel format and any sink constraints into account. Returns the
  8400. * source plane bpp so that dithering can be selected on mismatches
  8401. * after encoders and crtc also have had their say. */
  8402. plane_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc),
  8403. fb, pipe_config);
  8404. if (plane_bpp < 0)
  8405. goto fail;
  8406. /*
  8407. * Determine the real pipe dimensions. Note that stereo modes can
  8408. * increase the actual pipe size due to the frame doubling and
  8409. * insertion of additional space for blanks between the frame. This
  8410. * is stored in the crtc timings. We use the requested mode to do this
  8411. * computation to clearly distinguish it from the adjusted mode, which
  8412. * can be changed by the connectors in the below retry loop.
  8413. */
  8414. drm_mode_set_crtcinfo(&pipe_config->requested_mode, CRTC_STEREO_DOUBLE);
  8415. pipe_config->pipe_src_w = pipe_config->requested_mode.crtc_hdisplay;
  8416. pipe_config->pipe_src_h = pipe_config->requested_mode.crtc_vdisplay;
  8417. encoder_retry:
  8418. /* Ensure the port clock defaults are reset when retrying. */
  8419. pipe_config->port_clock = 0;
  8420. pipe_config->pixel_multiplier = 1;
  8421. /* Fill in default crtc timings, allow encoders to overwrite them. */
  8422. drm_mode_set_crtcinfo(&pipe_config->adjusted_mode, CRTC_STEREO_DOUBLE);
  8423. /* Pass our mode to the connectors and the CRTC to give them a chance to
  8424. * adjust it according to limitations or connector properties, and also
  8425. * a chance to reject the mode entirely.
  8426. */
  8427. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  8428. base.head) {
  8429. if (&encoder->new_crtc->base != crtc)
  8430. continue;
  8431. if (!(encoder->compute_config(encoder, pipe_config))) {
  8432. DRM_DEBUG_KMS("Encoder config failure\n");
  8433. goto fail;
  8434. }
  8435. }
  8436. /* Set default port clock if not overwritten by the encoder. Needs to be
  8437. * done afterwards in case the encoder adjusts the mode. */
  8438. if (!pipe_config->port_clock)
  8439. pipe_config->port_clock = pipe_config->adjusted_mode.crtc_clock
  8440. * pipe_config->pixel_multiplier;
  8441. ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config);
  8442. if (ret < 0) {
  8443. DRM_DEBUG_KMS("CRTC fixup failed\n");
  8444. goto fail;
  8445. }
  8446. if (ret == RETRY) {
  8447. if (WARN(!retry, "loop in pipe configuration computation\n")) {
  8448. ret = -EINVAL;
  8449. goto fail;
  8450. }
  8451. DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
  8452. retry = false;
  8453. goto encoder_retry;
  8454. }
  8455. pipe_config->dither = pipe_config->pipe_bpp != plane_bpp;
  8456. DRM_DEBUG_KMS("plane bpp: %i, pipe bpp: %i, dithering: %i\n",
  8457. plane_bpp, pipe_config->pipe_bpp, pipe_config->dither);
  8458. return pipe_config;
  8459. fail:
  8460. kfree(pipe_config);
  8461. return ERR_PTR(ret);
  8462. }
  8463. /* Computes which crtcs are affected and sets the relevant bits in the mask. For
  8464. * simplicity we use the crtc's pipe number (because it's easier to obtain). */
  8465. static void
  8466. intel_modeset_affected_pipes(struct drm_crtc *crtc, unsigned *modeset_pipes,
  8467. unsigned *prepare_pipes, unsigned *disable_pipes)
  8468. {
  8469. struct intel_crtc *intel_crtc;
  8470. struct drm_device *dev = crtc->dev;
  8471. struct intel_encoder *encoder;
  8472. struct intel_connector *connector;
  8473. struct drm_crtc *tmp_crtc;
  8474. *disable_pipes = *modeset_pipes = *prepare_pipes = 0;
  8475. /* Check which crtcs have changed outputs connected to them, these need
  8476. * to be part of the prepare_pipes mask. We don't (yet) support global
  8477. * modeset across multiple crtcs, so modeset_pipes will only have one
  8478. * bit set at most. */
  8479. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8480. base.head) {
  8481. if (connector->base.encoder == &connector->new_encoder->base)
  8482. continue;
  8483. if (connector->base.encoder) {
  8484. tmp_crtc = connector->base.encoder->crtc;
  8485. *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe;
  8486. }
  8487. if (connector->new_encoder)
  8488. *prepare_pipes |=
  8489. 1 << connector->new_encoder->new_crtc->pipe;
  8490. }
  8491. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  8492. base.head) {
  8493. if (encoder->base.crtc == &encoder->new_crtc->base)
  8494. continue;
  8495. if (encoder->base.crtc) {
  8496. tmp_crtc = encoder->base.crtc;
  8497. *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe;
  8498. }
  8499. if (encoder->new_crtc)
  8500. *prepare_pipes |= 1 << encoder->new_crtc->pipe;
  8501. }
  8502. /* Check for pipes that will be enabled/disabled ... */
  8503. for_each_intel_crtc(dev, intel_crtc) {
  8504. if (intel_crtc->base.enabled == intel_crtc->new_enabled)
  8505. continue;
  8506. if (!intel_crtc->new_enabled)
  8507. *disable_pipes |= 1 << intel_crtc->pipe;
  8508. else
  8509. *prepare_pipes |= 1 << intel_crtc->pipe;
  8510. }
  8511. /* set_mode is also used to update properties on life display pipes. */
  8512. intel_crtc = to_intel_crtc(crtc);
  8513. if (intel_crtc->new_enabled)
  8514. *prepare_pipes |= 1 << intel_crtc->pipe;
  8515. /*
  8516. * For simplicity do a full modeset on any pipe where the output routing
  8517. * changed. We could be more clever, but that would require us to be
  8518. * more careful with calling the relevant encoder->mode_set functions.
  8519. */
  8520. if (*prepare_pipes)
  8521. *modeset_pipes = *prepare_pipes;
  8522. /* ... and mask these out. */
  8523. *modeset_pipes &= ~(*disable_pipes);
  8524. *prepare_pipes &= ~(*disable_pipes);
  8525. /*
  8526. * HACK: We don't (yet) fully support global modesets. intel_set_config
  8527. * obies this rule, but the modeset restore mode of
  8528. * intel_modeset_setup_hw_state does not.
  8529. */
  8530. *modeset_pipes &= 1 << intel_crtc->pipe;
  8531. *prepare_pipes &= 1 << intel_crtc->pipe;
  8532. DRM_DEBUG_KMS("set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n",
  8533. *modeset_pipes, *prepare_pipes, *disable_pipes);
  8534. }
  8535. static bool intel_crtc_in_use(struct drm_crtc *crtc)
  8536. {
  8537. struct drm_encoder *encoder;
  8538. struct drm_device *dev = crtc->dev;
  8539. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)
  8540. if (encoder->crtc == crtc)
  8541. return true;
  8542. return false;
  8543. }
  8544. static void
  8545. intel_modeset_update_state(struct drm_device *dev, unsigned prepare_pipes)
  8546. {
  8547. struct intel_encoder *intel_encoder;
  8548. struct intel_crtc *intel_crtc;
  8549. struct drm_connector *connector;
  8550. list_for_each_entry(intel_encoder, &dev->mode_config.encoder_list,
  8551. base.head) {
  8552. if (!intel_encoder->base.crtc)
  8553. continue;
  8554. intel_crtc = to_intel_crtc(intel_encoder->base.crtc);
  8555. if (prepare_pipes & (1 << intel_crtc->pipe))
  8556. intel_encoder->connectors_active = false;
  8557. }
  8558. intel_modeset_commit_output_state(dev);
  8559. /* Double check state. */
  8560. for_each_intel_crtc(dev, intel_crtc) {
  8561. WARN_ON(intel_crtc->base.enabled != intel_crtc_in_use(&intel_crtc->base));
  8562. WARN_ON(intel_crtc->new_config &&
  8563. intel_crtc->new_config != &intel_crtc->config);
  8564. WARN_ON(intel_crtc->base.enabled != !!intel_crtc->new_config);
  8565. }
  8566. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  8567. if (!connector->encoder || !connector->encoder->crtc)
  8568. continue;
  8569. intel_crtc = to_intel_crtc(connector->encoder->crtc);
  8570. if (prepare_pipes & (1 << intel_crtc->pipe)) {
  8571. struct drm_property *dpms_property =
  8572. dev->mode_config.dpms_property;
  8573. connector->dpms = DRM_MODE_DPMS_ON;
  8574. drm_object_property_set_value(&connector->base,
  8575. dpms_property,
  8576. DRM_MODE_DPMS_ON);
  8577. intel_encoder = to_intel_encoder(connector->encoder);
  8578. intel_encoder->connectors_active = true;
  8579. }
  8580. }
  8581. }
  8582. static bool intel_fuzzy_clock_check(int clock1, int clock2)
  8583. {
  8584. int diff;
  8585. if (clock1 == clock2)
  8586. return true;
  8587. if (!clock1 || !clock2)
  8588. return false;
  8589. diff = abs(clock1 - clock2);
  8590. if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
  8591. return true;
  8592. return false;
  8593. }
  8594. #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \
  8595. list_for_each_entry((intel_crtc), \
  8596. &(dev)->mode_config.crtc_list, \
  8597. base.head) \
  8598. if (mask & (1 <<(intel_crtc)->pipe))
  8599. static bool
  8600. intel_pipe_config_compare(struct drm_device *dev,
  8601. struct intel_crtc_config *current_config,
  8602. struct intel_crtc_config *pipe_config)
  8603. {
  8604. #define PIPE_CONF_CHECK_X(name) \
  8605. if (current_config->name != pipe_config->name) { \
  8606. DRM_ERROR("mismatch in " #name " " \
  8607. "(expected 0x%08x, found 0x%08x)\n", \
  8608. current_config->name, \
  8609. pipe_config->name); \
  8610. return false; \
  8611. }
  8612. #define PIPE_CONF_CHECK_I(name) \
  8613. if (current_config->name != pipe_config->name) { \
  8614. DRM_ERROR("mismatch in " #name " " \
  8615. "(expected %i, found %i)\n", \
  8616. current_config->name, \
  8617. pipe_config->name); \
  8618. return false; \
  8619. }
  8620. #define PIPE_CONF_CHECK_FLAGS(name, mask) \
  8621. if ((current_config->name ^ pipe_config->name) & (mask)) { \
  8622. DRM_ERROR("mismatch in " #name "(" #mask ") " \
  8623. "(expected %i, found %i)\n", \
  8624. current_config->name & (mask), \
  8625. pipe_config->name & (mask)); \
  8626. return false; \
  8627. }
  8628. #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \
  8629. if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
  8630. DRM_ERROR("mismatch in " #name " " \
  8631. "(expected %i, found %i)\n", \
  8632. current_config->name, \
  8633. pipe_config->name); \
  8634. return false; \
  8635. }
  8636. #define PIPE_CONF_QUIRK(quirk) \
  8637. ((current_config->quirks | pipe_config->quirks) & (quirk))
  8638. PIPE_CONF_CHECK_I(cpu_transcoder);
  8639. PIPE_CONF_CHECK_I(has_pch_encoder);
  8640. PIPE_CONF_CHECK_I(fdi_lanes);
  8641. PIPE_CONF_CHECK_I(fdi_m_n.gmch_m);
  8642. PIPE_CONF_CHECK_I(fdi_m_n.gmch_n);
  8643. PIPE_CONF_CHECK_I(fdi_m_n.link_m);
  8644. PIPE_CONF_CHECK_I(fdi_m_n.link_n);
  8645. PIPE_CONF_CHECK_I(fdi_m_n.tu);
  8646. PIPE_CONF_CHECK_I(has_dp_encoder);
  8647. PIPE_CONF_CHECK_I(dp_m_n.gmch_m);
  8648. PIPE_CONF_CHECK_I(dp_m_n.gmch_n);
  8649. PIPE_CONF_CHECK_I(dp_m_n.link_m);
  8650. PIPE_CONF_CHECK_I(dp_m_n.link_n);
  8651. PIPE_CONF_CHECK_I(dp_m_n.tu);
  8652. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hdisplay);
  8653. PIPE_CONF_CHECK_I(adjusted_mode.crtc_htotal);
  8654. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hblank_start);
  8655. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hblank_end);
  8656. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hsync_start);
  8657. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hsync_end);
  8658. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vdisplay);
  8659. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vtotal);
  8660. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vblank_start);
  8661. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vblank_end);
  8662. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vsync_start);
  8663. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vsync_end);
  8664. PIPE_CONF_CHECK_I(pixel_multiplier);
  8665. PIPE_CONF_CHECK_I(has_hdmi_sink);
  8666. if ((INTEL_INFO(dev)->gen < 8 && !IS_HASWELL(dev)) ||
  8667. IS_VALLEYVIEW(dev))
  8668. PIPE_CONF_CHECK_I(limited_color_range);
  8669. PIPE_CONF_CHECK_I(has_audio);
  8670. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  8671. DRM_MODE_FLAG_INTERLACE);
  8672. if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
  8673. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  8674. DRM_MODE_FLAG_PHSYNC);
  8675. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  8676. DRM_MODE_FLAG_NHSYNC);
  8677. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  8678. DRM_MODE_FLAG_PVSYNC);
  8679. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  8680. DRM_MODE_FLAG_NVSYNC);
  8681. }
  8682. PIPE_CONF_CHECK_I(pipe_src_w);
  8683. PIPE_CONF_CHECK_I(pipe_src_h);
  8684. /*
  8685. * FIXME: BIOS likes to set up a cloned config with lvds+external
  8686. * screen. Since we don't yet re-compute the pipe config when moving
  8687. * just the lvds port away to another pipe the sw tracking won't match.
  8688. *
  8689. * Proper atomic modesets with recomputed global state will fix this.
  8690. * Until then just don't check gmch state for inherited modes.
  8691. */
  8692. if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_INHERITED_MODE)) {
  8693. PIPE_CONF_CHECK_I(gmch_pfit.control);
  8694. /* pfit ratios are autocomputed by the hw on gen4+ */
  8695. if (INTEL_INFO(dev)->gen < 4)
  8696. PIPE_CONF_CHECK_I(gmch_pfit.pgm_ratios);
  8697. PIPE_CONF_CHECK_I(gmch_pfit.lvds_border_bits);
  8698. }
  8699. PIPE_CONF_CHECK_I(pch_pfit.enabled);
  8700. if (current_config->pch_pfit.enabled) {
  8701. PIPE_CONF_CHECK_I(pch_pfit.pos);
  8702. PIPE_CONF_CHECK_I(pch_pfit.size);
  8703. }
  8704. /* BDW+ don't expose a synchronous way to read the state */
  8705. if (IS_HASWELL(dev))
  8706. PIPE_CONF_CHECK_I(ips_enabled);
  8707. PIPE_CONF_CHECK_I(double_wide);
  8708. PIPE_CONF_CHECK_I(shared_dpll);
  8709. PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
  8710. PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
  8711. PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
  8712. PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
  8713. if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5)
  8714. PIPE_CONF_CHECK_I(pipe_bpp);
  8715. PIPE_CONF_CHECK_CLOCK_FUZZY(adjusted_mode.crtc_clock);
  8716. PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock);
  8717. #undef PIPE_CONF_CHECK_X
  8718. #undef PIPE_CONF_CHECK_I
  8719. #undef PIPE_CONF_CHECK_FLAGS
  8720. #undef PIPE_CONF_CHECK_CLOCK_FUZZY
  8721. #undef PIPE_CONF_QUIRK
  8722. return true;
  8723. }
  8724. static void
  8725. check_connector_state(struct drm_device *dev)
  8726. {
  8727. struct intel_connector *connector;
  8728. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8729. base.head) {
  8730. /* This also checks the encoder/connector hw state with the
  8731. * ->get_hw_state callbacks. */
  8732. intel_connector_check_state(connector);
  8733. WARN(&connector->new_encoder->base != connector->base.encoder,
  8734. "connector's staged encoder doesn't match current encoder\n");
  8735. }
  8736. }
  8737. static void
  8738. check_encoder_state(struct drm_device *dev)
  8739. {
  8740. struct intel_encoder *encoder;
  8741. struct intel_connector *connector;
  8742. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  8743. base.head) {
  8744. bool enabled = false;
  8745. bool active = false;
  8746. enum pipe pipe, tracked_pipe;
  8747. DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
  8748. encoder->base.base.id,
  8749. encoder->base.name);
  8750. WARN(&encoder->new_crtc->base != encoder->base.crtc,
  8751. "encoder's stage crtc doesn't match current crtc\n");
  8752. WARN(encoder->connectors_active && !encoder->base.crtc,
  8753. "encoder's active_connectors set, but no crtc\n");
  8754. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8755. base.head) {
  8756. if (connector->base.encoder != &encoder->base)
  8757. continue;
  8758. enabled = true;
  8759. if (connector->base.dpms != DRM_MODE_DPMS_OFF)
  8760. active = true;
  8761. }
  8762. WARN(!!encoder->base.crtc != enabled,
  8763. "encoder's enabled state mismatch "
  8764. "(expected %i, found %i)\n",
  8765. !!encoder->base.crtc, enabled);
  8766. WARN(active && !encoder->base.crtc,
  8767. "active encoder with no crtc\n");
  8768. WARN(encoder->connectors_active != active,
  8769. "encoder's computed active state doesn't match tracked active state "
  8770. "(expected %i, found %i)\n", active, encoder->connectors_active);
  8771. active = encoder->get_hw_state(encoder, &pipe);
  8772. WARN(active != encoder->connectors_active,
  8773. "encoder's hw state doesn't match sw tracking "
  8774. "(expected %i, found %i)\n",
  8775. encoder->connectors_active, active);
  8776. if (!encoder->base.crtc)
  8777. continue;
  8778. tracked_pipe = to_intel_crtc(encoder->base.crtc)->pipe;
  8779. WARN(active && pipe != tracked_pipe,
  8780. "active encoder's pipe doesn't match"
  8781. "(expected %i, found %i)\n",
  8782. tracked_pipe, pipe);
  8783. }
  8784. }
  8785. static void
  8786. check_crtc_state(struct drm_device *dev)
  8787. {
  8788. struct drm_i915_private *dev_priv = dev->dev_private;
  8789. struct intel_crtc *crtc;
  8790. struct intel_encoder *encoder;
  8791. struct intel_crtc_config pipe_config;
  8792. for_each_intel_crtc(dev, crtc) {
  8793. bool enabled = false;
  8794. bool active = false;
  8795. memset(&pipe_config, 0, sizeof(pipe_config));
  8796. DRM_DEBUG_KMS("[CRTC:%d]\n",
  8797. crtc->base.base.id);
  8798. WARN(crtc->active && !crtc->base.enabled,
  8799. "active crtc, but not enabled in sw tracking\n");
  8800. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  8801. base.head) {
  8802. if (encoder->base.crtc != &crtc->base)
  8803. continue;
  8804. enabled = true;
  8805. if (encoder->connectors_active)
  8806. active = true;
  8807. }
  8808. WARN(active != crtc->active,
  8809. "crtc's computed active state doesn't match tracked active state "
  8810. "(expected %i, found %i)\n", active, crtc->active);
  8811. WARN(enabled != crtc->base.enabled,
  8812. "crtc's computed enabled state doesn't match tracked enabled state "
  8813. "(expected %i, found %i)\n", enabled, crtc->base.enabled);
  8814. active = dev_priv->display.get_pipe_config(crtc,
  8815. &pipe_config);
  8816. /* hw state is inconsistent with the pipe A quirk */
  8817. if (crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE)
  8818. active = crtc->active;
  8819. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  8820. base.head) {
  8821. enum pipe pipe;
  8822. if (encoder->base.crtc != &crtc->base)
  8823. continue;
  8824. if (encoder->get_hw_state(encoder, &pipe))
  8825. encoder->get_config(encoder, &pipe_config);
  8826. }
  8827. WARN(crtc->active != active,
  8828. "crtc active state doesn't match with hw state "
  8829. "(expected %i, found %i)\n", crtc->active, active);
  8830. if (active &&
  8831. !intel_pipe_config_compare(dev, &crtc->config, &pipe_config)) {
  8832. WARN(1, "pipe state doesn't match!\n");
  8833. intel_dump_pipe_config(crtc, &pipe_config,
  8834. "[hw state]");
  8835. intel_dump_pipe_config(crtc, &crtc->config,
  8836. "[sw state]");
  8837. }
  8838. }
  8839. }
  8840. static void
  8841. check_shared_dpll_state(struct drm_device *dev)
  8842. {
  8843. struct drm_i915_private *dev_priv = dev->dev_private;
  8844. struct intel_crtc *crtc;
  8845. struct intel_dpll_hw_state dpll_hw_state;
  8846. int i;
  8847. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  8848. struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
  8849. int enabled_crtcs = 0, active_crtcs = 0;
  8850. bool active;
  8851. memset(&dpll_hw_state, 0, sizeof(dpll_hw_state));
  8852. DRM_DEBUG_KMS("%s\n", pll->name);
  8853. active = pll->get_hw_state(dev_priv, pll, &dpll_hw_state);
  8854. WARN(pll->active > pll->refcount,
  8855. "more active pll users than references: %i vs %i\n",
  8856. pll->active, pll->refcount);
  8857. WARN(pll->active && !pll->on,
  8858. "pll in active use but not on in sw tracking\n");
  8859. WARN(pll->on && !pll->active,
  8860. "pll in on but not on in use in sw tracking\n");
  8861. WARN(pll->on != active,
  8862. "pll on state mismatch (expected %i, found %i)\n",
  8863. pll->on, active);
  8864. for_each_intel_crtc(dev, crtc) {
  8865. if (crtc->base.enabled && intel_crtc_to_shared_dpll(crtc) == pll)
  8866. enabled_crtcs++;
  8867. if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll)
  8868. active_crtcs++;
  8869. }
  8870. WARN(pll->active != active_crtcs,
  8871. "pll active crtcs mismatch (expected %i, found %i)\n",
  8872. pll->active, active_crtcs);
  8873. WARN(pll->refcount != enabled_crtcs,
  8874. "pll enabled crtcs mismatch (expected %i, found %i)\n",
  8875. pll->refcount, enabled_crtcs);
  8876. WARN(pll->on && memcmp(&pll->hw_state, &dpll_hw_state,
  8877. sizeof(dpll_hw_state)),
  8878. "pll hw state mismatch\n");
  8879. }
  8880. }
  8881. void
  8882. intel_modeset_check_state(struct drm_device *dev)
  8883. {
  8884. check_connector_state(dev);
  8885. check_encoder_state(dev);
  8886. check_crtc_state(dev);
  8887. check_shared_dpll_state(dev);
  8888. }
  8889. void ironlake_check_encoder_dotclock(const struct intel_crtc_config *pipe_config,
  8890. int dotclock)
  8891. {
  8892. /*
  8893. * FDI already provided one idea for the dotclock.
  8894. * Yell if the encoder disagrees.
  8895. */
  8896. WARN(!intel_fuzzy_clock_check(pipe_config->adjusted_mode.crtc_clock, dotclock),
  8897. "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
  8898. pipe_config->adjusted_mode.crtc_clock, dotclock);
  8899. }
  8900. static void update_scanline_offset(struct intel_crtc *crtc)
  8901. {
  8902. struct drm_device *dev = crtc->base.dev;
  8903. /*
  8904. * The scanline counter increments at the leading edge of hsync.
  8905. *
  8906. * On most platforms it starts counting from vtotal-1 on the
  8907. * first active line. That means the scanline counter value is
  8908. * always one less than what we would expect. Ie. just after
  8909. * start of vblank, which also occurs at start of hsync (on the
  8910. * last active line), the scanline counter will read vblank_start-1.
  8911. *
  8912. * On gen2 the scanline counter starts counting from 1 instead
  8913. * of vtotal-1, so we have to subtract one (or rather add vtotal-1
  8914. * to keep the value positive), instead of adding one.
  8915. *
  8916. * On HSW+ the behaviour of the scanline counter depends on the output
  8917. * type. For DP ports it behaves like most other platforms, but on HDMI
  8918. * there's an extra 1 line difference. So we need to add two instead of
  8919. * one to the value.
  8920. */
  8921. if (IS_GEN2(dev)) {
  8922. const struct drm_display_mode *mode = &crtc->config.adjusted_mode;
  8923. int vtotal;
  8924. vtotal = mode->crtc_vtotal;
  8925. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  8926. vtotal /= 2;
  8927. crtc->scanline_offset = vtotal - 1;
  8928. } else if (HAS_DDI(dev) &&
  8929. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI)) {
  8930. crtc->scanline_offset = 2;
  8931. } else
  8932. crtc->scanline_offset = 1;
  8933. }
  8934. static int __intel_set_mode(struct drm_crtc *crtc,
  8935. struct drm_display_mode *mode,
  8936. int x, int y, struct drm_framebuffer *fb)
  8937. {
  8938. struct drm_device *dev = crtc->dev;
  8939. struct drm_i915_private *dev_priv = dev->dev_private;
  8940. struct drm_display_mode *saved_mode;
  8941. struct intel_crtc_config *pipe_config = NULL;
  8942. struct intel_crtc *intel_crtc;
  8943. unsigned disable_pipes, prepare_pipes, modeset_pipes;
  8944. int ret = 0;
  8945. saved_mode = kmalloc(sizeof(*saved_mode), GFP_KERNEL);
  8946. if (!saved_mode)
  8947. return -ENOMEM;
  8948. intel_modeset_affected_pipes(crtc, &modeset_pipes,
  8949. &prepare_pipes, &disable_pipes);
  8950. *saved_mode = crtc->mode;
  8951. /* Hack: Because we don't (yet) support global modeset on multiple
  8952. * crtcs, we don't keep track of the new mode for more than one crtc.
  8953. * Hence simply check whether any bit is set in modeset_pipes in all the
  8954. * pieces of code that are not yet converted to deal with mutliple crtcs
  8955. * changing their mode at the same time. */
  8956. if (modeset_pipes) {
  8957. pipe_config = intel_modeset_pipe_config(crtc, fb, mode);
  8958. if (IS_ERR(pipe_config)) {
  8959. ret = PTR_ERR(pipe_config);
  8960. pipe_config = NULL;
  8961. goto out;
  8962. }
  8963. intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config,
  8964. "[modeset]");
  8965. to_intel_crtc(crtc)->new_config = pipe_config;
  8966. }
  8967. /*
  8968. * See if the config requires any additional preparation, e.g.
  8969. * to adjust global state with pipes off. We need to do this
  8970. * here so we can get the modeset_pipe updated config for the new
  8971. * mode set on this crtc. For other crtcs we need to use the
  8972. * adjusted_mode bits in the crtc directly.
  8973. */
  8974. if (IS_VALLEYVIEW(dev)) {
  8975. valleyview_modeset_global_pipes(dev, &prepare_pipes);
  8976. /* may have added more to prepare_pipes than we should */
  8977. prepare_pipes &= ~disable_pipes;
  8978. }
  8979. for_each_intel_crtc_masked(dev, disable_pipes, intel_crtc)
  8980. intel_crtc_disable(&intel_crtc->base);
  8981. for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) {
  8982. if (intel_crtc->base.enabled)
  8983. dev_priv->display.crtc_disable(&intel_crtc->base);
  8984. }
  8985. /* crtc->mode is already used by the ->mode_set callbacks, hence we need
  8986. * to set it here already despite that we pass it down the callchain.
  8987. */
  8988. if (modeset_pipes) {
  8989. crtc->mode = *mode;
  8990. /* mode_set/enable/disable functions rely on a correct pipe
  8991. * config. */
  8992. to_intel_crtc(crtc)->config = *pipe_config;
  8993. to_intel_crtc(crtc)->new_config = &to_intel_crtc(crtc)->config;
  8994. /*
  8995. * Calculate and store various constants which
  8996. * are later needed by vblank and swap-completion
  8997. * timestamping. They are derived from true hwmode.
  8998. */
  8999. drm_calc_timestamping_constants(crtc,
  9000. &pipe_config->adjusted_mode);
  9001. }
  9002. /* Only after disabling all output pipelines that will be changed can we
  9003. * update the the output configuration. */
  9004. intel_modeset_update_state(dev, prepare_pipes);
  9005. if (dev_priv->display.modeset_global_resources)
  9006. dev_priv->display.modeset_global_resources(dev);
  9007. /* Set up the DPLL and any encoders state that needs to adjust or depend
  9008. * on the DPLL.
  9009. */
  9010. for_each_intel_crtc_masked(dev, modeset_pipes, intel_crtc) {
  9011. struct drm_framebuffer *old_fb;
  9012. struct drm_i915_gem_object *old_obj = NULL;
  9013. struct drm_i915_gem_object *obj =
  9014. to_intel_framebuffer(fb)->obj;
  9015. mutex_lock(&dev->struct_mutex);
  9016. ret = intel_pin_and_fence_fb_obj(dev,
  9017. obj,
  9018. NULL);
  9019. if (ret != 0) {
  9020. DRM_ERROR("pin & fence failed\n");
  9021. mutex_unlock(&dev->struct_mutex);
  9022. goto done;
  9023. }
  9024. old_fb = crtc->primary->fb;
  9025. if (old_fb) {
  9026. old_obj = to_intel_framebuffer(old_fb)->obj;
  9027. intel_unpin_fb_obj(old_obj);
  9028. }
  9029. i915_gem_track_fb(old_obj, obj,
  9030. INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe));
  9031. mutex_unlock(&dev->struct_mutex);
  9032. crtc->primary->fb = fb;
  9033. crtc->x = x;
  9034. crtc->y = y;
  9035. ret = dev_priv->display.crtc_mode_set(&intel_crtc->base,
  9036. x, y, fb);
  9037. if (ret)
  9038. goto done;
  9039. }
  9040. /* Now enable the clocks, plane, pipe, and connectors that we set up. */
  9041. for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) {
  9042. update_scanline_offset(intel_crtc);
  9043. dev_priv->display.crtc_enable(&intel_crtc->base);
  9044. }
  9045. /* FIXME: add subpixel order */
  9046. done:
  9047. if (ret && crtc->enabled)
  9048. crtc->mode = *saved_mode;
  9049. out:
  9050. kfree(pipe_config);
  9051. kfree(saved_mode);
  9052. return ret;
  9053. }
  9054. static int intel_set_mode(struct drm_crtc *crtc,
  9055. struct drm_display_mode *mode,
  9056. int x, int y, struct drm_framebuffer *fb)
  9057. {
  9058. int ret;
  9059. ret = __intel_set_mode(crtc, mode, x, y, fb);
  9060. if (ret == 0)
  9061. intel_modeset_check_state(crtc->dev);
  9062. return ret;
  9063. }
  9064. void intel_crtc_restore_mode(struct drm_crtc *crtc)
  9065. {
  9066. intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y, crtc->primary->fb);
  9067. }
  9068. #undef for_each_intel_crtc_masked
  9069. static void intel_set_config_free(struct intel_set_config *config)
  9070. {
  9071. if (!config)
  9072. return;
  9073. kfree(config->save_connector_encoders);
  9074. kfree(config->save_encoder_crtcs);
  9075. kfree(config->save_crtc_enabled);
  9076. kfree(config);
  9077. }
  9078. static int intel_set_config_save_state(struct drm_device *dev,
  9079. struct intel_set_config *config)
  9080. {
  9081. struct drm_crtc *crtc;
  9082. struct drm_encoder *encoder;
  9083. struct drm_connector *connector;
  9084. int count;
  9085. config->save_crtc_enabled =
  9086. kcalloc(dev->mode_config.num_crtc,
  9087. sizeof(bool), GFP_KERNEL);
  9088. if (!config->save_crtc_enabled)
  9089. return -ENOMEM;
  9090. config->save_encoder_crtcs =
  9091. kcalloc(dev->mode_config.num_encoder,
  9092. sizeof(struct drm_crtc *), GFP_KERNEL);
  9093. if (!config->save_encoder_crtcs)
  9094. return -ENOMEM;
  9095. config->save_connector_encoders =
  9096. kcalloc(dev->mode_config.num_connector,
  9097. sizeof(struct drm_encoder *), GFP_KERNEL);
  9098. if (!config->save_connector_encoders)
  9099. return -ENOMEM;
  9100. /* Copy data. Note that driver private data is not affected.
  9101. * Should anything bad happen only the expected state is
  9102. * restored, not the drivers personal bookkeeping.
  9103. */
  9104. count = 0;
  9105. for_each_crtc(dev, crtc) {
  9106. config->save_crtc_enabled[count++] = crtc->enabled;
  9107. }
  9108. count = 0;
  9109. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  9110. config->save_encoder_crtcs[count++] = encoder->crtc;
  9111. }
  9112. count = 0;
  9113. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  9114. config->save_connector_encoders[count++] = connector->encoder;
  9115. }
  9116. return 0;
  9117. }
  9118. static void intel_set_config_restore_state(struct drm_device *dev,
  9119. struct intel_set_config *config)
  9120. {
  9121. struct intel_crtc *crtc;
  9122. struct intel_encoder *encoder;
  9123. struct intel_connector *connector;
  9124. int count;
  9125. count = 0;
  9126. for_each_intel_crtc(dev, crtc) {
  9127. crtc->new_enabled = config->save_crtc_enabled[count++];
  9128. if (crtc->new_enabled)
  9129. crtc->new_config = &crtc->config;
  9130. else
  9131. crtc->new_config = NULL;
  9132. }
  9133. count = 0;
  9134. list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) {
  9135. encoder->new_crtc =
  9136. to_intel_crtc(config->save_encoder_crtcs[count++]);
  9137. }
  9138. count = 0;
  9139. list_for_each_entry(connector, &dev->mode_config.connector_list, base.head) {
  9140. connector->new_encoder =
  9141. to_intel_encoder(config->save_connector_encoders[count++]);
  9142. }
  9143. }
  9144. static bool
  9145. is_crtc_connector_off(struct drm_mode_set *set)
  9146. {
  9147. int i;
  9148. if (set->num_connectors == 0)
  9149. return false;
  9150. if (WARN_ON(set->connectors == NULL))
  9151. return false;
  9152. for (i = 0; i < set->num_connectors; i++)
  9153. if (set->connectors[i]->encoder &&
  9154. set->connectors[i]->encoder->crtc == set->crtc &&
  9155. set->connectors[i]->dpms != DRM_MODE_DPMS_ON)
  9156. return true;
  9157. return false;
  9158. }
  9159. static void
  9160. intel_set_config_compute_mode_changes(struct drm_mode_set *set,
  9161. struct intel_set_config *config)
  9162. {
  9163. /* We should be able to check here if the fb has the same properties
  9164. * and then just flip_or_move it */
  9165. if (is_crtc_connector_off(set)) {
  9166. config->mode_changed = true;
  9167. } else if (set->crtc->primary->fb != set->fb) {
  9168. /*
  9169. * If we have no fb, we can only flip as long as the crtc is
  9170. * active, otherwise we need a full mode set. The crtc may
  9171. * be active if we've only disabled the primary plane, or
  9172. * in fastboot situations.
  9173. */
  9174. if (set->crtc->primary->fb == NULL) {
  9175. struct intel_crtc *intel_crtc =
  9176. to_intel_crtc(set->crtc);
  9177. if (intel_crtc->active) {
  9178. DRM_DEBUG_KMS("crtc has no fb, will flip\n");
  9179. config->fb_changed = true;
  9180. } else {
  9181. DRM_DEBUG_KMS("inactive crtc, full mode set\n");
  9182. config->mode_changed = true;
  9183. }
  9184. } else if (set->fb == NULL) {
  9185. config->mode_changed = true;
  9186. } else if (set->fb->pixel_format !=
  9187. set->crtc->primary->fb->pixel_format) {
  9188. config->mode_changed = true;
  9189. } else {
  9190. config->fb_changed = true;
  9191. }
  9192. }
  9193. if (set->fb && (set->x != set->crtc->x || set->y != set->crtc->y))
  9194. config->fb_changed = true;
  9195. if (set->mode && !drm_mode_equal(set->mode, &set->crtc->mode)) {
  9196. DRM_DEBUG_KMS("modes are different, full mode set\n");
  9197. drm_mode_debug_printmodeline(&set->crtc->mode);
  9198. drm_mode_debug_printmodeline(set->mode);
  9199. config->mode_changed = true;
  9200. }
  9201. DRM_DEBUG_KMS("computed changes for [CRTC:%d], mode_changed=%d, fb_changed=%d\n",
  9202. set->crtc->base.id, config->mode_changed, config->fb_changed);
  9203. }
  9204. static int
  9205. intel_modeset_stage_output_state(struct drm_device *dev,
  9206. struct drm_mode_set *set,
  9207. struct intel_set_config *config)
  9208. {
  9209. struct intel_connector *connector;
  9210. struct intel_encoder *encoder;
  9211. struct intel_crtc *crtc;
  9212. int ro;
  9213. /* The upper layers ensure that we either disable a crtc or have a list
  9214. * of connectors. For paranoia, double-check this. */
  9215. WARN_ON(!set->fb && (set->num_connectors != 0));
  9216. WARN_ON(set->fb && (set->num_connectors == 0));
  9217. list_for_each_entry(connector, &dev->mode_config.connector_list,
  9218. base.head) {
  9219. /* Otherwise traverse passed in connector list and get encoders
  9220. * for them. */
  9221. for (ro = 0; ro < set->num_connectors; ro++) {
  9222. if (set->connectors[ro] == &connector->base) {
  9223. connector->new_encoder = connector->encoder;
  9224. break;
  9225. }
  9226. }
  9227. /* If we disable the crtc, disable all its connectors. Also, if
  9228. * the connector is on the changing crtc but not on the new
  9229. * connector list, disable it. */
  9230. if ((!set->fb || ro == set->num_connectors) &&
  9231. connector->base.encoder &&
  9232. connector->base.encoder->crtc == set->crtc) {
  9233. connector->new_encoder = NULL;
  9234. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n",
  9235. connector->base.base.id,
  9236. connector->base.name);
  9237. }
  9238. if (&connector->new_encoder->base != connector->base.encoder) {
  9239. DRM_DEBUG_KMS("encoder changed, full mode switch\n");
  9240. config->mode_changed = true;
  9241. }
  9242. }
  9243. /* connector->new_encoder is now updated for all connectors. */
  9244. /* Update crtc of enabled connectors. */
  9245. list_for_each_entry(connector, &dev->mode_config.connector_list,
  9246. base.head) {
  9247. struct drm_crtc *new_crtc;
  9248. if (!connector->new_encoder)
  9249. continue;
  9250. new_crtc = connector->new_encoder->base.crtc;
  9251. for (ro = 0; ro < set->num_connectors; ro++) {
  9252. if (set->connectors[ro] == &connector->base)
  9253. new_crtc = set->crtc;
  9254. }
  9255. /* Make sure the new CRTC will work with the encoder */
  9256. if (!drm_encoder_crtc_ok(&connector->new_encoder->base,
  9257. new_crtc)) {
  9258. return -EINVAL;
  9259. }
  9260. connector->encoder->new_crtc = to_intel_crtc(new_crtc);
  9261. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n",
  9262. connector->base.base.id,
  9263. connector->base.name,
  9264. new_crtc->base.id);
  9265. }
  9266. /* Check for any encoders that needs to be disabled. */
  9267. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  9268. base.head) {
  9269. int num_connectors = 0;
  9270. list_for_each_entry(connector,
  9271. &dev->mode_config.connector_list,
  9272. base.head) {
  9273. if (connector->new_encoder == encoder) {
  9274. WARN_ON(!connector->new_encoder->new_crtc);
  9275. num_connectors++;
  9276. }
  9277. }
  9278. if (num_connectors == 0)
  9279. encoder->new_crtc = NULL;
  9280. else if (num_connectors > 1)
  9281. return -EINVAL;
  9282. /* Only now check for crtc changes so we don't miss encoders
  9283. * that will be disabled. */
  9284. if (&encoder->new_crtc->base != encoder->base.crtc) {
  9285. DRM_DEBUG_KMS("crtc changed, full mode switch\n");
  9286. config->mode_changed = true;
  9287. }
  9288. }
  9289. /* Now we've also updated encoder->new_crtc for all encoders. */
  9290. for_each_intel_crtc(dev, crtc) {
  9291. crtc->new_enabled = false;
  9292. list_for_each_entry(encoder,
  9293. &dev->mode_config.encoder_list,
  9294. base.head) {
  9295. if (encoder->new_crtc == crtc) {
  9296. crtc->new_enabled = true;
  9297. break;
  9298. }
  9299. }
  9300. if (crtc->new_enabled != crtc->base.enabled) {
  9301. DRM_DEBUG_KMS("crtc %sabled, full mode switch\n",
  9302. crtc->new_enabled ? "en" : "dis");
  9303. config->mode_changed = true;
  9304. }
  9305. if (crtc->new_enabled)
  9306. crtc->new_config = &crtc->config;
  9307. else
  9308. crtc->new_config = NULL;
  9309. }
  9310. return 0;
  9311. }
  9312. static void disable_crtc_nofb(struct intel_crtc *crtc)
  9313. {
  9314. struct drm_device *dev = crtc->base.dev;
  9315. struct intel_encoder *encoder;
  9316. struct intel_connector *connector;
  9317. DRM_DEBUG_KMS("Trying to restore without FB -> disabling pipe %c\n",
  9318. pipe_name(crtc->pipe));
  9319. list_for_each_entry(connector, &dev->mode_config.connector_list, base.head) {
  9320. if (connector->new_encoder &&
  9321. connector->new_encoder->new_crtc == crtc)
  9322. connector->new_encoder = NULL;
  9323. }
  9324. list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) {
  9325. if (encoder->new_crtc == crtc)
  9326. encoder->new_crtc = NULL;
  9327. }
  9328. crtc->new_enabled = false;
  9329. crtc->new_config = NULL;
  9330. }
  9331. static int intel_crtc_set_config(struct drm_mode_set *set)
  9332. {
  9333. struct drm_device *dev;
  9334. struct drm_mode_set save_set;
  9335. struct intel_set_config *config;
  9336. int ret;
  9337. BUG_ON(!set);
  9338. BUG_ON(!set->crtc);
  9339. BUG_ON(!set->crtc->helper_private);
  9340. /* Enforce sane interface api - has been abused by the fb helper. */
  9341. BUG_ON(!set->mode && set->fb);
  9342. BUG_ON(set->fb && set->num_connectors == 0);
  9343. if (set->fb) {
  9344. DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n",
  9345. set->crtc->base.id, set->fb->base.id,
  9346. (int)set->num_connectors, set->x, set->y);
  9347. } else {
  9348. DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set->crtc->base.id);
  9349. }
  9350. dev = set->crtc->dev;
  9351. ret = -ENOMEM;
  9352. config = kzalloc(sizeof(*config), GFP_KERNEL);
  9353. if (!config)
  9354. goto out_config;
  9355. ret = intel_set_config_save_state(dev, config);
  9356. if (ret)
  9357. goto out_config;
  9358. save_set.crtc = set->crtc;
  9359. save_set.mode = &set->crtc->mode;
  9360. save_set.x = set->crtc->x;
  9361. save_set.y = set->crtc->y;
  9362. save_set.fb = set->crtc->primary->fb;
  9363. /* Compute whether we need a full modeset, only an fb base update or no
  9364. * change at all. In the future we might also check whether only the
  9365. * mode changed, e.g. for LVDS where we only change the panel fitter in
  9366. * such cases. */
  9367. intel_set_config_compute_mode_changes(set, config);
  9368. ret = intel_modeset_stage_output_state(dev, set, config);
  9369. if (ret)
  9370. goto fail;
  9371. if (config->mode_changed) {
  9372. ret = intel_set_mode(set->crtc, set->mode,
  9373. set->x, set->y, set->fb);
  9374. } else if (config->fb_changed) {
  9375. struct drm_i915_private *dev_priv = dev->dev_private;
  9376. struct intel_crtc *intel_crtc = to_intel_crtc(set->crtc);
  9377. intel_crtc_wait_for_pending_flips(set->crtc);
  9378. ret = intel_pipe_set_base(set->crtc,
  9379. set->x, set->y, set->fb);
  9380. /*
  9381. * We need to make sure the primary plane is re-enabled if it
  9382. * has previously been turned off.
  9383. */
  9384. if (!intel_crtc->primary_enabled && ret == 0) {
  9385. WARN_ON(!intel_crtc->active);
  9386. intel_enable_primary_hw_plane(dev_priv, intel_crtc->plane,
  9387. intel_crtc->pipe);
  9388. }
  9389. /*
  9390. * In the fastboot case this may be our only check of the
  9391. * state after boot. It would be better to only do it on
  9392. * the first update, but we don't have a nice way of doing that
  9393. * (and really, set_config isn't used much for high freq page
  9394. * flipping, so increasing its cost here shouldn't be a big
  9395. * deal).
  9396. */
  9397. if (i915.fastboot && ret == 0)
  9398. intel_modeset_check_state(set->crtc->dev);
  9399. }
  9400. if (ret) {
  9401. DRM_DEBUG_KMS("failed to set mode on [CRTC:%d], err = %d\n",
  9402. set->crtc->base.id, ret);
  9403. fail:
  9404. intel_set_config_restore_state(dev, config);
  9405. /*
  9406. * HACK: if the pipe was on, but we didn't have a framebuffer,
  9407. * force the pipe off to avoid oopsing in the modeset code
  9408. * due to fb==NULL. This should only happen during boot since
  9409. * we don't yet reconstruct the FB from the hardware state.
  9410. */
  9411. if (to_intel_crtc(save_set.crtc)->new_enabled && !save_set.fb)
  9412. disable_crtc_nofb(to_intel_crtc(save_set.crtc));
  9413. /* Try to restore the config */
  9414. if (config->mode_changed &&
  9415. intel_set_mode(save_set.crtc, save_set.mode,
  9416. save_set.x, save_set.y, save_set.fb))
  9417. DRM_ERROR("failed to restore config after modeset failure\n");
  9418. }
  9419. out_config:
  9420. intel_set_config_free(config);
  9421. return ret;
  9422. }
  9423. static const struct drm_crtc_funcs intel_crtc_funcs = {
  9424. .gamma_set = intel_crtc_gamma_set,
  9425. .set_config = intel_crtc_set_config,
  9426. .destroy = intel_crtc_destroy,
  9427. .page_flip = intel_crtc_page_flip,
  9428. };
  9429. static void intel_cpu_pll_init(struct drm_device *dev)
  9430. {
  9431. if (HAS_DDI(dev))
  9432. intel_ddi_pll_init(dev);
  9433. }
  9434. static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private *dev_priv,
  9435. struct intel_shared_dpll *pll,
  9436. struct intel_dpll_hw_state *hw_state)
  9437. {
  9438. uint32_t val;
  9439. val = I915_READ(PCH_DPLL(pll->id));
  9440. hw_state->dpll = val;
  9441. hw_state->fp0 = I915_READ(PCH_FP0(pll->id));
  9442. hw_state->fp1 = I915_READ(PCH_FP1(pll->id));
  9443. return val & DPLL_VCO_ENABLE;
  9444. }
  9445. static void ibx_pch_dpll_mode_set(struct drm_i915_private *dev_priv,
  9446. struct intel_shared_dpll *pll)
  9447. {
  9448. I915_WRITE(PCH_FP0(pll->id), pll->hw_state.fp0);
  9449. I915_WRITE(PCH_FP1(pll->id), pll->hw_state.fp1);
  9450. }
  9451. static void ibx_pch_dpll_enable(struct drm_i915_private *dev_priv,
  9452. struct intel_shared_dpll *pll)
  9453. {
  9454. /* PCH refclock must be enabled first */
  9455. ibx_assert_pch_refclk_enabled(dev_priv);
  9456. I915_WRITE(PCH_DPLL(pll->id), pll->hw_state.dpll);
  9457. /* Wait for the clocks to stabilize. */
  9458. POSTING_READ(PCH_DPLL(pll->id));
  9459. udelay(150);
  9460. /* The pixel multiplier can only be updated once the
  9461. * DPLL is enabled and the clocks are stable.
  9462. *
  9463. * So write it again.
  9464. */
  9465. I915_WRITE(PCH_DPLL(pll->id), pll->hw_state.dpll);
  9466. POSTING_READ(PCH_DPLL(pll->id));
  9467. udelay(200);
  9468. }
  9469. static void ibx_pch_dpll_disable(struct drm_i915_private *dev_priv,
  9470. struct intel_shared_dpll *pll)
  9471. {
  9472. struct drm_device *dev = dev_priv->dev;
  9473. struct intel_crtc *crtc;
  9474. /* Make sure no transcoder isn't still depending on us. */
  9475. for_each_intel_crtc(dev, crtc) {
  9476. if (intel_crtc_to_shared_dpll(crtc) == pll)
  9477. assert_pch_transcoder_disabled(dev_priv, crtc->pipe);
  9478. }
  9479. I915_WRITE(PCH_DPLL(pll->id), 0);
  9480. POSTING_READ(PCH_DPLL(pll->id));
  9481. udelay(200);
  9482. }
  9483. static char *ibx_pch_dpll_names[] = {
  9484. "PCH DPLL A",
  9485. "PCH DPLL B",
  9486. };
  9487. static void ibx_pch_dpll_init(struct drm_device *dev)
  9488. {
  9489. struct drm_i915_private *dev_priv = dev->dev_private;
  9490. int i;
  9491. dev_priv->num_shared_dpll = 2;
  9492. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  9493. dev_priv->shared_dplls[i].id = i;
  9494. dev_priv->shared_dplls[i].name = ibx_pch_dpll_names[i];
  9495. dev_priv->shared_dplls[i].mode_set = ibx_pch_dpll_mode_set;
  9496. dev_priv->shared_dplls[i].enable = ibx_pch_dpll_enable;
  9497. dev_priv->shared_dplls[i].disable = ibx_pch_dpll_disable;
  9498. dev_priv->shared_dplls[i].get_hw_state =
  9499. ibx_pch_dpll_get_hw_state;
  9500. }
  9501. }
  9502. static void intel_shared_dpll_init(struct drm_device *dev)
  9503. {
  9504. struct drm_i915_private *dev_priv = dev->dev_private;
  9505. if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
  9506. ibx_pch_dpll_init(dev);
  9507. else
  9508. dev_priv->num_shared_dpll = 0;
  9509. BUG_ON(dev_priv->num_shared_dpll > I915_NUM_PLLS);
  9510. }
  9511. static int
  9512. intel_primary_plane_disable(struct drm_plane *plane)
  9513. {
  9514. struct drm_device *dev = plane->dev;
  9515. struct drm_i915_private *dev_priv = dev->dev_private;
  9516. struct intel_plane *intel_plane = to_intel_plane(plane);
  9517. struct intel_crtc *intel_crtc;
  9518. if (!plane->fb)
  9519. return 0;
  9520. BUG_ON(!plane->crtc);
  9521. intel_crtc = to_intel_crtc(plane->crtc);
  9522. /*
  9523. * Even though we checked plane->fb above, it's still possible that
  9524. * the primary plane has been implicitly disabled because the crtc
  9525. * coordinates given weren't visible, or because we detected
  9526. * that it was 100% covered by a sprite plane. Or, the CRTC may be
  9527. * off and we've set a fb, but haven't actually turned on the CRTC yet.
  9528. * In either case, we need to unpin the FB and let the fb pointer get
  9529. * updated, but otherwise we don't need to touch the hardware.
  9530. */
  9531. if (!intel_crtc->primary_enabled)
  9532. goto disable_unpin;
  9533. intel_crtc_wait_for_pending_flips(plane->crtc);
  9534. intel_disable_primary_hw_plane(dev_priv, intel_plane->plane,
  9535. intel_plane->pipe);
  9536. disable_unpin:
  9537. i915_gem_track_fb(to_intel_framebuffer(plane->fb)->obj, NULL,
  9538. INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe));
  9539. intel_unpin_fb_obj(to_intel_framebuffer(plane->fb)->obj);
  9540. plane->fb = NULL;
  9541. return 0;
  9542. }
  9543. static int
  9544. intel_primary_plane_setplane(struct drm_plane *plane, struct drm_crtc *crtc,
  9545. struct drm_framebuffer *fb, int crtc_x, int crtc_y,
  9546. unsigned int crtc_w, unsigned int crtc_h,
  9547. uint32_t src_x, uint32_t src_y,
  9548. uint32_t src_w, uint32_t src_h)
  9549. {
  9550. struct drm_device *dev = crtc->dev;
  9551. struct drm_i915_private *dev_priv = dev->dev_private;
  9552. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  9553. struct intel_plane *intel_plane = to_intel_plane(plane);
  9554. struct drm_i915_gem_object *obj, *old_obj = NULL;
  9555. struct drm_rect dest = {
  9556. /* integer pixels */
  9557. .x1 = crtc_x,
  9558. .y1 = crtc_y,
  9559. .x2 = crtc_x + crtc_w,
  9560. .y2 = crtc_y + crtc_h,
  9561. };
  9562. struct drm_rect src = {
  9563. /* 16.16 fixed point */
  9564. .x1 = src_x,
  9565. .y1 = src_y,
  9566. .x2 = src_x + src_w,
  9567. .y2 = src_y + src_h,
  9568. };
  9569. const struct drm_rect clip = {
  9570. /* integer pixels */
  9571. .x2 = intel_crtc->active ? intel_crtc->config.pipe_src_w : 0,
  9572. .y2 = intel_crtc->active ? intel_crtc->config.pipe_src_h : 0,
  9573. };
  9574. bool visible;
  9575. int ret;
  9576. ret = drm_plane_helper_check_update(plane, crtc, fb,
  9577. &src, &dest, &clip,
  9578. DRM_PLANE_HELPER_NO_SCALING,
  9579. DRM_PLANE_HELPER_NO_SCALING,
  9580. false, true, &visible);
  9581. if (ret)
  9582. return ret;
  9583. if (plane->fb)
  9584. old_obj = to_intel_framebuffer(plane->fb)->obj;
  9585. obj = to_intel_framebuffer(fb)->obj;
  9586. /*
  9587. * If the CRTC isn't enabled, we're just pinning the framebuffer,
  9588. * updating the fb pointer, and returning without touching the
  9589. * hardware. This allows us to later do a drmModeSetCrtc with fb=-1 to
  9590. * turn on the display with all planes setup as desired.
  9591. */
  9592. if (!crtc->enabled) {
  9593. /*
  9594. * If we already called setplane while the crtc was disabled,
  9595. * we may have an fb pinned; unpin it.
  9596. */
  9597. if (plane->fb)
  9598. intel_unpin_fb_obj(old_obj);
  9599. i915_gem_track_fb(old_obj, obj,
  9600. INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe));
  9601. /* Pin and return without programming hardware */
  9602. return intel_pin_and_fence_fb_obj(dev, obj, NULL);
  9603. }
  9604. intel_crtc_wait_for_pending_flips(crtc);
  9605. /*
  9606. * If clipping results in a non-visible primary plane, we'll disable
  9607. * the primary plane. Note that this is a bit different than what
  9608. * happens if userspace explicitly disables the plane by passing fb=0
  9609. * because plane->fb still gets set and pinned.
  9610. */
  9611. if (!visible) {
  9612. /*
  9613. * Try to pin the new fb first so that we can bail out if we
  9614. * fail.
  9615. */
  9616. if (plane->fb != fb) {
  9617. ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
  9618. if (ret)
  9619. return ret;
  9620. }
  9621. i915_gem_track_fb(old_obj, obj,
  9622. INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe));
  9623. if (intel_crtc->primary_enabled)
  9624. intel_disable_primary_hw_plane(dev_priv,
  9625. intel_plane->plane,
  9626. intel_plane->pipe);
  9627. if (plane->fb != fb)
  9628. if (plane->fb)
  9629. intel_unpin_fb_obj(old_obj);
  9630. return 0;
  9631. }
  9632. ret = intel_pipe_set_base(crtc, src.x1, src.y1, fb);
  9633. if (ret)
  9634. return ret;
  9635. if (!intel_crtc->primary_enabled)
  9636. intel_enable_primary_hw_plane(dev_priv, intel_crtc->plane,
  9637. intel_crtc->pipe);
  9638. return 0;
  9639. }
  9640. /* Common destruction function for both primary and cursor planes */
  9641. static void intel_plane_destroy(struct drm_plane *plane)
  9642. {
  9643. struct intel_plane *intel_plane = to_intel_plane(plane);
  9644. drm_plane_cleanup(plane);
  9645. kfree(intel_plane);
  9646. }
  9647. static const struct drm_plane_funcs intel_primary_plane_funcs = {
  9648. .update_plane = intel_primary_plane_setplane,
  9649. .disable_plane = intel_primary_plane_disable,
  9650. .destroy = intel_plane_destroy,
  9651. };
  9652. static struct drm_plane *intel_primary_plane_create(struct drm_device *dev,
  9653. int pipe)
  9654. {
  9655. struct intel_plane *primary;
  9656. const uint32_t *intel_primary_formats;
  9657. int num_formats;
  9658. primary = kzalloc(sizeof(*primary), GFP_KERNEL);
  9659. if (primary == NULL)
  9660. return NULL;
  9661. primary->can_scale = false;
  9662. primary->max_downscale = 1;
  9663. primary->pipe = pipe;
  9664. primary->plane = pipe;
  9665. if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4)
  9666. primary->plane = !pipe;
  9667. if (INTEL_INFO(dev)->gen <= 3) {
  9668. intel_primary_formats = intel_primary_formats_gen2;
  9669. num_formats = ARRAY_SIZE(intel_primary_formats_gen2);
  9670. } else {
  9671. intel_primary_formats = intel_primary_formats_gen4;
  9672. num_formats = ARRAY_SIZE(intel_primary_formats_gen4);
  9673. }
  9674. drm_universal_plane_init(dev, &primary->base, 0,
  9675. &intel_primary_plane_funcs,
  9676. intel_primary_formats, num_formats,
  9677. DRM_PLANE_TYPE_PRIMARY);
  9678. return &primary->base;
  9679. }
  9680. static int
  9681. intel_cursor_plane_disable(struct drm_plane *plane)
  9682. {
  9683. if (!plane->fb)
  9684. return 0;
  9685. BUG_ON(!plane->crtc);
  9686. return intel_crtc_cursor_set_obj(plane->crtc, NULL, 0, 0);
  9687. }
  9688. static int
  9689. intel_cursor_plane_update(struct drm_plane *plane, struct drm_crtc *crtc,
  9690. struct drm_framebuffer *fb, int crtc_x, int crtc_y,
  9691. unsigned int crtc_w, unsigned int crtc_h,
  9692. uint32_t src_x, uint32_t src_y,
  9693. uint32_t src_w, uint32_t src_h)
  9694. {
  9695. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  9696. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  9697. struct drm_i915_gem_object *obj = intel_fb->obj;
  9698. struct drm_rect dest = {
  9699. /* integer pixels */
  9700. .x1 = crtc_x,
  9701. .y1 = crtc_y,
  9702. .x2 = crtc_x + crtc_w,
  9703. .y2 = crtc_y + crtc_h,
  9704. };
  9705. struct drm_rect src = {
  9706. /* 16.16 fixed point */
  9707. .x1 = src_x,
  9708. .y1 = src_y,
  9709. .x2 = src_x + src_w,
  9710. .y2 = src_y + src_h,
  9711. };
  9712. const struct drm_rect clip = {
  9713. /* integer pixels */
  9714. .x2 = intel_crtc->config.pipe_src_w,
  9715. .y2 = intel_crtc->config.pipe_src_h,
  9716. };
  9717. bool visible;
  9718. int ret;
  9719. ret = drm_plane_helper_check_update(plane, crtc, fb,
  9720. &src, &dest, &clip,
  9721. DRM_PLANE_HELPER_NO_SCALING,
  9722. DRM_PLANE_HELPER_NO_SCALING,
  9723. true, true, &visible);
  9724. if (ret)
  9725. return ret;
  9726. crtc->cursor_x = crtc_x;
  9727. crtc->cursor_y = crtc_y;
  9728. if (fb != crtc->cursor->fb) {
  9729. return intel_crtc_cursor_set_obj(crtc, obj, crtc_w, crtc_h);
  9730. } else {
  9731. intel_crtc_update_cursor(crtc, visible);
  9732. return 0;
  9733. }
  9734. }
  9735. static const struct drm_plane_funcs intel_cursor_plane_funcs = {
  9736. .update_plane = intel_cursor_plane_update,
  9737. .disable_plane = intel_cursor_plane_disable,
  9738. .destroy = intel_plane_destroy,
  9739. };
  9740. static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev,
  9741. int pipe)
  9742. {
  9743. struct intel_plane *cursor;
  9744. cursor = kzalloc(sizeof(*cursor), GFP_KERNEL);
  9745. if (cursor == NULL)
  9746. return NULL;
  9747. cursor->can_scale = false;
  9748. cursor->max_downscale = 1;
  9749. cursor->pipe = pipe;
  9750. cursor->plane = pipe;
  9751. drm_universal_plane_init(dev, &cursor->base, 0,
  9752. &intel_cursor_plane_funcs,
  9753. intel_cursor_formats,
  9754. ARRAY_SIZE(intel_cursor_formats),
  9755. DRM_PLANE_TYPE_CURSOR);
  9756. return &cursor->base;
  9757. }
  9758. static void intel_crtc_init(struct drm_device *dev, int pipe)
  9759. {
  9760. struct drm_i915_private *dev_priv = dev->dev_private;
  9761. struct intel_crtc *intel_crtc;
  9762. struct drm_plane *primary = NULL;
  9763. struct drm_plane *cursor = NULL;
  9764. int i, ret;
  9765. intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL);
  9766. if (intel_crtc == NULL)
  9767. return;
  9768. primary = intel_primary_plane_create(dev, pipe);
  9769. if (!primary)
  9770. goto fail;
  9771. cursor = intel_cursor_plane_create(dev, pipe);
  9772. if (!cursor)
  9773. goto fail;
  9774. ret = drm_crtc_init_with_planes(dev, &intel_crtc->base, primary,
  9775. cursor, &intel_crtc_funcs);
  9776. if (ret)
  9777. goto fail;
  9778. drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256);
  9779. for (i = 0; i < 256; i++) {
  9780. intel_crtc->lut_r[i] = i;
  9781. intel_crtc->lut_g[i] = i;
  9782. intel_crtc->lut_b[i] = i;
  9783. }
  9784. /*
  9785. * On gen2/3 only plane A can do fbc, but the panel fitter and lvds port
  9786. * is hooked to pipe B. Hence we want plane A feeding pipe B.
  9787. */
  9788. intel_crtc->pipe = pipe;
  9789. intel_crtc->plane = pipe;
  9790. if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) {
  9791. DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
  9792. intel_crtc->plane = !pipe;
  9793. }
  9794. intel_crtc->cursor_base = ~0;
  9795. intel_crtc->cursor_cntl = ~0;
  9796. init_waitqueue_head(&intel_crtc->vbl_wait);
  9797. BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
  9798. dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL);
  9799. dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base;
  9800. dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base;
  9801. drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
  9802. WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe);
  9803. return;
  9804. fail:
  9805. if (primary)
  9806. drm_plane_cleanup(primary);
  9807. if (cursor)
  9808. drm_plane_cleanup(cursor);
  9809. kfree(intel_crtc);
  9810. }
  9811. enum pipe intel_get_pipe_from_connector(struct intel_connector *connector)
  9812. {
  9813. struct drm_encoder *encoder = connector->base.encoder;
  9814. struct drm_device *dev = connector->base.dev;
  9815. WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
  9816. if (!encoder)
  9817. return INVALID_PIPE;
  9818. return to_intel_crtc(encoder->crtc)->pipe;
  9819. }
  9820. int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data,
  9821. struct drm_file *file)
  9822. {
  9823. struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
  9824. struct drm_mode_object *drmmode_obj;
  9825. struct intel_crtc *crtc;
  9826. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  9827. return -ENODEV;
  9828. drmmode_obj = drm_mode_object_find(dev, pipe_from_crtc_id->crtc_id,
  9829. DRM_MODE_OBJECT_CRTC);
  9830. if (!drmmode_obj) {
  9831. DRM_ERROR("no such CRTC id\n");
  9832. return -ENOENT;
  9833. }
  9834. crtc = to_intel_crtc(obj_to_crtc(drmmode_obj));
  9835. pipe_from_crtc_id->pipe = crtc->pipe;
  9836. return 0;
  9837. }
  9838. static int intel_encoder_clones(struct intel_encoder *encoder)
  9839. {
  9840. struct drm_device *dev = encoder->base.dev;
  9841. struct intel_encoder *source_encoder;
  9842. int index_mask = 0;
  9843. int entry = 0;
  9844. list_for_each_entry(source_encoder,
  9845. &dev->mode_config.encoder_list, base.head) {
  9846. if (encoders_cloneable(encoder, source_encoder))
  9847. index_mask |= (1 << entry);
  9848. entry++;
  9849. }
  9850. return index_mask;
  9851. }
  9852. static bool has_edp_a(struct drm_device *dev)
  9853. {
  9854. struct drm_i915_private *dev_priv = dev->dev_private;
  9855. if (!IS_MOBILE(dev))
  9856. return false;
  9857. if ((I915_READ(DP_A) & DP_DETECTED) == 0)
  9858. return false;
  9859. if (IS_GEN5(dev) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE))
  9860. return false;
  9861. return true;
  9862. }
  9863. const char *intel_output_name(int output)
  9864. {
  9865. static const char *names[] = {
  9866. [INTEL_OUTPUT_UNUSED] = "Unused",
  9867. [INTEL_OUTPUT_ANALOG] = "Analog",
  9868. [INTEL_OUTPUT_DVO] = "DVO",
  9869. [INTEL_OUTPUT_SDVO] = "SDVO",
  9870. [INTEL_OUTPUT_LVDS] = "LVDS",
  9871. [INTEL_OUTPUT_TVOUT] = "TV",
  9872. [INTEL_OUTPUT_HDMI] = "HDMI",
  9873. [INTEL_OUTPUT_DISPLAYPORT] = "DisplayPort",
  9874. [INTEL_OUTPUT_EDP] = "eDP",
  9875. [INTEL_OUTPUT_DSI] = "DSI",
  9876. [INTEL_OUTPUT_UNKNOWN] = "Unknown",
  9877. };
  9878. if (output < 0 || output >= ARRAY_SIZE(names) || !names[output])
  9879. return "Invalid";
  9880. return names[output];
  9881. }
  9882. static bool intel_crt_present(struct drm_device *dev)
  9883. {
  9884. struct drm_i915_private *dev_priv = dev->dev_private;
  9885. if (IS_ULT(dev))
  9886. return false;
  9887. if (IS_CHERRYVIEW(dev))
  9888. return false;
  9889. if (IS_VALLEYVIEW(dev) && !dev_priv->vbt.int_crt_support)
  9890. return false;
  9891. return true;
  9892. }
  9893. static void intel_setup_outputs(struct drm_device *dev)
  9894. {
  9895. struct drm_i915_private *dev_priv = dev->dev_private;
  9896. struct intel_encoder *encoder;
  9897. bool dpd_is_edp = false;
  9898. intel_lvds_init(dev);
  9899. if (intel_crt_present(dev))
  9900. intel_crt_init(dev);
  9901. if (HAS_DDI(dev)) {
  9902. int found;
  9903. /* Haswell uses DDI functions to detect digital outputs */
  9904. found = I915_READ(DDI_BUF_CTL_A) & DDI_INIT_DISPLAY_DETECTED;
  9905. /* DDI A only supports eDP */
  9906. if (found)
  9907. intel_ddi_init(dev, PORT_A);
  9908. /* DDI B, C and D detection is indicated by the SFUSE_STRAP
  9909. * register */
  9910. found = I915_READ(SFUSE_STRAP);
  9911. if (found & SFUSE_STRAP_DDIB_DETECTED)
  9912. intel_ddi_init(dev, PORT_B);
  9913. if (found & SFUSE_STRAP_DDIC_DETECTED)
  9914. intel_ddi_init(dev, PORT_C);
  9915. if (found & SFUSE_STRAP_DDID_DETECTED)
  9916. intel_ddi_init(dev, PORT_D);
  9917. } else if (HAS_PCH_SPLIT(dev)) {
  9918. int found;
  9919. dpd_is_edp = intel_dp_is_edp(dev, PORT_D);
  9920. if (has_edp_a(dev))
  9921. intel_dp_init(dev, DP_A, PORT_A);
  9922. if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) {
  9923. /* PCH SDVOB multiplex with HDMIB */
  9924. found = intel_sdvo_init(dev, PCH_SDVOB, true);
  9925. if (!found)
  9926. intel_hdmi_init(dev, PCH_HDMIB, PORT_B);
  9927. if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
  9928. intel_dp_init(dev, PCH_DP_B, PORT_B);
  9929. }
  9930. if (I915_READ(PCH_HDMIC) & SDVO_DETECTED)
  9931. intel_hdmi_init(dev, PCH_HDMIC, PORT_C);
  9932. if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED)
  9933. intel_hdmi_init(dev, PCH_HDMID, PORT_D);
  9934. if (I915_READ(PCH_DP_C) & DP_DETECTED)
  9935. intel_dp_init(dev, PCH_DP_C, PORT_C);
  9936. if (I915_READ(PCH_DP_D) & DP_DETECTED)
  9937. intel_dp_init(dev, PCH_DP_D, PORT_D);
  9938. } else if (IS_VALLEYVIEW(dev)) {
  9939. if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIB) & SDVO_DETECTED) {
  9940. intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIB,
  9941. PORT_B);
  9942. if (I915_READ(VLV_DISPLAY_BASE + DP_B) & DP_DETECTED)
  9943. intel_dp_init(dev, VLV_DISPLAY_BASE + DP_B, PORT_B);
  9944. }
  9945. if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIC) & SDVO_DETECTED) {
  9946. intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIC,
  9947. PORT_C);
  9948. if (I915_READ(VLV_DISPLAY_BASE + DP_C) & DP_DETECTED)
  9949. intel_dp_init(dev, VLV_DISPLAY_BASE + DP_C, PORT_C);
  9950. }
  9951. if (IS_CHERRYVIEW(dev)) {
  9952. if (I915_READ(VLV_DISPLAY_BASE + CHV_HDMID) & SDVO_DETECTED) {
  9953. intel_hdmi_init(dev, VLV_DISPLAY_BASE + CHV_HDMID,
  9954. PORT_D);
  9955. if (I915_READ(VLV_DISPLAY_BASE + DP_D) & DP_DETECTED)
  9956. intel_dp_init(dev, VLV_DISPLAY_BASE + DP_D, PORT_D);
  9957. }
  9958. }
  9959. intel_dsi_init(dev);
  9960. } else if (SUPPORTS_DIGITAL_OUTPUTS(dev)) {
  9961. bool found = false;
  9962. if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
  9963. DRM_DEBUG_KMS("probing SDVOB\n");
  9964. found = intel_sdvo_init(dev, GEN3_SDVOB, true);
  9965. if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) {
  9966. DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
  9967. intel_hdmi_init(dev, GEN4_HDMIB, PORT_B);
  9968. }
  9969. if (!found && SUPPORTS_INTEGRATED_DP(dev))
  9970. intel_dp_init(dev, DP_B, PORT_B);
  9971. }
  9972. /* Before G4X SDVOC doesn't have its own detect register */
  9973. if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
  9974. DRM_DEBUG_KMS("probing SDVOC\n");
  9975. found = intel_sdvo_init(dev, GEN3_SDVOC, false);
  9976. }
  9977. if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) {
  9978. if (SUPPORTS_INTEGRATED_HDMI(dev)) {
  9979. DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
  9980. intel_hdmi_init(dev, GEN4_HDMIC, PORT_C);
  9981. }
  9982. if (SUPPORTS_INTEGRATED_DP(dev))
  9983. intel_dp_init(dev, DP_C, PORT_C);
  9984. }
  9985. if (SUPPORTS_INTEGRATED_DP(dev) &&
  9986. (I915_READ(DP_D) & DP_DETECTED))
  9987. intel_dp_init(dev, DP_D, PORT_D);
  9988. } else if (IS_GEN2(dev))
  9989. intel_dvo_init(dev);
  9990. if (SUPPORTS_TV(dev))
  9991. intel_tv_init(dev);
  9992. intel_edp_psr_init(dev);
  9993. list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) {
  9994. encoder->base.possible_crtcs = encoder->crtc_mask;
  9995. encoder->base.possible_clones =
  9996. intel_encoder_clones(encoder);
  9997. }
  9998. intel_init_pch_refclk(dev);
  9999. drm_helper_move_panel_connectors_to_head(dev);
  10000. }
  10001. static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
  10002. {
  10003. struct drm_device *dev = fb->dev;
  10004. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  10005. drm_framebuffer_cleanup(fb);
  10006. mutex_lock(&dev->struct_mutex);
  10007. WARN_ON(!intel_fb->obj->framebuffer_references--);
  10008. drm_gem_object_unreference(&intel_fb->obj->base);
  10009. mutex_unlock(&dev->struct_mutex);
  10010. kfree(intel_fb);
  10011. }
  10012. static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
  10013. struct drm_file *file,
  10014. unsigned int *handle)
  10015. {
  10016. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  10017. struct drm_i915_gem_object *obj = intel_fb->obj;
  10018. return drm_gem_handle_create(file, &obj->base, handle);
  10019. }
  10020. static const struct drm_framebuffer_funcs intel_fb_funcs = {
  10021. .destroy = intel_user_framebuffer_destroy,
  10022. .create_handle = intel_user_framebuffer_create_handle,
  10023. };
  10024. static int intel_framebuffer_init(struct drm_device *dev,
  10025. struct intel_framebuffer *intel_fb,
  10026. struct drm_mode_fb_cmd2 *mode_cmd,
  10027. struct drm_i915_gem_object *obj)
  10028. {
  10029. int aligned_height;
  10030. int pitch_limit;
  10031. int ret;
  10032. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  10033. if (obj->tiling_mode == I915_TILING_Y) {
  10034. DRM_DEBUG("hardware does not support tiling Y\n");
  10035. return -EINVAL;
  10036. }
  10037. if (mode_cmd->pitches[0] & 63) {
  10038. DRM_DEBUG("pitch (%d) must be at least 64 byte aligned\n",
  10039. mode_cmd->pitches[0]);
  10040. return -EINVAL;
  10041. }
  10042. if (INTEL_INFO(dev)->gen >= 5 && !IS_VALLEYVIEW(dev)) {
  10043. pitch_limit = 32*1024;
  10044. } else if (INTEL_INFO(dev)->gen >= 4) {
  10045. if (obj->tiling_mode)
  10046. pitch_limit = 16*1024;
  10047. else
  10048. pitch_limit = 32*1024;
  10049. } else if (INTEL_INFO(dev)->gen >= 3) {
  10050. if (obj->tiling_mode)
  10051. pitch_limit = 8*1024;
  10052. else
  10053. pitch_limit = 16*1024;
  10054. } else
  10055. /* XXX DSPC is limited to 4k tiled */
  10056. pitch_limit = 8*1024;
  10057. if (mode_cmd->pitches[0] > pitch_limit) {
  10058. DRM_DEBUG("%s pitch (%d) must be at less than %d\n",
  10059. obj->tiling_mode ? "tiled" : "linear",
  10060. mode_cmd->pitches[0], pitch_limit);
  10061. return -EINVAL;
  10062. }
  10063. if (obj->tiling_mode != I915_TILING_NONE &&
  10064. mode_cmd->pitches[0] != obj->stride) {
  10065. DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n",
  10066. mode_cmd->pitches[0], obj->stride);
  10067. return -EINVAL;
  10068. }
  10069. /* Reject formats not supported by any plane early. */
  10070. switch (mode_cmd->pixel_format) {
  10071. case DRM_FORMAT_C8:
  10072. case DRM_FORMAT_RGB565:
  10073. case DRM_FORMAT_XRGB8888:
  10074. case DRM_FORMAT_ARGB8888:
  10075. break;
  10076. case DRM_FORMAT_XRGB1555:
  10077. case DRM_FORMAT_ARGB1555:
  10078. if (INTEL_INFO(dev)->gen > 3) {
  10079. DRM_DEBUG("unsupported pixel format: %s\n",
  10080. drm_get_format_name(mode_cmd->pixel_format));
  10081. return -EINVAL;
  10082. }
  10083. break;
  10084. case DRM_FORMAT_XBGR8888:
  10085. case DRM_FORMAT_ABGR8888:
  10086. case DRM_FORMAT_XRGB2101010:
  10087. case DRM_FORMAT_ARGB2101010:
  10088. case DRM_FORMAT_XBGR2101010:
  10089. case DRM_FORMAT_ABGR2101010:
  10090. if (INTEL_INFO(dev)->gen < 4) {
  10091. DRM_DEBUG("unsupported pixel format: %s\n",
  10092. drm_get_format_name(mode_cmd->pixel_format));
  10093. return -EINVAL;
  10094. }
  10095. break;
  10096. case DRM_FORMAT_YUYV:
  10097. case DRM_FORMAT_UYVY:
  10098. case DRM_FORMAT_YVYU:
  10099. case DRM_FORMAT_VYUY:
  10100. if (INTEL_INFO(dev)->gen < 5) {
  10101. DRM_DEBUG("unsupported pixel format: %s\n",
  10102. drm_get_format_name(mode_cmd->pixel_format));
  10103. return -EINVAL;
  10104. }
  10105. break;
  10106. default:
  10107. DRM_DEBUG("unsupported pixel format: %s\n",
  10108. drm_get_format_name(mode_cmd->pixel_format));
  10109. return -EINVAL;
  10110. }
  10111. /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
  10112. if (mode_cmd->offsets[0] != 0)
  10113. return -EINVAL;
  10114. aligned_height = intel_align_height(dev, mode_cmd->height,
  10115. obj->tiling_mode);
  10116. /* FIXME drm helper for size checks (especially planar formats)? */
  10117. if (obj->base.size < aligned_height * mode_cmd->pitches[0])
  10118. return -EINVAL;
  10119. drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd);
  10120. intel_fb->obj = obj;
  10121. intel_fb->obj->framebuffer_references++;
  10122. ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs);
  10123. if (ret) {
  10124. DRM_ERROR("framebuffer init failed %d\n", ret);
  10125. return ret;
  10126. }
  10127. return 0;
  10128. }
  10129. static struct drm_framebuffer *
  10130. intel_user_framebuffer_create(struct drm_device *dev,
  10131. struct drm_file *filp,
  10132. struct drm_mode_fb_cmd2 *mode_cmd)
  10133. {
  10134. struct drm_i915_gem_object *obj;
  10135. obj = to_intel_bo(drm_gem_object_lookup(dev, filp,
  10136. mode_cmd->handles[0]));
  10137. if (&obj->base == NULL)
  10138. return ERR_PTR(-ENOENT);
  10139. return intel_framebuffer_create(dev, mode_cmd, obj);
  10140. }
  10141. #ifndef CONFIG_DRM_I915_FBDEV
  10142. static inline void intel_fbdev_output_poll_changed(struct drm_device *dev)
  10143. {
  10144. }
  10145. #endif
  10146. static const struct drm_mode_config_funcs intel_mode_funcs = {
  10147. .fb_create = intel_user_framebuffer_create,
  10148. .output_poll_changed = intel_fbdev_output_poll_changed,
  10149. };
  10150. /* Set up chip specific display functions */
  10151. static void intel_init_display(struct drm_device *dev)
  10152. {
  10153. struct drm_i915_private *dev_priv = dev->dev_private;
  10154. if (HAS_PCH_SPLIT(dev) || IS_G4X(dev))
  10155. dev_priv->display.find_dpll = g4x_find_best_dpll;
  10156. else if (IS_CHERRYVIEW(dev))
  10157. dev_priv->display.find_dpll = chv_find_best_dpll;
  10158. else if (IS_VALLEYVIEW(dev))
  10159. dev_priv->display.find_dpll = vlv_find_best_dpll;
  10160. else if (IS_PINEVIEW(dev))
  10161. dev_priv->display.find_dpll = pnv_find_best_dpll;
  10162. else
  10163. dev_priv->display.find_dpll = i9xx_find_best_dpll;
  10164. if (HAS_DDI(dev)) {
  10165. dev_priv->display.get_pipe_config = haswell_get_pipe_config;
  10166. dev_priv->display.get_plane_config = ironlake_get_plane_config;
  10167. dev_priv->display.crtc_mode_set = haswell_crtc_mode_set;
  10168. dev_priv->display.crtc_enable = haswell_crtc_enable;
  10169. dev_priv->display.crtc_disable = haswell_crtc_disable;
  10170. dev_priv->display.off = haswell_crtc_off;
  10171. dev_priv->display.update_primary_plane =
  10172. ironlake_update_primary_plane;
  10173. } else if (HAS_PCH_SPLIT(dev)) {
  10174. dev_priv->display.get_pipe_config = ironlake_get_pipe_config;
  10175. dev_priv->display.get_plane_config = ironlake_get_plane_config;
  10176. dev_priv->display.crtc_mode_set = ironlake_crtc_mode_set;
  10177. dev_priv->display.crtc_enable = ironlake_crtc_enable;
  10178. dev_priv->display.crtc_disable = ironlake_crtc_disable;
  10179. dev_priv->display.off = ironlake_crtc_off;
  10180. dev_priv->display.update_primary_plane =
  10181. ironlake_update_primary_plane;
  10182. } else if (IS_VALLEYVIEW(dev)) {
  10183. dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
  10184. dev_priv->display.get_plane_config = i9xx_get_plane_config;
  10185. dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set;
  10186. dev_priv->display.crtc_enable = valleyview_crtc_enable;
  10187. dev_priv->display.crtc_disable = i9xx_crtc_disable;
  10188. dev_priv->display.off = i9xx_crtc_off;
  10189. dev_priv->display.update_primary_plane =
  10190. i9xx_update_primary_plane;
  10191. } else {
  10192. dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
  10193. dev_priv->display.get_plane_config = i9xx_get_plane_config;
  10194. dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set;
  10195. dev_priv->display.crtc_enable = i9xx_crtc_enable;
  10196. dev_priv->display.crtc_disable = i9xx_crtc_disable;
  10197. dev_priv->display.off = i9xx_crtc_off;
  10198. dev_priv->display.update_primary_plane =
  10199. i9xx_update_primary_plane;
  10200. }
  10201. /* Returns the core display clock speed */
  10202. if (IS_VALLEYVIEW(dev))
  10203. dev_priv->display.get_display_clock_speed =
  10204. valleyview_get_display_clock_speed;
  10205. else if (IS_I945G(dev) || (IS_G33(dev) && !IS_PINEVIEW_M(dev)))
  10206. dev_priv->display.get_display_clock_speed =
  10207. i945_get_display_clock_speed;
  10208. else if (IS_I915G(dev))
  10209. dev_priv->display.get_display_clock_speed =
  10210. i915_get_display_clock_speed;
  10211. else if (IS_I945GM(dev) || IS_845G(dev))
  10212. dev_priv->display.get_display_clock_speed =
  10213. i9xx_misc_get_display_clock_speed;
  10214. else if (IS_PINEVIEW(dev))
  10215. dev_priv->display.get_display_clock_speed =
  10216. pnv_get_display_clock_speed;
  10217. else if (IS_I915GM(dev))
  10218. dev_priv->display.get_display_clock_speed =
  10219. i915gm_get_display_clock_speed;
  10220. else if (IS_I865G(dev))
  10221. dev_priv->display.get_display_clock_speed =
  10222. i865_get_display_clock_speed;
  10223. else if (IS_I85X(dev))
  10224. dev_priv->display.get_display_clock_speed =
  10225. i855_get_display_clock_speed;
  10226. else /* 852, 830 */
  10227. dev_priv->display.get_display_clock_speed =
  10228. i830_get_display_clock_speed;
  10229. if (HAS_PCH_SPLIT(dev)) {
  10230. if (IS_GEN5(dev)) {
  10231. dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
  10232. dev_priv->display.write_eld = ironlake_write_eld;
  10233. } else if (IS_GEN6(dev)) {
  10234. dev_priv->display.fdi_link_train = gen6_fdi_link_train;
  10235. dev_priv->display.write_eld = ironlake_write_eld;
  10236. dev_priv->display.modeset_global_resources =
  10237. snb_modeset_global_resources;
  10238. } else if (IS_IVYBRIDGE(dev)) {
  10239. /* FIXME: detect B0+ stepping and use auto training */
  10240. dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
  10241. dev_priv->display.write_eld = ironlake_write_eld;
  10242. dev_priv->display.modeset_global_resources =
  10243. ivb_modeset_global_resources;
  10244. } else if (IS_HASWELL(dev) || IS_GEN8(dev)) {
  10245. dev_priv->display.fdi_link_train = hsw_fdi_link_train;
  10246. dev_priv->display.write_eld = haswell_write_eld;
  10247. dev_priv->display.modeset_global_resources =
  10248. haswell_modeset_global_resources;
  10249. }
  10250. } else if (IS_G4X(dev)) {
  10251. dev_priv->display.write_eld = g4x_write_eld;
  10252. } else if (IS_VALLEYVIEW(dev)) {
  10253. dev_priv->display.modeset_global_resources =
  10254. valleyview_modeset_global_resources;
  10255. dev_priv->display.write_eld = ironlake_write_eld;
  10256. }
  10257. /* Default just returns -ENODEV to indicate unsupported */
  10258. dev_priv->display.queue_flip = intel_default_queue_flip;
  10259. switch (INTEL_INFO(dev)->gen) {
  10260. case 2:
  10261. dev_priv->display.queue_flip = intel_gen2_queue_flip;
  10262. break;
  10263. case 3:
  10264. dev_priv->display.queue_flip = intel_gen3_queue_flip;
  10265. break;
  10266. case 4:
  10267. case 5:
  10268. dev_priv->display.queue_flip = intel_gen4_queue_flip;
  10269. break;
  10270. case 6:
  10271. dev_priv->display.queue_flip = intel_gen6_queue_flip;
  10272. break;
  10273. case 7:
  10274. case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */
  10275. dev_priv->display.queue_flip = intel_gen7_queue_flip;
  10276. break;
  10277. }
  10278. intel_panel_init_backlight_funcs(dev);
  10279. }
  10280. /*
  10281. * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend,
  10282. * resume, or other times. This quirk makes sure that's the case for
  10283. * affected systems.
  10284. */
  10285. static void quirk_pipea_force(struct drm_device *dev)
  10286. {
  10287. struct drm_i915_private *dev_priv = dev->dev_private;
  10288. dev_priv->quirks |= QUIRK_PIPEA_FORCE;
  10289. DRM_INFO("applying pipe a force quirk\n");
  10290. }
  10291. /*
  10292. * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
  10293. */
  10294. static void quirk_ssc_force_disable(struct drm_device *dev)
  10295. {
  10296. struct drm_i915_private *dev_priv = dev->dev_private;
  10297. dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE;
  10298. DRM_INFO("applying lvds SSC disable quirk\n");
  10299. }
  10300. /*
  10301. * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
  10302. * brightness value
  10303. */
  10304. static void quirk_invert_brightness(struct drm_device *dev)
  10305. {
  10306. struct drm_i915_private *dev_priv = dev->dev_private;
  10307. dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS;
  10308. DRM_INFO("applying inverted panel brightness quirk\n");
  10309. }
  10310. struct intel_quirk {
  10311. int device;
  10312. int subsystem_vendor;
  10313. int subsystem_device;
  10314. void (*hook)(struct drm_device *dev);
  10315. };
  10316. /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
  10317. struct intel_dmi_quirk {
  10318. void (*hook)(struct drm_device *dev);
  10319. const struct dmi_system_id (*dmi_id_list)[];
  10320. };
  10321. static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
  10322. {
  10323. DRM_INFO("Backlight polarity reversed on %s\n", id->ident);
  10324. return 1;
  10325. }
  10326. static const struct intel_dmi_quirk intel_dmi_quirks[] = {
  10327. {
  10328. .dmi_id_list = &(const struct dmi_system_id[]) {
  10329. {
  10330. .callback = intel_dmi_reverse_brightness,
  10331. .ident = "NCR Corporation",
  10332. .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
  10333. DMI_MATCH(DMI_PRODUCT_NAME, ""),
  10334. },
  10335. },
  10336. { } /* terminating entry */
  10337. },
  10338. .hook = quirk_invert_brightness,
  10339. },
  10340. };
  10341. static struct intel_quirk intel_quirks[] = {
  10342. /* HP Mini needs pipe A force quirk (LP: #322104) */
  10343. { 0x27ae, 0x103c, 0x361a, quirk_pipea_force },
  10344. /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
  10345. { 0x2592, 0x1179, 0x0001, quirk_pipea_force },
  10346. /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
  10347. { 0x2782, 0x17aa, 0x201a, quirk_pipea_force },
  10348. /* Lenovo U160 cannot use SSC on LVDS */
  10349. { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable },
  10350. /* Sony Vaio Y cannot use SSC on LVDS */
  10351. { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable },
  10352. /* Acer Aspire 5734Z must invert backlight brightness */
  10353. { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness },
  10354. /* Acer/eMachines G725 */
  10355. { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness },
  10356. /* Acer/eMachines e725 */
  10357. { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness },
  10358. /* Acer/Packard Bell NCL20 */
  10359. { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness },
  10360. /* Acer Aspire 4736Z */
  10361. { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness },
  10362. /* Acer Aspire 5336 */
  10363. { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness },
  10364. };
  10365. static void intel_init_quirks(struct drm_device *dev)
  10366. {
  10367. struct pci_dev *d = dev->pdev;
  10368. int i;
  10369. for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) {
  10370. struct intel_quirk *q = &intel_quirks[i];
  10371. if (d->device == q->device &&
  10372. (d->subsystem_vendor == q->subsystem_vendor ||
  10373. q->subsystem_vendor == PCI_ANY_ID) &&
  10374. (d->subsystem_device == q->subsystem_device ||
  10375. q->subsystem_device == PCI_ANY_ID))
  10376. q->hook(dev);
  10377. }
  10378. for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) {
  10379. if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0)
  10380. intel_dmi_quirks[i].hook(dev);
  10381. }
  10382. }
  10383. /* Disable the VGA plane that we never use */
  10384. static void i915_disable_vga(struct drm_device *dev)
  10385. {
  10386. struct drm_i915_private *dev_priv = dev->dev_private;
  10387. u8 sr1;
  10388. u32 vga_reg = i915_vgacntrl_reg(dev);
  10389. /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
  10390. vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
  10391. outb(SR01, VGA_SR_INDEX);
  10392. sr1 = inb(VGA_SR_DATA);
  10393. outb(sr1 | 1<<5, VGA_SR_DATA);
  10394. vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
  10395. udelay(300);
  10396. I915_WRITE(vga_reg, VGA_DISP_DISABLE);
  10397. POSTING_READ(vga_reg);
  10398. }
  10399. void intel_modeset_init_hw(struct drm_device *dev)
  10400. {
  10401. intel_prepare_ddi(dev);
  10402. intel_init_clock_gating(dev);
  10403. intel_reset_dpio(dev);
  10404. intel_enable_gt_powersave(dev);
  10405. }
  10406. void intel_modeset_suspend_hw(struct drm_device *dev)
  10407. {
  10408. intel_suspend_hw(dev);
  10409. }
  10410. void intel_modeset_init(struct drm_device *dev)
  10411. {
  10412. struct drm_i915_private *dev_priv = dev->dev_private;
  10413. int sprite, ret;
  10414. enum pipe pipe;
  10415. struct intel_crtc *crtc;
  10416. drm_mode_config_init(dev);
  10417. dev->mode_config.min_width = 0;
  10418. dev->mode_config.min_height = 0;
  10419. dev->mode_config.preferred_depth = 24;
  10420. dev->mode_config.prefer_shadow = 1;
  10421. dev->mode_config.funcs = &intel_mode_funcs;
  10422. intel_init_quirks(dev);
  10423. intel_init_pm(dev);
  10424. if (INTEL_INFO(dev)->num_pipes == 0)
  10425. return;
  10426. intel_init_display(dev);
  10427. if (IS_GEN2(dev)) {
  10428. dev->mode_config.max_width = 2048;
  10429. dev->mode_config.max_height = 2048;
  10430. } else if (IS_GEN3(dev)) {
  10431. dev->mode_config.max_width = 4096;
  10432. dev->mode_config.max_height = 4096;
  10433. } else {
  10434. dev->mode_config.max_width = 8192;
  10435. dev->mode_config.max_height = 8192;
  10436. }
  10437. if (IS_GEN2(dev)) {
  10438. dev->mode_config.cursor_width = GEN2_CURSOR_WIDTH;
  10439. dev->mode_config.cursor_height = GEN2_CURSOR_HEIGHT;
  10440. } else {
  10441. dev->mode_config.cursor_width = MAX_CURSOR_WIDTH;
  10442. dev->mode_config.cursor_height = MAX_CURSOR_HEIGHT;
  10443. }
  10444. dev->mode_config.fb_base = dev_priv->gtt.mappable_base;
  10445. DRM_DEBUG_KMS("%d display pipe%s available.\n",
  10446. INTEL_INFO(dev)->num_pipes,
  10447. INTEL_INFO(dev)->num_pipes > 1 ? "s" : "");
  10448. for_each_pipe(pipe) {
  10449. intel_crtc_init(dev, pipe);
  10450. for_each_sprite(pipe, sprite) {
  10451. ret = intel_plane_init(dev, pipe, sprite);
  10452. if (ret)
  10453. DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n",
  10454. pipe_name(pipe), sprite_name(pipe, sprite), ret);
  10455. }
  10456. }
  10457. intel_init_dpio(dev);
  10458. intel_reset_dpio(dev);
  10459. intel_cpu_pll_init(dev);
  10460. intel_shared_dpll_init(dev);
  10461. /* Just disable it once at startup */
  10462. i915_disable_vga(dev);
  10463. intel_setup_outputs(dev);
  10464. /* Just in case the BIOS is doing something questionable. */
  10465. intel_disable_fbc(dev);
  10466. drm_modeset_lock_all(dev);
  10467. intel_modeset_setup_hw_state(dev, false);
  10468. drm_modeset_unlock_all(dev);
  10469. for_each_intel_crtc(dev, crtc) {
  10470. if (!crtc->active)
  10471. continue;
  10472. /*
  10473. * Note that reserving the BIOS fb up front prevents us
  10474. * from stuffing other stolen allocations like the ring
  10475. * on top. This prevents some ugliness at boot time, and
  10476. * can even allow for smooth boot transitions if the BIOS
  10477. * fb is large enough for the active pipe configuration.
  10478. */
  10479. if (dev_priv->display.get_plane_config) {
  10480. dev_priv->display.get_plane_config(crtc,
  10481. &crtc->plane_config);
  10482. /*
  10483. * If the fb is shared between multiple heads, we'll
  10484. * just get the first one.
  10485. */
  10486. intel_find_plane_obj(crtc, &crtc->plane_config);
  10487. }
  10488. }
  10489. }
  10490. static void intel_enable_pipe_a(struct drm_device *dev)
  10491. {
  10492. struct intel_connector *connector;
  10493. struct drm_connector *crt = NULL;
  10494. struct intel_load_detect_pipe load_detect_temp;
  10495. struct drm_modeset_acquire_ctx ctx;
  10496. /* We can't just switch on the pipe A, we need to set things up with a
  10497. * proper mode and output configuration. As a gross hack, enable pipe A
  10498. * by enabling the load detect pipe once. */
  10499. list_for_each_entry(connector,
  10500. &dev->mode_config.connector_list,
  10501. base.head) {
  10502. if (connector->encoder->type == INTEL_OUTPUT_ANALOG) {
  10503. crt = &connector->base;
  10504. break;
  10505. }
  10506. }
  10507. if (!crt)
  10508. return;
  10509. if (intel_get_load_detect_pipe(crt, NULL, &load_detect_temp, &ctx))
  10510. intel_release_load_detect_pipe(crt, &load_detect_temp, &ctx);
  10511. }
  10512. static bool
  10513. intel_check_plane_mapping(struct intel_crtc *crtc)
  10514. {
  10515. struct drm_device *dev = crtc->base.dev;
  10516. struct drm_i915_private *dev_priv = dev->dev_private;
  10517. u32 reg, val;
  10518. if (INTEL_INFO(dev)->num_pipes == 1)
  10519. return true;
  10520. reg = DSPCNTR(!crtc->plane);
  10521. val = I915_READ(reg);
  10522. if ((val & DISPLAY_PLANE_ENABLE) &&
  10523. (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe))
  10524. return false;
  10525. return true;
  10526. }
  10527. static void intel_sanitize_crtc(struct intel_crtc *crtc)
  10528. {
  10529. struct drm_device *dev = crtc->base.dev;
  10530. struct drm_i915_private *dev_priv = dev->dev_private;
  10531. u32 reg;
  10532. /* Clear any frame start delays used for debugging left by the BIOS */
  10533. reg = PIPECONF(crtc->config.cpu_transcoder);
  10534. I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
  10535. /* restore vblank interrupts to correct state */
  10536. if (crtc->active)
  10537. drm_vblank_on(dev, crtc->pipe);
  10538. else
  10539. drm_vblank_off(dev, crtc->pipe);
  10540. /* We need to sanitize the plane -> pipe mapping first because this will
  10541. * disable the crtc (and hence change the state) if it is wrong. Note
  10542. * that gen4+ has a fixed plane -> pipe mapping. */
  10543. if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) {
  10544. struct intel_connector *connector;
  10545. bool plane;
  10546. DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n",
  10547. crtc->base.base.id);
  10548. /* Pipe has the wrong plane attached and the plane is active.
  10549. * Temporarily change the plane mapping and disable everything
  10550. * ... */
  10551. plane = crtc->plane;
  10552. crtc->plane = !plane;
  10553. dev_priv->display.crtc_disable(&crtc->base);
  10554. crtc->plane = plane;
  10555. /* ... and break all links. */
  10556. list_for_each_entry(connector, &dev->mode_config.connector_list,
  10557. base.head) {
  10558. if (connector->encoder->base.crtc != &crtc->base)
  10559. continue;
  10560. connector->base.dpms = DRM_MODE_DPMS_OFF;
  10561. connector->base.encoder = NULL;
  10562. }
  10563. /* multiple connectors may have the same encoder:
  10564. * handle them and break crtc link separately */
  10565. list_for_each_entry(connector, &dev->mode_config.connector_list,
  10566. base.head)
  10567. if (connector->encoder->base.crtc == &crtc->base) {
  10568. connector->encoder->base.crtc = NULL;
  10569. connector->encoder->connectors_active = false;
  10570. }
  10571. WARN_ON(crtc->active);
  10572. crtc->base.enabled = false;
  10573. }
  10574. if (dev_priv->quirks & QUIRK_PIPEA_FORCE &&
  10575. crtc->pipe == PIPE_A && !crtc->active) {
  10576. /* BIOS forgot to enable pipe A, this mostly happens after
  10577. * resume. Force-enable the pipe to fix this, the update_dpms
  10578. * call below we restore the pipe to the right state, but leave
  10579. * the required bits on. */
  10580. intel_enable_pipe_a(dev);
  10581. }
  10582. /* Adjust the state of the output pipe according to whether we
  10583. * have active connectors/encoders. */
  10584. intel_crtc_update_dpms(&crtc->base);
  10585. if (crtc->active != crtc->base.enabled) {
  10586. struct intel_encoder *encoder;
  10587. /* This can happen either due to bugs in the get_hw_state
  10588. * functions or because the pipe is force-enabled due to the
  10589. * pipe A quirk. */
  10590. DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n",
  10591. crtc->base.base.id,
  10592. crtc->base.enabled ? "enabled" : "disabled",
  10593. crtc->active ? "enabled" : "disabled");
  10594. crtc->base.enabled = crtc->active;
  10595. /* Because we only establish the connector -> encoder ->
  10596. * crtc links if something is active, this means the
  10597. * crtc is now deactivated. Break the links. connector
  10598. * -> encoder links are only establish when things are
  10599. * actually up, hence no need to break them. */
  10600. WARN_ON(crtc->active);
  10601. for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
  10602. WARN_ON(encoder->connectors_active);
  10603. encoder->base.crtc = NULL;
  10604. }
  10605. }
  10606. if (crtc->active || IS_VALLEYVIEW(dev) || INTEL_INFO(dev)->gen < 5) {
  10607. /*
  10608. * We start out with underrun reporting disabled to avoid races.
  10609. * For correct bookkeeping mark this on active crtcs.
  10610. *
  10611. * Also on gmch platforms we dont have any hardware bits to
  10612. * disable the underrun reporting. Which means we need to start
  10613. * out with underrun reporting disabled also on inactive pipes,
  10614. * since otherwise we'll complain about the garbage we read when
  10615. * e.g. coming up after runtime pm.
  10616. *
  10617. * No protection against concurrent access is required - at
  10618. * worst a fifo underrun happens which also sets this to false.
  10619. */
  10620. crtc->cpu_fifo_underrun_disabled = true;
  10621. crtc->pch_fifo_underrun_disabled = true;
  10622. update_scanline_offset(crtc);
  10623. }
  10624. }
  10625. static void intel_sanitize_encoder(struct intel_encoder *encoder)
  10626. {
  10627. struct intel_connector *connector;
  10628. struct drm_device *dev = encoder->base.dev;
  10629. /* We need to check both for a crtc link (meaning that the
  10630. * encoder is active and trying to read from a pipe) and the
  10631. * pipe itself being active. */
  10632. bool has_active_crtc = encoder->base.crtc &&
  10633. to_intel_crtc(encoder->base.crtc)->active;
  10634. if (encoder->connectors_active && !has_active_crtc) {
  10635. DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
  10636. encoder->base.base.id,
  10637. encoder->base.name);
  10638. /* Connector is active, but has no active pipe. This is
  10639. * fallout from our resume register restoring. Disable
  10640. * the encoder manually again. */
  10641. if (encoder->base.crtc) {
  10642. DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
  10643. encoder->base.base.id,
  10644. encoder->base.name);
  10645. encoder->disable(encoder);
  10646. }
  10647. encoder->base.crtc = NULL;
  10648. encoder->connectors_active = false;
  10649. /* Inconsistent output/port/pipe state happens presumably due to
  10650. * a bug in one of the get_hw_state functions. Or someplace else
  10651. * in our code, like the register restore mess on resume. Clamp
  10652. * things to off as a safer default. */
  10653. list_for_each_entry(connector,
  10654. &dev->mode_config.connector_list,
  10655. base.head) {
  10656. if (connector->encoder != encoder)
  10657. continue;
  10658. connector->base.dpms = DRM_MODE_DPMS_OFF;
  10659. connector->base.encoder = NULL;
  10660. }
  10661. }
  10662. /* Enabled encoders without active connectors will be fixed in
  10663. * the crtc fixup. */
  10664. }
  10665. void i915_redisable_vga_power_on(struct drm_device *dev)
  10666. {
  10667. struct drm_i915_private *dev_priv = dev->dev_private;
  10668. u32 vga_reg = i915_vgacntrl_reg(dev);
  10669. if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) {
  10670. DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
  10671. i915_disable_vga(dev);
  10672. }
  10673. }
  10674. void i915_redisable_vga(struct drm_device *dev)
  10675. {
  10676. struct drm_i915_private *dev_priv = dev->dev_private;
  10677. /* This function can be called both from intel_modeset_setup_hw_state or
  10678. * at a very early point in our resume sequence, where the power well
  10679. * structures are not yet restored. Since this function is at a very
  10680. * paranoid "someone might have enabled VGA while we were not looking"
  10681. * level, just check if the power well is enabled instead of trying to
  10682. * follow the "don't touch the power well if we don't need it" policy
  10683. * the rest of the driver uses. */
  10684. if (!intel_display_power_enabled(dev_priv, POWER_DOMAIN_VGA))
  10685. return;
  10686. i915_redisable_vga_power_on(dev);
  10687. }
  10688. static bool primary_get_hw_state(struct intel_crtc *crtc)
  10689. {
  10690. struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
  10691. if (!crtc->active)
  10692. return false;
  10693. return I915_READ(DSPCNTR(crtc->plane)) & DISPLAY_PLANE_ENABLE;
  10694. }
  10695. static void intel_modeset_readout_hw_state(struct drm_device *dev)
  10696. {
  10697. struct drm_i915_private *dev_priv = dev->dev_private;
  10698. enum pipe pipe;
  10699. struct intel_crtc *crtc;
  10700. struct intel_encoder *encoder;
  10701. struct intel_connector *connector;
  10702. int i;
  10703. for_each_intel_crtc(dev, crtc) {
  10704. memset(&crtc->config, 0, sizeof(crtc->config));
  10705. crtc->config.quirks |= PIPE_CONFIG_QUIRK_INHERITED_MODE;
  10706. crtc->active = dev_priv->display.get_pipe_config(crtc,
  10707. &crtc->config);
  10708. crtc->base.enabled = crtc->active;
  10709. crtc->primary_enabled = primary_get_hw_state(crtc);
  10710. DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n",
  10711. crtc->base.base.id,
  10712. crtc->active ? "enabled" : "disabled");
  10713. }
  10714. /* FIXME: Smash this into the new shared dpll infrastructure. */
  10715. if (HAS_DDI(dev))
  10716. intel_ddi_setup_hw_pll_state(dev);
  10717. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  10718. struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
  10719. pll->on = pll->get_hw_state(dev_priv, pll, &pll->hw_state);
  10720. pll->active = 0;
  10721. for_each_intel_crtc(dev, crtc) {
  10722. if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll)
  10723. pll->active++;
  10724. }
  10725. pll->refcount = pll->active;
  10726. DRM_DEBUG_KMS("%s hw state readout: refcount %i, on %i\n",
  10727. pll->name, pll->refcount, pll->on);
  10728. }
  10729. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  10730. base.head) {
  10731. pipe = 0;
  10732. if (encoder->get_hw_state(encoder, &pipe)) {
  10733. crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  10734. encoder->base.crtc = &crtc->base;
  10735. encoder->get_config(encoder, &crtc->config);
  10736. } else {
  10737. encoder->base.crtc = NULL;
  10738. }
  10739. encoder->connectors_active = false;
  10740. DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
  10741. encoder->base.base.id,
  10742. encoder->base.name,
  10743. encoder->base.crtc ? "enabled" : "disabled",
  10744. pipe_name(pipe));
  10745. }
  10746. list_for_each_entry(connector, &dev->mode_config.connector_list,
  10747. base.head) {
  10748. if (connector->get_hw_state(connector)) {
  10749. connector->base.dpms = DRM_MODE_DPMS_ON;
  10750. connector->encoder->connectors_active = true;
  10751. connector->base.encoder = &connector->encoder->base;
  10752. } else {
  10753. connector->base.dpms = DRM_MODE_DPMS_OFF;
  10754. connector->base.encoder = NULL;
  10755. }
  10756. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
  10757. connector->base.base.id,
  10758. connector->base.name,
  10759. connector->base.encoder ? "enabled" : "disabled");
  10760. }
  10761. }
  10762. /* Scan out the current hw modeset state, sanitizes it and maps it into the drm
  10763. * and i915 state tracking structures. */
  10764. void intel_modeset_setup_hw_state(struct drm_device *dev,
  10765. bool force_restore)
  10766. {
  10767. struct drm_i915_private *dev_priv = dev->dev_private;
  10768. enum pipe pipe;
  10769. struct intel_crtc *crtc;
  10770. struct intel_encoder *encoder;
  10771. int i;
  10772. intel_modeset_readout_hw_state(dev);
  10773. /*
  10774. * Now that we have the config, copy it to each CRTC struct
  10775. * Note that this could go away if we move to using crtc_config
  10776. * checking everywhere.
  10777. */
  10778. for_each_intel_crtc(dev, crtc) {
  10779. if (crtc->active && i915.fastboot) {
  10780. intel_mode_from_pipe_config(&crtc->base.mode, &crtc->config);
  10781. DRM_DEBUG_KMS("[CRTC:%d] found active mode: ",
  10782. crtc->base.base.id);
  10783. drm_mode_debug_printmodeline(&crtc->base.mode);
  10784. }
  10785. }
  10786. /* HW state is read out, now we need to sanitize this mess. */
  10787. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  10788. base.head) {
  10789. intel_sanitize_encoder(encoder);
  10790. }
  10791. for_each_pipe(pipe) {
  10792. crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  10793. intel_sanitize_crtc(crtc);
  10794. intel_dump_pipe_config(crtc, &crtc->config, "[setup_hw_state]");
  10795. }
  10796. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  10797. struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
  10798. if (!pll->on || pll->active)
  10799. continue;
  10800. DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll->name);
  10801. pll->disable(dev_priv, pll);
  10802. pll->on = false;
  10803. }
  10804. if (HAS_PCH_SPLIT(dev))
  10805. ilk_wm_get_hw_state(dev);
  10806. if (force_restore) {
  10807. i915_redisable_vga(dev);
  10808. /*
  10809. * We need to use raw interfaces for restoring state to avoid
  10810. * checking (bogus) intermediate states.
  10811. */
  10812. for_each_pipe(pipe) {
  10813. struct drm_crtc *crtc =
  10814. dev_priv->pipe_to_crtc_mapping[pipe];
  10815. __intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y,
  10816. crtc->primary->fb);
  10817. }
  10818. } else {
  10819. intel_modeset_update_staged_output_state(dev);
  10820. }
  10821. intel_modeset_check_state(dev);
  10822. }
  10823. void intel_modeset_gem_init(struct drm_device *dev)
  10824. {
  10825. struct drm_crtc *c;
  10826. struct intel_framebuffer *fb;
  10827. mutex_lock(&dev->struct_mutex);
  10828. intel_init_gt_powersave(dev);
  10829. mutex_unlock(&dev->struct_mutex);
  10830. intel_modeset_init_hw(dev);
  10831. intel_setup_overlay(dev);
  10832. /*
  10833. * Make sure any fbs we allocated at startup are properly
  10834. * pinned & fenced. When we do the allocation it's too early
  10835. * for this.
  10836. */
  10837. mutex_lock(&dev->struct_mutex);
  10838. for_each_crtc(dev, c) {
  10839. if (!c->primary->fb)
  10840. continue;
  10841. fb = to_intel_framebuffer(c->primary->fb);
  10842. if (intel_pin_and_fence_fb_obj(dev, fb->obj, NULL)) {
  10843. DRM_ERROR("failed to pin boot fb on pipe %d\n",
  10844. to_intel_crtc(c)->pipe);
  10845. drm_framebuffer_unreference(c->primary->fb);
  10846. c->primary->fb = NULL;
  10847. }
  10848. }
  10849. mutex_unlock(&dev->struct_mutex);
  10850. }
  10851. void intel_connector_unregister(struct intel_connector *intel_connector)
  10852. {
  10853. struct drm_connector *connector = &intel_connector->base;
  10854. intel_panel_destroy_backlight(connector);
  10855. drm_sysfs_connector_remove(connector);
  10856. }
  10857. void intel_modeset_cleanup(struct drm_device *dev)
  10858. {
  10859. struct drm_i915_private *dev_priv = dev->dev_private;
  10860. struct drm_connector *connector;
  10861. /*
  10862. * Interrupts and polling as the first thing to avoid creating havoc.
  10863. * Too much stuff here (turning of rps, connectors, ...) would
  10864. * experience fancy races otherwise.
  10865. */
  10866. drm_irq_uninstall(dev);
  10867. cancel_work_sync(&dev_priv->hotplug_work);
  10868. /*
  10869. * Due to the hpd irq storm handling the hotplug work can re-arm the
  10870. * poll handlers. Hence disable polling after hpd handling is shut down.
  10871. */
  10872. drm_kms_helper_poll_fini(dev);
  10873. mutex_lock(&dev->struct_mutex);
  10874. intel_unregister_dsm_handler();
  10875. intel_disable_fbc(dev);
  10876. intel_disable_gt_powersave(dev);
  10877. ironlake_teardown_rc6(dev);
  10878. mutex_unlock(&dev->struct_mutex);
  10879. /* flush any delayed tasks or pending work */
  10880. flush_scheduled_work();
  10881. /* destroy the backlight and sysfs files before encoders/connectors */
  10882. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  10883. struct intel_connector *intel_connector;
  10884. intel_connector = to_intel_connector(connector);
  10885. intel_connector->unregister(intel_connector);
  10886. }
  10887. drm_mode_config_cleanup(dev);
  10888. intel_cleanup_overlay(dev);
  10889. mutex_lock(&dev->struct_mutex);
  10890. intel_cleanup_gt_powersave(dev);
  10891. mutex_unlock(&dev->struct_mutex);
  10892. }
  10893. /*
  10894. * Return which encoder is currently attached for connector.
  10895. */
  10896. struct drm_encoder *intel_best_encoder(struct drm_connector *connector)
  10897. {
  10898. return &intel_attached_encoder(connector)->base;
  10899. }
  10900. void intel_connector_attach_encoder(struct intel_connector *connector,
  10901. struct intel_encoder *encoder)
  10902. {
  10903. connector->encoder = encoder;
  10904. drm_mode_connector_attach_encoder(&connector->base,
  10905. &encoder->base);
  10906. }
  10907. /*
  10908. * set vga decode state - true == enable VGA decode
  10909. */
  10910. int intel_modeset_vga_set_state(struct drm_device *dev, bool state)
  10911. {
  10912. struct drm_i915_private *dev_priv = dev->dev_private;
  10913. unsigned reg = INTEL_INFO(dev)->gen >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL;
  10914. u16 gmch_ctrl;
  10915. if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) {
  10916. DRM_ERROR("failed to read control word\n");
  10917. return -EIO;
  10918. }
  10919. if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state)
  10920. return 0;
  10921. if (state)
  10922. gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
  10923. else
  10924. gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
  10925. if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) {
  10926. DRM_ERROR("failed to write control word\n");
  10927. return -EIO;
  10928. }
  10929. return 0;
  10930. }
  10931. struct intel_display_error_state {
  10932. u32 power_well_driver;
  10933. int num_transcoders;
  10934. struct intel_cursor_error_state {
  10935. u32 control;
  10936. u32 position;
  10937. u32 base;
  10938. u32 size;
  10939. } cursor[I915_MAX_PIPES];
  10940. struct intel_pipe_error_state {
  10941. bool power_domain_on;
  10942. u32 source;
  10943. u32 stat;
  10944. } pipe[I915_MAX_PIPES];
  10945. struct intel_plane_error_state {
  10946. u32 control;
  10947. u32 stride;
  10948. u32 size;
  10949. u32 pos;
  10950. u32 addr;
  10951. u32 surface;
  10952. u32 tile_offset;
  10953. } plane[I915_MAX_PIPES];
  10954. struct intel_transcoder_error_state {
  10955. bool power_domain_on;
  10956. enum transcoder cpu_transcoder;
  10957. u32 conf;
  10958. u32 htotal;
  10959. u32 hblank;
  10960. u32 hsync;
  10961. u32 vtotal;
  10962. u32 vblank;
  10963. u32 vsync;
  10964. } transcoder[4];
  10965. };
  10966. struct intel_display_error_state *
  10967. intel_display_capture_error_state(struct drm_device *dev)
  10968. {
  10969. struct drm_i915_private *dev_priv = dev->dev_private;
  10970. struct intel_display_error_state *error;
  10971. int transcoders[] = {
  10972. TRANSCODER_A,
  10973. TRANSCODER_B,
  10974. TRANSCODER_C,
  10975. TRANSCODER_EDP,
  10976. };
  10977. int i;
  10978. if (INTEL_INFO(dev)->num_pipes == 0)
  10979. return NULL;
  10980. error = kzalloc(sizeof(*error), GFP_ATOMIC);
  10981. if (error == NULL)
  10982. return NULL;
  10983. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  10984. error->power_well_driver = I915_READ(HSW_PWR_WELL_DRIVER);
  10985. for_each_pipe(i) {
  10986. error->pipe[i].power_domain_on =
  10987. intel_display_power_enabled_unlocked(dev_priv,
  10988. POWER_DOMAIN_PIPE(i));
  10989. if (!error->pipe[i].power_domain_on)
  10990. continue;
  10991. error->cursor[i].control = I915_READ(CURCNTR(i));
  10992. error->cursor[i].position = I915_READ(CURPOS(i));
  10993. error->cursor[i].base = I915_READ(CURBASE(i));
  10994. error->plane[i].control = I915_READ(DSPCNTR(i));
  10995. error->plane[i].stride = I915_READ(DSPSTRIDE(i));
  10996. if (INTEL_INFO(dev)->gen <= 3) {
  10997. error->plane[i].size = I915_READ(DSPSIZE(i));
  10998. error->plane[i].pos = I915_READ(DSPPOS(i));
  10999. }
  11000. if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev))
  11001. error->plane[i].addr = I915_READ(DSPADDR(i));
  11002. if (INTEL_INFO(dev)->gen >= 4) {
  11003. error->plane[i].surface = I915_READ(DSPSURF(i));
  11004. error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
  11005. }
  11006. error->pipe[i].source = I915_READ(PIPESRC(i));
  11007. if (!HAS_PCH_SPLIT(dev))
  11008. error->pipe[i].stat = I915_READ(PIPESTAT(i));
  11009. }
  11010. error->num_transcoders = INTEL_INFO(dev)->num_pipes;
  11011. if (HAS_DDI(dev_priv->dev))
  11012. error->num_transcoders++; /* Account for eDP. */
  11013. for (i = 0; i < error->num_transcoders; i++) {
  11014. enum transcoder cpu_transcoder = transcoders[i];
  11015. error->transcoder[i].power_domain_on =
  11016. intel_display_power_enabled_unlocked(dev_priv,
  11017. POWER_DOMAIN_TRANSCODER(cpu_transcoder));
  11018. if (!error->transcoder[i].power_domain_on)
  11019. continue;
  11020. error->transcoder[i].cpu_transcoder = cpu_transcoder;
  11021. error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder));
  11022. error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder));
  11023. error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder));
  11024. error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder));
  11025. error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder));
  11026. error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder));
  11027. error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder));
  11028. }
  11029. return error;
  11030. }
  11031. #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
  11032. void
  11033. intel_display_print_error_state(struct drm_i915_error_state_buf *m,
  11034. struct drm_device *dev,
  11035. struct intel_display_error_state *error)
  11036. {
  11037. int i;
  11038. if (!error)
  11039. return;
  11040. err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev)->num_pipes);
  11041. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  11042. err_printf(m, "PWR_WELL_CTL2: %08x\n",
  11043. error->power_well_driver);
  11044. for_each_pipe(i) {
  11045. err_printf(m, "Pipe [%d]:\n", i);
  11046. err_printf(m, " Power: %s\n",
  11047. error->pipe[i].power_domain_on ? "on" : "off");
  11048. err_printf(m, " SRC: %08x\n", error->pipe[i].source);
  11049. err_printf(m, " STAT: %08x\n", error->pipe[i].stat);
  11050. err_printf(m, "Plane [%d]:\n", i);
  11051. err_printf(m, " CNTR: %08x\n", error->plane[i].control);
  11052. err_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
  11053. if (INTEL_INFO(dev)->gen <= 3) {
  11054. err_printf(m, " SIZE: %08x\n", error->plane[i].size);
  11055. err_printf(m, " POS: %08x\n", error->plane[i].pos);
  11056. }
  11057. if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev))
  11058. err_printf(m, " ADDR: %08x\n", error->plane[i].addr);
  11059. if (INTEL_INFO(dev)->gen >= 4) {
  11060. err_printf(m, " SURF: %08x\n", error->plane[i].surface);
  11061. err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
  11062. }
  11063. err_printf(m, "Cursor [%d]:\n", i);
  11064. err_printf(m, " CNTR: %08x\n", error->cursor[i].control);
  11065. err_printf(m, " POS: %08x\n", error->cursor[i].position);
  11066. err_printf(m, " BASE: %08x\n", error->cursor[i].base);
  11067. }
  11068. for (i = 0; i < error->num_transcoders; i++) {
  11069. err_printf(m, "CPU transcoder: %c\n",
  11070. transcoder_name(error->transcoder[i].cpu_transcoder));
  11071. err_printf(m, " Power: %s\n",
  11072. error->transcoder[i].power_domain_on ? "on" : "off");
  11073. err_printf(m, " CONF: %08x\n", error->transcoder[i].conf);
  11074. err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal);
  11075. err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank);
  11076. err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync);
  11077. err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal);
  11078. err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank);
  11079. err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync);
  11080. }
  11081. }