intel_display.c 365 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283
  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_CHERRYVIEW(dev)) {
  1329. enum dpio_phy phy;
  1330. u32 val;
  1331. for (phy = DPIO_PHY0; phy < I915_NUM_PHYS_VLV; phy++) {
  1332. /* Poll for phypwrgood signal */
  1333. if (wait_for(I915_READ(DISPLAY_PHY_STATUS) &
  1334. PHY_POWERGOOD(phy), 1))
  1335. DRM_ERROR("Display PHY %d is not power up\n", phy);
  1336. /*
  1337. * Deassert common lane reset for PHY.
  1338. *
  1339. * This should only be done on init and resume from S3
  1340. * with both PLLs disabled, or we risk losing DPIO and
  1341. * PLL synchronization.
  1342. */
  1343. val = I915_READ(DISPLAY_PHY_CONTROL);
  1344. I915_WRITE(DISPLAY_PHY_CONTROL,
  1345. PHY_COM_LANE_RESET_DEASSERT(phy, val));
  1346. }
  1347. }
  1348. }
  1349. static void vlv_enable_pll(struct intel_crtc *crtc)
  1350. {
  1351. struct drm_device *dev = crtc->base.dev;
  1352. struct drm_i915_private *dev_priv = dev->dev_private;
  1353. int reg = DPLL(crtc->pipe);
  1354. u32 dpll = crtc->config.dpll_hw_state.dpll;
  1355. assert_pipe_disabled(dev_priv, crtc->pipe);
  1356. /* No really, not for ILK+ */
  1357. BUG_ON(!IS_VALLEYVIEW(dev_priv->dev));
  1358. /* PLL is protected by panel, make sure we can write it */
  1359. if (IS_MOBILE(dev_priv->dev) && !IS_I830(dev_priv->dev))
  1360. assert_panel_unlocked(dev_priv, crtc->pipe);
  1361. I915_WRITE(reg, dpll);
  1362. POSTING_READ(reg);
  1363. udelay(150);
  1364. if (wait_for(((I915_READ(reg) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1))
  1365. DRM_ERROR("DPLL %d failed to lock\n", crtc->pipe);
  1366. I915_WRITE(DPLL_MD(crtc->pipe), crtc->config.dpll_hw_state.dpll_md);
  1367. POSTING_READ(DPLL_MD(crtc->pipe));
  1368. /* We do this three times for luck */
  1369. I915_WRITE(reg, dpll);
  1370. POSTING_READ(reg);
  1371. udelay(150); /* wait for warmup */
  1372. I915_WRITE(reg, dpll);
  1373. POSTING_READ(reg);
  1374. udelay(150); /* wait for warmup */
  1375. I915_WRITE(reg, dpll);
  1376. POSTING_READ(reg);
  1377. udelay(150); /* wait for warmup */
  1378. }
  1379. static void chv_enable_pll(struct intel_crtc *crtc)
  1380. {
  1381. struct drm_device *dev = crtc->base.dev;
  1382. struct drm_i915_private *dev_priv = dev->dev_private;
  1383. int pipe = crtc->pipe;
  1384. enum dpio_channel port = vlv_pipe_to_channel(pipe);
  1385. u32 tmp;
  1386. assert_pipe_disabled(dev_priv, crtc->pipe);
  1387. BUG_ON(!IS_CHERRYVIEW(dev_priv->dev));
  1388. mutex_lock(&dev_priv->dpio_lock);
  1389. /* Enable back the 10bit clock to display controller */
  1390. tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
  1391. tmp |= DPIO_DCLKP_EN;
  1392. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp);
  1393. /*
  1394. * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
  1395. */
  1396. udelay(1);
  1397. /* Enable PLL */
  1398. I915_WRITE(DPLL(pipe), crtc->config.dpll_hw_state.dpll);
  1399. /* Check PLL is locked */
  1400. if (wait_for(((I915_READ(DPLL(pipe)) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1))
  1401. DRM_ERROR("PLL %d failed to lock\n", pipe);
  1402. /* not sure when this should be written */
  1403. I915_WRITE(DPLL_MD(pipe), crtc->config.dpll_hw_state.dpll_md);
  1404. POSTING_READ(DPLL_MD(pipe));
  1405. mutex_unlock(&dev_priv->dpio_lock);
  1406. }
  1407. static void i9xx_enable_pll(struct intel_crtc *crtc)
  1408. {
  1409. struct drm_device *dev = crtc->base.dev;
  1410. struct drm_i915_private *dev_priv = dev->dev_private;
  1411. int reg = DPLL(crtc->pipe);
  1412. u32 dpll = crtc->config.dpll_hw_state.dpll;
  1413. assert_pipe_disabled(dev_priv, crtc->pipe);
  1414. /* No really, not for ILK+ */
  1415. BUG_ON(INTEL_INFO(dev)->gen >= 5);
  1416. /* PLL is protected by panel, make sure we can write it */
  1417. if (IS_MOBILE(dev) && !IS_I830(dev))
  1418. assert_panel_unlocked(dev_priv, crtc->pipe);
  1419. I915_WRITE(reg, dpll);
  1420. /* Wait for the clocks to stabilize. */
  1421. POSTING_READ(reg);
  1422. udelay(150);
  1423. if (INTEL_INFO(dev)->gen >= 4) {
  1424. I915_WRITE(DPLL_MD(crtc->pipe),
  1425. crtc->config.dpll_hw_state.dpll_md);
  1426. } else {
  1427. /* The pixel multiplier can only be updated once the
  1428. * DPLL is enabled and the clocks are stable.
  1429. *
  1430. * So write it again.
  1431. */
  1432. I915_WRITE(reg, dpll);
  1433. }
  1434. /* We do this three times for luck */
  1435. I915_WRITE(reg, dpll);
  1436. POSTING_READ(reg);
  1437. udelay(150); /* wait for warmup */
  1438. I915_WRITE(reg, dpll);
  1439. POSTING_READ(reg);
  1440. udelay(150); /* wait for warmup */
  1441. I915_WRITE(reg, dpll);
  1442. POSTING_READ(reg);
  1443. udelay(150); /* wait for warmup */
  1444. }
  1445. /**
  1446. * i9xx_disable_pll - disable a PLL
  1447. * @dev_priv: i915 private structure
  1448. * @pipe: pipe PLL to disable
  1449. *
  1450. * Disable the PLL for @pipe, making sure the pipe is off first.
  1451. *
  1452. * Note! This is for pre-ILK only.
  1453. */
  1454. static void i9xx_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
  1455. {
  1456. /* Don't disable pipe A or pipe A PLLs if needed */
  1457. if (pipe == PIPE_A && (dev_priv->quirks & QUIRK_PIPEA_FORCE))
  1458. return;
  1459. /* Make sure the pipe isn't still relying on us */
  1460. assert_pipe_disabled(dev_priv, pipe);
  1461. I915_WRITE(DPLL(pipe), 0);
  1462. POSTING_READ(DPLL(pipe));
  1463. }
  1464. static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
  1465. {
  1466. u32 val = 0;
  1467. /* Make sure the pipe isn't still relying on us */
  1468. assert_pipe_disabled(dev_priv, pipe);
  1469. /*
  1470. * Leave integrated clock source and reference clock enabled for pipe B.
  1471. * The latter is needed for VGA hotplug / manual detection.
  1472. */
  1473. if (pipe == PIPE_B)
  1474. val = DPLL_INTEGRATED_CRI_CLK_VLV | DPLL_REFA_CLK_ENABLE_VLV;
  1475. I915_WRITE(DPLL(pipe), val);
  1476. POSTING_READ(DPLL(pipe));
  1477. }
  1478. static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
  1479. {
  1480. enum dpio_channel port = vlv_pipe_to_channel(pipe);
  1481. u32 val;
  1482. /* Make sure the pipe isn't still relying on us */
  1483. assert_pipe_disabled(dev_priv, pipe);
  1484. /* Set PLL en = 0 */
  1485. val = DPLL_SSC_REF_CLOCK_CHV;
  1486. if (pipe != PIPE_A)
  1487. val |= DPLL_INTEGRATED_CRI_CLK_VLV;
  1488. I915_WRITE(DPLL(pipe), val);
  1489. POSTING_READ(DPLL(pipe));
  1490. mutex_lock(&dev_priv->dpio_lock);
  1491. /* Disable 10bit clock to display controller */
  1492. val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
  1493. val &= ~DPIO_DCLKP_EN;
  1494. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val);
  1495. /* disable left/right clock distribution */
  1496. if (pipe != PIPE_B) {
  1497. val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0);
  1498. val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK);
  1499. vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val);
  1500. } else {
  1501. val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1);
  1502. val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK);
  1503. vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val);
  1504. }
  1505. mutex_unlock(&dev_priv->dpio_lock);
  1506. }
  1507. void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
  1508. struct intel_digital_port *dport)
  1509. {
  1510. u32 port_mask;
  1511. int dpll_reg;
  1512. switch (dport->port) {
  1513. case PORT_B:
  1514. port_mask = DPLL_PORTB_READY_MASK;
  1515. dpll_reg = DPLL(0);
  1516. break;
  1517. case PORT_C:
  1518. port_mask = DPLL_PORTC_READY_MASK;
  1519. dpll_reg = DPLL(0);
  1520. break;
  1521. case PORT_D:
  1522. port_mask = DPLL_PORTD_READY_MASK;
  1523. dpll_reg = DPIO_PHY_STATUS;
  1524. break;
  1525. default:
  1526. BUG();
  1527. }
  1528. if (wait_for((I915_READ(dpll_reg) & port_mask) == 0, 1000))
  1529. WARN(1, "timed out waiting for port %c ready: 0x%08x\n",
  1530. port_name(dport->port), I915_READ(dpll_reg));
  1531. }
  1532. static void intel_prepare_shared_dpll(struct intel_crtc *crtc)
  1533. {
  1534. struct drm_device *dev = crtc->base.dev;
  1535. struct drm_i915_private *dev_priv = dev->dev_private;
  1536. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  1537. if (WARN_ON(pll == NULL))
  1538. return;
  1539. WARN_ON(!pll->refcount);
  1540. if (pll->active == 0) {
  1541. DRM_DEBUG_DRIVER("setting up %s\n", pll->name);
  1542. WARN_ON(pll->on);
  1543. assert_shared_dpll_disabled(dev_priv, pll);
  1544. pll->mode_set(dev_priv, pll);
  1545. }
  1546. }
  1547. /**
  1548. * intel_enable_shared_dpll - enable PCH PLL
  1549. * @dev_priv: i915 private structure
  1550. * @pipe: pipe PLL to enable
  1551. *
  1552. * The PCH PLL needs to be enabled before the PCH transcoder, since it
  1553. * drives the transcoder clock.
  1554. */
  1555. static void intel_enable_shared_dpll(struct intel_crtc *crtc)
  1556. {
  1557. struct drm_device *dev = crtc->base.dev;
  1558. struct drm_i915_private *dev_priv = dev->dev_private;
  1559. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  1560. if (WARN_ON(pll == NULL))
  1561. return;
  1562. if (WARN_ON(pll->refcount == 0))
  1563. return;
  1564. DRM_DEBUG_KMS("enable %s (active %d, on? %d)for crtc %d\n",
  1565. pll->name, pll->active, pll->on,
  1566. crtc->base.base.id);
  1567. if (pll->active++) {
  1568. WARN_ON(!pll->on);
  1569. assert_shared_dpll_enabled(dev_priv, pll);
  1570. return;
  1571. }
  1572. WARN_ON(pll->on);
  1573. DRM_DEBUG_KMS("enabling %s\n", pll->name);
  1574. pll->enable(dev_priv, pll);
  1575. pll->on = true;
  1576. }
  1577. static void intel_disable_shared_dpll(struct intel_crtc *crtc)
  1578. {
  1579. struct drm_device *dev = crtc->base.dev;
  1580. struct drm_i915_private *dev_priv = dev->dev_private;
  1581. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  1582. /* PCH only available on ILK+ */
  1583. BUG_ON(INTEL_INFO(dev)->gen < 5);
  1584. if (WARN_ON(pll == NULL))
  1585. return;
  1586. if (WARN_ON(pll->refcount == 0))
  1587. return;
  1588. DRM_DEBUG_KMS("disable %s (active %d, on? %d) for crtc %d\n",
  1589. pll->name, pll->active, pll->on,
  1590. crtc->base.base.id);
  1591. if (WARN_ON(pll->active == 0)) {
  1592. assert_shared_dpll_disabled(dev_priv, pll);
  1593. return;
  1594. }
  1595. assert_shared_dpll_enabled(dev_priv, pll);
  1596. WARN_ON(!pll->on);
  1597. if (--pll->active)
  1598. return;
  1599. DRM_DEBUG_KMS("disabling %s\n", pll->name);
  1600. pll->disable(dev_priv, pll);
  1601. pll->on = false;
  1602. }
  1603. static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv,
  1604. enum pipe pipe)
  1605. {
  1606. struct drm_device *dev = dev_priv->dev;
  1607. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  1608. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1609. uint32_t reg, val, pipeconf_val;
  1610. /* PCH only available on ILK+ */
  1611. BUG_ON(INTEL_INFO(dev)->gen < 5);
  1612. /* Make sure PCH DPLL is enabled */
  1613. assert_shared_dpll_enabled(dev_priv,
  1614. intel_crtc_to_shared_dpll(intel_crtc));
  1615. /* FDI must be feeding us bits for PCH ports */
  1616. assert_fdi_tx_enabled(dev_priv, pipe);
  1617. assert_fdi_rx_enabled(dev_priv, pipe);
  1618. if (HAS_PCH_CPT(dev)) {
  1619. /* Workaround: Set the timing override bit before enabling the
  1620. * pch transcoder. */
  1621. reg = TRANS_CHICKEN2(pipe);
  1622. val = I915_READ(reg);
  1623. val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
  1624. I915_WRITE(reg, val);
  1625. }
  1626. reg = PCH_TRANSCONF(pipe);
  1627. val = I915_READ(reg);
  1628. pipeconf_val = I915_READ(PIPECONF(pipe));
  1629. if (HAS_PCH_IBX(dev_priv->dev)) {
  1630. /*
  1631. * make the BPC in transcoder be consistent with
  1632. * that in pipeconf reg.
  1633. */
  1634. val &= ~PIPECONF_BPC_MASK;
  1635. val |= pipeconf_val & PIPECONF_BPC_MASK;
  1636. }
  1637. val &= ~TRANS_INTERLACE_MASK;
  1638. if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK)
  1639. if (HAS_PCH_IBX(dev_priv->dev) &&
  1640. intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO))
  1641. val |= TRANS_LEGACY_INTERLACED_ILK;
  1642. else
  1643. val |= TRANS_INTERLACED;
  1644. else
  1645. val |= TRANS_PROGRESSIVE;
  1646. I915_WRITE(reg, val | TRANS_ENABLE);
  1647. if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100))
  1648. DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe));
  1649. }
  1650. static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
  1651. enum transcoder cpu_transcoder)
  1652. {
  1653. u32 val, pipeconf_val;
  1654. /* PCH only available on ILK+ */
  1655. BUG_ON(INTEL_INFO(dev_priv->dev)->gen < 5);
  1656. /* FDI must be feeding us bits for PCH ports */
  1657. assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder);
  1658. assert_fdi_rx_enabled(dev_priv, TRANSCODER_A);
  1659. /* Workaround: set timing override bit. */
  1660. val = I915_READ(_TRANSA_CHICKEN2);
  1661. val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
  1662. I915_WRITE(_TRANSA_CHICKEN2, val);
  1663. val = TRANS_ENABLE;
  1664. pipeconf_val = I915_READ(PIPECONF(cpu_transcoder));
  1665. if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) ==
  1666. PIPECONF_INTERLACED_ILK)
  1667. val |= TRANS_INTERLACED;
  1668. else
  1669. val |= TRANS_PROGRESSIVE;
  1670. I915_WRITE(LPT_TRANSCONF, val);
  1671. if (wait_for(I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE, 100))
  1672. DRM_ERROR("Failed to enable PCH transcoder\n");
  1673. }
  1674. static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv,
  1675. enum pipe pipe)
  1676. {
  1677. struct drm_device *dev = dev_priv->dev;
  1678. uint32_t reg, val;
  1679. /* FDI relies on the transcoder */
  1680. assert_fdi_tx_disabled(dev_priv, pipe);
  1681. assert_fdi_rx_disabled(dev_priv, pipe);
  1682. /* Ports must be off as well */
  1683. assert_pch_ports_disabled(dev_priv, pipe);
  1684. reg = PCH_TRANSCONF(pipe);
  1685. val = I915_READ(reg);
  1686. val &= ~TRANS_ENABLE;
  1687. I915_WRITE(reg, val);
  1688. /* wait for PCH transcoder off, transcoder state */
  1689. if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50))
  1690. DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe));
  1691. if (!HAS_PCH_IBX(dev)) {
  1692. /* Workaround: Clear the timing override chicken bit again. */
  1693. reg = TRANS_CHICKEN2(pipe);
  1694. val = I915_READ(reg);
  1695. val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
  1696. I915_WRITE(reg, val);
  1697. }
  1698. }
  1699. static void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
  1700. {
  1701. u32 val;
  1702. val = I915_READ(LPT_TRANSCONF);
  1703. val &= ~TRANS_ENABLE;
  1704. I915_WRITE(LPT_TRANSCONF, val);
  1705. /* wait for PCH transcoder off, transcoder state */
  1706. if (wait_for((I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE) == 0, 50))
  1707. DRM_ERROR("Failed to disable PCH transcoder\n");
  1708. /* Workaround: clear timing override bit. */
  1709. val = I915_READ(_TRANSA_CHICKEN2);
  1710. val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
  1711. I915_WRITE(_TRANSA_CHICKEN2, val);
  1712. }
  1713. /**
  1714. * intel_enable_pipe - enable a pipe, asserting requirements
  1715. * @crtc: crtc responsible for the pipe
  1716. *
  1717. * Enable @crtc's pipe, making sure that various hardware specific requirements
  1718. * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc.
  1719. */
  1720. static void intel_enable_pipe(struct intel_crtc *crtc)
  1721. {
  1722. struct drm_device *dev = crtc->base.dev;
  1723. struct drm_i915_private *dev_priv = dev->dev_private;
  1724. enum pipe pipe = crtc->pipe;
  1725. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  1726. pipe);
  1727. enum pipe pch_transcoder;
  1728. int reg;
  1729. u32 val;
  1730. assert_planes_disabled(dev_priv, pipe);
  1731. assert_cursor_disabled(dev_priv, pipe);
  1732. assert_sprites_disabled(dev_priv, pipe);
  1733. if (HAS_PCH_LPT(dev_priv->dev))
  1734. pch_transcoder = TRANSCODER_A;
  1735. else
  1736. pch_transcoder = pipe;
  1737. /*
  1738. * A pipe without a PLL won't actually be able to drive bits from
  1739. * a plane. On ILK+ the pipe PLLs are integrated, so we don't
  1740. * need the check.
  1741. */
  1742. if (!HAS_PCH_SPLIT(dev_priv->dev))
  1743. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DSI))
  1744. assert_dsi_pll_enabled(dev_priv);
  1745. else
  1746. assert_pll_enabled(dev_priv, pipe);
  1747. else {
  1748. if (crtc->config.has_pch_encoder) {
  1749. /* if driving the PCH, we need FDI enabled */
  1750. assert_fdi_rx_pll_enabled(dev_priv, pch_transcoder);
  1751. assert_fdi_tx_pll_enabled(dev_priv,
  1752. (enum pipe) cpu_transcoder);
  1753. }
  1754. /* FIXME: assert CPU port conditions for SNB+ */
  1755. }
  1756. reg = PIPECONF(cpu_transcoder);
  1757. val = I915_READ(reg);
  1758. if (val & PIPECONF_ENABLE) {
  1759. WARN_ON(!(pipe == PIPE_A &&
  1760. dev_priv->quirks & QUIRK_PIPEA_FORCE));
  1761. return;
  1762. }
  1763. I915_WRITE(reg, val | PIPECONF_ENABLE);
  1764. POSTING_READ(reg);
  1765. }
  1766. /**
  1767. * intel_disable_pipe - disable a pipe, asserting requirements
  1768. * @dev_priv: i915 private structure
  1769. * @pipe: pipe to disable
  1770. *
  1771. * Disable @pipe, making sure that various hardware specific requirements
  1772. * are met, if applicable, e.g. plane disabled, panel fitter off, etc.
  1773. *
  1774. * @pipe should be %PIPE_A or %PIPE_B.
  1775. *
  1776. * Will wait until the pipe has shut down before returning.
  1777. */
  1778. static void intel_disable_pipe(struct drm_i915_private *dev_priv,
  1779. enum pipe pipe)
  1780. {
  1781. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  1782. pipe);
  1783. int reg;
  1784. u32 val;
  1785. /*
  1786. * Make sure planes won't keep trying to pump pixels to us,
  1787. * or we might hang the display.
  1788. */
  1789. assert_planes_disabled(dev_priv, pipe);
  1790. assert_cursor_disabled(dev_priv, pipe);
  1791. assert_sprites_disabled(dev_priv, pipe);
  1792. /* Don't disable pipe A or pipe A PLLs if needed */
  1793. if (pipe == PIPE_A && (dev_priv->quirks & QUIRK_PIPEA_FORCE))
  1794. return;
  1795. reg = PIPECONF(cpu_transcoder);
  1796. val = I915_READ(reg);
  1797. if ((val & PIPECONF_ENABLE) == 0)
  1798. return;
  1799. I915_WRITE(reg, val & ~PIPECONF_ENABLE);
  1800. intel_wait_for_pipe_off(dev_priv->dev, pipe);
  1801. }
  1802. /*
  1803. * Plane regs are double buffered, going from enabled->disabled needs a
  1804. * trigger in order to latch. The display address reg provides this.
  1805. */
  1806. void intel_flush_primary_plane(struct drm_i915_private *dev_priv,
  1807. enum plane plane)
  1808. {
  1809. struct drm_device *dev = dev_priv->dev;
  1810. u32 reg = INTEL_INFO(dev)->gen >= 4 ? DSPSURF(plane) : DSPADDR(plane);
  1811. I915_WRITE(reg, I915_READ(reg));
  1812. POSTING_READ(reg);
  1813. }
  1814. /**
  1815. * intel_enable_primary_hw_plane - enable the primary plane on a given pipe
  1816. * @dev_priv: i915 private structure
  1817. * @plane: plane to enable
  1818. * @pipe: pipe being fed
  1819. *
  1820. * Enable @plane on @pipe, making sure that @pipe is running first.
  1821. */
  1822. static void intel_enable_primary_hw_plane(struct drm_i915_private *dev_priv,
  1823. enum plane plane, enum pipe pipe)
  1824. {
  1825. struct drm_device *dev = dev_priv->dev;
  1826. struct intel_crtc *intel_crtc =
  1827. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  1828. int reg;
  1829. u32 val;
  1830. /* If the pipe isn't enabled, we can't pump pixels and may hang */
  1831. assert_pipe_enabled(dev_priv, pipe);
  1832. if (intel_crtc->primary_enabled)
  1833. return;
  1834. intel_crtc->primary_enabled = true;
  1835. reg = DSPCNTR(plane);
  1836. val = I915_READ(reg);
  1837. WARN_ON(val & DISPLAY_PLANE_ENABLE);
  1838. I915_WRITE(reg, val | DISPLAY_PLANE_ENABLE);
  1839. intel_flush_primary_plane(dev_priv, plane);
  1840. /*
  1841. * BDW signals flip done immediately if the plane
  1842. * is disabled, even if the plane enable is already
  1843. * armed to occur at the next vblank :(
  1844. */
  1845. if (IS_BROADWELL(dev))
  1846. intel_wait_for_vblank(dev, intel_crtc->pipe);
  1847. }
  1848. /**
  1849. * intel_disable_primary_hw_plane - disable the primary hardware plane
  1850. * @dev_priv: i915 private structure
  1851. * @plane: plane to disable
  1852. * @pipe: pipe consuming the data
  1853. *
  1854. * Disable @plane; should be an independent operation.
  1855. */
  1856. static void intel_disable_primary_hw_plane(struct drm_i915_private *dev_priv,
  1857. enum plane plane, enum pipe pipe)
  1858. {
  1859. struct intel_crtc *intel_crtc =
  1860. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  1861. int reg;
  1862. u32 val;
  1863. if (!intel_crtc->primary_enabled)
  1864. return;
  1865. intel_crtc->primary_enabled = false;
  1866. reg = DSPCNTR(plane);
  1867. val = I915_READ(reg);
  1868. WARN_ON((val & DISPLAY_PLANE_ENABLE) == 0);
  1869. I915_WRITE(reg, val & ~DISPLAY_PLANE_ENABLE);
  1870. intel_flush_primary_plane(dev_priv, plane);
  1871. }
  1872. static bool need_vtd_wa(struct drm_device *dev)
  1873. {
  1874. #ifdef CONFIG_INTEL_IOMMU
  1875. if (INTEL_INFO(dev)->gen >= 6 && intel_iommu_gfx_mapped)
  1876. return true;
  1877. #endif
  1878. return false;
  1879. }
  1880. static int intel_align_height(struct drm_device *dev, int height, bool tiled)
  1881. {
  1882. int tile_height;
  1883. tile_height = tiled ? (IS_GEN2(dev) ? 16 : 8) : 1;
  1884. return ALIGN(height, tile_height);
  1885. }
  1886. int
  1887. intel_pin_and_fence_fb_obj(struct drm_device *dev,
  1888. struct drm_i915_gem_object *obj,
  1889. struct intel_engine_cs *pipelined)
  1890. {
  1891. struct drm_i915_private *dev_priv = dev->dev_private;
  1892. u32 alignment;
  1893. int ret;
  1894. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  1895. switch (obj->tiling_mode) {
  1896. case I915_TILING_NONE:
  1897. if (IS_BROADWATER(dev) || IS_CRESTLINE(dev))
  1898. alignment = 128 * 1024;
  1899. else if (INTEL_INFO(dev)->gen >= 4)
  1900. alignment = 4 * 1024;
  1901. else
  1902. alignment = 64 * 1024;
  1903. break;
  1904. case I915_TILING_X:
  1905. /* pin() will align the object as required by fence */
  1906. alignment = 0;
  1907. break;
  1908. case I915_TILING_Y:
  1909. WARN(1, "Y tiled bo slipped through, driver bug!\n");
  1910. return -EINVAL;
  1911. default:
  1912. BUG();
  1913. }
  1914. /* Note that the w/a also requires 64 PTE of padding following the
  1915. * bo. We currently fill all unused PTE with the shadow page and so
  1916. * we should always have valid PTE following the scanout preventing
  1917. * the VT-d warning.
  1918. */
  1919. if (need_vtd_wa(dev) && alignment < 256 * 1024)
  1920. alignment = 256 * 1024;
  1921. dev_priv->mm.interruptible = false;
  1922. ret = i915_gem_object_pin_to_display_plane(obj, alignment, pipelined);
  1923. if (ret)
  1924. goto err_interruptible;
  1925. /* Install a fence for tiled scan-out. Pre-i965 always needs a
  1926. * fence, whereas 965+ only requires a fence if using
  1927. * framebuffer compression. For simplicity, we always install
  1928. * a fence as the cost is not that onerous.
  1929. */
  1930. ret = i915_gem_object_get_fence(obj);
  1931. if (ret)
  1932. goto err_unpin;
  1933. i915_gem_object_pin_fence(obj);
  1934. dev_priv->mm.interruptible = true;
  1935. return 0;
  1936. err_unpin:
  1937. i915_gem_object_unpin_from_display_plane(obj);
  1938. err_interruptible:
  1939. dev_priv->mm.interruptible = true;
  1940. return ret;
  1941. }
  1942. void intel_unpin_fb_obj(struct drm_i915_gem_object *obj)
  1943. {
  1944. WARN_ON(!mutex_is_locked(&obj->base.dev->struct_mutex));
  1945. i915_gem_object_unpin_fence(obj);
  1946. i915_gem_object_unpin_from_display_plane(obj);
  1947. }
  1948. /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel
  1949. * is assumed to be a power-of-two. */
  1950. unsigned long intel_gen4_compute_page_offset(int *x, int *y,
  1951. unsigned int tiling_mode,
  1952. unsigned int cpp,
  1953. unsigned int pitch)
  1954. {
  1955. if (tiling_mode != I915_TILING_NONE) {
  1956. unsigned int tile_rows, tiles;
  1957. tile_rows = *y / 8;
  1958. *y %= 8;
  1959. tiles = *x / (512/cpp);
  1960. *x %= 512/cpp;
  1961. return tile_rows * pitch * 8 + tiles * 4096;
  1962. } else {
  1963. unsigned int offset;
  1964. offset = *y * pitch + *x * cpp;
  1965. *y = 0;
  1966. *x = (offset & 4095) / cpp;
  1967. return offset & -4096;
  1968. }
  1969. }
  1970. int intel_format_to_fourcc(int format)
  1971. {
  1972. switch (format) {
  1973. case DISPPLANE_8BPP:
  1974. return DRM_FORMAT_C8;
  1975. case DISPPLANE_BGRX555:
  1976. return DRM_FORMAT_XRGB1555;
  1977. case DISPPLANE_BGRX565:
  1978. return DRM_FORMAT_RGB565;
  1979. default:
  1980. case DISPPLANE_BGRX888:
  1981. return DRM_FORMAT_XRGB8888;
  1982. case DISPPLANE_RGBX888:
  1983. return DRM_FORMAT_XBGR8888;
  1984. case DISPPLANE_BGRX101010:
  1985. return DRM_FORMAT_XRGB2101010;
  1986. case DISPPLANE_RGBX101010:
  1987. return DRM_FORMAT_XBGR2101010;
  1988. }
  1989. }
  1990. static bool intel_alloc_plane_obj(struct intel_crtc *crtc,
  1991. struct intel_plane_config *plane_config)
  1992. {
  1993. struct drm_device *dev = crtc->base.dev;
  1994. struct drm_i915_gem_object *obj = NULL;
  1995. struct drm_mode_fb_cmd2 mode_cmd = { 0 };
  1996. u32 base = plane_config->base;
  1997. if (plane_config->size == 0)
  1998. return false;
  1999. obj = i915_gem_object_create_stolen_for_preallocated(dev, base, base,
  2000. plane_config->size);
  2001. if (!obj)
  2002. return false;
  2003. if (plane_config->tiled) {
  2004. obj->tiling_mode = I915_TILING_X;
  2005. obj->stride = crtc->base.primary->fb->pitches[0];
  2006. }
  2007. mode_cmd.pixel_format = crtc->base.primary->fb->pixel_format;
  2008. mode_cmd.width = crtc->base.primary->fb->width;
  2009. mode_cmd.height = crtc->base.primary->fb->height;
  2010. mode_cmd.pitches[0] = crtc->base.primary->fb->pitches[0];
  2011. mutex_lock(&dev->struct_mutex);
  2012. if (intel_framebuffer_init(dev, to_intel_framebuffer(crtc->base.primary->fb),
  2013. &mode_cmd, obj)) {
  2014. DRM_DEBUG_KMS("intel fb init failed\n");
  2015. goto out_unref_obj;
  2016. }
  2017. obj->frontbuffer_bits = INTEL_FRONTBUFFER_PRIMARY(crtc->pipe);
  2018. mutex_unlock(&dev->struct_mutex);
  2019. DRM_DEBUG_KMS("plane fb obj %p\n", obj);
  2020. return true;
  2021. out_unref_obj:
  2022. drm_gem_object_unreference(&obj->base);
  2023. mutex_unlock(&dev->struct_mutex);
  2024. return false;
  2025. }
  2026. static void intel_find_plane_obj(struct intel_crtc *intel_crtc,
  2027. struct intel_plane_config *plane_config)
  2028. {
  2029. struct drm_device *dev = intel_crtc->base.dev;
  2030. struct drm_crtc *c;
  2031. struct intel_crtc *i;
  2032. struct drm_i915_gem_object *obj;
  2033. if (!intel_crtc->base.primary->fb)
  2034. return;
  2035. if (intel_alloc_plane_obj(intel_crtc, plane_config))
  2036. return;
  2037. kfree(intel_crtc->base.primary->fb);
  2038. intel_crtc->base.primary->fb = NULL;
  2039. /*
  2040. * Failed to alloc the obj, check to see if we should share
  2041. * an fb with another CRTC instead
  2042. */
  2043. for_each_crtc(dev, c) {
  2044. i = to_intel_crtc(c);
  2045. if (c == &intel_crtc->base)
  2046. continue;
  2047. if (!i->active)
  2048. continue;
  2049. obj = intel_fb_obj(c->primary->fb);
  2050. if (obj == NULL)
  2051. continue;
  2052. if (i915_gem_obj_ggtt_offset(obj) == plane_config->base) {
  2053. drm_framebuffer_reference(c->primary->fb);
  2054. intel_crtc->base.primary->fb = c->primary->fb;
  2055. obj->frontbuffer_bits |= INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe);
  2056. break;
  2057. }
  2058. }
  2059. }
  2060. static void i9xx_update_primary_plane(struct drm_crtc *crtc,
  2061. struct drm_framebuffer *fb,
  2062. int x, int y)
  2063. {
  2064. struct drm_device *dev = crtc->dev;
  2065. struct drm_i915_private *dev_priv = dev->dev_private;
  2066. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2067. struct drm_i915_gem_object *obj = intel_fb_obj(fb);
  2068. int plane = intel_crtc->plane;
  2069. unsigned long linear_offset;
  2070. u32 dspcntr;
  2071. u32 reg;
  2072. reg = DSPCNTR(plane);
  2073. dspcntr = I915_READ(reg);
  2074. /* Mask out pixel format bits in case we change it */
  2075. dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
  2076. switch (fb->pixel_format) {
  2077. case DRM_FORMAT_C8:
  2078. dspcntr |= DISPPLANE_8BPP;
  2079. break;
  2080. case DRM_FORMAT_XRGB1555:
  2081. case DRM_FORMAT_ARGB1555:
  2082. dspcntr |= DISPPLANE_BGRX555;
  2083. break;
  2084. case DRM_FORMAT_RGB565:
  2085. dspcntr |= DISPPLANE_BGRX565;
  2086. break;
  2087. case DRM_FORMAT_XRGB8888:
  2088. case DRM_FORMAT_ARGB8888:
  2089. dspcntr |= DISPPLANE_BGRX888;
  2090. break;
  2091. case DRM_FORMAT_XBGR8888:
  2092. case DRM_FORMAT_ABGR8888:
  2093. dspcntr |= DISPPLANE_RGBX888;
  2094. break;
  2095. case DRM_FORMAT_XRGB2101010:
  2096. case DRM_FORMAT_ARGB2101010:
  2097. dspcntr |= DISPPLANE_BGRX101010;
  2098. break;
  2099. case DRM_FORMAT_XBGR2101010:
  2100. case DRM_FORMAT_ABGR2101010:
  2101. dspcntr |= DISPPLANE_RGBX101010;
  2102. break;
  2103. default:
  2104. BUG();
  2105. }
  2106. if (INTEL_INFO(dev)->gen >= 4) {
  2107. if (obj->tiling_mode != I915_TILING_NONE)
  2108. dspcntr |= DISPPLANE_TILED;
  2109. else
  2110. dspcntr &= ~DISPPLANE_TILED;
  2111. }
  2112. if (IS_G4X(dev))
  2113. dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
  2114. I915_WRITE(reg, dspcntr);
  2115. linear_offset = y * fb->pitches[0] + x * (fb->bits_per_pixel / 8);
  2116. if (INTEL_INFO(dev)->gen >= 4) {
  2117. intel_crtc->dspaddr_offset =
  2118. intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
  2119. fb->bits_per_pixel / 8,
  2120. fb->pitches[0]);
  2121. linear_offset -= intel_crtc->dspaddr_offset;
  2122. } else {
  2123. intel_crtc->dspaddr_offset = linear_offset;
  2124. }
  2125. DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n",
  2126. i915_gem_obj_ggtt_offset(obj), linear_offset, x, y,
  2127. fb->pitches[0]);
  2128. I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
  2129. if (INTEL_INFO(dev)->gen >= 4) {
  2130. I915_WRITE(DSPSURF(plane),
  2131. i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset);
  2132. I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
  2133. I915_WRITE(DSPLINOFF(plane), linear_offset);
  2134. } else
  2135. I915_WRITE(DSPADDR(plane), i915_gem_obj_ggtt_offset(obj) + linear_offset);
  2136. POSTING_READ(reg);
  2137. }
  2138. static void ironlake_update_primary_plane(struct drm_crtc *crtc,
  2139. struct drm_framebuffer *fb,
  2140. int x, int y)
  2141. {
  2142. struct drm_device *dev = crtc->dev;
  2143. struct drm_i915_private *dev_priv = dev->dev_private;
  2144. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2145. struct drm_i915_gem_object *obj = intel_fb_obj(fb);
  2146. int plane = intel_crtc->plane;
  2147. unsigned long linear_offset;
  2148. u32 dspcntr;
  2149. u32 reg;
  2150. reg = DSPCNTR(plane);
  2151. dspcntr = I915_READ(reg);
  2152. /* Mask out pixel format bits in case we change it */
  2153. dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
  2154. switch (fb->pixel_format) {
  2155. case DRM_FORMAT_C8:
  2156. dspcntr |= DISPPLANE_8BPP;
  2157. break;
  2158. case DRM_FORMAT_RGB565:
  2159. dspcntr |= DISPPLANE_BGRX565;
  2160. break;
  2161. case DRM_FORMAT_XRGB8888:
  2162. case DRM_FORMAT_ARGB8888:
  2163. dspcntr |= DISPPLANE_BGRX888;
  2164. break;
  2165. case DRM_FORMAT_XBGR8888:
  2166. case DRM_FORMAT_ABGR8888:
  2167. dspcntr |= DISPPLANE_RGBX888;
  2168. break;
  2169. case DRM_FORMAT_XRGB2101010:
  2170. case DRM_FORMAT_ARGB2101010:
  2171. dspcntr |= DISPPLANE_BGRX101010;
  2172. break;
  2173. case DRM_FORMAT_XBGR2101010:
  2174. case DRM_FORMAT_ABGR2101010:
  2175. dspcntr |= DISPPLANE_RGBX101010;
  2176. break;
  2177. default:
  2178. BUG();
  2179. }
  2180. if (obj->tiling_mode != I915_TILING_NONE)
  2181. dspcntr |= DISPPLANE_TILED;
  2182. else
  2183. dspcntr &= ~DISPPLANE_TILED;
  2184. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  2185. dspcntr &= ~DISPPLANE_TRICKLE_FEED_DISABLE;
  2186. else
  2187. dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
  2188. I915_WRITE(reg, dspcntr);
  2189. linear_offset = y * fb->pitches[0] + x * (fb->bits_per_pixel / 8);
  2190. intel_crtc->dspaddr_offset =
  2191. intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
  2192. fb->bits_per_pixel / 8,
  2193. fb->pitches[0]);
  2194. linear_offset -= intel_crtc->dspaddr_offset;
  2195. DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n",
  2196. i915_gem_obj_ggtt_offset(obj), linear_offset, x, y,
  2197. fb->pitches[0]);
  2198. I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
  2199. I915_WRITE(DSPSURF(plane),
  2200. i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset);
  2201. if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  2202. I915_WRITE(DSPOFFSET(plane), (y << 16) | x);
  2203. } else {
  2204. I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
  2205. I915_WRITE(DSPLINOFF(plane), linear_offset);
  2206. }
  2207. POSTING_READ(reg);
  2208. }
  2209. /* Assume fb object is pinned & idle & fenced and just update base pointers */
  2210. static int
  2211. intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb,
  2212. int x, int y, enum mode_set_atomic state)
  2213. {
  2214. struct drm_device *dev = crtc->dev;
  2215. struct drm_i915_private *dev_priv = dev->dev_private;
  2216. if (dev_priv->display.disable_fbc)
  2217. dev_priv->display.disable_fbc(dev);
  2218. intel_increase_pllclock(dev, to_intel_crtc(crtc)->pipe);
  2219. dev_priv->display.update_primary_plane(crtc, fb, x, y);
  2220. return 0;
  2221. }
  2222. void intel_display_handle_reset(struct drm_device *dev)
  2223. {
  2224. struct drm_i915_private *dev_priv = dev->dev_private;
  2225. struct drm_crtc *crtc;
  2226. /*
  2227. * Flips in the rings have been nuked by the reset,
  2228. * so complete all pending flips so that user space
  2229. * will get its events and not get stuck.
  2230. *
  2231. * Also update the base address of all primary
  2232. * planes to the the last fb to make sure we're
  2233. * showing the correct fb after a reset.
  2234. *
  2235. * Need to make two loops over the crtcs so that we
  2236. * don't try to grab a crtc mutex before the
  2237. * pending_flip_queue really got woken up.
  2238. */
  2239. for_each_crtc(dev, crtc) {
  2240. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2241. enum plane plane = intel_crtc->plane;
  2242. intel_prepare_page_flip(dev, plane);
  2243. intel_finish_page_flip_plane(dev, plane);
  2244. }
  2245. for_each_crtc(dev, crtc) {
  2246. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2247. drm_modeset_lock(&crtc->mutex, NULL);
  2248. /*
  2249. * FIXME: Once we have proper support for primary planes (and
  2250. * disabling them without disabling the entire crtc) allow again
  2251. * a NULL crtc->primary->fb.
  2252. */
  2253. if (intel_crtc->active && crtc->primary->fb)
  2254. dev_priv->display.update_primary_plane(crtc,
  2255. crtc->primary->fb,
  2256. crtc->x,
  2257. crtc->y);
  2258. drm_modeset_unlock(&crtc->mutex);
  2259. }
  2260. }
  2261. static int
  2262. intel_finish_fb(struct drm_framebuffer *old_fb)
  2263. {
  2264. struct drm_i915_gem_object *obj = intel_fb_obj(old_fb);
  2265. struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
  2266. bool was_interruptible = dev_priv->mm.interruptible;
  2267. int ret;
  2268. /* Big Hammer, we also need to ensure that any pending
  2269. * MI_WAIT_FOR_EVENT inside a user batch buffer on the
  2270. * current scanout is retired before unpinning the old
  2271. * framebuffer.
  2272. *
  2273. * This should only fail upon a hung GPU, in which case we
  2274. * can safely continue.
  2275. */
  2276. dev_priv->mm.interruptible = false;
  2277. ret = i915_gem_object_finish_gpu(obj);
  2278. dev_priv->mm.interruptible = was_interruptible;
  2279. return ret;
  2280. }
  2281. static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc)
  2282. {
  2283. struct drm_device *dev = crtc->dev;
  2284. struct drm_i915_private *dev_priv = dev->dev_private;
  2285. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2286. unsigned long flags;
  2287. bool pending;
  2288. if (i915_reset_in_progress(&dev_priv->gpu_error) ||
  2289. intel_crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter))
  2290. return false;
  2291. spin_lock_irqsave(&dev->event_lock, flags);
  2292. pending = to_intel_crtc(crtc)->unpin_work != NULL;
  2293. spin_unlock_irqrestore(&dev->event_lock, flags);
  2294. return pending;
  2295. }
  2296. static int
  2297. intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
  2298. struct drm_framebuffer *fb)
  2299. {
  2300. struct drm_device *dev = crtc->dev;
  2301. struct drm_i915_private *dev_priv = dev->dev_private;
  2302. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2303. enum pipe pipe = intel_crtc->pipe;
  2304. struct drm_framebuffer *old_fb = crtc->primary->fb;
  2305. struct drm_i915_gem_object *obj = intel_fb_obj(fb);
  2306. struct drm_i915_gem_object *old_obj = intel_fb_obj(old_fb);
  2307. int ret;
  2308. if (intel_crtc_has_pending_flip(crtc)) {
  2309. DRM_ERROR("pipe is still busy with an old pageflip\n");
  2310. return -EBUSY;
  2311. }
  2312. /* no fb bound */
  2313. if (!fb) {
  2314. DRM_ERROR("No FB bound\n");
  2315. return 0;
  2316. }
  2317. if (intel_crtc->plane > INTEL_INFO(dev)->num_pipes) {
  2318. DRM_ERROR("no plane for crtc: plane %c, num_pipes %d\n",
  2319. plane_name(intel_crtc->plane),
  2320. INTEL_INFO(dev)->num_pipes);
  2321. return -EINVAL;
  2322. }
  2323. mutex_lock(&dev->struct_mutex);
  2324. ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
  2325. if (ret == 0)
  2326. i915_gem_track_fb(old_obj, obj,
  2327. INTEL_FRONTBUFFER_PRIMARY(pipe));
  2328. mutex_unlock(&dev->struct_mutex);
  2329. if (ret != 0) {
  2330. DRM_ERROR("pin & fence failed\n");
  2331. return ret;
  2332. }
  2333. /*
  2334. * Update pipe size and adjust fitter if needed: the reason for this is
  2335. * that in compute_mode_changes we check the native mode (not the pfit
  2336. * mode) to see if we can flip rather than do a full mode set. In the
  2337. * fastboot case, we'll flip, but if we don't update the pipesrc and
  2338. * pfit state, we'll end up with a big fb scanned out into the wrong
  2339. * sized surface.
  2340. *
  2341. * To fix this properly, we need to hoist the checks up into
  2342. * compute_mode_changes (or above), check the actual pfit state and
  2343. * whether the platform allows pfit disable with pipe active, and only
  2344. * then update the pipesrc and pfit state, even on the flip path.
  2345. */
  2346. if (i915.fastboot) {
  2347. const struct drm_display_mode *adjusted_mode =
  2348. &intel_crtc->config.adjusted_mode;
  2349. I915_WRITE(PIPESRC(intel_crtc->pipe),
  2350. ((adjusted_mode->crtc_hdisplay - 1) << 16) |
  2351. (adjusted_mode->crtc_vdisplay - 1));
  2352. if (!intel_crtc->config.pch_pfit.enabled &&
  2353. (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) ||
  2354. intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) {
  2355. I915_WRITE(PF_CTL(intel_crtc->pipe), 0);
  2356. I915_WRITE(PF_WIN_POS(intel_crtc->pipe), 0);
  2357. I915_WRITE(PF_WIN_SZ(intel_crtc->pipe), 0);
  2358. }
  2359. intel_crtc->config.pipe_src_w = adjusted_mode->crtc_hdisplay;
  2360. intel_crtc->config.pipe_src_h = adjusted_mode->crtc_vdisplay;
  2361. }
  2362. dev_priv->display.update_primary_plane(crtc, fb, x, y);
  2363. if (intel_crtc->active)
  2364. intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_PRIMARY(pipe));
  2365. crtc->primary->fb = fb;
  2366. crtc->x = x;
  2367. crtc->y = y;
  2368. if (old_fb) {
  2369. if (intel_crtc->active && old_fb != fb)
  2370. intel_wait_for_vblank(dev, intel_crtc->pipe);
  2371. mutex_lock(&dev->struct_mutex);
  2372. intel_unpin_fb_obj(old_obj);
  2373. mutex_unlock(&dev->struct_mutex);
  2374. }
  2375. mutex_lock(&dev->struct_mutex);
  2376. intel_update_fbc(dev);
  2377. mutex_unlock(&dev->struct_mutex);
  2378. return 0;
  2379. }
  2380. static void intel_fdi_normal_train(struct drm_crtc *crtc)
  2381. {
  2382. struct drm_device *dev = crtc->dev;
  2383. struct drm_i915_private *dev_priv = dev->dev_private;
  2384. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2385. int pipe = intel_crtc->pipe;
  2386. u32 reg, temp;
  2387. /* enable normal train */
  2388. reg = FDI_TX_CTL(pipe);
  2389. temp = I915_READ(reg);
  2390. if (IS_IVYBRIDGE(dev)) {
  2391. temp &= ~FDI_LINK_TRAIN_NONE_IVB;
  2392. temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
  2393. } else {
  2394. temp &= ~FDI_LINK_TRAIN_NONE;
  2395. temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
  2396. }
  2397. I915_WRITE(reg, temp);
  2398. reg = FDI_RX_CTL(pipe);
  2399. temp = I915_READ(reg);
  2400. if (HAS_PCH_CPT(dev)) {
  2401. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2402. temp |= FDI_LINK_TRAIN_NORMAL_CPT;
  2403. } else {
  2404. temp &= ~FDI_LINK_TRAIN_NONE;
  2405. temp |= FDI_LINK_TRAIN_NONE;
  2406. }
  2407. I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
  2408. /* wait one idle pattern time */
  2409. POSTING_READ(reg);
  2410. udelay(1000);
  2411. /* IVB wants error correction enabled */
  2412. if (IS_IVYBRIDGE(dev))
  2413. I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
  2414. FDI_FE_ERRC_ENABLE);
  2415. }
  2416. static bool pipe_has_enabled_pch(struct intel_crtc *crtc)
  2417. {
  2418. return crtc->base.enabled && crtc->active &&
  2419. crtc->config.has_pch_encoder;
  2420. }
  2421. static void ivb_modeset_global_resources(struct drm_device *dev)
  2422. {
  2423. struct drm_i915_private *dev_priv = dev->dev_private;
  2424. struct intel_crtc *pipe_B_crtc =
  2425. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]);
  2426. struct intel_crtc *pipe_C_crtc =
  2427. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_C]);
  2428. uint32_t temp;
  2429. /*
  2430. * When everything is off disable fdi C so that we could enable fdi B
  2431. * with all lanes. Note that we don't care about enabled pipes without
  2432. * an enabled pch encoder.
  2433. */
  2434. if (!pipe_has_enabled_pch(pipe_B_crtc) &&
  2435. !pipe_has_enabled_pch(pipe_C_crtc)) {
  2436. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
  2437. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
  2438. temp = I915_READ(SOUTH_CHICKEN1);
  2439. temp &= ~FDI_BC_BIFURCATION_SELECT;
  2440. DRM_DEBUG_KMS("disabling fdi C rx\n");
  2441. I915_WRITE(SOUTH_CHICKEN1, temp);
  2442. }
  2443. }
  2444. /* The FDI link training functions for ILK/Ibexpeak. */
  2445. static void ironlake_fdi_link_train(struct drm_crtc *crtc)
  2446. {
  2447. struct drm_device *dev = crtc->dev;
  2448. struct drm_i915_private *dev_priv = dev->dev_private;
  2449. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2450. int pipe = intel_crtc->pipe;
  2451. u32 reg, temp, tries;
  2452. /* FDI needs bits from pipe first */
  2453. assert_pipe_enabled(dev_priv, pipe);
  2454. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2455. for train result */
  2456. reg = FDI_RX_IMR(pipe);
  2457. temp = I915_READ(reg);
  2458. temp &= ~FDI_RX_SYMBOL_LOCK;
  2459. temp &= ~FDI_RX_BIT_LOCK;
  2460. I915_WRITE(reg, temp);
  2461. I915_READ(reg);
  2462. udelay(150);
  2463. /* enable CPU FDI TX and PCH FDI RX */
  2464. reg = FDI_TX_CTL(pipe);
  2465. temp = I915_READ(reg);
  2466. temp &= ~FDI_DP_PORT_WIDTH_MASK;
  2467. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2468. temp &= ~FDI_LINK_TRAIN_NONE;
  2469. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2470. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2471. reg = FDI_RX_CTL(pipe);
  2472. temp = I915_READ(reg);
  2473. temp &= ~FDI_LINK_TRAIN_NONE;
  2474. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2475. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2476. POSTING_READ(reg);
  2477. udelay(150);
  2478. /* Ironlake workaround, enable clock pointer after FDI enable*/
  2479. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
  2480. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
  2481. FDI_RX_PHASE_SYNC_POINTER_EN);
  2482. reg = FDI_RX_IIR(pipe);
  2483. for (tries = 0; tries < 5; tries++) {
  2484. temp = I915_READ(reg);
  2485. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2486. if ((temp & FDI_RX_BIT_LOCK)) {
  2487. DRM_DEBUG_KMS("FDI train 1 done.\n");
  2488. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2489. break;
  2490. }
  2491. }
  2492. if (tries == 5)
  2493. DRM_ERROR("FDI train 1 fail!\n");
  2494. /* Train 2 */
  2495. reg = FDI_TX_CTL(pipe);
  2496. temp = I915_READ(reg);
  2497. temp &= ~FDI_LINK_TRAIN_NONE;
  2498. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2499. I915_WRITE(reg, temp);
  2500. reg = FDI_RX_CTL(pipe);
  2501. temp = I915_READ(reg);
  2502. temp &= ~FDI_LINK_TRAIN_NONE;
  2503. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2504. I915_WRITE(reg, temp);
  2505. POSTING_READ(reg);
  2506. udelay(150);
  2507. reg = FDI_RX_IIR(pipe);
  2508. for (tries = 0; tries < 5; tries++) {
  2509. temp = I915_READ(reg);
  2510. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2511. if (temp & FDI_RX_SYMBOL_LOCK) {
  2512. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2513. DRM_DEBUG_KMS("FDI train 2 done.\n");
  2514. break;
  2515. }
  2516. }
  2517. if (tries == 5)
  2518. DRM_ERROR("FDI train 2 fail!\n");
  2519. DRM_DEBUG_KMS("FDI train done\n");
  2520. }
  2521. static const int snb_b_fdi_train_param[] = {
  2522. FDI_LINK_TRAIN_400MV_0DB_SNB_B,
  2523. FDI_LINK_TRAIN_400MV_6DB_SNB_B,
  2524. FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
  2525. FDI_LINK_TRAIN_800MV_0DB_SNB_B,
  2526. };
  2527. /* The FDI link training functions for SNB/Cougarpoint. */
  2528. static void gen6_fdi_link_train(struct drm_crtc *crtc)
  2529. {
  2530. struct drm_device *dev = crtc->dev;
  2531. struct drm_i915_private *dev_priv = dev->dev_private;
  2532. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2533. int pipe = intel_crtc->pipe;
  2534. u32 reg, temp, i, retry;
  2535. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2536. for train result */
  2537. reg = FDI_RX_IMR(pipe);
  2538. temp = I915_READ(reg);
  2539. temp &= ~FDI_RX_SYMBOL_LOCK;
  2540. temp &= ~FDI_RX_BIT_LOCK;
  2541. I915_WRITE(reg, temp);
  2542. POSTING_READ(reg);
  2543. udelay(150);
  2544. /* enable CPU FDI TX and PCH FDI RX */
  2545. reg = FDI_TX_CTL(pipe);
  2546. temp = I915_READ(reg);
  2547. temp &= ~FDI_DP_PORT_WIDTH_MASK;
  2548. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2549. temp &= ~FDI_LINK_TRAIN_NONE;
  2550. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2551. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2552. /* SNB-B */
  2553. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2554. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2555. I915_WRITE(FDI_RX_MISC(pipe),
  2556. FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
  2557. reg = FDI_RX_CTL(pipe);
  2558. temp = I915_READ(reg);
  2559. if (HAS_PCH_CPT(dev)) {
  2560. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2561. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2562. } else {
  2563. temp &= ~FDI_LINK_TRAIN_NONE;
  2564. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2565. }
  2566. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2567. POSTING_READ(reg);
  2568. udelay(150);
  2569. for (i = 0; i < 4; i++) {
  2570. reg = FDI_TX_CTL(pipe);
  2571. temp = I915_READ(reg);
  2572. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2573. temp |= snb_b_fdi_train_param[i];
  2574. I915_WRITE(reg, temp);
  2575. POSTING_READ(reg);
  2576. udelay(500);
  2577. for (retry = 0; retry < 5; retry++) {
  2578. reg = FDI_RX_IIR(pipe);
  2579. temp = I915_READ(reg);
  2580. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2581. if (temp & FDI_RX_BIT_LOCK) {
  2582. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2583. DRM_DEBUG_KMS("FDI train 1 done.\n");
  2584. break;
  2585. }
  2586. udelay(50);
  2587. }
  2588. if (retry < 5)
  2589. break;
  2590. }
  2591. if (i == 4)
  2592. DRM_ERROR("FDI train 1 fail!\n");
  2593. /* Train 2 */
  2594. reg = FDI_TX_CTL(pipe);
  2595. temp = I915_READ(reg);
  2596. temp &= ~FDI_LINK_TRAIN_NONE;
  2597. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2598. if (IS_GEN6(dev)) {
  2599. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2600. /* SNB-B */
  2601. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2602. }
  2603. I915_WRITE(reg, temp);
  2604. reg = FDI_RX_CTL(pipe);
  2605. temp = I915_READ(reg);
  2606. if (HAS_PCH_CPT(dev)) {
  2607. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2608. temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
  2609. } else {
  2610. temp &= ~FDI_LINK_TRAIN_NONE;
  2611. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2612. }
  2613. I915_WRITE(reg, temp);
  2614. POSTING_READ(reg);
  2615. udelay(150);
  2616. for (i = 0; i < 4; i++) {
  2617. reg = FDI_TX_CTL(pipe);
  2618. temp = I915_READ(reg);
  2619. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2620. temp |= snb_b_fdi_train_param[i];
  2621. I915_WRITE(reg, temp);
  2622. POSTING_READ(reg);
  2623. udelay(500);
  2624. for (retry = 0; retry < 5; retry++) {
  2625. reg = FDI_RX_IIR(pipe);
  2626. temp = I915_READ(reg);
  2627. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2628. if (temp & FDI_RX_SYMBOL_LOCK) {
  2629. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2630. DRM_DEBUG_KMS("FDI train 2 done.\n");
  2631. break;
  2632. }
  2633. udelay(50);
  2634. }
  2635. if (retry < 5)
  2636. break;
  2637. }
  2638. if (i == 4)
  2639. DRM_ERROR("FDI train 2 fail!\n");
  2640. DRM_DEBUG_KMS("FDI train done.\n");
  2641. }
  2642. /* Manual link training for Ivy Bridge A0 parts */
  2643. static void ivb_manual_fdi_link_train(struct drm_crtc *crtc)
  2644. {
  2645. struct drm_device *dev = crtc->dev;
  2646. struct drm_i915_private *dev_priv = dev->dev_private;
  2647. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2648. int pipe = intel_crtc->pipe;
  2649. u32 reg, temp, i, j;
  2650. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2651. for train result */
  2652. reg = FDI_RX_IMR(pipe);
  2653. temp = I915_READ(reg);
  2654. temp &= ~FDI_RX_SYMBOL_LOCK;
  2655. temp &= ~FDI_RX_BIT_LOCK;
  2656. I915_WRITE(reg, temp);
  2657. POSTING_READ(reg);
  2658. udelay(150);
  2659. DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
  2660. I915_READ(FDI_RX_IIR(pipe)));
  2661. /* Try each vswing and preemphasis setting twice before moving on */
  2662. for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) {
  2663. /* disable first in case we need to retry */
  2664. reg = FDI_TX_CTL(pipe);
  2665. temp = I915_READ(reg);
  2666. temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
  2667. temp &= ~FDI_TX_ENABLE;
  2668. I915_WRITE(reg, temp);
  2669. reg = FDI_RX_CTL(pipe);
  2670. temp = I915_READ(reg);
  2671. temp &= ~FDI_LINK_TRAIN_AUTO;
  2672. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2673. temp &= ~FDI_RX_ENABLE;
  2674. I915_WRITE(reg, temp);
  2675. /* enable CPU FDI TX and PCH FDI RX */
  2676. reg = FDI_TX_CTL(pipe);
  2677. temp = I915_READ(reg);
  2678. temp &= ~FDI_DP_PORT_WIDTH_MASK;
  2679. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2680. temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
  2681. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2682. temp |= snb_b_fdi_train_param[j/2];
  2683. temp |= FDI_COMPOSITE_SYNC;
  2684. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2685. I915_WRITE(FDI_RX_MISC(pipe),
  2686. FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
  2687. reg = FDI_RX_CTL(pipe);
  2688. temp = I915_READ(reg);
  2689. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2690. temp |= FDI_COMPOSITE_SYNC;
  2691. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2692. POSTING_READ(reg);
  2693. udelay(1); /* should be 0.5us */
  2694. for (i = 0; i < 4; i++) {
  2695. reg = FDI_RX_IIR(pipe);
  2696. temp = I915_READ(reg);
  2697. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2698. if (temp & FDI_RX_BIT_LOCK ||
  2699. (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
  2700. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2701. DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
  2702. i);
  2703. break;
  2704. }
  2705. udelay(1); /* should be 0.5us */
  2706. }
  2707. if (i == 4) {
  2708. DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2);
  2709. continue;
  2710. }
  2711. /* Train 2 */
  2712. reg = FDI_TX_CTL(pipe);
  2713. temp = I915_READ(reg);
  2714. temp &= ~FDI_LINK_TRAIN_NONE_IVB;
  2715. temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
  2716. I915_WRITE(reg, temp);
  2717. reg = FDI_RX_CTL(pipe);
  2718. temp = I915_READ(reg);
  2719. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2720. temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
  2721. I915_WRITE(reg, temp);
  2722. POSTING_READ(reg);
  2723. udelay(2); /* should be 1.5us */
  2724. for (i = 0; i < 4; i++) {
  2725. reg = FDI_RX_IIR(pipe);
  2726. temp = I915_READ(reg);
  2727. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2728. if (temp & FDI_RX_SYMBOL_LOCK ||
  2729. (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) {
  2730. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2731. DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
  2732. i);
  2733. goto train_done;
  2734. }
  2735. udelay(2); /* should be 1.5us */
  2736. }
  2737. if (i == 4)
  2738. DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2);
  2739. }
  2740. train_done:
  2741. DRM_DEBUG_KMS("FDI train done.\n");
  2742. }
  2743. static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc)
  2744. {
  2745. struct drm_device *dev = intel_crtc->base.dev;
  2746. struct drm_i915_private *dev_priv = dev->dev_private;
  2747. int pipe = intel_crtc->pipe;
  2748. u32 reg, temp;
  2749. /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
  2750. reg = FDI_RX_CTL(pipe);
  2751. temp = I915_READ(reg);
  2752. temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16));
  2753. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2754. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2755. I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
  2756. POSTING_READ(reg);
  2757. udelay(200);
  2758. /* Switch from Rawclk to PCDclk */
  2759. temp = I915_READ(reg);
  2760. I915_WRITE(reg, temp | FDI_PCDCLK);
  2761. POSTING_READ(reg);
  2762. udelay(200);
  2763. /* Enable CPU FDI TX PLL, always on for Ironlake */
  2764. reg = FDI_TX_CTL(pipe);
  2765. temp = I915_READ(reg);
  2766. if ((temp & FDI_TX_PLL_ENABLE) == 0) {
  2767. I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
  2768. POSTING_READ(reg);
  2769. udelay(100);
  2770. }
  2771. }
  2772. static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
  2773. {
  2774. struct drm_device *dev = intel_crtc->base.dev;
  2775. struct drm_i915_private *dev_priv = dev->dev_private;
  2776. int pipe = intel_crtc->pipe;
  2777. u32 reg, temp;
  2778. /* Switch from PCDclk to Rawclk */
  2779. reg = FDI_RX_CTL(pipe);
  2780. temp = I915_READ(reg);
  2781. I915_WRITE(reg, temp & ~FDI_PCDCLK);
  2782. /* Disable CPU FDI TX PLL */
  2783. reg = FDI_TX_CTL(pipe);
  2784. temp = I915_READ(reg);
  2785. I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
  2786. POSTING_READ(reg);
  2787. udelay(100);
  2788. reg = FDI_RX_CTL(pipe);
  2789. temp = I915_READ(reg);
  2790. I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
  2791. /* Wait for the clocks to turn off. */
  2792. POSTING_READ(reg);
  2793. udelay(100);
  2794. }
  2795. static void ironlake_fdi_disable(struct drm_crtc *crtc)
  2796. {
  2797. struct drm_device *dev = crtc->dev;
  2798. struct drm_i915_private *dev_priv = dev->dev_private;
  2799. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2800. int pipe = intel_crtc->pipe;
  2801. u32 reg, temp;
  2802. /* disable CPU FDI tx and PCH FDI rx */
  2803. reg = FDI_TX_CTL(pipe);
  2804. temp = I915_READ(reg);
  2805. I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
  2806. POSTING_READ(reg);
  2807. reg = FDI_RX_CTL(pipe);
  2808. temp = I915_READ(reg);
  2809. temp &= ~(0x7 << 16);
  2810. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2811. I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
  2812. POSTING_READ(reg);
  2813. udelay(100);
  2814. /* Ironlake workaround, disable clock pointer after downing FDI */
  2815. if (HAS_PCH_IBX(dev))
  2816. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
  2817. /* still set train pattern 1 */
  2818. reg = FDI_TX_CTL(pipe);
  2819. temp = I915_READ(reg);
  2820. temp &= ~FDI_LINK_TRAIN_NONE;
  2821. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2822. I915_WRITE(reg, temp);
  2823. reg = FDI_RX_CTL(pipe);
  2824. temp = I915_READ(reg);
  2825. if (HAS_PCH_CPT(dev)) {
  2826. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2827. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2828. } else {
  2829. temp &= ~FDI_LINK_TRAIN_NONE;
  2830. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2831. }
  2832. /* BPC in FDI rx is consistent with that in PIPECONF */
  2833. temp &= ~(0x07 << 16);
  2834. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2835. I915_WRITE(reg, temp);
  2836. POSTING_READ(reg);
  2837. udelay(100);
  2838. }
  2839. bool intel_has_pending_fb_unpin(struct drm_device *dev)
  2840. {
  2841. struct intel_crtc *crtc;
  2842. /* Note that we don't need to be called with mode_config.lock here
  2843. * as our list of CRTC objects is static for the lifetime of the
  2844. * device and so cannot disappear as we iterate. Similarly, we can
  2845. * happily treat the predicates as racy, atomic checks as userspace
  2846. * cannot claim and pin a new fb without at least acquring the
  2847. * struct_mutex and so serialising with us.
  2848. */
  2849. for_each_intel_crtc(dev, crtc) {
  2850. if (atomic_read(&crtc->unpin_work_count) == 0)
  2851. continue;
  2852. if (crtc->unpin_work)
  2853. intel_wait_for_vblank(dev, crtc->pipe);
  2854. return true;
  2855. }
  2856. return false;
  2857. }
  2858. void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
  2859. {
  2860. struct drm_device *dev = crtc->dev;
  2861. struct drm_i915_private *dev_priv = dev->dev_private;
  2862. if (crtc->primary->fb == NULL)
  2863. return;
  2864. WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue));
  2865. WARN_ON(wait_event_timeout(dev_priv->pending_flip_queue,
  2866. !intel_crtc_has_pending_flip(crtc),
  2867. 60*HZ) == 0);
  2868. mutex_lock(&dev->struct_mutex);
  2869. intel_finish_fb(crtc->primary->fb);
  2870. mutex_unlock(&dev->struct_mutex);
  2871. }
  2872. /* Program iCLKIP clock to the desired frequency */
  2873. static void lpt_program_iclkip(struct drm_crtc *crtc)
  2874. {
  2875. struct drm_device *dev = crtc->dev;
  2876. struct drm_i915_private *dev_priv = dev->dev_private;
  2877. int clock = to_intel_crtc(crtc)->config.adjusted_mode.crtc_clock;
  2878. u32 divsel, phaseinc, auxdiv, phasedir = 0;
  2879. u32 temp;
  2880. mutex_lock(&dev_priv->dpio_lock);
  2881. /* It is necessary to ungate the pixclk gate prior to programming
  2882. * the divisors, and gate it back when it is done.
  2883. */
  2884. I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
  2885. /* Disable SSCCTL */
  2886. intel_sbi_write(dev_priv, SBI_SSCCTL6,
  2887. intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK) |
  2888. SBI_SSCCTL_DISABLE,
  2889. SBI_ICLK);
  2890. /* 20MHz is a corner case which is out of range for the 7-bit divisor */
  2891. if (clock == 20000) {
  2892. auxdiv = 1;
  2893. divsel = 0x41;
  2894. phaseinc = 0x20;
  2895. } else {
  2896. /* The iCLK virtual clock root frequency is in MHz,
  2897. * but the adjusted_mode->crtc_clock in in KHz. To get the
  2898. * divisors, it is necessary to divide one by another, so we
  2899. * convert the virtual clock precision to KHz here for higher
  2900. * precision.
  2901. */
  2902. u32 iclk_virtual_root_freq = 172800 * 1000;
  2903. u32 iclk_pi_range = 64;
  2904. u32 desired_divisor, msb_divisor_value, pi_value;
  2905. desired_divisor = (iclk_virtual_root_freq / clock);
  2906. msb_divisor_value = desired_divisor / iclk_pi_range;
  2907. pi_value = desired_divisor % iclk_pi_range;
  2908. auxdiv = 0;
  2909. divsel = msb_divisor_value - 2;
  2910. phaseinc = pi_value;
  2911. }
  2912. /* This should not happen with any sane values */
  2913. WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
  2914. ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
  2915. WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) &
  2916. ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
  2917. DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
  2918. clock,
  2919. auxdiv,
  2920. divsel,
  2921. phasedir,
  2922. phaseinc);
  2923. /* Program SSCDIVINTPHASE6 */
  2924. temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
  2925. temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
  2926. temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
  2927. temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
  2928. temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
  2929. temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
  2930. temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
  2931. intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
  2932. /* Program SSCAUXDIV */
  2933. temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
  2934. temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
  2935. temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
  2936. intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
  2937. /* Enable modulator and associated divider */
  2938. temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
  2939. temp &= ~SBI_SSCCTL_DISABLE;
  2940. intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
  2941. /* Wait for initialization time */
  2942. udelay(24);
  2943. I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE);
  2944. mutex_unlock(&dev_priv->dpio_lock);
  2945. }
  2946. static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc,
  2947. enum pipe pch_transcoder)
  2948. {
  2949. struct drm_device *dev = crtc->base.dev;
  2950. struct drm_i915_private *dev_priv = dev->dev_private;
  2951. enum transcoder cpu_transcoder = crtc->config.cpu_transcoder;
  2952. I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder),
  2953. I915_READ(HTOTAL(cpu_transcoder)));
  2954. I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder),
  2955. I915_READ(HBLANK(cpu_transcoder)));
  2956. I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder),
  2957. I915_READ(HSYNC(cpu_transcoder)));
  2958. I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder),
  2959. I915_READ(VTOTAL(cpu_transcoder)));
  2960. I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder),
  2961. I915_READ(VBLANK(cpu_transcoder)));
  2962. I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder),
  2963. I915_READ(VSYNC(cpu_transcoder)));
  2964. I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder),
  2965. I915_READ(VSYNCSHIFT(cpu_transcoder)));
  2966. }
  2967. static void cpt_enable_fdi_bc_bifurcation(struct drm_device *dev)
  2968. {
  2969. struct drm_i915_private *dev_priv = dev->dev_private;
  2970. uint32_t temp;
  2971. temp = I915_READ(SOUTH_CHICKEN1);
  2972. if (temp & FDI_BC_BIFURCATION_SELECT)
  2973. return;
  2974. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
  2975. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
  2976. temp |= FDI_BC_BIFURCATION_SELECT;
  2977. DRM_DEBUG_KMS("enabling fdi C rx\n");
  2978. I915_WRITE(SOUTH_CHICKEN1, temp);
  2979. POSTING_READ(SOUTH_CHICKEN1);
  2980. }
  2981. static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc)
  2982. {
  2983. struct drm_device *dev = intel_crtc->base.dev;
  2984. struct drm_i915_private *dev_priv = dev->dev_private;
  2985. switch (intel_crtc->pipe) {
  2986. case PIPE_A:
  2987. break;
  2988. case PIPE_B:
  2989. if (intel_crtc->config.fdi_lanes > 2)
  2990. WARN_ON(I915_READ(SOUTH_CHICKEN1) & FDI_BC_BIFURCATION_SELECT);
  2991. else
  2992. cpt_enable_fdi_bc_bifurcation(dev);
  2993. break;
  2994. case PIPE_C:
  2995. cpt_enable_fdi_bc_bifurcation(dev);
  2996. break;
  2997. default:
  2998. BUG();
  2999. }
  3000. }
  3001. /*
  3002. * Enable PCH resources required for PCH ports:
  3003. * - PCH PLLs
  3004. * - FDI training & RX/TX
  3005. * - update transcoder timings
  3006. * - DP transcoding bits
  3007. * - transcoder
  3008. */
  3009. static void ironlake_pch_enable(struct drm_crtc *crtc)
  3010. {
  3011. struct drm_device *dev = crtc->dev;
  3012. struct drm_i915_private *dev_priv = dev->dev_private;
  3013. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3014. int pipe = intel_crtc->pipe;
  3015. u32 reg, temp;
  3016. assert_pch_transcoder_disabled(dev_priv, pipe);
  3017. if (IS_IVYBRIDGE(dev))
  3018. ivybridge_update_fdi_bc_bifurcation(intel_crtc);
  3019. /* Write the TU size bits before fdi link training, so that error
  3020. * detection works. */
  3021. I915_WRITE(FDI_RX_TUSIZE1(pipe),
  3022. I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
  3023. /* For PCH output, training FDI link */
  3024. dev_priv->display.fdi_link_train(crtc);
  3025. /* We need to program the right clock selection before writing the pixel
  3026. * mutliplier into the DPLL. */
  3027. if (HAS_PCH_CPT(dev)) {
  3028. u32 sel;
  3029. temp = I915_READ(PCH_DPLL_SEL);
  3030. temp |= TRANS_DPLL_ENABLE(pipe);
  3031. sel = TRANS_DPLLB_SEL(pipe);
  3032. if (intel_crtc->config.shared_dpll == DPLL_ID_PCH_PLL_B)
  3033. temp |= sel;
  3034. else
  3035. temp &= ~sel;
  3036. I915_WRITE(PCH_DPLL_SEL, temp);
  3037. }
  3038. /* XXX: pch pll's can be enabled any time before we enable the PCH
  3039. * transcoder, and we actually should do this to not upset any PCH
  3040. * transcoder that already use the clock when we share it.
  3041. *
  3042. * Note that enable_shared_dpll tries to do the right thing, but
  3043. * get_shared_dpll unconditionally resets the pll - we need that to have
  3044. * the right LVDS enable sequence. */
  3045. intel_enable_shared_dpll(intel_crtc);
  3046. /* set transcoder timing, panel must allow it */
  3047. assert_panel_unlocked(dev_priv, pipe);
  3048. ironlake_pch_transcoder_set_timings(intel_crtc, pipe);
  3049. intel_fdi_normal_train(crtc);
  3050. /* For PCH DP, enable TRANS_DP_CTL */
  3051. if (HAS_PCH_CPT(dev) &&
  3052. (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) ||
  3053. intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) {
  3054. u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
  3055. reg = TRANS_DP_CTL(pipe);
  3056. temp = I915_READ(reg);
  3057. temp &= ~(TRANS_DP_PORT_SEL_MASK |
  3058. TRANS_DP_SYNC_MASK |
  3059. TRANS_DP_BPC_MASK);
  3060. temp |= (TRANS_DP_OUTPUT_ENABLE |
  3061. TRANS_DP_ENH_FRAMING);
  3062. temp |= bpc << 9; /* same format but at 11:9 */
  3063. if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC)
  3064. temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
  3065. if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC)
  3066. temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
  3067. switch (intel_trans_dp_port_sel(crtc)) {
  3068. case PCH_DP_B:
  3069. temp |= TRANS_DP_PORT_SEL_B;
  3070. break;
  3071. case PCH_DP_C:
  3072. temp |= TRANS_DP_PORT_SEL_C;
  3073. break;
  3074. case PCH_DP_D:
  3075. temp |= TRANS_DP_PORT_SEL_D;
  3076. break;
  3077. default:
  3078. BUG();
  3079. }
  3080. I915_WRITE(reg, temp);
  3081. }
  3082. ironlake_enable_pch_transcoder(dev_priv, pipe);
  3083. }
  3084. static void lpt_pch_enable(struct drm_crtc *crtc)
  3085. {
  3086. struct drm_device *dev = crtc->dev;
  3087. struct drm_i915_private *dev_priv = dev->dev_private;
  3088. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3089. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  3090. assert_pch_transcoder_disabled(dev_priv, TRANSCODER_A);
  3091. lpt_program_iclkip(crtc);
  3092. /* Set transcoder timing. */
  3093. ironlake_pch_transcoder_set_timings(intel_crtc, PIPE_A);
  3094. lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
  3095. }
  3096. static void intel_put_shared_dpll(struct intel_crtc *crtc)
  3097. {
  3098. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  3099. if (pll == NULL)
  3100. return;
  3101. if (pll->refcount == 0) {
  3102. WARN(1, "bad %s refcount\n", pll->name);
  3103. return;
  3104. }
  3105. if (--pll->refcount == 0) {
  3106. WARN_ON(pll->on);
  3107. WARN_ON(pll->active);
  3108. }
  3109. crtc->config.shared_dpll = DPLL_ID_PRIVATE;
  3110. }
  3111. static struct intel_shared_dpll *intel_get_shared_dpll(struct intel_crtc *crtc)
  3112. {
  3113. struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
  3114. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  3115. enum intel_dpll_id i;
  3116. if (pll) {
  3117. DRM_DEBUG_KMS("CRTC:%d dropping existing %s\n",
  3118. crtc->base.base.id, pll->name);
  3119. intel_put_shared_dpll(crtc);
  3120. }
  3121. if (HAS_PCH_IBX(dev_priv->dev)) {
  3122. /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */
  3123. i = (enum intel_dpll_id) crtc->pipe;
  3124. pll = &dev_priv->shared_dplls[i];
  3125. DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n",
  3126. crtc->base.base.id, pll->name);
  3127. WARN_ON(pll->refcount);
  3128. goto found;
  3129. }
  3130. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  3131. pll = &dev_priv->shared_dplls[i];
  3132. /* Only want to check enabled timings first */
  3133. if (pll->refcount == 0)
  3134. continue;
  3135. if (memcmp(&crtc->config.dpll_hw_state, &pll->hw_state,
  3136. sizeof(pll->hw_state)) == 0) {
  3137. DRM_DEBUG_KMS("CRTC:%d sharing existing %s (refcount %d, ative %d)\n",
  3138. crtc->base.base.id,
  3139. pll->name, pll->refcount, pll->active);
  3140. goto found;
  3141. }
  3142. }
  3143. /* Ok no matching timings, maybe there's a free one? */
  3144. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  3145. pll = &dev_priv->shared_dplls[i];
  3146. if (pll->refcount == 0) {
  3147. DRM_DEBUG_KMS("CRTC:%d allocated %s\n",
  3148. crtc->base.base.id, pll->name);
  3149. goto found;
  3150. }
  3151. }
  3152. return NULL;
  3153. found:
  3154. if (pll->refcount == 0)
  3155. pll->hw_state = crtc->config.dpll_hw_state;
  3156. crtc->config.shared_dpll = i;
  3157. DRM_DEBUG_DRIVER("using %s for pipe %c\n", pll->name,
  3158. pipe_name(crtc->pipe));
  3159. pll->refcount++;
  3160. return pll;
  3161. }
  3162. static void cpt_verify_modeset(struct drm_device *dev, int pipe)
  3163. {
  3164. struct drm_i915_private *dev_priv = dev->dev_private;
  3165. int dslreg = PIPEDSL(pipe);
  3166. u32 temp;
  3167. temp = I915_READ(dslreg);
  3168. udelay(500);
  3169. if (wait_for(I915_READ(dslreg) != temp, 5)) {
  3170. if (wait_for(I915_READ(dslreg) != temp, 5))
  3171. DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe));
  3172. }
  3173. }
  3174. static void ironlake_pfit_enable(struct intel_crtc *crtc)
  3175. {
  3176. struct drm_device *dev = crtc->base.dev;
  3177. struct drm_i915_private *dev_priv = dev->dev_private;
  3178. int pipe = crtc->pipe;
  3179. if (crtc->config.pch_pfit.enabled) {
  3180. /* Force use of hard-coded filter coefficients
  3181. * as some pre-programmed values are broken,
  3182. * e.g. x201.
  3183. */
  3184. if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev))
  3185. I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
  3186. PF_PIPE_SEL_IVB(pipe));
  3187. else
  3188. I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
  3189. I915_WRITE(PF_WIN_POS(pipe), crtc->config.pch_pfit.pos);
  3190. I915_WRITE(PF_WIN_SZ(pipe), crtc->config.pch_pfit.size);
  3191. }
  3192. }
  3193. static void intel_enable_planes(struct drm_crtc *crtc)
  3194. {
  3195. struct drm_device *dev = crtc->dev;
  3196. enum pipe pipe = to_intel_crtc(crtc)->pipe;
  3197. struct drm_plane *plane;
  3198. struct intel_plane *intel_plane;
  3199. drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) {
  3200. intel_plane = to_intel_plane(plane);
  3201. if (intel_plane->pipe == pipe)
  3202. intel_plane_restore(&intel_plane->base);
  3203. }
  3204. }
  3205. static void intel_disable_planes(struct drm_crtc *crtc)
  3206. {
  3207. struct drm_device *dev = crtc->dev;
  3208. enum pipe pipe = to_intel_crtc(crtc)->pipe;
  3209. struct drm_plane *plane;
  3210. struct intel_plane *intel_plane;
  3211. drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) {
  3212. intel_plane = to_intel_plane(plane);
  3213. if (intel_plane->pipe == pipe)
  3214. intel_plane_disable(&intel_plane->base);
  3215. }
  3216. }
  3217. void hsw_enable_ips(struct intel_crtc *crtc)
  3218. {
  3219. struct drm_device *dev = crtc->base.dev;
  3220. struct drm_i915_private *dev_priv = dev->dev_private;
  3221. if (!crtc->config.ips_enabled)
  3222. return;
  3223. /* We can only enable IPS after we enable a plane and wait for a vblank */
  3224. intel_wait_for_vblank(dev, crtc->pipe);
  3225. assert_plane_enabled(dev_priv, crtc->plane);
  3226. if (IS_BROADWELL(dev)) {
  3227. mutex_lock(&dev_priv->rps.hw_lock);
  3228. WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0xc0000000));
  3229. mutex_unlock(&dev_priv->rps.hw_lock);
  3230. /* Quoting Art Runyan: "its not safe to expect any particular
  3231. * value in IPS_CTL bit 31 after enabling IPS through the
  3232. * mailbox." Moreover, the mailbox may return a bogus state,
  3233. * so we need to just enable it and continue on.
  3234. */
  3235. } else {
  3236. I915_WRITE(IPS_CTL, IPS_ENABLE);
  3237. /* The bit only becomes 1 in the next vblank, so this wait here
  3238. * is essentially intel_wait_for_vblank. If we don't have this
  3239. * and don't wait for vblanks until the end of crtc_enable, then
  3240. * the HW state readout code will complain that the expected
  3241. * IPS_CTL value is not the one we read. */
  3242. if (wait_for(I915_READ_NOTRACE(IPS_CTL) & IPS_ENABLE, 50))
  3243. DRM_ERROR("Timed out waiting for IPS enable\n");
  3244. }
  3245. }
  3246. void hsw_disable_ips(struct intel_crtc *crtc)
  3247. {
  3248. struct drm_device *dev = crtc->base.dev;
  3249. struct drm_i915_private *dev_priv = dev->dev_private;
  3250. if (!crtc->config.ips_enabled)
  3251. return;
  3252. assert_plane_enabled(dev_priv, crtc->plane);
  3253. if (IS_BROADWELL(dev)) {
  3254. mutex_lock(&dev_priv->rps.hw_lock);
  3255. WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0));
  3256. mutex_unlock(&dev_priv->rps.hw_lock);
  3257. /* wait for pcode to finish disabling IPS, which may take up to 42ms */
  3258. if (wait_for((I915_READ(IPS_CTL) & IPS_ENABLE) == 0, 42))
  3259. DRM_ERROR("Timed out waiting for IPS disable\n");
  3260. } else {
  3261. I915_WRITE(IPS_CTL, 0);
  3262. POSTING_READ(IPS_CTL);
  3263. }
  3264. /* We need to wait for a vblank before we can disable the plane. */
  3265. intel_wait_for_vblank(dev, crtc->pipe);
  3266. }
  3267. /** Loads the palette/gamma unit for the CRTC with the prepared values */
  3268. static void intel_crtc_load_lut(struct drm_crtc *crtc)
  3269. {
  3270. struct drm_device *dev = crtc->dev;
  3271. struct drm_i915_private *dev_priv = dev->dev_private;
  3272. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3273. enum pipe pipe = intel_crtc->pipe;
  3274. int palreg = PALETTE(pipe);
  3275. int i;
  3276. bool reenable_ips = false;
  3277. /* The clocks have to be on to load the palette. */
  3278. if (!crtc->enabled || !intel_crtc->active)
  3279. return;
  3280. if (!HAS_PCH_SPLIT(dev_priv->dev)) {
  3281. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI))
  3282. assert_dsi_pll_enabled(dev_priv);
  3283. else
  3284. assert_pll_enabled(dev_priv, pipe);
  3285. }
  3286. /* use legacy palette for Ironlake */
  3287. if (HAS_PCH_SPLIT(dev))
  3288. palreg = LGC_PALETTE(pipe);
  3289. /* Workaround : Do not read or write the pipe palette/gamma data while
  3290. * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
  3291. */
  3292. if (IS_HASWELL(dev) && intel_crtc->config.ips_enabled &&
  3293. ((I915_READ(GAMMA_MODE(pipe)) & GAMMA_MODE_MODE_MASK) ==
  3294. GAMMA_MODE_MODE_SPLIT)) {
  3295. hsw_disable_ips(intel_crtc);
  3296. reenable_ips = true;
  3297. }
  3298. for (i = 0; i < 256; i++) {
  3299. I915_WRITE(palreg + 4 * i,
  3300. (intel_crtc->lut_r[i] << 16) |
  3301. (intel_crtc->lut_g[i] << 8) |
  3302. intel_crtc->lut_b[i]);
  3303. }
  3304. if (reenable_ips)
  3305. hsw_enable_ips(intel_crtc);
  3306. }
  3307. static void intel_crtc_dpms_overlay(struct intel_crtc *intel_crtc, bool enable)
  3308. {
  3309. if (!enable && intel_crtc->overlay) {
  3310. struct drm_device *dev = intel_crtc->base.dev;
  3311. struct drm_i915_private *dev_priv = dev->dev_private;
  3312. mutex_lock(&dev->struct_mutex);
  3313. dev_priv->mm.interruptible = false;
  3314. (void) intel_overlay_switch_off(intel_crtc->overlay);
  3315. dev_priv->mm.interruptible = true;
  3316. mutex_unlock(&dev->struct_mutex);
  3317. }
  3318. /* Let userspace switch the overlay on again. In most cases userspace
  3319. * has to recompute where to put it anyway.
  3320. */
  3321. }
  3322. static void intel_crtc_enable_planes(struct drm_crtc *crtc)
  3323. {
  3324. struct drm_device *dev = crtc->dev;
  3325. struct drm_i915_private *dev_priv = dev->dev_private;
  3326. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3327. int pipe = intel_crtc->pipe;
  3328. int plane = intel_crtc->plane;
  3329. drm_vblank_on(dev, pipe);
  3330. intel_enable_primary_hw_plane(dev_priv, plane, pipe);
  3331. intel_enable_planes(crtc);
  3332. intel_crtc_update_cursor(crtc, true);
  3333. intel_crtc_dpms_overlay(intel_crtc, true);
  3334. hsw_enable_ips(intel_crtc);
  3335. mutex_lock(&dev->struct_mutex);
  3336. intel_update_fbc(dev);
  3337. mutex_unlock(&dev->struct_mutex);
  3338. /*
  3339. * FIXME: Once we grow proper nuclear flip support out of this we need
  3340. * to compute the mask of flip planes precisely. For the time being
  3341. * consider this a flip from a NULL plane.
  3342. */
  3343. intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe));
  3344. }
  3345. static void intel_crtc_disable_planes(struct drm_crtc *crtc)
  3346. {
  3347. struct drm_device *dev = crtc->dev;
  3348. struct drm_i915_private *dev_priv = dev->dev_private;
  3349. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3350. int pipe = intel_crtc->pipe;
  3351. int plane = intel_crtc->plane;
  3352. intel_crtc_wait_for_pending_flips(crtc);
  3353. if (dev_priv->fbc.plane == plane)
  3354. intel_disable_fbc(dev);
  3355. hsw_disable_ips(intel_crtc);
  3356. intel_crtc_dpms_overlay(intel_crtc, false);
  3357. intel_crtc_update_cursor(crtc, false);
  3358. intel_disable_planes(crtc);
  3359. intel_disable_primary_hw_plane(dev_priv, plane, pipe);
  3360. /*
  3361. * FIXME: Once we grow proper nuclear flip support out of this we need
  3362. * to compute the mask of flip planes precisely. For the time being
  3363. * consider this a flip to a NULL plane.
  3364. */
  3365. intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe));
  3366. drm_vblank_off(dev, pipe);
  3367. }
  3368. static void ironlake_crtc_enable(struct drm_crtc *crtc)
  3369. {
  3370. struct drm_device *dev = crtc->dev;
  3371. struct drm_i915_private *dev_priv = dev->dev_private;
  3372. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3373. struct intel_encoder *encoder;
  3374. int pipe = intel_crtc->pipe;
  3375. enum plane plane = intel_crtc->plane;
  3376. WARN_ON(!crtc->enabled);
  3377. if (intel_crtc->active)
  3378. return;
  3379. if (intel_crtc->config.has_pch_encoder)
  3380. intel_prepare_shared_dpll(intel_crtc);
  3381. if (intel_crtc->config.has_dp_encoder)
  3382. intel_dp_set_m_n(intel_crtc);
  3383. intel_set_pipe_timings(intel_crtc);
  3384. if (intel_crtc->config.has_pch_encoder) {
  3385. intel_cpu_transcoder_set_m_n(intel_crtc,
  3386. &intel_crtc->config.fdi_m_n);
  3387. }
  3388. ironlake_set_pipeconf(crtc);
  3389. /* Set up the display plane register */
  3390. I915_WRITE(DSPCNTR(plane), DISPPLANE_GAMMA_ENABLE);
  3391. POSTING_READ(DSPCNTR(plane));
  3392. dev_priv->display.update_primary_plane(crtc, crtc->primary->fb,
  3393. crtc->x, crtc->y);
  3394. intel_crtc->active = true;
  3395. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  3396. intel_set_pch_fifo_underrun_reporting(dev, pipe, true);
  3397. for_each_encoder_on_crtc(dev, crtc, encoder)
  3398. if (encoder->pre_enable)
  3399. encoder->pre_enable(encoder);
  3400. if (intel_crtc->config.has_pch_encoder) {
  3401. /* Note: FDI PLL enabling _must_ be done before we enable the
  3402. * cpu pipes, hence this is separate from all the other fdi/pch
  3403. * enabling. */
  3404. ironlake_fdi_pll_enable(intel_crtc);
  3405. } else {
  3406. assert_fdi_tx_disabled(dev_priv, pipe);
  3407. assert_fdi_rx_disabled(dev_priv, pipe);
  3408. }
  3409. ironlake_pfit_enable(intel_crtc);
  3410. /*
  3411. * On ILK+ LUT must be loaded before the pipe is running but with
  3412. * clocks enabled
  3413. */
  3414. intel_crtc_load_lut(crtc);
  3415. intel_update_watermarks(crtc);
  3416. intel_enable_pipe(intel_crtc);
  3417. if (intel_crtc->config.has_pch_encoder)
  3418. ironlake_pch_enable(crtc);
  3419. for_each_encoder_on_crtc(dev, crtc, encoder)
  3420. encoder->enable(encoder);
  3421. if (HAS_PCH_CPT(dev))
  3422. cpt_verify_modeset(dev, intel_crtc->pipe);
  3423. intel_crtc_enable_planes(crtc);
  3424. }
  3425. /* IPS only exists on ULT machines and is tied to pipe A. */
  3426. static bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
  3427. {
  3428. return HAS_IPS(crtc->base.dev) && crtc->pipe == PIPE_A;
  3429. }
  3430. /*
  3431. * This implements the workaround described in the "notes" section of the mode
  3432. * set sequence documentation. When going from no pipes or single pipe to
  3433. * multiple pipes, and planes are enabled after the pipe, we need to wait at
  3434. * least 2 vblanks on the first pipe before enabling planes on the second pipe.
  3435. */
  3436. static void haswell_mode_set_planes_workaround(struct intel_crtc *crtc)
  3437. {
  3438. struct drm_device *dev = crtc->base.dev;
  3439. struct intel_crtc *crtc_it, *other_active_crtc = NULL;
  3440. /* We want to get the other_active_crtc only if there's only 1 other
  3441. * active crtc. */
  3442. for_each_intel_crtc(dev, crtc_it) {
  3443. if (!crtc_it->active || crtc_it == crtc)
  3444. continue;
  3445. if (other_active_crtc)
  3446. return;
  3447. other_active_crtc = crtc_it;
  3448. }
  3449. if (!other_active_crtc)
  3450. return;
  3451. intel_wait_for_vblank(dev, other_active_crtc->pipe);
  3452. intel_wait_for_vblank(dev, other_active_crtc->pipe);
  3453. }
  3454. static void haswell_crtc_enable(struct drm_crtc *crtc)
  3455. {
  3456. struct drm_device *dev = crtc->dev;
  3457. struct drm_i915_private *dev_priv = dev->dev_private;
  3458. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3459. struct intel_encoder *encoder;
  3460. int pipe = intel_crtc->pipe;
  3461. enum plane plane = intel_crtc->plane;
  3462. WARN_ON(!crtc->enabled);
  3463. if (intel_crtc->active)
  3464. return;
  3465. if (intel_crtc->config.has_dp_encoder)
  3466. intel_dp_set_m_n(intel_crtc);
  3467. intel_set_pipe_timings(intel_crtc);
  3468. if (intel_crtc->config.has_pch_encoder) {
  3469. intel_cpu_transcoder_set_m_n(intel_crtc,
  3470. &intel_crtc->config.fdi_m_n);
  3471. }
  3472. haswell_set_pipeconf(crtc);
  3473. intel_set_pipe_csc(crtc);
  3474. /* Set up the display plane register */
  3475. I915_WRITE(DSPCNTR(plane), DISPPLANE_GAMMA_ENABLE | DISPPLANE_PIPE_CSC_ENABLE);
  3476. POSTING_READ(DSPCNTR(plane));
  3477. dev_priv->display.update_primary_plane(crtc, crtc->primary->fb,
  3478. crtc->x, crtc->y);
  3479. intel_crtc->active = true;
  3480. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  3481. if (intel_crtc->config.has_pch_encoder)
  3482. intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, true);
  3483. if (intel_crtc->config.has_pch_encoder)
  3484. dev_priv->display.fdi_link_train(crtc);
  3485. for_each_encoder_on_crtc(dev, crtc, encoder)
  3486. if (encoder->pre_enable)
  3487. encoder->pre_enable(encoder);
  3488. intel_ddi_enable_pipe_clock(intel_crtc);
  3489. ironlake_pfit_enable(intel_crtc);
  3490. /*
  3491. * On ILK+ LUT must be loaded before the pipe is running but with
  3492. * clocks enabled
  3493. */
  3494. intel_crtc_load_lut(crtc);
  3495. intel_ddi_set_pipe_settings(crtc);
  3496. intel_ddi_enable_transcoder_func(crtc);
  3497. intel_update_watermarks(crtc);
  3498. intel_enable_pipe(intel_crtc);
  3499. if (intel_crtc->config.has_pch_encoder)
  3500. lpt_pch_enable(crtc);
  3501. for_each_encoder_on_crtc(dev, crtc, encoder) {
  3502. encoder->enable(encoder);
  3503. intel_opregion_notify_encoder(encoder, true);
  3504. }
  3505. /* If we change the relative order between pipe/planes enabling, we need
  3506. * to change the workaround. */
  3507. haswell_mode_set_planes_workaround(intel_crtc);
  3508. intel_crtc_enable_planes(crtc);
  3509. }
  3510. static void ironlake_pfit_disable(struct intel_crtc *crtc)
  3511. {
  3512. struct drm_device *dev = crtc->base.dev;
  3513. struct drm_i915_private *dev_priv = dev->dev_private;
  3514. int pipe = crtc->pipe;
  3515. /* To avoid upsetting the power well on haswell only disable the pfit if
  3516. * it's in use. The hw state code will make sure we get this right. */
  3517. if (crtc->config.pch_pfit.enabled) {
  3518. I915_WRITE(PF_CTL(pipe), 0);
  3519. I915_WRITE(PF_WIN_POS(pipe), 0);
  3520. I915_WRITE(PF_WIN_SZ(pipe), 0);
  3521. }
  3522. }
  3523. static void ironlake_crtc_disable(struct drm_crtc *crtc)
  3524. {
  3525. struct drm_device *dev = crtc->dev;
  3526. struct drm_i915_private *dev_priv = dev->dev_private;
  3527. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3528. struct intel_encoder *encoder;
  3529. int pipe = intel_crtc->pipe;
  3530. u32 reg, temp;
  3531. if (!intel_crtc->active)
  3532. return;
  3533. intel_crtc_disable_planes(crtc);
  3534. for_each_encoder_on_crtc(dev, crtc, encoder)
  3535. encoder->disable(encoder);
  3536. if (intel_crtc->config.has_pch_encoder)
  3537. intel_set_pch_fifo_underrun_reporting(dev, pipe, false);
  3538. intel_disable_pipe(dev_priv, pipe);
  3539. ironlake_pfit_disable(intel_crtc);
  3540. for_each_encoder_on_crtc(dev, crtc, encoder)
  3541. if (encoder->post_disable)
  3542. encoder->post_disable(encoder);
  3543. if (intel_crtc->config.has_pch_encoder) {
  3544. ironlake_fdi_disable(crtc);
  3545. ironlake_disable_pch_transcoder(dev_priv, pipe);
  3546. intel_set_pch_fifo_underrun_reporting(dev, pipe, true);
  3547. if (HAS_PCH_CPT(dev)) {
  3548. /* disable TRANS_DP_CTL */
  3549. reg = TRANS_DP_CTL(pipe);
  3550. temp = I915_READ(reg);
  3551. temp &= ~(TRANS_DP_OUTPUT_ENABLE |
  3552. TRANS_DP_PORT_SEL_MASK);
  3553. temp |= TRANS_DP_PORT_SEL_NONE;
  3554. I915_WRITE(reg, temp);
  3555. /* disable DPLL_SEL */
  3556. temp = I915_READ(PCH_DPLL_SEL);
  3557. temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe));
  3558. I915_WRITE(PCH_DPLL_SEL, temp);
  3559. }
  3560. /* disable PCH DPLL */
  3561. intel_disable_shared_dpll(intel_crtc);
  3562. ironlake_fdi_pll_disable(intel_crtc);
  3563. }
  3564. intel_crtc->active = false;
  3565. intel_update_watermarks(crtc);
  3566. mutex_lock(&dev->struct_mutex);
  3567. intel_update_fbc(dev);
  3568. mutex_unlock(&dev->struct_mutex);
  3569. }
  3570. static void haswell_crtc_disable(struct drm_crtc *crtc)
  3571. {
  3572. struct drm_device *dev = crtc->dev;
  3573. struct drm_i915_private *dev_priv = dev->dev_private;
  3574. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3575. struct intel_encoder *encoder;
  3576. int pipe = intel_crtc->pipe;
  3577. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  3578. if (!intel_crtc->active)
  3579. return;
  3580. intel_crtc_disable_planes(crtc);
  3581. for_each_encoder_on_crtc(dev, crtc, encoder) {
  3582. intel_opregion_notify_encoder(encoder, false);
  3583. encoder->disable(encoder);
  3584. }
  3585. if (intel_crtc->config.has_pch_encoder)
  3586. intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, false);
  3587. intel_disable_pipe(dev_priv, pipe);
  3588. intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder);
  3589. ironlake_pfit_disable(intel_crtc);
  3590. intel_ddi_disable_pipe_clock(intel_crtc);
  3591. for_each_encoder_on_crtc(dev, crtc, encoder)
  3592. if (encoder->post_disable)
  3593. encoder->post_disable(encoder);
  3594. if (intel_crtc->config.has_pch_encoder) {
  3595. lpt_disable_pch_transcoder(dev_priv);
  3596. intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, true);
  3597. intel_ddi_fdi_disable(crtc);
  3598. }
  3599. intel_crtc->active = false;
  3600. intel_update_watermarks(crtc);
  3601. mutex_lock(&dev->struct_mutex);
  3602. intel_update_fbc(dev);
  3603. mutex_unlock(&dev->struct_mutex);
  3604. }
  3605. static void ironlake_crtc_off(struct drm_crtc *crtc)
  3606. {
  3607. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3608. intel_put_shared_dpll(intel_crtc);
  3609. }
  3610. static void haswell_crtc_off(struct drm_crtc *crtc)
  3611. {
  3612. intel_ddi_put_crtc_pll(crtc);
  3613. }
  3614. static void i9xx_pfit_enable(struct intel_crtc *crtc)
  3615. {
  3616. struct drm_device *dev = crtc->base.dev;
  3617. struct drm_i915_private *dev_priv = dev->dev_private;
  3618. struct intel_crtc_config *pipe_config = &crtc->config;
  3619. if (!crtc->config.gmch_pfit.control)
  3620. return;
  3621. /*
  3622. * The panel fitter should only be adjusted whilst the pipe is disabled,
  3623. * according to register description and PRM.
  3624. */
  3625. WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE);
  3626. assert_pipe_disabled(dev_priv, crtc->pipe);
  3627. I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios);
  3628. I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control);
  3629. /* Border color in case we don't scale up to the full screen. Black by
  3630. * default, change to something else for debugging. */
  3631. I915_WRITE(BCLRPAT(crtc->pipe), 0);
  3632. }
  3633. #define for_each_power_domain(domain, mask) \
  3634. for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \
  3635. if ((1 << (domain)) & (mask))
  3636. enum intel_display_power_domain
  3637. intel_display_port_power_domain(struct intel_encoder *intel_encoder)
  3638. {
  3639. struct drm_device *dev = intel_encoder->base.dev;
  3640. struct intel_digital_port *intel_dig_port;
  3641. switch (intel_encoder->type) {
  3642. case INTEL_OUTPUT_UNKNOWN:
  3643. /* Only DDI platforms should ever use this output type */
  3644. WARN_ON_ONCE(!HAS_DDI(dev));
  3645. case INTEL_OUTPUT_DISPLAYPORT:
  3646. case INTEL_OUTPUT_HDMI:
  3647. case INTEL_OUTPUT_EDP:
  3648. intel_dig_port = enc_to_dig_port(&intel_encoder->base);
  3649. switch (intel_dig_port->port) {
  3650. case PORT_A:
  3651. return POWER_DOMAIN_PORT_DDI_A_4_LANES;
  3652. case PORT_B:
  3653. return POWER_DOMAIN_PORT_DDI_B_4_LANES;
  3654. case PORT_C:
  3655. return POWER_DOMAIN_PORT_DDI_C_4_LANES;
  3656. case PORT_D:
  3657. return POWER_DOMAIN_PORT_DDI_D_4_LANES;
  3658. default:
  3659. WARN_ON_ONCE(1);
  3660. return POWER_DOMAIN_PORT_OTHER;
  3661. }
  3662. case INTEL_OUTPUT_ANALOG:
  3663. return POWER_DOMAIN_PORT_CRT;
  3664. case INTEL_OUTPUT_DSI:
  3665. return POWER_DOMAIN_PORT_DSI;
  3666. default:
  3667. return POWER_DOMAIN_PORT_OTHER;
  3668. }
  3669. }
  3670. static unsigned long get_crtc_power_domains(struct drm_crtc *crtc)
  3671. {
  3672. struct drm_device *dev = crtc->dev;
  3673. struct intel_encoder *intel_encoder;
  3674. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3675. enum pipe pipe = intel_crtc->pipe;
  3676. unsigned long mask;
  3677. enum transcoder transcoder;
  3678. transcoder = intel_pipe_to_cpu_transcoder(dev->dev_private, pipe);
  3679. mask = BIT(POWER_DOMAIN_PIPE(pipe));
  3680. mask |= BIT(POWER_DOMAIN_TRANSCODER(transcoder));
  3681. if (intel_crtc->config.pch_pfit.enabled ||
  3682. intel_crtc->config.pch_pfit.force_thru)
  3683. mask |= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe));
  3684. for_each_encoder_on_crtc(dev, crtc, intel_encoder)
  3685. mask |= BIT(intel_display_port_power_domain(intel_encoder));
  3686. return mask;
  3687. }
  3688. void intel_display_set_init_power(struct drm_i915_private *dev_priv,
  3689. bool enable)
  3690. {
  3691. if (dev_priv->power_domains.init_power_on == enable)
  3692. return;
  3693. if (enable)
  3694. intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
  3695. else
  3696. intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
  3697. dev_priv->power_domains.init_power_on = enable;
  3698. }
  3699. static void modeset_update_crtc_power_domains(struct drm_device *dev)
  3700. {
  3701. struct drm_i915_private *dev_priv = dev->dev_private;
  3702. unsigned long pipe_domains[I915_MAX_PIPES] = { 0, };
  3703. struct intel_crtc *crtc;
  3704. /*
  3705. * First get all needed power domains, then put all unneeded, to avoid
  3706. * any unnecessary toggling of the power wells.
  3707. */
  3708. for_each_intel_crtc(dev, crtc) {
  3709. enum intel_display_power_domain domain;
  3710. if (!crtc->base.enabled)
  3711. continue;
  3712. pipe_domains[crtc->pipe] = get_crtc_power_domains(&crtc->base);
  3713. for_each_power_domain(domain, pipe_domains[crtc->pipe])
  3714. intel_display_power_get(dev_priv, domain);
  3715. }
  3716. for_each_intel_crtc(dev, crtc) {
  3717. enum intel_display_power_domain domain;
  3718. for_each_power_domain(domain, crtc->enabled_power_domains)
  3719. intel_display_power_put(dev_priv, domain);
  3720. crtc->enabled_power_domains = pipe_domains[crtc->pipe];
  3721. }
  3722. intel_display_set_init_power(dev_priv, false);
  3723. }
  3724. /* returns HPLL frequency in kHz */
  3725. static int valleyview_get_vco(struct drm_i915_private *dev_priv)
  3726. {
  3727. int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 };
  3728. /* Obtain SKU information */
  3729. mutex_lock(&dev_priv->dpio_lock);
  3730. hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) &
  3731. CCK_FUSE_HPLL_FREQ_MASK;
  3732. mutex_unlock(&dev_priv->dpio_lock);
  3733. return vco_freq[hpll_freq] * 1000;
  3734. }
  3735. static void vlv_update_cdclk(struct drm_device *dev)
  3736. {
  3737. struct drm_i915_private *dev_priv = dev->dev_private;
  3738. dev_priv->vlv_cdclk_freq = dev_priv->display.get_display_clock_speed(dev);
  3739. DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz",
  3740. dev_priv->vlv_cdclk_freq);
  3741. /*
  3742. * Program the gmbus_freq based on the cdclk frequency.
  3743. * BSpec erroneously claims we should aim for 4MHz, but
  3744. * in fact 1MHz is the correct frequency.
  3745. */
  3746. I915_WRITE(GMBUSFREQ_VLV, dev_priv->vlv_cdclk_freq);
  3747. }
  3748. /* Adjust CDclk dividers to allow high res or save power if possible */
  3749. static void valleyview_set_cdclk(struct drm_device *dev, int cdclk)
  3750. {
  3751. struct drm_i915_private *dev_priv = dev->dev_private;
  3752. u32 val, cmd;
  3753. WARN_ON(dev_priv->display.get_display_clock_speed(dev) != dev_priv->vlv_cdclk_freq);
  3754. if (cdclk >= 320000) /* jump to highest voltage for 400MHz too */
  3755. cmd = 2;
  3756. else if (cdclk == 266667)
  3757. cmd = 1;
  3758. else
  3759. cmd = 0;
  3760. mutex_lock(&dev_priv->rps.hw_lock);
  3761. val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
  3762. val &= ~DSPFREQGUAR_MASK;
  3763. val |= (cmd << DSPFREQGUAR_SHIFT);
  3764. vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val);
  3765. if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) &
  3766. DSPFREQSTAT_MASK) == (cmd << DSPFREQSTAT_SHIFT),
  3767. 50)) {
  3768. DRM_ERROR("timed out waiting for CDclk change\n");
  3769. }
  3770. mutex_unlock(&dev_priv->rps.hw_lock);
  3771. if (cdclk == 400000) {
  3772. u32 divider, vco;
  3773. vco = valleyview_get_vco(dev_priv);
  3774. divider = DIV_ROUND_CLOSEST(vco << 1, cdclk) - 1;
  3775. mutex_lock(&dev_priv->dpio_lock);
  3776. /* adjust cdclk divider */
  3777. val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL);
  3778. val &= ~DISPLAY_FREQUENCY_VALUES;
  3779. val |= divider;
  3780. vlv_cck_write(dev_priv, CCK_DISPLAY_CLOCK_CONTROL, val);
  3781. if (wait_for((vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL) &
  3782. DISPLAY_FREQUENCY_STATUS) == (divider << DISPLAY_FREQUENCY_STATUS_SHIFT),
  3783. 50))
  3784. DRM_ERROR("timed out waiting for CDclk change\n");
  3785. mutex_unlock(&dev_priv->dpio_lock);
  3786. }
  3787. mutex_lock(&dev_priv->dpio_lock);
  3788. /* adjust self-refresh exit latency value */
  3789. val = vlv_bunit_read(dev_priv, BUNIT_REG_BISOC);
  3790. val &= ~0x7f;
  3791. /*
  3792. * For high bandwidth configs, we set a higher latency in the bunit
  3793. * so that the core display fetch happens in time to avoid underruns.
  3794. */
  3795. if (cdclk == 400000)
  3796. val |= 4500 / 250; /* 4.5 usec */
  3797. else
  3798. val |= 3000 / 250; /* 3.0 usec */
  3799. vlv_bunit_write(dev_priv, BUNIT_REG_BISOC, val);
  3800. mutex_unlock(&dev_priv->dpio_lock);
  3801. vlv_update_cdclk(dev);
  3802. }
  3803. static int valleyview_calc_cdclk(struct drm_i915_private *dev_priv,
  3804. int max_pixclk)
  3805. {
  3806. int vco = valleyview_get_vco(dev_priv);
  3807. int freq_320 = (vco << 1) % 320000 != 0 ? 333333 : 320000;
  3808. /*
  3809. * Really only a few cases to deal with, as only 4 CDclks are supported:
  3810. * 200MHz
  3811. * 267MHz
  3812. * 320/333MHz (depends on HPLL freq)
  3813. * 400MHz
  3814. * So we check to see whether we're above 90% of the lower bin and
  3815. * adjust if needed.
  3816. *
  3817. * We seem to get an unstable or solid color picture at 200MHz.
  3818. * Not sure what's wrong. For now use 200MHz only when all pipes
  3819. * are off.
  3820. */
  3821. if (max_pixclk > freq_320*9/10)
  3822. return 400000;
  3823. else if (max_pixclk > 266667*9/10)
  3824. return freq_320;
  3825. else if (max_pixclk > 0)
  3826. return 266667;
  3827. else
  3828. return 200000;
  3829. }
  3830. /* compute the max pixel clock for new configuration */
  3831. static int intel_mode_max_pixclk(struct drm_i915_private *dev_priv)
  3832. {
  3833. struct drm_device *dev = dev_priv->dev;
  3834. struct intel_crtc *intel_crtc;
  3835. int max_pixclk = 0;
  3836. for_each_intel_crtc(dev, intel_crtc) {
  3837. if (intel_crtc->new_enabled)
  3838. max_pixclk = max(max_pixclk,
  3839. intel_crtc->new_config->adjusted_mode.crtc_clock);
  3840. }
  3841. return max_pixclk;
  3842. }
  3843. static void valleyview_modeset_global_pipes(struct drm_device *dev,
  3844. unsigned *prepare_pipes)
  3845. {
  3846. struct drm_i915_private *dev_priv = dev->dev_private;
  3847. struct intel_crtc *intel_crtc;
  3848. int max_pixclk = intel_mode_max_pixclk(dev_priv);
  3849. if (valleyview_calc_cdclk(dev_priv, max_pixclk) ==
  3850. dev_priv->vlv_cdclk_freq)
  3851. return;
  3852. /* disable/enable all currently active pipes while we change cdclk */
  3853. for_each_intel_crtc(dev, intel_crtc)
  3854. if (intel_crtc->base.enabled)
  3855. *prepare_pipes |= (1 << intel_crtc->pipe);
  3856. }
  3857. static void valleyview_modeset_global_resources(struct drm_device *dev)
  3858. {
  3859. struct drm_i915_private *dev_priv = dev->dev_private;
  3860. int max_pixclk = intel_mode_max_pixclk(dev_priv);
  3861. int req_cdclk = valleyview_calc_cdclk(dev_priv, max_pixclk);
  3862. if (req_cdclk != dev_priv->vlv_cdclk_freq)
  3863. valleyview_set_cdclk(dev, req_cdclk);
  3864. modeset_update_crtc_power_domains(dev);
  3865. }
  3866. static void valleyview_crtc_enable(struct drm_crtc *crtc)
  3867. {
  3868. struct drm_device *dev = crtc->dev;
  3869. struct drm_i915_private *dev_priv = dev->dev_private;
  3870. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3871. struct intel_encoder *encoder;
  3872. int pipe = intel_crtc->pipe;
  3873. int plane = intel_crtc->plane;
  3874. bool is_dsi;
  3875. u32 dspcntr;
  3876. WARN_ON(!crtc->enabled);
  3877. if (intel_crtc->active)
  3878. return;
  3879. is_dsi = intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI);
  3880. if (!is_dsi && !IS_CHERRYVIEW(dev))
  3881. vlv_prepare_pll(intel_crtc);
  3882. /* Set up the display plane register */
  3883. dspcntr = DISPPLANE_GAMMA_ENABLE;
  3884. if (intel_crtc->config.has_dp_encoder)
  3885. intel_dp_set_m_n(intel_crtc);
  3886. intel_set_pipe_timings(intel_crtc);
  3887. /* pipesrc and dspsize control the size that is scaled from,
  3888. * which should always be the user's requested size.
  3889. */
  3890. I915_WRITE(DSPSIZE(plane),
  3891. ((intel_crtc->config.pipe_src_h - 1) << 16) |
  3892. (intel_crtc->config.pipe_src_w - 1));
  3893. I915_WRITE(DSPPOS(plane), 0);
  3894. i9xx_set_pipeconf(intel_crtc);
  3895. I915_WRITE(DSPCNTR(plane), dspcntr);
  3896. POSTING_READ(DSPCNTR(plane));
  3897. dev_priv->display.update_primary_plane(crtc, crtc->primary->fb,
  3898. crtc->x, crtc->y);
  3899. intel_crtc->active = true;
  3900. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  3901. for_each_encoder_on_crtc(dev, crtc, encoder)
  3902. if (encoder->pre_pll_enable)
  3903. encoder->pre_pll_enable(encoder);
  3904. if (!is_dsi) {
  3905. if (IS_CHERRYVIEW(dev))
  3906. chv_enable_pll(intel_crtc);
  3907. else
  3908. vlv_enable_pll(intel_crtc);
  3909. }
  3910. for_each_encoder_on_crtc(dev, crtc, encoder)
  3911. if (encoder->pre_enable)
  3912. encoder->pre_enable(encoder);
  3913. i9xx_pfit_enable(intel_crtc);
  3914. intel_crtc_load_lut(crtc);
  3915. intel_update_watermarks(crtc);
  3916. intel_enable_pipe(intel_crtc);
  3917. for_each_encoder_on_crtc(dev, crtc, encoder)
  3918. encoder->enable(encoder);
  3919. intel_crtc_enable_planes(crtc);
  3920. /* Underruns don't raise interrupts, so check manually. */
  3921. i9xx_check_fifo_underruns(dev);
  3922. }
  3923. static void i9xx_set_pll_dividers(struct intel_crtc *crtc)
  3924. {
  3925. struct drm_device *dev = crtc->base.dev;
  3926. struct drm_i915_private *dev_priv = dev->dev_private;
  3927. I915_WRITE(FP0(crtc->pipe), crtc->config.dpll_hw_state.fp0);
  3928. I915_WRITE(FP1(crtc->pipe), crtc->config.dpll_hw_state.fp1);
  3929. }
  3930. static void i9xx_crtc_enable(struct drm_crtc *crtc)
  3931. {
  3932. struct drm_device *dev = crtc->dev;
  3933. struct drm_i915_private *dev_priv = dev->dev_private;
  3934. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3935. struct intel_encoder *encoder;
  3936. int pipe = intel_crtc->pipe;
  3937. int plane = intel_crtc->plane;
  3938. u32 dspcntr;
  3939. WARN_ON(!crtc->enabled);
  3940. if (intel_crtc->active)
  3941. return;
  3942. i9xx_set_pll_dividers(intel_crtc);
  3943. /* Set up the display plane register */
  3944. dspcntr = DISPPLANE_GAMMA_ENABLE;
  3945. if (pipe == 0)
  3946. dspcntr &= ~DISPPLANE_SEL_PIPE_MASK;
  3947. else
  3948. dspcntr |= DISPPLANE_SEL_PIPE_B;
  3949. if (intel_crtc->config.has_dp_encoder)
  3950. intel_dp_set_m_n(intel_crtc);
  3951. intel_set_pipe_timings(intel_crtc);
  3952. /* pipesrc and dspsize control the size that is scaled from,
  3953. * which should always be the user's requested size.
  3954. */
  3955. I915_WRITE(DSPSIZE(plane),
  3956. ((intel_crtc->config.pipe_src_h - 1) << 16) |
  3957. (intel_crtc->config.pipe_src_w - 1));
  3958. I915_WRITE(DSPPOS(plane), 0);
  3959. i9xx_set_pipeconf(intel_crtc);
  3960. I915_WRITE(DSPCNTR(plane), dspcntr);
  3961. POSTING_READ(DSPCNTR(plane));
  3962. dev_priv->display.update_primary_plane(crtc, crtc->primary->fb,
  3963. crtc->x, crtc->y);
  3964. intel_crtc->active = true;
  3965. if (!IS_GEN2(dev))
  3966. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  3967. for_each_encoder_on_crtc(dev, crtc, encoder)
  3968. if (encoder->pre_enable)
  3969. encoder->pre_enable(encoder);
  3970. i9xx_enable_pll(intel_crtc);
  3971. i9xx_pfit_enable(intel_crtc);
  3972. intel_crtc_load_lut(crtc);
  3973. intel_update_watermarks(crtc);
  3974. intel_enable_pipe(intel_crtc);
  3975. for_each_encoder_on_crtc(dev, crtc, encoder)
  3976. encoder->enable(encoder);
  3977. intel_crtc_enable_planes(crtc);
  3978. /*
  3979. * Gen2 reports pipe underruns whenever all planes are disabled.
  3980. * So don't enable underrun reporting before at least some planes
  3981. * are enabled.
  3982. * FIXME: Need to fix the logic to work when we turn off all planes
  3983. * but leave the pipe running.
  3984. */
  3985. if (IS_GEN2(dev))
  3986. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  3987. /* Underruns don't raise interrupts, so check manually. */
  3988. i9xx_check_fifo_underruns(dev);
  3989. }
  3990. static void i9xx_pfit_disable(struct intel_crtc *crtc)
  3991. {
  3992. struct drm_device *dev = crtc->base.dev;
  3993. struct drm_i915_private *dev_priv = dev->dev_private;
  3994. if (!crtc->config.gmch_pfit.control)
  3995. return;
  3996. assert_pipe_disabled(dev_priv, crtc->pipe);
  3997. DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n",
  3998. I915_READ(PFIT_CONTROL));
  3999. I915_WRITE(PFIT_CONTROL, 0);
  4000. }
  4001. static void i9xx_crtc_disable(struct drm_crtc *crtc)
  4002. {
  4003. struct drm_device *dev = crtc->dev;
  4004. struct drm_i915_private *dev_priv = dev->dev_private;
  4005. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4006. struct intel_encoder *encoder;
  4007. int pipe = intel_crtc->pipe;
  4008. if (!intel_crtc->active)
  4009. return;
  4010. /*
  4011. * Gen2 reports pipe underruns whenever all planes are disabled.
  4012. * So diasble underrun reporting before all the planes get disabled.
  4013. * FIXME: Need to fix the logic to work when we turn off all planes
  4014. * but leave the pipe running.
  4015. */
  4016. if (IS_GEN2(dev))
  4017. intel_set_cpu_fifo_underrun_reporting(dev, pipe, false);
  4018. /*
  4019. * Vblank time updates from the shadow to live plane control register
  4020. * are blocked if the memory self-refresh mode is active at that
  4021. * moment. So to make sure the plane gets truly disabled, disable
  4022. * first the self-refresh mode. The self-refresh enable bit in turn
  4023. * will be checked/applied by the HW only at the next frame start
  4024. * event which is after the vblank start event, so we need to have a
  4025. * wait-for-vblank between disabling the plane and the pipe.
  4026. */
  4027. intel_set_memory_cxsr(dev_priv, false);
  4028. intel_crtc_disable_planes(crtc);
  4029. for_each_encoder_on_crtc(dev, crtc, encoder)
  4030. encoder->disable(encoder);
  4031. /*
  4032. * On gen2 planes are double buffered but the pipe isn't, so we must
  4033. * wait for planes to fully turn off before disabling the pipe.
  4034. * We also need to wait on all gmch platforms because of the
  4035. * self-refresh mode constraint explained above.
  4036. */
  4037. intel_wait_for_vblank(dev, pipe);
  4038. intel_disable_pipe(dev_priv, pipe);
  4039. i9xx_pfit_disable(intel_crtc);
  4040. for_each_encoder_on_crtc(dev, crtc, encoder)
  4041. if (encoder->post_disable)
  4042. encoder->post_disable(encoder);
  4043. if (!intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI)) {
  4044. if (IS_CHERRYVIEW(dev))
  4045. chv_disable_pll(dev_priv, pipe);
  4046. else if (IS_VALLEYVIEW(dev))
  4047. vlv_disable_pll(dev_priv, pipe);
  4048. else
  4049. i9xx_disable_pll(dev_priv, pipe);
  4050. }
  4051. if (!IS_GEN2(dev))
  4052. intel_set_cpu_fifo_underrun_reporting(dev, pipe, false);
  4053. intel_crtc->active = false;
  4054. intel_update_watermarks(crtc);
  4055. mutex_lock(&dev->struct_mutex);
  4056. intel_update_fbc(dev);
  4057. mutex_unlock(&dev->struct_mutex);
  4058. }
  4059. static void i9xx_crtc_off(struct drm_crtc *crtc)
  4060. {
  4061. }
  4062. static void intel_crtc_update_sarea(struct drm_crtc *crtc,
  4063. bool enabled)
  4064. {
  4065. struct drm_device *dev = crtc->dev;
  4066. struct drm_i915_master_private *master_priv;
  4067. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4068. int pipe = intel_crtc->pipe;
  4069. if (!dev->primary->master)
  4070. return;
  4071. master_priv = dev->primary->master->driver_priv;
  4072. if (!master_priv->sarea_priv)
  4073. return;
  4074. switch (pipe) {
  4075. case 0:
  4076. master_priv->sarea_priv->pipeA_w = enabled ? crtc->mode.hdisplay : 0;
  4077. master_priv->sarea_priv->pipeA_h = enabled ? crtc->mode.vdisplay : 0;
  4078. break;
  4079. case 1:
  4080. master_priv->sarea_priv->pipeB_w = enabled ? crtc->mode.hdisplay : 0;
  4081. master_priv->sarea_priv->pipeB_h = enabled ? crtc->mode.vdisplay : 0;
  4082. break;
  4083. default:
  4084. DRM_ERROR("Can't update pipe %c in SAREA\n", pipe_name(pipe));
  4085. break;
  4086. }
  4087. }
  4088. /**
  4089. * Sets the power management mode of the pipe and plane.
  4090. */
  4091. void intel_crtc_update_dpms(struct drm_crtc *crtc)
  4092. {
  4093. struct drm_device *dev = crtc->dev;
  4094. struct drm_i915_private *dev_priv = dev->dev_private;
  4095. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4096. struct intel_encoder *intel_encoder;
  4097. enum intel_display_power_domain domain;
  4098. unsigned long domains;
  4099. bool enable = false;
  4100. for_each_encoder_on_crtc(dev, crtc, intel_encoder)
  4101. enable |= intel_encoder->connectors_active;
  4102. if (enable) {
  4103. if (!intel_crtc->active) {
  4104. /*
  4105. * FIXME: DDI plls and relevant code isn't converted
  4106. * yet, so do runtime PM for DPMS only for all other
  4107. * platforms for now.
  4108. */
  4109. if (!HAS_DDI(dev)) {
  4110. domains = get_crtc_power_domains(crtc);
  4111. for_each_power_domain(domain, domains)
  4112. intel_display_power_get(dev_priv, domain);
  4113. intel_crtc->enabled_power_domains = domains;
  4114. }
  4115. dev_priv->display.crtc_enable(crtc);
  4116. }
  4117. } else {
  4118. if (intel_crtc->active) {
  4119. dev_priv->display.crtc_disable(crtc);
  4120. if (!HAS_DDI(dev)) {
  4121. domains = intel_crtc->enabled_power_domains;
  4122. for_each_power_domain(domain, domains)
  4123. intel_display_power_put(dev_priv, domain);
  4124. intel_crtc->enabled_power_domains = 0;
  4125. }
  4126. }
  4127. }
  4128. intel_crtc_update_sarea(crtc, enable);
  4129. }
  4130. static void intel_crtc_disable(struct drm_crtc *crtc)
  4131. {
  4132. struct drm_device *dev = crtc->dev;
  4133. struct drm_connector *connector;
  4134. struct drm_i915_private *dev_priv = dev->dev_private;
  4135. struct drm_i915_gem_object *old_obj = intel_fb_obj(crtc->primary->fb);
  4136. enum pipe pipe = to_intel_crtc(crtc)->pipe;
  4137. /* crtc should still be enabled when we disable it. */
  4138. WARN_ON(!crtc->enabled);
  4139. dev_priv->display.crtc_disable(crtc);
  4140. intel_crtc_update_sarea(crtc, false);
  4141. dev_priv->display.off(crtc);
  4142. assert_plane_disabled(dev->dev_private, to_intel_crtc(crtc)->plane);
  4143. assert_cursor_disabled(dev_priv, pipe);
  4144. assert_pipe_disabled(dev->dev_private, pipe);
  4145. if (crtc->primary->fb) {
  4146. mutex_lock(&dev->struct_mutex);
  4147. intel_unpin_fb_obj(old_obj);
  4148. i915_gem_track_fb(old_obj, NULL,
  4149. INTEL_FRONTBUFFER_PRIMARY(pipe));
  4150. mutex_unlock(&dev->struct_mutex);
  4151. crtc->primary->fb = NULL;
  4152. }
  4153. /* Update computed state. */
  4154. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  4155. if (!connector->encoder || !connector->encoder->crtc)
  4156. continue;
  4157. if (connector->encoder->crtc != crtc)
  4158. continue;
  4159. connector->dpms = DRM_MODE_DPMS_OFF;
  4160. to_intel_encoder(connector->encoder)->connectors_active = false;
  4161. }
  4162. }
  4163. void intel_encoder_destroy(struct drm_encoder *encoder)
  4164. {
  4165. struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
  4166. drm_encoder_cleanup(encoder);
  4167. kfree(intel_encoder);
  4168. }
  4169. /* Simple dpms helper for encoders with just one connector, no cloning and only
  4170. * one kind of off state. It clamps all !ON modes to fully OFF and changes the
  4171. * state of the entire output pipe. */
  4172. static void intel_encoder_dpms(struct intel_encoder *encoder, int mode)
  4173. {
  4174. if (mode == DRM_MODE_DPMS_ON) {
  4175. encoder->connectors_active = true;
  4176. intel_crtc_update_dpms(encoder->base.crtc);
  4177. } else {
  4178. encoder->connectors_active = false;
  4179. intel_crtc_update_dpms(encoder->base.crtc);
  4180. }
  4181. }
  4182. /* Cross check the actual hw state with our own modeset state tracking (and it's
  4183. * internal consistency). */
  4184. static void intel_connector_check_state(struct intel_connector *connector)
  4185. {
  4186. if (connector->get_hw_state(connector)) {
  4187. struct intel_encoder *encoder = connector->encoder;
  4188. struct drm_crtc *crtc;
  4189. bool encoder_enabled;
  4190. enum pipe pipe;
  4191. DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
  4192. connector->base.base.id,
  4193. connector->base.name);
  4194. WARN(connector->base.dpms == DRM_MODE_DPMS_OFF,
  4195. "wrong connector dpms state\n");
  4196. WARN(connector->base.encoder != &encoder->base,
  4197. "active connector not linked to encoder\n");
  4198. WARN(!encoder->connectors_active,
  4199. "encoder->connectors_active not set\n");
  4200. encoder_enabled = encoder->get_hw_state(encoder, &pipe);
  4201. WARN(!encoder_enabled, "encoder not enabled\n");
  4202. if (WARN_ON(!encoder->base.crtc))
  4203. return;
  4204. crtc = encoder->base.crtc;
  4205. WARN(!crtc->enabled, "crtc not enabled\n");
  4206. WARN(!to_intel_crtc(crtc)->active, "crtc not active\n");
  4207. WARN(pipe != to_intel_crtc(crtc)->pipe,
  4208. "encoder active on the wrong pipe\n");
  4209. }
  4210. }
  4211. /* Even simpler default implementation, if there's really no special case to
  4212. * consider. */
  4213. void intel_connector_dpms(struct drm_connector *connector, int mode)
  4214. {
  4215. /* All the simple cases only support two dpms states. */
  4216. if (mode != DRM_MODE_DPMS_ON)
  4217. mode = DRM_MODE_DPMS_OFF;
  4218. if (mode == connector->dpms)
  4219. return;
  4220. connector->dpms = mode;
  4221. /* Only need to change hw state when actually enabled */
  4222. if (connector->encoder)
  4223. intel_encoder_dpms(to_intel_encoder(connector->encoder), mode);
  4224. intel_modeset_check_state(connector->dev);
  4225. }
  4226. /* Simple connector->get_hw_state implementation for encoders that support only
  4227. * one connector and no cloning and hence the encoder state determines the state
  4228. * of the connector. */
  4229. bool intel_connector_get_hw_state(struct intel_connector *connector)
  4230. {
  4231. enum pipe pipe = 0;
  4232. struct intel_encoder *encoder = connector->encoder;
  4233. return encoder->get_hw_state(encoder, &pipe);
  4234. }
  4235. static bool ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe,
  4236. struct intel_crtc_config *pipe_config)
  4237. {
  4238. struct drm_i915_private *dev_priv = dev->dev_private;
  4239. struct intel_crtc *pipe_B_crtc =
  4240. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]);
  4241. DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
  4242. pipe_name(pipe), pipe_config->fdi_lanes);
  4243. if (pipe_config->fdi_lanes > 4) {
  4244. DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
  4245. pipe_name(pipe), pipe_config->fdi_lanes);
  4246. return false;
  4247. }
  4248. if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  4249. if (pipe_config->fdi_lanes > 2) {
  4250. DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
  4251. pipe_config->fdi_lanes);
  4252. return false;
  4253. } else {
  4254. return true;
  4255. }
  4256. }
  4257. if (INTEL_INFO(dev)->num_pipes == 2)
  4258. return true;
  4259. /* Ivybridge 3 pipe is really complicated */
  4260. switch (pipe) {
  4261. case PIPE_A:
  4262. return true;
  4263. case PIPE_B:
  4264. if (dev_priv->pipe_to_crtc_mapping[PIPE_C]->enabled &&
  4265. pipe_config->fdi_lanes > 2) {
  4266. DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
  4267. pipe_name(pipe), pipe_config->fdi_lanes);
  4268. return false;
  4269. }
  4270. return true;
  4271. case PIPE_C:
  4272. if (!pipe_has_enabled_pch(pipe_B_crtc) ||
  4273. pipe_B_crtc->config.fdi_lanes <= 2) {
  4274. if (pipe_config->fdi_lanes > 2) {
  4275. DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
  4276. pipe_name(pipe), pipe_config->fdi_lanes);
  4277. return false;
  4278. }
  4279. } else {
  4280. DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
  4281. return false;
  4282. }
  4283. return true;
  4284. default:
  4285. BUG();
  4286. }
  4287. }
  4288. #define RETRY 1
  4289. static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc,
  4290. struct intel_crtc_config *pipe_config)
  4291. {
  4292. struct drm_device *dev = intel_crtc->base.dev;
  4293. struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
  4294. int lane, link_bw, fdi_dotclock;
  4295. bool setup_ok, needs_recompute = false;
  4296. retry:
  4297. /* FDI is a binary signal running at ~2.7GHz, encoding
  4298. * each output octet as 10 bits. The actual frequency
  4299. * is stored as a divider into a 100MHz clock, and the
  4300. * mode pixel clock is stored in units of 1KHz.
  4301. * Hence the bw of each lane in terms of the mode signal
  4302. * is:
  4303. */
  4304. link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10;
  4305. fdi_dotclock = adjusted_mode->crtc_clock;
  4306. lane = ironlake_get_lanes_required(fdi_dotclock, link_bw,
  4307. pipe_config->pipe_bpp);
  4308. pipe_config->fdi_lanes = lane;
  4309. intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock,
  4310. link_bw, &pipe_config->fdi_m_n);
  4311. setup_ok = ironlake_check_fdi_lanes(intel_crtc->base.dev,
  4312. intel_crtc->pipe, pipe_config);
  4313. if (!setup_ok && pipe_config->pipe_bpp > 6*3) {
  4314. pipe_config->pipe_bpp -= 2*3;
  4315. DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
  4316. pipe_config->pipe_bpp);
  4317. needs_recompute = true;
  4318. pipe_config->bw_constrained = true;
  4319. goto retry;
  4320. }
  4321. if (needs_recompute)
  4322. return RETRY;
  4323. return setup_ok ? 0 : -EINVAL;
  4324. }
  4325. static void hsw_compute_ips_config(struct intel_crtc *crtc,
  4326. struct intel_crtc_config *pipe_config)
  4327. {
  4328. pipe_config->ips_enabled = i915.enable_ips &&
  4329. hsw_crtc_supports_ips(crtc) &&
  4330. pipe_config->pipe_bpp <= 24;
  4331. }
  4332. static int intel_crtc_compute_config(struct intel_crtc *crtc,
  4333. struct intel_crtc_config *pipe_config)
  4334. {
  4335. struct drm_device *dev = crtc->base.dev;
  4336. struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
  4337. /* FIXME should check pixel clock limits on all platforms */
  4338. if (INTEL_INFO(dev)->gen < 4) {
  4339. struct drm_i915_private *dev_priv = dev->dev_private;
  4340. int clock_limit =
  4341. dev_priv->display.get_display_clock_speed(dev);
  4342. /*
  4343. * Enable pixel doubling when the dot clock
  4344. * is > 90% of the (display) core speed.
  4345. *
  4346. * GDG double wide on either pipe,
  4347. * otherwise pipe A only.
  4348. */
  4349. if ((crtc->pipe == PIPE_A || IS_I915G(dev)) &&
  4350. adjusted_mode->crtc_clock > clock_limit * 9 / 10) {
  4351. clock_limit *= 2;
  4352. pipe_config->double_wide = true;
  4353. }
  4354. if (adjusted_mode->crtc_clock > clock_limit * 9 / 10)
  4355. return -EINVAL;
  4356. }
  4357. /*
  4358. * Pipe horizontal size must be even in:
  4359. * - DVO ganged mode
  4360. * - LVDS dual channel mode
  4361. * - Double wide pipe
  4362. */
  4363. if ((intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
  4364. intel_is_dual_link_lvds(dev)) || pipe_config->double_wide)
  4365. pipe_config->pipe_src_w &= ~1;
  4366. /* Cantiga+ cannot handle modes with a hsync front porch of 0.
  4367. * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
  4368. */
  4369. if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) &&
  4370. adjusted_mode->hsync_start == adjusted_mode->hdisplay)
  4371. return -EINVAL;
  4372. if ((IS_G4X(dev) || IS_VALLEYVIEW(dev)) && pipe_config->pipe_bpp > 10*3) {
  4373. pipe_config->pipe_bpp = 10*3; /* 12bpc is gen5+ */
  4374. } else if (INTEL_INFO(dev)->gen <= 4 && pipe_config->pipe_bpp > 8*3) {
  4375. /* only a 8bpc pipe, with 6bpc dither through the panel fitter
  4376. * for lvds. */
  4377. pipe_config->pipe_bpp = 8*3;
  4378. }
  4379. if (HAS_IPS(dev))
  4380. hsw_compute_ips_config(crtc, pipe_config);
  4381. /* XXX: PCH clock sharing is done in ->mode_set, so make sure the old
  4382. * clock survives for now. */
  4383. if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
  4384. pipe_config->shared_dpll = crtc->config.shared_dpll;
  4385. if (pipe_config->has_pch_encoder)
  4386. return ironlake_fdi_compute_config(crtc, pipe_config);
  4387. return 0;
  4388. }
  4389. static int valleyview_get_display_clock_speed(struct drm_device *dev)
  4390. {
  4391. struct drm_i915_private *dev_priv = dev->dev_private;
  4392. int vco = valleyview_get_vco(dev_priv);
  4393. u32 val;
  4394. int divider;
  4395. mutex_lock(&dev_priv->dpio_lock);
  4396. val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL);
  4397. mutex_unlock(&dev_priv->dpio_lock);
  4398. divider = val & DISPLAY_FREQUENCY_VALUES;
  4399. WARN((val & DISPLAY_FREQUENCY_STATUS) !=
  4400. (divider << DISPLAY_FREQUENCY_STATUS_SHIFT),
  4401. "cdclk change in progress\n");
  4402. return DIV_ROUND_CLOSEST(vco << 1, divider + 1);
  4403. }
  4404. static int i945_get_display_clock_speed(struct drm_device *dev)
  4405. {
  4406. return 400000;
  4407. }
  4408. static int i915_get_display_clock_speed(struct drm_device *dev)
  4409. {
  4410. return 333000;
  4411. }
  4412. static int i9xx_misc_get_display_clock_speed(struct drm_device *dev)
  4413. {
  4414. return 200000;
  4415. }
  4416. static int pnv_get_display_clock_speed(struct drm_device *dev)
  4417. {
  4418. u16 gcfgc = 0;
  4419. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  4420. switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
  4421. case GC_DISPLAY_CLOCK_267_MHZ_PNV:
  4422. return 267000;
  4423. case GC_DISPLAY_CLOCK_333_MHZ_PNV:
  4424. return 333000;
  4425. case GC_DISPLAY_CLOCK_444_MHZ_PNV:
  4426. return 444000;
  4427. case GC_DISPLAY_CLOCK_200_MHZ_PNV:
  4428. return 200000;
  4429. default:
  4430. DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc);
  4431. case GC_DISPLAY_CLOCK_133_MHZ_PNV:
  4432. return 133000;
  4433. case GC_DISPLAY_CLOCK_167_MHZ_PNV:
  4434. return 167000;
  4435. }
  4436. }
  4437. static int i915gm_get_display_clock_speed(struct drm_device *dev)
  4438. {
  4439. u16 gcfgc = 0;
  4440. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  4441. if (gcfgc & GC_LOW_FREQUENCY_ENABLE)
  4442. return 133000;
  4443. else {
  4444. switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
  4445. case GC_DISPLAY_CLOCK_333_MHZ:
  4446. return 333000;
  4447. default:
  4448. case GC_DISPLAY_CLOCK_190_200_MHZ:
  4449. return 190000;
  4450. }
  4451. }
  4452. }
  4453. static int i865_get_display_clock_speed(struct drm_device *dev)
  4454. {
  4455. return 266000;
  4456. }
  4457. static int i855_get_display_clock_speed(struct drm_device *dev)
  4458. {
  4459. u16 hpllcc = 0;
  4460. /* Assume that the hardware is in the high speed state. This
  4461. * should be the default.
  4462. */
  4463. switch (hpllcc & GC_CLOCK_CONTROL_MASK) {
  4464. case GC_CLOCK_133_200:
  4465. case GC_CLOCK_100_200:
  4466. return 200000;
  4467. case GC_CLOCK_166_250:
  4468. return 250000;
  4469. case GC_CLOCK_100_133:
  4470. return 133000;
  4471. }
  4472. /* Shouldn't happen */
  4473. return 0;
  4474. }
  4475. static int i830_get_display_clock_speed(struct drm_device *dev)
  4476. {
  4477. return 133000;
  4478. }
  4479. static void
  4480. intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den)
  4481. {
  4482. while (*num > DATA_LINK_M_N_MASK ||
  4483. *den > DATA_LINK_M_N_MASK) {
  4484. *num >>= 1;
  4485. *den >>= 1;
  4486. }
  4487. }
  4488. static void compute_m_n(unsigned int m, unsigned int n,
  4489. uint32_t *ret_m, uint32_t *ret_n)
  4490. {
  4491. *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
  4492. *ret_m = div_u64((uint64_t) m * *ret_n, n);
  4493. intel_reduce_m_n_ratio(ret_m, ret_n);
  4494. }
  4495. void
  4496. intel_link_compute_m_n(int bits_per_pixel, int nlanes,
  4497. int pixel_clock, int link_clock,
  4498. struct intel_link_m_n *m_n)
  4499. {
  4500. m_n->tu = 64;
  4501. compute_m_n(bits_per_pixel * pixel_clock,
  4502. link_clock * nlanes * 8,
  4503. &m_n->gmch_m, &m_n->gmch_n);
  4504. compute_m_n(pixel_clock, link_clock,
  4505. &m_n->link_m, &m_n->link_n);
  4506. }
  4507. static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
  4508. {
  4509. if (i915.panel_use_ssc >= 0)
  4510. return i915.panel_use_ssc != 0;
  4511. return dev_priv->vbt.lvds_use_ssc
  4512. && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
  4513. }
  4514. static int i9xx_get_refclk(struct drm_crtc *crtc, int num_connectors)
  4515. {
  4516. struct drm_device *dev = crtc->dev;
  4517. struct drm_i915_private *dev_priv = dev->dev_private;
  4518. int refclk;
  4519. if (IS_VALLEYVIEW(dev)) {
  4520. refclk = 100000;
  4521. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  4522. intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
  4523. refclk = dev_priv->vbt.lvds_ssc_freq;
  4524. DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
  4525. } else if (!IS_GEN2(dev)) {
  4526. refclk = 96000;
  4527. } else {
  4528. refclk = 48000;
  4529. }
  4530. return refclk;
  4531. }
  4532. static uint32_t pnv_dpll_compute_fp(struct dpll *dpll)
  4533. {
  4534. return (1 << dpll->n) << 16 | dpll->m2;
  4535. }
  4536. static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll)
  4537. {
  4538. return dpll->n << 16 | dpll->m1 << 8 | dpll->m2;
  4539. }
  4540. static void i9xx_update_pll_dividers(struct intel_crtc *crtc,
  4541. intel_clock_t *reduced_clock)
  4542. {
  4543. struct drm_device *dev = crtc->base.dev;
  4544. u32 fp, fp2 = 0;
  4545. if (IS_PINEVIEW(dev)) {
  4546. fp = pnv_dpll_compute_fp(&crtc->config.dpll);
  4547. if (reduced_clock)
  4548. fp2 = pnv_dpll_compute_fp(reduced_clock);
  4549. } else {
  4550. fp = i9xx_dpll_compute_fp(&crtc->config.dpll);
  4551. if (reduced_clock)
  4552. fp2 = i9xx_dpll_compute_fp(reduced_clock);
  4553. }
  4554. crtc->config.dpll_hw_state.fp0 = fp;
  4555. crtc->lowfreq_avail = false;
  4556. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
  4557. reduced_clock && i915.powersave) {
  4558. crtc->config.dpll_hw_state.fp1 = fp2;
  4559. crtc->lowfreq_avail = true;
  4560. } else {
  4561. crtc->config.dpll_hw_state.fp1 = fp;
  4562. }
  4563. }
  4564. static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe
  4565. pipe)
  4566. {
  4567. u32 reg_val;
  4568. /*
  4569. * PLLB opamp always calibrates to max value of 0x3f, force enable it
  4570. * and set it to a reasonable value instead.
  4571. */
  4572. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
  4573. reg_val &= 0xffffff00;
  4574. reg_val |= 0x00000030;
  4575. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
  4576. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
  4577. reg_val &= 0x8cffffff;
  4578. reg_val = 0x8c000000;
  4579. vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
  4580. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
  4581. reg_val &= 0xffffff00;
  4582. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
  4583. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
  4584. reg_val &= 0x00ffffff;
  4585. reg_val |= 0xb0000000;
  4586. vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
  4587. }
  4588. static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc,
  4589. struct intel_link_m_n *m_n)
  4590. {
  4591. struct drm_device *dev = crtc->base.dev;
  4592. struct drm_i915_private *dev_priv = dev->dev_private;
  4593. int pipe = crtc->pipe;
  4594. I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
  4595. I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n);
  4596. I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m);
  4597. I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n);
  4598. }
  4599. static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc,
  4600. struct intel_link_m_n *m_n)
  4601. {
  4602. struct drm_device *dev = crtc->base.dev;
  4603. struct drm_i915_private *dev_priv = dev->dev_private;
  4604. int pipe = crtc->pipe;
  4605. enum transcoder transcoder = crtc->config.cpu_transcoder;
  4606. if (INTEL_INFO(dev)->gen >= 5) {
  4607. I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m);
  4608. I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n);
  4609. I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m);
  4610. I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n);
  4611. } else {
  4612. I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
  4613. I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n);
  4614. I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m);
  4615. I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n);
  4616. }
  4617. }
  4618. static void intel_dp_set_m_n(struct intel_crtc *crtc)
  4619. {
  4620. if (crtc->config.has_pch_encoder)
  4621. intel_pch_transcoder_set_m_n(crtc, &crtc->config.dp_m_n);
  4622. else
  4623. intel_cpu_transcoder_set_m_n(crtc, &crtc->config.dp_m_n);
  4624. }
  4625. static void vlv_update_pll(struct intel_crtc *crtc)
  4626. {
  4627. u32 dpll, dpll_md;
  4628. /*
  4629. * Enable DPIO clock input. We should never disable the reference
  4630. * clock for pipe B, since VGA hotplug / manual detection depends
  4631. * on it.
  4632. */
  4633. dpll = DPLL_EXT_BUFFER_ENABLE_VLV | DPLL_REFA_CLK_ENABLE_VLV |
  4634. DPLL_VGA_MODE_DIS | DPLL_INTEGRATED_CLOCK_VLV;
  4635. /* We should never disable this, set it here for state tracking */
  4636. if (crtc->pipe == PIPE_B)
  4637. dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
  4638. dpll |= DPLL_VCO_ENABLE;
  4639. crtc->config.dpll_hw_state.dpll = dpll;
  4640. dpll_md = (crtc->config.pixel_multiplier - 1)
  4641. << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  4642. crtc->config.dpll_hw_state.dpll_md = dpll_md;
  4643. }
  4644. static void vlv_prepare_pll(struct intel_crtc *crtc)
  4645. {
  4646. struct drm_device *dev = crtc->base.dev;
  4647. struct drm_i915_private *dev_priv = dev->dev_private;
  4648. int pipe = crtc->pipe;
  4649. u32 mdiv;
  4650. u32 bestn, bestm1, bestm2, bestp1, bestp2;
  4651. u32 coreclk, reg_val;
  4652. mutex_lock(&dev_priv->dpio_lock);
  4653. bestn = crtc->config.dpll.n;
  4654. bestm1 = crtc->config.dpll.m1;
  4655. bestm2 = crtc->config.dpll.m2;
  4656. bestp1 = crtc->config.dpll.p1;
  4657. bestp2 = crtc->config.dpll.p2;
  4658. /* See eDP HDMI DPIO driver vbios notes doc */
  4659. /* PLL B needs special handling */
  4660. if (pipe == PIPE_B)
  4661. vlv_pllb_recal_opamp(dev_priv, pipe);
  4662. /* Set up Tx target for periodic Rcomp update */
  4663. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f);
  4664. /* Disable target IRef on PLL */
  4665. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe));
  4666. reg_val &= 0x00ffffff;
  4667. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val);
  4668. /* Disable fast lock */
  4669. vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610);
  4670. /* Set idtafcrecal before PLL is enabled */
  4671. mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
  4672. mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
  4673. mdiv |= ((bestn << DPIO_N_SHIFT));
  4674. mdiv |= (1 << DPIO_K_SHIFT);
  4675. /*
  4676. * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
  4677. * but we don't support that).
  4678. * Note: don't use the DAC post divider as it seems unstable.
  4679. */
  4680. mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
  4681. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
  4682. mdiv |= DPIO_ENABLE_CALIBRATION;
  4683. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
  4684. /* Set HBR and RBR LPF coefficients */
  4685. if (crtc->config.port_clock == 162000 ||
  4686. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_ANALOG) ||
  4687. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI))
  4688. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
  4689. 0x009f0003);
  4690. else
  4691. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
  4692. 0x00d0000f);
  4693. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_EDP) ||
  4694. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT)) {
  4695. /* Use SSC source */
  4696. if (pipe == PIPE_A)
  4697. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4698. 0x0df40000);
  4699. else
  4700. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4701. 0x0df70000);
  4702. } else { /* HDMI or VGA */
  4703. /* Use bend source */
  4704. if (pipe == PIPE_A)
  4705. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4706. 0x0df70000);
  4707. else
  4708. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4709. 0x0df40000);
  4710. }
  4711. coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe));
  4712. coreclk = (coreclk & 0x0000ff00) | 0x01c00000;
  4713. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT) ||
  4714. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_EDP))
  4715. coreclk |= 0x01000000;
  4716. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk);
  4717. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000);
  4718. mutex_unlock(&dev_priv->dpio_lock);
  4719. }
  4720. static void chv_update_pll(struct intel_crtc *crtc)
  4721. {
  4722. struct drm_device *dev = crtc->base.dev;
  4723. struct drm_i915_private *dev_priv = dev->dev_private;
  4724. int pipe = crtc->pipe;
  4725. int dpll_reg = DPLL(crtc->pipe);
  4726. enum dpio_channel port = vlv_pipe_to_channel(pipe);
  4727. u32 loopfilter, intcoeff;
  4728. u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac;
  4729. int refclk;
  4730. crtc->config.dpll_hw_state.dpll = DPLL_SSC_REF_CLOCK_CHV |
  4731. DPLL_REFA_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS |
  4732. DPLL_VCO_ENABLE;
  4733. if (pipe != PIPE_A)
  4734. crtc->config.dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
  4735. crtc->config.dpll_hw_state.dpll_md =
  4736. (crtc->config.pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  4737. bestn = crtc->config.dpll.n;
  4738. bestm2_frac = crtc->config.dpll.m2 & 0x3fffff;
  4739. bestm1 = crtc->config.dpll.m1;
  4740. bestm2 = crtc->config.dpll.m2 >> 22;
  4741. bestp1 = crtc->config.dpll.p1;
  4742. bestp2 = crtc->config.dpll.p2;
  4743. /*
  4744. * Enable Refclk and SSC
  4745. */
  4746. I915_WRITE(dpll_reg,
  4747. crtc->config.dpll_hw_state.dpll & ~DPLL_VCO_ENABLE);
  4748. mutex_lock(&dev_priv->dpio_lock);
  4749. /* p1 and p2 divider */
  4750. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port),
  4751. 5 << DPIO_CHV_S1_DIV_SHIFT |
  4752. bestp1 << DPIO_CHV_P1_DIV_SHIFT |
  4753. bestp2 << DPIO_CHV_P2_DIV_SHIFT |
  4754. 1 << DPIO_CHV_K_DIV_SHIFT);
  4755. /* Feedback post-divider - m2 */
  4756. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2);
  4757. /* Feedback refclk divider - n and m1 */
  4758. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port),
  4759. DPIO_CHV_M1_DIV_BY_2 |
  4760. 1 << DPIO_CHV_N_DIV_SHIFT);
  4761. /* M2 fraction division */
  4762. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac);
  4763. /* M2 fraction division enable */
  4764. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port),
  4765. DPIO_CHV_FRAC_DIV_EN |
  4766. (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT));
  4767. /* Loop filter */
  4768. refclk = i9xx_get_refclk(&crtc->base, 0);
  4769. loopfilter = 5 << DPIO_CHV_PROP_COEFF_SHIFT |
  4770. 2 << DPIO_CHV_GAIN_CTRL_SHIFT;
  4771. if (refclk == 100000)
  4772. intcoeff = 11;
  4773. else if (refclk == 38400)
  4774. intcoeff = 10;
  4775. else
  4776. intcoeff = 9;
  4777. loopfilter |= intcoeff << DPIO_CHV_INT_COEFF_SHIFT;
  4778. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter);
  4779. /* AFC Recal */
  4780. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port),
  4781. vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) |
  4782. DPIO_AFC_RECAL);
  4783. mutex_unlock(&dev_priv->dpio_lock);
  4784. }
  4785. static void i9xx_update_pll(struct intel_crtc *crtc,
  4786. intel_clock_t *reduced_clock,
  4787. int num_connectors)
  4788. {
  4789. struct drm_device *dev = crtc->base.dev;
  4790. struct drm_i915_private *dev_priv = dev->dev_private;
  4791. u32 dpll;
  4792. bool is_sdvo;
  4793. struct dpll *clock = &crtc->config.dpll;
  4794. i9xx_update_pll_dividers(crtc, reduced_clock);
  4795. is_sdvo = intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_SDVO) ||
  4796. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI);
  4797. dpll = DPLL_VGA_MODE_DIS;
  4798. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS))
  4799. dpll |= DPLLB_MODE_LVDS;
  4800. else
  4801. dpll |= DPLLB_MODE_DAC_SERIAL;
  4802. if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) {
  4803. dpll |= (crtc->config.pixel_multiplier - 1)
  4804. << SDVO_MULTIPLIER_SHIFT_HIRES;
  4805. }
  4806. if (is_sdvo)
  4807. dpll |= DPLL_SDVO_HIGH_SPEED;
  4808. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT))
  4809. dpll |= DPLL_SDVO_HIGH_SPEED;
  4810. /* compute bitmask from p1 value */
  4811. if (IS_PINEVIEW(dev))
  4812. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
  4813. else {
  4814. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  4815. if (IS_G4X(dev) && reduced_clock)
  4816. dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  4817. }
  4818. switch (clock->p2) {
  4819. case 5:
  4820. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  4821. break;
  4822. case 7:
  4823. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  4824. break;
  4825. case 10:
  4826. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  4827. break;
  4828. case 14:
  4829. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  4830. break;
  4831. }
  4832. if (INTEL_INFO(dev)->gen >= 4)
  4833. dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
  4834. if (crtc->config.sdvo_tv_clock)
  4835. dpll |= PLL_REF_INPUT_TVCLKINBC;
  4836. else if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
  4837. intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  4838. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  4839. else
  4840. dpll |= PLL_REF_INPUT_DREFCLK;
  4841. dpll |= DPLL_VCO_ENABLE;
  4842. crtc->config.dpll_hw_state.dpll = dpll;
  4843. if (INTEL_INFO(dev)->gen >= 4) {
  4844. u32 dpll_md = (crtc->config.pixel_multiplier - 1)
  4845. << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  4846. crtc->config.dpll_hw_state.dpll_md = dpll_md;
  4847. }
  4848. }
  4849. static void i8xx_update_pll(struct intel_crtc *crtc,
  4850. intel_clock_t *reduced_clock,
  4851. int num_connectors)
  4852. {
  4853. struct drm_device *dev = crtc->base.dev;
  4854. struct drm_i915_private *dev_priv = dev->dev_private;
  4855. u32 dpll;
  4856. struct dpll *clock = &crtc->config.dpll;
  4857. i9xx_update_pll_dividers(crtc, reduced_clock);
  4858. dpll = DPLL_VGA_MODE_DIS;
  4859. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS)) {
  4860. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  4861. } else {
  4862. if (clock->p1 == 2)
  4863. dpll |= PLL_P1_DIVIDE_BY_TWO;
  4864. else
  4865. dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  4866. if (clock->p2 == 4)
  4867. dpll |= PLL_P2_DIVIDE_BY_4;
  4868. }
  4869. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DVO))
  4870. dpll |= DPLL_DVO_2X_MODE;
  4871. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
  4872. intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  4873. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  4874. else
  4875. dpll |= PLL_REF_INPUT_DREFCLK;
  4876. dpll |= DPLL_VCO_ENABLE;
  4877. crtc->config.dpll_hw_state.dpll = dpll;
  4878. }
  4879. static void intel_set_pipe_timings(struct intel_crtc *intel_crtc)
  4880. {
  4881. struct drm_device *dev = intel_crtc->base.dev;
  4882. struct drm_i915_private *dev_priv = dev->dev_private;
  4883. enum pipe pipe = intel_crtc->pipe;
  4884. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  4885. struct drm_display_mode *adjusted_mode =
  4886. &intel_crtc->config.adjusted_mode;
  4887. uint32_t crtc_vtotal, crtc_vblank_end;
  4888. int vsyncshift = 0;
  4889. /* We need to be careful not to changed the adjusted mode, for otherwise
  4890. * the hw state checker will get angry at the mismatch. */
  4891. crtc_vtotal = adjusted_mode->crtc_vtotal;
  4892. crtc_vblank_end = adjusted_mode->crtc_vblank_end;
  4893. if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
  4894. /* the chip adds 2 halflines automatically */
  4895. crtc_vtotal -= 1;
  4896. crtc_vblank_end -= 1;
  4897. if (intel_pipe_has_type(&intel_crtc->base, INTEL_OUTPUT_SDVO))
  4898. vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
  4899. else
  4900. vsyncshift = adjusted_mode->crtc_hsync_start -
  4901. adjusted_mode->crtc_htotal / 2;
  4902. if (vsyncshift < 0)
  4903. vsyncshift += adjusted_mode->crtc_htotal;
  4904. }
  4905. if (INTEL_INFO(dev)->gen > 3)
  4906. I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
  4907. I915_WRITE(HTOTAL(cpu_transcoder),
  4908. (adjusted_mode->crtc_hdisplay - 1) |
  4909. ((adjusted_mode->crtc_htotal - 1) << 16));
  4910. I915_WRITE(HBLANK(cpu_transcoder),
  4911. (adjusted_mode->crtc_hblank_start - 1) |
  4912. ((adjusted_mode->crtc_hblank_end - 1) << 16));
  4913. I915_WRITE(HSYNC(cpu_transcoder),
  4914. (adjusted_mode->crtc_hsync_start - 1) |
  4915. ((adjusted_mode->crtc_hsync_end - 1) << 16));
  4916. I915_WRITE(VTOTAL(cpu_transcoder),
  4917. (adjusted_mode->crtc_vdisplay - 1) |
  4918. ((crtc_vtotal - 1) << 16));
  4919. I915_WRITE(VBLANK(cpu_transcoder),
  4920. (adjusted_mode->crtc_vblank_start - 1) |
  4921. ((crtc_vblank_end - 1) << 16));
  4922. I915_WRITE(VSYNC(cpu_transcoder),
  4923. (adjusted_mode->crtc_vsync_start - 1) |
  4924. ((adjusted_mode->crtc_vsync_end - 1) << 16));
  4925. /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
  4926. * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
  4927. * documented on the DDI_FUNC_CTL register description, EDP Input Select
  4928. * bits. */
  4929. if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP &&
  4930. (pipe == PIPE_B || pipe == PIPE_C))
  4931. I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
  4932. /* pipesrc controls the size that is scaled from, which should
  4933. * always be the user's requested size.
  4934. */
  4935. I915_WRITE(PIPESRC(pipe),
  4936. ((intel_crtc->config.pipe_src_w - 1) << 16) |
  4937. (intel_crtc->config.pipe_src_h - 1));
  4938. }
  4939. static void intel_get_pipe_timings(struct intel_crtc *crtc,
  4940. struct intel_crtc_config *pipe_config)
  4941. {
  4942. struct drm_device *dev = crtc->base.dev;
  4943. struct drm_i915_private *dev_priv = dev->dev_private;
  4944. enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
  4945. uint32_t tmp;
  4946. tmp = I915_READ(HTOTAL(cpu_transcoder));
  4947. pipe_config->adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
  4948. pipe_config->adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
  4949. tmp = I915_READ(HBLANK(cpu_transcoder));
  4950. pipe_config->adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1;
  4951. pipe_config->adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1;
  4952. tmp = I915_READ(HSYNC(cpu_transcoder));
  4953. pipe_config->adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
  4954. pipe_config->adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
  4955. tmp = I915_READ(VTOTAL(cpu_transcoder));
  4956. pipe_config->adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
  4957. pipe_config->adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
  4958. tmp = I915_READ(VBLANK(cpu_transcoder));
  4959. pipe_config->adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1;
  4960. pipe_config->adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1;
  4961. tmp = I915_READ(VSYNC(cpu_transcoder));
  4962. pipe_config->adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
  4963. pipe_config->adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
  4964. if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) {
  4965. pipe_config->adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
  4966. pipe_config->adjusted_mode.crtc_vtotal += 1;
  4967. pipe_config->adjusted_mode.crtc_vblank_end += 1;
  4968. }
  4969. tmp = I915_READ(PIPESRC(crtc->pipe));
  4970. pipe_config->pipe_src_h = (tmp & 0xffff) + 1;
  4971. pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1;
  4972. pipe_config->requested_mode.vdisplay = pipe_config->pipe_src_h;
  4973. pipe_config->requested_mode.hdisplay = pipe_config->pipe_src_w;
  4974. }
  4975. void intel_mode_from_pipe_config(struct drm_display_mode *mode,
  4976. struct intel_crtc_config *pipe_config)
  4977. {
  4978. mode->hdisplay = pipe_config->adjusted_mode.crtc_hdisplay;
  4979. mode->htotal = pipe_config->adjusted_mode.crtc_htotal;
  4980. mode->hsync_start = pipe_config->adjusted_mode.crtc_hsync_start;
  4981. mode->hsync_end = pipe_config->adjusted_mode.crtc_hsync_end;
  4982. mode->vdisplay = pipe_config->adjusted_mode.crtc_vdisplay;
  4983. mode->vtotal = pipe_config->adjusted_mode.crtc_vtotal;
  4984. mode->vsync_start = pipe_config->adjusted_mode.crtc_vsync_start;
  4985. mode->vsync_end = pipe_config->adjusted_mode.crtc_vsync_end;
  4986. mode->flags = pipe_config->adjusted_mode.flags;
  4987. mode->clock = pipe_config->adjusted_mode.crtc_clock;
  4988. mode->flags |= pipe_config->adjusted_mode.flags;
  4989. }
  4990. static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc)
  4991. {
  4992. struct drm_device *dev = intel_crtc->base.dev;
  4993. struct drm_i915_private *dev_priv = dev->dev_private;
  4994. uint32_t pipeconf;
  4995. pipeconf = 0;
  4996. if (dev_priv->quirks & QUIRK_PIPEA_FORCE &&
  4997. I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE)
  4998. pipeconf |= PIPECONF_ENABLE;
  4999. if (intel_crtc->config.double_wide)
  5000. pipeconf |= PIPECONF_DOUBLE_WIDE;
  5001. /* only g4x and later have fancy bpc/dither controls */
  5002. if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) {
  5003. /* Bspec claims that we can't use dithering for 30bpp pipes. */
  5004. if (intel_crtc->config.dither && intel_crtc->config.pipe_bpp != 30)
  5005. pipeconf |= PIPECONF_DITHER_EN |
  5006. PIPECONF_DITHER_TYPE_SP;
  5007. switch (intel_crtc->config.pipe_bpp) {
  5008. case 18:
  5009. pipeconf |= PIPECONF_6BPC;
  5010. break;
  5011. case 24:
  5012. pipeconf |= PIPECONF_8BPC;
  5013. break;
  5014. case 30:
  5015. pipeconf |= PIPECONF_10BPC;
  5016. break;
  5017. default:
  5018. /* Case prevented by intel_choose_pipe_bpp_dither. */
  5019. BUG();
  5020. }
  5021. }
  5022. if (HAS_PIPE_CXSR(dev)) {
  5023. if (intel_crtc->lowfreq_avail) {
  5024. DRM_DEBUG_KMS("enabling CxSR downclocking\n");
  5025. pipeconf |= PIPECONF_CXSR_DOWNCLOCK;
  5026. } else {
  5027. DRM_DEBUG_KMS("disabling CxSR downclocking\n");
  5028. }
  5029. }
  5030. if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
  5031. if (INTEL_INFO(dev)->gen < 4 ||
  5032. intel_pipe_has_type(&intel_crtc->base, INTEL_OUTPUT_SDVO))
  5033. pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
  5034. else
  5035. pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT;
  5036. } else
  5037. pipeconf |= PIPECONF_PROGRESSIVE;
  5038. if (IS_VALLEYVIEW(dev) && intel_crtc->config.limited_color_range)
  5039. pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
  5040. I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf);
  5041. POSTING_READ(PIPECONF(intel_crtc->pipe));
  5042. }
  5043. static int i9xx_crtc_mode_set(struct drm_crtc *crtc,
  5044. int x, int y,
  5045. struct drm_framebuffer *fb)
  5046. {
  5047. struct drm_device *dev = crtc->dev;
  5048. struct drm_i915_private *dev_priv = dev->dev_private;
  5049. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5050. int refclk, num_connectors = 0;
  5051. intel_clock_t clock, reduced_clock;
  5052. bool ok, has_reduced_clock = false;
  5053. bool is_lvds = false, is_dsi = false;
  5054. struct intel_encoder *encoder;
  5055. const intel_limit_t *limit;
  5056. for_each_encoder_on_crtc(dev, crtc, encoder) {
  5057. switch (encoder->type) {
  5058. case INTEL_OUTPUT_LVDS:
  5059. is_lvds = true;
  5060. break;
  5061. case INTEL_OUTPUT_DSI:
  5062. is_dsi = true;
  5063. break;
  5064. }
  5065. num_connectors++;
  5066. }
  5067. if (is_dsi)
  5068. return 0;
  5069. if (!intel_crtc->config.clock_set) {
  5070. refclk = i9xx_get_refclk(crtc, num_connectors);
  5071. /*
  5072. * Returns a set of divisors for the desired target clock with
  5073. * the given refclk, or FALSE. The returned values represent
  5074. * the clock equation: reflck * (5 * (m1 + 2) + (m2 + 2)) / (n +
  5075. * 2) / p1 / p2.
  5076. */
  5077. limit = intel_limit(crtc, refclk);
  5078. ok = dev_priv->display.find_dpll(limit, crtc,
  5079. intel_crtc->config.port_clock,
  5080. refclk, NULL, &clock);
  5081. if (!ok) {
  5082. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  5083. return -EINVAL;
  5084. }
  5085. if (is_lvds && dev_priv->lvds_downclock_avail) {
  5086. /*
  5087. * Ensure we match the reduced clock's P to the target
  5088. * clock. If the clocks don't match, we can't switch
  5089. * the display clock by using the FP0/FP1. In such case
  5090. * we will disable the LVDS downclock feature.
  5091. */
  5092. has_reduced_clock =
  5093. dev_priv->display.find_dpll(limit, crtc,
  5094. dev_priv->lvds_downclock,
  5095. refclk, &clock,
  5096. &reduced_clock);
  5097. }
  5098. /* Compat-code for transition, will disappear. */
  5099. intel_crtc->config.dpll.n = clock.n;
  5100. intel_crtc->config.dpll.m1 = clock.m1;
  5101. intel_crtc->config.dpll.m2 = clock.m2;
  5102. intel_crtc->config.dpll.p1 = clock.p1;
  5103. intel_crtc->config.dpll.p2 = clock.p2;
  5104. }
  5105. if (IS_GEN2(dev)) {
  5106. i8xx_update_pll(intel_crtc,
  5107. has_reduced_clock ? &reduced_clock : NULL,
  5108. num_connectors);
  5109. } else if (IS_CHERRYVIEW(dev)) {
  5110. chv_update_pll(intel_crtc);
  5111. } else if (IS_VALLEYVIEW(dev)) {
  5112. vlv_update_pll(intel_crtc);
  5113. } else {
  5114. i9xx_update_pll(intel_crtc,
  5115. has_reduced_clock ? &reduced_clock : NULL,
  5116. num_connectors);
  5117. }
  5118. return 0;
  5119. }
  5120. static void i9xx_get_pfit_config(struct intel_crtc *crtc,
  5121. struct intel_crtc_config *pipe_config)
  5122. {
  5123. struct drm_device *dev = crtc->base.dev;
  5124. struct drm_i915_private *dev_priv = dev->dev_private;
  5125. uint32_t tmp;
  5126. if (INTEL_INFO(dev)->gen <= 3 && (IS_I830(dev) || !IS_MOBILE(dev)))
  5127. return;
  5128. tmp = I915_READ(PFIT_CONTROL);
  5129. if (!(tmp & PFIT_ENABLE))
  5130. return;
  5131. /* Check whether the pfit is attached to our pipe. */
  5132. if (INTEL_INFO(dev)->gen < 4) {
  5133. if (crtc->pipe != PIPE_B)
  5134. return;
  5135. } else {
  5136. if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
  5137. return;
  5138. }
  5139. pipe_config->gmch_pfit.control = tmp;
  5140. pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS);
  5141. if (INTEL_INFO(dev)->gen < 5)
  5142. pipe_config->gmch_pfit.lvds_border_bits =
  5143. I915_READ(LVDS) & LVDS_BORDER_ENABLE;
  5144. }
  5145. static void vlv_crtc_clock_get(struct intel_crtc *crtc,
  5146. struct intel_crtc_config *pipe_config)
  5147. {
  5148. struct drm_device *dev = crtc->base.dev;
  5149. struct drm_i915_private *dev_priv = dev->dev_private;
  5150. int pipe = pipe_config->cpu_transcoder;
  5151. intel_clock_t clock;
  5152. u32 mdiv;
  5153. int refclk = 100000;
  5154. mutex_lock(&dev_priv->dpio_lock);
  5155. mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
  5156. mutex_unlock(&dev_priv->dpio_lock);
  5157. clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
  5158. clock.m2 = mdiv & DPIO_M2DIV_MASK;
  5159. clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
  5160. clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
  5161. clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
  5162. vlv_clock(refclk, &clock);
  5163. /* clock.dot is the fast clock */
  5164. pipe_config->port_clock = clock.dot / 5;
  5165. }
  5166. static void i9xx_get_plane_config(struct intel_crtc *crtc,
  5167. struct intel_plane_config *plane_config)
  5168. {
  5169. struct drm_device *dev = crtc->base.dev;
  5170. struct drm_i915_private *dev_priv = dev->dev_private;
  5171. u32 val, base, offset;
  5172. int pipe = crtc->pipe, plane = crtc->plane;
  5173. int fourcc, pixel_format;
  5174. int aligned_height;
  5175. crtc->base.primary->fb = kzalloc(sizeof(struct intel_framebuffer), GFP_KERNEL);
  5176. if (!crtc->base.primary->fb) {
  5177. DRM_DEBUG_KMS("failed to alloc fb\n");
  5178. return;
  5179. }
  5180. val = I915_READ(DSPCNTR(plane));
  5181. if (INTEL_INFO(dev)->gen >= 4)
  5182. if (val & DISPPLANE_TILED)
  5183. plane_config->tiled = true;
  5184. pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
  5185. fourcc = intel_format_to_fourcc(pixel_format);
  5186. crtc->base.primary->fb->pixel_format = fourcc;
  5187. crtc->base.primary->fb->bits_per_pixel =
  5188. drm_format_plane_cpp(fourcc, 0) * 8;
  5189. if (INTEL_INFO(dev)->gen >= 4) {
  5190. if (plane_config->tiled)
  5191. offset = I915_READ(DSPTILEOFF(plane));
  5192. else
  5193. offset = I915_READ(DSPLINOFF(plane));
  5194. base = I915_READ(DSPSURF(plane)) & 0xfffff000;
  5195. } else {
  5196. base = I915_READ(DSPADDR(plane));
  5197. }
  5198. plane_config->base = base;
  5199. val = I915_READ(PIPESRC(pipe));
  5200. crtc->base.primary->fb->width = ((val >> 16) & 0xfff) + 1;
  5201. crtc->base.primary->fb->height = ((val >> 0) & 0xfff) + 1;
  5202. val = I915_READ(DSPSTRIDE(pipe));
  5203. crtc->base.primary->fb->pitches[0] = val & 0xffffff80;
  5204. aligned_height = intel_align_height(dev, crtc->base.primary->fb->height,
  5205. plane_config->tiled);
  5206. plane_config->size = PAGE_ALIGN(crtc->base.primary->fb->pitches[0] *
  5207. aligned_height);
  5208. DRM_DEBUG_KMS("pipe/plane %d/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
  5209. pipe, plane, crtc->base.primary->fb->width,
  5210. crtc->base.primary->fb->height,
  5211. crtc->base.primary->fb->bits_per_pixel, base,
  5212. crtc->base.primary->fb->pitches[0],
  5213. plane_config->size);
  5214. }
  5215. static void chv_crtc_clock_get(struct intel_crtc *crtc,
  5216. struct intel_crtc_config *pipe_config)
  5217. {
  5218. struct drm_device *dev = crtc->base.dev;
  5219. struct drm_i915_private *dev_priv = dev->dev_private;
  5220. int pipe = pipe_config->cpu_transcoder;
  5221. enum dpio_channel port = vlv_pipe_to_channel(pipe);
  5222. intel_clock_t clock;
  5223. u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2;
  5224. int refclk = 100000;
  5225. mutex_lock(&dev_priv->dpio_lock);
  5226. cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
  5227. pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
  5228. pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
  5229. pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
  5230. mutex_unlock(&dev_priv->dpio_lock);
  5231. clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
  5232. clock.m2 = ((pll_dw0 & 0xff) << 22) | (pll_dw2 & 0x3fffff);
  5233. clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
  5234. clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
  5235. clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
  5236. chv_clock(refclk, &clock);
  5237. /* clock.dot is the fast clock */
  5238. pipe_config->port_clock = clock.dot / 5;
  5239. }
  5240. static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
  5241. struct intel_crtc_config *pipe_config)
  5242. {
  5243. struct drm_device *dev = crtc->base.dev;
  5244. struct drm_i915_private *dev_priv = dev->dev_private;
  5245. uint32_t tmp;
  5246. if (!intel_display_power_enabled(dev_priv,
  5247. POWER_DOMAIN_PIPE(crtc->pipe)))
  5248. return false;
  5249. pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
  5250. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  5251. tmp = I915_READ(PIPECONF(crtc->pipe));
  5252. if (!(tmp & PIPECONF_ENABLE))
  5253. return false;
  5254. if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) {
  5255. switch (tmp & PIPECONF_BPC_MASK) {
  5256. case PIPECONF_6BPC:
  5257. pipe_config->pipe_bpp = 18;
  5258. break;
  5259. case PIPECONF_8BPC:
  5260. pipe_config->pipe_bpp = 24;
  5261. break;
  5262. case PIPECONF_10BPC:
  5263. pipe_config->pipe_bpp = 30;
  5264. break;
  5265. default:
  5266. break;
  5267. }
  5268. }
  5269. if (IS_VALLEYVIEW(dev) && (tmp & PIPECONF_COLOR_RANGE_SELECT))
  5270. pipe_config->limited_color_range = true;
  5271. if (INTEL_INFO(dev)->gen < 4)
  5272. pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
  5273. intel_get_pipe_timings(crtc, pipe_config);
  5274. i9xx_get_pfit_config(crtc, pipe_config);
  5275. if (INTEL_INFO(dev)->gen >= 4) {
  5276. tmp = I915_READ(DPLL_MD(crtc->pipe));
  5277. pipe_config->pixel_multiplier =
  5278. ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
  5279. >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
  5280. pipe_config->dpll_hw_state.dpll_md = tmp;
  5281. } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) {
  5282. tmp = I915_READ(DPLL(crtc->pipe));
  5283. pipe_config->pixel_multiplier =
  5284. ((tmp & SDVO_MULTIPLIER_MASK)
  5285. >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
  5286. } else {
  5287. /* Note that on i915G/GM the pixel multiplier is in the sdvo
  5288. * port and will be fixed up in the encoder->get_config
  5289. * function. */
  5290. pipe_config->pixel_multiplier = 1;
  5291. }
  5292. pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe));
  5293. if (!IS_VALLEYVIEW(dev)) {
  5294. pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe));
  5295. pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe));
  5296. } else {
  5297. /* Mask out read-only status bits. */
  5298. pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
  5299. DPLL_PORTC_READY_MASK |
  5300. DPLL_PORTB_READY_MASK);
  5301. }
  5302. if (IS_CHERRYVIEW(dev))
  5303. chv_crtc_clock_get(crtc, pipe_config);
  5304. else if (IS_VALLEYVIEW(dev))
  5305. vlv_crtc_clock_get(crtc, pipe_config);
  5306. else
  5307. i9xx_crtc_clock_get(crtc, pipe_config);
  5308. return true;
  5309. }
  5310. static void ironlake_init_pch_refclk(struct drm_device *dev)
  5311. {
  5312. struct drm_i915_private *dev_priv = dev->dev_private;
  5313. struct drm_mode_config *mode_config = &dev->mode_config;
  5314. struct intel_encoder *encoder;
  5315. u32 val, final;
  5316. bool has_lvds = false;
  5317. bool has_cpu_edp = false;
  5318. bool has_panel = false;
  5319. bool has_ck505 = false;
  5320. bool can_ssc = false;
  5321. /* We need to take the global config into account */
  5322. list_for_each_entry(encoder, &mode_config->encoder_list,
  5323. base.head) {
  5324. switch (encoder->type) {
  5325. case INTEL_OUTPUT_LVDS:
  5326. has_panel = true;
  5327. has_lvds = true;
  5328. break;
  5329. case INTEL_OUTPUT_EDP:
  5330. has_panel = true;
  5331. if (enc_to_dig_port(&encoder->base)->port == PORT_A)
  5332. has_cpu_edp = true;
  5333. break;
  5334. }
  5335. }
  5336. if (HAS_PCH_IBX(dev)) {
  5337. has_ck505 = dev_priv->vbt.display_clock_mode;
  5338. can_ssc = has_ck505;
  5339. } else {
  5340. has_ck505 = false;
  5341. can_ssc = true;
  5342. }
  5343. DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n",
  5344. has_panel, has_lvds, has_ck505);
  5345. /* Ironlake: try to setup display ref clock before DPLL
  5346. * enabling. This is only under driver's control after
  5347. * PCH B stepping, previous chipset stepping should be
  5348. * ignoring this setting.
  5349. */
  5350. val = I915_READ(PCH_DREF_CONTROL);
  5351. /* As we must carefully and slowly disable/enable each source in turn,
  5352. * compute the final state we want first and check if we need to
  5353. * make any changes at all.
  5354. */
  5355. final = val;
  5356. final &= ~DREF_NONSPREAD_SOURCE_MASK;
  5357. if (has_ck505)
  5358. final |= DREF_NONSPREAD_CK505_ENABLE;
  5359. else
  5360. final |= DREF_NONSPREAD_SOURCE_ENABLE;
  5361. final &= ~DREF_SSC_SOURCE_MASK;
  5362. final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  5363. final &= ~DREF_SSC1_ENABLE;
  5364. if (has_panel) {
  5365. final |= DREF_SSC_SOURCE_ENABLE;
  5366. if (intel_panel_use_ssc(dev_priv) && can_ssc)
  5367. final |= DREF_SSC1_ENABLE;
  5368. if (has_cpu_edp) {
  5369. if (intel_panel_use_ssc(dev_priv) && can_ssc)
  5370. final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
  5371. else
  5372. final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
  5373. } else
  5374. final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  5375. } else {
  5376. final |= DREF_SSC_SOURCE_DISABLE;
  5377. final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  5378. }
  5379. if (final == val)
  5380. return;
  5381. /* Always enable nonspread source */
  5382. val &= ~DREF_NONSPREAD_SOURCE_MASK;
  5383. if (has_ck505)
  5384. val |= DREF_NONSPREAD_CK505_ENABLE;
  5385. else
  5386. val |= DREF_NONSPREAD_SOURCE_ENABLE;
  5387. if (has_panel) {
  5388. val &= ~DREF_SSC_SOURCE_MASK;
  5389. val |= DREF_SSC_SOURCE_ENABLE;
  5390. /* SSC must be turned on before enabling the CPU output */
  5391. if (intel_panel_use_ssc(dev_priv) && can_ssc) {
  5392. DRM_DEBUG_KMS("Using SSC on panel\n");
  5393. val |= DREF_SSC1_ENABLE;
  5394. } else
  5395. val &= ~DREF_SSC1_ENABLE;
  5396. /* Get SSC going before enabling the outputs */
  5397. I915_WRITE(PCH_DREF_CONTROL, val);
  5398. POSTING_READ(PCH_DREF_CONTROL);
  5399. udelay(200);
  5400. val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  5401. /* Enable CPU source on CPU attached eDP */
  5402. if (has_cpu_edp) {
  5403. if (intel_panel_use_ssc(dev_priv) && can_ssc) {
  5404. DRM_DEBUG_KMS("Using SSC on eDP\n");
  5405. val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
  5406. } else
  5407. val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
  5408. } else
  5409. val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  5410. I915_WRITE(PCH_DREF_CONTROL, val);
  5411. POSTING_READ(PCH_DREF_CONTROL);
  5412. udelay(200);
  5413. } else {
  5414. DRM_DEBUG_KMS("Disabling SSC entirely\n");
  5415. val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  5416. /* Turn off CPU output */
  5417. val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  5418. I915_WRITE(PCH_DREF_CONTROL, val);
  5419. POSTING_READ(PCH_DREF_CONTROL);
  5420. udelay(200);
  5421. /* Turn off the SSC source */
  5422. val &= ~DREF_SSC_SOURCE_MASK;
  5423. val |= DREF_SSC_SOURCE_DISABLE;
  5424. /* Turn off SSC1 */
  5425. val &= ~DREF_SSC1_ENABLE;
  5426. I915_WRITE(PCH_DREF_CONTROL, val);
  5427. POSTING_READ(PCH_DREF_CONTROL);
  5428. udelay(200);
  5429. }
  5430. BUG_ON(val != final);
  5431. }
  5432. static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv)
  5433. {
  5434. uint32_t tmp;
  5435. tmp = I915_READ(SOUTH_CHICKEN2);
  5436. tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
  5437. I915_WRITE(SOUTH_CHICKEN2, tmp);
  5438. if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) &
  5439. FDI_MPHY_IOSFSB_RESET_STATUS, 100))
  5440. DRM_ERROR("FDI mPHY reset assert timeout\n");
  5441. tmp = I915_READ(SOUTH_CHICKEN2);
  5442. tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
  5443. I915_WRITE(SOUTH_CHICKEN2, tmp);
  5444. if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) &
  5445. FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100))
  5446. DRM_ERROR("FDI mPHY reset de-assert timeout\n");
  5447. }
  5448. /* WaMPhyProgramming:hsw */
  5449. static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv)
  5450. {
  5451. uint32_t tmp;
  5452. tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
  5453. tmp &= ~(0xFF << 24);
  5454. tmp |= (0x12 << 24);
  5455. intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
  5456. tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
  5457. tmp |= (1 << 11);
  5458. intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
  5459. tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
  5460. tmp |= (1 << 11);
  5461. intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
  5462. tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
  5463. tmp |= (1 << 24) | (1 << 21) | (1 << 18);
  5464. intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
  5465. tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
  5466. tmp |= (1 << 24) | (1 << 21) | (1 << 18);
  5467. intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
  5468. tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
  5469. tmp &= ~(7 << 13);
  5470. tmp |= (5 << 13);
  5471. intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
  5472. tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
  5473. tmp &= ~(7 << 13);
  5474. tmp |= (5 << 13);
  5475. intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
  5476. tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
  5477. tmp &= ~0xFF;
  5478. tmp |= 0x1C;
  5479. intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
  5480. tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
  5481. tmp &= ~0xFF;
  5482. tmp |= 0x1C;
  5483. intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
  5484. tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
  5485. tmp &= ~(0xFF << 16);
  5486. tmp |= (0x1C << 16);
  5487. intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
  5488. tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
  5489. tmp &= ~(0xFF << 16);
  5490. tmp |= (0x1C << 16);
  5491. intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
  5492. tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
  5493. tmp |= (1 << 27);
  5494. intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
  5495. tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
  5496. tmp |= (1 << 27);
  5497. intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
  5498. tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
  5499. tmp &= ~(0xF << 28);
  5500. tmp |= (4 << 28);
  5501. intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
  5502. tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
  5503. tmp &= ~(0xF << 28);
  5504. tmp |= (4 << 28);
  5505. intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
  5506. }
  5507. /* Implements 3 different sequences from BSpec chapter "Display iCLK
  5508. * Programming" based on the parameters passed:
  5509. * - Sequence to enable CLKOUT_DP
  5510. * - Sequence to enable CLKOUT_DP without spread
  5511. * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
  5512. */
  5513. static void lpt_enable_clkout_dp(struct drm_device *dev, bool with_spread,
  5514. bool with_fdi)
  5515. {
  5516. struct drm_i915_private *dev_priv = dev->dev_private;
  5517. uint32_t reg, tmp;
  5518. if (WARN(with_fdi && !with_spread, "FDI requires downspread\n"))
  5519. with_spread = true;
  5520. if (WARN(dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE &&
  5521. with_fdi, "LP PCH doesn't have FDI\n"))
  5522. with_fdi = false;
  5523. mutex_lock(&dev_priv->dpio_lock);
  5524. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  5525. tmp &= ~SBI_SSCCTL_DISABLE;
  5526. tmp |= SBI_SSCCTL_PATHALT;
  5527. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  5528. udelay(24);
  5529. if (with_spread) {
  5530. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  5531. tmp &= ~SBI_SSCCTL_PATHALT;
  5532. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  5533. if (with_fdi) {
  5534. lpt_reset_fdi_mphy(dev_priv);
  5535. lpt_program_fdi_mphy(dev_priv);
  5536. }
  5537. }
  5538. reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ?
  5539. SBI_GEN0 : SBI_DBUFF0;
  5540. tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
  5541. tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE;
  5542. intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
  5543. mutex_unlock(&dev_priv->dpio_lock);
  5544. }
  5545. /* Sequence to disable CLKOUT_DP */
  5546. static void lpt_disable_clkout_dp(struct drm_device *dev)
  5547. {
  5548. struct drm_i915_private *dev_priv = dev->dev_private;
  5549. uint32_t reg, tmp;
  5550. mutex_lock(&dev_priv->dpio_lock);
  5551. reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ?
  5552. SBI_GEN0 : SBI_DBUFF0;
  5553. tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
  5554. tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE;
  5555. intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
  5556. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  5557. if (!(tmp & SBI_SSCCTL_DISABLE)) {
  5558. if (!(tmp & SBI_SSCCTL_PATHALT)) {
  5559. tmp |= SBI_SSCCTL_PATHALT;
  5560. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  5561. udelay(32);
  5562. }
  5563. tmp |= SBI_SSCCTL_DISABLE;
  5564. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  5565. }
  5566. mutex_unlock(&dev_priv->dpio_lock);
  5567. }
  5568. static void lpt_init_pch_refclk(struct drm_device *dev)
  5569. {
  5570. struct drm_mode_config *mode_config = &dev->mode_config;
  5571. struct intel_encoder *encoder;
  5572. bool has_vga = false;
  5573. list_for_each_entry(encoder, &mode_config->encoder_list, base.head) {
  5574. switch (encoder->type) {
  5575. case INTEL_OUTPUT_ANALOG:
  5576. has_vga = true;
  5577. break;
  5578. }
  5579. }
  5580. if (has_vga)
  5581. lpt_enable_clkout_dp(dev, true, true);
  5582. else
  5583. lpt_disable_clkout_dp(dev);
  5584. }
  5585. /*
  5586. * Initialize reference clocks when the driver loads
  5587. */
  5588. void intel_init_pch_refclk(struct drm_device *dev)
  5589. {
  5590. if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
  5591. ironlake_init_pch_refclk(dev);
  5592. else if (HAS_PCH_LPT(dev))
  5593. lpt_init_pch_refclk(dev);
  5594. }
  5595. static int ironlake_get_refclk(struct drm_crtc *crtc)
  5596. {
  5597. struct drm_device *dev = crtc->dev;
  5598. struct drm_i915_private *dev_priv = dev->dev_private;
  5599. struct intel_encoder *encoder;
  5600. int num_connectors = 0;
  5601. bool is_lvds = false;
  5602. for_each_encoder_on_crtc(dev, crtc, encoder) {
  5603. switch (encoder->type) {
  5604. case INTEL_OUTPUT_LVDS:
  5605. is_lvds = true;
  5606. break;
  5607. }
  5608. num_connectors++;
  5609. }
  5610. if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
  5611. DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
  5612. dev_priv->vbt.lvds_ssc_freq);
  5613. return dev_priv->vbt.lvds_ssc_freq;
  5614. }
  5615. return 120000;
  5616. }
  5617. static void ironlake_set_pipeconf(struct drm_crtc *crtc)
  5618. {
  5619. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  5620. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5621. int pipe = intel_crtc->pipe;
  5622. uint32_t val;
  5623. val = 0;
  5624. switch (intel_crtc->config.pipe_bpp) {
  5625. case 18:
  5626. val |= PIPECONF_6BPC;
  5627. break;
  5628. case 24:
  5629. val |= PIPECONF_8BPC;
  5630. break;
  5631. case 30:
  5632. val |= PIPECONF_10BPC;
  5633. break;
  5634. case 36:
  5635. val |= PIPECONF_12BPC;
  5636. break;
  5637. default:
  5638. /* Case prevented by intel_choose_pipe_bpp_dither. */
  5639. BUG();
  5640. }
  5641. if (intel_crtc->config.dither)
  5642. val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
  5643. if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
  5644. val |= PIPECONF_INTERLACED_ILK;
  5645. else
  5646. val |= PIPECONF_PROGRESSIVE;
  5647. if (intel_crtc->config.limited_color_range)
  5648. val |= PIPECONF_COLOR_RANGE_SELECT;
  5649. I915_WRITE(PIPECONF(pipe), val);
  5650. POSTING_READ(PIPECONF(pipe));
  5651. }
  5652. /*
  5653. * Set up the pipe CSC unit.
  5654. *
  5655. * Currently only full range RGB to limited range RGB conversion
  5656. * is supported, but eventually this should handle various
  5657. * RGB<->YCbCr scenarios as well.
  5658. */
  5659. static void intel_set_pipe_csc(struct drm_crtc *crtc)
  5660. {
  5661. struct drm_device *dev = crtc->dev;
  5662. struct drm_i915_private *dev_priv = dev->dev_private;
  5663. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5664. int pipe = intel_crtc->pipe;
  5665. uint16_t coeff = 0x7800; /* 1.0 */
  5666. /*
  5667. * TODO: Check what kind of values actually come out of the pipe
  5668. * with these coeff/postoff values and adjust to get the best
  5669. * accuracy. Perhaps we even need to take the bpc value into
  5670. * consideration.
  5671. */
  5672. if (intel_crtc->config.limited_color_range)
  5673. coeff = ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */
  5674. /*
  5675. * GY/GU and RY/RU should be the other way around according
  5676. * to BSpec, but reality doesn't agree. Just set them up in
  5677. * a way that results in the correct picture.
  5678. */
  5679. I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe), coeff << 16);
  5680. I915_WRITE(PIPE_CSC_COEFF_BY(pipe), 0);
  5681. I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe), coeff);
  5682. I915_WRITE(PIPE_CSC_COEFF_BU(pipe), 0);
  5683. I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe), 0);
  5684. I915_WRITE(PIPE_CSC_COEFF_BV(pipe), coeff << 16);
  5685. I915_WRITE(PIPE_CSC_PREOFF_HI(pipe), 0);
  5686. I915_WRITE(PIPE_CSC_PREOFF_ME(pipe), 0);
  5687. I915_WRITE(PIPE_CSC_PREOFF_LO(pipe), 0);
  5688. if (INTEL_INFO(dev)->gen > 6) {
  5689. uint16_t postoff = 0;
  5690. if (intel_crtc->config.limited_color_range)
  5691. postoff = (16 * (1 << 12) / 255) & 0x1fff;
  5692. I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe), postoff);
  5693. I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe), postoff);
  5694. I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe), postoff);
  5695. I915_WRITE(PIPE_CSC_MODE(pipe), 0);
  5696. } else {
  5697. uint32_t mode = CSC_MODE_YUV_TO_RGB;
  5698. if (intel_crtc->config.limited_color_range)
  5699. mode |= CSC_BLACK_SCREEN_OFFSET;
  5700. I915_WRITE(PIPE_CSC_MODE(pipe), mode);
  5701. }
  5702. }
  5703. static void haswell_set_pipeconf(struct drm_crtc *crtc)
  5704. {
  5705. struct drm_device *dev = crtc->dev;
  5706. struct drm_i915_private *dev_priv = dev->dev_private;
  5707. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5708. enum pipe pipe = intel_crtc->pipe;
  5709. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  5710. uint32_t val;
  5711. val = 0;
  5712. if (IS_HASWELL(dev) && intel_crtc->config.dither)
  5713. val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
  5714. if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
  5715. val |= PIPECONF_INTERLACED_ILK;
  5716. else
  5717. val |= PIPECONF_PROGRESSIVE;
  5718. I915_WRITE(PIPECONF(cpu_transcoder), val);
  5719. POSTING_READ(PIPECONF(cpu_transcoder));
  5720. I915_WRITE(GAMMA_MODE(intel_crtc->pipe), GAMMA_MODE_MODE_8BIT);
  5721. POSTING_READ(GAMMA_MODE(intel_crtc->pipe));
  5722. if (IS_BROADWELL(dev)) {
  5723. val = 0;
  5724. switch (intel_crtc->config.pipe_bpp) {
  5725. case 18:
  5726. val |= PIPEMISC_DITHER_6_BPC;
  5727. break;
  5728. case 24:
  5729. val |= PIPEMISC_DITHER_8_BPC;
  5730. break;
  5731. case 30:
  5732. val |= PIPEMISC_DITHER_10_BPC;
  5733. break;
  5734. case 36:
  5735. val |= PIPEMISC_DITHER_12_BPC;
  5736. break;
  5737. default:
  5738. /* Case prevented by pipe_config_set_bpp. */
  5739. BUG();
  5740. }
  5741. if (intel_crtc->config.dither)
  5742. val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
  5743. I915_WRITE(PIPEMISC(pipe), val);
  5744. }
  5745. }
  5746. static bool ironlake_compute_clocks(struct drm_crtc *crtc,
  5747. intel_clock_t *clock,
  5748. bool *has_reduced_clock,
  5749. intel_clock_t *reduced_clock)
  5750. {
  5751. struct drm_device *dev = crtc->dev;
  5752. struct drm_i915_private *dev_priv = dev->dev_private;
  5753. struct intel_encoder *intel_encoder;
  5754. int refclk;
  5755. const intel_limit_t *limit;
  5756. bool ret, is_lvds = false;
  5757. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  5758. switch (intel_encoder->type) {
  5759. case INTEL_OUTPUT_LVDS:
  5760. is_lvds = true;
  5761. break;
  5762. }
  5763. }
  5764. refclk = ironlake_get_refclk(crtc);
  5765. /*
  5766. * Returns a set of divisors for the desired target clock with the given
  5767. * refclk, or FALSE. The returned values represent the clock equation:
  5768. * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
  5769. */
  5770. limit = intel_limit(crtc, refclk);
  5771. ret = dev_priv->display.find_dpll(limit, crtc,
  5772. to_intel_crtc(crtc)->config.port_clock,
  5773. refclk, NULL, clock);
  5774. if (!ret)
  5775. return false;
  5776. if (is_lvds && dev_priv->lvds_downclock_avail) {
  5777. /*
  5778. * Ensure we match the reduced clock's P to the target clock.
  5779. * If the clocks don't match, we can't switch the display clock
  5780. * by using the FP0/FP1. In such case we will disable the LVDS
  5781. * downclock feature.
  5782. */
  5783. *has_reduced_clock =
  5784. dev_priv->display.find_dpll(limit, crtc,
  5785. dev_priv->lvds_downclock,
  5786. refclk, clock,
  5787. reduced_clock);
  5788. }
  5789. return true;
  5790. }
  5791. int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
  5792. {
  5793. /*
  5794. * Account for spread spectrum to avoid
  5795. * oversubscribing the link. Max center spread
  5796. * is 2.5%; use 5% for safety's sake.
  5797. */
  5798. u32 bps = target_clock * bpp * 21 / 20;
  5799. return DIV_ROUND_UP(bps, link_bw * 8);
  5800. }
  5801. static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor)
  5802. {
  5803. return i9xx_dpll_compute_m(dpll) < factor * dpll->n;
  5804. }
  5805. static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc,
  5806. u32 *fp,
  5807. intel_clock_t *reduced_clock, u32 *fp2)
  5808. {
  5809. struct drm_crtc *crtc = &intel_crtc->base;
  5810. struct drm_device *dev = crtc->dev;
  5811. struct drm_i915_private *dev_priv = dev->dev_private;
  5812. struct intel_encoder *intel_encoder;
  5813. uint32_t dpll;
  5814. int factor, num_connectors = 0;
  5815. bool is_lvds = false, is_sdvo = false;
  5816. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  5817. switch (intel_encoder->type) {
  5818. case INTEL_OUTPUT_LVDS:
  5819. is_lvds = true;
  5820. break;
  5821. case INTEL_OUTPUT_SDVO:
  5822. case INTEL_OUTPUT_HDMI:
  5823. is_sdvo = true;
  5824. break;
  5825. }
  5826. num_connectors++;
  5827. }
  5828. /* Enable autotuning of the PLL clock (if permissible) */
  5829. factor = 21;
  5830. if (is_lvds) {
  5831. if ((intel_panel_use_ssc(dev_priv) &&
  5832. dev_priv->vbt.lvds_ssc_freq == 100000) ||
  5833. (HAS_PCH_IBX(dev) && intel_is_dual_link_lvds(dev)))
  5834. factor = 25;
  5835. } else if (intel_crtc->config.sdvo_tv_clock)
  5836. factor = 20;
  5837. if (ironlake_needs_fb_cb_tune(&intel_crtc->config.dpll, factor))
  5838. *fp |= FP_CB_TUNE;
  5839. if (fp2 && (reduced_clock->m < factor * reduced_clock->n))
  5840. *fp2 |= FP_CB_TUNE;
  5841. dpll = 0;
  5842. if (is_lvds)
  5843. dpll |= DPLLB_MODE_LVDS;
  5844. else
  5845. dpll |= DPLLB_MODE_DAC_SERIAL;
  5846. dpll |= (intel_crtc->config.pixel_multiplier - 1)
  5847. << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
  5848. if (is_sdvo)
  5849. dpll |= DPLL_SDVO_HIGH_SPEED;
  5850. if (intel_crtc->config.has_dp_encoder)
  5851. dpll |= DPLL_SDVO_HIGH_SPEED;
  5852. /* compute bitmask from p1 value */
  5853. dpll |= (1 << (intel_crtc->config.dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  5854. /* also FPA1 */
  5855. dpll |= (1 << (intel_crtc->config.dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  5856. switch (intel_crtc->config.dpll.p2) {
  5857. case 5:
  5858. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  5859. break;
  5860. case 7:
  5861. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  5862. break;
  5863. case 10:
  5864. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  5865. break;
  5866. case 14:
  5867. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  5868. break;
  5869. }
  5870. if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  5871. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  5872. else
  5873. dpll |= PLL_REF_INPUT_DREFCLK;
  5874. return dpll | DPLL_VCO_ENABLE;
  5875. }
  5876. static int ironlake_crtc_mode_set(struct drm_crtc *crtc,
  5877. int x, int y,
  5878. struct drm_framebuffer *fb)
  5879. {
  5880. struct drm_device *dev = crtc->dev;
  5881. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5882. int num_connectors = 0;
  5883. intel_clock_t clock, reduced_clock;
  5884. u32 dpll = 0, fp = 0, fp2 = 0;
  5885. bool ok, has_reduced_clock = false;
  5886. bool is_lvds = false;
  5887. struct intel_encoder *encoder;
  5888. struct intel_shared_dpll *pll;
  5889. for_each_encoder_on_crtc(dev, crtc, encoder) {
  5890. switch (encoder->type) {
  5891. case INTEL_OUTPUT_LVDS:
  5892. is_lvds = true;
  5893. break;
  5894. }
  5895. num_connectors++;
  5896. }
  5897. WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)),
  5898. "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev));
  5899. ok = ironlake_compute_clocks(crtc, &clock,
  5900. &has_reduced_clock, &reduced_clock);
  5901. if (!ok && !intel_crtc->config.clock_set) {
  5902. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  5903. return -EINVAL;
  5904. }
  5905. /* Compat-code for transition, will disappear. */
  5906. if (!intel_crtc->config.clock_set) {
  5907. intel_crtc->config.dpll.n = clock.n;
  5908. intel_crtc->config.dpll.m1 = clock.m1;
  5909. intel_crtc->config.dpll.m2 = clock.m2;
  5910. intel_crtc->config.dpll.p1 = clock.p1;
  5911. intel_crtc->config.dpll.p2 = clock.p2;
  5912. }
  5913. /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
  5914. if (intel_crtc->config.has_pch_encoder) {
  5915. fp = i9xx_dpll_compute_fp(&intel_crtc->config.dpll);
  5916. if (has_reduced_clock)
  5917. fp2 = i9xx_dpll_compute_fp(&reduced_clock);
  5918. dpll = ironlake_compute_dpll(intel_crtc,
  5919. &fp, &reduced_clock,
  5920. has_reduced_clock ? &fp2 : NULL);
  5921. intel_crtc->config.dpll_hw_state.dpll = dpll;
  5922. intel_crtc->config.dpll_hw_state.fp0 = fp;
  5923. if (has_reduced_clock)
  5924. intel_crtc->config.dpll_hw_state.fp1 = fp2;
  5925. else
  5926. intel_crtc->config.dpll_hw_state.fp1 = fp;
  5927. pll = intel_get_shared_dpll(intel_crtc);
  5928. if (pll == NULL) {
  5929. DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
  5930. pipe_name(intel_crtc->pipe));
  5931. return -EINVAL;
  5932. }
  5933. } else
  5934. intel_put_shared_dpll(intel_crtc);
  5935. if (is_lvds && has_reduced_clock && i915.powersave)
  5936. intel_crtc->lowfreq_avail = true;
  5937. else
  5938. intel_crtc->lowfreq_avail = false;
  5939. return 0;
  5940. }
  5941. static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc,
  5942. struct intel_link_m_n *m_n)
  5943. {
  5944. struct drm_device *dev = crtc->base.dev;
  5945. struct drm_i915_private *dev_priv = dev->dev_private;
  5946. enum pipe pipe = crtc->pipe;
  5947. m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe));
  5948. m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe));
  5949. m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe))
  5950. & ~TU_SIZE_MASK;
  5951. m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe));
  5952. m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe))
  5953. & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
  5954. }
  5955. static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc,
  5956. enum transcoder transcoder,
  5957. struct intel_link_m_n *m_n)
  5958. {
  5959. struct drm_device *dev = crtc->base.dev;
  5960. struct drm_i915_private *dev_priv = dev->dev_private;
  5961. enum pipe pipe = crtc->pipe;
  5962. if (INTEL_INFO(dev)->gen >= 5) {
  5963. m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder));
  5964. m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder));
  5965. m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder))
  5966. & ~TU_SIZE_MASK;
  5967. m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder));
  5968. m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder))
  5969. & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
  5970. } else {
  5971. m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe));
  5972. m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe));
  5973. m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe))
  5974. & ~TU_SIZE_MASK;
  5975. m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe));
  5976. m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe))
  5977. & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
  5978. }
  5979. }
  5980. void intel_dp_get_m_n(struct intel_crtc *crtc,
  5981. struct intel_crtc_config *pipe_config)
  5982. {
  5983. if (crtc->config.has_pch_encoder)
  5984. intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n);
  5985. else
  5986. intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
  5987. &pipe_config->dp_m_n);
  5988. }
  5989. static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc,
  5990. struct intel_crtc_config *pipe_config)
  5991. {
  5992. intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
  5993. &pipe_config->fdi_m_n);
  5994. }
  5995. static void ironlake_get_pfit_config(struct intel_crtc *crtc,
  5996. struct intel_crtc_config *pipe_config)
  5997. {
  5998. struct drm_device *dev = crtc->base.dev;
  5999. struct drm_i915_private *dev_priv = dev->dev_private;
  6000. uint32_t tmp;
  6001. tmp = I915_READ(PF_CTL(crtc->pipe));
  6002. if (tmp & PF_ENABLE) {
  6003. pipe_config->pch_pfit.enabled = true;
  6004. pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe));
  6005. pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe));
  6006. /* We currently do not free assignements of panel fitters on
  6007. * ivb/hsw (since we don't use the higher upscaling modes which
  6008. * differentiates them) so just WARN about this case for now. */
  6009. if (IS_GEN7(dev)) {
  6010. WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) !=
  6011. PF_PIPE_SEL_IVB(crtc->pipe));
  6012. }
  6013. }
  6014. }
  6015. static void ironlake_get_plane_config(struct intel_crtc *crtc,
  6016. struct intel_plane_config *plane_config)
  6017. {
  6018. struct drm_device *dev = crtc->base.dev;
  6019. struct drm_i915_private *dev_priv = dev->dev_private;
  6020. u32 val, base, offset;
  6021. int pipe = crtc->pipe, plane = crtc->plane;
  6022. int fourcc, pixel_format;
  6023. int aligned_height;
  6024. crtc->base.primary->fb = kzalloc(sizeof(struct intel_framebuffer), GFP_KERNEL);
  6025. if (!crtc->base.primary->fb) {
  6026. DRM_DEBUG_KMS("failed to alloc fb\n");
  6027. return;
  6028. }
  6029. val = I915_READ(DSPCNTR(plane));
  6030. if (INTEL_INFO(dev)->gen >= 4)
  6031. if (val & DISPPLANE_TILED)
  6032. plane_config->tiled = true;
  6033. pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
  6034. fourcc = intel_format_to_fourcc(pixel_format);
  6035. crtc->base.primary->fb->pixel_format = fourcc;
  6036. crtc->base.primary->fb->bits_per_pixel =
  6037. drm_format_plane_cpp(fourcc, 0) * 8;
  6038. base = I915_READ(DSPSURF(plane)) & 0xfffff000;
  6039. if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  6040. offset = I915_READ(DSPOFFSET(plane));
  6041. } else {
  6042. if (plane_config->tiled)
  6043. offset = I915_READ(DSPTILEOFF(plane));
  6044. else
  6045. offset = I915_READ(DSPLINOFF(plane));
  6046. }
  6047. plane_config->base = base;
  6048. val = I915_READ(PIPESRC(pipe));
  6049. crtc->base.primary->fb->width = ((val >> 16) & 0xfff) + 1;
  6050. crtc->base.primary->fb->height = ((val >> 0) & 0xfff) + 1;
  6051. val = I915_READ(DSPSTRIDE(pipe));
  6052. crtc->base.primary->fb->pitches[0] = val & 0xffffff80;
  6053. aligned_height = intel_align_height(dev, crtc->base.primary->fb->height,
  6054. plane_config->tiled);
  6055. plane_config->size = PAGE_ALIGN(crtc->base.primary->fb->pitches[0] *
  6056. aligned_height);
  6057. DRM_DEBUG_KMS("pipe/plane %d/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
  6058. pipe, plane, crtc->base.primary->fb->width,
  6059. crtc->base.primary->fb->height,
  6060. crtc->base.primary->fb->bits_per_pixel, base,
  6061. crtc->base.primary->fb->pitches[0],
  6062. plane_config->size);
  6063. }
  6064. static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
  6065. struct intel_crtc_config *pipe_config)
  6066. {
  6067. struct drm_device *dev = crtc->base.dev;
  6068. struct drm_i915_private *dev_priv = dev->dev_private;
  6069. uint32_t tmp;
  6070. pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
  6071. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  6072. tmp = I915_READ(PIPECONF(crtc->pipe));
  6073. if (!(tmp & PIPECONF_ENABLE))
  6074. return false;
  6075. switch (tmp & PIPECONF_BPC_MASK) {
  6076. case PIPECONF_6BPC:
  6077. pipe_config->pipe_bpp = 18;
  6078. break;
  6079. case PIPECONF_8BPC:
  6080. pipe_config->pipe_bpp = 24;
  6081. break;
  6082. case PIPECONF_10BPC:
  6083. pipe_config->pipe_bpp = 30;
  6084. break;
  6085. case PIPECONF_12BPC:
  6086. pipe_config->pipe_bpp = 36;
  6087. break;
  6088. default:
  6089. break;
  6090. }
  6091. if (tmp & PIPECONF_COLOR_RANGE_SELECT)
  6092. pipe_config->limited_color_range = true;
  6093. if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) {
  6094. struct intel_shared_dpll *pll;
  6095. pipe_config->has_pch_encoder = true;
  6096. tmp = I915_READ(FDI_RX_CTL(crtc->pipe));
  6097. pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
  6098. FDI_DP_PORT_WIDTH_SHIFT) + 1;
  6099. ironlake_get_fdi_m_n_config(crtc, pipe_config);
  6100. if (HAS_PCH_IBX(dev_priv->dev)) {
  6101. pipe_config->shared_dpll =
  6102. (enum intel_dpll_id) crtc->pipe;
  6103. } else {
  6104. tmp = I915_READ(PCH_DPLL_SEL);
  6105. if (tmp & TRANS_DPLLB_SEL(crtc->pipe))
  6106. pipe_config->shared_dpll = DPLL_ID_PCH_PLL_B;
  6107. else
  6108. pipe_config->shared_dpll = DPLL_ID_PCH_PLL_A;
  6109. }
  6110. pll = &dev_priv->shared_dplls[pipe_config->shared_dpll];
  6111. WARN_ON(!pll->get_hw_state(dev_priv, pll,
  6112. &pipe_config->dpll_hw_state));
  6113. tmp = pipe_config->dpll_hw_state.dpll;
  6114. pipe_config->pixel_multiplier =
  6115. ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK)
  6116. >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1;
  6117. ironlake_pch_clock_get(crtc, pipe_config);
  6118. } else {
  6119. pipe_config->pixel_multiplier = 1;
  6120. }
  6121. intel_get_pipe_timings(crtc, pipe_config);
  6122. ironlake_get_pfit_config(crtc, pipe_config);
  6123. return true;
  6124. }
  6125. static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv)
  6126. {
  6127. struct drm_device *dev = dev_priv->dev;
  6128. struct intel_ddi_plls *plls = &dev_priv->ddi_plls;
  6129. struct intel_crtc *crtc;
  6130. for_each_intel_crtc(dev, crtc)
  6131. WARN(crtc->active, "CRTC for pipe %c enabled\n",
  6132. pipe_name(crtc->pipe));
  6133. WARN(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on\n");
  6134. WARN(plls->spll_refcount, "SPLL enabled\n");
  6135. WARN(plls->wrpll1_refcount, "WRPLL1 enabled\n");
  6136. WARN(plls->wrpll2_refcount, "WRPLL2 enabled\n");
  6137. WARN(I915_READ(PCH_PP_STATUS) & PP_ON, "Panel power on\n");
  6138. WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE,
  6139. "CPU PWM1 enabled\n");
  6140. WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE,
  6141. "CPU PWM2 enabled\n");
  6142. WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE,
  6143. "PCH PWM1 enabled\n");
  6144. WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
  6145. "Utility pin enabled\n");
  6146. WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n");
  6147. /*
  6148. * In theory we can still leave IRQs enabled, as long as only the HPD
  6149. * interrupts remain enabled. We used to check for that, but since it's
  6150. * gen-specific and since we only disable LCPLL after we fully disable
  6151. * the interrupts, the check below should be enough.
  6152. */
  6153. WARN(!dev_priv->pm.irqs_disabled, "IRQs enabled\n");
  6154. }
  6155. static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv)
  6156. {
  6157. struct drm_device *dev = dev_priv->dev;
  6158. if (IS_HASWELL(dev))
  6159. return I915_READ(D_COMP_HSW);
  6160. else
  6161. return I915_READ(D_COMP_BDW);
  6162. }
  6163. static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val)
  6164. {
  6165. struct drm_device *dev = dev_priv->dev;
  6166. if (IS_HASWELL(dev)) {
  6167. mutex_lock(&dev_priv->rps.hw_lock);
  6168. if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP,
  6169. val))
  6170. DRM_ERROR("Failed to write to D_COMP\n");
  6171. mutex_unlock(&dev_priv->rps.hw_lock);
  6172. } else {
  6173. I915_WRITE(D_COMP_BDW, val);
  6174. POSTING_READ(D_COMP_BDW);
  6175. }
  6176. }
  6177. /*
  6178. * This function implements pieces of two sequences from BSpec:
  6179. * - Sequence for display software to disable LCPLL
  6180. * - Sequence for display software to allow package C8+
  6181. * The steps implemented here are just the steps that actually touch the LCPLL
  6182. * register. Callers should take care of disabling all the display engine
  6183. * functions, doing the mode unset, fixing interrupts, etc.
  6184. */
  6185. static void hsw_disable_lcpll(struct drm_i915_private *dev_priv,
  6186. bool switch_to_fclk, bool allow_power_down)
  6187. {
  6188. uint32_t val;
  6189. assert_can_disable_lcpll(dev_priv);
  6190. val = I915_READ(LCPLL_CTL);
  6191. if (switch_to_fclk) {
  6192. val |= LCPLL_CD_SOURCE_FCLK;
  6193. I915_WRITE(LCPLL_CTL, val);
  6194. if (wait_for_atomic_us(I915_READ(LCPLL_CTL) &
  6195. LCPLL_CD_SOURCE_FCLK_DONE, 1))
  6196. DRM_ERROR("Switching to FCLK failed\n");
  6197. val = I915_READ(LCPLL_CTL);
  6198. }
  6199. val |= LCPLL_PLL_DISABLE;
  6200. I915_WRITE(LCPLL_CTL, val);
  6201. POSTING_READ(LCPLL_CTL);
  6202. if (wait_for((I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK) == 0, 1))
  6203. DRM_ERROR("LCPLL still locked\n");
  6204. val = hsw_read_dcomp(dev_priv);
  6205. val |= D_COMP_COMP_DISABLE;
  6206. hsw_write_dcomp(dev_priv, val);
  6207. ndelay(100);
  6208. if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0,
  6209. 1))
  6210. DRM_ERROR("D_COMP RCOMP still in progress\n");
  6211. if (allow_power_down) {
  6212. val = I915_READ(LCPLL_CTL);
  6213. val |= LCPLL_POWER_DOWN_ALLOW;
  6214. I915_WRITE(LCPLL_CTL, val);
  6215. POSTING_READ(LCPLL_CTL);
  6216. }
  6217. }
  6218. /*
  6219. * Fully restores LCPLL, disallowing power down and switching back to LCPLL
  6220. * source.
  6221. */
  6222. static void hsw_restore_lcpll(struct drm_i915_private *dev_priv)
  6223. {
  6224. uint32_t val;
  6225. unsigned long irqflags;
  6226. val = I915_READ(LCPLL_CTL);
  6227. if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK |
  6228. LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK)
  6229. return;
  6230. /*
  6231. * Make sure we're not on PC8 state before disabling PC8, otherwise
  6232. * we'll hang the machine. To prevent PC8 state, just enable force_wake.
  6233. *
  6234. * The other problem is that hsw_restore_lcpll() is called as part of
  6235. * the runtime PM resume sequence, so we can't just call
  6236. * gen6_gt_force_wake_get() because that function calls
  6237. * intel_runtime_pm_get(), and we can't change the runtime PM refcount
  6238. * while we are on the resume sequence. So to solve this problem we have
  6239. * to call special forcewake code that doesn't touch runtime PM and
  6240. * doesn't enable the forcewake delayed work.
  6241. */
  6242. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  6243. if (dev_priv->uncore.forcewake_count++ == 0)
  6244. dev_priv->uncore.funcs.force_wake_get(dev_priv, FORCEWAKE_ALL);
  6245. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  6246. if (val & LCPLL_POWER_DOWN_ALLOW) {
  6247. val &= ~LCPLL_POWER_DOWN_ALLOW;
  6248. I915_WRITE(LCPLL_CTL, val);
  6249. POSTING_READ(LCPLL_CTL);
  6250. }
  6251. val = hsw_read_dcomp(dev_priv);
  6252. val |= D_COMP_COMP_FORCE;
  6253. val &= ~D_COMP_COMP_DISABLE;
  6254. hsw_write_dcomp(dev_priv, val);
  6255. val = I915_READ(LCPLL_CTL);
  6256. val &= ~LCPLL_PLL_DISABLE;
  6257. I915_WRITE(LCPLL_CTL, val);
  6258. if (wait_for(I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK, 5))
  6259. DRM_ERROR("LCPLL not locked yet\n");
  6260. if (val & LCPLL_CD_SOURCE_FCLK) {
  6261. val = I915_READ(LCPLL_CTL);
  6262. val &= ~LCPLL_CD_SOURCE_FCLK;
  6263. I915_WRITE(LCPLL_CTL, val);
  6264. if (wait_for_atomic_us((I915_READ(LCPLL_CTL) &
  6265. LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1))
  6266. DRM_ERROR("Switching back to LCPLL failed\n");
  6267. }
  6268. /* See the big comment above. */
  6269. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  6270. if (--dev_priv->uncore.forcewake_count == 0)
  6271. dev_priv->uncore.funcs.force_wake_put(dev_priv, FORCEWAKE_ALL);
  6272. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  6273. }
  6274. /*
  6275. * Package states C8 and deeper are really deep PC states that can only be
  6276. * reached when all the devices on the system allow it, so even if the graphics
  6277. * device allows PC8+, it doesn't mean the system will actually get to these
  6278. * states. Our driver only allows PC8+ when going into runtime PM.
  6279. *
  6280. * The requirements for PC8+ are that all the outputs are disabled, the power
  6281. * well is disabled and most interrupts are disabled, and these are also
  6282. * requirements for runtime PM. When these conditions are met, we manually do
  6283. * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
  6284. * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
  6285. * hang the machine.
  6286. *
  6287. * When we really reach PC8 or deeper states (not just when we allow it) we lose
  6288. * the state of some registers, so when we come back from PC8+ we need to
  6289. * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
  6290. * need to take care of the registers kept by RC6. Notice that this happens even
  6291. * if we don't put the device in PCI D3 state (which is what currently happens
  6292. * because of the runtime PM support).
  6293. *
  6294. * For more, read "Display Sequences for Package C8" on the hardware
  6295. * documentation.
  6296. */
  6297. void hsw_enable_pc8(struct drm_i915_private *dev_priv)
  6298. {
  6299. struct drm_device *dev = dev_priv->dev;
  6300. uint32_t val;
  6301. DRM_DEBUG_KMS("Enabling package C8+\n");
  6302. if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) {
  6303. val = I915_READ(SOUTH_DSPCLK_GATE_D);
  6304. val &= ~PCH_LP_PARTITION_LEVEL_DISABLE;
  6305. I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
  6306. }
  6307. lpt_disable_clkout_dp(dev);
  6308. hsw_disable_lcpll(dev_priv, true, true);
  6309. }
  6310. void hsw_disable_pc8(struct drm_i915_private *dev_priv)
  6311. {
  6312. struct drm_device *dev = dev_priv->dev;
  6313. uint32_t val;
  6314. DRM_DEBUG_KMS("Disabling package C8+\n");
  6315. hsw_restore_lcpll(dev_priv);
  6316. lpt_init_pch_refclk(dev);
  6317. if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) {
  6318. val = I915_READ(SOUTH_DSPCLK_GATE_D);
  6319. val |= PCH_LP_PARTITION_LEVEL_DISABLE;
  6320. I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
  6321. }
  6322. intel_prepare_ddi(dev);
  6323. }
  6324. static void snb_modeset_global_resources(struct drm_device *dev)
  6325. {
  6326. modeset_update_crtc_power_domains(dev);
  6327. }
  6328. static void haswell_modeset_global_resources(struct drm_device *dev)
  6329. {
  6330. modeset_update_crtc_power_domains(dev);
  6331. }
  6332. static int haswell_crtc_mode_set(struct drm_crtc *crtc,
  6333. int x, int y,
  6334. struct drm_framebuffer *fb)
  6335. {
  6336. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6337. if (!intel_ddi_pll_select(intel_crtc))
  6338. return -EINVAL;
  6339. intel_ddi_pll_enable(intel_crtc);
  6340. intel_crtc->lowfreq_avail = false;
  6341. return 0;
  6342. }
  6343. static bool haswell_get_pipe_config(struct intel_crtc *crtc,
  6344. struct intel_crtc_config *pipe_config)
  6345. {
  6346. struct drm_device *dev = crtc->base.dev;
  6347. struct drm_i915_private *dev_priv = dev->dev_private;
  6348. enum intel_display_power_domain pfit_domain;
  6349. uint32_t tmp;
  6350. if (!intel_display_power_enabled(dev_priv,
  6351. POWER_DOMAIN_PIPE(crtc->pipe)))
  6352. return false;
  6353. pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
  6354. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  6355. tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
  6356. if (tmp & TRANS_DDI_FUNC_ENABLE) {
  6357. enum pipe trans_edp_pipe;
  6358. switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
  6359. default:
  6360. WARN(1, "unknown pipe linked to edp transcoder\n");
  6361. case TRANS_DDI_EDP_INPUT_A_ONOFF:
  6362. case TRANS_DDI_EDP_INPUT_A_ON:
  6363. trans_edp_pipe = PIPE_A;
  6364. break;
  6365. case TRANS_DDI_EDP_INPUT_B_ONOFF:
  6366. trans_edp_pipe = PIPE_B;
  6367. break;
  6368. case TRANS_DDI_EDP_INPUT_C_ONOFF:
  6369. trans_edp_pipe = PIPE_C;
  6370. break;
  6371. }
  6372. if (trans_edp_pipe == crtc->pipe)
  6373. pipe_config->cpu_transcoder = TRANSCODER_EDP;
  6374. }
  6375. if (!intel_display_power_enabled(dev_priv,
  6376. POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder)))
  6377. return false;
  6378. tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder));
  6379. if (!(tmp & PIPECONF_ENABLE))
  6380. return false;
  6381. /*
  6382. * Haswell has only FDI/PCH transcoder A. It is which is connected to
  6383. * DDI E. So just check whether this pipe is wired to DDI E and whether
  6384. * the PCH transcoder is on.
  6385. */
  6386. tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder));
  6387. if ((tmp & TRANS_DDI_PORT_MASK) == TRANS_DDI_SELECT_PORT(PORT_E) &&
  6388. I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) {
  6389. pipe_config->has_pch_encoder = true;
  6390. tmp = I915_READ(FDI_RX_CTL(PIPE_A));
  6391. pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
  6392. FDI_DP_PORT_WIDTH_SHIFT) + 1;
  6393. ironlake_get_fdi_m_n_config(crtc, pipe_config);
  6394. }
  6395. intel_get_pipe_timings(crtc, pipe_config);
  6396. pfit_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe);
  6397. if (intel_display_power_enabled(dev_priv, pfit_domain))
  6398. ironlake_get_pfit_config(crtc, pipe_config);
  6399. if (IS_HASWELL(dev))
  6400. pipe_config->ips_enabled = hsw_crtc_supports_ips(crtc) &&
  6401. (I915_READ(IPS_CTL) & IPS_ENABLE);
  6402. pipe_config->pixel_multiplier = 1;
  6403. return true;
  6404. }
  6405. static struct {
  6406. int clock;
  6407. u32 config;
  6408. } hdmi_audio_clock[] = {
  6409. { DIV_ROUND_UP(25200 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_25175 },
  6410. { 25200, AUD_CONFIG_PIXEL_CLOCK_HDMI_25200 }, /* default per bspec */
  6411. { 27000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27000 },
  6412. { 27000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27027 },
  6413. { 54000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54000 },
  6414. { 54000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54054 },
  6415. { DIV_ROUND_UP(74250 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_74176 },
  6416. { 74250, AUD_CONFIG_PIXEL_CLOCK_HDMI_74250 },
  6417. { DIV_ROUND_UP(148500 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_148352 },
  6418. { 148500, AUD_CONFIG_PIXEL_CLOCK_HDMI_148500 },
  6419. };
  6420. /* get AUD_CONFIG_PIXEL_CLOCK_HDMI_* value for mode */
  6421. static u32 audio_config_hdmi_pixel_clock(struct drm_display_mode *mode)
  6422. {
  6423. int i;
  6424. for (i = 0; i < ARRAY_SIZE(hdmi_audio_clock); i++) {
  6425. if (mode->clock == hdmi_audio_clock[i].clock)
  6426. break;
  6427. }
  6428. if (i == ARRAY_SIZE(hdmi_audio_clock)) {
  6429. DRM_DEBUG_KMS("HDMI audio pixel clock setting for %d not found, falling back to defaults\n", mode->clock);
  6430. i = 1;
  6431. }
  6432. DRM_DEBUG_KMS("Configuring HDMI audio for pixel clock %d (0x%08x)\n",
  6433. hdmi_audio_clock[i].clock,
  6434. hdmi_audio_clock[i].config);
  6435. return hdmi_audio_clock[i].config;
  6436. }
  6437. static bool intel_eld_uptodate(struct drm_connector *connector,
  6438. int reg_eldv, uint32_t bits_eldv,
  6439. int reg_elda, uint32_t bits_elda,
  6440. int reg_edid)
  6441. {
  6442. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  6443. uint8_t *eld = connector->eld;
  6444. uint32_t i;
  6445. i = I915_READ(reg_eldv);
  6446. i &= bits_eldv;
  6447. if (!eld[0])
  6448. return !i;
  6449. if (!i)
  6450. return false;
  6451. i = I915_READ(reg_elda);
  6452. i &= ~bits_elda;
  6453. I915_WRITE(reg_elda, i);
  6454. for (i = 0; i < eld[2]; i++)
  6455. if (I915_READ(reg_edid) != *((uint32_t *)eld + i))
  6456. return false;
  6457. return true;
  6458. }
  6459. static void g4x_write_eld(struct drm_connector *connector,
  6460. struct drm_crtc *crtc,
  6461. struct drm_display_mode *mode)
  6462. {
  6463. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  6464. uint8_t *eld = connector->eld;
  6465. uint32_t eldv;
  6466. uint32_t len;
  6467. uint32_t i;
  6468. i = I915_READ(G4X_AUD_VID_DID);
  6469. if (i == INTEL_AUDIO_DEVBLC || i == INTEL_AUDIO_DEVCL)
  6470. eldv = G4X_ELDV_DEVCL_DEVBLC;
  6471. else
  6472. eldv = G4X_ELDV_DEVCTG;
  6473. if (intel_eld_uptodate(connector,
  6474. G4X_AUD_CNTL_ST, eldv,
  6475. G4X_AUD_CNTL_ST, G4X_ELD_ADDR,
  6476. G4X_HDMIW_HDMIEDID))
  6477. return;
  6478. i = I915_READ(G4X_AUD_CNTL_ST);
  6479. i &= ~(eldv | G4X_ELD_ADDR);
  6480. len = (i >> 9) & 0x1f; /* ELD buffer size */
  6481. I915_WRITE(G4X_AUD_CNTL_ST, i);
  6482. if (!eld[0])
  6483. return;
  6484. len = min_t(uint8_t, eld[2], len);
  6485. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  6486. for (i = 0; i < len; i++)
  6487. I915_WRITE(G4X_HDMIW_HDMIEDID, *((uint32_t *)eld + i));
  6488. i = I915_READ(G4X_AUD_CNTL_ST);
  6489. i |= eldv;
  6490. I915_WRITE(G4X_AUD_CNTL_ST, i);
  6491. }
  6492. static void haswell_write_eld(struct drm_connector *connector,
  6493. struct drm_crtc *crtc,
  6494. struct drm_display_mode *mode)
  6495. {
  6496. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  6497. uint8_t *eld = connector->eld;
  6498. uint32_t eldv;
  6499. uint32_t i;
  6500. int len;
  6501. int pipe = to_intel_crtc(crtc)->pipe;
  6502. int tmp;
  6503. int hdmiw_hdmiedid = HSW_AUD_EDID_DATA(pipe);
  6504. int aud_cntl_st = HSW_AUD_DIP_ELD_CTRL(pipe);
  6505. int aud_config = HSW_AUD_CFG(pipe);
  6506. int aud_cntrl_st2 = HSW_AUD_PIN_ELD_CP_VLD;
  6507. /* Audio output enable */
  6508. DRM_DEBUG_DRIVER("HDMI audio: enable codec\n");
  6509. tmp = I915_READ(aud_cntrl_st2);
  6510. tmp |= (AUDIO_OUTPUT_ENABLE_A << (pipe * 4));
  6511. I915_WRITE(aud_cntrl_st2, tmp);
  6512. POSTING_READ(aud_cntrl_st2);
  6513. assert_pipe_disabled(dev_priv, to_intel_crtc(crtc)->pipe);
  6514. /* Set ELD valid state */
  6515. tmp = I915_READ(aud_cntrl_st2);
  6516. DRM_DEBUG_DRIVER("HDMI audio: pin eld vld status=0x%08x\n", tmp);
  6517. tmp |= (AUDIO_ELD_VALID_A << (pipe * 4));
  6518. I915_WRITE(aud_cntrl_st2, tmp);
  6519. tmp = I915_READ(aud_cntrl_st2);
  6520. DRM_DEBUG_DRIVER("HDMI audio: eld vld status=0x%08x\n", tmp);
  6521. /* Enable HDMI mode */
  6522. tmp = I915_READ(aud_config);
  6523. DRM_DEBUG_DRIVER("HDMI audio: audio conf: 0x%08x\n", tmp);
  6524. /* clear N_programing_enable and N_value_index */
  6525. tmp &= ~(AUD_CONFIG_N_VALUE_INDEX | AUD_CONFIG_N_PROG_ENABLE);
  6526. I915_WRITE(aud_config, tmp);
  6527. DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe));
  6528. eldv = AUDIO_ELD_VALID_A << (pipe * 4);
  6529. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  6530. DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
  6531. eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
  6532. I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */
  6533. } else {
  6534. I915_WRITE(aud_config, audio_config_hdmi_pixel_clock(mode));
  6535. }
  6536. if (intel_eld_uptodate(connector,
  6537. aud_cntrl_st2, eldv,
  6538. aud_cntl_st, IBX_ELD_ADDRESS,
  6539. hdmiw_hdmiedid))
  6540. return;
  6541. i = I915_READ(aud_cntrl_st2);
  6542. i &= ~eldv;
  6543. I915_WRITE(aud_cntrl_st2, i);
  6544. if (!eld[0])
  6545. return;
  6546. i = I915_READ(aud_cntl_st);
  6547. i &= ~IBX_ELD_ADDRESS;
  6548. I915_WRITE(aud_cntl_st, i);
  6549. i = (i >> 29) & DIP_PORT_SEL_MASK; /* DIP_Port_Select, 0x1 = PortB */
  6550. DRM_DEBUG_DRIVER("port num:%d\n", i);
  6551. len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */
  6552. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  6553. for (i = 0; i < len; i++)
  6554. I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i));
  6555. i = I915_READ(aud_cntrl_st2);
  6556. i |= eldv;
  6557. I915_WRITE(aud_cntrl_st2, i);
  6558. }
  6559. static void ironlake_write_eld(struct drm_connector *connector,
  6560. struct drm_crtc *crtc,
  6561. struct drm_display_mode *mode)
  6562. {
  6563. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  6564. uint8_t *eld = connector->eld;
  6565. uint32_t eldv;
  6566. uint32_t i;
  6567. int len;
  6568. int hdmiw_hdmiedid;
  6569. int aud_config;
  6570. int aud_cntl_st;
  6571. int aud_cntrl_st2;
  6572. int pipe = to_intel_crtc(crtc)->pipe;
  6573. if (HAS_PCH_IBX(connector->dev)) {
  6574. hdmiw_hdmiedid = IBX_HDMIW_HDMIEDID(pipe);
  6575. aud_config = IBX_AUD_CFG(pipe);
  6576. aud_cntl_st = IBX_AUD_CNTL_ST(pipe);
  6577. aud_cntrl_st2 = IBX_AUD_CNTL_ST2;
  6578. } else if (IS_VALLEYVIEW(connector->dev)) {
  6579. hdmiw_hdmiedid = VLV_HDMIW_HDMIEDID(pipe);
  6580. aud_config = VLV_AUD_CFG(pipe);
  6581. aud_cntl_st = VLV_AUD_CNTL_ST(pipe);
  6582. aud_cntrl_st2 = VLV_AUD_CNTL_ST2;
  6583. } else {
  6584. hdmiw_hdmiedid = CPT_HDMIW_HDMIEDID(pipe);
  6585. aud_config = CPT_AUD_CFG(pipe);
  6586. aud_cntl_st = CPT_AUD_CNTL_ST(pipe);
  6587. aud_cntrl_st2 = CPT_AUD_CNTRL_ST2;
  6588. }
  6589. DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe));
  6590. if (IS_VALLEYVIEW(connector->dev)) {
  6591. struct intel_encoder *intel_encoder;
  6592. struct intel_digital_port *intel_dig_port;
  6593. intel_encoder = intel_attached_encoder(connector);
  6594. intel_dig_port = enc_to_dig_port(&intel_encoder->base);
  6595. i = intel_dig_port->port;
  6596. } else {
  6597. i = I915_READ(aud_cntl_st);
  6598. i = (i >> 29) & DIP_PORT_SEL_MASK;
  6599. /* DIP_Port_Select, 0x1 = PortB */
  6600. }
  6601. if (!i) {
  6602. DRM_DEBUG_DRIVER("Audio directed to unknown port\n");
  6603. /* operate blindly on all ports */
  6604. eldv = IBX_ELD_VALIDB;
  6605. eldv |= IBX_ELD_VALIDB << 4;
  6606. eldv |= IBX_ELD_VALIDB << 8;
  6607. } else {
  6608. DRM_DEBUG_DRIVER("ELD on port %c\n", port_name(i));
  6609. eldv = IBX_ELD_VALIDB << ((i - 1) * 4);
  6610. }
  6611. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  6612. DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
  6613. eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
  6614. I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */
  6615. } else {
  6616. I915_WRITE(aud_config, audio_config_hdmi_pixel_clock(mode));
  6617. }
  6618. if (intel_eld_uptodate(connector,
  6619. aud_cntrl_st2, eldv,
  6620. aud_cntl_st, IBX_ELD_ADDRESS,
  6621. hdmiw_hdmiedid))
  6622. return;
  6623. i = I915_READ(aud_cntrl_st2);
  6624. i &= ~eldv;
  6625. I915_WRITE(aud_cntrl_st2, i);
  6626. if (!eld[0])
  6627. return;
  6628. i = I915_READ(aud_cntl_st);
  6629. i &= ~IBX_ELD_ADDRESS;
  6630. I915_WRITE(aud_cntl_st, i);
  6631. len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */
  6632. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  6633. for (i = 0; i < len; i++)
  6634. I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i));
  6635. i = I915_READ(aud_cntrl_st2);
  6636. i |= eldv;
  6637. I915_WRITE(aud_cntrl_st2, i);
  6638. }
  6639. void intel_write_eld(struct drm_encoder *encoder,
  6640. struct drm_display_mode *mode)
  6641. {
  6642. struct drm_crtc *crtc = encoder->crtc;
  6643. struct drm_connector *connector;
  6644. struct drm_device *dev = encoder->dev;
  6645. struct drm_i915_private *dev_priv = dev->dev_private;
  6646. connector = drm_select_eld(encoder, mode);
  6647. if (!connector)
  6648. return;
  6649. DRM_DEBUG_DRIVER("ELD on [CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  6650. connector->base.id,
  6651. connector->name,
  6652. connector->encoder->base.id,
  6653. connector->encoder->name);
  6654. connector->eld[6] = drm_av_sync_delay(connector, mode) / 2;
  6655. if (dev_priv->display.write_eld)
  6656. dev_priv->display.write_eld(connector, crtc, mode);
  6657. }
  6658. static void i845_update_cursor(struct drm_crtc *crtc, u32 base)
  6659. {
  6660. struct drm_device *dev = crtc->dev;
  6661. struct drm_i915_private *dev_priv = dev->dev_private;
  6662. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6663. uint32_t cntl;
  6664. if (base != intel_crtc->cursor_base) {
  6665. /* On these chipsets we can only modify the base whilst
  6666. * the cursor is disabled.
  6667. */
  6668. if (intel_crtc->cursor_cntl) {
  6669. I915_WRITE(_CURACNTR, 0);
  6670. POSTING_READ(_CURACNTR);
  6671. intel_crtc->cursor_cntl = 0;
  6672. }
  6673. I915_WRITE(_CURABASE, base);
  6674. POSTING_READ(_CURABASE);
  6675. }
  6676. /* XXX width must be 64, stride 256 => 0x00 << 28 */
  6677. cntl = 0;
  6678. if (base)
  6679. cntl = (CURSOR_ENABLE |
  6680. CURSOR_GAMMA_ENABLE |
  6681. CURSOR_FORMAT_ARGB);
  6682. if (intel_crtc->cursor_cntl != cntl) {
  6683. I915_WRITE(_CURACNTR, cntl);
  6684. POSTING_READ(_CURACNTR);
  6685. intel_crtc->cursor_cntl = cntl;
  6686. }
  6687. }
  6688. static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base)
  6689. {
  6690. struct drm_device *dev = crtc->dev;
  6691. struct drm_i915_private *dev_priv = dev->dev_private;
  6692. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6693. int pipe = intel_crtc->pipe;
  6694. uint32_t cntl;
  6695. cntl = 0;
  6696. if (base) {
  6697. cntl = MCURSOR_GAMMA_ENABLE;
  6698. switch (intel_crtc->cursor_width) {
  6699. case 64:
  6700. cntl |= CURSOR_MODE_64_ARGB_AX;
  6701. break;
  6702. case 128:
  6703. cntl |= CURSOR_MODE_128_ARGB_AX;
  6704. break;
  6705. case 256:
  6706. cntl |= CURSOR_MODE_256_ARGB_AX;
  6707. break;
  6708. default:
  6709. WARN_ON(1);
  6710. return;
  6711. }
  6712. cntl |= pipe << 28; /* Connect to correct pipe */
  6713. }
  6714. if (intel_crtc->cursor_cntl != cntl) {
  6715. I915_WRITE(CURCNTR(pipe), cntl);
  6716. POSTING_READ(CURCNTR(pipe));
  6717. intel_crtc->cursor_cntl = cntl;
  6718. }
  6719. /* and commit changes on next vblank */
  6720. I915_WRITE(CURBASE(pipe), base);
  6721. POSTING_READ(CURBASE(pipe));
  6722. }
  6723. static void ivb_update_cursor(struct drm_crtc *crtc, u32 base)
  6724. {
  6725. struct drm_device *dev = crtc->dev;
  6726. struct drm_i915_private *dev_priv = dev->dev_private;
  6727. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6728. int pipe = intel_crtc->pipe;
  6729. uint32_t cntl;
  6730. cntl = 0;
  6731. if (base) {
  6732. cntl = MCURSOR_GAMMA_ENABLE;
  6733. switch (intel_crtc->cursor_width) {
  6734. case 64:
  6735. cntl |= CURSOR_MODE_64_ARGB_AX;
  6736. break;
  6737. case 128:
  6738. cntl |= CURSOR_MODE_128_ARGB_AX;
  6739. break;
  6740. case 256:
  6741. cntl |= CURSOR_MODE_256_ARGB_AX;
  6742. break;
  6743. default:
  6744. WARN_ON(1);
  6745. return;
  6746. }
  6747. }
  6748. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  6749. cntl |= CURSOR_PIPE_CSC_ENABLE;
  6750. if (intel_crtc->cursor_cntl != cntl) {
  6751. I915_WRITE(CURCNTR(pipe), cntl);
  6752. POSTING_READ(CURCNTR(pipe));
  6753. intel_crtc->cursor_cntl = cntl;
  6754. }
  6755. /* and commit changes on next vblank */
  6756. I915_WRITE(CURBASE(pipe), base);
  6757. POSTING_READ(CURBASE(pipe));
  6758. }
  6759. /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
  6760. static void intel_crtc_update_cursor(struct drm_crtc *crtc,
  6761. bool on)
  6762. {
  6763. struct drm_device *dev = crtc->dev;
  6764. struct drm_i915_private *dev_priv = dev->dev_private;
  6765. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6766. int pipe = intel_crtc->pipe;
  6767. int x = crtc->cursor_x;
  6768. int y = crtc->cursor_y;
  6769. u32 base = 0, pos = 0;
  6770. if (on)
  6771. base = intel_crtc->cursor_addr;
  6772. if (x >= intel_crtc->config.pipe_src_w)
  6773. base = 0;
  6774. if (y >= intel_crtc->config.pipe_src_h)
  6775. base = 0;
  6776. if (x < 0) {
  6777. if (x + intel_crtc->cursor_width <= 0)
  6778. base = 0;
  6779. pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
  6780. x = -x;
  6781. }
  6782. pos |= x << CURSOR_X_SHIFT;
  6783. if (y < 0) {
  6784. if (y + intel_crtc->cursor_height <= 0)
  6785. base = 0;
  6786. pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
  6787. y = -y;
  6788. }
  6789. pos |= y << CURSOR_Y_SHIFT;
  6790. if (base == 0 && intel_crtc->cursor_base == 0)
  6791. return;
  6792. I915_WRITE(CURPOS(pipe), pos);
  6793. if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev) || IS_BROADWELL(dev))
  6794. ivb_update_cursor(crtc, base);
  6795. else if (IS_845G(dev) || IS_I865G(dev))
  6796. i845_update_cursor(crtc, base);
  6797. else
  6798. i9xx_update_cursor(crtc, base);
  6799. intel_crtc->cursor_base = base;
  6800. }
  6801. /*
  6802. * intel_crtc_cursor_set_obj - Set cursor to specified GEM object
  6803. *
  6804. * Note that the object's reference will be consumed if the update fails. If
  6805. * the update succeeds, the reference of the old object (if any) will be
  6806. * consumed.
  6807. */
  6808. static int intel_crtc_cursor_set_obj(struct drm_crtc *crtc,
  6809. struct drm_i915_gem_object *obj,
  6810. uint32_t width, uint32_t height)
  6811. {
  6812. struct drm_device *dev = crtc->dev;
  6813. struct drm_i915_private *dev_priv = dev->dev_private;
  6814. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6815. enum pipe pipe = intel_crtc->pipe;
  6816. unsigned old_width;
  6817. uint32_t addr;
  6818. int ret;
  6819. /* if we want to turn off the cursor ignore width and height */
  6820. if (!obj) {
  6821. DRM_DEBUG_KMS("cursor off\n");
  6822. addr = 0;
  6823. obj = NULL;
  6824. mutex_lock(&dev->struct_mutex);
  6825. goto finish;
  6826. }
  6827. /* Check for which cursor types we support */
  6828. if (!((width == 64 && height == 64) ||
  6829. (width == 128 && height == 128 && !IS_GEN2(dev)) ||
  6830. (width == 256 && height == 256 && !IS_GEN2(dev)))) {
  6831. DRM_DEBUG("Cursor dimension not supported\n");
  6832. return -EINVAL;
  6833. }
  6834. if (obj->base.size < width * height * 4) {
  6835. DRM_DEBUG_KMS("buffer is too small\n");
  6836. ret = -ENOMEM;
  6837. goto fail;
  6838. }
  6839. /* we only need to pin inside GTT if cursor is non-phy */
  6840. mutex_lock(&dev->struct_mutex);
  6841. if (!INTEL_INFO(dev)->cursor_needs_physical) {
  6842. unsigned alignment;
  6843. if (obj->tiling_mode) {
  6844. DRM_DEBUG_KMS("cursor cannot be tiled\n");
  6845. ret = -EINVAL;
  6846. goto fail_locked;
  6847. }
  6848. /* Note that the w/a also requires 2 PTE of padding following
  6849. * the bo. We currently fill all unused PTE with the shadow
  6850. * page and so we should always have valid PTE following the
  6851. * cursor preventing the VT-d warning.
  6852. */
  6853. alignment = 0;
  6854. if (need_vtd_wa(dev))
  6855. alignment = 64*1024;
  6856. ret = i915_gem_object_pin_to_display_plane(obj, alignment, NULL);
  6857. if (ret) {
  6858. DRM_DEBUG_KMS("failed to move cursor bo into the GTT\n");
  6859. goto fail_locked;
  6860. }
  6861. ret = i915_gem_object_put_fence(obj);
  6862. if (ret) {
  6863. DRM_DEBUG_KMS("failed to release fence for cursor");
  6864. goto fail_unpin;
  6865. }
  6866. addr = i915_gem_obj_ggtt_offset(obj);
  6867. } else {
  6868. int align = IS_I830(dev) ? 16 * 1024 : 256;
  6869. ret = i915_gem_object_attach_phys(obj, align);
  6870. if (ret) {
  6871. DRM_DEBUG_KMS("failed to attach phys object\n");
  6872. goto fail_locked;
  6873. }
  6874. addr = obj->phys_handle->busaddr;
  6875. }
  6876. if (IS_GEN2(dev))
  6877. I915_WRITE(CURSIZE, (height << 12) | width);
  6878. finish:
  6879. if (intel_crtc->cursor_bo) {
  6880. if (!INTEL_INFO(dev)->cursor_needs_physical)
  6881. i915_gem_object_unpin_from_display_plane(intel_crtc->cursor_bo);
  6882. }
  6883. i915_gem_track_fb(intel_crtc->cursor_bo, obj,
  6884. INTEL_FRONTBUFFER_CURSOR(pipe));
  6885. mutex_unlock(&dev->struct_mutex);
  6886. old_width = intel_crtc->cursor_width;
  6887. intel_crtc->cursor_addr = addr;
  6888. intel_crtc->cursor_bo = obj;
  6889. intel_crtc->cursor_width = width;
  6890. intel_crtc->cursor_height = height;
  6891. if (intel_crtc->active) {
  6892. if (old_width != width)
  6893. intel_update_watermarks(crtc);
  6894. intel_crtc_update_cursor(crtc, intel_crtc->cursor_bo != NULL);
  6895. }
  6896. intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_CURSOR(pipe));
  6897. return 0;
  6898. fail_unpin:
  6899. i915_gem_object_unpin_from_display_plane(obj);
  6900. fail_locked:
  6901. mutex_unlock(&dev->struct_mutex);
  6902. fail:
  6903. drm_gem_object_unreference_unlocked(&obj->base);
  6904. return ret;
  6905. }
  6906. static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
  6907. u16 *blue, uint32_t start, uint32_t size)
  6908. {
  6909. int end = (start + size > 256) ? 256 : start + size, i;
  6910. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6911. for (i = start; i < end; i++) {
  6912. intel_crtc->lut_r[i] = red[i] >> 8;
  6913. intel_crtc->lut_g[i] = green[i] >> 8;
  6914. intel_crtc->lut_b[i] = blue[i] >> 8;
  6915. }
  6916. intel_crtc_load_lut(crtc);
  6917. }
  6918. /* VESA 640x480x72Hz mode to set on the pipe */
  6919. static struct drm_display_mode load_detect_mode = {
  6920. DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
  6921. 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  6922. };
  6923. struct drm_framebuffer *
  6924. __intel_framebuffer_create(struct drm_device *dev,
  6925. struct drm_mode_fb_cmd2 *mode_cmd,
  6926. struct drm_i915_gem_object *obj)
  6927. {
  6928. struct intel_framebuffer *intel_fb;
  6929. int ret;
  6930. intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
  6931. if (!intel_fb) {
  6932. drm_gem_object_unreference_unlocked(&obj->base);
  6933. return ERR_PTR(-ENOMEM);
  6934. }
  6935. ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj);
  6936. if (ret)
  6937. goto err;
  6938. return &intel_fb->base;
  6939. err:
  6940. drm_gem_object_unreference_unlocked(&obj->base);
  6941. kfree(intel_fb);
  6942. return ERR_PTR(ret);
  6943. }
  6944. static struct drm_framebuffer *
  6945. intel_framebuffer_create(struct drm_device *dev,
  6946. struct drm_mode_fb_cmd2 *mode_cmd,
  6947. struct drm_i915_gem_object *obj)
  6948. {
  6949. struct drm_framebuffer *fb;
  6950. int ret;
  6951. ret = i915_mutex_lock_interruptible(dev);
  6952. if (ret)
  6953. return ERR_PTR(ret);
  6954. fb = __intel_framebuffer_create(dev, mode_cmd, obj);
  6955. mutex_unlock(&dev->struct_mutex);
  6956. return fb;
  6957. }
  6958. static u32
  6959. intel_framebuffer_pitch_for_width(int width, int bpp)
  6960. {
  6961. u32 pitch = DIV_ROUND_UP(width * bpp, 8);
  6962. return ALIGN(pitch, 64);
  6963. }
  6964. static u32
  6965. intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp)
  6966. {
  6967. u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp);
  6968. return PAGE_ALIGN(pitch * mode->vdisplay);
  6969. }
  6970. static struct drm_framebuffer *
  6971. intel_framebuffer_create_for_mode(struct drm_device *dev,
  6972. struct drm_display_mode *mode,
  6973. int depth, int bpp)
  6974. {
  6975. struct drm_i915_gem_object *obj;
  6976. struct drm_mode_fb_cmd2 mode_cmd = { 0 };
  6977. obj = i915_gem_alloc_object(dev,
  6978. intel_framebuffer_size_for_mode(mode, bpp));
  6979. if (obj == NULL)
  6980. return ERR_PTR(-ENOMEM);
  6981. mode_cmd.width = mode->hdisplay;
  6982. mode_cmd.height = mode->vdisplay;
  6983. mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width,
  6984. bpp);
  6985. mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth);
  6986. return intel_framebuffer_create(dev, &mode_cmd, obj);
  6987. }
  6988. static struct drm_framebuffer *
  6989. mode_fits_in_fbdev(struct drm_device *dev,
  6990. struct drm_display_mode *mode)
  6991. {
  6992. #ifdef CONFIG_DRM_I915_FBDEV
  6993. struct drm_i915_private *dev_priv = dev->dev_private;
  6994. struct drm_i915_gem_object *obj;
  6995. struct drm_framebuffer *fb;
  6996. if (!dev_priv->fbdev)
  6997. return NULL;
  6998. if (!dev_priv->fbdev->fb)
  6999. return NULL;
  7000. obj = dev_priv->fbdev->fb->obj;
  7001. BUG_ON(!obj);
  7002. fb = &dev_priv->fbdev->fb->base;
  7003. if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay,
  7004. fb->bits_per_pixel))
  7005. return NULL;
  7006. if (obj->base.size < mode->vdisplay * fb->pitches[0])
  7007. return NULL;
  7008. return fb;
  7009. #else
  7010. return NULL;
  7011. #endif
  7012. }
  7013. bool intel_get_load_detect_pipe(struct drm_connector *connector,
  7014. struct drm_display_mode *mode,
  7015. struct intel_load_detect_pipe *old,
  7016. struct drm_modeset_acquire_ctx *ctx)
  7017. {
  7018. struct intel_crtc *intel_crtc;
  7019. struct intel_encoder *intel_encoder =
  7020. intel_attached_encoder(connector);
  7021. struct drm_crtc *possible_crtc;
  7022. struct drm_encoder *encoder = &intel_encoder->base;
  7023. struct drm_crtc *crtc = NULL;
  7024. struct drm_device *dev = encoder->dev;
  7025. struct drm_framebuffer *fb;
  7026. struct drm_mode_config *config = &dev->mode_config;
  7027. int ret, i = -1;
  7028. DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  7029. connector->base.id, connector->name,
  7030. encoder->base.id, encoder->name);
  7031. drm_modeset_acquire_init(ctx, 0);
  7032. retry:
  7033. ret = drm_modeset_lock(&config->connection_mutex, ctx);
  7034. if (ret)
  7035. goto fail_unlock;
  7036. /*
  7037. * Algorithm gets a little messy:
  7038. *
  7039. * - if the connector already has an assigned crtc, use it (but make
  7040. * sure it's on first)
  7041. *
  7042. * - try to find the first unused crtc that can drive this connector,
  7043. * and use that if we find one
  7044. */
  7045. /* See if we already have a CRTC for this connector */
  7046. if (encoder->crtc) {
  7047. crtc = encoder->crtc;
  7048. ret = drm_modeset_lock(&crtc->mutex, ctx);
  7049. if (ret)
  7050. goto fail_unlock;
  7051. old->dpms_mode = connector->dpms;
  7052. old->load_detect_temp = false;
  7053. /* Make sure the crtc and connector are running */
  7054. if (connector->dpms != DRM_MODE_DPMS_ON)
  7055. connector->funcs->dpms(connector, DRM_MODE_DPMS_ON);
  7056. return true;
  7057. }
  7058. /* Find an unused one (if possible) */
  7059. for_each_crtc(dev, possible_crtc) {
  7060. i++;
  7061. if (!(encoder->possible_crtcs & (1 << i)))
  7062. continue;
  7063. if (!possible_crtc->enabled) {
  7064. crtc = possible_crtc;
  7065. break;
  7066. }
  7067. }
  7068. /*
  7069. * If we didn't find an unused CRTC, don't use any.
  7070. */
  7071. if (!crtc) {
  7072. DRM_DEBUG_KMS("no pipe available for load-detect\n");
  7073. goto fail_unlock;
  7074. }
  7075. ret = drm_modeset_lock(&crtc->mutex, ctx);
  7076. if (ret)
  7077. goto fail_unlock;
  7078. intel_encoder->new_crtc = to_intel_crtc(crtc);
  7079. to_intel_connector(connector)->new_encoder = intel_encoder;
  7080. intel_crtc = to_intel_crtc(crtc);
  7081. intel_crtc->new_enabled = true;
  7082. intel_crtc->new_config = &intel_crtc->config;
  7083. old->dpms_mode = connector->dpms;
  7084. old->load_detect_temp = true;
  7085. old->release_fb = NULL;
  7086. if (!mode)
  7087. mode = &load_detect_mode;
  7088. /* We need a framebuffer large enough to accommodate all accesses
  7089. * that the plane may generate whilst we perform load detection.
  7090. * We can not rely on the fbcon either being present (we get called
  7091. * during its initialisation to detect all boot displays, or it may
  7092. * not even exist) or that it is large enough to satisfy the
  7093. * requested mode.
  7094. */
  7095. fb = mode_fits_in_fbdev(dev, mode);
  7096. if (fb == NULL) {
  7097. DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
  7098. fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32);
  7099. old->release_fb = fb;
  7100. } else
  7101. DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
  7102. if (IS_ERR(fb)) {
  7103. DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
  7104. goto fail;
  7105. }
  7106. if (intel_set_mode(crtc, mode, 0, 0, fb)) {
  7107. DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
  7108. if (old->release_fb)
  7109. old->release_fb->funcs->destroy(old->release_fb);
  7110. goto fail;
  7111. }
  7112. /* let the connector get through one full cycle before testing */
  7113. intel_wait_for_vblank(dev, intel_crtc->pipe);
  7114. return true;
  7115. fail:
  7116. intel_crtc->new_enabled = crtc->enabled;
  7117. if (intel_crtc->new_enabled)
  7118. intel_crtc->new_config = &intel_crtc->config;
  7119. else
  7120. intel_crtc->new_config = NULL;
  7121. fail_unlock:
  7122. if (ret == -EDEADLK) {
  7123. drm_modeset_backoff(ctx);
  7124. goto retry;
  7125. }
  7126. drm_modeset_drop_locks(ctx);
  7127. drm_modeset_acquire_fini(ctx);
  7128. return false;
  7129. }
  7130. void intel_release_load_detect_pipe(struct drm_connector *connector,
  7131. struct intel_load_detect_pipe *old,
  7132. struct drm_modeset_acquire_ctx *ctx)
  7133. {
  7134. struct intel_encoder *intel_encoder =
  7135. intel_attached_encoder(connector);
  7136. struct drm_encoder *encoder = &intel_encoder->base;
  7137. struct drm_crtc *crtc = encoder->crtc;
  7138. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7139. DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  7140. connector->base.id, connector->name,
  7141. encoder->base.id, encoder->name);
  7142. if (old->load_detect_temp) {
  7143. to_intel_connector(connector)->new_encoder = NULL;
  7144. intel_encoder->new_crtc = NULL;
  7145. intel_crtc->new_enabled = false;
  7146. intel_crtc->new_config = NULL;
  7147. intel_set_mode(crtc, NULL, 0, 0, NULL);
  7148. if (old->release_fb) {
  7149. drm_framebuffer_unregister_private(old->release_fb);
  7150. drm_framebuffer_unreference(old->release_fb);
  7151. }
  7152. goto unlock;
  7153. return;
  7154. }
  7155. /* Switch crtc and encoder back off if necessary */
  7156. if (old->dpms_mode != DRM_MODE_DPMS_ON)
  7157. connector->funcs->dpms(connector, old->dpms_mode);
  7158. unlock:
  7159. drm_modeset_drop_locks(ctx);
  7160. drm_modeset_acquire_fini(ctx);
  7161. }
  7162. static int i9xx_pll_refclk(struct drm_device *dev,
  7163. const struct intel_crtc_config *pipe_config)
  7164. {
  7165. struct drm_i915_private *dev_priv = dev->dev_private;
  7166. u32 dpll = pipe_config->dpll_hw_state.dpll;
  7167. if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
  7168. return dev_priv->vbt.lvds_ssc_freq;
  7169. else if (HAS_PCH_SPLIT(dev))
  7170. return 120000;
  7171. else if (!IS_GEN2(dev))
  7172. return 96000;
  7173. else
  7174. return 48000;
  7175. }
  7176. /* Returns the clock of the currently programmed mode of the given pipe. */
  7177. static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
  7178. struct intel_crtc_config *pipe_config)
  7179. {
  7180. struct drm_device *dev = crtc->base.dev;
  7181. struct drm_i915_private *dev_priv = dev->dev_private;
  7182. int pipe = pipe_config->cpu_transcoder;
  7183. u32 dpll = pipe_config->dpll_hw_state.dpll;
  7184. u32 fp;
  7185. intel_clock_t clock;
  7186. int refclk = i9xx_pll_refclk(dev, pipe_config);
  7187. if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
  7188. fp = pipe_config->dpll_hw_state.fp0;
  7189. else
  7190. fp = pipe_config->dpll_hw_state.fp1;
  7191. clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
  7192. if (IS_PINEVIEW(dev)) {
  7193. clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
  7194. clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
  7195. } else {
  7196. clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
  7197. clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
  7198. }
  7199. if (!IS_GEN2(dev)) {
  7200. if (IS_PINEVIEW(dev))
  7201. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
  7202. DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
  7203. else
  7204. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
  7205. DPLL_FPA01_P1_POST_DIV_SHIFT);
  7206. switch (dpll & DPLL_MODE_MASK) {
  7207. case DPLLB_MODE_DAC_SERIAL:
  7208. clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
  7209. 5 : 10;
  7210. break;
  7211. case DPLLB_MODE_LVDS:
  7212. clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
  7213. 7 : 14;
  7214. break;
  7215. default:
  7216. DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
  7217. "mode\n", (int)(dpll & DPLL_MODE_MASK));
  7218. return;
  7219. }
  7220. if (IS_PINEVIEW(dev))
  7221. pineview_clock(refclk, &clock);
  7222. else
  7223. i9xx_clock(refclk, &clock);
  7224. } else {
  7225. u32 lvds = IS_I830(dev) ? 0 : I915_READ(LVDS);
  7226. bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN);
  7227. if (is_lvds) {
  7228. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
  7229. DPLL_FPA01_P1_POST_DIV_SHIFT);
  7230. if (lvds & LVDS_CLKB_POWER_UP)
  7231. clock.p2 = 7;
  7232. else
  7233. clock.p2 = 14;
  7234. } else {
  7235. if (dpll & PLL_P1_DIVIDE_BY_TWO)
  7236. clock.p1 = 2;
  7237. else {
  7238. clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
  7239. DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
  7240. }
  7241. if (dpll & PLL_P2_DIVIDE_BY_4)
  7242. clock.p2 = 4;
  7243. else
  7244. clock.p2 = 2;
  7245. }
  7246. i9xx_clock(refclk, &clock);
  7247. }
  7248. /*
  7249. * This value includes pixel_multiplier. We will use
  7250. * port_clock to compute adjusted_mode.crtc_clock in the
  7251. * encoder's get_config() function.
  7252. */
  7253. pipe_config->port_clock = clock.dot;
  7254. }
  7255. int intel_dotclock_calculate(int link_freq,
  7256. const struct intel_link_m_n *m_n)
  7257. {
  7258. /*
  7259. * The calculation for the data clock is:
  7260. * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
  7261. * But we want to avoid losing precison if possible, so:
  7262. * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
  7263. *
  7264. * and the link clock is simpler:
  7265. * link_clock = (m * link_clock) / n
  7266. */
  7267. if (!m_n->link_n)
  7268. return 0;
  7269. return div_u64((u64)m_n->link_m * link_freq, m_n->link_n);
  7270. }
  7271. static void ironlake_pch_clock_get(struct intel_crtc *crtc,
  7272. struct intel_crtc_config *pipe_config)
  7273. {
  7274. struct drm_device *dev = crtc->base.dev;
  7275. /* read out port_clock from the DPLL */
  7276. i9xx_crtc_clock_get(crtc, pipe_config);
  7277. /*
  7278. * This value does not include pixel_multiplier.
  7279. * We will check that port_clock and adjusted_mode.crtc_clock
  7280. * agree once we know their relationship in the encoder's
  7281. * get_config() function.
  7282. */
  7283. pipe_config->adjusted_mode.crtc_clock =
  7284. intel_dotclock_calculate(intel_fdi_link_freq(dev) * 10000,
  7285. &pipe_config->fdi_m_n);
  7286. }
  7287. /** Returns the currently programmed mode of the given pipe. */
  7288. struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
  7289. struct drm_crtc *crtc)
  7290. {
  7291. struct drm_i915_private *dev_priv = dev->dev_private;
  7292. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7293. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  7294. struct drm_display_mode *mode;
  7295. struct intel_crtc_config pipe_config;
  7296. int htot = I915_READ(HTOTAL(cpu_transcoder));
  7297. int hsync = I915_READ(HSYNC(cpu_transcoder));
  7298. int vtot = I915_READ(VTOTAL(cpu_transcoder));
  7299. int vsync = I915_READ(VSYNC(cpu_transcoder));
  7300. enum pipe pipe = intel_crtc->pipe;
  7301. mode = kzalloc(sizeof(*mode), GFP_KERNEL);
  7302. if (!mode)
  7303. return NULL;
  7304. /*
  7305. * Construct a pipe_config sufficient for getting the clock info
  7306. * back out of crtc_clock_get.
  7307. *
  7308. * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need
  7309. * to use a real value here instead.
  7310. */
  7311. pipe_config.cpu_transcoder = (enum transcoder) pipe;
  7312. pipe_config.pixel_multiplier = 1;
  7313. pipe_config.dpll_hw_state.dpll = I915_READ(DPLL(pipe));
  7314. pipe_config.dpll_hw_state.fp0 = I915_READ(FP0(pipe));
  7315. pipe_config.dpll_hw_state.fp1 = I915_READ(FP1(pipe));
  7316. i9xx_crtc_clock_get(intel_crtc, &pipe_config);
  7317. mode->clock = pipe_config.port_clock / pipe_config.pixel_multiplier;
  7318. mode->hdisplay = (htot & 0xffff) + 1;
  7319. mode->htotal = ((htot & 0xffff0000) >> 16) + 1;
  7320. mode->hsync_start = (hsync & 0xffff) + 1;
  7321. mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1;
  7322. mode->vdisplay = (vtot & 0xffff) + 1;
  7323. mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1;
  7324. mode->vsync_start = (vsync & 0xffff) + 1;
  7325. mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1;
  7326. drm_mode_set_name(mode);
  7327. return mode;
  7328. }
  7329. static void intel_increase_pllclock(struct drm_device *dev,
  7330. enum pipe pipe)
  7331. {
  7332. struct drm_i915_private *dev_priv = dev->dev_private;
  7333. int dpll_reg = DPLL(pipe);
  7334. int dpll;
  7335. if (HAS_PCH_SPLIT(dev))
  7336. return;
  7337. if (!dev_priv->lvds_downclock_avail)
  7338. return;
  7339. dpll = I915_READ(dpll_reg);
  7340. if (!HAS_PIPE_CXSR(dev) && (dpll & DISPLAY_RATE_SELECT_FPA1)) {
  7341. DRM_DEBUG_DRIVER("upclocking LVDS\n");
  7342. assert_panel_unlocked(dev_priv, pipe);
  7343. dpll &= ~DISPLAY_RATE_SELECT_FPA1;
  7344. I915_WRITE(dpll_reg, dpll);
  7345. intel_wait_for_vblank(dev, pipe);
  7346. dpll = I915_READ(dpll_reg);
  7347. if (dpll & DISPLAY_RATE_SELECT_FPA1)
  7348. DRM_DEBUG_DRIVER("failed to upclock LVDS!\n");
  7349. }
  7350. }
  7351. static void intel_decrease_pllclock(struct drm_crtc *crtc)
  7352. {
  7353. struct drm_device *dev = crtc->dev;
  7354. struct drm_i915_private *dev_priv = dev->dev_private;
  7355. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7356. if (HAS_PCH_SPLIT(dev))
  7357. return;
  7358. if (!dev_priv->lvds_downclock_avail)
  7359. return;
  7360. /*
  7361. * Since this is called by a timer, we should never get here in
  7362. * the manual case.
  7363. */
  7364. if (!HAS_PIPE_CXSR(dev) && intel_crtc->lowfreq_avail) {
  7365. int pipe = intel_crtc->pipe;
  7366. int dpll_reg = DPLL(pipe);
  7367. int dpll;
  7368. DRM_DEBUG_DRIVER("downclocking LVDS\n");
  7369. assert_panel_unlocked(dev_priv, pipe);
  7370. dpll = I915_READ(dpll_reg);
  7371. dpll |= DISPLAY_RATE_SELECT_FPA1;
  7372. I915_WRITE(dpll_reg, dpll);
  7373. intel_wait_for_vblank(dev, pipe);
  7374. dpll = I915_READ(dpll_reg);
  7375. if (!(dpll & DISPLAY_RATE_SELECT_FPA1))
  7376. DRM_DEBUG_DRIVER("failed to downclock LVDS!\n");
  7377. }
  7378. }
  7379. void intel_mark_busy(struct drm_device *dev)
  7380. {
  7381. struct drm_i915_private *dev_priv = dev->dev_private;
  7382. if (dev_priv->mm.busy)
  7383. return;
  7384. intel_runtime_pm_get(dev_priv);
  7385. i915_update_gfx_val(dev_priv);
  7386. dev_priv->mm.busy = true;
  7387. }
  7388. void intel_mark_idle(struct drm_device *dev)
  7389. {
  7390. struct drm_i915_private *dev_priv = dev->dev_private;
  7391. struct drm_crtc *crtc;
  7392. if (!dev_priv->mm.busy)
  7393. return;
  7394. dev_priv->mm.busy = false;
  7395. if (!i915.powersave)
  7396. goto out;
  7397. for_each_crtc(dev, crtc) {
  7398. if (!crtc->primary->fb)
  7399. continue;
  7400. intel_decrease_pllclock(crtc);
  7401. }
  7402. if (INTEL_INFO(dev)->gen >= 6)
  7403. gen6_rps_idle(dev->dev_private);
  7404. out:
  7405. intel_runtime_pm_put(dev_priv);
  7406. }
  7407. /**
  7408. * intel_mark_fb_busy - mark given planes as busy
  7409. * @dev: DRM device
  7410. * @frontbuffer_bits: bits for the affected planes
  7411. * @ring: optional ring for asynchronous commands
  7412. *
  7413. * This function gets called every time the screen contents change. It can be
  7414. * used to keep e.g. the update rate at the nominal refresh rate with DRRS.
  7415. */
  7416. static void intel_mark_fb_busy(struct drm_device *dev,
  7417. unsigned frontbuffer_bits,
  7418. struct intel_engine_cs *ring)
  7419. {
  7420. enum pipe pipe;
  7421. if (!i915.powersave)
  7422. return;
  7423. for_each_pipe(pipe) {
  7424. if (!(frontbuffer_bits & INTEL_FRONTBUFFER_ALL_MASK(pipe)))
  7425. continue;
  7426. intel_increase_pllclock(dev, pipe);
  7427. if (ring && intel_fbc_enabled(dev))
  7428. ring->fbc_dirty = true;
  7429. }
  7430. }
  7431. /**
  7432. * intel_fb_obj_invalidate - invalidate frontbuffer object
  7433. * @obj: GEM object to invalidate
  7434. * @ring: set for asynchronous rendering
  7435. *
  7436. * This function gets called every time rendering on the given object starts and
  7437. * frontbuffer caching (fbc, low refresh rate for DRRS, panel self refresh) must
  7438. * be invalidated. If @ring is non-NULL any subsequent invalidation will be delayed
  7439. * until the rendering completes or a flip on this frontbuffer plane is
  7440. * scheduled.
  7441. */
  7442. void intel_fb_obj_invalidate(struct drm_i915_gem_object *obj,
  7443. struct intel_engine_cs *ring)
  7444. {
  7445. struct drm_device *dev = obj->base.dev;
  7446. struct drm_i915_private *dev_priv = dev->dev_private;
  7447. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  7448. if (!obj->frontbuffer_bits)
  7449. return;
  7450. if (ring) {
  7451. mutex_lock(&dev_priv->fb_tracking.lock);
  7452. dev_priv->fb_tracking.busy_bits
  7453. |= obj->frontbuffer_bits;
  7454. dev_priv->fb_tracking.flip_bits
  7455. &= ~obj->frontbuffer_bits;
  7456. mutex_unlock(&dev_priv->fb_tracking.lock);
  7457. }
  7458. intel_mark_fb_busy(dev, obj->frontbuffer_bits, ring);
  7459. intel_edp_psr_exit(dev);
  7460. }
  7461. /**
  7462. * intel_frontbuffer_flush - flush frontbuffer
  7463. * @dev: DRM device
  7464. * @frontbuffer_bits: frontbuffer plane tracking bits
  7465. *
  7466. * This function gets called every time rendering on the given planes has
  7467. * completed and frontbuffer caching can be started again. Flushes will get
  7468. * delayed if they're blocked by some oustanding asynchronous rendering.
  7469. *
  7470. * Can be called without any locks held.
  7471. */
  7472. void intel_frontbuffer_flush(struct drm_device *dev,
  7473. unsigned frontbuffer_bits)
  7474. {
  7475. struct drm_i915_private *dev_priv = dev->dev_private;
  7476. /* Delay flushing when rings are still busy.*/
  7477. mutex_lock(&dev_priv->fb_tracking.lock);
  7478. frontbuffer_bits &= ~dev_priv->fb_tracking.busy_bits;
  7479. mutex_unlock(&dev_priv->fb_tracking.lock);
  7480. intel_mark_fb_busy(dev, frontbuffer_bits, NULL);
  7481. intel_edp_psr_exit(dev);
  7482. }
  7483. /**
  7484. * intel_fb_obj_flush - flush frontbuffer object
  7485. * @obj: GEM object to flush
  7486. * @retire: set when retiring asynchronous rendering
  7487. *
  7488. * This function gets called every time rendering on the given object has
  7489. * completed and frontbuffer caching can be started again. If @retire is true
  7490. * then any delayed flushes will be unblocked.
  7491. */
  7492. void intel_fb_obj_flush(struct drm_i915_gem_object *obj,
  7493. bool retire)
  7494. {
  7495. struct drm_device *dev = obj->base.dev;
  7496. struct drm_i915_private *dev_priv = dev->dev_private;
  7497. unsigned frontbuffer_bits;
  7498. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  7499. if (!obj->frontbuffer_bits)
  7500. return;
  7501. frontbuffer_bits = obj->frontbuffer_bits;
  7502. if (retire) {
  7503. mutex_lock(&dev_priv->fb_tracking.lock);
  7504. /* Filter out new bits since rendering started. */
  7505. frontbuffer_bits &= dev_priv->fb_tracking.busy_bits;
  7506. dev_priv->fb_tracking.busy_bits &= ~frontbuffer_bits;
  7507. mutex_unlock(&dev_priv->fb_tracking.lock);
  7508. }
  7509. intel_frontbuffer_flush(dev, frontbuffer_bits);
  7510. }
  7511. /**
  7512. * intel_frontbuffer_flip_prepare - prepare asnychronous frontbuffer flip
  7513. * @dev: DRM device
  7514. * @frontbuffer_bits: frontbuffer plane tracking bits
  7515. *
  7516. * This function gets called after scheduling a flip on @obj. The actual
  7517. * frontbuffer flushing will be delayed until completion is signalled with
  7518. * intel_frontbuffer_flip_complete. If an invalidate happens in between this
  7519. * flush will be cancelled.
  7520. *
  7521. * Can be called without any locks held.
  7522. */
  7523. void intel_frontbuffer_flip_prepare(struct drm_device *dev,
  7524. unsigned frontbuffer_bits)
  7525. {
  7526. struct drm_i915_private *dev_priv = dev->dev_private;
  7527. mutex_lock(&dev_priv->fb_tracking.lock);
  7528. dev_priv->fb_tracking.flip_bits
  7529. |= frontbuffer_bits;
  7530. mutex_unlock(&dev_priv->fb_tracking.lock);
  7531. }
  7532. /**
  7533. * intel_frontbuffer_flip_complete - complete asynchronous frontbuffer flush
  7534. * @dev: DRM device
  7535. * @frontbuffer_bits: frontbuffer plane tracking bits
  7536. *
  7537. * This function gets called after the flip has been latched and will complete
  7538. * on the next vblank. It will execute the fush if it hasn't been cancalled yet.
  7539. *
  7540. * Can be called without any locks held.
  7541. */
  7542. void intel_frontbuffer_flip_complete(struct drm_device *dev,
  7543. unsigned frontbuffer_bits)
  7544. {
  7545. struct drm_i915_private *dev_priv = dev->dev_private;
  7546. mutex_lock(&dev_priv->fb_tracking.lock);
  7547. /* Mask any cancelled flips. */
  7548. frontbuffer_bits &= dev_priv->fb_tracking.flip_bits;
  7549. dev_priv->fb_tracking.flip_bits &= ~frontbuffer_bits;
  7550. mutex_unlock(&dev_priv->fb_tracking.lock);
  7551. intel_frontbuffer_flush(dev, frontbuffer_bits);
  7552. }
  7553. static void intel_crtc_destroy(struct drm_crtc *crtc)
  7554. {
  7555. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7556. struct drm_device *dev = crtc->dev;
  7557. struct intel_unpin_work *work;
  7558. unsigned long flags;
  7559. spin_lock_irqsave(&dev->event_lock, flags);
  7560. work = intel_crtc->unpin_work;
  7561. intel_crtc->unpin_work = NULL;
  7562. spin_unlock_irqrestore(&dev->event_lock, flags);
  7563. if (work) {
  7564. cancel_work_sync(&work->work);
  7565. kfree(work);
  7566. }
  7567. drm_crtc_cleanup(crtc);
  7568. kfree(intel_crtc);
  7569. }
  7570. static void intel_unpin_work_fn(struct work_struct *__work)
  7571. {
  7572. struct intel_unpin_work *work =
  7573. container_of(__work, struct intel_unpin_work, work);
  7574. struct drm_device *dev = work->crtc->dev;
  7575. enum pipe pipe = to_intel_crtc(work->crtc)->pipe;
  7576. mutex_lock(&dev->struct_mutex);
  7577. intel_unpin_fb_obj(work->old_fb_obj);
  7578. drm_gem_object_unreference(&work->pending_flip_obj->base);
  7579. drm_gem_object_unreference(&work->old_fb_obj->base);
  7580. intel_update_fbc(dev);
  7581. mutex_unlock(&dev->struct_mutex);
  7582. intel_frontbuffer_flip_complete(dev, INTEL_FRONTBUFFER_PRIMARY(pipe));
  7583. BUG_ON(atomic_read(&to_intel_crtc(work->crtc)->unpin_work_count) == 0);
  7584. atomic_dec(&to_intel_crtc(work->crtc)->unpin_work_count);
  7585. kfree(work);
  7586. }
  7587. static void do_intel_finish_page_flip(struct drm_device *dev,
  7588. struct drm_crtc *crtc)
  7589. {
  7590. struct drm_i915_private *dev_priv = dev->dev_private;
  7591. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7592. struct intel_unpin_work *work;
  7593. unsigned long flags;
  7594. /* Ignore early vblank irqs */
  7595. if (intel_crtc == NULL)
  7596. return;
  7597. spin_lock_irqsave(&dev->event_lock, flags);
  7598. work = intel_crtc->unpin_work;
  7599. /* Ensure we don't miss a work->pending update ... */
  7600. smp_rmb();
  7601. if (work == NULL || atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
  7602. spin_unlock_irqrestore(&dev->event_lock, flags);
  7603. return;
  7604. }
  7605. /* and that the unpin work is consistent wrt ->pending. */
  7606. smp_rmb();
  7607. intel_crtc->unpin_work = NULL;
  7608. if (work->event)
  7609. drm_send_vblank_event(dev, intel_crtc->pipe, work->event);
  7610. drm_crtc_vblank_put(crtc);
  7611. spin_unlock_irqrestore(&dev->event_lock, flags);
  7612. wake_up_all(&dev_priv->pending_flip_queue);
  7613. queue_work(dev_priv->wq, &work->work);
  7614. trace_i915_flip_complete(intel_crtc->plane, work->pending_flip_obj);
  7615. }
  7616. void intel_finish_page_flip(struct drm_device *dev, int pipe)
  7617. {
  7618. struct drm_i915_private *dev_priv = dev->dev_private;
  7619. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  7620. do_intel_finish_page_flip(dev, crtc);
  7621. }
  7622. void intel_finish_page_flip_plane(struct drm_device *dev, int plane)
  7623. {
  7624. struct drm_i915_private *dev_priv = dev->dev_private;
  7625. struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane];
  7626. do_intel_finish_page_flip(dev, crtc);
  7627. }
  7628. /* Is 'a' after or equal to 'b'? */
  7629. static bool g4x_flip_count_after_eq(u32 a, u32 b)
  7630. {
  7631. return !((a - b) & 0x80000000);
  7632. }
  7633. static bool page_flip_finished(struct intel_crtc *crtc)
  7634. {
  7635. struct drm_device *dev = crtc->base.dev;
  7636. struct drm_i915_private *dev_priv = dev->dev_private;
  7637. /*
  7638. * The relevant registers doen't exist on pre-ctg.
  7639. * As the flip done interrupt doesn't trigger for mmio
  7640. * flips on gmch platforms, a flip count check isn't
  7641. * really needed there. But since ctg has the registers,
  7642. * include it in the check anyway.
  7643. */
  7644. if (INTEL_INFO(dev)->gen < 5 && !IS_G4X(dev))
  7645. return true;
  7646. /*
  7647. * A DSPSURFLIVE check isn't enough in case the mmio and CS flips
  7648. * used the same base address. In that case the mmio flip might
  7649. * have completed, but the CS hasn't even executed the flip yet.
  7650. *
  7651. * A flip count check isn't enough as the CS might have updated
  7652. * the base address just after start of vblank, but before we
  7653. * managed to process the interrupt. This means we'd complete the
  7654. * CS flip too soon.
  7655. *
  7656. * Combining both checks should get us a good enough result. It may
  7657. * still happen that the CS flip has been executed, but has not
  7658. * yet actually completed. But in case the base address is the same
  7659. * anyway, we don't really care.
  7660. */
  7661. return (I915_READ(DSPSURFLIVE(crtc->plane)) & ~0xfff) ==
  7662. crtc->unpin_work->gtt_offset &&
  7663. g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_GM45(crtc->pipe)),
  7664. crtc->unpin_work->flip_count);
  7665. }
  7666. void intel_prepare_page_flip(struct drm_device *dev, int plane)
  7667. {
  7668. struct drm_i915_private *dev_priv = dev->dev_private;
  7669. struct intel_crtc *intel_crtc =
  7670. to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]);
  7671. unsigned long flags;
  7672. /* NB: An MMIO update of the plane base pointer will also
  7673. * generate a page-flip completion irq, i.e. every modeset
  7674. * is also accompanied by a spurious intel_prepare_page_flip().
  7675. */
  7676. spin_lock_irqsave(&dev->event_lock, flags);
  7677. if (intel_crtc->unpin_work && page_flip_finished(intel_crtc))
  7678. atomic_inc_not_zero(&intel_crtc->unpin_work->pending);
  7679. spin_unlock_irqrestore(&dev->event_lock, flags);
  7680. }
  7681. static inline void intel_mark_page_flip_active(struct intel_crtc *intel_crtc)
  7682. {
  7683. /* Ensure that the work item is consistent when activating it ... */
  7684. smp_wmb();
  7685. atomic_set(&intel_crtc->unpin_work->pending, INTEL_FLIP_PENDING);
  7686. /* and that it is marked active as soon as the irq could fire. */
  7687. smp_wmb();
  7688. }
  7689. static int intel_gen2_queue_flip(struct drm_device *dev,
  7690. struct drm_crtc *crtc,
  7691. struct drm_framebuffer *fb,
  7692. struct drm_i915_gem_object *obj,
  7693. struct intel_engine_cs *ring,
  7694. uint32_t flags)
  7695. {
  7696. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7697. u32 flip_mask;
  7698. int ret;
  7699. ret = intel_ring_begin(ring, 6);
  7700. if (ret)
  7701. return ret;
  7702. /* Can't queue multiple flips, so wait for the previous
  7703. * one to finish before executing the next.
  7704. */
  7705. if (intel_crtc->plane)
  7706. flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
  7707. else
  7708. flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
  7709. intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
  7710. intel_ring_emit(ring, MI_NOOP);
  7711. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  7712. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  7713. intel_ring_emit(ring, fb->pitches[0]);
  7714. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
  7715. intel_ring_emit(ring, 0); /* aux display base address, unused */
  7716. intel_mark_page_flip_active(intel_crtc);
  7717. __intel_ring_advance(ring);
  7718. return 0;
  7719. }
  7720. static int intel_gen3_queue_flip(struct drm_device *dev,
  7721. struct drm_crtc *crtc,
  7722. struct drm_framebuffer *fb,
  7723. struct drm_i915_gem_object *obj,
  7724. struct intel_engine_cs *ring,
  7725. uint32_t flags)
  7726. {
  7727. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7728. u32 flip_mask;
  7729. int ret;
  7730. ret = intel_ring_begin(ring, 6);
  7731. if (ret)
  7732. return ret;
  7733. if (intel_crtc->plane)
  7734. flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
  7735. else
  7736. flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
  7737. intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
  7738. intel_ring_emit(ring, MI_NOOP);
  7739. intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 |
  7740. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  7741. intel_ring_emit(ring, fb->pitches[0]);
  7742. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
  7743. intel_ring_emit(ring, MI_NOOP);
  7744. intel_mark_page_flip_active(intel_crtc);
  7745. __intel_ring_advance(ring);
  7746. return 0;
  7747. }
  7748. static int intel_gen4_queue_flip(struct drm_device *dev,
  7749. struct drm_crtc *crtc,
  7750. struct drm_framebuffer *fb,
  7751. struct drm_i915_gem_object *obj,
  7752. struct intel_engine_cs *ring,
  7753. uint32_t flags)
  7754. {
  7755. struct drm_i915_private *dev_priv = dev->dev_private;
  7756. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7757. uint32_t pf, pipesrc;
  7758. int ret;
  7759. ret = intel_ring_begin(ring, 4);
  7760. if (ret)
  7761. return ret;
  7762. /* i965+ uses the linear or tiled offsets from the
  7763. * Display Registers (which do not change across a page-flip)
  7764. * so we need only reprogram the base address.
  7765. */
  7766. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  7767. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  7768. intel_ring_emit(ring, fb->pitches[0]);
  7769. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset |
  7770. obj->tiling_mode);
  7771. /* XXX Enabling the panel-fitter across page-flip is so far
  7772. * untested on non-native modes, so ignore it for now.
  7773. * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
  7774. */
  7775. pf = 0;
  7776. pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
  7777. intel_ring_emit(ring, pf | pipesrc);
  7778. intel_mark_page_flip_active(intel_crtc);
  7779. __intel_ring_advance(ring);
  7780. return 0;
  7781. }
  7782. static int intel_gen6_queue_flip(struct drm_device *dev,
  7783. struct drm_crtc *crtc,
  7784. struct drm_framebuffer *fb,
  7785. struct drm_i915_gem_object *obj,
  7786. struct intel_engine_cs *ring,
  7787. uint32_t flags)
  7788. {
  7789. struct drm_i915_private *dev_priv = dev->dev_private;
  7790. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7791. uint32_t pf, pipesrc;
  7792. int ret;
  7793. ret = intel_ring_begin(ring, 4);
  7794. if (ret)
  7795. return ret;
  7796. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  7797. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  7798. intel_ring_emit(ring, fb->pitches[0] | obj->tiling_mode);
  7799. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
  7800. /* Contrary to the suggestions in the documentation,
  7801. * "Enable Panel Fitter" does not seem to be required when page
  7802. * flipping with a non-native mode, and worse causes a normal
  7803. * modeset to fail.
  7804. * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
  7805. */
  7806. pf = 0;
  7807. pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
  7808. intel_ring_emit(ring, pf | pipesrc);
  7809. intel_mark_page_flip_active(intel_crtc);
  7810. __intel_ring_advance(ring);
  7811. return 0;
  7812. }
  7813. static int intel_gen7_queue_flip(struct drm_device *dev,
  7814. struct drm_crtc *crtc,
  7815. struct drm_framebuffer *fb,
  7816. struct drm_i915_gem_object *obj,
  7817. struct intel_engine_cs *ring,
  7818. uint32_t flags)
  7819. {
  7820. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7821. uint32_t plane_bit = 0;
  7822. int len, ret;
  7823. switch (intel_crtc->plane) {
  7824. case PLANE_A:
  7825. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A;
  7826. break;
  7827. case PLANE_B:
  7828. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B;
  7829. break;
  7830. case PLANE_C:
  7831. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C;
  7832. break;
  7833. default:
  7834. WARN_ONCE(1, "unknown plane in flip command\n");
  7835. return -ENODEV;
  7836. }
  7837. len = 4;
  7838. if (ring->id == RCS) {
  7839. len += 6;
  7840. /*
  7841. * On Gen 8, SRM is now taking an extra dword to accommodate
  7842. * 48bits addresses, and we need a NOOP for the batch size to
  7843. * stay even.
  7844. */
  7845. if (IS_GEN8(dev))
  7846. len += 2;
  7847. }
  7848. /*
  7849. * BSpec MI_DISPLAY_FLIP for IVB:
  7850. * "The full packet must be contained within the same cache line."
  7851. *
  7852. * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same
  7853. * cacheline, if we ever start emitting more commands before
  7854. * the MI_DISPLAY_FLIP we may need to first emit everything else,
  7855. * then do the cacheline alignment, and finally emit the
  7856. * MI_DISPLAY_FLIP.
  7857. */
  7858. ret = intel_ring_cacheline_align(ring);
  7859. if (ret)
  7860. return ret;
  7861. ret = intel_ring_begin(ring, len);
  7862. if (ret)
  7863. return ret;
  7864. /* Unmask the flip-done completion message. Note that the bspec says that
  7865. * we should do this for both the BCS and RCS, and that we must not unmask
  7866. * more than one flip event at any time (or ensure that one flip message
  7867. * can be sent by waiting for flip-done prior to queueing new flips).
  7868. * Experimentation says that BCS works despite DERRMR masking all
  7869. * flip-done completion events and that unmasking all planes at once
  7870. * for the RCS also doesn't appear to drop events. Setting the DERRMR
  7871. * to zero does lead to lockups within MI_DISPLAY_FLIP.
  7872. */
  7873. if (ring->id == RCS) {
  7874. intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1));
  7875. intel_ring_emit(ring, DERRMR);
  7876. intel_ring_emit(ring, ~(DERRMR_PIPEA_PRI_FLIP_DONE |
  7877. DERRMR_PIPEB_PRI_FLIP_DONE |
  7878. DERRMR_PIPEC_PRI_FLIP_DONE));
  7879. if (IS_GEN8(dev))
  7880. intel_ring_emit(ring, MI_STORE_REGISTER_MEM_GEN8(1) |
  7881. MI_SRM_LRM_GLOBAL_GTT);
  7882. else
  7883. intel_ring_emit(ring, MI_STORE_REGISTER_MEM(1) |
  7884. MI_SRM_LRM_GLOBAL_GTT);
  7885. intel_ring_emit(ring, DERRMR);
  7886. intel_ring_emit(ring, ring->scratch.gtt_offset + 256);
  7887. if (IS_GEN8(dev)) {
  7888. intel_ring_emit(ring, 0);
  7889. intel_ring_emit(ring, MI_NOOP);
  7890. }
  7891. }
  7892. intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | plane_bit);
  7893. intel_ring_emit(ring, (fb->pitches[0] | obj->tiling_mode));
  7894. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
  7895. intel_ring_emit(ring, (MI_NOOP));
  7896. intel_mark_page_flip_active(intel_crtc);
  7897. __intel_ring_advance(ring);
  7898. return 0;
  7899. }
  7900. static bool use_mmio_flip(struct intel_engine_cs *ring,
  7901. struct drm_i915_gem_object *obj)
  7902. {
  7903. /*
  7904. * This is not being used for older platforms, because
  7905. * non-availability of flip done interrupt forces us to use
  7906. * CS flips. Older platforms derive flip done using some clever
  7907. * tricks involving the flip_pending status bits and vblank irqs.
  7908. * So using MMIO flips there would disrupt this mechanism.
  7909. */
  7910. if (ring == NULL)
  7911. return true;
  7912. if (INTEL_INFO(ring->dev)->gen < 5)
  7913. return false;
  7914. if (i915.use_mmio_flip < 0)
  7915. return false;
  7916. else if (i915.use_mmio_flip > 0)
  7917. return true;
  7918. else
  7919. return ring != obj->ring;
  7920. }
  7921. static void intel_do_mmio_flip(struct intel_crtc *intel_crtc)
  7922. {
  7923. struct drm_device *dev = intel_crtc->base.dev;
  7924. struct drm_i915_private *dev_priv = dev->dev_private;
  7925. struct intel_framebuffer *intel_fb =
  7926. to_intel_framebuffer(intel_crtc->base.primary->fb);
  7927. struct drm_i915_gem_object *obj = intel_fb->obj;
  7928. u32 dspcntr;
  7929. u32 reg;
  7930. intel_mark_page_flip_active(intel_crtc);
  7931. reg = DSPCNTR(intel_crtc->plane);
  7932. dspcntr = I915_READ(reg);
  7933. if (INTEL_INFO(dev)->gen >= 4) {
  7934. if (obj->tiling_mode != I915_TILING_NONE)
  7935. dspcntr |= DISPPLANE_TILED;
  7936. else
  7937. dspcntr &= ~DISPPLANE_TILED;
  7938. }
  7939. I915_WRITE(reg, dspcntr);
  7940. I915_WRITE(DSPSURF(intel_crtc->plane),
  7941. intel_crtc->unpin_work->gtt_offset);
  7942. POSTING_READ(DSPSURF(intel_crtc->plane));
  7943. }
  7944. static int intel_postpone_flip(struct drm_i915_gem_object *obj)
  7945. {
  7946. struct intel_engine_cs *ring;
  7947. int ret;
  7948. lockdep_assert_held(&obj->base.dev->struct_mutex);
  7949. if (!obj->last_write_seqno)
  7950. return 0;
  7951. ring = obj->ring;
  7952. if (i915_seqno_passed(ring->get_seqno(ring, true),
  7953. obj->last_write_seqno))
  7954. return 0;
  7955. ret = i915_gem_check_olr(ring, obj->last_write_seqno);
  7956. if (ret)
  7957. return ret;
  7958. if (WARN_ON(!ring->irq_get(ring)))
  7959. return 0;
  7960. return 1;
  7961. }
  7962. void intel_notify_mmio_flip(struct intel_engine_cs *ring)
  7963. {
  7964. struct drm_i915_private *dev_priv = to_i915(ring->dev);
  7965. struct intel_crtc *intel_crtc;
  7966. unsigned long irq_flags;
  7967. u32 seqno;
  7968. seqno = ring->get_seqno(ring, false);
  7969. spin_lock_irqsave(&dev_priv->mmio_flip_lock, irq_flags);
  7970. for_each_intel_crtc(ring->dev, intel_crtc) {
  7971. struct intel_mmio_flip *mmio_flip;
  7972. mmio_flip = &intel_crtc->mmio_flip;
  7973. if (mmio_flip->seqno == 0)
  7974. continue;
  7975. if (ring->id != mmio_flip->ring_id)
  7976. continue;
  7977. if (i915_seqno_passed(seqno, mmio_flip->seqno)) {
  7978. intel_do_mmio_flip(intel_crtc);
  7979. mmio_flip->seqno = 0;
  7980. ring->irq_put(ring);
  7981. }
  7982. }
  7983. spin_unlock_irqrestore(&dev_priv->mmio_flip_lock, irq_flags);
  7984. }
  7985. static int intel_queue_mmio_flip(struct drm_device *dev,
  7986. struct drm_crtc *crtc,
  7987. struct drm_framebuffer *fb,
  7988. struct drm_i915_gem_object *obj,
  7989. struct intel_engine_cs *ring,
  7990. uint32_t flags)
  7991. {
  7992. struct drm_i915_private *dev_priv = dev->dev_private;
  7993. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7994. unsigned long irq_flags;
  7995. int ret;
  7996. if (WARN_ON(intel_crtc->mmio_flip.seqno))
  7997. return -EBUSY;
  7998. ret = intel_postpone_flip(obj);
  7999. if (ret < 0)
  8000. return ret;
  8001. if (ret == 0) {
  8002. intel_do_mmio_flip(intel_crtc);
  8003. return 0;
  8004. }
  8005. spin_lock_irqsave(&dev_priv->mmio_flip_lock, irq_flags);
  8006. intel_crtc->mmio_flip.seqno = obj->last_write_seqno;
  8007. intel_crtc->mmio_flip.ring_id = obj->ring->id;
  8008. spin_unlock_irqrestore(&dev_priv->mmio_flip_lock, irq_flags);
  8009. /*
  8010. * Double check to catch cases where irq fired before
  8011. * mmio flip data was ready
  8012. */
  8013. intel_notify_mmio_flip(obj->ring);
  8014. return 0;
  8015. }
  8016. static int intel_default_queue_flip(struct drm_device *dev,
  8017. struct drm_crtc *crtc,
  8018. struct drm_framebuffer *fb,
  8019. struct drm_i915_gem_object *obj,
  8020. struct intel_engine_cs *ring,
  8021. uint32_t flags)
  8022. {
  8023. return -ENODEV;
  8024. }
  8025. static int intel_crtc_page_flip(struct drm_crtc *crtc,
  8026. struct drm_framebuffer *fb,
  8027. struct drm_pending_vblank_event *event,
  8028. uint32_t page_flip_flags)
  8029. {
  8030. struct drm_device *dev = crtc->dev;
  8031. struct drm_i915_private *dev_priv = dev->dev_private;
  8032. struct drm_framebuffer *old_fb = crtc->primary->fb;
  8033. struct drm_i915_gem_object *obj = intel_fb_obj(fb);
  8034. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  8035. enum pipe pipe = intel_crtc->pipe;
  8036. struct intel_unpin_work *work;
  8037. struct intel_engine_cs *ring;
  8038. unsigned long flags;
  8039. int ret;
  8040. /*
  8041. * drm_mode_page_flip_ioctl() should already catch this, but double
  8042. * check to be safe. In the future we may enable pageflipping from
  8043. * a disabled primary plane.
  8044. */
  8045. if (WARN_ON(intel_fb_obj(old_fb) == NULL))
  8046. return -EBUSY;
  8047. /* Can't change pixel format via MI display flips. */
  8048. if (fb->pixel_format != crtc->primary->fb->pixel_format)
  8049. return -EINVAL;
  8050. /*
  8051. * TILEOFF/LINOFF registers can't be changed via MI display flips.
  8052. * Note that pitch changes could also affect these register.
  8053. */
  8054. if (INTEL_INFO(dev)->gen > 3 &&
  8055. (fb->offsets[0] != crtc->primary->fb->offsets[0] ||
  8056. fb->pitches[0] != crtc->primary->fb->pitches[0]))
  8057. return -EINVAL;
  8058. if (i915_terminally_wedged(&dev_priv->gpu_error))
  8059. goto out_hang;
  8060. work = kzalloc(sizeof(*work), GFP_KERNEL);
  8061. if (work == NULL)
  8062. return -ENOMEM;
  8063. work->event = event;
  8064. work->crtc = crtc;
  8065. work->old_fb_obj = intel_fb_obj(old_fb);
  8066. INIT_WORK(&work->work, intel_unpin_work_fn);
  8067. ret = drm_crtc_vblank_get(crtc);
  8068. if (ret)
  8069. goto free_work;
  8070. /* We borrow the event spin lock for protecting unpin_work */
  8071. spin_lock_irqsave(&dev->event_lock, flags);
  8072. if (intel_crtc->unpin_work) {
  8073. spin_unlock_irqrestore(&dev->event_lock, flags);
  8074. kfree(work);
  8075. drm_crtc_vblank_put(crtc);
  8076. DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
  8077. return -EBUSY;
  8078. }
  8079. intel_crtc->unpin_work = work;
  8080. spin_unlock_irqrestore(&dev->event_lock, flags);
  8081. if (atomic_read(&intel_crtc->unpin_work_count) >= 2)
  8082. flush_workqueue(dev_priv->wq);
  8083. ret = i915_mutex_lock_interruptible(dev);
  8084. if (ret)
  8085. goto cleanup;
  8086. /* Reference the objects for the scheduled work. */
  8087. drm_gem_object_reference(&work->old_fb_obj->base);
  8088. drm_gem_object_reference(&obj->base);
  8089. crtc->primary->fb = fb;
  8090. work->pending_flip_obj = obj;
  8091. work->enable_stall_check = true;
  8092. atomic_inc(&intel_crtc->unpin_work_count);
  8093. intel_crtc->reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter);
  8094. if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
  8095. work->flip_count = I915_READ(PIPE_FLIPCOUNT_GM45(pipe)) + 1;
  8096. if (IS_VALLEYVIEW(dev)) {
  8097. ring = &dev_priv->ring[BCS];
  8098. if (obj->tiling_mode != work->old_fb_obj->tiling_mode)
  8099. /* vlv: DISPLAY_FLIP fails to change tiling */
  8100. ring = NULL;
  8101. } else if (IS_IVYBRIDGE(dev)) {
  8102. ring = &dev_priv->ring[BCS];
  8103. } else if (INTEL_INFO(dev)->gen >= 7) {
  8104. ring = obj->ring;
  8105. if (ring == NULL || ring->id != RCS)
  8106. ring = &dev_priv->ring[BCS];
  8107. } else {
  8108. ring = &dev_priv->ring[RCS];
  8109. }
  8110. ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
  8111. if (ret)
  8112. goto cleanup_pending;
  8113. work->gtt_offset =
  8114. i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset;
  8115. if (use_mmio_flip(ring, obj))
  8116. ret = intel_queue_mmio_flip(dev, crtc, fb, obj, ring,
  8117. page_flip_flags);
  8118. else
  8119. ret = dev_priv->display.queue_flip(dev, crtc, fb, obj, ring,
  8120. page_flip_flags);
  8121. if (ret)
  8122. goto cleanup_unpin;
  8123. i915_gem_track_fb(work->old_fb_obj, obj,
  8124. INTEL_FRONTBUFFER_PRIMARY(pipe));
  8125. intel_disable_fbc(dev);
  8126. intel_frontbuffer_flip_prepare(dev, INTEL_FRONTBUFFER_PRIMARY(pipe));
  8127. mutex_unlock(&dev->struct_mutex);
  8128. trace_i915_flip_request(intel_crtc->plane, obj);
  8129. return 0;
  8130. cleanup_unpin:
  8131. intel_unpin_fb_obj(obj);
  8132. cleanup_pending:
  8133. atomic_dec(&intel_crtc->unpin_work_count);
  8134. crtc->primary->fb = old_fb;
  8135. drm_gem_object_unreference(&work->old_fb_obj->base);
  8136. drm_gem_object_unreference(&obj->base);
  8137. mutex_unlock(&dev->struct_mutex);
  8138. cleanup:
  8139. spin_lock_irqsave(&dev->event_lock, flags);
  8140. intel_crtc->unpin_work = NULL;
  8141. spin_unlock_irqrestore(&dev->event_lock, flags);
  8142. drm_crtc_vblank_put(crtc);
  8143. free_work:
  8144. kfree(work);
  8145. if (ret == -EIO) {
  8146. out_hang:
  8147. intel_crtc_wait_for_pending_flips(crtc);
  8148. ret = intel_pipe_set_base(crtc, crtc->x, crtc->y, fb);
  8149. if (ret == 0 && event)
  8150. drm_send_vblank_event(dev, pipe, event);
  8151. }
  8152. return ret;
  8153. }
  8154. static struct drm_crtc_helper_funcs intel_helper_funcs = {
  8155. .mode_set_base_atomic = intel_pipe_set_base_atomic,
  8156. .load_lut = intel_crtc_load_lut,
  8157. };
  8158. /**
  8159. * intel_modeset_update_staged_output_state
  8160. *
  8161. * Updates the staged output configuration state, e.g. after we've read out the
  8162. * current hw state.
  8163. */
  8164. static void intel_modeset_update_staged_output_state(struct drm_device *dev)
  8165. {
  8166. struct intel_crtc *crtc;
  8167. struct intel_encoder *encoder;
  8168. struct intel_connector *connector;
  8169. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8170. base.head) {
  8171. connector->new_encoder =
  8172. to_intel_encoder(connector->base.encoder);
  8173. }
  8174. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  8175. base.head) {
  8176. encoder->new_crtc =
  8177. to_intel_crtc(encoder->base.crtc);
  8178. }
  8179. for_each_intel_crtc(dev, crtc) {
  8180. crtc->new_enabled = crtc->base.enabled;
  8181. if (crtc->new_enabled)
  8182. crtc->new_config = &crtc->config;
  8183. else
  8184. crtc->new_config = NULL;
  8185. }
  8186. }
  8187. /**
  8188. * intel_modeset_commit_output_state
  8189. *
  8190. * This function copies the stage display pipe configuration to the real one.
  8191. */
  8192. static void intel_modeset_commit_output_state(struct drm_device *dev)
  8193. {
  8194. struct intel_crtc *crtc;
  8195. struct intel_encoder *encoder;
  8196. struct intel_connector *connector;
  8197. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8198. base.head) {
  8199. connector->base.encoder = &connector->new_encoder->base;
  8200. }
  8201. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  8202. base.head) {
  8203. encoder->base.crtc = &encoder->new_crtc->base;
  8204. }
  8205. for_each_intel_crtc(dev, crtc) {
  8206. crtc->base.enabled = crtc->new_enabled;
  8207. }
  8208. }
  8209. static void
  8210. connected_sink_compute_bpp(struct intel_connector *connector,
  8211. struct intel_crtc_config *pipe_config)
  8212. {
  8213. int bpp = pipe_config->pipe_bpp;
  8214. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n",
  8215. connector->base.base.id,
  8216. connector->base.name);
  8217. /* Don't use an invalid EDID bpc value */
  8218. if (connector->base.display_info.bpc &&
  8219. connector->base.display_info.bpc * 3 < bpp) {
  8220. DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
  8221. bpp, connector->base.display_info.bpc*3);
  8222. pipe_config->pipe_bpp = connector->base.display_info.bpc*3;
  8223. }
  8224. /* Clamp bpp to 8 on screens without EDID 1.4 */
  8225. if (connector->base.display_info.bpc == 0 && bpp > 24) {
  8226. DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n",
  8227. bpp);
  8228. pipe_config->pipe_bpp = 24;
  8229. }
  8230. }
  8231. static int
  8232. compute_baseline_pipe_bpp(struct intel_crtc *crtc,
  8233. struct drm_framebuffer *fb,
  8234. struct intel_crtc_config *pipe_config)
  8235. {
  8236. struct drm_device *dev = crtc->base.dev;
  8237. struct intel_connector *connector;
  8238. int bpp;
  8239. switch (fb->pixel_format) {
  8240. case DRM_FORMAT_C8:
  8241. bpp = 8*3; /* since we go through a colormap */
  8242. break;
  8243. case DRM_FORMAT_XRGB1555:
  8244. case DRM_FORMAT_ARGB1555:
  8245. /* checked in intel_framebuffer_init already */
  8246. if (WARN_ON(INTEL_INFO(dev)->gen > 3))
  8247. return -EINVAL;
  8248. case DRM_FORMAT_RGB565:
  8249. bpp = 6*3; /* min is 18bpp */
  8250. break;
  8251. case DRM_FORMAT_XBGR8888:
  8252. case DRM_FORMAT_ABGR8888:
  8253. /* checked in intel_framebuffer_init already */
  8254. if (WARN_ON(INTEL_INFO(dev)->gen < 4))
  8255. return -EINVAL;
  8256. case DRM_FORMAT_XRGB8888:
  8257. case DRM_FORMAT_ARGB8888:
  8258. bpp = 8*3;
  8259. break;
  8260. case DRM_FORMAT_XRGB2101010:
  8261. case DRM_FORMAT_ARGB2101010:
  8262. case DRM_FORMAT_XBGR2101010:
  8263. case DRM_FORMAT_ABGR2101010:
  8264. /* checked in intel_framebuffer_init already */
  8265. if (WARN_ON(INTEL_INFO(dev)->gen < 4))
  8266. return -EINVAL;
  8267. bpp = 10*3;
  8268. break;
  8269. /* TODO: gen4+ supports 16 bpc floating point, too. */
  8270. default:
  8271. DRM_DEBUG_KMS("unsupported depth\n");
  8272. return -EINVAL;
  8273. }
  8274. pipe_config->pipe_bpp = bpp;
  8275. /* Clamp display bpp to EDID value */
  8276. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8277. base.head) {
  8278. if (!connector->new_encoder ||
  8279. connector->new_encoder->new_crtc != crtc)
  8280. continue;
  8281. connected_sink_compute_bpp(connector, pipe_config);
  8282. }
  8283. return bpp;
  8284. }
  8285. static void intel_dump_crtc_timings(const struct drm_display_mode *mode)
  8286. {
  8287. DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
  8288. "type: 0x%x flags: 0x%x\n",
  8289. mode->crtc_clock,
  8290. mode->crtc_hdisplay, mode->crtc_hsync_start,
  8291. mode->crtc_hsync_end, mode->crtc_htotal,
  8292. mode->crtc_vdisplay, mode->crtc_vsync_start,
  8293. mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags);
  8294. }
  8295. static void intel_dump_pipe_config(struct intel_crtc *crtc,
  8296. struct intel_crtc_config *pipe_config,
  8297. const char *context)
  8298. {
  8299. DRM_DEBUG_KMS("[CRTC:%d]%s config for pipe %c\n", crtc->base.base.id,
  8300. context, pipe_name(crtc->pipe));
  8301. DRM_DEBUG_KMS("cpu_transcoder: %c\n", transcoder_name(pipe_config->cpu_transcoder));
  8302. DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n",
  8303. pipe_config->pipe_bpp, pipe_config->dither);
  8304. DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
  8305. pipe_config->has_pch_encoder,
  8306. pipe_config->fdi_lanes,
  8307. pipe_config->fdi_m_n.gmch_m, pipe_config->fdi_m_n.gmch_n,
  8308. pipe_config->fdi_m_n.link_m, pipe_config->fdi_m_n.link_n,
  8309. pipe_config->fdi_m_n.tu);
  8310. DRM_DEBUG_KMS("dp: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
  8311. pipe_config->has_dp_encoder,
  8312. pipe_config->dp_m_n.gmch_m, pipe_config->dp_m_n.gmch_n,
  8313. pipe_config->dp_m_n.link_m, pipe_config->dp_m_n.link_n,
  8314. pipe_config->dp_m_n.tu);
  8315. DRM_DEBUG_KMS("requested mode:\n");
  8316. drm_mode_debug_printmodeline(&pipe_config->requested_mode);
  8317. DRM_DEBUG_KMS("adjusted mode:\n");
  8318. drm_mode_debug_printmodeline(&pipe_config->adjusted_mode);
  8319. intel_dump_crtc_timings(&pipe_config->adjusted_mode);
  8320. DRM_DEBUG_KMS("port clock: %d\n", pipe_config->port_clock);
  8321. DRM_DEBUG_KMS("pipe src size: %dx%d\n",
  8322. pipe_config->pipe_src_w, pipe_config->pipe_src_h);
  8323. DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
  8324. pipe_config->gmch_pfit.control,
  8325. pipe_config->gmch_pfit.pgm_ratios,
  8326. pipe_config->gmch_pfit.lvds_border_bits);
  8327. DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
  8328. pipe_config->pch_pfit.pos,
  8329. pipe_config->pch_pfit.size,
  8330. pipe_config->pch_pfit.enabled ? "enabled" : "disabled");
  8331. DRM_DEBUG_KMS("ips: %i\n", pipe_config->ips_enabled);
  8332. DRM_DEBUG_KMS("double wide: %i\n", pipe_config->double_wide);
  8333. }
  8334. static bool encoders_cloneable(const struct intel_encoder *a,
  8335. const struct intel_encoder *b)
  8336. {
  8337. /* masks could be asymmetric, so check both ways */
  8338. return a == b || (a->cloneable & (1 << b->type) &&
  8339. b->cloneable & (1 << a->type));
  8340. }
  8341. static bool check_single_encoder_cloning(struct intel_crtc *crtc,
  8342. struct intel_encoder *encoder)
  8343. {
  8344. struct drm_device *dev = crtc->base.dev;
  8345. struct intel_encoder *source_encoder;
  8346. list_for_each_entry(source_encoder,
  8347. &dev->mode_config.encoder_list, base.head) {
  8348. if (source_encoder->new_crtc != crtc)
  8349. continue;
  8350. if (!encoders_cloneable(encoder, source_encoder))
  8351. return false;
  8352. }
  8353. return true;
  8354. }
  8355. static bool check_encoder_cloning(struct intel_crtc *crtc)
  8356. {
  8357. struct drm_device *dev = crtc->base.dev;
  8358. struct intel_encoder *encoder;
  8359. list_for_each_entry(encoder,
  8360. &dev->mode_config.encoder_list, base.head) {
  8361. if (encoder->new_crtc != crtc)
  8362. continue;
  8363. if (!check_single_encoder_cloning(crtc, encoder))
  8364. return false;
  8365. }
  8366. return true;
  8367. }
  8368. static struct intel_crtc_config *
  8369. intel_modeset_pipe_config(struct drm_crtc *crtc,
  8370. struct drm_framebuffer *fb,
  8371. struct drm_display_mode *mode)
  8372. {
  8373. struct drm_device *dev = crtc->dev;
  8374. struct intel_encoder *encoder;
  8375. struct intel_crtc_config *pipe_config;
  8376. int plane_bpp, ret = -EINVAL;
  8377. bool retry = true;
  8378. if (!check_encoder_cloning(to_intel_crtc(crtc))) {
  8379. DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
  8380. return ERR_PTR(-EINVAL);
  8381. }
  8382. pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL);
  8383. if (!pipe_config)
  8384. return ERR_PTR(-ENOMEM);
  8385. drm_mode_copy(&pipe_config->adjusted_mode, mode);
  8386. drm_mode_copy(&pipe_config->requested_mode, mode);
  8387. pipe_config->cpu_transcoder =
  8388. (enum transcoder) to_intel_crtc(crtc)->pipe;
  8389. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  8390. /*
  8391. * Sanitize sync polarity flags based on requested ones. If neither
  8392. * positive or negative polarity is requested, treat this as meaning
  8393. * negative polarity.
  8394. */
  8395. if (!(pipe_config->adjusted_mode.flags &
  8396. (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
  8397. pipe_config->adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
  8398. if (!(pipe_config->adjusted_mode.flags &
  8399. (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
  8400. pipe_config->adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
  8401. /* Compute a starting value for pipe_config->pipe_bpp taking the source
  8402. * plane pixel format and any sink constraints into account. Returns the
  8403. * source plane bpp so that dithering can be selected on mismatches
  8404. * after encoders and crtc also have had their say. */
  8405. plane_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc),
  8406. fb, pipe_config);
  8407. if (plane_bpp < 0)
  8408. goto fail;
  8409. /*
  8410. * Determine the real pipe dimensions. Note that stereo modes can
  8411. * increase the actual pipe size due to the frame doubling and
  8412. * insertion of additional space for blanks between the frame. This
  8413. * is stored in the crtc timings. We use the requested mode to do this
  8414. * computation to clearly distinguish it from the adjusted mode, which
  8415. * can be changed by the connectors in the below retry loop.
  8416. */
  8417. drm_mode_set_crtcinfo(&pipe_config->requested_mode, CRTC_STEREO_DOUBLE);
  8418. pipe_config->pipe_src_w = pipe_config->requested_mode.crtc_hdisplay;
  8419. pipe_config->pipe_src_h = pipe_config->requested_mode.crtc_vdisplay;
  8420. encoder_retry:
  8421. /* Ensure the port clock defaults are reset when retrying. */
  8422. pipe_config->port_clock = 0;
  8423. pipe_config->pixel_multiplier = 1;
  8424. /* Fill in default crtc timings, allow encoders to overwrite them. */
  8425. drm_mode_set_crtcinfo(&pipe_config->adjusted_mode, CRTC_STEREO_DOUBLE);
  8426. /* Pass our mode to the connectors and the CRTC to give them a chance to
  8427. * adjust it according to limitations or connector properties, and also
  8428. * a chance to reject the mode entirely.
  8429. */
  8430. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  8431. base.head) {
  8432. if (&encoder->new_crtc->base != crtc)
  8433. continue;
  8434. if (!(encoder->compute_config(encoder, pipe_config))) {
  8435. DRM_DEBUG_KMS("Encoder config failure\n");
  8436. goto fail;
  8437. }
  8438. }
  8439. /* Set default port clock if not overwritten by the encoder. Needs to be
  8440. * done afterwards in case the encoder adjusts the mode. */
  8441. if (!pipe_config->port_clock)
  8442. pipe_config->port_clock = pipe_config->adjusted_mode.crtc_clock
  8443. * pipe_config->pixel_multiplier;
  8444. ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config);
  8445. if (ret < 0) {
  8446. DRM_DEBUG_KMS("CRTC fixup failed\n");
  8447. goto fail;
  8448. }
  8449. if (ret == RETRY) {
  8450. if (WARN(!retry, "loop in pipe configuration computation\n")) {
  8451. ret = -EINVAL;
  8452. goto fail;
  8453. }
  8454. DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
  8455. retry = false;
  8456. goto encoder_retry;
  8457. }
  8458. pipe_config->dither = pipe_config->pipe_bpp != plane_bpp;
  8459. DRM_DEBUG_KMS("plane bpp: %i, pipe bpp: %i, dithering: %i\n",
  8460. plane_bpp, pipe_config->pipe_bpp, pipe_config->dither);
  8461. return pipe_config;
  8462. fail:
  8463. kfree(pipe_config);
  8464. return ERR_PTR(ret);
  8465. }
  8466. /* Computes which crtcs are affected and sets the relevant bits in the mask. For
  8467. * simplicity we use the crtc's pipe number (because it's easier to obtain). */
  8468. static void
  8469. intel_modeset_affected_pipes(struct drm_crtc *crtc, unsigned *modeset_pipes,
  8470. unsigned *prepare_pipes, unsigned *disable_pipes)
  8471. {
  8472. struct intel_crtc *intel_crtc;
  8473. struct drm_device *dev = crtc->dev;
  8474. struct intel_encoder *encoder;
  8475. struct intel_connector *connector;
  8476. struct drm_crtc *tmp_crtc;
  8477. *disable_pipes = *modeset_pipes = *prepare_pipes = 0;
  8478. /* Check which crtcs have changed outputs connected to them, these need
  8479. * to be part of the prepare_pipes mask. We don't (yet) support global
  8480. * modeset across multiple crtcs, so modeset_pipes will only have one
  8481. * bit set at most. */
  8482. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8483. base.head) {
  8484. if (connector->base.encoder == &connector->new_encoder->base)
  8485. continue;
  8486. if (connector->base.encoder) {
  8487. tmp_crtc = connector->base.encoder->crtc;
  8488. *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe;
  8489. }
  8490. if (connector->new_encoder)
  8491. *prepare_pipes |=
  8492. 1 << connector->new_encoder->new_crtc->pipe;
  8493. }
  8494. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  8495. base.head) {
  8496. if (encoder->base.crtc == &encoder->new_crtc->base)
  8497. continue;
  8498. if (encoder->base.crtc) {
  8499. tmp_crtc = encoder->base.crtc;
  8500. *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe;
  8501. }
  8502. if (encoder->new_crtc)
  8503. *prepare_pipes |= 1 << encoder->new_crtc->pipe;
  8504. }
  8505. /* Check for pipes that will be enabled/disabled ... */
  8506. for_each_intel_crtc(dev, intel_crtc) {
  8507. if (intel_crtc->base.enabled == intel_crtc->new_enabled)
  8508. continue;
  8509. if (!intel_crtc->new_enabled)
  8510. *disable_pipes |= 1 << intel_crtc->pipe;
  8511. else
  8512. *prepare_pipes |= 1 << intel_crtc->pipe;
  8513. }
  8514. /* set_mode is also used to update properties on life display pipes. */
  8515. intel_crtc = to_intel_crtc(crtc);
  8516. if (intel_crtc->new_enabled)
  8517. *prepare_pipes |= 1 << intel_crtc->pipe;
  8518. /*
  8519. * For simplicity do a full modeset on any pipe where the output routing
  8520. * changed. We could be more clever, but that would require us to be
  8521. * more careful with calling the relevant encoder->mode_set functions.
  8522. */
  8523. if (*prepare_pipes)
  8524. *modeset_pipes = *prepare_pipes;
  8525. /* ... and mask these out. */
  8526. *modeset_pipes &= ~(*disable_pipes);
  8527. *prepare_pipes &= ~(*disable_pipes);
  8528. /*
  8529. * HACK: We don't (yet) fully support global modesets. intel_set_config
  8530. * obies this rule, but the modeset restore mode of
  8531. * intel_modeset_setup_hw_state does not.
  8532. */
  8533. *modeset_pipes &= 1 << intel_crtc->pipe;
  8534. *prepare_pipes &= 1 << intel_crtc->pipe;
  8535. DRM_DEBUG_KMS("set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n",
  8536. *modeset_pipes, *prepare_pipes, *disable_pipes);
  8537. }
  8538. static bool intel_crtc_in_use(struct drm_crtc *crtc)
  8539. {
  8540. struct drm_encoder *encoder;
  8541. struct drm_device *dev = crtc->dev;
  8542. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)
  8543. if (encoder->crtc == crtc)
  8544. return true;
  8545. return false;
  8546. }
  8547. static void
  8548. intel_modeset_update_state(struct drm_device *dev, unsigned prepare_pipes)
  8549. {
  8550. struct intel_encoder *intel_encoder;
  8551. struct intel_crtc *intel_crtc;
  8552. struct drm_connector *connector;
  8553. list_for_each_entry(intel_encoder, &dev->mode_config.encoder_list,
  8554. base.head) {
  8555. if (!intel_encoder->base.crtc)
  8556. continue;
  8557. intel_crtc = to_intel_crtc(intel_encoder->base.crtc);
  8558. if (prepare_pipes & (1 << intel_crtc->pipe))
  8559. intel_encoder->connectors_active = false;
  8560. }
  8561. intel_modeset_commit_output_state(dev);
  8562. /* Double check state. */
  8563. for_each_intel_crtc(dev, intel_crtc) {
  8564. WARN_ON(intel_crtc->base.enabled != intel_crtc_in_use(&intel_crtc->base));
  8565. WARN_ON(intel_crtc->new_config &&
  8566. intel_crtc->new_config != &intel_crtc->config);
  8567. WARN_ON(intel_crtc->base.enabled != !!intel_crtc->new_config);
  8568. }
  8569. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  8570. if (!connector->encoder || !connector->encoder->crtc)
  8571. continue;
  8572. intel_crtc = to_intel_crtc(connector->encoder->crtc);
  8573. if (prepare_pipes & (1 << intel_crtc->pipe)) {
  8574. struct drm_property *dpms_property =
  8575. dev->mode_config.dpms_property;
  8576. connector->dpms = DRM_MODE_DPMS_ON;
  8577. drm_object_property_set_value(&connector->base,
  8578. dpms_property,
  8579. DRM_MODE_DPMS_ON);
  8580. intel_encoder = to_intel_encoder(connector->encoder);
  8581. intel_encoder->connectors_active = true;
  8582. }
  8583. }
  8584. }
  8585. static bool intel_fuzzy_clock_check(int clock1, int clock2)
  8586. {
  8587. int diff;
  8588. if (clock1 == clock2)
  8589. return true;
  8590. if (!clock1 || !clock2)
  8591. return false;
  8592. diff = abs(clock1 - clock2);
  8593. if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
  8594. return true;
  8595. return false;
  8596. }
  8597. #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \
  8598. list_for_each_entry((intel_crtc), \
  8599. &(dev)->mode_config.crtc_list, \
  8600. base.head) \
  8601. if (mask & (1 <<(intel_crtc)->pipe))
  8602. static bool
  8603. intel_pipe_config_compare(struct drm_device *dev,
  8604. struct intel_crtc_config *current_config,
  8605. struct intel_crtc_config *pipe_config)
  8606. {
  8607. #define PIPE_CONF_CHECK_X(name) \
  8608. if (current_config->name != pipe_config->name) { \
  8609. DRM_ERROR("mismatch in " #name " " \
  8610. "(expected 0x%08x, found 0x%08x)\n", \
  8611. current_config->name, \
  8612. pipe_config->name); \
  8613. return false; \
  8614. }
  8615. #define PIPE_CONF_CHECK_I(name) \
  8616. if (current_config->name != pipe_config->name) { \
  8617. DRM_ERROR("mismatch in " #name " " \
  8618. "(expected %i, found %i)\n", \
  8619. current_config->name, \
  8620. pipe_config->name); \
  8621. return false; \
  8622. }
  8623. #define PIPE_CONF_CHECK_FLAGS(name, mask) \
  8624. if ((current_config->name ^ pipe_config->name) & (mask)) { \
  8625. DRM_ERROR("mismatch in " #name "(" #mask ") " \
  8626. "(expected %i, found %i)\n", \
  8627. current_config->name & (mask), \
  8628. pipe_config->name & (mask)); \
  8629. return false; \
  8630. }
  8631. #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \
  8632. if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
  8633. DRM_ERROR("mismatch in " #name " " \
  8634. "(expected %i, found %i)\n", \
  8635. current_config->name, \
  8636. pipe_config->name); \
  8637. return false; \
  8638. }
  8639. #define PIPE_CONF_QUIRK(quirk) \
  8640. ((current_config->quirks | pipe_config->quirks) & (quirk))
  8641. PIPE_CONF_CHECK_I(cpu_transcoder);
  8642. PIPE_CONF_CHECK_I(has_pch_encoder);
  8643. PIPE_CONF_CHECK_I(fdi_lanes);
  8644. PIPE_CONF_CHECK_I(fdi_m_n.gmch_m);
  8645. PIPE_CONF_CHECK_I(fdi_m_n.gmch_n);
  8646. PIPE_CONF_CHECK_I(fdi_m_n.link_m);
  8647. PIPE_CONF_CHECK_I(fdi_m_n.link_n);
  8648. PIPE_CONF_CHECK_I(fdi_m_n.tu);
  8649. PIPE_CONF_CHECK_I(has_dp_encoder);
  8650. PIPE_CONF_CHECK_I(dp_m_n.gmch_m);
  8651. PIPE_CONF_CHECK_I(dp_m_n.gmch_n);
  8652. PIPE_CONF_CHECK_I(dp_m_n.link_m);
  8653. PIPE_CONF_CHECK_I(dp_m_n.link_n);
  8654. PIPE_CONF_CHECK_I(dp_m_n.tu);
  8655. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hdisplay);
  8656. PIPE_CONF_CHECK_I(adjusted_mode.crtc_htotal);
  8657. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hblank_start);
  8658. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hblank_end);
  8659. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hsync_start);
  8660. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hsync_end);
  8661. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vdisplay);
  8662. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vtotal);
  8663. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vblank_start);
  8664. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vblank_end);
  8665. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vsync_start);
  8666. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vsync_end);
  8667. PIPE_CONF_CHECK_I(pixel_multiplier);
  8668. PIPE_CONF_CHECK_I(has_hdmi_sink);
  8669. if ((INTEL_INFO(dev)->gen < 8 && !IS_HASWELL(dev)) ||
  8670. IS_VALLEYVIEW(dev))
  8671. PIPE_CONF_CHECK_I(limited_color_range);
  8672. PIPE_CONF_CHECK_I(has_audio);
  8673. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  8674. DRM_MODE_FLAG_INTERLACE);
  8675. if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
  8676. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  8677. DRM_MODE_FLAG_PHSYNC);
  8678. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  8679. DRM_MODE_FLAG_NHSYNC);
  8680. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  8681. DRM_MODE_FLAG_PVSYNC);
  8682. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  8683. DRM_MODE_FLAG_NVSYNC);
  8684. }
  8685. PIPE_CONF_CHECK_I(pipe_src_w);
  8686. PIPE_CONF_CHECK_I(pipe_src_h);
  8687. /*
  8688. * FIXME: BIOS likes to set up a cloned config with lvds+external
  8689. * screen. Since we don't yet re-compute the pipe config when moving
  8690. * just the lvds port away to another pipe the sw tracking won't match.
  8691. *
  8692. * Proper atomic modesets with recomputed global state will fix this.
  8693. * Until then just don't check gmch state for inherited modes.
  8694. */
  8695. if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_INHERITED_MODE)) {
  8696. PIPE_CONF_CHECK_I(gmch_pfit.control);
  8697. /* pfit ratios are autocomputed by the hw on gen4+ */
  8698. if (INTEL_INFO(dev)->gen < 4)
  8699. PIPE_CONF_CHECK_I(gmch_pfit.pgm_ratios);
  8700. PIPE_CONF_CHECK_I(gmch_pfit.lvds_border_bits);
  8701. }
  8702. PIPE_CONF_CHECK_I(pch_pfit.enabled);
  8703. if (current_config->pch_pfit.enabled) {
  8704. PIPE_CONF_CHECK_I(pch_pfit.pos);
  8705. PIPE_CONF_CHECK_I(pch_pfit.size);
  8706. }
  8707. /* BDW+ don't expose a synchronous way to read the state */
  8708. if (IS_HASWELL(dev))
  8709. PIPE_CONF_CHECK_I(ips_enabled);
  8710. PIPE_CONF_CHECK_I(double_wide);
  8711. PIPE_CONF_CHECK_I(shared_dpll);
  8712. PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
  8713. PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
  8714. PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
  8715. PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
  8716. if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5)
  8717. PIPE_CONF_CHECK_I(pipe_bpp);
  8718. PIPE_CONF_CHECK_CLOCK_FUZZY(adjusted_mode.crtc_clock);
  8719. PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock);
  8720. #undef PIPE_CONF_CHECK_X
  8721. #undef PIPE_CONF_CHECK_I
  8722. #undef PIPE_CONF_CHECK_FLAGS
  8723. #undef PIPE_CONF_CHECK_CLOCK_FUZZY
  8724. #undef PIPE_CONF_QUIRK
  8725. return true;
  8726. }
  8727. static void
  8728. check_connector_state(struct drm_device *dev)
  8729. {
  8730. struct intel_connector *connector;
  8731. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8732. base.head) {
  8733. /* This also checks the encoder/connector hw state with the
  8734. * ->get_hw_state callbacks. */
  8735. intel_connector_check_state(connector);
  8736. WARN(&connector->new_encoder->base != connector->base.encoder,
  8737. "connector's staged encoder doesn't match current encoder\n");
  8738. }
  8739. }
  8740. static void
  8741. check_encoder_state(struct drm_device *dev)
  8742. {
  8743. struct intel_encoder *encoder;
  8744. struct intel_connector *connector;
  8745. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  8746. base.head) {
  8747. bool enabled = false;
  8748. bool active = false;
  8749. enum pipe pipe, tracked_pipe;
  8750. DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
  8751. encoder->base.base.id,
  8752. encoder->base.name);
  8753. WARN(&encoder->new_crtc->base != encoder->base.crtc,
  8754. "encoder's stage crtc doesn't match current crtc\n");
  8755. WARN(encoder->connectors_active && !encoder->base.crtc,
  8756. "encoder's active_connectors set, but no crtc\n");
  8757. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8758. base.head) {
  8759. if (connector->base.encoder != &encoder->base)
  8760. continue;
  8761. enabled = true;
  8762. if (connector->base.dpms != DRM_MODE_DPMS_OFF)
  8763. active = true;
  8764. }
  8765. WARN(!!encoder->base.crtc != enabled,
  8766. "encoder's enabled state mismatch "
  8767. "(expected %i, found %i)\n",
  8768. !!encoder->base.crtc, enabled);
  8769. WARN(active && !encoder->base.crtc,
  8770. "active encoder with no crtc\n");
  8771. WARN(encoder->connectors_active != active,
  8772. "encoder's computed active state doesn't match tracked active state "
  8773. "(expected %i, found %i)\n", active, encoder->connectors_active);
  8774. active = encoder->get_hw_state(encoder, &pipe);
  8775. WARN(active != encoder->connectors_active,
  8776. "encoder's hw state doesn't match sw tracking "
  8777. "(expected %i, found %i)\n",
  8778. encoder->connectors_active, active);
  8779. if (!encoder->base.crtc)
  8780. continue;
  8781. tracked_pipe = to_intel_crtc(encoder->base.crtc)->pipe;
  8782. WARN(active && pipe != tracked_pipe,
  8783. "active encoder's pipe doesn't match"
  8784. "(expected %i, found %i)\n",
  8785. tracked_pipe, pipe);
  8786. }
  8787. }
  8788. static void
  8789. check_crtc_state(struct drm_device *dev)
  8790. {
  8791. struct drm_i915_private *dev_priv = dev->dev_private;
  8792. struct intel_crtc *crtc;
  8793. struct intel_encoder *encoder;
  8794. struct intel_crtc_config pipe_config;
  8795. for_each_intel_crtc(dev, crtc) {
  8796. bool enabled = false;
  8797. bool active = false;
  8798. memset(&pipe_config, 0, sizeof(pipe_config));
  8799. DRM_DEBUG_KMS("[CRTC:%d]\n",
  8800. crtc->base.base.id);
  8801. WARN(crtc->active && !crtc->base.enabled,
  8802. "active crtc, but not enabled in sw tracking\n");
  8803. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  8804. base.head) {
  8805. if (encoder->base.crtc != &crtc->base)
  8806. continue;
  8807. enabled = true;
  8808. if (encoder->connectors_active)
  8809. active = true;
  8810. }
  8811. WARN(active != crtc->active,
  8812. "crtc's computed active state doesn't match tracked active state "
  8813. "(expected %i, found %i)\n", active, crtc->active);
  8814. WARN(enabled != crtc->base.enabled,
  8815. "crtc's computed enabled state doesn't match tracked enabled state "
  8816. "(expected %i, found %i)\n", enabled, crtc->base.enabled);
  8817. active = dev_priv->display.get_pipe_config(crtc,
  8818. &pipe_config);
  8819. /* hw state is inconsistent with the pipe A quirk */
  8820. if (crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE)
  8821. active = crtc->active;
  8822. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  8823. base.head) {
  8824. enum pipe pipe;
  8825. if (encoder->base.crtc != &crtc->base)
  8826. continue;
  8827. if (encoder->get_hw_state(encoder, &pipe))
  8828. encoder->get_config(encoder, &pipe_config);
  8829. }
  8830. WARN(crtc->active != active,
  8831. "crtc active state doesn't match with hw state "
  8832. "(expected %i, found %i)\n", crtc->active, active);
  8833. if (active &&
  8834. !intel_pipe_config_compare(dev, &crtc->config, &pipe_config)) {
  8835. WARN(1, "pipe state doesn't match!\n");
  8836. intel_dump_pipe_config(crtc, &pipe_config,
  8837. "[hw state]");
  8838. intel_dump_pipe_config(crtc, &crtc->config,
  8839. "[sw state]");
  8840. }
  8841. }
  8842. }
  8843. static void
  8844. check_shared_dpll_state(struct drm_device *dev)
  8845. {
  8846. struct drm_i915_private *dev_priv = dev->dev_private;
  8847. struct intel_crtc *crtc;
  8848. struct intel_dpll_hw_state dpll_hw_state;
  8849. int i;
  8850. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  8851. struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
  8852. int enabled_crtcs = 0, active_crtcs = 0;
  8853. bool active;
  8854. memset(&dpll_hw_state, 0, sizeof(dpll_hw_state));
  8855. DRM_DEBUG_KMS("%s\n", pll->name);
  8856. active = pll->get_hw_state(dev_priv, pll, &dpll_hw_state);
  8857. WARN(pll->active > pll->refcount,
  8858. "more active pll users than references: %i vs %i\n",
  8859. pll->active, pll->refcount);
  8860. WARN(pll->active && !pll->on,
  8861. "pll in active use but not on in sw tracking\n");
  8862. WARN(pll->on && !pll->active,
  8863. "pll in on but not on in use in sw tracking\n");
  8864. WARN(pll->on != active,
  8865. "pll on state mismatch (expected %i, found %i)\n",
  8866. pll->on, active);
  8867. for_each_intel_crtc(dev, crtc) {
  8868. if (crtc->base.enabled && intel_crtc_to_shared_dpll(crtc) == pll)
  8869. enabled_crtcs++;
  8870. if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll)
  8871. active_crtcs++;
  8872. }
  8873. WARN(pll->active != active_crtcs,
  8874. "pll active crtcs mismatch (expected %i, found %i)\n",
  8875. pll->active, active_crtcs);
  8876. WARN(pll->refcount != enabled_crtcs,
  8877. "pll enabled crtcs mismatch (expected %i, found %i)\n",
  8878. pll->refcount, enabled_crtcs);
  8879. WARN(pll->on && memcmp(&pll->hw_state, &dpll_hw_state,
  8880. sizeof(dpll_hw_state)),
  8881. "pll hw state mismatch\n");
  8882. }
  8883. }
  8884. void
  8885. intel_modeset_check_state(struct drm_device *dev)
  8886. {
  8887. check_connector_state(dev);
  8888. check_encoder_state(dev);
  8889. check_crtc_state(dev);
  8890. check_shared_dpll_state(dev);
  8891. }
  8892. void ironlake_check_encoder_dotclock(const struct intel_crtc_config *pipe_config,
  8893. int dotclock)
  8894. {
  8895. /*
  8896. * FDI already provided one idea for the dotclock.
  8897. * Yell if the encoder disagrees.
  8898. */
  8899. WARN(!intel_fuzzy_clock_check(pipe_config->adjusted_mode.crtc_clock, dotclock),
  8900. "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
  8901. pipe_config->adjusted_mode.crtc_clock, dotclock);
  8902. }
  8903. static void update_scanline_offset(struct intel_crtc *crtc)
  8904. {
  8905. struct drm_device *dev = crtc->base.dev;
  8906. /*
  8907. * The scanline counter increments at the leading edge of hsync.
  8908. *
  8909. * On most platforms it starts counting from vtotal-1 on the
  8910. * first active line. That means the scanline counter value is
  8911. * always one less than what we would expect. Ie. just after
  8912. * start of vblank, which also occurs at start of hsync (on the
  8913. * last active line), the scanline counter will read vblank_start-1.
  8914. *
  8915. * On gen2 the scanline counter starts counting from 1 instead
  8916. * of vtotal-1, so we have to subtract one (or rather add vtotal-1
  8917. * to keep the value positive), instead of adding one.
  8918. *
  8919. * On HSW+ the behaviour of the scanline counter depends on the output
  8920. * type. For DP ports it behaves like most other platforms, but on HDMI
  8921. * there's an extra 1 line difference. So we need to add two instead of
  8922. * one to the value.
  8923. */
  8924. if (IS_GEN2(dev)) {
  8925. const struct drm_display_mode *mode = &crtc->config.adjusted_mode;
  8926. int vtotal;
  8927. vtotal = mode->crtc_vtotal;
  8928. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  8929. vtotal /= 2;
  8930. crtc->scanline_offset = vtotal - 1;
  8931. } else if (HAS_DDI(dev) &&
  8932. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI)) {
  8933. crtc->scanline_offset = 2;
  8934. } else
  8935. crtc->scanline_offset = 1;
  8936. }
  8937. static int __intel_set_mode(struct drm_crtc *crtc,
  8938. struct drm_display_mode *mode,
  8939. int x, int y, struct drm_framebuffer *fb)
  8940. {
  8941. struct drm_device *dev = crtc->dev;
  8942. struct drm_i915_private *dev_priv = dev->dev_private;
  8943. struct drm_display_mode *saved_mode;
  8944. struct intel_crtc_config *pipe_config = NULL;
  8945. struct intel_crtc *intel_crtc;
  8946. unsigned disable_pipes, prepare_pipes, modeset_pipes;
  8947. int ret = 0;
  8948. saved_mode = kmalloc(sizeof(*saved_mode), GFP_KERNEL);
  8949. if (!saved_mode)
  8950. return -ENOMEM;
  8951. intel_modeset_affected_pipes(crtc, &modeset_pipes,
  8952. &prepare_pipes, &disable_pipes);
  8953. *saved_mode = crtc->mode;
  8954. /* Hack: Because we don't (yet) support global modeset on multiple
  8955. * crtcs, we don't keep track of the new mode for more than one crtc.
  8956. * Hence simply check whether any bit is set in modeset_pipes in all the
  8957. * pieces of code that are not yet converted to deal with mutliple crtcs
  8958. * changing their mode at the same time. */
  8959. if (modeset_pipes) {
  8960. pipe_config = intel_modeset_pipe_config(crtc, fb, mode);
  8961. if (IS_ERR(pipe_config)) {
  8962. ret = PTR_ERR(pipe_config);
  8963. pipe_config = NULL;
  8964. goto out;
  8965. }
  8966. intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config,
  8967. "[modeset]");
  8968. to_intel_crtc(crtc)->new_config = pipe_config;
  8969. }
  8970. /*
  8971. * See if the config requires any additional preparation, e.g.
  8972. * to adjust global state with pipes off. We need to do this
  8973. * here so we can get the modeset_pipe updated config for the new
  8974. * mode set on this crtc. For other crtcs we need to use the
  8975. * adjusted_mode bits in the crtc directly.
  8976. */
  8977. if (IS_VALLEYVIEW(dev)) {
  8978. valleyview_modeset_global_pipes(dev, &prepare_pipes);
  8979. /* may have added more to prepare_pipes than we should */
  8980. prepare_pipes &= ~disable_pipes;
  8981. }
  8982. for_each_intel_crtc_masked(dev, disable_pipes, intel_crtc)
  8983. intel_crtc_disable(&intel_crtc->base);
  8984. for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) {
  8985. if (intel_crtc->base.enabled)
  8986. dev_priv->display.crtc_disable(&intel_crtc->base);
  8987. }
  8988. /* crtc->mode is already used by the ->mode_set callbacks, hence we need
  8989. * to set it here already despite that we pass it down the callchain.
  8990. */
  8991. if (modeset_pipes) {
  8992. crtc->mode = *mode;
  8993. /* mode_set/enable/disable functions rely on a correct pipe
  8994. * config. */
  8995. to_intel_crtc(crtc)->config = *pipe_config;
  8996. to_intel_crtc(crtc)->new_config = &to_intel_crtc(crtc)->config;
  8997. /*
  8998. * Calculate and store various constants which
  8999. * are later needed by vblank and swap-completion
  9000. * timestamping. They are derived from true hwmode.
  9001. */
  9002. drm_calc_timestamping_constants(crtc,
  9003. &pipe_config->adjusted_mode);
  9004. }
  9005. /* Only after disabling all output pipelines that will be changed can we
  9006. * update the the output configuration. */
  9007. intel_modeset_update_state(dev, prepare_pipes);
  9008. if (dev_priv->display.modeset_global_resources)
  9009. dev_priv->display.modeset_global_resources(dev);
  9010. /* Set up the DPLL and any encoders state that needs to adjust or depend
  9011. * on the DPLL.
  9012. */
  9013. for_each_intel_crtc_masked(dev, modeset_pipes, intel_crtc) {
  9014. struct drm_framebuffer *old_fb = crtc->primary->fb;
  9015. struct drm_i915_gem_object *old_obj = intel_fb_obj(old_fb);
  9016. struct drm_i915_gem_object *obj = intel_fb_obj(fb);
  9017. mutex_lock(&dev->struct_mutex);
  9018. ret = intel_pin_and_fence_fb_obj(dev,
  9019. obj,
  9020. NULL);
  9021. if (ret != 0) {
  9022. DRM_ERROR("pin & fence failed\n");
  9023. mutex_unlock(&dev->struct_mutex);
  9024. goto done;
  9025. }
  9026. if (old_fb)
  9027. intel_unpin_fb_obj(old_obj);
  9028. i915_gem_track_fb(old_obj, obj,
  9029. INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe));
  9030. mutex_unlock(&dev->struct_mutex);
  9031. crtc->primary->fb = fb;
  9032. crtc->x = x;
  9033. crtc->y = y;
  9034. ret = dev_priv->display.crtc_mode_set(&intel_crtc->base,
  9035. x, y, fb);
  9036. if (ret)
  9037. goto done;
  9038. }
  9039. /* Now enable the clocks, plane, pipe, and connectors that we set up. */
  9040. for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) {
  9041. update_scanline_offset(intel_crtc);
  9042. dev_priv->display.crtc_enable(&intel_crtc->base);
  9043. }
  9044. /* FIXME: add subpixel order */
  9045. done:
  9046. if (ret && crtc->enabled)
  9047. crtc->mode = *saved_mode;
  9048. out:
  9049. kfree(pipe_config);
  9050. kfree(saved_mode);
  9051. return ret;
  9052. }
  9053. static int intel_set_mode(struct drm_crtc *crtc,
  9054. struct drm_display_mode *mode,
  9055. int x, int y, struct drm_framebuffer *fb)
  9056. {
  9057. int ret;
  9058. ret = __intel_set_mode(crtc, mode, x, y, fb);
  9059. if (ret == 0)
  9060. intel_modeset_check_state(crtc->dev);
  9061. return ret;
  9062. }
  9063. void intel_crtc_restore_mode(struct drm_crtc *crtc)
  9064. {
  9065. intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y, crtc->primary->fb);
  9066. }
  9067. #undef for_each_intel_crtc_masked
  9068. static void intel_set_config_free(struct intel_set_config *config)
  9069. {
  9070. if (!config)
  9071. return;
  9072. kfree(config->save_connector_encoders);
  9073. kfree(config->save_encoder_crtcs);
  9074. kfree(config->save_crtc_enabled);
  9075. kfree(config);
  9076. }
  9077. static int intel_set_config_save_state(struct drm_device *dev,
  9078. struct intel_set_config *config)
  9079. {
  9080. struct drm_crtc *crtc;
  9081. struct drm_encoder *encoder;
  9082. struct drm_connector *connector;
  9083. int count;
  9084. config->save_crtc_enabled =
  9085. kcalloc(dev->mode_config.num_crtc,
  9086. sizeof(bool), GFP_KERNEL);
  9087. if (!config->save_crtc_enabled)
  9088. return -ENOMEM;
  9089. config->save_encoder_crtcs =
  9090. kcalloc(dev->mode_config.num_encoder,
  9091. sizeof(struct drm_crtc *), GFP_KERNEL);
  9092. if (!config->save_encoder_crtcs)
  9093. return -ENOMEM;
  9094. config->save_connector_encoders =
  9095. kcalloc(dev->mode_config.num_connector,
  9096. sizeof(struct drm_encoder *), GFP_KERNEL);
  9097. if (!config->save_connector_encoders)
  9098. return -ENOMEM;
  9099. /* Copy data. Note that driver private data is not affected.
  9100. * Should anything bad happen only the expected state is
  9101. * restored, not the drivers personal bookkeeping.
  9102. */
  9103. count = 0;
  9104. for_each_crtc(dev, crtc) {
  9105. config->save_crtc_enabled[count++] = crtc->enabled;
  9106. }
  9107. count = 0;
  9108. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  9109. config->save_encoder_crtcs[count++] = encoder->crtc;
  9110. }
  9111. count = 0;
  9112. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  9113. config->save_connector_encoders[count++] = connector->encoder;
  9114. }
  9115. return 0;
  9116. }
  9117. static void intel_set_config_restore_state(struct drm_device *dev,
  9118. struct intel_set_config *config)
  9119. {
  9120. struct intel_crtc *crtc;
  9121. struct intel_encoder *encoder;
  9122. struct intel_connector *connector;
  9123. int count;
  9124. count = 0;
  9125. for_each_intel_crtc(dev, crtc) {
  9126. crtc->new_enabled = config->save_crtc_enabled[count++];
  9127. if (crtc->new_enabled)
  9128. crtc->new_config = &crtc->config;
  9129. else
  9130. crtc->new_config = NULL;
  9131. }
  9132. count = 0;
  9133. list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) {
  9134. encoder->new_crtc =
  9135. to_intel_crtc(config->save_encoder_crtcs[count++]);
  9136. }
  9137. count = 0;
  9138. list_for_each_entry(connector, &dev->mode_config.connector_list, base.head) {
  9139. connector->new_encoder =
  9140. to_intel_encoder(config->save_connector_encoders[count++]);
  9141. }
  9142. }
  9143. static bool
  9144. is_crtc_connector_off(struct drm_mode_set *set)
  9145. {
  9146. int i;
  9147. if (set->num_connectors == 0)
  9148. return false;
  9149. if (WARN_ON(set->connectors == NULL))
  9150. return false;
  9151. for (i = 0; i < set->num_connectors; i++)
  9152. if (set->connectors[i]->encoder &&
  9153. set->connectors[i]->encoder->crtc == set->crtc &&
  9154. set->connectors[i]->dpms != DRM_MODE_DPMS_ON)
  9155. return true;
  9156. return false;
  9157. }
  9158. static void
  9159. intel_set_config_compute_mode_changes(struct drm_mode_set *set,
  9160. struct intel_set_config *config)
  9161. {
  9162. /* We should be able to check here if the fb has the same properties
  9163. * and then just flip_or_move it */
  9164. if (is_crtc_connector_off(set)) {
  9165. config->mode_changed = true;
  9166. } else if (set->crtc->primary->fb != set->fb) {
  9167. /*
  9168. * If we have no fb, we can only flip as long as the crtc is
  9169. * active, otherwise we need a full mode set. The crtc may
  9170. * be active if we've only disabled the primary plane, or
  9171. * in fastboot situations.
  9172. */
  9173. if (set->crtc->primary->fb == NULL) {
  9174. struct intel_crtc *intel_crtc =
  9175. to_intel_crtc(set->crtc);
  9176. if (intel_crtc->active) {
  9177. DRM_DEBUG_KMS("crtc has no fb, will flip\n");
  9178. config->fb_changed = true;
  9179. } else {
  9180. DRM_DEBUG_KMS("inactive crtc, full mode set\n");
  9181. config->mode_changed = true;
  9182. }
  9183. } else if (set->fb == NULL) {
  9184. config->mode_changed = true;
  9185. } else if (set->fb->pixel_format !=
  9186. set->crtc->primary->fb->pixel_format) {
  9187. config->mode_changed = true;
  9188. } else {
  9189. config->fb_changed = true;
  9190. }
  9191. }
  9192. if (set->fb && (set->x != set->crtc->x || set->y != set->crtc->y))
  9193. config->fb_changed = true;
  9194. if (set->mode && !drm_mode_equal(set->mode, &set->crtc->mode)) {
  9195. DRM_DEBUG_KMS("modes are different, full mode set\n");
  9196. drm_mode_debug_printmodeline(&set->crtc->mode);
  9197. drm_mode_debug_printmodeline(set->mode);
  9198. config->mode_changed = true;
  9199. }
  9200. DRM_DEBUG_KMS("computed changes for [CRTC:%d], mode_changed=%d, fb_changed=%d\n",
  9201. set->crtc->base.id, config->mode_changed, config->fb_changed);
  9202. }
  9203. static int
  9204. intel_modeset_stage_output_state(struct drm_device *dev,
  9205. struct drm_mode_set *set,
  9206. struct intel_set_config *config)
  9207. {
  9208. struct intel_connector *connector;
  9209. struct intel_encoder *encoder;
  9210. struct intel_crtc *crtc;
  9211. int ro;
  9212. /* The upper layers ensure that we either disable a crtc or have a list
  9213. * of connectors. For paranoia, double-check this. */
  9214. WARN_ON(!set->fb && (set->num_connectors != 0));
  9215. WARN_ON(set->fb && (set->num_connectors == 0));
  9216. list_for_each_entry(connector, &dev->mode_config.connector_list,
  9217. base.head) {
  9218. /* Otherwise traverse passed in connector list and get encoders
  9219. * for them. */
  9220. for (ro = 0; ro < set->num_connectors; ro++) {
  9221. if (set->connectors[ro] == &connector->base) {
  9222. connector->new_encoder = connector->encoder;
  9223. break;
  9224. }
  9225. }
  9226. /* If we disable the crtc, disable all its connectors. Also, if
  9227. * the connector is on the changing crtc but not on the new
  9228. * connector list, disable it. */
  9229. if ((!set->fb || ro == set->num_connectors) &&
  9230. connector->base.encoder &&
  9231. connector->base.encoder->crtc == set->crtc) {
  9232. connector->new_encoder = NULL;
  9233. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n",
  9234. connector->base.base.id,
  9235. connector->base.name);
  9236. }
  9237. if (&connector->new_encoder->base != connector->base.encoder) {
  9238. DRM_DEBUG_KMS("encoder changed, full mode switch\n");
  9239. config->mode_changed = true;
  9240. }
  9241. }
  9242. /* connector->new_encoder is now updated for all connectors. */
  9243. /* Update crtc of enabled connectors. */
  9244. list_for_each_entry(connector, &dev->mode_config.connector_list,
  9245. base.head) {
  9246. struct drm_crtc *new_crtc;
  9247. if (!connector->new_encoder)
  9248. continue;
  9249. new_crtc = connector->new_encoder->base.crtc;
  9250. for (ro = 0; ro < set->num_connectors; ro++) {
  9251. if (set->connectors[ro] == &connector->base)
  9252. new_crtc = set->crtc;
  9253. }
  9254. /* Make sure the new CRTC will work with the encoder */
  9255. if (!drm_encoder_crtc_ok(&connector->new_encoder->base,
  9256. new_crtc)) {
  9257. return -EINVAL;
  9258. }
  9259. connector->encoder->new_crtc = to_intel_crtc(new_crtc);
  9260. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n",
  9261. connector->base.base.id,
  9262. connector->base.name,
  9263. new_crtc->base.id);
  9264. }
  9265. /* Check for any encoders that needs to be disabled. */
  9266. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  9267. base.head) {
  9268. int num_connectors = 0;
  9269. list_for_each_entry(connector,
  9270. &dev->mode_config.connector_list,
  9271. base.head) {
  9272. if (connector->new_encoder == encoder) {
  9273. WARN_ON(!connector->new_encoder->new_crtc);
  9274. num_connectors++;
  9275. }
  9276. }
  9277. if (num_connectors == 0)
  9278. encoder->new_crtc = NULL;
  9279. else if (num_connectors > 1)
  9280. return -EINVAL;
  9281. /* Only now check for crtc changes so we don't miss encoders
  9282. * that will be disabled. */
  9283. if (&encoder->new_crtc->base != encoder->base.crtc) {
  9284. DRM_DEBUG_KMS("crtc changed, full mode switch\n");
  9285. config->mode_changed = true;
  9286. }
  9287. }
  9288. /* Now we've also updated encoder->new_crtc for all encoders. */
  9289. for_each_intel_crtc(dev, crtc) {
  9290. crtc->new_enabled = false;
  9291. list_for_each_entry(encoder,
  9292. &dev->mode_config.encoder_list,
  9293. base.head) {
  9294. if (encoder->new_crtc == crtc) {
  9295. crtc->new_enabled = true;
  9296. break;
  9297. }
  9298. }
  9299. if (crtc->new_enabled != crtc->base.enabled) {
  9300. DRM_DEBUG_KMS("crtc %sabled, full mode switch\n",
  9301. crtc->new_enabled ? "en" : "dis");
  9302. config->mode_changed = true;
  9303. }
  9304. if (crtc->new_enabled)
  9305. crtc->new_config = &crtc->config;
  9306. else
  9307. crtc->new_config = NULL;
  9308. }
  9309. return 0;
  9310. }
  9311. static void disable_crtc_nofb(struct intel_crtc *crtc)
  9312. {
  9313. struct drm_device *dev = crtc->base.dev;
  9314. struct intel_encoder *encoder;
  9315. struct intel_connector *connector;
  9316. DRM_DEBUG_KMS("Trying to restore without FB -> disabling pipe %c\n",
  9317. pipe_name(crtc->pipe));
  9318. list_for_each_entry(connector, &dev->mode_config.connector_list, base.head) {
  9319. if (connector->new_encoder &&
  9320. connector->new_encoder->new_crtc == crtc)
  9321. connector->new_encoder = NULL;
  9322. }
  9323. list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) {
  9324. if (encoder->new_crtc == crtc)
  9325. encoder->new_crtc = NULL;
  9326. }
  9327. crtc->new_enabled = false;
  9328. crtc->new_config = NULL;
  9329. }
  9330. static int intel_crtc_set_config(struct drm_mode_set *set)
  9331. {
  9332. struct drm_device *dev;
  9333. struct drm_mode_set save_set;
  9334. struct intel_set_config *config;
  9335. int ret;
  9336. BUG_ON(!set);
  9337. BUG_ON(!set->crtc);
  9338. BUG_ON(!set->crtc->helper_private);
  9339. /* Enforce sane interface api - has been abused by the fb helper. */
  9340. BUG_ON(!set->mode && set->fb);
  9341. BUG_ON(set->fb && set->num_connectors == 0);
  9342. if (set->fb) {
  9343. DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n",
  9344. set->crtc->base.id, set->fb->base.id,
  9345. (int)set->num_connectors, set->x, set->y);
  9346. } else {
  9347. DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set->crtc->base.id);
  9348. }
  9349. dev = set->crtc->dev;
  9350. ret = -ENOMEM;
  9351. config = kzalloc(sizeof(*config), GFP_KERNEL);
  9352. if (!config)
  9353. goto out_config;
  9354. ret = intel_set_config_save_state(dev, config);
  9355. if (ret)
  9356. goto out_config;
  9357. save_set.crtc = set->crtc;
  9358. save_set.mode = &set->crtc->mode;
  9359. save_set.x = set->crtc->x;
  9360. save_set.y = set->crtc->y;
  9361. save_set.fb = set->crtc->primary->fb;
  9362. /* Compute whether we need a full modeset, only an fb base update or no
  9363. * change at all. In the future we might also check whether only the
  9364. * mode changed, e.g. for LVDS where we only change the panel fitter in
  9365. * such cases. */
  9366. intel_set_config_compute_mode_changes(set, config);
  9367. ret = intel_modeset_stage_output_state(dev, set, config);
  9368. if (ret)
  9369. goto fail;
  9370. if (config->mode_changed) {
  9371. ret = intel_set_mode(set->crtc, set->mode,
  9372. set->x, set->y, set->fb);
  9373. } else if (config->fb_changed) {
  9374. struct drm_i915_private *dev_priv = dev->dev_private;
  9375. struct intel_crtc *intel_crtc = to_intel_crtc(set->crtc);
  9376. intel_crtc_wait_for_pending_flips(set->crtc);
  9377. ret = intel_pipe_set_base(set->crtc,
  9378. set->x, set->y, set->fb);
  9379. /*
  9380. * We need to make sure the primary plane is re-enabled if it
  9381. * has previously been turned off.
  9382. */
  9383. if (!intel_crtc->primary_enabled && ret == 0) {
  9384. WARN_ON(!intel_crtc->active);
  9385. intel_enable_primary_hw_plane(dev_priv, intel_crtc->plane,
  9386. intel_crtc->pipe);
  9387. }
  9388. /*
  9389. * In the fastboot case this may be our only check of the
  9390. * state after boot. It would be better to only do it on
  9391. * the first update, but we don't have a nice way of doing that
  9392. * (and really, set_config isn't used much for high freq page
  9393. * flipping, so increasing its cost here shouldn't be a big
  9394. * deal).
  9395. */
  9396. if (i915.fastboot && ret == 0)
  9397. intel_modeset_check_state(set->crtc->dev);
  9398. }
  9399. if (ret) {
  9400. DRM_DEBUG_KMS("failed to set mode on [CRTC:%d], err = %d\n",
  9401. set->crtc->base.id, ret);
  9402. fail:
  9403. intel_set_config_restore_state(dev, config);
  9404. /*
  9405. * HACK: if the pipe was on, but we didn't have a framebuffer,
  9406. * force the pipe off to avoid oopsing in the modeset code
  9407. * due to fb==NULL. This should only happen during boot since
  9408. * we don't yet reconstruct the FB from the hardware state.
  9409. */
  9410. if (to_intel_crtc(save_set.crtc)->new_enabled && !save_set.fb)
  9411. disable_crtc_nofb(to_intel_crtc(save_set.crtc));
  9412. /* Try to restore the config */
  9413. if (config->mode_changed &&
  9414. intel_set_mode(save_set.crtc, save_set.mode,
  9415. save_set.x, save_set.y, save_set.fb))
  9416. DRM_ERROR("failed to restore config after modeset failure\n");
  9417. }
  9418. out_config:
  9419. intel_set_config_free(config);
  9420. return ret;
  9421. }
  9422. static const struct drm_crtc_funcs intel_crtc_funcs = {
  9423. .gamma_set = intel_crtc_gamma_set,
  9424. .set_config = intel_crtc_set_config,
  9425. .destroy = intel_crtc_destroy,
  9426. .page_flip = intel_crtc_page_flip,
  9427. };
  9428. static void intel_cpu_pll_init(struct drm_device *dev)
  9429. {
  9430. if (HAS_DDI(dev))
  9431. intel_ddi_pll_init(dev);
  9432. }
  9433. static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private *dev_priv,
  9434. struct intel_shared_dpll *pll,
  9435. struct intel_dpll_hw_state *hw_state)
  9436. {
  9437. uint32_t val;
  9438. val = I915_READ(PCH_DPLL(pll->id));
  9439. hw_state->dpll = val;
  9440. hw_state->fp0 = I915_READ(PCH_FP0(pll->id));
  9441. hw_state->fp1 = I915_READ(PCH_FP1(pll->id));
  9442. return val & DPLL_VCO_ENABLE;
  9443. }
  9444. static void ibx_pch_dpll_mode_set(struct drm_i915_private *dev_priv,
  9445. struct intel_shared_dpll *pll)
  9446. {
  9447. I915_WRITE(PCH_FP0(pll->id), pll->hw_state.fp0);
  9448. I915_WRITE(PCH_FP1(pll->id), pll->hw_state.fp1);
  9449. }
  9450. static void ibx_pch_dpll_enable(struct drm_i915_private *dev_priv,
  9451. struct intel_shared_dpll *pll)
  9452. {
  9453. /* PCH refclock must be enabled first */
  9454. ibx_assert_pch_refclk_enabled(dev_priv);
  9455. I915_WRITE(PCH_DPLL(pll->id), pll->hw_state.dpll);
  9456. /* Wait for the clocks to stabilize. */
  9457. POSTING_READ(PCH_DPLL(pll->id));
  9458. udelay(150);
  9459. /* The pixel multiplier can only be updated once the
  9460. * DPLL is enabled and the clocks are stable.
  9461. *
  9462. * So write it again.
  9463. */
  9464. I915_WRITE(PCH_DPLL(pll->id), pll->hw_state.dpll);
  9465. POSTING_READ(PCH_DPLL(pll->id));
  9466. udelay(200);
  9467. }
  9468. static void ibx_pch_dpll_disable(struct drm_i915_private *dev_priv,
  9469. struct intel_shared_dpll *pll)
  9470. {
  9471. struct drm_device *dev = dev_priv->dev;
  9472. struct intel_crtc *crtc;
  9473. /* Make sure no transcoder isn't still depending on us. */
  9474. for_each_intel_crtc(dev, crtc) {
  9475. if (intel_crtc_to_shared_dpll(crtc) == pll)
  9476. assert_pch_transcoder_disabled(dev_priv, crtc->pipe);
  9477. }
  9478. I915_WRITE(PCH_DPLL(pll->id), 0);
  9479. POSTING_READ(PCH_DPLL(pll->id));
  9480. udelay(200);
  9481. }
  9482. static char *ibx_pch_dpll_names[] = {
  9483. "PCH DPLL A",
  9484. "PCH DPLL B",
  9485. };
  9486. static void ibx_pch_dpll_init(struct drm_device *dev)
  9487. {
  9488. struct drm_i915_private *dev_priv = dev->dev_private;
  9489. int i;
  9490. dev_priv->num_shared_dpll = 2;
  9491. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  9492. dev_priv->shared_dplls[i].id = i;
  9493. dev_priv->shared_dplls[i].name = ibx_pch_dpll_names[i];
  9494. dev_priv->shared_dplls[i].mode_set = ibx_pch_dpll_mode_set;
  9495. dev_priv->shared_dplls[i].enable = ibx_pch_dpll_enable;
  9496. dev_priv->shared_dplls[i].disable = ibx_pch_dpll_disable;
  9497. dev_priv->shared_dplls[i].get_hw_state =
  9498. ibx_pch_dpll_get_hw_state;
  9499. }
  9500. }
  9501. static void intel_shared_dpll_init(struct drm_device *dev)
  9502. {
  9503. struct drm_i915_private *dev_priv = dev->dev_private;
  9504. if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
  9505. ibx_pch_dpll_init(dev);
  9506. else
  9507. dev_priv->num_shared_dpll = 0;
  9508. BUG_ON(dev_priv->num_shared_dpll > I915_NUM_PLLS);
  9509. }
  9510. static int
  9511. intel_primary_plane_disable(struct drm_plane *plane)
  9512. {
  9513. struct drm_device *dev = plane->dev;
  9514. struct drm_i915_private *dev_priv = dev->dev_private;
  9515. struct intel_plane *intel_plane = to_intel_plane(plane);
  9516. struct intel_crtc *intel_crtc;
  9517. if (!plane->fb)
  9518. return 0;
  9519. BUG_ON(!plane->crtc);
  9520. intel_crtc = to_intel_crtc(plane->crtc);
  9521. /*
  9522. * Even though we checked plane->fb above, it's still possible that
  9523. * the primary plane has been implicitly disabled because the crtc
  9524. * coordinates given weren't visible, or because we detected
  9525. * that it was 100% covered by a sprite plane. Or, the CRTC may be
  9526. * off and we've set a fb, but haven't actually turned on the CRTC yet.
  9527. * In either case, we need to unpin the FB and let the fb pointer get
  9528. * updated, but otherwise we don't need to touch the hardware.
  9529. */
  9530. if (!intel_crtc->primary_enabled)
  9531. goto disable_unpin;
  9532. intel_crtc_wait_for_pending_flips(plane->crtc);
  9533. intel_disable_primary_hw_plane(dev_priv, intel_plane->plane,
  9534. intel_plane->pipe);
  9535. disable_unpin:
  9536. mutex_lock(&dev->struct_mutex);
  9537. i915_gem_track_fb(intel_fb_obj(plane->fb), NULL,
  9538. INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe));
  9539. intel_unpin_fb_obj(intel_fb_obj(plane->fb));
  9540. mutex_unlock(&dev->struct_mutex);
  9541. plane->fb = NULL;
  9542. return 0;
  9543. }
  9544. static int
  9545. intel_primary_plane_setplane(struct drm_plane *plane, struct drm_crtc *crtc,
  9546. struct drm_framebuffer *fb, int crtc_x, int crtc_y,
  9547. unsigned int crtc_w, unsigned int crtc_h,
  9548. uint32_t src_x, uint32_t src_y,
  9549. uint32_t src_w, uint32_t src_h)
  9550. {
  9551. struct drm_device *dev = crtc->dev;
  9552. struct drm_i915_private *dev_priv = dev->dev_private;
  9553. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  9554. struct intel_plane *intel_plane = to_intel_plane(plane);
  9555. struct drm_i915_gem_object *obj = intel_fb_obj(fb);
  9556. struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->fb);
  9557. struct drm_rect dest = {
  9558. /* integer pixels */
  9559. .x1 = crtc_x,
  9560. .y1 = crtc_y,
  9561. .x2 = crtc_x + crtc_w,
  9562. .y2 = crtc_y + crtc_h,
  9563. };
  9564. struct drm_rect src = {
  9565. /* 16.16 fixed point */
  9566. .x1 = src_x,
  9567. .y1 = src_y,
  9568. .x2 = src_x + src_w,
  9569. .y2 = src_y + src_h,
  9570. };
  9571. const struct drm_rect clip = {
  9572. /* integer pixels */
  9573. .x2 = intel_crtc->active ? intel_crtc->config.pipe_src_w : 0,
  9574. .y2 = intel_crtc->active ? intel_crtc->config.pipe_src_h : 0,
  9575. };
  9576. bool visible;
  9577. int ret;
  9578. ret = drm_plane_helper_check_update(plane, crtc, fb,
  9579. &src, &dest, &clip,
  9580. DRM_PLANE_HELPER_NO_SCALING,
  9581. DRM_PLANE_HELPER_NO_SCALING,
  9582. false, true, &visible);
  9583. if (ret)
  9584. return ret;
  9585. /*
  9586. * If the CRTC isn't enabled, we're just pinning the framebuffer,
  9587. * updating the fb pointer, and returning without touching the
  9588. * hardware. This allows us to later do a drmModeSetCrtc with fb=-1 to
  9589. * turn on the display with all planes setup as desired.
  9590. */
  9591. if (!crtc->enabled) {
  9592. mutex_lock(&dev->struct_mutex);
  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. ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
  9603. mutex_unlock(&dev->struct_mutex);
  9604. return ret;
  9605. }
  9606. intel_crtc_wait_for_pending_flips(crtc);
  9607. /*
  9608. * If clipping results in a non-visible primary plane, we'll disable
  9609. * the primary plane. Note that this is a bit different than what
  9610. * happens if userspace explicitly disables the plane by passing fb=0
  9611. * because plane->fb still gets set and pinned.
  9612. */
  9613. if (!visible) {
  9614. mutex_lock(&dev->struct_mutex);
  9615. /*
  9616. * Try to pin the new fb first so that we can bail out if we
  9617. * fail.
  9618. */
  9619. if (plane->fb != fb) {
  9620. ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
  9621. if (ret) {
  9622. mutex_unlock(&dev->struct_mutex);
  9623. return ret;
  9624. }
  9625. }
  9626. i915_gem_track_fb(old_obj, obj,
  9627. INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe));
  9628. if (intel_crtc->primary_enabled)
  9629. intel_disable_primary_hw_plane(dev_priv,
  9630. intel_plane->plane,
  9631. intel_plane->pipe);
  9632. if (plane->fb != fb)
  9633. if (plane->fb)
  9634. intel_unpin_fb_obj(old_obj);
  9635. mutex_unlock(&dev->struct_mutex);
  9636. return 0;
  9637. }
  9638. ret = intel_pipe_set_base(crtc, src.x1, src.y1, fb);
  9639. if (ret)
  9640. return ret;
  9641. if (!intel_crtc->primary_enabled)
  9642. intel_enable_primary_hw_plane(dev_priv, intel_crtc->plane,
  9643. intel_crtc->pipe);
  9644. return 0;
  9645. }
  9646. /* Common destruction function for both primary and cursor planes */
  9647. static void intel_plane_destroy(struct drm_plane *plane)
  9648. {
  9649. struct intel_plane *intel_plane = to_intel_plane(plane);
  9650. drm_plane_cleanup(plane);
  9651. kfree(intel_plane);
  9652. }
  9653. static const struct drm_plane_funcs intel_primary_plane_funcs = {
  9654. .update_plane = intel_primary_plane_setplane,
  9655. .disable_plane = intel_primary_plane_disable,
  9656. .destroy = intel_plane_destroy,
  9657. };
  9658. static struct drm_plane *intel_primary_plane_create(struct drm_device *dev,
  9659. int pipe)
  9660. {
  9661. struct intel_plane *primary;
  9662. const uint32_t *intel_primary_formats;
  9663. int num_formats;
  9664. primary = kzalloc(sizeof(*primary), GFP_KERNEL);
  9665. if (primary == NULL)
  9666. return NULL;
  9667. primary->can_scale = false;
  9668. primary->max_downscale = 1;
  9669. primary->pipe = pipe;
  9670. primary->plane = pipe;
  9671. if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4)
  9672. primary->plane = !pipe;
  9673. if (INTEL_INFO(dev)->gen <= 3) {
  9674. intel_primary_formats = intel_primary_formats_gen2;
  9675. num_formats = ARRAY_SIZE(intel_primary_formats_gen2);
  9676. } else {
  9677. intel_primary_formats = intel_primary_formats_gen4;
  9678. num_formats = ARRAY_SIZE(intel_primary_formats_gen4);
  9679. }
  9680. drm_universal_plane_init(dev, &primary->base, 0,
  9681. &intel_primary_plane_funcs,
  9682. intel_primary_formats, num_formats,
  9683. DRM_PLANE_TYPE_PRIMARY);
  9684. return &primary->base;
  9685. }
  9686. static int
  9687. intel_cursor_plane_disable(struct drm_plane *plane)
  9688. {
  9689. if (!plane->fb)
  9690. return 0;
  9691. BUG_ON(!plane->crtc);
  9692. return intel_crtc_cursor_set_obj(plane->crtc, NULL, 0, 0);
  9693. }
  9694. static int
  9695. intel_cursor_plane_update(struct drm_plane *plane, struct drm_crtc *crtc,
  9696. struct drm_framebuffer *fb, int crtc_x, int crtc_y,
  9697. unsigned int crtc_w, unsigned int crtc_h,
  9698. uint32_t src_x, uint32_t src_y,
  9699. uint32_t src_w, uint32_t src_h)
  9700. {
  9701. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  9702. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  9703. struct drm_i915_gem_object *obj = intel_fb->obj;
  9704. struct drm_rect dest = {
  9705. /* integer pixels */
  9706. .x1 = crtc_x,
  9707. .y1 = crtc_y,
  9708. .x2 = crtc_x + crtc_w,
  9709. .y2 = crtc_y + crtc_h,
  9710. };
  9711. struct drm_rect src = {
  9712. /* 16.16 fixed point */
  9713. .x1 = src_x,
  9714. .y1 = src_y,
  9715. .x2 = src_x + src_w,
  9716. .y2 = src_y + src_h,
  9717. };
  9718. const struct drm_rect clip = {
  9719. /* integer pixels */
  9720. .x2 = intel_crtc->config.pipe_src_w,
  9721. .y2 = intel_crtc->config.pipe_src_h,
  9722. };
  9723. bool visible;
  9724. int ret;
  9725. ret = drm_plane_helper_check_update(plane, crtc, fb,
  9726. &src, &dest, &clip,
  9727. DRM_PLANE_HELPER_NO_SCALING,
  9728. DRM_PLANE_HELPER_NO_SCALING,
  9729. true, true, &visible);
  9730. if (ret)
  9731. return ret;
  9732. crtc->cursor_x = crtc_x;
  9733. crtc->cursor_y = crtc_y;
  9734. if (fb != crtc->cursor->fb) {
  9735. return intel_crtc_cursor_set_obj(crtc, obj, crtc_w, crtc_h);
  9736. } else {
  9737. intel_crtc_update_cursor(crtc, visible);
  9738. return 0;
  9739. }
  9740. }
  9741. static const struct drm_plane_funcs intel_cursor_plane_funcs = {
  9742. .update_plane = intel_cursor_plane_update,
  9743. .disable_plane = intel_cursor_plane_disable,
  9744. .destroy = intel_plane_destroy,
  9745. };
  9746. static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev,
  9747. int pipe)
  9748. {
  9749. struct intel_plane *cursor;
  9750. cursor = kzalloc(sizeof(*cursor), GFP_KERNEL);
  9751. if (cursor == NULL)
  9752. return NULL;
  9753. cursor->can_scale = false;
  9754. cursor->max_downscale = 1;
  9755. cursor->pipe = pipe;
  9756. cursor->plane = pipe;
  9757. drm_universal_plane_init(dev, &cursor->base, 0,
  9758. &intel_cursor_plane_funcs,
  9759. intel_cursor_formats,
  9760. ARRAY_SIZE(intel_cursor_formats),
  9761. DRM_PLANE_TYPE_CURSOR);
  9762. return &cursor->base;
  9763. }
  9764. static void intel_crtc_init(struct drm_device *dev, int pipe)
  9765. {
  9766. struct drm_i915_private *dev_priv = dev->dev_private;
  9767. struct intel_crtc *intel_crtc;
  9768. struct drm_plane *primary = NULL;
  9769. struct drm_plane *cursor = NULL;
  9770. int i, ret;
  9771. intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL);
  9772. if (intel_crtc == NULL)
  9773. return;
  9774. primary = intel_primary_plane_create(dev, pipe);
  9775. if (!primary)
  9776. goto fail;
  9777. cursor = intel_cursor_plane_create(dev, pipe);
  9778. if (!cursor)
  9779. goto fail;
  9780. ret = drm_crtc_init_with_planes(dev, &intel_crtc->base, primary,
  9781. cursor, &intel_crtc_funcs);
  9782. if (ret)
  9783. goto fail;
  9784. drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256);
  9785. for (i = 0; i < 256; i++) {
  9786. intel_crtc->lut_r[i] = i;
  9787. intel_crtc->lut_g[i] = i;
  9788. intel_crtc->lut_b[i] = i;
  9789. }
  9790. /*
  9791. * On gen2/3 only plane A can do fbc, but the panel fitter and lvds port
  9792. * is hooked to pipe B. Hence we want plane A feeding pipe B.
  9793. */
  9794. intel_crtc->pipe = pipe;
  9795. intel_crtc->plane = pipe;
  9796. if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) {
  9797. DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
  9798. intel_crtc->plane = !pipe;
  9799. }
  9800. intel_crtc->cursor_base = ~0;
  9801. intel_crtc->cursor_cntl = ~0;
  9802. init_waitqueue_head(&intel_crtc->vbl_wait);
  9803. BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
  9804. dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL);
  9805. dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base;
  9806. dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base;
  9807. drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
  9808. WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe);
  9809. return;
  9810. fail:
  9811. if (primary)
  9812. drm_plane_cleanup(primary);
  9813. if (cursor)
  9814. drm_plane_cleanup(cursor);
  9815. kfree(intel_crtc);
  9816. }
  9817. enum pipe intel_get_pipe_from_connector(struct intel_connector *connector)
  9818. {
  9819. struct drm_encoder *encoder = connector->base.encoder;
  9820. struct drm_device *dev = connector->base.dev;
  9821. WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
  9822. if (!encoder)
  9823. return INVALID_PIPE;
  9824. return to_intel_crtc(encoder->crtc)->pipe;
  9825. }
  9826. int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data,
  9827. struct drm_file *file)
  9828. {
  9829. struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
  9830. struct drm_mode_object *drmmode_obj;
  9831. struct intel_crtc *crtc;
  9832. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  9833. return -ENODEV;
  9834. drmmode_obj = drm_mode_object_find(dev, pipe_from_crtc_id->crtc_id,
  9835. DRM_MODE_OBJECT_CRTC);
  9836. if (!drmmode_obj) {
  9837. DRM_ERROR("no such CRTC id\n");
  9838. return -ENOENT;
  9839. }
  9840. crtc = to_intel_crtc(obj_to_crtc(drmmode_obj));
  9841. pipe_from_crtc_id->pipe = crtc->pipe;
  9842. return 0;
  9843. }
  9844. static int intel_encoder_clones(struct intel_encoder *encoder)
  9845. {
  9846. struct drm_device *dev = encoder->base.dev;
  9847. struct intel_encoder *source_encoder;
  9848. int index_mask = 0;
  9849. int entry = 0;
  9850. list_for_each_entry(source_encoder,
  9851. &dev->mode_config.encoder_list, base.head) {
  9852. if (encoders_cloneable(encoder, source_encoder))
  9853. index_mask |= (1 << entry);
  9854. entry++;
  9855. }
  9856. return index_mask;
  9857. }
  9858. static bool has_edp_a(struct drm_device *dev)
  9859. {
  9860. struct drm_i915_private *dev_priv = dev->dev_private;
  9861. if (!IS_MOBILE(dev))
  9862. return false;
  9863. if ((I915_READ(DP_A) & DP_DETECTED) == 0)
  9864. return false;
  9865. if (IS_GEN5(dev) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE))
  9866. return false;
  9867. return true;
  9868. }
  9869. const char *intel_output_name(int output)
  9870. {
  9871. static const char *names[] = {
  9872. [INTEL_OUTPUT_UNUSED] = "Unused",
  9873. [INTEL_OUTPUT_ANALOG] = "Analog",
  9874. [INTEL_OUTPUT_DVO] = "DVO",
  9875. [INTEL_OUTPUT_SDVO] = "SDVO",
  9876. [INTEL_OUTPUT_LVDS] = "LVDS",
  9877. [INTEL_OUTPUT_TVOUT] = "TV",
  9878. [INTEL_OUTPUT_HDMI] = "HDMI",
  9879. [INTEL_OUTPUT_DISPLAYPORT] = "DisplayPort",
  9880. [INTEL_OUTPUT_EDP] = "eDP",
  9881. [INTEL_OUTPUT_DSI] = "DSI",
  9882. [INTEL_OUTPUT_UNKNOWN] = "Unknown",
  9883. };
  9884. if (output < 0 || output >= ARRAY_SIZE(names) || !names[output])
  9885. return "Invalid";
  9886. return names[output];
  9887. }
  9888. static bool intel_crt_present(struct drm_device *dev)
  9889. {
  9890. struct drm_i915_private *dev_priv = dev->dev_private;
  9891. if (IS_ULT(dev))
  9892. return false;
  9893. if (IS_CHERRYVIEW(dev))
  9894. return false;
  9895. if (IS_VALLEYVIEW(dev) && !dev_priv->vbt.int_crt_support)
  9896. return false;
  9897. return true;
  9898. }
  9899. static void intel_setup_outputs(struct drm_device *dev)
  9900. {
  9901. struct drm_i915_private *dev_priv = dev->dev_private;
  9902. struct intel_encoder *encoder;
  9903. bool dpd_is_edp = false;
  9904. intel_lvds_init(dev);
  9905. if (intel_crt_present(dev))
  9906. intel_crt_init(dev);
  9907. if (HAS_DDI(dev)) {
  9908. int found;
  9909. /* Haswell uses DDI functions to detect digital outputs */
  9910. found = I915_READ(DDI_BUF_CTL_A) & DDI_INIT_DISPLAY_DETECTED;
  9911. /* DDI A only supports eDP */
  9912. if (found)
  9913. intel_ddi_init(dev, PORT_A);
  9914. /* DDI B, C and D detection is indicated by the SFUSE_STRAP
  9915. * register */
  9916. found = I915_READ(SFUSE_STRAP);
  9917. if (found & SFUSE_STRAP_DDIB_DETECTED)
  9918. intel_ddi_init(dev, PORT_B);
  9919. if (found & SFUSE_STRAP_DDIC_DETECTED)
  9920. intel_ddi_init(dev, PORT_C);
  9921. if (found & SFUSE_STRAP_DDID_DETECTED)
  9922. intel_ddi_init(dev, PORT_D);
  9923. } else if (HAS_PCH_SPLIT(dev)) {
  9924. int found;
  9925. dpd_is_edp = intel_dp_is_edp(dev, PORT_D);
  9926. if (has_edp_a(dev))
  9927. intel_dp_init(dev, DP_A, PORT_A);
  9928. if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) {
  9929. /* PCH SDVOB multiplex with HDMIB */
  9930. found = intel_sdvo_init(dev, PCH_SDVOB, true);
  9931. if (!found)
  9932. intel_hdmi_init(dev, PCH_HDMIB, PORT_B);
  9933. if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
  9934. intel_dp_init(dev, PCH_DP_B, PORT_B);
  9935. }
  9936. if (I915_READ(PCH_HDMIC) & SDVO_DETECTED)
  9937. intel_hdmi_init(dev, PCH_HDMIC, PORT_C);
  9938. if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED)
  9939. intel_hdmi_init(dev, PCH_HDMID, PORT_D);
  9940. if (I915_READ(PCH_DP_C) & DP_DETECTED)
  9941. intel_dp_init(dev, PCH_DP_C, PORT_C);
  9942. if (I915_READ(PCH_DP_D) & DP_DETECTED)
  9943. intel_dp_init(dev, PCH_DP_D, PORT_D);
  9944. } else if (IS_VALLEYVIEW(dev)) {
  9945. if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIB) & SDVO_DETECTED) {
  9946. intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIB,
  9947. PORT_B);
  9948. if (I915_READ(VLV_DISPLAY_BASE + DP_B) & DP_DETECTED)
  9949. intel_dp_init(dev, VLV_DISPLAY_BASE + DP_B, PORT_B);
  9950. }
  9951. if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIC) & SDVO_DETECTED) {
  9952. intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIC,
  9953. PORT_C);
  9954. if (I915_READ(VLV_DISPLAY_BASE + DP_C) & DP_DETECTED)
  9955. intel_dp_init(dev, VLV_DISPLAY_BASE + DP_C, PORT_C);
  9956. }
  9957. if (IS_CHERRYVIEW(dev)) {
  9958. if (I915_READ(VLV_DISPLAY_BASE + CHV_HDMID) & SDVO_DETECTED) {
  9959. intel_hdmi_init(dev, VLV_DISPLAY_BASE + CHV_HDMID,
  9960. PORT_D);
  9961. if (I915_READ(VLV_DISPLAY_BASE + DP_D) & DP_DETECTED)
  9962. intel_dp_init(dev, VLV_DISPLAY_BASE + DP_D, PORT_D);
  9963. }
  9964. }
  9965. intel_dsi_init(dev);
  9966. } else if (SUPPORTS_DIGITAL_OUTPUTS(dev)) {
  9967. bool found = false;
  9968. if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
  9969. DRM_DEBUG_KMS("probing SDVOB\n");
  9970. found = intel_sdvo_init(dev, GEN3_SDVOB, true);
  9971. if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) {
  9972. DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
  9973. intel_hdmi_init(dev, GEN4_HDMIB, PORT_B);
  9974. }
  9975. if (!found && SUPPORTS_INTEGRATED_DP(dev))
  9976. intel_dp_init(dev, DP_B, PORT_B);
  9977. }
  9978. /* Before G4X SDVOC doesn't have its own detect register */
  9979. if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
  9980. DRM_DEBUG_KMS("probing SDVOC\n");
  9981. found = intel_sdvo_init(dev, GEN3_SDVOC, false);
  9982. }
  9983. if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) {
  9984. if (SUPPORTS_INTEGRATED_HDMI(dev)) {
  9985. DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
  9986. intel_hdmi_init(dev, GEN4_HDMIC, PORT_C);
  9987. }
  9988. if (SUPPORTS_INTEGRATED_DP(dev))
  9989. intel_dp_init(dev, DP_C, PORT_C);
  9990. }
  9991. if (SUPPORTS_INTEGRATED_DP(dev) &&
  9992. (I915_READ(DP_D) & DP_DETECTED))
  9993. intel_dp_init(dev, DP_D, PORT_D);
  9994. } else if (IS_GEN2(dev))
  9995. intel_dvo_init(dev);
  9996. if (SUPPORTS_TV(dev))
  9997. intel_tv_init(dev);
  9998. intel_edp_psr_init(dev);
  9999. list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) {
  10000. encoder->base.possible_crtcs = encoder->crtc_mask;
  10001. encoder->base.possible_clones =
  10002. intel_encoder_clones(encoder);
  10003. }
  10004. intel_init_pch_refclk(dev);
  10005. drm_helper_move_panel_connectors_to_head(dev);
  10006. }
  10007. static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
  10008. {
  10009. struct drm_device *dev = fb->dev;
  10010. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  10011. drm_framebuffer_cleanup(fb);
  10012. mutex_lock(&dev->struct_mutex);
  10013. WARN_ON(!intel_fb->obj->framebuffer_references--);
  10014. drm_gem_object_unreference(&intel_fb->obj->base);
  10015. mutex_unlock(&dev->struct_mutex);
  10016. kfree(intel_fb);
  10017. }
  10018. static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
  10019. struct drm_file *file,
  10020. unsigned int *handle)
  10021. {
  10022. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  10023. struct drm_i915_gem_object *obj = intel_fb->obj;
  10024. return drm_gem_handle_create(file, &obj->base, handle);
  10025. }
  10026. static const struct drm_framebuffer_funcs intel_fb_funcs = {
  10027. .destroy = intel_user_framebuffer_destroy,
  10028. .create_handle = intel_user_framebuffer_create_handle,
  10029. };
  10030. static int intel_framebuffer_init(struct drm_device *dev,
  10031. struct intel_framebuffer *intel_fb,
  10032. struct drm_mode_fb_cmd2 *mode_cmd,
  10033. struct drm_i915_gem_object *obj)
  10034. {
  10035. int aligned_height;
  10036. int pitch_limit;
  10037. int ret;
  10038. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  10039. if (obj->tiling_mode == I915_TILING_Y) {
  10040. DRM_DEBUG("hardware does not support tiling Y\n");
  10041. return -EINVAL;
  10042. }
  10043. if (mode_cmd->pitches[0] & 63) {
  10044. DRM_DEBUG("pitch (%d) must be at least 64 byte aligned\n",
  10045. mode_cmd->pitches[0]);
  10046. return -EINVAL;
  10047. }
  10048. if (INTEL_INFO(dev)->gen >= 5 && !IS_VALLEYVIEW(dev)) {
  10049. pitch_limit = 32*1024;
  10050. } else if (INTEL_INFO(dev)->gen >= 4) {
  10051. if (obj->tiling_mode)
  10052. pitch_limit = 16*1024;
  10053. else
  10054. pitch_limit = 32*1024;
  10055. } else if (INTEL_INFO(dev)->gen >= 3) {
  10056. if (obj->tiling_mode)
  10057. pitch_limit = 8*1024;
  10058. else
  10059. pitch_limit = 16*1024;
  10060. } else
  10061. /* XXX DSPC is limited to 4k tiled */
  10062. pitch_limit = 8*1024;
  10063. if (mode_cmd->pitches[0] > pitch_limit) {
  10064. DRM_DEBUG("%s pitch (%d) must be at less than %d\n",
  10065. obj->tiling_mode ? "tiled" : "linear",
  10066. mode_cmd->pitches[0], pitch_limit);
  10067. return -EINVAL;
  10068. }
  10069. if (obj->tiling_mode != I915_TILING_NONE &&
  10070. mode_cmd->pitches[0] != obj->stride) {
  10071. DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n",
  10072. mode_cmd->pitches[0], obj->stride);
  10073. return -EINVAL;
  10074. }
  10075. /* Reject formats not supported by any plane early. */
  10076. switch (mode_cmd->pixel_format) {
  10077. case DRM_FORMAT_C8:
  10078. case DRM_FORMAT_RGB565:
  10079. case DRM_FORMAT_XRGB8888:
  10080. case DRM_FORMAT_ARGB8888:
  10081. break;
  10082. case DRM_FORMAT_XRGB1555:
  10083. case DRM_FORMAT_ARGB1555:
  10084. if (INTEL_INFO(dev)->gen > 3) {
  10085. DRM_DEBUG("unsupported pixel format: %s\n",
  10086. drm_get_format_name(mode_cmd->pixel_format));
  10087. return -EINVAL;
  10088. }
  10089. break;
  10090. case DRM_FORMAT_XBGR8888:
  10091. case DRM_FORMAT_ABGR8888:
  10092. case DRM_FORMAT_XRGB2101010:
  10093. case DRM_FORMAT_ARGB2101010:
  10094. case DRM_FORMAT_XBGR2101010:
  10095. case DRM_FORMAT_ABGR2101010:
  10096. if (INTEL_INFO(dev)->gen < 4) {
  10097. DRM_DEBUG("unsupported pixel format: %s\n",
  10098. drm_get_format_name(mode_cmd->pixel_format));
  10099. return -EINVAL;
  10100. }
  10101. break;
  10102. case DRM_FORMAT_YUYV:
  10103. case DRM_FORMAT_UYVY:
  10104. case DRM_FORMAT_YVYU:
  10105. case DRM_FORMAT_VYUY:
  10106. if (INTEL_INFO(dev)->gen < 5) {
  10107. DRM_DEBUG("unsupported pixel format: %s\n",
  10108. drm_get_format_name(mode_cmd->pixel_format));
  10109. return -EINVAL;
  10110. }
  10111. break;
  10112. default:
  10113. DRM_DEBUG("unsupported pixel format: %s\n",
  10114. drm_get_format_name(mode_cmd->pixel_format));
  10115. return -EINVAL;
  10116. }
  10117. /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
  10118. if (mode_cmd->offsets[0] != 0)
  10119. return -EINVAL;
  10120. aligned_height = intel_align_height(dev, mode_cmd->height,
  10121. obj->tiling_mode);
  10122. /* FIXME drm helper for size checks (especially planar formats)? */
  10123. if (obj->base.size < aligned_height * mode_cmd->pitches[0])
  10124. return -EINVAL;
  10125. drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd);
  10126. intel_fb->obj = obj;
  10127. intel_fb->obj->framebuffer_references++;
  10128. ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs);
  10129. if (ret) {
  10130. DRM_ERROR("framebuffer init failed %d\n", ret);
  10131. return ret;
  10132. }
  10133. return 0;
  10134. }
  10135. static struct drm_framebuffer *
  10136. intel_user_framebuffer_create(struct drm_device *dev,
  10137. struct drm_file *filp,
  10138. struct drm_mode_fb_cmd2 *mode_cmd)
  10139. {
  10140. struct drm_i915_gem_object *obj;
  10141. obj = to_intel_bo(drm_gem_object_lookup(dev, filp,
  10142. mode_cmd->handles[0]));
  10143. if (&obj->base == NULL)
  10144. return ERR_PTR(-ENOENT);
  10145. return intel_framebuffer_create(dev, mode_cmd, obj);
  10146. }
  10147. #ifndef CONFIG_DRM_I915_FBDEV
  10148. static inline void intel_fbdev_output_poll_changed(struct drm_device *dev)
  10149. {
  10150. }
  10151. #endif
  10152. static const struct drm_mode_config_funcs intel_mode_funcs = {
  10153. .fb_create = intel_user_framebuffer_create,
  10154. .output_poll_changed = intel_fbdev_output_poll_changed,
  10155. };
  10156. /* Set up chip specific display functions */
  10157. static void intel_init_display(struct drm_device *dev)
  10158. {
  10159. struct drm_i915_private *dev_priv = dev->dev_private;
  10160. if (HAS_PCH_SPLIT(dev) || IS_G4X(dev))
  10161. dev_priv->display.find_dpll = g4x_find_best_dpll;
  10162. else if (IS_CHERRYVIEW(dev))
  10163. dev_priv->display.find_dpll = chv_find_best_dpll;
  10164. else if (IS_VALLEYVIEW(dev))
  10165. dev_priv->display.find_dpll = vlv_find_best_dpll;
  10166. else if (IS_PINEVIEW(dev))
  10167. dev_priv->display.find_dpll = pnv_find_best_dpll;
  10168. else
  10169. dev_priv->display.find_dpll = i9xx_find_best_dpll;
  10170. if (HAS_DDI(dev)) {
  10171. dev_priv->display.get_pipe_config = haswell_get_pipe_config;
  10172. dev_priv->display.get_plane_config = ironlake_get_plane_config;
  10173. dev_priv->display.crtc_mode_set = haswell_crtc_mode_set;
  10174. dev_priv->display.crtc_enable = haswell_crtc_enable;
  10175. dev_priv->display.crtc_disable = haswell_crtc_disable;
  10176. dev_priv->display.off = haswell_crtc_off;
  10177. dev_priv->display.update_primary_plane =
  10178. ironlake_update_primary_plane;
  10179. } else if (HAS_PCH_SPLIT(dev)) {
  10180. dev_priv->display.get_pipe_config = ironlake_get_pipe_config;
  10181. dev_priv->display.get_plane_config = ironlake_get_plane_config;
  10182. dev_priv->display.crtc_mode_set = ironlake_crtc_mode_set;
  10183. dev_priv->display.crtc_enable = ironlake_crtc_enable;
  10184. dev_priv->display.crtc_disable = ironlake_crtc_disable;
  10185. dev_priv->display.off = ironlake_crtc_off;
  10186. dev_priv->display.update_primary_plane =
  10187. ironlake_update_primary_plane;
  10188. } else if (IS_VALLEYVIEW(dev)) {
  10189. dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
  10190. dev_priv->display.get_plane_config = i9xx_get_plane_config;
  10191. dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set;
  10192. dev_priv->display.crtc_enable = valleyview_crtc_enable;
  10193. dev_priv->display.crtc_disable = i9xx_crtc_disable;
  10194. dev_priv->display.off = i9xx_crtc_off;
  10195. dev_priv->display.update_primary_plane =
  10196. i9xx_update_primary_plane;
  10197. } else {
  10198. dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
  10199. dev_priv->display.get_plane_config = i9xx_get_plane_config;
  10200. dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set;
  10201. dev_priv->display.crtc_enable = i9xx_crtc_enable;
  10202. dev_priv->display.crtc_disable = i9xx_crtc_disable;
  10203. dev_priv->display.off = i9xx_crtc_off;
  10204. dev_priv->display.update_primary_plane =
  10205. i9xx_update_primary_plane;
  10206. }
  10207. /* Returns the core display clock speed */
  10208. if (IS_VALLEYVIEW(dev))
  10209. dev_priv->display.get_display_clock_speed =
  10210. valleyview_get_display_clock_speed;
  10211. else if (IS_I945G(dev) || (IS_G33(dev) && !IS_PINEVIEW_M(dev)))
  10212. dev_priv->display.get_display_clock_speed =
  10213. i945_get_display_clock_speed;
  10214. else if (IS_I915G(dev))
  10215. dev_priv->display.get_display_clock_speed =
  10216. i915_get_display_clock_speed;
  10217. else if (IS_I945GM(dev) || IS_845G(dev))
  10218. dev_priv->display.get_display_clock_speed =
  10219. i9xx_misc_get_display_clock_speed;
  10220. else if (IS_PINEVIEW(dev))
  10221. dev_priv->display.get_display_clock_speed =
  10222. pnv_get_display_clock_speed;
  10223. else if (IS_I915GM(dev))
  10224. dev_priv->display.get_display_clock_speed =
  10225. i915gm_get_display_clock_speed;
  10226. else if (IS_I865G(dev))
  10227. dev_priv->display.get_display_clock_speed =
  10228. i865_get_display_clock_speed;
  10229. else if (IS_I85X(dev))
  10230. dev_priv->display.get_display_clock_speed =
  10231. i855_get_display_clock_speed;
  10232. else /* 852, 830 */
  10233. dev_priv->display.get_display_clock_speed =
  10234. i830_get_display_clock_speed;
  10235. if (HAS_PCH_SPLIT(dev)) {
  10236. if (IS_GEN5(dev)) {
  10237. dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
  10238. dev_priv->display.write_eld = ironlake_write_eld;
  10239. } else if (IS_GEN6(dev)) {
  10240. dev_priv->display.fdi_link_train = gen6_fdi_link_train;
  10241. dev_priv->display.write_eld = ironlake_write_eld;
  10242. dev_priv->display.modeset_global_resources =
  10243. snb_modeset_global_resources;
  10244. } else if (IS_IVYBRIDGE(dev)) {
  10245. /* FIXME: detect B0+ stepping and use auto training */
  10246. dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
  10247. dev_priv->display.write_eld = ironlake_write_eld;
  10248. dev_priv->display.modeset_global_resources =
  10249. ivb_modeset_global_resources;
  10250. } else if (IS_HASWELL(dev) || IS_GEN8(dev)) {
  10251. dev_priv->display.fdi_link_train = hsw_fdi_link_train;
  10252. dev_priv->display.write_eld = haswell_write_eld;
  10253. dev_priv->display.modeset_global_resources =
  10254. haswell_modeset_global_resources;
  10255. }
  10256. } else if (IS_G4X(dev)) {
  10257. dev_priv->display.write_eld = g4x_write_eld;
  10258. } else if (IS_VALLEYVIEW(dev)) {
  10259. dev_priv->display.modeset_global_resources =
  10260. valleyview_modeset_global_resources;
  10261. dev_priv->display.write_eld = ironlake_write_eld;
  10262. }
  10263. /* Default just returns -ENODEV to indicate unsupported */
  10264. dev_priv->display.queue_flip = intel_default_queue_flip;
  10265. switch (INTEL_INFO(dev)->gen) {
  10266. case 2:
  10267. dev_priv->display.queue_flip = intel_gen2_queue_flip;
  10268. break;
  10269. case 3:
  10270. dev_priv->display.queue_flip = intel_gen3_queue_flip;
  10271. break;
  10272. case 4:
  10273. case 5:
  10274. dev_priv->display.queue_flip = intel_gen4_queue_flip;
  10275. break;
  10276. case 6:
  10277. dev_priv->display.queue_flip = intel_gen6_queue_flip;
  10278. break;
  10279. case 7:
  10280. case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */
  10281. dev_priv->display.queue_flip = intel_gen7_queue_flip;
  10282. break;
  10283. }
  10284. intel_panel_init_backlight_funcs(dev);
  10285. }
  10286. /*
  10287. * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend,
  10288. * resume, or other times. This quirk makes sure that's the case for
  10289. * affected systems.
  10290. */
  10291. static void quirk_pipea_force(struct drm_device *dev)
  10292. {
  10293. struct drm_i915_private *dev_priv = dev->dev_private;
  10294. dev_priv->quirks |= QUIRK_PIPEA_FORCE;
  10295. DRM_INFO("applying pipe a force quirk\n");
  10296. }
  10297. /*
  10298. * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
  10299. */
  10300. static void quirk_ssc_force_disable(struct drm_device *dev)
  10301. {
  10302. struct drm_i915_private *dev_priv = dev->dev_private;
  10303. dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE;
  10304. DRM_INFO("applying lvds SSC disable quirk\n");
  10305. }
  10306. /*
  10307. * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
  10308. * brightness value
  10309. */
  10310. static void quirk_invert_brightness(struct drm_device *dev)
  10311. {
  10312. struct drm_i915_private *dev_priv = dev->dev_private;
  10313. dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS;
  10314. DRM_INFO("applying inverted panel brightness quirk\n");
  10315. }
  10316. struct intel_quirk {
  10317. int device;
  10318. int subsystem_vendor;
  10319. int subsystem_device;
  10320. void (*hook)(struct drm_device *dev);
  10321. };
  10322. /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
  10323. struct intel_dmi_quirk {
  10324. void (*hook)(struct drm_device *dev);
  10325. const struct dmi_system_id (*dmi_id_list)[];
  10326. };
  10327. static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
  10328. {
  10329. DRM_INFO("Backlight polarity reversed on %s\n", id->ident);
  10330. return 1;
  10331. }
  10332. static const struct intel_dmi_quirk intel_dmi_quirks[] = {
  10333. {
  10334. .dmi_id_list = &(const struct dmi_system_id[]) {
  10335. {
  10336. .callback = intel_dmi_reverse_brightness,
  10337. .ident = "NCR Corporation",
  10338. .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
  10339. DMI_MATCH(DMI_PRODUCT_NAME, ""),
  10340. },
  10341. },
  10342. { } /* terminating entry */
  10343. },
  10344. .hook = quirk_invert_brightness,
  10345. },
  10346. };
  10347. static struct intel_quirk intel_quirks[] = {
  10348. /* HP Mini needs pipe A force quirk (LP: #322104) */
  10349. { 0x27ae, 0x103c, 0x361a, quirk_pipea_force },
  10350. /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
  10351. { 0x2592, 0x1179, 0x0001, quirk_pipea_force },
  10352. /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
  10353. { 0x2782, 0x17aa, 0x201a, quirk_pipea_force },
  10354. /* Lenovo U160 cannot use SSC on LVDS */
  10355. { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable },
  10356. /* Sony Vaio Y cannot use SSC on LVDS */
  10357. { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable },
  10358. /* Acer Aspire 5734Z must invert backlight brightness */
  10359. { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness },
  10360. /* Acer/eMachines G725 */
  10361. { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness },
  10362. /* Acer/eMachines e725 */
  10363. { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness },
  10364. /* Acer/Packard Bell NCL20 */
  10365. { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness },
  10366. /* Acer Aspire 4736Z */
  10367. { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness },
  10368. /* Acer Aspire 5336 */
  10369. { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness },
  10370. };
  10371. static void intel_init_quirks(struct drm_device *dev)
  10372. {
  10373. struct pci_dev *d = dev->pdev;
  10374. int i;
  10375. for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) {
  10376. struct intel_quirk *q = &intel_quirks[i];
  10377. if (d->device == q->device &&
  10378. (d->subsystem_vendor == q->subsystem_vendor ||
  10379. q->subsystem_vendor == PCI_ANY_ID) &&
  10380. (d->subsystem_device == q->subsystem_device ||
  10381. q->subsystem_device == PCI_ANY_ID))
  10382. q->hook(dev);
  10383. }
  10384. for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) {
  10385. if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0)
  10386. intel_dmi_quirks[i].hook(dev);
  10387. }
  10388. }
  10389. /* Disable the VGA plane that we never use */
  10390. static void i915_disable_vga(struct drm_device *dev)
  10391. {
  10392. struct drm_i915_private *dev_priv = dev->dev_private;
  10393. u8 sr1;
  10394. u32 vga_reg = i915_vgacntrl_reg(dev);
  10395. /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
  10396. vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
  10397. outb(SR01, VGA_SR_INDEX);
  10398. sr1 = inb(VGA_SR_DATA);
  10399. outb(sr1 | 1<<5, VGA_SR_DATA);
  10400. vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
  10401. udelay(300);
  10402. I915_WRITE(vga_reg, VGA_DISP_DISABLE);
  10403. POSTING_READ(vga_reg);
  10404. }
  10405. void intel_modeset_init_hw(struct drm_device *dev)
  10406. {
  10407. intel_prepare_ddi(dev);
  10408. if (IS_VALLEYVIEW(dev))
  10409. vlv_update_cdclk(dev);
  10410. intel_init_clock_gating(dev);
  10411. intel_reset_dpio(dev);
  10412. intel_enable_gt_powersave(dev);
  10413. }
  10414. void intel_modeset_suspend_hw(struct drm_device *dev)
  10415. {
  10416. intel_suspend_hw(dev);
  10417. }
  10418. void intel_modeset_init(struct drm_device *dev)
  10419. {
  10420. struct drm_i915_private *dev_priv = dev->dev_private;
  10421. int sprite, ret;
  10422. enum pipe pipe;
  10423. struct intel_crtc *crtc;
  10424. drm_mode_config_init(dev);
  10425. dev->mode_config.min_width = 0;
  10426. dev->mode_config.min_height = 0;
  10427. dev->mode_config.preferred_depth = 24;
  10428. dev->mode_config.prefer_shadow = 1;
  10429. dev->mode_config.funcs = &intel_mode_funcs;
  10430. intel_init_quirks(dev);
  10431. intel_init_pm(dev);
  10432. if (INTEL_INFO(dev)->num_pipes == 0)
  10433. return;
  10434. intel_init_display(dev);
  10435. if (IS_GEN2(dev)) {
  10436. dev->mode_config.max_width = 2048;
  10437. dev->mode_config.max_height = 2048;
  10438. } else if (IS_GEN3(dev)) {
  10439. dev->mode_config.max_width = 4096;
  10440. dev->mode_config.max_height = 4096;
  10441. } else {
  10442. dev->mode_config.max_width = 8192;
  10443. dev->mode_config.max_height = 8192;
  10444. }
  10445. if (IS_GEN2(dev)) {
  10446. dev->mode_config.cursor_width = GEN2_CURSOR_WIDTH;
  10447. dev->mode_config.cursor_height = GEN2_CURSOR_HEIGHT;
  10448. } else {
  10449. dev->mode_config.cursor_width = MAX_CURSOR_WIDTH;
  10450. dev->mode_config.cursor_height = MAX_CURSOR_HEIGHT;
  10451. }
  10452. dev->mode_config.fb_base = dev_priv->gtt.mappable_base;
  10453. DRM_DEBUG_KMS("%d display pipe%s available.\n",
  10454. INTEL_INFO(dev)->num_pipes,
  10455. INTEL_INFO(dev)->num_pipes > 1 ? "s" : "");
  10456. for_each_pipe(pipe) {
  10457. intel_crtc_init(dev, pipe);
  10458. for_each_sprite(pipe, sprite) {
  10459. ret = intel_plane_init(dev, pipe, sprite);
  10460. if (ret)
  10461. DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n",
  10462. pipe_name(pipe), sprite_name(pipe, sprite), ret);
  10463. }
  10464. }
  10465. intel_init_dpio(dev);
  10466. intel_reset_dpio(dev);
  10467. intel_cpu_pll_init(dev);
  10468. intel_shared_dpll_init(dev);
  10469. /* Just disable it once at startup */
  10470. i915_disable_vga(dev);
  10471. intel_setup_outputs(dev);
  10472. /* Just in case the BIOS is doing something questionable. */
  10473. intel_disable_fbc(dev);
  10474. drm_modeset_lock_all(dev);
  10475. intel_modeset_setup_hw_state(dev, false);
  10476. drm_modeset_unlock_all(dev);
  10477. for_each_intel_crtc(dev, crtc) {
  10478. if (!crtc->active)
  10479. continue;
  10480. /*
  10481. * Note that reserving the BIOS fb up front prevents us
  10482. * from stuffing other stolen allocations like the ring
  10483. * on top. This prevents some ugliness at boot time, and
  10484. * can even allow for smooth boot transitions if the BIOS
  10485. * fb is large enough for the active pipe configuration.
  10486. */
  10487. if (dev_priv->display.get_plane_config) {
  10488. dev_priv->display.get_plane_config(crtc,
  10489. &crtc->plane_config);
  10490. /*
  10491. * If the fb is shared between multiple heads, we'll
  10492. * just get the first one.
  10493. */
  10494. intel_find_plane_obj(crtc, &crtc->plane_config);
  10495. }
  10496. }
  10497. }
  10498. static void intel_enable_pipe_a(struct drm_device *dev)
  10499. {
  10500. struct intel_connector *connector;
  10501. struct drm_connector *crt = NULL;
  10502. struct intel_load_detect_pipe load_detect_temp;
  10503. struct drm_modeset_acquire_ctx ctx;
  10504. /* We can't just switch on the pipe A, we need to set things up with a
  10505. * proper mode and output configuration. As a gross hack, enable pipe A
  10506. * by enabling the load detect pipe once. */
  10507. list_for_each_entry(connector,
  10508. &dev->mode_config.connector_list,
  10509. base.head) {
  10510. if (connector->encoder->type == INTEL_OUTPUT_ANALOG) {
  10511. crt = &connector->base;
  10512. break;
  10513. }
  10514. }
  10515. if (!crt)
  10516. return;
  10517. if (intel_get_load_detect_pipe(crt, NULL, &load_detect_temp, &ctx))
  10518. intel_release_load_detect_pipe(crt, &load_detect_temp, &ctx);
  10519. }
  10520. static bool
  10521. intel_check_plane_mapping(struct intel_crtc *crtc)
  10522. {
  10523. struct drm_device *dev = crtc->base.dev;
  10524. struct drm_i915_private *dev_priv = dev->dev_private;
  10525. u32 reg, val;
  10526. if (INTEL_INFO(dev)->num_pipes == 1)
  10527. return true;
  10528. reg = DSPCNTR(!crtc->plane);
  10529. val = I915_READ(reg);
  10530. if ((val & DISPLAY_PLANE_ENABLE) &&
  10531. (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe))
  10532. return false;
  10533. return true;
  10534. }
  10535. static void intel_sanitize_crtc(struct intel_crtc *crtc)
  10536. {
  10537. struct drm_device *dev = crtc->base.dev;
  10538. struct drm_i915_private *dev_priv = dev->dev_private;
  10539. u32 reg;
  10540. /* Clear any frame start delays used for debugging left by the BIOS */
  10541. reg = PIPECONF(crtc->config.cpu_transcoder);
  10542. I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
  10543. /* restore vblank interrupts to correct state */
  10544. if (crtc->active)
  10545. drm_vblank_on(dev, crtc->pipe);
  10546. else
  10547. drm_vblank_off(dev, crtc->pipe);
  10548. /* We need to sanitize the plane -> pipe mapping first because this will
  10549. * disable the crtc (and hence change the state) if it is wrong. Note
  10550. * that gen4+ has a fixed plane -> pipe mapping. */
  10551. if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) {
  10552. struct intel_connector *connector;
  10553. bool plane;
  10554. DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n",
  10555. crtc->base.base.id);
  10556. /* Pipe has the wrong plane attached and the plane is active.
  10557. * Temporarily change the plane mapping and disable everything
  10558. * ... */
  10559. plane = crtc->plane;
  10560. crtc->plane = !plane;
  10561. dev_priv->display.crtc_disable(&crtc->base);
  10562. crtc->plane = plane;
  10563. /* ... and break all links. */
  10564. list_for_each_entry(connector, &dev->mode_config.connector_list,
  10565. base.head) {
  10566. if (connector->encoder->base.crtc != &crtc->base)
  10567. continue;
  10568. connector->base.dpms = DRM_MODE_DPMS_OFF;
  10569. connector->base.encoder = NULL;
  10570. }
  10571. /* multiple connectors may have the same encoder:
  10572. * handle them and break crtc link separately */
  10573. list_for_each_entry(connector, &dev->mode_config.connector_list,
  10574. base.head)
  10575. if (connector->encoder->base.crtc == &crtc->base) {
  10576. connector->encoder->base.crtc = NULL;
  10577. connector->encoder->connectors_active = false;
  10578. }
  10579. WARN_ON(crtc->active);
  10580. crtc->base.enabled = false;
  10581. }
  10582. if (dev_priv->quirks & QUIRK_PIPEA_FORCE &&
  10583. crtc->pipe == PIPE_A && !crtc->active) {
  10584. /* BIOS forgot to enable pipe A, this mostly happens after
  10585. * resume. Force-enable the pipe to fix this, the update_dpms
  10586. * call below we restore the pipe to the right state, but leave
  10587. * the required bits on. */
  10588. intel_enable_pipe_a(dev);
  10589. }
  10590. /* Adjust the state of the output pipe according to whether we
  10591. * have active connectors/encoders. */
  10592. intel_crtc_update_dpms(&crtc->base);
  10593. if (crtc->active != crtc->base.enabled) {
  10594. struct intel_encoder *encoder;
  10595. /* This can happen either due to bugs in the get_hw_state
  10596. * functions or because the pipe is force-enabled due to the
  10597. * pipe A quirk. */
  10598. DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n",
  10599. crtc->base.base.id,
  10600. crtc->base.enabled ? "enabled" : "disabled",
  10601. crtc->active ? "enabled" : "disabled");
  10602. crtc->base.enabled = crtc->active;
  10603. /* Because we only establish the connector -> encoder ->
  10604. * crtc links if something is active, this means the
  10605. * crtc is now deactivated. Break the links. connector
  10606. * -> encoder links are only establish when things are
  10607. * actually up, hence no need to break them. */
  10608. WARN_ON(crtc->active);
  10609. for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
  10610. WARN_ON(encoder->connectors_active);
  10611. encoder->base.crtc = NULL;
  10612. }
  10613. }
  10614. if (crtc->active || IS_VALLEYVIEW(dev) || INTEL_INFO(dev)->gen < 5) {
  10615. /*
  10616. * We start out with underrun reporting disabled to avoid races.
  10617. * For correct bookkeeping mark this on active crtcs.
  10618. *
  10619. * Also on gmch platforms we dont have any hardware bits to
  10620. * disable the underrun reporting. Which means we need to start
  10621. * out with underrun reporting disabled also on inactive pipes,
  10622. * since otherwise we'll complain about the garbage we read when
  10623. * e.g. coming up after runtime pm.
  10624. *
  10625. * No protection against concurrent access is required - at
  10626. * worst a fifo underrun happens which also sets this to false.
  10627. */
  10628. crtc->cpu_fifo_underrun_disabled = true;
  10629. crtc->pch_fifo_underrun_disabled = true;
  10630. update_scanline_offset(crtc);
  10631. }
  10632. }
  10633. static void intel_sanitize_encoder(struct intel_encoder *encoder)
  10634. {
  10635. struct intel_connector *connector;
  10636. struct drm_device *dev = encoder->base.dev;
  10637. /* We need to check both for a crtc link (meaning that the
  10638. * encoder is active and trying to read from a pipe) and the
  10639. * pipe itself being active. */
  10640. bool has_active_crtc = encoder->base.crtc &&
  10641. to_intel_crtc(encoder->base.crtc)->active;
  10642. if (encoder->connectors_active && !has_active_crtc) {
  10643. DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
  10644. encoder->base.base.id,
  10645. encoder->base.name);
  10646. /* Connector is active, but has no active pipe. This is
  10647. * fallout from our resume register restoring. Disable
  10648. * the encoder manually again. */
  10649. if (encoder->base.crtc) {
  10650. DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
  10651. encoder->base.base.id,
  10652. encoder->base.name);
  10653. encoder->disable(encoder);
  10654. }
  10655. encoder->base.crtc = NULL;
  10656. encoder->connectors_active = false;
  10657. /* Inconsistent output/port/pipe state happens presumably due to
  10658. * a bug in one of the get_hw_state functions. Or someplace else
  10659. * in our code, like the register restore mess on resume. Clamp
  10660. * things to off as a safer default. */
  10661. list_for_each_entry(connector,
  10662. &dev->mode_config.connector_list,
  10663. base.head) {
  10664. if (connector->encoder != encoder)
  10665. continue;
  10666. connector->base.dpms = DRM_MODE_DPMS_OFF;
  10667. connector->base.encoder = NULL;
  10668. }
  10669. }
  10670. /* Enabled encoders without active connectors will be fixed in
  10671. * the crtc fixup. */
  10672. }
  10673. void i915_redisable_vga_power_on(struct drm_device *dev)
  10674. {
  10675. struct drm_i915_private *dev_priv = dev->dev_private;
  10676. u32 vga_reg = i915_vgacntrl_reg(dev);
  10677. if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) {
  10678. DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
  10679. i915_disable_vga(dev);
  10680. }
  10681. }
  10682. void i915_redisable_vga(struct drm_device *dev)
  10683. {
  10684. struct drm_i915_private *dev_priv = dev->dev_private;
  10685. /* This function can be called both from intel_modeset_setup_hw_state or
  10686. * at a very early point in our resume sequence, where the power well
  10687. * structures are not yet restored. Since this function is at a very
  10688. * paranoid "someone might have enabled VGA while we were not looking"
  10689. * level, just check if the power well is enabled instead of trying to
  10690. * follow the "don't touch the power well if we don't need it" policy
  10691. * the rest of the driver uses. */
  10692. if (!intel_display_power_enabled(dev_priv, POWER_DOMAIN_VGA))
  10693. return;
  10694. i915_redisable_vga_power_on(dev);
  10695. }
  10696. static bool primary_get_hw_state(struct intel_crtc *crtc)
  10697. {
  10698. struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
  10699. if (!crtc->active)
  10700. return false;
  10701. return I915_READ(DSPCNTR(crtc->plane)) & DISPLAY_PLANE_ENABLE;
  10702. }
  10703. static void intel_modeset_readout_hw_state(struct drm_device *dev)
  10704. {
  10705. struct drm_i915_private *dev_priv = dev->dev_private;
  10706. enum pipe pipe;
  10707. struct intel_crtc *crtc;
  10708. struct intel_encoder *encoder;
  10709. struct intel_connector *connector;
  10710. int i;
  10711. for_each_intel_crtc(dev, crtc) {
  10712. memset(&crtc->config, 0, sizeof(crtc->config));
  10713. crtc->config.quirks |= PIPE_CONFIG_QUIRK_INHERITED_MODE;
  10714. crtc->active = dev_priv->display.get_pipe_config(crtc,
  10715. &crtc->config);
  10716. crtc->base.enabled = crtc->active;
  10717. crtc->primary_enabled = primary_get_hw_state(crtc);
  10718. DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n",
  10719. crtc->base.base.id,
  10720. crtc->active ? "enabled" : "disabled");
  10721. }
  10722. /* FIXME: Smash this into the new shared dpll infrastructure. */
  10723. if (HAS_DDI(dev))
  10724. intel_ddi_setup_hw_pll_state(dev);
  10725. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  10726. struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
  10727. pll->on = pll->get_hw_state(dev_priv, pll, &pll->hw_state);
  10728. pll->active = 0;
  10729. for_each_intel_crtc(dev, crtc) {
  10730. if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll)
  10731. pll->active++;
  10732. }
  10733. pll->refcount = pll->active;
  10734. DRM_DEBUG_KMS("%s hw state readout: refcount %i, on %i\n",
  10735. pll->name, pll->refcount, pll->on);
  10736. }
  10737. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  10738. base.head) {
  10739. pipe = 0;
  10740. if (encoder->get_hw_state(encoder, &pipe)) {
  10741. crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  10742. encoder->base.crtc = &crtc->base;
  10743. encoder->get_config(encoder, &crtc->config);
  10744. } else {
  10745. encoder->base.crtc = NULL;
  10746. }
  10747. encoder->connectors_active = false;
  10748. DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
  10749. encoder->base.base.id,
  10750. encoder->base.name,
  10751. encoder->base.crtc ? "enabled" : "disabled",
  10752. pipe_name(pipe));
  10753. }
  10754. list_for_each_entry(connector, &dev->mode_config.connector_list,
  10755. base.head) {
  10756. if (connector->get_hw_state(connector)) {
  10757. connector->base.dpms = DRM_MODE_DPMS_ON;
  10758. connector->encoder->connectors_active = true;
  10759. connector->base.encoder = &connector->encoder->base;
  10760. } else {
  10761. connector->base.dpms = DRM_MODE_DPMS_OFF;
  10762. connector->base.encoder = NULL;
  10763. }
  10764. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
  10765. connector->base.base.id,
  10766. connector->base.name,
  10767. connector->base.encoder ? "enabled" : "disabled");
  10768. }
  10769. }
  10770. /* Scan out the current hw modeset state, sanitizes it and maps it into the drm
  10771. * and i915 state tracking structures. */
  10772. void intel_modeset_setup_hw_state(struct drm_device *dev,
  10773. bool force_restore)
  10774. {
  10775. struct drm_i915_private *dev_priv = dev->dev_private;
  10776. enum pipe pipe;
  10777. struct intel_crtc *crtc;
  10778. struct intel_encoder *encoder;
  10779. int i;
  10780. intel_modeset_readout_hw_state(dev);
  10781. /*
  10782. * Now that we have the config, copy it to each CRTC struct
  10783. * Note that this could go away if we move to using crtc_config
  10784. * checking everywhere.
  10785. */
  10786. for_each_intel_crtc(dev, crtc) {
  10787. if (crtc->active && i915.fastboot) {
  10788. intel_mode_from_pipe_config(&crtc->base.mode, &crtc->config);
  10789. DRM_DEBUG_KMS("[CRTC:%d] found active mode: ",
  10790. crtc->base.base.id);
  10791. drm_mode_debug_printmodeline(&crtc->base.mode);
  10792. }
  10793. }
  10794. /* HW state is read out, now we need to sanitize this mess. */
  10795. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  10796. base.head) {
  10797. intel_sanitize_encoder(encoder);
  10798. }
  10799. for_each_pipe(pipe) {
  10800. crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  10801. intel_sanitize_crtc(crtc);
  10802. intel_dump_pipe_config(crtc, &crtc->config, "[setup_hw_state]");
  10803. }
  10804. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  10805. struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
  10806. if (!pll->on || pll->active)
  10807. continue;
  10808. DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll->name);
  10809. pll->disable(dev_priv, pll);
  10810. pll->on = false;
  10811. }
  10812. if (HAS_PCH_SPLIT(dev))
  10813. ilk_wm_get_hw_state(dev);
  10814. if (force_restore) {
  10815. i915_redisable_vga(dev);
  10816. /*
  10817. * We need to use raw interfaces for restoring state to avoid
  10818. * checking (bogus) intermediate states.
  10819. */
  10820. for_each_pipe(pipe) {
  10821. struct drm_crtc *crtc =
  10822. dev_priv->pipe_to_crtc_mapping[pipe];
  10823. __intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y,
  10824. crtc->primary->fb);
  10825. }
  10826. } else {
  10827. intel_modeset_update_staged_output_state(dev);
  10828. }
  10829. intel_modeset_check_state(dev);
  10830. }
  10831. void intel_modeset_gem_init(struct drm_device *dev)
  10832. {
  10833. struct drm_crtc *c;
  10834. struct drm_i915_gem_object *obj;
  10835. mutex_lock(&dev->struct_mutex);
  10836. intel_init_gt_powersave(dev);
  10837. mutex_unlock(&dev->struct_mutex);
  10838. intel_modeset_init_hw(dev);
  10839. intel_setup_overlay(dev);
  10840. /*
  10841. * Make sure any fbs we allocated at startup are properly
  10842. * pinned & fenced. When we do the allocation it's too early
  10843. * for this.
  10844. */
  10845. mutex_lock(&dev->struct_mutex);
  10846. for_each_crtc(dev, c) {
  10847. obj = intel_fb_obj(c->primary->fb);
  10848. if (obj == NULL)
  10849. continue;
  10850. if (intel_pin_and_fence_fb_obj(dev, obj, NULL)) {
  10851. DRM_ERROR("failed to pin boot fb on pipe %d\n",
  10852. to_intel_crtc(c)->pipe);
  10853. drm_framebuffer_unreference(c->primary->fb);
  10854. c->primary->fb = NULL;
  10855. }
  10856. }
  10857. mutex_unlock(&dev->struct_mutex);
  10858. }
  10859. void intel_connector_unregister(struct intel_connector *intel_connector)
  10860. {
  10861. struct drm_connector *connector = &intel_connector->base;
  10862. intel_panel_destroy_backlight(connector);
  10863. drm_sysfs_connector_remove(connector);
  10864. }
  10865. void intel_modeset_cleanup(struct drm_device *dev)
  10866. {
  10867. struct drm_i915_private *dev_priv = dev->dev_private;
  10868. struct drm_connector *connector;
  10869. /*
  10870. * Interrupts and polling as the first thing to avoid creating havoc.
  10871. * Too much stuff here (turning of rps, connectors, ...) would
  10872. * experience fancy races otherwise.
  10873. */
  10874. drm_irq_uninstall(dev);
  10875. cancel_work_sync(&dev_priv->hotplug_work);
  10876. /*
  10877. * Due to the hpd irq storm handling the hotplug work can re-arm the
  10878. * poll handlers. Hence disable polling after hpd handling is shut down.
  10879. */
  10880. drm_kms_helper_poll_fini(dev);
  10881. mutex_lock(&dev->struct_mutex);
  10882. intel_unregister_dsm_handler();
  10883. intel_disable_fbc(dev);
  10884. intel_disable_gt_powersave(dev);
  10885. ironlake_teardown_rc6(dev);
  10886. mutex_unlock(&dev->struct_mutex);
  10887. /* flush any delayed tasks or pending work */
  10888. flush_scheduled_work();
  10889. /* destroy the backlight and sysfs files before encoders/connectors */
  10890. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  10891. struct intel_connector *intel_connector;
  10892. intel_connector = to_intel_connector(connector);
  10893. intel_connector->unregister(intel_connector);
  10894. }
  10895. drm_mode_config_cleanup(dev);
  10896. intel_cleanup_overlay(dev);
  10897. mutex_lock(&dev->struct_mutex);
  10898. intel_cleanup_gt_powersave(dev);
  10899. mutex_unlock(&dev->struct_mutex);
  10900. }
  10901. /*
  10902. * Return which encoder is currently attached for connector.
  10903. */
  10904. struct drm_encoder *intel_best_encoder(struct drm_connector *connector)
  10905. {
  10906. return &intel_attached_encoder(connector)->base;
  10907. }
  10908. void intel_connector_attach_encoder(struct intel_connector *connector,
  10909. struct intel_encoder *encoder)
  10910. {
  10911. connector->encoder = encoder;
  10912. drm_mode_connector_attach_encoder(&connector->base,
  10913. &encoder->base);
  10914. }
  10915. /*
  10916. * set vga decode state - true == enable VGA decode
  10917. */
  10918. int intel_modeset_vga_set_state(struct drm_device *dev, bool state)
  10919. {
  10920. struct drm_i915_private *dev_priv = dev->dev_private;
  10921. unsigned reg = INTEL_INFO(dev)->gen >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL;
  10922. u16 gmch_ctrl;
  10923. if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) {
  10924. DRM_ERROR("failed to read control word\n");
  10925. return -EIO;
  10926. }
  10927. if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state)
  10928. return 0;
  10929. if (state)
  10930. gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
  10931. else
  10932. gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
  10933. if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) {
  10934. DRM_ERROR("failed to write control word\n");
  10935. return -EIO;
  10936. }
  10937. return 0;
  10938. }
  10939. struct intel_display_error_state {
  10940. u32 power_well_driver;
  10941. int num_transcoders;
  10942. struct intel_cursor_error_state {
  10943. u32 control;
  10944. u32 position;
  10945. u32 base;
  10946. u32 size;
  10947. } cursor[I915_MAX_PIPES];
  10948. struct intel_pipe_error_state {
  10949. bool power_domain_on;
  10950. u32 source;
  10951. u32 stat;
  10952. } pipe[I915_MAX_PIPES];
  10953. struct intel_plane_error_state {
  10954. u32 control;
  10955. u32 stride;
  10956. u32 size;
  10957. u32 pos;
  10958. u32 addr;
  10959. u32 surface;
  10960. u32 tile_offset;
  10961. } plane[I915_MAX_PIPES];
  10962. struct intel_transcoder_error_state {
  10963. bool power_domain_on;
  10964. enum transcoder cpu_transcoder;
  10965. u32 conf;
  10966. u32 htotal;
  10967. u32 hblank;
  10968. u32 hsync;
  10969. u32 vtotal;
  10970. u32 vblank;
  10971. u32 vsync;
  10972. } transcoder[4];
  10973. };
  10974. struct intel_display_error_state *
  10975. intel_display_capture_error_state(struct drm_device *dev)
  10976. {
  10977. struct drm_i915_private *dev_priv = dev->dev_private;
  10978. struct intel_display_error_state *error;
  10979. int transcoders[] = {
  10980. TRANSCODER_A,
  10981. TRANSCODER_B,
  10982. TRANSCODER_C,
  10983. TRANSCODER_EDP,
  10984. };
  10985. int i;
  10986. if (INTEL_INFO(dev)->num_pipes == 0)
  10987. return NULL;
  10988. error = kzalloc(sizeof(*error), GFP_ATOMIC);
  10989. if (error == NULL)
  10990. return NULL;
  10991. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  10992. error->power_well_driver = I915_READ(HSW_PWR_WELL_DRIVER);
  10993. for_each_pipe(i) {
  10994. error->pipe[i].power_domain_on =
  10995. intel_display_power_enabled_unlocked(dev_priv,
  10996. POWER_DOMAIN_PIPE(i));
  10997. if (!error->pipe[i].power_domain_on)
  10998. continue;
  10999. error->cursor[i].control = I915_READ(CURCNTR(i));
  11000. error->cursor[i].position = I915_READ(CURPOS(i));
  11001. error->cursor[i].base = I915_READ(CURBASE(i));
  11002. error->plane[i].control = I915_READ(DSPCNTR(i));
  11003. error->plane[i].stride = I915_READ(DSPSTRIDE(i));
  11004. if (INTEL_INFO(dev)->gen <= 3) {
  11005. error->plane[i].size = I915_READ(DSPSIZE(i));
  11006. error->plane[i].pos = I915_READ(DSPPOS(i));
  11007. }
  11008. if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev))
  11009. error->plane[i].addr = I915_READ(DSPADDR(i));
  11010. if (INTEL_INFO(dev)->gen >= 4) {
  11011. error->plane[i].surface = I915_READ(DSPSURF(i));
  11012. error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
  11013. }
  11014. error->pipe[i].source = I915_READ(PIPESRC(i));
  11015. if (!HAS_PCH_SPLIT(dev))
  11016. error->pipe[i].stat = I915_READ(PIPESTAT(i));
  11017. }
  11018. error->num_transcoders = INTEL_INFO(dev)->num_pipes;
  11019. if (HAS_DDI(dev_priv->dev))
  11020. error->num_transcoders++; /* Account for eDP. */
  11021. for (i = 0; i < error->num_transcoders; i++) {
  11022. enum transcoder cpu_transcoder = transcoders[i];
  11023. error->transcoder[i].power_domain_on =
  11024. intel_display_power_enabled_unlocked(dev_priv,
  11025. POWER_DOMAIN_TRANSCODER(cpu_transcoder));
  11026. if (!error->transcoder[i].power_domain_on)
  11027. continue;
  11028. error->transcoder[i].cpu_transcoder = cpu_transcoder;
  11029. error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder));
  11030. error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder));
  11031. error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder));
  11032. error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder));
  11033. error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder));
  11034. error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder));
  11035. error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder));
  11036. }
  11037. return error;
  11038. }
  11039. #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
  11040. void
  11041. intel_display_print_error_state(struct drm_i915_error_state_buf *m,
  11042. struct drm_device *dev,
  11043. struct intel_display_error_state *error)
  11044. {
  11045. int i;
  11046. if (!error)
  11047. return;
  11048. err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev)->num_pipes);
  11049. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  11050. err_printf(m, "PWR_WELL_CTL2: %08x\n",
  11051. error->power_well_driver);
  11052. for_each_pipe(i) {
  11053. err_printf(m, "Pipe [%d]:\n", i);
  11054. err_printf(m, " Power: %s\n",
  11055. error->pipe[i].power_domain_on ? "on" : "off");
  11056. err_printf(m, " SRC: %08x\n", error->pipe[i].source);
  11057. err_printf(m, " STAT: %08x\n", error->pipe[i].stat);
  11058. err_printf(m, "Plane [%d]:\n", i);
  11059. err_printf(m, " CNTR: %08x\n", error->plane[i].control);
  11060. err_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
  11061. if (INTEL_INFO(dev)->gen <= 3) {
  11062. err_printf(m, " SIZE: %08x\n", error->plane[i].size);
  11063. err_printf(m, " POS: %08x\n", error->plane[i].pos);
  11064. }
  11065. if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev))
  11066. err_printf(m, " ADDR: %08x\n", error->plane[i].addr);
  11067. if (INTEL_INFO(dev)->gen >= 4) {
  11068. err_printf(m, " SURF: %08x\n", error->plane[i].surface);
  11069. err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
  11070. }
  11071. err_printf(m, "Cursor [%d]:\n", i);
  11072. err_printf(m, " CNTR: %08x\n", error->cursor[i].control);
  11073. err_printf(m, " POS: %08x\n", error->cursor[i].position);
  11074. err_printf(m, " BASE: %08x\n", error->cursor[i].base);
  11075. }
  11076. for (i = 0; i < error->num_transcoders; i++) {
  11077. err_printf(m, "CPU transcoder: %c\n",
  11078. transcoder_name(error->transcoder[i].cpu_transcoder));
  11079. err_printf(m, " Power: %s\n",
  11080. error->transcoder[i].power_domain_on ? "on" : "off");
  11081. err_printf(m, " CONF: %08x\n", error->transcoder[i].conf);
  11082. err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal);
  11083. err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank);
  11084. err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync);
  11085. err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal);
  11086. err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank);
  11087. err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync);
  11088. }
  11089. }