intel_display.c 249 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301
  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 <linux/dma_remapping.h>
  42. bool intel_pipe_has_type(struct drm_crtc *crtc, int type);
  43. static void intel_increase_pllclock(struct drm_crtc *crtc);
  44. static void intel_crtc_update_cursor(struct drm_crtc *crtc, bool on);
  45. typedef struct {
  46. /* given values */
  47. int n;
  48. int m1, m2;
  49. int p1, p2;
  50. /* derived values */
  51. int dot;
  52. int vco;
  53. int m;
  54. int p;
  55. } intel_clock_t;
  56. typedef struct {
  57. int min, max;
  58. } intel_range_t;
  59. typedef struct {
  60. int dot_limit;
  61. int p2_slow, p2_fast;
  62. } intel_p2_t;
  63. #define INTEL_P2_NUM 2
  64. typedef struct intel_limit intel_limit_t;
  65. struct intel_limit {
  66. intel_range_t dot, vco, n, m, m1, m2, p, p1;
  67. intel_p2_t p2;
  68. bool (* find_pll)(const intel_limit_t *, struct drm_crtc *,
  69. int, int, intel_clock_t *, intel_clock_t *);
  70. };
  71. /* FDI */
  72. #define IRONLAKE_FDI_FREQ 2700000 /* in kHz for mode->clock */
  73. int
  74. intel_pch_rawclk(struct drm_device *dev)
  75. {
  76. struct drm_i915_private *dev_priv = dev->dev_private;
  77. WARN_ON(!HAS_PCH_SPLIT(dev));
  78. return I915_READ(PCH_RAWCLK_FREQ) & RAWCLK_FREQ_MASK;
  79. }
  80. static bool
  81. intel_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
  82. int target, int refclk, intel_clock_t *match_clock,
  83. intel_clock_t *best_clock);
  84. static bool
  85. intel_g4x_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
  86. int target, int refclk, intel_clock_t *match_clock,
  87. intel_clock_t *best_clock);
  88. static bool
  89. intel_find_pll_g4x_dp(const intel_limit_t *, struct drm_crtc *crtc,
  90. int target, int refclk, intel_clock_t *match_clock,
  91. intel_clock_t *best_clock);
  92. static bool
  93. intel_find_pll_ironlake_dp(const intel_limit_t *, struct drm_crtc *crtc,
  94. int target, int refclk, intel_clock_t *match_clock,
  95. intel_clock_t *best_clock);
  96. static bool
  97. intel_vlv_find_best_pll(const intel_limit_t *limit, struct drm_crtc *crtc,
  98. int target, int refclk, intel_clock_t *match_clock,
  99. intel_clock_t *best_clock);
  100. static inline u32 /* units of 100MHz */
  101. intel_fdi_link_freq(struct drm_device *dev)
  102. {
  103. if (IS_GEN5(dev)) {
  104. struct drm_i915_private *dev_priv = dev->dev_private;
  105. return (I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK) + 2;
  106. } else
  107. return 27;
  108. }
  109. static const intel_limit_t intel_limits_i8xx_dvo = {
  110. .dot = { .min = 25000, .max = 350000 },
  111. .vco = { .min = 930000, .max = 1400000 },
  112. .n = { .min = 3, .max = 16 },
  113. .m = { .min = 96, .max = 140 },
  114. .m1 = { .min = 18, .max = 26 },
  115. .m2 = { .min = 6, .max = 16 },
  116. .p = { .min = 4, .max = 128 },
  117. .p1 = { .min = 2, .max = 33 },
  118. .p2 = { .dot_limit = 165000,
  119. .p2_slow = 4, .p2_fast = 2 },
  120. .find_pll = intel_find_best_PLL,
  121. };
  122. static const intel_limit_t intel_limits_i8xx_lvds = {
  123. .dot = { .min = 25000, .max = 350000 },
  124. .vco = { .min = 930000, .max = 1400000 },
  125. .n = { .min = 3, .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 = 1, .max = 6 },
  131. .p2 = { .dot_limit = 165000,
  132. .p2_slow = 14, .p2_fast = 7 },
  133. .find_pll = intel_find_best_PLL,
  134. };
  135. static const intel_limit_t intel_limits_i9xx_sdvo = {
  136. .dot = { .min = 20000, .max = 400000 },
  137. .vco = { .min = 1400000, .max = 2800000 },
  138. .n = { .min = 1, .max = 6 },
  139. .m = { .min = 70, .max = 120 },
  140. .m1 = { .min = 10, .max = 22 },
  141. .m2 = { .min = 5, .max = 9 },
  142. .p = { .min = 5, .max = 80 },
  143. .p1 = { .min = 1, .max = 8 },
  144. .p2 = { .dot_limit = 200000,
  145. .p2_slow = 10, .p2_fast = 5 },
  146. .find_pll = intel_find_best_PLL,
  147. };
  148. static const intel_limit_t intel_limits_i9xx_lvds = {
  149. .dot = { .min = 20000, .max = 400000 },
  150. .vco = { .min = 1400000, .max = 2800000 },
  151. .n = { .min = 1, .max = 6 },
  152. .m = { .min = 70, .max = 120 },
  153. .m1 = { .min = 10, .max = 22 },
  154. .m2 = { .min = 5, .max = 9 },
  155. .p = { .min = 7, .max = 98 },
  156. .p1 = { .min = 1, .max = 8 },
  157. .p2 = { .dot_limit = 112000,
  158. .p2_slow = 14, .p2_fast = 7 },
  159. .find_pll = intel_find_best_PLL,
  160. };
  161. static const intel_limit_t intel_limits_g4x_sdvo = {
  162. .dot = { .min = 25000, .max = 270000 },
  163. .vco = { .min = 1750000, .max = 3500000},
  164. .n = { .min = 1, .max = 4 },
  165. .m = { .min = 104, .max = 138 },
  166. .m1 = { .min = 17, .max = 23 },
  167. .m2 = { .min = 5, .max = 11 },
  168. .p = { .min = 10, .max = 30 },
  169. .p1 = { .min = 1, .max = 3},
  170. .p2 = { .dot_limit = 270000,
  171. .p2_slow = 10,
  172. .p2_fast = 10
  173. },
  174. .find_pll = intel_g4x_find_best_PLL,
  175. };
  176. static const intel_limit_t intel_limits_g4x_hdmi = {
  177. .dot = { .min = 22000, .max = 400000 },
  178. .vco = { .min = 1750000, .max = 3500000},
  179. .n = { .min = 1, .max = 4 },
  180. .m = { .min = 104, .max = 138 },
  181. .m1 = { .min = 16, .max = 23 },
  182. .m2 = { .min = 5, .max = 11 },
  183. .p = { .min = 5, .max = 80 },
  184. .p1 = { .min = 1, .max = 8},
  185. .p2 = { .dot_limit = 165000,
  186. .p2_slow = 10, .p2_fast = 5 },
  187. .find_pll = intel_g4x_find_best_PLL,
  188. };
  189. static const intel_limit_t intel_limits_g4x_single_channel_lvds = {
  190. .dot = { .min = 20000, .max = 115000 },
  191. .vco = { .min = 1750000, .max = 3500000 },
  192. .n = { .min = 1, .max = 3 },
  193. .m = { .min = 104, .max = 138 },
  194. .m1 = { .min = 17, .max = 23 },
  195. .m2 = { .min = 5, .max = 11 },
  196. .p = { .min = 28, .max = 112 },
  197. .p1 = { .min = 2, .max = 8 },
  198. .p2 = { .dot_limit = 0,
  199. .p2_slow = 14, .p2_fast = 14
  200. },
  201. .find_pll = intel_g4x_find_best_PLL,
  202. };
  203. static const intel_limit_t intel_limits_g4x_dual_channel_lvds = {
  204. .dot = { .min = 80000, .max = 224000 },
  205. .vco = { .min = 1750000, .max = 3500000 },
  206. .n = { .min = 1, .max = 3 },
  207. .m = { .min = 104, .max = 138 },
  208. .m1 = { .min = 17, .max = 23 },
  209. .m2 = { .min = 5, .max = 11 },
  210. .p = { .min = 14, .max = 42 },
  211. .p1 = { .min = 2, .max = 6 },
  212. .p2 = { .dot_limit = 0,
  213. .p2_slow = 7, .p2_fast = 7
  214. },
  215. .find_pll = intel_g4x_find_best_PLL,
  216. };
  217. static const intel_limit_t intel_limits_g4x_display_port = {
  218. .dot = { .min = 161670, .max = 227000 },
  219. .vco = { .min = 1750000, .max = 3500000},
  220. .n = { .min = 1, .max = 2 },
  221. .m = { .min = 97, .max = 108 },
  222. .m1 = { .min = 0x10, .max = 0x12 },
  223. .m2 = { .min = 0x05, .max = 0x06 },
  224. .p = { .min = 10, .max = 20 },
  225. .p1 = { .min = 1, .max = 2},
  226. .p2 = { .dot_limit = 0,
  227. .p2_slow = 10, .p2_fast = 10 },
  228. .find_pll = intel_find_pll_g4x_dp,
  229. };
  230. static const intel_limit_t intel_limits_pineview_sdvo = {
  231. .dot = { .min = 20000, .max = 400000},
  232. .vco = { .min = 1700000, .max = 3500000 },
  233. /* Pineview's Ncounter is a ring counter */
  234. .n = { .min = 3, .max = 6 },
  235. .m = { .min = 2, .max = 256 },
  236. /* Pineview only has one combined m divider, which we treat as m2. */
  237. .m1 = { .min = 0, .max = 0 },
  238. .m2 = { .min = 0, .max = 254 },
  239. .p = { .min = 5, .max = 80 },
  240. .p1 = { .min = 1, .max = 8 },
  241. .p2 = { .dot_limit = 200000,
  242. .p2_slow = 10, .p2_fast = 5 },
  243. .find_pll = intel_find_best_PLL,
  244. };
  245. static const intel_limit_t intel_limits_pineview_lvds = {
  246. .dot = { .min = 20000, .max = 400000 },
  247. .vco = { .min = 1700000, .max = 3500000 },
  248. .n = { .min = 3, .max = 6 },
  249. .m = { .min = 2, .max = 256 },
  250. .m1 = { .min = 0, .max = 0 },
  251. .m2 = { .min = 0, .max = 254 },
  252. .p = { .min = 7, .max = 112 },
  253. .p1 = { .min = 1, .max = 8 },
  254. .p2 = { .dot_limit = 112000,
  255. .p2_slow = 14, .p2_fast = 14 },
  256. .find_pll = intel_find_best_PLL,
  257. };
  258. /* Ironlake / Sandybridge
  259. *
  260. * We calculate clock using (register_value + 2) for N/M1/M2, so here
  261. * the range value for them is (actual_value - 2).
  262. */
  263. static const intel_limit_t intel_limits_ironlake_dac = {
  264. .dot = { .min = 25000, .max = 350000 },
  265. .vco = { .min = 1760000, .max = 3510000 },
  266. .n = { .min = 1, .max = 5 },
  267. .m = { .min = 79, .max = 127 },
  268. .m1 = { .min = 12, .max = 22 },
  269. .m2 = { .min = 5, .max = 9 },
  270. .p = { .min = 5, .max = 80 },
  271. .p1 = { .min = 1, .max = 8 },
  272. .p2 = { .dot_limit = 225000,
  273. .p2_slow = 10, .p2_fast = 5 },
  274. .find_pll = intel_g4x_find_best_PLL,
  275. };
  276. static const intel_limit_t intel_limits_ironlake_single_lvds = {
  277. .dot = { .min = 25000, .max = 350000 },
  278. .vco = { .min = 1760000, .max = 3510000 },
  279. .n = { .min = 1, .max = 3 },
  280. .m = { .min = 79, .max = 118 },
  281. .m1 = { .min = 12, .max = 22 },
  282. .m2 = { .min = 5, .max = 9 },
  283. .p = { .min = 28, .max = 112 },
  284. .p1 = { .min = 2, .max = 8 },
  285. .p2 = { .dot_limit = 225000,
  286. .p2_slow = 14, .p2_fast = 14 },
  287. .find_pll = intel_g4x_find_best_PLL,
  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. .find_pll = intel_g4x_find_best_PLL,
  301. };
  302. /* LVDS 100mhz refclk limits. */
  303. static const intel_limit_t intel_limits_ironlake_single_lvds_100m = {
  304. .dot = { .min = 25000, .max = 350000 },
  305. .vco = { .min = 1760000, .max = 3510000 },
  306. .n = { .min = 1, .max = 2 },
  307. .m = { .min = 79, .max = 126 },
  308. .m1 = { .min = 12, .max = 22 },
  309. .m2 = { .min = 5, .max = 9 },
  310. .p = { .min = 28, .max = 112 },
  311. .p1 = { .min = 2, .max = 8 },
  312. .p2 = { .dot_limit = 225000,
  313. .p2_slow = 14, .p2_fast = 14 },
  314. .find_pll = intel_g4x_find_best_PLL,
  315. };
  316. static const intel_limit_t intel_limits_ironlake_dual_lvds_100m = {
  317. .dot = { .min = 25000, .max = 350000 },
  318. .vco = { .min = 1760000, .max = 3510000 },
  319. .n = { .min = 1, .max = 3 },
  320. .m = { .min = 79, .max = 126 },
  321. .m1 = { .min = 12, .max = 22 },
  322. .m2 = { .min = 5, .max = 9 },
  323. .p = { .min = 14, .max = 42 },
  324. .p1 = { .min = 2, .max = 6 },
  325. .p2 = { .dot_limit = 225000,
  326. .p2_slow = 7, .p2_fast = 7 },
  327. .find_pll = intel_g4x_find_best_PLL,
  328. };
  329. static const intel_limit_t intel_limits_ironlake_display_port = {
  330. .dot = { .min = 25000, .max = 350000 },
  331. .vco = { .min = 1760000, .max = 3510000},
  332. .n = { .min = 1, .max = 2 },
  333. .m = { .min = 81, .max = 90 },
  334. .m1 = { .min = 12, .max = 22 },
  335. .m2 = { .min = 5, .max = 9 },
  336. .p = { .min = 10, .max = 20 },
  337. .p1 = { .min = 1, .max = 2},
  338. .p2 = { .dot_limit = 0,
  339. .p2_slow = 10, .p2_fast = 10 },
  340. .find_pll = intel_find_pll_ironlake_dp,
  341. };
  342. static const intel_limit_t intel_limits_vlv_dac = {
  343. .dot = { .min = 25000, .max = 270000 },
  344. .vco = { .min = 4000000, .max = 6000000 },
  345. .n = { .min = 1, .max = 7 },
  346. .m = { .min = 22, .max = 450 }, /* guess */
  347. .m1 = { .min = 2, .max = 3 },
  348. .m2 = { .min = 11, .max = 156 },
  349. .p = { .min = 10, .max = 30 },
  350. .p1 = { .min = 2, .max = 3 },
  351. .p2 = { .dot_limit = 270000,
  352. .p2_slow = 2, .p2_fast = 20 },
  353. .find_pll = intel_vlv_find_best_pll,
  354. };
  355. static const intel_limit_t intel_limits_vlv_hdmi = {
  356. .dot = { .min = 20000, .max = 165000 },
  357. .vco = { .min = 4000000, .max = 5994000},
  358. .n = { .min = 1, .max = 7 },
  359. .m = { .min = 60, .max = 300 }, /* guess */
  360. .m1 = { .min = 2, .max = 3 },
  361. .m2 = { .min = 11, .max = 156 },
  362. .p = { .min = 10, .max = 30 },
  363. .p1 = { .min = 2, .max = 3 },
  364. .p2 = { .dot_limit = 270000,
  365. .p2_slow = 2, .p2_fast = 20 },
  366. .find_pll = intel_vlv_find_best_pll,
  367. };
  368. static const intel_limit_t intel_limits_vlv_dp = {
  369. .dot = { .min = 25000, .max = 270000 },
  370. .vco = { .min = 4000000, .max = 6000000 },
  371. .n = { .min = 1, .max = 7 },
  372. .m = { .min = 22, .max = 450 },
  373. .m1 = { .min = 2, .max = 3 },
  374. .m2 = { .min = 11, .max = 156 },
  375. .p = { .min = 10, .max = 30 },
  376. .p1 = { .min = 2, .max = 3 },
  377. .p2 = { .dot_limit = 270000,
  378. .p2_slow = 2, .p2_fast = 20 },
  379. .find_pll = intel_vlv_find_best_pll,
  380. };
  381. u32 intel_dpio_read(struct drm_i915_private *dev_priv, int reg)
  382. {
  383. WARN_ON(!mutex_is_locked(&dev_priv->dpio_lock));
  384. if (wait_for_atomic_us((I915_READ(DPIO_PKT) & DPIO_BUSY) == 0, 100)) {
  385. DRM_ERROR("DPIO idle wait timed out\n");
  386. return 0;
  387. }
  388. I915_WRITE(DPIO_REG, reg);
  389. I915_WRITE(DPIO_PKT, DPIO_RID | DPIO_OP_READ | DPIO_PORTID |
  390. DPIO_BYTE);
  391. if (wait_for_atomic_us((I915_READ(DPIO_PKT) & DPIO_BUSY) == 0, 100)) {
  392. DRM_ERROR("DPIO read wait timed out\n");
  393. return 0;
  394. }
  395. return I915_READ(DPIO_DATA);
  396. }
  397. static void intel_dpio_write(struct drm_i915_private *dev_priv, int reg,
  398. u32 val)
  399. {
  400. WARN_ON(!mutex_is_locked(&dev_priv->dpio_lock));
  401. if (wait_for_atomic_us((I915_READ(DPIO_PKT) & DPIO_BUSY) == 0, 100)) {
  402. DRM_ERROR("DPIO idle wait timed out\n");
  403. return;
  404. }
  405. I915_WRITE(DPIO_DATA, val);
  406. I915_WRITE(DPIO_REG, reg);
  407. I915_WRITE(DPIO_PKT, DPIO_RID | DPIO_OP_WRITE | DPIO_PORTID |
  408. DPIO_BYTE);
  409. if (wait_for_atomic_us((I915_READ(DPIO_PKT) & DPIO_BUSY) == 0, 100))
  410. DRM_ERROR("DPIO write wait timed out\n");
  411. }
  412. static void vlv_init_dpio(struct drm_device *dev)
  413. {
  414. struct drm_i915_private *dev_priv = dev->dev_private;
  415. /* Reset the DPIO config */
  416. I915_WRITE(DPIO_CTL, 0);
  417. POSTING_READ(DPIO_CTL);
  418. I915_WRITE(DPIO_CTL, 1);
  419. POSTING_READ(DPIO_CTL);
  420. }
  421. static const intel_limit_t *intel_ironlake_limit(struct drm_crtc *crtc,
  422. int refclk)
  423. {
  424. struct drm_device *dev = crtc->dev;
  425. const intel_limit_t *limit;
  426. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  427. if (intel_is_dual_link_lvds(dev)) {
  428. /* LVDS dual channel */
  429. if (refclk == 100000)
  430. limit = &intel_limits_ironlake_dual_lvds_100m;
  431. else
  432. limit = &intel_limits_ironlake_dual_lvds;
  433. } else {
  434. if (refclk == 100000)
  435. limit = &intel_limits_ironlake_single_lvds_100m;
  436. else
  437. limit = &intel_limits_ironlake_single_lvds;
  438. }
  439. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) ||
  440. intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))
  441. limit = &intel_limits_ironlake_display_port;
  442. else
  443. limit = &intel_limits_ironlake_dac;
  444. return limit;
  445. }
  446. static const intel_limit_t *intel_g4x_limit(struct drm_crtc *crtc)
  447. {
  448. struct drm_device *dev = crtc->dev;
  449. const intel_limit_t *limit;
  450. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  451. if (intel_is_dual_link_lvds(dev))
  452. /* LVDS with dual channel */
  453. limit = &intel_limits_g4x_dual_channel_lvds;
  454. else
  455. /* LVDS with dual channel */
  456. limit = &intel_limits_g4x_single_channel_lvds;
  457. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI) ||
  458. intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) {
  459. limit = &intel_limits_g4x_hdmi;
  460. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO)) {
  461. limit = &intel_limits_g4x_sdvo;
  462. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  463. limit = &intel_limits_g4x_display_port;
  464. } else /* The option is for other outputs */
  465. limit = &intel_limits_i9xx_sdvo;
  466. return limit;
  467. }
  468. static const intel_limit_t *intel_limit(struct drm_crtc *crtc, int refclk)
  469. {
  470. struct drm_device *dev = crtc->dev;
  471. const intel_limit_t *limit;
  472. if (HAS_PCH_SPLIT(dev))
  473. limit = intel_ironlake_limit(crtc, refclk);
  474. else if (IS_G4X(dev)) {
  475. limit = intel_g4x_limit(crtc);
  476. } else if (IS_PINEVIEW(dev)) {
  477. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  478. limit = &intel_limits_pineview_lvds;
  479. else
  480. limit = &intel_limits_pineview_sdvo;
  481. } else if (IS_VALLEYVIEW(dev)) {
  482. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG))
  483. limit = &intel_limits_vlv_dac;
  484. else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI))
  485. limit = &intel_limits_vlv_hdmi;
  486. else
  487. limit = &intel_limits_vlv_dp;
  488. } else if (!IS_GEN2(dev)) {
  489. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  490. limit = &intel_limits_i9xx_lvds;
  491. else
  492. limit = &intel_limits_i9xx_sdvo;
  493. } else {
  494. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  495. limit = &intel_limits_i8xx_lvds;
  496. else
  497. limit = &intel_limits_i8xx_dvo;
  498. }
  499. return limit;
  500. }
  501. /* m1 is reserved as 0 in Pineview, n is a ring counter */
  502. static void pineview_clock(int refclk, intel_clock_t *clock)
  503. {
  504. clock->m = clock->m2 + 2;
  505. clock->p = clock->p1 * clock->p2;
  506. clock->vco = refclk * clock->m / clock->n;
  507. clock->dot = clock->vco / clock->p;
  508. }
  509. static void intel_clock(struct drm_device *dev, int refclk, intel_clock_t *clock)
  510. {
  511. if (IS_PINEVIEW(dev)) {
  512. pineview_clock(refclk, clock);
  513. return;
  514. }
  515. clock->m = 5 * (clock->m1 + 2) + (clock->m2 + 2);
  516. clock->p = clock->p1 * clock->p2;
  517. clock->vco = refclk * clock->m / (clock->n + 2);
  518. clock->dot = clock->vco / clock->p;
  519. }
  520. /**
  521. * Returns whether any output on the specified pipe is of the specified type
  522. */
  523. bool intel_pipe_has_type(struct drm_crtc *crtc, int type)
  524. {
  525. struct drm_device *dev = crtc->dev;
  526. struct intel_encoder *encoder;
  527. for_each_encoder_on_crtc(dev, crtc, encoder)
  528. if (encoder->type == type)
  529. return true;
  530. return false;
  531. }
  532. #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
  533. /**
  534. * Returns whether the given set of divisors are valid for a given refclk with
  535. * the given connectors.
  536. */
  537. static bool intel_PLL_is_valid(struct drm_device *dev,
  538. const intel_limit_t *limit,
  539. const intel_clock_t *clock)
  540. {
  541. if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
  542. INTELPllInvalid("p1 out of range\n");
  543. if (clock->p < limit->p.min || limit->p.max < clock->p)
  544. INTELPllInvalid("p out of range\n");
  545. if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
  546. INTELPllInvalid("m2 out of range\n");
  547. if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
  548. INTELPllInvalid("m1 out of range\n");
  549. if (clock->m1 <= clock->m2 && !IS_PINEVIEW(dev))
  550. INTELPllInvalid("m1 <= m2\n");
  551. if (clock->m < limit->m.min || limit->m.max < clock->m)
  552. INTELPllInvalid("m out of range\n");
  553. if (clock->n < limit->n.min || limit->n.max < clock->n)
  554. INTELPllInvalid("n out of range\n");
  555. if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
  556. INTELPllInvalid("vco out of range\n");
  557. /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
  558. * connector, etc., rather than just a single range.
  559. */
  560. if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
  561. INTELPllInvalid("dot out of range\n");
  562. return true;
  563. }
  564. static bool
  565. intel_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
  566. int target, int refclk, intel_clock_t *match_clock,
  567. intel_clock_t *best_clock)
  568. {
  569. struct drm_device *dev = crtc->dev;
  570. intel_clock_t clock;
  571. int err = target;
  572. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  573. /*
  574. * For LVDS just rely on its current settings for dual-channel.
  575. * We haven't figured out how to reliably set up different
  576. * single/dual channel state, if we even can.
  577. */
  578. if (intel_is_dual_link_lvds(dev))
  579. clock.p2 = limit->p2.p2_fast;
  580. else
  581. clock.p2 = limit->p2.p2_slow;
  582. } else {
  583. if (target < limit->p2.dot_limit)
  584. clock.p2 = limit->p2.p2_slow;
  585. else
  586. clock.p2 = limit->p2.p2_fast;
  587. }
  588. memset(best_clock, 0, sizeof(*best_clock));
  589. for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
  590. clock.m1++) {
  591. for (clock.m2 = limit->m2.min;
  592. clock.m2 <= limit->m2.max; clock.m2++) {
  593. /* m1 is always 0 in Pineview */
  594. if (clock.m2 >= clock.m1 && !IS_PINEVIEW(dev))
  595. break;
  596. for (clock.n = limit->n.min;
  597. clock.n <= limit->n.max; clock.n++) {
  598. for (clock.p1 = limit->p1.min;
  599. clock.p1 <= limit->p1.max; clock.p1++) {
  600. int this_err;
  601. intel_clock(dev, refclk, &clock);
  602. if (!intel_PLL_is_valid(dev, limit,
  603. &clock))
  604. continue;
  605. if (match_clock &&
  606. clock.p != match_clock->p)
  607. continue;
  608. this_err = abs(clock.dot - target);
  609. if (this_err < err) {
  610. *best_clock = clock;
  611. err = this_err;
  612. }
  613. }
  614. }
  615. }
  616. }
  617. return (err != target);
  618. }
  619. static bool
  620. intel_g4x_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
  621. int target, int refclk, intel_clock_t *match_clock,
  622. intel_clock_t *best_clock)
  623. {
  624. struct drm_device *dev = crtc->dev;
  625. intel_clock_t clock;
  626. int max_n;
  627. bool found;
  628. /* approximately equals target * 0.00585 */
  629. int err_most = (target >> 8) + (target >> 9);
  630. found = false;
  631. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  632. int lvds_reg;
  633. if (HAS_PCH_SPLIT(dev))
  634. lvds_reg = PCH_LVDS;
  635. else
  636. lvds_reg = LVDS;
  637. if (intel_is_dual_link_lvds(dev))
  638. clock.p2 = limit->p2.p2_fast;
  639. else
  640. clock.p2 = limit->p2.p2_slow;
  641. } else {
  642. if (target < limit->p2.dot_limit)
  643. clock.p2 = limit->p2.p2_slow;
  644. else
  645. clock.p2 = limit->p2.p2_fast;
  646. }
  647. memset(best_clock, 0, sizeof(*best_clock));
  648. max_n = limit->n.max;
  649. /* based on hardware requirement, prefer smaller n to precision */
  650. for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
  651. /* based on hardware requirement, prefere larger m1,m2 */
  652. for (clock.m1 = limit->m1.max;
  653. clock.m1 >= limit->m1.min; clock.m1--) {
  654. for (clock.m2 = limit->m2.max;
  655. clock.m2 >= limit->m2.min; clock.m2--) {
  656. for (clock.p1 = limit->p1.max;
  657. clock.p1 >= limit->p1.min; clock.p1--) {
  658. int this_err;
  659. intel_clock(dev, refclk, &clock);
  660. if (!intel_PLL_is_valid(dev, limit,
  661. &clock))
  662. continue;
  663. if (match_clock &&
  664. clock.p != match_clock->p)
  665. continue;
  666. this_err = abs(clock.dot - target);
  667. if (this_err < err_most) {
  668. *best_clock = clock;
  669. err_most = this_err;
  670. max_n = clock.n;
  671. found = true;
  672. }
  673. }
  674. }
  675. }
  676. }
  677. return found;
  678. }
  679. static bool
  680. intel_find_pll_ironlake_dp(const intel_limit_t *limit, struct drm_crtc *crtc,
  681. int target, int refclk, intel_clock_t *match_clock,
  682. intel_clock_t *best_clock)
  683. {
  684. struct drm_device *dev = crtc->dev;
  685. intel_clock_t clock;
  686. if (target < 200000) {
  687. clock.n = 1;
  688. clock.p1 = 2;
  689. clock.p2 = 10;
  690. clock.m1 = 12;
  691. clock.m2 = 9;
  692. } else {
  693. clock.n = 2;
  694. clock.p1 = 1;
  695. clock.p2 = 10;
  696. clock.m1 = 14;
  697. clock.m2 = 8;
  698. }
  699. intel_clock(dev, refclk, &clock);
  700. memcpy(best_clock, &clock, sizeof(intel_clock_t));
  701. return true;
  702. }
  703. /* DisplayPort has only two frequencies, 162MHz and 270MHz */
  704. static bool
  705. intel_find_pll_g4x_dp(const intel_limit_t *limit, struct drm_crtc *crtc,
  706. int target, int refclk, intel_clock_t *match_clock,
  707. intel_clock_t *best_clock)
  708. {
  709. intel_clock_t clock;
  710. if (target < 200000) {
  711. clock.p1 = 2;
  712. clock.p2 = 10;
  713. clock.n = 2;
  714. clock.m1 = 23;
  715. clock.m2 = 8;
  716. } else {
  717. clock.p1 = 1;
  718. clock.p2 = 10;
  719. clock.n = 1;
  720. clock.m1 = 14;
  721. clock.m2 = 2;
  722. }
  723. clock.m = 5 * (clock.m1 + 2) + (clock.m2 + 2);
  724. clock.p = (clock.p1 * clock.p2);
  725. clock.dot = 96000 * clock.m / (clock.n + 2) / clock.p;
  726. clock.vco = 0;
  727. memcpy(best_clock, &clock, sizeof(intel_clock_t));
  728. return true;
  729. }
  730. static bool
  731. intel_vlv_find_best_pll(const intel_limit_t *limit, struct drm_crtc *crtc,
  732. int target, int refclk, intel_clock_t *match_clock,
  733. intel_clock_t *best_clock)
  734. {
  735. u32 p1, p2, m1, m2, vco, bestn, bestm1, bestm2, bestp1, bestp2;
  736. u32 m, n, fastclk;
  737. u32 updrate, minupdate, fracbits, p;
  738. unsigned long bestppm, ppm, absppm;
  739. int dotclk, flag;
  740. flag = 0;
  741. dotclk = target * 1000;
  742. bestppm = 1000000;
  743. ppm = absppm = 0;
  744. fastclk = dotclk / (2*100);
  745. updrate = 0;
  746. minupdate = 19200;
  747. fracbits = 1;
  748. n = p = p1 = p2 = m = m1 = m2 = vco = bestn = 0;
  749. bestm1 = bestm2 = bestp1 = bestp2 = 0;
  750. /* based on hardware requirement, prefer smaller n to precision */
  751. for (n = limit->n.min; n <= ((refclk) / minupdate); n++) {
  752. updrate = refclk / n;
  753. for (p1 = limit->p1.max; p1 > limit->p1.min; p1--) {
  754. for (p2 = limit->p2.p2_fast+1; p2 > 0; p2--) {
  755. if (p2 > 10)
  756. p2 = p2 - 1;
  757. p = p1 * p2;
  758. /* based on hardware requirement, prefer bigger m1,m2 values */
  759. for (m1 = limit->m1.min; m1 <= limit->m1.max; m1++) {
  760. m2 = (((2*(fastclk * p * n / m1 )) +
  761. refclk) / (2*refclk));
  762. m = m1 * m2;
  763. vco = updrate * m;
  764. if (vco >= limit->vco.min && vco < limit->vco.max) {
  765. ppm = 1000000 * ((vco / p) - fastclk) / fastclk;
  766. absppm = (ppm > 0) ? ppm : (-ppm);
  767. if (absppm < 100 && ((p1 * p2) > (bestp1 * bestp2))) {
  768. bestppm = 0;
  769. flag = 1;
  770. }
  771. if (absppm < bestppm - 10) {
  772. bestppm = absppm;
  773. flag = 1;
  774. }
  775. if (flag) {
  776. bestn = n;
  777. bestm1 = m1;
  778. bestm2 = m2;
  779. bestp1 = p1;
  780. bestp2 = p2;
  781. flag = 0;
  782. }
  783. }
  784. }
  785. }
  786. }
  787. }
  788. best_clock->n = bestn;
  789. best_clock->m1 = bestm1;
  790. best_clock->m2 = bestm2;
  791. best_clock->p1 = bestp1;
  792. best_clock->p2 = bestp2;
  793. return true;
  794. }
  795. enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv,
  796. enum pipe pipe)
  797. {
  798. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  799. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  800. return intel_crtc->cpu_transcoder;
  801. }
  802. static void ironlake_wait_for_vblank(struct drm_device *dev, int pipe)
  803. {
  804. struct drm_i915_private *dev_priv = dev->dev_private;
  805. u32 frame, frame_reg = PIPEFRAME(pipe);
  806. frame = I915_READ(frame_reg);
  807. if (wait_for(I915_READ_NOTRACE(frame_reg) != frame, 50))
  808. DRM_DEBUG_KMS("vblank wait timed out\n");
  809. }
  810. /**
  811. * intel_wait_for_vblank - wait for vblank on a given pipe
  812. * @dev: drm device
  813. * @pipe: pipe to wait for
  814. *
  815. * Wait for vblank to occur on a given pipe. Needed for various bits of
  816. * mode setting code.
  817. */
  818. void intel_wait_for_vblank(struct drm_device *dev, int pipe)
  819. {
  820. struct drm_i915_private *dev_priv = dev->dev_private;
  821. int pipestat_reg = PIPESTAT(pipe);
  822. if (INTEL_INFO(dev)->gen >= 5) {
  823. ironlake_wait_for_vblank(dev, pipe);
  824. return;
  825. }
  826. /* Clear existing vblank status. Note this will clear any other
  827. * sticky status fields as well.
  828. *
  829. * This races with i915_driver_irq_handler() with the result
  830. * that either function could miss a vblank event. Here it is not
  831. * fatal, as we will either wait upon the next vblank interrupt or
  832. * timeout. Generally speaking intel_wait_for_vblank() is only
  833. * called during modeset at which time the GPU should be idle and
  834. * should *not* be performing page flips and thus not waiting on
  835. * vblanks...
  836. * Currently, the result of us stealing a vblank from the irq
  837. * handler is that a single frame will be skipped during swapbuffers.
  838. */
  839. I915_WRITE(pipestat_reg,
  840. I915_READ(pipestat_reg) | PIPE_VBLANK_INTERRUPT_STATUS);
  841. /* Wait for vblank interrupt bit to set */
  842. if (wait_for(I915_READ(pipestat_reg) &
  843. PIPE_VBLANK_INTERRUPT_STATUS,
  844. 50))
  845. DRM_DEBUG_KMS("vblank wait timed out\n");
  846. }
  847. /*
  848. * intel_wait_for_pipe_off - wait for pipe to turn off
  849. * @dev: drm device
  850. * @pipe: pipe to wait for
  851. *
  852. * After disabling a pipe, we can't wait for vblank in the usual way,
  853. * spinning on the vblank interrupt status bit, since we won't actually
  854. * see an interrupt when the pipe is disabled.
  855. *
  856. * On Gen4 and above:
  857. * wait for the pipe register state bit to turn off
  858. *
  859. * Otherwise:
  860. * wait for the display line value to settle (it usually
  861. * ends up stopping at the start of the next frame).
  862. *
  863. */
  864. void intel_wait_for_pipe_off(struct drm_device *dev, int pipe)
  865. {
  866. struct drm_i915_private *dev_priv = dev->dev_private;
  867. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  868. pipe);
  869. if (INTEL_INFO(dev)->gen >= 4) {
  870. int reg = PIPECONF(cpu_transcoder);
  871. /* Wait for the Pipe State to go off */
  872. if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0,
  873. 100))
  874. WARN(1, "pipe_off wait timed out\n");
  875. } else {
  876. u32 last_line, line_mask;
  877. int reg = PIPEDSL(pipe);
  878. unsigned long timeout = jiffies + msecs_to_jiffies(100);
  879. if (IS_GEN2(dev))
  880. line_mask = DSL_LINEMASK_GEN2;
  881. else
  882. line_mask = DSL_LINEMASK_GEN3;
  883. /* Wait for the display line to settle */
  884. do {
  885. last_line = I915_READ(reg) & line_mask;
  886. mdelay(5);
  887. } while (((I915_READ(reg) & line_mask) != last_line) &&
  888. time_after(timeout, jiffies));
  889. if (time_after(jiffies, timeout))
  890. WARN(1, "pipe_off wait timed out\n");
  891. }
  892. }
  893. /*
  894. * ibx_digital_port_connected - is the specified port connected?
  895. * @dev_priv: i915 private structure
  896. * @port: the port to test
  897. *
  898. * Returns true if @port is connected, false otherwise.
  899. */
  900. bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
  901. struct intel_digital_port *port)
  902. {
  903. u32 bit;
  904. if (HAS_PCH_IBX(dev_priv->dev)) {
  905. switch(port->port) {
  906. case PORT_B:
  907. bit = SDE_PORTB_HOTPLUG;
  908. break;
  909. case PORT_C:
  910. bit = SDE_PORTC_HOTPLUG;
  911. break;
  912. case PORT_D:
  913. bit = SDE_PORTD_HOTPLUG;
  914. break;
  915. default:
  916. return true;
  917. }
  918. } else {
  919. switch(port->port) {
  920. case PORT_B:
  921. bit = SDE_PORTB_HOTPLUG_CPT;
  922. break;
  923. case PORT_C:
  924. bit = SDE_PORTC_HOTPLUG_CPT;
  925. break;
  926. case PORT_D:
  927. bit = SDE_PORTD_HOTPLUG_CPT;
  928. break;
  929. default:
  930. return true;
  931. }
  932. }
  933. return I915_READ(SDEISR) & bit;
  934. }
  935. static const char *state_string(bool enabled)
  936. {
  937. return enabled ? "on" : "off";
  938. }
  939. /* Only for pre-ILK configs */
  940. static void assert_pll(struct drm_i915_private *dev_priv,
  941. enum pipe pipe, bool state)
  942. {
  943. int reg;
  944. u32 val;
  945. bool cur_state;
  946. reg = DPLL(pipe);
  947. val = I915_READ(reg);
  948. cur_state = !!(val & DPLL_VCO_ENABLE);
  949. WARN(cur_state != state,
  950. "PLL state assertion failure (expected %s, current %s)\n",
  951. state_string(state), state_string(cur_state));
  952. }
  953. #define assert_pll_enabled(d, p) assert_pll(d, p, true)
  954. #define assert_pll_disabled(d, p) assert_pll(d, p, false)
  955. /* For ILK+ */
  956. static void assert_pch_pll(struct drm_i915_private *dev_priv,
  957. struct intel_pch_pll *pll,
  958. struct intel_crtc *crtc,
  959. bool state)
  960. {
  961. u32 val;
  962. bool cur_state;
  963. if (HAS_PCH_LPT(dev_priv->dev)) {
  964. DRM_DEBUG_DRIVER("LPT detected: skipping PCH PLL test\n");
  965. return;
  966. }
  967. if (WARN (!pll,
  968. "asserting PCH PLL %s with no PLL\n", state_string(state)))
  969. return;
  970. val = I915_READ(pll->pll_reg);
  971. cur_state = !!(val & DPLL_VCO_ENABLE);
  972. WARN(cur_state != state,
  973. "PCH PLL state for reg %x assertion failure (expected %s, current %s), val=%08x\n",
  974. pll->pll_reg, state_string(state), state_string(cur_state), val);
  975. /* Make sure the selected PLL is correctly attached to the transcoder */
  976. if (crtc && HAS_PCH_CPT(dev_priv->dev)) {
  977. u32 pch_dpll;
  978. pch_dpll = I915_READ(PCH_DPLL_SEL);
  979. cur_state = pll->pll_reg == _PCH_DPLL_B;
  980. if (!WARN(((pch_dpll >> (4 * crtc->pipe)) & 1) != cur_state,
  981. "PLL[%d] not attached to this transcoder %d: %08x\n",
  982. cur_state, crtc->pipe, pch_dpll)) {
  983. cur_state = !!(val >> (4*crtc->pipe + 3));
  984. WARN(cur_state != state,
  985. "PLL[%d] not %s on this transcoder %d: %08x\n",
  986. pll->pll_reg == _PCH_DPLL_B,
  987. state_string(state),
  988. crtc->pipe,
  989. val);
  990. }
  991. }
  992. }
  993. #define assert_pch_pll_enabled(d, p, c) assert_pch_pll(d, p, c, true)
  994. #define assert_pch_pll_disabled(d, p, c) assert_pch_pll(d, p, c, false)
  995. static void assert_fdi_tx(struct drm_i915_private *dev_priv,
  996. enum pipe pipe, bool state)
  997. {
  998. int reg;
  999. u32 val;
  1000. bool cur_state;
  1001. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  1002. pipe);
  1003. if (HAS_DDI(dev_priv->dev)) {
  1004. /* DDI does not have a specific FDI_TX register */
  1005. reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
  1006. val = I915_READ(reg);
  1007. cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
  1008. } else {
  1009. reg = FDI_TX_CTL(pipe);
  1010. val = I915_READ(reg);
  1011. cur_state = !!(val & FDI_TX_ENABLE);
  1012. }
  1013. WARN(cur_state != state,
  1014. "FDI TX state assertion failure (expected %s, current %s)\n",
  1015. state_string(state), state_string(cur_state));
  1016. }
  1017. #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
  1018. #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
  1019. static void assert_fdi_rx(struct drm_i915_private *dev_priv,
  1020. enum pipe pipe, bool state)
  1021. {
  1022. int reg;
  1023. u32 val;
  1024. bool cur_state;
  1025. reg = FDI_RX_CTL(pipe);
  1026. val = I915_READ(reg);
  1027. cur_state = !!(val & FDI_RX_ENABLE);
  1028. WARN(cur_state != state,
  1029. "FDI RX state assertion failure (expected %s, current %s)\n",
  1030. state_string(state), state_string(cur_state));
  1031. }
  1032. #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
  1033. #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
  1034. static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
  1035. enum pipe pipe)
  1036. {
  1037. int reg;
  1038. u32 val;
  1039. /* ILK FDI PLL is always enabled */
  1040. if (dev_priv->info->gen == 5)
  1041. return;
  1042. /* On Haswell, DDI ports are responsible for the FDI PLL setup */
  1043. if (HAS_DDI(dev_priv->dev))
  1044. return;
  1045. reg = FDI_TX_CTL(pipe);
  1046. val = I915_READ(reg);
  1047. WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n");
  1048. }
  1049. static void assert_fdi_rx_pll_enabled(struct drm_i915_private *dev_priv,
  1050. enum pipe pipe)
  1051. {
  1052. int reg;
  1053. u32 val;
  1054. reg = FDI_RX_CTL(pipe);
  1055. val = I915_READ(reg);
  1056. WARN(!(val & FDI_RX_PLL_ENABLE), "FDI RX PLL assertion failure, should be active but is disabled\n");
  1057. }
  1058. static void assert_panel_unlocked(struct drm_i915_private *dev_priv,
  1059. enum pipe pipe)
  1060. {
  1061. int pp_reg, lvds_reg;
  1062. u32 val;
  1063. enum pipe panel_pipe = PIPE_A;
  1064. bool locked = true;
  1065. if (HAS_PCH_SPLIT(dev_priv->dev)) {
  1066. pp_reg = PCH_PP_CONTROL;
  1067. lvds_reg = PCH_LVDS;
  1068. } else {
  1069. pp_reg = PP_CONTROL;
  1070. lvds_reg = LVDS;
  1071. }
  1072. val = I915_READ(pp_reg);
  1073. if (!(val & PANEL_POWER_ON) ||
  1074. ((val & PANEL_UNLOCK_REGS) == PANEL_UNLOCK_REGS))
  1075. locked = false;
  1076. if (I915_READ(lvds_reg) & LVDS_PIPEB_SELECT)
  1077. panel_pipe = PIPE_B;
  1078. WARN(panel_pipe == pipe && locked,
  1079. "panel assertion failure, pipe %c regs locked\n",
  1080. pipe_name(pipe));
  1081. }
  1082. void assert_pipe(struct drm_i915_private *dev_priv,
  1083. enum pipe pipe, bool state)
  1084. {
  1085. int reg;
  1086. u32 val;
  1087. bool cur_state;
  1088. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  1089. pipe);
  1090. /* if we need the pipe A quirk it must be always on */
  1091. if (pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE)
  1092. state = true;
  1093. if (IS_HASWELL(dev_priv->dev) && cpu_transcoder != TRANSCODER_EDP &&
  1094. !(I915_READ(HSW_PWR_WELL_DRIVER) & HSW_PWR_WELL_ENABLE)) {
  1095. cur_state = false;
  1096. } else {
  1097. reg = PIPECONF(cpu_transcoder);
  1098. val = I915_READ(reg);
  1099. cur_state = !!(val & PIPECONF_ENABLE);
  1100. }
  1101. WARN(cur_state != state,
  1102. "pipe %c assertion failure (expected %s, current %s)\n",
  1103. pipe_name(pipe), state_string(state), state_string(cur_state));
  1104. }
  1105. static void assert_plane(struct drm_i915_private *dev_priv,
  1106. enum plane plane, bool state)
  1107. {
  1108. int reg;
  1109. u32 val;
  1110. bool cur_state;
  1111. reg = DSPCNTR(plane);
  1112. val = I915_READ(reg);
  1113. cur_state = !!(val & DISPLAY_PLANE_ENABLE);
  1114. WARN(cur_state != state,
  1115. "plane %c assertion failure (expected %s, current %s)\n",
  1116. plane_name(plane), state_string(state), state_string(cur_state));
  1117. }
  1118. #define assert_plane_enabled(d, p) assert_plane(d, p, true)
  1119. #define assert_plane_disabled(d, p) assert_plane(d, p, false)
  1120. static void assert_planes_disabled(struct drm_i915_private *dev_priv,
  1121. enum pipe pipe)
  1122. {
  1123. int reg, i;
  1124. u32 val;
  1125. int cur_pipe;
  1126. /* Planes are fixed to pipes on ILK+ */
  1127. if (HAS_PCH_SPLIT(dev_priv->dev)) {
  1128. reg = DSPCNTR(pipe);
  1129. val = I915_READ(reg);
  1130. WARN((val & DISPLAY_PLANE_ENABLE),
  1131. "plane %c assertion failure, should be disabled but not\n",
  1132. plane_name(pipe));
  1133. return;
  1134. }
  1135. /* Need to check both planes against the pipe */
  1136. for (i = 0; i < 2; i++) {
  1137. reg = DSPCNTR(i);
  1138. val = I915_READ(reg);
  1139. cur_pipe = (val & DISPPLANE_SEL_PIPE_MASK) >>
  1140. DISPPLANE_SEL_PIPE_SHIFT;
  1141. WARN((val & DISPLAY_PLANE_ENABLE) && pipe == cur_pipe,
  1142. "plane %c assertion failure, should be off on pipe %c but is still active\n",
  1143. plane_name(i), pipe_name(pipe));
  1144. }
  1145. }
  1146. static void assert_pch_refclk_enabled(struct drm_i915_private *dev_priv)
  1147. {
  1148. u32 val;
  1149. bool enabled;
  1150. if (HAS_PCH_LPT(dev_priv->dev)) {
  1151. DRM_DEBUG_DRIVER("LPT does not has PCH refclk, skipping check\n");
  1152. return;
  1153. }
  1154. val = I915_READ(PCH_DREF_CONTROL);
  1155. enabled = !!(val & (DREF_SSC_SOURCE_MASK | DREF_NONSPREAD_SOURCE_MASK |
  1156. DREF_SUPERSPREAD_SOURCE_MASK));
  1157. WARN(!enabled, "PCH refclk assertion failure, should be active but is disabled\n");
  1158. }
  1159. static void assert_transcoder_disabled(struct drm_i915_private *dev_priv,
  1160. enum pipe pipe)
  1161. {
  1162. int reg;
  1163. u32 val;
  1164. bool enabled;
  1165. reg = TRANSCONF(pipe);
  1166. val = I915_READ(reg);
  1167. enabled = !!(val & TRANS_ENABLE);
  1168. WARN(enabled,
  1169. "transcoder assertion failed, should be off on pipe %c but is still active\n",
  1170. pipe_name(pipe));
  1171. }
  1172. static bool dp_pipe_enabled(struct drm_i915_private *dev_priv,
  1173. enum pipe pipe, u32 port_sel, u32 val)
  1174. {
  1175. if ((val & DP_PORT_EN) == 0)
  1176. return false;
  1177. if (HAS_PCH_CPT(dev_priv->dev)) {
  1178. u32 trans_dp_ctl_reg = TRANS_DP_CTL(pipe);
  1179. u32 trans_dp_ctl = I915_READ(trans_dp_ctl_reg);
  1180. if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel)
  1181. return false;
  1182. } else {
  1183. if ((val & DP_PIPE_MASK) != (pipe << 30))
  1184. return false;
  1185. }
  1186. return true;
  1187. }
  1188. static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv,
  1189. enum pipe pipe, u32 val)
  1190. {
  1191. if ((val & PORT_ENABLE) == 0)
  1192. return false;
  1193. if (HAS_PCH_CPT(dev_priv->dev)) {
  1194. if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
  1195. return false;
  1196. } else {
  1197. if ((val & TRANSCODER_MASK) != TRANSCODER(pipe))
  1198. return false;
  1199. }
  1200. return true;
  1201. }
  1202. static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv,
  1203. enum pipe pipe, u32 val)
  1204. {
  1205. if ((val & LVDS_PORT_EN) == 0)
  1206. return false;
  1207. if (HAS_PCH_CPT(dev_priv->dev)) {
  1208. if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
  1209. return false;
  1210. } else {
  1211. if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe))
  1212. return false;
  1213. }
  1214. return true;
  1215. }
  1216. static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv,
  1217. enum pipe pipe, u32 val)
  1218. {
  1219. if ((val & ADPA_DAC_ENABLE) == 0)
  1220. return false;
  1221. if (HAS_PCH_CPT(dev_priv->dev)) {
  1222. if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
  1223. return false;
  1224. } else {
  1225. if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe))
  1226. return false;
  1227. }
  1228. return true;
  1229. }
  1230. static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
  1231. enum pipe pipe, int reg, u32 port_sel)
  1232. {
  1233. u32 val = I915_READ(reg);
  1234. WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val),
  1235. "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
  1236. reg, pipe_name(pipe));
  1237. WARN(HAS_PCH_IBX(dev_priv->dev) && (val & DP_PORT_EN) == 0
  1238. && (val & DP_PIPEB_SELECT),
  1239. "IBX PCH dp port still using transcoder B\n");
  1240. }
  1241. static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
  1242. enum pipe pipe, int reg)
  1243. {
  1244. u32 val = I915_READ(reg);
  1245. WARN(hdmi_pipe_enabled(dev_priv, pipe, val),
  1246. "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
  1247. reg, pipe_name(pipe));
  1248. WARN(HAS_PCH_IBX(dev_priv->dev) && (val & PORT_ENABLE) == 0
  1249. && (val & SDVO_PIPE_B_SELECT),
  1250. "IBX PCH hdmi port still using transcoder B\n");
  1251. }
  1252. static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
  1253. enum pipe pipe)
  1254. {
  1255. int reg;
  1256. u32 val;
  1257. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B);
  1258. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C);
  1259. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_D, TRANS_DP_PORT_SEL_D);
  1260. reg = PCH_ADPA;
  1261. val = I915_READ(reg);
  1262. WARN(adpa_pipe_enabled(dev_priv, pipe, val),
  1263. "PCH VGA enabled on transcoder %c, should be disabled\n",
  1264. pipe_name(pipe));
  1265. reg = PCH_LVDS;
  1266. val = I915_READ(reg);
  1267. WARN(lvds_pipe_enabled(dev_priv, pipe, val),
  1268. "PCH LVDS enabled on transcoder %c, should be disabled\n",
  1269. pipe_name(pipe));
  1270. assert_pch_hdmi_disabled(dev_priv, pipe, HDMIB);
  1271. assert_pch_hdmi_disabled(dev_priv, pipe, HDMIC);
  1272. assert_pch_hdmi_disabled(dev_priv, pipe, HDMID);
  1273. }
  1274. /**
  1275. * intel_enable_pll - enable a PLL
  1276. * @dev_priv: i915 private structure
  1277. * @pipe: pipe PLL to enable
  1278. *
  1279. * Enable @pipe's PLL so we can start pumping pixels from a plane. Check to
  1280. * make sure the PLL reg is writable first though, since the panel write
  1281. * protect mechanism may be enabled.
  1282. *
  1283. * Note! This is for pre-ILK only.
  1284. *
  1285. * Unfortunately needed by dvo_ns2501 since the dvo depends on it running.
  1286. */
  1287. static void intel_enable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
  1288. {
  1289. int reg;
  1290. u32 val;
  1291. /* No really, not for ILK+ */
  1292. BUG_ON(!IS_VALLEYVIEW(dev_priv->dev) && dev_priv->info->gen >= 5);
  1293. /* PLL is protected by panel, make sure we can write it */
  1294. if (IS_MOBILE(dev_priv->dev) && !IS_I830(dev_priv->dev))
  1295. assert_panel_unlocked(dev_priv, pipe);
  1296. reg = DPLL(pipe);
  1297. val = I915_READ(reg);
  1298. val |= DPLL_VCO_ENABLE;
  1299. /* We do this three times for luck */
  1300. I915_WRITE(reg, val);
  1301. POSTING_READ(reg);
  1302. udelay(150); /* wait for warmup */
  1303. I915_WRITE(reg, val);
  1304. POSTING_READ(reg);
  1305. udelay(150); /* wait for warmup */
  1306. I915_WRITE(reg, val);
  1307. POSTING_READ(reg);
  1308. udelay(150); /* wait for warmup */
  1309. }
  1310. /**
  1311. * intel_disable_pll - disable a PLL
  1312. * @dev_priv: i915 private structure
  1313. * @pipe: pipe PLL to disable
  1314. *
  1315. * Disable the PLL for @pipe, making sure the pipe is off first.
  1316. *
  1317. * Note! This is for pre-ILK only.
  1318. */
  1319. static void intel_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
  1320. {
  1321. int reg;
  1322. u32 val;
  1323. /* Don't disable pipe A or pipe A PLLs if needed */
  1324. if (pipe == PIPE_A && (dev_priv->quirks & QUIRK_PIPEA_FORCE))
  1325. return;
  1326. /* Make sure the pipe isn't still relying on us */
  1327. assert_pipe_disabled(dev_priv, pipe);
  1328. reg = DPLL(pipe);
  1329. val = I915_READ(reg);
  1330. val &= ~DPLL_VCO_ENABLE;
  1331. I915_WRITE(reg, val);
  1332. POSTING_READ(reg);
  1333. }
  1334. /* SBI access */
  1335. static void
  1336. intel_sbi_write(struct drm_i915_private *dev_priv, u16 reg, u32 value,
  1337. enum intel_sbi_destination destination)
  1338. {
  1339. u32 tmp;
  1340. WARN_ON(!mutex_is_locked(&dev_priv->dpio_lock));
  1341. if (wait_for((I915_READ(SBI_CTL_STAT) & SBI_BUSY) == 0,
  1342. 100)) {
  1343. DRM_ERROR("timeout waiting for SBI to become ready\n");
  1344. return;
  1345. }
  1346. I915_WRITE(SBI_ADDR, (reg << 16));
  1347. I915_WRITE(SBI_DATA, value);
  1348. if (destination == SBI_ICLK)
  1349. tmp = SBI_CTL_DEST_ICLK | SBI_CTL_OP_CRWR;
  1350. else
  1351. tmp = SBI_CTL_DEST_MPHY | SBI_CTL_OP_IOWR;
  1352. I915_WRITE(SBI_CTL_STAT, SBI_BUSY | tmp);
  1353. if (wait_for((I915_READ(SBI_CTL_STAT) & (SBI_BUSY | SBI_RESPONSE_FAIL)) == 0,
  1354. 100)) {
  1355. DRM_ERROR("timeout waiting for SBI to complete write transaction\n");
  1356. return;
  1357. }
  1358. }
  1359. static u32
  1360. intel_sbi_read(struct drm_i915_private *dev_priv, u16 reg,
  1361. enum intel_sbi_destination destination)
  1362. {
  1363. u32 value = 0;
  1364. WARN_ON(!mutex_is_locked(&dev_priv->dpio_lock));
  1365. if (wait_for((I915_READ(SBI_CTL_STAT) & SBI_BUSY) == 0,
  1366. 100)) {
  1367. DRM_ERROR("timeout waiting for SBI to become ready\n");
  1368. return 0;
  1369. }
  1370. I915_WRITE(SBI_ADDR, (reg << 16));
  1371. if (destination == SBI_ICLK)
  1372. value = SBI_CTL_DEST_ICLK | SBI_CTL_OP_CRRD;
  1373. else
  1374. value = SBI_CTL_DEST_MPHY | SBI_CTL_OP_IORD;
  1375. I915_WRITE(SBI_CTL_STAT, value | SBI_BUSY);
  1376. if (wait_for((I915_READ(SBI_CTL_STAT) & (SBI_BUSY | SBI_RESPONSE_FAIL)) == 0,
  1377. 100)) {
  1378. DRM_ERROR("timeout waiting for SBI to complete read transaction\n");
  1379. return 0;
  1380. }
  1381. return I915_READ(SBI_DATA);
  1382. }
  1383. /**
  1384. * ironlake_enable_pch_pll - enable PCH PLL
  1385. * @dev_priv: i915 private structure
  1386. * @pipe: pipe PLL to enable
  1387. *
  1388. * The PCH PLL needs to be enabled before the PCH transcoder, since it
  1389. * drives the transcoder clock.
  1390. */
  1391. static void ironlake_enable_pch_pll(struct intel_crtc *intel_crtc)
  1392. {
  1393. struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private;
  1394. struct intel_pch_pll *pll;
  1395. int reg;
  1396. u32 val;
  1397. /* PCH PLLs only available on ILK, SNB and IVB */
  1398. BUG_ON(dev_priv->info->gen < 5);
  1399. pll = intel_crtc->pch_pll;
  1400. if (pll == NULL)
  1401. return;
  1402. if (WARN_ON(pll->refcount == 0))
  1403. return;
  1404. DRM_DEBUG_KMS("enable PCH PLL %x (active %d, on? %d)for crtc %d\n",
  1405. pll->pll_reg, pll->active, pll->on,
  1406. intel_crtc->base.base.id);
  1407. /* PCH refclock must be enabled first */
  1408. assert_pch_refclk_enabled(dev_priv);
  1409. if (pll->active++ && pll->on) {
  1410. assert_pch_pll_enabled(dev_priv, pll, NULL);
  1411. return;
  1412. }
  1413. DRM_DEBUG_KMS("enabling PCH PLL %x\n", pll->pll_reg);
  1414. reg = pll->pll_reg;
  1415. val = I915_READ(reg);
  1416. val |= DPLL_VCO_ENABLE;
  1417. I915_WRITE(reg, val);
  1418. POSTING_READ(reg);
  1419. udelay(200);
  1420. pll->on = true;
  1421. }
  1422. static void intel_disable_pch_pll(struct intel_crtc *intel_crtc)
  1423. {
  1424. struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private;
  1425. struct intel_pch_pll *pll = intel_crtc->pch_pll;
  1426. int reg;
  1427. u32 val;
  1428. /* PCH only available on ILK+ */
  1429. BUG_ON(dev_priv->info->gen < 5);
  1430. if (pll == NULL)
  1431. return;
  1432. if (WARN_ON(pll->refcount == 0))
  1433. return;
  1434. DRM_DEBUG_KMS("disable PCH PLL %x (active %d, on? %d) for crtc %d\n",
  1435. pll->pll_reg, pll->active, pll->on,
  1436. intel_crtc->base.base.id);
  1437. if (WARN_ON(pll->active == 0)) {
  1438. assert_pch_pll_disabled(dev_priv, pll, NULL);
  1439. return;
  1440. }
  1441. if (--pll->active) {
  1442. assert_pch_pll_enabled(dev_priv, pll, NULL);
  1443. return;
  1444. }
  1445. DRM_DEBUG_KMS("disabling PCH PLL %x\n", pll->pll_reg);
  1446. /* Make sure transcoder isn't still depending on us */
  1447. assert_transcoder_disabled(dev_priv, intel_crtc->pipe);
  1448. reg = pll->pll_reg;
  1449. val = I915_READ(reg);
  1450. val &= ~DPLL_VCO_ENABLE;
  1451. I915_WRITE(reg, val);
  1452. POSTING_READ(reg);
  1453. udelay(200);
  1454. pll->on = false;
  1455. }
  1456. static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv,
  1457. enum pipe pipe)
  1458. {
  1459. struct drm_device *dev = dev_priv->dev;
  1460. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  1461. uint32_t reg, val, pipeconf_val;
  1462. /* PCH only available on ILK+ */
  1463. BUG_ON(dev_priv->info->gen < 5);
  1464. /* Make sure PCH DPLL is enabled */
  1465. assert_pch_pll_enabled(dev_priv,
  1466. to_intel_crtc(crtc)->pch_pll,
  1467. to_intel_crtc(crtc));
  1468. /* FDI must be feeding us bits for PCH ports */
  1469. assert_fdi_tx_enabled(dev_priv, pipe);
  1470. assert_fdi_rx_enabled(dev_priv, pipe);
  1471. if (HAS_PCH_CPT(dev)) {
  1472. /* Workaround: Set the timing override bit before enabling the
  1473. * pch transcoder. */
  1474. reg = TRANS_CHICKEN2(pipe);
  1475. val = I915_READ(reg);
  1476. val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
  1477. I915_WRITE(reg, val);
  1478. }
  1479. reg = TRANSCONF(pipe);
  1480. val = I915_READ(reg);
  1481. pipeconf_val = I915_READ(PIPECONF(pipe));
  1482. if (HAS_PCH_IBX(dev_priv->dev)) {
  1483. /*
  1484. * make the BPC in transcoder be consistent with
  1485. * that in pipeconf reg.
  1486. */
  1487. val &= ~PIPECONF_BPC_MASK;
  1488. val |= pipeconf_val & PIPECONF_BPC_MASK;
  1489. }
  1490. val &= ~TRANS_INTERLACE_MASK;
  1491. if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK)
  1492. if (HAS_PCH_IBX(dev_priv->dev) &&
  1493. intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO))
  1494. val |= TRANS_LEGACY_INTERLACED_ILK;
  1495. else
  1496. val |= TRANS_INTERLACED;
  1497. else
  1498. val |= TRANS_PROGRESSIVE;
  1499. I915_WRITE(reg, val | TRANS_ENABLE);
  1500. if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100))
  1501. DRM_ERROR("failed to enable transcoder %d\n", pipe);
  1502. }
  1503. static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
  1504. enum transcoder cpu_transcoder)
  1505. {
  1506. u32 val, pipeconf_val;
  1507. /* PCH only available on ILK+ */
  1508. BUG_ON(dev_priv->info->gen < 5);
  1509. /* FDI must be feeding us bits for PCH ports */
  1510. assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder);
  1511. assert_fdi_rx_enabled(dev_priv, TRANSCODER_A);
  1512. /* Workaround: set timing override bit. */
  1513. val = I915_READ(_TRANSA_CHICKEN2);
  1514. val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
  1515. I915_WRITE(_TRANSA_CHICKEN2, val);
  1516. val = TRANS_ENABLE;
  1517. pipeconf_val = I915_READ(PIPECONF(cpu_transcoder));
  1518. if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) ==
  1519. PIPECONF_INTERLACED_ILK)
  1520. val |= TRANS_INTERLACED;
  1521. else
  1522. val |= TRANS_PROGRESSIVE;
  1523. I915_WRITE(TRANSCONF(TRANSCODER_A), val);
  1524. if (wait_for(I915_READ(_TRANSACONF) & TRANS_STATE_ENABLE, 100))
  1525. DRM_ERROR("Failed to enable PCH transcoder\n");
  1526. }
  1527. static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv,
  1528. enum pipe pipe)
  1529. {
  1530. struct drm_device *dev = dev_priv->dev;
  1531. uint32_t reg, val;
  1532. /* FDI relies on the transcoder */
  1533. assert_fdi_tx_disabled(dev_priv, pipe);
  1534. assert_fdi_rx_disabled(dev_priv, pipe);
  1535. /* Ports must be off as well */
  1536. assert_pch_ports_disabled(dev_priv, pipe);
  1537. reg = TRANSCONF(pipe);
  1538. val = I915_READ(reg);
  1539. val &= ~TRANS_ENABLE;
  1540. I915_WRITE(reg, val);
  1541. /* wait for PCH transcoder off, transcoder state */
  1542. if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50))
  1543. DRM_ERROR("failed to disable transcoder %d\n", pipe);
  1544. if (!HAS_PCH_IBX(dev)) {
  1545. /* Workaround: Clear the timing override chicken bit again. */
  1546. reg = TRANS_CHICKEN2(pipe);
  1547. val = I915_READ(reg);
  1548. val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
  1549. I915_WRITE(reg, val);
  1550. }
  1551. }
  1552. static void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
  1553. {
  1554. u32 val;
  1555. val = I915_READ(_TRANSACONF);
  1556. val &= ~TRANS_ENABLE;
  1557. I915_WRITE(_TRANSACONF, val);
  1558. /* wait for PCH transcoder off, transcoder state */
  1559. if (wait_for((I915_READ(_TRANSACONF) & TRANS_STATE_ENABLE) == 0, 50))
  1560. DRM_ERROR("Failed to disable PCH transcoder\n");
  1561. /* Workaround: clear timing override bit. */
  1562. val = I915_READ(_TRANSA_CHICKEN2);
  1563. val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
  1564. I915_WRITE(_TRANSA_CHICKEN2, val);
  1565. }
  1566. /**
  1567. * intel_enable_pipe - enable a pipe, asserting requirements
  1568. * @dev_priv: i915 private structure
  1569. * @pipe: pipe to enable
  1570. * @pch_port: on ILK+, is this pipe driving a PCH port or not
  1571. *
  1572. * Enable @pipe, making sure that various hardware specific requirements
  1573. * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc.
  1574. *
  1575. * @pipe should be %PIPE_A or %PIPE_B.
  1576. *
  1577. * Will wait until the pipe is actually running (i.e. first vblank) before
  1578. * returning.
  1579. */
  1580. static void intel_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe,
  1581. bool pch_port)
  1582. {
  1583. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  1584. pipe);
  1585. enum pipe pch_transcoder;
  1586. int reg;
  1587. u32 val;
  1588. if (HAS_PCH_LPT(dev_priv->dev))
  1589. pch_transcoder = TRANSCODER_A;
  1590. else
  1591. pch_transcoder = pipe;
  1592. /*
  1593. * A pipe without a PLL won't actually be able to drive bits from
  1594. * a plane. On ILK+ the pipe PLLs are integrated, so we don't
  1595. * need the check.
  1596. */
  1597. if (!HAS_PCH_SPLIT(dev_priv->dev))
  1598. assert_pll_enabled(dev_priv, pipe);
  1599. else {
  1600. if (pch_port) {
  1601. /* if driving the PCH, we need FDI enabled */
  1602. assert_fdi_rx_pll_enabled(dev_priv, pch_transcoder);
  1603. assert_fdi_tx_pll_enabled(dev_priv,
  1604. (enum pipe) cpu_transcoder);
  1605. }
  1606. /* FIXME: assert CPU port conditions for SNB+ */
  1607. }
  1608. reg = PIPECONF(cpu_transcoder);
  1609. val = I915_READ(reg);
  1610. if (val & PIPECONF_ENABLE)
  1611. return;
  1612. I915_WRITE(reg, val | PIPECONF_ENABLE);
  1613. intel_wait_for_vblank(dev_priv->dev, pipe);
  1614. }
  1615. /**
  1616. * intel_disable_pipe - disable a pipe, asserting requirements
  1617. * @dev_priv: i915 private structure
  1618. * @pipe: pipe to disable
  1619. *
  1620. * Disable @pipe, making sure that various hardware specific requirements
  1621. * are met, if applicable, e.g. plane disabled, panel fitter off, etc.
  1622. *
  1623. * @pipe should be %PIPE_A or %PIPE_B.
  1624. *
  1625. * Will wait until the pipe has shut down before returning.
  1626. */
  1627. static void intel_disable_pipe(struct drm_i915_private *dev_priv,
  1628. enum pipe pipe)
  1629. {
  1630. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  1631. pipe);
  1632. int reg;
  1633. u32 val;
  1634. /*
  1635. * Make sure planes won't keep trying to pump pixels to us,
  1636. * or we might hang the display.
  1637. */
  1638. assert_planes_disabled(dev_priv, pipe);
  1639. /* Don't disable pipe A or pipe A PLLs if needed */
  1640. if (pipe == PIPE_A && (dev_priv->quirks & QUIRK_PIPEA_FORCE))
  1641. return;
  1642. reg = PIPECONF(cpu_transcoder);
  1643. val = I915_READ(reg);
  1644. if ((val & PIPECONF_ENABLE) == 0)
  1645. return;
  1646. I915_WRITE(reg, val & ~PIPECONF_ENABLE);
  1647. intel_wait_for_pipe_off(dev_priv->dev, pipe);
  1648. }
  1649. /*
  1650. * Plane regs are double buffered, going from enabled->disabled needs a
  1651. * trigger in order to latch. The display address reg provides this.
  1652. */
  1653. void intel_flush_display_plane(struct drm_i915_private *dev_priv,
  1654. enum plane plane)
  1655. {
  1656. if (dev_priv->info->gen >= 4)
  1657. I915_WRITE(DSPSURF(plane), I915_READ(DSPSURF(plane)));
  1658. else
  1659. I915_WRITE(DSPADDR(plane), I915_READ(DSPADDR(plane)));
  1660. }
  1661. /**
  1662. * intel_enable_plane - enable a display plane on a given pipe
  1663. * @dev_priv: i915 private structure
  1664. * @plane: plane to enable
  1665. * @pipe: pipe being fed
  1666. *
  1667. * Enable @plane on @pipe, making sure that @pipe is running first.
  1668. */
  1669. static void intel_enable_plane(struct drm_i915_private *dev_priv,
  1670. enum plane plane, enum pipe pipe)
  1671. {
  1672. int reg;
  1673. u32 val;
  1674. /* If the pipe isn't enabled, we can't pump pixels and may hang */
  1675. assert_pipe_enabled(dev_priv, pipe);
  1676. reg = DSPCNTR(plane);
  1677. val = I915_READ(reg);
  1678. if (val & DISPLAY_PLANE_ENABLE)
  1679. return;
  1680. I915_WRITE(reg, val | DISPLAY_PLANE_ENABLE);
  1681. intel_flush_display_plane(dev_priv, plane);
  1682. intel_wait_for_vblank(dev_priv->dev, pipe);
  1683. }
  1684. /**
  1685. * intel_disable_plane - disable a display plane
  1686. * @dev_priv: i915 private structure
  1687. * @plane: plane to disable
  1688. * @pipe: pipe consuming the data
  1689. *
  1690. * Disable @plane; should be an independent operation.
  1691. */
  1692. static void intel_disable_plane(struct drm_i915_private *dev_priv,
  1693. enum plane plane, enum pipe pipe)
  1694. {
  1695. int reg;
  1696. u32 val;
  1697. reg = DSPCNTR(plane);
  1698. val = I915_READ(reg);
  1699. if ((val & DISPLAY_PLANE_ENABLE) == 0)
  1700. return;
  1701. I915_WRITE(reg, val & ~DISPLAY_PLANE_ENABLE);
  1702. intel_flush_display_plane(dev_priv, plane);
  1703. intel_wait_for_vblank(dev_priv->dev, pipe);
  1704. }
  1705. int
  1706. intel_pin_and_fence_fb_obj(struct drm_device *dev,
  1707. struct drm_i915_gem_object *obj,
  1708. struct intel_ring_buffer *pipelined)
  1709. {
  1710. struct drm_i915_private *dev_priv = dev->dev_private;
  1711. u32 alignment;
  1712. int ret;
  1713. switch (obj->tiling_mode) {
  1714. case I915_TILING_NONE:
  1715. if (IS_BROADWATER(dev) || IS_CRESTLINE(dev))
  1716. alignment = 128 * 1024;
  1717. else if (INTEL_INFO(dev)->gen >= 4)
  1718. alignment = 4 * 1024;
  1719. else
  1720. alignment = 64 * 1024;
  1721. break;
  1722. case I915_TILING_X:
  1723. /* pin() will align the object as required by fence */
  1724. alignment = 0;
  1725. break;
  1726. case I915_TILING_Y:
  1727. /* FIXME: Is this true? */
  1728. DRM_ERROR("Y tiled not allowed for scan out buffers\n");
  1729. return -EINVAL;
  1730. default:
  1731. BUG();
  1732. }
  1733. dev_priv->mm.interruptible = false;
  1734. ret = i915_gem_object_pin_to_display_plane(obj, alignment, pipelined);
  1735. if (ret)
  1736. goto err_interruptible;
  1737. /* Install a fence for tiled scan-out. Pre-i965 always needs a
  1738. * fence, whereas 965+ only requires a fence if using
  1739. * framebuffer compression. For simplicity, we always install
  1740. * a fence as the cost is not that onerous.
  1741. */
  1742. ret = i915_gem_object_get_fence(obj);
  1743. if (ret)
  1744. goto err_unpin;
  1745. i915_gem_object_pin_fence(obj);
  1746. dev_priv->mm.interruptible = true;
  1747. return 0;
  1748. err_unpin:
  1749. i915_gem_object_unpin(obj);
  1750. err_interruptible:
  1751. dev_priv->mm.interruptible = true;
  1752. return ret;
  1753. }
  1754. void intel_unpin_fb_obj(struct drm_i915_gem_object *obj)
  1755. {
  1756. i915_gem_object_unpin_fence(obj);
  1757. i915_gem_object_unpin(obj);
  1758. }
  1759. /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel
  1760. * is assumed to be a power-of-two. */
  1761. unsigned long intel_gen4_compute_offset_xtiled(int *x, int *y,
  1762. unsigned int bpp,
  1763. unsigned int pitch)
  1764. {
  1765. int tile_rows, tiles;
  1766. tile_rows = *y / 8;
  1767. *y %= 8;
  1768. tiles = *x / (512/bpp);
  1769. *x %= 512/bpp;
  1770. return tile_rows * pitch * 8 + tiles * 4096;
  1771. }
  1772. static int i9xx_update_plane(struct drm_crtc *crtc, struct drm_framebuffer *fb,
  1773. int x, int y)
  1774. {
  1775. struct drm_device *dev = crtc->dev;
  1776. struct drm_i915_private *dev_priv = dev->dev_private;
  1777. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1778. struct intel_framebuffer *intel_fb;
  1779. struct drm_i915_gem_object *obj;
  1780. int plane = intel_crtc->plane;
  1781. unsigned long linear_offset;
  1782. u32 dspcntr;
  1783. u32 reg;
  1784. switch (plane) {
  1785. case 0:
  1786. case 1:
  1787. break;
  1788. default:
  1789. DRM_ERROR("Can't update plane %d in SAREA\n", plane);
  1790. return -EINVAL;
  1791. }
  1792. intel_fb = to_intel_framebuffer(fb);
  1793. obj = intel_fb->obj;
  1794. reg = DSPCNTR(plane);
  1795. dspcntr = I915_READ(reg);
  1796. /* Mask out pixel format bits in case we change it */
  1797. dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
  1798. switch (fb->pixel_format) {
  1799. case DRM_FORMAT_C8:
  1800. dspcntr |= DISPPLANE_8BPP;
  1801. break;
  1802. case DRM_FORMAT_XRGB1555:
  1803. case DRM_FORMAT_ARGB1555:
  1804. dspcntr |= DISPPLANE_BGRX555;
  1805. break;
  1806. case DRM_FORMAT_RGB565:
  1807. dspcntr |= DISPPLANE_BGRX565;
  1808. break;
  1809. case DRM_FORMAT_XRGB8888:
  1810. case DRM_FORMAT_ARGB8888:
  1811. dspcntr |= DISPPLANE_BGRX888;
  1812. break;
  1813. case DRM_FORMAT_XBGR8888:
  1814. case DRM_FORMAT_ABGR8888:
  1815. dspcntr |= DISPPLANE_RGBX888;
  1816. break;
  1817. case DRM_FORMAT_XRGB2101010:
  1818. case DRM_FORMAT_ARGB2101010:
  1819. dspcntr |= DISPPLANE_BGRX101010;
  1820. break;
  1821. case DRM_FORMAT_XBGR2101010:
  1822. case DRM_FORMAT_ABGR2101010:
  1823. dspcntr |= DISPPLANE_RGBX101010;
  1824. break;
  1825. default:
  1826. DRM_ERROR("Unknown pixel format 0x%08x\n", fb->pixel_format);
  1827. return -EINVAL;
  1828. }
  1829. if (INTEL_INFO(dev)->gen >= 4) {
  1830. if (obj->tiling_mode != I915_TILING_NONE)
  1831. dspcntr |= DISPPLANE_TILED;
  1832. else
  1833. dspcntr &= ~DISPPLANE_TILED;
  1834. }
  1835. I915_WRITE(reg, dspcntr);
  1836. linear_offset = y * fb->pitches[0] + x * (fb->bits_per_pixel / 8);
  1837. if (INTEL_INFO(dev)->gen >= 4) {
  1838. intel_crtc->dspaddr_offset =
  1839. intel_gen4_compute_offset_xtiled(&x, &y,
  1840. fb->bits_per_pixel / 8,
  1841. fb->pitches[0]);
  1842. linear_offset -= intel_crtc->dspaddr_offset;
  1843. } else {
  1844. intel_crtc->dspaddr_offset = linear_offset;
  1845. }
  1846. DRM_DEBUG_KMS("Writing base %08X %08lX %d %d %d\n",
  1847. obj->gtt_offset, linear_offset, x, y, fb->pitches[0]);
  1848. I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
  1849. if (INTEL_INFO(dev)->gen >= 4) {
  1850. I915_MODIFY_DISPBASE(DSPSURF(plane),
  1851. obj->gtt_offset + intel_crtc->dspaddr_offset);
  1852. I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
  1853. I915_WRITE(DSPLINOFF(plane), linear_offset);
  1854. } else
  1855. I915_WRITE(DSPADDR(plane), obj->gtt_offset + linear_offset);
  1856. POSTING_READ(reg);
  1857. return 0;
  1858. }
  1859. static int ironlake_update_plane(struct drm_crtc *crtc,
  1860. struct drm_framebuffer *fb, int x, int y)
  1861. {
  1862. struct drm_device *dev = crtc->dev;
  1863. struct drm_i915_private *dev_priv = dev->dev_private;
  1864. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1865. struct intel_framebuffer *intel_fb;
  1866. struct drm_i915_gem_object *obj;
  1867. int plane = intel_crtc->plane;
  1868. unsigned long linear_offset;
  1869. u32 dspcntr;
  1870. u32 reg;
  1871. switch (plane) {
  1872. case 0:
  1873. case 1:
  1874. case 2:
  1875. break;
  1876. default:
  1877. DRM_ERROR("Can't update plane %d in SAREA\n", plane);
  1878. return -EINVAL;
  1879. }
  1880. intel_fb = to_intel_framebuffer(fb);
  1881. obj = intel_fb->obj;
  1882. reg = DSPCNTR(plane);
  1883. dspcntr = I915_READ(reg);
  1884. /* Mask out pixel format bits in case we change it */
  1885. dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
  1886. switch (fb->pixel_format) {
  1887. case DRM_FORMAT_C8:
  1888. dspcntr |= DISPPLANE_8BPP;
  1889. break;
  1890. case DRM_FORMAT_RGB565:
  1891. dspcntr |= DISPPLANE_BGRX565;
  1892. break;
  1893. case DRM_FORMAT_XRGB8888:
  1894. case DRM_FORMAT_ARGB8888:
  1895. dspcntr |= DISPPLANE_BGRX888;
  1896. break;
  1897. case DRM_FORMAT_XBGR8888:
  1898. case DRM_FORMAT_ABGR8888:
  1899. dspcntr |= DISPPLANE_RGBX888;
  1900. break;
  1901. case DRM_FORMAT_XRGB2101010:
  1902. case DRM_FORMAT_ARGB2101010:
  1903. dspcntr |= DISPPLANE_BGRX101010;
  1904. break;
  1905. case DRM_FORMAT_XBGR2101010:
  1906. case DRM_FORMAT_ABGR2101010:
  1907. dspcntr |= DISPPLANE_RGBX101010;
  1908. break;
  1909. default:
  1910. DRM_ERROR("Unknown pixel format 0x%08x\n", fb->pixel_format);
  1911. return -EINVAL;
  1912. }
  1913. if (obj->tiling_mode != I915_TILING_NONE)
  1914. dspcntr |= DISPPLANE_TILED;
  1915. else
  1916. dspcntr &= ~DISPPLANE_TILED;
  1917. /* must disable */
  1918. dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
  1919. I915_WRITE(reg, dspcntr);
  1920. linear_offset = y * fb->pitches[0] + x * (fb->bits_per_pixel / 8);
  1921. intel_crtc->dspaddr_offset =
  1922. intel_gen4_compute_offset_xtiled(&x, &y,
  1923. fb->bits_per_pixel / 8,
  1924. fb->pitches[0]);
  1925. linear_offset -= intel_crtc->dspaddr_offset;
  1926. DRM_DEBUG_KMS("Writing base %08X %08lX %d %d %d\n",
  1927. obj->gtt_offset, linear_offset, x, y, fb->pitches[0]);
  1928. I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
  1929. I915_MODIFY_DISPBASE(DSPSURF(plane),
  1930. obj->gtt_offset + intel_crtc->dspaddr_offset);
  1931. if (IS_HASWELL(dev)) {
  1932. I915_WRITE(DSPOFFSET(plane), (y << 16) | x);
  1933. } else {
  1934. I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
  1935. I915_WRITE(DSPLINOFF(plane), linear_offset);
  1936. }
  1937. POSTING_READ(reg);
  1938. return 0;
  1939. }
  1940. /* Assume fb object is pinned & idle & fenced and just update base pointers */
  1941. static int
  1942. intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb,
  1943. int x, int y, enum mode_set_atomic state)
  1944. {
  1945. struct drm_device *dev = crtc->dev;
  1946. struct drm_i915_private *dev_priv = dev->dev_private;
  1947. if (dev_priv->display.disable_fbc)
  1948. dev_priv->display.disable_fbc(dev);
  1949. intel_increase_pllclock(crtc);
  1950. return dev_priv->display.update_plane(crtc, fb, x, y);
  1951. }
  1952. static int
  1953. intel_finish_fb(struct drm_framebuffer *old_fb)
  1954. {
  1955. struct drm_i915_gem_object *obj = to_intel_framebuffer(old_fb)->obj;
  1956. struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
  1957. bool was_interruptible = dev_priv->mm.interruptible;
  1958. int ret;
  1959. WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue));
  1960. wait_event(dev_priv->pending_flip_queue,
  1961. i915_reset_in_progress(&dev_priv->gpu_error) ||
  1962. atomic_read(&obj->pending_flip) == 0);
  1963. /* Big Hammer, we also need to ensure that any pending
  1964. * MI_WAIT_FOR_EVENT inside a user batch buffer on the
  1965. * current scanout is retired before unpinning the old
  1966. * framebuffer.
  1967. *
  1968. * This should only fail upon a hung GPU, in which case we
  1969. * can safely continue.
  1970. */
  1971. dev_priv->mm.interruptible = false;
  1972. ret = i915_gem_object_finish_gpu(obj);
  1973. dev_priv->mm.interruptible = was_interruptible;
  1974. return ret;
  1975. }
  1976. static void intel_crtc_update_sarea_pos(struct drm_crtc *crtc, int x, int y)
  1977. {
  1978. struct drm_device *dev = crtc->dev;
  1979. struct drm_i915_master_private *master_priv;
  1980. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1981. if (!dev->primary->master)
  1982. return;
  1983. master_priv = dev->primary->master->driver_priv;
  1984. if (!master_priv->sarea_priv)
  1985. return;
  1986. switch (intel_crtc->pipe) {
  1987. case 0:
  1988. master_priv->sarea_priv->pipeA_x = x;
  1989. master_priv->sarea_priv->pipeA_y = y;
  1990. break;
  1991. case 1:
  1992. master_priv->sarea_priv->pipeB_x = x;
  1993. master_priv->sarea_priv->pipeB_y = y;
  1994. break;
  1995. default:
  1996. break;
  1997. }
  1998. }
  1999. static int
  2000. intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
  2001. struct drm_framebuffer *fb)
  2002. {
  2003. struct drm_device *dev = crtc->dev;
  2004. struct drm_i915_private *dev_priv = dev->dev_private;
  2005. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2006. struct drm_framebuffer *old_fb;
  2007. int ret;
  2008. /* no fb bound */
  2009. if (!fb) {
  2010. DRM_ERROR("No FB bound\n");
  2011. return 0;
  2012. }
  2013. if(intel_crtc->plane > dev_priv->num_pipe) {
  2014. DRM_ERROR("no plane for crtc: plane %d, num_pipes %d\n",
  2015. intel_crtc->plane,
  2016. dev_priv->num_pipe);
  2017. return -EINVAL;
  2018. }
  2019. mutex_lock(&dev->struct_mutex);
  2020. ret = intel_pin_and_fence_fb_obj(dev,
  2021. to_intel_framebuffer(fb)->obj,
  2022. NULL);
  2023. if (ret != 0) {
  2024. mutex_unlock(&dev->struct_mutex);
  2025. DRM_ERROR("pin & fence failed\n");
  2026. return ret;
  2027. }
  2028. if (crtc->fb)
  2029. intel_finish_fb(crtc->fb);
  2030. ret = dev_priv->display.update_plane(crtc, fb, x, y);
  2031. if (ret) {
  2032. intel_unpin_fb_obj(to_intel_framebuffer(fb)->obj);
  2033. mutex_unlock(&dev->struct_mutex);
  2034. DRM_ERROR("failed to update base address\n");
  2035. return ret;
  2036. }
  2037. old_fb = crtc->fb;
  2038. crtc->fb = fb;
  2039. crtc->x = x;
  2040. crtc->y = y;
  2041. if (old_fb) {
  2042. intel_wait_for_vblank(dev, intel_crtc->pipe);
  2043. intel_unpin_fb_obj(to_intel_framebuffer(old_fb)->obj);
  2044. }
  2045. intel_update_fbc(dev);
  2046. mutex_unlock(&dev->struct_mutex);
  2047. intel_crtc_update_sarea_pos(crtc, x, y);
  2048. return 0;
  2049. }
  2050. static void intel_fdi_normal_train(struct drm_crtc *crtc)
  2051. {
  2052. struct drm_device *dev = crtc->dev;
  2053. struct drm_i915_private *dev_priv = dev->dev_private;
  2054. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2055. int pipe = intel_crtc->pipe;
  2056. u32 reg, temp;
  2057. /* enable normal train */
  2058. reg = FDI_TX_CTL(pipe);
  2059. temp = I915_READ(reg);
  2060. if (IS_IVYBRIDGE(dev)) {
  2061. temp &= ~FDI_LINK_TRAIN_NONE_IVB;
  2062. temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
  2063. } else {
  2064. temp &= ~FDI_LINK_TRAIN_NONE;
  2065. temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
  2066. }
  2067. I915_WRITE(reg, temp);
  2068. reg = FDI_RX_CTL(pipe);
  2069. temp = I915_READ(reg);
  2070. if (HAS_PCH_CPT(dev)) {
  2071. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2072. temp |= FDI_LINK_TRAIN_NORMAL_CPT;
  2073. } else {
  2074. temp &= ~FDI_LINK_TRAIN_NONE;
  2075. temp |= FDI_LINK_TRAIN_NONE;
  2076. }
  2077. I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
  2078. /* wait one idle pattern time */
  2079. POSTING_READ(reg);
  2080. udelay(1000);
  2081. /* IVB wants error correction enabled */
  2082. if (IS_IVYBRIDGE(dev))
  2083. I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
  2084. FDI_FE_ERRC_ENABLE);
  2085. }
  2086. static void ivb_modeset_global_resources(struct drm_device *dev)
  2087. {
  2088. struct drm_i915_private *dev_priv = dev->dev_private;
  2089. struct intel_crtc *pipe_B_crtc =
  2090. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]);
  2091. struct intel_crtc *pipe_C_crtc =
  2092. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_C]);
  2093. uint32_t temp;
  2094. /* When everything is off disable fdi C so that we could enable fdi B
  2095. * with all lanes. XXX: This misses the case where a pipe is not using
  2096. * any pch resources and so doesn't need any fdi lanes. */
  2097. if (!pipe_B_crtc->base.enabled && !pipe_C_crtc->base.enabled) {
  2098. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
  2099. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
  2100. temp = I915_READ(SOUTH_CHICKEN1);
  2101. temp &= ~FDI_BC_BIFURCATION_SELECT;
  2102. DRM_DEBUG_KMS("disabling fdi C rx\n");
  2103. I915_WRITE(SOUTH_CHICKEN1, temp);
  2104. }
  2105. }
  2106. /* The FDI link training functions for ILK/Ibexpeak. */
  2107. static void ironlake_fdi_link_train(struct drm_crtc *crtc)
  2108. {
  2109. struct drm_device *dev = crtc->dev;
  2110. struct drm_i915_private *dev_priv = dev->dev_private;
  2111. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2112. int pipe = intel_crtc->pipe;
  2113. int plane = intel_crtc->plane;
  2114. u32 reg, temp, tries;
  2115. /* FDI needs bits from pipe & plane first */
  2116. assert_pipe_enabled(dev_priv, pipe);
  2117. assert_plane_enabled(dev_priv, plane);
  2118. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2119. for train result */
  2120. reg = FDI_RX_IMR(pipe);
  2121. temp = I915_READ(reg);
  2122. temp &= ~FDI_RX_SYMBOL_LOCK;
  2123. temp &= ~FDI_RX_BIT_LOCK;
  2124. I915_WRITE(reg, temp);
  2125. I915_READ(reg);
  2126. udelay(150);
  2127. /* enable CPU FDI TX and PCH FDI RX */
  2128. reg = FDI_TX_CTL(pipe);
  2129. temp = I915_READ(reg);
  2130. temp &= ~(7 << 19);
  2131. temp |= (intel_crtc->fdi_lanes - 1) << 19;
  2132. temp &= ~FDI_LINK_TRAIN_NONE;
  2133. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2134. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2135. reg = FDI_RX_CTL(pipe);
  2136. temp = I915_READ(reg);
  2137. temp &= ~FDI_LINK_TRAIN_NONE;
  2138. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2139. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2140. POSTING_READ(reg);
  2141. udelay(150);
  2142. /* Ironlake workaround, enable clock pointer after FDI enable*/
  2143. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
  2144. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
  2145. FDI_RX_PHASE_SYNC_POINTER_EN);
  2146. reg = FDI_RX_IIR(pipe);
  2147. for (tries = 0; tries < 5; tries++) {
  2148. temp = I915_READ(reg);
  2149. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2150. if ((temp & FDI_RX_BIT_LOCK)) {
  2151. DRM_DEBUG_KMS("FDI train 1 done.\n");
  2152. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2153. break;
  2154. }
  2155. }
  2156. if (tries == 5)
  2157. DRM_ERROR("FDI train 1 fail!\n");
  2158. /* Train 2 */
  2159. reg = FDI_TX_CTL(pipe);
  2160. temp = I915_READ(reg);
  2161. temp &= ~FDI_LINK_TRAIN_NONE;
  2162. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2163. I915_WRITE(reg, temp);
  2164. reg = FDI_RX_CTL(pipe);
  2165. temp = I915_READ(reg);
  2166. temp &= ~FDI_LINK_TRAIN_NONE;
  2167. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2168. I915_WRITE(reg, temp);
  2169. POSTING_READ(reg);
  2170. udelay(150);
  2171. reg = FDI_RX_IIR(pipe);
  2172. for (tries = 0; tries < 5; tries++) {
  2173. temp = I915_READ(reg);
  2174. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2175. if (temp & FDI_RX_SYMBOL_LOCK) {
  2176. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2177. DRM_DEBUG_KMS("FDI train 2 done.\n");
  2178. break;
  2179. }
  2180. }
  2181. if (tries == 5)
  2182. DRM_ERROR("FDI train 2 fail!\n");
  2183. DRM_DEBUG_KMS("FDI train done\n");
  2184. }
  2185. static const int snb_b_fdi_train_param[] = {
  2186. FDI_LINK_TRAIN_400MV_0DB_SNB_B,
  2187. FDI_LINK_TRAIN_400MV_6DB_SNB_B,
  2188. FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
  2189. FDI_LINK_TRAIN_800MV_0DB_SNB_B,
  2190. };
  2191. /* The FDI link training functions for SNB/Cougarpoint. */
  2192. static void gen6_fdi_link_train(struct drm_crtc *crtc)
  2193. {
  2194. struct drm_device *dev = crtc->dev;
  2195. struct drm_i915_private *dev_priv = dev->dev_private;
  2196. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2197. int pipe = intel_crtc->pipe;
  2198. u32 reg, temp, i, retry;
  2199. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2200. for train result */
  2201. reg = FDI_RX_IMR(pipe);
  2202. temp = I915_READ(reg);
  2203. temp &= ~FDI_RX_SYMBOL_LOCK;
  2204. temp &= ~FDI_RX_BIT_LOCK;
  2205. I915_WRITE(reg, temp);
  2206. POSTING_READ(reg);
  2207. udelay(150);
  2208. /* enable CPU FDI TX and PCH FDI RX */
  2209. reg = FDI_TX_CTL(pipe);
  2210. temp = I915_READ(reg);
  2211. temp &= ~(7 << 19);
  2212. temp |= (intel_crtc->fdi_lanes - 1) << 19;
  2213. temp &= ~FDI_LINK_TRAIN_NONE;
  2214. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2215. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2216. /* SNB-B */
  2217. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2218. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2219. I915_WRITE(FDI_RX_MISC(pipe),
  2220. FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
  2221. reg = FDI_RX_CTL(pipe);
  2222. temp = I915_READ(reg);
  2223. if (HAS_PCH_CPT(dev)) {
  2224. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2225. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2226. } else {
  2227. temp &= ~FDI_LINK_TRAIN_NONE;
  2228. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2229. }
  2230. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2231. POSTING_READ(reg);
  2232. udelay(150);
  2233. for (i = 0; i < 4; i++) {
  2234. reg = FDI_TX_CTL(pipe);
  2235. temp = I915_READ(reg);
  2236. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2237. temp |= snb_b_fdi_train_param[i];
  2238. I915_WRITE(reg, temp);
  2239. POSTING_READ(reg);
  2240. udelay(500);
  2241. for (retry = 0; retry < 5; retry++) {
  2242. reg = FDI_RX_IIR(pipe);
  2243. temp = I915_READ(reg);
  2244. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2245. if (temp & FDI_RX_BIT_LOCK) {
  2246. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2247. DRM_DEBUG_KMS("FDI train 1 done.\n");
  2248. break;
  2249. }
  2250. udelay(50);
  2251. }
  2252. if (retry < 5)
  2253. break;
  2254. }
  2255. if (i == 4)
  2256. DRM_ERROR("FDI train 1 fail!\n");
  2257. /* Train 2 */
  2258. reg = FDI_TX_CTL(pipe);
  2259. temp = I915_READ(reg);
  2260. temp &= ~FDI_LINK_TRAIN_NONE;
  2261. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2262. if (IS_GEN6(dev)) {
  2263. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2264. /* SNB-B */
  2265. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2266. }
  2267. I915_WRITE(reg, temp);
  2268. reg = FDI_RX_CTL(pipe);
  2269. temp = I915_READ(reg);
  2270. if (HAS_PCH_CPT(dev)) {
  2271. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2272. temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
  2273. } else {
  2274. temp &= ~FDI_LINK_TRAIN_NONE;
  2275. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2276. }
  2277. I915_WRITE(reg, temp);
  2278. POSTING_READ(reg);
  2279. udelay(150);
  2280. for (i = 0; i < 4; i++) {
  2281. reg = FDI_TX_CTL(pipe);
  2282. temp = I915_READ(reg);
  2283. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2284. temp |= snb_b_fdi_train_param[i];
  2285. I915_WRITE(reg, temp);
  2286. POSTING_READ(reg);
  2287. udelay(500);
  2288. for (retry = 0; retry < 5; retry++) {
  2289. reg = FDI_RX_IIR(pipe);
  2290. temp = I915_READ(reg);
  2291. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2292. if (temp & FDI_RX_SYMBOL_LOCK) {
  2293. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2294. DRM_DEBUG_KMS("FDI train 2 done.\n");
  2295. break;
  2296. }
  2297. udelay(50);
  2298. }
  2299. if (retry < 5)
  2300. break;
  2301. }
  2302. if (i == 4)
  2303. DRM_ERROR("FDI train 2 fail!\n");
  2304. DRM_DEBUG_KMS("FDI train done.\n");
  2305. }
  2306. /* Manual link training for Ivy Bridge A0 parts */
  2307. static void ivb_manual_fdi_link_train(struct drm_crtc *crtc)
  2308. {
  2309. struct drm_device *dev = crtc->dev;
  2310. struct drm_i915_private *dev_priv = dev->dev_private;
  2311. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2312. int pipe = intel_crtc->pipe;
  2313. u32 reg, temp, i;
  2314. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2315. for train result */
  2316. reg = FDI_RX_IMR(pipe);
  2317. temp = I915_READ(reg);
  2318. temp &= ~FDI_RX_SYMBOL_LOCK;
  2319. temp &= ~FDI_RX_BIT_LOCK;
  2320. I915_WRITE(reg, temp);
  2321. POSTING_READ(reg);
  2322. udelay(150);
  2323. DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
  2324. I915_READ(FDI_RX_IIR(pipe)));
  2325. /* enable CPU FDI TX and PCH FDI RX */
  2326. reg = FDI_TX_CTL(pipe);
  2327. temp = I915_READ(reg);
  2328. temp &= ~(7 << 19);
  2329. temp |= (intel_crtc->fdi_lanes - 1) << 19;
  2330. temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
  2331. temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
  2332. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2333. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2334. temp |= FDI_COMPOSITE_SYNC;
  2335. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2336. I915_WRITE(FDI_RX_MISC(pipe),
  2337. FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
  2338. reg = FDI_RX_CTL(pipe);
  2339. temp = I915_READ(reg);
  2340. temp &= ~FDI_LINK_TRAIN_AUTO;
  2341. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2342. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2343. temp |= FDI_COMPOSITE_SYNC;
  2344. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2345. POSTING_READ(reg);
  2346. udelay(150);
  2347. for (i = 0; i < 4; i++) {
  2348. reg = FDI_TX_CTL(pipe);
  2349. temp = I915_READ(reg);
  2350. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2351. temp |= snb_b_fdi_train_param[i];
  2352. I915_WRITE(reg, temp);
  2353. POSTING_READ(reg);
  2354. udelay(500);
  2355. reg = FDI_RX_IIR(pipe);
  2356. temp = I915_READ(reg);
  2357. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2358. if (temp & FDI_RX_BIT_LOCK ||
  2359. (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
  2360. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2361. DRM_DEBUG_KMS("FDI train 1 done, level %i.\n", i);
  2362. break;
  2363. }
  2364. }
  2365. if (i == 4)
  2366. DRM_ERROR("FDI train 1 fail!\n");
  2367. /* Train 2 */
  2368. reg = FDI_TX_CTL(pipe);
  2369. temp = I915_READ(reg);
  2370. temp &= ~FDI_LINK_TRAIN_NONE_IVB;
  2371. temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
  2372. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2373. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2374. I915_WRITE(reg, temp);
  2375. reg = FDI_RX_CTL(pipe);
  2376. temp = I915_READ(reg);
  2377. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2378. temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
  2379. I915_WRITE(reg, temp);
  2380. POSTING_READ(reg);
  2381. udelay(150);
  2382. for (i = 0; i < 4; i++) {
  2383. reg = FDI_TX_CTL(pipe);
  2384. temp = I915_READ(reg);
  2385. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2386. temp |= snb_b_fdi_train_param[i];
  2387. I915_WRITE(reg, temp);
  2388. POSTING_READ(reg);
  2389. udelay(500);
  2390. reg = FDI_RX_IIR(pipe);
  2391. temp = I915_READ(reg);
  2392. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2393. if (temp & FDI_RX_SYMBOL_LOCK) {
  2394. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2395. DRM_DEBUG_KMS("FDI train 2 done, level %i.\n", i);
  2396. break;
  2397. }
  2398. }
  2399. if (i == 4)
  2400. DRM_ERROR("FDI train 2 fail!\n");
  2401. DRM_DEBUG_KMS("FDI train done.\n");
  2402. }
  2403. static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc)
  2404. {
  2405. struct drm_device *dev = intel_crtc->base.dev;
  2406. struct drm_i915_private *dev_priv = dev->dev_private;
  2407. int pipe = intel_crtc->pipe;
  2408. u32 reg, temp;
  2409. /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
  2410. reg = FDI_RX_CTL(pipe);
  2411. temp = I915_READ(reg);
  2412. temp &= ~((0x7 << 19) | (0x7 << 16));
  2413. temp |= (intel_crtc->fdi_lanes - 1) << 19;
  2414. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2415. I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
  2416. POSTING_READ(reg);
  2417. udelay(200);
  2418. /* Switch from Rawclk to PCDclk */
  2419. temp = I915_READ(reg);
  2420. I915_WRITE(reg, temp | FDI_PCDCLK);
  2421. POSTING_READ(reg);
  2422. udelay(200);
  2423. /* Enable CPU FDI TX PLL, always on for Ironlake */
  2424. reg = FDI_TX_CTL(pipe);
  2425. temp = I915_READ(reg);
  2426. if ((temp & FDI_TX_PLL_ENABLE) == 0) {
  2427. I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
  2428. POSTING_READ(reg);
  2429. udelay(100);
  2430. }
  2431. }
  2432. static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
  2433. {
  2434. struct drm_device *dev = intel_crtc->base.dev;
  2435. struct drm_i915_private *dev_priv = dev->dev_private;
  2436. int pipe = intel_crtc->pipe;
  2437. u32 reg, temp;
  2438. /* Switch from PCDclk to Rawclk */
  2439. reg = FDI_RX_CTL(pipe);
  2440. temp = I915_READ(reg);
  2441. I915_WRITE(reg, temp & ~FDI_PCDCLK);
  2442. /* Disable CPU FDI TX PLL */
  2443. reg = FDI_TX_CTL(pipe);
  2444. temp = I915_READ(reg);
  2445. I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
  2446. POSTING_READ(reg);
  2447. udelay(100);
  2448. reg = FDI_RX_CTL(pipe);
  2449. temp = I915_READ(reg);
  2450. I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
  2451. /* Wait for the clocks to turn off. */
  2452. POSTING_READ(reg);
  2453. udelay(100);
  2454. }
  2455. static void ironlake_fdi_disable(struct drm_crtc *crtc)
  2456. {
  2457. struct drm_device *dev = crtc->dev;
  2458. struct drm_i915_private *dev_priv = dev->dev_private;
  2459. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2460. int pipe = intel_crtc->pipe;
  2461. u32 reg, temp;
  2462. /* disable CPU FDI tx and PCH FDI rx */
  2463. reg = FDI_TX_CTL(pipe);
  2464. temp = I915_READ(reg);
  2465. I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
  2466. POSTING_READ(reg);
  2467. reg = FDI_RX_CTL(pipe);
  2468. temp = I915_READ(reg);
  2469. temp &= ~(0x7 << 16);
  2470. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2471. I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
  2472. POSTING_READ(reg);
  2473. udelay(100);
  2474. /* Ironlake workaround, disable clock pointer after downing FDI */
  2475. if (HAS_PCH_IBX(dev)) {
  2476. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
  2477. }
  2478. /* still set train pattern 1 */
  2479. reg = FDI_TX_CTL(pipe);
  2480. temp = I915_READ(reg);
  2481. temp &= ~FDI_LINK_TRAIN_NONE;
  2482. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2483. I915_WRITE(reg, temp);
  2484. reg = FDI_RX_CTL(pipe);
  2485. temp = I915_READ(reg);
  2486. if (HAS_PCH_CPT(dev)) {
  2487. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2488. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2489. } else {
  2490. temp &= ~FDI_LINK_TRAIN_NONE;
  2491. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2492. }
  2493. /* BPC in FDI rx is consistent with that in PIPECONF */
  2494. temp &= ~(0x07 << 16);
  2495. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2496. I915_WRITE(reg, temp);
  2497. POSTING_READ(reg);
  2498. udelay(100);
  2499. }
  2500. static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc)
  2501. {
  2502. struct drm_device *dev = crtc->dev;
  2503. struct drm_i915_private *dev_priv = dev->dev_private;
  2504. unsigned long flags;
  2505. bool pending;
  2506. if (i915_reset_in_progress(&dev_priv->gpu_error))
  2507. return false;
  2508. spin_lock_irqsave(&dev->event_lock, flags);
  2509. pending = to_intel_crtc(crtc)->unpin_work != NULL;
  2510. spin_unlock_irqrestore(&dev->event_lock, flags);
  2511. return pending;
  2512. }
  2513. static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
  2514. {
  2515. struct drm_device *dev = crtc->dev;
  2516. struct drm_i915_private *dev_priv = dev->dev_private;
  2517. if (crtc->fb == NULL)
  2518. return;
  2519. WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue));
  2520. wait_event(dev_priv->pending_flip_queue,
  2521. !intel_crtc_has_pending_flip(crtc));
  2522. mutex_lock(&dev->struct_mutex);
  2523. intel_finish_fb(crtc->fb);
  2524. mutex_unlock(&dev->struct_mutex);
  2525. }
  2526. static bool ironlake_crtc_driving_pch(struct drm_crtc *crtc)
  2527. {
  2528. struct drm_device *dev = crtc->dev;
  2529. struct intel_encoder *intel_encoder;
  2530. /*
  2531. * If there's a non-PCH eDP on this crtc, it must be DP_A, and that
  2532. * must be driven by its own crtc; no sharing is possible.
  2533. */
  2534. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  2535. switch (intel_encoder->type) {
  2536. case INTEL_OUTPUT_EDP:
  2537. if (!intel_encoder_is_pch_edp(&intel_encoder->base))
  2538. return false;
  2539. continue;
  2540. }
  2541. }
  2542. return true;
  2543. }
  2544. static bool haswell_crtc_driving_pch(struct drm_crtc *crtc)
  2545. {
  2546. return intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG);
  2547. }
  2548. /* Program iCLKIP clock to the desired frequency */
  2549. static void lpt_program_iclkip(struct drm_crtc *crtc)
  2550. {
  2551. struct drm_device *dev = crtc->dev;
  2552. struct drm_i915_private *dev_priv = dev->dev_private;
  2553. u32 divsel, phaseinc, auxdiv, phasedir = 0;
  2554. u32 temp;
  2555. mutex_lock(&dev_priv->dpio_lock);
  2556. /* It is necessary to ungate the pixclk gate prior to programming
  2557. * the divisors, and gate it back when it is done.
  2558. */
  2559. I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
  2560. /* Disable SSCCTL */
  2561. intel_sbi_write(dev_priv, SBI_SSCCTL6,
  2562. intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK) |
  2563. SBI_SSCCTL_DISABLE,
  2564. SBI_ICLK);
  2565. /* 20MHz is a corner case which is out of range for the 7-bit divisor */
  2566. if (crtc->mode.clock == 20000) {
  2567. auxdiv = 1;
  2568. divsel = 0x41;
  2569. phaseinc = 0x20;
  2570. } else {
  2571. /* The iCLK virtual clock root frequency is in MHz,
  2572. * but the crtc->mode.clock in in KHz. To get the divisors,
  2573. * it is necessary to divide one by another, so we
  2574. * convert the virtual clock precision to KHz here for higher
  2575. * precision.
  2576. */
  2577. u32 iclk_virtual_root_freq = 172800 * 1000;
  2578. u32 iclk_pi_range = 64;
  2579. u32 desired_divisor, msb_divisor_value, pi_value;
  2580. desired_divisor = (iclk_virtual_root_freq / crtc->mode.clock);
  2581. msb_divisor_value = desired_divisor / iclk_pi_range;
  2582. pi_value = desired_divisor % iclk_pi_range;
  2583. auxdiv = 0;
  2584. divsel = msb_divisor_value - 2;
  2585. phaseinc = pi_value;
  2586. }
  2587. /* This should not happen with any sane values */
  2588. WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
  2589. ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
  2590. WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) &
  2591. ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
  2592. DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
  2593. crtc->mode.clock,
  2594. auxdiv,
  2595. divsel,
  2596. phasedir,
  2597. phaseinc);
  2598. /* Program SSCDIVINTPHASE6 */
  2599. temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
  2600. temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
  2601. temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
  2602. temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
  2603. temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
  2604. temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
  2605. temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
  2606. intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
  2607. /* Program SSCAUXDIV */
  2608. temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
  2609. temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
  2610. temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
  2611. intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
  2612. /* Enable modulator and associated divider */
  2613. temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
  2614. temp &= ~SBI_SSCCTL_DISABLE;
  2615. intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
  2616. /* Wait for initialization time */
  2617. udelay(24);
  2618. I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE);
  2619. mutex_unlock(&dev_priv->dpio_lock);
  2620. }
  2621. /*
  2622. * Enable PCH resources required for PCH ports:
  2623. * - PCH PLLs
  2624. * - FDI training & RX/TX
  2625. * - update transcoder timings
  2626. * - DP transcoding bits
  2627. * - transcoder
  2628. */
  2629. static void ironlake_pch_enable(struct drm_crtc *crtc)
  2630. {
  2631. struct drm_device *dev = crtc->dev;
  2632. struct drm_i915_private *dev_priv = dev->dev_private;
  2633. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2634. int pipe = intel_crtc->pipe;
  2635. u32 reg, temp;
  2636. assert_transcoder_disabled(dev_priv, pipe);
  2637. /* Write the TU size bits before fdi link training, so that error
  2638. * detection works. */
  2639. I915_WRITE(FDI_RX_TUSIZE1(pipe),
  2640. I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
  2641. /* For PCH output, training FDI link */
  2642. dev_priv->display.fdi_link_train(crtc);
  2643. /* XXX: pch pll's can be enabled any time before we enable the PCH
  2644. * transcoder, and we actually should do this to not upset any PCH
  2645. * transcoder that already use the clock when we share it.
  2646. *
  2647. * Note that enable_pch_pll tries to do the right thing, but get_pch_pll
  2648. * unconditionally resets the pll - we need that to have the right LVDS
  2649. * enable sequence. */
  2650. ironlake_enable_pch_pll(intel_crtc);
  2651. if (HAS_PCH_CPT(dev)) {
  2652. u32 sel;
  2653. temp = I915_READ(PCH_DPLL_SEL);
  2654. switch (pipe) {
  2655. default:
  2656. case 0:
  2657. temp |= TRANSA_DPLL_ENABLE;
  2658. sel = TRANSA_DPLLB_SEL;
  2659. break;
  2660. case 1:
  2661. temp |= TRANSB_DPLL_ENABLE;
  2662. sel = TRANSB_DPLLB_SEL;
  2663. break;
  2664. case 2:
  2665. temp |= TRANSC_DPLL_ENABLE;
  2666. sel = TRANSC_DPLLB_SEL;
  2667. break;
  2668. }
  2669. if (intel_crtc->pch_pll->pll_reg == _PCH_DPLL_B)
  2670. temp |= sel;
  2671. else
  2672. temp &= ~sel;
  2673. I915_WRITE(PCH_DPLL_SEL, temp);
  2674. }
  2675. /* set transcoder timing, panel must allow it */
  2676. assert_panel_unlocked(dev_priv, pipe);
  2677. I915_WRITE(TRANS_HTOTAL(pipe), I915_READ(HTOTAL(pipe)));
  2678. I915_WRITE(TRANS_HBLANK(pipe), I915_READ(HBLANK(pipe)));
  2679. I915_WRITE(TRANS_HSYNC(pipe), I915_READ(HSYNC(pipe)));
  2680. I915_WRITE(TRANS_VTOTAL(pipe), I915_READ(VTOTAL(pipe)));
  2681. I915_WRITE(TRANS_VBLANK(pipe), I915_READ(VBLANK(pipe)));
  2682. I915_WRITE(TRANS_VSYNC(pipe), I915_READ(VSYNC(pipe)));
  2683. I915_WRITE(TRANS_VSYNCSHIFT(pipe), I915_READ(VSYNCSHIFT(pipe)));
  2684. intel_fdi_normal_train(crtc);
  2685. /* For PCH DP, enable TRANS_DP_CTL */
  2686. if (HAS_PCH_CPT(dev) &&
  2687. (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) ||
  2688. intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) {
  2689. u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
  2690. reg = TRANS_DP_CTL(pipe);
  2691. temp = I915_READ(reg);
  2692. temp &= ~(TRANS_DP_PORT_SEL_MASK |
  2693. TRANS_DP_SYNC_MASK |
  2694. TRANS_DP_BPC_MASK);
  2695. temp |= (TRANS_DP_OUTPUT_ENABLE |
  2696. TRANS_DP_ENH_FRAMING);
  2697. temp |= bpc << 9; /* same format but at 11:9 */
  2698. if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC)
  2699. temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
  2700. if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC)
  2701. temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
  2702. switch (intel_trans_dp_port_sel(crtc)) {
  2703. case PCH_DP_B:
  2704. temp |= TRANS_DP_PORT_SEL_B;
  2705. break;
  2706. case PCH_DP_C:
  2707. temp |= TRANS_DP_PORT_SEL_C;
  2708. break;
  2709. case PCH_DP_D:
  2710. temp |= TRANS_DP_PORT_SEL_D;
  2711. break;
  2712. default:
  2713. BUG();
  2714. }
  2715. I915_WRITE(reg, temp);
  2716. }
  2717. ironlake_enable_pch_transcoder(dev_priv, pipe);
  2718. }
  2719. static void lpt_pch_enable(struct drm_crtc *crtc)
  2720. {
  2721. struct drm_device *dev = crtc->dev;
  2722. struct drm_i915_private *dev_priv = dev->dev_private;
  2723. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2724. enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
  2725. assert_transcoder_disabled(dev_priv, TRANSCODER_A);
  2726. lpt_program_iclkip(crtc);
  2727. /* Set transcoder timing. */
  2728. I915_WRITE(_TRANS_HTOTAL_A, I915_READ(HTOTAL(cpu_transcoder)));
  2729. I915_WRITE(_TRANS_HBLANK_A, I915_READ(HBLANK(cpu_transcoder)));
  2730. I915_WRITE(_TRANS_HSYNC_A, I915_READ(HSYNC(cpu_transcoder)));
  2731. I915_WRITE(_TRANS_VTOTAL_A, I915_READ(VTOTAL(cpu_transcoder)));
  2732. I915_WRITE(_TRANS_VBLANK_A, I915_READ(VBLANK(cpu_transcoder)));
  2733. I915_WRITE(_TRANS_VSYNC_A, I915_READ(VSYNC(cpu_transcoder)));
  2734. I915_WRITE(_TRANS_VSYNCSHIFT_A, I915_READ(VSYNCSHIFT(cpu_transcoder)));
  2735. lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
  2736. }
  2737. static void intel_put_pch_pll(struct intel_crtc *intel_crtc)
  2738. {
  2739. struct intel_pch_pll *pll = intel_crtc->pch_pll;
  2740. if (pll == NULL)
  2741. return;
  2742. if (pll->refcount == 0) {
  2743. WARN(1, "bad PCH PLL refcount\n");
  2744. return;
  2745. }
  2746. --pll->refcount;
  2747. intel_crtc->pch_pll = NULL;
  2748. }
  2749. static struct intel_pch_pll *intel_get_pch_pll(struct intel_crtc *intel_crtc, u32 dpll, u32 fp)
  2750. {
  2751. struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private;
  2752. struct intel_pch_pll *pll;
  2753. int i;
  2754. pll = intel_crtc->pch_pll;
  2755. if (pll) {
  2756. DRM_DEBUG_KMS("CRTC:%d reusing existing PCH PLL %x\n",
  2757. intel_crtc->base.base.id, pll->pll_reg);
  2758. goto prepare;
  2759. }
  2760. if (HAS_PCH_IBX(dev_priv->dev)) {
  2761. /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */
  2762. i = intel_crtc->pipe;
  2763. pll = &dev_priv->pch_plls[i];
  2764. DRM_DEBUG_KMS("CRTC:%d using pre-allocated PCH PLL %x\n",
  2765. intel_crtc->base.base.id, pll->pll_reg);
  2766. goto found;
  2767. }
  2768. for (i = 0; i < dev_priv->num_pch_pll; i++) {
  2769. pll = &dev_priv->pch_plls[i];
  2770. /* Only want to check enabled timings first */
  2771. if (pll->refcount == 0)
  2772. continue;
  2773. if (dpll == (I915_READ(pll->pll_reg) & 0x7fffffff) &&
  2774. fp == I915_READ(pll->fp0_reg)) {
  2775. DRM_DEBUG_KMS("CRTC:%d sharing existing PCH PLL %x (refcount %d, ative %d)\n",
  2776. intel_crtc->base.base.id,
  2777. pll->pll_reg, pll->refcount, pll->active);
  2778. goto found;
  2779. }
  2780. }
  2781. /* Ok no matching timings, maybe there's a free one? */
  2782. for (i = 0; i < dev_priv->num_pch_pll; i++) {
  2783. pll = &dev_priv->pch_plls[i];
  2784. if (pll->refcount == 0) {
  2785. DRM_DEBUG_KMS("CRTC:%d allocated PCH PLL %x\n",
  2786. intel_crtc->base.base.id, pll->pll_reg);
  2787. goto found;
  2788. }
  2789. }
  2790. return NULL;
  2791. found:
  2792. intel_crtc->pch_pll = pll;
  2793. pll->refcount++;
  2794. DRM_DEBUG_DRIVER("using pll %d for pipe %d\n", i, intel_crtc->pipe);
  2795. prepare: /* separate function? */
  2796. DRM_DEBUG_DRIVER("switching PLL %x off\n", pll->pll_reg);
  2797. /* Wait for the clocks to stabilize before rewriting the regs */
  2798. I915_WRITE(pll->pll_reg, dpll & ~DPLL_VCO_ENABLE);
  2799. POSTING_READ(pll->pll_reg);
  2800. udelay(150);
  2801. I915_WRITE(pll->fp0_reg, fp);
  2802. I915_WRITE(pll->pll_reg, dpll & ~DPLL_VCO_ENABLE);
  2803. pll->on = false;
  2804. return pll;
  2805. }
  2806. void intel_cpt_verify_modeset(struct drm_device *dev, int pipe)
  2807. {
  2808. struct drm_i915_private *dev_priv = dev->dev_private;
  2809. int dslreg = PIPEDSL(pipe);
  2810. u32 temp;
  2811. temp = I915_READ(dslreg);
  2812. udelay(500);
  2813. if (wait_for(I915_READ(dslreg) != temp, 5)) {
  2814. if (wait_for(I915_READ(dslreg) != temp, 5))
  2815. DRM_ERROR("mode set failed: pipe %d stuck\n", pipe);
  2816. }
  2817. }
  2818. static void ironlake_crtc_enable(struct drm_crtc *crtc)
  2819. {
  2820. struct drm_device *dev = crtc->dev;
  2821. struct drm_i915_private *dev_priv = dev->dev_private;
  2822. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2823. struct intel_encoder *encoder;
  2824. int pipe = intel_crtc->pipe;
  2825. int plane = intel_crtc->plane;
  2826. u32 temp;
  2827. bool is_pch_port;
  2828. WARN_ON(!crtc->enabled);
  2829. if (intel_crtc->active)
  2830. return;
  2831. intel_crtc->active = true;
  2832. intel_update_watermarks(dev);
  2833. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  2834. temp = I915_READ(PCH_LVDS);
  2835. if ((temp & LVDS_PORT_EN) == 0)
  2836. I915_WRITE(PCH_LVDS, temp | LVDS_PORT_EN);
  2837. }
  2838. is_pch_port = ironlake_crtc_driving_pch(crtc);
  2839. if (is_pch_port) {
  2840. /* Note: FDI PLL enabling _must_ be done before we enable the
  2841. * cpu pipes, hence this is separate from all the other fdi/pch
  2842. * enabling. */
  2843. ironlake_fdi_pll_enable(intel_crtc);
  2844. } else {
  2845. assert_fdi_tx_disabled(dev_priv, pipe);
  2846. assert_fdi_rx_disabled(dev_priv, pipe);
  2847. }
  2848. for_each_encoder_on_crtc(dev, crtc, encoder)
  2849. if (encoder->pre_enable)
  2850. encoder->pre_enable(encoder);
  2851. /* Enable panel fitting for LVDS */
  2852. if (dev_priv->pch_pf_size &&
  2853. (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) ||
  2854. intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) {
  2855. /* Force use of hard-coded filter coefficients
  2856. * as some pre-programmed values are broken,
  2857. * e.g. x201.
  2858. */
  2859. if (IS_IVYBRIDGE(dev))
  2860. I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
  2861. PF_PIPE_SEL_IVB(pipe));
  2862. else
  2863. I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
  2864. I915_WRITE(PF_WIN_POS(pipe), dev_priv->pch_pf_pos);
  2865. I915_WRITE(PF_WIN_SZ(pipe), dev_priv->pch_pf_size);
  2866. }
  2867. /*
  2868. * On ILK+ LUT must be loaded before the pipe is running but with
  2869. * clocks enabled
  2870. */
  2871. intel_crtc_load_lut(crtc);
  2872. intel_enable_pipe(dev_priv, pipe, is_pch_port);
  2873. intel_enable_plane(dev_priv, plane, pipe);
  2874. if (is_pch_port)
  2875. ironlake_pch_enable(crtc);
  2876. mutex_lock(&dev->struct_mutex);
  2877. intel_update_fbc(dev);
  2878. mutex_unlock(&dev->struct_mutex);
  2879. intel_crtc_update_cursor(crtc, true);
  2880. for_each_encoder_on_crtc(dev, crtc, encoder)
  2881. encoder->enable(encoder);
  2882. if (HAS_PCH_CPT(dev))
  2883. intel_cpt_verify_modeset(dev, intel_crtc->pipe);
  2884. /*
  2885. * There seems to be a race in PCH platform hw (at least on some
  2886. * outputs) where an enabled pipe still completes any pageflip right
  2887. * away (as if the pipe is off) instead of waiting for vblank. As soon
  2888. * as the first vblank happend, everything works as expected. Hence just
  2889. * wait for one vblank before returning to avoid strange things
  2890. * happening.
  2891. */
  2892. intel_wait_for_vblank(dev, intel_crtc->pipe);
  2893. }
  2894. static void haswell_crtc_enable(struct drm_crtc *crtc)
  2895. {
  2896. struct drm_device *dev = crtc->dev;
  2897. struct drm_i915_private *dev_priv = dev->dev_private;
  2898. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2899. struct intel_encoder *encoder;
  2900. int pipe = intel_crtc->pipe;
  2901. int plane = intel_crtc->plane;
  2902. bool is_pch_port;
  2903. WARN_ON(!crtc->enabled);
  2904. if (intel_crtc->active)
  2905. return;
  2906. intel_crtc->active = true;
  2907. intel_update_watermarks(dev);
  2908. is_pch_port = haswell_crtc_driving_pch(crtc);
  2909. if (is_pch_port)
  2910. dev_priv->display.fdi_link_train(crtc);
  2911. for_each_encoder_on_crtc(dev, crtc, encoder)
  2912. if (encoder->pre_enable)
  2913. encoder->pre_enable(encoder);
  2914. intel_ddi_enable_pipe_clock(intel_crtc);
  2915. /* Enable panel fitting for eDP */
  2916. if (dev_priv->pch_pf_size &&
  2917. intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) {
  2918. /* Force use of hard-coded filter coefficients
  2919. * as some pre-programmed values are broken,
  2920. * e.g. x201.
  2921. */
  2922. I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
  2923. PF_PIPE_SEL_IVB(pipe));
  2924. I915_WRITE(PF_WIN_POS(pipe), dev_priv->pch_pf_pos);
  2925. I915_WRITE(PF_WIN_SZ(pipe), dev_priv->pch_pf_size);
  2926. }
  2927. /*
  2928. * On ILK+ LUT must be loaded before the pipe is running but with
  2929. * clocks enabled
  2930. */
  2931. intel_crtc_load_lut(crtc);
  2932. intel_ddi_set_pipe_settings(crtc);
  2933. intel_ddi_enable_pipe_func(crtc);
  2934. intel_enable_pipe(dev_priv, pipe, is_pch_port);
  2935. intel_enable_plane(dev_priv, plane, pipe);
  2936. if (is_pch_port)
  2937. lpt_pch_enable(crtc);
  2938. mutex_lock(&dev->struct_mutex);
  2939. intel_update_fbc(dev);
  2940. mutex_unlock(&dev->struct_mutex);
  2941. intel_crtc_update_cursor(crtc, true);
  2942. for_each_encoder_on_crtc(dev, crtc, encoder)
  2943. encoder->enable(encoder);
  2944. /*
  2945. * There seems to be a race in PCH platform hw (at least on some
  2946. * outputs) where an enabled pipe still completes any pageflip right
  2947. * away (as if the pipe is off) instead of waiting for vblank. As soon
  2948. * as the first vblank happend, everything works as expected. Hence just
  2949. * wait for one vblank before returning to avoid strange things
  2950. * happening.
  2951. */
  2952. intel_wait_for_vblank(dev, intel_crtc->pipe);
  2953. }
  2954. static void ironlake_crtc_disable(struct drm_crtc *crtc)
  2955. {
  2956. struct drm_device *dev = crtc->dev;
  2957. struct drm_i915_private *dev_priv = dev->dev_private;
  2958. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2959. struct intel_encoder *encoder;
  2960. int pipe = intel_crtc->pipe;
  2961. int plane = intel_crtc->plane;
  2962. u32 reg, temp;
  2963. if (!intel_crtc->active)
  2964. return;
  2965. for_each_encoder_on_crtc(dev, crtc, encoder)
  2966. encoder->disable(encoder);
  2967. intel_crtc_wait_for_pending_flips(crtc);
  2968. drm_vblank_off(dev, pipe);
  2969. intel_crtc_update_cursor(crtc, false);
  2970. intel_disable_plane(dev_priv, plane, pipe);
  2971. if (dev_priv->cfb_plane == plane)
  2972. intel_disable_fbc(dev);
  2973. intel_disable_pipe(dev_priv, pipe);
  2974. /* Disable PF */
  2975. I915_WRITE(PF_CTL(pipe), 0);
  2976. I915_WRITE(PF_WIN_SZ(pipe), 0);
  2977. for_each_encoder_on_crtc(dev, crtc, encoder)
  2978. if (encoder->post_disable)
  2979. encoder->post_disable(encoder);
  2980. ironlake_fdi_disable(crtc);
  2981. ironlake_disable_pch_transcoder(dev_priv, pipe);
  2982. if (HAS_PCH_CPT(dev)) {
  2983. /* disable TRANS_DP_CTL */
  2984. reg = TRANS_DP_CTL(pipe);
  2985. temp = I915_READ(reg);
  2986. temp &= ~(TRANS_DP_OUTPUT_ENABLE | TRANS_DP_PORT_SEL_MASK);
  2987. temp |= TRANS_DP_PORT_SEL_NONE;
  2988. I915_WRITE(reg, temp);
  2989. /* disable DPLL_SEL */
  2990. temp = I915_READ(PCH_DPLL_SEL);
  2991. switch (pipe) {
  2992. case 0:
  2993. temp &= ~(TRANSA_DPLL_ENABLE | TRANSA_DPLLB_SEL);
  2994. break;
  2995. case 1:
  2996. temp &= ~(TRANSB_DPLL_ENABLE | TRANSB_DPLLB_SEL);
  2997. break;
  2998. case 2:
  2999. /* C shares PLL A or B */
  3000. temp &= ~(TRANSC_DPLL_ENABLE | TRANSC_DPLLB_SEL);
  3001. break;
  3002. default:
  3003. BUG(); /* wtf */
  3004. }
  3005. I915_WRITE(PCH_DPLL_SEL, temp);
  3006. }
  3007. /* disable PCH DPLL */
  3008. intel_disable_pch_pll(intel_crtc);
  3009. ironlake_fdi_pll_disable(intel_crtc);
  3010. intel_crtc->active = false;
  3011. intel_update_watermarks(dev);
  3012. mutex_lock(&dev->struct_mutex);
  3013. intel_update_fbc(dev);
  3014. mutex_unlock(&dev->struct_mutex);
  3015. }
  3016. static void haswell_crtc_disable(struct drm_crtc *crtc)
  3017. {
  3018. struct drm_device *dev = crtc->dev;
  3019. struct drm_i915_private *dev_priv = dev->dev_private;
  3020. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3021. struct intel_encoder *encoder;
  3022. int pipe = intel_crtc->pipe;
  3023. int plane = intel_crtc->plane;
  3024. enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
  3025. bool is_pch_port;
  3026. if (!intel_crtc->active)
  3027. return;
  3028. is_pch_port = haswell_crtc_driving_pch(crtc);
  3029. for_each_encoder_on_crtc(dev, crtc, encoder)
  3030. encoder->disable(encoder);
  3031. intel_crtc_wait_for_pending_flips(crtc);
  3032. drm_vblank_off(dev, pipe);
  3033. intel_crtc_update_cursor(crtc, false);
  3034. intel_disable_plane(dev_priv, plane, pipe);
  3035. if (dev_priv->cfb_plane == plane)
  3036. intel_disable_fbc(dev);
  3037. intel_disable_pipe(dev_priv, pipe);
  3038. intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder);
  3039. /* Disable PF */
  3040. I915_WRITE(PF_CTL(pipe), 0);
  3041. I915_WRITE(PF_WIN_SZ(pipe), 0);
  3042. intel_ddi_disable_pipe_clock(intel_crtc);
  3043. for_each_encoder_on_crtc(dev, crtc, encoder)
  3044. if (encoder->post_disable)
  3045. encoder->post_disable(encoder);
  3046. if (is_pch_port) {
  3047. lpt_disable_pch_transcoder(dev_priv);
  3048. intel_ddi_fdi_disable(crtc);
  3049. }
  3050. intel_crtc->active = false;
  3051. intel_update_watermarks(dev);
  3052. mutex_lock(&dev->struct_mutex);
  3053. intel_update_fbc(dev);
  3054. mutex_unlock(&dev->struct_mutex);
  3055. }
  3056. static void ironlake_crtc_off(struct drm_crtc *crtc)
  3057. {
  3058. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3059. intel_put_pch_pll(intel_crtc);
  3060. }
  3061. static void haswell_crtc_off(struct drm_crtc *crtc)
  3062. {
  3063. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3064. /* Stop saying we're using TRANSCODER_EDP because some other CRTC might
  3065. * start using it. */
  3066. intel_crtc->cpu_transcoder = (enum transcoder) intel_crtc->pipe;
  3067. intel_ddi_put_crtc_pll(crtc);
  3068. }
  3069. static void intel_crtc_dpms_overlay(struct intel_crtc *intel_crtc, bool enable)
  3070. {
  3071. if (!enable && intel_crtc->overlay) {
  3072. struct drm_device *dev = intel_crtc->base.dev;
  3073. struct drm_i915_private *dev_priv = dev->dev_private;
  3074. mutex_lock(&dev->struct_mutex);
  3075. dev_priv->mm.interruptible = false;
  3076. (void) intel_overlay_switch_off(intel_crtc->overlay);
  3077. dev_priv->mm.interruptible = true;
  3078. mutex_unlock(&dev->struct_mutex);
  3079. }
  3080. /* Let userspace switch the overlay on again. In most cases userspace
  3081. * has to recompute where to put it anyway.
  3082. */
  3083. }
  3084. static void i9xx_crtc_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. struct intel_encoder *encoder;
  3090. int pipe = intel_crtc->pipe;
  3091. int plane = intel_crtc->plane;
  3092. WARN_ON(!crtc->enabled);
  3093. if (intel_crtc->active)
  3094. return;
  3095. intel_crtc->active = true;
  3096. intel_update_watermarks(dev);
  3097. intel_enable_pll(dev_priv, pipe);
  3098. for_each_encoder_on_crtc(dev, crtc, encoder)
  3099. if (encoder->pre_enable)
  3100. encoder->pre_enable(encoder);
  3101. intel_enable_pipe(dev_priv, pipe, false);
  3102. intel_enable_plane(dev_priv, plane, pipe);
  3103. intel_crtc_load_lut(crtc);
  3104. intel_update_fbc(dev);
  3105. /* Give the overlay scaler a chance to enable if it's on this pipe */
  3106. intel_crtc_dpms_overlay(intel_crtc, true);
  3107. intel_crtc_update_cursor(crtc, true);
  3108. for_each_encoder_on_crtc(dev, crtc, encoder)
  3109. encoder->enable(encoder);
  3110. }
  3111. static void i9xx_crtc_disable(struct drm_crtc *crtc)
  3112. {
  3113. struct drm_device *dev = crtc->dev;
  3114. struct drm_i915_private *dev_priv = dev->dev_private;
  3115. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3116. struct intel_encoder *encoder;
  3117. int pipe = intel_crtc->pipe;
  3118. int plane = intel_crtc->plane;
  3119. u32 pctl;
  3120. if (!intel_crtc->active)
  3121. return;
  3122. for_each_encoder_on_crtc(dev, crtc, encoder)
  3123. encoder->disable(encoder);
  3124. /* Give the overlay scaler a chance to disable if it's on this pipe */
  3125. intel_crtc_wait_for_pending_flips(crtc);
  3126. drm_vblank_off(dev, pipe);
  3127. intel_crtc_dpms_overlay(intel_crtc, false);
  3128. intel_crtc_update_cursor(crtc, false);
  3129. if (dev_priv->cfb_plane == plane)
  3130. intel_disable_fbc(dev);
  3131. intel_disable_plane(dev_priv, plane, pipe);
  3132. intel_disable_pipe(dev_priv, pipe);
  3133. /* Disable pannel fitter if it is on this pipe. */
  3134. pctl = I915_READ(PFIT_CONTROL);
  3135. if ((pctl & PFIT_ENABLE) &&
  3136. ((pctl & PFIT_PIPE_MASK) >> PFIT_PIPE_SHIFT) == pipe)
  3137. I915_WRITE(PFIT_CONTROL, 0);
  3138. intel_disable_pll(dev_priv, pipe);
  3139. intel_crtc->active = false;
  3140. intel_update_fbc(dev);
  3141. intel_update_watermarks(dev);
  3142. }
  3143. static void i9xx_crtc_off(struct drm_crtc *crtc)
  3144. {
  3145. }
  3146. static void intel_crtc_update_sarea(struct drm_crtc *crtc,
  3147. bool enabled)
  3148. {
  3149. struct drm_device *dev = crtc->dev;
  3150. struct drm_i915_master_private *master_priv;
  3151. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3152. int pipe = intel_crtc->pipe;
  3153. if (!dev->primary->master)
  3154. return;
  3155. master_priv = dev->primary->master->driver_priv;
  3156. if (!master_priv->sarea_priv)
  3157. return;
  3158. switch (pipe) {
  3159. case 0:
  3160. master_priv->sarea_priv->pipeA_w = enabled ? crtc->mode.hdisplay : 0;
  3161. master_priv->sarea_priv->pipeA_h = enabled ? crtc->mode.vdisplay : 0;
  3162. break;
  3163. case 1:
  3164. master_priv->sarea_priv->pipeB_w = enabled ? crtc->mode.hdisplay : 0;
  3165. master_priv->sarea_priv->pipeB_h = enabled ? crtc->mode.vdisplay : 0;
  3166. break;
  3167. default:
  3168. DRM_ERROR("Can't update pipe %c in SAREA\n", pipe_name(pipe));
  3169. break;
  3170. }
  3171. }
  3172. /**
  3173. * Sets the power management mode of the pipe and plane.
  3174. */
  3175. void intel_crtc_update_dpms(struct drm_crtc *crtc)
  3176. {
  3177. struct drm_device *dev = crtc->dev;
  3178. struct drm_i915_private *dev_priv = dev->dev_private;
  3179. struct intel_encoder *intel_encoder;
  3180. bool enable = false;
  3181. for_each_encoder_on_crtc(dev, crtc, intel_encoder)
  3182. enable |= intel_encoder->connectors_active;
  3183. if (enable)
  3184. dev_priv->display.crtc_enable(crtc);
  3185. else
  3186. dev_priv->display.crtc_disable(crtc);
  3187. intel_crtc_update_sarea(crtc, enable);
  3188. }
  3189. static void intel_crtc_noop(struct drm_crtc *crtc)
  3190. {
  3191. }
  3192. static void intel_crtc_disable(struct drm_crtc *crtc)
  3193. {
  3194. struct drm_device *dev = crtc->dev;
  3195. struct drm_connector *connector;
  3196. struct drm_i915_private *dev_priv = dev->dev_private;
  3197. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3198. /* crtc should still be enabled when we disable it. */
  3199. WARN_ON(!crtc->enabled);
  3200. intel_crtc->eld_vld = false;
  3201. dev_priv->display.crtc_disable(crtc);
  3202. intel_crtc_update_sarea(crtc, false);
  3203. dev_priv->display.off(crtc);
  3204. assert_plane_disabled(dev->dev_private, to_intel_crtc(crtc)->plane);
  3205. assert_pipe_disabled(dev->dev_private, to_intel_crtc(crtc)->pipe);
  3206. if (crtc->fb) {
  3207. mutex_lock(&dev->struct_mutex);
  3208. intel_unpin_fb_obj(to_intel_framebuffer(crtc->fb)->obj);
  3209. mutex_unlock(&dev->struct_mutex);
  3210. crtc->fb = NULL;
  3211. }
  3212. /* Update computed state. */
  3213. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  3214. if (!connector->encoder || !connector->encoder->crtc)
  3215. continue;
  3216. if (connector->encoder->crtc != crtc)
  3217. continue;
  3218. connector->dpms = DRM_MODE_DPMS_OFF;
  3219. to_intel_encoder(connector->encoder)->connectors_active = false;
  3220. }
  3221. }
  3222. void intel_modeset_disable(struct drm_device *dev)
  3223. {
  3224. struct drm_crtc *crtc;
  3225. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  3226. if (crtc->enabled)
  3227. intel_crtc_disable(crtc);
  3228. }
  3229. }
  3230. void intel_encoder_noop(struct drm_encoder *encoder)
  3231. {
  3232. }
  3233. void intel_encoder_destroy(struct drm_encoder *encoder)
  3234. {
  3235. struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
  3236. drm_encoder_cleanup(encoder);
  3237. kfree(intel_encoder);
  3238. }
  3239. /* Simple dpms helper for encodres with just one connector, no cloning and only
  3240. * one kind of off state. It clamps all !ON modes to fully OFF and changes the
  3241. * state of the entire output pipe. */
  3242. void intel_encoder_dpms(struct intel_encoder *encoder, int mode)
  3243. {
  3244. if (mode == DRM_MODE_DPMS_ON) {
  3245. encoder->connectors_active = true;
  3246. intel_crtc_update_dpms(encoder->base.crtc);
  3247. } else {
  3248. encoder->connectors_active = false;
  3249. intel_crtc_update_dpms(encoder->base.crtc);
  3250. }
  3251. }
  3252. /* Cross check the actual hw state with our own modeset state tracking (and it's
  3253. * internal consistency). */
  3254. static void intel_connector_check_state(struct intel_connector *connector)
  3255. {
  3256. if (connector->get_hw_state(connector)) {
  3257. struct intel_encoder *encoder = connector->encoder;
  3258. struct drm_crtc *crtc;
  3259. bool encoder_enabled;
  3260. enum pipe pipe;
  3261. DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
  3262. connector->base.base.id,
  3263. drm_get_connector_name(&connector->base));
  3264. WARN(connector->base.dpms == DRM_MODE_DPMS_OFF,
  3265. "wrong connector dpms state\n");
  3266. WARN(connector->base.encoder != &encoder->base,
  3267. "active connector not linked to encoder\n");
  3268. WARN(!encoder->connectors_active,
  3269. "encoder->connectors_active not set\n");
  3270. encoder_enabled = encoder->get_hw_state(encoder, &pipe);
  3271. WARN(!encoder_enabled, "encoder not enabled\n");
  3272. if (WARN_ON(!encoder->base.crtc))
  3273. return;
  3274. crtc = encoder->base.crtc;
  3275. WARN(!crtc->enabled, "crtc not enabled\n");
  3276. WARN(!to_intel_crtc(crtc)->active, "crtc not active\n");
  3277. WARN(pipe != to_intel_crtc(crtc)->pipe,
  3278. "encoder active on the wrong pipe\n");
  3279. }
  3280. }
  3281. /* Even simpler default implementation, if there's really no special case to
  3282. * consider. */
  3283. void intel_connector_dpms(struct drm_connector *connector, int mode)
  3284. {
  3285. struct intel_encoder *encoder = intel_attached_encoder(connector);
  3286. /* All the simple cases only support two dpms states. */
  3287. if (mode != DRM_MODE_DPMS_ON)
  3288. mode = DRM_MODE_DPMS_OFF;
  3289. if (mode == connector->dpms)
  3290. return;
  3291. connector->dpms = mode;
  3292. /* Only need to change hw state when actually enabled */
  3293. if (encoder->base.crtc)
  3294. intel_encoder_dpms(encoder, mode);
  3295. else
  3296. WARN_ON(encoder->connectors_active != false);
  3297. intel_modeset_check_state(connector->dev);
  3298. }
  3299. /* Simple connector->get_hw_state implementation for encoders that support only
  3300. * one connector and no cloning and hence the encoder state determines the state
  3301. * of the connector. */
  3302. bool intel_connector_get_hw_state(struct intel_connector *connector)
  3303. {
  3304. enum pipe pipe = 0;
  3305. struct intel_encoder *encoder = connector->encoder;
  3306. return encoder->get_hw_state(encoder, &pipe);
  3307. }
  3308. static bool intel_crtc_mode_fixup(struct drm_crtc *crtc,
  3309. const struct drm_display_mode *mode,
  3310. struct drm_display_mode *adjusted_mode)
  3311. {
  3312. struct drm_device *dev = crtc->dev;
  3313. if (HAS_PCH_SPLIT(dev)) {
  3314. /* FDI link clock is fixed at 2.7G */
  3315. if (mode->clock * 3 > IRONLAKE_FDI_FREQ * 4)
  3316. return false;
  3317. }
  3318. /* All interlaced capable intel hw wants timings in frames. Note though
  3319. * that intel_lvds_mode_fixup does some funny tricks with the crtc
  3320. * timings, so we need to be careful not to clobber these.*/
  3321. if (!(adjusted_mode->private_flags & INTEL_MODE_CRTC_TIMINGS_SET))
  3322. drm_mode_set_crtcinfo(adjusted_mode, 0);
  3323. /* WaPruneModeWithIncorrectHsyncOffset: Cantiga+ cannot handle modes
  3324. * with a hsync front porch of 0.
  3325. */
  3326. if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) &&
  3327. adjusted_mode->hsync_start == adjusted_mode->hdisplay)
  3328. return false;
  3329. return true;
  3330. }
  3331. static int valleyview_get_display_clock_speed(struct drm_device *dev)
  3332. {
  3333. return 400000; /* FIXME */
  3334. }
  3335. static int i945_get_display_clock_speed(struct drm_device *dev)
  3336. {
  3337. return 400000;
  3338. }
  3339. static int i915_get_display_clock_speed(struct drm_device *dev)
  3340. {
  3341. return 333000;
  3342. }
  3343. static int i9xx_misc_get_display_clock_speed(struct drm_device *dev)
  3344. {
  3345. return 200000;
  3346. }
  3347. static int i915gm_get_display_clock_speed(struct drm_device *dev)
  3348. {
  3349. u16 gcfgc = 0;
  3350. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  3351. if (gcfgc & GC_LOW_FREQUENCY_ENABLE)
  3352. return 133000;
  3353. else {
  3354. switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
  3355. case GC_DISPLAY_CLOCK_333_MHZ:
  3356. return 333000;
  3357. default:
  3358. case GC_DISPLAY_CLOCK_190_200_MHZ:
  3359. return 190000;
  3360. }
  3361. }
  3362. }
  3363. static int i865_get_display_clock_speed(struct drm_device *dev)
  3364. {
  3365. return 266000;
  3366. }
  3367. static int i855_get_display_clock_speed(struct drm_device *dev)
  3368. {
  3369. u16 hpllcc = 0;
  3370. /* Assume that the hardware is in the high speed state. This
  3371. * should be the default.
  3372. */
  3373. switch (hpllcc & GC_CLOCK_CONTROL_MASK) {
  3374. case GC_CLOCK_133_200:
  3375. case GC_CLOCK_100_200:
  3376. return 200000;
  3377. case GC_CLOCK_166_250:
  3378. return 250000;
  3379. case GC_CLOCK_100_133:
  3380. return 133000;
  3381. }
  3382. /* Shouldn't happen */
  3383. return 0;
  3384. }
  3385. static int i830_get_display_clock_speed(struct drm_device *dev)
  3386. {
  3387. return 133000;
  3388. }
  3389. static void
  3390. intel_reduce_ratio(uint32_t *num, uint32_t *den)
  3391. {
  3392. while (*num > 0xffffff || *den > 0xffffff) {
  3393. *num >>= 1;
  3394. *den >>= 1;
  3395. }
  3396. }
  3397. void
  3398. intel_link_compute_m_n(int bits_per_pixel, int nlanes,
  3399. int pixel_clock, int link_clock,
  3400. struct intel_link_m_n *m_n)
  3401. {
  3402. m_n->tu = 64;
  3403. m_n->gmch_m = bits_per_pixel * pixel_clock;
  3404. m_n->gmch_n = link_clock * nlanes * 8;
  3405. intel_reduce_ratio(&m_n->gmch_m, &m_n->gmch_n);
  3406. m_n->link_m = pixel_clock;
  3407. m_n->link_n = link_clock;
  3408. intel_reduce_ratio(&m_n->link_m, &m_n->link_n);
  3409. }
  3410. static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
  3411. {
  3412. if (i915_panel_use_ssc >= 0)
  3413. return i915_panel_use_ssc != 0;
  3414. return dev_priv->lvds_use_ssc
  3415. && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
  3416. }
  3417. /**
  3418. * intel_choose_pipe_bpp_dither - figure out what color depth the pipe should send
  3419. * @crtc: CRTC structure
  3420. * @mode: requested mode
  3421. *
  3422. * A pipe may be connected to one or more outputs. Based on the depth of the
  3423. * attached framebuffer, choose a good color depth to use on the pipe.
  3424. *
  3425. * If possible, match the pipe depth to the fb depth. In some cases, this
  3426. * isn't ideal, because the connected output supports a lesser or restricted
  3427. * set of depths. Resolve that here:
  3428. * LVDS typically supports only 6bpc, so clamp down in that case
  3429. * HDMI supports only 8bpc or 12bpc, so clamp to 8bpc with dither for 10bpc
  3430. * Displays may support a restricted set as well, check EDID and clamp as
  3431. * appropriate.
  3432. * DP may want to dither down to 6bpc to fit larger modes
  3433. *
  3434. * RETURNS:
  3435. * Dithering requirement (i.e. false if display bpc and pipe bpc match,
  3436. * true if they don't match).
  3437. */
  3438. static bool intel_choose_pipe_bpp_dither(struct drm_crtc *crtc,
  3439. struct drm_framebuffer *fb,
  3440. unsigned int *pipe_bpp,
  3441. struct drm_display_mode *mode)
  3442. {
  3443. struct drm_device *dev = crtc->dev;
  3444. struct drm_i915_private *dev_priv = dev->dev_private;
  3445. struct drm_connector *connector;
  3446. struct intel_encoder *intel_encoder;
  3447. unsigned int display_bpc = UINT_MAX, bpc;
  3448. /* Walk the encoders & connectors on this crtc, get min bpc */
  3449. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  3450. if (intel_encoder->type == INTEL_OUTPUT_LVDS) {
  3451. unsigned int lvds_bpc;
  3452. if ((I915_READ(PCH_LVDS) & LVDS_A3_POWER_MASK) ==
  3453. LVDS_A3_POWER_UP)
  3454. lvds_bpc = 8;
  3455. else
  3456. lvds_bpc = 6;
  3457. if (lvds_bpc < display_bpc) {
  3458. DRM_DEBUG_KMS("clamping display bpc (was %d) to LVDS (%d)\n", display_bpc, lvds_bpc);
  3459. display_bpc = lvds_bpc;
  3460. }
  3461. continue;
  3462. }
  3463. /* Not one of the known troublemakers, check the EDID */
  3464. list_for_each_entry(connector, &dev->mode_config.connector_list,
  3465. head) {
  3466. if (connector->encoder != &intel_encoder->base)
  3467. continue;
  3468. /* Don't use an invalid EDID bpc value */
  3469. if (connector->display_info.bpc &&
  3470. connector->display_info.bpc < display_bpc) {
  3471. DRM_DEBUG_KMS("clamping display bpc (was %d) to EDID reported max of %d\n", display_bpc, connector->display_info.bpc);
  3472. display_bpc = connector->display_info.bpc;
  3473. }
  3474. }
  3475. if (intel_encoder->type == INTEL_OUTPUT_EDP) {
  3476. /* Use VBT settings if we have an eDP panel */
  3477. unsigned int edp_bpc = dev_priv->edp.bpp / 3;
  3478. if (edp_bpc && edp_bpc < display_bpc) {
  3479. DRM_DEBUG_KMS("clamping display bpc (was %d) to eDP (%d)\n", display_bpc, edp_bpc);
  3480. display_bpc = edp_bpc;
  3481. }
  3482. continue;
  3483. }
  3484. /*
  3485. * HDMI is either 12 or 8, so if the display lets 10bpc sneak
  3486. * through, clamp it down. (Note: >12bpc will be caught below.)
  3487. */
  3488. if (intel_encoder->type == INTEL_OUTPUT_HDMI) {
  3489. if (display_bpc > 8 && display_bpc < 12) {
  3490. DRM_DEBUG_KMS("forcing bpc to 12 for HDMI\n");
  3491. display_bpc = 12;
  3492. } else {
  3493. DRM_DEBUG_KMS("forcing bpc to 8 for HDMI\n");
  3494. display_bpc = 8;
  3495. }
  3496. }
  3497. }
  3498. if (mode->private_flags & INTEL_MODE_DP_FORCE_6BPC) {
  3499. DRM_DEBUG_KMS("Dithering DP to 6bpc\n");
  3500. display_bpc = 6;
  3501. }
  3502. /*
  3503. * We could just drive the pipe at the highest bpc all the time and
  3504. * enable dithering as needed, but that costs bandwidth. So choose
  3505. * the minimum value that expresses the full color range of the fb but
  3506. * also stays within the max display bpc discovered above.
  3507. */
  3508. switch (fb->depth) {
  3509. case 8:
  3510. bpc = 8; /* since we go through a colormap */
  3511. break;
  3512. case 15:
  3513. case 16:
  3514. bpc = 6; /* min is 18bpp */
  3515. break;
  3516. case 24:
  3517. bpc = 8;
  3518. break;
  3519. case 30:
  3520. bpc = 10;
  3521. break;
  3522. case 48:
  3523. bpc = 12;
  3524. break;
  3525. default:
  3526. DRM_DEBUG("unsupported depth, assuming 24 bits\n");
  3527. bpc = min((unsigned int)8, display_bpc);
  3528. break;
  3529. }
  3530. display_bpc = min(display_bpc, bpc);
  3531. DRM_DEBUG_KMS("setting pipe bpc to %d (max display bpc %d)\n",
  3532. bpc, display_bpc);
  3533. *pipe_bpp = display_bpc * 3;
  3534. return display_bpc != bpc;
  3535. }
  3536. static int vlv_get_refclk(struct drm_crtc *crtc)
  3537. {
  3538. struct drm_device *dev = crtc->dev;
  3539. struct drm_i915_private *dev_priv = dev->dev_private;
  3540. int refclk = 27000; /* for DP & HDMI */
  3541. return 100000; /* only one validated so far */
  3542. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) {
  3543. refclk = 96000;
  3544. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  3545. if (intel_panel_use_ssc(dev_priv))
  3546. refclk = 100000;
  3547. else
  3548. refclk = 96000;
  3549. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) {
  3550. refclk = 100000;
  3551. }
  3552. return refclk;
  3553. }
  3554. static int i9xx_get_refclk(struct drm_crtc *crtc, int num_connectors)
  3555. {
  3556. struct drm_device *dev = crtc->dev;
  3557. struct drm_i915_private *dev_priv = dev->dev_private;
  3558. int refclk;
  3559. if (IS_VALLEYVIEW(dev)) {
  3560. refclk = vlv_get_refclk(crtc);
  3561. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  3562. intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
  3563. refclk = dev_priv->lvds_ssc_freq * 1000;
  3564. DRM_DEBUG_KMS("using SSC reference clock of %d MHz\n",
  3565. refclk / 1000);
  3566. } else if (!IS_GEN2(dev)) {
  3567. refclk = 96000;
  3568. } else {
  3569. refclk = 48000;
  3570. }
  3571. return refclk;
  3572. }
  3573. static void i9xx_adjust_sdvo_tv_clock(struct drm_display_mode *adjusted_mode,
  3574. intel_clock_t *clock)
  3575. {
  3576. /* SDVO TV has fixed PLL values depend on its clock range,
  3577. this mirrors vbios setting. */
  3578. if (adjusted_mode->clock >= 100000
  3579. && adjusted_mode->clock < 140500) {
  3580. clock->p1 = 2;
  3581. clock->p2 = 10;
  3582. clock->n = 3;
  3583. clock->m1 = 16;
  3584. clock->m2 = 8;
  3585. } else if (adjusted_mode->clock >= 140500
  3586. && adjusted_mode->clock <= 200000) {
  3587. clock->p1 = 1;
  3588. clock->p2 = 10;
  3589. clock->n = 6;
  3590. clock->m1 = 12;
  3591. clock->m2 = 8;
  3592. }
  3593. }
  3594. static void i9xx_update_pll_dividers(struct drm_crtc *crtc,
  3595. intel_clock_t *clock,
  3596. intel_clock_t *reduced_clock)
  3597. {
  3598. struct drm_device *dev = crtc->dev;
  3599. struct drm_i915_private *dev_priv = dev->dev_private;
  3600. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3601. int pipe = intel_crtc->pipe;
  3602. u32 fp, fp2 = 0;
  3603. if (IS_PINEVIEW(dev)) {
  3604. fp = (1 << clock->n) << 16 | clock->m1 << 8 | clock->m2;
  3605. if (reduced_clock)
  3606. fp2 = (1 << reduced_clock->n) << 16 |
  3607. reduced_clock->m1 << 8 | reduced_clock->m2;
  3608. } else {
  3609. fp = clock->n << 16 | clock->m1 << 8 | clock->m2;
  3610. if (reduced_clock)
  3611. fp2 = reduced_clock->n << 16 | reduced_clock->m1 << 8 |
  3612. reduced_clock->m2;
  3613. }
  3614. I915_WRITE(FP0(pipe), fp);
  3615. intel_crtc->lowfreq_avail = false;
  3616. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  3617. reduced_clock && i915_powersave) {
  3618. I915_WRITE(FP1(pipe), fp2);
  3619. intel_crtc->lowfreq_avail = true;
  3620. } else {
  3621. I915_WRITE(FP1(pipe), fp);
  3622. }
  3623. }
  3624. static void vlv_update_pll(struct drm_crtc *crtc,
  3625. struct drm_display_mode *mode,
  3626. struct drm_display_mode *adjusted_mode,
  3627. intel_clock_t *clock, intel_clock_t *reduced_clock,
  3628. int num_connectors)
  3629. {
  3630. struct drm_device *dev = crtc->dev;
  3631. struct drm_i915_private *dev_priv = dev->dev_private;
  3632. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3633. int pipe = intel_crtc->pipe;
  3634. u32 dpll, mdiv, pdiv;
  3635. u32 bestn, bestm1, bestm2, bestp1, bestp2;
  3636. bool is_sdvo;
  3637. u32 temp;
  3638. mutex_lock(&dev_priv->dpio_lock);
  3639. is_sdvo = intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO) ||
  3640. intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI);
  3641. dpll = DPLL_VGA_MODE_DIS;
  3642. dpll |= DPLL_EXT_BUFFER_ENABLE_VLV;
  3643. dpll |= DPLL_REFA_CLK_ENABLE_VLV;
  3644. dpll |= DPLL_INTEGRATED_CLOCK_VLV;
  3645. I915_WRITE(DPLL(pipe), dpll);
  3646. POSTING_READ(DPLL(pipe));
  3647. bestn = clock->n;
  3648. bestm1 = clock->m1;
  3649. bestm2 = clock->m2;
  3650. bestp1 = clock->p1;
  3651. bestp2 = clock->p2;
  3652. /*
  3653. * In Valleyview PLL and program lane counter registers are exposed
  3654. * through DPIO interface
  3655. */
  3656. mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
  3657. mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
  3658. mdiv |= ((bestn << DPIO_N_SHIFT));
  3659. mdiv |= (1 << DPIO_POST_DIV_SHIFT);
  3660. mdiv |= (1 << DPIO_K_SHIFT);
  3661. mdiv |= DPIO_ENABLE_CALIBRATION;
  3662. intel_dpio_write(dev_priv, DPIO_DIV(pipe), mdiv);
  3663. intel_dpio_write(dev_priv, DPIO_CORE_CLK(pipe), 0x01000000);
  3664. pdiv = (1 << DPIO_REFSEL_OVERRIDE) | (5 << DPIO_PLL_MODESEL_SHIFT) |
  3665. (3 << DPIO_BIAS_CURRENT_CTL_SHIFT) | (1<<20) |
  3666. (7 << DPIO_PLL_REFCLK_SEL_SHIFT) | (8 << DPIO_DRIVER_CTL_SHIFT) |
  3667. (5 << DPIO_CLK_BIAS_CTL_SHIFT);
  3668. intel_dpio_write(dev_priv, DPIO_REFSFR(pipe), pdiv);
  3669. intel_dpio_write(dev_priv, DPIO_LFP_COEFF(pipe), 0x005f003b);
  3670. dpll |= DPLL_VCO_ENABLE;
  3671. I915_WRITE(DPLL(pipe), dpll);
  3672. POSTING_READ(DPLL(pipe));
  3673. if (wait_for(((I915_READ(DPLL(pipe)) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1))
  3674. DRM_ERROR("DPLL %d failed to lock\n", pipe);
  3675. intel_dpio_write(dev_priv, DPIO_FASTCLK_DISABLE, 0x620);
  3676. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT))
  3677. intel_dp_set_m_n(crtc, mode, adjusted_mode);
  3678. I915_WRITE(DPLL(pipe), dpll);
  3679. /* Wait for the clocks to stabilize. */
  3680. POSTING_READ(DPLL(pipe));
  3681. udelay(150);
  3682. temp = 0;
  3683. if (is_sdvo) {
  3684. temp = intel_mode_get_pixel_multiplier(adjusted_mode);
  3685. if (temp > 1)
  3686. temp = (temp - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  3687. else
  3688. temp = 0;
  3689. }
  3690. I915_WRITE(DPLL_MD(pipe), temp);
  3691. POSTING_READ(DPLL_MD(pipe));
  3692. /* Now program lane control registers */
  3693. if(intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)
  3694. || intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI))
  3695. {
  3696. temp = 0x1000C4;
  3697. if(pipe == 1)
  3698. temp |= (1 << 21);
  3699. intel_dpio_write(dev_priv, DPIO_DATA_CHANNEL1, temp);
  3700. }
  3701. if(intel_pipe_has_type(crtc,INTEL_OUTPUT_EDP))
  3702. {
  3703. temp = 0x1000C4;
  3704. if(pipe == 1)
  3705. temp |= (1 << 21);
  3706. intel_dpio_write(dev_priv, DPIO_DATA_CHANNEL2, temp);
  3707. }
  3708. mutex_unlock(&dev_priv->dpio_lock);
  3709. }
  3710. static void i9xx_update_pll(struct drm_crtc *crtc,
  3711. struct drm_display_mode *mode,
  3712. struct drm_display_mode *adjusted_mode,
  3713. intel_clock_t *clock, intel_clock_t *reduced_clock,
  3714. int num_connectors)
  3715. {
  3716. struct drm_device *dev = crtc->dev;
  3717. struct drm_i915_private *dev_priv = dev->dev_private;
  3718. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3719. struct intel_encoder *encoder;
  3720. int pipe = intel_crtc->pipe;
  3721. u32 dpll;
  3722. bool is_sdvo;
  3723. i9xx_update_pll_dividers(crtc, clock, reduced_clock);
  3724. is_sdvo = intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO) ||
  3725. intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI);
  3726. dpll = DPLL_VGA_MODE_DIS;
  3727. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  3728. dpll |= DPLLB_MODE_LVDS;
  3729. else
  3730. dpll |= DPLLB_MODE_DAC_SERIAL;
  3731. if (is_sdvo) {
  3732. int pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
  3733. if (pixel_multiplier > 1) {
  3734. if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev))
  3735. dpll |= (pixel_multiplier - 1) << SDVO_MULTIPLIER_SHIFT_HIRES;
  3736. }
  3737. dpll |= DPLL_DVO_HIGH_SPEED;
  3738. }
  3739. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT))
  3740. dpll |= DPLL_DVO_HIGH_SPEED;
  3741. /* compute bitmask from p1 value */
  3742. if (IS_PINEVIEW(dev))
  3743. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
  3744. else {
  3745. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  3746. if (IS_G4X(dev) && reduced_clock)
  3747. dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  3748. }
  3749. switch (clock->p2) {
  3750. case 5:
  3751. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  3752. break;
  3753. case 7:
  3754. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  3755. break;
  3756. case 10:
  3757. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  3758. break;
  3759. case 14:
  3760. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  3761. break;
  3762. }
  3763. if (INTEL_INFO(dev)->gen >= 4)
  3764. dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
  3765. if (is_sdvo && intel_pipe_has_type(crtc, INTEL_OUTPUT_TVOUT))
  3766. dpll |= PLL_REF_INPUT_TVCLKINBC;
  3767. else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_TVOUT))
  3768. /* XXX: just matching BIOS for now */
  3769. /* dpll |= PLL_REF_INPUT_TVCLKINBC; */
  3770. dpll |= 3;
  3771. else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  3772. intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  3773. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  3774. else
  3775. dpll |= PLL_REF_INPUT_DREFCLK;
  3776. dpll |= DPLL_VCO_ENABLE;
  3777. I915_WRITE(DPLL(pipe), dpll & ~DPLL_VCO_ENABLE);
  3778. POSTING_READ(DPLL(pipe));
  3779. udelay(150);
  3780. for_each_encoder_on_crtc(dev, crtc, encoder)
  3781. if (encoder->pre_pll_enable)
  3782. encoder->pre_pll_enable(encoder);
  3783. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT))
  3784. intel_dp_set_m_n(crtc, mode, adjusted_mode);
  3785. I915_WRITE(DPLL(pipe), dpll);
  3786. /* Wait for the clocks to stabilize. */
  3787. POSTING_READ(DPLL(pipe));
  3788. udelay(150);
  3789. if (INTEL_INFO(dev)->gen >= 4) {
  3790. u32 temp = 0;
  3791. if (is_sdvo) {
  3792. temp = intel_mode_get_pixel_multiplier(adjusted_mode);
  3793. if (temp > 1)
  3794. temp = (temp - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  3795. else
  3796. temp = 0;
  3797. }
  3798. I915_WRITE(DPLL_MD(pipe), temp);
  3799. } else {
  3800. /* The pixel multiplier can only be updated once the
  3801. * DPLL is enabled and the clocks are stable.
  3802. *
  3803. * So write it again.
  3804. */
  3805. I915_WRITE(DPLL(pipe), dpll);
  3806. }
  3807. }
  3808. static void i8xx_update_pll(struct drm_crtc *crtc,
  3809. struct drm_display_mode *adjusted_mode,
  3810. intel_clock_t *clock, intel_clock_t *reduced_clock,
  3811. int num_connectors)
  3812. {
  3813. struct drm_device *dev = crtc->dev;
  3814. struct drm_i915_private *dev_priv = dev->dev_private;
  3815. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3816. struct intel_encoder *encoder;
  3817. int pipe = intel_crtc->pipe;
  3818. u32 dpll;
  3819. i9xx_update_pll_dividers(crtc, clock, reduced_clock);
  3820. dpll = DPLL_VGA_MODE_DIS;
  3821. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  3822. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  3823. } else {
  3824. if (clock->p1 == 2)
  3825. dpll |= PLL_P1_DIVIDE_BY_TWO;
  3826. else
  3827. dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  3828. if (clock->p2 == 4)
  3829. dpll |= PLL_P2_DIVIDE_BY_4;
  3830. }
  3831. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_TVOUT))
  3832. /* XXX: just matching BIOS for now */
  3833. /* dpll |= PLL_REF_INPUT_TVCLKINBC; */
  3834. dpll |= 3;
  3835. else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  3836. intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  3837. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  3838. else
  3839. dpll |= PLL_REF_INPUT_DREFCLK;
  3840. dpll |= DPLL_VCO_ENABLE;
  3841. I915_WRITE(DPLL(pipe), dpll & ~DPLL_VCO_ENABLE);
  3842. POSTING_READ(DPLL(pipe));
  3843. udelay(150);
  3844. for_each_encoder_on_crtc(dev, crtc, encoder)
  3845. if (encoder->pre_pll_enable)
  3846. encoder->pre_pll_enable(encoder);
  3847. I915_WRITE(DPLL(pipe), dpll);
  3848. /* Wait for the clocks to stabilize. */
  3849. POSTING_READ(DPLL(pipe));
  3850. udelay(150);
  3851. /* The pixel multiplier can only be updated once the
  3852. * DPLL is enabled and the clocks are stable.
  3853. *
  3854. * So write it again.
  3855. */
  3856. I915_WRITE(DPLL(pipe), dpll);
  3857. }
  3858. static void intel_set_pipe_timings(struct intel_crtc *intel_crtc,
  3859. struct drm_display_mode *mode,
  3860. struct drm_display_mode *adjusted_mode)
  3861. {
  3862. struct drm_device *dev = intel_crtc->base.dev;
  3863. struct drm_i915_private *dev_priv = dev->dev_private;
  3864. enum pipe pipe = intel_crtc->pipe;
  3865. enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
  3866. uint32_t vsyncshift;
  3867. if (!IS_GEN2(dev) && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
  3868. /* the chip adds 2 halflines automatically */
  3869. adjusted_mode->crtc_vtotal -= 1;
  3870. adjusted_mode->crtc_vblank_end -= 1;
  3871. vsyncshift = adjusted_mode->crtc_hsync_start
  3872. - adjusted_mode->crtc_htotal / 2;
  3873. } else {
  3874. vsyncshift = 0;
  3875. }
  3876. if (INTEL_INFO(dev)->gen > 3)
  3877. I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
  3878. I915_WRITE(HTOTAL(cpu_transcoder),
  3879. (adjusted_mode->crtc_hdisplay - 1) |
  3880. ((adjusted_mode->crtc_htotal - 1) << 16));
  3881. I915_WRITE(HBLANK(cpu_transcoder),
  3882. (adjusted_mode->crtc_hblank_start - 1) |
  3883. ((adjusted_mode->crtc_hblank_end - 1) << 16));
  3884. I915_WRITE(HSYNC(cpu_transcoder),
  3885. (adjusted_mode->crtc_hsync_start - 1) |
  3886. ((adjusted_mode->crtc_hsync_end - 1) << 16));
  3887. I915_WRITE(VTOTAL(cpu_transcoder),
  3888. (adjusted_mode->crtc_vdisplay - 1) |
  3889. ((adjusted_mode->crtc_vtotal - 1) << 16));
  3890. I915_WRITE(VBLANK(cpu_transcoder),
  3891. (adjusted_mode->crtc_vblank_start - 1) |
  3892. ((adjusted_mode->crtc_vblank_end - 1) << 16));
  3893. I915_WRITE(VSYNC(cpu_transcoder),
  3894. (adjusted_mode->crtc_vsync_start - 1) |
  3895. ((adjusted_mode->crtc_vsync_end - 1) << 16));
  3896. /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
  3897. * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
  3898. * documented on the DDI_FUNC_CTL register description, EDP Input Select
  3899. * bits. */
  3900. if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP &&
  3901. (pipe == PIPE_B || pipe == PIPE_C))
  3902. I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
  3903. /* pipesrc controls the size that is scaled from, which should
  3904. * always be the user's requested size.
  3905. */
  3906. I915_WRITE(PIPESRC(pipe),
  3907. ((mode->hdisplay - 1) << 16) | (mode->vdisplay - 1));
  3908. }
  3909. static int i9xx_crtc_mode_set(struct drm_crtc *crtc,
  3910. struct drm_display_mode *mode,
  3911. struct drm_display_mode *adjusted_mode,
  3912. int x, int y,
  3913. struct drm_framebuffer *fb)
  3914. {
  3915. struct drm_device *dev = crtc->dev;
  3916. struct drm_i915_private *dev_priv = dev->dev_private;
  3917. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3918. int pipe = intel_crtc->pipe;
  3919. int plane = intel_crtc->plane;
  3920. int refclk, num_connectors = 0;
  3921. intel_clock_t clock, reduced_clock;
  3922. u32 dspcntr, pipeconf;
  3923. bool ok, has_reduced_clock = false, is_sdvo = false;
  3924. bool is_lvds = false, is_tv = false, is_dp = false;
  3925. struct intel_encoder *encoder;
  3926. const intel_limit_t *limit;
  3927. int ret;
  3928. for_each_encoder_on_crtc(dev, crtc, encoder) {
  3929. switch (encoder->type) {
  3930. case INTEL_OUTPUT_LVDS:
  3931. is_lvds = true;
  3932. break;
  3933. case INTEL_OUTPUT_SDVO:
  3934. case INTEL_OUTPUT_HDMI:
  3935. is_sdvo = true;
  3936. if (encoder->needs_tv_clock)
  3937. is_tv = true;
  3938. break;
  3939. case INTEL_OUTPUT_TVOUT:
  3940. is_tv = true;
  3941. break;
  3942. case INTEL_OUTPUT_DISPLAYPORT:
  3943. is_dp = true;
  3944. break;
  3945. }
  3946. num_connectors++;
  3947. }
  3948. refclk = i9xx_get_refclk(crtc, num_connectors);
  3949. /*
  3950. * Returns a set of divisors for the desired target clock with the given
  3951. * refclk, or FALSE. The returned values represent the clock equation:
  3952. * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
  3953. */
  3954. limit = intel_limit(crtc, refclk);
  3955. ok = limit->find_pll(limit, crtc, adjusted_mode->clock, refclk, NULL,
  3956. &clock);
  3957. if (!ok) {
  3958. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  3959. return -EINVAL;
  3960. }
  3961. /* Ensure that the cursor is valid for the new mode before changing... */
  3962. intel_crtc_update_cursor(crtc, true);
  3963. if (is_lvds && dev_priv->lvds_downclock_avail) {
  3964. /*
  3965. * Ensure we match the reduced clock's P to the target clock.
  3966. * If the clocks don't match, we can't switch the display clock
  3967. * by using the FP0/FP1. In such case we will disable the LVDS
  3968. * downclock feature.
  3969. */
  3970. has_reduced_clock = limit->find_pll(limit, crtc,
  3971. dev_priv->lvds_downclock,
  3972. refclk,
  3973. &clock,
  3974. &reduced_clock);
  3975. }
  3976. if (is_sdvo && is_tv)
  3977. i9xx_adjust_sdvo_tv_clock(adjusted_mode, &clock);
  3978. if (IS_GEN2(dev))
  3979. i8xx_update_pll(crtc, adjusted_mode, &clock,
  3980. has_reduced_clock ? &reduced_clock : NULL,
  3981. num_connectors);
  3982. else if (IS_VALLEYVIEW(dev))
  3983. vlv_update_pll(crtc, mode, adjusted_mode, &clock,
  3984. has_reduced_clock ? &reduced_clock : NULL,
  3985. num_connectors);
  3986. else
  3987. i9xx_update_pll(crtc, mode, adjusted_mode, &clock,
  3988. has_reduced_clock ? &reduced_clock : NULL,
  3989. num_connectors);
  3990. /* setup pipeconf */
  3991. pipeconf = I915_READ(PIPECONF(pipe));
  3992. /* Set up the display plane register */
  3993. dspcntr = DISPPLANE_GAMMA_ENABLE;
  3994. if (pipe == 0)
  3995. dspcntr &= ~DISPPLANE_SEL_PIPE_MASK;
  3996. else
  3997. dspcntr |= DISPPLANE_SEL_PIPE_B;
  3998. if (pipe == 0 && INTEL_INFO(dev)->gen < 4) {
  3999. /* Enable pixel doubling when the dot clock is > 90% of the (display)
  4000. * core speed.
  4001. *
  4002. * XXX: No double-wide on 915GM pipe B. Is that the only reason for the
  4003. * pipe == 0 check?
  4004. */
  4005. if (mode->clock >
  4006. dev_priv->display.get_display_clock_speed(dev) * 9 / 10)
  4007. pipeconf |= PIPECONF_DOUBLE_WIDE;
  4008. else
  4009. pipeconf &= ~PIPECONF_DOUBLE_WIDE;
  4010. }
  4011. /* default to 8bpc */
  4012. pipeconf &= ~(PIPECONF_BPC_MASK | PIPECONF_DITHER_EN);
  4013. if (is_dp) {
  4014. if (adjusted_mode->private_flags & INTEL_MODE_DP_FORCE_6BPC) {
  4015. pipeconf |= PIPECONF_6BPC |
  4016. PIPECONF_DITHER_EN |
  4017. PIPECONF_DITHER_TYPE_SP;
  4018. }
  4019. }
  4020. if (IS_VALLEYVIEW(dev) && intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) {
  4021. if (adjusted_mode->private_flags & INTEL_MODE_DP_FORCE_6BPC) {
  4022. pipeconf |= PIPECONF_6BPC |
  4023. PIPECONF_ENABLE |
  4024. I965_PIPECONF_ACTIVE;
  4025. }
  4026. }
  4027. DRM_DEBUG_KMS("Mode for pipe %c:\n", pipe == 0 ? 'A' : 'B');
  4028. drm_mode_debug_printmodeline(mode);
  4029. if (HAS_PIPE_CXSR(dev)) {
  4030. if (intel_crtc->lowfreq_avail) {
  4031. DRM_DEBUG_KMS("enabling CxSR downclocking\n");
  4032. pipeconf |= PIPECONF_CXSR_DOWNCLOCK;
  4033. } else {
  4034. DRM_DEBUG_KMS("disabling CxSR downclocking\n");
  4035. pipeconf &= ~PIPECONF_CXSR_DOWNCLOCK;
  4036. }
  4037. }
  4038. pipeconf &= ~PIPECONF_INTERLACE_MASK;
  4039. if (!IS_GEN2(dev) &&
  4040. adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
  4041. pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
  4042. else
  4043. pipeconf |= PIPECONF_PROGRESSIVE;
  4044. intel_set_pipe_timings(intel_crtc, mode, adjusted_mode);
  4045. /* pipesrc and dspsize control the size that is scaled from,
  4046. * which should always be the user's requested size.
  4047. */
  4048. I915_WRITE(DSPSIZE(plane),
  4049. ((mode->vdisplay - 1) << 16) |
  4050. (mode->hdisplay - 1));
  4051. I915_WRITE(DSPPOS(plane), 0);
  4052. I915_WRITE(PIPECONF(pipe), pipeconf);
  4053. POSTING_READ(PIPECONF(pipe));
  4054. intel_enable_pipe(dev_priv, pipe, false);
  4055. intel_wait_for_vblank(dev, pipe);
  4056. I915_WRITE(DSPCNTR(plane), dspcntr);
  4057. POSTING_READ(DSPCNTR(plane));
  4058. ret = intel_pipe_set_base(crtc, x, y, fb);
  4059. intel_update_watermarks(dev);
  4060. return ret;
  4061. }
  4062. static void ironlake_init_pch_refclk(struct drm_device *dev)
  4063. {
  4064. struct drm_i915_private *dev_priv = dev->dev_private;
  4065. struct drm_mode_config *mode_config = &dev->mode_config;
  4066. struct intel_encoder *encoder;
  4067. u32 temp;
  4068. bool has_lvds = false;
  4069. bool has_cpu_edp = false;
  4070. bool has_pch_edp = false;
  4071. bool has_panel = false;
  4072. bool has_ck505 = false;
  4073. bool can_ssc = false;
  4074. /* We need to take the global config into account */
  4075. list_for_each_entry(encoder, &mode_config->encoder_list,
  4076. base.head) {
  4077. switch (encoder->type) {
  4078. case INTEL_OUTPUT_LVDS:
  4079. has_panel = true;
  4080. has_lvds = true;
  4081. break;
  4082. case INTEL_OUTPUT_EDP:
  4083. has_panel = true;
  4084. if (intel_encoder_is_pch_edp(&encoder->base))
  4085. has_pch_edp = true;
  4086. else
  4087. has_cpu_edp = true;
  4088. break;
  4089. }
  4090. }
  4091. if (HAS_PCH_IBX(dev)) {
  4092. has_ck505 = dev_priv->display_clock_mode;
  4093. can_ssc = has_ck505;
  4094. } else {
  4095. has_ck505 = false;
  4096. can_ssc = true;
  4097. }
  4098. DRM_DEBUG_KMS("has_panel %d has_lvds %d has_pch_edp %d has_cpu_edp %d has_ck505 %d\n",
  4099. has_panel, has_lvds, has_pch_edp, has_cpu_edp,
  4100. has_ck505);
  4101. /* Ironlake: try to setup display ref clock before DPLL
  4102. * enabling. This is only under driver's control after
  4103. * PCH B stepping, previous chipset stepping should be
  4104. * ignoring this setting.
  4105. */
  4106. temp = I915_READ(PCH_DREF_CONTROL);
  4107. /* Always enable nonspread source */
  4108. temp &= ~DREF_NONSPREAD_SOURCE_MASK;
  4109. if (has_ck505)
  4110. temp |= DREF_NONSPREAD_CK505_ENABLE;
  4111. else
  4112. temp |= DREF_NONSPREAD_SOURCE_ENABLE;
  4113. if (has_panel) {
  4114. temp &= ~DREF_SSC_SOURCE_MASK;
  4115. temp |= DREF_SSC_SOURCE_ENABLE;
  4116. /* SSC must be turned on before enabling the CPU output */
  4117. if (intel_panel_use_ssc(dev_priv) && can_ssc) {
  4118. DRM_DEBUG_KMS("Using SSC on panel\n");
  4119. temp |= DREF_SSC1_ENABLE;
  4120. } else
  4121. temp &= ~DREF_SSC1_ENABLE;
  4122. /* Get SSC going before enabling the outputs */
  4123. I915_WRITE(PCH_DREF_CONTROL, temp);
  4124. POSTING_READ(PCH_DREF_CONTROL);
  4125. udelay(200);
  4126. temp &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  4127. /* Enable CPU source on CPU attached eDP */
  4128. if (has_cpu_edp) {
  4129. if (intel_panel_use_ssc(dev_priv) && can_ssc) {
  4130. DRM_DEBUG_KMS("Using SSC on eDP\n");
  4131. temp |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
  4132. }
  4133. else
  4134. temp |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
  4135. } else
  4136. temp |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  4137. I915_WRITE(PCH_DREF_CONTROL, temp);
  4138. POSTING_READ(PCH_DREF_CONTROL);
  4139. udelay(200);
  4140. } else {
  4141. DRM_DEBUG_KMS("Disabling SSC entirely\n");
  4142. temp &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  4143. /* Turn off CPU output */
  4144. temp |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  4145. I915_WRITE(PCH_DREF_CONTROL, temp);
  4146. POSTING_READ(PCH_DREF_CONTROL);
  4147. udelay(200);
  4148. /* Turn off the SSC source */
  4149. temp &= ~DREF_SSC_SOURCE_MASK;
  4150. temp |= DREF_SSC_SOURCE_DISABLE;
  4151. /* Turn off SSC1 */
  4152. temp &= ~ DREF_SSC1_ENABLE;
  4153. I915_WRITE(PCH_DREF_CONTROL, temp);
  4154. POSTING_READ(PCH_DREF_CONTROL);
  4155. udelay(200);
  4156. }
  4157. }
  4158. /* Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O. */
  4159. static void lpt_init_pch_refclk(struct drm_device *dev)
  4160. {
  4161. struct drm_i915_private *dev_priv = dev->dev_private;
  4162. struct drm_mode_config *mode_config = &dev->mode_config;
  4163. struct intel_encoder *encoder;
  4164. bool has_vga = false;
  4165. bool is_sdv = false;
  4166. u32 tmp;
  4167. list_for_each_entry(encoder, &mode_config->encoder_list, base.head) {
  4168. switch (encoder->type) {
  4169. case INTEL_OUTPUT_ANALOG:
  4170. has_vga = true;
  4171. break;
  4172. }
  4173. }
  4174. if (!has_vga)
  4175. return;
  4176. mutex_lock(&dev_priv->dpio_lock);
  4177. /* XXX: Rip out SDV support once Haswell ships for real. */
  4178. if (IS_HASWELL(dev) && (dev->pci_device & 0xFF00) == 0x0C00)
  4179. is_sdv = true;
  4180. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  4181. tmp &= ~SBI_SSCCTL_DISABLE;
  4182. tmp |= SBI_SSCCTL_PATHALT;
  4183. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  4184. udelay(24);
  4185. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  4186. tmp &= ~SBI_SSCCTL_PATHALT;
  4187. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  4188. if (!is_sdv) {
  4189. tmp = I915_READ(SOUTH_CHICKEN2);
  4190. tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
  4191. I915_WRITE(SOUTH_CHICKEN2, tmp);
  4192. if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) &
  4193. FDI_MPHY_IOSFSB_RESET_STATUS, 100))
  4194. DRM_ERROR("FDI mPHY reset assert timeout\n");
  4195. tmp = I915_READ(SOUTH_CHICKEN2);
  4196. tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
  4197. I915_WRITE(SOUTH_CHICKEN2, tmp);
  4198. if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) &
  4199. FDI_MPHY_IOSFSB_RESET_STATUS) == 0,
  4200. 100))
  4201. DRM_ERROR("FDI mPHY reset de-assert timeout\n");
  4202. }
  4203. tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
  4204. tmp &= ~(0xFF << 24);
  4205. tmp |= (0x12 << 24);
  4206. intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
  4207. if (!is_sdv) {
  4208. tmp = intel_sbi_read(dev_priv, 0x808C, SBI_MPHY);
  4209. tmp &= ~(0x3 << 6);
  4210. tmp |= (1 << 6) | (1 << 0);
  4211. intel_sbi_write(dev_priv, 0x808C, tmp, SBI_MPHY);
  4212. }
  4213. if (is_sdv) {
  4214. tmp = intel_sbi_read(dev_priv, 0x800C, SBI_MPHY);
  4215. tmp |= 0x7FFF;
  4216. intel_sbi_write(dev_priv, 0x800C, tmp, SBI_MPHY);
  4217. }
  4218. tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
  4219. tmp |= (1 << 11);
  4220. intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
  4221. tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
  4222. tmp |= (1 << 11);
  4223. intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
  4224. if (is_sdv) {
  4225. tmp = intel_sbi_read(dev_priv, 0x2038, SBI_MPHY);
  4226. tmp |= (0x3F << 24) | (0xF << 20) | (0xF << 16);
  4227. intel_sbi_write(dev_priv, 0x2038, tmp, SBI_MPHY);
  4228. tmp = intel_sbi_read(dev_priv, 0x2138, SBI_MPHY);
  4229. tmp |= (0x3F << 24) | (0xF << 20) | (0xF << 16);
  4230. intel_sbi_write(dev_priv, 0x2138, tmp, SBI_MPHY);
  4231. tmp = intel_sbi_read(dev_priv, 0x203C, SBI_MPHY);
  4232. tmp |= (0x3F << 8);
  4233. intel_sbi_write(dev_priv, 0x203C, tmp, SBI_MPHY);
  4234. tmp = intel_sbi_read(dev_priv, 0x213C, SBI_MPHY);
  4235. tmp |= (0x3F << 8);
  4236. intel_sbi_write(dev_priv, 0x213C, tmp, SBI_MPHY);
  4237. }
  4238. tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
  4239. tmp |= (1 << 24) | (1 << 21) | (1 << 18);
  4240. intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
  4241. tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
  4242. tmp |= (1 << 24) | (1 << 21) | (1 << 18);
  4243. intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
  4244. if (!is_sdv) {
  4245. tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
  4246. tmp &= ~(7 << 13);
  4247. tmp |= (5 << 13);
  4248. intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
  4249. tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
  4250. tmp &= ~(7 << 13);
  4251. tmp |= (5 << 13);
  4252. intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
  4253. }
  4254. tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
  4255. tmp &= ~0xFF;
  4256. tmp |= 0x1C;
  4257. intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
  4258. tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
  4259. tmp &= ~0xFF;
  4260. tmp |= 0x1C;
  4261. intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
  4262. tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
  4263. tmp &= ~(0xFF << 16);
  4264. tmp |= (0x1C << 16);
  4265. intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
  4266. tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
  4267. tmp &= ~(0xFF << 16);
  4268. tmp |= (0x1C << 16);
  4269. intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
  4270. if (!is_sdv) {
  4271. tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
  4272. tmp |= (1 << 27);
  4273. intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
  4274. tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
  4275. tmp |= (1 << 27);
  4276. intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
  4277. tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
  4278. tmp &= ~(0xF << 28);
  4279. tmp |= (4 << 28);
  4280. intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
  4281. tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
  4282. tmp &= ~(0xF << 28);
  4283. tmp |= (4 << 28);
  4284. intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
  4285. }
  4286. /* ULT uses SBI_GEN0, but ULT doesn't have VGA, so we don't care. */
  4287. tmp = intel_sbi_read(dev_priv, SBI_DBUFF0, SBI_ICLK);
  4288. tmp |= SBI_DBUFF0_ENABLE;
  4289. intel_sbi_write(dev_priv, SBI_DBUFF0, tmp, SBI_ICLK);
  4290. mutex_unlock(&dev_priv->dpio_lock);
  4291. }
  4292. /*
  4293. * Initialize reference clocks when the driver loads
  4294. */
  4295. void intel_init_pch_refclk(struct drm_device *dev)
  4296. {
  4297. if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
  4298. ironlake_init_pch_refclk(dev);
  4299. else if (HAS_PCH_LPT(dev))
  4300. lpt_init_pch_refclk(dev);
  4301. }
  4302. static int ironlake_get_refclk(struct drm_crtc *crtc)
  4303. {
  4304. struct drm_device *dev = crtc->dev;
  4305. struct drm_i915_private *dev_priv = dev->dev_private;
  4306. struct intel_encoder *encoder;
  4307. struct intel_encoder *edp_encoder = NULL;
  4308. int num_connectors = 0;
  4309. bool is_lvds = false;
  4310. for_each_encoder_on_crtc(dev, crtc, encoder) {
  4311. switch (encoder->type) {
  4312. case INTEL_OUTPUT_LVDS:
  4313. is_lvds = true;
  4314. break;
  4315. case INTEL_OUTPUT_EDP:
  4316. edp_encoder = encoder;
  4317. break;
  4318. }
  4319. num_connectors++;
  4320. }
  4321. if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
  4322. DRM_DEBUG_KMS("using SSC reference clock of %d MHz\n",
  4323. dev_priv->lvds_ssc_freq);
  4324. return dev_priv->lvds_ssc_freq * 1000;
  4325. }
  4326. return 120000;
  4327. }
  4328. static void ironlake_set_pipeconf(struct drm_crtc *crtc,
  4329. struct drm_display_mode *adjusted_mode,
  4330. bool dither)
  4331. {
  4332. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  4333. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4334. int pipe = intel_crtc->pipe;
  4335. uint32_t val;
  4336. val = I915_READ(PIPECONF(pipe));
  4337. val &= ~PIPECONF_BPC_MASK;
  4338. switch (intel_crtc->bpp) {
  4339. case 18:
  4340. val |= PIPECONF_6BPC;
  4341. break;
  4342. case 24:
  4343. val |= PIPECONF_8BPC;
  4344. break;
  4345. case 30:
  4346. val |= PIPECONF_10BPC;
  4347. break;
  4348. case 36:
  4349. val |= PIPECONF_12BPC;
  4350. break;
  4351. default:
  4352. /* Case prevented by intel_choose_pipe_bpp_dither. */
  4353. BUG();
  4354. }
  4355. val &= ~(PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_MASK);
  4356. if (dither)
  4357. val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
  4358. val &= ~PIPECONF_INTERLACE_MASK;
  4359. if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
  4360. val |= PIPECONF_INTERLACED_ILK;
  4361. else
  4362. val |= PIPECONF_PROGRESSIVE;
  4363. if (adjusted_mode->private_flags & INTEL_MODE_LIMITED_COLOR_RANGE)
  4364. val |= PIPECONF_COLOR_RANGE_SELECT;
  4365. else
  4366. val &= ~PIPECONF_COLOR_RANGE_SELECT;
  4367. I915_WRITE(PIPECONF(pipe), val);
  4368. POSTING_READ(PIPECONF(pipe));
  4369. }
  4370. static void haswell_set_pipeconf(struct drm_crtc *crtc,
  4371. struct drm_display_mode *adjusted_mode,
  4372. bool dither)
  4373. {
  4374. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  4375. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4376. enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
  4377. uint32_t val;
  4378. val = I915_READ(PIPECONF(cpu_transcoder));
  4379. val &= ~(PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_MASK);
  4380. if (dither)
  4381. val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
  4382. val &= ~PIPECONF_INTERLACE_MASK_HSW;
  4383. if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
  4384. val |= PIPECONF_INTERLACED_ILK;
  4385. else
  4386. val |= PIPECONF_PROGRESSIVE;
  4387. I915_WRITE(PIPECONF(cpu_transcoder), val);
  4388. POSTING_READ(PIPECONF(cpu_transcoder));
  4389. }
  4390. static bool ironlake_compute_clocks(struct drm_crtc *crtc,
  4391. struct drm_display_mode *adjusted_mode,
  4392. intel_clock_t *clock,
  4393. bool *has_reduced_clock,
  4394. intel_clock_t *reduced_clock)
  4395. {
  4396. struct drm_device *dev = crtc->dev;
  4397. struct drm_i915_private *dev_priv = dev->dev_private;
  4398. struct intel_encoder *intel_encoder;
  4399. int refclk;
  4400. const intel_limit_t *limit;
  4401. bool ret, is_sdvo = false, is_tv = false, is_lvds = false;
  4402. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  4403. switch (intel_encoder->type) {
  4404. case INTEL_OUTPUT_LVDS:
  4405. is_lvds = true;
  4406. break;
  4407. case INTEL_OUTPUT_SDVO:
  4408. case INTEL_OUTPUT_HDMI:
  4409. is_sdvo = true;
  4410. if (intel_encoder->needs_tv_clock)
  4411. is_tv = true;
  4412. break;
  4413. case INTEL_OUTPUT_TVOUT:
  4414. is_tv = true;
  4415. break;
  4416. }
  4417. }
  4418. refclk = ironlake_get_refclk(crtc);
  4419. /*
  4420. * Returns a set of divisors for the desired target clock with the given
  4421. * refclk, or FALSE. The returned values represent the clock equation:
  4422. * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
  4423. */
  4424. limit = intel_limit(crtc, refclk);
  4425. ret = limit->find_pll(limit, crtc, adjusted_mode->clock, refclk, NULL,
  4426. clock);
  4427. if (!ret)
  4428. return false;
  4429. if (is_lvds && dev_priv->lvds_downclock_avail) {
  4430. /*
  4431. * Ensure we match the reduced clock's P to the target clock.
  4432. * If the clocks don't match, we can't switch the display clock
  4433. * by using the FP0/FP1. In such case we will disable the LVDS
  4434. * downclock feature.
  4435. */
  4436. *has_reduced_clock = limit->find_pll(limit, crtc,
  4437. dev_priv->lvds_downclock,
  4438. refclk,
  4439. clock,
  4440. reduced_clock);
  4441. }
  4442. if (is_sdvo && is_tv)
  4443. i9xx_adjust_sdvo_tv_clock(adjusted_mode, clock);
  4444. return true;
  4445. }
  4446. static void cpt_enable_fdi_bc_bifurcation(struct drm_device *dev)
  4447. {
  4448. struct drm_i915_private *dev_priv = dev->dev_private;
  4449. uint32_t temp;
  4450. temp = I915_READ(SOUTH_CHICKEN1);
  4451. if (temp & FDI_BC_BIFURCATION_SELECT)
  4452. return;
  4453. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
  4454. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
  4455. temp |= FDI_BC_BIFURCATION_SELECT;
  4456. DRM_DEBUG_KMS("enabling fdi C rx\n");
  4457. I915_WRITE(SOUTH_CHICKEN1, temp);
  4458. POSTING_READ(SOUTH_CHICKEN1);
  4459. }
  4460. static bool ironlake_check_fdi_lanes(struct intel_crtc *intel_crtc)
  4461. {
  4462. struct drm_device *dev = intel_crtc->base.dev;
  4463. struct drm_i915_private *dev_priv = dev->dev_private;
  4464. struct intel_crtc *pipe_B_crtc =
  4465. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]);
  4466. DRM_DEBUG_KMS("checking fdi config on pipe %i, lanes %i\n",
  4467. intel_crtc->pipe, intel_crtc->fdi_lanes);
  4468. if (intel_crtc->fdi_lanes > 4) {
  4469. DRM_DEBUG_KMS("invalid fdi lane config on pipe %i: %i lanes\n",
  4470. intel_crtc->pipe, intel_crtc->fdi_lanes);
  4471. /* Clamp lanes to avoid programming the hw with bogus values. */
  4472. intel_crtc->fdi_lanes = 4;
  4473. return false;
  4474. }
  4475. if (dev_priv->num_pipe == 2)
  4476. return true;
  4477. switch (intel_crtc->pipe) {
  4478. case PIPE_A:
  4479. return true;
  4480. case PIPE_B:
  4481. if (dev_priv->pipe_to_crtc_mapping[PIPE_C]->enabled &&
  4482. intel_crtc->fdi_lanes > 2) {
  4483. DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %i: %i lanes\n",
  4484. intel_crtc->pipe, intel_crtc->fdi_lanes);
  4485. /* Clamp lanes to avoid programming the hw with bogus values. */
  4486. intel_crtc->fdi_lanes = 2;
  4487. return false;
  4488. }
  4489. if (intel_crtc->fdi_lanes > 2)
  4490. WARN_ON(I915_READ(SOUTH_CHICKEN1) & FDI_BC_BIFURCATION_SELECT);
  4491. else
  4492. cpt_enable_fdi_bc_bifurcation(dev);
  4493. return true;
  4494. case PIPE_C:
  4495. if (!pipe_B_crtc->base.enabled || pipe_B_crtc->fdi_lanes <= 2) {
  4496. if (intel_crtc->fdi_lanes > 2) {
  4497. DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %i: %i lanes\n",
  4498. intel_crtc->pipe, intel_crtc->fdi_lanes);
  4499. /* Clamp lanes to avoid programming the hw with bogus values. */
  4500. intel_crtc->fdi_lanes = 2;
  4501. return false;
  4502. }
  4503. } else {
  4504. DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
  4505. return false;
  4506. }
  4507. cpt_enable_fdi_bc_bifurcation(dev);
  4508. return true;
  4509. default:
  4510. BUG();
  4511. }
  4512. }
  4513. int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
  4514. {
  4515. /*
  4516. * Account for spread spectrum to avoid
  4517. * oversubscribing the link. Max center spread
  4518. * is 2.5%; use 5% for safety's sake.
  4519. */
  4520. u32 bps = target_clock * bpp * 21 / 20;
  4521. return bps / (link_bw * 8) + 1;
  4522. }
  4523. static void ironlake_set_m_n(struct drm_crtc *crtc,
  4524. struct drm_display_mode *mode,
  4525. struct drm_display_mode *adjusted_mode)
  4526. {
  4527. struct drm_device *dev = crtc->dev;
  4528. struct drm_i915_private *dev_priv = dev->dev_private;
  4529. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4530. enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
  4531. struct intel_encoder *intel_encoder, *edp_encoder = NULL;
  4532. struct intel_link_m_n m_n = {0};
  4533. int target_clock, pixel_multiplier, lane, link_bw;
  4534. bool is_dp = false, is_cpu_edp = false;
  4535. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  4536. switch (intel_encoder->type) {
  4537. case INTEL_OUTPUT_DISPLAYPORT:
  4538. is_dp = true;
  4539. break;
  4540. case INTEL_OUTPUT_EDP:
  4541. is_dp = true;
  4542. if (!intel_encoder_is_pch_edp(&intel_encoder->base))
  4543. is_cpu_edp = true;
  4544. edp_encoder = intel_encoder;
  4545. break;
  4546. }
  4547. }
  4548. /* FDI link */
  4549. pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
  4550. lane = 0;
  4551. /* CPU eDP doesn't require FDI link, so just set DP M/N
  4552. according to current link config */
  4553. if (is_cpu_edp) {
  4554. intel_edp_link_config(edp_encoder, &lane, &link_bw);
  4555. } else {
  4556. /* FDI is a binary signal running at ~2.7GHz, encoding
  4557. * each output octet as 10 bits. The actual frequency
  4558. * is stored as a divider into a 100MHz clock, and the
  4559. * mode pixel clock is stored in units of 1KHz.
  4560. * Hence the bw of each lane in terms of the mode signal
  4561. * is:
  4562. */
  4563. link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10;
  4564. }
  4565. /* [e]DP over FDI requires target mode clock instead of link clock. */
  4566. if (edp_encoder)
  4567. target_clock = intel_edp_target_clock(edp_encoder, mode);
  4568. else if (is_dp)
  4569. target_clock = mode->clock;
  4570. else
  4571. target_clock = adjusted_mode->clock;
  4572. if (!lane)
  4573. lane = ironlake_get_lanes_required(target_clock, link_bw,
  4574. intel_crtc->bpp);
  4575. intel_crtc->fdi_lanes = lane;
  4576. if (pixel_multiplier > 1)
  4577. link_bw *= pixel_multiplier;
  4578. intel_link_compute_m_n(intel_crtc->bpp, lane, target_clock, link_bw, &m_n);
  4579. I915_WRITE(PIPE_DATA_M1(cpu_transcoder), TU_SIZE(m_n.tu) | m_n.gmch_m);
  4580. I915_WRITE(PIPE_DATA_N1(cpu_transcoder), m_n.gmch_n);
  4581. I915_WRITE(PIPE_LINK_M1(cpu_transcoder), m_n.link_m);
  4582. I915_WRITE(PIPE_LINK_N1(cpu_transcoder), m_n.link_n);
  4583. }
  4584. static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc,
  4585. struct drm_display_mode *adjusted_mode,
  4586. intel_clock_t *clock, u32 fp)
  4587. {
  4588. struct drm_crtc *crtc = &intel_crtc->base;
  4589. struct drm_device *dev = crtc->dev;
  4590. struct drm_i915_private *dev_priv = dev->dev_private;
  4591. struct intel_encoder *intel_encoder;
  4592. uint32_t dpll;
  4593. int factor, pixel_multiplier, num_connectors = 0;
  4594. bool is_lvds = false, is_sdvo = false, is_tv = false;
  4595. bool is_dp = false, is_cpu_edp = false;
  4596. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  4597. switch (intel_encoder->type) {
  4598. case INTEL_OUTPUT_LVDS:
  4599. is_lvds = true;
  4600. break;
  4601. case INTEL_OUTPUT_SDVO:
  4602. case INTEL_OUTPUT_HDMI:
  4603. is_sdvo = true;
  4604. if (intel_encoder->needs_tv_clock)
  4605. is_tv = true;
  4606. break;
  4607. case INTEL_OUTPUT_TVOUT:
  4608. is_tv = true;
  4609. break;
  4610. case INTEL_OUTPUT_DISPLAYPORT:
  4611. is_dp = true;
  4612. break;
  4613. case INTEL_OUTPUT_EDP:
  4614. is_dp = true;
  4615. if (!intel_encoder_is_pch_edp(&intel_encoder->base))
  4616. is_cpu_edp = true;
  4617. break;
  4618. }
  4619. num_connectors++;
  4620. }
  4621. /* Enable autotuning of the PLL clock (if permissible) */
  4622. factor = 21;
  4623. if (is_lvds) {
  4624. if ((intel_panel_use_ssc(dev_priv) &&
  4625. dev_priv->lvds_ssc_freq == 100) ||
  4626. intel_is_dual_link_lvds(dev))
  4627. factor = 25;
  4628. } else if (is_sdvo && is_tv)
  4629. factor = 20;
  4630. if (clock->m < factor * clock->n)
  4631. fp |= FP_CB_TUNE;
  4632. dpll = 0;
  4633. if (is_lvds)
  4634. dpll |= DPLLB_MODE_LVDS;
  4635. else
  4636. dpll |= DPLLB_MODE_DAC_SERIAL;
  4637. if (is_sdvo) {
  4638. pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
  4639. if (pixel_multiplier > 1) {
  4640. dpll |= (pixel_multiplier - 1) << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
  4641. }
  4642. dpll |= DPLL_DVO_HIGH_SPEED;
  4643. }
  4644. if (is_dp && !is_cpu_edp)
  4645. dpll |= DPLL_DVO_HIGH_SPEED;
  4646. /* compute bitmask from p1 value */
  4647. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  4648. /* also FPA1 */
  4649. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  4650. switch (clock->p2) {
  4651. case 5:
  4652. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  4653. break;
  4654. case 7:
  4655. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  4656. break;
  4657. case 10:
  4658. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  4659. break;
  4660. case 14:
  4661. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  4662. break;
  4663. }
  4664. if (is_sdvo && is_tv)
  4665. dpll |= PLL_REF_INPUT_TVCLKINBC;
  4666. else if (is_tv)
  4667. /* XXX: just matching BIOS for now */
  4668. /* dpll |= PLL_REF_INPUT_TVCLKINBC; */
  4669. dpll |= 3;
  4670. else if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  4671. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  4672. else
  4673. dpll |= PLL_REF_INPUT_DREFCLK;
  4674. return dpll;
  4675. }
  4676. static int ironlake_crtc_mode_set(struct drm_crtc *crtc,
  4677. struct drm_display_mode *mode,
  4678. struct drm_display_mode *adjusted_mode,
  4679. int x, int y,
  4680. struct drm_framebuffer *fb)
  4681. {
  4682. struct drm_device *dev = crtc->dev;
  4683. struct drm_i915_private *dev_priv = dev->dev_private;
  4684. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4685. int pipe = intel_crtc->pipe;
  4686. int plane = intel_crtc->plane;
  4687. int num_connectors = 0;
  4688. intel_clock_t clock, reduced_clock;
  4689. u32 dpll, fp = 0, fp2 = 0;
  4690. bool ok, has_reduced_clock = false;
  4691. bool is_lvds = false, is_dp = false, is_cpu_edp = false;
  4692. struct intel_encoder *encoder;
  4693. int ret;
  4694. bool dither, fdi_config_ok;
  4695. for_each_encoder_on_crtc(dev, crtc, encoder) {
  4696. switch (encoder->type) {
  4697. case INTEL_OUTPUT_LVDS:
  4698. is_lvds = true;
  4699. break;
  4700. case INTEL_OUTPUT_DISPLAYPORT:
  4701. is_dp = true;
  4702. break;
  4703. case INTEL_OUTPUT_EDP:
  4704. is_dp = true;
  4705. if (!intel_encoder_is_pch_edp(&encoder->base))
  4706. is_cpu_edp = true;
  4707. break;
  4708. }
  4709. num_connectors++;
  4710. }
  4711. WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)),
  4712. "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev));
  4713. ok = ironlake_compute_clocks(crtc, adjusted_mode, &clock,
  4714. &has_reduced_clock, &reduced_clock);
  4715. if (!ok) {
  4716. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  4717. return -EINVAL;
  4718. }
  4719. /* Ensure that the cursor is valid for the new mode before changing... */
  4720. intel_crtc_update_cursor(crtc, true);
  4721. /* determine panel color depth */
  4722. dither = intel_choose_pipe_bpp_dither(crtc, fb, &intel_crtc->bpp,
  4723. adjusted_mode);
  4724. if (is_lvds && dev_priv->lvds_dither)
  4725. dither = true;
  4726. fp = clock.n << 16 | clock.m1 << 8 | clock.m2;
  4727. if (has_reduced_clock)
  4728. fp2 = reduced_clock.n << 16 | reduced_clock.m1 << 8 |
  4729. reduced_clock.m2;
  4730. dpll = ironlake_compute_dpll(intel_crtc, adjusted_mode, &clock, fp);
  4731. DRM_DEBUG_KMS("Mode for pipe %d:\n", pipe);
  4732. drm_mode_debug_printmodeline(mode);
  4733. /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
  4734. if (!is_cpu_edp) {
  4735. struct intel_pch_pll *pll;
  4736. pll = intel_get_pch_pll(intel_crtc, dpll, fp);
  4737. if (pll == NULL) {
  4738. DRM_DEBUG_DRIVER("failed to find PLL for pipe %d\n",
  4739. pipe);
  4740. return -EINVAL;
  4741. }
  4742. } else
  4743. intel_put_pch_pll(intel_crtc);
  4744. if (is_dp && !is_cpu_edp)
  4745. intel_dp_set_m_n(crtc, mode, adjusted_mode);
  4746. for_each_encoder_on_crtc(dev, crtc, encoder)
  4747. if (encoder->pre_pll_enable)
  4748. encoder->pre_pll_enable(encoder);
  4749. if (intel_crtc->pch_pll) {
  4750. I915_WRITE(intel_crtc->pch_pll->pll_reg, dpll);
  4751. /* Wait for the clocks to stabilize. */
  4752. POSTING_READ(intel_crtc->pch_pll->pll_reg);
  4753. udelay(150);
  4754. /* The pixel multiplier can only be updated once the
  4755. * DPLL is enabled and the clocks are stable.
  4756. *
  4757. * So write it again.
  4758. */
  4759. I915_WRITE(intel_crtc->pch_pll->pll_reg, dpll);
  4760. }
  4761. intel_crtc->lowfreq_avail = false;
  4762. if (intel_crtc->pch_pll) {
  4763. if (is_lvds && has_reduced_clock && i915_powersave) {
  4764. I915_WRITE(intel_crtc->pch_pll->fp1_reg, fp2);
  4765. intel_crtc->lowfreq_avail = true;
  4766. } else {
  4767. I915_WRITE(intel_crtc->pch_pll->fp1_reg, fp);
  4768. }
  4769. }
  4770. intel_set_pipe_timings(intel_crtc, mode, adjusted_mode);
  4771. /* Note, this also computes intel_crtc->fdi_lanes which is used below in
  4772. * ironlake_check_fdi_lanes. */
  4773. ironlake_set_m_n(crtc, mode, adjusted_mode);
  4774. fdi_config_ok = ironlake_check_fdi_lanes(intel_crtc);
  4775. ironlake_set_pipeconf(crtc, adjusted_mode, dither);
  4776. intel_wait_for_vblank(dev, pipe);
  4777. /* Set up the display plane register */
  4778. I915_WRITE(DSPCNTR(plane), DISPPLANE_GAMMA_ENABLE);
  4779. POSTING_READ(DSPCNTR(plane));
  4780. ret = intel_pipe_set_base(crtc, x, y, fb);
  4781. intel_update_watermarks(dev);
  4782. intel_update_linetime_watermarks(dev, pipe, adjusted_mode);
  4783. return fdi_config_ok ? ret : -EINVAL;
  4784. }
  4785. static void haswell_modeset_global_resources(struct drm_device *dev)
  4786. {
  4787. struct drm_i915_private *dev_priv = dev->dev_private;
  4788. bool enable = false;
  4789. struct intel_crtc *crtc;
  4790. struct intel_encoder *encoder;
  4791. list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head) {
  4792. if (crtc->pipe != PIPE_A && crtc->base.enabled)
  4793. enable = true;
  4794. /* XXX: Should check for edp transcoder here, but thanks to init
  4795. * sequence that's not yet available. Just in case desktop eDP
  4796. * on PORT D is possible on haswell, too. */
  4797. }
  4798. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  4799. base.head) {
  4800. if (encoder->type != INTEL_OUTPUT_EDP &&
  4801. encoder->connectors_active)
  4802. enable = true;
  4803. }
  4804. /* Even the eDP panel fitter is outside the always-on well. */
  4805. if (dev_priv->pch_pf_size)
  4806. enable = true;
  4807. intel_set_power_well(dev, enable);
  4808. }
  4809. static int haswell_crtc_mode_set(struct drm_crtc *crtc,
  4810. struct drm_display_mode *mode,
  4811. struct drm_display_mode *adjusted_mode,
  4812. int x, int y,
  4813. struct drm_framebuffer *fb)
  4814. {
  4815. struct drm_device *dev = crtc->dev;
  4816. struct drm_i915_private *dev_priv = dev->dev_private;
  4817. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4818. int pipe = intel_crtc->pipe;
  4819. int plane = intel_crtc->plane;
  4820. int num_connectors = 0;
  4821. bool is_dp = false, is_cpu_edp = false;
  4822. struct intel_encoder *encoder;
  4823. int ret;
  4824. bool dither;
  4825. for_each_encoder_on_crtc(dev, crtc, encoder) {
  4826. switch (encoder->type) {
  4827. case INTEL_OUTPUT_DISPLAYPORT:
  4828. is_dp = true;
  4829. break;
  4830. case INTEL_OUTPUT_EDP:
  4831. is_dp = true;
  4832. if (!intel_encoder_is_pch_edp(&encoder->base))
  4833. is_cpu_edp = true;
  4834. break;
  4835. }
  4836. num_connectors++;
  4837. }
  4838. /* We are not sure yet this won't happen. */
  4839. WARN(!HAS_PCH_LPT(dev), "Unexpected PCH type %d\n",
  4840. INTEL_PCH_TYPE(dev));
  4841. WARN(num_connectors != 1, "%d connectors attached to pipe %c\n",
  4842. num_connectors, pipe_name(pipe));
  4843. WARN_ON(I915_READ(PIPECONF(intel_crtc->cpu_transcoder)) &
  4844. (PIPECONF_ENABLE | I965_PIPECONF_ACTIVE));
  4845. WARN_ON(I915_READ(DSPCNTR(plane)) & DISPLAY_PLANE_ENABLE);
  4846. if (!intel_ddi_pll_mode_set(crtc, adjusted_mode->clock))
  4847. return -EINVAL;
  4848. /* Ensure that the cursor is valid for the new mode before changing... */
  4849. intel_crtc_update_cursor(crtc, true);
  4850. /* determine panel color depth */
  4851. dither = intel_choose_pipe_bpp_dither(crtc, fb, &intel_crtc->bpp,
  4852. adjusted_mode);
  4853. DRM_DEBUG_KMS("Mode for pipe %d:\n", pipe);
  4854. drm_mode_debug_printmodeline(mode);
  4855. if (is_dp && !is_cpu_edp)
  4856. intel_dp_set_m_n(crtc, mode, adjusted_mode);
  4857. intel_crtc->lowfreq_avail = false;
  4858. intel_set_pipe_timings(intel_crtc, mode, adjusted_mode);
  4859. if (!is_dp || is_cpu_edp)
  4860. ironlake_set_m_n(crtc, mode, adjusted_mode);
  4861. haswell_set_pipeconf(crtc, adjusted_mode, dither);
  4862. /* Set up the display plane register */
  4863. I915_WRITE(DSPCNTR(plane), DISPPLANE_GAMMA_ENABLE);
  4864. POSTING_READ(DSPCNTR(plane));
  4865. ret = intel_pipe_set_base(crtc, x, y, fb);
  4866. intel_update_watermarks(dev);
  4867. intel_update_linetime_watermarks(dev, pipe, adjusted_mode);
  4868. return ret;
  4869. }
  4870. static int intel_crtc_mode_set(struct drm_crtc *crtc,
  4871. struct drm_display_mode *mode,
  4872. struct drm_display_mode *adjusted_mode,
  4873. int x, int y,
  4874. struct drm_framebuffer *fb)
  4875. {
  4876. struct drm_device *dev = crtc->dev;
  4877. struct drm_i915_private *dev_priv = dev->dev_private;
  4878. struct drm_encoder_helper_funcs *encoder_funcs;
  4879. struct intel_encoder *encoder;
  4880. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4881. int pipe = intel_crtc->pipe;
  4882. int ret;
  4883. if (IS_HASWELL(dev) && intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))
  4884. intel_crtc->cpu_transcoder = TRANSCODER_EDP;
  4885. else
  4886. intel_crtc->cpu_transcoder = pipe;
  4887. drm_vblank_pre_modeset(dev, pipe);
  4888. ret = dev_priv->display.crtc_mode_set(crtc, mode, adjusted_mode,
  4889. x, y, fb);
  4890. drm_vblank_post_modeset(dev, pipe);
  4891. if (ret != 0)
  4892. return ret;
  4893. for_each_encoder_on_crtc(dev, crtc, encoder) {
  4894. DRM_DEBUG_KMS("[ENCODER:%d:%s] set [MODE:%d:%s]\n",
  4895. encoder->base.base.id,
  4896. drm_get_encoder_name(&encoder->base),
  4897. mode->base.id, mode->name);
  4898. encoder_funcs = encoder->base.helper_private;
  4899. encoder_funcs->mode_set(&encoder->base, mode, adjusted_mode);
  4900. }
  4901. return 0;
  4902. }
  4903. static bool intel_eld_uptodate(struct drm_connector *connector,
  4904. int reg_eldv, uint32_t bits_eldv,
  4905. int reg_elda, uint32_t bits_elda,
  4906. int reg_edid)
  4907. {
  4908. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  4909. uint8_t *eld = connector->eld;
  4910. uint32_t i;
  4911. i = I915_READ(reg_eldv);
  4912. i &= bits_eldv;
  4913. if (!eld[0])
  4914. return !i;
  4915. if (!i)
  4916. return false;
  4917. i = I915_READ(reg_elda);
  4918. i &= ~bits_elda;
  4919. I915_WRITE(reg_elda, i);
  4920. for (i = 0; i < eld[2]; i++)
  4921. if (I915_READ(reg_edid) != *((uint32_t *)eld + i))
  4922. return false;
  4923. return true;
  4924. }
  4925. static void g4x_write_eld(struct drm_connector *connector,
  4926. struct drm_crtc *crtc)
  4927. {
  4928. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  4929. uint8_t *eld = connector->eld;
  4930. uint32_t eldv;
  4931. uint32_t len;
  4932. uint32_t i;
  4933. i = I915_READ(G4X_AUD_VID_DID);
  4934. if (i == INTEL_AUDIO_DEVBLC || i == INTEL_AUDIO_DEVCL)
  4935. eldv = G4X_ELDV_DEVCL_DEVBLC;
  4936. else
  4937. eldv = G4X_ELDV_DEVCTG;
  4938. if (intel_eld_uptodate(connector,
  4939. G4X_AUD_CNTL_ST, eldv,
  4940. G4X_AUD_CNTL_ST, G4X_ELD_ADDR,
  4941. G4X_HDMIW_HDMIEDID))
  4942. return;
  4943. i = I915_READ(G4X_AUD_CNTL_ST);
  4944. i &= ~(eldv | G4X_ELD_ADDR);
  4945. len = (i >> 9) & 0x1f; /* ELD buffer size */
  4946. I915_WRITE(G4X_AUD_CNTL_ST, i);
  4947. if (!eld[0])
  4948. return;
  4949. len = min_t(uint8_t, eld[2], len);
  4950. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  4951. for (i = 0; i < len; i++)
  4952. I915_WRITE(G4X_HDMIW_HDMIEDID, *((uint32_t *)eld + i));
  4953. i = I915_READ(G4X_AUD_CNTL_ST);
  4954. i |= eldv;
  4955. I915_WRITE(G4X_AUD_CNTL_ST, i);
  4956. }
  4957. static void haswell_write_eld(struct drm_connector *connector,
  4958. struct drm_crtc *crtc)
  4959. {
  4960. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  4961. uint8_t *eld = connector->eld;
  4962. struct drm_device *dev = crtc->dev;
  4963. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4964. uint32_t eldv;
  4965. uint32_t i;
  4966. int len;
  4967. int pipe = to_intel_crtc(crtc)->pipe;
  4968. int tmp;
  4969. int hdmiw_hdmiedid = HSW_AUD_EDID_DATA(pipe);
  4970. int aud_cntl_st = HSW_AUD_DIP_ELD_CTRL(pipe);
  4971. int aud_config = HSW_AUD_CFG(pipe);
  4972. int aud_cntrl_st2 = HSW_AUD_PIN_ELD_CP_VLD;
  4973. DRM_DEBUG_DRIVER("HDMI: Haswell Audio initialize....\n");
  4974. /* Audio output enable */
  4975. DRM_DEBUG_DRIVER("HDMI audio: enable codec\n");
  4976. tmp = I915_READ(aud_cntrl_st2);
  4977. tmp |= (AUDIO_OUTPUT_ENABLE_A << (pipe * 4));
  4978. I915_WRITE(aud_cntrl_st2, tmp);
  4979. /* Wait for 1 vertical blank */
  4980. intel_wait_for_vblank(dev, pipe);
  4981. /* Set ELD valid state */
  4982. tmp = I915_READ(aud_cntrl_st2);
  4983. DRM_DEBUG_DRIVER("HDMI audio: pin eld vld status=0x%8x\n", tmp);
  4984. tmp |= (AUDIO_ELD_VALID_A << (pipe * 4));
  4985. I915_WRITE(aud_cntrl_st2, tmp);
  4986. tmp = I915_READ(aud_cntrl_st2);
  4987. DRM_DEBUG_DRIVER("HDMI audio: eld vld status=0x%8x\n", tmp);
  4988. /* Enable HDMI mode */
  4989. tmp = I915_READ(aud_config);
  4990. DRM_DEBUG_DRIVER("HDMI audio: audio conf: 0x%8x\n", tmp);
  4991. /* clear N_programing_enable and N_value_index */
  4992. tmp &= ~(AUD_CONFIG_N_VALUE_INDEX | AUD_CONFIG_N_PROG_ENABLE);
  4993. I915_WRITE(aud_config, tmp);
  4994. DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe));
  4995. eldv = AUDIO_ELD_VALID_A << (pipe * 4);
  4996. intel_crtc->eld_vld = true;
  4997. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  4998. DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
  4999. eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
  5000. I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */
  5001. } else
  5002. I915_WRITE(aud_config, 0);
  5003. if (intel_eld_uptodate(connector,
  5004. aud_cntrl_st2, eldv,
  5005. aud_cntl_st, IBX_ELD_ADDRESS,
  5006. hdmiw_hdmiedid))
  5007. return;
  5008. i = I915_READ(aud_cntrl_st2);
  5009. i &= ~eldv;
  5010. I915_WRITE(aud_cntrl_st2, i);
  5011. if (!eld[0])
  5012. return;
  5013. i = I915_READ(aud_cntl_st);
  5014. i &= ~IBX_ELD_ADDRESS;
  5015. I915_WRITE(aud_cntl_st, i);
  5016. i = (i >> 29) & DIP_PORT_SEL_MASK; /* DIP_Port_Select, 0x1 = PortB */
  5017. DRM_DEBUG_DRIVER("port num:%d\n", i);
  5018. len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */
  5019. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  5020. for (i = 0; i < len; i++)
  5021. I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i));
  5022. i = I915_READ(aud_cntrl_st2);
  5023. i |= eldv;
  5024. I915_WRITE(aud_cntrl_st2, i);
  5025. }
  5026. static void ironlake_write_eld(struct drm_connector *connector,
  5027. struct drm_crtc *crtc)
  5028. {
  5029. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  5030. uint8_t *eld = connector->eld;
  5031. uint32_t eldv;
  5032. uint32_t i;
  5033. int len;
  5034. int hdmiw_hdmiedid;
  5035. int aud_config;
  5036. int aud_cntl_st;
  5037. int aud_cntrl_st2;
  5038. int pipe = to_intel_crtc(crtc)->pipe;
  5039. if (HAS_PCH_IBX(connector->dev)) {
  5040. hdmiw_hdmiedid = IBX_HDMIW_HDMIEDID(pipe);
  5041. aud_config = IBX_AUD_CFG(pipe);
  5042. aud_cntl_st = IBX_AUD_CNTL_ST(pipe);
  5043. aud_cntrl_st2 = IBX_AUD_CNTL_ST2;
  5044. } else {
  5045. hdmiw_hdmiedid = CPT_HDMIW_HDMIEDID(pipe);
  5046. aud_config = CPT_AUD_CFG(pipe);
  5047. aud_cntl_st = CPT_AUD_CNTL_ST(pipe);
  5048. aud_cntrl_st2 = CPT_AUD_CNTRL_ST2;
  5049. }
  5050. DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe));
  5051. i = I915_READ(aud_cntl_st);
  5052. i = (i >> 29) & DIP_PORT_SEL_MASK; /* DIP_Port_Select, 0x1 = PortB */
  5053. if (!i) {
  5054. DRM_DEBUG_DRIVER("Audio directed to unknown port\n");
  5055. /* operate blindly on all ports */
  5056. eldv = IBX_ELD_VALIDB;
  5057. eldv |= IBX_ELD_VALIDB << 4;
  5058. eldv |= IBX_ELD_VALIDB << 8;
  5059. } else {
  5060. DRM_DEBUG_DRIVER("ELD on port %c\n", 'A' + i);
  5061. eldv = IBX_ELD_VALIDB << ((i - 1) * 4);
  5062. }
  5063. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  5064. DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
  5065. eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
  5066. I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */
  5067. } else
  5068. I915_WRITE(aud_config, 0);
  5069. if (intel_eld_uptodate(connector,
  5070. aud_cntrl_st2, eldv,
  5071. aud_cntl_st, IBX_ELD_ADDRESS,
  5072. hdmiw_hdmiedid))
  5073. return;
  5074. i = I915_READ(aud_cntrl_st2);
  5075. i &= ~eldv;
  5076. I915_WRITE(aud_cntrl_st2, i);
  5077. if (!eld[0])
  5078. return;
  5079. i = I915_READ(aud_cntl_st);
  5080. i &= ~IBX_ELD_ADDRESS;
  5081. I915_WRITE(aud_cntl_st, i);
  5082. len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */
  5083. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  5084. for (i = 0; i < len; i++)
  5085. I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i));
  5086. i = I915_READ(aud_cntrl_st2);
  5087. i |= eldv;
  5088. I915_WRITE(aud_cntrl_st2, i);
  5089. }
  5090. void intel_write_eld(struct drm_encoder *encoder,
  5091. struct drm_display_mode *mode)
  5092. {
  5093. struct drm_crtc *crtc = encoder->crtc;
  5094. struct drm_connector *connector;
  5095. struct drm_device *dev = encoder->dev;
  5096. struct drm_i915_private *dev_priv = dev->dev_private;
  5097. connector = drm_select_eld(encoder, mode);
  5098. if (!connector)
  5099. return;
  5100. DRM_DEBUG_DRIVER("ELD on [CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  5101. connector->base.id,
  5102. drm_get_connector_name(connector),
  5103. connector->encoder->base.id,
  5104. drm_get_encoder_name(connector->encoder));
  5105. connector->eld[6] = drm_av_sync_delay(connector, mode) / 2;
  5106. if (dev_priv->display.write_eld)
  5107. dev_priv->display.write_eld(connector, crtc);
  5108. }
  5109. /** Loads the palette/gamma unit for the CRTC with the prepared values */
  5110. void intel_crtc_load_lut(struct drm_crtc *crtc)
  5111. {
  5112. struct drm_device *dev = crtc->dev;
  5113. struct drm_i915_private *dev_priv = dev->dev_private;
  5114. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5115. int palreg = PALETTE(intel_crtc->pipe);
  5116. int i;
  5117. /* The clocks have to be on to load the palette. */
  5118. if (!crtc->enabled || !intel_crtc->active)
  5119. return;
  5120. /* use legacy palette for Ironlake */
  5121. if (HAS_PCH_SPLIT(dev))
  5122. palreg = LGC_PALETTE(intel_crtc->pipe);
  5123. for (i = 0; i < 256; i++) {
  5124. I915_WRITE(palreg + 4 * i,
  5125. (intel_crtc->lut_r[i] << 16) |
  5126. (intel_crtc->lut_g[i] << 8) |
  5127. intel_crtc->lut_b[i]);
  5128. }
  5129. }
  5130. static void i845_update_cursor(struct drm_crtc *crtc, u32 base)
  5131. {
  5132. struct drm_device *dev = crtc->dev;
  5133. struct drm_i915_private *dev_priv = dev->dev_private;
  5134. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5135. bool visible = base != 0;
  5136. u32 cntl;
  5137. if (intel_crtc->cursor_visible == visible)
  5138. return;
  5139. cntl = I915_READ(_CURACNTR);
  5140. if (visible) {
  5141. /* On these chipsets we can only modify the base whilst
  5142. * the cursor is disabled.
  5143. */
  5144. I915_WRITE(_CURABASE, base);
  5145. cntl &= ~(CURSOR_FORMAT_MASK);
  5146. /* XXX width must be 64, stride 256 => 0x00 << 28 */
  5147. cntl |= CURSOR_ENABLE |
  5148. CURSOR_GAMMA_ENABLE |
  5149. CURSOR_FORMAT_ARGB;
  5150. } else
  5151. cntl &= ~(CURSOR_ENABLE | CURSOR_GAMMA_ENABLE);
  5152. I915_WRITE(_CURACNTR, cntl);
  5153. intel_crtc->cursor_visible = visible;
  5154. }
  5155. static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base)
  5156. {
  5157. struct drm_device *dev = crtc->dev;
  5158. struct drm_i915_private *dev_priv = dev->dev_private;
  5159. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5160. int pipe = intel_crtc->pipe;
  5161. bool visible = base != 0;
  5162. if (intel_crtc->cursor_visible != visible) {
  5163. uint32_t cntl = I915_READ(CURCNTR(pipe));
  5164. if (base) {
  5165. cntl &= ~(CURSOR_MODE | MCURSOR_PIPE_SELECT);
  5166. cntl |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE;
  5167. cntl |= pipe << 28; /* Connect to correct pipe */
  5168. } else {
  5169. cntl &= ~(CURSOR_MODE | MCURSOR_GAMMA_ENABLE);
  5170. cntl |= CURSOR_MODE_DISABLE;
  5171. }
  5172. I915_WRITE(CURCNTR(pipe), cntl);
  5173. intel_crtc->cursor_visible = visible;
  5174. }
  5175. /* and commit changes on next vblank */
  5176. I915_WRITE(CURBASE(pipe), base);
  5177. }
  5178. static void ivb_update_cursor(struct drm_crtc *crtc, u32 base)
  5179. {
  5180. struct drm_device *dev = crtc->dev;
  5181. struct drm_i915_private *dev_priv = dev->dev_private;
  5182. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5183. int pipe = intel_crtc->pipe;
  5184. bool visible = base != 0;
  5185. if (intel_crtc->cursor_visible != visible) {
  5186. uint32_t cntl = I915_READ(CURCNTR_IVB(pipe));
  5187. if (base) {
  5188. cntl &= ~CURSOR_MODE;
  5189. cntl |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE;
  5190. } else {
  5191. cntl &= ~(CURSOR_MODE | MCURSOR_GAMMA_ENABLE);
  5192. cntl |= CURSOR_MODE_DISABLE;
  5193. }
  5194. I915_WRITE(CURCNTR_IVB(pipe), cntl);
  5195. intel_crtc->cursor_visible = visible;
  5196. }
  5197. /* and commit changes on next vblank */
  5198. I915_WRITE(CURBASE_IVB(pipe), base);
  5199. }
  5200. /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
  5201. static void intel_crtc_update_cursor(struct drm_crtc *crtc,
  5202. bool on)
  5203. {
  5204. struct drm_device *dev = crtc->dev;
  5205. struct drm_i915_private *dev_priv = dev->dev_private;
  5206. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5207. int pipe = intel_crtc->pipe;
  5208. int x = intel_crtc->cursor_x;
  5209. int y = intel_crtc->cursor_y;
  5210. u32 base, pos;
  5211. bool visible;
  5212. pos = 0;
  5213. if (on && crtc->enabled && crtc->fb) {
  5214. base = intel_crtc->cursor_addr;
  5215. if (x > (int) crtc->fb->width)
  5216. base = 0;
  5217. if (y > (int) crtc->fb->height)
  5218. base = 0;
  5219. } else
  5220. base = 0;
  5221. if (x < 0) {
  5222. if (x + intel_crtc->cursor_width < 0)
  5223. base = 0;
  5224. pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
  5225. x = -x;
  5226. }
  5227. pos |= x << CURSOR_X_SHIFT;
  5228. if (y < 0) {
  5229. if (y + intel_crtc->cursor_height < 0)
  5230. base = 0;
  5231. pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
  5232. y = -y;
  5233. }
  5234. pos |= y << CURSOR_Y_SHIFT;
  5235. visible = base != 0;
  5236. if (!visible && !intel_crtc->cursor_visible)
  5237. return;
  5238. if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) {
  5239. I915_WRITE(CURPOS_IVB(pipe), pos);
  5240. ivb_update_cursor(crtc, base);
  5241. } else {
  5242. I915_WRITE(CURPOS(pipe), pos);
  5243. if (IS_845G(dev) || IS_I865G(dev))
  5244. i845_update_cursor(crtc, base);
  5245. else
  5246. i9xx_update_cursor(crtc, base);
  5247. }
  5248. }
  5249. static int intel_crtc_cursor_set(struct drm_crtc *crtc,
  5250. struct drm_file *file,
  5251. uint32_t handle,
  5252. uint32_t width, uint32_t height)
  5253. {
  5254. struct drm_device *dev = crtc->dev;
  5255. struct drm_i915_private *dev_priv = dev->dev_private;
  5256. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5257. struct drm_i915_gem_object *obj;
  5258. uint32_t addr;
  5259. int ret;
  5260. /* if we want to turn off the cursor ignore width and height */
  5261. if (!handle) {
  5262. DRM_DEBUG_KMS("cursor off\n");
  5263. addr = 0;
  5264. obj = NULL;
  5265. mutex_lock(&dev->struct_mutex);
  5266. goto finish;
  5267. }
  5268. /* Currently we only support 64x64 cursors */
  5269. if (width != 64 || height != 64) {
  5270. DRM_ERROR("we currently only support 64x64 cursors\n");
  5271. return -EINVAL;
  5272. }
  5273. obj = to_intel_bo(drm_gem_object_lookup(dev, file, handle));
  5274. if (&obj->base == NULL)
  5275. return -ENOENT;
  5276. if (obj->base.size < width * height * 4) {
  5277. DRM_ERROR("buffer is to small\n");
  5278. ret = -ENOMEM;
  5279. goto fail;
  5280. }
  5281. /* we only need to pin inside GTT if cursor is non-phy */
  5282. mutex_lock(&dev->struct_mutex);
  5283. if (!dev_priv->info->cursor_needs_physical) {
  5284. if (obj->tiling_mode) {
  5285. DRM_ERROR("cursor cannot be tiled\n");
  5286. ret = -EINVAL;
  5287. goto fail_locked;
  5288. }
  5289. ret = i915_gem_object_pin_to_display_plane(obj, 0, NULL);
  5290. if (ret) {
  5291. DRM_ERROR("failed to move cursor bo into the GTT\n");
  5292. goto fail_locked;
  5293. }
  5294. ret = i915_gem_object_put_fence(obj);
  5295. if (ret) {
  5296. DRM_ERROR("failed to release fence for cursor");
  5297. goto fail_unpin;
  5298. }
  5299. addr = obj->gtt_offset;
  5300. } else {
  5301. int align = IS_I830(dev) ? 16 * 1024 : 256;
  5302. ret = i915_gem_attach_phys_object(dev, obj,
  5303. (intel_crtc->pipe == 0) ? I915_GEM_PHYS_CURSOR_0 : I915_GEM_PHYS_CURSOR_1,
  5304. align);
  5305. if (ret) {
  5306. DRM_ERROR("failed to attach phys object\n");
  5307. goto fail_locked;
  5308. }
  5309. addr = obj->phys_obj->handle->busaddr;
  5310. }
  5311. if (IS_GEN2(dev))
  5312. I915_WRITE(CURSIZE, (height << 12) | width);
  5313. finish:
  5314. if (intel_crtc->cursor_bo) {
  5315. if (dev_priv->info->cursor_needs_physical) {
  5316. if (intel_crtc->cursor_bo != obj)
  5317. i915_gem_detach_phys_object(dev, intel_crtc->cursor_bo);
  5318. } else
  5319. i915_gem_object_unpin(intel_crtc->cursor_bo);
  5320. drm_gem_object_unreference(&intel_crtc->cursor_bo->base);
  5321. }
  5322. mutex_unlock(&dev->struct_mutex);
  5323. intel_crtc->cursor_addr = addr;
  5324. intel_crtc->cursor_bo = obj;
  5325. intel_crtc->cursor_width = width;
  5326. intel_crtc->cursor_height = height;
  5327. intel_crtc_update_cursor(crtc, true);
  5328. return 0;
  5329. fail_unpin:
  5330. i915_gem_object_unpin(obj);
  5331. fail_locked:
  5332. mutex_unlock(&dev->struct_mutex);
  5333. fail:
  5334. drm_gem_object_unreference_unlocked(&obj->base);
  5335. return ret;
  5336. }
  5337. static int intel_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
  5338. {
  5339. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5340. intel_crtc->cursor_x = x;
  5341. intel_crtc->cursor_y = y;
  5342. intel_crtc_update_cursor(crtc, true);
  5343. return 0;
  5344. }
  5345. /** Sets the color ramps on behalf of RandR */
  5346. void intel_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
  5347. u16 blue, int regno)
  5348. {
  5349. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5350. intel_crtc->lut_r[regno] = red >> 8;
  5351. intel_crtc->lut_g[regno] = green >> 8;
  5352. intel_crtc->lut_b[regno] = blue >> 8;
  5353. }
  5354. void intel_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green,
  5355. u16 *blue, int regno)
  5356. {
  5357. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5358. *red = intel_crtc->lut_r[regno] << 8;
  5359. *green = intel_crtc->lut_g[regno] << 8;
  5360. *blue = intel_crtc->lut_b[regno] << 8;
  5361. }
  5362. static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
  5363. u16 *blue, uint32_t start, uint32_t size)
  5364. {
  5365. int end = (start + size > 256) ? 256 : start + size, i;
  5366. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5367. for (i = start; i < end; i++) {
  5368. intel_crtc->lut_r[i] = red[i] >> 8;
  5369. intel_crtc->lut_g[i] = green[i] >> 8;
  5370. intel_crtc->lut_b[i] = blue[i] >> 8;
  5371. }
  5372. intel_crtc_load_lut(crtc);
  5373. }
  5374. /**
  5375. * Get a pipe with a simple mode set on it for doing load-based monitor
  5376. * detection.
  5377. *
  5378. * It will be up to the load-detect code to adjust the pipe as appropriate for
  5379. * its requirements. The pipe will be connected to no other encoders.
  5380. *
  5381. * Currently this code will only succeed if there is a pipe with no encoders
  5382. * configured for it. In the future, it could choose to temporarily disable
  5383. * some outputs to free up a pipe for its use.
  5384. *
  5385. * \return crtc, or NULL if no pipes are available.
  5386. */
  5387. /* VESA 640x480x72Hz mode to set on the pipe */
  5388. static struct drm_display_mode load_detect_mode = {
  5389. DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
  5390. 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  5391. };
  5392. static struct drm_framebuffer *
  5393. intel_framebuffer_create(struct drm_device *dev,
  5394. struct drm_mode_fb_cmd2 *mode_cmd,
  5395. struct drm_i915_gem_object *obj)
  5396. {
  5397. struct intel_framebuffer *intel_fb;
  5398. int ret;
  5399. intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
  5400. if (!intel_fb) {
  5401. drm_gem_object_unreference_unlocked(&obj->base);
  5402. return ERR_PTR(-ENOMEM);
  5403. }
  5404. ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj);
  5405. if (ret) {
  5406. drm_gem_object_unreference_unlocked(&obj->base);
  5407. kfree(intel_fb);
  5408. return ERR_PTR(ret);
  5409. }
  5410. return &intel_fb->base;
  5411. }
  5412. static u32
  5413. intel_framebuffer_pitch_for_width(int width, int bpp)
  5414. {
  5415. u32 pitch = DIV_ROUND_UP(width * bpp, 8);
  5416. return ALIGN(pitch, 64);
  5417. }
  5418. static u32
  5419. intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp)
  5420. {
  5421. u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp);
  5422. return ALIGN(pitch * mode->vdisplay, PAGE_SIZE);
  5423. }
  5424. static struct drm_framebuffer *
  5425. intel_framebuffer_create_for_mode(struct drm_device *dev,
  5426. struct drm_display_mode *mode,
  5427. int depth, int bpp)
  5428. {
  5429. struct drm_i915_gem_object *obj;
  5430. struct drm_mode_fb_cmd2 mode_cmd = { 0 };
  5431. obj = i915_gem_alloc_object(dev,
  5432. intel_framebuffer_size_for_mode(mode, bpp));
  5433. if (obj == NULL)
  5434. return ERR_PTR(-ENOMEM);
  5435. mode_cmd.width = mode->hdisplay;
  5436. mode_cmd.height = mode->vdisplay;
  5437. mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width,
  5438. bpp);
  5439. mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth);
  5440. return intel_framebuffer_create(dev, &mode_cmd, obj);
  5441. }
  5442. static struct drm_framebuffer *
  5443. mode_fits_in_fbdev(struct drm_device *dev,
  5444. struct drm_display_mode *mode)
  5445. {
  5446. struct drm_i915_private *dev_priv = dev->dev_private;
  5447. struct drm_i915_gem_object *obj;
  5448. struct drm_framebuffer *fb;
  5449. if (dev_priv->fbdev == NULL)
  5450. return NULL;
  5451. obj = dev_priv->fbdev->ifb.obj;
  5452. if (obj == NULL)
  5453. return NULL;
  5454. fb = &dev_priv->fbdev->ifb.base;
  5455. if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay,
  5456. fb->bits_per_pixel))
  5457. return NULL;
  5458. if (obj->base.size < mode->vdisplay * fb->pitches[0])
  5459. return NULL;
  5460. return fb;
  5461. }
  5462. bool intel_get_load_detect_pipe(struct drm_connector *connector,
  5463. struct drm_display_mode *mode,
  5464. struct intel_load_detect_pipe *old)
  5465. {
  5466. struct intel_crtc *intel_crtc;
  5467. struct intel_encoder *intel_encoder =
  5468. intel_attached_encoder(connector);
  5469. struct drm_crtc *possible_crtc;
  5470. struct drm_encoder *encoder = &intel_encoder->base;
  5471. struct drm_crtc *crtc = NULL;
  5472. struct drm_device *dev = encoder->dev;
  5473. struct drm_framebuffer *fb;
  5474. int i = -1;
  5475. DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  5476. connector->base.id, drm_get_connector_name(connector),
  5477. encoder->base.id, drm_get_encoder_name(encoder));
  5478. /*
  5479. * Algorithm gets a little messy:
  5480. *
  5481. * - if the connector already has an assigned crtc, use it (but make
  5482. * sure it's on first)
  5483. *
  5484. * - try to find the first unused crtc that can drive this connector,
  5485. * and use that if we find one
  5486. */
  5487. /* See if we already have a CRTC for this connector */
  5488. if (encoder->crtc) {
  5489. crtc = encoder->crtc;
  5490. mutex_lock(&crtc->mutex);
  5491. old->dpms_mode = connector->dpms;
  5492. old->load_detect_temp = false;
  5493. /* Make sure the crtc and connector are running */
  5494. if (connector->dpms != DRM_MODE_DPMS_ON)
  5495. connector->funcs->dpms(connector, DRM_MODE_DPMS_ON);
  5496. return true;
  5497. }
  5498. /* Find an unused one (if possible) */
  5499. list_for_each_entry(possible_crtc, &dev->mode_config.crtc_list, head) {
  5500. i++;
  5501. if (!(encoder->possible_crtcs & (1 << i)))
  5502. continue;
  5503. if (!possible_crtc->enabled) {
  5504. crtc = possible_crtc;
  5505. break;
  5506. }
  5507. }
  5508. /*
  5509. * If we didn't find an unused CRTC, don't use any.
  5510. */
  5511. if (!crtc) {
  5512. DRM_DEBUG_KMS("no pipe available for load-detect\n");
  5513. return false;
  5514. }
  5515. mutex_lock(&crtc->mutex);
  5516. intel_encoder->new_crtc = to_intel_crtc(crtc);
  5517. to_intel_connector(connector)->new_encoder = intel_encoder;
  5518. intel_crtc = to_intel_crtc(crtc);
  5519. old->dpms_mode = connector->dpms;
  5520. old->load_detect_temp = true;
  5521. old->release_fb = NULL;
  5522. if (!mode)
  5523. mode = &load_detect_mode;
  5524. /* We need a framebuffer large enough to accommodate all accesses
  5525. * that the plane may generate whilst we perform load detection.
  5526. * We can not rely on the fbcon either being present (we get called
  5527. * during its initialisation to detect all boot displays, or it may
  5528. * not even exist) or that it is large enough to satisfy the
  5529. * requested mode.
  5530. */
  5531. fb = mode_fits_in_fbdev(dev, mode);
  5532. if (fb == NULL) {
  5533. DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
  5534. fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32);
  5535. old->release_fb = fb;
  5536. } else
  5537. DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
  5538. if (IS_ERR(fb)) {
  5539. DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
  5540. mutex_unlock(&crtc->mutex);
  5541. return false;
  5542. }
  5543. if (intel_set_mode(crtc, mode, 0, 0, fb)) {
  5544. DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
  5545. if (old->release_fb)
  5546. old->release_fb->funcs->destroy(old->release_fb);
  5547. mutex_unlock(&crtc->mutex);
  5548. return false;
  5549. }
  5550. /* let the connector get through one full cycle before testing */
  5551. intel_wait_for_vblank(dev, intel_crtc->pipe);
  5552. return true;
  5553. }
  5554. void intel_release_load_detect_pipe(struct drm_connector *connector,
  5555. struct intel_load_detect_pipe *old)
  5556. {
  5557. struct intel_encoder *intel_encoder =
  5558. intel_attached_encoder(connector);
  5559. struct drm_encoder *encoder = &intel_encoder->base;
  5560. struct drm_crtc *crtc = encoder->crtc;
  5561. DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  5562. connector->base.id, drm_get_connector_name(connector),
  5563. encoder->base.id, drm_get_encoder_name(encoder));
  5564. if (old->load_detect_temp) {
  5565. to_intel_connector(connector)->new_encoder = NULL;
  5566. intel_encoder->new_crtc = NULL;
  5567. intel_set_mode(crtc, NULL, 0, 0, NULL);
  5568. if (old->release_fb) {
  5569. drm_framebuffer_unregister_private(old->release_fb);
  5570. drm_framebuffer_unreference(old->release_fb);
  5571. }
  5572. mutex_unlock(&crtc->mutex);
  5573. return;
  5574. }
  5575. /* Switch crtc and encoder back off if necessary */
  5576. if (old->dpms_mode != DRM_MODE_DPMS_ON)
  5577. connector->funcs->dpms(connector, old->dpms_mode);
  5578. mutex_unlock(&crtc->mutex);
  5579. }
  5580. /* Returns the clock of the currently programmed mode of the given pipe. */
  5581. static int intel_crtc_clock_get(struct drm_device *dev, struct drm_crtc *crtc)
  5582. {
  5583. struct drm_i915_private *dev_priv = dev->dev_private;
  5584. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5585. int pipe = intel_crtc->pipe;
  5586. u32 dpll = I915_READ(DPLL(pipe));
  5587. u32 fp;
  5588. intel_clock_t clock;
  5589. if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
  5590. fp = I915_READ(FP0(pipe));
  5591. else
  5592. fp = I915_READ(FP1(pipe));
  5593. clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
  5594. if (IS_PINEVIEW(dev)) {
  5595. clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
  5596. clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
  5597. } else {
  5598. clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
  5599. clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
  5600. }
  5601. if (!IS_GEN2(dev)) {
  5602. if (IS_PINEVIEW(dev))
  5603. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
  5604. DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
  5605. else
  5606. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
  5607. DPLL_FPA01_P1_POST_DIV_SHIFT);
  5608. switch (dpll & DPLL_MODE_MASK) {
  5609. case DPLLB_MODE_DAC_SERIAL:
  5610. clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
  5611. 5 : 10;
  5612. break;
  5613. case DPLLB_MODE_LVDS:
  5614. clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
  5615. 7 : 14;
  5616. break;
  5617. default:
  5618. DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
  5619. "mode\n", (int)(dpll & DPLL_MODE_MASK));
  5620. return 0;
  5621. }
  5622. /* XXX: Handle the 100Mhz refclk */
  5623. intel_clock(dev, 96000, &clock);
  5624. } else {
  5625. bool is_lvds = (pipe == 1) && (I915_READ(LVDS) & LVDS_PORT_EN);
  5626. if (is_lvds) {
  5627. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
  5628. DPLL_FPA01_P1_POST_DIV_SHIFT);
  5629. clock.p2 = 14;
  5630. if ((dpll & PLL_REF_INPUT_MASK) ==
  5631. PLLB_REF_INPUT_SPREADSPECTRUMIN) {
  5632. /* XXX: might not be 66MHz */
  5633. intel_clock(dev, 66000, &clock);
  5634. } else
  5635. intel_clock(dev, 48000, &clock);
  5636. } else {
  5637. if (dpll & PLL_P1_DIVIDE_BY_TWO)
  5638. clock.p1 = 2;
  5639. else {
  5640. clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
  5641. DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
  5642. }
  5643. if (dpll & PLL_P2_DIVIDE_BY_4)
  5644. clock.p2 = 4;
  5645. else
  5646. clock.p2 = 2;
  5647. intel_clock(dev, 48000, &clock);
  5648. }
  5649. }
  5650. /* XXX: It would be nice to validate the clocks, but we can't reuse
  5651. * i830PllIsValid() because it relies on the xf86_config connector
  5652. * configuration being accurate, which it isn't necessarily.
  5653. */
  5654. return clock.dot;
  5655. }
  5656. /** Returns the currently programmed mode of the given pipe. */
  5657. struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
  5658. struct drm_crtc *crtc)
  5659. {
  5660. struct drm_i915_private *dev_priv = dev->dev_private;
  5661. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5662. enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
  5663. struct drm_display_mode *mode;
  5664. int htot = I915_READ(HTOTAL(cpu_transcoder));
  5665. int hsync = I915_READ(HSYNC(cpu_transcoder));
  5666. int vtot = I915_READ(VTOTAL(cpu_transcoder));
  5667. int vsync = I915_READ(VSYNC(cpu_transcoder));
  5668. mode = kzalloc(sizeof(*mode), GFP_KERNEL);
  5669. if (!mode)
  5670. return NULL;
  5671. mode->clock = intel_crtc_clock_get(dev, crtc);
  5672. mode->hdisplay = (htot & 0xffff) + 1;
  5673. mode->htotal = ((htot & 0xffff0000) >> 16) + 1;
  5674. mode->hsync_start = (hsync & 0xffff) + 1;
  5675. mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1;
  5676. mode->vdisplay = (vtot & 0xffff) + 1;
  5677. mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1;
  5678. mode->vsync_start = (vsync & 0xffff) + 1;
  5679. mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1;
  5680. drm_mode_set_name(mode);
  5681. return mode;
  5682. }
  5683. static void intel_increase_pllclock(struct drm_crtc *crtc)
  5684. {
  5685. struct drm_device *dev = crtc->dev;
  5686. drm_i915_private_t *dev_priv = dev->dev_private;
  5687. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5688. int pipe = intel_crtc->pipe;
  5689. int dpll_reg = DPLL(pipe);
  5690. int dpll;
  5691. if (HAS_PCH_SPLIT(dev))
  5692. return;
  5693. if (!dev_priv->lvds_downclock_avail)
  5694. return;
  5695. dpll = I915_READ(dpll_reg);
  5696. if (!HAS_PIPE_CXSR(dev) && (dpll & DISPLAY_RATE_SELECT_FPA1)) {
  5697. DRM_DEBUG_DRIVER("upclocking LVDS\n");
  5698. assert_panel_unlocked(dev_priv, pipe);
  5699. dpll &= ~DISPLAY_RATE_SELECT_FPA1;
  5700. I915_WRITE(dpll_reg, dpll);
  5701. intel_wait_for_vblank(dev, pipe);
  5702. dpll = I915_READ(dpll_reg);
  5703. if (dpll & DISPLAY_RATE_SELECT_FPA1)
  5704. DRM_DEBUG_DRIVER("failed to upclock LVDS!\n");
  5705. }
  5706. }
  5707. static void intel_decrease_pllclock(struct drm_crtc *crtc)
  5708. {
  5709. struct drm_device *dev = crtc->dev;
  5710. drm_i915_private_t *dev_priv = dev->dev_private;
  5711. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5712. if (HAS_PCH_SPLIT(dev))
  5713. return;
  5714. if (!dev_priv->lvds_downclock_avail)
  5715. return;
  5716. /*
  5717. * Since this is called by a timer, we should never get here in
  5718. * the manual case.
  5719. */
  5720. if (!HAS_PIPE_CXSR(dev) && intel_crtc->lowfreq_avail) {
  5721. int pipe = intel_crtc->pipe;
  5722. int dpll_reg = DPLL(pipe);
  5723. int dpll;
  5724. DRM_DEBUG_DRIVER("downclocking LVDS\n");
  5725. assert_panel_unlocked(dev_priv, pipe);
  5726. dpll = I915_READ(dpll_reg);
  5727. dpll |= DISPLAY_RATE_SELECT_FPA1;
  5728. I915_WRITE(dpll_reg, dpll);
  5729. intel_wait_for_vblank(dev, pipe);
  5730. dpll = I915_READ(dpll_reg);
  5731. if (!(dpll & DISPLAY_RATE_SELECT_FPA1))
  5732. DRM_DEBUG_DRIVER("failed to downclock LVDS!\n");
  5733. }
  5734. }
  5735. void intel_mark_busy(struct drm_device *dev)
  5736. {
  5737. i915_update_gfx_val(dev->dev_private);
  5738. }
  5739. void intel_mark_idle(struct drm_device *dev)
  5740. {
  5741. struct drm_crtc *crtc;
  5742. if (!i915_powersave)
  5743. return;
  5744. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  5745. if (!crtc->fb)
  5746. continue;
  5747. intel_decrease_pllclock(crtc);
  5748. }
  5749. }
  5750. void intel_mark_fb_busy(struct drm_i915_gem_object *obj)
  5751. {
  5752. struct drm_device *dev = obj->base.dev;
  5753. struct drm_crtc *crtc;
  5754. if (!i915_powersave)
  5755. return;
  5756. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  5757. if (!crtc->fb)
  5758. continue;
  5759. if (to_intel_framebuffer(crtc->fb)->obj == obj)
  5760. intel_increase_pllclock(crtc);
  5761. }
  5762. }
  5763. static void intel_crtc_destroy(struct drm_crtc *crtc)
  5764. {
  5765. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5766. struct drm_device *dev = crtc->dev;
  5767. struct intel_unpin_work *work;
  5768. unsigned long flags;
  5769. spin_lock_irqsave(&dev->event_lock, flags);
  5770. work = intel_crtc->unpin_work;
  5771. intel_crtc->unpin_work = NULL;
  5772. spin_unlock_irqrestore(&dev->event_lock, flags);
  5773. if (work) {
  5774. cancel_work_sync(&work->work);
  5775. kfree(work);
  5776. }
  5777. drm_crtc_cleanup(crtc);
  5778. kfree(intel_crtc);
  5779. }
  5780. static void intel_unpin_work_fn(struct work_struct *__work)
  5781. {
  5782. struct intel_unpin_work *work =
  5783. container_of(__work, struct intel_unpin_work, work);
  5784. struct drm_device *dev = work->crtc->dev;
  5785. mutex_lock(&dev->struct_mutex);
  5786. intel_unpin_fb_obj(work->old_fb_obj);
  5787. drm_gem_object_unreference(&work->pending_flip_obj->base);
  5788. drm_gem_object_unreference(&work->old_fb_obj->base);
  5789. intel_update_fbc(dev);
  5790. mutex_unlock(&dev->struct_mutex);
  5791. BUG_ON(atomic_read(&to_intel_crtc(work->crtc)->unpin_work_count) == 0);
  5792. atomic_dec(&to_intel_crtc(work->crtc)->unpin_work_count);
  5793. kfree(work);
  5794. }
  5795. static void do_intel_finish_page_flip(struct drm_device *dev,
  5796. struct drm_crtc *crtc)
  5797. {
  5798. drm_i915_private_t *dev_priv = dev->dev_private;
  5799. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5800. struct intel_unpin_work *work;
  5801. struct drm_i915_gem_object *obj;
  5802. unsigned long flags;
  5803. /* Ignore early vblank irqs */
  5804. if (intel_crtc == NULL)
  5805. return;
  5806. spin_lock_irqsave(&dev->event_lock, flags);
  5807. work = intel_crtc->unpin_work;
  5808. /* Ensure we don't miss a work->pending update ... */
  5809. smp_rmb();
  5810. if (work == NULL || atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
  5811. spin_unlock_irqrestore(&dev->event_lock, flags);
  5812. return;
  5813. }
  5814. /* and that the unpin work is consistent wrt ->pending. */
  5815. smp_rmb();
  5816. intel_crtc->unpin_work = NULL;
  5817. if (work->event)
  5818. drm_send_vblank_event(dev, intel_crtc->pipe, work->event);
  5819. drm_vblank_put(dev, intel_crtc->pipe);
  5820. spin_unlock_irqrestore(&dev->event_lock, flags);
  5821. obj = work->old_fb_obj;
  5822. wake_up_all(&dev_priv->pending_flip_queue);
  5823. queue_work(dev_priv->wq, &work->work);
  5824. trace_i915_flip_complete(intel_crtc->plane, work->pending_flip_obj);
  5825. }
  5826. void intel_finish_page_flip(struct drm_device *dev, int pipe)
  5827. {
  5828. drm_i915_private_t *dev_priv = dev->dev_private;
  5829. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  5830. do_intel_finish_page_flip(dev, crtc);
  5831. }
  5832. void intel_finish_page_flip_plane(struct drm_device *dev, int plane)
  5833. {
  5834. drm_i915_private_t *dev_priv = dev->dev_private;
  5835. struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane];
  5836. do_intel_finish_page_flip(dev, crtc);
  5837. }
  5838. void intel_prepare_page_flip(struct drm_device *dev, int plane)
  5839. {
  5840. drm_i915_private_t *dev_priv = dev->dev_private;
  5841. struct intel_crtc *intel_crtc =
  5842. to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]);
  5843. unsigned long flags;
  5844. /* NB: An MMIO update of the plane base pointer will also
  5845. * generate a page-flip completion irq, i.e. every modeset
  5846. * is also accompanied by a spurious intel_prepare_page_flip().
  5847. */
  5848. spin_lock_irqsave(&dev->event_lock, flags);
  5849. if (intel_crtc->unpin_work)
  5850. atomic_inc_not_zero(&intel_crtc->unpin_work->pending);
  5851. spin_unlock_irqrestore(&dev->event_lock, flags);
  5852. }
  5853. inline static void intel_mark_page_flip_active(struct intel_crtc *intel_crtc)
  5854. {
  5855. /* Ensure that the work item is consistent when activating it ... */
  5856. smp_wmb();
  5857. atomic_set(&intel_crtc->unpin_work->pending, INTEL_FLIP_PENDING);
  5858. /* and that it is marked active as soon as the irq could fire. */
  5859. smp_wmb();
  5860. }
  5861. static int intel_gen2_queue_flip(struct drm_device *dev,
  5862. struct drm_crtc *crtc,
  5863. struct drm_framebuffer *fb,
  5864. struct drm_i915_gem_object *obj)
  5865. {
  5866. struct drm_i915_private *dev_priv = dev->dev_private;
  5867. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5868. u32 flip_mask;
  5869. struct intel_ring_buffer *ring = &dev_priv->ring[RCS];
  5870. int ret;
  5871. ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
  5872. if (ret)
  5873. goto err;
  5874. ret = intel_ring_begin(ring, 6);
  5875. if (ret)
  5876. goto err_unpin;
  5877. /* Can't queue multiple flips, so wait for the previous
  5878. * one to finish before executing the next.
  5879. */
  5880. if (intel_crtc->plane)
  5881. flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
  5882. else
  5883. flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
  5884. intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
  5885. intel_ring_emit(ring, MI_NOOP);
  5886. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  5887. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  5888. intel_ring_emit(ring, fb->pitches[0]);
  5889. intel_ring_emit(ring, obj->gtt_offset + intel_crtc->dspaddr_offset);
  5890. intel_ring_emit(ring, 0); /* aux display base address, unused */
  5891. intel_mark_page_flip_active(intel_crtc);
  5892. intel_ring_advance(ring);
  5893. return 0;
  5894. err_unpin:
  5895. intel_unpin_fb_obj(obj);
  5896. err:
  5897. return ret;
  5898. }
  5899. static int intel_gen3_queue_flip(struct drm_device *dev,
  5900. struct drm_crtc *crtc,
  5901. struct drm_framebuffer *fb,
  5902. struct drm_i915_gem_object *obj)
  5903. {
  5904. struct drm_i915_private *dev_priv = dev->dev_private;
  5905. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5906. u32 flip_mask;
  5907. struct intel_ring_buffer *ring = &dev_priv->ring[RCS];
  5908. int ret;
  5909. ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
  5910. if (ret)
  5911. goto err;
  5912. ret = intel_ring_begin(ring, 6);
  5913. if (ret)
  5914. goto err_unpin;
  5915. if (intel_crtc->plane)
  5916. flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
  5917. else
  5918. flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
  5919. intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
  5920. intel_ring_emit(ring, MI_NOOP);
  5921. intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 |
  5922. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  5923. intel_ring_emit(ring, fb->pitches[0]);
  5924. intel_ring_emit(ring, obj->gtt_offset + intel_crtc->dspaddr_offset);
  5925. intel_ring_emit(ring, MI_NOOP);
  5926. intel_mark_page_flip_active(intel_crtc);
  5927. intel_ring_advance(ring);
  5928. return 0;
  5929. err_unpin:
  5930. intel_unpin_fb_obj(obj);
  5931. err:
  5932. return ret;
  5933. }
  5934. static int intel_gen4_queue_flip(struct drm_device *dev,
  5935. struct drm_crtc *crtc,
  5936. struct drm_framebuffer *fb,
  5937. struct drm_i915_gem_object *obj)
  5938. {
  5939. struct drm_i915_private *dev_priv = dev->dev_private;
  5940. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5941. uint32_t pf, pipesrc;
  5942. struct intel_ring_buffer *ring = &dev_priv->ring[RCS];
  5943. int ret;
  5944. ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
  5945. if (ret)
  5946. goto err;
  5947. ret = intel_ring_begin(ring, 4);
  5948. if (ret)
  5949. goto err_unpin;
  5950. /* i965+ uses the linear or tiled offsets from the
  5951. * Display Registers (which do not change across a page-flip)
  5952. * so we need only reprogram the base address.
  5953. */
  5954. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  5955. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  5956. intel_ring_emit(ring, fb->pitches[0]);
  5957. intel_ring_emit(ring,
  5958. (obj->gtt_offset + intel_crtc->dspaddr_offset) |
  5959. obj->tiling_mode);
  5960. /* XXX Enabling the panel-fitter across page-flip is so far
  5961. * untested on non-native modes, so ignore it for now.
  5962. * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
  5963. */
  5964. pf = 0;
  5965. pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
  5966. intel_ring_emit(ring, pf | pipesrc);
  5967. intel_mark_page_flip_active(intel_crtc);
  5968. intel_ring_advance(ring);
  5969. return 0;
  5970. err_unpin:
  5971. intel_unpin_fb_obj(obj);
  5972. err:
  5973. return ret;
  5974. }
  5975. static int intel_gen6_queue_flip(struct drm_device *dev,
  5976. struct drm_crtc *crtc,
  5977. struct drm_framebuffer *fb,
  5978. struct drm_i915_gem_object *obj)
  5979. {
  5980. struct drm_i915_private *dev_priv = dev->dev_private;
  5981. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5982. struct intel_ring_buffer *ring = &dev_priv->ring[RCS];
  5983. uint32_t pf, pipesrc;
  5984. int ret;
  5985. ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
  5986. if (ret)
  5987. goto err;
  5988. ret = intel_ring_begin(ring, 4);
  5989. if (ret)
  5990. goto err_unpin;
  5991. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  5992. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  5993. intel_ring_emit(ring, fb->pitches[0] | obj->tiling_mode);
  5994. intel_ring_emit(ring, obj->gtt_offset + intel_crtc->dspaddr_offset);
  5995. /* Contrary to the suggestions in the documentation,
  5996. * "Enable Panel Fitter" does not seem to be required when page
  5997. * flipping with a non-native mode, and worse causes a normal
  5998. * modeset to fail.
  5999. * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
  6000. */
  6001. pf = 0;
  6002. pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
  6003. intel_ring_emit(ring, pf | pipesrc);
  6004. intel_mark_page_flip_active(intel_crtc);
  6005. intel_ring_advance(ring);
  6006. return 0;
  6007. err_unpin:
  6008. intel_unpin_fb_obj(obj);
  6009. err:
  6010. return ret;
  6011. }
  6012. /*
  6013. * On gen7 we currently use the blit ring because (in early silicon at least)
  6014. * the render ring doesn't give us interrpts for page flip completion, which
  6015. * means clients will hang after the first flip is queued. Fortunately the
  6016. * blit ring generates interrupts properly, so use it instead.
  6017. */
  6018. static int intel_gen7_queue_flip(struct drm_device *dev,
  6019. struct drm_crtc *crtc,
  6020. struct drm_framebuffer *fb,
  6021. struct drm_i915_gem_object *obj)
  6022. {
  6023. struct drm_i915_private *dev_priv = dev->dev_private;
  6024. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6025. struct intel_ring_buffer *ring = &dev_priv->ring[BCS];
  6026. uint32_t plane_bit = 0;
  6027. int ret;
  6028. ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
  6029. if (ret)
  6030. goto err;
  6031. switch(intel_crtc->plane) {
  6032. case PLANE_A:
  6033. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A;
  6034. break;
  6035. case PLANE_B:
  6036. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B;
  6037. break;
  6038. case PLANE_C:
  6039. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C;
  6040. break;
  6041. default:
  6042. WARN_ONCE(1, "unknown plane in flip command\n");
  6043. ret = -ENODEV;
  6044. goto err_unpin;
  6045. }
  6046. ret = intel_ring_begin(ring, 4);
  6047. if (ret)
  6048. goto err_unpin;
  6049. intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | plane_bit);
  6050. intel_ring_emit(ring, (fb->pitches[0] | obj->tiling_mode));
  6051. intel_ring_emit(ring, obj->gtt_offset + intel_crtc->dspaddr_offset);
  6052. intel_ring_emit(ring, (MI_NOOP));
  6053. intel_mark_page_flip_active(intel_crtc);
  6054. intel_ring_advance(ring);
  6055. return 0;
  6056. err_unpin:
  6057. intel_unpin_fb_obj(obj);
  6058. err:
  6059. return ret;
  6060. }
  6061. static int intel_default_queue_flip(struct drm_device *dev,
  6062. struct drm_crtc *crtc,
  6063. struct drm_framebuffer *fb,
  6064. struct drm_i915_gem_object *obj)
  6065. {
  6066. return -ENODEV;
  6067. }
  6068. static int intel_crtc_page_flip(struct drm_crtc *crtc,
  6069. struct drm_framebuffer *fb,
  6070. struct drm_pending_vblank_event *event)
  6071. {
  6072. struct drm_device *dev = crtc->dev;
  6073. struct drm_i915_private *dev_priv = dev->dev_private;
  6074. struct intel_framebuffer *intel_fb;
  6075. struct drm_i915_gem_object *obj;
  6076. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6077. struct intel_unpin_work *work;
  6078. unsigned long flags;
  6079. int ret;
  6080. /* Can't change pixel format via MI display flips. */
  6081. if (fb->pixel_format != crtc->fb->pixel_format)
  6082. return -EINVAL;
  6083. /*
  6084. * TILEOFF/LINOFF registers can't be changed via MI display flips.
  6085. * Note that pitch changes could also affect these register.
  6086. */
  6087. if (INTEL_INFO(dev)->gen > 3 &&
  6088. (fb->offsets[0] != crtc->fb->offsets[0] ||
  6089. fb->pitches[0] != crtc->fb->pitches[0]))
  6090. return -EINVAL;
  6091. work = kzalloc(sizeof *work, GFP_KERNEL);
  6092. if (work == NULL)
  6093. return -ENOMEM;
  6094. work->event = event;
  6095. work->crtc = crtc;
  6096. intel_fb = to_intel_framebuffer(crtc->fb);
  6097. work->old_fb_obj = intel_fb->obj;
  6098. INIT_WORK(&work->work, intel_unpin_work_fn);
  6099. ret = drm_vblank_get(dev, intel_crtc->pipe);
  6100. if (ret)
  6101. goto free_work;
  6102. /* We borrow the event spin lock for protecting unpin_work */
  6103. spin_lock_irqsave(&dev->event_lock, flags);
  6104. if (intel_crtc->unpin_work) {
  6105. spin_unlock_irqrestore(&dev->event_lock, flags);
  6106. kfree(work);
  6107. drm_vblank_put(dev, intel_crtc->pipe);
  6108. DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
  6109. return -EBUSY;
  6110. }
  6111. intel_crtc->unpin_work = work;
  6112. spin_unlock_irqrestore(&dev->event_lock, flags);
  6113. intel_fb = to_intel_framebuffer(fb);
  6114. obj = intel_fb->obj;
  6115. if (atomic_read(&intel_crtc->unpin_work_count) >= 2)
  6116. flush_workqueue(dev_priv->wq);
  6117. ret = i915_mutex_lock_interruptible(dev);
  6118. if (ret)
  6119. goto cleanup;
  6120. /* Reference the objects for the scheduled work. */
  6121. drm_gem_object_reference(&work->old_fb_obj->base);
  6122. drm_gem_object_reference(&obj->base);
  6123. crtc->fb = fb;
  6124. work->pending_flip_obj = obj;
  6125. work->enable_stall_check = true;
  6126. atomic_inc(&intel_crtc->unpin_work_count);
  6127. ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
  6128. if (ret)
  6129. goto cleanup_pending;
  6130. intel_disable_fbc(dev);
  6131. intel_mark_fb_busy(obj);
  6132. mutex_unlock(&dev->struct_mutex);
  6133. trace_i915_flip_request(intel_crtc->plane, obj);
  6134. return 0;
  6135. cleanup_pending:
  6136. atomic_dec(&intel_crtc->unpin_work_count);
  6137. drm_gem_object_unreference(&work->old_fb_obj->base);
  6138. drm_gem_object_unreference(&obj->base);
  6139. mutex_unlock(&dev->struct_mutex);
  6140. cleanup:
  6141. spin_lock_irqsave(&dev->event_lock, flags);
  6142. intel_crtc->unpin_work = NULL;
  6143. spin_unlock_irqrestore(&dev->event_lock, flags);
  6144. drm_vblank_put(dev, intel_crtc->pipe);
  6145. free_work:
  6146. kfree(work);
  6147. return ret;
  6148. }
  6149. static struct drm_crtc_helper_funcs intel_helper_funcs = {
  6150. .mode_set_base_atomic = intel_pipe_set_base_atomic,
  6151. .load_lut = intel_crtc_load_lut,
  6152. .disable = intel_crtc_noop,
  6153. };
  6154. bool intel_encoder_check_is_cloned(struct intel_encoder *encoder)
  6155. {
  6156. struct intel_encoder *other_encoder;
  6157. struct drm_crtc *crtc = &encoder->new_crtc->base;
  6158. if (WARN_ON(!crtc))
  6159. return false;
  6160. list_for_each_entry(other_encoder,
  6161. &crtc->dev->mode_config.encoder_list,
  6162. base.head) {
  6163. if (&other_encoder->new_crtc->base != crtc ||
  6164. encoder == other_encoder)
  6165. continue;
  6166. else
  6167. return true;
  6168. }
  6169. return false;
  6170. }
  6171. static bool intel_encoder_crtc_ok(struct drm_encoder *encoder,
  6172. struct drm_crtc *crtc)
  6173. {
  6174. struct drm_device *dev;
  6175. struct drm_crtc *tmp;
  6176. int crtc_mask = 1;
  6177. WARN(!crtc, "checking null crtc?\n");
  6178. dev = crtc->dev;
  6179. list_for_each_entry(tmp, &dev->mode_config.crtc_list, head) {
  6180. if (tmp == crtc)
  6181. break;
  6182. crtc_mask <<= 1;
  6183. }
  6184. if (encoder->possible_crtcs & crtc_mask)
  6185. return true;
  6186. return false;
  6187. }
  6188. /**
  6189. * intel_modeset_update_staged_output_state
  6190. *
  6191. * Updates the staged output configuration state, e.g. after we've read out the
  6192. * current hw state.
  6193. */
  6194. static void intel_modeset_update_staged_output_state(struct drm_device *dev)
  6195. {
  6196. struct intel_encoder *encoder;
  6197. struct intel_connector *connector;
  6198. list_for_each_entry(connector, &dev->mode_config.connector_list,
  6199. base.head) {
  6200. connector->new_encoder =
  6201. to_intel_encoder(connector->base.encoder);
  6202. }
  6203. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  6204. base.head) {
  6205. encoder->new_crtc =
  6206. to_intel_crtc(encoder->base.crtc);
  6207. }
  6208. }
  6209. /**
  6210. * intel_modeset_commit_output_state
  6211. *
  6212. * This function copies the stage display pipe configuration to the real one.
  6213. */
  6214. static void intel_modeset_commit_output_state(struct drm_device *dev)
  6215. {
  6216. struct intel_encoder *encoder;
  6217. struct intel_connector *connector;
  6218. list_for_each_entry(connector, &dev->mode_config.connector_list,
  6219. base.head) {
  6220. connector->base.encoder = &connector->new_encoder->base;
  6221. }
  6222. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  6223. base.head) {
  6224. encoder->base.crtc = &encoder->new_crtc->base;
  6225. }
  6226. }
  6227. static struct drm_display_mode *
  6228. intel_modeset_adjusted_mode(struct drm_crtc *crtc,
  6229. struct drm_display_mode *mode)
  6230. {
  6231. struct drm_device *dev = crtc->dev;
  6232. struct drm_display_mode *adjusted_mode;
  6233. struct drm_encoder_helper_funcs *encoder_funcs;
  6234. struct intel_encoder *encoder;
  6235. adjusted_mode = drm_mode_duplicate(dev, mode);
  6236. if (!adjusted_mode)
  6237. return ERR_PTR(-ENOMEM);
  6238. /* Pass our mode to the connectors and the CRTC to give them a chance to
  6239. * adjust it according to limitations or connector properties, and also
  6240. * a chance to reject the mode entirely.
  6241. */
  6242. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  6243. base.head) {
  6244. if (&encoder->new_crtc->base != crtc)
  6245. continue;
  6246. encoder_funcs = encoder->base.helper_private;
  6247. if (!(encoder_funcs->mode_fixup(&encoder->base, mode,
  6248. adjusted_mode))) {
  6249. DRM_DEBUG_KMS("Encoder fixup failed\n");
  6250. goto fail;
  6251. }
  6252. }
  6253. if (!(intel_crtc_mode_fixup(crtc, mode, adjusted_mode))) {
  6254. DRM_DEBUG_KMS("CRTC fixup failed\n");
  6255. goto fail;
  6256. }
  6257. DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id);
  6258. return adjusted_mode;
  6259. fail:
  6260. drm_mode_destroy(dev, adjusted_mode);
  6261. return ERR_PTR(-EINVAL);
  6262. }
  6263. /* Computes which crtcs are affected and sets the relevant bits in the mask. For
  6264. * simplicity we use the crtc's pipe number (because it's easier to obtain). */
  6265. static void
  6266. intel_modeset_affected_pipes(struct drm_crtc *crtc, unsigned *modeset_pipes,
  6267. unsigned *prepare_pipes, unsigned *disable_pipes)
  6268. {
  6269. struct intel_crtc *intel_crtc;
  6270. struct drm_device *dev = crtc->dev;
  6271. struct intel_encoder *encoder;
  6272. struct intel_connector *connector;
  6273. struct drm_crtc *tmp_crtc;
  6274. *disable_pipes = *modeset_pipes = *prepare_pipes = 0;
  6275. /* Check which crtcs have changed outputs connected to them, these need
  6276. * to be part of the prepare_pipes mask. We don't (yet) support global
  6277. * modeset across multiple crtcs, so modeset_pipes will only have one
  6278. * bit set at most. */
  6279. list_for_each_entry(connector, &dev->mode_config.connector_list,
  6280. base.head) {
  6281. if (connector->base.encoder == &connector->new_encoder->base)
  6282. continue;
  6283. if (connector->base.encoder) {
  6284. tmp_crtc = connector->base.encoder->crtc;
  6285. *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe;
  6286. }
  6287. if (connector->new_encoder)
  6288. *prepare_pipes |=
  6289. 1 << connector->new_encoder->new_crtc->pipe;
  6290. }
  6291. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  6292. base.head) {
  6293. if (encoder->base.crtc == &encoder->new_crtc->base)
  6294. continue;
  6295. if (encoder->base.crtc) {
  6296. tmp_crtc = encoder->base.crtc;
  6297. *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe;
  6298. }
  6299. if (encoder->new_crtc)
  6300. *prepare_pipes |= 1 << encoder->new_crtc->pipe;
  6301. }
  6302. /* Check for any pipes that will be fully disabled ... */
  6303. list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list,
  6304. base.head) {
  6305. bool used = false;
  6306. /* Don't try to disable disabled crtcs. */
  6307. if (!intel_crtc->base.enabled)
  6308. continue;
  6309. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  6310. base.head) {
  6311. if (encoder->new_crtc == intel_crtc)
  6312. used = true;
  6313. }
  6314. if (!used)
  6315. *disable_pipes |= 1 << intel_crtc->pipe;
  6316. }
  6317. /* set_mode is also used to update properties on life display pipes. */
  6318. intel_crtc = to_intel_crtc(crtc);
  6319. if (crtc->enabled)
  6320. *prepare_pipes |= 1 << intel_crtc->pipe;
  6321. /* We only support modeset on one single crtc, hence we need to do that
  6322. * only for the passed in crtc iff we change anything else than just
  6323. * disable crtcs.
  6324. *
  6325. * This is actually not true, to be fully compatible with the old crtc
  6326. * helper we automatically disable _any_ output (i.e. doesn't need to be
  6327. * connected to the crtc we're modesetting on) if it's disconnected.
  6328. * Which is a rather nutty api (since changed the output configuration
  6329. * without userspace's explicit request can lead to confusion), but
  6330. * alas. Hence we currently need to modeset on all pipes we prepare. */
  6331. if (*prepare_pipes)
  6332. *modeset_pipes = *prepare_pipes;
  6333. /* ... and mask these out. */
  6334. *modeset_pipes &= ~(*disable_pipes);
  6335. *prepare_pipes &= ~(*disable_pipes);
  6336. }
  6337. static bool intel_crtc_in_use(struct drm_crtc *crtc)
  6338. {
  6339. struct drm_encoder *encoder;
  6340. struct drm_device *dev = crtc->dev;
  6341. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)
  6342. if (encoder->crtc == crtc)
  6343. return true;
  6344. return false;
  6345. }
  6346. static void
  6347. intel_modeset_update_state(struct drm_device *dev, unsigned prepare_pipes)
  6348. {
  6349. struct intel_encoder *intel_encoder;
  6350. struct intel_crtc *intel_crtc;
  6351. struct drm_connector *connector;
  6352. list_for_each_entry(intel_encoder, &dev->mode_config.encoder_list,
  6353. base.head) {
  6354. if (!intel_encoder->base.crtc)
  6355. continue;
  6356. intel_crtc = to_intel_crtc(intel_encoder->base.crtc);
  6357. if (prepare_pipes & (1 << intel_crtc->pipe))
  6358. intel_encoder->connectors_active = false;
  6359. }
  6360. intel_modeset_commit_output_state(dev);
  6361. /* Update computed state. */
  6362. list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list,
  6363. base.head) {
  6364. intel_crtc->base.enabled = intel_crtc_in_use(&intel_crtc->base);
  6365. }
  6366. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  6367. if (!connector->encoder || !connector->encoder->crtc)
  6368. continue;
  6369. intel_crtc = to_intel_crtc(connector->encoder->crtc);
  6370. if (prepare_pipes & (1 << intel_crtc->pipe)) {
  6371. struct drm_property *dpms_property =
  6372. dev->mode_config.dpms_property;
  6373. connector->dpms = DRM_MODE_DPMS_ON;
  6374. drm_object_property_set_value(&connector->base,
  6375. dpms_property,
  6376. DRM_MODE_DPMS_ON);
  6377. intel_encoder = to_intel_encoder(connector->encoder);
  6378. intel_encoder->connectors_active = true;
  6379. }
  6380. }
  6381. }
  6382. #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \
  6383. list_for_each_entry((intel_crtc), \
  6384. &(dev)->mode_config.crtc_list, \
  6385. base.head) \
  6386. if (mask & (1 <<(intel_crtc)->pipe)) \
  6387. void
  6388. intel_modeset_check_state(struct drm_device *dev)
  6389. {
  6390. struct intel_crtc *crtc;
  6391. struct intel_encoder *encoder;
  6392. struct intel_connector *connector;
  6393. list_for_each_entry(connector, &dev->mode_config.connector_list,
  6394. base.head) {
  6395. /* This also checks the encoder/connector hw state with the
  6396. * ->get_hw_state callbacks. */
  6397. intel_connector_check_state(connector);
  6398. WARN(&connector->new_encoder->base != connector->base.encoder,
  6399. "connector's staged encoder doesn't match current encoder\n");
  6400. }
  6401. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  6402. base.head) {
  6403. bool enabled = false;
  6404. bool active = false;
  6405. enum pipe pipe, tracked_pipe;
  6406. DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
  6407. encoder->base.base.id,
  6408. drm_get_encoder_name(&encoder->base));
  6409. WARN(&encoder->new_crtc->base != encoder->base.crtc,
  6410. "encoder's stage crtc doesn't match current crtc\n");
  6411. WARN(encoder->connectors_active && !encoder->base.crtc,
  6412. "encoder's active_connectors set, but no crtc\n");
  6413. list_for_each_entry(connector, &dev->mode_config.connector_list,
  6414. base.head) {
  6415. if (connector->base.encoder != &encoder->base)
  6416. continue;
  6417. enabled = true;
  6418. if (connector->base.dpms != DRM_MODE_DPMS_OFF)
  6419. active = true;
  6420. }
  6421. WARN(!!encoder->base.crtc != enabled,
  6422. "encoder's enabled state mismatch "
  6423. "(expected %i, found %i)\n",
  6424. !!encoder->base.crtc, enabled);
  6425. WARN(active && !encoder->base.crtc,
  6426. "active encoder with no crtc\n");
  6427. WARN(encoder->connectors_active != active,
  6428. "encoder's computed active state doesn't match tracked active state "
  6429. "(expected %i, found %i)\n", active, encoder->connectors_active);
  6430. active = encoder->get_hw_state(encoder, &pipe);
  6431. WARN(active != encoder->connectors_active,
  6432. "encoder's hw state doesn't match sw tracking "
  6433. "(expected %i, found %i)\n",
  6434. encoder->connectors_active, active);
  6435. if (!encoder->base.crtc)
  6436. continue;
  6437. tracked_pipe = to_intel_crtc(encoder->base.crtc)->pipe;
  6438. WARN(active && pipe != tracked_pipe,
  6439. "active encoder's pipe doesn't match"
  6440. "(expected %i, found %i)\n",
  6441. tracked_pipe, pipe);
  6442. }
  6443. list_for_each_entry(crtc, &dev->mode_config.crtc_list,
  6444. base.head) {
  6445. bool enabled = false;
  6446. bool active = false;
  6447. DRM_DEBUG_KMS("[CRTC:%d]\n",
  6448. crtc->base.base.id);
  6449. WARN(crtc->active && !crtc->base.enabled,
  6450. "active crtc, but not enabled in sw tracking\n");
  6451. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  6452. base.head) {
  6453. if (encoder->base.crtc != &crtc->base)
  6454. continue;
  6455. enabled = true;
  6456. if (encoder->connectors_active)
  6457. active = true;
  6458. }
  6459. WARN(active != crtc->active,
  6460. "crtc's computed active state doesn't match tracked active state "
  6461. "(expected %i, found %i)\n", active, crtc->active);
  6462. WARN(enabled != crtc->base.enabled,
  6463. "crtc's computed enabled state doesn't match tracked enabled state "
  6464. "(expected %i, found %i)\n", enabled, crtc->base.enabled);
  6465. assert_pipe(dev->dev_private, crtc->pipe, crtc->active);
  6466. }
  6467. }
  6468. int intel_set_mode(struct drm_crtc *crtc,
  6469. struct drm_display_mode *mode,
  6470. int x, int y, struct drm_framebuffer *fb)
  6471. {
  6472. struct drm_device *dev = crtc->dev;
  6473. drm_i915_private_t *dev_priv = dev->dev_private;
  6474. struct drm_display_mode *adjusted_mode, *saved_mode, *saved_hwmode;
  6475. struct intel_crtc *intel_crtc;
  6476. unsigned disable_pipes, prepare_pipes, modeset_pipes;
  6477. int ret = 0;
  6478. saved_mode = kmalloc(2 * sizeof(*saved_mode), GFP_KERNEL);
  6479. if (!saved_mode)
  6480. return -ENOMEM;
  6481. saved_hwmode = saved_mode + 1;
  6482. intel_modeset_affected_pipes(crtc, &modeset_pipes,
  6483. &prepare_pipes, &disable_pipes);
  6484. DRM_DEBUG_KMS("set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n",
  6485. modeset_pipes, prepare_pipes, disable_pipes);
  6486. for_each_intel_crtc_masked(dev, disable_pipes, intel_crtc)
  6487. intel_crtc_disable(&intel_crtc->base);
  6488. *saved_hwmode = crtc->hwmode;
  6489. *saved_mode = crtc->mode;
  6490. /* Hack: Because we don't (yet) support global modeset on multiple
  6491. * crtcs, we don't keep track of the new mode for more than one crtc.
  6492. * Hence simply check whether any bit is set in modeset_pipes in all the
  6493. * pieces of code that are not yet converted to deal with mutliple crtcs
  6494. * changing their mode at the same time. */
  6495. adjusted_mode = NULL;
  6496. if (modeset_pipes) {
  6497. adjusted_mode = intel_modeset_adjusted_mode(crtc, mode);
  6498. if (IS_ERR(adjusted_mode)) {
  6499. ret = PTR_ERR(adjusted_mode);
  6500. goto out;
  6501. }
  6502. }
  6503. for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) {
  6504. if (intel_crtc->base.enabled)
  6505. dev_priv->display.crtc_disable(&intel_crtc->base);
  6506. }
  6507. /* crtc->mode is already used by the ->mode_set callbacks, hence we need
  6508. * to set it here already despite that we pass it down the callchain.
  6509. */
  6510. if (modeset_pipes)
  6511. crtc->mode = *mode;
  6512. /* Only after disabling all output pipelines that will be changed can we
  6513. * update the the output configuration. */
  6514. intel_modeset_update_state(dev, prepare_pipes);
  6515. if (dev_priv->display.modeset_global_resources)
  6516. dev_priv->display.modeset_global_resources(dev);
  6517. /* Set up the DPLL and any encoders state that needs to adjust or depend
  6518. * on the DPLL.
  6519. */
  6520. for_each_intel_crtc_masked(dev, modeset_pipes, intel_crtc) {
  6521. ret = intel_crtc_mode_set(&intel_crtc->base,
  6522. mode, adjusted_mode,
  6523. x, y, fb);
  6524. if (ret)
  6525. goto done;
  6526. }
  6527. /* Now enable the clocks, plane, pipe, and connectors that we set up. */
  6528. for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc)
  6529. dev_priv->display.crtc_enable(&intel_crtc->base);
  6530. if (modeset_pipes) {
  6531. /* Store real post-adjustment hardware mode. */
  6532. crtc->hwmode = *adjusted_mode;
  6533. /* Calculate and store various constants which
  6534. * are later needed by vblank and swap-completion
  6535. * timestamping. They are derived from true hwmode.
  6536. */
  6537. drm_calc_timestamping_constants(crtc);
  6538. }
  6539. /* FIXME: add subpixel order */
  6540. done:
  6541. drm_mode_destroy(dev, adjusted_mode);
  6542. if (ret && crtc->enabled) {
  6543. crtc->hwmode = *saved_hwmode;
  6544. crtc->mode = *saved_mode;
  6545. } else {
  6546. intel_modeset_check_state(dev);
  6547. }
  6548. out:
  6549. kfree(saved_mode);
  6550. return ret;
  6551. }
  6552. void intel_crtc_restore_mode(struct drm_crtc *crtc)
  6553. {
  6554. intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y, crtc->fb);
  6555. }
  6556. #undef for_each_intel_crtc_masked
  6557. static void intel_set_config_free(struct intel_set_config *config)
  6558. {
  6559. if (!config)
  6560. return;
  6561. kfree(config->save_connector_encoders);
  6562. kfree(config->save_encoder_crtcs);
  6563. kfree(config);
  6564. }
  6565. static int intel_set_config_save_state(struct drm_device *dev,
  6566. struct intel_set_config *config)
  6567. {
  6568. struct drm_encoder *encoder;
  6569. struct drm_connector *connector;
  6570. int count;
  6571. config->save_encoder_crtcs =
  6572. kcalloc(dev->mode_config.num_encoder,
  6573. sizeof(struct drm_crtc *), GFP_KERNEL);
  6574. if (!config->save_encoder_crtcs)
  6575. return -ENOMEM;
  6576. config->save_connector_encoders =
  6577. kcalloc(dev->mode_config.num_connector,
  6578. sizeof(struct drm_encoder *), GFP_KERNEL);
  6579. if (!config->save_connector_encoders)
  6580. return -ENOMEM;
  6581. /* Copy data. Note that driver private data is not affected.
  6582. * Should anything bad happen only the expected state is
  6583. * restored, not the drivers personal bookkeeping.
  6584. */
  6585. count = 0;
  6586. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  6587. config->save_encoder_crtcs[count++] = encoder->crtc;
  6588. }
  6589. count = 0;
  6590. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  6591. config->save_connector_encoders[count++] = connector->encoder;
  6592. }
  6593. return 0;
  6594. }
  6595. static void intel_set_config_restore_state(struct drm_device *dev,
  6596. struct intel_set_config *config)
  6597. {
  6598. struct intel_encoder *encoder;
  6599. struct intel_connector *connector;
  6600. int count;
  6601. count = 0;
  6602. list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) {
  6603. encoder->new_crtc =
  6604. to_intel_crtc(config->save_encoder_crtcs[count++]);
  6605. }
  6606. count = 0;
  6607. list_for_each_entry(connector, &dev->mode_config.connector_list, base.head) {
  6608. connector->new_encoder =
  6609. to_intel_encoder(config->save_connector_encoders[count++]);
  6610. }
  6611. }
  6612. static void
  6613. intel_set_config_compute_mode_changes(struct drm_mode_set *set,
  6614. struct intel_set_config *config)
  6615. {
  6616. /* We should be able to check here if the fb has the same properties
  6617. * and then just flip_or_move it */
  6618. if (set->crtc->fb != set->fb) {
  6619. /* If we have no fb then treat it as a full mode set */
  6620. if (set->crtc->fb == NULL) {
  6621. DRM_DEBUG_KMS("crtc has no fb, full mode set\n");
  6622. config->mode_changed = true;
  6623. } else if (set->fb == NULL) {
  6624. config->mode_changed = true;
  6625. } else if (set->fb->depth != set->crtc->fb->depth) {
  6626. config->mode_changed = true;
  6627. } else if (set->fb->bits_per_pixel !=
  6628. set->crtc->fb->bits_per_pixel) {
  6629. config->mode_changed = true;
  6630. } else
  6631. config->fb_changed = true;
  6632. }
  6633. if (set->fb && (set->x != set->crtc->x || set->y != set->crtc->y))
  6634. config->fb_changed = true;
  6635. if (set->mode && !drm_mode_equal(set->mode, &set->crtc->mode)) {
  6636. DRM_DEBUG_KMS("modes are different, full mode set\n");
  6637. drm_mode_debug_printmodeline(&set->crtc->mode);
  6638. drm_mode_debug_printmodeline(set->mode);
  6639. config->mode_changed = true;
  6640. }
  6641. }
  6642. static int
  6643. intel_modeset_stage_output_state(struct drm_device *dev,
  6644. struct drm_mode_set *set,
  6645. struct intel_set_config *config)
  6646. {
  6647. struct drm_crtc *new_crtc;
  6648. struct intel_connector *connector;
  6649. struct intel_encoder *encoder;
  6650. int count, ro;
  6651. /* The upper layers ensure that we either disabl a crtc or have a list
  6652. * of connectors. For paranoia, double-check this. */
  6653. WARN_ON(!set->fb && (set->num_connectors != 0));
  6654. WARN_ON(set->fb && (set->num_connectors == 0));
  6655. count = 0;
  6656. list_for_each_entry(connector, &dev->mode_config.connector_list,
  6657. base.head) {
  6658. /* Otherwise traverse passed in connector list and get encoders
  6659. * for them. */
  6660. for (ro = 0; ro < set->num_connectors; ro++) {
  6661. if (set->connectors[ro] == &connector->base) {
  6662. connector->new_encoder = connector->encoder;
  6663. break;
  6664. }
  6665. }
  6666. /* If we disable the crtc, disable all its connectors. Also, if
  6667. * the connector is on the changing crtc but not on the new
  6668. * connector list, disable it. */
  6669. if ((!set->fb || ro == set->num_connectors) &&
  6670. connector->base.encoder &&
  6671. connector->base.encoder->crtc == set->crtc) {
  6672. connector->new_encoder = NULL;
  6673. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n",
  6674. connector->base.base.id,
  6675. drm_get_connector_name(&connector->base));
  6676. }
  6677. if (&connector->new_encoder->base != connector->base.encoder) {
  6678. DRM_DEBUG_KMS("encoder changed, full mode switch\n");
  6679. config->mode_changed = true;
  6680. }
  6681. }
  6682. /* connector->new_encoder is now updated for all connectors. */
  6683. /* Update crtc of enabled connectors. */
  6684. count = 0;
  6685. list_for_each_entry(connector, &dev->mode_config.connector_list,
  6686. base.head) {
  6687. if (!connector->new_encoder)
  6688. continue;
  6689. new_crtc = connector->new_encoder->base.crtc;
  6690. for (ro = 0; ro < set->num_connectors; ro++) {
  6691. if (set->connectors[ro] == &connector->base)
  6692. new_crtc = set->crtc;
  6693. }
  6694. /* Make sure the new CRTC will work with the encoder */
  6695. if (!intel_encoder_crtc_ok(&connector->new_encoder->base,
  6696. new_crtc)) {
  6697. return -EINVAL;
  6698. }
  6699. connector->encoder->new_crtc = to_intel_crtc(new_crtc);
  6700. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n",
  6701. connector->base.base.id,
  6702. drm_get_connector_name(&connector->base),
  6703. new_crtc->base.id);
  6704. }
  6705. /* Check for any encoders that needs to be disabled. */
  6706. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  6707. base.head) {
  6708. list_for_each_entry(connector,
  6709. &dev->mode_config.connector_list,
  6710. base.head) {
  6711. if (connector->new_encoder == encoder) {
  6712. WARN_ON(!connector->new_encoder->new_crtc);
  6713. goto next_encoder;
  6714. }
  6715. }
  6716. encoder->new_crtc = NULL;
  6717. next_encoder:
  6718. /* Only now check for crtc changes so we don't miss encoders
  6719. * that will be disabled. */
  6720. if (&encoder->new_crtc->base != encoder->base.crtc) {
  6721. DRM_DEBUG_KMS("crtc changed, full mode switch\n");
  6722. config->mode_changed = true;
  6723. }
  6724. }
  6725. /* Now we've also updated encoder->new_crtc for all encoders. */
  6726. return 0;
  6727. }
  6728. static int intel_crtc_set_config(struct drm_mode_set *set)
  6729. {
  6730. struct drm_device *dev;
  6731. struct drm_mode_set save_set;
  6732. struct intel_set_config *config;
  6733. int ret;
  6734. BUG_ON(!set);
  6735. BUG_ON(!set->crtc);
  6736. BUG_ON(!set->crtc->helper_private);
  6737. if (!set->mode)
  6738. set->fb = NULL;
  6739. /* The fb helper likes to play gross jokes with ->mode_set_config.
  6740. * Unfortunately the crtc helper doesn't do much at all for this case,
  6741. * so we have to cope with this madness until the fb helper is fixed up. */
  6742. if (set->fb && set->num_connectors == 0)
  6743. return 0;
  6744. if (set->fb) {
  6745. DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n",
  6746. set->crtc->base.id, set->fb->base.id,
  6747. (int)set->num_connectors, set->x, set->y);
  6748. } else {
  6749. DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set->crtc->base.id);
  6750. }
  6751. dev = set->crtc->dev;
  6752. ret = -ENOMEM;
  6753. config = kzalloc(sizeof(*config), GFP_KERNEL);
  6754. if (!config)
  6755. goto out_config;
  6756. ret = intel_set_config_save_state(dev, config);
  6757. if (ret)
  6758. goto out_config;
  6759. save_set.crtc = set->crtc;
  6760. save_set.mode = &set->crtc->mode;
  6761. save_set.x = set->crtc->x;
  6762. save_set.y = set->crtc->y;
  6763. save_set.fb = set->crtc->fb;
  6764. /* Compute whether we need a full modeset, only an fb base update or no
  6765. * change at all. In the future we might also check whether only the
  6766. * mode changed, e.g. for LVDS where we only change the panel fitter in
  6767. * such cases. */
  6768. intel_set_config_compute_mode_changes(set, config);
  6769. ret = intel_modeset_stage_output_state(dev, set, config);
  6770. if (ret)
  6771. goto fail;
  6772. if (config->mode_changed) {
  6773. if (set->mode) {
  6774. DRM_DEBUG_KMS("attempting to set mode from"
  6775. " userspace\n");
  6776. drm_mode_debug_printmodeline(set->mode);
  6777. }
  6778. ret = intel_set_mode(set->crtc, set->mode,
  6779. set->x, set->y, set->fb);
  6780. if (ret) {
  6781. DRM_ERROR("failed to set mode on [CRTC:%d], err = %d\n",
  6782. set->crtc->base.id, ret);
  6783. goto fail;
  6784. }
  6785. } else if (config->fb_changed) {
  6786. ret = intel_pipe_set_base(set->crtc,
  6787. set->x, set->y, set->fb);
  6788. }
  6789. intel_set_config_free(config);
  6790. return 0;
  6791. fail:
  6792. intel_set_config_restore_state(dev, config);
  6793. /* Try to restore the config */
  6794. if (config->mode_changed &&
  6795. intel_set_mode(save_set.crtc, save_set.mode,
  6796. save_set.x, save_set.y, save_set.fb))
  6797. DRM_ERROR("failed to restore config after modeset failure\n");
  6798. out_config:
  6799. intel_set_config_free(config);
  6800. return ret;
  6801. }
  6802. static const struct drm_crtc_funcs intel_crtc_funcs = {
  6803. .cursor_set = intel_crtc_cursor_set,
  6804. .cursor_move = intel_crtc_cursor_move,
  6805. .gamma_set = intel_crtc_gamma_set,
  6806. .set_config = intel_crtc_set_config,
  6807. .destroy = intel_crtc_destroy,
  6808. .page_flip = intel_crtc_page_flip,
  6809. };
  6810. static void intel_cpu_pll_init(struct drm_device *dev)
  6811. {
  6812. if (HAS_DDI(dev))
  6813. intel_ddi_pll_init(dev);
  6814. }
  6815. static void intel_pch_pll_init(struct drm_device *dev)
  6816. {
  6817. drm_i915_private_t *dev_priv = dev->dev_private;
  6818. int i;
  6819. if (dev_priv->num_pch_pll == 0) {
  6820. DRM_DEBUG_KMS("No PCH PLLs on this hardware, skipping initialisation\n");
  6821. return;
  6822. }
  6823. for (i = 0; i < dev_priv->num_pch_pll; i++) {
  6824. dev_priv->pch_plls[i].pll_reg = _PCH_DPLL(i);
  6825. dev_priv->pch_plls[i].fp0_reg = _PCH_FP0(i);
  6826. dev_priv->pch_plls[i].fp1_reg = _PCH_FP1(i);
  6827. }
  6828. }
  6829. static void intel_crtc_init(struct drm_device *dev, int pipe)
  6830. {
  6831. drm_i915_private_t *dev_priv = dev->dev_private;
  6832. struct intel_crtc *intel_crtc;
  6833. int i;
  6834. intel_crtc = kzalloc(sizeof(struct intel_crtc) + (INTELFB_CONN_LIMIT * sizeof(struct drm_connector *)), GFP_KERNEL);
  6835. if (intel_crtc == NULL)
  6836. return;
  6837. drm_crtc_init(dev, &intel_crtc->base, &intel_crtc_funcs);
  6838. drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256);
  6839. for (i = 0; i < 256; i++) {
  6840. intel_crtc->lut_r[i] = i;
  6841. intel_crtc->lut_g[i] = i;
  6842. intel_crtc->lut_b[i] = i;
  6843. }
  6844. /* Swap pipes & planes for FBC on pre-965 */
  6845. intel_crtc->pipe = pipe;
  6846. intel_crtc->plane = pipe;
  6847. intel_crtc->cpu_transcoder = pipe;
  6848. if (IS_MOBILE(dev) && IS_GEN3(dev)) {
  6849. DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
  6850. intel_crtc->plane = !pipe;
  6851. }
  6852. BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
  6853. dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL);
  6854. dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base;
  6855. dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base;
  6856. intel_crtc->bpp = 24; /* default for pre-Ironlake */
  6857. drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
  6858. }
  6859. int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data,
  6860. struct drm_file *file)
  6861. {
  6862. struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
  6863. struct drm_mode_object *drmmode_obj;
  6864. struct intel_crtc *crtc;
  6865. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  6866. return -ENODEV;
  6867. drmmode_obj = drm_mode_object_find(dev, pipe_from_crtc_id->crtc_id,
  6868. DRM_MODE_OBJECT_CRTC);
  6869. if (!drmmode_obj) {
  6870. DRM_ERROR("no such CRTC id\n");
  6871. return -EINVAL;
  6872. }
  6873. crtc = to_intel_crtc(obj_to_crtc(drmmode_obj));
  6874. pipe_from_crtc_id->pipe = crtc->pipe;
  6875. return 0;
  6876. }
  6877. static int intel_encoder_clones(struct intel_encoder *encoder)
  6878. {
  6879. struct drm_device *dev = encoder->base.dev;
  6880. struct intel_encoder *source_encoder;
  6881. int index_mask = 0;
  6882. int entry = 0;
  6883. list_for_each_entry(source_encoder,
  6884. &dev->mode_config.encoder_list, base.head) {
  6885. if (encoder == source_encoder)
  6886. index_mask |= (1 << entry);
  6887. /* Intel hw has only one MUX where enocoders could be cloned. */
  6888. if (encoder->cloneable && source_encoder->cloneable)
  6889. index_mask |= (1 << entry);
  6890. entry++;
  6891. }
  6892. return index_mask;
  6893. }
  6894. static bool has_edp_a(struct drm_device *dev)
  6895. {
  6896. struct drm_i915_private *dev_priv = dev->dev_private;
  6897. if (!IS_MOBILE(dev))
  6898. return false;
  6899. if ((I915_READ(DP_A) & DP_DETECTED) == 0)
  6900. return false;
  6901. if (IS_GEN5(dev) &&
  6902. (I915_READ(ILK_DISPLAY_CHICKEN_FUSES) & ILK_eDP_A_DISABLE))
  6903. return false;
  6904. return true;
  6905. }
  6906. static void intel_setup_outputs(struct drm_device *dev)
  6907. {
  6908. struct drm_i915_private *dev_priv = dev->dev_private;
  6909. struct intel_encoder *encoder;
  6910. bool dpd_is_edp = false;
  6911. bool has_lvds;
  6912. has_lvds = intel_lvds_init(dev);
  6913. if (!has_lvds && !HAS_PCH_SPLIT(dev)) {
  6914. /* disable the panel fitter on everything but LVDS */
  6915. I915_WRITE(PFIT_CONTROL, 0);
  6916. }
  6917. if (!(HAS_DDI(dev) && (I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)))
  6918. intel_crt_init(dev);
  6919. if (HAS_DDI(dev)) {
  6920. int found;
  6921. /* Haswell uses DDI functions to detect digital outputs */
  6922. found = I915_READ(DDI_BUF_CTL_A) & DDI_INIT_DISPLAY_DETECTED;
  6923. /* DDI A only supports eDP */
  6924. if (found)
  6925. intel_ddi_init(dev, PORT_A);
  6926. /* DDI B, C and D detection is indicated by the SFUSE_STRAP
  6927. * register */
  6928. found = I915_READ(SFUSE_STRAP);
  6929. if (found & SFUSE_STRAP_DDIB_DETECTED)
  6930. intel_ddi_init(dev, PORT_B);
  6931. if (found & SFUSE_STRAP_DDIC_DETECTED)
  6932. intel_ddi_init(dev, PORT_C);
  6933. if (found & SFUSE_STRAP_DDID_DETECTED)
  6934. intel_ddi_init(dev, PORT_D);
  6935. } else if (HAS_PCH_SPLIT(dev)) {
  6936. int found;
  6937. dpd_is_edp = intel_dpd_is_edp(dev);
  6938. if (has_edp_a(dev))
  6939. intel_dp_init(dev, DP_A, PORT_A);
  6940. if (I915_READ(HDMIB) & PORT_DETECTED) {
  6941. /* PCH SDVOB multiplex with HDMIB */
  6942. found = intel_sdvo_init(dev, PCH_SDVOB, true);
  6943. if (!found)
  6944. intel_hdmi_init(dev, HDMIB, PORT_B);
  6945. if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
  6946. intel_dp_init(dev, PCH_DP_B, PORT_B);
  6947. }
  6948. if (I915_READ(HDMIC) & PORT_DETECTED)
  6949. intel_hdmi_init(dev, HDMIC, PORT_C);
  6950. if (!dpd_is_edp && I915_READ(HDMID) & PORT_DETECTED)
  6951. intel_hdmi_init(dev, HDMID, PORT_D);
  6952. if (I915_READ(PCH_DP_C) & DP_DETECTED)
  6953. intel_dp_init(dev, PCH_DP_C, PORT_C);
  6954. if (I915_READ(PCH_DP_D) & DP_DETECTED)
  6955. intel_dp_init(dev, PCH_DP_D, PORT_D);
  6956. } else if (IS_VALLEYVIEW(dev)) {
  6957. /* Check for built-in panel first. Shares lanes with HDMI on SDVOC */
  6958. if (I915_READ(VLV_DISPLAY_BASE + DP_C) & DP_DETECTED)
  6959. intel_dp_init(dev, VLV_DISPLAY_BASE + DP_C, PORT_C);
  6960. if (I915_READ(VLV_DISPLAY_BASE + SDVOB) & PORT_DETECTED) {
  6961. intel_hdmi_init(dev, VLV_DISPLAY_BASE + SDVOB, PORT_B);
  6962. if (I915_READ(VLV_DISPLAY_BASE + DP_B) & DP_DETECTED)
  6963. intel_dp_init(dev, VLV_DISPLAY_BASE + DP_B, PORT_B);
  6964. }
  6965. if (I915_READ(VLV_DISPLAY_BASE + SDVOC) & PORT_DETECTED)
  6966. intel_hdmi_init(dev, VLV_DISPLAY_BASE + SDVOC, PORT_C);
  6967. } else if (SUPPORTS_DIGITAL_OUTPUTS(dev)) {
  6968. bool found = false;
  6969. if (I915_READ(SDVOB) & SDVO_DETECTED) {
  6970. DRM_DEBUG_KMS("probing SDVOB\n");
  6971. found = intel_sdvo_init(dev, SDVOB, true);
  6972. if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) {
  6973. DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
  6974. intel_hdmi_init(dev, SDVOB, PORT_B);
  6975. }
  6976. if (!found && SUPPORTS_INTEGRATED_DP(dev)) {
  6977. DRM_DEBUG_KMS("probing DP_B\n");
  6978. intel_dp_init(dev, DP_B, PORT_B);
  6979. }
  6980. }
  6981. /* Before G4X SDVOC doesn't have its own detect register */
  6982. if (I915_READ(SDVOB) & SDVO_DETECTED) {
  6983. DRM_DEBUG_KMS("probing SDVOC\n");
  6984. found = intel_sdvo_init(dev, SDVOC, false);
  6985. }
  6986. if (!found && (I915_READ(SDVOC) & SDVO_DETECTED)) {
  6987. if (SUPPORTS_INTEGRATED_HDMI(dev)) {
  6988. DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
  6989. intel_hdmi_init(dev, SDVOC, PORT_C);
  6990. }
  6991. if (SUPPORTS_INTEGRATED_DP(dev)) {
  6992. DRM_DEBUG_KMS("probing DP_C\n");
  6993. intel_dp_init(dev, DP_C, PORT_C);
  6994. }
  6995. }
  6996. if (SUPPORTS_INTEGRATED_DP(dev) &&
  6997. (I915_READ(DP_D) & DP_DETECTED)) {
  6998. DRM_DEBUG_KMS("probing DP_D\n");
  6999. intel_dp_init(dev, DP_D, PORT_D);
  7000. }
  7001. } else if (IS_GEN2(dev))
  7002. intel_dvo_init(dev);
  7003. if (SUPPORTS_TV(dev))
  7004. intel_tv_init(dev);
  7005. list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) {
  7006. encoder->base.possible_crtcs = encoder->crtc_mask;
  7007. encoder->base.possible_clones =
  7008. intel_encoder_clones(encoder);
  7009. }
  7010. intel_init_pch_refclk(dev);
  7011. drm_helper_move_panel_connectors_to_head(dev);
  7012. }
  7013. static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
  7014. {
  7015. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  7016. drm_framebuffer_cleanup(fb);
  7017. drm_gem_object_unreference_unlocked(&intel_fb->obj->base);
  7018. kfree(intel_fb);
  7019. }
  7020. static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
  7021. struct drm_file *file,
  7022. unsigned int *handle)
  7023. {
  7024. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  7025. struct drm_i915_gem_object *obj = intel_fb->obj;
  7026. return drm_gem_handle_create(file, &obj->base, handle);
  7027. }
  7028. static const struct drm_framebuffer_funcs intel_fb_funcs = {
  7029. .destroy = intel_user_framebuffer_destroy,
  7030. .create_handle = intel_user_framebuffer_create_handle,
  7031. };
  7032. int intel_framebuffer_init(struct drm_device *dev,
  7033. struct intel_framebuffer *intel_fb,
  7034. struct drm_mode_fb_cmd2 *mode_cmd,
  7035. struct drm_i915_gem_object *obj)
  7036. {
  7037. int ret;
  7038. if (obj->tiling_mode == I915_TILING_Y) {
  7039. DRM_DEBUG("hardware does not support tiling Y\n");
  7040. return -EINVAL;
  7041. }
  7042. if (mode_cmd->pitches[0] & 63) {
  7043. DRM_DEBUG("pitch (%d) must be at least 64 byte aligned\n",
  7044. mode_cmd->pitches[0]);
  7045. return -EINVAL;
  7046. }
  7047. /* FIXME <= Gen4 stride limits are bit unclear */
  7048. if (mode_cmd->pitches[0] > 32768) {
  7049. DRM_DEBUG("pitch (%d) must be at less than 32768\n",
  7050. mode_cmd->pitches[0]);
  7051. return -EINVAL;
  7052. }
  7053. if (obj->tiling_mode != I915_TILING_NONE &&
  7054. mode_cmd->pitches[0] != obj->stride) {
  7055. DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n",
  7056. mode_cmd->pitches[0], obj->stride);
  7057. return -EINVAL;
  7058. }
  7059. /* Reject formats not supported by any plane early. */
  7060. switch (mode_cmd->pixel_format) {
  7061. case DRM_FORMAT_C8:
  7062. case DRM_FORMAT_RGB565:
  7063. case DRM_FORMAT_XRGB8888:
  7064. case DRM_FORMAT_ARGB8888:
  7065. break;
  7066. case DRM_FORMAT_XRGB1555:
  7067. case DRM_FORMAT_ARGB1555:
  7068. if (INTEL_INFO(dev)->gen > 3) {
  7069. DRM_DEBUG("invalid format: 0x%08x\n", mode_cmd->pixel_format);
  7070. return -EINVAL;
  7071. }
  7072. break;
  7073. case DRM_FORMAT_XBGR8888:
  7074. case DRM_FORMAT_ABGR8888:
  7075. case DRM_FORMAT_XRGB2101010:
  7076. case DRM_FORMAT_ARGB2101010:
  7077. case DRM_FORMAT_XBGR2101010:
  7078. case DRM_FORMAT_ABGR2101010:
  7079. if (INTEL_INFO(dev)->gen < 4) {
  7080. DRM_DEBUG("invalid format: 0x%08x\n", mode_cmd->pixel_format);
  7081. return -EINVAL;
  7082. }
  7083. break;
  7084. case DRM_FORMAT_YUYV:
  7085. case DRM_FORMAT_UYVY:
  7086. case DRM_FORMAT_YVYU:
  7087. case DRM_FORMAT_VYUY:
  7088. if (INTEL_INFO(dev)->gen < 5) {
  7089. DRM_DEBUG("invalid format: 0x%08x\n", mode_cmd->pixel_format);
  7090. return -EINVAL;
  7091. }
  7092. break;
  7093. default:
  7094. DRM_DEBUG("unsupported pixel format 0x%08x\n", mode_cmd->pixel_format);
  7095. return -EINVAL;
  7096. }
  7097. /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
  7098. if (mode_cmd->offsets[0] != 0)
  7099. return -EINVAL;
  7100. drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd);
  7101. intel_fb->obj = obj;
  7102. ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs);
  7103. if (ret) {
  7104. DRM_ERROR("framebuffer init failed %d\n", ret);
  7105. return ret;
  7106. }
  7107. return 0;
  7108. }
  7109. static struct drm_framebuffer *
  7110. intel_user_framebuffer_create(struct drm_device *dev,
  7111. struct drm_file *filp,
  7112. struct drm_mode_fb_cmd2 *mode_cmd)
  7113. {
  7114. struct drm_i915_gem_object *obj;
  7115. obj = to_intel_bo(drm_gem_object_lookup(dev, filp,
  7116. mode_cmd->handles[0]));
  7117. if (&obj->base == NULL)
  7118. return ERR_PTR(-ENOENT);
  7119. return intel_framebuffer_create(dev, mode_cmd, obj);
  7120. }
  7121. static const struct drm_mode_config_funcs intel_mode_funcs = {
  7122. .fb_create = intel_user_framebuffer_create,
  7123. .output_poll_changed = intel_fb_output_poll_changed,
  7124. };
  7125. /* Set up chip specific display functions */
  7126. static void intel_init_display(struct drm_device *dev)
  7127. {
  7128. struct drm_i915_private *dev_priv = dev->dev_private;
  7129. /* We always want a DPMS function */
  7130. if (HAS_DDI(dev)) {
  7131. dev_priv->display.crtc_mode_set = haswell_crtc_mode_set;
  7132. dev_priv->display.crtc_enable = haswell_crtc_enable;
  7133. dev_priv->display.crtc_disable = haswell_crtc_disable;
  7134. dev_priv->display.off = haswell_crtc_off;
  7135. dev_priv->display.update_plane = ironlake_update_plane;
  7136. } else if (HAS_PCH_SPLIT(dev)) {
  7137. dev_priv->display.crtc_mode_set = ironlake_crtc_mode_set;
  7138. dev_priv->display.crtc_enable = ironlake_crtc_enable;
  7139. dev_priv->display.crtc_disable = ironlake_crtc_disable;
  7140. dev_priv->display.off = ironlake_crtc_off;
  7141. dev_priv->display.update_plane = ironlake_update_plane;
  7142. } else {
  7143. dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set;
  7144. dev_priv->display.crtc_enable = i9xx_crtc_enable;
  7145. dev_priv->display.crtc_disable = i9xx_crtc_disable;
  7146. dev_priv->display.off = i9xx_crtc_off;
  7147. dev_priv->display.update_plane = i9xx_update_plane;
  7148. }
  7149. /* Returns the core display clock speed */
  7150. if (IS_VALLEYVIEW(dev))
  7151. dev_priv->display.get_display_clock_speed =
  7152. valleyview_get_display_clock_speed;
  7153. else if (IS_I945G(dev) || (IS_G33(dev) && !IS_PINEVIEW_M(dev)))
  7154. dev_priv->display.get_display_clock_speed =
  7155. i945_get_display_clock_speed;
  7156. else if (IS_I915G(dev))
  7157. dev_priv->display.get_display_clock_speed =
  7158. i915_get_display_clock_speed;
  7159. else if (IS_I945GM(dev) || IS_845G(dev) || IS_PINEVIEW_M(dev))
  7160. dev_priv->display.get_display_clock_speed =
  7161. i9xx_misc_get_display_clock_speed;
  7162. else if (IS_I915GM(dev))
  7163. dev_priv->display.get_display_clock_speed =
  7164. i915gm_get_display_clock_speed;
  7165. else if (IS_I865G(dev))
  7166. dev_priv->display.get_display_clock_speed =
  7167. i865_get_display_clock_speed;
  7168. else if (IS_I85X(dev))
  7169. dev_priv->display.get_display_clock_speed =
  7170. i855_get_display_clock_speed;
  7171. else /* 852, 830 */
  7172. dev_priv->display.get_display_clock_speed =
  7173. i830_get_display_clock_speed;
  7174. if (HAS_PCH_SPLIT(dev)) {
  7175. if (IS_GEN5(dev)) {
  7176. dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
  7177. dev_priv->display.write_eld = ironlake_write_eld;
  7178. } else if (IS_GEN6(dev)) {
  7179. dev_priv->display.fdi_link_train = gen6_fdi_link_train;
  7180. dev_priv->display.write_eld = ironlake_write_eld;
  7181. } else if (IS_IVYBRIDGE(dev)) {
  7182. /* FIXME: detect B0+ stepping and use auto training */
  7183. dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
  7184. dev_priv->display.write_eld = ironlake_write_eld;
  7185. dev_priv->display.modeset_global_resources =
  7186. ivb_modeset_global_resources;
  7187. } else if (IS_HASWELL(dev)) {
  7188. dev_priv->display.fdi_link_train = hsw_fdi_link_train;
  7189. dev_priv->display.write_eld = haswell_write_eld;
  7190. dev_priv->display.modeset_global_resources =
  7191. haswell_modeset_global_resources;
  7192. }
  7193. } else if (IS_G4X(dev)) {
  7194. dev_priv->display.write_eld = g4x_write_eld;
  7195. }
  7196. /* Default just returns -ENODEV to indicate unsupported */
  7197. dev_priv->display.queue_flip = intel_default_queue_flip;
  7198. switch (INTEL_INFO(dev)->gen) {
  7199. case 2:
  7200. dev_priv->display.queue_flip = intel_gen2_queue_flip;
  7201. break;
  7202. case 3:
  7203. dev_priv->display.queue_flip = intel_gen3_queue_flip;
  7204. break;
  7205. case 4:
  7206. case 5:
  7207. dev_priv->display.queue_flip = intel_gen4_queue_flip;
  7208. break;
  7209. case 6:
  7210. dev_priv->display.queue_flip = intel_gen6_queue_flip;
  7211. break;
  7212. case 7:
  7213. dev_priv->display.queue_flip = intel_gen7_queue_flip;
  7214. break;
  7215. }
  7216. }
  7217. /*
  7218. * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend,
  7219. * resume, or other times. This quirk makes sure that's the case for
  7220. * affected systems.
  7221. */
  7222. static void quirk_pipea_force(struct drm_device *dev)
  7223. {
  7224. struct drm_i915_private *dev_priv = dev->dev_private;
  7225. dev_priv->quirks |= QUIRK_PIPEA_FORCE;
  7226. DRM_INFO("applying pipe a force quirk\n");
  7227. }
  7228. /*
  7229. * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
  7230. */
  7231. static void quirk_ssc_force_disable(struct drm_device *dev)
  7232. {
  7233. struct drm_i915_private *dev_priv = dev->dev_private;
  7234. dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE;
  7235. DRM_INFO("applying lvds SSC disable quirk\n");
  7236. }
  7237. /*
  7238. * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
  7239. * brightness value
  7240. */
  7241. static void quirk_invert_brightness(struct drm_device *dev)
  7242. {
  7243. struct drm_i915_private *dev_priv = dev->dev_private;
  7244. dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS;
  7245. DRM_INFO("applying inverted panel brightness quirk\n");
  7246. }
  7247. struct intel_quirk {
  7248. int device;
  7249. int subsystem_vendor;
  7250. int subsystem_device;
  7251. void (*hook)(struct drm_device *dev);
  7252. };
  7253. /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
  7254. struct intel_dmi_quirk {
  7255. void (*hook)(struct drm_device *dev);
  7256. const struct dmi_system_id (*dmi_id_list)[];
  7257. };
  7258. static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
  7259. {
  7260. DRM_INFO("Backlight polarity reversed on %s\n", id->ident);
  7261. return 1;
  7262. }
  7263. static const struct intel_dmi_quirk intel_dmi_quirks[] = {
  7264. {
  7265. .dmi_id_list = &(const struct dmi_system_id[]) {
  7266. {
  7267. .callback = intel_dmi_reverse_brightness,
  7268. .ident = "NCR Corporation",
  7269. .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
  7270. DMI_MATCH(DMI_PRODUCT_NAME, ""),
  7271. },
  7272. },
  7273. { } /* terminating entry */
  7274. },
  7275. .hook = quirk_invert_brightness,
  7276. },
  7277. };
  7278. static struct intel_quirk intel_quirks[] = {
  7279. /* HP Mini needs pipe A force quirk (LP: #322104) */
  7280. { 0x27ae, 0x103c, 0x361a, quirk_pipea_force },
  7281. /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
  7282. { 0x2592, 0x1179, 0x0001, quirk_pipea_force },
  7283. /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
  7284. { 0x2782, 0x17aa, 0x201a, quirk_pipea_force },
  7285. /* 830/845 need to leave pipe A & dpll A up */
  7286. { 0x2562, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force },
  7287. { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force },
  7288. /* Lenovo U160 cannot use SSC on LVDS */
  7289. { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable },
  7290. /* Sony Vaio Y cannot use SSC on LVDS */
  7291. { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable },
  7292. /* Acer Aspire 5734Z must invert backlight brightness */
  7293. { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness },
  7294. /* Acer/eMachines G725 */
  7295. { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness },
  7296. /* Acer/eMachines e725 */
  7297. { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness },
  7298. /* Acer/Packard Bell NCL20 */
  7299. { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness },
  7300. };
  7301. static void intel_init_quirks(struct drm_device *dev)
  7302. {
  7303. struct pci_dev *d = dev->pdev;
  7304. int i;
  7305. for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) {
  7306. struct intel_quirk *q = &intel_quirks[i];
  7307. if (d->device == q->device &&
  7308. (d->subsystem_vendor == q->subsystem_vendor ||
  7309. q->subsystem_vendor == PCI_ANY_ID) &&
  7310. (d->subsystem_device == q->subsystem_device ||
  7311. q->subsystem_device == PCI_ANY_ID))
  7312. q->hook(dev);
  7313. }
  7314. for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) {
  7315. if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0)
  7316. intel_dmi_quirks[i].hook(dev);
  7317. }
  7318. }
  7319. /* Disable the VGA plane that we never use */
  7320. static void i915_disable_vga(struct drm_device *dev)
  7321. {
  7322. struct drm_i915_private *dev_priv = dev->dev_private;
  7323. u8 sr1;
  7324. u32 vga_reg = i915_vgacntrl_reg(dev);
  7325. vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
  7326. outb(SR01, VGA_SR_INDEX);
  7327. sr1 = inb(VGA_SR_DATA);
  7328. outb(sr1 | 1<<5, VGA_SR_DATA);
  7329. vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
  7330. udelay(300);
  7331. I915_WRITE(vga_reg, VGA_DISP_DISABLE);
  7332. POSTING_READ(vga_reg);
  7333. }
  7334. void intel_modeset_init_hw(struct drm_device *dev)
  7335. {
  7336. intel_init_power_well(dev);
  7337. intel_prepare_ddi(dev);
  7338. intel_init_clock_gating(dev);
  7339. mutex_lock(&dev->struct_mutex);
  7340. intel_enable_gt_powersave(dev);
  7341. mutex_unlock(&dev->struct_mutex);
  7342. }
  7343. void intel_modeset_init(struct drm_device *dev)
  7344. {
  7345. struct drm_i915_private *dev_priv = dev->dev_private;
  7346. int i, ret;
  7347. drm_mode_config_init(dev);
  7348. dev->mode_config.min_width = 0;
  7349. dev->mode_config.min_height = 0;
  7350. dev->mode_config.preferred_depth = 24;
  7351. dev->mode_config.prefer_shadow = 1;
  7352. dev->mode_config.funcs = &intel_mode_funcs;
  7353. intel_init_quirks(dev);
  7354. intel_init_pm(dev);
  7355. intel_init_display(dev);
  7356. if (IS_GEN2(dev)) {
  7357. dev->mode_config.max_width = 2048;
  7358. dev->mode_config.max_height = 2048;
  7359. } else if (IS_GEN3(dev)) {
  7360. dev->mode_config.max_width = 4096;
  7361. dev->mode_config.max_height = 4096;
  7362. } else {
  7363. dev->mode_config.max_width = 8192;
  7364. dev->mode_config.max_height = 8192;
  7365. }
  7366. dev->mode_config.fb_base = dev_priv->gtt.mappable_base;
  7367. DRM_DEBUG_KMS("%d display pipe%s available.\n",
  7368. dev_priv->num_pipe, dev_priv->num_pipe > 1 ? "s" : "");
  7369. for (i = 0; i < dev_priv->num_pipe; i++) {
  7370. intel_crtc_init(dev, i);
  7371. ret = intel_plane_init(dev, i);
  7372. if (ret)
  7373. DRM_DEBUG_KMS("plane %d init failed: %d\n", i, ret);
  7374. }
  7375. intel_cpu_pll_init(dev);
  7376. intel_pch_pll_init(dev);
  7377. /* Just disable it once at startup */
  7378. i915_disable_vga(dev);
  7379. intel_setup_outputs(dev);
  7380. /* Just in case the BIOS is doing something questionable. */
  7381. intel_disable_fbc(dev);
  7382. }
  7383. static void
  7384. intel_connector_break_all_links(struct intel_connector *connector)
  7385. {
  7386. connector->base.dpms = DRM_MODE_DPMS_OFF;
  7387. connector->base.encoder = NULL;
  7388. connector->encoder->connectors_active = false;
  7389. connector->encoder->base.crtc = NULL;
  7390. }
  7391. static void intel_enable_pipe_a(struct drm_device *dev)
  7392. {
  7393. struct intel_connector *connector;
  7394. struct drm_connector *crt = NULL;
  7395. struct intel_load_detect_pipe load_detect_temp;
  7396. /* We can't just switch on the pipe A, we need to set things up with a
  7397. * proper mode and output configuration. As a gross hack, enable pipe A
  7398. * by enabling the load detect pipe once. */
  7399. list_for_each_entry(connector,
  7400. &dev->mode_config.connector_list,
  7401. base.head) {
  7402. if (connector->encoder->type == INTEL_OUTPUT_ANALOG) {
  7403. crt = &connector->base;
  7404. break;
  7405. }
  7406. }
  7407. if (!crt)
  7408. return;
  7409. if (intel_get_load_detect_pipe(crt, NULL, &load_detect_temp))
  7410. intel_release_load_detect_pipe(crt, &load_detect_temp);
  7411. }
  7412. static bool
  7413. intel_check_plane_mapping(struct intel_crtc *crtc)
  7414. {
  7415. struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
  7416. u32 reg, val;
  7417. if (dev_priv->num_pipe == 1)
  7418. return true;
  7419. reg = DSPCNTR(!crtc->plane);
  7420. val = I915_READ(reg);
  7421. if ((val & DISPLAY_PLANE_ENABLE) &&
  7422. (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe))
  7423. return false;
  7424. return true;
  7425. }
  7426. static void intel_sanitize_crtc(struct intel_crtc *crtc)
  7427. {
  7428. struct drm_device *dev = crtc->base.dev;
  7429. struct drm_i915_private *dev_priv = dev->dev_private;
  7430. u32 reg;
  7431. /* Clear any frame start delays used for debugging left by the BIOS */
  7432. reg = PIPECONF(crtc->cpu_transcoder);
  7433. I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
  7434. /* We need to sanitize the plane -> pipe mapping first because this will
  7435. * disable the crtc (and hence change the state) if it is wrong. Note
  7436. * that gen4+ has a fixed plane -> pipe mapping. */
  7437. if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) {
  7438. struct intel_connector *connector;
  7439. bool plane;
  7440. DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n",
  7441. crtc->base.base.id);
  7442. /* Pipe has the wrong plane attached and the plane is active.
  7443. * Temporarily change the plane mapping and disable everything
  7444. * ... */
  7445. plane = crtc->plane;
  7446. crtc->plane = !plane;
  7447. dev_priv->display.crtc_disable(&crtc->base);
  7448. crtc->plane = plane;
  7449. /* ... and break all links. */
  7450. list_for_each_entry(connector, &dev->mode_config.connector_list,
  7451. base.head) {
  7452. if (connector->encoder->base.crtc != &crtc->base)
  7453. continue;
  7454. intel_connector_break_all_links(connector);
  7455. }
  7456. WARN_ON(crtc->active);
  7457. crtc->base.enabled = false;
  7458. }
  7459. if (dev_priv->quirks & QUIRK_PIPEA_FORCE &&
  7460. crtc->pipe == PIPE_A && !crtc->active) {
  7461. /* BIOS forgot to enable pipe A, this mostly happens after
  7462. * resume. Force-enable the pipe to fix this, the update_dpms
  7463. * call below we restore the pipe to the right state, but leave
  7464. * the required bits on. */
  7465. intel_enable_pipe_a(dev);
  7466. }
  7467. /* Adjust the state of the output pipe according to whether we
  7468. * have active connectors/encoders. */
  7469. intel_crtc_update_dpms(&crtc->base);
  7470. if (crtc->active != crtc->base.enabled) {
  7471. struct intel_encoder *encoder;
  7472. /* This can happen either due to bugs in the get_hw_state
  7473. * functions or because the pipe is force-enabled due to the
  7474. * pipe A quirk. */
  7475. DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n",
  7476. crtc->base.base.id,
  7477. crtc->base.enabled ? "enabled" : "disabled",
  7478. crtc->active ? "enabled" : "disabled");
  7479. crtc->base.enabled = crtc->active;
  7480. /* Because we only establish the connector -> encoder ->
  7481. * crtc links if something is active, this means the
  7482. * crtc is now deactivated. Break the links. connector
  7483. * -> encoder links are only establish when things are
  7484. * actually up, hence no need to break them. */
  7485. WARN_ON(crtc->active);
  7486. for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
  7487. WARN_ON(encoder->connectors_active);
  7488. encoder->base.crtc = NULL;
  7489. }
  7490. }
  7491. }
  7492. static void intel_sanitize_encoder(struct intel_encoder *encoder)
  7493. {
  7494. struct intel_connector *connector;
  7495. struct drm_device *dev = encoder->base.dev;
  7496. /* We need to check both for a crtc link (meaning that the
  7497. * encoder is active and trying to read from a pipe) and the
  7498. * pipe itself being active. */
  7499. bool has_active_crtc = encoder->base.crtc &&
  7500. to_intel_crtc(encoder->base.crtc)->active;
  7501. if (encoder->connectors_active && !has_active_crtc) {
  7502. DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
  7503. encoder->base.base.id,
  7504. drm_get_encoder_name(&encoder->base));
  7505. /* Connector is active, but has no active pipe. This is
  7506. * fallout from our resume register restoring. Disable
  7507. * the encoder manually again. */
  7508. if (encoder->base.crtc) {
  7509. DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
  7510. encoder->base.base.id,
  7511. drm_get_encoder_name(&encoder->base));
  7512. encoder->disable(encoder);
  7513. }
  7514. /* Inconsistent output/port/pipe state happens presumably due to
  7515. * a bug in one of the get_hw_state functions. Or someplace else
  7516. * in our code, like the register restore mess on resume. Clamp
  7517. * things to off as a safer default. */
  7518. list_for_each_entry(connector,
  7519. &dev->mode_config.connector_list,
  7520. base.head) {
  7521. if (connector->encoder != encoder)
  7522. continue;
  7523. intel_connector_break_all_links(connector);
  7524. }
  7525. }
  7526. /* Enabled encoders without active connectors will be fixed in
  7527. * the crtc fixup. */
  7528. }
  7529. void i915_redisable_vga(struct drm_device *dev)
  7530. {
  7531. struct drm_i915_private *dev_priv = dev->dev_private;
  7532. u32 vga_reg = i915_vgacntrl_reg(dev);
  7533. if (I915_READ(vga_reg) != VGA_DISP_DISABLE) {
  7534. DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
  7535. i915_disable_vga(dev);
  7536. }
  7537. }
  7538. /* Scan out the current hw modeset state, sanitizes it and maps it into the drm
  7539. * and i915 state tracking structures. */
  7540. void intel_modeset_setup_hw_state(struct drm_device *dev,
  7541. bool force_restore)
  7542. {
  7543. struct drm_i915_private *dev_priv = dev->dev_private;
  7544. enum pipe pipe;
  7545. u32 tmp;
  7546. struct intel_crtc *crtc;
  7547. struct intel_encoder *encoder;
  7548. struct intel_connector *connector;
  7549. if (HAS_DDI(dev)) {
  7550. tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
  7551. if (tmp & TRANS_DDI_FUNC_ENABLE) {
  7552. switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
  7553. case TRANS_DDI_EDP_INPUT_A_ON:
  7554. case TRANS_DDI_EDP_INPUT_A_ONOFF:
  7555. pipe = PIPE_A;
  7556. break;
  7557. case TRANS_DDI_EDP_INPUT_B_ONOFF:
  7558. pipe = PIPE_B;
  7559. break;
  7560. case TRANS_DDI_EDP_INPUT_C_ONOFF:
  7561. pipe = PIPE_C;
  7562. break;
  7563. }
  7564. crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  7565. crtc->cpu_transcoder = TRANSCODER_EDP;
  7566. DRM_DEBUG_KMS("Pipe %c using transcoder EDP\n",
  7567. pipe_name(pipe));
  7568. }
  7569. }
  7570. for_each_pipe(pipe) {
  7571. crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  7572. tmp = I915_READ(PIPECONF(crtc->cpu_transcoder));
  7573. if (tmp & PIPECONF_ENABLE)
  7574. crtc->active = true;
  7575. else
  7576. crtc->active = false;
  7577. crtc->base.enabled = crtc->active;
  7578. DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n",
  7579. crtc->base.base.id,
  7580. crtc->active ? "enabled" : "disabled");
  7581. }
  7582. if (HAS_DDI(dev))
  7583. intel_ddi_setup_hw_pll_state(dev);
  7584. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  7585. base.head) {
  7586. pipe = 0;
  7587. if (encoder->get_hw_state(encoder, &pipe)) {
  7588. encoder->base.crtc =
  7589. dev_priv->pipe_to_crtc_mapping[pipe];
  7590. } else {
  7591. encoder->base.crtc = NULL;
  7592. }
  7593. encoder->connectors_active = false;
  7594. DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe=%i\n",
  7595. encoder->base.base.id,
  7596. drm_get_encoder_name(&encoder->base),
  7597. encoder->base.crtc ? "enabled" : "disabled",
  7598. pipe);
  7599. }
  7600. list_for_each_entry(connector, &dev->mode_config.connector_list,
  7601. base.head) {
  7602. if (connector->get_hw_state(connector)) {
  7603. connector->base.dpms = DRM_MODE_DPMS_ON;
  7604. connector->encoder->connectors_active = true;
  7605. connector->base.encoder = &connector->encoder->base;
  7606. } else {
  7607. connector->base.dpms = DRM_MODE_DPMS_OFF;
  7608. connector->base.encoder = NULL;
  7609. }
  7610. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
  7611. connector->base.base.id,
  7612. drm_get_connector_name(&connector->base),
  7613. connector->base.encoder ? "enabled" : "disabled");
  7614. }
  7615. /* HW state is read out, now we need to sanitize this mess. */
  7616. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  7617. base.head) {
  7618. intel_sanitize_encoder(encoder);
  7619. }
  7620. for_each_pipe(pipe) {
  7621. crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  7622. intel_sanitize_crtc(crtc);
  7623. }
  7624. if (force_restore) {
  7625. for_each_pipe(pipe) {
  7626. intel_crtc_restore_mode(dev_priv->pipe_to_crtc_mapping[pipe]);
  7627. }
  7628. i915_redisable_vga(dev);
  7629. } else {
  7630. intel_modeset_update_staged_output_state(dev);
  7631. }
  7632. intel_modeset_check_state(dev);
  7633. drm_mode_config_reset(dev);
  7634. }
  7635. void intel_modeset_gem_init(struct drm_device *dev)
  7636. {
  7637. intel_modeset_init_hw(dev);
  7638. intel_setup_overlay(dev);
  7639. intel_modeset_setup_hw_state(dev, false);
  7640. }
  7641. void intel_modeset_cleanup(struct drm_device *dev)
  7642. {
  7643. struct drm_i915_private *dev_priv = dev->dev_private;
  7644. struct drm_crtc *crtc;
  7645. struct intel_crtc *intel_crtc;
  7646. drm_kms_helper_poll_fini(dev);
  7647. mutex_lock(&dev->struct_mutex);
  7648. intel_unregister_dsm_handler();
  7649. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  7650. /* Skip inactive CRTCs */
  7651. if (!crtc->fb)
  7652. continue;
  7653. intel_crtc = to_intel_crtc(crtc);
  7654. intel_increase_pllclock(crtc);
  7655. }
  7656. intel_disable_fbc(dev);
  7657. intel_disable_gt_powersave(dev);
  7658. ironlake_teardown_rc6(dev);
  7659. if (IS_VALLEYVIEW(dev))
  7660. vlv_init_dpio(dev);
  7661. mutex_unlock(&dev->struct_mutex);
  7662. /* Disable the irq before mode object teardown, for the irq might
  7663. * enqueue unpin/hotplug work. */
  7664. drm_irq_uninstall(dev);
  7665. cancel_work_sync(&dev_priv->hotplug_work);
  7666. cancel_work_sync(&dev_priv->rps.work);
  7667. /* flush any delayed tasks or pending work */
  7668. flush_scheduled_work();
  7669. drm_mode_config_cleanup(dev);
  7670. intel_cleanup_overlay(dev);
  7671. }
  7672. /*
  7673. * Return which encoder is currently attached for connector.
  7674. */
  7675. struct drm_encoder *intel_best_encoder(struct drm_connector *connector)
  7676. {
  7677. return &intel_attached_encoder(connector)->base;
  7678. }
  7679. void intel_connector_attach_encoder(struct intel_connector *connector,
  7680. struct intel_encoder *encoder)
  7681. {
  7682. connector->encoder = encoder;
  7683. drm_mode_connector_attach_encoder(&connector->base,
  7684. &encoder->base);
  7685. }
  7686. /*
  7687. * set vga decode state - true == enable VGA decode
  7688. */
  7689. int intel_modeset_vga_set_state(struct drm_device *dev, bool state)
  7690. {
  7691. struct drm_i915_private *dev_priv = dev->dev_private;
  7692. u16 gmch_ctrl;
  7693. pci_read_config_word(dev_priv->bridge_dev, INTEL_GMCH_CTRL, &gmch_ctrl);
  7694. if (state)
  7695. gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
  7696. else
  7697. gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
  7698. pci_write_config_word(dev_priv->bridge_dev, INTEL_GMCH_CTRL, gmch_ctrl);
  7699. return 0;
  7700. }
  7701. #ifdef CONFIG_DEBUG_FS
  7702. #include <linux/seq_file.h>
  7703. struct intel_display_error_state {
  7704. struct intel_cursor_error_state {
  7705. u32 control;
  7706. u32 position;
  7707. u32 base;
  7708. u32 size;
  7709. } cursor[I915_MAX_PIPES];
  7710. struct intel_pipe_error_state {
  7711. u32 conf;
  7712. u32 source;
  7713. u32 htotal;
  7714. u32 hblank;
  7715. u32 hsync;
  7716. u32 vtotal;
  7717. u32 vblank;
  7718. u32 vsync;
  7719. } pipe[I915_MAX_PIPES];
  7720. struct intel_plane_error_state {
  7721. u32 control;
  7722. u32 stride;
  7723. u32 size;
  7724. u32 pos;
  7725. u32 addr;
  7726. u32 surface;
  7727. u32 tile_offset;
  7728. } plane[I915_MAX_PIPES];
  7729. };
  7730. struct intel_display_error_state *
  7731. intel_display_capture_error_state(struct drm_device *dev)
  7732. {
  7733. drm_i915_private_t *dev_priv = dev->dev_private;
  7734. struct intel_display_error_state *error;
  7735. enum transcoder cpu_transcoder;
  7736. int i;
  7737. error = kmalloc(sizeof(*error), GFP_ATOMIC);
  7738. if (error == NULL)
  7739. return NULL;
  7740. for_each_pipe(i) {
  7741. cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, i);
  7742. error->cursor[i].control = I915_READ(CURCNTR(i));
  7743. error->cursor[i].position = I915_READ(CURPOS(i));
  7744. error->cursor[i].base = I915_READ(CURBASE(i));
  7745. error->plane[i].control = I915_READ(DSPCNTR(i));
  7746. error->plane[i].stride = I915_READ(DSPSTRIDE(i));
  7747. error->plane[i].size = I915_READ(DSPSIZE(i));
  7748. error->plane[i].pos = I915_READ(DSPPOS(i));
  7749. error->plane[i].addr = I915_READ(DSPADDR(i));
  7750. if (INTEL_INFO(dev)->gen >= 4) {
  7751. error->plane[i].surface = I915_READ(DSPSURF(i));
  7752. error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
  7753. }
  7754. error->pipe[i].conf = I915_READ(PIPECONF(cpu_transcoder));
  7755. error->pipe[i].source = I915_READ(PIPESRC(i));
  7756. error->pipe[i].htotal = I915_READ(HTOTAL(cpu_transcoder));
  7757. error->pipe[i].hblank = I915_READ(HBLANK(cpu_transcoder));
  7758. error->pipe[i].hsync = I915_READ(HSYNC(cpu_transcoder));
  7759. error->pipe[i].vtotal = I915_READ(VTOTAL(cpu_transcoder));
  7760. error->pipe[i].vblank = I915_READ(VBLANK(cpu_transcoder));
  7761. error->pipe[i].vsync = I915_READ(VSYNC(cpu_transcoder));
  7762. }
  7763. return error;
  7764. }
  7765. void
  7766. intel_display_print_error_state(struct seq_file *m,
  7767. struct drm_device *dev,
  7768. struct intel_display_error_state *error)
  7769. {
  7770. drm_i915_private_t *dev_priv = dev->dev_private;
  7771. int i;
  7772. seq_printf(m, "Num Pipes: %d\n", dev_priv->num_pipe);
  7773. for_each_pipe(i) {
  7774. seq_printf(m, "Pipe [%d]:\n", i);
  7775. seq_printf(m, " CONF: %08x\n", error->pipe[i].conf);
  7776. seq_printf(m, " SRC: %08x\n", error->pipe[i].source);
  7777. seq_printf(m, " HTOTAL: %08x\n", error->pipe[i].htotal);
  7778. seq_printf(m, " HBLANK: %08x\n", error->pipe[i].hblank);
  7779. seq_printf(m, " HSYNC: %08x\n", error->pipe[i].hsync);
  7780. seq_printf(m, " VTOTAL: %08x\n", error->pipe[i].vtotal);
  7781. seq_printf(m, " VBLANK: %08x\n", error->pipe[i].vblank);
  7782. seq_printf(m, " VSYNC: %08x\n", error->pipe[i].vsync);
  7783. seq_printf(m, "Plane [%d]:\n", i);
  7784. seq_printf(m, " CNTR: %08x\n", error->plane[i].control);
  7785. seq_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
  7786. seq_printf(m, " SIZE: %08x\n", error->plane[i].size);
  7787. seq_printf(m, " POS: %08x\n", error->plane[i].pos);
  7788. seq_printf(m, " ADDR: %08x\n", error->plane[i].addr);
  7789. if (INTEL_INFO(dev)->gen >= 4) {
  7790. seq_printf(m, " SURF: %08x\n", error->plane[i].surface);
  7791. seq_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
  7792. }
  7793. seq_printf(m, "Cursor [%d]:\n", i);
  7794. seq_printf(m, " CNTR: %08x\n", error->cursor[i].control);
  7795. seq_printf(m, " POS: %08x\n", error->cursor[i].position);
  7796. seq_printf(m, " BASE: %08x\n", error->cursor[i].base);
  7797. }
  7798. }
  7799. #endif