evergreen.c 184 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128
  1. /*
  2. * Copyright 2010 Advanced Micro Devices, Inc.
  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 shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * Authors: Alex Deucher
  23. */
  24. #include <linux/firmware.h>
  25. #include <linux/slab.h>
  26. #include <drm/drmP.h>
  27. #include "radeon.h"
  28. #include "radeon_asic.h"
  29. #include "radeon_audio.h"
  30. #include <drm/radeon_drm.h>
  31. #include "evergreend.h"
  32. #include "atom.h"
  33. #include "avivod.h"
  34. #include "evergreen_reg.h"
  35. #include "evergreen_blit_shaders.h"
  36. #include "radeon_ucode.h"
  37. /*
  38. * Indirect registers accessor
  39. */
  40. u32 eg_cg_rreg(struct radeon_device *rdev, u32 reg)
  41. {
  42. unsigned long flags;
  43. u32 r;
  44. spin_lock_irqsave(&rdev->cg_idx_lock, flags);
  45. WREG32(EVERGREEN_CG_IND_ADDR, ((reg) & 0xffff));
  46. r = RREG32(EVERGREEN_CG_IND_DATA);
  47. spin_unlock_irqrestore(&rdev->cg_idx_lock, flags);
  48. return r;
  49. }
  50. void eg_cg_wreg(struct radeon_device *rdev, u32 reg, u32 v)
  51. {
  52. unsigned long flags;
  53. spin_lock_irqsave(&rdev->cg_idx_lock, flags);
  54. WREG32(EVERGREEN_CG_IND_ADDR, ((reg) & 0xffff));
  55. WREG32(EVERGREEN_CG_IND_DATA, (v));
  56. spin_unlock_irqrestore(&rdev->cg_idx_lock, flags);
  57. }
  58. u32 eg_pif_phy0_rreg(struct radeon_device *rdev, u32 reg)
  59. {
  60. unsigned long flags;
  61. u32 r;
  62. spin_lock_irqsave(&rdev->pif_idx_lock, flags);
  63. WREG32(EVERGREEN_PIF_PHY0_INDEX, ((reg) & 0xffff));
  64. r = RREG32(EVERGREEN_PIF_PHY0_DATA);
  65. spin_unlock_irqrestore(&rdev->pif_idx_lock, flags);
  66. return r;
  67. }
  68. void eg_pif_phy0_wreg(struct radeon_device *rdev, u32 reg, u32 v)
  69. {
  70. unsigned long flags;
  71. spin_lock_irqsave(&rdev->pif_idx_lock, flags);
  72. WREG32(EVERGREEN_PIF_PHY0_INDEX, ((reg) & 0xffff));
  73. WREG32(EVERGREEN_PIF_PHY0_DATA, (v));
  74. spin_unlock_irqrestore(&rdev->pif_idx_lock, flags);
  75. }
  76. u32 eg_pif_phy1_rreg(struct radeon_device *rdev, u32 reg)
  77. {
  78. unsigned long flags;
  79. u32 r;
  80. spin_lock_irqsave(&rdev->pif_idx_lock, flags);
  81. WREG32(EVERGREEN_PIF_PHY1_INDEX, ((reg) & 0xffff));
  82. r = RREG32(EVERGREEN_PIF_PHY1_DATA);
  83. spin_unlock_irqrestore(&rdev->pif_idx_lock, flags);
  84. return r;
  85. }
  86. void eg_pif_phy1_wreg(struct radeon_device *rdev, u32 reg, u32 v)
  87. {
  88. unsigned long flags;
  89. spin_lock_irqsave(&rdev->pif_idx_lock, flags);
  90. WREG32(EVERGREEN_PIF_PHY1_INDEX, ((reg) & 0xffff));
  91. WREG32(EVERGREEN_PIF_PHY1_DATA, (v));
  92. spin_unlock_irqrestore(&rdev->pif_idx_lock, flags);
  93. }
  94. static const u32 crtc_offsets[6] =
  95. {
  96. EVERGREEN_CRTC0_REGISTER_OFFSET,
  97. EVERGREEN_CRTC1_REGISTER_OFFSET,
  98. EVERGREEN_CRTC2_REGISTER_OFFSET,
  99. EVERGREEN_CRTC3_REGISTER_OFFSET,
  100. EVERGREEN_CRTC4_REGISTER_OFFSET,
  101. EVERGREEN_CRTC5_REGISTER_OFFSET
  102. };
  103. #include "clearstate_evergreen.h"
  104. static const u32 sumo_rlc_save_restore_register_list[] =
  105. {
  106. 0x98fc,
  107. 0x9830,
  108. 0x9834,
  109. 0x9838,
  110. 0x9870,
  111. 0x9874,
  112. 0x8a14,
  113. 0x8b24,
  114. 0x8bcc,
  115. 0x8b10,
  116. 0x8d00,
  117. 0x8d04,
  118. 0x8c00,
  119. 0x8c04,
  120. 0x8c08,
  121. 0x8c0c,
  122. 0x8d8c,
  123. 0x8c20,
  124. 0x8c24,
  125. 0x8c28,
  126. 0x8c18,
  127. 0x8c1c,
  128. 0x8cf0,
  129. 0x8e2c,
  130. 0x8e38,
  131. 0x8c30,
  132. 0x9508,
  133. 0x9688,
  134. 0x9608,
  135. 0x960c,
  136. 0x9610,
  137. 0x9614,
  138. 0x88c4,
  139. 0x88d4,
  140. 0xa008,
  141. 0x900c,
  142. 0x9100,
  143. 0x913c,
  144. 0x98f8,
  145. 0x98f4,
  146. 0x9b7c,
  147. 0x3f8c,
  148. 0x8950,
  149. 0x8954,
  150. 0x8a18,
  151. 0x8b28,
  152. 0x9144,
  153. 0x9148,
  154. 0x914c,
  155. 0x3f90,
  156. 0x3f94,
  157. 0x915c,
  158. 0x9160,
  159. 0x9178,
  160. 0x917c,
  161. 0x9180,
  162. 0x918c,
  163. 0x9190,
  164. 0x9194,
  165. 0x9198,
  166. 0x919c,
  167. 0x91a8,
  168. 0x91ac,
  169. 0x91b0,
  170. 0x91b4,
  171. 0x91b8,
  172. 0x91c4,
  173. 0x91c8,
  174. 0x91cc,
  175. 0x91d0,
  176. 0x91d4,
  177. 0x91e0,
  178. 0x91e4,
  179. 0x91ec,
  180. 0x91f0,
  181. 0x91f4,
  182. 0x9200,
  183. 0x9204,
  184. 0x929c,
  185. 0x9150,
  186. 0x802c,
  187. };
  188. static void evergreen_gpu_init(struct radeon_device *rdev);
  189. void evergreen_fini(struct radeon_device *rdev);
  190. void evergreen_pcie_gen2_enable(struct radeon_device *rdev);
  191. void evergreen_program_aspm(struct radeon_device *rdev);
  192. extern void cayman_cp_int_cntl_setup(struct radeon_device *rdev,
  193. int ring, u32 cp_int_cntl);
  194. extern void cayman_vm_decode_fault(struct radeon_device *rdev,
  195. u32 status, u32 addr);
  196. void cik_init_cp_pg_table(struct radeon_device *rdev);
  197. extern u32 si_get_csb_size(struct radeon_device *rdev);
  198. extern void si_get_csb_buffer(struct radeon_device *rdev, volatile u32 *buffer);
  199. extern u32 cik_get_csb_size(struct radeon_device *rdev);
  200. extern void cik_get_csb_buffer(struct radeon_device *rdev, volatile u32 *buffer);
  201. extern void rv770_set_clk_bypass_mode(struct radeon_device *rdev);
  202. static const u32 evergreen_golden_registers[] =
  203. {
  204. 0x3f90, 0xffff0000, 0xff000000,
  205. 0x9148, 0xffff0000, 0xff000000,
  206. 0x3f94, 0xffff0000, 0xff000000,
  207. 0x914c, 0xffff0000, 0xff000000,
  208. 0x9b7c, 0xffffffff, 0x00000000,
  209. 0x8a14, 0xffffffff, 0x00000007,
  210. 0x8b10, 0xffffffff, 0x00000000,
  211. 0x960c, 0xffffffff, 0x54763210,
  212. 0x88c4, 0xffffffff, 0x000000c2,
  213. 0x88d4, 0xffffffff, 0x00000010,
  214. 0x8974, 0xffffffff, 0x00000000,
  215. 0xc78, 0x00000080, 0x00000080,
  216. 0x5eb4, 0xffffffff, 0x00000002,
  217. 0x5e78, 0xffffffff, 0x001000f0,
  218. 0x6104, 0x01000300, 0x00000000,
  219. 0x5bc0, 0x00300000, 0x00000000,
  220. 0x7030, 0xffffffff, 0x00000011,
  221. 0x7c30, 0xffffffff, 0x00000011,
  222. 0x10830, 0xffffffff, 0x00000011,
  223. 0x11430, 0xffffffff, 0x00000011,
  224. 0x12030, 0xffffffff, 0x00000011,
  225. 0x12c30, 0xffffffff, 0x00000011,
  226. 0xd02c, 0xffffffff, 0x08421000,
  227. 0x240c, 0xffffffff, 0x00000380,
  228. 0x8b24, 0xffffffff, 0x00ff0fff,
  229. 0x28a4c, 0x06000000, 0x06000000,
  230. 0x10c, 0x00000001, 0x00000001,
  231. 0x8d00, 0xffffffff, 0x100e4848,
  232. 0x8d04, 0xffffffff, 0x00164745,
  233. 0x8c00, 0xffffffff, 0xe4000003,
  234. 0x8c04, 0xffffffff, 0x40600060,
  235. 0x8c08, 0xffffffff, 0x001c001c,
  236. 0x8cf0, 0xffffffff, 0x08e00620,
  237. 0x8c20, 0xffffffff, 0x00800080,
  238. 0x8c24, 0xffffffff, 0x00800080,
  239. 0x8c18, 0xffffffff, 0x20202078,
  240. 0x8c1c, 0xffffffff, 0x00001010,
  241. 0x28350, 0xffffffff, 0x00000000,
  242. 0xa008, 0xffffffff, 0x00010000,
  243. 0x5c4, 0xffffffff, 0x00000001,
  244. 0x9508, 0xffffffff, 0x00000002,
  245. 0x913c, 0x0000000f, 0x0000000a
  246. };
  247. static const u32 evergreen_golden_registers2[] =
  248. {
  249. 0x2f4c, 0xffffffff, 0x00000000,
  250. 0x54f4, 0xffffffff, 0x00000000,
  251. 0x54f0, 0xffffffff, 0x00000000,
  252. 0x5498, 0xffffffff, 0x00000000,
  253. 0x549c, 0xffffffff, 0x00000000,
  254. 0x5494, 0xffffffff, 0x00000000,
  255. 0x53cc, 0xffffffff, 0x00000000,
  256. 0x53c8, 0xffffffff, 0x00000000,
  257. 0x53c4, 0xffffffff, 0x00000000,
  258. 0x53c0, 0xffffffff, 0x00000000,
  259. 0x53bc, 0xffffffff, 0x00000000,
  260. 0x53b8, 0xffffffff, 0x00000000,
  261. 0x53b4, 0xffffffff, 0x00000000,
  262. 0x53b0, 0xffffffff, 0x00000000
  263. };
  264. static const u32 cypress_mgcg_init[] =
  265. {
  266. 0x802c, 0xffffffff, 0xc0000000,
  267. 0x5448, 0xffffffff, 0x00000100,
  268. 0x55e4, 0xffffffff, 0x00000100,
  269. 0x160c, 0xffffffff, 0x00000100,
  270. 0x5644, 0xffffffff, 0x00000100,
  271. 0xc164, 0xffffffff, 0x00000100,
  272. 0x8a18, 0xffffffff, 0x00000100,
  273. 0x897c, 0xffffffff, 0x06000100,
  274. 0x8b28, 0xffffffff, 0x00000100,
  275. 0x9144, 0xffffffff, 0x00000100,
  276. 0x9a60, 0xffffffff, 0x00000100,
  277. 0x9868, 0xffffffff, 0x00000100,
  278. 0x8d58, 0xffffffff, 0x00000100,
  279. 0x9510, 0xffffffff, 0x00000100,
  280. 0x949c, 0xffffffff, 0x00000100,
  281. 0x9654, 0xffffffff, 0x00000100,
  282. 0x9030, 0xffffffff, 0x00000100,
  283. 0x9034, 0xffffffff, 0x00000100,
  284. 0x9038, 0xffffffff, 0x00000100,
  285. 0x903c, 0xffffffff, 0x00000100,
  286. 0x9040, 0xffffffff, 0x00000100,
  287. 0xa200, 0xffffffff, 0x00000100,
  288. 0xa204, 0xffffffff, 0x00000100,
  289. 0xa208, 0xffffffff, 0x00000100,
  290. 0xa20c, 0xffffffff, 0x00000100,
  291. 0x971c, 0xffffffff, 0x00000100,
  292. 0x977c, 0xffffffff, 0x00000100,
  293. 0x3f80, 0xffffffff, 0x00000100,
  294. 0xa210, 0xffffffff, 0x00000100,
  295. 0xa214, 0xffffffff, 0x00000100,
  296. 0x4d8, 0xffffffff, 0x00000100,
  297. 0x9784, 0xffffffff, 0x00000100,
  298. 0x9698, 0xffffffff, 0x00000100,
  299. 0x4d4, 0xffffffff, 0x00000200,
  300. 0x30cc, 0xffffffff, 0x00000100,
  301. 0xd0c0, 0xffffffff, 0xff000100,
  302. 0x802c, 0xffffffff, 0x40000000,
  303. 0x915c, 0xffffffff, 0x00010000,
  304. 0x9160, 0xffffffff, 0x00030002,
  305. 0x9178, 0xffffffff, 0x00070000,
  306. 0x917c, 0xffffffff, 0x00030002,
  307. 0x9180, 0xffffffff, 0x00050004,
  308. 0x918c, 0xffffffff, 0x00010006,
  309. 0x9190, 0xffffffff, 0x00090008,
  310. 0x9194, 0xffffffff, 0x00070000,
  311. 0x9198, 0xffffffff, 0x00030002,
  312. 0x919c, 0xffffffff, 0x00050004,
  313. 0x91a8, 0xffffffff, 0x00010006,
  314. 0x91ac, 0xffffffff, 0x00090008,
  315. 0x91b0, 0xffffffff, 0x00070000,
  316. 0x91b4, 0xffffffff, 0x00030002,
  317. 0x91b8, 0xffffffff, 0x00050004,
  318. 0x91c4, 0xffffffff, 0x00010006,
  319. 0x91c8, 0xffffffff, 0x00090008,
  320. 0x91cc, 0xffffffff, 0x00070000,
  321. 0x91d0, 0xffffffff, 0x00030002,
  322. 0x91d4, 0xffffffff, 0x00050004,
  323. 0x91e0, 0xffffffff, 0x00010006,
  324. 0x91e4, 0xffffffff, 0x00090008,
  325. 0x91e8, 0xffffffff, 0x00000000,
  326. 0x91ec, 0xffffffff, 0x00070000,
  327. 0x91f0, 0xffffffff, 0x00030002,
  328. 0x91f4, 0xffffffff, 0x00050004,
  329. 0x9200, 0xffffffff, 0x00010006,
  330. 0x9204, 0xffffffff, 0x00090008,
  331. 0x9208, 0xffffffff, 0x00070000,
  332. 0x920c, 0xffffffff, 0x00030002,
  333. 0x9210, 0xffffffff, 0x00050004,
  334. 0x921c, 0xffffffff, 0x00010006,
  335. 0x9220, 0xffffffff, 0x00090008,
  336. 0x9224, 0xffffffff, 0x00070000,
  337. 0x9228, 0xffffffff, 0x00030002,
  338. 0x922c, 0xffffffff, 0x00050004,
  339. 0x9238, 0xffffffff, 0x00010006,
  340. 0x923c, 0xffffffff, 0x00090008,
  341. 0x9240, 0xffffffff, 0x00070000,
  342. 0x9244, 0xffffffff, 0x00030002,
  343. 0x9248, 0xffffffff, 0x00050004,
  344. 0x9254, 0xffffffff, 0x00010006,
  345. 0x9258, 0xffffffff, 0x00090008,
  346. 0x925c, 0xffffffff, 0x00070000,
  347. 0x9260, 0xffffffff, 0x00030002,
  348. 0x9264, 0xffffffff, 0x00050004,
  349. 0x9270, 0xffffffff, 0x00010006,
  350. 0x9274, 0xffffffff, 0x00090008,
  351. 0x9278, 0xffffffff, 0x00070000,
  352. 0x927c, 0xffffffff, 0x00030002,
  353. 0x9280, 0xffffffff, 0x00050004,
  354. 0x928c, 0xffffffff, 0x00010006,
  355. 0x9290, 0xffffffff, 0x00090008,
  356. 0x9294, 0xffffffff, 0x00000000,
  357. 0x929c, 0xffffffff, 0x00000001,
  358. 0x802c, 0xffffffff, 0x40010000,
  359. 0x915c, 0xffffffff, 0x00010000,
  360. 0x9160, 0xffffffff, 0x00030002,
  361. 0x9178, 0xffffffff, 0x00070000,
  362. 0x917c, 0xffffffff, 0x00030002,
  363. 0x9180, 0xffffffff, 0x00050004,
  364. 0x918c, 0xffffffff, 0x00010006,
  365. 0x9190, 0xffffffff, 0x00090008,
  366. 0x9194, 0xffffffff, 0x00070000,
  367. 0x9198, 0xffffffff, 0x00030002,
  368. 0x919c, 0xffffffff, 0x00050004,
  369. 0x91a8, 0xffffffff, 0x00010006,
  370. 0x91ac, 0xffffffff, 0x00090008,
  371. 0x91b0, 0xffffffff, 0x00070000,
  372. 0x91b4, 0xffffffff, 0x00030002,
  373. 0x91b8, 0xffffffff, 0x00050004,
  374. 0x91c4, 0xffffffff, 0x00010006,
  375. 0x91c8, 0xffffffff, 0x00090008,
  376. 0x91cc, 0xffffffff, 0x00070000,
  377. 0x91d0, 0xffffffff, 0x00030002,
  378. 0x91d4, 0xffffffff, 0x00050004,
  379. 0x91e0, 0xffffffff, 0x00010006,
  380. 0x91e4, 0xffffffff, 0x00090008,
  381. 0x91e8, 0xffffffff, 0x00000000,
  382. 0x91ec, 0xffffffff, 0x00070000,
  383. 0x91f0, 0xffffffff, 0x00030002,
  384. 0x91f4, 0xffffffff, 0x00050004,
  385. 0x9200, 0xffffffff, 0x00010006,
  386. 0x9204, 0xffffffff, 0x00090008,
  387. 0x9208, 0xffffffff, 0x00070000,
  388. 0x920c, 0xffffffff, 0x00030002,
  389. 0x9210, 0xffffffff, 0x00050004,
  390. 0x921c, 0xffffffff, 0x00010006,
  391. 0x9220, 0xffffffff, 0x00090008,
  392. 0x9224, 0xffffffff, 0x00070000,
  393. 0x9228, 0xffffffff, 0x00030002,
  394. 0x922c, 0xffffffff, 0x00050004,
  395. 0x9238, 0xffffffff, 0x00010006,
  396. 0x923c, 0xffffffff, 0x00090008,
  397. 0x9240, 0xffffffff, 0x00070000,
  398. 0x9244, 0xffffffff, 0x00030002,
  399. 0x9248, 0xffffffff, 0x00050004,
  400. 0x9254, 0xffffffff, 0x00010006,
  401. 0x9258, 0xffffffff, 0x00090008,
  402. 0x925c, 0xffffffff, 0x00070000,
  403. 0x9260, 0xffffffff, 0x00030002,
  404. 0x9264, 0xffffffff, 0x00050004,
  405. 0x9270, 0xffffffff, 0x00010006,
  406. 0x9274, 0xffffffff, 0x00090008,
  407. 0x9278, 0xffffffff, 0x00070000,
  408. 0x927c, 0xffffffff, 0x00030002,
  409. 0x9280, 0xffffffff, 0x00050004,
  410. 0x928c, 0xffffffff, 0x00010006,
  411. 0x9290, 0xffffffff, 0x00090008,
  412. 0x9294, 0xffffffff, 0x00000000,
  413. 0x929c, 0xffffffff, 0x00000001,
  414. 0x802c, 0xffffffff, 0xc0000000
  415. };
  416. static const u32 redwood_mgcg_init[] =
  417. {
  418. 0x802c, 0xffffffff, 0xc0000000,
  419. 0x5448, 0xffffffff, 0x00000100,
  420. 0x55e4, 0xffffffff, 0x00000100,
  421. 0x160c, 0xffffffff, 0x00000100,
  422. 0x5644, 0xffffffff, 0x00000100,
  423. 0xc164, 0xffffffff, 0x00000100,
  424. 0x8a18, 0xffffffff, 0x00000100,
  425. 0x897c, 0xffffffff, 0x06000100,
  426. 0x8b28, 0xffffffff, 0x00000100,
  427. 0x9144, 0xffffffff, 0x00000100,
  428. 0x9a60, 0xffffffff, 0x00000100,
  429. 0x9868, 0xffffffff, 0x00000100,
  430. 0x8d58, 0xffffffff, 0x00000100,
  431. 0x9510, 0xffffffff, 0x00000100,
  432. 0x949c, 0xffffffff, 0x00000100,
  433. 0x9654, 0xffffffff, 0x00000100,
  434. 0x9030, 0xffffffff, 0x00000100,
  435. 0x9034, 0xffffffff, 0x00000100,
  436. 0x9038, 0xffffffff, 0x00000100,
  437. 0x903c, 0xffffffff, 0x00000100,
  438. 0x9040, 0xffffffff, 0x00000100,
  439. 0xa200, 0xffffffff, 0x00000100,
  440. 0xa204, 0xffffffff, 0x00000100,
  441. 0xa208, 0xffffffff, 0x00000100,
  442. 0xa20c, 0xffffffff, 0x00000100,
  443. 0x971c, 0xffffffff, 0x00000100,
  444. 0x977c, 0xffffffff, 0x00000100,
  445. 0x3f80, 0xffffffff, 0x00000100,
  446. 0xa210, 0xffffffff, 0x00000100,
  447. 0xa214, 0xffffffff, 0x00000100,
  448. 0x4d8, 0xffffffff, 0x00000100,
  449. 0x9784, 0xffffffff, 0x00000100,
  450. 0x9698, 0xffffffff, 0x00000100,
  451. 0x4d4, 0xffffffff, 0x00000200,
  452. 0x30cc, 0xffffffff, 0x00000100,
  453. 0xd0c0, 0xffffffff, 0xff000100,
  454. 0x802c, 0xffffffff, 0x40000000,
  455. 0x915c, 0xffffffff, 0x00010000,
  456. 0x9160, 0xffffffff, 0x00030002,
  457. 0x9178, 0xffffffff, 0x00070000,
  458. 0x917c, 0xffffffff, 0x00030002,
  459. 0x9180, 0xffffffff, 0x00050004,
  460. 0x918c, 0xffffffff, 0x00010006,
  461. 0x9190, 0xffffffff, 0x00090008,
  462. 0x9194, 0xffffffff, 0x00070000,
  463. 0x9198, 0xffffffff, 0x00030002,
  464. 0x919c, 0xffffffff, 0x00050004,
  465. 0x91a8, 0xffffffff, 0x00010006,
  466. 0x91ac, 0xffffffff, 0x00090008,
  467. 0x91b0, 0xffffffff, 0x00070000,
  468. 0x91b4, 0xffffffff, 0x00030002,
  469. 0x91b8, 0xffffffff, 0x00050004,
  470. 0x91c4, 0xffffffff, 0x00010006,
  471. 0x91c8, 0xffffffff, 0x00090008,
  472. 0x91cc, 0xffffffff, 0x00070000,
  473. 0x91d0, 0xffffffff, 0x00030002,
  474. 0x91d4, 0xffffffff, 0x00050004,
  475. 0x91e0, 0xffffffff, 0x00010006,
  476. 0x91e4, 0xffffffff, 0x00090008,
  477. 0x91e8, 0xffffffff, 0x00000000,
  478. 0x91ec, 0xffffffff, 0x00070000,
  479. 0x91f0, 0xffffffff, 0x00030002,
  480. 0x91f4, 0xffffffff, 0x00050004,
  481. 0x9200, 0xffffffff, 0x00010006,
  482. 0x9204, 0xffffffff, 0x00090008,
  483. 0x9294, 0xffffffff, 0x00000000,
  484. 0x929c, 0xffffffff, 0x00000001,
  485. 0x802c, 0xffffffff, 0xc0000000
  486. };
  487. static const u32 cedar_golden_registers[] =
  488. {
  489. 0x3f90, 0xffff0000, 0xff000000,
  490. 0x9148, 0xffff0000, 0xff000000,
  491. 0x3f94, 0xffff0000, 0xff000000,
  492. 0x914c, 0xffff0000, 0xff000000,
  493. 0x9b7c, 0xffffffff, 0x00000000,
  494. 0x8a14, 0xffffffff, 0x00000007,
  495. 0x8b10, 0xffffffff, 0x00000000,
  496. 0x960c, 0xffffffff, 0x54763210,
  497. 0x88c4, 0xffffffff, 0x000000c2,
  498. 0x88d4, 0xffffffff, 0x00000000,
  499. 0x8974, 0xffffffff, 0x00000000,
  500. 0xc78, 0x00000080, 0x00000080,
  501. 0x5eb4, 0xffffffff, 0x00000002,
  502. 0x5e78, 0xffffffff, 0x001000f0,
  503. 0x6104, 0x01000300, 0x00000000,
  504. 0x5bc0, 0x00300000, 0x00000000,
  505. 0x7030, 0xffffffff, 0x00000011,
  506. 0x7c30, 0xffffffff, 0x00000011,
  507. 0x10830, 0xffffffff, 0x00000011,
  508. 0x11430, 0xffffffff, 0x00000011,
  509. 0xd02c, 0xffffffff, 0x08421000,
  510. 0x240c, 0xffffffff, 0x00000380,
  511. 0x8b24, 0xffffffff, 0x00ff0fff,
  512. 0x28a4c, 0x06000000, 0x06000000,
  513. 0x10c, 0x00000001, 0x00000001,
  514. 0x8d00, 0xffffffff, 0x100e4848,
  515. 0x8d04, 0xffffffff, 0x00164745,
  516. 0x8c00, 0xffffffff, 0xe4000003,
  517. 0x8c04, 0xffffffff, 0x40600060,
  518. 0x8c08, 0xffffffff, 0x001c001c,
  519. 0x8cf0, 0xffffffff, 0x08e00410,
  520. 0x8c20, 0xffffffff, 0x00800080,
  521. 0x8c24, 0xffffffff, 0x00800080,
  522. 0x8c18, 0xffffffff, 0x20202078,
  523. 0x8c1c, 0xffffffff, 0x00001010,
  524. 0x28350, 0xffffffff, 0x00000000,
  525. 0xa008, 0xffffffff, 0x00010000,
  526. 0x5c4, 0xffffffff, 0x00000001,
  527. 0x9508, 0xffffffff, 0x00000002
  528. };
  529. static const u32 cedar_mgcg_init[] =
  530. {
  531. 0x802c, 0xffffffff, 0xc0000000,
  532. 0x5448, 0xffffffff, 0x00000100,
  533. 0x55e4, 0xffffffff, 0x00000100,
  534. 0x160c, 0xffffffff, 0x00000100,
  535. 0x5644, 0xffffffff, 0x00000100,
  536. 0xc164, 0xffffffff, 0x00000100,
  537. 0x8a18, 0xffffffff, 0x00000100,
  538. 0x897c, 0xffffffff, 0x06000100,
  539. 0x8b28, 0xffffffff, 0x00000100,
  540. 0x9144, 0xffffffff, 0x00000100,
  541. 0x9a60, 0xffffffff, 0x00000100,
  542. 0x9868, 0xffffffff, 0x00000100,
  543. 0x8d58, 0xffffffff, 0x00000100,
  544. 0x9510, 0xffffffff, 0x00000100,
  545. 0x949c, 0xffffffff, 0x00000100,
  546. 0x9654, 0xffffffff, 0x00000100,
  547. 0x9030, 0xffffffff, 0x00000100,
  548. 0x9034, 0xffffffff, 0x00000100,
  549. 0x9038, 0xffffffff, 0x00000100,
  550. 0x903c, 0xffffffff, 0x00000100,
  551. 0x9040, 0xffffffff, 0x00000100,
  552. 0xa200, 0xffffffff, 0x00000100,
  553. 0xa204, 0xffffffff, 0x00000100,
  554. 0xa208, 0xffffffff, 0x00000100,
  555. 0xa20c, 0xffffffff, 0x00000100,
  556. 0x971c, 0xffffffff, 0x00000100,
  557. 0x977c, 0xffffffff, 0x00000100,
  558. 0x3f80, 0xffffffff, 0x00000100,
  559. 0xa210, 0xffffffff, 0x00000100,
  560. 0xa214, 0xffffffff, 0x00000100,
  561. 0x4d8, 0xffffffff, 0x00000100,
  562. 0x9784, 0xffffffff, 0x00000100,
  563. 0x9698, 0xffffffff, 0x00000100,
  564. 0x4d4, 0xffffffff, 0x00000200,
  565. 0x30cc, 0xffffffff, 0x00000100,
  566. 0xd0c0, 0xffffffff, 0xff000100,
  567. 0x802c, 0xffffffff, 0x40000000,
  568. 0x915c, 0xffffffff, 0x00010000,
  569. 0x9178, 0xffffffff, 0x00050000,
  570. 0x917c, 0xffffffff, 0x00030002,
  571. 0x918c, 0xffffffff, 0x00010004,
  572. 0x9190, 0xffffffff, 0x00070006,
  573. 0x9194, 0xffffffff, 0x00050000,
  574. 0x9198, 0xffffffff, 0x00030002,
  575. 0x91a8, 0xffffffff, 0x00010004,
  576. 0x91ac, 0xffffffff, 0x00070006,
  577. 0x91e8, 0xffffffff, 0x00000000,
  578. 0x9294, 0xffffffff, 0x00000000,
  579. 0x929c, 0xffffffff, 0x00000001,
  580. 0x802c, 0xffffffff, 0xc0000000
  581. };
  582. static const u32 juniper_mgcg_init[] =
  583. {
  584. 0x802c, 0xffffffff, 0xc0000000,
  585. 0x5448, 0xffffffff, 0x00000100,
  586. 0x55e4, 0xffffffff, 0x00000100,
  587. 0x160c, 0xffffffff, 0x00000100,
  588. 0x5644, 0xffffffff, 0x00000100,
  589. 0xc164, 0xffffffff, 0x00000100,
  590. 0x8a18, 0xffffffff, 0x00000100,
  591. 0x897c, 0xffffffff, 0x06000100,
  592. 0x8b28, 0xffffffff, 0x00000100,
  593. 0x9144, 0xffffffff, 0x00000100,
  594. 0x9a60, 0xffffffff, 0x00000100,
  595. 0x9868, 0xffffffff, 0x00000100,
  596. 0x8d58, 0xffffffff, 0x00000100,
  597. 0x9510, 0xffffffff, 0x00000100,
  598. 0x949c, 0xffffffff, 0x00000100,
  599. 0x9654, 0xffffffff, 0x00000100,
  600. 0x9030, 0xffffffff, 0x00000100,
  601. 0x9034, 0xffffffff, 0x00000100,
  602. 0x9038, 0xffffffff, 0x00000100,
  603. 0x903c, 0xffffffff, 0x00000100,
  604. 0x9040, 0xffffffff, 0x00000100,
  605. 0xa200, 0xffffffff, 0x00000100,
  606. 0xa204, 0xffffffff, 0x00000100,
  607. 0xa208, 0xffffffff, 0x00000100,
  608. 0xa20c, 0xffffffff, 0x00000100,
  609. 0x971c, 0xffffffff, 0x00000100,
  610. 0xd0c0, 0xffffffff, 0xff000100,
  611. 0x802c, 0xffffffff, 0x40000000,
  612. 0x915c, 0xffffffff, 0x00010000,
  613. 0x9160, 0xffffffff, 0x00030002,
  614. 0x9178, 0xffffffff, 0x00070000,
  615. 0x917c, 0xffffffff, 0x00030002,
  616. 0x9180, 0xffffffff, 0x00050004,
  617. 0x918c, 0xffffffff, 0x00010006,
  618. 0x9190, 0xffffffff, 0x00090008,
  619. 0x9194, 0xffffffff, 0x00070000,
  620. 0x9198, 0xffffffff, 0x00030002,
  621. 0x919c, 0xffffffff, 0x00050004,
  622. 0x91a8, 0xffffffff, 0x00010006,
  623. 0x91ac, 0xffffffff, 0x00090008,
  624. 0x91b0, 0xffffffff, 0x00070000,
  625. 0x91b4, 0xffffffff, 0x00030002,
  626. 0x91b8, 0xffffffff, 0x00050004,
  627. 0x91c4, 0xffffffff, 0x00010006,
  628. 0x91c8, 0xffffffff, 0x00090008,
  629. 0x91cc, 0xffffffff, 0x00070000,
  630. 0x91d0, 0xffffffff, 0x00030002,
  631. 0x91d4, 0xffffffff, 0x00050004,
  632. 0x91e0, 0xffffffff, 0x00010006,
  633. 0x91e4, 0xffffffff, 0x00090008,
  634. 0x91e8, 0xffffffff, 0x00000000,
  635. 0x91ec, 0xffffffff, 0x00070000,
  636. 0x91f0, 0xffffffff, 0x00030002,
  637. 0x91f4, 0xffffffff, 0x00050004,
  638. 0x9200, 0xffffffff, 0x00010006,
  639. 0x9204, 0xffffffff, 0x00090008,
  640. 0x9208, 0xffffffff, 0x00070000,
  641. 0x920c, 0xffffffff, 0x00030002,
  642. 0x9210, 0xffffffff, 0x00050004,
  643. 0x921c, 0xffffffff, 0x00010006,
  644. 0x9220, 0xffffffff, 0x00090008,
  645. 0x9224, 0xffffffff, 0x00070000,
  646. 0x9228, 0xffffffff, 0x00030002,
  647. 0x922c, 0xffffffff, 0x00050004,
  648. 0x9238, 0xffffffff, 0x00010006,
  649. 0x923c, 0xffffffff, 0x00090008,
  650. 0x9240, 0xffffffff, 0x00070000,
  651. 0x9244, 0xffffffff, 0x00030002,
  652. 0x9248, 0xffffffff, 0x00050004,
  653. 0x9254, 0xffffffff, 0x00010006,
  654. 0x9258, 0xffffffff, 0x00090008,
  655. 0x925c, 0xffffffff, 0x00070000,
  656. 0x9260, 0xffffffff, 0x00030002,
  657. 0x9264, 0xffffffff, 0x00050004,
  658. 0x9270, 0xffffffff, 0x00010006,
  659. 0x9274, 0xffffffff, 0x00090008,
  660. 0x9278, 0xffffffff, 0x00070000,
  661. 0x927c, 0xffffffff, 0x00030002,
  662. 0x9280, 0xffffffff, 0x00050004,
  663. 0x928c, 0xffffffff, 0x00010006,
  664. 0x9290, 0xffffffff, 0x00090008,
  665. 0x9294, 0xffffffff, 0x00000000,
  666. 0x929c, 0xffffffff, 0x00000001,
  667. 0x802c, 0xffffffff, 0xc0000000,
  668. 0x977c, 0xffffffff, 0x00000100,
  669. 0x3f80, 0xffffffff, 0x00000100,
  670. 0xa210, 0xffffffff, 0x00000100,
  671. 0xa214, 0xffffffff, 0x00000100,
  672. 0x4d8, 0xffffffff, 0x00000100,
  673. 0x9784, 0xffffffff, 0x00000100,
  674. 0x9698, 0xffffffff, 0x00000100,
  675. 0x4d4, 0xffffffff, 0x00000200,
  676. 0x30cc, 0xffffffff, 0x00000100,
  677. 0x802c, 0xffffffff, 0xc0000000
  678. };
  679. static const u32 supersumo_golden_registers[] =
  680. {
  681. 0x5eb4, 0xffffffff, 0x00000002,
  682. 0x5c4, 0xffffffff, 0x00000001,
  683. 0x7030, 0xffffffff, 0x00000011,
  684. 0x7c30, 0xffffffff, 0x00000011,
  685. 0x6104, 0x01000300, 0x00000000,
  686. 0x5bc0, 0x00300000, 0x00000000,
  687. 0x8c04, 0xffffffff, 0x40600060,
  688. 0x8c08, 0xffffffff, 0x001c001c,
  689. 0x8c20, 0xffffffff, 0x00800080,
  690. 0x8c24, 0xffffffff, 0x00800080,
  691. 0x8c18, 0xffffffff, 0x20202078,
  692. 0x8c1c, 0xffffffff, 0x00001010,
  693. 0x918c, 0xffffffff, 0x00010006,
  694. 0x91a8, 0xffffffff, 0x00010006,
  695. 0x91c4, 0xffffffff, 0x00010006,
  696. 0x91e0, 0xffffffff, 0x00010006,
  697. 0x9200, 0xffffffff, 0x00010006,
  698. 0x9150, 0xffffffff, 0x6e944040,
  699. 0x917c, 0xffffffff, 0x00030002,
  700. 0x9180, 0xffffffff, 0x00050004,
  701. 0x9198, 0xffffffff, 0x00030002,
  702. 0x919c, 0xffffffff, 0x00050004,
  703. 0x91b4, 0xffffffff, 0x00030002,
  704. 0x91b8, 0xffffffff, 0x00050004,
  705. 0x91d0, 0xffffffff, 0x00030002,
  706. 0x91d4, 0xffffffff, 0x00050004,
  707. 0x91f0, 0xffffffff, 0x00030002,
  708. 0x91f4, 0xffffffff, 0x00050004,
  709. 0x915c, 0xffffffff, 0x00010000,
  710. 0x9160, 0xffffffff, 0x00030002,
  711. 0x3f90, 0xffff0000, 0xff000000,
  712. 0x9178, 0xffffffff, 0x00070000,
  713. 0x9194, 0xffffffff, 0x00070000,
  714. 0x91b0, 0xffffffff, 0x00070000,
  715. 0x91cc, 0xffffffff, 0x00070000,
  716. 0x91ec, 0xffffffff, 0x00070000,
  717. 0x9148, 0xffff0000, 0xff000000,
  718. 0x9190, 0xffffffff, 0x00090008,
  719. 0x91ac, 0xffffffff, 0x00090008,
  720. 0x91c8, 0xffffffff, 0x00090008,
  721. 0x91e4, 0xffffffff, 0x00090008,
  722. 0x9204, 0xffffffff, 0x00090008,
  723. 0x3f94, 0xffff0000, 0xff000000,
  724. 0x914c, 0xffff0000, 0xff000000,
  725. 0x929c, 0xffffffff, 0x00000001,
  726. 0x8a18, 0xffffffff, 0x00000100,
  727. 0x8b28, 0xffffffff, 0x00000100,
  728. 0x9144, 0xffffffff, 0x00000100,
  729. 0x5644, 0xffffffff, 0x00000100,
  730. 0x9b7c, 0xffffffff, 0x00000000,
  731. 0x8030, 0xffffffff, 0x0000100a,
  732. 0x8a14, 0xffffffff, 0x00000007,
  733. 0x8b24, 0xffffffff, 0x00ff0fff,
  734. 0x8b10, 0xffffffff, 0x00000000,
  735. 0x28a4c, 0x06000000, 0x06000000,
  736. 0x4d8, 0xffffffff, 0x00000100,
  737. 0x913c, 0xffff000f, 0x0100000a,
  738. 0x960c, 0xffffffff, 0x54763210,
  739. 0x88c4, 0xffffffff, 0x000000c2,
  740. 0x88d4, 0xffffffff, 0x00000010,
  741. 0x8974, 0xffffffff, 0x00000000,
  742. 0xc78, 0x00000080, 0x00000080,
  743. 0x5e78, 0xffffffff, 0x001000f0,
  744. 0xd02c, 0xffffffff, 0x08421000,
  745. 0xa008, 0xffffffff, 0x00010000,
  746. 0x8d00, 0xffffffff, 0x100e4848,
  747. 0x8d04, 0xffffffff, 0x00164745,
  748. 0x8c00, 0xffffffff, 0xe4000003,
  749. 0x8cf0, 0x1fffffff, 0x08e00620,
  750. 0x28350, 0xffffffff, 0x00000000,
  751. 0x9508, 0xffffffff, 0x00000002
  752. };
  753. static const u32 sumo_golden_registers[] =
  754. {
  755. 0x900c, 0x00ffffff, 0x0017071f,
  756. 0x8c18, 0xffffffff, 0x10101060,
  757. 0x8c1c, 0xffffffff, 0x00001010,
  758. 0x8c30, 0x0000000f, 0x00000005,
  759. 0x9688, 0x0000000f, 0x00000007
  760. };
  761. static const u32 wrestler_golden_registers[] =
  762. {
  763. 0x5eb4, 0xffffffff, 0x00000002,
  764. 0x5c4, 0xffffffff, 0x00000001,
  765. 0x7030, 0xffffffff, 0x00000011,
  766. 0x7c30, 0xffffffff, 0x00000011,
  767. 0x6104, 0x01000300, 0x00000000,
  768. 0x5bc0, 0x00300000, 0x00000000,
  769. 0x918c, 0xffffffff, 0x00010006,
  770. 0x91a8, 0xffffffff, 0x00010006,
  771. 0x9150, 0xffffffff, 0x6e944040,
  772. 0x917c, 0xffffffff, 0x00030002,
  773. 0x9198, 0xffffffff, 0x00030002,
  774. 0x915c, 0xffffffff, 0x00010000,
  775. 0x3f90, 0xffff0000, 0xff000000,
  776. 0x9178, 0xffffffff, 0x00070000,
  777. 0x9194, 0xffffffff, 0x00070000,
  778. 0x9148, 0xffff0000, 0xff000000,
  779. 0x9190, 0xffffffff, 0x00090008,
  780. 0x91ac, 0xffffffff, 0x00090008,
  781. 0x3f94, 0xffff0000, 0xff000000,
  782. 0x914c, 0xffff0000, 0xff000000,
  783. 0x929c, 0xffffffff, 0x00000001,
  784. 0x8a18, 0xffffffff, 0x00000100,
  785. 0x8b28, 0xffffffff, 0x00000100,
  786. 0x9144, 0xffffffff, 0x00000100,
  787. 0x9b7c, 0xffffffff, 0x00000000,
  788. 0x8030, 0xffffffff, 0x0000100a,
  789. 0x8a14, 0xffffffff, 0x00000001,
  790. 0x8b24, 0xffffffff, 0x00ff0fff,
  791. 0x8b10, 0xffffffff, 0x00000000,
  792. 0x28a4c, 0x06000000, 0x06000000,
  793. 0x4d8, 0xffffffff, 0x00000100,
  794. 0x913c, 0xffff000f, 0x0100000a,
  795. 0x960c, 0xffffffff, 0x54763210,
  796. 0x88c4, 0xffffffff, 0x000000c2,
  797. 0x88d4, 0xffffffff, 0x00000010,
  798. 0x8974, 0xffffffff, 0x00000000,
  799. 0xc78, 0x00000080, 0x00000080,
  800. 0x5e78, 0xffffffff, 0x001000f0,
  801. 0xd02c, 0xffffffff, 0x08421000,
  802. 0xa008, 0xffffffff, 0x00010000,
  803. 0x8d00, 0xffffffff, 0x100e4848,
  804. 0x8d04, 0xffffffff, 0x00164745,
  805. 0x8c00, 0xffffffff, 0xe4000003,
  806. 0x8cf0, 0x1fffffff, 0x08e00410,
  807. 0x28350, 0xffffffff, 0x00000000,
  808. 0x9508, 0xffffffff, 0x00000002,
  809. 0x900c, 0xffffffff, 0x0017071f,
  810. 0x8c18, 0xffffffff, 0x10101060,
  811. 0x8c1c, 0xffffffff, 0x00001010
  812. };
  813. static const u32 barts_golden_registers[] =
  814. {
  815. 0x5eb4, 0xffffffff, 0x00000002,
  816. 0x5e78, 0x8f311ff1, 0x001000f0,
  817. 0x3f90, 0xffff0000, 0xff000000,
  818. 0x9148, 0xffff0000, 0xff000000,
  819. 0x3f94, 0xffff0000, 0xff000000,
  820. 0x914c, 0xffff0000, 0xff000000,
  821. 0xc78, 0x00000080, 0x00000080,
  822. 0xbd4, 0x70073777, 0x00010001,
  823. 0xd02c, 0xbfffff1f, 0x08421000,
  824. 0xd0b8, 0x03773777, 0x02011003,
  825. 0x5bc0, 0x00200000, 0x50100000,
  826. 0x98f8, 0x33773777, 0x02011003,
  827. 0x98fc, 0xffffffff, 0x76543210,
  828. 0x7030, 0x31000311, 0x00000011,
  829. 0x2f48, 0x00000007, 0x02011003,
  830. 0x6b28, 0x00000010, 0x00000012,
  831. 0x7728, 0x00000010, 0x00000012,
  832. 0x10328, 0x00000010, 0x00000012,
  833. 0x10f28, 0x00000010, 0x00000012,
  834. 0x11b28, 0x00000010, 0x00000012,
  835. 0x12728, 0x00000010, 0x00000012,
  836. 0x240c, 0x000007ff, 0x00000380,
  837. 0x8a14, 0xf000001f, 0x00000007,
  838. 0x8b24, 0x3fff3fff, 0x00ff0fff,
  839. 0x8b10, 0x0000ff0f, 0x00000000,
  840. 0x28a4c, 0x07ffffff, 0x06000000,
  841. 0x10c, 0x00000001, 0x00010003,
  842. 0xa02c, 0xffffffff, 0x0000009b,
  843. 0x913c, 0x0000000f, 0x0100000a,
  844. 0x8d00, 0xffff7f7f, 0x100e4848,
  845. 0x8d04, 0x00ffffff, 0x00164745,
  846. 0x8c00, 0xfffc0003, 0xe4000003,
  847. 0x8c04, 0xf8ff00ff, 0x40600060,
  848. 0x8c08, 0x00ff00ff, 0x001c001c,
  849. 0x8cf0, 0x1fff1fff, 0x08e00620,
  850. 0x8c20, 0x0fff0fff, 0x00800080,
  851. 0x8c24, 0x0fff0fff, 0x00800080,
  852. 0x8c18, 0xffffffff, 0x20202078,
  853. 0x8c1c, 0x0000ffff, 0x00001010,
  854. 0x28350, 0x00000f01, 0x00000000,
  855. 0x9508, 0x3700001f, 0x00000002,
  856. 0x960c, 0xffffffff, 0x54763210,
  857. 0x88c4, 0x001f3ae3, 0x000000c2,
  858. 0x88d4, 0x0000001f, 0x00000010,
  859. 0x8974, 0xffffffff, 0x00000000
  860. };
  861. static const u32 turks_golden_registers[] =
  862. {
  863. 0x5eb4, 0xffffffff, 0x00000002,
  864. 0x5e78, 0x8f311ff1, 0x001000f0,
  865. 0x8c8, 0x00003000, 0x00001070,
  866. 0x8cc, 0x000fffff, 0x00040035,
  867. 0x3f90, 0xffff0000, 0xfff00000,
  868. 0x9148, 0xffff0000, 0xfff00000,
  869. 0x3f94, 0xffff0000, 0xfff00000,
  870. 0x914c, 0xffff0000, 0xfff00000,
  871. 0xc78, 0x00000080, 0x00000080,
  872. 0xbd4, 0x00073007, 0x00010002,
  873. 0xd02c, 0xbfffff1f, 0x08421000,
  874. 0xd0b8, 0x03773777, 0x02010002,
  875. 0x5bc0, 0x00200000, 0x50100000,
  876. 0x98f8, 0x33773777, 0x00010002,
  877. 0x98fc, 0xffffffff, 0x33221100,
  878. 0x7030, 0x31000311, 0x00000011,
  879. 0x2f48, 0x33773777, 0x00010002,
  880. 0x6b28, 0x00000010, 0x00000012,
  881. 0x7728, 0x00000010, 0x00000012,
  882. 0x10328, 0x00000010, 0x00000012,
  883. 0x10f28, 0x00000010, 0x00000012,
  884. 0x11b28, 0x00000010, 0x00000012,
  885. 0x12728, 0x00000010, 0x00000012,
  886. 0x240c, 0x000007ff, 0x00000380,
  887. 0x8a14, 0xf000001f, 0x00000007,
  888. 0x8b24, 0x3fff3fff, 0x00ff0fff,
  889. 0x8b10, 0x0000ff0f, 0x00000000,
  890. 0x28a4c, 0x07ffffff, 0x06000000,
  891. 0x10c, 0x00000001, 0x00010003,
  892. 0xa02c, 0xffffffff, 0x0000009b,
  893. 0x913c, 0x0000000f, 0x0100000a,
  894. 0x8d00, 0xffff7f7f, 0x100e4848,
  895. 0x8d04, 0x00ffffff, 0x00164745,
  896. 0x8c00, 0xfffc0003, 0xe4000003,
  897. 0x8c04, 0xf8ff00ff, 0x40600060,
  898. 0x8c08, 0x00ff00ff, 0x001c001c,
  899. 0x8cf0, 0x1fff1fff, 0x08e00410,
  900. 0x8c20, 0x0fff0fff, 0x00800080,
  901. 0x8c24, 0x0fff0fff, 0x00800080,
  902. 0x8c18, 0xffffffff, 0x20202078,
  903. 0x8c1c, 0x0000ffff, 0x00001010,
  904. 0x28350, 0x00000f01, 0x00000000,
  905. 0x9508, 0x3700001f, 0x00000002,
  906. 0x960c, 0xffffffff, 0x54763210,
  907. 0x88c4, 0x001f3ae3, 0x000000c2,
  908. 0x88d4, 0x0000001f, 0x00000010,
  909. 0x8974, 0xffffffff, 0x00000000
  910. };
  911. static const u32 caicos_golden_registers[] =
  912. {
  913. 0x5eb4, 0xffffffff, 0x00000002,
  914. 0x5e78, 0x8f311ff1, 0x001000f0,
  915. 0x8c8, 0x00003420, 0x00001450,
  916. 0x8cc, 0x000fffff, 0x00040035,
  917. 0x3f90, 0xffff0000, 0xfffc0000,
  918. 0x9148, 0xffff0000, 0xfffc0000,
  919. 0x3f94, 0xffff0000, 0xfffc0000,
  920. 0x914c, 0xffff0000, 0xfffc0000,
  921. 0xc78, 0x00000080, 0x00000080,
  922. 0xbd4, 0x00073007, 0x00010001,
  923. 0xd02c, 0xbfffff1f, 0x08421000,
  924. 0xd0b8, 0x03773777, 0x02010001,
  925. 0x5bc0, 0x00200000, 0x50100000,
  926. 0x98f8, 0x33773777, 0x02010001,
  927. 0x98fc, 0xffffffff, 0x33221100,
  928. 0x7030, 0x31000311, 0x00000011,
  929. 0x2f48, 0x33773777, 0x02010001,
  930. 0x6b28, 0x00000010, 0x00000012,
  931. 0x7728, 0x00000010, 0x00000012,
  932. 0x10328, 0x00000010, 0x00000012,
  933. 0x10f28, 0x00000010, 0x00000012,
  934. 0x11b28, 0x00000010, 0x00000012,
  935. 0x12728, 0x00000010, 0x00000012,
  936. 0x240c, 0x000007ff, 0x00000380,
  937. 0x8a14, 0xf000001f, 0x00000001,
  938. 0x8b24, 0x3fff3fff, 0x00ff0fff,
  939. 0x8b10, 0x0000ff0f, 0x00000000,
  940. 0x28a4c, 0x07ffffff, 0x06000000,
  941. 0x10c, 0x00000001, 0x00010003,
  942. 0xa02c, 0xffffffff, 0x0000009b,
  943. 0x913c, 0x0000000f, 0x0100000a,
  944. 0x8d00, 0xffff7f7f, 0x100e4848,
  945. 0x8d04, 0x00ffffff, 0x00164745,
  946. 0x8c00, 0xfffc0003, 0xe4000003,
  947. 0x8c04, 0xf8ff00ff, 0x40600060,
  948. 0x8c08, 0x00ff00ff, 0x001c001c,
  949. 0x8cf0, 0x1fff1fff, 0x08e00410,
  950. 0x8c20, 0x0fff0fff, 0x00800080,
  951. 0x8c24, 0x0fff0fff, 0x00800080,
  952. 0x8c18, 0xffffffff, 0x20202078,
  953. 0x8c1c, 0x0000ffff, 0x00001010,
  954. 0x28350, 0x00000f01, 0x00000000,
  955. 0x9508, 0x3700001f, 0x00000002,
  956. 0x960c, 0xffffffff, 0x54763210,
  957. 0x88c4, 0x001f3ae3, 0x000000c2,
  958. 0x88d4, 0x0000001f, 0x00000010,
  959. 0x8974, 0xffffffff, 0x00000000
  960. };
  961. static void evergreen_init_golden_registers(struct radeon_device *rdev)
  962. {
  963. switch (rdev->family) {
  964. case CHIP_CYPRESS:
  965. case CHIP_HEMLOCK:
  966. radeon_program_register_sequence(rdev,
  967. evergreen_golden_registers,
  968. (const u32)ARRAY_SIZE(evergreen_golden_registers));
  969. radeon_program_register_sequence(rdev,
  970. evergreen_golden_registers2,
  971. (const u32)ARRAY_SIZE(evergreen_golden_registers2));
  972. radeon_program_register_sequence(rdev,
  973. cypress_mgcg_init,
  974. (const u32)ARRAY_SIZE(cypress_mgcg_init));
  975. break;
  976. case CHIP_JUNIPER:
  977. radeon_program_register_sequence(rdev,
  978. evergreen_golden_registers,
  979. (const u32)ARRAY_SIZE(evergreen_golden_registers));
  980. radeon_program_register_sequence(rdev,
  981. evergreen_golden_registers2,
  982. (const u32)ARRAY_SIZE(evergreen_golden_registers2));
  983. radeon_program_register_sequence(rdev,
  984. juniper_mgcg_init,
  985. (const u32)ARRAY_SIZE(juniper_mgcg_init));
  986. break;
  987. case CHIP_REDWOOD:
  988. radeon_program_register_sequence(rdev,
  989. evergreen_golden_registers,
  990. (const u32)ARRAY_SIZE(evergreen_golden_registers));
  991. radeon_program_register_sequence(rdev,
  992. evergreen_golden_registers2,
  993. (const u32)ARRAY_SIZE(evergreen_golden_registers2));
  994. radeon_program_register_sequence(rdev,
  995. redwood_mgcg_init,
  996. (const u32)ARRAY_SIZE(redwood_mgcg_init));
  997. break;
  998. case CHIP_CEDAR:
  999. radeon_program_register_sequence(rdev,
  1000. cedar_golden_registers,
  1001. (const u32)ARRAY_SIZE(cedar_golden_registers));
  1002. radeon_program_register_sequence(rdev,
  1003. evergreen_golden_registers2,
  1004. (const u32)ARRAY_SIZE(evergreen_golden_registers2));
  1005. radeon_program_register_sequence(rdev,
  1006. cedar_mgcg_init,
  1007. (const u32)ARRAY_SIZE(cedar_mgcg_init));
  1008. break;
  1009. case CHIP_PALM:
  1010. radeon_program_register_sequence(rdev,
  1011. wrestler_golden_registers,
  1012. (const u32)ARRAY_SIZE(wrestler_golden_registers));
  1013. break;
  1014. case CHIP_SUMO:
  1015. radeon_program_register_sequence(rdev,
  1016. supersumo_golden_registers,
  1017. (const u32)ARRAY_SIZE(supersumo_golden_registers));
  1018. break;
  1019. case CHIP_SUMO2:
  1020. radeon_program_register_sequence(rdev,
  1021. supersumo_golden_registers,
  1022. (const u32)ARRAY_SIZE(supersumo_golden_registers));
  1023. radeon_program_register_sequence(rdev,
  1024. sumo_golden_registers,
  1025. (const u32)ARRAY_SIZE(sumo_golden_registers));
  1026. break;
  1027. case CHIP_BARTS:
  1028. radeon_program_register_sequence(rdev,
  1029. barts_golden_registers,
  1030. (const u32)ARRAY_SIZE(barts_golden_registers));
  1031. break;
  1032. case CHIP_TURKS:
  1033. radeon_program_register_sequence(rdev,
  1034. turks_golden_registers,
  1035. (const u32)ARRAY_SIZE(turks_golden_registers));
  1036. break;
  1037. case CHIP_CAICOS:
  1038. radeon_program_register_sequence(rdev,
  1039. caicos_golden_registers,
  1040. (const u32)ARRAY_SIZE(caicos_golden_registers));
  1041. break;
  1042. default:
  1043. break;
  1044. }
  1045. }
  1046. /**
  1047. * evergreen_get_allowed_info_register - fetch the register for the info ioctl
  1048. *
  1049. * @rdev: radeon_device pointer
  1050. * @reg: register offset in bytes
  1051. * @val: register value
  1052. *
  1053. * Returns 0 for success or -EINVAL for an invalid register
  1054. *
  1055. */
  1056. int evergreen_get_allowed_info_register(struct radeon_device *rdev,
  1057. u32 reg, u32 *val)
  1058. {
  1059. switch (reg) {
  1060. case GRBM_STATUS:
  1061. case GRBM_STATUS_SE0:
  1062. case GRBM_STATUS_SE1:
  1063. case SRBM_STATUS:
  1064. case SRBM_STATUS2:
  1065. case DMA_STATUS_REG:
  1066. case UVD_STATUS:
  1067. *val = RREG32(reg);
  1068. return 0;
  1069. default:
  1070. return -EINVAL;
  1071. }
  1072. }
  1073. void evergreen_tiling_fields(unsigned tiling_flags, unsigned *bankw,
  1074. unsigned *bankh, unsigned *mtaspect,
  1075. unsigned *tile_split)
  1076. {
  1077. *bankw = (tiling_flags >> RADEON_TILING_EG_BANKW_SHIFT) & RADEON_TILING_EG_BANKW_MASK;
  1078. *bankh = (tiling_flags >> RADEON_TILING_EG_BANKH_SHIFT) & RADEON_TILING_EG_BANKH_MASK;
  1079. *mtaspect = (tiling_flags >> RADEON_TILING_EG_MACRO_TILE_ASPECT_SHIFT) & RADEON_TILING_EG_MACRO_TILE_ASPECT_MASK;
  1080. *tile_split = (tiling_flags >> RADEON_TILING_EG_TILE_SPLIT_SHIFT) & RADEON_TILING_EG_TILE_SPLIT_MASK;
  1081. switch (*bankw) {
  1082. default:
  1083. case 1: *bankw = EVERGREEN_ADDR_SURF_BANK_WIDTH_1; break;
  1084. case 2: *bankw = EVERGREEN_ADDR_SURF_BANK_WIDTH_2; break;
  1085. case 4: *bankw = EVERGREEN_ADDR_SURF_BANK_WIDTH_4; break;
  1086. case 8: *bankw = EVERGREEN_ADDR_SURF_BANK_WIDTH_8; break;
  1087. }
  1088. switch (*bankh) {
  1089. default:
  1090. case 1: *bankh = EVERGREEN_ADDR_SURF_BANK_HEIGHT_1; break;
  1091. case 2: *bankh = EVERGREEN_ADDR_SURF_BANK_HEIGHT_2; break;
  1092. case 4: *bankh = EVERGREEN_ADDR_SURF_BANK_HEIGHT_4; break;
  1093. case 8: *bankh = EVERGREEN_ADDR_SURF_BANK_HEIGHT_8; break;
  1094. }
  1095. switch (*mtaspect) {
  1096. default:
  1097. case 1: *mtaspect = EVERGREEN_ADDR_SURF_MACRO_TILE_ASPECT_1; break;
  1098. case 2: *mtaspect = EVERGREEN_ADDR_SURF_MACRO_TILE_ASPECT_2; break;
  1099. case 4: *mtaspect = EVERGREEN_ADDR_SURF_MACRO_TILE_ASPECT_4; break;
  1100. case 8: *mtaspect = EVERGREEN_ADDR_SURF_MACRO_TILE_ASPECT_8; break;
  1101. }
  1102. }
  1103. static int sumo_set_uvd_clock(struct radeon_device *rdev, u32 clock,
  1104. u32 cntl_reg, u32 status_reg)
  1105. {
  1106. int r, i;
  1107. struct atom_clock_dividers dividers;
  1108. r = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
  1109. clock, false, &dividers);
  1110. if (r)
  1111. return r;
  1112. WREG32_P(cntl_reg, dividers.post_div, ~(DCLK_DIR_CNTL_EN|DCLK_DIVIDER_MASK));
  1113. for (i = 0; i < 100; i++) {
  1114. if (RREG32(status_reg) & DCLK_STATUS)
  1115. break;
  1116. mdelay(10);
  1117. }
  1118. if (i == 100)
  1119. return -ETIMEDOUT;
  1120. return 0;
  1121. }
  1122. int sumo_set_uvd_clocks(struct radeon_device *rdev, u32 vclk, u32 dclk)
  1123. {
  1124. int r = 0;
  1125. u32 cg_scratch = RREG32(CG_SCRATCH1);
  1126. r = sumo_set_uvd_clock(rdev, vclk, CG_VCLK_CNTL, CG_VCLK_STATUS);
  1127. if (r)
  1128. goto done;
  1129. cg_scratch &= 0xffff0000;
  1130. cg_scratch |= vclk / 100; /* Mhz */
  1131. r = sumo_set_uvd_clock(rdev, dclk, CG_DCLK_CNTL, CG_DCLK_STATUS);
  1132. if (r)
  1133. goto done;
  1134. cg_scratch &= 0x0000ffff;
  1135. cg_scratch |= (dclk / 100) << 16; /* Mhz */
  1136. done:
  1137. WREG32(CG_SCRATCH1, cg_scratch);
  1138. return r;
  1139. }
  1140. int evergreen_set_uvd_clocks(struct radeon_device *rdev, u32 vclk, u32 dclk)
  1141. {
  1142. /* start off with something large */
  1143. unsigned fb_div = 0, vclk_div = 0, dclk_div = 0;
  1144. int r;
  1145. /* bypass vclk and dclk with bclk */
  1146. WREG32_P(CG_UPLL_FUNC_CNTL_2,
  1147. VCLK_SRC_SEL(1) | DCLK_SRC_SEL(1),
  1148. ~(VCLK_SRC_SEL_MASK | DCLK_SRC_SEL_MASK));
  1149. /* put PLL in bypass mode */
  1150. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_BYPASS_EN_MASK, ~UPLL_BYPASS_EN_MASK);
  1151. if (!vclk || !dclk) {
  1152. /* keep the Bypass mode, put PLL to sleep */
  1153. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_SLEEP_MASK, ~UPLL_SLEEP_MASK);
  1154. return 0;
  1155. }
  1156. r = radeon_uvd_calc_upll_dividers(rdev, vclk, dclk, 125000, 250000,
  1157. 16384, 0x03FFFFFF, 0, 128, 5,
  1158. &fb_div, &vclk_div, &dclk_div);
  1159. if (r)
  1160. return r;
  1161. /* set VCO_MODE to 1 */
  1162. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_VCO_MODE_MASK, ~UPLL_VCO_MODE_MASK);
  1163. /* toggle UPLL_SLEEP to 1 then back to 0 */
  1164. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_SLEEP_MASK, ~UPLL_SLEEP_MASK);
  1165. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_SLEEP_MASK);
  1166. /* deassert UPLL_RESET */
  1167. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_RESET_MASK);
  1168. mdelay(1);
  1169. r = radeon_uvd_send_upll_ctlreq(rdev, CG_UPLL_FUNC_CNTL);
  1170. if (r)
  1171. return r;
  1172. /* assert UPLL_RESET again */
  1173. WREG32_P(CG_UPLL_FUNC_CNTL, UPLL_RESET_MASK, ~UPLL_RESET_MASK);
  1174. /* disable spread spectrum. */
  1175. WREG32_P(CG_UPLL_SPREAD_SPECTRUM, 0, ~SSEN_MASK);
  1176. /* set feedback divider */
  1177. WREG32_P(CG_UPLL_FUNC_CNTL_3, UPLL_FB_DIV(fb_div), ~UPLL_FB_DIV_MASK);
  1178. /* set ref divider to 0 */
  1179. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_REF_DIV_MASK);
  1180. if (fb_div < 307200)
  1181. WREG32_P(CG_UPLL_FUNC_CNTL_4, 0, ~UPLL_SPARE_ISPARE9);
  1182. else
  1183. WREG32_P(CG_UPLL_FUNC_CNTL_4, UPLL_SPARE_ISPARE9, ~UPLL_SPARE_ISPARE9);
  1184. /* set PDIV_A and PDIV_B */
  1185. WREG32_P(CG_UPLL_FUNC_CNTL_2,
  1186. UPLL_PDIV_A(vclk_div) | UPLL_PDIV_B(dclk_div),
  1187. ~(UPLL_PDIV_A_MASK | UPLL_PDIV_B_MASK));
  1188. /* give the PLL some time to settle */
  1189. mdelay(15);
  1190. /* deassert PLL_RESET */
  1191. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_RESET_MASK);
  1192. mdelay(15);
  1193. /* switch from bypass mode to normal mode */
  1194. WREG32_P(CG_UPLL_FUNC_CNTL, 0, ~UPLL_BYPASS_EN_MASK);
  1195. r = radeon_uvd_send_upll_ctlreq(rdev, CG_UPLL_FUNC_CNTL);
  1196. if (r)
  1197. return r;
  1198. /* switch VCLK and DCLK selection */
  1199. WREG32_P(CG_UPLL_FUNC_CNTL_2,
  1200. VCLK_SRC_SEL(2) | DCLK_SRC_SEL(2),
  1201. ~(VCLK_SRC_SEL_MASK | DCLK_SRC_SEL_MASK));
  1202. mdelay(100);
  1203. return 0;
  1204. }
  1205. void evergreen_fix_pci_max_read_req_size(struct radeon_device *rdev)
  1206. {
  1207. int readrq;
  1208. u16 v;
  1209. readrq = pcie_get_readrq(rdev->pdev);
  1210. v = ffs(readrq) - 8;
  1211. /* if bios or OS sets MAX_READ_REQUEST_SIZE to an invalid value, fix it
  1212. * to avoid hangs or perfomance issues
  1213. */
  1214. if ((v == 0) || (v == 6) || (v == 7))
  1215. pcie_set_readrq(rdev->pdev, 512);
  1216. }
  1217. void dce4_program_fmt(struct drm_encoder *encoder)
  1218. {
  1219. struct drm_device *dev = encoder->dev;
  1220. struct radeon_device *rdev = dev->dev_private;
  1221. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  1222. struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
  1223. struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
  1224. int bpc = 0;
  1225. u32 tmp = 0;
  1226. enum radeon_connector_dither dither = RADEON_FMT_DITHER_DISABLE;
  1227. if (connector) {
  1228. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  1229. bpc = radeon_get_monitor_bpc(connector);
  1230. dither = radeon_connector->dither;
  1231. }
  1232. /* LVDS/eDP FMT is set up by atom */
  1233. if (radeon_encoder->devices & ATOM_DEVICE_LCD_SUPPORT)
  1234. return;
  1235. /* not needed for analog */
  1236. if ((radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1) ||
  1237. (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2))
  1238. return;
  1239. if (bpc == 0)
  1240. return;
  1241. switch (bpc) {
  1242. case 6:
  1243. if (dither == RADEON_FMT_DITHER_ENABLE)
  1244. /* XXX sort out optimal dither settings */
  1245. tmp |= (FMT_FRAME_RANDOM_ENABLE | FMT_HIGHPASS_RANDOM_ENABLE |
  1246. FMT_SPATIAL_DITHER_EN);
  1247. else
  1248. tmp |= FMT_TRUNCATE_EN;
  1249. break;
  1250. case 8:
  1251. if (dither == RADEON_FMT_DITHER_ENABLE)
  1252. /* XXX sort out optimal dither settings */
  1253. tmp |= (FMT_FRAME_RANDOM_ENABLE | FMT_HIGHPASS_RANDOM_ENABLE |
  1254. FMT_RGB_RANDOM_ENABLE |
  1255. FMT_SPATIAL_DITHER_EN | FMT_SPATIAL_DITHER_DEPTH);
  1256. else
  1257. tmp |= (FMT_TRUNCATE_EN | FMT_TRUNCATE_DEPTH);
  1258. break;
  1259. case 10:
  1260. default:
  1261. /* not needed */
  1262. break;
  1263. }
  1264. WREG32(FMT_BIT_DEPTH_CONTROL + radeon_crtc->crtc_offset, tmp);
  1265. }
  1266. static bool dce4_is_in_vblank(struct radeon_device *rdev, int crtc)
  1267. {
  1268. if (RREG32(EVERGREEN_CRTC_STATUS + crtc_offsets[crtc]) & EVERGREEN_CRTC_V_BLANK)
  1269. return true;
  1270. else
  1271. return false;
  1272. }
  1273. static bool dce4_is_counter_moving(struct radeon_device *rdev, int crtc)
  1274. {
  1275. u32 pos1, pos2;
  1276. pos1 = RREG32(EVERGREEN_CRTC_STATUS_POSITION + crtc_offsets[crtc]);
  1277. pos2 = RREG32(EVERGREEN_CRTC_STATUS_POSITION + crtc_offsets[crtc]);
  1278. if (pos1 != pos2)
  1279. return true;
  1280. else
  1281. return false;
  1282. }
  1283. /**
  1284. * dce4_wait_for_vblank - vblank wait asic callback.
  1285. *
  1286. * @rdev: radeon_device pointer
  1287. * @crtc: crtc to wait for vblank on
  1288. *
  1289. * Wait for vblank on the requested crtc (evergreen+).
  1290. */
  1291. void dce4_wait_for_vblank(struct radeon_device *rdev, int crtc)
  1292. {
  1293. unsigned i = 0;
  1294. if (crtc >= rdev->num_crtc)
  1295. return;
  1296. if (!(RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[crtc]) & EVERGREEN_CRTC_MASTER_EN))
  1297. return;
  1298. /* depending on when we hit vblank, we may be close to active; if so,
  1299. * wait for another frame.
  1300. */
  1301. while (dce4_is_in_vblank(rdev, crtc)) {
  1302. if (i++ % 100 == 0) {
  1303. if (!dce4_is_counter_moving(rdev, crtc))
  1304. break;
  1305. }
  1306. }
  1307. while (!dce4_is_in_vblank(rdev, crtc)) {
  1308. if (i++ % 100 == 0) {
  1309. if (!dce4_is_counter_moving(rdev, crtc))
  1310. break;
  1311. }
  1312. }
  1313. }
  1314. /**
  1315. * evergreen_page_flip - pageflip callback.
  1316. *
  1317. * @rdev: radeon_device pointer
  1318. * @crtc_id: crtc to cleanup pageflip on
  1319. * @crtc_base: new address of the crtc (GPU MC address)
  1320. *
  1321. * Triggers the actual pageflip by updating the primary
  1322. * surface base address (evergreen+).
  1323. */
  1324. void evergreen_page_flip(struct radeon_device *rdev, int crtc_id, u64 crtc_base,
  1325. bool async)
  1326. {
  1327. struct radeon_crtc *radeon_crtc = rdev->mode_info.crtcs[crtc_id];
  1328. /* update the scanout addresses */
  1329. WREG32(EVERGREEN_GRPH_FLIP_CONTROL + radeon_crtc->crtc_offset,
  1330. async ? EVERGREEN_GRPH_SURFACE_UPDATE_H_RETRACE_EN : 0);
  1331. WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS_HIGH + radeon_crtc->crtc_offset,
  1332. upper_32_bits(crtc_base));
  1333. WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset,
  1334. (u32)crtc_base);
  1335. /* post the write */
  1336. RREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset);
  1337. }
  1338. /**
  1339. * evergreen_page_flip_pending - check if page flip is still pending
  1340. *
  1341. * @rdev: radeon_device pointer
  1342. * @crtc_id: crtc to check
  1343. *
  1344. * Returns the current update pending status.
  1345. */
  1346. bool evergreen_page_flip_pending(struct radeon_device *rdev, int crtc_id)
  1347. {
  1348. struct radeon_crtc *radeon_crtc = rdev->mode_info.crtcs[crtc_id];
  1349. /* Return current update_pending status: */
  1350. return !!(RREG32(EVERGREEN_GRPH_UPDATE + radeon_crtc->crtc_offset) &
  1351. EVERGREEN_GRPH_SURFACE_UPDATE_PENDING);
  1352. }
  1353. /* get temperature in millidegrees */
  1354. int evergreen_get_temp(struct radeon_device *rdev)
  1355. {
  1356. u32 temp, toffset;
  1357. int actual_temp = 0;
  1358. if (rdev->family == CHIP_JUNIPER) {
  1359. toffset = (RREG32(CG_THERMAL_CTRL) & TOFFSET_MASK) >>
  1360. TOFFSET_SHIFT;
  1361. temp = (RREG32(CG_TS0_STATUS) & TS0_ADC_DOUT_MASK) >>
  1362. TS0_ADC_DOUT_SHIFT;
  1363. if (toffset & 0x100)
  1364. actual_temp = temp / 2 - (0x200 - toffset);
  1365. else
  1366. actual_temp = temp / 2 + toffset;
  1367. actual_temp = actual_temp * 1000;
  1368. } else {
  1369. temp = (RREG32(CG_MULT_THERMAL_STATUS) & ASIC_T_MASK) >>
  1370. ASIC_T_SHIFT;
  1371. if (temp & 0x400)
  1372. actual_temp = -256;
  1373. else if (temp & 0x200)
  1374. actual_temp = 255;
  1375. else if (temp & 0x100) {
  1376. actual_temp = temp & 0x1ff;
  1377. actual_temp |= ~0x1ff;
  1378. } else
  1379. actual_temp = temp & 0xff;
  1380. actual_temp = (actual_temp * 1000) / 2;
  1381. }
  1382. return actual_temp;
  1383. }
  1384. int sumo_get_temp(struct radeon_device *rdev)
  1385. {
  1386. u32 temp = RREG32(CG_THERMAL_STATUS) & 0xff;
  1387. int actual_temp = temp - 49;
  1388. return actual_temp * 1000;
  1389. }
  1390. /**
  1391. * sumo_pm_init_profile - Initialize power profiles callback.
  1392. *
  1393. * @rdev: radeon_device pointer
  1394. *
  1395. * Initialize the power states used in profile mode
  1396. * (sumo, trinity, SI).
  1397. * Used for profile mode only.
  1398. */
  1399. void sumo_pm_init_profile(struct radeon_device *rdev)
  1400. {
  1401. int idx;
  1402. /* default */
  1403. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
  1404. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
  1405. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
  1406. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
  1407. /* low,mid sh/mh */
  1408. if (rdev->flags & RADEON_IS_MOBILITY)
  1409. idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 0);
  1410. else
  1411. idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
  1412. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = idx;
  1413. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = idx;
  1414. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
  1415. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
  1416. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = idx;
  1417. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = idx;
  1418. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
  1419. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
  1420. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = idx;
  1421. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = idx;
  1422. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
  1423. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
  1424. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = idx;
  1425. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = idx;
  1426. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
  1427. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
  1428. /* high sh/mh */
  1429. idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
  1430. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = idx;
  1431. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = idx;
  1432. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
  1433. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx =
  1434. rdev->pm.power_state[idx].num_clock_modes - 1;
  1435. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = idx;
  1436. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = idx;
  1437. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
  1438. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx =
  1439. rdev->pm.power_state[idx].num_clock_modes - 1;
  1440. }
  1441. /**
  1442. * btc_pm_init_profile - Initialize power profiles callback.
  1443. *
  1444. * @rdev: radeon_device pointer
  1445. *
  1446. * Initialize the power states used in profile mode
  1447. * (BTC, cayman).
  1448. * Used for profile mode only.
  1449. */
  1450. void btc_pm_init_profile(struct radeon_device *rdev)
  1451. {
  1452. int idx;
  1453. /* default */
  1454. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
  1455. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
  1456. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
  1457. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 2;
  1458. /* starting with BTC, there is one state that is used for both
  1459. * MH and SH. Difference is that we always use the high clock index for
  1460. * mclk.
  1461. */
  1462. if (rdev->flags & RADEON_IS_MOBILITY)
  1463. idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_BATTERY, 0);
  1464. else
  1465. idx = radeon_pm_get_type_index(rdev, POWER_STATE_TYPE_PERFORMANCE, 0);
  1466. /* low sh */
  1467. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = idx;
  1468. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = idx;
  1469. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
  1470. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
  1471. /* mid sh */
  1472. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = idx;
  1473. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = idx;
  1474. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
  1475. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 1;
  1476. /* high sh */
  1477. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = idx;
  1478. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = idx;
  1479. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
  1480. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 2;
  1481. /* low mh */
  1482. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = idx;
  1483. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = idx;
  1484. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
  1485. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
  1486. /* mid mh */
  1487. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = idx;
  1488. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = idx;
  1489. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
  1490. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 1;
  1491. /* high mh */
  1492. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = idx;
  1493. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = idx;
  1494. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
  1495. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 2;
  1496. }
  1497. /**
  1498. * evergreen_pm_misc - set additional pm hw parameters callback.
  1499. *
  1500. * @rdev: radeon_device pointer
  1501. *
  1502. * Set non-clock parameters associated with a power state
  1503. * (voltage, etc.) (evergreen+).
  1504. */
  1505. void evergreen_pm_misc(struct radeon_device *rdev)
  1506. {
  1507. int req_ps_idx = rdev->pm.requested_power_state_index;
  1508. int req_cm_idx = rdev->pm.requested_clock_mode_index;
  1509. struct radeon_power_state *ps = &rdev->pm.power_state[req_ps_idx];
  1510. struct radeon_voltage *voltage = &ps->clock_info[req_cm_idx].voltage;
  1511. if (voltage->type == VOLTAGE_SW) {
  1512. /* 0xff0x are flags rather then an actual voltage */
  1513. if ((voltage->voltage & 0xff00) == 0xff00)
  1514. return;
  1515. if (voltage->voltage && (voltage->voltage != rdev->pm.current_vddc)) {
  1516. radeon_atom_set_voltage(rdev, voltage->voltage, SET_VOLTAGE_TYPE_ASIC_VDDC);
  1517. rdev->pm.current_vddc = voltage->voltage;
  1518. DRM_DEBUG("Setting: vddc: %d\n", voltage->voltage);
  1519. }
  1520. /* starting with BTC, there is one state that is used for both
  1521. * MH and SH. Difference is that we always use the high clock index for
  1522. * mclk and vddci.
  1523. */
  1524. if ((rdev->pm.pm_method == PM_METHOD_PROFILE) &&
  1525. (rdev->family >= CHIP_BARTS) &&
  1526. rdev->pm.active_crtc_count &&
  1527. ((rdev->pm.profile_index == PM_PROFILE_MID_MH_IDX) ||
  1528. (rdev->pm.profile_index == PM_PROFILE_LOW_MH_IDX)))
  1529. voltage = &rdev->pm.power_state[req_ps_idx].
  1530. clock_info[rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx].voltage;
  1531. /* 0xff0x are flags rather then an actual voltage */
  1532. if ((voltage->vddci & 0xff00) == 0xff00)
  1533. return;
  1534. if (voltage->vddci && (voltage->vddci != rdev->pm.current_vddci)) {
  1535. radeon_atom_set_voltage(rdev, voltage->vddci, SET_VOLTAGE_TYPE_ASIC_VDDCI);
  1536. rdev->pm.current_vddci = voltage->vddci;
  1537. DRM_DEBUG("Setting: vddci: %d\n", voltage->vddci);
  1538. }
  1539. }
  1540. }
  1541. /**
  1542. * evergreen_pm_prepare - pre-power state change callback.
  1543. *
  1544. * @rdev: radeon_device pointer
  1545. *
  1546. * Prepare for a power state change (evergreen+).
  1547. */
  1548. void evergreen_pm_prepare(struct radeon_device *rdev)
  1549. {
  1550. struct drm_device *ddev = rdev->ddev;
  1551. struct drm_crtc *crtc;
  1552. struct radeon_crtc *radeon_crtc;
  1553. u32 tmp;
  1554. /* disable any active CRTCs */
  1555. list_for_each_entry(crtc, &ddev->mode_config.crtc_list, head) {
  1556. radeon_crtc = to_radeon_crtc(crtc);
  1557. if (radeon_crtc->enabled) {
  1558. tmp = RREG32(EVERGREEN_CRTC_CONTROL + radeon_crtc->crtc_offset);
  1559. tmp |= EVERGREEN_CRTC_DISP_READ_REQUEST_DISABLE;
  1560. WREG32(EVERGREEN_CRTC_CONTROL + radeon_crtc->crtc_offset, tmp);
  1561. }
  1562. }
  1563. }
  1564. /**
  1565. * evergreen_pm_finish - post-power state change callback.
  1566. *
  1567. * @rdev: radeon_device pointer
  1568. *
  1569. * Clean up after a power state change (evergreen+).
  1570. */
  1571. void evergreen_pm_finish(struct radeon_device *rdev)
  1572. {
  1573. struct drm_device *ddev = rdev->ddev;
  1574. struct drm_crtc *crtc;
  1575. struct radeon_crtc *radeon_crtc;
  1576. u32 tmp;
  1577. /* enable any active CRTCs */
  1578. list_for_each_entry(crtc, &ddev->mode_config.crtc_list, head) {
  1579. radeon_crtc = to_radeon_crtc(crtc);
  1580. if (radeon_crtc->enabled) {
  1581. tmp = RREG32(EVERGREEN_CRTC_CONTROL + radeon_crtc->crtc_offset);
  1582. tmp &= ~EVERGREEN_CRTC_DISP_READ_REQUEST_DISABLE;
  1583. WREG32(EVERGREEN_CRTC_CONTROL + radeon_crtc->crtc_offset, tmp);
  1584. }
  1585. }
  1586. }
  1587. /**
  1588. * evergreen_hpd_sense - hpd sense callback.
  1589. *
  1590. * @rdev: radeon_device pointer
  1591. * @hpd: hpd (hotplug detect) pin
  1592. *
  1593. * Checks if a digital monitor is connected (evergreen+).
  1594. * Returns true if connected, false if not connected.
  1595. */
  1596. bool evergreen_hpd_sense(struct radeon_device *rdev, enum radeon_hpd_id hpd)
  1597. {
  1598. bool connected = false;
  1599. switch (hpd) {
  1600. case RADEON_HPD_1:
  1601. if (RREG32(DC_HPD1_INT_STATUS) & DC_HPDx_SENSE)
  1602. connected = true;
  1603. break;
  1604. case RADEON_HPD_2:
  1605. if (RREG32(DC_HPD2_INT_STATUS) & DC_HPDx_SENSE)
  1606. connected = true;
  1607. break;
  1608. case RADEON_HPD_3:
  1609. if (RREG32(DC_HPD3_INT_STATUS) & DC_HPDx_SENSE)
  1610. connected = true;
  1611. break;
  1612. case RADEON_HPD_4:
  1613. if (RREG32(DC_HPD4_INT_STATUS) & DC_HPDx_SENSE)
  1614. connected = true;
  1615. break;
  1616. case RADEON_HPD_5:
  1617. if (RREG32(DC_HPD5_INT_STATUS) & DC_HPDx_SENSE)
  1618. connected = true;
  1619. break;
  1620. case RADEON_HPD_6:
  1621. if (RREG32(DC_HPD6_INT_STATUS) & DC_HPDx_SENSE)
  1622. connected = true;
  1623. break;
  1624. default:
  1625. break;
  1626. }
  1627. return connected;
  1628. }
  1629. /**
  1630. * evergreen_hpd_set_polarity - hpd set polarity callback.
  1631. *
  1632. * @rdev: radeon_device pointer
  1633. * @hpd: hpd (hotplug detect) pin
  1634. *
  1635. * Set the polarity of the hpd pin (evergreen+).
  1636. */
  1637. void evergreen_hpd_set_polarity(struct radeon_device *rdev,
  1638. enum radeon_hpd_id hpd)
  1639. {
  1640. u32 tmp;
  1641. bool connected = evergreen_hpd_sense(rdev, hpd);
  1642. switch (hpd) {
  1643. case RADEON_HPD_1:
  1644. tmp = RREG32(DC_HPD1_INT_CONTROL);
  1645. if (connected)
  1646. tmp &= ~DC_HPDx_INT_POLARITY;
  1647. else
  1648. tmp |= DC_HPDx_INT_POLARITY;
  1649. WREG32(DC_HPD1_INT_CONTROL, tmp);
  1650. break;
  1651. case RADEON_HPD_2:
  1652. tmp = RREG32(DC_HPD2_INT_CONTROL);
  1653. if (connected)
  1654. tmp &= ~DC_HPDx_INT_POLARITY;
  1655. else
  1656. tmp |= DC_HPDx_INT_POLARITY;
  1657. WREG32(DC_HPD2_INT_CONTROL, tmp);
  1658. break;
  1659. case RADEON_HPD_3:
  1660. tmp = RREG32(DC_HPD3_INT_CONTROL);
  1661. if (connected)
  1662. tmp &= ~DC_HPDx_INT_POLARITY;
  1663. else
  1664. tmp |= DC_HPDx_INT_POLARITY;
  1665. WREG32(DC_HPD3_INT_CONTROL, tmp);
  1666. break;
  1667. case RADEON_HPD_4:
  1668. tmp = RREG32(DC_HPD4_INT_CONTROL);
  1669. if (connected)
  1670. tmp &= ~DC_HPDx_INT_POLARITY;
  1671. else
  1672. tmp |= DC_HPDx_INT_POLARITY;
  1673. WREG32(DC_HPD4_INT_CONTROL, tmp);
  1674. break;
  1675. case RADEON_HPD_5:
  1676. tmp = RREG32(DC_HPD5_INT_CONTROL);
  1677. if (connected)
  1678. tmp &= ~DC_HPDx_INT_POLARITY;
  1679. else
  1680. tmp |= DC_HPDx_INT_POLARITY;
  1681. WREG32(DC_HPD5_INT_CONTROL, tmp);
  1682. break;
  1683. case RADEON_HPD_6:
  1684. tmp = RREG32(DC_HPD6_INT_CONTROL);
  1685. if (connected)
  1686. tmp &= ~DC_HPDx_INT_POLARITY;
  1687. else
  1688. tmp |= DC_HPDx_INT_POLARITY;
  1689. WREG32(DC_HPD6_INT_CONTROL, tmp);
  1690. break;
  1691. default:
  1692. break;
  1693. }
  1694. }
  1695. /**
  1696. * evergreen_hpd_init - hpd setup callback.
  1697. *
  1698. * @rdev: radeon_device pointer
  1699. *
  1700. * Setup the hpd pins used by the card (evergreen+).
  1701. * Enable the pin, set the polarity, and enable the hpd interrupts.
  1702. */
  1703. void evergreen_hpd_init(struct radeon_device *rdev)
  1704. {
  1705. struct drm_device *dev = rdev->ddev;
  1706. struct drm_connector *connector;
  1707. unsigned enabled = 0;
  1708. u32 tmp = DC_HPDx_CONNECTION_TIMER(0x9c4) |
  1709. DC_HPDx_RX_INT_TIMER(0xfa) | DC_HPDx_EN;
  1710. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  1711. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  1712. if (connector->connector_type == DRM_MODE_CONNECTOR_eDP ||
  1713. connector->connector_type == DRM_MODE_CONNECTOR_LVDS) {
  1714. /* don't try to enable hpd on eDP or LVDS avoid breaking the
  1715. * aux dp channel on imac and help (but not completely fix)
  1716. * https://bugzilla.redhat.com/show_bug.cgi?id=726143
  1717. * also avoid interrupt storms during dpms.
  1718. */
  1719. continue;
  1720. }
  1721. switch (radeon_connector->hpd.hpd) {
  1722. case RADEON_HPD_1:
  1723. WREG32(DC_HPD1_CONTROL, tmp);
  1724. break;
  1725. case RADEON_HPD_2:
  1726. WREG32(DC_HPD2_CONTROL, tmp);
  1727. break;
  1728. case RADEON_HPD_3:
  1729. WREG32(DC_HPD3_CONTROL, tmp);
  1730. break;
  1731. case RADEON_HPD_4:
  1732. WREG32(DC_HPD4_CONTROL, tmp);
  1733. break;
  1734. case RADEON_HPD_5:
  1735. WREG32(DC_HPD5_CONTROL, tmp);
  1736. break;
  1737. case RADEON_HPD_6:
  1738. WREG32(DC_HPD6_CONTROL, tmp);
  1739. break;
  1740. default:
  1741. break;
  1742. }
  1743. radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd);
  1744. if (radeon_connector->hpd.hpd != RADEON_HPD_NONE)
  1745. enabled |= 1 << radeon_connector->hpd.hpd;
  1746. }
  1747. radeon_irq_kms_enable_hpd(rdev, enabled);
  1748. }
  1749. /**
  1750. * evergreen_hpd_fini - hpd tear down callback.
  1751. *
  1752. * @rdev: radeon_device pointer
  1753. *
  1754. * Tear down the hpd pins used by the card (evergreen+).
  1755. * Disable the hpd interrupts.
  1756. */
  1757. void evergreen_hpd_fini(struct radeon_device *rdev)
  1758. {
  1759. struct drm_device *dev = rdev->ddev;
  1760. struct drm_connector *connector;
  1761. unsigned disabled = 0;
  1762. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  1763. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  1764. switch (radeon_connector->hpd.hpd) {
  1765. case RADEON_HPD_1:
  1766. WREG32(DC_HPD1_CONTROL, 0);
  1767. break;
  1768. case RADEON_HPD_2:
  1769. WREG32(DC_HPD2_CONTROL, 0);
  1770. break;
  1771. case RADEON_HPD_3:
  1772. WREG32(DC_HPD3_CONTROL, 0);
  1773. break;
  1774. case RADEON_HPD_4:
  1775. WREG32(DC_HPD4_CONTROL, 0);
  1776. break;
  1777. case RADEON_HPD_5:
  1778. WREG32(DC_HPD5_CONTROL, 0);
  1779. break;
  1780. case RADEON_HPD_6:
  1781. WREG32(DC_HPD6_CONTROL, 0);
  1782. break;
  1783. default:
  1784. break;
  1785. }
  1786. if (radeon_connector->hpd.hpd != RADEON_HPD_NONE)
  1787. disabled |= 1 << radeon_connector->hpd.hpd;
  1788. }
  1789. radeon_irq_kms_disable_hpd(rdev, disabled);
  1790. }
  1791. /* watermark setup */
  1792. static u32 evergreen_line_buffer_adjust(struct radeon_device *rdev,
  1793. struct radeon_crtc *radeon_crtc,
  1794. struct drm_display_mode *mode,
  1795. struct drm_display_mode *other_mode)
  1796. {
  1797. u32 tmp, buffer_alloc, i;
  1798. u32 pipe_offset = radeon_crtc->crtc_id * 0x20;
  1799. /*
  1800. * Line Buffer Setup
  1801. * There are 3 line buffers, each one shared by 2 display controllers.
  1802. * DC_LB_MEMORY_SPLIT controls how that line buffer is shared between
  1803. * the display controllers. The paritioning is done via one of four
  1804. * preset allocations specified in bits 2:0:
  1805. * first display controller
  1806. * 0 - first half of lb (3840 * 2)
  1807. * 1 - first 3/4 of lb (5760 * 2)
  1808. * 2 - whole lb (7680 * 2), other crtc must be disabled
  1809. * 3 - first 1/4 of lb (1920 * 2)
  1810. * second display controller
  1811. * 4 - second half of lb (3840 * 2)
  1812. * 5 - second 3/4 of lb (5760 * 2)
  1813. * 6 - whole lb (7680 * 2), other crtc must be disabled
  1814. * 7 - last 1/4 of lb (1920 * 2)
  1815. */
  1816. /* this can get tricky if we have two large displays on a paired group
  1817. * of crtcs. Ideally for multiple large displays we'd assign them to
  1818. * non-linked crtcs for maximum line buffer allocation.
  1819. */
  1820. if (radeon_crtc->base.enabled && mode) {
  1821. if (other_mode) {
  1822. tmp = 0; /* 1/2 */
  1823. buffer_alloc = 1;
  1824. } else {
  1825. tmp = 2; /* whole */
  1826. buffer_alloc = 2;
  1827. }
  1828. } else {
  1829. tmp = 0;
  1830. buffer_alloc = 0;
  1831. }
  1832. /* second controller of the pair uses second half of the lb */
  1833. if (radeon_crtc->crtc_id % 2)
  1834. tmp += 4;
  1835. WREG32(DC_LB_MEMORY_SPLIT + radeon_crtc->crtc_offset, tmp);
  1836. if (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE5(rdev)) {
  1837. WREG32(PIPE0_DMIF_BUFFER_CONTROL + pipe_offset,
  1838. DMIF_BUFFERS_ALLOCATED(buffer_alloc));
  1839. for (i = 0; i < rdev->usec_timeout; i++) {
  1840. if (RREG32(PIPE0_DMIF_BUFFER_CONTROL + pipe_offset) &
  1841. DMIF_BUFFERS_ALLOCATED_COMPLETED)
  1842. break;
  1843. udelay(1);
  1844. }
  1845. }
  1846. if (radeon_crtc->base.enabled && mode) {
  1847. switch (tmp) {
  1848. case 0:
  1849. case 4:
  1850. default:
  1851. if (ASIC_IS_DCE5(rdev))
  1852. return 4096 * 2;
  1853. else
  1854. return 3840 * 2;
  1855. case 1:
  1856. case 5:
  1857. if (ASIC_IS_DCE5(rdev))
  1858. return 6144 * 2;
  1859. else
  1860. return 5760 * 2;
  1861. case 2:
  1862. case 6:
  1863. if (ASIC_IS_DCE5(rdev))
  1864. return 8192 * 2;
  1865. else
  1866. return 7680 * 2;
  1867. case 3:
  1868. case 7:
  1869. if (ASIC_IS_DCE5(rdev))
  1870. return 2048 * 2;
  1871. else
  1872. return 1920 * 2;
  1873. }
  1874. }
  1875. /* controller not enabled, so no lb used */
  1876. return 0;
  1877. }
  1878. u32 evergreen_get_number_of_dram_channels(struct radeon_device *rdev)
  1879. {
  1880. u32 tmp = RREG32(MC_SHARED_CHMAP);
  1881. switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
  1882. case 0:
  1883. default:
  1884. return 1;
  1885. case 1:
  1886. return 2;
  1887. case 2:
  1888. return 4;
  1889. case 3:
  1890. return 8;
  1891. }
  1892. }
  1893. struct evergreen_wm_params {
  1894. u32 dram_channels; /* number of dram channels */
  1895. u32 yclk; /* bandwidth per dram data pin in kHz */
  1896. u32 sclk; /* engine clock in kHz */
  1897. u32 disp_clk; /* display clock in kHz */
  1898. u32 src_width; /* viewport width */
  1899. u32 active_time; /* active display time in ns */
  1900. u32 blank_time; /* blank time in ns */
  1901. bool interlaced; /* mode is interlaced */
  1902. fixed20_12 vsc; /* vertical scale ratio */
  1903. u32 num_heads; /* number of active crtcs */
  1904. u32 bytes_per_pixel; /* bytes per pixel display + overlay */
  1905. u32 lb_size; /* line buffer allocated to pipe */
  1906. u32 vtaps; /* vertical scaler taps */
  1907. };
  1908. static u32 evergreen_dram_bandwidth(struct evergreen_wm_params *wm)
  1909. {
  1910. /* Calculate DRAM Bandwidth and the part allocated to display. */
  1911. fixed20_12 dram_efficiency; /* 0.7 */
  1912. fixed20_12 yclk, dram_channels, bandwidth;
  1913. fixed20_12 a;
  1914. a.full = dfixed_const(1000);
  1915. yclk.full = dfixed_const(wm->yclk);
  1916. yclk.full = dfixed_div(yclk, a);
  1917. dram_channels.full = dfixed_const(wm->dram_channels * 4);
  1918. a.full = dfixed_const(10);
  1919. dram_efficiency.full = dfixed_const(7);
  1920. dram_efficiency.full = dfixed_div(dram_efficiency, a);
  1921. bandwidth.full = dfixed_mul(dram_channels, yclk);
  1922. bandwidth.full = dfixed_mul(bandwidth, dram_efficiency);
  1923. return dfixed_trunc(bandwidth);
  1924. }
  1925. static u32 evergreen_dram_bandwidth_for_display(struct evergreen_wm_params *wm)
  1926. {
  1927. /* Calculate DRAM Bandwidth and the part allocated to display. */
  1928. fixed20_12 disp_dram_allocation; /* 0.3 to 0.7 */
  1929. fixed20_12 yclk, dram_channels, bandwidth;
  1930. fixed20_12 a;
  1931. a.full = dfixed_const(1000);
  1932. yclk.full = dfixed_const(wm->yclk);
  1933. yclk.full = dfixed_div(yclk, a);
  1934. dram_channels.full = dfixed_const(wm->dram_channels * 4);
  1935. a.full = dfixed_const(10);
  1936. disp_dram_allocation.full = dfixed_const(3); /* XXX worse case value 0.3 */
  1937. disp_dram_allocation.full = dfixed_div(disp_dram_allocation, a);
  1938. bandwidth.full = dfixed_mul(dram_channels, yclk);
  1939. bandwidth.full = dfixed_mul(bandwidth, disp_dram_allocation);
  1940. return dfixed_trunc(bandwidth);
  1941. }
  1942. static u32 evergreen_data_return_bandwidth(struct evergreen_wm_params *wm)
  1943. {
  1944. /* Calculate the display Data return Bandwidth */
  1945. fixed20_12 return_efficiency; /* 0.8 */
  1946. fixed20_12 sclk, bandwidth;
  1947. fixed20_12 a;
  1948. a.full = dfixed_const(1000);
  1949. sclk.full = dfixed_const(wm->sclk);
  1950. sclk.full = dfixed_div(sclk, a);
  1951. a.full = dfixed_const(10);
  1952. return_efficiency.full = dfixed_const(8);
  1953. return_efficiency.full = dfixed_div(return_efficiency, a);
  1954. a.full = dfixed_const(32);
  1955. bandwidth.full = dfixed_mul(a, sclk);
  1956. bandwidth.full = dfixed_mul(bandwidth, return_efficiency);
  1957. return dfixed_trunc(bandwidth);
  1958. }
  1959. static u32 evergreen_dmif_request_bandwidth(struct evergreen_wm_params *wm)
  1960. {
  1961. /* Calculate the DMIF Request Bandwidth */
  1962. fixed20_12 disp_clk_request_efficiency; /* 0.8 */
  1963. fixed20_12 disp_clk, bandwidth;
  1964. fixed20_12 a;
  1965. a.full = dfixed_const(1000);
  1966. disp_clk.full = dfixed_const(wm->disp_clk);
  1967. disp_clk.full = dfixed_div(disp_clk, a);
  1968. a.full = dfixed_const(10);
  1969. disp_clk_request_efficiency.full = dfixed_const(8);
  1970. disp_clk_request_efficiency.full = dfixed_div(disp_clk_request_efficiency, a);
  1971. a.full = dfixed_const(32);
  1972. bandwidth.full = dfixed_mul(a, disp_clk);
  1973. bandwidth.full = dfixed_mul(bandwidth, disp_clk_request_efficiency);
  1974. return dfixed_trunc(bandwidth);
  1975. }
  1976. static u32 evergreen_available_bandwidth(struct evergreen_wm_params *wm)
  1977. {
  1978. /* Calculate the Available bandwidth. Display can use this temporarily but not in average. */
  1979. u32 dram_bandwidth = evergreen_dram_bandwidth(wm);
  1980. u32 data_return_bandwidth = evergreen_data_return_bandwidth(wm);
  1981. u32 dmif_req_bandwidth = evergreen_dmif_request_bandwidth(wm);
  1982. return min(dram_bandwidth, min(data_return_bandwidth, dmif_req_bandwidth));
  1983. }
  1984. static u32 evergreen_average_bandwidth(struct evergreen_wm_params *wm)
  1985. {
  1986. /* Calculate the display mode Average Bandwidth
  1987. * DisplayMode should contain the source and destination dimensions,
  1988. * timing, etc.
  1989. */
  1990. fixed20_12 bpp;
  1991. fixed20_12 line_time;
  1992. fixed20_12 src_width;
  1993. fixed20_12 bandwidth;
  1994. fixed20_12 a;
  1995. a.full = dfixed_const(1000);
  1996. line_time.full = dfixed_const(wm->active_time + wm->blank_time);
  1997. line_time.full = dfixed_div(line_time, a);
  1998. bpp.full = dfixed_const(wm->bytes_per_pixel);
  1999. src_width.full = dfixed_const(wm->src_width);
  2000. bandwidth.full = dfixed_mul(src_width, bpp);
  2001. bandwidth.full = dfixed_mul(bandwidth, wm->vsc);
  2002. bandwidth.full = dfixed_div(bandwidth, line_time);
  2003. return dfixed_trunc(bandwidth);
  2004. }
  2005. static u32 evergreen_latency_watermark(struct evergreen_wm_params *wm)
  2006. {
  2007. /* First calcualte the latency in ns */
  2008. u32 mc_latency = 2000; /* 2000 ns. */
  2009. u32 available_bandwidth = evergreen_available_bandwidth(wm);
  2010. u32 worst_chunk_return_time = (512 * 8 * 1000) / available_bandwidth;
  2011. u32 cursor_line_pair_return_time = (128 * 4 * 1000) / available_bandwidth;
  2012. u32 dc_latency = 40000000 / wm->disp_clk; /* dc pipe latency */
  2013. u32 other_heads_data_return_time = ((wm->num_heads + 1) * worst_chunk_return_time) +
  2014. (wm->num_heads * cursor_line_pair_return_time);
  2015. u32 latency = mc_latency + other_heads_data_return_time + dc_latency;
  2016. u32 max_src_lines_per_dst_line, lb_fill_bw, line_fill_time;
  2017. fixed20_12 a, b, c;
  2018. if (wm->num_heads == 0)
  2019. return 0;
  2020. a.full = dfixed_const(2);
  2021. b.full = dfixed_const(1);
  2022. if ((wm->vsc.full > a.full) ||
  2023. ((wm->vsc.full > b.full) && (wm->vtaps >= 3)) ||
  2024. (wm->vtaps >= 5) ||
  2025. ((wm->vsc.full >= a.full) && wm->interlaced))
  2026. max_src_lines_per_dst_line = 4;
  2027. else
  2028. max_src_lines_per_dst_line = 2;
  2029. a.full = dfixed_const(available_bandwidth);
  2030. b.full = dfixed_const(wm->num_heads);
  2031. a.full = dfixed_div(a, b);
  2032. lb_fill_bw = min(dfixed_trunc(a), wm->disp_clk * wm->bytes_per_pixel / 1000);
  2033. a.full = dfixed_const(max_src_lines_per_dst_line * wm->src_width * wm->bytes_per_pixel);
  2034. b.full = dfixed_const(1000);
  2035. c.full = dfixed_const(lb_fill_bw);
  2036. b.full = dfixed_div(c, b);
  2037. a.full = dfixed_div(a, b);
  2038. line_fill_time = dfixed_trunc(a);
  2039. if (line_fill_time < wm->active_time)
  2040. return latency;
  2041. else
  2042. return latency + (line_fill_time - wm->active_time);
  2043. }
  2044. static bool evergreen_average_bandwidth_vs_dram_bandwidth_for_display(struct evergreen_wm_params *wm)
  2045. {
  2046. if (evergreen_average_bandwidth(wm) <=
  2047. (evergreen_dram_bandwidth_for_display(wm) / wm->num_heads))
  2048. return true;
  2049. else
  2050. return false;
  2051. };
  2052. static bool evergreen_average_bandwidth_vs_available_bandwidth(struct evergreen_wm_params *wm)
  2053. {
  2054. if (evergreen_average_bandwidth(wm) <=
  2055. (evergreen_available_bandwidth(wm) / wm->num_heads))
  2056. return true;
  2057. else
  2058. return false;
  2059. };
  2060. static bool evergreen_check_latency_hiding(struct evergreen_wm_params *wm)
  2061. {
  2062. u32 lb_partitions = wm->lb_size / wm->src_width;
  2063. u32 line_time = wm->active_time + wm->blank_time;
  2064. u32 latency_tolerant_lines;
  2065. u32 latency_hiding;
  2066. fixed20_12 a;
  2067. a.full = dfixed_const(1);
  2068. if (wm->vsc.full > a.full)
  2069. latency_tolerant_lines = 1;
  2070. else {
  2071. if (lb_partitions <= (wm->vtaps + 1))
  2072. latency_tolerant_lines = 1;
  2073. else
  2074. latency_tolerant_lines = 2;
  2075. }
  2076. latency_hiding = (latency_tolerant_lines * line_time + wm->blank_time);
  2077. if (evergreen_latency_watermark(wm) <= latency_hiding)
  2078. return true;
  2079. else
  2080. return false;
  2081. }
  2082. static void evergreen_program_watermarks(struct radeon_device *rdev,
  2083. struct radeon_crtc *radeon_crtc,
  2084. u32 lb_size, u32 num_heads)
  2085. {
  2086. struct drm_display_mode *mode = &radeon_crtc->base.mode;
  2087. struct evergreen_wm_params wm_low, wm_high;
  2088. u32 dram_channels;
  2089. u32 active_time;
  2090. u32 line_time = 0;
  2091. u32 latency_watermark_a = 0, latency_watermark_b = 0;
  2092. u32 priority_a_mark = 0, priority_b_mark = 0;
  2093. u32 priority_a_cnt = PRIORITY_OFF;
  2094. u32 priority_b_cnt = PRIORITY_OFF;
  2095. u32 pipe_offset = radeon_crtc->crtc_id * 16;
  2096. u32 tmp, arb_control3;
  2097. fixed20_12 a, b, c;
  2098. if (radeon_crtc->base.enabled && num_heads && mode) {
  2099. active_time = (u32) div_u64((u64)mode->crtc_hdisplay * 1000000,
  2100. (u32)mode->clock);
  2101. line_time = (u32) div_u64((u64)mode->crtc_htotal * 1000000,
  2102. (u32)mode->clock);
  2103. line_time = min(line_time, (u32)65535);
  2104. priority_a_cnt = 0;
  2105. priority_b_cnt = 0;
  2106. dram_channels = evergreen_get_number_of_dram_channels(rdev);
  2107. /* watermark for high clocks */
  2108. if ((rdev->pm.pm_method == PM_METHOD_DPM) && rdev->pm.dpm_enabled) {
  2109. wm_high.yclk =
  2110. radeon_dpm_get_mclk(rdev, false) * 10;
  2111. wm_high.sclk =
  2112. radeon_dpm_get_sclk(rdev, false) * 10;
  2113. } else {
  2114. wm_high.yclk = rdev->pm.current_mclk * 10;
  2115. wm_high.sclk = rdev->pm.current_sclk * 10;
  2116. }
  2117. wm_high.disp_clk = mode->clock;
  2118. wm_high.src_width = mode->crtc_hdisplay;
  2119. wm_high.active_time = active_time;
  2120. wm_high.blank_time = line_time - wm_high.active_time;
  2121. wm_high.interlaced = false;
  2122. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  2123. wm_high.interlaced = true;
  2124. wm_high.vsc = radeon_crtc->vsc;
  2125. wm_high.vtaps = 1;
  2126. if (radeon_crtc->rmx_type != RMX_OFF)
  2127. wm_high.vtaps = 2;
  2128. wm_high.bytes_per_pixel = 4; /* XXX: get this from fb config */
  2129. wm_high.lb_size = lb_size;
  2130. wm_high.dram_channels = dram_channels;
  2131. wm_high.num_heads = num_heads;
  2132. /* watermark for low clocks */
  2133. if ((rdev->pm.pm_method == PM_METHOD_DPM) && rdev->pm.dpm_enabled) {
  2134. wm_low.yclk =
  2135. radeon_dpm_get_mclk(rdev, true) * 10;
  2136. wm_low.sclk =
  2137. radeon_dpm_get_sclk(rdev, true) * 10;
  2138. } else {
  2139. wm_low.yclk = rdev->pm.current_mclk * 10;
  2140. wm_low.sclk = rdev->pm.current_sclk * 10;
  2141. }
  2142. wm_low.disp_clk = mode->clock;
  2143. wm_low.src_width = mode->crtc_hdisplay;
  2144. wm_low.active_time = active_time;
  2145. wm_low.blank_time = line_time - wm_low.active_time;
  2146. wm_low.interlaced = false;
  2147. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  2148. wm_low.interlaced = true;
  2149. wm_low.vsc = radeon_crtc->vsc;
  2150. wm_low.vtaps = 1;
  2151. if (radeon_crtc->rmx_type != RMX_OFF)
  2152. wm_low.vtaps = 2;
  2153. wm_low.bytes_per_pixel = 4; /* XXX: get this from fb config */
  2154. wm_low.lb_size = lb_size;
  2155. wm_low.dram_channels = dram_channels;
  2156. wm_low.num_heads = num_heads;
  2157. /* set for high clocks */
  2158. latency_watermark_a = min(evergreen_latency_watermark(&wm_high), (u32)65535);
  2159. /* set for low clocks */
  2160. latency_watermark_b = min(evergreen_latency_watermark(&wm_low), (u32)65535);
  2161. /* possibly force display priority to high */
  2162. /* should really do this at mode validation time... */
  2163. if (!evergreen_average_bandwidth_vs_dram_bandwidth_for_display(&wm_high) ||
  2164. !evergreen_average_bandwidth_vs_available_bandwidth(&wm_high) ||
  2165. !evergreen_check_latency_hiding(&wm_high) ||
  2166. (rdev->disp_priority == 2)) {
  2167. DRM_DEBUG_KMS("force priority a to high\n");
  2168. priority_a_cnt |= PRIORITY_ALWAYS_ON;
  2169. }
  2170. if (!evergreen_average_bandwidth_vs_dram_bandwidth_for_display(&wm_low) ||
  2171. !evergreen_average_bandwidth_vs_available_bandwidth(&wm_low) ||
  2172. !evergreen_check_latency_hiding(&wm_low) ||
  2173. (rdev->disp_priority == 2)) {
  2174. DRM_DEBUG_KMS("force priority b to high\n");
  2175. priority_b_cnt |= PRIORITY_ALWAYS_ON;
  2176. }
  2177. a.full = dfixed_const(1000);
  2178. b.full = dfixed_const(mode->clock);
  2179. b.full = dfixed_div(b, a);
  2180. c.full = dfixed_const(latency_watermark_a);
  2181. c.full = dfixed_mul(c, b);
  2182. c.full = dfixed_mul(c, radeon_crtc->hsc);
  2183. c.full = dfixed_div(c, a);
  2184. a.full = dfixed_const(16);
  2185. c.full = dfixed_div(c, a);
  2186. priority_a_mark = dfixed_trunc(c);
  2187. priority_a_cnt |= priority_a_mark & PRIORITY_MARK_MASK;
  2188. a.full = dfixed_const(1000);
  2189. b.full = dfixed_const(mode->clock);
  2190. b.full = dfixed_div(b, a);
  2191. c.full = dfixed_const(latency_watermark_b);
  2192. c.full = dfixed_mul(c, b);
  2193. c.full = dfixed_mul(c, radeon_crtc->hsc);
  2194. c.full = dfixed_div(c, a);
  2195. a.full = dfixed_const(16);
  2196. c.full = dfixed_div(c, a);
  2197. priority_b_mark = dfixed_trunc(c);
  2198. priority_b_cnt |= priority_b_mark & PRIORITY_MARK_MASK;
  2199. /* Save number of lines the linebuffer leads before the scanout */
  2200. radeon_crtc->lb_vblank_lead_lines = DIV_ROUND_UP(lb_size, mode->crtc_hdisplay);
  2201. }
  2202. /* select wm A */
  2203. arb_control3 = RREG32(PIPE0_ARBITRATION_CONTROL3 + pipe_offset);
  2204. tmp = arb_control3;
  2205. tmp &= ~LATENCY_WATERMARK_MASK(3);
  2206. tmp |= LATENCY_WATERMARK_MASK(1);
  2207. WREG32(PIPE0_ARBITRATION_CONTROL3 + pipe_offset, tmp);
  2208. WREG32(PIPE0_LATENCY_CONTROL + pipe_offset,
  2209. (LATENCY_LOW_WATERMARK(latency_watermark_a) |
  2210. LATENCY_HIGH_WATERMARK(line_time)));
  2211. /* select wm B */
  2212. tmp = RREG32(PIPE0_ARBITRATION_CONTROL3 + pipe_offset);
  2213. tmp &= ~LATENCY_WATERMARK_MASK(3);
  2214. tmp |= LATENCY_WATERMARK_MASK(2);
  2215. WREG32(PIPE0_ARBITRATION_CONTROL3 + pipe_offset, tmp);
  2216. WREG32(PIPE0_LATENCY_CONTROL + pipe_offset,
  2217. (LATENCY_LOW_WATERMARK(latency_watermark_b) |
  2218. LATENCY_HIGH_WATERMARK(line_time)));
  2219. /* restore original selection */
  2220. WREG32(PIPE0_ARBITRATION_CONTROL3 + pipe_offset, arb_control3);
  2221. /* write the priority marks */
  2222. WREG32(PRIORITY_A_CNT + radeon_crtc->crtc_offset, priority_a_cnt);
  2223. WREG32(PRIORITY_B_CNT + radeon_crtc->crtc_offset, priority_b_cnt);
  2224. /* save values for DPM */
  2225. radeon_crtc->line_time = line_time;
  2226. radeon_crtc->wm_high = latency_watermark_a;
  2227. radeon_crtc->wm_low = latency_watermark_b;
  2228. }
  2229. /**
  2230. * evergreen_bandwidth_update - update display watermarks callback.
  2231. *
  2232. * @rdev: radeon_device pointer
  2233. *
  2234. * Update the display watermarks based on the requested mode(s)
  2235. * (evergreen+).
  2236. */
  2237. void evergreen_bandwidth_update(struct radeon_device *rdev)
  2238. {
  2239. struct drm_display_mode *mode0 = NULL;
  2240. struct drm_display_mode *mode1 = NULL;
  2241. u32 num_heads = 0, lb_size;
  2242. int i;
  2243. if (!rdev->mode_info.mode_config_initialized)
  2244. return;
  2245. radeon_update_display_priority(rdev);
  2246. for (i = 0; i < rdev->num_crtc; i++) {
  2247. if (rdev->mode_info.crtcs[i]->base.enabled)
  2248. num_heads++;
  2249. }
  2250. for (i = 0; i < rdev->num_crtc; i += 2) {
  2251. mode0 = &rdev->mode_info.crtcs[i]->base.mode;
  2252. mode1 = &rdev->mode_info.crtcs[i+1]->base.mode;
  2253. lb_size = evergreen_line_buffer_adjust(rdev, rdev->mode_info.crtcs[i], mode0, mode1);
  2254. evergreen_program_watermarks(rdev, rdev->mode_info.crtcs[i], lb_size, num_heads);
  2255. lb_size = evergreen_line_buffer_adjust(rdev, rdev->mode_info.crtcs[i+1], mode1, mode0);
  2256. evergreen_program_watermarks(rdev, rdev->mode_info.crtcs[i+1], lb_size, num_heads);
  2257. }
  2258. }
  2259. /**
  2260. * evergreen_mc_wait_for_idle - wait for MC idle callback.
  2261. *
  2262. * @rdev: radeon_device pointer
  2263. *
  2264. * Wait for the MC (memory controller) to be idle.
  2265. * (evergreen+).
  2266. * Returns 0 if the MC is idle, -1 if not.
  2267. */
  2268. int evergreen_mc_wait_for_idle(struct radeon_device *rdev)
  2269. {
  2270. unsigned i;
  2271. u32 tmp;
  2272. for (i = 0; i < rdev->usec_timeout; i++) {
  2273. /* read MC_STATUS */
  2274. tmp = RREG32(SRBM_STATUS) & 0x1F00;
  2275. if (!tmp)
  2276. return 0;
  2277. udelay(1);
  2278. }
  2279. return -1;
  2280. }
  2281. /*
  2282. * GART
  2283. */
  2284. void evergreen_pcie_gart_tlb_flush(struct radeon_device *rdev)
  2285. {
  2286. unsigned i;
  2287. u32 tmp;
  2288. WREG32(HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
  2289. WREG32(VM_CONTEXT0_REQUEST_RESPONSE, REQUEST_TYPE(1));
  2290. for (i = 0; i < rdev->usec_timeout; i++) {
  2291. /* read MC_STATUS */
  2292. tmp = RREG32(VM_CONTEXT0_REQUEST_RESPONSE);
  2293. tmp = (tmp & RESPONSE_TYPE_MASK) >> RESPONSE_TYPE_SHIFT;
  2294. if (tmp == 2) {
  2295. pr_warn("[drm] r600 flush TLB failed\n");
  2296. return;
  2297. }
  2298. if (tmp) {
  2299. return;
  2300. }
  2301. udelay(1);
  2302. }
  2303. }
  2304. static int evergreen_pcie_gart_enable(struct radeon_device *rdev)
  2305. {
  2306. u32 tmp;
  2307. int r;
  2308. if (rdev->gart.robj == NULL) {
  2309. dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
  2310. return -EINVAL;
  2311. }
  2312. r = radeon_gart_table_vram_pin(rdev);
  2313. if (r)
  2314. return r;
  2315. /* Setup L2 cache */
  2316. WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
  2317. ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
  2318. EFFECTIVE_L2_QUEUE_SIZE(7));
  2319. WREG32(VM_L2_CNTL2, 0);
  2320. WREG32(VM_L2_CNTL3, BANK_SELECT(0) | CACHE_UPDATE_MODE(2));
  2321. /* Setup TLB control */
  2322. tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
  2323. SYSTEM_ACCESS_MODE_NOT_IN_SYS |
  2324. SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU |
  2325. EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5);
  2326. if (rdev->flags & RADEON_IS_IGP) {
  2327. WREG32(FUS_MC_VM_MD_L1_TLB0_CNTL, tmp);
  2328. WREG32(FUS_MC_VM_MD_L1_TLB1_CNTL, tmp);
  2329. WREG32(FUS_MC_VM_MD_L1_TLB2_CNTL, tmp);
  2330. } else {
  2331. WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp);
  2332. WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp);
  2333. WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp);
  2334. if ((rdev->family == CHIP_JUNIPER) ||
  2335. (rdev->family == CHIP_CYPRESS) ||
  2336. (rdev->family == CHIP_HEMLOCK) ||
  2337. (rdev->family == CHIP_BARTS))
  2338. WREG32(MC_VM_MD_L1_TLB3_CNTL, tmp);
  2339. }
  2340. WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp);
  2341. WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp);
  2342. WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp);
  2343. WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp);
  2344. WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
  2345. WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
  2346. WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
  2347. WREG32(VM_CONTEXT0_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
  2348. RANGE_PROTECTION_FAULT_ENABLE_DEFAULT);
  2349. WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
  2350. (u32)(rdev->dummy_page.addr >> 12));
  2351. WREG32(VM_CONTEXT1_CNTL, 0);
  2352. evergreen_pcie_gart_tlb_flush(rdev);
  2353. DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
  2354. (unsigned)(rdev->mc.gtt_size >> 20),
  2355. (unsigned long long)rdev->gart.table_addr);
  2356. rdev->gart.ready = true;
  2357. return 0;
  2358. }
  2359. static void evergreen_pcie_gart_disable(struct radeon_device *rdev)
  2360. {
  2361. u32 tmp;
  2362. /* Disable all tables */
  2363. WREG32(VM_CONTEXT0_CNTL, 0);
  2364. WREG32(VM_CONTEXT1_CNTL, 0);
  2365. /* Setup L2 cache */
  2366. WREG32(VM_L2_CNTL, ENABLE_L2_FRAGMENT_PROCESSING |
  2367. EFFECTIVE_L2_QUEUE_SIZE(7));
  2368. WREG32(VM_L2_CNTL2, 0);
  2369. WREG32(VM_L2_CNTL3, BANK_SELECT(0) | CACHE_UPDATE_MODE(2));
  2370. /* Setup TLB control */
  2371. tmp = EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5);
  2372. WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp);
  2373. WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp);
  2374. WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp);
  2375. WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp);
  2376. WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp);
  2377. WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp);
  2378. WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp);
  2379. radeon_gart_table_vram_unpin(rdev);
  2380. }
  2381. static void evergreen_pcie_gart_fini(struct radeon_device *rdev)
  2382. {
  2383. evergreen_pcie_gart_disable(rdev);
  2384. radeon_gart_table_vram_free(rdev);
  2385. radeon_gart_fini(rdev);
  2386. }
  2387. static void evergreen_agp_enable(struct radeon_device *rdev)
  2388. {
  2389. u32 tmp;
  2390. /* Setup L2 cache */
  2391. WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
  2392. ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
  2393. EFFECTIVE_L2_QUEUE_SIZE(7));
  2394. WREG32(VM_L2_CNTL2, 0);
  2395. WREG32(VM_L2_CNTL3, BANK_SELECT(0) | CACHE_UPDATE_MODE(2));
  2396. /* Setup TLB control */
  2397. tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
  2398. SYSTEM_ACCESS_MODE_NOT_IN_SYS |
  2399. SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU |
  2400. EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5);
  2401. WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp);
  2402. WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp);
  2403. WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp);
  2404. WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp);
  2405. WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp);
  2406. WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp);
  2407. WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp);
  2408. WREG32(VM_CONTEXT0_CNTL, 0);
  2409. WREG32(VM_CONTEXT1_CNTL, 0);
  2410. }
  2411. static const unsigned ni_dig_offsets[] =
  2412. {
  2413. NI_DIG0_REGISTER_OFFSET,
  2414. NI_DIG1_REGISTER_OFFSET,
  2415. NI_DIG2_REGISTER_OFFSET,
  2416. NI_DIG3_REGISTER_OFFSET,
  2417. NI_DIG4_REGISTER_OFFSET,
  2418. NI_DIG5_REGISTER_OFFSET
  2419. };
  2420. static const unsigned ni_tx_offsets[] =
  2421. {
  2422. NI_DCIO_UNIPHY0_UNIPHY_TX_CONTROL1,
  2423. NI_DCIO_UNIPHY1_UNIPHY_TX_CONTROL1,
  2424. NI_DCIO_UNIPHY2_UNIPHY_TX_CONTROL1,
  2425. NI_DCIO_UNIPHY3_UNIPHY_TX_CONTROL1,
  2426. NI_DCIO_UNIPHY4_UNIPHY_TX_CONTROL1,
  2427. NI_DCIO_UNIPHY5_UNIPHY_TX_CONTROL1
  2428. };
  2429. static const unsigned evergreen_dp_offsets[] =
  2430. {
  2431. EVERGREEN_DP0_REGISTER_OFFSET,
  2432. EVERGREEN_DP1_REGISTER_OFFSET,
  2433. EVERGREEN_DP2_REGISTER_OFFSET,
  2434. EVERGREEN_DP3_REGISTER_OFFSET,
  2435. EVERGREEN_DP4_REGISTER_OFFSET,
  2436. EVERGREEN_DP5_REGISTER_OFFSET
  2437. };
  2438. /*
  2439. * Assumption is that EVERGREEN_CRTC_MASTER_EN enable for requested crtc
  2440. * We go from crtc to connector and it is not relible since it
  2441. * should be an opposite direction .If crtc is enable then
  2442. * find the dig_fe which selects this crtc and insure that it enable.
  2443. * if such dig_fe is found then find dig_be which selects found dig_be and
  2444. * insure that it enable and in DP_SST mode.
  2445. * if UNIPHY_PLL_CONTROL1.enable then we should disconnect timing
  2446. * from dp symbols clocks .
  2447. */
  2448. static bool evergreen_is_dp_sst_stream_enabled(struct radeon_device *rdev,
  2449. unsigned crtc_id, unsigned *ret_dig_fe)
  2450. {
  2451. unsigned i;
  2452. unsigned dig_fe;
  2453. unsigned dig_be;
  2454. unsigned dig_en_be;
  2455. unsigned uniphy_pll;
  2456. unsigned digs_fe_selected;
  2457. unsigned dig_be_mode;
  2458. unsigned dig_fe_mask;
  2459. bool is_enabled = false;
  2460. bool found_crtc = false;
  2461. /* loop through all running dig_fe to find selected crtc */
  2462. for (i = 0; i < ARRAY_SIZE(ni_dig_offsets); i++) {
  2463. dig_fe = RREG32(NI_DIG_FE_CNTL + ni_dig_offsets[i]);
  2464. if (dig_fe & NI_DIG_FE_CNTL_SYMCLK_FE_ON &&
  2465. crtc_id == NI_DIG_FE_CNTL_SOURCE_SELECT(dig_fe)) {
  2466. /* found running pipe */
  2467. found_crtc = true;
  2468. dig_fe_mask = 1 << i;
  2469. dig_fe = i;
  2470. break;
  2471. }
  2472. }
  2473. if (found_crtc) {
  2474. /* loop through all running dig_be to find selected dig_fe */
  2475. for (i = 0; i < ARRAY_SIZE(ni_dig_offsets); i++) {
  2476. dig_be = RREG32(NI_DIG_BE_CNTL + ni_dig_offsets[i]);
  2477. /* if dig_fe_selected by dig_be? */
  2478. digs_fe_selected = NI_DIG_BE_CNTL_FE_SOURCE_SELECT(dig_be);
  2479. dig_be_mode = NI_DIG_FE_CNTL_MODE(dig_be);
  2480. if (dig_fe_mask & digs_fe_selected &&
  2481. /* if dig_be in sst mode? */
  2482. dig_be_mode == NI_DIG_BE_DPSST) {
  2483. dig_en_be = RREG32(NI_DIG_BE_EN_CNTL +
  2484. ni_dig_offsets[i]);
  2485. uniphy_pll = RREG32(NI_DCIO_UNIPHY0_PLL_CONTROL1 +
  2486. ni_tx_offsets[i]);
  2487. /* dig_be enable and tx is running */
  2488. if (dig_en_be & NI_DIG_BE_EN_CNTL_ENABLE &&
  2489. dig_en_be & NI_DIG_BE_EN_CNTL_SYMBCLK_ON &&
  2490. uniphy_pll & NI_DCIO_UNIPHY0_PLL_CONTROL1_ENABLE) {
  2491. is_enabled = true;
  2492. *ret_dig_fe = dig_fe;
  2493. break;
  2494. }
  2495. }
  2496. }
  2497. }
  2498. return is_enabled;
  2499. }
  2500. /*
  2501. * Blank dig when in dp sst mode
  2502. * Dig ignores crtc timing
  2503. */
  2504. static void evergreen_blank_dp_output(struct radeon_device *rdev,
  2505. unsigned dig_fe)
  2506. {
  2507. unsigned stream_ctrl;
  2508. unsigned fifo_ctrl;
  2509. unsigned counter = 0;
  2510. if (dig_fe >= ARRAY_SIZE(evergreen_dp_offsets)) {
  2511. DRM_ERROR("invalid dig_fe %d\n", dig_fe);
  2512. return;
  2513. }
  2514. stream_ctrl = RREG32(EVERGREEN_DP_VID_STREAM_CNTL +
  2515. evergreen_dp_offsets[dig_fe]);
  2516. if (!(stream_ctrl & EVERGREEN_DP_VID_STREAM_CNTL_ENABLE)) {
  2517. DRM_ERROR("dig %d , should be enable\n", dig_fe);
  2518. return;
  2519. }
  2520. stream_ctrl &=~EVERGREEN_DP_VID_STREAM_CNTL_ENABLE;
  2521. WREG32(EVERGREEN_DP_VID_STREAM_CNTL +
  2522. evergreen_dp_offsets[dig_fe], stream_ctrl);
  2523. stream_ctrl = RREG32(EVERGREEN_DP_VID_STREAM_CNTL +
  2524. evergreen_dp_offsets[dig_fe]);
  2525. while (counter < 32 && stream_ctrl & EVERGREEN_DP_VID_STREAM_STATUS) {
  2526. msleep(1);
  2527. counter++;
  2528. stream_ctrl = RREG32(EVERGREEN_DP_VID_STREAM_CNTL +
  2529. evergreen_dp_offsets[dig_fe]);
  2530. }
  2531. if (counter >= 32 )
  2532. DRM_ERROR("counter exceeds %d\n", counter);
  2533. fifo_ctrl = RREG32(EVERGREEN_DP_STEER_FIFO + evergreen_dp_offsets[dig_fe]);
  2534. fifo_ctrl |= EVERGREEN_DP_STEER_FIFO_RESET;
  2535. WREG32(EVERGREEN_DP_STEER_FIFO + evergreen_dp_offsets[dig_fe], fifo_ctrl);
  2536. }
  2537. void evergreen_mc_stop(struct radeon_device *rdev, struct evergreen_mc_save *save)
  2538. {
  2539. u32 crtc_enabled, tmp, frame_count, blackout;
  2540. int i, j;
  2541. unsigned dig_fe;
  2542. if (!ASIC_IS_NODCE(rdev)) {
  2543. save->vga_render_control = RREG32(VGA_RENDER_CONTROL);
  2544. save->vga_hdp_control = RREG32(VGA_HDP_CONTROL);
  2545. /* disable VGA render */
  2546. WREG32(VGA_RENDER_CONTROL, 0);
  2547. }
  2548. /* blank the display controllers */
  2549. for (i = 0; i < rdev->num_crtc; i++) {
  2550. crtc_enabled = RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i]) & EVERGREEN_CRTC_MASTER_EN;
  2551. if (crtc_enabled) {
  2552. save->crtc_enabled[i] = true;
  2553. if (ASIC_IS_DCE6(rdev)) {
  2554. tmp = RREG32(EVERGREEN_CRTC_BLANK_CONTROL + crtc_offsets[i]);
  2555. if (!(tmp & EVERGREEN_CRTC_BLANK_DATA_EN)) {
  2556. radeon_wait_for_vblank(rdev, i);
  2557. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 1);
  2558. tmp |= EVERGREEN_CRTC_BLANK_DATA_EN;
  2559. WREG32(EVERGREEN_CRTC_BLANK_CONTROL + crtc_offsets[i], tmp);
  2560. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 0);
  2561. }
  2562. } else {
  2563. tmp = RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i]);
  2564. if (!(tmp & EVERGREEN_CRTC_DISP_READ_REQUEST_DISABLE)) {
  2565. radeon_wait_for_vblank(rdev, i);
  2566. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 1);
  2567. tmp |= EVERGREEN_CRTC_DISP_READ_REQUEST_DISABLE;
  2568. WREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i], tmp);
  2569. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 0);
  2570. }
  2571. }
  2572. /* wait for the next frame */
  2573. frame_count = radeon_get_vblank_counter(rdev, i);
  2574. for (j = 0; j < rdev->usec_timeout; j++) {
  2575. if (radeon_get_vblank_counter(rdev, i) != frame_count)
  2576. break;
  2577. udelay(1);
  2578. }
  2579. /*we should disable dig if it drives dp sst*/
  2580. /*but we are in radeon_device_init and the topology is unknown*/
  2581. /*and it is available after radeon_modeset_init*/
  2582. /*the following method radeon_atom_encoder_dpms_dig*/
  2583. /*does the job if we initialize it properly*/
  2584. /*for now we do it this manually*/
  2585. /**/
  2586. if (ASIC_IS_DCE5(rdev) &&
  2587. evergreen_is_dp_sst_stream_enabled(rdev, i ,&dig_fe))
  2588. evergreen_blank_dp_output(rdev, dig_fe);
  2589. /*we could remove 6 lines below*/
  2590. /* XXX this is a hack to avoid strange behavior with EFI on certain systems */
  2591. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 1);
  2592. tmp = RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i]);
  2593. tmp &= ~EVERGREEN_CRTC_MASTER_EN;
  2594. WREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i], tmp);
  2595. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 0);
  2596. save->crtc_enabled[i] = false;
  2597. /* ***** */
  2598. } else {
  2599. save->crtc_enabled[i] = false;
  2600. }
  2601. }
  2602. radeon_mc_wait_for_idle(rdev);
  2603. blackout = RREG32(MC_SHARED_BLACKOUT_CNTL);
  2604. if ((blackout & BLACKOUT_MODE_MASK) != 1) {
  2605. /* Block CPU access */
  2606. WREG32(BIF_FB_EN, 0);
  2607. /* blackout the MC */
  2608. blackout &= ~BLACKOUT_MODE_MASK;
  2609. WREG32(MC_SHARED_BLACKOUT_CNTL, blackout | 1);
  2610. }
  2611. /* wait for the MC to settle */
  2612. udelay(100);
  2613. /* lock double buffered regs */
  2614. for (i = 0; i < rdev->num_crtc; i++) {
  2615. if (save->crtc_enabled[i]) {
  2616. tmp = RREG32(EVERGREEN_GRPH_UPDATE + crtc_offsets[i]);
  2617. if (!(tmp & EVERGREEN_GRPH_UPDATE_LOCK)) {
  2618. tmp |= EVERGREEN_GRPH_UPDATE_LOCK;
  2619. WREG32(EVERGREEN_GRPH_UPDATE + crtc_offsets[i], tmp);
  2620. }
  2621. tmp = RREG32(EVERGREEN_MASTER_UPDATE_LOCK + crtc_offsets[i]);
  2622. if (!(tmp & 1)) {
  2623. tmp |= 1;
  2624. WREG32(EVERGREEN_MASTER_UPDATE_LOCK + crtc_offsets[i], tmp);
  2625. }
  2626. }
  2627. }
  2628. }
  2629. void evergreen_mc_resume(struct radeon_device *rdev, struct evergreen_mc_save *save)
  2630. {
  2631. u32 tmp, frame_count;
  2632. int i, j;
  2633. /* update crtc base addresses */
  2634. for (i = 0; i < rdev->num_crtc; i++) {
  2635. WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS_HIGH + crtc_offsets[i],
  2636. upper_32_bits(rdev->mc.vram_start));
  2637. WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS_HIGH + crtc_offsets[i],
  2638. upper_32_bits(rdev->mc.vram_start));
  2639. WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS + crtc_offsets[i],
  2640. (u32)rdev->mc.vram_start);
  2641. WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS + crtc_offsets[i],
  2642. (u32)rdev->mc.vram_start);
  2643. }
  2644. if (!ASIC_IS_NODCE(rdev)) {
  2645. WREG32(EVERGREEN_VGA_MEMORY_BASE_ADDRESS_HIGH, upper_32_bits(rdev->mc.vram_start));
  2646. WREG32(EVERGREEN_VGA_MEMORY_BASE_ADDRESS, (u32)rdev->mc.vram_start);
  2647. }
  2648. /* unlock regs and wait for update */
  2649. for (i = 0; i < rdev->num_crtc; i++) {
  2650. if (save->crtc_enabled[i]) {
  2651. tmp = RREG32(EVERGREEN_MASTER_UPDATE_MODE + crtc_offsets[i]);
  2652. if ((tmp & 0x7) != 0) {
  2653. tmp &= ~0x7;
  2654. WREG32(EVERGREEN_MASTER_UPDATE_MODE + crtc_offsets[i], tmp);
  2655. }
  2656. tmp = RREG32(EVERGREEN_GRPH_UPDATE + crtc_offsets[i]);
  2657. if (tmp & EVERGREEN_GRPH_UPDATE_LOCK) {
  2658. tmp &= ~EVERGREEN_GRPH_UPDATE_LOCK;
  2659. WREG32(EVERGREEN_GRPH_UPDATE + crtc_offsets[i], tmp);
  2660. }
  2661. tmp = RREG32(EVERGREEN_MASTER_UPDATE_LOCK + crtc_offsets[i]);
  2662. if (tmp & 1) {
  2663. tmp &= ~1;
  2664. WREG32(EVERGREEN_MASTER_UPDATE_LOCK + crtc_offsets[i], tmp);
  2665. }
  2666. for (j = 0; j < rdev->usec_timeout; j++) {
  2667. tmp = RREG32(EVERGREEN_GRPH_UPDATE + crtc_offsets[i]);
  2668. if ((tmp & EVERGREEN_GRPH_SURFACE_UPDATE_PENDING) == 0)
  2669. break;
  2670. udelay(1);
  2671. }
  2672. }
  2673. }
  2674. /* unblackout the MC */
  2675. tmp = RREG32(MC_SHARED_BLACKOUT_CNTL);
  2676. tmp &= ~BLACKOUT_MODE_MASK;
  2677. WREG32(MC_SHARED_BLACKOUT_CNTL, tmp);
  2678. /* allow CPU access */
  2679. WREG32(BIF_FB_EN, FB_READ_EN | FB_WRITE_EN);
  2680. for (i = 0; i < rdev->num_crtc; i++) {
  2681. if (save->crtc_enabled[i]) {
  2682. if (ASIC_IS_DCE6(rdev)) {
  2683. tmp = RREG32(EVERGREEN_CRTC_BLANK_CONTROL + crtc_offsets[i]);
  2684. tmp &= ~EVERGREEN_CRTC_BLANK_DATA_EN;
  2685. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 1);
  2686. WREG32(EVERGREEN_CRTC_BLANK_CONTROL + crtc_offsets[i], tmp);
  2687. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 0);
  2688. } else {
  2689. tmp = RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i]);
  2690. tmp &= ~EVERGREEN_CRTC_DISP_READ_REQUEST_DISABLE;
  2691. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 1);
  2692. WREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i], tmp);
  2693. WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 0);
  2694. }
  2695. /* wait for the next frame */
  2696. frame_count = radeon_get_vblank_counter(rdev, i);
  2697. for (j = 0; j < rdev->usec_timeout; j++) {
  2698. if (radeon_get_vblank_counter(rdev, i) != frame_count)
  2699. break;
  2700. udelay(1);
  2701. }
  2702. }
  2703. }
  2704. if (!ASIC_IS_NODCE(rdev)) {
  2705. /* Unlock vga access */
  2706. WREG32(VGA_HDP_CONTROL, save->vga_hdp_control);
  2707. mdelay(1);
  2708. WREG32(VGA_RENDER_CONTROL, save->vga_render_control);
  2709. }
  2710. }
  2711. void evergreen_mc_program(struct radeon_device *rdev)
  2712. {
  2713. struct evergreen_mc_save save;
  2714. u32 tmp;
  2715. int i, j;
  2716. /* Initialize HDP */
  2717. for (i = 0, j = 0; i < 32; i++, j += 0x18) {
  2718. WREG32((0x2c14 + j), 0x00000000);
  2719. WREG32((0x2c18 + j), 0x00000000);
  2720. WREG32((0x2c1c + j), 0x00000000);
  2721. WREG32((0x2c20 + j), 0x00000000);
  2722. WREG32((0x2c24 + j), 0x00000000);
  2723. }
  2724. WREG32(HDP_REG_COHERENCY_FLUSH_CNTL, 0);
  2725. evergreen_mc_stop(rdev, &save);
  2726. if (evergreen_mc_wait_for_idle(rdev)) {
  2727. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  2728. }
  2729. /* Lockout access through VGA aperture*/
  2730. WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE);
  2731. /* Update configuration */
  2732. if (rdev->flags & RADEON_IS_AGP) {
  2733. if (rdev->mc.vram_start < rdev->mc.gtt_start) {
  2734. /* VRAM before AGP */
  2735. WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
  2736. rdev->mc.vram_start >> 12);
  2737. WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
  2738. rdev->mc.gtt_end >> 12);
  2739. } else {
  2740. /* VRAM after AGP */
  2741. WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
  2742. rdev->mc.gtt_start >> 12);
  2743. WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
  2744. rdev->mc.vram_end >> 12);
  2745. }
  2746. } else {
  2747. WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
  2748. rdev->mc.vram_start >> 12);
  2749. WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
  2750. rdev->mc.vram_end >> 12);
  2751. }
  2752. WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR, rdev->vram_scratch.gpu_addr >> 12);
  2753. /* llano/ontario only */
  2754. if ((rdev->family == CHIP_PALM) ||
  2755. (rdev->family == CHIP_SUMO) ||
  2756. (rdev->family == CHIP_SUMO2)) {
  2757. tmp = RREG32(MC_FUS_VM_FB_OFFSET) & 0x000FFFFF;
  2758. tmp |= ((rdev->mc.vram_end >> 20) & 0xF) << 24;
  2759. tmp |= ((rdev->mc.vram_start >> 20) & 0xF) << 20;
  2760. WREG32(MC_FUS_VM_FB_OFFSET, tmp);
  2761. }
  2762. tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16;
  2763. tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF);
  2764. WREG32(MC_VM_FB_LOCATION, tmp);
  2765. WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8));
  2766. WREG32(HDP_NONSURFACE_INFO, (2 << 7) | (1 << 30));
  2767. WREG32(HDP_NONSURFACE_SIZE, 0x3FFFFFFF);
  2768. if (rdev->flags & RADEON_IS_AGP) {
  2769. WREG32(MC_VM_AGP_TOP, rdev->mc.gtt_end >> 16);
  2770. WREG32(MC_VM_AGP_BOT, rdev->mc.gtt_start >> 16);
  2771. WREG32(MC_VM_AGP_BASE, rdev->mc.agp_base >> 22);
  2772. } else {
  2773. WREG32(MC_VM_AGP_BASE, 0);
  2774. WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF);
  2775. WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF);
  2776. }
  2777. if (evergreen_mc_wait_for_idle(rdev)) {
  2778. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  2779. }
  2780. evergreen_mc_resume(rdev, &save);
  2781. /* we need to own VRAM, so turn off the VGA renderer here
  2782. * to stop it overwriting our objects */
  2783. rv515_vga_render_disable(rdev);
  2784. }
  2785. /*
  2786. * CP.
  2787. */
  2788. void evergreen_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
  2789. {
  2790. struct radeon_ring *ring = &rdev->ring[ib->ring];
  2791. u32 next_rptr;
  2792. /* set to DX10/11 mode */
  2793. radeon_ring_write(ring, PACKET3(PACKET3_MODE_CONTROL, 0));
  2794. radeon_ring_write(ring, 1);
  2795. if (ring->rptr_save_reg) {
  2796. next_rptr = ring->wptr + 3 + 4;
  2797. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  2798. radeon_ring_write(ring, ((ring->rptr_save_reg -
  2799. PACKET3_SET_CONFIG_REG_START) >> 2));
  2800. radeon_ring_write(ring, next_rptr);
  2801. } else if (rdev->wb.enabled) {
  2802. next_rptr = ring->wptr + 5 + 4;
  2803. radeon_ring_write(ring, PACKET3(PACKET3_MEM_WRITE, 3));
  2804. radeon_ring_write(ring, ring->next_rptr_gpu_addr & 0xfffffffc);
  2805. radeon_ring_write(ring, (upper_32_bits(ring->next_rptr_gpu_addr) & 0xff) | (1 << 18));
  2806. radeon_ring_write(ring, next_rptr);
  2807. radeon_ring_write(ring, 0);
  2808. }
  2809. radeon_ring_write(ring, PACKET3(PACKET3_INDIRECT_BUFFER, 2));
  2810. radeon_ring_write(ring,
  2811. #ifdef __BIG_ENDIAN
  2812. (2 << 0) |
  2813. #endif
  2814. (ib->gpu_addr & 0xFFFFFFFC));
  2815. radeon_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFF);
  2816. radeon_ring_write(ring, ib->length_dw);
  2817. }
  2818. static int evergreen_cp_load_microcode(struct radeon_device *rdev)
  2819. {
  2820. const __be32 *fw_data;
  2821. int i;
  2822. if (!rdev->me_fw || !rdev->pfp_fw)
  2823. return -EINVAL;
  2824. r700_cp_stop(rdev);
  2825. WREG32(CP_RB_CNTL,
  2826. #ifdef __BIG_ENDIAN
  2827. BUF_SWAP_32BIT |
  2828. #endif
  2829. RB_NO_UPDATE | RB_BLKSZ(15) | RB_BUFSZ(3));
  2830. fw_data = (const __be32 *)rdev->pfp_fw->data;
  2831. WREG32(CP_PFP_UCODE_ADDR, 0);
  2832. for (i = 0; i < EVERGREEN_PFP_UCODE_SIZE; i++)
  2833. WREG32(CP_PFP_UCODE_DATA, be32_to_cpup(fw_data++));
  2834. WREG32(CP_PFP_UCODE_ADDR, 0);
  2835. fw_data = (const __be32 *)rdev->me_fw->data;
  2836. WREG32(CP_ME_RAM_WADDR, 0);
  2837. for (i = 0; i < EVERGREEN_PM4_UCODE_SIZE; i++)
  2838. WREG32(CP_ME_RAM_DATA, be32_to_cpup(fw_data++));
  2839. WREG32(CP_PFP_UCODE_ADDR, 0);
  2840. WREG32(CP_ME_RAM_WADDR, 0);
  2841. WREG32(CP_ME_RAM_RADDR, 0);
  2842. return 0;
  2843. }
  2844. static int evergreen_cp_start(struct radeon_device *rdev)
  2845. {
  2846. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  2847. int r, i;
  2848. uint32_t cp_me;
  2849. r = radeon_ring_lock(rdev, ring, 7);
  2850. if (r) {
  2851. DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
  2852. return r;
  2853. }
  2854. radeon_ring_write(ring, PACKET3(PACKET3_ME_INITIALIZE, 5));
  2855. radeon_ring_write(ring, 0x1);
  2856. radeon_ring_write(ring, 0x0);
  2857. radeon_ring_write(ring, rdev->config.evergreen.max_hw_contexts - 1);
  2858. radeon_ring_write(ring, PACKET3_ME_INITIALIZE_DEVICE_ID(1));
  2859. radeon_ring_write(ring, 0);
  2860. radeon_ring_write(ring, 0);
  2861. radeon_ring_unlock_commit(rdev, ring, false);
  2862. cp_me = 0xff;
  2863. WREG32(CP_ME_CNTL, cp_me);
  2864. r = radeon_ring_lock(rdev, ring, evergreen_default_size + 19);
  2865. if (r) {
  2866. DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
  2867. return r;
  2868. }
  2869. /* setup clear context state */
  2870. radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  2871. radeon_ring_write(ring, PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
  2872. for (i = 0; i < evergreen_default_size; i++)
  2873. radeon_ring_write(ring, evergreen_default_state[i]);
  2874. radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  2875. radeon_ring_write(ring, PACKET3_PREAMBLE_END_CLEAR_STATE);
  2876. /* set clear context state */
  2877. radeon_ring_write(ring, PACKET3(PACKET3_CLEAR_STATE, 0));
  2878. radeon_ring_write(ring, 0);
  2879. /* SQ_VTX_BASE_VTX_LOC */
  2880. radeon_ring_write(ring, 0xc0026f00);
  2881. radeon_ring_write(ring, 0x00000000);
  2882. radeon_ring_write(ring, 0x00000000);
  2883. radeon_ring_write(ring, 0x00000000);
  2884. /* Clear consts */
  2885. radeon_ring_write(ring, 0xc0036f00);
  2886. radeon_ring_write(ring, 0x00000bc4);
  2887. radeon_ring_write(ring, 0xffffffff);
  2888. radeon_ring_write(ring, 0xffffffff);
  2889. radeon_ring_write(ring, 0xffffffff);
  2890. radeon_ring_write(ring, 0xc0026900);
  2891. radeon_ring_write(ring, 0x00000316);
  2892. radeon_ring_write(ring, 0x0000000e); /* VGT_VERTEX_REUSE_BLOCK_CNTL */
  2893. radeon_ring_write(ring, 0x00000010); /* */
  2894. radeon_ring_unlock_commit(rdev, ring, false);
  2895. return 0;
  2896. }
  2897. static int evergreen_cp_resume(struct radeon_device *rdev)
  2898. {
  2899. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  2900. u32 tmp;
  2901. u32 rb_bufsz;
  2902. int r;
  2903. /* Reset cp; if cp is reset, then PA, SH, VGT also need to be reset */
  2904. WREG32(GRBM_SOFT_RESET, (SOFT_RESET_CP |
  2905. SOFT_RESET_PA |
  2906. SOFT_RESET_SH |
  2907. SOFT_RESET_VGT |
  2908. SOFT_RESET_SPI |
  2909. SOFT_RESET_SX));
  2910. RREG32(GRBM_SOFT_RESET);
  2911. mdelay(15);
  2912. WREG32(GRBM_SOFT_RESET, 0);
  2913. RREG32(GRBM_SOFT_RESET);
  2914. /* Set ring buffer size */
  2915. rb_bufsz = order_base_2(ring->ring_size / 8);
  2916. tmp = (order_base_2(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
  2917. #ifdef __BIG_ENDIAN
  2918. tmp |= BUF_SWAP_32BIT;
  2919. #endif
  2920. WREG32(CP_RB_CNTL, tmp);
  2921. WREG32(CP_SEM_WAIT_TIMER, 0x0);
  2922. WREG32(CP_SEM_INCOMPLETE_TIMER_CNTL, 0x0);
  2923. /* Set the write pointer delay */
  2924. WREG32(CP_RB_WPTR_DELAY, 0);
  2925. /* Initialize the ring buffer's read and write pointers */
  2926. WREG32(CP_RB_CNTL, tmp | RB_RPTR_WR_ENA);
  2927. WREG32(CP_RB_RPTR_WR, 0);
  2928. ring->wptr = 0;
  2929. WREG32(CP_RB_WPTR, ring->wptr);
  2930. /* set the wb address whether it's enabled or not */
  2931. WREG32(CP_RB_RPTR_ADDR,
  2932. ((rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFFFFFFFC));
  2933. WREG32(CP_RB_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFF);
  2934. WREG32(SCRATCH_ADDR, ((rdev->wb.gpu_addr + RADEON_WB_SCRATCH_OFFSET) >> 8) & 0xFFFFFFFF);
  2935. if (rdev->wb.enabled)
  2936. WREG32(SCRATCH_UMSK, 0xff);
  2937. else {
  2938. tmp |= RB_NO_UPDATE;
  2939. WREG32(SCRATCH_UMSK, 0);
  2940. }
  2941. mdelay(1);
  2942. WREG32(CP_RB_CNTL, tmp);
  2943. WREG32(CP_RB_BASE, ring->gpu_addr >> 8);
  2944. WREG32(CP_DEBUG, (1 << 27) | (1 << 28));
  2945. evergreen_cp_start(rdev);
  2946. ring->ready = true;
  2947. r = radeon_ring_test(rdev, RADEON_RING_TYPE_GFX_INDEX, ring);
  2948. if (r) {
  2949. ring->ready = false;
  2950. return r;
  2951. }
  2952. return 0;
  2953. }
  2954. /*
  2955. * Core functions
  2956. */
  2957. static void evergreen_gpu_init(struct radeon_device *rdev)
  2958. {
  2959. u32 gb_addr_config;
  2960. u32 mc_shared_chmap, mc_arb_ramcfg;
  2961. u32 sx_debug_1;
  2962. u32 smx_dc_ctl0;
  2963. u32 sq_config;
  2964. u32 sq_lds_resource_mgmt;
  2965. u32 sq_gpr_resource_mgmt_1;
  2966. u32 sq_gpr_resource_mgmt_2;
  2967. u32 sq_gpr_resource_mgmt_3;
  2968. u32 sq_thread_resource_mgmt;
  2969. u32 sq_thread_resource_mgmt_2;
  2970. u32 sq_stack_resource_mgmt_1;
  2971. u32 sq_stack_resource_mgmt_2;
  2972. u32 sq_stack_resource_mgmt_3;
  2973. u32 vgt_cache_invalidation;
  2974. u32 hdp_host_path_cntl, tmp;
  2975. u32 disabled_rb_mask;
  2976. int i, j, ps_thread_count;
  2977. switch (rdev->family) {
  2978. case CHIP_CYPRESS:
  2979. case CHIP_HEMLOCK:
  2980. rdev->config.evergreen.num_ses = 2;
  2981. rdev->config.evergreen.max_pipes = 4;
  2982. rdev->config.evergreen.max_tile_pipes = 8;
  2983. rdev->config.evergreen.max_simds = 10;
  2984. rdev->config.evergreen.max_backends = 4 * rdev->config.evergreen.num_ses;
  2985. rdev->config.evergreen.max_gprs = 256;
  2986. rdev->config.evergreen.max_threads = 248;
  2987. rdev->config.evergreen.max_gs_threads = 32;
  2988. rdev->config.evergreen.max_stack_entries = 512;
  2989. rdev->config.evergreen.sx_num_of_sets = 4;
  2990. rdev->config.evergreen.sx_max_export_size = 256;
  2991. rdev->config.evergreen.sx_max_export_pos_size = 64;
  2992. rdev->config.evergreen.sx_max_export_smx_size = 192;
  2993. rdev->config.evergreen.max_hw_contexts = 8;
  2994. rdev->config.evergreen.sq_num_cf_insts = 2;
  2995. rdev->config.evergreen.sc_prim_fifo_size = 0x100;
  2996. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  2997. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  2998. gb_addr_config = CYPRESS_GB_ADDR_CONFIG_GOLDEN;
  2999. break;
  3000. case CHIP_JUNIPER:
  3001. rdev->config.evergreen.num_ses = 1;
  3002. rdev->config.evergreen.max_pipes = 4;
  3003. rdev->config.evergreen.max_tile_pipes = 4;
  3004. rdev->config.evergreen.max_simds = 10;
  3005. rdev->config.evergreen.max_backends = 4 * rdev->config.evergreen.num_ses;
  3006. rdev->config.evergreen.max_gprs = 256;
  3007. rdev->config.evergreen.max_threads = 248;
  3008. rdev->config.evergreen.max_gs_threads = 32;
  3009. rdev->config.evergreen.max_stack_entries = 512;
  3010. rdev->config.evergreen.sx_num_of_sets = 4;
  3011. rdev->config.evergreen.sx_max_export_size = 256;
  3012. rdev->config.evergreen.sx_max_export_pos_size = 64;
  3013. rdev->config.evergreen.sx_max_export_smx_size = 192;
  3014. rdev->config.evergreen.max_hw_contexts = 8;
  3015. rdev->config.evergreen.sq_num_cf_insts = 2;
  3016. rdev->config.evergreen.sc_prim_fifo_size = 0x100;
  3017. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  3018. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  3019. gb_addr_config = JUNIPER_GB_ADDR_CONFIG_GOLDEN;
  3020. break;
  3021. case CHIP_REDWOOD:
  3022. rdev->config.evergreen.num_ses = 1;
  3023. rdev->config.evergreen.max_pipes = 4;
  3024. rdev->config.evergreen.max_tile_pipes = 4;
  3025. rdev->config.evergreen.max_simds = 5;
  3026. rdev->config.evergreen.max_backends = 2 * rdev->config.evergreen.num_ses;
  3027. rdev->config.evergreen.max_gprs = 256;
  3028. rdev->config.evergreen.max_threads = 248;
  3029. rdev->config.evergreen.max_gs_threads = 32;
  3030. rdev->config.evergreen.max_stack_entries = 256;
  3031. rdev->config.evergreen.sx_num_of_sets = 4;
  3032. rdev->config.evergreen.sx_max_export_size = 256;
  3033. rdev->config.evergreen.sx_max_export_pos_size = 64;
  3034. rdev->config.evergreen.sx_max_export_smx_size = 192;
  3035. rdev->config.evergreen.max_hw_contexts = 8;
  3036. rdev->config.evergreen.sq_num_cf_insts = 2;
  3037. rdev->config.evergreen.sc_prim_fifo_size = 0x100;
  3038. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  3039. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  3040. gb_addr_config = REDWOOD_GB_ADDR_CONFIG_GOLDEN;
  3041. break;
  3042. case CHIP_CEDAR:
  3043. default:
  3044. rdev->config.evergreen.num_ses = 1;
  3045. rdev->config.evergreen.max_pipes = 2;
  3046. rdev->config.evergreen.max_tile_pipes = 2;
  3047. rdev->config.evergreen.max_simds = 2;
  3048. rdev->config.evergreen.max_backends = 1 * rdev->config.evergreen.num_ses;
  3049. rdev->config.evergreen.max_gprs = 256;
  3050. rdev->config.evergreen.max_threads = 192;
  3051. rdev->config.evergreen.max_gs_threads = 16;
  3052. rdev->config.evergreen.max_stack_entries = 256;
  3053. rdev->config.evergreen.sx_num_of_sets = 4;
  3054. rdev->config.evergreen.sx_max_export_size = 128;
  3055. rdev->config.evergreen.sx_max_export_pos_size = 32;
  3056. rdev->config.evergreen.sx_max_export_smx_size = 96;
  3057. rdev->config.evergreen.max_hw_contexts = 4;
  3058. rdev->config.evergreen.sq_num_cf_insts = 1;
  3059. rdev->config.evergreen.sc_prim_fifo_size = 0x40;
  3060. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  3061. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  3062. gb_addr_config = CEDAR_GB_ADDR_CONFIG_GOLDEN;
  3063. break;
  3064. case CHIP_PALM:
  3065. rdev->config.evergreen.num_ses = 1;
  3066. rdev->config.evergreen.max_pipes = 2;
  3067. rdev->config.evergreen.max_tile_pipes = 2;
  3068. rdev->config.evergreen.max_simds = 2;
  3069. rdev->config.evergreen.max_backends = 1 * rdev->config.evergreen.num_ses;
  3070. rdev->config.evergreen.max_gprs = 256;
  3071. rdev->config.evergreen.max_threads = 192;
  3072. rdev->config.evergreen.max_gs_threads = 16;
  3073. rdev->config.evergreen.max_stack_entries = 256;
  3074. rdev->config.evergreen.sx_num_of_sets = 4;
  3075. rdev->config.evergreen.sx_max_export_size = 128;
  3076. rdev->config.evergreen.sx_max_export_pos_size = 32;
  3077. rdev->config.evergreen.sx_max_export_smx_size = 96;
  3078. rdev->config.evergreen.max_hw_contexts = 4;
  3079. rdev->config.evergreen.sq_num_cf_insts = 1;
  3080. rdev->config.evergreen.sc_prim_fifo_size = 0x40;
  3081. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  3082. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  3083. gb_addr_config = CEDAR_GB_ADDR_CONFIG_GOLDEN;
  3084. break;
  3085. case CHIP_SUMO:
  3086. rdev->config.evergreen.num_ses = 1;
  3087. rdev->config.evergreen.max_pipes = 4;
  3088. rdev->config.evergreen.max_tile_pipes = 4;
  3089. if (rdev->pdev->device == 0x9648)
  3090. rdev->config.evergreen.max_simds = 3;
  3091. else if ((rdev->pdev->device == 0x9647) ||
  3092. (rdev->pdev->device == 0x964a))
  3093. rdev->config.evergreen.max_simds = 4;
  3094. else
  3095. rdev->config.evergreen.max_simds = 5;
  3096. rdev->config.evergreen.max_backends = 2 * rdev->config.evergreen.num_ses;
  3097. rdev->config.evergreen.max_gprs = 256;
  3098. rdev->config.evergreen.max_threads = 248;
  3099. rdev->config.evergreen.max_gs_threads = 32;
  3100. rdev->config.evergreen.max_stack_entries = 256;
  3101. rdev->config.evergreen.sx_num_of_sets = 4;
  3102. rdev->config.evergreen.sx_max_export_size = 256;
  3103. rdev->config.evergreen.sx_max_export_pos_size = 64;
  3104. rdev->config.evergreen.sx_max_export_smx_size = 192;
  3105. rdev->config.evergreen.max_hw_contexts = 8;
  3106. rdev->config.evergreen.sq_num_cf_insts = 2;
  3107. rdev->config.evergreen.sc_prim_fifo_size = 0x40;
  3108. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  3109. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  3110. gb_addr_config = SUMO_GB_ADDR_CONFIG_GOLDEN;
  3111. break;
  3112. case CHIP_SUMO2:
  3113. rdev->config.evergreen.num_ses = 1;
  3114. rdev->config.evergreen.max_pipes = 4;
  3115. rdev->config.evergreen.max_tile_pipes = 4;
  3116. rdev->config.evergreen.max_simds = 2;
  3117. rdev->config.evergreen.max_backends = 1 * rdev->config.evergreen.num_ses;
  3118. rdev->config.evergreen.max_gprs = 256;
  3119. rdev->config.evergreen.max_threads = 248;
  3120. rdev->config.evergreen.max_gs_threads = 32;
  3121. rdev->config.evergreen.max_stack_entries = 512;
  3122. rdev->config.evergreen.sx_num_of_sets = 4;
  3123. rdev->config.evergreen.sx_max_export_size = 256;
  3124. rdev->config.evergreen.sx_max_export_pos_size = 64;
  3125. rdev->config.evergreen.sx_max_export_smx_size = 192;
  3126. rdev->config.evergreen.max_hw_contexts = 4;
  3127. rdev->config.evergreen.sq_num_cf_insts = 2;
  3128. rdev->config.evergreen.sc_prim_fifo_size = 0x40;
  3129. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  3130. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  3131. gb_addr_config = SUMO2_GB_ADDR_CONFIG_GOLDEN;
  3132. break;
  3133. case CHIP_BARTS:
  3134. rdev->config.evergreen.num_ses = 2;
  3135. rdev->config.evergreen.max_pipes = 4;
  3136. rdev->config.evergreen.max_tile_pipes = 8;
  3137. rdev->config.evergreen.max_simds = 7;
  3138. rdev->config.evergreen.max_backends = 4 * rdev->config.evergreen.num_ses;
  3139. rdev->config.evergreen.max_gprs = 256;
  3140. rdev->config.evergreen.max_threads = 248;
  3141. rdev->config.evergreen.max_gs_threads = 32;
  3142. rdev->config.evergreen.max_stack_entries = 512;
  3143. rdev->config.evergreen.sx_num_of_sets = 4;
  3144. rdev->config.evergreen.sx_max_export_size = 256;
  3145. rdev->config.evergreen.sx_max_export_pos_size = 64;
  3146. rdev->config.evergreen.sx_max_export_smx_size = 192;
  3147. rdev->config.evergreen.max_hw_contexts = 8;
  3148. rdev->config.evergreen.sq_num_cf_insts = 2;
  3149. rdev->config.evergreen.sc_prim_fifo_size = 0x100;
  3150. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  3151. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  3152. gb_addr_config = BARTS_GB_ADDR_CONFIG_GOLDEN;
  3153. break;
  3154. case CHIP_TURKS:
  3155. rdev->config.evergreen.num_ses = 1;
  3156. rdev->config.evergreen.max_pipes = 4;
  3157. rdev->config.evergreen.max_tile_pipes = 4;
  3158. rdev->config.evergreen.max_simds = 6;
  3159. rdev->config.evergreen.max_backends = 2 * rdev->config.evergreen.num_ses;
  3160. rdev->config.evergreen.max_gprs = 256;
  3161. rdev->config.evergreen.max_threads = 248;
  3162. rdev->config.evergreen.max_gs_threads = 32;
  3163. rdev->config.evergreen.max_stack_entries = 256;
  3164. rdev->config.evergreen.sx_num_of_sets = 4;
  3165. rdev->config.evergreen.sx_max_export_size = 256;
  3166. rdev->config.evergreen.sx_max_export_pos_size = 64;
  3167. rdev->config.evergreen.sx_max_export_smx_size = 192;
  3168. rdev->config.evergreen.max_hw_contexts = 8;
  3169. rdev->config.evergreen.sq_num_cf_insts = 2;
  3170. rdev->config.evergreen.sc_prim_fifo_size = 0x100;
  3171. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  3172. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  3173. gb_addr_config = TURKS_GB_ADDR_CONFIG_GOLDEN;
  3174. break;
  3175. case CHIP_CAICOS:
  3176. rdev->config.evergreen.num_ses = 1;
  3177. rdev->config.evergreen.max_pipes = 2;
  3178. rdev->config.evergreen.max_tile_pipes = 2;
  3179. rdev->config.evergreen.max_simds = 2;
  3180. rdev->config.evergreen.max_backends = 1 * rdev->config.evergreen.num_ses;
  3181. rdev->config.evergreen.max_gprs = 256;
  3182. rdev->config.evergreen.max_threads = 192;
  3183. rdev->config.evergreen.max_gs_threads = 16;
  3184. rdev->config.evergreen.max_stack_entries = 256;
  3185. rdev->config.evergreen.sx_num_of_sets = 4;
  3186. rdev->config.evergreen.sx_max_export_size = 128;
  3187. rdev->config.evergreen.sx_max_export_pos_size = 32;
  3188. rdev->config.evergreen.sx_max_export_smx_size = 96;
  3189. rdev->config.evergreen.max_hw_contexts = 4;
  3190. rdev->config.evergreen.sq_num_cf_insts = 1;
  3191. rdev->config.evergreen.sc_prim_fifo_size = 0x40;
  3192. rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
  3193. rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
  3194. gb_addr_config = CAICOS_GB_ADDR_CONFIG_GOLDEN;
  3195. break;
  3196. }
  3197. /* Initialize HDP */
  3198. for (i = 0, j = 0; i < 32; i++, j += 0x18) {
  3199. WREG32((0x2c14 + j), 0x00000000);
  3200. WREG32((0x2c18 + j), 0x00000000);
  3201. WREG32((0x2c1c + j), 0x00000000);
  3202. WREG32((0x2c20 + j), 0x00000000);
  3203. WREG32((0x2c24 + j), 0x00000000);
  3204. }
  3205. WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
  3206. WREG32(SRBM_INT_CNTL, 0x1);
  3207. WREG32(SRBM_INT_ACK, 0x1);
  3208. evergreen_fix_pci_max_read_req_size(rdev);
  3209. mc_shared_chmap = RREG32(MC_SHARED_CHMAP);
  3210. if ((rdev->family == CHIP_PALM) ||
  3211. (rdev->family == CHIP_SUMO) ||
  3212. (rdev->family == CHIP_SUMO2))
  3213. mc_arb_ramcfg = RREG32(FUS_MC_ARB_RAMCFG);
  3214. else
  3215. mc_arb_ramcfg = RREG32(MC_ARB_RAMCFG);
  3216. /* setup tiling info dword. gb_addr_config is not adequate since it does
  3217. * not have bank info, so create a custom tiling dword.
  3218. * bits 3:0 num_pipes
  3219. * bits 7:4 num_banks
  3220. * bits 11:8 group_size
  3221. * bits 15:12 row_size
  3222. */
  3223. rdev->config.evergreen.tile_config = 0;
  3224. switch (rdev->config.evergreen.max_tile_pipes) {
  3225. case 1:
  3226. default:
  3227. rdev->config.evergreen.tile_config |= (0 << 0);
  3228. break;
  3229. case 2:
  3230. rdev->config.evergreen.tile_config |= (1 << 0);
  3231. break;
  3232. case 4:
  3233. rdev->config.evergreen.tile_config |= (2 << 0);
  3234. break;
  3235. case 8:
  3236. rdev->config.evergreen.tile_config |= (3 << 0);
  3237. break;
  3238. }
  3239. /* num banks is 8 on all fusion asics. 0 = 4, 1 = 8, 2 = 16 */
  3240. if (rdev->flags & RADEON_IS_IGP)
  3241. rdev->config.evergreen.tile_config |= 1 << 4;
  3242. else {
  3243. switch ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT) {
  3244. case 0: /* four banks */
  3245. rdev->config.evergreen.tile_config |= 0 << 4;
  3246. break;
  3247. case 1: /* eight banks */
  3248. rdev->config.evergreen.tile_config |= 1 << 4;
  3249. break;
  3250. case 2: /* sixteen banks */
  3251. default:
  3252. rdev->config.evergreen.tile_config |= 2 << 4;
  3253. break;
  3254. }
  3255. }
  3256. rdev->config.evergreen.tile_config |= 0 << 8;
  3257. rdev->config.evergreen.tile_config |=
  3258. ((gb_addr_config & 0x30000000) >> 28) << 12;
  3259. if ((rdev->family >= CHIP_CEDAR) && (rdev->family <= CHIP_HEMLOCK)) {
  3260. u32 efuse_straps_4;
  3261. u32 efuse_straps_3;
  3262. efuse_straps_4 = RREG32_RCU(0x204);
  3263. efuse_straps_3 = RREG32_RCU(0x203);
  3264. tmp = (((efuse_straps_4 & 0xf) << 4) |
  3265. ((efuse_straps_3 & 0xf0000000) >> 28));
  3266. } else {
  3267. tmp = 0;
  3268. for (i = (rdev->config.evergreen.num_ses - 1); i >= 0; i--) {
  3269. u32 rb_disable_bitmap;
  3270. WREG32(GRBM_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_INDEX(i));
  3271. WREG32(RLC_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_INDEX(i));
  3272. rb_disable_bitmap = (RREG32(CC_RB_BACKEND_DISABLE) & 0x00ff0000) >> 16;
  3273. tmp <<= 4;
  3274. tmp |= rb_disable_bitmap;
  3275. }
  3276. }
  3277. /* enabled rb are just the one not disabled :) */
  3278. disabled_rb_mask = tmp;
  3279. tmp = 0;
  3280. for (i = 0; i < rdev->config.evergreen.max_backends; i++)
  3281. tmp |= (1 << i);
  3282. /* if all the backends are disabled, fix it up here */
  3283. if ((disabled_rb_mask & tmp) == tmp) {
  3284. for (i = 0; i < rdev->config.evergreen.max_backends; i++)
  3285. disabled_rb_mask &= ~(1 << i);
  3286. }
  3287. for (i = 0; i < rdev->config.evergreen.num_ses; i++) {
  3288. u32 simd_disable_bitmap;
  3289. WREG32(GRBM_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_INDEX(i));
  3290. WREG32(RLC_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_INDEX(i));
  3291. simd_disable_bitmap = (RREG32(CC_GC_SHADER_PIPE_CONFIG) & 0xffff0000) >> 16;
  3292. simd_disable_bitmap |= 0xffffffff << rdev->config.evergreen.max_simds;
  3293. tmp <<= 16;
  3294. tmp |= simd_disable_bitmap;
  3295. }
  3296. rdev->config.evergreen.active_simds = hweight32(~tmp);
  3297. WREG32(GRBM_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_BROADCAST_WRITES);
  3298. WREG32(RLC_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_BROADCAST_WRITES);
  3299. WREG32(GB_ADDR_CONFIG, gb_addr_config);
  3300. WREG32(DMIF_ADDR_CONFIG, gb_addr_config);
  3301. WREG32(HDP_ADDR_CONFIG, gb_addr_config);
  3302. WREG32(DMA_TILING_CONFIG, gb_addr_config);
  3303. WREG32(UVD_UDEC_ADDR_CONFIG, gb_addr_config);
  3304. WREG32(UVD_UDEC_DB_ADDR_CONFIG, gb_addr_config);
  3305. WREG32(UVD_UDEC_DBW_ADDR_CONFIG, gb_addr_config);
  3306. if ((rdev->config.evergreen.max_backends == 1) &&
  3307. (rdev->flags & RADEON_IS_IGP)) {
  3308. if ((disabled_rb_mask & 3) == 1) {
  3309. /* RB0 disabled, RB1 enabled */
  3310. tmp = 0x11111111;
  3311. } else {
  3312. /* RB1 disabled, RB0 enabled */
  3313. tmp = 0x00000000;
  3314. }
  3315. } else {
  3316. tmp = gb_addr_config & NUM_PIPES_MASK;
  3317. tmp = r6xx_remap_render_backend(rdev, tmp, rdev->config.evergreen.max_backends,
  3318. EVERGREEN_MAX_BACKENDS, disabled_rb_mask);
  3319. }
  3320. WREG32(GB_BACKEND_MAP, tmp);
  3321. WREG32(CGTS_SYS_TCC_DISABLE, 0);
  3322. WREG32(CGTS_TCC_DISABLE, 0);
  3323. WREG32(CGTS_USER_SYS_TCC_DISABLE, 0);
  3324. WREG32(CGTS_USER_TCC_DISABLE, 0);
  3325. /* set HW defaults for 3D engine */
  3326. WREG32(CP_QUEUE_THRESHOLDS, (ROQ_IB1_START(0x16) |
  3327. ROQ_IB2_START(0x2b)));
  3328. WREG32(CP_MEQ_THRESHOLDS, STQ_SPLIT(0x30));
  3329. WREG32(TA_CNTL_AUX, (DISABLE_CUBE_ANISO |
  3330. SYNC_GRADIENT |
  3331. SYNC_WALKER |
  3332. SYNC_ALIGNER));
  3333. sx_debug_1 = RREG32(SX_DEBUG_1);
  3334. sx_debug_1 |= ENABLE_NEW_SMX_ADDRESS;
  3335. WREG32(SX_DEBUG_1, sx_debug_1);
  3336. smx_dc_ctl0 = RREG32(SMX_DC_CTL0);
  3337. smx_dc_ctl0 &= ~NUMBER_OF_SETS(0x1ff);
  3338. smx_dc_ctl0 |= NUMBER_OF_SETS(rdev->config.evergreen.sx_num_of_sets);
  3339. WREG32(SMX_DC_CTL0, smx_dc_ctl0);
  3340. if (rdev->family <= CHIP_SUMO2)
  3341. WREG32(SMX_SAR_CTL0, 0x00010000);
  3342. WREG32(SX_EXPORT_BUFFER_SIZES, (COLOR_BUFFER_SIZE((rdev->config.evergreen.sx_max_export_size / 4) - 1) |
  3343. POSITION_BUFFER_SIZE((rdev->config.evergreen.sx_max_export_pos_size / 4) - 1) |
  3344. SMX_BUFFER_SIZE((rdev->config.evergreen.sx_max_export_smx_size / 4) - 1)));
  3345. WREG32(PA_SC_FIFO_SIZE, (SC_PRIM_FIFO_SIZE(rdev->config.evergreen.sc_prim_fifo_size) |
  3346. SC_HIZ_TILE_FIFO_SIZE(rdev->config.evergreen.sc_hiz_tile_fifo_size) |
  3347. SC_EARLYZ_TILE_FIFO_SIZE(rdev->config.evergreen.sc_earlyz_tile_fifo_size)));
  3348. WREG32(VGT_NUM_INSTANCES, 1);
  3349. WREG32(SPI_CONFIG_CNTL, 0);
  3350. WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(4));
  3351. WREG32(CP_PERFMON_CNTL, 0);
  3352. WREG32(SQ_MS_FIFO_SIZES, (CACHE_FIFO_SIZE(16 * rdev->config.evergreen.sq_num_cf_insts) |
  3353. FETCH_FIFO_HIWATER(0x4) |
  3354. DONE_FIFO_HIWATER(0xe0) |
  3355. ALU_UPDATE_FIFO_HIWATER(0x8)));
  3356. sq_config = RREG32(SQ_CONFIG);
  3357. sq_config &= ~(PS_PRIO(3) |
  3358. VS_PRIO(3) |
  3359. GS_PRIO(3) |
  3360. ES_PRIO(3));
  3361. sq_config |= (VC_ENABLE |
  3362. EXPORT_SRC_C |
  3363. PS_PRIO(0) |
  3364. VS_PRIO(1) |
  3365. GS_PRIO(2) |
  3366. ES_PRIO(3));
  3367. switch (rdev->family) {
  3368. case CHIP_CEDAR:
  3369. case CHIP_PALM:
  3370. case CHIP_SUMO:
  3371. case CHIP_SUMO2:
  3372. case CHIP_CAICOS:
  3373. /* no vertex cache */
  3374. sq_config &= ~VC_ENABLE;
  3375. break;
  3376. default:
  3377. break;
  3378. }
  3379. sq_lds_resource_mgmt = RREG32(SQ_LDS_RESOURCE_MGMT);
  3380. sq_gpr_resource_mgmt_1 = NUM_PS_GPRS((rdev->config.evergreen.max_gprs - (4 * 2))* 12 / 32);
  3381. sq_gpr_resource_mgmt_1 |= NUM_VS_GPRS((rdev->config.evergreen.max_gprs - (4 * 2)) * 6 / 32);
  3382. sq_gpr_resource_mgmt_1 |= NUM_CLAUSE_TEMP_GPRS(4);
  3383. sq_gpr_resource_mgmt_2 = NUM_GS_GPRS((rdev->config.evergreen.max_gprs - (4 * 2)) * 4 / 32);
  3384. sq_gpr_resource_mgmt_2 |= NUM_ES_GPRS((rdev->config.evergreen.max_gprs - (4 * 2)) * 4 / 32);
  3385. sq_gpr_resource_mgmt_3 = NUM_HS_GPRS((rdev->config.evergreen.max_gprs - (4 * 2)) * 3 / 32);
  3386. sq_gpr_resource_mgmt_3 |= NUM_LS_GPRS((rdev->config.evergreen.max_gprs - (4 * 2)) * 3 / 32);
  3387. switch (rdev->family) {
  3388. case CHIP_CEDAR:
  3389. case CHIP_PALM:
  3390. case CHIP_SUMO:
  3391. case CHIP_SUMO2:
  3392. ps_thread_count = 96;
  3393. break;
  3394. default:
  3395. ps_thread_count = 128;
  3396. break;
  3397. }
  3398. sq_thread_resource_mgmt = NUM_PS_THREADS(ps_thread_count);
  3399. sq_thread_resource_mgmt |= NUM_VS_THREADS((((rdev->config.evergreen.max_threads - ps_thread_count) / 6) / 8) * 8);
  3400. sq_thread_resource_mgmt |= NUM_GS_THREADS((((rdev->config.evergreen.max_threads - ps_thread_count) / 6) / 8) * 8);
  3401. sq_thread_resource_mgmt |= NUM_ES_THREADS((((rdev->config.evergreen.max_threads - ps_thread_count) / 6) / 8) * 8);
  3402. sq_thread_resource_mgmt_2 = NUM_HS_THREADS((((rdev->config.evergreen.max_threads - ps_thread_count) / 6) / 8) * 8);
  3403. sq_thread_resource_mgmt_2 |= NUM_LS_THREADS((((rdev->config.evergreen.max_threads - ps_thread_count) / 6) / 8) * 8);
  3404. sq_stack_resource_mgmt_1 = NUM_PS_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6);
  3405. sq_stack_resource_mgmt_1 |= NUM_VS_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6);
  3406. sq_stack_resource_mgmt_2 = NUM_GS_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6);
  3407. sq_stack_resource_mgmt_2 |= NUM_ES_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6);
  3408. sq_stack_resource_mgmt_3 = NUM_HS_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6);
  3409. sq_stack_resource_mgmt_3 |= NUM_LS_STACK_ENTRIES((rdev->config.evergreen.max_stack_entries * 1) / 6);
  3410. WREG32(SQ_CONFIG, sq_config);
  3411. WREG32(SQ_GPR_RESOURCE_MGMT_1, sq_gpr_resource_mgmt_1);
  3412. WREG32(SQ_GPR_RESOURCE_MGMT_2, sq_gpr_resource_mgmt_2);
  3413. WREG32(SQ_GPR_RESOURCE_MGMT_3, sq_gpr_resource_mgmt_3);
  3414. WREG32(SQ_THREAD_RESOURCE_MGMT, sq_thread_resource_mgmt);
  3415. WREG32(SQ_THREAD_RESOURCE_MGMT_2, sq_thread_resource_mgmt_2);
  3416. WREG32(SQ_STACK_RESOURCE_MGMT_1, sq_stack_resource_mgmt_1);
  3417. WREG32(SQ_STACK_RESOURCE_MGMT_2, sq_stack_resource_mgmt_2);
  3418. WREG32(SQ_STACK_RESOURCE_MGMT_3, sq_stack_resource_mgmt_3);
  3419. WREG32(SQ_DYN_GPR_CNTL_PS_FLUSH_REQ, 0);
  3420. WREG32(SQ_LDS_RESOURCE_MGMT, sq_lds_resource_mgmt);
  3421. WREG32(PA_SC_FORCE_EOV_MAX_CNTS, (FORCE_EOV_MAX_CLK_CNT(4095) |
  3422. FORCE_EOV_MAX_REZ_CNT(255)));
  3423. switch (rdev->family) {
  3424. case CHIP_CEDAR:
  3425. case CHIP_PALM:
  3426. case CHIP_SUMO:
  3427. case CHIP_SUMO2:
  3428. case CHIP_CAICOS:
  3429. vgt_cache_invalidation = CACHE_INVALIDATION(TC_ONLY);
  3430. break;
  3431. default:
  3432. vgt_cache_invalidation = CACHE_INVALIDATION(VC_AND_TC);
  3433. break;
  3434. }
  3435. vgt_cache_invalidation |= AUTO_INVLD_EN(ES_AND_GS_AUTO);
  3436. WREG32(VGT_CACHE_INVALIDATION, vgt_cache_invalidation);
  3437. WREG32(VGT_GS_VERTEX_REUSE, 16);
  3438. WREG32(PA_SU_LINE_STIPPLE_VALUE, 0);
  3439. WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
  3440. WREG32(VGT_VERTEX_REUSE_BLOCK_CNTL, 14);
  3441. WREG32(VGT_OUT_DEALLOC_CNTL, 16);
  3442. WREG32(CB_PERF_CTR0_SEL_0, 0);
  3443. WREG32(CB_PERF_CTR0_SEL_1, 0);
  3444. WREG32(CB_PERF_CTR1_SEL_0, 0);
  3445. WREG32(CB_PERF_CTR1_SEL_1, 0);
  3446. WREG32(CB_PERF_CTR2_SEL_0, 0);
  3447. WREG32(CB_PERF_CTR2_SEL_1, 0);
  3448. WREG32(CB_PERF_CTR3_SEL_0, 0);
  3449. WREG32(CB_PERF_CTR3_SEL_1, 0);
  3450. /* clear render buffer base addresses */
  3451. WREG32(CB_COLOR0_BASE, 0);
  3452. WREG32(CB_COLOR1_BASE, 0);
  3453. WREG32(CB_COLOR2_BASE, 0);
  3454. WREG32(CB_COLOR3_BASE, 0);
  3455. WREG32(CB_COLOR4_BASE, 0);
  3456. WREG32(CB_COLOR5_BASE, 0);
  3457. WREG32(CB_COLOR6_BASE, 0);
  3458. WREG32(CB_COLOR7_BASE, 0);
  3459. WREG32(CB_COLOR8_BASE, 0);
  3460. WREG32(CB_COLOR9_BASE, 0);
  3461. WREG32(CB_COLOR10_BASE, 0);
  3462. WREG32(CB_COLOR11_BASE, 0);
  3463. /* set the shader const cache sizes to 0 */
  3464. for (i = SQ_ALU_CONST_BUFFER_SIZE_PS_0; i < 0x28200; i += 4)
  3465. WREG32(i, 0);
  3466. for (i = SQ_ALU_CONST_BUFFER_SIZE_HS_0; i < 0x29000; i += 4)
  3467. WREG32(i, 0);
  3468. tmp = RREG32(HDP_MISC_CNTL);
  3469. tmp |= HDP_FLUSH_INVALIDATE_CACHE;
  3470. WREG32(HDP_MISC_CNTL, tmp);
  3471. hdp_host_path_cntl = RREG32(HDP_HOST_PATH_CNTL);
  3472. WREG32(HDP_HOST_PATH_CNTL, hdp_host_path_cntl);
  3473. WREG32(PA_CL_ENHANCE, CLIP_VTX_REORDER_ENA | NUM_CLIP_SEQ(3));
  3474. udelay(50);
  3475. }
  3476. int evergreen_mc_init(struct radeon_device *rdev)
  3477. {
  3478. u32 tmp;
  3479. int chansize, numchan;
  3480. /* Get VRAM informations */
  3481. rdev->mc.vram_is_ddr = true;
  3482. if ((rdev->family == CHIP_PALM) ||
  3483. (rdev->family == CHIP_SUMO) ||
  3484. (rdev->family == CHIP_SUMO2))
  3485. tmp = RREG32(FUS_MC_ARB_RAMCFG);
  3486. else
  3487. tmp = RREG32(MC_ARB_RAMCFG);
  3488. if (tmp & CHANSIZE_OVERRIDE) {
  3489. chansize = 16;
  3490. } else if (tmp & CHANSIZE_MASK) {
  3491. chansize = 64;
  3492. } else {
  3493. chansize = 32;
  3494. }
  3495. tmp = RREG32(MC_SHARED_CHMAP);
  3496. switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
  3497. case 0:
  3498. default:
  3499. numchan = 1;
  3500. break;
  3501. case 1:
  3502. numchan = 2;
  3503. break;
  3504. case 2:
  3505. numchan = 4;
  3506. break;
  3507. case 3:
  3508. numchan = 8;
  3509. break;
  3510. }
  3511. rdev->mc.vram_width = numchan * chansize;
  3512. /* Could aper size report 0 ? */
  3513. rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
  3514. rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
  3515. /* Setup GPU memory space */
  3516. if ((rdev->family == CHIP_PALM) ||
  3517. (rdev->family == CHIP_SUMO) ||
  3518. (rdev->family == CHIP_SUMO2)) {
  3519. /* size in bytes on fusion */
  3520. rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE);
  3521. rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE);
  3522. } else {
  3523. /* size in MB on evergreen/cayman/tn */
  3524. rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE) * 1024ULL * 1024ULL;
  3525. rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE) * 1024ULL * 1024ULL;
  3526. }
  3527. rdev->mc.visible_vram_size = rdev->mc.aper_size;
  3528. r700_vram_gtt_location(rdev, &rdev->mc);
  3529. radeon_update_bandwidth_info(rdev);
  3530. return 0;
  3531. }
  3532. void evergreen_print_gpu_status_regs(struct radeon_device *rdev)
  3533. {
  3534. dev_info(rdev->dev, " GRBM_STATUS = 0x%08X\n",
  3535. RREG32(GRBM_STATUS));
  3536. dev_info(rdev->dev, " GRBM_STATUS_SE0 = 0x%08X\n",
  3537. RREG32(GRBM_STATUS_SE0));
  3538. dev_info(rdev->dev, " GRBM_STATUS_SE1 = 0x%08X\n",
  3539. RREG32(GRBM_STATUS_SE1));
  3540. dev_info(rdev->dev, " SRBM_STATUS = 0x%08X\n",
  3541. RREG32(SRBM_STATUS));
  3542. dev_info(rdev->dev, " SRBM_STATUS2 = 0x%08X\n",
  3543. RREG32(SRBM_STATUS2));
  3544. dev_info(rdev->dev, " R_008674_CP_STALLED_STAT1 = 0x%08X\n",
  3545. RREG32(CP_STALLED_STAT1));
  3546. dev_info(rdev->dev, " R_008678_CP_STALLED_STAT2 = 0x%08X\n",
  3547. RREG32(CP_STALLED_STAT2));
  3548. dev_info(rdev->dev, " R_00867C_CP_BUSY_STAT = 0x%08X\n",
  3549. RREG32(CP_BUSY_STAT));
  3550. dev_info(rdev->dev, " R_008680_CP_STAT = 0x%08X\n",
  3551. RREG32(CP_STAT));
  3552. dev_info(rdev->dev, " R_00D034_DMA_STATUS_REG = 0x%08X\n",
  3553. RREG32(DMA_STATUS_REG));
  3554. if (rdev->family >= CHIP_CAYMAN) {
  3555. dev_info(rdev->dev, " R_00D834_DMA_STATUS_REG = 0x%08X\n",
  3556. RREG32(DMA_STATUS_REG + 0x800));
  3557. }
  3558. }
  3559. bool evergreen_is_display_hung(struct radeon_device *rdev)
  3560. {
  3561. u32 crtc_hung = 0;
  3562. u32 crtc_status[6];
  3563. u32 i, j, tmp;
  3564. for (i = 0; i < rdev->num_crtc; i++) {
  3565. if (RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i]) & EVERGREEN_CRTC_MASTER_EN) {
  3566. crtc_status[i] = RREG32(EVERGREEN_CRTC_STATUS_HV_COUNT + crtc_offsets[i]);
  3567. crtc_hung |= (1 << i);
  3568. }
  3569. }
  3570. for (j = 0; j < 10; j++) {
  3571. for (i = 0; i < rdev->num_crtc; i++) {
  3572. if (crtc_hung & (1 << i)) {
  3573. tmp = RREG32(EVERGREEN_CRTC_STATUS_HV_COUNT + crtc_offsets[i]);
  3574. if (tmp != crtc_status[i])
  3575. crtc_hung &= ~(1 << i);
  3576. }
  3577. }
  3578. if (crtc_hung == 0)
  3579. return false;
  3580. udelay(100);
  3581. }
  3582. return true;
  3583. }
  3584. u32 evergreen_gpu_check_soft_reset(struct radeon_device *rdev)
  3585. {
  3586. u32 reset_mask = 0;
  3587. u32 tmp;
  3588. /* GRBM_STATUS */
  3589. tmp = RREG32(GRBM_STATUS);
  3590. if (tmp & (PA_BUSY | SC_BUSY |
  3591. SH_BUSY | SX_BUSY |
  3592. TA_BUSY | VGT_BUSY |
  3593. DB_BUSY | CB_BUSY |
  3594. SPI_BUSY | VGT_BUSY_NO_DMA))
  3595. reset_mask |= RADEON_RESET_GFX;
  3596. if (tmp & (CF_RQ_PENDING | PF_RQ_PENDING |
  3597. CP_BUSY | CP_COHERENCY_BUSY))
  3598. reset_mask |= RADEON_RESET_CP;
  3599. if (tmp & GRBM_EE_BUSY)
  3600. reset_mask |= RADEON_RESET_GRBM | RADEON_RESET_GFX | RADEON_RESET_CP;
  3601. /* DMA_STATUS_REG */
  3602. tmp = RREG32(DMA_STATUS_REG);
  3603. if (!(tmp & DMA_IDLE))
  3604. reset_mask |= RADEON_RESET_DMA;
  3605. /* SRBM_STATUS2 */
  3606. tmp = RREG32(SRBM_STATUS2);
  3607. if (tmp & DMA_BUSY)
  3608. reset_mask |= RADEON_RESET_DMA;
  3609. /* SRBM_STATUS */
  3610. tmp = RREG32(SRBM_STATUS);
  3611. if (tmp & (RLC_RQ_PENDING | RLC_BUSY))
  3612. reset_mask |= RADEON_RESET_RLC;
  3613. if (tmp & IH_BUSY)
  3614. reset_mask |= RADEON_RESET_IH;
  3615. if (tmp & SEM_BUSY)
  3616. reset_mask |= RADEON_RESET_SEM;
  3617. if (tmp & GRBM_RQ_PENDING)
  3618. reset_mask |= RADEON_RESET_GRBM;
  3619. if (tmp & VMC_BUSY)
  3620. reset_mask |= RADEON_RESET_VMC;
  3621. if (tmp & (MCB_BUSY | MCB_NON_DISPLAY_BUSY |
  3622. MCC_BUSY | MCD_BUSY))
  3623. reset_mask |= RADEON_RESET_MC;
  3624. if (evergreen_is_display_hung(rdev))
  3625. reset_mask |= RADEON_RESET_DISPLAY;
  3626. /* VM_L2_STATUS */
  3627. tmp = RREG32(VM_L2_STATUS);
  3628. if (tmp & L2_BUSY)
  3629. reset_mask |= RADEON_RESET_VMC;
  3630. /* Skip MC reset as it's mostly likely not hung, just busy */
  3631. if (reset_mask & RADEON_RESET_MC) {
  3632. DRM_DEBUG("MC busy: 0x%08X, clearing.\n", reset_mask);
  3633. reset_mask &= ~RADEON_RESET_MC;
  3634. }
  3635. return reset_mask;
  3636. }
  3637. static void evergreen_gpu_soft_reset(struct radeon_device *rdev, u32 reset_mask)
  3638. {
  3639. struct evergreen_mc_save save;
  3640. u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
  3641. u32 tmp;
  3642. if (reset_mask == 0)
  3643. return;
  3644. dev_info(rdev->dev, "GPU softreset: 0x%08X\n", reset_mask);
  3645. evergreen_print_gpu_status_regs(rdev);
  3646. /* Disable CP parsing/prefetching */
  3647. WREG32(CP_ME_CNTL, CP_ME_HALT | CP_PFP_HALT);
  3648. if (reset_mask & RADEON_RESET_DMA) {
  3649. /* Disable DMA */
  3650. tmp = RREG32(DMA_RB_CNTL);
  3651. tmp &= ~DMA_RB_ENABLE;
  3652. WREG32(DMA_RB_CNTL, tmp);
  3653. }
  3654. udelay(50);
  3655. evergreen_mc_stop(rdev, &save);
  3656. if (evergreen_mc_wait_for_idle(rdev)) {
  3657. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  3658. }
  3659. if (reset_mask & (RADEON_RESET_GFX | RADEON_RESET_COMPUTE)) {
  3660. grbm_soft_reset |= SOFT_RESET_DB |
  3661. SOFT_RESET_CB |
  3662. SOFT_RESET_PA |
  3663. SOFT_RESET_SC |
  3664. SOFT_RESET_SPI |
  3665. SOFT_RESET_SX |
  3666. SOFT_RESET_SH |
  3667. SOFT_RESET_TC |
  3668. SOFT_RESET_TA |
  3669. SOFT_RESET_VC |
  3670. SOFT_RESET_VGT;
  3671. }
  3672. if (reset_mask & RADEON_RESET_CP) {
  3673. grbm_soft_reset |= SOFT_RESET_CP |
  3674. SOFT_RESET_VGT;
  3675. srbm_soft_reset |= SOFT_RESET_GRBM;
  3676. }
  3677. if (reset_mask & RADEON_RESET_DMA)
  3678. srbm_soft_reset |= SOFT_RESET_DMA;
  3679. if (reset_mask & RADEON_RESET_DISPLAY)
  3680. srbm_soft_reset |= SOFT_RESET_DC;
  3681. if (reset_mask & RADEON_RESET_RLC)
  3682. srbm_soft_reset |= SOFT_RESET_RLC;
  3683. if (reset_mask & RADEON_RESET_SEM)
  3684. srbm_soft_reset |= SOFT_RESET_SEM;
  3685. if (reset_mask & RADEON_RESET_IH)
  3686. srbm_soft_reset |= SOFT_RESET_IH;
  3687. if (reset_mask & RADEON_RESET_GRBM)
  3688. srbm_soft_reset |= SOFT_RESET_GRBM;
  3689. if (reset_mask & RADEON_RESET_VMC)
  3690. srbm_soft_reset |= SOFT_RESET_VMC;
  3691. if (!(rdev->flags & RADEON_IS_IGP)) {
  3692. if (reset_mask & RADEON_RESET_MC)
  3693. srbm_soft_reset |= SOFT_RESET_MC;
  3694. }
  3695. if (grbm_soft_reset) {
  3696. tmp = RREG32(GRBM_SOFT_RESET);
  3697. tmp |= grbm_soft_reset;
  3698. dev_info(rdev->dev, "GRBM_SOFT_RESET=0x%08X\n", tmp);
  3699. WREG32(GRBM_SOFT_RESET, tmp);
  3700. tmp = RREG32(GRBM_SOFT_RESET);
  3701. udelay(50);
  3702. tmp &= ~grbm_soft_reset;
  3703. WREG32(GRBM_SOFT_RESET, tmp);
  3704. tmp = RREG32(GRBM_SOFT_RESET);
  3705. }
  3706. if (srbm_soft_reset) {
  3707. tmp = RREG32(SRBM_SOFT_RESET);
  3708. tmp |= srbm_soft_reset;
  3709. dev_info(rdev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
  3710. WREG32(SRBM_SOFT_RESET, tmp);
  3711. tmp = RREG32(SRBM_SOFT_RESET);
  3712. udelay(50);
  3713. tmp &= ~srbm_soft_reset;
  3714. WREG32(SRBM_SOFT_RESET, tmp);
  3715. tmp = RREG32(SRBM_SOFT_RESET);
  3716. }
  3717. /* Wait a little for things to settle down */
  3718. udelay(50);
  3719. evergreen_mc_resume(rdev, &save);
  3720. udelay(50);
  3721. evergreen_print_gpu_status_regs(rdev);
  3722. }
  3723. void evergreen_gpu_pci_config_reset(struct radeon_device *rdev)
  3724. {
  3725. struct evergreen_mc_save save;
  3726. u32 tmp, i;
  3727. dev_info(rdev->dev, "GPU pci config reset\n");
  3728. /* disable dpm? */
  3729. /* Disable CP parsing/prefetching */
  3730. WREG32(CP_ME_CNTL, CP_ME_HALT | CP_PFP_HALT);
  3731. udelay(50);
  3732. /* Disable DMA */
  3733. tmp = RREG32(DMA_RB_CNTL);
  3734. tmp &= ~DMA_RB_ENABLE;
  3735. WREG32(DMA_RB_CNTL, tmp);
  3736. /* XXX other engines? */
  3737. /* halt the rlc */
  3738. r600_rlc_stop(rdev);
  3739. udelay(50);
  3740. /* set mclk/sclk to bypass */
  3741. rv770_set_clk_bypass_mode(rdev);
  3742. /* disable BM */
  3743. pci_clear_master(rdev->pdev);
  3744. /* disable mem access */
  3745. evergreen_mc_stop(rdev, &save);
  3746. if (evergreen_mc_wait_for_idle(rdev)) {
  3747. dev_warn(rdev->dev, "Wait for MC idle timed out !\n");
  3748. }
  3749. /* reset */
  3750. radeon_pci_config_reset(rdev);
  3751. /* wait for asic to come out of reset */
  3752. for (i = 0; i < rdev->usec_timeout; i++) {
  3753. if (RREG32(CONFIG_MEMSIZE) != 0xffffffff)
  3754. break;
  3755. udelay(1);
  3756. }
  3757. }
  3758. int evergreen_asic_reset(struct radeon_device *rdev, bool hard)
  3759. {
  3760. u32 reset_mask;
  3761. if (hard) {
  3762. evergreen_gpu_pci_config_reset(rdev);
  3763. return 0;
  3764. }
  3765. reset_mask = evergreen_gpu_check_soft_reset(rdev);
  3766. if (reset_mask)
  3767. r600_set_bios_scratch_engine_hung(rdev, true);
  3768. /* try soft reset */
  3769. evergreen_gpu_soft_reset(rdev, reset_mask);
  3770. reset_mask = evergreen_gpu_check_soft_reset(rdev);
  3771. /* try pci config reset */
  3772. if (reset_mask && radeon_hard_reset)
  3773. evergreen_gpu_pci_config_reset(rdev);
  3774. reset_mask = evergreen_gpu_check_soft_reset(rdev);
  3775. if (!reset_mask)
  3776. r600_set_bios_scratch_engine_hung(rdev, false);
  3777. return 0;
  3778. }
  3779. /**
  3780. * evergreen_gfx_is_lockup - Check if the GFX engine is locked up
  3781. *
  3782. * @rdev: radeon_device pointer
  3783. * @ring: radeon_ring structure holding ring information
  3784. *
  3785. * Check if the GFX engine is locked up.
  3786. * Returns true if the engine appears to be locked up, false if not.
  3787. */
  3788. bool evergreen_gfx_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
  3789. {
  3790. u32 reset_mask = evergreen_gpu_check_soft_reset(rdev);
  3791. if (!(reset_mask & (RADEON_RESET_GFX |
  3792. RADEON_RESET_COMPUTE |
  3793. RADEON_RESET_CP))) {
  3794. radeon_ring_lockup_update(rdev, ring);
  3795. return false;
  3796. }
  3797. return radeon_ring_test_lockup(rdev, ring);
  3798. }
  3799. /*
  3800. * RLC
  3801. */
  3802. #define RLC_SAVE_RESTORE_LIST_END_MARKER 0x00000000
  3803. #define RLC_CLEAR_STATE_END_MARKER 0x00000001
  3804. void sumo_rlc_fini(struct radeon_device *rdev)
  3805. {
  3806. int r;
  3807. /* save restore block */
  3808. if (rdev->rlc.save_restore_obj) {
  3809. r = radeon_bo_reserve(rdev->rlc.save_restore_obj, false);
  3810. if (unlikely(r != 0))
  3811. dev_warn(rdev->dev, "(%d) reserve RLC sr bo failed\n", r);
  3812. radeon_bo_unpin(rdev->rlc.save_restore_obj);
  3813. radeon_bo_unreserve(rdev->rlc.save_restore_obj);
  3814. radeon_bo_unref(&rdev->rlc.save_restore_obj);
  3815. rdev->rlc.save_restore_obj = NULL;
  3816. }
  3817. /* clear state block */
  3818. if (rdev->rlc.clear_state_obj) {
  3819. r = radeon_bo_reserve(rdev->rlc.clear_state_obj, false);
  3820. if (unlikely(r != 0))
  3821. dev_warn(rdev->dev, "(%d) reserve RLC c bo failed\n", r);
  3822. radeon_bo_unpin(rdev->rlc.clear_state_obj);
  3823. radeon_bo_unreserve(rdev->rlc.clear_state_obj);
  3824. radeon_bo_unref(&rdev->rlc.clear_state_obj);
  3825. rdev->rlc.clear_state_obj = NULL;
  3826. }
  3827. /* clear state block */
  3828. if (rdev->rlc.cp_table_obj) {
  3829. r = radeon_bo_reserve(rdev->rlc.cp_table_obj, false);
  3830. if (unlikely(r != 0))
  3831. dev_warn(rdev->dev, "(%d) reserve RLC cp table bo failed\n", r);
  3832. radeon_bo_unpin(rdev->rlc.cp_table_obj);
  3833. radeon_bo_unreserve(rdev->rlc.cp_table_obj);
  3834. radeon_bo_unref(&rdev->rlc.cp_table_obj);
  3835. rdev->rlc.cp_table_obj = NULL;
  3836. }
  3837. }
  3838. #define CP_ME_TABLE_SIZE 96
  3839. int sumo_rlc_init(struct radeon_device *rdev)
  3840. {
  3841. const u32 *src_ptr;
  3842. volatile u32 *dst_ptr;
  3843. u32 dws, data, i, j, k, reg_num;
  3844. u32 reg_list_num, reg_list_hdr_blk_index, reg_list_blk_index = 0;
  3845. u64 reg_list_mc_addr;
  3846. const struct cs_section_def *cs_data;
  3847. int r;
  3848. src_ptr = rdev->rlc.reg_list;
  3849. dws = rdev->rlc.reg_list_size;
  3850. if (rdev->family >= CHIP_BONAIRE) {
  3851. dws += (5 * 16) + 48 + 48 + 64;
  3852. }
  3853. cs_data = rdev->rlc.cs_data;
  3854. if (src_ptr) {
  3855. /* save restore block */
  3856. if (rdev->rlc.save_restore_obj == NULL) {
  3857. r = radeon_bo_create(rdev, dws * 4, PAGE_SIZE, true,
  3858. RADEON_GEM_DOMAIN_VRAM, 0, NULL,
  3859. NULL, &rdev->rlc.save_restore_obj);
  3860. if (r) {
  3861. dev_warn(rdev->dev, "(%d) create RLC sr bo failed\n", r);
  3862. return r;
  3863. }
  3864. }
  3865. r = radeon_bo_reserve(rdev->rlc.save_restore_obj, false);
  3866. if (unlikely(r != 0)) {
  3867. sumo_rlc_fini(rdev);
  3868. return r;
  3869. }
  3870. r = radeon_bo_pin(rdev->rlc.save_restore_obj, RADEON_GEM_DOMAIN_VRAM,
  3871. &rdev->rlc.save_restore_gpu_addr);
  3872. if (r) {
  3873. radeon_bo_unreserve(rdev->rlc.save_restore_obj);
  3874. dev_warn(rdev->dev, "(%d) pin RLC sr bo failed\n", r);
  3875. sumo_rlc_fini(rdev);
  3876. return r;
  3877. }
  3878. r = radeon_bo_kmap(rdev->rlc.save_restore_obj, (void **)&rdev->rlc.sr_ptr);
  3879. if (r) {
  3880. dev_warn(rdev->dev, "(%d) map RLC sr bo failed\n", r);
  3881. sumo_rlc_fini(rdev);
  3882. return r;
  3883. }
  3884. /* write the sr buffer */
  3885. dst_ptr = rdev->rlc.sr_ptr;
  3886. if (rdev->family >= CHIP_TAHITI) {
  3887. /* SI */
  3888. for (i = 0; i < rdev->rlc.reg_list_size; i++)
  3889. dst_ptr[i] = cpu_to_le32(src_ptr[i]);
  3890. } else {
  3891. /* ON/LN/TN */
  3892. /* format:
  3893. * dw0: (reg2 << 16) | reg1
  3894. * dw1: reg1 save space
  3895. * dw2: reg2 save space
  3896. */
  3897. for (i = 0; i < dws; i++) {
  3898. data = src_ptr[i] >> 2;
  3899. i++;
  3900. if (i < dws)
  3901. data |= (src_ptr[i] >> 2) << 16;
  3902. j = (((i - 1) * 3) / 2);
  3903. dst_ptr[j] = cpu_to_le32(data);
  3904. }
  3905. j = ((i * 3) / 2);
  3906. dst_ptr[j] = cpu_to_le32(RLC_SAVE_RESTORE_LIST_END_MARKER);
  3907. }
  3908. radeon_bo_kunmap(rdev->rlc.save_restore_obj);
  3909. radeon_bo_unreserve(rdev->rlc.save_restore_obj);
  3910. }
  3911. if (cs_data) {
  3912. /* clear state block */
  3913. if (rdev->family >= CHIP_BONAIRE) {
  3914. rdev->rlc.clear_state_size = dws = cik_get_csb_size(rdev);
  3915. } else if (rdev->family >= CHIP_TAHITI) {
  3916. rdev->rlc.clear_state_size = si_get_csb_size(rdev);
  3917. dws = rdev->rlc.clear_state_size + (256 / 4);
  3918. } else {
  3919. reg_list_num = 0;
  3920. dws = 0;
  3921. for (i = 0; cs_data[i].section != NULL; i++) {
  3922. for (j = 0; cs_data[i].section[j].extent != NULL; j++) {
  3923. reg_list_num++;
  3924. dws += cs_data[i].section[j].reg_count;
  3925. }
  3926. }
  3927. reg_list_blk_index = (3 * reg_list_num + 2);
  3928. dws += reg_list_blk_index;
  3929. rdev->rlc.clear_state_size = dws;
  3930. }
  3931. if (rdev->rlc.clear_state_obj == NULL) {
  3932. r = radeon_bo_create(rdev, dws * 4, PAGE_SIZE, true,
  3933. RADEON_GEM_DOMAIN_VRAM, 0, NULL,
  3934. NULL, &rdev->rlc.clear_state_obj);
  3935. if (r) {
  3936. dev_warn(rdev->dev, "(%d) create RLC c bo failed\n", r);
  3937. sumo_rlc_fini(rdev);
  3938. return r;
  3939. }
  3940. }
  3941. r = radeon_bo_reserve(rdev->rlc.clear_state_obj, false);
  3942. if (unlikely(r != 0)) {
  3943. sumo_rlc_fini(rdev);
  3944. return r;
  3945. }
  3946. r = radeon_bo_pin(rdev->rlc.clear_state_obj, RADEON_GEM_DOMAIN_VRAM,
  3947. &rdev->rlc.clear_state_gpu_addr);
  3948. if (r) {
  3949. radeon_bo_unreserve(rdev->rlc.clear_state_obj);
  3950. dev_warn(rdev->dev, "(%d) pin RLC c bo failed\n", r);
  3951. sumo_rlc_fini(rdev);
  3952. return r;
  3953. }
  3954. r = radeon_bo_kmap(rdev->rlc.clear_state_obj, (void **)&rdev->rlc.cs_ptr);
  3955. if (r) {
  3956. dev_warn(rdev->dev, "(%d) map RLC c bo failed\n", r);
  3957. sumo_rlc_fini(rdev);
  3958. return r;
  3959. }
  3960. /* set up the cs buffer */
  3961. dst_ptr = rdev->rlc.cs_ptr;
  3962. if (rdev->family >= CHIP_BONAIRE) {
  3963. cik_get_csb_buffer(rdev, dst_ptr);
  3964. } else if (rdev->family >= CHIP_TAHITI) {
  3965. reg_list_mc_addr = rdev->rlc.clear_state_gpu_addr + 256;
  3966. dst_ptr[0] = cpu_to_le32(upper_32_bits(reg_list_mc_addr));
  3967. dst_ptr[1] = cpu_to_le32(lower_32_bits(reg_list_mc_addr));
  3968. dst_ptr[2] = cpu_to_le32(rdev->rlc.clear_state_size);
  3969. si_get_csb_buffer(rdev, &dst_ptr[(256/4)]);
  3970. } else {
  3971. reg_list_hdr_blk_index = 0;
  3972. reg_list_mc_addr = rdev->rlc.clear_state_gpu_addr + (reg_list_blk_index * 4);
  3973. data = upper_32_bits(reg_list_mc_addr);
  3974. dst_ptr[reg_list_hdr_blk_index] = cpu_to_le32(data);
  3975. reg_list_hdr_blk_index++;
  3976. for (i = 0; cs_data[i].section != NULL; i++) {
  3977. for (j = 0; cs_data[i].section[j].extent != NULL; j++) {
  3978. reg_num = cs_data[i].section[j].reg_count;
  3979. data = reg_list_mc_addr & 0xffffffff;
  3980. dst_ptr[reg_list_hdr_blk_index] = cpu_to_le32(data);
  3981. reg_list_hdr_blk_index++;
  3982. data = (cs_data[i].section[j].reg_index * 4) & 0xffffffff;
  3983. dst_ptr[reg_list_hdr_blk_index] = cpu_to_le32(data);
  3984. reg_list_hdr_blk_index++;
  3985. data = 0x08000000 | (reg_num * 4);
  3986. dst_ptr[reg_list_hdr_blk_index] = cpu_to_le32(data);
  3987. reg_list_hdr_blk_index++;
  3988. for (k = 0; k < reg_num; k++) {
  3989. data = cs_data[i].section[j].extent[k];
  3990. dst_ptr[reg_list_blk_index + k] = cpu_to_le32(data);
  3991. }
  3992. reg_list_mc_addr += reg_num * 4;
  3993. reg_list_blk_index += reg_num;
  3994. }
  3995. }
  3996. dst_ptr[reg_list_hdr_blk_index] = cpu_to_le32(RLC_CLEAR_STATE_END_MARKER);
  3997. }
  3998. radeon_bo_kunmap(rdev->rlc.clear_state_obj);
  3999. radeon_bo_unreserve(rdev->rlc.clear_state_obj);
  4000. }
  4001. if (rdev->rlc.cp_table_size) {
  4002. if (rdev->rlc.cp_table_obj == NULL) {
  4003. r = radeon_bo_create(rdev, rdev->rlc.cp_table_size,
  4004. PAGE_SIZE, true,
  4005. RADEON_GEM_DOMAIN_VRAM, 0, NULL,
  4006. NULL, &rdev->rlc.cp_table_obj);
  4007. if (r) {
  4008. dev_warn(rdev->dev, "(%d) create RLC cp table bo failed\n", r);
  4009. sumo_rlc_fini(rdev);
  4010. return r;
  4011. }
  4012. }
  4013. r = radeon_bo_reserve(rdev->rlc.cp_table_obj, false);
  4014. if (unlikely(r != 0)) {
  4015. dev_warn(rdev->dev, "(%d) reserve RLC cp table bo failed\n", r);
  4016. sumo_rlc_fini(rdev);
  4017. return r;
  4018. }
  4019. r = radeon_bo_pin(rdev->rlc.cp_table_obj, RADEON_GEM_DOMAIN_VRAM,
  4020. &rdev->rlc.cp_table_gpu_addr);
  4021. if (r) {
  4022. radeon_bo_unreserve(rdev->rlc.cp_table_obj);
  4023. dev_warn(rdev->dev, "(%d) pin RLC cp_table bo failed\n", r);
  4024. sumo_rlc_fini(rdev);
  4025. return r;
  4026. }
  4027. r = radeon_bo_kmap(rdev->rlc.cp_table_obj, (void **)&rdev->rlc.cp_table_ptr);
  4028. if (r) {
  4029. dev_warn(rdev->dev, "(%d) map RLC cp table bo failed\n", r);
  4030. sumo_rlc_fini(rdev);
  4031. return r;
  4032. }
  4033. cik_init_cp_pg_table(rdev);
  4034. radeon_bo_kunmap(rdev->rlc.cp_table_obj);
  4035. radeon_bo_unreserve(rdev->rlc.cp_table_obj);
  4036. }
  4037. return 0;
  4038. }
  4039. static void evergreen_rlc_start(struct radeon_device *rdev)
  4040. {
  4041. u32 mask = RLC_ENABLE;
  4042. if (rdev->flags & RADEON_IS_IGP) {
  4043. mask |= GFX_POWER_GATING_ENABLE | GFX_POWER_GATING_SRC;
  4044. }
  4045. WREG32(RLC_CNTL, mask);
  4046. }
  4047. int evergreen_rlc_resume(struct radeon_device *rdev)
  4048. {
  4049. u32 i;
  4050. const __be32 *fw_data;
  4051. if (!rdev->rlc_fw)
  4052. return -EINVAL;
  4053. r600_rlc_stop(rdev);
  4054. WREG32(RLC_HB_CNTL, 0);
  4055. if (rdev->flags & RADEON_IS_IGP) {
  4056. if (rdev->family == CHIP_ARUBA) {
  4057. u32 always_on_bitmap =
  4058. 3 | (3 << (16 * rdev->config.cayman.max_shader_engines));
  4059. /* find out the number of active simds */
  4060. u32 tmp = (RREG32(CC_GC_SHADER_PIPE_CONFIG) & 0xffff0000) >> 16;
  4061. tmp |= 0xffffffff << rdev->config.cayman.max_simds_per_se;
  4062. tmp = hweight32(~tmp);
  4063. if (tmp == rdev->config.cayman.max_simds_per_se) {
  4064. WREG32(TN_RLC_LB_ALWAYS_ACTIVE_SIMD_MASK, always_on_bitmap);
  4065. WREG32(TN_RLC_LB_PARAMS, 0x00601004);
  4066. WREG32(TN_RLC_LB_INIT_SIMD_MASK, 0xffffffff);
  4067. WREG32(TN_RLC_LB_CNTR_INIT, 0x00000000);
  4068. WREG32(TN_RLC_LB_CNTR_MAX, 0x00002000);
  4069. }
  4070. } else {
  4071. WREG32(RLC_HB_WPTR_LSB_ADDR, 0);
  4072. WREG32(RLC_HB_WPTR_MSB_ADDR, 0);
  4073. }
  4074. WREG32(TN_RLC_SAVE_AND_RESTORE_BASE, rdev->rlc.save_restore_gpu_addr >> 8);
  4075. WREG32(TN_RLC_CLEAR_STATE_RESTORE_BASE, rdev->rlc.clear_state_gpu_addr >> 8);
  4076. } else {
  4077. WREG32(RLC_HB_BASE, 0);
  4078. WREG32(RLC_HB_RPTR, 0);
  4079. WREG32(RLC_HB_WPTR, 0);
  4080. WREG32(RLC_HB_WPTR_LSB_ADDR, 0);
  4081. WREG32(RLC_HB_WPTR_MSB_ADDR, 0);
  4082. }
  4083. WREG32(RLC_MC_CNTL, 0);
  4084. WREG32(RLC_UCODE_CNTL, 0);
  4085. fw_data = (const __be32 *)rdev->rlc_fw->data;
  4086. if (rdev->family >= CHIP_ARUBA) {
  4087. for (i = 0; i < ARUBA_RLC_UCODE_SIZE; i++) {
  4088. WREG32(RLC_UCODE_ADDR, i);
  4089. WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
  4090. }
  4091. } else if (rdev->family >= CHIP_CAYMAN) {
  4092. for (i = 0; i < CAYMAN_RLC_UCODE_SIZE; i++) {
  4093. WREG32(RLC_UCODE_ADDR, i);
  4094. WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
  4095. }
  4096. } else {
  4097. for (i = 0; i < EVERGREEN_RLC_UCODE_SIZE; i++) {
  4098. WREG32(RLC_UCODE_ADDR, i);
  4099. WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
  4100. }
  4101. }
  4102. WREG32(RLC_UCODE_ADDR, 0);
  4103. evergreen_rlc_start(rdev);
  4104. return 0;
  4105. }
  4106. /* Interrupts */
  4107. u32 evergreen_get_vblank_counter(struct radeon_device *rdev, int crtc)
  4108. {
  4109. if (crtc >= rdev->num_crtc)
  4110. return 0;
  4111. else
  4112. return RREG32(CRTC_STATUS_FRAME_COUNT + crtc_offsets[crtc]);
  4113. }
  4114. void evergreen_disable_interrupt_state(struct radeon_device *rdev)
  4115. {
  4116. u32 tmp;
  4117. if (rdev->family >= CHIP_CAYMAN) {
  4118. cayman_cp_int_cntl_setup(rdev, 0,
  4119. CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
  4120. cayman_cp_int_cntl_setup(rdev, 1, 0);
  4121. cayman_cp_int_cntl_setup(rdev, 2, 0);
  4122. tmp = RREG32(CAYMAN_DMA1_CNTL) & ~TRAP_ENABLE;
  4123. WREG32(CAYMAN_DMA1_CNTL, tmp);
  4124. } else
  4125. WREG32(CP_INT_CNTL, CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
  4126. tmp = RREG32(DMA_CNTL) & ~TRAP_ENABLE;
  4127. WREG32(DMA_CNTL, tmp);
  4128. WREG32(GRBM_INT_CNTL, 0);
  4129. WREG32(SRBM_INT_CNTL, 0);
  4130. WREG32(INT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, 0);
  4131. WREG32(INT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, 0);
  4132. if (rdev->num_crtc >= 4) {
  4133. WREG32(INT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, 0);
  4134. WREG32(INT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, 0);
  4135. }
  4136. if (rdev->num_crtc >= 6) {
  4137. WREG32(INT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, 0);
  4138. WREG32(INT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, 0);
  4139. }
  4140. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, 0);
  4141. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, 0);
  4142. if (rdev->num_crtc >= 4) {
  4143. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, 0);
  4144. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, 0);
  4145. }
  4146. if (rdev->num_crtc >= 6) {
  4147. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, 0);
  4148. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, 0);
  4149. }
  4150. /* only one DAC on DCE5 */
  4151. if (!ASIC_IS_DCE5(rdev))
  4152. WREG32(DACA_AUTODETECT_INT_CONTROL, 0);
  4153. WREG32(DACB_AUTODETECT_INT_CONTROL, 0);
  4154. tmp = RREG32(DC_HPD1_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  4155. WREG32(DC_HPD1_INT_CONTROL, tmp);
  4156. tmp = RREG32(DC_HPD2_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  4157. WREG32(DC_HPD2_INT_CONTROL, tmp);
  4158. tmp = RREG32(DC_HPD3_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  4159. WREG32(DC_HPD3_INT_CONTROL, tmp);
  4160. tmp = RREG32(DC_HPD4_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  4161. WREG32(DC_HPD4_INT_CONTROL, tmp);
  4162. tmp = RREG32(DC_HPD5_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  4163. WREG32(DC_HPD5_INT_CONTROL, tmp);
  4164. tmp = RREG32(DC_HPD6_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  4165. WREG32(DC_HPD6_INT_CONTROL, tmp);
  4166. }
  4167. int evergreen_irq_set(struct radeon_device *rdev)
  4168. {
  4169. u32 cp_int_cntl = CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE;
  4170. u32 cp_int_cntl1 = 0, cp_int_cntl2 = 0;
  4171. u32 crtc1 = 0, crtc2 = 0, crtc3 = 0, crtc4 = 0, crtc5 = 0, crtc6 = 0;
  4172. u32 hpd1, hpd2, hpd3, hpd4, hpd5, hpd6;
  4173. u32 grbm_int_cntl = 0;
  4174. u32 afmt1 = 0, afmt2 = 0, afmt3 = 0, afmt4 = 0, afmt5 = 0, afmt6 = 0;
  4175. u32 dma_cntl, dma_cntl1 = 0;
  4176. u32 thermal_int = 0;
  4177. if (!rdev->irq.installed) {
  4178. WARN(1, "Can't enable IRQ/MSI because no handler is installed\n");
  4179. return -EINVAL;
  4180. }
  4181. /* don't enable anything if the ih is disabled */
  4182. if (!rdev->ih.enabled) {
  4183. r600_disable_interrupts(rdev);
  4184. /* force the active interrupt state to all disabled */
  4185. evergreen_disable_interrupt_state(rdev);
  4186. return 0;
  4187. }
  4188. hpd1 = RREG32(DC_HPD1_INT_CONTROL) & ~(DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN);
  4189. hpd2 = RREG32(DC_HPD2_INT_CONTROL) & ~(DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN);
  4190. hpd3 = RREG32(DC_HPD3_INT_CONTROL) & ~(DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN);
  4191. hpd4 = RREG32(DC_HPD4_INT_CONTROL) & ~(DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN);
  4192. hpd5 = RREG32(DC_HPD5_INT_CONTROL) & ~(DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN);
  4193. hpd6 = RREG32(DC_HPD6_INT_CONTROL) & ~(DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN);
  4194. if (rdev->family == CHIP_ARUBA)
  4195. thermal_int = RREG32(TN_CG_THERMAL_INT_CTRL) &
  4196. ~(THERM_INT_MASK_HIGH | THERM_INT_MASK_LOW);
  4197. else
  4198. thermal_int = RREG32(CG_THERMAL_INT) &
  4199. ~(THERM_INT_MASK_HIGH | THERM_INT_MASK_LOW);
  4200. afmt1 = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
  4201. afmt2 = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
  4202. afmt3 = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
  4203. afmt4 = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
  4204. afmt5 = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
  4205. afmt6 = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET) & ~AFMT_AZ_FORMAT_WTRIG_MASK;
  4206. dma_cntl = RREG32(DMA_CNTL) & ~TRAP_ENABLE;
  4207. if (rdev->family >= CHIP_CAYMAN) {
  4208. /* enable CP interrupts on all rings */
  4209. if (atomic_read(&rdev->irq.ring_int[RADEON_RING_TYPE_GFX_INDEX])) {
  4210. DRM_DEBUG("evergreen_irq_set: sw int gfx\n");
  4211. cp_int_cntl |= TIME_STAMP_INT_ENABLE;
  4212. }
  4213. if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP1_INDEX])) {
  4214. DRM_DEBUG("evergreen_irq_set: sw int cp1\n");
  4215. cp_int_cntl1 |= TIME_STAMP_INT_ENABLE;
  4216. }
  4217. if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP2_INDEX])) {
  4218. DRM_DEBUG("evergreen_irq_set: sw int cp2\n");
  4219. cp_int_cntl2 |= TIME_STAMP_INT_ENABLE;
  4220. }
  4221. } else {
  4222. if (atomic_read(&rdev->irq.ring_int[RADEON_RING_TYPE_GFX_INDEX])) {
  4223. DRM_DEBUG("evergreen_irq_set: sw int gfx\n");
  4224. cp_int_cntl |= RB_INT_ENABLE;
  4225. cp_int_cntl |= TIME_STAMP_INT_ENABLE;
  4226. }
  4227. }
  4228. if (atomic_read(&rdev->irq.ring_int[R600_RING_TYPE_DMA_INDEX])) {
  4229. DRM_DEBUG("r600_irq_set: sw int dma\n");
  4230. dma_cntl |= TRAP_ENABLE;
  4231. }
  4232. if (rdev->family >= CHIP_CAYMAN) {
  4233. dma_cntl1 = RREG32(CAYMAN_DMA1_CNTL) & ~TRAP_ENABLE;
  4234. if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_DMA1_INDEX])) {
  4235. DRM_DEBUG("r600_irq_set: sw int dma1\n");
  4236. dma_cntl1 |= TRAP_ENABLE;
  4237. }
  4238. }
  4239. if (rdev->irq.dpm_thermal) {
  4240. DRM_DEBUG("dpm thermal\n");
  4241. thermal_int |= THERM_INT_MASK_HIGH | THERM_INT_MASK_LOW;
  4242. }
  4243. if (rdev->irq.crtc_vblank_int[0] ||
  4244. atomic_read(&rdev->irq.pflip[0])) {
  4245. DRM_DEBUG("evergreen_irq_set: vblank 0\n");
  4246. crtc1 |= VBLANK_INT_MASK;
  4247. }
  4248. if (rdev->irq.crtc_vblank_int[1] ||
  4249. atomic_read(&rdev->irq.pflip[1])) {
  4250. DRM_DEBUG("evergreen_irq_set: vblank 1\n");
  4251. crtc2 |= VBLANK_INT_MASK;
  4252. }
  4253. if (rdev->irq.crtc_vblank_int[2] ||
  4254. atomic_read(&rdev->irq.pflip[2])) {
  4255. DRM_DEBUG("evergreen_irq_set: vblank 2\n");
  4256. crtc3 |= VBLANK_INT_MASK;
  4257. }
  4258. if (rdev->irq.crtc_vblank_int[3] ||
  4259. atomic_read(&rdev->irq.pflip[3])) {
  4260. DRM_DEBUG("evergreen_irq_set: vblank 3\n");
  4261. crtc4 |= VBLANK_INT_MASK;
  4262. }
  4263. if (rdev->irq.crtc_vblank_int[4] ||
  4264. atomic_read(&rdev->irq.pflip[4])) {
  4265. DRM_DEBUG("evergreen_irq_set: vblank 4\n");
  4266. crtc5 |= VBLANK_INT_MASK;
  4267. }
  4268. if (rdev->irq.crtc_vblank_int[5] ||
  4269. atomic_read(&rdev->irq.pflip[5])) {
  4270. DRM_DEBUG("evergreen_irq_set: vblank 5\n");
  4271. crtc6 |= VBLANK_INT_MASK;
  4272. }
  4273. if (rdev->irq.hpd[0]) {
  4274. DRM_DEBUG("evergreen_irq_set: hpd 1\n");
  4275. hpd1 |= DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN;
  4276. }
  4277. if (rdev->irq.hpd[1]) {
  4278. DRM_DEBUG("evergreen_irq_set: hpd 2\n");
  4279. hpd2 |= DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN;
  4280. }
  4281. if (rdev->irq.hpd[2]) {
  4282. DRM_DEBUG("evergreen_irq_set: hpd 3\n");
  4283. hpd3 |= DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN;
  4284. }
  4285. if (rdev->irq.hpd[3]) {
  4286. DRM_DEBUG("evergreen_irq_set: hpd 4\n");
  4287. hpd4 |= DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN;
  4288. }
  4289. if (rdev->irq.hpd[4]) {
  4290. DRM_DEBUG("evergreen_irq_set: hpd 5\n");
  4291. hpd5 |= DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN;
  4292. }
  4293. if (rdev->irq.hpd[5]) {
  4294. DRM_DEBUG("evergreen_irq_set: hpd 6\n");
  4295. hpd6 |= DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN;
  4296. }
  4297. if (rdev->irq.afmt[0]) {
  4298. DRM_DEBUG("evergreen_irq_set: hdmi 0\n");
  4299. afmt1 |= AFMT_AZ_FORMAT_WTRIG_MASK;
  4300. }
  4301. if (rdev->irq.afmt[1]) {
  4302. DRM_DEBUG("evergreen_irq_set: hdmi 1\n");
  4303. afmt2 |= AFMT_AZ_FORMAT_WTRIG_MASK;
  4304. }
  4305. if (rdev->irq.afmt[2]) {
  4306. DRM_DEBUG("evergreen_irq_set: hdmi 2\n");
  4307. afmt3 |= AFMT_AZ_FORMAT_WTRIG_MASK;
  4308. }
  4309. if (rdev->irq.afmt[3]) {
  4310. DRM_DEBUG("evergreen_irq_set: hdmi 3\n");
  4311. afmt4 |= AFMT_AZ_FORMAT_WTRIG_MASK;
  4312. }
  4313. if (rdev->irq.afmt[4]) {
  4314. DRM_DEBUG("evergreen_irq_set: hdmi 4\n");
  4315. afmt5 |= AFMT_AZ_FORMAT_WTRIG_MASK;
  4316. }
  4317. if (rdev->irq.afmt[5]) {
  4318. DRM_DEBUG("evergreen_irq_set: hdmi 5\n");
  4319. afmt6 |= AFMT_AZ_FORMAT_WTRIG_MASK;
  4320. }
  4321. if (rdev->family >= CHIP_CAYMAN) {
  4322. cayman_cp_int_cntl_setup(rdev, 0, cp_int_cntl);
  4323. cayman_cp_int_cntl_setup(rdev, 1, cp_int_cntl1);
  4324. cayman_cp_int_cntl_setup(rdev, 2, cp_int_cntl2);
  4325. } else
  4326. WREG32(CP_INT_CNTL, cp_int_cntl);
  4327. WREG32(DMA_CNTL, dma_cntl);
  4328. if (rdev->family >= CHIP_CAYMAN)
  4329. WREG32(CAYMAN_DMA1_CNTL, dma_cntl1);
  4330. WREG32(GRBM_INT_CNTL, grbm_int_cntl);
  4331. WREG32(INT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, crtc1);
  4332. WREG32(INT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, crtc2);
  4333. if (rdev->num_crtc >= 4) {
  4334. WREG32(INT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, crtc3);
  4335. WREG32(INT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, crtc4);
  4336. }
  4337. if (rdev->num_crtc >= 6) {
  4338. WREG32(INT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, crtc5);
  4339. WREG32(INT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, crtc6);
  4340. }
  4341. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET,
  4342. GRPH_PFLIP_INT_MASK);
  4343. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET,
  4344. GRPH_PFLIP_INT_MASK);
  4345. if (rdev->num_crtc >= 4) {
  4346. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET,
  4347. GRPH_PFLIP_INT_MASK);
  4348. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET,
  4349. GRPH_PFLIP_INT_MASK);
  4350. }
  4351. if (rdev->num_crtc >= 6) {
  4352. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET,
  4353. GRPH_PFLIP_INT_MASK);
  4354. WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET,
  4355. GRPH_PFLIP_INT_MASK);
  4356. }
  4357. WREG32(DC_HPD1_INT_CONTROL, hpd1);
  4358. WREG32(DC_HPD2_INT_CONTROL, hpd2);
  4359. WREG32(DC_HPD3_INT_CONTROL, hpd3);
  4360. WREG32(DC_HPD4_INT_CONTROL, hpd4);
  4361. WREG32(DC_HPD5_INT_CONTROL, hpd5);
  4362. WREG32(DC_HPD6_INT_CONTROL, hpd6);
  4363. if (rdev->family == CHIP_ARUBA)
  4364. WREG32(TN_CG_THERMAL_INT_CTRL, thermal_int);
  4365. else
  4366. WREG32(CG_THERMAL_INT, thermal_int);
  4367. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, afmt1);
  4368. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, afmt2);
  4369. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, afmt3);
  4370. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, afmt4);
  4371. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, afmt5);
  4372. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, afmt6);
  4373. /* posting read */
  4374. RREG32(SRBM_STATUS);
  4375. return 0;
  4376. }
  4377. static void evergreen_irq_ack(struct radeon_device *rdev)
  4378. {
  4379. u32 tmp;
  4380. rdev->irq.stat_regs.evergreen.disp_int = RREG32(DISP_INTERRUPT_STATUS);
  4381. rdev->irq.stat_regs.evergreen.disp_int_cont = RREG32(DISP_INTERRUPT_STATUS_CONTINUE);
  4382. rdev->irq.stat_regs.evergreen.disp_int_cont2 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE2);
  4383. rdev->irq.stat_regs.evergreen.disp_int_cont3 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE3);
  4384. rdev->irq.stat_regs.evergreen.disp_int_cont4 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE4);
  4385. rdev->irq.stat_regs.evergreen.disp_int_cont5 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE5);
  4386. rdev->irq.stat_regs.evergreen.d1grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET);
  4387. rdev->irq.stat_regs.evergreen.d2grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET);
  4388. if (rdev->num_crtc >= 4) {
  4389. rdev->irq.stat_regs.evergreen.d3grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET);
  4390. rdev->irq.stat_regs.evergreen.d4grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET);
  4391. }
  4392. if (rdev->num_crtc >= 6) {
  4393. rdev->irq.stat_regs.evergreen.d5grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET);
  4394. rdev->irq.stat_regs.evergreen.d6grph_int = RREG32(GRPH_INT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET);
  4395. }
  4396. rdev->irq.stat_regs.evergreen.afmt_status1 = RREG32(AFMT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET);
  4397. rdev->irq.stat_regs.evergreen.afmt_status2 = RREG32(AFMT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET);
  4398. rdev->irq.stat_regs.evergreen.afmt_status3 = RREG32(AFMT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET);
  4399. rdev->irq.stat_regs.evergreen.afmt_status4 = RREG32(AFMT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET);
  4400. rdev->irq.stat_regs.evergreen.afmt_status5 = RREG32(AFMT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET);
  4401. rdev->irq.stat_regs.evergreen.afmt_status6 = RREG32(AFMT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET);
  4402. if (rdev->irq.stat_regs.evergreen.d1grph_int & GRPH_PFLIP_INT_OCCURRED)
  4403. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  4404. if (rdev->irq.stat_regs.evergreen.d2grph_int & GRPH_PFLIP_INT_OCCURRED)
  4405. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  4406. if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VBLANK_INTERRUPT)
  4407. WREG32(VBLANK_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VBLANK_ACK);
  4408. if (rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VLINE_INTERRUPT)
  4409. WREG32(VLINE_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VLINE_ACK);
  4410. if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VBLANK_INTERRUPT)
  4411. WREG32(VBLANK_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VBLANK_ACK);
  4412. if (rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VLINE_INTERRUPT)
  4413. WREG32(VLINE_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VLINE_ACK);
  4414. if (rdev->num_crtc >= 4) {
  4415. if (rdev->irq.stat_regs.evergreen.d3grph_int & GRPH_PFLIP_INT_OCCURRED)
  4416. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  4417. if (rdev->irq.stat_regs.evergreen.d4grph_int & GRPH_PFLIP_INT_OCCURRED)
  4418. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  4419. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT)
  4420. WREG32(VBLANK_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VBLANK_ACK);
  4421. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VLINE_INTERRUPT)
  4422. WREG32(VLINE_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VLINE_ACK);
  4423. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT)
  4424. WREG32(VBLANK_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VBLANK_ACK);
  4425. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VLINE_INTERRUPT)
  4426. WREG32(VLINE_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VLINE_ACK);
  4427. }
  4428. if (rdev->num_crtc >= 6) {
  4429. if (rdev->irq.stat_regs.evergreen.d5grph_int & GRPH_PFLIP_INT_OCCURRED)
  4430. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  4431. if (rdev->irq.stat_regs.evergreen.d6grph_int & GRPH_PFLIP_INT_OCCURRED)
  4432. WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, GRPH_PFLIP_INT_CLEAR);
  4433. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT)
  4434. WREG32(VBLANK_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VBLANK_ACK);
  4435. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VLINE_INTERRUPT)
  4436. WREG32(VLINE_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VLINE_ACK);
  4437. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT)
  4438. WREG32(VBLANK_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VBLANK_ACK);
  4439. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VLINE_INTERRUPT)
  4440. WREG32(VLINE_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VLINE_ACK);
  4441. }
  4442. if (rdev->irq.stat_regs.evergreen.disp_int & DC_HPD1_INTERRUPT) {
  4443. tmp = RREG32(DC_HPD1_INT_CONTROL);
  4444. tmp |= DC_HPDx_INT_ACK;
  4445. WREG32(DC_HPD1_INT_CONTROL, tmp);
  4446. }
  4447. if (rdev->irq.stat_regs.evergreen.disp_int_cont & DC_HPD2_INTERRUPT) {
  4448. tmp = RREG32(DC_HPD2_INT_CONTROL);
  4449. tmp |= DC_HPDx_INT_ACK;
  4450. WREG32(DC_HPD2_INT_CONTROL, tmp);
  4451. }
  4452. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & DC_HPD3_INTERRUPT) {
  4453. tmp = RREG32(DC_HPD3_INT_CONTROL);
  4454. tmp |= DC_HPDx_INT_ACK;
  4455. WREG32(DC_HPD3_INT_CONTROL, tmp);
  4456. }
  4457. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & DC_HPD4_INTERRUPT) {
  4458. tmp = RREG32(DC_HPD4_INT_CONTROL);
  4459. tmp |= DC_HPDx_INT_ACK;
  4460. WREG32(DC_HPD4_INT_CONTROL, tmp);
  4461. }
  4462. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & DC_HPD5_INTERRUPT) {
  4463. tmp = RREG32(DC_HPD5_INT_CONTROL);
  4464. tmp |= DC_HPDx_INT_ACK;
  4465. WREG32(DC_HPD5_INT_CONTROL, tmp);
  4466. }
  4467. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & DC_HPD6_INTERRUPT) {
  4468. tmp = RREG32(DC_HPD6_INT_CONTROL);
  4469. tmp |= DC_HPDx_INT_ACK;
  4470. WREG32(DC_HPD6_INT_CONTROL, tmp);
  4471. }
  4472. if (rdev->irq.stat_regs.evergreen.disp_int & DC_HPD1_RX_INTERRUPT) {
  4473. tmp = RREG32(DC_HPD1_INT_CONTROL);
  4474. tmp |= DC_HPDx_RX_INT_ACK;
  4475. WREG32(DC_HPD1_INT_CONTROL, tmp);
  4476. }
  4477. if (rdev->irq.stat_regs.evergreen.disp_int_cont & DC_HPD2_RX_INTERRUPT) {
  4478. tmp = RREG32(DC_HPD2_INT_CONTROL);
  4479. tmp |= DC_HPDx_RX_INT_ACK;
  4480. WREG32(DC_HPD2_INT_CONTROL, tmp);
  4481. }
  4482. if (rdev->irq.stat_regs.evergreen.disp_int_cont2 & DC_HPD3_RX_INTERRUPT) {
  4483. tmp = RREG32(DC_HPD3_INT_CONTROL);
  4484. tmp |= DC_HPDx_RX_INT_ACK;
  4485. WREG32(DC_HPD3_INT_CONTROL, tmp);
  4486. }
  4487. if (rdev->irq.stat_regs.evergreen.disp_int_cont3 & DC_HPD4_RX_INTERRUPT) {
  4488. tmp = RREG32(DC_HPD4_INT_CONTROL);
  4489. tmp |= DC_HPDx_RX_INT_ACK;
  4490. WREG32(DC_HPD4_INT_CONTROL, tmp);
  4491. }
  4492. if (rdev->irq.stat_regs.evergreen.disp_int_cont4 & DC_HPD5_RX_INTERRUPT) {
  4493. tmp = RREG32(DC_HPD5_INT_CONTROL);
  4494. tmp |= DC_HPDx_RX_INT_ACK;
  4495. WREG32(DC_HPD5_INT_CONTROL, tmp);
  4496. }
  4497. if (rdev->irq.stat_regs.evergreen.disp_int_cont5 & DC_HPD6_RX_INTERRUPT) {
  4498. tmp = RREG32(DC_HPD6_INT_CONTROL);
  4499. tmp |= DC_HPDx_RX_INT_ACK;
  4500. WREG32(DC_HPD6_INT_CONTROL, tmp);
  4501. }
  4502. if (rdev->irq.stat_regs.evergreen.afmt_status1 & AFMT_AZ_FORMAT_WTRIG) {
  4503. tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET);
  4504. tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
  4505. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, tmp);
  4506. }
  4507. if (rdev->irq.stat_regs.evergreen.afmt_status2 & AFMT_AZ_FORMAT_WTRIG) {
  4508. tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET);
  4509. tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
  4510. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, tmp);
  4511. }
  4512. if (rdev->irq.stat_regs.evergreen.afmt_status3 & AFMT_AZ_FORMAT_WTRIG) {
  4513. tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET);
  4514. tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
  4515. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, tmp);
  4516. }
  4517. if (rdev->irq.stat_regs.evergreen.afmt_status4 & AFMT_AZ_FORMAT_WTRIG) {
  4518. tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET);
  4519. tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
  4520. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, tmp);
  4521. }
  4522. if (rdev->irq.stat_regs.evergreen.afmt_status5 & AFMT_AZ_FORMAT_WTRIG) {
  4523. tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET);
  4524. tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
  4525. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, tmp);
  4526. }
  4527. if (rdev->irq.stat_regs.evergreen.afmt_status6 & AFMT_AZ_FORMAT_WTRIG) {
  4528. tmp = RREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET);
  4529. tmp |= AFMT_AZ_FORMAT_WTRIG_ACK;
  4530. WREG32(AFMT_AUDIO_PACKET_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, tmp);
  4531. }
  4532. }
  4533. static void evergreen_irq_disable(struct radeon_device *rdev)
  4534. {
  4535. r600_disable_interrupts(rdev);
  4536. /* Wait and acknowledge irq */
  4537. mdelay(1);
  4538. evergreen_irq_ack(rdev);
  4539. evergreen_disable_interrupt_state(rdev);
  4540. }
  4541. void evergreen_irq_suspend(struct radeon_device *rdev)
  4542. {
  4543. evergreen_irq_disable(rdev);
  4544. r600_rlc_stop(rdev);
  4545. }
  4546. static u32 evergreen_get_ih_wptr(struct radeon_device *rdev)
  4547. {
  4548. u32 wptr, tmp;
  4549. if (rdev->wb.enabled)
  4550. wptr = le32_to_cpu(rdev->wb.wb[R600_WB_IH_WPTR_OFFSET/4]);
  4551. else
  4552. wptr = RREG32(IH_RB_WPTR);
  4553. if (wptr & RB_OVERFLOW) {
  4554. wptr &= ~RB_OVERFLOW;
  4555. /* When a ring buffer overflow happen start parsing interrupt
  4556. * from the last not overwritten vector (wptr + 16). Hopefully
  4557. * this should allow us to catchup.
  4558. */
  4559. dev_warn(rdev->dev, "IH ring buffer overflow (0x%08X, 0x%08X, 0x%08X)\n",
  4560. wptr, rdev->ih.rptr, (wptr + 16) & rdev->ih.ptr_mask);
  4561. rdev->ih.rptr = (wptr + 16) & rdev->ih.ptr_mask;
  4562. tmp = RREG32(IH_RB_CNTL);
  4563. tmp |= IH_WPTR_OVERFLOW_CLEAR;
  4564. WREG32(IH_RB_CNTL, tmp);
  4565. }
  4566. return (wptr & rdev->ih.ptr_mask);
  4567. }
  4568. int evergreen_irq_process(struct radeon_device *rdev)
  4569. {
  4570. u32 wptr;
  4571. u32 rptr;
  4572. u32 src_id, src_data;
  4573. u32 ring_index;
  4574. bool queue_hotplug = false;
  4575. bool queue_hdmi = false;
  4576. bool queue_dp = false;
  4577. bool queue_thermal = false;
  4578. u32 status, addr;
  4579. if (!rdev->ih.enabled || rdev->shutdown)
  4580. return IRQ_NONE;
  4581. wptr = evergreen_get_ih_wptr(rdev);
  4582. restart_ih:
  4583. /* is somebody else already processing irqs? */
  4584. if (atomic_xchg(&rdev->ih.lock, 1))
  4585. return IRQ_NONE;
  4586. rptr = rdev->ih.rptr;
  4587. DRM_DEBUG("evergreen_irq_process start: rptr %d, wptr %d\n", rptr, wptr);
  4588. /* Order reading of wptr vs. reading of IH ring data */
  4589. rmb();
  4590. /* display interrupts */
  4591. evergreen_irq_ack(rdev);
  4592. while (rptr != wptr) {
  4593. /* wptr/rptr are in bytes! */
  4594. ring_index = rptr / 4;
  4595. src_id = le32_to_cpu(rdev->ih.ring[ring_index]) & 0xff;
  4596. src_data = le32_to_cpu(rdev->ih.ring[ring_index + 1]) & 0xfffffff;
  4597. switch (src_id) {
  4598. case 1: /* D1 vblank/vline */
  4599. switch (src_data) {
  4600. case 0: /* D1 vblank */
  4601. if (!(rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VBLANK_INTERRUPT))
  4602. DRM_DEBUG("IH: D1 vblank - IH event w/o asserted irq bit?\n");
  4603. if (rdev->irq.crtc_vblank_int[0]) {
  4604. drm_handle_vblank(rdev->ddev, 0);
  4605. rdev->pm.vblank_sync = true;
  4606. wake_up(&rdev->irq.vblank_queue);
  4607. }
  4608. if (atomic_read(&rdev->irq.pflip[0]))
  4609. radeon_crtc_handle_vblank(rdev, 0);
  4610. rdev->irq.stat_regs.evergreen.disp_int &= ~LB_D1_VBLANK_INTERRUPT;
  4611. DRM_DEBUG("IH: D1 vblank\n");
  4612. break;
  4613. case 1: /* D1 vline */
  4614. if (!(rdev->irq.stat_regs.evergreen.disp_int & LB_D1_VLINE_INTERRUPT))
  4615. DRM_DEBUG("IH: D1 vline - IH event w/o asserted irq bit?\n");
  4616. rdev->irq.stat_regs.evergreen.disp_int &= ~LB_D1_VLINE_INTERRUPT;
  4617. DRM_DEBUG("IH: D1 vline\n");
  4618. break;
  4619. default:
  4620. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4621. break;
  4622. }
  4623. break;
  4624. case 2: /* D2 vblank/vline */
  4625. switch (src_data) {
  4626. case 0: /* D2 vblank */
  4627. if (!(rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VBLANK_INTERRUPT))
  4628. DRM_DEBUG("IH: D2 vblank - IH event w/o asserted irq bit?\n");
  4629. if (rdev->irq.crtc_vblank_int[1]) {
  4630. drm_handle_vblank(rdev->ddev, 1);
  4631. rdev->pm.vblank_sync = true;
  4632. wake_up(&rdev->irq.vblank_queue);
  4633. }
  4634. if (atomic_read(&rdev->irq.pflip[1]))
  4635. radeon_crtc_handle_vblank(rdev, 1);
  4636. rdev->irq.stat_regs.evergreen.disp_int_cont &= ~LB_D2_VBLANK_INTERRUPT;
  4637. DRM_DEBUG("IH: D2 vblank\n");
  4638. break;
  4639. case 1: /* D2 vline */
  4640. if (!(rdev->irq.stat_regs.evergreen.disp_int_cont & LB_D2_VLINE_INTERRUPT))
  4641. DRM_DEBUG("IH: D2 vline - IH event w/o asserted irq bit?\n");
  4642. rdev->irq.stat_regs.evergreen.disp_int_cont &= ~LB_D2_VLINE_INTERRUPT;
  4643. DRM_DEBUG("IH: D2 vline\n");
  4644. break;
  4645. default:
  4646. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4647. break;
  4648. }
  4649. break;
  4650. case 3: /* D3 vblank/vline */
  4651. switch (src_data) {
  4652. case 0: /* D3 vblank */
  4653. if (!(rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT))
  4654. DRM_DEBUG("IH: D3 vblank - IH event w/o asserted irq bit?\n");
  4655. if (rdev->irq.crtc_vblank_int[2]) {
  4656. drm_handle_vblank(rdev->ddev, 2);
  4657. rdev->pm.vblank_sync = true;
  4658. wake_up(&rdev->irq.vblank_queue);
  4659. }
  4660. if (atomic_read(&rdev->irq.pflip[2]))
  4661. radeon_crtc_handle_vblank(rdev, 2);
  4662. rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~LB_D3_VBLANK_INTERRUPT;
  4663. DRM_DEBUG("IH: D3 vblank\n");
  4664. break;
  4665. case 1: /* D3 vline */
  4666. if (!(rdev->irq.stat_regs.evergreen.disp_int_cont2 & LB_D3_VLINE_INTERRUPT))
  4667. DRM_DEBUG("IH: D3 vline - IH event w/o asserted irq bit?\n");
  4668. rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~LB_D3_VLINE_INTERRUPT;
  4669. DRM_DEBUG("IH: D3 vline\n");
  4670. break;
  4671. default:
  4672. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4673. break;
  4674. }
  4675. break;
  4676. case 4: /* D4 vblank/vline */
  4677. switch (src_data) {
  4678. case 0: /* D4 vblank */
  4679. if (!(rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT))
  4680. DRM_DEBUG("IH: D4 vblank - IH event w/o asserted irq bit?\n");
  4681. if (rdev->irq.crtc_vblank_int[3]) {
  4682. drm_handle_vblank(rdev->ddev, 3);
  4683. rdev->pm.vblank_sync = true;
  4684. wake_up(&rdev->irq.vblank_queue);
  4685. }
  4686. if (atomic_read(&rdev->irq.pflip[3]))
  4687. radeon_crtc_handle_vblank(rdev, 3);
  4688. rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~LB_D4_VBLANK_INTERRUPT;
  4689. DRM_DEBUG("IH: D4 vblank\n");
  4690. break;
  4691. case 1: /* D4 vline */
  4692. if (!(rdev->irq.stat_regs.evergreen.disp_int_cont3 & LB_D4_VLINE_INTERRUPT))
  4693. DRM_DEBUG("IH: D4 vline - IH event w/o asserted irq bit?\n");
  4694. rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~LB_D4_VLINE_INTERRUPT;
  4695. DRM_DEBUG("IH: D4 vline\n");
  4696. break;
  4697. default:
  4698. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4699. break;
  4700. }
  4701. break;
  4702. case 5: /* D5 vblank/vline */
  4703. switch (src_data) {
  4704. case 0: /* D5 vblank */
  4705. if (!(rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT))
  4706. DRM_DEBUG("IH: D5 vblank - IH event w/o asserted irq bit?\n");
  4707. if (rdev->irq.crtc_vblank_int[4]) {
  4708. drm_handle_vblank(rdev->ddev, 4);
  4709. rdev->pm.vblank_sync = true;
  4710. wake_up(&rdev->irq.vblank_queue);
  4711. }
  4712. if (atomic_read(&rdev->irq.pflip[4]))
  4713. radeon_crtc_handle_vblank(rdev, 4);
  4714. rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~LB_D5_VBLANK_INTERRUPT;
  4715. DRM_DEBUG("IH: D5 vblank\n");
  4716. break;
  4717. case 1: /* D5 vline */
  4718. if (!(rdev->irq.stat_regs.evergreen.disp_int_cont4 & LB_D5_VLINE_INTERRUPT))
  4719. DRM_DEBUG("IH: D5 vline - IH event w/o asserted irq bit?\n");
  4720. rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~LB_D5_VLINE_INTERRUPT;
  4721. DRM_DEBUG("IH: D5 vline\n");
  4722. break;
  4723. default:
  4724. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4725. break;
  4726. }
  4727. break;
  4728. case 6: /* D6 vblank/vline */
  4729. switch (src_data) {
  4730. case 0: /* D6 vblank */
  4731. if (!(rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT))
  4732. DRM_DEBUG("IH: D6 vblank - IH event w/o asserted irq bit?\n");
  4733. if (rdev->irq.crtc_vblank_int[5]) {
  4734. drm_handle_vblank(rdev->ddev, 5);
  4735. rdev->pm.vblank_sync = true;
  4736. wake_up(&rdev->irq.vblank_queue);
  4737. }
  4738. if (atomic_read(&rdev->irq.pflip[5]))
  4739. radeon_crtc_handle_vblank(rdev, 5);
  4740. rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~LB_D6_VBLANK_INTERRUPT;
  4741. DRM_DEBUG("IH: D6 vblank\n");
  4742. break;
  4743. case 1: /* D6 vline */
  4744. if (!(rdev->irq.stat_regs.evergreen.disp_int_cont5 & LB_D6_VLINE_INTERRUPT))
  4745. DRM_DEBUG("IH: D6 vline - IH event w/o asserted irq bit?\n");
  4746. rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~LB_D6_VLINE_INTERRUPT;
  4747. DRM_DEBUG("IH: D6 vline\n");
  4748. break;
  4749. default:
  4750. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4751. break;
  4752. }
  4753. break;
  4754. case 8: /* D1 page flip */
  4755. case 10: /* D2 page flip */
  4756. case 12: /* D3 page flip */
  4757. case 14: /* D4 page flip */
  4758. case 16: /* D5 page flip */
  4759. case 18: /* D6 page flip */
  4760. DRM_DEBUG("IH: D%d flip\n", ((src_id - 8) >> 1) + 1);
  4761. if (radeon_use_pflipirq > 0)
  4762. radeon_crtc_handle_flip(rdev, (src_id - 8) >> 1);
  4763. break;
  4764. case 42: /* HPD hotplug */
  4765. switch (src_data) {
  4766. case 0:
  4767. if (!(rdev->irq.stat_regs.evergreen.disp_int & DC_HPD1_INTERRUPT))
  4768. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  4769. rdev->irq.stat_regs.evergreen.disp_int &= ~DC_HPD1_INTERRUPT;
  4770. queue_hotplug = true;
  4771. DRM_DEBUG("IH: HPD1\n");
  4772. break;
  4773. case 1:
  4774. if (!(rdev->irq.stat_regs.evergreen.disp_int_cont & DC_HPD2_INTERRUPT))
  4775. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  4776. rdev->irq.stat_regs.evergreen.disp_int_cont &= ~DC_HPD2_INTERRUPT;
  4777. queue_hotplug = true;
  4778. DRM_DEBUG("IH: HPD2\n");
  4779. break;
  4780. case 2:
  4781. if (!(rdev->irq.stat_regs.evergreen.disp_int_cont2 & DC_HPD3_INTERRUPT))
  4782. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  4783. rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~DC_HPD3_INTERRUPT;
  4784. queue_hotplug = true;
  4785. DRM_DEBUG("IH: HPD3\n");
  4786. break;
  4787. case 3:
  4788. if (!(rdev->irq.stat_regs.evergreen.disp_int_cont3 & DC_HPD4_INTERRUPT))
  4789. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  4790. rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~DC_HPD4_INTERRUPT;
  4791. queue_hotplug = true;
  4792. DRM_DEBUG("IH: HPD4\n");
  4793. break;
  4794. case 4:
  4795. if (!(rdev->irq.stat_regs.evergreen.disp_int_cont4 & DC_HPD5_INTERRUPT))
  4796. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  4797. rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~DC_HPD5_INTERRUPT;
  4798. queue_hotplug = true;
  4799. DRM_DEBUG("IH: HPD5\n");
  4800. break;
  4801. case 5:
  4802. if (!(rdev->irq.stat_regs.evergreen.disp_int_cont5 & DC_HPD6_INTERRUPT))
  4803. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  4804. rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~DC_HPD6_INTERRUPT;
  4805. queue_hotplug = true;
  4806. DRM_DEBUG("IH: HPD6\n");
  4807. break;
  4808. case 6:
  4809. if (!(rdev->irq.stat_regs.evergreen.disp_int & DC_HPD1_RX_INTERRUPT))
  4810. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  4811. rdev->irq.stat_regs.evergreen.disp_int &= ~DC_HPD1_RX_INTERRUPT;
  4812. queue_dp = true;
  4813. DRM_DEBUG("IH: HPD_RX 1\n");
  4814. break;
  4815. case 7:
  4816. if (!(rdev->irq.stat_regs.evergreen.disp_int_cont & DC_HPD2_RX_INTERRUPT))
  4817. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  4818. rdev->irq.stat_regs.evergreen.disp_int_cont &= ~DC_HPD2_RX_INTERRUPT;
  4819. queue_dp = true;
  4820. DRM_DEBUG("IH: HPD_RX 2\n");
  4821. break;
  4822. case 8:
  4823. if (!(rdev->irq.stat_regs.evergreen.disp_int_cont2 & DC_HPD3_RX_INTERRUPT))
  4824. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  4825. rdev->irq.stat_regs.evergreen.disp_int_cont2 &= ~DC_HPD3_RX_INTERRUPT;
  4826. queue_dp = true;
  4827. DRM_DEBUG("IH: HPD_RX 3\n");
  4828. break;
  4829. case 9:
  4830. if (!(rdev->irq.stat_regs.evergreen.disp_int_cont3 & DC_HPD4_RX_INTERRUPT))
  4831. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  4832. rdev->irq.stat_regs.evergreen.disp_int_cont3 &= ~DC_HPD4_RX_INTERRUPT;
  4833. queue_dp = true;
  4834. DRM_DEBUG("IH: HPD_RX 4\n");
  4835. break;
  4836. case 10:
  4837. if (!(rdev->irq.stat_regs.evergreen.disp_int_cont4 & DC_HPD5_RX_INTERRUPT))
  4838. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  4839. rdev->irq.stat_regs.evergreen.disp_int_cont4 &= ~DC_HPD5_RX_INTERRUPT;
  4840. queue_dp = true;
  4841. DRM_DEBUG("IH: HPD_RX 5\n");
  4842. break;
  4843. case 11:
  4844. if (!(rdev->irq.stat_regs.evergreen.disp_int_cont5 & DC_HPD6_RX_INTERRUPT))
  4845. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  4846. rdev->irq.stat_regs.evergreen.disp_int_cont5 &= ~DC_HPD6_RX_INTERRUPT;
  4847. queue_dp = true;
  4848. DRM_DEBUG("IH: HPD_RX 6\n");
  4849. break;
  4850. default:
  4851. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4852. break;
  4853. }
  4854. break;
  4855. case 44: /* hdmi */
  4856. switch (src_data) {
  4857. case 0:
  4858. if (!(rdev->irq.stat_regs.evergreen.afmt_status1 & AFMT_AZ_FORMAT_WTRIG))
  4859. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  4860. rdev->irq.stat_regs.evergreen.afmt_status1 &= ~AFMT_AZ_FORMAT_WTRIG;
  4861. queue_hdmi = true;
  4862. DRM_DEBUG("IH: HDMI0\n");
  4863. break;
  4864. case 1:
  4865. if (!(rdev->irq.stat_regs.evergreen.afmt_status2 & AFMT_AZ_FORMAT_WTRIG))
  4866. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  4867. rdev->irq.stat_regs.evergreen.afmt_status2 &= ~AFMT_AZ_FORMAT_WTRIG;
  4868. queue_hdmi = true;
  4869. DRM_DEBUG("IH: HDMI1\n");
  4870. break;
  4871. case 2:
  4872. if (!(rdev->irq.stat_regs.evergreen.afmt_status3 & AFMT_AZ_FORMAT_WTRIG))
  4873. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  4874. rdev->irq.stat_regs.evergreen.afmt_status3 &= ~AFMT_AZ_FORMAT_WTRIG;
  4875. queue_hdmi = true;
  4876. DRM_DEBUG("IH: HDMI2\n");
  4877. break;
  4878. case 3:
  4879. if (!(rdev->irq.stat_regs.evergreen.afmt_status4 & AFMT_AZ_FORMAT_WTRIG))
  4880. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  4881. rdev->irq.stat_regs.evergreen.afmt_status4 &= ~AFMT_AZ_FORMAT_WTRIG;
  4882. queue_hdmi = true;
  4883. DRM_DEBUG("IH: HDMI3\n");
  4884. break;
  4885. case 4:
  4886. if (!(rdev->irq.stat_regs.evergreen.afmt_status5 & AFMT_AZ_FORMAT_WTRIG))
  4887. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  4888. rdev->irq.stat_regs.evergreen.afmt_status5 &= ~AFMT_AZ_FORMAT_WTRIG;
  4889. queue_hdmi = true;
  4890. DRM_DEBUG("IH: HDMI4\n");
  4891. break;
  4892. case 5:
  4893. if (!(rdev->irq.stat_regs.evergreen.afmt_status6 & AFMT_AZ_FORMAT_WTRIG))
  4894. DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
  4895. rdev->irq.stat_regs.evergreen.afmt_status6 &= ~AFMT_AZ_FORMAT_WTRIG;
  4896. queue_hdmi = true;
  4897. DRM_DEBUG("IH: HDMI5\n");
  4898. break;
  4899. default:
  4900. DRM_ERROR("Unhandled interrupt: %d %d\n", src_id, src_data);
  4901. break;
  4902. }
  4903. case 96:
  4904. DRM_ERROR("SRBM_READ_ERROR: 0x%x\n", RREG32(SRBM_READ_ERROR));
  4905. WREG32(SRBM_INT_ACK, 0x1);
  4906. break;
  4907. case 124: /* UVD */
  4908. DRM_DEBUG("IH: UVD int: 0x%08x\n", src_data);
  4909. radeon_fence_process(rdev, R600_RING_TYPE_UVD_INDEX);
  4910. break;
  4911. case 146:
  4912. case 147:
  4913. addr = RREG32(VM_CONTEXT1_PROTECTION_FAULT_ADDR);
  4914. status = RREG32(VM_CONTEXT1_PROTECTION_FAULT_STATUS);
  4915. /* reset addr and status */
  4916. WREG32_P(VM_CONTEXT1_CNTL2, 1, ~1);
  4917. if (addr == 0x0 && status == 0x0)
  4918. break;
  4919. dev_err(rdev->dev, "GPU fault detected: %d 0x%08x\n", src_id, src_data);
  4920. dev_err(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
  4921. addr);
  4922. dev_err(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
  4923. status);
  4924. cayman_vm_decode_fault(rdev, status, addr);
  4925. break;
  4926. case 176: /* CP_INT in ring buffer */
  4927. case 177: /* CP_INT in IB1 */
  4928. case 178: /* CP_INT in IB2 */
  4929. DRM_DEBUG("IH: CP int: 0x%08x\n", src_data);
  4930. radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
  4931. break;
  4932. case 181: /* CP EOP event */
  4933. DRM_DEBUG("IH: CP EOP\n");
  4934. if (rdev->family >= CHIP_CAYMAN) {
  4935. switch (src_data) {
  4936. case 0:
  4937. radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
  4938. break;
  4939. case 1:
  4940. radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
  4941. break;
  4942. case 2:
  4943. radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
  4944. break;
  4945. }
  4946. } else
  4947. radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
  4948. break;
  4949. case 224: /* DMA trap event */
  4950. DRM_DEBUG("IH: DMA trap\n");
  4951. radeon_fence_process(rdev, R600_RING_TYPE_DMA_INDEX);
  4952. break;
  4953. case 230: /* thermal low to high */
  4954. DRM_DEBUG("IH: thermal low to high\n");
  4955. rdev->pm.dpm.thermal.high_to_low = false;
  4956. queue_thermal = true;
  4957. break;
  4958. case 231: /* thermal high to low */
  4959. DRM_DEBUG("IH: thermal high to low\n");
  4960. rdev->pm.dpm.thermal.high_to_low = true;
  4961. queue_thermal = true;
  4962. break;
  4963. case 233: /* GUI IDLE */
  4964. DRM_DEBUG("IH: GUI idle\n");
  4965. break;
  4966. case 244: /* DMA trap event */
  4967. if (rdev->family >= CHIP_CAYMAN) {
  4968. DRM_DEBUG("IH: DMA1 trap\n");
  4969. radeon_fence_process(rdev, CAYMAN_RING_TYPE_DMA1_INDEX);
  4970. }
  4971. break;
  4972. default:
  4973. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  4974. break;
  4975. }
  4976. /* wptr/rptr are in bytes! */
  4977. rptr += 16;
  4978. rptr &= rdev->ih.ptr_mask;
  4979. WREG32(IH_RB_RPTR, rptr);
  4980. }
  4981. if (queue_dp)
  4982. schedule_work(&rdev->dp_work);
  4983. if (queue_hotplug)
  4984. schedule_delayed_work(&rdev->hotplug_work, 0);
  4985. if (queue_hdmi)
  4986. schedule_work(&rdev->audio_work);
  4987. if (queue_thermal && rdev->pm.dpm_enabled)
  4988. schedule_work(&rdev->pm.dpm.thermal.work);
  4989. rdev->ih.rptr = rptr;
  4990. atomic_set(&rdev->ih.lock, 0);
  4991. /* make sure wptr hasn't changed while processing */
  4992. wptr = evergreen_get_ih_wptr(rdev);
  4993. if (wptr != rptr)
  4994. goto restart_ih;
  4995. return IRQ_HANDLED;
  4996. }
  4997. static void evergreen_uvd_init(struct radeon_device *rdev)
  4998. {
  4999. int r;
  5000. if (!rdev->has_uvd)
  5001. return;
  5002. r = radeon_uvd_init(rdev);
  5003. if (r) {
  5004. dev_err(rdev->dev, "failed UVD (%d) init.\n", r);
  5005. /*
  5006. * At this point rdev->uvd.vcpu_bo is NULL which trickles down
  5007. * to early fails uvd_v2_2_resume() and thus nothing happens
  5008. * there. So it is pointless to try to go through that code
  5009. * hence why we disable uvd here.
  5010. */
  5011. rdev->has_uvd = 0;
  5012. return;
  5013. }
  5014. rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_obj = NULL;
  5015. r600_ring_init(rdev, &rdev->ring[R600_RING_TYPE_UVD_INDEX], 4096);
  5016. }
  5017. static void evergreen_uvd_start(struct radeon_device *rdev)
  5018. {
  5019. int r;
  5020. if (!rdev->has_uvd)
  5021. return;
  5022. r = uvd_v2_2_resume(rdev);
  5023. if (r) {
  5024. dev_err(rdev->dev, "failed UVD resume (%d).\n", r);
  5025. goto error;
  5026. }
  5027. r = radeon_fence_driver_start_ring(rdev, R600_RING_TYPE_UVD_INDEX);
  5028. if (r) {
  5029. dev_err(rdev->dev, "failed initializing UVD fences (%d).\n", r);
  5030. goto error;
  5031. }
  5032. return;
  5033. error:
  5034. rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_size = 0;
  5035. }
  5036. static void evergreen_uvd_resume(struct radeon_device *rdev)
  5037. {
  5038. struct radeon_ring *ring;
  5039. int r;
  5040. if (!rdev->has_uvd || !rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_size)
  5041. return;
  5042. ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
  5043. r = radeon_ring_init(rdev, ring, ring->ring_size, 0, PACKET0(UVD_NO_OP, 0));
  5044. if (r) {
  5045. dev_err(rdev->dev, "failed initializing UVD ring (%d).\n", r);
  5046. return;
  5047. }
  5048. r = uvd_v1_0_init(rdev);
  5049. if (r) {
  5050. dev_err(rdev->dev, "failed initializing UVD (%d).\n", r);
  5051. return;
  5052. }
  5053. }
  5054. static int evergreen_startup(struct radeon_device *rdev)
  5055. {
  5056. struct radeon_ring *ring;
  5057. int r;
  5058. /* enable pcie gen2 link */
  5059. evergreen_pcie_gen2_enable(rdev);
  5060. /* enable aspm */
  5061. evergreen_program_aspm(rdev);
  5062. /* scratch needs to be initialized before MC */
  5063. r = r600_vram_scratch_init(rdev);
  5064. if (r)
  5065. return r;
  5066. evergreen_mc_program(rdev);
  5067. if (ASIC_IS_DCE5(rdev) && !rdev->pm.dpm_enabled) {
  5068. r = ni_mc_load_microcode(rdev);
  5069. if (r) {
  5070. DRM_ERROR("Failed to load MC firmware!\n");
  5071. return r;
  5072. }
  5073. }
  5074. if (rdev->flags & RADEON_IS_AGP) {
  5075. evergreen_agp_enable(rdev);
  5076. } else {
  5077. r = evergreen_pcie_gart_enable(rdev);
  5078. if (r)
  5079. return r;
  5080. }
  5081. evergreen_gpu_init(rdev);
  5082. /* allocate rlc buffers */
  5083. if (rdev->flags & RADEON_IS_IGP) {
  5084. rdev->rlc.reg_list = sumo_rlc_save_restore_register_list;
  5085. rdev->rlc.reg_list_size =
  5086. (u32)ARRAY_SIZE(sumo_rlc_save_restore_register_list);
  5087. rdev->rlc.cs_data = evergreen_cs_data;
  5088. r = sumo_rlc_init(rdev);
  5089. if (r) {
  5090. DRM_ERROR("Failed to init rlc BOs!\n");
  5091. return r;
  5092. }
  5093. }
  5094. /* allocate wb buffer */
  5095. r = radeon_wb_init(rdev);
  5096. if (r)
  5097. return r;
  5098. r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
  5099. if (r) {
  5100. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  5101. return r;
  5102. }
  5103. r = radeon_fence_driver_start_ring(rdev, R600_RING_TYPE_DMA_INDEX);
  5104. if (r) {
  5105. dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
  5106. return r;
  5107. }
  5108. evergreen_uvd_start(rdev);
  5109. /* Enable IRQ */
  5110. if (!rdev->irq.installed) {
  5111. r = radeon_irq_kms_init(rdev);
  5112. if (r)
  5113. return r;
  5114. }
  5115. r = r600_irq_init(rdev);
  5116. if (r) {
  5117. DRM_ERROR("radeon: IH init failed (%d).\n", r);
  5118. radeon_irq_kms_fini(rdev);
  5119. return r;
  5120. }
  5121. evergreen_irq_set(rdev);
  5122. ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  5123. r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP_RPTR_OFFSET,
  5124. RADEON_CP_PACKET2);
  5125. if (r)
  5126. return r;
  5127. ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
  5128. r = radeon_ring_init(rdev, ring, ring->ring_size, R600_WB_DMA_RPTR_OFFSET,
  5129. DMA_PACKET(DMA_PACKET_NOP, 0, 0));
  5130. if (r)
  5131. return r;
  5132. r = evergreen_cp_load_microcode(rdev);
  5133. if (r)
  5134. return r;
  5135. r = evergreen_cp_resume(rdev);
  5136. if (r)
  5137. return r;
  5138. r = r600_dma_resume(rdev);
  5139. if (r)
  5140. return r;
  5141. evergreen_uvd_resume(rdev);
  5142. r = radeon_ib_pool_init(rdev);
  5143. if (r) {
  5144. dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
  5145. return r;
  5146. }
  5147. r = radeon_audio_init(rdev);
  5148. if (r) {
  5149. DRM_ERROR("radeon: audio init failed\n");
  5150. return r;
  5151. }
  5152. return 0;
  5153. }
  5154. int evergreen_resume(struct radeon_device *rdev)
  5155. {
  5156. int r;
  5157. /* reset the asic, the gfx blocks are often in a bad state
  5158. * after the driver is unloaded or after a resume
  5159. */
  5160. if (radeon_asic_reset(rdev))
  5161. dev_warn(rdev->dev, "GPU reset failed !\n");
  5162. /* Do not reset GPU before posting, on rv770 hw unlike on r500 hw,
  5163. * posting will perform necessary task to bring back GPU into good
  5164. * shape.
  5165. */
  5166. /* post card */
  5167. atom_asic_init(rdev->mode_info.atom_context);
  5168. /* init golden registers */
  5169. evergreen_init_golden_registers(rdev);
  5170. if (rdev->pm.pm_method == PM_METHOD_DPM)
  5171. radeon_pm_resume(rdev);
  5172. rdev->accel_working = true;
  5173. r = evergreen_startup(rdev);
  5174. if (r) {
  5175. DRM_ERROR("evergreen startup failed on resume\n");
  5176. rdev->accel_working = false;
  5177. return r;
  5178. }
  5179. return r;
  5180. }
  5181. int evergreen_suspend(struct radeon_device *rdev)
  5182. {
  5183. radeon_pm_suspend(rdev);
  5184. radeon_audio_fini(rdev);
  5185. if (rdev->has_uvd) {
  5186. uvd_v1_0_fini(rdev);
  5187. radeon_uvd_suspend(rdev);
  5188. }
  5189. r700_cp_stop(rdev);
  5190. r600_dma_stop(rdev);
  5191. evergreen_irq_suspend(rdev);
  5192. radeon_wb_disable(rdev);
  5193. evergreen_pcie_gart_disable(rdev);
  5194. return 0;
  5195. }
  5196. /* Plan is to move initialization in that function and use
  5197. * helper function so that radeon_device_init pretty much
  5198. * do nothing more than calling asic specific function. This
  5199. * should also allow to remove a bunch of callback function
  5200. * like vram_info.
  5201. */
  5202. int evergreen_init(struct radeon_device *rdev)
  5203. {
  5204. int r;
  5205. /* Read BIOS */
  5206. if (!radeon_get_bios(rdev)) {
  5207. if (ASIC_IS_AVIVO(rdev))
  5208. return -EINVAL;
  5209. }
  5210. /* Must be an ATOMBIOS */
  5211. if (!rdev->is_atom_bios) {
  5212. dev_err(rdev->dev, "Expecting atombios for evergreen GPU\n");
  5213. return -EINVAL;
  5214. }
  5215. r = radeon_atombios_init(rdev);
  5216. if (r)
  5217. return r;
  5218. /* reset the asic, the gfx blocks are often in a bad state
  5219. * after the driver is unloaded or after a resume
  5220. */
  5221. if (radeon_asic_reset(rdev))
  5222. dev_warn(rdev->dev, "GPU reset failed !\n");
  5223. /* Post card if necessary */
  5224. if (!radeon_card_posted(rdev)) {
  5225. if (!rdev->bios) {
  5226. dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
  5227. return -EINVAL;
  5228. }
  5229. DRM_INFO("GPU not posted. posting now...\n");
  5230. atom_asic_init(rdev->mode_info.atom_context);
  5231. }
  5232. /* init golden registers */
  5233. evergreen_init_golden_registers(rdev);
  5234. /* Initialize scratch registers */
  5235. r600_scratch_init(rdev);
  5236. /* Initialize surface registers */
  5237. radeon_surface_init(rdev);
  5238. /* Initialize clocks */
  5239. radeon_get_clock_info(rdev->ddev);
  5240. /* Fence driver */
  5241. r = radeon_fence_driver_init(rdev);
  5242. if (r)
  5243. return r;
  5244. /* initialize AGP */
  5245. if (rdev->flags & RADEON_IS_AGP) {
  5246. r = radeon_agp_init(rdev);
  5247. if (r)
  5248. radeon_agp_disable(rdev);
  5249. }
  5250. /* initialize memory controller */
  5251. r = evergreen_mc_init(rdev);
  5252. if (r)
  5253. return r;
  5254. /* Memory manager */
  5255. r = radeon_bo_init(rdev);
  5256. if (r)
  5257. return r;
  5258. if (ASIC_IS_DCE5(rdev)) {
  5259. if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw || !rdev->mc_fw) {
  5260. r = ni_init_microcode(rdev);
  5261. if (r) {
  5262. DRM_ERROR("Failed to load firmware!\n");
  5263. return r;
  5264. }
  5265. }
  5266. } else {
  5267. if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw) {
  5268. r = r600_init_microcode(rdev);
  5269. if (r) {
  5270. DRM_ERROR("Failed to load firmware!\n");
  5271. return r;
  5272. }
  5273. }
  5274. }
  5275. /* Initialize power management */
  5276. radeon_pm_init(rdev);
  5277. rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ring_obj = NULL;
  5278. r600_ring_init(rdev, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX], 1024 * 1024);
  5279. rdev->ring[R600_RING_TYPE_DMA_INDEX].ring_obj = NULL;
  5280. r600_ring_init(rdev, &rdev->ring[R600_RING_TYPE_DMA_INDEX], 64 * 1024);
  5281. evergreen_uvd_init(rdev);
  5282. rdev->ih.ring_obj = NULL;
  5283. r600_ih_ring_init(rdev, 64 * 1024);
  5284. r = r600_pcie_gart_init(rdev);
  5285. if (r)
  5286. return r;
  5287. rdev->accel_working = true;
  5288. r = evergreen_startup(rdev);
  5289. if (r) {
  5290. dev_err(rdev->dev, "disabling GPU acceleration\n");
  5291. r700_cp_fini(rdev);
  5292. r600_dma_fini(rdev);
  5293. r600_irq_fini(rdev);
  5294. if (rdev->flags & RADEON_IS_IGP)
  5295. sumo_rlc_fini(rdev);
  5296. radeon_wb_fini(rdev);
  5297. radeon_ib_pool_fini(rdev);
  5298. radeon_irq_kms_fini(rdev);
  5299. evergreen_pcie_gart_fini(rdev);
  5300. rdev->accel_working = false;
  5301. }
  5302. /* Don't start up if the MC ucode is missing on BTC parts.
  5303. * The default clocks and voltages before the MC ucode
  5304. * is loaded are not suffient for advanced operations.
  5305. */
  5306. if (ASIC_IS_DCE5(rdev)) {
  5307. if (!rdev->mc_fw && !(rdev->flags & RADEON_IS_IGP)) {
  5308. DRM_ERROR("radeon: MC ucode required for NI+.\n");
  5309. return -EINVAL;
  5310. }
  5311. }
  5312. return 0;
  5313. }
  5314. void evergreen_fini(struct radeon_device *rdev)
  5315. {
  5316. radeon_pm_fini(rdev);
  5317. radeon_audio_fini(rdev);
  5318. r700_cp_fini(rdev);
  5319. r600_dma_fini(rdev);
  5320. r600_irq_fini(rdev);
  5321. if (rdev->flags & RADEON_IS_IGP)
  5322. sumo_rlc_fini(rdev);
  5323. radeon_wb_fini(rdev);
  5324. radeon_ib_pool_fini(rdev);
  5325. radeon_irq_kms_fini(rdev);
  5326. uvd_v1_0_fini(rdev);
  5327. radeon_uvd_fini(rdev);
  5328. evergreen_pcie_gart_fini(rdev);
  5329. r600_vram_scratch_fini(rdev);
  5330. radeon_gem_fini(rdev);
  5331. radeon_fence_driver_fini(rdev);
  5332. radeon_agp_fini(rdev);
  5333. radeon_bo_fini(rdev);
  5334. radeon_atombios_fini(rdev);
  5335. kfree(rdev->bios);
  5336. rdev->bios = NULL;
  5337. }
  5338. void evergreen_pcie_gen2_enable(struct radeon_device *rdev)
  5339. {
  5340. u32 link_width_cntl, speed_cntl;
  5341. if (radeon_pcie_gen2 == 0)
  5342. return;
  5343. if (rdev->flags & RADEON_IS_IGP)
  5344. return;
  5345. if (!(rdev->flags & RADEON_IS_PCIE))
  5346. return;
  5347. /* x2 cards have a special sequence */
  5348. if (ASIC_IS_X2(rdev))
  5349. return;
  5350. if ((rdev->pdev->bus->max_bus_speed != PCIE_SPEED_5_0GT) &&
  5351. (rdev->pdev->bus->max_bus_speed != PCIE_SPEED_8_0GT))
  5352. return;
  5353. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  5354. if (speed_cntl & LC_CURRENT_DATA_RATE) {
  5355. DRM_INFO("PCIE gen 2 link speeds already enabled\n");
  5356. return;
  5357. }
  5358. DRM_INFO("enabling PCIE gen 2 link speeds, disable with radeon.pcie_gen2=0\n");
  5359. if ((speed_cntl & LC_OTHER_SIDE_EVER_SENT_GEN2) ||
  5360. (speed_cntl & LC_OTHER_SIDE_SUPPORTS_GEN2)) {
  5361. link_width_cntl = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
  5362. link_width_cntl &= ~LC_UPCONFIGURE_DIS;
  5363. WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
  5364. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  5365. speed_cntl &= ~LC_TARGET_LINK_SPEED_OVERRIDE_EN;
  5366. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
  5367. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  5368. speed_cntl |= LC_CLR_FAILED_SPD_CHANGE_CNT;
  5369. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
  5370. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  5371. speed_cntl &= ~LC_CLR_FAILED_SPD_CHANGE_CNT;
  5372. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
  5373. speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  5374. speed_cntl |= LC_GEN2_EN_STRAP;
  5375. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
  5376. } else {
  5377. link_width_cntl = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
  5378. /* XXX: only disable it if gen1 bridge vendor == 0x111d or 0x1106 */
  5379. if (1)
  5380. link_width_cntl |= LC_UPCONFIGURE_DIS;
  5381. else
  5382. link_width_cntl &= ~LC_UPCONFIGURE_DIS;
  5383. WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
  5384. }
  5385. }
  5386. void evergreen_program_aspm(struct radeon_device *rdev)
  5387. {
  5388. u32 data, orig;
  5389. u32 pcie_lc_cntl, pcie_lc_cntl_old;
  5390. bool disable_l0s, disable_l1 = false, disable_plloff_in_l1 = false;
  5391. /* fusion_platform = true
  5392. * if the system is a fusion system
  5393. * (APU or DGPU in a fusion system).
  5394. * todo: check if the system is a fusion platform.
  5395. */
  5396. bool fusion_platform = false;
  5397. if (radeon_aspm == 0)
  5398. return;
  5399. if (!(rdev->flags & RADEON_IS_PCIE))
  5400. return;
  5401. switch (rdev->family) {
  5402. case CHIP_CYPRESS:
  5403. case CHIP_HEMLOCK:
  5404. case CHIP_JUNIPER:
  5405. case CHIP_REDWOOD:
  5406. case CHIP_CEDAR:
  5407. case CHIP_SUMO:
  5408. case CHIP_SUMO2:
  5409. case CHIP_PALM:
  5410. case CHIP_ARUBA:
  5411. disable_l0s = true;
  5412. break;
  5413. default:
  5414. disable_l0s = false;
  5415. break;
  5416. }
  5417. if (rdev->flags & RADEON_IS_IGP)
  5418. fusion_platform = true; /* XXX also dGPUs in a fusion system */
  5419. data = orig = RREG32_PIF_PHY0(PB0_PIF_PAIRING);
  5420. if (fusion_platform)
  5421. data &= ~MULTI_PIF;
  5422. else
  5423. data |= MULTI_PIF;
  5424. if (data != orig)
  5425. WREG32_PIF_PHY0(PB0_PIF_PAIRING, data);
  5426. data = orig = RREG32_PIF_PHY1(PB1_PIF_PAIRING);
  5427. if (fusion_platform)
  5428. data &= ~MULTI_PIF;
  5429. else
  5430. data |= MULTI_PIF;
  5431. if (data != orig)
  5432. WREG32_PIF_PHY1(PB1_PIF_PAIRING, data);
  5433. pcie_lc_cntl = pcie_lc_cntl_old = RREG32_PCIE_PORT(PCIE_LC_CNTL);
  5434. pcie_lc_cntl &= ~(LC_L0S_INACTIVITY_MASK | LC_L1_INACTIVITY_MASK);
  5435. if (!disable_l0s) {
  5436. if (rdev->family >= CHIP_BARTS)
  5437. pcie_lc_cntl |= LC_L0S_INACTIVITY(7);
  5438. else
  5439. pcie_lc_cntl |= LC_L0S_INACTIVITY(3);
  5440. }
  5441. if (!disable_l1) {
  5442. if (rdev->family >= CHIP_BARTS)
  5443. pcie_lc_cntl |= LC_L1_INACTIVITY(7);
  5444. else
  5445. pcie_lc_cntl |= LC_L1_INACTIVITY(8);
  5446. if (!disable_plloff_in_l1) {
  5447. data = orig = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_0);
  5448. data &= ~(PLL_POWER_STATE_IN_OFF_0_MASK | PLL_POWER_STATE_IN_TXS2_0_MASK);
  5449. data |= PLL_POWER_STATE_IN_OFF_0(7) | PLL_POWER_STATE_IN_TXS2_0(7);
  5450. if (data != orig)
  5451. WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_0, data);
  5452. data = orig = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_1);
  5453. data &= ~(PLL_POWER_STATE_IN_OFF_1_MASK | PLL_POWER_STATE_IN_TXS2_1_MASK);
  5454. data |= PLL_POWER_STATE_IN_OFF_1(7) | PLL_POWER_STATE_IN_TXS2_1(7);
  5455. if (data != orig)
  5456. WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_1, data);
  5457. data = orig = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_0);
  5458. data &= ~(PLL_POWER_STATE_IN_OFF_0_MASK | PLL_POWER_STATE_IN_TXS2_0_MASK);
  5459. data |= PLL_POWER_STATE_IN_OFF_0(7) | PLL_POWER_STATE_IN_TXS2_0(7);
  5460. if (data != orig)
  5461. WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_0, data);
  5462. data = orig = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_1);
  5463. data &= ~(PLL_POWER_STATE_IN_OFF_1_MASK | PLL_POWER_STATE_IN_TXS2_1_MASK);
  5464. data |= PLL_POWER_STATE_IN_OFF_1(7) | PLL_POWER_STATE_IN_TXS2_1(7);
  5465. if (data != orig)
  5466. WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_1, data);
  5467. if (rdev->family >= CHIP_BARTS) {
  5468. data = orig = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_0);
  5469. data &= ~PLL_RAMP_UP_TIME_0_MASK;
  5470. data |= PLL_RAMP_UP_TIME_0(4);
  5471. if (data != orig)
  5472. WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_0, data);
  5473. data = orig = RREG32_PIF_PHY0(PB0_PIF_PWRDOWN_1);
  5474. data &= ~PLL_RAMP_UP_TIME_1_MASK;
  5475. data |= PLL_RAMP_UP_TIME_1(4);
  5476. if (data != orig)
  5477. WREG32_PIF_PHY0(PB0_PIF_PWRDOWN_1, data);
  5478. data = orig = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_0);
  5479. data &= ~PLL_RAMP_UP_TIME_0_MASK;
  5480. data |= PLL_RAMP_UP_TIME_0(4);
  5481. if (data != orig)
  5482. WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_0, data);
  5483. data = orig = RREG32_PIF_PHY1(PB1_PIF_PWRDOWN_1);
  5484. data &= ~PLL_RAMP_UP_TIME_1_MASK;
  5485. data |= PLL_RAMP_UP_TIME_1(4);
  5486. if (data != orig)
  5487. WREG32_PIF_PHY1(PB1_PIF_PWRDOWN_1, data);
  5488. }
  5489. data = orig = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
  5490. data &= ~LC_DYN_LANES_PWR_STATE_MASK;
  5491. data |= LC_DYN_LANES_PWR_STATE(3);
  5492. if (data != orig)
  5493. WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, data);
  5494. if (rdev->family >= CHIP_BARTS) {
  5495. data = orig = RREG32_PIF_PHY0(PB0_PIF_CNTL);
  5496. data &= ~LS2_EXIT_TIME_MASK;
  5497. data |= LS2_EXIT_TIME(1);
  5498. if (data != orig)
  5499. WREG32_PIF_PHY0(PB0_PIF_CNTL, data);
  5500. data = orig = RREG32_PIF_PHY1(PB1_PIF_CNTL);
  5501. data &= ~LS2_EXIT_TIME_MASK;
  5502. data |= LS2_EXIT_TIME(1);
  5503. if (data != orig)
  5504. WREG32_PIF_PHY1(PB1_PIF_CNTL, data);
  5505. }
  5506. }
  5507. }
  5508. /* evergreen parts only */
  5509. if (rdev->family < CHIP_BARTS)
  5510. pcie_lc_cntl |= LC_PMI_TO_L1_DIS;
  5511. if (pcie_lc_cntl != pcie_lc_cntl_old)
  5512. WREG32_PCIE_PORT(PCIE_LC_CNTL, pcie_lc_cntl);
  5513. }