intel_display.c 228 KB

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