intel_display.c 213 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651
  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/module.h>
  27. #include <linux/input.h>
  28. #include <linux/i2c.h>
  29. #include <linux/kernel.h>
  30. #include <linux/slab.h>
  31. #include <linux/vgaarb.h>
  32. #include "drmP.h"
  33. #include "intel_drv.h"
  34. #include "i915_drm.h"
  35. #include "i915_drv.h"
  36. #include "i915_trace.h"
  37. #include "drm_dp_helper.h"
  38. #include "drm_crtc_helper.h"
  39. #define HAS_eDP (intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))
  40. bool intel_pipe_has_type (struct drm_crtc *crtc, int type);
  41. static void intel_update_watermarks(struct drm_device *dev);
  42. static void intel_increase_pllclock(struct drm_crtc *crtc);
  43. static void intel_crtc_update_cursor(struct drm_crtc *crtc, bool on);
  44. typedef struct {
  45. /* given values */
  46. int n;
  47. int m1, m2;
  48. int p1, p2;
  49. /* derived values */
  50. int dot;
  51. int vco;
  52. int m;
  53. int p;
  54. } intel_clock_t;
  55. typedef struct {
  56. int min, max;
  57. } intel_range_t;
  58. typedef struct {
  59. int dot_limit;
  60. int p2_slow, p2_fast;
  61. } intel_p2_t;
  62. #define INTEL_P2_NUM 2
  63. typedef struct intel_limit intel_limit_t;
  64. struct intel_limit {
  65. intel_range_t dot, vco, n, m, m1, m2, p, p1;
  66. intel_p2_t p2;
  67. bool (* find_pll)(const intel_limit_t *, struct drm_crtc *,
  68. int, int, intel_clock_t *);
  69. };
  70. #define I8XX_DOT_MIN 25000
  71. #define I8XX_DOT_MAX 350000
  72. #define I8XX_VCO_MIN 930000
  73. #define I8XX_VCO_MAX 1400000
  74. #define I8XX_N_MIN 3
  75. #define I8XX_N_MAX 16
  76. #define I8XX_M_MIN 96
  77. #define I8XX_M_MAX 140
  78. #define I8XX_M1_MIN 18
  79. #define I8XX_M1_MAX 26
  80. #define I8XX_M2_MIN 6
  81. #define I8XX_M2_MAX 16
  82. #define I8XX_P_MIN 4
  83. #define I8XX_P_MAX 128
  84. #define I8XX_P1_MIN 2
  85. #define I8XX_P1_MAX 33
  86. #define I8XX_P1_LVDS_MIN 1
  87. #define I8XX_P1_LVDS_MAX 6
  88. #define I8XX_P2_SLOW 4
  89. #define I8XX_P2_FAST 2
  90. #define I8XX_P2_LVDS_SLOW 14
  91. #define I8XX_P2_LVDS_FAST 7
  92. #define I8XX_P2_SLOW_LIMIT 165000
  93. #define I9XX_DOT_MIN 20000
  94. #define I9XX_DOT_MAX 400000
  95. #define I9XX_VCO_MIN 1400000
  96. #define I9XX_VCO_MAX 2800000
  97. #define PINEVIEW_VCO_MIN 1700000
  98. #define PINEVIEW_VCO_MAX 3500000
  99. #define I9XX_N_MIN 1
  100. #define I9XX_N_MAX 6
  101. /* Pineview's Ncounter is a ring counter */
  102. #define PINEVIEW_N_MIN 3
  103. #define PINEVIEW_N_MAX 6
  104. #define I9XX_M_MIN 70
  105. #define I9XX_M_MAX 120
  106. #define PINEVIEW_M_MIN 2
  107. #define PINEVIEW_M_MAX 256
  108. #define I9XX_M1_MIN 10
  109. #define I9XX_M1_MAX 22
  110. #define I9XX_M2_MIN 5
  111. #define I9XX_M2_MAX 9
  112. /* Pineview M1 is reserved, and must be 0 */
  113. #define PINEVIEW_M1_MIN 0
  114. #define PINEVIEW_M1_MAX 0
  115. #define PINEVIEW_M2_MIN 0
  116. #define PINEVIEW_M2_MAX 254
  117. #define I9XX_P_SDVO_DAC_MIN 5
  118. #define I9XX_P_SDVO_DAC_MAX 80
  119. #define I9XX_P_LVDS_MIN 7
  120. #define I9XX_P_LVDS_MAX 98
  121. #define PINEVIEW_P_LVDS_MIN 7
  122. #define PINEVIEW_P_LVDS_MAX 112
  123. #define I9XX_P1_MIN 1
  124. #define I9XX_P1_MAX 8
  125. #define I9XX_P2_SDVO_DAC_SLOW 10
  126. #define I9XX_P2_SDVO_DAC_FAST 5
  127. #define I9XX_P2_SDVO_DAC_SLOW_LIMIT 200000
  128. #define I9XX_P2_LVDS_SLOW 14
  129. #define I9XX_P2_LVDS_FAST 7
  130. #define I9XX_P2_LVDS_SLOW_LIMIT 112000
  131. /*The parameter is for SDVO on G4x platform*/
  132. #define G4X_DOT_SDVO_MIN 25000
  133. #define G4X_DOT_SDVO_MAX 270000
  134. #define G4X_VCO_MIN 1750000
  135. #define G4X_VCO_MAX 3500000
  136. #define G4X_N_SDVO_MIN 1
  137. #define G4X_N_SDVO_MAX 4
  138. #define G4X_M_SDVO_MIN 104
  139. #define G4X_M_SDVO_MAX 138
  140. #define G4X_M1_SDVO_MIN 17
  141. #define G4X_M1_SDVO_MAX 23
  142. #define G4X_M2_SDVO_MIN 5
  143. #define G4X_M2_SDVO_MAX 11
  144. #define G4X_P_SDVO_MIN 10
  145. #define G4X_P_SDVO_MAX 30
  146. #define G4X_P1_SDVO_MIN 1
  147. #define G4X_P1_SDVO_MAX 3
  148. #define G4X_P2_SDVO_SLOW 10
  149. #define G4X_P2_SDVO_FAST 10
  150. #define G4X_P2_SDVO_LIMIT 270000
  151. /*The parameter is for HDMI_DAC on G4x platform*/
  152. #define G4X_DOT_HDMI_DAC_MIN 22000
  153. #define G4X_DOT_HDMI_DAC_MAX 400000
  154. #define G4X_N_HDMI_DAC_MIN 1
  155. #define G4X_N_HDMI_DAC_MAX 4
  156. #define G4X_M_HDMI_DAC_MIN 104
  157. #define G4X_M_HDMI_DAC_MAX 138
  158. #define G4X_M1_HDMI_DAC_MIN 16
  159. #define G4X_M1_HDMI_DAC_MAX 23
  160. #define G4X_M2_HDMI_DAC_MIN 5
  161. #define G4X_M2_HDMI_DAC_MAX 11
  162. #define G4X_P_HDMI_DAC_MIN 5
  163. #define G4X_P_HDMI_DAC_MAX 80
  164. #define G4X_P1_HDMI_DAC_MIN 1
  165. #define G4X_P1_HDMI_DAC_MAX 8
  166. #define G4X_P2_HDMI_DAC_SLOW 10
  167. #define G4X_P2_HDMI_DAC_FAST 5
  168. #define G4X_P2_HDMI_DAC_LIMIT 165000
  169. /*The parameter is for SINGLE_CHANNEL_LVDS on G4x platform*/
  170. #define G4X_DOT_SINGLE_CHANNEL_LVDS_MIN 20000
  171. #define G4X_DOT_SINGLE_CHANNEL_LVDS_MAX 115000
  172. #define G4X_N_SINGLE_CHANNEL_LVDS_MIN 1
  173. #define G4X_N_SINGLE_CHANNEL_LVDS_MAX 3
  174. #define G4X_M_SINGLE_CHANNEL_LVDS_MIN 104
  175. #define G4X_M_SINGLE_CHANNEL_LVDS_MAX 138
  176. #define G4X_M1_SINGLE_CHANNEL_LVDS_MIN 17
  177. #define G4X_M1_SINGLE_CHANNEL_LVDS_MAX 23
  178. #define G4X_M2_SINGLE_CHANNEL_LVDS_MIN 5
  179. #define G4X_M2_SINGLE_CHANNEL_LVDS_MAX 11
  180. #define G4X_P_SINGLE_CHANNEL_LVDS_MIN 28
  181. #define G4X_P_SINGLE_CHANNEL_LVDS_MAX 112
  182. #define G4X_P1_SINGLE_CHANNEL_LVDS_MIN 2
  183. #define G4X_P1_SINGLE_CHANNEL_LVDS_MAX 8
  184. #define G4X_P2_SINGLE_CHANNEL_LVDS_SLOW 14
  185. #define G4X_P2_SINGLE_CHANNEL_LVDS_FAST 14
  186. #define G4X_P2_SINGLE_CHANNEL_LVDS_LIMIT 0
  187. /*The parameter is for DUAL_CHANNEL_LVDS on G4x platform*/
  188. #define G4X_DOT_DUAL_CHANNEL_LVDS_MIN 80000
  189. #define G4X_DOT_DUAL_CHANNEL_LVDS_MAX 224000
  190. #define G4X_N_DUAL_CHANNEL_LVDS_MIN 1
  191. #define G4X_N_DUAL_CHANNEL_LVDS_MAX 3
  192. #define G4X_M_DUAL_CHANNEL_LVDS_MIN 104
  193. #define G4X_M_DUAL_CHANNEL_LVDS_MAX 138
  194. #define G4X_M1_DUAL_CHANNEL_LVDS_MIN 17
  195. #define G4X_M1_DUAL_CHANNEL_LVDS_MAX 23
  196. #define G4X_M2_DUAL_CHANNEL_LVDS_MIN 5
  197. #define G4X_M2_DUAL_CHANNEL_LVDS_MAX 11
  198. #define G4X_P_DUAL_CHANNEL_LVDS_MIN 14
  199. #define G4X_P_DUAL_CHANNEL_LVDS_MAX 42
  200. #define G4X_P1_DUAL_CHANNEL_LVDS_MIN 2
  201. #define G4X_P1_DUAL_CHANNEL_LVDS_MAX 6
  202. #define G4X_P2_DUAL_CHANNEL_LVDS_SLOW 7
  203. #define G4X_P2_DUAL_CHANNEL_LVDS_FAST 7
  204. #define G4X_P2_DUAL_CHANNEL_LVDS_LIMIT 0
  205. /*The parameter is for DISPLAY PORT on G4x platform*/
  206. #define G4X_DOT_DISPLAY_PORT_MIN 161670
  207. #define G4X_DOT_DISPLAY_PORT_MAX 227000
  208. #define G4X_N_DISPLAY_PORT_MIN 1
  209. #define G4X_N_DISPLAY_PORT_MAX 2
  210. #define G4X_M_DISPLAY_PORT_MIN 97
  211. #define G4X_M_DISPLAY_PORT_MAX 108
  212. #define G4X_M1_DISPLAY_PORT_MIN 0x10
  213. #define G4X_M1_DISPLAY_PORT_MAX 0x12
  214. #define G4X_M2_DISPLAY_PORT_MIN 0x05
  215. #define G4X_M2_DISPLAY_PORT_MAX 0x06
  216. #define G4X_P_DISPLAY_PORT_MIN 10
  217. #define G4X_P_DISPLAY_PORT_MAX 20
  218. #define G4X_P1_DISPLAY_PORT_MIN 1
  219. #define G4X_P1_DISPLAY_PORT_MAX 2
  220. #define G4X_P2_DISPLAY_PORT_SLOW 10
  221. #define G4X_P2_DISPLAY_PORT_FAST 10
  222. #define G4X_P2_DISPLAY_PORT_LIMIT 0
  223. /* Ironlake / Sandybridge */
  224. /* as we calculate clock using (register_value + 2) for
  225. N/M1/M2, so here the range value for them is (actual_value-2).
  226. */
  227. #define IRONLAKE_DOT_MIN 25000
  228. #define IRONLAKE_DOT_MAX 350000
  229. #define IRONLAKE_VCO_MIN 1760000
  230. #define IRONLAKE_VCO_MAX 3510000
  231. #define IRONLAKE_M1_MIN 12
  232. #define IRONLAKE_M1_MAX 22
  233. #define IRONLAKE_M2_MIN 5
  234. #define IRONLAKE_M2_MAX 9
  235. #define IRONLAKE_P2_DOT_LIMIT 225000 /* 225Mhz */
  236. /* We have parameter ranges for different type of outputs. */
  237. /* DAC & HDMI Refclk 120Mhz */
  238. #define IRONLAKE_DAC_N_MIN 1
  239. #define IRONLAKE_DAC_N_MAX 5
  240. #define IRONLAKE_DAC_M_MIN 79
  241. #define IRONLAKE_DAC_M_MAX 127
  242. #define IRONLAKE_DAC_P_MIN 5
  243. #define IRONLAKE_DAC_P_MAX 80
  244. #define IRONLAKE_DAC_P1_MIN 1
  245. #define IRONLAKE_DAC_P1_MAX 8
  246. #define IRONLAKE_DAC_P2_SLOW 10
  247. #define IRONLAKE_DAC_P2_FAST 5
  248. /* LVDS single-channel 120Mhz refclk */
  249. #define IRONLAKE_LVDS_S_N_MIN 1
  250. #define IRONLAKE_LVDS_S_N_MAX 3
  251. #define IRONLAKE_LVDS_S_M_MIN 79
  252. #define IRONLAKE_LVDS_S_M_MAX 118
  253. #define IRONLAKE_LVDS_S_P_MIN 28
  254. #define IRONLAKE_LVDS_S_P_MAX 112
  255. #define IRONLAKE_LVDS_S_P1_MIN 2
  256. #define IRONLAKE_LVDS_S_P1_MAX 8
  257. #define IRONLAKE_LVDS_S_P2_SLOW 14
  258. #define IRONLAKE_LVDS_S_P2_FAST 14
  259. /* LVDS dual-channel 120Mhz refclk */
  260. #define IRONLAKE_LVDS_D_N_MIN 1
  261. #define IRONLAKE_LVDS_D_N_MAX 3
  262. #define IRONLAKE_LVDS_D_M_MIN 79
  263. #define IRONLAKE_LVDS_D_M_MAX 127
  264. #define IRONLAKE_LVDS_D_P_MIN 14
  265. #define IRONLAKE_LVDS_D_P_MAX 56
  266. #define IRONLAKE_LVDS_D_P1_MIN 2
  267. #define IRONLAKE_LVDS_D_P1_MAX 8
  268. #define IRONLAKE_LVDS_D_P2_SLOW 7
  269. #define IRONLAKE_LVDS_D_P2_FAST 7
  270. /* LVDS single-channel 100Mhz refclk */
  271. #define IRONLAKE_LVDS_S_SSC_N_MIN 1
  272. #define IRONLAKE_LVDS_S_SSC_N_MAX 2
  273. #define IRONLAKE_LVDS_S_SSC_M_MIN 79
  274. #define IRONLAKE_LVDS_S_SSC_M_MAX 126
  275. #define IRONLAKE_LVDS_S_SSC_P_MIN 28
  276. #define IRONLAKE_LVDS_S_SSC_P_MAX 112
  277. #define IRONLAKE_LVDS_S_SSC_P1_MIN 2
  278. #define IRONLAKE_LVDS_S_SSC_P1_MAX 8
  279. #define IRONLAKE_LVDS_S_SSC_P2_SLOW 14
  280. #define IRONLAKE_LVDS_S_SSC_P2_FAST 14
  281. /* LVDS dual-channel 100Mhz refclk */
  282. #define IRONLAKE_LVDS_D_SSC_N_MIN 1
  283. #define IRONLAKE_LVDS_D_SSC_N_MAX 3
  284. #define IRONLAKE_LVDS_D_SSC_M_MIN 79
  285. #define IRONLAKE_LVDS_D_SSC_M_MAX 126
  286. #define IRONLAKE_LVDS_D_SSC_P_MIN 14
  287. #define IRONLAKE_LVDS_D_SSC_P_MAX 42
  288. #define IRONLAKE_LVDS_D_SSC_P1_MIN 2
  289. #define IRONLAKE_LVDS_D_SSC_P1_MAX 6
  290. #define IRONLAKE_LVDS_D_SSC_P2_SLOW 7
  291. #define IRONLAKE_LVDS_D_SSC_P2_FAST 7
  292. /* DisplayPort */
  293. #define IRONLAKE_DP_N_MIN 1
  294. #define IRONLAKE_DP_N_MAX 2
  295. #define IRONLAKE_DP_M_MIN 81
  296. #define IRONLAKE_DP_M_MAX 90
  297. #define IRONLAKE_DP_P_MIN 10
  298. #define IRONLAKE_DP_P_MAX 20
  299. #define IRONLAKE_DP_P2_FAST 10
  300. #define IRONLAKE_DP_P2_SLOW 10
  301. #define IRONLAKE_DP_P2_LIMIT 0
  302. #define IRONLAKE_DP_P1_MIN 1
  303. #define IRONLAKE_DP_P1_MAX 2
  304. /* FDI */
  305. #define IRONLAKE_FDI_FREQ 2700000 /* in kHz for mode->clock */
  306. static bool
  307. intel_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
  308. int target, int refclk, intel_clock_t *best_clock);
  309. static bool
  310. intel_g4x_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
  311. int target, int refclk, intel_clock_t *best_clock);
  312. static bool
  313. intel_find_pll_g4x_dp(const intel_limit_t *, struct drm_crtc *crtc,
  314. int target, int refclk, intel_clock_t *best_clock);
  315. static bool
  316. intel_find_pll_ironlake_dp(const intel_limit_t *, struct drm_crtc *crtc,
  317. int target, int refclk, intel_clock_t *best_clock);
  318. static inline u32 /* units of 100MHz */
  319. intel_fdi_link_freq(struct drm_device *dev)
  320. {
  321. if (IS_GEN5(dev)) {
  322. struct drm_i915_private *dev_priv = dev->dev_private;
  323. return (I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK) + 2;
  324. } else
  325. return 27;
  326. }
  327. static const intel_limit_t intel_limits_i8xx_dvo = {
  328. .dot = { .min = I8XX_DOT_MIN, .max = I8XX_DOT_MAX },
  329. .vco = { .min = I8XX_VCO_MIN, .max = I8XX_VCO_MAX },
  330. .n = { .min = I8XX_N_MIN, .max = I8XX_N_MAX },
  331. .m = { .min = I8XX_M_MIN, .max = I8XX_M_MAX },
  332. .m1 = { .min = I8XX_M1_MIN, .max = I8XX_M1_MAX },
  333. .m2 = { .min = I8XX_M2_MIN, .max = I8XX_M2_MAX },
  334. .p = { .min = I8XX_P_MIN, .max = I8XX_P_MAX },
  335. .p1 = { .min = I8XX_P1_MIN, .max = I8XX_P1_MAX },
  336. .p2 = { .dot_limit = I8XX_P2_SLOW_LIMIT,
  337. .p2_slow = I8XX_P2_SLOW, .p2_fast = I8XX_P2_FAST },
  338. .find_pll = intel_find_best_PLL,
  339. };
  340. static const intel_limit_t intel_limits_i8xx_lvds = {
  341. .dot = { .min = I8XX_DOT_MIN, .max = I8XX_DOT_MAX },
  342. .vco = { .min = I8XX_VCO_MIN, .max = I8XX_VCO_MAX },
  343. .n = { .min = I8XX_N_MIN, .max = I8XX_N_MAX },
  344. .m = { .min = I8XX_M_MIN, .max = I8XX_M_MAX },
  345. .m1 = { .min = I8XX_M1_MIN, .max = I8XX_M1_MAX },
  346. .m2 = { .min = I8XX_M2_MIN, .max = I8XX_M2_MAX },
  347. .p = { .min = I8XX_P_MIN, .max = I8XX_P_MAX },
  348. .p1 = { .min = I8XX_P1_LVDS_MIN, .max = I8XX_P1_LVDS_MAX },
  349. .p2 = { .dot_limit = I8XX_P2_SLOW_LIMIT,
  350. .p2_slow = I8XX_P2_LVDS_SLOW, .p2_fast = I8XX_P2_LVDS_FAST },
  351. .find_pll = intel_find_best_PLL,
  352. };
  353. static const intel_limit_t intel_limits_i9xx_sdvo = {
  354. .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX },
  355. .vco = { .min = I9XX_VCO_MIN, .max = I9XX_VCO_MAX },
  356. .n = { .min = I9XX_N_MIN, .max = I9XX_N_MAX },
  357. .m = { .min = I9XX_M_MIN, .max = I9XX_M_MAX },
  358. .m1 = { .min = I9XX_M1_MIN, .max = I9XX_M1_MAX },
  359. .m2 = { .min = I9XX_M2_MIN, .max = I9XX_M2_MAX },
  360. .p = { .min = I9XX_P_SDVO_DAC_MIN, .max = I9XX_P_SDVO_DAC_MAX },
  361. .p1 = { .min = I9XX_P1_MIN, .max = I9XX_P1_MAX },
  362. .p2 = { .dot_limit = I9XX_P2_SDVO_DAC_SLOW_LIMIT,
  363. .p2_slow = I9XX_P2_SDVO_DAC_SLOW, .p2_fast = I9XX_P2_SDVO_DAC_FAST },
  364. .find_pll = intel_find_best_PLL,
  365. };
  366. static const intel_limit_t intel_limits_i9xx_lvds = {
  367. .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX },
  368. .vco = { .min = I9XX_VCO_MIN, .max = I9XX_VCO_MAX },
  369. .n = { .min = I9XX_N_MIN, .max = I9XX_N_MAX },
  370. .m = { .min = I9XX_M_MIN, .max = I9XX_M_MAX },
  371. .m1 = { .min = I9XX_M1_MIN, .max = I9XX_M1_MAX },
  372. .m2 = { .min = I9XX_M2_MIN, .max = I9XX_M2_MAX },
  373. .p = { .min = I9XX_P_LVDS_MIN, .max = I9XX_P_LVDS_MAX },
  374. .p1 = { .min = I9XX_P1_MIN, .max = I9XX_P1_MAX },
  375. /* The single-channel range is 25-112Mhz, and dual-channel
  376. * is 80-224Mhz. Prefer single channel as much as possible.
  377. */
  378. .p2 = { .dot_limit = I9XX_P2_LVDS_SLOW_LIMIT,
  379. .p2_slow = I9XX_P2_LVDS_SLOW, .p2_fast = I9XX_P2_LVDS_FAST },
  380. .find_pll = intel_find_best_PLL,
  381. };
  382. /* below parameter and function is for G4X Chipset Family*/
  383. static const intel_limit_t intel_limits_g4x_sdvo = {
  384. .dot = { .min = G4X_DOT_SDVO_MIN, .max = G4X_DOT_SDVO_MAX },
  385. .vco = { .min = G4X_VCO_MIN, .max = G4X_VCO_MAX},
  386. .n = { .min = G4X_N_SDVO_MIN, .max = G4X_N_SDVO_MAX },
  387. .m = { .min = G4X_M_SDVO_MIN, .max = G4X_M_SDVO_MAX },
  388. .m1 = { .min = G4X_M1_SDVO_MIN, .max = G4X_M1_SDVO_MAX },
  389. .m2 = { .min = G4X_M2_SDVO_MIN, .max = G4X_M2_SDVO_MAX },
  390. .p = { .min = G4X_P_SDVO_MIN, .max = G4X_P_SDVO_MAX },
  391. .p1 = { .min = G4X_P1_SDVO_MIN, .max = G4X_P1_SDVO_MAX},
  392. .p2 = { .dot_limit = G4X_P2_SDVO_LIMIT,
  393. .p2_slow = G4X_P2_SDVO_SLOW,
  394. .p2_fast = G4X_P2_SDVO_FAST
  395. },
  396. .find_pll = intel_g4x_find_best_PLL,
  397. };
  398. static const intel_limit_t intel_limits_g4x_hdmi = {
  399. .dot = { .min = G4X_DOT_HDMI_DAC_MIN, .max = G4X_DOT_HDMI_DAC_MAX },
  400. .vco = { .min = G4X_VCO_MIN, .max = G4X_VCO_MAX},
  401. .n = { .min = G4X_N_HDMI_DAC_MIN, .max = G4X_N_HDMI_DAC_MAX },
  402. .m = { .min = G4X_M_HDMI_DAC_MIN, .max = G4X_M_HDMI_DAC_MAX },
  403. .m1 = { .min = G4X_M1_HDMI_DAC_MIN, .max = G4X_M1_HDMI_DAC_MAX },
  404. .m2 = { .min = G4X_M2_HDMI_DAC_MIN, .max = G4X_M2_HDMI_DAC_MAX },
  405. .p = { .min = G4X_P_HDMI_DAC_MIN, .max = G4X_P_HDMI_DAC_MAX },
  406. .p1 = { .min = G4X_P1_HDMI_DAC_MIN, .max = G4X_P1_HDMI_DAC_MAX},
  407. .p2 = { .dot_limit = G4X_P2_HDMI_DAC_LIMIT,
  408. .p2_slow = G4X_P2_HDMI_DAC_SLOW,
  409. .p2_fast = G4X_P2_HDMI_DAC_FAST
  410. },
  411. .find_pll = intel_g4x_find_best_PLL,
  412. };
  413. static const intel_limit_t intel_limits_g4x_single_channel_lvds = {
  414. .dot = { .min = G4X_DOT_SINGLE_CHANNEL_LVDS_MIN,
  415. .max = G4X_DOT_SINGLE_CHANNEL_LVDS_MAX },
  416. .vco = { .min = G4X_VCO_MIN,
  417. .max = G4X_VCO_MAX },
  418. .n = { .min = G4X_N_SINGLE_CHANNEL_LVDS_MIN,
  419. .max = G4X_N_SINGLE_CHANNEL_LVDS_MAX },
  420. .m = { .min = G4X_M_SINGLE_CHANNEL_LVDS_MIN,
  421. .max = G4X_M_SINGLE_CHANNEL_LVDS_MAX },
  422. .m1 = { .min = G4X_M1_SINGLE_CHANNEL_LVDS_MIN,
  423. .max = G4X_M1_SINGLE_CHANNEL_LVDS_MAX },
  424. .m2 = { .min = G4X_M2_SINGLE_CHANNEL_LVDS_MIN,
  425. .max = G4X_M2_SINGLE_CHANNEL_LVDS_MAX },
  426. .p = { .min = G4X_P_SINGLE_CHANNEL_LVDS_MIN,
  427. .max = G4X_P_SINGLE_CHANNEL_LVDS_MAX },
  428. .p1 = { .min = G4X_P1_SINGLE_CHANNEL_LVDS_MIN,
  429. .max = G4X_P1_SINGLE_CHANNEL_LVDS_MAX },
  430. .p2 = { .dot_limit = G4X_P2_SINGLE_CHANNEL_LVDS_LIMIT,
  431. .p2_slow = G4X_P2_SINGLE_CHANNEL_LVDS_SLOW,
  432. .p2_fast = G4X_P2_SINGLE_CHANNEL_LVDS_FAST
  433. },
  434. .find_pll = intel_g4x_find_best_PLL,
  435. };
  436. static const intel_limit_t intel_limits_g4x_dual_channel_lvds = {
  437. .dot = { .min = G4X_DOT_DUAL_CHANNEL_LVDS_MIN,
  438. .max = G4X_DOT_DUAL_CHANNEL_LVDS_MAX },
  439. .vco = { .min = G4X_VCO_MIN,
  440. .max = G4X_VCO_MAX },
  441. .n = { .min = G4X_N_DUAL_CHANNEL_LVDS_MIN,
  442. .max = G4X_N_DUAL_CHANNEL_LVDS_MAX },
  443. .m = { .min = G4X_M_DUAL_CHANNEL_LVDS_MIN,
  444. .max = G4X_M_DUAL_CHANNEL_LVDS_MAX },
  445. .m1 = { .min = G4X_M1_DUAL_CHANNEL_LVDS_MIN,
  446. .max = G4X_M1_DUAL_CHANNEL_LVDS_MAX },
  447. .m2 = { .min = G4X_M2_DUAL_CHANNEL_LVDS_MIN,
  448. .max = G4X_M2_DUAL_CHANNEL_LVDS_MAX },
  449. .p = { .min = G4X_P_DUAL_CHANNEL_LVDS_MIN,
  450. .max = G4X_P_DUAL_CHANNEL_LVDS_MAX },
  451. .p1 = { .min = G4X_P1_DUAL_CHANNEL_LVDS_MIN,
  452. .max = G4X_P1_DUAL_CHANNEL_LVDS_MAX },
  453. .p2 = { .dot_limit = G4X_P2_DUAL_CHANNEL_LVDS_LIMIT,
  454. .p2_slow = G4X_P2_DUAL_CHANNEL_LVDS_SLOW,
  455. .p2_fast = G4X_P2_DUAL_CHANNEL_LVDS_FAST
  456. },
  457. .find_pll = intel_g4x_find_best_PLL,
  458. };
  459. static const intel_limit_t intel_limits_g4x_display_port = {
  460. .dot = { .min = G4X_DOT_DISPLAY_PORT_MIN,
  461. .max = G4X_DOT_DISPLAY_PORT_MAX },
  462. .vco = { .min = G4X_VCO_MIN,
  463. .max = G4X_VCO_MAX},
  464. .n = { .min = G4X_N_DISPLAY_PORT_MIN,
  465. .max = G4X_N_DISPLAY_PORT_MAX },
  466. .m = { .min = G4X_M_DISPLAY_PORT_MIN,
  467. .max = G4X_M_DISPLAY_PORT_MAX },
  468. .m1 = { .min = G4X_M1_DISPLAY_PORT_MIN,
  469. .max = G4X_M1_DISPLAY_PORT_MAX },
  470. .m2 = { .min = G4X_M2_DISPLAY_PORT_MIN,
  471. .max = G4X_M2_DISPLAY_PORT_MAX },
  472. .p = { .min = G4X_P_DISPLAY_PORT_MIN,
  473. .max = G4X_P_DISPLAY_PORT_MAX },
  474. .p1 = { .min = G4X_P1_DISPLAY_PORT_MIN,
  475. .max = G4X_P1_DISPLAY_PORT_MAX},
  476. .p2 = { .dot_limit = G4X_P2_DISPLAY_PORT_LIMIT,
  477. .p2_slow = G4X_P2_DISPLAY_PORT_SLOW,
  478. .p2_fast = G4X_P2_DISPLAY_PORT_FAST },
  479. .find_pll = intel_find_pll_g4x_dp,
  480. };
  481. static const intel_limit_t intel_limits_pineview_sdvo = {
  482. .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX},
  483. .vco = { .min = PINEVIEW_VCO_MIN, .max = PINEVIEW_VCO_MAX },
  484. .n = { .min = PINEVIEW_N_MIN, .max = PINEVIEW_N_MAX },
  485. .m = { .min = PINEVIEW_M_MIN, .max = PINEVIEW_M_MAX },
  486. .m1 = { .min = PINEVIEW_M1_MIN, .max = PINEVIEW_M1_MAX },
  487. .m2 = { .min = PINEVIEW_M2_MIN, .max = PINEVIEW_M2_MAX },
  488. .p = { .min = I9XX_P_SDVO_DAC_MIN, .max = I9XX_P_SDVO_DAC_MAX },
  489. .p1 = { .min = I9XX_P1_MIN, .max = I9XX_P1_MAX },
  490. .p2 = { .dot_limit = I9XX_P2_SDVO_DAC_SLOW_LIMIT,
  491. .p2_slow = I9XX_P2_SDVO_DAC_SLOW, .p2_fast = I9XX_P2_SDVO_DAC_FAST },
  492. .find_pll = intel_find_best_PLL,
  493. };
  494. static const intel_limit_t intel_limits_pineview_lvds = {
  495. .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX },
  496. .vco = { .min = PINEVIEW_VCO_MIN, .max = PINEVIEW_VCO_MAX },
  497. .n = { .min = PINEVIEW_N_MIN, .max = PINEVIEW_N_MAX },
  498. .m = { .min = PINEVIEW_M_MIN, .max = PINEVIEW_M_MAX },
  499. .m1 = { .min = PINEVIEW_M1_MIN, .max = PINEVIEW_M1_MAX },
  500. .m2 = { .min = PINEVIEW_M2_MIN, .max = PINEVIEW_M2_MAX },
  501. .p = { .min = PINEVIEW_P_LVDS_MIN, .max = PINEVIEW_P_LVDS_MAX },
  502. .p1 = { .min = I9XX_P1_MIN, .max = I9XX_P1_MAX },
  503. /* Pineview only supports single-channel mode. */
  504. .p2 = { .dot_limit = I9XX_P2_LVDS_SLOW_LIMIT,
  505. .p2_slow = I9XX_P2_LVDS_SLOW, .p2_fast = I9XX_P2_LVDS_SLOW },
  506. .find_pll = intel_find_best_PLL,
  507. };
  508. static const intel_limit_t intel_limits_ironlake_dac = {
  509. .dot = { .min = IRONLAKE_DOT_MIN, .max = IRONLAKE_DOT_MAX },
  510. .vco = { .min = IRONLAKE_VCO_MIN, .max = IRONLAKE_VCO_MAX },
  511. .n = { .min = IRONLAKE_DAC_N_MIN, .max = IRONLAKE_DAC_N_MAX },
  512. .m = { .min = IRONLAKE_DAC_M_MIN, .max = IRONLAKE_DAC_M_MAX },
  513. .m1 = { .min = IRONLAKE_M1_MIN, .max = IRONLAKE_M1_MAX },
  514. .m2 = { .min = IRONLAKE_M2_MIN, .max = IRONLAKE_M2_MAX },
  515. .p = { .min = IRONLAKE_DAC_P_MIN, .max = IRONLAKE_DAC_P_MAX },
  516. .p1 = { .min = IRONLAKE_DAC_P1_MIN, .max = IRONLAKE_DAC_P1_MAX },
  517. .p2 = { .dot_limit = IRONLAKE_P2_DOT_LIMIT,
  518. .p2_slow = IRONLAKE_DAC_P2_SLOW,
  519. .p2_fast = IRONLAKE_DAC_P2_FAST },
  520. .find_pll = intel_g4x_find_best_PLL,
  521. };
  522. static const intel_limit_t intel_limits_ironlake_single_lvds = {
  523. .dot = { .min = IRONLAKE_DOT_MIN, .max = IRONLAKE_DOT_MAX },
  524. .vco = { .min = IRONLAKE_VCO_MIN, .max = IRONLAKE_VCO_MAX },
  525. .n = { .min = IRONLAKE_LVDS_S_N_MIN, .max = IRONLAKE_LVDS_S_N_MAX },
  526. .m = { .min = IRONLAKE_LVDS_S_M_MIN, .max = IRONLAKE_LVDS_S_M_MAX },
  527. .m1 = { .min = IRONLAKE_M1_MIN, .max = IRONLAKE_M1_MAX },
  528. .m2 = { .min = IRONLAKE_M2_MIN, .max = IRONLAKE_M2_MAX },
  529. .p = { .min = IRONLAKE_LVDS_S_P_MIN, .max = IRONLAKE_LVDS_S_P_MAX },
  530. .p1 = { .min = IRONLAKE_LVDS_S_P1_MIN, .max = IRONLAKE_LVDS_S_P1_MAX },
  531. .p2 = { .dot_limit = IRONLAKE_P2_DOT_LIMIT,
  532. .p2_slow = IRONLAKE_LVDS_S_P2_SLOW,
  533. .p2_fast = IRONLAKE_LVDS_S_P2_FAST },
  534. .find_pll = intel_g4x_find_best_PLL,
  535. };
  536. static const intel_limit_t intel_limits_ironlake_dual_lvds = {
  537. .dot = { .min = IRONLAKE_DOT_MIN, .max = IRONLAKE_DOT_MAX },
  538. .vco = { .min = IRONLAKE_VCO_MIN, .max = IRONLAKE_VCO_MAX },
  539. .n = { .min = IRONLAKE_LVDS_D_N_MIN, .max = IRONLAKE_LVDS_D_N_MAX },
  540. .m = { .min = IRONLAKE_LVDS_D_M_MIN, .max = IRONLAKE_LVDS_D_M_MAX },
  541. .m1 = { .min = IRONLAKE_M1_MIN, .max = IRONLAKE_M1_MAX },
  542. .m2 = { .min = IRONLAKE_M2_MIN, .max = IRONLAKE_M2_MAX },
  543. .p = { .min = IRONLAKE_LVDS_D_P_MIN, .max = IRONLAKE_LVDS_D_P_MAX },
  544. .p1 = { .min = IRONLAKE_LVDS_D_P1_MIN, .max = IRONLAKE_LVDS_D_P1_MAX },
  545. .p2 = { .dot_limit = IRONLAKE_P2_DOT_LIMIT,
  546. .p2_slow = IRONLAKE_LVDS_D_P2_SLOW,
  547. .p2_fast = IRONLAKE_LVDS_D_P2_FAST },
  548. .find_pll = intel_g4x_find_best_PLL,
  549. };
  550. static const intel_limit_t intel_limits_ironlake_single_lvds_100m = {
  551. .dot = { .min = IRONLAKE_DOT_MIN, .max = IRONLAKE_DOT_MAX },
  552. .vco = { .min = IRONLAKE_VCO_MIN, .max = IRONLAKE_VCO_MAX },
  553. .n = { .min = IRONLAKE_LVDS_S_SSC_N_MIN, .max = IRONLAKE_LVDS_S_SSC_N_MAX },
  554. .m = { .min = IRONLAKE_LVDS_S_SSC_M_MIN, .max = IRONLAKE_LVDS_S_SSC_M_MAX },
  555. .m1 = { .min = IRONLAKE_M1_MIN, .max = IRONLAKE_M1_MAX },
  556. .m2 = { .min = IRONLAKE_M2_MIN, .max = IRONLAKE_M2_MAX },
  557. .p = { .min = IRONLAKE_LVDS_S_SSC_P_MIN, .max = IRONLAKE_LVDS_S_SSC_P_MAX },
  558. .p1 = { .min = IRONLAKE_LVDS_S_SSC_P1_MIN,.max = IRONLAKE_LVDS_S_SSC_P1_MAX },
  559. .p2 = { .dot_limit = IRONLAKE_P2_DOT_LIMIT,
  560. .p2_slow = IRONLAKE_LVDS_S_SSC_P2_SLOW,
  561. .p2_fast = IRONLAKE_LVDS_S_SSC_P2_FAST },
  562. .find_pll = intel_g4x_find_best_PLL,
  563. };
  564. static const intel_limit_t intel_limits_ironlake_dual_lvds_100m = {
  565. .dot = { .min = IRONLAKE_DOT_MIN, .max = IRONLAKE_DOT_MAX },
  566. .vco = { .min = IRONLAKE_VCO_MIN, .max = IRONLAKE_VCO_MAX },
  567. .n = { .min = IRONLAKE_LVDS_D_SSC_N_MIN, .max = IRONLAKE_LVDS_D_SSC_N_MAX },
  568. .m = { .min = IRONLAKE_LVDS_D_SSC_M_MIN, .max = IRONLAKE_LVDS_D_SSC_M_MAX },
  569. .m1 = { .min = IRONLAKE_M1_MIN, .max = IRONLAKE_M1_MAX },
  570. .m2 = { .min = IRONLAKE_M2_MIN, .max = IRONLAKE_M2_MAX },
  571. .p = { .min = IRONLAKE_LVDS_D_SSC_P_MIN, .max = IRONLAKE_LVDS_D_SSC_P_MAX },
  572. .p1 = { .min = IRONLAKE_LVDS_D_SSC_P1_MIN,.max = IRONLAKE_LVDS_D_SSC_P1_MAX },
  573. .p2 = { .dot_limit = IRONLAKE_P2_DOT_LIMIT,
  574. .p2_slow = IRONLAKE_LVDS_D_SSC_P2_SLOW,
  575. .p2_fast = IRONLAKE_LVDS_D_SSC_P2_FAST },
  576. .find_pll = intel_g4x_find_best_PLL,
  577. };
  578. static const intel_limit_t intel_limits_ironlake_display_port = {
  579. .dot = { .min = IRONLAKE_DOT_MIN,
  580. .max = IRONLAKE_DOT_MAX },
  581. .vco = { .min = IRONLAKE_VCO_MIN,
  582. .max = IRONLAKE_VCO_MAX},
  583. .n = { .min = IRONLAKE_DP_N_MIN,
  584. .max = IRONLAKE_DP_N_MAX },
  585. .m = { .min = IRONLAKE_DP_M_MIN,
  586. .max = IRONLAKE_DP_M_MAX },
  587. .m1 = { .min = IRONLAKE_M1_MIN,
  588. .max = IRONLAKE_M1_MAX },
  589. .m2 = { .min = IRONLAKE_M2_MIN,
  590. .max = IRONLAKE_M2_MAX },
  591. .p = { .min = IRONLAKE_DP_P_MIN,
  592. .max = IRONLAKE_DP_P_MAX },
  593. .p1 = { .min = IRONLAKE_DP_P1_MIN,
  594. .max = IRONLAKE_DP_P1_MAX},
  595. .p2 = { .dot_limit = IRONLAKE_DP_P2_LIMIT,
  596. .p2_slow = IRONLAKE_DP_P2_SLOW,
  597. .p2_fast = IRONLAKE_DP_P2_FAST },
  598. .find_pll = intel_find_pll_ironlake_dp,
  599. };
  600. static const intel_limit_t *intel_ironlake_limit(struct drm_crtc *crtc,
  601. int refclk)
  602. {
  603. struct drm_device *dev = crtc->dev;
  604. struct drm_i915_private *dev_priv = dev->dev_private;
  605. const intel_limit_t *limit;
  606. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  607. if ((I915_READ(PCH_LVDS) & LVDS_CLKB_POWER_MASK) ==
  608. LVDS_CLKB_POWER_UP) {
  609. /* LVDS dual channel */
  610. if (refclk == 100000)
  611. limit = &intel_limits_ironlake_dual_lvds_100m;
  612. else
  613. limit = &intel_limits_ironlake_dual_lvds;
  614. } else {
  615. if (refclk == 100000)
  616. limit = &intel_limits_ironlake_single_lvds_100m;
  617. else
  618. limit = &intel_limits_ironlake_single_lvds;
  619. }
  620. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) ||
  621. HAS_eDP)
  622. limit = &intel_limits_ironlake_display_port;
  623. else
  624. limit = &intel_limits_ironlake_dac;
  625. return limit;
  626. }
  627. static const intel_limit_t *intel_g4x_limit(struct drm_crtc *crtc)
  628. {
  629. struct drm_device *dev = crtc->dev;
  630. struct drm_i915_private *dev_priv = dev->dev_private;
  631. const intel_limit_t *limit;
  632. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  633. if ((I915_READ(LVDS) & LVDS_CLKB_POWER_MASK) ==
  634. LVDS_CLKB_POWER_UP)
  635. /* LVDS with dual channel */
  636. limit = &intel_limits_g4x_dual_channel_lvds;
  637. else
  638. /* LVDS with dual channel */
  639. limit = &intel_limits_g4x_single_channel_lvds;
  640. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI) ||
  641. intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) {
  642. limit = &intel_limits_g4x_hdmi;
  643. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO)) {
  644. limit = &intel_limits_g4x_sdvo;
  645. } else if (intel_pipe_has_type (crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  646. limit = &intel_limits_g4x_display_port;
  647. } else /* The option is for other outputs */
  648. limit = &intel_limits_i9xx_sdvo;
  649. return limit;
  650. }
  651. static const intel_limit_t *intel_limit(struct drm_crtc *crtc, int refclk)
  652. {
  653. struct drm_device *dev = crtc->dev;
  654. const intel_limit_t *limit;
  655. if (HAS_PCH_SPLIT(dev))
  656. limit = intel_ironlake_limit(crtc, refclk);
  657. else if (IS_G4X(dev)) {
  658. limit = intel_g4x_limit(crtc);
  659. } else if (IS_PINEVIEW(dev)) {
  660. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  661. limit = &intel_limits_pineview_lvds;
  662. else
  663. limit = &intel_limits_pineview_sdvo;
  664. } else if (!IS_GEN2(dev)) {
  665. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  666. limit = &intel_limits_i9xx_lvds;
  667. else
  668. limit = &intel_limits_i9xx_sdvo;
  669. } else {
  670. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  671. limit = &intel_limits_i8xx_lvds;
  672. else
  673. limit = &intel_limits_i8xx_dvo;
  674. }
  675. return limit;
  676. }
  677. /* m1 is reserved as 0 in Pineview, n is a ring counter */
  678. static void pineview_clock(int refclk, intel_clock_t *clock)
  679. {
  680. clock->m = clock->m2 + 2;
  681. clock->p = clock->p1 * clock->p2;
  682. clock->vco = refclk * clock->m / clock->n;
  683. clock->dot = clock->vco / clock->p;
  684. }
  685. static void intel_clock(struct drm_device *dev, int refclk, intel_clock_t *clock)
  686. {
  687. if (IS_PINEVIEW(dev)) {
  688. pineview_clock(refclk, clock);
  689. return;
  690. }
  691. clock->m = 5 * (clock->m1 + 2) + (clock->m2 + 2);
  692. clock->p = clock->p1 * clock->p2;
  693. clock->vco = refclk * clock->m / (clock->n + 2);
  694. clock->dot = clock->vco / clock->p;
  695. }
  696. /**
  697. * Returns whether any output on the specified pipe is of the specified type
  698. */
  699. bool intel_pipe_has_type(struct drm_crtc *crtc, int type)
  700. {
  701. struct drm_device *dev = crtc->dev;
  702. struct drm_mode_config *mode_config = &dev->mode_config;
  703. struct intel_encoder *encoder;
  704. list_for_each_entry(encoder, &mode_config->encoder_list, base.head)
  705. if (encoder->base.crtc == crtc && encoder->type == type)
  706. return true;
  707. return false;
  708. }
  709. #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
  710. /**
  711. * Returns whether the given set of divisors are valid for a given refclk with
  712. * the given connectors.
  713. */
  714. static bool intel_PLL_is_valid(struct drm_device *dev,
  715. const intel_limit_t *limit,
  716. const intel_clock_t *clock)
  717. {
  718. if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
  719. INTELPllInvalid ("p1 out of range\n");
  720. if (clock->p < limit->p.min || limit->p.max < clock->p)
  721. INTELPllInvalid ("p out of range\n");
  722. if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
  723. INTELPllInvalid ("m2 out of range\n");
  724. if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
  725. INTELPllInvalid ("m1 out of range\n");
  726. if (clock->m1 <= clock->m2 && !IS_PINEVIEW(dev))
  727. INTELPllInvalid ("m1 <= m2\n");
  728. if (clock->m < limit->m.min || limit->m.max < clock->m)
  729. INTELPllInvalid ("m out of range\n");
  730. if (clock->n < limit->n.min || limit->n.max < clock->n)
  731. INTELPllInvalid ("n out of range\n");
  732. if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
  733. INTELPllInvalid ("vco out of range\n");
  734. /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
  735. * connector, etc., rather than just a single range.
  736. */
  737. if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
  738. INTELPllInvalid ("dot out of range\n");
  739. return true;
  740. }
  741. static bool
  742. intel_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
  743. int target, int refclk, intel_clock_t *best_clock)
  744. {
  745. struct drm_device *dev = crtc->dev;
  746. struct drm_i915_private *dev_priv = dev->dev_private;
  747. intel_clock_t clock;
  748. int err = target;
  749. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  750. (I915_READ(LVDS)) != 0) {
  751. /*
  752. * For LVDS, if the panel is on, just rely on its current
  753. * settings for dual-channel. We haven't figured out how to
  754. * reliably set up different single/dual channel state, if we
  755. * even can.
  756. */
  757. if ((I915_READ(LVDS) & LVDS_CLKB_POWER_MASK) ==
  758. LVDS_CLKB_POWER_UP)
  759. clock.p2 = limit->p2.p2_fast;
  760. else
  761. clock.p2 = limit->p2.p2_slow;
  762. } else {
  763. if (target < limit->p2.dot_limit)
  764. clock.p2 = limit->p2.p2_slow;
  765. else
  766. clock.p2 = limit->p2.p2_fast;
  767. }
  768. memset (best_clock, 0, sizeof (*best_clock));
  769. for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
  770. clock.m1++) {
  771. for (clock.m2 = limit->m2.min;
  772. clock.m2 <= limit->m2.max; clock.m2++) {
  773. /* m1 is always 0 in Pineview */
  774. if (clock.m2 >= clock.m1 && !IS_PINEVIEW(dev))
  775. break;
  776. for (clock.n = limit->n.min;
  777. clock.n <= limit->n.max; clock.n++) {
  778. for (clock.p1 = limit->p1.min;
  779. clock.p1 <= limit->p1.max; clock.p1++) {
  780. int this_err;
  781. intel_clock(dev, refclk, &clock);
  782. if (!intel_PLL_is_valid(dev, limit,
  783. &clock))
  784. continue;
  785. this_err = abs(clock.dot - target);
  786. if (this_err < err) {
  787. *best_clock = clock;
  788. err = this_err;
  789. }
  790. }
  791. }
  792. }
  793. }
  794. return (err != target);
  795. }
  796. static bool
  797. intel_g4x_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
  798. int target, int refclk, intel_clock_t *best_clock)
  799. {
  800. struct drm_device *dev = crtc->dev;
  801. struct drm_i915_private *dev_priv = dev->dev_private;
  802. intel_clock_t clock;
  803. int max_n;
  804. bool found;
  805. /* approximately equals target * 0.00585 */
  806. int err_most = (target >> 8) + (target >> 9);
  807. found = false;
  808. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  809. int lvds_reg;
  810. if (HAS_PCH_SPLIT(dev))
  811. lvds_reg = PCH_LVDS;
  812. else
  813. lvds_reg = LVDS;
  814. if ((I915_READ(lvds_reg) & LVDS_CLKB_POWER_MASK) ==
  815. LVDS_CLKB_POWER_UP)
  816. clock.p2 = limit->p2.p2_fast;
  817. else
  818. clock.p2 = limit->p2.p2_slow;
  819. } else {
  820. if (target < limit->p2.dot_limit)
  821. clock.p2 = limit->p2.p2_slow;
  822. else
  823. clock.p2 = limit->p2.p2_fast;
  824. }
  825. memset(best_clock, 0, sizeof(*best_clock));
  826. max_n = limit->n.max;
  827. /* based on hardware requirement, prefer smaller n to precision */
  828. for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
  829. /* based on hardware requirement, prefere larger m1,m2 */
  830. for (clock.m1 = limit->m1.max;
  831. clock.m1 >= limit->m1.min; clock.m1--) {
  832. for (clock.m2 = limit->m2.max;
  833. clock.m2 >= limit->m2.min; clock.m2--) {
  834. for (clock.p1 = limit->p1.max;
  835. clock.p1 >= limit->p1.min; clock.p1--) {
  836. int this_err;
  837. intel_clock(dev, refclk, &clock);
  838. if (!intel_PLL_is_valid(dev, limit,
  839. &clock))
  840. continue;
  841. this_err = abs(clock.dot - target);
  842. if (this_err < err_most) {
  843. *best_clock = clock;
  844. err_most = this_err;
  845. max_n = clock.n;
  846. found = true;
  847. }
  848. }
  849. }
  850. }
  851. }
  852. return found;
  853. }
  854. static bool
  855. intel_find_pll_ironlake_dp(const intel_limit_t *limit, struct drm_crtc *crtc,
  856. int target, int refclk, intel_clock_t *best_clock)
  857. {
  858. struct drm_device *dev = crtc->dev;
  859. intel_clock_t clock;
  860. if (target < 200000) {
  861. clock.n = 1;
  862. clock.p1 = 2;
  863. clock.p2 = 10;
  864. clock.m1 = 12;
  865. clock.m2 = 9;
  866. } else {
  867. clock.n = 2;
  868. clock.p1 = 1;
  869. clock.p2 = 10;
  870. clock.m1 = 14;
  871. clock.m2 = 8;
  872. }
  873. intel_clock(dev, refclk, &clock);
  874. memcpy(best_clock, &clock, sizeof(intel_clock_t));
  875. return true;
  876. }
  877. /* DisplayPort has only two frequencies, 162MHz and 270MHz */
  878. static bool
  879. intel_find_pll_g4x_dp(const intel_limit_t *limit, struct drm_crtc *crtc,
  880. int target, int refclk, intel_clock_t *best_clock)
  881. {
  882. intel_clock_t clock;
  883. if (target < 200000) {
  884. clock.p1 = 2;
  885. clock.p2 = 10;
  886. clock.n = 2;
  887. clock.m1 = 23;
  888. clock.m2 = 8;
  889. } else {
  890. clock.p1 = 1;
  891. clock.p2 = 10;
  892. clock.n = 1;
  893. clock.m1 = 14;
  894. clock.m2 = 2;
  895. }
  896. clock.m = 5 * (clock.m1 + 2) + (clock.m2 + 2);
  897. clock.p = (clock.p1 * clock.p2);
  898. clock.dot = 96000 * clock.m / (clock.n + 2) / clock.p;
  899. clock.vco = 0;
  900. memcpy(best_clock, &clock, sizeof(intel_clock_t));
  901. return true;
  902. }
  903. /**
  904. * intel_wait_for_vblank - wait for vblank on a given pipe
  905. * @dev: drm device
  906. * @pipe: pipe to wait for
  907. *
  908. * Wait for vblank to occur on a given pipe. Needed for various bits of
  909. * mode setting code.
  910. */
  911. void intel_wait_for_vblank(struct drm_device *dev, int pipe)
  912. {
  913. struct drm_i915_private *dev_priv = dev->dev_private;
  914. int pipestat_reg = PIPESTAT(pipe);
  915. /* Clear existing vblank status. Note this will clear any other
  916. * sticky status fields as well.
  917. *
  918. * This races with i915_driver_irq_handler() with the result
  919. * that either function could miss a vblank event. Here it is not
  920. * fatal, as we will either wait upon the next vblank interrupt or
  921. * timeout. Generally speaking intel_wait_for_vblank() is only
  922. * called during modeset at which time the GPU should be idle and
  923. * should *not* be performing page flips and thus not waiting on
  924. * vblanks...
  925. * Currently, the result of us stealing a vblank from the irq
  926. * handler is that a single frame will be skipped during swapbuffers.
  927. */
  928. I915_WRITE(pipestat_reg,
  929. I915_READ(pipestat_reg) | PIPE_VBLANK_INTERRUPT_STATUS);
  930. /* Wait for vblank interrupt bit to set */
  931. if (wait_for(I915_READ(pipestat_reg) &
  932. PIPE_VBLANK_INTERRUPT_STATUS,
  933. 50))
  934. DRM_DEBUG_KMS("vblank wait timed out\n");
  935. }
  936. /*
  937. * intel_wait_for_pipe_off - wait for pipe to turn off
  938. * @dev: drm device
  939. * @pipe: pipe to wait for
  940. *
  941. * After disabling a pipe, we can't wait for vblank in the usual way,
  942. * spinning on the vblank interrupt status bit, since we won't actually
  943. * see an interrupt when the pipe is disabled.
  944. *
  945. * On Gen4 and above:
  946. * wait for the pipe register state bit to turn off
  947. *
  948. * Otherwise:
  949. * wait for the display line value to settle (it usually
  950. * ends up stopping at the start of the next frame).
  951. *
  952. */
  953. void intel_wait_for_pipe_off(struct drm_device *dev, int pipe)
  954. {
  955. struct drm_i915_private *dev_priv = dev->dev_private;
  956. if (INTEL_INFO(dev)->gen >= 4) {
  957. int reg = PIPECONF(pipe);
  958. /* Wait for the Pipe State to go off */
  959. if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0,
  960. 100))
  961. DRM_DEBUG_KMS("pipe_off wait timed out\n");
  962. } else {
  963. u32 last_line;
  964. int reg = PIPEDSL(pipe);
  965. unsigned long timeout = jiffies + msecs_to_jiffies(100);
  966. /* Wait for the display line to settle */
  967. do {
  968. last_line = I915_READ(reg) & DSL_LINEMASK;
  969. mdelay(5);
  970. } while (((I915_READ(reg) & DSL_LINEMASK) != last_line) &&
  971. time_after(timeout, jiffies));
  972. if (time_after(jiffies, timeout))
  973. DRM_DEBUG_KMS("pipe_off wait timed out\n");
  974. }
  975. }
  976. static const char *state_string(bool enabled)
  977. {
  978. return enabled ? "on" : "off";
  979. }
  980. /* Only for pre-ILK configs */
  981. static void assert_pll(struct drm_i915_private *dev_priv,
  982. enum pipe pipe, bool state)
  983. {
  984. int reg;
  985. u32 val;
  986. bool cur_state;
  987. reg = DPLL(pipe);
  988. val = I915_READ(reg);
  989. cur_state = !!(val & DPLL_VCO_ENABLE);
  990. WARN(cur_state != state,
  991. "PLL state assertion failure (expected %s, current %s)\n",
  992. state_string(state), state_string(cur_state));
  993. }
  994. #define assert_pll_enabled(d, p) assert_pll(d, p, true)
  995. #define assert_pll_disabled(d, p) assert_pll(d, p, false)
  996. /* For ILK+ */
  997. static void assert_pch_pll(struct drm_i915_private *dev_priv,
  998. enum pipe pipe, bool state)
  999. {
  1000. int reg;
  1001. u32 val;
  1002. bool cur_state;
  1003. reg = PCH_DPLL(pipe);
  1004. val = I915_READ(reg);
  1005. cur_state = !!(val & DPLL_VCO_ENABLE);
  1006. WARN(cur_state != state,
  1007. "PCH PLL state assertion failure (expected %s, current %s)\n",
  1008. state_string(state), state_string(cur_state));
  1009. }
  1010. #define assert_pch_pll_enabled(d, p) assert_pch_pll(d, p, true)
  1011. #define assert_pch_pll_disabled(d, p) assert_pch_pll(d, p, false)
  1012. static void assert_fdi_tx(struct drm_i915_private *dev_priv,
  1013. enum pipe pipe, bool state)
  1014. {
  1015. int reg;
  1016. u32 val;
  1017. bool cur_state;
  1018. reg = FDI_TX_CTL(pipe);
  1019. val = I915_READ(reg);
  1020. cur_state = !!(val & FDI_TX_ENABLE);
  1021. WARN(cur_state != state,
  1022. "FDI TX state assertion failure (expected %s, current %s)\n",
  1023. state_string(state), state_string(cur_state));
  1024. }
  1025. #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
  1026. #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
  1027. static void assert_fdi_rx(struct drm_i915_private *dev_priv,
  1028. enum pipe pipe, bool state)
  1029. {
  1030. int reg;
  1031. u32 val;
  1032. bool cur_state;
  1033. reg = FDI_RX_CTL(pipe);
  1034. val = I915_READ(reg);
  1035. cur_state = !!(val & FDI_RX_ENABLE);
  1036. WARN(cur_state != state,
  1037. "FDI RX state assertion failure (expected %s, current %s)\n",
  1038. state_string(state), state_string(cur_state));
  1039. }
  1040. #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
  1041. #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
  1042. static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
  1043. enum pipe pipe)
  1044. {
  1045. int reg;
  1046. u32 val;
  1047. /* ILK FDI PLL is always enabled */
  1048. if (dev_priv->info->gen == 5)
  1049. return;
  1050. reg = FDI_TX_CTL(pipe);
  1051. val = I915_READ(reg);
  1052. WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n");
  1053. }
  1054. static void assert_fdi_rx_pll_enabled(struct drm_i915_private *dev_priv,
  1055. enum pipe pipe)
  1056. {
  1057. int reg;
  1058. u32 val;
  1059. reg = FDI_RX_CTL(pipe);
  1060. val = I915_READ(reg);
  1061. WARN(!(val & FDI_RX_PLL_ENABLE), "FDI RX PLL assertion failure, should be active but is disabled\n");
  1062. }
  1063. static void assert_panel_unlocked(struct drm_i915_private *dev_priv,
  1064. enum pipe pipe)
  1065. {
  1066. int pp_reg, lvds_reg;
  1067. u32 val;
  1068. enum pipe panel_pipe = PIPE_A;
  1069. bool locked = locked;
  1070. if (HAS_PCH_SPLIT(dev_priv->dev)) {
  1071. pp_reg = PCH_PP_CONTROL;
  1072. lvds_reg = PCH_LVDS;
  1073. } else {
  1074. pp_reg = PP_CONTROL;
  1075. lvds_reg = LVDS;
  1076. }
  1077. val = I915_READ(pp_reg);
  1078. if (!(val & PANEL_POWER_ON) ||
  1079. ((val & PANEL_UNLOCK_REGS) == PANEL_UNLOCK_REGS))
  1080. locked = false;
  1081. if (I915_READ(lvds_reg) & LVDS_PIPEB_SELECT)
  1082. panel_pipe = PIPE_B;
  1083. WARN(panel_pipe == pipe && locked,
  1084. "panel assertion failure, pipe %c regs locked\n",
  1085. pipe_name(pipe));
  1086. }
  1087. static void assert_pipe(struct drm_i915_private *dev_priv,
  1088. enum pipe pipe, bool state)
  1089. {
  1090. int reg;
  1091. u32 val;
  1092. bool cur_state;
  1093. reg = PIPECONF(pipe);
  1094. val = I915_READ(reg);
  1095. cur_state = !!(val & PIPECONF_ENABLE);
  1096. WARN(cur_state != state,
  1097. "pipe %c assertion failure (expected %s, current %s)\n",
  1098. pipe_name(pipe), state_string(state), state_string(cur_state));
  1099. }
  1100. #define assert_pipe_enabled(d, p) assert_pipe(d, p, true)
  1101. #define assert_pipe_disabled(d, p) assert_pipe(d, p, false)
  1102. static void assert_plane_enabled(struct drm_i915_private *dev_priv,
  1103. enum plane plane)
  1104. {
  1105. int reg;
  1106. u32 val;
  1107. reg = DSPCNTR(plane);
  1108. val = I915_READ(reg);
  1109. WARN(!(val & DISPLAY_PLANE_ENABLE),
  1110. "plane %c assertion failure, should be active but is disabled\n",
  1111. plane_name(plane));
  1112. }
  1113. static void assert_planes_disabled(struct drm_i915_private *dev_priv,
  1114. enum pipe pipe)
  1115. {
  1116. int reg, i;
  1117. u32 val;
  1118. int cur_pipe;
  1119. /* Planes are fixed to pipes on ILK+ */
  1120. if (HAS_PCH_SPLIT(dev_priv->dev))
  1121. return;
  1122. /* Need to check both planes against the pipe */
  1123. for (i = 0; i < 2; i++) {
  1124. reg = DSPCNTR(i);
  1125. val = I915_READ(reg);
  1126. cur_pipe = (val & DISPPLANE_SEL_PIPE_MASK) >>
  1127. DISPPLANE_SEL_PIPE_SHIFT;
  1128. WARN((val & DISPLAY_PLANE_ENABLE) && pipe == cur_pipe,
  1129. "plane %c assertion failure, should be off on pipe %c but is still active\n",
  1130. plane_name(i), pipe_name(pipe));
  1131. }
  1132. }
  1133. static void assert_pch_refclk_enabled(struct drm_i915_private *dev_priv)
  1134. {
  1135. u32 val;
  1136. bool enabled;
  1137. val = I915_READ(PCH_DREF_CONTROL);
  1138. enabled = !!(val & (DREF_SSC_SOURCE_MASK | DREF_NONSPREAD_SOURCE_MASK |
  1139. DREF_SUPERSPREAD_SOURCE_MASK));
  1140. WARN(!enabled, "PCH refclk assertion failure, should be active but is disabled\n");
  1141. }
  1142. static void assert_transcoder_disabled(struct drm_i915_private *dev_priv,
  1143. enum pipe pipe)
  1144. {
  1145. int reg;
  1146. u32 val;
  1147. bool enabled;
  1148. reg = TRANSCONF(pipe);
  1149. val = I915_READ(reg);
  1150. enabled = !!(val & TRANS_ENABLE);
  1151. WARN(enabled,
  1152. "transcoder assertion failed, should be off on pipe %c but is still active\n",
  1153. pipe_name(pipe));
  1154. }
  1155. static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
  1156. enum pipe pipe, int reg)
  1157. {
  1158. u32 val = I915_READ(reg);
  1159. WARN(DP_PIPE_ENABLED(val, pipe),
  1160. "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
  1161. reg, pipe_name(pipe));
  1162. }
  1163. static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
  1164. enum pipe pipe, int reg)
  1165. {
  1166. u32 val = I915_READ(reg);
  1167. WARN(HDMI_PIPE_ENABLED(val, pipe),
  1168. "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
  1169. reg, pipe_name(pipe));
  1170. }
  1171. static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
  1172. enum pipe pipe)
  1173. {
  1174. int reg;
  1175. u32 val;
  1176. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B);
  1177. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C);
  1178. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_D);
  1179. reg = PCH_ADPA;
  1180. val = I915_READ(reg);
  1181. WARN(ADPA_PIPE_ENABLED(val, pipe),
  1182. "PCH VGA enabled on transcoder %c, should be disabled\n",
  1183. pipe_name(pipe));
  1184. reg = PCH_LVDS;
  1185. val = I915_READ(reg);
  1186. WARN(LVDS_PIPE_ENABLED(val, pipe),
  1187. "PCH LVDS enabled on transcoder %c, should be disabled\n",
  1188. pipe_name(pipe));
  1189. assert_pch_hdmi_disabled(dev_priv, pipe, HDMIB);
  1190. assert_pch_hdmi_disabled(dev_priv, pipe, HDMIC);
  1191. assert_pch_hdmi_disabled(dev_priv, pipe, HDMID);
  1192. }
  1193. /**
  1194. * intel_enable_pll - enable a PLL
  1195. * @dev_priv: i915 private structure
  1196. * @pipe: pipe PLL to enable
  1197. *
  1198. * Enable @pipe's PLL so we can start pumping pixels from a plane. Check to
  1199. * make sure the PLL reg is writable first though, since the panel write
  1200. * protect mechanism may be enabled.
  1201. *
  1202. * Note! This is for pre-ILK only.
  1203. */
  1204. static void intel_enable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
  1205. {
  1206. int reg;
  1207. u32 val;
  1208. /* No really, not for ILK+ */
  1209. BUG_ON(dev_priv->info->gen >= 5);
  1210. /* PLL is protected by panel, make sure we can write it */
  1211. if (IS_MOBILE(dev_priv->dev) && !IS_I830(dev_priv->dev))
  1212. assert_panel_unlocked(dev_priv, pipe);
  1213. reg = DPLL(pipe);
  1214. val = I915_READ(reg);
  1215. val |= DPLL_VCO_ENABLE;
  1216. /* We do this three times for luck */
  1217. I915_WRITE(reg, val);
  1218. POSTING_READ(reg);
  1219. udelay(150); /* wait for warmup */
  1220. I915_WRITE(reg, val);
  1221. POSTING_READ(reg);
  1222. udelay(150); /* wait for warmup */
  1223. I915_WRITE(reg, val);
  1224. POSTING_READ(reg);
  1225. udelay(150); /* wait for warmup */
  1226. }
  1227. /**
  1228. * intel_disable_pll - disable a PLL
  1229. * @dev_priv: i915 private structure
  1230. * @pipe: pipe PLL to disable
  1231. *
  1232. * Disable the PLL for @pipe, making sure the pipe is off first.
  1233. *
  1234. * Note! This is for pre-ILK only.
  1235. */
  1236. static void intel_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
  1237. {
  1238. int reg;
  1239. u32 val;
  1240. /* Don't disable pipe A or pipe A PLLs if needed */
  1241. if (pipe == PIPE_A && (dev_priv->quirks & QUIRK_PIPEA_FORCE))
  1242. return;
  1243. /* Make sure the pipe isn't still relying on us */
  1244. assert_pipe_disabled(dev_priv, pipe);
  1245. reg = DPLL(pipe);
  1246. val = I915_READ(reg);
  1247. val &= ~DPLL_VCO_ENABLE;
  1248. I915_WRITE(reg, val);
  1249. POSTING_READ(reg);
  1250. }
  1251. /**
  1252. * intel_enable_pch_pll - enable PCH PLL
  1253. * @dev_priv: i915 private structure
  1254. * @pipe: pipe PLL to enable
  1255. *
  1256. * The PCH PLL needs to be enabled before the PCH transcoder, since it
  1257. * drives the transcoder clock.
  1258. */
  1259. static void intel_enable_pch_pll(struct drm_i915_private *dev_priv,
  1260. enum pipe pipe)
  1261. {
  1262. int reg;
  1263. u32 val;
  1264. /* PCH only available on ILK+ */
  1265. BUG_ON(dev_priv->info->gen < 5);
  1266. /* PCH refclock must be enabled first */
  1267. assert_pch_refclk_enabled(dev_priv);
  1268. reg = PCH_DPLL(pipe);
  1269. val = I915_READ(reg);
  1270. val |= DPLL_VCO_ENABLE;
  1271. I915_WRITE(reg, val);
  1272. POSTING_READ(reg);
  1273. udelay(200);
  1274. }
  1275. static void intel_disable_pch_pll(struct drm_i915_private *dev_priv,
  1276. enum pipe pipe)
  1277. {
  1278. int reg;
  1279. u32 val;
  1280. /* PCH only available on ILK+ */
  1281. BUG_ON(dev_priv->info->gen < 5);
  1282. /* Make sure transcoder isn't still depending on us */
  1283. assert_transcoder_disabled(dev_priv, pipe);
  1284. reg = PCH_DPLL(pipe);
  1285. val = I915_READ(reg);
  1286. val &= ~DPLL_VCO_ENABLE;
  1287. I915_WRITE(reg, val);
  1288. POSTING_READ(reg);
  1289. udelay(200);
  1290. }
  1291. static void intel_enable_transcoder(struct drm_i915_private *dev_priv,
  1292. enum pipe pipe)
  1293. {
  1294. int reg;
  1295. u32 val;
  1296. /* PCH only available on ILK+ */
  1297. BUG_ON(dev_priv->info->gen < 5);
  1298. /* Make sure PCH DPLL is enabled */
  1299. assert_pch_pll_enabled(dev_priv, pipe);
  1300. /* FDI must be feeding us bits for PCH ports */
  1301. assert_fdi_tx_enabled(dev_priv, pipe);
  1302. assert_fdi_rx_enabled(dev_priv, pipe);
  1303. reg = TRANSCONF(pipe);
  1304. val = I915_READ(reg);
  1305. /*
  1306. * make the BPC in transcoder be consistent with
  1307. * that in pipeconf reg.
  1308. */
  1309. val &= ~PIPE_BPC_MASK;
  1310. val |= I915_READ(PIPECONF(pipe)) & PIPE_BPC_MASK;
  1311. I915_WRITE(reg, val | TRANS_ENABLE);
  1312. if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100))
  1313. DRM_ERROR("failed to enable transcoder %d\n", pipe);
  1314. }
  1315. static void intel_disable_transcoder(struct drm_i915_private *dev_priv,
  1316. enum pipe pipe)
  1317. {
  1318. int reg;
  1319. u32 val;
  1320. /* FDI relies on the transcoder */
  1321. assert_fdi_tx_disabled(dev_priv, pipe);
  1322. assert_fdi_rx_disabled(dev_priv, pipe);
  1323. /* Ports must be off as well */
  1324. assert_pch_ports_disabled(dev_priv, pipe);
  1325. reg = TRANSCONF(pipe);
  1326. val = I915_READ(reg);
  1327. val &= ~TRANS_ENABLE;
  1328. I915_WRITE(reg, val);
  1329. /* wait for PCH transcoder off, transcoder state */
  1330. if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50))
  1331. DRM_ERROR("failed to disable transcoder\n");
  1332. }
  1333. /**
  1334. * intel_enable_pipe - enable a pipe, asserting requirements
  1335. * @dev_priv: i915 private structure
  1336. * @pipe: pipe to enable
  1337. * @pch_port: on ILK+, is this pipe driving a PCH port or not
  1338. *
  1339. * Enable @pipe, making sure that various hardware specific requirements
  1340. * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc.
  1341. *
  1342. * @pipe should be %PIPE_A or %PIPE_B.
  1343. *
  1344. * Will wait until the pipe is actually running (i.e. first vblank) before
  1345. * returning.
  1346. */
  1347. static void intel_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe,
  1348. bool pch_port)
  1349. {
  1350. int reg;
  1351. u32 val;
  1352. /*
  1353. * A pipe without a PLL won't actually be able to drive bits from
  1354. * a plane. On ILK+ the pipe PLLs are integrated, so we don't
  1355. * need the check.
  1356. */
  1357. if (!HAS_PCH_SPLIT(dev_priv->dev))
  1358. assert_pll_enabled(dev_priv, pipe);
  1359. else {
  1360. if (pch_port) {
  1361. /* if driving the PCH, we need FDI enabled */
  1362. assert_fdi_rx_pll_enabled(dev_priv, pipe);
  1363. assert_fdi_tx_pll_enabled(dev_priv, pipe);
  1364. }
  1365. /* FIXME: assert CPU port conditions for SNB+ */
  1366. }
  1367. reg = PIPECONF(pipe);
  1368. val = I915_READ(reg);
  1369. if (val & PIPECONF_ENABLE)
  1370. return;
  1371. I915_WRITE(reg, val | PIPECONF_ENABLE);
  1372. intel_wait_for_vblank(dev_priv->dev, pipe);
  1373. }
  1374. /**
  1375. * intel_disable_pipe - disable a pipe, asserting requirements
  1376. * @dev_priv: i915 private structure
  1377. * @pipe: pipe to disable
  1378. *
  1379. * Disable @pipe, making sure that various hardware specific requirements
  1380. * are met, if applicable, e.g. plane disabled, panel fitter off, etc.
  1381. *
  1382. * @pipe should be %PIPE_A or %PIPE_B.
  1383. *
  1384. * Will wait until the pipe has shut down before returning.
  1385. */
  1386. static void intel_disable_pipe(struct drm_i915_private *dev_priv,
  1387. enum pipe pipe)
  1388. {
  1389. int reg;
  1390. u32 val;
  1391. /*
  1392. * Make sure planes won't keep trying to pump pixels to us,
  1393. * or we might hang the display.
  1394. */
  1395. assert_planes_disabled(dev_priv, pipe);
  1396. /* Don't disable pipe A or pipe A PLLs if needed */
  1397. if (pipe == PIPE_A && (dev_priv->quirks & QUIRK_PIPEA_FORCE))
  1398. return;
  1399. reg = PIPECONF(pipe);
  1400. val = I915_READ(reg);
  1401. if ((val & PIPECONF_ENABLE) == 0)
  1402. return;
  1403. I915_WRITE(reg, val & ~PIPECONF_ENABLE);
  1404. intel_wait_for_pipe_off(dev_priv->dev, pipe);
  1405. }
  1406. /**
  1407. * intel_enable_plane - enable a display plane on a given pipe
  1408. * @dev_priv: i915 private structure
  1409. * @plane: plane to enable
  1410. * @pipe: pipe being fed
  1411. *
  1412. * Enable @plane on @pipe, making sure that @pipe is running first.
  1413. */
  1414. static void intel_enable_plane(struct drm_i915_private *dev_priv,
  1415. enum plane plane, enum pipe pipe)
  1416. {
  1417. int reg;
  1418. u32 val;
  1419. /* If the pipe isn't enabled, we can't pump pixels and may hang */
  1420. assert_pipe_enabled(dev_priv, pipe);
  1421. reg = DSPCNTR(plane);
  1422. val = I915_READ(reg);
  1423. if (val & DISPLAY_PLANE_ENABLE)
  1424. return;
  1425. I915_WRITE(reg, val | DISPLAY_PLANE_ENABLE);
  1426. intel_wait_for_vblank(dev_priv->dev, pipe);
  1427. }
  1428. /*
  1429. * Plane regs are double buffered, going from enabled->disabled needs a
  1430. * trigger in order to latch. The display address reg provides this.
  1431. */
  1432. static void intel_flush_display_plane(struct drm_i915_private *dev_priv,
  1433. enum plane plane)
  1434. {
  1435. u32 reg = DSPADDR(plane);
  1436. I915_WRITE(reg, I915_READ(reg));
  1437. }
  1438. /**
  1439. * intel_disable_plane - disable a display plane
  1440. * @dev_priv: i915 private structure
  1441. * @plane: plane to disable
  1442. * @pipe: pipe consuming the data
  1443. *
  1444. * Disable @plane; should be an independent operation.
  1445. */
  1446. static void intel_disable_plane(struct drm_i915_private *dev_priv,
  1447. enum plane plane, enum pipe pipe)
  1448. {
  1449. int reg;
  1450. u32 val;
  1451. reg = DSPCNTR(plane);
  1452. val = I915_READ(reg);
  1453. if ((val & DISPLAY_PLANE_ENABLE) == 0)
  1454. return;
  1455. I915_WRITE(reg, val & ~DISPLAY_PLANE_ENABLE);
  1456. intel_flush_display_plane(dev_priv, plane);
  1457. intel_wait_for_vblank(dev_priv->dev, pipe);
  1458. }
  1459. static void disable_pch_dp(struct drm_i915_private *dev_priv,
  1460. enum pipe pipe, int reg)
  1461. {
  1462. u32 val = I915_READ(reg);
  1463. if (DP_PIPE_ENABLED(val, pipe))
  1464. I915_WRITE(reg, val & ~DP_PORT_EN);
  1465. }
  1466. static void disable_pch_hdmi(struct drm_i915_private *dev_priv,
  1467. enum pipe pipe, int reg)
  1468. {
  1469. u32 val = I915_READ(reg);
  1470. if (HDMI_PIPE_ENABLED(val, pipe))
  1471. I915_WRITE(reg, val & ~PORT_ENABLE);
  1472. }
  1473. /* Disable any ports connected to this transcoder */
  1474. static void intel_disable_pch_ports(struct drm_i915_private *dev_priv,
  1475. enum pipe pipe)
  1476. {
  1477. u32 reg, val;
  1478. val = I915_READ(PCH_PP_CONTROL);
  1479. I915_WRITE(PCH_PP_CONTROL, val | PANEL_UNLOCK_REGS);
  1480. disable_pch_dp(dev_priv, pipe, PCH_DP_B);
  1481. disable_pch_dp(dev_priv, pipe, PCH_DP_C);
  1482. disable_pch_dp(dev_priv, pipe, PCH_DP_D);
  1483. reg = PCH_ADPA;
  1484. val = I915_READ(reg);
  1485. if (ADPA_PIPE_ENABLED(val, pipe))
  1486. I915_WRITE(reg, val & ~ADPA_DAC_ENABLE);
  1487. reg = PCH_LVDS;
  1488. val = I915_READ(reg);
  1489. if (LVDS_PIPE_ENABLED(val, pipe)) {
  1490. I915_WRITE(reg, val & ~LVDS_PORT_EN);
  1491. POSTING_READ(reg);
  1492. udelay(100);
  1493. }
  1494. disable_pch_hdmi(dev_priv, pipe, HDMIB);
  1495. disable_pch_hdmi(dev_priv, pipe, HDMIC);
  1496. disable_pch_hdmi(dev_priv, pipe, HDMID);
  1497. }
  1498. static void i8xx_enable_fbc(struct drm_crtc *crtc, unsigned long interval)
  1499. {
  1500. struct drm_device *dev = crtc->dev;
  1501. struct drm_i915_private *dev_priv = dev->dev_private;
  1502. struct drm_framebuffer *fb = crtc->fb;
  1503. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  1504. struct drm_i915_gem_object *obj = intel_fb->obj;
  1505. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1506. int plane, i;
  1507. u32 fbc_ctl, fbc_ctl2;
  1508. if (fb->pitch == dev_priv->cfb_pitch &&
  1509. obj->fence_reg == dev_priv->cfb_fence &&
  1510. intel_crtc->plane == dev_priv->cfb_plane &&
  1511. I915_READ(FBC_CONTROL) & FBC_CTL_EN)
  1512. return;
  1513. i8xx_disable_fbc(dev);
  1514. dev_priv->cfb_pitch = dev_priv->cfb_size / FBC_LL_SIZE;
  1515. if (fb->pitch < dev_priv->cfb_pitch)
  1516. dev_priv->cfb_pitch = fb->pitch;
  1517. /* FBC_CTL wants 64B units */
  1518. dev_priv->cfb_pitch = (dev_priv->cfb_pitch / 64) - 1;
  1519. dev_priv->cfb_fence = obj->fence_reg;
  1520. dev_priv->cfb_plane = intel_crtc->plane;
  1521. plane = dev_priv->cfb_plane == 0 ? FBC_CTL_PLANEA : FBC_CTL_PLANEB;
  1522. /* Clear old tags */
  1523. for (i = 0; i < (FBC_LL_SIZE / 32) + 1; i++)
  1524. I915_WRITE(FBC_TAG + (i * 4), 0);
  1525. /* Set it up... */
  1526. fbc_ctl2 = FBC_CTL_FENCE_DBL | FBC_CTL_IDLE_IMM | plane;
  1527. if (obj->tiling_mode != I915_TILING_NONE)
  1528. fbc_ctl2 |= FBC_CTL_CPU_FENCE;
  1529. I915_WRITE(FBC_CONTROL2, fbc_ctl2);
  1530. I915_WRITE(FBC_FENCE_OFF, crtc->y);
  1531. /* enable it... */
  1532. fbc_ctl = FBC_CTL_EN | FBC_CTL_PERIODIC;
  1533. if (IS_I945GM(dev))
  1534. fbc_ctl |= FBC_CTL_C3_IDLE; /* 945 needs special SR handling */
  1535. fbc_ctl |= (dev_priv->cfb_pitch & 0xff) << FBC_CTL_STRIDE_SHIFT;
  1536. fbc_ctl |= (interval & 0x2fff) << FBC_CTL_INTERVAL_SHIFT;
  1537. if (obj->tiling_mode != I915_TILING_NONE)
  1538. fbc_ctl |= dev_priv->cfb_fence;
  1539. I915_WRITE(FBC_CONTROL, fbc_ctl);
  1540. DRM_DEBUG_KMS("enabled FBC, pitch %ld, yoff %d, plane %d, ",
  1541. dev_priv->cfb_pitch, crtc->y, dev_priv->cfb_plane);
  1542. }
  1543. void i8xx_disable_fbc(struct drm_device *dev)
  1544. {
  1545. struct drm_i915_private *dev_priv = dev->dev_private;
  1546. u32 fbc_ctl;
  1547. /* Disable compression */
  1548. fbc_ctl = I915_READ(FBC_CONTROL);
  1549. if ((fbc_ctl & FBC_CTL_EN) == 0)
  1550. return;
  1551. fbc_ctl &= ~FBC_CTL_EN;
  1552. I915_WRITE(FBC_CONTROL, fbc_ctl);
  1553. /* Wait for compressing bit to clear */
  1554. if (wait_for((I915_READ(FBC_STATUS) & FBC_STAT_COMPRESSING) == 0, 10)) {
  1555. DRM_DEBUG_KMS("FBC idle timed out\n");
  1556. return;
  1557. }
  1558. DRM_DEBUG_KMS("disabled FBC\n");
  1559. }
  1560. static bool i8xx_fbc_enabled(struct drm_device *dev)
  1561. {
  1562. struct drm_i915_private *dev_priv = dev->dev_private;
  1563. return I915_READ(FBC_CONTROL) & FBC_CTL_EN;
  1564. }
  1565. static void g4x_enable_fbc(struct drm_crtc *crtc, unsigned long interval)
  1566. {
  1567. struct drm_device *dev = crtc->dev;
  1568. struct drm_i915_private *dev_priv = dev->dev_private;
  1569. struct drm_framebuffer *fb = crtc->fb;
  1570. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  1571. struct drm_i915_gem_object *obj = intel_fb->obj;
  1572. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1573. int plane = intel_crtc->plane == 0 ? DPFC_CTL_PLANEA : DPFC_CTL_PLANEB;
  1574. unsigned long stall_watermark = 200;
  1575. u32 dpfc_ctl;
  1576. dpfc_ctl = I915_READ(DPFC_CONTROL);
  1577. if (dpfc_ctl & DPFC_CTL_EN) {
  1578. if (dev_priv->cfb_pitch == dev_priv->cfb_pitch / 64 - 1 &&
  1579. dev_priv->cfb_fence == obj->fence_reg &&
  1580. dev_priv->cfb_plane == intel_crtc->plane &&
  1581. dev_priv->cfb_y == crtc->y)
  1582. return;
  1583. I915_WRITE(DPFC_CONTROL, dpfc_ctl & ~DPFC_CTL_EN);
  1584. intel_wait_for_vblank(dev, intel_crtc->pipe);
  1585. }
  1586. dev_priv->cfb_pitch = (dev_priv->cfb_pitch / 64) - 1;
  1587. dev_priv->cfb_fence = obj->fence_reg;
  1588. dev_priv->cfb_plane = intel_crtc->plane;
  1589. dev_priv->cfb_y = crtc->y;
  1590. dpfc_ctl = plane | DPFC_SR_EN | DPFC_CTL_LIMIT_1X;
  1591. if (obj->tiling_mode != I915_TILING_NONE) {
  1592. dpfc_ctl |= DPFC_CTL_FENCE_EN | dev_priv->cfb_fence;
  1593. I915_WRITE(DPFC_CHICKEN, DPFC_HT_MODIFY);
  1594. } else {
  1595. I915_WRITE(DPFC_CHICKEN, ~DPFC_HT_MODIFY);
  1596. }
  1597. I915_WRITE(DPFC_RECOMP_CTL, DPFC_RECOMP_STALL_EN |
  1598. (stall_watermark << DPFC_RECOMP_STALL_WM_SHIFT) |
  1599. (interval << DPFC_RECOMP_TIMER_COUNT_SHIFT));
  1600. I915_WRITE(DPFC_FENCE_YOFF, crtc->y);
  1601. /* enable it... */
  1602. I915_WRITE(DPFC_CONTROL, I915_READ(DPFC_CONTROL) | DPFC_CTL_EN);
  1603. DRM_DEBUG_KMS("enabled fbc on plane %d\n", intel_crtc->plane);
  1604. }
  1605. void g4x_disable_fbc(struct drm_device *dev)
  1606. {
  1607. struct drm_i915_private *dev_priv = dev->dev_private;
  1608. u32 dpfc_ctl;
  1609. /* Disable compression */
  1610. dpfc_ctl = I915_READ(DPFC_CONTROL);
  1611. if (dpfc_ctl & DPFC_CTL_EN) {
  1612. dpfc_ctl &= ~DPFC_CTL_EN;
  1613. I915_WRITE(DPFC_CONTROL, dpfc_ctl);
  1614. DRM_DEBUG_KMS("disabled FBC\n");
  1615. }
  1616. }
  1617. static bool g4x_fbc_enabled(struct drm_device *dev)
  1618. {
  1619. struct drm_i915_private *dev_priv = dev->dev_private;
  1620. return I915_READ(DPFC_CONTROL) & DPFC_CTL_EN;
  1621. }
  1622. static void sandybridge_blit_fbc_update(struct drm_device *dev)
  1623. {
  1624. struct drm_i915_private *dev_priv = dev->dev_private;
  1625. u32 blt_ecoskpd;
  1626. /* Make sure blitter notifies FBC of writes */
  1627. __gen6_gt_force_wake_get(dev_priv);
  1628. blt_ecoskpd = I915_READ(GEN6_BLITTER_ECOSKPD);
  1629. blt_ecoskpd |= GEN6_BLITTER_FBC_NOTIFY <<
  1630. GEN6_BLITTER_LOCK_SHIFT;
  1631. I915_WRITE(GEN6_BLITTER_ECOSKPD, blt_ecoskpd);
  1632. blt_ecoskpd |= GEN6_BLITTER_FBC_NOTIFY;
  1633. I915_WRITE(GEN6_BLITTER_ECOSKPD, blt_ecoskpd);
  1634. blt_ecoskpd &= ~(GEN6_BLITTER_FBC_NOTIFY <<
  1635. GEN6_BLITTER_LOCK_SHIFT);
  1636. I915_WRITE(GEN6_BLITTER_ECOSKPD, blt_ecoskpd);
  1637. POSTING_READ(GEN6_BLITTER_ECOSKPD);
  1638. __gen6_gt_force_wake_put(dev_priv);
  1639. }
  1640. static void ironlake_enable_fbc(struct drm_crtc *crtc, unsigned long interval)
  1641. {
  1642. struct drm_device *dev = crtc->dev;
  1643. struct drm_i915_private *dev_priv = dev->dev_private;
  1644. struct drm_framebuffer *fb = crtc->fb;
  1645. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  1646. struct drm_i915_gem_object *obj = intel_fb->obj;
  1647. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1648. int plane = intel_crtc->plane == 0 ? DPFC_CTL_PLANEA : DPFC_CTL_PLANEB;
  1649. unsigned long stall_watermark = 200;
  1650. u32 dpfc_ctl;
  1651. dpfc_ctl = I915_READ(ILK_DPFC_CONTROL);
  1652. if (dpfc_ctl & DPFC_CTL_EN) {
  1653. if (dev_priv->cfb_pitch == dev_priv->cfb_pitch / 64 - 1 &&
  1654. dev_priv->cfb_fence == obj->fence_reg &&
  1655. dev_priv->cfb_plane == intel_crtc->plane &&
  1656. dev_priv->cfb_offset == obj->gtt_offset &&
  1657. dev_priv->cfb_y == crtc->y)
  1658. return;
  1659. I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl & ~DPFC_CTL_EN);
  1660. intel_wait_for_vblank(dev, intel_crtc->pipe);
  1661. }
  1662. dev_priv->cfb_pitch = (dev_priv->cfb_pitch / 64) - 1;
  1663. dev_priv->cfb_fence = obj->fence_reg;
  1664. dev_priv->cfb_plane = intel_crtc->plane;
  1665. dev_priv->cfb_offset = obj->gtt_offset;
  1666. dev_priv->cfb_y = crtc->y;
  1667. dpfc_ctl &= DPFC_RESERVED;
  1668. dpfc_ctl |= (plane | DPFC_CTL_LIMIT_1X);
  1669. if (obj->tiling_mode != I915_TILING_NONE) {
  1670. dpfc_ctl |= (DPFC_CTL_FENCE_EN | dev_priv->cfb_fence);
  1671. I915_WRITE(ILK_DPFC_CHICKEN, DPFC_HT_MODIFY);
  1672. } else {
  1673. I915_WRITE(ILK_DPFC_CHICKEN, ~DPFC_HT_MODIFY);
  1674. }
  1675. I915_WRITE(ILK_DPFC_RECOMP_CTL, DPFC_RECOMP_STALL_EN |
  1676. (stall_watermark << DPFC_RECOMP_STALL_WM_SHIFT) |
  1677. (interval << DPFC_RECOMP_TIMER_COUNT_SHIFT));
  1678. I915_WRITE(ILK_DPFC_FENCE_YOFF, crtc->y);
  1679. I915_WRITE(ILK_FBC_RT_BASE, obj->gtt_offset | ILK_FBC_RT_VALID);
  1680. /* enable it... */
  1681. I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl | DPFC_CTL_EN);
  1682. if (IS_GEN6(dev)) {
  1683. I915_WRITE(SNB_DPFC_CTL_SA,
  1684. SNB_CPU_FENCE_ENABLE | dev_priv->cfb_fence);
  1685. I915_WRITE(DPFC_CPU_FENCE_OFFSET, crtc->y);
  1686. sandybridge_blit_fbc_update(dev);
  1687. }
  1688. DRM_DEBUG_KMS("enabled fbc on plane %d\n", intel_crtc->plane);
  1689. }
  1690. void ironlake_disable_fbc(struct drm_device *dev)
  1691. {
  1692. struct drm_i915_private *dev_priv = dev->dev_private;
  1693. u32 dpfc_ctl;
  1694. /* Disable compression */
  1695. dpfc_ctl = I915_READ(ILK_DPFC_CONTROL);
  1696. if (dpfc_ctl & DPFC_CTL_EN) {
  1697. dpfc_ctl &= ~DPFC_CTL_EN;
  1698. I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl);
  1699. DRM_DEBUG_KMS("disabled FBC\n");
  1700. }
  1701. }
  1702. static bool ironlake_fbc_enabled(struct drm_device *dev)
  1703. {
  1704. struct drm_i915_private *dev_priv = dev->dev_private;
  1705. return I915_READ(ILK_DPFC_CONTROL) & DPFC_CTL_EN;
  1706. }
  1707. bool intel_fbc_enabled(struct drm_device *dev)
  1708. {
  1709. struct drm_i915_private *dev_priv = dev->dev_private;
  1710. if (!dev_priv->display.fbc_enabled)
  1711. return false;
  1712. return dev_priv->display.fbc_enabled(dev);
  1713. }
  1714. void intel_enable_fbc(struct drm_crtc *crtc, unsigned long interval)
  1715. {
  1716. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  1717. if (!dev_priv->display.enable_fbc)
  1718. return;
  1719. dev_priv->display.enable_fbc(crtc, interval);
  1720. }
  1721. void intel_disable_fbc(struct drm_device *dev)
  1722. {
  1723. struct drm_i915_private *dev_priv = dev->dev_private;
  1724. if (!dev_priv->display.disable_fbc)
  1725. return;
  1726. dev_priv->display.disable_fbc(dev);
  1727. }
  1728. /**
  1729. * intel_update_fbc - enable/disable FBC as needed
  1730. * @dev: the drm_device
  1731. *
  1732. * Set up the framebuffer compression hardware at mode set time. We
  1733. * enable it if possible:
  1734. * - plane A only (on pre-965)
  1735. * - no pixel mulitply/line duplication
  1736. * - no alpha buffer discard
  1737. * - no dual wide
  1738. * - framebuffer <= 2048 in width, 1536 in height
  1739. *
  1740. * We can't assume that any compression will take place (worst case),
  1741. * so the compressed buffer has to be the same size as the uncompressed
  1742. * one. It also must reside (along with the line length buffer) in
  1743. * stolen memory.
  1744. *
  1745. * We need to enable/disable FBC on a global basis.
  1746. */
  1747. static void intel_update_fbc(struct drm_device *dev)
  1748. {
  1749. struct drm_i915_private *dev_priv = dev->dev_private;
  1750. struct drm_crtc *crtc = NULL, *tmp_crtc;
  1751. struct intel_crtc *intel_crtc;
  1752. struct drm_framebuffer *fb;
  1753. struct intel_framebuffer *intel_fb;
  1754. struct drm_i915_gem_object *obj;
  1755. DRM_DEBUG_KMS("\n");
  1756. if (!i915_powersave)
  1757. return;
  1758. if (!I915_HAS_FBC(dev))
  1759. return;
  1760. /*
  1761. * If FBC is already on, we just have to verify that we can
  1762. * keep it that way...
  1763. * Need to disable if:
  1764. * - more than one pipe is active
  1765. * - changing FBC params (stride, fence, mode)
  1766. * - new fb is too large to fit in compressed buffer
  1767. * - going to an unsupported config (interlace, pixel multiply, etc.)
  1768. */
  1769. list_for_each_entry(tmp_crtc, &dev->mode_config.crtc_list, head) {
  1770. if (tmp_crtc->enabled && tmp_crtc->fb) {
  1771. if (crtc) {
  1772. DRM_DEBUG_KMS("more than one pipe active, disabling compression\n");
  1773. dev_priv->no_fbc_reason = FBC_MULTIPLE_PIPES;
  1774. goto out_disable;
  1775. }
  1776. crtc = tmp_crtc;
  1777. }
  1778. }
  1779. if (!crtc || crtc->fb == NULL) {
  1780. DRM_DEBUG_KMS("no output, disabling\n");
  1781. dev_priv->no_fbc_reason = FBC_NO_OUTPUT;
  1782. goto out_disable;
  1783. }
  1784. intel_crtc = to_intel_crtc(crtc);
  1785. fb = crtc->fb;
  1786. intel_fb = to_intel_framebuffer(fb);
  1787. obj = intel_fb->obj;
  1788. if (intel_fb->obj->base.size > dev_priv->cfb_size) {
  1789. DRM_DEBUG_KMS("framebuffer too large, disabling "
  1790. "compression\n");
  1791. dev_priv->no_fbc_reason = FBC_STOLEN_TOO_SMALL;
  1792. goto out_disable;
  1793. }
  1794. if ((crtc->mode.flags & DRM_MODE_FLAG_INTERLACE) ||
  1795. (crtc->mode.flags & DRM_MODE_FLAG_DBLSCAN)) {
  1796. DRM_DEBUG_KMS("mode incompatible with compression, "
  1797. "disabling\n");
  1798. dev_priv->no_fbc_reason = FBC_UNSUPPORTED_MODE;
  1799. goto out_disable;
  1800. }
  1801. if ((crtc->mode.hdisplay > 2048) ||
  1802. (crtc->mode.vdisplay > 1536)) {
  1803. DRM_DEBUG_KMS("mode too large for compression, disabling\n");
  1804. dev_priv->no_fbc_reason = FBC_MODE_TOO_LARGE;
  1805. goto out_disable;
  1806. }
  1807. if ((IS_I915GM(dev) || IS_I945GM(dev)) && intel_crtc->plane != 0) {
  1808. DRM_DEBUG_KMS("plane not 0, disabling compression\n");
  1809. dev_priv->no_fbc_reason = FBC_BAD_PLANE;
  1810. goto out_disable;
  1811. }
  1812. if (obj->tiling_mode != I915_TILING_X) {
  1813. DRM_DEBUG_KMS("framebuffer not tiled, disabling compression\n");
  1814. dev_priv->no_fbc_reason = FBC_NOT_TILED;
  1815. goto out_disable;
  1816. }
  1817. /* If the kernel debugger is active, always disable compression */
  1818. if (in_dbg_master())
  1819. goto out_disable;
  1820. intel_enable_fbc(crtc, 500);
  1821. return;
  1822. out_disable:
  1823. /* Multiple disables should be harmless */
  1824. if (intel_fbc_enabled(dev)) {
  1825. DRM_DEBUG_KMS("unsupported config, disabling FBC\n");
  1826. intel_disable_fbc(dev);
  1827. }
  1828. }
  1829. int
  1830. intel_pin_and_fence_fb_obj(struct drm_device *dev,
  1831. struct drm_i915_gem_object *obj,
  1832. struct intel_ring_buffer *pipelined)
  1833. {
  1834. struct drm_i915_private *dev_priv = dev->dev_private;
  1835. u32 alignment;
  1836. int ret;
  1837. switch (obj->tiling_mode) {
  1838. case I915_TILING_NONE:
  1839. if (IS_BROADWATER(dev) || IS_CRESTLINE(dev))
  1840. alignment = 128 * 1024;
  1841. else if (INTEL_INFO(dev)->gen >= 4)
  1842. alignment = 4 * 1024;
  1843. else
  1844. alignment = 64 * 1024;
  1845. break;
  1846. case I915_TILING_X:
  1847. /* pin() will align the object as required by fence */
  1848. alignment = 0;
  1849. break;
  1850. case I915_TILING_Y:
  1851. /* FIXME: Is this true? */
  1852. DRM_ERROR("Y tiled not allowed for scan out buffers\n");
  1853. return -EINVAL;
  1854. default:
  1855. BUG();
  1856. }
  1857. dev_priv->mm.interruptible = false;
  1858. ret = i915_gem_object_pin(obj, alignment, true);
  1859. if (ret)
  1860. goto err_interruptible;
  1861. ret = i915_gem_object_set_to_display_plane(obj, pipelined);
  1862. if (ret)
  1863. goto err_unpin;
  1864. /* Install a fence for tiled scan-out. Pre-i965 always needs a
  1865. * fence, whereas 965+ only requires a fence if using
  1866. * framebuffer compression. For simplicity, we always install
  1867. * a fence as the cost is not that onerous.
  1868. */
  1869. if (obj->tiling_mode != I915_TILING_NONE) {
  1870. ret = i915_gem_object_get_fence(obj, pipelined);
  1871. if (ret)
  1872. goto err_unpin;
  1873. }
  1874. dev_priv->mm.interruptible = true;
  1875. return 0;
  1876. err_unpin:
  1877. i915_gem_object_unpin(obj);
  1878. err_interruptible:
  1879. dev_priv->mm.interruptible = true;
  1880. return ret;
  1881. }
  1882. /* Assume fb object is pinned & idle & fenced and just update base pointers */
  1883. static int
  1884. intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb,
  1885. int x, int y, enum mode_set_atomic state)
  1886. {
  1887. struct drm_device *dev = crtc->dev;
  1888. struct drm_i915_private *dev_priv = dev->dev_private;
  1889. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1890. struct intel_framebuffer *intel_fb;
  1891. struct drm_i915_gem_object *obj;
  1892. int plane = intel_crtc->plane;
  1893. unsigned long Start, Offset;
  1894. u32 dspcntr;
  1895. u32 reg;
  1896. switch (plane) {
  1897. case 0:
  1898. case 1:
  1899. break;
  1900. default:
  1901. DRM_ERROR("Can't update plane %d in SAREA\n", plane);
  1902. return -EINVAL;
  1903. }
  1904. intel_fb = to_intel_framebuffer(fb);
  1905. obj = intel_fb->obj;
  1906. reg = DSPCNTR(plane);
  1907. dspcntr = I915_READ(reg);
  1908. /* Mask out pixel format bits in case we change it */
  1909. dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
  1910. switch (fb->bits_per_pixel) {
  1911. case 8:
  1912. dspcntr |= DISPPLANE_8BPP;
  1913. break;
  1914. case 16:
  1915. if (fb->depth == 15)
  1916. dspcntr |= DISPPLANE_15_16BPP;
  1917. else
  1918. dspcntr |= DISPPLANE_16BPP;
  1919. break;
  1920. case 24:
  1921. case 32:
  1922. dspcntr |= DISPPLANE_32BPP_NO_ALPHA;
  1923. break;
  1924. default:
  1925. DRM_ERROR("Unknown color depth\n");
  1926. return -EINVAL;
  1927. }
  1928. if (INTEL_INFO(dev)->gen >= 4) {
  1929. if (obj->tiling_mode != I915_TILING_NONE)
  1930. dspcntr |= DISPPLANE_TILED;
  1931. else
  1932. dspcntr &= ~DISPPLANE_TILED;
  1933. }
  1934. if (HAS_PCH_SPLIT(dev))
  1935. /* must disable */
  1936. dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
  1937. I915_WRITE(reg, dspcntr);
  1938. Start = obj->gtt_offset;
  1939. Offset = y * fb->pitch + x * (fb->bits_per_pixel / 8);
  1940. DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n",
  1941. Start, Offset, x, y, fb->pitch);
  1942. I915_WRITE(DSPSTRIDE(plane), fb->pitch);
  1943. if (INTEL_INFO(dev)->gen >= 4) {
  1944. I915_WRITE(DSPSURF(plane), Start);
  1945. I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
  1946. I915_WRITE(DSPADDR(plane), Offset);
  1947. } else
  1948. I915_WRITE(DSPADDR(plane), Start + Offset);
  1949. POSTING_READ(reg);
  1950. intel_update_fbc(dev);
  1951. intel_increase_pllclock(crtc);
  1952. return 0;
  1953. }
  1954. static int
  1955. intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
  1956. struct drm_framebuffer *old_fb)
  1957. {
  1958. struct drm_device *dev = crtc->dev;
  1959. struct drm_i915_master_private *master_priv;
  1960. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1961. int ret;
  1962. /* no fb bound */
  1963. if (!crtc->fb) {
  1964. DRM_DEBUG_KMS("No FB bound\n");
  1965. return 0;
  1966. }
  1967. switch (intel_crtc->plane) {
  1968. case 0:
  1969. case 1:
  1970. break;
  1971. default:
  1972. return -EINVAL;
  1973. }
  1974. mutex_lock(&dev->struct_mutex);
  1975. ret = intel_pin_and_fence_fb_obj(dev,
  1976. to_intel_framebuffer(crtc->fb)->obj,
  1977. NULL);
  1978. if (ret != 0) {
  1979. mutex_unlock(&dev->struct_mutex);
  1980. return ret;
  1981. }
  1982. if (old_fb) {
  1983. struct drm_i915_private *dev_priv = dev->dev_private;
  1984. struct drm_i915_gem_object *obj = to_intel_framebuffer(old_fb)->obj;
  1985. wait_event(dev_priv->pending_flip_queue,
  1986. atomic_read(&dev_priv->mm.wedged) ||
  1987. atomic_read(&obj->pending_flip) == 0);
  1988. /* Big Hammer, we also need to ensure that any pending
  1989. * MI_WAIT_FOR_EVENT inside a user batch buffer on the
  1990. * current scanout is retired before unpinning the old
  1991. * framebuffer.
  1992. *
  1993. * This should only fail upon a hung GPU, in which case we
  1994. * can safely continue.
  1995. */
  1996. ret = i915_gem_object_flush_gpu(obj);
  1997. (void) ret;
  1998. }
  1999. ret = intel_pipe_set_base_atomic(crtc, crtc->fb, x, y,
  2000. LEAVE_ATOMIC_MODE_SET);
  2001. if (ret) {
  2002. i915_gem_object_unpin(to_intel_framebuffer(crtc->fb)->obj);
  2003. mutex_unlock(&dev->struct_mutex);
  2004. return ret;
  2005. }
  2006. if (old_fb) {
  2007. intel_wait_for_vblank(dev, intel_crtc->pipe);
  2008. i915_gem_object_unpin(to_intel_framebuffer(old_fb)->obj);
  2009. }
  2010. mutex_unlock(&dev->struct_mutex);
  2011. if (!dev->primary->master)
  2012. return 0;
  2013. master_priv = dev->primary->master->driver_priv;
  2014. if (!master_priv->sarea_priv)
  2015. return 0;
  2016. if (intel_crtc->pipe) {
  2017. master_priv->sarea_priv->pipeB_x = x;
  2018. master_priv->sarea_priv->pipeB_y = y;
  2019. } else {
  2020. master_priv->sarea_priv->pipeA_x = x;
  2021. master_priv->sarea_priv->pipeA_y = y;
  2022. }
  2023. return 0;
  2024. }
  2025. static void ironlake_set_pll_edp(struct drm_crtc *crtc, int clock)
  2026. {
  2027. struct drm_device *dev = crtc->dev;
  2028. struct drm_i915_private *dev_priv = dev->dev_private;
  2029. u32 dpa_ctl;
  2030. DRM_DEBUG_KMS("eDP PLL enable for clock %d\n", clock);
  2031. dpa_ctl = I915_READ(DP_A);
  2032. dpa_ctl &= ~DP_PLL_FREQ_MASK;
  2033. if (clock < 200000) {
  2034. u32 temp;
  2035. dpa_ctl |= DP_PLL_FREQ_160MHZ;
  2036. /* workaround for 160Mhz:
  2037. 1) program 0x4600c bits 15:0 = 0x8124
  2038. 2) program 0x46010 bit 0 = 1
  2039. 3) program 0x46034 bit 24 = 1
  2040. 4) program 0x64000 bit 14 = 1
  2041. */
  2042. temp = I915_READ(0x4600c);
  2043. temp &= 0xffff0000;
  2044. I915_WRITE(0x4600c, temp | 0x8124);
  2045. temp = I915_READ(0x46010);
  2046. I915_WRITE(0x46010, temp | 1);
  2047. temp = I915_READ(0x46034);
  2048. I915_WRITE(0x46034, temp | (1 << 24));
  2049. } else {
  2050. dpa_ctl |= DP_PLL_FREQ_270MHZ;
  2051. }
  2052. I915_WRITE(DP_A, dpa_ctl);
  2053. POSTING_READ(DP_A);
  2054. udelay(500);
  2055. }
  2056. static void intel_fdi_normal_train(struct drm_crtc *crtc)
  2057. {
  2058. struct drm_device *dev = crtc->dev;
  2059. struct drm_i915_private *dev_priv = dev->dev_private;
  2060. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2061. int pipe = intel_crtc->pipe;
  2062. u32 reg, temp;
  2063. /* enable normal train */
  2064. reg = FDI_TX_CTL(pipe);
  2065. temp = I915_READ(reg);
  2066. temp &= ~FDI_LINK_TRAIN_NONE;
  2067. temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
  2068. I915_WRITE(reg, temp);
  2069. reg = FDI_RX_CTL(pipe);
  2070. temp = I915_READ(reg);
  2071. if (HAS_PCH_CPT(dev)) {
  2072. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2073. temp |= FDI_LINK_TRAIN_NORMAL_CPT;
  2074. } else {
  2075. temp &= ~FDI_LINK_TRAIN_NONE;
  2076. temp |= FDI_LINK_TRAIN_NONE;
  2077. }
  2078. I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
  2079. /* wait one idle pattern time */
  2080. POSTING_READ(reg);
  2081. udelay(1000);
  2082. }
  2083. /* The FDI link training functions for ILK/Ibexpeak. */
  2084. static void ironlake_fdi_link_train(struct drm_crtc *crtc)
  2085. {
  2086. struct drm_device *dev = crtc->dev;
  2087. struct drm_i915_private *dev_priv = dev->dev_private;
  2088. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2089. int pipe = intel_crtc->pipe;
  2090. int plane = intel_crtc->plane;
  2091. u32 reg, temp, tries;
  2092. /* FDI needs bits from pipe & plane first */
  2093. assert_pipe_enabled(dev_priv, pipe);
  2094. assert_plane_enabled(dev_priv, plane);
  2095. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2096. for train result */
  2097. reg = FDI_RX_IMR(pipe);
  2098. temp = I915_READ(reg);
  2099. temp &= ~FDI_RX_SYMBOL_LOCK;
  2100. temp &= ~FDI_RX_BIT_LOCK;
  2101. I915_WRITE(reg, temp);
  2102. I915_READ(reg);
  2103. udelay(150);
  2104. /* enable CPU FDI TX and PCH FDI RX */
  2105. reg = FDI_TX_CTL(pipe);
  2106. temp = I915_READ(reg);
  2107. temp &= ~(7 << 19);
  2108. temp |= (intel_crtc->fdi_lanes - 1) << 19;
  2109. temp &= ~FDI_LINK_TRAIN_NONE;
  2110. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2111. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2112. reg = FDI_RX_CTL(pipe);
  2113. temp = I915_READ(reg);
  2114. temp &= ~FDI_LINK_TRAIN_NONE;
  2115. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2116. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2117. POSTING_READ(reg);
  2118. udelay(150);
  2119. /* Ironlake workaround, enable clock pointer after FDI enable*/
  2120. if (HAS_PCH_IBX(dev)) {
  2121. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
  2122. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
  2123. FDI_RX_PHASE_SYNC_POINTER_EN);
  2124. }
  2125. reg = FDI_RX_IIR(pipe);
  2126. for (tries = 0; tries < 5; tries++) {
  2127. temp = I915_READ(reg);
  2128. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2129. if ((temp & FDI_RX_BIT_LOCK)) {
  2130. DRM_DEBUG_KMS("FDI train 1 done.\n");
  2131. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2132. break;
  2133. }
  2134. }
  2135. if (tries == 5)
  2136. DRM_ERROR("FDI train 1 fail!\n");
  2137. /* Train 2 */
  2138. reg = FDI_TX_CTL(pipe);
  2139. temp = I915_READ(reg);
  2140. temp &= ~FDI_LINK_TRAIN_NONE;
  2141. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2142. I915_WRITE(reg, temp);
  2143. reg = FDI_RX_CTL(pipe);
  2144. temp = I915_READ(reg);
  2145. temp &= ~FDI_LINK_TRAIN_NONE;
  2146. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2147. I915_WRITE(reg, temp);
  2148. POSTING_READ(reg);
  2149. udelay(150);
  2150. reg = FDI_RX_IIR(pipe);
  2151. for (tries = 0; tries < 5; tries++) {
  2152. temp = I915_READ(reg);
  2153. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2154. if (temp & FDI_RX_SYMBOL_LOCK) {
  2155. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2156. DRM_DEBUG_KMS("FDI train 2 done.\n");
  2157. break;
  2158. }
  2159. }
  2160. if (tries == 5)
  2161. DRM_ERROR("FDI train 2 fail!\n");
  2162. DRM_DEBUG_KMS("FDI train done\n");
  2163. }
  2164. static const int snb_b_fdi_train_param [] = {
  2165. FDI_LINK_TRAIN_400MV_0DB_SNB_B,
  2166. FDI_LINK_TRAIN_400MV_6DB_SNB_B,
  2167. FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
  2168. FDI_LINK_TRAIN_800MV_0DB_SNB_B,
  2169. };
  2170. /* The FDI link training functions for SNB/Cougarpoint. */
  2171. static void gen6_fdi_link_train(struct drm_crtc *crtc)
  2172. {
  2173. struct drm_device *dev = crtc->dev;
  2174. struct drm_i915_private *dev_priv = dev->dev_private;
  2175. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2176. int pipe = intel_crtc->pipe;
  2177. u32 reg, temp, i;
  2178. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2179. for train result */
  2180. reg = FDI_RX_IMR(pipe);
  2181. temp = I915_READ(reg);
  2182. temp &= ~FDI_RX_SYMBOL_LOCK;
  2183. temp &= ~FDI_RX_BIT_LOCK;
  2184. I915_WRITE(reg, temp);
  2185. POSTING_READ(reg);
  2186. udelay(150);
  2187. /* enable CPU FDI TX and PCH FDI RX */
  2188. reg = FDI_TX_CTL(pipe);
  2189. temp = I915_READ(reg);
  2190. temp &= ~(7 << 19);
  2191. temp |= (intel_crtc->fdi_lanes - 1) << 19;
  2192. temp &= ~FDI_LINK_TRAIN_NONE;
  2193. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2194. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2195. /* SNB-B */
  2196. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2197. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2198. reg = FDI_RX_CTL(pipe);
  2199. temp = I915_READ(reg);
  2200. if (HAS_PCH_CPT(dev)) {
  2201. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2202. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2203. } else {
  2204. temp &= ~FDI_LINK_TRAIN_NONE;
  2205. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2206. }
  2207. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2208. POSTING_READ(reg);
  2209. udelay(150);
  2210. for (i = 0; i < 4; i++ ) {
  2211. reg = FDI_TX_CTL(pipe);
  2212. temp = I915_READ(reg);
  2213. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2214. temp |= snb_b_fdi_train_param[i];
  2215. I915_WRITE(reg, temp);
  2216. POSTING_READ(reg);
  2217. udelay(500);
  2218. reg = FDI_RX_IIR(pipe);
  2219. temp = I915_READ(reg);
  2220. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2221. if (temp & FDI_RX_BIT_LOCK) {
  2222. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2223. DRM_DEBUG_KMS("FDI train 1 done.\n");
  2224. break;
  2225. }
  2226. }
  2227. if (i == 4)
  2228. DRM_ERROR("FDI train 1 fail!\n");
  2229. /* Train 2 */
  2230. reg = FDI_TX_CTL(pipe);
  2231. temp = I915_READ(reg);
  2232. temp &= ~FDI_LINK_TRAIN_NONE;
  2233. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2234. if (IS_GEN6(dev)) {
  2235. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2236. /* SNB-B */
  2237. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2238. }
  2239. I915_WRITE(reg, temp);
  2240. reg = FDI_RX_CTL(pipe);
  2241. temp = I915_READ(reg);
  2242. if (HAS_PCH_CPT(dev)) {
  2243. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2244. temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
  2245. } else {
  2246. temp &= ~FDI_LINK_TRAIN_NONE;
  2247. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2248. }
  2249. I915_WRITE(reg, temp);
  2250. POSTING_READ(reg);
  2251. udelay(150);
  2252. for (i = 0; i < 4; i++ ) {
  2253. reg = FDI_TX_CTL(pipe);
  2254. temp = I915_READ(reg);
  2255. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2256. temp |= snb_b_fdi_train_param[i];
  2257. I915_WRITE(reg, temp);
  2258. POSTING_READ(reg);
  2259. udelay(500);
  2260. reg = FDI_RX_IIR(pipe);
  2261. temp = I915_READ(reg);
  2262. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2263. if (temp & FDI_RX_SYMBOL_LOCK) {
  2264. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2265. DRM_DEBUG_KMS("FDI train 2 done.\n");
  2266. break;
  2267. }
  2268. }
  2269. if (i == 4)
  2270. DRM_ERROR("FDI train 2 fail!\n");
  2271. DRM_DEBUG_KMS("FDI train done.\n");
  2272. }
  2273. static void ironlake_fdi_enable(struct drm_crtc *crtc)
  2274. {
  2275. struct drm_device *dev = crtc->dev;
  2276. struct drm_i915_private *dev_priv = dev->dev_private;
  2277. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2278. int pipe = intel_crtc->pipe;
  2279. u32 reg, temp;
  2280. /* Write the TU size bits so error detection works */
  2281. I915_WRITE(FDI_RX_TUSIZE1(pipe),
  2282. I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
  2283. /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
  2284. reg = FDI_RX_CTL(pipe);
  2285. temp = I915_READ(reg);
  2286. temp &= ~((0x7 << 19) | (0x7 << 16));
  2287. temp |= (intel_crtc->fdi_lanes - 1) << 19;
  2288. temp |= (I915_READ(PIPECONF(pipe)) & PIPE_BPC_MASK) << 11;
  2289. I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
  2290. POSTING_READ(reg);
  2291. udelay(200);
  2292. /* Switch from Rawclk to PCDclk */
  2293. temp = I915_READ(reg);
  2294. I915_WRITE(reg, temp | FDI_PCDCLK);
  2295. POSTING_READ(reg);
  2296. udelay(200);
  2297. /* Enable CPU FDI TX PLL, always on for Ironlake */
  2298. reg = FDI_TX_CTL(pipe);
  2299. temp = I915_READ(reg);
  2300. if ((temp & FDI_TX_PLL_ENABLE) == 0) {
  2301. I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
  2302. POSTING_READ(reg);
  2303. udelay(100);
  2304. }
  2305. }
  2306. static void ironlake_fdi_disable(struct drm_crtc *crtc)
  2307. {
  2308. struct drm_device *dev = crtc->dev;
  2309. struct drm_i915_private *dev_priv = dev->dev_private;
  2310. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2311. int pipe = intel_crtc->pipe;
  2312. u32 reg, temp;
  2313. /* disable CPU FDI tx and PCH FDI rx */
  2314. reg = FDI_TX_CTL(pipe);
  2315. temp = I915_READ(reg);
  2316. I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
  2317. POSTING_READ(reg);
  2318. reg = FDI_RX_CTL(pipe);
  2319. temp = I915_READ(reg);
  2320. temp &= ~(0x7 << 16);
  2321. temp |= (I915_READ(PIPECONF(pipe)) & PIPE_BPC_MASK) << 11;
  2322. I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
  2323. POSTING_READ(reg);
  2324. udelay(100);
  2325. /* Ironlake workaround, disable clock pointer after downing FDI */
  2326. if (HAS_PCH_IBX(dev)) {
  2327. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
  2328. I915_WRITE(FDI_RX_CHICKEN(pipe),
  2329. I915_READ(FDI_RX_CHICKEN(pipe) &
  2330. ~FDI_RX_PHASE_SYNC_POINTER_EN));
  2331. }
  2332. /* still set train pattern 1 */
  2333. reg = FDI_TX_CTL(pipe);
  2334. temp = I915_READ(reg);
  2335. temp &= ~FDI_LINK_TRAIN_NONE;
  2336. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2337. I915_WRITE(reg, temp);
  2338. reg = FDI_RX_CTL(pipe);
  2339. temp = I915_READ(reg);
  2340. if (HAS_PCH_CPT(dev)) {
  2341. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2342. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2343. } else {
  2344. temp &= ~FDI_LINK_TRAIN_NONE;
  2345. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2346. }
  2347. /* BPC in FDI rx is consistent with that in PIPECONF */
  2348. temp &= ~(0x07 << 16);
  2349. temp |= (I915_READ(PIPECONF(pipe)) & PIPE_BPC_MASK) << 11;
  2350. I915_WRITE(reg, temp);
  2351. POSTING_READ(reg);
  2352. udelay(100);
  2353. }
  2354. /*
  2355. * When we disable a pipe, we need to clear any pending scanline wait events
  2356. * to avoid hanging the ring, which we assume we are waiting on.
  2357. */
  2358. static void intel_clear_scanline_wait(struct drm_device *dev)
  2359. {
  2360. struct drm_i915_private *dev_priv = dev->dev_private;
  2361. struct intel_ring_buffer *ring;
  2362. u32 tmp;
  2363. if (IS_GEN2(dev))
  2364. /* Can't break the hang on i8xx */
  2365. return;
  2366. ring = LP_RING(dev_priv);
  2367. tmp = I915_READ_CTL(ring);
  2368. if (tmp & RING_WAIT)
  2369. I915_WRITE_CTL(ring, tmp);
  2370. }
  2371. static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
  2372. {
  2373. struct drm_i915_gem_object *obj;
  2374. struct drm_i915_private *dev_priv;
  2375. if (crtc->fb == NULL)
  2376. return;
  2377. obj = to_intel_framebuffer(crtc->fb)->obj;
  2378. dev_priv = crtc->dev->dev_private;
  2379. wait_event(dev_priv->pending_flip_queue,
  2380. atomic_read(&obj->pending_flip) == 0);
  2381. }
  2382. static bool intel_crtc_driving_pch(struct drm_crtc *crtc)
  2383. {
  2384. struct drm_device *dev = crtc->dev;
  2385. struct drm_mode_config *mode_config = &dev->mode_config;
  2386. struct intel_encoder *encoder;
  2387. /*
  2388. * If there's a non-PCH eDP on this crtc, it must be DP_A, and that
  2389. * must be driven by its own crtc; no sharing is possible.
  2390. */
  2391. list_for_each_entry(encoder, &mode_config->encoder_list, base.head) {
  2392. if (encoder->base.crtc != crtc)
  2393. continue;
  2394. switch (encoder->type) {
  2395. case INTEL_OUTPUT_EDP:
  2396. if (!intel_encoder_is_pch_edp(&encoder->base))
  2397. return false;
  2398. continue;
  2399. }
  2400. }
  2401. return true;
  2402. }
  2403. /*
  2404. * Enable PCH resources required for PCH ports:
  2405. * - PCH PLLs
  2406. * - FDI training & RX/TX
  2407. * - update transcoder timings
  2408. * - DP transcoding bits
  2409. * - transcoder
  2410. */
  2411. static void ironlake_pch_enable(struct drm_crtc *crtc)
  2412. {
  2413. struct drm_device *dev = crtc->dev;
  2414. struct drm_i915_private *dev_priv = dev->dev_private;
  2415. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2416. int pipe = intel_crtc->pipe;
  2417. u32 reg, temp;
  2418. /* For PCH output, training FDI link */
  2419. if (IS_GEN6(dev))
  2420. gen6_fdi_link_train(crtc);
  2421. else
  2422. ironlake_fdi_link_train(crtc);
  2423. intel_enable_pch_pll(dev_priv, pipe);
  2424. if (HAS_PCH_CPT(dev)) {
  2425. /* Be sure PCH DPLL SEL is set */
  2426. temp = I915_READ(PCH_DPLL_SEL);
  2427. if (pipe == 0 && (temp & TRANSA_DPLL_ENABLE) == 0)
  2428. temp |= (TRANSA_DPLL_ENABLE | TRANSA_DPLLA_SEL);
  2429. else if (pipe == 1 && (temp & TRANSB_DPLL_ENABLE) == 0)
  2430. temp |= (TRANSB_DPLL_ENABLE | TRANSB_DPLLB_SEL);
  2431. I915_WRITE(PCH_DPLL_SEL, temp);
  2432. }
  2433. /* set transcoder timing, panel must allow it */
  2434. assert_panel_unlocked(dev_priv, pipe);
  2435. I915_WRITE(TRANS_HTOTAL(pipe), I915_READ(HTOTAL(pipe)));
  2436. I915_WRITE(TRANS_HBLANK(pipe), I915_READ(HBLANK(pipe)));
  2437. I915_WRITE(TRANS_HSYNC(pipe), I915_READ(HSYNC(pipe)));
  2438. I915_WRITE(TRANS_VTOTAL(pipe), I915_READ(VTOTAL(pipe)));
  2439. I915_WRITE(TRANS_VBLANK(pipe), I915_READ(VBLANK(pipe)));
  2440. I915_WRITE(TRANS_VSYNC(pipe), I915_READ(VSYNC(pipe)));
  2441. intel_fdi_normal_train(crtc);
  2442. /* For PCH DP, enable TRANS_DP_CTL */
  2443. if (HAS_PCH_CPT(dev) &&
  2444. intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  2445. reg = TRANS_DP_CTL(pipe);
  2446. temp = I915_READ(reg);
  2447. temp &= ~(TRANS_DP_PORT_SEL_MASK |
  2448. TRANS_DP_SYNC_MASK |
  2449. TRANS_DP_BPC_MASK);
  2450. temp |= (TRANS_DP_OUTPUT_ENABLE |
  2451. TRANS_DP_ENH_FRAMING);
  2452. temp |= TRANS_DP_8BPC;
  2453. if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC)
  2454. temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
  2455. if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC)
  2456. temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
  2457. switch (intel_trans_dp_port_sel(crtc)) {
  2458. case PCH_DP_B:
  2459. temp |= TRANS_DP_PORT_SEL_B;
  2460. break;
  2461. case PCH_DP_C:
  2462. temp |= TRANS_DP_PORT_SEL_C;
  2463. break;
  2464. case PCH_DP_D:
  2465. temp |= TRANS_DP_PORT_SEL_D;
  2466. break;
  2467. default:
  2468. DRM_DEBUG_KMS("Wrong PCH DP port return. Guess port B\n");
  2469. temp |= TRANS_DP_PORT_SEL_B;
  2470. break;
  2471. }
  2472. I915_WRITE(reg, temp);
  2473. }
  2474. intel_enable_transcoder(dev_priv, pipe);
  2475. }
  2476. static void ironlake_crtc_enable(struct drm_crtc *crtc)
  2477. {
  2478. struct drm_device *dev = crtc->dev;
  2479. struct drm_i915_private *dev_priv = dev->dev_private;
  2480. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2481. int pipe = intel_crtc->pipe;
  2482. int plane = intel_crtc->plane;
  2483. u32 temp;
  2484. bool is_pch_port;
  2485. if (intel_crtc->active)
  2486. return;
  2487. intel_crtc->active = true;
  2488. intel_update_watermarks(dev);
  2489. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  2490. temp = I915_READ(PCH_LVDS);
  2491. if ((temp & LVDS_PORT_EN) == 0)
  2492. I915_WRITE(PCH_LVDS, temp | LVDS_PORT_EN);
  2493. }
  2494. is_pch_port = intel_crtc_driving_pch(crtc);
  2495. if (is_pch_port)
  2496. ironlake_fdi_enable(crtc);
  2497. else
  2498. ironlake_fdi_disable(crtc);
  2499. /* Enable panel fitting for LVDS */
  2500. if (dev_priv->pch_pf_size &&
  2501. (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) || HAS_eDP)) {
  2502. /* Force use of hard-coded filter coefficients
  2503. * as some pre-programmed values are broken,
  2504. * e.g. x201.
  2505. */
  2506. I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
  2507. I915_WRITE(PF_WIN_POS(pipe), dev_priv->pch_pf_pos);
  2508. I915_WRITE(PF_WIN_SZ(pipe), dev_priv->pch_pf_size);
  2509. }
  2510. intel_enable_pipe(dev_priv, pipe, is_pch_port);
  2511. intel_enable_plane(dev_priv, plane, pipe);
  2512. if (is_pch_port)
  2513. ironlake_pch_enable(crtc);
  2514. intel_crtc_load_lut(crtc);
  2515. intel_update_fbc(dev);
  2516. intel_crtc_update_cursor(crtc, true);
  2517. }
  2518. static void ironlake_crtc_disable(struct drm_crtc *crtc)
  2519. {
  2520. struct drm_device *dev = crtc->dev;
  2521. struct drm_i915_private *dev_priv = dev->dev_private;
  2522. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2523. int pipe = intel_crtc->pipe;
  2524. int plane = intel_crtc->plane;
  2525. u32 reg, temp;
  2526. if (!intel_crtc->active)
  2527. return;
  2528. intel_crtc_wait_for_pending_flips(crtc);
  2529. drm_vblank_off(dev, pipe);
  2530. intel_crtc_update_cursor(crtc, false);
  2531. intel_disable_plane(dev_priv, plane, pipe);
  2532. if (dev_priv->cfb_plane == plane &&
  2533. dev_priv->display.disable_fbc)
  2534. dev_priv->display.disable_fbc(dev);
  2535. intel_disable_pipe(dev_priv, pipe);
  2536. /* Disable PF */
  2537. I915_WRITE(PF_CTL(pipe), 0);
  2538. I915_WRITE(PF_WIN_SZ(pipe), 0);
  2539. ironlake_fdi_disable(crtc);
  2540. /* This is a horrible layering violation; we should be doing this in
  2541. * the connector/encoder ->prepare instead, but we don't always have
  2542. * enough information there about the config to know whether it will
  2543. * actually be necessary or just cause undesired flicker.
  2544. */
  2545. intel_disable_pch_ports(dev_priv, pipe);
  2546. intel_disable_transcoder(dev_priv, pipe);
  2547. if (HAS_PCH_CPT(dev)) {
  2548. /* disable TRANS_DP_CTL */
  2549. reg = TRANS_DP_CTL(pipe);
  2550. temp = I915_READ(reg);
  2551. temp &= ~(TRANS_DP_OUTPUT_ENABLE | TRANS_DP_PORT_SEL_MASK);
  2552. temp |= TRANS_DP_PORT_SEL_NONE;
  2553. I915_WRITE(reg, temp);
  2554. /* disable DPLL_SEL */
  2555. temp = I915_READ(PCH_DPLL_SEL);
  2556. switch (pipe) {
  2557. case 0:
  2558. temp &= ~(TRANSA_DPLL_ENABLE | TRANSA_DPLLA_SEL);
  2559. break;
  2560. case 1:
  2561. temp &= ~(TRANSB_DPLL_ENABLE | TRANSB_DPLLB_SEL);
  2562. break;
  2563. case 2:
  2564. /* FIXME: manage transcoder PLLs? */
  2565. temp &= ~(TRANSC_DPLL_ENABLE | TRANSC_DPLLB_SEL);
  2566. break;
  2567. default:
  2568. BUG(); /* wtf */
  2569. }
  2570. I915_WRITE(PCH_DPLL_SEL, temp);
  2571. }
  2572. /* disable PCH DPLL */
  2573. intel_disable_pch_pll(dev_priv, pipe);
  2574. /* Switch from PCDclk to Rawclk */
  2575. reg = FDI_RX_CTL(pipe);
  2576. temp = I915_READ(reg);
  2577. I915_WRITE(reg, temp & ~FDI_PCDCLK);
  2578. /* Disable CPU FDI TX PLL */
  2579. reg = FDI_TX_CTL(pipe);
  2580. temp = I915_READ(reg);
  2581. I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
  2582. POSTING_READ(reg);
  2583. udelay(100);
  2584. reg = FDI_RX_CTL(pipe);
  2585. temp = I915_READ(reg);
  2586. I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
  2587. /* Wait for the clocks to turn off. */
  2588. POSTING_READ(reg);
  2589. udelay(100);
  2590. intel_crtc->active = false;
  2591. intel_update_watermarks(dev);
  2592. intel_update_fbc(dev);
  2593. intel_clear_scanline_wait(dev);
  2594. }
  2595. static void ironlake_crtc_dpms(struct drm_crtc *crtc, int mode)
  2596. {
  2597. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2598. int pipe = intel_crtc->pipe;
  2599. int plane = intel_crtc->plane;
  2600. /* XXX: When our outputs are all unaware of DPMS modes other than off
  2601. * and on, we should map those modes to DRM_MODE_DPMS_OFF in the CRTC.
  2602. */
  2603. switch (mode) {
  2604. case DRM_MODE_DPMS_ON:
  2605. case DRM_MODE_DPMS_STANDBY:
  2606. case DRM_MODE_DPMS_SUSPEND:
  2607. DRM_DEBUG_KMS("crtc %d/%d dpms on\n", pipe, plane);
  2608. ironlake_crtc_enable(crtc);
  2609. break;
  2610. case DRM_MODE_DPMS_OFF:
  2611. DRM_DEBUG_KMS("crtc %d/%d dpms off\n", pipe, plane);
  2612. ironlake_crtc_disable(crtc);
  2613. break;
  2614. }
  2615. }
  2616. static void intel_crtc_dpms_overlay(struct intel_crtc *intel_crtc, bool enable)
  2617. {
  2618. if (!enable && intel_crtc->overlay) {
  2619. struct drm_device *dev = intel_crtc->base.dev;
  2620. struct drm_i915_private *dev_priv = dev->dev_private;
  2621. mutex_lock(&dev->struct_mutex);
  2622. dev_priv->mm.interruptible = false;
  2623. (void) intel_overlay_switch_off(intel_crtc->overlay);
  2624. dev_priv->mm.interruptible = true;
  2625. mutex_unlock(&dev->struct_mutex);
  2626. }
  2627. /* Let userspace switch the overlay on again. In most cases userspace
  2628. * has to recompute where to put it anyway.
  2629. */
  2630. }
  2631. static void i9xx_crtc_enable(struct drm_crtc *crtc)
  2632. {
  2633. struct drm_device *dev = crtc->dev;
  2634. struct drm_i915_private *dev_priv = dev->dev_private;
  2635. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2636. int pipe = intel_crtc->pipe;
  2637. int plane = intel_crtc->plane;
  2638. if (intel_crtc->active)
  2639. return;
  2640. intel_crtc->active = true;
  2641. intel_update_watermarks(dev);
  2642. intel_enable_pll(dev_priv, pipe);
  2643. intel_enable_pipe(dev_priv, pipe, false);
  2644. intel_enable_plane(dev_priv, plane, pipe);
  2645. intel_crtc_load_lut(crtc);
  2646. intel_update_fbc(dev);
  2647. /* Give the overlay scaler a chance to enable if it's on this pipe */
  2648. intel_crtc_dpms_overlay(intel_crtc, true);
  2649. intel_crtc_update_cursor(crtc, true);
  2650. }
  2651. static void i9xx_crtc_disable(struct drm_crtc *crtc)
  2652. {
  2653. struct drm_device *dev = crtc->dev;
  2654. struct drm_i915_private *dev_priv = dev->dev_private;
  2655. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2656. int pipe = intel_crtc->pipe;
  2657. int plane = intel_crtc->plane;
  2658. if (!intel_crtc->active)
  2659. return;
  2660. /* Give the overlay scaler a chance to disable if it's on this pipe */
  2661. intel_crtc_wait_for_pending_flips(crtc);
  2662. drm_vblank_off(dev, pipe);
  2663. intel_crtc_dpms_overlay(intel_crtc, false);
  2664. intel_crtc_update_cursor(crtc, false);
  2665. if (dev_priv->cfb_plane == plane &&
  2666. dev_priv->display.disable_fbc)
  2667. dev_priv->display.disable_fbc(dev);
  2668. intel_disable_plane(dev_priv, plane, pipe);
  2669. intel_disable_pipe(dev_priv, pipe);
  2670. intel_disable_pll(dev_priv, pipe);
  2671. intel_crtc->active = false;
  2672. intel_update_fbc(dev);
  2673. intel_update_watermarks(dev);
  2674. intel_clear_scanline_wait(dev);
  2675. }
  2676. static void i9xx_crtc_dpms(struct drm_crtc *crtc, int mode)
  2677. {
  2678. /* XXX: When our outputs are all unaware of DPMS modes other than off
  2679. * and on, we should map those modes to DRM_MODE_DPMS_OFF in the CRTC.
  2680. */
  2681. switch (mode) {
  2682. case DRM_MODE_DPMS_ON:
  2683. case DRM_MODE_DPMS_STANDBY:
  2684. case DRM_MODE_DPMS_SUSPEND:
  2685. i9xx_crtc_enable(crtc);
  2686. break;
  2687. case DRM_MODE_DPMS_OFF:
  2688. i9xx_crtc_disable(crtc);
  2689. break;
  2690. }
  2691. }
  2692. /**
  2693. * Sets the power management mode of the pipe and plane.
  2694. */
  2695. static void intel_crtc_dpms(struct drm_crtc *crtc, int mode)
  2696. {
  2697. struct drm_device *dev = crtc->dev;
  2698. struct drm_i915_private *dev_priv = dev->dev_private;
  2699. struct drm_i915_master_private *master_priv;
  2700. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2701. int pipe = intel_crtc->pipe;
  2702. bool enabled;
  2703. if (intel_crtc->dpms_mode == mode)
  2704. return;
  2705. intel_crtc->dpms_mode = mode;
  2706. dev_priv->display.dpms(crtc, mode);
  2707. if (!dev->primary->master)
  2708. return;
  2709. master_priv = dev->primary->master->driver_priv;
  2710. if (!master_priv->sarea_priv)
  2711. return;
  2712. enabled = crtc->enabled && mode != DRM_MODE_DPMS_OFF;
  2713. switch (pipe) {
  2714. case 0:
  2715. master_priv->sarea_priv->pipeA_w = enabled ? crtc->mode.hdisplay : 0;
  2716. master_priv->sarea_priv->pipeA_h = enabled ? crtc->mode.vdisplay : 0;
  2717. break;
  2718. case 1:
  2719. master_priv->sarea_priv->pipeB_w = enabled ? crtc->mode.hdisplay : 0;
  2720. master_priv->sarea_priv->pipeB_h = enabled ? crtc->mode.vdisplay : 0;
  2721. break;
  2722. default:
  2723. DRM_ERROR("Can't update pipe %c in SAREA\n", pipe_name(pipe));
  2724. break;
  2725. }
  2726. }
  2727. static void intel_crtc_disable(struct drm_crtc *crtc)
  2728. {
  2729. struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
  2730. struct drm_device *dev = crtc->dev;
  2731. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_OFF);
  2732. if (crtc->fb) {
  2733. mutex_lock(&dev->struct_mutex);
  2734. i915_gem_object_unpin(to_intel_framebuffer(crtc->fb)->obj);
  2735. mutex_unlock(&dev->struct_mutex);
  2736. }
  2737. }
  2738. /* Prepare for a mode set.
  2739. *
  2740. * Note we could be a lot smarter here. We need to figure out which outputs
  2741. * will be enabled, which disabled (in short, how the config will changes)
  2742. * and perform the minimum necessary steps to accomplish that, e.g. updating
  2743. * watermarks, FBC configuration, making sure PLLs are programmed correctly,
  2744. * panel fitting is in the proper state, etc.
  2745. */
  2746. static void i9xx_crtc_prepare(struct drm_crtc *crtc)
  2747. {
  2748. i9xx_crtc_disable(crtc);
  2749. }
  2750. static void i9xx_crtc_commit(struct drm_crtc *crtc)
  2751. {
  2752. i9xx_crtc_enable(crtc);
  2753. }
  2754. static void ironlake_crtc_prepare(struct drm_crtc *crtc)
  2755. {
  2756. ironlake_crtc_disable(crtc);
  2757. }
  2758. static void ironlake_crtc_commit(struct drm_crtc *crtc)
  2759. {
  2760. ironlake_crtc_enable(crtc);
  2761. }
  2762. void intel_encoder_prepare (struct drm_encoder *encoder)
  2763. {
  2764. struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
  2765. /* lvds has its own version of prepare see intel_lvds_prepare */
  2766. encoder_funcs->dpms(encoder, DRM_MODE_DPMS_OFF);
  2767. }
  2768. void intel_encoder_commit (struct drm_encoder *encoder)
  2769. {
  2770. struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
  2771. /* lvds has its own version of commit see intel_lvds_commit */
  2772. encoder_funcs->dpms(encoder, DRM_MODE_DPMS_ON);
  2773. }
  2774. void intel_encoder_destroy(struct drm_encoder *encoder)
  2775. {
  2776. struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
  2777. drm_encoder_cleanup(encoder);
  2778. kfree(intel_encoder);
  2779. }
  2780. static bool intel_crtc_mode_fixup(struct drm_crtc *crtc,
  2781. struct drm_display_mode *mode,
  2782. struct drm_display_mode *adjusted_mode)
  2783. {
  2784. struct drm_device *dev = crtc->dev;
  2785. if (HAS_PCH_SPLIT(dev)) {
  2786. /* FDI link clock is fixed at 2.7G */
  2787. if (mode->clock * 3 > IRONLAKE_FDI_FREQ * 4)
  2788. return false;
  2789. }
  2790. /* XXX some encoders set the crtcinfo, others don't.
  2791. * Obviously we need some form of conflict resolution here...
  2792. */
  2793. if (adjusted_mode->crtc_htotal == 0)
  2794. drm_mode_set_crtcinfo(adjusted_mode, 0);
  2795. return true;
  2796. }
  2797. static int i945_get_display_clock_speed(struct drm_device *dev)
  2798. {
  2799. return 400000;
  2800. }
  2801. static int i915_get_display_clock_speed(struct drm_device *dev)
  2802. {
  2803. return 333000;
  2804. }
  2805. static int i9xx_misc_get_display_clock_speed(struct drm_device *dev)
  2806. {
  2807. return 200000;
  2808. }
  2809. static int i915gm_get_display_clock_speed(struct drm_device *dev)
  2810. {
  2811. u16 gcfgc = 0;
  2812. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  2813. if (gcfgc & GC_LOW_FREQUENCY_ENABLE)
  2814. return 133000;
  2815. else {
  2816. switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
  2817. case GC_DISPLAY_CLOCK_333_MHZ:
  2818. return 333000;
  2819. default:
  2820. case GC_DISPLAY_CLOCK_190_200_MHZ:
  2821. return 190000;
  2822. }
  2823. }
  2824. }
  2825. static int i865_get_display_clock_speed(struct drm_device *dev)
  2826. {
  2827. return 266000;
  2828. }
  2829. static int i855_get_display_clock_speed(struct drm_device *dev)
  2830. {
  2831. u16 hpllcc = 0;
  2832. /* Assume that the hardware is in the high speed state. This
  2833. * should be the default.
  2834. */
  2835. switch (hpllcc & GC_CLOCK_CONTROL_MASK) {
  2836. case GC_CLOCK_133_200:
  2837. case GC_CLOCK_100_200:
  2838. return 200000;
  2839. case GC_CLOCK_166_250:
  2840. return 250000;
  2841. case GC_CLOCK_100_133:
  2842. return 133000;
  2843. }
  2844. /* Shouldn't happen */
  2845. return 0;
  2846. }
  2847. static int i830_get_display_clock_speed(struct drm_device *dev)
  2848. {
  2849. return 133000;
  2850. }
  2851. struct fdi_m_n {
  2852. u32 tu;
  2853. u32 gmch_m;
  2854. u32 gmch_n;
  2855. u32 link_m;
  2856. u32 link_n;
  2857. };
  2858. static void
  2859. fdi_reduce_ratio(u32 *num, u32 *den)
  2860. {
  2861. while (*num > 0xffffff || *den > 0xffffff) {
  2862. *num >>= 1;
  2863. *den >>= 1;
  2864. }
  2865. }
  2866. static void
  2867. ironlake_compute_m_n(int bits_per_pixel, int nlanes, int pixel_clock,
  2868. int link_clock, struct fdi_m_n *m_n)
  2869. {
  2870. m_n->tu = 64; /* default size */
  2871. /* BUG_ON(pixel_clock > INT_MAX / 36); */
  2872. m_n->gmch_m = bits_per_pixel * pixel_clock;
  2873. m_n->gmch_n = link_clock * nlanes * 8;
  2874. fdi_reduce_ratio(&m_n->gmch_m, &m_n->gmch_n);
  2875. m_n->link_m = pixel_clock;
  2876. m_n->link_n = link_clock;
  2877. fdi_reduce_ratio(&m_n->link_m, &m_n->link_n);
  2878. }
  2879. struct intel_watermark_params {
  2880. unsigned long fifo_size;
  2881. unsigned long max_wm;
  2882. unsigned long default_wm;
  2883. unsigned long guard_size;
  2884. unsigned long cacheline_size;
  2885. };
  2886. /* Pineview has different values for various configs */
  2887. static const struct intel_watermark_params pineview_display_wm = {
  2888. PINEVIEW_DISPLAY_FIFO,
  2889. PINEVIEW_MAX_WM,
  2890. PINEVIEW_DFT_WM,
  2891. PINEVIEW_GUARD_WM,
  2892. PINEVIEW_FIFO_LINE_SIZE
  2893. };
  2894. static const struct intel_watermark_params pineview_display_hplloff_wm = {
  2895. PINEVIEW_DISPLAY_FIFO,
  2896. PINEVIEW_MAX_WM,
  2897. PINEVIEW_DFT_HPLLOFF_WM,
  2898. PINEVIEW_GUARD_WM,
  2899. PINEVIEW_FIFO_LINE_SIZE
  2900. };
  2901. static const struct intel_watermark_params pineview_cursor_wm = {
  2902. PINEVIEW_CURSOR_FIFO,
  2903. PINEVIEW_CURSOR_MAX_WM,
  2904. PINEVIEW_CURSOR_DFT_WM,
  2905. PINEVIEW_CURSOR_GUARD_WM,
  2906. PINEVIEW_FIFO_LINE_SIZE,
  2907. };
  2908. static const struct intel_watermark_params pineview_cursor_hplloff_wm = {
  2909. PINEVIEW_CURSOR_FIFO,
  2910. PINEVIEW_CURSOR_MAX_WM,
  2911. PINEVIEW_CURSOR_DFT_WM,
  2912. PINEVIEW_CURSOR_GUARD_WM,
  2913. PINEVIEW_FIFO_LINE_SIZE
  2914. };
  2915. static const struct intel_watermark_params g4x_wm_info = {
  2916. G4X_FIFO_SIZE,
  2917. G4X_MAX_WM,
  2918. G4X_MAX_WM,
  2919. 2,
  2920. G4X_FIFO_LINE_SIZE,
  2921. };
  2922. static const struct intel_watermark_params g4x_cursor_wm_info = {
  2923. I965_CURSOR_FIFO,
  2924. I965_CURSOR_MAX_WM,
  2925. I965_CURSOR_DFT_WM,
  2926. 2,
  2927. G4X_FIFO_LINE_SIZE,
  2928. };
  2929. static const struct intel_watermark_params i965_cursor_wm_info = {
  2930. I965_CURSOR_FIFO,
  2931. I965_CURSOR_MAX_WM,
  2932. I965_CURSOR_DFT_WM,
  2933. 2,
  2934. I915_FIFO_LINE_SIZE,
  2935. };
  2936. static const struct intel_watermark_params i945_wm_info = {
  2937. I945_FIFO_SIZE,
  2938. I915_MAX_WM,
  2939. 1,
  2940. 2,
  2941. I915_FIFO_LINE_SIZE
  2942. };
  2943. static const struct intel_watermark_params i915_wm_info = {
  2944. I915_FIFO_SIZE,
  2945. I915_MAX_WM,
  2946. 1,
  2947. 2,
  2948. I915_FIFO_LINE_SIZE
  2949. };
  2950. static const struct intel_watermark_params i855_wm_info = {
  2951. I855GM_FIFO_SIZE,
  2952. I915_MAX_WM,
  2953. 1,
  2954. 2,
  2955. I830_FIFO_LINE_SIZE
  2956. };
  2957. static const struct intel_watermark_params i830_wm_info = {
  2958. I830_FIFO_SIZE,
  2959. I915_MAX_WM,
  2960. 1,
  2961. 2,
  2962. I830_FIFO_LINE_SIZE
  2963. };
  2964. static const struct intel_watermark_params ironlake_display_wm_info = {
  2965. ILK_DISPLAY_FIFO,
  2966. ILK_DISPLAY_MAXWM,
  2967. ILK_DISPLAY_DFTWM,
  2968. 2,
  2969. ILK_FIFO_LINE_SIZE
  2970. };
  2971. static const struct intel_watermark_params ironlake_cursor_wm_info = {
  2972. ILK_CURSOR_FIFO,
  2973. ILK_CURSOR_MAXWM,
  2974. ILK_CURSOR_DFTWM,
  2975. 2,
  2976. ILK_FIFO_LINE_SIZE
  2977. };
  2978. static const struct intel_watermark_params ironlake_display_srwm_info = {
  2979. ILK_DISPLAY_SR_FIFO,
  2980. ILK_DISPLAY_MAX_SRWM,
  2981. ILK_DISPLAY_DFT_SRWM,
  2982. 2,
  2983. ILK_FIFO_LINE_SIZE
  2984. };
  2985. static const struct intel_watermark_params ironlake_cursor_srwm_info = {
  2986. ILK_CURSOR_SR_FIFO,
  2987. ILK_CURSOR_MAX_SRWM,
  2988. ILK_CURSOR_DFT_SRWM,
  2989. 2,
  2990. ILK_FIFO_LINE_SIZE
  2991. };
  2992. static const struct intel_watermark_params sandybridge_display_wm_info = {
  2993. SNB_DISPLAY_FIFO,
  2994. SNB_DISPLAY_MAXWM,
  2995. SNB_DISPLAY_DFTWM,
  2996. 2,
  2997. SNB_FIFO_LINE_SIZE
  2998. };
  2999. static const struct intel_watermark_params sandybridge_cursor_wm_info = {
  3000. SNB_CURSOR_FIFO,
  3001. SNB_CURSOR_MAXWM,
  3002. SNB_CURSOR_DFTWM,
  3003. 2,
  3004. SNB_FIFO_LINE_SIZE
  3005. };
  3006. static const struct intel_watermark_params sandybridge_display_srwm_info = {
  3007. SNB_DISPLAY_SR_FIFO,
  3008. SNB_DISPLAY_MAX_SRWM,
  3009. SNB_DISPLAY_DFT_SRWM,
  3010. 2,
  3011. SNB_FIFO_LINE_SIZE
  3012. };
  3013. static const struct intel_watermark_params sandybridge_cursor_srwm_info = {
  3014. SNB_CURSOR_SR_FIFO,
  3015. SNB_CURSOR_MAX_SRWM,
  3016. SNB_CURSOR_DFT_SRWM,
  3017. 2,
  3018. SNB_FIFO_LINE_SIZE
  3019. };
  3020. /**
  3021. * intel_calculate_wm - calculate watermark level
  3022. * @clock_in_khz: pixel clock
  3023. * @wm: chip FIFO params
  3024. * @pixel_size: display pixel size
  3025. * @latency_ns: memory latency for the platform
  3026. *
  3027. * Calculate the watermark level (the level at which the display plane will
  3028. * start fetching from memory again). Each chip has a different display
  3029. * FIFO size and allocation, so the caller needs to figure that out and pass
  3030. * in the correct intel_watermark_params structure.
  3031. *
  3032. * As the pixel clock runs, the FIFO will be drained at a rate that depends
  3033. * on the pixel size. When it reaches the watermark level, it'll start
  3034. * fetching FIFO line sized based chunks from memory until the FIFO fills
  3035. * past the watermark point. If the FIFO drains completely, a FIFO underrun
  3036. * will occur, and a display engine hang could result.
  3037. */
  3038. static unsigned long intel_calculate_wm(unsigned long clock_in_khz,
  3039. const struct intel_watermark_params *wm,
  3040. int fifo_size,
  3041. int pixel_size,
  3042. unsigned long latency_ns)
  3043. {
  3044. long entries_required, wm_size;
  3045. /*
  3046. * Note: we need to make sure we don't overflow for various clock &
  3047. * latency values.
  3048. * clocks go from a few thousand to several hundred thousand.
  3049. * latency is usually a few thousand
  3050. */
  3051. entries_required = ((clock_in_khz / 1000) * pixel_size * latency_ns) /
  3052. 1000;
  3053. entries_required = DIV_ROUND_UP(entries_required, wm->cacheline_size);
  3054. DRM_DEBUG_KMS("FIFO entries required for mode: %d\n", entries_required);
  3055. wm_size = fifo_size - (entries_required + wm->guard_size);
  3056. DRM_DEBUG_KMS("FIFO watermark level: %d\n", wm_size);
  3057. /* Don't promote wm_size to unsigned... */
  3058. if (wm_size > (long)wm->max_wm)
  3059. wm_size = wm->max_wm;
  3060. if (wm_size <= 0)
  3061. wm_size = wm->default_wm;
  3062. return wm_size;
  3063. }
  3064. struct cxsr_latency {
  3065. int is_desktop;
  3066. int is_ddr3;
  3067. unsigned long fsb_freq;
  3068. unsigned long mem_freq;
  3069. unsigned long display_sr;
  3070. unsigned long display_hpll_disable;
  3071. unsigned long cursor_sr;
  3072. unsigned long cursor_hpll_disable;
  3073. };
  3074. static const struct cxsr_latency cxsr_latency_table[] = {
  3075. {1, 0, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */
  3076. {1, 0, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */
  3077. {1, 0, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */
  3078. {1, 1, 800, 667, 6420, 36420, 6873, 36873}, /* DDR3-667 SC */
  3079. {1, 1, 800, 800, 5902, 35902, 6318, 36318}, /* DDR3-800 SC */
  3080. {1, 0, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */
  3081. {1, 0, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */
  3082. {1, 0, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */
  3083. {1, 1, 667, 667, 6438, 36438, 6911, 36911}, /* DDR3-667 SC */
  3084. {1, 1, 667, 800, 5941, 35941, 6377, 36377}, /* DDR3-800 SC */
  3085. {1, 0, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */
  3086. {1, 0, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */
  3087. {1, 0, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */
  3088. {1, 1, 400, 667, 6509, 36509, 7062, 37062}, /* DDR3-667 SC */
  3089. {1, 1, 400, 800, 5985, 35985, 6501, 36501}, /* DDR3-800 SC */
  3090. {0, 0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */
  3091. {0, 0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */
  3092. {0, 0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */
  3093. {0, 1, 800, 667, 6476, 36476, 6955, 36955}, /* DDR3-667 SC */
  3094. {0, 1, 800, 800, 5958, 35958, 6400, 36400}, /* DDR3-800 SC */
  3095. {0, 0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */
  3096. {0, 0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */
  3097. {0, 0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */
  3098. {0, 1, 667, 667, 6494, 36494, 6993, 36993}, /* DDR3-667 SC */
  3099. {0, 1, 667, 800, 5998, 35998, 6460, 36460}, /* DDR3-800 SC */
  3100. {0, 0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */
  3101. {0, 0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */
  3102. {0, 0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */
  3103. {0, 1, 400, 667, 6566, 36566, 7145, 37145}, /* DDR3-667 SC */
  3104. {0, 1, 400, 800, 6042, 36042, 6584, 36584}, /* DDR3-800 SC */
  3105. };
  3106. static const struct cxsr_latency *intel_get_cxsr_latency(int is_desktop,
  3107. int is_ddr3,
  3108. int fsb,
  3109. int mem)
  3110. {
  3111. const struct cxsr_latency *latency;
  3112. int i;
  3113. if (fsb == 0 || mem == 0)
  3114. return NULL;
  3115. for (i = 0; i < ARRAY_SIZE(cxsr_latency_table); i++) {
  3116. latency = &cxsr_latency_table[i];
  3117. if (is_desktop == latency->is_desktop &&
  3118. is_ddr3 == latency->is_ddr3 &&
  3119. fsb == latency->fsb_freq && mem == latency->mem_freq)
  3120. return latency;
  3121. }
  3122. DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n");
  3123. return NULL;
  3124. }
  3125. static void pineview_disable_cxsr(struct drm_device *dev)
  3126. {
  3127. struct drm_i915_private *dev_priv = dev->dev_private;
  3128. /* deactivate cxsr */
  3129. I915_WRITE(DSPFW3, I915_READ(DSPFW3) & ~PINEVIEW_SELF_REFRESH_EN);
  3130. }
  3131. /*
  3132. * Latency for FIFO fetches is dependent on several factors:
  3133. * - memory configuration (speed, channels)
  3134. * - chipset
  3135. * - current MCH state
  3136. * It can be fairly high in some situations, so here we assume a fairly
  3137. * pessimal value. It's a tradeoff between extra memory fetches (if we
  3138. * set this value too high, the FIFO will fetch frequently to stay full)
  3139. * and power consumption (set it too low to save power and we might see
  3140. * FIFO underruns and display "flicker").
  3141. *
  3142. * A value of 5us seems to be a good balance; safe for very low end
  3143. * platforms but not overly aggressive on lower latency configs.
  3144. */
  3145. static const int latency_ns = 5000;
  3146. static int i9xx_get_fifo_size(struct drm_device *dev, int plane)
  3147. {
  3148. struct drm_i915_private *dev_priv = dev->dev_private;
  3149. uint32_t dsparb = I915_READ(DSPARB);
  3150. int size;
  3151. size = dsparb & 0x7f;
  3152. if (plane)
  3153. size = ((dsparb >> DSPARB_CSTART_SHIFT) & 0x7f) - size;
  3154. DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb,
  3155. plane ? "B" : "A", size);
  3156. return size;
  3157. }
  3158. static int i85x_get_fifo_size(struct drm_device *dev, int plane)
  3159. {
  3160. struct drm_i915_private *dev_priv = dev->dev_private;
  3161. uint32_t dsparb = I915_READ(DSPARB);
  3162. int size;
  3163. size = dsparb & 0x1ff;
  3164. if (plane)
  3165. size = ((dsparb >> DSPARB_BEND_SHIFT) & 0x1ff) - size;
  3166. size >>= 1; /* Convert to cachelines */
  3167. DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb,
  3168. plane ? "B" : "A", size);
  3169. return size;
  3170. }
  3171. static int i845_get_fifo_size(struct drm_device *dev, int plane)
  3172. {
  3173. struct drm_i915_private *dev_priv = dev->dev_private;
  3174. uint32_t dsparb = I915_READ(DSPARB);
  3175. int size;
  3176. size = dsparb & 0x7f;
  3177. size >>= 2; /* Convert to cachelines */
  3178. DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb,
  3179. plane ? "B" : "A",
  3180. size);
  3181. return size;
  3182. }
  3183. static int i830_get_fifo_size(struct drm_device *dev, int plane)
  3184. {
  3185. struct drm_i915_private *dev_priv = dev->dev_private;
  3186. uint32_t dsparb = I915_READ(DSPARB);
  3187. int size;
  3188. size = dsparb & 0x7f;
  3189. size >>= 1; /* Convert to cachelines */
  3190. DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb,
  3191. plane ? "B" : "A", size);
  3192. return size;
  3193. }
  3194. static struct drm_crtc *single_enabled_crtc(struct drm_device *dev)
  3195. {
  3196. struct drm_crtc *crtc, *enabled = NULL;
  3197. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  3198. if (crtc->enabled && crtc->fb) {
  3199. if (enabled)
  3200. return NULL;
  3201. enabled = crtc;
  3202. }
  3203. }
  3204. return enabled;
  3205. }
  3206. static void pineview_update_wm(struct drm_device *dev)
  3207. {
  3208. struct drm_i915_private *dev_priv = dev->dev_private;
  3209. struct drm_crtc *crtc;
  3210. const struct cxsr_latency *latency;
  3211. u32 reg;
  3212. unsigned long wm;
  3213. latency = intel_get_cxsr_latency(IS_PINEVIEW_G(dev), dev_priv->is_ddr3,
  3214. dev_priv->fsb_freq, dev_priv->mem_freq);
  3215. if (!latency) {
  3216. DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n");
  3217. pineview_disable_cxsr(dev);
  3218. return;
  3219. }
  3220. crtc = single_enabled_crtc(dev);
  3221. if (crtc) {
  3222. int clock = crtc->mode.clock;
  3223. int pixel_size = crtc->fb->bits_per_pixel / 8;
  3224. /* Display SR */
  3225. wm = intel_calculate_wm(clock, &pineview_display_wm,
  3226. pineview_display_wm.fifo_size,
  3227. pixel_size, latency->display_sr);
  3228. reg = I915_READ(DSPFW1);
  3229. reg &= ~DSPFW_SR_MASK;
  3230. reg |= wm << DSPFW_SR_SHIFT;
  3231. I915_WRITE(DSPFW1, reg);
  3232. DRM_DEBUG_KMS("DSPFW1 register is %x\n", reg);
  3233. /* cursor SR */
  3234. wm = intel_calculate_wm(clock, &pineview_cursor_wm,
  3235. pineview_display_wm.fifo_size,
  3236. pixel_size, latency->cursor_sr);
  3237. reg = I915_READ(DSPFW3);
  3238. reg &= ~DSPFW_CURSOR_SR_MASK;
  3239. reg |= (wm & 0x3f) << DSPFW_CURSOR_SR_SHIFT;
  3240. I915_WRITE(DSPFW3, reg);
  3241. /* Display HPLL off SR */
  3242. wm = intel_calculate_wm(clock, &pineview_display_hplloff_wm,
  3243. pineview_display_hplloff_wm.fifo_size,
  3244. pixel_size, latency->display_hpll_disable);
  3245. reg = I915_READ(DSPFW3);
  3246. reg &= ~DSPFW_HPLL_SR_MASK;
  3247. reg |= wm & DSPFW_HPLL_SR_MASK;
  3248. I915_WRITE(DSPFW3, reg);
  3249. /* cursor HPLL off SR */
  3250. wm = intel_calculate_wm(clock, &pineview_cursor_hplloff_wm,
  3251. pineview_display_hplloff_wm.fifo_size,
  3252. pixel_size, latency->cursor_hpll_disable);
  3253. reg = I915_READ(DSPFW3);
  3254. reg &= ~DSPFW_HPLL_CURSOR_MASK;
  3255. reg |= (wm & 0x3f) << DSPFW_HPLL_CURSOR_SHIFT;
  3256. I915_WRITE(DSPFW3, reg);
  3257. DRM_DEBUG_KMS("DSPFW3 register is %x\n", reg);
  3258. /* activate cxsr */
  3259. I915_WRITE(DSPFW3,
  3260. I915_READ(DSPFW3) | PINEVIEW_SELF_REFRESH_EN);
  3261. DRM_DEBUG_KMS("Self-refresh is enabled\n");
  3262. } else {
  3263. pineview_disable_cxsr(dev);
  3264. DRM_DEBUG_KMS("Self-refresh is disabled\n");
  3265. }
  3266. }
  3267. static bool g4x_compute_wm0(struct drm_device *dev,
  3268. int plane,
  3269. const struct intel_watermark_params *display,
  3270. int display_latency_ns,
  3271. const struct intel_watermark_params *cursor,
  3272. int cursor_latency_ns,
  3273. int *plane_wm,
  3274. int *cursor_wm)
  3275. {
  3276. struct drm_crtc *crtc;
  3277. int htotal, hdisplay, clock, pixel_size;
  3278. int line_time_us, line_count;
  3279. int entries, tlb_miss;
  3280. crtc = intel_get_crtc_for_plane(dev, plane);
  3281. if (crtc->fb == NULL || !crtc->enabled)
  3282. return false;
  3283. htotal = crtc->mode.htotal;
  3284. hdisplay = crtc->mode.hdisplay;
  3285. clock = crtc->mode.clock;
  3286. pixel_size = crtc->fb->bits_per_pixel / 8;
  3287. /* Use the small buffer method to calculate plane watermark */
  3288. entries = ((clock * pixel_size / 1000) * display_latency_ns) / 1000;
  3289. tlb_miss = display->fifo_size*display->cacheline_size - hdisplay * 8;
  3290. if (tlb_miss > 0)
  3291. entries += tlb_miss;
  3292. entries = DIV_ROUND_UP(entries, display->cacheline_size);
  3293. *plane_wm = entries + display->guard_size;
  3294. if (*plane_wm > (int)display->max_wm)
  3295. *plane_wm = display->max_wm;
  3296. /* Use the large buffer method to calculate cursor watermark */
  3297. line_time_us = ((htotal * 1000) / clock);
  3298. line_count = (cursor_latency_ns / line_time_us + 1000) / 1000;
  3299. entries = line_count * 64 * pixel_size;
  3300. tlb_miss = cursor->fifo_size*cursor->cacheline_size - hdisplay * 8;
  3301. if (tlb_miss > 0)
  3302. entries += tlb_miss;
  3303. entries = DIV_ROUND_UP(entries, cursor->cacheline_size);
  3304. *cursor_wm = entries + cursor->guard_size;
  3305. if (*cursor_wm > (int)cursor->max_wm)
  3306. *cursor_wm = (int)cursor->max_wm;
  3307. return true;
  3308. }
  3309. /*
  3310. * Check the wm result.
  3311. *
  3312. * If any calculated watermark values is larger than the maximum value that
  3313. * can be programmed into the associated watermark register, that watermark
  3314. * must be disabled.
  3315. */
  3316. static bool g4x_check_srwm(struct drm_device *dev,
  3317. int display_wm, int cursor_wm,
  3318. const struct intel_watermark_params *display,
  3319. const struct intel_watermark_params *cursor)
  3320. {
  3321. DRM_DEBUG_KMS("SR watermark: display plane %d, cursor %d\n",
  3322. display_wm, cursor_wm);
  3323. if (display_wm > display->max_wm) {
  3324. DRM_DEBUG_KMS("display watermark is too large(%d), disabling\n",
  3325. display_wm, display->max_wm);
  3326. return false;
  3327. }
  3328. if (cursor_wm > cursor->max_wm) {
  3329. DRM_DEBUG_KMS("cursor watermark is too large(%d), disabling\n",
  3330. cursor_wm, cursor->max_wm);
  3331. return false;
  3332. }
  3333. if (!(display_wm || cursor_wm)) {
  3334. DRM_DEBUG_KMS("SR latency is 0, disabling\n");
  3335. return false;
  3336. }
  3337. return true;
  3338. }
  3339. static bool g4x_compute_srwm(struct drm_device *dev,
  3340. int plane,
  3341. int latency_ns,
  3342. const struct intel_watermark_params *display,
  3343. const struct intel_watermark_params *cursor,
  3344. int *display_wm, int *cursor_wm)
  3345. {
  3346. struct drm_crtc *crtc;
  3347. int hdisplay, htotal, pixel_size, clock;
  3348. unsigned long line_time_us;
  3349. int line_count, line_size;
  3350. int small, large;
  3351. int entries;
  3352. if (!latency_ns) {
  3353. *display_wm = *cursor_wm = 0;
  3354. return false;
  3355. }
  3356. crtc = intel_get_crtc_for_plane(dev, plane);
  3357. hdisplay = crtc->mode.hdisplay;
  3358. htotal = crtc->mode.htotal;
  3359. clock = crtc->mode.clock;
  3360. pixel_size = crtc->fb->bits_per_pixel / 8;
  3361. line_time_us = (htotal * 1000) / clock;
  3362. line_count = (latency_ns / line_time_us + 1000) / 1000;
  3363. line_size = hdisplay * pixel_size;
  3364. /* Use the minimum of the small and large buffer method for primary */
  3365. small = ((clock * pixel_size / 1000) * latency_ns) / 1000;
  3366. large = line_count * line_size;
  3367. entries = DIV_ROUND_UP(min(small, large), display->cacheline_size);
  3368. *display_wm = entries + display->guard_size;
  3369. /* calculate the self-refresh watermark for display cursor */
  3370. entries = line_count * pixel_size * 64;
  3371. entries = DIV_ROUND_UP(entries, cursor->cacheline_size);
  3372. *cursor_wm = entries + cursor->guard_size;
  3373. return g4x_check_srwm(dev,
  3374. *display_wm, *cursor_wm,
  3375. display, cursor);
  3376. }
  3377. #define single_plane_enabled(mask) is_power_of_2(mask)
  3378. static void g4x_update_wm(struct drm_device *dev)
  3379. {
  3380. static const int sr_latency_ns = 12000;
  3381. struct drm_i915_private *dev_priv = dev->dev_private;
  3382. int planea_wm, planeb_wm, cursora_wm, cursorb_wm;
  3383. int plane_sr, cursor_sr;
  3384. unsigned int enabled = 0;
  3385. if (g4x_compute_wm0(dev, 0,
  3386. &g4x_wm_info, latency_ns,
  3387. &g4x_cursor_wm_info, latency_ns,
  3388. &planea_wm, &cursora_wm))
  3389. enabled |= 1;
  3390. if (g4x_compute_wm0(dev, 1,
  3391. &g4x_wm_info, latency_ns,
  3392. &g4x_cursor_wm_info, latency_ns,
  3393. &planeb_wm, &cursorb_wm))
  3394. enabled |= 2;
  3395. plane_sr = cursor_sr = 0;
  3396. if (single_plane_enabled(enabled) &&
  3397. g4x_compute_srwm(dev, ffs(enabled) - 1,
  3398. sr_latency_ns,
  3399. &g4x_wm_info,
  3400. &g4x_cursor_wm_info,
  3401. &plane_sr, &cursor_sr))
  3402. I915_WRITE(FW_BLC_SELF, FW_BLC_SELF_EN);
  3403. else
  3404. I915_WRITE(FW_BLC_SELF,
  3405. I915_READ(FW_BLC_SELF) & ~FW_BLC_SELF_EN);
  3406. DRM_DEBUG_KMS("Setting FIFO watermarks - A: plane=%d, cursor=%d, B: plane=%d, cursor=%d, SR: plane=%d, cursor=%d\n",
  3407. planea_wm, cursora_wm,
  3408. planeb_wm, cursorb_wm,
  3409. plane_sr, cursor_sr);
  3410. I915_WRITE(DSPFW1,
  3411. (plane_sr << DSPFW_SR_SHIFT) |
  3412. (cursorb_wm << DSPFW_CURSORB_SHIFT) |
  3413. (planeb_wm << DSPFW_PLANEB_SHIFT) |
  3414. planea_wm);
  3415. I915_WRITE(DSPFW2,
  3416. (I915_READ(DSPFW2) & DSPFW_CURSORA_MASK) |
  3417. (cursora_wm << DSPFW_CURSORA_SHIFT));
  3418. /* HPLL off in SR has some issues on G4x... disable it */
  3419. I915_WRITE(DSPFW3,
  3420. (I915_READ(DSPFW3) & ~DSPFW_HPLL_SR_EN) |
  3421. (cursor_sr << DSPFW_CURSOR_SR_SHIFT));
  3422. }
  3423. static void i965_update_wm(struct drm_device *dev)
  3424. {
  3425. struct drm_i915_private *dev_priv = dev->dev_private;
  3426. struct drm_crtc *crtc;
  3427. int srwm = 1;
  3428. int cursor_sr = 16;
  3429. /* Calc sr entries for one plane configs */
  3430. crtc = single_enabled_crtc(dev);
  3431. if (crtc) {
  3432. /* self-refresh has much higher latency */
  3433. static const int sr_latency_ns = 12000;
  3434. int clock = crtc->mode.clock;
  3435. int htotal = crtc->mode.htotal;
  3436. int hdisplay = crtc->mode.hdisplay;
  3437. int pixel_size = crtc->fb->bits_per_pixel / 8;
  3438. unsigned long line_time_us;
  3439. int entries;
  3440. line_time_us = ((htotal * 1000) / clock);
  3441. /* Use ns/us then divide to preserve precision */
  3442. entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) *
  3443. pixel_size * hdisplay;
  3444. entries = DIV_ROUND_UP(entries, I915_FIFO_LINE_SIZE);
  3445. srwm = I965_FIFO_SIZE - entries;
  3446. if (srwm < 0)
  3447. srwm = 1;
  3448. srwm &= 0x1ff;
  3449. DRM_DEBUG_KMS("self-refresh entries: %d, wm: %d\n",
  3450. entries, srwm);
  3451. entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) *
  3452. pixel_size * 64;
  3453. entries = DIV_ROUND_UP(entries,
  3454. i965_cursor_wm_info.cacheline_size);
  3455. cursor_sr = i965_cursor_wm_info.fifo_size -
  3456. (entries + i965_cursor_wm_info.guard_size);
  3457. if (cursor_sr > i965_cursor_wm_info.max_wm)
  3458. cursor_sr = i965_cursor_wm_info.max_wm;
  3459. DRM_DEBUG_KMS("self-refresh watermark: display plane %d "
  3460. "cursor %d\n", srwm, cursor_sr);
  3461. if (IS_CRESTLINE(dev))
  3462. I915_WRITE(FW_BLC_SELF, FW_BLC_SELF_EN);
  3463. } else {
  3464. /* Turn off self refresh if both pipes are enabled */
  3465. if (IS_CRESTLINE(dev))
  3466. I915_WRITE(FW_BLC_SELF, I915_READ(FW_BLC_SELF)
  3467. & ~FW_BLC_SELF_EN);
  3468. }
  3469. DRM_DEBUG_KMS("Setting FIFO watermarks - A: 8, B: 8, C: 8, SR %d\n",
  3470. srwm);
  3471. /* 965 has limitations... */
  3472. I915_WRITE(DSPFW1, (srwm << DSPFW_SR_SHIFT) |
  3473. (8 << 16) | (8 << 8) | (8 << 0));
  3474. I915_WRITE(DSPFW2, (8 << 8) | (8 << 0));
  3475. /* update cursor SR watermark */
  3476. I915_WRITE(DSPFW3, (cursor_sr << DSPFW_CURSOR_SR_SHIFT));
  3477. }
  3478. static void i9xx_update_wm(struct drm_device *dev)
  3479. {
  3480. struct drm_i915_private *dev_priv = dev->dev_private;
  3481. const struct intel_watermark_params *wm_info;
  3482. uint32_t fwater_lo;
  3483. uint32_t fwater_hi;
  3484. int cwm, srwm = 1;
  3485. int fifo_size;
  3486. int planea_wm, planeb_wm;
  3487. struct drm_crtc *crtc, *enabled = NULL;
  3488. if (IS_I945GM(dev))
  3489. wm_info = &i945_wm_info;
  3490. else if (!IS_GEN2(dev))
  3491. wm_info = &i915_wm_info;
  3492. else
  3493. wm_info = &i855_wm_info;
  3494. fifo_size = dev_priv->display.get_fifo_size(dev, 0);
  3495. crtc = intel_get_crtc_for_plane(dev, 0);
  3496. if (crtc->enabled && crtc->fb) {
  3497. planea_wm = intel_calculate_wm(crtc->mode.clock,
  3498. wm_info, fifo_size,
  3499. crtc->fb->bits_per_pixel / 8,
  3500. latency_ns);
  3501. enabled = crtc;
  3502. } else
  3503. planea_wm = fifo_size - wm_info->guard_size;
  3504. fifo_size = dev_priv->display.get_fifo_size(dev, 1);
  3505. crtc = intel_get_crtc_for_plane(dev, 1);
  3506. if (crtc->enabled && crtc->fb) {
  3507. planeb_wm = intel_calculate_wm(crtc->mode.clock,
  3508. wm_info, fifo_size,
  3509. crtc->fb->bits_per_pixel / 8,
  3510. latency_ns);
  3511. if (enabled == NULL)
  3512. enabled = crtc;
  3513. else
  3514. enabled = NULL;
  3515. } else
  3516. planeb_wm = fifo_size - wm_info->guard_size;
  3517. DRM_DEBUG_KMS("FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm);
  3518. /*
  3519. * Overlay gets an aggressive default since video jitter is bad.
  3520. */
  3521. cwm = 2;
  3522. /* Play safe and disable self-refresh before adjusting watermarks. */
  3523. if (IS_I945G(dev) || IS_I945GM(dev))
  3524. I915_WRITE(FW_BLC_SELF, FW_BLC_SELF_EN_MASK | 0);
  3525. else if (IS_I915GM(dev))
  3526. I915_WRITE(INSTPM, I915_READ(INSTPM) & ~INSTPM_SELF_EN);
  3527. /* Calc sr entries for one plane configs */
  3528. if (HAS_FW_BLC(dev) && enabled) {
  3529. /* self-refresh has much higher latency */
  3530. static const int sr_latency_ns = 6000;
  3531. int clock = enabled->mode.clock;
  3532. int htotal = enabled->mode.htotal;
  3533. int hdisplay = enabled->mode.hdisplay;
  3534. int pixel_size = enabled->fb->bits_per_pixel / 8;
  3535. unsigned long line_time_us;
  3536. int entries;
  3537. line_time_us = (htotal * 1000) / clock;
  3538. /* Use ns/us then divide to preserve precision */
  3539. entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) *
  3540. pixel_size * hdisplay;
  3541. entries = DIV_ROUND_UP(entries, wm_info->cacheline_size);
  3542. DRM_DEBUG_KMS("self-refresh entries: %d\n", entries);
  3543. srwm = wm_info->fifo_size - entries;
  3544. if (srwm < 0)
  3545. srwm = 1;
  3546. if (IS_I945G(dev) || IS_I945GM(dev))
  3547. I915_WRITE(FW_BLC_SELF,
  3548. FW_BLC_SELF_FIFO_MASK | (srwm & 0xff));
  3549. else if (IS_I915GM(dev))
  3550. I915_WRITE(FW_BLC_SELF, srwm & 0x3f);
  3551. }
  3552. DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n",
  3553. planea_wm, planeb_wm, cwm, srwm);
  3554. fwater_lo = ((planeb_wm & 0x3f) << 16) | (planea_wm & 0x3f);
  3555. fwater_hi = (cwm & 0x1f);
  3556. /* Set request length to 8 cachelines per fetch */
  3557. fwater_lo = fwater_lo | (1 << 24) | (1 << 8);
  3558. fwater_hi = fwater_hi | (1 << 8);
  3559. I915_WRITE(FW_BLC, fwater_lo);
  3560. I915_WRITE(FW_BLC2, fwater_hi);
  3561. if (HAS_FW_BLC(dev)) {
  3562. if (enabled) {
  3563. if (IS_I945G(dev) || IS_I945GM(dev))
  3564. I915_WRITE(FW_BLC_SELF,
  3565. FW_BLC_SELF_EN_MASK | FW_BLC_SELF_EN);
  3566. else if (IS_I915GM(dev))
  3567. I915_WRITE(INSTPM, I915_READ(INSTPM) | INSTPM_SELF_EN);
  3568. DRM_DEBUG_KMS("memory self refresh enabled\n");
  3569. } else
  3570. DRM_DEBUG_KMS("memory self refresh disabled\n");
  3571. }
  3572. }
  3573. static void i830_update_wm(struct drm_device *dev)
  3574. {
  3575. struct drm_i915_private *dev_priv = dev->dev_private;
  3576. struct drm_crtc *crtc;
  3577. uint32_t fwater_lo;
  3578. int planea_wm;
  3579. crtc = single_enabled_crtc(dev);
  3580. if (crtc == NULL)
  3581. return;
  3582. planea_wm = intel_calculate_wm(crtc->mode.clock, &i830_wm_info,
  3583. dev_priv->display.get_fifo_size(dev, 0),
  3584. crtc->fb->bits_per_pixel / 8,
  3585. latency_ns);
  3586. fwater_lo = I915_READ(FW_BLC) & ~0xfff;
  3587. fwater_lo |= (3<<8) | planea_wm;
  3588. DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d\n", planea_wm);
  3589. I915_WRITE(FW_BLC, fwater_lo);
  3590. }
  3591. #define ILK_LP0_PLANE_LATENCY 700
  3592. #define ILK_LP0_CURSOR_LATENCY 1300
  3593. static bool ironlake_compute_wm0(struct drm_device *dev,
  3594. int pipe,
  3595. const struct intel_watermark_params *display,
  3596. int display_latency_ns,
  3597. const struct intel_watermark_params *cursor,
  3598. int cursor_latency_ns,
  3599. int *plane_wm,
  3600. int *cursor_wm)
  3601. {
  3602. struct drm_crtc *crtc;
  3603. int htotal, hdisplay, clock, pixel_size;
  3604. int line_time_us, line_count;
  3605. int entries, tlb_miss;
  3606. crtc = intel_get_crtc_for_pipe(dev, pipe);
  3607. if (crtc->fb == NULL || !crtc->enabled)
  3608. return false;
  3609. htotal = crtc->mode.htotal;
  3610. hdisplay = crtc->mode.hdisplay;
  3611. clock = crtc->mode.clock;
  3612. pixel_size = crtc->fb->bits_per_pixel / 8;
  3613. /* Use the small buffer method to calculate plane watermark */
  3614. entries = ((clock * pixel_size / 1000) * display_latency_ns) / 1000;
  3615. tlb_miss = display->fifo_size*display->cacheline_size - hdisplay * 8;
  3616. if (tlb_miss > 0)
  3617. entries += tlb_miss;
  3618. entries = DIV_ROUND_UP(entries, display->cacheline_size);
  3619. *plane_wm = entries + display->guard_size;
  3620. if (*plane_wm > (int)display->max_wm)
  3621. *plane_wm = display->max_wm;
  3622. /* Use the large buffer method to calculate cursor watermark */
  3623. line_time_us = ((htotal * 1000) / clock);
  3624. line_count = (cursor_latency_ns / line_time_us + 1000) / 1000;
  3625. entries = line_count * 64 * pixel_size;
  3626. tlb_miss = cursor->fifo_size*cursor->cacheline_size - hdisplay * 8;
  3627. if (tlb_miss > 0)
  3628. entries += tlb_miss;
  3629. entries = DIV_ROUND_UP(entries, cursor->cacheline_size);
  3630. *cursor_wm = entries + cursor->guard_size;
  3631. if (*cursor_wm > (int)cursor->max_wm)
  3632. *cursor_wm = (int)cursor->max_wm;
  3633. return true;
  3634. }
  3635. /*
  3636. * Check the wm result.
  3637. *
  3638. * If any calculated watermark values is larger than the maximum value that
  3639. * can be programmed into the associated watermark register, that watermark
  3640. * must be disabled.
  3641. */
  3642. static bool ironlake_check_srwm(struct drm_device *dev, int level,
  3643. int fbc_wm, int display_wm, int cursor_wm,
  3644. const struct intel_watermark_params *display,
  3645. const struct intel_watermark_params *cursor)
  3646. {
  3647. struct drm_i915_private *dev_priv = dev->dev_private;
  3648. DRM_DEBUG_KMS("watermark %d: display plane %d, fbc lines %d,"
  3649. " cursor %d\n", level, display_wm, fbc_wm, cursor_wm);
  3650. if (fbc_wm > SNB_FBC_MAX_SRWM) {
  3651. DRM_DEBUG_KMS("fbc watermark(%d) is too large(%d), disabling wm%d+\n",
  3652. fbc_wm, SNB_FBC_MAX_SRWM, level);
  3653. /* fbc has it's own way to disable FBC WM */
  3654. I915_WRITE(DISP_ARB_CTL,
  3655. I915_READ(DISP_ARB_CTL) | DISP_FBC_WM_DIS);
  3656. return false;
  3657. }
  3658. if (display_wm > display->max_wm) {
  3659. DRM_DEBUG_KMS("display watermark(%d) is too large(%d), disabling wm%d+\n",
  3660. display_wm, SNB_DISPLAY_MAX_SRWM, level);
  3661. return false;
  3662. }
  3663. if (cursor_wm > cursor->max_wm) {
  3664. DRM_DEBUG_KMS("cursor watermark(%d) is too large(%d), disabling wm%d+\n",
  3665. cursor_wm, SNB_CURSOR_MAX_SRWM, level);
  3666. return false;
  3667. }
  3668. if (!(fbc_wm || display_wm || cursor_wm)) {
  3669. DRM_DEBUG_KMS("latency %d is 0, disabling wm%d+\n", level, level);
  3670. return false;
  3671. }
  3672. return true;
  3673. }
  3674. /*
  3675. * Compute watermark values of WM[1-3],
  3676. */
  3677. static bool ironlake_compute_srwm(struct drm_device *dev, int level, int plane,
  3678. int latency_ns,
  3679. const struct intel_watermark_params *display,
  3680. const struct intel_watermark_params *cursor,
  3681. int *fbc_wm, int *display_wm, int *cursor_wm)
  3682. {
  3683. struct drm_crtc *crtc;
  3684. unsigned long line_time_us;
  3685. int hdisplay, htotal, pixel_size, clock;
  3686. int line_count, line_size;
  3687. int small, large;
  3688. int entries;
  3689. if (!latency_ns) {
  3690. *fbc_wm = *display_wm = *cursor_wm = 0;
  3691. return false;
  3692. }
  3693. crtc = intel_get_crtc_for_plane(dev, plane);
  3694. hdisplay = crtc->mode.hdisplay;
  3695. htotal = crtc->mode.htotal;
  3696. clock = crtc->mode.clock;
  3697. pixel_size = crtc->fb->bits_per_pixel / 8;
  3698. line_time_us = (htotal * 1000) / clock;
  3699. line_count = (latency_ns / line_time_us + 1000) / 1000;
  3700. line_size = hdisplay * pixel_size;
  3701. /* Use the minimum of the small and large buffer method for primary */
  3702. small = ((clock * pixel_size / 1000) * latency_ns) / 1000;
  3703. large = line_count * line_size;
  3704. entries = DIV_ROUND_UP(min(small, large), display->cacheline_size);
  3705. *display_wm = entries + display->guard_size;
  3706. /*
  3707. * Spec says:
  3708. * FBC WM = ((Final Primary WM * 64) / number of bytes per line) + 2
  3709. */
  3710. *fbc_wm = DIV_ROUND_UP(*display_wm * 64, line_size) + 2;
  3711. /* calculate the self-refresh watermark for display cursor */
  3712. entries = line_count * pixel_size * 64;
  3713. entries = DIV_ROUND_UP(entries, cursor->cacheline_size);
  3714. *cursor_wm = entries + cursor->guard_size;
  3715. return ironlake_check_srwm(dev, level,
  3716. *fbc_wm, *display_wm, *cursor_wm,
  3717. display, cursor);
  3718. }
  3719. static void ironlake_update_wm(struct drm_device *dev)
  3720. {
  3721. struct drm_i915_private *dev_priv = dev->dev_private;
  3722. int fbc_wm, plane_wm, cursor_wm;
  3723. unsigned int enabled;
  3724. enabled = 0;
  3725. if (ironlake_compute_wm0(dev, 0,
  3726. &ironlake_display_wm_info,
  3727. ILK_LP0_PLANE_LATENCY,
  3728. &ironlake_cursor_wm_info,
  3729. ILK_LP0_CURSOR_LATENCY,
  3730. &plane_wm, &cursor_wm)) {
  3731. I915_WRITE(WM0_PIPEA_ILK,
  3732. (plane_wm << WM0_PIPE_PLANE_SHIFT) | cursor_wm);
  3733. DRM_DEBUG_KMS("FIFO watermarks For pipe A -"
  3734. " plane %d, " "cursor: %d\n",
  3735. plane_wm, cursor_wm);
  3736. enabled |= 1;
  3737. }
  3738. if (ironlake_compute_wm0(dev, 1,
  3739. &ironlake_display_wm_info,
  3740. ILK_LP0_PLANE_LATENCY,
  3741. &ironlake_cursor_wm_info,
  3742. ILK_LP0_CURSOR_LATENCY,
  3743. &plane_wm, &cursor_wm)) {
  3744. I915_WRITE(WM0_PIPEB_ILK,
  3745. (plane_wm << WM0_PIPE_PLANE_SHIFT) | cursor_wm);
  3746. DRM_DEBUG_KMS("FIFO watermarks For pipe B -"
  3747. " plane %d, cursor: %d\n",
  3748. plane_wm, cursor_wm);
  3749. enabled |= 2;
  3750. }
  3751. /*
  3752. * Calculate and update the self-refresh watermark only when one
  3753. * display plane is used.
  3754. */
  3755. I915_WRITE(WM3_LP_ILK, 0);
  3756. I915_WRITE(WM2_LP_ILK, 0);
  3757. I915_WRITE(WM1_LP_ILK, 0);
  3758. if (!single_plane_enabled(enabled))
  3759. return;
  3760. enabled = ffs(enabled) - 1;
  3761. /* WM1 */
  3762. if (!ironlake_compute_srwm(dev, 1, enabled,
  3763. ILK_READ_WM1_LATENCY() * 500,
  3764. &ironlake_display_srwm_info,
  3765. &ironlake_cursor_srwm_info,
  3766. &fbc_wm, &plane_wm, &cursor_wm))
  3767. return;
  3768. I915_WRITE(WM1_LP_ILK,
  3769. WM1_LP_SR_EN |
  3770. (ILK_READ_WM1_LATENCY() << WM1_LP_LATENCY_SHIFT) |
  3771. (fbc_wm << WM1_LP_FBC_SHIFT) |
  3772. (plane_wm << WM1_LP_SR_SHIFT) |
  3773. cursor_wm);
  3774. /* WM2 */
  3775. if (!ironlake_compute_srwm(dev, 2, enabled,
  3776. ILK_READ_WM2_LATENCY() * 500,
  3777. &ironlake_display_srwm_info,
  3778. &ironlake_cursor_srwm_info,
  3779. &fbc_wm, &plane_wm, &cursor_wm))
  3780. return;
  3781. I915_WRITE(WM2_LP_ILK,
  3782. WM2_LP_EN |
  3783. (ILK_READ_WM2_LATENCY() << WM1_LP_LATENCY_SHIFT) |
  3784. (fbc_wm << WM1_LP_FBC_SHIFT) |
  3785. (plane_wm << WM1_LP_SR_SHIFT) |
  3786. cursor_wm);
  3787. /*
  3788. * WM3 is unsupported on ILK, probably because we don't have latency
  3789. * data for that power state
  3790. */
  3791. }
  3792. static void sandybridge_update_wm(struct drm_device *dev)
  3793. {
  3794. struct drm_i915_private *dev_priv = dev->dev_private;
  3795. int latency = SNB_READ_WM0_LATENCY() * 100; /* In unit 0.1us */
  3796. int fbc_wm, plane_wm, cursor_wm;
  3797. unsigned int enabled;
  3798. enabled = 0;
  3799. if (ironlake_compute_wm0(dev, 0,
  3800. &sandybridge_display_wm_info, latency,
  3801. &sandybridge_cursor_wm_info, latency,
  3802. &plane_wm, &cursor_wm)) {
  3803. I915_WRITE(WM0_PIPEA_ILK,
  3804. (plane_wm << WM0_PIPE_PLANE_SHIFT) | cursor_wm);
  3805. DRM_DEBUG_KMS("FIFO watermarks For pipe A -"
  3806. " plane %d, " "cursor: %d\n",
  3807. plane_wm, cursor_wm);
  3808. enabled |= 1;
  3809. }
  3810. if (ironlake_compute_wm0(dev, 1,
  3811. &sandybridge_display_wm_info, latency,
  3812. &sandybridge_cursor_wm_info, latency,
  3813. &plane_wm, &cursor_wm)) {
  3814. I915_WRITE(WM0_PIPEB_ILK,
  3815. (plane_wm << WM0_PIPE_PLANE_SHIFT) | cursor_wm);
  3816. DRM_DEBUG_KMS("FIFO watermarks For pipe B -"
  3817. " plane %d, cursor: %d\n",
  3818. plane_wm, cursor_wm);
  3819. enabled |= 2;
  3820. }
  3821. /*
  3822. * Calculate and update the self-refresh watermark only when one
  3823. * display plane is used.
  3824. *
  3825. * SNB support 3 levels of watermark.
  3826. *
  3827. * WM1/WM2/WM2 watermarks have to be enabled in the ascending order,
  3828. * and disabled in the descending order
  3829. *
  3830. */
  3831. I915_WRITE(WM3_LP_ILK, 0);
  3832. I915_WRITE(WM2_LP_ILK, 0);
  3833. I915_WRITE(WM1_LP_ILK, 0);
  3834. if (!single_plane_enabled(enabled))
  3835. return;
  3836. enabled = ffs(enabled) - 1;
  3837. /* WM1 */
  3838. if (!ironlake_compute_srwm(dev, 1, enabled,
  3839. SNB_READ_WM1_LATENCY() * 500,
  3840. &sandybridge_display_srwm_info,
  3841. &sandybridge_cursor_srwm_info,
  3842. &fbc_wm, &plane_wm, &cursor_wm))
  3843. return;
  3844. I915_WRITE(WM1_LP_ILK,
  3845. WM1_LP_SR_EN |
  3846. (SNB_READ_WM1_LATENCY() << WM1_LP_LATENCY_SHIFT) |
  3847. (fbc_wm << WM1_LP_FBC_SHIFT) |
  3848. (plane_wm << WM1_LP_SR_SHIFT) |
  3849. cursor_wm);
  3850. /* WM2 */
  3851. if (!ironlake_compute_srwm(dev, 2, enabled,
  3852. SNB_READ_WM2_LATENCY() * 500,
  3853. &sandybridge_display_srwm_info,
  3854. &sandybridge_cursor_srwm_info,
  3855. &fbc_wm, &plane_wm, &cursor_wm))
  3856. return;
  3857. I915_WRITE(WM2_LP_ILK,
  3858. WM2_LP_EN |
  3859. (SNB_READ_WM2_LATENCY() << WM1_LP_LATENCY_SHIFT) |
  3860. (fbc_wm << WM1_LP_FBC_SHIFT) |
  3861. (plane_wm << WM1_LP_SR_SHIFT) |
  3862. cursor_wm);
  3863. /* WM3 */
  3864. if (!ironlake_compute_srwm(dev, 3, enabled,
  3865. SNB_READ_WM3_LATENCY() * 500,
  3866. &sandybridge_display_srwm_info,
  3867. &sandybridge_cursor_srwm_info,
  3868. &fbc_wm, &plane_wm, &cursor_wm))
  3869. return;
  3870. I915_WRITE(WM3_LP_ILK,
  3871. WM3_LP_EN |
  3872. (SNB_READ_WM3_LATENCY() << WM1_LP_LATENCY_SHIFT) |
  3873. (fbc_wm << WM1_LP_FBC_SHIFT) |
  3874. (plane_wm << WM1_LP_SR_SHIFT) |
  3875. cursor_wm);
  3876. }
  3877. /**
  3878. * intel_update_watermarks - update FIFO watermark values based on current modes
  3879. *
  3880. * Calculate watermark values for the various WM regs based on current mode
  3881. * and plane configuration.
  3882. *
  3883. * There are several cases to deal with here:
  3884. * - normal (i.e. non-self-refresh)
  3885. * - self-refresh (SR) mode
  3886. * - lines are large relative to FIFO size (buffer can hold up to 2)
  3887. * - lines are small relative to FIFO size (buffer can hold more than 2
  3888. * lines), so need to account for TLB latency
  3889. *
  3890. * The normal calculation is:
  3891. * watermark = dotclock * bytes per pixel * latency
  3892. * where latency is platform & configuration dependent (we assume pessimal
  3893. * values here).
  3894. *
  3895. * The SR calculation is:
  3896. * watermark = (trunc(latency/line time)+1) * surface width *
  3897. * bytes per pixel
  3898. * where
  3899. * line time = htotal / dotclock
  3900. * surface width = hdisplay for normal plane and 64 for cursor
  3901. * and latency is assumed to be high, as above.
  3902. *
  3903. * The final value programmed to the register should always be rounded up,
  3904. * and include an extra 2 entries to account for clock crossings.
  3905. *
  3906. * We don't use the sprite, so we can ignore that. And on Crestline we have
  3907. * to set the non-SR watermarks to 8.
  3908. */
  3909. static void intel_update_watermarks(struct drm_device *dev)
  3910. {
  3911. struct drm_i915_private *dev_priv = dev->dev_private;
  3912. if (dev_priv->display.update_wm)
  3913. dev_priv->display.update_wm(dev);
  3914. }
  3915. static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
  3916. {
  3917. return dev_priv->lvds_use_ssc && i915_panel_use_ssc;
  3918. }
  3919. static int intel_crtc_mode_set(struct drm_crtc *crtc,
  3920. struct drm_display_mode *mode,
  3921. struct drm_display_mode *adjusted_mode,
  3922. int x, int y,
  3923. struct drm_framebuffer *old_fb)
  3924. {
  3925. struct drm_device *dev = crtc->dev;
  3926. struct drm_i915_private *dev_priv = dev->dev_private;
  3927. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3928. int pipe = intel_crtc->pipe;
  3929. int plane = intel_crtc->plane;
  3930. u32 fp_reg, dpll_reg;
  3931. int refclk, num_connectors = 0;
  3932. intel_clock_t clock, reduced_clock;
  3933. u32 dpll, fp = 0, fp2 = 0, dspcntr, pipeconf;
  3934. bool ok, has_reduced_clock = false, is_sdvo = false, is_dvo = false;
  3935. bool is_crt = false, is_lvds = false, is_tv = false, is_dp = false;
  3936. struct intel_encoder *has_edp_encoder = NULL;
  3937. struct drm_mode_config *mode_config = &dev->mode_config;
  3938. struct intel_encoder *encoder;
  3939. const intel_limit_t *limit;
  3940. int ret;
  3941. struct fdi_m_n m_n = {0};
  3942. u32 reg, temp;
  3943. u32 lvds_sync = 0;
  3944. int target_clock;
  3945. drm_vblank_pre_modeset(dev, pipe);
  3946. list_for_each_entry(encoder, &mode_config->encoder_list, base.head) {
  3947. if (encoder->base.crtc != crtc)
  3948. continue;
  3949. switch (encoder->type) {
  3950. case INTEL_OUTPUT_LVDS:
  3951. is_lvds = true;
  3952. break;
  3953. case INTEL_OUTPUT_SDVO:
  3954. case INTEL_OUTPUT_HDMI:
  3955. is_sdvo = true;
  3956. if (encoder->needs_tv_clock)
  3957. is_tv = true;
  3958. break;
  3959. case INTEL_OUTPUT_DVO:
  3960. is_dvo = true;
  3961. break;
  3962. case INTEL_OUTPUT_TVOUT:
  3963. is_tv = true;
  3964. break;
  3965. case INTEL_OUTPUT_ANALOG:
  3966. is_crt = true;
  3967. break;
  3968. case INTEL_OUTPUT_DISPLAYPORT:
  3969. is_dp = true;
  3970. break;
  3971. case INTEL_OUTPUT_EDP:
  3972. has_edp_encoder = encoder;
  3973. break;
  3974. }
  3975. num_connectors++;
  3976. }
  3977. if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
  3978. refclk = dev_priv->lvds_ssc_freq * 1000;
  3979. DRM_DEBUG_KMS("using SSC reference clock of %d MHz\n",
  3980. refclk / 1000);
  3981. } else if (!IS_GEN2(dev)) {
  3982. refclk = 96000;
  3983. if (HAS_PCH_SPLIT(dev) &&
  3984. (!has_edp_encoder || intel_encoder_is_pch_edp(&has_edp_encoder->base)))
  3985. refclk = 120000; /* 120Mhz refclk */
  3986. } else {
  3987. refclk = 48000;
  3988. }
  3989. /*
  3990. * Returns a set of divisors for the desired target clock with the given
  3991. * refclk, or FALSE. The returned values represent the clock equation:
  3992. * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
  3993. */
  3994. limit = intel_limit(crtc, refclk);
  3995. ok = limit->find_pll(limit, crtc, adjusted_mode->clock, refclk, &clock);
  3996. if (!ok) {
  3997. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  3998. drm_vblank_post_modeset(dev, pipe);
  3999. return -EINVAL;
  4000. }
  4001. /* Ensure that the cursor is valid for the new mode before changing... */
  4002. intel_crtc_update_cursor(crtc, true);
  4003. if (is_lvds && dev_priv->lvds_downclock_avail) {
  4004. has_reduced_clock = limit->find_pll(limit, crtc,
  4005. dev_priv->lvds_downclock,
  4006. refclk,
  4007. &reduced_clock);
  4008. if (has_reduced_clock && (clock.p != reduced_clock.p)) {
  4009. /*
  4010. * If the different P is found, it means that we can't
  4011. * switch the display clock by using the FP0/FP1.
  4012. * In such case we will disable the LVDS downclock
  4013. * feature.
  4014. */
  4015. DRM_DEBUG_KMS("Different P is found for "
  4016. "LVDS clock/downclock\n");
  4017. has_reduced_clock = 0;
  4018. }
  4019. }
  4020. /* SDVO TV has fixed PLL values depend on its clock range,
  4021. this mirrors vbios setting. */
  4022. if (is_sdvo && is_tv) {
  4023. if (adjusted_mode->clock >= 100000
  4024. && adjusted_mode->clock < 140500) {
  4025. clock.p1 = 2;
  4026. clock.p2 = 10;
  4027. clock.n = 3;
  4028. clock.m1 = 16;
  4029. clock.m2 = 8;
  4030. } else if (adjusted_mode->clock >= 140500
  4031. && adjusted_mode->clock <= 200000) {
  4032. clock.p1 = 1;
  4033. clock.p2 = 10;
  4034. clock.n = 6;
  4035. clock.m1 = 12;
  4036. clock.m2 = 8;
  4037. }
  4038. }
  4039. /* FDI link */
  4040. if (HAS_PCH_SPLIT(dev)) {
  4041. int pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
  4042. int lane = 0, link_bw, bpp;
  4043. /* CPU eDP doesn't require FDI link, so just set DP M/N
  4044. according to current link config */
  4045. if (has_edp_encoder && !intel_encoder_is_pch_edp(&has_edp_encoder->base)) {
  4046. target_clock = mode->clock;
  4047. intel_edp_link_config(has_edp_encoder,
  4048. &lane, &link_bw);
  4049. } else {
  4050. /* [e]DP over FDI requires target mode clock
  4051. instead of link clock */
  4052. if (is_dp || intel_encoder_is_pch_edp(&has_edp_encoder->base))
  4053. target_clock = mode->clock;
  4054. else
  4055. target_clock = adjusted_mode->clock;
  4056. /* FDI is a binary signal running at ~2.7GHz, encoding
  4057. * each output octet as 10 bits. The actual frequency
  4058. * is stored as a divider into a 100MHz clock, and the
  4059. * mode pixel clock is stored in units of 1KHz.
  4060. * Hence the bw of each lane in terms of the mode signal
  4061. * is:
  4062. */
  4063. link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10;
  4064. }
  4065. /* determine panel color depth */
  4066. temp = I915_READ(PIPECONF(pipe));
  4067. temp &= ~PIPE_BPC_MASK;
  4068. if (is_lvds) {
  4069. /* the BPC will be 6 if it is 18-bit LVDS panel */
  4070. if ((I915_READ(PCH_LVDS) & LVDS_A3_POWER_MASK) == LVDS_A3_POWER_UP)
  4071. temp |= PIPE_8BPC;
  4072. else
  4073. temp |= PIPE_6BPC;
  4074. } else if (has_edp_encoder) {
  4075. switch (dev_priv->edp.bpp/3) {
  4076. case 8:
  4077. temp |= PIPE_8BPC;
  4078. break;
  4079. case 10:
  4080. temp |= PIPE_10BPC;
  4081. break;
  4082. case 6:
  4083. temp |= PIPE_6BPC;
  4084. break;
  4085. case 12:
  4086. temp |= PIPE_12BPC;
  4087. break;
  4088. }
  4089. } else
  4090. temp |= PIPE_8BPC;
  4091. I915_WRITE(PIPECONF(pipe), temp);
  4092. switch (temp & PIPE_BPC_MASK) {
  4093. case PIPE_8BPC:
  4094. bpp = 24;
  4095. break;
  4096. case PIPE_10BPC:
  4097. bpp = 30;
  4098. break;
  4099. case PIPE_6BPC:
  4100. bpp = 18;
  4101. break;
  4102. case PIPE_12BPC:
  4103. bpp = 36;
  4104. break;
  4105. default:
  4106. DRM_ERROR("unknown pipe bpc value\n");
  4107. bpp = 24;
  4108. }
  4109. if (!lane) {
  4110. /*
  4111. * Account for spread spectrum to avoid
  4112. * oversubscribing the link. Max center spread
  4113. * is 2.5%; use 5% for safety's sake.
  4114. */
  4115. u32 bps = target_clock * bpp * 21 / 20;
  4116. lane = bps / (link_bw * 8) + 1;
  4117. }
  4118. intel_crtc->fdi_lanes = lane;
  4119. if (pixel_multiplier > 1)
  4120. link_bw *= pixel_multiplier;
  4121. ironlake_compute_m_n(bpp, lane, target_clock, link_bw, &m_n);
  4122. }
  4123. /* Ironlake: try to setup display ref clock before DPLL
  4124. * enabling. This is only under driver's control after
  4125. * PCH B stepping, previous chipset stepping should be
  4126. * ignoring this setting.
  4127. */
  4128. if (HAS_PCH_SPLIT(dev)) {
  4129. temp = I915_READ(PCH_DREF_CONTROL);
  4130. /* Always enable nonspread source */
  4131. temp &= ~DREF_NONSPREAD_SOURCE_MASK;
  4132. temp |= DREF_NONSPREAD_SOURCE_ENABLE;
  4133. temp &= ~DREF_SSC_SOURCE_MASK;
  4134. temp |= DREF_SSC_SOURCE_ENABLE;
  4135. I915_WRITE(PCH_DREF_CONTROL, temp);
  4136. POSTING_READ(PCH_DREF_CONTROL);
  4137. udelay(200);
  4138. if (has_edp_encoder) {
  4139. if (intel_panel_use_ssc(dev_priv)) {
  4140. temp |= DREF_SSC1_ENABLE;
  4141. I915_WRITE(PCH_DREF_CONTROL, temp);
  4142. POSTING_READ(PCH_DREF_CONTROL);
  4143. udelay(200);
  4144. }
  4145. temp &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  4146. /* Enable CPU source on CPU attached eDP */
  4147. if (!intel_encoder_is_pch_edp(&has_edp_encoder->base)) {
  4148. if (intel_panel_use_ssc(dev_priv))
  4149. temp |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
  4150. else
  4151. temp |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
  4152. } else {
  4153. /* Enable SSC on PCH eDP if needed */
  4154. if (intel_panel_use_ssc(dev_priv)) {
  4155. DRM_ERROR("enabling SSC on PCH\n");
  4156. temp |= DREF_SUPERSPREAD_SOURCE_ENABLE;
  4157. }
  4158. }
  4159. I915_WRITE(PCH_DREF_CONTROL, temp);
  4160. POSTING_READ(PCH_DREF_CONTROL);
  4161. udelay(200);
  4162. }
  4163. }
  4164. if (IS_PINEVIEW(dev)) {
  4165. fp = (1 << clock.n) << 16 | clock.m1 << 8 | clock.m2;
  4166. if (has_reduced_clock)
  4167. fp2 = (1 << reduced_clock.n) << 16 |
  4168. reduced_clock.m1 << 8 | reduced_clock.m2;
  4169. } else {
  4170. fp = clock.n << 16 | clock.m1 << 8 | clock.m2;
  4171. if (has_reduced_clock)
  4172. fp2 = reduced_clock.n << 16 | reduced_clock.m1 << 8 |
  4173. reduced_clock.m2;
  4174. }
  4175. /* Enable autotuning of the PLL clock (if permissible) */
  4176. if (HAS_PCH_SPLIT(dev)) {
  4177. int factor = 21;
  4178. if (is_lvds) {
  4179. if ((intel_panel_use_ssc(dev_priv) &&
  4180. dev_priv->lvds_ssc_freq == 100) ||
  4181. (I915_READ(PCH_LVDS) & LVDS_CLKB_POWER_MASK) == LVDS_CLKB_POWER_UP)
  4182. factor = 25;
  4183. } else if (is_sdvo && is_tv)
  4184. factor = 20;
  4185. if (clock.m1 < factor * clock.n)
  4186. fp |= FP_CB_TUNE;
  4187. }
  4188. dpll = 0;
  4189. if (!HAS_PCH_SPLIT(dev))
  4190. dpll = DPLL_VGA_MODE_DIS;
  4191. if (!IS_GEN2(dev)) {
  4192. if (is_lvds)
  4193. dpll |= DPLLB_MODE_LVDS;
  4194. else
  4195. dpll |= DPLLB_MODE_DAC_SERIAL;
  4196. if (is_sdvo) {
  4197. int pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
  4198. if (pixel_multiplier > 1) {
  4199. if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev))
  4200. dpll |= (pixel_multiplier - 1) << SDVO_MULTIPLIER_SHIFT_HIRES;
  4201. else if (HAS_PCH_SPLIT(dev))
  4202. dpll |= (pixel_multiplier - 1) << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
  4203. }
  4204. dpll |= DPLL_DVO_HIGH_SPEED;
  4205. }
  4206. if (is_dp || intel_encoder_is_pch_edp(&has_edp_encoder->base))
  4207. dpll |= DPLL_DVO_HIGH_SPEED;
  4208. /* compute bitmask from p1 value */
  4209. if (IS_PINEVIEW(dev))
  4210. dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
  4211. else {
  4212. dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  4213. /* also FPA1 */
  4214. if (HAS_PCH_SPLIT(dev))
  4215. dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  4216. if (IS_G4X(dev) && has_reduced_clock)
  4217. dpll |= (1 << (reduced_clock.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  4218. }
  4219. switch (clock.p2) {
  4220. case 5:
  4221. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  4222. break;
  4223. case 7:
  4224. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  4225. break;
  4226. case 10:
  4227. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  4228. break;
  4229. case 14:
  4230. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  4231. break;
  4232. }
  4233. if (INTEL_INFO(dev)->gen >= 4 && !HAS_PCH_SPLIT(dev))
  4234. dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
  4235. } else {
  4236. if (is_lvds) {
  4237. dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  4238. } else {
  4239. if (clock.p1 == 2)
  4240. dpll |= PLL_P1_DIVIDE_BY_TWO;
  4241. else
  4242. dpll |= (clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  4243. if (clock.p2 == 4)
  4244. dpll |= PLL_P2_DIVIDE_BY_4;
  4245. }
  4246. }
  4247. if (is_sdvo && is_tv)
  4248. dpll |= PLL_REF_INPUT_TVCLKINBC;
  4249. else if (is_tv)
  4250. /* XXX: just matching BIOS for now */
  4251. /* dpll |= PLL_REF_INPUT_TVCLKINBC; */
  4252. dpll |= 3;
  4253. else if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  4254. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  4255. else
  4256. dpll |= PLL_REF_INPUT_DREFCLK;
  4257. /* setup pipeconf */
  4258. pipeconf = I915_READ(PIPECONF(pipe));
  4259. /* Set up the display plane register */
  4260. dspcntr = DISPPLANE_GAMMA_ENABLE;
  4261. /* Ironlake's plane is forced to pipe, bit 24 is to
  4262. enable color space conversion */
  4263. if (!HAS_PCH_SPLIT(dev)) {
  4264. if (pipe == 0)
  4265. dspcntr &= ~DISPPLANE_SEL_PIPE_MASK;
  4266. else
  4267. dspcntr |= DISPPLANE_SEL_PIPE_B;
  4268. }
  4269. if (pipe == 0 && INTEL_INFO(dev)->gen < 4) {
  4270. /* Enable pixel doubling when the dot clock is > 90% of the (display)
  4271. * core speed.
  4272. *
  4273. * XXX: No double-wide on 915GM pipe B. Is that the only reason for the
  4274. * pipe == 0 check?
  4275. */
  4276. if (mode->clock >
  4277. dev_priv->display.get_display_clock_speed(dev) * 9 / 10)
  4278. pipeconf |= PIPECONF_DOUBLE_WIDE;
  4279. else
  4280. pipeconf &= ~PIPECONF_DOUBLE_WIDE;
  4281. }
  4282. if (!HAS_PCH_SPLIT(dev))
  4283. dpll |= DPLL_VCO_ENABLE;
  4284. DRM_DEBUG_KMS("Mode for pipe %c:\n", pipe == 0 ? 'A' : 'B');
  4285. drm_mode_debug_printmodeline(mode);
  4286. /* assign to Ironlake registers */
  4287. if (HAS_PCH_SPLIT(dev)) {
  4288. fp_reg = PCH_FP0(pipe);
  4289. dpll_reg = PCH_DPLL(pipe);
  4290. } else {
  4291. fp_reg = FP0(pipe);
  4292. dpll_reg = DPLL(pipe);
  4293. }
  4294. /* PCH eDP needs FDI, but CPU eDP does not */
  4295. if (!has_edp_encoder || intel_encoder_is_pch_edp(&has_edp_encoder->base)) {
  4296. I915_WRITE(fp_reg, fp);
  4297. I915_WRITE(dpll_reg, dpll & ~DPLL_VCO_ENABLE);
  4298. POSTING_READ(dpll_reg);
  4299. udelay(150);
  4300. }
  4301. /* enable transcoder DPLL */
  4302. if (HAS_PCH_CPT(dev)) {
  4303. temp = I915_READ(PCH_DPLL_SEL);
  4304. switch (pipe) {
  4305. case 0:
  4306. temp |= TRANSA_DPLL_ENABLE | TRANSA_DPLLA_SEL;
  4307. break;
  4308. case 1:
  4309. temp |= TRANSB_DPLL_ENABLE | TRANSB_DPLLB_SEL;
  4310. break;
  4311. case 2:
  4312. /* FIXME: manage transcoder PLLs? */
  4313. temp |= TRANSC_DPLL_ENABLE | TRANSC_DPLLB_SEL;
  4314. break;
  4315. default:
  4316. BUG();
  4317. }
  4318. I915_WRITE(PCH_DPLL_SEL, temp);
  4319. POSTING_READ(PCH_DPLL_SEL);
  4320. udelay(150);
  4321. }
  4322. /* The LVDS pin pair needs to be on before the DPLLs are enabled.
  4323. * This is an exception to the general rule that mode_set doesn't turn
  4324. * things on.
  4325. */
  4326. if (is_lvds) {
  4327. reg = LVDS;
  4328. if (HAS_PCH_SPLIT(dev))
  4329. reg = PCH_LVDS;
  4330. temp = I915_READ(reg);
  4331. temp |= LVDS_PORT_EN | LVDS_A0A2_CLKA_POWER_UP;
  4332. if (pipe == 1) {
  4333. if (HAS_PCH_CPT(dev))
  4334. temp |= PORT_TRANS_B_SEL_CPT;
  4335. else
  4336. temp |= LVDS_PIPEB_SELECT;
  4337. } else {
  4338. if (HAS_PCH_CPT(dev))
  4339. temp &= ~PORT_TRANS_SEL_MASK;
  4340. else
  4341. temp &= ~LVDS_PIPEB_SELECT;
  4342. }
  4343. /* set the corresponsding LVDS_BORDER bit */
  4344. temp |= dev_priv->lvds_border_bits;
  4345. /* Set the B0-B3 data pairs corresponding to whether we're going to
  4346. * set the DPLLs for dual-channel mode or not.
  4347. */
  4348. if (clock.p2 == 7)
  4349. temp |= LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP;
  4350. else
  4351. temp &= ~(LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP);
  4352. /* It would be nice to set 24 vs 18-bit mode (LVDS_A3_POWER_UP)
  4353. * appropriately here, but we need to look more thoroughly into how
  4354. * panels behave in the two modes.
  4355. */
  4356. /* set the dithering flag on non-PCH LVDS as needed */
  4357. if (INTEL_INFO(dev)->gen >= 4 && !HAS_PCH_SPLIT(dev)) {
  4358. if (dev_priv->lvds_dither)
  4359. temp |= LVDS_ENABLE_DITHER;
  4360. else
  4361. temp &= ~LVDS_ENABLE_DITHER;
  4362. }
  4363. if (adjusted_mode->flags & DRM_MODE_FLAG_NHSYNC)
  4364. lvds_sync |= LVDS_HSYNC_POLARITY;
  4365. if (adjusted_mode->flags & DRM_MODE_FLAG_NVSYNC)
  4366. lvds_sync |= LVDS_VSYNC_POLARITY;
  4367. if ((temp & (LVDS_HSYNC_POLARITY | LVDS_VSYNC_POLARITY))
  4368. != lvds_sync) {
  4369. char flags[2] = "-+";
  4370. DRM_INFO("Changing LVDS panel from "
  4371. "(%chsync, %cvsync) to (%chsync, %cvsync)\n",
  4372. flags[!(temp & LVDS_HSYNC_POLARITY)],
  4373. flags[!(temp & LVDS_VSYNC_POLARITY)],
  4374. flags[!(lvds_sync & LVDS_HSYNC_POLARITY)],
  4375. flags[!(lvds_sync & LVDS_VSYNC_POLARITY)]);
  4376. temp &= ~(LVDS_HSYNC_POLARITY | LVDS_VSYNC_POLARITY);
  4377. temp |= lvds_sync;
  4378. }
  4379. I915_WRITE(reg, temp);
  4380. }
  4381. /* set the dithering flag and clear for anything other than a panel. */
  4382. if (HAS_PCH_SPLIT(dev)) {
  4383. pipeconf &= ~PIPECONF_DITHER_EN;
  4384. pipeconf &= ~PIPECONF_DITHER_TYPE_MASK;
  4385. if (dev_priv->lvds_dither && (is_lvds || has_edp_encoder)) {
  4386. pipeconf |= PIPECONF_DITHER_EN;
  4387. pipeconf |= PIPECONF_DITHER_TYPE_ST1;
  4388. }
  4389. }
  4390. if (is_dp || intel_encoder_is_pch_edp(&has_edp_encoder->base)) {
  4391. intel_dp_set_m_n(crtc, mode, adjusted_mode);
  4392. } else if (HAS_PCH_SPLIT(dev)) {
  4393. /* For non-DP output, clear any trans DP clock recovery setting.*/
  4394. I915_WRITE(TRANSDATA_M1(pipe), 0);
  4395. I915_WRITE(TRANSDATA_N1(pipe), 0);
  4396. I915_WRITE(TRANSDPLINK_M1(pipe), 0);
  4397. I915_WRITE(TRANSDPLINK_N1(pipe), 0);
  4398. }
  4399. if (!has_edp_encoder || intel_encoder_is_pch_edp(&has_edp_encoder->base)) {
  4400. I915_WRITE(dpll_reg, dpll);
  4401. /* Wait for the clocks to stabilize. */
  4402. POSTING_READ(dpll_reg);
  4403. udelay(150);
  4404. if (INTEL_INFO(dev)->gen >= 4 && !HAS_PCH_SPLIT(dev)) {
  4405. temp = 0;
  4406. if (is_sdvo) {
  4407. temp = intel_mode_get_pixel_multiplier(adjusted_mode);
  4408. if (temp > 1)
  4409. temp = (temp - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  4410. else
  4411. temp = 0;
  4412. }
  4413. I915_WRITE(DPLL_MD(pipe), temp);
  4414. } else {
  4415. /* The pixel multiplier can only be updated once the
  4416. * DPLL is enabled and the clocks are stable.
  4417. *
  4418. * So write it again.
  4419. */
  4420. I915_WRITE(dpll_reg, dpll);
  4421. }
  4422. }
  4423. intel_crtc->lowfreq_avail = false;
  4424. if (is_lvds && has_reduced_clock && i915_powersave) {
  4425. I915_WRITE(fp_reg + 4, fp2);
  4426. intel_crtc->lowfreq_avail = true;
  4427. if (HAS_PIPE_CXSR(dev)) {
  4428. DRM_DEBUG_KMS("enabling CxSR downclocking\n");
  4429. pipeconf |= PIPECONF_CXSR_DOWNCLOCK;
  4430. }
  4431. } else {
  4432. I915_WRITE(fp_reg + 4, fp);
  4433. if (HAS_PIPE_CXSR(dev)) {
  4434. DRM_DEBUG_KMS("disabling CxSR downclocking\n");
  4435. pipeconf &= ~PIPECONF_CXSR_DOWNCLOCK;
  4436. }
  4437. }
  4438. if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
  4439. pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
  4440. /* the chip adds 2 halflines automatically */
  4441. adjusted_mode->crtc_vdisplay -= 1;
  4442. adjusted_mode->crtc_vtotal -= 1;
  4443. adjusted_mode->crtc_vblank_start -= 1;
  4444. adjusted_mode->crtc_vblank_end -= 1;
  4445. adjusted_mode->crtc_vsync_end -= 1;
  4446. adjusted_mode->crtc_vsync_start -= 1;
  4447. } else
  4448. pipeconf &= ~PIPECONF_INTERLACE_W_FIELD_INDICATION; /* progressive */
  4449. I915_WRITE(HTOTAL(pipe),
  4450. (adjusted_mode->crtc_hdisplay - 1) |
  4451. ((adjusted_mode->crtc_htotal - 1) << 16));
  4452. I915_WRITE(HBLANK(pipe),
  4453. (adjusted_mode->crtc_hblank_start - 1) |
  4454. ((adjusted_mode->crtc_hblank_end - 1) << 16));
  4455. I915_WRITE(HSYNC(pipe),
  4456. (adjusted_mode->crtc_hsync_start - 1) |
  4457. ((adjusted_mode->crtc_hsync_end - 1) << 16));
  4458. I915_WRITE(VTOTAL(pipe),
  4459. (adjusted_mode->crtc_vdisplay - 1) |
  4460. ((adjusted_mode->crtc_vtotal - 1) << 16));
  4461. I915_WRITE(VBLANK(pipe),
  4462. (adjusted_mode->crtc_vblank_start - 1) |
  4463. ((adjusted_mode->crtc_vblank_end - 1) << 16));
  4464. I915_WRITE(VSYNC(pipe),
  4465. (adjusted_mode->crtc_vsync_start - 1) |
  4466. ((adjusted_mode->crtc_vsync_end - 1) << 16));
  4467. /* pipesrc and dspsize control the size that is scaled from,
  4468. * which should always be the user's requested size.
  4469. */
  4470. if (!HAS_PCH_SPLIT(dev)) {
  4471. I915_WRITE(DSPSIZE(plane),
  4472. ((mode->vdisplay - 1) << 16) |
  4473. (mode->hdisplay - 1));
  4474. I915_WRITE(DSPPOS(plane), 0);
  4475. }
  4476. I915_WRITE(PIPESRC(pipe),
  4477. ((mode->hdisplay - 1) << 16) | (mode->vdisplay - 1));
  4478. if (HAS_PCH_SPLIT(dev)) {
  4479. I915_WRITE(PIPE_DATA_M1(pipe), TU_SIZE(m_n.tu) | m_n.gmch_m);
  4480. I915_WRITE(PIPE_DATA_N1(pipe), m_n.gmch_n);
  4481. I915_WRITE(PIPE_LINK_M1(pipe), m_n.link_m);
  4482. I915_WRITE(PIPE_LINK_N1(pipe), m_n.link_n);
  4483. if (has_edp_encoder && !intel_encoder_is_pch_edp(&has_edp_encoder->base)) {
  4484. ironlake_set_pll_edp(crtc, adjusted_mode->clock);
  4485. }
  4486. }
  4487. I915_WRITE(PIPECONF(pipe), pipeconf);
  4488. POSTING_READ(PIPECONF(pipe));
  4489. if (!HAS_PCH_SPLIT(dev))
  4490. intel_enable_pipe(dev_priv, pipe, false);
  4491. intel_wait_for_vblank(dev, pipe);
  4492. if (IS_GEN5(dev)) {
  4493. /* enable address swizzle for tiling buffer */
  4494. temp = I915_READ(DISP_ARB_CTL);
  4495. I915_WRITE(DISP_ARB_CTL, temp | DISP_TILE_SURFACE_SWIZZLING);
  4496. }
  4497. I915_WRITE(DSPCNTR(plane), dspcntr);
  4498. POSTING_READ(DSPCNTR(plane));
  4499. if (!HAS_PCH_SPLIT(dev))
  4500. intel_enable_plane(dev_priv, plane, pipe);
  4501. ret = intel_pipe_set_base(crtc, x, y, old_fb);
  4502. intel_update_watermarks(dev);
  4503. drm_vblank_post_modeset(dev, pipe);
  4504. return ret;
  4505. }
  4506. /** Loads the palette/gamma unit for the CRTC with the prepared values */
  4507. void intel_crtc_load_lut(struct drm_crtc *crtc)
  4508. {
  4509. struct drm_device *dev = crtc->dev;
  4510. struct drm_i915_private *dev_priv = dev->dev_private;
  4511. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4512. int palreg = PALETTE(intel_crtc->pipe);
  4513. int i;
  4514. /* The clocks have to be on to load the palette. */
  4515. if (!crtc->enabled)
  4516. return;
  4517. /* use legacy palette for Ironlake */
  4518. if (HAS_PCH_SPLIT(dev))
  4519. palreg = LGC_PALETTE(intel_crtc->pipe);
  4520. for (i = 0; i < 256; i++) {
  4521. I915_WRITE(palreg + 4 * i,
  4522. (intel_crtc->lut_r[i] << 16) |
  4523. (intel_crtc->lut_g[i] << 8) |
  4524. intel_crtc->lut_b[i]);
  4525. }
  4526. }
  4527. static void i845_update_cursor(struct drm_crtc *crtc, u32 base)
  4528. {
  4529. struct drm_device *dev = crtc->dev;
  4530. struct drm_i915_private *dev_priv = dev->dev_private;
  4531. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4532. bool visible = base != 0;
  4533. u32 cntl;
  4534. if (intel_crtc->cursor_visible == visible)
  4535. return;
  4536. cntl = I915_READ(_CURACNTR);
  4537. if (visible) {
  4538. /* On these chipsets we can only modify the base whilst
  4539. * the cursor is disabled.
  4540. */
  4541. I915_WRITE(_CURABASE, base);
  4542. cntl &= ~(CURSOR_FORMAT_MASK);
  4543. /* XXX width must be 64, stride 256 => 0x00 << 28 */
  4544. cntl |= CURSOR_ENABLE |
  4545. CURSOR_GAMMA_ENABLE |
  4546. CURSOR_FORMAT_ARGB;
  4547. } else
  4548. cntl &= ~(CURSOR_ENABLE | CURSOR_GAMMA_ENABLE);
  4549. I915_WRITE(_CURACNTR, cntl);
  4550. intel_crtc->cursor_visible = visible;
  4551. }
  4552. static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base)
  4553. {
  4554. struct drm_device *dev = crtc->dev;
  4555. struct drm_i915_private *dev_priv = dev->dev_private;
  4556. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4557. int pipe = intel_crtc->pipe;
  4558. bool visible = base != 0;
  4559. if (intel_crtc->cursor_visible != visible) {
  4560. uint32_t cntl = I915_READ(CURCNTR(pipe));
  4561. if (base) {
  4562. cntl &= ~(CURSOR_MODE | MCURSOR_PIPE_SELECT);
  4563. cntl |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE;
  4564. cntl |= pipe << 28; /* Connect to correct pipe */
  4565. } else {
  4566. cntl &= ~(CURSOR_MODE | MCURSOR_GAMMA_ENABLE);
  4567. cntl |= CURSOR_MODE_DISABLE;
  4568. }
  4569. I915_WRITE(CURCNTR(pipe), cntl);
  4570. intel_crtc->cursor_visible = visible;
  4571. }
  4572. /* and commit changes on next vblank */
  4573. I915_WRITE(CURBASE(pipe), base);
  4574. }
  4575. /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
  4576. static void intel_crtc_update_cursor(struct drm_crtc *crtc,
  4577. bool on)
  4578. {
  4579. struct drm_device *dev = crtc->dev;
  4580. struct drm_i915_private *dev_priv = dev->dev_private;
  4581. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4582. int pipe = intel_crtc->pipe;
  4583. int x = intel_crtc->cursor_x;
  4584. int y = intel_crtc->cursor_y;
  4585. u32 base, pos;
  4586. bool visible;
  4587. pos = 0;
  4588. if (on && crtc->enabled && crtc->fb) {
  4589. base = intel_crtc->cursor_addr;
  4590. if (x > (int) crtc->fb->width)
  4591. base = 0;
  4592. if (y > (int) crtc->fb->height)
  4593. base = 0;
  4594. } else
  4595. base = 0;
  4596. if (x < 0) {
  4597. if (x + intel_crtc->cursor_width < 0)
  4598. base = 0;
  4599. pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
  4600. x = -x;
  4601. }
  4602. pos |= x << CURSOR_X_SHIFT;
  4603. if (y < 0) {
  4604. if (y + intel_crtc->cursor_height < 0)
  4605. base = 0;
  4606. pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
  4607. y = -y;
  4608. }
  4609. pos |= y << CURSOR_Y_SHIFT;
  4610. visible = base != 0;
  4611. if (!visible && !intel_crtc->cursor_visible)
  4612. return;
  4613. I915_WRITE(CURPOS(pipe), pos);
  4614. if (IS_845G(dev) || IS_I865G(dev))
  4615. i845_update_cursor(crtc, base);
  4616. else
  4617. i9xx_update_cursor(crtc, base);
  4618. if (visible)
  4619. intel_mark_busy(dev, to_intel_framebuffer(crtc->fb)->obj);
  4620. }
  4621. static int intel_crtc_cursor_set(struct drm_crtc *crtc,
  4622. struct drm_file *file,
  4623. uint32_t handle,
  4624. uint32_t width, uint32_t height)
  4625. {
  4626. struct drm_device *dev = crtc->dev;
  4627. struct drm_i915_private *dev_priv = dev->dev_private;
  4628. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4629. struct drm_i915_gem_object *obj;
  4630. uint32_t addr;
  4631. int ret;
  4632. DRM_DEBUG_KMS("\n");
  4633. /* if we want to turn off the cursor ignore width and height */
  4634. if (!handle) {
  4635. DRM_DEBUG_KMS("cursor off\n");
  4636. addr = 0;
  4637. obj = NULL;
  4638. mutex_lock(&dev->struct_mutex);
  4639. goto finish;
  4640. }
  4641. /* Currently we only support 64x64 cursors */
  4642. if (width != 64 || height != 64) {
  4643. DRM_ERROR("we currently only support 64x64 cursors\n");
  4644. return -EINVAL;
  4645. }
  4646. obj = to_intel_bo(drm_gem_object_lookup(dev, file, handle));
  4647. if (&obj->base == NULL)
  4648. return -ENOENT;
  4649. if (obj->base.size < width * height * 4) {
  4650. DRM_ERROR("buffer is to small\n");
  4651. ret = -ENOMEM;
  4652. goto fail;
  4653. }
  4654. /* we only need to pin inside GTT if cursor is non-phy */
  4655. mutex_lock(&dev->struct_mutex);
  4656. if (!dev_priv->info->cursor_needs_physical) {
  4657. if (obj->tiling_mode) {
  4658. DRM_ERROR("cursor cannot be tiled\n");
  4659. ret = -EINVAL;
  4660. goto fail_locked;
  4661. }
  4662. ret = i915_gem_object_pin(obj, PAGE_SIZE, true);
  4663. if (ret) {
  4664. DRM_ERROR("failed to pin cursor bo\n");
  4665. goto fail_locked;
  4666. }
  4667. ret = i915_gem_object_set_to_gtt_domain(obj, 0);
  4668. if (ret) {
  4669. DRM_ERROR("failed to move cursor bo into the GTT\n");
  4670. goto fail_unpin;
  4671. }
  4672. ret = i915_gem_object_put_fence(obj);
  4673. if (ret) {
  4674. DRM_ERROR("failed to move cursor bo into the GTT\n");
  4675. goto fail_unpin;
  4676. }
  4677. addr = obj->gtt_offset;
  4678. } else {
  4679. int align = IS_I830(dev) ? 16 * 1024 : 256;
  4680. ret = i915_gem_attach_phys_object(dev, obj,
  4681. (intel_crtc->pipe == 0) ? I915_GEM_PHYS_CURSOR_0 : I915_GEM_PHYS_CURSOR_1,
  4682. align);
  4683. if (ret) {
  4684. DRM_ERROR("failed to attach phys object\n");
  4685. goto fail_locked;
  4686. }
  4687. addr = obj->phys_obj->handle->busaddr;
  4688. }
  4689. if (IS_GEN2(dev))
  4690. I915_WRITE(CURSIZE, (height << 12) | width);
  4691. finish:
  4692. if (intel_crtc->cursor_bo) {
  4693. if (dev_priv->info->cursor_needs_physical) {
  4694. if (intel_crtc->cursor_bo != obj)
  4695. i915_gem_detach_phys_object(dev, intel_crtc->cursor_bo);
  4696. } else
  4697. i915_gem_object_unpin(intel_crtc->cursor_bo);
  4698. drm_gem_object_unreference(&intel_crtc->cursor_bo->base);
  4699. }
  4700. mutex_unlock(&dev->struct_mutex);
  4701. intel_crtc->cursor_addr = addr;
  4702. intel_crtc->cursor_bo = obj;
  4703. intel_crtc->cursor_width = width;
  4704. intel_crtc->cursor_height = height;
  4705. intel_crtc_update_cursor(crtc, true);
  4706. return 0;
  4707. fail_unpin:
  4708. i915_gem_object_unpin(obj);
  4709. fail_locked:
  4710. mutex_unlock(&dev->struct_mutex);
  4711. fail:
  4712. drm_gem_object_unreference_unlocked(&obj->base);
  4713. return ret;
  4714. }
  4715. static int intel_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
  4716. {
  4717. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4718. intel_crtc->cursor_x = x;
  4719. intel_crtc->cursor_y = y;
  4720. intel_crtc_update_cursor(crtc, true);
  4721. return 0;
  4722. }
  4723. /** Sets the color ramps on behalf of RandR */
  4724. void intel_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
  4725. u16 blue, int regno)
  4726. {
  4727. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4728. intel_crtc->lut_r[regno] = red >> 8;
  4729. intel_crtc->lut_g[regno] = green >> 8;
  4730. intel_crtc->lut_b[regno] = blue >> 8;
  4731. }
  4732. void intel_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green,
  4733. u16 *blue, int regno)
  4734. {
  4735. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4736. *red = intel_crtc->lut_r[regno] << 8;
  4737. *green = intel_crtc->lut_g[regno] << 8;
  4738. *blue = intel_crtc->lut_b[regno] << 8;
  4739. }
  4740. static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
  4741. u16 *blue, uint32_t start, uint32_t size)
  4742. {
  4743. int end = (start + size > 256) ? 256 : start + size, i;
  4744. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4745. for (i = start; i < end; i++) {
  4746. intel_crtc->lut_r[i] = red[i] >> 8;
  4747. intel_crtc->lut_g[i] = green[i] >> 8;
  4748. intel_crtc->lut_b[i] = blue[i] >> 8;
  4749. }
  4750. intel_crtc_load_lut(crtc);
  4751. }
  4752. /**
  4753. * Get a pipe with a simple mode set on it for doing load-based monitor
  4754. * detection.
  4755. *
  4756. * It will be up to the load-detect code to adjust the pipe as appropriate for
  4757. * its requirements. The pipe will be connected to no other encoders.
  4758. *
  4759. * Currently this code will only succeed if there is a pipe with no encoders
  4760. * configured for it. In the future, it could choose to temporarily disable
  4761. * some outputs to free up a pipe for its use.
  4762. *
  4763. * \return crtc, or NULL if no pipes are available.
  4764. */
  4765. /* VESA 640x480x72Hz mode to set on the pipe */
  4766. static struct drm_display_mode load_detect_mode = {
  4767. DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
  4768. 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  4769. };
  4770. struct drm_crtc *intel_get_load_detect_pipe(struct intel_encoder *intel_encoder,
  4771. struct drm_connector *connector,
  4772. struct drm_display_mode *mode,
  4773. int *dpms_mode)
  4774. {
  4775. struct intel_crtc *intel_crtc;
  4776. struct drm_crtc *possible_crtc;
  4777. struct drm_crtc *supported_crtc =NULL;
  4778. struct drm_encoder *encoder = &intel_encoder->base;
  4779. struct drm_crtc *crtc = NULL;
  4780. struct drm_device *dev = encoder->dev;
  4781. struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
  4782. struct drm_crtc_helper_funcs *crtc_funcs;
  4783. int i = -1;
  4784. /*
  4785. * Algorithm gets a little messy:
  4786. * - if the connector already has an assigned crtc, use it (but make
  4787. * sure it's on first)
  4788. * - try to find the first unused crtc that can drive this connector,
  4789. * and use that if we find one
  4790. * - if there are no unused crtcs available, try to use the first
  4791. * one we found that supports the connector
  4792. */
  4793. /* See if we already have a CRTC for this connector */
  4794. if (encoder->crtc) {
  4795. crtc = encoder->crtc;
  4796. /* Make sure the crtc and connector are running */
  4797. intel_crtc = to_intel_crtc(crtc);
  4798. *dpms_mode = intel_crtc->dpms_mode;
  4799. if (intel_crtc->dpms_mode != DRM_MODE_DPMS_ON) {
  4800. crtc_funcs = crtc->helper_private;
  4801. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON);
  4802. encoder_funcs->dpms(encoder, DRM_MODE_DPMS_ON);
  4803. }
  4804. return crtc;
  4805. }
  4806. /* Find an unused one (if possible) */
  4807. list_for_each_entry(possible_crtc, &dev->mode_config.crtc_list, head) {
  4808. i++;
  4809. if (!(encoder->possible_crtcs & (1 << i)))
  4810. continue;
  4811. if (!possible_crtc->enabled) {
  4812. crtc = possible_crtc;
  4813. break;
  4814. }
  4815. if (!supported_crtc)
  4816. supported_crtc = possible_crtc;
  4817. }
  4818. /*
  4819. * If we didn't find an unused CRTC, don't use any.
  4820. */
  4821. if (!crtc) {
  4822. return NULL;
  4823. }
  4824. encoder->crtc = crtc;
  4825. connector->encoder = encoder;
  4826. intel_encoder->load_detect_temp = true;
  4827. intel_crtc = to_intel_crtc(crtc);
  4828. *dpms_mode = intel_crtc->dpms_mode;
  4829. if (!crtc->enabled) {
  4830. if (!mode)
  4831. mode = &load_detect_mode;
  4832. drm_crtc_helper_set_mode(crtc, mode, 0, 0, crtc->fb);
  4833. } else {
  4834. if (intel_crtc->dpms_mode != DRM_MODE_DPMS_ON) {
  4835. crtc_funcs = crtc->helper_private;
  4836. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON);
  4837. }
  4838. /* Add this connector to the crtc */
  4839. encoder_funcs->mode_set(encoder, &crtc->mode, &crtc->mode);
  4840. encoder_funcs->commit(encoder);
  4841. }
  4842. /* let the connector get through one full cycle before testing */
  4843. intel_wait_for_vblank(dev, intel_crtc->pipe);
  4844. return crtc;
  4845. }
  4846. void intel_release_load_detect_pipe(struct intel_encoder *intel_encoder,
  4847. struct drm_connector *connector, int dpms_mode)
  4848. {
  4849. struct drm_encoder *encoder = &intel_encoder->base;
  4850. struct drm_device *dev = encoder->dev;
  4851. struct drm_crtc *crtc = encoder->crtc;
  4852. struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
  4853. struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
  4854. if (intel_encoder->load_detect_temp) {
  4855. encoder->crtc = NULL;
  4856. connector->encoder = NULL;
  4857. intel_encoder->load_detect_temp = false;
  4858. crtc->enabled = drm_helper_crtc_in_use(crtc);
  4859. drm_helper_disable_unused_functions(dev);
  4860. }
  4861. /* Switch crtc and encoder back off if necessary */
  4862. if (crtc->enabled && dpms_mode != DRM_MODE_DPMS_ON) {
  4863. if (encoder->crtc == crtc)
  4864. encoder_funcs->dpms(encoder, dpms_mode);
  4865. crtc_funcs->dpms(crtc, dpms_mode);
  4866. }
  4867. }
  4868. /* Returns the clock of the currently programmed mode of the given pipe. */
  4869. static int intel_crtc_clock_get(struct drm_device *dev, struct drm_crtc *crtc)
  4870. {
  4871. struct drm_i915_private *dev_priv = dev->dev_private;
  4872. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4873. int pipe = intel_crtc->pipe;
  4874. u32 dpll = I915_READ(DPLL(pipe));
  4875. u32 fp;
  4876. intel_clock_t clock;
  4877. if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
  4878. fp = FP0(pipe);
  4879. else
  4880. fp = FP1(pipe);
  4881. clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
  4882. if (IS_PINEVIEW(dev)) {
  4883. clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
  4884. clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
  4885. } else {
  4886. clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
  4887. clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
  4888. }
  4889. if (!IS_GEN2(dev)) {
  4890. if (IS_PINEVIEW(dev))
  4891. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
  4892. DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
  4893. else
  4894. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
  4895. DPLL_FPA01_P1_POST_DIV_SHIFT);
  4896. switch (dpll & DPLL_MODE_MASK) {
  4897. case DPLLB_MODE_DAC_SERIAL:
  4898. clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
  4899. 5 : 10;
  4900. break;
  4901. case DPLLB_MODE_LVDS:
  4902. clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
  4903. 7 : 14;
  4904. break;
  4905. default:
  4906. DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
  4907. "mode\n", (int)(dpll & DPLL_MODE_MASK));
  4908. return 0;
  4909. }
  4910. /* XXX: Handle the 100Mhz refclk */
  4911. intel_clock(dev, 96000, &clock);
  4912. } else {
  4913. bool is_lvds = (pipe == 1) && (I915_READ(LVDS) & LVDS_PORT_EN);
  4914. if (is_lvds) {
  4915. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
  4916. DPLL_FPA01_P1_POST_DIV_SHIFT);
  4917. clock.p2 = 14;
  4918. if ((dpll & PLL_REF_INPUT_MASK) ==
  4919. PLLB_REF_INPUT_SPREADSPECTRUMIN) {
  4920. /* XXX: might not be 66MHz */
  4921. intel_clock(dev, 66000, &clock);
  4922. } else
  4923. intel_clock(dev, 48000, &clock);
  4924. } else {
  4925. if (dpll & PLL_P1_DIVIDE_BY_TWO)
  4926. clock.p1 = 2;
  4927. else {
  4928. clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
  4929. DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
  4930. }
  4931. if (dpll & PLL_P2_DIVIDE_BY_4)
  4932. clock.p2 = 4;
  4933. else
  4934. clock.p2 = 2;
  4935. intel_clock(dev, 48000, &clock);
  4936. }
  4937. }
  4938. /* XXX: It would be nice to validate the clocks, but we can't reuse
  4939. * i830PllIsValid() because it relies on the xf86_config connector
  4940. * configuration being accurate, which it isn't necessarily.
  4941. */
  4942. return clock.dot;
  4943. }
  4944. /** Returns the currently programmed mode of the given pipe. */
  4945. struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
  4946. struct drm_crtc *crtc)
  4947. {
  4948. struct drm_i915_private *dev_priv = dev->dev_private;
  4949. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4950. int pipe = intel_crtc->pipe;
  4951. struct drm_display_mode *mode;
  4952. int htot = I915_READ(HTOTAL(pipe));
  4953. int hsync = I915_READ(HSYNC(pipe));
  4954. int vtot = I915_READ(VTOTAL(pipe));
  4955. int vsync = I915_READ(VSYNC(pipe));
  4956. mode = kzalloc(sizeof(*mode), GFP_KERNEL);
  4957. if (!mode)
  4958. return NULL;
  4959. mode->clock = intel_crtc_clock_get(dev, crtc);
  4960. mode->hdisplay = (htot & 0xffff) + 1;
  4961. mode->htotal = ((htot & 0xffff0000) >> 16) + 1;
  4962. mode->hsync_start = (hsync & 0xffff) + 1;
  4963. mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1;
  4964. mode->vdisplay = (vtot & 0xffff) + 1;
  4965. mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1;
  4966. mode->vsync_start = (vsync & 0xffff) + 1;
  4967. mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1;
  4968. drm_mode_set_name(mode);
  4969. drm_mode_set_crtcinfo(mode, 0);
  4970. return mode;
  4971. }
  4972. #define GPU_IDLE_TIMEOUT 500 /* ms */
  4973. /* When this timer fires, we've been idle for awhile */
  4974. static void intel_gpu_idle_timer(unsigned long arg)
  4975. {
  4976. struct drm_device *dev = (struct drm_device *)arg;
  4977. drm_i915_private_t *dev_priv = dev->dev_private;
  4978. if (!list_empty(&dev_priv->mm.active_list)) {
  4979. /* Still processing requests, so just re-arm the timer. */
  4980. mod_timer(&dev_priv->idle_timer, jiffies +
  4981. msecs_to_jiffies(GPU_IDLE_TIMEOUT));
  4982. return;
  4983. }
  4984. dev_priv->busy = false;
  4985. queue_work(dev_priv->wq, &dev_priv->idle_work);
  4986. }
  4987. #define CRTC_IDLE_TIMEOUT 1000 /* ms */
  4988. static void intel_crtc_idle_timer(unsigned long arg)
  4989. {
  4990. struct intel_crtc *intel_crtc = (struct intel_crtc *)arg;
  4991. struct drm_crtc *crtc = &intel_crtc->base;
  4992. drm_i915_private_t *dev_priv = crtc->dev->dev_private;
  4993. struct intel_framebuffer *intel_fb;
  4994. intel_fb = to_intel_framebuffer(crtc->fb);
  4995. if (intel_fb && intel_fb->obj->active) {
  4996. /* The framebuffer is still being accessed by the GPU. */
  4997. mod_timer(&intel_crtc->idle_timer, jiffies +
  4998. msecs_to_jiffies(CRTC_IDLE_TIMEOUT));
  4999. return;
  5000. }
  5001. intel_crtc->busy = false;
  5002. queue_work(dev_priv->wq, &dev_priv->idle_work);
  5003. }
  5004. static void intel_increase_pllclock(struct drm_crtc *crtc)
  5005. {
  5006. struct drm_device *dev = crtc->dev;
  5007. drm_i915_private_t *dev_priv = dev->dev_private;
  5008. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5009. int pipe = intel_crtc->pipe;
  5010. int dpll_reg = DPLL(pipe);
  5011. int dpll;
  5012. if (HAS_PCH_SPLIT(dev))
  5013. return;
  5014. if (!dev_priv->lvds_downclock_avail)
  5015. return;
  5016. dpll = I915_READ(dpll_reg);
  5017. if (!HAS_PIPE_CXSR(dev) && (dpll & DISPLAY_RATE_SELECT_FPA1)) {
  5018. DRM_DEBUG_DRIVER("upclocking LVDS\n");
  5019. /* Unlock panel regs */
  5020. I915_WRITE(PP_CONTROL,
  5021. I915_READ(PP_CONTROL) | PANEL_UNLOCK_REGS);
  5022. dpll &= ~DISPLAY_RATE_SELECT_FPA1;
  5023. I915_WRITE(dpll_reg, dpll);
  5024. intel_wait_for_vblank(dev, pipe);
  5025. dpll = I915_READ(dpll_reg);
  5026. if (dpll & DISPLAY_RATE_SELECT_FPA1)
  5027. DRM_DEBUG_DRIVER("failed to upclock LVDS!\n");
  5028. /* ...and lock them again */
  5029. I915_WRITE(PP_CONTROL, I915_READ(PP_CONTROL) & 0x3);
  5030. }
  5031. /* Schedule downclock */
  5032. mod_timer(&intel_crtc->idle_timer, jiffies +
  5033. msecs_to_jiffies(CRTC_IDLE_TIMEOUT));
  5034. }
  5035. static void intel_decrease_pllclock(struct drm_crtc *crtc)
  5036. {
  5037. struct drm_device *dev = crtc->dev;
  5038. drm_i915_private_t *dev_priv = dev->dev_private;
  5039. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5040. int pipe = intel_crtc->pipe;
  5041. int dpll_reg = DPLL(pipe);
  5042. int dpll = I915_READ(dpll_reg);
  5043. if (HAS_PCH_SPLIT(dev))
  5044. return;
  5045. if (!dev_priv->lvds_downclock_avail)
  5046. return;
  5047. /*
  5048. * Since this is called by a timer, we should never get here in
  5049. * the manual case.
  5050. */
  5051. if (!HAS_PIPE_CXSR(dev) && intel_crtc->lowfreq_avail) {
  5052. DRM_DEBUG_DRIVER("downclocking LVDS\n");
  5053. /* Unlock panel regs */
  5054. I915_WRITE(PP_CONTROL, I915_READ(PP_CONTROL) |
  5055. PANEL_UNLOCK_REGS);
  5056. dpll |= DISPLAY_RATE_SELECT_FPA1;
  5057. I915_WRITE(dpll_reg, dpll);
  5058. intel_wait_for_vblank(dev, pipe);
  5059. dpll = I915_READ(dpll_reg);
  5060. if (!(dpll & DISPLAY_RATE_SELECT_FPA1))
  5061. DRM_DEBUG_DRIVER("failed to downclock LVDS!\n");
  5062. /* ...and lock them again */
  5063. I915_WRITE(PP_CONTROL, I915_READ(PP_CONTROL) & 0x3);
  5064. }
  5065. }
  5066. /**
  5067. * intel_idle_update - adjust clocks for idleness
  5068. * @work: work struct
  5069. *
  5070. * Either the GPU or display (or both) went idle. Check the busy status
  5071. * here and adjust the CRTC and GPU clocks as necessary.
  5072. */
  5073. static void intel_idle_update(struct work_struct *work)
  5074. {
  5075. drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
  5076. idle_work);
  5077. struct drm_device *dev = dev_priv->dev;
  5078. struct drm_crtc *crtc;
  5079. struct intel_crtc *intel_crtc;
  5080. if (!i915_powersave)
  5081. return;
  5082. mutex_lock(&dev->struct_mutex);
  5083. i915_update_gfx_val(dev_priv);
  5084. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  5085. /* Skip inactive CRTCs */
  5086. if (!crtc->fb)
  5087. continue;
  5088. intel_crtc = to_intel_crtc(crtc);
  5089. if (!intel_crtc->busy)
  5090. intel_decrease_pllclock(crtc);
  5091. }
  5092. mutex_unlock(&dev->struct_mutex);
  5093. }
  5094. /**
  5095. * intel_mark_busy - mark the GPU and possibly the display busy
  5096. * @dev: drm device
  5097. * @obj: object we're operating on
  5098. *
  5099. * Callers can use this function to indicate that the GPU is busy processing
  5100. * commands. If @obj matches one of the CRTC objects (i.e. it's a scanout
  5101. * buffer), we'll also mark the display as busy, so we know to increase its
  5102. * clock frequency.
  5103. */
  5104. void intel_mark_busy(struct drm_device *dev, struct drm_i915_gem_object *obj)
  5105. {
  5106. drm_i915_private_t *dev_priv = dev->dev_private;
  5107. struct drm_crtc *crtc = NULL;
  5108. struct intel_framebuffer *intel_fb;
  5109. struct intel_crtc *intel_crtc;
  5110. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  5111. return;
  5112. if (!dev_priv->busy)
  5113. dev_priv->busy = true;
  5114. else
  5115. mod_timer(&dev_priv->idle_timer, jiffies +
  5116. msecs_to_jiffies(GPU_IDLE_TIMEOUT));
  5117. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  5118. if (!crtc->fb)
  5119. continue;
  5120. intel_crtc = to_intel_crtc(crtc);
  5121. intel_fb = to_intel_framebuffer(crtc->fb);
  5122. if (intel_fb->obj == obj) {
  5123. if (!intel_crtc->busy) {
  5124. /* Non-busy -> busy, upclock */
  5125. intel_increase_pllclock(crtc);
  5126. intel_crtc->busy = true;
  5127. } else {
  5128. /* Busy -> busy, put off timer */
  5129. mod_timer(&intel_crtc->idle_timer, jiffies +
  5130. msecs_to_jiffies(CRTC_IDLE_TIMEOUT));
  5131. }
  5132. }
  5133. }
  5134. }
  5135. static void intel_crtc_destroy(struct drm_crtc *crtc)
  5136. {
  5137. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5138. struct drm_device *dev = crtc->dev;
  5139. struct intel_unpin_work *work;
  5140. unsigned long flags;
  5141. spin_lock_irqsave(&dev->event_lock, flags);
  5142. work = intel_crtc->unpin_work;
  5143. intel_crtc->unpin_work = NULL;
  5144. spin_unlock_irqrestore(&dev->event_lock, flags);
  5145. if (work) {
  5146. cancel_work_sync(&work->work);
  5147. kfree(work);
  5148. }
  5149. drm_crtc_cleanup(crtc);
  5150. kfree(intel_crtc);
  5151. }
  5152. static void intel_unpin_work_fn(struct work_struct *__work)
  5153. {
  5154. struct intel_unpin_work *work =
  5155. container_of(__work, struct intel_unpin_work, work);
  5156. mutex_lock(&work->dev->struct_mutex);
  5157. i915_gem_object_unpin(work->old_fb_obj);
  5158. drm_gem_object_unreference(&work->pending_flip_obj->base);
  5159. drm_gem_object_unreference(&work->old_fb_obj->base);
  5160. mutex_unlock(&work->dev->struct_mutex);
  5161. kfree(work);
  5162. }
  5163. static void do_intel_finish_page_flip(struct drm_device *dev,
  5164. struct drm_crtc *crtc)
  5165. {
  5166. drm_i915_private_t *dev_priv = dev->dev_private;
  5167. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5168. struct intel_unpin_work *work;
  5169. struct drm_i915_gem_object *obj;
  5170. struct drm_pending_vblank_event *e;
  5171. struct timeval tnow, tvbl;
  5172. unsigned long flags;
  5173. /* Ignore early vblank irqs */
  5174. if (intel_crtc == NULL)
  5175. return;
  5176. do_gettimeofday(&tnow);
  5177. spin_lock_irqsave(&dev->event_lock, flags);
  5178. work = intel_crtc->unpin_work;
  5179. if (work == NULL || !work->pending) {
  5180. spin_unlock_irqrestore(&dev->event_lock, flags);
  5181. return;
  5182. }
  5183. intel_crtc->unpin_work = NULL;
  5184. if (work->event) {
  5185. e = work->event;
  5186. e->event.sequence = drm_vblank_count_and_time(dev, intel_crtc->pipe, &tvbl);
  5187. /* Called before vblank count and timestamps have
  5188. * been updated for the vblank interval of flip
  5189. * completion? Need to increment vblank count and
  5190. * add one videorefresh duration to returned timestamp
  5191. * to account for this. We assume this happened if we
  5192. * get called over 0.9 frame durations after the last
  5193. * timestamped vblank.
  5194. *
  5195. * This calculation can not be used with vrefresh rates
  5196. * below 5Hz (10Hz to be on the safe side) without
  5197. * promoting to 64 integers.
  5198. */
  5199. if (10 * (timeval_to_ns(&tnow) - timeval_to_ns(&tvbl)) >
  5200. 9 * crtc->framedur_ns) {
  5201. e->event.sequence++;
  5202. tvbl = ns_to_timeval(timeval_to_ns(&tvbl) +
  5203. crtc->framedur_ns);
  5204. }
  5205. e->event.tv_sec = tvbl.tv_sec;
  5206. e->event.tv_usec = tvbl.tv_usec;
  5207. list_add_tail(&e->base.link,
  5208. &e->base.file_priv->event_list);
  5209. wake_up_interruptible(&e->base.file_priv->event_wait);
  5210. }
  5211. drm_vblank_put(dev, intel_crtc->pipe);
  5212. spin_unlock_irqrestore(&dev->event_lock, flags);
  5213. obj = work->old_fb_obj;
  5214. atomic_clear_mask(1 << intel_crtc->plane,
  5215. &obj->pending_flip.counter);
  5216. if (atomic_read(&obj->pending_flip) == 0)
  5217. wake_up(&dev_priv->pending_flip_queue);
  5218. schedule_work(&work->work);
  5219. trace_i915_flip_complete(intel_crtc->plane, work->pending_flip_obj);
  5220. }
  5221. void intel_finish_page_flip(struct drm_device *dev, int pipe)
  5222. {
  5223. drm_i915_private_t *dev_priv = dev->dev_private;
  5224. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  5225. do_intel_finish_page_flip(dev, crtc);
  5226. }
  5227. void intel_finish_page_flip_plane(struct drm_device *dev, int plane)
  5228. {
  5229. drm_i915_private_t *dev_priv = dev->dev_private;
  5230. struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane];
  5231. do_intel_finish_page_flip(dev, crtc);
  5232. }
  5233. void intel_prepare_page_flip(struct drm_device *dev, int plane)
  5234. {
  5235. drm_i915_private_t *dev_priv = dev->dev_private;
  5236. struct intel_crtc *intel_crtc =
  5237. to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]);
  5238. unsigned long flags;
  5239. spin_lock_irqsave(&dev->event_lock, flags);
  5240. if (intel_crtc->unpin_work) {
  5241. if ((++intel_crtc->unpin_work->pending) > 1)
  5242. DRM_ERROR("Prepared flip multiple times\n");
  5243. } else {
  5244. DRM_DEBUG_DRIVER("preparing flip with no unpin work?\n");
  5245. }
  5246. spin_unlock_irqrestore(&dev->event_lock, flags);
  5247. }
  5248. static int intel_crtc_page_flip(struct drm_crtc *crtc,
  5249. struct drm_framebuffer *fb,
  5250. struct drm_pending_vblank_event *event)
  5251. {
  5252. struct drm_device *dev = crtc->dev;
  5253. struct drm_i915_private *dev_priv = dev->dev_private;
  5254. struct intel_framebuffer *intel_fb;
  5255. struct drm_i915_gem_object *obj;
  5256. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5257. struct intel_unpin_work *work;
  5258. unsigned long flags, offset;
  5259. int pipe = intel_crtc->pipe;
  5260. u32 pf, pipesrc;
  5261. int ret;
  5262. work = kzalloc(sizeof *work, GFP_KERNEL);
  5263. if (work == NULL)
  5264. return -ENOMEM;
  5265. work->event = event;
  5266. work->dev = crtc->dev;
  5267. intel_fb = to_intel_framebuffer(crtc->fb);
  5268. work->old_fb_obj = intel_fb->obj;
  5269. INIT_WORK(&work->work, intel_unpin_work_fn);
  5270. /* We borrow the event spin lock for protecting unpin_work */
  5271. spin_lock_irqsave(&dev->event_lock, flags);
  5272. if (intel_crtc->unpin_work) {
  5273. spin_unlock_irqrestore(&dev->event_lock, flags);
  5274. kfree(work);
  5275. DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
  5276. return -EBUSY;
  5277. }
  5278. intel_crtc->unpin_work = work;
  5279. spin_unlock_irqrestore(&dev->event_lock, flags);
  5280. intel_fb = to_intel_framebuffer(fb);
  5281. obj = intel_fb->obj;
  5282. mutex_lock(&dev->struct_mutex);
  5283. ret = intel_pin_and_fence_fb_obj(dev, obj, LP_RING(dev_priv));
  5284. if (ret)
  5285. goto cleanup_work;
  5286. /* Reference the objects for the scheduled work. */
  5287. drm_gem_object_reference(&work->old_fb_obj->base);
  5288. drm_gem_object_reference(&obj->base);
  5289. crtc->fb = fb;
  5290. ret = drm_vblank_get(dev, intel_crtc->pipe);
  5291. if (ret)
  5292. goto cleanup_objs;
  5293. if (IS_GEN3(dev) || IS_GEN2(dev)) {
  5294. u32 flip_mask;
  5295. /* Can't queue multiple flips, so wait for the previous
  5296. * one to finish before executing the next.
  5297. */
  5298. ret = BEGIN_LP_RING(2);
  5299. if (ret)
  5300. goto cleanup_objs;
  5301. if (intel_crtc->plane)
  5302. flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
  5303. else
  5304. flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
  5305. OUT_RING(MI_WAIT_FOR_EVENT | flip_mask);
  5306. OUT_RING(MI_NOOP);
  5307. ADVANCE_LP_RING();
  5308. }
  5309. work->pending_flip_obj = obj;
  5310. work->enable_stall_check = true;
  5311. /* Offset into the new buffer for cases of shared fbs between CRTCs */
  5312. offset = crtc->y * fb->pitch + crtc->x * fb->bits_per_pixel/8;
  5313. ret = BEGIN_LP_RING(4);
  5314. if (ret)
  5315. goto cleanup_objs;
  5316. /* Block clients from rendering to the new back buffer until
  5317. * the flip occurs and the object is no longer visible.
  5318. */
  5319. atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
  5320. switch (INTEL_INFO(dev)->gen) {
  5321. case 2:
  5322. OUT_RING(MI_DISPLAY_FLIP |
  5323. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  5324. OUT_RING(fb->pitch);
  5325. OUT_RING(obj->gtt_offset + offset);
  5326. OUT_RING(MI_NOOP);
  5327. break;
  5328. case 3:
  5329. OUT_RING(MI_DISPLAY_FLIP_I915 |
  5330. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  5331. OUT_RING(fb->pitch);
  5332. OUT_RING(obj->gtt_offset + offset);
  5333. OUT_RING(MI_NOOP);
  5334. break;
  5335. case 4:
  5336. case 5:
  5337. /* i965+ uses the linear or tiled offsets from the
  5338. * Display Registers (which do not change across a page-flip)
  5339. * so we need only reprogram the base address.
  5340. */
  5341. OUT_RING(MI_DISPLAY_FLIP |
  5342. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  5343. OUT_RING(fb->pitch);
  5344. OUT_RING(obj->gtt_offset | obj->tiling_mode);
  5345. /* XXX Enabling the panel-fitter across page-flip is so far
  5346. * untested on non-native modes, so ignore it for now.
  5347. * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
  5348. */
  5349. pf = 0;
  5350. pipesrc = I915_READ(PIPESRC(pipe)) & 0x0fff0fff;
  5351. OUT_RING(pf | pipesrc);
  5352. break;
  5353. case 6:
  5354. OUT_RING(MI_DISPLAY_FLIP |
  5355. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  5356. OUT_RING(fb->pitch | obj->tiling_mode);
  5357. OUT_RING(obj->gtt_offset);
  5358. pf = I915_READ(PF_CTL(pipe)) & PF_ENABLE;
  5359. pipesrc = I915_READ(PIPESRC(pipe)) & 0x0fff0fff;
  5360. OUT_RING(pf | pipesrc);
  5361. break;
  5362. }
  5363. ADVANCE_LP_RING();
  5364. mutex_unlock(&dev->struct_mutex);
  5365. trace_i915_flip_request(intel_crtc->plane, obj);
  5366. return 0;
  5367. cleanup_objs:
  5368. drm_gem_object_unreference(&work->old_fb_obj->base);
  5369. drm_gem_object_unreference(&obj->base);
  5370. cleanup_work:
  5371. mutex_unlock(&dev->struct_mutex);
  5372. spin_lock_irqsave(&dev->event_lock, flags);
  5373. intel_crtc->unpin_work = NULL;
  5374. spin_unlock_irqrestore(&dev->event_lock, flags);
  5375. kfree(work);
  5376. return ret;
  5377. }
  5378. static void intel_crtc_reset(struct drm_crtc *crtc)
  5379. {
  5380. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5381. /* Reset flags back to the 'unknown' status so that they
  5382. * will be correctly set on the initial modeset.
  5383. */
  5384. intel_crtc->dpms_mode = -1;
  5385. }
  5386. static struct drm_crtc_helper_funcs intel_helper_funcs = {
  5387. .dpms = intel_crtc_dpms,
  5388. .mode_fixup = intel_crtc_mode_fixup,
  5389. .mode_set = intel_crtc_mode_set,
  5390. .mode_set_base = intel_pipe_set_base,
  5391. .mode_set_base_atomic = intel_pipe_set_base_atomic,
  5392. .load_lut = intel_crtc_load_lut,
  5393. .disable = intel_crtc_disable,
  5394. };
  5395. static const struct drm_crtc_funcs intel_crtc_funcs = {
  5396. .reset = intel_crtc_reset,
  5397. .cursor_set = intel_crtc_cursor_set,
  5398. .cursor_move = intel_crtc_cursor_move,
  5399. .gamma_set = intel_crtc_gamma_set,
  5400. .set_config = drm_crtc_helper_set_config,
  5401. .destroy = intel_crtc_destroy,
  5402. .page_flip = intel_crtc_page_flip,
  5403. };
  5404. static void intel_sanitize_modesetting(struct drm_device *dev,
  5405. int pipe, int plane)
  5406. {
  5407. struct drm_i915_private *dev_priv = dev->dev_private;
  5408. u32 reg, val;
  5409. if (HAS_PCH_SPLIT(dev))
  5410. return;
  5411. /* Who knows what state these registers were left in by the BIOS or
  5412. * grub?
  5413. *
  5414. * If we leave the registers in a conflicting state (e.g. with the
  5415. * display plane reading from the other pipe than the one we intend
  5416. * to use) then when we attempt to teardown the active mode, we will
  5417. * not disable the pipes and planes in the correct order -- leaving
  5418. * a plane reading from a disabled pipe and possibly leading to
  5419. * undefined behaviour.
  5420. */
  5421. reg = DSPCNTR(plane);
  5422. val = I915_READ(reg);
  5423. if ((val & DISPLAY_PLANE_ENABLE) == 0)
  5424. return;
  5425. if (!!(val & DISPPLANE_SEL_PIPE_MASK) == pipe)
  5426. return;
  5427. /* This display plane is active and attached to the other CPU pipe. */
  5428. pipe = !pipe;
  5429. /* Disable the plane and wait for it to stop reading from the pipe. */
  5430. intel_disable_plane(dev_priv, plane, pipe);
  5431. intel_disable_pipe(dev_priv, pipe);
  5432. }
  5433. static void intel_crtc_init(struct drm_device *dev, int pipe)
  5434. {
  5435. drm_i915_private_t *dev_priv = dev->dev_private;
  5436. struct intel_crtc *intel_crtc;
  5437. int i;
  5438. intel_crtc = kzalloc(sizeof(struct intel_crtc) + (INTELFB_CONN_LIMIT * sizeof(struct drm_connector *)), GFP_KERNEL);
  5439. if (intel_crtc == NULL)
  5440. return;
  5441. drm_crtc_init(dev, &intel_crtc->base, &intel_crtc_funcs);
  5442. drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256);
  5443. for (i = 0; i < 256; i++) {
  5444. intel_crtc->lut_r[i] = i;
  5445. intel_crtc->lut_g[i] = i;
  5446. intel_crtc->lut_b[i] = i;
  5447. }
  5448. /* Swap pipes & planes for FBC on pre-965 */
  5449. intel_crtc->pipe = pipe;
  5450. intel_crtc->plane = pipe;
  5451. if (IS_MOBILE(dev) && IS_GEN3(dev)) {
  5452. DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
  5453. intel_crtc->plane = !pipe;
  5454. }
  5455. BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
  5456. dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL);
  5457. dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base;
  5458. dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base;
  5459. intel_crtc_reset(&intel_crtc->base);
  5460. intel_crtc->active = true; /* force the pipe off on setup_init_config */
  5461. if (HAS_PCH_SPLIT(dev)) {
  5462. intel_helper_funcs.prepare = ironlake_crtc_prepare;
  5463. intel_helper_funcs.commit = ironlake_crtc_commit;
  5464. } else {
  5465. intel_helper_funcs.prepare = i9xx_crtc_prepare;
  5466. intel_helper_funcs.commit = i9xx_crtc_commit;
  5467. }
  5468. drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
  5469. intel_crtc->busy = false;
  5470. setup_timer(&intel_crtc->idle_timer, intel_crtc_idle_timer,
  5471. (unsigned long)intel_crtc);
  5472. intel_sanitize_modesetting(dev, intel_crtc->pipe, intel_crtc->plane);
  5473. }
  5474. int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data,
  5475. struct drm_file *file)
  5476. {
  5477. drm_i915_private_t *dev_priv = dev->dev_private;
  5478. struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
  5479. struct drm_mode_object *drmmode_obj;
  5480. struct intel_crtc *crtc;
  5481. if (!dev_priv) {
  5482. DRM_ERROR("called with no initialization\n");
  5483. return -EINVAL;
  5484. }
  5485. drmmode_obj = drm_mode_object_find(dev, pipe_from_crtc_id->crtc_id,
  5486. DRM_MODE_OBJECT_CRTC);
  5487. if (!drmmode_obj) {
  5488. DRM_ERROR("no such CRTC id\n");
  5489. return -EINVAL;
  5490. }
  5491. crtc = to_intel_crtc(obj_to_crtc(drmmode_obj));
  5492. pipe_from_crtc_id->pipe = crtc->pipe;
  5493. return 0;
  5494. }
  5495. static int intel_encoder_clones(struct drm_device *dev, int type_mask)
  5496. {
  5497. struct intel_encoder *encoder;
  5498. int index_mask = 0;
  5499. int entry = 0;
  5500. list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) {
  5501. if (type_mask & encoder->clone_mask)
  5502. index_mask |= (1 << entry);
  5503. entry++;
  5504. }
  5505. return index_mask;
  5506. }
  5507. static bool has_edp_a(struct drm_device *dev)
  5508. {
  5509. struct drm_i915_private *dev_priv = dev->dev_private;
  5510. if (!IS_MOBILE(dev))
  5511. return false;
  5512. if ((I915_READ(DP_A) & DP_DETECTED) == 0)
  5513. return false;
  5514. if (IS_GEN5(dev) &&
  5515. (I915_READ(ILK_DISPLAY_CHICKEN_FUSES) & ILK_eDP_A_DISABLE))
  5516. return false;
  5517. return true;
  5518. }
  5519. static void intel_setup_outputs(struct drm_device *dev)
  5520. {
  5521. struct drm_i915_private *dev_priv = dev->dev_private;
  5522. struct intel_encoder *encoder;
  5523. bool dpd_is_edp = false;
  5524. bool has_lvds = false;
  5525. if (IS_MOBILE(dev) && !IS_I830(dev))
  5526. has_lvds = intel_lvds_init(dev);
  5527. if (!has_lvds && !HAS_PCH_SPLIT(dev)) {
  5528. /* disable the panel fitter on everything but LVDS */
  5529. I915_WRITE(PFIT_CONTROL, 0);
  5530. }
  5531. if (HAS_PCH_SPLIT(dev)) {
  5532. dpd_is_edp = intel_dpd_is_edp(dev);
  5533. if (has_edp_a(dev))
  5534. intel_dp_init(dev, DP_A);
  5535. if (dpd_is_edp && (I915_READ(PCH_DP_D) & DP_DETECTED))
  5536. intel_dp_init(dev, PCH_DP_D);
  5537. }
  5538. intel_crt_init(dev);
  5539. if (HAS_PCH_SPLIT(dev)) {
  5540. int found;
  5541. if (I915_READ(HDMIB) & PORT_DETECTED) {
  5542. /* PCH SDVOB multiplex with HDMIB */
  5543. found = intel_sdvo_init(dev, PCH_SDVOB);
  5544. if (!found)
  5545. intel_hdmi_init(dev, HDMIB);
  5546. if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
  5547. intel_dp_init(dev, PCH_DP_B);
  5548. }
  5549. if (I915_READ(HDMIC) & PORT_DETECTED)
  5550. intel_hdmi_init(dev, HDMIC);
  5551. if (I915_READ(HDMID) & PORT_DETECTED)
  5552. intel_hdmi_init(dev, HDMID);
  5553. if (I915_READ(PCH_DP_C) & DP_DETECTED)
  5554. intel_dp_init(dev, PCH_DP_C);
  5555. if (!dpd_is_edp && (I915_READ(PCH_DP_D) & DP_DETECTED))
  5556. intel_dp_init(dev, PCH_DP_D);
  5557. } else if (SUPPORTS_DIGITAL_OUTPUTS(dev)) {
  5558. bool found = false;
  5559. if (I915_READ(SDVOB) & SDVO_DETECTED) {
  5560. DRM_DEBUG_KMS("probing SDVOB\n");
  5561. found = intel_sdvo_init(dev, SDVOB);
  5562. if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) {
  5563. DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
  5564. intel_hdmi_init(dev, SDVOB);
  5565. }
  5566. if (!found && SUPPORTS_INTEGRATED_DP(dev)) {
  5567. DRM_DEBUG_KMS("probing DP_B\n");
  5568. intel_dp_init(dev, DP_B);
  5569. }
  5570. }
  5571. /* Before G4X SDVOC doesn't have its own detect register */
  5572. if (I915_READ(SDVOB) & SDVO_DETECTED) {
  5573. DRM_DEBUG_KMS("probing SDVOC\n");
  5574. found = intel_sdvo_init(dev, SDVOC);
  5575. }
  5576. if (!found && (I915_READ(SDVOC) & SDVO_DETECTED)) {
  5577. if (SUPPORTS_INTEGRATED_HDMI(dev)) {
  5578. DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
  5579. intel_hdmi_init(dev, SDVOC);
  5580. }
  5581. if (SUPPORTS_INTEGRATED_DP(dev)) {
  5582. DRM_DEBUG_KMS("probing DP_C\n");
  5583. intel_dp_init(dev, DP_C);
  5584. }
  5585. }
  5586. if (SUPPORTS_INTEGRATED_DP(dev) &&
  5587. (I915_READ(DP_D) & DP_DETECTED)) {
  5588. DRM_DEBUG_KMS("probing DP_D\n");
  5589. intel_dp_init(dev, DP_D);
  5590. }
  5591. } else if (IS_GEN2(dev))
  5592. intel_dvo_init(dev);
  5593. if (SUPPORTS_TV(dev))
  5594. intel_tv_init(dev);
  5595. list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) {
  5596. encoder->base.possible_crtcs = encoder->crtc_mask;
  5597. encoder->base.possible_clones =
  5598. intel_encoder_clones(dev, encoder->clone_mask);
  5599. }
  5600. intel_panel_setup_backlight(dev);
  5601. }
  5602. static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
  5603. {
  5604. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  5605. drm_framebuffer_cleanup(fb);
  5606. drm_gem_object_unreference_unlocked(&intel_fb->obj->base);
  5607. kfree(intel_fb);
  5608. }
  5609. static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
  5610. struct drm_file *file,
  5611. unsigned int *handle)
  5612. {
  5613. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  5614. struct drm_i915_gem_object *obj = intel_fb->obj;
  5615. return drm_gem_handle_create(file, &obj->base, handle);
  5616. }
  5617. static const struct drm_framebuffer_funcs intel_fb_funcs = {
  5618. .destroy = intel_user_framebuffer_destroy,
  5619. .create_handle = intel_user_framebuffer_create_handle,
  5620. };
  5621. int intel_framebuffer_init(struct drm_device *dev,
  5622. struct intel_framebuffer *intel_fb,
  5623. struct drm_mode_fb_cmd *mode_cmd,
  5624. struct drm_i915_gem_object *obj)
  5625. {
  5626. int ret;
  5627. if (obj->tiling_mode == I915_TILING_Y)
  5628. return -EINVAL;
  5629. if (mode_cmd->pitch & 63)
  5630. return -EINVAL;
  5631. switch (mode_cmd->bpp) {
  5632. case 8:
  5633. case 16:
  5634. case 24:
  5635. case 32:
  5636. break;
  5637. default:
  5638. return -EINVAL;
  5639. }
  5640. ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs);
  5641. if (ret) {
  5642. DRM_ERROR("framebuffer init failed %d\n", ret);
  5643. return ret;
  5644. }
  5645. drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd);
  5646. intel_fb->obj = obj;
  5647. return 0;
  5648. }
  5649. static struct drm_framebuffer *
  5650. intel_user_framebuffer_create(struct drm_device *dev,
  5651. struct drm_file *filp,
  5652. struct drm_mode_fb_cmd *mode_cmd)
  5653. {
  5654. struct drm_i915_gem_object *obj;
  5655. struct intel_framebuffer *intel_fb;
  5656. int ret;
  5657. obj = to_intel_bo(drm_gem_object_lookup(dev, filp, mode_cmd->handle));
  5658. if (&obj->base == NULL)
  5659. return ERR_PTR(-ENOENT);
  5660. intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
  5661. if (!intel_fb)
  5662. return ERR_PTR(-ENOMEM);
  5663. ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj);
  5664. if (ret) {
  5665. drm_gem_object_unreference_unlocked(&obj->base);
  5666. kfree(intel_fb);
  5667. return ERR_PTR(ret);
  5668. }
  5669. return &intel_fb->base;
  5670. }
  5671. static const struct drm_mode_config_funcs intel_mode_funcs = {
  5672. .fb_create = intel_user_framebuffer_create,
  5673. .output_poll_changed = intel_fb_output_poll_changed,
  5674. };
  5675. static struct drm_i915_gem_object *
  5676. intel_alloc_context_page(struct drm_device *dev)
  5677. {
  5678. struct drm_i915_gem_object *ctx;
  5679. int ret;
  5680. ctx = i915_gem_alloc_object(dev, 4096);
  5681. if (!ctx) {
  5682. DRM_DEBUG("failed to alloc power context, RC6 disabled\n");
  5683. return NULL;
  5684. }
  5685. mutex_lock(&dev->struct_mutex);
  5686. ret = i915_gem_object_pin(ctx, 4096, true);
  5687. if (ret) {
  5688. DRM_ERROR("failed to pin power context: %d\n", ret);
  5689. goto err_unref;
  5690. }
  5691. ret = i915_gem_object_set_to_gtt_domain(ctx, 1);
  5692. if (ret) {
  5693. DRM_ERROR("failed to set-domain on power context: %d\n", ret);
  5694. goto err_unpin;
  5695. }
  5696. mutex_unlock(&dev->struct_mutex);
  5697. return ctx;
  5698. err_unpin:
  5699. i915_gem_object_unpin(ctx);
  5700. err_unref:
  5701. drm_gem_object_unreference(&ctx->base);
  5702. mutex_unlock(&dev->struct_mutex);
  5703. return NULL;
  5704. }
  5705. bool ironlake_set_drps(struct drm_device *dev, u8 val)
  5706. {
  5707. struct drm_i915_private *dev_priv = dev->dev_private;
  5708. u16 rgvswctl;
  5709. rgvswctl = I915_READ16(MEMSWCTL);
  5710. if (rgvswctl & MEMCTL_CMD_STS) {
  5711. DRM_DEBUG("gpu busy, RCS change rejected\n");
  5712. return false; /* still busy with another command */
  5713. }
  5714. rgvswctl = (MEMCTL_CMD_CHFREQ << MEMCTL_CMD_SHIFT) |
  5715. (val << MEMCTL_FREQ_SHIFT) | MEMCTL_SFCAVM;
  5716. I915_WRITE16(MEMSWCTL, rgvswctl);
  5717. POSTING_READ16(MEMSWCTL);
  5718. rgvswctl |= MEMCTL_CMD_STS;
  5719. I915_WRITE16(MEMSWCTL, rgvswctl);
  5720. return true;
  5721. }
  5722. void ironlake_enable_drps(struct drm_device *dev)
  5723. {
  5724. struct drm_i915_private *dev_priv = dev->dev_private;
  5725. u32 rgvmodectl = I915_READ(MEMMODECTL);
  5726. u8 fmax, fmin, fstart, vstart;
  5727. /* Enable temp reporting */
  5728. I915_WRITE16(PMMISC, I915_READ(PMMISC) | MCPPCE_EN);
  5729. I915_WRITE16(TSC1, I915_READ(TSC1) | TSE);
  5730. /* 100ms RC evaluation intervals */
  5731. I915_WRITE(RCUPEI, 100000);
  5732. I915_WRITE(RCDNEI, 100000);
  5733. /* Set max/min thresholds to 90ms and 80ms respectively */
  5734. I915_WRITE(RCBMAXAVG, 90000);
  5735. I915_WRITE(RCBMINAVG, 80000);
  5736. I915_WRITE(MEMIHYST, 1);
  5737. /* Set up min, max, and cur for interrupt handling */
  5738. fmax = (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT;
  5739. fmin = (rgvmodectl & MEMMODE_FMIN_MASK);
  5740. fstart = (rgvmodectl & MEMMODE_FSTART_MASK) >>
  5741. MEMMODE_FSTART_SHIFT;
  5742. vstart = (I915_READ(PXVFREQ_BASE + (fstart * 4)) & PXVFREQ_PX_MASK) >>
  5743. PXVFREQ_PX_SHIFT;
  5744. dev_priv->fmax = fmax; /* IPS callback will increase this */
  5745. dev_priv->fstart = fstart;
  5746. dev_priv->max_delay = fstart;
  5747. dev_priv->min_delay = fmin;
  5748. dev_priv->cur_delay = fstart;
  5749. DRM_DEBUG_DRIVER("fmax: %d, fmin: %d, fstart: %d\n",
  5750. fmax, fmin, fstart);
  5751. I915_WRITE(MEMINTREN, MEMINT_CX_SUPR_EN | MEMINT_EVAL_CHG_EN);
  5752. /*
  5753. * Interrupts will be enabled in ironlake_irq_postinstall
  5754. */
  5755. I915_WRITE(VIDSTART, vstart);
  5756. POSTING_READ(VIDSTART);
  5757. rgvmodectl |= MEMMODE_SWMODE_EN;
  5758. I915_WRITE(MEMMODECTL, rgvmodectl);
  5759. if (wait_for((I915_READ(MEMSWCTL) & MEMCTL_CMD_STS) == 0, 10))
  5760. DRM_ERROR("stuck trying to change perf mode\n");
  5761. msleep(1);
  5762. ironlake_set_drps(dev, fstart);
  5763. dev_priv->last_count1 = I915_READ(0x112e4) + I915_READ(0x112e8) +
  5764. I915_READ(0x112e0);
  5765. dev_priv->last_time1 = jiffies_to_msecs(jiffies);
  5766. dev_priv->last_count2 = I915_READ(0x112f4);
  5767. getrawmonotonic(&dev_priv->last_time2);
  5768. }
  5769. void ironlake_disable_drps(struct drm_device *dev)
  5770. {
  5771. struct drm_i915_private *dev_priv = dev->dev_private;
  5772. u16 rgvswctl = I915_READ16(MEMSWCTL);
  5773. /* Ack interrupts, disable EFC interrupt */
  5774. I915_WRITE(MEMINTREN, I915_READ(MEMINTREN) & ~MEMINT_EVAL_CHG_EN);
  5775. I915_WRITE(MEMINTRSTS, MEMINT_EVAL_CHG);
  5776. I915_WRITE(DEIER, I915_READ(DEIER) & ~DE_PCU_EVENT);
  5777. I915_WRITE(DEIIR, DE_PCU_EVENT);
  5778. I915_WRITE(DEIMR, I915_READ(DEIMR) | DE_PCU_EVENT);
  5779. /* Go back to the starting frequency */
  5780. ironlake_set_drps(dev, dev_priv->fstart);
  5781. msleep(1);
  5782. rgvswctl |= MEMCTL_CMD_STS;
  5783. I915_WRITE(MEMSWCTL, rgvswctl);
  5784. msleep(1);
  5785. }
  5786. void gen6_set_rps(struct drm_device *dev, u8 val)
  5787. {
  5788. struct drm_i915_private *dev_priv = dev->dev_private;
  5789. u32 swreq;
  5790. swreq = (val & 0x3ff) << 25;
  5791. I915_WRITE(GEN6_RPNSWREQ, swreq);
  5792. }
  5793. void gen6_disable_rps(struct drm_device *dev)
  5794. {
  5795. struct drm_i915_private *dev_priv = dev->dev_private;
  5796. I915_WRITE(GEN6_RPNSWREQ, 1 << 31);
  5797. I915_WRITE(GEN6_PMINTRMSK, 0xffffffff);
  5798. I915_WRITE(GEN6_PMIER, 0);
  5799. I915_WRITE(GEN6_PMIIR, I915_READ(GEN6_PMIIR));
  5800. }
  5801. static unsigned long intel_pxfreq(u32 vidfreq)
  5802. {
  5803. unsigned long freq;
  5804. int div = (vidfreq & 0x3f0000) >> 16;
  5805. int post = (vidfreq & 0x3000) >> 12;
  5806. int pre = (vidfreq & 0x7);
  5807. if (!pre)
  5808. return 0;
  5809. freq = ((div * 133333) / ((1<<post) * pre));
  5810. return freq;
  5811. }
  5812. void intel_init_emon(struct drm_device *dev)
  5813. {
  5814. struct drm_i915_private *dev_priv = dev->dev_private;
  5815. u32 lcfuse;
  5816. u8 pxw[16];
  5817. int i;
  5818. /* Disable to program */
  5819. I915_WRITE(ECR, 0);
  5820. POSTING_READ(ECR);
  5821. /* Program energy weights for various events */
  5822. I915_WRITE(SDEW, 0x15040d00);
  5823. I915_WRITE(CSIEW0, 0x007f0000);
  5824. I915_WRITE(CSIEW1, 0x1e220004);
  5825. I915_WRITE(CSIEW2, 0x04000004);
  5826. for (i = 0; i < 5; i++)
  5827. I915_WRITE(PEW + (i * 4), 0);
  5828. for (i = 0; i < 3; i++)
  5829. I915_WRITE(DEW + (i * 4), 0);
  5830. /* Program P-state weights to account for frequency power adjustment */
  5831. for (i = 0; i < 16; i++) {
  5832. u32 pxvidfreq = I915_READ(PXVFREQ_BASE + (i * 4));
  5833. unsigned long freq = intel_pxfreq(pxvidfreq);
  5834. unsigned long vid = (pxvidfreq & PXVFREQ_PX_MASK) >>
  5835. PXVFREQ_PX_SHIFT;
  5836. unsigned long val;
  5837. val = vid * vid;
  5838. val *= (freq / 1000);
  5839. val *= 255;
  5840. val /= (127*127*900);
  5841. if (val > 0xff)
  5842. DRM_ERROR("bad pxval: %ld\n", val);
  5843. pxw[i] = val;
  5844. }
  5845. /* Render standby states get 0 weight */
  5846. pxw[14] = 0;
  5847. pxw[15] = 0;
  5848. for (i = 0; i < 4; i++) {
  5849. u32 val = (pxw[i*4] << 24) | (pxw[(i*4)+1] << 16) |
  5850. (pxw[(i*4)+2] << 8) | (pxw[(i*4)+3]);
  5851. I915_WRITE(PXW + (i * 4), val);
  5852. }
  5853. /* Adjust magic regs to magic values (more experimental results) */
  5854. I915_WRITE(OGW0, 0);
  5855. I915_WRITE(OGW1, 0);
  5856. I915_WRITE(EG0, 0x00007f00);
  5857. I915_WRITE(EG1, 0x0000000e);
  5858. I915_WRITE(EG2, 0x000e0000);
  5859. I915_WRITE(EG3, 0x68000300);
  5860. I915_WRITE(EG4, 0x42000000);
  5861. I915_WRITE(EG5, 0x00140031);
  5862. I915_WRITE(EG6, 0);
  5863. I915_WRITE(EG7, 0);
  5864. for (i = 0; i < 8; i++)
  5865. I915_WRITE(PXWL + (i * 4), 0);
  5866. /* Enable PMON + select events */
  5867. I915_WRITE(ECR, 0x80000019);
  5868. lcfuse = I915_READ(LCFUSE02);
  5869. dev_priv->corr = (lcfuse & LCFUSE_HIV_MASK);
  5870. }
  5871. void gen6_enable_rps(struct drm_i915_private *dev_priv)
  5872. {
  5873. u32 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
  5874. u32 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
  5875. u32 pcu_mbox;
  5876. int cur_freq, min_freq, max_freq;
  5877. int i;
  5878. /* Here begins a magic sequence of register writes to enable
  5879. * auto-downclocking.
  5880. *
  5881. * Perhaps there might be some value in exposing these to
  5882. * userspace...
  5883. */
  5884. I915_WRITE(GEN6_RC_STATE, 0);
  5885. __gen6_gt_force_wake_get(dev_priv);
  5886. /* disable the counters and set deterministic thresholds */
  5887. I915_WRITE(GEN6_RC_CONTROL, 0);
  5888. I915_WRITE(GEN6_RC1_WAKE_RATE_LIMIT, 1000 << 16);
  5889. I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16 | 30);
  5890. I915_WRITE(GEN6_RC6pp_WAKE_RATE_LIMIT, 30);
  5891. I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000);
  5892. I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25);
  5893. for (i = 0; i < I915_NUM_RINGS; i++)
  5894. I915_WRITE(RING_MAX_IDLE(dev_priv->ring[i].mmio_base), 10);
  5895. I915_WRITE(GEN6_RC_SLEEP, 0);
  5896. I915_WRITE(GEN6_RC1e_THRESHOLD, 1000);
  5897. I915_WRITE(GEN6_RC6_THRESHOLD, 50000);
  5898. I915_WRITE(GEN6_RC6p_THRESHOLD, 100000);
  5899. I915_WRITE(GEN6_RC6pp_THRESHOLD, 64000); /* unused */
  5900. I915_WRITE(GEN6_RC_CONTROL,
  5901. GEN6_RC_CTL_RC6p_ENABLE |
  5902. GEN6_RC_CTL_RC6_ENABLE |
  5903. GEN6_RC_CTL_EI_MODE(1) |
  5904. GEN6_RC_CTL_HW_ENABLE);
  5905. I915_WRITE(GEN6_RPNSWREQ,
  5906. GEN6_FREQUENCY(10) |
  5907. GEN6_OFFSET(0) |
  5908. GEN6_AGGRESSIVE_TURBO);
  5909. I915_WRITE(GEN6_RC_VIDEO_FREQ,
  5910. GEN6_FREQUENCY(12));
  5911. I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 1000000);
  5912. I915_WRITE(GEN6_RP_INTERRUPT_LIMITS,
  5913. 18 << 24 |
  5914. 6 << 16);
  5915. I915_WRITE(GEN6_RP_UP_THRESHOLD, 10000);
  5916. I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 1000000);
  5917. I915_WRITE(GEN6_RP_UP_EI, 100000);
  5918. I915_WRITE(GEN6_RP_DOWN_EI, 5000000);
  5919. I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10);
  5920. I915_WRITE(GEN6_RP_CONTROL,
  5921. GEN6_RP_MEDIA_TURBO |
  5922. GEN6_RP_USE_NORMAL_FREQ |
  5923. GEN6_RP_MEDIA_IS_GFX |
  5924. GEN6_RP_ENABLE |
  5925. GEN6_RP_UP_BUSY_AVG |
  5926. GEN6_RP_DOWN_IDLE_CONT);
  5927. if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0,
  5928. 500))
  5929. DRM_ERROR("timeout waiting for pcode mailbox to become idle\n");
  5930. I915_WRITE(GEN6_PCODE_DATA, 0);
  5931. I915_WRITE(GEN6_PCODE_MAILBOX,
  5932. GEN6_PCODE_READY |
  5933. GEN6_PCODE_WRITE_MIN_FREQ_TABLE);
  5934. if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0,
  5935. 500))
  5936. DRM_ERROR("timeout waiting for pcode mailbox to finish\n");
  5937. min_freq = (rp_state_cap & 0xff0000) >> 16;
  5938. max_freq = rp_state_cap & 0xff;
  5939. cur_freq = (gt_perf_status & 0xff00) >> 8;
  5940. /* Check for overclock support */
  5941. if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0,
  5942. 500))
  5943. DRM_ERROR("timeout waiting for pcode mailbox to become idle\n");
  5944. I915_WRITE(GEN6_PCODE_MAILBOX, GEN6_READ_OC_PARAMS);
  5945. pcu_mbox = I915_READ(GEN6_PCODE_DATA);
  5946. if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0,
  5947. 500))
  5948. DRM_ERROR("timeout waiting for pcode mailbox to finish\n");
  5949. if (pcu_mbox & (1<<31)) { /* OC supported */
  5950. max_freq = pcu_mbox & 0xff;
  5951. DRM_DEBUG_DRIVER("overclocking supported, adjusting frequency max to %dMHz\n", pcu_mbox * 50);
  5952. }
  5953. /* In units of 100MHz */
  5954. dev_priv->max_delay = max_freq;
  5955. dev_priv->min_delay = min_freq;
  5956. dev_priv->cur_delay = cur_freq;
  5957. /* requires MSI enabled */
  5958. I915_WRITE(GEN6_PMIER,
  5959. GEN6_PM_MBOX_EVENT |
  5960. GEN6_PM_THERMAL_EVENT |
  5961. GEN6_PM_RP_DOWN_TIMEOUT |
  5962. GEN6_PM_RP_UP_THRESHOLD |
  5963. GEN6_PM_RP_DOWN_THRESHOLD |
  5964. GEN6_PM_RP_UP_EI_EXPIRED |
  5965. GEN6_PM_RP_DOWN_EI_EXPIRED);
  5966. I915_WRITE(GEN6_PMIMR, 0);
  5967. /* enable all PM interrupts */
  5968. I915_WRITE(GEN6_PMINTRMSK, 0);
  5969. __gen6_gt_force_wake_put(dev_priv);
  5970. }
  5971. void intel_enable_clock_gating(struct drm_device *dev)
  5972. {
  5973. struct drm_i915_private *dev_priv = dev->dev_private;
  5974. int pipe;
  5975. /*
  5976. * Disable clock gating reported to work incorrectly according to the
  5977. * specs, but enable as much else as we can.
  5978. */
  5979. if (HAS_PCH_SPLIT(dev)) {
  5980. uint32_t dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE;
  5981. if (IS_GEN5(dev)) {
  5982. /* Required for FBC */
  5983. dspclk_gate |= DPFCUNIT_CLOCK_GATE_DISABLE |
  5984. DPFCRUNIT_CLOCK_GATE_DISABLE |
  5985. DPFDUNIT_CLOCK_GATE_DISABLE;
  5986. /* Required for CxSR */
  5987. dspclk_gate |= DPARBUNIT_CLOCK_GATE_DISABLE;
  5988. I915_WRITE(PCH_3DCGDIS0,
  5989. MARIUNIT_CLOCK_GATE_DISABLE |
  5990. SVSMUNIT_CLOCK_GATE_DISABLE);
  5991. I915_WRITE(PCH_3DCGDIS1,
  5992. VFMUNIT_CLOCK_GATE_DISABLE);
  5993. }
  5994. I915_WRITE(PCH_DSPCLK_GATE_D, dspclk_gate);
  5995. /*
  5996. * On Ibex Peak and Cougar Point, we need to disable clock
  5997. * gating for the panel power sequencer or it will fail to
  5998. * start up when no ports are active.
  5999. */
  6000. I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE);
  6001. /*
  6002. * According to the spec the following bits should be set in
  6003. * order to enable memory self-refresh
  6004. * The bit 22/21 of 0x42004
  6005. * The bit 5 of 0x42020
  6006. * The bit 15 of 0x45000
  6007. */
  6008. if (IS_GEN5(dev)) {
  6009. I915_WRITE(ILK_DISPLAY_CHICKEN2,
  6010. (I915_READ(ILK_DISPLAY_CHICKEN2) |
  6011. ILK_DPARB_GATE | ILK_VSDPFD_FULL));
  6012. I915_WRITE(ILK_DSPCLK_GATE,
  6013. (I915_READ(ILK_DSPCLK_GATE) |
  6014. ILK_DPARB_CLK_GATE));
  6015. I915_WRITE(DISP_ARB_CTL,
  6016. (I915_READ(DISP_ARB_CTL) |
  6017. DISP_FBC_WM_DIS));
  6018. I915_WRITE(WM3_LP_ILK, 0);
  6019. I915_WRITE(WM2_LP_ILK, 0);
  6020. I915_WRITE(WM1_LP_ILK, 0);
  6021. }
  6022. /*
  6023. * Based on the document from hardware guys the following bits
  6024. * should be set unconditionally in order to enable FBC.
  6025. * The bit 22 of 0x42000
  6026. * The bit 22 of 0x42004
  6027. * The bit 7,8,9 of 0x42020.
  6028. */
  6029. if (IS_IRONLAKE_M(dev)) {
  6030. I915_WRITE(ILK_DISPLAY_CHICKEN1,
  6031. I915_READ(ILK_DISPLAY_CHICKEN1) |
  6032. ILK_FBCQ_DIS);
  6033. I915_WRITE(ILK_DISPLAY_CHICKEN2,
  6034. I915_READ(ILK_DISPLAY_CHICKEN2) |
  6035. ILK_DPARB_GATE);
  6036. I915_WRITE(ILK_DSPCLK_GATE,
  6037. I915_READ(ILK_DSPCLK_GATE) |
  6038. ILK_DPFC_DIS1 |
  6039. ILK_DPFC_DIS2 |
  6040. ILK_CLK_FBC);
  6041. }
  6042. I915_WRITE(ILK_DISPLAY_CHICKEN2,
  6043. I915_READ(ILK_DISPLAY_CHICKEN2) |
  6044. ILK_ELPIN_409_SELECT);
  6045. if (IS_GEN5(dev)) {
  6046. I915_WRITE(_3D_CHICKEN2,
  6047. _3D_CHICKEN2_WM_READ_PIPELINED << 16 |
  6048. _3D_CHICKEN2_WM_READ_PIPELINED);
  6049. }
  6050. if (IS_GEN6(dev)) {
  6051. I915_WRITE(WM3_LP_ILK, 0);
  6052. I915_WRITE(WM2_LP_ILK, 0);
  6053. I915_WRITE(WM1_LP_ILK, 0);
  6054. /*
  6055. * According to the spec the following bits should be
  6056. * set in order to enable memory self-refresh and fbc:
  6057. * The bit21 and bit22 of 0x42000
  6058. * The bit21 and bit22 of 0x42004
  6059. * The bit5 and bit7 of 0x42020
  6060. * The bit14 of 0x70180
  6061. * The bit14 of 0x71180
  6062. */
  6063. I915_WRITE(ILK_DISPLAY_CHICKEN1,
  6064. I915_READ(ILK_DISPLAY_CHICKEN1) |
  6065. ILK_FBCQ_DIS | ILK_PABSTRETCH_DIS);
  6066. I915_WRITE(ILK_DISPLAY_CHICKEN2,
  6067. I915_READ(ILK_DISPLAY_CHICKEN2) |
  6068. ILK_DPARB_GATE | ILK_VSDPFD_FULL);
  6069. I915_WRITE(ILK_DSPCLK_GATE,
  6070. I915_READ(ILK_DSPCLK_GATE) |
  6071. ILK_DPARB_CLK_GATE |
  6072. ILK_DPFD_CLK_GATE);
  6073. for_each_pipe(pipe)
  6074. I915_WRITE(DSPCNTR(pipe),
  6075. I915_READ(DSPCNTR(pipe)) |
  6076. DISPPLANE_TRICKLE_FEED_DISABLE);
  6077. }
  6078. } else if (IS_G4X(dev)) {
  6079. uint32_t dspclk_gate;
  6080. I915_WRITE(RENCLK_GATE_D1, 0);
  6081. I915_WRITE(RENCLK_GATE_D2, VF_UNIT_CLOCK_GATE_DISABLE |
  6082. GS_UNIT_CLOCK_GATE_DISABLE |
  6083. CL_UNIT_CLOCK_GATE_DISABLE);
  6084. I915_WRITE(RAMCLK_GATE_D, 0);
  6085. dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE |
  6086. OVRUNIT_CLOCK_GATE_DISABLE |
  6087. OVCUNIT_CLOCK_GATE_DISABLE;
  6088. if (IS_GM45(dev))
  6089. dspclk_gate |= DSSUNIT_CLOCK_GATE_DISABLE;
  6090. I915_WRITE(DSPCLK_GATE_D, dspclk_gate);
  6091. } else if (IS_CRESTLINE(dev)) {
  6092. I915_WRITE(RENCLK_GATE_D1, I965_RCC_CLOCK_GATE_DISABLE);
  6093. I915_WRITE(RENCLK_GATE_D2, 0);
  6094. I915_WRITE(DSPCLK_GATE_D, 0);
  6095. I915_WRITE(RAMCLK_GATE_D, 0);
  6096. I915_WRITE16(DEUC, 0);
  6097. } else if (IS_BROADWATER(dev)) {
  6098. I915_WRITE(RENCLK_GATE_D1, I965_RCZ_CLOCK_GATE_DISABLE |
  6099. I965_RCC_CLOCK_GATE_DISABLE |
  6100. I965_RCPB_CLOCK_GATE_DISABLE |
  6101. I965_ISC_CLOCK_GATE_DISABLE |
  6102. I965_FBC_CLOCK_GATE_DISABLE);
  6103. I915_WRITE(RENCLK_GATE_D2, 0);
  6104. } else if (IS_GEN3(dev)) {
  6105. u32 dstate = I915_READ(D_STATE);
  6106. dstate |= DSTATE_PLL_D3_OFF | DSTATE_GFX_CLOCK_GATING |
  6107. DSTATE_DOT_CLOCK_GATING;
  6108. I915_WRITE(D_STATE, dstate);
  6109. } else if (IS_I85X(dev) || IS_I865G(dev)) {
  6110. I915_WRITE(RENCLK_GATE_D1, SV_CLOCK_GATE_DISABLE);
  6111. } else if (IS_I830(dev)) {
  6112. I915_WRITE(DSPCLK_GATE_D, OVRUNIT_CLOCK_GATE_DISABLE);
  6113. }
  6114. }
  6115. static void ironlake_teardown_rc6(struct drm_device *dev)
  6116. {
  6117. struct drm_i915_private *dev_priv = dev->dev_private;
  6118. if (dev_priv->renderctx) {
  6119. i915_gem_object_unpin(dev_priv->renderctx);
  6120. drm_gem_object_unreference(&dev_priv->renderctx->base);
  6121. dev_priv->renderctx = NULL;
  6122. }
  6123. if (dev_priv->pwrctx) {
  6124. i915_gem_object_unpin(dev_priv->pwrctx);
  6125. drm_gem_object_unreference(&dev_priv->pwrctx->base);
  6126. dev_priv->pwrctx = NULL;
  6127. }
  6128. }
  6129. static void ironlake_disable_rc6(struct drm_device *dev)
  6130. {
  6131. struct drm_i915_private *dev_priv = dev->dev_private;
  6132. if (I915_READ(PWRCTXA)) {
  6133. /* Wake the GPU, prevent RC6, then restore RSTDBYCTL */
  6134. I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) | RCX_SW_EXIT);
  6135. wait_for(((I915_READ(RSTDBYCTL) & RSX_STATUS_MASK) == RSX_STATUS_ON),
  6136. 50);
  6137. I915_WRITE(PWRCTXA, 0);
  6138. POSTING_READ(PWRCTXA);
  6139. I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) & ~RCX_SW_EXIT);
  6140. POSTING_READ(RSTDBYCTL);
  6141. }
  6142. ironlake_teardown_rc6(dev);
  6143. }
  6144. static int ironlake_setup_rc6(struct drm_device *dev)
  6145. {
  6146. struct drm_i915_private *dev_priv = dev->dev_private;
  6147. if (dev_priv->renderctx == NULL)
  6148. dev_priv->renderctx = intel_alloc_context_page(dev);
  6149. if (!dev_priv->renderctx)
  6150. return -ENOMEM;
  6151. if (dev_priv->pwrctx == NULL)
  6152. dev_priv->pwrctx = intel_alloc_context_page(dev);
  6153. if (!dev_priv->pwrctx) {
  6154. ironlake_teardown_rc6(dev);
  6155. return -ENOMEM;
  6156. }
  6157. return 0;
  6158. }
  6159. void ironlake_enable_rc6(struct drm_device *dev)
  6160. {
  6161. struct drm_i915_private *dev_priv = dev->dev_private;
  6162. int ret;
  6163. /* rc6 disabled by default due to repeated reports of hanging during
  6164. * boot and resume.
  6165. */
  6166. if (!i915_enable_rc6)
  6167. return;
  6168. ret = ironlake_setup_rc6(dev);
  6169. if (ret)
  6170. return;
  6171. /*
  6172. * GPU can automatically power down the render unit if given a page
  6173. * to save state.
  6174. */
  6175. ret = BEGIN_LP_RING(6);
  6176. if (ret) {
  6177. ironlake_teardown_rc6(dev);
  6178. return;
  6179. }
  6180. OUT_RING(MI_SUSPEND_FLUSH | MI_SUSPEND_FLUSH_EN);
  6181. OUT_RING(MI_SET_CONTEXT);
  6182. OUT_RING(dev_priv->renderctx->gtt_offset |
  6183. MI_MM_SPACE_GTT |
  6184. MI_SAVE_EXT_STATE_EN |
  6185. MI_RESTORE_EXT_STATE_EN |
  6186. MI_RESTORE_INHIBIT);
  6187. OUT_RING(MI_SUSPEND_FLUSH);
  6188. OUT_RING(MI_NOOP);
  6189. OUT_RING(MI_FLUSH);
  6190. ADVANCE_LP_RING();
  6191. I915_WRITE(PWRCTXA, dev_priv->pwrctx->gtt_offset | PWRCTX_EN);
  6192. I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) & ~RCX_SW_EXIT);
  6193. }
  6194. /* Set up chip specific display functions */
  6195. static void intel_init_display(struct drm_device *dev)
  6196. {
  6197. struct drm_i915_private *dev_priv = dev->dev_private;
  6198. /* We always want a DPMS function */
  6199. if (HAS_PCH_SPLIT(dev))
  6200. dev_priv->display.dpms = ironlake_crtc_dpms;
  6201. else
  6202. dev_priv->display.dpms = i9xx_crtc_dpms;
  6203. if (I915_HAS_FBC(dev)) {
  6204. if (HAS_PCH_SPLIT(dev)) {
  6205. dev_priv->display.fbc_enabled = ironlake_fbc_enabled;
  6206. dev_priv->display.enable_fbc = ironlake_enable_fbc;
  6207. dev_priv->display.disable_fbc = ironlake_disable_fbc;
  6208. } else if (IS_GM45(dev)) {
  6209. dev_priv->display.fbc_enabled = g4x_fbc_enabled;
  6210. dev_priv->display.enable_fbc = g4x_enable_fbc;
  6211. dev_priv->display.disable_fbc = g4x_disable_fbc;
  6212. } else if (IS_CRESTLINE(dev)) {
  6213. dev_priv->display.fbc_enabled = i8xx_fbc_enabled;
  6214. dev_priv->display.enable_fbc = i8xx_enable_fbc;
  6215. dev_priv->display.disable_fbc = i8xx_disable_fbc;
  6216. }
  6217. /* 855GM needs testing */
  6218. }
  6219. /* Returns the core display clock speed */
  6220. if (IS_I945G(dev) || (IS_G33(dev) && ! IS_PINEVIEW_M(dev)))
  6221. dev_priv->display.get_display_clock_speed =
  6222. i945_get_display_clock_speed;
  6223. else if (IS_I915G(dev))
  6224. dev_priv->display.get_display_clock_speed =
  6225. i915_get_display_clock_speed;
  6226. else if (IS_I945GM(dev) || IS_845G(dev) || IS_PINEVIEW_M(dev))
  6227. dev_priv->display.get_display_clock_speed =
  6228. i9xx_misc_get_display_clock_speed;
  6229. else if (IS_I915GM(dev))
  6230. dev_priv->display.get_display_clock_speed =
  6231. i915gm_get_display_clock_speed;
  6232. else if (IS_I865G(dev))
  6233. dev_priv->display.get_display_clock_speed =
  6234. i865_get_display_clock_speed;
  6235. else if (IS_I85X(dev))
  6236. dev_priv->display.get_display_clock_speed =
  6237. i855_get_display_clock_speed;
  6238. else /* 852, 830 */
  6239. dev_priv->display.get_display_clock_speed =
  6240. i830_get_display_clock_speed;
  6241. /* For FIFO watermark updates */
  6242. if (HAS_PCH_SPLIT(dev)) {
  6243. if (IS_GEN5(dev)) {
  6244. if (I915_READ(MLTR_ILK) & ILK_SRLT_MASK)
  6245. dev_priv->display.update_wm = ironlake_update_wm;
  6246. else {
  6247. DRM_DEBUG_KMS("Failed to get proper latency. "
  6248. "Disable CxSR\n");
  6249. dev_priv->display.update_wm = NULL;
  6250. }
  6251. } else if (IS_GEN6(dev)) {
  6252. if (SNB_READ_WM0_LATENCY()) {
  6253. dev_priv->display.update_wm = sandybridge_update_wm;
  6254. } else {
  6255. DRM_DEBUG_KMS("Failed to read display plane latency. "
  6256. "Disable CxSR\n");
  6257. dev_priv->display.update_wm = NULL;
  6258. }
  6259. } else
  6260. dev_priv->display.update_wm = NULL;
  6261. } else if (IS_PINEVIEW(dev)) {
  6262. if (!intel_get_cxsr_latency(IS_PINEVIEW_G(dev),
  6263. dev_priv->is_ddr3,
  6264. dev_priv->fsb_freq,
  6265. dev_priv->mem_freq)) {
  6266. DRM_INFO("failed to find known CxSR latency "
  6267. "(found ddr%s fsb freq %d, mem freq %d), "
  6268. "disabling CxSR\n",
  6269. (dev_priv->is_ddr3 == 1) ? "3": "2",
  6270. dev_priv->fsb_freq, dev_priv->mem_freq);
  6271. /* Disable CxSR and never update its watermark again */
  6272. pineview_disable_cxsr(dev);
  6273. dev_priv->display.update_wm = NULL;
  6274. } else
  6275. dev_priv->display.update_wm = pineview_update_wm;
  6276. } else if (IS_G4X(dev))
  6277. dev_priv->display.update_wm = g4x_update_wm;
  6278. else if (IS_GEN4(dev))
  6279. dev_priv->display.update_wm = i965_update_wm;
  6280. else if (IS_GEN3(dev)) {
  6281. dev_priv->display.update_wm = i9xx_update_wm;
  6282. dev_priv->display.get_fifo_size = i9xx_get_fifo_size;
  6283. } else if (IS_I85X(dev)) {
  6284. dev_priv->display.update_wm = i9xx_update_wm;
  6285. dev_priv->display.get_fifo_size = i85x_get_fifo_size;
  6286. } else {
  6287. dev_priv->display.update_wm = i830_update_wm;
  6288. if (IS_845G(dev))
  6289. dev_priv->display.get_fifo_size = i845_get_fifo_size;
  6290. else
  6291. dev_priv->display.get_fifo_size = i830_get_fifo_size;
  6292. }
  6293. }
  6294. /*
  6295. * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend,
  6296. * resume, or other times. This quirk makes sure that's the case for
  6297. * affected systems.
  6298. */
  6299. static void quirk_pipea_force (struct drm_device *dev)
  6300. {
  6301. struct drm_i915_private *dev_priv = dev->dev_private;
  6302. dev_priv->quirks |= QUIRK_PIPEA_FORCE;
  6303. DRM_DEBUG_DRIVER("applying pipe a force quirk\n");
  6304. }
  6305. struct intel_quirk {
  6306. int device;
  6307. int subsystem_vendor;
  6308. int subsystem_device;
  6309. void (*hook)(struct drm_device *dev);
  6310. };
  6311. struct intel_quirk intel_quirks[] = {
  6312. /* HP Compaq 2730p needs pipe A force quirk (LP: #291555) */
  6313. { 0x2a42, 0x103c, 0x30eb, quirk_pipea_force },
  6314. /* HP Mini needs pipe A force quirk (LP: #322104) */
  6315. { 0x27ae,0x103c, 0x361a, quirk_pipea_force },
  6316. /* Thinkpad R31 needs pipe A force quirk */
  6317. { 0x3577, 0x1014, 0x0505, quirk_pipea_force },
  6318. /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
  6319. { 0x2592, 0x1179, 0x0001, quirk_pipea_force },
  6320. /* ThinkPad X30 needs pipe A force quirk (LP: #304614) */
  6321. { 0x3577, 0x1014, 0x0513, quirk_pipea_force },
  6322. /* ThinkPad X40 needs pipe A force quirk */
  6323. /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
  6324. { 0x2782, 0x17aa, 0x201a, quirk_pipea_force },
  6325. /* 855 & before need to leave pipe A & dpll A up */
  6326. { 0x3582, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force },
  6327. { 0x2562, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force },
  6328. };
  6329. static void intel_init_quirks(struct drm_device *dev)
  6330. {
  6331. struct pci_dev *d = dev->pdev;
  6332. int i;
  6333. for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) {
  6334. struct intel_quirk *q = &intel_quirks[i];
  6335. if (d->device == q->device &&
  6336. (d->subsystem_vendor == q->subsystem_vendor ||
  6337. q->subsystem_vendor == PCI_ANY_ID) &&
  6338. (d->subsystem_device == q->subsystem_device ||
  6339. q->subsystem_device == PCI_ANY_ID))
  6340. q->hook(dev);
  6341. }
  6342. }
  6343. /* Disable the VGA plane that we never use */
  6344. static void i915_disable_vga(struct drm_device *dev)
  6345. {
  6346. struct drm_i915_private *dev_priv = dev->dev_private;
  6347. u8 sr1;
  6348. u32 vga_reg;
  6349. if (HAS_PCH_SPLIT(dev))
  6350. vga_reg = CPU_VGACNTRL;
  6351. else
  6352. vga_reg = VGACNTRL;
  6353. vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
  6354. outb(1, VGA_SR_INDEX);
  6355. sr1 = inb(VGA_SR_DATA);
  6356. outb(sr1 | 1<<5, VGA_SR_DATA);
  6357. vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
  6358. udelay(300);
  6359. I915_WRITE(vga_reg, VGA_DISP_DISABLE);
  6360. POSTING_READ(vga_reg);
  6361. }
  6362. void intel_modeset_init(struct drm_device *dev)
  6363. {
  6364. struct drm_i915_private *dev_priv = dev->dev_private;
  6365. int i;
  6366. drm_mode_config_init(dev);
  6367. dev->mode_config.min_width = 0;
  6368. dev->mode_config.min_height = 0;
  6369. dev->mode_config.funcs = (void *)&intel_mode_funcs;
  6370. intel_init_quirks(dev);
  6371. intel_init_display(dev);
  6372. if (IS_GEN2(dev)) {
  6373. dev->mode_config.max_width = 2048;
  6374. dev->mode_config.max_height = 2048;
  6375. } else if (IS_GEN3(dev)) {
  6376. dev->mode_config.max_width = 4096;
  6377. dev->mode_config.max_height = 4096;
  6378. } else {
  6379. dev->mode_config.max_width = 8192;
  6380. dev->mode_config.max_height = 8192;
  6381. }
  6382. dev->mode_config.fb_base = dev->agp->base;
  6383. DRM_DEBUG_KMS("%d display pipe%s available.\n",
  6384. dev_priv->num_pipe, dev_priv->num_pipe > 1 ? "s" : "");
  6385. for (i = 0; i < dev_priv->num_pipe; i++) {
  6386. intel_crtc_init(dev, i);
  6387. }
  6388. intel_setup_outputs(dev);
  6389. intel_enable_clock_gating(dev);
  6390. /* Just disable it once at startup */
  6391. i915_disable_vga(dev);
  6392. if (IS_IRONLAKE_M(dev)) {
  6393. ironlake_enable_drps(dev);
  6394. intel_init_emon(dev);
  6395. }
  6396. if (IS_GEN6(dev))
  6397. gen6_enable_rps(dev_priv);
  6398. if (IS_IRONLAKE_M(dev))
  6399. ironlake_enable_rc6(dev);
  6400. INIT_WORK(&dev_priv->idle_work, intel_idle_update);
  6401. setup_timer(&dev_priv->idle_timer, intel_gpu_idle_timer,
  6402. (unsigned long)dev);
  6403. intel_setup_overlay(dev);
  6404. }
  6405. void intel_modeset_cleanup(struct drm_device *dev)
  6406. {
  6407. struct drm_i915_private *dev_priv = dev->dev_private;
  6408. struct drm_crtc *crtc;
  6409. struct intel_crtc *intel_crtc;
  6410. drm_kms_helper_poll_fini(dev);
  6411. mutex_lock(&dev->struct_mutex);
  6412. intel_unregister_dsm_handler();
  6413. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  6414. /* Skip inactive CRTCs */
  6415. if (!crtc->fb)
  6416. continue;
  6417. intel_crtc = to_intel_crtc(crtc);
  6418. intel_increase_pllclock(crtc);
  6419. }
  6420. if (dev_priv->display.disable_fbc)
  6421. dev_priv->display.disable_fbc(dev);
  6422. if (IS_IRONLAKE_M(dev))
  6423. ironlake_disable_drps(dev);
  6424. if (IS_GEN6(dev))
  6425. gen6_disable_rps(dev);
  6426. if (IS_IRONLAKE_M(dev))
  6427. ironlake_disable_rc6(dev);
  6428. mutex_unlock(&dev->struct_mutex);
  6429. /* Disable the irq before mode object teardown, for the irq might
  6430. * enqueue unpin/hotplug work. */
  6431. drm_irq_uninstall(dev);
  6432. cancel_work_sync(&dev_priv->hotplug_work);
  6433. /* Shut off idle work before the crtcs get freed. */
  6434. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  6435. intel_crtc = to_intel_crtc(crtc);
  6436. del_timer_sync(&intel_crtc->idle_timer);
  6437. }
  6438. del_timer_sync(&dev_priv->idle_timer);
  6439. cancel_work_sync(&dev_priv->idle_work);
  6440. drm_mode_config_cleanup(dev);
  6441. }
  6442. /*
  6443. * Return which encoder is currently attached for connector.
  6444. */
  6445. struct drm_encoder *intel_best_encoder(struct drm_connector *connector)
  6446. {
  6447. return &intel_attached_encoder(connector)->base;
  6448. }
  6449. void intel_connector_attach_encoder(struct intel_connector *connector,
  6450. struct intel_encoder *encoder)
  6451. {
  6452. connector->encoder = encoder;
  6453. drm_mode_connector_attach_encoder(&connector->base,
  6454. &encoder->base);
  6455. }
  6456. /*
  6457. * set vga decode state - true == enable VGA decode
  6458. */
  6459. int intel_modeset_vga_set_state(struct drm_device *dev, bool state)
  6460. {
  6461. struct drm_i915_private *dev_priv = dev->dev_private;
  6462. u16 gmch_ctrl;
  6463. pci_read_config_word(dev_priv->bridge_dev, INTEL_GMCH_CTRL, &gmch_ctrl);
  6464. if (state)
  6465. gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
  6466. else
  6467. gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
  6468. pci_write_config_word(dev_priv->bridge_dev, INTEL_GMCH_CTRL, gmch_ctrl);
  6469. return 0;
  6470. }
  6471. #ifdef CONFIG_DEBUG_FS
  6472. #include <linux/seq_file.h>
  6473. struct intel_display_error_state {
  6474. struct intel_cursor_error_state {
  6475. u32 control;
  6476. u32 position;
  6477. u32 base;
  6478. u32 size;
  6479. } cursor[2];
  6480. struct intel_pipe_error_state {
  6481. u32 conf;
  6482. u32 source;
  6483. u32 htotal;
  6484. u32 hblank;
  6485. u32 hsync;
  6486. u32 vtotal;
  6487. u32 vblank;
  6488. u32 vsync;
  6489. } pipe[2];
  6490. struct intel_plane_error_state {
  6491. u32 control;
  6492. u32 stride;
  6493. u32 size;
  6494. u32 pos;
  6495. u32 addr;
  6496. u32 surface;
  6497. u32 tile_offset;
  6498. } plane[2];
  6499. };
  6500. struct intel_display_error_state *
  6501. intel_display_capture_error_state(struct drm_device *dev)
  6502. {
  6503. drm_i915_private_t *dev_priv = dev->dev_private;
  6504. struct intel_display_error_state *error;
  6505. int i;
  6506. error = kmalloc(sizeof(*error), GFP_ATOMIC);
  6507. if (error == NULL)
  6508. return NULL;
  6509. for (i = 0; i < 2; i++) {
  6510. error->cursor[i].control = I915_READ(CURCNTR(i));
  6511. error->cursor[i].position = I915_READ(CURPOS(i));
  6512. error->cursor[i].base = I915_READ(CURBASE(i));
  6513. error->plane[i].control = I915_READ(DSPCNTR(i));
  6514. error->plane[i].stride = I915_READ(DSPSTRIDE(i));
  6515. error->plane[i].size = I915_READ(DSPSIZE(i));
  6516. error->plane[i].pos= I915_READ(DSPPOS(i));
  6517. error->plane[i].addr = I915_READ(DSPADDR(i));
  6518. if (INTEL_INFO(dev)->gen >= 4) {
  6519. error->plane[i].surface = I915_READ(DSPSURF(i));
  6520. error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
  6521. }
  6522. error->pipe[i].conf = I915_READ(PIPECONF(i));
  6523. error->pipe[i].source = I915_READ(PIPESRC(i));
  6524. error->pipe[i].htotal = I915_READ(HTOTAL(i));
  6525. error->pipe[i].hblank = I915_READ(HBLANK(i));
  6526. error->pipe[i].hsync = I915_READ(HSYNC(i));
  6527. error->pipe[i].vtotal = I915_READ(VTOTAL(i));
  6528. error->pipe[i].vblank = I915_READ(VBLANK(i));
  6529. error->pipe[i].vsync = I915_READ(VSYNC(i));
  6530. }
  6531. return error;
  6532. }
  6533. void
  6534. intel_display_print_error_state(struct seq_file *m,
  6535. struct drm_device *dev,
  6536. struct intel_display_error_state *error)
  6537. {
  6538. int i;
  6539. for (i = 0; i < 2; i++) {
  6540. seq_printf(m, "Pipe [%d]:\n", i);
  6541. seq_printf(m, " CONF: %08x\n", error->pipe[i].conf);
  6542. seq_printf(m, " SRC: %08x\n", error->pipe[i].source);
  6543. seq_printf(m, " HTOTAL: %08x\n", error->pipe[i].htotal);
  6544. seq_printf(m, " HBLANK: %08x\n", error->pipe[i].hblank);
  6545. seq_printf(m, " HSYNC: %08x\n", error->pipe[i].hsync);
  6546. seq_printf(m, " VTOTAL: %08x\n", error->pipe[i].vtotal);
  6547. seq_printf(m, " VBLANK: %08x\n", error->pipe[i].vblank);
  6548. seq_printf(m, " VSYNC: %08x\n", error->pipe[i].vsync);
  6549. seq_printf(m, "Plane [%d]:\n", i);
  6550. seq_printf(m, " CNTR: %08x\n", error->plane[i].control);
  6551. seq_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
  6552. seq_printf(m, " SIZE: %08x\n", error->plane[i].size);
  6553. seq_printf(m, " POS: %08x\n", error->plane[i].pos);
  6554. seq_printf(m, " ADDR: %08x\n", error->plane[i].addr);
  6555. if (INTEL_INFO(dev)->gen >= 4) {
  6556. seq_printf(m, " SURF: %08x\n", error->plane[i].surface);
  6557. seq_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
  6558. }
  6559. seq_printf(m, "Cursor [%d]:\n", i);
  6560. seq_printf(m, " CNTR: %08x\n", error->cursor[i].control);
  6561. seq_printf(m, " POS: %08x\n", error->cursor[i].position);
  6562. seq_printf(m, " BASE: %08x\n", error->cursor[i].base);
  6563. }
  6564. }
  6565. #endif